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