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
|
72
|
14 |
instanceVariableNames:'views topViews myProcess mySensor isModal previousGroup'
|
|
15 |
classVariableNames:'ActiveGroup ScheduledWindowGroups LeaveSignal'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Interface-Support'
|
11
|
18 |
!
|
|
19 |
|
54
|
20 |
WindowGroup comment:'
|
|
21 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
22 |
All Rights Reserved
|
54
|
23 |
|
85
|
24 |
$Header: /cvs/stx/stx/libview/WindowGroup.st,v 1.15 1994-11-22 23:09:16 claus Exp $
|
54
|
25 |
'!
|
|
26 |
|
46
|
27 |
!WindowGroup class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
32 |
All Rights Reserved
|
46
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
85
|
45 |
$Header: /cvs/stx/stx/libview/WindowGroup.st,v 1.15 1994-11-22 23:09:16 claus Exp $
|
46
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
"
|
|
52 |
! !
|
|
53 |
|
54
|
54 |
!WindowGroup class methodsFor:'initialization'!
|
46
|
55 |
|
|
56 |
initialize
|
|
57 |
LeaveSignal isNil ifTrue:[
|
72
|
58 |
LeaveSignal := (Signal new) mayProceed:true.
|
|
59 |
LeaveSignal nameClass:self message:#leaveSignal.
|
|
60 |
LeaveSignal notifierString:'unhandled leave signal'.
|
|
61 |
"/ ScheduledWindowGroups := IdentitySet new.
|
54
|
62 |
].
|
46
|
63 |
|
|
64 |
"WindowGroup initialize"
|
|
65 |
! !
|
|
66 |
|
72
|
67 |
!WindowGroup class methodsFor:'signal access'!
|
|
68 |
|
|
69 |
leaveSignal
|
|
70 |
^ LeaveSignal
|
|
71 |
! !
|
|
72 |
|
11
|
73 |
!WindowGroup class methodsFor:'instance creation'!
|
|
74 |
|
|
75 |
new
|
26
|
76 |
"create and return a new WindowGroup object"
|
|
77 |
|
11
|
78 |
^ self basicNew initialize
|
|
79 |
! !
|
|
80 |
|
26
|
81 |
!WindowGroup class methodsFor:'accessing'!
|
|
82 |
|
|
83 |
activeGroup
|
|
84 |
"return the currently active windowGroup"
|
|
85 |
|
|
86 |
^ ActiveGroup
|
54
|
87 |
!
|
|
88 |
|
|
89 |
scheduledWindowGroups
|
|
90 |
^ ScheduledWindowGroups
|
26
|
91 |
! !
|
|
92 |
|
11
|
93 |
!WindowGroup methodsFor:'accessing'!
|
|
94 |
|
26
|
95 |
sensor
|
|
96 |
"return the windowGroups sensor"
|
|
97 |
|
|
98 |
^ mySensor
|
|
99 |
!
|
|
100 |
|
11
|
101 |
addView:aView
|
26
|
102 |
"add aView to the windowGroup"
|
|
103 |
|
11
|
104 |
views isNil ifTrue:[
|
72
|
105 |
views := OrderedCollection new.
|
11
|
106 |
].
|
|
107 |
views add:aView
|
|
108 |
!
|
|
109 |
|
54
|
110 |
addTopView:aView
|
|
111 |
"add a topview to the group"
|
|
112 |
|
|
113 |
topViews isNil ifTrue:[
|
72
|
114 |
topViews := OrderedCollection new.
|
54
|
115 |
].
|
|
116 |
topViews add:aView
|
|
117 |
!
|
|
118 |
|
26
|
119 |
removeView:aView
|
|
120 |
"remove aView from the windowGroup;
|
|
121 |
if this was the last view in this group,
|
81
|
122 |
also shut down the corresponding process
|
|
123 |
(actually, only wake it up here - it will terminate itself
|
|
124 |
when finding out that all views are gone)"
|
11
|
125 |
|
|
126 |
views notNil ifTrue:[
|
72
|
127 |
views remove:aView ifAbsent:[].
|
|
128 |
views isEmpty ifTrue:[
|
|
129 |
views := nil
|
|
130 |
]
|
11
|
131 |
].
|
|
132 |
topViews notNil ifTrue:[
|
72
|
133 |
topViews remove:aView ifAbsent:[].
|
|
134 |
topViews isEmpty ifTrue:[
|
|
135 |
topViews := nil
|
|
136 |
]
|
11
|
137 |
].
|
54
|
138 |
"
|
|
139 |
wakeup my process to look if last view has been
|
|
140 |
removed (and terminate if so)
|
|
141 |
"
|
81
|
142 |
mySensor notNil ifTrue:[mySensor eventSemaphore signal]
|
11
|
143 |
!
|
|
144 |
|
|
145 |
views
|
26
|
146 |
"return the views accociated to this windowGroup"
|
|
147 |
|
11
|
148 |
^ views
|
|
149 |
!
|
|
150 |
|
46
|
151 |
topViews
|
|
152 |
"return the topviews accociated to this windowGroup"
|
|
153 |
|
|
154 |
^ topViews
|
|
155 |
!
|
|
156 |
|
11
|
157 |
process
|
26
|
158 |
"return the windowGroups process"
|
|
159 |
|
11
|
160 |
^ myProcess
|
|
161 |
!
|
|
162 |
|
54
|
163 |
isModal
|
|
164 |
^ isModal
|
|
165 |
!
|
|
166 |
|
|
167 |
previousGroup
|
|
168 |
"return the windowgroup that started this group.
|
|
169 |
(for modal groups only)"
|
|
170 |
|
|
171 |
^ previousGroup
|
|
172 |
!
|
|
173 |
|
|
174 |
mainGroup
|
|
175 |
"return the main windowgroup (that is the top one,
|
|
176 |
which is not modal)"
|
|
177 |
|
|
178 |
|g|
|
|
179 |
|
|
180 |
g := self.
|
|
181 |
[g notNil and:[g isModal]] whileTrue:[
|
72
|
182 |
g := g previousGroup
|
54
|
183 |
].
|
|
184 |
^ g
|
|
185 |
!
|
|
186 |
|
11
|
187 |
sensor:aSensor
|
26
|
188 |
"set the windowGroups sensor"
|
|
189 |
|
11
|
190 |
mySensor := aSensor
|
54
|
191 |
! !
|
|
192 |
|
|
193 |
!WindowGroup methodsFor:'enumeration'!
|
|
194 |
|
|
195 |
allViewsDo:aBlock
|
|
196 |
"evaluate aBlock for all views & topviews in this group"
|
|
197 |
|
|
198 |
topViews notNil ifTrue:[topViews do:aBlock].
|
|
199 |
views notNil ifTrue:[views do:aBlock]
|
|
200 |
!
|
|
201 |
|
|
202 |
allTopViewsExcept:aView do:aBlock
|
|
203 |
"evaluate aBlock for all topviews except aView in this group"
|
|
204 |
|
|
205 |
topViews notNil ifTrue:[
|
72
|
206 |
topViews do:[:v |
|
|
207 |
v ~~ aView ifTrue:[aBlock value:v]
|
|
208 |
]
|
54
|
209 |
].
|
|
210 |
! !
|
|
211 |
|
|
212 |
!WindowGroup methodsFor:'special'!
|
|
213 |
|
|
214 |
showCursor:aCursor
|
|
215 |
"change the cursor to aCursor in all of my views"
|
|
216 |
|
|
217 |
|c|
|
|
218 |
|
|
219 |
c := aCursor.
|
|
220 |
self allViewsDo:[:aView |
|
72
|
221 |
c := c on:(aView device).
|
|
222 |
aView device setCursor:c id in:aView id.
|
54
|
223 |
].
|
11
|
224 |
!
|
|
225 |
|
54
|
226 |
restoreCursors
|
|
227 |
"restore the original cursors in all of my views"
|
|
228 |
|
|
229 |
|c|
|
|
230 |
|
|
231 |
self allViewsDo:[:aView |
|
72
|
232 |
c := aView cursor on:(aView device).
|
|
233 |
aView device setCursor:(c id) in:(aView id).
|
11
|
234 |
].
|
54
|
235 |
!
|
|
236 |
|
|
237 |
withCursor:aCursor do:aBlock
|
|
238 |
"evaluate aBlock while showing aCursor in all
|
|
239 |
my views (used to show wait-cursor while doing something)"
|
|
240 |
|
|
241 |
|oldCursors|
|
|
242 |
|
72
|
243 |
"
|
|
244 |
get mapping of view->cursor for all of my subviews
|
|
245 |
"
|
54
|
246 |
oldCursors := IdentityDictionary new.
|
|
247 |
self allViewsDo:[:aView |
|
72
|
248 |
oldCursors at:aView put:(aView cursor).
|
|
249 |
aView cursor:aCursor
|
54
|
250 |
].
|
|
251 |
|
|
252 |
aBlock valueNowOrOnUnwindDo:[
|
72
|
253 |
"
|
|
254 |
restore cursors
|
|
255 |
"
|
|
256 |
oldCursors keysAndValuesDo:[:view :cursor |
|
|
257 |
view cursor:cursor
|
|
258 |
]
|
54
|
259 |
]
|
11
|
260 |
! !
|
|
261 |
|
19
|
262 |
!WindowGroup methodsFor:'event handling'!
|
11
|
263 |
|
19
|
264 |
processEvent
|
46
|
265 |
"process a single event from either the damage- or user input queues.
|
|
266 |
Debugger abort brings us back here."
|
19
|
267 |
|
72
|
268 |
|event|
|
11
|
269 |
|
72
|
270 |
self processExposeEvents.
|
|
271 |
[mySensor hasEvents] whileTrue:[
|
|
272 |
event := mySensor nextEvent.
|
|
273 |
(views isNil and:[topViews isNil]) ifFalse:[
|
|
274 |
event sendEvent.
|
|
275 |
].
|
|
276 |
]
|
48
|
277 |
!
|
|
278 |
|
|
279 |
processExposeEvents
|
|
280 |
"process all expose events from the damage queue"
|
|
281 |
|
|
282 |
|event view rect oldActive|
|
|
283 |
|
|
284 |
oldActive := ActiveGroup.
|
|
285 |
ActiveGroup := self.
|
81
|
286 |
[mySensor notNil and:[mySensor hasDamage]] whileTrue:[
|
72
|
287 |
event := mySensor nextDamage.
|
78
|
288 |
event notNil ifTrue:[
|
|
289 |
(views isNil and:[topViews isNil]) ifFalse:[
|
|
290 |
event isDamage ifTrue:[
|
|
291 |
view := event view.
|
|
292 |
rect := event rectangle.
|
|
293 |
view shown ifTrue:[
|
81
|
294 |
view transformation notNil ifTrue:[
|
85
|
295 |
view deviceExposeX:(rect left) y:(rect top) width:(rect width) height:(rect height)
|
81
|
296 |
] ifFalse:[
|
|
297 |
view exposeX:(rect left) y:(rect top) width:(rect width) height:(rect height)
|
|
298 |
]
|
78
|
299 |
]
|
|
300 |
] ifFalse:[
|
|
301 |
event sendEvent.
|
72
|
302 |
]
|
|
303 |
]
|
|
304 |
]
|
48
|
305 |
].
|
|
306 |
ActiveGroup := oldActive
|
11
|
307 |
!
|
|
308 |
|
19
|
309 |
eventLoop
|
|
310 |
"loop executed by windowGroup process;
|
|
311 |
wait-for and process events forever"
|
|
312 |
|
23
|
313 |
self eventLoopWhile:[true]
|
|
314 |
!
|
|
315 |
|
|
316 |
eventLoopWhile:aBlock
|
|
317 |
"wait-for and process events while aBlock evaluates to true."
|
|
318 |
|
78
|
319 |
|abortSignal|
|
|
320 |
|
|
321 |
abortSignal := Object abortSignal.
|
72
|
322 |
"/ ScheduledWindowGroups add:self.
|
78
|
323 |
|
|
324 |
(SignalSet with:LeaveSignal with:abortSignal)
|
72
|
325 |
handle:[:ex |
|
|
326 |
ex return
|
46
|
327 |
] do:[
|
78
|
328 |
|p g oldActive mainGroup|
|
|
329 |
|
|
330 |
isModal ifTrue:[
|
|
331 |
mainGroup := self mainGroup.
|
|
332 |
].
|
54
|
333 |
|
72
|
334 |
aBlock whileTrue:[
|
|
335 |
(views isNil and:[topViews isNil]) ifTrue:[
|
|
336 |
"/ ScheduledWindowGroups remove:self ifAbsent:[].
|
|
337 |
myProcess notNil ifTrue:[
|
|
338 |
p := myProcess.
|
|
339 |
myProcess := nil.
|
|
340 |
p terminate.
|
|
341 |
"not reached - there is no life after death"
|
|
342 |
].
|
|
343 |
"
|
|
344 |
this is the end of a modal loop
|
|
345 |
(not having a private process ...)
|
|
346 |
"
|
|
347 |
^ self
|
|
348 |
].
|
78
|
349 |
abortSignal handle:[:ex |
|
72
|
350 |
ex return
|
|
351 |
] do:[
|
|
352 |
"
|
|
353 |
if modal, break out of the wait after some time
|
|
354 |
to allow servicing update-events of the blocked
|
|
355 |
windowgroup.
|
|
356 |
"
|
|
357 |
isModal ifTrue:[
|
|
358 |
mySensor eventSemaphore waitWithTimeout:0.2.
|
|
359 |
] ifFalse:[
|
78
|
360 |
Processor activeProcess setStateTo:#eventWait if:#active.
|
72
|
361 |
mySensor eventSemaphore wait.
|
|
362 |
].
|
|
363 |
oldActive := ActiveGroup.
|
|
364 |
ActiveGroup := self.
|
|
365 |
self processEvent
|
|
366 |
].
|
|
367 |
ActiveGroup := oldActive.
|
81
|
368 |
oldActive := nil.
|
72
|
369 |
|
|
370 |
"
|
|
371 |
if modal, also check for redraw events in my maingroup
|
78
|
372 |
(we arrive here after every event for myself or after the
|
|
373 |
above timeout)
|
72
|
374 |
"
|
78
|
375 |
mainGroup notNil ifTrue:[
|
|
376 |
mainGroup processExposeEvents.
|
72
|
377 |
]
|
|
378 |
]
|
54
|
379 |
].
|
72
|
380 |
"/ ScheduledWindowGroups remove:self ifAbsent:[].
|
28
|
381 |
!
|
|
382 |
|
|
383 |
waitForExposeFor:aView
|
|
384 |
"wait for a noExpose on aView, then process all exposes.
|
|
385 |
To be used after a scroll"
|
|
386 |
|
|
387 |
mySensor waitForExposeFor:aView.
|
|
388 |
self processExposeEvents
|
46
|
389 |
!
|
|
390 |
|
|
391 |
leaveEventLoop
|
65
|
392 |
^ LeaveSignal raise
|
19
|
393 |
! !
|
|
394 |
|
|
395 |
!WindowGroup methodsFor:'activation / deactivation'!
|
|
396 |
|
46
|
397 |
restart
|
54
|
398 |
"restart after a snapin."
|
46
|
399 |
|
48
|
400 |
topViews notNil ifTrue:[
|
72
|
401 |
"
|
|
402 |
need a new semaphore, since obsolete processes
|
|
403 |
(from our previous live) may still sit on the current semaphore
|
|
404 |
"
|
|
405 |
mySensor eventSemaphore:Semaphore new.
|
|
406 |
isModal ifFalse:[
|
|
407 |
self startup
|
|
408 |
]
|
48
|
409 |
]
|
46
|
410 |
!
|
|
411 |
|
11
|
412 |
startup
|
19
|
413 |
"startup the window-group;
|
|
414 |
this creates a new window group process, which
|
|
415 |
does the event processing."
|
|
416 |
|
23
|
417 |
|nm|
|
|
418 |
|
54
|
419 |
previousGroup := nil.
|
11
|
420 |
myProcess isNil ifTrue:[
|
72
|
421 |
isModal := false.
|
|
422 |
"/ ScheduledWindowGroups add:self.
|
|
423 |
myProcess := [
|
|
424 |
topViews notNil ifTrue:[
|
|
425 |
topViews do:[:aView |
|
|
426 |
aView realize
|
|
427 |
].
|
|
428 |
].
|
|
429 |
self eventLoopWhile:[true]
|
|
430 |
] forkAt:Processor userSchedulingPriority.
|
19
|
431 |
|
72
|
432 |
(topViews notNil and:[topViews isEmpty not]) ifTrue:[
|
|
433 |
"give the handler process a user friendly name"
|
|
434 |
nm := topViews first name.
|
|
435 |
nm isNil ifTrue:[
|
|
436 |
nm := topViews first label.
|
|
437 |
].
|
|
438 |
myProcess name:(topViews first name)
|
|
439 |
] ifFalse:[
|
|
440 |
myProcess name:'window handler'.
|
|
441 |
].
|
19
|
442 |
|
72
|
443 |
"when the process dies, we have to close-down
|
|
444 |
the views as well
|
|
445 |
"
|
|
446 |
myProcess exitAction:[self closeDownViews]
|
11
|
447 |
]
|
|
448 |
!
|
|
449 |
|
48
|
450 |
startupModal:checkBlock
|
|
451 |
"startup the window-group in a modal loop (i.e. under the
|
|
452 |
currently running process);
|
|
453 |
checkBlock is evaluated and loop is left, when false is
|
|
454 |
returned."
|
|
455 |
|
54
|
456 |
"set previousGroup to the main (non-modal) group"
|
|
457 |
|
|
458 |
previousGroup := WindowGroup activeGroup.
|
|
459 |
isModal := true.
|
48
|
460 |
topViews do:[:aView |
|
72
|
461 |
aView realize.
|
48
|
462 |
].
|
81
|
463 |
[
|
|
464 |
self eventLoopWhile:checkBlock.
|
|
465 |
] valueNowOrOnUnwindDo:[
|
|
466 |
"
|
|
467 |
cleanup, in case of a terminate
|
|
468 |
"
|
|
469 |
previousGroup := nil.
|
|
470 |
topViews := nil.
|
|
471 |
views := nil.
|
|
472 |
topViews notNil ifTrue:[
|
|
473 |
topViews do:[:aView |
|
|
474 |
aView destroy
|
|
475 |
].
|
|
476 |
].
|
|
477 |
views notNil ifTrue:[
|
|
478 |
views do:[:aView |
|
|
479 |
aView destroy
|
|
480 |
]
|
|
481 |
].
|
|
482 |
].
|
48
|
483 |
!
|
|
484 |
|
19
|
485 |
closeDownViews
|
|
486 |
"destroy all views associated to this window group"
|
|
487 |
|
11
|
488 |
topViews notNil ifTrue:[
|
72
|
489 |
topViews do:[:aTopView | aTopView destroy]
|
11
|
490 |
].
|
|
491 |
views := nil.
|
|
492 |
topViews := nil.
|
72
|
493 |
"/ ScheduledWindowGroups remove:self ifAbsent:[].
|
19
|
494 |
!
|
|
495 |
|
|
496 |
shutdown
|
|
497 |
"shutdow the window group; close all views and
|
|
498 |
terminate process"
|
|
499 |
|
46
|
500 |
|p|
|
|
501 |
|
19
|
502 |
self closeDownViews.
|
11
|
503 |
myProcess notNil ifTrue:[
|
72
|
504 |
p := myProcess.
|
|
505 |
myProcess := nil.
|
|
506 |
"/ ScheduledWindowGroups remove:self ifAbsent:[].
|
|
507 |
p terminate.
|
11
|
508 |
]
|
|
509 |
! !
|
|
510 |
|
|
511 |
!WindowGroup methodsFor:'initialization'!
|
|
512 |
|
|
513 |
reinitialize
|
72
|
514 |
"reinitialize the windowgroup after an image restart"
|
|
515 |
|
19
|
516 |
"throw away old (zombie) process"
|
72
|
517 |
myProcess notNil ifTrue:[
|
|
518 |
"careful: the old processes exitaction must be cleared
|
|
519 |
otherwise, it might do destroy or other actions when it
|
|
520 |
gets finalized ...
|
|
521 |
"
|
|
522 |
myProcess exitAction:nil.
|
|
523 |
myProcess := nil.
|
|
524 |
].
|
19
|
525 |
|
11
|
526 |
"throw away old events"
|
54
|
527 |
mySensor reinitialize
|
11
|
528 |
!
|
|
529 |
|
|
530 |
initialize
|
19
|
531 |
"setup the windowgroup, by creating a new sensor
|
|
532 |
and an event semaphore"
|
|
533 |
|
11
|
534 |
mySensor := WindowSensor new.
|
72
|
535 |
mySensor eventSemaphore:Semaphore new.
|
|
536 |
isModal := false.
|
11
|
537 |
! !
|
19
|
538 |
|
|
539 |
!WindowGroup methodsFor:'printing'!
|
|
540 |
|
|
541 |
printString
|
|
542 |
"return a printed representation;
|
|
543 |
just for more user friendlyness, add name of process."
|
|
544 |
|
23
|
545 |
myProcess isNil ifTrue:[^ super printString].
|
19
|
546 |
^ 'WindowGroup(' , myProcess nameOrId , ')'
|
|
547 |
! !
|