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