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 |
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. |
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" |