|
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 code viewProperties superclassName className methodName |
|
15 categoryName' |
|
16 classVariableNames:'HandCursor' |
|
17 poolDictionaries:'' |
|
18 category:'Interface-UIPainter' |
|
19 ! |
|
20 |
|
21 Object subclass:#ViewProperty |
|
22 instanceVariableNames:'aspectSelector changeSelector name nameIndex view elementClass |
|
23 labelSelector identifier' |
|
24 classVariableNames:'Identifier' |
|
25 poolDictionaries:'' |
|
26 privateIn:UIPainterView |
|
27 ! |
|
28 |
1 UIPainterView::ViewProperty subclass:#GroupProperties |
29 UIPainterView::ViewProperty subclass:#GroupProperties |
2 instanceVariableNames:'controlledObjects group' |
30 instanceVariableNames:'controlledObjects group' |
3 classVariableNames:'' |
31 classVariableNames:'' |
4 poolDictionaries:'' |
32 poolDictionaries:'' |
5 privateIn:UIPainterView |
33 privateIn:UIPainterView |
6 ! |
34 ! |
|
35 |
|
36 !UIPainterView class methodsFor:'documentation'! |
|
37 |
|
38 copyright |
|
39 " |
|
40 COPYRIGHT (c) 1995 by Claus Gittinger |
|
41 All Rights Reserved |
|
42 |
|
43 This software is furnished under a license and may be used |
|
44 only in accordance with the terms of that license and with the |
|
45 inclusion of the above copyright notice. This software may not |
|
46 be provided or otherwise made available to, or used by, any |
|
47 other person. No title to or ownership of the software is |
|
48 hereby transferred. |
|
49 " |
|
50 ! |
|
51 |
|
52 documentation |
|
53 " |
|
54 not yet finished, not yet published, not yet released. |
|
55 " |
|
56 ! ! |
|
57 |
|
58 !UIPainterView methodsFor:'accessing'! |
|
59 |
|
60 className |
|
61 ^ className |
|
62 |
|
63 "Modified: 5.9.1995 / 18:41:30 / claus" |
|
64 ! |
|
65 |
|
66 className:aString |
|
67 className := aString |
|
68 |
|
69 "Modified: 5.9.1995 / 18:47:17 / claus" |
|
70 ! |
|
71 |
|
72 methodName |
|
73 ^ methodName |
|
74 |
|
75 "Modified: 5.9.1995 / 18:41:34 / claus" |
|
76 ! |
|
77 |
|
78 methodName:aString |
|
79 methodName := aString |
|
80 |
|
81 "Modified: 5.9.1995 / 18:47:27 / claus" |
|
82 ! ! |
|
83 |
|
84 !UIPainterView methodsFor:'builder interface'! |
|
85 |
|
86 application |
|
87 self halt. |
|
88 ^ nil |
|
89 |
|
90 "Modified: 6.9.1995 / 00:46:44 / claus" |
|
91 ! |
|
92 |
|
93 aspectAt:aSymbol |
|
94 self halt. |
|
95 ^ nil |
|
96 |
|
97 "Modified: 6.9.1995 / 00:45:35 / claus" |
|
98 ! |
|
99 |
|
100 createdComponent:newView forSpec:aSpec |
|
101 "callBack from UISpec view building" |
|
102 |
|
103 |props| |
|
104 |
|
105 props := self propertiesForNewView:newView. |
|
106 |
|
107 aSpec name notNil ifTrue:[ |
|
108 (self propertyOfName:(aSpec name)) isNil ifTrue:[ |
|
109 props name:aSpec name |
|
110 ] |
|
111 ]. |
|
112 |
|
113 props labelSelector:(aSpec labelSelector). |
|
114 props aspectSelector:(aSpec modelSelector). |
|
115 |
|
116 viewProperties add:props. |
|
117 ! ! |
|
118 |
|
119 !UIPainterView methodsFor:'code manipulation'! |
|
120 |
|
121 changeClass |
|
122 |box classNameHolder superclassNameHolder| |
|
123 |
|
124 classNameHolder := (className ? 'MyClass') asValue. |
|
125 superclassNameHolder := (superclassName ? 'ApplicationModel') asValue. |
|
126 |
|
127 box := DialogBox new. |
|
128 box addTextLabel:'class:'. |
|
129 box addInputFieldOn:classNameHolder. |
|
130 box addTextLabel:'super class:'. |
|
131 box addInputFieldOn:superclassNameHolder. |
|
132 box addAbortButton; addOkButton. |
|
133 |
|
134 box open. |
|
135 |
|
136 box accepted ifTrue:[ |
|
137 className := classNameHolder value. |
|
138 superclassName := superclassNameHolder value. |
|
139 ]. |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 ! |
|
147 |
|
148 changeVariables |
|
149 | box names propList p n newName| |
|
150 |
|
151 names := VariableArray new. |
|
152 propList := VariableArray new. |
|
153 viewProperties do:[:props | |
|
154 n := props name. |
|
155 n notNil ifTrue:[ |
|
156 names add:n. |
|
157 propList add:props |
|
158 ] |
|
159 ]. |
|
160 box := BuilderVariablesBox new. |
|
161 box list:names. |
|
162 box selectAction:[:selection | |
|
163 p := propList at:selection |
|
164 ]. |
|
165 box okAction:[ |
|
166 newName := box enterValue. |
|
167 Transcript showCR:('renamed ' , (p name) , 'to:' , newName). |
|
168 p name:newName |
|
169 ]. |
|
170 box showAtPointer |
|
171 |
|
172 |
|
173 |
|
174 ! ! |
|
175 |
|
176 !UIPainterView methodsFor:'creating subviews'! |
|
177 |
|
178 addProperties:properties for:aView |
|
179 "set properties to a view and add properties to viewProperties. |
|
180 In case that properties are nil properties are created |
|
181 " |
|
182 |name props| |
|
183 |
|
184 (props := properties) isNil ifTrue:[ |
|
185 props := self propertiesForNewView:aView. |
|
186 ]. |
|
187 |
|
188 viewProperties add:props. |
|
189 name := props name. |
|
190 |
|
191 (aView respondsTo:#label:) ifTrue:[ |
|
192 aView label:name |
|
193 ]. |
|
194 aView name:name. |
|
195 ^ props |
|
196 ! |
|
197 |
|
198 propertiesForNewView:aView |
|
199 |cls props index| |
|
200 |
|
201 cls := aView class. |
|
202 |
|
203 props := ViewProperty new. |
|
204 props view:aView. |
|
205 props elementClass:cls. |
|
206 index := self variableIndexForClass:cls. |
|
207 props nameIndex:index. |
|
208 props name:(self variableNameForClass:cls index:index). |
|
209 |
|
210 "/ props initCode:nil. --- add user-defined init code later |
|
211 |
|
212 ^ props |
|
213 ! |
|
214 |
|
215 setupCreatedObject:anObject |
|
216 "set default properties for a created object |
|
217 " |
|
218 |props| |
|
219 |
|
220 props := self addProperties:nil for:anObject. |
|
221 self undoCreate:(props identifier). |
|
222 ! ! |
|
223 |
|
224 !UIPainterView methodsFor:'cut & paste'! |
|
225 |
|
226 convertForPaste:something |
|
227 ^ nil |
|
228 |
|
229 |
|
230 ! |
|
231 |
|
232 copySelection |
|
233 "copy the selection into the cut&paste-buffer |
|
234 " |
|
235 |tmp| |
|
236 |
|
237 tmp := OrderedCollection new. |
|
238 |
|
239 self selectionDo:[:aView||topSpec| |
|
240 topSpec := aView specClass |
|
241 fromView:aView |
|
242 callBack:[:spec :aSubView | |
|
243 aSubView geometryLayout:(aSubView geometryLayout copy) |
|
244 ]. |
|
245 tmp add:topSpec. |
|
246 ]. |
|
247 |
|
248 self setSelection:tmp |
|
249 |
|
250 ! |
|
251 |
|
252 deleteSelection |
|
253 "delete the selection |
|
254 " |
|
255 undoHistory transactionNamed:'delete' do:[ |
|
256 super deleteSelection |
|
257 ]. |
|
258 |
|
259 |
|
260 ! |
|
261 |
|
262 pasteBuffer |
|
263 "add the objects in the paste-buffer |
|
264 " |
|
265 |sel firstEntry builder| |
|
266 |
|
267 sel := self getSelection. |
|
268 self unselect. |
|
269 |
|
270 sel size == 0 ifTrue:[firstEntry := sel] |
|
271 ifFalse:[firstEntry := sel at:1]. |
|
272 |
|
273 (firstEntry isKindOf:UISpecification) ifFalse:[ |
|
274 ^ self |
|
275 ]. |
|
276 builder := UIBuilder new. |
|
277 selection := OrderedCollection new. |
|
278 |
|
279 sel do:[:aSpec| |
|
280 builder componentCreationHook:[:view :spec :aBuilder | |
|
281 self createdComponent:view forSpec:spec |
|
282 ]. |
|
283 builder applicationClass:(Smalltalk classNamed:className). |
|
284 selection add:(aSpec buildViewWithLayoutFor:builder in:self). |
|
285 ]. |
|
286 |
|
287 undoHistory transactionNamed:'paste' do:[ |
|
288 selection do:[:aView| |props| |
|
289 props := self propertyOfView:aView. |
|
290 self undoCreate:(props identifier) |
|
291 ] |
|
292 ]. |
|
293 |
|
294 selection size == 1 ifTrue:[ |
|
295 selection := selection at:1 |
|
296 ]. |
|
297 self showSelection. |
|
298 self realizeAllSubViews. |
|
299 inputView raise. |
|
300 self changed:#tree |
|
301 |
|
302 ! ! |
|
303 |
|
304 !UIPainterView methodsFor:'generating output'! |
|
305 |
|
306 generateClassDefinition |
|
307 |defCode| |
|
308 |
|
309 defCode := superclassName , ' subclass:#' , className , '\'. |
|
310 defCode := defCode , ' instanceVariableNames:'''. |
|
311 defCode := defCode , self subviewVariableNames , '''\'. |
|
312 defCode := defCode , ' classVariableNames:''''\'. |
|
313 defCode := defCode , ' poolDictionaries:''''\'. |
|
314 defCode := defCode , ' category:''' , categoryName , '''\'. |
|
315 defCode := defCode , Character excla asString , '\\'. |
|
316 |
|
317 code := code , (defCode withCRs) |
|
318 |
|
319 |
|
320 |
|
321 ! |
|
322 |
|
323 generateCode |
|
324 code := ''. |
|
325 (Smalltalk classNamed:className) isNil ifTrue:[ |
|
326 self generateClassDefinition. |
|
327 ]. |
|
328 "/ self generateInitMethod. |
|
329 code := code , self generateWindowSpec. |
|
330 self generateOutlets. |
|
331 |
|
332 |
|
333 ^ code withCRs |
|
334 |
|
335 "Modified: 5.9.1995 / 20:57:53 / claus" |
|
336 ! ! |
|
337 |
|
338 !UIPainterView ignoredMethodsFor:'generating output'! |
|
339 |
|
340 generateInitCodeForGroup:aGroup |
|
341 |c name p objects outlets moreCode sym typ val| |
|
342 |
|
343 " <name> := <GroupClass> in:<name-of-superview>" |
|
344 |
|
345 p := self propertyOfGroup:aGroup. |
|
346 name := p at:#variableName. |
|
347 c := ' ' , name , ' := ' , (aGroup class name) , ' new.\'. |
|
348 |
|
349 code := code , c withCRs. |
|
350 |
|
351 " <name> <symbol>:<value>" |
|
352 |
|
353 objects := p at:#controlledObjects ifAbsent:[nil]. |
|
354 objects notNil ifTrue:[ |
|
355 objects do:[:controlledObject | |
|
356 c := c , name , ' add:' , (self variableNameOf:controlledObject) , '.\' |
|
357 ] |
|
358 ]. |
|
359 |
|
360 code := code , c withCRs |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 ! |
|
367 |
|
368 generateInitCodeForOtherStuff |
|
369 |g c name p outlets moreCode sym typ val| |
|
370 |
|
371 "generate code for groups" |
|
372 |
|
373 viewProperties do:[:props | |
|
374 g := props at:#group ifAbsent:[nil]. |
|
375 g notNil ifTrue:[ |
|
376 self generateInitCodeForGroup:g |
|
377 ] |
|
378 ] |
|
379 |
|
380 |
|
381 ! |
|
382 |
|
383 generateInitCodeForView:aView |
|
384 |c name p outlets moreCode sym typ val| |
|
385 |
|
386 " <name> := <ViewClass> in:<name-of-superview>" |
|
387 |
|
388 p := self propertyOfView:aView. |
|
389 name := p at:#variableName. |
|
390 c := ' ' , name , ' := ' , |
|
391 (aView class name) , ' in:' , (self variableNameOf:(aView superView)) , '.\'. |
|
392 |
|
393 " <name> origin:(...) extent:(...)" |
|
394 |
|
395 c := c , ' ' , name , ' origin:(', aView origin printString , ')' |
|
396 , ' extent:(', aView extent printString , ').\'. |
|
397 |
|
398 moreCode := p at:#initCode ifAbsent:nil. |
|
399 moreCode notNil ifTrue:[ |
|
400 c := c , moreCode , '\' withCRs |
|
401 ]. |
|
402 |
|
403 code := code , c withCRs. |
|
404 |
|
405 " <name> <symbol>:<value>" |
|
406 |
|
407 outlets := p at:#outlets ifAbsent:[nil]. |
|
408 outlets notNil ifTrue:[ |
|
409 outlets do:[:selectorOutlet | |
|
410 sym := selectorOutlet at:#selector. |
|
411 typ := selectorOutlet at:#type. |
|
412 val := selectorOutlet at:#value. |
|
413 c := ' ' , name , ' ' , sym. |
|
414 (typ == #number) ifTrue:[ |
|
415 c := c , val printString |
|
416 ]. |
|
417 (typ == #string) ifTrue:[ |
|
418 c := c , '''' , val , '''' |
|
419 ]. |
|
420 (typ == #text) ifTrue:[ |
|
421 c := c , '''' , val asString , '''' |
|
422 ]. |
|
423 (typ == #strings) ifTrue:[ |
|
424 c := c , '#( '. |
|
425 val asText do:[:aString | |
|
426 c := c , '''' , aString , ''' ' |
|
427 ]. |
|
428 c := c , ')' |
|
429 ]. |
|
430 (typ == #block) ifTrue:[ |
|
431 c := c , val |
|
432 ]. |
|
433 (typ == #color) ifTrue:[ |
|
434 c := c , '(Color name:''' , val , ''')' |
|
435 ]. |
|
436 c := c , '.' , Character cr asString. |
|
437 code := code , c |
|
438 ] |
|
439 ]. |
|
440 |
|
441 self subviewsOf:aView do:[:v | |
|
442 self generateInitCodeForView:v |
|
443 ] |
|
444 |
|
445 "Modified: 5.9.1995 / 20:06:07 / claus" |
|
446 ! |
|
447 |
|
448 generateInitMethod |
|
449 |defCode| |
|
450 |
|
451 defCode := Character excla asString , |
|
452 className , ' methodsFor:''initialization''' , |
|
453 Character excla asString , '\\'. |
|
454 |
|
455 defCode := defCode , 'initialize\'. |
|
456 defCode := defCode , ' super initialize.\'. |
|
457 defCode := defCode , ' self setupSubViews.\'. |
|
458 defCode := defCode , ' self setupLocalStuff\'. |
|
459 defCode := defCode , Character excla asString , '\\'. |
|
460 |
|
461 defCode := defCode , 'setupSubViews\'. |
|
462 code := code , defCode withCRs. |
|
463 |
|
464 self subviewsOf:self do:[:v | |
|
465 self generateInitCodeForView:v |
|
466 ]. |
|
467 |
|
468 self generateInitCodeForOtherStuff. |
|
469 |
|
470 code := code , ' ^ self\' withCRs. |
|
471 |
|
472 defCode := Character excla asString , '\\'. |
|
473 defCode := defCode , 'setupLocalStuff\'. |
|
474 defCode := defCode , ' ^ self\'. |
|
475 defCode := defCode , Character excla asString , ' ' , |
|
476 Character excla asString , '\\'. |
|
477 |
|
478 code := code , defCode withCRs |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 ! ! |
|
485 |
|
486 !UIPainterView methodsFor:'generating output'! |
|
487 |
|
488 generateOutlets |
|
489 ^ self |
|
490 ! |
|
491 |
|
492 generateWindowSpec |
|
493 |spec specArray str| |
|
494 |
|
495 subViews remove:inputView. |
|
496 [ |
|
497 spec := FullSpec fromView:self callBack:[:newSpec :view | self stuffPropertiesFrom:view intoSpec:newSpec]. |
|
498 ] valueNowOrOnUnwindDo:[ |
|
499 subViews addFirst:inputView. |
|
500 ]. |
|
501 |
|
502 specArray := spec literalArrayEncoding. |
|
503 str := WriteStream on:String new. |
|
504 self prettyPrintSpecArray:specArray on:str indent:5. |
|
505 |
|
506 code := Character excla asString |
|
507 , className , ' class methodsFor:''interface specs''' |
|
508 , Character excla asString , '\\' |
|
509 |
|
510 , methodName , '\' |
|
511 , ' "this window spec was automatically generated by the ST/X UIPainter"\\' |
|
512 , ' "do not manually edit this - the painter/builder may not be able to\' |
|
513 , ' handle the specification if its corrupted."\\' |
|
514 , ' "UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '"\' |
|
515 , ' "' , className , ' new openInterface:#' , methodName , '"\'. |
|
516 |
|
517 methodName = 'windowSpec' ifTrue:[ |
|
518 code := code , ' "' , className , ' open"\' |
|
519 ]. |
|
520 code := code |
|
521 , '\' |
|
522 , ' <resource: #canvas>\\' |
|
523 , ' ^\' |
|
524 , ' ', str contents |
|
525 , '\' |
|
526 , Character excla asString |
|
527 , ' ' |
|
528 , Character excla asString |
|
529 , '\\'. |
|
530 |
|
531 ^ code withCRs |
|
532 |
|
533 "Modified: 5.9.1995 / 21:01:35 / claus" |
|
534 ! |
|
535 |
|
536 nameOfClass |
|
537 ^ 'NewView' |
|
538 ! |
|
539 |
|
540 outletValueOf:aSymbol for:aView |
|
541 "/ |c name p outlets moreCode sym typ val| |
|
542 "/ |
|
543 "/ p := self propertyOfView:aView. |
|
544 "/ outlets := p at:#outlets ifAbsent:[^ nil]. |
|
545 "/ outlets notNil ifTrue:[ |
|
546 "/ outlets do:[:selectorOutlet | |
|
547 "/ sym := selectorOutlet at:#selector. |
|
548 "/ (sym == aSymbol) ifTrue:[ |
|
549 "/ typ := selectorOutlet at:#type. |
|
550 "/ val := selectorOutlet at:#value. |
|
551 "/ ^ val |
|
552 "/ ] |
|
553 "/ ] |
|
554 "/ ]. |
|
555 ^ nil |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 ! |
|
561 |
|
562 prettyPrintSpecArray:spec on:aStream indent:i |
|
563 "just for your convenience: prettyPrint a specArray to aStream - it looks better that way" |
|
564 |
|
565 |what oneLine| |
|
566 |
|
567 spec isArray ifFalse:[ |
|
568 spec isLiteral ifTrue:[ |
|
569 aStream nextPutAll:spec storeString |
|
570 ] ifFalse:[ |
|
571 self halt. |
|
572 ]. |
|
573 ^ self |
|
574 ]. |
|
575 |
|
576 spec isEmpty ifTrue:[ |
|
577 aStream nextPutAll:'#()'. |
|
578 ^ self |
|
579 ]. |
|
580 |
|
581 what := spec at:1. |
|
582 what isArray ifTrue:[ |
|
583 aStream cr; spaces:i+2. |
|
584 aStream nextPutAll:'#('. |
|
585 "/ a spec-collection |
|
586 spec do:[:element | |
|
587 self prettyPrintSpecArray:element on:aStream indent:i+2. |
|
588 ]. |
|
589 aStream cr. |
|
590 aStream spaces:i+1. |
|
591 aStream nextPutAll:')'. |
|
592 ^ self. |
|
593 ]. |
|
594 |
|
595 oneLine := false. |
|
596 (#(#LayoutFrame #LayoutOrigin #AlignmentOrigin |
|
597 #Rectangle #Point |
|
598 #Color #ColorValue |
|
599 ) |
|
600 includesIdentical:what) ifTrue:[ |
|
601 oneLine := true |
|
602 ]. |
|
603 |
|
604 oneLine ifFalse:[ |
|
605 aStream cr. |
|
606 aStream spaces:i+2. |
|
607 ]. |
|
608 aStream nextPutAll:'#('. |
|
609 |
|
610 |
|
611 aStream nextPutAll:what storeString. |
|
612 |
|
613 oneLine ifFalse:[ |
|
614 aStream cr. |
|
615 aStream spaces:i+4. |
|
616 ]. |
|
617 |
|
618 2 to:spec size do:[:index | |
|
619 aStream space. |
|
620 self prettyPrintSpecArray:(spec at:index) on:aStream indent:i+4. |
|
621 oneLine ifFalse:[ |
|
622 (index odd and:[index ~~ (spec size)]) ifTrue:[ |
|
623 aStream cr; spaces:i+4. |
|
624 ] |
|
625 ] |
|
626 ]. |
|
627 oneLine ifFalse:[ |
|
628 aStream cr. |
|
629 aStream spaces:i+1. |
|
630 ]. |
|
631 aStream nextPutAll:')'. |
|
632 |
|
633 "Modified: 5.9.1995 / 17:44:20 / claus" |
|
634 ! |
|
635 |
|
636 storeContentsOn:aStream |
|
637 viewProperties do:[:p| p storeOn:aStream] |
|
638 ! |
|
639 |
|
640 stuffPropertiesFrom:view intoSpec:newSpec |
|
641 "stuff any additional information (held in the properties) into the spec |
|
642 which was just created from view" |
|
643 |
|
644 |props aspectSelector changeSelector labelSelector name| |
|
645 |
|
646 props := self propertyOfView:view. |
|
647 props isNil ifTrue:[^ self]. |
|
648 |
|
649 (aspectSelector := props aspectSelector) notNil ifTrue:[ |
|
650 newSpec model:aspectSelector |
|
651 ]. |
|
652 (changeSelector := props changeSelector) notNil ifTrue:[ |
|
653 newSpec change:changeSelector |
|
654 ]. |
|
655 (labelSelector := props labelSelector) notNil ifTrue:[ |
|
656 newSpec label:labelSelector |
|
657 ]. |
|
658 (name := props name) notNil ifTrue:[ |
|
659 newSpec name:name |
|
660 ]. |
|
661 |
|
662 ! |
|
663 |
|
664 subviewVariableNames |
|
665 |names| |
|
666 |
|
667 names := ''. |
|
668 viewProperties do:[:p| names := names , ' ' , (p name)]. |
|
669 ^ names |
|
670 ! |
|
671 |
|
672 subviewsOf:aView do:aBlock |
|
673 |subs v| |
|
674 |
|
675 (subs := aView subViews) notNil ifTrue:[ |
|
676 subs do:[:v| |
|
677 (v ~~ inputView and:[v notNil]) ifTrue:[ |
|
678 (viewProperties detect:[:p | p view == v] ifNone:nil) notNil ifTrue:[ |
|
679 (v superView == aView) ifTrue:[ |
|
680 aBlock value:v |
|
681 ] |
|
682 ] |
|
683 ] |
|
684 ] |
|
685 ] |
|
686 |
|
687 ! ! |
|
688 |
|
689 !UIPainterView methodsFor:'group manipulations'! |
|
690 |
|
691 groupEnterFields |
|
692 |props name index group objects| |
|
693 |
|
694 selection isNil ifTrue:[^ self]. |
|
695 self selectionDo:[:aView | |
|
696 (aView isKindOf:EditField) ifFalse:[ |
|
697 self warn:'select EditFields only !!'. |
|
698 ^ self |
|
699 ] |
|
700 ]. |
|
701 self selectionHiddenDo:[ |
|
702 group := EnterFieldGroup new. |
|
703 |
|
704 props := GroupProperties new. |
|
705 props elementClass:EnterFieldGroup. |
|
706 props group:group. |
|
707 index := self variableIndexForClass:EnterFieldGroup. |
|
708 props nameIndex:index. |
|
709 name := self variableNameForClass:EnterFieldGroup index:index. |
|
710 props name:name. |
|
711 objects := OrderedCollection new. |
|
712 props controlledObjects:objects. |
|
713 viewProperties add:props. |
|
714 |
|
715 self selectionDo:[:aView | |
|
716 objects add:aView. |
|
717 group add:aView |
|
718 ]. |
|
719 ] |
|
720 |
|
721 |
|
722 ! |
|
723 |
|
724 groupRadioButtons |
|
725 |props name index group objects| |
|
726 |
|
727 selection isNil ifTrue:[^ self]. |
|
728 self selectionDo:[:aView | |
|
729 (aView isKindOf:RadioButton) ifFalse:[ |
|
730 self warn:'select RadioButtons only !!'. |
|
731 ^ self |
|
732 ] |
|
733 ]. |
|
734 self selectionHiddenDo:[ |
|
735 group := RadioButtonGroup new. |
|
736 |
|
737 props := GroupProperties new. |
|
738 props elementClass:RadioButtonGroup. |
|
739 props group:group. |
|
740 index := self variableIndexForClass:RadioButtonGroup. |
|
741 props nameIndex:index. |
|
742 name := self variableNameForClass:RadioButtonGroup index:index. |
|
743 props name:name. |
|
744 group groupID:name asSymbol. |
|
745 objects := OrderedCollection new. |
|
746 props controlledObjects:objects. |
|
747 viewProperties add:props. |
|
748 |
|
749 self selectionDo:[:aView | |
|
750 aView turnOff. |
|
751 objects add:aView. |
|
752 group add:aView |
|
753 ]. |
|
754 ] |
|
755 |
|
756 "Modified: 5.9.1995 / 16:06:15 / claus" |
|
757 ! ! |
|
758 |
|
759 !UIPainterView methodsFor:'initialization'! |
|
760 |
|
761 initialize |
|
762 super initialize. |
|
763 |
|
764 superclassName := 'ApplicationModel'. |
|
765 className := 'NewApplication'. |
|
766 methodName := 'windowSpec'. |
|
767 categoryName := 'Applications'. |
|
768 |
|
769 viewProperties := OrderedCollection new. |
|
770 HandCursor := Cursor leftHand. |
|
771 |
|
772 "Modified: 5.9.1995 / 19:58:06 / claus" |
|
773 ! |
|
774 |
|
775 initializeMiddleButtonMenu |
|
776 |labels| |
|
777 |
|
778 labels := resources array:#( |
|
779 'copy' |
|
780 'cut' |
|
781 'paste' |
|
782 '-' |
|
783 'save' |
|
784 'print' |
|
785 '-' |
|
786 'inspect' |
|
787 ). |
|
788 |
|
789 self middleButtonMenu:(PopUpMenu |
|
790 labels:labels |
|
791 selectors:#( |
|
792 copySelection |
|
793 deleteSelection |
|
794 pasteBuffer |
|
795 nil |
|
796 save |
|
797 print |
|
798 nil |
|
799 inspectSelection |
|
800 ) |
|
801 receiver:self |
|
802 for:self) |
|
803 |
|
804 ! ! |
|
805 |
|
806 !UIPainterView methodsFor:'interface to Builder'! |
|
807 |
|
808 addOutletDefinitionFor:outletSymbol type:type value:outletValue for:aView |
|
809 |outletProps selectorProps viewProps| |
|
810 |
|
811 viewProps := self propertyOfView:aView. |
|
812 "/ outletProps := viewProps at:#outlets ifAbsent:[nil]. |
|
813 "/ outletProps isNil ifTrue:[ |
|
814 "/ outletProps := Dictionary new. |
|
815 "/ viewProps at:#outlets put:outletProps |
|
816 "/ ]. |
|
817 "/ selectorProps := outletProps at:outletSymbol ifAbsent:[nil]. |
|
818 "/ selectorProps isNil ifTrue:[ |
|
819 "/ selectorProps := Dictionary new. |
|
820 "/ outletProps at:outletSymbol put:selectorProps |
|
821 "/ ]. |
|
822 "/ |
|
823 "/ selectorProps at:#selector put:outletSymbol. |
|
824 "/ selectorProps at:#type put:type. |
|
825 "/ selectorProps at:#value put:outletValue |
|
826 |
|
827 ! |
|
828 |
|
829 addSpec:specOrSpecArray |
|
830 |spec builder| |
|
831 |
|
832 spec := UISpecification from:specOrSpecArray. |
|
833 |
|
834 builder := UIBuilder new. |
|
835 builder componentCreationHook:[:view :spec :aBuilder | |
|
836 self createdComponent:view forSpec:spec |
|
837 ]. |
|
838 builder applicationClass:(Smalltalk classNamed:className). |
|
839 spec setupView:self for:builder. |
|
840 self realizeAllSubViews. |
|
841 inputView raise. |
|
842 |
|
843 "/ viewProperties := OrderedCollection new. |
|
844 "/ self generatePropertiesFor:(self subViews select:[:v | v ~~ inputView]). |
|
845 |
|
846 self changed:#tree. |
|
847 |
|
848 |
|
849 "Modified: 5.9.1995 / 23:36:55 / claus" |
|
850 ! |
|
851 |
|
852 applicationName |
|
853 ^ className |
|
854 ! |
|
855 |
|
856 aspectSelectorForView:aView |
|
857 |props aspect| |
|
858 |
|
859 props := self propertyOfView:aView. |
|
860 props isNil ifTrue:[^ nil]. |
|
861 ^ props aspectSelector |
|
862 |
|
863 ! |
|
864 |
|
865 changeSelectorForView:aView |
|
866 |props aspect| |
|
867 |
|
868 props := self propertyOfView:aView. |
|
869 props isNil ifTrue:[^ nil]. |
|
870 "/ ^ props changeSelector |
|
871 ^ nil |
|
872 ! |
|
873 |
|
874 generatePropertiesFor:aCollectionOfViews |
|
875 |
|
876 "/ done as two loops, to get bread-first naming |
|
877 |
|
878 aCollectionOfViews do:[:aView| |
|
879 |props| |
|
880 |
|
881 props := self propertiesForNewView:aView. |
|
882 viewProperties add:props. |
|
883 aView name:(props name). |
|
884 |
|
885 aView geometryLayout isNil ifTrue:[ |
|
886 aView geometryLayout:(aView bounds asLayout). |
|
887 ] |
|
888 ]. |
|
889 |
|
890 aCollectionOfViews do:[:aView | |
|
891 |subs| |
|
892 |
|
893 subs := aView subViews. |
|
894 subs notNil ifTrue:[ |
|
895 self generatePropertiesFor:subs |
|
896 ] |
|
897 ]. |
|
898 |
|
899 ! |
|
900 |
|
901 inspectAttributes |
|
902 |p| |
|
903 |
|
904 self singleSelectionDo:[:aView | |
|
905 p := self propertyOfView:aView. |
|
906 p inspect |
|
907 ] |
|
908 ! |
|
909 |
|
910 setAspectSelector:aspectSymbol forView:aView |
|
911 |props| |
|
912 |
|
913 props := self propertyOfView:aView. |
|
914 |
|
915 undoHistory transactionNamed:'aspect' do:[ |
|
916 self selectionDo:[:aView| |
|
917 undoHistory isTransactionOpen ifTrue:[ |
|
918 |oldAspect| |
|
919 |
|
920 oldAspect := props aspectSelector. |
|
921 undoHistory addUndoBlock:[ |
|
922 props aspectSelector:oldAspect. |
|
923 self elementChanged:aView. |
|
924 ] |
|
925 ]. |
|
926 ]. |
|
927 ]. |
|
928 |
|
929 props aspectSelector:aspectSymbol |
|
930 |
|
931 ! |
|
932 |
|
933 setChangeSelector:changeSymbol forView:aView |
|
934 |props| |
|
935 |
|
936 props := self propertyOfView:aView. |
|
937 props changeSelector:changeSymbol |
|
938 |
|
939 ! |
|
940 |
|
941 setupFromSpec:specOrSpecArray |
|
942 self removeAll. |
|
943 self addSpec:specOrSpecArray |
|
944 ! |
|
945 |
|
946 showFontPanel |
|
947 |action| |
|
948 |
|
949 fontPanel isNil ifTrue:[ |
|
950 fontPanel := FontPanel new |
|
951 ]. |
|
952 |
|
953 selection notNil ifTrue:[ |
|
954 action := [:family :face :style :size | |
|
955 self changeFontFamily:family face:face |
|
956 style:style size:size |
|
957 ]. |
|
958 fontPanel action:action. |
|
959 fontPanel showAtPointer |
|
960 ] |
|
961 ! ! |
|
962 |
|
963 !UIPainterView methodsFor:'misc'! |
|
964 |
|
965 changeFontFamily:family face:face style:style size:size |
|
966 |f| |
|
967 |
|
968 f := Font family:family |
|
969 face:face |
|
970 style:style |
|
971 size:size. |
|
972 |
|
973 f notNil ifTrue:[ |
|
974 self selectionHiddenDo:[ |
|
975 self selectionDo:[:aView | |
|
976 aView font:f. |
|
977 self elementChanged:aView. |
|
978 ] |
|
979 ] |
|
980 ] |
|
981 |
|
982 "Modified: 5.9.1995 / 12:13:27 / claus" |
|
983 ! |
|
984 |
|
985 changeVariableNameOf:aView to:newName |
|
986 |prop| |
|
987 |
|
988 prop := self propertyOf:aView. |
|
989 |
|
990 prop isNil ifTrue:[ |
|
991 ^ self error:'no such view' |
|
992 ]. |
|
993 |
|
994 ((aView respondsTo:#label:) and:[aView label = prop name]) ifTrue:[ |
|
995 self selectionHiddenDo:[ |
|
996 |layout| |
|
997 layout := aView geometryLayout copy. |
|
998 aView label:newName. |
|
999 aView geometryLayout:layout. |
|
1000 ] |
|
1001 ]. |
|
1002 |
|
1003 prop name:newName. |
|
1004 aView name:newName. |
|
1005 self changed:#widgetName |
|
1006 |
|
1007 |
|
1008 |
|
1009 ! |
|
1010 |
|
1011 variableIndexForClass:aClass |
|
1012 |max| |
|
1013 |
|
1014 max := 0. |
|
1015 |
|
1016 viewProperties do:[:p| |
|
1017 p elementClass == aClass ifTrue:[ |
|
1018 max := max max:(p nameIndex) |
|
1019 ] |
|
1020 ]. |
|
1021 ^ max + 1 |
|
1022 |
|
1023 ! |
|
1024 |
|
1025 variableNameForClass:aClass index:index |
|
1026 |n| |
|
1027 |
|
1028 n := (aClass name) , index printString. |
|
1029 n at:1 put:(n at:1) asLowercase. |
|
1030 ^ n |
|
1031 |
|
1032 ! |
|
1033 |
|
1034 variableNameOf:aView |
|
1035 |prop| |
|
1036 |
|
1037 aView notNil ifTrue:[ |
|
1038 prop := self propertyOf:aView |
|
1039 ]. |
|
1040 |
|
1041 prop notNil ifTrue:[^ prop name] |
|
1042 ifFalse:[^ 'self'] |
|
1043 |
|
1044 ! ! |
|
1045 |
|
1046 !UIPainterView methodsFor:'private undo-actions'! |
|
1047 |
|
1048 undoCreate:aViewIdentifier |
|
1049 |
|
1050 undoHistory isTransactionOpen ifTrue:[ |
|
1051 undoHistory addUndoBlock:[ |
|
1052 |props| |
|
1053 |
|
1054 props := self propertyOfIdentifier:aViewIdentifier. |
|
1055 |
|
1056 props notNil ifTrue:[ |
|
1057 self removeObject:(props view) |
|
1058 ] |
|
1059 ] |
|
1060 ] |
|
1061 ! |
|
1062 |
|
1063 undoRemove:propertyOfView |
|
1064 |clsName layout parent aView| |
|
1065 |
|
1066 undoHistory isTransactionOpen ifFalse:[ |
|
1067 ^ self |
|
1068 ]. |
|
1069 |
|
1070 aView := propertyOfView view. |
|
1071 clsName := aView class. |
|
1072 layout := aView geometryLayout. |
|
1073 parent := aView superView. |
|
1074 |
|
1075 parent ~~ self ifTrue:[ |
|
1076 parent := (self propertyOf:parent) identifier. |
|
1077 ] ifFalse:[ |
|
1078 parent := nil |
|
1079 ]. |
|
1080 propertyOfView view:nil. |
|
1081 |
|
1082 undoHistory addUndoBlock:[ |
|
1083 |recreatedView props| |
|
1084 |
|
1085 parent notNil ifTrue:[ |
|
1086 props := self propertyOfIdentifier:parent. |
|
1087 |
|
1088 props notNil ifTrue:[parent := props view] |
|
1089 ifFalse:[parent := self] |
|
1090 ] ifFalse:[ |
|
1091 parent := self |
|
1092 ]. |
|
1093 |
|
1094 recreatedView := clsName in:parent. |
|
1095 recreatedView geometryLayout:layout. |
|
1096 propertyOfView view:recreatedView. |
|
1097 self addProperties:propertyOfView for:recreatedView. |
|
1098 recreatedView realize. |
|
1099 inputView raise. |
|
1100 self changed:#tree. |
|
1101 ]. |
|
1102 aView := nil. |
|
1103 |
|
1104 ! ! |
|
1105 |
|
1106 !UIPainterView methodsFor:'removing components'! |
|
1107 |
|
1108 remove:something |
|
1109 "remove something, anObject or a collection of objects from the contents |
|
1110 do redraw" |
|
1111 |
|
1112 self forEach:something do:[:anObject | |
|
1113 self removeObject:anObject |
|
1114 ] |
|
1115 |
|
1116 |
|
1117 ! |
|
1118 |
|
1119 removeAll |
|
1120 "remove the argument, anObject" |
|
1121 |
|
1122 self unselect. |
|
1123 |
|
1124 subViews notNil ifTrue:[ |
|
1125 subViews copy do:[:sub | |
|
1126 sub ~~ inputView ifTrue:[ |
|
1127 self removeTreeFrom:sub |
|
1128 ] |
|
1129 ] |
|
1130 ]. |
|
1131 |
|
1132 viewProperties := OrderedCollection new. |
|
1133 undoHistory reinitialize. |
|
1134 self changed:#tree |
|
1135 ! |
|
1136 |
|
1137 removeObject:anObject |
|
1138 "remove the argument, anObject" |
|
1139 |
|
1140 self removeTreeFrom:anObject. |
|
1141 self changed:#tree |
|
1142 |
|
1143 "Modified: 5.9.1995 / 20:51:28 / claus" |
|
1144 ! |
|
1145 |
|
1146 removeTreeFrom:anObject |
|
1147 "remove the argument, anObject and all of its children |
|
1148 " |
|
1149 |props| |
|
1150 |
|
1151 anObject notNil ifTrue:[ |
|
1152 (anObject subViews notNil) ifTrue:[ |
|
1153 anObject subViews copy do:[:sub | |
|
1154 self removeTreeFrom:sub |
|
1155 ] |
|
1156 ]. |
|
1157 props := self propertyOf:anObject. |
|
1158 self undoRemove:props. |
|
1159 viewProperties remove:props. |
|
1160 anObject destroy |
|
1161 ] |
|
1162 ! ! |
|
1163 |
|
1164 !UIPainterView methodsFor:'selections'! |
|
1165 |
|
1166 addNameToSelection:aString |
|
1167 |prop| |
|
1168 |
|
1169 prop := self propertyOfName:aString. |
|
1170 |
|
1171 prop notNil ifTrue:[ |
|
1172 self addToSelection:(prop view) |
|
1173 ] |
|
1174 |
|
1175 ! |
|
1176 |
|
1177 removeNameFromSelection:aString |
|
1178 |prop| |
|
1179 |
|
1180 prop := self propertyOfName:aString. |
|
1181 |
|
1182 prop notNil ifTrue:[ |
|
1183 self removeFromSelection:(prop view) |
|
1184 ] |
|
1185 |
|
1186 ! |
|
1187 |
|
1188 selectName:aStringOrCollection |
|
1189 |prop coll s| |
|
1190 |
|
1191 (aStringOrCollection isNil or:[aStringOrCollection isEmpty]) ifTrue:[ |
|
1192 ^ self unselect |
|
1193 ]. |
|
1194 |
|
1195 (s := aStringOrCollection) isString ifFalse:[ |
|
1196 s size == 1 ifTrue:[ |
|
1197 s := s first |
|
1198 ] ifFalse:[ |
|
1199 coll := OrderedCollection new. |
|
1200 |
|
1201 s do:[:aName| |
|
1202 (prop := self propertyOfName:aName) notNil ifTrue:[ |
|
1203 coll add:(prop view) |
|
1204 ] |
|
1205 ]. |
|
1206 coll size == 1 ifTrue:[ ^ self select:(coll at:1) ]. |
|
1207 coll size == 0 ifTrue:[ ^ self unselect ]. |
|
1208 |
|
1209 self hideSelection. |
|
1210 selection := coll. |
|
1211 self showSelection. |
|
1212 ^ self changed:#selection |
|
1213 ] |
|
1214 ]. |
|
1215 |
|
1216 prop := self propertyOfName:s. |
|
1217 prop isNil ifTrue:[^ self unselect] |
|
1218 ifFalse:[^ self select:(prop view)] |
|
1219 |
|
1220 ! ! |
|
1221 |
|
1222 !UIPainterView methodsFor:'seraching property'! |
|
1223 |
|
1224 propertyOf:something |
|
1225 |
|
1226 ^ viewProperties detect:[:p| (p view == something or:[p group == something])] |
|
1227 ifNone:nil |
|
1228 |
|
1229 |
|
1230 |
|
1231 |
|
1232 |
|
1233 ! |
|
1234 |
|
1235 propertyOfGroup:aGroup |
|
1236 |
|
1237 ^ viewProperties detect:[:p| p group == aGroup] ifNone:nil |
|
1238 ! |
|
1239 |
|
1240 propertyOfIdentifier:anIdentifier |
|
1241 |
|
1242 ^ viewProperties detect:[:p| p identifier == anIdentifier] ifNone:nil. |
|
1243 ! |
|
1244 |
|
1245 propertyOfName:aString |
|
1246 |
|
1247 aString = 'self' ifFalse:[ |
|
1248 ^ viewProperties detect:[:p| p name = aString] ifNone:nil |
|
1249 ]. |
|
1250 ^ nil |
|
1251 ! |
|
1252 |
|
1253 propertyOfView:aView |
|
1254 |
|
1255 aView == self ifFalse:[ |
|
1256 ^ viewProperties detect:[:p| p view == aView] ifNone:nil |
|
1257 ]. |
|
1258 ^ nil |
|
1259 ! ! |
|
1260 |
|
1261 !UIPainterView methodsFor:'testing'! |
|
1262 |
|
1263 isHorizontalResizable:aComponent |
|
1264 |
|
1265 (aComponent isKindOf:ScrollBar) ifTrue:[ |
|
1266 ^ aComponent orientation == #horizontal |
|
1267 ]. |
|
1268 (aComponent isKindOf:Scroller) ifTrue:[ |
|
1269 ^ aComponent orientation == #horizontal |
|
1270 ]. |
|
1271 (aComponent isKindOf:Slider) ifTrue:[ |
|
1272 ^ aComponent orientation == #horizontal |
|
1273 ]. |
|
1274 ^ true |
|
1275 |
|
1276 |
|
1277 ! |
|
1278 |
|
1279 isVerticalResizable:aComponent |
|
1280 |
|
1281 (aComponent isKindOf:EditField) ifTrue:[ |
|
1282 ^ false |
|
1283 ]. |
|
1284 (aComponent isKindOf:ScrollBar) ifTrue:[ |
|
1285 ^ aComponent orientation == #vertical |
|
1286 ]. |
|
1287 (aComponent isKindOf:Scroller) ifTrue:[ |
|
1288 ^ aComponent orientation == #vertical |
|
1289 ]. |
|
1290 (aComponent isKindOf:Slider) ifTrue:[ |
|
1291 ^ aComponent orientation == #vertical |
|
1292 ]. |
|
1293 ^ true |
|
1294 |
|
1295 |
|
1296 ! ! |
|
1297 |
|
1298 !UIPainterView::ViewProperty class methodsFor:'instance creation'! |
|
1299 |
|
1300 new |
|
1301 Identifier notNil ifTrue:[Identifier := Identifier + 1] |
|
1302 ifFalse:[Identifier := 1]. |
|
1303 |
|
1304 ^ self basicNew initialize |
|
1305 ! ! |
|
1306 |
|
1307 !UIPainterView::ViewProperty methodsFor:'accessing'! |
|
1308 |
|
1309 aspectSelector |
|
1310 "return the value of the instance variable 'aspectSelector' (automatically generated)" |
|
1311 |
|
1312 ^ aspectSelector |
|
1313 ! |
|
1314 |
|
1315 aspectSelector:something |
|
1316 "set the value of the instance variable 'aspectSelector' (automatically generated)" |
|
1317 |
|
1318 aspectSelector := something. |
|
1319 ! |
|
1320 |
|
1321 changeSelector |
|
1322 "return the value of the instance variable 'changeSelector' (automatically generated)" |
|
1323 |
|
1324 ^ changeSelector! |
|
1325 |
|
1326 changeSelector:something |
|
1327 "set the value of the instance variable 'changeSelector' (automatically generated)" |
|
1328 |
|
1329 changeSelector := something.! |
|
1330 |
|
1331 elementClass |
|
1332 "return the value of the instance variable 'elementClass' (automatically generated)" |
|
1333 |
|
1334 ^ elementClass! |
|
1335 |
|
1336 elementClass:something |
|
1337 "set the value of the instance variable 'elementClass' (automatically generated)" |
|
1338 |
|
1339 elementClass := something.! |
|
1340 |
|
1341 group |
|
1342 ^ nil |
|
1343 ! |
|
1344 |
|
1345 identifier |
|
1346 "return the unique identifier assigned to property |
|
1347 " |
|
1348 ^ identifier |
|
1349 ! |
|
1350 |
|
1351 labelSelector |
|
1352 "return the value of the instance variable 'labelSelector' (automatically generated)" |
|
1353 |
|
1354 ^ labelSelector! |
|
1355 |
|
1356 labelSelector:something |
|
1357 "set the value of the instance variable 'labelSelector' (automatically generated)" |
|
1358 |
|
1359 labelSelector := something.! |
|
1360 |
|
1361 name |
|
1362 "return the value of the instance variable 'name' (automatically generated)" |
|
1363 |
|
1364 ^ name! |
|
1365 |
|
1366 name:something |
|
1367 "set the value of the instance variable 'name' (automatically generated)" |
|
1368 |
|
1369 name := something.! |
|
1370 |
|
1371 nameIndex |
|
1372 "return the value of the instance variable 'nameIndex' (automatically generated)" |
|
1373 |
|
1374 ^ nameIndex! |
|
1375 |
|
1376 nameIndex:something |
|
1377 "set the value of the instance variable 'nameIndex' (automatically generated)" |
|
1378 |
|
1379 nameIndex := something.! |
|
1380 |
|
1381 view |
|
1382 "return the value of the instance variable 'view' (automatically generated)" |
|
1383 |
|
1384 ^ view! |
|
1385 |
|
1386 view:something |
|
1387 "set the value of the instance variable 'view' (automatically generated)" |
|
1388 |
|
1389 view := something.! ! |
|
1390 |
|
1391 !UIPainterView::ViewProperty methodsFor:'initialization'! |
|
1392 |
|
1393 initialize |
|
1394 super initialize. |
|
1395 identifier := Identifier |
|
1396 ! ! |
|
1397 |
|
1398 !UIPainterView::GroupProperties class methodsFor:'documentation'! |
|
1399 |
|
1400 version |
|
1401 ^ '$Header$' |
|
1402 ! ! |
7 |
1403 |
8 !UIPainterView::GroupProperties methodsFor:'accessing'! |
1404 !UIPainterView::GroupProperties methodsFor:'accessing'! |
9 |
1405 |
10 controlledObjects |
1406 controlledObjects |
11 "return the value of the instance variable 'controlledObjects' (automatically generated)" |
1407 "return the value of the instance variable 'controlledObjects' (automatically generated)" |