1 /* Font.c- text/font settings
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1999 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 typedef struct _Panel
{
34 CallbackRec callbacks
;
57 WMFont
*windowTitleFont
;
58 WMFont
*menuTitleFont
;
75 #define ICON_FILE "fonts"
79 static proplist_t DefaultWindowTitleFont
= NULL
;
80 static proplist_t DefaultMenuTitleFont
= NULL
;
81 static proplist_t DefaultMenuTextFont
= NULL
;
82 static proplist_t DefaultIconTitleFont
= NULL
;
83 static proplist_t DefaultClipTitleFont
= NULL
;
84 static proplist_t DefaultDisplayFont
= NULL
;
89 drawMenuItem(WMScreen
*scr
, Display
*dpy
, Drawable d
,
90 int x
, int y
, int w
, int h
,
91 GC light
, GC dark
, GC black
, GC white
,
92 WMFont
*font
, int fh
, char *text
)
94 XFillRectangle(dpy
, d
, light
, x
, y
, w
, h
);
96 XDrawLine(dpy
, d
, black
, x
, y
, x
, y
+h
);
97 XDrawLine(dpy
, d
, black
, x
+w
, y
, x
+w
, y
+h
);
99 XDrawLine(dpy
, d
, white
, x
+1, y
, x
+1, y
+h
-1);
100 XDrawLine(dpy
, d
, white
, x
+1, y
, x
+w
-1, y
);
102 XDrawLine(dpy
, d
, dark
, x
+w
-1, y
+1, x
+w
-1, y
+h
-3);
103 XDrawLine(dpy
, d
, dark
, x
+1, y
+h
-2, x
+w
-1, y
+h
-2);
105 XDrawLine(dpy
, d
, black
, x
, y
+h
-1, x
+w
, y
+h
-1);
107 WMDrawString(scr
, d
, black
, font
, x
+ 5, y
+(h
-fh
)/2,
114 paintPreviewBox(Panel
*panel
)
116 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
117 Display
*dpy
= WMScreenDisplay(scr
);
118 GC black
= WMColorGC(panel
->black
);
119 GC white
= WMColorGC(panel
->white
);
120 GC dark
= WMColorGC(panel
->dark
);
121 GC light
= WMColorGC(panel
->light
);
124 if (panel
->preview
== None
) {
127 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
128 240-4, 215-4, WMScreenDepth(scr
));
130 pix
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
131 240-4, 215-4, WMScreenDepth(scr
));
133 WMSetLabelImage(panel
->prevL
, pix
);
134 WMReleasePixmap(pix
);
137 XFillRectangle(dpy
, panel
->preview
, WMColorGC(panel
->back
),
144 fh
= WMFontHeight(panel
->windowTitleFont
);
147 XFillRectangle(dpy
, panel
->preview
, black
,
150 XDrawLine(dpy
, panel
->preview
, light
,
152 XDrawLine(dpy
, panel
->preview
, light
,
155 XDrawLine(dpy
, panel
->preview
, dark
,
156 20, 20+h
, 220, 20+h
);
157 XDrawLine(dpy
, panel
->preview
, dark
,
160 WMDrawString(scr
, panel
->preview
, white
, panel
->windowTitleFont
,
161 20+(200-WMWidthOfString(panel
->windowTitleFont
, "Window Titlebar", 15))/2,
162 20+(h
-fh
)/2, "Window Titlebar", 15);
174 fh
= WMFontHeight(panel
->menuTitleFont
);
177 XFillRectangle(dpy
, panel
->preview
, black
,
178 mx
-1, my
-1, mw
+3, h
+3);
180 XDrawLine(dpy
, panel
->preview
, light
,
182 XDrawLine(dpy
, panel
->preview
, light
,
185 XDrawLine(dpy
, panel
->preview
, dark
,
186 mx
, my
+h
, mx
+mw
, my
+h
);
187 XDrawLine(dpy
, panel
->preview
, dark
,
188 mx
+mw
, my
, mx
+mw
, my
+h
);
190 WMDrawString(scr
, panel
->preview
, white
, panel
->menuTitleFont
,
191 mx
+5, my
+(h
-fh
)/2, "Menu Title", 10);
193 fh2
= WMFontHeight(panel
->menuItemFont
);
197 for (i
= 0; i
< 4; i
++) {
198 drawMenuItem(scr
, dpy
, panel
->preview
,
199 mx
-1, my
+2+h
+i
*h2
, mw
+2, h2
,
200 light
, dark
, black
, white
,
201 panel
->menuItemFont
, fh2
,
207 WMRedisplayWidget(panel
->prevL
);
213 showData(_Panel
*panel
)
215 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
218 str
= GetStringForKey("WindowTitleFont");
220 panel
->windowTitleFont
= WMCreateFont(scr
, str
);
223 str
= GetStringForKey("MenuTitleFont");
225 panel
->menuTitleFont
= WMCreateFont(scr
, str
);
228 str
= GetStringForKey("MenuTextFont");
230 panel
->menuItemFont
= WMCreateFont(scr
, str
);
235 paintPreviewBox(panel
);
240 setLanguageType(Panel
*p
, Bool multiByte
)
243 WMMapWidget(p
->fsetL
);
244 WMMapWidget(p
->fsetLs
);
245 WMMapWidget(p
->addB
);
246 WMMapWidget(p
->editB
);
247 WMMapWidget(p
->remB
);
249 WMUnmapWidget(p
->fontT
);
250 WMUnmapWidget(p
->changeB
);
252 WMUnmapWidget(p
->fsetL
);
253 WMUnmapWidget(p
->fsetLs
);
254 WMUnmapWidget(p
->addB
);
255 WMUnmapWidget(p
->editB
);
256 WMUnmapWidget(p
->remB
);
258 WMMapWidget(p
->fontT
);
259 WMMapWidget(p
->changeB
);
269 readFontEncodings(Panel
*panel
)
271 proplist_t pl
= NULL
;
275 path
= WMPathForResourceOfType("font.data", NULL
);
277 msg
= _("Could not locate font information file WPrefs.app/font.data");
281 pl
= PLGetProplistWithPath(path
);
283 msg
= _("Could not read font information file WPrefs.app/font.data");
287 proplist_t key
= PLMakeString("Encodings");
291 array
= PLGetDictionaryEntry(pl
, key
);
293 if (!array
|| !PLIsArray(array
)) {
294 msg
= _("Invalid data in font information file WPrefs.app/font.data.\n"
295 "Encodings data not found.");
299 WMAddPopUpButtonItem(panel
->langP
, _("- Custom -"));
301 for (i
= 0; i
< PLGetNumberOfElements(array
); i
++) {
302 proplist_t item
, str
;
304 item
= PLGetArrayElement(array
, i
);
305 str
= PLGetArrayElement(item
, 0);
306 mi
= WMAddPopUpButtonItem(panel
->langP
, PLGetString(str
));
307 WMSetMenuItemRepresentedObject(mi
, PLRetain(item
));
310 key
= PLMakeString("WindowTitleFont");
311 DefaultWindowTitleFont
= PLGetDictionaryEntry(pl
, key
);
314 key
= PLMakeString("MenuTitleFont");
315 DefaultMenuTitleFont
= PLGetDictionaryEntry(pl
, key
);
318 key
= PLMakeString("MenuTextFont");
319 DefaultMenuTextFont
= PLGetDictionaryEntry(pl
, key
);
329 WMRunAlertPanel(WMWidgetScreen(panel
->parent
), panel
->parent
,
330 _("Error"), msg
, _("OK"), NULL
, NULL
);
336 changeLanguageAction(WMWidget
*w
, void *data
)
338 /*Panel *panel = (Panel*)data;*/
342 mi
= WMGetPopUpButtonMenuItem(w
, WMGetPopUpButtonSelectedItem(w
));
343 pl
= WMGetMenuItemRepresentedObject(mi
);
354 createPanel(Panel
*p
)
356 _Panel
*panel
= (_Panel
*)p
;
357 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
360 panel
->box
= WMCreateBox(panel
->parent
);
361 WMSetBoxExpandsToParent(panel
->box
, 2, 2, 0, 0);
364 panel
->prevL
= WMCreateLabel(panel
->box
);
365 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
-20);
366 WMMoveWidget(panel
->prevL
, 15, 10);
367 WMSetLabelRelief(panel
->prevL
, WRSunken
);
368 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
371 /* language selection */
373 panel
->langF
= WMCreateFrame(panel
->box
);
374 WMResizeWidget(panel
->langF
, 245, 50);
375 WMMoveWidget(panel
->langF
, 265, 10);
376 WMSetFrameTitle(panel
->langF
, _("Default Font Sets"));
378 panel
->langP
= WMCreatePopUpButton(panel
->langF
);
379 WMResizeWidget(panel
->langP
, 215, 20);
380 WMMoveWidget(panel
->langP
, 15, 20);
382 WMMapSubwidgets(panel
->langF
);
386 panel
->fsetL
= WMCreateLabel(panel
->box
);
387 WMResizeWidget(panel
->fsetL
, 205, 20);
388 WMMoveWidget(panel
->fsetL
, 215, 127);
389 WMSetLabelText(panel
->fsetL
, _("Font Set"));
390 WMSetLabelRelief(panel
->fsetL
, WRSunken
);
391 WMSetLabelTextAlignment(panel
->fsetL
, WACenter
);
396 color
= WMDarkGrayColor(scr
);
397 font
= WMBoldSystemFontOfSize(scr
, 12);
399 WMSetWidgetBackgroundColor(panel
->fsetL
, color
);
400 WMSetLabelFont(panel
->fsetL
, font
);
403 WMReleaseColor(color
);
405 color
= WMWhiteColor(scr
);
406 WMSetLabelTextColor(panel
->fsetL
, color
);
407 WMReleaseColor(color
);
410 panel
->fsetLs
= WMCreateList(panel
->box
);
411 WMResizeWidget(panel
->fsetLs
, 205, 71);
412 WMMoveWidget(panel
->fsetLs
, 215, 149);
415 panel
->addB
= WMCreateCommandButton(panel
->box
);
416 WMResizeWidget(panel
->addB
, 80, 24);
417 WMMoveWidget(panel
->addB
, 430, 127);
418 WMSetButtonText(panel
->addB
, _("Add..."));
420 panel
->editB
= WMCreateCommandButton(panel
->box
);
421 WMResizeWidget(panel
->editB
, 80, 24);
422 WMMoveWidget(panel
->editB
, 430, 161);
423 WMSetButtonText(panel
->editB
, _("Change..."));
425 panel
->remB
= WMCreateCommandButton(panel
->box
);
426 WMResizeWidget(panel
->remB
, 80, 24);
427 WMMoveWidget(panel
->remB
, 430, 195);
428 WMSetButtonText(panel
->remB
, _("Remove"));
431 panel
->fontT
= WMCreateTextField(panel
->box
);
432 WMResizeWidget(panel
->fontT
, 240, 20);
433 WMMoveWidget(panel
->fontT
, 265, 130);
435 panel
->changeB
= WMCreateCommandButton(panel
->box
);
436 WMResizeWidget(panel
->changeB
, 104, 24);
437 WMMoveWidget(panel
->changeB
, 335, 160);
438 WMSetButtonText(panel
->changeB
, _("Change..."));
441 panel
->black
= WMBlackColor(scr
);
442 panel
->white
= WMWhiteColor(scr
);
443 panel
->light
= WMGrayColor(scr
);
444 panel
->dark
= WMDarkGrayColor(scr
);
445 panel
->back
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
448 for (i
= 0; Languages
[i
].language
!= NULL
; i
++) {
449 WMAddPopUpButtonItem(panel
->langP
, Languages
[i
].language
);
452 for (i
= 0; Options
[i
].description
!= NULL
; i
++) {
453 WMAddListItem(panel
->settingLs
, Options
[i
].description
);
456 WMRealizeWidget(panel
->box
);
457 WMMapSubwidgets(panel
->box
);
459 setLanguageType(panel
, False
);
463 readFontEncodings(panel
);
470 InitFont(WMScreen
*scr
, WMWidget
*parent
)
474 panel
= wmalloc(sizeof(_Panel
));
475 memset(panel
, 0, sizeof(_Panel
));
477 panel
->sectionName
= _("Font Preferences");
478 panel
->description
= _("Font Configurations for Windows, Menus etc");
480 panel
->parent
= parent
;
482 panel
->callbacks
.createWidgets
= createPanel
;
484 AddSection(panel
, ICON_FILE
);