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