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