wrlib: return NULL if XImage could not be taken, for consistency
[wmaker-crm.git] / WPrefs.app / Appearance.c
blob8d5020c537d4a768f06c456e37865f6e84d45b8a
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 *label;
298 } textureOptions[] = {
299 { "FTitleBack", "(solid, black)", N_("[Focused]") },
300 { "UTitleBack", "(solid, gray)", N_("[Unfocused]") },
301 { "PTitleBack", "(solid, \"#616161\")", N_("[Owner of Focused]") },
302 { "ResizebarBack", "(solid, gray)", N_("[Resizebar]") },
303 { "MenuTitleBack", "(solid, black)", N_("[Menu Title]") },
304 { "MenuTextBack", "(solid, gray)", N_("[Menu Item]") },
305 { "IconBack", "(solid, gray)", N_("[Icon]") },
306 { "WorkspaceBack", "(solid, black)", N_("[Background]") }
309 enum {
310 RESIZEBAR_BEVEL = -1,
311 MENU_BEVEL = -2
314 enum {
315 TEXPREV_WIDTH = 40,
316 TEXPREV_HEIGHT = 24
319 enum {
320 MSTYLE_NORMAL,
321 MSTYLE_SINGLE,
322 MSTYLE_FLAT
325 enum {
326 FTITLE_COL,
327 UTITLE_COL,
328 OTITLE_COL,
329 MTITLE_COL,
330 MITEM_COL,
331 MDISAB_COL,
332 MHIGH_COL,
333 MHIGHT_COL,
334 FFBORDER_COL,
335 FBORDER_COL,
336 FSBORDER_COL,
337 ICONT_COL,
338 ICONB_COL,
339 CLIP_COL,
340 CCLIP_COL
343 static const struct {
344 const char *key;
345 const char *default_value;
346 } colorOptions[] = {
347 { "FTitleColor", "white" },
348 { "UTitleColor", "black" },
349 { "PTitleColor", "white" },
350 { "MenuTitleColor", "white" },
351 { "MenuTextColor", "black" },
352 { "MenuDisabledColor", "#616161" },
353 { "HighlightColor", "white" },
354 { "HighlightTextColor", "black" },
355 { "FrameFocusedBorderColor", "black" },
356 { "FrameBorderColor", "black" },
357 { "FrameSelectedBorderColor", "white" },
358 { "IconTitleColor", "white" },
359 { "IconTitleBack", "black" },
360 { "ClipTitleColor", "black" },
361 { "CClipTitleColor", "#454045" }
364 static WMRect previewPositions[] = {
365 #define PFOCUSED 0
366 {{30, 10}, {190, 20}},
367 #define PUNFOCUSED 1
368 {{30, 40}, {190, 20}},
369 #define POWNER 2
370 {{30, 70}, {190, 20}},
371 #define PRESIZEBAR 3
372 {{30, 100}, {190, 9}},
373 #define PMTITLE 4
374 {{30, 120}, {90, 20}},
375 #define PMITEM 5
376 {{30, 140}, {90, 20 * 4}},
377 #define PICON 6
378 {{155, 130}, {64, 64}}
381 #define PBACKGROUND 7
382 #define EVERYTHING 0xff
384 static WMRect previewColorPositions[] = {
385 {{30, 10}, {190, 20}},
386 {{30, 40}, {190, 20}},
387 {{30, 70}, {190, 20}},
388 {{30, 120}, {90, 20}},
389 {{30, 140}, {90, 20}},
390 {{30, 160}, {90, 20}},
391 {{30, 180}, {90, 20}},
392 {{30, 200}, {90, 20}},
393 {{0, 0}, {0, 0}},
394 {{0, 0}, {0, 0}},
395 {{0, 0}, {0, 0}},
396 {{155, 130}, {64, 64}},
397 {{155, 130}, {64, 64}},
398 {{155, 130}, {64, 64}},
399 {{155, 130}, {64, 64}}
402 static void str2rcolor(RContext * rc, const char *name, RColor * color)
404 XColor xcolor;
406 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
408 color->alpha = 255;
409 color->red = xcolor.red >> 8;
410 color->green = xcolor.green >> 8;
411 color->blue = xcolor.blue >> 8;
414 static void dumpRImage(const char *path, RImage * image)
416 FILE *f;
417 int channels = (image->format == RRGBAFormat ? 4 : 3);
419 f = fopen(path, "wb");
420 if (!f) {
421 werror("%s", path);
422 return;
424 fprintf(f, "%02x%02x%1x", image->width, image->height, channels);
426 fwrite(image->data, 1, image->width * image->height * channels, f);
428 fsync(fileno(f));
429 if (fclose(f) < 0) {
430 werror("%s", path);
434 static int isPixmap(WMPropList * prop)
436 WMPropList *p;
437 char *s;
439 p = WMGetFromPLArray(prop, 0);
440 s = WMGetFromPLString(p);
441 if (strcasecmp(&s[1], "pixmap") == 0)
442 return 1;
443 else
444 return 0;
447 /**********************************************************************/
449 static void drawResizebarBevel(RImage * img)
451 RColor light;
452 RColor dark;
453 int width = img->width;
454 int height = img->height;
455 int cwidth = 28;
457 light.alpha = 0;
458 light.red = light.green = light.blue = 80;
460 dark.alpha = 0;
461 dark.red = dark.green = dark.blue = 40;
463 ROperateLine(img, RSubtractOperation, 0, 0, width - 1, 0, &dark);
464 ROperateLine(img, RAddOperation, 0, 1, width - 1, 1, &light);
466 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height - 1, &dark);
467 ROperateLine(img, RAddOperation, cwidth + 1, 2, cwidth + 1, height - 1, &light);
469 ROperateLine(img, RSubtractOperation, width - cwidth - 2, 2, width - cwidth - 2, height - 1, &dark);
470 ROperateLine(img, RAddOperation, width - cwidth - 1, 2, width - cwidth - 1, height - 1, &light);
474 static void drawMenuBevel(RImage * img)
476 RColor light, dark, mid;
477 int i;
478 int iheight = img->height / 4;
480 light.alpha = 0;
481 light.red = light.green = light.blue = 80;
483 dark.alpha = 255;
484 dark.red = dark.green = dark.blue = 0;
486 mid.alpha = 0;
487 mid.red = mid.green = mid.blue = 40;
489 for (i = 1; i < 4; i++) {
490 ROperateLine(img, RSubtractOperation, 0, i * iheight - 2, img->width - 1, i * iheight - 2, &mid);
492 RDrawLine(img, 0, i * iheight - 1, img->width - 1, i * iheight - 1, &dark);
494 ROperateLine(img, RAddOperation, 1, i * iheight, img->width - 2, i * iheight, &light);
498 static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int height, const char *path, int border)
500 char *type;
501 RImage *image = NULL;
502 RImage *timage = NULL;
503 Pixmap pixmap;
504 RContext *rc = WMScreenRContext(scr);
505 char *str;
506 RColor rcolor;
508 type = WMGetFromPLString(WMGetFromPLArray(texture, 0));
510 if (strcasecmp(&type[1], "pixmap") == 0 ||
511 (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T')) {
512 char *path;
514 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
515 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
516 if (path) {
517 timage = RLoadImage(rc, path, 0);
518 if (!timage)
519 wwarning("could not load file '%s': %s", path, RMessageForError(RErrorCode));
520 wfree(path);
521 } else {
522 wwarning("could not find file '%s' for %s of texture", str, type);
523 timage = NULL;
525 if (!timage) {
526 texture = WMCreatePropListFromDescription("(solid, black)");
527 type = "solid";
531 if (strcasecmp(type, "solid") == 0) {
533 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
535 str2rcolor(rc, str, &rcolor);
537 image = RCreateImage(width, height, False);
538 RClearImage(image, &rcolor);
539 } else if (strcasecmp(type, "igradient") == 0) {
540 int t1, t2;
541 RColor c1[2], c2[2];
543 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
544 str2rcolor(rc, str, &c1[0]);
545 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
546 str2rcolor(rc, str, &c1[1]);
547 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
548 t1 = atoi(str);
550 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
551 str2rcolor(rc, str, &c2[0]);
552 str = WMGetFromPLString(WMGetFromPLArray(texture, 5));
553 str2rcolor(rc, str, &c2[1]);
554 str = WMGetFromPLString(WMGetFromPLArray(texture, 6));
555 t2 = atoi(str);
557 image = RRenderInterwovenGradient(width, height, c1, t1, c2, t2);
558 } else if (strcasecmp(&type[1], "gradient") == 0) {
559 int style;
560 RColor rcolor2;
562 switch (toupper(type[0])) {
563 case 'V':
564 style = RVerticalGradient;
565 break;
566 case 'H':
567 style = RHorizontalGradient;
568 break;
569 default:
570 wwarning("unknow direction in '%s', falling back to diagonal", type);
571 case 'D':
572 style = RDiagonalGradient;
573 break;
576 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
577 str2rcolor(rc, str, &rcolor);
578 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
579 str2rcolor(rc, str, &rcolor2);
581 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
582 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T') {
583 int style;
584 RColor rcolor2;
585 int i;
586 RImage *grad = NULL;
588 switch (toupper(type[1])) {
589 case 'V':
590 style = RVerticalGradient;
591 break;
592 case 'H':
593 style = RHorizontalGradient;
594 break;
595 default:
596 wwarning("unknow direction in '%s', falling back to diagonal", type);
597 case 'D':
598 style = RDiagonalGradient;
599 break;
602 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
603 str2rcolor(rc, str, &rcolor);
604 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
605 str2rcolor(rc, str, &rcolor2);
607 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
609 image = RMakeTiledImage(timage, width, height);
610 RReleaseImage(timage);
612 i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
614 RCombineImagesWithOpaqueness(image, grad, i);
615 RReleaseImage(grad);
617 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'M') {
618 int style;
619 RColor **colors;
620 int i, j;
622 switch (toupper(type[1])) {
623 case 'V':
624 style = RVerticalGradient;
625 break;
626 case 'H':
627 style = RHorizontalGradient;
628 break;
629 default:
630 wwarning("unknow direction in '%s', falling back to diagonal", type);
631 case 'D':
632 style = RDiagonalGradient;
633 break;
636 j = WMGetPropListItemCount(texture);
638 if (j > 0) {
639 colors = wmalloc(j * sizeof(RColor *));
641 for (i = 2; i < j; i++) {
642 str = WMGetFromPLString(WMGetFromPLArray(texture, i));
643 colors[i - 2] = wmalloc(sizeof(RColor));
644 str2rcolor(rc, str, colors[i - 2]);
646 colors[i - 2] = NULL;
648 image = RRenderMultiGradient(width, height, colors, style);
650 for (i = 0; colors[i] != NULL; i++)
651 wfree(colors[i]);
652 wfree(colors);
654 } else if (strcasecmp(&type[1], "pixmap") == 0) {
655 RColor color;
657 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
658 str2rcolor(rc, str, &color);
660 switch (toupper(type[0])) {
661 case 'T':
662 image = RMakeTiledImage(timage, width, height);
663 RReleaseImage(timage);
664 break;
665 case 'C':
666 image = RMakeCenteredImage(timage, width, height, &color);
667 RReleaseImage(timage);
668 break;
669 case 'F':
670 case 'S':
671 case 'M':
672 image = RScaleImage(timage, width, height);
673 RReleaseImage(timage);
674 break;
676 default:
677 wwarning("type '%s' in not a supported type for a texture", type);
678 RReleaseImage(timage);
679 return None;
683 if (!image)
684 return None;
686 if (path) {
687 dumpRImage(path, image);
690 if (border < 0) {
691 if (border == RESIZEBAR_BEVEL) {
692 drawResizebarBevel(image);
693 } else if (border == MENU_BEVEL) {
694 drawMenuBevel(image);
695 RBevelImage(image, RBEV_RAISED2);
697 } else if (border) {
698 RBevelImage(image, border);
701 RConvertImage(rc, image, &pixmap);
702 RReleaseImage(image);
704 return pixmap;
707 static Pixmap renderMenu(_Panel * panel, WMPropList * texture, int width, int iheight)
709 WMScreen *scr = WMWidgetScreen(panel->parent);
710 Display *dpy = WMScreenDisplay(scr);
711 Pixmap pix, tmp;
712 GC gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
713 int i;
715 switch (panel->menuStyle) {
716 case MSTYLE_NORMAL:
717 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
719 pix = XCreatePixmap(dpy, tmp, width, iheight * 4, WMScreenDepth(scr));
720 for (i = 0; i < 4; i++) {
721 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight * i);
723 XFreePixmap(dpy, tmp);
724 break;
725 case MSTYLE_SINGLE:
726 pix = renderTexture(scr, texture, width, iheight * 4, NULL, MENU_BEVEL);
727 break;
728 case MSTYLE_FLAT:
729 pix = renderTexture(scr, texture, width, iheight * 4, NULL, RBEV_RAISED2);
730 break;
731 default:
732 pix = None;
734 XFreeGC(dpy, gc);
736 return pix;
739 static void renderPreview(_Panel * panel, GC gc, int part, int relief)
741 WMListItem *item;
742 TextureListItem *titem;
743 Pixmap pix;
744 WMScreen *scr = WMWidgetScreen(panel->box);
746 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
747 titem = (TextureListItem *) item->clientData;
749 pix = renderTexture(scr, titem->prop,
750 previewPositions[part].size.width, previewPositions[part].size.height, NULL, relief);
752 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
753 previewPositions[part].size.width,
754 previewPositions[part].size.height, previewPositions[part].pos.x, previewPositions[part].pos.y);
756 XCopyArea(WMScreenDisplay(scr), pix, panel->previewNoText, gc, 0, 0,
757 previewPositions[part].size.width,
758 previewPositions[part].size.height, previewPositions[part].pos.x, previewPositions[part].pos.y);
760 XFreePixmap(WMScreenDisplay(scr), pix);
763 static void updatePreviewBox(_Panel * panel, int elements)
765 WMScreen *scr = WMWidgetScreen(panel->parent);
766 Display *dpy = WMScreenDisplay(scr);
767 Pixmap pix;
768 GC gc;
769 int colorUpdate = 0;
771 gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
773 if (panel->preview == None) {
774 WMPixmap *p;
776 panel->previewNoText = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
777 240 - 4, 215 - 4, WMScreenDepth(scr));
778 panel->previewBack = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
779 240 - 4, 215 - 4, WMScreenDepth(scr));
781 p = WMCreatePixmap(scr, 240 - 4, 215 - 4, WMScreenDepth(scr), False);
782 panel->preview = WMGetPixmapXID(p);
783 WMSetLabelImage(panel->prevL, p);
784 WMReleasePixmap(p);
786 if (elements & (1 << PBACKGROUND)) {
787 Pixmap tmp;
788 TextureListItem *titem;
789 WMListItem *item;
791 item = WMGetListItem(panel->texLs,
792 panel->textureIndex[PBACKGROUND]);
793 titem = (TextureListItem *) item->clientData;
794 tmp = renderTexture(scr, titem->prop, 240 - 4, 215 - 4, NULL, 0);
796 XCopyArea(dpy, tmp, panel->preview, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
797 XCopyArea(dpy, tmp, panel->previewNoText, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
798 XCopyArea(dpy, tmp, panel->previewBack, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
799 XFreePixmap(dpy, tmp);
802 if (elements & (1 << PFOCUSED)) {
803 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
804 colorUpdate |= 1 << FTITLE_COL | 1 << FFBORDER_COL;
806 if (elements & (1 << PUNFOCUSED)) {
807 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
808 colorUpdate |= 1 << UTITLE_COL | 1 << FBORDER_COL;
810 if (elements & (1 << POWNER)) {
811 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
812 colorUpdate |= 1 << OTITLE_COL | 1 << FBORDER_COL;
814 if (elements & (1 << PRESIZEBAR)) {
815 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
816 colorUpdate |= 1 << FBORDER_COL;
818 if (elements & (1 << PMTITLE)) {
819 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
820 colorUpdate |= 1 << MTITLE_COL | 1 << FBORDER_COL;
822 if (elements & (1 << PMITEM)) {
823 WMListItem *item;
824 TextureListItem *titem;
826 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
827 titem = (TextureListItem *) item->clientData;
829 pix = renderMenu(panel, titem->prop,
830 previewPositions[PMITEM].size.width, previewPositions[PMITEM].size.height / 4);
832 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
833 previewPositions[PMITEM].size.width,
834 previewPositions[PMITEM].size.height,
835 previewPositions[PMITEM].pos.x, previewPositions[PMITEM].pos.y);
837 XCopyArea(dpy, pix, panel->previewNoText, gc, 0, 0,
838 previewPositions[PMITEM].size.width,
839 previewPositions[PMITEM].size.height,
840 previewPositions[PMITEM].pos.x, previewPositions[PMITEM].pos.y);
842 XFreePixmap(dpy, pix);
844 colorUpdate |= 1 << MITEM_COL | 1 << MDISAB_COL |
845 1 << MHIGH_COL | 1 << MHIGHT_COL |
846 1 << FBORDER_COL;
848 if (elements & (1 << PICON)) {
849 WMListItem *item;
850 TextureListItem *titem;
852 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
853 titem = (TextureListItem *) item->clientData;
855 renderPreview(panel, gc, PICON, titem->ispixmap ? 0 : RBEV_RAISED3);
858 if (colorUpdate)
859 updateColorPreviewBox(panel, colorUpdate);
860 else
861 WMRedisplayWidget(panel->prevL);
863 XFreeGC(dpy, gc);
866 static void cancelNewTexture(void *data)
868 _Panel *panel = (_Panel *) data;
870 HideTexturePanel(panel->texturePanel);
873 static char *makeFileName(const char *prefix)
875 char *fname;
877 fname = wstrdup(prefix);
879 while (access(fname, F_OK) == 0) {
880 char buf[30];
882 wfree(fname);
883 sprintf(buf, "%08lx.cache", time(NULL));
884 fname = wstrconcat(prefix, buf);
887 return fname;
890 static void okNewTexture(void *data)
892 _Panel *panel = (_Panel *) data;
893 WMListItem *item;
894 char *name;
895 char *str;
896 WMPropList *prop;
897 TextureListItem *titem;
898 WMScreen *scr = WMWidgetScreen(panel->parent);
900 titem = wmalloc(sizeof(TextureListItem));
902 HideTexturePanel(panel->texturePanel);
904 name = GetTexturePanelTextureName(panel->texturePanel);
906 prop = GetTexturePanelTexture(panel->texturePanel);
908 str = WMGetPropListDescription(prop, False);
910 titem->title = name;
911 titem->prop = prop;
912 titem->texture = str;
913 titem->selectedFor = 0;
915 titem->ispixmap = isPixmap(prop);
917 titem->path = makeFileName(panel->fprefix);
918 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
920 item = WMAddListItem(panel->texLs, "");
921 item->clientData = titem;
923 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
926 static void okEditTexture(void *data)
928 _Panel *panel = (_Panel *) data;
929 WMListItem *item;
930 char *name;
931 char *str;
932 WMPropList *prop;
933 TextureListItem *titem;
935 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
936 titem = (TextureListItem *) item->clientData;
938 HideTexturePanel(panel->texturePanel);
940 if (titem->current) {
941 name = GetTexturePanelTextureName(panel->texturePanel);
943 wfree(titem->title);
944 titem->title = name;
947 prop = GetTexturePanelTexture(panel->texturePanel);
949 str = WMGetPropListDescription(prop, False);
951 WMReleasePropList(titem->prop);
952 titem->prop = prop;
954 titem->ispixmap = isPixmap(prop);
956 wfree(titem->texture);
957 titem->texture = str;
959 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
960 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
961 TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
963 WMRedisplayWidget(panel->texLs);
965 if (titem->selectedFor) {
966 if (titem->selectedFor & (1 << PBACKGROUND))
967 updatePreviewBox(panel, EVERYTHING);
968 else
969 updatePreviewBox(panel, titem->selectedFor);
972 changePage(panel->secP, panel);
975 static void editTexture(WMWidget * w, void *data)
977 _Panel *panel = (_Panel *) data;
978 WMListItem *item;
979 TextureListItem *titem;
981 /* Parameter not used, but tell the compiler that it is ok */
982 (void) w;
984 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
985 titem = (TextureListItem *) item->clientData;
987 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
989 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
991 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
992 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
994 ShowTexturePanel(panel->texturePanel);
997 static void newTexture(WMWidget * w, void *data)
999 _Panel *panel = (_Panel *) data;
1001 /* Parameter not used, but tell the compiler that it is ok */
1002 (void) w;
1004 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
1006 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1008 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1010 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1012 ShowTexturePanel(panel->texturePanel);
1015 static void deleteTexture(WMWidget * w, void *data)
1017 _Panel *panel = (_Panel *) data;
1018 WMListItem *item;
1019 TextureListItem *titem;
1020 int row;
1021 int section;
1023 /* Parameter not used, but tell the compiler that it is ok */
1024 (void) w;
1026 section = WMGetPopUpButtonSelectedItem(panel->secP);
1027 row = WMGetListSelectedItemRow(panel->texLs);
1028 item = WMGetListItem(panel->texLs, row);
1029 titem = (TextureListItem *) item->clientData;
1031 if (titem->selectedFor & (1 << section)) {
1032 TextureListItem *titem2;
1034 panel->textureIndex[section] = section;
1035 item = WMGetListItem(panel->texLs, section);
1036 titem2 = (TextureListItem *) item->clientData;
1037 titem2->selectedFor |= 1 << section;
1040 wfree(titem->title);
1041 wfree(titem->texture);
1042 WMReleasePropList(titem->prop);
1043 if (titem->path) {
1044 if (remove(titem->path) < 0 && errno != ENOENT) {
1045 werror("could not remove file %s", titem->path);
1047 wfree(titem->path);
1050 wfree(titem);
1052 WMRemoveListItem(panel->texLs, row);
1053 WMSetButtonEnabled(panel->delB, False);
1056 static void extractTexture(WMWidget * w, void *data)
1058 _Panel *panel = (_Panel *) data;
1059 char *path;
1060 WMOpenPanel *opanel;
1061 WMScreen *scr = WMWidgetScreen(w);
1063 opanel = WMGetOpenPanel(scr);
1064 WMSetFilePanelCanChooseDirectories(opanel, False);
1065 WMSetFilePanelCanChooseFiles(opanel, True);
1067 if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(), _("Select File"), NULL)) {
1068 path = WMGetFilePanelFileName(opanel);
1070 OpenExtractPanelFor(panel);
1072 wfree(path);
1076 static void changePage(WMWidget * w, void *data)
1078 _Panel *panel = (_Panel *) data;
1079 int section;
1080 WMScreen *scr = WMWidgetScreen(panel->box);
1081 RContext *rc = WMScreenRContext(scr);
1082 static WMPoint positions[] = {
1083 {5, 10},
1084 {5, 40},
1085 {5, 70},
1086 {5, 100},
1087 {5, 120},
1088 {5, 160},
1089 {130, 150}
1092 if (w) {
1093 section = WMGetPopUpButtonSelectedItem(panel->secP);
1095 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1097 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1100 GC gc;
1102 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1103 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1104 positions[panel->oldsection].x,
1105 positions[panel->oldsection].y, 22, 22 ,
1106 positions[panel->oldsection].x,
1107 positions[panel->oldsection].y);
1109 if (w) {
1110 panel->oldsection = section;
1111 WMDrawPixmap(panel->hand, panel->preview, positions[section].x, positions[section].y);
1113 WMRedisplayWidget(panel->prevL);
1116 static void previewClick(XEvent * event, void *clientData)
1118 _Panel *panel = (_Panel *) clientData;
1119 int i;
1121 switch (panel->oldTabItem) {
1122 case 0:
1123 for (i = 0; i < wlengthof(previewPositions); i++) {
1124 if (event->xbutton.x >= previewPositions[i].pos.x
1125 && event->xbutton.y >= previewPositions[i].pos.y
1126 && event->xbutton.x < previewPositions[i].pos.x
1127 + previewPositions[i].size.width
1128 && event->xbutton.y < previewPositions[i].pos.y + previewPositions[i].size.height) {
1130 WMSetPopUpButtonSelectedItem(panel->secP, i);
1131 changePage(panel->secP, panel);
1132 return;
1135 break;
1136 case 1:
1137 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1138 if (event->xbutton.x >= previewColorPositions[i].pos.x
1139 && event->xbutton.y >= previewColorPositions[i].pos.y
1140 && event->xbutton.x < previewColorPositions[i].pos.x
1141 + previewColorPositions[i].size.width
1142 && event->xbutton.y < previewColorPositions[i].pos.y
1143 + previewColorPositions[i].size.height) {
1145 /* yuck kluge */
1146 if (i == 7)
1147 i = 4;
1149 WMSetPopUpButtonSelectedItem(panel->colP, i);
1150 changeColorPage(panel->colP, panel);
1151 return;
1154 break;
1158 static void textureClick(WMWidget * w, void *data)
1160 _Panel *panel = (_Panel *) data;
1161 int i;
1162 WMListItem *item;
1163 TextureListItem *titem;
1165 /* Parameter not used, but tell the compiler that it is ok */
1166 (void) w;
1168 i = WMGetListSelectedItemRow(panel->texLs);
1170 item = WMGetListItem(panel->texLs, i);
1172 titem = (TextureListItem *) item->clientData;
1174 if (titem->current) {
1175 WMSetButtonEnabled(panel->delB, False);
1176 } else {
1177 WMSetButtonEnabled(panel->delB, True);
1181 static void textureDoubleClick(WMWidget * w, void *data)
1183 _Panel *panel = (_Panel *) data;
1184 int i, section;
1185 WMListItem *item;
1186 TextureListItem *titem;
1188 /* Parameter not used, but tell the compiler that it is ok */
1189 (void) w;
1191 /* unselect old texture */
1192 section = WMGetPopUpButtonSelectedItem(panel->secP);
1194 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1195 titem = (TextureListItem *) item->clientData;
1196 titem->selectedFor &= ~(1 << section);
1198 /* select new texture */
1199 i = WMGetListSelectedItemRow(panel->texLs);
1201 item = WMGetListItem(panel->texLs, i);
1203 titem = (TextureListItem *) item->clientData;
1205 titem->selectedFor |= 1 << section;
1207 panel->textureIndex[section] = i;
1209 WMRedisplayWidget(panel->texLs);
1211 if (section == PBACKGROUND)
1212 updatePreviewBox(panel, EVERYTHING);
1213 else
1214 updatePreviewBox(panel, 1 << section);
1217 static void paintListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
1219 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
1220 WMScreen *scr = WMWidgetScreen(lPtr);
1221 int width, height, x, y;
1222 Display *dpy = WMScreenDisplay(scr);
1223 WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
1224 WMListItem *item;
1225 WMColor *black = WMBlackColor(scr);
1226 TextureListItem *titem;
1228 /* Parameter not used, but tell the compiler that it is ok */
1229 (void) text;
1231 item = WMGetListItem(lPtr, index);
1232 titem = (TextureListItem *) item->clientData;
1233 if (!titem) {
1234 WMReleaseColor(back);
1235 WMReleaseColor(black);
1236 return;
1239 width = rect->size.width;
1240 height = rect->size.height;
1241 x = rect->pos.x;
1242 y = rect->pos.y;
1244 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
1246 if (titem->preview)
1247 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1248 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1250 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1251 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1252 else if (titem->selectedFor)
1253 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1255 WMDrawString(scr, d, black, panel->boldFont,
1256 x + TEXPREV_WIDTH + 22, y + 2, titem->title, strlen(titem->title));
1258 WMDrawString(scr, d, black, panel->smallFont,
1259 x + TEXPREV_WIDTH + 14, y + 18, titem->texture, strlen(titem->texture));
1261 WMReleaseColor(back);
1262 WMReleaseColor(black);
1265 static Pixmap loadRImage(WMScreen * scr, const char *path)
1267 FILE *f;
1268 RImage *image;
1269 int w, h, d, cnt;
1270 size_t read_size;
1271 Pixmap pixmap;
1273 f = fopen(path, "rb");
1274 if (!f)
1275 return None;
1277 cnt = fscanf(f, "%02x%02x%1x", &w, &h, &d);
1278 if (cnt != 3) {
1279 fclose(f);
1280 return None;
1282 image = RCreateImage(w, h, d == 4);
1283 read_size = w * h * d;
1284 if (fread(image->data, 1, read_size, f) == read_size)
1285 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1286 else
1287 pixmap = None;
1289 fclose(f);
1291 RReleaseImage(image);
1293 return pixmap;
1296 static void fillTextureList(WMList * lPtr)
1298 WMPropList *textureList;
1299 WMPropList *texture;
1300 WMUserDefaults *udb = WMGetStandardUserDefaults();
1301 TextureListItem *titem;
1302 WMScreen *scr = WMWidgetScreen(lPtr);
1303 int i;
1305 textureList = WMGetUDObjectForKey(udb, "TextureList");
1306 if (!textureList)
1307 return;
1309 for (i = 0; i < WMGetPropListItemCount(textureList); i++) {
1310 WMListItem *item;
1312 texture = WMGetFromPLArray(textureList, i);
1314 titem = wmalloc(sizeof(TextureListItem));
1316 titem->title = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 0)));
1317 titem->prop = WMRetainPropList(WMGetFromPLArray(texture, 1));
1318 titem->texture = WMGetPropListDescription(titem->prop, False);
1319 titem->selectedFor = 0;
1320 titem->path = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
1322 titem->preview = loadRImage(scr, titem->path);
1323 if (!titem->preview) {
1324 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1326 item = WMAddListItem(lPtr, "");
1327 item->clientData = titem;
1331 static void fillColorList(_Panel * panel)
1333 WMColor *color;
1334 WMPropList *list;
1335 WMUserDefaults *udb = WMGetStandardUserDefaults();
1336 WMScreen *scr = WMWidgetScreen(panel->box);
1337 int i;
1339 list = WMGetUDObjectForKey(udb, "ColorList");
1340 if (!list) {
1341 for (i = 0; i < 24; i++) {
1342 color = WMCreateNamedColor(scr, sampleColors[i], False);
1343 if (!color)
1344 continue;
1345 WMSetColorWellColor(panel->sampW[i], color);
1346 WMReleaseColor(color);
1348 } else {
1349 WMPropList *c;
1351 for (i = 0; i < WMIN(24, WMGetPropListItemCount(list)); i++) {
1352 c = WMGetFromPLArray(list, i);
1353 if (!c || !WMIsPLString(c))
1354 continue;
1355 color = WMCreateNamedColor(scr, WMGetFromPLString(c), False);
1356 if (!color)
1357 continue;
1358 WMSetColorWellColor(panel->sampW[i], color);
1359 WMReleaseColor(color);
1364 /*************************************************************************/
1366 static void changeColorPage(WMWidget * w, void *data)
1368 _Panel *panel = (_Panel *) data;
1369 int section;
1370 WMScreen *scr = WMWidgetScreen(panel->box);
1371 RContext *rc = WMScreenRContext(scr);
1372 static WMPoint positions[] = {
1373 {5, 10},
1374 {5, 40},
1375 {5, 70},
1376 {5, 120},
1377 {5, 140},
1378 {5, 160},
1379 {5, 180},
1380 {5, 180},
1381 {-22, -21},
1382 {-22, -21},
1383 {-22, -21},
1384 {130, 132},
1385 {130, 132},
1386 {130, 132},
1387 {130, 132}
1390 if (panel->preview) {
1391 GC gc;
1393 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1394 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1395 positions[panel->oldcsection].x,
1396 positions[panel->oldcsection].y, 22, 22 ,
1397 positions[panel->oldcsection].x,
1398 positions[panel->oldcsection].y);
1400 if (w) {
1401 section = WMGetPopUpButtonSelectedItem(panel->colP);
1403 panel->oldcsection = section;
1404 if (panel->preview)
1405 WMDrawPixmap(panel->hand, panel->preview, positions[section].x, positions[section].y);
1407 if (section >= ICONT_COL)
1408 updateColorPreviewBox(panel, 1 << section);
1410 WMSetColorWellColor(panel->colW, panel->colors[section]);
1412 WMRedisplayWidget(panel->prevL);
1415 static void
1416 paintText(WMScreen * scr, Drawable d, WMColor * color, WMFont * font,
1417 int x, int y, int w, int h, WMAlignment align, char *text)
1419 int l = strlen(text);
1421 switch (align) {
1422 case WALeft:
1423 x += 5;
1424 break;
1425 case WARight:
1426 x += w - 5 - WMWidthOfString(font, text, l);
1427 break;
1428 default:
1429 case WACenter:
1430 x += (w - WMWidthOfString(font, text, l)) / 2;
1431 break;
1433 WMDrawString(scr, d, color, font, x, y + (h - WMFontHeight(font)) / 2, text, l);
1436 static void updateColorPreviewBox(_Panel * panel, int elements)
1438 WMScreen *scr = WMWidgetScreen(panel->box);
1439 Display *dpy = WMScreenDisplay(scr);
1440 Pixmap d, pnot;
1441 GC gc;
1443 d = panel->preview;
1444 pnot = panel->previewNoText;
1445 gc = WMColorGC(panel->colors[FTITLE_COL]);
1447 if (elements & (1 << FTITLE_COL)) {
1448 XCopyArea(dpy, pnot, d, gc, 30, 10, 190, 20, 30, 10);
1449 paintText(scr, d, panel->colors[FTITLE_COL],
1450 panel->boldFont, 30, 10, 190, 20,
1451 panel->titleAlignment, _("Focused Window"));
1453 if (elements & (1 << UTITLE_COL)) {
1454 XCopyArea(dpy, pnot, d, gc, 30, 40, 190, 20, 30, 40);
1455 paintText(scr, d, panel->colors[UTITLE_COL],
1456 panel->boldFont, 30, 40, 190, 20,
1457 panel->titleAlignment,
1458 _("Unfocused Window"));
1460 if (elements & (1 << OTITLE_COL)) {
1461 XCopyArea(dpy, pnot, d, gc, 30, 70, 190, 20, 30, 70);
1462 paintText(scr, d, panel->colors[OTITLE_COL],
1463 panel->boldFont, 30, 70, 190, 20,
1464 panel->titleAlignment,
1465 _("Owner of Focused Window"));
1467 if (elements & (1 << MTITLE_COL)) {
1468 XCopyArea(dpy, pnot, d, gc, 30, 120, 90, 20, 30, 120);
1469 paintText(scr, d, panel->colors[MTITLE_COL],
1470 panel->boldFont, 30, 120, 90, 20, WALeft,
1471 _("Menu Title"));
1473 if (elements & (1 << MITEM_COL)) {
1474 XCopyArea(dpy, pnot, d, gc, 30, 140, 90, 20, 30, 140);
1475 paintText(scr, d, panel->colors[MITEM_COL],
1476 panel->normalFont, 30, 140, 90, 20, WALeft,
1477 _("Normal Item"));
1478 XCopyArea(dpy, pnot, d, gc, 30, 200, 90, 20, 30, 200);
1479 paintText(scr, d, panel->colors[MITEM_COL],
1480 panel->normalFont, 30, 200, 90, 20, WALeft,
1481 _("Normal Item"));
1483 if (elements & (1 << MDISAB_COL)) {
1484 XCopyArea(dpy, pnot, d, gc, 30, 160, 90, 20, 30, 160);
1485 paintText(scr, d, panel->colors[MDISAB_COL],
1486 panel->normalFont, 30, 160, 90, 20, WALeft,
1487 _("Disabled Item"));
1489 if (elements & (1 << MHIGH_COL)) {
1490 XFillRectangle(WMScreenDisplay(scr), d,
1491 WMColorGC(panel->colors[MHIGH_COL]),
1492 31, 181, 87, 17);
1493 XFillRectangle(WMScreenDisplay(scr), pnot,
1494 WMColorGC(panel->colors[MHIGH_COL]),
1495 31, 181, 87, 17);
1496 elements |= 1 << MHIGHT_COL;
1498 if (elements & (1 << MHIGHT_COL)) {
1499 XCopyArea(dpy, pnot, d, gc, 30, 180, 90, 20, 30, 180);
1500 paintText(scr, d, panel->colors[MHIGHT_COL],
1501 panel->normalFont, 30, 180, 90, 20, WALeft,
1502 _("Highlighted"));
1504 if (elements & (1 << FBORDER_COL)) {
1505 XDrawRectangle(dpy, pnot,
1506 WMColorGC(panel->colors[FBORDER_COL]),
1507 29, 39, 190, 20);
1508 XDrawRectangle(dpy, d,
1509 WMColorGC(panel->colors[FBORDER_COL]),
1510 29, 39, 190, 20);
1511 XDrawRectangle(dpy, pnot,
1512 WMColorGC(panel->colors[FBORDER_COL]),
1513 29, 69, 190, 20);
1514 XDrawRectangle(dpy, d,
1515 WMColorGC(panel->colors[FBORDER_COL]),
1516 29, 69, 190, 20);
1517 XDrawLine(dpy, pnot,
1518 WMColorGC(panel->colors[FBORDER_COL]),
1519 30, 100, 30, 109);
1520 XDrawLine(dpy, d,
1521 WMColorGC(panel->colors[FBORDER_COL]),
1522 30, 100, 30, 109);
1523 XDrawLine(dpy, pnot,
1524 WMColorGC(panel->colors[FBORDER_COL]),
1525 31, 109, 219, 109);
1526 XDrawLine(dpy, d,
1527 WMColorGC(panel->colors[FBORDER_COL]),
1528 31, 109, 219, 109);
1529 XDrawLine(dpy, pnot,
1530 WMColorGC(panel->colors[FBORDER_COL]),
1531 220, 100, 220, 109);
1532 XDrawLine(dpy, d,
1533 WMColorGC(panel->colors[FBORDER_COL]),
1534 220, 100, 220, 109);
1535 XDrawLine(dpy, pnot,
1536 WMColorGC(panel->colors[FBORDER_COL]),
1537 29, 120, 29, 220);
1538 XDrawLine(dpy, d,
1539 WMColorGC(panel->colors[FBORDER_COL]),
1540 29, 120, 29, 220);
1541 XDrawLine(dpy, pnot,
1542 WMColorGC(panel->colors[FBORDER_COL]),
1543 29, 119, 119, 119);
1544 XDrawLine(dpy, d,
1545 WMColorGC(panel->colors[FBORDER_COL]),
1546 29, 119, 119, 119);
1547 XDrawLine(dpy, pnot,
1548 WMColorGC(panel->colors[FBORDER_COL]),
1549 119, 120, 119, 220);
1550 XDrawLine(dpy, d,
1551 WMColorGC(panel->colors[FBORDER_COL]),
1552 119, 120, 119, 220);
1555 if (elements & (1 << FFBORDER_COL)) {
1556 XDrawRectangle(dpy, pnot,
1557 WMColorGC(panel->colors[FFBORDER_COL]),
1558 29, 9, 190, 20);
1559 XDrawRectangle(dpy, d,
1560 WMColorGC(panel->colors[FFBORDER_COL]),
1561 29, 9, 190, 20);
1564 if (elements & (1 << ICONT_COL) || elements & (1 << ICONB_COL)) {
1565 RColor rgb;
1566 RHSVColor hsv, hsv2;
1567 int v;
1568 WMColor *light, *dim;
1570 updatePreviewBox(panel, 1 << PICON);
1572 rgb.red = WMRedComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1573 rgb.green = WMGreenComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1574 rgb.blue = WMBlueComponentOfColor(panel->colors[ICONB_COL]) >> 8;
1575 RRGBtoHSV(&rgb, &hsv);
1576 RHSVtoRGB(&hsv, &rgb);
1577 hsv2 = hsv;
1579 v = hsv.value * 16 / 10;
1580 hsv.value = (v > 255 ? 255 : v);
1581 RHSVtoRGB(&hsv, &rgb);
1582 light = WMCreateRGBColor(scr, rgb.red << 8, rgb.green << 8, rgb.blue << 8, False);
1584 hsv2.value = hsv2.value / 2;
1585 RHSVtoRGB(&hsv2, &rgb);
1586 dim = WMCreateRGBColor(scr, rgb.red << 8, rgb.green << 8, rgb.blue << 8, False);
1588 XFillRectangle(dpy, d, WMColorGC(panel->colors[ICONB_COL]), 156, 131, 62, 11);
1589 XDrawLine(dpy, d, WMColorGC(light), 155, 130, 155, 142);
1590 XDrawLine(dpy, d, WMColorGC(light), 156, 130, 217, 130);
1591 XDrawLine(dpy, d, WMColorGC(dim), 218, 130, 218, 142);
1593 paintText(scr, d, panel->colors[ICONT_COL],
1594 panel->smallFont, 155, 130, 64, 13, WALeft,
1595 _("Icon Text"));
1599 if (elements & (1 << CLIP_COL) || elements & (1 << CCLIP_COL)) {
1600 Pixmap pix;
1601 RColor black;
1602 RColor dark;
1603 RColor light;
1604 RImage *tile;
1605 TextureListItem *titem;
1606 WMListItem *item;
1607 XPoint p[4];
1609 item = WMGetListItem(panel->texLs, panel->textureIndex[PICON]);
1610 titem = (TextureListItem *) item->clientData;
1612 pix = renderTexture(scr, titem->prop, 64, 64, NULL, titem->ispixmap ? 0 : RBEV_RAISED3);
1613 tile = RCreateImageFromDrawable(WMScreenRContext(scr), pix, None);
1615 black.alpha = 255;
1616 black.red = black.green = black.blue = 0;
1618 dark.alpha = 0;
1619 dark.red = dark.green = dark.blue = 60;
1621 light.alpha = 0;
1622 light.red = light.green = light.blue = 80;
1624 /* top right */
1625 ROperateLine(tile, RSubtractOperation, 64 - 1 - 23, 0, 64 - 2, 23 - 1, &dark);
1626 RDrawLine(tile, 64 - 1 - 23 - 1, 0, 64 - 1, 23 + 1, &black);
1627 ROperateLine(tile, RAddOperation, 64 - 1 - 23, 2, 64 - 3, 23, &light);
1629 /* arrow bevel */
1630 ROperateLine(tile, RSubtractOperation, 64 - 7 - (23 - 15), 4, 64 - 5, 4, &dark);
1631 ROperateLine(tile, RSubtractOperation, 64 - 6 - (23 - 15), 5, 64 - 5, 6 + 23 - 15, &dark);
1632 ROperateLine(tile, RAddOperation, 64 - 5, 4, 64 - 5, 6 + 23 - 15, &light);
1634 /* bottom left */
1635 ROperateLine(tile, RAddOperation, 2, 64 - 1 - 23 + 2, 23 - 2, 64 - 3, &dark);
1636 RDrawLine(tile, 0, 64 - 1 - 23 - 1, 23 + 1, 64 - 1, &black);
1637 ROperateLine(tile, RSubtractOperation, 0, 64 - 1 - 23 - 2, 23 + 1, 64 - 2, &light);
1639 /* arrow bevel */
1640 ROperateLine(tile, RSubtractOperation, 4, 64 - 7 - (23 - 15), 4, 64 - 5, &dark);
1641 ROperateLine(tile, RSubtractOperation, 5, 64 - 6 - (23 - 15), 6 + 23 - 15, 64 - 5, &dark);
1642 ROperateLine(tile, RAddOperation, 4, 64 - 5, 6 + 23 - 15, 64 - 5, &light);
1644 RConvertImage(WMScreenRContext(scr), tile, &pix);
1645 RReleaseImage(tile);
1647 XCopyArea(dpy, pix, d, gc, 0, 0, 64, 64, 155, 130);
1648 XFreePixmap(dpy, pix);
1650 /* top right arrow */
1651 p[0].x = p[3].x = 155 + 64 - 5 - (23 - 15);
1652 p[0].y = p[3].y = 130 + 5;
1653 p[1].x = 155 + 64 - 6;
1654 p[1].y = 130 + 5;
1655 p[2].x = 155 + 64 - 6;
1656 p[2].y = 130 + 4 + 23 - 15;
1658 XFillPolygon(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 3, Convex, CoordModeOrigin);
1659 XDrawLines(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 4, CoordModeOrigin);
1661 /* bottom left arrow */
1662 p[0].x = p[3].x = 155 + 5;
1663 p[0].y = p[3].y = 130 + 64 - 5 - (23 - 15);
1664 p[1].x = 155 + 5;
1665 p[1].y = 130 + 64 - 6;
1666 p[2].x = 155 + 4 + 23 - 15;
1667 p[2].y = 130 + 64 - 6;
1669 XFillPolygon(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 3, Convex, CoordModeOrigin);
1670 XDrawLines(dpy, d, WMColorGC(panel->colors[CLIP_COL]), p, 4, CoordModeOrigin);
1674 if (elements & (1 << CLIP_COL))
1675 paintText(scr, d, panel->colors[CLIP_COL],
1676 panel->boldFont, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft,
1677 _("Clip"));
1679 if (elements & (1 << CCLIP_COL)) {
1680 paintText(scr, d, panel->colors[CCLIP_COL],
1681 panel->boldFont, 155+2, 130 + 2, 26, 15, WALeft, _("Coll."));
1682 paintText(scr, d, panel->colors[CCLIP_COL],
1683 panel->boldFont, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft,
1684 _("Clip"));
1687 WMRedisplayWidget(panel->prevL);
1690 static void colorWellObserver(void *self, WMNotification * n)
1692 _Panel *panel = (_Panel *) self;
1693 int p;
1695 /* Parameter not used, but tell the compiler that it is ok */
1696 (void) n;
1698 p = WMGetPopUpButtonSelectedItem(panel->colP);
1700 WMReleaseColor(panel->colors[p]);
1702 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1704 updateColorPreviewBox(panel, 1 << p);
1707 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item)
1709 _Panel *panel = self->data;
1710 int i;
1712 /* Parameter not used, but tell the compiler that it is ok */
1713 (void) tabView;
1715 i = WMGetTabViewItemIdentifier(item);
1716 switch (i) {
1717 case TAB_TEXTURE:
1718 switch (panel->oldTabItem) {
1719 case TAB_COLOR:
1720 changeColorPage(NULL, panel);
1721 break;
1723 changePage(panel->secP, panel);
1724 break;
1725 case TAB_COLOR:
1726 switch (panel->oldTabItem) {
1727 case TAB_TEXTURE:
1728 changePage(NULL, panel);
1729 break;
1731 changeColorPage(panel->colP, panel);
1732 break;
1733 case TAB_OPTIONS:
1734 switch (panel->oldTabItem) {
1735 case TAB_TEXTURE:
1736 changePage(NULL, panel);
1737 break;
1738 case TAB_COLOR:
1739 changeColorPage(NULL, panel);
1740 break;
1742 break;
1745 panel->oldTabItem = i;
1748 /*************************************************************************/
1750 static void menuStyleCallback(WMWidget * self, void *data)
1752 _Panel *panel = (_Panel *) data;
1754 if (self == panel->mstyB[0]) {
1755 panel->menuStyle = MSTYLE_NORMAL;
1756 updatePreviewBox(panel, 1 << PMITEM);
1758 } else if (self == panel->mstyB[1]) {
1759 panel->menuStyle = MSTYLE_SINGLE;
1760 updatePreviewBox(panel, 1 << PMITEM);
1762 } else if (self == panel->mstyB[2]) {
1763 panel->menuStyle = MSTYLE_FLAT;
1764 updatePreviewBox(panel, 1 << PMITEM);
1768 static void titleAlignCallback(WMWidget * self, void *data)
1770 _Panel *panel = (_Panel *) data;
1772 if (self == panel->taliB[0]) {
1773 panel->titleAlignment = WALeft;
1774 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1776 } else if (self == panel->taliB[1]) {
1777 panel->titleAlignment = WACenter;
1778 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1780 } else if (self == panel->taliB[2]) {
1781 panel->titleAlignment = WARight;
1782 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1786 static void createPanel(Panel * p)
1788 _Panel *panel = (_Panel *) p;
1789 WMFont *font;
1790 WMScreen *scr = WMWidgetScreen(panel->parent);
1791 WMTabViewItem *item;
1792 int i;
1793 char *tmp;
1794 Bool ok = True;
1796 panel->fprefix = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1798 if (access(panel->fprefix, F_OK) != 0) {
1799 if (mkdir(panel->fprefix, 0755) < 0) {
1800 werror("%s", panel->fprefix);
1801 ok = False;
1804 if (ok) {
1805 tmp = wstrconcat(panel->fprefix, "/WPrefs/");
1806 wfree(panel->fprefix);
1807 panel->fprefix = tmp;
1808 if (access(panel->fprefix, F_OK) != 0) {
1809 if (mkdir(panel->fprefix, 0755) < 0) {
1810 werror("%s", panel->fprefix);
1815 panel->smallFont = WMSystemFontOfSize(scr, 10);
1816 panel->normalFont = WMSystemFontOfSize(scr, 12);
1817 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1819 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1820 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1821 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1823 panel->box = WMCreateBox(panel->parent);
1824 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1826 /* preview box */
1827 panel->prevL = WMCreateLabel(panel->box);
1828 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1829 WMMoveWidget(panel->prevL, 15, 10);
1830 WMSetLabelRelief(panel->prevL, WRSunken);
1831 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1833 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask, previewClick, panel);
1835 /* tabview */
1837 tabviewDelegate.data = panel;
1839 panel->tabv = WMCreateTabView(panel->box);
1840 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1841 WMMoveWidget(panel->tabv, 265, 10);
1842 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1844 /*** texture list ***/
1846 panel->texF = WMCreateFrame(panel->box);
1847 WMSetFrameRelief(panel->texF, WRFlat);
1849 item = WMCreateTabViewItemWithIdentifier(TAB_TEXTURE);
1850 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1851 WMSetTabViewItemLabel(item, _("Texture"));
1853 WMAddItemInTabView(panel->tabv, item);
1855 panel->secP = WMCreatePopUpButton(panel->texF);
1856 WMResizeWidget(panel->secP, 228, 20);
1857 WMMoveWidget(panel->secP, 7, 7);
1858 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1859 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1860 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1861 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1862 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1863 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1864 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1865 WMAddPopUpButtonItem(panel->secP, _("Workspace Background"));
1867 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1868 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1870 panel->texLs = WMCreateList(panel->texF);
1871 WMResizeWidget(panel->texLs, 165, 155);
1872 WMMoveWidget(panel->texLs, 70, 33);
1873 WMSetListUserDrawItemHeight(panel->texLs, 35);
1874 WMSetListUserDrawProc(panel->texLs, paintListItem);
1875 WMHangData(panel->texLs, panel);
1876 WMSetListAction(panel->texLs, textureClick, panel);
1877 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1879 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1880 "for the selected item."), WMWidgetView(panel->texLs));
1882 /* command buttons */
1884 font = WMSystemFontOfSize(scr, 10);
1886 panel->newB = WMCreateCommandButton(panel->texF);
1887 WMResizeWidget(panel->newB, 57, 39);
1888 WMMoveWidget(panel->newB, 7, 33);
1889 WMSetButtonFont(panel->newB, font);
1890 WMSetButtonImagePosition(panel->newB, WIPAbove);
1891 WMSetButtonText(panel->newB, _("New"));
1892 WMSetButtonAction(panel->newB, newTexture, panel);
1893 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1895 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel->newB));
1897 panel->ripB = WMCreateCommandButton(panel->texF);
1898 WMResizeWidget(panel->ripB, 57, 39);
1899 WMMoveWidget(panel->ripB, 7, 72);
1900 WMSetButtonFont(panel->ripB, font);
1901 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1902 WMSetButtonText(panel->ripB, _("Extract..."));
1903 WMSetButtonAction(panel->ripB, extractTexture, panel);
1904 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1906 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel->ripB));
1908 WMSetButtonEnabled(panel->ripB, False);
1910 panel->editB = WMCreateCommandButton(panel->texF);
1911 WMResizeWidget(panel->editB, 57, 39);
1912 WMMoveWidget(panel->editB, 7, 111);
1913 WMSetButtonFont(panel->editB, font);
1914 WMSetButtonImagePosition(panel->editB, WIPAbove);
1915 WMSetButtonText(panel->editB, _("Edit"));
1916 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1917 WMSetButtonAction(panel->editB, editTexture, panel);
1918 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel->editB));
1920 panel->delB = WMCreateCommandButton(panel->texF);
1921 WMResizeWidget(panel->delB, 57, 38);
1922 WMMoveWidget(panel->delB, 7, 150);
1923 WMSetButtonFont(panel->delB, font);
1924 WMSetButtonImagePosition(panel->delB, WIPAbove);
1925 WMSetButtonText(panel->delB, _("Delete"));
1926 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1927 WMSetButtonEnabled(panel->delB, False);
1928 WMSetButtonAction(panel->delB, deleteTexture, panel);
1929 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel->delB));
1931 WMReleaseFont(font);
1933 WMMapSubwidgets(panel->texF);
1935 /*** colors ***/
1936 panel->colF = WMCreateFrame(panel->box);
1937 WMSetFrameRelief(panel->colF, WRFlat);
1939 item = WMCreateTabViewItemWithIdentifier(TAB_COLOR);
1940 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1941 WMSetTabViewItemLabel(item, _("Color"));
1943 WMAddItemInTabView(panel->tabv, item);
1945 panel->colP = WMCreatePopUpButton(panel->colF);
1946 WMResizeWidget(panel->colP, 228, 20);
1947 WMMoveWidget(panel->colP, 7, 7);
1948 WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1949 WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1950 WMAddPopUpButtonItem(panel->colP, _("Owner of Focused Window Title"));
1951 WMAddPopUpButtonItem(panel->colP, _("Menu Title"));
1952 WMAddPopUpButtonItem(panel->colP, _("Menu Item Text"));
1953 WMAddPopUpButtonItem(panel->colP, _("Disabled Menu Item Text"));
1954 WMAddPopUpButtonItem(panel->colP, _("Menu Highlight Color"));
1955 WMAddPopUpButtonItem(panel->colP, _("Highlighted Menu Text Color"));
1956 WMAddPopUpButtonItem(panel->colP, _("Focused Window Border Color"));
1957 WMAddPopUpButtonItem(panel->colP, _("Window Border Color"));
1958 WMAddPopUpButtonItem(panel->colP, _("Selected Window Border Color"));
1959 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1960 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1961 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1962 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1964 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1966 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1968 panel->colW = WMCreateColorWell(panel->colF);
1969 WMResizeWidget(panel->colW, 65, 50);
1970 WMMoveWidget(panel->colW, 30, 75);
1971 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->colW);
1973 for (i = 0; i < 4; i++) {
1974 int j;
1975 for (j = 0; j < 6; j++) {
1976 panel->sampW[i + j * 4] = WMCreateColorWell(panel->colF);
1977 WMResizeWidget(panel->sampW[i + j * 4], 22, 22);
1978 WMMoveWidget(panel->sampW[i + j * 4], 130 + i * 22, 40 + j * 22);
1979 WSetColorWellBordered(panel->sampW[i + j * 4], False);
1983 WMMapSubwidgets(panel->colF);
1985 /*** options ***/
1986 panel->optF = WMCreateFrame(panel->box);
1987 WMSetFrameRelief(panel->optF, WRFlat);
1989 item = WMCreateTabViewItemWithIdentifier(TAB_OPTIONS);
1990 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1991 WMSetTabViewItemLabel(item, _("Options"));
1993 WMAddItemInTabView(panel->tabv, item);
1995 panel->mstyF = WMCreateFrame(panel->optF);
1996 WMResizeWidget(panel->mstyF, 215, 85);
1997 WMMoveWidget(panel->mstyF, 15, 10);
1998 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
2000 for (i = 0; i < 3; i++) {
2001 WMPixmap *icon;
2002 char *path;
2004 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
2005 WMResizeWidget(panel->mstyB[i], 54, 54);
2006 WMMoveWidget(panel->mstyB[i], 15 + i * 65, 20);
2007 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
2008 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
2009 switch (i) {
2010 case 0:
2011 path = LocateImage(MSTYLE1_FILE);
2012 break;
2013 case 1:
2014 path = LocateImage(MSTYLE2_FILE);
2015 break;
2016 case 2:
2017 path = LocateImage(MSTYLE3_FILE);
2018 break;
2020 if (path) {
2021 icon = WMCreatePixmapFromFile(scr, path);
2022 if (icon) {
2023 WMSetButtonImage(panel->mstyB[i], icon);
2024 WMReleasePixmap(icon);
2025 } else {
2026 wwarning(_("could not load icon file %s"), path);
2028 wfree(path);
2031 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
2032 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
2034 WMMapSubwidgets(panel->mstyF);
2036 panel->taliF = WMCreateFrame(panel->optF);
2037 WMResizeWidget(panel->taliF, 110, 80);
2038 WMMoveWidget(panel->taliF, 15, 100);
2039 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
2041 for (i = 0; i < 3; i++) {
2042 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
2043 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
2044 switch (i) {
2045 case 0:
2046 WMSetButtonText(panel->taliB[i], _("Left"));
2047 break;
2048 case 1:
2049 WMSetButtonText(panel->taliB[i], _("Center"));
2050 break;
2051 case 2:
2052 WMSetButtonText(panel->taliB[i], _("Right"));
2053 break;
2055 WMResizeWidget(panel->taliB[i], 90, 18);
2056 WMMoveWidget(panel->taliB[i], 10, 15 + 20 * i);
2058 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
2059 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
2061 WMMapSubwidgets(panel->taliF);
2063 WMMapSubwidgets(panel->optF);
2065 /**/ WMRealizeWidget(panel->box);
2066 WMMapSubwidgets(panel->box);
2068 WMSetPopUpButtonSelectedItem(panel->secP, 0);
2070 showData(panel);
2072 changePage(panel->secP, panel);
2074 fillTextureList(panel->texLs);
2076 fillColorList(panel);
2078 panel->texturePanel = CreateTexturePanel(panel->parent);
2081 static void setupTextureFor(WMList *list, const char *key, const char *defValue, const char *title, int index)
2083 WMListItem *item;
2084 TextureListItem *titem;
2086 titem = wmalloc(sizeof(TextureListItem));
2088 titem->title = wstrdup(title);
2089 titem->prop = GetObjectForKey(key);
2090 if (!titem->prop || !WMIsPLArray(titem->prop)) {
2091 /* Maybe also give a error message to stderr that the entry is bad? */
2092 titem->prop = WMCreatePropListFromDescription(defValue);
2093 } else {
2094 WMRetainPropList(titem->prop);
2096 titem->texture = WMGetPropListDescription((WMPropList *) titem->prop, False);
2097 titem->current = 1;
2098 titem->selectedFor = 1 << index;
2100 titem->ispixmap = isPixmap(titem->prop);
2102 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
2104 item = WMAddListItem(list, "");
2105 item->clientData = titem;
2108 static void showData(_Panel * panel)
2110 int i;
2111 const char *str;
2113 str = GetStringForKey("MenuStyle");
2114 if (str && strcasecmp(str, "flat") == 0) {
2115 panel->menuStyle = MSTYLE_FLAT;
2116 } else if (str && strcasecmp(str, "singletexture") == 0) {
2117 panel->menuStyle = MSTYLE_SINGLE;
2118 } else {
2119 panel->menuStyle = MSTYLE_NORMAL;
2122 str = GetStringForKey("TitleJustify");
2123 if (str && strcasecmp(str, "left") == 0) {
2124 panel->titleAlignment = WALeft;
2125 } else if (str && strcasecmp(str, "right") == 0) {
2126 panel->titleAlignment = WARight;
2127 } else {
2128 panel->titleAlignment = WACenter;
2131 for (i = 0; i < wlengthof(colorOptions); i++) {
2132 WMColor *color;
2134 str = GetStringForKey(colorOptions[i].key);
2135 if (!str)
2136 str = colorOptions[i].default_value;
2138 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->box), str, False))) {
2139 color = WMCreateNamedColor(WMWidgetScreen(panel->box), "#000000", False);
2142 panel->colors[i] = color;
2144 changeColorPage(panel->colP, panel);
2146 for (i = 0; i < wlengthof(textureOptions); i++) {
2147 setupTextureFor(panel->texLs, textureOptions[i].key,
2148 textureOptions[i].default_value, _(textureOptions[i].label), i);
2149 panel->textureIndex[i] = i;
2151 updatePreviewBox(panel, EVERYTHING);
2153 WMSetButtonSelected(panel->mstyB[panel->menuStyle], True);
2154 WMSetButtonSelected(panel->taliB[panel->titleAlignment], True);
2157 static void storeData(_Panel * panel)
2159 TextureListItem *titem;
2160 WMListItem *item;
2161 int i;
2163 for (i = 0; i < wlengthof(textureOptions); i++) {
2164 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2165 titem = (TextureListItem *) item->clientData;
2166 SetObjectForKey(titem->prop, textureOptions[i].key);
2169 for (i = 0; i < wlengthof(colorOptions); i++) {
2170 char *str;
2172 str = WMGetColorRGBDescription(panel->colors[i]);
2174 if (str) {
2175 SetStringForKey(str, colorOptions[i].key);
2176 wfree(str);
2180 switch (panel->menuStyle) {
2181 case MSTYLE_SINGLE:
2182 SetStringForKey("singletexture", "MenuStyle");
2183 break;
2184 case MSTYLE_FLAT:
2185 SetStringForKey("flat", "MenuStyle");
2186 break;
2187 default:
2188 case MSTYLE_NORMAL:
2189 SetStringForKey("normal", "MenuStyle");
2190 break;
2192 switch (panel->titleAlignment) {
2193 case WALeft:
2194 SetStringForKey("left", "TitleJustify");
2195 break;
2196 case WARight:
2197 SetStringForKey("right", "TitleJustify");
2198 break;
2199 default:
2200 case WACenter:
2201 SetStringForKey("center", "TitleJustify");
2202 break;
2206 static void prepareForClose(_Panel * panel)
2208 WMPropList *textureList;
2209 WMPropList *texture;
2210 TextureListItem *titem;
2211 WMListItem *item;
2212 WMUserDefaults *udb = WMGetStandardUserDefaults();
2213 int i;
2215 textureList = WMCreatePLArray(NULL, NULL);
2217 /* store list of textures */
2218 for (i = 8; i < WMGetListNumberOfRows(panel->texLs); i++) {
2219 item = WMGetListItem(panel->texLs, i);
2220 titem = (TextureListItem *) item->clientData;
2222 texture = WMCreatePLArray(WMCreatePLString(titem->title),
2223 WMRetainPropList(titem->prop), WMCreatePLString(titem->path), NULL);
2225 WMAddToPLArray(textureList, texture);
2228 WMSetUDObjectForKey(udb, textureList, "TextureList");
2229 WMReleasePropList(textureList);
2231 /* store list of colors */
2232 textureList = WMCreatePLArray(NULL, NULL);
2233 for (i = 0; i < 24; i++) {
2234 WMColor *color;
2235 char *str;
2237 color = WMGetColorWellColor(panel->sampW[i]);
2239 str = WMGetColorRGBDescription(color);
2240 WMAddToPLArray(textureList, WMCreatePLString(str));
2241 wfree(str);
2243 WMSetUDObjectForKey(udb, textureList, "ColorList");
2244 WMReleasePropList(textureList);
2246 WMSynchronizeUserDefaults(udb);
2249 Panel *InitAppearance(WMWidget *parent)
2251 _Panel *panel;
2253 panel = wmalloc(sizeof(_Panel));
2255 panel->sectionName = _("Appearance Preferences");
2257 panel->description = _("Background texture configuration for windows,\n" "menus and icons.");
2259 panel->parent = parent;
2261 panel->callbacks.createWidgets = createPanel;
2262 panel->callbacks.updateDomain = storeData;
2263 panel->callbacks.prepareForClose = prepareForClose;
2265 AddSection(panel, ICON_FILE);
2267 return panel;
2270 /****************************************************************************/
2272 typedef struct ExtractPanel {
2273 WMWindow *win;
2275 WMLabel *label;
2276 WMList *list;
2278 WMButton *closeB;
2279 WMButton *extrB;
2280 } ExtractPanel;
2282 static void OpenExtractPanelFor(_Panel *panel)
2284 ExtractPanel *epanel;
2285 WMColor *color;
2286 WMFont *font;
2287 WMScreen *scr = WMWidgetScreen(panel->parent);
2289 epanel = wmalloc(sizeof(ExtractPanel));
2290 epanel->win = WMCreatePanelWithStyleForWindow(panel->parent, "extract",
2291 WMTitledWindowMask | WMClosableWindowMask);
2292 WMResizeWidget(epanel->win, 245, 250);
2293 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2295 epanel->label = WMCreateLabel(epanel->win);
2296 WMResizeWidget(epanel->label, 225, 18);
2297 WMMoveWidget(epanel->label, 10, 10);
2298 WMSetLabelTextAlignment(epanel->label, WACenter);
2299 WMSetLabelRelief(epanel->label, WRSunken);
2301 color = WMDarkGrayColor(scr);
2302 WMSetWidgetBackgroundColor(epanel->label, color);
2303 WMReleaseColor(color);
2305 color = WMWhiteColor(scr);
2306 WMSetLabelTextColor(epanel->label, color);
2307 WMReleaseColor(color);
2309 font = WMBoldSystemFontOfSize(scr, 12);
2310 WMSetLabelFont(epanel->label, font);
2311 WMReleaseFont(font);
2313 WMSetLabelText(epanel->label, _("Textures"));
2315 epanel->list = WMCreateList(epanel->win);
2316 WMResizeWidget(epanel->list, 225, 165);
2317 WMMoveWidget(epanel->list, 10, 30);
2319 epanel->closeB = WMCreateCommandButton(epanel->win);
2320 WMResizeWidget(epanel->closeB, 74, 24);
2321 WMMoveWidget(epanel->closeB, 165, 215);
2322 WMSetButtonText(epanel->closeB, _("Close"));
2324 epanel->extrB = WMCreateCommandButton(epanel->win);
2325 WMResizeWidget(epanel->extrB, 74, 24);
2326 WMMoveWidget(epanel->extrB, 80, 215);
2327 WMSetButtonText(epanel->extrB, _("Extract"));
2329 WMMapSubwidgets(epanel->win);
2331 /* take textures from file */
2333 WMRealizeWidget(epanel->win);
2335 WMMapWidget(epanel->win);