author | Claus Gittinger <cg@exept.de> |
Thu, 09 Apr 1998 13:32:29 +0200 | |
changeset 1483 | e0fb580b5131 |
parent 1333 | 56af09878b96 |
child 1626 | 3013631d4384 |
permissions | -rw-r--r-- |
104 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
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 |
||
13 |
Controller subclass:#VariablePanelController |
|
582 | 14 |
instanceVariableNames:'movedHandle prevPos startPos' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Interface-Support-Controllers' |
|
104 | 18 |
! |
19 |
||
20 |
!VariablePanelController class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
150 | 36 |
documentation |
37 |
" |
|
38 |
An abstract class for variablePanel controllers; |
|
39 |
normally, not used directly by applications, these are created automatically |
|
40 |
whenever a variablePanel is created. |
|
41 |
Instances are responsible for tracking the mouse pointer and resize the |
|
42 |
views (a panel) subviews as appropriate. |
|
582 | 43 |
|
44 |
[author:] |
|
45 |
Claus Gittinger |
|
150 | 46 |
" |
104 | 47 |
! ! |
48 |
||
49 |
!VariablePanelController methodsFor:'event handling'! |
|
50 |
||
161 | 51 |
buttonMotion:state x:bx y:by |
104 | 52 |
"mouse-button was moved while pressed; |
53 |
clear prev handleBar and draw handle bar at new position" |
|
54 |
||
131 | 55 |
|pos limitMin limitMax subViews barHeight |
56 |
oldHx oldHy newHx newHy| |
|
104 | 57 |
|
58 |
movedHandle isNil ifTrue: [^ self]. "should not happen" |
|
59 |
||
60 |
"speedup - if there is already another movement, |
|
61 |
ignore thisone ... " |
|
62 |
||
63 |
view buttonMotionEventPending ifTrue:[^ self]. |
|
64 |
||
65 |
subViews := view subViews. |
|
66 |
barHeight := view barHeight. |
|
67 |
||
294
667773990289
merged all variablePanel code into a common class.
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
68 |
view orientation ~~ #vertical ifTrue:[ |
104 | 69 |
pos := bx - startPos. |
70 |
" |
|
71 |
the two lines below will not allow resizing down to zero |
|
72 |
(so that some is always visible) |
|
73 |
" |
|
74 |
"/ limitMin := barHeight // 2. |
|
75 |
"/ limitMax := view width - barHeight. |
|
76 |
" |
|
77 |
these allow resizing to zero - which is better ? |
|
78 |
" |
|
79 |
limitMin := 0. |
|
80 |
limitMax := view innerWidth. |
|
81 |
||
82 |
movedHandle > 1 ifTrue:[ |
|
83 |
limitMin := (subViews at:movedHandle) origin x + (barHeight // 2) |
|
84 |
]. |
|
85 |
movedHandle < (subViews size - 1) ifTrue:[ |
|
86 |
limitMax := (subViews at:(movedHandle + 2)) origin x - barHeight |
|
87 |
]. |
|
88 |
] ifFalse:[ |
|
89 |
pos := by - startPos. |
|
90 |
" |
|
91 |
the two lines below will not allow resizing down to zero |
|
92 |
(so that some is always visible) |
|
93 |
" |
|
94 |
"/ limitMin := barHeight // 2. |
|
95 |
"/ limitMax := view height - barHeight. |
|
96 |
" |
|
97 |
these allow resizing to zero - which is better ? |
|
98 |
" |
|
99 |
limitMin := 0. |
|
100 |
limitMax := view innerHeight. |
|
101 |
||
102 |
movedHandle > 1 ifTrue:[ |
|
103 |
limitMin := (subViews at:movedHandle) origin y + (barHeight // 2) |
|
104 |
]. |
|
105 |
movedHandle < (subViews size - 1) ifTrue:[ |
|
106 |
limitMax := (subViews at:(movedHandle + 2)) origin y - barHeight |
|
107 |
]. |
|
108 |
]. |
|
109 |
||
110 |
limitMax := limitMax - barHeight. |
|
111 |
(pos < limitMin) ifTrue:[ "check against view limits" |
|
112 |
pos := limitMin |
|
113 |
] ifFalse:[ |
|
114 |
(pos > limitMax) ifTrue:[ |
|
115 |
pos := limitMax |
|
116 |
] |
|
117 |
]. |
|
118 |
||
1215
0d9e67bdfbe4
check for any change before moving handle (tiny optimization)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
119 |
prevPos == pos ifTrue:[^ self]. |
0d9e67bdfbe4
check for any change before moving handle (tiny optimization)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
120 |
|
0d9e67bdfbe4
check for any change before moving handle (tiny optimization)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
121 |
view orientation ~~ #vertical ifTrue:[ |
131 | 122 |
oldHx := prevPos. |
123 |
newHx := pos. |
|
124 |
oldHy := newHy := 0. |
|
104 | 125 |
] ifFalse:[ |
131 | 126 |
oldHy := prevPos. |
127 |
newHy := pos. |
|
128 |
oldHx := newHx := 0. |
|
104 | 129 |
]. |
131 | 130 |
view invertHandleBarAtX:oldHx y:oldHy. |
131 |
view invertHandleBarAtX:newHx y:newHy. |
|
132 |
||
104 | 133 |
prevPos := pos |
134 |
! |
|
135 |
||
200 | 136 |
buttonPress:button x:bx y:by |
137 |
"button was pressed - if it hits a handle, start move" |
|
138 |
||
139 |
|handle barHeight group| |
|
140 |
||
141 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
872 | 142 |
handle := 1. |
143 |
barHeight := view barHeight. |
|
200 | 144 |
|
872 | 145 |
" |
146 |
search the handle, invert the first time |
|
147 |
" |
|
148 |
view handleOriginsWithIndexDo:[:hPoint :hIndex | |
|
149 |
|hx hy| |
|
200 | 150 |
|
872 | 151 |
view orientation ~~ #vertical ifTrue:[ |
152 |
hx := hPoint x. |
|
1333 | 153 |
(bx between:(hx - barHeight) and:(hx + barHeight)) ifTrue:[ |
872 | 154 |
movedHandle := handle. |
155 |
prevPos := hx. |
|
156 |
startPos := bx - hx. |
|
200 | 157 |
|
872 | 158 |
view grabPointer. |
159 |
view invertHandleBarAtX:hx y:0. |
|
160 |
(group := view windowGroup) notNil ifTrue:[ |
|
161 |
group showCursor:view cursor |
|
162 |
]. |
|
163 |
^ self |
|
164 |
]. |
|
165 |
] ifFalse:[ |
|
166 |
hy := hPoint y. |
|
1333 | 167 |
(by between:(hy - barHeight) and:(hy + barHeight)) ifTrue:[ |
872 | 168 |
movedHandle := handle. |
169 |
prevPos := hy. |
|
170 |
startPos := by - hy. |
|
200 | 171 |
|
872 | 172 |
view grabPointer. |
173 |
view invertHandleBarAtX:0 y:hy. |
|
174 |
(group := view windowGroup) notNil ifTrue:[ |
|
175 |
group showCursor:view cursor |
|
176 |
]. |
|
177 |
^ self |
|
178 |
]. |
|
179 |
]. |
|
180 |
handle := handle + 1 |
|
181 |
]. |
|
182 |
movedHandle := nil |
|
200 | 183 |
] ifFalse:[ |
872 | 184 |
super buttonPress:button x:bx y:by |
200 | 185 |
] |
1333 | 186 |
|
187 |
"Modified: 21.9.1997 / 12:06:48 / cg" |
|
200 | 188 |
! |
189 |
||
104 | 190 |
buttonRelease:button x:x y:y |
191 |
"end bar-move" |
|
192 |
||
193 |
|aboveView belowView aboveIndex belowIndex |
|
131 | 194 |
newPos oldPos group subViews |
195 |
relCornerAbove fromIndex toIndex| |
|
104 | 196 |
|
197 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
198 |
movedHandle isNil ifTrue:[^ self]. |
|
199 |
||
821 | 200 |
view ungrabPointer. |
104 | 201 |
(group := view windowGroup) notNil ifTrue:[ |
202 |
group restoreCursors |
|
203 |
]. |
|
204 |
||
205 |
"undo the last invert" |
|
206 |
||
294
667773990289
merged all variablePanel code into a common class.
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
207 |
view orientation ~~ #vertical ifTrue:[ |
104 | 208 |
view invertHandleBarAtX:prevPos y:0. |
209 |
] ifFalse:[ |
|
210 |
view invertHandleBarAtX:0 y:prevPos. |
|
211 |
]. |
|
212 |
||
213 |
"compute the new relative heights" |
|
214 |
||
215 |
aboveIndex := movedHandle. |
|
216 |
belowIndex := movedHandle + 1. |
|
217 |
movedHandle := nil. |
|
218 |
subViews := view subViews. |
|
219 |
||
220 |
aboveView := subViews at:aboveIndex. |
|
221 |
belowView := subViews at:belowIndex. |
|
222 |
||
131 | 223 |
relCornerAbove := aboveView relativeCorner. |
294
667773990289
merged all variablePanel code into a common class.
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
224 |
view orientation ~~ #vertical ifTrue:[ |
131 | 225 |
oldPos := relCornerAbove x. |
104 | 226 |
newPos := (prevPos + startPos / view width) asFloat. |
131 | 227 |
aboveView relativeCorner:newPos @ relCornerAbove y. |
104 | 228 |
belowView relativeOrigin:newPos @ belowView relativeOrigin y. |
229 |
] ifFalse:[ |
|
131 | 230 |
oldPos := relCornerAbove y. |
104 | 231 |
newPos := (prevPos + startPos / view height) asFloat. |
131 | 232 |
aboveView relativeCorner:relCornerAbove x @ newPos. |
104 | 233 |
belowView relativeOrigin:belowView relativeOrigin x @ newPos. |
234 |
]. |
|
235 |
||
236 |
view lockRedraw. |
|
237 |
||
238 |
oldPos > newPos ifTrue:[ |
|
131 | 239 |
fromIndex := aboveIndex. toIndex := belowIndex. |
104 | 240 |
] ifFalse:[ |
131 | 241 |
fromIndex := belowIndex. toIndex := aboveIndex. |
104 | 242 |
]. |
131 | 243 |
view resizeSubviewsFrom:fromIndex to:toIndex. |
104 | 244 |
view redrawHandlesFrom:aboveIndex to:belowIndex. |
245 |
view unlockRedraw. |
|
246 |
] ifFalse:[ |
|
247 |
super buttonRelease:button x:x y:y |
|
248 |
] |
|
1483 | 249 |
! |
250 |
||
251 |
pointerEnter:state x:x y:y |
|
252 |
state == 0 ifTrue:[ |
|
253 |
movedHandle notNil ifTrue:[self buttonRelease:1 x:x y:y] |
|
254 |
] |
|
255 |
||
256 |
"Created: / 9.4.1998 / 12:34:22 / cg" |
|
257 |
"Modified: / 9.4.1998 / 12:35:05 / cg" |
|
200 | 258 |
! ! |
104 | 259 |
|
203 | 260 |
!VariablePanelController class methodsFor:'documentation'! |
261 |
||
262 |
version |
|
1483 | 263 |
^ '$Header: /cvs/stx/stx/libwidg/VariablePanelController.st,v 1.15 1998-04-09 11:32:29 cg Exp $' |
203 | 264 |
! ! |