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