ObjectView.st
changeset 2435 a47df77ac405
parent 2381 ba992e7f3929
child 2449 b9bf97bf089d
equal deleted inserted replaced
2434:a9b9d8f2ab5b 2435:a47df77ac405
   630 endLineDrag
   630 endLineDrag
   631     "cleanup after line drag; select them. Find the origin and destination
   631     "cleanup after line drag; select them. Find the origin and destination
   632      views and relative offsets, then dispatch to one of the endLineDrag methods.
   632      views and relative offsets, then dispatch to one of the endLineDrag methods.
   633      These can be redefined in subclasses to allow connect between views."
   633      These can be redefined in subclasses to allow connect between views."
   634 
   634 
   635     |rootPoint viewId offs 
   635     |rootPoint viewId offs transformation2
   636      lastViewId destinationId destinationView destinationPoint inMySelf|
   636      lastViewId destinationId destinationView destinationPoint 
       
   637      inMySelf dragOrigin|
   637 
   638 
   638     self invertDragLine.
   639     self invertDragLine.
   639 
   640 
   640     self cursor:oldCursor.
   641     self cursor:oldCursor.
   641 
   642 
   646          get device coordinates
   647          get device coordinates
   647         "
   648         "
   648         transformation notNil ifTrue:[
   649         transformation notNil ifTrue:[
   649             rootPoint := transformation applyTo:rootPoint.
   650             rootPoint := transformation applyTo:rootPoint.
   650         ].
   651         ].
   651         viewId := rootView id.
       
   652 
   652 
   653         "
   653         "
   654          translate to screen
   654          translate to screen
   655         "
   655         "
   656         offs := device translatePoint:0@0 from:(self id) to:viewId.
   656         offs := device translatePoint:0@0 fromView:self toView:rootView.
   657         rootPoint := rootPoint + offs.
   657         rootPoint := rootPoint + offs.
   658 
   658 
   659         "search view the drop is in"
   659         "search view the drop is in"
   660 
   660         viewId := rootView id.
   661         [viewId notNil] whileTrue:[
   661         [viewId notNil] whileTrue:[
   662             destinationId := device viewIdFromPoint:rootPoint in:viewId.
   662             destinationId := device viewIdFromPoint:rootPoint in:viewId.
   663             lastViewId := viewId.
   663             lastViewId := viewId.
   664             viewId := destinationId
   664             viewId := destinationId
   665         ].
   665         ].
   669         rootMotion := false
   669         rootMotion := false
   670     ] ifFalse:[
   670     ] ifFalse:[
   671         inMySelf := true
   671         inMySelf := true
   672     ].
   672     ].
   673 
   673 
       
   674     dragOrigin := dragObject origin.
   674     inMySelf ifTrue:[
   675     inMySelf ifTrue:[
   675         "a simple line within myself"
   676         "a simple line within myself"
   676         self lineDragFrom:dragObject origin to:dragObject corner
   677         self lineDragFrom:dragOrigin to:dragObject corner
   677     ] ifFalse:[
   678     ] ifFalse:[
   678         "into another one"
   679         "into another one"
   679         destinationView notNil ifTrue:[
   680         destinationView notNil ifTrue:[
   680             destinationPoint := device translatePoint:rootPoint from:(rootView id) to:(destinationView id).
   681             destinationPoint := device translatePoint:rootPoint fromView:rootView toView:destinationView.
   681             destinationView transformation notNil ifTrue:[
   682             (transformation2 := destinationView transformation) notNil ifTrue:[
   682                 destinationPoint := destinationView transformation applyInverseTo:destinationPoint
   683                 destinationPoint := transformation2 applyInverseTo:destinationPoint
   683             ].
   684             ].
   684             "
   685             "
   685              move into another smalltalk view
   686              move into another smalltalk view
   686             "
   687             "
   687             self lineDragFrom:dragObject origin to:destinationPoint in:destinationView
   688             self lineDragFrom:dragOrigin to:destinationPoint in:destinationView
   688         ] ifFalse:[
   689         ] ifFalse:[
   689             "
   690             "
   690              not one of my views
   691              not one of my views
   691             "
   692             "
   692             self lineDragFrom:dragObject origin
   693             self lineDragFrom:dragOrigin to:destinationPoint inAlienViewId:destinationId
   693                            to:destinationPoint 
       
   694                            inAlienViewId:destinationId
       
   695         ] 
   694         ] 
   696     ].
   695     ].
   697     self setDefaultActions.
   696     self setDefaultActions.
   698     dragObject := nil
   697     dragObject := nil
       
   698 
       
   699     "Modified: / 10.10.2001 / 14:41:52 / cg"
   699 !
   700 !
   700 
   701 
   701 invertDragLine
   702 invertDragLine
   702     "helper for line dragging - invert the dragged line.
   703     "helper for line dragging - invert the dragged line.
   703      Extracted for easier redefinition in subclasses
   704      Extracted for easier redefinition in subclasses
   717             p2 := transformation applyTo:p2.
   718             p2 := transformation applyTo:p2.
   718         ].
   719         ].
   719         "
   720         "
   720          translate to screen
   721          translate to screen
   721         "
   722         "
   722         offs := device translatePoint:0@0 from:(self id) to:(rootView id).
   723         offs := device translatePoint:0@0 fromView:self toView:rootView.
   723         p1 := p1 + offs.
   724         p1 := p1 + offs.
   724         p2 := p2 + offs.
   725         p2 := p2 + offs.
   725     ] ifFalse:[
   726     ] ifFalse:[
   726         dragger := self.
   727         dragger := self.
   727     ].
   728     ].
   730         dragger lineWidth:0. 
   731         dragger lineWidth:0. 
   731         dragger displayLineFrom:p1 to:p2.
   732         dragger displayLineFrom:p1 to:p2.
   732         dragger flush
   733         dragger flush
   733     ].
   734     ].
   734 
   735 
   735     "Modified: 16.12.1995 / 17:32:56 / cg"
   736     "Modified: / 10.10.2001 / 13:59:05 / cg"
   736 !
   737 !
   737 
   738 
   738 lineDragFrom:startPoint to:endPoint
   739 lineDragFrom:startPoint to:endPoint
   739     "this is called after a line-drag. Nothing is done here.
   740     "this is called after a line-drag. Nothing is done here.
   740      - should be redefined in subclasses"
   741      - should be redefined in subclasses"
   837     "cleanup after object move - called when the object move ends.
   838     "cleanup after object move - called when the object move ends.
   838      Find the destination view and position and dispatch to
   839      Find the destination view and position and dispatch to
   839      one of the moveObjectXXX-methods which should do the real move. 
   840      one of the moveObjectXXX-methods which should do the real move. 
   840      These can be redefined in subclasses."
   841      These can be redefined in subclasses."
   841 
   842 
   842     |inMySelf rootPoint destinationPoint p
   843     |inMySelf rootPoint destinationPoint p transformation2
   843      viewId destinationView destinationId lastViewId|
   844      viewId destinationView destinationId lastViewId|
   844 
   845 
   845     movedObject notNil ifTrue:[
   846     movedObject notNil ifTrue:[
   846 	self invertDragObject:movedObject delta:moveDelta.    
   847         self invertDragObject:movedObject delta:moveDelta.    
   847 
   848 
   848 	"check if object is to be put into another view"
   849         "check if object is to be put into another view"
   849 	rootMotion ifTrue:[
   850         rootMotion ifTrue:[
   850 	    p := lastButt.
   851             p := lastButt.
   851 	    "
   852             "
   852 	     get device coordinates
   853              get device coordinates
   853 	    "
   854             "
   854 	    transformation notNil ifTrue:[
   855             transformation notNil ifTrue:[
   855 		p := transformation applyTo:p.
   856                 p := transformation applyTo:p.
   856 	    ].
   857             ].
   857 	    viewId := rootView id.
   858             "
   858 	    "
   859              translate to screen
   859 	     translate to screen
   860             "
   860 	    "
   861             rootPoint := p + (device translatePoint:0@0 fromView:self toView:rootView).
   861 	    rootPoint := p + (device translatePoint:0@0 from:(self id) to:viewId).
   862 
   862 
   863             "search view the drop is in"
   863 	    "search view the drop is in"
   864             viewId := rootView id.
   864 	    [viewId notNil] whileTrue:[
   865             [viewId notNil] whileTrue:[
   865 		destinationId := device viewIdFromPoint:rootPoint in:viewId.
   866                 destinationId := device viewIdFromPoint:rootPoint in:viewId.
   866 		lastViewId := viewId.
   867                 lastViewId := viewId.
   867 		viewId := destinationId
   868                 viewId := destinationId
   868 	    ].
   869             ].
   869 	    destinationView := device viewFromId:lastViewId.
   870             destinationView := device viewFromId:lastViewId.
   870 	    destinationId := lastViewId.
   871             destinationId := lastViewId.
   871 	    inMySelf := (destinationView == self).
   872             inMySelf := (destinationView == self).
   872 	    rootMotion := false
   873             rootMotion := false
   873 	] ifFalse:[
   874         ] ifFalse:[
   874 	    inMySelf := true
   875             inMySelf := true
   875 	].
   876         ].
   876 
   877 
   877 	inMySelf ifTrue:[
   878         inMySelf ifTrue:[
   878 	    "simple move"
   879             "simple move"
   879 	    self move:movedObject by:moveDelta
   880             self move:movedObject by:moveDelta
   880 	] ifFalse:[
   881         ] ifFalse:[
   881 	    destinationPoint := device translatePoint:rootPoint
   882             destinationPoint := device translatePoint:rootPoint        "/ use id here - could be alian view
   882 						 from:(rootView id) 
   883                                                  from:(rootView id) 
   883 						   to:destinationId.
   884                                                    to:destinationId.
   884 	    destinationView notNil ifTrue:[
   885             destinationView notNil ifTrue:[
   885 		destinationView transformation notNil ifTrue:[
   886                 (transformation2 := destinationView transformation) notNil ifTrue:[
   886 		    destinationPoint := destinationView transformation applyInverseTo:destinationPoint
   887                     destinationPoint := transformation2 applyInverseTo:destinationPoint
   887 		].
   888                 ].
   888 		"
   889                 "
   889 		 move into another smalltalk view
   890                  move into another smalltalk view
   890 		"
   891                 "
   891 		self move:movedObject to:destinationPoint in:destinationView
   892                 self move:movedObject to:destinationPoint in:destinationView
   892 	    ] ifFalse:[
   893             ] ifFalse:[
   893 		"
   894                 "
   894 		 not one of my views
   895                  not one of my views
   895 		"
   896                 "
   896 		self move:movedObject to:destinationPoint inAlienViewId:destinationId
   897                 self move:movedObject to:destinationPoint inAlienViewId:destinationId
   897 	    ] 
   898             ] 
   898 	].
   899         ].
   899 	self setDefaultActions.
   900         self setDefaultActions.
   900 	movedObject := nil
   901         movedObject := nil
   901     ]
   902     ]
       
   903 
       
   904     "Modified: / 10.10.2001 / 14:43:09 / cg"
   902 !
   905 !
   903 
   906 
   904 invertDragObject:movedObject delta:moveDelta
   907 invertDragObject:movedObject delta:moveDelta
   905     "draw inverting for an object move"
   908     "draw inverting for an object move"
   906 
   909 
   919 "/ 'device ' print. p printNL.
   922 "/ 'device ' print. p printNL.
   920         ].
   923         ].
   921         "
   924         "
   922          translate to screen
   925          translate to screen
   923         "
   926         "
   924         offs := device translatePoint:0@0 from:(self id) to:(rootView id).
   927         offs := device translatePoint:0@0 fromView:self toView:rootView.
   925 "/ 'offs' print. offs printNL.
   928 "/ 'offs' print. offs printNL.
   926         p := p + offs.
   929         p := p + offs.
   927 "/ 'screen ' print. p printNL.
   930 "/ 'screen ' print. p printNL.
   928         "
   931         "
   929          p is where we want it ...
   932          p is where we want it ...
   951             self showDragging:movedObject offset:moveDelta.
   954             self showDragging:movedObject offset:moveDelta.
   952         ].
   955         ].
   953         self flush
   956         self flush
   954     ].
   957     ].
   955 
   958 
   956     "Modified: 16.12.1995 / 17:33:04 / cg"
   959     "Modified: / 10.10.2001 / 13:59:19 / cg"
   957 !
   960 !
   958 
   961 
   959 setMoveActions
   962 setMoveActions
   960     "setup to drag an object. Call this (for example) from your buttonPress
   963     "setup to drag an object. Call this (for example) from your buttonPress
   961      method, to make the view start to drag some object.
   964      method, to make the view start to drag some object.
  3241 ! !
  3244 ! !
  3242 
  3245 
  3243 !ObjectView class methodsFor:'documentation'!
  3246 !ObjectView class methodsFor:'documentation'!
  3244 
  3247 
  3245 version
  3248 version
  3246     ^ '$Header: /cvs/stx/stx/libwidg/ObjectView.st,v 1.87 2001-07-10 18:57:07 cg Exp $'
  3249     ^ '$Header: /cvs/stx/stx/libwidg/ObjectView.st,v 1.88 2001-10-10 13:40:15 cg Exp $'
  3247 ! !
  3250 ! !