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