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