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,
25 #include <X11/Xlocale.h>
28 typedef struct _Panel
{
34 CallbackRec callbacks
;
41 WMFontPanel
*fontPanel
;
43 WMPopUpButton
*fontSel
;
79 WMPixmap
*alt_up_arrow
;
80 WMPixmap
*alt_down_arrow
;
92 #define ICON_FILE "fonts"
94 static WMRect previewPositions
[] = {
100 {{30, 105},{90, 20}},
102 {{30, 125},{90, 20*4}},
104 {{156, 35},{64, 64}},
106 {{156, 105},{64, 64}}
108 #define EVERYTHING 0xff
110 static char *colorOptions
[] = {
111 #define FTITLE (1<<0)
112 "FTitleColor", "white",
113 #define DISCOL (1<<1) /* Display uses white always */
114 #define MTITLE (1<<2)
115 "MenuTitleColor", "white",
117 "MenuTextColor", "black",
119 "ClipTitleColor", "black",
121 "ClipTitleColor", "#454045",
123 "IconTitleColor", "white",
125 "IconTitleBack", "black"
128 #define MSTYLE_NORMAL 0
129 #define MSTYLE_SINGLE 1
130 #define MSTYLE_FLAT 2
133 #define RESIZEBAR_BEVEL -1
134 #define MENU_BEVEL -2
135 #define CLIP_BUTTON_SIZE 23
139 static char *textureOptions
[] = {
149 static char * hand_xpm
[] = {
173 " .%%%&@.......... ",
174 " .%*%%&#%%%%%%%%%$. ",
175 " .*#%%%%%%%%%&&&&==. ",
176 " .-%%%%%%%%%=*-;;;#$. ",
177 " .-%%%%%%%%&..>..... ",
192 static char *up_arrow_xpm
[] = {
208 static char *down_arrow_xpm
[] = {
224 static char *alt_up_arrow_xpm
[] = {
239 static char *alt_down_arrow_xpm
[] = {
255 static WMPropList
*CurrentFontArray
= NULL
;
256 //static WMPropList *CurrentMenuTitleFont = NULL;
257 //static WMPropList *CurrentMenuTextFont = NULL;
258 //static WMPropList *CurrentIconTitleFont = NULL;
259 //static WMPropList *CurrentClipTitleFont = NULL;
260 //static WMPropList *CurrentLargeDisplayFont = NULL;
262 static WMPropList
*DefaultWindowTitleFont
= NULL
;
263 static WMPropList
*DefaultMenuTitleFont
= NULL
;
264 static WMPropList
*DefaultMenuTextFont
= NULL
;
265 static WMPropList
*DefaultIconTitleFont
= NULL
;
266 static WMPropList
*DefaultClipTitleFont
= NULL
;
267 static WMPropList
*DefaultLargeDisplayFont
= NULL
;
269 static void changePage(WMWidget
*w
, void *data
);
270 static void setLanguageType(void *data
, Bool multiByte
);
271 static void refillFontSetList(void *data
);
272 static void readFontEncodings(void *data
);
273 static void changeLanguageAction(WMWidget
*w
, void *data
);
274 static void checkListForArrows(void *data
);
276 static char* getFontEncoding(void *data
);
277 static char* getFontSampleString(void *data
);
279 /* note single element */
280 static WMFont
* getFontForPreview(void *data
, int element
);
281 static WMFont
* getDefaultSystemFont(void *data
, int element
);
283 static WMPropList
* getDefaultFontProp(void *data
, char *encoding
, int section
);
284 static WMPropList
* getCurrentFontProp(void *data
, int section
);
286 static Bool
isEncodingMultiByte(void *data
);
289 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
293 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
296 color
->red
= xcolor
.red
>> 8;
297 color
->green
= xcolor
.green
>> 8;
298 color
->blue
= xcolor
.blue
>> 8;
302 drawMenuBevel(RImage
*img
)
304 RColor light
, dark
, mid
;
306 int iheight
= img
->height
/ 4;
309 light
.red
= light
.green
= light
.blue
= 80;
312 dark
.red
= dark
.green
= dark
.blue
= 0;
315 mid
.red
= mid
.green
= mid
.blue
= 40;
317 for (i
= 1; i
< 4; i
++) {
318 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
319 img
->width
-1, i
*iheight
-2, &mid
);
321 RDrawLine(img
, 0, i
*iheight
-1, img
->width
-1, i
*iheight
-1, &dark
);
323 ROperateLine(img
, RAddOperation
, 1, i
*iheight
,
324 img
->width
-2, i
*iheight
, &light
);
329 paintTitle(WMScreen
*scr
, Drawable d
, WMColor
*color
, WMFont
*font
,
330 int part
, WMAlignment align
, char *text
)
332 int l
= strlen(text
);
333 int x
= previewPositions
[part
].pos
.x
;
334 int y
= previewPositions
[part
].pos
.y
;
335 int w
= previewPositions
[part
].size
.width
;
336 int h
= previewPositions
[part
].size
.height
;
343 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
347 x
+= (w
- WMWidthOfString(font
, text
, l
))/2;
350 WMDrawString(scr
, d
, color
, font
, x
,
351 y
+ (h
- WMFontHeight(font
))/2, text
, l
);
355 paintItems(WMScreen
*scr
, Drawable d
, WMColor
*color
, WMFont
*font
,
356 int part
, char *text
)
358 int l
= strlen(text
);
359 int x
= previewPositions
[part
].pos
.x
;
360 int y
= previewPositions
[part
].pos
.y
;
361 int w
= previewPositions
[part
].size
.width
;
362 int h
= previewPositions
[part
].size
.height
/4;
364 for( i
= 0; i
< 4 ; i
++) {
365 WMDrawString(scr
, d
, color
, font
, x
+5,
366 y
+(20*i
)+(h
- WMFontHeight(font
))/2, text
, l
);
371 paintIcon(WMScreen
*scr
,Drawable d
, WMColor
*color
, WMColor
*Iback
,
372 WMFont
*font
, int part
, char *text
)
374 Display
*dpy
= WMScreenDisplay(scr
);
375 int l
= strlen(text
);
376 int x
= previewPositions
[part
].pos
.x
+1;
377 int y
= previewPositions
[part
].pos
.y
+1;
378 int w
= previewPositions
[part
].size
.width
-2;
379 int h
= WMFontHeight(font
)+2;
381 XFillRectangle(dpy
, d
, WMColorGC(Iback
), x
, y
, w
, h
);
382 x
+= (w
- WMWidthOfString(font
, text
, l
))/2;
383 WMDrawString(scr
, d
, color
, font
, x
,
384 y
+ (h
- WMFontHeight(font
))/2, text
, l
);
389 drawFonts(_Panel
*panel
, int elements
)
391 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
395 pixmap
= WMGetLabelImage(panel
->prevL
);
396 d
= WMGetPixmapXID(pixmap
);
398 if(elements
& FTITLE
) {
399 paintTitle(scr
, d
, panel
->colors
[0], getFontForPreview(panel
, WINTITLE
),
400 WINTITLE
, panel
->titleAlignment
, _("Window Title Font"));
402 if(elements
& DISCOL
) {
403 paintTitle(scr
, d
, panel
->white
, getFontForPreview(panel
, DISTITLE
),
404 DISTITLE
, WACenter
, _("Display"));
406 if(elements
& MTITLE
) {
407 paintTitle(scr
, d
, panel
->colors
[1], getFontForPreview(panel
, PMTITLE
),
408 PMTITLE
, WALeft
, _("Menu Title"));
410 if(elements
& MITEM
) {
411 paintItems(scr
, d
, panel
->colors
[2], getFontForPreview(panel
, PMITEM
),
412 PMITEM
, _("Menu Item"));
414 if(elements
& CLIP
) {
415 WMDrawString(scr
, d
, panel
->colors
[4],
416 getFontForPreview(panel
, PCLIP
), 169,37, "1",1);
417 WMDrawString(scr
, d
, panel
->colors
[3],
418 getFontForPreview(panel
, PCLIP
),179, 84, _("Clip title"), 10);
420 if(elements
& ICONT
) {
421 paintIcon(scr
, d
, panel
->colors
[5], panel
->colors
[6],
422 getFontForPreview(panel
, PICON
), PICON
, _("Icon Title"));
427 dumpRImage(char *path
, RImage
*image
)
430 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
432 f
= fopen(path
, "w");
437 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
, channels
);
439 fwrite(image
->data
, 1, image
->width
* image
->height
* channels
, f
);
447 isPixmap(WMPropList
*prop
)
452 p
= WMGetFromPLArray(prop
, 0);
453 s
= WMGetFromPLString(p
);
454 if (strcasecmp(&s
[1], "pixmap")==0)
461 renderTexture(WMScreen
*scr
, WMPropList
*texture
, int width
, int height
,
462 char *path
, int border
)
465 RImage
*image
= NULL
;
467 RContext
*rc
= WMScreenRContext(scr
);
472 type
= WMGetFromPLString(WMGetFromPLArray(texture
, 0));
474 if (strcasecmp(type
, "solid")==0) {
476 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
478 str2rcolor(rc
, str
, &rcolor
);
480 image
= RCreateImage(width
, height
, False
);
481 RClearImage(image
, &rcolor
);
482 } else if (strcasecmp(type
, "igradient")==0) {
486 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
487 str2rcolor(rc
, str
, &c1
[0]);
488 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
489 str2rcolor(rc
, str
, &c1
[1]);
490 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
493 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
494 str2rcolor(rc
, str
, &c2
[0]);
495 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 5));
496 str2rcolor(rc
, str
, &c2
[1]);
497 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 6));
500 image
= RRenderInterwovenGradient(width
, height
, c1
, t1
, c2
, t2
);
501 } else if (strcasecmp(&type
[1], "gradient")==0) {
505 switch (toupper(type
[0])) {
507 style
= RVerticalGradient
;
510 style
= RHorizontalGradient
;
514 style
= RDiagonalGradient
;
518 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
519 str2rcolor(rc
, str
, &rcolor
);
520 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
521 str2rcolor(rc
, str
, &rcolor2
);
523 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
524 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
528 RImage
*grad
, *timage
;
531 switch (toupper(type
[1])) {
533 style
= RVerticalGradient
;
536 style
= RHorizontalGradient
;
540 style
= RDiagonalGradient
;
544 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
545 str2rcolor(rc
, str
, &rcolor
);
546 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
547 str2rcolor(rc
, str
, &rcolor2
);
549 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
551 if ((path
=wfindfileinarray(GetObjectForKey("PixmapPath"), str
))!=NULL
)
552 timage
= RLoadImage(rc
, path
, 0);
554 if (!path
|| !timage
) {
555 wwarning("could not load file '%s': %s", path
,
556 RMessageForError(RErrorCode
));
558 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
560 image
= RMakeTiledImage(timage
, width
, height
);
561 RReleaseImage(timage
);
563 i
= atoi(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
565 RCombineImagesWithOpaqueness(image
, grad
, i
);
568 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
573 switch (toupper(type
[1])) {
575 style
= RVerticalGradient
;
578 style
= RHorizontalGradient
;
582 style
= RDiagonalGradient
;
586 j
= WMGetPropListItemCount(texture
);
589 colors
= wmalloc(j
* sizeof(RColor
*));
591 for (i
= 2; i
< j
; i
++) {
592 str
= WMGetFromPLString(WMGetFromPLArray(texture
, i
));
593 colors
[i
-2] = wmalloc(sizeof(RColor
));
594 str2rcolor(rc
, str
, colors
[i
-2]);
598 image
= RRenderMultiGradient(width
, height
, colors
, style
);
600 for (i
= 0; colors
[i
]!=NULL
; i
++)
604 } else if (strcasecmp(&type
[1], "pixmap")==0) {
605 RImage
*timage
= NULL
;
609 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
611 if ((path
=wfindfileinarray(GetObjectForKey("PixmapPath"), str
))!=NULL
)
612 timage
= RLoadImage(rc
, path
, 0);
614 if (!path
|| !timage
) {
615 wwarning("could not load file '%s': %s", path
? path
: str
,
616 RMessageForError(RErrorCode
));
618 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
619 str2rcolor(rc
, str
, &color
);
621 switch (toupper(type
[0])) {
623 image
= RMakeTiledImage(timage
, width
, height
);
624 RReleaseImage(timage
);
628 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
629 RReleaseImage(timage
);
634 image
= RScaleImage(timage
, width
, height
);
635 RReleaseImage(timage
);
648 dumpRImage(path
, image
);
652 if (border
== MENU_BEVEL
) {
653 drawMenuBevel(image
);
654 RBevelImage(image
, RBEV_RAISED2
);
657 RBevelImage(image
, border
);
660 RConvertImage(rc
, image
, &pixmap
);
661 RReleaseImage(image
);
667 renderMenu(_Panel
*panel
, WMPropList
*texture
, int width
, int iheight
)
669 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
670 Display
*dpy
= WMScreenDisplay(scr
);
672 RContext
*rc
= WMScreenRContext(scr
);
673 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
676 switch (panel
->menuStyle
) {
678 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
680 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*4, WMScreenDepth(scr
));
681 for (i
= 0; i
< 4; i
++) {
682 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
*i
);
684 XFreePixmap(dpy
, tmp
);
687 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, MENU_BEVEL
);
690 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, RBEV_RAISED2
);
699 renderClip(_Panel
*panel
, GC gc
, int part
, int relief
)
701 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
702 Display
*dpy
= WMScreenDisplay(scr
);
703 RContext
*rc
= WMScreenRContext(scr
);
715 prop
= GetObjectForKey(textureOptions
[part
]);
717 pix
= renderTexture(scr
, prop
,
718 previewPositions
[part
].size
.width
,
719 previewPositions
[part
].size
.height
,
723 original
= XGetImage(dpy
, pix
, 0, 0, 64, 64,
726 wwarning(_("error capturing \"original\" tile image"),
727 RMessageForError(RErrorCode
));
729 tile
= RCreateImageFromXImage(rc
, original
, NULL
);
731 XDestroyImage(original
);
732 XFreePixmap(WMScreenDisplay(scr
), pix
);
734 pt
= CLIP_BUTTON_SIZE
*ICON_SIZE
/64;
735 tp
= ICON_SIZE
-1 - pt
;
739 black
.red
= black
.green
= black
.blue
= 0;
742 dark
.red
= dark
.green
= dark
.blue
= 60;
745 light
.red
= light
.green
= light
.blue
= 80;
749 ROperateLine(tile
, RSubtractOperation
, tp
, 0, ICON_SIZE
-2,
751 RDrawLine(tile
, tp
-1, 0, ICON_SIZE
-1, pt
+1, &black
);
752 ROperateLine(tile
, RAddOperation
, tp
, 2, ICON_SIZE
-3,
756 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 7 - as
, 4,
757 ICON_SIZE
- 5, 4, &dark
);
758 ROperateLine(tile
, RSubtractOperation
, ICON_SIZE
- 6 - as
, 5,
759 ICON_SIZE
- 5, 6 + as
, &dark
);
760 ROperateLine(tile
, RAddOperation
, ICON_SIZE
- 5, 4, ICON_SIZE
- 5, 6 + as
,
764 ROperateLine(tile
, RAddOperation
, 2, tp
+2, pt
-2,
766 RDrawLine(tile
, 0, tp
-1, pt
+1, ICON_SIZE
-1, &black
);
767 ROperateLine(tile
, RSubtractOperation
, 0, tp
-2, pt
+1,
768 ICON_SIZE
-2, &light
);
771 ROperateLine(tile
, RSubtractOperation
, 4, ICON_SIZE
- 7 - as
, 4,
772 ICON_SIZE
- 5, &dark
);
773 ROperateLine(tile
, RSubtractOperation
, 5, ICON_SIZE
- 6 - as
,
774 6 + as
, ICON_SIZE
- 5, &dark
);
775 ROperateLine(tile
, RAddOperation
, 4, ICON_SIZE
- 5, 6 + as
, ICON_SIZE
- 5,
778 RConvertImage(rc
, tile
, &pix
);
780 /* top right arrow */
781 p
[0].x
= p
[3].x
= ICON_SIZE
-5-as
;
783 p
[1].x
= ICON_SIZE
-6;
785 p
[2].x
= ICON_SIZE
-6;
787 XFillPolygon(dpy
, pix
, WMColorGC(panel
->colors
[4]), p
, 3, Convex
, CoordModeOrigin
);
788 XDrawLines(dpy
, pix
, WMColorGC(panel
->colors
[4]), p
, 4, CoordModeOrigin
);
790 /* bottom left arrow */
792 p
[0].y
= p
[3].y
= ICON_SIZE
-5-as
;
794 p
[1].y
= ICON_SIZE
-6;
796 p
[2].y
= ICON_SIZE
-6;
797 XFillPolygon(dpy
, pix
, WMColorGC(panel
->colors
[4]), p
, 3, Convex
, CoordModeOrigin
);
798 XDrawLines(dpy
, pix
, WMColorGC(panel
->colors
[4]), p
, 4, CoordModeOrigin
);
800 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
801 previewPositions
[part
].size
.width
,
802 previewPositions
[part
].size
.height
,
803 previewPositions
[part
].pos
.x
,
804 previewPositions
[part
].pos
.y
);
807 XFreePixmap(WMScreenDisplay(scr
), pix
);
811 renderPreview(_Panel
*panel
, GC gc
, int part
, int relief
)
815 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
817 prop
= GetObjectForKey(textureOptions
[part
]);
819 pix
= renderTexture(scr
, prop
,
820 previewPositions
[part
].size
.width
,
821 previewPositions
[part
].size
.height
,
823 XCopyArea(WMScreenDisplay(scr
), pix
,
824 panel
->preview
, gc
, 0, 0,
825 previewPositions
[part
].size
.width
,
826 previewPositions
[part
].size
.height
,
827 previewPositions
[part
].pos
.x
,
828 previewPositions
[part
].pos
.y
);
830 XFreePixmap(WMScreenDisplay(scr
), pix
);
834 paintPreviewBox(Panel
*panel
, int elements
)
836 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
837 Display
*dpy
= WMScreenDisplay(scr
);
840 WMColor
*black
= WMBlackColor(scr
);
843 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
845 if (panel
->preview
== None
) {
848 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
849 240-4, 190-4, WMScreenDepth(scr
));
851 pix
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
852 240-4, 190-4, WMScreenDepth(scr
));
854 WMSetLabelImage(panel
->prevL
, pix
);
855 WMReleasePixmap(pix
);
857 XFillRectangle(dpy
, panel
->preview
, WMColorGC(panel
->back
),
860 if (elements
& (1<<WINTITLE
)) {
861 renderPreview(panel
, gc
, WINTITLE
, RBEV_RAISED2
);
862 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
863 previewPositions
[WINTITLE
].pos
.x
-1,
864 previewPositions
[WINTITLE
].pos
.y
-1,
865 previewPositions
[WINTITLE
].size
.width
,
866 previewPositions
[WINTITLE
].size
.height
);
868 if (elements
& (1<<DISTITLE
)) {
869 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(panel
->back
),
870 previewPositions
[DISTITLE
].pos
.x
-1,
871 previewPositions
[DISTITLE
].pos
.y
-1,
872 previewPositions
[DISTITLE
].size
.width
,
873 previewPositions
[DISTITLE
].size
.height
);
875 if (elements
& (1<<PMTITLE
)) {
876 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
877 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
878 previewPositions
[PMTITLE
].pos
.x
-1,
879 previewPositions
[PMTITLE
].pos
.y
-1,
880 previewPositions
[PMTITLE
].size
.width
,
881 previewPositions
[PMTITLE
].size
.height
);
883 if (elements
& (1<<PMITEM
)) {
886 prop
= GetObjectForKey(textureOptions
[PMITEM
]);
887 mitem
= renderMenu(panel
, prop
,
888 previewPositions
[PMITEM
].size
.width
,
889 previewPositions
[PMITEM
].size
.height
/4);
891 XCopyArea(dpy
, mitem
, panel
->preview
, gc
, 0, 0,
892 previewPositions
[PMITEM
].size
.width
,
893 previewPositions
[PMITEM
].size
.height
,
894 previewPositions
[PMITEM
].pos
.x
,
895 previewPositions
[PMITEM
].pos
.y
);
897 XFreePixmap(dpy
, mitem
);
899 if (elements
& (1<<PMITEM
|1<<PMTITLE
)) {
900 XDrawLine(dpy
, panel
->preview
, gc
, 29, 125, 29, 125+20*4+25);
901 XDrawLine(dpy
, panel
->preview
, gc
, 119, 125, 119, 125+20*4+25);
903 if (elements
& (1<<PCLIP
)) {
904 renderClip(panel
, gc
, PCLIP
, RBEV_RAISED3
);
905 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
906 previewPositions
[PCLIP
].pos
.x
-1,
907 previewPositions
[PCLIP
].pos
.y
-1,
908 previewPositions
[PCLIP
].size
.width
,
909 previewPositions
[PCLIP
].size
.height
);
911 if (elements
& (1<<PICON
)) {
912 renderPreview(panel
, gc
, PICON
, RBEV_RAISED3
);
913 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
914 previewPositions
[PICON
].pos
.x
-1,
915 previewPositions
[PICON
].pos
.y
-1,
916 previewPositions
[PICON
].size
.width
,
917 previewPositions
[PICON
].size
.height
);
919 drawFonts(panel
, elements
);
920 WMRedisplayWidget(panel
->prevL
);
922 WMReleaseColor(black
);
926 paintTextField(void *data
, int section
)
928 _Panel
*panel
= (_Panel
*)data
;
931 encoding
= WMGetPopUpButtonSelectedItem(panel
->langP
);
932 WMSetTextFieldFont(panel
->fontT
, getFontForPreview(panel
, section
));
934 case 0: /* Current Font in theme */
935 WMSetTextFieldText(panel
->fontT
,
936 "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
938 case 1: /* default */
939 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
940 // "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
942 case 2: /* latin1 iso8859-1 */
943 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
944 // "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
946 case 3: /* latin2 iso8859-2 */
947 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
948 // "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
950 case 4: /* Greek iso8859-7 */
951 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
952 // "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
954 /* luckily all these happen to have the MultiByte chars in the same places */
955 case 5: /* Japanese jisx0208.1983 */
956 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
957 // "Window Maker ÀßÄê¥æ¡¼¥Æ¥£¥ê¥Æ¥£");
959 case 6: /* Korean ksc5601.1987 */
960 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
961 // "À©µµ¿ì ¸ÞÀÌÄ¿ ¼³Á¤");
963 case 7: /* korean2 daewoo */
964 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
965 // "À©µµ¿ì ¸ÞÀÌÄ¿ ¼³Á¤");
967 case 8: /* Russian koi8-r */
968 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
969 // "ó×ÏÊÓÔ×Á Window Maker");
971 case 9: /* Ukranian koi8-u */
972 WMSetTextFieldText(panel
->fontT
, getFontSampleString(panel
));
973 // "ABCDEFGHIKLMNOPQRSTUVXYWZabcdefghiklmnopqrstuvxywz0123456789\x00e0\x00e6\x00e7\x00eb\x00ee\x00f0\x00f1\x00f3\x00f9\x00fd\x00c0\x00c6\x00c7\x00cb\x00ce\x00d0\x00d1\x00d3\x00d9\x00dd");
979 previewClick(XEvent
*event
, void *clientData
)
981 _Panel
*panel
= (_Panel
*)clientData
;
984 for (i
= 0; i
< sizeof(previewPositions
)/sizeof(WMRect
); i
++) {
985 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
986 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
987 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
988 + previewPositions
[i
].size
.width
989 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
990 + previewPositions
[i
].size
.height
) {
992 WMSetPopUpButtonSelectedItem(panel
->fontSel
, i
);
993 changePage(panel
->fontSel
, panel
);
1000 changePage(WMWidget
*w
, void *data
)
1002 _Panel
*panel
= (_Panel
*)data
;
1004 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1005 RContext
*rc
= WMScreenRContext(scr
);
1006 static WMPoint positions
[] = {
1016 section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1021 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1022 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1023 positions
[panel
->oldsection
].x
,
1024 positions
[panel
->oldsection
].y
, 22, 22);
1025 WMReleaseColor(color
);
1028 panel
->oldsection
= section
;
1029 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1030 positions
[section
].y
);
1032 WMRedisplayWidget(panel
->prevL
);
1033 paintTextField(panel
, section
);
1034 refillFontSetList(panel
);
1038 setLanguageType(void *data
, Bool multiByte
)
1040 _Panel
*p
= (_Panel
*)data
;
1043 WMMapWidget(p
->fsetL
);
1044 WMMapWidget(p
->fsetLs
);
1045 WMMapWidget(p
->addB
);
1046 WMMapWidget(p
->editB
);
1047 WMMapWidget(p
->remB
);
1048 WMMapWidget(p
->upB
);
1049 WMMapWidget(p
->downB
);
1051 WMUnmapWidget(p
->fontT
);
1052 WMUnmapWidget(p
->changeB
);
1054 WMUnmapWidget(p
->fsetL
);
1055 WMUnmapWidget(p
->fsetLs
);
1056 WMUnmapWidget(p
->addB
);
1057 WMUnmapWidget(p
->editB
);
1058 WMUnmapWidget(p
->remB
);
1059 WMUnmapWidget(p
->upB
);
1060 WMUnmapWidget(p
->downB
);
1062 WMMapWidget(p
->fontT
);
1063 WMMapWidget(p
->changeB
);
1068 refillFontSetList(void *data
)
1070 _Panel
*panel
= (_Panel
*)data
;
1072 char *encoding
= getFontEncoding(panel
);
1073 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1076 WMClearList(panel
->fsetLs
);
1078 array
= getCurrentFontProp(panel
, section
);
1080 array
= getDefaultFontProp(panel
, encoding
, section
);
1083 wwarning("error not Font prop given");
1085 for (i
= 0; i
< WMGetPropListItemCount(array
); i
++) {
1086 WMGetFromPLArray(array
, i
);
1087 WMAddListItem( panel
->fsetLs
,
1089 WMGetFromPLArray(array
, i
)));
1091 WMReleasePropList(array
);
1092 WMSelectListItem(panel
->fsetLs
, 0);
1095 checkListForArrows(panel
);
1099 insertCurrentFont(char *data
, char *type
)
1105 key
= WMCreatePLString(type
);
1106 array
= WMCreatePLArray(NULL
);
1108 str
= wstrdup(data
);
1109 tmp
= strtok(str
, ",");
1111 WMAddToPLArray(array
, WMCreatePLString(tmp
));
1112 tmp
= strtok(NULL
, ",");
1117 WMPutInPLDictionary(CurrentFontArray
, key
, array
);
1121 readFontEncodings(void *data
)
1123 _Panel
*panel
= (_Panel
*)data
;
1124 WMPropList
*pl
= NULL
;
1128 path
= WMPathForResourceOfType("font.data", NULL
);
1130 msg
= _("Could not locate font information file WPrefs.app/font.data");
1134 pl
= WMReadPropListFromFile(path
);
1136 msg
= _("Could not read font information file WPrefs.app/font.data");
1140 WMPropList
*key
= WMCreatePLString("Encodings");
1144 array
= WMGetFromPLDictionary(pl
, key
);
1145 WMReleasePropList(key
);
1146 if (!array
|| !WMIsPLArray(array
)) {
1147 msg
= _("Invalid data in font information file WPrefs.app/font.data.\n"
1148 "Encodings data not found.");
1152 WMAddPopUpButtonItem(panel
->langP
, _("Current"));
1154 for (i
= 0; i
< WMGetPropListItemCount(array
); i
++) {
1155 WMPropList
*item
, *str
;
1157 item
= WMGetFromPLArray(array
, i
);
1158 str
= WMGetFromPLArray(item
, 0);
1159 mi
= WMAddPopUpButtonItem(panel
->langP
, WMGetFromPLString(str
));
1160 WMSetMenuItemRepresentedObject(mi
, WMRetainPropList(item
));
1162 WMSetPopUpButtonSelectedItem(panel
->langP
, 0);
1165 key
= WMCreatePLString("WindowTitleFont");
1166 DefaultWindowTitleFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1167 WMReleasePropList(key
);
1169 key
= WMCreatePLString("MenuTitleFont");
1170 DefaultMenuTitleFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1171 WMReleasePropList(key
);
1173 key
= WMCreatePLString("MenuTextFont");
1174 DefaultMenuTextFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1175 WMReleasePropList(key
);
1177 key
= WMCreatePLString("IconTitleFont");
1178 DefaultIconTitleFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1179 WMReleasePropList(key
);
1181 key
= WMCreatePLString("ClipTitleFont");
1182 DefaultClipTitleFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1183 WMReleasePropList(key
);
1185 key
= WMCreatePLString("LargeDisplayFont");
1186 DefaultLargeDisplayFont
= WMRetainPropList(WMGetFromPLDictionary(pl
, key
));
1187 WMReleasePropList(key
);
1190 WMReleasePropList(pl
);
1194 WMReleasePropList(pl
);
1196 WMRunAlertPanel(WMWidgetScreen(panel
->parent
), panel
->parent
,
1197 _("Error"), msg
, _("OK"), NULL
, NULL
);
1201 checkListForArrows(void *data
)
1203 _Panel
*panel
= (_Panel
*)data
;
1205 list
= WMGetListNumberOfRows(panel
->fsetLs
);
1209 if(WMGetListSelectedItemRow(panel
->fsetLs
) == 0) {
1210 WMSetButtonEnabled(panel
->upB
, False
);
1211 WMSetButtonEnabled(panel
->downB
, True
);
1212 } else if(WMGetListSelectedItemRow(panel
->fsetLs
) == list
-1) {
1213 WMSetButtonEnabled(panel
->downB
, False
);
1214 WMSetButtonEnabled(panel
->upB
, True
);
1216 WMSetButtonEnabled(panel
->upB
, True
);
1217 WMSetButtonEnabled(panel
->downB
, True
);
1221 WMSetButtonEnabled(panel
->upB
, False
);
1222 WMSetButtonEnabled(panel
->downB
, False
);
1224 /* added to control the Remove button */
1226 WMSetButtonEnabled(panel
->remB
, True
);
1228 WMSetButtonEnabled(panel
->remB
, False
);
1232 fontOfLang(void *data
, char *encoding
, int section
)
1234 _Panel
*panel
= (_Panel
*)data
;
1240 array
= getCurrentFontProp(panel
, section
);
1242 array
= getDefaultFontProp(panel
, encoding
, section
);
1245 wwarning("error no font prop given");
1248 for(i
=0; i
<WMGetPropListItemCount(array
); i
++)
1250 if(buf
) buf
= wstrconcat(buf
, ",");
1251 buf
= wstrconcat(buf
, WMGetFromPLString(WMGetFromPLArray(array
, i
)));
1253 WMReleasePropList(array
);
1254 return wstrdup(buf
);
1259 changeLanguageAction(WMWidget
*w
, void *data
)
1261 Panel
*panel
= (Panel
*)data
;
1262 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1265 section
= WMGetPopUpButtonSelectedItem(w
);
1267 if(isEncodingMultiByte(panel
)) {
1268 setLanguageType(panel
, True
);
1270 if(panel
->MultiByteText
) setLanguageType(panel
, True
);
1271 else setLanguageType(panel
, False
);
1274 paintPreviewBox(panel
, EVERYTHING
);
1275 changePage(panel
->fontSel
, panel
);
1279 getFontForPreview(void *data
, int element
)
1281 _Panel
*panel
= (_Panel
*)data
;
1284 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1285 char *encoding
= getFontEncoding(panel
);
1286 fname
= fontOfLang(panel
, encoding
, element
);
1287 if (WMHasAntialiasingSupport(scr
))
1289 if(panel
->AntialiasedText
) {
1290 font
= WMCreateFontWithFlags(scr
, fname
, WFAntialiased
);
1292 font
= WMCreateFont(scr
, fname
);
1295 font
= WMCreateFont(scr
, fname
);
1300 length
= strlen("\"")+
1301 strlen(fname
)+strlen("\" was not loaded correctly. Make sure the font is available for that encoding.\nLoadind default system font.");
1302 msg
= wmalloc(length
+1);
1303 snprintf(msg
, length
+ 1,
1304 "\"%s\" was not loaded correctly. Make sure the font is available for that encoding.\nLoading default system font.",
1306 WMRunAlertPanel(WMWidgetScreen(panel
->parent
),panel
->parent
,
1307 _("Warning"), msg
, _("OK"), NULL
, NULL
);
1308 font
= getDefaultSystemFont(panel
, element
);
1314 getFontSampleString(void *data
)
1316 _Panel
*panel
= (_Panel
*)data
;
1317 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1322 section
= WMGetPopUpButtonSelectedItem(panel
->langP
);
1323 mi
= WMGetPopUpButtonMenuItem(panel
->langP
, section
);
1324 pl
= WMGetMenuItemRepresentedObject(mi
);
1330 sample
= WMGetFromPLString(WMGetFromPLArray(pl
,3));
1336 getFontEncoding(void *data
)
1338 _Panel
*panel
= (_Panel
*)data
;
1339 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1344 section
= WMGetPopUpButtonSelectedItem(panel
->langP
);
1345 mi
= WMGetPopUpButtonMenuItem(panel
->langP
, section
);
1346 pl
= WMGetMenuItemRepresentedObject(mi
);
1352 encoding
= WMGetFromPLString(WMGetFromPLArray(pl
,2));
1358 isEncodingMultiByte(void *data
)
1360 _Panel
*panel
= (_Panel
*)data
;
1361 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1366 section
= WMGetPopUpButtonSelectedItem(panel
->langP
);
1367 mi
= WMGetPopUpButtonMenuItem(panel
->langP
, section
);
1368 pl
= WMGetMenuItemRepresentedObject(mi
);
1375 multiByte
= WMGetFromPLString(WMGetFromPLArray(pl
,1));
1376 res
= atoi(multiByte
);
1385 getCurrentFontProp(void *data
, int section
)
1390 array
= WMRetainPropList(
1391 WMGetFromPLDictionary(CurrentFontArray
,
1392 WMCreatePLString("WindowTitleFont")));
1395 array
= WMRetainPropList(
1396 WMGetFromPLDictionary(CurrentFontArray
,
1397 WMCreatePLString("LargeDisplayFont")));
1400 array
= WMRetainPropList(
1401 WMGetFromPLDictionary(CurrentFontArray
,
1402 WMCreatePLString("MenuTitleFont")));
1405 array
= WMRetainPropList(
1406 WMGetFromPLDictionary(CurrentFontArray
,
1407 WMCreatePLString("MenuTextFont")));
1410 array
= WMRetainPropList(
1411 WMGetFromPLDictionary(CurrentFontArray
,
1412 WMCreatePLString("ClipTitleFont")));
1415 array
= WMRetainPropList(
1416 WMGetFromPLDictionary(CurrentFontArray
,
1417 WMCreatePLString("IconTitleFont")));
1420 if(!WMIsPLArray(array
)) {
1428 getDefaultFontProp(void *data
, char *encoding
, int section
)
1431 WMPropList
*key
= WMCreatePLString(encoding
);
1434 array
= WMRetainPropList(
1435 WMGetFromPLDictionary(DefaultWindowTitleFont
, key
));
1436 WMReleasePropList(key
);
1439 array
= WMRetainPropList(
1440 WMGetFromPLDictionary(DefaultLargeDisplayFont
, key
));
1441 WMReleasePropList(key
);
1444 array
= WMRetainPropList(
1445 WMGetFromPLDictionary(DefaultMenuTitleFont
, key
));
1446 WMReleasePropList(key
);
1449 array
= WMRetainPropList(
1450 WMGetFromPLDictionary(DefaultMenuTextFont
, key
));
1451 WMReleasePropList(key
);
1454 array
= WMRetainPropList(
1455 WMGetFromPLDictionary(DefaultClipTitleFont
, key
));
1456 WMReleasePropList(key
);
1459 array
= WMRetainPropList(
1460 WMGetFromPLDictionary(DefaultIconTitleFont
, key
));
1461 WMReleasePropList(key
);
1464 if(!WMIsPLArray(array
)) {
1472 getDefaultSystemFont(void *data
, int element
)
1474 _Panel
*panel
= (_Panel
*)data
;
1475 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1478 return WMBoldSystemFontOfSize(scr
, 12);
1481 return WMBoldSystemFontOfSize(scr
, 24);
1484 return WMBoldSystemFontOfSize(scr
, 12);
1487 return WMSystemFontOfSize(scr
, 12);
1490 return WMSystemFontOfSize(scr
, 8);
1493 return WMSystemFontOfSize(scr
, 8);
1499 multiClick(WMWidget
*w
, void *data
)
1501 _Panel
*panel
= (_Panel
*)data
;
1502 if(!panel
->MultiByteText
) {
1503 WMSetButtonText(panel
->togMulti
, _("Yes"));
1504 setLanguageType(panel
, True
);
1505 panel
->MultiByteText
= True
;
1507 WMSetButtonText(panel
->togMulti
, _("Auto"));
1508 if(isEncodingMultiByte(panel
)) setLanguageType(panel
, True
);
1509 else setLanguageType(panel
, False
);
1510 panel
->MultiByteText
= False
;
1515 toggleAA(WMWidget
*w
, void *data
)
1517 _Panel
*panel
= (_Panel
*)data
;
1519 if(panel
->AntialiasedText
)
1520 panel
->AntialiasedText
= False
;
1522 panel
->AntialiasedText
= True
;
1523 /* hmm now i gotta redraw all the fonts in the preview section
1524 * and the text field
1526 paintPreviewBox(panel
, EVERYTHING
);
1527 changePage(panel
->fontSel
, panel
);
1528 if(isEncodingMultiByte(panel
)) setLanguageType(panel
, True
);
1532 listClick(WMWidget
*w
, void *data
)
1534 _Panel
*panel
= (_Panel
*)data
;
1536 checkListForArrows(panel
);
1540 moveUpListItem(WMWidget
*w
, void *data
)
1542 _Panel
*panel
= (_Panel
*)data
;
1548 char *encoding
= getFontEncoding(panel
);
1549 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1552 array
= getCurrentFontProp(panel
, section
);
1554 array
= getDefaultFontProp(panel
, encoding
, section
);
1556 pos
= WMGetListSelectedItemRow(panel
->fsetLs
);
1558 tmp
= WMGetListItem(panel
->fsetLs
, pos
);
1559 listtext
= wstrdup(tmp
->text
);
1560 string
= WMCreatePLString(listtext
);
1562 WMRemoveListItem(panel
->fsetLs
, pos
);
1563 WMDeleteFromPLArray(array
, pos
);
1564 WMInsertListItem(panel
->fsetLs
, pos
-1, listtext
);
1565 WMInsertInPLArray(array
, pos
-1, string
);
1567 paintPreviewBox(panel
, EVERYTHING
);
1568 changePage(panel
->fontSel
, panel
);
1570 WMSelectListItem(panel
->fsetLs
, pos
-1);
1571 checkListForArrows(panel
);
1575 moveDownListItem(WMWidget
*w
, void *data
)
1577 _Panel
*panel
= (_Panel
*)data
;
1583 char *encoding
= getFontEncoding(panel
);
1584 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1587 array
= getCurrentFontProp(panel
, section
);
1589 array
= getDefaultFontProp(panel
, encoding
, section
);
1591 pos
= WMGetListSelectedItemRow(panel
->fsetLs
);
1593 tmp
= WMGetListItem(panel
->fsetLs
, pos
);
1594 listtext
= wstrdup(tmp
->text
);
1595 string
= WMCreatePLString(listtext
);
1596 WMRemoveListItem(panel
->fsetLs
, pos
);
1597 WMDeleteFromPLArray(array
, pos
);
1598 WMInsertListItem(panel
->fsetLs
, pos
+1, listtext
);
1599 WMInsertInPLArray(array
, pos
+1, string
);
1601 paintPreviewBox(panel
, EVERYTHING
);
1602 changePage(panel
->fontSel
, panel
);
1604 WMSelectListItem(panel
->fsetLs
, pos
+1);
1605 checkListForArrows(panel
);
1609 addButtonAction(WMWidget
*w
, void *data
)
1611 _Panel
*panel
= (_Panel
*)data
;
1616 char *encoding
= getFontEncoding(panel
);
1617 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1620 array
= getCurrentFontProp(panel
, section
);
1622 array
= getDefaultFontProp(panel
, encoding
, section
);
1624 WMHideFontPanel(panel
->fontPanel
);
1625 chosenFont
= WMGetFontPanelFontName(panel
->fontPanel
);
1626 string
= WMCreatePLString(chosenFont
);
1627 pos
= WMGetListSelectedItemRow(panel
->fsetLs
);
1628 WMInsertListItem(panel
->fsetLs
, pos
+1, chosenFont
);
1629 WMInsertInPLArray(array
, pos
+1, string
);
1630 WMSelectListItem(panel
->fsetLs
, pos
+1);
1632 paintPreviewBox(panel
, EVERYTHING
);
1633 changePage(panel
->fontSel
, panel
);
1637 changeButtonAction(WMWidget
*w
, void *data
)
1639 _Panel
*panel
= (_Panel
*)data
;
1644 char *encoding
= getFontEncoding(panel
);
1645 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1648 array
= getCurrentFontProp(panel
, section
);
1650 array
= getDefaultFontProp(panel
, encoding
, section
);
1652 WMHideFontPanel(panel
->fontPanel
);
1654 chosenFont
= WMGetFontPanelFontName(panel
->fontPanel
);
1655 string
= WMCreatePLString(chosenFont
);
1657 pos
= WMGetListSelectedItemRow(panel
->fsetLs
);
1658 WMRemoveListItem(panel
->fsetLs
, pos
);
1659 WMDeleteFromPLArray(array
, pos
);
1660 WMInsertListItem(panel
->fsetLs
, pos
, chosenFont
);
1661 WMInsertInPLArray(array
, pos
, string
);
1662 WMSelectListItem(panel
->fsetLs
, pos
);
1664 paintPreviewBox(panel
, EVERYTHING
);
1665 changePage(panel
->fontSel
, panel
);
1669 changeButtonClick(WMWidget
*w
, void *data
)
1671 _Panel
*panel
= (_Panel
*)data
;
1673 WMSetFontPanelAction(panel
->fontPanel
, changeButtonAction
, panel
);
1674 WMShowFontPanel(panel
->fontPanel
);
1678 addButtonClick(WMWidget
*w
, void *data
)
1680 _Panel
*panel
= (_Panel
*)data
;
1682 WMSetFontPanelAction(panel
->fontPanel
, addButtonAction
, panel
);
1683 WMShowFontPanel(panel
->fontPanel
);
1687 removeButtonClick(WMWidget
*w
, void *data
)
1689 _Panel
*panel
= (_Panel
*)data
;
1693 char *encoding
= getFontEncoding(panel
);
1694 int section
= WMGetPopUpButtonSelectedItem(panel
->fontSel
);
1697 array
= getCurrentFontProp(panel
, section
);
1699 array
= getDefaultFontProp(panel
, encoding
, section
);
1701 pos
= WMGetListSelectedItemRow(panel
->fsetLs
);
1702 WMRemoveListItem(panel
->fsetLs
, pos
);
1703 WMDeleteFromPLArray(array
, pos
);
1705 list
= WMGetListNumberOfRows(panel
->fsetLs
);
1708 WMSelectListItem(panel
->fsetLs
, pos
);
1709 else if(list
== pos
)
1710 WMSelectListItem(panel
->fsetLs
, list
-1);
1712 WMSelectListItem(panel
->fsetLs
, 0);
1714 checkListForArrows(panel
);
1716 paintPreviewBox(panel
, EVERYTHING
);
1717 changePage(panel
->fontSel
, panel
);
1721 showData(_Panel
*panel
)
1723 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1727 CurrentFontArray
= WMCreatePLDictionary(NULL
, NULL
);
1729 str
= GetStringForKey("WindowTitleFont");
1730 insertCurrentFont(wstrdup(str
), "WindowTitleFont");
1732 str
= GetStringForKey("LargeDisplayFont");
1733 insertCurrentFont(wstrdup(str
), "LargeDisplayFont");
1735 str
= GetStringForKey("MenuTitleFont");
1736 insertCurrentFont(wstrdup(str
), "MenuTitleFont");
1738 str
= GetStringForKey("MenuTextFont");
1739 insertCurrentFont(wstrdup(str
), "MenuTextFont");
1741 str
= GetStringForKey("ClipTitleFont");
1742 insertCurrentFont(wstrdup(str
), "ClipTitleFont");
1744 str
= GetStringForKey("IconTitleFont");
1745 insertCurrentFont(wstrdup(str
), "IconTitleFont");
1747 /* i put this here cause it needs to be known before we paint */
1748 readFontEncodings(panel
);
1750 str
= GetStringForKey("MenuStyle");
1751 if (str
&& strcasecmp(str
, "flat")==0) {
1752 panel
->menuStyle
= MSTYLE_FLAT
;
1753 } else if (str
&& strcasecmp(str
, "singletexture")==0) {
1754 panel
->menuStyle
= MSTYLE_SINGLE
;
1756 panel
->menuStyle
= MSTYLE_NORMAL
;
1759 str
= GetStringForKey("TitleJustify");
1760 if (str
&& strcasecmp(str
, "left")==0) {
1761 panel
->titleAlignment
= WALeft
;
1762 } else if (str
&& strcasecmp(str
, "right")==0) {
1763 panel
->titleAlignment
= WARight
;
1765 panel
->titleAlignment
= WACenter
;
1767 for (i
= 0; i
< sizeof(colorOptions
)/(2*sizeof(char*)); i
++) {
1770 str
= GetStringForKey(colorOptions
[i
*2]);
1772 str
= colorOptions
[i
*2+1];
1774 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), str
, False
))) {
1775 color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), "#000000", False
);
1777 panel
->colors
[i
] = color
;
1780 str
= GetStringForKey("MultiByteText");
1783 if (strcasecmp(str
, "YES")==0) {
1784 setLanguageType(panel
, True
);
1785 WMSetButtonText(panel
->togMulti
, "Yes");
1786 printf("yes multi\n");
1787 panel
->MultiByteText
= True
;
1788 } else if (strcasecmp(str
, "AUTO") == 0) {
1790 locale
= setlocale(LC_CTYPE
, NULL
);
1792 && (strncmp(locale
, "ja", 2) == 0
1793 || strncmp(locale
, "zh", 2) == 0
1794 || strncmp(locale
, "ko", 2) == 0)) {
1795 setLanguageType(panel
, True
);
1796 WMSetButtonText(panel
->togMulti
, "Auto");
1797 printf("auto multi\n");
1798 panel
->MultiByteText
= True
;
1800 setLanguageType(panel
, False
);
1801 WMSetButtonText(panel
->togMulti
, "Auto");
1802 panel
->MultiByteText
= False
;
1807 locale
= setlocale(LC_CTYPE
, NULL
);
1809 && (strncmp(locale
, "ja", 2) == 0
1810 || strncmp(locale
, "zh", 2) == 0
1811 || strncmp(locale
, "ko", 2) == 0)) {
1812 setLanguageType(panel
, True
);
1813 WMSetButtonText(panel
->togMulti
, "Auto");
1814 printf("auto multi\n");
1815 panel
->MultiByteText
= True
;
1817 setLanguageType(panel
, False
);
1818 WMSetButtonText(panel
->togMulti
, "Auto");
1819 panel
->MultiByteText
= False
;
1822 /* gotta check for Antialiasing AFTER MultiByte incase the use has both
1823 * to maintain behavior in Current Fonts set or i could add another if
1824 * statement to setLanguageType =) */
1825 if (WMHasAntialiasingSupport(scr
))
1827 WMMapWidget(panel
->togAA
);
1828 if(GetBoolForKey("AntialiasedText")){
1829 WMSetButtonSelected(panel
->togAA
, True
);
1830 panel
->AntialiasedText
= True
;
1832 WMSetButtonSelected(panel
->togAA
, False
);
1833 panel
->AntialiasedText
= False
;
1836 WMUnmapWidget(panel
->togAA
);
1840 paintPreviewBox(panel
, EVERYTHING
);
1844 createPanel(Panel
*p
)
1846 _Panel
*panel
= (_Panel
*)p
;
1847 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1850 panel
->box
= WMCreateBox(panel
->parent
);
1851 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
1853 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1854 panel
->up_arrow
= WMCreatePixmapFromXPMData(scr
, up_arrow_xpm
);
1855 panel
->down_arrow
= WMCreatePixmapFromXPMData(scr
, down_arrow_xpm
);
1856 panel
->alt_up_arrow
= WMCreatePixmapFromXPMData(scr
, alt_up_arrow_xpm
);
1857 panel
->alt_down_arrow
= WMCreatePixmapFromXPMData(scr
, alt_down_arrow_xpm
);
1859 panel
->prevL
= WMCreateLabel(panel
->box
);
1860 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 45);
1861 WMMoveWidget(panel
->prevL
, 15, 35);
1862 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1863 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1865 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1866 previewClick
, panel
);
1868 /* Widget Selection */
1869 panel
->fontSel
= WMCreatePopUpButton(panel
->box
);
1870 WMResizeWidget(panel
->fontSel
, 135, 20);
1871 WMMoveWidget(panel
->fontSel
, 15, 10);
1872 WMAddPopUpButtonItem(panel
->fontSel
, _("Window Title Font"));
1873 WMAddPopUpButtonItem(panel
->fontSel
, _("Large Display Font"));
1874 WMAddPopUpButtonItem(panel
->fontSel
, _("Menu Title Font"));
1875 WMAddPopUpButtonItem(panel
->fontSel
, _("Menu Item Font" ));
1876 WMAddPopUpButtonItem(panel
->fontSel
, _("Clip Title Font"));
1877 WMAddPopUpButtonItem(panel
->fontSel
, _("Icon Title Font"));
1879 WMSetPopUpButtonSelectedItem(panel
->fontSel
, 0);
1881 WMSetPopUpButtonAction(panel
->fontSel
, changePage
, panel
);
1883 /* MultiByteText toggle */
1884 panel
->multiF
= WMCreateFrame(panel
->box
);
1885 WMResizeWidget(panel
->multiF
, 70, 50);
1886 WMMoveWidget(panel
->multiF
, 440, 10);
1887 WMSetFrameTitle(panel
->multiF
, _("MultiByte"));
1890 panel
->togMulti
= WMCreateCommandButton(panel
->multiF
);
1891 WMResizeWidget(panel
->togMulti
, 40, 20);
1892 WMMoveWidget(panel
->togMulti
, 15, 20);
1893 WMSetButtonAction(panel
->togMulti
, multiClick
, panel
);
1895 WMMapSubwidgets(panel
->multiF
);
1897 /* language selection */
1898 panel
->langF
= WMCreateFrame(panel
->box
);
1899 WMResizeWidget(panel
->langF
, 165, 50);
1900 WMMoveWidget(panel
->langF
, 265, 10);
1901 WMSetFrameTitle(panel
->langF
, _("Default Font Encodings"));
1903 panel
->langP
= WMCreatePopUpButton(panel
->langF
);
1904 WMResizeWidget(panel
->langP
, 135, 20);
1905 WMMoveWidget(panel
->langP
, 15, 20);
1907 WMSetPopUpButtonAction(panel
->langP
, changeLanguageAction
, panel
);
1909 WMMapSubwidgets(panel
->langF
);
1912 if (WMHasAntialiasingSupport(scr
))
1914 panel
->togAA
= WMCreateSwitchButton(panel
->box
);
1915 WMResizeWidget(panel
->togAA
, 110, 20);
1916 WMMoveWidget(panel
->togAA
, 155, 10);
1917 WMSetButtonText(panel
->togAA
, _("Smooth Fonts"));
1918 WMSetBalloonTextForView(_("Smooth Font edges for the eye candy\n"
1919 "requires a restart after saving"),
1920 WMWidgetView(panel
->togAA
));
1921 WMSetButtonAction(panel
->togAA
, toggleAA
, panel
);
1924 panel
->fsetL
= WMCreateLabel(panel
->box
);
1925 WMResizeWidget(panel
->fsetL
, 245, 20);
1926 WMMoveWidget(panel
->fsetL
, 265, 70);
1927 WMSetLabelText(panel
->fsetL
, _("Font Set"));
1928 WMSetLabelRelief(panel
->fsetL
, WRSunken
);
1929 WMSetLabelTextAlignment(panel
->fsetL
, WACenter
);
1934 color
= WMDarkGrayColor(scr
);
1935 font
= WMBoldSystemFontOfSize(scr
, 12);
1937 WMSetWidgetBackgroundColor(panel
->fsetL
, color
);
1938 WMSetLabelFont(panel
->fsetL
, font
);
1940 WMReleaseFont(font
);
1941 WMReleaseColor(color
);
1943 color
= WMWhiteColor(scr
);
1944 WMSetLabelTextColor(panel
->fsetL
, color
);
1945 WMReleaseColor(color
);
1948 panel
->fsetLs
= WMCreateList(panel
->box
);
1949 WMResizeWidget(panel
->fsetLs
, 245, 86);
1950 WMMoveWidget(panel
->fsetLs
, 265, 92);
1951 WMSetListAction(panel
->fsetLs
, listClick
, panel
);
1952 WMSetListDoubleAction(panel
->fsetLs
, changeButtonClick
, panel
);
1954 panel
->addB
= WMCreateCommandButton(panel
->box
);
1955 WMResizeWidget(panel
->addB
, 78, 24);
1956 WMMoveWidget(panel
->addB
, 265, 201);
1957 WMSetButtonText(panel
->addB
, _("Add..."));
1958 WMSetButtonAction(panel
->addB
, addButtonClick
, panel
);
1960 panel
->editB
= WMCreateCommandButton(panel
->box
);
1961 WMResizeWidget(panel
->editB
, 78, 24);
1962 WMMoveWidget(panel
->editB
, 348, 201);
1963 WMSetButtonText(panel
->editB
, _("Change..."));
1964 WMSetButtonAction(panel
->editB
, changeButtonClick
, panel
);
1966 panel
->remB
= WMCreateCommandButton(panel
->box
);
1967 WMResizeWidget(panel
->remB
, 78, 24);
1968 WMMoveWidget(panel
->remB
, 431, 201);
1969 WMSetButtonText(panel
->remB
, _("Remove"));
1970 WMSetButtonAction(panel
->remB
, removeButtonClick
, panel
);
1972 /* happy Up/Down buttons */
1973 panel
->upB
= WMCreateCommandButton(panel
->box
);
1974 WMResizeWidget(panel
->upB
, 16, 16);
1975 WMMoveWidget(panel
->upB
, 265, 182);
1976 WMSetButtonImage(panel
->upB
, panel
->up_arrow
);
1977 WMSetButtonAltImage(panel
->upB
, panel
->alt_up_arrow
);
1978 WMSetButtonImagePosition(panel
->upB
, WIPImageOnly
);
1979 WMSetButtonImageDimsWhenDisabled(panel
->upB
, True
);
1980 WMSetButtonAction(panel
->upB
, moveUpListItem
, panel
);
1982 panel
->downB
= WMCreateCommandButton(panel
->box
);
1983 WMResizeWidget(panel
->downB
, 16, 16);
1984 WMMoveWidget(panel
->downB
, 286, 182);
1985 WMSetButtonImage(panel
->downB
, panel
->down_arrow
);
1986 WMSetButtonAltImage(panel
->downB
, panel
->alt_down_arrow
);
1987 WMSetButtonImagePosition(panel
->downB
, WIPImageOnly
);
1988 WMSetButtonImageDimsWhenDisabled(panel
->downB
, True
);
1989 WMSetButtonAction(panel
->downB
, moveDownListItem
, panel
);
1992 panel
->fontT
= WMCreateTextField(panel
->box
);
1993 WMResizeWidget(panel
->fontT
, 245, 30);
1994 WMMoveWidget(panel
->fontT
, 265, 120);
1996 panel
->changeB
= WMCreateCommandButton(panel
->box
);
1997 WMResizeWidget(panel
->changeB
, 104, 24);
1998 WMMoveWidget(panel
->changeB
, 335, 160);
1999 WMSetButtonText(panel
->changeB
, _("Change..."));
2000 WMSetButtonAction(panel
->changeB
, changeButtonClick
, panel
);
2003 panel
->black
= WMBlackColor(scr
);
2004 panel
->white
= WMWhiteColor(scr
);
2005 panel
->light
= WMGrayColor(scr
);
2006 panel
->dark
= WMDarkGrayColor(scr
);
2007 panel
->back
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
2009 /* Font Panel !!!!! */
2010 panel
->fontPanel
= WMGetFontPanel(scr
);
2013 for (i
= 0; Languages
[i
].language
!= NULL
; i
++) {
2014 WMAddPopUpButtonItem(panel
->langP
, Languages
[i
].language
);
2017 for (i
= 0; Options
[i
].description
!= NULL
; i
++) {
2018 WMAddListItem(panel
->settingLs
, Options
[i
].description
);
2021 WMRealizeWidget(panel
->box
);
2022 WMMapSubwidgets(panel
->box
);
2025 changePage(panel
->fontSel
, panel
);
2031 _Panel
*panel
= (_Panel
*)p
;
2034 char *encoding
= getFontEncoding(panel
);
2040 SetStringForKey(fontOfLang(panel
, encoding
, i
),
2044 SetStringForKey(fontOfLang(panel
, encoding
, i
),
2045 "LargeDisplayFont");
2048 SetStringForKey(fontOfLang(panel
, encoding
, i
),
2052 SetStringForKey(fontOfLang(panel
, encoding
, i
),
2056 SetStringForKey(fontOfLang(panel
, encoding
, i
),
2060 SetStringForKey(fontOfLang(panel
, encoding
, i
),
2066 if (WMHasAntialiasingSupport(WMWidgetScreen(panel
->box
)))
2067 SetBoolForKey(WMGetButtonSelected(panel
->togAA
), "AntialiasedText");
2069 if(panel
->MultiByteText
)
2070 SetStringForKey("YES", "MultiByteText");
2072 if(isEncodingMultiByte(panel
)) SetStringForKey("YES", "MultiByteText");
2073 else SetStringForKey("AUTO", "MultiByteText");
2078 prepClosure(Panel
*p
)
2080 _Panel
*panel
= (_Panel
*)p
;
2081 WMFreeFontPanel(panel
->fontPanel
);
2082 WMReleasePropList(CurrentFontArray
);
2083 /* and what ever else i've forgotten or overlooked
2084 * maybe someone will add them */
2088 InitFont(WMScreen
*scr
, WMWidget
*parent
)
2092 panel
= wmalloc(sizeof(_Panel
));
2093 memset(panel
, 0, sizeof(_Panel
));
2095 panel
->sectionName
= _("Font Preferences");
2096 panel
->description
= _("Font Configurations for Windows, Menus etc");
2098 panel
->parent
= parent
;
2100 panel
->callbacks
.createWidgets
= createPanel
;
2101 panel
->callbacks
.updateDomain
= storeData
;
2102 panel
->callbacks
.prepareForClose
= prepClosure
;
2104 AddSection(panel
, ICON_FILE
);