author | Claus Gittinger <cg@exept.de> |
Mon, 20 Oct 2008 16:44:15 +0200 | |
changeset 2551 | 9e73083f6ea5 |
parent 2497 | 7efb31ff6de5 |
child 3471 | fa2a226e3022 |
permissions | -rw-r--r-- |
88 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
734 | 3 |
All Rights Reserved |
88 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1389 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
100 | 14 |
WindowBuilder subclass:#UIBuilder |
734 | 15 |
instanceVariableNames:'view currentMenuSelector spec specStack composite lastComponent |
1324 | 16 |
compositeView menuBar isEditing showDefaults isSubBuilder' |
1032 | 17 |
classVariableNames:'' |
223 | 18 |
poolDictionaries:'' |
2361 | 19 |
category:'Interface-Framework' |
66 | 20 |
! |
21 |
||
22 |
!UIBuilder class methodsFor:'documentation'! |
|
23 |
||
125 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
734 | 27 |
All Rights Reserved |
125 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
88 | 36 |
! |
37 |
||
66 | 38 |
documentation |
39 |
" |
|
775 | 40 |
this class allows parsing windowSpecs as created by ST/X's |
41 |
UIPainter and should be able to handle most of ST-80's specs. |
|
42 |
(and thereby allow to run applications built with this tool). |
|
43 |
However, it is not guaranteed that all of ST-80's winSpecs are understood. |
|
44 |
||
734 | 45 |
It also provides some rudimentary support for building interfaces |
46 |
programatically, by using #newComposite .. #add: .. #endComposite. |
|
47 |
This has been added for ST80-compatibility - we do not recommend using |
|
48 |
that for new ST/X programs. |
|
775 | 49 |
Those were added to allow execution of some PD applications. |
50 |
The programatic building protocol is not complete and certainly not bug free. |
|
223 | 51 |
|
373 | 52 |
Notice: |
775 | 53 |
some of this class was implemented using protocol information |
734 | 54 |
from alpha testers, literature and by reading public domain code |
373 | 55 |
- it may not be complete or compatible to |
56 |
the corresponding ST-80 class. |
|
57 |
If you encounter any incompatibilities, please forward a note |
|
58 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
59 |
||
775 | 60 |
[instance variables:] |
61 |
view <View> |
|
62 |
temporary - holds the view being built |
|
63 |
when creating components using the |
|
64 |
programmatic building interface. |
|
65 |
||
66 |
currentMenuSelector not yet used |
|
67 |
||
68 |
spec <UISpec> |
|
69 |
temporary - holds the spec being parsed |
|
70 |
when creating components using the |
|
71 |
programmatic building interface. |
|
72 |
||
73 |
specStack <Collection> |
|
74 |
temporary - holds the spec-stack when |
|
75 |
creating composites using newComposite/ |
|
76 |
endComposite, |
|
77 |
while creating components using the |
|
78 |
programmatic building interface. |
|
79 |
||
80 |
composite <SpecCollection> |
|
81 |
temporary - holds the current composite |
|
82 |
when using newComposite/ endComposite, |
|
83 |
while creating components using the |
|
84 |
programmatic building interface. |
|
85 |
||
86 |
lastComponent <View> |
|
87 |
temporary - holds the last component |
|
88 |
being built, |
|
89 |
when creating components using the |
|
90 |
programmatic building interface. |
|
91 |
||
92 |
compositeView <View> |
|
93 |
temporary - holds the current composites |
|
94 |
view, when creating components using the |
|
95 |
programmatic building interface. |
|
96 |
||
97 |
menuBar not yet used |
|
98 |
||
99 |
isEditing <Boolean> |
|
100 |
flag which is set when an interface is built |
|
101 |
by the UIPainter (as opposed to being built |
|
102 |
for the application). |
|
103 |
Changes the way aspects are aquired, |
|
104 |
(actually, no models are created/set) |
|
105 |
to prevent false building when no |
|
106 |
real applicationModel is present. |
|
107 |
(as is the case when the painter builds |
|
108 |
components). |
|
109 |
||
223 | 110 |
[author:] |
111 |
Claus Gittinger |
|
66 | 112 |
" |
113 |
! ! |
|
114 |
||
115 |
!UIBuilder class methodsFor:'initialization'! |
|
116 |
||
117 |
initialize |
|
118 |
Verbose := false "/ debugging flag |
|
119 |
! ! |
|
120 |
||
1763 | 121 |
!UIBuilder methodsFor:'Compatibility-VW'! |
734 | 122 |
|
123 |
wrapper |
|
124 |
"ST/X has no wrappers - return the view here" |
|
125 |
||
1207 | 126 |
^ view ? window |
734 | 127 |
|
128 |
"Created: / 3.3.1997 / 18:28:31 / cg" |
|
129 |
"Modified: / 31.10.1997 / 18:42:52 / cg" |
|
130 |
! ! |
|
131 |
||
86 | 132 |
!UIBuilder methodsFor:'accessing'! |
133 |
||
751 | 134 |
isEditing |
2368 | 135 |
"true if building from a GUI builder resource ( UIPainter, ... ), |
136 |
false if building for the real thing. |
|
137 |
If true, no models or actions should be set (no application is running)" |
|
138 |
||
751 | 139 |
^ isEditing ? false |
140 |
! |
|
141 |
||
142 |
isEditing:aState |
|
143 |
"true if build from a GUI builder resource ( UIPainter, ... ); if true, no |
|
144 |
models or actions should be set (no application is running) |
|
145 |
" |
|
146 |
isEditing := aState |
|
147 |
! |
|
148 |
||
1324 | 149 |
isSubBuilder |
1325 | 150 |
"return true, if this uiBuilder is for a subCanvas (i.e. a subApp) |
151 |
as opposed to a topApp builder" |
|
152 |
||
1324 | 153 |
^ isSubBuilder ? false |
154 |
||
155 |
"Created: / 29.1.2000 / 16:31:31 / cg" |
|
1325 | 156 |
"Modified: / 31.1.2000 / 15:03:09 / cg" |
1324 | 157 |
! |
158 |
||
159 |
isSubBuilder:aBoolean |
|
1325 | 160 |
"set/clear the flag, which states that this uiBuilder is for a subCanvas (i.e. a subApp) |
161 |
as opposed to a topApp builder. The default is false." |
|
162 |
||
1324 | 163 |
isSubBuilder := aBoolean |
164 |
||
165 |
"Created: / 29.1.2000 / 16:31:19 / cg" |
|
1325 | 166 |
"Modified: / 31.1.2000 / 15:03:37 / cg" |
1324 | 167 |
! |
168 |
||
721
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
169 |
menuBar |
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
170 |
"return the value of the instance variable 'menuBar' (automatically generated)" |
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
171 |
|
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
172 |
^ menuBar |
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
173 |
|
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
174 |
"Created: / 27.10.1997 / 16:30:12 / cg" |
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
175 |
! |
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
176 |
|
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
177 |
menuBar:something |
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
178 |
"set the value of the instance variable 'menuBar' (automatically generated)" |
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
179 |
|
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
180 |
menuBar := something. |
1246 | 181 |
self keyboardProcessor menuBar:menuBar. |
721
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
182 |
|
1889d708a951
provide a handle to the applications menuBar
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
183 |
"Created: / 27.10.1997 / 16:30:13 / cg" |
863 | 184 |
! |
185 |
||
186 |
showDefaults |
|
187 |
"returns true if the builder is in editing mode and the building |
|
188 |
components will build a default contents |
|
189 |
" |
|
190 |
self isEditing ifTrue:[ |
|
191 |
^ showDefaults ? false |
|
192 |
]. |
|
193 |
^ false |
|
194 |
||
195 |
! |
|
196 |
||
197 |
showDefaults:aBool |
|
198 |
"true if the builder is in editing mode and the building |
|
199 |
components will build a default contents |
|
200 |
" |
|
201 |
showDefaults := aBool |
|
1145 | 202 |
! |
203 |
||
204 |
spec |
|
205 |
"return the current spec" |
|
206 |
||
207 |
^ spec |
|
1204 | 208 |
! |
209 |
||
210 |
spec:aSpec |
|
211 |
"set the current spec" |
|
212 |
||
213 |
spec := aSpec |
|
1970 | 214 |
! |
215 |
||
216 |
view |
|
217 |
||
218 |
^view |
|
219 |
! |
|
220 |
||
221 |
view: something |
|
222 |
||
223 |
view := something |
|
224 |
! |
|
225 |
||
226 |
view:viewArg spec:specArg |
|
227 |
"set instance variables (automatically generated)" |
|
228 |
||
229 |
view := viewArg. |
|
230 |
spec := specArg. |
|
86 | 231 |
! ! |
232 |
||
372
6d7718f3d298
more ST-80 compatibility stuff
Claus Gittinger <cg@exept.de>
parents:
367
diff
changeset
|
233 |
!UIBuilder methodsFor:'building'! |
66 | 234 |
|
734 | 235 |
buildFromSpec:aSpecOrSpecArray |
2367
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
236 |
^ self buildWindowFromSpec:aSpecOrSpecArray |
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
237 |
! |
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
238 |
|
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
239 |
buildFromSpec:aSpecArray in:aView |
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
240 |
"build a window hierarchy according to my spec into an existing view" |
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
241 |
|
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
242 |
spec := UISpecification from:aSpecArray. |
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
243 |
^ spec buildViewFor:self in:aView. |
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
244 |
|
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
245 |
"Modified: 3.3.1997 / 18:44:02 / cg" |
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
246 |
! |
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
247 |
|
2497 | 248 |
buildViewForSpec:aSpecOrSpecArray in:aView |
2381 | 249 |
"used when building a subSpec; moved from the UISPec class to here, |
250 |
to allow different behavior in WebBuilder..." |
|
251 |
||
2497 | 252 |
|spec windowSpec| |
2381 | 253 |
|
2497 | 254 |
spec := UISpecification from:aSpecOrSpecArray. |
255 |
spec class == FullSpec ifTrue:[ |
|
256 |
spec component buildViewFor:self in:aView. |
|
257 |
(windowSpec := spec window) notNil ifTrue:[ |
|
2461 | 258 |
aView preferredExtent:(windowSpec bounds extent). |
259 |
"/ notice: this assumes, that the embedded spec's attributes are |
|
260 |
"/ used (for example: bg-color). |
|
261 |
"/ it would be a good idea to add some overwrite mechanism in |
|
262 |
"/ the UISubspecification. |
|
263 |
windowSpec setAttributesIn:aView with:self. |
|
2381 | 264 |
]. |
265 |
] ifFalse:[ |
|
2497 | 266 |
spec buildViewFor:self in:aView. |
2381 | 267 |
]. |
268 |
! |
|
269 |
||
2367
cc70db1e6d78
allow for both a window and a webPage to be built from the same spec
Claus Gittinger <cg@exept.de>
parents:
2361
diff
changeset
|
270 |
buildWindowFromSpec:aSpecOrSpecArray |
2071 | 271 |
spec := UISpecification from:aSpecOrSpecArray. |
734 | 272 |
window notNil ifTrue:[ |
2071 | 273 |
spec buildViewFor:self in:window. |
274 |
] ifFalse:[ |
|
275 |
window := spec buildViewFor:self in:nil. |
|
734 | 276 |
]. |
277 |
^ window |
|
278 |
! |
|
279 |
||
280 |
doFinalHookup |
|
281 |
||
282 |
"Created: 14.2.1997 / 14:52:27 / cg" |
|
283 |
! |
|
284 |
||
285 |
newSubBuilder |
|
286 |
|builder| |
|
287 |
||
288 |
builder := UIBuilder new. |
|
751 | 289 |
|
290 |
builder isEditing:isEditing. |
|
863 | 291 |
builder showDefaults:showDefaults. |
734 | 292 |
builder bindings:(self bindings). |
293 |
builder application:(self application). |
|
854 | 294 |
"/ builder applicationClass:applicationClass. |
751 | 295 |
^ builder |
2497 | 296 |
! |
297 |
||
298 |
rebuildFromSpec:aSpecOrSpecArray |
|
299 |
"remove what I have and rebuild from a possibily different spec" |
|
300 |
||
301 |
|windowBefore| |
|
302 |
||
303 |
windowBefore := self window. |
|
304 |
windowBefore notNil ifTrue:[ |
|
305 |
windowBefore destroySubViews |
|
306 |
]. |
|
307 |
"/ self buildViewForSpec:aSpecOrSpecArray in:windowBefore. |
|
308 |
self buildFromSpec:aSpecOrSpecArray in:windowBefore. |
|
309 |
windowBefore notNil ifTrue:[ |
|
310 |
windowBefore realizeAllSubViews |
|
311 |
] |
|
734 | 312 |
! ! |
313 |
||
1772 | 314 |
!UIBuilder methodsFor:'building-programatically'! |
734 | 315 |
|
367 | 316 |
add:aSpec |
1359
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
317 |
|collectedComponents appWinClass| |
478 | 318 |
|
319 |
composite notNil ifTrue:[ |
|
320 |
(collectedComponents := composite collection) isNil ifTrue:[ |
|
321 |
composite collection:(collectedComponents := OrderedCollection new). |
|
322 |
]. |
|
323 |
collectedComponents add:aSpec. |
|
324 |
view := aSpec buildViewWithLayoutFor:self in:compositeView. |
|
325 |
] ifFalse:[ |
|
326 |
spec isNil ifTrue:[ |
|
327 |
spec := FullSpec new. |
|
328 |
]. |
|
329 |
||
330 |
(aSpec isMemberOf:WindowSpec) ifTrue:[ |
|
331 |
spec window:aSpec |
|
332 |
] ifFalse:[ |
|
333 |
((aSpec isMemberOf:ComponentSpec) |
|
334 |
or:[(aSpec isMemberOf:SpecCollection)]) ifTrue:[ |
|
335 |
spec component:aSpec. |
|
336 |
||
337 |
window isNil ifTrue:[ |
|
1359
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
338 |
application notNil ifTrue:[ |
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
339 |
appWinClass := application applicationWindowClass |
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
340 |
] ifFalse:[ |
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
341 |
appWinClass := ApplicationWindow |
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
342 |
]. |
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
343 |
window := appWinClass new. |
734 | 344 |
window extent:300@300. |
478 | 345 |
]. |
346 |
aSpec buildViewWithLayoutFor:self in:window. |
|
347 |
"/ builder window displayBox |
|
348 |
composite := aSpec. |
|
349 |
compositeView := window. |
|
350 |
] ifFalse:[ |
|
351 |
spec component isNil ifTrue:[ |
|
352 |
spec component:SpecCollection new. |
|
353 |
spec component collection:OrderedCollection new. |
|
354 |
]. |
|
734 | 355 |
composite := spec component. |
356 |
window isNil ifTrue:[ |
|
965
04cadbd21aac
use new ApplicationWindow (instead of StandardSystemView)
Claus Gittinger <cg@exept.de>
parents:
917
diff
changeset
|
357 |
window := ApplicationWindow new. |
734 | 358 |
window extent:300@300. |
359 |
]. |
|
360 |
compositeView := window. |
|
478 | 361 |
spec component collection add:aSpec. |
362 |
view := aSpec buildViewWithLayoutFor:self in:compositeView. |
|
363 |
]. |
|
364 |
] |
|
365 |
]. |
|
366 |
||
367 |
lastComponent := view. |
|
367 | 368 |
^ view |
369 |
||
965
04cadbd21aac
use new ApplicationWindow (instead of StandardSystemView)
Claus Gittinger <cg@exept.de>
parents:
917
diff
changeset
|
370 |
"Modified: / 18.6.1998 / 19:09:38 / cg" |
478 | 371 |
! |
372 |
||
373 |
endComposite |
|
734 | 374 |
|entry finishedComposite finishedView| |
478 | 375 |
|
2083 | 376 |
(specStack notEmptyOrNil) ifTrue:[ |
734 | 377 |
finishedComposite := composite. |
378 |
finishedView := compositeView. |
|
379 |
||
380 |
"/ pop |
|
478 | 381 |
entry := specStack removeLast. |
382 |
composite := entry key. |
|
383 |
compositeView := entry value. |
|
734 | 384 |
|
385 |
lastComponent := finishedView. |
|
386 |
^ finishedComposite |
|
478 | 387 |
]. |
2551 | 388 |
self breakPoint:#cg. |
478 | 389 |
^ composite |
390 |
||
734 | 391 |
"Created: / 3.3.1997 / 17:17:43 / cg" |
392 |
"Modified: / 30.10.1997 / 23:28:04 / cg" |
|
478 | 393 |
! |
394 |
||
395 |
endCompositeLayout:layout |
|
734 | 396 |
composite compositeSpec isNil ifTrue:[ |
397 |
composite compositeSpec:(CompositeSpec new). |
|
398 |
]. |
|
399 |
composite compositeSpec layout:layout. |
|
479 | 400 |
compositeView layout:layout. |
478 | 401 |
self endComposite |
402 |
||
734 | 403 |
"Modified: / 30.10.1997 / 23:10:10 / cg" |
479 | 404 |
! |
405 |
||
406 |
endCompositeLayout:layout properties:props |
|
407 |
self endCompositeLayout:layout |
|
408 |
||
409 |
"Created: 3.3.1997 / 22:15:17 / cg" |
|
478 | 410 |
! |
411 |
||
412 |
newComposite |
|
413 |
|newComposite| |
|
414 |
||
734 | 415 |
"/ push the composite being built ... |
478 | 416 |
specStack isNil ifTrue:[ |
417 |
specStack := OrderedCollection new |
|
418 |
]. |
|
419 |
specStack addLast:(composite->compositeView). |
|
734 | 420 |
|
421 |
"/ start creating a new one ... |
|
478 | 422 |
newComposite := CompositeSpecCollection new. |
423 |
newComposite compositeSpec:(CompositeSpec new). |
|
424 |
compositeView := self add:newComposite. |
|
425 |
composite := newComposite. |
|
426 |
^ compositeView |
|
427 |
||
734 | 428 |
"Created: / 3.3.1997 / 17:15:36 / cg" |
429 |
"Modified: / 1.11.1997 / 02:48:44 / cg" |
|
100 | 430 |
! ! |
86 | 431 |
|
479 | 432 |
!UIBuilder methodsFor:'initialization'! |
433 |
||
434 |
setupWindowFor:aView |
|
435 |
|ext| |
|
436 |
||
437 |
window notNil ifTrue:[ |
|
438 |
ext := window extent. |
|
439 |
||
440 |
((window isMemberOf:View) |
|
441 |
or:[window isMemberOf:SimpleView]) ifTrue:[ |
|
442 |
aView addSubView:window. |
|
443 |
]. |
|
444 |
]. |
|
445 |
||
446 |
window := aView. |
|
447 |
||
448 |
aView container isNil ifTrue:[ |
|
449 |
spec notNil ifTrue:[ |
|
450 |
spec window setupView:window for:self |
|
451 |
] |
|
452 |
]. |
|
453 |
||
775 | 454 |
"Modified: / 27.1.1998 / 12:27:45 / cg" |
479 | 455 |
! ! |
456 |
||
132 | 457 |
!UIBuilder class methodsFor:'documentation'! |
458 |
||
459 |
version |
|
2551 | 460 |
^ '$Header: /cvs/stx/stx/libview2/UIBuilder.st,v 1.63 2008-10-20 14:44:15 cg Exp $' |
132 | 461 |
! ! |
1763 | 462 |
|
100 | 463 |
UIBuilder initialize! |