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