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