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