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