author | sr |
Mon, 19 May 2008 12:41:59 +0200 | |
changeset 2461 | b5eebe78cf6e |
parent 2381 | 9be3a9bd23d0 |
child 2497 | 7efb31ff6de5 |
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 |
|
2381 | 248 |
buildViewForSpec:aSpec in:aView |
249 |
"used when building a subSpec; moved from the UISPec class to here, |
|
250 |
to allow different behavior in WebBuilder..." |
|
251 |
||
2461 | 252 |
|windowSpec| |
2381 | 253 |
|
254 |
aSpec class == FullSpec ifTrue:[ |
|
255 |
aSpec component buildViewFor:self in:aView. |
|
2461 | 256 |
(windowSpec := aSpec window) notNil ifTrue:[ |
257 |
aView preferredExtent:(windowSpec bounds extent). |
|
258 |
"/ notice: this assumes, that the embedded spec's attributes are |
|
259 |
"/ used (for example: bg-color). |
|
260 |
"/ it would be a good idea to add some overwrite mechanism in |
|
261 |
"/ the UISubspecification. |
|
262 |
windowSpec setAttributesIn:aView with:self. |
|
2381 | 263 |
]. |
264 |
] ifFalse:[ |
|
265 |
aSpec buildViewFor:self in:aView. |
|
266 |
]. |
|
267 |
! |
|
268 |
||
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
|
269 |
buildWindowFromSpec:aSpecOrSpecArray |
2071 | 270 |
spec := UISpecification from:aSpecOrSpecArray. |
734 | 271 |
window notNil ifTrue:[ |
2071 | 272 |
spec buildViewFor:self in:window. |
273 |
] ifFalse:[ |
|
274 |
window := spec buildViewFor:self in:nil. |
|
734 | 275 |
]. |
276 |
^ window |
|
277 |
! |
|
278 |
||
279 |
doFinalHookup |
|
280 |
||
281 |
"Created: 14.2.1997 / 14:52:27 / cg" |
|
282 |
! |
|
283 |
||
284 |
newSubBuilder |
|
285 |
|builder| |
|
286 |
||
287 |
builder := UIBuilder new. |
|
751 | 288 |
|
289 |
builder isEditing:isEditing. |
|
863 | 290 |
builder showDefaults:showDefaults. |
734 | 291 |
builder bindings:(self bindings). |
292 |
builder application:(self application). |
|
854 | 293 |
"/ builder applicationClass:applicationClass. |
751 | 294 |
^ builder |
734 | 295 |
! ! |
296 |
||
1772 | 297 |
!UIBuilder methodsFor:'building-programatically'! |
734 | 298 |
|
367 | 299 |
add:aSpec |
1359
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
300 |
|collectedComponents appWinClass| |
478 | 301 |
|
302 |
composite notNil ifTrue:[ |
|
303 |
(collectedComponents := composite collection) isNil ifTrue:[ |
|
304 |
composite collection:(collectedComponents := OrderedCollection new). |
|
305 |
]. |
|
306 |
collectedComponents add:aSpec. |
|
307 |
view := aSpec buildViewWithLayoutFor:self in:compositeView. |
|
308 |
] ifFalse:[ |
|
309 |
spec isNil ifTrue:[ |
|
310 |
spec := FullSpec new. |
|
311 |
]. |
|
312 |
||
313 |
(aSpec isMemberOf:WindowSpec) ifTrue:[ |
|
314 |
spec window:aSpec |
|
315 |
] ifFalse:[ |
|
316 |
((aSpec isMemberOf:ComponentSpec) |
|
317 |
or:[(aSpec isMemberOf:SpecCollection)]) ifTrue:[ |
|
318 |
spec component:aSpec. |
|
319 |
||
320 |
window isNil ifTrue:[ |
|
1359
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
321 |
application notNil ifTrue:[ |
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
322 |
appWinClass := application applicationWindowClass |
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
323 |
] ifFalse:[ |
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
324 |
appWinClass := ApplicationWindow |
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
325 |
]. |
f40bfb94f862
allow for application to decide what type of
Claus Gittinger <cg@exept.de>
parents:
1325
diff
changeset
|
326 |
window := appWinClass new. |
734 | 327 |
window extent:300@300. |
478 | 328 |
]. |
329 |
aSpec buildViewWithLayoutFor:self in:window. |
|
330 |
"/ builder window displayBox |
|
331 |
composite := aSpec. |
|
332 |
compositeView := window. |
|
333 |
] ifFalse:[ |
|
334 |
spec component isNil ifTrue:[ |
|
335 |
spec component:SpecCollection new. |
|
336 |
spec component collection:OrderedCollection new. |
|
337 |
]. |
|
734 | 338 |
composite := spec component. |
339 |
window isNil ifTrue:[ |
|
965
04cadbd21aac
use new ApplicationWindow (instead of StandardSystemView)
Claus Gittinger <cg@exept.de>
parents:
917
diff
changeset
|
340 |
window := ApplicationWindow new. |
734 | 341 |
window extent:300@300. |
342 |
]. |
|
343 |
compositeView := window. |
|
478 | 344 |
spec component collection add:aSpec. |
345 |
view := aSpec buildViewWithLayoutFor:self in:compositeView. |
|
346 |
]. |
|
347 |
] |
|
348 |
]. |
|
349 |
||
350 |
lastComponent := view. |
|
367 | 351 |
^ view |
352 |
||
965
04cadbd21aac
use new ApplicationWindow (instead of StandardSystemView)
Claus Gittinger <cg@exept.de>
parents:
917
diff
changeset
|
353 |
"Modified: / 18.6.1998 / 19:09:38 / cg" |
478 | 354 |
! |
355 |
||
356 |
endComposite |
|
734 | 357 |
|entry finishedComposite finishedView| |
478 | 358 |
|
2083 | 359 |
(specStack notEmptyOrNil) ifTrue:[ |
734 | 360 |
finishedComposite := composite. |
361 |
finishedView := compositeView. |
|
362 |
||
363 |
"/ pop |
|
478 | 364 |
entry := specStack removeLast. |
365 |
composite := entry key. |
|
366 |
compositeView := entry value. |
|
734 | 367 |
|
368 |
lastComponent := finishedView. |
|
369 |
^ finishedComposite |
|
478 | 370 |
]. |
734 | 371 |
self halt. |
478 | 372 |
^ composite |
373 |
||
734 | 374 |
"Created: / 3.3.1997 / 17:17:43 / cg" |
375 |
"Modified: / 30.10.1997 / 23:28:04 / cg" |
|
478 | 376 |
! |
377 |
||
378 |
endCompositeLayout:layout |
|
734 | 379 |
composite compositeSpec isNil ifTrue:[ |
380 |
composite compositeSpec:(CompositeSpec new). |
|
381 |
]. |
|
382 |
composite compositeSpec layout:layout. |
|
479 | 383 |
compositeView layout:layout. |
478 | 384 |
self endComposite |
385 |
||
734 | 386 |
"Modified: / 30.10.1997 / 23:10:10 / cg" |
479 | 387 |
! |
388 |
||
389 |
endCompositeLayout:layout properties:props |
|
390 |
self endCompositeLayout:layout |
|
391 |
||
392 |
"Created: 3.3.1997 / 22:15:17 / cg" |
|
478 | 393 |
! |
394 |
||
395 |
newComposite |
|
396 |
|newComposite| |
|
397 |
||
734 | 398 |
"/ push the composite being built ... |
478 | 399 |
specStack isNil ifTrue:[ |
400 |
specStack := OrderedCollection new |
|
401 |
]. |
|
402 |
specStack addLast:(composite->compositeView). |
|
734 | 403 |
|
404 |
"/ start creating a new one ... |
|
478 | 405 |
newComposite := CompositeSpecCollection new. |
406 |
newComposite compositeSpec:(CompositeSpec new). |
|
407 |
compositeView := self add:newComposite. |
|
408 |
composite := newComposite. |
|
409 |
^ compositeView |
|
410 |
||
734 | 411 |
"Created: / 3.3.1997 / 17:15:36 / cg" |
412 |
"Modified: / 1.11.1997 / 02:48:44 / cg" |
|
100 | 413 |
! ! |
86 | 414 |
|
479 | 415 |
!UIBuilder methodsFor:'initialization'! |
416 |
||
417 |
setupWindowFor:aView |
|
418 |
|ext| |
|
419 |
||
420 |
window notNil ifTrue:[ |
|
421 |
ext := window extent. |
|
422 |
||
423 |
((window isMemberOf:View) |
|
424 |
or:[window isMemberOf:SimpleView]) ifTrue:[ |
|
425 |
aView addSubView:window. |
|
426 |
]. |
|
427 |
]. |
|
428 |
||
429 |
window := aView. |
|
430 |
||
431 |
aView container isNil ifTrue:[ |
|
432 |
spec notNil ifTrue:[ |
|
433 |
spec window setupView:window for:self |
|
434 |
] |
|
435 |
]. |
|
436 |
||
775 | 437 |
"Modified: / 27.1.1998 / 12:27:45 / cg" |
479 | 438 |
! ! |
439 |
||
132 | 440 |
!UIBuilder class methodsFor:'documentation'! |
441 |
||
442 |
version |
|
2461 | 443 |
^ '$Header: /cvs/stx/stx/libview2/UIBuilder.st,v 1.61 2008-05-19 10:41:59 sr Exp $' |
132 | 444 |
! ! |
1763 | 445 |
|
100 | 446 |
UIBuilder initialize! |