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
|
|
14 |
instanceVariableNames:'views topViews myProcess mySensor'
|
|
15 |
classVariableNames:'ActiveGroup'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Interface-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
!WindowGroup class methodsFor:'instance creation'!
|
|
21 |
|
|
22 |
new
|
26
|
23 |
"create and return a new WindowGroup object"
|
|
24 |
|
11
|
25 |
^ self basicNew initialize
|
|
26 |
! !
|
|
27 |
|
26
|
28 |
!WindowGroup class methodsFor:'accessing'!
|
|
29 |
|
|
30 |
activeGroup
|
|
31 |
"return the currently active windowGroup"
|
|
32 |
|
|
33 |
^ ActiveGroup
|
|
34 |
! !
|
|
35 |
|
11
|
36 |
!WindowGroup methodsFor:'accessing'!
|
|
37 |
|
26
|
38 |
sensor
|
|
39 |
"return the windowGroups sensor"
|
|
40 |
|
|
41 |
^ mySensor
|
|
42 |
!
|
|
43 |
|
11
|
44 |
addView:aView
|
26
|
45 |
"add aView to the windowGroup"
|
|
46 |
|
11
|
47 |
views isNil ifTrue:[
|
|
48 |
views := OrderedCollection new.
|
|
49 |
].
|
|
50 |
views add:aView
|
|
51 |
!
|
|
52 |
|
26
|
53 |
removeView:aView
|
|
54 |
"remove aView from the windowGroup;
|
|
55 |
if this was the last view in this group,
|
|
56 |
also shut down the corresponding process"
|
11
|
57 |
|
|
58 |
views notNil ifTrue:[
|
|
59 |
views remove:aView ifAbsent:[].
|
|
60 |
views isEmpty ifTrue:[
|
|
61 |
views := nil
|
|
62 |
]
|
|
63 |
].
|
|
64 |
topViews notNil ifTrue:[
|
|
65 |
topViews remove:aView ifAbsent:[].
|
|
66 |
topViews isEmpty ifTrue:[
|
|
67 |
topViews := nil
|
|
68 |
]
|
|
69 |
].
|
|
70 |
|
|
71 |
(views isNil and:[topViews isNil]) ifTrue:[
|
|
72 |
views := nil.
|
|
73 |
topViews := nil.
|
|
74 |
myProcess notNil ifTrue:[
|
23
|
75 |
myProcess terminate.
|
|
76 |
myProcess := nil
|
11
|
77 |
]
|
|
78 |
].
|
23
|
79 |
mySensor eventSemaphore signal
|
11
|
80 |
!
|
|
81 |
|
|
82 |
views
|
26
|
83 |
"return the views accociated to this windowGroup"
|
|
84 |
|
11
|
85 |
^ views
|
|
86 |
!
|
|
87 |
|
|
88 |
process
|
26
|
89 |
"return the windowGroups process"
|
|
90 |
|
11
|
91 |
^ myProcess
|
|
92 |
!
|
|
93 |
|
|
94 |
sensor:aSensor
|
26
|
95 |
"set the windowGroups sensor"
|
|
96 |
|
11
|
97 |
mySensor := aSensor
|
|
98 |
!
|
|
99 |
|
|
100 |
addTopView:aView
|
|
101 |
topViews isNil ifTrue:[
|
|
102 |
topViews := OrderedCollection new.
|
|
103 |
].
|
|
104 |
topViews add:aView
|
|
105 |
! !
|
|
106 |
|
19
|
107 |
!WindowGroup methodsFor:'event handling'!
|
11
|
108 |
|
19
|
109 |
processEvent
|
23
|
110 |
"process a single event from either the damage- or user input queues"
|
19
|
111 |
|
11
|
112 |
|damage event view rect|
|
|
113 |
|
17
|
114 |
ActiveGroup := self.
|
11
|
115 |
[mySensor hasDamage] whileTrue:[
|
|
116 |
damage := mySensor nextDamage.
|
|
117 |
view := damage at:1.
|
|
118 |
rect := damage at:2.
|
|
119 |
view exposeX:rect left y:rect top width:rect width height:rect height
|
|
120 |
].
|
|
121 |
[mySensor hasEvents] whileTrue:[
|
|
122 |
event := mySensor nextEvent.
|
|
123 |
event sendEvent
|
|
124 |
]
|
|
125 |
!
|
|
126 |
|
19
|
127 |
eventLoop
|
|
128 |
"loop executed by windowGroup process;
|
|
129 |
wait-for and process events forever"
|
|
130 |
|
23
|
131 |
self eventLoopWhile:[true]
|
|
132 |
!
|
|
133 |
|
|
134 |
eventLoopWhile:aBlock
|
|
135 |
"wait-for and process events while aBlock evaluates to true."
|
|
136 |
|
|
137 |
aBlock whileTrue:[
|
19
|
138 |
mySensor eventSemaphore wait.
|
|
139 |
self processEvent
|
|
140 |
]
|
|
141 |
! !
|
|
142 |
|
|
143 |
!WindowGroup methodsFor:'activation / deactivation'!
|
|
144 |
|
11
|
145 |
startup
|
19
|
146 |
"startup the window-group;
|
|
147 |
this creates a new window group process, which
|
|
148 |
does the event processing."
|
|
149 |
|
23
|
150 |
|nm|
|
|
151 |
|
11
|
152 |
myProcess isNil ifTrue:[
|
|
153 |
myProcess := [
|
19
|
154 |
self eventLoop
|
11
|
155 |
] forkAt:Processor userSchedulingPriority.
|
19
|
156 |
|
11
|
157 |
(topViews notNil and:[topViews isEmpty not]) ifTrue:[
|
|
158 |
"give the handler process a user friendly name"
|
23
|
159 |
nm := topViews first iconLabel.
|
|
160 |
nm isNil ifTrue:[
|
|
161 |
nm := topViews first name.
|
|
162 |
nm isNil ifTrue:[
|
|
163 |
nm := topViews first label.
|
|
164 |
]
|
|
165 |
].
|
11
|
166 |
myProcess name:(topViews first name)
|
|
167 |
] ifFalse:[
|
|
168 |
myProcess name:'window handler'.
|
|
169 |
].
|
19
|
170 |
|
|
171 |
"when the process dies, we have to close-down
|
|
172 |
the views as well"
|
|
173 |
myProcess exitAction:[self closeDownViews]
|
11
|
174 |
]
|
|
175 |
!
|
|
176 |
|
19
|
177 |
closeDownViews
|
|
178 |
"destroy all views associated to this window group"
|
|
179 |
|
11
|
180 |
topViews notNil ifTrue:[
|
|
181 |
topViews do:[:aTopView | aTopView destroy]
|
|
182 |
].
|
|
183 |
views := nil.
|
|
184 |
topViews := nil.
|
19
|
185 |
!
|
|
186 |
|
|
187 |
shutdown
|
|
188 |
"shutdow the window group; close all views and
|
|
189 |
terminate process"
|
|
190 |
|
|
191 |
self closeDownViews.
|
11
|
192 |
myProcess notNil ifTrue:[
|
|
193 |
myProcess terminate.
|
|
194 |
myProcess := nil
|
|
195 |
]
|
|
196 |
! !
|
|
197 |
|
|
198 |
!WindowGroup methodsFor:'initialization'!
|
|
199 |
|
|
200 |
reinitialize
|
19
|
201 |
"throw away old (zombie) process"
|
11
|
202 |
myProcess := nil.
|
19
|
203 |
|
11
|
204 |
"throw away old events"
|
19
|
205 |
self initialize
|
11
|
206 |
!
|
|
207 |
|
|
208 |
initialize
|
19
|
209 |
"setup the windowgroup, by creating a new sensor
|
|
210 |
and an event semaphore"
|
|
211 |
|
11
|
212 |
mySensor := WindowSensor new.
|
|
213 |
mySensor eventSemaphore:Semaphore new
|
|
214 |
! !
|
19
|
215 |
|
|
216 |
!WindowGroup methodsFor:'printing'!
|
|
217 |
|
|
218 |
printString
|
|
219 |
"return a printed representation;
|
|
220 |
just for more user friendlyness, add name of process."
|
|
221 |
|
23
|
222 |
myProcess isNil ifTrue:[^ super printString].
|
19
|
223 |
^ 'WindowGroup(' , myProcess nameOrId , ')'
|
|
224 |
! !
|