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
|
80
|
14 |
instanceVariableNames:'model view'
|
0
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Interface-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
Controller comment:'
|
46
|
21 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
80
|
22 |
All Rights Reserved
|
54
|
23 |
|
99
|
24 |
$Header: /cvs/stx/stx/libview/Controller.st,v 1.11 1995-02-16 16:29:32 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 |
"
|
99
|
45 |
$Header: /cvs/stx/stx/libview/Controller.st,v 1.11 1995-02-16 16:29:32 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
|
|
60 |
offers much more flexibility (although view initialization becomes a bit more complex).
|
46
|
61 |
|
|
62 |
Instance variables:
|
80
|
63 |
view aView the view I controll
|
|
64 |
model aModel the model which is to be worked on
|
46
|
65 |
"
|
|
66 |
! !
|
0
|
67 |
|
89
|
68 |
!Controller class methodsFor:'instance creation'!
|
|
69 |
|
|
70 |
new
|
|
71 |
^ self basicNew initialize
|
|
72 |
! !
|
|
73 |
|
0
|
74 |
!Controller methodsFor:'initialize / release'!
|
|
75 |
|
|
76 |
initialize
|
|
77 |
"initialize the controller; subclasses should redefine
|
|
78 |
this and include a super initialize for proper initialization."
|
|
79 |
|
|
80 |
^ self
|
|
81 |
!
|
|
82 |
|
92
|
83 |
startUp
|
|
84 |
"startup the controller; this is sent when the view realizes,
|
|
85 |
right before it becomes visible.
|
|
86 |
Can be redefined in subclasses to do some startup action."
|
|
87 |
|
|
88 |
^ self
|
|
89 |
!
|
|
90 |
|
0
|
91 |
release
|
92
|
92 |
"close down the controller; this is sent when the view is destroyed.
|
|
93 |
Can be redefined in subclasses to do some cleanup action. However,
|
|
94 |
these redfined methods should do a super release."
|
|
95 |
|
0
|
96 |
view controller:nil.
|
|
97 |
view := nil.
|
|
98 |
model := nil
|
|
99 |
! !
|
|
100 |
|
99
|
101 |
!Controller methodsFor:'ST-80 compatibility'!
|
|
102 |
|
|
103 |
open
|
|
104 |
"open my view"
|
|
105 |
|
|
106 |
view open
|
|
107 |
! !
|
|
108 |
|
0
|
109 |
!Controller methodsFor:'accessing'!
|
|
110 |
|
|
111 |
view:aView
|
|
112 |
"set my view"
|
|
113 |
|
|
114 |
view notNil ifTrue:[
|
80
|
115 |
model notNil ifTrue:[
|
|
116 |
model removeDependent:view
|
|
117 |
]
|
0
|
118 |
].
|
|
119 |
view := aView.
|
|
120 |
model notNil ifTrue:[
|
80
|
121 |
model addDependent:view
|
0
|
122 |
].
|
|
123 |
!
|
|
124 |
|
|
125 |
view
|
|
126 |
"return my view"
|
|
127 |
|
|
128 |
^ view
|
|
129 |
!
|
|
130 |
|
|
131 |
model:aModel
|
|
132 |
"set my model"
|
|
133 |
|
|
134 |
model notNil ifTrue:[
|
80
|
135 |
model removeDependent:view
|
0
|
136 |
].
|
|
137 |
model := aModel.
|
|
138 |
model notNil ifTrue:[model addDependent:view]
|
|
139 |
!
|
|
140 |
|
|
141 |
model
|
|
142 |
"return my model"
|
|
143 |
|
|
144 |
^ view model
|
80
|
145 |
! !
|
|
146 |
|
86
|
147 |
!Controller methodsFor:'event handling'!
|
0
|
148 |
|
80
|
149 |
redButtonActivity
|
|
150 |
"actually, this should be called 'leftButtonActivity'.
|
|
151 |
But for ST-80 compatibility ...."
|
12
|
152 |
|
80
|
153 |
^ self
|
0
|
154 |
!
|
|
155 |
|
80
|
156 |
yellowButtonActivity
|
|
157 |
"actually, this should be called 'middleButtonActivity'.
|
|
158 |
But for ST-80 compatibility ...."
|
0
|
159 |
|
89
|
160 |
|sym menu actionSelector|
|
|
161 |
|
|
162 |
"
|
|
163 |
try ST-80 style menus first:
|
|
164 |
if there is a model, and a menuSymbol is defined,
|
|
165 |
ask model for the menu and launch that if non-nil.
|
|
166 |
"
|
|
167 |
(model notNil
|
|
168 |
and:[(sym := view menuSymbol) notNil
|
|
169 |
and:[sym isSymbol]]) ifTrue:[
|
|
170 |
"
|
|
171 |
ask model for the menu
|
|
172 |
"
|
|
173 |
menu := model perform:sym.
|
|
174 |
menu notNil ifTrue:[
|
|
175 |
"
|
|
176 |
got one, launch the menu. It is supposed
|
|
177 |
to return an actionSelector.
|
|
178 |
"
|
|
179 |
actionSelector := menu startUp.
|
|
180 |
(actionSelector notNil
|
|
181 |
and:[actionSelector isSymbol]) ifTrue:[
|
|
182 |
model perform:actionSelector
|
|
183 |
]
|
|
184 |
].
|
|
185 |
^ self
|
|
186 |
].
|
|
187 |
view middleButtonMenu notNil ifTrue:[
|
|
188 |
view middleButtonMenu showAtPointer
|
|
189 |
]
|
12
|
190 |
!
|
|
191 |
|
80
|
192 |
blueButtonActivity
|
|
193 |
"actually, this should be called 'rightButtonActivity'.
|
|
194 |
But for ST-80 compatibility ...."
|
0
|
195 |
|
80
|
196 |
^ self
|
9
|
197 |
! !
|
|
198 |
|
80
|
199 |
!Controller methodsFor:'low level events'!
|
|
200 |
|
|
201 |
buttonPress:button x:x y:y
|
92
|
202 |
"a mouse button was pressed in my view.
|
|
203 |
Translate buttonPress events into similar ST-80 type
|
|
204 |
event messages. This method and/or these ST-80 methods
|
|
205 |
can be redefined in subclasses"
|
0
|
206 |
|
80
|
207 |
((button == 1) or:[button == #select]) ifTrue:[
|
|
208 |
self redButtonActivity
|
|
209 |
].
|
|
210 |
((button == 2) or:[button == #menu]) ifTrue:[
|
|
211 |
self yellowButtonActivity
|
|
212 |
].
|
|
213 |
(button == 3) ifTrue:[
|
|
214 |
self blueButtonActivity
|
|
215 |
]
|
|
216 |
!
|
0
|
217 |
|
80
|
218 |
buttonRelease:button x:x y:y
|
92
|
219 |
"a mouse button was released in my view; nothing done here"
|
|
220 |
|
80
|
221 |
^ self
|
|
222 |
!
|
|
223 |
|
|
224 |
buttonMotion:buttonMask x:x y:y
|
92
|
225 |
"mouse was moved with button pressed in my view; nothing done here"
|
|
226 |
|
80
|
227 |
^ self
|
|
228 |
!
|
|
229 |
|
|
230 |
pointerEnter:state x:x y:y
|
92
|
231 |
"mouse pointer entered my view; nothing done here"
|
|
232 |
|
80
|
233 |
^ self
|
|
234 |
!
|
|
235 |
|
|
236 |
pointerLeave:state
|
92
|
237 |
"mouse pointer left my view; nothing done here"
|
|
238 |
|
80
|
239 |
^ self
|
|
240 |
!
|
|
241 |
|
|
242 |
keyPress:key x:x y:y
|
92
|
243 |
"key was pressed in my view; nothing done here"
|
|
244 |
|
80
|
245 |
^ self
|
|
246 |
!
|
|
247 |
|
|
248 |
keyRelease:key x:x y:y
|
92
|
249 |
"key was released in my view; nothing done here"
|
|
250 |
|
80
|
251 |
^ self
|
0
|
252 |
! !
|