author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 17:23:54 +0100 | |
changeset 174 | d80a6cc3f9b2 |
parent 161 | a33764a0af35 |
child 200 | aa3e56929a5a |
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 |
'From Smalltalk/X, Version:2.10.4 on 6-mar-1995 at 20:00:02'! |
|
14 |
||
15 |
Controller subclass:#VariablePanelController |
|
16 |
instanceVariableNames:'movedHandle prevPos startPos isHorizontal' |
|
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
126 | 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. |
|
45 |
" |
|
46 |
! |
|
47 |
||
104 | 48 |
version |
174
d80a6cc3f9b2
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
49 |
^ '$Header: /cvs/stx/stx/libwidg/VariablePanelController.st,v 1.6 1995-11-11 16:23:39 cg Exp $' |
104 | 50 |
! ! |
51 |
||
52 |
!VariablePanelController methodsFor:'event handling'! |
|
53 |
||
161 | 54 |
buttonMotion:state x:bx y:by |
104 | 55 |
"mouse-button was moved while pressed; |
56 |
clear prev handleBar and draw handle bar at new position" |
|
57 |
||
131 | 58 |
|pos limitMin limitMax subViews barHeight |
59 |
oldHx oldHy newHx newHy| |
|
104 | 60 |
|
61 |
movedHandle isNil ifTrue: [^ self]. "should not happen" |
|
62 |
||
63 |
"speedup - if there is already another movement, |
|
64 |
ignore thisone ... " |
|
65 |
||
66 |
view buttonMotionEventPending ifTrue:[^ self]. |
|
67 |
||
68 |
subViews := view subViews. |
|
69 |
barHeight := view barHeight. |
|
70 |
||
71 |
isHorizontal ifTrue:[ |
|
72 |
pos := bx - startPos. |
|
73 |
" |
|
74 |
the two lines below will not allow resizing down to zero |
|
75 |
(so that some is always visible) |
|
76 |
" |
|
77 |
"/ limitMin := barHeight // 2. |
|
78 |
"/ limitMax := view width - barHeight. |
|
79 |
" |
|
80 |
these allow resizing to zero - which is better ? |
|
81 |
" |
|
82 |
limitMin := 0. |
|
83 |
limitMax := view innerWidth. |
|
84 |
||
85 |
movedHandle > 1 ifTrue:[ |
|
86 |
limitMin := (subViews at:movedHandle) origin x + (barHeight // 2) |
|
87 |
]. |
|
88 |
movedHandle < (subViews size - 1) ifTrue:[ |
|
89 |
limitMax := (subViews at:(movedHandle + 2)) origin x - barHeight |
|
90 |
]. |
|
91 |
] ifFalse:[ |
|
92 |
pos := by - startPos. |
|
93 |
" |
|
94 |
the two lines below will not allow resizing down to zero |
|
95 |
(so that some is always visible) |
|
96 |
" |
|
97 |
"/ limitMin := barHeight // 2. |
|
98 |
"/ limitMax := view height - barHeight. |
|
99 |
" |
|
100 |
these allow resizing to zero - which is better ? |
|
101 |
" |
|
102 |
limitMin := 0. |
|
103 |
limitMax := view innerHeight. |
|
104 |
||
105 |
movedHandle > 1 ifTrue:[ |
|
106 |
limitMin := (subViews at:movedHandle) origin y + (barHeight // 2) |
|
107 |
]. |
|
108 |
movedHandle < (subViews size - 1) ifTrue:[ |
|
109 |
limitMax := (subViews at:(movedHandle + 2)) origin y - barHeight |
|
110 |
]. |
|
111 |
]. |
|
112 |
||
113 |
limitMax := limitMax - barHeight. |
|
114 |
(pos < limitMin) ifTrue:[ "check against view limits" |
|
115 |
pos := limitMin |
|
116 |
] ifFalse:[ |
|
117 |
(pos > limitMax) ifTrue:[ |
|
118 |
pos := limitMax |
|
119 |
] |
|
120 |
]. |
|
121 |
||
122 |
isHorizontal ifTrue:[ |
|
131 | 123 |
oldHx := prevPos. |
124 |
newHx := pos. |
|
125 |
oldHy := newHy := 0. |
|
104 | 126 |
] ifFalse:[ |
131 | 127 |
oldHy := prevPos. |
128 |
newHy := pos. |
|
129 |
oldHx := newHx := 0. |
|
104 | 130 |
]. |
131 | 131 |
view invertHandleBarAtX:oldHx y:oldHy. |
132 |
view invertHandleBarAtX:newHx y:newHy. |
|
133 |
||
104 | 134 |
prevPos := pos |
135 |
! |
|
136 |
||
137 |
buttonRelease:button x:x y:y |
|
138 |
"end bar-move" |
|
139 |
||
140 |
|aboveView belowView aboveIndex belowIndex |
|
131 | 141 |
newPos oldPos group subViews |
142 |
relCornerAbove fromIndex toIndex| |
|
104 | 143 |
|
144 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
145 |
movedHandle isNil ifTrue:[^ self]. |
|
146 |
||
147 |
(group := view windowGroup) notNil ifTrue:[ |
|
148 |
group restoreCursors |
|
149 |
]. |
|
150 |
||
151 |
"undo the last invert" |
|
152 |
||
153 |
isHorizontal ifTrue:[ |
|
154 |
view invertHandleBarAtX:prevPos y:0. |
|
155 |
] ifFalse:[ |
|
156 |
view invertHandleBarAtX:0 y:prevPos. |
|
157 |
]. |
|
158 |
||
159 |
"compute the new relative heights" |
|
160 |
||
161 |
aboveIndex := movedHandle. |
|
162 |
belowIndex := movedHandle + 1. |
|
163 |
movedHandle := nil. |
|
164 |
subViews := view subViews. |
|
165 |
||
166 |
aboveView := subViews at:aboveIndex. |
|
167 |
belowView := subViews at:belowIndex. |
|
168 |
||
131 | 169 |
relCornerAbove := aboveView relativeCorner. |
104 | 170 |
isHorizontal ifTrue:[ |
131 | 171 |
oldPos := relCornerAbove x. |
104 | 172 |
newPos := (prevPos + startPos / view width) asFloat. |
131 | 173 |
aboveView relativeCorner:newPos @ relCornerAbove y. |
104 | 174 |
belowView relativeOrigin:newPos @ belowView relativeOrigin y. |
175 |
] ifFalse:[ |
|
131 | 176 |
oldPos := relCornerAbove y. |
104 | 177 |
newPos := (prevPos + startPos / view height) asFloat. |
131 | 178 |
aboveView relativeCorner:relCornerAbove x @ newPos. |
104 | 179 |
belowView relativeOrigin:belowView relativeOrigin x @ newPos. |
180 |
]. |
|
181 |
||
182 |
view lockRedraw. |
|
183 |
||
184 |
oldPos > newPos ifTrue:[ |
|
131 | 185 |
fromIndex := aboveIndex. toIndex := belowIndex. |
104 | 186 |
] ifFalse:[ |
131 | 187 |
fromIndex := belowIndex. toIndex := aboveIndex. |
104 | 188 |
]. |
131 | 189 |
view resizeSubviewsFrom:fromIndex to:toIndex. |
104 | 190 |
view redrawHandlesFrom:aboveIndex to:belowIndex. |
191 |
view unlockRedraw. |
|
192 |
] ifFalse:[ |
|
193 |
super buttonRelease:button x:x y:y |
|
194 |
] |
|
195 |
! |
|
196 |
||
197 |
buttonPress:button x:bx y:by |
|
198 |
"button was pressed - if it hits a handle, start move" |
|
199 |
||
200 |
|handle barHeight group| |
|
201 |
||
202 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
203 |
handle := 1. |
|
204 |
barHeight := view barHeight. |
|
205 |
||
206 |
" |
|
207 |
search the handle, invert the first time |
|
208 |
" |
|
209 |
view handleOriginsDo:[:hPoint | |
|
210 |
|hx hy| |
|
211 |
||
212 |
isHorizontal ifTrue:[ |
|
213 |
hx := hPoint x. |
|
214 |
(bx between:hx and:(hx + barHeight)) ifTrue:[ |
|
215 |
movedHandle := handle. |
|
216 |
prevPos := hx. |
|
217 |
startPos := bx - hx. |
|
218 |
||
219 |
view invertHandleBarAtX:hx y:0. |
|
220 |
(group := view windowGroup) notNil ifTrue:[ |
|
221 |
group showCursor:view cursor |
|
222 |
]. |
|
223 |
^ self |
|
224 |
]. |
|
225 |
] ifFalse:[ |
|
226 |
hy := hPoint y. |
|
227 |
(by between:hy and:(hy + barHeight)) ifTrue:[ |
|
228 |
movedHandle := handle. |
|
229 |
prevPos := hy. |
|
230 |
startPos := by - hy. |
|
231 |
||
232 |
view invertHandleBarAtX:0 y:hy. |
|
233 |
(group := view windowGroup) notNil ifTrue:[ |
|
234 |
group showCursor:view cursor |
|
235 |
]. |
|
236 |
^ self |
|
237 |
]. |
|
238 |
]. |
|
239 |
handle := handle + 1 |
|
240 |
]. |
|
241 |
movedHandle := nil |
|
242 |
] ifFalse:[ |
|
243 |
super buttonPress:button x:bx y:by |
|
244 |
] |
|
245 |
! ! |