Added explicit fall-through comments to pacify GCC.
[wmaker-crm.git] / WPrefs.app / Appearance.c
blob909812d219ee4be9ed763d6b99ff8c902a03023a
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 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
451 color->alpha = 255;
452 color->red = xcolor.red >> 8;
453 color->green = xcolor.green >> 8;
454 color->blue = xcolor.blue >> 8;
457 static void dumpRImage(const char *path, RImage * image)
459 FILE *f;
460 int channels = (image->format == RRGBAFormat ? 4 : 3);
462 f = fopen(path, "wb");
463 if (!f) {
464 werror("%s", path);
465 return;
467 fprintf(f, "%02x%02x%1x", image->width, image->height, channels);
469 fwrite(image->data, 1, image->width * image->height * channels, f);
471 fsync(fileno(f));
472 if (fclose(f) < 0) {
473 werror("%s", path);
477 static int isPixmap(WMPropList * prop)
479 WMPropList *p;
480 char *s;
482 p = WMGetFromPLArray(prop, 0);
483 s = WMGetFromPLString(p);
484 if (strcasecmp(&s[1], "pixmap") == 0)
485 return 1;
486 else
487 return 0;
490 /**********************************************************************/
492 static void drawResizebarBevel(RImage * img)
494 RColor light;
495 RColor dark;
496 int width = img->width;
497 int height = img->height;
498 int cwidth = 28;
500 light.alpha = 0;
501 light.red = light.green = light.blue = 80;
503 dark.alpha = 0;
504 dark.red = dark.green = dark.blue = 40;
506 ROperateLine(img, RSubtractOperation, 0, 0, width - 1, 0, &dark);
507 ROperateLine(img, RAddOperation, 0, 1, width - 1, 1, &light);
509 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height - 1, &dark);
510 ROperateLine(img, RAddOperation, cwidth + 1, 2, cwidth + 1, height - 1, &light);
512 ROperateLine(img, RSubtractOperation, width - cwidth - 2, 2, width - cwidth - 2, height - 1, &dark);
513 ROperateLine(img, RAddOperation, width - cwidth - 1, 2, width - cwidth - 1, height - 1, &light);
517 static void drawMenuBevel(RImage * img)
519 RColor light, dark, mid;
520 int i;
521 int iheight = img->height / 4;
523 light.alpha = 0;
524 light.red = light.green = light.blue = 80;
526 dark.alpha = 255;
527 dark.red = dark.green = dark.blue = 0;
529 mid.alpha = 0;
530 mid.red = mid.green = mid.blue = 40;
532 for (i = 1; i < 4; i++) {
533 ROperateLine(img, RSubtractOperation, 0, i * iheight - 2, img->width - 1, i * iheight - 2, &mid);
535 RDrawLine(img, 0, i * iheight - 1, img->width - 1, i * iheight - 1, &dark);
537 ROperateLine(img, RAddOperation, 1, i * iheight, img->width - 2, i * iheight, &light);
541 static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int height, const char *path, int border)
543 char *type;
544 RImage *image = NULL;
545 RImage *timage = NULL;
546 Pixmap pixmap;
547 RContext *rc = WMScreenRContext(scr);
548 char *str;
549 RColor rcolor;
551 type = WMGetFromPLString(WMGetFromPLArray(texture, 0));
553 if (strcasecmp(&type[1], "pixmap") == 0 ||
554 (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T')) {
555 char *path;
557 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
558 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
559 if (path) {
560 timage = RLoadImage(rc, path, 0);
561 if (!timage)
562 wwarning(_("could not load file '%s': %s"), path, RMessageForError(RErrorCode));
563 wfree(path);
564 } else {
565 wwarning(_("could not find file '%s' for texture type %s"), str, type);
566 timage = NULL;
568 if (!timage) {
569 texture = WMCreatePropListFromDescription("(solid, black)");
570 type = "solid";
574 if (strcasecmp(type, "solid") == 0) {
576 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
578 str2rcolor(rc, str, &rcolor);
580 image = RCreateImage(width, height, False);
581 RClearImage(image, &rcolor);
582 } else if (strcasecmp(type, "igradient") == 0) {
583 int t1, t2;
584 RColor c1[2], c2[2];
586 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
587 str2rcolor(rc, str, &c1[0]);
588 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
589 str2rcolor(rc, str, &c1[1]);
590 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
591 t1 = atoi(str);
593 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
594 str2rcolor(rc, str, &c2[0]);
595 str = WMGetFromPLString(WMGetFromPLArray(texture, 5));
596 str2rcolor(rc, str, &c2[1]);
597 str = WMGetFromPLString(WMGetFromPLArray(texture, 6));
598 t2 = atoi(str);
600 image = RRenderInterwovenGradient(width, height, c1, t1, c2, t2);
601 } else if (strcasecmp(&type[1], "gradient") == 0) {
602 RGradientStyle style;
603 RColor rcolor2;
605 switch (toupper(type[0])) {
606 case 'V':
607 style = RVerticalGradient;
608 break;
609 case 'H':
610 style = RHorizontalGradient;
611 break;
612 default:
613 wwarning(_("unknown direction in '%s', falling back to diagonal"), type);
614 /* FALLTHRU */
615 case 'D':
616 style = RDiagonalGradient;
617 break;
620 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
621 str2rcolor(rc, str, &rcolor);
622 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
623 str2rcolor(rc, str, &rcolor2);
625 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
626 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T') {
627 RGradientStyle style;
628 RColor rcolor2;
629 int i;
630 RImage *grad = NULL;
632 switch (toupper(type[1])) {
633 case 'V':
634 style = RVerticalGradient;
635 break;
636 case 'H':
637 style = RHorizontalGradient;
638 break;
639 default:
640 wwarning(_("unknown direction in '%s', falling back to diagonal"), type);
641 /* FALLTHRU */
642 case 'D':
643 style = RDiagonalGradient;
644 break;
647 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
648 str2rcolor(rc, str, &rcolor);
649 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
650 str2rcolor(rc, str, &rcolor2);
652 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
654 image = RMakeTiledImage(timage, width, height);
655 RReleaseImage(timage);
657 i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
659 RCombineImagesWithOpaqueness(image, grad, i);
660 RReleaseImage(grad);
662 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'M') {
663 RGradientStyle style;
664 RColor **colors;
665 int i, j;
667 switch (toupper(type[1])) {
668 case 'V':
669 style = RVerticalGradient;
670 break;
671 case 'H':
672 style = RHorizontalGradient;
673 break;
674 default:
675 wwarning(_("unknown direction in '%s', falling back to diagonal"), type);
676 /* FALLTHRU */
677 case 'D':
678 style = RDiagonalGradient;
679 break;
682 j = WMGetPropListItemCount(texture);
684 if (j > 0) {
685 colors = wmalloc(j * sizeof(RColor *));
687 for (i = 2; i < j; i++) {
688 str = WMGetFromPLString(WMGetFromPLArray(texture, i));
689 colors[i - 2] = wmalloc(sizeof(RColor));
690 str2rcolor(rc, str, colors[i - 2]);
692 colors[i - 2] = NULL;
694 image = RRenderMultiGradient(width, height, colors, style);
696 for (i = 0; colors[i] != NULL; i++)
697 wfree(colors[i]);
698 wfree(colors);
700 } else if (strcasecmp(&type[1], "pixmap") == 0) {
701 RColor color;
703 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
704 str2rcolor(rc, str, &color);
706 switch (toupper(type[0])) {
707 case 'T':
708 image = RMakeTiledImage(timage, width, height);
709 RReleaseImage(timage);
710 break;
711 case 'C':
712 image = RMakeCenteredImage(timage, width, height, &color);
713 RReleaseImage(timage);
714 break;
715 case 'F':
716 case 'S':
717 case 'M':
718 image = RScaleImage(timage, width, height);
719 RReleaseImage(timage);
720 break;
722 default:
723 wwarning(_("type '%s' is not a supported type for a texture"), type);
724 RReleaseImage(timage);
725 return None;
729 if (!image)
730 return None;
732 if (path) {
733 dumpRImage(path, image);
736 if (border < 0) {
737 if (border == RESIZEBAR_BEVEL) {
738 drawResizebarBevel(image);
739 } else if (border == MENU_BEVEL) {
740 drawMenuBevel(image);
741 RBevelImage(image, RBEV_RAISED2);
743 } else if (border) {
744 RBevelImage(image, border);
747 RConvertImage(rc, image, &pixmap);
748 RReleaseImage(image);
750 return pixmap;
753 static Pixmap renderMenu(_Panel * panel, WMPropList * texture, int width, int iheight)
755 WMScreen *scr = WMWidgetScreen(panel->parent);
756 Display *dpy = WMScreenDisplay(scr);
757 Pixmap pix, tmp;
758 GC gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
759 int i;
761 switch (panel->menuStyle) {
762 case MSTYLE_NORMAL:
763 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
765 pix = XCreatePixmap(dpy, tmp, width, iheight * 4, WMScreenDepth(scr));
766 for (i = 0; i < 4; i++) {
767 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight * i);
769 XFreePixmap(dpy, tmp);
770 break;
771 case MSTYLE_SINGLE:
772 pix = renderTexture(scr, texture, width, iheight * 4, NULL, MENU_BEVEL);
773 break;
774 case MSTYLE_FLAT:
775 pix = renderTexture(scr, texture, width, iheight * 4, NULL, RBEV_RAISED2);
776 break;
777 default:
778 pix = None;
780 XFreeGC(dpy, gc);
782 return pix;
785 static void renderPreview(_Panel * panel, GC gc, int part, int relief)
787 WMListItem *item;
788 TextureListItem *titem;
789 Pixmap pix;
790 WMScreen *scr = WMWidgetScreen(panel->box);
792 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
793 titem = (TextureListItem *) item->clientData;
795 pix = renderTexture(scr, titem->prop,
796 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
797 NULL, relief);
799 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, 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 XCopyArea(WMScreenDisplay(scr), pix, panel->previewNoText, gc, 0, 0,
804 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
805 textureOptions[part].preview.pos.x, textureOptions[part].preview.pos.y);
807 XFreePixmap(WMScreenDisplay(scr), pix);
810 static void updatePreviewBox(_Panel * panel, int elements)
812 WMScreen *scr = WMWidgetScreen(panel->parent);
813 Display *dpy = WMScreenDisplay(scr);
814 Pixmap pix;
815 GC gc;
816 int colorUpdate = 0;
818 gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
820 if (panel->preview == None) {
821 WMPixmap *p;
823 panel->previewNoText = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
824 240 - 4, 215 - 4, WMScreenDepth(scr));
825 panel->previewBack = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
826 240 - 4, 215 - 4, WMScreenDepth(scr));
828 p = WMCreatePixmap(scr, 240 - 4, 215 - 4, WMScreenDepth(scr), False);
829 panel->preview = WMGetPixmapXID(p);
830 WMSetLabelImage(panel->prevL, p);
831 WMReleasePixmap(p);
833 if (elements & (1 << PBACKGROUND)) {
834 Pixmap tmp;
835 TextureListItem *titem;
836 WMListItem *item;
838 item = WMGetListItem(panel->texLs,
839 panel->textureIndex[PBACKGROUND]);
840 titem = (TextureListItem *) item->clientData;
841 tmp = renderTexture(scr, titem->prop, 240 - 4, 215 - 4, NULL, 0);
843 XCopyArea(dpy, tmp, panel->preview, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
844 XCopyArea(dpy, tmp, panel->previewNoText, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
845 XCopyArea(dpy, tmp, panel->previewBack, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
846 XFreePixmap(dpy, tmp);
849 if (elements & (1 << PFOCUSED)) {
850 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
851 colorUpdate |= 1 << FTITLE_COL | 1 << FFBORDER_COL;
853 if (elements & (1 << PUNFOCUSED)) {
854 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
855 colorUpdate |= 1 << UTITLE_COL | 1 << FBORDER_COL;
857 if (elements & (1 << POWNER)) {
858 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
859 colorUpdate |= 1 << OTITLE_COL | 1 << FBORDER_COL;
861 if (elements & (1 << PRESIZEBAR)) {
862 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
863 colorUpdate |= 1 << FBORDER_COL;
865 if (elements & (1 << PMTITLE)) {
866 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
867 colorUpdate |= 1 << MTITLE_COL | 1 << FBORDER_COL;
869 if (elements & (1 << PMITEM)) {
870 WMListItem *item;
871 TextureListItem *titem;
873 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
874 titem = (TextureListItem *) item->clientData;
876 pix = renderMenu(panel, titem->prop,
877 textureOptions[PMITEM].preview.size.width,
878 textureOptions[PMITEM].preview.size.height / 4);
880 XCopyArea(dpy, pix, panel->preview, 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 XCopyArea(dpy, pix, panel->previewNoText, gc, 0, 0,
885 textureOptions[PMITEM].preview.size.width, textureOptions[PMITEM].preview.size.height,
886 textureOptions[PMITEM].preview.pos.x, textureOptions[PMITEM].preview.pos.y);
888 XFreePixmap(dpy, pix);
890 colorUpdate |= 1 << MITEM_COL | 1 << MDISAB_COL |
891 1 << MHIGH_COL | 1 << MHIGHT_COL |
892 1 << FBORDER_COL;
894 if (elements & (1 << PICON)) {
895 WMListItem *item;
896 TextureListItem *titem;
898 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
899 titem = (TextureListItem *) item->clientData;
901 renderPreview(panel, gc, PICON, titem->ispixmap ? 0 : RBEV_RAISED3);
904 if (colorUpdate)
905 updateColorPreviewBox(panel, colorUpdate);
906 else
907 WMRedisplayWidget(panel->prevL);
909 XFreeGC(dpy, gc);
912 static void cancelNewTexture(void *data)
914 _Panel *panel = (_Panel *) data;
916 HideTexturePanel(panel->texturePanel);
919 static char *makeFileName(const char *prefix)
921 char *fname;
923 fname = wstrdup(prefix);
925 while (access(fname, F_OK) == 0) {
926 char buf[30];
928 wfree(fname);
929 sprintf(buf, "%08lx.cache", time(NULL));
930 fname = wstrconcat(prefix, buf);
933 return fname;
936 static void okNewTexture(void *data)
938 _Panel *panel = (_Panel *) data;
939 WMListItem *item;
940 char *name;
941 char *str;
942 WMPropList *prop;
943 TextureListItem *titem;
944 WMScreen *scr = WMWidgetScreen(panel->parent);
946 titem = wmalloc(sizeof(TextureListItem));
948 HideTexturePanel(panel->texturePanel);
950 name = GetTexturePanelTextureName(panel->texturePanel);
952 prop = GetTexturePanelTexture(panel->texturePanel);
954 str = WMGetPropListDescription(prop, False);
956 titem->title = name;
957 titem->prop = prop;
958 titem->texture = str;
959 titem->selectedFor = 0;
961 titem->ispixmap = isPixmap(prop);
963 titem->path = makeFileName(panel->fprefix);
964 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
966 item = WMAddListItem(panel->texLs, "");
967 item->clientData = titem;
969 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
972 static void okEditTexture(void *data)
974 _Panel *panel = (_Panel *) data;
975 WMListItem *item;
976 char *name;
977 char *str;
978 WMPropList *prop;
979 TextureListItem *titem;
981 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
982 titem = (TextureListItem *) item->clientData;
984 HideTexturePanel(panel->texturePanel);
986 if (titem->current) {
987 name = GetTexturePanelTextureName(panel->texturePanel);
989 wfree(titem->title);
990 titem->title = name;
993 prop = GetTexturePanelTexture(panel->texturePanel);
995 str = WMGetPropListDescription(prop, False);
997 WMReleasePropList(titem->prop);
998 titem->prop = prop;
1000 titem->ispixmap = isPixmap(prop);
1002 wfree(titem->texture);
1003 titem->texture = str;
1005 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
1006 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
1007 TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
1009 WMRedisplayWidget(panel->texLs);
1011 if (titem->selectedFor) {
1012 if (titem->selectedFor & (1 << PBACKGROUND))
1013 updatePreviewBox(panel, EVERYTHING);
1014 else
1015 updatePreviewBox(panel, titem->selectedFor);
1018 changePage(panel->secP, panel);
1021 static void editTexture(WMWidget * w, void *data)
1023 _Panel *panel = (_Panel *) data;
1024 WMListItem *item;
1025 TextureListItem *titem;
1027 /* Parameter not used, but tell the compiler that it is ok */
1028 (void) w;
1030 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
1031 titem = (TextureListItem *) item->clientData;
1033 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
1035 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
1037 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1038 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
1040 ShowTexturePanel(panel->texturePanel);
1043 static void newTexture(WMWidget * w, void *data)
1045 _Panel *panel = (_Panel *) data;
1047 /* Parameter not used, but tell the compiler that it is ok */
1048 (void) w;
1050 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
1052 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1054 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1056 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1058 ShowTexturePanel(panel->texturePanel);
1061 static void deleteTexture(WMWidget * w, void *data)
1063 _Panel *panel = (_Panel *) data;
1064 WMListItem *item;
1065 TextureListItem *titem;
1066 int row;
1067 int section;
1069 /* Parameter not used, but tell the compiler that it is ok */
1070 (void) w;
1072 section = WMGetPopUpButtonSelectedItem(panel->secP);
1073 row = WMGetListSelectedItemRow(panel->texLs);
1074 item = WMGetListItem(panel->texLs, row);
1075 titem = (TextureListItem *) item->clientData;
1077 if (titem->selectedFor & (1 << section)) {
1078 TextureListItem *titem2;
1080 panel->textureIndex[section] = section;
1081 item = WMGetListItem(panel->texLs, section);
1082 titem2 = (TextureListItem *) item->clientData;
1083 titem2->selectedFor |= 1 << section;
1086 wfree(titem->title);
1087 wfree(titem->texture);
1088 WMReleasePropList(titem->prop);
1089 if (titem->path) {
1090 if (remove(titem->path) < 0 && errno != ENOENT) {
1091 werror(_("could not remove file %s"), titem->path);
1093 wfree(titem->path);
1096 wfree(titem);
1098 WMRemoveListItem(panel->texLs, row);
1099 WMSetButtonEnabled(panel->delB, False);
1102 static void extractTexture(WMWidget * w, void *data)
1104 _Panel *panel = (_Panel *) data;
1105 char *path;
1106 WMOpenPanel *opanel;
1107 WMScreen *scr = WMWidgetScreen(w);
1109 opanel = WMGetOpenPanel(scr);
1110 WMSetFilePanelCanChooseDirectories(opanel, False);
1111 WMSetFilePanelCanChooseFiles(opanel, True);
1113 if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(), _("Select File"), NULL)) {
1114 path = WMGetFilePanelFileName(opanel);
1116 OpenExtractPanelFor(panel);
1118 wfree(path);
1122 static void changePage(WMWidget * w, void *data)
1124 _Panel *panel = (_Panel *) data;
1125 int section;
1126 WMScreen *scr = WMWidgetScreen(panel->box);
1127 RContext *rc = WMScreenRContext(scr);
1129 if (w) {
1130 section = WMGetPopUpButtonSelectedItem(panel->secP);
1132 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1134 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1137 GC gc;
1139 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1140 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1141 textureOptions[panel->oldsection].hand.x, textureOptions[panel->oldsection].hand.y, 22, 22,
1142 textureOptions[panel->oldsection].hand.x, textureOptions[panel->oldsection].hand.y);
1144 if (w) {
1145 panel->oldsection = section;
1146 WMDrawPixmap(panel->hand, panel->preview, textureOptions[section].hand.x, textureOptions[section].hand.y);
1148 WMRedisplayWidget(panel->prevL);
1151 static void previewClick(XEvent * event, void *clientData)
1153 _Panel *panel = (_Panel *) clientData;
1154 int i;
1156 switch (panel->oldTabItem) {
1157 case 0:
1158 for (i = 0; i < wlengthof(textureOptions); i++) {
1159 if (event->xbutton.x >= textureOptions[i].preview.pos.x &&
1160 event->xbutton.y >= textureOptions[i].preview.pos.y &&
1161 event->xbutton.x < textureOptions[i].preview.pos.x + textureOptions[i].preview.size.width &&
1162 event->xbutton.y < textureOptions[i].preview.pos.y + textureOptions[i].preview.size.height) {
1164 WMSetPopUpButtonSelectedItem(panel->secP, i);
1165 changePage(panel->secP, panel);
1166 return;
1169 break;
1170 case 1:
1171 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1172 if (event->xbutton.x >= colorOptions[i].preview.pos.x &&
1173 event->xbutton.y >= colorOptions[i].preview.pos.y &&
1174 event->xbutton.x < colorOptions[i].preview.pos.x + colorOptions[i].preview.size.width &&
1175 event->xbutton.y < colorOptions[i].preview.pos.y + colorOptions[i].preview.size.height) {
1178 * yuck kluge: the entry #7 is HighlightTextColor which does not have actually a
1179 * display area, but are reused to make the last "Normal Item" menu entry actually
1180 * pick the same color item as the other similar item displayed, which corresponds
1181 * to MenuTextColor
1183 if (i == 7)
1184 i = 4;
1186 WMSetPopUpButtonSelectedItem(panel->colP, i);
1187 changeColorPage(panel->colP, panel);
1188 return;
1191 break;
1195 static void textureClick(WMWidget * w, void *data)
1197 _Panel *panel = (_Panel *) data;
1198 int i;
1199 WMListItem *item;
1200 TextureListItem *titem;
1202 /* Parameter not used, but tell the compiler that it is ok */
1203 (void) w;
1205 i = WMGetListSelectedItemRow(panel->texLs);
1207 item = WMGetListItem(panel->texLs, i);
1209 titem = (TextureListItem *) item->clientData;
1211 if (titem->current) {
1212 WMSetButtonEnabled(panel->delB, False);
1213 } else {
1214 WMSetButtonEnabled(panel->delB, True);
1218 static void textureDoubleClick(WMWidget * w, void *data)
1220 _Panel *panel = (_Panel *) data;
1221 int i, section;
1222 WMListItem *item;
1223 TextureListItem *titem;
1225 /* Parameter not used, but tell the compiler that it is ok */
1226 (void) w;
1228 /* unselect old texture */
1229 section = WMGetPopUpButtonSelectedItem(panel->secP);
1231 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1232 titem = (TextureListItem *) item->clientData;
1233 titem->selectedFor &= ~(1 << section);
1235 /* select new texture */
1236 i = WMGetListSelectedItemRow(panel->texLs);
1238 item = WMGetListItem(panel->texLs, i);
1240 titem = (TextureListItem *) item->clientData;
1242 titem->selectedFor |= 1 << section;
1244 panel->textureIndex[section] = i;
1246 WMRedisplayWidget(panel->texLs);
1248 if (section == PBACKGROUND)
1249 updatePreviewBox(panel, EVERYTHING);
1250 else
1251 updatePreviewBox(panel, 1 << section);
1254 static void paintListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
1256 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
1257 WMScreen *scr = WMWidgetScreen(lPtr);
1258 int width, height, x, y;
1259 Display *dpy = WMScreenDisplay(scr);
1260 WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
1261 WMListItem *item;
1262 WMColor *black = WMBlackColor(scr);
1263 TextureListItem *titem;
1265 /* Parameter not used, but tell the compiler that it is ok */
1266 (void) text;
1268 item = WMGetListItem(lPtr, index);
1269 titem = (TextureListItem *) item->clientData;
1270 if (!titem) {
1271 WMReleaseColor(back);
1272 WMReleaseColor(black);
1273 return;
1276 width = rect->size.width;
1277 height = rect->size.height;
1278 x = rect->pos.x;
1279 y = rect->pos.y;
1281 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
1283 if (titem->preview)
1284 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1285 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1287 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1288 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1289 else if (titem->selectedFor)
1290 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1292 WMDrawString(scr, d, black, panel->boldFont,
1293 x + TEXPREV_WIDTH + 22, y + 2, titem->title, strlen(titem->title));
1295 WMDrawString(scr, d, black, panel->smallFont,
1296 x + TEXPREV_WIDTH + 14, y + 18, titem->texture, strlen(titem->texture));
1298 WMReleaseColor(back);
1299 WMReleaseColor(black);
1302 static Pixmap loadRImage(WMScreen * scr, const char *path)
1304 FILE *f;
1305 RImage *image;
1306 int w, h, d, cnt;
1307 size_t read_size;
1308 Pixmap pixmap;
1310 f = fopen(path, "rb");
1311 if (!f)
1312 return None;
1314 cnt = fscanf(f, "%02x%02x%1x", &w, &h, &d);
1315 if (cnt != 3) {
1316 wwarning(_("could not read size of image from '%s', ignoring"), path);
1317 fclose(f);
1318 return None;
1320 if (d < 3 || d > 4) {
1321 wwarning(_("image \"%s\" has an invalid depth of %d, ignoring"), path, d);
1322 fclose(f);
1323 return None;
1325 image = RCreateImage(w, h, d == 4);
1326 if (image == NULL) {
1327 wwarning(_("could not create RImage for \"%s\": %s"),
1328 path, RMessageForError(RErrorCode));
1329 fclose(f);
1330 return None;
1332 read_size = w * h * d;
1333 if (fread(image->data, 1, read_size, f) == read_size)
1334 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1335 else
1336 pixmap = None;
1338 fclose(f);
1340 RReleaseImage(image);
1342 return pixmap;
1345 static void fillTextureList(WMList * lPtr)
1347 WMPropList *textureList;
1348 WMPropList *texture;
1349 WMUserDefaults *udb = WMGetStandardUserDefaults();
1350 TextureListItem *titem;
1351 WMScreen *scr = WMWidgetScreen(lPtr);
1352 int i;
1354 textureList = WMGetUDObjectForKey(udb, "TextureList");
1355 if (!textureList)
1356 return;
1358 for (i = 0; i < WMGetPropListItemCount(textureList); i++) {
1359 WMListItem *item;
1361 texture = WMGetFromPLArray(textureList, i);
1363 titem = wmalloc(sizeof(TextureListItem));
1365 titem->title = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 0)));
1366 titem->prop = WMRetainPropList(WMGetFromPLArray(texture, 1));
1367 titem->texture = WMGetPropListDescription(titem->prop, False);
1368 titem->selectedFor = 0;
1369 titem->path = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
1371 titem->preview = loadRImage(scr, titem->path);
1372 if (!titem->preview) {
1373 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1375 item = WMAddListItem(lPtr, "");
1376 item->clientData = titem;
1380 static void fillColorList(_Panel * panel)
1382 WMColor *color;
1383 WMPropList *list;
1384 WMUserDefaults *udb = WMGetStandardUserDefaults();
1385 WMScreen *scr = WMWidgetScreen(panel->box);
1386 int i;
1388 list = WMGetUDObjectForKey(udb, "ColorList");
1389 if (!list) {
1390 for (i = 0; i < wlengthof(sample_colors); i++) {
1391 color = WMCreateNamedColor(scr, sample_colors[i], False);
1392 if (!color)
1393 continue;
1394 WMSetColorWellColor(panel->sampW[i], color);
1395 WMReleaseColor(color);
1397 } else {
1398 WMPropList *c;
1400 for (i = 0; i < WMIN(wlengthof(sample_colors), WMGetPropListItemCount(list)); i++) {
1401 c = WMGetFromPLArray(list, i);
1402 if (!c || !WMIsPLString(c))
1403 continue;
1404 color = WMCreateNamedColor(scr, WMGetFromPLString(c), False);
1405 if (!color)
1406 continue;
1407 WMSetColorWellColor(panel->sampW[i], color);
1408 WMReleaseColor(color);
1413 /*************************************************************************/
1415 static void changeColorPage(WMWidget * w, void *data)
1417 _Panel *panel = (_Panel *) data;
1418 int section;
1419 WMScreen *scr = WMWidgetScreen(panel->box);
1420 RContext *rc = WMScreenRContext(scr);
1422 if (panel->preview) {
1423 GC gc;
1425 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1426 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1427 colorOptions[panel->oldcsection].hand.x,
1428 colorOptions[panel->oldcsection].hand.y, 22, 22 ,
1429 colorOptions[panel->oldcsection].hand.x,
1430 colorOptions[panel->oldcsection].hand.y);
1432 if (w) {
1433 section = WMGetPopUpButtonSelectedItem(panel->colP);
1435 panel->oldcsection = section;
1436 if (panel->preview)
1437 WMDrawPixmap(panel->hand, panel->preview,
1438 colorOptions[section].hand.x, colorOptions[section].hand.y);
1440 if (section >= ICONT_COL)
1441 updateColorPreviewBox(panel, 1 << section);
1443 WMSetColorWellColor(panel->colW, panel->colors[section]);
1445 WMRedisplayWidget(panel->prevL);
1448 static void
1449 paintText(WMScreen * scr, Drawable d, WMColor * color, WMFont * font,
1450 int x, int y, int w, int h, WMAlignment align, char *text)
1452 int l = strlen(text);
1454 switch (align) {
1455 case WALeft:
1456 x += 5;
1457 break;
1458 case WARight:
1459 x += w - 5 - WMWidthOfString(font, text, l);
1460 break;
1461 default:
1462 case WACenter:
1463 x += (w - WMWidthOfString(font, text, l)) / 2;
1464 break;
1466 WMDrawString(scr, d, color, font, x, y + (h - WMFontHeight(font)) / 2, text, l);
1469 static void updateColorPreviewBox(_Panel * panel, int elements)
1471 WMScreen *scr = WMWidgetScreen(panel->box);
1472 Display *dpy = WMScreenDisplay(scr);
1473 Pixmap d, pnot;
1474 GC gc;
1476 d = panel->preview;
1477 pnot = panel->previewNoText;
1478 gc = WMColorGC(panel->colors[FTITLE_COL]);
1480 if (elements & (1 << FTITLE_COL)) {
1481 XCopyArea(dpy, pnot, d, gc, 30, 10, 190, 20, 30, 10);
1482 paintText(scr, d, panel->colors[FTITLE_COL],
1483 panel->boldFont, 30, 10, 190, 20,
1484 panel->titleAlignment, _("Focused Window"));
1486 if (elements & (1 << UTITLE_COL)) {
1487 XCopyArea(dpy, pnot, d, gc, 30, 40, 190, 20, 30, 40);
1488 paintText(scr, d, panel->colors[UTITLE_COL],
1489 panel->boldFont, 30, 40, 190, 20,
1490 panel->titleAlignment,
1491 _("Unfocused Window"));
1493 if (elements & (1 << OTITLE_COL)) {
1494 XCopyArea(dpy, pnot, d, gc, 30, 70, 190, 20, 30, 70);
1495 paintText(scr, d, panel->colors[OTITLE_COL],
1496 panel->boldFont, 30, 70, 190, 20,
1497 panel->titleAlignment,
1498 _("Owner of Focused Window"));
1500 if (elements & (1 << MTITLE_COL)) {
1501 XCopyArea(dpy, pnot, d, gc, 30, 120, 90, 20, 30, 120);
1502 paintText(scr, d, panel->colors[MTITLE_COL],
1503 panel->boldFont, 30, 120, 90, 20, WALeft,
1504 _("Menu Title"));
1506 if (elements & (1 << MITEM_COL)) {
1507 XCopyArea(dpy, pnot, d, gc, 30, 140, 90, 20, 30, 140);
1508 paintText(scr, d, panel->colors[MITEM_COL],
1509 panel->normalFont, 30, 140, 90, 20, WALeft,
1510 _("Normal Item"));
1511 XCopyArea(dpy, pnot, d, gc, 30, 200, 90, 20, 30, 200);
1512 paintText(scr, d, panel->colors[MITEM_COL],
1513 panel->normalFont, 30, 200, 90, 20, WALeft,
1514 _("Normal Item"));
1516 if (elements & (1 << MDISAB_COL)) {
1517 XCopyArea(dpy, pnot, d, gc, 30, 160, 90, 20, 30, 160);
1518 paintText(scr, d, panel->colors[MDISAB_COL],
1519 panel->normalFont, 30, 160, 90, 20, WALeft,
1520 _("Disabled Item"));
1522 if (elements & (1 << MHIGH_COL)) {
1523 XFillRectangle(WMScreenDisplay(scr), d,
1524 WMColorGC(panel->colors[MHIGH_COL]),
1525 31, 181, 87, 17);
1526 XFillRectangle(WMScreenDisplay(scr), pnot,
1527 WMColorGC(panel->colors[MHIGH_COL]),
1528 31, 181, 87, 17);
1529 elements |= 1 << MHIGHT_COL;
1531 if (elements & (1 << MHIGHT_COL)) {
1532 XCopyArea(dpy, pnot, d, gc, 30, 180, 90, 20, 30, 180);
1533 paintText(scr, d, panel->colors[MHIGHT_COL],
1534 panel->normalFont, 30, 180, 90, 20, WALeft,
1535 _("Highlighted"));
1537 if (elements & (1 << FBORDER_COL)) {
1538 XDrawRectangle(dpy, pnot,
1539 WMColorGC(panel->colors[FBORDER_COL]),
1540 29, 39, 190, 20);
1541 XDrawRectangle(dpy, d,
1542 WMColorGC(panel->colors[FBORDER_COL]),
1543 29, 39, 190, 20);
1544 XDrawRectangle(dpy, pnot,
1545 WMColorGC(panel->colors[FBORDER_COL]),
1546 29, 69, 190, 20);
1547 XDrawRectangle(dpy, d,
1548 WMColorGC(panel->colors[FBORDER_COL]),
1549 29, 69, 190, 20);
1550 XDrawLine(dpy, pnot,
1551 WMColorGC(panel->colors[FBORDER_COL]),
1552 30, 100, 30, 109);
1553 XDrawLine(dpy, d,
1554 WMColorGC(panel->colors[FBORDER_COL]),
1555 30, 100, 30, 109);
1556 XDrawLine(dpy, pnot,
1557 WMColorGC(panel->colors[FBORDER_COL]),
1558 31, 109, 219, 109);
1559 XDrawLine(dpy, d,
1560 WMColorGC(panel->colors[FBORDER_COL]),
1561 31, 109, 219, 109);
1562 XDrawLine(dpy, pnot,
1563 WMColorGC(panel->colors[FBORDER_COL]),
1564 220, 100, 220, 109);
1565 XDrawLine(dpy, d,
1566 WMColorGC(panel->colors[FBORDER_COL]),
1567 220, 100, 220, 109);
1568 XDrawLine(dpy, pnot,
1569 WMColorGC(panel->colors[FBORDER_COL]),
1570 29, 120, 29, 220);
1571 XDrawLine(dpy, d,
1572 WMColorGC(panel->colors[FBORDER_COL]),
1573 29, 120, 29, 220);
1574 XDrawLine(dpy, pnot,
1575 WMColorGC(panel->colors[FBORDER_COL]),
1576 29, 119, 119, 119);
1577 XDrawLine(dpy, d,
1578 WMColorGC(panel->colors[FBORDER_COL]),
1579 29, 119, 119, 119);
1580 XDrawLine(dpy, pnot,
1581 WMColorGC(panel->colors[FBORDER_COL]),
1582 119, 120, 119, 220);
1583 XDrawLine(dpy, d,
1584 WMColorGC(panel->colors[FBORDER_COL]),
1585 119, 120, 119, 220);
1588 if (elements & (1 << FFBORDER_COL)) {
1589 XDrawRectangle(dpy, pnot,
1590 WMColorGC(panel->colors[FFBORDER_COL]),
1591 29, 9, 190, 20);
1592 XDrawRectangle(dpy, d,
1593 WMColorGC(panel->colors[FFBORDER_COL]),
1594 29, 9, 190, 20);
1597 if (elements & (1 << ICONT_COL) || elements & (1 << ICONB_COL)) {
1598 RColor rgb;
1599 RHSVColor hsv, hsv2;
1600 int v;
1601 WMColor *light, *dim;
1603 updatePreviewBox(panel, 1 << PICON);
1605 rgb.red = WMRedComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1606 rgb.green = WMGreenComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1607 rgb.blue = WMBlueComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1608 RRGBtoHSV(&rgb, &hsv);
1609 RHSVtoRGB(&hsv, &rgb);
1610 hsv2 = hsv;
1612 v = hsv.value * 16 / 10;
1613 hsv.value = (v > 255 ? 255 : v);
1614 RHSVtoRGB(&hsv, &rgb);
1615 light = WMCreateRGBColor(scr, rgb.red << 8, rgb.green << 8, rgb.blue << 8, False);
1617 hsv2.value = hsv2.value / 2;
1618 RHSVtoRGB(&hsv2, &rgb);
1619 dim = WMCreateRGBColor(scr, rgb.red << 8, rgb.green << 8, rgb.blue << 8, False);
1621 XFillRectangle(dpy, d, WMColorGC(panel->colors[ICONB_COL]), 156, 131, 62, 11);
1622 XDrawLine(dpy, d, WMColorGC(light), 155, 130, 155, 142);
1623 XDrawLine(dpy, d, WMColorGC(light), 156, 130, 217, 130);
1624 XDrawLine(dpy, d, WMColorGC(dim), 218, 130, 218, 142);
1626 paintText(scr, d, panel->colors[ICONT_COL],
1627 panel->smallFont, 155, 130, 64, 13, WALeft,
1628 _("Icon Text"));
1630 WMReleaseColor(light);
1631 WMReleaseColor(dim);
1634 if (elements & (1 << CLIP_COL) || elements & (1 << CCLIP_COL)) {
1635 Pixmap pix;
1636 RColor black;
1637 RColor dark;
1638 RColor light;
1639 RImage *tile;
1640 TextureListItem *titem;
1641 WMListItem *item;
1642 XPoint p[4];
1644 item = WMGetListItem(panel->texLs, panel->textureIndex[PICON]);
1645 titem = (TextureListItem *) item->clientData;
1647 pix = renderTexture(scr, titem->prop, 64, 64, NULL, titem->ispixmap ? 0 : RBEV_RAISED3);
1648 tile = RCreateImageFromDrawable(WMScreenRContext(scr), pix, None);
1650 black.alpha = 255;
1651 black.red = black.green = black.blue = 0;
1653 dark.alpha = 0;
1654 dark.red = dark.green = dark.blue = 60;
1656 light.alpha = 0;
1657 light.red = light.green = light.blue = 80;
1659 /* top right */
1660 ROperateLine(tile, RSubtractOperation, 64 - 1 - 23, 0, 64 - 2, 23 - 1, &dark);
1661 RDrawLine(tile, 64 - 1 - 23 - 1, 0, 64 - 1, 23 + 1, &black);
1662 ROperateLine(tile, RAddOperation, 64 - 1 - 23, 2, 64 - 3, 23, &light);
1664 /* arrow bevel */
1665 ROperateLine(tile, RSubtractOperation, 64 - 7 - (23 - 15), 4, 64 - 5, 4, &dark);
1666 ROperateLine(tile, RSubtractOperation, 64 - 6 - (23 - 15), 5, 64 - 5, 6 + 23 - 15, &dark);
1667 ROperateLine(tile, RAddOperation, 64 - 5, 4, 64 - 5, 6 + 23 - 15, &light);
1669 /* bottom left */
1670 ROperateLine(tile, RAddOperation, 2, 64 - 1 - 23 + 2, 23 - 2, 64 - 3, &dark);
1671 RDrawLine(tile, 0, 64 - 1 - 23 - 1, 23 + 1, 64 - 1, &black);
1672 ROperateLine(tile, RSubtractOperation, 0, 64 - 1 - 23 - 2, 23 + 1, 64 - 2, &light);
1674 /* arrow bevel */
1675 ROperateLine(tile, RSubtractOperation, 4, 64 - 7 - (23 - 15), 4, 64 - 5, &dark);
1676 ROperateLine(tile, RSubtractOperation, 5, 64 - 6 - (23 - 15), 6 + 23 - 15, 64 - 5, &dark);
1677 ROperateLine(tile, RAddOperation, 4, 64 - 5, 6 + 23 - 15, 64 - 5, &light);
1679 RConvertImage(WMScreenRContext(scr), tile, &pix);
1680 RReleaseImage(tile);
1682 XCopyArea(dpy, pix, d, gc, 0, 0, 64, 64, 155, 130);
1683 XFreePixmap(dpy, pix);
1685 /* top right arrow */
1686 p[0].x = p[3].x = 155 + 64 - 5 - (23 - 15);
1687 p[0].y = p[3].y = 130 + 5;
1688 p[1].x = 155 + 64 - 6;
1689 p[1].y = 130 + 5;
1690 p[2].x = 155 + 64 - 6;
1691 p[2].y = 130 + 4 + 23 - 15;
1693 XFillPolygon(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 3, Convex, CoordModeOrigin);
1694 XDrawLines(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 4, CoordModeOrigin);
1696 /* bottom left arrow */
1697 p[0].x = p[3].x = 155 + 5;
1698 p[0].y = p[3].y = 130 + 64 - 5 - (23 - 15);
1699 p[1].x = 155 + 5;
1700 p[1].y = 130 + 64 - 6;
1701 p[2].x = 155 + 4 + 23 - 15;
1702 p[2].y = 130 + 64 - 6;
1704 XFillPolygon(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 3, Convex, CoordModeOrigin);
1705 XDrawLines(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 4, CoordModeOrigin);
1709 if (elements & (1 << CLIP_COL))
1710 paintText(scr, d, panel->colors[CLIP_COL],
1711 panel->boldFont, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft,
1712 _("Clip"));
1714 if (elements & (1 << CCLIP_COL)) {
1715 paintText(scr, d, panel->colors[CCLIP_COL],
1716 panel->boldFont, 155+2, 130 + 2, 26, 15, WALeft, _("Coll."));
1717 paintText(scr, d, panel->colors[CCLIP_COL],
1718 panel->boldFont, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft,
1719 _("Clip"));
1722 WMRedisplayWidget(panel->prevL);
1725 static void colorWellObserver(void *self, WMNotification * n)
1727 _Panel *panel = (_Panel *) self;
1728 int p;
1730 /* Parameter not used, but tell the compiler that it is ok */
1731 (void) n;
1733 p = WMGetPopUpButtonSelectedItem(panel->colP);
1735 WMReleaseColor(panel->colors[p]);
1737 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1739 updateColorPreviewBox(panel, 1 << p);
1742 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item)
1744 _Panel *panel = self->data;
1745 int i;
1747 /* Parameter not used, but tell the compiler that it is ok */
1748 (void) tabView;
1750 i = WMGetTabViewItemIdentifier(item);
1751 switch (i) {
1752 case TAB_TEXTURE:
1753 switch (panel->oldTabItem) {
1754 case TAB_COLOR:
1755 changeColorPage(NULL, panel);
1756 break;
1758 changePage(panel->secP, panel);
1759 break;
1760 case TAB_COLOR:
1761 switch (panel->oldTabItem) {
1762 case TAB_TEXTURE:
1763 changePage(NULL, panel);
1764 break;
1766 changeColorPage(panel->colP, panel);
1767 break;
1768 case TAB_OPTIONS:
1769 switch (panel->oldTabItem) {
1770 case TAB_TEXTURE:
1771 changePage(NULL, panel);
1772 break;
1773 case TAB_COLOR:
1774 changeColorPage(NULL, panel);
1775 break;
1777 break;
1780 panel->oldTabItem = i;
1783 /*************************************************************************/
1785 static void menuStyleCallback(WMWidget * self, void *data)
1787 _Panel *panel = (_Panel *) data;
1788 menu_style_index i;
1790 for (i = 0; i < wlengthof(menu_style); i++) {
1791 if (self == panel->mstyB[i]) {
1792 panel->menuStyle = i;
1793 break;
1797 updatePreviewBox(panel, 1 << PMITEM);
1800 static void titleAlignCallback(WMWidget * self, void *data)
1802 _Panel *panel = (_Panel *) data;
1803 WMAlignment align;
1805 for (align = 0; align < wlengthof(wintitle_align); align++) {
1806 if (self == panel->taliB[align]) {
1807 panel->titleAlignment = align;
1808 break;
1812 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1815 static void createPanel(Panel * p)
1817 _Panel *panel = (_Panel *) p;
1818 WMFont *font;
1819 WMScreen *scr = WMWidgetScreen(panel->parent);
1820 WMTabViewItem *item;
1821 int i;
1822 char *tmp;
1823 Bool ok = True;
1825 panel->fprefix = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1827 if (access(panel->fprefix, F_OK) != 0) {
1828 if (mkdir(panel->fprefix, 0755) < 0) {
1829 werror("%s", panel->fprefix);
1830 ok = False;
1833 if (ok) {
1834 tmp = wstrconcat(panel->fprefix, "/WPrefs/");
1835 wfree(panel->fprefix);
1836 panel->fprefix = tmp;
1837 if (access(panel->fprefix, F_OK) != 0) {
1838 if (mkdir(panel->fprefix, 0755) < 0) {
1839 werror("%s", panel->fprefix);
1844 panel->smallFont = WMSystemFontOfSize(scr, 10);
1845 panel->normalFont = WMSystemFontOfSize(scr, 12);
1846 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1848 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1849 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1850 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1852 panel->box = WMCreateBox(panel->parent);
1853 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1855 /* preview box */
1856 panel->prevL = WMCreateLabel(panel->box);
1857 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1858 WMMoveWidget(panel->prevL, 15, 10);
1859 WMSetLabelRelief(panel->prevL, WRSunken);
1860 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1862 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask, previewClick, panel);
1864 /* tabview */
1866 tabviewDelegate.data = panel;
1868 panel->tabv = WMCreateTabView(panel->box);
1869 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1870 WMMoveWidget(panel->tabv, 265, 10);
1871 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1873 /*** texture list ***/
1875 panel->texF = WMCreateFrame(panel->box);
1876 WMSetFrameRelief(panel->texF, WRFlat);
1878 item = WMCreateTabViewItemWithIdentifier(TAB_TEXTURE);
1879 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1880 WMSetTabViewItemLabel(item, _("Texture"));
1882 WMAddItemInTabView(panel->tabv, item);
1884 panel->secP = WMCreatePopUpButton(panel->texF);
1885 WMResizeWidget(panel->secP, 228, 20);
1886 WMMoveWidget(panel->secP, 7, 7);
1888 for (i = 0; i < wlengthof(textureOptions); i++)
1889 WMAddPopUpButtonItem(panel->secP, _(textureOptions[i].popup_label));
1891 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1892 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1894 panel->texLs = WMCreateList(panel->texF);
1895 WMResizeWidget(panel->texLs, 165, 155);
1896 WMMoveWidget(panel->texLs, 70, 33);
1897 WMSetListUserDrawItemHeight(panel->texLs, 35);
1898 WMSetListUserDrawProc(panel->texLs, paintListItem);
1899 WMHangData(panel->texLs, panel);
1900 WMSetListAction(panel->texLs, textureClick, panel);
1901 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1903 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1904 "for the selected item."), WMWidgetView(panel->texLs));
1906 /* command buttons */
1908 font = WMSystemFontOfSize(scr, 10);
1910 panel->newB = WMCreateCommandButton(panel->texF);
1911 WMResizeWidget(panel->newB, 57, 39);
1912 WMMoveWidget(panel->newB, 7, 33);
1913 WMSetButtonFont(panel->newB, font);
1914 WMSetButtonImagePosition(panel->newB, WIPAbove);
1915 WMSetButtonText(panel->newB, _("New"));
1916 WMSetButtonAction(panel->newB, newTexture, panel);
1917 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1919 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel->newB));
1921 panel->ripB = WMCreateCommandButton(panel->texF);
1922 WMResizeWidget(panel->ripB, 57, 39);
1923 WMMoveWidget(panel->ripB, 7, 72);
1924 WMSetButtonFont(panel->ripB, font);
1925 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1926 WMSetButtonText(panel->ripB, _("Extract..."));
1927 WMSetButtonAction(panel->ripB, extractTexture, panel);
1928 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1930 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel->ripB));
1932 WMSetButtonEnabled(panel->ripB, False);
1934 panel->editB = WMCreateCommandButton(panel->texF);
1935 WMResizeWidget(panel->editB, 57, 39);
1936 WMMoveWidget(panel->editB, 7, 111);
1937 WMSetButtonFont(panel->editB, font);
1938 WMSetButtonImagePosition(panel->editB, WIPAbove);
1939 WMSetButtonText(panel->editB, _("Edit"));
1940 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1941 WMSetButtonAction(panel->editB, editTexture, panel);
1942 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel->editB));
1944 panel->delB = WMCreateCommandButton(panel->texF);
1945 WMResizeWidget(panel->delB, 57, 38);
1946 WMMoveWidget(panel->delB, 7, 150);
1947 WMSetButtonFont(panel->delB, font);
1948 WMSetButtonImagePosition(panel->delB, WIPAbove);
1949 WMSetButtonText(panel->delB, _("Delete"));
1950 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1951 WMSetButtonEnabled(panel->delB, False);
1952 WMSetButtonAction(panel->delB, deleteTexture, panel);
1953 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel->delB));
1955 WMReleaseFont(font);
1957 WMMapSubwidgets(panel->texF);
1959 /*** colors ***/
1960 panel->colF = WMCreateFrame(panel->box);
1961 WMSetFrameRelief(panel->colF, WRFlat);
1963 item = WMCreateTabViewItemWithIdentifier(TAB_COLOR);
1964 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1965 WMSetTabViewItemLabel(item, _("Color"));
1967 WMAddItemInTabView(panel->tabv, item);
1969 panel->colP = WMCreatePopUpButton(panel->colF);
1970 WMResizeWidget(panel->colP, 228, 20);
1971 WMMoveWidget(panel->colP, 7, 7);
1973 for (i = 0; i < wlengthof(colorOptions); i++)
1974 WMAddPopUpButtonItem(panel->colP, _(colorOptions[i].label));
1976 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1978 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1980 panel->colW = WMCreateColorWell(panel->colF);
1981 WMResizeWidget(panel->colW, 65, 50);
1982 WMMoveWidget(panel->colW, 30, 75);
1983 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->colW);
1985 { /* Distribute the color samples regularly in the right half */
1986 const int parent_width = 242;
1987 const int parent_height = 195;
1988 const int available_width = (parent_width / 2) - 7;
1989 const int available_height = parent_height - 7 - 20 - 7 - 7;
1990 const int widget_size = 22;
1992 const int nb_x = (int) round(sqrt(wlengthof(sample_colors) * available_width / available_height));
1993 const int nb_y = (wlengthof(sample_colors) + nb_x - 1) / nb_x;
1995 const int offset_x = (parent_width / 2) + (available_width - nb_x * widget_size) / 2;
1996 const int offset_y = (7 + 20 + 7) + (available_height - nb_y * widget_size) / 2;
1998 int x, y;
2000 x = 0; y = 0;
2001 for (i = 0; i < wlengthof(sample_colors); i++) {
2002 panel->sampW[i] = WMCreateColorWell(panel->colF);
2003 WMResizeWidget(panel->sampW[i], widget_size, widget_size);
2004 WMMoveWidget(panel->sampW[i], offset_x + x * widget_size, offset_y + y * widget_size);
2005 WSetColorWellBordered(panel->sampW[i], False);
2006 if (++x >= nb_x) {
2007 y++;
2008 x = 0;
2013 WMMapSubwidgets(panel->colF);
2015 /*** options ***/
2016 panel->optF = WMCreateFrame(panel->box);
2017 WMSetFrameRelief(panel->optF, WRFlat);
2019 item = WMCreateTabViewItemWithIdentifier(TAB_OPTIONS);
2020 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
2021 WMSetTabViewItemLabel(item, _("Options"));
2023 WMAddItemInTabView(panel->tabv, item);
2025 panel->mstyF = WMCreateFrame(panel->optF);
2026 WMResizeWidget(panel->mstyF, 215, 85);
2027 WMMoveWidget(panel->mstyF, 15, 10);
2028 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
2030 for (i = 0; i < wlengthof(menu_style); i++) {
2031 WMPixmap *icon;
2032 char *path;
2034 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
2035 WMResizeWidget(panel->mstyB[i], 54, 54);
2036 WMMoveWidget(panel->mstyB[i], 15 + i * 65, 20);
2037 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
2038 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
2039 path = LocateImage(menu_style[i].file_name);
2040 if (path) {
2041 icon = WMCreatePixmapFromFile(scr, path);
2042 if (icon) {
2043 WMSetButtonImage(panel->mstyB[i], icon);
2044 WMReleasePixmap(icon);
2045 } else {
2046 wwarning(_("could not load icon file %s"), path);
2048 wfree(path);
2051 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
2052 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
2054 WMMapSubwidgets(panel->mstyF);
2056 panel->taliF = WMCreateFrame(panel->optF);
2057 WMResizeWidget(panel->taliF, 110, 80);
2058 WMMoveWidget(panel->taliF, 15, 100);
2059 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
2061 for (i = 0; i < wlengthof(wintitle_align); i++) {
2062 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
2063 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
2064 WMSetButtonText(panel->taliB[i], _(wintitle_align[i].label));
2065 WMResizeWidget(panel->taliB[i], 90, 18);
2066 WMMoveWidget(panel->taliB[i], 10, 15 + 20 * i);
2068 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
2069 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
2071 WMMapSubwidgets(panel->taliF);
2073 WMMapSubwidgets(panel->optF);
2075 /**/ WMRealizeWidget(panel->box);
2076 WMMapSubwidgets(panel->box);
2078 WMSetPopUpButtonSelectedItem(panel->secP, 0);
2080 showData(panel);
2082 changePage(panel->secP, panel);
2084 fillTextureList(panel->texLs);
2086 fillColorList(panel);
2088 panel->texturePanel = CreateTexturePanel(panel->parent);
2091 static void setupTextureFor(WMList *list, const char *key, const char *defValue, const char *title, int index)
2093 WMListItem *item;
2094 TextureListItem *titem;
2096 titem = wmalloc(sizeof(TextureListItem));
2098 titem->title = wstrdup(title);
2099 titem->prop = GetObjectForKey(key);
2100 if (!titem->prop || !WMIsPLArray(titem->prop)) {
2101 /* Maybe also give a error message to stderr that the entry is bad? */
2102 titem->prop = WMCreatePropListFromDescription(defValue);
2103 } else {
2104 WMRetainPropList(titem->prop);
2106 titem->texture = WMGetPropListDescription((WMPropList *) titem->prop, False);
2107 titem->current = 1;
2108 titem->selectedFor = 1 << index;
2110 titem->ispixmap = isPixmap(titem->prop);
2112 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
2114 item = WMAddListItem(list, "");
2115 item->clientData = titem;
2118 static void showData(_Panel * panel)
2120 int i;
2121 const char *str;
2123 str = GetStringForKey("MenuStyle");
2124 panel->menuStyle = MSTYLE_NORMAL;
2125 if (str != NULL) {
2126 for (i = 0; i < wlengthof(menu_style); i++) {
2127 if (strcasecmp(str, menu_style[i].db_value) == 0) {
2128 panel->menuStyle = i;
2129 break;
2134 str = GetStringForKey("TitleJustify");
2135 panel->titleAlignment = WACenter;
2136 if (str != NULL) {
2137 WMAlignment align;
2139 for (align = 0; align < wlengthof(wintitle_align); align++) {
2140 if (strcasecmp(str, wintitle_align[align].db_value) == 0) {
2141 panel->titleAlignment = align;
2142 break;
2147 for (i = 0; i < wlengthof(colorOptions); i++) {
2148 WMColor *color;
2150 str = GetStringForKey(colorOptions[i].key);
2151 if (!str)
2152 str = colorOptions[i].default_value;
2154 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->box), str, False))) {
2155 color = WMCreateNamedColor(WMWidgetScreen(panel->box), "#000000", False);
2158 panel->colors[i] = color;
2160 changeColorPage(panel->colP, panel);
2162 for (i = 0; i < wlengthof(textureOptions); i++) {
2163 setupTextureFor(panel->texLs, textureOptions[i].key,
2164 textureOptions[i].default_value, _(textureOptions[i].texture_label), i);
2165 panel->textureIndex[i] = i;
2167 updatePreviewBox(panel, EVERYTHING);
2169 WMSetButtonSelected(panel->mstyB[panel->menuStyle], True);
2170 WMSetButtonSelected(panel->taliB[panel->titleAlignment], True);
2173 static void storeData(_Panel * panel)
2175 TextureListItem *titem;
2176 WMListItem *item;
2177 int i;
2179 for (i = 0; i < wlengthof(textureOptions); i++) {
2180 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2181 titem = (TextureListItem *) item->clientData;
2182 SetObjectForKey(titem->prop, textureOptions[i].key);
2185 for (i = 0; i < wlengthof(colorOptions); i++) {
2186 char *str;
2188 str = WMGetColorRGBDescription(panel->colors[i]);
2190 if (str) {
2191 SetStringForKey(str, colorOptions[i].key);
2192 wfree(str);
2196 SetStringForKey(menu_style[panel->menuStyle].db_value, "MenuStyle");
2197 SetStringForKey(wintitle_align[panel->titleAlignment].db_value, "TitleJustify");
2200 static void prepareForClose(_Panel * panel)
2202 WMPropList *textureList;
2203 WMPropList *texture;
2204 TextureListItem *titem;
2205 WMListItem *item;
2206 WMUserDefaults *udb = WMGetStandardUserDefaults();
2207 int i;
2209 textureList = WMCreatePLArray(NULL, NULL);
2211 /* store list of textures */
2212 for (i = 8; i < WMGetListNumberOfRows(panel->texLs); i++) {
2213 WMPropList *pl_title, *pl_path;
2215 item = WMGetListItem(panel->texLs, i);
2216 titem = (TextureListItem *) item->clientData;
2218 pl_title = WMCreatePLString(titem->title);
2219 pl_path = WMCreatePLString(titem->path);
2220 texture = WMCreatePLArray(pl_title, titem->prop, pl_path, NULL);
2221 WMReleasePropList(pl_title);
2222 WMReleasePropList(pl_path);
2224 WMAddToPLArray(textureList, texture);
2227 WMSetUDObjectForKey(udb, textureList, "TextureList");
2228 WMReleasePropList(textureList);
2230 /* store list of colors */
2231 textureList = WMCreatePLArray(NULL, NULL);
2232 for (i = 0; i < wlengthof(sample_colors); i++) {
2233 WMColor *color;
2234 char *str;
2235 WMPropList *pl_color;
2237 color = WMGetColorWellColor(panel->sampW[i]);
2239 str = WMGetColorRGBDescription(color);
2240 pl_color = WMCreatePLString(str);
2241 WMAddToPLArray(textureList, pl_color);
2242 WMReleasePropList(pl_color);
2243 wfree(str);
2245 WMSetUDObjectForKey(udb, textureList, "ColorList");
2246 WMReleasePropList(textureList);
2248 WMSynchronizeUserDefaults(udb);
2251 Panel *InitAppearance(WMWidget *parent)
2253 _Panel *panel;
2255 panel = wmalloc(sizeof(_Panel));
2257 panel->sectionName = _("Appearance Preferences");
2259 panel->description = _("Background texture configuration for windows,\n" "menus and icons.");
2261 panel->parent = parent;
2263 panel->callbacks.createWidgets = createPanel;
2264 panel->callbacks.updateDomain = storeData;
2265 panel->callbacks.prepareForClose = prepareForClose;
2267 AddSection(panel, ICON_FILE);
2269 return panel;
2272 /****************************************************************************/
2274 typedef struct ExtractPanel {
2275 WMWindow *win;
2277 WMLabel *label;
2278 WMList *list;
2280 WMButton *closeB;
2281 WMButton *extrB;
2282 } ExtractPanel;
2284 static void OpenExtractPanelFor(_Panel *panel)
2286 ExtractPanel *epanel;
2287 WMColor *color;
2288 WMFont *font;
2289 WMScreen *scr = WMWidgetScreen(panel->parent);
2291 epanel = wmalloc(sizeof(ExtractPanel));
2292 epanel->win = WMCreatePanelWithStyleForWindow(panel->parent, "extract",
2293 WMTitledWindowMask | WMClosableWindowMask);
2294 WMResizeWidget(epanel->win, 245, 250);
2295 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2297 epanel->label = WMCreateLabel(epanel->win);
2298 WMResizeWidget(epanel->label, 225, 18);
2299 WMMoveWidget(epanel->label, 10, 10);
2300 WMSetLabelTextAlignment(epanel->label, WACenter);
2301 WMSetLabelRelief(epanel->label, WRSunken);
2303 color = WMDarkGrayColor(scr);
2304 WMSetWidgetBackgroundColor(epanel->label, color);
2305 WMReleaseColor(color);
2307 color = WMWhiteColor(scr);
2308 WMSetLabelTextColor(epanel->label, color);
2309 WMReleaseColor(color);
2311 font = WMBoldSystemFontOfSize(scr, 12);
2312 WMSetLabelFont(epanel->label, font);
2313 WMReleaseFont(font);
2315 WMSetLabelText(epanel->label, _("Textures"));
2317 epanel->list = WMCreateList(epanel->win);
2318 WMResizeWidget(epanel->list, 225, 165);
2319 WMMoveWidget(epanel->list, 10, 30);
2321 epanel->closeB = WMCreateCommandButton(epanel->win);
2322 WMResizeWidget(epanel->closeB, 74, 24);
2323 WMMoveWidget(epanel->closeB, 165, 215);
2324 WMSetButtonText(epanel->closeB, _("Close"));
2326 epanel->extrB = WMCreateCommandButton(epanel->win);
2327 WMResizeWidget(epanel->extrB, 74, 24);
2328 WMMoveWidget(epanel->extrB, 80, 215);
2329 WMSetButtonText(epanel->extrB, _("Extract"));
2331 WMMapSubwidgets(epanel->win);
2333 /* take textures from file */
2335 WMRealizeWidget(epanel->win);
2337 WMMapWidget(epanel->win);