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
|
|
14 |
instanceVariableNames:'model aspectMsg changeMsg menuMsg'
|
|
15 |
classVariableNames:''
|
118
|
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 |
|
|
45 |
Instance variables:
|
|
46 |
|
135
|
47 |
model <nil | any> the model (if any)
|
140
|
48 |
|
135
|
49 |
aspectMsg <nil | Symbol> the aspect; typically
|
|
50 |
dependentViews react on changes
|
|
51 |
of this aspect and update their contents.
|
140
|
52 |
|
135
|
53 |
changeMsg <nil | Symbol> the changeMessage; typically
|
|
54 |
dependentViews send this message to
|
|
55 |
the model to tell it about changes.
|
140
|
56 |
|
135
|
57 |
menuMsg <nil | Symbol> the menuMessage; typically
|
|
58 |
dependentViews send this message to
|
|
59 |
the model to ask for a popup menu.
|
140
|
60 |
Some classes allow setting an explicit
|
|
61 |
menuHolder and menuPerformer.
|
2
|
62 |
"
|
|
63 |
! !
|
0
|
64 |
|
118
|
65 |
!View class methodsFor:'instance creation'!
|
|
66 |
|
269
|
67 |
model:aModel
|
|
68 |
"st-80 style view creation: create a new view and set its model"
|
|
69 |
|
|
70 |
^ self new model:aModel
|
|
71 |
!
|
|
72 |
|
140
|
73 |
on:aModel aspect:aspectMsg
|
|
74 |
"st-80 style view creation: create a new view, set its model
|
|
75 |
and selectors for aspect"
|
|
76 |
|
|
77 |
^ self new
|
|
78 |
on:aModel
|
|
79 |
aspect:aspectMsg
|
|
80 |
!
|
|
81 |
|
|
82 |
on:aModel aspect:aspectMsg change:changeMsg
|
|
83 |
"st-80 style view creation: create a new view, set its model
|
|
84 |
and selectors for aspect and change"
|
|
85 |
|
|
86 |
^ self new
|
|
87 |
on:aModel
|
|
88 |
aspect:aspectMsg
|
|
89 |
change:changeMsg
|
|
90 |
!
|
|
91 |
|
135
|
92 |
on:aModel aspect:aspectMsg change:changeMsg menu:menuMsg
|
118
|
93 |
"st-80 style view creation: create a new view, set its model
|
140
|
94 |
and selectors for aspect, change and menu"
|
118
|
95 |
|
135
|
96 |
^ self new
|
|
97 |
on:aModel
|
|
98 |
aspect:aspectMsg
|
|
99 |
change:changeMsg
|
|
100 |
menu:menuMsg
|
118
|
101 |
!
|
|
102 |
|
269
|
103 |
on:aModel aspect:aspectMsg menu:menuMsg
|
|
104 |
"st-80 style view creation: create a new view, set its model
|
|
105 |
and selectors for aspect and menu"
|
118
|
106 |
|
269
|
107 |
^ self new
|
|
108 |
on:aModel
|
|
109 |
aspect:aspectMsg
|
|
110 |
menu:menuMsg
|
118
|
111 |
! !
|
|
112 |
|
123
|
113 |
!View class methodsFor:'defaults'!
|
|
114 |
|
140
|
115 |
defaultAspectMessage
|
135
|
116 |
"subclasses which by default do NOT want to be informed about changed
|
|
117 |
models should redefine this to return nil"
|
118
|
118 |
|
135
|
119 |
^ #value
|
0
|
120 |
!
|
|
121 |
|
140
|
122 |
defaultChangeMessage
|
135
|
123 |
"subclasses which by default do NOT want to inform the model
|
|
124 |
should redefine this to return nil"
|
0
|
125 |
|
135
|
126 |
^ #value:
|
0
|
127 |
! !
|
|
128 |
|
170
|
129 |
!View methodsFor:'accessing-channels'!
|
|
130 |
|
|
131 |
setupChannel:newChannel for:changeSelector withOld:oldChannel
|
|
132 |
"common code to change a channel"
|
|
133 |
|
|
134 |
|oldValue|
|
|
135 |
|
|
136 |
oldChannel notNil ifTrue:[
|
|
137 |
oldChannel retractInterrestFor:self.
|
|
138 |
oldValue := oldChannel value.
|
|
139 |
].
|
|
140 |
newChannel onChangeSend:changeSelector to:self.
|
|
141 |
self perform:changeSelector.
|
|
142 |
^ newChannel
|
|
143 |
! !
|
|
144 |
|
269
|
145 |
!View methodsFor:'accessing-menus'!
|
|
146 |
|
|
147 |
menuHolder
|
|
148 |
"who has the menu ?
|
|
149 |
By default, its the model if I have one."
|
|
150 |
|
|
151 |
model notNil ifTrue:[^ model].
|
|
152 |
^ self
|
|
153 |
!
|
|
154 |
|
|
155 |
menuPerformer
|
|
156 |
"who should perform the menu actions ?
|
|
157 |
By default, its the model if I have one."
|
|
158 |
|
|
159 |
model notNil ifTrue:[^ model].
|
|
160 |
^ self
|
|
161 |
! !
|
|
162 |
|
118
|
163 |
!View methodsFor:'accessing-mvc'!
|
|
164 |
|
269
|
165 |
addModelInterfaceTo:aDictionary
|
|
166 |
"this adds entries for all messages sent to my model
|
|
167 |
to aDictionary"
|
|
168 |
|
|
169 |
aDictionary at:#aspectMessage put:aspectMsg.
|
|
170 |
aDictionary at:#changeMessage put:changeMsg.
|
|
171 |
aDictionary at:#menuMessage put:menuMsg.
|
|
172 |
|
|
173 |
"
|
|
174 |
Button new modelInterface
|
|
175 |
"
|
|
176 |
!
|
135
|
177 |
|
269
|
178 |
aspect
|
|
179 |
"Return the aspect used with changes from/to the model"
|
|
180 |
|
|
181 |
^ aspectMsg
|
|
182 |
!
|
|
183 |
|
|
184 |
aspectMessage
|
|
185 |
"Return the aspect used with changes from/to the model"
|
|
186 |
|
|
187 |
^ aspectMsg
|
|
188 |
!
|
|
189 |
|
|
190 |
aspectMessage:aspectSymbol
|
|
191 |
"ST-80 style updating: If a views aspectSymbol is nonNil,
|
|
192 |
it will respond to changes of this aspect from the model."
|
|
193 |
|
|
194 |
aspectMsg := aspectSymbol
|
135
|
195 |
!
|
|
196 |
|
269
|
197 |
change:changeSymbol
|
|
198 |
"ST-80 style change notification: If a views changeSymbol is nonNil,
|
|
199 |
it will send it to its model when something changes.
|
|
200 |
Alias for changeMessage: for ST-80 compatibility."
|
|
201 |
|
|
202 |
self changeMessage:changeSymbol
|
|
203 |
!
|
|
204 |
|
|
205 |
changeMessage
|
|
206 |
"Return the symbol sent to the model if nonNil when something changes."
|
135
|
207 |
|
269
|
208 |
^ changeMsg
|
|
209 |
!
|
|
210 |
|
|
211 |
changeMessage:aSymbol
|
|
212 |
"ST-80 style change notification: If a views changeSymbol is nonNil,
|
|
213 |
it will send it to its model when something changes.
|
|
214 |
This is the same as change: which was added for ST-80 compatibility."
|
|
215 |
|
|
216 |
changeMsg := aSymbol
|
|
217 |
!
|
|
218 |
|
|
219 |
controller:aController
|
|
220 |
"set the controller"
|
118
|
221 |
|
269
|
222 |
super controller:aController.
|
|
223 |
controller notNil ifTrue:[
|
|
224 |
controller model:model
|
0
|
225 |
]
|
|
226 |
!
|
|
227 |
|
269
|
228 |
menu:menuSymbol
|
|
229 |
"ST-80 style menus: If a views menuSymbol is nonNil, it
|
|
230 |
will send it to its model when the middleButton is pressed.
|
|
231 |
That method should return nil or the menu to be shown.
|
|
232 |
This is useful for very dynamic menus, where it does not
|
|
233 |
make sense to define an initial menu.
|
|
234 |
Alias for #menuMessage:, for ST-80 compatibility."
|
|
235 |
|
|
236 |
menuMsg := menuSymbol
|
|
237 |
!
|
|
238 |
|
|
239 |
menuMessage
|
|
240 |
"Return the symbol sent to the model to aquire the menu"
|
|
241 |
|
|
242 |
^ menuMsg
|
|
243 |
!
|
|
244 |
|
|
245 |
menuMessage:aSymbol
|
|
246 |
"ST-80 style menus: If a views menuSymbol is nonNil, it
|
|
247 |
will send it to its model when the middleButton is pressed.
|
|
248 |
That method should return nil or the menu to be shown.
|
|
249 |
This is useful for very dynamic menus, where it does not
|
|
250 |
make sense to define an initial menu.
|
|
251 |
This is the same as #menu: which was added for ST-80 compatibility."
|
|
252 |
|
|
253 |
menuMsg := aSymbol
|
|
254 |
!
|
|
255 |
|
118
|
256 |
model
|
|
257 |
"return the model, for non-MVC views,
|
|
258 |
this is nil or the receiver"
|
|
259 |
|
|
260 |
^ model
|
|
261 |
!
|
|
262 |
|
|
263 |
model:aModel
|
|
264 |
"set the model"
|
|
265 |
|
|
266 |
model notNil ifTrue:[
|
|
267 |
model removeDependent:self
|
89
|
268 |
].
|
118
|
269 |
model := aModel.
|
135
|
270 |
|
118
|
271 |
model notNil ifTrue:[
|
|
272 |
aModel addDependent:self
|
|
273 |
].
|
|
274 |
controller notNil ifTrue:[
|
|
275 |
controller model:aModel
|
|
276 |
]
|
|
277 |
!
|
|
278 |
|
140
|
279 |
modelInterface
|
|
280 |
"this returns a dictionary of messages sent to my model.
|
|
281 |
It can be used for builders and wrappers to get information
|
|
282 |
about the messages sent to my model.
|
|
283 |
The returned dictionary contains one entry for each get-Msg,
|
|
284 |
and the recevier will implement corresponding messages (with a colon)
|
|
285 |
to set the message symbol."
|
|
286 |
|
|
287 |
|d|
|
|
288 |
|
|
289 |
d := IdentityDictionary new.
|
|
290 |
self addModelInterfaceTo:d.
|
|
291 |
^ d
|
|
292 |
|
|
293 |
"
|
|
294 |
Button new modelInterface
|
|
295 |
Label new modelInterface
|
|
296 |
"
|
|
297 |
|
|
298 |
"
|
|
299 |
does the view support setting the menuMessage ?
|
|
300 |
|
|
301 |
SelectionInListView new modelInterface includesKey:#menuMessage
|
|
302 |
"
|
|
303 |
|
|
304 |
"
|
|
305 |
turn off all interaction to the model:
|
|
306 |
|
|
307 |
|m v if|
|
|
308 |
|
|
309 |
m := SelectionInList new.
|
|
310 |
m list:#('one' 'two' 'tree' 'four') asValue.
|
|
311 |
m selection:1 asValue.
|
|
312 |
v := SelectionInListView on:m.
|
|
313 |
v open.
|
|
314 |
v inspect.
|
|
315 |
|
|
316 |
if := v modelInterface.
|
|
317 |
if inspect.
|
|
318 |
|
|
319 |
if keysAndValuesDo:[:what :msg |
|
|
320 |
v perform:(what , ':') asSymbol with:nil.
|
|
321 |
].
|
|
322 |
"
|
269
|
323 |
!
|
|
324 |
|
|
325 |
on:aModel aspect:aspectSymbol
|
|
326 |
"ST-80 compatibility: set model and aspect
|
|
327 |
messages - needs a view which uses these"
|
|
328 |
|
|
329 |
aspectMsg := aspectSymbol.
|
|
330 |
self model:aModel.
|
|
331 |
!
|
|
332 |
|
|
333 |
on:aModel aspect:aspectSymbol change:changeSymbol
|
|
334 |
"ST-80 compatibility: set model, aspect and change
|
|
335 |
messages - needs a view which uses these"
|
|
336 |
|
|
337 |
aspectMsg := aspectSymbol.
|
|
338 |
changeMsg := changeSymbol.
|
|
339 |
self model:aModel.
|
|
340 |
!
|
|
341 |
|
|
342 |
on:aModel aspect:aspectSymbol change:changeSymbol menu:menuSymbol
|
|
343 |
"ST-80 compatibility: set model, aspect, change and menu
|
|
344 |
messages - needs a view which uses these"
|
|
345 |
|
|
346 |
aspectMsg := aspectSymbol.
|
|
347 |
changeMsg := changeSymbol.
|
|
348 |
menuMsg := menuSymbol.
|
|
349 |
self model:aModel.
|
|
350 |
!
|
|
351 |
|
|
352 |
on:aModel aspect:aspectSymbol menu:menuSymbol
|
|
353 |
"ST-80 compatibility: set model, aspect and menu
|
|
354 |
messages - needs a view which uses these"
|
|
355 |
|
|
356 |
aspectMsg := aspectSymbol.
|
|
357 |
menuMsg := menuSymbol.
|
|
358 |
self model:aModel.
|
|
359 |
!
|
|
360 |
|
|
361 |
sendChangeMessage:aSelector with:arg
|
|
362 |
"tell the model about a change"
|
|
363 |
|
|
364 |
|n selector|
|
|
365 |
|
|
366 |
"/
|
|
367 |
"/ MVC way of doing it:
|
|
368 |
"/ if the model is a block, evaluate it, optionally
|
|
369 |
"/ passing the arg and the receiver as arguments.
|
|
370 |
"/
|
|
371 |
"/ otherwise (the common case) send it a changeMsg message
|
|
372 |
"/ also with arg and the receiver (depending on the number of arguments
|
|
373 |
"/ as defined by the selector).
|
|
374 |
"/
|
|
375 |
(model notNil and:[aSelector notNil]) ifTrue:[
|
|
376 |
n := aSelector numArgs.
|
|
377 |
model isBlock ifTrue:[
|
|
378 |
n := model numArgs.
|
|
379 |
n == 0 ifTrue:[
|
|
380 |
selector := #value
|
|
381 |
] ifFalse:[
|
|
382 |
n == 1 ifTrue:[
|
|
383 |
selector := #value:
|
|
384 |
] ifFalse:[
|
|
385 |
selector := #value:value:
|
|
386 |
]
|
|
387 |
]
|
|
388 |
] ifFalse:[
|
|
389 |
selector := aSelector
|
|
390 |
].
|
|
391 |
n == 0 ifTrue:[
|
|
392 |
model perform:selector
|
|
393 |
] ifFalse:[
|
|
394 |
n == 1 ifTrue:[
|
|
395 |
model perform:selector with:arg
|
|
396 |
] ifFalse:[
|
|
397 |
model perform:selector with:arg with:self
|
|
398 |
]
|
|
399 |
]
|
|
400 |
]
|
|
401 |
!
|
|
402 |
|
|
403 |
sendChangeMessageWith:arg
|
|
404 |
"tell the model about a change"
|
|
405 |
|
|
406 |
self sendChangeMessage:changeMsg with:arg
|
72
|
407 |
! !
|
|
408 |
|
269
|
409 |
!View methodsFor:'drawing'!
|
118
|
410 |
|
269
|
411 |
redraw
|
|
412 |
"redraw myself
|
|
413 |
if there is a model, this one shall redraw itself,
|
|
414 |
otherwise we cannot do much here - has to be redefined in subclasses"
|
118
|
415 |
|
269
|
416 |
model notNil ifTrue:[
|
|
417 |
model update:self
|
|
418 |
]
|
118
|
419 |
! !
|
|
420 |
|
|
421 |
!View methodsFor:'initialization'!
|
|
422 |
|
|
423 |
initialize
|
|
424 |
super initialize.
|
140
|
425 |
|
|
426 |
aspectMsg := self class defaultAspectMessage.
|
|
427 |
changeMsg := self class defaultChangeMessage.
|
|
428 |
|
135
|
429 |
model notNil ifTrue:[
|
|
430 |
controller notNil ifTrue:[
|
118
|
431 |
controller model:model
|
|
432 |
]
|
81
|
433 |
].
|
118
|
434 |
! !
|
|
435 |
|
|
436 |
!View methodsFor:'realization'!
|
|
437 |
|
|
438 |
destroy
|
|
439 |
"unrealize & destroy - make me invisible, destroy subviews then
|
|
440 |
make me unknown to the device"
|
|
441 |
|
|
442 |
model notNil ifTrue:[
|
|
443 |
model removeDependent:self.
|
|
444 |
model := nil.
|
|
445 |
].
|
|
446 |
super destroy.
|
|
447 |
! !
|
269
|
448 |
|
|
449 |
!View class methodsFor:'documentation'!
|
|
450 |
|
|
451 |
version
|
|
452 |
^ '$Header: /cvs/stx/stx/libview/View.st,v 1.48 1995-11-27 22:31:52 cg Exp $'
|
|
453 |
! !
|