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 |
"
|
0
|
12 |
|
|
13 |
Object subclass:#WindowSensor
|
72
|
14 |
instanceVariableNames:'eventSemaphore damage mouseAndKeyboard
|
|
15 |
compressMotionEvents ignoreUserInput
|
|
16 |
buttonState exposeEventSemaphore
|
|
17 |
catchExpose gotExpose gotOtherEvent
|
81
|
18 |
translateKeyboardEvents'
|
72
|
19 |
classVariableNames:'ControlCEnabled'
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Interface-Support'
|
0
|
22 |
!
|
|
23 |
|
|
24 |
WindowSensor comment:'
|
46
|
25 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
26 |
All Rights Reserved
|
54
|
27 |
|
110
|
28 |
$Header: /cvs/stx/stx/libview/WindowSensor.st,v 1.18 1995-02-28 21:51:15 claus Exp $
|
12
|
29 |
'!
|
0
|
30 |
|
46
|
31 |
!WindowSensor class methodsFor:'documentation'!
|
|
32 |
|
|
33 |
copyright
|
|
34 |
"
|
|
35 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
36 |
All Rights Reserved
|
46
|
37 |
|
|
38 |
This software is furnished under a license and may be used
|
|
39 |
only in accordance with the terms of that license and with the
|
|
40 |
inclusion of the above copyright notice. This software may not
|
|
41 |
be provided or otherwise made available to, or used by, any
|
|
42 |
other person. No title to or ownership of the software is
|
|
43 |
hereby transferred.
|
|
44 |
"
|
|
45 |
!
|
|
46 |
|
|
47 |
version
|
|
48 |
"
|
110
|
49 |
$Header: /cvs/stx/stx/libview/WindowSensor.st,v 1.18 1995-02-28 21:51:15 claus Exp $
|
46
|
50 |
"
|
|
51 |
!
|
|
52 |
|
|
53 |
documentation
|
|
54 |
"
|
72
|
55 |
Instances of this class keep track of events and damage areas for a group of
|
|
56 |
views. All incoming expose rectangles and events (from Workstation) are
|
|
57 |
collected here, until someone gets a chance to handle them.
|
|
58 |
When adding an expose rectangle, WindowSensor tries to merge the rectangle
|
|
59 |
with the list of existing damages to minimize redrawing.
|
47
|
60 |
|
|
61 |
instance variables:
|
72
|
62 |
eventSemaphore <Semaphore> the semaphore to be signalled when an event
|
|
63 |
(or damage) arrives
|
47
|
64 |
|
72
|
65 |
damage <Collection> collection of damage events
|
47
|
66 |
|
72
|
67 |
mouseAndKeyboard <Collection> collection of user events
|
47
|
68 |
|
72
|
69 |
compressMotionEvents <Boolean> if true, multiple motion events are
|
|
70 |
compressed to one event. If false, each
|
|
71 |
event is handled individual.
|
|
72 |
(should be set to false when doing free-hand drawing)
|
47
|
73 |
|
72
|
74 |
ignoreUserInput <Boolean> if true, key & button events are ignored
|
|
75 |
(usually set to true by WindowGroup, while a
|
|
76 |
modalbox covers a view)
|
47
|
77 |
|
72
|
78 |
buttonState the current state (currently unused)
|
|
79 |
|
|
80 |
exposeEventSemaphore <Semaphore> X-special: semaphore to be signalled when
|
|
81 |
expose event arrives after a copyArea.
|
47
|
82 |
|
72
|
83 |
catchExpose <Boolean> true, while waiting for an expose event
|
|
84 |
(after a copyArea)
|
47
|
85 |
|
72
|
86 |
gotExpose <Boolean> set to true, when an expose event arrives
|
|
87 |
(after a copyarea)
|
47
|
88 |
|
72
|
89 |
gotOtherEvent <Boolean> set to true if other events arrive while
|
|
90 |
waiting for expose (after a copyarea).
|
47
|
91 |
|
81
|
92 |
translateKeyboardEvents <Boolean> if true, keyboard events are translated via
|
|
93 |
the devices leyboardMap; if false, they
|
|
94 |
are reported as raw-keys. Default is true.
|
|
95 |
|
47
|
96 |
class variables:
|
72
|
97 |
ControlCEnabled <Boolean> if true (which is the default) Control-C
|
|
98 |
will interrupt the process handling the
|
|
99 |
view.
|
|
100 |
For secure stand-alone applications,
|
|
101 |
this can be set to false, in which case
|
|
102 |
Control-C does NOT interrupt the process.
|
46
|
103 |
"
|
|
104 |
! !
|
|
105 |
|
47
|
106 |
!WindowSensor class methodsFor:'initialization'!
|
|
107 |
|
|
108 |
initialize
|
81
|
109 |
ControlCEnabled := true.
|
|
110 |
|
47
|
111 |
!
|
|
112 |
|
|
113 |
disableControlC
|
72
|
114 |
"disable Control-C processing. If enabled,
|
47
|
115 |
pressing CNTL-C in a view will interrupt it and bring
|
72
|
116 |
its process into the debugger (actually raising signal).
|
47
|
117 |
Otherwise, CNTL-C is sent to the view like any other key.
|
|
118 |
"
|
|
119 |
|
|
120 |
ControlCEnabled := false
|
|
121 |
!
|
|
122 |
|
|
123 |
enableControlC
|
72
|
124 |
"enable Control-C processing. If enabled,
|
47
|
125 |
pressing CNTL-C in a view will interrupt it and bring
|
72
|
126 |
its process into the debugger (actually raising signal).
|
47
|
127 |
Otherwise, CNTL-C is sent to the view like any other key.
|
|
128 |
"
|
|
129 |
|
|
130 |
ControlCEnabled := true
|
|
131 |
! !
|
|
132 |
|
0
|
133 |
!WindowSensor class methodsFor:'instance creation'!
|
|
134 |
|
|
135 |
new
|
|
136 |
^ self basicNew initialize
|
|
137 |
! !
|
|
138 |
|
|
139 |
!WindowSensor methodsFor:'damage'!
|
|
140 |
|
12
|
141 |
addDamage: aRectangle view:aView
|
0
|
142 |
"Add aRectangle to the damage list.
|
|
143 |
We try to merge incoming rectangles with the existing damage by discarding
|
|
144 |
incoming rectangles which are contained in the existing damage or replacing
|
|
145 |
any existing damage rectangle with incoming rectangles that completely contain it.
|
|
146 |
There could be much more optimization here (for example joining rectangles)..."
|
|
147 |
|
54
|
148 |
|count temp index newEvent
|
|
149 |
sz "{ Class: SmallInteger }" |
|
0
|
150 |
|
54
|
151 |
sz := damage size.
|
|
152 |
sz == 0 ifTrue: [
|
72
|
153 |
newEvent := WindowEvent damageFor:aView rectangle:aRectangle.
|
|
154 |
damage := OrderedCollection with:newEvent.
|
|
155 |
^ self
|
46
|
156 |
].
|
|
157 |
|
47
|
158 |
"
|
|
159 |
first look, if this rectangle is already in the expose list;
|
|
160 |
if so, dont add to queue
|
|
161 |
"
|
46
|
162 |
damage do: [:aDamage |
|
72
|
163 |
aDamage notNil ifTrue:[
|
|
164 |
aDamage isDamage ifTrue:[
|
|
165 |
aDamage view == aView ifTrue:[
|
|
166 |
((aDamage rectangle) contains:aRectangle) ifTrue: [^self]
|
|
167 |
]
|
|
168 |
]
|
|
169 |
].
|
46
|
170 |
].
|
|
171 |
|
47
|
172 |
"
|
|
173 |
then look, if new rectangle contains any in the expose list;
|
|
174 |
if so, remove the old damage
|
|
175 |
"
|
46
|
176 |
count := 0.
|
54
|
177 |
1 to:sz do:[:i |
|
72
|
178 |
|aDamage|
|
12
|
179 |
|
72
|
180 |
aDamage := damage at:i.
|
|
181 |
aDamage notNil ifTrue:[
|
|
182 |
aDamage isDamage ifTrue:[
|
|
183 |
(aDamage view) == aView ifTrue:[
|
|
184 |
(aRectangle contains:(aDamage rectangle)) ifTrue: [
|
|
185 |
damage at:i put:nil.
|
|
186 |
count := count + 1
|
|
187 |
]
|
|
188 |
]
|
|
189 |
]
|
|
190 |
]
|
46
|
191 |
].
|
|
192 |
|
47
|
193 |
count > 10 ifTrue: [
|
72
|
194 |
temp := OrderedCollection new:(sz - count + 1).
|
|
195 |
index := 1.
|
|
196 |
damage do:[:aDamage |
|
|
197 |
aDamage notNil ifTrue: [
|
|
198 |
temp add: aDamage.
|
|
199 |
]
|
|
200 |
].
|
|
201 |
damage := temp
|
0
|
202 |
].
|
46
|
203 |
newEvent := WindowEvent damageFor:aView rectangle:aRectangle.
|
|
204 |
damage add:newEvent.
|
0
|
205 |
!
|
|
206 |
|
|
207 |
nextDamage
|
12
|
208 |
"retrieve the next damage rectangle or nil, if there is none"
|
0
|
209 |
|
47
|
210 |
|d|
|
|
211 |
|
|
212 |
[d isNil] whileTrue:[
|
72
|
213 |
damage size == 0 ifTrue:[^ nil].
|
|
214 |
d := damage removeFirst.
|
0
|
215 |
].
|
47
|
216 |
^ d
|
0
|
217 |
!
|
|
218 |
|
|
219 |
nextEvent
|
12
|
220 |
"retrieve the next event or nil, if there is none"
|
0
|
221 |
|
47
|
222 |
|e|
|
|
223 |
|
|
224 |
[e isNil] whileTrue:[
|
72
|
225 |
mouseAndKeyboard size == 0 ifTrue:[^ nil].
|
|
226 |
e := mouseAndKeyboard removeFirst.
|
0
|
227 |
].
|
47
|
228 |
^ e
|
0
|
229 |
! !
|
|
230 |
|
26
|
231 |
!WindowSensor methodsFor:'special'!
|
|
232 |
|
54
|
233 |
catchExpose
|
|
234 |
"start catching noExpose events (must be done BEFORE a bitblt,
|
|
235 |
to prepare for the exposeEventSemaphore to be signalled when
|
|
236 |
the noExpose event arrives)."
|
26
|
237 |
|
54
|
238 |
gotExpose := false.
|
|
239 |
gotOtherEvent := false.
|
|
240 |
catchExpose := true.
|
26
|
241 |
exposeEventSemaphore := Semaphore new.
|
28
|
242 |
!
|
|
243 |
|
26
|
244 |
waitForExposeFor:aView
|
54
|
245 |
"wait until a noExpose arrives (after a bitblt)"
|
|
246 |
|
90
|
247 |
Processor activeProcessIsSystemProcess ifTrue:[
|
|
248 |
"
|
|
249 |
cannot really suspend, if its a systemProcess
|
|
250 |
"
|
|
251 |
[gotExpose] whileFalse:[
|
|
252 |
aView device dispatchExposeEventFor:aView id.
|
|
253 |
Processor yield.
|
|
254 |
]
|
|
255 |
] ifFalse:[
|
72
|
256 |
[gotExpose] whileFalse:[
|
|
257 |
"
|
81
|
258 |
just in case we have a (network or software) problem ...
|
|
259 |
explanation: it may happen, that an expose event is totally
|
|
260 |
lost - for example, if the network breaks down.
|
|
261 |
To not block forever, we wait with a timeout, to get out of here
|
|
262 |
if the event does not arrive after 15 seconds.
|
72
|
263 |
"
|
|
264 |
(exposeEventSemaphore waitWithTimeout:5) ifFalse:[
|
|
265 |
aView device synchronizeOutput.
|
90
|
266 |
'WSENSOR: late expose event' errorPrintNL.
|
72
|
267 |
(exposeEventSemaphore waitWithTimeout:10) ifFalse:[
|
81
|
268 |
'WSENSOR: lost expose event again - ignore' errorPrintNL.
|
72
|
269 |
].
|
81
|
270 |
"
|
|
271 |
you can put a comment around the following line, if you dont
|
|
272 |
like the message ...
|
|
273 |
"
|
72
|
274 |
gotExpose := true.
|
|
275 |
^ self
|
|
276 |
]
|
|
277 |
].
|
26
|
278 |
|
72
|
279 |
"
|
|
280 |
other incoming events have been ignored during the wait.
|
|
281 |
Now handle those ...
|
|
282 |
"
|
|
283 |
gotOtherEvent ifTrue:[
|
|
284 |
eventSemaphore signal
|
|
285 |
].
|
26
|
286 |
].
|
28
|
287 |
catchExpose := false
|
47
|
288 |
!
|
|
289 |
|
|
290 |
flushUserEvents
|
|
291 |
"throw away all pending user events"
|
|
292 |
|
72
|
293 |
(mouseAndKeyboard isNil or:[mouseAndKeyboard size > 0]) ifTrue:[
|
|
294 |
mouseAndKeyboard := OrderedCollection new
|
|
295 |
].
|
47
|
296 |
!
|
|
297 |
|
|
298 |
flushExposeEvents
|
|
299 |
"throw away all pending expose events; this
|
|
300 |
can be done after a full redraw (or in views, which are
|
|
301 |
doing full redraws anly)"
|
|
302 |
|
72
|
303 |
(damage isNil or:[damage size > 0]) ifTrue:[
|
|
304 |
damage := OrderedCollection new
|
|
305 |
].
|
|
306 |
!
|
|
307 |
|
78
|
308 |
flushExposeEventsFor:aView
|
|
309 |
"throw away all pending expose events for aView;
|
|
310 |
this can be done after a full redraw
|
|
311 |
(or in views, which are always doing full redraws -
|
|
312 |
instead of drawing the clip-area only)"
|
|
313 |
|
|
314 |
damage notNil ifTrue:[
|
|
315 |
1 to:damage size do:[:index |
|
|
316 |
|aDamage|
|
|
317 |
|
|
318 |
aDamage := damage at:index.
|
|
319 |
aDamage notNil ifTrue:[
|
|
320 |
aDamage view == aView ifTrue:[
|
|
321 |
damage at:index put:nil
|
|
322 |
]
|
|
323 |
]
|
|
324 |
]
|
|
325 |
].
|
|
326 |
!
|
|
327 |
|
|
328 |
flushUserEventsFor:aView
|
|
329 |
"throw away all pending user events for aView"
|
|
330 |
|
|
331 |
mouseAndKeyboard notNil ifTrue:[
|
|
332 |
1 to:mouseAndKeyboard size do:[:i |
|
|
333 |
|anEvent|
|
|
334 |
|
|
335 |
anEvent := mouseAndKeyboard at:i.
|
|
336 |
anEvent notNil ifTrue:[
|
|
337 |
anEvent view == aView ifTrue:[
|
|
338 |
mouseAndKeyboard at:i put:nil
|
|
339 |
]
|
|
340 |
]
|
|
341 |
]
|
|
342 |
].
|
|
343 |
!
|
|
344 |
|
|
345 |
flushEventsFor:aView
|
|
346 |
"throw away all events for aView"
|
|
347 |
|
|
348 |
self flushExposeEventsFor:aView.
|
|
349 |
self flushUserEventsFor:aView.
|
|
350 |
!
|
|
351 |
|
72
|
352 |
pushUserEvent:anEvent
|
|
353 |
"manually put an event into the queue - this allows
|
|
354 |
simulation of events (implementation of recorders & playback)."
|
|
355 |
|
|
356 |
mouseAndKeyboard addLast:anEvent.
|
|
357 |
self notifyEventArrival
|
|
358 |
!
|
|
359 |
|
|
360 |
pushUserEvent:aSelector for:aView withArguments:arguments
|
|
361 |
"manually put an event into the queue - this allows
|
|
362 |
simulation of events (implementation of recorders & playback)."
|
|
363 |
|
|
364 |
self pushEvent:(WindowEvent
|
|
365 |
for:aView
|
|
366 |
type:aSelector
|
|
367 |
arguments:arguments).
|
|
368 |
|
|
369 |
"
|
|
370 |
|b|
|
|
371 |
b := Button label:'test'.
|
|
372 |
b open.
|
|
373 |
(Delay forSeconds:5) wait.
|
|
374 |
b sensor pushEvent:#pointerEnter:x:y: for:b withArguments:#(0 1 1).
|
|
375 |
(Delay forSeconds:1) wait.
|
|
376 |
b sensor pushEvent:#buttonPress:x:y: for:b withArguments:#(1 1 1).
|
|
377 |
(Delay forSeconds:2) wait.
|
|
378 |
b sensor pushEvent:#buttonRelease:x:y: for:b withArguments:#(1 1 1).
|
|
379 |
(Delay forSeconds:1) wait.
|
|
380 |
b sensor pushEvent:#pointerLeave: for:b withArguments:#(0).
|
|
381 |
"
|
|
382 |
!
|
|
383 |
|
|
384 |
forwardKeyEventsTo:aView
|
|
385 |
"remove all keyboard events and send them to aSensor instead"
|
|
386 |
|
|
387 |
"/ 'fwd' printNL.
|
|
388 |
1 to:mouseAndKeyboard size do:[:i |
|
|
389 |
|anEvent|
|
|
390 |
|
|
391 |
anEvent := mouseAndKeyboard at:i.
|
|
392 |
anEvent notNil ifTrue:[
|
|
393 |
anEvent isKeyEvent ifTrue:[
|
|
394 |
anEvent view:aView.
|
|
395 |
aView sensor pushUserEvent:anEvent.
|
|
396 |
"/ anEvent type printNL.
|
|
397 |
mouseAndKeyboard at:i put:nil
|
|
398 |
]
|
|
399 |
]
|
|
400 |
].
|
26
|
401 |
! !
|
|
402 |
|
90
|
403 |
!WindowSensor methodsFor:'queries '!
|
|
404 |
|
|
405 |
hasDamageFor:aView
|
|
406 |
"return true, if any exposure events are pending for aView"
|
|
407 |
|
|
408 |
damage size ~~ 0 ifTrue:[
|
|
409 |
damage do:[:aDamage |
|
|
410 |
aDamage notNil ifTrue:[
|
|
411 |
aDamage view == aView ifTrue:[^ true].
|
|
412 |
].
|
|
413 |
]
|
|
414 |
].
|
|
415 |
^ false
|
|
416 |
!
|
|
417 |
|
|
418 |
hasDamage
|
|
419 |
"return true, if any exposure events are pending"
|
|
420 |
|
|
421 |
^ damage size ~~ 0
|
|
422 |
!
|
|
423 |
|
|
424 |
hasEvents
|
|
425 |
"return true, if any mouse/keyboard events are pending"
|
|
426 |
|
|
427 |
^ mouseAndKeyboard size ~~ 0
|
|
428 |
!
|
|
429 |
|
|
430 |
eventPending
|
|
431 |
"return true, if either damage or events are pending"
|
|
432 |
|
|
433 |
mouseAndKeyboard size ~~ 0 ifTrue:[^ true].
|
|
434 |
^ damage size ~~ 0
|
110
|
435 |
!
|
|
436 |
|
|
437 |
hasButtonMotionEventsFor:aView
|
|
438 |
"return true, if any buttonMotion events are pending"
|
|
439 |
|
|
440 |
mouseAndKeyboard size ~~ 0 ifTrue:[
|
|
441 |
mouseAndKeyboard do:[:anEvent |
|
|
442 |
anEvent notNil ifTrue:[
|
|
443 |
anEvent view == aView ifTrue:[
|
|
444 |
anEvent type == #buttonMotion:x:y: ifTrue:[^ true].
|
|
445 |
]
|
|
446 |
].
|
|
447 |
]
|
|
448 |
].
|
|
449 |
^ aView device eventPending:#buttonMotion for:aView id
|
90
|
450 |
! !
|
|
451 |
|
0
|
452 |
!WindowSensor methodsFor:'event processing'!
|
|
453 |
|
12
|
454 |
notifyEventArrival
|
78
|
455 |
"an event arrived - if there is an eventSemaphore,
|
12
|
456 |
signal it, to wake up any controller process"
|
0
|
457 |
|
28
|
458 |
catchExpose == true ifTrue:[
|
72
|
459 |
"
|
|
460 |
dont wake up, if we are currently waiting for an expose
|
|
461 |
but remember arrival of something.
|
|
462 |
"
|
|
463 |
gotOtherEvent := true.
|
|
464 |
^ self
|
28
|
465 |
].
|
12
|
466 |
eventSemaphore notNil ifTrue:[
|
72
|
467 |
eventSemaphore signal
|
12
|
468 |
]
|
0
|
469 |
!
|
|
470 |
|
12
|
471 |
exposeX:left y:top width:width height:height view:aView
|
46
|
472 |
"an expose event arrived - this is sent from the device (Display)"
|
|
473 |
|
|
474 |
self addDamage:(Rectangle left:left top:top width:width height:height) view:aView.
|
12
|
475 |
self notifyEventArrival
|
|
476 |
!
|
|
477 |
|
28
|
478 |
noExposeView:aView
|
46
|
479 |
"an noexpose event arrived - this is sent from the device (Display)"
|
|
480 |
|
28
|
481 |
gotExpose := true.
|
|
482 |
exposeEventSemaphore notNil ifTrue:[
|
72
|
483 |
exposeEventSemaphore signal
|
28
|
484 |
]
|
|
485 |
!
|
|
486 |
|
12
|
487 |
graphicExposeX:left y:top width:width height:height view:aView
|
|
488 |
self addDamage:(left @ top extent:width @ height) view:aView.
|
|
489 |
!
|
|
490 |
|
|
491 |
buttonMotion:state x:x y:y view:aView
|
46
|
492 |
"mouse was moved - this is sent from the device (Display)"
|
12
|
493 |
|
47
|
494 |
|args|
|
|
495 |
|
|
496 |
ignoreUserInput == true ifTrue:[
|
72
|
497 |
^ self
|
47
|
498 |
].
|
|
499 |
args := Array with:state with:x with:y.
|
|
500 |
|
28
|
501 |
compressMotionEvents ifTrue:[
|
72
|
502 |
"
|
|
503 |
merge with last motion
|
|
504 |
"
|
|
505 |
mouseAndKeyboard reverseDo:[:ev |
|
|
506 |
ev notNil ifTrue:[
|
|
507 |
((ev type == #buttonMotion:x:y:)
|
|
508 |
and:[(ev view == aView)
|
|
509 |
and:[(ev arguments at:1) == state]]) ifTrue:[
|
|
510 |
ev arguments:args.
|
|
511 |
^ self
|
|
512 |
]
|
|
513 |
]
|
|
514 |
]
|
28
|
515 |
].
|
46
|
516 |
mouseAndKeyboard
|
72
|
517 |
addLast:(WindowEvent
|
|
518 |
for:aView
|
|
519 |
type:#buttonMotion:x:y:
|
|
520 |
arguments:args).
|
12
|
521 |
self notifyEventArrival
|
|
522 |
!
|
|
523 |
|
|
524 |
buttonPress:button x:x y:y view:aView
|
46
|
525 |
"mouse button was pressed - this is sent from the device (Display)"
|
12
|
526 |
|
47
|
527 |
ignoreUserInput == true ifTrue:[
|
72
|
528 |
^ self
|
47
|
529 |
].
|
46
|
530 |
mouseAndKeyboard
|
72
|
531 |
addLast:(WindowEvent
|
|
532 |
for:aView
|
|
533 |
type:#buttonPress:x:y:
|
|
534 |
arguments:(Array with:button with:x with:y)).
|
12
|
535 |
self notifyEventArrival
|
|
536 |
!
|
|
537 |
|
|
538 |
buttonRelease:button x:x y:y view:aView
|
46
|
539 |
"mouse button was released- this is sent from the device (Display)"
|
12
|
540 |
|
47
|
541 |
ignoreUserInput == true ifTrue:[
|
72
|
542 |
^ self
|
47
|
543 |
].
|
46
|
544 |
mouseAndKeyboard
|
72
|
545 |
addLast:(WindowEvent
|
|
546 |
for:aView
|
|
547 |
type:#buttonRelease:x:y:
|
|
548 |
arguments:(Array with:button with:x with:y)).
|
47
|
549 |
self notifyEventArrival
|
|
550 |
!
|
|
551 |
|
|
552 |
buttonMultiPress:button x:x y:y view:aView
|
|
553 |
"mouse button was pressed - this is sent from the device (Display)"
|
|
554 |
|
|
555 |
ignoreUserInput == true ifTrue:[
|
72
|
556 |
^ self
|
47
|
557 |
].
|
|
558 |
mouseAndKeyboard
|
72
|
559 |
addLast:(WindowEvent
|
|
560 |
for:aView
|
|
561 |
type:#buttonMultiPress:x:y:
|
|
562 |
arguments:(Array with:button with:x with:y)).
|
47
|
563 |
self notifyEventArrival
|
|
564 |
!
|
|
565 |
|
|
566 |
buttonShiftPress:button x:x y:y view:aView
|
|
567 |
"mouse button was pressed - this is sent from the device (Display)"
|
|
568 |
|
|
569 |
ignoreUserInput == true ifTrue:[
|
72
|
570 |
^ self
|
47
|
571 |
].
|
|
572 |
mouseAndKeyboard
|
72
|
573 |
addLast:(WindowEvent
|
|
574 |
for:aView
|
|
575 |
type:#buttonShiftPress:x:y:
|
|
576 |
arguments:(Array with:button with:x with:y)).
|
47
|
577 |
self notifyEventArrival
|
|
578 |
!
|
|
579 |
|
|
580 |
keyPress:key x:x y:y view:aView
|
72
|
581 |
"key was pressed - this is sent from the device (Display).
|
|
582 |
beside the keyboard translation, CntlC processing is done here."
|
47
|
583 |
|
|
584 |
|xlatedKey group process|
|
|
585 |
|
81
|
586 |
translateKeyboardEvents ifTrue:[
|
|
587 |
xlatedKey := aView device translateKey:key.
|
|
588 |
] ifFalse:[
|
|
589 |
xlatedKey := key.
|
|
590 |
].
|
85
|
591 |
|
|
592 |
(xlatedKey == #CtrlV) ifTrue:[
|
|
593 |
'Smalltalk/X ' errorPrint.
|
|
594 |
Smalltalk versionString errorPrint. ' of ' errorPrint.
|
|
595 |
Smalltalk versionDate errorPrintNL.
|
|
596 |
Smalltalk copyrightString errorPrintNL.
|
|
597 |
].
|
|
598 |
|
|
599 |
((xlatedKey == #UserInterrupt) and:[ControlCEnabled]) ifTrue:[
|
72
|
600 |
"
|
90
|
601 |
Special handling for Ctrl-C: interrupt the underlying process.
|
47
|
602 |
|
72
|
603 |
cannot halt here (this would stop the event-dispatcher),
|
|
604 |
but instead interrupt the underlying process and have it
|
|
605 |
perform the userInterrupt in the interrupt-method.
|
|
606 |
"
|
|
607 |
group := aView windowGroup.
|
|
608 |
group notNil ifTrue:[
|
|
609 |
process := group process.
|
|
610 |
process notNil ifTrue:[
|
|
611 |
process interruptWith:[process userInterrupt]
|
|
612 |
]
|
|
613 |
].
|
|
614 |
^ self
|
47
|
615 |
].
|
72
|
616 |
|
47
|
617 |
ignoreUserInput == true ifTrue:[
|
72
|
618 |
^ self
|
47
|
619 |
].
|
|
620 |
mouseAndKeyboard
|
72
|
621 |
addLast:(WindowEvent
|
|
622 |
for:aView
|
|
623 |
type:#keyPress:x:y:
|
|
624 |
arguments:(Array with:xlatedKey with:x with:y)).
|
12
|
625 |
self notifyEventArrival
|
|
626 |
!
|
|
627 |
|
62
|
628 |
keyRelease:key x:x y:y view:aView
|
|
629 |
"key was released - this is sent from the device (Display)."
|
|
630 |
|
|
631 |
|xlatedKey|
|
|
632 |
|
|
633 |
ignoreUserInput == true ifTrue:[
|
72
|
634 |
^ self
|
62
|
635 |
].
|
81
|
636 |
translateKeyboardEvents ifTrue:[
|
|
637 |
xlatedKey := aView device translateKey:key.
|
|
638 |
] ifFalse:[
|
|
639 |
xlatedKey := key.
|
|
640 |
].
|
62
|
641 |
mouseAndKeyboard
|
72
|
642 |
addLast:(WindowEvent
|
|
643 |
for:aView
|
|
644 |
type:#keyRelease:x:y:
|
|
645 |
arguments:(Array with:xlatedKey with:x with:y)).
|
62
|
646 |
self notifyEventArrival
|
|
647 |
!
|
|
648 |
|
12
|
649 |
pointerEnter:state x:x y:y view:aView
|
46
|
650 |
"mouse cursor was moved into the view - this is sent from the device (Display)"
|
12
|
651 |
|
46
|
652 |
mouseAndKeyboard
|
72
|
653 |
addLast:(WindowEvent
|
|
654 |
for:aView
|
|
655 |
type:#pointerEnter:x:y:
|
|
656 |
arguments:(Array with:state with:x with:y)).
|
12
|
657 |
self notifyEventArrival
|
|
658 |
!
|
|
659 |
|
|
660 |
pointerLeave:state view:aView
|
46
|
661 |
"mouse cursor was moved out of the view - this is sent from the device (Display)"
|
12
|
662 |
|
46
|
663 |
mouseAndKeyboard
|
72
|
664 |
addLast:(WindowEvent
|
|
665 |
for:aView
|
|
666 |
type:#pointerLeave:
|
|
667 |
arguments:(Array with:state)).
|
12
|
668 |
self notifyEventArrival
|
|
669 |
!
|
|
670 |
|
47
|
671 |
configureX:x y:y width:w height:h view:aView
|
|
672 |
damage
|
72
|
673 |
addLast:(WindowEvent
|
|
674 |
for:aView
|
|
675 |
type:#configureX:y:width:height:
|
|
676 |
arguments:(Array with:x with:y with:w with:h)).
|
|
677 |
self notifyEventArrival
|
|
678 |
!
|
|
679 |
|
|
680 |
coveredBy:sibling view:aView
|
|
681 |
"aView was covered by one of its siblings"
|
|
682 |
|
|
683 |
damage
|
|
684 |
addLast:(WindowEvent
|
|
685 |
for:aView
|
|
686 |
type:#coveredBy:
|
|
687 |
arguments:(Array with:sibling)).
|
46
|
688 |
self notifyEventArrival
|
|
689 |
!
|
|
690 |
|
|
691 |
focusInView:aView
|
|
692 |
"view got input focus - this is sent from the device (Display)"
|
12
|
693 |
|
46
|
694 |
mouseAndKeyboard
|
72
|
695 |
addLast:(WindowEvent
|
|
696 |
for:aView
|
|
697 |
type:#focusIn).
|
46
|
698 |
self notifyEventArrival
|
|
699 |
!
|
|
700 |
|
|
701 |
focusOutView:aView
|
|
702 |
"view lost input focus - this is sent from the device (Display)"
|
|
703 |
|
|
704 |
mouseAndKeyboard
|
72
|
705 |
addLast:(WindowEvent
|
|
706 |
for:aView
|
|
707 |
type:#focusOut).
|
12
|
708 |
self notifyEventArrival
|
47
|
709 |
!
|
|
710 |
|
|
711 |
mappedView:aView
|
|
712 |
"view was mapped (from window manager)"
|
|
713 |
|
|
714 |
damage
|
72
|
715 |
addLast:(WindowEvent
|
|
716 |
for:aView
|
|
717 |
type:#mapped).
|
47
|
718 |
self notifyEventArrival
|
|
719 |
!
|
|
720 |
|
|
721 |
unmappedView:aView
|
|
722 |
"view was unmapped (from window manager)"
|
|
723 |
|
|
724 |
damage
|
72
|
725 |
addLast:(WindowEvent
|
|
726 |
for:aView
|
|
727 |
type:#unmapped).
|
47
|
728 |
self notifyEventArrival
|
|
729 |
!
|
|
730 |
|
|
731 |
terminateView:aView
|
|
732 |
"view should terminate (from window manager)"
|
|
733 |
|
|
734 |
self flushEventsFor:aView.
|
|
735 |
damage
|
72
|
736 |
addLast:(WindowEvent
|
|
737 |
for:aView
|
|
738 |
type:#terminate).
|
47
|
739 |
self notifyEventArrival
|
|
740 |
!
|
|
741 |
|
|
742 |
saveAndTerminateView:aView
|
|
743 |
"view should save & terminate (from window manager)"
|
|
744 |
|
|
745 |
self flushEventsFor:aView.
|
|
746 |
damage
|
72
|
747 |
addLast:(WindowEvent
|
|
748 |
for:aView
|
|
749 |
type:#saveAndTerminate).
|
47
|
750 |
self notifyEventArrival
|
|
751 |
!
|
|
752 |
|
|
753 |
destroyedView:aView
|
|
754 |
"view was destroyed (from window manager)"
|
|
755 |
|
|
756 |
"at this time, the view is already gone; remove
|
|
757 |
all pending events for this one ..."
|
|
758 |
|
|
759 |
self flushEventsFor:aView.
|
|
760 |
damage
|
72
|
761 |
addLast:(WindowEvent
|
|
762 |
for:aView
|
|
763 |
type:#destroyed).
|
47
|
764 |
self notifyEventArrival
|
12
|
765 |
! !
|
|
766 |
|
|
767 |
!WindowSensor methodsFor:'initialization'!
|
|
768 |
|
|
769 |
initialize
|
|
770 |
"initialize the event queues to empty"
|
|
771 |
|
|
772 |
damage := OrderedCollection new.
|
28
|
773 |
mouseAndKeyboard := OrderedCollection new.
|
|
774 |
gotExpose := true.
|
|
775 |
catchExpose := false.
|
47
|
776 |
compressMotionEvents := true.
|
|
777 |
ignoreUserInput := false.
|
81
|
778 |
translateKeyboardEvents := true
|
54
|
779 |
!
|
|
780 |
|
|
781 |
reinitialize
|
|
782 |
"reinitialize the event queues to empty; leave other setup as-is"
|
|
783 |
|
72
|
784 |
self flushUserEvents.
|
|
785 |
self flushExposeEvents.
|
54
|
786 |
gotExpose := true.
|
|
787 |
catchExpose := false.
|
0
|
788 |
! !
|
|
789 |
|
|
790 |
!WindowSensor methodsFor:'accessing'!
|
|
791 |
|
47
|
792 |
ignoreUserInput:aBoolean
|
|
793 |
ignoreUserInput := aBoolean
|
|
794 |
!
|
|
795 |
|
|
796 |
ignoreUserInput
|
|
797 |
^ ignoreUserInput
|
|
798 |
!
|
|
799 |
|
12
|
800 |
eventSemaphore:aSemaphore
|
|
801 |
"set the semaphore used to signal event arrival"
|
|
802 |
|
|
803 |
eventSemaphore := aSemaphore
|
|
804 |
!
|
|
805 |
|
|
806 |
eventSemaphore
|
|
807 |
"return the semaphore used to signal event arrival"
|
|
808 |
|
|
809 |
^ eventSemaphore
|
46
|
810 |
!
|
|
811 |
|
|
812 |
compressMotionEvents:aBoolean
|
|
813 |
compressMotionEvents := aBoolean
|
0
|
814 |
! !
|