author | Claus Gittinger <cg@exept.de> |
Thu, 07 Dec 1995 11:34:06 +0100 | |
changeset 134 | f83c245371c2 |
parent 114 | e577a2f332d0 |
child 138 | 492fb73ca439 |
permissions | -rw-r--r-- |
50 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
" |
|
12 |
||
52 | 13 |
'From Smalltalk/X, Version:2.10.5 on 24-mar-1995 at 9:31:53 am'! |
14 |
||
50 | 15 |
Model subclass:#ApplicationModel |
52 | 16 |
instanceVariableNames:'builder resources' |
50 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
52 | 19 |
category:'Interface-Framework' |
50 | 20 |
! |
21 |
||
52 | 22 |
ApplicationModel class instanceVariableNames:'ClassResources'! |
23 |
||
50 | 24 |
!ApplicationModel class methodsFor:'documentation'! |
25 |
||
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! |
|
39 |
||
40 |
version |
|
114
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
100
diff
changeset
|
41 |
^ '$Header: /cvs/stx/stx/libview2/Attic/AppModel.st,v 1.17 1995-11-11 16:04:14 cg Exp $' |
50 | 42 |
! |
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
Since many ST-80 classes are subclasses of ApplicationModel, this class |
|
47 |
is provided here to allow easier porting of ST-80 code. |
|
57 | 48 |
|
63 | 49 |
It does not (currently) provide much functionality and is NOT |
50 |
compatible to the corresponding ST80 class; therefore, manual |
|
50 | 51 |
changes have to be made to get those applications to run under ST/X. |
57 | 52 |
(but at least, this enables you to fileIn that code and have a superclass |
78 | 53 |
for them) |
54 |
||
55 |
As time goes by, ST/X applications are going to be converted to |
|
56 |
become subclasses of this abstract class - see NewLauncher for a |
|
57 |
first concrete example. |
|
58 |
||
59 |
ApplicationModel is prepared to build a view from a windowSpec, as |
|
60 |
created by the windowBuilder. If you subclass does not provide such |
|
61 |
a spec, you should at least redefine: |
|
62 |
||
63 |
openInterface - to create a topview and open it |
|
64 |
||
65 |
you may want to redefine: |
|
66 |
||
67 |
closeRequest - to catch window closing |
|
68 |
focusSequence - to define a sequence for focus-stepping |
|
69 |
||
50 | 70 |
|
52 | 71 |
The classResources have been put into this class to allow ST/X |
57 | 72 |
applications (which used to be subclasses of StandardSystemView) |
73 |
to migrate smoothly into ApplicationModels (which is better design ...). |
|
52 | 74 |
|
50 | 75 |
Instance variables: |
52 | 76 |
resources ResourcePack language string translation |
77 |
||
78 | 78 |
builder WindowBuilder a builder who knows how to create |
79 |
a window hierarchy from a specification |
|
80 |
||
81 |
||
82 |
Notice: this class was implemented using protocol information |
|
83 |
from alpha testers and PD code - it may not be complete or compatible to |
|
84 |
the corresponding ST-80 class. If you encounter any incompatibilities, |
|
85 |
please forward a note to the ST/X team. |
|
50 | 86 |
" |
87 |
! ! |
|
88 |
||
52 | 89 |
!ApplicationModel class methodsFor:'initialization'! |
90 |
||
91 |
initialize |
|
92 |
self == ApplicationModel ifTrue:[ |
|
93 |
Smalltalk addDependent:self |
|
94 |
] |
|
95 |
||
96 |
" |
|
97 |
ApplicationModel initialize |
|
98 |
" |
|
99 |
! ! |
|
100 |
||
101 |
!ApplicationModel class methodsFor:'instance creation'! |
|
102 |
||
103 |
new |
|
63 | 104 |
^ super new basicInitialize initialize |
52 | 105 |
! ! |
106 |
||
50 | 107 |
!ApplicationModel class methodsFor:'startup'! |
108 |
||
109 |
open |
|
69 | 110 |
"create an instance of the application and open its view" |
111 |
||
63 | 112 |
self new open |
113 |
||
114 |
" |
|
115 |
self open |
|
116 |
" |
|
57 | 117 |
! |
118 |
||
63 | 119 |
openOn:anApplicationModel |
83 | 120 |
"I dont really understand what this method is useful for ..." |
121 |
||
63 | 122 |
anApplicationModel open |
78 | 123 |
! |
124 |
||
125 |
openOnDevice:aDevice |
|
126 |
"create an instance of the application and open its view |
|
127 |
on another device. |
|
128 |
EXPERIMENTAL and unfinished." |
|
129 |
||
130 |
self new openOnDevice:aDevice |
|
100 | 131 |
! |
132 |
||
133 |
openInterface:anInterfaceSymbol |
|
134 |
"create an instance of the application and open a view as |
|
135 |
specified by anInterfaceSymbol." |
|
136 |
||
137 |
self new openInterface:anInterfaceSymbol |
|
138 |
||
139 |
"Modified: 5.9.1995 / 17:54:50 / claus" |
|
50 | 140 |
! ! |
52 | 141 |
|
142 |
!ApplicationModel class methodsFor:'change & update'! |
|
143 |
||
144 |
update:something |
|
69 | 145 |
"flush resources on language changes" |
146 |
||
52 | 147 |
something == #Language ifTrue:[ |
148 |
"flush resources on language changes" |
|
149 |
self flushAllClassResources |
|
150 |
] |
|
151 |
! ! |
|
152 |
||
63 | 153 |
!ApplicationModel class methodsFor:'queries'! |
154 |
||
155 |
interfaceSpecFor:aSelector |
|
69 | 156 |
"return an interface spec" |
157 |
||
63 | 158 |
^ self perform:aSelector |
159 |
! ! |
|
160 |
||
52 | 161 |
!ApplicationModel class methodsFor:'resources'! |
162 |
||
163 |
classResources |
|
164 |
"if not already loaded, get the classes resourcePack |
|
165 |
and return it" |
|
166 |
||
167 |
ClassResources isNil ifTrue:[ |
|
168 |
ClassResources := ResourcePack for:self. |
|
169 |
]. |
|
170 |
^ ClassResources |
|
171 |
! |
|
172 |
||
173 |
classResources:aResourcePack |
|
174 |
"allow setting of the classResources" |
|
175 |
||
176 |
ClassResources := aResourcePack |
|
177 |
! |
|
178 |
||
179 |
flushAllClassResources |
|
180 |
"flush all classes resource translations. |
|
181 |
Needed after a resource file / language setting has changed." |
|
182 |
||
183 |
ResourcePack flushCachedResourcePacks. |
|
184 |
self flushClassResources. |
|
185 |
self allSubclassesDo:[:aClass | |
|
186 |
aClass flushClassResources. |
|
187 |
] |
|
188 |
! |
|
189 |
||
190 |
flushClassResources |
|
191 |
"flush classes resource string translations. |
|
192 |
Needed whenever a resource file / language setting has changed" |
|
193 |
||
194 |
ClassResources := nil. |
|
63 | 195 |
! |
196 |
||
197 |
updateClassResources |
|
198 |
"update my classResources" |
|
199 |
||
200 |
ClassResources := nil. |
|
201 |
self classResources |
|
52 | 202 |
! ! |
203 |
||
204 |
!ApplicationModel methodsFor:'initialization'! |
|
205 |
||
85 | 206 |
createBuilder |
207 |
"create a UI Builder for me. |
|
208 |
This method can be redefined if (eventually) there are |
|
209 |
spec readers for other UI languages (motif UIL ?)" |
|
210 |
||
211 |
|cls| |
|
212 |
||
213 |
(cls := UIBuilder) isNil ifTrue:[ |
|
214 |
(cls := WindowBuilder) isNil ifTrue:[ |
|
215 |
^ nil |
|
216 |
] |
|
217 |
]. |
|
218 |
^ cls new |
|
219 |
! |
|
220 |
||
63 | 221 |
basicInitialize |
69 | 222 |
"initialize the application. |
223 |
Since ST-80 applications seem commonly to redefine initialize |
|
224 |
without doing a super initialize, the real initialization is |
|
225 |
done here ..." |
|
226 |
||
52 | 227 |
super initialize. |
72 | 228 |
|
229 |
"claus: I wanted to delay the creation & assignment of the |
|
230 |
builder till later, to allow setting to another builder. |
|
231 |
however, some ST-80 code accesses the builder right after instance |
|
232 |
creation ..." |
|
233 |
||
234 |
"/ " |
|
235 |
"/ Create a windowBuilder to have someone around which |
|
236 |
"/ understands the builder protocol. Since UIBuilder is not present |
|
237 |
"/ in all systems, this allows operation without one (unless a spec |
|
238 |
"/ is read later ...) |
|
239 |
"/ " |
|
85 | 240 |
builder := self createBuilder. |
78 | 241 |
builder notNil ifTrue:[builder application:self]. |
52 | 242 |
resources := self class classResources. |
63 | 243 |
! |
244 |
||
245 |
initialize |
|
83 | 246 |
"nothing done here; |
247 |
but can be redefined in concrete applications" |
|
63 | 248 |
! |
249 |
||
250 |
addTopViewsToCurrentProject |
|
251 |
"add all of my topViews to the current projects list of views. |
|
252 |
This allows hiding views on a per-project basis." |
|
253 |
||
254 |
self windowGroup topViews do:[:aView | |
|
255 |
aView addToCurrentProject |
|
256 |
] |
|
52 | 257 |
! ! |
57 | 258 |
|
71 | 259 |
!ApplicationModel methodsFor:'queries'! |
260 |
||
261 |
processName |
|
262 |
"return a name to be shown for me in the process monitor" |
|
263 |
||
264 |
^ 'Application' |
|
265 |
! ! |
|
266 |
||
57 | 267 |
!ApplicationModel methodsFor:'startup'! |
268 |
||
85 | 269 |
allButOpenInterface:aSymbol |
270 |
"create my views but do not open the main window" |
|
271 |
||
272 |
|spec| |
|
273 |
||
274 |
spec := self class interfaceSpecFor:aSymbol. |
|
275 |
self allButOpenFrom:spec. |
|
276 |
^ builder |
|
277 |
! |
|
278 |
||
63 | 279 |
allButOpenFrom:aSpec |
69 | 280 |
"create my views but do not open the main window" |
281 |
||
71 | 282 |
|realBuilder| |
283 |
||
72 | 284 |
"/ DISABLED; see comment in basicInitialize |
285 |
"/ |
|
286 |
"/ " |
|
287 |
"/ here, we kludge a bit: up to now, the builder was an |
|
288 |
"/ instance of the no-op WindowBuilder. Now, it becomes |
|
289 |
"/ a UIBuilder .... |
|
290 |
"/ This allows for ApplicationModels without a UIBuilder |
|
291 |
"/ if not needed. |
|
292 |
"/ " |
|
293 |
"/ realBuilder := UIBuilder new. |
|
294 |
"/ builder := realBuilder. |
|
295 |
"/ builder application:self. |
|
296 |
"/ builder bindings:builder bindings. |
|
71 | 297 |
|
63 | 298 |
self preBuildWith:builder. |
299 |
builder buildFromSpec:aSpec. |
|
85 | 300 |
builder window model:self. |
301 |
builder window application:self. |
|
63 | 302 |
self postBuildWith:builder. |
303 |
! |
|
57 | 304 |
|
69 | 305 |
open |
306 |
"open a standard interface" |
|
307 |
||
78 | 308 |
self openInterface |
69 | 309 |
! |
310 |
||
63 | 311 |
openInterface |
78 | 312 |
"open a standard interface on another device. |
313 |
Subclasses which do not have an interfaceSpec |
|
314 |
may want to redefine this method and create & open their view(s) |
|
315 |
there. (see NewLauncher as an example)." |
|
69 | 316 |
|
63 | 317 |
self openInterface:#windowSpec |
57 | 318 |
! |
319 |
||
63 | 320 |
openInterface:aSymbol |
78 | 321 |
"open an interface on another display; |
322 |
the argument, aSymbol specifies which interface. |
|
69 | 323 |
Typically, applications only use one interface, |
78 | 324 |
returned by the #windowSpec method." |
69 | 325 |
|
85 | 326 |
self allButOpenInterface:aSymbol. |
78 | 327 |
builder openWithExtent:nil. |
328 |
||
63 | 329 |
^ builder |
330 |
! |
|
331 |
||
85 | 332 |
menuFor:aSymbol |
333 |
"create a new menuBuilder, to read specs and |
|
334 |
create a menu from it. Return this menu" |
|
335 |
||
336 |
|spec mbuilder| |
|
337 |
||
338 |
spec := self class interfaceSpecFor:aSymbol. |
|
339 |
mbuilder := UIBuilder new. |
|
340 |
mbuilder buildFromSpec:spec. |
|
341 |
||
342 |
builder componentAt:#windowMenuHolder put:(mbuilder window asValue). |
|
343 |
^ mbuilder window |
|
344 |
! |
|
345 |
||
63 | 346 |
closeDownViews |
69 | 347 |
"close down the applications view" |
63 | 348 |
|
349 |
|wg views| |
|
350 |
||
351 |
(wg := self windowGroup) notNil ifTrue:[ |
|
352 |
views := wg topViews. |
|
353 |
views notNil ifTrue:[ |
|
90 | 354 |
views copy do:[:aView | |
355 |
aView notNil ifTrue:[aView destroy] |
|
63 | 356 |
] |
357 |
] |
|
358 |
] |
|
359 |
! |
|
360 |
||
361 |
close |
|
69 | 362 |
"this is sent by my topView when about to be closed |
81 | 363 |
by the program (not by the windowManager). |
364 |
Could be redefined in subclasses." |
|
69 | 365 |
|
366 |
self closeDownViews |
|
367 |
! |
|
368 |
||
369 |
closeRequest |
|
63 | 370 |
"this is sent by my topView when about to be closed by the |
69 | 371 |
windowmanager. Can be redefined to inform & query about unsafed |
372 |
view contents, to send #close on ok, or ignore the closeRequest." |
|
63 | 373 |
|
374 |
self closeDownViews |
|
375 |
! |
|
376 |
||
377 |
opened |
|
378 |
"this is sent by my topView when its finally open" |
|
379 |
||
380 |
self addTopViewsToCurrentProject. |
|
381 |
self postOpenWith:builder |
|
57 | 382 |
! |
383 |
||
69 | 384 |
restarted |
385 |
"sent by my windowGroup, when restarted from an image. |
|
386 |
Nothing done here, but can be redefined to perform any actions |
|
387 |
required to reset the application after an image-restart. |
|
388 |
(for example: check if application files are still around, restart |
|
389 |
subprocesses etc.)." |
|
63 | 390 |
! |
57 | 391 |
|
63 | 392 |
saveAndTerminateRequest |
393 |
"some windowManagers send this to shut down an application |
|
394 |
and have it save its state for restart. |
|
395 |
Can be redefined in subclasses" |
|
396 |
||
397 |
self closeRequest |
|
398 |
! |
|
399 |
||
400 |
preBuildWith:aBuilder |
|
69 | 401 |
"this is sent before an interface is built from a spec. |
402 |
Can be redefined in subclasses. |
|
403 |
mhmh - what should this do here ?" |
|
61 | 404 |
! |
405 |
||
406 |
postBuildWith:aBuilder |
|
69 | 407 |
"this is sent after an interface is built from a spec. |
408 |
Can be redefined in subclasses. |
|
409 |
mhmh - what should this do here ?" |
|
63 | 410 |
! |
61 | 411 |
|
63 | 412 |
postOpenWith:aBuilder |
69 | 413 |
"this is sent after the applications main window is opened. |
414 |
Can be redefined in subclasses. |
|
415 |
mhmh - what should this do here ?" |
|
57 | 416 |
! ! |
417 |
||
418 |
!ApplicationModel methodsFor:'accessing'! |
|
419 |
||
420 |
resources |
|
69 | 421 |
"return the applications resources - thats a ResourcePack containing |
422 |
language strings" |
|
423 |
||
57 | 424 |
^ resources |
425 |
! |
|
426 |
||
81 | 427 |
window |
428 |
"return my topWindow" |
|
429 |
||
430 |
^ builder window |
|
431 |
! |
|
432 |
||
63 | 433 |
windowGroup |
69 | 434 |
"return the applications windowGroup" |
435 |
||
63 | 436 |
^ builder window windowGroup |
437 |
! |
|
438 |
||
57 | 439 |
builder |
69 | 440 |
"return the applications builder; this one has more information |
441 |
about views, components etc." |
|
442 |
||
57 | 443 |
^ builder |
444 |
! |
|
445 |
||
446 |
builder:aBuilder |
|
69 | 447 |
"set the applications builder. Normally, you should not set it |
448 |
directly, but depend on the default builder, as created when the application |
|
449 |
was created." |
|
450 |
||
57 | 451 |
builder := aBuilder |
63 | 452 |
! |
453 |
||
454 |
focusSequence |
|
69 | 455 |
"return a focusSequence for stepping through the applications views. |
456 |
The builder usually keeps track of so-called 'tabable' views. |
|
72 | 457 |
Stepping is done with the FocusNext/FocusPrevius keys, which are |
458 |
typically bound to Meta-CursorUp/Meta-CursorDown. |
|
459 |
Subclasses which do not use the builder (but instead build their view |
|
460 |
programmatically) should redefine this method to return a collection of |
|
461 |
views which defines the sequence." |
|
69 | 462 |
|
72 | 463 |
builder notNil ifTrue:[ |
464 |
^ builder focusSequence |
|
465 |
]. |
|
466 |
^ nil |
|
57 | 467 |
! ! |
72 | 468 |
|
85 | 469 |
!ApplicationModel methodsFor:'window events'! |
470 |
||
471 |
windowEvent:anEvent from:anApplicationWindow |
|
472 |
^ self |
|
473 |
! ! |
|
474 |
||
81 | 475 |
!ApplicationModel methodsFor:'misc'! |
72 | 476 |
|
81 | 477 |
withCursor:aCursor do:aBlock |
87 | 478 |
"evaluate aBlock, showing aCursor in my topView and all of its subviews. |
479 |
Return the value of aBlock." |
|
72 | 480 |
|
87 | 481 |
^ self window withCursor:aCursor do:aBlock |
81 | 482 |
! |
72 | 483 |
|
81 | 484 |
withWaitCursorDo:aBlock |
87 | 485 |
"evaluate aBlock, showing a waitCursor in my topView and all of its subviews. |
486 |
Return the value of aBlock." |
|
72 | 487 |
|
87 | 488 |
^ self withCursor:Cursor wait do:aBlock |
81 | 489 |
! ! |