36
|
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 |
"
|
1881
|
12 |
"{ Package: 'stx:libwidg2' }"
|
|
13 |
|
4986
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
327
|
16 |
Model subclass:#TabulatorSpecification
|
128
|
17 |
instanceVariableNames:'tabUnit unitReference tabPositions tabTypes'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Views-Support'
|
19
|
21 |
!
|
|
22 |
|
25
|
23 |
!TabulatorSpecification class methodsFor:'documentation'!
|
|
24 |
|
28
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
25
|
39 |
documentation
|
|
40 |
"
|
|
41 |
This is a helper class for table widgets and tabular data in
|
|
42 |
lists.
|
|
43 |
A tabulatorSpecification keeps track of where the tabs are,
|
36
|
44 |
and how they align. They are to be used in conjunction with
|
|
45 |
MultiColumnListEntry or the upcoming TableWidget.
|
|
46 |
However, they may also be useful to represent tabs in a
|
|
47 |
paragraph of text.
|
158
|
48 |
|
|
49 |
|
|
50 |
[author:]
|
|
51 |
Claus Gittinger
|
|
52 |
|
|
53 |
[see also:]
|
199
|
54 |
Ruler TabSpecRuler
|
158
|
55 |
ListView
|
28
|
56 |
"
|
|
57 |
!
|
25
|
58 |
|
28
|
59 |
examples
|
|
60 |
"
|
25
|
61 |
Example use (in a ListView):
|
161
|
62 |
[exBegin]
|
|
63 |
|listView tabSpec entry|
|
25
|
64 |
|
161
|
65 |
listView := ListView new.
|
25
|
66 |
|
161
|
67 |
tabSpec := TabulatorSpecification new.
|
|
68 |
tabSpec unit:#inch.
|
|
69 |
tabSpec positions:#(0 1 2.5 3.5 4 5 ).
|
|
70 |
tabSpec align: #(#left #left #right #right #center #decimal ).
|
25
|
71 |
|
161
|
72 |
entry := MultiColListEntry new.
|
|
73 |
entry tabulatorSpecification:tabSpec.
|
|
74 |
entry colAt:1 put:'left';
|
|
75 |
colAt:2 put:'left';
|
|
76 |
colAt:3 put:'right';
|
|
77 |
colAt:4 put:'right';
|
|
78 |
colAt:5 put:'center';
|
|
79 |
colAt:6 put:'.decimal'.
|
25
|
80 |
|
161
|
81 |
listView at:1 put:entry.
|
25
|
82 |
|
161
|
83 |
entry := MultiColListEntry new.
|
|
84 |
entry tabulatorSpecification:tabSpec.
|
|
85 |
entry colAt:1 put:'col1';
|
|
86 |
colAt:2 put:'col2';
|
|
87 |
colAt:3 put:'col3';
|
|
88 |
colAt:4 put:'col4';
|
|
89 |
colAt:5 put:'col5';
|
|
90 |
colAt:6 put:'col6.decimal'.
|
25
|
91 |
|
161
|
92 |
listView at:2 put:entry.
|
25
|
93 |
|
161
|
94 |
entry := MultiColListEntry new.
|
|
95 |
entry tabulatorSpecification:tabSpec.
|
|
96 |
entry colAt:1 put:'foo';
|
|
97 |
colAt:2 put:'fooBar';
|
|
98 |
colAt:3 put:'bar';
|
|
99 |
colAt:4 put:'barFoo';
|
|
100 |
colAt:5 put:'baz';
|
|
101 |
colAt:6 put:'1234.56'.
|
25
|
102 |
|
161
|
103 |
listView at:3 put:entry.
|
1881
|
104 |
(ScrollableView forView:listView) open
|
161
|
105 |
[exEnd]
|
25
|
106 |
|
28
|
107 |
|
|
108 |
defining field positions in millimeter :
|
161
|
109 |
[exBegin]
|
|
110 |
|listView tabSpec entry|
|
28
|
111 |
|
161
|
112 |
listView := ListView new.
|
28
|
113 |
|
161
|
114 |
tabSpec := TabulatorSpecification new.
|
|
115 |
tabSpec unit:#mm.
|
|
116 |
tabSpec positions:#(0 10 20 40).
|
|
117 |
tabSpec align: #left.
|
28
|
118 |
|
161
|
119 |
entry := MultiColListEntry new.
|
|
120 |
entry tabulatorSpecification:tabSpec.
|
|
121 |
entry colAt:1 put:'1';
|
|
122 |
colAt:2 put:'2';
|
|
123 |
colAt:3 put:'3';
|
|
124 |
colAt:4 put:'4'.
|
28
|
125 |
|
161
|
126 |
listView at:1 put:entry.
|
28
|
127 |
|
161
|
128 |
entry := MultiColListEntry new.
|
|
129 |
entry tabulatorSpecification:tabSpec.
|
|
130 |
entry colAt:1 put:'aa';
|
|
131 |
colAt:2 put:'bb';
|
|
132 |
colAt:3 put:'cc';
|
|
133 |
colAt:4 put:'dd'.
|
28
|
134 |
|
161
|
135 |
listView at:2 put:entry.
|
28
|
136 |
|
161
|
137 |
listView open
|
|
138 |
[exEnd]
|
28
|
139 |
|
|
140 |
defining field widths in millimeter :
|
161
|
141 |
[exBegin]
|
|
142 |
|listView tabSpec entry|
|
28
|
143 |
|
161
|
144 |
listView := ListView new.
|
28
|
145 |
|
161
|
146 |
tabSpec := TabulatorSpecification new.
|
|
147 |
tabSpec unit:#mm.
|
|
148 |
tabSpec widths:#(10 10 20 10).
|
|
149 |
tabSpec align: #left.
|
28
|
150 |
|
161
|
151 |
entry := MultiColListEntry new.
|
|
152 |
entry tabulatorSpecification:tabSpec.
|
|
153 |
entry colAt:1 put:'1';
|
|
154 |
colAt:2 put:'2';
|
|
155 |
colAt:3 put:'3';
|
|
156 |
colAt:4 put:'4'.
|
28
|
157 |
|
161
|
158 |
listView at:1 put:entry.
|
28
|
159 |
|
161
|
160 |
entry := MultiColListEntry new.
|
|
161 |
entry tabulatorSpecification:tabSpec.
|
|
162 |
entry colAt:1 put:'aa';
|
|
163 |
colAt:2 put:'bb';
|
|
164 |
colAt:3 put:'cc';
|
|
165 |
colAt:4 put:'dd'.
|
28
|
166 |
|
161
|
167 |
listView at:2 put:entry.
|
28
|
168 |
|
161
|
169 |
listView open
|
|
170 |
[exEnd]
|
28
|
171 |
|
|
172 |
defining field widths in pixels :
|
161
|
173 |
[exBegin]
|
|
174 |
|listView tabSpec entry|
|
28
|
175 |
|
161
|
176 |
listView := ListView new.
|
28
|
177 |
|
161
|
178 |
tabSpec := TabulatorSpecification new.
|
|
179 |
tabSpec unit:#pixel.
|
|
180 |
tabSpec widths:#(50 30 30 50).
|
|
181 |
tabSpec align: #left.
|
28
|
182 |
|
161
|
183 |
entry := MultiColListEntry new.
|
|
184 |
entry tabulatorSpecification:tabSpec.
|
|
185 |
entry colAt:1 put:'1';
|
|
186 |
colAt:2 put:'2';
|
|
187 |
colAt:3 put:'3';
|
|
188 |
colAt:4 put:'4'.
|
28
|
189 |
|
161
|
190 |
listView at:1 put:entry.
|
28
|
191 |
|
161
|
192 |
entry := MultiColListEntry new.
|
|
193 |
entry tabulatorSpecification:tabSpec.
|
|
194 |
entry colAt:1 put:'aa';
|
|
195 |
colAt:2 put:'bb';
|
|
196 |
colAt:3 put:'cc';
|
|
197 |
colAt:4 put:'dd'.
|
28
|
198 |
|
161
|
199 |
listView at:2 put:entry.
|
28
|
200 |
|
161
|
201 |
listView open
|
|
202 |
[exEnd]
|
199
|
203 |
|
|
204 |
same as first example, but adding a TabSpecRuler to show where
|
|
205 |
the tabs are:
|
|
206 |
[exBegin]
|
|
207 |
|top ruler listView tabSpec entry|
|
|
208 |
|
|
209 |
top := StandardSystemView extent:300@300.
|
|
210 |
|
|
211 |
ruler := TabSpecRuler origin:0.0@0.0 corner:1.0@20 in:top.
|
|
212 |
ruler level:0.
|
327
|
213 |
ruler tabsAreVariable:false.
|
|
214 |
|
199
|
215 |
listView := ListView in:top.
|
|
216 |
listView origin:0.0@0.0 corner:1.0@1.0.
|
|
217 |
listView topInset:20.
|
|
218 |
|
|
219 |
tabSpec := TabulatorSpecification new.
|
|
220 |
tabSpec unit:#inch.
|
|
221 |
tabSpec positions:#(0 1 2.5 3.5 4 5 ).
|
|
222 |
tabSpec align: #(#left #left #right #right #center #decimal ).
|
|
223 |
|
|
224 |
ruler tabulatorSpecification:tabSpec.
|
|
225 |
|
|
226 |
entry := MultiColListEntry new.
|
|
227 |
entry tabulatorSpecification:tabSpec.
|
|
228 |
entry colAt:1 put:'left';
|
|
229 |
colAt:2 put:'left';
|
|
230 |
colAt:3 put:'right';
|
|
231 |
colAt:4 put:'right';
|
|
232 |
colAt:5 put:'center';
|
|
233 |
colAt:6 put:'.decimal'.
|
|
234 |
|
|
235 |
listView at:1 put:entry.
|
|
236 |
|
|
237 |
entry := MultiColListEntry new.
|
|
238 |
entry tabulatorSpecification:tabSpec.
|
|
239 |
entry colAt:1 put:'col1';
|
|
240 |
colAt:2 put:'col2';
|
|
241 |
colAt:3 put:'col3';
|
|
242 |
colAt:4 put:'col4';
|
|
243 |
colAt:5 put:'col5';
|
|
244 |
colAt:6 put:'col6.decimal'.
|
|
245 |
|
|
246 |
listView at:2 put:entry.
|
|
247 |
|
|
248 |
entry := MultiColListEntry new.
|
|
249 |
entry tabulatorSpecification:tabSpec.
|
|
250 |
entry colAt:1 put:'foo';
|
|
251 |
colAt:2 put:'fooBar';
|
|
252 |
colAt:3 put:'bar';
|
|
253 |
colAt:4 put:'barFoo';
|
|
254 |
colAt:5 put:'baz';
|
|
255 |
colAt:6 put:'1234.56'.
|
|
256 |
|
|
257 |
listView at:3 put:entry.
|
|
258 |
top open
|
|
259 |
[exEnd]
|
327
|
260 |
|
|
261 |
much like previous example, but allow some tab positions to be
|
|
262 |
changed (with synchronousOperation):
|
|
263 |
[exBegin]
|
|
264 |
|top ruler listView tabSpec entry|
|
|
265 |
|
|
266 |
top := StandardSystemView extent:300@300.
|
|
267 |
|
|
268 |
ruler := TabSpecRuler origin:0.0@0.0 corner:1.0@20 in:top.
|
|
269 |
ruler level:0.
|
|
270 |
ruler fixedTabs:#(1).
|
|
271 |
ruler synchronousOperation:true.
|
|
272 |
|
|
273 |
listView := ListView in:top.
|
|
274 |
listView origin:0.0@0.0 corner:1.0@1.0.
|
|
275 |
listView topInset:20.
|
|
276 |
|
|
277 |
tabSpec := TabulatorSpecification new.
|
|
278 |
tabSpec unit:#inch.
|
|
279 |
tabSpec positions:#(0 1 2.5 3.5 4 5 ).
|
|
280 |
tabSpec align: #(#left #left #left #left #left #decimal ).
|
|
281 |
|
|
282 |
ruler tabulatorSpecification:tabSpec.
|
|
283 |
|
|
284 |
entry := MultiColListEntry new.
|
|
285 |
entry tabulatorSpecification:tabSpec.
|
|
286 |
entry colAt:1 put:'left';
|
|
287 |
colAt:2 put:'left';
|
|
288 |
colAt:3 put:'left';
|
|
289 |
colAt:4 put:'left';
|
|
290 |
colAt:5 put:'left';
|
|
291 |
colAt:6 put:'.decimal'.
|
|
292 |
|
|
293 |
listView at:1 put:entry.
|
|
294 |
|
|
295 |
entry := MultiColListEntry new.
|
|
296 |
entry tabulatorSpecification:tabSpec.
|
|
297 |
entry colAt:1 put:'col1';
|
|
298 |
colAt:2 put:'col2';
|
|
299 |
colAt:3 put:'col3';
|
|
300 |
colAt:4 put:'col4';
|
|
301 |
colAt:5 put:'col5';
|
|
302 |
colAt:6 put:'col6'.
|
|
303 |
|
|
304 |
listView at:2 put:entry.
|
|
305 |
|
|
306 |
entry := MultiColListEntry new.
|
|
307 |
entry tabulatorSpecification:tabSpec.
|
|
308 |
entry colAt:1 put:'foo';
|
|
309 |
colAt:2 put:'fooBar';
|
|
310 |
colAt:3 put:'bar';
|
|
311 |
colAt:4 put:'barFoo';
|
|
312 |
colAt:5 put:'baz';
|
|
313 |
colAt:6 put:'1234.56'.
|
|
314 |
|
|
315 |
listView at:3 put:entry.
|
|
316 |
|
|
317 |
entry := MultiColListEntry new.
|
|
318 |
entry tabulatorSpecification:tabSpec.
|
|
319 |
entry colAt:1 put:'hello';
|
|
320 |
colAt:2 put:'world';
|
|
321 |
colAt:3 put:'how';
|
|
322 |
colAt:4 put:'about';
|
|
323 |
colAt:5 put:'this';
|
|
324 |
colAt:6 put:'0.2345'.
|
|
325 |
listView at:4 put:entry.
|
|
326 |
|
|
327 |
tabSpec onChangeSend:#redraw to:listView.
|
|
328 |
top open
|
|
329 |
[exEnd]
|
25
|
330 |
"
|
|
331 |
! !
|
|
332 |
|
70
|
333 |
!TabulatorSpecification class methodsFor:'instance creation'!
|
|
334 |
|
|
335 |
unit:unit positions:positions
|
|
336 |
^ (self new) unit:unit; positions:positions
|
|
337 |
|
|
338 |
"
|
|
339 |
TabulatorSpecification unit:#inch positions:#(0 3)
|
|
340 |
"
|
|
341 |
|
|
342 |
"Modified: 30.8.1995 / 16:37:50 / claus"
|
|
343 |
! !
|
|
344 |
|
97
|
345 |
!TabulatorSpecification methodsFor:'accessing'!
|
|
346 |
|
|
347 |
align
|
|
348 |
"return the align-vector"
|
|
349 |
|
|
350 |
^ tabTypes
|
|
351 |
!
|
|
352 |
|
|
353 |
align:types
|
|
354 |
"
|
|
355 |
an array of tab-types; each one is
|
|
356 |
#left
|
|
357 |
#right
|
|
358 |
#center
|
|
359 |
#decimal
|
|
360 |
or a symbol which gives align of all tabs
|
|
361 |
|
|
362 |
"
|
|
363 |
tabTypes := types
|
|
364 |
!
|
|
365 |
|
327
|
366 |
moveTabAtIndex:index to:unitPosition
|
|
367 |
"set an individual position"
|
|
368 |
|
|
369 |
tabPositions at:index put:unitPosition.
|
|
370 |
self changed:#tabPosition with:index
|
|
371 |
|
|
372 |
"Modified: 28.3.1997 / 14:55:27 / cg"
|
|
373 |
!
|
|
374 |
|
97
|
375 |
positions
|
|
376 |
"return the position-vector"
|
|
377 |
|
|
378 |
^ tabPositions
|
|
379 |
!
|
|
380 |
|
|
381 |
positions:tabs
|
|
382 |
"set the position-vector"
|
|
383 |
|
|
384 |
tabPositions := tabs
|
|
385 |
!
|
|
386 |
|
|
387 |
size
|
|
388 |
"return the number of tabs in this spec"
|
|
389 |
|
|
390 |
^ tabPositions size
|
|
391 |
!
|
|
392 |
|
|
393 |
unit
|
|
394 |
"return the unit"
|
|
395 |
|
|
396 |
^ tabUnit
|
|
397 |
!
|
|
398 |
|
|
399 |
unit:aSymbol
|
|
400 |
"set the unit.
|
|
401 |
allowed are: #inch, #mm, #cm, #pixel and #col"
|
|
402 |
|
|
403 |
tabUnit := aSymbol
|
|
404 |
!
|
|
405 |
|
|
406 |
unitRelativeTo:someObject
|
|
407 |
"set for a relative unit. someObject should return its width
|
|
408 |
and the tabs are set fraction-relative to this number (in pixel)."
|
|
409 |
|
|
410 |
tabUnit := #relative.
|
|
411 |
unitReference := someObject
|
|
412 |
!
|
|
413 |
|
|
414 |
widths
|
|
415 |
"return a width-vector"
|
|
416 |
|
|
417 |
|prev|
|
|
418 |
|
|
419 |
prev := 0.
|
|
420 |
^ tabPositions collect:[:p | |w| w := p - prev. prev := p. w].
|
|
421 |
|
|
422 |
"
|
|
423 |
|spec|
|
|
424 |
|
|
425 |
spec := TabulatorSpecification new.
|
|
426 |
spec unit:#inch.
|
|
427 |
spec positions:#(0 1 2.5 3.5 4 5 ).
|
|
428 |
spec align: #(#left #left #right #right #center #decimal ).
|
|
429 |
spec widths
|
|
430 |
"
|
|
431 |
!
|
|
432 |
|
|
433 |
widths:fieldWidths
|
|
434 |
"set the position-vector from a vector of field widths"
|
|
435 |
|
|
436 |
|pos|
|
|
437 |
|
|
438 |
pos := 0.
|
|
439 |
tabPositions := fieldWidths collect:[:w |
|
|
440 |
|p|
|
|
441 |
|
|
442 |
p := pos.
|
|
443 |
pos := pos + w.
|
|
444 |
p].
|
|
445 |
! !
|
|
446 |
|
19
|
447 |
!TabulatorSpecification methodsFor:'queries'!
|
|
448 |
|
|
449 |
pixelsPerUnitOn:aGC
|
327
|
450 |
"return the number of device pixels one unit of my tabs
|
|
451 |
takes on aGC"
|
|
452 |
|
4986
|
453 |
|gcDevice mm|
|
128
|
454 |
|
19
|
455 |
tabUnit isNil ifTrue:[
|
128
|
456 |
tabUnit := #col
|
25
|
457 |
].
|
|
458 |
tabUnit == #relative ifTrue:[
|
128
|
459 |
^ unitReference width
|
19
|
460 |
].
|
|
461 |
tabUnit == #col ifTrue:[
|
128
|
462 |
^ aGC font width
|
19
|
463 |
].
|
4986
|
464 |
gcDevice := aGC graphicsDevice.
|
19
|
465 |
tabUnit == #inch ifTrue:[
|
4986
|
466 |
^ gcDevice horizontalPixelPerInch
|
19
|
467 |
].
|
4986
|
468 |
mm := gcDevice horizontalPixelPerMillimeter.
|
19
|
469 |
tabUnit == #mm ifTrue:[
|
128
|
470 |
^ mm
|
19
|
471 |
].
|
|
472 |
tabUnit == #cm ifTrue:[
|
128
|
473 |
^ mm * 10
|
19
|
474 |
].
|
|
475 |
"
|
|
476 |
assume pixels
|
|
477 |
"
|
|
478 |
^ 1.
|
128
|
479 |
|
327
|
480 |
"Modified: 28.3.1997 / 14:52:12 / cg"
|
19
|
481 |
!
|
|
482 |
|
|
483 |
positionOfTab:index forString:aString on:aGC
|
25
|
484 |
"return the position (in device units) of the string to be drawn
|
|
485 |
at position index."
|
|
486 |
|
19
|
487 |
|pos type idx left|
|
|
488 |
|
|
489 |
pos := self positionOfTab:index on:aGC.
|
|
490 |
pos isNil ifTrue:[^ nil].
|
|
491 |
|
28
|
492 |
type := self typeOfTab:index.
|
19
|
493 |
|
|
494 |
type == #right ifTrue:[
|
25
|
495 |
^ pos - (aGC font widthOf:aString).
|
19
|
496 |
].
|
|
497 |
type == #center ifTrue:[
|
25
|
498 |
^ pos - ((aGC font widthOf:aString) // 2).
|
19
|
499 |
].
|
|
500 |
type == #decimal ifTrue:[
|
25
|
501 |
idx := aString indexOf:$..
|
|
502 |
idx == 0 ifTrue:[
|
|
503 |
^ pos - (aGC font widthOf:aString).
|
|
504 |
].
|
|
505 |
left := aString copyTo:(idx-1).
|
|
506 |
^ pos - (aGC font widthOf:left).
|
19
|
507 |
].
|
|
508 |
"default is left"
|
|
509 |
^ pos
|
|
510 |
!
|
|
511 |
|
97
|
512 |
positionOfTab:index on:aGC
|
|
513 |
"return the position (in device units) of the tab at index"
|
25
|
514 |
|
97
|
515 |
|unit pos|
|
25
|
516 |
|
97
|
517 |
tabPositions isNil ifTrue:[^ nil].
|
19
|
518 |
|
97
|
519 |
unit := self pixelsPerUnitOn:aGC.
|
4477
|
520 |
pos := ((tabPositions at:index) * unit) asInteger.
|
97
|
521 |
^ pos
|
19
|
522 |
!
|
|
523 |
|
97
|
524 |
typeOfTab:index
|
|
525 |
"return the type of the tab at position index."
|
28
|
526 |
|
97
|
527 |
tabPositions isNil ifTrue:[^ #left].
|
|
528 |
tabTypes notNil ifTrue:[
|
|
529 |
(tabTypes isMemberOf:Symbol) ifTrue:[
|
|
530 |
^ tabTypes
|
|
531 |
].
|
|
532 |
^ tabTypes at:index.
|
|
533 |
].
|
|
534 |
"default is left"
|
|
535 |
^ #left
|
327
|
536 |
!
|
|
537 |
|
|
538 |
unitsPerPixelOn:aGC
|
|
539 |
"return the number of units that one device pixels
|
|
540 |
takes on aGC"
|
|
541 |
|
|
542 |
^ 1 / (self pixelsPerUnitOn:aGC)
|
|
543 |
|
|
544 |
"Modified: 28.3.1997 / 14:52:01 / cg"
|
19
|
545 |
! !
|
|
546 |
|
98
|
547 |
!TabulatorSpecification class methodsFor:'documentation'!
|
|
548 |
|
|
549 |
version
|
4986
|
550 |
^ '$Header$'
|
98
|
551 |
! !
|
4477
|
552 |
|