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