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