WPrefs: grouped items related to the window title alignment in a single place
[wmaker-crm.git] / WPrefs.app / Appearance.c
blob86525f72788b0cc603c47649ad2da59099e034aa
1 /* Apperance.c- color/texture for titlebar etc.
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "WPrefs.h"
24 #include <unistd.h>
25 #include <errno.h>
26 #include <ctype.h>
27 #include <time.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 #include <fcntl.h>
32 #include "TexturePanel.h"
35 static const struct {
36 const char *key;
37 const char *default_value;
38 const char *label;
39 WMRect preview; /* The rectangle where the corresponding object is displayed */
40 WMPoint hand; /* The coordinate where the hand is drawn when pointing this item */
41 } colorOptions[] = {
42 /* Related to Window titles */
43 { "FTitleColor", "white", N_("Focused Window Title"),
44 { { 30, 10 }, { 190, 20 } }, { 5, 10 } },
45 { "UTitleColor", "black", N_("Unfocused Window Title"),
46 { { 30, 40 }, { 190, 20 } }, { 5, 40 } },
47 { "PTitleColor", "white", N_("Owner of Focused Window Title"),
48 { { 30, 70 }, { 190, 20 } }, { 5, 70 } },
50 /* Related to Menus */
51 { "MenuTitleColor", "white", N_("Menu Title") ,
52 { { 30, 120 }, { 90, 20 } }, { 5, 120 } },
53 { "MenuTextColor", "black", N_("Menu Item Text") ,
54 { { 30, 140 }, { 90, 20 } }, { 5, 140 } },
55 { "MenuDisabledColor", "#616161", N_("Disabled Menu Item Text") ,
56 { { 30, 160 }, { 90, 20 } }, { 5, 160 } },
57 { "HighlightColor", "white", N_("Menu Highlight Color") ,
58 { { 30, 180 }, { 90, 20 } }, { 5, 180 } },
59 { "HighlightTextColor", "black", N_("Highlighted Menu Text Color") ,
60 { { 30, 200 }, { 90, 20 } }, { 5, 180 } },
62 * yuck kluge: the coordinate for HighlightTextColor are actually those of the last "Normal item"
63 * at the bottom when user clicks it, the "yuck kluge" in the function 'previewClick' will swap it
64 * for the MenuTextColor selection as user would expect
66 * Note that the entries are reffered by their index for performance
69 /* Related to Window's border */
70 { "FrameFocusedBorderColor", "black", N_("Focused Window Border Color") ,
71 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
72 { "FrameBorderColor", "black", N_("Window Border Color") ,
73 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
74 { "FrameSelectedBorderColor", "white", N_("Selected Window Border Color") ,
75 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
77 /* Related to Icons and Clip */
78 { "IconTitleColor", "white", N_("Miniwindow Title") ,
79 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
80 { "IconTitleBack", "black", N_("Miniwindow Title Back") ,
81 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
82 { "ClipTitleColor", "black", N_("Clip Title") ,
83 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
84 { "CClipTitleColor", "#454045", N_("Collapsed Clip Title") ,
85 { { 155, 130 }, { 64, 64 } }, { 130, 132 } }
88 /********************************************************************/
89 typedef enum {
90 MSTYLE_NORMAL = 0,
91 MSTYLE_SINGLE = 1,
92 MSTYLE_FLAT = 2
93 } menu_style_index;
95 static const struct {
96 const char *db_value;
97 const char *file_name;
98 } menu_style[] = {
99 [MSTYLE_NORMAL] { "normal", "msty1" },
100 [MSTYLE_SINGLE] { "singletexture", "msty2" },
101 [MSTYLE_FLAT] { "flat", "msty3" }
104 /********************************************************************/
105 static const struct {
106 const char *label;
107 const char *db_value;
108 } wintitle_align[] = {
109 [WALeft] { N_("Left"), "left" },
110 [WACenter] { N_("Center"), "center" },
111 [WARight] { N_("Right"), "right" }
114 /********************************************************************/
115 typedef struct _Panel {
116 WMBox *box;
117 char *sectionName;
119 char *description;
121 CallbackRec callbacks;
123 WMWidget *parent;
125 WMLabel *prevL;
127 WMTabView *tabv;
129 /* texture list */
130 WMFrame *texF;
131 WMList *texLs;
133 WMPopUpButton *secP;
135 WMButton *newB;
136 WMButton *editB;
137 WMButton *ripB;
138 WMButton *delB;
140 /* text color */
141 WMFrame *colF;
143 WMPopUpButton *colP;
144 WMColor *colors[wlengthof_nocheck(colorOptions)];
146 WMColorWell *colW;
148 WMColorWell *sampW[24];
150 /* options */
151 WMFrame *optF;
153 WMFrame *mstyF;
154 WMButton *mstyB[wlengthof_nocheck(menu_style)];
156 WMFrame *taliF;
157 WMButton *taliB[wlengthof_nocheck(wintitle_align)];
159 /* */
161 int textureIndex[8];
163 WMFont *smallFont;
164 WMFont *normalFont;
165 WMFont *boldFont;
167 TexturePanel *texturePanel;
169 WMPixmap *onLed;
170 WMPixmap *offLed;
171 WMPixmap *hand;
173 int oldsection;
174 int oldcsection;
176 char oldTabItem;
178 menu_style_index menuStyle;
180 WMAlignment titleAlignment;
182 Pixmap preview;
183 Pixmap previewNoText;
184 Pixmap previewBack;
186 char *fprefix;
187 } _Panel;
189 typedef struct {
190 char *title;
191 char *texture;
192 WMPropList *prop;
193 Pixmap preview;
195 char *path;
197 char selectedFor;
198 unsigned current:1;
199 unsigned ispixmap:1;
200 } TextureListItem;
202 enum {
203 TAB_TEXTURE,
204 TAB_COLOR,
205 TAB_OPTIONS
208 static void updateColorPreviewBox(_Panel * panel, int elements);
210 static void showData(_Panel * panel);
212 static void changePage(WMWidget * w, void *data);
214 static void changeColorPage(WMWidget * w, void *data);
216 static void OpenExtractPanelFor(_Panel *panel);
218 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item);
220 static WMTabViewDelegate tabviewDelegate = {
221 NULL,
222 NULL, /* didChangeNumberOfItems */
223 changedTabItem, /* didSelectItem */
224 NULL, /* shouldSelectItem */
225 NULL /* willSelectItem */
228 #define ICON_FILE "appearance"
230 #define TNEW_FILE "tnew"
231 #define TDEL_FILE "tdel"
232 #define TEDIT_FILE "tedit"
233 #define TEXTR_FILE "textr"
235 /* XPM */
236 static char *blueled_xpm[] = {
237 "8 8 17 1",
238 " c None",
239 ". c #020204",
240 "+ c #16B6FC",
241 "@ c #176AFC",
242 "# c #163AFC",
243 "$ c #72D2FC",
244 "% c #224CF4",
245 "& c #76D6FC",
246 "* c #16AAFC",
247 "= c #CEE9FC",
248 "- c #229EFC",
249 "; c #164CFC",
250 "> c #FAFEFC",
251 ", c #2482FC",
252 "' c #1652FC",
253 ") c #1E76FC",
254 "! c #1A60FC",
255 " .... ",
256 " .=>-@. ",
257 ".=>$@@'.",
258 ".=$@!;;.",
259 ".!@*+!#.",
260 ".#'*+*,.",
261 " .@)@,. ",
262 " .... "
265 /* XPM */
266 static char *blueled2_xpm[] = {
267 /* width height num_colors chars_per_pixel */
268 " 8 8 17 1",
269 /* colors */
270 ". c None",
271 "# c #090909",
272 "a c #4b63a4",
273 "b c #011578",
274 "c c #264194",
275 "d c #04338c",
276 "e c #989dac",
277 "f c #011a7c",
278 "g c #465c9c",
279 "h c #03278a",
280 "i c #6175ac",
281 "j c #011e74",
282 "k c #043a90",
283 "l c #042f94",
284 "m c #0933a4",
285 "n c #022184",
286 "o c #012998",
287 /* pixels */
288 "..####..",
289 ".#aimn#.",
290 "#aechnf#",
291 "#gchnjf#",
292 "#jndknb#",
293 "#bjdddl#",
294 ".#nono#.",
295 "..####.."
298 /* XPM */
299 static char *hand_xpm[] = {
300 "22 21 19 1",
301 " c None",
302 ". c #030305",
303 "+ c #7F7F7E",
304 "@ c #B5B5B6",
305 "# c #C5C5C6",
306 "$ c #969697",
307 "% c #FDFDFB",
308 "& c #F2F2F4",
309 "* c #E5E5E4",
310 "= c #ECECEC",
311 "- c #DCDCDC",
312 "; c #D2D2D0",
313 "> c #101010",
314 ", c #767674",
315 "' c #676767",
316 ") c #535355",
317 "! c #323234",
318 "~ c #3E3C56",
319 "{ c #333147",
320 " ",
321 " ..... ",
322 " ..+@##$. ",
323 " .%%%&@.......... ",
324 " .%*%%&#%%%%%%%%%$. ",
325 " .*#%%%%%%%%%&&&&==. ",
326 " .-%%%%%%%%%=*-;;;#$. ",
327 " .-%%%%%%%%&..>..... ",
328 " >-%%%%%%%%%*#+. ",
329 " >-%%%%%%%%%*@,. ",
330 " >#%%%%%%%%%*@'. ",
331 " >$&&%%%%%%=... ",
332 " .+@@;=&%%&;$,> ",
333 " .',$@####$+). ",
334 " .!',+$++,'. ",
335 " ..>>>>>. ",
336 " ",
337 " ~~{{{~~ ",
338 " {{{{{{{{{{{ ",
339 " ~~{{{~~ ",
343 static char *sampleColors[] = {
344 "black",
345 "#292929",
346 "#525252",
347 "#848484",
348 "#adadad",
349 "#d6d6d6",
350 "white",
351 "#d6d68c",
352 "#d6a57b",
353 "#8cd68c",
354 "#8cd6ce",
355 "#d68c8c",
356 "#8c9cd6",
357 "#bd86d6",
358 "#d68cbd",
359 "#d64a4a",
360 "#4a5ad6",
361 "#4ad6ce",
362 "#4ad65a",
363 "#ced64a",
364 "#d6844a",
365 "#8ad631",
366 "#ce29c6",
367 "#ce2973",
368 "black"
371 static const struct {
372 const char *key;
373 const char *default_value;
374 const char *texture_label; /* text used when displaying the list of textures */
375 WMRect preview; /* The rectangle where the corresponding object is displayed */
376 WMPoint hand; /* The coordinate where the hand is drawn when pointing this item */
377 const char *popup_label; /* text used for the popup button with the list of editable items */
378 } textureOptions[] = {
380 #define PFOCUSED 0
381 { "FTitleBack", "(solid, black)", N_("[Focused]"),
382 { { 30, 10 }, { 190, 20 } }, { 5, 10 }, N_("Titlebar of Focused Window") },
384 #define PUNFOCUSED 1
385 { "UTitleBack", "(solid, gray)", N_("[Unfocused]"),
386 { { 30, 40 }, { 190, 20 } }, { 5, 40 }, N_("Titlebar of Unfocused Windows") },
388 #define POWNER 2
389 { "PTitleBack", "(solid, \"#616161\")", N_("[Owner of Focused]"),
390 { { 30, 70 }, { 190, 20 } }, { 5, 70 }, N_("Titlebar of Focused Window's Owner") },
392 #define PRESIZEBAR 3
393 { "ResizebarBack", "(solid, gray)", N_("[Resizebar]"),
394 { { 30, 100 }, { 190, 9 } }, { 5, 100 }, N_("Window Resizebar") },
396 #define PMTITLE 4
397 { "MenuTitleBack", "(solid, black)", N_("[Menu Title]"),
398 { { 30, 120 }, { 90, 20 } }, { 5, 120 }, N_("Titlebar of Menus") },
400 #define PMITEM 5
401 { "MenuTextBack", "(solid, gray)", N_("[Menu Item]"),
402 { { 30, 140 }, { 90, 20 * 4 } }, { 5, 160 }, N_("Menu Items") },
404 #define PICON 6
405 { "IconBack", "(solid, gray)", N_("[Icon]"),
406 { { 155, 130 }, { 64, 64 } }, { 130, 150 }, N_("Icon Background") },
408 #define PBACKGROUND 7
409 { "WorkspaceBack", "(solid, black)", N_("[Background]"),
410 { { -1, -1}, { 0, 0 } }, { -22, -21 }, N_("Workspace Background") }
412 #define EVERYTHING 0xff
415 enum {
416 RESIZEBAR_BEVEL = -1,
417 MENU_BEVEL = -2
420 enum {
421 TEXPREV_WIDTH = 40,
422 TEXPREV_HEIGHT = 24
425 enum {
426 FTITLE_COL,
427 UTITLE_COL,
428 OTITLE_COL,
429 MTITLE_COL,
430 MITEM_COL,
431 MDISAB_COL,
432 MHIGH_COL,
433 MHIGHT_COL,
434 FFBORDER_COL,
435 FBORDER_COL,
436 FSBORDER_COL,
437 ICONT_COL,
438 ICONB_COL,
439 CLIP_COL,
440 CCLIP_COL
444 static void str2rcolor(RContext * rc, const char *name, RColor * color)
446 XColor xcolor;
448 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
450 color->alpha = 255;
451 color->red = xcolor.red >> 8;
452 color->green = xcolor.green >> 8;
453 color->blue = xcolor.blue >> 8;
456 static void dumpRImage(const char *path, RImage * image)
458 FILE *f;
459 int channels = (image->format == RRGBAFormat ? 4 : 3);
461 f = fopen(path, "wb");
462 if (!f) {
463 werror("%s", path);
464 return;
466 fprintf(f, "%02x%02x%1x", image->width, image->height, channels);
468 fwrite(image->data, 1, image->width * image->height * channels, f);
470 fsync(fileno(f));
471 if (fclose(f) < 0) {
472 werror("%s", path);
476 static int isPixmap(WMPropList * prop)
478 WMPropList *p;
479 char *s;
481 p = WMGetFromPLArray(prop, 0);
482 s = WMGetFromPLString(p);
483 if (strcasecmp(&s[1], "pixmap") == 0)
484 return 1;
485 else
486 return 0;
489 /**********************************************************************/
491 static void drawResizebarBevel(RImage * img)
493 RColor light;
494 RColor dark;
495 int width = img->width;
496 int height = img->height;
497 int cwidth = 28;
499 light.alpha = 0;
500 light.red = light.green = light.blue = 80;
502 dark.alpha = 0;
503 dark.red = dark.green = dark.blue = 40;
505 ROperateLine(img, RSubtractOperation, 0, 0, width - 1, 0, &dark);
506 ROperateLine(img, RAddOperation, 0, 1, width - 1, 1, &light);
508 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height - 1, &dark);
509 ROperateLine(img, RAddOperation, cwidth + 1, 2, cwidth + 1, height - 1, &light);
511 ROperateLine(img, RSubtractOperation, width - cwidth - 2, 2, width - cwidth - 2, height - 1, &dark);
512 ROperateLine(img, RAddOperation, width - cwidth - 1, 2, width - cwidth - 1, height - 1, &light);
516 static void drawMenuBevel(RImage * img)
518 RColor light, dark, mid;
519 int i;
520 int iheight = img->height / 4;
522 light.alpha = 0;
523 light.red = light.green = light.blue = 80;
525 dark.alpha = 255;
526 dark.red = dark.green = dark.blue = 0;
528 mid.alpha = 0;
529 mid.red = mid.green = mid.blue = 40;
531 for (i = 1; i < 4; i++) {
532 ROperateLine(img, RSubtractOperation, 0, i * iheight - 2, img->width - 1, i * iheight - 2, &mid);
534 RDrawLine(img, 0, i * iheight - 1, img->width - 1, i * iheight - 1, &dark);
536 ROperateLine(img, RAddOperation, 1, i * iheight, img->width - 2, i * iheight, &light);
540 static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int height, const char *path, int border)
542 char *type;
543 RImage *image = NULL;
544 RImage *timage = NULL;
545 Pixmap pixmap;
546 RContext *rc = WMScreenRContext(scr);
547 char *str;
548 RColor rcolor;
550 type = WMGetFromPLString(WMGetFromPLArray(texture, 0));
552 if (strcasecmp(&type[1], "pixmap") == 0 ||
553 (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T')) {
554 char *path;
556 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
557 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
558 if (path) {
559 timage = RLoadImage(rc, path, 0);
560 if (!timage)
561 wwarning("could not load file '%s': %s", path, RMessageForError(RErrorCode));
562 wfree(path);
563 } else {
564 wwarning("could not find file '%s' for %s of texture", str, type);
565 timage = NULL;
567 if (!timage) {
568 texture = WMCreatePropListFromDescription("(solid, black)");
569 type = "solid";
573 if (strcasecmp(type, "solid") == 0) {
575 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
577 str2rcolor(rc, str, &rcolor);
579 image = RCreateImage(width, height, False);
580 RClearImage(image, &rcolor);
581 } else if (strcasecmp(type, "igradient") == 0) {
582 int t1, t2;
583 RColor c1[2], c2[2];
585 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
586 str2rcolor(rc, str, &c1[0]);
587 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
588 str2rcolor(rc, str, &c1[1]);
589 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
590 t1 = atoi(str);
592 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
593 str2rcolor(rc, str, &c2[0]);
594 str = WMGetFromPLString(WMGetFromPLArray(texture, 5));
595 str2rcolor(rc, str, &c2[1]);
596 str = WMGetFromPLString(WMGetFromPLArray(texture, 6));
597 t2 = atoi(str);
599 image = RRenderInterwovenGradient(width, height, c1, t1, c2, t2);
600 } else if (strcasecmp(&type[1], "gradient") == 0) {
601 RGradientStyle style;
602 RColor rcolor2;
604 switch (toupper(type[0])) {
605 case 'V':
606 style = RVerticalGradient;
607 break;
608 case 'H':
609 style = RHorizontalGradient;
610 break;
611 default:
612 wwarning("unknow direction in '%s', falling back to diagonal", type);
613 case 'D':
614 style = RDiagonalGradient;
615 break;
618 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
619 str2rcolor(rc, str, &rcolor);
620 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
621 str2rcolor(rc, str, &rcolor2);
623 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
624 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T') {
625 RGradientStyle style;
626 RColor rcolor2;
627 int i;
628 RImage *grad = NULL;
630 switch (toupper(type[1])) {
631 case 'V':
632 style = RVerticalGradient;
633 break;
634 case 'H':
635 style = RHorizontalGradient;
636 break;
637 default:
638 wwarning("unknow direction in '%s', falling back to diagonal", type);
639 case 'D':
640 style = RDiagonalGradient;
641 break;
644 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
645 str2rcolor(rc, str, &rcolor);
646 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
647 str2rcolor(rc, str, &rcolor2);
649 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
651 image = RMakeTiledImage(timage, width, height);
652 RReleaseImage(timage);
654 i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
656 RCombineImagesWithOpaqueness(image, grad, i);
657 RReleaseImage(grad);
659 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'M') {
660 RGradientStyle style;
661 RColor **colors;
662 int i, j;
664 switch (toupper(type[1])) {
665 case 'V':
666 style = RVerticalGradient;
667 break;
668 case 'H':
669 style = RHorizontalGradient;
670 break;
671 default:
672 wwarning("unknow direction in '%s', falling back to diagonal", type);
673 case 'D':
674 style = RDiagonalGradient;
675 break;
678 j = WMGetPropListItemCount(texture);
680 if (j > 0) {
681 colors = wmalloc(j * sizeof(RColor *));
683 for (i = 2; i < j; i++) {
684 str = WMGetFromPLString(WMGetFromPLArray(texture, i));
685 colors[i - 2] = wmalloc(sizeof(RColor));
686 str2rcolor(rc, str, colors[i - 2]);
688 colors[i - 2] = NULL;
690 image = RRenderMultiGradient(width, height, colors, style);
692 for (i = 0; colors[i] != NULL; i++)
693 wfree(colors[i]);
694 wfree(colors);
696 } else if (strcasecmp(&type[1], "pixmap") == 0) {
697 RColor color;
699 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
700 str2rcolor(rc, str, &color);
702 switch (toupper(type[0])) {
703 case 'T':
704 image = RMakeTiledImage(timage, width, height);
705 RReleaseImage(timage);
706 break;
707 case 'C':
708 image = RMakeCenteredImage(timage, width, height, &color);
709 RReleaseImage(timage);
710 break;
711 case 'F':
712 case 'S':
713 case 'M':
714 image = RScaleImage(timage, width, height);
715 RReleaseImage(timage);
716 break;
718 default:
719 wwarning("type '%s' in not a supported type for a texture", type);
720 RReleaseImage(timage);
721 return None;
725 if (!image)
726 return None;
728 if (path) {
729 dumpRImage(path, image);
732 if (border < 0) {
733 if (border == RESIZEBAR_BEVEL) {
734 drawResizebarBevel(image);
735 } else if (border == MENU_BEVEL) {
736 drawMenuBevel(image);
737 RBevelImage(image, RBEV_RAISED2);
739 } else if (border) {
740 RBevelImage(image, border);
743 RConvertImage(rc, image, &pixmap);
744 RReleaseImage(image);
746 return pixmap;
749 static Pixmap renderMenu(_Panel * panel, WMPropList * texture, int width, int iheight)
751 WMScreen *scr = WMWidgetScreen(panel->parent);
752 Display *dpy = WMScreenDisplay(scr);
753 Pixmap pix, tmp;
754 GC gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
755 int i;
757 switch (panel->menuStyle) {
758 case MSTYLE_NORMAL:
759 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
761 pix = XCreatePixmap(dpy, tmp, width, iheight * 4, WMScreenDepth(scr));
762 for (i = 0; i < 4; i++) {
763 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight * i);
765 XFreePixmap(dpy, tmp);
766 break;
767 case MSTYLE_SINGLE:
768 pix = renderTexture(scr, texture, width, iheight * 4, NULL, MENU_BEVEL);
769 break;
770 case MSTYLE_FLAT:
771 pix = renderTexture(scr, texture, width, iheight * 4, NULL, RBEV_RAISED2);
772 break;
773 default:
774 pix = None;
776 XFreeGC(dpy, gc);
778 return pix;
781 static void renderPreview(_Panel * panel, GC gc, int part, int relief)
783 WMListItem *item;
784 TextureListItem *titem;
785 Pixmap pix;
786 WMScreen *scr = WMWidgetScreen(panel->box);
788 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
789 titem = (TextureListItem *) item->clientData;
791 pix = renderTexture(scr, titem->prop,
792 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
793 NULL, relief);
795 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
796 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
797 textureOptions[part].preview.pos.x, textureOptions[part].preview.pos.y);
799 XCopyArea(WMScreenDisplay(scr), pix, panel->previewNoText, gc, 0, 0,
800 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
801 textureOptions[part].preview.pos.x, textureOptions[part].preview.pos.y);
803 XFreePixmap(WMScreenDisplay(scr), pix);
806 static void updatePreviewBox(_Panel * panel, int elements)
808 WMScreen *scr = WMWidgetScreen(panel->parent);
809 Display *dpy = WMScreenDisplay(scr);
810 Pixmap pix;
811 GC gc;
812 int colorUpdate = 0;
814 gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
816 if (panel->preview == None) {
817 WMPixmap *p;
819 panel->previewNoText = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
820 240 - 4, 215 - 4, WMScreenDepth(scr));
821 panel->previewBack = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
822 240 - 4, 215 - 4, WMScreenDepth(scr));
824 p = WMCreatePixmap(scr, 240 - 4, 215 - 4, WMScreenDepth(scr), False);
825 panel->preview = WMGetPixmapXID(p);
826 WMSetLabelImage(panel->prevL, p);
827 WMReleasePixmap(p);
829 if (elements & (1 << PBACKGROUND)) {
830 Pixmap tmp;
831 TextureListItem *titem;
832 WMListItem *item;
834 item = WMGetListItem(panel->texLs,
835 panel->textureIndex[PBACKGROUND]);
836 titem = (TextureListItem *) item->clientData;
837 tmp = renderTexture(scr, titem->prop, 240 - 4, 215 - 4, NULL, 0);
839 XCopyArea(dpy, tmp, panel->preview, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
840 XCopyArea(dpy, tmp, panel->previewNoText, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
841 XCopyArea(dpy, tmp, panel->previewBack, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
842 XFreePixmap(dpy, tmp);
845 if (elements & (1 << PFOCUSED)) {
846 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
847 colorUpdate |= 1 << FTITLE_COL | 1 << FFBORDER_COL;
849 if (elements & (1 << PUNFOCUSED)) {
850 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
851 colorUpdate |= 1 << UTITLE_COL | 1 << FBORDER_COL;
853 if (elements & (1 << POWNER)) {
854 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
855 colorUpdate |= 1 << OTITLE_COL | 1 << FBORDER_COL;
857 if (elements & (1 << PRESIZEBAR)) {
858 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
859 colorUpdate |= 1 << FBORDER_COL;
861 if (elements & (1 << PMTITLE)) {
862 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
863 colorUpdate |= 1 << MTITLE_COL | 1 << FBORDER_COL;
865 if (elements & (1 << PMITEM)) {
866 WMListItem *item;
867 TextureListItem *titem;
869 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
870 titem = (TextureListItem *) item->clientData;
872 pix = renderMenu(panel, titem->prop,
873 textureOptions[PMITEM].preview.size.width,
874 textureOptions[PMITEM].preview.size.height / 4);
876 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
877 textureOptions[PMITEM].preview.size.width, textureOptions[PMITEM].preview.size.height,
878 textureOptions[PMITEM].preview.pos.x, textureOptions[PMITEM].preview.pos.y);
880 XCopyArea(dpy, pix, panel->previewNoText, gc, 0, 0,
881 textureOptions[PMITEM].preview.size.width, textureOptions[PMITEM].preview.size.height,
882 textureOptions[PMITEM].preview.pos.x, textureOptions[PMITEM].preview.pos.y);
884 XFreePixmap(dpy, pix);
886 colorUpdate |= 1 << MITEM_COL | 1 << MDISAB_COL |
887 1 << MHIGH_COL | 1 << MHIGHT_COL |
888 1 << FBORDER_COL;
890 if (elements & (1 << PICON)) {
891 WMListItem *item;
892 TextureListItem *titem;
894 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
895 titem = (TextureListItem *) item->clientData;
897 renderPreview(panel, gc, PICON, titem->ispixmap ? 0 : RBEV_RAISED3);
900 if (colorUpdate)
901 updateColorPreviewBox(panel, colorUpdate);
902 else
903 WMRedisplayWidget(panel->prevL);
905 XFreeGC(dpy, gc);
908 static void cancelNewTexture(void *data)
910 _Panel *panel = (_Panel *) data;
912 HideTexturePanel(panel->texturePanel);
915 static char *makeFileName(const char *prefix)
917 char *fname;
919 fname = wstrdup(prefix);
921 while (access(fname, F_OK) == 0) {
922 char buf[30];
924 wfree(fname);
925 sprintf(buf, "%08lx.cache", time(NULL));
926 fname = wstrconcat(prefix, buf);
929 return fname;
932 static void okNewTexture(void *data)
934 _Panel *panel = (_Panel *) data;
935 WMListItem *item;
936 char *name;
937 char *str;
938 WMPropList *prop;
939 TextureListItem *titem;
940 WMScreen *scr = WMWidgetScreen(panel->parent);
942 titem = wmalloc(sizeof(TextureListItem));
944 HideTexturePanel(panel->texturePanel);
946 name = GetTexturePanelTextureName(panel->texturePanel);
948 prop = GetTexturePanelTexture(panel->texturePanel);
950 str = WMGetPropListDescription(prop, False);
952 titem->title = name;
953 titem->prop = prop;
954 titem->texture = str;
955 titem->selectedFor = 0;
957 titem->ispixmap = isPixmap(prop);
959 titem->path = makeFileName(panel->fprefix);
960 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
962 item = WMAddListItem(panel->texLs, "");
963 item->clientData = titem;
965 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
968 static void okEditTexture(void *data)
970 _Panel *panel = (_Panel *) data;
971 WMListItem *item;
972 char *name;
973 char *str;
974 WMPropList *prop;
975 TextureListItem *titem;
977 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
978 titem = (TextureListItem *) item->clientData;
980 HideTexturePanel(panel->texturePanel);
982 if (titem->current) {
983 name = GetTexturePanelTextureName(panel->texturePanel);
985 wfree(titem->title);
986 titem->title = name;
989 prop = GetTexturePanelTexture(panel->texturePanel);
991 str = WMGetPropListDescription(prop, False);
993 WMReleasePropList(titem->prop);
994 titem->prop = prop;
996 titem->ispixmap = isPixmap(prop);
998 wfree(titem->texture);
999 titem->texture = str;
1001 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
1002 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
1003 TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
1005 WMRedisplayWidget(panel->texLs);
1007 if (titem->selectedFor) {
1008 if (titem->selectedFor & (1 << PBACKGROUND))
1009 updatePreviewBox(panel, EVERYTHING);
1010 else
1011 updatePreviewBox(panel, titem->selectedFor);
1014 changePage(panel->secP, panel);
1017 static void editTexture(WMWidget * w, void *data)
1019 _Panel *panel = (_Panel *) data;
1020 WMListItem *item;
1021 TextureListItem *titem;
1023 /* Parameter not used, but tell the compiler that it is ok */
1024 (void) w;
1026 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
1027 titem = (TextureListItem *) item->clientData;
1029 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
1031 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
1033 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1034 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
1036 ShowTexturePanel(panel->texturePanel);
1039 static void newTexture(WMWidget * w, void *data)
1041 _Panel *panel = (_Panel *) data;
1043 /* Parameter not used, but tell the compiler that it is ok */
1044 (void) w;
1046 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
1048 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1050 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1052 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1054 ShowTexturePanel(panel->texturePanel);
1057 static void deleteTexture(WMWidget * w, void *data)
1059 _Panel *panel = (_Panel *) data;
1060 WMListItem *item;
1061 TextureListItem *titem;
1062 int row;
1063 int section;
1065 /* Parameter not used, but tell the compiler that it is ok */
1066 (void) w;
1068 section = WMGetPopUpButtonSelectedItem(panel->secP);
1069 row = WMGetListSelectedItemRow(panel->texLs);
1070 item = WMGetListItem(panel->texLs, row);
1071 titem = (TextureListItem *) item->clientData;
1073 if (titem->selectedFor & (1 << section)) {
1074 TextureListItem *titem2;
1076 panel->textureIndex[section] = section;
1077 item = WMGetListItem(panel->texLs, section);
1078 titem2 = (TextureListItem *) item->clientData;
1079 titem2->selectedFor |= 1 << section;
1082 wfree(titem->title);
1083 wfree(titem->texture);
1084 WMReleasePropList(titem->prop);
1085 if (titem->path) {
1086 if (remove(titem->path) < 0 && errno != ENOENT) {
1087 werror("could not remove file %s", titem->path);
1089 wfree(titem->path);
1092 wfree(titem);
1094 WMRemoveListItem(panel->texLs, row);
1095 WMSetButtonEnabled(panel->delB, False);
1098 static void extractTexture(WMWidget * w, void *data)
1100 _Panel *panel = (_Panel *) data;
1101 char *path;
1102 WMOpenPanel *opanel;
1103 WMScreen *scr = WMWidgetScreen(w);
1105 opanel = WMGetOpenPanel(scr);
1106 WMSetFilePanelCanChooseDirectories(opanel, False);
1107 WMSetFilePanelCanChooseFiles(opanel, True);
1109 if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(), _("Select File"), NULL)) {
1110 path = WMGetFilePanelFileName(opanel);
1112 OpenExtractPanelFor(panel);
1114 wfree(path);
1118 static void changePage(WMWidget * w, void *data)
1120 _Panel *panel = (_Panel *) data;
1121 int section;
1122 WMScreen *scr = WMWidgetScreen(panel->box);
1123 RContext *rc = WMScreenRContext(scr);
1125 if (w) {
1126 section = WMGetPopUpButtonSelectedItem(panel->secP);
1128 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1130 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1133 GC gc;
1135 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1136 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1137 textureOptions[panel->oldsection].hand.x, textureOptions[panel->oldsection].hand.y, 22, 22,
1138 textureOptions[panel->oldsection].hand.x, textureOptions[panel->oldsection].hand.y);
1140 if (w) {
1141 panel->oldsection = section;
1142 WMDrawPixmap(panel->hand, panel->preview, textureOptions[section].hand.x, textureOptions[section].hand.y);
1144 WMRedisplayWidget(panel->prevL);
1147 static void previewClick(XEvent * event, void *clientData)
1149 _Panel *panel = (_Panel *) clientData;
1150 int i;
1152 switch (panel->oldTabItem) {
1153 case 0:
1154 for (i = 0; i < wlengthof(textureOptions); i++) {
1155 if (event->xbutton.x >= textureOptions[i].preview.pos.x &&
1156 event->xbutton.y >= textureOptions[i].preview.pos.y &&
1157 event->xbutton.x < textureOptions[i].preview.pos.x + textureOptions[i].preview.size.width &&
1158 event->xbutton.y < textureOptions[i].preview.pos.y + textureOptions[i].preview.size.height) {
1160 WMSetPopUpButtonSelectedItem(panel->secP, i);
1161 changePage(panel->secP, panel);
1162 return;
1165 break;
1166 case 1:
1167 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1168 if (event->xbutton.x >= colorOptions[i].preview.pos.x &&
1169 event->xbutton.y >= colorOptions[i].preview.pos.y &&
1170 event->xbutton.x < colorOptions[i].preview.pos.x + colorOptions[i].preview.size.width &&
1171 event->xbutton.y < colorOptions[i].preview.pos.y + colorOptions[i].preview.size.height) {
1174 * yuck kluge: the entry #7 is HighlightTextColor which does not have actually a
1175 * display area, but are reused to make the last "Normal Item" menu entry actually
1176 * pick the same color item as the other similar item displayed, which corresponds
1177 * to MenuTextColor
1179 if (i == 7)
1180 i = 4;
1182 WMSetPopUpButtonSelectedItem(panel->colP, i);
1183 changeColorPage(panel->colP, panel);
1184 return;
1187 break;
1191 static void textureClick(WMWidget * w, void *data)
1193 _Panel *panel = (_Panel *) data;
1194 int i;
1195 WMListItem *item;
1196 TextureListItem *titem;
1198 /* Parameter not used, but tell the compiler that it is ok */
1199 (void) w;
1201 i = WMGetListSelectedItemRow(panel->texLs);
1203 item = WMGetListItem(panel->texLs, i);
1205 titem = (TextureListItem *) item->clientData;
1207 if (titem->current) {
1208 WMSetButtonEnabled(panel->delB, False);
1209 } else {
1210 WMSetButtonEnabled(panel->delB, True);
1214 static void textureDoubleClick(WMWidget * w, void *data)
1216 _Panel *panel = (_Panel *) data;
1217 int i, section;
1218 WMListItem *item;
1219 TextureListItem *titem;
1221 /* Parameter not used, but tell the compiler that it is ok */
1222 (void) w;
1224 /* unselect old texture */
1225 section = WMGetPopUpButtonSelectedItem(panel->secP);
1227 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1228 titem = (TextureListItem *) item->clientData;
1229 titem->selectedFor &= ~(1 << section);
1231 /* select new texture */
1232 i = WMGetListSelectedItemRow(panel->texLs);
1234 item = WMGetListItem(panel->texLs, i);
1236 titem = (TextureListItem *) item->clientData;
1238 titem->selectedFor |= 1 << section;
1240 panel->textureIndex[section] = i;
1242 WMRedisplayWidget(panel->texLs);
1244 if (section == PBACKGROUND)
1245 updatePreviewBox(panel, EVERYTHING);
1246 else
1247 updatePreviewBox(panel, 1 << section);
1250 static void paintListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
1252 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
1253 WMScreen *scr = WMWidgetScreen(lPtr);
1254 int width, height, x, y;
1255 Display *dpy = WMScreenDisplay(scr);
1256 WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
1257 WMListItem *item;
1258 WMColor *black = WMBlackColor(scr);
1259 TextureListItem *titem;
1261 /* Parameter not used, but tell the compiler that it is ok */
1262 (void) text;
1264 item = WMGetListItem(lPtr, index);
1265 titem = (TextureListItem *) item->clientData;
1266 if (!titem) {
1267 WMReleaseColor(back);
1268 WMReleaseColor(black);
1269 return;
1272 width = rect->size.width;
1273 height = rect->size.height;
1274 x = rect->pos.x;
1275 y = rect->pos.y;
1277 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
1279 if (titem->preview)
1280 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1281 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1283 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1284 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1285 else if (titem->selectedFor)
1286 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1288 WMDrawString(scr, d, black, panel->boldFont,
1289 x + TEXPREV_WIDTH + 22, y + 2, titem->title, strlen(titem->title));
1291 WMDrawString(scr, d, black, panel->smallFont,
1292 x + TEXPREV_WIDTH + 14, y + 18, titem->texture, strlen(titem->texture));
1294 WMReleaseColor(back);
1295 WMReleaseColor(black);
1298 static Pixmap loadRImage(WMScreen * scr, const char *path)
1300 FILE *f;
1301 RImage *image;
1302 int w, h, d, cnt;
1303 size_t read_size;
1304 Pixmap pixmap;
1306 f = fopen(path, "rb");
1307 if (!f)
1308 return None;
1310 cnt = fscanf(f, "%02x%02x%1x", &w, &h, &d);
1311 if (cnt != 3) {
1312 fclose(f);
1313 return None;
1315 image = RCreateImage(w, h, d == 4);
1316 read_size = w * h * d;
1317 if (fread(image->data, 1, read_size, f) == read_size)
1318 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1319 else
1320 pixmap = None;
1322 fclose(f);
1324 RReleaseImage(image);
1326 return pixmap;
1329 static void fillTextureList(WMList * lPtr)
1331 WMPropList *textureList;
1332 WMPropList *texture;
1333 WMUserDefaults *udb = WMGetStandardUserDefaults();
1334 TextureListItem *titem;
1335 WMScreen *scr = WMWidgetScreen(lPtr);
1336 int i;
1338 textureList = WMGetUDObjectForKey(udb, "TextureList");
1339 if (!textureList)
1340 return;
1342 for (i = 0; i < WMGetPropListItemCount(textureList); i++) {
1343 WMListItem *item;
1345 texture = WMGetFromPLArray(textureList, i);
1347 titem = wmalloc(sizeof(TextureListItem));
1349 titem->title = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 0)));
1350 titem->prop = WMRetainPropList(WMGetFromPLArray(texture, 1));
1351 titem->texture = WMGetPropListDescription(titem->prop, False);
1352 titem->selectedFor = 0;
1353 titem->path = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
1355 titem->preview = loadRImage(scr, titem->path);
1356 if (!titem->preview) {
1357 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1359 item = WMAddListItem(lPtr, "");
1360 item->clientData = titem;
1364 static void fillColorList(_Panel * panel)
1366 WMColor *color;
1367 WMPropList *list;
1368 WMUserDefaults *udb = WMGetStandardUserDefaults();
1369 WMScreen *scr = WMWidgetScreen(panel->box);
1370 int i;
1372 list = WMGetUDObjectForKey(udb, "ColorList");
1373 if (!list) {
1374 for (i = 0; i < 24; i++) {
1375 color = WMCreateNamedColor(scr, sampleColors[i], False);
1376 if (!color)
1377 continue;
1378 WMSetColorWellColor(panel->sampW[i], color);
1379 WMReleaseColor(color);
1381 } else {
1382 WMPropList *c;
1384 for (i = 0; i < WMIN(24, WMGetPropListItemCount(list)); i++) {
1385 c = WMGetFromPLArray(list, i);
1386 if (!c || !WMIsPLString(c))
1387 continue;
1388 color = WMCreateNamedColor(scr, WMGetFromPLString(c), False);
1389 if (!color)
1390 continue;
1391 WMSetColorWellColor(panel->sampW[i], color);
1392 WMReleaseColor(color);
1397 /*************************************************************************/
1399 static void changeColorPage(WMWidget * w, void *data)
1401 _Panel *panel = (_Panel *) data;
1402 int section;
1403 WMScreen *scr = WMWidgetScreen(panel->box);
1404 RContext *rc = WMScreenRContext(scr);
1406 if (panel->preview) {
1407 GC gc;
1409 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1410 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1411 colorOptions[panel->oldcsection].hand.x,
1412 colorOptions[panel->oldcsection].hand.y, 22, 22 ,
1413 colorOptions[panel->oldcsection].hand.x,
1414 colorOptions[panel->oldcsection].hand.y);
1416 if (w) {
1417 section = WMGetPopUpButtonSelectedItem(panel->colP);
1419 panel->oldcsection = section;
1420 if (panel->preview)
1421 WMDrawPixmap(panel->hand, panel->preview,
1422 colorOptions[section].hand.x, colorOptions[section].hand.y);
1424 if (section >= ICONT_COL)
1425 updateColorPreviewBox(panel, 1 << section);
1427 WMSetColorWellColor(panel->colW, panel->colors[section]);
1429 WMRedisplayWidget(panel->prevL);
1432 static void
1433 paintText(WMScreen * scr, Drawable d, WMColor * color, WMFont * font,
1434 int x, int y, int w, int h, WMAlignment align, char *text)
1436 int l = strlen(text);
1438 switch (align) {
1439 case WALeft:
1440 x += 5;
1441 break;
1442 case WARight:
1443 x += w - 5 - WMWidthOfString(font, text, l);
1444 break;
1445 default:
1446 case WACenter:
1447 x += (w - WMWidthOfString(font, text, l)) / 2;
1448 break;
1450 WMDrawString(scr, d, color, font, x, y + (h - WMFontHeight(font)) / 2, text, l);
1453 static void updateColorPreviewBox(_Panel * panel, int elements)
1455 WMScreen *scr = WMWidgetScreen(panel->box);
1456 Display *dpy = WMScreenDisplay(scr);
1457 Pixmap d, pnot;
1458 GC gc;
1460 d = panel->preview;
1461 pnot = panel->previewNoText;
1462 gc = WMColorGC(panel->colors[FTITLE_COL]);
1464 if (elements & (1 << FTITLE_COL)) {
1465 XCopyArea(dpy, pnot, d, gc, 30, 10, 190, 20, 30, 10);
1466 paintText(scr, d, panel->colors[FTITLE_COL],
1467 panel->boldFont, 30, 10, 190, 20,
1468 panel->titleAlignment, _("Focused Window"));
1470 if (elements & (1 << UTITLE_COL)) {
1471 XCopyArea(dpy, pnot, d, gc, 30, 40, 190, 20, 30, 40);
1472 paintText(scr, d, panel->colors[UTITLE_COL],
1473 panel->boldFont, 30, 40, 190, 20,
1474 panel->titleAlignment,
1475 _("Unfocused Window"));
1477 if (elements & (1 << OTITLE_COL)) {
1478 XCopyArea(dpy, pnot, d, gc, 30, 70, 190, 20, 30, 70);
1479 paintText(scr, d, panel->colors[OTITLE_COL],
1480 panel->boldFont, 30, 70, 190, 20,
1481 panel->titleAlignment,
1482 _("Owner of Focused Window"));
1484 if (elements & (1 << MTITLE_COL)) {
1485 XCopyArea(dpy, pnot, d, gc, 30, 120, 90, 20, 30, 120);
1486 paintText(scr, d, panel->colors[MTITLE_COL],
1487 panel->boldFont, 30, 120, 90, 20, WALeft,
1488 _("Menu Title"));
1490 if (elements & (1 << MITEM_COL)) {
1491 XCopyArea(dpy, pnot, d, gc, 30, 140, 90, 20, 30, 140);
1492 paintText(scr, d, panel->colors[MITEM_COL],
1493 panel->normalFont, 30, 140, 90, 20, WALeft,
1494 _("Normal Item"));
1495 XCopyArea(dpy, pnot, d, gc, 30, 200, 90, 20, 30, 200);
1496 paintText(scr, d, panel->colors[MITEM_COL],
1497 panel->normalFont, 30, 200, 90, 20, WALeft,
1498 _("Normal Item"));
1500 if (elements & (1 << MDISAB_COL)) {
1501 XCopyArea(dpy, pnot, d, gc, 30, 160, 90, 20, 30, 160);
1502 paintText(scr, d, panel->colors[MDISAB_COL],
1503 panel->normalFont, 30, 160, 90, 20, WALeft,
1504 _("Disabled Item"));
1506 if (elements & (1 << MHIGH_COL)) {
1507 XFillRectangle(WMScreenDisplay(scr), d,
1508 WMColorGC(panel->colors[MHIGH_COL]),
1509 31, 181, 87, 17);
1510 XFillRectangle(WMScreenDisplay(scr), pnot,
1511 WMColorGC(panel->colors[MHIGH_COL]),
1512 31, 181, 87, 17);
1513 elements |= 1 << MHIGHT_COL;
1515 if (elements & (1 << MHIGHT_COL)) {
1516 XCopyArea(dpy, pnot, d, gc, 30, 180, 90, 20, 30, 180);
1517 paintText(scr, d, panel->colors[MHIGHT_COL],
1518 panel->normalFont, 30, 180, 90, 20, WALeft,
1519 _("Highlighted"));
1521 if (elements & (1 << FBORDER_COL)) {
1522 XDrawRectangle(dpy, pnot,
1523 WMColorGC(panel->colors[FBORDER_COL]),
1524 29, 39, 190, 20);
1525 XDrawRectangle(dpy, d,
1526 WMColorGC(panel->colors[FBORDER_COL]),
1527 29, 39, 190, 20);
1528 XDrawRectangle(dpy, pnot,
1529 WMColorGC(panel->colors[FBORDER_COL]),
1530 29, 69, 190, 20);
1531 XDrawRectangle(dpy, d,
1532 WMColorGC(panel->colors[FBORDER_COL]),
1533 29, 69, 190, 20);
1534 XDrawLine(dpy, pnot,
1535 WMColorGC(panel->colors[FBORDER_COL]),
1536 30, 100, 30, 109);
1537 XDrawLine(dpy, d,
1538 WMColorGC(panel->colors[FBORDER_COL]),
1539 30, 100, 30, 109);
1540 XDrawLine(dpy, pnot,
1541 WMColorGC(panel->colors[FBORDER_COL]),
1542 31, 109, 219, 109);
1543 XDrawLine(dpy, d,
1544 WMColorGC(panel->colors[FBORDER_COL]),
1545 31, 109, 219, 109);
1546 XDrawLine(dpy, pnot,
1547 WMColorGC(panel->colors[FBORDER_COL]),
1548 220, 100, 220, 109);
1549 XDrawLine(dpy, d,
1550 WMColorGC(panel->colors[FBORDER_COL]),
1551 220, 100, 220, 109);
1552 XDrawLine(dpy, pnot,
1553 WMColorGC(panel->colors[FBORDER_COL]),
1554 29, 120, 29, 220);
1555 XDrawLine(dpy, d,
1556 WMColorGC(panel->colors[FBORDER_COL]),
1557 29, 120, 29, 220);
1558 XDrawLine(dpy, pnot,
1559 WMColorGC(panel->colors[FBORDER_COL]),
1560 29, 119, 119, 119);
1561 XDrawLine(dpy, d,
1562 WMColorGC(panel->colors[FBORDER_COL]),
1563 29, 119, 119, 119);
1564 XDrawLine(dpy, pnot,
1565 WMColorGC(panel->colors[FBORDER_COL]),
1566 119, 120, 119, 220);
1567 XDrawLine(dpy, d,
1568 WMColorGC(panel->colors[FBORDER_COL]),
1569 119, 120, 119, 220);
1572 if (elements & (1 << FFBORDER_COL)) {
1573 XDrawRectangle(dpy, pnot,
1574 WMColorGC(panel->colors[FFBORDER_COL]),
1575 29, 9, 190, 20);
1576 XDrawRectangle(dpy, d,
1577 WMColorGC(panel->colors[FFBORDER_COL]),
1578 29, 9, 190, 20);
1581 if (elements & (1 << ICONT_COL) || elements & (1 << ICONB_COL)) {
1582 RColor rgb;
1583 RHSVColor hsv, hsv2;
1584 int v;
1585 WMColor *light, *dim;
1587 updatePreviewBox(panel, 1 << PICON);
1589 rgb.red = WMRedComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1590 rgb.green = WMGreenComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1591 rgb.blue = WMBlueComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1592 RRGBtoHSV(&rgb, &hsv);
1593 RHSVtoRGB(&hsv, &rgb);
1594 hsv2 = hsv;
1596 v = hsv.value * 16 / 10;
1597 hsv.value = (v > 255 ? 255 : v);
1598 RHSVtoRGB(&hsv, &rgb);
1599 light = WMCreateRGBColor(scr, rgb.red << 8, rgb.green << 8, rgb.blue << 8, False);
1601 hsv2.value = hsv2.value / 2;
1602 RHSVtoRGB(&hsv2, &rgb);
1603 dim = WMCreateRGBColor(scr, rgb.red << 8, rgb.green << 8, rgb.blue << 8, False);
1605 XFillRectangle(dpy, d, WMColorGC(panel->colors[ICONB_COL]), 156, 131, 62, 11);
1606 XDrawLine(dpy, d, WMColorGC(light), 155, 130, 155, 142);
1607 XDrawLine(dpy, d, WMColorGC(light), 156, 130, 217, 130);
1608 XDrawLine(dpy, d, WMColorGC(dim), 218, 130, 218, 142);
1610 paintText(scr, d, panel->colors[ICONT_COL],
1611 panel->smallFont, 155, 130, 64, 13, WALeft,
1612 _("Icon Text"));
1616 if (elements & (1 << CLIP_COL) || elements & (1 << CCLIP_COL)) {
1617 Pixmap pix;
1618 RColor black;
1619 RColor dark;
1620 RColor light;
1621 RImage *tile;
1622 TextureListItem *titem;
1623 WMListItem *item;
1624 XPoint p[4];
1626 item = WMGetListItem(panel->texLs, panel->textureIndex[PICON]);
1627 titem = (TextureListItem *) item->clientData;
1629 pix = renderTexture(scr, titem->prop, 64, 64, NULL, titem->ispixmap ? 0 : RBEV_RAISED3);
1630 tile = RCreateImageFromDrawable(WMScreenRContext(scr), pix, None);
1632 black.alpha = 255;
1633 black.red = black.green = black.blue = 0;
1635 dark.alpha = 0;
1636 dark.red = dark.green = dark.blue = 60;
1638 light.alpha = 0;
1639 light.red = light.green = light.blue = 80;
1641 /* top right */
1642 ROperateLine(tile, RSubtractOperation, 64 - 1 - 23, 0, 64 - 2, 23 - 1, &dark);
1643 RDrawLine(tile, 64 - 1 - 23 - 1, 0, 64 - 1, 23 + 1, &black);
1644 ROperateLine(tile, RAddOperation, 64 - 1 - 23, 2, 64 - 3, 23, &light);
1646 /* arrow bevel */
1647 ROperateLine(tile, RSubtractOperation, 64 - 7 - (23 - 15), 4, 64 - 5, 4, &dark);
1648 ROperateLine(tile, RSubtractOperation, 64 - 6 - (23 - 15), 5, 64 - 5, 6 + 23 - 15, &dark);
1649 ROperateLine(tile, RAddOperation, 64 - 5, 4, 64 - 5, 6 + 23 - 15, &light);
1651 /* bottom left */
1652 ROperateLine(tile, RAddOperation, 2, 64 - 1 - 23 + 2, 23 - 2, 64 - 3, &dark);
1653 RDrawLine(tile, 0, 64 - 1 - 23 - 1, 23 + 1, 64 - 1, &black);
1654 ROperateLine(tile, RSubtractOperation, 0, 64 - 1 - 23 - 2, 23 + 1, 64 - 2, &light);
1656 /* arrow bevel */
1657 ROperateLine(tile, RSubtractOperation, 4, 64 - 7 - (23 - 15), 4, 64 - 5, &dark);
1658 ROperateLine(tile, RSubtractOperation, 5, 64 - 6 - (23 - 15), 6 + 23 - 15, 64 - 5, &dark);
1659 ROperateLine(tile, RAddOperation, 4, 64 - 5, 6 + 23 - 15, 64 - 5, &light);
1661 RConvertImage(WMScreenRContext(scr), tile, &pix);
1662 RReleaseImage(tile);
1664 XCopyArea(dpy, pix, d, gc, 0, 0, 64, 64, 155, 130);
1665 XFreePixmap(dpy, pix);
1667 /* top right arrow */
1668 p[0].x = p[3].x = 155 + 64 - 5 - (23 - 15);
1669 p[0].y = p[3].y = 130 + 5;
1670 p[1].x = 155 + 64 - 6;
1671 p[1].y = 130 + 5;
1672 p[2].x = 155 + 64 - 6;
1673 p[2].y = 130 + 4 + 23 - 15;
1675 XFillPolygon(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 3, Convex, CoordModeOrigin);
1676 XDrawLines(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 4, CoordModeOrigin);
1678 /* bottom left arrow */
1679 p[0].x = p[3].x = 155 + 5;
1680 p[0].y = p[3].y = 130 + 64 - 5 - (23 - 15);
1681 p[1].x = 155 + 5;
1682 p[1].y = 130 + 64 - 6;
1683 p[2].x = 155 + 4 + 23 - 15;
1684 p[2].y = 130 + 64 - 6;
1686 XFillPolygon(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 3, Convex, CoordModeOrigin);
1687 XDrawLines(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 4, CoordModeOrigin);
1691 if (elements & (1 << CLIP_COL))
1692 paintText(scr, d, panel->colors[CLIP_COL],
1693 panel->boldFont, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft,
1694 _("Clip"));
1696 if (elements & (1 << CCLIP_COL)) {
1697 paintText(scr, d, panel->colors[CCLIP_COL],
1698 panel->boldFont, 155+2, 130 + 2, 26, 15, WALeft, _("Coll."));
1699 paintText(scr, d, panel->colors[CCLIP_COL],
1700 panel->boldFont, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft,
1701 _("Clip"));
1704 WMRedisplayWidget(panel->prevL);
1707 static void colorWellObserver(void *self, WMNotification * n)
1709 _Panel *panel = (_Panel *) self;
1710 int p;
1712 /* Parameter not used, but tell the compiler that it is ok */
1713 (void) n;
1715 p = WMGetPopUpButtonSelectedItem(panel->colP);
1717 WMReleaseColor(panel->colors[p]);
1719 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1721 updateColorPreviewBox(panel, 1 << p);
1724 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item)
1726 _Panel *panel = self->data;
1727 int i;
1729 /* Parameter not used, but tell the compiler that it is ok */
1730 (void) tabView;
1732 i = WMGetTabViewItemIdentifier(item);
1733 switch (i) {
1734 case TAB_TEXTURE:
1735 switch (panel->oldTabItem) {
1736 case TAB_COLOR:
1737 changeColorPage(NULL, panel);
1738 break;
1740 changePage(panel->secP, panel);
1741 break;
1742 case TAB_COLOR:
1743 switch (panel->oldTabItem) {
1744 case TAB_TEXTURE:
1745 changePage(NULL, panel);
1746 break;
1748 changeColorPage(panel->colP, panel);
1749 break;
1750 case TAB_OPTIONS:
1751 switch (panel->oldTabItem) {
1752 case TAB_TEXTURE:
1753 changePage(NULL, panel);
1754 break;
1755 case TAB_COLOR:
1756 changeColorPage(NULL, panel);
1757 break;
1759 break;
1762 panel->oldTabItem = i;
1765 /*************************************************************************/
1767 static void menuStyleCallback(WMWidget * self, void *data)
1769 _Panel *panel = (_Panel *) data;
1770 menu_style_index i;
1772 for (i = 0; i < wlengthof(menu_style); i++) {
1773 if (self == panel->mstyB[i]) {
1774 panel->menuStyle = i;
1775 break;
1779 updatePreviewBox(panel, 1 << PMITEM);
1782 static void titleAlignCallback(WMWidget * self, void *data)
1784 _Panel *panel = (_Panel *) data;
1785 WMAlignment align;
1787 for (align = 0; align < wlengthof(wintitle_align); align++) {
1788 if (self == panel->taliB[align]) {
1789 panel->titleAlignment = align;
1790 break;
1794 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1797 static void createPanel(Panel * p)
1799 _Panel *panel = (_Panel *) p;
1800 WMFont *font;
1801 WMScreen *scr = WMWidgetScreen(panel->parent);
1802 WMTabViewItem *item;
1803 int i;
1804 char *tmp;
1805 Bool ok = True;
1807 panel->fprefix = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1809 if (access(panel->fprefix, F_OK) != 0) {
1810 if (mkdir(panel->fprefix, 0755) < 0) {
1811 werror("%s", panel->fprefix);
1812 ok = False;
1815 if (ok) {
1816 tmp = wstrconcat(panel->fprefix, "/WPrefs/");
1817 wfree(panel->fprefix);
1818 panel->fprefix = tmp;
1819 if (access(panel->fprefix, F_OK) != 0) {
1820 if (mkdir(panel->fprefix, 0755) < 0) {
1821 werror("%s", panel->fprefix);
1826 panel->smallFont = WMSystemFontOfSize(scr, 10);
1827 panel->normalFont = WMSystemFontOfSize(scr, 12);
1828 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1830 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1831 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1832 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1834 panel->box = WMCreateBox(panel->parent);
1835 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1837 /* preview box */
1838 panel->prevL = WMCreateLabel(panel->box);
1839 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1840 WMMoveWidget(panel->prevL, 15, 10);
1841 WMSetLabelRelief(panel->prevL, WRSunken);
1842 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1844 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask, previewClick, panel);
1846 /* tabview */
1848 tabviewDelegate.data = panel;
1850 panel->tabv = WMCreateTabView(panel->box);
1851 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1852 WMMoveWidget(panel->tabv, 265, 10);
1853 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1855 /*** texture list ***/
1857 panel->texF = WMCreateFrame(panel->box);
1858 WMSetFrameRelief(panel->texF, WRFlat);
1860 item = WMCreateTabViewItemWithIdentifier(TAB_TEXTURE);
1861 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1862 WMSetTabViewItemLabel(item, _("Texture"));
1864 WMAddItemInTabView(panel->tabv, item);
1866 panel->secP = WMCreatePopUpButton(panel->texF);
1867 WMResizeWidget(panel->secP, 228, 20);
1868 WMMoveWidget(panel->secP, 7, 7);
1870 for (i = 0; i < wlengthof(textureOptions); i++)
1871 WMAddPopUpButtonItem(panel->secP, _(textureOptions[i].popup_label));
1873 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1874 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1876 panel->texLs = WMCreateList(panel->texF);
1877 WMResizeWidget(panel->texLs, 165, 155);
1878 WMMoveWidget(panel->texLs, 70, 33);
1879 WMSetListUserDrawItemHeight(panel->texLs, 35);
1880 WMSetListUserDrawProc(panel->texLs, paintListItem);
1881 WMHangData(panel->texLs, panel);
1882 WMSetListAction(panel->texLs, textureClick, panel);
1883 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1885 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1886 "for the selected item."), WMWidgetView(panel->texLs));
1888 /* command buttons */
1890 font = WMSystemFontOfSize(scr, 10);
1892 panel->newB = WMCreateCommandButton(panel->texF);
1893 WMResizeWidget(panel->newB, 57, 39);
1894 WMMoveWidget(panel->newB, 7, 33);
1895 WMSetButtonFont(panel->newB, font);
1896 WMSetButtonImagePosition(panel->newB, WIPAbove);
1897 WMSetButtonText(panel->newB, _("New"));
1898 WMSetButtonAction(panel->newB, newTexture, panel);
1899 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1901 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel->newB));
1903 panel->ripB = WMCreateCommandButton(panel->texF);
1904 WMResizeWidget(panel->ripB, 57, 39);
1905 WMMoveWidget(panel->ripB, 7, 72);
1906 WMSetButtonFont(panel->ripB, font);
1907 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1908 WMSetButtonText(panel->ripB, _("Extract..."));
1909 WMSetButtonAction(panel->ripB, extractTexture, panel);
1910 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1912 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel->ripB));
1914 WMSetButtonEnabled(panel->ripB, False);
1916 panel->editB = WMCreateCommandButton(panel->texF);
1917 WMResizeWidget(panel->editB, 57, 39);
1918 WMMoveWidget(panel->editB, 7, 111);
1919 WMSetButtonFont(panel->editB, font);
1920 WMSetButtonImagePosition(panel->editB, WIPAbove);
1921 WMSetButtonText(panel->editB, _("Edit"));
1922 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1923 WMSetButtonAction(panel->editB, editTexture, panel);
1924 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel->editB));
1926 panel->delB = WMCreateCommandButton(panel->texF);
1927 WMResizeWidget(panel->delB, 57, 38);
1928 WMMoveWidget(panel->delB, 7, 150);
1929 WMSetButtonFont(panel->delB, font);
1930 WMSetButtonImagePosition(panel->delB, WIPAbove);
1931 WMSetButtonText(panel->delB, _("Delete"));
1932 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1933 WMSetButtonEnabled(panel->delB, False);
1934 WMSetButtonAction(panel->delB, deleteTexture, panel);
1935 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel->delB));
1937 WMReleaseFont(font);
1939 WMMapSubwidgets(panel->texF);
1941 /*** colors ***/
1942 panel->colF = WMCreateFrame(panel->box);
1943 WMSetFrameRelief(panel->colF, WRFlat);
1945 item = WMCreateTabViewItemWithIdentifier(TAB_COLOR);
1946 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1947 WMSetTabViewItemLabel(item, _("Color"));
1949 WMAddItemInTabView(panel->tabv, item);
1951 panel->colP = WMCreatePopUpButton(panel->colF);
1952 WMResizeWidget(panel->colP, 228, 20);
1953 WMMoveWidget(panel->colP, 7, 7);
1955 for (i = 0; i < wlengthof(colorOptions); i++)
1956 WMAddPopUpButtonItem(panel->colP, _(colorOptions[i].label));
1958 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1960 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1962 panel->colW = WMCreateColorWell(panel->colF);
1963 WMResizeWidget(panel->colW, 65, 50);
1964 WMMoveWidget(panel->colW, 30, 75);
1965 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->colW);
1967 for (i = 0; i < 4; i++) {
1968 int j;
1969 for (j = 0; j < 6; j++) {
1970 panel->sampW[i + j * 4] = WMCreateColorWell(panel->colF);
1971 WMResizeWidget(panel->sampW[i + j * 4], 22, 22);
1972 WMMoveWidget(panel->sampW[i + j * 4], 130 + i * 22, 40 + j * 22);
1973 WSetColorWellBordered(panel->sampW[i + j * 4], False);
1977 WMMapSubwidgets(panel->colF);
1979 /*** options ***/
1980 panel->optF = WMCreateFrame(panel->box);
1981 WMSetFrameRelief(panel->optF, WRFlat);
1983 item = WMCreateTabViewItemWithIdentifier(TAB_OPTIONS);
1984 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1985 WMSetTabViewItemLabel(item, _("Options"));
1987 WMAddItemInTabView(panel->tabv, item);
1989 panel->mstyF = WMCreateFrame(panel->optF);
1990 WMResizeWidget(panel->mstyF, 215, 85);
1991 WMMoveWidget(panel->mstyF, 15, 10);
1992 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1994 for (i = 0; i < wlengthof(menu_style); i++) {
1995 WMPixmap *icon;
1996 char *path;
1998 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1999 WMResizeWidget(panel->mstyB[i], 54, 54);
2000 WMMoveWidget(panel->mstyB[i], 15 + i * 65, 20);
2001 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
2002 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
2003 path = LocateImage(menu_style[i].file_name);
2004 if (path) {
2005 icon = WMCreatePixmapFromFile(scr, path);
2006 if (icon) {
2007 WMSetButtonImage(panel->mstyB[i], icon);
2008 WMReleasePixmap(icon);
2009 } else {
2010 wwarning(_("could not load icon file %s"), path);
2012 wfree(path);
2015 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
2016 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
2018 WMMapSubwidgets(panel->mstyF);
2020 panel->taliF = WMCreateFrame(panel->optF);
2021 WMResizeWidget(panel->taliF, 110, 80);
2022 WMMoveWidget(panel->taliF, 15, 100);
2023 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
2025 for (i = 0; i < wlengthof(wintitle_align); i++) {
2026 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
2027 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
2028 WMSetButtonText(panel->taliB[i], _(wintitle_align[i].label));
2029 WMResizeWidget(panel->taliB[i], 90, 18);
2030 WMMoveWidget(panel->taliB[i], 10, 15 + 20 * i);
2032 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
2033 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
2035 WMMapSubwidgets(panel->taliF);
2037 WMMapSubwidgets(panel->optF);
2039 /**/ WMRealizeWidget(panel->box);
2040 WMMapSubwidgets(panel->box);
2042 WMSetPopUpButtonSelectedItem(panel->secP, 0);
2044 showData(panel);
2046 changePage(panel->secP, panel);
2048 fillTextureList(panel->texLs);
2050 fillColorList(panel);
2052 panel->texturePanel = CreateTexturePanel(panel->parent);
2055 static void setupTextureFor(WMList *list, const char *key, const char *defValue, const char *title, int index)
2057 WMListItem *item;
2058 TextureListItem *titem;
2060 titem = wmalloc(sizeof(TextureListItem));
2062 titem->title = wstrdup(title);
2063 titem->prop = GetObjectForKey(key);
2064 if (!titem->prop || !WMIsPLArray(titem->prop)) {
2065 /* Maybe also give a error message to stderr that the entry is bad? */
2066 titem->prop = WMCreatePropListFromDescription(defValue);
2067 } else {
2068 WMRetainPropList(titem->prop);
2070 titem->texture = WMGetPropListDescription((WMPropList *) titem->prop, False);
2071 titem->current = 1;
2072 titem->selectedFor = 1 << index;
2074 titem->ispixmap = isPixmap(titem->prop);
2076 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
2078 item = WMAddListItem(list, "");
2079 item->clientData = titem;
2082 static void showData(_Panel * panel)
2084 int i;
2085 const char *str;
2087 str = GetStringForKey("MenuStyle");
2088 panel->menuStyle = MSTYLE_NORMAL;
2089 if (str != NULL) {
2090 for (i = 0; i < wlengthof(menu_style); i++) {
2091 if (strcasecmp(str, menu_style[i].db_value) == 0) {
2092 panel->menuStyle = i;
2093 break;
2098 str = GetStringForKey("TitleJustify");
2099 panel->titleAlignment = WACenter;
2100 if (str != NULL) {
2101 WMAlignment align;
2103 for (align = 0; align < wlengthof(wintitle_align); align++) {
2104 if (strcasecmp(str, wintitle_align[align].db_value) == 0) {
2105 panel->titleAlignment = align;
2106 break;
2111 for (i = 0; i < wlengthof(colorOptions); i++) {
2112 WMColor *color;
2114 str = GetStringForKey(colorOptions[i].key);
2115 if (!str)
2116 str = colorOptions[i].default_value;
2118 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->box), str, False))) {
2119 color = WMCreateNamedColor(WMWidgetScreen(panel->box), "#000000", False);
2122 panel->colors[i] = color;
2124 changeColorPage(panel->colP, panel);
2126 for (i = 0; i < wlengthof(textureOptions); i++) {
2127 setupTextureFor(panel->texLs, textureOptions[i].key,
2128 textureOptions[i].default_value, _(textureOptions[i].texture_label), i);
2129 panel->textureIndex[i] = i;
2131 updatePreviewBox(panel, EVERYTHING);
2133 WMSetButtonSelected(panel->mstyB[panel->menuStyle], True);
2134 WMSetButtonSelected(panel->taliB[panel->titleAlignment], True);
2137 static void storeData(_Panel * panel)
2139 TextureListItem *titem;
2140 WMListItem *item;
2141 int i;
2143 for (i = 0; i < wlengthof(textureOptions); i++) {
2144 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2145 titem = (TextureListItem *) item->clientData;
2146 SetObjectForKey(titem->prop, textureOptions[i].key);
2149 for (i = 0; i < wlengthof(colorOptions); i++) {
2150 char *str;
2152 str = WMGetColorRGBDescription(panel->colors[i]);
2154 if (str) {
2155 SetStringForKey(str, colorOptions[i].key);
2156 wfree(str);
2160 SetStringForKey(menu_style[panel->menuStyle].db_value, "MenuStyle");
2161 SetStringForKey(wintitle_align[panel->titleAlignment].db_value, "TitleJustify");
2164 static void prepareForClose(_Panel * panel)
2166 WMPropList *textureList;
2167 WMPropList *texture;
2168 TextureListItem *titem;
2169 WMListItem *item;
2170 WMUserDefaults *udb = WMGetStandardUserDefaults();
2171 int i;
2173 textureList = WMCreatePLArray(NULL, NULL);
2175 /* store list of textures */
2176 for (i = 8; i < WMGetListNumberOfRows(panel->texLs); i++) {
2177 item = WMGetListItem(panel->texLs, i);
2178 titem = (TextureListItem *) item->clientData;
2180 texture = WMCreatePLArray(WMCreatePLString(titem->title),
2181 WMRetainPropList(titem->prop), WMCreatePLString(titem->path), NULL);
2183 WMAddToPLArray(textureList, texture);
2186 WMSetUDObjectForKey(udb, textureList, "TextureList");
2187 WMReleasePropList(textureList);
2189 /* store list of colors */
2190 textureList = WMCreatePLArray(NULL, NULL);
2191 for (i = 0; i < 24; i++) {
2192 WMColor *color;
2193 char *str;
2195 color = WMGetColorWellColor(panel->sampW[i]);
2197 str = WMGetColorRGBDescription(color);
2198 WMAddToPLArray(textureList, WMCreatePLString(str));
2199 wfree(str);
2201 WMSetUDObjectForKey(udb, textureList, "ColorList");
2202 WMReleasePropList(textureList);
2204 WMSynchronizeUserDefaults(udb);
2207 Panel *InitAppearance(WMWidget *parent)
2209 _Panel *panel;
2211 panel = wmalloc(sizeof(_Panel));
2213 panel->sectionName = _("Appearance Preferences");
2215 panel->description = _("Background texture configuration for windows,\n" "menus and icons.");
2217 panel->parent = parent;
2219 panel->callbacks.createWidgets = createPanel;
2220 panel->callbacks.updateDomain = storeData;
2221 panel->callbacks.prepareForClose = prepareForClose;
2223 AddSection(panel, ICON_FILE);
2225 return panel;
2228 /****************************************************************************/
2230 typedef struct ExtractPanel {
2231 WMWindow *win;
2233 WMLabel *label;
2234 WMList *list;
2236 WMButton *closeB;
2237 WMButton *extrB;
2238 } ExtractPanel;
2240 static void OpenExtractPanelFor(_Panel *panel)
2242 ExtractPanel *epanel;
2243 WMColor *color;
2244 WMFont *font;
2245 WMScreen *scr = WMWidgetScreen(panel->parent);
2247 epanel = wmalloc(sizeof(ExtractPanel));
2248 epanel->win = WMCreatePanelWithStyleForWindow(panel->parent, "extract",
2249 WMTitledWindowMask | WMClosableWindowMask);
2250 WMResizeWidget(epanel->win, 245, 250);
2251 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2253 epanel->label = WMCreateLabel(epanel->win);
2254 WMResizeWidget(epanel->label, 225, 18);
2255 WMMoveWidget(epanel->label, 10, 10);
2256 WMSetLabelTextAlignment(epanel->label, WACenter);
2257 WMSetLabelRelief(epanel->label, WRSunken);
2259 color = WMDarkGrayColor(scr);
2260 WMSetWidgetBackgroundColor(epanel->label, color);
2261 WMReleaseColor(color);
2263 color = WMWhiteColor(scr);
2264 WMSetLabelTextColor(epanel->label, color);
2265 WMReleaseColor(color);
2267 font = WMBoldSystemFontOfSize(scr, 12);
2268 WMSetLabelFont(epanel->label, font);
2269 WMReleaseFont(font);
2271 WMSetLabelText(epanel->label, _("Textures"));
2273 epanel->list = WMCreateList(epanel->win);
2274 WMResizeWidget(epanel->list, 225, 165);
2275 WMMoveWidget(epanel->list, 10, 30);
2277 epanel->closeB = WMCreateCommandButton(epanel->win);
2278 WMResizeWidget(epanel->closeB, 74, 24);
2279 WMMoveWidget(epanel->closeB, 165, 215);
2280 WMSetButtonText(epanel->closeB, _("Close"));
2282 epanel->extrB = WMCreateCommandButton(epanel->win);
2283 WMResizeWidget(epanel->extrB, 74, 24);
2284 WMMoveWidget(epanel->extrB, 80, 215);
2285 WMSetButtonText(epanel->extrB, _("Extract"));
2287 WMMapSubwidgets(epanel->win);
2289 /* take textures from file */
2291 WMRealizeWidget(epanel->win);
2293 WMMapWidget(epanel->win);