1 /* Font.c- text/font settings
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1999-2003 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,
24 #include <X11/Xlocale.h>
27 typedef struct _Panel
{
33 CallbackRec callbacks
;
39 WMFontPanel
*fontPanel
;
41 WMPopUpButton
*fontSel
;
77 WMPixmap
*alt_up_arrow
;
78 WMPixmap
*alt_down_arrow
;
88 #define ICON_FILE "fonts"
90 static WMRect previewPositions
[] = {
92 {{30, 10}, {190, 20}},
96 {{30, 105}, {90, 20}},
98 {{30, 125}, {90, 20 * 4}},
100 {{156, 35}, {64, 64}},
102 {{156, 105}, {64, 64}}
105 #define EVERYTHING 0xff
107 static char *colorOptions
[] = {
108 #define FTITLE (1<<0)
109 "FTitleColor", "white",
110 #define DISCOL (1<<1) /* Display uses white always */
111 #define MTITLE (1<<2)
112 "MenuTitleColor", "white",
114 "MenuTextColor", "black",
116 "ClipTitleColor", "black",
118 "ClipTitleColor", "#454045",
120 "IconTitleColor", "white",
122 "IconTitleBack", "black"
125 #define MSTYLE_NORMAL 0
126 #define MSTYLE_SINGLE 1
127 #define MSTYLE_FLAT 2
129 #define RESIZEBAR_BEVEL -1
130 #define MENU_BEVEL -2
131 #define CLIP_BUTTON_SIZE 23
134 static char *textureOptions
[] = {
144 static char *hand_xpm
[] = {
168 " .%%%&@.......... ",
169 " .%*%%&#%%%%%%%%%$. ",
170 " .*#%%%%%%%%%&&&&==. ",
171 " .-%%%%%%%%%=*-;;;#$. ",
172 " .-%%%%%%%%&..>..... ",
188 static char *up_arrow_xpm
[] = {
204 static char *down_arrow_xpm
[] = {
220 static char *alt_up_arrow_xpm
[] = {
235 static char *alt_down_arrow_xpm
[] = {
252 static WMPropList
*CurrentFontArray
= NULL
;
253 //static WMPropList *CurrentMenuTitleFont = NULL;
254 //static WMPropList *CurrentMenuTextFont = NULL;
255 //static WMPropList *CurrentIconTitleFont = NULL;
256 //static WMPropList *CurrentClipTitleFont = NULL;
257 //static WMPropList *CurrentLargeDisplayFont = NULL;
259 static WMPropList
*DefaultWindowTitleFont
= NULL
;
260 static WMPropList
*DefaultMenuTitleFont
= NULL
;
261 static WMPropList
*DefaultMenuTextFont
= NULL
;
262 static WMPropList
*DefaultIconTitleFont
= NULL
;
263 static WMPropList
*DefaultClipTitleFont
= NULL
;
264 static WMPropList
*DefaultLargeDisplayFont
= NULL
;
266 static void changePage(WMWidget
* w
, void *data
);
267 static void setLanguageType(void *data
, Bool multiByte
);
268 static void refillFontSetList(void *data
);
269 static void readFontEncodings(void *data
);
270 static void changeLanguageAction(WMWidget
* w
, void *data
);
271 static void checkListForArrows(void *data
);
273 static char *getFontEncoding(void *data
);
274 static char *getFontSampleString(void *data
);
276 /* note single element */
277 static WMFont
*getFontForPreview(void *data
, int element
);
278 static WMFont
*getDefaultSystemFont(void *data
, int element
);
280 static WMPropList
*getDefaultFontProp(void *data
, char *encoding
, int section
);
281 static WMPropList
*getCurrentFontProp(void *data
, int section
);
283 static Bool
isEncodingMultiByte(void *data
);
285 static void str2rcolor(RContext
* rc
, char *name
, RColor
* color
)
289 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
292 color
->red
= xcolor
.red
>> 8;
293 color
->green
= xcolor
.green
>> 8;
294 color
->blue
= xcolor
.blue
>> 8;
297 static void drawMenuBevel(RImage
* img
)
299 RColor light
, dark
, mid
;
301 int iheight
= img
->height
/ 4;
304 light
.red
= light
.green
= light
.blue
= 80;
307 dark
.red
= dark
.green
= dark
.blue
= 0;
310 mid
.red
= mid
.green
= mid
.blue
= 40;
312 for (i
= 1; i
< 4; i
++) {
313 ROperateLine(img
, RSubtractOperation
, 0, i
* iheight
- 2, img
->width
- 1, i
* iheight
- 2, &mid
);
315 RDrawLine(img
, 0, i
* iheight
- 1, img
->width
- 1, i
* iheight
- 1, &dark
);
317 ROperateLine(img
, RAddOperation
, 1, i
* iheight
, img
->width
- 2, i
* iheight
, &light
);
322 paintTitle(WMScreen
* scr
, Drawable d
, WMColor
* color
, WMFont
* font
, int part
, WMAlignment align
, char *text
)
324 int l
= strlen(text
);
325 int x
= previewPositions
[part
].pos
.x
;
326 int y
= previewPositions
[part
].pos
.y
;
327 int w
= previewPositions
[part
].size
.width
;
328 int h
= previewPositions
[part
].size
.height
;
335 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
339 x
+= (w
- WMWidthOfString(font
, text
, l
)) / 2;
342 WMDrawString(scr
, d
, color
, font
, x
, y
+ (h
- WMFontHeight(font
)) / 2, text
, l
);
345 static void paintItems(WMScreen
* scr
, Drawable d
, WMColor
* color
, WMFont
* font
, int part
, char *text
)
347 int l
= strlen(text
);
348 int x
= previewPositions
[part
].pos
.x
;
349 int y
= previewPositions
[part
].pos
.y
;
350 //int w = previewPositions[part].size.width;
351 int h
= previewPositions
[part
].size
.height
/ 4;
353 for (i
= 0; i
< 4; i
++) {
354 WMDrawString(scr
, d
, color
, font
, x
+ 5, y
+ (20 * i
) + (h
- WMFontHeight(font
)) / 2, text
, l
);
359 paintIcon(WMScreen
* scr
, Drawable d
, WMColor
* color
, WMColor
* Iback
, WMFont
* font
, int part
, char *text
)
361 Display
*dpy
= WMScreenDisplay(scr
);
362 int l
= strlen(text
);
363 int x
= previewPositions
[part
].pos
.x
+ 1;
364 int y
= previewPositions
[part
].pos
.y
+ 1;
365 int w
= previewPositions
[part
].size
.width
- 2;
366 int h
= WMFontHeight(font
) + 2;
368 XFillRectangle(dpy
, d
, WMColorGC(Iback
), x
, y
, w
, h
);
369 x
+= (w
- WMWidthOfString(font
, text
, l
)) / 2;
370 WMDrawString(scr
, d
, color
, font
, x
, y
+ (h
- WMFontHeight(font
)) / 2, text
, l
);
374 static void drawFonts(_Panel
* panel
, int elements
)
376 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
380 pixmap
= WMGetLabelImage(panel
->prevL
);
381 d
= WMGetPixmapXID(pixmap
);
383 if (elements
& FTITLE
) {
384 paintTitle(scr
, d
, panel
->colors
[0], getFontForPreview(panel
, WINTITLE
),
385 WINTITLE
, panel
->titleAlignment
, _("Window Title Font"));
387 if (elements
& DISCOL
) {
388 paintTitle(scr
, d
, panel
->white
, getFontForPreview(panel
, DISTITLE
),
389 DISTITLE
, WACenter
, _("Display"));
391 if (elements
& MTITLE
) {
392 paintTitle(scr
, d
, panel
->colors
[1], getFontForPreview(panel
, PMTITLE
),
393 PMTITLE
, WALeft
, _("Menu Title"));
395 if (elements
& MITEM
) {
396 paintItems(scr
, d
, panel
->colors
[2], getFontForPreview(panel
, PMITEM
), PMITEM
, _("Menu Item"));
398 if (elements
& CLIP
) {
399 WMDrawString(scr
, d
, panel
->colors
[4], getFontForPreview(panel
, PCLIP
), 169, 37, "1", 1);
400 WMDrawString(scr
, d
, panel
->colors
[3],
401 getFontForPreview(panel
, PCLIP
), 179, 84, _("Clip title"), 10);
403 if (elements
& ICONT
) {
404 paintIcon(scr
, d
, panel
->colors
[5], panel
->colors
[6],
405 getFontForPreview(panel
, PICON
), PICON
, _("Icon Title"));
409 static void dumpRImage(char *path
, RImage
* image
)
412 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
414 f
= fopen(path
, "w");
419 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
, channels
);
421 fwrite(image
->data
, 1, image
->width
* image
->height
* channels
, f
);
429 isPixmap(WMPropList *prop)
434 p = WMGetFromPLArray(prop, 0);
435 s = WMGetFromPLString(p);
436 if (strcasecmp(&s[1], "pixmap")==0)
442 static Pixmap
renderTexture(WMScreen
* scr
, WMPropList
* texture
, int width
, int height
, char *path
, int border
)
445 RImage
*image
= NULL
;
447 RContext
*rc
= WMScreenRContext(scr
);
451 type
= WMGetFromPLString(WMGetFromPLArray(texture
, 0));
453 if (strcasecmp(type
, "solid") == 0) {
455 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
457 str2rcolor(rc
, str
, &rcolor
);
459 image
= RCreateImage(width
, height
, False
);
460 RClearImage(image
, &rcolor
);
461 } else if (strcasecmp(type
, "igradient") == 0) {
465 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
466 str2rcolor(rc
, str
, &c1
[0]);
467 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
468 str2rcolor(rc
, str
, &c1
[1]);
469 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
472 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
473 str2rcolor(rc
, str
, &c2
[0]);
474 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 5));
475 str2rcolor(rc
, str
, &c2
[1]);
476 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 6));
479 image
= RRenderInterwovenGradient(width
, height
, c1
, t1
, c2
, t2
);
480 } else if (strcasecmp(&type
[1], "gradient") == 0) {
484 switch (toupper(type
[0])) {
486 style
= RVerticalGradient
;
489 style
= RHorizontalGradient
;
493 style
= RDiagonalGradient
;
497 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
498 str2rcolor(rc
, str
, &rcolor
);
499 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
500 str2rcolor(rc
, str
, &rcolor2
);
502 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
503 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'T') {
507 RImage
*grad
, *timage
;
510 switch (toupper(type
[1])) {
512 style
= RVerticalGradient
;
515 style
= RHorizontalGradient
;
519 style
= RDiagonalGradient
;
523 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
524 str2rcolor(rc
, str
, &rcolor
);
525 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
526 str2rcolor(rc
, str
, &rcolor2
);
528 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
530 if ((path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
)) != NULL
)
531 timage
= RLoadImage(rc
, path
, 0);
533 if (!path
|| !timage
) {
534 wwarning("could not load file '%s': %s", path
, RMessageForError(RErrorCode
));
536 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
538 image
= RMakeTiledImage(timage
, width
, height
);
539 RReleaseImage(timage
);
541 i
= atoi(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
543 RCombineImagesWithOpaqueness(image
, grad
, i
);
546 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'M') {
551 switch (toupper(type
[1])) {
553 style
= RVerticalGradient
;
556 style
= RHorizontalGradient
;
560 style
= RDiagonalGradient
;
564 j
= WMGetPropListItemCount(texture
);
567 colors
= wmalloc(j
* sizeof(RColor
*));
569 for (i
= 2; i
< j
; i
++) {
570 str
= WMGetFromPLString(WMGetFromPLArray(texture
, i
));
571 colors
[i
- 2] = wmalloc(sizeof(RColor
));
572 str2rcolor(rc
, str
, colors
[i
- 2]);
574 colors
[i
- 2] = NULL
;
576 image
= RRenderMultiGradient(width
, height
, colors
, style
);
578 for (i
= 0; colors
[i
] != NULL
; i
++)
582 } else if (strcasecmp(&type
[1], "pixmap") == 0) {
583 RImage
*timage
= NULL
;
587 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
589 if ((path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
)) != NULL
)
590 timage
= RLoadImage(rc
, path
, 0);
592 if (!path
|| !timage
) {
593 wwarning("could not load file '%s': %s", path
? path
: str
, RMessageForError(RErrorCode
));
595 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
596 str2rcolor(rc
, str
, &color
);
598 switch (toupper(type
[0])) {
600 image
= RMakeTiledImage(timage
, width
, height
);
601 RReleaseImage(timage
);
605 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
606 RReleaseImage(timage
);
611 image
= RScaleImage(timage
, width
, height
);
612 RReleaseImage(timage
);
625 dumpRImage(path
, image
);
629 if (border
== MENU_BEVEL
) {
630 drawMenuBevel(image
);
631 RBevelImage(image
, RBEV_RAISED2
);
634 RBevelImage(image
, border
);
637 RConvertImage(rc
, image
, &pixmap
);
638 RReleaseImage(image
);
643 static Pixmap
renderMenu(_Panel
* panel
, WMPropList
* texture
, int width
, int iheight
)
645 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
646 Display
*dpy
= WMScreenDisplay(scr
);
648 //RContext *rc = WMScreenRContext(scr);
649 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
652 switch (panel
->menuStyle
) {
654 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
656 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
* 4, WMScreenDepth(scr
));
657 for (i
= 0; i
< 4; i
++) {
658 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
* i
);
660 XFreePixmap(dpy
, tmp
);
663 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, MENU_BEVEL
);
666 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, RBEV_RAISED2
);
674 static void renderClip(_Panel
* panel
, GC gc
, int part
, int relief
)
676 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
677 Display
*dpy
= WMScreenDisplay(scr
);
678 RContext
*rc
= WMScreenRContext(scr
);
690 prop
= GetObjectForKey(textureOptions
[part
]);
692 pix
= renderTexture(scr
, prop
,
693 previewPositions
[part
].size
.width
, previewPositions
[part
].size
.height
, NULL
, relief
);
695 original
= XGetImage(dpy
, pix
, 0, 0, 64, 64, AllPlanes
, ZPixmap
);
697 wwarning(_("error capturing \"original\" tile image"), RMessageForError(RErrorCode
));
699 tile
= RCreateImageFromXImage(rc
, original
, NULL
);
701 XDestroyImage(original
);
702 XFreePixmap(WMScreenDisplay(scr
), pix
);
704 pt
= CLIP_BUTTON_SIZE
* ICON_SIZE
/ 64;
705 tp
= ICON_SIZE
- 1 - pt
;
709 black
.red
= black
.green
= black
.blue
= 0;
712 dark
.red
= dark
.green
= dark
.blue
= 60;
715 light
.red
= light
.green
= light
.blue
= 80;
718 ROperateLine(tile
, RSubtractOperation
, tp
, 0, ICON_SIZE
- 2, pt
- 1, &dark
);
719 RDrawLine(tile
, tp
- 1, 0, ICON_SIZE
- 1, pt
+ 1, &black
);
720 ROperateLine(tile
, RAddOperation
, tp
, 2, ICON_SIZE
- 3, pt
, &light
);
723 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, 4, &dark
);
724 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5, ICON_SIZE
- 5, 6 + as
, &dark
);
725 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
, &light
);
728 ROperateLine(tile
, RAddOperation
, 2, tp
+ 2, pt
- 2, ICON_SIZE
- 3, &dark
);
729 RDrawLine(tile
, 0, tp
- 1, pt
+ 1, ICON_SIZE
- 1, &black
);
730 ROperateLine(tile
, RSubtractOperation
, 0, tp
- 2, pt
+ 1, ICON_SIZE
- 2, &light
);
733 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4, ICON_SIZE
- 5, &dark
);
734 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
, 6 + as
, ICON_SIZE
- 5, &dark
);
735 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5, &light
);
737 RConvertImage(rc
, tile
, &pix
);
739 /* top right arrow */
740 p
[0].x
= p
[3].x
= ICON_SIZE
- 5 - as
;
742 p
[1].x
= ICON_SIZE
- 6;
744 p
[2].x
= ICON_SIZE
- 6;
746 XFillPolygon(dpy
, pix
, WMColorGC(panel
->colors
[4]), p
, 3, Convex
, CoordModeOrigin
);
747 XDrawLines(dpy
, pix
, WMColorGC(panel
->colors
[4]), p
, 4, CoordModeOrigin
);
749 /* bottom left arrow */
751 p
[0].y
= p
[3].y
= ICON_SIZE
- 5 - as
;
753 p
[1].y
= ICON_SIZE
- 6;
755 p
[2].y
= ICON_SIZE
- 6;
756 XFillPolygon(dpy
, pix
, WMColorGC(panel
->colors
[4]), p
, 3, Convex
, CoordModeOrigin
);
757 XDrawLines(dpy
, pix
, WMColorGC(panel
->colors
[4]), p
, 4, CoordModeOrigin
);
759 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
760 previewPositions
[part
].size
.width
,
761 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
764 XFreePixmap(WMScreenDisplay(scr
), pix
);
767 static void renderPreview(_Panel
* panel
, GC gc
, int part
, int relief
)
771 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
773 prop
= GetObjectForKey(textureOptions
[part
]);
775 pix
= renderTexture(scr
, prop
,
776 previewPositions
[part
].size
.width
, previewPositions
[part
].size
.height
, NULL
, relief
);
777 XCopyArea(WMScreenDisplay(scr
), pix
,
778 panel
->preview
, gc
, 0, 0,
779 previewPositions
[part
].size
.width
,
780 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
782 XFreePixmap(WMScreenDisplay(scr
), pix
);
785 static void paintPreviewBox(Panel
* panel
, int elements
)
787 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
788 Display
*dpy
= WMScreenDisplay(scr
);
791 WMColor
*black
= WMBlackColor(scr
);
794 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
796 if (panel
->preview
== None
) {
799 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
800 240 - 4, 190 - 4, WMScreenDepth(scr
));
802 pix
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
, 240 - 4, 190 - 4, WMScreenDepth(scr
));
804 WMSetLabelImage(panel
->prevL
, pix
);
805 WMReleasePixmap(pix
);
807 XFillRectangle(dpy
, panel
->preview
, WMColorGC(panel
->back
), 0, 0, 240 - 4, 190 - 4);
809 if (elements
& (1 << WINTITLE
)) {
810 renderPreview(panel
, gc
, WINTITLE
, RBEV_RAISED2
);
811 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
812 previewPositions
[WINTITLE
].pos
.x
- 1,
813 previewPositions
[WINTITLE
].pos
.y
- 1,
814 previewPositions
[WINTITLE
].size
.width
, previewPositions
[WINTITLE
].size
.height
);
816 if (elements
& (1 << DISTITLE
)) {
817 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(panel
->back
),
818 previewPositions
[DISTITLE
].pos
.x
- 1,
819 previewPositions
[DISTITLE
].pos
.y
- 1,
820 previewPositions
[DISTITLE
].size
.width
, previewPositions
[DISTITLE
].size
.height
);
822 if (elements
& (1 << PMTITLE
)) {
823 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
824 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
825 previewPositions
[PMTITLE
].pos
.x
- 1,
826 previewPositions
[PMTITLE
].pos
.y
- 1,
827 previewPositions
[PMTITLE
].size
.width
, previewPositions
[PMTITLE
].size
.height
);
829 if (elements
& (1 << PMITEM
)) {
832 prop
= GetObjectForKey(textureOptions
[PMITEM
]);
833 mitem
= renderMenu(panel
, prop
,
834 previewPositions
[PMITEM
].size
.width
, previewPositions
[PMITEM
].size
.height
/ 4);
836 XCopyArea(dpy
, mitem
, panel
->preview
, gc
, 0, 0,
837 previewPositions
[PMITEM
].size
.width
,
838 previewPositions
[PMITEM
].size
.height
,
839 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
841 XFreePixmap(dpy
, mitem
);
843 if (elements
& (1 << PMITEM
| 1 << PMTITLE
)) {
844 XDrawLine(dpy
, panel
->preview
, gc
, 29, 125, 29, 125 + 20 * 4 + 25);
845 XDrawLine(dpy
, panel
->preview
, gc
, 119, 125, 119, 125 + 20 * 4 + 25);
847 if (elements
& (1 << PCLIP
)) {
848 renderClip(panel
, gc
, PCLIP
, RBEV_RAISED3
);
849 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
850 previewPositions
[PCLIP
].pos
.x
- 1,
851 previewPositions
[PCLIP
].pos
.y
- 1,
852 previewPositions
[PCLIP
].size
.width
, previewPositions
[PCLIP
].size
.height
);
854 if (elements
& (1 << PICON
)) {
855 renderPreview(panel
, gc
, PICON
, RBEV_RAISED3
);
856 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
857 previewPositions
[PICON
].pos
.x
- 1,
858 previewPositions
[PICON
].pos
.y
- 1,
859 previewPositions
[PICON
].size
.width
, previewPositions
[PICON
].size
.height
);
861 drawFonts(panel
, elements
);
862 WMRedisplayWidget(panel
->prevL
);
864 WMReleaseColor(black
);
867 static void paintTextField(void *data
, int section
)
869 _Panel
*panel
= (_Panel
*) data
;
870 //char *sample = NULL;
872 encoding
= WMGetPopUpButtonSelectedItem(panel
->langP
);
873 WMSetTextFieldFont(panel
->fontT
, getFontForPreview(panel
, section
));
875 case 0: /* Current Font in theme */
876 WMSetTextFieldText(panel
->fontT
,
877 "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
879 case 1: /* default */
880 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
881 // "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
883 case 2: /* latin1 iso8859-1 */
884 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
885 // "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
887 case 3: /* latin2 iso8859-2 */
888 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
889 // "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
891 case 4: /* Greek iso8859-7 */
892 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
893 // "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
895 /* luckily all these happen to have the MultiByte chars in the same places */
896 case 5: /* Japanese jisx0208.1983 */
897 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
898 // "Window Maker ÀßÄê¥æ¡¼¥Æ¥£¥ê¥Æ¥£");
900 case 6: /* Korean ksc5601.1987 */
901 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
902 // "À©µµ¿ì ¸ÞÀÌÄ¿ ¼³Á¤");
904 case 7: /* korean2 daewoo */
905 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
906 // "À©µµ¿ì ¸ÞÀÌÄ¿ ¼³Á¤");
908 case 8: /* Russian koi8-r */
909 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
910 // "ó×ÏÊÓÔ×Á Window Maker");
912 case 9: /* Ukranian koi8-u */
913 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
914 // "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
919 static void previewClick(XEvent
* event
, void *clientData
)
921 _Panel
*panel
= (_Panel
*) clientData
;
924 for (i
= 0; i
< sizeof(previewPositions
) / sizeof(WMRect
); i
++) {
925 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
926 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
927 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
928 + previewPositions
[i
].size
.width
929 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
+ previewPositions
[i
].size
.height
) {
931 WMSetPopUpButtonSelectedItem(panel
->fontSel
, i
);
932 changePage(panel
->fontSel
, panel
);
938 static void changePage(WMWidget
* w
, void *data
)
940 _Panel
*panel
= (_Panel
*) data
;
942 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
943 RContext
*rc
= WMScreenRContext(scr
);
944 static WMPoint positions
[] = {
954 section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
959 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
960 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
961 positions
[panel
->oldsection
].x
, positions
[panel
->oldsection
].y
, 22, 22);
962 WMReleaseColor(color
);
965 panel
->oldsection
= section
;
966 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
968 WMRedisplayWidget(panel
->prevL
);
969 paintTextField(panel
, section
);
970 refillFontSetList(panel
);
973 static void setLanguageType(void *data
, Bool multiByte
)
975 _Panel
*p
= (_Panel
*) data
;
978 WMMapWidget(p
->fsetL
);
979 WMMapWidget(p
->fsetLs
);
980 WMMapWidget(p
->addB
);
981 WMMapWidget(p
->editB
);
982 WMMapWidget(p
->remB
);
984 WMMapWidget(p
->downB
);
986 WMUnmapWidget(p
->fontT
);
987 WMUnmapWidget(p
->changeB
);
989 WMUnmapWidget(p
->fsetL
);
990 WMUnmapWidget(p
->fsetLs
);
991 WMUnmapWidget(p
->addB
);
992 WMUnmapWidget(p
->editB
);
993 WMUnmapWidget(p
->remB
);
994 WMUnmapWidget(p
->upB
);
995 WMUnmapWidget(p
->downB
);
997 WMMapWidget(p
->fontT
);
998 WMMapWidget(p
->changeB
);
1002 static void refillFontSetList(void *data
)
1004 _Panel
*panel
= (_Panel
*) data
;
1006 char *encoding
= getFontEncoding(panel
);
1007 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1010 WMClearList(panel
->fsetLs
);
1012 array
= getCurrentFontProp(panel
, section
);
1014 array
= getDefaultFontProp(panel
, encoding
, section
);
1017 wwarning("error not Font prop given");
1019 for (i
= 0; i
< WMGetPropListItemCount(array
); i
++) {
1020 WMGetFromPLArray(array
, i
);
1021 WMAddListItem(panel
->fsetLs
, WMGetFromPLString(WMGetFromPLArray(array
, i
)));
1023 WMReleasePropList(array
);
1024 WMSelectListItem(panel
->fsetLs
, 0);
1027 checkListForArrows(panel
);
1030 static void insertCurrentFont(char *data
, char *type
)
1036 key
= WMCreatePLString(type
);
1037 array
= WMCreatePLArray(NULL
);
1039 str
= wstrdup(data
);
1040 tmp
= strtok(str
, ",");
1042 WMAddToPLArray(array
, WMCreatePLString(tmp
));
1043 tmp
= strtok(NULL
, ",");
1047 WMPutInPLDictionary(CurrentFontArray
, key
, array
);
1050 static void readFontEncodings(void *data
)
1052 _Panel
*panel
= (_Panel
*) data
;
1053 WMPropList
*pl
= NULL
;
1057 path
= WMPathForResourceOfType("font.data", NULL
);
1059 msg
= _("Could not locate font information file WPrefs.app/font.data");
1063 pl
= WMReadPropListFromFile(path
);
1065 msg
= _("Could not read font information file WPrefs.app/font.data");
1069 WMPropList
*key
= WMCreatePLString("Encodings");
1073 array
= WMGetFromPLDictionary(pl
, key
);
1074 WMReleasePropList(key
);
1075 if (!array
|| !WMIsPLArray(array
)) {
1076 msg
= _("Invalid data in font information file WPrefs.app/font.data.\n"
1077 "Encodings data not found.");
1081 WMAddPopUpButtonItem(panel
->langP
, _("Current"));
1083 for (i
= 0; i
< WMGetPropListItemCount(array
); i
++) {
1084 WMPropList
*item
, *str
;
1086 item
= WMGetFromPLArray(array
, i
);
1087 str
= WMGetFromPLArray(item
, 0);
1088 mi
= WMAddPopUpButtonItem(panel
->langP
, WMGetFromPLString(str
));
1089 WMSetMenuItemRepresentedObject(mi
, WMRetainPropList(item
));
1091 WMSetPopUpButtonSelectedItem(panel
->langP
, 0);
1093 key
= WMCreatePLString("WindowTitleFont");
1094 DefaultWindowTitleFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1095 WMReleasePropList(key
);
1097 key
= WMCreatePLString("MenuTitleFont");
1098 DefaultMenuTitleFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1099 WMReleasePropList(key
);
1101 key
= WMCreatePLString("MenuTextFont");
1102 DefaultMenuTextFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1103 WMReleasePropList(key
);
1105 key
= WMCreatePLString("IconTitleFont");
1106 DefaultIconTitleFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1107 WMReleasePropList(key
);
1109 key
= WMCreatePLString("ClipTitleFont");
1110 DefaultClipTitleFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1111 WMReleasePropList(key
);
1113 key
= WMCreatePLString("LargeDisplayFont");
1114 DefaultLargeDisplayFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1115 WMReleasePropList(key
);
1118 WMReleasePropList(pl
);
1122 WMReleasePropList(pl
);
1124 WMRunAlertPanel(WMWidgetScreen(panel
->parent
), panel
->parent
, _("Error"), msg
, _("OK"), NULL
, NULL
);
1127 static void checkListForArrows(void *data
)
1129 _Panel
*panel
= (_Panel
*) data
;
1131 list
= WMGetListNumberOfRows(panel
->fsetLs
);
1134 if (WMGetListSelectedItemRow(panel
->fsetLs
) == 0) {
1135 WMSetButtonEnabled(panel
->upB
, False
);
1136 WMSetButtonEnabled(panel
->downB
, True
);
1137 } else if (WMGetListSelectedItemRow(panel
->fsetLs
) == list
- 1) {
1138 WMSetButtonEnabled(panel
->downB
, False
);
1139 WMSetButtonEnabled(panel
->upB
, True
);
1141 WMSetButtonEnabled(panel
->upB
, True
);
1142 WMSetButtonEnabled(panel
->downB
, True
);
1146 WMSetButtonEnabled(panel
->upB
, False
);
1147 WMSetButtonEnabled(panel
->downB
, False
);
1149 /* added to control the Remove button */
1151 WMSetButtonEnabled(panel
->remB
, True
);
1153 WMSetButtonEnabled(panel
->remB
, False
);
1156 static char *fontOfLang(void *data
, char *encoding
, int section
)
1158 _Panel
*panel
= (_Panel
*) data
;
1164 array
= getCurrentFontProp(panel
, section
);
1166 array
= getDefaultFontProp(panel
, encoding
, section
);
1169 wwarning("error no font prop given");
1172 for (i
= 0; i
< WMGetPropListItemCount(array
); i
++) {
1174 buf
= wstrconcat(buf
, ",");
1175 buf
= wstrconcat(buf
, WMGetFromPLString(WMGetFromPLArray(array
, i
)));
1177 WMReleasePropList(array
);
1178 return wstrdup(buf
);
1182 static void changeLanguageAction(WMWidget
* w
, void *data
)
1184 Panel
*panel
= (Panel
*) data
;
1185 //WMScreen *scr = WMWidgetScreen(panel->box);
1188 section
= WMGetPopUpButtonSelectedItem(w
);
1190 if (isEncodingMultiByte(panel
)) {
1191 setLanguageType(panel
, True
);
1193 if (panel
->MultiByteText
)
1194 setLanguageType(panel
, True
);
1196 setLanguageType(panel
, False
);
1199 paintPreviewBox(panel
, EVERYTHING
);
1200 changePage(panel
->fontSel
, panel
);
1203 static WMFont
*getFontForPreview(void *data
, int element
)
1205 _Panel
*panel
= (_Panel
*) data
;
1208 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1209 char *encoding
= getFontEncoding(panel
);
1210 fname
= fontOfLang(panel
, encoding
, element
);
1211 //if (WMHasAntialiasingSupport(scr)) {
1212 if (panel
->AntialiasedText
) {
1213 // fix this -Dan font = WMCreateFontWithFlags(scr, fname, WFAntialiased);
1214 font
= WMCreateFont(scr
, fname
);
1216 font
= WMCreateFont(scr
, fname
);
1219 // font = WMCreateFont(scr, fname);
1224 length
= strlen("\"") +
1227 ("\" was not loaded correctly. Make sure the font is available for that encoding.\nLoadind default system font.");
1228 msg
= wmalloc(length
+ 1);
1229 snprintf(msg
, length
+ 1,
1230 "\"%s\" was not loaded correctly. Make sure the font is available for that encoding.\nLoading default system font.",
1232 WMRunAlertPanel(WMWidgetScreen(panel
->parent
), panel
->parent
,
1233 _("Warning"), msg
, _("OK"), NULL
, NULL
);
1234 font
= getDefaultSystemFont(panel
, element
);
1239 static char *getFontSampleString(void *data
)
1241 _Panel
*panel
= (_Panel
*) data
;
1242 //WMScreen *scr = WMWidgetScreen(panel->box);
1247 section
= WMGetPopUpButtonSelectedItem(panel
->langP
);
1248 mi
= WMGetPopUpButtonMenuItem(panel
->langP
, section
);
1249 pl
= WMGetMenuItemRepresentedObject(mi
);
1255 sample
= WMGetFromPLString(WMGetFromPLArray(pl
, 3));
1260 static char *getFontEncoding(void *data
)
1262 _Panel
*panel
= (_Panel
*) data
;
1263 //WMScreen *scr = WMWidgetScreen(panel->box);
1268 section
= WMGetPopUpButtonSelectedItem(panel
->langP
);
1269 mi
= WMGetPopUpButtonMenuItem(panel
->langP
, section
);
1270 pl
= WMGetMenuItemRepresentedObject(mi
);
1276 encoding
= WMGetFromPLString(WMGetFromPLArray(pl
, 2));
1281 static Bool
isEncodingMultiByte(void *data
)
1283 _Panel
*panel
= (_Panel
*) data
;
1284 //WMScreen *scr = WMWidgetScreen(panel->box);
1289 section
= WMGetPopUpButtonSelectedItem(panel
->langP
);
1290 mi
= WMGetPopUpButtonMenuItem(panel
->langP
, section
);
1291 pl
= WMGetMenuItemRepresentedObject(mi
);
1298 multiByte
= WMGetFromPLString(WMGetFromPLArray(pl
, 1));
1299 res
= atoi(multiByte
);
1307 static WMPropList
*getCurrentFontProp(void *data
, int section
)
1312 array
= WMRetainPropList(WMGetFromPLDictionary(CurrentFontArray
,
1313 WMCreatePLString("WindowTitleFont")));
1316 array
= WMRetainPropList(WMGetFromPLDictionary(CurrentFontArray
,
1317 WMCreatePLString("LargeDisplayFont")));
1320 array
= WMRetainPropList(WMGetFromPLDictionary(CurrentFontArray
,
1321 WMCreatePLString("MenuTitleFont")));
1324 array
= WMRetainPropList(WMGetFromPLDictionary(CurrentFontArray
,
1325 WMCreatePLString("MenuTextFont")));
1328 array
= WMRetainPropList(WMGetFromPLDictionary(CurrentFontArray
,
1329 WMCreatePLString("ClipTitleFont")));
1332 array
= WMRetainPropList(WMGetFromPLDictionary(CurrentFontArray
,
1333 WMCreatePLString("IconTitleFont")));
1336 if (!WMIsPLArray(array
)) {
1343 static WMPropList
*getDefaultFontProp(void *data
, char *encoding
, int section
)
1346 WMPropList
*key
= WMCreatePLString(encoding
);
1349 array
= WMRetainPropList(WMGetFromPLDictionary(DefaultWindowTitleFont
, key
));
1350 WMReleasePropList(key
);
1353 array
= WMRetainPropList(WMGetFromPLDictionary(DefaultLargeDisplayFont
, key
));
1354 WMReleasePropList(key
);
1357 array
= WMRetainPropList(WMGetFromPLDictionary(DefaultMenuTitleFont
, key
));
1358 WMReleasePropList(key
);
1361 array
= WMRetainPropList(WMGetFromPLDictionary(DefaultMenuTextFont
, key
));
1362 WMReleasePropList(key
);
1365 array
= WMRetainPropList(WMGetFromPLDictionary(DefaultClipTitleFont
, key
));
1366 WMReleasePropList(key
);
1369 array
= WMRetainPropList(WMGetFromPLDictionary(DefaultIconTitleFont
, key
));
1370 WMReleasePropList(key
);
1373 if (!WMIsPLArray(array
)) {
1380 static WMFont
*getDefaultSystemFont(void *data
, int element
)
1382 _Panel
*panel
= (_Panel
*) data
;
1383 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1388 return WMBoldSystemFontOfSize(scr
, 12);
1390 return WMBoldSystemFontOfSize(scr
, 24);
1393 return WMSystemFontOfSize(scr
, 8);
1396 return WMSystemFontOfSize(scr
, 12);
1400 static void multiClick(WMWidget
* w
, void *data
)
1402 _Panel
*panel
= (_Panel
*) data
;
1403 if (!panel
->MultiByteText
) {
1404 WMSetButtonText(panel
->togMulti
, _("Yes"));
1405 setLanguageType(panel
, True
);
1406 panel
->MultiByteText
= True
;
1408 WMSetButtonText(panel
->togMulti
, _("Auto"));
1409 if (isEncodingMultiByte(panel
))
1410 setLanguageType(panel
, True
);
1412 setLanguageType(panel
, False
);
1413 panel
->MultiByteText
= False
;
1417 static void toggleAA(WMWidget
* w
, void *data
)
1419 _Panel
*panel
= (_Panel
*) data
;
1421 if (panel
->AntialiasedText
)
1422 panel
->AntialiasedText
= False
;
1424 panel
->AntialiasedText
= True
;
1425 /* hmm now i gotta redraw all the fonts in the preview section
1426 * and the text field
1428 paintPreviewBox(panel
, EVERYTHING
);
1429 changePage(panel
->fontSel
, panel
);
1430 if (isEncodingMultiByte(panel
))
1431 setLanguageType(panel
, True
);
1434 static void listClick(WMWidget
* w
, void *data
)
1436 _Panel
*panel
= (_Panel
*) data
;
1438 checkListForArrows(panel
);
1441 static void moveUpListItem(WMWidget
* w
, void *data
)
1443 _Panel
*panel
= (_Panel
*) data
;
1449 char *encoding
= getFontEncoding(panel
);
1450 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1453 array
= getCurrentFontProp(panel
, section
);
1455 array
= getDefaultFontProp(panel
, encoding
, section
);
1457 pos
= WMGetListSelectedItemRow(panel
->fsetLs
);
1459 tmp
= WMGetListItem(panel
->fsetLs
, pos
);
1460 listtext
= wstrdup(tmp
->text
);
1461 string
= WMCreatePLString(listtext
);
1463 WMRemoveListItem(panel
->fsetLs
, pos
);
1464 WMDeleteFromPLArray(array
, pos
);
1465 WMInsertListItem(panel
->fsetLs
, pos
- 1, listtext
);
1466 WMInsertInPLArray(array
, pos
- 1, string
);
1468 paintPreviewBox(panel
, EVERYTHING
);
1469 changePage(panel
->fontSel
, panel
);
1471 WMSelectListItem(panel
->fsetLs
, pos
- 1);
1472 checkListForArrows(panel
);
1475 static void moveDownListItem(WMWidget
* w
, void *data
)
1477 _Panel
*panel
= (_Panel
*) data
;
1483 char *encoding
= getFontEncoding(panel
);
1484 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1487 array
= getCurrentFontProp(panel
, section
);
1489 array
= getDefaultFontProp(panel
, encoding
, section
);
1491 pos
= WMGetListSelectedItemRow(panel
->fsetLs
);
1493 tmp
= WMGetListItem(panel
->fsetLs
, pos
);
1494 listtext
= wstrdup(tmp
->text
);
1495 string
= WMCreatePLString(listtext
);
1496 WMRemoveListItem(panel
->fsetLs
, pos
);
1497 WMDeleteFromPLArray(array
, pos
);
1498 WMInsertListItem(panel
->fsetLs
, pos
+ 1, listtext
);
1499 WMInsertInPLArray(array
, pos
+ 1, string
);
1501 paintPreviewBox(panel
, EVERYTHING
);
1502 changePage(panel
->fontSel
, panel
);
1504 WMSelectListItem(panel
->fsetLs
, pos
+ 1);
1505 checkListForArrows(panel
);
1508 static void addButtonAction(WMWidget
* w
, void *data
)
1510 _Panel
*panel
= (_Panel
*) data
;
1515 char *encoding
= getFontEncoding(panel
);
1516 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1519 array
= getCurrentFontProp(panel
, section
);
1521 array
= getDefaultFontProp(panel
, encoding
, section
);
1523 WMHideFontPanel(panel
->fontPanel
);
1524 chosenFont
= WMGetFontName(WMGetFontPanelFont(panel
->fontPanel
));
1525 string
= WMCreatePLString(chosenFont
);
1526 pos
= WMGetListSelectedItemRow(panel
->fsetLs
);
1527 WMInsertListItem(panel
->fsetLs
, pos
+ 1, chosenFont
);
1528 WMInsertInPLArray(array
, pos
+ 1, string
);
1529 WMSelectListItem(panel
->fsetLs
, pos
+ 1);
1531 paintPreviewBox(panel
, EVERYTHING
);
1532 changePage(panel
->fontSel
, panel
);
1535 static void changeButtonAction(WMWidget
* w
, void *data
)
1537 _Panel
*panel
= (_Panel
*) data
;
1542 char *encoding
= getFontEncoding(panel
);
1543 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1546 array
= getCurrentFontProp(panel
, section
);
1548 array
= getDefaultFontProp(panel
, encoding
, section
);
1550 WMHideFontPanel(panel
->fontPanel
);
1552 chosenFont
= WMGetFontName(WMGetFontPanelFont(panel
->fontPanel
));
1553 string
= WMCreatePLString(chosenFont
);
1555 pos
= WMGetListSelectedItemRow(panel
->fsetLs
);
1556 WMRemoveListItem(panel
->fsetLs
, pos
);
1557 WMDeleteFromPLArray(array
, pos
);
1558 WMInsertListItem(panel
->fsetLs
, pos
, chosenFont
);
1559 WMInsertInPLArray(array
, pos
, string
);
1560 WMSelectListItem(panel
->fsetLs
, pos
);
1562 paintPreviewBox(panel
, EVERYTHING
);
1563 changePage(panel
->fontSel
, panel
);
1566 static void changeButtonClick(WMWidget
* w
, void *data
)
1568 _Panel
*panel
= (_Panel
*) data
;
1570 WMSetFontPanelAction(panel
->fontPanel
, changeButtonAction
, panel
);
1571 WMShowFontPanel(panel
->fontPanel
);
1574 static void addButtonClick(WMWidget
* w
, void *data
)
1576 _Panel
*panel
= (_Panel
*) data
;
1578 WMSetFontPanelAction(panel
->fontPanel
, addButtonAction
, panel
);
1579 WMShowFontPanel(panel
->fontPanel
);
1582 static void removeButtonClick(WMWidget
* w
, void *data
)
1584 _Panel
*panel
= (_Panel
*) data
;
1588 char *encoding
= getFontEncoding(panel
);
1589 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1592 array
= getCurrentFontProp(panel
, section
);
1594 array
= getDefaultFontProp(panel
, encoding
, section
);
1596 pos
= WMGetListSelectedItemRow(panel
->fsetLs
);
1597 WMRemoveListItem(panel
->fsetLs
, pos
);
1598 WMDeleteFromPLArray(array
, pos
);
1600 list
= WMGetListNumberOfRows(panel
->fsetLs
);
1603 WMSelectListItem(panel
->fsetLs
, pos
);
1604 else if (list
== pos
)
1605 WMSelectListItem(panel
->fsetLs
, list
- 1);
1607 WMSelectListItem(panel
->fsetLs
, 0);
1609 checkListForArrows(panel
);
1611 paintPreviewBox(panel
, EVERYTHING
);
1612 changePage(panel
->fontSel
, panel
);
1615 static void showData(_Panel
* panel
)
1617 //WMScreen *scr = WMWidgetScreen(panel->parent);
1621 CurrentFontArray
= WMCreatePLDictionary(NULL
, NULL
);
1623 str
= GetStringForKey("WindowTitleFont");
1624 insertCurrentFont(wstrdup(str
), "WindowTitleFont");
1626 str
= GetStringForKey("LargeDisplayFont");
1627 insertCurrentFont(wstrdup(str
), "LargeDisplayFont");
1629 str
= GetStringForKey("MenuTitleFont");
1630 insertCurrentFont(wstrdup(str
), "MenuTitleFont");
1632 str
= GetStringForKey("MenuTextFont");
1633 insertCurrentFont(wstrdup(str
), "MenuTextFont");
1635 str
= GetStringForKey("ClipTitleFont");
1636 insertCurrentFont(wstrdup(str
), "ClipTitleFont");
1638 str
= GetStringForKey("IconTitleFont");
1639 insertCurrentFont(wstrdup(str
), "IconTitleFont");
1641 /* i put this here cause it needs to be known before we paint */
1642 readFontEncodings(panel
);
1644 str
= GetStringForKey("MenuStyle");
1645 if (str
&& strcasecmp(str
, "flat") == 0) {
1646 panel
->menuStyle
= MSTYLE_FLAT
;
1647 } else if (str
&& strcasecmp(str
, "singletexture") == 0) {
1648 panel
->menuStyle
= MSTYLE_SINGLE
;
1650 panel
->menuStyle
= MSTYLE_NORMAL
;
1653 str
= GetStringForKey("TitleJustify");
1654 if (str
&& strcasecmp(str
, "left") == 0) {
1655 panel
->titleAlignment
= WALeft
;
1656 } else if (str
&& strcasecmp(str
, "right") == 0) {
1657 panel
->titleAlignment
= WARight
;
1659 panel
->titleAlignment
= WACenter
;
1661 for (i
= 0; i
< sizeof(colorOptions
) / (2 * sizeof(char *)); i
++) {
1664 str
= GetStringForKey(colorOptions
[i
* 2]);
1666 str
= colorOptions
[i
* 2 + 1];
1668 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), str
, False
))) {
1669 color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), "#000000", False
);
1671 panel
->colors
[i
] = color
;
1674 str
= GetStringForKey("MultiByteText");
1676 if (strcasecmp(str
, "YES") == 0) {
1677 setLanguageType(panel
, True
);
1678 WMSetButtonText(panel
->togMulti
, "Yes");
1679 printf("yes multi\n");
1680 panel
->MultiByteText
= True
;
1681 } else if (strcasecmp(str
, "AUTO") == 0) {
1683 locale
= setlocale(LC_CTYPE
, NULL
);
1685 && (strncmp(locale
, "ja", 2) == 0
1686 || strncmp(locale
, "zh", 2) == 0 || strncmp(locale
, "ko", 2) == 0)) {
1687 setLanguageType(panel
, True
);
1688 WMSetButtonText(panel
->togMulti
, "Auto");
1689 printf("auto multi\n");
1690 panel
->MultiByteText
= True
;
1692 setLanguageType(panel
, False
);
1693 WMSetButtonText(panel
->togMulti
, "Auto");
1694 panel
->MultiByteText
= False
;
1699 locale
= setlocale(LC_CTYPE
, NULL
);
1701 && (strncmp(locale
, "ja", 2) == 0
1702 || strncmp(locale
, "zh", 2) == 0 || strncmp(locale
, "ko", 2) == 0)) {
1703 setLanguageType(panel
, True
);
1704 WMSetButtonText(panel
->togMulti
, "Auto");
1705 printf("auto multi\n");
1706 panel
->MultiByteText
= True
;
1708 setLanguageType(panel
, False
);
1709 WMSetButtonText(panel
->togMulti
, "Auto");
1710 panel
->MultiByteText
= False
;
1713 /* gotta check for Antialiasing AFTER MultiByte incase the use has both
1714 * to maintain behavior in Current Fonts set or i could add another if
1715 * statement to setLanguageType =) */
1716 //if (WMHasAntialiasingSupport(scr)) {
1717 WMMapWidget(panel
->togAA
);
1718 if (GetBoolForKey("AntialiasedText")) {
1719 WMSetButtonSelected(panel
->togAA
, True
);
1720 panel
->AntialiasedText
= True
;
1722 WMSetButtonSelected(panel
->togAA
, False
);
1723 panel
->AntialiasedText
= False
;
1726 // WMUnmapWidget(panel->togAA);
1729 paintPreviewBox(panel
, EVERYTHING
);
1732 static void createPanel(Panel
* p
)
1734 _Panel
*panel
= (_Panel
*) p
;
1735 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1737 panel
->box
= WMCreateBox(panel
->parent
);
1738 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
1740 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1741 panel
->up_arrow
= WMCreatePixmapFromXPMData(scr
, up_arrow_xpm
);
1742 panel
->down_arrow
= WMCreatePixmapFromXPMData(scr
, down_arrow_xpm
);
1743 panel
->alt_up_arrow
= WMCreatePixmapFromXPMData(scr
, alt_up_arrow_xpm
);
1744 panel
->alt_down_arrow
= WMCreatePixmapFromXPMData(scr
, alt_down_arrow_xpm
);
1746 panel
->prevL
= WMCreateLabel(panel
->box
);
1747 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 45);
1748 WMMoveWidget(panel
->prevL
, 15, 35);
1749 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1750 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1752 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
, previewClick
, panel
);
1754 /* Widget Selection */
1755 panel
->fontSel
= WMCreatePopUpButton(panel
->box
);
1756 WMResizeWidget(panel
->fontSel
, 135, 20);
1757 WMMoveWidget(panel
->fontSel
, 15, 10);
1758 WMAddPopUpButtonItem(panel
->fontSel
, _("Window Title Font"));
1759 WMAddPopUpButtonItem(panel
->fontSel
, _("Large Display Font"));
1760 WMAddPopUpButtonItem(panel
->fontSel
, _("Menu Title Font"));
1761 WMAddPopUpButtonItem(panel
->fontSel
, _("Menu Item Font"));
1762 WMAddPopUpButtonItem(panel
->fontSel
, _("Clip Title Font"));
1763 WMAddPopUpButtonItem(panel
->fontSel
, _("Icon Title Font"));
1765 WMSetPopUpButtonSelectedItem(panel
->fontSel
, 0);
1767 WMSetPopUpButtonAction(panel
->fontSel
, changePage
, panel
);
1769 /* MultiByteText toggle */
1770 panel
->multiF
= WMCreateFrame(panel
->box
);
1771 WMResizeWidget(panel
->multiF
, 70, 50);
1772 WMMoveWidget(panel
->multiF
, 440, 10);
1773 WMSetFrameTitle(panel
->multiF
, _("MultiByte"));
1775 panel
->togMulti
= WMCreateCommandButton(panel
->multiF
);
1776 WMResizeWidget(panel
->togMulti
, 40, 20);
1777 WMMoveWidget(panel
->togMulti
, 15, 20);
1778 WMSetButtonAction(panel
->togMulti
, multiClick
, panel
);
1780 WMMapSubwidgets(panel
->multiF
);
1782 /* language selection */
1783 panel
->langF
= WMCreateFrame(panel
->box
);
1784 WMResizeWidget(panel
->langF
, 165, 50);
1785 WMMoveWidget(panel
->langF
, 265, 10);
1786 WMSetFrameTitle(panel
->langF
, _("Default Font Encodings"));
1788 panel
->langP
= WMCreatePopUpButton(panel
->langF
);
1789 WMResizeWidget(panel
->langP
, 135, 20);
1790 WMMoveWidget(panel
->langP
, 15, 20);
1792 WMSetPopUpButtonAction(panel
->langP
, changeLanguageAction
, panel
);
1794 WMMapSubwidgets(panel
->langF
);
1797 //if (WMHasAntialiasingSupport(scr)) {
1798 panel
->togAA
= WMCreateSwitchButton(panel
->box
);
1799 WMResizeWidget(panel
->togAA
, 110, 20);
1800 WMMoveWidget(panel
->togAA
, 155, 10);
1801 WMSetButtonText(panel
->togAA
, _("Smooth Fonts"));
1802 WMSetBalloonTextForView(_("Smooth Font edges for the eye candy\n"
1803 "requires a restart after saving"), WMWidgetView(panel
->togAA
));
1804 WMSetButtonAction(panel
->togAA
, toggleAA
, panel
);
1807 panel
->fsetL
= WMCreateLabel(panel
->box
);
1808 WMResizeWidget(panel
->fsetL
, 245, 20);
1809 WMMoveWidget(panel
->fsetL
, 265, 70);
1810 WMSetLabelText(panel
->fsetL
, _("Font Set"));
1811 WMSetLabelRelief(panel
->fsetL
, WRSunken
);
1812 WMSetLabelTextAlignment(panel
->fsetL
, WACenter
);
1817 color
= WMDarkGrayColor(scr
);
1818 font
= WMBoldSystemFontOfSize(scr
, 12);
1820 WMSetWidgetBackgroundColor(panel
->fsetL
, color
);
1821 WMSetLabelFont(panel
->fsetL
, font
);
1823 WMReleaseFont(font
);
1824 WMReleaseColor(color
);
1826 color
= WMWhiteColor(scr
);
1827 WMSetLabelTextColor(panel
->fsetL
, color
);
1828 WMReleaseColor(color
);
1831 panel
->fsetLs
= WMCreateList(panel
->box
);
1832 WMResizeWidget(panel
->fsetLs
, 245, 86);
1833 WMMoveWidget(panel
->fsetLs
, 265, 92);
1834 WMSetListAction(panel
->fsetLs
, listClick
, panel
);
1835 WMSetListDoubleAction(panel
->fsetLs
, changeButtonClick
, panel
);
1837 panel
->addB
= WMCreateCommandButton(panel
->box
);
1838 WMResizeWidget(panel
->addB
, 78, 24);
1839 WMMoveWidget(panel
->addB
, 265, 201);
1840 WMSetButtonText(panel
->addB
, _("Add..."));
1841 WMSetButtonAction(panel
->addB
, addButtonClick
, panel
);
1843 panel
->editB
= WMCreateCommandButton(panel
->box
);
1844 WMResizeWidget(panel
->editB
, 78, 24);
1845 WMMoveWidget(panel
->editB
, 348, 201);
1846 WMSetButtonText(panel
->editB
, _("Change..."));
1847 WMSetButtonAction(panel
->editB
, changeButtonClick
, panel
);
1849 panel
->remB
= WMCreateCommandButton(panel
->box
);
1850 WMResizeWidget(panel
->remB
, 78, 24);
1851 WMMoveWidget(panel
->remB
, 431, 201);
1852 WMSetButtonText(panel
->remB
, _("Remove"));
1853 WMSetButtonAction(panel
->remB
, removeButtonClick
, panel
);
1855 /* happy Up/Down buttons */
1856 panel
->upB
= WMCreateCommandButton(panel
->box
);
1857 WMResizeWidget(panel
->upB
, 16, 16);
1858 WMMoveWidget(panel
->upB
, 265, 182);
1859 WMSetButtonImage(panel
->upB
, panel
->up_arrow
);
1860 WMSetButtonAltImage(panel
->upB
, panel
->alt_up_arrow
);
1861 WMSetButtonImagePosition(panel
->upB
, WIPImageOnly
);
1862 WMSetButtonImageDimsWhenDisabled(panel
->upB
, True
);
1863 WMSetButtonAction(panel
->upB
, moveUpListItem
, panel
);
1865 panel
->downB
= WMCreateCommandButton(panel
->box
);
1866 WMResizeWidget(panel
->downB
, 16, 16);
1867 WMMoveWidget(panel
->downB
, 286, 182);
1868 WMSetButtonImage(panel
->downB
, panel
->down_arrow
);
1869 WMSetButtonAltImage(panel
->downB
, panel
->alt_down_arrow
);
1870 WMSetButtonImagePosition(panel
->downB
, WIPImageOnly
);
1871 WMSetButtonImageDimsWhenDisabled(panel
->downB
, True
);
1872 WMSetButtonAction(panel
->downB
, moveDownListItem
, panel
);
1875 panel
->fontT
= WMCreateTextField(panel
->box
);
1876 WMResizeWidget(panel
->fontT
, 245, 30);
1877 WMMoveWidget(panel
->fontT
, 265, 120);
1879 panel
->changeB
= WMCreateCommandButton(panel
->box
);
1880 WMResizeWidget(panel
->changeB
, 104, 24);
1881 WMMoveWidget(panel
->changeB
, 335, 160);
1882 WMSetButtonText(panel
->changeB
, _("Change..."));
1883 WMSetButtonAction(panel
->changeB
, changeButtonClick
, panel
);
1885 panel
->black
= WMBlackColor(scr
);
1886 panel
->white
= WMWhiteColor(scr
);
1887 panel
->light
= WMGrayColor(scr
);
1888 panel
->dark
= WMDarkGrayColor(scr
);
1889 panel
->back
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1891 /* Font Panel !!!!! */
1892 panel
->fontPanel
= WMGetFontPanel(scr
);
1895 for (i
= 0; Languages
[i
].language
!= NULL
; i
++) {
1896 WMAddPopUpButtonItem(panel
->langP
, Languages
[i
].language
);
1899 for (i
= 0; Options
[i
].description
!= NULL
; i
++) {
1900 WMAddListItem(panel
->settingLs
, Options
[i
].description
);
1903 WMRealizeWidget(panel
->box
);
1904 WMMapSubwidgets(panel
->box
);
1907 changePage(panel
->fontSel
, panel
);
1910 static void storeData(Panel
* p
)
1912 _Panel
*panel
= (_Panel
*) p
;
1915 char *encoding
= getFontEncoding(panel
);
1917 for (i
= 0; i
< 6; i
++) {
1920 SetStringForKey(fontOfLang(panel
, encoding
, i
), "WindowTitleFont");
1923 SetStringForKey(fontOfLang(panel
, encoding
, i
), "LargeDisplayFont");
1926 SetStringForKey(fontOfLang(panel
, encoding
, i
), "MenuTitleFont");
1929 SetStringForKey(fontOfLang(panel
, encoding
, i
), "MenuTextFont");
1932 SetStringForKey(fontOfLang(panel
, encoding
, i
), "ClipTitleFont");
1935 SetStringForKey(fontOfLang(panel
, encoding
, i
), "IconTitleFont");
1940 //if (WMHasAntialiasingSupport(WMWidgetScreen(panel->box)))
1941 SetBoolForKey(WMGetButtonSelected(panel
->togAA
), "AntialiasedText");
1943 if (panel
->MultiByteText
)
1944 SetStringForKey("YES", "MultiByteText");
1946 if (isEncodingMultiByte(panel
))
1947 SetStringForKey("YES", "MultiByteText");
1949 SetStringForKey("AUTO", "MultiByteText");
1953 static void prepClosure(Panel
* p
)
1955 _Panel
*panel
= (_Panel
*) p
;
1956 WMFreeFontPanel(panel
->fontPanel
);
1957 WMReleasePropList(CurrentFontArray
);
1958 /* and what ever else i've forgotten or overlooked
1959 * maybe someone will add them */
1962 Panel
*InitFont(WMScreen
* scr
, WMWidget
* parent
)
1966 panel
= wmalloc(sizeof(_Panel
));
1967 memset(panel
, 0, sizeof(_Panel
));
1969 panel
->sectionName
= _("Font Preferences");
1970 panel
->description
= _("Font Configurations for Windows, Menus etc");
1972 panel
->parent
= parent
;
1974 panel
->callbacks
.createWidgets
= createPanel
;
1975 panel
->callbacks
.updateDomain
= storeData
;
1976 panel
->callbacks
.prepareForClose
= prepClosure
;
1978 AddSection(panel
, ICON_FILE
);