Update Serbian translation from master branch
[wmaker-crm.git] / WPrefs.app / Appearance.c
blob01ddc28ed290e76aedd6fd8b0a563c169189e862
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>
31 #include <math.h>
33 #include "TexturePanel.h"
36 static const struct {
37 const char *key;
38 const char *default_value;
39 const char *label;
40 WMRect preview; /* The rectangle where the corresponding object is displayed */
41 WMPoint hand; /* The coordinate where the hand is drawn when pointing this item */
42 } colorOptions[] = {
43 /* Related to Window titles */
44 { "FTitleColor", "white", N_("Focused Window Title"),
45 { { 30, 10 }, { 190, 20 } }, { 5, 10 } },
46 { "UTitleColor", "black", N_("Unfocused Window Title"),
47 { { 30, 40 }, { 190, 20 } }, { 5, 40 } },
48 { "PTitleColor", "white", N_("Owner of Focused Window Title"),
49 { { 30, 70 }, { 190, 20 } }, { 5, 70 } },
51 /* Related to Menus */
52 { "MenuTitleColor", "white", N_("Menu Title") ,
53 { { 30, 120 }, { 90, 20 } }, { 5, 120 } },
54 { "MenuTextColor", "black", N_("Menu Item Text") ,
55 { { 30, 140 }, { 90, 20 } }, { 5, 140 } },
56 { "MenuDisabledColor", "#616161", N_("Disabled Menu Item Text") ,
57 { { 30, 160 }, { 90, 20 } }, { 5, 160 } },
58 { "HighlightColor", "white", N_("Menu Highlight Color") ,
59 { { 30, 180 }, { 90, 20 } }, { 5, 180 } },
60 { "HighlightTextColor", "black", N_("Highlighted Menu Text Color") ,
61 { { 30, 200 }, { 90, 20 } }, { 5, 180 } },
63 * yuck kluge: the coordinate for HighlightTextColor are actually those of the last "Normal item"
64 * at the bottom when user clicks it, the "yuck kluge" in the function 'previewClick' will swap it
65 * for the MenuTextColor selection as user would expect
67 * Note that the entries are reffered by their index for performance
70 /* Related to Window's border */
71 { "FrameFocusedBorderColor", "black", N_("Focused Window Border Color") ,
72 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
73 { "FrameBorderColor", "black", N_("Window Border Color") ,
74 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
75 { "FrameSelectedBorderColor", "white", N_("Selected Window Border Color") ,
76 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
78 /* Related to Icons and Clip */
79 { "IconTitleColor", "white", N_("Miniwindow Title") ,
80 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
81 { "IconTitleBack", "black", N_("Miniwindow Title Back") ,
82 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
83 { "ClipTitleColor", "black", N_("Clip Title") ,
84 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
85 { "CClipTitleColor", "#454045", N_("Collapsed Clip Title") ,
86 { { 155, 130 }, { 64, 64 } }, { 130, 132 } }
89 /********************************************************************/
90 typedef enum {
91 MSTYLE_NORMAL = 0,
92 MSTYLE_SINGLE = 1,
93 MSTYLE_FLAT = 2
94 } menu_style_index;
96 static const struct {
97 const char *db_value;
98 const char *file_name;
99 } menu_style[] = {
100 [MSTYLE_NORMAL] = { "normal", "msty1" },
101 [MSTYLE_SINGLE] = { "singletexture", "msty2" },
102 [MSTYLE_FLAT] = { "flat", "msty3" }
105 /********************************************************************/
106 static const struct {
107 const char *label;
108 const char *db_value;
109 } wintitle_align[] = {
110 [WALeft] = { N_("Left"), "left" },
111 [WACenter] = { N_("Center"), "center" },
112 [WARight] = { N_("Right"), "right" }
115 /********************************************************************/
116 static const char *const sample_colors[] = {
117 "black",
118 "#292929",
119 "#525252",
120 "#848484",
121 "#adadad",
122 "#d6d6d6",
123 "white",
124 "#d6d68c",
125 "#d6a57b",
126 "#8cd68c",
127 "#8cd6ce",
128 "#d68c8c",
129 "#8c9cd6",
130 "#bd86d6",
131 "#d68cbd",
132 "#d64a4a",
133 "#4a5ad6",
134 "#4ad6ce",
135 "#4ad65a",
136 "#ced64a",
137 "#d6844a",
138 "#8ad631",
139 "#ce29c6",
140 "#ce2973"
143 /********************************************************************/
144 typedef struct _Panel {
145 WMBox *box;
146 char *sectionName;
148 char *description;
150 CallbackRec callbacks;
152 WMWidget *parent;
154 WMLabel *prevL;
156 WMTabView *tabv;
158 /* texture list */
159 WMFrame *texF;
160 WMList *texLs;
162 WMPopUpButton *secP;
164 WMButton *newB;
165 WMButton *editB;
166 WMButton *ripB;
167 WMButton *delB;
169 /* text color */
170 WMFrame *colF;
172 WMPopUpButton *colP;
173 WMColor *colors[wlengthof_nocheck(colorOptions)];
175 WMColorWell *colW;
177 WMColorWell *sampW[wlengthof_nocheck(sample_colors)];
179 /* options */
180 WMFrame *optF;
182 WMFrame *mstyF;
183 WMButton *mstyB[wlengthof_nocheck(menu_style)];
185 WMFrame *taliF;
186 WMButton *taliB[wlengthof_nocheck(wintitle_align)];
188 /* */
190 int textureIndex[8];
192 WMFont *smallFont;
193 WMFont *normalFont;
194 WMFont *boldFont;
196 TexturePanel *texturePanel;
198 WMPixmap *onLed;
199 WMPixmap *offLed;
200 WMPixmap *hand;
202 int oldsection;
203 int oldcsection;
205 char oldTabItem;
207 menu_style_index menuStyle;
209 WMAlignment titleAlignment;
211 Pixmap preview;
212 Pixmap previewNoText;
213 Pixmap previewBack;
215 char *fprefix;
216 } _Panel;
218 typedef struct {
219 char *title;
220 char *texture;
221 WMPropList *prop;
222 Pixmap preview;
224 char *path;
226 char selectedFor;
227 unsigned current:1;
228 unsigned ispixmap:1;
229 } TextureListItem;
231 enum {
232 TAB_TEXTURE,
233 TAB_COLOR,
234 TAB_OPTIONS
237 static void updateColorPreviewBox(_Panel * panel, int elements);
239 static void showData(_Panel * panel);
241 static void changePage(WMWidget * w, void *data);
243 static void changeColorPage(WMWidget * w, void *data);
245 static void OpenExtractPanelFor(_Panel *panel);
247 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item);
249 static WMTabViewDelegate tabviewDelegate = {
250 NULL,
251 NULL, /* didChangeNumberOfItems */
252 changedTabItem, /* didSelectItem */
253 NULL, /* shouldSelectItem */
254 NULL /* willSelectItem */
257 #define ICON_FILE "appearance"
259 #define TNEW_FILE "tnew"
260 #define TDEL_FILE "tdel"
261 #define TEDIT_FILE "tedit"
262 #define TEXTR_FILE "textr"
264 /* XPM */
265 static char *blueled_xpm[] = {
266 "8 8 17 1",
267 " c None",
268 ". c #020204",
269 "+ c #16B6FC",
270 "@ c #176AFC",
271 "# c #163AFC",
272 "$ c #72D2FC",
273 "% c #224CF4",
274 "& c #76D6FC",
275 "* c #16AAFC",
276 "= c #CEE9FC",
277 "- c #229EFC",
278 "; c #164CFC",
279 "> c #FAFEFC",
280 ", c #2482FC",
281 "' c #1652FC",
282 ") c #1E76FC",
283 "! c #1A60FC",
284 " .... ",
285 " .=>-@. ",
286 ".=>$@@'.",
287 ".=$@!;;.",
288 ".!@*+!#.",
289 ".#'*+*,.",
290 " .@)@,. ",
291 " .... "
294 /* XPM */
295 static char *blueled2_xpm[] = {
296 /* width height num_colors chars_per_pixel */
297 " 8 8 17 1",
298 /* colors */
299 ". c None",
300 "# c #090909",
301 "a c #4b63a4",
302 "b c #011578",
303 "c c #264194",
304 "d c #04338c",
305 "e c #989dac",
306 "f c #011a7c",
307 "g c #465c9c",
308 "h c #03278a",
309 "i c #6175ac",
310 "j c #011e74",
311 "k c #043a90",
312 "l c #042f94",
313 "m c #0933a4",
314 "n c #022184",
315 "o c #012998",
316 /* pixels */
317 "..####..",
318 ".#aimn#.",
319 "#aechnf#",
320 "#gchnjf#",
321 "#jndknb#",
322 "#bjdddl#",
323 ".#nono#.",
324 "..####.."
327 /* XPM */
328 static char *hand_xpm[] = {
329 "22 21 19 1",
330 " c None",
331 ". c #030305",
332 "+ c #7F7F7E",
333 "@ c #B5B5B6",
334 "# c #C5C5C6",
335 "$ c #969697",
336 "% c #FDFDFB",
337 "& c #F2F2F4",
338 "* c #E5E5E4",
339 "= c #ECECEC",
340 "- c #DCDCDC",
341 "; c #D2D2D0",
342 "> c #101010",
343 ", c #767674",
344 "' c #676767",
345 ") c #535355",
346 "! c #323234",
347 "~ c #3E3C56",
348 "{ c #333147",
349 " ",
350 " ..... ",
351 " ..+@##$. ",
352 " .%%%&@.......... ",
353 " .%*%%&#%%%%%%%%%$. ",
354 " .*#%%%%%%%%%&&&&==. ",
355 " .-%%%%%%%%%=*-;;;#$. ",
356 " .-%%%%%%%%&..>..... ",
357 " >-%%%%%%%%%*#+. ",
358 " >-%%%%%%%%%*@,. ",
359 " >#%%%%%%%%%*@'. ",
360 " >$&&%%%%%%=... ",
361 " .+@@;=&%%&;$,> ",
362 " .',$@####$+). ",
363 " .!',+$++,'. ",
364 " ..>>>>>. ",
365 " ",
366 " ~~{{{~~ ",
367 " {{{{{{{{{{{ ",
368 " ~~{{{~~ ",
372 static const struct {
373 const char *key;
374 const char *default_value;
375 const char *texture_label; /* text used when displaying the list of textures */
376 WMRect preview; /* The rectangle where the corresponding object is displayed */
377 WMPoint hand; /* The coordinate where the hand is drawn when pointing this item */
378 const char *popup_label; /* text used for the popup button with the list of editable items */
379 } textureOptions[] = {
381 #define PFOCUSED 0
382 { "FTitleBack", "(solid, black)", N_("[Focused]"),
383 { { 30, 10 }, { 190, 20 } }, { 5, 10 }, N_("Titlebar of Focused Window") },
385 #define PUNFOCUSED 1
386 { "UTitleBack", "(solid, gray)", N_("[Unfocused]"),
387 { { 30, 40 }, { 190, 20 } }, { 5, 40 }, N_("Titlebar of Unfocused Windows") },
389 #define POWNER 2
390 { "PTitleBack", "(solid, \"#616161\")", N_("[Owner of Focused]"),
391 { { 30, 70 }, { 190, 20 } }, { 5, 70 }, N_("Titlebar of Focused Window's Owner") },
393 #define PRESIZEBAR 3
394 { "ResizebarBack", "(solid, gray)", N_("[Resizebar]"),
395 { { 30, 100 }, { 190, 9 } }, { 5, 100 }, N_("Window Resizebar") },
397 #define PMTITLE 4
398 { "MenuTitleBack", "(solid, black)", N_("[Menu Title]"),
399 { { 30, 120 }, { 90, 20 } }, { 5, 120 }, N_("Titlebar of Menus") },
401 #define PMITEM 5
402 { "MenuTextBack", "(solid, gray)", N_("[Menu Item]"),
403 { { 30, 140 }, { 90, 20 * 4 } }, { 5, 160 }, N_("Menu Items") },
405 #define PICON 6
406 { "IconBack", "(solid, gray)", N_("[Icon]"),
407 { { 155, 130 }, { 64, 64 } }, { 130, 150 }, N_("Icon Background") },
409 #define PBACKGROUND 7
410 { "WorkspaceBack", "(solid, black)", N_("[Background]"),
411 { { -1, -1}, { 0, 0 } }, { -22, -21 }, N_("Workspace Background") }
413 #define EVERYTHING 0xff
416 enum {
417 RESIZEBAR_BEVEL = -1,
418 MENU_BEVEL = -2
421 enum {
422 TEXPREV_WIDTH = 40,
423 TEXPREV_HEIGHT = 24
426 enum {
427 FTITLE_COL,
428 UTITLE_COL,
429 OTITLE_COL,
430 MTITLE_COL,
431 MITEM_COL,
432 MDISAB_COL,
433 MHIGH_COL,
434 MHIGHT_COL,
435 FFBORDER_COL,
436 FBORDER_COL,
437 FSBORDER_COL,
438 ICONT_COL,
439 ICONB_COL,
440 CLIP_COL,
441 CCLIP_COL
445 static void str2rcolor(RContext * rc, const char *name, RColor * color)
447 XColor xcolor;
449 if (XParseColor(rc->dpy, rc->cmap, name, &xcolor) != 0) {
450 color->alpha = 255;
451 color->red = xcolor.red >> 8;
452 color->green = xcolor.green >> 8;
453 color->blue = xcolor.blue >> 8;
454 } else {
455 /* Color Name was not found - Return white instead */
456 color->alpha = 255;
457 color->red = 255;
458 color->green = 255;
459 color->blue = 255;
463 static void dumpRImage(const char *path, RImage * image)
465 FILE *f;
466 int channels = (image->format == RRGBAFormat ? 4 : 3);
468 f = fopen(path, "wb");
469 if (!f) {
470 werror("%s", path);
471 return;
473 fprintf(f, "%02x%02x%1x", image->width, image->height, channels);
475 fwrite(image->data, 1, image->width * image->height * channels, f);
477 fsync(fileno(f));
478 if (fclose(f) < 0) {
479 werror("%s", path);
483 static int isPixmap(WMPropList * prop)
485 WMPropList *p;
486 char *s;
488 p = WMGetFromPLArray(prop, 0);
489 s = WMGetFromPLString(p);
490 if (strcasecmp(&s[1], "pixmap") == 0)
491 return 1;
492 else
493 return 0;
496 /**********************************************************************/
498 static void drawResizebarBevel(RImage * img)
500 RColor light;
501 RColor dark;
502 int width = img->width;
503 int height = img->height;
504 int cwidth = 28;
506 light.alpha = 0;
507 light.red = light.green = light.blue = 80;
509 dark.alpha = 0;
510 dark.red = dark.green = dark.blue = 40;
512 ROperateLine(img, RSubtractOperation, 0, 0, width - 1, 0, &dark);
513 ROperateLine(img, RAddOperation, 0, 1, width - 1, 1, &light);
515 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height - 1, &dark);
516 ROperateLine(img, RAddOperation, cwidth + 1, 2, cwidth + 1, height - 1, &light);
518 ROperateLine(img, RSubtractOperation, width - cwidth - 2, 2, width - cwidth - 2, height - 1, &dark);
519 ROperateLine(img, RAddOperation, width - cwidth - 1, 2, width - cwidth - 1, height - 1, &light);
523 static void drawMenuBevel(RImage * img)
525 RColor light, dark, mid;
526 int i;
527 int iheight = img->height / 4;
529 light.alpha = 0;
530 light.red = light.green = light.blue = 80;
532 dark.alpha = 255;
533 dark.red = dark.green = dark.blue = 0;
535 mid.alpha = 0;
536 mid.red = mid.green = mid.blue = 40;
538 for (i = 1; i < 4; i++) {
539 ROperateLine(img, RSubtractOperation, 0, i * iheight - 2, img->width - 1, i * iheight - 2, &mid);
541 RDrawLine(img, 0, i * iheight - 1, img->width - 1, i * iheight - 1, &dark);
543 ROperateLine(img, RAddOperation, 1, i * iheight, img->width - 2, i * iheight, &light);
547 static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int height, const char *path, int border)
549 char *type;
550 RImage *image = NULL;
551 RImage *timage = NULL;
552 Pixmap pixmap;
553 RContext *rc = WMScreenRContext(scr);
554 char *str;
555 RColor rcolor;
557 type = WMGetFromPLString(WMGetFromPLArray(texture, 0));
559 if (strcasecmp(&type[1], "pixmap") == 0 ||
560 (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T')) {
561 char *path;
563 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
564 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
565 if (path) {
566 timage = RLoadImage(rc, path, 0);
567 if (!timage)
568 wwarning(_("could not load file '%s': %s"), path, RMessageForError(RErrorCode));
569 wfree(path);
570 } else {
571 wwarning(_("could not find file '%s' for texture type %s"), str, type);
572 timage = NULL;
574 if (!timage) {
575 texture = WMCreatePropListFromDescription("(solid, black)");
576 type = "solid";
580 if (strcasecmp(type, "solid") == 0) {
582 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
584 str2rcolor(rc, str, &rcolor);
586 image = RCreateImage(width, height, False);
587 RClearImage(image, &rcolor);
588 } else if (strcasecmp(type, "igradient") == 0) {
589 int t1, t2;
590 RColor c1[2], c2[2];
592 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
593 str2rcolor(rc, str, &c1[0]);
594 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
595 str2rcolor(rc, str, &c1[1]);
596 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
597 t1 = atoi(str);
599 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
600 str2rcolor(rc, str, &c2[0]);
601 str = WMGetFromPLString(WMGetFromPLArray(texture, 5));
602 str2rcolor(rc, str, &c2[1]);
603 str = WMGetFromPLString(WMGetFromPLArray(texture, 6));
604 t2 = atoi(str);
606 image = RRenderInterwovenGradient(width, height, c1, t1, c2, t2);
607 } else if (strcasecmp(&type[1], "gradient") == 0) {
608 RGradientStyle style;
609 RColor rcolor2;
611 switch (toupper(type[0])) {
612 case 'V':
613 style = RVerticalGradient;
614 break;
615 case 'H':
616 style = RHorizontalGradient;
617 break;
618 default:
619 wwarning(_("unknown direction in '%s', falling back to diagonal"), type);
620 /* FALLTHRU */
621 case 'D':
622 style = RDiagonalGradient;
623 break;
626 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
627 str2rcolor(rc, str, &rcolor);
628 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
629 str2rcolor(rc, str, &rcolor2);
631 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
632 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T') {
633 RGradientStyle style;
634 RColor rcolor2;
635 int i;
636 RImage *grad = NULL;
638 switch (toupper(type[1])) {
639 case 'V':
640 style = RVerticalGradient;
641 break;
642 case 'H':
643 style = RHorizontalGradient;
644 break;
645 default:
646 wwarning(_("unknown direction in '%s', falling back to diagonal"), type);
647 /* FALLTHRU */
648 case 'D':
649 style = RDiagonalGradient;
650 break;
653 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
654 str2rcolor(rc, str, &rcolor);
655 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
656 str2rcolor(rc, str, &rcolor2);
658 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
660 image = RMakeTiledImage(timage, width, height);
661 RReleaseImage(timage);
663 i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
665 RCombineImagesWithOpaqueness(image, grad, i);
666 RReleaseImage(grad);
668 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'M') {
669 RGradientStyle style;
670 RColor **colors;
671 int i, j;
673 switch (toupper(type[1])) {
674 case 'V':
675 style = RVerticalGradient;
676 break;
677 case 'H':
678 style = RHorizontalGradient;
679 break;
680 default:
681 wwarning(_("unknown direction in '%s', falling back to diagonal"), type);
682 /* FALLTHRU */
683 case 'D':
684 style = RDiagonalGradient;
685 break;
688 j = WMGetPropListItemCount(texture);
690 if (j > 0) {
691 colors = wmalloc(j * sizeof(RColor *));
693 for (i = 2; i < j; i++) {
694 str = WMGetFromPLString(WMGetFromPLArray(texture, i));
695 colors[i - 2] = wmalloc(sizeof(RColor));
696 str2rcolor(rc, str, colors[i - 2]);
698 colors[i - 2] = NULL;
700 image = RRenderMultiGradient(width, height, colors, style);
702 for (i = 0; colors[i] != NULL; i++)
703 wfree(colors[i]);
704 wfree(colors);
706 } else if (strcasecmp(&type[1], "pixmap") == 0) {
707 RColor color;
709 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
710 str2rcolor(rc, str, &color);
712 switch (toupper(type[0])) {
713 case 'T':
714 image = RMakeTiledImage(timage, width, height);
715 RReleaseImage(timage);
716 break;
717 case 'C':
718 image = RMakeCenteredImage(timage, width, height, &color);
719 RReleaseImage(timage);
720 break;
721 case 'F':
722 case 'S':
723 case 'M':
724 image = RScaleImage(timage, width, height);
725 RReleaseImage(timage);
726 break;
728 default:
729 wwarning(_("type '%s' is not a supported type for a texture"), type);
730 RReleaseImage(timage);
731 return None;
735 if (!image)
736 return None;
738 if (path) {
739 dumpRImage(path, image);
742 if (border < 0) {
743 if (border == RESIZEBAR_BEVEL) {
744 drawResizebarBevel(image);
745 } else if (border == MENU_BEVEL) {
746 drawMenuBevel(image);
747 RBevelImage(image, RBEV_RAISED2);
749 } else if (border) {
750 RBevelImage(image, border);
753 RConvertImage(rc, image, &pixmap);
754 RReleaseImage(image);
756 return pixmap;
759 static Pixmap renderMenu(_Panel * panel, WMPropList * texture, int width, int iheight)
761 WMScreen *scr = WMWidgetScreen(panel->parent);
762 Display *dpy = WMScreenDisplay(scr);
763 Pixmap pix, tmp;
764 GC gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
765 int i;
767 switch (panel->menuStyle) {
768 case MSTYLE_NORMAL:
769 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
771 pix = XCreatePixmap(dpy, tmp, width, iheight * 4, WMScreenDepth(scr));
772 for (i = 0; i < 4; i++) {
773 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight * i);
775 XFreePixmap(dpy, tmp);
776 break;
777 case MSTYLE_SINGLE:
778 pix = renderTexture(scr, texture, width, iheight * 4, NULL, MENU_BEVEL);
779 break;
780 case MSTYLE_FLAT:
781 pix = renderTexture(scr, texture, width, iheight * 4, NULL, RBEV_RAISED2);
782 break;
783 default:
784 pix = None;
786 XFreeGC(dpy, gc);
788 return pix;
791 static void renderPreview(_Panel * panel, GC gc, int part, int relief)
793 WMListItem *item;
794 TextureListItem *titem;
795 Pixmap pix;
796 WMScreen *scr = WMWidgetScreen(panel->box);
798 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
799 titem = (TextureListItem *) item->clientData;
801 pix = renderTexture(scr, titem->prop,
802 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
803 NULL, relief);
805 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
806 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
807 textureOptions[part].preview.pos.x, textureOptions[part].preview.pos.y);
809 XCopyArea(WMScreenDisplay(scr), pix, panel->previewNoText, gc, 0, 0,
810 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
811 textureOptions[part].preview.pos.x, textureOptions[part].preview.pos.y);
813 XFreePixmap(WMScreenDisplay(scr), pix);
816 static void updatePreviewBox(_Panel * panel, int elements)
818 WMScreen *scr = WMWidgetScreen(panel->parent);
819 Display *dpy = WMScreenDisplay(scr);
820 Pixmap pix;
821 GC gc;
822 int colorUpdate = 0;
824 gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
826 if (panel->preview == None) {
827 WMPixmap *p;
829 panel->previewNoText = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
830 240 - 4, 215 - 4, WMScreenDepth(scr));
831 panel->previewBack = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
832 240 - 4, 215 - 4, WMScreenDepth(scr));
834 p = WMCreatePixmap(scr, 240 - 4, 215 - 4, WMScreenDepth(scr), False);
835 panel->preview = WMGetPixmapXID(p);
836 WMSetLabelImage(panel->prevL, p);
837 WMReleasePixmap(p);
839 if (elements & (1 << PBACKGROUND)) {
840 Pixmap tmp;
841 TextureListItem *titem;
842 WMListItem *item;
844 item = WMGetListItem(panel->texLs,
845 panel->textureIndex[PBACKGROUND]);
846 titem = (TextureListItem *) item->clientData;
847 tmp = renderTexture(scr, titem->prop, 240 - 4, 215 - 4, NULL, 0);
849 XCopyArea(dpy, tmp, panel->preview, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
850 XCopyArea(dpy, tmp, panel->previewNoText, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
851 XCopyArea(dpy, tmp, panel->previewBack, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
852 XFreePixmap(dpy, tmp);
855 if (elements & (1 << PFOCUSED)) {
856 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
857 colorUpdate |= 1 << FTITLE_COL | 1 << FFBORDER_COL;
859 if (elements & (1 << PUNFOCUSED)) {
860 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
861 colorUpdate |= 1 << UTITLE_COL | 1 << FBORDER_COL;
863 if (elements & (1 << POWNER)) {
864 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
865 colorUpdate |= 1 << OTITLE_COL | 1 << FBORDER_COL;
867 if (elements & (1 << PRESIZEBAR)) {
868 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
869 colorUpdate |= 1 << FBORDER_COL;
871 if (elements & (1 << PMTITLE)) {
872 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
873 colorUpdate |= 1 << MTITLE_COL | 1 << FBORDER_COL;
875 if (elements & (1 << PMITEM)) {
876 WMListItem *item;
877 TextureListItem *titem;
879 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
880 titem = (TextureListItem *) item->clientData;
882 pix = renderMenu(panel, titem->prop,
883 textureOptions[PMITEM].preview.size.width,
884 textureOptions[PMITEM].preview.size.height / 4);
886 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
887 textureOptions[PMITEM].preview.size.width, textureOptions[PMITEM].preview.size.height,
888 textureOptions[PMITEM].preview.pos.x, textureOptions[PMITEM].preview.pos.y);
890 XCopyArea(dpy, pix, panel->previewNoText, gc, 0, 0,
891 textureOptions[PMITEM].preview.size.width, textureOptions[PMITEM].preview.size.height,
892 textureOptions[PMITEM].preview.pos.x, textureOptions[PMITEM].preview.pos.y);
894 XFreePixmap(dpy, pix);
896 colorUpdate |= 1 << MITEM_COL | 1 << MDISAB_COL |
897 1 << MHIGH_COL | 1 << MHIGHT_COL |
898 1 << FBORDER_COL;
900 if (elements & (1 << PICON)) {
901 WMListItem *item;
902 TextureListItem *titem;
904 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
905 titem = (TextureListItem *) item->clientData;
907 renderPreview(panel, gc, PICON, titem->ispixmap ? 0 : RBEV_RAISED3);
910 if (colorUpdate)
911 updateColorPreviewBox(panel, colorUpdate);
912 else
913 WMRedisplayWidget(panel->prevL);
915 XFreeGC(dpy, gc);
918 static void cancelNewTexture(void *data)
920 _Panel *panel = (_Panel *) data;
922 HideTexturePanel(panel->texturePanel);
925 static char *makeFileName(const char *prefix)
927 char *fname;
929 fname = wstrdup(prefix);
931 while (access(fname, F_OK) == 0) {
932 char buf[30];
934 wfree(fname);
935 sprintf(buf, "%08lx.cache", time(NULL));
936 fname = wstrconcat(prefix, buf);
939 return fname;
942 static void okNewTexture(void *data)
944 _Panel *panel = (_Panel *) data;
945 WMListItem *item;
946 char *name;
947 char *str;
948 WMPropList *prop;
949 TextureListItem *titem;
950 WMScreen *scr = WMWidgetScreen(panel->parent);
952 titem = wmalloc(sizeof(TextureListItem));
954 HideTexturePanel(panel->texturePanel);
956 name = GetTexturePanelTextureName(panel->texturePanel);
958 prop = GetTexturePanelTexture(panel->texturePanel);
960 str = WMGetPropListDescription(prop, False);
962 titem->title = name;
963 titem->prop = prop;
964 titem->texture = str;
965 titem->selectedFor = 0;
967 titem->ispixmap = isPixmap(prop);
969 titem->path = makeFileName(panel->fprefix);
970 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
972 item = WMAddListItem(panel->texLs, "");
973 item->clientData = titem;
975 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
978 static void okEditTexture(void *data)
980 _Panel *panel = (_Panel *) data;
981 WMListItem *item;
982 char *name;
983 char *str;
984 WMPropList *prop;
985 TextureListItem *titem;
987 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
988 titem = (TextureListItem *) item->clientData;
990 HideTexturePanel(panel->texturePanel);
992 if (titem->current) {
993 name = GetTexturePanelTextureName(panel->texturePanel);
995 wfree(titem->title);
996 titem->title = name;
999 prop = GetTexturePanelTexture(panel->texturePanel);
1001 str = WMGetPropListDescription(prop, False);
1003 WMReleasePropList(titem->prop);
1004 titem->prop = prop;
1006 titem->ispixmap = isPixmap(prop);
1008 wfree(titem->texture);
1009 titem->texture = str;
1011 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
1012 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
1013 TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
1015 WMRedisplayWidget(panel->texLs);
1017 if (titem->selectedFor) {
1018 if (titem->selectedFor & (1 << PBACKGROUND))
1019 updatePreviewBox(panel, EVERYTHING);
1020 else
1021 updatePreviewBox(panel, titem->selectedFor);
1024 changePage(panel->secP, panel);
1027 static void editTexture(WMWidget * w, void *data)
1029 _Panel *panel = (_Panel *) data;
1030 WMListItem *item;
1031 TextureListItem *titem;
1033 /* Parameter not used, but tell the compiler that it is ok */
1034 (void) w;
1036 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
1037 titem = (TextureListItem *) item->clientData;
1039 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
1041 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
1043 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1044 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
1046 ShowTexturePanel(panel->texturePanel);
1049 static void newTexture(WMWidget * w, void *data)
1051 _Panel *panel = (_Panel *) data;
1053 /* Parameter not used, but tell the compiler that it is ok */
1054 (void) w;
1056 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
1058 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1060 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1062 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1064 ShowTexturePanel(panel->texturePanel);
1067 static void deleteTexture(WMWidget * w, void *data)
1069 _Panel *panel = (_Panel *) data;
1070 WMListItem *item;
1071 TextureListItem *titem;
1072 int row;
1073 int section;
1075 /* Parameter not used, but tell the compiler that it is ok */
1076 (void) w;
1078 section = WMGetPopUpButtonSelectedItem(panel->secP);
1079 if (section < 0)
1080 return;
1081 row = WMGetListSelectedItemRow(panel->texLs);
1082 item = WMGetListItem(panel->texLs, row);
1083 titem = (TextureListItem *) item->clientData;
1085 if (titem->selectedFor & (1 << section)) {
1086 TextureListItem *titem2;
1088 panel->textureIndex[section] = section;
1089 item = WMGetListItem(panel->texLs, section);
1090 titem2 = (TextureListItem *) item->clientData;
1091 titem2->selectedFor |= 1 << section;
1094 wfree(titem->title);
1095 wfree(titem->texture);
1096 WMReleasePropList(titem->prop);
1097 if (titem->path) {
1098 if (remove(titem->path) < 0 && errno != ENOENT) {
1099 werror(_("could not remove file %s"), titem->path);
1101 wfree(titem->path);
1104 wfree(titem);
1106 WMRemoveListItem(panel->texLs, row);
1107 WMSetButtonEnabled(panel->delB, False);
1110 static void extractTexture(WMWidget * w, void *data)
1112 _Panel *panel = (_Panel *) data;
1113 char *path;
1114 WMOpenPanel *opanel;
1115 WMScreen *scr = WMWidgetScreen(w);
1117 opanel = WMGetOpenPanel(scr);
1118 WMSetFilePanelCanChooseDirectories(opanel, False);
1119 WMSetFilePanelCanChooseFiles(opanel, True);
1121 if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(), _("Select File"), NULL)) {
1122 path = WMGetFilePanelFileName(opanel);
1124 OpenExtractPanelFor(panel);
1126 wfree(path);
1130 static void changePage(WMWidget * w, void *data)
1132 _Panel *panel = (_Panel *) data;
1133 int section;
1134 WMScreen *scr = WMWidgetScreen(panel->box);
1135 RContext *rc = WMScreenRContext(scr);
1137 if (w) {
1138 section = WMGetPopUpButtonSelectedItem(panel->secP);
1139 if (section < 0)
1140 return;
1142 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1144 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1147 GC gc;
1149 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1150 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1151 textureOptions[panel->oldsection].hand.x, textureOptions[panel->oldsection].hand.y, 22, 22,
1152 textureOptions[panel->oldsection].hand.x, textureOptions[panel->oldsection].hand.y);
1154 if (w) {
1155 panel->oldsection = section;
1156 WMDrawPixmap(panel->hand, panel->preview, textureOptions[section].hand.x, textureOptions[section].hand.y);
1158 WMRedisplayWidget(panel->prevL);
1161 static void previewClick(XEvent * event, void *clientData)
1163 _Panel *panel = (_Panel *) clientData;
1164 int i;
1166 switch (panel->oldTabItem) {
1167 case 0:
1168 for (i = 0; i < wlengthof(textureOptions); i++) {
1169 if (event->xbutton.x >= textureOptions[i].preview.pos.x &&
1170 event->xbutton.y >= textureOptions[i].preview.pos.y &&
1171 event->xbutton.x < textureOptions[i].preview.pos.x + textureOptions[i].preview.size.width &&
1172 event->xbutton.y < textureOptions[i].preview.pos.y + textureOptions[i].preview.size.height) {
1174 WMSetPopUpButtonSelectedItem(panel->secP, i);
1175 changePage(panel->secP, panel);
1176 return;
1179 break;
1180 case 1:
1181 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1182 if (event->xbutton.x >= colorOptions[i].preview.pos.x &&
1183 event->xbutton.y >= colorOptions[i].preview.pos.y &&
1184 event->xbutton.x < colorOptions[i].preview.pos.x + colorOptions[i].preview.size.width &&
1185 event->xbutton.y < colorOptions[i].preview.pos.y + colorOptions[i].preview.size.height) {
1188 * yuck kluge: the entry #7 is HighlightTextColor which does not have actually a
1189 * display area, but are reused to make the last "Normal Item" menu entry actually
1190 * pick the same color item as the other similar item displayed, which corresponds
1191 * to MenuTextColor
1193 if (i == 7)
1194 i = 4;
1196 WMSetPopUpButtonSelectedItem(panel->colP, i);
1197 changeColorPage(panel->colP, panel);
1198 return;
1201 break;
1205 static void textureClick(WMWidget * w, void *data)
1207 _Panel *panel = (_Panel *) data;
1208 int i;
1209 WMListItem *item;
1210 TextureListItem *titem;
1212 /* Parameter not used, but tell the compiler that it is ok */
1213 (void) w;
1215 i = WMGetListSelectedItemRow(panel->texLs);
1217 item = WMGetListItem(panel->texLs, i);
1219 titem = (TextureListItem *) item->clientData;
1221 if (titem->current) {
1222 WMSetButtonEnabled(panel->delB, False);
1223 } else {
1224 WMSetButtonEnabled(panel->delB, True);
1228 static void textureDoubleClick(WMWidget * w, void *data)
1230 _Panel *panel = (_Panel *) data;
1231 int i, section;
1232 WMListItem *item;
1233 TextureListItem *titem;
1235 /* Parameter not used, but tell the compiler that it is ok */
1236 (void) w;
1238 /* unselect old texture */
1239 section = WMGetPopUpButtonSelectedItem(panel->secP);
1240 if (section < 0)
1241 return;
1243 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1244 titem = (TextureListItem *) item->clientData;
1245 titem->selectedFor &= ~(1 << section);
1247 /* select new texture */
1248 i = WMGetListSelectedItemRow(panel->texLs);
1250 item = WMGetListItem(panel->texLs, i);
1252 titem = (TextureListItem *) item->clientData;
1254 titem->selectedFor |= 1 << section;
1256 panel->textureIndex[section] = i;
1258 WMRedisplayWidget(panel->texLs);
1260 if (section == PBACKGROUND)
1261 updatePreviewBox(panel, EVERYTHING);
1262 else
1263 updatePreviewBox(panel, 1 << section);
1266 static void paintListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
1268 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
1269 WMScreen *scr = WMWidgetScreen(lPtr);
1270 int width, height, x, y, tmp;
1271 Display *dpy = WMScreenDisplay(scr);
1272 WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
1273 WMListItem *item;
1274 WMColor *black = WMBlackColor(scr);
1275 TextureListItem *titem;
1277 /* Parameter not used, but tell the compiler that it is ok */
1278 (void) text;
1280 item = WMGetListItem(lPtr, index);
1281 titem = (TextureListItem *) item->clientData;
1282 if (!titem) {
1283 WMReleaseColor(back);
1284 WMReleaseColor(black);
1285 return;
1288 width = rect->size.width;
1289 height = rect->size.height;
1290 x = rect->pos.x;
1291 y = rect->pos.y;
1293 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
1295 if (titem->preview)
1296 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1297 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1299 tmp = WMGetPopUpButtonSelectedItem(panel->secP);
1300 if ((tmp >= 0) && ((1 << tmp) & titem->selectedFor))
1301 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1302 else if (titem->selectedFor)
1303 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1305 WMDrawString(scr, d, black, panel->boldFont,
1306 x + TEXPREV_WIDTH + 22, y + 2, titem->title, strlen(titem->title));
1308 WMDrawString(scr, d, black, panel->smallFont,
1309 x + TEXPREV_WIDTH + 14, y + 18, titem->texture, strlen(titem->texture));
1311 WMReleaseColor(back);
1312 WMReleaseColor(black);
1315 static Pixmap loadRImage(WMScreen * scr, const char *path)
1317 FILE *f;
1318 RImage *image;
1319 int w, h, d, cnt;
1320 size_t read_size;
1321 Pixmap pixmap;
1323 f = fopen(path, "rb");
1324 if (!f)
1325 return None;
1327 cnt = fscanf(f, "%02x%02x%1x", &w, &h, &d);
1328 if (cnt != 3) {
1329 wwarning(_("could not read size of image from '%s', ignoring"), path);
1330 fclose(f);
1331 return None;
1333 if (d < 3 || d > 4) {
1334 wwarning(_("image \"%s\" has an invalid depth of %d, ignoring"), path, d);
1335 fclose(f);
1336 return None;
1338 image = RCreateImage(w, h, d == 4);
1339 if (image == NULL) {
1340 wwarning(_("could not create RImage for \"%s\": %s"),
1341 path, RMessageForError(RErrorCode));
1342 fclose(f);
1343 return None;
1345 read_size = w * h * d;
1346 if (fread(image->data, 1, read_size, f) == read_size)
1347 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1348 else
1349 pixmap = None;
1351 fclose(f);
1353 RReleaseImage(image);
1355 return pixmap;
1358 static void fillTextureList(WMList * lPtr)
1360 WMPropList *textureList;
1361 WMPropList *texture;
1362 WMUserDefaults *udb = WMGetStandardUserDefaults();
1363 TextureListItem *titem;
1364 WMScreen *scr = WMWidgetScreen(lPtr);
1365 int i;
1367 textureList = WMGetUDObjectForKey(udb, "TextureList");
1368 if (!textureList)
1369 return;
1371 for (i = 0; i < WMGetPropListItemCount(textureList); i++) {
1372 WMListItem *item;
1374 texture = WMGetFromPLArray(textureList, i);
1376 titem = wmalloc(sizeof(TextureListItem));
1378 titem->title = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 0)));
1379 titem->prop = WMRetainPropList(WMGetFromPLArray(texture, 1));
1380 titem->texture = WMGetPropListDescription(titem->prop, False);
1381 titem->selectedFor = 0;
1382 titem->path = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
1384 titem->preview = loadRImage(scr, titem->path);
1385 if (!titem->preview) {
1386 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1388 item = WMAddListItem(lPtr, "");
1389 item->clientData = titem;
1393 static void fillColorList(_Panel * panel)
1395 WMColor *color;
1396 WMPropList *list;
1397 WMUserDefaults *udb = WMGetStandardUserDefaults();
1398 WMScreen *scr = WMWidgetScreen(panel->box);
1399 int i;
1401 list = WMGetUDObjectForKey(udb, "ColorList");
1402 if (!list) {
1403 for (i = 0; i < wlengthof(sample_colors); i++) {
1404 color = WMCreateNamedColor(scr, sample_colors[i], False);
1405 if (!color)
1406 continue;
1407 WMSetColorWellColor(panel->sampW[i], color);
1408 WMReleaseColor(color);
1410 } else {
1411 WMPropList *c;
1413 for (i = 0; i < WMIN(wlengthof(sample_colors), WMGetPropListItemCount(list)); i++) {
1414 c = WMGetFromPLArray(list, i);
1415 if (!c || !WMIsPLString(c))
1416 continue;
1417 color = WMCreateNamedColor(scr, WMGetFromPLString(c), False);
1418 if (!color)
1419 continue;
1420 WMSetColorWellColor(panel->sampW[i], color);
1421 WMReleaseColor(color);
1426 /*************************************************************************/
1428 static void changeColorPage(WMWidget * w, void *data)
1430 _Panel *panel = (_Panel *) data;
1431 int section;
1432 WMScreen *scr = WMWidgetScreen(panel->box);
1433 RContext *rc = WMScreenRContext(scr);
1435 section = WMGetPopUpButtonSelectedItem(panel->colP);
1436 if (section < 0)
1437 return;
1439 if (panel->preview) {
1440 GC gc;
1442 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1443 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1444 colorOptions[panel->oldcsection].hand.x,
1445 colorOptions[panel->oldcsection].hand.y, 22, 22 ,
1446 colorOptions[panel->oldcsection].hand.x,
1447 colorOptions[panel->oldcsection].hand.y);
1449 if (w) {
1451 panel->oldcsection = section;
1452 if (panel->preview)
1453 WMDrawPixmap(panel->hand, panel->preview,
1454 colorOptions[section].hand.x, colorOptions[section].hand.y);
1456 if (section >= ICONT_COL)
1457 updateColorPreviewBox(panel, 1 << section);
1459 WMSetColorWellColor(panel->colW, panel->colors[section]);
1461 WMRedisplayWidget(panel->prevL);
1464 static void
1465 paintText(WMScreen * scr, Drawable d, WMColor * color, WMFont * font,
1466 int x, int y, int w, int h, WMAlignment align, char *text)
1468 int l = strlen(text);
1470 switch (align) {
1471 case WALeft:
1472 x += 5;
1473 break;
1474 case WARight:
1475 x += w - 5 - WMWidthOfString(font, text, l);
1476 break;
1477 default:
1478 case WACenter:
1479 x += (w - WMWidthOfString(font, text, l)) / 2;
1480 break;
1482 WMDrawString(scr, d, color, font, x, y + (h - WMFontHeight(font)) / 2, text, l);
1485 static void updateColorPreviewBox(_Panel * panel, int elements)
1487 WMScreen *scr = WMWidgetScreen(panel->box);
1488 Display *dpy = WMScreenDisplay(scr);
1489 Pixmap d, pnot;
1490 GC gc;
1492 d = panel->preview;
1493 pnot = panel->previewNoText;
1494 gc = WMColorGC(panel->colors[FTITLE_COL]);
1496 if (elements & (1 << FTITLE_COL)) {
1497 XCopyArea(dpy, pnot, d, gc, 30, 10, 190, 20, 30, 10);
1498 paintText(scr, d, panel->colors[FTITLE_COL],
1499 panel->boldFont, 30, 10, 190, 20,
1500 panel->titleAlignment, _("Focused Window"));
1502 if (elements & (1 << UTITLE_COL)) {
1503 XCopyArea(dpy, pnot, d, gc, 30, 40, 190, 20, 30, 40);
1504 paintText(scr, d, panel->colors[UTITLE_COL],
1505 panel->boldFont, 30, 40, 190, 20,
1506 panel->titleAlignment,
1507 _("Unfocused Window"));
1509 if (elements & (1 << OTITLE_COL)) {
1510 XCopyArea(dpy, pnot, d, gc, 30, 70, 190, 20, 30, 70);
1511 paintText(scr, d, panel->colors[OTITLE_COL],
1512 panel->boldFont, 30, 70, 190, 20,
1513 panel->titleAlignment,
1514 _("Owner of Focused Window"));
1516 if (elements & (1 << MTITLE_COL)) {
1517 XCopyArea(dpy, pnot, d, gc, 30, 120, 90, 20, 30, 120);
1518 paintText(scr, d, panel->colors[MTITLE_COL],
1519 panel->boldFont, 30, 120, 90, 20, WALeft,
1520 _("Menu Title"));
1522 if (elements & (1 << MITEM_COL)) {
1523 XCopyArea(dpy, pnot, d, gc, 30, 140, 90, 20, 30, 140);
1524 paintText(scr, d, panel->colors[MITEM_COL],
1525 panel->normalFont, 30, 140, 90, 20, WALeft,
1526 _("Normal Item"));
1527 XCopyArea(dpy, pnot, d, gc, 30, 200, 90, 20, 30, 200);
1528 paintText(scr, d, panel->colors[MITEM_COL],
1529 panel->normalFont, 30, 200, 90, 20, WALeft,
1530 _("Normal Item"));
1532 if (elements & (1 << MDISAB_COL)) {
1533 XCopyArea(dpy, pnot, d, gc, 30, 160, 90, 20, 30, 160);
1534 paintText(scr, d, panel->colors[MDISAB_COL],
1535 panel->normalFont, 30, 160, 90, 20, WALeft,
1536 _("Disabled Item"));
1538 if (elements & (1 << MHIGH_COL)) {
1539 XFillRectangle(WMScreenDisplay(scr), d,
1540 WMColorGC(panel->colors[MHIGH_COL]),
1541 31, 181, 87, 17);
1542 XFillRectangle(WMScreenDisplay(scr), pnot,
1543 WMColorGC(panel->colors[MHIGH_COL]),
1544 31, 181, 87, 17);
1545 elements |= 1 << MHIGHT_COL;
1547 if (elements & (1 << MHIGHT_COL)) {
1548 XCopyArea(dpy, pnot, d, gc, 30, 180, 90, 20, 30, 180);
1549 paintText(scr, d, panel->colors[MHIGHT_COL],
1550 panel->normalFont, 30, 180, 90, 20, WALeft,
1551 _("Highlighted"));
1553 if (elements & (1 << FBORDER_COL)) {
1554 XDrawRectangle(dpy, pnot,
1555 WMColorGC(panel->colors[FBORDER_COL]),
1556 29, 39, 190, 20);
1557 XDrawRectangle(dpy, d,
1558 WMColorGC(panel->colors[FBORDER_COL]),
1559 29, 39, 190, 20);
1560 XDrawRectangle(dpy, pnot,
1561 WMColorGC(panel->colors[FBORDER_COL]),
1562 29, 69, 190, 20);
1563 XDrawRectangle(dpy, d,
1564 WMColorGC(panel->colors[FBORDER_COL]),
1565 29, 69, 190, 20);
1566 XDrawLine(dpy, pnot,
1567 WMColorGC(panel->colors[FBORDER_COL]),
1568 30, 100, 30, 109);
1569 XDrawLine(dpy, d,
1570 WMColorGC(panel->colors[FBORDER_COL]),
1571 30, 100, 30, 109);
1572 XDrawLine(dpy, pnot,
1573 WMColorGC(panel->colors[FBORDER_COL]),
1574 31, 109, 219, 109);
1575 XDrawLine(dpy, d,
1576 WMColorGC(panel->colors[FBORDER_COL]),
1577 31, 109, 219, 109);
1578 XDrawLine(dpy, pnot,
1579 WMColorGC(panel->colors[FBORDER_COL]),
1580 220, 100, 220, 109);
1581 XDrawLine(dpy, d,
1582 WMColorGC(panel->colors[FBORDER_COL]),
1583 220, 100, 220, 109);
1584 XDrawLine(dpy, pnot,
1585 WMColorGC(panel->colors[FBORDER_COL]),
1586 29, 120, 29, 220);
1587 XDrawLine(dpy, d,
1588 WMColorGC(panel->colors[FBORDER_COL]),
1589 29, 120, 29, 220);
1590 XDrawLine(dpy, pnot,
1591 WMColorGC(panel->colors[FBORDER_COL]),
1592 29, 119, 119, 119);
1593 XDrawLine(dpy, d,
1594 WMColorGC(panel->colors[FBORDER_COL]),
1595 29, 119, 119, 119);
1596 XDrawLine(dpy, pnot,
1597 WMColorGC(panel->colors[FBORDER_COL]),
1598 119, 120, 119, 220);
1599 XDrawLine(dpy, d,
1600 WMColorGC(panel->colors[FBORDER_COL]),
1601 119, 120, 119, 220);
1604 if (elements & (1 << FFBORDER_COL)) {
1605 XDrawRectangle(dpy, pnot,
1606 WMColorGC(panel->colors[FFBORDER_COL]),
1607 29, 9, 190, 20);
1608 XDrawRectangle(dpy, d,
1609 WMColorGC(panel->colors[FFBORDER_COL]),
1610 29, 9, 190, 20);
1613 if (elements & (1 << ICONT_COL) || elements & (1 << ICONB_COL)) {
1614 RColor rgb;
1615 RHSVColor hsv, hsv2;
1616 int v;
1617 WMColor *light, *dim;
1619 updatePreviewBox(panel, 1 << PICON);
1621 rgb.red = WMRedComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1622 rgb.green = WMGreenComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1623 rgb.blue = WMBlueComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1624 RRGBtoHSV(&rgb, &hsv);
1625 RHSVtoRGB(&hsv, &rgb);
1626 hsv2 = hsv;
1628 v = hsv.value * 16 / 10;
1629 hsv.value = (v > 255 ? 255 : v);
1630 RHSVtoRGB(&hsv, &rgb);
1631 light = WMCreateRGBColor(scr, rgb.red << 8, rgb.green << 8, rgb.blue << 8, False);
1633 hsv2.value = hsv2.value / 2;
1634 RHSVtoRGB(&hsv2, &rgb);
1635 dim = WMCreateRGBColor(scr, rgb.red << 8, rgb.green << 8, rgb.blue << 8, False);
1637 XFillRectangle(dpy, d, WMColorGC(panel->colors[ICONB_COL]), 156, 131, 62, 11);
1638 XDrawLine(dpy, d, WMColorGC(light), 155, 130, 155, 142);
1639 XDrawLine(dpy, d, WMColorGC(light), 156, 130, 217, 130);
1640 XDrawLine(dpy, d, WMColorGC(dim), 218, 130, 218, 142);
1642 paintText(scr, d, panel->colors[ICONT_COL],
1643 panel->smallFont, 155, 130, 64, 13, WALeft,
1644 _("Icon Text"));
1646 WMReleaseColor(light);
1647 WMReleaseColor(dim);
1650 if (elements & (1 << CLIP_COL) || elements & (1 << CCLIP_COL)) {
1651 Pixmap pix;
1652 RColor black;
1653 RColor dark;
1654 RColor light;
1655 RImage *tile;
1656 TextureListItem *titem;
1657 WMListItem *item;
1658 XPoint p[4];
1660 item = WMGetListItem(panel->texLs, panel->textureIndex[PICON]);
1661 titem = (TextureListItem *) item->clientData;
1663 pix = renderTexture(scr, titem->prop, 64, 64, NULL, titem->ispixmap ? 0 : RBEV_RAISED3);
1664 tile = RCreateImageFromDrawable(WMScreenRContext(scr), pix, None);
1666 black.alpha = 255;
1667 black.red = black.green = black.blue = 0;
1669 dark.alpha = 0;
1670 dark.red = dark.green = dark.blue = 60;
1672 light.alpha = 0;
1673 light.red = light.green = light.blue = 80;
1675 /* top right */
1676 ROperateLine(tile, RSubtractOperation, 64 - 1 - 23, 0, 64 - 2, 23 - 1, &dark);
1677 RDrawLine(tile, 64 - 1 - 23 - 1, 0, 64 - 1, 23 + 1, &black);
1678 ROperateLine(tile, RAddOperation, 64 - 1 - 23, 2, 64 - 3, 23, &light);
1680 /* arrow bevel */
1681 ROperateLine(tile, RSubtractOperation, 64 - 7 - (23 - 15), 4, 64 - 5, 4, &dark);
1682 ROperateLine(tile, RSubtractOperation, 64 - 6 - (23 - 15), 5, 64 - 5, 6 + 23 - 15, &dark);
1683 ROperateLine(tile, RAddOperation, 64 - 5, 4, 64 - 5, 6 + 23 - 15, &light);
1685 /* bottom left */
1686 ROperateLine(tile, RAddOperation, 2, 64 - 1 - 23 + 2, 23 - 2, 64 - 3, &dark);
1687 RDrawLine(tile, 0, 64 - 1 - 23 - 1, 23 + 1, 64 - 1, &black);
1688 ROperateLine(tile, RSubtractOperation, 0, 64 - 1 - 23 - 2, 23 + 1, 64 - 2, &light);
1690 /* arrow bevel */
1691 ROperateLine(tile, RSubtractOperation, 4, 64 - 7 - (23 - 15), 4, 64 - 5, &dark);
1692 ROperateLine(tile, RSubtractOperation, 5, 64 - 6 - (23 - 15), 6 + 23 - 15, 64 - 5, &dark);
1693 ROperateLine(tile, RAddOperation, 4, 64 - 5, 6 + 23 - 15, 64 - 5, &light);
1695 RConvertImage(WMScreenRContext(scr), tile, &pix);
1696 RReleaseImage(tile);
1698 XCopyArea(dpy, pix, d, gc, 0, 0, 64, 64, 155, 130);
1699 XFreePixmap(dpy, pix);
1701 /* top right arrow */
1702 p[0].x = p[3].x = 155 + 64 - 5 - (23 - 15);
1703 p[0].y = p[3].y = 130 + 5;
1704 p[1].x = 155 + 64 - 6;
1705 p[1].y = 130 + 5;
1706 p[2].x = 155 + 64 - 6;
1707 p[2].y = 130 + 4 + 23 - 15;
1709 XFillPolygon(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 3, Convex, CoordModeOrigin);
1710 XDrawLines(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 4, CoordModeOrigin);
1712 /* bottom left arrow */
1713 p[0].x = p[3].x = 155 + 5;
1714 p[0].y = p[3].y = 130 + 64 - 5 - (23 - 15);
1715 p[1].x = 155 + 5;
1716 p[1].y = 130 + 64 - 6;
1717 p[2].x = 155 + 4 + 23 - 15;
1718 p[2].y = 130 + 64 - 6;
1720 XFillPolygon(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 3, Convex, CoordModeOrigin);
1721 XDrawLines(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 4, CoordModeOrigin);
1725 if (elements & (1 << CLIP_COL))
1726 paintText(scr, d, panel->colors[CLIP_COL],
1727 panel->boldFont, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft,
1728 _("Clip"));
1730 if (elements & (1 << CCLIP_COL)) {
1731 paintText(scr, d, panel->colors[CCLIP_COL],
1732 panel->boldFont, 155+2, 130 + 2, 26, 15, WALeft, _("Coll."));
1733 paintText(scr, d, panel->colors[CCLIP_COL],
1734 panel->boldFont, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft,
1735 _("Clip"));
1738 WMRedisplayWidget(panel->prevL);
1741 static void colorWellObserver(void *self, WMNotification * n)
1743 _Panel *panel = (_Panel *) self;
1744 int p;
1746 /* Parameter not used, but tell the compiler that it is ok */
1747 (void) n;
1749 p = WMGetPopUpButtonSelectedItem(panel->colP);
1750 if (p < 0)
1751 return;
1753 WMReleaseColor(panel->colors[p]);
1755 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1757 updateColorPreviewBox(panel, 1 << p);
1760 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item)
1762 _Panel *panel = self->data;
1763 int i;
1765 /* Parameter not used, but tell the compiler that it is ok */
1766 (void) tabView;
1768 i = WMGetTabViewItemIdentifier(item);
1769 switch (i) {
1770 case TAB_TEXTURE:
1771 switch (panel->oldTabItem) {
1772 case TAB_COLOR:
1773 changeColorPage(NULL, panel);
1774 break;
1776 changePage(panel->secP, panel);
1777 break;
1778 case TAB_COLOR:
1779 switch (panel->oldTabItem) {
1780 case TAB_TEXTURE:
1781 changePage(NULL, panel);
1782 break;
1784 changeColorPage(panel->colP, panel);
1785 break;
1786 case TAB_OPTIONS:
1787 switch (panel->oldTabItem) {
1788 case TAB_TEXTURE:
1789 changePage(NULL, panel);
1790 break;
1791 case TAB_COLOR:
1792 changeColorPage(NULL, panel);
1793 break;
1795 break;
1798 panel->oldTabItem = i;
1801 /*************************************************************************/
1803 static void menuStyleCallback(WMWidget * self, void *data)
1805 _Panel *panel = (_Panel *) data;
1806 menu_style_index i;
1808 for (i = 0; i < wlengthof(menu_style); i++) {
1809 if (self == panel->mstyB[i]) {
1810 panel->menuStyle = i;
1811 break;
1815 updatePreviewBox(panel, 1 << PMITEM);
1818 static void titleAlignCallback(WMWidget * self, void *data)
1820 _Panel *panel = (_Panel *) data;
1821 WMAlignment align;
1823 for (align = 0; align < wlengthof(wintitle_align); align++) {
1824 if (self == panel->taliB[align]) {
1825 panel->titleAlignment = align;
1826 break;
1830 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1833 static void createPanel(Panel * p)
1835 _Panel *panel = (_Panel *) p;
1836 WMFont *font;
1837 WMScreen *scr = WMWidgetScreen(panel->parent);
1838 WMTabViewItem *item;
1839 int i;
1840 char *tmp;
1841 Bool ok = True;
1843 panel->fprefix = wstrconcat(wuserdatapath(), "/" PACKAGE_TARNAME);
1845 if (access(panel->fprefix, F_OK) != 0) {
1846 if (-1 == mkdir(panel->fprefix, 0755) && errno != EEXIST) {
1847 werror("%s", panel->fprefix);
1848 ok = False;
1851 if (ok) {
1852 tmp = wstrconcat(panel->fprefix, "/WPrefs/");
1853 wfree(panel->fprefix);
1854 panel->fprefix = tmp;
1855 if (access(panel->fprefix, F_OK) != 0) {
1856 if (-1 == mkdir(panel->fprefix, 0755) && errno != EEXIST) {
1857 werror("%s", panel->fprefix);
1862 panel->smallFont = WMSystemFontOfSize(scr, 10);
1863 panel->normalFont = WMSystemFontOfSize(scr, 12);
1864 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1866 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1867 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1868 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1870 panel->box = WMCreateBox(panel->parent);
1871 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1873 /* preview box */
1874 panel->prevL = WMCreateLabel(panel->box);
1875 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1876 WMMoveWidget(panel->prevL, 15, 10);
1877 WMSetLabelRelief(panel->prevL, WRSunken);
1878 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1880 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask, previewClick, panel);
1882 /* tabview */
1884 tabviewDelegate.data = panel;
1886 panel->tabv = WMCreateTabView(panel->box);
1887 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1888 WMMoveWidget(panel->tabv, 265, 10);
1889 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1891 /*** texture list ***/
1893 panel->texF = WMCreateFrame(panel->box);
1894 WMSetFrameRelief(panel->texF, WRFlat);
1896 item = WMCreateTabViewItemWithIdentifier(TAB_TEXTURE);
1897 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1898 WMSetTabViewItemLabel(item, _("Texture"));
1900 WMAddItemInTabView(panel->tabv, item);
1902 panel->secP = WMCreatePopUpButton(panel->texF);
1903 WMResizeWidget(panel->secP, 228, 20);
1904 WMMoveWidget(panel->secP, 7, 7);
1906 for (i = 0; i < wlengthof(textureOptions); i++)
1907 WMAddPopUpButtonItem(panel->secP, _(textureOptions[i].popup_label));
1909 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1910 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1912 panel->texLs = WMCreateList(panel->texF);
1913 WMResizeWidget(panel->texLs, 165, 155);
1914 WMMoveWidget(panel->texLs, 70, 33);
1915 WMSetListUserDrawItemHeight(panel->texLs, 35);
1916 WMSetListUserDrawProc(panel->texLs, paintListItem);
1917 WMHangData(panel->texLs, panel);
1918 WMSetListAction(panel->texLs, textureClick, panel);
1919 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1921 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1922 "for the selected item."), WMWidgetView(panel->texLs));
1924 /* command buttons */
1926 font = WMSystemFontOfSize(scr, 10);
1928 panel->newB = WMCreateCommandButton(panel->texF);
1929 WMResizeWidget(panel->newB, 57, 39);
1930 WMMoveWidget(panel->newB, 7, 33);
1931 WMSetButtonFont(panel->newB, font);
1932 WMSetButtonImagePosition(panel->newB, WIPAbove);
1933 WMSetButtonText(panel->newB, _("New"));
1934 WMSetButtonAction(panel->newB, newTexture, panel);
1935 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1937 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel->newB));
1939 panel->ripB = WMCreateCommandButton(panel->texF);
1940 WMResizeWidget(panel->ripB, 57, 39);
1941 WMMoveWidget(panel->ripB, 7, 72);
1942 WMSetButtonFont(panel->ripB, font);
1943 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1944 WMSetButtonText(panel->ripB, _("Extract..."));
1945 WMSetButtonAction(panel->ripB, extractTexture, panel);
1946 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1948 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel->ripB));
1950 WMSetButtonEnabled(panel->ripB, False);
1952 panel->editB = WMCreateCommandButton(panel->texF);
1953 WMResizeWidget(panel->editB, 57, 39);
1954 WMMoveWidget(panel->editB, 7, 111);
1955 WMSetButtonFont(panel->editB, font);
1956 WMSetButtonImagePosition(panel->editB, WIPAbove);
1957 WMSetButtonText(panel->editB, _("Edit"));
1958 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1959 WMSetButtonAction(panel->editB, editTexture, panel);
1960 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel->editB));
1962 panel->delB = WMCreateCommandButton(panel->texF);
1963 WMResizeWidget(panel->delB, 57, 38);
1964 WMMoveWidget(panel->delB, 7, 150);
1965 WMSetButtonFont(panel->delB, font);
1966 WMSetButtonImagePosition(panel->delB, WIPAbove);
1967 WMSetButtonText(panel->delB, _("Delete"));
1968 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1969 WMSetButtonEnabled(panel->delB, False);
1970 WMSetButtonAction(panel->delB, deleteTexture, panel);
1971 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel->delB));
1973 WMReleaseFont(font);
1975 WMMapSubwidgets(panel->texF);
1977 /*** colors ***/
1978 panel->colF = WMCreateFrame(panel->box);
1979 WMSetFrameRelief(panel->colF, WRFlat);
1981 item = WMCreateTabViewItemWithIdentifier(TAB_COLOR);
1982 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1983 WMSetTabViewItemLabel(item, _("Color"));
1985 WMAddItemInTabView(panel->tabv, item);
1987 panel->colP = WMCreatePopUpButton(panel->colF);
1988 WMResizeWidget(panel->colP, 228, 20);
1989 WMMoveWidget(panel->colP, 7, 7);
1991 for (i = 0; i < wlengthof(colorOptions); i++)
1992 WMAddPopUpButtonItem(panel->colP, _(colorOptions[i].label));
1994 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1996 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1998 panel->colW = WMCreateColorWell(panel->colF);
1999 WMResizeWidget(panel->colW, 65, 50);
2000 WMMoveWidget(panel->colW, 30, 75);
2001 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->colW);
2003 { /* Distribute the color samples regularly in the right half */
2004 const int parent_width = 242;
2005 const int parent_height = 195;
2006 const int available_width = (parent_width / 2) - 7;
2007 const int available_height = parent_height - 7 - 20 - 7 - 7;
2008 const int widget_size = 22;
2010 const int nb_x = (int) round(sqrt(wlengthof(sample_colors) * available_width / available_height));
2011 const int nb_y = (wlengthof(sample_colors) + nb_x - 1) / nb_x;
2013 const int offset_x = (parent_width / 2) + (available_width - nb_x * widget_size) / 2;
2014 const int offset_y = (7 + 20 + 7) + (available_height - nb_y * widget_size) / 2;
2016 int x, y;
2018 x = 0; y = 0;
2019 for (i = 0; i < wlengthof(sample_colors); i++) {
2020 panel->sampW[i] = WMCreateColorWell(panel->colF);
2021 WMResizeWidget(panel->sampW[i], widget_size, widget_size);
2022 WMMoveWidget(panel->sampW[i], offset_x + x * widget_size, offset_y + y * widget_size);
2023 WSetColorWellBordered(panel->sampW[i], False);
2024 if (++x >= nb_x) {
2025 y++;
2026 x = 0;
2031 WMMapSubwidgets(panel->colF);
2033 /*** options ***/
2034 panel->optF = WMCreateFrame(panel->box);
2035 WMSetFrameRelief(panel->optF, WRFlat);
2037 item = WMCreateTabViewItemWithIdentifier(TAB_OPTIONS);
2038 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
2039 WMSetTabViewItemLabel(item, _("Options"));
2041 WMAddItemInTabView(panel->tabv, item);
2043 panel->mstyF = WMCreateFrame(panel->optF);
2044 WMResizeWidget(panel->mstyF, 215, 85);
2045 WMMoveWidget(panel->mstyF, 15, 10);
2046 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
2048 for (i = 0; i < wlengthof(menu_style); i++) {
2049 WMPixmap *icon;
2050 char *path;
2052 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
2053 WMResizeWidget(panel->mstyB[i], 54, 54);
2054 WMMoveWidget(panel->mstyB[i], 15 + i * 65, 20);
2055 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
2056 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
2057 path = LocateImage(menu_style[i].file_name);
2058 if (path) {
2059 icon = WMCreatePixmapFromFile(scr, path);
2060 if (icon) {
2061 WMSetButtonImage(panel->mstyB[i], icon);
2062 WMReleasePixmap(icon);
2063 } else {
2064 wwarning(_("could not load icon file %s"), path);
2066 wfree(path);
2069 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
2070 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
2072 WMMapSubwidgets(panel->mstyF);
2074 panel->taliF = WMCreateFrame(panel->optF);
2075 WMResizeWidget(panel->taliF, 110, 80);
2076 WMMoveWidget(panel->taliF, 15, 100);
2077 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
2079 for (i = 0; i < wlengthof(wintitle_align); i++) {
2080 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
2081 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
2082 WMSetButtonText(panel->taliB[i], _(wintitle_align[i].label));
2083 WMResizeWidget(panel->taliB[i], 90, 18);
2084 WMMoveWidget(panel->taliB[i], 10, 15 + 20 * i);
2086 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
2087 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
2089 WMMapSubwidgets(panel->taliF);
2091 WMMapSubwidgets(panel->optF);
2093 /**/ WMRealizeWidget(panel->box);
2094 WMMapSubwidgets(panel->box);
2096 WMSetPopUpButtonSelectedItem(panel->secP, 0);
2098 showData(panel);
2100 changePage(panel->secP, panel);
2102 fillTextureList(panel->texLs);
2104 fillColorList(panel);
2106 panel->texturePanel = CreateTexturePanel(panel->parent);
2109 static void setupTextureFor(WMList *list, const char *key, const char *defValue, const char *title, int index)
2111 WMListItem *item;
2112 TextureListItem *titem;
2114 titem = wmalloc(sizeof(TextureListItem));
2116 titem->title = wstrdup(title);
2117 titem->prop = GetObjectForKey(key);
2118 if (!titem->prop || !WMIsPLArray(titem->prop)) {
2119 /* Maybe also give a error message to stderr that the entry is bad? */
2120 titem->prop = WMCreatePropListFromDescription(defValue);
2121 } else {
2122 WMRetainPropList(titem->prop);
2124 titem->texture = WMGetPropListDescription((WMPropList *) titem->prop, False);
2125 titem->current = 1;
2126 titem->selectedFor = 1 << index;
2128 titem->ispixmap = isPixmap(titem->prop);
2130 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
2132 item = WMAddListItem(list, "");
2133 item->clientData = titem;
2136 static void showData(_Panel * panel)
2138 int i;
2139 const char *str;
2141 str = GetStringForKey("MenuStyle");
2142 panel->menuStyle = MSTYLE_NORMAL;
2143 if (str != NULL) {
2144 for (i = 0; i < wlengthof(menu_style); i++) {
2145 if (strcasecmp(str, menu_style[i].db_value) == 0) {
2146 panel->menuStyle = i;
2147 break;
2152 str = GetStringForKey("TitleJustify");
2153 panel->titleAlignment = WACenter;
2154 if (str != NULL) {
2155 WMAlignment align;
2157 for (align = 0; align < wlengthof(wintitle_align); align++) {
2158 if (strcasecmp(str, wintitle_align[align].db_value) == 0) {
2159 panel->titleAlignment = align;
2160 break;
2165 for (i = 0; i < wlengthof(colorOptions); i++) {
2166 WMColor *color;
2168 str = GetStringForKey(colorOptions[i].key);
2169 if (!str)
2170 str = colorOptions[i].default_value;
2172 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->box), str, False))) {
2173 color = WMCreateNamedColor(WMWidgetScreen(panel->box), "#000000", False);
2176 panel->colors[i] = color;
2178 changeColorPage(panel->colP, panel);
2180 for (i = 0; i < wlengthof(textureOptions); i++) {
2181 setupTextureFor(panel->texLs, textureOptions[i].key,
2182 textureOptions[i].default_value, _(textureOptions[i].texture_label), i);
2183 panel->textureIndex[i] = i;
2185 updatePreviewBox(panel, EVERYTHING);
2187 WMSetButtonSelected(panel->mstyB[panel->menuStyle], True);
2188 WMSetButtonSelected(panel->taliB[panel->titleAlignment], True);
2191 static void storeData(_Panel * panel)
2193 TextureListItem *titem;
2194 WMListItem *item;
2195 int i;
2197 for (i = 0; i < wlengthof(textureOptions); i++) {
2198 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2199 titem = (TextureListItem *) item->clientData;
2200 SetObjectForKey(titem->prop, textureOptions[i].key);
2203 for (i = 0; i < wlengthof(colorOptions); i++) {
2204 char *str;
2206 str = WMGetColorRGBDescription(panel->colors[i]);
2208 if (str) {
2209 SetStringForKey(str, colorOptions[i].key);
2210 wfree(str);
2214 SetStringForKey(menu_style[panel->menuStyle].db_value, "MenuStyle");
2215 SetStringForKey(wintitle_align[panel->titleAlignment].db_value, "TitleJustify");
2218 static void prepareForClose(_Panel * panel)
2220 WMPropList *textureList;
2221 WMPropList *texture;
2222 TextureListItem *titem;
2223 WMListItem *item;
2224 WMUserDefaults *udb = WMGetStandardUserDefaults();
2225 int i;
2227 textureList = WMCreatePLArray(NULL, NULL);
2229 /* store list of textures */
2230 for (i = 8; i < WMGetListNumberOfRows(panel->texLs); i++) {
2231 WMPropList *pl_title, *pl_path;
2233 item = WMGetListItem(panel->texLs, i);
2234 titem = (TextureListItem *) item->clientData;
2236 pl_title = WMCreatePLString(titem->title);
2237 pl_path = WMCreatePLString(titem->path);
2238 texture = WMCreatePLArray(pl_title, titem->prop, pl_path, NULL);
2239 WMReleasePropList(pl_title);
2240 WMReleasePropList(pl_path);
2242 WMAddToPLArray(textureList, texture);
2245 WMSetUDObjectForKey(udb, textureList, "TextureList");
2246 WMReleasePropList(textureList);
2248 /* store list of colors */
2249 textureList = WMCreatePLArray(NULL, NULL);
2250 for (i = 0; i < wlengthof(sample_colors); i++) {
2251 WMColor *color;
2252 char *str;
2253 WMPropList *pl_color;
2255 color = WMGetColorWellColor(panel->sampW[i]);
2257 str = WMGetColorRGBDescription(color);
2258 pl_color = WMCreatePLString(str);
2259 WMAddToPLArray(textureList, pl_color);
2260 WMReleasePropList(pl_color);
2261 wfree(str);
2263 WMSetUDObjectForKey(udb, textureList, "ColorList");
2264 WMReleasePropList(textureList);
2266 WMSynchronizeUserDefaults(udb);
2269 Panel *InitAppearance(WMWidget *parent)
2271 _Panel *panel;
2273 panel = wmalloc(sizeof(_Panel));
2275 panel->sectionName = _("Appearance Preferences");
2277 panel->description = _("Background texture configuration for windows,\n" "menus and icons.");
2279 panel->parent = parent;
2281 panel->callbacks.createWidgets = createPanel;
2282 panel->callbacks.updateDomain = storeData;
2283 panel->callbacks.prepareForClose = prepareForClose;
2285 AddSection(panel, ICON_FILE);
2287 return panel;
2290 /****************************************************************************/
2292 typedef struct ExtractPanel {
2293 WMWindow *win;
2295 WMLabel *label;
2296 WMList *list;
2298 WMButton *closeB;
2299 WMButton *extrB;
2300 } ExtractPanel;
2302 static void OpenExtractPanelFor(_Panel *panel)
2304 ExtractPanel *epanel;
2305 WMColor *color;
2306 WMFont *font;
2307 WMScreen *scr = WMWidgetScreen(panel->parent);
2309 epanel = wmalloc(sizeof(ExtractPanel));
2310 epanel->win = WMCreatePanelWithStyleForWindow(panel->parent, "extract",
2311 WMTitledWindowMask | WMClosableWindowMask);
2312 WMResizeWidget(epanel->win, 245, 250);
2313 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2315 epanel->label = WMCreateLabel(epanel->win);
2316 WMResizeWidget(epanel->label, 225, 18);
2317 WMMoveWidget(epanel->label, 10, 10);
2318 WMSetLabelTextAlignment(epanel->label, WACenter);
2319 WMSetLabelRelief(epanel->label, WRSunken);
2321 color = WMDarkGrayColor(scr);
2322 WMSetWidgetBackgroundColor(epanel->label, color);
2323 WMReleaseColor(color);
2325 color = WMWhiteColor(scr);
2326 WMSetLabelTextColor(epanel->label, color);
2327 WMReleaseColor(color);
2329 font = WMBoldSystemFontOfSize(scr, 12);
2330 WMSetLabelFont(epanel->label, font);
2331 WMReleaseFont(font);
2333 WMSetLabelText(epanel->label, _("Textures"));
2335 epanel->list = WMCreateList(epanel->win);
2336 WMResizeWidget(epanel->list, 225, 165);
2337 WMMoveWidget(epanel->list, 10, 30);
2339 epanel->closeB = WMCreateCommandButton(epanel->win);
2340 WMResizeWidget(epanel->closeB, 74, 24);
2341 WMMoveWidget(epanel->closeB, 165, 215);
2342 WMSetButtonText(epanel->closeB, _("Close"));
2344 epanel->extrB = WMCreateCommandButton(epanel->win);
2345 WMResizeWidget(epanel->extrB, 74, 24);
2346 WMMoveWidget(epanel->extrB, 80, 215);
2347 WMSetButtonText(epanel->extrB, _("Extract"));
2349 WMMapSubwidgets(epanel->win);
2351 /* take textures from file */
2353 WMRealizeWidget(epanel->win);
2355 WMMapWidget(epanel->win);