0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
80
|
3 |
All Rights Reserved
|
0
|
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 |
"
|
|
12 |
|
|
13 |
Object subclass:#Controller
|
134
|
14 |
instanceVariableNames:'model view sensor'
|
0
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
141
|
17 |
category:'Interface-Support-Controllers'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
Controller comment:'
|
46
|
21 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
80
|
22 |
All Rights Reserved
|
54
|
23 |
|
157
|
24 |
$Header: /cvs/stx/stx/libview/Controller.st,v 1.23 1995-07-23 02:25:33 claus Exp $
|
46
|
25 |
'!
|
0
|
26 |
|
46
|
27 |
!Controller class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
80
|
32 |
All Rights Reserved
|
0
|
33 |
|
46
|
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 |
!
|
0
|
42 |
|
46
|
43 |
version
|
|
44 |
"
|
157
|
45 |
$Header: /cvs/stx/stx/libview/Controller.st,v 1.23 1995-07-23 02:25:33 claus Exp $
|
46
|
46 |
"
|
|
47 |
!
|
0
|
48 |
|
46
|
49 |
documentation
|
|
50 |
"
|
|
51 |
Controllers can be used to controll the user-interactions
|
89
|
52 |
to a model which is shown in a view. For very simple views,
|
46
|
53 |
(and due to the evolution of Smalltalk/X) many view-classes have
|
|
54 |
the controller function integrated.
|
80
|
55 |
To allow both controller and non-controller operation, events are
|
|
56 |
sent directly to the view, if its controller instance variable
|
|
57 |
is nil. Otherwise, the controller gets the event.
|
89
|
58 |
For now (vsn 2.10.4) there are only a few view classes using controllers;
|
|
59 |
however, over time, more will be converted, since separating the controller
|
127
|
60 |
offers much more flexibility
|
|
61 |
(although view initialization becomes a bit more complex).
|
46
|
62 |
|
|
63 |
Instance variables:
|
80
|
64 |
view aView the view I controll
|
|
65 |
model aModel the model which is to be worked on
|
46
|
66 |
"
|
|
67 |
! !
|
0
|
68 |
|
89
|
69 |
!Controller class methodsFor:'instance creation'!
|
|
70 |
|
|
71 |
new
|
|
72 |
^ self basicNew initialize
|
|
73 |
! !
|
|
74 |
|
0
|
75 |
!Controller methodsFor:'initialize / release'!
|
|
76 |
|
|
77 |
initialize
|
|
78 |
"initialize the controller; subclasses should redefine
|
|
79 |
this and include a super initialize for proper initialization."
|
|
80 |
|
|
81 |
^ self
|
|
82 |
!
|
|
83 |
|
92
|
84 |
startUp
|
|
85 |
"startup the controller; this is sent when the view realizes,
|
|
86 |
right before it becomes visible.
|
|
87 |
Can be redefined in subclasses to do some startup action."
|
|
88 |
|
157
|
89 |
self controlInitialize.
|
92
|
90 |
!
|
|
91 |
|
0
|
92 |
release
|
92
|
93 |
"close down the controller; this is sent when the view is destroyed.
|
|
94 |
Can be redefined in subclasses to do some cleanup action. However,
|
140
|
95 |
these redefined methods should do a super release."
|
92
|
96 |
|
140
|
97 |
view notNil ifTrue:[view controller:nil].
|
0
|
98 |
view := nil.
|
|
99 |
model := nil
|
157
|
100 |
!
|
|
101 |
|
|
102 |
controlInitialize
|
|
103 |
^ self
|
0
|
104 |
! !
|
|
105 |
|
99
|
106 |
!Controller methodsFor:'ST-80 compatibility'!
|
|
107 |
|
|
108 |
open
|
|
109 |
"open my view"
|
|
110 |
|
|
111 |
view open
|
|
112 |
! !
|
|
113 |
|
0
|
114 |
!Controller methodsFor:'accessing'!
|
|
115 |
|
|
116 |
view:aView
|
|
117 |
"set my view"
|
|
118 |
|
|
119 |
view notNil ifTrue:[
|
80
|
120 |
model notNil ifTrue:[
|
|
121 |
model removeDependent:view
|
|
122 |
]
|
0
|
123 |
].
|
|
124 |
view := aView.
|
|
125 |
model notNil ifTrue:[
|
127
|
126 |
"/ model addDependent:view
|
|
127 |
view notNil ifTrue:[
|
|
128 |
view model:model
|
|
129 |
]
|
0
|
130 |
].
|
|
131 |
!
|
|
132 |
|
|
133 |
view
|
|
134 |
"return my view"
|
|
135 |
|
|
136 |
^ view
|
|
137 |
!
|
|
138 |
|
|
139 |
model:aModel
|
|
140 |
"set my model"
|
|
141 |
|
|
142 |
model notNil ifTrue:[
|
80
|
143 |
model removeDependent:view
|
0
|
144 |
].
|
|
145 |
model := aModel.
|
127
|
146 |
"/ model notNil ifTrue:[model addDependent:view]
|
0
|
147 |
!
|
|
148 |
|
|
149 |
model
|
|
150 |
"return my model"
|
|
151 |
|
127
|
152 |
^ model
|
|
153 |
!
|
|
154 |
|
|
155 |
sensor
|
|
156 |
"return my views sensor"
|
|
157 |
|
|
158 |
^ view sensor
|
123
|
159 |
!
|
|
160 |
|
|
161 |
menuHolder
|
134
|
162 |
"by default, the model has to provide the menu"
|
|
163 |
|
154
|
164 |
model isNil ifTrue:[^ view].
|
134
|
165 |
^ model
|
125
|
166 |
!
|
|
167 |
|
|
168 |
menuPerformer
|
134
|
169 |
"by default, the model is performing menu actions"
|
|
170 |
|
154
|
171 |
model isNil ifTrue:[^ view].
|
134
|
172 |
^ model
|
|
173 |
! !
|
|
174 |
|
|
175 |
!Controller methodsFor:'menus'!
|
|
176 |
|
|
177 |
yellowButtonMenu
|
|
178 |
"actually, this should be called 'middleButtonMenu'.
|
|
179 |
But for ST-80 compatibility ...."
|
|
180 |
|
|
181 |
|sym menuHolder m|
|
|
182 |
|
|
183 |
(m := view middleButtonMenu) notNil ifTrue:[
|
|
184 |
"/
|
|
185 |
"/ has been assigned a static middleButtonMenu
|
|
186 |
"/ (or a cached menu)
|
|
187 |
"/
|
|
188 |
^ m
|
|
189 |
].
|
|
190 |
|
|
191 |
menuHolder := self menuHolder.
|
|
192 |
|
|
193 |
"
|
|
194 |
try ST-80 style menus first:
|
137
|
195 |
if there is a model, and a menuMessage is defined,
|
134
|
196 |
ask model for the menu and launch that if non-nil.
|
|
197 |
"
|
|
198 |
(menuHolder notNil
|
137
|
199 |
and:[(sym := view menuMessage) notNil
|
134
|
200 |
and:[sym isSymbol]]) ifTrue:[
|
|
201 |
"
|
|
202 |
ask model for the menu
|
|
203 |
"
|
|
204 |
^ menuHolder perform:sym.
|
|
205 |
].
|
125
|
206 |
^ nil
|
80
|
207 |
! !
|
|
208 |
|
86
|
209 |
!Controller methodsFor:'event handling'!
|
0
|
210 |
|
80
|
211 |
redButtonActivity
|
|
212 |
"actually, this should be called 'leftButtonActivity'.
|
|
213 |
But for ST-80 compatibility ...."
|
12
|
214 |
|
80
|
215 |
^ self
|
0
|
216 |
!
|
|
217 |
|
80
|
218 |
yellowButtonActivity
|
|
219 |
"actually, this should be called 'middleButtonActivity'.
|
|
220 |
But for ST-80 compatibility ...."
|
0
|
221 |
|
154
|
222 |
|menu actionSelector menuPerformer|
|
123
|
223 |
|
134
|
224 |
menu := self yellowButtonMenu.
|
|
225 |
menu notNil ifTrue:[
|
|
226 |
menuPerformer := self menuPerformer.
|
154
|
227 |
|
134
|
228 |
"
|
|
229 |
got one, launch the menu. It is supposed
|
|
230 |
to return an actionSelector.
|
|
231 |
"
|
154
|
232 |
"
|
|
233 |
a temporary kludge: subMenus dont know about
|
|
234 |
actionSelectors yet ...
|
|
235 |
"
|
|
236 |
menu receiver isNil ifTrue:[
|
|
237 |
menu receiver:menuPerformer
|
|
238 |
] ifFalse:[
|
134
|
239 |
"
|
154
|
240 |
if the menu has an explicit receiver,
|
|
241 |
thats the one to do the work.
|
|
242 |
"
|
|
243 |
menuPerformer := menu receiver
|
|
244 |
].
|
134
|
245 |
actionSelector := menu startUp.
|
89
|
246 |
|
134
|
247 |
(actionSelector notNil
|
|
248 |
and:[actionSelector isSymbol]) ifTrue:[
|
|
249 |
menuPerformer perform:actionSelector
|
89
|
250 |
].
|
|
251 |
^ self
|
|
252 |
].
|
125
|
253 |
"
|
|
254 |
ST/X style static menus - going to be obsoleted ...
|
|
255 |
"
|
109
|
256 |
(menu := view middleButtonMenu) notNil ifTrue:[
|
|
257 |
menu showAtPointer
|
89
|
258 |
]
|
12
|
259 |
!
|
|
260 |
|
80
|
261 |
blueButtonActivity
|
|
262 |
"actually, this should be called 'rightButtonActivity'.
|
|
263 |
But for ST-80 compatibility ...."
|
0
|
264 |
|
80
|
265 |
^ self
|
9
|
266 |
! !
|
|
267 |
|
80
|
268 |
!Controller methodsFor:'low level events'!
|
|
269 |
|
|
270 |
buttonPress:button x:x y:y
|
92
|
271 |
"a mouse button was pressed in my view.
|
|
272 |
Translate buttonPress events into similar ST-80 type
|
|
273 |
event messages. This method and/or these ST-80 methods
|
|
274 |
can be redefined in subclasses"
|
0
|
275 |
|
80
|
276 |
((button == 1) or:[button == #select]) ifTrue:[
|
|
277 |
self redButtonActivity
|
|
278 |
].
|
|
279 |
((button == 2) or:[button == #menu]) ifTrue:[
|
|
280 |
self yellowButtonActivity
|
|
281 |
].
|
|
282 |
(button == 3) ifTrue:[
|
|
283 |
self blueButtonActivity
|
|
284 |
]
|
|
285 |
!
|
0
|
286 |
|
118
|
287 |
buttonMultiPress:button x:x y:y
|
|
288 |
"a mouse button was pressed again shortly after in my view"
|
|
289 |
|
|
290 |
^ self buttonPress:button x:x y:y
|
|
291 |
!
|
|
292 |
|
|
293 |
buttonShiftPress:button x:x y:y
|
|
294 |
"a mouse button was pressed again shortly after in my view"
|
|
295 |
|
|
296 |
^ self buttonPress:button x:x y:y
|
|
297 |
!
|
|
298 |
|
80
|
299 |
buttonRelease:button x:x y:y
|
92
|
300 |
"a mouse button was released in my view; nothing done here"
|
|
301 |
|
80
|
302 |
^ self
|
|
303 |
!
|
|
304 |
|
|
305 |
buttonMotion:buttonMask x:x y:y
|
92
|
306 |
"mouse was moved with button pressed in my view; nothing done here"
|
|
307 |
|
80
|
308 |
^ self
|
|
309 |
!
|
|
310 |
|
|
311 |
pointerEnter:state x:x y:y
|
92
|
312 |
"mouse pointer entered my view; nothing done here"
|
|
313 |
|
80
|
314 |
^ self
|
|
315 |
!
|
|
316 |
|
|
317 |
pointerLeave:state
|
92
|
318 |
"mouse pointer left my view; nothing done here"
|
|
319 |
|
80
|
320 |
^ self
|
|
321 |
!
|
|
322 |
|
109
|
323 |
focusIn
|
|
324 |
"my view got the keyboard focus; nothing done here"
|
|
325 |
|
|
326 |
^ self
|
|
327 |
!
|
|
328 |
|
|
329 |
focusOut
|
|
330 |
"my view lost keyboard focus; nothing done here"
|
|
331 |
|
|
332 |
^ self
|
|
333 |
!
|
|
334 |
|
80
|
335 |
keyPress:key x:x y:y
|
92
|
336 |
"key was pressed in my view; nothing done here"
|
|
337 |
|
80
|
338 |
^ self
|
|
339 |
!
|
|
340 |
|
|
341 |
keyRelease:key x:x y:y
|
92
|
342 |
"key was released in my view; nothing done here"
|
|
343 |
|
80
|
344 |
^ self
|
153
|
345 |
!
|
|
346 |
|
|
347 |
devicePointerEnter:state x:x y:y
|
|
348 |
"this is the low-level (untransformed) event as received
|
|
349 |
from the device (i.e. coordinates are in device coordinates).
|
|
350 |
If there is a transformation, apply the inverse
|
|
351 |
and send a pointerEnter with the logical coordinates."
|
|
352 |
|
|
353 |
|lx ly trans|
|
|
354 |
|
|
355 |
lx := x.
|
|
356 |
ly := y.
|
|
357 |
(trans := view transformation) notNil ifTrue:[
|
|
358 |
lx := trans applyInverseToX:lx.
|
|
359 |
ly := trans applyInverseToY:ly.
|
|
360 |
].
|
|
361 |
self pointerEnter:state x:lx y:ly
|
|
362 |
!
|
|
363 |
|
|
364 |
deviceKeyPress:key x:x y:y
|
|
365 |
"this is the low-level (untransformed) event as received
|
|
366 |
from the device (i.e. coordinates are in device coordinates).
|
|
367 |
If there is a transformation, apply the inverse
|
|
368 |
and send a keyPress with the logical coordinates."
|
|
369 |
|
|
370 |
|lx ly trans|
|
|
371 |
|
|
372 |
lx := x.
|
|
373 |
ly := y.
|
|
374 |
(trans := view transformation) notNil ifTrue:[
|
|
375 |
lx := trans applyInverseToX:lx.
|
|
376 |
ly := trans applyInverseToY:ly.
|
|
377 |
].
|
|
378 |
self keyPress:key x:lx y:ly
|
|
379 |
!
|
|
380 |
|
|
381 |
deviceKeyRelease:key x:x y:y
|
|
382 |
"this is the low-level (untransformed) event as received
|
|
383 |
from the device (i.e. coordinates are in device coordinates).
|
|
384 |
If there is a transformation, apply the inverse
|
|
385 |
and send a keyRelease with the logical coordinates."
|
|
386 |
|
|
387 |
|lx ly trans|
|
|
388 |
|
|
389 |
lx := x.
|
|
390 |
ly := y.
|
|
391 |
(trans := view transformation) notNil ifTrue:[
|
|
392 |
lx := trans applyInverseToX:lx.
|
|
393 |
ly := trans applyInverseToY:ly.
|
|
394 |
].
|
|
395 |
self keyRelease:key x:lx y:ly
|
|
396 |
!
|
|
397 |
|
|
398 |
deviceButtonPress:button x:x y:y
|
|
399 |
"this is the low-level (untransformed) event as received
|
|
400 |
from the device (i.e. coordinates are in device coordinates).
|
|
401 |
If there is a transformation, apply the inverse
|
|
402 |
and send a buttonPress with the logical coordinates."
|
|
403 |
|
|
404 |
|lx ly trans|
|
|
405 |
|
|
406 |
lx := x.
|
|
407 |
ly := y.
|
|
408 |
(trans := view transformation) notNil ifTrue:[
|
|
409 |
lx := trans applyInverseToX:lx.
|
|
410 |
ly := trans applyInverseToY:ly.
|
|
411 |
].
|
|
412 |
self buttonPress:button x:lx y:ly
|
|
413 |
!
|
|
414 |
|
|
415 |
deviceButtonRelease:button x:x y:y
|
|
416 |
"this is the low-level (untransformed) event as received
|
|
417 |
from the device (i.e. coordinates are in device coordinates).
|
|
418 |
If there is a transformation, apply the inverse
|
|
419 |
and send a buttonRelease with the logical coordinates."
|
|
420 |
|
|
421 |
|lx ly trans|
|
|
422 |
|
|
423 |
lx := x.
|
|
424 |
ly := y.
|
|
425 |
(trans := view transformation) notNil ifTrue:[
|
|
426 |
lx := trans applyInverseToX:lx.
|
|
427 |
ly := trans applyInverseToY:ly.
|
|
428 |
].
|
|
429 |
self buttonRelease:button x:lx y:ly
|
|
430 |
!
|
|
431 |
|
|
432 |
deviceButtonMotion:state x:x y:y
|
|
433 |
"this is the low-level (untransformed) event as received
|
|
434 |
from the device (i.e. coordinates are in device coordinates).
|
|
435 |
If there is a transformation, apply the inverse
|
|
436 |
and send a buttonMotion with the logical coordinates."
|
|
437 |
|
|
438 |
|lx ly trans|
|
|
439 |
|
|
440 |
lx := x.
|
|
441 |
ly := y.
|
|
442 |
(trans := view transformation) notNil ifTrue:[
|
|
443 |
lx := trans applyInverseToX:lx.
|
|
444 |
ly := trans applyInverseToY:ly.
|
|
445 |
].
|
|
446 |
self buttonMotion:state x:lx y:ly
|
0
|
447 |
! !
|