DragAndDropManager.st
changeset 341 5afe98e6185b
child 342 7563cbf04502
equal deleted inserted replaced
340:0e8959b8a9cf 341:5afe98e6185b
       
     1 Object subclass:#DragAndDropManager
       
     2 	instanceVariableNames:'dragView motionAction releaseAction initialPoint previousPoint
       
     3 		rememberedDelegate'
       
     4 	classVariableNames:''
       
     5 	poolDictionaries:''
       
     6 	category:'Interface-Support'
       
     7 !
       
     8 
       
     9 View subclass:#DragAndDropTestClass
       
    10 	instanceVariableNames:''
       
    11 	classVariableNames:''
       
    12 	poolDictionaries:''
       
    13 	privateIn:DragAndDropManager
       
    14 !
       
    15 
       
    16 !DragAndDropManager class methodsFor:'documentation'!
       
    17 
       
    18 history
       
    19 
       
    20     "Created: 26.10.1996 / 15:02:00 / cg"
       
    21     "Modified: 26.10.1996 / 15:21:42 / cg"
       
    22 ! !
       
    23 
       
    24 !DragAndDropManager privateMethodsFor:'dragging - lines'!
       
    25 
       
    26 doLineDragX:x y:y
       
    27     previousPoint notNil ifTrue:[
       
    28         self invertLineFrom:initialPoint to:previousPoint
       
    29     ].
       
    30     previousPoint := x @ y.
       
    31     self invertLineFrom:initialPoint to:previousPoint
       
    32 
       
    33     "Modified: 26.10.1996 / 15:16:59 / cg"
       
    34 !
       
    35 
       
    36 endLineDragX:x y:y
       
    37     previousPoint notNil ifTrue:[
       
    38         self invertLineFrom:initialPoint to:previousPoint
       
    39     ].
       
    40     previousPoint := nil.
       
    41     self uncatchEvents
       
    42 
       
    43     "Created: 26.10.1996 / 15:17:20 / cg"
       
    44     "Modified: 26.10.1996 / 15:22:41 / cg"
       
    45 !
       
    46 
       
    47 invertLineFrom:ip1 to:ip2
       
    48     |t offs p1 p2 rootView|
       
    49 
       
    50     rootView := dragView device rootView.
       
    51 
       
    52     p1 := ip1.
       
    53     p2 := ip2.
       
    54 
       
    55     "
       
    56      get device coordinates
       
    57     "
       
    58     (t := dragView transformation) notNil ifTrue:[
       
    59         p1 := t applyTo:p1.
       
    60         p2 := t applyTo:p2.
       
    61     ].
       
    62 
       
    63     "
       
    64      translate to screen
       
    65     "
       
    66     offs := dragView device 
       
    67                 translatePoint:0@0 
       
    68                 from:(dragView id) to:(rootView id).
       
    69     p1 := p1 + offs.
       
    70     p2 := p2 + offs.
       
    71 
       
    72     rootView clippedByChildren:false.
       
    73     rootView xoring:[
       
    74         rootView lineWidth:0. 
       
    75         rootView displayLineFrom:p1 to:p2.
       
    76         rootView flush
       
    77     ].
       
    78 
       
    79     "Created: 26.10.1996 / 15:15:26 / cg"
       
    80     "Modified: 26.10.1996 / 15:27:09 / cg"
       
    81 ! !
       
    82 
       
    83 !DragAndDropManager methodsFor:'dragging - lines'!
       
    84 
       
    85 setupForLineDragFrom:aView at:p
       
    86     self catchEventsFrom:aView.
       
    87     motionAction := #doLineDragX:y:.
       
    88     releaseAction := #endLineDragX:y:.
       
    89     initialPoint := p.
       
    90     previousPoint := nil
       
    91 
       
    92     "Modified: 26.10.1996 / 15:09:26 / cg"
       
    93     "Created: 26.10.1996 / 15:16:13 / cg"
       
    94 ! !
       
    95 
       
    96 !DragAndDropManager methodsFor:'event catching'!
       
    97 
       
    98 buttonMotion:button x:x y:y view:aView
       
    99     self perform:motionAction with:x with:y
       
   100 
       
   101     "Created: 26.10.1996 / 15:09:00 / cg"
       
   102 !
       
   103 
       
   104 buttonRelease:button x:x y:y view:aView
       
   105     self perform:releaseAction with:x with:y
       
   106 
       
   107     "Created: 26.10.1996 / 15:09:14 / cg"
       
   108 !
       
   109 
       
   110 handlesButtonMotion:button inView:aView
       
   111     "query from event processor: am I interested in button-events ?
       
   112      yes I am (to activate the clicked-on field)."
       
   113 
       
   114     ^ aView == dragView
       
   115 
       
   116     "Created: 26.10.1996 / 15:05:36 / cg"
       
   117 !
       
   118 
       
   119 handlesButtonRelease:button inView:aView
       
   120     "query from event processor: am I interested in button-events ?
       
   121      yes I am (to activate the clicked-on field)."
       
   122 
       
   123     ^ aView == dragView
       
   124 
       
   125     "Created: 26.10.1996 / 15:05:48 / cg"
       
   126 ! !
       
   127 
       
   128 !DragAndDropManager methodsFor:'private'!
       
   129 
       
   130 catchEventsFrom:aView
       
   131     dragView := aView.
       
   132     rememberedDelegate := aView delegate.
       
   133     aView delegate:self
       
   134 
       
   135     "Created: 26.10.1996 / 15:03:12 / cg"
       
   136     "Modified: 26.10.1996 / 15:21:57 / cg"
       
   137 !
       
   138 
       
   139 uncatchEvents
       
   140     dragView delegate:rememberedDelegate.
       
   141     dragView := nil.
       
   142 
       
   143     "Created: 26.10.1996 / 15:22:29 / cg"
       
   144 ! !
       
   145 
       
   146 !DragAndDropManager::DragAndDropTestClass methodsFor:'events'!
       
   147 
       
   148 buttonPress:button x:x y:y
       
   149     DragAndDropManager new
       
   150         setupForLineDragFrom:self at:(x@y)
       
   151 
       
   152     "
       
   153      self new open
       
   154     "
       
   155 ! !
       
   156 
       
   157 !DragAndDropManager class methodsFor:'documentation'!
       
   158 
       
   159 version
       
   160     ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.1 1996-10-26 14:40:21 cg Exp $'
       
   161 ! !