UIPainterView.st
changeset 285 d80b3c6a4373
parent 281 aabb4037f6a3
child 288 675327dd4d7d
equal deleted inserted replaced
284:995078a58977 285:d80b3c6a4373
   278         self withinTransaction:#paste objects:newSel do:[
   278         self withinTransaction:#paste objects:newSel do:[
   279             undoHistory addUndoSelector:#undoCreate:
   279             undoHistory addUndoSelector:#undoCreate:
   280                                withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier])
   280                                withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier])
   281         ].
   281         ].
   282 
   282 
   283         newSel size == 1 ifTrue:[
       
   284             newSel := newSel at:1
       
   285         ].
       
   286         self realizeAllSubViews.
   283         self realizeAllSubViews.
       
   284         newSel do:[:v| v raise].
   287         inputView raise.
   285         inputView raise.
   288         self elementChangedSize:frame.
   286         self elementChangedSize:frame.
       
   287 
       
   288         newSel size == 1 ifTrue:[newSel := newSel at:1].
   289     ].
   289     ].
   290     ^ newSel
   290     ^ newSel
   291 
       
   292     "Created: 11.8.1997 / 00:59:38 / cg"
       
   293     "Modified: 11.8.1997 / 01:05:27 / cg"
       
   294 !
   291 !
   295 
   292 
   296 pasteWithLayout
   293 pasteWithLayout
   297     "add the objects in the paste-buffer to the object view; don't change the
   294     "add the objects in the paste-buffer to the object view; don't change the
   298      layout
   295      layout
   313         ^ self canPaste:(anObjectOrCollection first theObject)
   310         ^ self canPaste:(anObjectOrCollection first theObject)
   314     ].
   311     ].
   315     ^ false
   312     ^ false
   316 !
   313 !
   317 
   314 
       
   315 canPaste
       
   316     "returns true if something to be past exists and can be paste into
       
   317      the selection if exists
       
   318     "
       
   319     ^ self canPaste:(self getSelection)
       
   320 !
       
   321 
   318 canPaste:something
   322 canPaste:something
   319     "returns true if something could be paste
   323     "returns true if something could be paste
   320     "
   324     "
   321     |el size|
   325     |el size|
   322 
   326 
   338 !
   342 !
   339 
   343 
   340 canPasteInto:aView
   344 canPasteInto:aView
   341     "can paste into a view
   345     "can paste into a view
   342     "
   346     "
   343     |spec|
   347     |prop|
   344 
   348 
   345     aView notNil ifTrue:[
   349     aView notNil ifTrue:[
   346         spec := self specFor:aView.
   350         (prop := self propertyRespondsToView:aView) notNil ifTrue:[
   347 
   351             ^ prop spec class supportsSubComponents
   348         spec isNil ifTrue:[^ aView specClass supportsSubComponents]
   352         ].
   349                   ifFalse:[^ spec  class     supportsSubComponents]
   353       ^ aView specClass supportsSubComponents.
   350     ].
   354     ].
   351     ^ false
   355     ^ false
   352 
   356 
   353 !
   357 !
   354 
   358 
   569         builder := UIBuilder new.
   573         builder := UIBuilder new.
   570         spec window setupView:self topView for:builder.
   574         spec window setupView:self topView for:builder.
   571         self addSpec:(spec component) builder:builder in:self.
   575         self addSpec:(spec component) builder:builder in:self.
   572         self realizeAllSubViews.
   576         self realizeAllSubViews.
   573         inputView raise.
   577         inputView raise.
       
   578         treeView canvasNameChanged:(spec window name).
   574     ]
   579     ]
   575 !
   580 !
   576 
   581 
   577 treeView:aTreeView
   582 treeView:aTreeView
   578     treeView := aTreeView
   583     treeView := aTreeView
   581 !UIPainterView methodsFor:'menus'!
   586 !UIPainterView methodsFor:'menus'!
   582 
   587 
   583 showMiddleButtonMenu
   588 showMiddleButtonMenu
   584     "show the middle button menu; this returns nil
   589     "show the middle button menu; this returns nil
   585     "
   590     "
   586     |menu|
       
   587 
       
   588     self enabled ifTrue:[
   591     self enabled ifTrue:[
   589         menu := MenuPanel fromSpec:(UIPainter menuCanvas) receiver:self.
   592         (MenuPanel fromSpec:(UIPainter menuCanvas) receiver:self) startUp
   590 
       
   591         self hasSelection ifFalse:[
       
   592             menu disableAll
       
   593         ].
       
   594         menu enabledAt:#paste put:(self canPaste:(self getSelection)).
       
   595         menu enabledAt:#undo  put:(undoHistory isEmpty not).
       
   596         menu startUp.
       
   597     ].
   593     ].
   598   ^ nil
   594   ^ nil
   599 
   595 
   600 
   596 
   601 
   597 
   621     ]
   617     ]
   622 ! !
   618 ! !
   623 
   619 
   624 !UIPainterView methodsFor:'searching'!
   620 !UIPainterView methodsFor:'searching'!
   625 
   621 
   626 findContainerViewAt:aPoint
   622 findContainerOfView:aView
   627     "find container view responds to aPoint.
   623     "returns the super view assigned to a view
   628     "
   624     "
   629     |view|
   625     |p|
   630 
   626 
   631     (view := self findObjectAt:aPoint) isNil ifTrue:[
   627     (p := self propertyOfParentForView:aView) isNil ifTrue:[
   632         ^ self
   628         ^ self
   633     ].
   629     ].
   634 
   630     ^ p view
   635     [(view specClass supportsSubComponents or:[(view := view superView) == self])
       
   636     ] whileFalse:[
       
   637         [(self propertyOfView:view) isNil] whileTrue:[
       
   638             (view := view superView) == self ifTrue:[^ self]
       
   639         ].
       
   640     ].
       
   641     ^ view
       
   642 !
   631 !
   643 
   632 
   644 findObjectAt:aPoint
   633 findObjectAt:aPoint
   645     "find the origin/corner of the currentWidget
   634     "find the origin/corner of the currentWidget
   646     "
   635     "
   647     |view|
   636     |view prop|
   648 
   637 
   649     view := super findObjectAt:aPoint.
   638     view := super findObjectAt:aPoint.
   650 
   639     prop := self propertyRespondsToView:view.
   651     view notNil ifTrue:[
   640 
   652         "can be a view within a view not visible
   641     prop notNil ifTrue:[^ prop view].
   653         "
   642   ^ nil
   654         [ (self propertyOfView:view) isNil ] whileTrue:[
       
   655             (view := view superView) == self ifTrue:[^ nil]
       
   656         ]
       
   657     ].
       
   658     ^ view
       
   659 !
   643 !
   660 
   644 
   661 findViewWithId:aViewId
   645 findViewWithId:aViewId
   662     "finds view assigned to identifier and returns the view or nil
   646     "finds view assigned to identifier and returns the view or nil
   663     "
   647     "
   688       ^ treeView propertyDetect:[:p| p name = name ].
   672       ^ treeView propertyDetect:[:p| p name = name ].
   689     ].
   673     ].
   690     ^ nil
   674     ^ nil
   691 !
   675 !
   692 
   676 
       
   677 propertyOfParentForView:aSubView
       
   678     "returns the property of the parent or nil
       
   679     "
       
   680     |item|
       
   681 
       
   682     (item := treeView detectItemRespondsToView:aSubView) notNil ifTrue:[
       
   683         (item := item parent) notNil ifTrue:[^ item contents]
       
   684     ].
       
   685     ^ nil
       
   686 !
       
   687 
   693 propertyOfView:aView
   688 propertyOfView:aView
   694     "returns property assigned to view
   689     "returns property assigned to view
   695     "
   690     "
   696     (aView isNil or:[aView == self]) ifFalse:[
   691     (aView isNil or:[aView == self]) ifFalse:[
   697         ^ treeView propertyDetect:[:p| p view == aView ]
   692         ^ treeView propertyDetect:[:p| p view == aView ]
       
   693     ].
       
   694     ^ nil
       
   695 !
       
   696 
       
   697 propertyRespondsToView:aView
       
   698     "detect the property responding to the argument a view. The property of the view or
       
   699      the first subview providing the properties is returned. If no property is detected
       
   700      nil is returned.
       
   701     "
       
   702     |item|
       
   703 
       
   704     item := treeView detectItemRespondsToView:aView.
       
   705 
       
   706     (item notNil and:[item parent notNil]) ifTrue:[
       
   707         ^ item contents
   698     ].
   708     ].
   699     ^ nil
   709     ^ nil
   700 !
   710 !
   701 
   711 
   702 uniqueNameFor:aSpecOrString
   712 uniqueNameFor:aSpecOrString
   792         treeView cvsSelection:something
   802         treeView cvsSelection:something
   793     ]
   803     ]
   794 
   804 
   795 !
   805 !
   796 
   806 
   797 updateSelectionFromModel:aSel
   807 updateSelectionFromModel:aSelOrNil
   798     "update selection from a new selection
   808     "update selection from a new selection
   799     "
   809     "
   800     |sel|
       
   801 
       
   802     selectionHiddenLevel == 0 ifTrue:[
   810     selectionHiddenLevel == 0 ifTrue:[
   803         self selectionDo:[:el| (aSel includes:el) ifFalse:[self showUnselected:el] ]
   811         aSelOrNil size ~~ 0 ifTrue:[
   804     ].
   812             self selectionDo:[:el| (aSelOrNil includes:el) ifFalse:[self showUnselected:el] ]
   805 
   813         ] ifFalse:[
   806     (aSel indexOf:self) ~~ 0 ifTrue:[
   814             self selectionDo:[:el| self showUnselected:el ]
   807         aSel size > 1 ifTrue:[sel := aSel copyWithout:self]
   815         ]
   808     ] ifFalse:[
   816     ].
   809         aSel size ~~ 0 ifTrue:[sel := aSel]
   817     self setSelection:aSelOrNil withRedraw:false.
   810     ].
       
   811 
       
   812     self setSelection:sel withRedraw:false.
       
   813     self showSelection
   818     self showSelection
   814 
       
   815 
   819 
   816 ! !
   820 ! !
   817 
   821 
   818 !UIPainterView methodsFor:'specification'!
   822 !UIPainterView methodsFor:'specification'!
   819 
   823 
   879 
   883 
   880 
   884 
   881 
   885 
   882 !
   886 !
   883 
   887 
       
   888 rebuildView:aView fromSpec:aSpec withBuilder:aBuilder
       
   889     |v|
       
   890 
       
   891     aSpec needsRebuildForAttributes ifTrue:[
       
   892         v := aSpec buildViewWithLayoutFor:aBuilder in:(self findContainerOfView:aView).
       
   893         v realize.    
       
   894         aView destroy.
       
   895         device sync.
       
   896         device flush.
       
   897         aView becomeSameAs:v.
       
   898         inputView raise.
       
   899     ] ifFalse:[
       
   900         aSpec setAttributesIn:aView with:aBuilder.
       
   901         self elementChangedSize:aView.
       
   902     ].
       
   903 
       
   904 !
       
   905 
   884 specFor:anObject
   906 specFor:anObject
   885     "returns spec assigned to an object
   907     "returns spec assigned to an object
   886     "
   908     "
   887     |prop spec|
   909     |prop spec|
   888 
   910 
   929                         name := props name
   951                         name := props name
   930                     ]
   952                     ]
   931                 ].
   953                 ].
   932                 aSpec name:name.
   954                 aSpec name:name.
   933                 self createUndoSpecModify:props.
   955                 self createUndoSpecModify:props.
   934 
   956                 self rebuildView:aView fromSpec:aSpec withBuilder:builder.
   935                 aSpec needsRebuildForAttributes ifTrue:[
       
   936                     v := aSpec buildViewWithLayoutFor:builder in:aView superView.
       
   937                     v realize.    
       
   938                     aView destroy.
       
   939                     device sync. device flush.
       
   940                     aView becomeSameAs:v.
       
   941                     inputView raise.
       
   942                 ] ifFalse:[
       
   943                     aSpec setAttributesIn:aView with:builder.
       
   944                     self elementChangedSize:aView.
       
   945                 ].
       
   946                 props spec:(aSpec copy).
   957                 props spec:(aSpec copy).
   947                 treeView propertyChanged:props.
   958                 treeView propertyChanged:props.
   948             ]
   959             ]
   949         ]
   960         ]
   950     ]
   961     ]
   951 
   962 
   952     "Modified: 4.7.1997 / 23:49:44 / cg"
   963     "Modified: 4.7.1997 / 23:49:44 / cg"
       
   964 ! !
       
   965 
       
   966 !UIPainterView methodsFor:'testing'!
       
   967 
       
   968 canChangeLayoutOfView:aView
       
   969     "returns true if the view can change its layout which is dependant on
       
   970      its parent view.
       
   971     "
       
   972     |item prnt|
       
   973 
       
   974     (     (item := treeView itemOfView:aView) isNil
       
   975       or:[(prnt := item parent) isNil]
       
   976     ) ifTrue:[
       
   977         ^ false
       
   978     ].
       
   979     ^ (prnt parent isNil or:[prnt contents spec class isLayoutContainer not])
       
   980 !
       
   981 
       
   982 canKeepLayoutInSelection
       
   983     "returns true if layout can be kept during a paste operation
       
   984     "
       
   985     |prop|
       
   986 
       
   987     prop := self propertyOfView:(self singleSelection).
       
   988   ^ (prop isNil or:[prop spec class isLayoutContainer not])
       
   989 !
       
   990 
       
   991 canMove:something
       
   992     "checks whether something is not nil and if all widgets derived from
       
   993      something can change their layout ( move, align, ... operation ).
       
   994     "
       
   995     something notNil ifTrue:[
       
   996         self forEach:something do:[:aView|
       
   997             (self canChangeLayoutOfView:aView) ifFalse:[^ false]
       
   998         ].
       
   999         ^ true
       
  1000     ].
       
  1001     ^ false
       
  1002 !
       
  1003 
       
  1004 canMoveOrAlignSelection
       
  1005     "returns true if a selection exists and all elements in the selection
       
  1006      can be moved or aligned
       
  1007     "
       
  1008   ^ self canMove:(self selection)
       
  1009 
   953 ! !
  1010 ! !
   954 
  1011 
   955 !UIPainterView methodsFor:'transaction'!
  1012 !UIPainterView methodsFor:'transaction'!
   956 
  1013 
   957 transaction:aType objects:something do:aOneArgBlock
  1014 transaction:aType objects:something do:aOneArgBlock
  1017 !
  1074 !
  1018 
  1075 
  1019 createUndoRemove:aView
  1076 createUndoRemove:aView
  1020     "create undo method before deleting views
  1077     "create undo method before deleting views
  1021     "
  1078     "
  1022     |frame prop pId spec|
  1079     |prop pid|
  1023 
  1080 
  1024     (prop := self propertyOfView:aView) notNil ifTrue:[
  1081     (prop := self propertyOfView:aView) notNil ifTrue:[
  1025         spec  := self fullSpecFor:aView.
  1082         (pid := self propertyOfParentForView:aView) notNil ifTrue:[
  1026         frame := aView superView.
  1083             pid := pid identifier
  1027 
  1084         ].
  1028         (self canPasteInto:frame) ifTrue:[
  1085 
  1029             (frame := self propertyOfView:frame) notNil ifTrue:[
       
  1030                 pId := frame identifier
       
  1031             ]
       
  1032         ].
       
  1033         undoHistory addUndoSelector:#undoRemove:
  1086         undoHistory addUndoSelector:#undoRemove:
  1034                            withArgs:(Array with:spec with:(prop identifier) with:pId)
  1087                            withArgs:(Array with:(self fullSpecFor:aView)
       
  1088                                with:(prop identifier)
       
  1089                                with:pid)
  1035     ]
  1090     ]
  1036 !
  1091 !
  1037 
  1092 
  1038 createUndoSpecModify:aProp
  1093 createUndoSpecModify:aProp
  1039     "undo method when changing the specification for an object
  1094     "undo method when changing the specification for an object
  1094         builder := UIBuilder new.
  1149         builder := UIBuilder new.
  1095         className notNil ifTrue:[
  1150         className notNil ifTrue:[
  1096             builder applicationClass:(Smalltalk classNamed:className).
  1151             builder applicationClass:(Smalltalk classNamed:className).
  1097         ].
  1152         ].
  1098         props spec:spec.
  1153         props spec:spec.
  1099 
  1154         self rebuildView:view fromSpec:spec withBuilder:builder.
  1100         spec needsRebuildForAttributes ifTrue:[
       
  1101             v := spec buildViewWithLayoutFor:builder in:view superView.
       
  1102             v realize.    
       
  1103             view destroy.
       
  1104             view become:v
       
  1105         ] ifFalse:[
       
  1106             spec setAttributesIn:view with:builder.
       
  1107             self elementChangedSize:view.
       
  1108         ].
       
  1109         treeView propertyChanged:props.
  1155         treeView propertyChanged:props.
  1110     ]
  1156     ]
  1111 ! !
  1157 ! !
  1112 
  1158 
  1113 !UIPainterView::ViewProperty class methodsFor:'instance creation'!
  1159 !UIPainterView::ViewProperty class methodsFor:'instance creation'!