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 |
|
92
|
24 |
$Header: /cvs/stx/stx/libview/Controller.st,v 1.10 1995-02-07 15:30:29 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 |
"
|
92
|
45 |
$Header: /cvs/stx/stx/libview/Controller.st,v 1.10 1995-02-07 15:30:29 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 |
|
|
101 |
!Controller methodsFor:'accessing'!
|
|
102 |
|
|
103 |
view:aView
|
|
104 |
"set my view"
|
|
105 |
|
|
106 |
view notNil ifTrue:[
|
80
|
107 |
model notNil ifTrue:[
|
|
108 |
model removeDependent:view
|
|
109 |
]
|
0
|
110 |
].
|
|
111 |
view := aView.
|
|
112 |
model notNil ifTrue:[
|
80
|
113 |
model addDependent:view
|
0
|
114 |
].
|
|
115 |
!
|
|
116 |
|
|
117 |
view
|
|
118 |
"return my view"
|
|
119 |
|
|
120 |
^ view
|
|
121 |
!
|
|
122 |
|
|
123 |
model:aModel
|
|
124 |
"set my model"
|
|
125 |
|
|
126 |
model notNil ifTrue:[
|
80
|
127 |
model removeDependent:view
|
0
|
128 |
].
|
|
129 |
model := aModel.
|
|
130 |
model notNil ifTrue:[model addDependent:view]
|
|
131 |
!
|
|
132 |
|
|
133 |
model
|
|
134 |
"return my model"
|
|
135 |
|
|
136 |
^ view model
|
80
|
137 |
! !
|
|
138 |
|
86
|
139 |
!Controller methodsFor:'event handling'!
|
0
|
140 |
|
80
|
141 |
redButtonActivity
|
|
142 |
"actually, this should be called 'leftButtonActivity'.
|
|
143 |
But for ST-80 compatibility ...."
|
12
|
144 |
|
80
|
145 |
^ self
|
0
|
146 |
!
|
|
147 |
|
80
|
148 |
yellowButtonActivity
|
|
149 |
"actually, this should be called 'middleButtonActivity'.
|
|
150 |
But for ST-80 compatibility ...."
|
0
|
151 |
|
89
|
152 |
|sym menu actionSelector|
|
|
153 |
|
|
154 |
"
|
|
155 |
try ST-80 style menus first:
|
|
156 |
if there is a model, and a menuSymbol is defined,
|
|
157 |
ask model for the menu and launch that if non-nil.
|
|
158 |
"
|
|
159 |
(model notNil
|
|
160 |
and:[(sym := view menuSymbol) notNil
|
|
161 |
and:[sym isSymbol]]) ifTrue:[
|
|
162 |
"
|
|
163 |
ask model for the menu
|
|
164 |
"
|
|
165 |
menu := model perform:sym.
|
|
166 |
menu notNil ifTrue:[
|
|
167 |
"
|
|
168 |
got one, launch the menu. It is supposed
|
|
169 |
to return an actionSelector.
|
|
170 |
"
|
|
171 |
actionSelector := menu startUp.
|
|
172 |
(actionSelector notNil
|
|
173 |
and:[actionSelector isSymbol]) ifTrue:[
|
|
174 |
model perform:actionSelector
|
|
175 |
]
|
|
176 |
].
|
|
177 |
^ self
|
|
178 |
].
|
|
179 |
view middleButtonMenu notNil ifTrue:[
|
|
180 |
view middleButtonMenu showAtPointer
|
|
181 |
]
|
12
|
182 |
!
|
|
183 |
|
80
|
184 |
blueButtonActivity
|
|
185 |
"actually, this should be called 'rightButtonActivity'.
|
|
186 |
But for ST-80 compatibility ...."
|
0
|
187 |
|
80
|
188 |
^ self
|
9
|
189 |
! !
|
|
190 |
|
80
|
191 |
!Controller methodsFor:'low level events'!
|
|
192 |
|
|
193 |
buttonPress:button x:x y:y
|
92
|
194 |
"a mouse button was pressed in my view.
|
|
195 |
Translate buttonPress events into similar ST-80 type
|
|
196 |
event messages. This method and/or these ST-80 methods
|
|
197 |
can be redefined in subclasses"
|
0
|
198 |
|
80
|
199 |
((button == 1) or:[button == #select]) ifTrue:[
|
|
200 |
self redButtonActivity
|
|
201 |
].
|
|
202 |
((button == 2) or:[button == #menu]) ifTrue:[
|
|
203 |
self yellowButtonActivity
|
|
204 |
].
|
|
205 |
(button == 3) ifTrue:[
|
|
206 |
self blueButtonActivity
|
|
207 |
]
|
|
208 |
!
|
0
|
209 |
|
80
|
210 |
buttonRelease:button x:x y:y
|
92
|
211 |
"a mouse button was released in my view; nothing done here"
|
|
212 |
|
80
|
213 |
^ self
|
|
214 |
!
|
|
215 |
|
|
216 |
buttonMotion:buttonMask x:x y:y
|
92
|
217 |
"mouse was moved with button pressed in my view; nothing done here"
|
|
218 |
|
80
|
219 |
^ self
|
|
220 |
!
|
|
221 |
|
|
222 |
pointerEnter:state x:x y:y
|
92
|
223 |
"mouse pointer entered my view; nothing done here"
|
|
224 |
|
80
|
225 |
^ self
|
|
226 |
!
|
|
227 |
|
|
228 |
pointerLeave:state
|
92
|
229 |
"mouse pointer left my view; nothing done here"
|
|
230 |
|
80
|
231 |
^ self
|
|
232 |
!
|
|
233 |
|
|
234 |
keyPress:key x:x y:y
|
92
|
235 |
"key was pressed in my view; nothing done here"
|
|
236 |
|
80
|
237 |
^ self
|
|
238 |
!
|
|
239 |
|
|
240 |
keyRelease:key x:x y:y
|
92
|
241 |
"key was released in my view; nothing done here"
|
|
242 |
|
80
|
243 |
^ self
|
0
|
244 |
! !
|