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