author | Claus Gittinger <cg@exept.de> |
Sat, 24 Feb 1996 18:19:17 +0100 | |
changeset 394 | 795f293f8520 |
parent 390 | 1d54a9b41463 |
child 398 | 6f10715fef28 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
59 | 3 |
All Rights Reserved |
0 | 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 |
||
77 | 13 |
|
14 |
||
15 |
DialogBox subclass:#FontPanel |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
16 |
instanceVariableNames:'previewField familyList faceList sizeList revertButton |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
17 |
currentFamily currentFace currentStyle currentFaceAndStyle |
382 | 18 |
currentSize selectedFont nameLabel encodingLabel' |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
19 |
classVariableNames:'' |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
20 |
poolDictionaries:'' |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
21 |
category:'Views-DialogBoxes' |
0 | 22 |
! |
23 |
||
77 | 24 |
!FontPanel class methodsFor:'documentation'! |
25 |
||
197 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1991 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 |
||
77 | 40 |
! |
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
this class implements a font chooser. |
|
45 |
||
46 |
usage: |
|
0 | 47 |
|
77 | 48 |
|panel| |
49 |
||
50 |
panel := FontPanel new. |
|
51 |
panel action:[:aFont | Transcript showCR:'the font is' , aFont printString]. |
|
52 |
panel show |
|
53 |
||
54 |
or simply: |
|
55 |
||
56 |
font := FontPanel fontFromUser |
|
57 |
" |
|
58 |
||
59 |
! ! |
|
0 | 60 |
|
61 |
!FontPanel class methodsFor:'defaults'! |
|
62 |
||
197 | 63 |
defaultExtent |
64 |
^ (Screen current pixelPerMillimeter * (120 @ 100)) rounded |
|
65 |
! |
|
66 |
||
382 | 67 |
defaultJISSampleString |
68 |
^ ('The quick brown fox |
|
69 |
jumps over the lazy dog |
|
70 |
1234567890 |
|
71 |
!!@#$%^&*(){}[]:"~;,./<>? |
|
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
72 |
|
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
73 |
\e$B$$$i$C$7$c$$$^$;\e(J \e$B@$4V\e(J |
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
74 |
' withEscapes decodeFrom:#jis7) |
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
75 |
|
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
76 |
"Modified: 23.2.1996 / 23:33:37 / cg" |
382 | 77 |
! |
78 |
||
79 |
defaultRomanSampleString |
|
110 | 80 |
^ 'The quick brown fox |
81 |
jumps over the lazy dog |
|
82 |
1234567890 |
|
83 |
!!@#$%^&*(){}[]:"~;,./<>? |
|
84 |
' , |
|
85 |
(Character value:16rE4) asString , |
|
86 |
(Character value:16rF6) asString , |
|
87 |
(Character value:16rFC) asString , |
|
88 |
(Character value:16rC4) asString , |
|
89 |
(Character value:16rD6) asString , |
|
90 |
(Character value:16rDC) asString , |
|
91 |
(Character value:16rDF) asString |
|
0 | 92 |
! ! |
93 |
||
94 |
!FontPanel class methodsFor:'startup'! |
|
95 |
||
96 |
fontFromUser |
|
77 | 97 |
"open a fontPanel and return the selected font, or nil |
98 |
if abort is pressed" |
|
99 |
||
0 | 100 |
|fontPanel| |
77 | 101 |
|
0 | 102 |
fontPanel := FontPanel new. |
103 |
fontPanel action:[:family :face :style :size | |
|
59 | 104 |
^ (Font family:family |
105 |
face:face |
|
106 |
style:style |
|
107 |
size:size) |
|
0 | 108 |
]. |
109 |
fontPanel showAtPointer. |
|
110 |
^ nil |
|
111 |
||
77 | 112 |
" |
113 |
FontPanel fontFromUser |
|
114 |
" |
|
0 | 115 |
! ! |
116 |
||
117 |
!FontPanel methodsFor:'accessing'! |
|
118 |
||
197 | 119 |
action:aBlock |
120 |
okAction := aBlock |
|
121 |
! |
|
122 |
||
0 | 123 |
initialFont:aFont |
128 | 124 |
"set the font to be selected initially" |
0 | 125 |
|
128 | 126 |
selectedFont := aFont. |
382 | 127 |
self showSelectedFont. |
128 |
self showPreview |
|
129 |
||
130 |
"Modified: 23.2.1996 / 00:51:32 / cg" |
|
101 | 131 |
! ! |
132 |
||
77 | 133 |
!FontPanel methodsFor:'initialization'! |
134 |
||
197 | 135 |
focusSequence |
136 |
|a| |
|
77 | 137 |
|
197 | 138 |
a := Array new:5. |
139 |
a at:1 put:familyList. |
|
140 |
a at:2 put:faceList. |
|
141 |
a at:3 put:sizeList. |
|
142 |
a at:4 put:abortButton. |
|
143 |
a at:5 put:okButton. |
|
144 |
^ a |
|
77 | 145 |
! |
146 |
||
147 |
initialize |
|
382 | 148 |
|familyLabel faceLabel sizeLabel panel fontBrowserView v1 v2 v3 |
149 |
mm fH eH| |
|
77 | 150 |
|
151 |
super initialize. |
|
152 |
||
382 | 153 |
mm := ViewSpacing. |
154 |
||
77 | 155 |
self addAbortButton. |
156 |
self addOkButton. |
|
157 |
||
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
158 |
panel := View origin:0.0@0.0 corner:1.0@1.0 in:self. |
382 | 159 |
panel bottomInset:(buttonPanel preferredExtent y + (mm*3)). |
77 | 160 |
|
150 | 161 |
label := resources string:'Font dialog'. |
77 | 162 |
|
382 | 163 |
encodingLabel := Label label:' ' in:panel. |
164 |
eH := encodingLabel preferredExtent y. |
|
165 |
encodingLabel origin:0.7@1.0 corner:1.0@1.0. |
|
166 |
encodingLabel topInset:(eH negated); horizontalInset:mm. |
|
167 |
encodingLabel level:-1; adjust:#left. |
|
168 |
||
169 |
"/ nameLabel := Label label:' ' in:panel. |
|
170 |
"/ nameLabel origin:0.0@1.0 corner:0.7@1.0. |
|
171 |
"/ nameLabel topInset:(eH negated); horizontalInset:mm. |
|
172 |
"/ nameLabel level:-1; adjust:#left. |
|
173 |
||
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
174 |
previewField := TextView origin:0.0@0.0 corner:1.0@0.4 in:panel. |
382 | 175 |
previewField inset:mm. |
77 | 176 |
|
382 | 177 |
"/ previewField contents:self class defaultSampleString. |
77 | 178 |
self is3D ifTrue:[ |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
179 |
previewField level:-1. |
77 | 180 |
] ifFalse:[ |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
181 |
previewField borderWidth:1. |
77 | 182 |
]. |
183 |
||
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
184 |
fontBrowserView := View origin:0.0@0.4 corner:1.0@1.0 in:panel. |
382 | 185 |
fontBrowserView bottomInset:(eH + mm). |
77 | 186 |
|
187 |
v1 := View origin:0.0@0.0 corner:0.4@1.0 in:fontBrowserView. |
|
188 |
||
189 |
familyLabel := Label label:'Family' in:v1. |
|
190 |
familyLabel borderWidth:0. |
|
191 |
familyLabel origin:(0.0 @ 0.0) extent:(1.0 @ nil). |
|
382 | 192 |
fH := familyLabel preferredExtent y. |
77 | 193 |
|
194 |
familyList := ScrollableView for:SelectionInListView in:v1. |
|
382 | 195 |
familyList origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
196 |
familyList inset:mm. |
|
197 |
familyList topInset:fH. |
|
198 |
||
128 | 199 |
familyList := familyList scrolledView. |
77 | 200 |
|
201 |
v2 := View origin:0.4@0.0 corner:0.8@1.0 |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
202 |
in:fontBrowserView. |
77 | 203 |
|
204 |
faceLabel := Label label:'Typeface' in:v2. |
|
205 |
faceLabel borderWidth:0. |
|
206 |
faceLabel origin:(0.0 @ 0.0) extent:(1.0 @ nil). |
|
207 |
||
208 |
faceList := ScrollableView for:SelectionInListView in:v2. |
|
382 | 209 |
faceList origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
210 |
faceList inset:mm. |
|
211 |
faceList topInset:fH. |
|
128 | 212 |
faceList := faceList scrolledView. |
77 | 213 |
|
214 |
v3 := View origin:0.8@0.0 corner:1.0@1.0 |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
215 |
in:fontBrowserView. |
77 | 216 |
|
217 |
sizeLabel := Label label:'Size' in:v3. |
|
218 |
sizeLabel borderWidth:0. |
|
219 |
sizeLabel origin:(0.0 @ 0.0)extent:(1.0 @ nil). |
|
220 |
||
221 |
sizeList := ScrollableView for:SelectionInListView in:v3. |
|
382 | 222 |
sizeList origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
223 |
sizeList inset:mm. |
|
224 |
sizeList topInset:fH. |
|
128 | 225 |
sizeList := sizeList scrolledView. |
77 | 226 |
|
227 |
familyList action:[:lineNr | self familySelected:(familyList selectionValue)]. |
|
228 |
faceList action:[:lineNr | self faceSelected:(faceList selectionValue)]. |
|
229 |
sizeList action:[:lineNr | self sizeSelected:(sizeList selectionValue)]. |
|
230 |
||
231 |
" |
|
232 |
FontPanel new showAtPointer |
|
233 |
" |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
234 |
|
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
235 |
"Modified: 23.2.1996 / 23:36:01 / cg" |
77 | 236 |
! |
237 |
||
197 | 238 |
realize |
239 |
"kludge for sco - xlsfont fails sometimes - try again here" |
|
240 |
||
241 |
|families| |
|
77 | 242 |
|
197 | 243 |
familyList list isNil ifTrue:[ |
244 |
families := device fontFamilies. |
|
245 |
families notNil ifTrue:[ |
|
246 |
families := families asOrderedCollection |
|
247 |
]. |
|
248 |
familyList list:families |
|
249 |
]. |
|
250 |
selectedFont notNil ifTrue:[ |
|
251 |
self showSelectedFont |
|
252 |
]. |
|
253 |
super realize |
|
77 | 254 |
! ! |
255 |
||
0 | 256 |
!FontPanel methodsFor:'private'! |
257 |
||
197 | 258 |
extractFaceAndStyleFrom:aString |
259 |
|index| |
|
260 |
||
261 |
index := aString indexOf:$-. |
|
262 |
(index ~~ 0) ifTrue:[ |
|
263 |
currentFaceAndStyle := aString. |
|
264 |
currentFace := aString copyTo:(index - 1). |
|
265 |
currentStyle := aString copyFrom:(index + 1) |
|
266 |
] |
|
267 |
||
268 |
! |
|
269 |
||
270 |
showPreview |
|
382 | 271 |
|f enc s| |
272 |
||
197 | 273 |
shown ifTrue:[ |
255 | 274 |
previewField clear. |
197 | 275 |
]. |
276 |
" |
|
277 |
show a wait cursor: for some fonts (kanji etc) the |
|
278 |
X-server needs quites some time to load the font |
|
279 |
" |
|
255 | 280 |
self withWaitCursorDo:[ |
382 | 281 |
previewField font:(f := Font family:currentFamily |
282 |
face:currentFace |
|
283 |
style:currentStyle |
|
284 |
size:currentSize). |
|
285 |
enc := f encoding. |
|
286 |
"/ enc isNil ifTrue:[enc := 'ASCII ?']. |
|
287 |
encodingLabel label:enc. |
|
288 |
nameLabel notNil ifTrue:[nameLabel label:(f fullName)]. |
|
289 |
||
290 |
(enc notNil and:[enc startsWith:'JIS']) ifTrue:[ |
|
291 |
s := self class defaultJISSampleString |
|
292 |
] ifFalse:[ |
|
293 |
s := self class defaultRomanSampleString. |
|
294 |
]. |
|
295 |
previewField contents:s . |
|
197 | 296 |
] |
255 | 297 |
|
382 | 298 |
"Modified: 23.2.1996 / 02:57:58 / cg" |
197 | 299 |
! |
300 |
||
128 | 301 |
showSelectedFont |
302 |
|fam face style sz| |
|
303 |
||
304 |
fam := selectedFont family. |
|
305 |
fam notNil ifTrue:[ |
|
306 |
self familySelected:fam. |
|
307 |
face := selectedFont face. |
|
308 |
face notNil ifTrue:[ |
|
309 |
style := selectedFont style. |
|
310 |
style notNil ifTrue:[ |
|
311 |
self faceSelected:(face , '-' , style). |
|
312 |
sz := selectedFont size. |
|
313 |
sz notNil ifTrue:[ |
|
314 |
self sizeSelected:sz |
|
315 |
] |
|
316 |
] |
|
317 |
] |
|
318 |
] |
|
197 | 319 |
! ! |
128 | 320 |
|
197 | 321 |
!FontPanel methodsFor:'queries'! |
0 | 322 |
|
197 | 323 |
preferredExtent |
324 |
^ 400@350 |
|
0 | 325 |
! ! |
77 | 326 |
|
327 |
!FontPanel methodsFor:'user interaction'! |
|
328 |
||
197 | 329 |
faceSelected:aFaceAndStyleName |
330 |
|sizes| |
|
331 |
||
332 |
aFaceAndStyleName notNil ifTrue:[ |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
333 |
self extractFaceAndStyleFrom:aFaceAndStyleName. |
197 | 334 |
]. |
335 |
sizes := device |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
336 |
sizesInFamily:currentFamily |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
337 |
face:currentFace |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
338 |
style:currentStyle. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
339 |
|
197 | 340 |
(sizes isNil or:[sizes isEmpty]) ifTrue:[ |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
341 |
sizeList list:nil. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
342 |
currentSize := nil. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
343 |
self showPreview. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
344 |
^ self |
197 | 345 |
]. |
346 |
||
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
347 |
sizes := (sizes asOrderedCollection sort) collect:[:entry | entry printString]. |
197 | 348 |
sizeList list:sizes. |
349 |
currentSize notNil ifTrue:[ |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
350 |
(sizes includes:(currentSize printString)) ifTrue:[ |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
351 |
sizeList selectElement:currentSize. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
352 |
self showPreview |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
353 |
] |
197 | 354 |
] |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
355 |
|
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
356 |
"Modified: 12.12.1995 / 17:36:28 / cg" |
197 | 357 |
! |
358 |
||
77 | 359 |
familySelected:aFamilyName |
360 |
|faces styles list| |
|
361 |
||
362 |
familyList selectElement:aFamilyName. |
|
363 |
||
364 |
currentFamily := aFamilyName. |
|
365 |
faces := device facesInFamily:aFamilyName. |
|
366 |
(faces isNil or:[faces isEmpty]) ifTrue:[ |
|
367 |
currentFace := currentStyle := currentFaceAndStyle := nil. |
|
368 |
faceList list:nil. |
|
369 |
self faceSelected:nil. |
|
370 |
^ self. |
|
371 |
]. |
|
372 |
||
373 |
list := OrderedCollection new. |
|
374 |
faces do:[:aFace | |
|
375 |
styles := device stylesInFamily:aFamilyName face:aFace. |
|
376 |
styles do:[:aStyle | |
|
377 |
list add:(aFace , '-' , aStyle) |
|
378 |
] |
|
379 |
]. |
|
380 |
faceList list:list. |
|
381 |
currentFaceAndStyle notNil ifTrue:[ |
|
382 |
(list includes:currentFaceAndStyle) ifTrue:[ |
|
383 |
faceList selectElement:currentFaceAndStyle. |
|
384 |
self faceSelected:currentFaceAndStyle. |
|
385 |
^ self |
|
386 |
] |
|
387 |
]. |
|
388 |
sizeList list:nil |
|
389 |
! |
|
390 |
||
391 |
okPressed |
|
392 |
self hide. |
|
393 |
okAction notNil ifTrue:[ |
|
394 |
okAction value:currentFamily |
|
395 |
value:currentFace |
|
396 |
value:currentStyle |
|
397 |
value:currentSize |
|
398 |
] |
|
399 |
! |
|
400 |
||
401 |
sizeSelected:aNumberOrString |
|
402 |
aNumberOrString isNumber ifTrue:[ |
|
403 |
currentSize := aNumberOrString |
|
404 |
] ifFalse:[ |
|
405 |
currentSize := Number readFromString:aNumberOrString |
|
406 |
]. |
|
407 |
self showPreview |
|
408 |
! ! |
|
197 | 409 |
|
243 | 410 |
!FontPanel class methodsFor:'documentation'! |
411 |
||
412 |
version |
|
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
413 |
^ '$Header: /cvs/stx/stx/libwidg/FontPanel.st,v 1.20 1996-02-23 22:37:35 cg Exp $' |
243 | 414 |
! ! |