DragAndDropManager.st
author Claus Gittinger <cg@exept.de>
Sat, 26 Oct 1996 18:49:55 +0200
changeset 343 3a611a1f882d
parent 342 7563cbf04502
child 345 626e8241dc76
permissions -rw-r--r--
*** empty log message ***

Object subclass:#DragAndDropManager
	instanceVariableNames:'dragView motionAction releaseAction initialPoint previousPoint
		rememberedDelegate dragBlock lineMode'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Support'
!

View subclass:#DemoView3
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	privateIn:DragAndDropManager
!

View subclass:#DemoView2
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	privateIn:DragAndDropManager
!

View subclass:#DemoView
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	privateIn:DragAndDropManager
!

!DragAndDropManager class methodsFor:'documentation'!

history

    "Created: 26.10.1996 / 15:02:00 / cg"
    "Modified: 26.10.1996 / 15:21:42 / cg"
! !

!DragAndDropManager methodsFor:'dragging - generic'!

doGenericDragX:x y:y
    previousPoint notNil ifTrue:[
        self invertGenericAt:previousPoint
    ].
    previousPoint := x @ y.
    self invertGenericAt:previousPoint

    "Modified: 26.10.1996 / 15:16:59 / cg"
!

endGenericDragX:x y:y
    previousPoint notNil ifTrue:[
        self invertGenericAt:previousPoint
    ].
    previousPoint := nil.
    self uncatchEvents

    "Created: 26.10.1996 / 15:17:20 / cg"
    "Modified: 26.10.1996 / 15:22:41 / cg"
!

invertGenericAt:ip
    |t offs p rootView|

    rootView := dragView device rootView.

    p := ip.

    "
     get device coordinates
    "
    (t := dragView transformation) notNil ifTrue:[
        p := t applyTo:p.
    ].

    "
     translate to screen
    "
    offs := dragView device 
                translatePoint:0@0 
                from:(dragView id) to:(rootView id).
    p := p + offs.

    rootView clippedByChildren:false.
    rootView xoring:[
        rootView lineWidth:0. 
        dragBlock value:p.
        rootView flush
    ].

    "Created: 26.10.1996 / 15:15:26 / cg"
    "Modified: 26.10.1996 / 15:27:09 / cg"
!

setupForGenericDragFrom:aView at:p into:aBlock
    self catchEventsFrom:aView.
    motionAction := #doGenericDragX:y:.
    releaseAction := #endGenericDragX:y:.
    initialPoint := p.
    previousPoint := nil.
    dragBlock := aBlock.

    "Modified: 26.10.1996 / 15:09:26 / cg"
    "Created: 26.10.1996 / 15:16:13 / cg"
! !

!DragAndDropManager methodsFor:'dragging - lines'!

doLineDragX:x y:y
    previousPoint notNil ifTrue:[
        self invertLineFrom:initialPoint to:previousPoint
    ].
    previousPoint := x @ y.
    self invertLineFrom:initialPoint to:previousPoint

    "Modified: 26.10.1996 / 15:16:59 / cg"
!

endLineDragX:x y:y
    previousPoint notNil ifTrue:[
        self invertLineFrom:initialPoint to:previousPoint
    ].
    previousPoint := nil.
    self uncatchEvents

    "Created: 26.10.1996 / 15:17:20 / cg"
    "Modified: 26.10.1996 / 15:22:41 / cg"
!

invertLineFrom:ip1 to:ip2
    |t offs p1 p2 rootView a|

    rootView := dragView device rootView.

    p1 := ip1.
    p2 := ip2.

    "
     get device coordinates
    "
    (t := dragView transformation) notNil ifTrue:[
        p1 := t applyTo:p1.
        p2 := t applyTo:p2.
    ].

    "
     translate to screen
    "
    offs := dragView device 
                translatePoint:0@0 
                from:(dragView id) to:(rootView id).
    p1 := p1 + offs.
    p2 := p2 + offs.

    rootView clippedByChildren:false.
    rootView xoring:[
        rootView lineWidth:0. 
        lineMode == #arrow ifTrue:[
            a := Arrow from:p1 to:p2.
            a arrowHeadLength:(rootView device horizontalPixelPerMillimeter * 4) rounded.
            a displayFilledOn:rootView.
        ] ifFalse:[
            rootView displayLineFrom:p1 to:p2.
        ].
        rootView flush
    ].

    "Created: 26.10.1996 / 15:15:26 / cg"
    "Modified: 26.10.1996 / 15:27:09 / cg"
!

setupForArrowDragFrom:aView at:p
    self catchEventsFrom:aView.
    motionAction := #doLineDragX:y:.
    releaseAction := #endLineDragX:y:.
    initialPoint := p.
    previousPoint := nil.
    dragBlock := nil.
    lineMode := #arrow.

    "Modified: 26.10.1996 / 15:09:26 / cg"
    "Created: 26.10.1996 / 15:16:13 / cg"
!

setupForLineDragFrom:aView at:p
    self catchEventsFrom:aView.
    motionAction := #doLineDragX:y:.
    releaseAction := #endLineDragX:y:.
    initialPoint := p.
    previousPoint := nil.
    dragBlock := nil.
    lineMode := nil.

    "Modified: 26.10.1996 / 15:09:26 / cg"
    "Created: 26.10.1996 / 15:16:13 / cg"
! !

!DragAndDropManager methodsFor:'event catching'!

buttonMotion:button x:x y:y view:aView
    self perform:motionAction with:x with:y

    "Created: 26.10.1996 / 15:09:00 / cg"
!

buttonRelease:button x:x y:y view:aView
    self perform:releaseAction with:x with:y

    "Created: 26.10.1996 / 15:09:14 / cg"
!

handlesButtonMotion:button inView:aView
    "query from event processor: am I interested in button-events ?
     yes I am (to activate the clicked-on field)."

    ^ aView == dragView

    "Created: 26.10.1996 / 15:05:36 / cg"
!

handlesButtonRelease:button inView:aView
    "query from event processor: am I interested in button-events ?
     yes I am (to activate the clicked-on field)."

    ^ aView == dragView

    "Created: 26.10.1996 / 15:05:48 / cg"
! !

!DragAndDropManager methodsFor:'private'!

catchEventsFrom:aView
    dragView := aView.
    rememberedDelegate := aView delegate.
    aView delegate:self

    "Created: 26.10.1996 / 15:03:12 / cg"
    "Modified: 26.10.1996 / 15:21:57 / cg"
!

uncatchEvents
    dragView delegate:rememberedDelegate.
    dragView := nil.

    "Created: 26.10.1996 / 15:22:29 / cg"
! !

!DragAndDropManager::DemoView3 methodsFor:'events'!

buttonPress:button x:x y:y
    DragAndDropManager new
        setupForArrowDragFrom:self at:(x@y)

    "
     self new open
    "
! !

!DragAndDropManager::DemoView2 methodsFor:'events'!

buttonPress:button x:x y:y
    DragAndDropManager new
        setupForGenericDragFrom:self at:(x@y) into:[:p | device rootView displayString:'hello' at:p]

    "
     self new open
    "


! !

!DragAndDropManager::DemoView methodsFor:'events'!

buttonPress:button x:x y:y
    DragAndDropManager new
        setupForLineDragFrom:self at:(x@y)

    "
     self new open
    "
! !

!DragAndDropManager class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.3 1996-10-26 16:49:55 cg Exp $'
! !