0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
0
|
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 |
|
|
13 |
Ruler subclass:#TextRuler
|
|
14 |
instanceVariableNames:'leftMargin rightMargin tabStops tabTypes'
|
|
15 |
classVariableNames:'leftAlignForm rightAlignForm
|
|
16 |
alignForm centerForm leftMarginForm
|
|
17 |
rightMarginForm leftTabForm rightTabForm
|
|
18 |
centerTabForm
|
|
19 |
decimalTabForm currentTabType moving'
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Views-Interactors'
|
|
22 |
!
|
|
23 |
|
|
24 |
TextRuler comment:'
|
|
25 |
|
4
|
26 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
0
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
a Ruler for page layout showing tabs., margins etc.
|
|
30 |
|
4
|
31 |
$Header: /cvs/stx/stx/libwidg2/TextRuler.st,v 1.3 1993-10-13 02:49:40 claus Exp $
|
0
|
32 |
written oct 91 by claus
|
|
33 |
'!
|
|
34 |
|
|
35 |
!TextRuler class methodsFor:'defaults'!
|
|
36 |
|
|
37 |
alignForm
|
|
38 |
"return the form displayed in the align-button"
|
|
39 |
|
|
40 |
alignForm isNil ifTrue:[
|
|
41 |
alignForm := Form fromFile:'align.bit' resolution:100
|
|
42 |
].
|
|
43 |
^ alignForm
|
|
44 |
!
|
|
45 |
|
|
46 |
centerForm
|
|
47 |
"return the form displayed in the center-button"
|
|
48 |
|
|
49 |
centerForm isNil ifTrue:[
|
|
50 |
centerForm := Form fromFile:'center.bit' resolution:100
|
|
51 |
].
|
|
52 |
^ centerForm
|
|
53 |
!
|
|
54 |
|
|
55 |
leftAlignForm
|
|
56 |
"return the form displayed in the leftAlign-button"
|
|
57 |
|
|
58 |
leftAlignForm isNil ifTrue:[
|
|
59 |
leftAlignForm := Form fromFile:'leftAlign.bit' resolution:100
|
|
60 |
].
|
|
61 |
^ leftAlignForm
|
|
62 |
!
|
|
63 |
|
|
64 |
rightAlignForm
|
|
65 |
"return the form displayed in the rightAlign-button"
|
|
66 |
|
|
67 |
rightAlignForm isNil ifTrue:[
|
|
68 |
rightAlignForm := Form fromFile:'rightAlign.bit' resolution:100
|
|
69 |
].
|
|
70 |
^ rightAlignForm
|
|
71 |
!
|
|
72 |
|
|
73 |
rightTabForm
|
|
74 |
"return the form displayed in the rightTab-button"
|
|
75 |
|
|
76 |
rightTabForm isNil ifTrue:[
|
|
77 |
rightTabForm := Form fromFile:'rightTab.bit' resolution:100
|
|
78 |
].
|
|
79 |
^ rightTabForm
|
|
80 |
!
|
|
81 |
|
|
82 |
leftTabForm
|
|
83 |
"return the form displayed in the leftTab-button"
|
|
84 |
|
|
85 |
leftTabForm isNil ifTrue:[
|
|
86 |
leftTabForm := Form fromFile:'leftTab.bit' resolution:100
|
|
87 |
].
|
|
88 |
^ leftTabForm
|
|
89 |
!
|
|
90 |
|
|
91 |
centerTabForm
|
|
92 |
"return the form displayed in the centerTab-button"
|
|
93 |
|
|
94 |
centerTabForm isNil ifTrue:[
|
|
95 |
centerTabForm := Form fromFile:'centerTab.bit' resolution:100
|
|
96 |
].
|
|
97 |
^ centerTabForm
|
|
98 |
!
|
|
99 |
|
|
100 |
decimalTabForm
|
|
101 |
"return the form displayed in the decimalTab-button"
|
|
102 |
|
|
103 |
decimalTabForm isNil ifTrue:[
|
|
104 |
decimalTabForm := Form fromFile:'decimalTab.bit' resolution:100
|
|
105 |
].
|
|
106 |
^ decimalTabForm
|
|
107 |
!
|
|
108 |
|
|
109 |
leftMarginForm
|
|
110 |
"return the form displayed for the left margin marker"
|
|
111 |
|
|
112 |
leftMarginForm isNil ifTrue:[
|
|
113 |
leftMarginForm := Form fromFile:'leftMargin.bit' resolution:100
|
|
114 |
].
|
|
115 |
^ leftMarginForm
|
|
116 |
!
|
|
117 |
|
|
118 |
rightMarginForm
|
|
119 |
"return the form displayed for the right margin marker"
|
|
120 |
|
|
121 |
rightMarginForm isNil ifTrue:[
|
|
122 |
rightMarginForm := Form fromFile:'rightMarg.bit' resolution:100
|
|
123 |
].
|
|
124 |
^ rightMarginForm
|
|
125 |
! !
|
|
126 |
|
|
127 |
!TextRuler methodsFor:'initializing'!
|
|
128 |
|
|
129 |
initialize
|
|
130 |
|leftAlignToggle alignToggle centerToggle rightAlignToggle
|
|
131 |
leftTabButton centerTabButton rightTabButton decimalTabButton
|
|
132 |
lineSpacingField panel1 panel2 panel3 scaleHeight h group|
|
|
133 |
|
|
134 |
super initialize.
|
|
135 |
|
|
136 |
scaleHeight := (font height) * 2.
|
|
137 |
self height:(scaleHeight * 3).
|
|
138 |
|
|
139 |
h := self class leftAlignForm height.
|
|
140 |
panel1 := HorizontalPanelView
|
|
141 |
origin:(0.0 @ 0.0)
|
|
142 |
extent:[(width // 3) @ (h*2) "(height - scaleHeight)"]
|
|
143 |
in:self.
|
|
144 |
panel1 borderWidth:0.
|
|
145 |
panel1 layout:#left.
|
|
146 |
|
|
147 |
panel2 := HorizontalPanelView
|
|
148 |
origin:[(width // 3) @ margin]
|
|
149 |
extent:[(width // 3) @ (h*2) "(height - scaleHeight)"]
|
|
150 |
in:self.
|
|
151 |
panel2 borderWidth:0.
|
|
152 |
panel2 layout:#center.
|
|
153 |
|
|
154 |
panel3 := HorizontalPanelView
|
|
155 |
origin:[(width // 3 * 2) @ margin]
|
|
156 |
extent:[((width // 3)-margin) @ (h*2) "(height - scaleHeight)"]
|
|
157 |
in:self.
|
|
158 |
panel3 borderWidth:0.
|
|
159 |
panel3 layout:#right.
|
|
160 |
|
|
161 |
leftAlignToggle := RadioButton form:(self class leftAlignForm)
|
|
162 |
action:[self leftAlign]
|
|
163 |
in:panel1.
|
|
164 |
alignToggle := RadioButton form:(self class alignForm)
|
|
165 |
action:[self align]
|
|
166 |
in:panel1.
|
|
167 |
centerToggle := RadioButton form:(self class centerForm)
|
|
168 |
action:[self center]
|
|
169 |
in:panel1.
|
|
170 |
rightAlignToggle := RadioButton form:(self class rightAlignForm)
|
|
171 |
action:[self rightAlign]
|
|
172 |
in:panel1.
|
|
173 |
group := RadioButtonGroup new.
|
|
174 |
group add:leftAlignToggle.
|
|
175 |
group add:alignToggle.
|
|
176 |
group add:centerToggle.
|
|
177 |
group add:rightAlignToggle.
|
|
178 |
|
|
179 |
leftTabButton := Button form:(self class leftTabForm)
|
|
180 |
action:[self leftTab]
|
|
181 |
in:panel2.
|
|
182 |
centerTabButton := Button form:(self class centerTabForm)
|
|
183 |
action:[self centerTab]
|
|
184 |
in:panel2.
|
|
185 |
rightTabButton := Button form:(self class rightTabForm)
|
|
186 |
action:[self rightTab]
|
|
187 |
in:panel2.
|
|
188 |
decimalTabButton := Button form:(self class decimalTabForm)
|
|
189 |
action:[self decimalTab]
|
|
190 |
in:panel2.
|
|
191 |
|
|
192 |
lineSpacingField := EditField in:panel3.
|
|
193 |
|
|
194 |
|
|
195 |
leftMargin := 0.25.
|
|
196 |
rightMargin := 8.25
|
|
197 |
|
|
198 |
"TextRuler new realize"
|
|
199 |
!
|
|
200 |
|
|
201 |
initEvents
|
|
202 |
super initEvents.
|
|
203 |
self enableButtonEvents.
|
|
204 |
self enableButtonMotionEvents
|
|
205 |
|
|
206 |
! !
|
|
207 |
|
|
208 |
!TextRuler methodsFor:'user interaction'!
|
|
209 |
|
|
210 |
leftAlign
|
|
211 |
^ self
|
|
212 |
!
|
|
213 |
|
|
214 |
rightAlign
|
|
215 |
^ self
|
|
216 |
!
|
|
217 |
|
|
218 |
align
|
|
219 |
^ self
|
|
220 |
!
|
|
221 |
|
|
222 |
center
|
|
223 |
^ self
|
|
224 |
!
|
|
225 |
|
|
226 |
leftTab
|
|
227 |
^ self
|
|
228 |
!
|
|
229 |
|
|
230 |
rightTab
|
|
231 |
^ self
|
|
232 |
!
|
|
233 |
|
|
234 |
centerTab
|
|
235 |
^ self
|
|
236 |
!
|
|
237 |
|
|
238 |
decimalTab
|
|
239 |
^ self
|
|
240 |
!
|
|
241 |
|
|
242 |
buttonPress:button x:x y:y
|
|
243 |
"position a tab or start moving a ruler"
|
|
244 |
|
|
245 |
|mpos|
|
|
246 |
|
|
247 |
mpos := self inchToPixel:leftMargin.
|
|
248 |
(((mpos - 4) <= x) and:[x <= (mpos + 4)]) ifTrue:[
|
|
249 |
"start moving left margin"
|
|
250 |
moving := #left.
|
|
251 |
^ self
|
|
252 |
].
|
|
253 |
mpos := self inchToPixel:rightMargin.
|
|
254 |
(((mpos - 4) <= x) and:[x <= (mpos + 4)]) ifTrue:[
|
|
255 |
"start moving right margin"
|
|
256 |
moving := #right.
|
|
257 |
^ self
|
|
258 |
].
|
|
259 |
|
|
260 |
^ self
|
|
261 |
!
|
|
262 |
|
|
263 |
buttonMotion:state x:x y:y
|
|
264 |
"position a tab or start moving a ruler"
|
|
265 |
|
|
266 |
|mpos|
|
|
267 |
|
|
268 |
moving notNil ifTrue:[
|
|
269 |
self clearMargin:moving.
|
|
270 |
mpos := self pixelToInch:x.
|
|
271 |
(mpos < 0) ifTrue:[
|
|
272 |
mpos := 0
|
|
273 |
].
|
|
274 |
(mpos > paperWidth) ifTrue:[
|
|
275 |
mpos := paperWidth
|
|
276 |
].
|
|
277 |
(moving == #left) ifTrue:[
|
|
278 |
leftMargin := mpos
|
|
279 |
].
|
|
280 |
(moving == #right) ifTrue:[
|
|
281 |
rightMargin := mpos
|
|
282 |
].
|
|
283 |
self drawMargin:moving
|
|
284 |
]
|
|
285 |
!
|
|
286 |
|
|
287 |
buttonRelease:button x:x y:y
|
|
288 |
"position a tab or start moving a ruler"
|
|
289 |
|
|
290 |
moving := nil
|
|
291 |
! !
|
|
292 |
|
|
293 |
!TextRuler methodsFor:'redrawing'!
|
|
294 |
|
|
295 |
clearMargin:which
|
|
296 |
"clear margin"
|
|
297 |
|
|
298 |
|x top form|
|
|
299 |
|
|
300 |
self paint:viewBackground.
|
|
301 |
self background:viewBackground.
|
|
302 |
|
|
303 |
top := height - (font height) - (font ascent).
|
|
304 |
|
|
305 |
(which == #left) ifTrue:[
|
|
306 |
x := (self inchToPixel:leftMargin) rounded.
|
|
307 |
form := self class leftMarginForm
|
|
308 |
].
|
|
309 |
(which == #right) ifTrue:[
|
|
310 |
x := (self inchToPixel:rightMargin) rounded.
|
|
311 |
form := self class rightMarginForm
|
|
312 |
].
|
|
313 |
|
|
314 |
self drawOpaqueForm:form x:(x - (form width // 2))
|
|
315 |
!
|
|
316 |
|
|
317 |
drawMargin:which
|
|
318 |
"clear margin"
|
|
319 |
|
|
320 |
|x top form|
|
|
321 |
|
|
322 |
self paint:fgColor.
|
|
323 |
self background:viewBackground.
|
|
324 |
|
|
325 |
top := height - (font height) - (font ascent).
|
|
326 |
|
|
327 |
(which == #left) ifTrue:[
|
|
328 |
x := (self inchToPixel:leftMargin) rounded.
|
|
329 |
form := self class leftMarginForm
|
|
330 |
].
|
|
331 |
(which == #right) ifTrue:[
|
|
332 |
x := (self inchToPixel:rightMargin) rounded.
|
|
333 |
form := self class rightMarginForm
|
|
334 |
].
|
|
335 |
|
|
336 |
self drawOpaqueForm:form x:(x - (form width // 2))
|
|
337 |
!
|
|
338 |
|
|
339 |
redraw
|
|
340 |
"redraw margin & tab marks"
|
|
341 |
|
|
342 |
|x top form tab type|
|
|
343 |
|
|
344 |
super redraw.
|
|
345 |
|
|
346 |
self paint:fgColor.
|
|
347 |
self background:viewBackground.
|
|
348 |
|
|
349 |
top := height - (font height) - (font ascent).
|
|
350 |
|
|
351 |
x := (self inchToPixel:leftMargin) rounded.
|
|
352 |
form := self class leftMarginForm.
|
|
353 |
self drawOpaqueForm:form x:(x - (form width // 2))
|
|
354 |
y:(top - form height).
|
|
355 |
x := (self inchToPixel:rightMargin) rounded.
|
|
356 |
form := self class rightMarginForm.
|
|
357 |
self drawOpaqueForm:form x:(x - (form width // 2))
|
|
358 |
y:(top - form height).
|
|
359 |
|
|
360 |
tabStops notNil ifTrue:[
|
|
361 |
1 to:tabStops size do:[:tabNr |
|
|
362 |
tab := tabStops at:tabNr.
|
|
363 |
type := tabTypes at:tabNr.
|
|
364 |
x := (self inchToPixel:tab) rounded.
|
|
365 |
(type == #left) ifTrue:[
|
|
366 |
form := self class leftTabForm
|
|
367 |
] ifFalse:[
|
|
368 |
(type == #right) ifTrue:[
|
|
369 |
form := self class rightTabForm
|
|
370 |
] ifFalse:[
|
|
371 |
(type == #center) ifTrue:[
|
|
372 |
form := self class centerTabForm
|
|
373 |
] ifFalse:[
|
|
374 |
(type == #decimal) ifTrue:[
|
|
375 |
form := self class decimalTabForm
|
|
376 |
]
|
|
377 |
]
|
|
378 |
]
|
|
379 |
].
|
|
380 |
self drawOpaqueForm:form x:(x - (form width // 2))
|
|
381 |
y:(top - form height)
|
|
382 |
]
|
|
383 |
]
|
|
384 |
! !
|