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