author | Stefan Vogel <sv@exept.de> |
Thu, 02 Jan 1997 17:29:06 +0100 | |
changeset 1149 | a3a75ffb29ce |
parent 1147 | 83ed804938e7 |
child 1151 | 1a3682212ea9 |
permissions | -rw-r--r-- |
0 | 1 |
" |
6 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
72 | 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 |
||
135 | 13 |
SimpleView subclass:#View |
1146
0167191529dd
moved menuHolder/menuPerformer up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
621
diff
changeset
|
14 |
instanceVariableNames:'model aspectMsg changeMsg menuMsg menuHolder menuPerformer' |
616 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
17 |
category:'Views-Basic' |
|
0 | 18 |
! |
19 |
||
2 | 20 |
!View class methodsFor:'documentation'! |
41 | 21 |
|
46 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
72 | 25 |
All Rights Reserved |
46 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
41 | 36 |
documentation |
2 | 37 |
" |
135 | 38 |
this class adds provisions for views which show or work on a model. |
39 |
This functionality used to be in View, but has been extracted into SimpleView and |
|
40 |
this new View class, to take some of the stuff out of views which do not need |
|
41 |
this functionality (i.e. all views which do only geometry management). |
|
82 | 42 |
Instances of View are seldom used, most views in the system inherit |
43 |
from this class. |
|
41 | 44 |
|
616 | 45 |
[Instance variables:] |
46 |
model <nil | any> the model (if any) |
|
41 | 47 |
|
616 | 48 |
aspectMsg <nil | Symbol> the aspect; typically |
49 |
dependentViews react on changes |
|
50 |
of this aspect and update their contents. |
|
51 |
||
52 |
changeMsg <nil | Symbol> the changeMessage; typically |
|
53 |
dependentViews send this message to |
|
54 |
the model to tell it about changes. |
|
140 | 55 |
|
616 | 56 |
menuMsg <nil | Symbol> the menuMessage; typically |
57 |
dependentViews send this message to |
|
58 |
the model to ask for a popup menu. |
|
59 |
Some classes allow setting an explicit |
|
60 |
menuHolder and menuPerformer. |
|
61 |
||
62 |
[see also:] |
|
621 | 63 |
StandardSystemView TopView DialogBox |
616 | 64 |
WindowGroup |
621 | 65 |
Model ValueHolder |
616 | 66 |
( introduction to view programming :html: programming/viewintro.html ) |
67 |
||
140 | 68 |
|
616 | 69 |
[author:] |
70 |
Claus Gittinger |
|
71 |
" |
|
72 |
! |
|
73 |
||
74 |
examples |
|
75 |
" |
|
76 |
a subView in a topView: |
|
621 | 77 |
[exBegin] |
616 | 78 |
|top v| |
140 | 79 |
|
616 | 80 |
topView := StandardSystemView new. |
81 |
v := View new. |
|
82 |
v origin:0.25 @ 0.25 corner:0.75 @ 0.75. |
|
83 |
top addSubView:v. |
|
84 |
top open |
|
621 | 85 |
[exEnd] |
616 | 86 |
|
87 |
||
88 |
the same, a bit more compact: |
|
621 | 89 |
[exBegin] |
616 | 90 |
|top v| |
91 |
||
92 |
topView := StandardSystemView new. |
|
93 |
v := View origin:0.25 @ 0.25 corner:0.75 @ 0.75 in:topView. |
|
94 |
top open |
|
621 | 95 |
[exEnd] |
96 |
||
2 | 97 |
" |
98 |
! ! |
|
0 | 99 |
|
118 | 100 |
!View class methodsFor:'instance creation'! |
101 |
||
269 | 102 |
model:aModel |
103 |
"st-80 style view creation: create a new view and set its model" |
|
104 |
||
105 |
^ self new model:aModel |
|
106 |
! |
|
107 |
||
140 | 108 |
on:aModel aspect:aspectMsg |
109 |
"st-80 style view creation: create a new view, set its model |
|
110 |
and selectors for aspect" |
|
111 |
||
112 |
^ self new |
|
113 |
on:aModel |
|
114 |
aspect:aspectMsg |
|
115 |
! |
|
116 |
||
117 |
on:aModel aspect:aspectMsg change:changeMsg |
|
118 |
"st-80 style view creation: create a new view, set its model |
|
119 |
and selectors for aspect and change" |
|
120 |
||
121 |
^ self new |
|
122 |
on:aModel |
|
123 |
aspect:aspectMsg |
|
124 |
change:changeMsg |
|
125 |
! |
|
126 |
||
135 | 127 |
on:aModel aspect:aspectMsg change:changeMsg menu:menuMsg |
118 | 128 |
"st-80 style view creation: create a new view, set its model |
140 | 129 |
and selectors for aspect, change and menu" |
118 | 130 |
|
135 | 131 |
^ self new |
132 |
on:aModel |
|
133 |
aspect:aspectMsg |
|
134 |
change:changeMsg |
|
135 |
menu:menuMsg |
|
118 | 136 |
! |
137 |
||
269 | 138 |
on:aModel aspect:aspectMsg menu:menuMsg |
139 |
"st-80 style view creation: create a new view, set its model |
|
140 |
and selectors for aspect and menu" |
|
118 | 141 |
|
269 | 142 |
^ self new |
143 |
on:aModel |
|
144 |
aspect:aspectMsg |
|
145 |
menu:menuMsg |
|
118 | 146 |
! ! |
147 |
||
123 | 148 |
!View class methodsFor:'defaults'! |
149 |
||
140 | 150 |
defaultAspectMessage |
135 | 151 |
"subclasses which by default do NOT want to be informed about changed |
152 |
models should redefine this to return nil" |
|
118 | 153 |
|
135 | 154 |
^ #value |
0 | 155 |
! |
156 |
||
140 | 157 |
defaultChangeMessage |
135 | 158 |
"subclasses which by default do NOT want to inform the model |
159 |
should redefine this to return nil" |
|
0 | 160 |
|
135 | 161 |
^ #value: |
0 | 162 |
! ! |
163 |
||
170 | 164 |
!View methodsFor:'accessing-channels'! |
165 |
||
166 |
setupChannel:newChannel for:changeSelector withOld:oldChannel |
|
167 |
"common code to change a channel" |
|
168 |
||
169 |
|oldValue| |
|
170 |
||
171 |
oldChannel notNil ifTrue:[ |
|
321
f31da2a1d387
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
269
diff
changeset
|
172 |
oldChannel retractInterestsFor:self. |
170 | 173 |
oldValue := oldChannel value. |
174 |
]. |
|
175 |
newChannel onChangeSend:changeSelector to:self. |
|
176 |
self perform:changeSelector. |
|
177 |
^ newChannel |
|
178 |
! ! |
|
179 |
||
269 | 180 |
!View methodsFor:'accessing-menus'! |
181 |
||
182 |
menuHolder |
|
183 |
"who has the menu ? |
|
1147
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
184 |
If no explicit menuHolder was defined, its the model if I have one. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
185 |
Otherwise, its the menuHolder (if nonNil) or mySelf. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
186 |
The menuHolder is supposed to return a popUpMenu when asked via the |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
187 |
menuMessage." |
269 | 188 |
|
1147
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
189 |
menuHolder notNil ifTrue:[^ menuHolder]. |
269 | 190 |
model notNil ifTrue:[^ model]. |
191 |
^ self |
|
1147
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
192 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
193 |
"Modified: 23.12.1996 / 13:56:55 / cg" |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
194 |
! |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
195 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
196 |
menuHolder:anObject |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
197 |
"change the one that provides the menu (via menuMsg)." |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
198 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
199 |
menuHolder := anObject |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
200 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
201 |
"Created: 23.12.1996 / 13:54:33 / cg" |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
202 |
! |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
203 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
204 |
menuMessage |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
205 |
"Return the symbol sent to the model to aquire the menu" |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
206 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
207 |
^ menuMsg |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
208 |
! |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
209 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
210 |
menuMessage:aSymbol |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
211 |
"ST-80 style menus: If a views menuSymbol is nonNil, it |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
212 |
will send it to its model when the middleButton is pressed. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
213 |
That method should return nil or the menu to be shown. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
214 |
This is useful for very dynamic menus, where it does not |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
215 |
make sense to define an initial menu. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
216 |
This is the same as #menu: which was added for ST-80 compatibility." |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
217 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
218 |
menuMsg := aSymbol |
269 | 219 |
! |
220 |
||
221 |
menuPerformer |
|
222 |
"who should perform the menu actions ? |
|
1147
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
223 |
If no menuPerformer was defined, its the model if I have one. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
224 |
Otherwise its the menuPerformer (if nonNil), or myself. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
225 |
The menuPerformer get messages from the menu" |
269 | 226 |
|
1147
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
227 |
menuPerformer notNil ifTrue:[^ menuPerformer]. |
269 | 228 |
model notNil ifTrue:[^ model]. |
229 |
^ self |
|
1147
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
230 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
231 |
"Modified: 23.12.1996 / 13:57:18 / cg" |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
232 |
! |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
233 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
234 |
menuPerformer:anObject |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
235 |
"change the one that does the menu actions. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
236 |
See the comment in SimpleView>>activateMenu on who gets the menus |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
237 |
message." |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
238 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
239 |
menuPerformer := anObject |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
240 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
241 |
" |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
242 |
|top textV plug| |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
243 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
244 |
plug := Plug new. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
245 |
plug respondTo:#textMenu |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
246 |
with:[ |m| |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
247 |
m := PopUpMenu |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
248 |
labels:#('copy' 'foo' '-' 'others') |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
249 |
selectors:#(copySelection foo nil others). |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
250 |
m subMenuAt:#others |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
251 |
put:(PopUpMenu |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
252 |
labels:#('bar' 'goto') |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
253 |
selectors:#(bar gotoLine)) |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
254 |
]. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
255 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
256 |
top := StandardSystemView new. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
257 |
top extent:300@300. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
258 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
259 |
textV := TextView origin:0.0@0.0 corner:1.0@1.0 in:top. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
260 |
textV menuHolder:plug; menuMessage:#textMenu; menuPerformer:plug. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
261 |
textV contents:'hello world'. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
262 |
top open. |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
263 |
" |
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
264 |
|
83ed804938e7
moved menuHolder/menuPerformer stuff up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1146
diff
changeset
|
265 |
"Created: 23.12.1996 / 13:57:28 / cg" |
269 | 266 |
! ! |
267 |
||
118 | 268 |
!View methodsFor:'accessing-mvc'! |
269 |
||
269 | 270 |
addModelInterfaceTo:aDictionary |
271 |
"this adds entries for all messages sent to my model |
|
272 |
to aDictionary" |
|
273 |
||
274 |
aDictionary at:#aspectMessage put:aspectMsg. |
|
275 |
aDictionary at:#changeMessage put:changeMsg. |
|
276 |
aDictionary at:#menuMessage put:menuMsg. |
|
277 |
||
278 |
" |
|
279 |
Button new modelInterface |
|
280 |
" |
|
281 |
! |
|
135 | 282 |
|
269 | 283 |
aspect |
284 |
"Return the aspect used with changes from/to the model" |
|
285 |
||
286 |
^ aspectMsg |
|
287 |
! |
|
288 |
||
289 |
aspectMessage |
|
290 |
"Return the aspect used with changes from/to the model" |
|
291 |
||
292 |
^ aspectMsg |
|
293 |
! |
|
294 |
||
295 |
aspectMessage:aspectSymbol |
|
296 |
"ST-80 style updating: If a views aspectSymbol is nonNil, |
|
297 |
it will respond to changes of this aspect from the model." |
|
298 |
||
299 |
aspectMsg := aspectSymbol |
|
135 | 300 |
! |
301 |
||
269 | 302 |
change:changeSymbol |
303 |
"ST-80 style change notification: If a views changeSymbol is nonNil, |
|
304 |
it will send it to its model when something changes. |
|
305 |
Alias for changeMessage: for ST-80 compatibility." |
|
306 |
||
307 |
self changeMessage:changeSymbol |
|
308 |
! |
|
309 |
||
310 |
changeMessage |
|
311 |
"Return the symbol sent to the model if nonNil when something changes." |
|
135 | 312 |
|
269 | 313 |
^ changeMsg |
314 |
! |
|
315 |
||
316 |
changeMessage:aSymbol |
|
317 |
"ST-80 style change notification: If a views changeSymbol is nonNil, |
|
318 |
it will send it to its model when something changes. |
|
319 |
This is the same as change: which was added for ST-80 compatibility." |
|
320 |
||
321 |
changeMsg := aSymbol |
|
322 |
! |
|
323 |
||
324 |
controller:aController |
|
325 |
"set the controller" |
|
118 | 326 |
|
269 | 327 |
super controller:aController. |
328 |
controller notNil ifTrue:[ |
|
329 |
controller model:model |
|
0 | 330 |
] |
331 |
! |
|
332 |
||
269 | 333 |
menu:menuSymbol |
334 |
"ST-80 style menus: If a views menuSymbol is nonNil, it |
|
335 |
will send it to its model when the middleButton is pressed. |
|
336 |
That method should return nil or the menu to be shown. |
|
337 |
This is useful for very dynamic menus, where it does not |
|
338 |
make sense to define an initial menu. |
|
339 |
Alias for #menuMessage:, for ST-80 compatibility." |
|
340 |
||
341 |
menuMsg := menuSymbol |
|
342 |
! |
|
343 |
||
118 | 344 |
model |
345 |
"return the model, for non-MVC views, |
|
346 |
this is nil or the receiver" |
|
347 |
||
348 |
^ model |
|
349 |
! |
|
350 |
||
351 |
model:aModel |
|
1149
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
352 |
"set the model. |
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
353 |
Here, if I am my own menuPerformer/menuHolder, |
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
354 |
set the menuHolder to the model. This is a compatibility kludge, |
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
355 |
since typically, ST-80 code expects the model to provide a menu |
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
356 |
and the view to perform it. |
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
357 |
Those apps which want the view to provide the (default) menu have to reset |
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
358 |
this by sending #menuHolder: message (again)" |
118 | 359 |
|
360 |
model notNil ifTrue:[ |
|
1149
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
361 |
model removeDependent:self |
89 | 362 |
]. |
118 | 363 |
model := aModel. |
1149
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
364 |
(menuPerformer == self and:[menuHolder == self]) ifTrue:[ |
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
365 |
menuPerformer := menuHolder := model |
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
366 |
]. |
118 | 367 |
model notNil ifTrue:[ |
1149
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
368 |
aModel addDependent:self |
118 | 369 |
]. |
370 |
controller notNil ifTrue:[ |
|
1149
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
371 |
controller model:aModel |
118 | 372 |
] |
1149
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
373 |
|
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
374 |
"Modified: 31.12.1996 / 15:02:28 / stefan" |
118 | 375 |
! |
376 |
||
140 | 377 |
modelInterface |
378 |
"this returns a dictionary of messages sent to my model. |
|
379 |
It can be used for builders and wrappers to get information |
|
380 |
about the messages sent to my model. |
|
381 |
The returned dictionary contains one entry for each get-Msg, |
|
382 |
and the recevier will implement corresponding messages (with a colon) |
|
383 |
to set the message symbol." |
|
384 |
||
385 |
|d| |
|
386 |
||
387 |
d := IdentityDictionary new. |
|
388 |
self addModelInterfaceTo:d. |
|
389 |
^ d |
|
390 |
||
391 |
" |
|
392 |
Button new modelInterface |
|
393 |
Label new modelInterface |
|
394 |
" |
|
395 |
||
396 |
" |
|
397 |
does the view support setting the menuMessage ? |
|
398 |
||
399 |
SelectionInListView new modelInterface includesKey:#menuMessage |
|
400 |
" |
|
401 |
||
402 |
" |
|
403 |
turn off all interaction to the model: |
|
404 |
||
405 |
|m v if| |
|
406 |
||
407 |
m := SelectionInList new. |
|
408 |
m list:#('one' 'two' 'tree' 'four') asValue. |
|
409 |
m selection:1 asValue. |
|
410 |
v := SelectionInListView on:m. |
|
411 |
v open. |
|
412 |
v inspect. |
|
413 |
||
414 |
if := v modelInterface. |
|
415 |
if inspect. |
|
416 |
||
417 |
if keysAndValuesDo:[:what :msg | |
|
418 |
v perform:(what , ':') asSymbol with:nil. |
|
419 |
]. |
|
420 |
" |
|
269 | 421 |
! |
422 |
||
423 |
on:aModel aspect:aspectSymbol |
|
424 |
"ST-80 compatibility: set model and aspect |
|
425 |
messages - needs a view which uses these" |
|
426 |
||
427 |
aspectMsg := aspectSymbol. |
|
428 |
self model:aModel. |
|
429 |
! |
|
430 |
||
431 |
on:aModel aspect:aspectSymbol change:changeSymbol |
|
432 |
"ST-80 compatibility: set model, aspect and change |
|
433 |
messages - needs a view which uses these" |
|
434 |
||
435 |
aspectMsg := aspectSymbol. |
|
436 |
changeMsg := changeSymbol. |
|
437 |
self model:aModel. |
|
438 |
! |
|
439 |
||
440 |
on:aModel aspect:aspectSymbol change:changeSymbol menu:menuSymbol |
|
441 |
"ST-80 compatibility: set model, aspect, change and menu |
|
442 |
messages - needs a view which uses these" |
|
443 |
||
444 |
aspectMsg := aspectSymbol. |
|
445 |
changeMsg := changeSymbol. |
|
446 |
menuMsg := menuSymbol. |
|
447 |
self model:aModel. |
|
448 |
! |
|
449 |
||
450 |
on:aModel aspect:aspectSymbol menu:menuSymbol |
|
451 |
"ST-80 compatibility: set model, aspect and menu |
|
452 |
messages - needs a view which uses these" |
|
453 |
||
454 |
aspectMsg := aspectSymbol. |
|
455 |
menuMsg := menuSymbol. |
|
456 |
self model:aModel. |
|
457 |
! |
|
458 |
||
459 |
sendChangeMessage:aSelector with:arg |
|
460 |
"tell the model about a change" |
|
461 |
||
462 |
|n selector| |
|
463 |
||
464 |
"/ |
|
465 |
"/ MVC way of doing it: |
|
466 |
"/ if the model is a block, evaluate it, optionally |
|
467 |
"/ passing the arg and the receiver as arguments. |
|
468 |
"/ |
|
469 |
"/ otherwise (the common case) send it a changeMsg message |
|
470 |
"/ also with arg and the receiver (depending on the number of arguments |
|
471 |
"/ as defined by the selector). |
|
472 |
"/ |
|
473 |
(model notNil and:[aSelector notNil]) ifTrue:[ |
|
474 |
n := aSelector numArgs. |
|
475 |
model isBlock ifTrue:[ |
|
476 |
n := model numArgs. |
|
477 |
n == 0 ifTrue:[ |
|
478 |
selector := #value |
|
479 |
] ifFalse:[ |
|
480 |
n == 1 ifTrue:[ |
|
481 |
selector := #value: |
|
482 |
] ifFalse:[ |
|
483 |
selector := #value:value: |
|
484 |
] |
|
485 |
] |
|
486 |
] ifFalse:[ |
|
487 |
selector := aSelector |
|
488 |
]. |
|
489 |
n == 0 ifTrue:[ |
|
490 |
model perform:selector |
|
491 |
] ifFalse:[ |
|
492 |
n == 1 ifTrue:[ |
|
493 |
model perform:selector with:arg |
|
494 |
] ifFalse:[ |
|
495 |
model perform:selector with:arg with:self |
|
496 |
] |
|
497 |
] |
|
498 |
] |
|
499 |
! |
|
500 |
||
501 |
sendChangeMessageWith:arg |
|
502 |
"tell the model about a change" |
|
503 |
||
504 |
self sendChangeMessage:changeMsg with:arg |
|
72 | 505 |
! ! |
506 |
||
269 | 507 |
!View methodsFor:'drawing'! |
118 | 508 |
|
269 | 509 |
redraw |
510 |
"redraw myself |
|
511 |
if there is a model, this one shall redraw itself, |
|
512 |
otherwise we cannot do much here - has to be redefined in subclasses" |
|
118 | 513 |
|
269 | 514 |
model notNil ifTrue:[ |
515 |
model update:self |
|
516 |
] |
|
118 | 517 |
! ! |
518 |
||
519 |
!View methodsFor:'initialization'! |
|
520 |
||
521 |
initialize |
|
522 |
super initialize. |
|
140 | 523 |
|
524 |
aspectMsg := self class defaultAspectMessage. |
|
525 |
changeMsg := self class defaultChangeMessage. |
|
526 |
||
135 | 527 |
model notNil ifTrue:[ |
528 |
controller notNil ifTrue:[ |
|
118 | 529 |
controller model:model |
530 |
] |
|
81 | 531 |
]. |
118 | 532 |
! ! |
533 |
||
534 |
!View methodsFor:'realization'! |
|
535 |
||
536 |
destroy |
|
537 |
"unrealize & destroy - make me invisible, destroy subviews then |
|
538 |
make me unknown to the device" |
|
539 |
||
540 |
model notNil ifTrue:[ |
|
541 |
model removeDependent:self. |
|
542 |
model := nil. |
|
543 |
]. |
|
544 |
super destroy. |
|
545 |
! ! |
|
269 | 546 |
|
547 |
!View class methodsFor:'documentation'! |
|
548 |
||
549 |
version |
|
1149
a3a75ffb29ce
Set meuPerformer also, when model is set.
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
550 |
^ '$Header: /cvs/stx/stx/libview/View.st,v 1.54 1997-01-02 16:29:06 stefan Exp $' |
269 | 551 |
! ! |