26
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
3 |
All Rights Reserved
|
26
|
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 |
"
|
11
|
12 |
|
|
13 |
Object subclass:#WindowGroup
|
90
|
14 |
instanceVariableNames:'views topViews myProcess mySensor isModal previousGroup
|
172
|
15 |
focusView focusSequence preEventHook postEventHook'
|
180
|
16 |
classVariableNames:'LastActiveGroup LastActiveProcess LeaveSignal'
|
72
|
17 |
poolDictionaries:''
|
|
18 |
category:'Interface-Support'
|
11
|
19 |
!
|
|
20 |
|
54
|
21 |
WindowGroup comment:'
|
|
22 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
23 |
All Rights Reserved
|
54
|
24 |
|
180
|
25 |
$Header: /cvs/stx/stx/libview/WindowGroup.st,v 1.33 1995-09-07 12:30:22 claus Exp $
|
54
|
26 |
'!
|
|
27 |
|
46
|
28 |
!WindowGroup class methodsFor:'documentation'!
|
|
29 |
|
|
30 |
copyright
|
|
31 |
"
|
|
32 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
33 |
All Rights Reserved
|
46
|
34 |
|
|
35 |
This software is furnished under a license and may be used
|
|
36 |
only in accordance with the terms of that license and with the
|
|
37 |
inclusion of the above copyright notice. This software may not
|
|
38 |
be provided or otherwise made available to, or used by, any
|
|
39 |
other person. No title to or ownership of the software is
|
|
40 |
hereby transferred.
|
|
41 |
"
|
|
42 |
!
|
|
43 |
|
|
44 |
version
|
|
45 |
"
|
180
|
46 |
$Header: /cvs/stx/stx/libview/WindowGroup.st,v 1.33 1995-09-07 12:30:22 claus Exp $
|
46
|
47 |
"
|
|
48 |
!
|
|
49 |
|
|
50 |
documentation
|
|
51 |
"
|
103
|
52 |
In Smalltalk/X, the known (ST-80) concept of a controller has been
|
|
53 |
extended to a WindowGroup which handles process related stuff, and
|
109
|
54 |
the Controller, which handles events only and defines the user interaction.
|
103
|
55 |
There is no polling in controllers (not even conceptionally).
|
|
56 |
|
|
57 |
WindowGroups are responsible to wait for and forward events for a group of
|
144
|
58 |
windows. All views in a group share a single windowSensor which holdes the
|
|
59 |
event queue (therefore views all share the same input event queue).
|
|
60 |
|
103
|
61 |
Except for modal boxes, a separate process is created for each windowGroup
|
144
|
62 |
which waits for events and processes them, by sending corresponding
|
|
63 |
event messages to the views controller or the view (*).
|
109
|
64 |
Therefore, multiple applications run in parallel.
|
103
|
65 |
Modal boxes create an extra window group for the components of the modal
|
144
|
66 |
box, but execute the event-processing loop in the original process -
|
|
67 |
therefore, the original windowgroup is blocked for the duration of the modal
|
|
68 |
interaction (**).
|
103
|
69 |
|
|
70 |
Normally, one windowgroup is associated to each topview (StandardSystemView)
|
144
|
71 |
and all of its subviews. However, this is not strictly required;
|
|
72 |
it is possible to create extra windowgroups for subviews, which will let them
|
|
73 |
run in parallel
|
|
74 |
(for example, the FileBrowsers kill Button is created that
|
|
75 |
way, to allow a kill of an executing unix command, while the browser
|
|
76 |
itself reads the pipeStream for incoming text).
|
|
77 |
|
|
78 |
On the other hand, multiple topviews can be placed into the same windowGroup;
|
|
79 |
which allows for multiview applications, of which only one communicates with
|
103
|
80 |
the user at a time.
|
109
|
81 |
|
103
|
82 |
Although currently not implemented, it is planned for a future version,
|
|
83 |
to also handle all topviews of a windowgroup as a unit with respect to
|
|
84 |
iconification and deiconification: if any of a windowgroups topviews gets
|
|
85 |
iconified, all others will be as well.
|
|
86 |
|
109
|
87 |
WindowGroups also support a focus window: this is the one that gets the
|
103
|
88 |
keyboard input - even if the cursor is located in another subview.
|
|
89 |
(this is a brand new feature and not yet released for public use)
|
|
90 |
|
|
91 |
Finally, windowgroups are the perfect place for things like defining a
|
|
92 |
cursor for all associated views, flushing all input, waiting for expose
|
|
93 |
events etc.
|
|
94 |
|
|
95 |
You dont have to care for details in the normal case, a windowgroup is
|
|
96 |
created for you automatically, when a view is opened.
|
|
97 |
|
|
98 |
instance variables:
|
144
|
99 |
|
103
|
100 |
views collection of views of this group
|
|
101 |
|
|
102 |
topViews collection of topviews of this group
|
|
103 |
|
|
104 |
myProcess the process executing the events
|
|
105 |
|
|
106 |
mySensor my input sensor
|
|
107 |
|
|
108 |
isModal true if this is for a modal box
|
|
109 |
|
|
110 |
previousGroup if modal, the group that started this one
|
|
111 |
|
|
112 |
focusView the one that has the focus (or nil)
|
|
113 |
|
|
114 |
focusSequence defines the focus sequence
|
|
115 |
|
|
116 |
|
|
117 |
clas variables:
|
|
118 |
LeaveSignal if raised, a modal box leaves (closes)
|
|
119 |
|
|
120 |
|
144
|
121 |
(*)
|
|
122 |
due to historic reasons, many views have the controller functionality
|
103
|
123 |
integrated, and handle events themself. The windowSensor takes care
|
|
124 |
of this, by checking if a view has a controller, and, if so, forwarding
|
|
125 |
the events to it. Otherwise, events are sent directly to the view.
|
144
|
126 |
|
|
127 |
In the future, all views will be rewritten to actually use a controller.
|
|
128 |
Currently (being in the middle of this migration), only some views
|
|
129 |
(buttons, toggles and subclasses) do so.
|
|
130 |
|
|
131 |
(**)
|
|
132 |
the modal-event loop peeks into the original groups damage queue
|
|
133 |
in regular time intervals - therefore, view updating is still done in
|
|
134 |
the blocked group.
|
103
|
135 |
|
|
136 |
For more information, read 'introduction to view programming' in the
|
|
137 |
doc/online directory.
|
46
|
138 |
"
|
|
139 |
! !
|
|
140 |
|
54
|
141 |
!WindowGroup class methodsFor:'initialization'!
|
46
|
142 |
|
|
143 |
initialize
|
|
144 |
LeaveSignal isNil ifTrue:[
|
72
|
145 |
LeaveSignal := (Signal new) mayProceed:true.
|
|
146 |
LeaveSignal nameClass:self message:#leaveSignal.
|
|
147 |
LeaveSignal notifierString:'unhandled leave signal'.
|
54
|
148 |
].
|
46
|
149 |
|
|
150 |
"WindowGroup initialize"
|
|
151 |
! !
|
|
152 |
|
144
|
153 |
!WindowGroup class methodsFor:'Signal constants'!
|
72
|
154 |
|
|
155 |
leaveSignal
|
109
|
156 |
"return the signal which is used to exit a modal loop.
|
144
|
157 |
This private signal, is always cought while a modalbox is active.
|
|
158 |
Raising it will exit the modal loop and return from the views #openModal
|
|
159 |
method."
|
109
|
160 |
|
72
|
161 |
^ LeaveSignal
|
|
162 |
! !
|
|
163 |
|
11
|
164 |
!WindowGroup class methodsFor:'instance creation'!
|
|
165 |
|
|
166 |
new
|
26
|
167 |
"create and return a new WindowGroup object"
|
|
168 |
|
11
|
169 |
^ self basicNew initialize
|
|
170 |
! !
|
|
171 |
|
26
|
172 |
!WindowGroup class methodsFor:'accessing'!
|
|
173 |
|
|
174 |
activeGroup
|
180
|
175 |
"return the currently active windowGroup.
|
|
176 |
The returned value may not be fully correct, in case the current process
|
|
177 |
handles multiple windowGroups simulaniously. In this case,
|
|
178 |
the first group is returned (prefering a modal if there is one).
|
|
179 |
(maybe we should return a collection of windowGroups here).
|
|
180 |
|
|
181 |
This method is required to simulate the historic ST-80 single display
|
|
182 |
behavior for Cursor>>show / Cursor>>showWhile and some others (raising the
|
|
183 |
activeGroups topView when modalBoxes appear) on multiple display screens.
|
|
184 |
These methods should change the cursor for the currently
|
|
185 |
active windowGroup ONLY, instead of globally affecting the display or
|
|
186 |
all views
|
|
187 |
(since, depending on the priority, other views could be unaffacted by this
|
|
188 |
and an overall cursor change does not make sense.)"
|
|
189 |
|
|
190 |
|activeProcess groups wg|
|
|
191 |
|
|
192 |
Processor isNil ifTrue:[^ nil]. "/ only during very early init phase
|
26
|
193 |
|
180
|
194 |
activeProcess := Processor activeProcess.
|
|
195 |
" caching the last value ..."
|
|
196 |
activeProcess == LastActive ifTrue:[
|
|
197 |
LastActiveGroup process == LastActive ifTrue:[
|
|
198 |
^ LastActiveGroup
|
|
199 |
]
|
|
200 |
].
|
|
201 |
groups := self scheduledWindowGroups
|
|
202 |
select:[:wg | wg process == activeProcess].
|
|
203 |
groups size == 1 ifTrue:[
|
|
204 |
wg := groups anElement
|
|
205 |
] ifFalse:[
|
|
206 |
wg := groups detect:[:wg | wg isModal] ifNone:nil.
|
|
207 |
wg isNil ifTrue:[
|
|
208 |
wg := groups anElement
|
|
209 |
]
|
|
210 |
].
|
|
211 |
wg notNil ifTrue:[
|
|
212 |
LastActiveProcess := activeProcess.
|
|
213 |
LastActiveGroup := wg.
|
|
214 |
].
|
|
215 |
^ wg
|
|
216 |
|
|
217 |
"
|
|
218 |
WindowGroup activeGroup
|
|
219 |
"
|
|
220 |
|
|
221 |
"Modified: 3.9.1995 / 14:49:53 / claus"
|
54
|
222 |
!
|
|
223 |
|
152
|
224 |
setActiveGroup:aGroup
|
|
225 |
"set the currently active windowGroup.
|
|
226 |
Temporary; do not use this interface, it will vanish."
|
|
227 |
|
180
|
228 |
LastActiveProcess := Processor activeProcess.
|
|
229 |
LastActiveGroup := aGroup
|
152
|
230 |
!
|
|
231 |
|
54
|
232 |
scheduledWindowGroups
|
180
|
233 |
"return a collection of all windowGroups (possibly for different
|
|
234 |
display devices) which are scheduled (i.e. which have a process
|
|
235 |
running, handling events)."
|
|
236 |
|
|
237 |
|set screens|
|
|
238 |
|
|
239 |
screens := Screen allScreens.
|
|
240 |
screens isNil ifTrue:[^ #()].
|
|
241 |
|
|
242 |
set := IdentitySet new.
|
|
243 |
screens do:[:aDevice |
|
|
244 |
aDevice allViewsDo:[:aView |
|
|
245 |
|wg|
|
109
|
246 |
|
180
|
247 |
(wg := aView windowGroup) notNil ifTrue:[
|
|
248 |
wg process notNil ifTrue:[
|
|
249 |
set add:wg
|
|
250 |
]
|
|
251 |
].
|
|
252 |
].
|
|
253 |
].
|
|
254 |
^ set asArray
|
|
255 |
|
|
256 |
"
|
|
257 |
WindowGroup scheduledWindowGroups
|
|
258 |
"
|
|
259 |
|
|
260 |
"Modified: 1.9.1995 / 13:43:09 / claus"
|
26
|
261 |
! !
|
|
262 |
|
11
|
263 |
!WindowGroup methodsFor:'accessing'!
|
|
264 |
|
26
|
265 |
sensor
|
|
266 |
"return the windowGroups sensor"
|
|
267 |
|
|
268 |
^ mySensor
|
|
269 |
!
|
|
270 |
|
11
|
271 |
addView:aView
|
26
|
272 |
"add aView to the windowGroup"
|
|
273 |
|
11
|
274 |
views isNil ifTrue:[
|
72
|
275 |
views := OrderedCollection new.
|
11
|
276 |
].
|
|
277 |
views add:aView
|
|
278 |
!
|
|
279 |
|
54
|
280 |
addTopView:aView
|
|
281 |
"add a topview to the group"
|
|
282 |
|
|
283 |
topViews isNil ifTrue:[
|
72
|
284 |
topViews := OrderedCollection new.
|
54
|
285 |
].
|
|
286 |
topViews add:aView
|
|
287 |
!
|
|
288 |
|
26
|
289 |
removeView:aView
|
|
290 |
"remove aView from the windowGroup;
|
|
291 |
if this was the last view in this group,
|
81
|
292 |
also shut down the corresponding process
|
|
293 |
(actually, only wake it up here - it will terminate itself
|
|
294 |
when finding out that all views are gone)"
|
11
|
295 |
|
|
296 |
views notNil ifTrue:[
|
72
|
297 |
views remove:aView ifAbsent:[].
|
|
298 |
views isEmpty ifTrue:[
|
|
299 |
views := nil
|
|
300 |
]
|
11
|
301 |
].
|
|
302 |
topViews notNil ifTrue:[
|
72
|
303 |
topViews remove:aView ifAbsent:[].
|
|
304 |
topViews isEmpty ifTrue:[
|
|
305 |
topViews := nil
|
|
306 |
]
|
11
|
307 |
].
|
54
|
308 |
"
|
|
309 |
wakeup my process to look if last view has been
|
|
310 |
removed (and terminate if so)
|
|
311 |
"
|
81
|
312 |
mySensor notNil ifTrue:[mySensor eventSemaphore signal]
|
11
|
313 |
!
|
|
314 |
|
|
315 |
views
|
26
|
316 |
"return the views accociated to this windowGroup"
|
|
317 |
|
11
|
318 |
^ views
|
|
319 |
!
|
|
320 |
|
46
|
321 |
topViews
|
|
322 |
"return the topviews accociated to this windowGroup"
|
|
323 |
|
|
324 |
^ topViews
|
|
325 |
!
|
|
326 |
|
11
|
327 |
process
|
26
|
328 |
"return the windowGroups process"
|
|
329 |
|
11
|
330 |
^ myProcess
|
|
331 |
!
|
|
332 |
|
54
|
333 |
isModal
|
103
|
334 |
"return true, if I am in a modal mode"
|
|
335 |
|
54
|
336 |
^ isModal
|
|
337 |
!
|
|
338 |
|
|
339 |
previousGroup
|
|
340 |
"return the windowgroup that started this group.
|
|
341 |
(for modal groups only)"
|
|
342 |
|
|
343 |
^ previousGroup
|
|
344 |
!
|
|
345 |
|
|
346 |
mainGroup
|
180
|
347 |
"return the main windowgroup
|
|
348 |
(that is the top one, which is not modal).
|
|
349 |
There is one exception to this: the debugger (which is sort of modal)
|
|
350 |
returns itself as mainGroup (not its debuggee)."
|
54
|
351 |
|
180
|
352 |
|g prev|
|
54
|
353 |
|
|
354 |
g := self.
|
180
|
355 |
[g notNil and:[g isModal and:[(prev := g previousGroup) notNil]]] whileTrue:[
|
|
356 |
g := prev
|
54
|
357 |
].
|
|
358 |
^ g
|
180
|
359 |
|
|
360 |
"Modified: 3.9.1995 / 14:57:20 / claus"
|
54
|
361 |
!
|
|
362 |
|
11
|
363 |
sensor:aSensor
|
26
|
364 |
"set the windowGroups sensor"
|
|
365 |
|
11
|
366 |
mySensor := aSensor
|
172
|
367 |
!
|
|
368 |
|
|
369 |
preEventHook:anObject
|
|
370 |
"set the preEventHook - this one will get all events
|
|
371 |
passed before being processed here (via #processEvent:).
|
|
372 |
If this returns true, the event is supposed to be already
|
|
373 |
processed and ignored here.
|
|
374 |
Otherwise, it is processed as usual."
|
|
375 |
|
|
376 |
preEventHook := anObject
|
|
377 |
!
|
|
378 |
|
|
379 |
postEventHook:anObject
|
|
380 |
"set the postEventHook - this one will get all events
|
|
381 |
passed after being processed here (via #processEvent:)."
|
|
382 |
|
|
383 |
postEventHook := anObject
|
54
|
384 |
! !
|
|
385 |
|
180
|
386 |
!WindowGroup methodsFor:'special accessing'!
|
|
387 |
|
|
388 |
setPreviousGroup:aGroup
|
|
389 |
"special entry for debugger:
|
|
390 |
set the windowgroup that started this group (for modal groups only).
|
|
391 |
This is not a public interface."
|
|
392 |
|
|
393 |
previousGroup := aGroup
|
|
394 |
|
|
395 |
"Modified: 3.9.1995 / 14:55:40 / claus"
|
|
396 |
!
|
|
397 |
|
|
398 |
setModal:aBoolean
|
|
399 |
"special entry for debugger: set the modal flag.
|
|
400 |
Not for public use"
|
|
401 |
|
|
402 |
isModal := aBoolean
|
|
403 |
|
|
404 |
"Modified: 3.9.1995 / 14:51:04 / claus"
|
|
405 |
!
|
|
406 |
|
|
407 |
setProcess:aProcess
|
|
408 |
"special entry for debugger: set the windowGroups process.
|
|
409 |
Not for public use."
|
|
410 |
|
|
411 |
myProcess := aProcess
|
|
412 |
|
|
413 |
"Modified: 3.9.1995 / 14:25:38 / claus"
|
|
414 |
! !
|
|
415 |
|
90
|
416 |
!WindowGroup methodsFor:'enumerating'!
|
54
|
417 |
|
|
418 |
allViewsDo:aBlock
|
157
|
419 |
"evaluate aBlock for all views & topviews in this group.
|
|
420 |
This works on a copy of the view collection, to allow for
|
158
|
421 |
destroy and other collection changing operations to be done."
|
54
|
422 |
|
157
|
423 |
topViews notNil ifTrue:[topViews copy do:aBlock].
|
|
424 |
views notNil ifTrue:[views copy do:aBlock]
|
54
|
425 |
!
|
|
426 |
|
|
427 |
allTopViewsExcept:aView do:aBlock
|
157
|
428 |
"evaluate aBlock for all topviews except aView in this group.
|
|
429 |
This works on a copy of the view collection, to allow for
|
158
|
430 |
destroy and other collection changing operations to be done."
|
157
|
431 |
|
|
432 |
topViews notNil ifTrue:[
|
|
433 |
topViews copy do:[:v |
|
|
434 |
v ~~ aView ifTrue:[aBlock value:v]
|
|
435 |
]
|
|
436 |
].
|
|
437 |
!
|
|
438 |
|
|
439 |
slavesDo:aBlock
|
|
440 |
"evaluate aBlock for all slaveViews.
|
|
441 |
This works on a copy of the view collection, to allow for
|
158
|
442 |
destroy and other collection changing operations to be done."
|
54
|
443 |
|
|
444 |
topViews notNil ifTrue:[
|
157
|
445 |
topViews copy do:[:v |
|
|
446 |
v notNil ifTrue:[
|
|
447 |
v type == #slave ifTrue:[aBlock value:v].
|
|
448 |
]
|
|
449 |
]
|
|
450 |
].
|
|
451 |
!
|
|
452 |
|
|
453 |
partnersDo:aBlock
|
|
454 |
"evaluate aBlock for all partnerViews.
|
|
455 |
This works on a copy of the view collection, to allow for
|
158
|
456 |
destroy and other collection changing operations to be done."
|
157
|
457 |
|
|
458 |
topViews notNil ifTrue:[
|
|
459 |
topViews copy do:[:v |
|
|
460 |
v notNil ifTrue:[
|
|
461 |
v type == #partner ifTrue:[aBlock value:v].
|
|
462 |
]
|
72
|
463 |
]
|
54
|
464 |
].
|
|
465 |
! !
|
|
466 |
|
|
467 |
!WindowGroup methodsFor:'special'!
|
|
468 |
|
|
469 |
showCursor:aCursor
|
144
|
470 |
"change the cursor to aCursor in all of my views."
|
54
|
471 |
|
|
472 |
|c|
|
|
473 |
|
|
474 |
c := aCursor.
|
|
475 |
self allViewsDo:[:aView |
|
72
|
476 |
c := c on:(aView device).
|
|
477 |
aView device setCursor:c id in:aView id.
|
54
|
478 |
].
|
11
|
479 |
!
|
|
480 |
|
54
|
481 |
restoreCursors
|
|
482 |
"restore the original cursors in all of my views"
|
|
483 |
|
|
484 |
|c|
|
|
485 |
|
|
486 |
self allViewsDo:[:aView |
|
72
|
487 |
c := aView cursor on:(aView device).
|
|
488 |
aView device setCursor:(c id) in:(aView id).
|
11
|
489 |
].
|
54
|
490 |
!
|
|
491 |
|
|
492 |
withCursor:aCursor do:aBlock
|
|
493 |
"evaluate aBlock while showing aCursor in all
|
160
|
494 |
my views (used to show wait-cursor while doing something).
|
|
495 |
Return the result as returned by aBlock."
|
54
|
496 |
|
|
497 |
|oldCursors|
|
|
498 |
|
72
|
499 |
"
|
|
500 |
get mapping of view->cursor for all of my subviews
|
|
501 |
"
|
54
|
502 |
oldCursors := IdentityDictionary new.
|
|
503 |
self allViewsDo:[:aView |
|
72
|
504 |
oldCursors at:aView put:(aView cursor).
|
|
505 |
aView cursor:aCursor
|
54
|
506 |
].
|
|
507 |
|
160
|
508 |
^ aBlock valueNowOrOnUnwindDo:[
|
72
|
509 |
"
|
144
|
510 |
restore cursors from the mapping
|
72
|
511 |
"
|
|
512 |
oldCursors keysAndValuesDo:[:view :cursor |
|
|
513 |
view cursor:cursor
|
|
514 |
]
|
54
|
515 |
]
|
11
|
516 |
! !
|
|
517 |
|
19
|
518 |
!WindowGroup methodsFor:'event handling'!
|
11
|
519 |
|
103
|
520 |
processEvents
|
|
521 |
"process events from either the damage- or user input queues.
|
|
522 |
Abort is assumed to be handled elsewhere."
|
19
|
523 |
|
90
|
524 |
|event ignore|
|
11
|
525 |
|
72
|
526 |
self processExposeEvents.
|
180
|
527 |
|
72
|
528 |
[mySensor hasEvents] whileTrue:[
|
|
529 |
event := mySensor nextEvent.
|
90
|
530 |
event notNil ifTrue:[
|
112
|
531 |
(views notNil or:[topViews notNil]) ifTrue:[
|
90
|
532 |
ignore := false.
|
172
|
533 |
|
|
534 |
(preEventHook notNil
|
|
535 |
and:[preEventHook processEvent:event]) ifTrue:[
|
|
536 |
ignore := true.
|
90
|
537 |
].
|
|
538 |
ignore ifFalse:[
|
103
|
539 |
"/
|
172
|
540 |
"/ FocusStepping is done right here
|
103
|
541 |
"/
|
172
|
542 |
event isKeyPressEvent ifTrue:[
|
|
543 |
event key == #FocusNext ifTrue:[
|
|
544 |
self focusNext.
|
|
545 |
ignore := true
|
|
546 |
].
|
|
547 |
event key == #FocusPrevious ifTrue:[
|
|
548 |
self focusPrevious.
|
|
549 |
ignore := true
|
|
550 |
].
|
103
|
551 |
].
|
172
|
552 |
ignore ifFalse:[
|
|
553 |
"/
|
|
554 |
"/ button events turn off explicit focus, and revert
|
|
555 |
"/ to implicit focus control
|
|
556 |
"/
|
|
557 |
(focusView notNil
|
|
558 |
and:[event isButtonEvent]) ifTrue:[
|
|
559 |
self focusView:nil
|
|
560 |
].
|
|
561 |
"/
|
|
562 |
"/ let the event forward itself
|
|
563 |
"/
|
180
|
564 |
LastActiveGroup := self.
|
|
565 |
LastActiveProcess := Processor activeProcess.
|
172
|
566 |
event sendEventWithFocusOn:focusView.
|
|
567 |
]
|
|
568 |
].
|
|
569 |
postEventHook notNil ifTrue:[
|
|
570 |
postEventHook processEvent:event
|
90
|
571 |
]
|
|
572 |
]
|
72
|
573 |
].
|
|
574 |
]
|
48
|
575 |
!
|
|
576 |
|
|
577 |
processExposeEvents
|
103
|
578 |
"process only expose events from the damage queue"
|
48
|
579 |
|
180
|
580 |
|event view rect x y w h sensor thisProcess|
|
109
|
581 |
|
|
582 |
(sensor := mySensor) isNil ifTrue:[^ self].
|
48
|
583 |
|
180
|
584 |
thisProcess := Processor activeProcess.
|
|
585 |
|
|
586 |
[sensor hasDamage] whileTrue:[
|
|
587 |
LastActiveGroup := self.
|
|
588 |
LastActiveProcess := thisProcess.
|
|
589 |
|
|
590 |
event := sensor nextDamage.
|
|
591 |
event notNil ifTrue:[
|
|
592 |
(views notNil or:[topViews notNil]) ifTrue:[
|
|
593 |
(preEventHook notNil
|
|
594 |
and:[preEventHook processEvent:event]) ifFalse:[
|
|
595 |
event isDamage ifTrue:[
|
|
596 |
view := event view.
|
|
597 |
"/
|
|
598 |
"/ if the view is no longer shown (iconified or closed),
|
|
599 |
"/ this is a leftover event and ignored.
|
|
600 |
"/
|
|
601 |
view shown ifTrue:[
|
|
602 |
rect := event rectangle.
|
|
603 |
x := rect left.
|
|
604 |
y := rect top.
|
|
605 |
w := rect width.
|
|
606 |
h := rect height.
|
|
607 |
LastActiveGroup := self.
|
|
608 |
LastActiveProcess := thisProcess.
|
|
609 |
view transformation notNil ifTrue:[
|
|
610 |
view deviceExposeX:x y:y width:w height:h
|
|
611 |
] ifFalse:[
|
|
612 |
view exposeX:x y:y width:w height:h
|
172
|
613 |
]
|
81
|
614 |
]
|
180
|
615 |
] ifFalse:[
|
|
616 |
"
|
|
617 |
mhmh - could we possibly arrive here ?
|
|
618 |
"
|
|
619 |
LastActiveGroup := self.
|
|
620 |
LastActiveProcess := thisProcess.
|
|
621 |
event sendEvent.
|
78
|
622 |
]
|
180
|
623 |
].
|
|
624 |
postEventHook notNil ifTrue:[
|
|
625 |
postEventHook processEvent:event
|
72
|
626 |
]
|
|
627 |
]
|
|
628 |
]
|
90
|
629 |
]
|
11
|
630 |
!
|
|
631 |
|
19
|
632 |
eventLoop
|
|
633 |
"loop executed by windowGroup process;
|
|
634 |
wait-for and process events forever"
|
|
635 |
|
135
|
636 |
self eventLoopWhile:[true] onLeave:[]
|
23
|
637 |
!
|
|
638 |
|
135
|
639 |
eventLoopWhile:aBlock onLeave:cleanupActions
|
90
|
640 |
"wait-for and process events.
|
|
641 |
Stay in this loop while there are still any views to dispatch for,
|
|
642 |
and aBlock evaluates to true."
|
78
|
643 |
|
180
|
644 |
|thisProcess|
|
78
|
645 |
|
180
|
646 |
thisProcess := Processor activeProcess.
|
|
647 |
|
109
|
648 |
[
|
|
649 |
"/
|
|
650 |
"/ on leave, exit the event loop
|
|
651 |
"/
|
|
652 |
LeaveSignal handle:[:ex |
|
90
|
653 |
ex return
|
|
654 |
] do:[
|
180
|
655 |
|p g mainGroup|
|
54
|
656 |
|
90
|
657 |
isModal ifTrue:[
|
|
658 |
mainGroup := self mainGroup.
|
72
|
659 |
].
|
90
|
660 |
|
180
|
661 |
aBlock whileTrue:[
|
|
662 |
LastActiveGroup := self.
|
|
663 |
LastActiveProcess := thisProcess.
|
103
|
664 |
|
90
|
665 |
(views isNil and:[topViews isNil]) ifTrue:[
|
|
666 |
myProcess notNil ifTrue:[
|
|
667 |
p := myProcess.
|
|
668 |
myProcess := nil.
|
|
669 |
p terminate.
|
|
670 |
"not reached - there is no life after death"
|
103
|
671 |
].
|
|
672 |
"
|
|
673 |
this is the end of a modal loop
|
|
674 |
(not having a private process ...)
|
|
675 |
"
|
|
676 |
^ self
|
72
|
677 |
].
|
|
678 |
|
103
|
679 |
"/
|
|
680 |
"/ on abort, stay in the event loop
|
|
681 |
"/
|
90
|
682 |
AbortSignal handle:[:ex |
|
|
683 |
ex return
|
|
684 |
] do:[
|
|
685 |
"
|
|
686 |
if modal, break out of the wait after some time
|
|
687 |
to allow servicing update-events of the blocked
|
|
688 |
windowgroup.
|
|
689 |
"
|
103
|
690 |
thisProcess setStateTo:#eventWait if:#active.
|
90
|
691 |
isModal ifTrue:[
|
|
692 |
mySensor eventSemaphore waitWithTimeout:0.2.
|
|
693 |
] ifFalse:[
|
|
694 |
mySensor eventSemaphore wait.
|
|
695 |
].
|
180
|
696 |
LastActiveGroup := self.
|
|
697 |
LastActiveProcess := thisProcess.
|
162
|
698 |
self processEvents.
|
90
|
699 |
].
|
|
700 |
|
|
701 |
"
|
|
702 |
if modal, also check for redraw events in my maingroup
|
|
703 |
(we arrive here after every event for myself or after the
|
|
704 |
above timeout)
|
|
705 |
"
|
|
706 |
mainGroup notNil ifTrue:[
|
|
707 |
mainGroup processExposeEvents.
|
|
708 |
]
|
103
|
709 |
].
|
90
|
710 |
].
|
109
|
711 |
] valueNowOrOnUnwindDo:[
|
135
|
712 |
cleanupActions notNil ifTrue:[cleanupActions value]
|
109
|
713 |
]
|
28
|
714 |
!
|
|
715 |
|
|
716 |
waitForExposeFor:aView
|
|
717 |
"wait for a noExpose on aView, then process all exposes.
|
|
718 |
To be used after a scroll"
|
|
719 |
|
|
720 |
mySensor waitForExposeFor:aView.
|
90
|
721 |
AbortSignal catch:[
|
|
722 |
self processExposeEvents
|
|
723 |
]
|
46
|
724 |
!
|
|
725 |
|
|
726 |
leaveEventLoop
|
103
|
727 |
"immediately leave the event loop, returning way back.
|
|
728 |
This can be used to leave (and closedown) a modal group.
|
|
729 |
(for normal views, this does not make sense)"
|
|
730 |
|
65
|
731 |
^ LeaveSignal raise
|
19
|
732 |
! !
|
|
733 |
|
|
734 |
!WindowGroup methodsFor:'activation / deactivation'!
|
|
735 |
|
135
|
736 |
realizeTopViews:isRestart
|
140
|
737 |
"realize all topViews associated to this windowGroup.
|
|
738 |
If this is a restart, tell topViews about it."
|
135
|
739 |
|
|
740 |
topViews notNil ifTrue:[
|
|
741 |
topViews do:[:aView |
|
|
742 |
aView realize.
|
140
|
743 |
isRestart ifTrue:[
|
|
744 |
aView restarted
|
|
745 |
]
|
135
|
746 |
].
|
|
747 |
].
|
|
748 |
!
|
|
749 |
|
46
|
750 |
restart
|
54
|
751 |
"restart after a snapin."
|
46
|
752 |
|
48
|
753 |
topViews notNil ifTrue:[
|
72
|
754 |
"
|
|
755 |
need a new semaphore, since obsolete processes
|
|
756 |
(from our previous live) may still sit on the current semaphore
|
|
757 |
"
|
|
758 |
mySensor eventSemaphore:Semaphore new.
|
|
759 |
isModal ifFalse:[
|
135
|
760 |
self startup:true
|
72
|
761 |
]
|
48
|
762 |
]
|
46
|
763 |
!
|
|
764 |
|
135
|
765 |
startup:isRestart
|
19
|
766 |
"startup the window-group;
|
|
767 |
this creates a new window group process, which
|
|
768 |
does the event processing."
|
|
769 |
|
152
|
770 |
|top nm dev devNm|
|
|
771 |
|
54
|
772 |
previousGroup := nil.
|
11
|
773 |
myProcess isNil ifTrue:[
|
72
|
774 |
isModal := false.
|
|
775 |
myProcess := [
|
135
|
776 |
self realizeTopViews:isRestart.
|
|
777 |
self eventLoopWhile:[true] onLeave:[]
|
72
|
778 |
] forkAt:Processor userSchedulingPriority.
|
19
|
779 |
|
72
|
780 |
(topViews notNil and:[topViews isEmpty not]) ifTrue:[
|
152
|
781 |
"
|
|
782 |
give the handler process a user friendly name
|
|
783 |
"
|
|
784 |
top := topViews first.
|
|
785 |
nm := top processName.
|
|
786 |
(dev := top device) notNil ifTrue:[
|
|
787 |
devNm := dev displayName.
|
|
788 |
devNm notNil ifTrue:[
|
|
789 |
nm := nm , ' (' , devNm , ')'
|
|
790 |
]
|
|
791 |
]
|
72
|
792 |
] ifFalse:[
|
152
|
793 |
nm := 'window handler'.
|
72
|
794 |
].
|
152
|
795 |
myProcess name:nm.
|
19
|
796 |
|
72
|
797 |
"when the process dies, we have to close-down
|
|
798 |
the views as well
|
|
799 |
"
|
|
800 |
myProcess exitAction:[self closeDownViews]
|
11
|
801 |
]
|
|
802 |
!
|
|
803 |
|
48
|
804 |
startupModal:checkBlock
|
|
805 |
"startup the window-group in a modal loop (i.e. under the
|
|
806 |
currently running process);
|
|
807 |
checkBlock is evaluated and loop is left, when false is
|
|
808 |
returned."
|
|
809 |
|
54
|
810 |
"set previousGroup to the main (non-modal) group"
|
|
811 |
|
|
812 |
previousGroup := WindowGroup activeGroup.
|
|
813 |
isModal := true.
|
135
|
814 |
self realizeTopViews:false.
|
|
815 |
self
|
|
816 |
eventLoopWhile:checkBlock
|
|
817 |
onLeave:[
|
|
818 |
"
|
|
819 |
cleanup, in case of a terminate
|
|
820 |
"
|
|
821 |
previousGroup := nil.
|
|
822 |
topViews := nil.
|
|
823 |
views := nil.
|
|
824 |
"
|
|
825 |
the following is rubbish;
|
|
826 |
the views could be reused ..
|
|
827 |
"
|
86
|
828 |
"
|
135
|
829 |
topViews notNil ifTrue:[
|
|
830 |
topViews do:[:aView |
|
|
831 |
aView destroy
|
|
832 |
].
|
|
833 |
topViews := nil.
|
81
|
834 |
].
|
135
|
835 |
views notNil ifTrue:[
|
|
836 |
views do:[:aView |
|
|
837 |
aView destroy
|
|
838 |
].
|
|
839 |
views := nil.
|
86
|
840 |
].
|
|
841 |
"
|
135
|
842 |
]
|
48
|
843 |
!
|
|
844 |
|
19
|
845 |
closeDownViews
|
|
846 |
"destroy all views associated to this window group"
|
|
847 |
|
11
|
848 |
topViews notNil ifTrue:[
|
72
|
849 |
topViews do:[:aTopView | aTopView destroy]
|
11
|
850 |
].
|
|
851 |
views := nil.
|
|
852 |
topViews := nil.
|
107
|
853 |
mySensor := nil.
|
19
|
854 |
!
|
|
855 |
|
|
856 |
shutdown
|
|
857 |
"shutdow the window group; close all views and
|
|
858 |
terminate process"
|
|
859 |
|
46
|
860 |
|p|
|
|
861 |
|
19
|
862 |
self closeDownViews.
|
11
|
863 |
myProcess notNil ifTrue:[
|
72
|
864 |
p := myProcess.
|
|
865 |
myProcess := nil.
|
|
866 |
p terminate.
|
11
|
867 |
]
|
|
868 |
! !
|
|
869 |
|
|
870 |
!WindowGroup methodsFor:'initialization'!
|
|
871 |
|
|
872 |
reinitialize
|
72
|
873 |
"reinitialize the windowgroup after an image restart"
|
|
874 |
|
19
|
875 |
"throw away old (zombie) process"
|
72
|
876 |
myProcess notNil ifTrue:[
|
|
877 |
"careful: the old processes exitaction must be cleared
|
|
878 |
otherwise, it might do destroy or other actions when it
|
|
879 |
gets finalized ...
|
|
880 |
"
|
|
881 |
myProcess exitAction:nil.
|
|
882 |
myProcess := nil.
|
|
883 |
].
|
19
|
884 |
|
11
|
885 |
"throw away old events"
|
54
|
886 |
mySensor reinitialize
|
11
|
887 |
!
|
|
888 |
|
|
889 |
initialize
|
19
|
890 |
"setup the windowgroup, by creating a new sensor
|
|
891 |
and an event semaphore"
|
|
892 |
|
11
|
893 |
mySensor := WindowSensor new.
|
72
|
894 |
mySensor eventSemaphore:Semaphore new.
|
|
895 |
isModal := false.
|
11
|
896 |
! !
|
19
|
897 |
|
90
|
898 |
!WindowGroup methodsFor:'focus control'!
|
|
899 |
|
135
|
900 |
focusSequence
|
|
901 |
"return the focus sequence for focusNext/focusPrevious.
|
|
902 |
Focus is stepped in the order in which subviews occur in
|
|
903 |
the sequence"
|
|
904 |
|
|
905 |
^ focusSequence
|
|
906 |
!
|
|
907 |
|
90
|
908 |
focusSequence:aSequenceableCollection
|
|
909 |
"define the focus sequence for focusNext/focusPrevious.
|
|
910 |
Focus is stepped in the order in which subviews occur in
|
|
911 |
the sequence"
|
|
912 |
|
|
913 |
focusSequence := aSequenceableCollection
|
|
914 |
!
|
|
915 |
|
|
916 |
focusView
|
135
|
917 |
"return the view which currently has the focus"
|
90
|
918 |
|
|
919 |
^ focusView
|
|
920 |
!
|
|
921 |
|
|
922 |
focusView:aViewOrNil
|
|
923 |
"give focus to aViewOrNil"
|
|
924 |
|
|
925 |
focusView notNil ifTrue:[
|
|
926 |
focusView focusOut.
|
|
927 |
].
|
|
928 |
focusView := aViewOrNil.
|
|
929 |
focusView notNil ifTrue:[
|
|
930 |
focusView focusIn
|
|
931 |
].
|
|
932 |
|
|
933 |
"
|
|
934 |
|top v1 v2|
|
|
935 |
|
|
936 |
top := StandardSystemView new.
|
|
937 |
v1 := EditTextView origin:0.0@0.0 corner:1.0@0.5 in:top.
|
|
938 |
v2 := EditTextView origin:0.0@0.5 corner:1.0@1.0 in:top.
|
|
939 |
top open.
|
|
940 |
top windowGroup focusView:v1.
|
|
941 |
"
|
|
942 |
!
|
|
943 |
|
|
944 |
focusNext
|
|
945 |
"give focus to next view in focusSequence"
|
|
946 |
|
|
947 |
|index|
|
|
948 |
|
157
|
949 |
focusSequence size == 0 ifTrue:[^ self].
|
90
|
950 |
focusView notNil ifTrue:[
|
|
951 |
index := (focusSequence indexOf:focusView) + 1.
|
|
952 |
index > focusSequence size ifTrue:[index := 1].
|
|
953 |
] ifFalse:[
|
|
954 |
index := 1.
|
|
955 |
].
|
|
956 |
self focusView:(focusSequence at:index)
|
|
957 |
|
|
958 |
"
|
|
959 |
|top v1 v2|
|
|
960 |
|
|
961 |
top := StandardSystemView new.
|
|
962 |
v1 := EditTextView origin:0.0@0.0 corner:1.0@0.5 in:top.
|
|
963 |
v2 := EditTextView origin:0.0@0.5 corner:1.0@1.0 in:top.
|
|
964 |
top open.
|
|
965 |
top windowGroup focusSequence:(Array with:v1 with:v2).
|
|
966 |
top windowGroup focusOn:v1.
|
|
967 |
(Delay forSeconds:10) wait.
|
|
968 |
top windowGroup focusNext.
|
|
969 |
"
|
|
970 |
!
|
|
971 |
|
|
972 |
focusPrevious
|
|
973 |
"give focus to previous view in focusSequence"
|
|
974 |
|
|
975 |
|index|
|
|
976 |
|
157
|
977 |
focusSequence size == 0 ifTrue:[^ self].
|
90
|
978 |
focusView notNil ifTrue:[
|
|
979 |
index := (focusSequence indexOf:focusView) - 1.
|
|
980 |
index < 1 ifTrue:[index := focusSequence size].
|
|
981 |
] ifFalse:[
|
|
982 |
index := focusSequence size.
|
|
983 |
].
|
|
984 |
self focusView:(focusSequence at:index)
|
|
985 |
! !
|
|
986 |
|
19
|
987 |
!WindowGroup methodsFor:'printing'!
|
|
988 |
|
90
|
989 |
printOn:aStream
|
19
|
990 |
"return a printed representation;
|
144
|
991 |
just for more user friendlyness: add name of process."
|
19
|
992 |
|
90
|
993 |
myProcess isNil ifTrue:[
|
|
994 |
(previousGroup notNil and:[previousGroup process notNil]) ifTrue:[
|
|
995 |
aStream nextPutAll:('WindowGroup(modal in ' , previousGroup process nameOrId , ')').
|
|
996 |
^ self.
|
|
997 |
].
|
|
998 |
^ super printOn:aStream
|
|
999 |
].
|
|
1000 |
aStream nextPutAll:('WindowGroup(' , myProcess nameOrId , ')')
|
19
|
1001 |
! !
|