6039
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2017 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libwidg' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
ButtonController subclass:#DragRectangleController
|
|
17 |
instanceVariableNames:'action startPoint lastX lastY'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Interface-Support-Controllers'
|
|
21 |
!
|
|
22 |
|
|
23 |
!DragRectangleController class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2017 by eXept Software AG
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
drags a rectangle
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
examples
|
|
46 |
"
|
|
47 |
|v c|
|
|
48 |
|
|
49 |
v := View new openAndWait.
|
|
50 |
c := DragRectangleController new.
|
|
51 |
c action:[:rect | Transcript showCR:rect ].
|
|
52 |
v openAndWait.
|
|
53 |
|
|
54 |
v controller:c.
|
|
55 |
"
|
|
56 |
! !
|
|
57 |
|
|
58 |
!DragRectangleController class methodsFor:'utilities'!
|
|
59 |
|
|
60 |
dragRectangleIn:aView thenDo:action
|
|
61 |
"drag a rectangle in aView"
|
|
62 |
|
|
63 |
|dragController oldController oldCursor|
|
|
64 |
|
|
65 |
dragController := DragRectangleController new.
|
|
66 |
dragController view:aView.
|
|
67 |
oldController := aView controller.
|
|
68 |
oldCursor := aView cursor.
|
|
69 |
|
|
70 |
aView cursor:Cursor origin.
|
|
71 |
dragController action:[:rectOrNil |
|
|
72 |
|image|
|
|
73 |
|
|
74 |
aView controller:oldController.
|
|
75 |
aView cursor:oldCursor.
|
|
76 |
action value:rectOrNil.
|
|
77 |
].
|
|
78 |
|
|
79 |
aView controller:dragController.
|
|
80 |
! !
|
|
81 |
|
|
82 |
!DragRectangleController methodsFor:'accessing'!
|
|
83 |
|
|
84 |
action:aBlock
|
|
85 |
"set the block which will be called when the rectangle drag is finished.
|
|
86 |
The block will be called with a nil arg, if escape is pressed"
|
|
87 |
|
|
88 |
action := aBlock
|
|
89 |
!
|
|
90 |
|
|
91 |
lastMousePoint
|
|
92 |
lastX isNil ifTrue:[^ nil].
|
|
93 |
^ lastX @ lastY
|
|
94 |
!
|
|
95 |
|
|
96 |
startPoint
|
|
97 |
^ startPoint
|
|
98 |
! !
|
|
99 |
|
|
100 |
!DragRectangleController methodsFor:'event handling'!
|
|
101 |
|
|
102 |
buttonMotion:buttonState x:x y:y
|
|
103 |
(buttonState == 0 or:[startPoint isNil]) ifTrue:[
|
|
104 |
super buttonMotion:buttonState x:x y:y.
|
|
105 |
^ self
|
|
106 |
].
|
|
107 |
|
|
108 |
lastX notNil ifTrue:[
|
|
109 |
view xoring:[
|
|
110 |
view displayRectangle:(startPoint corner:(lastX@lastY))
|
|
111 |
].
|
|
112 |
].
|
|
113 |
|
|
114 |
lastX := x.
|
|
115 |
lastY := y.
|
|
116 |
|
|
117 |
startPoint ~= (x@y) ifTrue:[
|
|
118 |
view xoring:[
|
|
119 |
view displayRectangle:(startPoint corner:(lastX@lastY))
|
|
120 |
].
|
|
121 |
].
|
|
122 |
!
|
|
123 |
|
|
124 |
buttonPress:button x:x y:y
|
|
125 |
startPoint := x@y.
|
|
126 |
view cursor:(Cursor corner).
|
|
127 |
!
|
|
128 |
|
|
129 |
buttonRelease:button x:x y:y
|
|
130 |
|rect|
|
|
131 |
|
|
132 |
startPoint isNil ifTrue:[
|
|
133 |
super buttonRelease:button x:x y:y.
|
|
134 |
^ self
|
|
135 |
].
|
|
136 |
|
|
137 |
lastX notNil ifTrue:[
|
|
138 |
view xoring:[
|
|
139 |
view displayRectangle:(startPoint corner:(lastX@lastY))
|
|
140 |
].
|
|
141 |
].
|
|
142 |
rect := startPoint corner:(lastX@lastY).
|
|
143 |
startPoint := lastX := lastY := nil.
|
|
144 |
action value:rect.
|
|
145 |
!
|
|
146 |
|
|
147 |
keyPress:key x:x y:y
|
|
148 |
startPoint isNil ifTrue:[
|
|
149 |
super keyPress:key x:x y:y.
|
|
150 |
^ self
|
|
151 |
].
|
|
152 |
|
|
153 |
lastX notNil ifTrue:[
|
|
154 |
view xoring:[
|
|
155 |
view displayRectangle:(startPoint corner:(lastX@lastY))
|
|
156 |
].
|
|
157 |
].
|
|
158 |
|
|
159 |
startPoint := nil.
|
|
160 |
action value:nil.
|
|
161 |
! !
|
|
162 |
|
|
163 |
!DragRectangleController class methodsFor:'documentation'!
|
|
164 |
|
|
165 |
version
|
|
166 |
^ '$Header$'
|
|
167 |
!
|
|
168 |
|
|
169 |
version_CVS
|
|
170 |
^ '$Header$'
|
|
171 |
! !
|
|
172 |
|