summaryrefslogtreecommitdiffstats
path: root/qtjava/designer/juic/java/util.xsl
blob: ad5bba42b42a387931c6004924fa7b85e33d93d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?xml version="1.0" encoding="iso-8859-1"?>
<!--
  ** Author: Marco Ladermann <marco.ladermann@gmx.de>
  ** Date:   Fri Mar 28 18:37:09 CET 2003 @775 /Internet Time/
  ** 
  ** This software is free software. It is released under the terms of the
  ** GNU Lesser General Public Licence (LGPL)
  ** see http://www.gnu.org/copyleft/lesser.html
  **
  ** These stylesheets are distributed in the hope that they will be useful,
  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  -->
<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:exsl="http://exslt.org/common"
    xmlns:func="http://exslt.org/functions"
    xmlns:date="http://exslt.org/dates-and-times"
    xmlns:kde="http://kde.org/functions"
    xmlns:java="http://kde.org/java"
    extension-element-prefixes="func"
 >
    <!--
      ** Utility functions for java output
      -->
 
    <!-- Are images in the ui file or in the project or loaded via function ? -->
    <func:function name="java:getPixmap">
        <xsl:param name="image" select="."/>
        <func:result>
            <xsl:choose>
                <xsl:when test="/UI/pixmapfunction">
                    <xsl:value-of select="concat(/UI/pixmapfunction,'( ',$image, ' )')"/>
                </xsl:when>
                <xsl:when test="/UI/pixmapinproject">
                    <xsl:value-of select="concat('TQPixmap.fromMimeSource( &quot;',
                                                                          $images,
                                                                          $image,
                                                                          '&quot; )')"/>

                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$image"/>
                </xsl:otherwise>
            </xsl:choose>
        </func:result>
    </func:function>
    
    <!-- Function to generate the appropriate translate function for strings -->
    <func:function name="java:tr">
        <xsl:param name="isUtf8"/>
        <func:result>
            <xsl:choose>
                <xsl:when test="string($isUtf8) = 'true'">
                    <xsl:text>trUtf8</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>tr</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </func:result>
    </func:function>

    <!-- Helper function to calculate the name of the containing node -->
    <func:function name="java:getNodeName">
        <xsl:param name="node" select="."/>
        <func:result>
            <xsl:variable name="nn" select="kde:getNodeName($node)"/>
            <xsl:choose>
                <xsl:when test="$nn = /UI/widget/property[@name = 'name']/cstring">
                    <xsl:value-of select="'this'"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$nn"/>
                </xsl:otherwise>
            </xsl:choose>
        </func:result>
    </func:function>
    
    <!-- Helper function to calculate the name of the containing container -->
    <func:function name="java:getContainerName">
        <xsl:param name="node" select="."/>
        <func:result>
            <xsl:choose>
                <xsl:when test="$node = /UI/widget and /UI/widget/@class = 'TQMainWindow'">
                    <xsl:value-of select="'centralWidget()'"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="java:getNodeName($node)"/>
                </xsl:otherwise>
            </xsl:choose>
        </func:result>
    </func:function>
    
    <!--
      ** Change signal/slot signature
      -->
    <func:function name="java:cpp-to-java-signature">
        <xsl:param name="node"/>
        <func:result>
            <xsl:variable name="s1" select="translate($node, '&amp;*', '  ')"/>
            <xsl:variable name="s2" select="kde:replace($s1, 'TQString', 'String')"/>
            <xsl:variable name="s3" select="kde:replace($s2, 'const', '')"/>
            <xsl:variable name="s4" select="kde:replace($s3, 'virtual', '')"/>
            <xsl:variable name="s5" select="kde:replace($s4, 'bool', 'boolean')"/>
            <xsl:variable name="result" select="$s5"/>
            <xsl:if test="$node != $result">
                <xsl:variable name="path" select="kde:printPath($node)"/>
                <xsl:message>
In element at <xsl:value-of select="$path"/>:
signature changed from C++: <xsl:value-of select="$node"/>
                   to Java: <xsl:value-of select="$result"/>
                </xsl:message>
            </xsl:if>
            <xsl:value-of select="$result"/>
        </func:result>
    </func:function>

	<!--
	  ** Mask backslash and quote characters
	  -->
    <func:function name="java:toJavaString">
      <xsl:param name="text"/>
      <func:result>
        <xsl:variable name="s1" select="kde:replace($text, '\', '\\')"/>
        <xsl:variable name="s2" select="kde:replace($s1, '&quot;', '\&quot;')" />
        <xsl:variable name="s3" select="kde:replace($s2, '&#xA;', '\n')" />
        <xsl:variable name="s4" select="kde:replace($s3, '&#xD;', '\r')" />
        <xsl:variable name="result" select="$s4" />
        <xsl:value-of select="$result"/>
      </func:result>
    </func:function>
</xsl:stylesheet>