DragRectangleController.st
author Jan Vrany <jan.vrany@labware.com>
Fri, 12 Aug 2022 22:38:28 +0100
branchjv
changeset 6857 58d68f671fa1
parent 6039 5db22cb319e3
child 6087 0c7c2f8ebcb8
permissions -rw-r--r--
cherry-picked GenericToolbarIconLibrary.st from 020158c929bb: * 4ecbe3a93aec: Merge, HG Automerge * 8e9dcb2a6533: #REFACTORING by cg, Claus Gittinger <cg@exept.de> * 58d88b144b2b: Merge, HG Automerge * 33c75b4a9999: #REFACTORING by mawalch, mawalch * 74f6a697ee26: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 7b8ba07cb680: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 0122e4e6c587: #FEATURE by cg, Claus Gittinger <cg@exept.de> * e296fa4b5ccb: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 6db292aae07d: #OTHER by mawalch, mawalch * 4366b65a2c8a: Copyright updates, Jan Vrany <jan.vrany@fit.cvut.cz> * 6b79d8bfdcd9: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 6a0103018ab9: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 87fbb0b00ca6: #REFACTORING by cg, Claus Gittinger <cg@exept.de> * 5c977f62957a: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 0ccfd6c3c75f: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 3926b9ae0a3c: #BUGFIX by cg, Claus Gittinger <cg@exept.de> * 8cebd063aeb5: #REFACTORING by cg, Claus Gittinger <cg@exept.de> * 5445f50f8b2b: #REFACTORING by cg, Claus Gittinger <cg@exept.de> * 272618940466: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 56bd6e2384a4: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * ffa93f79e6ae: #DOCUMENTATION by cg, Claus Gittinger <cg@exept.de> * 9410312a11cb: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 0036104e42ed: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 21fad03d5f11: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 8fd99a9d1d84: #REFACTORING by cg, Claus Gittinger <cg@exept.de> * e4ed7fc09ca1: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 2c79a677e38a: #BUGFIX by cg, Claus Gittinger <cg@exept.de> * 81227f5c6bfa: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * a7d893a3c1e1: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 7928d87ff963: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 6ed15ff79b07: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * a1a9e33d6daf: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 07f0100f7064: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 23d027d53e04: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 823ff944a2a5: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 046733c3db59: #REFACTORING by exept, Claus Gittinger <cg@exept.de> * 040921add07a: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 5777bb6431cb: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 27448b51c873: #FEATURE by exept, Claus Gittinger <cg@exept.de> * 1309dd75d7f5: #FEATURE by exept, Claus Gittinger <cg@exept.de> * 6415731ee5e5: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * c7802dbb6d7d: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 23bf1e00dc95: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 645f74e46f86: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 236c24a6ce6c: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 8db4c188c57a: #REFACTORING by exept, Claus Gittinger <cg@exept.de> * 5d1367f2f32a: #BUGFIX by exept, Claus Gittinger <cg@exept.de> * e012b62927a6: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * cec8de8d957c: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 8e9b8e68a545: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 5274979b30fb: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 73e483e60e05: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * dc6e33c97410: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 041ace9885e8: #TUNING by cg, Claus Gittinger <cg@exept.de> * bdfd1b407c29: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 52afc5fcc948: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * f9c23ed981dc: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 2678c19d0794: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 043c6c163b4f: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 5e779e09b004: version method, Claus Gittinger <cg@exept.de> * 51394e1ee44c: #FEATURE by exept, Claus Gittinger <cg@exept.de> * c6a190f66fb7: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 34b9831cd1ee: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 3fa783b7f48d: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * b46f5a561997: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 3bedf44e10d1: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * d0ccad2a39b8: #FEATURE by exept, Claus Gittinger <cg@exept.de> * 20f0d7ec75e0: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 86c9b274be4e: #FEATURE by stefan, Stefan Vogel <sv@exept.de> * 4c58992375bb: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 4facc54a9585: #OTHER by exept, Claus Gittinger <cg@exept.de> * d9b1c96aa2b8: #REFACTORING by exept, Claus Gittinger <cg@exept.de> * de0b89624b00: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 8d5a93082103: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * c06c9bee59db: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de>

"
 COPYRIGHT (c) 2017 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libwidg' }"

"{ NameSpace: Smalltalk }"

ButtonController subclass:#DragRectangleController
	instanceVariableNames:'action startPoint lastX lastY'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Support-Controllers'
!

!DragRectangleController class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2017 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    drags a rectangle
"
!

examples
"
    |v c|

    v := View new openAndWait.
    c := DragRectangleController new.
    c action:[:rect | Transcript showCR:rect ].
    v openAndWait.
    
    v controller:c.
"
! !

!DragRectangleController class methodsFor:'utilities'!

dragRectangleIn:aView thenDo:action
    "drag a rectangle in aView"
    
    |dragController oldController oldCursor|
    
    dragController := DragRectangleController new.
    dragController view:aView.
    oldController := aView controller.
    oldCursor := aView cursor.

    aView cursor:Cursor origin.
    dragController action:[:rectOrNil |
        |image|

        aView controller:oldController.
        aView cursor:oldCursor.
        action value:rectOrNil.
    ].
    
    aView controller:dragController.
! !

!DragRectangleController methodsFor:'accessing'!

action:aBlock
    "set the block which will be called when the rectangle drag is finished.
     The block will be called with a nil arg, if escape is pressed"
     
    action := aBlock
!

lastMousePoint
    lastX isNil ifTrue:[^ nil].
    ^ lastX @ lastY
!

startPoint
    ^ startPoint
! !

!DragRectangleController methodsFor:'event handling'!

buttonMotion:buttonState x:x y:y
    (buttonState == 0 or:[startPoint isNil]) ifTrue:[
        super buttonMotion:buttonState x:x y:y.
        ^ self
    ].
    
    lastX notNil ifTrue:[
        view xoring:[
            view displayRectangle:(startPoint corner:(lastX@lastY))
        ].
    ].
    
    lastX := x.
    lastY := y.

    startPoint ~= (x@y) ifTrue:[
        view xoring:[
            view displayRectangle:(startPoint corner:(lastX@lastY))
        ].
    ].
!

buttonPress:button x:x y:y
    startPoint := x@y.
    view cursor:(Cursor corner).
!

buttonRelease:button x:x y:y
    |rect|
    
    startPoint isNil ifTrue:[
        super buttonRelease:button x:x y:y.
        ^ self
    ].

    lastX notNil ifTrue:[
        view xoring:[
            view displayRectangle:(startPoint corner:(lastX@lastY))
        ].
    ].
    rect := startPoint corner:(lastX@lastY).
    startPoint := lastX := lastY := nil.
    action value:rect.
!

keyPress:key x:x y:y
    startPoint isNil ifTrue:[
        super keyPress:key x:x y:y.
        ^ self
    ].

    lastX notNil ifTrue:[
        view xoring:[
            view displayRectangle:(startPoint corner:(lastX@lastY))
        ].
    ].

    startPoint := nil.
    action value:nil.
! !

!DragRectangleController class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !