author | Claus Gittinger <cg@exept.de> |
Wed, 12 Jun 1996 14:57:41 +0200 | |
changeset 762 | 832730063164 |
parent 740 | 2d5cb01c7e11 |
child 797 | 2f9cd56f48ee |
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 |
||
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 |
||
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 |
|
112 |
!FontPanel class methodsFor:'defaults'! |
|
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 |
||
162 |
!FontPanel class methodsFor:'startup'! |
|
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 |
|
0 | 209 |
|fontPanel| |
77 | 210 |
|
0 | 211 |
fontPanel := FontPanel new. |
415 | 212 |
fontPanel filter:aFilterBlock. |
413 | 213 |
someTitle notNil ifTrue:[ |
214 |
fontPanel label:someTitle |
|
215 |
]. |
|
0 | 216 |
fontPanel action:[:family :face :style :size | |
410 | 217 |
^ (Font family:family |
218 |
face:face |
|
219 |
style:style |
|
220 |
size:size) |
|
0 | 221 |
]. |
410 | 222 |
aFont notNil ifTrue:[ |
223 |
fontPanel initialFont:aFont. |
|
224 |
]. |
|
225 |
||
0 | 226 |
fontPanel showAtPointer. |
227 |
^ nil |
|
228 |
||
77 | 229 |
" |
413 | 230 |
FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font' |
77 | 231 |
" |
410 | 232 |
|
413 | 233 |
"Created: 27.2.1996 / 00:59:46 / cg" |
595 | 234 |
"Modified: 29.4.1996 / 09:45:23 / cg" |
0 | 235 |
! ! |
236 |
||
237 |
!FontPanel methodsFor:'accessing'! |
|
238 |
||
595 | 239 |
action:aFourArgBlock |
240 |
"set the action to be evaluated on ok. |
|
241 |
The block will be evaluated with family, face, style and size." |
|
242 |
||
243 |
okAction := aFourArgBlock |
|
244 |
||
245 |
"Modified: 29.4.1996 / 09:44:35 / cg" |
|
197 | 246 |
! |
247 |
||
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
248 |
encoding:aPattern |
595 | 249 |
"set the encoding goal" |
250 |
||
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
251 |
encoding := aPattern. |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
252 |
shown ifTrue:[ |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
253 |
self updateFamilyList |
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 |
|
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
256 |
"Created: 29.2.1996 / 04:05:31 / cg" |
595 | 257 |
"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
|
258 |
! |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
259 |
|
415 | 260 |
filter:aOneArgBlock |
595 | 261 |
"set a filter; if non-nil, only fonts for which the filterBlock |
262 |
returns true will be offered" |
|
263 |
||
415 | 264 |
filter := aOneArgBlock. |
265 |
shown ifTrue:[ |
|
266 |
self updateFamilyList |
|
267 |
]. |
|
268 |
||
269 |
"Created: 27.2.1996 / 01:40:08 / cg" |
|
595 | 270 |
"Modified: 29.4.1996 / 09:40:49 / cg" |
415 | 271 |
! |
272 |
||
0 | 273 |
initialFont:aFont |
128 | 274 |
"set the font to be selected initially" |
0 | 275 |
|
128 | 276 |
selectedFont := aFont. |
382 | 277 |
self showSelectedFont. |
278 |
self showPreview |
|
279 |
||
280 |
"Modified: 23.2.1996 / 00:51:32 / cg" |
|
101 | 281 |
! ! |
282 |
||
77 | 283 |
!FontPanel methodsFor:'initialization'! |
284 |
||
285 |
initialize |
|
382 | 286 |
|familyLabel faceLabel sizeLabel panel fontBrowserView v1 v2 v3 |
287 |
mm fH eH| |
|
77 | 288 |
|
289 |
super initialize. |
|
290 |
||
382 | 291 |
mm := ViewSpacing. |
292 |
||
77 | 293 |
self addAbortButton. |
294 |
self addOkButton. |
|
295 |
||
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
296 |
panel := View origin:0.0@0.0 corner:1.0@1.0 in:self. |
382 | 297 |
panel bottomInset:(buttonPanel preferredExtent y + (mm*3)). |
77 | 298 |
|
150 | 299 |
label := resources string:'Font dialog'. |
77 | 300 |
|
382 | 301 |
encodingLabel := Label label:' ' in:panel. |
302 |
eH := encodingLabel preferredExtent y. |
|
303 |
encodingLabel origin:0.7@1.0 corner:1.0@1.0. |
|
304 |
encodingLabel topInset:(eH negated); horizontalInset:mm. |
|
305 |
encodingLabel level:-1; adjust:#left. |
|
306 |
||
307 |
"/ nameLabel := Label label:' ' in:panel. |
|
308 |
"/ nameLabel origin:0.0@1.0 corner:0.7@1.0. |
|
309 |
"/ nameLabel topInset:(eH negated); horizontalInset:mm. |
|
310 |
"/ nameLabel level:-1; adjust:#left. |
|
311 |
||
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
312 |
previewField := TextView origin:0.0@0.0 corner:1.0@0.4 in:panel. |
382 | 313 |
previewField inset:mm. |
77 | 314 |
|
382 | 315 |
"/ previewField contents:self class defaultSampleString. |
77 | 316 |
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
|
317 |
previewField level:-1. |
77 | 318 |
] ifFalse:[ |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
319 |
previewField borderWidth:1. |
77 | 320 |
]. |
321 |
||
390
1d54a9b41463
say Hello world in JIS font ;-)
Claus Gittinger <cg@exept.de>
parents:
382
diff
changeset
|
322 |
fontBrowserView := View origin:0.0@0.4 corner:1.0@1.0 in:panel. |
382 | 323 |
fontBrowserView bottomInset:(eH + mm). |
77 | 324 |
|
325 |
v1 := View origin:0.0@0.0 corner:0.4@1.0 in:fontBrowserView. |
|
326 |
||
327 |
familyLabel := Label label:'Family' in:v1. |
|
328 |
familyLabel borderWidth:0. |
|
329 |
familyLabel origin:(0.0 @ 0.0) extent:(1.0 @ nil). |
|
382 | 330 |
fH := familyLabel preferredExtent y. |
77 | 331 |
|
332 |
familyList := ScrollableView for:SelectionInListView in:v1. |
|
382 | 333 |
familyList origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
334 |
familyList inset:mm. |
|
335 |
familyList topInset:fH. |
|
336 |
||
128 | 337 |
familyList := familyList scrolledView. |
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
338 |
self makeTabable:familyList. |
77 | 339 |
|
340 |
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
|
341 |
in:fontBrowserView. |
77 | 342 |
|
343 |
faceLabel := Label label:'Typeface' in:v2. |
|
344 |
faceLabel borderWidth:0. |
|
345 |
faceLabel origin:(0.0 @ 0.0) extent:(1.0 @ nil). |
|
346 |
||
347 |
faceList := ScrollableView for:SelectionInListView in:v2. |
|
382 | 348 |
faceList origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
349 |
faceList inset:mm. |
|
350 |
faceList topInset:fH. |
|
128 | 351 |
faceList := faceList scrolledView. |
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
352 |
self makeTabable:faceList. |
77 | 353 |
|
354 |
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
|
355 |
in:fontBrowserView. |
77 | 356 |
|
357 |
sizeLabel := Label label:'Size' in:v3. |
|
358 |
sizeLabel borderWidth:0. |
|
359 |
sizeLabel origin:(0.0 @ 0.0)extent:(1.0 @ nil). |
|
360 |
||
361 |
sizeList := ScrollableView for:SelectionInListView in:v3. |
|
382 | 362 |
sizeList origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
363 |
sizeList inset:mm. |
|
364 |
sizeList topInset:fH. |
|
128 | 365 |
sizeList := sizeList scrolledView. |
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
366 |
self makeTabable:sizeList. |
77 | 367 |
|
368 |
familyList action:[:lineNr | self familySelected:(familyList selectionValue)]. |
|
369 |
faceList action:[:lineNr | self faceSelected:(faceList selectionValue)]. |
|
370 |
sizeList action:[:lineNr | self sizeSelected:(sizeList selectionValue)]. |
|
371 |
||
372 |
" |
|
373 |
FontPanel new showAtPointer |
|
374 |
" |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
375 |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
376 |
"Modified: 31.5.1996 / 22:01:45 / cg" |
77 | 377 |
! |
378 |
||
197 | 379 |
realize |
380 |
"kludge for sco - xlsfont fails sometimes - try again here" |
|
381 |
||
415 | 382 |
self updateFamilyList. |
383 |
super realize |
|
384 |
||
385 |
"Modified: 27.2.1996 / 01:40:47 / cg" |
|
386 |
! |
|
387 |
||
388 |
updateFamilyList |
|
389 |
"kludge for sco - xlsfont fails sometimes - try again here" |
|
390 |
||
197 | 391 |
|families| |
77 | 392 |
|
197 | 393 |
familyList list isNil ifTrue:[ |
415 | 394 |
families := device fontFamiliesFiltering:filter. |
395 |
families notNil ifTrue:[ |
|
396 |
families := families asOrderedCollection |
|
397 |
]. |
|
398 |
familyList list:families |
|
197 | 399 |
]. |
400 |
selectedFont notNil ifTrue:[ |
|
415 | 401 |
self showSelectedFont |
197 | 402 |
]. |
415 | 403 |
|
404 |
"Modified: 27.2.1996 / 01:39:42 / cg" |
|
405 |
"Created: 27.2.1996 / 01:40:37 / cg" |
|
77 | 406 |
! ! |
407 |
||
0 | 408 |
!FontPanel methodsFor:'private'! |
409 |
||
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
410 |
clearPreview |
595 | 411 |
"clear the preview subview" |
412 |
||
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
413 |
shown ifTrue:[ |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
414 |
previewField clear. |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
415 |
encodingLabel label:''. |
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 |
|
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
418 |
"Created: 17.4.1996 / 15:19:16 / cg" |
595 | 419 |
"Modified: 29.4.1996 / 09:41:27 / cg" |
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
420 |
! |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
421 |
|
197 | 422 |
extractFaceAndStyleFrom:aString |
595 | 423 |
"given a string, extract currentFace and currentStyle" |
424 |
||
197 | 425 |
|index| |
426 |
||
427 |
index := aString indexOf:$-. |
|
428 |
(index ~~ 0) ifTrue:[ |
|
595 | 429 |
currentFaceAndStyle := aString. |
430 |
currentFace := aString copyTo:(index - 1). |
|
431 |
currentStyle := aString copyFrom:(index + 1) |
|
197 | 432 |
] |
433 |
||
595 | 434 |
"Modified: 29.4.1996 / 09:41:47 / cg" |
197 | 435 |
! |
436 |
||
437 |
showPreview |
|
595 | 438 |
"show the preview text" |
439 |
||
450 | 440 |
|f enc s all fonts scalable| |
382 | 441 |
|
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
442 |
self clearPreview. |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
443 |
|
197 | 444 |
" |
445 |
show a wait cursor: for some fonts (kanji etc) the |
|
446 |
X-server needs quites some time to load the font |
|
447 |
" |
|
255 | 448 |
self withWaitCursorDo:[ |
450 | 449 |
all := fonts := device |
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
450 |
fontsInFamily:currentFamily |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
451 |
face:currentFace |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
452 |
style:currentStyle |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
453 |
filtering:filter. |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
454 |
|
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
455 |
fonts := fonts select:[:f | f size == currentSize]. |
450 | 456 |
fonts notEmpty ifTrue:[ |
457 |
f := fonts anElement. |
|
458 |
] ifFalse:[ |
|
459 |
"/ mhmh |
|
460 |
"/ X returns size0 for scalable fonts. Any size is possible. |
|
461 |
"/ |
|
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
462 |
|
450 | 463 |
fonts := all select:[:f | f size == 0]. |
464 |
fonts notEmpty ifTrue:[ |
|
465 |
f := Font family:currentFamily |
|
466 |
face:currentFace |
|
467 |
style:currentStyle |
|
468 |
size:currentSize |
|
469 |
encoding:(fonts anElement encoding). |
|
470 |
] ifFalse:[ |
|
471 |
^ self |
|
472 |
] |
|
473 |
]. |
|
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
474 |
|
540 | 475 |
f := f on:device. |
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
476 |
previewField font:f. |
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
477 |
|
382 | 478 |
enc := f encoding. |
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
479 |
enc isNil ifTrue:[enc := 'ascii ?']. |
382 | 480 |
encodingLabel label:enc. |
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
481 |
|
382 | 482 |
nameLabel notNil ifTrue:[nameLabel label:(f fullName)]. |
483 |
||
399 | 484 |
(enc notNil and:[enc startsWith:'jis']) ifTrue:[ |
382 | 485 |
s := self class defaultJISSampleString |
486 |
] ifFalse:[ |
|
487 |
s := self class defaultRomanSampleString. |
|
488 |
]. |
|
434
22586d8221e1
dont get confused by same-name but different encoding
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
489 |
previewField contents:s. |
197 | 490 |
] |
255 | 491 |
|
595 | 492 |
"Modified: 29.4.1996 / 09:42:01 / cg" |
197 | 493 |
! |
494 |
||
128 | 495 |
showSelectedFont |
496 |
|fam face style sz| |
|
497 |
||
498 |
fam := selectedFont family. |
|
499 |
fam notNil ifTrue:[ |
|
500 |
self familySelected:fam. |
|
501 |
face := selectedFont face. |
|
502 |
face notNil ifTrue:[ |
|
503 |
style := selectedFont style. |
|
504 |
style notNil ifTrue:[ |
|
505 |
self faceSelected:(face , '-' , style). |
|
506 |
sz := selectedFont size. |
|
507 |
sz notNil ifTrue:[ |
|
508 |
self sizeSelected:sz |
|
509 |
] |
|
510 |
] |
|
511 |
] |
|
512 |
] |
|
197 | 513 |
! ! |
128 | 514 |
|
197 | 515 |
!FontPanel methodsFor:'queries'! |
0 | 516 |
|
197 | 517 |
preferredExtent |
595 | 518 |
"return the boxes preferredExtent" |
572 | 519 |
|
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
520 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
521 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
522 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
523 |
|
197 | 524 |
^ 400@350 |
572 | 525 |
|
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
526 |
"Modified: 29.5.1996 / 12:12:47 / cg" |
0 | 527 |
! ! |
77 | 528 |
|
529 |
!FontPanel methodsFor:'user interaction'! |
|
530 |
||
197 | 531 |
faceSelected:aFaceAndStyleName |
595 | 532 |
"a fonts face was seleted; find available sizes and update lists" |
533 |
||
197 | 534 |
|sizes| |
535 |
||
536 |
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
|
537 |
self extractFaceAndStyleFrom:aFaceAndStyleName. |
197 | 538 |
]. |
539 |
sizes := device |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
540 |
sizesInFamily:currentFamily |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
541 |
face:currentFace |
415 | 542 |
style:currentStyle |
543 |
filtering:filter. |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
544 |
|
197 | 545 |
(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
|
546 |
sizeList list:nil. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
547 |
currentSize := nil. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
548 |
self showPreview. |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
549 |
^ self |
197 | 550 |
]. |
551 |
||
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
552 |
self clearPreview. |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
553 |
|
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
554 |
sizes := (sizes asOrderedCollection sort) collect:[:entry | entry printString]. |
197 | 555 |
sizeList list:sizes. |
556 |
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
|
557 |
(sizes includes:(currentSize printString)) ifTrue:[ |
690 | 558 |
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
|
559 |
self showPreview |
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
560 |
] |
197 | 561 |
] |
251
25f76efaa547
oops - dont pass a collection of numbers to the size-view
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
562 |
|
690 | 563 |
"Modified: 26.5.1996 / 15:03:24 / cg" |
197 | 564 |
! |
565 |
||
77 | 566 |
familySelected:aFamilyName |
595 | 567 |
"a fonts family was seleted; find available faces and update lists" |
568 |
||
77 | 569 |
|faces styles list| |
570 |
||
690 | 571 |
familyList setSelectElement:aFamilyName. |
77 | 572 |
|
573 |
currentFamily := aFamilyName. |
|
415 | 574 |
faces := device facesInFamily:aFamilyName filtering:filter. |
77 | 575 |
(faces isNil or:[faces isEmpty]) ifTrue:[ |
415 | 576 |
currentFace := currentStyle := currentFaceAndStyle := nil. |
577 |
faceList list:nil. |
|
578 |
self faceSelected:nil. |
|
579 |
^ self. |
|
77 | 580 |
]. |
581 |
||
582 |
list := OrderedCollection new. |
|
583 |
faces do:[:aFace | |
|
415 | 584 |
styles := device stylesInFamily:aFamilyName face:aFace filtering:filter. |
585 |
styles do:[:aStyle | |
|
586 |
list add:(aFace , '-' , aStyle) |
|
587 |
] |
|
77 | 588 |
]. |
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
589 |
|
77 | 590 |
faceList list:list. |
591 |
currentFaceAndStyle notNil ifTrue:[ |
|
415 | 592 |
(list includes:currentFaceAndStyle) ifTrue:[ |
690 | 593 |
faceList setSelectElement:currentFaceAndStyle. |
415 | 594 |
self faceSelected:currentFaceAndStyle. |
595 |
^ self |
|
596 |
] |
|
77 | 597 |
]. |
541
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
598 |
sizeList list:nil. |
76018ea821ca
clear preview & encoding when no font is shown
Claus Gittinger <cg@exept.de>
parents:
540
diff
changeset
|
599 |
self clearPreview. |
415 | 600 |
|
690 | 601 |
"Modified: 26.5.1996 / 15:04:29 / cg" |
77 | 602 |
! |
603 |
||
604 |
okPressed |
|
595 | 605 |
"ok was pressed; hide myself and evaluate the okAction, passing |
606 |
family, face, style and size as arguments" |
|
607 |
||
77 | 608 |
self hide. |
609 |
okAction notNil ifTrue:[ |
|
410 | 610 |
currentFamily notNil ifTrue:[ |
595 | 611 |
okAction |
612 |
value:currentFamily |
|
410 | 613 |
value:currentFace |
614 |
value:currentStyle |
|
615 |
value:currentSize |
|
616 |
] |
|
77 | 617 |
] |
410 | 618 |
|
595 | 619 |
"Modified: 29.4.1996 / 09:44:08 / cg" |
77 | 620 |
! |
621 |
||
622 |
sizeSelected:aNumberOrString |
|
595 | 623 |
"a size was seleted; update preview" |
624 |
||
77 | 625 |
aNumberOrString isNumber ifTrue:[ |
595 | 626 |
currentSize := aNumberOrString |
77 | 627 |
] ifFalse:[ |
595 | 628 |
currentSize := Number readFromString:aNumberOrString |
77 | 629 |
]. |
630 |
self showPreview |
|
595 | 631 |
|
632 |
"Modified: 29.4.1996 / 09:43:23 / cg" |
|
77 | 633 |
! ! |
197 | 634 |
|
243 | 635 |
!FontPanel class methodsFor:'documentation'! |
636 |
||
637 |
version |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
638 |
^ '$Header: /cvs/stx/stx/libwidg/FontPanel.st,v 1.37 1996-05-31 20:18:25 cg Exp $' |
243 | 639 |
! ! |