author | Claus Gittinger <cg@exept.de> |
Fri, 29 Sep 2000 09:42:44 +0200 | |
changeset 2287 | b33ad40d7538 |
parent 2286 | 2a1a6b7cb322 |
child 2353 | 0d373c7046f7 |
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 |
||
2275 | 15 |
"{ Package: 'stx:libwidg' }" |
16 |
||
77 | 17 |
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
|
18 |
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
|
19 |
currentFamily currentFace currentStyle currentFaceAndStyle |
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
20 |
currentSize selectedFont nameLabel encodingLabel filter encoding' |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
21 |
classVariableNames:'' |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
22 |
poolDictionaries:'' |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
23 |
category:'Views-DialogBoxes' |
0 | 24 |
! |
25 |
||
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
26 |
!FontPanel class methodsFor:'documentation'! |
77 | 27 |
|
197 | 28 |
copyright |
29 |
" |
|
30 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
31 |
All Rights Reserved |
|
32 |
||
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
||
41 |
||
77 | 42 |
! |
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
this class implements a font chooser. |
|
47 |
||
595 | 48 |
[author:] |
49 |
Claus Gittinger |
|
50 |
||
51 |
[see also:] |
|
52 |
Font FontDescription |
|
53 |
View Dialog |
|
54 |
" |
|
55 |
! |
|
56 |
||
57 |
examples |
|
58 |
" |
|
59 |
very simple: |
|
60 |
[exBegin] |
|
61 |
|font| |
|
62 |
||
63 |
font := FontPanel fontFromUser. |
|
655 | 64 |
Transcript showCR:font |
595 | 65 |
[exEnd] |
66 |
||
67 |
||
68 |
with initial font: |
|
69 |
[exBegin] |
|
70 |
|font| |
|
71 |
||
72 |
font := FontPanel |
|
73 |
fontFromUserInitial:(Font |
|
74 |
family:'courier' |
|
75 |
size:12). |
|
655 | 76 |
Transcript showCR:font |
595 | 77 |
[exEnd] |
78 |
||
79 |
||
80 |
with initial font & title: |
|
81 |
[exBegin] |
|
82 |
|font| |
|
83 |
||
84 |
font := FontPanel |
|
85 |
fontFromUserInitial:(Font |
|
86 |
family:'courier' |
|
87 |
size:12) |
|
88 |
title:'select a fooBar font'. |
|
655 | 89 |
Transcript showCR:font |
595 | 90 |
[exEnd] |
91 |
||
92 |
||
93 |
full setup; setting a filter to only present iso fonts |
|
94 |
and callBack action: |
|
95 |
[exBegin] |
|
0 | 96 |
|
585 | 97 |
|panel| |
77 | 98 |
|
585 | 99 |
panel := FontPanel new. |
595 | 100 |
panel label:'hi there - which iso font ?'. |
101 |
panel filter:[:fd | fd encoding notNil |
|
102 |
and:[fd encoding startsWith:'iso']]. |
|
103 |
panel action:[:family :face :style :size | |
|
655 | 104 |
Transcript showCR:'family:' , family. |
105 |
Transcript showCR:'face:' , face. |
|
106 |
Transcript showCR:'style:' , style. |
|
107 |
Transcript showCR:'size:' , size printString. |
|
595 | 108 |
]. |
109 |
panel open |
|
110 |
[exEnd] |
|
77 | 111 |
" |
112 |
! ! |
|
0 | 113 |
|
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
114 |
!FontPanel class methodsFor:'defaults'! |
0 | 115 |
|
197 | 116 |
defaultExtent |
571 | 117 |
"return the default extent of my instances. |
118 |
The value returned here is usually ignored, and |
|
119 |
the value from preferredExtent taken instead." |
|
120 |
||
197 | 121 |
^ (Screen current pixelPerMillimeter * (120 @ 100)) rounded |
571 | 122 |
|
123 |
"Modified: 22.4.1996 / 23:36:19 / cg" |
|
197 | 124 |
! |
125 |
||
382 | 126 |
defaultJISSampleString |
595 | 127 |
"return the sample jis preview text" |
128 |
||
382 | 129 |
^ ('The quick brown fox |
130 |
jumps over the lazy dog |
|
131 |
1234567890 |
|
132 |
!!@#$%^&*(){}[]:"~;,./<>? |
|
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
133 |
|
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
134 |
\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
|
135 |
' withEscapes decodeFrom:#jis7) |
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
136 |
|
595 | 137 |
"Modified: 29.4.1996 / 09:46:11 / cg" |
382 | 138 |
! |
139 |
||
140 |
defaultRomanSampleString |
|
595 | 141 |
"return the sample roman preview text" |
142 |
||
2275 | 143 |
|t| |
144 |
||
2286 | 145 |
Smalltalk language == #de ifTrue:[ |
2275 | 146 |
t := 'Franz jagt im komplett verwahrlosten Taxi |
147 |
quer durch Bayern'. |
|
148 |
] ifFalse:[ |
|
149 |
t := 'The quick brown fox |
|
150 |
jumps over the lazy dog'. |
|
151 |
]. |
|
152 |
t := t , ' |
|
110 | 153 |
1234567890 |
154 |
!!@#$%^&*(){}[]:"~;,./<>? |
|
155 |
' , |
|
398 | 156 |
(Character value:16rE4) asString , "/ umlaut a |
157 |
(Character value:16rF6) asString , "/ umlaut o |
|
158 |
(Character value:16rFC) asString , "/ umlaut u |
|
159 |
(Character value:16rC4) asString , "/ umlaut A |
|
160 |
(Character value:16rD6) asString , "/ umlaut O |
|
161 |
(Character value:16rDC) asString , "/ umlaut U |
|
162 |
(Character value:16rDF) asString , "/ sz |
|
163 |
(Character value:233) asString , "/ e-degu |
|
164 |
(Character value:232) asString , "/ e-grave |
|
165 |
(Character value:234) asString , "/ e-circonflex |
|
166 |
(Character value:197) asString , "/ A |
|
2276 | 167 |
(Character value:169) asString. "/ copyright |
168 |
^ t |
|
398 | 169 |
|
595 | 170 |
"Modified: 29.4.1996 / 09:46:19 / cg" |
0 | 171 |
! ! |
172 |
||
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
173 |
!FontPanel class methodsFor:'startup'! |
0 | 174 |
|
175 |
fontFromUser |
|
77 | 176 |
"open a fontPanel and return the selected font, or nil |
177 |
if abort is pressed" |
|
178 |
||
410 | 179 |
^ self fontFromUserInitial:nil |
180 |
||
181 |
" |
|
182 |
FontPanel fontFromUser |
|
183 |
" |
|
184 |
||
185 |
"Modified: 27.2.1996 / 00:51:59 / cg" |
|
186 |
! |
|
187 |
||
188 |
fontFromUserInitial:aFont |
|
595 | 189 |
"open a fontPanel showing aFont initially, |
190 |
and return the selected font, or nil if abort is pressed" |
|
410 | 191 |
|
413 | 192 |
^ self fontFromUserInitial:aFont title:nil |
193 |
||
194 |
" |
|
195 |
FontPanel fontFromUserInitial:(Font family:'courier' size:12) |
|
196 |
" |
|
197 |
||
198 |
"Created: 27.2.1996 / 00:51:44 / cg" |
|
595 | 199 |
"Modified: 29.4.1996 / 09:45:52 / cg" |
413 | 200 |
! |
201 |
||
202 |
fontFromUserInitial:aFont title:someTitle |
|
595 | 203 |
"open a fontPanel with title and return the selected font, |
204 |
or nil if abort is pressed" |
|
413 | 205 |
|
415 | 206 |
^ self fontFromUserInitial:aFont title:someTitle filter:nil |
207 |
||
208 |
" |
|
209 |
FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font' |
|
210 |
" |
|
211 |
||
212 |
"Created: 27.2.1996 / 00:59:46 / cg" |
|
595 | 213 |
"Modified: 29.4.1996 / 09:45:34 / cg" |
415 | 214 |
! |
215 |
||
216 |
fontFromUserInitial:aFont title:someTitle filter:aFilterBlock |
|
595 | 217 |
"open a fontPanel with title and font-filter |
218 |
and return the selected font, or nil if abort is pressed" |
|
415 | 219 |
|
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
220 |
|fontPanel selectedFont| |
77 | 221 |
|
0 | 222 |
fontPanel := FontPanel new. |
415 | 223 |
fontPanel filter:aFilterBlock. |
413 | 224 |
someTitle notNil ifTrue:[ |
225 |
fontPanel label:someTitle |
|
226 |
]. |
|
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
227 |
fontPanel action:[:aFontDescription | selectedFont := aFontDescription]. |
410 | 228 |
aFont notNil ifTrue:[ |
229 |
fontPanel initialFont:aFont. |
|
230 |
]. |
|
231 |
||
0 | 232 |
fontPanel showAtPointer. |
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
233 |
fontPanel destroy. |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
234 |
^ selectedFont |
0 | 235 |
|
77 | 236 |
" |
413 | 237 |
FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font' |
77 | 238 |
" |
410 | 239 |
|
413 | 240 |
"Created: 27.2.1996 / 00:59:46 / cg" |
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
241 |
"Modified: 10.4.1997 / 09:53:03 / cg" |
0 | 242 |
! ! |
243 |
||
244 |
!FontPanel methodsFor:'accessing'! |
|
245 |
||
595 | 246 |
action:aFourArgBlock |
247 |
"set the action to be evaluated on ok. |
|
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
248 |
The block will be evaluated with family, face, style, size and encoding." |
595 | 249 |
|
250 |
okAction := aFourArgBlock |
|
251 |
||
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
252 |
"Modified: 10.4.1997 / 09:49:58 / cg" |
197 | 253 |
! |
254 |
||
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
255 |
encoding:aPattern |
595 | 256 |
"set the encoding goal" |
257 |
||
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
258 |
encoding := aPattern. |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
259 |
shown ifTrue:[ |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
260 |
self updateFamilyList |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
261 |
]. |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
262 |
|
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
263 |
"Created: 29.2.1996 / 04:05:31 / cg" |
595 | 264 |
"Modified: 29.4.1996 / 09:40:18 / cg" |
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
265 |
! |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
266 |
|
415 | 267 |
filter:aOneArgBlock |
595 | 268 |
"set a filter; if non-nil, only fonts for which the filterBlock |
269 |
returns true will be offered" |
|
270 |
||
415 | 271 |
filter := aOneArgBlock. |
272 |
shown ifTrue:[ |
|
273 |
self updateFamilyList |
|
274 |
]. |
|
275 |
||
276 |
"Created: 27.2.1996 / 01:40:08 / cg" |
|
595 | 277 |
"Modified: 29.4.1996 / 09:40:49 / cg" |
415 | 278 |
! |
279 |
||
0 | 280 |
initialFont:aFont |
128 | 281 |
"set the font to be selected initially" |
0 | 282 |
|
128 | 283 |
selectedFont := aFont. |
382 | 284 |
self showSelectedFont. |
285 |
self showPreview |
|
286 |
||
287 |
"Modified: 23.2.1996 / 00:51:32 / cg" |
|
101 | 288 |
! ! |
289 |
||
77 | 290 |
!FontPanel methodsFor:'initialization'! |
291 |
||
292 |
initialize |
|
382 | 293 |
|familyLabel faceLabel sizeLabel panel fontBrowserView v1 v2 v3 |
294 |
mm fH eH| |
|
77 | 295 |
|
296 |
super initialize. |
|
297 |
||
382 | 298 |
mm := ViewSpacing. |
299 |
||
1763 | 300 |
self addAbortAndOkButtons. |
77 | 301 |
|
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
302 |
panel := View origin:0.0@0.0 corner:1.0@1.0 in:self. |
382 | 303 |
panel bottomInset:(buttonPanel preferredExtent y + (mm*3)). |
77 | 304 |
|
150 | 305 |
label := resources string:'Font dialog'. |
77 | 306 |
|
382 | 307 |
encodingLabel := Label label:' ' in:panel. |
308 |
eH := encodingLabel preferredExtent y. |
|
309 |
encodingLabel origin:0.7@1.0 corner:1.0@1.0. |
|
310 |
encodingLabel topInset:(eH negated); horizontalInset:mm. |
|
311 |
encodingLabel level:-1; adjust:#left. |
|
312 |
||
313 |
"/ nameLabel := Label label:' ' in:panel. |
|
314 |
"/ nameLabel origin:0.0@1.0 corner:0.7@1.0. |
|
315 |
"/ nameLabel topInset:(eH negated); horizontalInset:mm. |
|
316 |
"/ nameLabel level:-1; adjust:#left. |
|
317 |
||
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
318 |
previewField := TextView origin:0.0@0.0 corner:1.0@0.4 in:panel. |
382 | 319 |
previewField inset:mm. |
77 | 320 |
|
382 | 321 |
"/ previewField contents:self class defaultSampleString. |
77 | 322 |
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
|
323 |
previewField level:-1. |
77 | 324 |
] ifFalse:[ |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
325 |
previewField borderWidth:1. |
77 | 326 |
]. |
327 |
||
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
328 |
fontBrowserView := View origin:0.0@0.4 corner:1.0@1.0 in:panel. |
382 | 329 |
fontBrowserView bottomInset:(eH + mm). |
77 | 330 |
|
331 |
v1 := View origin:0.0@0.0 corner:0.4@1.0 in:fontBrowserView. |
|
332 |
||
333 |
familyLabel := Label label:'Family' in:v1. |
|
334 |
familyLabel borderWidth:0. |
|
335 |
familyLabel origin:(0.0 @ 0.0) extent:(1.0 @ nil). |
|
382 | 336 |
fH := familyLabel preferredExtent y. |
77 | 337 |
|
338 |
familyList := ScrollableView for:SelectionInListView in:v1. |
|
382 | 339 |
familyList origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
340 |
familyList inset:mm. |
|
341 |
familyList topInset:fH. |
|
342 |
||
128 | 343 |
familyList := familyList scrolledView. |
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
344 |
self makeTabable:familyList. |
77 | 345 |
|
346 |
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
|
347 |
in:fontBrowserView. |
77 | 348 |
|
349 |
faceLabel := Label label:'Typeface' in:v2. |
|
350 |
faceLabel borderWidth:0. |
|
351 |
faceLabel origin:(0.0 @ 0.0) extent:(1.0 @ nil). |
|
352 |
||
353 |
faceList := ScrollableView for:SelectionInListView in:v2. |
|
382 | 354 |
faceList origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
355 |
faceList inset:mm. |
|
356 |
faceList topInset:fH. |
|
128 | 357 |
faceList := faceList scrolledView. |
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
358 |
self makeTabable:faceList. |
77 | 359 |
|
360 |
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
|
361 |
in:fontBrowserView. |
77 | 362 |
|
363 |
sizeLabel := Label label:'Size' in:v3. |
|
364 |
sizeLabel borderWidth:0. |
|
365 |
sizeLabel origin:(0.0 @ 0.0)extent:(1.0 @ nil). |
|
366 |
||
367 |
sizeList := ScrollableView for:SelectionInListView in:v3. |
|
382 | 368 |
sizeList origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
369 |
sizeList inset:mm. |
|
370 |
sizeList topInset:fH. |
|
128 | 371 |
sizeList := sizeList scrolledView. |
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
372 |
self makeTabable:sizeList. |
77 | 373 |
|
374 |
familyList action:[:lineNr | self familySelected:(familyList selectionValue)]. |
|
375 |
faceList action:[:lineNr | self faceSelected:(faceList selectionValue)]. |
|
376 |
sizeList action:[:lineNr | self sizeSelected:(sizeList selectionValue)]. |
|
377 |
||
378 |
" |
|
379 |
FontPanel new showAtPointer |
|
380 |
" |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
381 |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
382 |
"Modified: 31.5.1996 / 22:01:45 / cg" |
77 | 383 |
! |
384 |
||
1277 | 385 |
postRealize |
197 | 386 |
"kludge for sco - xlsfont fails sometimes - try again here" |
387 |
||
415 | 388 |
self updateFamilyList. |
1277 | 389 |
super postRealize |
415 | 390 |
|
391 |
"Modified: 27.2.1996 / 01:40:47 / cg" |
|
1277 | 392 |
"Created: 24.7.1997 / 18:12:42 / cg" |
415 | 393 |
! |
394 |
||
395 |
updateFamilyList |
|
396 |
"kludge for sco - xlsfont fails sometimes - try again here" |
|
397 |
||
197 | 398 |
|families| |
77 | 399 |
|
197 | 400 |
familyList list isNil ifTrue:[ |
415 | 401 |
families := device fontFamiliesFiltering:filter. |
402 |
families notNil ifTrue:[ |
|
403 |
families := families asOrderedCollection |
|
404 |
]. |
|
405 |
familyList list:families |
|
197 | 406 |
]. |
407 |
selectedFont notNil ifTrue:[ |
|
415 | 408 |
self showSelectedFont |
197 | 409 |
]. |
415 | 410 |
|
411 |
"Modified: 27.2.1996 / 01:39:42 / cg" |
|
412 |
"Created: 27.2.1996 / 01:40:37 / cg" |
|
77 | 413 |
! ! |
414 |
||
0 | 415 |
!FontPanel methodsFor:'private'! |
416 |
||
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
417 |
clearPreview |
595 | 418 |
"clear the preview subview" |
419 |
||
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
420 |
shown ifTrue:[ |
1297
f5ea02391a59
use #contents: instead of #clear
Claus Gittinger <cg@exept.de>
parents:
1284
diff
changeset
|
421 |
previewField contents:nil. |
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
422 |
encodingLabel label:''. |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
423 |
]. |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
424 |
|
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
425 |
"Created: 17.4.1996 / 15:19:16 / cg" |
1297
f5ea02391a59
use #contents: instead of #clear
Claus Gittinger <cg@exept.de>
parents:
1284
diff
changeset
|
426 |
"Modified: 11.8.1997 / 03:01:42 / cg" |
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
427 |
! |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
428 |
|
197 | 429 |
extractFaceAndStyleFrom:aString |
595 | 430 |
"given a string, extract currentFace and currentStyle" |
431 |
||
197 | 432 |
|index| |
433 |
||
434 |
index := aString indexOf:$-. |
|
435 |
(index ~~ 0) ifTrue:[ |
|
595 | 436 |
currentFaceAndStyle := aString. |
437 |
currentFace := aString copyTo:(index - 1). |
|
438 |
currentStyle := aString copyFrom:(index + 1) |
|
197 | 439 |
] |
440 |
||
595 | 441 |
"Modified: 29.4.1996 / 09:41:47 / cg" |
197 | 442 |
! |
443 |
||
444 |
showPreview |
|
595 | 445 |
"show the preview text" |
446 |
||
1284 | 447 |
|f enc s all fonts| |
382 | 448 |
|
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
449 |
self clearPreview. |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
450 |
|
197 | 451 |
" |
452 |
show a wait cursor: for some fonts (kanji etc) the |
|
453 |
X-server needs quites some time to load the font |
|
454 |
" |
|
255 | 455 |
self withWaitCursorDo:[ |
450 | 456 |
all := fonts := device |
1257 | 457 |
fontsInFamily:(currentFamily ? '*') |
458 |
face:(currentFace ? '*') |
|
459 |
style:(currentStyle ? '*') |
|
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
460 |
filtering:filter. |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
461 |
|
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
462 |
fonts := fonts select:[:f | f size == currentSize]. |
450 | 463 |
fonts notEmpty ifTrue:[ |
464 |
f := fonts anElement. |
|
465 |
] ifFalse:[ |
|
466 |
"/ mhmh |
|
467 |
"/ X returns size0 for scalable fonts. Any size is possible. |
|
468 |
"/ |
|
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
469 |
|
450 | 470 |
fonts := all select:[:f | f size == 0]. |
471 |
fonts notEmpty ifTrue:[ |
|
472 |
f := Font family:currentFamily |
|
473 |
face:currentFace |
|
474 |
style:currentStyle |
|
475 |
size:currentSize |
|
476 |
encoding:(fonts anElement encoding). |
|
477 |
] |
|
478 |
]. |
|
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
479 |
|
2287
b33ad40d7538
preview fixed when font is bad
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
480 |
f notNil ifTrue:[ |
b33ad40d7538
preview fixed when font is bad
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
481 |
f := f onDevice:device. |
b33ad40d7538
preview fixed when font is bad
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
482 |
previewField font:f. |
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
483 |
|
2287
b33ad40d7538
preview fixed when font is bad
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
484 |
enc := f encoding. |
b33ad40d7538
preview fixed when font is bad
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
485 |
enc isNil ifTrue:[enc := 'ascii ?']. |
b33ad40d7538
preview fixed when font is bad
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
486 |
encodingLabel label:enc. |
b33ad40d7538
preview fixed when font is bad
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
487 |
]. |
382 | 488 |
nameLabel notNil ifTrue:[nameLabel label:(f fullName)]. |
489 |
||
399 | 490 |
(enc notNil and:[enc startsWith:'jis']) ifTrue:[ |
382 | 491 |
s := self class defaultJISSampleString |
492 |
] ifFalse:[ |
|
493 |
s := self class defaultRomanSampleString. |
|
494 |
]. |
|
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
495 |
previewField contents:s. |
197 | 496 |
] |
255 | 497 |
|
1257 | 498 |
"Modified: 30.6.1997 / 17:26:22 / cg" |
197 | 499 |
! |
500 |
||
128 | 501 |
showSelectedFont |
502 |
|fam face style sz| |
|
503 |
||
504 |
fam := selectedFont family. |
|
505 |
fam notNil ifTrue:[ |
|
506 |
self familySelected:fam. |
|
507 |
face := selectedFont face. |
|
508 |
face notNil ifTrue:[ |
|
509 |
style := selectedFont style. |
|
510 |
style notNil ifTrue:[ |
|
511 |
self faceSelected:(face , '-' , style). |
|
512 |
sz := selectedFont size. |
|
513 |
sz notNil ifTrue:[ |
|
514 |
self sizeSelected:sz |
|
515 |
] |
|
516 |
] |
|
517 |
] |
|
518 |
] |
|
197 | 519 |
! ! |
128 | 520 |
|
197 | 521 |
!FontPanel methodsFor:'queries'! |
0 | 522 |
|
197 | 523 |
preferredExtent |
595 | 524 |
"return the boxes preferredExtent" |
572 | 525 |
|
797 | 526 |
"/ If I have an explicit preferredExtent .. |
527 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
528 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
529 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
530 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
531 |
|
197 | 532 |
^ 400@350 |
572 | 533 |
|
797 | 534 |
"Modified: 19.7.1996 / 20:44:08 / cg" |
0 | 535 |
! ! |
77 | 536 |
|
537 |
!FontPanel methodsFor:'user interaction'! |
|
538 |
||
197 | 539 |
faceSelected:aFaceAndStyleName |
595 | 540 |
"a fonts face was seleted; find available sizes and update lists" |
541 |
||
197 | 542 |
|sizes| |
543 |
||
544 |
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
|
545 |
self extractFaceAndStyleFrom:aFaceAndStyleName. |
197 | 546 |
]. |
547 |
sizes := device |
|
1257 | 548 |
sizesInFamily:(currentFamily ? '*') |
549 |
face:(currentFace ? '*') |
|
550 |
style:(currentStyle ? '*') |
|
415 | 551 |
filtering:filter. |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
552 |
|
197 | 553 |
(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
|
554 |
sizeList list:nil. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
555 |
currentSize := nil. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
556 |
self showPreview. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
557 |
^ self |
197 | 558 |
]. |
559 |
||
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
560 |
self clearPreview. |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
561 |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
562 |
sizes := (sizes asOrderedCollection sort) collect:[:entry | entry printString]. |
197 | 563 |
sizeList list:sizes. |
564 |
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
|
565 |
(sizes includes:(currentSize printString)) ifTrue:[ |
2170 | 566 |
sizeList setSelectElement:currentSize printString. |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
567 |
self showPreview |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
568 |
] |
197 | 569 |
] |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
570 |
|
1257 | 571 |
"Modified: 30.6.1997 / 17:25:46 / cg" |
197 | 572 |
! |
573 |
||
77 | 574 |
familySelected:aFamilyName |
595 | 575 |
"a fonts family was seleted; find available faces and update lists" |
576 |
||
77 | 577 |
|faces styles list| |
578 |
||
690 | 579 |
familyList setSelectElement:aFamilyName. |
77 | 580 |
|
581 |
currentFamily := aFamilyName. |
|
415 | 582 |
faces := device facesInFamily:aFamilyName filtering:filter. |
77 | 583 |
(faces isNil or:[faces isEmpty]) ifTrue:[ |
415 | 584 |
currentFace := currentStyle := currentFaceAndStyle := nil. |
585 |
faceList list:nil. |
|
586 |
self faceSelected:nil. |
|
587 |
^ self. |
|
77 | 588 |
]. |
589 |
||
590 |
list := OrderedCollection new. |
|
591 |
faces do:[:aFace | |
|
415 | 592 |
styles := device stylesInFamily:aFamilyName face:aFace filtering:filter. |
593 |
styles do:[:aStyle | |
|
594 |
list add:(aFace , '-' , aStyle) |
|
595 |
] |
|
77 | 596 |
]. |
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
597 |
|
77 | 598 |
faceList list:list. |
599 |
currentFaceAndStyle notNil ifTrue:[ |
|
415 | 600 |
(list includes:currentFaceAndStyle) ifTrue:[ |
690 | 601 |
faceList setSelectElement:currentFaceAndStyle. |
415 | 602 |
self faceSelected:currentFaceAndStyle. |
603 |
^ self |
|
604 |
] |
|
77 | 605 |
]. |
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
606 |
sizeList list:nil. |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
607 |
self clearPreview. |
415 | 608 |
|
690 | 609 |
"Modified: 26.5.1996 / 15:04:29 / cg" |
77 | 610 |
! |
611 |
||
612 |
okPressed |
|
595 | 613 |
"ok was pressed; hide myself and evaluate the okAction, passing |
614 |
family, face, style and size as arguments" |
|
615 |
||
77 | 616 |
self hide. |
617 |
okAction notNil ifTrue:[ |
|
410 | 618 |
currentFamily notNil ifTrue:[ |
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
619 |
okAction value:(FontDescription |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
620 |
family:currentFamily |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
621 |
face:currentFace |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
622 |
style:currentStyle |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
623 |
size:currentSize |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
624 |
encoding:encoding). |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
625 |
|
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
626 |
"/ okAction |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
627 |
"/ value:currentFamily |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
628 |
"/ value:currentFace |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
629 |
"/ value:currentStyle |
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
630 |
"/ value:currentSize |
410 | 631 |
] |
77 | 632 |
] |
410 | 633 |
|
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
634 |
"Modified: 10.4.1997 / 09:51:31 / cg" |
77 | 635 |
! |
636 |
||
637 |
sizeSelected:aNumberOrString |
|
595 | 638 |
"a size was seleted; update preview" |
639 |
||
77 | 640 |
aNumberOrString isNumber ifTrue:[ |
595 | 641 |
currentSize := aNumberOrString |
77 | 642 |
] ifFalse:[ |
595 | 643 |
currentSize := Number readFromString:aNumberOrString |
77 | 644 |
]. |
645 |
self showPreview |
|
595 | 646 |
|
647 |
"Modified: 29.4.1996 / 09:43:23 / cg" |
|
77 | 648 |
! ! |
197 | 649 |
|
1185
3b8bd5ea8d62
action block is evaluated with a fontDescription
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
650 |
!FontPanel class methodsFor:'documentation'! |
243 | 651 |
|
652 |
version |
|
2287
b33ad40d7538
preview fixed when font is bad
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
653 |
^ '$Header: /cvs/stx/stx/libwidg/FontPanel.st,v 1.50 2000-09-29 07:42:44 cg Exp $' |
243 | 654 |
! ! |