author | ca |
Fri, 28 Mar 1997 15:57:20 +0100 | |
changeset 89 | 35c5711729c2 |
parent 86 | 06bdbae8bd8e |
child 96 | 73725336b4fe |
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 |
|
14 |
instanceVariableNames:'fontPanel viewProperties superclassName className methodName |
|
15 |
categoryName' |
|
16 |
classVariableNames:'HandCursor' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-UIPainter' |
|
19 |
! |
|
20 |
||
51 | 21 |
Object subclass:#ViewProperty |
78 | 22 |
instanceVariableNames:'view spec identifier' |
52 | 23 |
classVariableNames:'Identifier' |
24 |
poolDictionaries:'' |
|
25 |
privateIn:UIPainterView |
|
51 | 26 |
! |
27 |
||
60 | 28 |
UIPainterView::ViewProperty subclass:#GroupProperties |
78 | 29 |
instanceVariableNames:'controlledObjects group name' |
60 | 30 |
classVariableNames:'' |
31 |
poolDictionaries:'' |
|
32 |
privateIn:UIPainterView |
|
33 |
! |
|
34 |
||
35 |
!UIPainterView class methodsFor:'documentation'! |
|
36 |
||
37 |
copyright |
|
38 |
" |
|
39 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
40 |
All Rights Reserved |
|
41 |
||
42 |
This software is furnished under a license and may be used |
|
43 |
only in accordance with the terms of that license and with the |
|
44 |
inclusion of the above copyright notice. This software may not |
|
45 |
be provided or otherwise made available to, or used by, any |
|
46 |
other person. No title to or ownership of the software is |
|
47 |
hereby transferred. |
|
48 |
" |
|
49 |
! |
|
50 |
||
51 |
documentation |
|
52 |
" |
|
53 |
not yet finished, not yet published, not yet released. |
|
54 |
" |
|
55 |
! ! |
|
56 |
||
57 |
!UIPainterView class methodsFor:'defaults'! |
|
58 |
||
59 |
defaultMenuMessage |
|
60 |
"This message is the default yo be sent to the menuHolder to get a menu |
|
61 |
" |
|
62 |
^ #menu |
|
63 |
||
64 |
||
65 |
! ! |
|
66 |
||
67 |
!UIPainterView methodsFor:'accessing'! |
|
68 |
||
69 |
application |
|
70 |
self halt. |
|
71 |
^ nil |
|
72 |
||
73 |
"Modified: 6.9.1995 / 00:46:44 / claus" |
|
74 |
! |
|
75 |
||
78 | 76 |
applicationName |
77 |
^ self className |
|
78 |
! |
|
79 |
||
80 |
applicationName:aName |
|
81 |
self className:aName |
|
82 |
! |
|
83 |
||
60 | 84 |
className |
85 |
^ className |
|
86 |
! |
|
87 |
||
78 | 88 |
className:aName |
89 |
className := aName |
|
60 | 90 |
! |
91 |
||
92 |
className:aClassName superclassName:aSuperclassName selector:aSelector |
|
78 | 93 |
className := aClassName. |
60 | 94 |
superclassName := aSuperclassName. |
78 | 95 |
methodName := aSelector. |
60 | 96 |
|
97 |
! |
|
98 |
||
99 |
methodName |
|
100 |
^ methodName |
|
101 |
! |
|
102 |
||
78 | 103 |
methodName:aName |
104 |
methodName := aName |
|
60 | 105 |
! |
106 |
||
107 |
selectNames:aStringOrCollection |
|
108 |
|prop coll s| |
|
109 |
||
110 |
(aStringOrCollection isNil or:[aStringOrCollection isEmpty]) ifTrue:[ |
|
111 |
^ self unselect |
|
112 |
]. |
|
113 |
||
114 |
(s := aStringOrCollection) isString ifFalse:[ |
|
115 |
s size == 1 ifTrue:[ |
|
116 |
s := s first |
|
117 |
] ifFalse:[ |
|
118 |
coll := OrderedCollection new. |
|
119 |
||
120 |
s do:[:aName| |
|
121 |
(prop := self propertyOfName:aName) notNil ifTrue:[ |
|
122 |
coll add:(prop view) |
|
123 |
] |
|
124 |
]. |
|
125 |
coll size == 1 ifTrue:[ ^ self select:(coll at:1) ]. |
|
126 |
coll size == 0 ifTrue:[ ^ self unselect ]. |
|
127 |
||
128 |
^ self select:coll. |
|
129 |
] |
|
130 |
]. |
|
131 |
||
132 |
prop := self propertyOfName:s. |
|
133 |
prop isNil ifTrue:[^ self unselect] |
|
134 |
ifFalse:[^ self select:(prop view)] |
|
135 |
||
136 |
! ! |
|
137 |
||
138 |
!UIPainterView methodsFor:'copy & cut & paste'! |
|
139 |
||
140 |
copySelection |
|
141 |
"copy the selection into the cut&paste-buffer |
|
142 |
" |
|
71 | 143 |
|specs coll| |
144 |
||
145 |
coll := self minSetOfSuperViews:selection. |
|
60 | 146 |
|
71 | 147 |
coll notNil ifTrue:[ |
148 |
self unselect. |
|
78 | 149 |
specs := coll collect:[:aView| self fullSpecFor:aView ]. |
60 | 150 |
self setSelection:specs |
151 |
]. |
|
78 | 152 |
|
153 |
||
60 | 154 |
! |
155 |
||
156 |
deleteSelection |
|
62 | 157 |
"delete the selection; copy the selection into the cut&paste-buffer |
158 |
and open a transaction |
|
60 | 159 |
" |
78 | 160 |
|text specs coll| |
71 | 161 |
|
78 | 162 |
coll := self minSetOfSuperViews:selection. |
60 | 163 |
|
78 | 164 |
coll notNil ifTrue:[ |
71 | 165 |
self unselect. |
78 | 166 |
specs := coll collect:[:aView| self fullSpecFor:aView ]. |
167 |
text := self transactionTextFor:coll. |
|
60 | 168 |
|
78 | 169 |
undoHistory transaction:#cut text:text do:[ |
170 |
coll reverseDo:[:o||p| |
|
171 |
(p := self propertyOfView:o) notNil ifTrue:[ |
|
172 |
self undoRemove:(p identifier) |
|
173 |
]. |
|
174 |
self remove:o |
|
175 |
] |
|
176 |
]. |
|
177 |
||
178 |
self setSelection:specs. |
|
179 |
self changed:#tree. |
|
60 | 180 |
] |
181 |
! |
|
182 |
||
183 |
pasteBuffer |
|
62 | 184 |
"add the objects in the paste-buffer to the object view |
60 | 185 |
" |
89 | 186 |
self pasteSpecifications:(self getSelection) keepLayout:false |
187 |
||
188 |
! |
|
189 |
||
190 |
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout |
|
191 |
"add the specs to the object view |
|
192 |
" |
|
78 | 193 |
|paste frame pasteOrigin pasteOffset builder| |
60 | 194 |
|
89 | 195 |
(self canPaste:aSpecificationOrList) ifFalse:[ |
196 |
^ self |
|
197 |
]. |
|
198 |
aSpecificationOrList isCollection ifTrue:[ |
|
199 |
paste := aSpecificationOrList |
|
200 |
] ifFalse:[ |
|
201 |
paste := Array with:aSpecificationOrList |
|
202 |
]. |
|
60 | 203 |
frame := self singleSelection. |
204 |
||
62 | 205 |
(self canPasteInto:frame) ifFalse:[ |
60 | 206 |
frame := self |
207 |
]. |
|
208 |
self unselect. |
|
209 |
||
89 | 210 |
selection := OrderedCollection new. |
211 |
builder := UIBuilder new. |
|
212 |
||
213 |
keepLayout ifFalse:[ |
|
214 |
pasteOffset := 0@0. |
|
215 |
pasteOrigin := self sensor mousePoint. |
|
216 |
pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id. |
|
217 |
]. |
|
60 | 218 |
|
219 |
paste do:[:aSpec| |
|
78 | 220 |
|view| |
60 | 221 |
|
78 | 222 |
view := self addSpec:aSpec builder:builder in:frame. |
60 | 223 |
|
89 | 224 |
keepLayout ifFalse:[ |
225 |
(frame bounds containsPoint:pasteOrigin) ifFalse:[ |
|
226 |
self moveObject:view to:pasteOffset. |
|
227 |
] ifTrue:[ |
|
228 |
self moveObject:view to:pasteOrigin + pasteOffset. |
|
229 |
]. |
|
230 |
pasteOffset := pasteOffset + 4 |
|
60 | 231 |
]. |
232 |
view realize. |
|
233 |
selection add:view. |
|
234 |
]. |
|
235 |
||
236 |
self transaction:#paste selectionDo:[:v| |
|
237 |
self undoCreate:((self propertyOfView:v) identifier) |
|
238 |
]. |
|
239 |
selection size == 1 ifTrue:[ |
|
240 |
selection := selection at:1 |
|
241 |
]. |
|
242 |
self showSelection. |
|
243 |
self realizeAllSubViews. |
|
244 |
inputView raise. |
|
62 | 245 |
self elementChangedSize:frame. |
60 | 246 |
self changed:#tree |
247 |
||
89 | 248 |
! |
249 |
||
250 |
pasteWithLayout |
|
251 |
"add the objects in the paste-buffer to the object view; don't change the |
|
252 |
layout |
|
253 |
" |
|
254 |
self pasteSpecifications:(self getSelection) keepLayout:true |
|
255 |
||
60 | 256 |
! ! |
257 |
||
258 |
!UIPainterView methodsFor:'drag & drop'! |
|
259 |
||
260 |
canDrop:anObjectOrCollection |
|
89 | 261 |
|spec| |
60 | 262 |
|
89 | 263 |
testMode ifFalse:[ |
264 |
anObjectOrCollection size == 1 ifTrue:[ |
|
265 |
spec := (anObjectOrCollection at:1) theObject. |
|
266 |
^ (spec isKindOf:UISpecification) |
|
267 |
] |
|
268 |
]. |
|
269 |
^ false |
|
60 | 270 |
! |
271 |
||
272 |
drop:anObjectOrCollection at:aPoint |
|
89 | 273 |
|spec| |
274 |
||
275 |
spec := (anObjectOrCollection at:1) theObject. |
|
276 |
self pasteSpecifications:spec keepLayout:false. |
|
60 | 277 |
|
278 |
||
279 |
! ! |
|
280 |
||
78 | 281 |
!UIPainterView methodsFor:'generating output'! |
282 |
||
60 | 283 |
generateActionMethodFor:aspect spec:protoSpec inClass:targetClass |
284 |
^ ('!!' , targetClass name , ' methodsFor:''actions''!!\\' , |
|
285 |
aspect , '\' , |
|
286 |
' "automatically generated by UIPainter ..."\' , |
|
287 |
'\' , |
|
288 |
' "action to be added ..."\' , |
|
289 |
' Transcript showCR:''action for ' , aspect , ' ...''.\' , |
|
290 |
'!! !!\\') withCRs |
|
291 |
! |
|
292 |
||
293 |
generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass |
|
294 |
^ ('!!' , targetClass name , ' methodsFor:''aspects''!!\\' , |
|
295 |
aspect , '\' , |
|
296 |
' "automatically generated by UIPainter ..."\' , |
|
297 |
'\' , |
|
298 |
' |holder|\' , |
|
299 |
'\' , |
|
300 |
' (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' , |
|
301 |
' builder aspectAt:#' , aspect , ' put:(holder := ' , ' ValueHolder new' , ').\' , |
|
302 |
' ].\' , |
|
303 |
' ^ holder\' , |
|
304 |
'!! !!\\') withCRs |
|
305 |
! |
|
306 |
||
307 |
generateAspectMethods |
|
308 |
|cls code| |
|
309 |
||
78 | 310 |
code := ''. |
311 |
||
60 | 312 |
className isNil ifTrue:[ |
69 | 313 |
self warn:'set the class first'. |
78 | 314 |
^ code |
60 | 315 |
]. |
89 | 316 |
cls := Smalltalk classNamed:className. |
60 | 317 |
|
318 |
viewProperties do:[:aProp | |
|
62 | 319 |
|modelSelector menuSelector protoSpec thisCode| |
60 | 320 |
|
78 | 321 |
(modelSelector := aProp model) notNil ifTrue:[ |
60 | 322 |
(cls implements:modelSelector asSymbol) ifFalse:[ |
323 |
protoSpec := aProp view specClass basicNew. |
|
324 |
"/ kludge .. |
|
325 |
(protoSpec isMemberOf:ActionButtonSpec) ifTrue:[ |
|
326 |
thisCode := (self generateActionMethodFor:modelSelector spec:protoSpec inClass:cls). |
|
327 |
] ifFalse:[ |
|
328 |
thisCode := (self generateAspectMethodFor:modelSelector spec:protoSpec inClass:cls). |
|
329 |
]. |
|
330 |
code := code , thisCode |
|
62 | 331 |
]. |
332 |
]. |
|
333 |
||
78 | 334 |
(menuSelector := aProp menu) notNil ifTrue:[ |
62 | 335 |
(cls implements:menuSelector asSymbol) ifFalse:[ |
336 |
protoSpec := aProp view specClass basicNew. |
|
337 |
"/ kludge .. |
|
338 |
thisCode := (self generateAspectMethodFor:menuSelector spec:protoSpec inClass:cls). |
|
339 |
code := code , thisCode |
|
60 | 340 |
] |
341 |
] |
|
342 |
]. |
|
343 |
^ code |
|
344 |
||
89 | 345 |
! |
60 | 346 |
|
347 |
generateClassDefinition |
|
348 |
|defCode| |
|
349 |
||
350 |
defCode := superclassName , ' subclass:#' , className , '\'. |
|
351 |
defCode := defCode , ' instanceVariableNames:'''. |
|
352 |
defCode := defCode , self subviewVariableNames , '''\'. |
|
353 |
defCode := defCode , ' classVariableNames:''''\'. |
|
354 |
defCode := defCode , ' poolDictionaries:''''\'. |
|
355 |
defCode := defCode , ' category:''' , categoryName , '''\'. |
|
356 |
defCode := defCode , Character excla asString , '\\'. |
|
357 |
||
358 |
^ defCode withCRs |
|
359 |
||
360 |
||
361 |
||
89 | 362 |
! |
60 | 363 |
|
364 |
generateCode |
|
365 |
"generate code for the windowSpec method" |
|
366 |
||
367 |
|code| |
|
368 |
||
369 |
code := ''. |
|
370 |
||
371 |
"/ (Smalltalk classNamed:className asSymbol) isNil ifTrue:[ |
|
372 |
"/ code := code , self generateClassDefinition. |
|
373 |
"/ ]. |
|
374 |
"/ code := code , self generateInitMethod. |
|
375 |
||
376 |
code := code , self generateWindowSpecMethodSource. |
|
377 |
||
378 |
"/ code := code , self generateAspectMethods. |
|
379 |
||
380 |
^ code withCRs |
|
381 |
||
382 |
"Modified: 5.9.1995 / 20:57:53 / claus" |
|
89 | 383 |
! |
60 | 384 |
|
385 |
generateInitCodeForGroup:aGroup |
|
386 |
|code c name p objects outlets moreCode sym typ val| |
|
387 |
||
388 |
" <name> := <GroupClass> in:<name-of-superview>" |
|
389 |
||
390 |
code := ''. |
|
391 |
||
392 |
p := self propertyOfGroup:aGroup. |
|
393 |
name := p at:#variableName. |
|
394 |
c := ' ' , name , ' := ' , (aGroup class name) , ' new.\'. |
|
395 |
||
396 |
code := code , c withCRs. |
|
397 |
||
398 |
" <name> <symbol>:<value>" |
|
399 |
||
400 |
objects := p at:#controlledObjects ifAbsent:[nil]. |
|
401 |
objects notNil ifTrue:[ |
|
402 |
objects do:[:controlledObject | |
|
78 | 403 |
c := c , name , ' add:' , (self uniqueNameOf:controlledObject) , '.\' |
60 | 404 |
] |
405 |
]. |
|
406 |
||
407 |
code := code , c withCRs |
|
408 |
||
409 |
||
410 |
||
411 |
||
412 |
||
413 |
! |
|
414 |
||
415 |
generateInitCodeForOtherStuff |
|
416 |
|code g c name p outlets moreCode sym typ val| |
|
417 |
||
418 |
code := ''. |
|
419 |
||
420 |
"generate code for groups" |
|
421 |
||
422 |
viewProperties do:[:props | |
|
423 |
g := props at:#group ifAbsent:[nil]. |
|
424 |
g notNil ifTrue:[ |
|
425 |
code := code , (self generateInitCodeForGroup:g) |
|
426 |
] |
|
427 |
]. |
|
428 |
^ code |
|
429 |
||
430 |
||
431 |
! |
|
432 |
||
433 |
generateInitCodeForView:aView |
|
434 |
|code c name p outlets moreCode sym typ val| |
|
435 |
||
436 |
" <name> := <ViewClass> in:<name-of-superview>" |
|
437 |
||
438 |
code := ''. |
|
439 |
||
440 |
p := self propertyOfView:aView. |
|
441 |
name := p at:#variableName. |
|
442 |
c := ' ' , name , ' := ' , |
|
78 | 443 |
(aView class name) , ' in:' , (self uniqueNameOf:(aView superView)) , '.\'. |
60 | 444 |
|
445 |
" <name> origin:(...) extent:(...)" |
|
446 |
||
447 |
c := c , ' ' , name , ' origin:(', aView origin printString , ')' |
|
448 |
, ' extent:(', aView extent printString , ').\'. |
|
449 |
||
450 |
moreCode := p at:#initCode ifAbsent:nil. |
|
451 |
moreCode notNil ifTrue:[ |
|
452 |
c := c , moreCode , '\' withCRs |
|
453 |
]. |
|
454 |
||
455 |
code := code , c withCRs. |
|
456 |
||
457 |
" <name> <symbol>:<value>" |
|
458 |
||
459 |
outlets := p at:#outlets ifAbsent:[nil]. |
|
460 |
outlets notNil ifTrue:[ |
|
461 |
outlets do:[:selectorOutlet | |
|
462 |
sym := selectorOutlet at:#selector. |
|
463 |
typ := selectorOutlet at:#type. |
|
464 |
val := selectorOutlet at:#value. |
|
465 |
c := ' ' , name , ' ' , sym. |
|
466 |
(typ == #number) ifTrue:[ |
|
467 |
c := c , val printString |
|
468 |
]. |
|
469 |
(typ == #string) ifTrue:[ |
|
470 |
c := c , '''' , val , '''' |
|
471 |
]. |
|
472 |
(typ == #text) ifTrue:[ |
|
473 |
c := c , '''' , val asString , '''' |
|
474 |
]. |
|
475 |
(typ == #strings) ifTrue:[ |
|
476 |
c := c , '#( '. |
|
477 |
val asText do:[:aString | |
|
478 |
c := c , '''' , aString , ''' ' |
|
479 |
]. |
|
480 |
c := c , ')' |
|
481 |
]. |
|
482 |
(typ == #block) ifTrue:[ |
|
483 |
c := c , val |
|
484 |
]. |
|
485 |
(typ == #color) ifTrue:[ |
|
486 |
c := c , '(Color name:''' , val , ''')' |
|
487 |
]. |
|
488 |
c := c , '.' , Character cr asString. |
|
489 |
code := code , c |
|
490 |
] |
|
491 |
]. |
|
492 |
||
493 |
self subviewsOf:aView do:[:v | |
|
494 |
code := code , (self generateInitCodeForView:v) |
|
495 |
]. |
|
496 |
^ code. |
|
497 |
||
498 |
"Modified: 5.9.1995 / 20:06:07 / claus" |
|
499 |
! |
|
500 |
||
501 |
generateInitMethod |
|
502 |
|defCode code| |
|
503 |
||
504 |
defCode := Character excla asString , |
|
505 |
className , ' methodsFor:''initialization''' , |
|
506 |
Character excla asString , '\\'. |
|
507 |
||
508 |
defCode := defCode , 'initialize\'. |
|
509 |
defCode := defCode , ' super initialize.\'. |
|
510 |
defCode := defCode , ' self setupSubViews.\'. |
|
511 |
defCode := defCode , ' self setupLocalStuff\'. |
|
512 |
defCode := defCode , Character excla asString , '\\'. |
|
513 |
||
514 |
defCode := defCode , 'setupSubViews\'. |
|
515 |
code := defCode withCRs. |
|
516 |
||
517 |
self subviewsOf:self do:[:v | |
|
518 |
code := code , (self generateInitCodeForView:v) |
|
519 |
]. |
|
520 |
||
521 |
code := code , (self generateInitCodeForOtherStuff). |
|
522 |
||
523 |
code := code , ' ^ self\' withCRs. |
|
524 |
||
525 |
defCode := Character excla asString , '\\'. |
|
526 |
defCode := defCode , 'setupLocalStuff\'. |
|
527 |
defCode := defCode , ' ^ self\'. |
|
528 |
defCode := defCode , Character excla asString , ' ' , |
|
529 |
Character excla asString , '\\'. |
|
530 |
||
531 |
code := code , defCode withCRs. |
|
532 |
^ code. |
|
533 |
||
534 |
||
535 |
||
536 |
||
537 |
! |
|
538 |
||
539 |
generateOutlets |
|
540 |
^ self |
|
89 | 541 |
! |
60 | 542 |
|
78 | 543 |
generateWindowSpecMethodSource |
544 |
|t s spec specArray str code| |
|
60 | 545 |
|
78 | 546 |
specArray := OrderedCollection new. |
60 | 547 |
|
78 | 548 |
self subViews do:[:aView| |
549 |
aView ~~ inputView ifTrue:[ |
|
550 |
specArray add:(self fullSpecFor:aView) |
|
60 | 551 |
] |
552 |
]. |
|
78 | 553 |
spec := FullSpec new. |
554 |
spec fromBuilder:self components:(SpecCollection new collection:specArray). |
|
60 | 555 |
specArray := spec literalArrayEncoding. |
556 |
||
557 |
str := WriteStream on:String new. |
|
86 | 558 |
UISpecification prettyPrintSpecArray:specArray on:str indent:5. |
60 | 559 |
|
560 |
code := Character excla asString |
|
561 |
, className , ' class methodsFor:''interface specs''' |
|
562 |
, Character excla asString , '\\' |
|
563 |
||
564 |
, methodName , '\' |
|
565 |
, ' "this window spec was automatically generated by the ST/X UIPainter"\\' |
|
566 |
, ' "do not manually edit this - the painter/builder may not be able to\' |
|
567 |
, ' handle the specification if its corrupted."\\' |
|
568 |
, ' "\' |
|
569 |
, ' UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\' |
|
570 |
, ' ' , className , ' new openInterface:#' , methodName , '\' |
|
571 |
, ' "\'. |
|
572 |
||
573 |
methodName = 'windowSpec' ifTrue:[ |
|
574 |
code := code , ' "' , className , ' open"\' |
|
575 |
]. |
|
576 |
code := code |
|
577 |
, '\' |
|
578 |
, ' <resource: #canvas>\\' |
|
579 |
, ' ^\' |
|
580 |
, ' ', str contents |
|
581 |
, '\' |
|
582 |
, Character excla asString |
|
583 |
, ' ' |
|
584 |
, Character excla asString |
|
585 |
, '\\'. |
|
586 |
||
587 |
^ code withCRs |
|
588 |
||
589 |
"Modified: 5.9.1995 / 21:01:35 / claus" |
|
89 | 590 |
! |
60 | 591 |
|
592 |
nameOfClass |
|
593 |
^ 'NewView' |
|
89 | 594 |
! |
60 | 595 |
|
596 |
outletValueOf:aSymbol for:aView |
|
597 |
"/ |c name p outlets moreCode sym typ val| |
|
598 |
"/ |
|
599 |
"/ p := self propertyOfView:aView. |
|
600 |
"/ outlets := p at:#outlets ifAbsent:[^ nil]. |
|
601 |
"/ outlets notNil ifTrue:[ |
|
602 |
"/ outlets do:[:selectorOutlet | |
|
603 |
"/ sym := selectorOutlet at:#selector. |
|
604 |
"/ (sym == aSymbol) ifTrue:[ |
|
605 |
"/ typ := selectorOutlet at:#type. |
|
606 |
"/ val := selectorOutlet at:#value. |
|
607 |
"/ ^ val |
|
608 |
"/ ] |
|
609 |
"/ ] |
|
610 |
"/ ]. |
|
611 |
^ nil |
|
612 |
||
613 |
||
614 |
||
615 |
||
616 |
! |
|
617 |
||
618 |
storeContentsOn:aStream |
|
619 |
viewProperties do:[:p| p storeOn:aStream] |
|
620 |
! |
|
621 |
||
622 |
subviewsOf:aView do:aBlock |
|
623 |
|subs v| |
|
624 |
||
625 |
(subs := aView subViews) notNil ifTrue:[ |
|
626 |
subs do:[:v| |
|
627 |
(v ~~ inputView and:[v notNil]) ifTrue:[ |
|
628 |
(viewProperties detect:[:p | p view == v] ifNone:nil) notNil ifTrue:[ |
|
629 |
(v superView == aView) ifTrue:[ |
|
630 |
aBlock value:v |
|
631 |
] |
|
632 |
] |
|
633 |
] |
|
634 |
] |
|
635 |
] |
|
636 |
||
637 |
! ! |
|
638 |
||
639 |
!UIPainterView methodsFor:'group manipulations'! |
|
640 |
||
641 |
groupEnterFields |
|
78 | 642 |
|props group objects| |
60 | 643 |
|
644 |
selection isNil ifTrue:[^ self]. |
|
645 |
self selectionDo:[:aView | |
|
646 |
(aView isKindOf:EditField) ifFalse:[ |
|
647 |
self warn:'select EditFields only !!'. |
|
648 |
^ self |
|
649 |
] |
|
650 |
]. |
|
62 | 651 |
self withSelectionHiddenDo:[ |
60 | 652 |
group := EnterFieldGroup new. |
653 |
props := GroupProperties new. |
|
78 | 654 |
name := self uniqueNameFor:EnterFieldGroup. |
60 | 655 |
props group:group. |
656 |
props name:name. |
|
78 | 657 |
group groupID:name asSymbol. |
60 | 658 |
objects := OrderedCollection new. |
659 |
props controlledObjects:objects. |
|
660 |
viewProperties add:props. |
|
661 |
||
662 |
self selectionDo:[:aView | |
|
663 |
objects add:aView. |
|
664 |
group add:aView |
|
665 |
]. |
|
666 |
] |
|
667 |
||
668 |
||
669 |
! |
|
670 |
||
671 |
groupRadioButtons |
|
78 | 672 |
|props name group objects| |
60 | 673 |
|
674 |
selection isNil ifTrue:[^ self]. |
|
675 |
self selectionDo:[:aView | |
|
676 |
(aView isKindOf:RadioButton) ifFalse:[ |
|
677 |
self warn:'select RadioButtons only !!'. |
|
678 |
^ self |
|
679 |
] |
|
680 |
]. |
|
62 | 681 |
self withSelectionHiddenDo:[ |
60 | 682 |
group := RadioButtonGroup new. |
683 |
props := GroupProperties new. |
|
78 | 684 |
name := self uniqueNameFor:RadioButtonGroup. |
60 | 685 |
props group:group. |
686 |
props name:name. |
|
687 |
group groupID:name asSymbol. |
|
688 |
objects := OrderedCollection new. |
|
689 |
props controlledObjects:objects. |
|
690 |
viewProperties add:props. |
|
691 |
||
692 |
self selectionDo:[:aView | |
|
693 |
aView turnOff. |
|
694 |
objects add:aView. |
|
695 |
group add:aView |
|
696 |
]. |
|
697 |
] |
|
698 |
||
699 |
"Modified: 5.9.1995 / 16:06:15 / claus" |
|
700 |
! ! |
|
701 |
||
702 |
!UIPainterView methodsFor:'initialization'! |
|
703 |
||
704 |
initialize |
|
62 | 705 |
"setup attributes |
706 |
" |
|
60 | 707 |
super initialize. |
708 |
||
709 |
superclassName := 'ApplicationModel'. |
|
710 |
className := 'NewApplication'. |
|
711 |
methodName := 'windowSpec'. |
|
712 |
categoryName := 'Applications'. |
|
713 |
viewProperties := OrderedCollection new. |
|
714 |
HandCursor := Cursor leftHand. |
|
715 |
||
716 |
"Modified: 5.9.1995 / 19:58:06 / claus" |
|
717 |
! |
|
718 |
||
78 | 719 |
initializeCreatedObject:anObject |
720 |
"set default properties for a created object |
|
721 |
" |
|
722 |
|props spec cls| |
|
60 | 723 |
|
78 | 724 |
cls := anObject class. |
725 |
spec := anObject specClass fromView:anObject. |
|
726 |
props := ViewProperty new. |
|
727 |
props view:anObject. |
|
728 |
props spec:spec. |
|
729 |
props name:(self uniqueNameFor:cls). |
|
730 |
viewProperties add:props. |
|
60 | 731 |
|
82 | 732 |
((spec respondsTo:#label:) and:[self supportsLabel:anObject]) ifTrue:[ |
78 | 733 |
anObject label:(props name). |
734 |
spec label:(props name) |
|
60 | 735 |
]. |
736 |
||
78 | 737 |
undoHistory transaction:#create text:(props name) do:[ |
738 |
self undoCreate:(props identifier). |
|
60 | 739 |
]. |
740 |
! |
|
741 |
||
742 |
setupFromSpec:specOrSpecArray |
|
78 | 743 |
|spec builder| |
60 | 744 |
|
78 | 745 |
self removeAll. |
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
746 |
|
78 | 747 |
spec := UISpecification from:specOrSpecArray. |
748 |
builder := UIBuilder new. |
|
749 |
spec window setupView:self topView for:builder. |
|
750 |
self addSpec:(spec component) builder:builder in:self. |
|
751 |
self realizeAllSubViews. |
|
752 |
inputView raise. |
|
753 |
self changed:#tree. |
|
60 | 754 |
! ! |
755 |
||
756 |
!UIPainterView methodsFor:'menus'! |
|
757 |
||
758 |
menu |
|
62 | 759 |
"returns middle-button menu dependent on the selection |
760 |
" |
|
71 | 761 |
|menu canPaste undoIdx undoText| |
60 | 762 |
|
763 |
testMode ifTrue:[^ nil ]. |
|
764 |
||
765 |
canPaste := self canPaste:(self getSelection). |
|
71 | 766 |
undoText := undoHistory lastTypeAsString. |
60 | 767 |
|
768 |
selection isNil ifTrue:[ |
|
71 | 769 |
undoIdx := 2. |
770 |
||
771 |
menu := PopUpMenu labels:( resources array:#('paste' 'undo') ) |
|
89 | 772 |
selectors:#( #paste #undoLast ) |
773 |
receiver:self |
|
71 | 774 |
] ifFalse:[ |
775 |
undoIdx := 4. |
|
60 | 776 |
|
71 | 777 |
menu := PopUpMenu labels:( resources array:#( |
778 |
'copy' |
|
779 |
'cut' |
|
780 |
'paste' |
|
781 |
'undo' |
|
782 |
'-' |
|
783 |
'arrange' |
|
784 |
'dimension' |
|
785 |
'align' |
|
786 |
) |
|
787 |
) |
|
788 |
selectors:#( #copySelection |
|
789 |
#deleteSelection |
|
89 | 790 |
#paste |
71 | 791 |
#undoLast |
792 |
nil |
|
793 |
#arrange |
|
794 |
#dimension |
|
795 |
#align |
|
796 |
) |
|
797 |
accelerators:#(#Copy |
|
798 |
#Cut |
|
89 | 799 |
nil |
71 | 800 |
nil |
801 |
nil |
|
802 |
nil |
|
803 |
nil |
|
804 |
nil |
|
805 |
) |
|
806 |
receiver:self. |
|
60 | 807 |
|
89 | 808 |
canPaste := (canPaste and:[self canPasteInto:selection]). |
71 | 809 |
menu subMenuAt:#arrange put:(self subMenuArrange). |
810 |
menu subMenuAt:#dimension put:(self subMenuDimension). |
|
811 |
menu subMenuAt:#align put:(self subMenuAlign). |
|
60 | 812 |
]. |
813 |
||
89 | 814 |
menu subMenuAt:#paste put:(self subMenuPaste). |
815 |
canPaste ifFalse:[menu disable:#paste]. |
|
816 |
||
71 | 817 |
undoText notNil ifTrue:[ |
818 |
menu labelAt:undoIdx put:((menu labels at:undoIdx), ': ', undoText) |
|
819 |
] ifFalse:[ |
|
820 |
menu disable:#undoLast |
|
821 |
]. |
|
60 | 822 |
^ menu |
823 |
||
62 | 824 |
|
825 |
||
60 | 826 |
! |
827 |
||
78 | 828 |
showFontPanel |
829 |
|action| |
|
830 |
||
831 |
fontPanel isNil ifTrue:[ |
|
832 |
fontPanel := FontPanel new |
|
833 |
]. |
|
834 |
||
835 |
selection notNil ifTrue:[ |
|
836 |
action := [:family :face :style :size | |
|
837 |
self changeFontFamily:family face:face |
|
838 |
style:style size:size |
|
839 |
]. |
|
840 |
fontPanel action:action. |
|
841 |
fontPanel showAtPointer |
|
842 |
] |
|
843 |
! |
|
844 |
||
60 | 845 |
subMenuAlign |
846 |
"returns submenu alignment |
|
847 |
" |
|
848 |
|menu| |
|
849 |
||
850 |
menu := PopUpMenu labels:( |
|
851 |
resources array:#( |
|
852 |
'align left' |
|
853 |
'align right' |
|
854 |
'align left & right' |
|
855 |
'align top' |
|
856 |
'align bottom' |
|
857 |
'align centered vertical' |
|
858 |
'align centered horizontal' |
|
859 |
'-' |
|
860 |
'spread horizontal' |
|
861 |
'spread vertical' |
|
62 | 862 |
'-' |
60 | 863 |
'center horizontal in frame' |
864 |
'center vertical in frame' |
|
865 |
) |
|
866 |
) |
|
867 |
||
868 |
selectors:#( |
|
869 |
alignSelectionLeft |
|
870 |
alignSelectionRight |
|
871 |
alignSelectionLeftAndRight |
|
872 |
alignSelectionTop |
|
873 |
alignSelectionBottom |
|
874 |
alignSelectionCenterHor |
|
875 |
alignSelectionCenterVer |
|
876 |
nil |
|
877 |
spreadSelectionHor |
|
878 |
spreadSelectionVer |
|
62 | 879 |
nil |
60 | 880 |
centerSelectionHor |
881 |
centerSelectionVer |
|
882 |
) |
|
883 |
receiver:self. |
|
884 |
^ menu |
|
885 |
||
886 |
! |
|
887 |
||
888 |
subMenuArrange |
|
889 |
"returns submenu arrange |
|
890 |
" |
|
891 |
|menu| |
|
892 |
||
893 |
menu := PopUpMenu labels:( |
|
894 |
resources array:#( |
|
895 |
'to front' |
|
896 |
'to back' |
|
897 |
) |
|
898 |
) |
|
899 |
selectors:#( |
|
900 |
raiseSelection |
|
901 |
lowerSelection |
|
902 |
) |
|
903 |
receiver:self. |
|
904 |
^ menu |
|
905 |
! |
|
906 |
||
907 |
subMenuDimension |
|
908 |
"returns submenu dimension |
|
909 |
" |
|
910 |
|menu| |
|
911 |
||
912 |
menu := PopUpMenu labels:( |
|
913 |
resources array:#( |
|
914 |
'default extent' |
|
915 |
'default width' |
|
916 |
'default height' |
|
917 |
'-' |
|
918 |
'copy extent' |
|
919 |
'-' |
|
920 |
'paste extent' |
|
921 |
'paste width' |
|
922 |
'paste height' |
|
89 | 923 |
'-' |
924 |
'copy layout' |
|
925 |
'paste layout' |
|
60 | 926 |
) |
927 |
) |
|
928 |
selectors:#( |
|
929 |
setToDefaultExtent |
|
930 |
setToDefaultWidth |
|
931 |
setToDefaultHeight |
|
932 |
nil |
|
933 |
copyExtent |
|
934 |
nil |
|
935 |
pasteExtent |
|
936 |
pasteWidth |
|
937 |
pasteHeight |
|
89 | 938 |
nil |
939 |
copyLayout |
|
940 |
pasteLayout |
|
60 | 941 |
) |
942 |
receiver:self. |
|
943 |
^ menu |
|
944 |
! |
|
945 |
||
946 |
subMenuFont |
|
947 |
"returns submenu dimension |
|
948 |
" |
|
949 |
|menu| |
|
950 |
||
951 |
menu := PopUpMenu labels:( |
|
952 |
resources array:#( |
|
953 |
'larger' |
|
954 |
'smaller' |
|
955 |
'-' |
|
956 |
'normal' |
|
957 |
'bold' |
|
958 |
'italic' |
|
959 |
'bold italic' |
|
960 |
'-' |
|
961 |
'font panel' |
|
962 |
) |
|
963 |
) |
|
964 |
selectors:#( |
|
965 |
largerFont |
|
966 |
smallerFont |
|
967 |
nil |
|
968 |
normalFont |
|
969 |
boldFont |
|
970 |
italicFont |
|
971 |
boldItalicFont |
|
972 |
nil |
|
973 |
showFontPanel |
|
974 |
) |
|
975 |
receiver:self. |
|
976 |
^ menu |
|
89 | 977 |
! |
978 |
||
979 |
subMenuPaste |
|
980 |
"returns submenu Paste |
|
981 |
" |
|
982 |
|menu| |
|
983 |
||
984 |
menu := PopUpMenu labels:( resources array:#('paste' 'keep layout') ) |
|
985 |
selectors:#( #pasteBuffer #pasteWithLayout ) |
|
986 |
accelerators:#( #Paste nil ) |
|
987 |
receiver:self. |
|
988 |
||
989 |
^ menu |
|
990 |
||
60 | 991 |
! ! |
992 |
||
993 |
!UIPainterView methodsFor:'misc'! |
|
994 |
||
995 |
changeFontFamily:family face:face style:style size:size |
|
996 |
|f| |
|
997 |
||
998 |
f := Font family:family |
|
999 |
face:face |
|
1000 |
style:style |
|
1001 |
size:size. |
|
1002 |
||
1003 |
f notNil ifTrue:[ |
|
62 | 1004 |
self withSelectionHiddenDo:[ |
60 | 1005 |
self selectionDo:[:aView | |
1006 |
aView font:f. |
|
62 | 1007 |
self elementChangedSize:aView. |
60 | 1008 |
] |
62 | 1009 |
]. |
1010 |
self changed:#any. |
|
60 | 1011 |
] |
1012 |
||
1013 |
"Modified: 5.9.1995 / 12:13:27 / claus" |
|
1014 |
! ! |
|
1015 |
||
1016 |
!UIPainterView methodsFor:'removing components'! |
|
1017 |
||
78 | 1018 |
remove:anObject |
1019 |
"remove anObject from the contents do redraw |
|
60 | 1020 |
" |
78 | 1021 |
|props| |
1022 |
||
1023 |
anObject notNil ifTrue:[ |
|
1024 |
(anObject subViews notNil) ifTrue:[ |
|
1025 |
anObject subViews copy do:[:sub | |
|
1026 |
self remove:sub |
|
1027 |
] |
|
1028 |
]. |
|
1029 |
(props := self propertyOfView:anObject) notNil ifTrue:[ |
|
1030 |
viewProperties remove:props ifAbsent:nil |
|
1031 |
]. |
|
1032 |
anObject destroy |
|
60 | 1033 |
] |
1034 |
! |
|
1035 |
||
1036 |
removeAll |
|
62 | 1037 |
"remove all objects and properties |
1038 |
" |
|
60 | 1039 |
self unselect. |
62 | 1040 |
viewProperties := OrderedCollection new. |
60 | 1041 |
|
1042 |
subViews notNil ifTrue:[ |
|
1043 |
subViews copy do:[:sub | |
|
1044 |
sub ~~ inputView ifTrue:[ |
|
78 | 1045 |
self remove:sub |
60 | 1046 |
] |
1047 |
] |
|
1048 |
]. |
|
1049 |
undoHistory reinitialize. |
|
1050 |
self changed:#tree |
|
1051 |
! ! |
|
1052 |
||
1053 |
!UIPainterView methodsFor:'searching'! |
|
1054 |
||
89 | 1055 |
findContainerViewAt:aPoint |
1056 |
"find container view responds to aPoint. |
|
1057 |
" |
|
1058 |
|view| |
|
1059 |
||
1060 |
(view := self findObjectAt:aPoint) isNil ifTrue:[ |
|
1061 |
^ self |
|
1062 |
]. |
|
1063 |
||
1064 |
[(view specClass supportsSubComponents or:[(view := view superView) == self]) |
|
1065 |
] whileFalse:[ |
|
1066 |
[(self propertyOfView:view) isNil] whileTrue:[ |
|
1067 |
(view := view superView) == self ifTrue:[^ self] |
|
1068 |
]. |
|
1069 |
]. |
|
1070 |
^ view |
|
1071 |
! |
|
1072 |
||
60 | 1073 |
findObjectAt:aPoint |
1074 |
"find the origin/corner of the currentWidget |
|
1075 |
" |
|
1076 |
|view| |
|
1077 |
||
1078 |
view := super findObjectAt:aPoint. |
|
1079 |
||
1080 |
view notNil ifTrue:[ |
|
1081 |
"can be a view within a view not visible |
|
1082 |
" |
|
1083 |
[ (self propertyOfView:view) isNil ] whileTrue:[ |
|
1084 |
(view := view superView) == self ifTrue:[^ nil] |
|
1085 |
] |
|
1086 |
]. |
|
1087 |
^ view |
|
1088 |
! |
|
1089 |
||
1090 |
findViewWithId:aViewId |
|
62 | 1091 |
"finds view assigned to identifier and returns the view or nil |
60 | 1092 |
" |
1093 |
|prop| |
|
1094 |
||
1095 |
prop := self propertyOfIdentifier:aViewId. |
|
1096 |
||
1097 |
prop notNil ifTrue:[^ prop view] |
|
1098 |
ifFalse:[^ nil] |
|
78 | 1099 |
! |
1100 |
||
1101 |
propertyOfGroup:aGroup |
|
1102 |
"returns property assigned to group |
|
1103 |
" |
|
1104 |
^ viewProperties detect:[:p| p group == aGroup] ifNone:nil |
|
1105 |
! |
|
1106 |
||
1107 |
propertyOfIdentifier:anId |
|
1108 |
"returns property assigned to unique identifier |
|
1109 |
" |
|
1110 |
anId notNil ifTrue:[ |
|
1111 |
^ viewProperties detect:[:p| p identifier == anId] ifNone:nil. |
|
1112 |
]. |
|
1113 |
^ nil |
|
1114 |
! |
|
1115 |
||
1116 |
propertyOfName:aString |
|
1117 |
"returns property assigned to name |
|
1118 |
" |
|
1119 |
aString = 'self' ifFalse:[ |
|
1120 |
^ viewProperties detect:[:p| p name = aString] ifNone:nil |
|
1121 |
]. |
|
1122 |
^ nil |
|
1123 |
! |
|
1124 |
||
1125 |
propertyOfView:aView |
|
1126 |
"returns property assigned to view |
|
1127 |
" |
|
1128 |
(aView isNil or:[aView == self]) ifFalse:[ |
|
1129 |
^ viewProperties detect:[:p| p view == aView] ifNone:nil |
|
1130 |
]. |
|
1131 |
^ nil |
|
1132 |
! |
|
1133 |
||
1134 |
uniqueNameFor:aClass |
|
1135 |
"generate and return an unique name for a class |
|
1136 |
" |
|
1137 |
|next name size| |
|
1138 |
||
1139 |
next := 0. |
|
1140 |
name := aClass name asString copy. |
|
1141 |
size := name size + 1. |
|
1142 |
||
1143 |
name at:1 put:(name at:1) asLowercase. |
|
1144 |
||
1145 |
viewProperties do:[:p||n| |
|
1146 |
n := p name. |
|
1147 |
||
1148 |
(n size >= size and:[n startsWith:name]) ifTrue:[ |
|
1149 |
next := next max:(p extractNumberStartingAt:size) |
|
1150 |
] |
|
1151 |
]. |
|
1152 |
next := next + 1. |
|
1153 |
name := name, next printString. |
|
1154 |
^ name |
|
1155 |
||
1156 |
||
1157 |
||
1158 |
! |
|
1159 |
||
1160 |
uniqueNameOf:aView |
|
86 | 1161 |
|name prop| |
78 | 1162 |
|
1163 |
aView notNil ifTrue:[ |
|
1164 |
prop := self propertyOfView:aView |
|
1165 |
]. |
|
86 | 1166 |
prop isNil ifTrue:[ |
1167 |
^ 'self' |
|
1168 |
]. |
|
1169 |
(name := prop name) isNil ifTrue:[ |
|
1170 |
name := self uniqueNameFor:(aView class). |
|
1171 |
prop name:name. |
|
1172 |
]. |
|
1173 |
^ name |
|
78 | 1174 |
|
60 | 1175 |
! ! |
1176 |
||
71 | 1177 |
!UIPainterView methodsFor:'selection'! |
1178 |
||
1179 |
addTreeFrom:aView to:aCollection |
|
1180 |
"add aView and contained subcomponents to collection |
|
1181 |
" |
|
78 | 1182 |
(self propertyOfView:aView) notNil ifTrue:[ |
71 | 1183 |
aCollection add:aView. |
1184 |
||
1185 |
(aView subViews notNil) ifTrue:[ |
|
1186 |
aView subViews do:[:subView| |
|
1187 |
self addTreeFrom:subView to:aCollection |
|
1188 |
] |
|
1189 |
]. |
|
1190 |
] |
|
1191 |
||
1192 |
! |
|
1193 |
||
1194 |
selectSubComponents |
|
1195 |
"select all subcomponents for current selection |
|
1196 |
" |
|
1197 |
|startAtView aCollection| |
|
1198 |
||
1199 |
aCollection := OrderedCollection new. |
|
1200 |
startAtView := self singleSelection. |
|
1201 |
||
1202 |
startAtView isNil ifTrue:[ |
|
1203 |
self subViews notNil ifTrue:[ |
|
1204 |
self subViews do:[:subView| |
|
1205 |
subView ~~ inputView ifTrue:[ |
|
1206 |
self addTreeFrom:subView to:aCollection |
|
1207 |
] |
|
1208 |
] |
|
1209 |
] |
|
1210 |
] ifFalse:[ |
|
1211 |
self addTreeFrom:startAtView to:aCollection |
|
1212 |
]. |
|
1213 |
||
1214 |
aCollection size > 1 ifTrue:[ |
|
1215 |
self withSelectionHiddenDo:[ |
|
1216 |
selection := aCollection |
|
1217 |
]. |
|
1218 |
self changed:#selection |
|
1219 |
] |
|
1220 |
! ! |
|
1221 |
||
78 | 1222 |
!UIPainterView methodsFor:'specification'! |
1223 |
||
1224 |
addSpec:aSpecification builder:aBuilder in:aFrame |
|
1225 |
"build view and subviews from aSpecification into a frame. The top view |
|
1226 |
is returned. The contained components of a spec are set to nil |
|
1227 |
" |
|
1228 |
aBuilder applicationClass:(Smalltalk classNamed:className). |
|
1229 |
||
1230 |
aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s| |
|
1231 |
p := ViewProperty new. |
|
1232 |
s := aSpec copy. |
|
1233 |
p spec:s. |
|
1234 |
p view:aView. |
|
1235 |
||
1236 |
s class supportsSubComponents ifTrue:[ |
|
1237 |
s component:nil |
|
1238 |
]. |
|
1239 |
||
1240 |
(self propertyOfName:(s name)) notNil ifTrue:[ |
|
1241 |
s name:(self uniqueNameFor:(aView class)) |
|
1242 |
]. |
|
1243 |
viewProperties add:p |
|
1244 |
]. |
|
1245 |
||
1246 |
^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame. |
|
60 | 1247 |
|
78 | 1248 |
! |
1249 |
||
1250 |
fullSpecFor:anObject |
|
1251 |
"generate a full spec for an object |
|
62 | 1252 |
" |
78 | 1253 |
|mySpec subSpecs| |
1254 |
||
1255 |
mySpec := self specFor:anObject. |
|
1256 |
||
1257 |
(mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[ |
|
1258 |
(anObject subViews notNil) ifTrue:[ |
|
1259 |
anObject subViews do:[:aSubView||spec| |
|
1260 |
spec := self fullSpecFor:aSubView. |
|
1261 |
spec notNil ifTrue:[ |
|
1262 |
subSpecs isNil ifTrue:[ |
|
1263 |
subSpecs := OrderedCollection new |
|
1264 |
]. |
|
1265 |
subSpecs add:spec. |
|
1266 |
]. |
|
1267 |
]. |
|
1268 |
subSpecs notNil ifTrue:[ |
|
1269 |
mySpec component:(SpecCollection new collection:subSpecs) |
|
1270 |
] |
|
1271 |
] |
|
1272 |
]. |
|
1273 |
^ mySpec |
|
1274 |
||
60 | 1275 |
|
1276 |
||
1277 |
||
1278 |
||
1279 |
||
1280 |
! |
|
1281 |
||
78 | 1282 |
specFor:anObject |
1283 |
"returns spec assigned to an object |
|
62 | 1284 |
" |
78 | 1285 |
|prop spec| |
60 | 1286 |
|
78 | 1287 |
(prop := self propertyOfView:anObject) notNil ifTrue:[ |
1288 |
spec := prop spec copy. |
|
1289 |
spec layoutFromView:anObject |
|
60 | 1290 |
]. |
78 | 1291 |
^ spec |
1292 |
||
1293 |
||
1294 |
||
60 | 1295 |
! |
1296 |
||
78 | 1297 |
updateFromSpec:aSpec |
1298 |
"update current selected view from specification |
|
62 | 1299 |
" |
78 | 1300 |
|props name builder v| |
1301 |
||
1302 |
self singleSelection notNil ifTrue:[ |
|
1303 |
self withSelectionHiddenDo:[ |
|
1304 |
self transaction:#specification selectionDo:[:aView| |
|
1305 |
builder := UIBuilder new. |
|
1306 |
props := self propertyOfView:aView. |
|
82 | 1307 |
name := (aSpec name) withoutSeparators. |
78 | 1308 |
|
82 | 1309 |
name = props name ifFalse:[ |
1310 |
(self propertyOfName:name) notNil ifTrue:[ |
|
1311 |
name := props name |
|
78 | 1312 |
] |
1313 |
]. |
|
82 | 1314 |
aSpec name:name. |
1315 |
self undoSpecModify:(props identifier). |
|
78 | 1316 |
|
1317 |
aSpec needsRebuildForAttributes ifTrue:[ |
|
1318 |
v := aSpec buildViewWithLayoutFor:builder in:aView superView. |
|
1319 |
v realize. |
|
1320 |
aView destroy. |
|
1321 |
device sync. device flush. |
|
1322 |
aView becomeSameAs:v. |
|
1323 |
inputView raise. |
|
1324 |
] ifFalse:[ |
|
1325 |
aSpec setAttributesIn:aView with:builder. |
|
1326 |
self elementChangedSize:aView. |
|
1327 |
]. |
|
1328 |
||
1329 |
props spec:(aSpec copy). |
|
1330 |
] |
|
1331 |
]. |
|
1332 |
self changed:#tree |
|
82 | 1333 |
] |
60 | 1334 |
! ! |
1335 |
||
1336 |
!UIPainterView methodsFor:'testing'! |
|
1337 |
||
1338 |
isHorizontalResizable:aComponent |
|
62 | 1339 |
"returns true if instance is horizontal resizeable |
1340 |
" |
|
60 | 1341 |
(aComponent isKindOf:ScrollBar) ifTrue:[ |
1342 |
^ aComponent orientation == #horizontal |
|
1343 |
]. |
|
1344 |
(aComponent isKindOf:Scroller) ifTrue:[ |
|
1345 |
^ aComponent orientation == #horizontal |
|
1346 |
]. |
|
1347 |
(aComponent isKindOf:Slider) ifTrue:[ |
|
1348 |
^ aComponent orientation == #horizontal |
|
1349 |
]. |
|
1350 |
^ true |
|
1351 |
||
1352 |
||
1353 |
! |
|
1354 |
||
1355 |
isVerticalResizable:aComponent |
|
62 | 1356 |
"returns true if instance is vertical resizeable |
1357 |
" |
|
60 | 1358 |
(aComponent isKindOf:EditField) ifTrue:[ |
1359 |
^ false |
|
1360 |
]. |
|
1361 |
(aComponent isKindOf:ComboBoxView) ifTrue:[ |
|
1362 |
^ false |
|
1363 |
]. |
|
1364 |
(aComponent isKindOf:CheckBox) ifTrue:[ |
|
1365 |
^ false |
|
1366 |
]. |
|
1367 |
(aComponent isKindOf:ScrollBar) ifTrue:[ |
|
1368 |
^ aComponent orientation == #vertical |
|
1369 |
]. |
|
1370 |
(aComponent isKindOf:Scroller) ifTrue:[ |
|
1371 |
^ aComponent orientation == #vertical |
|
1372 |
]. |
|
1373 |
(aComponent isKindOf:Slider) ifTrue:[ |
|
1374 |
^ aComponent orientation == #vertical |
|
1375 |
]. |
|
1376 |
^ true |
|
1377 |
||
1378 |
||
82 | 1379 |
! |
1380 |
||
1381 |
supportsLabel:aComponent |
|
1382 |
"returns true if component supports label |
|
1383 |
" |
|
1384 |
(aComponent respondsTo:#label:) ifTrue:[ |
|
1385 |
( (aComponent isKindOf:ArrowButton) |
|
1386 |
or:[aComponent isKindOf:CheckToggle] |
|
1387 |
) ifFalse:[ |
|
1388 |
^ true |
|
1389 |
] |
|
1390 |
]. |
|
1391 |
^ false |
|
60 | 1392 |
! ! |
1393 |
||
1394 |
!UIPainterView methodsFor:'transaction'! |
|
1395 |
||
1396 |
transaction:aType objects:something do:aOneArgBlock |
|
1397 |
"opens a transaction and evaluates a block within the transaction; the |
|
1398 |
argument to the block is a view from derived from something |
|
1399 |
" |
|
1400 |
|text| |
|
1401 |
||
1402 |
something notNil ifTrue:[ |
|
1403 |
text := self transactionTextFor:something. |
|
1404 |
||
1405 |
undoHistory transaction:aType text:text do:[ |
|
1406 |
something isCollection ifTrue:[ |
|
1407 |
something do:[:aView| aOneArgBlock value:aView ] |
|
1408 |
] ifFalse:[ |
|
1409 |
aOneArgBlock value:something |
|
1410 |
] |
|
1411 |
] |
|
1412 |
] |
|
1413 |
! |
|
1414 |
||
1415 |
transactionTextFor:anElementOrCollection |
|
1416 |
"returns text used by transaction or nil |
|
1417 |
" |
|
1418 |
|props size| |
|
1419 |
||
1420 |
anElementOrCollection notNil ifTrue:[ |
|
1421 |
anElementOrCollection isCollection ifTrue:[ |
|
1422 |
size := anElementOrCollection size. |
|
1423 |
size == 0 ifTrue:[^ nil]. |
|
1424 |
size ~~ 1 ifTrue:[^ size printString, ' elements']. |
|
1425 |
||
1426 |
props := self propertyOfView:(anElementOrCollection at:1). |
|
1427 |
] ifFalse:[ |
|
1428 |
props := self propertyOfView:anElementOrCollection |
|
1429 |
]. |
|
1430 |
props notNil ifTrue:[ ^ props name ] |
|
1431 |
]. |
|
1432 |
^ nil |
|
1433 |
! ! |
|
1434 |
||
1435 |
!UIPainterView methodsFor:'undo actions'! |
|
1436 |
||
1437 |
undoCreate:aViewId |
|
62 | 1438 |
"undo method when creating or pasting an object |
1439 |
" |
|
60 | 1440 |
undoHistory addUndoBlock:[ |
78 | 1441 |
self remove:(self findViewWithId:aViewId) |
60 | 1442 |
] |
1443 |
||
1444 |
! |
|
1445 |
||
1446 |
undoLayout:aViewId |
|
62 | 1447 |
"undo method when changing the layout (position or dimension) |
60 | 1448 |
" |
62 | 1449 |
|view layout extent| |
60 | 1450 |
|
1451 |
(view := self findViewWithId:aViewId) notNil ifTrue:[ |
|
62 | 1452 |
(layout := view geometryLayout copy) isNil ifTrue:[ |
1453 |
extent := view extent copy |
|
1454 |
]. |
|
1455 |
undoHistory addUndoBlock:[ |
|
1456 |
(view := self findViewWithId:aViewId) notNil ifTrue:[ |
|
1457 |
layout notNil ifTrue:[view geometryLayout:layout] |
|
1458 |
ifFalse:[view extent:extent] |
|
60 | 1459 |
] |
1460 |
] |
|
62 | 1461 |
]. |
1462 |
view := nil |
|
60 | 1463 |
! |
1464 |
||
1465 |
undoLayoutView:aView |
|
1466 |
"undo method for changing layout on a view |
|
1467 |
" |
|
1468 |
|prop| |
|
1469 |
||
1470 |
undoHistory isTransactionOpen ifTrue:[ |
|
1471 |
prop := self propertyOfView:aView. |
|
1472 |
prop notNil ifTrue:[ |
|
1473 |
self undoLayout:(prop identifier) |
|
1474 |
] |
|
1475 |
] |
|
1476 |
! |
|
1477 |
||
1478 |
undoRemove:aViewId |
|
62 | 1479 |
"undo method when removing an object |
60 | 1480 |
" |
78 | 1481 |
|frame prop spec parentId| |
60 | 1482 |
|
78 | 1483 |
frame := self findViewWithId:aViewId. |
1484 |
spec := self fullSpecFor:frame. |
|
1485 |
frame := frame superView. |
|
60 | 1486 |
|
78 | 1487 |
(self canPasteInto:frame) ifTrue:[ |
1488 |
(prop := self propertyOfView:frame) notNil ifTrue:[ |
|
1489 |
parentId := prop identifier |
|
1490 |
] |
|
1491 |
]. |
|
1492 |
frame := nil. |
|
1493 |
prop := nil. |
|
60 | 1494 |
|
78 | 1495 |
undoHistory addUndoBlock:[ |
1496 |
|view| |
|
60 | 1497 |
|
78 | 1498 |
frame := self findViewWithId:parentId. |
1499 |
frame isNil ifTrue:[ |
|
1500 |
frame := self |
|
60 | 1501 |
]. |
78 | 1502 |
view := self addSpec:spec builder:(UIBuilder new) in:frame. |
1503 |
view realize. |
|
1504 |
inputView raise. |
|
60 | 1505 |
] |
1506 |
! |
|
1507 |
||
1508 |
undoSpecModify:aViewId |
|
62 | 1509 |
"undo method when changing the specification for an object |
60 | 1510 |
" |
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1511 |
|builder view spec v props| |
60 | 1512 |
|
1513 |
(view := self findViewWithId:aViewId) notNil ifTrue:[ |
|
78 | 1514 |
spec := self specFor:view. |
60 | 1515 |
view := nil. |
1516 |
||
1517 |
undoHistory addUndoBlock:[ |
|
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1518 |
props := self propertyOfIdentifier:aViewId. |
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1519 |
props notNil ifTrue:[ |
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1520 |
view := props view. |
60 | 1521 |
builder := UIBuilder new. |
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1522 |
props spec:spec. |
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1523 |
|
75 | 1524 |
spec needsRebuildForAttributes ifTrue:[ |
1525 |
v := spec buildViewWithLayoutFor:builder in:view superView. |
|
1526 |
v realize. |
|
1527 |
view destroy. |
|
80
3316c52ef2b7
write back specification to properties after undo modification
ca
parents:
78
diff
changeset
|
1528 |
view become:v |
75 | 1529 |
] ifFalse:[ |
1530 |
spec setAttributesIn:view with:builder. |
|
1531 |
self elementChangedSize:view. |
|
1532 |
]. |
|
60 | 1533 |
] |
1534 |
] |
|
1535 |
]. |
|
1536 |
||
1537 |
||
1538 |
||
1539 |
! ! |
|
1540 |
||
1541 |
!UIPainterView::ViewProperty class methodsFor:'documentation'! |
|
1542 |
||
1543 |
version |
|
1544 |
^ '$Header$' |
|
1545 |
! ! |
|
1546 |
||
51 | 1547 |
!UIPainterView::ViewProperty class methodsFor:'instance creation'! |
1548 |
||
1549 |
new |
|
1550 |
Identifier notNil ifTrue:[Identifier := Identifier + 1] |
|
1551 |
ifFalse:[Identifier := 1]. |
|
1552 |
||
1553 |
^ self basicNew initialize |
|
1554 |
! ! |
|
1555 |
||
1556 |
!UIPainterView::ViewProperty methodsFor:'accessing'! |
|
1557 |
||
1558 |
group |
|
1559 |
^ nil |
|
1560 |
! |
|
1561 |
||
1562 |
identifier |
|
1563 |
"return the unique identifier assigned to property |
|
1564 |
" |
|
1565 |
^ identifier |
|
1566 |
! |
|
1567 |
||
78 | 1568 |
spec |
1569 |
"return the value of the instance variable 'spec' (automatically generated)" |
|
51 | 1570 |
|
78 | 1571 |
^ spec! |
59 | 1572 |
|
78 | 1573 |
spec:something |
1574 |
"set the value of the instance variable 'spec' (automatically generated)" |
|
51 | 1575 |
|
78 | 1576 |
spec := something.! |
57 | 1577 |
|
51 | 1578 |
view |
1579 |
"return the value of the instance variable 'view' (automatically generated)" |
|
1580 |
||
1581 |
^ view! |
|
1582 |
||
1583 |
view:something |
|
1584 |
"set the value of the instance variable 'view' (automatically generated)" |
|
1585 |
||
1586 |
view := something.! ! |
|
1587 |
||
1588 |
!UIPainterView::ViewProperty methodsFor:'initialization'! |
|
1589 |
||
1590 |
initialize |
|
1591 |
super initialize. |
|
1592 |
identifier := Identifier |
|
1593 |
! ! |
|
1594 |
||
78 | 1595 |
!UIPainterView::ViewProperty methodsFor:'misc'! |
1596 |
||
1597 |
extractNumberStartingAt:anIndex |
|
1598 |
"return the number from the name starting at anIndex or 0. |
|
1599 |
" |
|
1600 |
|val| |
|
1601 |
||
1602 |
val := 0. |
|
1603 |
||
1604 |
self name from:anIndex do:[:c| |
|
1605 |
c isDigit ifTrue:[val := val * 10 + c digitValue] |
|
1606 |
ifFalse:[^ 0] |
|
1607 |
]. |
|
1608 |
^ val |
|
1609 |
||
1610 |
! ! |
|
1611 |
||
1612 |
!UIPainterView::ViewProperty methodsFor:'spec messages'! |
|
1613 |
||
1614 |
doesNotUnderstand:aMessage |
|
1615 |
spec notNil ifTrue:[ |
|
1616 |
(spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec] |
|
1617 |
]. |
|
1618 |
^ nil |
|
1619 |
! |
|
1620 |
||
1621 |
layout |
|
1622 |
spec layout |
|
1623 |
! |
|
1624 |
||
1625 |
layout:aLayout |
|
1626 |
spec layout:aLayout |
|
1627 |
! |
|
1628 |
||
1629 |
name |
|
1630 |
^ spec name |
|
1631 |
! |
|
1632 |
||
1633 |
name:aName |
|
1634 |
spec name:aName |
|
1635 |
! ! |
|
1636 |
||
60 | 1637 |
!UIPainterView::GroupProperties methodsFor:'accessing'! |
1638 |
||
1639 |
controlledObjects |
|
1640 |
"return the value of the instance variable 'controlledObjects' (automatically generated)" |
|
1641 |
||
1642 |
^ controlledObjects! |
|
1643 |
||
1644 |
controlledObjects:something |
|
1645 |
"set the value of the instance variable 'controlledObjects' (automatically generated)" |
|
1646 |
||
1647 |
controlledObjects := something.! |
|
1648 |
||
1649 |
group |
|
78 | 1650 |
"return the value of the instance variable 'group' |
1651 |
" |
|
1652 |
^ group |
|
1653 |
! |
|
60 | 1654 |
|
1655 |
group:something |
|
78 | 1656 |
"set the value of the instance variable 'group' |
1657 |
" |
|
1658 |
group := something. |
|
1659 |
! |
|
71 | 1660 |
|
1661 |
name |
|
78 | 1662 |
"return the value of the group name |
1663 |
" |
|
1664 |
^ name |
|
71 | 1665 |
! |
1666 |
||
1667 |
name:aName |
|
78 | 1668 |
"set the value of the group name |
1669 |
" |
|
1670 |
name := aName |
|
71 | 1671 |
! ! |
60 | 1672 |
|
1673 |
!UIPainterView class methodsFor:'documentation'! |
|
1674 |
||
1675 |
version |
|
1676 |
^ '$Header$' |
|
1677 |
! ! |