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