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