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