17 poolDictionaries:'' |
17 poolDictionaries:'' |
18 category:'Interface-UIPainter' |
18 category:'Interface-UIPainter' |
19 ! |
19 ! |
20 |
20 |
21 Object subclass:#ViewProperty |
21 Object subclass:#ViewProperty |
22 instanceVariableNames:'aspectSelector changeSelector name nameIndex view elementClass |
22 instanceVariableNames:'aspectSelector changeSelector nameIndex view elementClass |
23 labelSelector identifier' |
23 labelSelector identifier tabable' |
24 classVariableNames:'Identifier' |
24 classVariableNames:'Identifier' |
25 poolDictionaries:'' |
25 poolDictionaries:'' |
26 privateIn:UIPainterView |
26 privateIn:UIPainterView |
27 ! |
27 ! |
28 |
28 |
243 props := self addProperties:nil for:anObject. |
240 props := self addProperties:nil for:anObject. |
244 |
241 |
245 undoHistory transaction:#create text:(props name) do:[ |
242 undoHistory transaction:#create text:(props name) do:[ |
246 self undoCreate:(props identifier). |
243 self undoCreate:(props identifier). |
247 ]. |
244 ]. |
|
245 ! ! |
|
246 |
|
247 !UIPainterView methodsFor:'drag & drop'! |
|
248 |
|
249 canDrop:anObjectOrCollection |
|
250 Transcript showCR:'canDrop'. |
|
251 ^ true |
|
252 |
|
253 |
|
254 ! |
|
255 |
|
256 drop:anObjectOrCollection at:aPoint |
|
257 Transcript showCR:'drop:anObjectOrCollection at:aPoint'. |
|
258 |
|
259 |
|
260 ! ! |
|
261 |
|
262 !UIPainterView methodsFor:'event handling'! |
|
263 |
|
264 keyPress:key x:x y:y |
|
265 <resource: #keyboard ( #Copy #Paste) > |
|
266 |
|
267 key == #Copy ifTrue:[ |
|
268 ^ self copySelection |
|
269 ]. |
|
270 |
|
271 key == #Paste ifTrue:[ |
|
272 ^ self pasteBuffer |
|
273 ]. |
|
274 |
|
275 super keyPress:key x:x y:y |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
248 ! ! |
281 ! ! |
249 |
282 |
250 !UIPainterView ignoredMethodsFor:'generating output'! |
283 !UIPainterView ignoredMethodsFor:'generating output'! |
251 |
284 |
252 generateClassDefinition |
285 generateClassDefinition |
449 ^ self |
482 ^ self |
450 ! ! |
483 ! ! |
451 |
484 |
452 !UIPainterView methodsFor:'generating output'! |
485 !UIPainterView methodsFor:'generating output'! |
453 |
486 |
454 generateSpecFor:something |
487 generateSpecFor:something |
455 "generate a spec for a view or collection of views |
488 "generate a spec for a view or collection of views |
456 " |
489 " |
457 |spec views| |
490 |spec views| |
458 |
491 |
459 something notNil ifTrue:[ |
492 something notNil ifTrue:[ |
460 something isCollection ifTrue:[views := something] |
493 something isCollection ifTrue:[views := something] |
461 ifFalse:[views := Array with:something]. |
494 ifFalse:[views := Array with:something]. |
462 |
495 |
463 spec := views collect:[:aView||topSpec| |
496 spec := views collect:[:aView||topSpec| |
|
497 aView specClass isNil ifTrue:[^ nil]. |
|
498 |
464 topSpec := aView specClass |
499 topSpec := aView specClass |
465 fromView:aView |
500 fromView:aView |
466 callBack:[:spec :aSubView | |
501 callBack:[:newSpec :view | self stuffPropertiesFrom:view intoSpec:newSpec]. |
467 "/ aSubView geometryLayout:(aSubView geometryLayout copy) |
|
468 ]. |
|
469 topSpec |
502 topSpec |
470 ] |
503 ] |
471 ]. |
504 ]. |
472 ^ spec |
505 ^ spec |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
473 ! |
512 ! |
474 |
513 |
475 generateWindowSpecMethodSource |
514 generateWindowSpecMethodSource |
476 |spec specArray str code| |
515 |spec specArray str code| |
477 |
516 |
492 |
531 |
493 , methodName , '\' |
532 , methodName , '\' |
494 , ' "this window spec was automatically generated by the ST/X UIPainter"\\' |
533 , ' "this window spec was automatically generated by the ST/X UIPainter"\\' |
495 , ' "do not manually edit this - the painter/builder may not be able to\' |
534 , ' "do not manually edit this - the painter/builder may not be able to\' |
496 , ' handle the specification if its corrupted."\\' |
535 , ' handle the specification if its corrupted."\\' |
497 , ' "UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '"\' |
536 , ' "\' |
498 , ' "' , className , ' new openInterface:#' , methodName , '"\'. |
537 , ' UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\' |
|
538 , ' ' , className , ' new openInterface:#' , methodName , '\' |
|
539 , ' "\'. |
499 |
540 |
500 methodName = 'windowSpec' ifTrue:[ |
541 methodName = 'windowSpec' ifTrue:[ |
501 code := code , ' "' , className , ' open"\' |
542 code := code , ' "' , className , ' open"\' |
502 ]. |
543 ]. |
503 code := code |
544 code := code |
626 |
667 |
627 stuffPropertiesFrom:view intoSpec:newSpec |
668 stuffPropertiesFrom:view intoSpec:newSpec |
628 "stuff any additional information (held in the properties) into the spec |
669 "stuff any additional information (held in the properties) into the spec |
629 which was just created from view" |
670 which was just created from view" |
630 |
671 |
631 |props aspectSelector changeSelector labelSelector name| |
672 |props aspectSelector changeSelector labelSelector name tabable| |
632 |
673 |
633 props := self propertyOfView:view. |
674 props := self propertyOfView:view. |
634 props isNil ifTrue:[^ self]. |
675 props isNil ifTrue:[^ self]. |
635 |
676 |
636 (aspectSelector := props aspectSelector) notNil ifTrue:[ |
677 (aspectSelector := props aspectSelector) notNil ifTrue:[ |
639 (changeSelector := props changeSelector) notNil ifTrue:[ |
680 (changeSelector := props changeSelector) notNil ifTrue:[ |
640 newSpec change:changeSelector |
681 newSpec change:changeSelector |
641 ]. |
682 ]. |
642 (labelSelector := props labelSelector) notNil ifTrue:[ |
683 (labelSelector := props labelSelector) notNil ifTrue:[ |
643 newSpec label:labelSelector |
684 newSpec label:labelSelector |
|
685 ]. |
|
686 (tabable := props tabable) notNil ifTrue:[ |
|
687 newSpec tabable:tabable |
644 ]. |
688 ]. |
645 (name := props name) notNil ifTrue:[ |
689 (name := props name) notNil ifTrue:[ |
646 newSpec name:name |
690 newSpec name:name |
647 ]. |
691 ]. |
648 |
692 |
790 |
834 |
791 spec := UISpecification from:specOrSpecArray. |
835 spec := UISpecification from:specOrSpecArray. |
792 |
836 |
793 builder := UIBuilder new. |
837 builder := UIBuilder new. |
794 builder componentCreationHook:[:view :spec :aBuilder | |
838 builder componentCreationHook:[:view :spec :aBuilder | |
795 self createdComponent:view forSpec:spec |
839 self createdComponent:view forSpec:spec builder:aBuilder |
796 ]. |
840 ]. |
797 builder applicationClass:(Smalltalk classNamed:className). |
841 builder applicationClass:(Smalltalk classNamed:className). |
798 spec setupView:self for:builder. |
842 spec setupView:self for:builder. |
|
843 |
799 self realizeAllSubViews. |
844 self realizeAllSubViews. |
800 inputView raise. |
845 inputView raise. |
801 |
846 |
802 "/ viewProperties := OrderedCollection new. |
847 "/ viewProperties := OrderedCollection new. |
803 "/ self generatePropertiesFor:(self subViews select:[:v | v ~~ inputView]). |
848 "/ self generatePropertiesFor:(self subViews select:[:v | v ~~ inputView]). |
835 props isNil ifTrue:[^ nil]. |
880 props isNil ifTrue:[^ nil]. |
836 "/ ^ props changeSelector |
881 "/ ^ props changeSelector |
837 ^ nil |
882 ^ nil |
838 ! |
883 ! |
839 |
884 |
840 createdComponent:newView forSpec:aSpec |
885 createdComponent:newView forSpec:aSpec builder:aBuilder |
841 "callBack from UISpec view building" |
886 "callBack from UISpec view building" |
842 |
887 |
843 |props| |
888 |props| |
844 |
889 |
845 props := self propertiesForNewView:newView. |
890 props := self propertiesForNewView:newView. |
1002 ! |
1072 ! |
1003 |
1073 |
1004 menuSelection |
1074 menuSelection |
1005 "menu in case of non empty selection; for views |
1075 "menu in case of non empty selection; for views |
1006 " |
1076 " |
1007 |menu arrangeMenu subMenuAlign| |
1077 |menu| |
1008 |
1078 |
1009 menu := PopUpMenu labels:( resources array:#( |
1079 menu := PopUpMenu labels:( resources array:#( |
1010 'copy' |
1080 'copy' |
1011 'cut' |
1081 'cut' |
1012 'paste' |
1082 'paste' |
1013 '-' |
1083 '-' |
1014 'arrange' |
1084 'arrange' |
1015 'dimension' |
1085 'dimension' |
|
1086 'align' |
1016 ) |
1087 ) |
1017 ) |
1088 ) |
1018 selectors:#( #copySelection |
1089 selectors:#( #copySelection |
1019 #deleteSelection |
1090 #deleteSelection |
1020 #pasteBuffer |
1091 #pasteBuffer |
1021 nil |
1092 nil |
1022 #arrange |
1093 #arrange |
1023 #dimension |
1094 #dimension |
|
1095 #align |
|
1096 ) |
|
1097 accelerators:#(#Copy |
|
1098 #Cut |
|
1099 #Paste |
|
1100 nil |
|
1101 nil |
|
1102 nil |
|
1103 nil |
1024 ) |
1104 ) |
1025 receiver:self. |
1105 receiver:self. |
1026 |
1106 |
1027 (self supportsSubComponents:selection) ifFalse:[ |
1107 ( (self canPaste:(self getSelection)) |
|
1108 and:[self supportsSubComponents:selection] |
|
1109 ) ifFalse:[ |
1028 menu disable:#pasteBuffer |
1110 menu disable:#pasteBuffer |
1029 ]. |
1111 ]. |
1030 |
1112 |
1031 arrangeMenu := PopUpMenu labels:#( 'to front' 'to back' ) |
1113 menu subMenuAt:#arrange put:(self subMenuArrange). |
1032 selectors:#( #raiseSelection #lowerSelection ) |
|
1033 receiver:self. |
|
1034 |
|
1035 |
|
1036 menu subMenuAt:#arrange put:arrangeMenu. |
|
1037 menu subMenuAt:#dimension put:(self subMenuDimension). |
1114 menu subMenuAt:#dimension put:(self subMenuDimension). |
1038 |
1115 menu subMenuAt:#align put:(self subMenuAlign). |
1039 selection size > 1 ifTrue:[ |
|
1040 menu addLabels:( resources array:#('align') ) |
|
1041 selectors:#( align ). |
|
1042 |
|
1043 menu subMenuAt:#align put:self subMenuAlign |
|
1044 ]. |
|
1045 ^ menu |
1116 ^ menu |
1046 ! |
1117 ! |
1047 |
1118 |
1048 subMenuAlign |
1119 subMenuAlign |
1049 "returns submenu alignment |
1120 "returns submenu alignment |
1137 deleteSelection |
1260 deleteSelection |
1138 "delete the selection |
1261 "delete the selection |
1139 " |
1262 " |
1140 |specs text| |
1263 |specs text| |
1141 |
1264 |
1142 selection notNil ifTrue:[ |
1265 self numberOfSelections ~~ 0 ifTrue:[ |
1143 specs := self generateSpecFor:selection. |
1266 specs := self generateSpecFor:selection. |
1144 text := self transactionTextFor:selection. |
1267 text := self transactionTextFor:selection. |
1145 |
1268 |
1146 undoHistory transaction:#cut text:text do:[ |
1269 undoHistory transaction:#cut text:text do:[ |
1147 super deleteSelection |
1270 super deleteSelection |
1148 ]. |
1271 ]. |
1149 self setSelection:specs |
1272 self setSelection:specs |
1167 ! |
1290 ! |
1168 |
1291 |
1169 pasteBuffer |
1292 pasteBuffer |
1170 "add the objects in the paste-buffer |
1293 "add the objects in the paste-buffer |
1171 " |
1294 " |
1172 |sel firstEntry builder frame| |
1295 |paste builder frame pasteOrigin pasteOffset| |
1173 |
1296 |
1174 sel := self getSelection. |
1297 paste := self getSelection. |
1175 frame := self. |
1298 |
1176 |
1299 (self canPaste:paste) ifFalse:[ ^ self]. |
1177 selection notNil ifTrue:[ |
1300 (paste isCollection) ifFalse:[ paste := Array with:paste]. |
1178 (self supportsSubComponents:selection) ifTrue:[ |
1301 |
1179 frame := selection |
1302 frame := self singleSelection. |
1180 ]. |
1303 |
1181 self unselect |
1304 (self supportsSubComponents:frame) ifFalse:[ |
1182 ]. |
1305 frame := self |
1183 |
1306 ]. |
1184 sel size == 0 ifTrue:[firstEntry := sel] |
1307 self unselect. |
1185 ifFalse:[firstEntry := sel at:1]. |
1308 |
1186 |
1309 builder := UIBuilder new. |
1187 (firstEntry isKindOf:UISpecification) ifFalse:[ |
1310 selection := OrderedCollection new. |
1188 ^ self |
1311 pasteOffset := 0@0. |
1189 ]. |
1312 pasteOrigin := self sensor mousePoint. |
1190 builder := UIBuilder new. |
1313 pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id. |
1191 selection := OrderedCollection new. |
1314 |
1192 |
1315 paste do:[:aSpec| |
1193 sel do:[:aSpec||v| |
1316 |v org| |
1194 builder componentCreationHook:[:view :spec :aBuilder | |
1317 |
1195 self createdComponent:view forSpec:spec |
1318 builder componentCreationHook:[:view :spec :aBuilder | |
|
1319 self createdComponent:view forSpec:spec builder:aBuilder. |
1196 ]. |
1320 ]. |
1197 builder applicationClass:(Smalltalk classNamed:className). |
1321 builder applicationClass:(Smalltalk classNamed:className). |
1198 v := aSpec buildViewWithLayoutFor:builder in:frame. |
1322 v := aSpec buildViewWithLayoutFor:builder in:frame. |
|
1323 |
|
1324 (frame bounds containsPoint:pasteOrigin) ifFalse:[ |
|
1325 self moveObject:v to:pasteOffset. |
|
1326 ] ifTrue:[ |
|
1327 self moveObject:v to:pasteOrigin + pasteOffset. |
|
1328 ]. |
|
1329 |
1199 v realize. |
1330 v realize. |
1200 selection add:v. |
1331 selection add:v. |
|
1332 |
|
1333 pasteOffset := pasteOffset + 4. |
1201 ]. |
1334 ]. |
1202 |
1335 |
1203 self transaction:#paste selectionDo:[:v| |
1336 self transaction:#paste selectionDo:[:v| |
1204 self undoCreate:((self propertyOfView:v) identifier) |
1337 self undoCreate:((self propertyOfView:v) identifier) |
1205 ]. |
1338 ]. |
1489 ! |
1622 ! |
1490 |
1623 |
1491 transactionTextFor:anElementOrCollection |
1624 transactionTextFor:anElementOrCollection |
1492 "returns text used by transaction or nil |
1625 "returns text used by transaction or nil |
1493 " |
1626 " |
1494 |props| |
1627 |props size| |
1495 |
1628 |
1496 anElementOrCollection notNil ifTrue:[ |
1629 anElementOrCollection notNil ifTrue:[ |
1497 anElementOrCollection size > 1 ifTrue:[ |
1630 anElementOrCollection isCollection ifTrue:[ |
1498 ^ 'a collection' |
1631 size := anElementOrCollection. |
|
1632 size == 0 ifTrue:[^ nil]. |
|
1633 size ~~ 1 ifTrue:[^ 'a collection']. |
|
1634 |
|
1635 props := self propertyOfView:(anElementOrCollection at:1). |
|
1636 ] ifFalse:[ |
|
1637 props := self propertyOfView:anElementOrCollection |
1499 ]. |
1638 ]. |
1500 |
1639 props notNil ifTrue:[ ^ props name ] |
1501 anElementOrCollection isCollection ifFalse:[ |
|
1502 props := self propertyOfView:anElementOrCollection |
|
1503 ] ifTrue:[ |
|
1504 anElementOrCollection notEmpty ifTrue:[ |
|
1505 props := self propertyOfView:(anElementOrCollection at:1) |
|
1506 ] |
|
1507 ]. |
|
1508 |
|
1509 props notNil ifTrue:[ |
|
1510 ^ props name |
|
1511 ] |
|
1512 ]. |
1640 ]. |
1513 ^ nil |
1641 ^ nil |
1514 ! |
1642 ! |
1515 |
1643 |
1516 undoCreate:aViewIdentifier |
1644 undoCreate:aViewIdentifier |
1568 ]. |
1696 ]. |
1569 aView := nil. |
1697 aView := nil. |
1570 |
1698 |
1571 ! ! |
1699 ! ! |
1572 |
1700 |
|
1701 !UIPainterView methodsFor:'update from Specification'! |
|
1702 |
|
1703 updateFromSpec:aSpec |
|
1704 "update current selected view from specification |
|
1705 " |
|
1706 self singleSelection notNil ifTrue:[ |
|
1707 self selectionHiddenDo:[ |
|
1708 self transaction:#specification selectionDo:[:aView| |
|
1709 |spec builder| |
|
1710 |
|
1711 spec := (self generateSpecFor:aView) first. |
|
1712 |
|
1713 undoHistory addUndoBlock:[ |
|
1714 builder := UIBuilder new. |
|
1715 spec setAttributesIn:aView with:builder. |
|
1716 aView superView sizeChanged:nil |
|
1717 ]. |
|
1718 builder := UIBuilder new. |
|
1719 aSpec setAttributesIn:aView with:builder. |
|
1720 aView superView sizeChanged:nil. |
|
1721 (self propertyOfView:aView) tabable:aSpec tabable. |
|
1722 ]. |
|
1723 self changed:#tree |
|
1724 ] |
|
1725 ] |
|
1726 |
|
1727 ! ! |
|
1728 |
1573 !UIPainterView::ViewProperty class methodsFor:'instance creation'! |
1729 !UIPainterView::ViewProperty class methodsFor:'instance creation'! |
1574 |
1730 |
1575 new |
1731 new |
1576 Identifier notNil ifTrue:[Identifier := Identifier + 1] |
1732 Identifier notNil ifTrue:[Identifier := Identifier + 1] |
1577 ifFalse:[Identifier := 1]. |
1733 ifFalse:[Identifier := 1]. |
1634 labelSelector := something.! |
1790 labelSelector := something.! |
1635 |
1791 |
1636 name |
1792 name |
1637 "return the value of the instance variable 'name' (automatically generated)" |
1793 "return the value of the instance variable 'name' (automatically generated)" |
1638 |
1794 |
1639 ^ name! |
1795 ^ view name |
|
1796 ! |
1640 |
1797 |
1641 name:something |
1798 name:something |
1642 "set the value of the instance variable 'name' (automatically generated)" |
1799 "set the value of the instance variable 'name' (automatically generated)" |
1643 |
1800 |
1644 name := something.! |
1801 view name:something |
|
1802 ! |
1645 |
1803 |
1646 nameIndex |
1804 nameIndex |
1647 "return the value of the instance variable 'nameIndex' (automatically generated)" |
1805 "return the value of the instance variable 'nameIndex' (automatically generated)" |
1648 |
1806 |
1649 ^ nameIndex! |
1807 ^ nameIndex! |
1650 |
1808 |
1651 nameIndex:something |
1809 nameIndex:something |
1652 "set the value of the instance variable 'nameIndex' (automatically generated)" |
1810 "set the value of the instance variable 'nameIndex' (automatically generated)" |
1653 |
1811 |
1654 nameIndex := something.! |
1812 nameIndex := something.! |
|
1813 |
|
1814 tabable |
|
1815 "return the value of the instance variable 'tabable' (automatically generated)" |
|
1816 |
|
1817 ^ tabable! |
|
1818 |
|
1819 tabable:something |
|
1820 "set the value of the instance variable 'tabable' (automatically generated)" |
|
1821 |
|
1822 tabable := something.! |
1655 |
1823 |
1656 view |
1824 view |
1657 "return the value of the instance variable 'view' (automatically generated)" |
1825 "return the value of the instance variable 'view' (automatically generated)" |
1658 |
1826 |
1659 ^ view! |
1827 ^ view! |