author | Claus Gittinger <cg@exept.de> |
Mon, 23 Dec 1996 13:45:37 +0100 | |
changeset 1146 | 0167191529dd |
parent 621 | decaeae1910d |
child 1147 | 83ed804938e7 |
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 ? |
|
184 |
By default, its the model if I have one." |
|
185 |
||
186 |
model notNil ifTrue:[^ model]. |
|
187 |
^ self |
|
188 |
! |
|
189 |
||
190 |
menuPerformer |
|
191 |
"who should perform the menu actions ? |
|
192 |
By default, its the model if I have one." |
|
193 |
||
194 |
model notNil ifTrue:[^ model]. |
|
195 |
^ self |
|
196 |
! ! |
|
197 |
||
118 | 198 |
!View methodsFor:'accessing-mvc'! |
199 |
||
269 | 200 |
addModelInterfaceTo:aDictionary |
201 |
"this adds entries for all messages sent to my model |
|
202 |
to aDictionary" |
|
203 |
||
204 |
aDictionary at:#aspectMessage put:aspectMsg. |
|
205 |
aDictionary at:#changeMessage put:changeMsg. |
|
206 |
aDictionary at:#menuMessage put:menuMsg. |
|
207 |
||
208 |
" |
|
209 |
Button new modelInterface |
|
210 |
" |
|
211 |
! |
|
135 | 212 |
|
269 | 213 |
aspect |
214 |
"Return the aspect used with changes from/to the model" |
|
215 |
||
216 |
^ aspectMsg |
|
217 |
! |
|
218 |
||
219 |
aspectMessage |
|
220 |
"Return the aspect used with changes from/to the model" |
|
221 |
||
222 |
^ aspectMsg |
|
223 |
! |
|
224 |
||
225 |
aspectMessage:aspectSymbol |
|
226 |
"ST-80 style updating: If a views aspectSymbol is nonNil, |
|
227 |
it will respond to changes of this aspect from the model." |
|
228 |
||
229 |
aspectMsg := aspectSymbol |
|
135 | 230 |
! |
231 |
||
269 | 232 |
change:changeSymbol |
233 |
"ST-80 style change notification: If a views changeSymbol is nonNil, |
|
234 |
it will send it to its model when something changes. |
|
235 |
Alias for changeMessage: for ST-80 compatibility." |
|
236 |
||
237 |
self changeMessage:changeSymbol |
|
238 |
! |
|
239 |
||
240 |
changeMessage |
|
241 |
"Return the symbol sent to the model if nonNil when something changes." |
|
135 | 242 |
|
269 | 243 |
^ changeMsg |
244 |
! |
|
245 |
||
246 |
changeMessage:aSymbol |
|
247 |
"ST-80 style change notification: If a views changeSymbol is nonNil, |
|
248 |
it will send it to its model when something changes. |
|
249 |
This is the same as change: which was added for ST-80 compatibility." |
|
250 |
||
251 |
changeMsg := aSymbol |
|
252 |
! |
|
253 |
||
254 |
controller:aController |
|
255 |
"set the controller" |
|
118 | 256 |
|
269 | 257 |
super controller:aController. |
258 |
controller notNil ifTrue:[ |
|
259 |
controller model:model |
|
0 | 260 |
] |
261 |
! |
|
262 |
||
269 | 263 |
menu:menuSymbol |
264 |
"ST-80 style menus: If a views menuSymbol is nonNil, it |
|
265 |
will send it to its model when the middleButton is pressed. |
|
266 |
That method should return nil or the menu to be shown. |
|
267 |
This is useful for very dynamic menus, where it does not |
|
268 |
make sense to define an initial menu. |
|
269 |
Alias for #menuMessage:, for ST-80 compatibility." |
|
270 |
||
271 |
menuMsg := menuSymbol |
|
272 |
! |
|
273 |
||
274 |
menuMessage |
|
275 |
"Return the symbol sent to the model to aquire the menu" |
|
276 |
||
277 |
^ menuMsg |
|
278 |
! |
|
279 |
||
280 |
menuMessage:aSymbol |
|
281 |
"ST-80 style menus: If a views menuSymbol is nonNil, it |
|
282 |
will send it to its model when the middleButton is pressed. |
|
283 |
That method should return nil or the menu to be shown. |
|
284 |
This is useful for very dynamic menus, where it does not |
|
285 |
make sense to define an initial menu. |
|
286 |
This is the same as #menu: which was added for ST-80 compatibility." |
|
287 |
||
288 |
menuMsg := aSymbol |
|
289 |
! |
|
290 |
||
118 | 291 |
model |
292 |
"return the model, for non-MVC views, |
|
293 |
this is nil or the receiver" |
|
294 |
||
295 |
^ model |
|
296 |
! |
|
297 |
||
298 |
model:aModel |
|
299 |
"set the model" |
|
300 |
||
301 |
model notNil ifTrue:[ |
|
302 |
model removeDependent:self |
|
89 | 303 |
]. |
118 | 304 |
model := aModel. |
135 | 305 |
|
118 | 306 |
model notNil ifTrue:[ |
307 |
aModel addDependent:self |
|
308 |
]. |
|
309 |
controller notNil ifTrue:[ |
|
310 |
controller model:aModel |
|
311 |
] |
|
312 |
! |
|
313 |
||
140 | 314 |
modelInterface |
315 |
"this returns a dictionary of messages sent to my model. |
|
316 |
It can be used for builders and wrappers to get information |
|
317 |
about the messages sent to my model. |
|
318 |
The returned dictionary contains one entry for each get-Msg, |
|
319 |
and the recevier will implement corresponding messages (with a colon) |
|
320 |
to set the message symbol." |
|
321 |
||
322 |
|d| |
|
323 |
||
324 |
d := IdentityDictionary new. |
|
325 |
self addModelInterfaceTo:d. |
|
326 |
^ d |
|
327 |
||
328 |
" |
|
329 |
Button new modelInterface |
|
330 |
Label new modelInterface |
|
331 |
" |
|
332 |
||
333 |
" |
|
334 |
does the view support setting the menuMessage ? |
|
335 |
||
336 |
SelectionInListView new modelInterface includesKey:#menuMessage |
|
337 |
" |
|
338 |
||
339 |
" |
|
340 |
turn off all interaction to the model: |
|
341 |
||
342 |
|m v if| |
|
343 |
||
344 |
m := SelectionInList new. |
|
345 |
m list:#('one' 'two' 'tree' 'four') asValue. |
|
346 |
m selection:1 asValue. |
|
347 |
v := SelectionInListView on:m. |
|
348 |
v open. |
|
349 |
v inspect. |
|
350 |
||
351 |
if := v modelInterface. |
|
352 |
if inspect. |
|
353 |
||
354 |
if keysAndValuesDo:[:what :msg | |
|
355 |
v perform:(what , ':') asSymbol with:nil. |
|
356 |
]. |
|
357 |
" |
|
269 | 358 |
! |
359 |
||
360 |
on:aModel aspect:aspectSymbol |
|
361 |
"ST-80 compatibility: set model and aspect |
|
362 |
messages - needs a view which uses these" |
|
363 |
||
364 |
aspectMsg := aspectSymbol. |
|
365 |
self model:aModel. |
|
366 |
! |
|
367 |
||
368 |
on:aModel aspect:aspectSymbol change:changeSymbol |
|
369 |
"ST-80 compatibility: set model, aspect and change |
|
370 |
messages - needs a view which uses these" |
|
371 |
||
372 |
aspectMsg := aspectSymbol. |
|
373 |
changeMsg := changeSymbol. |
|
374 |
self model:aModel. |
|
375 |
! |
|
376 |
||
377 |
on:aModel aspect:aspectSymbol change:changeSymbol menu:menuSymbol |
|
378 |
"ST-80 compatibility: set model, aspect, change and menu |
|
379 |
messages - needs a view which uses these" |
|
380 |
||
381 |
aspectMsg := aspectSymbol. |
|
382 |
changeMsg := changeSymbol. |
|
383 |
menuMsg := menuSymbol. |
|
384 |
self model:aModel. |
|
385 |
! |
|
386 |
||
387 |
on:aModel aspect:aspectSymbol menu:menuSymbol |
|
388 |
"ST-80 compatibility: set model, aspect and menu |
|
389 |
messages - needs a view which uses these" |
|
390 |
||
391 |
aspectMsg := aspectSymbol. |
|
392 |
menuMsg := menuSymbol. |
|
393 |
self model:aModel. |
|
394 |
! |
|
395 |
||
396 |
sendChangeMessage:aSelector with:arg |
|
397 |
"tell the model about a change" |
|
398 |
||
399 |
|n selector| |
|
400 |
||
401 |
"/ |
|
402 |
"/ MVC way of doing it: |
|
403 |
"/ if the model is a block, evaluate it, optionally |
|
404 |
"/ passing the arg and the receiver as arguments. |
|
405 |
"/ |
|
406 |
"/ otherwise (the common case) send it a changeMsg message |
|
407 |
"/ also with arg and the receiver (depending on the number of arguments |
|
408 |
"/ as defined by the selector). |
|
409 |
"/ |
|
410 |
(model notNil and:[aSelector notNil]) ifTrue:[ |
|
411 |
n := aSelector numArgs. |
|
412 |
model isBlock ifTrue:[ |
|
413 |
n := model numArgs. |
|
414 |
n == 0 ifTrue:[ |
|
415 |
selector := #value |
|
416 |
] ifFalse:[ |
|
417 |
n == 1 ifTrue:[ |
|
418 |
selector := #value: |
|
419 |
] ifFalse:[ |
|
420 |
selector := #value:value: |
|
421 |
] |
|
422 |
] |
|
423 |
] ifFalse:[ |
|
424 |
selector := aSelector |
|
425 |
]. |
|
426 |
n == 0 ifTrue:[ |
|
427 |
model perform:selector |
|
428 |
] ifFalse:[ |
|
429 |
n == 1 ifTrue:[ |
|
430 |
model perform:selector with:arg |
|
431 |
] ifFalse:[ |
|
432 |
model perform:selector with:arg with:self |
|
433 |
] |
|
434 |
] |
|
435 |
] |
|
436 |
! |
|
437 |
||
438 |
sendChangeMessageWith:arg |
|
439 |
"tell the model about a change" |
|
440 |
||
441 |
self sendChangeMessage:changeMsg with:arg |
|
72 | 442 |
! ! |
443 |
||
269 | 444 |
!View methodsFor:'drawing'! |
118 | 445 |
|
269 | 446 |
redraw |
447 |
"redraw myself |
|
448 |
if there is a model, this one shall redraw itself, |
|
449 |
otherwise we cannot do much here - has to be redefined in subclasses" |
|
118 | 450 |
|
269 | 451 |
model notNil ifTrue:[ |
452 |
model update:self |
|
453 |
] |
|
118 | 454 |
! ! |
455 |
||
456 |
!View methodsFor:'initialization'! |
|
457 |
||
458 |
initialize |
|
459 |
super initialize. |
|
140 | 460 |
|
461 |
aspectMsg := self class defaultAspectMessage. |
|
462 |
changeMsg := self class defaultChangeMessage. |
|
463 |
||
135 | 464 |
model notNil ifTrue:[ |
465 |
controller notNil ifTrue:[ |
|
118 | 466 |
controller model:model |
467 |
] |
|
81 | 468 |
]. |
118 | 469 |
! ! |
470 |
||
471 |
!View methodsFor:'realization'! |
|
472 |
||
473 |
destroy |
|
474 |
"unrealize & destroy - make me invisible, destroy subviews then |
|
475 |
make me unknown to the device" |
|
476 |
||
477 |
model notNil ifTrue:[ |
|
478 |
model removeDependent:self. |
|
479 |
model := nil. |
|
480 |
]. |
|
481 |
super destroy. |
|
482 |
! ! |
|
269 | 483 |
|
484 |
!View class methodsFor:'documentation'! |
|
485 |
||
486 |
version |
|
1146
0167191529dd
moved menuHolder/menuPerformer up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
621
diff
changeset
|
487 |
^ '$Header: /cvs/stx/stx/libview/View.st,v 1.52 1996-12-23 12:45:37 cg Exp $' |
269 | 488 |
! ! |