UIObjectView.st
changeset 2501 43386f544f3d
parent 2485 59ecb1305177
child 2503 36dce8c654af
equal deleted inserted replaced
2500:3e2feb544801 2501:43386f544f3d
   193     |type v h|
   193     |type v h|
   194 
   194 
   195     type := self layoutType:aView.
   195     type := self layoutType:aView.
   196 
   196 
   197     (type == #LayoutFrame or:[type == #Rectangle]) ifTrue:[
   197     (type == #LayoutFrame or:[type == #Rectangle]) ifTrue:[
   198 	v := self isVerticalResizable:aView.
   198         v := self isVerticalResizable:aView.
   199 	h := self isHorizontalResizable:aView.
   199         h := self isHorizontalResizable:aView.
   200 
   200 
   201 	h ifTrue:[  aBlock value:(aView leftCenter ) value:#left.
   201         h ifTrue:[  
   202 		    aBlock value:(aView rightCenter) value:#right.
   202             aBlock value:(aView leftCenter ) value:#left.
   203 		 ].
   203             aBlock value:(aView rightCenter) value:#right
   204 	v ifTrue:[  aBlock value:(aView topCenter   ) value:#top.
   204         ].
   205 		    aBlock value:(aView bottomCenter) value:#bottom.
   205         v ifTrue:[  
   206 		 ].
   206             aBlock value:(aView topCenter   ) value:#top.
   207 
   207             aBlock value:(aView bottomCenter) value:#bottom.
   208 	(h and:[v]) ifTrue:[
   208         ].
   209 	    aBlock value:(aView origin    ) value:#origin.
   209 
   210 	    aBlock value:(aView topRight  ) value:#topRight.
   210         (h and:[v]) ifTrue:[
   211 	    aBlock value:(aView bottomLeft) value:#bottomLeft.
   211             aBlock value:(aView origin    ) value:#origin.
   212 	    aBlock value:(aView corner    ) value:#corner.
   212             aBlock value:(aView topRight  ) value:#topRight.
   213 	  ^ self
   213             aBlock value:(aView bottomLeft) value:#bottomLeft.
   214 	]
   214             aBlock value:(aView corner    ) value:#corner.
       
   215             ^ self
       
   216         ]
   215     ].
   217     ].
   216 
   218 
   217     aBlock value:(aView origin    ) value:#view.
   219     aBlock value:(aView origin    ) value:#view.
   218     aBlock value:(aView topRight  ) value:#view.
   220     aBlock value:(aView topRight  ) value:#view.
   219     aBlock value:(aView bottomLeft) value:#view.
   221     aBlock value:(aView bottomLeft) value:#view.
   220 
   222 
   221     type == #Extent ifTrue:[
   223     type == #Extent ifTrue:[
   222 	v := self isVerticalResizable:aView.
   224         v := self isVerticalResizable:aView.
   223 	h := self isHorizontalResizable:aView.
   225         h := self isHorizontalResizable:aView.
   224 
   226 
   225 	v ifTrue:[aBlock value:(aView bottomCenter) value:#bottom].
   227         v ifTrue:[ aBlock value:(aView bottomCenter) value:#bottom ].
   226 	h ifTrue:[aBlock value:(aView rightCenter ) value:#right ].
   228         h ifTrue:[ aBlock value:(aView rightCenter ) value:#right ].
   227 
   229 
   228 	(h and:[v]) ifTrue:[
   230         (h and:[v]) ifTrue:[
   229 	    aBlock value:(aView corner) value:#corner.
   231             aBlock value:(aView corner) value:#corner.
   230 	  ^ self
   232             ^ self
   231 	]
   233         ]
   232     ].
   234     ].
   233     aBlock value:(aView corner) value:#view.
   235     aBlock value:(aView corner) value:#view.
   234 
       
   235 
       
   236 ! !
   236 ! !
   237 
   237 
   238 !UIObjectView class methodsFor:'queries'!
   238 !UIObjectView class methodsFor:'queries'!
   239 
   239 
   240 isHorizontalResizable:aComponent
   240 isHorizontalResizable:aComponent
   476 
   476 
   477 doublePressed:pressPoint
   477 doublePressed:pressPoint
   478 !
   478 !
   479 
   479 
   480 elementChangedSize:aView
   480 elementChangedSize:aView
   481     "some element has changed its size; collect them during selectionHiddenLevel 
   481     "some element has changed its size; collect them while selectionHiddenLevel is on"
   482      is on
   482 
   483     "
       
   484     |spv|
   483     |spv|
   485 
   484 
   486     spv := self findContainerOfView:aView.
   485     spv := self findContainerOfView:aView.
   487 
   486 
   488     selectionHiddenLevel ~~ 0 ifTrue:[setOfSuperViewsSizeChanged add:spv]
   487     aView isView ifFalse:[
   489 			     ifFalse:[spv sizeChanged:nil]
   488         spv invalidate.
       
   489     ].
       
   490 
       
   491     spv := self findContainerOfView:aView.
       
   492 
       
   493     selectionHiddenLevel ~~ 0 ifTrue:[
       
   494         setOfSuperViewsSizeChanged add:spv
       
   495     ] ifFalse:[
       
   496         spv sizeChanged:nil
       
   497     ]
   490 !
   498 !
   491 
   499 
   492 exposeX:x y:y width:w height:h
   500 exposeX:x y:y width:w height:h
   493     "handle an expose event from device; redraw selection
   501     "handle an expose event from device; redraw selection
   494     "
   502     "
   495     resizeData isNil ifTrue:[
   503 
       
   504 "/    resizeData isNil ifTrue:[
   496         super exposeX:x y:y width:w height:h.
   505         super exposeX:x y:y width:w height:h.
   497 
   506 
   498         "/ handle any expose events (for subcomponents) before
   507         "/ handle any expose events (for subcomponents) before
   499         "/ redrawing the handles.
   508         "/ redrawing the handles.
   500 "/        (self sensor hasExposeEventFor:nil) ifTrue:[^ self].
   509 "/        (self sensor hasExposeEventFor:nil) ifTrue:[^ self].
   506 "/                    v exposeX:0 y:0 width:v width height:v height.
   515 "/                    v exposeX:0 y:0 width:v width height:v height.
   507 "/                ]
   516 "/                ]
   508 "/            ].
   517 "/            ].
   509 "/            self showSelected:aComponent
   518 "/            self showSelected:aComponent
   510 "/        ]
   519 "/        ]
   511     ].
   520 "/    ].
   512 
   521 
   513     "Modified: / 9.11.1998 / 12:50:34 / cg"
   522     "Modified: / 9.11.1998 / 12:50:34 / cg"
   514 !
   523 !
   515 
   524 
   516 keyPress:key x:x y:y
   525 keyPress:key x:x y:y
   563 processEvent:anEvent
   572 processEvent:anEvent
   564     "catch expose events for components, and redraw its handles after
   573     "catch expose events for components, and redraw its handles after
   565      the redraw when this happens.
   574      the redraw when this happens.
   566      Return true, if I have eaten the event"
   575      Return true, if I have eaten the event"
   567 
   576 
   568     |evView p|
   577     |evView widget p|
   569 
   578 
   570     self testMode ifTrue:[^ false].
   579     self testMode ifTrue:[^ false].
   571 
   580 
       
   581     anEvent isInputEvent ifFalse:[^ false].
       
   582     anEvent isPointerEnterLeaveEvent ifTrue:[^ true. ^ false].
       
   583     anEvent isKeyboardFocusEvent ifTrue:[^ true. ^ false].
       
   584 
   572     evView := anEvent view.
   585     evView := anEvent view.
   573     (evView isNil or:[evView == self]) ifTrue:[
   586     evView isNil ifTrue:[
   574         ^ false
   587         ^ false
   575     ].
   588     ].
   576 
   589     (evView == self) ifTrue:[
   577     (evView isComponentOf:self) ifFalse:[
   590         "/ new: check for a component to be hit by the event
       
   591         components notEmptyOrNil ifTrue:[
       
   592             p := (anEvent x @ anEvent y).        
       
   593             
       
   594             widget := components detect:[:c | c bounds containsPoint:p ] ifNone:nil.
       
   595         ].
       
   596         widget isNil ifTrue:[
       
   597             ^ false
       
   598         ].
       
   599     ] ifFalse:[
       
   600         widget := evView.
       
   601     ].
       
   602 
       
   603     (widget isComponentOf:self) ifFalse:[
   578         ^ false
   604         ^ false
   579     ].
   605     ].
   580 
       
   581     anEvent isInputEvent ifFalse:[
       
   582         "/ #isDamage: handled in PostEventHandler
       
   583 
       
   584 "/        (shown and:[anEvent isDamage]) ifTrue:[
       
   585 "/            (self isSelected:evView) ifTrue:[
       
   586 "/                self showSelected:evView
       
   587 "/            ].
       
   588 "/        ].
       
   589         ^ false
       
   590     ].
       
   591 
       
   592     (anEvent isButtonEvent or:[anEvent isKeyEvent])  ifFalse:[
   606     (anEvent isButtonEvent or:[anEvent isKeyEvent])  ifFalse:[
   593         ^ true
   607         ^ true
   594     ].
   608     ].
   595 
   609 
   596     anEvent isButtonMotionEvent ifTrue:[
   610     anEvent isButtonMotionEvent ifTrue:[
   597         "/ use current point - layout of underlaying view might change
   611         "/ use current point - layout of underlaying view might change
   598         "/ and computation dependent on origin is wrong
   612         "/ and computation dependent on origin is wrong
   599         p := self sensor mousePoint.
   613         p := self sensor mousePoint.
   600         p := device translatePoint:p fromView:nil toView:self.
   614         p := device translatePoint:p fromView:nil toView:self.
   601     ] ifFalse:[
   615     ] ifFalse:[
   602         p := Point x:(anEvent x) y:(anEvent y).
   616         p := (anEvent x) @ (anEvent y).
   603         p := device translatePoint:p fromView:evView toView:self.
   617         p := device translatePoint:p fromView:evView toView:self.
   604     ].
   618     ].
   605 
   619 
   606     "/ patch the event
   620     "/ patch the event
   607     anEvent x:p x.
   621     anEvent x:p x.
   612 
   626 
   613 redrawX:nx y:ny width:nw height:nh
   627 redrawX:nx y:ny width:nw height:nh
   614     |redrawFrame|
   628     |redrawFrame|
   615 
   629 
   616     redrawFrame := Rectangle left:nx top:ny width:nw height:nh.
   630     redrawFrame := Rectangle left:nx top:ny width:nw height:nh.
   617     self clearRectangle:redrawFrame.
   631     "/ self clearRectangle:redrawFrame.
       
   632     super redrawX:nx y:ny width:nw height:nh.
   618 
   633 
   619     self selectionDo:[:aComponent |
   634     self selectionDo:[:aComponent |
   620         |anyHandleToRedraw|
   635         |anyHandleToRedraw|
   621 
   636 
   622         anyHandleToRedraw := false.
   637         anyHandleToRedraw := false.
   690 ! !
   705 ! !
   691 
   706 
   692 !UIObjectView methodsFor:'misc'!
   707 !UIObjectView methodsFor:'misc'!
   693 
   708 
   694 invertOutlineOf:something
   709 invertOutlineOf:something
   695     "invert outline of an object or collection of objects
   710     "invert outline of an object or collection of objects"
   696     "
   711 
   697     |wasClipped|
   712     |wasClipped|
   698 
   713 
       
   714 ^ self.
   699     (wasClipped := clipChildren) ifTrue:[
   715     (wasClipped := clipChildren) ifTrue:[
   700         self clippedByChildren:(clipChildren := false).
   716         self clippedByChildren:(clipChildren := false).
   701     ].
   717     ].
   702 
   718 
   703     self xoring:[
   719     self xoring:[
   704         |p|
   720         |p|
   705 
   721 
   706         something isCollection ifTrue:[
   722         something isCollection ifTrue:[
   707             something do:[:v |
   723             something do:[:v |
   708                 |p|
       
   709 
       
   710                 p := v originRelativeTo:self.
   724                 p := v originRelativeTo:self.
   711                 self displayRectangle:(p extent:v extent).
   725                 self displayRectangle:(p extent:v extent).
   712             ].
   726             ].
   713         ] ifFalse:[
   727         ] ifFalse:[
   714             |p|
       
   715 
       
   716             p := something originRelativeTo:self.
   728             p := something originRelativeTo:self.
   717             self displayRectangle:(p extent:something extent).
   729             self displayRectangle:(p extent:something extent).
   718         ]
   730         ]
   719     ].
   731     ].
   720 
   732 
   738             (setOfViews contains:[:v | aView isComponentOf:v]) not
   750             (setOfViews contains:[:v | aView isComponentOf:v]) not
   739         ]
   751         ]
   740 !
   752 !
   741 
   753 
   742 redrawObjectsInVisible:redrawFrame
   754 redrawObjectsInVisible:redrawFrame
   743     "my objects are views - they redraw themself"
   755     "my objects are views - they redraw themself.
   744 
   756      - no longer - all non-views MUST be redrawn."
       
   757 
       
   758     super redrawObjectsInVisible:redrawFrame.
   745     ^ self
   759     ^ self
   746 
       
   747 !
   760 !
   748 
   761 
   749 setDefaultActions
   762 setDefaultActions
   750     "set default actions
   763     "set default actions
   751     "
   764     "
   761 ! !
   774 ! !
   762 
   775 
   763 !UIObjectView methodsFor:'object moving'!
   776 !UIObjectView methodsFor:'object moving'!
   764 
   777 
   765 doObjectMove:aPoint
   778 doObjectMove:aPoint
   766     "move selection
   779     "move selection"
   767     "
   780 
   768     movedObject notNil ifTrue:[
   781     movedObject notNil ifTrue:[
   769 	self invertOutlineOf:movedObject.
   782         self hideSelection.
   770 
   783         self repairDamage.
   771 	movedObject keysAndValuesDo:[:i :v|
   784 
   772 	    self moveObject:v to:(aPoint - (moveDelta at:i)).
   785         self invertOutlineOf:movedObject.
   773 	].
   786 
   774 	self invertOutlineOf:movedObject.
   787         movedObject keysAndValuesDo:[:i :v|
   775     ]
   788             self moveObject:v to:(aPoint - (moveDelta at:i)).
   776 
   789         ].
       
   790         self invertOutlineOf:movedObject.
       
   791 
       
   792         self showSelection.
       
   793         self repairDamage.
       
   794     ]
   777 !
   795 !
   778 
   796 
   779 endObjectMove
   797 endObjectMove
   780     "cleanup after object(s) move
   798     "cleanup after object(s) move
   781      send expose to each view - workaround....
   799      send expose to each view - workaround....
   789     movedObject := nil.
   807     movedObject := nil.
   790 
   808 
   791     self withSelectionHiddenDo:[
   809     self withSelectionHiddenDo:[
   792         self setSelection:newSel withRedraw:false.
   810         self setSelection:newSel withRedraw:false.
   793 
   811 
       
   812         components notEmptyOrNil ifTrue:[
       
   813             self invalidate.
       
   814         ].
   794         self allSubViewsDo:[:v|
   815         self allSubViewsDo:[:v|
   795             v shown ifTrue:[
   816             v shown ifTrue:[
   796                 v fill:v viewBackground.
   817                 v fill:v viewBackground.
   797                 v exposeX:0 y:0 width:v width height:v height.
   818                 v exposeX:0 y:0 width:v width height:v height.
   798             ].
   819             ].
   821         ]
   842         ]
   822     ]
   843     ]
   823 !
   844 !
   824 
   845 
   825 startObjectMoveAt:aPoint
   846 startObjectMoveAt:aPoint
   826     "start object(s) move at a point
   847     "start object(s) move at a point"
   827     "
   848 
   828     self startObjectMove:(self selection) at:aPoint.
   849     self startObjectMove:(self selection) at:aPoint.
   829     movedObject := self selection.
   850     movedObject := self selection.
   830 
   851 
   831     movedObject isCollection ifFalse:[
   852     movedObject isCollection ifFalse:[
   832         movedObject := Array with:movedObject
   853         movedObject := Array with:movedObject
   833     ].
   854     ].
   834     self setSelection:nil withRedraw:true.
   855 "/    self setSelection:nil withRedraw:true.
   835 
   856 
   836     moveDelta := movedObject collect:[:aView|
   857     moveDelta := movedObject collect:[:aView | aPoint - aView computeOrigin].
   837         aPoint - aView computeOrigin
   858 
   838     ].
       
   839     self transaction:#move objects:movedObject do:[:v|self createUndoLayout:v].
   859     self transaction:#move objects:movedObject do:[:v|self createUndoLayout:v].
   840     self invertOutlineOf:movedObject.
   860     self invertOutlineOf:movedObject.
   841 !
   861 !
   842 
   862 
   843 startSelectMoreOrMove:aPoint
   863 startSelectMoreOrMove:aPoint
   859 
   879 
   860 startSelectOrMove:aPoint
   880 startSelectOrMove:aPoint
   861     "a button is pressed at a point; start moving or selecting"
   881     "a button is pressed at a point; start moving or selecting"
   862 
   882 
   863     |selectedView containerOfSelectedView
   883     |selectedView containerOfSelectedView
   864      clickedView viewOperatedUpon b pView|
   884      clickedView viewOperatedUpon borderHandleSelector pView|
   865 
   885 
   866     self enabled ifFalse:[^ self].
   886     self enabled ifFalse:[^ self].
   867 
   887 
   868     selectedView := self singleSelection.
   888     selectedView := self singleSelection.
   869 
   889 
   872 "/    and:[clickedView isComponentOf:selectedView]) ifTrue:[
   892 "/    and:[clickedView isComponentOf:selectedView]) ifTrue:[
   873 "/        self unselect.
   893 "/        self unselect.
   874 "/        selectedView := nil.    
   894 "/        selectedView := nil.    
   875 "/    ].
   895 "/    ].
   876 
   896 
       
   897     "/ if there is already a selection, see if user clicked onto a handle
       
   898     "/ then, this may be the start of a resize operation.
   877     selectedView notNil ifTrue:[
   899     selectedView notNil ifTrue:[
   878         containerOfSelectedView := self findContainerOfView:selectedView.
   900         containerOfSelectedView := self findContainerOfView:selectedView.
   879 
   901 
   880         containerOfSelectedView specClass canResizeSubComponents ifTrue:[
   902         containerOfSelectedView specClass canResizeSubComponents ifTrue:[
   881             b := self whichHandleOf:selectedView isHitBy:aPoint.
   903             borderHandleSelector := self whichHandleOf:selectedView isHitBy:aPoint.
   882             (b notNil and:[b ~~ #view]) ifTrue:[
   904             (borderHandleSelector notNil and:[borderHandleSelector ~~ #view]) ifTrue:[
   883                 self startResizeBorder:b of:selectedView.
   905                 self startResizeBorder:borderHandleSelector.
   884                 ^ self
   906                 ^ self
   885             ]
   907             ]
   886         ].
   908         ].
   887         viewOperatedUpon := selectedView.
   909         viewOperatedUpon := selectedView.
   888 
   910 
   970     "
   992     "
   971     |p object|
   993     |p object|
   972 
   994 
   973     object := resizeData object.
   995     object := resizeData object.
   974 
   996 
       
   997 self hideSelection.
       
   998 self repairDamage.
   975     self invertOutlineOf:object.
   999     self invertOutlineOf:object.
   976     p := (self alignToGrid:aPoint) - (resizeData delta).
  1000     p := (self alignToGrid:aPoint) - (resizeData delta).
   977 
  1001 
   978     self perform:(resizeData selector) with:object with:p.
  1002     self perform:(resizeData selector) with:object with:p.
   979     Delay waitForSeconds:0.05.
  1003     Delay waitForSeconds:0.05.
   980     [self sensor hasExposeEventFor:nil] whileTrue:[
  1004     [self sensor hasExposeEventFor:nil] whileTrue:[
   981         self windowGroup processExposeEvents
  1005         self windowGroup processExposeEvents
   982     ].
  1006     ].
   983 
  1007 
   984    "/ object geometryLayout:(object geometryLayout).
  1008    "/ object geometryLayout:(object geometryLayout).
   985     self invertOutlineOf:object
  1009     self invertOutlineOf:object.
       
  1010 
       
  1011 self showSelection.
       
  1012 self repairDamage.
   986 !
  1013 !
   987 
  1014 
   988 endResize
  1015 endResize
   989     "cleanup after object resize
  1016     "cleanup after object resize
   990     "
  1017     "
  1012 !
  1039 !
  1013 
  1040 
  1014 layoutChanged
  1041 layoutChanged
  1015 !
  1042 !
  1016 
  1043 
  1017 startResizeBorder:b of:selection
  1044 startResizeBorder:borderHandleSelector
  1018     "resize selected view
  1045     "start resizing the selected view at the given borderHandle"
  1019     "
  1046 
  1020     |object|
  1047     |object|
  1021 
  1048 
  1022     object := self singleSelection.
  1049     object := self singleSelection.
  1023     self actionResize:object selector:b.
  1050     self actionResize:object selector:borderHandleSelector.
  1024 
  1051 
  1025     self transaction:#resize selectionDo:[:aView|
  1052     self 
  1026         self createUndoLayout:aView
  1053         transaction:#resize 
  1027     ].
  1054         selectionDo:[:aView|
  1028     self setSelection:nil withRedraw:true.
  1055             self createUndoLayout:aView
       
  1056         ].
       
  1057     "/ self setSelection:nil withRedraw:true.
  1029 
  1058 
  1030     motionAction  := [:movePoint | self doDragResize:movePoint].
  1059     motionAction  := [:movePoint | self doDragResize:movePoint].
  1031     releaseAction := [self endResize].
  1060     releaseAction := [self endResize].
       
  1061 
  1032     self invertOutlineOf:object
  1062     self invertOutlineOf:object
  1033 ! !
  1063 ! !
  1034 
  1064 
  1035 !UIObjectView methodsFor:'private'!
  1065 !UIObjectView methodsFor:'private'!
  1036 
  1066 
  1053         aTwoArgAction value:(pnt + dlt extent:ext) value:wht
  1083         aTwoArgAction value:(pnt + dlt extent:ext) value:wht
  1054     ]
  1084     ]
  1055 !
  1085 !
  1056 
  1086 
  1057 whichHandleOf:aComponent isHitBy:aPoint
  1087 whichHandleOf:aComponent isHitBy:aPoint
  1058     "returns kind of handle or nil
  1088     "returns kind of handle or nil"
  1059     "
  1089 
  1060     self handlesOf:aComponent do:[:rectangle :what|
  1090     self handlesOf:aComponent do:[:rectangle :what|
  1061 	(rectangle containsPoint:aPoint) ifTrue:[^ what]
  1091         (rectangle containsPoint:aPoint) ifTrue:[^ what]
  1062     ].
  1092     ].
  1063   ^ nil
  1093     ^ nil
  1064 ! !
  1094 ! !
  1065 
  1095 
  1066 !UIObjectView methodsFor:'private-resizing subviews'!
  1096 !UIObjectView methodsFor:'private-resizing subviews'!
  1067 
  1097 
  1068 recomputeShapeIfTransparentBox:aView
  1098 recomputeShapeIfTransparentBox:aView
  1134 
  1164 
  1135 resize:aView top:aPoint
  1165 resize:aView top:aPoint
  1136     "resize a views top"
  1166     "resize a views top"
  1137 
  1167 
  1138     undoHistory withoutTransactionDo:[
  1168     undoHistory withoutTransactionDo:[
  1139         self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0
  1169         self shiftLayout:aView 
       
  1170                 top:((aPoint y) - (aView computeOrigin y)) 
       
  1171                 bottom:0
  1140     ]
  1172     ]
  1141 !
  1173 !
  1142 
  1174 
  1143 resize:aView topRight:aPoint
  1175 resize:aView topRight:aPoint
  1144     "resize a views top and right"
  1176     "resize a views top and right"
  1145 
  1177 
  1146     undoHistory withoutTransactionDo:[
  1178     undoHistory withoutTransactionDo:[
  1147         self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y))
  1179         self shiftLayout:aView 
  1148                             bottom:0
  1180                 top:((aPoint y) - (aView computeOrigin y))
  1149                               left:0
  1181                 bottom:0
  1150                              right:((aPoint x) - (aView computeCorner x))
  1182                 left:0
       
  1183                 right:((aPoint x) - (aView computeCorner x))
  1151 
  1184 
  1152     ]
  1185     ]
  1153 ! !
  1186 ! !
  1154 
  1187 
  1155 !UIObjectView methodsFor:'private-shift layout'!
  1188 !UIObjectView methodsFor:'private-shift layout'!
  1213 ! !
  1246 ! !
  1214 
  1247 
  1215 !UIObjectView methodsFor:'searching'!
  1248 !UIObjectView methodsFor:'searching'!
  1216 
  1249 
  1217 findObjectAt:aPoint
  1250 findObjectAt:aPoint
  1218     |view viewId lastId point|
  1251     |view viewId lastId point component componentOrView|
  1219 
  1252 
  1220     point  := aPoint + (device translatePoint:0@0 fromView:self toView:rootView).
  1253     componentOrView := self findObjectAt:aPoint in:self.
  1221 
  1254 
  1222     viewId := rootView id.
  1255     componentOrView == self ifTrue:[^ nil].
  1223     [viewId notNil] whileTrue:[
  1256     ^ componentOrView.
  1224         lastId := viewId.
  1257 
  1225         viewId := device viewIdFromPoint:point in:lastId
  1258 "/ cg: old code, which I do not understand
  1226     ].
  1259 "/    point := device translatePoint:aPoint fromView:self toView:rootView.
  1227 
       
  1228     view := device viewFromId:lastId.
       
  1229     view == self ifTrue:[ ^ nil].
       
  1230     ^ view
       
  1231 "/    view ~~ inputView ifTrue:[^ view].
       
  1232 "/
  1260 "/
  1233 "/    "/ look for 'hidden' views ...
  1261 "/    viewId := rootView id.
  1234 "/
  1262 "/    [viewId notNil] whileTrue:[
  1235 "/    listOfViews := OrderedCollection new.
  1263 "/        lastId := viewId.
  1236 "/    self allSubViewsDo:[:aView |
  1264 "/        viewId := device viewIdFromPoint:point in:lastId. "/ must be rootView coordinate
  1237 "/        |org|
       
  1238 "/
       
  1239 "/        aView ~~ inputView ifTrue:[
       
  1240 "/            org := device translatePoint:0@0 fromView:aView toView:self.
       
  1241 "/            ((org extent:aView extent) containsPoint:aPoint) ifTrue:[
       
  1242 "/                listOfViews add:aView.
       
  1243 "/            ]
       
  1244 "/        ]
       
  1245 "/    ].
  1265 "/    ].
  1246 "/
  1266 "/
  1247 "/    listOfViews size > 0 ifTrue:[
  1267 "/    view := device viewFromId:lastId.
  1248 "/        ^ listOfViews last
  1268 "/    (view isNil or:[view == self]) ifTrue:[ 
       
  1269 "/        "/ used to return nil here;
       
  1270 "/        "/ now support a mix of views and components...
       
  1271 "/        components notEmptyOrNil ifTrue:[
       
  1272 "/            component := components detect:[:c | c bounds containsPoint:aPoint] ifNone:nil.
       
  1273 "/            ^ component
       
  1274 "/        ].
       
  1275 "/        ^ nil
  1249 "/    ].
  1276 "/    ].
  1250 "/    ^ nil
  1277 "/    ^ view
  1251 "/
  1278 !
  1252 "/    "Modified: / 10.10.2001 / 14:05:07 / cg"
  1279 
  1253 "/
  1280 findObjectAt:aPoint in:aView
  1254 "/
  1281     |lastHit lastRelPoint view point|
       
  1282 
       
  1283     "/ reverse search, to find covering ones first.
       
  1284     aView subViews reverseDo:[:aSubView |
       
  1285         |innerObject relPoint|
       
  1286 
       
  1287         ((aSubView origin extent:aSubView extent) containsPoint:aPoint) ifTrue:[
       
  1288             relPoint := device translatePoint:aPoint fromView:aView toView:aSubView.
       
  1289             innerObject := self findObjectAt:relPoint in:aSubView.
       
  1290             innerObject notNil ifTrue:[ ^ innerObject ].
       
  1291             lastHit := aSubView.
       
  1292             lastRelPoint := relPoint.
       
  1293         ]
       
  1294     ].
       
  1295     view := lastHit ? aView.
       
  1296     point := lastRelPoint ? aPoint.
       
  1297 
       
  1298     view components notEmptyOrNil ifTrue:[
       
  1299         view components reverseDo:[:eachComponent |
       
  1300             (eachComponent frame containsPoint:point) ifTrue:[
       
  1301                 ^ eachComponent
       
  1302             ].
       
  1303         ].
       
  1304     ].
       
  1305     ^ view
  1255 ! !
  1306 ! !
  1256 
  1307 
  1257 !UIObjectView methodsFor:'selections'!
  1308 !UIObjectView methodsFor:'selections'!
  1258 
  1309 
  1259 hideSelection
  1310 hideSelection
  1260     "hide the selection - undraw hilights - whatever that is
  1311     "hide the selection - undraw hilights - whatever that is
  1261     "
  1312     "
  1262     self showUnselected:selection.
  1313 super hideSelection.
       
  1314 "/    self showUnselected:selection.
  1263 !
  1315 !
  1264 
  1316 
  1265 moveableSelection
  1317 moveableSelection
  1266     "checks whether the selection is not empty and all selected instances
  1318     "checks whether the selection is not empty and all selected instances
  1267      can be moved. If true the selection is returned otherwise nil
  1319      can be moved. If true the selection is returned otherwise nil
  1320 
  1372 
  1321 
  1373 
  1322 !
  1374 !
  1323 
  1375 
  1324 showSelection
  1376 showSelection
  1325     "show the selection - draw handles
  1377     "show the selection - draw handles"
  1326     "
  1378 
  1327     selectionHiddenLevel == 0 ifTrue:[
  1379     selectionHiddenLevel == 0 ifTrue:[
  1328 	self selectionDo:[:el| self showSelected:el ]
  1380         super showSelection
  1329     ].
  1381     ].
  1330 !
  1382 !
  1331 
  1383 
  1332 singleSelection
  1384 singleSelection
  1333     "checks whether a single element is selected; in this case the element is
  1385     "checks whether a single element is selected; in this case the element is
  1437     |
  1489     |
  1438     aView isInputOnly ifTrue:[^ self ].
  1490     aView isInputOnly ifTrue:[^ self ].
  1439 
  1491 
  1440     (aView shown and:[theDamages notEmpty]) ifFalse:[ ^ self ].
  1492     (aView shown and:[theDamages notEmpty]) ifFalse:[ ^ self ].
  1441 
  1493 
       
  1494     aView components notEmptyOrNil ifTrue:[ self halt ].
  1442     aView subViews notNil ifTrue:[
  1495     aView subViews notNil ifTrue:[
  1443         aView subViews reverseDo:[:v| self recursiveRepair:theDamages startIn:v ].
  1496         aView subViews reverseDo:[:v| self recursiveRepair:theDamages startIn:v ].
  1444         theDamages isEmpty ifTrue:[ ^ self ].
  1497         theDamages isEmpty ifTrue:[ ^ self ].
  1445     ].
  1498     ].
  1446 
  1499 
  1527         selection := sel
  1580         selection := sel
  1528     ]
  1581     ]
  1529 !
  1582 !
  1530 
  1583 
  1531 showUnselected:something
  1584 showUnselected:something
  1532     "show a component ot list of components unselected
  1585     "show a component or list of components unselected"
  1533     "
  1586 
  1534     |damages oldClipped|
  1587     |damages oldClipped savedSelection|
  1535 
  1588 
  1536     (selectionHiddenLevel ~~ 0 or:[something isNil]) ifTrue:[
  1589     (selectionHiddenLevel ~~ 0 or:[something isNil]) ifTrue:[
  1537         ^ self
  1590         ^ self
  1538     ].
  1591     ].
  1539 
  1592 
  1553             ].                        
  1606             ].                        
  1554             damages add:aDamage
  1607             damages add:aDamage
  1555         ]
  1608         ]
  1556     ].
  1609     ].
  1557 
  1610 
  1558     damages do:[:el| self clearRectangle:el ].
  1611     damages do:[:el| self clearRectangle:el. ].
  1559 
  1612 
  1560     (oldClipped := clipChildren) ifFalse:[
  1613     (oldClipped := clipChildren) ifFalse:[
  1561         self clippedByChildren:(clipChildren := true)
  1614         self clippedByChildren:(clipChildren := true)
  1562     ].
  1615     ].
  1563     self subViews reverseDo:[:v| self recursiveRepair:damages startIn:v].
  1616     self subViews reverseDo:[:v| self recursiveRepair:damages startIn:v].
  1564 
  1617 
  1565     oldClipped ~~ clipChildren ifTrue:[
  1618     oldClipped ~~ clipChildren ifTrue:[
  1566         self clippedByChildren:(clipChildren := oldClipped).
  1619         self clippedByChildren:(clipChildren := oldClipped).
  1567     ].
  1620     ].
  1568     device "sync" flush.
  1621 
       
  1622     device flush.
       
  1623 
       
  1624     savedSelection := selection.
       
  1625     [
       
  1626         selection := nil.
       
  1627         damages do:[:el| self invalidate:el ].
       
  1628         self repairDamage.
       
  1629     ] ensure:[
       
  1630         selection := savedSelection
       
  1631     ].
  1569 ! !
  1632 ! !
  1570 
  1633 
  1571 !UIObjectView methodsFor:'testing'!
  1634 !UIObjectView methodsFor:'testing'!
  1572 
  1635 
  1573 hasSelection
  1636 hasSelection
  1802 
  1865 
  1803 setLayout:aLayout
  1866 setLayout:aLayout
  1804     "change layout for all selected objects
  1867     "change layout for all selected objects
  1805     "
  1868     "
  1806     self transaction:#layout dimensionDo:[:v|
  1869     self transaction:#layout dimensionDo:[:v|
  1807 	v geometryLayout:(aLayout copy)
  1870         v geometryLayout:(aLayout copy)
  1808     ].    
  1871     ].    
  1809 
       
  1810 !
  1872 !
  1811 
  1873 
  1812 setToDefaultExtent
  1874 setToDefaultExtent
  1813     "change extent of all selected views to their default extent
  1875     "change extent of all selected views to their default extent
  1814     "
  1876     "