author | ca |
Wed, 04 Jun 1997 13:28:48 +0200 | |
changeset 137 | 335faeed1663 |
parent 134 | d5ab85ec27fd |
child 141 | d06c04391233 |
permissions | -rw-r--r-- |
60 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
UIObjectView subclass:#UIPainterView |
|
111 | 14 |
instanceVariableNames:'listHolder superclassName className methodName categoryName' |
60 | 15 |
classVariableNames:'HandCursor' |
16 |
poolDictionaries:'' |
|
17 |
category:'Interface-UIPainter' |
|
18 |
! |
|
19 |
||
128 | 20 |
Object subclass:#ViewProperty |
21 |
instanceVariableNames:'view spec identifier' |
|
22 |
classVariableNames:'Identifier' |
|
119 | 23 |
poolDictionaries:'' |
24 |
privateIn:UIPainterView |
|
25 |
! |
|
26 |
||
128 | 27 |
MultiSelectionInList subclass:#ListHolder |
28 |
instanceVariableNames:'painter propertyList masterElement disabledChanged' |
|
29 |
classVariableNames:'' |
|
52 | 30 |
poolDictionaries:'' |
31 |
privateIn:UIPainterView |
|
51 | 32 |
! |
33 |
||
60 | 34 |
UIPainterView::ViewProperty subclass:#GroupProperties |
78 | 35 |
instanceVariableNames:'controlledObjects group name' |
60 | 36 |
classVariableNames:'' |
37 |
poolDictionaries:'' |
|
38 |
privateIn:UIPainterView |
|
39 |
! |
|
40 |
||
41 |
!UIPainterView class methodsFor:'documentation'! |
|
42 |
||
43 |
copyright |
|
44 |
" |
|
45 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
46 |
All Rights Reserved |
|
47 |
||
48 |
This software is furnished under a license and may be used |
|
49 |
only in accordance with the terms of that license and with the |
|
50 |
inclusion of the above copyright notice. This software may not |
|
51 |
be provided or otherwise made available to, or used by, any |
|
52 |
other person. No title to or ownership of the software is |
|
53 |
hereby transferred. |
|
54 |
" |
|
55 |
! |
|
56 |
||
57 |
documentation |
|
58 |
" |
|
128 | 59 |
buildIn view used by the UIPainter; from this view, the layout of the |
60 |
new application derives from. |
|
61 |
||
62 |
[see also:] |
|
63 |
UIBuilder |
|
64 |
UIObjectView |
|
60 | 65 |
" |
66 |
! ! |
|
67 |
||
68 |
!UIPainterView class methodsFor:'defaults'! |
|
69 |
||
70 |
defaultMenuMessage |
|
71 |
"This message is the default yo be sent to the menuHolder to get a menu |
|
72 |
" |
|
121 | 73 |
^ #showMiddleButtonMenu |
60 | 74 |
|
75 |
||
76 |
! ! |
|
77 |
||
111 | 78 |
!UIPainterView class methodsFor:'menu specs'! |
79 |
||
80 |
menu |
|
81 |
||
82 |
^ #(#Menu #( |
|
83 |
#(#MenuItem |
|
84 |
#'label:' 'copy' |
|
115 | 85 |
#'value:' #copySelection |
111 | 86 |
#'shortcutKeyCharacter:' #Copy |
87 |
) |
|
88 |
#(#MenuItem |
|
89 |
#'label:' 'cut' |
|
115 | 90 |
#'value:' #deleteSelection |
111 | 91 |
#'shortcutKeyCharacter:' #Cut |
92 |
) |
|
93 |
#(#MenuItem |
|
115 | 94 |
#'label:' 'paste' |
111 | 95 |
#'nameKey:' #paste |
115 | 96 |
#'value:' #paste |
111 | 97 |
#'submenu:' |
98 |
#(#Menu #( |
|
99 |
#(#MenuItem |
|
100 |
#'label:' 'paste' |
|
115 | 101 |
#'value:' #pasteBuffer |
111 | 102 |
#'shortcutKeyCharacter:' #Paste |
103 |
) |
|
104 |
#(#MenuItem |
|
105 |
#'label:' 'keep layout' |
|
115 | 106 |
#'value:' #pasteWithLayout |
111 | 107 |
) |
108 |
) |
|
109 |
nil |
|
110 |
nil |
|
111 |
) |
|
112 |
) |
|
113 |
#(#MenuItem |
|
115 | 114 |
#'label:' 'undo' |
115 |
#'nameKey:' #undo |
|
116 |
#'value:' #undoLast) |
|
111 | 117 |
#(#MenuItem |
118 |
#'label:' 'arrange' |
|
115 | 119 |
#'value:' #arrange |
111 | 120 |
#'submenu:' |
121 |
#(#Menu #( |
|
122 |
#(#MenuItem |
|
123 |
#'label:' 'to front' |
|
115 | 124 |
#'value:' #raiseSelection |
111 | 125 |
) |
126 |
#(#MenuItem |
|
127 |
#'label:' 'to back' |
|
115 | 128 |
#'value:' #lowerSelection |
111 | 129 |
) |
130 |
) |
|
131 |
nil |
|
132 |
nil |
|
133 |
) |
|
134 |
) |
|
135 |
#(#MenuItem |
|
136 |
#'label:' 'dimension' |
|
115 | 137 |
#'value:' #dimension |
111 | 138 |
#'submenu:' |
139 |
#(#Menu #( |
|
140 |
#(#MenuItem |
|
141 |
#'label:' 'default extent' |
|
115 | 142 |
#'value:' #setToDefaultExtent |
111 | 143 |
) |
144 |
#(#MenuItem |
|
145 |
#'label:' 'default width' |
|
115 | 146 |
#'value:' #setToDefaultWidth |
111 | 147 |
) |
148 |
#(#MenuItem |
|
149 |
#'label:' 'default height' |
|
115 | 150 |
#'value:' #setToDefaultHeight |
111 | 151 |
) |
152 |
#(#MenuItem |
|
153 |
#'label:' 'copy extent' |
|
115 | 154 |
#'value:' #copyExtent |
111 | 155 |
) |
156 |
#(#MenuItem |
|
157 |
#'label:' 'paste extent' |
|
115 | 158 |
#'value:' #pasteExtent |
111 | 159 |
) |
160 |
#(#MenuItem |
|
161 |
#'label:' 'paste width' |
|
115 | 162 |
#'value:' #pasteWidth |
111 | 163 |
) |
164 |
#(#MenuItem |
|
165 |
#'label:' 'paste height' |
|
115 | 166 |
#'value:' #pasteHeight |
111 | 167 |
) |
168 |
#(#MenuItem |
|
169 |
#'label:' 'copy layout' |
|
115 | 170 |
#'value:' #copyLayout |
111 | 171 |
) |
172 |
#(#MenuItem |
|
173 |
#'label:' 'paste layout' |
|
115 | 174 |
#'value:' #pasteLayout |
111 | 175 |
) |
176 |
) |
|
177 |
#(3 1 3) |
|
178 |
nil |
|
179 |
) |
|
180 |
) |
|
181 |
#(#MenuItem |
|
182 |
#'label:' 'align' |
|
115 | 183 |
#'value:' #align |
111 | 184 |
#'submenu:' |
185 |
#(#Menu #( |
|
186 |
#(#MenuItem |
|
115 | 187 |
#'value:' #alignSelectionLeft |
119 | 188 |
#'labelImage:' #( ResourceRetriever UIPainter iconAlignL 'align left' ) |
111 | 189 |
) |
190 |
#(#MenuItem |
|
115 | 191 |
#'value:' #alignSelectionRight |
119 | 192 |
#'labelImage:' #( ResourceRetriever UIPainter iconAlignR 'align right' ) |
111 | 193 |
) |
194 |
#(#MenuItem |
|
115 | 195 |
#'value:' #alignSelectionLeftAndRight |
119 | 196 |
#'labelImage:' #( ResourceRetriever UIPainter iconAlignLR 'align left & right' ) |
111 | 197 |
) |
198 |
#(#MenuItem |
|
115 | 199 |
#'value:' #alignSelectionTop |
119 | 200 |
#'labelImage:' #( ResourceRetriever UIPainter iconAlignT 'align top' ) |
201 |
) |
|
202 |
#(#MenuItem |
|
203 |
#'value:' #alignSelectionBottom |
|
204 |
#'labelImage:' #( ResourceRetriever UIPainter iconAlignB 'align bottom' ) |
|
111 | 205 |
) |
206 |
#(#MenuItem |
|
119 | 207 |
#'value:' #alignSelectionTopAndBottom |
208 |
#'labelImage:' #( ResourceRetriever UIPainter iconAlignTB 'align top & bottom' ) |
|
111 | 209 |
) |
210 |
#(#MenuItem |
|
115 | 211 |
#'value:' #alignSelectionCenterHor |
119 | 212 |
#'labelImage:' #( ResourceRetriever UIPainter iconAlignCenterH 'align centered horizontal' ) |
111 | 213 |
) |
214 |
#(#MenuItem |
|
115 | 215 |
#'value:' #alignSelectionCenterVer |
119 | 216 |
#'labelImage:' #( ResourceRetriever UIPainter iconAlignCenterV 'align centered vertical' ) |
111 | 217 |
) |
218 |
#(#MenuItem |
|
219 |
#'label:' 'spread horizontal' |
|
115 | 220 |
#'value:' #spreadSelectionHor |
111 | 221 |
) |
222 |
#(#MenuItem |
|
223 |
#'label:' 'spread vertical' |
|
115 | 224 |
#'value:' #spreadSelectionVer |
111 | 225 |
) |
226 |
#(#MenuItem |
|
227 |
#'label:' 'center horizontal in frame' |
|
115 | 228 |
#'value:' #centerSelectionHor |
111 | 229 |
) |
230 |
#(#MenuItem |
|
231 |
#'label:' 'center vertical in frame' |
|
115 | 232 |
#'value:' #centerSelectionVer |
111 | 233 |
) |
234 |
) |
|
119 | 235 |
#(8 2) |
111 | 236 |
nil |
237 |
) |
|
238 |
) |
|
239 |
) |
|
240 |
#(4) |
|
241 |
nil |
|
242 |
) |
|
243 |
! ! |
|
244 |
||
60 | 245 |
!UIPainterView methodsFor:'accessing'! |
246 |
||
247 |
application |
|
248 |
self halt. |
|
249 |
^ nil |
|
250 |
||
251 |
"Modified: 6.9.1995 / 00:46:44 / claus" |
|
252 |
! |
|
253 |
||
78 | 254 |
applicationName |
255 |
^ self className |
|
256 |
! |
|
257 |
||
258 |
applicationName:aName |
|
259 |
self className:aName |
|
260 |
! |
|
261 |
||
60 | 262 |
className |
263 |
^ className |
|
264 |
! |
|
265 |
||
78 | 266 |
className:aName |
267 |
className := aName |
|
60 | 268 |
! |
269 |
||
270 |
className:aClassName superclassName:aSuperclassName selector:aSelector |
|
78 | 271 |
className := aClassName. |
60 | 272 |
superclassName := aSuperclassName. |
78 | 273 |
methodName := aSelector. |
60 | 274 |
|
275 |
! |
|
276 |
||
111 | 277 |
listHolder |
278 |
^ listHolder |
|
279 |
! |
|
280 |
||
60 | 281 |
methodName |
282 |
^ methodName |
|
283 |
! |
|
284 |
||
78 | 285 |
methodName:aName |
286 |
methodName := aName |
|
60 | 287 |
! |
288 |
||
289 |
selectNames:aStringOrCollection |
|
290 |
|prop coll s| |
|
291 |
||
292 |
(aStringOrCollection isNil or:[aStringOrCollection isEmpty]) ifTrue:[ |
|
131 | 293 |
^ self select:nil |
60 | 294 |
]. |
295 |
||
296 |
(s := aStringOrCollection) isString ifFalse:[ |
|
297 |
s size == 1 ifTrue:[ |
|
298 |
s := s first |
|
299 |
] ifFalse:[ |
|
300 |
coll := OrderedCollection new. |
|
301 |
||
302 |
s do:[:aName| |
|
303 |
(prop := self propertyOfName:aName) notNil ifTrue:[ |
|
304 |
coll add:(prop view) |
|
305 |
] |
|
306 |
]. |
|
307 |
coll size == 1 ifTrue:[ ^ self select:(coll at:1) ]. |
|
131 | 308 |
coll size == 0 ifTrue:[ ^ self select:nil ]. |
60 | 309 |
|
310 |
^ self select:coll. |
|
311 |
] |
|
312 |
]. |
|
313 |
||
314 |
prop := self propertyOfName:s. |
|
131 | 315 |
prop isNil ifTrue:[^ self select:nil] |
60 | 316 |
ifFalse:[^ self select:(prop view)] |
317 |
||
318 |
! ! |
|
319 |
||
111 | 320 |
!UIPainterView methodsFor:'change & update'! |
321 |
||
322 |
changed:aParameter |
|
323 |
aParameter == #layout ifTrue:[ |
|
324 |
listHolder removeDependent:self. |
|
325 |
listHolder changed:aParameter. |
|
326 |
listHolder addDependent:self. |
|
327 |
] ifFalse:[ |
|
328 |
super changed:aParameter |
|
329 |
] |
|
330 |
! |
|
331 |
||
332 |
selectionChanged |
|
333 |
"selection has changed |
|
334 |
" |
|
335 |
|newSel| |
|
336 |
||
128 | 337 |
self selectionDo:[:aView||p| |
338 |
(p := self propertyOfView:aView) notNil ifTrue:[ |
|
339 |
newSel isNil ifTrue:[ |
|
340 |
newSel := OrderedCollection new |
|
341 |
]. |
|
342 |
newSel add:(listHolder indexOfName:(p name)) |
|
111 | 343 |
] |
344 |
]. |
|
345 |
listHolder removeDependent:self. |
|
346 |
listHolder selectionIndex:newSel. |
|
347 |
listHolder addDependent:self. |
|
348 |
! |
|
349 |
||
350 |
update:what with:aParm from:aSender |
|
351 |
|loIdx newSel| |
|
352 |
||
353 |
(what == #selectionIndex and:[aSender == listHolder]) ifFalse:[ |
|
354 |
^ self |
|
355 |
]. |
|
356 |
loIdx := listHolder selectionIndex. |
|
357 |
||
358 |
loIdx size ~~ 0 ifTrue:[ |
|
359 |
newSel := loIdx collect:[:i|(listHolder propertyAt:i) view] |
|
360 |
]. |
|
128 | 361 |
self updateSelectionFrom:newSel. |
362 |
! |
|
363 |
||
364 |
updateSelectionFrom:aSel |
|
365 |
"update selection from a new selection |
|
366 |
" |
|
367 |
|csel| |
|
368 |
||
369 |
selectionHiddenLevel == 0 ifTrue:[ |
|
370 |
aSel isCollection ifTrue:[ |
|
371 |
self selectionDo:[:el| |
|
372 |
(aSel includes:el) ifFalse:[self showUnselected:el] |
|
373 |
] |
|
374 |
] ifFalse:[ |
|
375 |
self selectionDo:[:el| |
|
376 |
aSel == el ifFalse:[self showUnselected:el] |
|
377 |
] |
|
378 |
] |
|
111 | 379 |
]. |
128 | 380 |
self setSelection:aSel withRedraw:false. |
381 |
self showSelection |
|
111 | 382 |
! ! |
383 |
||
60 | 384 |
!UIPainterView methodsFor:'copy & cut & paste'! |
385 |
||
386 |
copySelection |
|
387 |
"copy the selection into the cut&paste-buffer |
|
388 |
" |
|
71 | 389 |
|specs coll| |
390 |
||
128 | 391 |
coll := self minSetOfSuperViews:(self selection). |
60 | 392 |
|
71 | 393 |
coll notNil ifTrue:[ |
131 | 394 |
self select:nil. |
78 | 395 |
specs := coll collect:[:aView| self fullSpecFor:aView ]. |
60 | 396 |
self setSelection:specs |
397 |
]. |
|
78 | 398 |
|
399 |
||
60 | 400 |
! |
401 |
||
402 |
deleteSelection |
|
62 | 403 |
"delete the selection; copy the selection into the cut&paste-buffer |
404 |
and open a transaction |
|
60 | 405 |
" |
134 | 406 |
|specs coll| |
71 | 407 |
|
128 | 408 |
coll := self minSetOfSuperViews:(self selection). |
60 | 409 |
|
78 | 410 |
coll notNil ifTrue:[ |
111 | 411 |
listHolder disableNotificationsWhileEvaluating:[ |
131 | 412 |
self select:nil. |
111 | 413 |
specs := coll collect:[:aView| self fullSpecFor:aView ]. |
60 | 414 |
|
134 | 415 |
self withinTransaction:#cut objects:coll do:[ |
416 |
coll reverseDo:[:aView| |
|
417 |
self createUndoRemove:aView. |
|
418 |
self remove:aView |
|
111 | 419 |
] |
420 |
]. |
|
421 |
self setSelection:specs. |
|
422 |
] |
|
60 | 423 |
] |
424 |
! |
|
425 |
||
426 |
pasteBuffer |
|
62 | 427 |
"add the objects in the paste-buffer to the object view |
60 | 428 |
" |
89 | 429 |
self pasteSpecifications:(self getSelection) keepLayout:false |
430 |
||
431 |
! |
|
432 |
||
433 |
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout |
|
434 |
"add the specs to the object view |
|
435 |
" |
|
111 | 436 |
|paste frame pasteOrigin pasteOffset builder newSel| |
60 | 437 |
|
89 | 438 |
(self canPaste:aSpecificationOrList) ifFalse:[ |
439 |
^ self |
|
440 |
]. |
|
441 |
aSpecificationOrList isCollection ifTrue:[ |
|
442 |
paste := aSpecificationOrList |
|
443 |
] ifFalse:[ |
|
444 |
paste := Array with:aSpecificationOrList |
|
445 |
]. |
|
60 | 446 |
frame := self singleSelection. |
447 |
||
62 | 448 |
(self canPasteInto:frame) ifFalse:[ |
60 | 449 |
frame := self |
450 |
]. |
|
131 | 451 |
self select:nil. |
60 | 452 |
|
111 | 453 |
newSel := OrderedCollection new. |
454 |
builder := UIBuilder new. |
|
89 | 455 |
|
456 |
keepLayout ifFalse:[ |
|
457 |
pasteOffset := 0@0. |
|
458 |
pasteOrigin := self sensor mousePoint. |
|
459 |
pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id. |
|
460 |
]. |
|
60 | 461 |
|
111 | 462 |
listHolder disableNotificationsWhileEvaluating:[ |
463 |
paste do:[:aSpec| |
|
464 |
|view| |
|
60 | 465 |
|
111 | 466 |
view := self addSpec:aSpec builder:builder in:frame. |
60 | 467 |
|
111 | 468 |
keepLayout ifFalse:[ |
469 |
(frame bounds containsPoint:pasteOrigin) ifFalse:[ |
|
470 |
self moveObject:view to:pasteOffset. |
|
471 |
] ifTrue:[ |
|
472 |
self moveObject:view to:pasteOrigin + pasteOffset. |
|
473 |
]. |
|
474 |
pasteOffset := pasteOffset + 4 |
|
89 | 475 |
]. |
111 | 476 |
view realize. |
477 |
newSel add:view. |
|
60 | 478 |
]. |
479 |
]. |
|
480 |
||
134 | 481 |
self withinTransaction:#paste objects:newSel do:[ |
482 |
undoHistory addUndoSelector:#undoCreate: |
|
483 |
withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier]) |
|
60 | 484 |
]. |
134 | 485 |
|
111 | 486 |
newSel size == 1 ifTrue:[ |
487 |
newSel := newSel at:1 |
|
60 | 488 |
]. |
489 |
self realizeAllSubViews. |
|
490 |
inputView raise. |
|
111 | 491 |
self select:newSel. |
62 | 492 |
self elementChangedSize:frame. |
89 | 493 |
! |
494 |
||
495 |
pasteWithLayout |
|
496 |
"add the objects in the paste-buffer to the object view; don't change the |
|
497 |
layout |
|
498 |
" |
|
499 |
self pasteSpecifications:(self getSelection) keepLayout:true |
|
500 |
||
60 | 501 |
! ! |
502 |
||
503 |
!UIPainterView methodsFor:'drag & drop'! |
|
504 |
||
505 |
canDrop:anObjectOrCollection |
|
89 | 506 |
|spec| |
60 | 507 |
|
119 | 508 |
self enabled ifTrue:[ |
89 | 509 |
anObjectOrCollection size == 1 ifTrue:[ |
510 |
spec := (anObjectOrCollection at:1) theObject. |
|
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
89
diff
changeset
|
511 |
^ (spec isKindOf:UISpecification) |
89 | 512 |
] |
513 |
]. |
|
514 |
^ false |
|
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
89
diff
changeset
|
515 |
|
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
89
diff
changeset
|
516 |
"Modified: 8.4.1997 / 01:01:50 / cg" |
60 | 517 |
! |
518 |
||
519 |
drop:anObjectOrCollection at:aPoint |
|
89 | 520 |
|spec| |
521 |
||
522 |
spec := (anObjectOrCollection at:1) theObject. |
|
523 |
self pasteSpecifications:spec keepLayout:false. |
|
60 | 524 |
|
525 |
||
526 |
! ! |
|
527 |
||
78 | 528 |
!UIPainterView methodsFor:'generating output'! |
529 |
||
60 | 530 |
generateActionMethodFor:aspect spec:protoSpec inClass:targetClass |
531 |
^ ('!!' , targetClass name , ' methodsFor:''actions''!!\\' , |
|
532 |
aspect , '\' , |
|
533 |
' "automatically generated by UIPainter ..."\' , |
|
534 |
'\' , |
|
535 |
' "action to be added ..."\' , |
|
536 |
' Transcript showCR:''action for ' , aspect , ' ...''.\' , |
|
537 |
'!! !!\\') withCRs |
|
538 |
! |
|
539 |
||
540 |
generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass |
|
134 | 541 |
|modelClass| |
542 |
||
543 |
modelClass := protoSpec defaultModelClass. |
|
544 |
||
60 | 545 |
^ ('!!' , targetClass name , ' methodsFor:''aspects''!!\\' , |
546 |
aspect , '\' , |
|
547 |
' "automatically generated by UIPainter ..."\' , |
|
548 |
'\' , |
|
549 |
' |holder|\' , |
|
550 |
'\' , |
|
551 |
' (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' , |
|
134 | 552 |
' builder aspectAt:#' , aspect , ' put:(holder := ' , ' ' , modelClass name , ' new' , ').\' , |
60 | 553 |
' ].\' , |
554 |
' ^ holder\' , |
|
555 |
'!! !!\\') withCRs |
|
556 |
! |
|
557 |
||
558 |
generateAspectMethods |
|
559 |
|cls code| |
|
560 |
||
78 | 561 |
code := ''. |
562 |
||
60 | 563 |
className isNil ifTrue:[ |
69 | 564 |
self warn:'set the class first'. |
78 | 565 |
^ code |
60 | 566 |
]. |
89 | 567 |
cls := Smalltalk classNamed:className. |
60 | 568 |
|
111 | 569 |
listHolder propertiesDo:[:aProp | |
62 | 570 |
|modelSelector menuSelector protoSpec thisCode| |
60 | 571 |
|
134 | 572 |
protoSpec := aProp spec. |
573 |
protoSpec isNil ifTrue:[ |
|
574 |
self halt. |
|
575 |
protoSpec := aProp view specClass basicNew. |
|
576 |
]. |
|
78 | 577 |
(modelSelector := aProp model) notNil ifTrue:[ |
60 | 578 |
(cls implements:modelSelector asSymbol) ifFalse:[ |
579 |
"/ kludge .. |
|
580 |
(protoSpec isMemberOf:ActionButtonSpec) ifTrue:[ |
|
581 |
thisCode := (self generateActionMethodFor:modelSelector spec:protoSpec inClass:cls). |
|
582 |
] ifFalse:[ |
|
583 |
thisCode := (self generateAspectMethodFor:modelSelector spec:protoSpec inClass:cls). |
|
584 |
]. |
|
585 |
code := code , thisCode |
|
62 | 586 |
]. |
587 |
]. |
|
588 |
||
78 | 589 |
(menuSelector := aProp menu) notNil ifTrue:[ |
62 | 590 |
(cls implements:menuSelector asSymbol) ifFalse:[ |
591 |
"/ kludge .. |
|
592 |
thisCode := (self generateAspectMethodFor:menuSelector spec:protoSpec inClass:cls). |
|
593 |
code := code , thisCode |
|
60 | 594 |
] |
111 | 595 |
]. |
596 |
||
597 |
aProp spec aspectSelectors do:[:aSel| |
|
598 |
(cls implements:aSel asSymbol) ifFalse:[ |
|
599 |
"/ kludge .. |
|
600 |
thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls). |
|
601 |
code := code , thisCode |
|
602 |
] |
|
603 |
]. |
|
137 | 604 |
aProp spec actionSelectors do:[:aSel| |
605 |
(cls implements:aSel asSymbol) ifFalse:[ |
|
606 |
"/ kludge .. |
|
607 |
thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls). |
|
608 |
code := code , thisCode |
|
609 |
] |
|
610 |
]. |
|
111 | 611 |
|
60 | 612 |
]. |
613 |
^ code |
|
614 |
||
89 | 615 |
! |
60 | 616 |
|
617 |
generateClassDefinition |
|
618 |
|defCode| |
|
619 |
||
620 |
defCode := superclassName , ' subclass:#' , className , '\'. |
|
621 |
defCode := defCode , ' instanceVariableNames:'''. |
|
622 |
defCode := defCode , self subviewVariableNames , '''\'. |
|
623 |
defCode := defCode , ' classVariableNames:''''\'. |
|
624 |
defCode := defCode , ' poolDictionaries:''''\'. |
|
625 |
defCode := defCode , ' category:''' , categoryName , '''\'. |
|
626 |
defCode := defCode , Character excla asString , '\\'. |
|
627 |
||
628 |
^ defCode withCRs |
|
629 |
||
630 |
||
631 |
||
89 | 632 |
! |
60 | 633 |
|
634 |
generateCode |
|
635 |
"generate code for the windowSpec method" |
|
636 |
||
637 |
|code| |
|
638 |
||
134 | 639 |
self resetModification. |
640 |
||
60 | 641 |
code := ''. |
642 |
||
643 |
"/ (Smalltalk classNamed:className asSymbol) isNil ifTrue:[ |
|
644 |
"/ code := code , self generateClassDefinition. |
|
645 |
"/ ]. |
|
646 |
"/ code := code , self generateInitMethod. |
|
647 |
||
648 |
code := code , self generateWindowSpecMethodSource. |
|
649 |
||
650 |
"/ code := code , self generateAspectMethods. |
|
651 |
||
652 |
^ code withCRs |
|
653 |
||
654 |
"Modified: 5.9.1995 / 20:57:53 / claus" |
|
89 | 655 |
! |
60 | 656 |
|
657 |
generateInitCodeForGroup:aGroup |
|
658 |
|code c name p objects outlets moreCode sym typ val| |
|
659 |
||
660 |
" <name> := <GroupClass> in:<name-of-superview>" |
|
661 |
||
662 |
code := ''. |
|
663 |
||
664 |
p := self propertyOfGroup:aGroup. |
|
665 |
name := p at:#variableName. |
|
666 |
c := ' ' , name , ' := ' , (aGroup class name) , ' new.\'. |
|
667 |
||
668 |
code := code , c withCRs. |
|
669 |
||
670 |
" <name> <symbol>:<value>" |
|
671 |
||
672 |
objects := p at:#controlledObjects ifAbsent:[nil]. |
|
673 |
objects notNil ifTrue:[ |
|
674 |
objects do:[:controlledObject | |
|
78 | 675 |
c := c , name , ' add:' , (self uniqueNameOf:controlledObject) , '.\' |
60 | 676 |
] |
677 |
]. |
|
678 |
||
679 |
code := code , c withCRs |
|
680 |
||
681 |
||
682 |
||
683 |
||
684 |
||
685 |
! |
|
686 |
||
687 |
generateInitCodeForOtherStuff |
|
688 |
|code g c name p outlets moreCode sym typ val| |
|
689 |
||
690 |
code := ''. |
|
691 |
||
692 |
"generate code for groups" |
|
693 |
||
111 | 694 |
listHolder propertiesDo:[:props| |
60 | 695 |
g := props at:#group ifAbsent:[nil]. |
696 |
g notNil ifTrue:[ |
|
697 |
code := code , (self generateInitCodeForGroup:g) |
|
698 |
] |
|
699 |
]. |
|
700 |
^ code |
|
701 |
||
702 |
||
703 |
! |
|
704 |
||
705 |
generateInitCodeForView:aView |
|
706 |
|code c name p outlets moreCode sym typ val| |
|
707 |
||
708 |
" <name> := <ViewClass> in:<name-of-superview>" |
|
709 |
||
710 |
code := ''. |
|
711 |
||
712 |
p := self propertyOfView:aView. |
|
713 |
name := p at:#variableName. |
|
714 |
c := ' ' , name , ' := ' , |
|
78 | 715 |
(aView class name) , ' in:' , (self uniqueNameOf:(aView superView)) , '.\'. |
60 | 716 |
|
717 |
" <name> origin:(...) extent:(...)" |
|
718 |
||
719 |
c := c , ' ' , name , ' origin:(', aView origin printString , ')' |
|
720 |
, ' extent:(', aView extent printString , ').\'. |
|
721 |
||
722 |
moreCode := p at:#initCode ifAbsent:nil. |
|
723 |
moreCode notNil ifTrue:[ |
|
724 |
c := c , moreCode , '\' withCRs |
|
725 |
]. |
|
726 |
||
727 |
code := code , c withCRs. |
|
728 |
||
729 |
" <name> <symbol>:<value>" |
|
730 |
||
731 |
outlets := p at:#outlets ifAbsent:[nil]. |
|
732 |
outlets notNil ifTrue:[ |
|
733 |
outlets do:[:selectorOutlet | |
|
734 |
sym := selectorOutlet at:#selector. |
|
735 |
typ := selectorOutlet at:#type. |
|
736 |
val := selectorOutlet at:#value. |
|
737 |
c := ' ' , name , ' ' , sym. |
|
738 |
(typ == #number) ifTrue:[ |
|
739 |
c := c , val printString |
|
740 |
]. |
|
741 |
(typ == #string) ifTrue:[ |
|
742 |
c := c , '''' , val , '''' |
|
743 |
]. |
|
744 |
(typ == #text) ifTrue:[ |
|
745 |
c := c , '''' , val asString , '''' |
|
746 |
]. |
|
747 |
(typ == #strings) ifTrue:[ |
|
748 |
c := c , '#( '. |
|
749 |
val asText do:[:aString | |
|
750 |
c := c , '''' , aString , ''' ' |
|
751 |
]. |
|
752 |
c := c , ')' |
|
753 |
]. |
|
754 |
(typ == #block) ifTrue:[ |
|
755 |
c := c , val |
|
756 |
]. |
|
757 |
(typ == #color) ifTrue:[ |
|
758 |
c := c , '(Color name:''' , val , ''')' |
|
759 |
]. |
|
760 |
c := c , '.' , Character cr asString. |
|
761 |
code := code , c |
|
762 |
] |
|
763 |
]. |
|
764 |
||
765 |
self subviewsOf:aView do:[:v | |
|
766 |
code := code , (self generateInitCodeForView:v) |
|
767 |
]. |
|
768 |
^ code. |
|
769 |
||
770 |
"Modified: 5.9.1995 / 20:06:07 / claus" |
|
771 |
! |
|
772 |
||
773 |
generateInitMethod |
|
774 |
|defCode code| |
|
775 |
||
776 |
defCode := Character excla asString , |
|
777 |
className , ' methodsFor:''initialization''' , |
|
778 |
Character excla asString , '\\'. |
|
779 |
||
780 |
defCode := defCode , 'initialize\'. |
|
781 |
defCode := defCode , ' super initialize.\'. |
|
782 |
defCode := defCode , ' self setupSubViews.\'. |
|
783 |
defCode := defCode , ' self setupLocalStuff\'. |
|
784 |
defCode := defCode , Character excla asString , '\\'. |
|
785 |
||
786 |
defCode := defCode , 'setupSubViews\'. |
|
787 |
code := defCode withCRs. |
|
788 |
||
789 |
self subviewsOf:self do:[:v | |
|
790 |
code := code , (self generateInitCodeForView:v) |
|
791 |
]. |
|
792 |
||
793 |
code := code , (self generateInitCodeForOtherStuff). |
|
794 |
||
795 |
code := code , ' ^ self\' withCRs. |
|
796 |
||
797 |
defCode := Character excla asString , '\\'. |
|
798 |
defCode := defCode , 'setupLocalStuff\'. |
|
799 |
defCode := defCode , ' ^ self\'. |
|
800 |
defCode := defCode , Character excla asString , ' ' , |
|
801 |
Character excla asString , '\\'. |
|
802 |
||
803 |
code := code , defCode withCRs. |
|
804 |
^ code. |
|
805 |
||
806 |
||
807 |
||
808 |
||
809 |
! |
|
810 |
||
811 |
generateOutlets |
|
812 |
^ self |
|
89 | 813 |
! |
60 | 814 |
|
78 | 815 |
generateWindowSpecMethodSource |
816 |
|t s spec specArray str code| |
|
60 | 817 |
|
78 | 818 |
specArray := OrderedCollection new. |
60 | 819 |
|
78 | 820 |
self subViews do:[:aView| |
821 |
aView ~~ inputView ifTrue:[ |
|
822 |
specArray add:(self fullSpecFor:aView) |
|
60 | 823 |
] |
824 |
]. |
|
78 | 825 |
spec := FullSpec new. |
826 |
spec fromBuilder:self components:(SpecCollection new collection:specArray). |
|
60 | 827 |
specArray := spec literalArrayEncoding. |
828 |
||
829 |
str := WriteStream on:String new. |
|
86 | 830 |
UISpecification prettyPrintSpecArray:specArray on:str indent:5. |
60 | 831 |
|
832 |
code := Character excla asString |
|
833 |
, className , ' class methodsFor:''interface specs''' |
|
834 |
, Character excla asString , '\\' |
|
835 |
||
836 |
, methodName , '\' |
|
837 |
, ' "this window spec was automatically generated by the ST/X UIPainter"\\' |
|
838 |
, ' "do not manually edit this - the painter/builder may not be able to\' |
|
839 |
, ' handle the specification if its corrupted."\\' |
|
840 |
, ' "\' |
|
841 |
, ' UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\' |
|
842 |
, ' ' , className , ' new openInterface:#' , methodName , '\' |
|
843 |
, ' "\'. |
|
844 |
||
845 |
methodName = 'windowSpec' ifTrue:[ |
|
846 |
code := code , ' "' , className , ' open"\' |
|
847 |
]. |
|
848 |
code := code |
|
849 |
, '\' |
|
850 |
, ' <resource: #canvas>\\' |
|
851 |
, ' ^\' |
|
852 |
, ' ', str contents |
|
853 |
, '\' |
|
854 |
, Character excla asString |
|
855 |
, ' ' |
|
856 |
, Character excla asString |
|
857 |
, '\\'. |
|
858 |
||
859 |
^ code withCRs |
|
860 |
||
861 |
"Modified: 5.9.1995 / 21:01:35 / claus" |
|
89 | 862 |
! |
60 | 863 |
|
864 |
nameOfClass |
|
865 |
^ 'NewView' |
|
89 | 866 |
! |
60 | 867 |
|
868 |
outletValueOf:aSymbol for:aView |
|
869 |
"/ |c name p outlets moreCode sym typ val| |
|
870 |
"/ |
|
871 |
"/ p := self propertyOfView:aView. |
|
872 |
"/ outlets := p at:#outlets ifAbsent:[^ nil]. |
|
873 |
"/ outlets notNil ifTrue:[ |
|
874 |
"/ outlets do:[:selectorOutlet | |
|
875 |
"/ sym := selectorOutlet at:#selector. |
|
876 |
"/ (sym == aSymbol) ifTrue:[ |
|
877 |
"/ typ := selectorOutlet at:#type. |
|
878 |
"/ val := selectorOutlet at:#value. |
|
879 |
"/ ^ val |
|
880 |
"/ ] |
|
881 |
"/ ] |
|
882 |
"/ ]. |
|
883 |
^ nil |
|
884 |
||
885 |
||
886 |
||
887 |
||
888 |
! |
|
889 |
||
890 |
storeContentsOn:aStream |
|
111 | 891 |
listHolder propertiesDo:[:p| p storeOn:aStream] |
60 | 892 |
! |
893 |
||
894 |
subviewsOf:aView do:aBlock |
|
895 |
|subs v| |
|
896 |
||
897 |
(subs := aView subViews) notNil ifTrue:[ |
|
898 |
subs do:[:v| |
|
899 |
(v ~~ inputView and:[v notNil]) ifTrue:[ |
|
111 | 900 |
(listHolder detectProperty:[:p|p view == v]) notNil ifTrue:[ |
60 | 901 |
(v superView == aView) ifTrue:[ |
902 |
aBlock value:v |
|
903 |
] |
|
904 |
] |
|
905 |
] |
|
906 |
] |
|
907 |
] |
|
908 |
||
909 |
! ! |
|
910 |
||
911 |
!UIPainterView methodsFor:'group manipulations'! |
|
912 |
||
913 |
groupEnterFields |
|
78 | 914 |
|props group objects| |
60 | 915 |
|
128 | 916 |
self hasSelection ifFalse:[ |
917 |
^ self |
|
918 |
]. |
|
60 | 919 |
self selectionDo:[:aView | |
920 |
(aView isKindOf:EditField) ifFalse:[ |
|
921 |
self warn:'select EditFields only !!'. |
|
922 |
^ self |
|
923 |
] |
|
924 |
]. |
|
62 | 925 |
self withSelectionHiddenDo:[ |
60 | 926 |
group := EnterFieldGroup new. |
927 |
props := GroupProperties new. |
|
111 | 928 |
name := self uniqueNameFor:(EnterFieldGroup className). |
60 | 929 |
props group:group. |
930 |
props name:name. |
|
78 | 931 |
group groupID:name asSymbol. |
60 | 932 |
objects := OrderedCollection new. |
933 |
props controlledObjects:objects. |
|
111 | 934 |
listHolder add:props. |
60 | 935 |
|
936 |
self selectionDo:[:aView | |
|
937 |
objects add:aView. |
|
938 |
group add:aView |
|
939 |
]. |
|
940 |
] |
|
941 |
||
942 |
||
943 |
! |
|
944 |
||
945 |
groupRadioButtons |
|
78 | 946 |
|props name group objects| |
60 | 947 |
|
128 | 948 |
self hasSelection ifFalse:[ |
949 |
^ self |
|
950 |
]. |
|
60 | 951 |
self selectionDo:[:aView | |
952 |
(aView isKindOf:RadioButton) ifFalse:[ |
|
953 |
self warn:'select RadioButtons only !!'. |
|
954 |
^ self |
|
955 |
] |
|
956 |
]. |
|
62 | 957 |
self withSelectionHiddenDo:[ |
60 | 958 |
group := RadioButtonGroup new. |
959 |
props := GroupProperties new. |
|
111 | 960 |
name := self uniqueNameFor:(RadioButtonGroup className). |
60 | 961 |
props group:group. |
962 |
props name:name. |
|
963 |
group groupID:name asSymbol. |
|
964 |
objects := OrderedCollection new. |
|
965 |
props controlledObjects:objects. |
|
111 | 966 |
listHolder add:props. |
60 | 967 |
|
968 |
self selectionDo:[:aView | |
|
969 |
aView turnOff. |
|
970 |
objects add:aView. |
|
971 |
group add:aView |
|
972 |
]. |
|
973 |
] |
|
974 |
||
975 |
"Modified: 5.9.1995 / 16:06:15 / claus" |
|
976 |
! ! |
|
977 |
||
978 |
!UIPainterView methodsFor:'initialization'! |
|
979 |
||
137 | 980 |
destroy |
981 |
"remove dependencies |
|
982 |
" |
|
983 |
listHolder notNil ifTrue:[ |
|
984 |
listHolder removeDependent:self. |
|
985 |
]. |
|
986 |
super destroy. |
|
987 |
! |
|
988 |
||
60 | 989 |
initialize |
62 | 990 |
"setup attributes |
991 |
" |
|
60 | 992 |
super initialize. |
993 |
||
994 |
superclassName := 'ApplicationModel'. |
|
995 |
className := 'NewApplication'. |
|
996 |
methodName := 'windowSpec'. |
|
997 |
categoryName := 'Applications'. |
|
111 | 998 |
listHolder := ListHolder for:self. |
60 | 999 |
HandCursor := Cursor leftHand. |
1000 |
||
1001 |
! |
|
1002 |
||
78 | 1003 |
initializeCreatedObject:anObject |
1004 |
"set default properties for a created object |
|
1005 |
" |
|
1006 |
|props spec cls| |
|
60 | 1007 |
|
78 | 1008 |
cls := anObject class. |
1009 |
spec := anObject specClass fromView:anObject. |
|
1010 |
props := ViewProperty new. |
|
1011 |
props view:anObject. |
|
1012 |
props spec:spec. |
|
111 | 1013 |
props name:(self uniqueNameFor:spec). |
1014 |
listHolder add:props. |
|
60 | 1015 |
|
82 | 1016 |
((spec respondsTo:#label:) and:[self supportsLabel:anObject]) ifTrue:[ |
78 | 1017 |
anObject label:(props name). |
1018 |
spec label:(props name) |
|
60 | 1019 |
]. |
1020 |
||
134 | 1021 |
undoHistory withinTransaction:#create text:(props name) do:[ |
1022 |
undoHistory addUndoSelector:#undoCreate: withArgs:(props identifier) |
|
60 | 1023 |
]. |
1024 |
! |
|
1025 |
||
1026 |
setupFromSpec:specOrSpecArray |
|
78 | 1027 |
|spec builder| |
60 | 1028 |
|
111 | 1029 |
listHolder disableNotificationsWhileEvaluating:[ |
1030 |
self removeAll. |
|
1031 |
spec := UISpecification from:specOrSpecArray. |
|
1032 |
builder := UIBuilder new. |
|
1033 |
spec window setupView:self topView for:builder. |
|
1034 |
self addSpec:(spec component) builder:builder in:self. |
|
1035 |
self realizeAllSubViews. |
|
1036 |
inputView raise. |
|
1037 |
] |
|
60 | 1038 |
! ! |
1039 |
||
1040 |
!UIPainterView methodsFor:'menus'! |
|
1041 |
||
121 | 1042 |
showMiddleButtonMenu |
1043 |
"show the middle button menu; this returns nil |
|
62 | 1044 |
" |
111 | 1045 |
|menu canPaste| |
60 | 1046 |
|
121 | 1047 |
self enabled ifFalse:[ |
1048 |
^ nil |
|
1049 |
]. |
|
111 | 1050 |
menu := MenuPanel fromSpec:(self class menu) receiver:self. |
60 | 1051 |
|
1052 |
canPaste := self canPaste:(self getSelection). |
|
1053 |
||
128 | 1054 |
self hasSelection ifTrue:[ |
1055 |
canPaste := (canPaste and:[self canPasteInto:(self selection)]) |
|
1056 |
] ifFalse:[ |
|
111 | 1057 |
menu disableAll |
1058 |
]. |
|
128 | 1059 |
menu enabledAt:#paste put:canPaste. |
134 | 1060 |
menu enabledAt:#undo put:(undoHistory isEmpty not). |
121 | 1061 |
menu startUp. |
1062 |
^ nil |
|
60 | 1063 |
|
62 | 1064 |
|
1065 |
||
60 | 1066 |
! ! |
1067 |
||
1068 |
!UIPainterView methodsFor:'misc'! |
|
1069 |
||
102
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1070 |
changeFont:aFontDescription |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1071 |
|f| |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1072 |
|
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1073 |
f := aFontDescription onDevice:device. |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1074 |
"/ f := Font family:family |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1075 |
"/ face:face |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1076 |
"/ style:style |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1077 |
"/ size:size. |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1078 |
|
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1079 |
f notNil ifTrue:[ |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1080 |
self withSelectionHiddenDo:[ |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1081 |
self selectionDo:[:aView | |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1082 |
aView font:f. |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1083 |
self elementChangedSize:aView. |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1084 |
] |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1085 |
]. |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1086 |
] |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1087 |
|
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1088 |
"Modified: 5.9.1995 / 12:13:27 / claus" |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1089 |
"Created: 10.4.1997 / 09:56:16 / cg" |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1090 |
! |
6fa9c1f05564
fontPanels actionblock passes a fontDescription
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1091 |
|
60 | 1092 |
changeFontFamily:family face:face style:style size:size |
1093 |
|f| |
|
1094 |
||
1095 |
f := Font family:family |
|
1096 |
face:face |
|
1097 |
style:style |
|
1098 |
size:size. |
|
1099 |
||
1100 |
f notNil ifTrue:[ |
|
62 | 1101 |
self withSelectionHiddenDo:[ |
60 | 1102 |
self selectionDo:[:aView | |
1103 |
aView font:f. |
|
62 | 1104 |
self elementChangedSize:aView. |
60 | 1105 |
] |
111 | 1106 |
] |
60 | 1107 |
] |
1108 |
||
1109 |
"Modified: 5.9.1995 / 12:13:27 / claus" |
|
1110 |
! ! |
|
1111 |
||
1112 |
!UIPainterView methodsFor:'removing components'! |
|
1113 |
||
78 | 1114 |
remove:anObject |
1115 |
"remove anObject from the contents do redraw |
|
60 | 1116 |
" |
134 | 1117 |
anObject notNil ifTrue:[ |
1118 |
listHolder remove:anObject |
|
1119 |
] |
|
60 | 1120 |
! |
1121 |
||
1122 |
removeAll |
|
62 | 1123 |
"remove all objects and properties |
1124 |
" |
|
111 | 1125 |
listHolder disableNotificationsWhileEvaluating:[ |
131 | 1126 |
self select:nil. |
134 | 1127 |
listHolder removeAll. |
1128 |
self removeUndoHistory. |
|
111 | 1129 |
] |
60 | 1130 |
! ! |
1131 |
||
1132 |
!UIPainterView methodsFor:'searching'! |
|
1133 |
||
89 | 1134 |
findContainerViewAt:aPoint |
1135 |
"find container view responds to aPoint. |
|
1136 |
" |
|
1137 |
|view| |
|
1138 |
||
1139 |
(view := self findObjectAt:aPoint) isNil ifTrue:[ |
|
1140 |
^ self |
|
1141 |
]. |
|
1142 |
||
1143 |
[(view specClass supportsSubComponents or:[(view := view superView) == self]) |
|
1144 |
] whileFalse:[ |
|
1145 |
[(self propertyOfView:view) isNil] whileTrue:[ |
|
1146 |
(view := view superView) == self ifTrue:[^ self] |
|
1147 |
]. |
|
1148 |
]. |
|
1149 |
^ view |
|
1150 |
! |
|
1151 |
||
60 | 1152 |
findObjectAt:aPoint |
1153 |
"find the origin/corner of the currentWidget |
|
1154 |
" |
|
1155 |
|view| |
|
1156 |
||
1157 |
view := super findObjectAt:aPoint. |
|
1158 |
||
1159 |
view notNil ifTrue:[ |
|
1160 |
"can be a view within a view not visible |
|
1161 |
" |
|
1162 |
[ (self propertyOfView:view) isNil ] whileTrue:[ |
|
1163 |
(view := view superView) == self ifTrue:[^ nil] |
|
1164 |
] |
|
1165 |
]. |
|
1166 |
^ view |
|
1167 |
! |
|
1168 |
||
1169 |
findViewWithId:aViewId |
|
62 | 1170 |
"finds view assigned to identifier and returns the view or nil |
60 | 1171 |
" |
1172 |
|prop| |
|
1173 |
||
1174 |
prop := self propertyOfIdentifier:aViewId. |
|
1175 |
||
1176 |
prop notNil ifTrue:[^ prop view] |
|
1177 |
ifFalse:[^ nil] |
|
78 | 1178 |
! |
1179 |
||
1180 |
propertyOfGroup:aGroup |
|
1181 |
"returns property assigned to group |
|
1182 |
" |
|
111 | 1183 |
^ listHolder detectProperty:[:p| p group == aGroup ] |
78 | 1184 |
! |
1185 |
||
1186 |
propertyOfIdentifier:anId |
|
1187 |
"returns property assigned to unique identifier |
|
1188 |
" |
|
1189 |
anId notNil ifTrue:[ |
|
111 | 1190 |
^ listHolder detectProperty:[:p| p identifier == anId ] |
78 | 1191 |
]. |
1192 |
^ nil |
|
1193 |
! |
|
1194 |
||
1195 |
propertyOfName:aString |
|
1196 |
"returns property assigned to name |
|
1197 |
" |
|
111 | 1198 |
|name| |
1199 |
||
1200 |
aString isNil ifFalse:[ |
|
1201 |
name := aString string withoutSeparators. |
|
1202 |
||
1203 |
name = 'self' ifFalse:[ |
|
1204 |
^ listHolder detectProperty:[:p| p name = name ]. |
|
1205 |
] |
|
78 | 1206 |
]. |
1207 |
^ nil |
|
1208 |
! |
|
1209 |
||
1210 |
propertyOfView:aView |
|
1211 |
"returns property assigned to view |
|
1212 |
" |
|
1213 |
(aView isNil or:[aView == self]) ifFalse:[ |
|
111 | 1214 |
^ listHolder detectProperty:[:p| p view == aView ] |
78 | 1215 |
]. |
1216 |
^ nil |
|
1217 |
! |
|
1218 |
||
111 | 1219 |
uniqueNameFor:aSpecOrString |
78 | 1220 |
"generate and return an unique name for a class |
1221 |
" |
|
1222 |
|next name size| |
|
1223 |
||
111 | 1224 |
aSpecOrString isString ifFalse:[name := aSpecOrString className asString] |
1225 |
ifTrue:[name := aSpecOrString]. |
|
78 | 1226 |
|
111 | 1227 |
(name endsWith:'Spec') ifTrue:[ |
1228 |
name := name copyFrom:1 to:(name size - 4). |
|
1229 |
] ifFalse:[ |
|
1230 |
name := name copy |
|
1231 |
]. |
|
78 | 1232 |
name at:1 put:(name at:1) asLowercase. |
111 | 1233 |
size := name size + 1. |
1234 |
next := 0. |
|
78 | 1235 |
|
111 | 1236 |
listHolder propertiesDo:[:p| |
1237 |
|n| |
|
78 | 1238 |
n := p name. |
1239 |
||
1240 |
(n size >= size and:[n startsWith:name]) ifTrue:[ |
|
1241 |
next := next max:(p extractNumberStartingAt:size) |
|
1242 |
] |
|
1243 |
]. |
|
1244 |
next := next + 1. |
|
1245 |
name := name, next printString. |
|
1246 |
^ name |
|
1247 |
||
1248 |
||
1249 |
||
1250 |
! |
|
1251 |
||
1252 |
uniqueNameOf:aView |
|
111 | 1253 |
|prop| |
78 | 1254 |
|
111 | 1255 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
1256 |
prop name isNil ifTrue:[ |
|
1257 |
prop name:(self uniqueNameFor:(prop spec)). |
|
1258 |
]. |
|
1259 |
^ prop name |
|
78 | 1260 |
]. |
111 | 1261 |
^ 'self' |
78 | 1262 |
|
60 | 1263 |
! ! |
1264 |
||
71 | 1265 |
!UIPainterView methodsFor:'selection'! |
1266 |
||
1267 |
addTreeFrom:aView to:aCollection |
|
1268 |
"add aView and contained subcomponents to collection |
|
1269 |
" |
|
78 | 1270 |
(self propertyOfView:aView) notNil ifTrue:[ |
71 | 1271 |
aCollection add:aView. |
1272 |
||
1273 |
(aView subViews notNil) ifTrue:[ |
|
1274 |
aView subViews do:[:subView| |
|
1275 |
self addTreeFrom:subView to:aCollection |
|
1276 |
] |
|
1277 |
]. |
|
1278 |
] |
|
1279 |
||
1280 |
! |
|
1281 |
||
1282 |
selectSubComponents |
|
1283 |
"select all subcomponents for current selection |
|
1284 |
" |
|
1285 |
|startAtView aCollection| |
|
1286 |
||
1287 |
aCollection := OrderedCollection new. |
|
1288 |
startAtView := self singleSelection. |
|
1289 |
||
1290 |
startAtView isNil ifTrue:[ |
|
1291 |
self subViews notNil ifTrue:[ |
|
1292 |
self subViews do:[:subView| |
|
1293 |
subView ~~ inputView ifTrue:[ |
|
1294 |
self addTreeFrom:subView to:aCollection |
|
1295 |
] |
|
1296 |
] |
|
1297 |
] |
|
1298 |
] ifFalse:[ |
|
1299 |
self addTreeFrom:startAtView to:aCollection |
|
1300 |
]. |
|
1301 |
||
1302 |
aCollection size > 1 ifTrue:[ |
|
128 | 1303 |
self updateSelectionFrom:aCollection. |
111 | 1304 |
self selectionChanged |
71 | 1305 |
] |
1306 |
! ! |
|
1307 |
||
78 | 1308 |
!UIPainterView methodsFor:'specification'! |
1309 |
||
1310 |
addSpec:aSpecification builder:aBuilder in:aFrame |
|
1311 |
"build view and subviews from aSpecification into a frame. The top view |
|
1312 |
is returned. The contained components of a spec are set to nil |
|
1313 |
" |
|
1314 |
aBuilder applicationClass:(Smalltalk classNamed:className). |
|
1315 |
||
111 | 1316 |
aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s n| |
78 | 1317 |
p := ViewProperty new. |
1318 |
s := aSpec copy. |
|
1319 |
p spec:s. |
|
1320 |
p view:aView. |
|
1321 |
||
1322 |
s class supportsSubComponents ifTrue:[ |
|
1323 |
s component:nil |
|
1324 |
]. |
|
1325 |
||
111 | 1326 |
n := s name. |
1327 |
||
1328 |
(n isNil or:[(self propertyOfName:n) notNil]) ifTrue:[ |
|
1329 |
s name:(self uniqueNameFor:s) |
|
78 | 1330 |
]. |
111 | 1331 |
listHolder add:p |
78 | 1332 |
]. |
1333 |
||
1334 |
^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame. |
|
60 | 1335 |
|
78 | 1336 |
! |
1337 |
||
1338 |
fullSpecFor:anObject |
|
1339 |
"generate a full spec for an object |
|
62 | 1340 |
" |
78 | 1341 |
|mySpec subSpecs| |
1342 |
||
1343 |
mySpec := self specFor:anObject. |
|
1344 |
||
1345 |
(mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[ |
|
1346 |
(anObject subViews notNil) ifTrue:[ |
|
1347 |
anObject subViews do:[:aSubView||spec| |
|
1348 |
spec := self fullSpecFor:aSubView. |
|
1349 |
spec notNil ifTrue:[ |
|
1350 |
subSpecs isNil ifTrue:[ |
|
1351 |
subSpecs := OrderedCollection new |
|
1352 |
]. |
|
1353 |
subSpecs add:spec. |
|
1354 |
]. |
|
1355 |
]. |
|
1356 |
subSpecs notNil ifTrue:[ |
|
1357 |
mySpec component:(SpecCollection new collection:subSpecs) |
|
1358 |
] |
|
1359 |
] |
|
1360 |
]. |
|
1361 |
^ mySpec |
|
1362 |
||
60 | 1363 |
|
1364 |
||
1365 |
||
1366 |
||
1367 |
||
1368 |
! |
|
1369 |
||
78 | 1370 |
specFor:anObject |
1371 |
"returns spec assigned to an object |
|
62 | 1372 |
" |
78 | 1373 |
|prop spec| |
60 | 1374 |
|
78 | 1375 |
(prop := self propertyOfView:anObject) notNil ifTrue:[ |
1376 |
spec := prop spec copy. |
|
1377 |
spec layoutFromView:anObject |
|
60 | 1378 |
]. |
78 | 1379 |
^ spec |
1380 |
||
1381 |
||
1382 |
||
60 | 1383 |
! |
1384 |
||
78 | 1385 |
updateFromSpec:aSpec |
1386 |
"update current selected view from specification |
|
62 | 1387 |
" |
78 | 1388 |
|props name builder v| |
1389 |
||
1390 |
self singleSelection notNil ifTrue:[ |
|
1391 |
self withSelectionHiddenDo:[ |
|
1392 |
self transaction:#specification selectionDo:[:aView| |
|
1393 |
builder := UIBuilder new. |
|
1394 |
props := self propertyOfView:aView. |
|
82 | 1395 |
name := (aSpec name) withoutSeparators. |
78 | 1396 |
|
82 | 1397 |
name = props name ifFalse:[ |
1398 |
(self propertyOfName:name) notNil ifTrue:[ |
|
1399 |
name := props name |
|
78 | 1400 |
] |
1401 |
]. |
|
82 | 1402 |
aSpec name:name. |
134 | 1403 |
self createUndoSpecModify:props. |
78 | 1404 |
|
1405 |
aSpec needsRebuildForAttributes ifTrue:[ |
|
1406 |
v := aSpec buildViewWithLayoutFor:builder in:aView superView. |
|
1407 |
v realize. |
|
1408 |
aView destroy. |
|
1409 |
device sync. device flush. |
|
1410 |
aView becomeSameAs:v. |
|
1411 |
inputView raise. |
|
1412 |
] ifFalse:[ |
|
1413 |
aSpec setAttributesIn:aView with:builder. |
|
1414 |
self elementChangedSize:aView. |
|
1415 |
]. |
|
1416 |
props spec:(aSpec copy). |
|
111 | 1417 |
listHolder propertyChanged:props. |
78 | 1418 |
] |
111 | 1419 |
] |
82 | 1420 |
] |
60 | 1421 |
! ! |
1422 |
||
1423 |
!UIPainterView methodsFor:'testing'! |
|
1424 |
||
1425 |
isHorizontalResizable:aComponent |
|
62 | 1426 |
"returns true if instance is horizontal resizeable |
1427 |
" |
|
60 | 1428 |
(aComponent isKindOf:ScrollBar) ifTrue:[ |
1429 |
^ aComponent orientation == #horizontal |
|
1430 |
]. |
|
1431 |
(aComponent isKindOf:Scroller) ifTrue:[ |
|
1432 |
^ aComponent orientation == #horizontal |
|
1433 |
]. |
|
1434 |
(aComponent isKindOf:Slider) ifTrue:[ |
|
1435 |
^ aComponent orientation == #horizontal |
|
1436 |
]. |
|
1437 |
^ true |
|
1438 |
||
1439 |
||
1440 |
! |
|
1441 |
||
1442 |
isVerticalResizable:aComponent |
|
62 | 1443 |
"returns true if instance is vertical resizeable |
1444 |
" |
|
60 | 1445 |
(aComponent isKindOf:EditField) ifTrue:[ |
1446 |
^ false |
|
1447 |
]. |
|
1448 |
(aComponent isKindOf:ComboBoxView) ifTrue:[ |
|
1449 |
^ false |
|
1450 |
]. |
|
1451 |
(aComponent isKindOf:CheckBox) ifTrue:[ |
|
1452 |
^ false |
|
1453 |
]. |
|
1454 |
(aComponent isKindOf:ScrollBar) ifTrue:[ |
|
1455 |
^ aComponent orientation == #vertical |
|
1456 |
]. |
|
1457 |
(aComponent isKindOf:Scroller) ifTrue:[ |
|
1458 |
^ aComponent orientation == #vertical |
|
1459 |
]. |
|
1460 |
(aComponent isKindOf:Slider) ifTrue:[ |
|
1461 |
^ aComponent orientation == #vertical |
|
1462 |
]. |
|
1463 |
^ true |
|
1464 |
||
1465 |
||
82 | 1466 |
! |
1467 |
||
1468 |
supportsLabel:aComponent |
|
1469 |
"returns true if component supports label |
|
1470 |
" |
|
1471 |
(aComponent respondsTo:#label:) ifTrue:[ |
|
1472 |
( (aComponent isKindOf:ArrowButton) |
|
1473 |
or:[aComponent isKindOf:CheckToggle] |
|
1474 |
) ifFalse:[ |
|
1475 |
^ true |
|
1476 |
] |
|
1477 |
]. |
|
1478 |
^ false |
|
60 | 1479 |
! ! |
1480 |
||
1481 |
!UIPainterView methodsFor:'transaction'! |
|
1482 |
||
1483 |
transaction:aType objects:something do:aOneArgBlock |
|
1484 |
"opens a transaction and evaluates a block within the transaction; the |
|
1485 |
argument to the block is a view from derived from something |
|
1486 |
" |
|
134 | 1487 |
self withinTransaction:aType objects:something do:[ |
1488 |
self forEach:something do:aOneArgBlock |
|
60 | 1489 |
] |
1490 |
! |
|
1491 |
||
134 | 1492 |
withinTransaction:aType objects:objects do:aNoneArgBlock |
1493 |
"evaluate a block with no arguments within a transaction |
|
60 | 1494 |
" |
134 | 1495 |
|text size prop| |
1496 |
||
1497 |
objects isNil ifTrue:[ ^ self ]. |
|
1498 |
||
1499 |
size := objects size. |
|
60 | 1500 |
|
134 | 1501 |
objects isCollection ifTrue:[ |
1502 |
size == 0 ifTrue:[ ^ self ]. |
|
1503 |
size == 1 ifTrue:[ prop := self propertyOfView:(objects first) ] |
|
1504 |
] ifFalse:[ |
|
1505 |
prop := self propertyOfView:objects |
|
1506 |
]. |
|
60 | 1507 |
|
134 | 1508 |
prop notNil ifTrue:[ |
1509 |
text := prop name |
|
1510 |
] ifFalse:[ |
|
1511 |
text := size printString, ' elements' |
|
60 | 1512 |
]. |
134 | 1513 |
|
1514 |
undoHistory withinTransaction:aType text:text do:[ |
|
1515 |
aNoneArgBlock value |
|
1516 |
] |
|
60 | 1517 |
! ! |
1518 |
||
1519 |
!UIPainterView methodsFor:'undo actions'! |
|
1520 |
||
134 | 1521 |
createUndoLayout:aView |
1522 |
"create undo action before changing a views layout |
|
60 | 1523 |
" |
134 | 1524 |
|lyt args prop| |
60 | 1525 |
|
1526 |
undoHistory isTransactionOpen ifTrue:[ |
|
1527 |
prop := self propertyOfView:aView. |
|
134 | 1528 |
|
60 | 1529 |
prop notNil ifTrue:[ |
134 | 1530 |
args := Array new:3. |
1531 |
args at:1 put:(prop identifier). |
|
1532 |
||
1533 |
(lyt := aView geometryLayout) notNil ifTrue:[ |
|
1534 |
args at:2 put:#geometryLayout: |
|
1535 |
] ifFalse:[ |
|
1536 |
lyt extent. |
|
1537 |
args at:2 put:#extent: |
|
1538 |
]. |
|
1539 |
args at:3 put:(lyt copy). |
|
1540 |
undoHistory addUndoSelector:#undoLayout: withArgs:args. |
|
60 | 1541 |
] |
1542 |
] |
|
1543 |
! |
|
1544 |
||
134 | 1545 |
createUndoRemove:aView |
1546 |
"create undo method before deleting views |
|
60 | 1547 |
" |
134 | 1548 |
|frame prop pId spec| |
1549 |
||
1550 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
|
1551 |
spec := self fullSpecFor:aView. |
|
1552 |
frame := aView superView. |
|
60 | 1553 |
|
134 | 1554 |
(self canPasteInto:frame) ifTrue:[ |
1555 |
(frame := self propertyOfView:frame) notNil ifTrue:[ |
|
1556 |
pId := frame identifier |
|
1557 |
] |
|
1558 |
]. |
|
1559 |
undoHistory addUndoSelector:#undoRemove: |
|
1560 |
withArgs:(Array with:spec with:(prop identifier) with:pId) |
|
1561 |
] |
|
1562 |
! |
|
60 | 1563 |
|
134 | 1564 |
createUndoSpecModify:aProp |
1565 |
"undo method when changing the specification for an object |
|
1566 |
" |
|
1567 |
aProp notNil ifTrue:[ |
|
1568 |
undoHistory addUndoSelector:#undoSpecModify: |
|
1569 |
withArgs:(Array with:(aProp spec) with:(aProp identifier)) |
|
1570 |
] |
|
1571 |
! |
|
60 | 1572 |
|
134 | 1573 |
undoCreate:something |
1574 |
"undo method for creating or pasting an object |
|
1575 |
" |
|
1576 |
self forEach:something do:[:anId|self remove:(self findViewWithId:anId)]. |
|
1577 |
! |
|
60 | 1578 |
|
134 | 1579 |
undoLayout:args |
1580 |
"undo method to set the old layout; see 'createUndoLayout:' |
|
1581 |
" |
|
1582 |
|view| |
|
1583 |
||
1584 |
(view := self findViewWithId:(args at:1)) notNil ifTrue:[ |
|
1585 |
view perform:(args at:2) with:(args at:3) |
|
60 | 1586 |
] |
1587 |
! |
|
1588 |
||
134 | 1589 |
undoRemove:args |
1590 |
"undo method when removing an object; see 'createUndoRemove:' |
|
1591 |
" |
|
1592 |
|frame prop view| |
|
1593 |
||
1594 |
(args at:3) notNil ifTrue:[ |
|
1595 |
frame := self findViewWithId:(args at:3). |
|
1596 |
]. |
|
1597 |
frame isNil ifTrue:[ |
|
1598 |
frame := self |
|
1599 |
]. |
|
1600 |
view := self addSpec:(args at:1) builder:(UIBuilder new) in:frame. |
|
1601 |
view realize. |
|
1602 |
inputView raise. |
|
1603 |
||
1604 |
prop := self propertyOfView:view. |
|
1605 |
prop identifier:(args at:2). |
|
1606 |
||
1607 |
! |
|
1608 |
||
1609 |
undoSpecModify:args |
|
1610 |
"undo method when changing a spec; see 'createUndoSpecModify:' |
|
60 | 1611 |
" |
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1612 |
|builder view spec v props| |
60 | 1613 |
|
134 | 1614 |
props := self propertyOfIdentifier:(args at:2). |
60 | 1615 |
|
134 | 1616 |
props notNil ifTrue:[ |
1617 |
view := props view. |
|
1618 |
spec := args at:1. |
|
1619 |
builder := UIBuilder new. |
|
1620 |
props spec:spec. |
|
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1621 |
|
134 | 1622 |
spec needsRebuildForAttributes ifTrue:[ |
1623 |
v := spec buildViewWithLayoutFor:builder in:view superView. |
|
1624 |
v realize. |
|
1625 |
view destroy. |
|
1626 |
view become:v |
|
1627 |
] ifFalse:[ |
|
1628 |
spec setAttributesIn:view with:builder. |
|
1629 |
self elementChangedSize:view. |
|
1630 |
]. |
|
1631 |
listHolder propertyChanged:props. |
|
1632 |
] ifFalse:[ |
|
1633 |
self halt |
|
1634 |
] |
|
60 | 1635 |
|
1636 |
||
1637 |
||
1638 |
! ! |
|
1639 |
||
128 | 1640 |
!UIPainterView::ViewProperty class methodsFor:'documentation'! |
1641 |
||
1642 |
version |
|
1643 |
^ '$Header$' |
|
1644 |
! ! |
|
1645 |
||
1646 |
!UIPainterView::ViewProperty class methodsFor:'instance creation'! |
|
1647 |
||
1648 |
new |
|
1649 |
Identifier notNil ifTrue:[Identifier := Identifier + 1] |
|
1650 |
ifFalse:[Identifier := 1]. |
|
1651 |
||
1652 |
^ self basicNew initialize |
|
1653 |
! ! |
|
1654 |
||
1655 |
!UIPainterView::ViewProperty methodsFor:'accessing'! |
|
1656 |
||
1657 |
group |
|
1658 |
^ nil |
|
1659 |
! |
|
1660 |
||
1661 |
identifier |
|
1662 |
"return the unique identifier assigned to property |
|
1663 |
" |
|
1664 |
^ identifier |
|
1665 |
! |
|
1666 |
||
134 | 1667 |
identifier:anIdentifier |
1668 |
"set the unique identifier assigned to property; called after an restore of |
|
1669 |
a deleted instance |
|
1670 |
" |
|
1671 |
identifier := anIdentifier |
|
1672 |
! |
|
1673 |
||
128 | 1674 |
spec |
1675 |
"return the value of the instance variable 'spec' (automatically generated)" |
|
1676 |
||
1677 |
^ spec! |
|
1678 |
||
1679 |
spec:something |
|
1680 |
"set the value of the instance variable 'spec' (automatically generated)" |
|
1681 |
||
1682 |
spec := something.! |
|
1683 |
||
1684 |
view |
|
1685 |
"return the value of the instance variable 'view' (automatically generated)" |
|
1686 |
||
1687 |
^ view! |
|
1688 |
||
1689 |
view:something |
|
1690 |
"set the value of the instance variable 'view' (automatically generated)" |
|
1691 |
||
1692 |
view := something.! ! |
|
1693 |
||
1694 |
!UIPainterView::ViewProperty methodsFor:'initialization'! |
|
1695 |
||
1696 |
initialize |
|
1697 |
super initialize. |
|
1698 |
identifier := Identifier |
|
1699 |
! ! |
|
1700 |
||
1701 |
!UIPainterView::ViewProperty methodsFor:'misc'! |
|
1702 |
||
1703 |
extractNumberStartingAt:anIndex |
|
1704 |
"return the number from the name starting at anIndex or 0. |
|
1705 |
" |
|
1706 |
|val| |
|
1707 |
||
1708 |
val := 0. |
|
1709 |
||
1710 |
self name from:anIndex do:[:c| |
|
1711 |
c isDigit ifTrue:[val := val * 10 + c digitValue] |
|
1712 |
ifFalse:[^ 0] |
|
1713 |
]. |
|
1714 |
^ val |
|
1715 |
||
1716 |
! ! |
|
1717 |
||
1718 |
!UIPainterView::ViewProperty methodsFor:'spec messages'! |
|
1719 |
||
1720 |
doesNotUnderstand:aMessage |
|
1721 |
spec notNil ifTrue:[ |
|
1722 |
(spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec] |
|
1723 |
]. |
|
1724 |
^ nil |
|
1725 |
! |
|
1726 |
||
1727 |
layout |
|
1728 |
spec layout |
|
1729 |
! |
|
1730 |
||
1731 |
layout:aLayout |
|
1732 |
spec layout:aLayout |
|
1733 |
! |
|
1734 |
||
1735 |
name |
|
1736 |
^ spec name |
|
1737 |
! |
|
1738 |
||
1739 |
name:aName |
|
1740 |
spec name:aName |
|
1741 |
! ! |
|
1742 |
||
111 | 1743 |
!UIPainterView::ListHolder class methodsFor:'instance creation'! |
1744 |
||
1745 |
for:aPainter |
|
1746 |
^ self new for:aPainter |
|
1747 |
! ! |
|
1748 |
||
1749 |
!UIPainterView::ListHolder methodsFor:'accessing'! |
|
1750 |
||
1751 |
painter |
|
1752 |
"returns painter |
|
1753 |
" |
|
1754 |
^ painter |
|
1755 |
! |
|
1756 |
||
1757 |
propertyAt:anIndex |
|
1758 |
"returns property at an index |
|
1759 |
" |
|
1760 |
^ propertyList at:anIndex |
|
1761 |
! ! |
|
1762 |
||
1763 |
!UIPainterView::ListHolder methodsFor:'adding & removing'! |
|
1764 |
||
1765 |
add:aProperty |
|
1766 |
"add property and update list |
|
1767 |
" |
|
1768 |
|idx list name last| |
|
1769 |
||
1770 |
list := self list. |
|
1771 |
idx := self findParentProperty:aProperty. |
|
1772 |
name := aProperty name. |
|
1773 |
||
1774 |
idx == 0 ifTrue:[ |
|
1775 |
last := list size |
|
1776 |
] ifFalse:[ |
|
1777 |
last := self lastInGroupStartingAt:idx. |
|
1778 |
name := (String new:(4+((list at:idx) leftIndent))), name. |
|
1779 |
]. |
|
1780 |
propertyList add:aProperty afterIndex:last. |
|
1781 |
list add:name afterIndex:last. |
|
1782 |
self changed:#size |
|
1783 |
||
1784 |
||
1785 |
! |
|
1786 |
||
1787 |
remove:aView |
|
1788 |
"remove all view relevant resources |
|
1789 |
" |
|
1790 |
|start| |
|
1791 |
||
1792 |
aView notNil ifTrue:[ |
|
1793 |
start := self findProperty:[:p| p view == aView ]. |
|
1794 |
||
1795 |
start ~~ 0 ifTrue:[ |
|
1796 |
self basicRemove:start. |
|
1797 |
self changed:#size. |
|
1798 |
] |
|
1799 |
] |
|
1800 |
! |
|
1801 |
||
1802 |
removeAll |
|
1803 |
masterElement := nil. |
|
1804 |
self selection:#(). |
|
1805 |
||
1806 |
[propertyList notEmpty] whileTrue:[ |
|
1807 |
self basicRemove:1 |
|
1808 |
]. |
|
1809 |
self changed:#size. |
|
1810 |
||
1811 |
! ! |
|
1812 |
||
1813 |
!UIPainterView::ListHolder methodsFor:'change & update'! |
|
1814 |
||
1815 |
changed:aParameter |
|
1816 |
"notify all dependents that the receiver has changed somehow. |
|
1817 |
Each dependent gets a '#update:'-message with aParameter |
|
1818 |
as argument. In case of disabled no notifications are raised |
|
1819 |
" |
|
1820 |
disabledChanged ifFalse:[ |
|
1821 |
super changed:aParameter |
|
1822 |
] |
|
1823 |
! |
|
1824 |
||
1825 |
disableNotificationsWhileEvaluating:aBlock |
|
1826 |
"perform block without notification; after evaluation of block, |
|
1827 |
a #size changed notification is raised |
|
1828 |
" |
|
1829 |
|oldState| |
|
1830 |
||
1831 |
oldState := disabledChanged. |
|
1832 |
disabledChanged := true. |
|
1833 |
aBlock value. |
|
1834 |
disabledChanged := oldState. |
|
1835 |
self changed:#size. |
|
1836 |
! |
|
1837 |
||
1838 |
propertyChanged:aProperty |
|
1839 |
"property list changed; update list names |
|
1840 |
" |
|
1841 |
|list idx oldName newName wspName view indent mid| |
|
1842 |
||
1843 |
view := aProperty view. |
|
1844 |
idx := self findProperty:[:p| p view == view ]. |
|
1845 |
||
1846 |
idx == 0 ifTrue:[ |
|
1847 |
^ self error |
|
1848 |
]. |
|
1849 |
||
1850 |
list := self list. |
|
1851 |
oldName := list at:idx. |
|
1852 |
wspName := oldName string withoutSeparators. |
|
1853 |
newName := aProperty name. |
|
1854 |
||
1855 |
wspName = newName ifFalse:[ |
|
1856 |
mid := self masterElement. |
|
1857 |
list at:idx put:((String new:(oldName leftIndent)), newName). |
|
1858 |
||
1859 |
idx == mid ifTrue:[ |
|
1860 |
masterElement := nil. |
|
1861 |
self masterElement:idx |
|
1862 |
]. |
|
1863 |
]. |
|
1864 |
self changed:#property |
|
1865 |
||
1866 |
! ! |
|
1867 |
||
1868 |
!UIPainterView::ListHolder methodsFor:'enumerating'! |
|
1869 |
||
1870 |
propertiesDo:aBlock |
|
1871 |
"evaluate a block for each property |
|
1872 |
" |
|
1873 |
propertyList do:aBlock |
|
1874 |
! ! |
|
1875 |
||
1876 |
!UIPainterView::ListHolder methodsFor:'initialization'! |
|
1877 |
||
1878 |
for:aPainter |
|
1879 |
"initialize for a painter |
|
1880 |
" |
|
119 | 1881 |
painter := aPainter. |
121 | 1882 |
disabledChanged := false. |
111 | 1883 |
self list:(OrderedCollection new). |
1884 |
propertyList := OrderedCollection new. |
|
1885 |
self selection:#(). |
|
1886 |
self addDependent:painter. |
|
1887 |
||
1888 |
! ! |
|
1889 |
||
1890 |
!UIPainterView::ListHolder methodsFor:'private'! |
|
1891 |
||
1892 |
basicRemove:start |
|
1893 |
"remove all resources assigned to a group starting at start; |
|
1894 |
no notifications are raised |
|
1895 |
" |
|
1896 |
|end view superView| |
|
1897 |
||
1898 |
end := self lastInGroupStartingAt:start. |
|
1899 |
view := (propertyList at:start) view. |
|
1900 |
||
1901 |
view notNil ifTrue:[ |
|
1902 |
superView := view superView. |
|
1903 |
view destroy. |
|
1904 |
superView sizeChanged:nil. |
|
1905 |
]. |
|
1906 |
||
1907 |
propertyList removeFromIndex:start toIndex:end. |
|
1908 |
self list removeFromIndex:start toIndex:end. |
|
1909 |
! |
|
1910 |
||
1911 |
masterElement |
|
1912 |
"returns index of master |
|
1913 |
" |
|
1914 |
^ self indexOfName:masterElement. |
|
1915 |
! |
|
1916 |
||
1917 |
masterElement:newIndex |
|
1918 |
"change master of selection |
|
1919 |
" |
|
1920 |
|name list oldIdx| |
|
1921 |
||
1922 |
(oldIdx := self masterElement) ~~ newIndex ifTrue:[ |
|
1923 |
list := self list. |
|
1924 |
||
1925 |
oldIdx ~~ 0 ifTrue:[ |
|
1926 |
list at:oldIdx put:masterElement |
|
1927 |
]. |
|
1928 |
newIndex ~~ 0 ifTrue:[ |
|
1929 |
masterElement := list at:newIndex. |
|
1930 |
name := Text string:masterElement. |
|
1931 |
name emphasizeFrom:(1+(name leftIndent)) with:#(#bold #underline). |
|
1932 |
list at:newIndex put:name. |
|
1933 |
] ifFalse:[ |
|
1934 |
masterElement := nil |
|
1935 |
]. |
|
1936 |
self changed:#list. |
|
1937 |
] |
|
1938 |
! ! |
|
1939 |
||
1940 |
!UIPainterView::ListHolder methodsFor:'searching'! |
|
1941 |
||
1942 |
detectProperty:aBlock |
|
1943 |
"find the property, for which evaluation of the argument, aBlock |
|
1944 |
returns true; return the property or nil if none detected |
|
1945 |
" |
|
1946 |
|idx| |
|
1947 |
||
1948 |
idx := self findProperty:aBlock. |
|
1949 |
idx ~~ 0 ifTrue:[ ^ propertyList at:idx ]. |
|
1950 |
^ nil |
|
1951 |
! |
|
1952 |
||
1953 |
findParentProperty:aChildProp |
|
1954 |
"returns index of parent or 0 |
|
1955 |
" |
|
1956 |
|view index| |
|
1957 |
||
1958 |
view := aChildProp view. |
|
1959 |
||
1960 |
view notNil ifTrue:[ |
|
1961 |
[ (view := view superView) notNil ] whileTrue:[ |
|
1962 |
index := self findProperty:[:aProp| aProp view == view ]. |
|
1963 |
index ~~ 0 ifTrue:[ |
|
1964 |
^ index |
|
1965 |
] |
|
1966 |
] |
|
1967 |
]. |
|
1968 |
^ 0 |
|
1969 |
||
1970 |
||
1971 |
! |
|
1972 |
||
1973 |
findProperty:aBlock |
|
1974 |
"find the first property, for which evaluation of the argument, aBlock |
|
1975 |
returns true; return its index or 0 if none detected |
|
1976 |
" |
|
1977 |
^ propertyList findFirst:aBlock |
|
1978 |
! |
|
1979 |
||
1980 |
indexOfName:aString |
|
1981 |
"returns index assigned to a string or 0 |
|
1982 |
" |
|
1983 |
|name list size| |
|
1984 |
||
1985 |
aString notNil ifTrue:[ |
|
1986 |
name := aString string withoutSeparators. |
|
1987 |
size := name size. |
|
1988 |
list := self list. |
|
1989 |
||
1990 |
list keysAndValuesDo:[:anIndex :aName| |
|
1991 |
|el| |
|
1992 |
||
1993 |
el := aName string. |
|
1994 |
(el endsWith:name) ifTrue:[ |
|
1995 |
(el size - el leftIndent) == name size ifTrue:[ |
|
1996 |
^ anIndex |
|
1997 |
] |
|
1998 |
] |
|
1999 |
] |
|
2000 |
]. |
|
2001 |
^ 0 |
|
2002 |
||
2003 |
! |
|
2004 |
||
2005 |
lastInGroupStartingAt:start |
|
2006 |
"returns last index of a group |
|
2007 |
" |
|
2008 |
|end list idt| |
|
2009 |
||
2010 |
list := self list. |
|
2011 |
||
2012 |
start < list size ifTrue:[ |
|
2013 |
idt := (list at:start) leftIndent. |
|
2014 |
end := list findFirst:[:el|(el leftIndent) <= idt] startingAt:(start+1). |
|
2015 |
end ~~ 0 ifTrue:[ |
|
2016 |
^ end - 1 |
|
2017 |
] |
|
2018 |
]. |
|
2019 |
^ list size |
|
2020 |
! ! |
|
2021 |
||
2022 |
!UIPainterView::ListHolder methodsFor:'selection'! |
|
2023 |
||
2024 |
selectGroup |
|
2025 |
"select all elements assigned to master |
|
2026 |
" |
|
2027 |
|start end sel size| |
|
2028 |
||
119 | 2029 |
painter enabled ifTrue:[ |
111 | 2030 |
(start := self masterElement) ~~ 0 ifTrue:[ |
2031 |
end := self lastInGroupStartingAt:start. |
|
2032 |
size := end - start + 1. |
|
2033 |
sel := Array new:size. |
|
2034 |
||
2035 |
1 to:size do:[:i| |
|
2036 |
sel at:i put:start. |
|
2037 |
start := start + 1 |
|
2038 |
]. |
|
2039 |
self selectionIndex:sel. |
|
2040 |
] ifFalse:[ |
|
2041 |
(self selectionIndex) size == 0 ifFalse:[ |
|
2042 |
self selectionIndex:#() |
|
2043 |
]. |
|
2044 |
] |
|
2045 |
] |
|
2046 |
! |
|
2047 |
||
2048 |
selectedProperty |
|
2049 |
"returns current selected instance; in case of multiple selection |
|
2050 |
or no selection nil is returned |
|
2051 |
" |
|
2052 |
|selection| |
|
2053 |
selection := self selectionIndex. |
|
2054 |
||
2055 |
selection size == 1 ifTrue:[ |
|
137 | 2056 |
propertyList size ~~ 0 ifTrue:[ |
2057 |
^ propertyList at:(selection first) |
|
2058 |
] |
|
111 | 2059 |
]. |
2060 |
^ nil |
|
2061 |
! |
|
2062 |
||
2063 |
selectionIndex:aList |
|
2064 |
|masterIndex aSel| |
|
2065 |
||
119 | 2066 |
painter enabled ifTrue:[aSel := aList] |
2067 |
ifFalse:[aSel := nil]. |
|
111 | 2068 |
|
2069 |
aSel size ~~ 0 ifTrue:[masterIndex := aSel at:1] |
|
2070 |
ifFalse:[masterIndex := 0]. |
|
2071 |
||
2072 |
self masterElement:masterIndex. |
|
2073 |
super selectionIndex:aSel |
|
2074 |
! ! |
|
2075 |
||
119 | 2076 |
!UIPainterView::GroupProperties methodsFor:'accessing'! |
2077 |
||
2078 |
controlledObjects |
|
2079 |
"return the value of the instance variable 'controlledObjects' (automatically generated)" |
|
2080 |
||
2081 |
^ controlledObjects! |
|
2082 |
||
2083 |
controlledObjects:something |
|
2084 |
"set the value of the instance variable 'controlledObjects' (automatically generated)" |
|
2085 |
||
2086 |
controlledObjects := something.! |
|
2087 |
||
2088 |
group |
|
2089 |
"return the value of the instance variable 'group' |
|
2090 |
" |
|
2091 |
^ group |
|
2092 |
! |
|
2093 |
||
2094 |
group:something |
|
2095 |
"set the value of the instance variable 'group' |
|
2096 |
" |
|
2097 |
group := something. |
|
2098 |
! |
|
2099 |
||
2100 |
name |
|
2101 |
"return the value of the group name |
|
2102 |
" |
|
2103 |
^ name |
|
2104 |
! |
|
2105 |
||
2106 |
name:aName |
|
2107 |
"set the value of the group name |
|
2108 |
" |
|
2109 |
name := aName |
|
2110 |
! ! |
|
2111 |
||
60 | 2112 |
!UIPainterView class methodsFor:'documentation'! |
2113 |
||
2114 |
version |
|
2115 |
^ '$Header$' |
|
2116 |
! ! |