summaryrefslogtreecommitdiffstats
path: root/qtjava/designer/juic/common/main.xsl
blob: fd18d27472c7b632453d16abfeaa20af9f5f4a15 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
<?xml version="1.0" encoding="iso-8859-1"?>
<!--
  ** Author: Marco Ladermann (<marco.ladermann@gmx.de>)
  ** Date:   Sat Feb 01 18:26:59 CET 2003 @768 /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:set="http://exslt.org/sets"
    extension-element-prefixes="exsl set"
>
    <xsl:import href="classes.xsl"/>
    <xsl:import href="properties.xsl"/>
    
    <xsl:output encoding="utf-8" indent="no" method="text"/>

    <!--
    <xsl:variable name="QtClasses" select="document('QtClasses.xml')"/>
    -->

    <!--
      ** Matching the root node call named templates to do all the work
      ** @param data opaque data for user purpose
      -->
    <xsl:template match="/" mode="main">
        <xsl:param name="data"/>
        <xsl:message>Java package    : "<xsl:value-of select="$package"/>"</xsl:message>
        <xsl:message>Abstract slots  : "<xsl:value-of select="$abstract"/>"</xsl:message>
        <xsl:message>Method main     : "<xsl:value-of select="$main"/>"</xsl:message>
        <xsl:message>Image directory : "<xsl:value-of select="$images"/>"</xsl:message>
        <xsl:message>Output directory: "<xsl:value-of select="$outdir"/>"</xsl:message>
        <xsl:message>OS type         : "<xsl:value-of select="$os"/>"</xsl:message>
        <xsl:message></xsl:message>
        <xsl:if test="$abstract and $main">
            <xsl:message>Class will be abstract without main method</xsl:message>
        </xsl:if>
        <xsl:call-template name="createFileHeader">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:call-template name="createClassPreamble">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:call-template name="createClassHeader">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:call-template name="createInstanceVariables">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:call-template name="createConstructors">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:call-template name="createSlots">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:call-template name="createMethods">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:call-template name="createMain">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:call-template name="createClassFooter">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!-- 
      ** Create the file header 
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createFileHeader">
        <xsl:param name="data"/>
        <xsl:call-template name="putFileHeader">
            <xsl:with-param name="comment" select="/UI/comment"/>
            <xsl:with-param name="author" select="/UI/author"/>
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!--
      ** Finds all Qt classes to import and forwards a set of them to the
      ** template "putClassPreamble". The set of classes is given as a set
      ** of class-tagged names.
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createClassPreamble">
        <xsl:param name="data"/>
        <xsl:variable name="classes.tf">
            <xsl:if test="not($abstract) and $main">
                <xsl:choose>
                    <xsl:when test="$kde">
                        <class>KApplication</class>
                        <class>KCmdLineArgs</class>
                    </xsl:when>
                    <xsl:otherwise>
                        <class>QApplication</class>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
            <class>QWidget</class>
            <xsl:apply-templates mode="classes"/>
        </xsl:variable>
        <xsl:variable name="classes.ns" select="exsl:node-set($classes.tf)"/>
        <xsl:variable name="classes" select="set:distinct($classes.ns/class)"/>
        
        <xsl:variable name="sortedClasses">
            <xsl:for-each select="exsl:node-set($classes)">
                <xsl:sort/>
                <class><xsl:value-of select="."/></class>
            </xsl:for-each>
        </xsl:variable>
        
        <xsl:call-template name="putClassPreamble">
            <xsl:with-param name="classes" select="exsl:node-set($sortedClasses)"/>
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>
    
    <!--
      ** Create the class header
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createClassHeader">
        <xsl:param name="data"/>
        <xsl:call-template name="putClassHeader">
            <xsl:with-param name="extends" select="/UI/widget/@class"/>
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!--
      ** Create the instance variables
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createInstanceVariables">
        <xsl:param name="data"/>
        <xsl:call-template name="putVariables">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:apply-templates mode="declareInstances" select="/UI">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>

    <!--
      ** Create the constructors
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createConstructors">
        <xsl:param name="data"/>
        <xsl:call-template name="putConstructors">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!--
      ** Create the slots
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createSlots">
        <xsl:param name="data"/>
        <xsl:for-each select="/UI/slots/slot | /UI/connections/slot">
            <xsl:call-template name="putSlot">
                <xsl:with-param name="data" select="$data"/>
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>

    <!--
      ** Create the signals
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createSignals">
        <xsl:param name="data"/>
        <xsl:for-each select="/UI/signals/signal">
            <xsl:call-template name="putSignal">
                <xsl:with-param name="data" select="$data"/>
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>

    <!--
      ** Create the methods
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createMethods">
        <xsl:param name="data"/>
        <xsl:call-template name="putMethods">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!--
      ** Create the main class
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createMain">
        <xsl:param name="data"/>
        <xsl:call-template name="putMain">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!--
      ** Create the class header, i.e. the class declaration and
      ** the declaration of the instance variables
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createClassFooter">
        <xsl:param name="data"/>
        <xsl:call-template name="putClassFooter">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!--
      ** Create the instance definitions
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createInstanceDefinitions">
        <xsl:param name="data"/>
        <xsl:apply-templates mode="defineInstances" select="/UI/widget">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>

    <!--
      ** Create the database definitions
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createDatabaseDefinitions">
        <xsl:param name="data"/>
        <xsl:for-each select="//widget[@class = 'QDataBrowser']">
            <xsl:call-template name="putDatabaseDefinition">
                <xsl:with-param name="data" select="$data"/>
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>

    <!--
      ** Create the action definitions
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createActionDefinitions">
        <xsl:param name="data"/>
        <xsl:apply-templates mode="defineActions" select="/UI/actions/*">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>

    <!--
      ** Create the toolbar definitions
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createToolbarDefinitions">
        <xsl:param name="data"/>
        <xsl:apply-templates mode="toolbar" select="/UI/toolbars/toolbar">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>

    <!--
      ** Create the menubar definitions
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createMenubarDefinitions">
        <xsl:param name="data"/>
        <xsl:apply-templates mode="menubar" select="/UI/menubar">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>

    <!--
      ** Create the connection definitions
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createConnectionDefinitions">
        <xsl:param name="data"/>
        <xsl:for-each select="/UI/connections/connection">
            <xsl:call-template name="putConnectionDefinition">
                <xsl:with-param name="data" select="$data"/>
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>

    <!--
      ** Create the tabstops definitions
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="createTabstopsDefinitions">
        <xsl:param name="data"/>
        <xsl:if test="/UI/tabstops">
            <xsl:call-template name="putTabstops">
                <xsl:with-param name="data" select="$data"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>


    <!--
      ** Declare instance variables for all children objects of the
      ** main widget, actions, menubars etc.
      ** @param data opaque data for user purpose
      -->
      
    <!-- Declare instances of all objects that are not QLayoutWidgets -->
    <xsl:template match="property[(@name = 'name') and not(../@class = 'QLayoutWidget')]" mode="declareInstances" priority="1">
        <xsl:param name="data"/>
        <xsl:call-template name="putInstanceVariable"><!-- call user hook -->
            <xsl:with-param name="class">
                <xsl:apply-templates mode="toClass" select=".."/>
            </xsl:with-param>
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>
    
    <!-- Declare instances of all objects that are QLayoutWidgets not included in a hbox, vbox or grid -->
    <xsl:template match="property[(@name = 'name') and (../@class = 'QLayoutWidget') and (count(ancestor::hbox|ancestor::vbox|ancestor::grid)=0)]" mode="declareInstances">
        <xsl:param name="data"/>
        <xsl:message>Declare a QLayoutWidget</xsl:message>
        <xsl:call-template name="putInstanceVariable"><!-- call user hook -->
            <xsl:with-param name="class">
                <xsl:apply-templates mode="toClass" select=".."/>
            </xsl:with-param>
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>
    
    <xsl:template match="menubar/item" mode="declareInstances">
        <xsl:param name="data"/>
        <xsl:call-template name="putInstanceVariable"><!-- call user hook -->
            <xsl:with-param name="class">
                <class>QPopupMenu</class>
            </xsl:with-param>
            <xsl:with-param name="name" select="@name"/>
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!-- leave out the main widget -->
    <xsl:template match="/UI/widget" mode="declareInstances" priority="1">
        <xsl:param name="data"/>
        <xsl:apply-templates mode="declareInstances" select="widget|grid|hbox|vbox">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>
    <!-- descent -->
    <xsl:template match="widget|grid|hbox|vbox" mode="declareInstances">
        <xsl:param name="data"/>
        <xsl:apply-templates mode="declareInstances" select="*">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="text()|@*" mode="declareInstances"/>

    <!--
      ** 
      **    The following templates generate the definitions of the instance variables.
      **    They are called/applied in the "putConstructor" template 
      **
      -->

    <!-- Match the toplevel widget -->  
    <xsl:template match="/UI/widget" mode="defineInstances" priority="1">
        <xsl:param name="data"/>
        <xsl:call-template name="putTopLevelWindowDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:apply-templates mode="defineInstances">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>

    <!-- Match subsequent widgets -->
    <xsl:template match="widget[@class = 'QLayoutWidget']" mode="defineInstances" priority="1">
        <xsl:param name="data"/>
        <xsl:if test="count(ancestor::hbox|ancestor::vbox|ancestor::grid)=0">
            <xsl:call-template name="putWidgetDefinition">
                <xsl:with-param name="data" select="$data"/>
            </xsl:call-template>
        </xsl:if>
        <xsl:apply-templates mode="defineInstances">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>
    <!-- Match subsequent widgets -->
    <xsl:template match="widget[not(@class = 'QLayoutWidget')]" mode="defineInstances">
        <xsl:param name="data"/>
        <xsl:call-template name="putWidgetDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:apply-templates mode="defineInstances">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>

    <!-- Match layout tags -->
    <xsl:template match="grid|hbox|vbox" mode="defineInstances">
        <xsl:param name="data"/>
        <xsl:variable name="class">
            <xsl:apply-templates mode="toClass" select="."/>
        </xsl:variable>
        <xsl:call-template name="putLayoutDefinition">
            <xsl:with-param name="class" select="$class"/>
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:apply-templates mode="defineInstances">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
        <xsl:for-each select="widget|spacer">
            <xsl:call-template name="putLayoutContentDefinition">
            <xsl:with-param name="data" select="$data"/>
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>

    <!-- Match column tags -->
    <xsl:template match="column" mode="defineInstances">
        <xsl:param name="data"/>
        <xsl:call-template name="putColumnDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!-- Match row tags -->
    <xsl:template match="row" mode="defineInstances">
        <xsl:param name="data"/>
        <xsl:call-template name="putRowDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!-- Match item tags -->
    <xsl:template match="item" mode="defineInstances">
        <xsl:param name="data"/>
        <xsl:variable name="containerClass">
            <xsl:apply-templates mode="toClass" select=".."/>
        </xsl:variable>
        <xsl:call-template name="putItemDefinition">
            <xsl:with-param name="class" select="$containerClass"/>
            <xsl:with-param name="number" select="count(preceding-sibling::item)"/>
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <!-- Match spacer tags -->
    <xsl:template match="spacer" mode="defineInstances">
        <xsl:param name="data"/>
        <xsl:call-template name="putSpacerDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <!-- <xsl:apply-templates mode="defineInstances">
                <xsl:with-param name="data" select="$data"/>
             </xsl:apply-templates>
        -->
    </xsl:template>

    <xsl:template match="property[not(@name = 'name')]" mode="defineInstances">
        <xsl:param name="data"/>
        <xsl:apply-templates mode="property">
            <xsl:with-param name="name" select="@name"/>
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>

    <!-- Ignore everything else -->
    <xsl:template match="text()|@*" mode="defineInstances"/>

    <!-- ACTIONS -->
    <xsl:template match="action" mode="defineActions">
        <xsl:param name="data"/>
        <xsl:call-template name="putActionDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:apply-templates select="*" mode="defineInstances">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="actiongroup" mode="defineActions">
        <xsl:param name="data"/>
        <xsl:call-template name="putActionGroupDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:apply-templates select="*" mode="defineActions">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>
    <!-- Ignore everything else -->
    <xsl:template match="*|text()|@*" mode="defineActions"/>

    <!-- 
      ** Match menubar 
      -->
    <xsl:template match="menubar" mode="menubar">
        <xsl:param name="data"/>
        <xsl:call-template name="putMenubarDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:apply-templates mode="menubar">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>
    
    <xsl:template match="item" mode="menubar">
        <xsl:param name="data"/>
        <xsl:call-template name="putMenubarItemDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:apply-templates mode="menubar">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="action" mode="menubar">
        <xsl:param name="data"/>
        <xsl:call-template name="putMenubarActionDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template match="separator" mode="menubar">
        <xsl:param name="data"/>
        <xsl:call-template name="putMenubarSeperatorDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template match="*|text()|@*" mode="menubar"/>
    
    <!-- 
      ** Match Toolbar 
      -->
    <xsl:template match="toolbar" mode="toolbar">
        <xsl:param name="data"/>
        <xsl:call-template name="putToolbarDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
        <xsl:apply-templates mode="toolbar">
            <xsl:with-param name="data" select="$data"/>
        </xsl:apply-templates>
    </xsl:template>
    
    <xsl:template match="action" mode="toolbar">
        <xsl:param name="data"/>
        <xsl:call-template name="putToolbarActionDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template match="separator" mode="toolbar">
        <xsl:param name="data"/>
        <xsl:call-template name="putToolbarSeperatorDefinition">
            <xsl:with-param name="data" select="$data"/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template match="*|text()|@*" mode="toolbar"/>

</xsl:stylesheet>