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