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