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