DragAndDropManager.st
changeset 3623 9ddec519a3c6
parent 3436 bf6858caeb31
child 3725 3fb5cf9108cf
equal deleted inserted replaced
3622:d07d40260d07 3623:9ddec519a3c6
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 "{ Package: 'stx:libview2' }"
    12 "{ Package: 'stx:libview2' }"
       
    13 
       
    14 "{ NameSpace: Smalltalk }"
    13 
    15 
    14 Object subclass:#DragAndDropManager
    16 Object subclass:#DragAndDropManager
    15 	instanceVariableNames:'dropContext dragView dropAction dragOffset handler restoreBlock
    17 	instanceVariableNames:'dropContext dragView dropAction dragOffset handler restoreBlock
    16 		alienCursor enabledCursor disabledCursor canDrop escapePressed
    18 		alienCursor enabledCursor disabledCursor canDrop escapePressed
    17 		passiveAction autoScrollTask disabledFlag giveFocusToTargetWidget
    19 		passiveAction autoScrollTask disabledFlag giveFocusToTargetWidget
   687 !DragAndDropManager class methodsFor:'translation'!
   689 !DragAndDropManager class methodsFor:'translation'!
   688 
   690 
   689 translatePointFromScreen:aPoint to:aView
   691 translatePointFromScreen:aPoint to:aView
   690     "translate a point from screen to view coordinates"
   692     "translate a point from screen to view coordinates"
   691 
   693 
   692     |device trans point offset|
   694     |viewsDevice trans point offset|
   693 
   695 
   694     aView isRootView ifTrue:[^ aPoint].
   696     aView isRootView ifTrue:[^ aPoint].
   695     device := aView device.
   697     viewsDevice := aView device.
   696     "/
   698     "/
   697     "/ get device coordinates
   699     "/ get device coordinates
   698     "/
   700     "/
   699     (trans := aView transformation) notNil ifTrue:[
   701     (trans := aView transformation) notNil ifTrue:[
   700         point := trans applyInverseTo:aPoint
   702         point := trans applyInverseTo:aPoint
   702         point := aPoint
   704         point := aPoint
   703     ].
   705     ].
   704     "/
   706     "/
   705     "/ translate to screen
   707     "/ translate to screen
   706     "/
   708     "/
   707     offset := device translatePoint:0@0 fromView:(device rootView) toView:aView.
   709     offset := viewsDevice translatePoint:0@0 fromView:(viewsDevice rootView) toView:aView.
   708     ^ offset + point
   710     ^ offset + point
   709 !
   711 !
   710 
   712 
   711 translatePointFromScreen:aPoint toView:aView
   713 translatePointFromScreen:aPoint toView:aView
   712     "translate a point from screen- to view coordinates"
   714     "translate a point from screen- to view coordinates"
   713 
   715 
   714     |device trans point offset|
   716     |viewsDevice trans point offset|
   715 
   717 
   716     device := aView device.
   718     viewsDevice := aView device.
   717 
   719 
   718     "/
   720     "/
   719     "/ translate to view
   721     "/ translate to view
   720     "/
   722     "/
   721     offset := device translatePoint:0@0 fromView:(device rootView) toView:aView.
   723     offset := viewsDevice translatePoint:0@0 fromView:(viewsDevice rootView) toView:aView.
   722     point := aPoint + offset.
   724     point := aPoint + offset.
   723 
   725 
   724     "/
   726     "/
   725     "/ get device coordinates
   727     "/ get device coordinates
   726     "/
   728     "/
   731 !
   733 !
   732 
   734 
   733 translatePointToScreen:aPoint from:aView
   735 translatePointToScreen:aPoint from:aView
   734     "translate a point from view- to screen coordinates"
   736     "translate a point from view- to screen coordinates"
   735 
   737 
   736     |device trans point offset|
   738     |viewsDevice trans point offset|
   737 
   739 
   738     aView isRootView ifTrue:[^ aPoint].
   740     aView isRootView ifTrue:[^ aPoint].
   739     device := aView device.
   741     viewsDevice := aView device.
   740     "/
   742     "/
   741     "/ get device coordinates
   743     "/ get device coordinates
   742     "/
   744     "/
   743     (trans := aView transformation) notNil ifTrue:[
   745     (trans := aView transformation) notNil ifTrue:[
   744         point := trans transformPoint:aPoint
   746         point := trans transformPoint:aPoint
   746         point := aPoint
   748         point := aPoint
   747     ].
   749     ].
   748     "/
   750     "/
   749     "/ translate to screen
   751     "/ translate to screen
   750     "/
   752     "/
   751     offset := device translatePoint:0@0 fromView:aView toView:(device rootView).
   753     offset := viewsDevice translatePoint:0@0 fromView:aView toView:(viewsDevice rootView).
   752     ^ offset + point
   754     ^ offset + point
   753 ! !
   755 ! !
   754 
   756 
   755 !DragAndDropManager methodsFor:'accessing'!
   757 !DragAndDropManager methodsFor:'accessing'!
   756 
   758 
  1603 !
  1605 !
  1604 
  1606 
  1605 doStart:aHandler for:aView atEnd:aFourArgEndBlock
  1607 doStart:aHandler for:aView atEnd:aFourArgEndBlock
  1606     "setup a handler and a restore block"
  1608     "setup a handler and a restore block"
  1607 
  1609 
  1608     |device lastActive windowGroup screenPoint|
  1610     |viewsDevice lastActive windowGroup screenPoint|
  1609 
  1611 
  1610     device := aView device.
  1612     viewsDevice := aView device.
  1611     lastActive := ActiveDragAndDropManagers at:device ifAbsent:nil.
  1613     lastActive := ActiveDragAndDropManagers at:viewsDevice ifAbsent:nil.
  1612 
  1614 
  1613     lastActive notNil ifTrue:[
  1615     lastActive notNil ifTrue:[
  1614         "/ self error:'oops - two dnd managers active' mayProceed:true.
  1616         "/ self error:'oops - two dnd managers active' mayProceed:true.
  1615 
  1617 
  1616         lastActive forceGiveUp.
  1618         lastActive forceGiveUp.
  1617         'DragAndDropManager [info]: oops - two dnd managers active' infoPrintCR.
  1619         'DragAndDropManager [info]: oops - two dnd managers active' infoPrintCR.
  1618     ].
  1620     ].
  1619     ActiveDragAndDropManagers at:device put:self.
  1621     ActiveDragAndDropManagers at:viewsDevice put:self.
  1620 
  1622 
  1621     dropContext sourceWidget:aView.
  1623     dropContext sourceWidget:aView.
  1622 
  1624 
  1623     dragOffset  isNil ifTrue:[ dragOffset  := 0 @ 0 ].
  1625     dragOffset  isNil ifTrue:[ dragOffset  := 0 @ 0 ].
  1624     alienCursor isNil ifTrue:[ alienCursor := disabledCursor ].
  1626     alienCursor isNil ifTrue:[ alienCursor := disabledCursor ].
  1642             autoScrollTask notNil ifTrue:[
  1644             autoScrollTask notNil ifTrue:[
  1643                 autoScrollTask terminate.
  1645                 autoScrollTask terminate.
  1644                 autoScrollTask := nil.
  1646                 autoScrollTask := nil.
  1645             ].
  1647             ].
  1646 
  1648 
  1647             ActiveDragAndDropManagers removeKey:device ifAbsent:nil.
  1649             ActiveDragAndDropManagers removeKey:viewsDevice ifAbsent:nil.
  1648             escapePressed ifFalse:[ aHandler postDragging ].
  1650             escapePressed ifFalse:[ aHandler postDragging ].
  1649 
  1651 
  1650             windowGroup removePreEventHook:self.
  1652             windowGroup removePreEventHook:self.
  1651             windowGroup removePostEventHook:self.
  1653             windowGroup removePostEventHook:self.
  1652             dragView cursor:savedCursor.
  1654             dragView cursor:savedCursor.
  1654             self triggerEndOfDropAction.
  1656             self triggerEndOfDropAction.
  1655         ].
  1657         ].
  1656     aHandler preDraggingIn:dragView.
  1658     aHandler preDraggingIn:dragView.
  1657 
  1659 
  1658     "/ must wait for all pending motion events to arrive, and ignore them
  1660     "/ must wait for all pending motion events to arrive, and ignore them
  1659     device sync.        
  1661     viewsDevice sync.        
  1660     dragView sensor flushMotionEventsFor:nil.
  1662     dragView sensor flushMotionEventsFor:nil.
  1661 
  1663 
  1662     autoScrollTask := 
  1664     autoScrollTask := 
  1663         [
  1665         [
  1664             [   |sensor|
  1666             [   |sensor|
  1680     autoScrollTask priority:(Processor userSchedulingPriority).
  1682     autoScrollTask priority:(Processor userSchedulingPriority).
  1681     autoScrollTask name:'Drag-AutoScroll'.
  1683     autoScrollTask name:'Drag-AutoScroll'.
  1682     autoScrollTask resume.
  1684     autoScrollTask resume.
  1683 
  1685 
  1684     "/ start with a first draw at the current mouse position
  1686     "/ start with a first draw at the current mouse position
  1685     screenPoint := device pointerPosition.
  1687     screenPoint := viewsDevice pointerPosition.
  1686     self buttonMotion:1 x:(screenPoint x) y:(screenPoint y) view:(device rootView).
  1688     self buttonMotion:1 x:(screenPoint x) y:(screenPoint y) view:(viewsDevice rootView).
  1687 !
  1689 !
  1688 
  1690 
  1689 forceGiveUp
  1691 forceGiveUp
  1690     "called if the DragAndDropManager no longer should be
  1692     "called if the DragAndDropManager no longer should be
  1691      active; a second one is started"
  1693      active; a second one is started"
  1714 ! !
  1716 ! !
  1715 
  1717 
  1716 !DragAndDropManager class methodsFor:'documentation'!
  1718 !DragAndDropManager class methodsFor:'documentation'!
  1717 
  1719 
  1718 version
  1720 version
  1719     ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.94 2014-12-21 23:33:02 cg Exp $'
  1721     ^ '$Header$'
  1720 !
  1722 !
  1721 
  1723 
  1722 version_CVS
  1724 version_CVS
  1723     ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.94 2014-12-21 23:33:02 cg Exp $'
  1725     ^ '$Header$'
  1724 ! !
  1726 ! !
  1725 
  1727 
  1726 
  1728 
  1727 DragAndDropManager initialize!
  1729 DragAndDropManager initialize!