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