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