412
|
1 |
MenuPanel subclass:#FontMenu
|
|
2 |
instanceVariableNames:'model enabledChannel fontFamily fontFace fontStyle fontSize'
|
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Interface-UIPainter'
|
|
6 |
!
|
|
7 |
|
|
8 |
!FontMenu class methodsFor:'documentation'!
|
|
9 |
|
|
10 |
documentation
|
|
11 |
"
|
|
12 |
FontMenu used by UIPainter
|
|
13 |
|
|
14 |
[see also:]
|
|
15 |
UIPainter
|
|
16 |
FontMenuSpec
|
|
17 |
"
|
|
18 |
|
|
19 |
|
|
20 |
!
|
|
21 |
|
|
22 |
examples
|
|
23 |
"
|
|
24 |
simple example
|
|
25 |
[exBegin]
|
|
26 |
|top|
|
|
27 |
|
|
28 |
top := StandardSystemView new.
|
|
29 |
top extent:250@30.
|
|
30 |
self origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
31 |
top open.
|
|
32 |
[exEnd]
|
|
33 |
"
|
|
34 |
! !
|
|
35 |
|
|
36 |
!FontMenu class methodsFor:'menu spec'!
|
|
37 |
|
|
38 |
menu
|
|
39 |
|
|
40 |
^ #(#Menu #(
|
|
41 |
(#MenuItem
|
|
42 |
#'label:' ''
|
|
43 |
#'indication:' false
|
|
44 |
)
|
|
45 |
(#MenuItem
|
|
46 |
#'label:' 'family'
|
|
47 |
#'value:' #fontFamily:
|
|
48 |
#'submenu:'
|
|
49 |
#(#Menu #( #(#MenuItem #'label:' 'helvetica' value:#helvetica )
|
|
50 |
#(#MenuItem #'label:' 'courier' value:#courier )
|
|
51 |
#(#MenuItem #'label:' 'times' value:#times )
|
|
52 |
#(#MenuItem #'label:' 'clean' value:#clean )
|
|
53 |
#(#MenuItem #'label:' 'fixed' value:#fixed )
|
|
54 |
#(#MenuItem #'label:' 'lucida' value:#lucida )
|
|
55 |
)
|
|
56 |
nil
|
|
57 |
nil
|
|
58 |
)
|
|
59 |
)
|
|
60 |
(#MenuItem
|
|
61 |
#'label:' 'face'
|
|
62 |
#'value:' #fontFace:
|
|
63 |
#'submenu:'
|
|
64 |
#(#Menu #( #(#MenuItem #label: 'bold' value:#bold )
|
|
65 |
#(#MenuItem #label: 'medium' value:#medium )
|
|
66 |
)
|
|
67 |
nil
|
|
68 |
nil
|
|
69 |
)
|
|
70 |
)
|
|
71 |
(#MenuItem
|
|
72 |
#'label:' 'style'
|
|
73 |
#'value:' #fontStyle:
|
|
74 |
#'submenu:'
|
|
75 |
#(#Menu #( #(#MenuItem #label: 'roman' value:#roman )
|
|
76 |
#(#MenuItem #label: 'italic' value:#italic )
|
|
77 |
#(#MenuItem #label: 'oblique' value:#oblique )
|
|
78 |
)
|
|
79 |
nil
|
|
80 |
nil
|
|
81 |
)
|
|
82 |
)
|
|
83 |
(#MenuItem
|
|
84 |
#'label:' 'size'
|
|
85 |
#'value:' #fontSize:
|
|
86 |
#'submenu:'
|
|
87 |
#(#Menu #( #(#MenuItem #label: '6' value:#6 )
|
|
88 |
#(#MenuItem #label: '8' value:#8 )
|
|
89 |
#(#MenuItem #label: '10' value:#10 )
|
|
90 |
#(#MenuItem #label: '12' value:#12 )
|
|
91 |
#(#MenuItem #label: '14' value:#14 )
|
|
92 |
#(#MenuItem #label: '16' value:#16 )
|
|
93 |
#(#MenuItem #label: '18' value:#18 )
|
|
94 |
#(#MenuItem #label: 'other ...' value:#size)
|
|
95 |
)
|
|
96 |
nil
|
|
97 |
nil
|
|
98 |
)
|
|
99 |
)
|
|
100 |
)
|
|
101 |
#( 1 )
|
|
102 |
nil
|
|
103 |
) decodeAsLiteralArray
|
|
104 |
! !
|
|
105 |
|
|
106 |
!FontMenu methodsFor:'accept'!
|
|
107 |
|
|
108 |
accept:anItem
|
|
109 |
"accept current selected item
|
|
110 |
"
|
|
111 |
|item selector arg|
|
|
112 |
|
|
113 |
selector := self selection value.
|
|
114 |
|
|
115 |
(item := super accept:anItem) isNil ifTrue:[
|
|
116 |
^ self
|
|
117 |
].
|
|
118 |
|
|
119 |
(arg := item value) isNil ifTrue:[
|
|
120 |
model notNil ifTrue:[
|
|
121 |
enabledChannel value ifTrue:[
|
|
122 |
arg := self fontDescription
|
|
123 |
].
|
|
124 |
model value:arg
|
|
125 |
].
|
|
126 |
^ self
|
|
127 |
].
|
|
128 |
|
|
129 |
(arg == #size and:[(arg := self readSize) isNil]) ifTrue:[
|
|
130 |
^ self
|
|
131 |
].
|
|
132 |
|
|
133 |
(self perform:selector with:arg) ifTrue:[
|
|
134 |
model notNil ifTrue:[model value:(self fontDescription)]
|
|
135 |
]
|
|
136 |
!
|
|
137 |
|
|
138 |
readSize
|
|
139 |
"read a size; in case of cancel nil is returned otherwise a number.
|
|
140 |
"
|
|
141 |
|size string|
|
|
142 |
|
|
143 |
string := EnterBox request:'size: '.
|
|
144 |
|
|
145 |
string size ~~ 0 ifTrue:[
|
|
146 |
size := SmallInteger readFrom:string onError:nil.
|
|
147 |
|
|
148 |
(size notNil and:[size >= 6 and:[size <= 48]]) ifTrue:[
|
|
149 |
^ size
|
|
150 |
]
|
|
151 |
].
|
|
152 |
^ nil
|
|
153 |
! !
|
|
154 |
|
|
155 |
!FontMenu methodsFor:'accessing'!
|
|
156 |
|
|
157 |
fontDescription
|
|
158 |
"get font description
|
|
159 |
"
|
|
160 |
^ FontDescription family:fontFamily face:fontFace style:fontStyle size:fontSize
|
|
161 |
!
|
|
162 |
|
|
163 |
fontDescription:aFontDesc
|
|
164 |
"set font description
|
|
165 |
"
|
|
166 |
|desc|
|
|
167 |
|
|
168 |
aFontDesc isNil ifTrue:[
|
|
169 |
enabledChannel value:false.
|
|
170 |
] ifFalse:[
|
|
171 |
self disabledRedrawDo:[
|
|
172 |
enabledChannel value:true.
|
|
173 |
|
|
174 |
self fontFamily:(aFontDesc family).
|
|
175 |
self fontFace:(aFontDesc face).
|
|
176 |
self fontStyle:(aFontDesc style).
|
|
177 |
self fontSize:(aFontDesc size).
|
|
178 |
]
|
|
179 |
]
|
|
180 |
!
|
|
181 |
|
|
182 |
fontFace
|
|
183 |
"get face, a string
|
|
184 |
"
|
|
185 |
^ fontFace
|
|
186 |
!
|
|
187 |
|
|
188 |
fontFace:aFace
|
|
189 |
"set face, a string; update item.
|
|
190 |
if the face changed true is returned otherwise nil
|
|
191 |
"
|
|
192 |
(aFace notNil and:[aFace ~= fontFace]) ifTrue:[
|
|
193 |
(self itemAt:#fontFace:) label:(fontFace := aFace).
|
|
194 |
^ true
|
|
195 |
].
|
|
196 |
^ false
|
|
197 |
!
|
|
198 |
|
|
199 |
fontFamily
|
|
200 |
"get family, a string
|
|
201 |
"
|
|
202 |
^ fontFamily
|
|
203 |
!
|
|
204 |
|
|
205 |
fontFamily:aFamily
|
|
206 |
"set family, a string; update item
|
|
207 |
if the family changed true is returned otherwise nil
|
|
208 |
"
|
|
209 |
(aFamily notNil and:[aFamily ~= fontFamily]) ifTrue:[
|
|
210 |
(self itemAt:#fontFamily:) label:(fontFamily := aFamily).
|
|
211 |
^ true
|
|
212 |
].
|
|
213 |
^ false
|
|
214 |
|
|
215 |
!
|
|
216 |
|
|
217 |
fontSize
|
|
218 |
"get size, a number
|
|
219 |
"
|
|
220 |
^ fontSize
|
|
221 |
!
|
|
222 |
|
|
223 |
fontSize:aSize
|
|
224 |
"set size, a number; update item
|
|
225 |
if the size changed true is returned otherwise nil
|
|
226 |
"
|
|
227 |
|label|
|
|
228 |
|
|
229 |
(aSize notNil and:[aSize ~= fontSize]) ifTrue:[
|
|
230 |
fontSize := aSize.
|
|
231 |
(self itemAt:#fontSize:) label:(aSize printString).
|
|
232 |
^ true
|
|
233 |
].
|
|
234 |
^ false
|
|
235 |
!
|
|
236 |
|
|
237 |
fontStyle
|
|
238 |
"get style, a string
|
|
239 |
"
|
|
240 |
^ fontStyle
|
|
241 |
|
|
242 |
!
|
|
243 |
|
|
244 |
fontStyle:aStyle
|
|
245 |
"set style, a string; update item
|
|
246 |
if the style changed true is returned otherwise nil
|
|
247 |
"
|
|
248 |
(aStyle notNil and:[aStyle ~= fontStyle]) ifTrue:[
|
|
249 |
(self itemAt:#fontStyle:) label:(fontStyle := aStyle).
|
|
250 |
^ true
|
|
251 |
].
|
|
252 |
^ false
|
|
253 |
! !
|
|
254 |
|
|
255 |
!FontMenu methodsFor:'accessing channels'!
|
|
256 |
|
|
257 |
model
|
|
258 |
"get my model
|
|
259 |
"
|
|
260 |
^ model
|
|
261 |
!
|
|
262 |
|
|
263 |
model:aValueHolder
|
|
264 |
"set my model
|
|
265 |
"
|
|
266 |
model notNil ifTrue:[
|
|
267 |
model removeDependent:self.
|
|
268 |
].
|
|
269 |
model := aValueHolder.
|
|
270 |
|
|
271 |
model notNil ifTrue:[
|
|
272 |
model addDependent:self.
|
|
273 |
self fontDescription:(model value)
|
|
274 |
].
|
|
275 |
! !
|
|
276 |
|
|
277 |
!FontMenu methodsFor:'change & update'!
|
|
278 |
|
|
279 |
update:something with:aParameter from:changedObject
|
|
280 |
"one of my models changed its value
|
|
281 |
"
|
|
282 |
changedObject == model ifTrue:[
|
|
283 |
^ self fontDescription:(model value)
|
|
284 |
].
|
|
285 |
super update:something with:aParameter from:changedObject
|
|
286 |
|
|
287 |
! !
|
|
288 |
|
|
289 |
!FontMenu methodsFor:'initialization'!
|
|
290 |
|
|
291 |
destroy
|
|
292 |
"release dependencies
|
|
293 |
"
|
|
294 |
self model:nil.
|
|
295 |
super destroy.
|
|
296 |
|
|
297 |
!
|
|
298 |
|
|
299 |
initialize
|
|
300 |
"setup menu
|
|
301 |
"
|
|
302 |
super initialize.
|
|
303 |
self verticalLayout:false.
|
|
304 |
self fitFirstPanel:false.
|
|
305 |
self menu:(self class menu).
|
|
306 |
enabledChannel := false asValue.
|
|
307 |
|
|
308 |
self fontDescription:(self font).
|
|
309 |
|
|
310 |
self do:[:anItem|
|
|
311 |
anItem hasIndication ifFalse:[
|
|
312 |
anItem enabled:enabledChannel
|
|
313 |
] ifTrue:[
|
|
314 |
anItem indication:enabledChannel
|
|
315 |
]
|
|
316 |
].
|
|
317 |
|
|
318 |
|
|
319 |
! !
|
|
320 |
|
|
321 |
!FontMenu class methodsFor:'documentation'!
|
|
322 |
|
|
323 |
version
|
|
324 |
^ '$Header: /cvs/stx/stx/libwidg2/FontMenu.st,v 1.1 1997-06-04 11:37:29 ca Exp $'
|
|
325 |
! !
|