38
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 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 |
|
49
|
13 |
SimpleView subclass:#TabSpecRuler
|
326
|
14 |
instanceVariableNames:'tabSpec titleEntry handleStyle handleCursor movedTabIndex
|
328
|
15 |
movedTabX synchronousOperation handleWidth fixedTabs
|
330
|
16 |
tabsAreVariable hiddenTabs'
|
200
|
17 |
classVariableNames:'DefaultHandleStyle'
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-Misc'
|
29
|
20 |
!
|
|
21 |
|
|
22 |
!TabSpecRuler class methodsFor:'documentation'!
|
|
23 |
|
38
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1994 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 |
|
36
|
38 |
documentation
|
|
39 |
"
|
326
|
40 |
It shows the tabulator positions of a TabulatorSpecification
|
|
41 |
and allows its tab positions to be manipulated.
|
|
42 |
(as shown in a FileBrowser, when the longList is enabled).
|
200
|
43 |
|
326
|
44 |
[author]
|
|
45 |
Claus Gittinger
|
200
|
46 |
|
|
47 |
[see also:]
|
|
48 |
TabulatorSpecification
|
|
49 |
Ruler
|
|
50 |
ListView
|
36
|
51 |
"
|
|
52 |
!
|
|
53 |
|
29
|
54 |
examples
|
|
55 |
"
|
326
|
56 |
[exBegin]
|
|
57 |
|top head spec|
|
29
|
58 |
|
326
|
59 |
top := View new.
|
|
60 |
top extent:300@100.
|
29
|
61 |
|
326
|
62 |
head := TabSpecRuler in:top.
|
|
63 |
head width:1.0.
|
|
64 |
head level:1.
|
29
|
65 |
|
326
|
66 |
spec := TabulatorSpecification new.
|
|
67 |
spec unit:#inch.
|
|
68 |
spec positions:#(0 1 2.5 3.5 4 5 ).
|
|
69 |
spec align: #(#left #left #right #right #center #decimal ).
|
29
|
70 |
|
326
|
71 |
head tabulatorSpecification:spec.
|
|
72 |
top open.
|
|
73 |
[exEnd]
|
29
|
74 |
"
|
|
75 |
|
|
76 |
! !
|
|
77 |
|
|
78 |
!TabSpecRuler class methodsFor:'defaults'!
|
|
79 |
|
|
80 |
updateStyleCache
|
|
81 |
DefaultHandleStyle := StyleSheet at:'tabRulerHandleStyle'.
|
|
82 |
|
|
83 |
! !
|
|
84 |
|
200
|
85 |
!TabSpecRuler methodsFor:'accessing'!
|
29
|
86 |
|
328
|
87 |
fixedTabs
|
|
88 |
"return the collection of tabIndices which are fixed;
|
|
89 |
or nil, if all are variable"
|
|
90 |
|
|
91 |
^ fixedTabs
|
|
92 |
|
|
93 |
"Created: 28.3.1997 / 15:02:29 / cg"
|
|
94 |
"Modified: 28.3.1997 / 15:03:05 / cg"
|
|
95 |
!
|
|
96 |
|
|
97 |
fixedTabs:something
|
|
98 |
"set the collection of tabIndices which are fixed;
|
|
99 |
nil, if all are to be variable"
|
|
100 |
|
|
101 |
fixedTabs := something.
|
|
102 |
|
|
103 |
"Created: 28.3.1997 / 15:02:29 / cg"
|
|
104 |
"Modified: 28.3.1997 / 15:03:18 / cg"
|
|
105 |
!
|
|
106 |
|
330
|
107 |
hiddenTabs
|
|
108 |
"return the collection of tabs which are to be hidden
|
|
109 |
(or nil if all are to be shown)"
|
|
110 |
|
|
111 |
^ hiddenTabs
|
|
112 |
|
|
113 |
"Created: 28.3.1997 / 15:35:54 / cg"
|
|
114 |
"Modified: 28.3.1997 / 15:36:18 / cg"
|
|
115 |
!
|
|
116 |
|
|
117 |
hiddenTabs:something
|
|
118 |
"set the collection of tabs which are to be hidden
|
|
119 |
(or nil if all are to be shown)"
|
|
120 |
|
|
121 |
hiddenTabs := something.
|
|
122 |
|
|
123 |
"Created: 28.3.1997 / 15:35:54 / cg"
|
|
124 |
"Modified: 28.3.1997 / 15:36:24 / cg"
|
|
125 |
!
|
|
126 |
|
328
|
127 |
synchronousOperation
|
|
128 |
"return the synchronousOperation mode settings value"
|
|
129 |
|
|
130 |
^ synchronousOperation
|
|
131 |
|
|
132 |
"Created: 28.3.1997 / 15:01:17 / cg"
|
|
133 |
"Modified: 28.3.1997 / 15:02:20 / cg"
|
|
134 |
!
|
|
135 |
|
|
136 |
synchronousOperation:something
|
|
137 |
"set/clear synchronousOperation mode;
|
|
138 |
if on, a move is immediately forwarded to dependents;
|
|
139 |
of off, its forwarded when the mouse button is released."
|
|
140 |
|
|
141 |
synchronousOperation := something.
|
|
142 |
|
|
143 |
"Modified: 28.3.1997 / 15:02:07 / cg"
|
|
144 |
!
|
|
145 |
|
|
146 |
tabsAreVariable
|
|
147 |
"return the value of the instance variable 'tabsAreVariable' (automatically generated)"
|
|
148 |
|
|
149 |
^ tabsAreVariable
|
|
150 |
|
|
151 |
"Created: 28.3.1997 / 15:05:27 / cg"
|
|
152 |
!
|
|
153 |
|
|
154 |
tabsAreVariable:something
|
|
155 |
"set/clear movability of tabs. If false, tab positions are only
|
|
156 |
displayed - but cannot be moved by the user.
|
|
157 |
The default is true."
|
|
158 |
|
|
159 |
tabsAreVariable := something.
|
|
160 |
|
|
161 |
"Created: 28.3.1997 / 15:05:27 / cg"
|
|
162 |
"Modified: 28.3.1997 / 15:06:19 / cg"
|
|
163 |
!
|
|
164 |
|
200
|
165 |
tabulatorSpecification:aTabSpec
|
|
166 |
"set my tabulator specification"
|
29
|
167 |
|
200
|
168 |
tabSpec := aTabSpec
|
29
|
169 |
|
200
|
170 |
"Modified: 4.6.1996 / 22:34:31 / cg"
|
29
|
171 |
! !
|
|
172 |
|
326
|
173 |
!TabSpecRuler methodsFor:'event handling'!
|
|
174 |
|
|
175 |
buttonMotion:state x:x y:y
|
|
176 |
"mouse-button was moved while pressed;
|
|
177 |
redraw thumb at its new position and, if scroll-mode is asynchronous,
|
|
178 |
the scroll action is performed"
|
|
179 |
|
|
180 |
|left right limit1 limit2 minSpacing newX|
|
|
181 |
|
|
182 |
movedTabIndex notNil ifTrue:[
|
328
|
183 |
minSpacing := 5.
|
|
184 |
|
326
|
185 |
left := limit1 := 0.
|
|
186 |
movedTabIndex > 1 ifTrue:[
|
|
187 |
left := self positionOfTabAtIndex:(movedTabIndex-1).
|
|
188 |
limit1 := left + minSpacing.
|
|
189 |
].
|
|
190 |
right := limit2 := width.
|
|
191 |
movedTabIndex < tabSpec size ifTrue:[
|
|
192 |
right := self positionOfTabAtIndex:(movedTabIndex+1).
|
|
193 |
limit2 := right - minSpacing.
|
|
194 |
].
|
|
195 |
newX := (x max:limit1) min:limit2.
|
|
196 |
x ~= newX ifTrue:[
|
|
197 |
self cursor:Cursor stop.
|
|
198 |
] ifFalse:[
|
|
199 |
self cursor:handleCursor
|
|
200 |
].
|
|
201 |
newX ~= movedTabX ifTrue:[
|
|
202 |
movedTabX := newX.
|
|
203 |
self clearRectangleX:left+handleWidth y:0
|
|
204 |
width:(right-left-handleWidth-handleWidth) height:height.
|
|
205 |
self redrawTabAtIndex:movedTabIndex.
|
|
206 |
synchronousOperation == true ifTrue:[
|
|
207 |
self moveTabAtIndex:movedTabIndex toX:movedTabX
|
|
208 |
]
|
|
209 |
]
|
|
210 |
] ifFalse:[
|
328
|
211 |
(self canMoveTabAtX:x) ifTrue:[
|
326
|
212 |
self cursor:handleCursor
|
|
213 |
] ifFalse:[
|
|
214 |
self cursor:(Cursor normal)
|
|
215 |
]
|
|
216 |
]
|
|
217 |
|
328
|
218 |
"Modified: 28.3.1997 / 15:17:14 / cg"
|
326
|
219 |
!
|
|
220 |
|
|
221 |
buttonPress:button x:x y:y
|
|
222 |
"mouse-button was pressed;
|
|
223 |
start moving the tab"
|
|
224 |
|
328
|
225 |
movedTabIndex := nil.
|
|
226 |
(self canMoveTabAtX:x) ifTrue:[
|
|
227 |
movedTabIndex := self indexOfTabAtX:x.
|
326
|
228 |
self cursor:handleCursor.
|
|
229 |
]
|
|
230 |
|
328
|
231 |
"Modified: 28.3.1997 / 15:13:15 / cg"
|
326
|
232 |
!
|
|
233 |
|
|
234 |
buttonRelease:button x:x y:y
|
|
235 |
"mouse-button was pressed;
|
|
236 |
start moving the tab"
|
|
237 |
|
|
238 |
|idx|
|
|
239 |
|
|
240 |
idx := movedTabIndex.
|
|
241 |
movedTabIndex := nil.
|
328
|
242 |
idx notNil ifTrue:[
|
|
243 |
synchronousOperation == true ifFalse:[
|
|
244 |
self moveTabAtIndex:idx toX:movedTabX
|
|
245 |
]
|
326
|
246 |
]
|
|
247 |
|
328
|
248 |
"Modified: 28.3.1997 / 15:10:23 / cg"
|
326
|
249 |
!
|
|
250 |
|
|
251 |
pointerLeave:state
|
|
252 |
"mouse left view - restore cursor."
|
|
253 |
|
|
254 |
self cursor:(Cursor normal).
|
|
255 |
|
|
256 |
"Created: 28.3.1997 / 13:37:52 / cg"
|
|
257 |
! !
|
|
258 |
|
29
|
259 |
!TabSpecRuler methodsFor:'initialization'!
|
|
260 |
|
|
261 |
initStyle
|
|
262 |
super initStyle.
|
|
263 |
|
326
|
264 |
handleStyle := DefaultHandleStyle.
|
|
265 |
handleCursor := (VariablePanel cursorForOrientation:#horizontal) onDevice:device.
|
|
266 |
self is3D ifTrue:[
|
|
267 |
handleWidth := 2.
|
|
268 |
] ifFalse:[
|
|
269 |
handleWidth := 1
|
|
270 |
]
|
|
271 |
|
|
272 |
"Modified: 28.3.1997 / 14:35:23 / cg"
|
29
|
273 |
!
|
|
274 |
|
|
275 |
initialize
|
|
276 |
super initialize.
|
|
277 |
|
328
|
278 |
tabsAreVariable := true.
|
|
279 |
|
326
|
280 |
self enableMotionEvents.
|
|
281 |
self enableEnterLeaveEvents.
|
|
282 |
|
29
|
283 |
self height:(font height + (2 * font descent)).
|
|
284 |
|
|
285 |
"
|
|
286 |
TabSpecRuler new open
|
|
287 |
"
|
326
|
288 |
|
328
|
289 |
"Modified: 28.3.1997 / 15:06:29 / cg"
|
326
|
290 |
! !
|
|
291 |
|
|
292 |
!TabSpecRuler methodsFor:'private'!
|
|
293 |
|
328
|
294 |
canMoveTabAtX:x
|
|
295 |
|idx|
|
|
296 |
|
|
297 |
tabsAreVariable ifTrue:[
|
|
298 |
(idx := self indexOfTabAtX:x) ~~ 0 ifTrue:[
|
|
299 |
(fixedTabs notNil and:[fixedTabs includes:idx]) ifFalse:[
|
|
300 |
^ true
|
|
301 |
]
|
|
302 |
]
|
|
303 |
].
|
|
304 |
^ false
|
|
305 |
|
|
306 |
"Created: 28.3.1997 / 15:12:05 / cg"
|
|
307 |
"Modified: 28.3.1997 / 15:19:01 / cg"
|
|
308 |
!
|
|
309 |
|
|
310 |
indexOfTabAtX:x
|
326
|
311 |
|xTab minDelta bestIndex|
|
|
312 |
|
|
313 |
tabSpec isNil ifTrue:[^ 0].
|
|
314 |
bestIndex := 0.
|
|
315 |
|
|
316 |
1 to:tabSpec size do:[:i |
|
|
317 |
xTab := tabSpec positionOfTab:i on:self.
|
|
318 |
(x between:(xTab-5) and:(xTab+5)) ifTrue:[
|
|
319 |
(minDelta isNil
|
|
320 |
or:[(x - xTab) abs < minDelta]) ifTrue:[
|
|
321 |
minDelta := (x - xTab) abs.
|
|
322 |
bestIndex := i.
|
|
323 |
]
|
|
324 |
]
|
|
325 |
].
|
|
326 |
^ bestIndex
|
|
327 |
|
|
328 |
"Modified: 28.3.1997 / 13:43:47 / cg"
|
328
|
329 |
"Created: 28.3.1997 / 15:12:09 / cg"
|
326
|
330 |
!
|
|
331 |
|
|
332 |
moveTabAtIndex:idx toX:movedTabX
|
328
|
333 |
|unitPosition|
|
326
|
334 |
|
328
|
335 |
unitPosition := (tabSpec unitsPerPixelOn:self) * movedTabX.
|
|
336 |
tabSpec moveTabAtIndex:idx to:unitPosition.
|
|
337 |
|
|
338 |
"Modified: 28.3.1997 / 14:54:58 / cg"
|
29
|
339 |
! !
|
|
340 |
|
200
|
341 |
!TabSpecRuler methodsFor:'redrawing'!
|
|
342 |
|
|
343 |
drawHandleAtX:x type:handleType
|
|
344 |
"redraw a tabulator handle"
|
|
345 |
|
326
|
346 |
self paint:Black.
|
|
347 |
self displayLineFromX:x y:0 toX:x y:height - 1.
|
|
348 |
self is3D ifTrue:[
|
|
349 |
self paint:White.
|
|
350 |
self displayLineFromX:x+1 y:0 toX:x+1 y:height - 1
|
|
351 |
]
|
200
|
352 |
|
326
|
353 |
"Modified: 28.3.1997 / 14:35:48 / cg"
|
|
354 |
!
|
|
355 |
|
|
356 |
positionOfTabAtIndex:idx
|
328
|
357 |
^ ( tabSpec positionOfTab:idx on:self ) rounded.
|
326
|
358 |
|
|
359 |
"Created: 28.3.1997 / 14:26:28 / cg"
|
328
|
360 |
"Modified: 28.3.1997 / 15:14:03 / cg"
|
200
|
361 |
!
|
29
|
362 |
|
200
|
363 |
redraw
|
|
364 |
"redraw the handles from by tabSpec"
|
|
365 |
|
326
|
366 |
tabSpec isNil ifTrue:[^ self].
|
|
367 |
shown ifFalse:[^ self].
|
|
368 |
|
|
369 |
1 to:tabSpec size do:[:idx |
|
|
370 |
self redrawTabAtIndex:idx.
|
|
371 |
]
|
|
372 |
|
|
373 |
"Modified: 28.3.1997 / 13:58:26 / cg"
|
|
374 |
!
|
|
375 |
|
|
376 |
redrawTabAtIndex:idx
|
|
377 |
"redraw a single handle"
|
|
378 |
|
200
|
379 |
|x|
|
|
380 |
|
|
381 |
tabSpec isNil ifTrue:[^ self].
|
330
|
382 |
(hiddenTabs notNil and:[hiddenTabs includes:idx]) ifTrue:[^ self].
|
|
383 |
|
326
|
384 |
idx == movedTabIndex ifTrue:[
|
|
385 |
x := movedTabX
|
|
386 |
] ifFalse:[
|
|
387 |
x := self positionOfTabAtIndex:idx.
|
|
388 |
].
|
|
389 |
self drawHandleAtX:x type:(tabSpec typeOfTab:idx).
|
200
|
390 |
|
326
|
391 |
"Created: 28.3.1997 / 13:57:54 / cg"
|
330
|
392 |
"Modified: 28.3.1997 / 15:37:07 / cg"
|
29
|
393 |
! !
|
|
394 |
|
200
|
395 |
!TabSpecRuler class methodsFor:'documentation'!
|
|
396 |
|
|
397 |
version
|
330
|
398 |
^ '$Header: /cvs/stx/stx/libwidg2/TabSpecRuler.st,v 1.10 1997-03-28 14:40:43 cg Exp $'
|
200
|
399 |
! !
|