19
|
1 |
'From Smalltalk/X, Version:2.10.3 on 12-aug-1994 at 10:44:09 pm'!
|
|
2 |
|
|
3 |
Object subclass:#TabulatorSpecification
|
|
4 |
instanceVariableNames:'tabUnit tabPositions tabTypes'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Views-Support'
|
|
8 |
!
|
|
9 |
|
|
10 |
!TabulatorSpecification methodsFor:'queries'!
|
|
11 |
|
|
12 |
pixelsPerUnitOn:aGC
|
|
13 |
"
|
|
14 |
return the number of device pixels one unit of my tabs
|
|
15 |
takes on aGC
|
|
16 |
"
|
|
17 |
tabUnit isNil ifTrue:[
|
|
18 |
tabUnit := #col
|
|
19 |
].
|
|
20 |
tabUnit == #col ifTrue:[
|
|
21 |
^ aGC font width
|
|
22 |
].
|
|
23 |
tabUnit == #inch ifTrue:[
|
|
24 |
^ aGC device horizontalPixelPerInch
|
|
25 |
].
|
|
26 |
tabUnit == #mm ifTrue:[
|
|
27 |
^ aGC device horizontalPixelPerMillimeter
|
|
28 |
].
|
|
29 |
tabUnit == #cm ifTrue:[
|
|
30 |
^ aGC device horizontalPixelPerMillimeter * 10
|
|
31 |
].
|
|
32 |
"
|
|
33 |
assume pixels
|
|
34 |
"
|
|
35 |
^ 1.
|
|
36 |
!
|
|
37 |
|
|
38 |
positionOfTab:index on:aGC
|
|
39 |
|unit pos|
|
|
40 |
|
|
41 |
tabPositions isNil ifTrue:[^ nil].
|
|
42 |
|
|
43 |
unit := self pixelsPerUnitOn:aGC.
|
|
44 |
pos := ((tabPositions at:index) * unit).
|
|
45 |
^ pos
|
|
46 |
!
|
|
47 |
|
|
48 |
positionOfTab:index forString:aString on:aGC
|
|
49 |
|pos type idx left|
|
|
50 |
|
|
51 |
pos := self positionOfTab:index on:aGC.
|
|
52 |
pos isNil ifTrue:[^ nil].
|
|
53 |
|
|
54 |
tabTypes notNil ifTrue:[
|
|
55 |
(tabTypes isMemberOf:Symbol) ifTrue:[
|
|
56 |
type := tabTypes
|
|
57 |
] ifFalse:[
|
|
58 |
type := tabTypes at:(index).
|
|
59 |
].
|
|
60 |
] ifFalse:[
|
|
61 |
type := #left
|
|
62 |
].
|
|
63 |
|
|
64 |
type == #right ifTrue:[
|
|
65 |
^ pos - (aGC font widthOf:aString).
|
|
66 |
].
|
|
67 |
type == #center ifTrue:[
|
|
68 |
^ pos - ((aGC font widthOf:aString) // 2).
|
|
69 |
].
|
|
70 |
type == #decimal ifTrue:[
|
|
71 |
idx := aString indexOf:$..
|
|
72 |
idx == 0 ifTrue:[
|
|
73 |
^ pos - (aGC font widthOf:aString).
|
|
74 |
].
|
|
75 |
left := aString copyTo:(idx-1).
|
|
76 |
^ pos - (aGC font widthOf:left).
|
|
77 |
].
|
|
78 |
"default is left"
|
|
79 |
^ pos
|
|
80 |
|
|
81 |
! !
|
|
82 |
|
|
83 |
!TabulatorSpecification methodsFor:'accessing'!
|
|
84 |
|
|
85 |
unit:aSymbol
|
|
86 |
"allowed are: #inch, #mm, #cm, #pixel and #col"
|
|
87 |
|
|
88 |
tabUnit := aSymbol
|
|
89 |
!
|
|
90 |
|
|
91 |
unit
|
|
92 |
^ tabUnit
|
|
93 |
!
|
|
94 |
|
|
95 |
align:types
|
|
96 |
"
|
|
97 |
an array of tab-types; each one is
|
|
98 |
#left
|
|
99 |
#right
|
|
100 |
#center
|
|
101 |
#decimal
|
|
102 |
or a symbol which gives align of all tabs
|
|
103 |
|
|
104 |
"
|
|
105 |
tabTypes := types
|
|
106 |
!
|
|
107 |
|
|
108 |
align
|
|
109 |
^ tabTypes
|
|
110 |
!
|
|
111 |
|
|
112 |
positions:tabs
|
|
113 |
tabPositions := tabs
|
|
114 |
!
|
|
115 |
|
|
116 |
positions
|
|
117 |
^ tabPositions
|
|
118 |
! !
|
|
119 |
|