author | Claus Gittinger <cg@exept.de> |
Mon, 18 Feb 2008 09:38:18 +0100 | |
changeset 3342 | 213558f50bc2 |
parent 3167 | 0c47978ab475 |
child 3398 | 7e778b89de59 |
permissions | -rw-r--r-- |
421 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
" |
|
2935
e3fa9d1a7a64
Moved ColorMenu and FontMenu from libtool2
Stefan Vogel <sv@exept.de>
parents:
2749
diff
changeset
|
12 |
"{ Package: 'stx:libwidg2' }" |
1808 | 13 |
|
412 | 14 |
MenuPanel subclass:#FontMenu |
2189 | 15 |
instanceVariableNames:'fontAspects enabledChannel' |
412 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-UIPainter' |
|
19 |
! |
|
20 |
||
21 |
!FontMenu class methodsFor:'documentation'! |
|
22 |
||
421 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
||
37 |
! |
|
38 |
||
412 | 39 |
documentation |
40 |
" |
|
41 |
FontMenu used by UIPainter |
|
42 |
||
421 | 43 |
[author:] |
44 |
Claus Atzkern |
|
45 |
||
412 | 46 |
[see also:] |
47 |
UIPainter |
|
48 |
FontMenuSpec |
|
49 |
" |
|
50 |
||
51 |
||
52 |
! |
|
53 |
||
54 |
examples |
|
55 |
" |
|
56 |
simple example |
|
57 |
[exBegin] |
|
2189 | 58 |
|top menu model| |
412 | 59 |
|
60 |
top := StandardSystemView new. |
|
2189 | 61 |
top extent:250@200. |
62 |
menu := FontMenu origin:0.0@0.4 extent:1.0@30 in:top. |
|
63 |
model := nil asValue. |
|
64 |
menu model:model. |
|
412 | 65 |
top open. |
2189 | 66 |
top waitUntilVisible. |
67 |
||
68 |
[ |new old| |
|
69 |
||
70 |
old := model value. |
|
71 |
[ top shown] whileTrue:[ |
|
72 |
new := model value. |
|
73 |
new ~= old ifTrue:[ |
|
74 |
old := new. |
|
75 |
old notNil ifTrue:[ Transcript showCR:(old userFriendlyName) ] |
|
76 |
ifFalse:[ Transcript showCR:'---------' ] |
|
77 |
]. |
|
78 |
Delay waitForSeconds:0.2. |
|
79 |
] |
|
80 |
||
81 |
] forkAt:8. |
|
412 | 82 |
[exEnd] |
83 |
" |
|
84 |
! ! |
|
85 |
||
3342 | 86 |
!FontMenu class methodsFor:'menu specs'! |
412 | 87 |
|
88 |
menu |
|
2189 | 89 |
"This resource specification was automatically generated |
90 |
by the MenuEditor of ST/X." |
|
91 |
||
92 |
"Do not manually edit this!! If it is corrupted, |
|
93 |
the MenuEditor may not be able to read the specification." |
|
94 |
||
95 |
" |
|
96 |
MenuEditor new openOnClass:FontMenu andSelector:#menu |
|
97 |
(Menu new fromLiteralArrayEncoding:(FontMenu menu)) startUp |
|
98 |
" |
|
799 | 99 |
|
583 | 100 |
<resource: #menu> |
412 | 101 |
|
2189 | 102 |
^ |
2749 | 103 |
#(Menu |
104 |
( |
|
105 |
(MenuItem |
|
106 |
label: 'enabled' |
|
107 |
itemValue: updateModel |
|
108 |
translateLabel: true |
|
109 |
indication: enabledChannel |
|
110 |
labelImage: (ResourceRetriever SystemBrowser emptyIcon) |
|
2189 | 111 |
) |
2749 | 112 |
(MenuItem |
113 |
enabled: enabledChannel |
|
114 |
label: 'Family' |
|
115 |
nameKey: fontFamily |
|
116 |
translateLabel: true |
|
117 |
isButton: true |
|
118 |
submenu: |
|
119 |
(Menu |
|
120 |
( |
|
121 |
(MenuItem |
|
122 |
label: 'helvetica' |
|
123 |
itemValue: fontFamily: |
|
124 |
translateLabel: true |
|
125 |
argument: helvetica |
|
126 |
) |
|
127 |
(MenuItem |
|
128 |
label: 'courier' |
|
129 |
itemValue: fontFamily: |
|
130 |
translateLabel: true |
|
131 |
argument: courier |
|
2189 | 132 |
) |
2749 | 133 |
(MenuItem |
134 |
label: 'times' |
|
135 |
itemValue: fontFamily: |
|
136 |
translateLabel: true |
|
137 |
argument: times |
|
2189 | 138 |
) |
2749 | 139 |
(MenuItem |
140 |
label: 'clean' |
|
141 |
itemValue: fontFamily: |
|
142 |
translateLabel: true |
|
143 |
argument: clean |
|
2189 | 144 |
) |
2749 | 145 |
(MenuItem |
146 |
label: 'fixed' |
|
147 |
itemValue: fontFamily: |
|
148 |
translateLabel: true |
|
149 |
argument: fixed |
|
2189 | 150 |
) |
2749 | 151 |
(MenuItem |
152 |
label: 'lucida' |
|
153 |
itemValue: fontFamily: |
|
154 |
translateLabel: true |
|
155 |
argument: lucida |
|
412 | 156 |
) |
2749 | 157 |
(MenuItem |
158 |
label: '-' |
|
159 |
) |
|
160 |
(MenuItem |
|
161 |
label: 'Other...' |
|
162 |
itemValue: launchFontFamilyDialog |
|
163 |
translateLabel: true |
|
2189 | 164 |
) |
165 |
) |
|
166 |
nil |
|
167 |
nil |
|
799 | 168 |
) |
2189 | 169 |
) |
2749 | 170 |
(MenuItem |
171 |
enabled: enabledChannel |
|
172 |
label: 'Face' |
|
173 |
nameKey: fontFace |
|
174 |
translateLabel: true |
|
175 |
isButton: true |
|
176 |
submenu: |
|
177 |
(Menu |
|
178 |
( |
|
179 |
(MenuItem |
|
180 |
label: 'bold' |
|
181 |
itemValue: fontFace: |
|
182 |
translateLabel: true |
|
183 |
argument: bold |
|
2189 | 184 |
) |
2749 | 185 |
(MenuItem |
186 |
label: 'medium' |
|
187 |
itemValue: fontFace: |
|
188 |
translateLabel: true |
|
189 |
argument: medium |
|
190 |
) |
|
191 |
(MenuItem |
|
192 |
label: '-' |
|
193 |
) |
|
194 |
(MenuItem |
|
195 |
label: 'Other...' |
|
196 |
itemValue: launchFontFaceDialog |
|
197 |
translateLabel: true |
|
2189 | 198 |
) |
199 |
) |
|
200 |
nil |
|
201 |
nil |
|
202 |
) |
|
203 |
) |
|
2749 | 204 |
(MenuItem |
205 |
enabled: enabledChannel |
|
206 |
label: 'Style' |
|
207 |
nameKey: fontStyle |
|
208 |
translateLabel: true |
|
209 |
isButton: true |
|
210 |
submenu: |
|
211 |
(Menu |
|
212 |
( |
|
213 |
(MenuItem |
|
214 |
label: 'roman' |
|
215 |
itemValue: fontStyle: |
|
216 |
translateLabel: true |
|
217 |
argument: roman |
|
412 | 218 |
) |
2749 | 219 |
(MenuItem |
220 |
label: 'italic' |
|
221 |
itemValue: fontStyle: |
|
222 |
translateLabel: true |
|
223 |
argument: italic |
|
412 | 224 |
) |
2749 | 225 |
(MenuItem |
226 |
label: 'oblique' |
|
227 |
itemValue: fontStyle: |
|
228 |
translateLabel: true |
|
229 |
argument: oblique |
|
230 |
) |
|
231 |
(MenuItem |
|
232 |
label: '-' |
|
233 |
) |
|
234 |
(MenuItem |
|
235 |
label: 'Other...' |
|
236 |
itemValue: launchFontStyleDialog |
|
237 |
translateLabel: true |
|
2189 | 238 |
) |
239 |
) |
|
240 |
nil |
|
241 |
nil |
|
799 | 242 |
) |
2189 | 243 |
) |
2749 | 244 |
(MenuItem |
245 |
enabled: enabledChannel |
|
246 |
label: 'Size' |
|
247 |
nameKey: fontSize |
|
248 |
translateLabel: true |
|
249 |
isButton: true |
|
250 |
submenu: |
|
251 |
(Menu |
|
252 |
( |
|
253 |
(MenuItem |
|
254 |
label: '6' |
|
255 |
itemValue: fontSize: |
|
256 |
translateLabel: true |
|
257 |
argument: 6 |
|
258 |
) |
|
259 |
(MenuItem |
|
260 |
label: '8' |
|
261 |
itemValue: fontSize: |
|
262 |
translateLabel: true |
|
263 |
argument: 8 |
|
2189 | 264 |
) |
2749 | 265 |
(MenuItem |
266 |
label: '10' |
|
267 |
itemValue: fontSize: |
|
268 |
translateLabel: true |
|
269 |
argument: 10 |
|
270 |
) |
|
271 |
(MenuItem |
|
272 |
label: '12' |
|
273 |
itemValue: fontSize: |
|
274 |
translateLabel: true |
|
275 |
argument: 12 |
|
2189 | 276 |
) |
2749 | 277 |
(MenuItem |
278 |
label: '14' |
|
279 |
itemValue: fontSize: |
|
280 |
translateLabel: true |
|
281 |
argument: 14 |
|
282 |
) |
|
283 |
(MenuItem |
|
284 |
label: '16' |
|
285 |
itemValue: fontSize: |
|
286 |
translateLabel: true |
|
287 |
argument: 16 |
|
2189 | 288 |
) |
2749 | 289 |
(MenuItem |
290 |
label: '18' |
|
291 |
itemValue: fontSize: |
|
292 |
translateLabel: true |
|
293 |
argument: 18 |
|
412 | 294 |
) |
2749 | 295 |
(MenuItem |
296 |
label: '-' |
|
297 |
) |
|
298 |
(MenuItem |
|
299 |
label: 'Other...' |
|
300 |
itemValue: launchFontSizeDialog |
|
301 |
translateLabel: true |
|
2189 | 302 |
) |
2749 | 303 |
) |
304 |
nil |
|
305 |
nil |
|
306 |
) |
|
307 |
) |
|
308 |
(MenuItem |
|
309 |
enabled: enabledChannel |
|
310 |
label: 'Encoding' |
|
311 |
nameKey: fontEncoding |
|
312 |
translateLabel: true |
|
313 |
isButton: true |
|
314 |
submenu: |
|
315 |
(Menu |
|
316 |
( |
|
317 |
(MenuItem |
|
318 |
label: 'latin-1' |
|
319 |
itemValue: fontEncoding: |
|
320 |
translateLabel: true |
|
321 |
argument: #'iso8859-1' |
|
2189 | 322 |
) |
2749 | 323 |
(MenuItem |
324 |
label: 'unicode' |
|
325 |
itemValue: fontEncoding: |
|
326 |
translateLabel: true |
|
327 |
argument: #'iso10646-1' |
|
2189 | 328 |
) |
2749 | 329 |
(MenuItem |
330 |
label: '-' |
|
331 |
) |
|
332 |
(MenuItem |
|
333 |
label: 'Other...' |
|
334 |
itemValue: launchFontEncodingDialog |
|
335 |
translateLabel: true |
|
2189 | 336 |
) |
337 |
) |
|
338 |
nil |
|
339 |
nil |
|
799 | 340 |
) |
2189 | 341 |
) |
342 |
) |
|
343 |
nil |
|
344 |
nil |
|
799 | 345 |
) |
412 | 346 |
! ! |
347 |
||
2189 | 348 |
!FontMenu methodsFor:'accessing'! |
412 | 349 |
|
2189 | 350 |
fontDescription |
351 |
"get font description |
|
412 | 352 |
" |
2189 | 353 |
enabledChannel value ifFalse:[^ nil]. |
412 | 354 |
|
2749 | 355 |
^ FontDescription |
356 |
family:(fontAspects at:#fontFamily) |
|
357 |
face:(fontAspects at:#fontFace) |
|
358 |
style:(fontAspects at:#fontStyle) |
|
359 |
size:(fontAspects at:#fontSize) |
|
360 |
encoding:(fontAspects at:#fontEncoding) |
|
2189 | 361 |
! |
412 | 362 |
|
2189 | 363 |
fontDescription:aFontDesc |
364 |
"set font description |
|
365 |
" |
|
366 |
|saveModel| |
|
367 |
||
3167 | 368 |
aFontDesc isNil ifTrue:[ |
2189 | 369 |
enabledChannel value:false. |
2459 | 370 |
^ self |
412 | 371 |
]. |
372 |
||
2189 | 373 |
self disabledRedrawDo:[ |
374 |
saveModel := model. "/ do not inform the model |
|
375 |
model := nil. |
|
376 |
||
377 |
enabledChannel value:true. |
|
378 |
||
379 |
(aFontDesc isSymbol or:[aFontDesc isString]) ifFalse:[ |
|
380 |
self fontFamily:(aFontDesc family). |
|
2749 | 381 |
self fontFace:(aFontDesc face). |
382 |
self fontStyle:(aFontDesc style). |
|
383 |
self fontSize:(aFontDesc size). |
|
384 |
self fontEncoding:(aFontDesc encoding ? #'iso10646-1'). |
|
2189 | 385 |
]. |
386 |
model := saveModel. |
|
387 |
] |
|
388 |
! ! |
|
389 |
||
390 |
!FontMenu methodsFor:'accessing-aspects'! |
|
391 |
||
392 |
fontAspectAt:key put:value |
|
393 |
(value isNil or:[value == (fontAspects at:key)]) ifTrue:[ |
|
412 | 394 |
^ self |
395 |
]. |
|
2189 | 396 |
fontAspects at:key put:value. |
397 |
(self itemAt:key) label:value. |
|
412 | 398 |
|
2189 | 399 |
self updateModel. |
400 |
! |
|
401 |
||
2749 | 402 |
fontEncoding:anEncodingSymbol |
403 |
^ self fontAspectAt:#fontEncoding put:anEncodingSymbol |
|
404 |
! |
|
405 |
||
2189 | 406 |
fontFace:aFace |
407 |
^ self fontAspectAt:#fontFace put:aFace |
|
412 | 408 |
! |
409 |
||
2189 | 410 |
fontFamily:aFamily |
411 |
^ self fontAspectAt:#fontFamily put:aFamily |
|
412 |
! |
|
413 |
||
414 |
fontSize:aSize |
|
415 |
^ self fontAspectAt:#fontSize put:aSize |
|
416 |
! |
|
417 |
||
418 |
fontStyle:aStyle |
|
419 |
^ self fontAspectAt:#fontStyle put:aStyle |
|
420 |
! |
|
421 |
||
2749 | 422 |
launchFontEncodingDialog |
423 |
"launch dialog to get a font encoding" |
|
424 |
||
425 |
|string| |
|
426 |
||
427 |
string := EnterBox request:'Encoding: '. |
|
428 |
||
429 |
string size ~~ 0 ifTrue:[ |
|
430 |
self fontEncoding:string asSymbol |
|
431 |
]. |
|
432 |
! |
|
433 |
||
434 |
launchFontFaceDialog |
|
435 |
"launch dialog to get a font face" |
|
436 |
||
437 |
|string| |
|
438 |
||
439 |
string := EnterBox request:'Face: '. |
|
440 |
||
441 |
string size ~~ 0 ifTrue:[ |
|
442 |
self fontFace:string |
|
443 |
]. |
|
444 |
! |
|
445 |
||
446 |
launchFontFamilyDialog |
|
447 |
"launch dialog to get a font family" |
|
448 |
||
449 |
|string| |
|
450 |
||
451 |
string := EnterBox request:'Family: '. |
|
452 |
||
453 |
string size ~~ 0 ifTrue:[ |
|
454 |
self fontFamily:string |
|
455 |
]. |
|
456 |
! |
|
457 |
||
2189 | 458 |
launchFontSizeDialog |
2749 | 459 |
"launch dialog to get a font size" |
460 |
||
412 | 461 |
|size string| |
462 |
||
463 |
string := EnterBox request:'size: '. |
|
464 |
||
465 |
string size ~~ 0 ifTrue:[ |
|
466 |
size := SmallInteger readFrom:string onError:nil. |
|
467 |
||
2749 | 468 |
(size notNil and:[size >= 1 and:[size <= 128]]) ifTrue:[ |
2189 | 469 |
self fontSize:size |
412 | 470 |
] |
471 |
]. |
|
2749 | 472 |
! |
473 |
||
474 |
launchFontStyleDialog |
|
475 |
"launch dialog to get a font style" |
|
476 |
||
477 |
|string| |
|
478 |
||
479 |
string := EnterBox request:'Style: '. |
|
480 |
||
481 |
string size ~~ 0 ifTrue:[ |
|
482 |
self fontFace:string |
|
483 |
]. |
|
412 | 484 |
! ! |
485 |
||
1818 | 486 |
!FontMenu methodsFor:'accessing-channels'! |
412 | 487 |
|
2189 | 488 |
enabledChannel |
489 |
^ enabledChannel |
|
490 |
! |
|
491 |
||
412 | 492 |
model:aValueHolder |
2749 | 493 |
"set my model" |
494 |
||
2184 | 495 |
super model:aValueHolder. |
2189 | 496 |
model ifNotNil:[ |
2186 | 497 |
self updateFromModel |
412 | 498 |
]. |
499 |
! ! |
|
500 |
||
501 |
!FontMenu methodsFor:'change & update'! |
|
502 |
||
2186 | 503 |
updateFromModel |
2184 | 504 |
self fontDescription:(model value) |
2189 | 505 |
! |
506 |
||
507 |
updateModel |
|
508 |
model ifNotNil:[ |
|
509 |
model value:(self fontDescription) withoutNotifying:self |
|
510 |
]. |
|
412 | 511 |
! ! |
512 |
||
513 |
!FontMenu methodsFor:'initialization'! |
|
514 |
||
515 |
destroy |
|
2749 | 516 |
"release dependencies" |
517 |
||
412 | 518 |
self model:nil. |
2189 | 519 |
enabledChannel removeDependent:self. |
412 | 520 |
super destroy. |
521 |
! |
|
522 |
||
523 |
initialize |
|
2749 | 524 |
"setup menu" |
525 |
||
412 | 526 |
super initialize. |
2189 | 527 |
|
528 |
fontAspects := IdentityDictionary new. |
|
529 |
enabledChannel := false asValue. |
|
530 |
||
2749 | 531 |
#( #fontFamily #fontFace #fontStyle #fontSize #fontEncoding) do:[:k| |
2189 | 532 |
fontAspects at:k put:(nil asValue) |
533 |
]. |
|
412 | 534 |
self verticalLayout:false. |
535 |
self menu:(self class menu). |
|
536 |
enabledChannel := false asValue. |
|
2189 | 537 |
receiver := self. |
412 | 538 |
|
539 |
self fontDescription:(self font). |
|
540 |
! ! |
|
541 |
||
542 |
!FontMenu class methodsFor:'documentation'! |
|
543 |
||
544 |
version |
|
3342 | 545 |
^ '$Header: /cvs/stx/stx/libwidg2/FontMenu.st,v 1.18 2008-02-18 08:38:18 cg Exp $' |
412 | 546 |
! ! |