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