util: clarify a bit of the code for parsing commands in wmgenmenu
[wmaker-crm.git] / WPrefs.app / Appearance.c
blobd5786e56fe05fa2da6f3ede806a4450392bc2d73
1 /* Apperance.c- color/texture for titlebar etc.
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1999-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "WPrefs.h"
24 #include <unistd.h>
25 #include <errno.h>
26 #include <ctype.h>
27 #include <time.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 #include <fcntl.h>
32 #include "TexturePanel.h"
34 typedef struct _Panel {
35 WMBox *box;
36 char *sectionName;
38 char *description;
40 CallbackRec callbacks;
42 WMWidget *parent;
44 WMLabel *prevL;
46 WMTabView *tabv;
48 /* texture list */
49 WMFrame *texF;
50 WMList *texLs;
52 WMPopUpButton *secP;
54 WMButton *newB;
55 WMButton *editB;
56 WMButton *ripB;
57 WMButton *delB;
59 /* text color */
60 WMFrame *colF;
62 WMPopUpButton *colP;
63 WMColor *colors[15];
65 WMColorWell *colW;
67 WMColorWell *sampW[24];
69 /* options */
70 WMFrame *optF;
72 WMFrame *mstyF;
73 WMButton *mstyB[3];
75 WMFrame *taliF;
76 WMButton *taliB[3];
78 /* */
80 int textureIndex[8];
82 WMFont *smallFont;
83 WMFont *normalFont;
84 WMFont *boldFont;
86 TexturePanel *texturePanel;
88 WMPixmap *onLed;
89 WMPixmap *offLed;
90 WMPixmap *hand;
92 int oldsection;
93 int oldcsection;
95 char oldTabItem;
97 int menuStyle;
99 int titleAlignment;
101 Pixmap preview;
102 Pixmap previewNoText;
103 Pixmap previewBack;
105 char *fprefix;
106 } _Panel;
108 typedef struct {
109 char *title;
110 char *texture;
111 WMPropList *prop;
112 Pixmap preview;
114 char *path;
116 char selectedFor;
117 unsigned current:1;
118 unsigned ispixmap:1;
119 } TextureListItem;
121 enum {
122 TAB_TEXTURE,
123 TAB_COLOR,
124 TAB_OPTIONS
127 static void updateColorPreviewBox(_Panel * panel, int elements);
129 static void showData(_Panel * panel);
131 static void changePage(WMWidget * w, void *data);
133 static void changeColorPage(WMWidget * w, void *data);
135 static void OpenExtractPanelFor(_Panel *panel);
137 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item);
139 static WMTabViewDelegate tabviewDelegate = {
140 NULL,
141 NULL, /* didChangeNumberOfItems */
142 changedTabItem, /* didSelectItem */
143 NULL, /* shouldSelectItem */
144 NULL /* willSelectItem */
147 #define ICON_FILE "appearance"
149 #define TNEW_FILE "tnew"
150 #define TDEL_FILE "tdel"
151 #define TEDIT_FILE "tedit"
152 #define TEXTR_FILE "textr"
154 #define MSTYLE1_FILE "msty1"
155 #define MSTYLE2_FILE "msty2"
156 #define MSTYLE3_FILE "msty3"
158 /* XPM */
159 static char *blueled_xpm[] = {
160 "8 8 17 1",
161 " c None",
162 ". c #020204",
163 "+ c #16B6FC",
164 "@ c #176AFC",
165 "# c #163AFC",
166 "$ c #72D2FC",
167 "% c #224CF4",
168 "& c #76D6FC",
169 "* c #16AAFC",
170 "= c #CEE9FC",
171 "- c #229EFC",
172 "; c #164CFC",
173 "> c #FAFEFC",
174 ", c #2482FC",
175 "' c #1652FC",
176 ") c #1E76FC",
177 "! c #1A60FC",
178 " .... ",
179 " .=>-@. ",
180 ".=>$@@'.",
181 ".=$@!;;.",
182 ".!@*+!#.",
183 ".#'*+*,.",
184 " .@)@,. ",
185 " .... "
188 /* XPM */
189 static char *blueled2_xpm[] = {
190 /* width height num_colors chars_per_pixel */
191 " 8 8 17 1",
192 /* colors */
193 ". c None",
194 "# c #090909",
195 "a c #4b63a4",
196 "b c #011578",
197 "c c #264194",
198 "d c #04338c",
199 "e c #989dac",
200 "f c #011a7c",
201 "g c #465c9c",
202 "h c #03278a",
203 "i c #6175ac",
204 "j c #011e74",
205 "k c #043a90",
206 "l c #042f94",
207 "m c #0933a4",
208 "n c #022184",
209 "o c #012998",
210 /* pixels */
211 "..####..",
212 ".#aimn#.",
213 "#aechnf#",
214 "#gchnjf#",
215 "#jndknb#",
216 "#bjdddl#",
217 ".#nono#.",
218 "..####.."
221 /* XPM */
222 static char *hand_xpm[] = {
223 "22 21 19 1",
224 " c None",
225 ". c #030305",
226 "+ c #7F7F7E",
227 "@ c #B5B5B6",
228 "# c #C5C5C6",
229 "$ c #969697",
230 "% c #FDFDFB",
231 "& c #F2F2F4",
232 "* c #E5E5E4",
233 "= c #ECECEC",
234 "- c #DCDCDC",
235 "; c #D2D2D0",
236 "> c #101010",
237 ", c #767674",
238 "' c #676767",
239 ") c #535355",
240 "! c #323234",
241 "~ c #3E3C56",
242 "{ c #333147",
243 " ",
244 " ..... ",
245 " ..+@##$. ",
246 " .%%%&@.......... ",
247 " .%*%%&#%%%%%%%%%$. ",
248 " .*#%%%%%%%%%&&&&==. ",
249 " .-%%%%%%%%%=*-;;;#$. ",
250 " .-%%%%%%%%&..>..... ",
251 " >-%%%%%%%%%*#+. ",
252 " >-%%%%%%%%%*@,. ",
253 " >#%%%%%%%%%*@'. ",
254 " >$&&%%%%%%=... ",
255 " .+@@;=&%%&;$,> ",
256 " .',$@####$+). ",
257 " .!',+$++,'. ",
258 " ..>>>>>. ",
259 " ",
260 " ~~{{{~~ ",
261 " {{{{{{{{{{{ ",
262 " ~~{{{~~ ",
266 static char *sampleColors[] = {
267 "black",
268 "#292929",
269 "#525252",
270 "#848484",
271 "#adadad",
272 "#d6d6d6",
273 "white",
274 "#d6d68c",
275 "#d6a57b",
276 "#8cd68c",
277 "#8cd6ce",
278 "#d68c8c",
279 "#8c9cd6",
280 "#bd86d6",
281 "#d68cbd",
282 "#d64a4a",
283 "#4a5ad6",
284 "#4ad6ce",
285 "#4ad65a",
286 "#ced64a",
287 "#d6844a",
288 "#8ad631",
289 "#ce29c6",
290 "#ce2973",
291 "black"
294 static const struct {
295 const char *key;
296 const char *default_value;
297 const char *texture_label; /* text used when displaying the list of textures */
298 WMRect preview; /* The rectangle where the corresponding object is displayed */
299 WMPoint hand; /* The coordinate where the hand is drawn when pointing this item */
300 const char *popup_label; /* text used for the popup button with the list of editable items */
301 } textureOptions[] = {
303 #define PFOCUSED 0
304 { "FTitleBack", "(solid, black)", N_("[Focused]"),
305 { { 30, 10 }, { 190, 20 } }, { 5, 10 }, N_("Titlebar of Focused Window") },
307 #define PUNFOCUSED 1
308 { "UTitleBack", "(solid, gray)", N_("[Unfocused]"),
309 { { 30, 40 }, { 190, 20 } }, { 5, 40 }, N_("Titlebar of Unfocused Windows") },
311 #define POWNER 2
312 { "PTitleBack", "(solid, \"#616161\")", N_("[Owner of Focused]"),
313 { { 30, 70 }, { 190, 20 } }, { 5, 70 }, N_("Titlebar of Focused Window's Owner") },
315 #define PRESIZEBAR 3
316 { "ResizebarBack", "(solid, gray)", N_("[Resizebar]"),
317 { { 30, 100 }, { 190, 9 } }, { 5, 100 }, N_("Window Resizebar") },
319 #define PMTITLE 4
320 { "MenuTitleBack", "(solid, black)", N_("[Menu Title]"),
321 { { 30, 120 }, { 90, 20 } }, { 5, 120 }, N_("Titlebar of Menus") },
323 #define PMITEM 5
324 { "MenuTextBack", "(solid, gray)", N_("[Menu Item]"),
325 { { 30, 140 }, { 90, 20 * 4 } }, { 5, 160 }, N_("Menu Items") },
327 #define PICON 6
328 { "IconBack", "(solid, gray)", N_("[Icon]"),
329 { { 155, 130 }, { 64, 64 } }, { 130, 150 }, N_("Icon Background") },
331 #define PBACKGROUND 7
332 { "WorkspaceBack", "(solid, black)", N_("[Background]"),
333 { { -1, -1}, { 0, 0 } }, { -22, -21 }, N_("Workspace Background") }
335 #define EVERYTHING 0xff
338 enum {
339 RESIZEBAR_BEVEL = -1,
340 MENU_BEVEL = -2
343 enum {
344 TEXPREV_WIDTH = 40,
345 TEXPREV_HEIGHT = 24
348 enum {
349 MSTYLE_NORMAL,
350 MSTYLE_SINGLE,
351 MSTYLE_FLAT
354 enum {
355 FTITLE_COL,
356 UTITLE_COL,
357 OTITLE_COL,
358 MTITLE_COL,
359 MITEM_COL,
360 MDISAB_COL,
361 MHIGH_COL,
362 MHIGHT_COL,
363 FFBORDER_COL,
364 FBORDER_COL,
365 FSBORDER_COL,
366 ICONT_COL,
367 ICONB_COL,
368 CLIP_COL,
369 CCLIP_COL
372 static const struct {
373 const char *key;
374 const char *default_value;
375 const char *label;
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 } colorOptions[] = {
379 /* Related to Window titles */
380 { "FTitleColor", "white", N_("Focused Window Title"),
381 { { 30, 10 }, { 190, 20 } }, { 5, 10 } },
382 { "UTitleColor", "black", N_("Unfocused Window Title"),
383 { { 30, 40 }, { 190, 20 } }, { 5, 40 } },
384 { "PTitleColor", "white", N_("Owner of Focused Window Title"),
385 { { 30, 70 }, { 190, 20 } }, { 5, 70 } },
387 /* Related to Menus */
388 { "MenuTitleColor", "white", N_("Menu Title") ,
389 { { 30, 120 }, { 90, 20 } }, { 5, 120 } },
390 { "MenuTextColor", "black", N_("Menu Item Text") ,
391 { { 30, 140 }, { 90, 20 } }, { 5, 140 } },
392 { "MenuDisabledColor", "#616161", N_("Disabled Menu Item Text") ,
393 { { 30, 160 }, { 90, 20 } }, { 5, 160 } },
394 { "HighlightColor", "white", N_("Menu Highlight Color") ,
395 { { 30, 180 }, { 90, 20 } }, { 5, 180 } },
396 { "HighlightTextColor", "black", N_("Highlighted Menu Text Color") ,
397 { { 30, 200 }, { 90, 20 } }, { 5, 180 } },
399 * yuck kluge: the coordinate for HighlightTextColor are actually those of the last "Normal item"
400 * at the bottom when user clicks it, the "yuck kluge" in the function 'previewClick' will swap it
401 * for the MenuTextColor selection as user would expect
403 * Note that the entries are reffered by their index for performance
406 /* Related to Window's border */
407 { "FrameFocusedBorderColor", "black", N_("Focused Window Border Color") ,
408 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
409 { "FrameBorderColor", "black", N_("Window Border Color") ,
410 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
411 { "FrameSelectedBorderColor", "white", N_("Selected Window Border Color") ,
412 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
414 /* Related to Icons and Clip */
415 { "IconTitleColor", "white", N_("Miniwindow Title") ,
416 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
417 { "IconTitleBack", "black", N_("Miniwindow Title Back") ,
418 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
419 { "ClipTitleColor", "black", N_("Clip Title") ,
420 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
421 { "CClipTitleColor", "#454045", N_("Collapsed Clip Title") ,
422 { { 155, 130 }, { 64, 64 } }, { 130, 132 } }
426 static void str2rcolor(RContext * rc, const char *name, RColor * color)
428 XColor xcolor;
430 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
432 color->alpha = 255;
433 color->red = xcolor.red >> 8;
434 color->green = xcolor.green >> 8;
435 color->blue = xcolor.blue >> 8;
438 static void dumpRImage(const char *path, RImage * image)
440 FILE *f;
441 int channels = (image->format == RRGBAFormat ? 4 : 3);
443 f = fopen(path, "wb");
444 if (!f) {
445 werror("%s", path);
446 return;
448 fprintf(f, "%02x%02x%1x", image->width, image->height, channels);
450 fwrite(image->data, 1, image->width * image->height * channels, f);
452 fsync(fileno(f));
453 if (fclose(f) < 0) {
454 werror("%s", path);
458 static int isPixmap(WMPropList * prop)
460 WMPropList *p;
461 char *s;
463 p = WMGetFromPLArray(prop, 0);
464 s = WMGetFromPLString(p);
465 if (strcasecmp(&s[1], "pixmap") == 0)
466 return 1;
467 else
468 return 0;
471 /**********************************************************************/
473 static void drawResizebarBevel(RImage * img)
475 RColor light;
476 RColor dark;
477 int width = img->width;
478 int height = img->height;
479 int cwidth = 28;
481 light.alpha = 0;
482 light.red = light.green = light.blue = 80;
484 dark.alpha = 0;
485 dark.red = dark.green = dark.blue = 40;
487 ROperateLine(img, RSubtractOperation, 0, 0, width - 1, 0, &dark);
488 ROperateLine(img, RAddOperation, 0, 1, width - 1, 1, &light);
490 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height - 1, &dark);
491 ROperateLine(img, RAddOperation, cwidth + 1, 2, cwidth + 1, height - 1, &light);
493 ROperateLine(img, RSubtractOperation, width - cwidth - 2, 2, width - cwidth - 2, height - 1, &dark);
494 ROperateLine(img, RAddOperation, width - cwidth - 1, 2, width - cwidth - 1, height - 1, &light);
498 static void drawMenuBevel(RImage * img)
500 RColor light, dark, mid;
501 int i;
502 int iheight = img->height / 4;
504 light.alpha = 0;
505 light.red = light.green = light.blue = 80;
507 dark.alpha = 255;
508 dark.red = dark.green = dark.blue = 0;
510 mid.alpha = 0;
511 mid.red = mid.green = mid.blue = 40;
513 for (i = 1; i < 4; i++) {
514 ROperateLine(img, RSubtractOperation, 0, i * iheight - 2, img->width - 1, i * iheight - 2, &mid);
516 RDrawLine(img, 0, i * iheight - 1, img->width - 1, i * iheight - 1, &dark);
518 ROperateLine(img, RAddOperation, 1, i * iheight, img->width - 2, i * iheight, &light);
522 static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int height, const char *path, int border)
524 char *type;
525 RImage *image = NULL;
526 RImage *timage = NULL;
527 Pixmap pixmap;
528 RContext *rc = WMScreenRContext(scr);
529 char *str;
530 RColor rcolor;
532 type = WMGetFromPLString(WMGetFromPLArray(texture, 0));
534 if (strcasecmp(&type[1], "pixmap") == 0 ||
535 (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T')) {
536 char *path;
538 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
539 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
540 if (path) {
541 timage = RLoadImage(rc, path, 0);
542 if (!timage)
543 wwarning("could not load file '%s': %s", path, RMessageForError(RErrorCode));
544 wfree(path);
545 } else {
546 wwarning("could not find file '%s' for %s of texture", str, type);
547 timage = NULL;
549 if (!timage) {
550 texture = WMCreatePropListFromDescription("(solid, black)");
551 type = "solid";
555 if (strcasecmp(type, "solid") == 0) {
557 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
559 str2rcolor(rc, str, &rcolor);
561 image = RCreateImage(width, height, False);
562 RClearImage(image, &rcolor);
563 } else if (strcasecmp(type, "igradient") == 0) {
564 int t1, t2;
565 RColor c1[2], c2[2];
567 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
568 str2rcolor(rc, str, &c1[0]);
569 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
570 str2rcolor(rc, str, &c1[1]);
571 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
572 t1 = atoi(str);
574 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
575 str2rcolor(rc, str, &c2[0]);
576 str = WMGetFromPLString(WMGetFromPLArray(texture, 5));
577 str2rcolor(rc, str, &c2[1]);
578 str = WMGetFromPLString(WMGetFromPLArray(texture, 6));
579 t2 = atoi(str);
581 image = RRenderInterwovenGradient(width, height, c1, t1, c2, t2);
582 } else if (strcasecmp(&type[1], "gradient") == 0) {
583 RGradientStyle style;
584 RColor rcolor2;
586 switch (toupper(type[0])) {
587 case 'V':
588 style = RVerticalGradient;
589 break;
590 case 'H':
591 style = RHorizontalGradient;
592 break;
593 default:
594 wwarning("unknow direction in '%s', falling back to diagonal", type);
595 case 'D':
596 style = RDiagonalGradient;
597 break;
600 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
601 str2rcolor(rc, str, &rcolor);
602 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
603 str2rcolor(rc, str, &rcolor2);
605 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
606 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T') {
607 RGradientStyle style;
608 RColor rcolor2;
609 int i;
610 RImage *grad = NULL;
612 switch (toupper(type[1])) {
613 case 'V':
614 style = RVerticalGradient;
615 break;
616 case 'H':
617 style = RHorizontalGradient;
618 break;
619 default:
620 wwarning("unknow direction in '%s', falling back to diagonal", type);
621 case 'D':
622 style = RDiagonalGradient;
623 break;
626 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
627 str2rcolor(rc, str, &rcolor);
628 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
629 str2rcolor(rc, str, &rcolor2);
631 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
633 image = RMakeTiledImage(timage, width, height);
634 RReleaseImage(timage);
636 i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
638 RCombineImagesWithOpaqueness(image, grad, i);
639 RReleaseImage(grad);
641 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'M') {
642 RGradientStyle style;
643 RColor **colors;
644 int i, j;
646 switch (toupper(type[1])) {
647 case 'V':
648 style = RVerticalGradient;
649 break;
650 case 'H':
651 style = RHorizontalGradient;
652 break;
653 default:
654 wwarning("unknow direction in '%s', falling back to diagonal", type);
655 case 'D':
656 style = RDiagonalGradient;
657 break;
660 j = WMGetPropListItemCount(texture);
662 if (j > 0) {
663 colors = wmalloc(j * sizeof(RColor *));
665 for (i = 2; i < j; i++) {
666 str = WMGetFromPLString(WMGetFromPLArray(texture, i));
667 colors[i - 2] = wmalloc(sizeof(RColor));
668 str2rcolor(rc, str, colors[i - 2]);
670 colors[i - 2] = NULL;
672 image = RRenderMultiGradient(width, height, colors, style);
674 for (i = 0; colors[i] != NULL; i++)
675 wfree(colors[i]);
676 wfree(colors);
678 } else if (strcasecmp(&type[1], "pixmap") == 0) {
679 RColor color;
681 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
682 str2rcolor(rc, str, &color);
684 switch (toupper(type[0])) {
685 case 'T':
686 image = RMakeTiledImage(timage, width, height);
687 RReleaseImage(timage);
688 break;
689 case 'C':
690 image = RMakeCenteredImage(timage, width, height, &color);
691 RReleaseImage(timage);
692 break;
693 case 'F':
694 case 'S':
695 case 'M':
696 image = RScaleImage(timage, width, height);
697 RReleaseImage(timage);
698 break;
700 default:
701 wwarning("type '%s' in not a supported type for a texture", type);
702 RReleaseImage(timage);
703 return None;
707 if (!image)
708 return None;
710 if (path) {
711 dumpRImage(path, image);
714 if (border < 0) {
715 if (border == RESIZEBAR_BEVEL) {
716 drawResizebarBevel(image);
717 } else if (border == MENU_BEVEL) {
718 drawMenuBevel(image);
719 RBevelImage(image, RBEV_RAISED2);
721 } else if (border) {
722 RBevelImage(image, border);
725 RConvertImage(rc, image, &pixmap);
726 RReleaseImage(image);
728 return pixmap;
731 static Pixmap renderMenu(_Panel * panel, WMPropList * texture, int width, int iheight)
733 WMScreen *scr = WMWidgetScreen(panel->parent);
734 Display *dpy = WMScreenDisplay(scr);
735 Pixmap pix, tmp;
736 GC gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
737 int i;
739 switch (panel->menuStyle) {
740 case MSTYLE_NORMAL:
741 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
743 pix = XCreatePixmap(dpy, tmp, width, iheight * 4, WMScreenDepth(scr));
744 for (i = 0; i < 4; i++) {
745 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight * i);
747 XFreePixmap(dpy, tmp);
748 break;
749 case MSTYLE_SINGLE:
750 pix = renderTexture(scr, texture, width, iheight * 4, NULL, MENU_BEVEL);
751 break;
752 case MSTYLE_FLAT:
753 pix = renderTexture(scr, texture, width, iheight * 4, NULL, RBEV_RAISED2);
754 break;
755 default:
756 pix = None;
758 XFreeGC(dpy, gc);
760 return pix;
763 static void renderPreview(_Panel * panel, GC gc, int part, int relief)
765 WMListItem *item;
766 TextureListItem *titem;
767 Pixmap pix;
768 WMScreen *scr = WMWidgetScreen(panel->box);
770 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
771 titem = (TextureListItem *) item->clientData;
773 pix = renderTexture(scr, titem->prop,
774 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
775 NULL, relief);
777 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
778 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
779 textureOptions[part].preview.pos.x, textureOptions[part].preview.pos.y);
781 XCopyArea(WMScreenDisplay(scr), pix, panel->previewNoText, gc, 0, 0,
782 textureOptions[part].preview.size.width, textureOptions[part].preview.size.height,
783 textureOptions[part].preview.pos.x, textureOptions[part].preview.pos.y);
785 XFreePixmap(WMScreenDisplay(scr), pix);
788 static void updatePreviewBox(_Panel * panel, int elements)
790 WMScreen *scr = WMWidgetScreen(panel->parent);
791 Display *dpy = WMScreenDisplay(scr);
792 Pixmap pix;
793 GC gc;
794 int colorUpdate = 0;
796 gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
798 if (panel->preview == None) {
799 WMPixmap *p;
801 panel->previewNoText = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
802 240 - 4, 215 - 4, WMScreenDepth(scr));
803 panel->previewBack = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
804 240 - 4, 215 - 4, WMScreenDepth(scr));
806 p = WMCreatePixmap(scr, 240 - 4, 215 - 4, WMScreenDepth(scr), False);
807 panel->preview = WMGetPixmapXID(p);
808 WMSetLabelImage(panel->prevL, p);
809 WMReleasePixmap(p);
811 if (elements & (1 << PBACKGROUND)) {
812 Pixmap tmp;
813 TextureListItem *titem;
814 WMListItem *item;
816 item = WMGetListItem(panel->texLs,
817 panel->textureIndex[PBACKGROUND]);
818 titem = (TextureListItem *) item->clientData;
819 tmp = renderTexture(scr, titem->prop, 240 - 4, 215 - 4, NULL, 0);
821 XCopyArea(dpy, tmp, panel->preview, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
822 XCopyArea(dpy, tmp, panel->previewNoText, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
823 XCopyArea(dpy, tmp, panel->previewBack, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
824 XFreePixmap(dpy, tmp);
827 if (elements & (1 << PFOCUSED)) {
828 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
829 colorUpdate |= 1 << FTITLE_COL | 1 << FFBORDER_COL;
831 if (elements & (1 << PUNFOCUSED)) {
832 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
833 colorUpdate |= 1 << UTITLE_COL | 1 << FBORDER_COL;
835 if (elements & (1 << POWNER)) {
836 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
837 colorUpdate |= 1 << OTITLE_COL | 1 << FBORDER_COL;
839 if (elements & (1 << PRESIZEBAR)) {
840 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
841 colorUpdate |= 1 << FBORDER_COL;
843 if (elements & (1 << PMTITLE)) {
844 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
845 colorUpdate |= 1 << MTITLE_COL | 1 << FBORDER_COL;
847 if (elements & (1 << PMITEM)) {
848 WMListItem *item;
849 TextureListItem *titem;
851 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
852 titem = (TextureListItem *) item->clientData;
854 pix = renderMenu(panel, titem->prop,
855 textureOptions[PMITEM].preview.size.width,
856 textureOptions[PMITEM].preview.size.height / 4);
858 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
859 textureOptions[PMITEM].preview.size.width, textureOptions[PMITEM].preview.size.height,
860 textureOptions[PMITEM].preview.pos.x, textureOptions[PMITEM].preview.pos.y);
862 XCopyArea(dpy, pix, panel->previewNoText, gc, 0, 0,
863 textureOptions[PMITEM].preview.size.width, textureOptions[PMITEM].preview.size.height,
864 textureOptions[PMITEM].preview.pos.x, textureOptions[PMITEM].preview.pos.y);
866 XFreePixmap(dpy, pix);
868 colorUpdate |= 1 << MITEM_COL | 1 << MDISAB_COL |
869 1 << MHIGH_COL | 1 << MHIGHT_COL |
870 1 << FBORDER_COL;
872 if (elements & (1 << PICON)) {
873 WMListItem *item;
874 TextureListItem *titem;
876 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
877 titem = (TextureListItem *) item->clientData;
879 renderPreview(panel, gc, PICON, titem->ispixmap ? 0 : RBEV_RAISED3);
882 if (colorUpdate)
883 updateColorPreviewBox(panel, colorUpdate);
884 else
885 WMRedisplayWidget(panel->prevL);
887 XFreeGC(dpy, gc);
890 static void cancelNewTexture(void *data)
892 _Panel *panel = (_Panel *) data;
894 HideTexturePanel(panel->texturePanel);
897 static char *makeFileName(const char *prefix)
899 char *fname;
901 fname = wstrdup(prefix);
903 while (access(fname, F_OK) == 0) {
904 char buf[30];
906 wfree(fname);
907 sprintf(buf, "%08lx.cache", time(NULL));
908 fname = wstrconcat(prefix, buf);
911 return fname;
914 static void okNewTexture(void *data)
916 _Panel *panel = (_Panel *) data;
917 WMListItem *item;
918 char *name;
919 char *str;
920 WMPropList *prop;
921 TextureListItem *titem;
922 WMScreen *scr = WMWidgetScreen(panel->parent);
924 titem = wmalloc(sizeof(TextureListItem));
926 HideTexturePanel(panel->texturePanel);
928 name = GetTexturePanelTextureName(panel->texturePanel);
930 prop = GetTexturePanelTexture(panel->texturePanel);
932 str = WMGetPropListDescription(prop, False);
934 titem->title = name;
935 titem->prop = prop;
936 titem->texture = str;
937 titem->selectedFor = 0;
939 titem->ispixmap = isPixmap(prop);
941 titem->path = makeFileName(panel->fprefix);
942 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
944 item = WMAddListItem(panel->texLs, "");
945 item->clientData = titem;
947 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
950 static void okEditTexture(void *data)
952 _Panel *panel = (_Panel *) data;
953 WMListItem *item;
954 char *name;
955 char *str;
956 WMPropList *prop;
957 TextureListItem *titem;
959 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
960 titem = (TextureListItem *) item->clientData;
962 HideTexturePanel(panel->texturePanel);
964 if (titem->current) {
965 name = GetTexturePanelTextureName(panel->texturePanel);
967 wfree(titem->title);
968 titem->title = name;
971 prop = GetTexturePanelTexture(panel->texturePanel);
973 str = WMGetPropListDescription(prop, False);
975 WMReleasePropList(titem->prop);
976 titem->prop = prop;
978 titem->ispixmap = isPixmap(prop);
980 wfree(titem->texture);
981 titem->texture = str;
983 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
984 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
985 TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
987 WMRedisplayWidget(panel->texLs);
989 if (titem->selectedFor) {
990 if (titem->selectedFor & (1 << PBACKGROUND))
991 updatePreviewBox(panel, EVERYTHING);
992 else
993 updatePreviewBox(panel, titem->selectedFor);
996 changePage(panel->secP, panel);
999 static void editTexture(WMWidget * w, void *data)
1001 _Panel *panel = (_Panel *) data;
1002 WMListItem *item;
1003 TextureListItem *titem;
1005 /* Parameter not used, but tell the compiler that it is ok */
1006 (void) w;
1008 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
1009 titem = (TextureListItem *) item->clientData;
1011 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
1013 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
1015 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1016 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
1018 ShowTexturePanel(panel->texturePanel);
1021 static void newTexture(WMWidget * w, void *data)
1023 _Panel *panel = (_Panel *) data;
1025 /* Parameter not used, but tell the compiler that it is ok */
1026 (void) w;
1028 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
1030 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1032 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1034 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1036 ShowTexturePanel(panel->texturePanel);
1039 static void deleteTexture(WMWidget * w, void *data)
1041 _Panel *panel = (_Panel *) data;
1042 WMListItem *item;
1043 TextureListItem *titem;
1044 int row;
1045 int section;
1047 /* Parameter not used, but tell the compiler that it is ok */
1048 (void) w;
1050 section = WMGetPopUpButtonSelectedItem(panel->secP);
1051 row = WMGetListSelectedItemRow(panel->texLs);
1052 item = WMGetListItem(panel->texLs, row);
1053 titem = (TextureListItem *) item->clientData;
1055 if (titem->selectedFor & (1 << section)) {
1056 TextureListItem *titem2;
1058 panel->textureIndex[section] = section;
1059 item = WMGetListItem(panel->texLs, section);
1060 titem2 = (TextureListItem *) item->clientData;
1061 titem2->selectedFor |= 1 << section;
1064 wfree(titem->title);
1065 wfree(titem->texture);
1066 WMReleasePropList(titem->prop);
1067 if (titem->path) {
1068 if (remove(titem->path) < 0 && errno != ENOENT) {
1069 werror("could not remove file %s", titem->path);
1071 wfree(titem->path);
1074 wfree(titem);
1076 WMRemoveListItem(panel->texLs, row);
1077 WMSetButtonEnabled(panel->delB, False);
1080 static void extractTexture(WMWidget * w, void *data)
1082 _Panel *panel = (_Panel *) data;
1083 char *path;
1084 WMOpenPanel *opanel;
1085 WMScreen *scr = WMWidgetScreen(w);
1087 opanel = WMGetOpenPanel(scr);
1088 WMSetFilePanelCanChooseDirectories(opanel, False);
1089 WMSetFilePanelCanChooseFiles(opanel, True);
1091 if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(), _("Select File"), NULL)) {
1092 path = WMGetFilePanelFileName(opanel);
1094 OpenExtractPanelFor(panel);
1096 wfree(path);
1100 static void changePage(WMWidget * w, void *data)
1102 _Panel *panel = (_Panel *) data;
1103 int section;
1104 WMScreen *scr = WMWidgetScreen(panel->box);
1105 RContext *rc = WMScreenRContext(scr);
1107 if (w) {
1108 section = WMGetPopUpButtonSelectedItem(panel->secP);
1110 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1112 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1115 GC gc;
1117 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1118 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1119 textureOptions[panel->oldsection].hand.x, textureOptions[panel->oldsection].hand.y, 22, 22,
1120 textureOptions[panel->oldsection].hand.x, textureOptions[panel->oldsection].hand.y);
1122 if (w) {
1123 panel->oldsection = section;
1124 WMDrawPixmap(panel->hand, panel->preview, textureOptions[section].hand.x, textureOptions[section].hand.y);
1126 WMRedisplayWidget(panel->prevL);
1129 static void previewClick(XEvent * event, void *clientData)
1131 _Panel *panel = (_Panel *) clientData;
1132 int i;
1134 switch (panel->oldTabItem) {
1135 case 0:
1136 for (i = 0; i < wlengthof(textureOptions); i++) {
1137 if (event->xbutton.x >= textureOptions[i].preview.pos.x &&
1138 event->xbutton.y >= textureOptions[i].preview.pos.y &&
1139 event->xbutton.x < textureOptions[i].preview.pos.x + textureOptions[i].preview.size.width &&
1140 event->xbutton.y < textureOptions[i].preview.pos.y + textureOptions[i].preview.size.height) {
1142 WMSetPopUpButtonSelectedItem(panel->secP, i);
1143 changePage(panel->secP, panel);
1144 return;
1147 break;
1148 case 1:
1149 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1150 if (event->xbutton.x >= colorOptions[i].preview.pos.x &&
1151 event->xbutton.y >= colorOptions[i].preview.pos.y &&
1152 event->xbutton.x < colorOptions[i].preview.pos.x + colorOptions[i].preview.size.width &&
1153 event->xbutton.y < colorOptions[i].preview.pos.y + colorOptions[i].preview.size.height) {
1156 * yuck kluge: the entry #7 is HighlightTextColor which does not have actually a
1157 * display area, but are reused to make the last "Normal Item" menu entry actually
1158 * pick the same color item as the other similar item displayed, which corresponds
1159 * to MenuTextColor
1161 if (i == 7)
1162 i = 4;
1164 WMSetPopUpButtonSelectedItem(panel->colP, i);
1165 changeColorPage(panel->colP, panel);
1166 return;
1169 break;
1173 static void textureClick(WMWidget * w, void *data)
1175 _Panel *panel = (_Panel *) data;
1176 int i;
1177 WMListItem *item;
1178 TextureListItem *titem;
1180 /* Parameter not used, but tell the compiler that it is ok */
1181 (void) w;
1183 i = WMGetListSelectedItemRow(panel->texLs);
1185 item = WMGetListItem(panel->texLs, i);
1187 titem = (TextureListItem *) item->clientData;
1189 if (titem->current) {
1190 WMSetButtonEnabled(panel->delB, False);
1191 } else {
1192 WMSetButtonEnabled(panel->delB, True);
1196 static void textureDoubleClick(WMWidget * w, void *data)
1198 _Panel *panel = (_Panel *) data;
1199 int i, section;
1200 WMListItem *item;
1201 TextureListItem *titem;
1203 /* Parameter not used, but tell the compiler that it is ok */
1204 (void) w;
1206 /* unselect old texture */
1207 section = WMGetPopUpButtonSelectedItem(panel->secP);
1209 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1210 titem = (TextureListItem *) item->clientData;
1211 titem->selectedFor &= ~(1 << section);
1213 /* select new texture */
1214 i = WMGetListSelectedItemRow(panel->texLs);
1216 item = WMGetListItem(panel->texLs, i);
1218 titem = (TextureListItem *) item->clientData;
1220 titem->selectedFor |= 1 << section;
1222 panel->textureIndex[section] = i;
1224 WMRedisplayWidget(panel->texLs);
1226 if (section == PBACKGROUND)
1227 updatePreviewBox(panel, EVERYTHING);
1228 else
1229 updatePreviewBox(panel, 1 << section);
1232 static void paintListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
1234 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
1235 WMScreen *scr = WMWidgetScreen(lPtr);
1236 int width, height, x, y;
1237 Display *dpy = WMScreenDisplay(scr);
1238 WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
1239 WMListItem *item;
1240 WMColor *black = WMBlackColor(scr);
1241 TextureListItem *titem;
1243 /* Parameter not used, but tell the compiler that it is ok */
1244 (void) text;
1246 item = WMGetListItem(lPtr, index);
1247 titem = (TextureListItem *) item->clientData;
1248 if (!titem) {
1249 WMReleaseColor(back);
1250 WMReleaseColor(black);
1251 return;
1254 width = rect->size.width;
1255 height = rect->size.height;
1256 x = rect->pos.x;
1257 y = rect->pos.y;
1259 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
1261 if (titem->preview)
1262 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1263 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1265 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1266 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1267 else if (titem->selectedFor)
1268 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1270 WMDrawString(scr, d, black, panel->boldFont,
1271 x + TEXPREV_WIDTH + 22, y + 2, titem->title, strlen(titem->title));
1273 WMDrawString(scr, d, black, panel->smallFont,
1274 x + TEXPREV_WIDTH + 14, y + 18, titem->texture, strlen(titem->texture));
1276 WMReleaseColor(back);
1277 WMReleaseColor(black);
1280 static Pixmap loadRImage(WMScreen * scr, const char *path)
1282 FILE *f;
1283 RImage *image;
1284 int w, h, d, cnt;
1285 size_t read_size;
1286 Pixmap pixmap;
1288 f = fopen(path, "rb");
1289 if (!f)
1290 return None;
1292 cnt = fscanf(f, "%02x%02x%1x", &w, &h, &d);
1293 if (cnt != 3) {
1294 fclose(f);
1295 return None;
1297 image = RCreateImage(w, h, d == 4);
1298 read_size = w * h * d;
1299 if (fread(image->data, 1, read_size, f) == read_size)
1300 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1301 else
1302 pixmap = None;
1304 fclose(f);
1306 RReleaseImage(image);
1308 return pixmap;
1311 static void fillTextureList(WMList * lPtr)
1313 WMPropList *textureList;
1314 WMPropList *texture;
1315 WMUserDefaults *udb = WMGetStandardUserDefaults();
1316 TextureListItem *titem;
1317 WMScreen *scr = WMWidgetScreen(lPtr);
1318 int i;
1320 textureList = WMGetUDObjectForKey(udb, "TextureList");
1321 if (!textureList)
1322 return;
1324 for (i = 0; i < WMGetPropListItemCount(textureList); i++) {
1325 WMListItem *item;
1327 texture = WMGetFromPLArray(textureList, i);
1329 titem = wmalloc(sizeof(TextureListItem));
1331 titem->title = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 0)));
1332 titem->prop = WMRetainPropList(WMGetFromPLArray(texture, 1));
1333 titem->texture = WMGetPropListDescription(titem->prop, False);
1334 titem->selectedFor = 0;
1335 titem->path = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
1337 titem->preview = loadRImage(scr, titem->path);
1338 if (!titem->preview) {
1339 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1341 item = WMAddListItem(lPtr, "");
1342 item->clientData = titem;
1346 static void fillColorList(_Panel * panel)
1348 WMColor *color;
1349 WMPropList *list;
1350 WMUserDefaults *udb = WMGetStandardUserDefaults();
1351 WMScreen *scr = WMWidgetScreen(panel->box);
1352 int i;
1354 list = WMGetUDObjectForKey(udb, "ColorList");
1355 if (!list) {
1356 for (i = 0; i < 24; i++) {
1357 color = WMCreateNamedColor(scr, sampleColors[i], False);
1358 if (!color)
1359 continue;
1360 WMSetColorWellColor(panel->sampW[i], color);
1361 WMReleaseColor(color);
1363 } else {
1364 WMPropList *c;
1366 for (i = 0; i < WMIN(24, WMGetPropListItemCount(list)); i++) {
1367 c = WMGetFromPLArray(list, i);
1368 if (!c || !WMIsPLString(c))
1369 continue;
1370 color = WMCreateNamedColor(scr, WMGetFromPLString(c), False);
1371 if (!color)
1372 continue;
1373 WMSetColorWellColor(panel->sampW[i], color);
1374 WMReleaseColor(color);
1379 /*************************************************************************/
1381 static void changeColorPage(WMWidget * w, void *data)
1383 _Panel *panel = (_Panel *) data;
1384 int section;
1385 WMScreen *scr = WMWidgetScreen(panel->box);
1386 RContext *rc = WMScreenRContext(scr);
1388 if (panel->preview) {
1389 GC gc;
1391 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1392 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1393 colorOptions[panel->oldcsection].hand.x,
1394 colorOptions[panel->oldcsection].hand.y, 22, 22 ,
1395 colorOptions[panel->oldcsection].hand.x,
1396 colorOptions[panel->oldcsection].hand.y);
1398 if (w) {
1399 section = WMGetPopUpButtonSelectedItem(panel->colP);
1401 panel->oldcsection = section;
1402 if (panel->preview)
1403 WMDrawPixmap(panel->hand, panel->preview,
1404 colorOptions[section].hand.x, colorOptions[section].hand.y);
1406 if (section >= ICONT_COL)
1407 updateColorPreviewBox(panel, 1 << section);
1409 WMSetColorWellColor(panel->colW, panel->colors[section]);
1411 WMRedisplayWidget(panel->prevL);
1414 static void
1415 paintText(WMScreen * scr, Drawable d, WMColor * color, WMFont * font,
1416 int x, int y, int w, int h, WMAlignment align, char *text)
1418 int l = strlen(text);
1420 switch (align) {
1421 case WALeft:
1422 x += 5;
1423 break;
1424 case WARight:
1425 x += w - 5 - WMWidthOfString(font, text, l);
1426 break;
1427 default:
1428 case WACenter:
1429 x += (w - WMWidthOfString(font, text, l)) / 2;
1430 break;
1432 WMDrawString(scr, d, color, font, x, y + (h - WMFontHeight(font)) / 2, text, l);
1435 static void updateColorPreviewBox(_Panel * panel, int elements)
1437 WMScreen *scr = WMWidgetScreen(panel->box);
1438 Display *dpy = WMScreenDisplay(scr);
1439 Pixmap d, pnot;
1440 GC gc;
1442 d = panel->preview;
1443 pnot = panel->previewNoText;
1444 gc = WMColorGC(panel->colors[FTITLE_COL]);
1446 if (elements & (1 << FTITLE_COL)) {
1447 XCopyArea(dpy, pnot, d, gc, 30, 10, 190, 20, 30, 10);
1448 paintText(scr, d, panel->colors[FTITLE_COL],
1449 panel->boldFont, 30, 10, 190, 20,
1450 panel->titleAlignment, _("Focused Window"));
1452 if (elements & (1 << UTITLE_COL)) {
1453 XCopyArea(dpy, pnot, d, gc, 30, 40, 190, 20, 30, 40);
1454 paintText(scr, d, panel->colors[UTITLE_COL],
1455 panel->boldFont, 30, 40, 190, 20,
1456 panel->titleAlignment,
1457 _("Unfocused Window"));
1459 if (elements & (1 << OTITLE_COL)) {
1460 XCopyArea(dpy, pnot, d, gc, 30, 70, 190, 20, 30, 70);
1461 paintText(scr, d, panel->colors[OTITLE_COL],
1462 panel->boldFont, 30, 70, 190, 20,
1463 panel->titleAlignment,
1464 _("Owner of Focused Window"));
1466 if (elements & (1 << MTITLE_COL)) {
1467 XCopyArea(dpy, pnot, d, gc, 30, 120, 90, 20, 30, 120);
1468 paintText(scr, d, panel->colors[MTITLE_COL],
1469 panel->boldFont, 30, 120, 90, 20, WALeft,
1470 _("Menu Title"));
1472 if (elements & (1 << MITEM_COL)) {
1473 XCopyArea(dpy, pnot, d, gc, 30, 140, 90, 20, 30, 140);
1474 paintText(scr, d, panel->colors[MITEM_COL],
1475 panel->normalFont, 30, 140, 90, 20, WALeft,
1476 _("Normal Item"));
1477 XCopyArea(dpy, pnot, d, gc, 30, 200, 90, 20, 30, 200);
1478 paintText(scr, d, panel->colors[MITEM_COL],
1479 panel->normalFont, 30, 200, 90, 20, WALeft,
1480 _("Normal Item"));
1482 if (elements & (1 << MDISAB_COL)) {
1483 XCopyArea(dpy, pnot, d, gc, 30, 160, 90, 20, 30, 160);
1484 paintText(scr, d, panel->colors[MDISAB_COL],
1485 panel->normalFont, 30, 160, 90, 20, WALeft,
1486 _("Disabled Item"));
1488 if (elements & (1 << MHIGH_COL)) {
1489 XFillRectangle(WMScreenDisplay(scr), d,
1490 WMColorGC(panel->colors[MHIGH_COL]),
1491 31, 181, 87, 17);
1492 XFillRectangle(WMScreenDisplay(scr), pnot,
1493 WMColorGC(panel->colors[MHIGH_COL]),
1494 31, 181, 87, 17);
1495 elements |= 1 << MHIGHT_COL;
1497 if (elements & (1 << MHIGHT_COL)) {
1498 XCopyArea(dpy, pnot, d, gc, 30, 180, 90, 20, 30, 180);
1499 paintText(scr, d, panel->colors[MHIGHT_COL],
1500 panel->normalFont, 30, 180, 90, 20, WALeft,
1501 _("Highlighted"));
1503 if (elements & (1 << FBORDER_COL)) {
1504 XDrawRectangle(dpy, pnot,
1505 WMColorGC(panel->colors[FBORDER_COL]),
1506 29, 39, 190, 20);
1507 XDrawRectangle(dpy, d,
1508 WMColorGC(panel->colors[FBORDER_COL]),
1509 29, 39, 190, 20);
1510 XDrawRectangle(dpy, pnot,
1511 WMColorGC(panel->colors[FBORDER_COL]),
1512 29, 69, 190, 20);
1513 XDrawRectangle(dpy, d,
1514 WMColorGC(panel->colors[FBORDER_COL]),
1515 29, 69, 190, 20);
1516 XDrawLine(dpy, pnot,
1517 WMColorGC(panel->colors[FBORDER_COL]),
1518 30, 100, 30, 109);
1519 XDrawLine(dpy, d,
1520 WMColorGC(panel->colors[FBORDER_COL]),
1521 30, 100, 30, 109);
1522 XDrawLine(dpy, pnot,
1523 WMColorGC(panel->colors[FBORDER_COL]),
1524 31, 109, 219, 109);
1525 XDrawLine(dpy, d,
1526 WMColorGC(panel->colors[FBORDER_COL]),
1527 31, 109, 219, 109);
1528 XDrawLine(dpy, pnot,
1529 WMColorGC(panel->colors[FBORDER_COL]),
1530 220, 100, 220, 109);
1531 XDrawLine(dpy, d,
1532 WMColorGC(panel->colors[FBORDER_COL]),
1533 220, 100, 220, 109);
1534 XDrawLine(dpy, pnot,
1535 WMColorGC(panel->colors[FBORDER_COL]),
1536 29, 120, 29, 220);
1537 XDrawLine(dpy, d,
1538 WMColorGC(panel->colors[FBORDER_COL]),
1539 29, 120, 29, 220);
1540 XDrawLine(dpy, pnot,
1541 WMColorGC(panel->colors[FBORDER_COL]),
1542 29, 119, 119, 119);
1543 XDrawLine(dpy, d,
1544 WMColorGC(panel->colors[FBORDER_COL]),
1545 29, 119, 119, 119);
1546 XDrawLine(dpy, pnot,
1547 WMColorGC(panel->colors[FBORDER_COL]),
1548 119, 120, 119, 220);
1549 XDrawLine(dpy, d,
1550 WMColorGC(panel->colors[FBORDER_COL]),
1551 119, 120, 119, 220);
1554 if (elements & (1 << FFBORDER_COL)) {
1555 XDrawRectangle(dpy, pnot,
1556 WMColorGC(panel->colors[FFBORDER_COL]),
1557 29, 9, 190, 20);
1558 XDrawRectangle(dpy, d,
1559 WMColorGC(panel->colors[FFBORDER_COL]),
1560 29, 9, 190, 20);
1563 if (elements & (1 << ICONT_COL) || elements & (1 << ICONB_COL)) {
1564 RColor rgb;
1565 RHSVColor hsv, hsv2;
1566 int v;
1567 WMColor *light, *dim;
1569 updatePreviewBox(panel, 1 << PICON);
1571 rgb.red = WMRedComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1572 rgb.green = WMGreenComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1573 rgb.blue = WMBlueComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1574 RRGBtoHSV(&rgb, &hsv);
1575 RHSVtoRGB(&hsv, &rgb);
1576 hsv2 = hsv;
1578 v = hsv.value * 16 / 10;
1579 hsv.value = (v > 255 ? 255 : v);
1580 RHSVtoRGB(&hsv, &rgb);
1581 light = WMCreateRGBColor(scr, rgb.red << 8, rgb.green << 8, rgb.blue << 8, False);
1583 hsv2.value = hsv2.value / 2;
1584 RHSVtoRGB(&hsv2, &rgb);
1585 dim = WMCreateRGBColor(scr, rgb.red << 8, rgb.green << 8, rgb.blue << 8, False);
1587 XFillRectangle(dpy, d, WMColorGC(panel->colors[ICONB_COL]), 156, 131, 62, 11);
1588 XDrawLine(dpy, d, WMColorGC(light), 155, 130, 155, 142);
1589 XDrawLine(dpy, d, WMColorGC(light), 156, 130, 217, 130);
1590 XDrawLine(dpy, d, WMColorGC(dim), 218, 130, 218, 142);
1592 paintText(scr, d, panel->colors[ICONT_COL],
1593 panel->smallFont, 155, 130, 64, 13, WALeft,
1594 _("Icon Text"));
1598 if (elements & (1 << CLIP_COL) || elements & (1 << CCLIP_COL)) {
1599 Pixmap pix;
1600 RColor black;
1601 RColor dark;
1602 RColor light;
1603 RImage *tile;
1604 TextureListItem *titem;
1605 WMListItem *item;
1606 XPoint p[4];
1608 item = WMGetListItem(panel->texLs, panel->textureIndex[PICON]);
1609 titem = (TextureListItem *) item->clientData;
1611 pix = renderTexture(scr, titem->prop, 64, 64, NULL, titem->ispixmap ? 0 : RBEV_RAISED3);
1612 tile = RCreateImageFromDrawable(WMScreenRContext(scr), pix, None);
1614 black.alpha = 255;
1615 black.red = black.green = black.blue = 0;
1617 dark.alpha = 0;
1618 dark.red = dark.green = dark.blue = 60;
1620 light.alpha = 0;
1621 light.red = light.green = light.blue = 80;
1623 /* top right */
1624 ROperateLine(tile, RSubtractOperation, 64 - 1 - 23, 0, 64 - 2, 23 - 1, &dark);
1625 RDrawLine(tile, 64 - 1 - 23 - 1, 0, 64 - 1, 23 + 1, &black);
1626 ROperateLine(tile, RAddOperation, 64 - 1 - 23, 2, 64 - 3, 23, &light);
1628 /* arrow bevel */
1629 ROperateLine(tile, RSubtractOperation, 64 - 7 - (23 - 15), 4, 64 - 5, 4, &dark);
1630 ROperateLine(tile, RSubtractOperation, 64 - 6 - (23 - 15), 5, 64 - 5, 6 + 23 - 15, &dark);
1631 ROperateLine(tile, RAddOperation, 64 - 5, 4, 64 - 5, 6 + 23 - 15, &light);
1633 /* bottom left */
1634 ROperateLine(tile, RAddOperation, 2, 64 - 1 - 23 + 2, 23 - 2, 64 - 3, &dark);
1635 RDrawLine(tile, 0, 64 - 1 - 23 - 1, 23 + 1, 64 - 1, &black);
1636 ROperateLine(tile, RSubtractOperation, 0, 64 - 1 - 23 - 2, 23 + 1, 64 - 2, &light);
1638 /* arrow bevel */
1639 ROperateLine(tile, RSubtractOperation, 4, 64 - 7 - (23 - 15), 4, 64 - 5, &dark);
1640 ROperateLine(tile, RSubtractOperation, 5, 64 - 6 - (23 - 15), 6 + 23 - 15, 64 - 5, &dark);
1641 ROperateLine(tile, RAddOperation, 4, 64 - 5, 6 + 23 - 15, 64 - 5, &light);
1643 RConvertImage(WMScreenRContext(scr), tile, &pix);
1644 RReleaseImage(tile);
1646 XCopyArea(dpy, pix, d, gc, 0, 0, 64, 64, 155, 130);
1647 XFreePixmap(dpy, pix);
1649 /* top right arrow */
1650 p[0].x = p[3].x = 155 + 64 - 5 - (23 - 15);
1651 p[0].y = p[3].y = 130 + 5;
1652 p[1].x = 155 + 64 - 6;
1653 p[1].y = 130 + 5;
1654 p[2].x = 155 + 64 - 6;
1655 p[2].y = 130 + 4 + 23 - 15;
1657 XFillPolygon(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 3, Convex, CoordModeOrigin);
1658 XDrawLines(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 4, CoordModeOrigin);
1660 /* bottom left arrow */
1661 p[0].x = p[3].x = 155 + 5;
1662 p[0].y = p[3].y = 130 + 64 - 5 - (23 - 15);
1663 p[1].x = 155 + 5;
1664 p[1].y = 130 + 64 - 6;
1665 p[2].x = 155 + 4 + 23 - 15;
1666 p[2].y = 130 + 64 - 6;
1668 XFillPolygon(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 3, Convex, CoordModeOrigin);
1669 XDrawLines(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 4, CoordModeOrigin);
1673 if (elements & (1 << CLIP_COL))
1674 paintText(scr, d, panel->colors[CLIP_COL],
1675 panel->boldFont, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft,
1676 _("Clip"));
1678 if (elements & (1 << CCLIP_COL)) {
1679 paintText(scr, d, panel->colors[CCLIP_COL],
1680 panel->boldFont, 155+2, 130 + 2, 26, 15, WALeft, _("Coll."));
1681 paintText(scr, d, panel->colors[CCLIP_COL],
1682 panel->boldFont, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft,
1683 _("Clip"));
1686 WMRedisplayWidget(panel->prevL);
1689 static void colorWellObserver(void *self, WMNotification * n)
1691 _Panel *panel = (_Panel *) self;
1692 int p;
1694 /* Parameter not used, but tell the compiler that it is ok */
1695 (void) n;
1697 p = WMGetPopUpButtonSelectedItem(panel->colP);
1699 WMReleaseColor(panel->colors[p]);
1701 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1703 updateColorPreviewBox(panel, 1 << p);
1706 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item)
1708 _Panel *panel = self->data;
1709 int i;
1711 /* Parameter not used, but tell the compiler that it is ok */
1712 (void) tabView;
1714 i = WMGetTabViewItemIdentifier(item);
1715 switch (i) {
1716 case TAB_TEXTURE:
1717 switch (panel->oldTabItem) {
1718 case TAB_COLOR:
1719 changeColorPage(NULL, panel);
1720 break;
1722 changePage(panel->secP, panel);
1723 break;
1724 case TAB_COLOR:
1725 switch (panel->oldTabItem) {
1726 case TAB_TEXTURE:
1727 changePage(NULL, panel);
1728 break;
1730 changeColorPage(panel->colP, panel);
1731 break;
1732 case TAB_OPTIONS:
1733 switch (panel->oldTabItem) {
1734 case TAB_TEXTURE:
1735 changePage(NULL, panel);
1736 break;
1737 case TAB_COLOR:
1738 changeColorPage(NULL, panel);
1739 break;
1741 break;
1744 panel->oldTabItem = i;
1747 /*************************************************************************/
1749 static void menuStyleCallback(WMWidget * self, void *data)
1751 _Panel *panel = (_Panel *) data;
1753 if (self == panel->mstyB[0]) {
1754 panel->menuStyle = MSTYLE_NORMAL;
1755 updatePreviewBox(panel, 1 << PMITEM);
1757 } else if (self == panel->mstyB[1]) {
1758 panel->menuStyle = MSTYLE_SINGLE;
1759 updatePreviewBox(panel, 1 << PMITEM);
1761 } else if (self == panel->mstyB[2]) {
1762 panel->menuStyle = MSTYLE_FLAT;
1763 updatePreviewBox(panel, 1 << PMITEM);
1767 static void titleAlignCallback(WMWidget * self, void *data)
1769 _Panel *panel = (_Panel *) data;
1771 if (self == panel->taliB[0]) {
1772 panel->titleAlignment = WALeft;
1773 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1775 } else if (self == panel->taliB[1]) {
1776 panel->titleAlignment = WACenter;
1777 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1779 } else if (self == panel->taliB[2]) {
1780 panel->titleAlignment = WARight;
1781 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1785 static void createPanel(Panel * p)
1787 _Panel *panel = (_Panel *) p;
1788 WMFont *font;
1789 WMScreen *scr = WMWidgetScreen(panel->parent);
1790 WMTabViewItem *item;
1791 int i;
1792 char *tmp;
1793 Bool ok = True;
1795 panel->fprefix = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1797 if (access(panel->fprefix, F_OK) != 0) {
1798 if (mkdir(panel->fprefix, 0755) < 0) {
1799 werror("%s", panel->fprefix);
1800 ok = False;
1803 if (ok) {
1804 tmp = wstrconcat(panel->fprefix, "/WPrefs/");
1805 wfree(panel->fprefix);
1806 panel->fprefix = tmp;
1807 if (access(panel->fprefix, F_OK) != 0) {
1808 if (mkdir(panel->fprefix, 0755) < 0) {
1809 werror("%s", panel->fprefix);
1814 panel->smallFont = WMSystemFontOfSize(scr, 10);
1815 panel->normalFont = WMSystemFontOfSize(scr, 12);
1816 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1818 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1819 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1820 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1822 panel->box = WMCreateBox(panel->parent);
1823 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1825 /* preview box */
1826 panel->prevL = WMCreateLabel(panel->box);
1827 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1828 WMMoveWidget(panel->prevL, 15, 10);
1829 WMSetLabelRelief(panel->prevL, WRSunken);
1830 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1832 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask, previewClick, panel);
1834 /* tabview */
1836 tabviewDelegate.data = panel;
1838 panel->tabv = WMCreateTabView(panel->box);
1839 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1840 WMMoveWidget(panel->tabv, 265, 10);
1841 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1843 /*** texture list ***/
1845 panel->texF = WMCreateFrame(panel->box);
1846 WMSetFrameRelief(panel->texF, WRFlat);
1848 item = WMCreateTabViewItemWithIdentifier(TAB_TEXTURE);
1849 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1850 WMSetTabViewItemLabel(item, _("Texture"));
1852 WMAddItemInTabView(panel->tabv, item);
1854 panel->secP = WMCreatePopUpButton(panel->texF);
1855 WMResizeWidget(panel->secP, 228, 20);
1856 WMMoveWidget(panel->secP, 7, 7);
1858 for (i = 0; i < wlengthof(textureOptions); i++)
1859 WMAddPopUpButtonItem(panel->secP, _(textureOptions[i].popup_label));
1861 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1862 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1864 panel->texLs = WMCreateList(panel->texF);
1865 WMResizeWidget(panel->texLs, 165, 155);
1866 WMMoveWidget(panel->texLs, 70, 33);
1867 WMSetListUserDrawItemHeight(panel->texLs, 35);
1868 WMSetListUserDrawProc(panel->texLs, paintListItem);
1869 WMHangData(panel->texLs, panel);
1870 WMSetListAction(panel->texLs, textureClick, panel);
1871 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1873 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1874 "for the selected item."), WMWidgetView(panel->texLs));
1876 /* command buttons */
1878 font = WMSystemFontOfSize(scr, 10);
1880 panel->newB = WMCreateCommandButton(panel->texF);
1881 WMResizeWidget(panel->newB, 57, 39);
1882 WMMoveWidget(panel->newB, 7, 33);
1883 WMSetButtonFont(panel->newB, font);
1884 WMSetButtonImagePosition(panel->newB, WIPAbove);
1885 WMSetButtonText(panel->newB, _("New"));
1886 WMSetButtonAction(panel->newB, newTexture, panel);
1887 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1889 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel->newB));
1891 panel->ripB = WMCreateCommandButton(panel->texF);
1892 WMResizeWidget(panel->ripB, 57, 39);
1893 WMMoveWidget(panel->ripB, 7, 72);
1894 WMSetButtonFont(panel->ripB, font);
1895 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1896 WMSetButtonText(panel->ripB, _("Extract..."));
1897 WMSetButtonAction(panel->ripB, extractTexture, panel);
1898 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1900 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel->ripB));
1902 WMSetButtonEnabled(panel->ripB, False);
1904 panel->editB = WMCreateCommandButton(panel->texF);
1905 WMResizeWidget(panel->editB, 57, 39);
1906 WMMoveWidget(panel->editB, 7, 111);
1907 WMSetButtonFont(panel->editB, font);
1908 WMSetButtonImagePosition(panel->editB, WIPAbove);
1909 WMSetButtonText(panel->editB, _("Edit"));
1910 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1911 WMSetButtonAction(panel->editB, editTexture, panel);
1912 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel->editB));
1914 panel->delB = WMCreateCommandButton(panel->texF);
1915 WMResizeWidget(panel->delB, 57, 38);
1916 WMMoveWidget(panel->delB, 7, 150);
1917 WMSetButtonFont(panel->delB, font);
1918 WMSetButtonImagePosition(panel->delB, WIPAbove);
1919 WMSetButtonText(panel->delB, _("Delete"));
1920 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1921 WMSetButtonEnabled(panel->delB, False);
1922 WMSetButtonAction(panel->delB, deleteTexture, panel);
1923 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel->delB));
1925 WMReleaseFont(font);
1927 WMMapSubwidgets(panel->texF);
1929 /*** colors ***/
1930 panel->colF = WMCreateFrame(panel->box);
1931 WMSetFrameRelief(panel->colF, WRFlat);
1933 item = WMCreateTabViewItemWithIdentifier(TAB_COLOR);
1934 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1935 WMSetTabViewItemLabel(item, _("Color"));
1937 WMAddItemInTabView(panel->tabv, item);
1939 panel->colP = WMCreatePopUpButton(panel->colF);
1940 WMResizeWidget(panel->colP, 228, 20);
1941 WMMoveWidget(panel->colP, 7, 7);
1943 for (i = 0; i < wlengthof(colorOptions); i++)
1944 WMAddPopUpButtonItem(panel->colP, _(colorOptions[i].label));
1946 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1948 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1950 panel->colW = WMCreateColorWell(panel->colF);
1951 WMResizeWidget(panel->colW, 65, 50);
1952 WMMoveWidget(panel->colW, 30, 75);
1953 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->colW);
1955 for (i = 0; i < 4; i++) {
1956 int j;
1957 for (j = 0; j < 6; j++) {
1958 panel->sampW[i + j * 4] = WMCreateColorWell(panel->colF);
1959 WMResizeWidget(panel->sampW[i + j * 4], 22, 22);
1960 WMMoveWidget(panel->sampW[i + j * 4], 130 + i * 22, 40 + j * 22);
1961 WSetColorWellBordered(panel->sampW[i + j * 4], False);
1965 WMMapSubwidgets(panel->colF);
1967 /*** options ***/
1968 panel->optF = WMCreateFrame(panel->box);
1969 WMSetFrameRelief(panel->optF, WRFlat);
1971 item = WMCreateTabViewItemWithIdentifier(TAB_OPTIONS);
1972 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1973 WMSetTabViewItemLabel(item, _("Options"));
1975 WMAddItemInTabView(panel->tabv, item);
1977 panel->mstyF = WMCreateFrame(panel->optF);
1978 WMResizeWidget(panel->mstyF, 215, 85);
1979 WMMoveWidget(panel->mstyF, 15, 10);
1980 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1982 for (i = 0; i < 3; i++) {
1983 WMPixmap *icon;
1984 char *path;
1986 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1987 WMResizeWidget(panel->mstyB[i], 54, 54);
1988 WMMoveWidget(panel->mstyB[i], 15 + i * 65, 20);
1989 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1990 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1991 switch (i) {
1992 case 0:
1993 path = LocateImage(MSTYLE1_FILE);
1994 break;
1995 case 1:
1996 path = LocateImage(MSTYLE2_FILE);
1997 break;
1998 case 2:
1999 path = LocateImage(MSTYLE3_FILE);
2000 break;
2002 if (path) {
2003 icon = WMCreatePixmapFromFile(scr, path);
2004 if (icon) {
2005 WMSetButtonImage(panel->mstyB[i], icon);
2006 WMReleasePixmap(icon);
2007 } else {
2008 wwarning(_("could not load icon file %s"), path);
2010 wfree(path);
2013 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
2014 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
2016 WMMapSubwidgets(panel->mstyF);
2018 panel->taliF = WMCreateFrame(panel->optF);
2019 WMResizeWidget(panel->taliF, 110, 80);
2020 WMMoveWidget(panel->taliF, 15, 100);
2021 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
2023 for (i = 0; i < 3; i++) {
2024 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
2025 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
2026 switch (i) {
2027 case 0:
2028 WMSetButtonText(panel->taliB[i], _("Left"));
2029 break;
2030 case 1:
2031 WMSetButtonText(panel->taliB[i], _("Center"));
2032 break;
2033 case 2:
2034 WMSetButtonText(panel->taliB[i], _("Right"));
2035 break;
2037 WMResizeWidget(panel->taliB[i], 90, 18);
2038 WMMoveWidget(panel->taliB[i], 10, 15 + 20 * i);
2040 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
2041 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
2043 WMMapSubwidgets(panel->taliF);
2045 WMMapSubwidgets(panel->optF);
2047 /**/ WMRealizeWidget(panel->box);
2048 WMMapSubwidgets(panel->box);
2050 WMSetPopUpButtonSelectedItem(panel->secP, 0);
2052 showData(panel);
2054 changePage(panel->secP, panel);
2056 fillTextureList(panel->texLs);
2058 fillColorList(panel);
2060 panel->texturePanel = CreateTexturePanel(panel->parent);
2063 static void setupTextureFor(WMList *list, const char *key, const char *defValue, const char *title, int index)
2065 WMListItem *item;
2066 TextureListItem *titem;
2068 titem = wmalloc(sizeof(TextureListItem));
2070 titem->title = wstrdup(title);
2071 titem->prop = GetObjectForKey(key);
2072 if (!titem->prop || !WMIsPLArray(titem->prop)) {
2073 /* Maybe also give a error message to stderr that the entry is bad? */
2074 titem->prop = WMCreatePropListFromDescription(defValue);
2075 } else {
2076 WMRetainPropList(titem->prop);
2078 titem->texture = WMGetPropListDescription((WMPropList *) titem->prop, False);
2079 titem->current = 1;
2080 titem->selectedFor = 1 << index;
2082 titem->ispixmap = isPixmap(titem->prop);
2084 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
2086 item = WMAddListItem(list, "");
2087 item->clientData = titem;
2090 static void showData(_Panel * panel)
2092 int i;
2093 const char *str;
2095 str = GetStringForKey("MenuStyle");
2096 if (str && strcasecmp(str, "flat") == 0) {
2097 panel->menuStyle = MSTYLE_FLAT;
2098 } else if (str && strcasecmp(str, "singletexture") == 0) {
2099 panel->menuStyle = MSTYLE_SINGLE;
2100 } else {
2101 panel->menuStyle = MSTYLE_NORMAL;
2104 str = GetStringForKey("TitleJustify");
2105 if (str && strcasecmp(str, "left") == 0) {
2106 panel->titleAlignment = WALeft;
2107 } else if (str && strcasecmp(str, "right") == 0) {
2108 panel->titleAlignment = WARight;
2109 } else {
2110 panel->titleAlignment = WACenter;
2113 for (i = 0; i < wlengthof(colorOptions); i++) {
2114 WMColor *color;
2116 str = GetStringForKey(colorOptions[i].key);
2117 if (!str)
2118 str = colorOptions[i].default_value;
2120 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->box), str, False))) {
2121 color = WMCreateNamedColor(WMWidgetScreen(panel->box), "#000000", False);
2124 panel->colors[i] = color;
2126 changeColorPage(panel->colP, panel);
2128 for (i = 0; i < wlengthof(textureOptions); i++) {
2129 setupTextureFor(panel->texLs, textureOptions[i].key,
2130 textureOptions[i].default_value, _(textureOptions[i].texture_label), i);
2131 panel->textureIndex[i] = i;
2133 updatePreviewBox(panel, EVERYTHING);
2135 WMSetButtonSelected(panel->mstyB[panel->menuStyle], True);
2136 WMSetButtonSelected(panel->taliB[panel->titleAlignment], True);
2139 static void storeData(_Panel * panel)
2141 TextureListItem *titem;
2142 WMListItem *item;
2143 int i;
2145 for (i = 0; i < wlengthof(textureOptions); i++) {
2146 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2147 titem = (TextureListItem *) item->clientData;
2148 SetObjectForKey(titem->prop, textureOptions[i].key);
2151 for (i = 0; i < wlengthof(colorOptions); i++) {
2152 char *str;
2154 str = WMGetColorRGBDescription(panel->colors[i]);
2156 if (str) {
2157 SetStringForKey(str, colorOptions[i].key);
2158 wfree(str);
2162 switch (panel->menuStyle) {
2163 case MSTYLE_SINGLE:
2164 SetStringForKey("singletexture", "MenuStyle");
2165 break;
2166 case MSTYLE_FLAT:
2167 SetStringForKey("flat", "MenuStyle");
2168 break;
2169 default:
2170 case MSTYLE_NORMAL:
2171 SetStringForKey("normal", "MenuStyle");
2172 break;
2174 switch (panel->titleAlignment) {
2175 case WALeft:
2176 SetStringForKey("left", "TitleJustify");
2177 break;
2178 case WARight:
2179 SetStringForKey("right", "TitleJustify");
2180 break;
2181 default:
2182 case WACenter:
2183 SetStringForKey("center", "TitleJustify");
2184 break;
2188 static void prepareForClose(_Panel * panel)
2190 WMPropList *textureList;
2191 WMPropList *texture;
2192 TextureListItem *titem;
2193 WMListItem *item;
2194 WMUserDefaults *udb = WMGetStandardUserDefaults();
2195 int i;
2197 textureList = WMCreatePLArray(NULL, NULL);
2199 /* store list of textures */
2200 for (i = 8; i < WMGetListNumberOfRows(panel->texLs); i++) {
2201 item = WMGetListItem(panel->texLs, i);
2202 titem = (TextureListItem *) item->clientData;
2204 texture = WMCreatePLArray(WMCreatePLString(titem->title),
2205 WMRetainPropList(titem->prop), WMCreatePLString(titem->path), NULL);
2207 WMAddToPLArray(textureList, texture);
2210 WMSetUDObjectForKey(udb, textureList, "TextureList");
2211 WMReleasePropList(textureList);
2213 /* store list of colors */
2214 textureList = WMCreatePLArray(NULL, NULL);
2215 for (i = 0; i < 24; i++) {
2216 WMColor *color;
2217 char *str;
2219 color = WMGetColorWellColor(panel->sampW[i]);
2221 str = WMGetColorRGBDescription(color);
2222 WMAddToPLArray(textureList, WMCreatePLString(str));
2223 wfree(str);
2225 WMSetUDObjectForKey(udb, textureList, "ColorList");
2226 WMReleasePropList(textureList);
2228 WMSynchronizeUserDefaults(udb);
2231 Panel *InitAppearance(WMWidget *parent)
2233 _Panel *panel;
2235 panel = wmalloc(sizeof(_Panel));
2237 panel->sectionName = _("Appearance Preferences");
2239 panel->description = _("Background texture configuration for windows,\n" "menus and icons.");
2241 panel->parent = parent;
2243 panel->callbacks.createWidgets = createPanel;
2244 panel->callbacks.updateDomain = storeData;
2245 panel->callbacks.prepareForClose = prepareForClose;
2247 AddSection(panel, ICON_FILE);
2249 return panel;
2252 /****************************************************************************/
2254 typedef struct ExtractPanel {
2255 WMWindow *win;
2257 WMLabel *label;
2258 WMList *list;
2260 WMButton *closeB;
2261 WMButton *extrB;
2262 } ExtractPanel;
2264 static void OpenExtractPanelFor(_Panel *panel)
2266 ExtractPanel *epanel;
2267 WMColor *color;
2268 WMFont *font;
2269 WMScreen *scr = WMWidgetScreen(panel->parent);
2271 epanel = wmalloc(sizeof(ExtractPanel));
2272 epanel->win = WMCreatePanelWithStyleForWindow(panel->parent, "extract",
2273 WMTitledWindowMask | WMClosableWindowMask);
2274 WMResizeWidget(epanel->win, 245, 250);
2275 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2277 epanel->label = WMCreateLabel(epanel->win);
2278 WMResizeWidget(epanel->label, 225, 18);
2279 WMMoveWidget(epanel->label, 10, 10);
2280 WMSetLabelTextAlignment(epanel->label, WACenter);
2281 WMSetLabelRelief(epanel->label, WRSunken);
2283 color = WMDarkGrayColor(scr);
2284 WMSetWidgetBackgroundColor(epanel->label, color);
2285 WMReleaseColor(color);
2287 color = WMWhiteColor(scr);
2288 WMSetLabelTextColor(epanel->label, color);
2289 WMReleaseColor(color);
2291 font = WMBoldSystemFontOfSize(scr, 12);
2292 WMSetLabelFont(epanel->label, font);
2293 WMReleaseFont(font);
2295 WMSetLabelText(epanel->label, _("Textures"));
2297 epanel->list = WMCreateList(epanel->win);
2298 WMResizeWidget(epanel->list, 225, 165);
2299 WMMoveWidget(epanel->list, 10, 30);
2301 epanel->closeB = WMCreateCommandButton(epanel->win);
2302 WMResizeWidget(epanel->closeB, 74, 24);
2303 WMMoveWidget(epanel->closeB, 165, 215);
2304 WMSetButtonText(epanel->closeB, _("Close"));
2306 epanel->extrB = WMCreateCommandButton(epanel->win);
2307 WMResizeWidget(epanel->extrB, 74, 24);
2308 WMMoveWidget(epanel->extrB, 80, 215);
2309 WMSetButtonText(epanel->extrB, _("Extract"));
2311 WMMapSubwidgets(epanel->win);
2313 /* take textures from file */
2315 WMRealizeWidget(epanel->win);
2317 WMMapWidget(epanel->win);