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:#WindowEvent
|
72
|
14 |
instanceVariableNames:'view type arguments'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Interface-Support'
|
11
|
18 |
!
|
|
19 |
|
54
|
20 |
WindowEvent comment:'
|
|
21 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
22 |
All Rights Reserved
|
54
|
23 |
|
89
|
24 |
$Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.11 1995-02-06 00:38:02 claus Exp $
|
54
|
25 |
'!
|
|
26 |
|
46
|
27 |
!WindowEvent 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 |
"
|
89
|
45 |
$Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.11 1995-02-06 00:38:02 claus Exp $
|
46
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
Instances of WindowEvent are created for every event coming from
|
72
|
52 |
the graphics device, to be handled by a windowGroup.
|
|
53 |
Usually, they are queued by a sensor, and processed in some event loop
|
|
54 |
in the window group.
|
46
|
55 |
"
|
|
56 |
! !
|
|
57 |
|
11
|
58 |
!WindowEvent class methodsFor:'instance creation'!
|
|
59 |
|
|
60 |
for:aView type:aSymbol arguments:argArray
|
|
61 |
"create and return a new windowEvent for sending
|
|
62 |
aSymbol-message with arguments to aView"
|
|
63 |
|
46
|
64 |
^ (self new) for:aView type:aSymbol arguments:argArray
|
|
65 |
!
|
|
66 |
|
72
|
67 |
for:aView type:aSymbol
|
|
68 |
"create and return a new windowEvent for sending
|
|
69 |
aSymbol-message with no arguments to aView"
|
|
70 |
|
|
71 |
^ (self new) for:aView type:aSymbol arguments:#()
|
|
72 |
!
|
|
73 |
|
46
|
74 |
damageFor:aView rectangle:aRectangle
|
|
75 |
"create and return a new damage Event for aRectangle
|
|
76 |
in aView"
|
|
77 |
|
|
78 |
^ (self new) for:aView type:#damage arguments:aRectangle
|
|
79 |
|
11
|
80 |
! !
|
|
81 |
|
72
|
82 |
!WindowEvent methodsFor:'queries'!
|
|
83 |
|
|
84 |
isKeyEvent
|
|
85 |
"return true, if this event is a keyboard event"
|
|
86 |
|
89
|
87 |
^ (type == #keyPress:x:y:) or:[type == #keyRelease:x:y:]
|
|
88 |
!
|
|
89 |
|
|
90 |
isKeyPressEvent
|
|
91 |
"return true, if this event is a keyboard event"
|
|
92 |
|
|
93 |
^ (type == #keyPress:x:y:)
|
|
94 |
!
|
|
95 |
|
|
96 |
isButtonEvent
|
|
97 |
"return true, if this event is a button event"
|
|
98 |
|
|
99 |
^ (type == #buttonPress:x:y:)
|
|
100 |
or:[type == #buttonRelease:x:y:
|
|
101 |
or:[type == #'buttonShiftPress:x:y:'
|
|
102 |
or:[type == #'buttonMultiPress:x:y:'
|
|
103 |
or:[type == #'buttonMotion:x:y:']]]]
|
72
|
104 |
!
|
|
105 |
|
|
106 |
isDamage
|
|
107 |
"return true, if this is a damage event"
|
|
108 |
|
|
109 |
^ type == #damage
|
|
110 |
! !
|
|
111 |
|
28
|
112 |
!WindowEvent methodsFor:'accessing'!
|
|
113 |
|
|
114 |
view
|
|
115 |
"return the view, for which the event is for"
|
|
116 |
|
|
117 |
^ view
|
|
118 |
!
|
|
119 |
|
72
|
120 |
view:aView
|
|
121 |
"set the view, for which the event is for"
|
|
122 |
|
|
123 |
view := aView
|
|
124 |
!
|
|
125 |
|
28
|
126 |
type
|
|
127 |
"return the type of the event"
|
|
128 |
|
|
129 |
^ type
|
|
130 |
!
|
|
131 |
|
|
132 |
arguments
|
|
133 |
"return the arguments of the event"
|
|
134 |
|
|
135 |
^ arguments
|
|
136 |
!
|
|
137 |
|
|
138 |
arguments:anArray
|
|
139 |
"set the arguments"
|
|
140 |
|
|
141 |
arguments := anArray
|
46
|
142 |
!
|
|
143 |
|
|
144 |
rectangle
|
|
145 |
"return the damage rectangle"
|
|
146 |
|
|
147 |
^ arguments "consider this a kludge"
|
89
|
148 |
!
|
|
149 |
|
|
150 |
key
|
|
151 |
"return the key of the key-event. For non key-events, nil is returned."
|
|
152 |
|
|
153 |
((type == #keyPress:x:y:)
|
|
154 |
or:[type == #keyRelease:x:y:]) ifTrue:[
|
|
155 |
^ arguments at:1
|
|
156 |
].
|
|
157 |
^ nil
|
28
|
158 |
! !
|
|
159 |
|
11
|
160 |
!WindowEvent methodsFor:'sending'!
|
|
161 |
|
|
162 |
sendEvent
|
81
|
163 |
"forward the event represented by the receiver to the delegate,
|
89
|
164 |
the controller or the view. Only messages which are understood by
|
|
165 |
the delegate are forwarded.
|
78
|
166 |
Delegated messages get the original view as an extra argument."
|
11
|
167 |
|
89
|
168 |
self sendEventWithFocusOn:nil
|
|
169 |
!
|
|
170 |
|
|
171 |
sendEventWithFocusOn:focusView
|
|
172 |
"forward the event represented by the receiver to the delegate,
|
|
173 |
the controller or the view. If focusView is nonNil, and its a keyboard
|
|
174 |
event, the event is forwarded to it (but not if there is a delegate).
|
|
175 |
If there is a delegate, only messages which are understood by it are
|
|
176 |
forwarded. Delegated messages get the original view as an extra argument.
|
|
177 |
Delegation has higher priority than both controller or focusView
|
|
178 |
forwarding."
|
|
179 |
|
81
|
180 |
|delegate selector eventReceiver controller|
|
11
|
181 |
|
78
|
182 |
selector := type.
|
89
|
183 |
|
78
|
184 |
delegate := view delegate.
|
|
185 |
delegate notNil ifTrue:[
|
|
186 |
"
|
|
187 |
what a kludge - sending to delegate needs another
|
|
188 |
selector and an additional argument.
|
|
189 |
have to edit the selector ...
|
|
190 |
"
|
|
191 |
(selector endsWith:':') ifTrue:[
|
|
192 |
selector := (selector , 'view:') asSymbol.
|
|
193 |
] ifFalse:[
|
|
194 |
selector := (selector , 'View:') asSymbol.
|
|
195 |
].
|
89
|
196 |
(delegate respondsTo:selector) ifTrue:[
|
|
197 |
"
|
|
198 |
mhmh have to convert to logical coordinates ...
|
|
199 |
"
|
|
200 |
view transformation notNil ifTrue:[
|
|
201 |
(#(
|
|
202 |
#'buttonPress:x:y:'
|
|
203 |
#'buttonRelease:x:y:'
|
|
204 |
#'buttonShiftPress:x:y:'
|
|
205 |
#'buttonMultiPress:x:y:'
|
|
206 |
#'buttonMotion:x:y:'
|
|
207 |
#'keyPress:x:y:'
|
|
208 |
#'keyRelease:x:y:'
|
|
209 |
#'pointerEnter:x:y:'
|
|
210 |
#'exposeX:y:width:height:'
|
|
211 |
#'graphicExposeX:y:width:height:'
|
|
212 |
)includes:type) ifTrue:[
|
|
213 |
arguments at:2 put:(view transformation applyInverseToX:(arguments at:2)).
|
|
214 |
arguments at:3 put:(view transformation applyInverseToY:(arguments at:3)).
|
|
215 |
(#(
|
|
216 |
#'exposeX:y:width:height:'
|
|
217 |
#'graphicExposeX:y:width:height:'
|
|
218 |
)includes:type) ifTrue:[
|
|
219 |
arguments at:4 put:(view transformation applyInverseScaleX:(arguments at:4)).
|
|
220 |
arguments at:5 put:(view transformation applyInverseScaleY:(arguments at:5)).
|
|
221 |
].
|
|
222 |
].
|
|
223 |
].
|
|
224 |
arguments isNil ifTrue:[
|
|
225 |
delegate perform:selector with:view
|
|
226 |
] ifFalse:[
|
|
227 |
delegate perform:selector withArguments:(arguments copyWith:view)
|
|
228 |
].
|
|
229 |
^ self
|
|
230 |
].
|
|
231 |
selector := type.
|
|
232 |
].
|
|
233 |
|
|
234 |
"
|
|
235 |
if there is a controller, that one gets all user events
|
|
236 |
"
|
|
237 |
eventReceiver := view.
|
|
238 |
(controller := view controller) notNil ifTrue:[
|
|
239 |
(#(
|
|
240 |
#'buttonPress:x:y:'
|
|
241 |
#'buttonRelease:x:y:'
|
|
242 |
#'buttonShiftPress:x:y:'
|
|
243 |
#'buttonMultiPress:x:y:'
|
|
244 |
#'buttonMotion:x:y:'
|
|
245 |
#'keyPress:x:y:'
|
|
246 |
#'keyRelease:x:y:'
|
|
247 |
#'focusIn'
|
|
248 |
#'focusOut'
|
|
249 |
#'pointerEnter:x:y:'
|
|
250 |
#'pointerLeave:'
|
|
251 |
) includes:selector) ifTrue:[
|
|
252 |
eventReceiver := controller.
|
72
|
253 |
]
|
89
|
254 |
].
|
|
255 |
|
|
256 |
"
|
|
257 |
if there is a focusView, and its a keyboard event, pass it
|
|
258 |
to that view (or its controller). In this case, some coordinate which is outside of
|
|
259 |
the focusView is passed as x/y coordinates.
|
|
260 |
"
|
|
261 |
focusView notNil ifTrue:[
|
|
262 |
(#(#'keyPress:x:y:'
|
|
263 |
#'keyRelease:x:y:'
|
|
264 |
)includes:selector) ifTrue:[
|
|
265 |
eventReceiver := focusView.
|
|
266 |
(controller := focusView controller) notNil ifTrue:[
|
81
|
267 |
eventReceiver := controller.
|
89
|
268 |
].
|
|
269 |
eventReceiver perform:selector
|
|
270 |
withArguments:(Array with:(arguments at:1)
|
|
271 |
with:-1
|
|
272 |
with:-1).
|
|
273 |
^ self
|
|
274 |
]
|
|
275 |
].
|
81
|
276 |
|
89
|
277 |
"
|
|
278 |
another one:
|
|
279 |
if the view has a transformation, edit the selector
|
|
280 |
from #foo to #deviceFoo...
|
|
281 |
This allows the view to handle the event either in device or
|
|
282 |
logical coordinates. (since the deviceFoo-messages default implementation
|
|
283 |
in PseudoView translates and resends).
|
|
284 |
Actually, I could always send deviceXXX without speed penalty
|
|
285 |
(event sending is no high frequency operation), but that just adds
|
|
286 |
another context to any debuggers walkback, making things less clear.
|
|
287 |
"
|
|
288 |
view transformation notNil ifTrue:[
|
|
289 |
(#(
|
|
290 |
#'buttonPress:x:y:'
|
|
291 |
#'buttonRelease:x:y:'
|
|
292 |
#'buttonShiftPress:x:y:'
|
|
293 |
#'buttonMultiPress:x:y:'
|
|
294 |
#'buttonMotion:x:y:'
|
|
295 |
#'keyPress:x:y:'
|
|
296 |
#'keyRelease:x:y:'
|
|
297 |
#'exposeX:y:width:height:'
|
|
298 |
#'graphicExposeX:y:width:height:'
|
|
299 |
#'pointerEnter:x:y:'
|
|
300 |
) includes:selector) ifTrue:[
|
|
301 |
selector := selector asString.
|
|
302 |
selector at:1 put:(selector at:1) asUppercase.
|
|
303 |
selector := ('device' , selector) asSymbol
|
|
304 |
]
|
|
305 |
].
|
|
306 |
eventReceiver perform:selector withArguments:arguments
|
11
|
307 |
! !
|
|
308 |
|
|
309 |
!WindowEvent methodsFor:'private accessing'!
|
|
310 |
|
|
311 |
for:aView type:aSymbol arguments:argArray
|
|
312 |
"set the instances of the window event"
|
|
313 |
|
|
314 |
view := aView.
|
|
315 |
type := aSymbol.
|
|
316 |
arguments := argArray
|
|
317 |
! !
|