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