WINGs: fix memory leak in getStreamObjects (Coverity #50119)
[wmaker-crm.git] / WPrefs.app / Appearance.c
blob256a74d0116e30b318428ba9f31c9b210b0577d9
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[14];
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 FBORDER_COL,
335 FSBORDER_COL,
336 ICONT_COL,
337 ICONB_COL,
338 CLIP_COL,
339 CCLIP_COL
342 static const struct {
343 const char *key;
344 const char *default_value;
345 } colorOptions[] = {
346 { "FTitleColor", "white" },
347 { "UTitleColor", "black" },
348 { "PTitleColor", "white" },
349 { "MenuTitleColor", "white" },
350 { "MenuTextColor", "black" },
351 { "MenuDisabledColor", "#616161" },
352 { "HighlightColor", "white" },
353 { "HighlightTextColor", "black" },
354 { "FrameBorderColor", "black" },
355 { "FrameSelectedBorderColor", "white" }/* , */
356 /* { "IconTitleColor", "white" }, */
357 /* { "IconTitleBack", "black" }, */
358 /* { "ClipTitleColor", "black" }, */
359 /* { "CClipTitleColor", "#454045" } */
362 static WMRect previewPositions[] = {
363 #define PFOCUSED 0
364 {{30, 10}, {190, 20}},
365 #define PUNFOCUSED 1
366 {{30, 40}, {190, 20}},
367 #define POWNER 2
368 {{30, 70}, {190, 20}},
369 #define PRESIZEBAR 3
370 {{30, 100}, {190, 9}},
371 #define PMTITLE 4
372 {{30, 120}, {90, 20}},
373 #define PMITEM 5
374 {{30, 140}, {90, 20 * 4}},
375 #define PICON 6
376 {{155, 130}, {64, 64}}
379 #define PBACKGROUND 7
380 #define EVERYTHING 0xff
382 static WMRect previewColorPositions[] = {
383 {{30, 10}, {190, 20}},
384 {{30, 40}, {190, 20}},
385 {{30, 70}, {190, 20}},
386 {{30, 120}, {90, 20}},
387 {{30, 140}, {90, 20}},
388 {{30, 160}, {90, 20}},
389 {{30, 180}, {90, 20}},
390 {{30, 200}, {90, 20}},
391 {{30, 40}, {190, 20}},
392 {{30, 10}, {190, 20}},
393 {{155, 130}, {64, 64}},
394 {{155, 130}, {64, 64}},
395 {{155, 130}, {64, 64}},
396 {{155, 130}, {64, 64}}
399 static void str2rcolor(RContext * rc, const char *name, RColor * color)
401 XColor xcolor;
403 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
405 color->alpha = 255;
406 color->red = xcolor.red >> 8;
407 color->green = xcolor.green >> 8;
408 color->blue = xcolor.blue >> 8;
411 static void dumpRImage(const char *path, RImage * image)
413 FILE *f;
414 int channels = (image->format == RRGBAFormat ? 4 : 3);
416 f = fopen(path, "wb");
417 if (!f) {
418 werror("%s", path);
419 return;
421 fprintf(f, "%02x%02x%1x", image->width, image->height, channels);
423 fwrite(image->data, 1, image->width * image->height * channels, f);
425 fsync(fileno(f));
426 if (fclose(f) < 0) {
427 werror("%s", path);
431 static int isPixmap(WMPropList * prop)
433 WMPropList *p;
434 char *s;
436 p = WMGetFromPLArray(prop, 0);
437 s = WMGetFromPLString(p);
438 if (strcasecmp(&s[1], "pixmap") == 0)
439 return 1;
440 else
441 return 0;
444 /**********************************************************************/
446 static void drawResizebarBevel(RImage * img)
448 RColor light;
449 RColor dark;
450 int width = img->width;
451 int height = img->height;
452 int cwidth = 28;
454 light.alpha = 0;
455 light.red = light.green = light.blue = 80;
457 dark.alpha = 0;
458 dark.red = dark.green = dark.blue = 40;
460 ROperateLine(img, RSubtractOperation, 0, 0, width - 1, 0, &dark);
461 ROperateLine(img, RAddOperation, 0, 1, width - 1, 1, &light);
463 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height - 1, &dark);
464 ROperateLine(img, RAddOperation, cwidth + 1, 2, cwidth + 1, height - 1, &light);
466 ROperateLine(img, RSubtractOperation, width - cwidth - 2, 2, width - cwidth - 2, height - 1, &dark);
467 ROperateLine(img, RAddOperation, width - cwidth - 1, 2, width - cwidth - 1, height - 1, &light);
471 static void drawMenuBevel(RImage * img)
473 RColor light, dark, mid;
474 int i;
475 int iheight = img->height / 4;
477 light.alpha = 0;
478 light.red = light.green = light.blue = 80;
480 dark.alpha = 255;
481 dark.red = dark.green = dark.blue = 0;
483 mid.alpha = 0;
484 mid.red = mid.green = mid.blue = 40;
486 for (i = 1; i < 4; i++) {
487 ROperateLine(img, RSubtractOperation, 0, i * iheight - 2, img->width - 1, i * iheight - 2, &mid);
489 RDrawLine(img, 0, i * iheight - 1, img->width - 1, i * iheight - 1, &dark);
491 ROperateLine(img, RAddOperation, 1, i * iheight, img->width - 2, i * iheight, &light);
495 static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int height, const char *path, int border)
497 char *type;
498 RImage *image = NULL;
499 RImage *timage = NULL;
500 Pixmap pixmap;
501 RContext *rc = WMScreenRContext(scr);
502 char *str;
503 RColor rcolor;
505 type = WMGetFromPLString(WMGetFromPLArray(texture, 0));
507 if (strcasecmp(&type[1], "pixmap") == 0 ||
508 (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T')) {
509 char *path;
511 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
512 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
513 if (path) {
514 timage = RLoadImage(rc, path, 0);
515 if (!timage) {
516 wwarning("could not load file '%s': %s", path ? path : str, RMessageForError(RErrorCode));
517 texture = WMCreatePropListFromDescription("(solid, black)");
518 type = "solid";
520 wfree(path);
524 if (strcasecmp(type, "solid") == 0) {
526 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
528 str2rcolor(rc, str, &rcolor);
530 image = RCreateImage(width, height, False);
531 RClearImage(image, &rcolor);
532 } else if (strcasecmp(type, "igradient") == 0) {
533 int t1, t2;
534 RColor c1[2], c2[2];
536 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
537 str2rcolor(rc, str, &c1[0]);
538 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
539 str2rcolor(rc, str, &c1[1]);
540 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
541 t1 = atoi(str);
543 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
544 str2rcolor(rc, str, &c2[0]);
545 str = WMGetFromPLString(WMGetFromPLArray(texture, 5));
546 str2rcolor(rc, str, &c2[1]);
547 str = WMGetFromPLString(WMGetFromPLArray(texture, 6));
548 t2 = atoi(str);
550 image = RRenderInterwovenGradient(width, height, c1, t1, c2, t2);
551 } else if (strcasecmp(&type[1], "gradient") == 0) {
552 int style;
553 RColor rcolor2;
555 switch (toupper(type[0])) {
556 case 'V':
557 style = RVerticalGradient;
558 break;
559 case 'H':
560 style = RHorizontalGradient;
561 break;
562 default:
563 case 'D':
564 style = RDiagonalGradient;
565 break;
568 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
569 str2rcolor(rc, str, &rcolor);
570 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
571 str2rcolor(rc, str, &rcolor2);
573 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
574 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T') {
575 int style;
576 RColor rcolor2;
577 int i;
578 RImage *grad = NULL;
580 switch (toupper(type[1])) {
581 case 'V':
582 style = RVerticalGradient;
583 break;
584 case 'H':
585 style = RHorizontalGradient;
586 break;
587 default:
588 case 'D':
589 style = RDiagonalGradient;
590 break;
593 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
594 str2rcolor(rc, str, &rcolor);
595 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
596 str2rcolor(rc, str, &rcolor2);
598 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
600 image = RMakeTiledImage(timage, width, height);
601 RReleaseImage(timage);
603 i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
605 RCombineImagesWithOpaqueness(image, grad, i);
606 RReleaseImage(grad);
608 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'M') {
609 int style;
610 RColor **colors;
611 int i, j;
613 switch (toupper(type[1])) {
614 case 'V':
615 style = RVerticalGradient;
616 break;
617 case 'H':
618 style = RHorizontalGradient;
619 break;
620 default:
621 case 'D':
622 style = RDiagonalGradient;
623 break;
626 j = WMGetPropListItemCount(texture);
628 if (j > 0) {
629 colors = wmalloc(j * sizeof(RColor *));
631 for (i = 2; i < j; i++) {
632 str = WMGetFromPLString(WMGetFromPLArray(texture, i));
633 colors[i - 2] = wmalloc(sizeof(RColor));
634 str2rcolor(rc, str, colors[i - 2]);
636 colors[i - 2] = NULL;
638 image = RRenderMultiGradient(width, height, colors, style);
640 for (i = 0; colors[i] != NULL; i++)
641 wfree(colors[i]);
642 wfree(colors);
644 } else if (strcasecmp(&type[1], "pixmap") == 0) {
645 RColor color;
647 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
648 str2rcolor(rc, str, &color);
650 switch (toupper(type[0])) {
651 case 'T':
652 image = RMakeTiledImage(timage, width, height);
653 RReleaseImage(timage);
654 break;
655 case 'C':
656 image = RMakeCenteredImage(timage, width, height, &color);
657 RReleaseImage(timage);
658 break;
659 case 'S':
660 case 'M':
661 image = RScaleImage(timage, width, height);
662 RReleaseImage(timage);
663 break;
667 if (!image)
668 return None;
670 if (path) {
671 dumpRImage(path, image);
674 if (border < 0) {
675 if (border == RESIZEBAR_BEVEL) {
676 drawResizebarBevel(image);
677 } else if (border == MENU_BEVEL) {
678 drawMenuBevel(image);
679 RBevelImage(image, RBEV_RAISED2);
681 } else if (border) {
682 RBevelImage(image, border);
685 RConvertImage(rc, image, &pixmap);
686 RReleaseImage(image);
688 return pixmap;
691 static Pixmap renderMenu(_Panel * panel, WMPropList * texture, int width, int iheight)
693 WMScreen *scr = WMWidgetScreen(panel->parent);
694 Display *dpy = WMScreenDisplay(scr);
695 Pixmap pix, tmp;
696 GC gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
697 int i;
699 switch (panel->menuStyle) {
700 case MSTYLE_NORMAL:
701 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
703 pix = XCreatePixmap(dpy, tmp, width, iheight * 4, WMScreenDepth(scr));
704 for (i = 0; i < 4; i++) {
705 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight * i);
707 XFreePixmap(dpy, tmp);
708 break;
709 case MSTYLE_SINGLE:
710 pix = renderTexture(scr, texture, width, iheight * 4, NULL, MENU_BEVEL);
711 break;
712 case MSTYLE_FLAT:
713 pix = renderTexture(scr, texture, width, iheight * 4, NULL, RBEV_RAISED2);
714 break;
715 default:
716 pix = None;
718 XFreeGC(dpy, gc);
720 return pix;
723 static void renderPreview(_Panel * panel, GC gc, int part, int relief)
725 WMListItem *item;
726 TextureListItem *titem;
727 Pixmap pix;
728 WMScreen *scr = WMWidgetScreen(panel->box);
730 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
731 titem = (TextureListItem *) item->clientData;
733 pix = renderTexture(scr, titem->prop,
734 previewPositions[part].size.width, previewPositions[part].size.height, NULL, relief);
736 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
737 previewPositions[part].size.width,
738 previewPositions[part].size.height, previewPositions[part].pos.x, previewPositions[part].pos.y);
740 XCopyArea(WMScreenDisplay(scr), pix, panel->previewNoText, gc, 0, 0,
741 previewPositions[part].size.width,
742 previewPositions[part].size.height, previewPositions[part].pos.x, previewPositions[part].pos.y);
744 XFreePixmap(WMScreenDisplay(scr), pix);
747 static void updatePreviewBox(_Panel * panel, int elements)
749 WMScreen *scr = WMWidgetScreen(panel->parent);
750 Display *dpy = WMScreenDisplay(scr);
751 Pixmap pix;
752 GC gc;
753 int colorUpdate = 0;
755 gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
757 if (panel->preview == None) {
758 WMPixmap *p;
760 panel->previewNoText = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
761 240 - 4, 215 - 4, WMScreenDepth(scr));
762 panel->previewBack = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
763 240 - 4, 215 - 4, WMScreenDepth(scr));
765 p = WMCreatePixmap(scr, 240 - 4, 215 - 4, WMScreenDepth(scr), False);
766 panel->preview = WMGetPixmapXID(p);
767 WMSetLabelImage(panel->prevL, p);
768 WMReleasePixmap(p);
770 if (elements & (1 << PBACKGROUND)) {
771 Pixmap tmp;
772 TextureListItem *titem;
773 WMListItem *item;
775 item = WMGetListItem(panel->texLs,
776 panel->textureIndex[PBACKGROUND]);
777 titem = (TextureListItem *) item->clientData;
778 tmp = renderTexture(scr, titem->prop, 240 - 4, 215 - 4, NULL, 0);
780 XCopyArea(dpy, tmp, panel->preview, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
781 XCopyArea(dpy, tmp, panel->previewNoText, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
782 XCopyArea(dpy, tmp, panel->previewBack, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
783 XFreePixmap(dpy, tmp);
786 if (elements & (1 << PFOCUSED)) {
787 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
788 colorUpdate |= 1 << FTITLE_COL | 1 << FSBORDER_COL;
790 if (elements & (1 << PUNFOCUSED)) {
791 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
792 colorUpdate |= 1 << UTITLE_COL | 1 << FBORDER_COL;
794 if (elements & (1 << POWNER)) {
795 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
796 colorUpdate |= 1 << OTITLE_COL | 1 << FBORDER_COL;
798 if (elements & (1 << PRESIZEBAR)) {
799 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
800 colorUpdate |= 1 << FBORDER_COL;
802 if (elements & (1 << PMTITLE)) {
803 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
804 colorUpdate |= 1 << MTITLE_COL | 1 << FBORDER_COL;
806 if (elements & (1 << PMITEM)) {
807 WMListItem *item;
808 TextureListItem *titem;
810 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
811 titem = (TextureListItem *) item->clientData;
813 pix = renderMenu(panel, titem->prop,
814 previewPositions[PMITEM].size.width, previewPositions[PMITEM].size.height / 4);
816 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
817 previewPositions[PMITEM].size.width,
818 previewPositions[PMITEM].size.height,
819 previewPositions[PMITEM].pos.x, previewPositions[PMITEM].pos.y);
821 XCopyArea(dpy, pix, panel->previewNoText, gc, 0, 0,
822 previewPositions[PMITEM].size.width,
823 previewPositions[PMITEM].size.height,
824 previewPositions[PMITEM].pos.x, previewPositions[PMITEM].pos.y);
826 XFreePixmap(dpy, pix);
828 colorUpdate |= 1 << MITEM_COL | 1 << MDISAB_COL |
829 1 << MHIGH_COL | 1 << MHIGHT_COL |
830 1 << FBORDER_COL;
832 if (elements & (1 << PICON)) {
833 WMListItem *item;
834 TextureListItem *titem;
836 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
837 titem = (TextureListItem *) item->clientData;
839 renderPreview(panel, gc, PICON, titem->ispixmap ? 0 : RBEV_RAISED3);
841 colorUpdate |= 1 << ICONT_COL | 1 << ICONB_COL |
842 1 << CLIP_COL | 1 << CCLIP_COL;
845 if (colorUpdate)
846 updateColorPreviewBox(panel, colorUpdate);
847 else
848 WMRedisplayWidget(panel->prevL);
850 XFreeGC(dpy, gc);
853 static void cancelNewTexture(void *data)
855 _Panel *panel = (_Panel *) data;
857 HideTexturePanel(panel->texturePanel);
860 static char *makeFileName(const char *prefix)
862 char *fname;
864 fname = wstrdup(prefix);
866 while (access(fname, F_OK) == 0) {
867 char buf[30];
869 wfree(fname);
870 sprintf(buf, "%08lx.cache", time(NULL));
871 fname = wstrconcat(prefix, buf);
874 return fname;
877 static void okNewTexture(void *data)
879 _Panel *panel = (_Panel *) data;
880 WMListItem *item;
881 char *name;
882 char *str;
883 WMPropList *prop;
884 TextureListItem *titem;
885 WMScreen *scr = WMWidgetScreen(panel->parent);
887 titem = wmalloc(sizeof(TextureListItem));
889 HideTexturePanel(panel->texturePanel);
891 name = GetTexturePanelTextureName(panel->texturePanel);
893 prop = GetTexturePanelTexture(panel->texturePanel);
895 str = WMGetPropListDescription(prop, False);
897 titem->title = name;
898 titem->prop = prop;
899 titem->texture = str;
900 titem->selectedFor = 0;
902 titem->ispixmap = isPixmap(prop);
904 titem->path = makeFileName(panel->fprefix);
905 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
907 item = WMAddListItem(panel->texLs, "");
908 item->clientData = titem;
910 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
913 static void okEditTexture(void *data)
915 _Panel *panel = (_Panel *) data;
916 WMListItem *item;
917 char *name;
918 char *str;
919 WMPropList *prop;
920 TextureListItem *titem;
922 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
923 titem = (TextureListItem *) item->clientData;
925 HideTexturePanel(panel->texturePanel);
927 if (titem->current) {
928 name = GetTexturePanelTextureName(panel->texturePanel);
930 wfree(titem->title);
931 titem->title = name;
934 prop = GetTexturePanelTexture(panel->texturePanel);
936 str = WMGetPropListDescription(prop, False);
938 WMReleasePropList(titem->prop);
939 titem->prop = prop;
941 titem->ispixmap = isPixmap(prop);
943 wfree(titem->texture);
944 titem->texture = str;
946 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
947 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
948 TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
950 WMRedisplayWidget(panel->texLs);
952 if (titem->selectedFor) {
953 if (titem->selectedFor & (1 << PBACKGROUND))
954 updatePreviewBox(panel, EVERYTHING);
955 else
956 updatePreviewBox(panel, titem->selectedFor);
959 changePage(panel->secP, panel);
962 static void editTexture(WMWidget * w, void *data)
964 _Panel *panel = (_Panel *) data;
965 WMListItem *item;
966 TextureListItem *titem;
968 /* Parameter not used, but tell the compiler that it is ok */
969 (void) w;
971 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
972 titem = (TextureListItem *) item->clientData;
974 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
976 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
978 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
979 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
981 ShowTexturePanel(panel->texturePanel);
984 static void newTexture(WMWidget * w, void *data)
986 _Panel *panel = (_Panel *) data;
988 /* Parameter not used, but tell the compiler that it is ok */
989 (void) w;
991 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
993 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
995 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
997 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
999 ShowTexturePanel(panel->texturePanel);
1002 static void deleteTexture(WMWidget * w, void *data)
1004 _Panel *panel = (_Panel *) data;
1005 WMListItem *item;
1006 TextureListItem *titem;
1007 int row;
1008 int section;
1010 /* Parameter not used, but tell the compiler that it is ok */
1011 (void) w;
1013 section = WMGetPopUpButtonSelectedItem(panel->secP);
1014 row = WMGetListSelectedItemRow(panel->texLs);
1015 item = WMGetListItem(panel->texLs, row);
1016 titem = (TextureListItem *) item->clientData;
1018 if (titem->selectedFor & (1 << section)) {
1019 TextureListItem *titem2;
1021 panel->textureIndex[section] = section;
1022 item = WMGetListItem(panel->texLs, section);
1023 titem2 = (TextureListItem *) item->clientData;
1024 titem2->selectedFor |= 1 << section;
1027 wfree(titem->title);
1028 wfree(titem->texture);
1029 WMReleasePropList(titem->prop);
1030 if (titem->path) {
1031 if (remove(titem->path) < 0 && errno != ENOENT) {
1032 werror("could not remove file %s", titem->path);
1034 wfree(titem->path);
1037 wfree(titem);
1039 WMRemoveListItem(panel->texLs, row);
1040 WMSetButtonEnabled(panel->delB, False);
1043 static void extractTexture(WMWidget * w, void *data)
1045 _Panel *panel = (_Panel *) data;
1046 char *path;
1047 WMOpenPanel *opanel;
1048 WMScreen *scr = WMWidgetScreen(w);
1050 opanel = WMGetOpenPanel(scr);
1051 WMSetFilePanelCanChooseDirectories(opanel, False);
1052 WMSetFilePanelCanChooseFiles(opanel, True);
1054 if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(), _("Select File"), NULL)) {
1055 path = WMGetFilePanelFileName(opanel);
1057 OpenExtractPanelFor(panel);
1059 wfree(path);
1063 static void changePage(WMWidget * w, void *data)
1065 _Panel *panel = (_Panel *) data;
1066 int section;
1067 WMScreen *scr = WMWidgetScreen(panel->box);
1068 RContext *rc = WMScreenRContext(scr);
1069 static WMPoint positions[] = {
1070 {5, 10},
1071 {5, 40},
1072 {5, 70},
1073 {5, 100},
1074 {5, 120},
1075 {5, 160},
1076 {130, 150}
1079 if (w) {
1080 section = WMGetPopUpButtonSelectedItem(panel->secP);
1082 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1084 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1087 GC gc;
1089 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1090 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1091 positions[panel->oldsection].x,
1092 positions[panel->oldsection].y, 22, 22 ,
1093 positions[panel->oldsection].x,
1094 positions[panel->oldsection].y);
1096 if (w) {
1097 panel->oldsection = section;
1098 WMDrawPixmap(panel->hand, panel->preview, positions[section].x, positions[section].y);
1100 WMRedisplayWidget(panel->prevL);
1103 static void previewClick(XEvent * event, void *clientData)
1105 _Panel *panel = (_Panel *) clientData;
1106 int i;
1108 switch (panel->oldTabItem) {
1109 case 0:
1110 for (i = 0; i < wlengthof(previewPositions); i++) {
1111 if (event->xbutton.x >= previewPositions[i].pos.x
1112 && event->xbutton.y >= previewPositions[i].pos.y
1113 && event->xbutton.x < previewPositions[i].pos.x
1114 + previewPositions[i].size.width
1115 && event->xbutton.y < previewPositions[i].pos.y + previewPositions[i].size.height) {
1117 WMSetPopUpButtonSelectedItem(panel->secP, i);
1118 changePage(panel->secP, panel);
1119 return;
1122 break;
1123 case 1:
1124 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1125 if (event->xbutton.x >= previewColorPositions[i].pos.x
1126 && event->xbutton.y >= previewColorPositions[i].pos.y
1127 && event->xbutton.x < previewColorPositions[i].pos.x
1128 + previewColorPositions[i].size.width
1129 && event->xbutton.y < previewColorPositions[i].pos.y
1130 + previewColorPositions[i].size.height) {
1132 /* yuck kluge */
1133 if (i == 7)
1134 i = 4;
1136 WMSetPopUpButtonSelectedItem(panel->colP, i);
1137 changeColorPage(panel->colP, panel);
1138 return;
1141 break;
1145 static void textureClick(WMWidget * w, void *data)
1147 _Panel *panel = (_Panel *) data;
1148 int i;
1149 WMListItem *item;
1150 TextureListItem *titem;
1152 /* Parameter not used, but tell the compiler that it is ok */
1153 (void) w;
1155 i = WMGetListSelectedItemRow(panel->texLs);
1157 item = WMGetListItem(panel->texLs, i);
1159 titem = (TextureListItem *) item->clientData;
1161 if (titem->current) {
1162 WMSetButtonEnabled(panel->delB, False);
1163 } else {
1164 WMSetButtonEnabled(panel->delB, True);
1168 static void textureDoubleClick(WMWidget * w, void *data)
1170 _Panel *panel = (_Panel *) data;
1171 int i, section;
1172 WMListItem *item;
1173 TextureListItem *titem;
1175 /* Parameter not used, but tell the compiler that it is ok */
1176 (void) w;
1178 /* unselect old texture */
1179 section = WMGetPopUpButtonSelectedItem(panel->secP);
1181 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1182 titem = (TextureListItem *) item->clientData;
1183 titem->selectedFor &= ~(1 << section);
1185 /* select new texture */
1186 i = WMGetListSelectedItemRow(panel->texLs);
1188 item = WMGetListItem(panel->texLs, i);
1190 titem = (TextureListItem *) item->clientData;
1192 titem->selectedFor |= 1 << section;
1194 panel->textureIndex[section] = i;
1196 WMRedisplayWidget(panel->texLs);
1198 if (section == PBACKGROUND)
1199 updatePreviewBox(panel, EVERYTHING);
1200 else
1201 updatePreviewBox(panel, 1 << section);
1204 static void paintListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
1206 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
1207 WMScreen *scr = WMWidgetScreen(lPtr);
1208 int width, height, x, y;
1209 Display *dpy = WMScreenDisplay(scr);
1210 WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
1211 WMListItem *item;
1212 WMColor *black = WMBlackColor(scr);
1213 TextureListItem *titem;
1215 /* Parameter not used, but tell the compiler that it is ok */
1216 (void) text;
1218 item = WMGetListItem(lPtr, index);
1219 titem = (TextureListItem *) item->clientData;
1220 if (!titem) {
1221 WMReleaseColor(back);
1222 WMReleaseColor(black);
1223 return;
1226 width = rect->size.width;
1227 height = rect->size.height;
1228 x = rect->pos.x;
1229 y = rect->pos.y;
1231 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
1233 if (titem->preview)
1234 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1235 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1237 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1238 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1239 else if (titem->selectedFor)
1240 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1242 WMDrawString(scr, d, black, panel->boldFont,
1243 x + TEXPREV_WIDTH + 22, y + 2, titem->title, strlen(titem->title));
1245 WMDrawString(scr, d, black, panel->smallFont,
1246 x + TEXPREV_WIDTH + 14, y + 18, titem->texture, strlen(titem->texture));
1248 WMReleaseColor(back);
1249 WMReleaseColor(black);
1252 static Pixmap loadRImage(WMScreen * scr, const char *path)
1254 FILE *f;
1255 RImage *image;
1256 int w, h, d, cnt;
1257 size_t read_size;
1258 Pixmap pixmap;
1260 f = fopen(path, "rb");
1261 if (!f)
1262 return None;
1264 cnt = fscanf(f, "%02x%02x%1x", &w, &h, &d);
1265 if (cnt != 3) {
1266 fclose(f);
1267 return None;
1269 image = RCreateImage(w, h, d == 4);
1270 read_size = w * h * d;
1271 if (fread(image->data, 1, read_size, f) != read_size) {
1272 fclose(f);
1273 return None;
1275 fclose(f);
1277 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1278 RReleaseImage(image);
1280 return pixmap;
1283 static void fillTextureList(WMList * lPtr)
1285 WMPropList *textureList;
1286 WMPropList *texture;
1287 WMUserDefaults *udb = WMGetStandardUserDefaults();
1288 TextureListItem *titem;
1289 WMScreen *scr = WMWidgetScreen(lPtr);
1290 int i;
1292 textureList = WMGetUDObjectForKey(udb, "TextureList");
1293 if (!textureList)
1294 return;
1296 for (i = 0; i < WMGetPropListItemCount(textureList); i++) {
1297 WMListItem *item;
1299 texture = WMGetFromPLArray(textureList, i);
1301 titem = wmalloc(sizeof(TextureListItem));
1303 titem->title = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 0)));
1304 titem->prop = WMRetainPropList(WMGetFromPLArray(texture, 1));
1305 titem->texture = WMGetPropListDescription(titem->prop, False);
1306 titem->selectedFor = 0;
1307 titem->path = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
1309 titem->preview = loadRImage(scr, titem->path);
1310 if (!titem->preview) {
1311 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1313 item = WMAddListItem(lPtr, "");
1314 item->clientData = titem;
1318 static void fillColorList(_Panel * panel)
1320 WMColor *color;
1321 WMPropList *list;
1322 WMUserDefaults *udb = WMGetStandardUserDefaults();
1323 WMScreen *scr = WMWidgetScreen(panel->box);
1324 int i;
1326 list = WMGetUDObjectForKey(udb, "ColorList");
1327 if (!list) {
1328 for (i = 0; i < 24; i++) {
1329 color = WMCreateNamedColor(scr, sampleColors[i], False);
1330 if (!color)
1331 continue;
1332 WMSetColorWellColor(panel->sampW[i], color);
1333 WMReleaseColor(color);
1335 } else {
1336 WMPropList *c;
1338 for (i = 0; i < WMIN(24, WMGetPropListItemCount(list)); i++) {
1339 c = WMGetFromPLArray(list, i);
1340 if (!c || !WMIsPLString(c))
1341 continue;
1342 color = WMCreateNamedColor(scr, WMGetFromPLString(c), False);
1343 if (!color)
1344 continue;
1345 WMSetColorWellColor(panel->sampW[i], color);
1346 WMReleaseColor(color);
1351 /*************************************************************************/
1353 static void changeColorPage(WMWidget * w, void *data)
1355 _Panel *panel = (_Panel *) data;
1356 int section;
1357 WMScreen *scr = WMWidgetScreen(panel->box);
1358 RContext *rc = WMScreenRContext(scr);
1359 static WMPoint positions[] = {
1360 {5, 10},
1361 {5, 40},
1362 {5, 70},
1363 {5, 120},
1364 {5, 140},
1365 {5, 160},
1366 {5, 180},
1367 {5, 180},
1368 {5, 40},
1369 {5, 10},
1370 {130, 140},
1371 {130, 140},
1372 {130, 140},
1373 {130, 140}
1376 if (panel->preview) {
1377 GC gc;
1379 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1380 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1381 positions[panel->oldcsection].x,
1382 positions[panel->oldcsection].y, 22, 22 ,
1383 positions[panel->oldcsection].x,
1384 positions[panel->oldcsection].y);
1386 if (w) {
1387 section = WMGetPopUpButtonSelectedItem(panel->colP);
1389 panel->oldcsection = section;
1390 if (panel->preview)
1391 WMDrawPixmap(panel->hand, panel->preview, positions[section].x, positions[section].y);
1393 section = WMGetPopUpButtonSelectedItem(panel->colP);
1395 WMSetColorWellColor(panel->colW, panel->colors[section]);
1397 WMRedisplayWidget(panel->prevL);
1400 static void
1401 paintText(WMScreen * scr, Drawable d, WMColor * color, WMFont * font,
1402 int x, int y, int w, int h, WMAlignment align, char *text)
1404 int l = strlen(text);
1406 switch (align) {
1407 case WALeft:
1408 x += 5;
1409 break;
1410 case WARight:
1411 x += w - 5 - WMWidthOfString(font, text, l);
1412 break;
1413 default:
1414 case WACenter:
1415 x += (w - WMWidthOfString(font, text, l)) / 2;
1416 break;
1418 WMDrawString(scr, d, color, font, x, y + (h - WMFontHeight(font)) / 2, text, l);
1421 static void updateColorPreviewBox(_Panel * panel, int elements)
1423 WMScreen *scr = WMWidgetScreen(panel->box);
1424 Display *dpy = WMScreenDisplay(scr);
1425 Pixmap d, pnot;
1426 GC gc;
1428 d = panel->preview;
1429 pnot = panel->previewNoText;
1430 gc = WMColorGC(panel->colors[FTITLE_COL]);
1432 if (elements & (1 << FTITLE_COL)) {
1433 XCopyArea(dpy, pnot, d, gc, 30, 10, 190, 20, 30, 10);
1434 paintText(scr, d, panel->colors[FTITLE_COL],
1435 panel->boldFont, 30, 10, 190, 20,
1436 panel->titleAlignment, _("Focused Window"));
1438 if (elements & (1 << UTITLE_COL)) {
1439 XCopyArea(dpy, pnot, d, gc, 30, 40, 190, 20, 30, 40);
1440 paintText(scr, d, panel->colors[UTITLE_COL],
1441 panel->boldFont, 30, 40, 190, 20,
1442 panel->titleAlignment,
1443 _("Unfocused Window"));
1445 if (elements & (1 << OTITLE_COL)) {
1446 XCopyArea(dpy, pnot, d, gc, 30, 70, 190, 20, 30, 70);
1447 paintText(scr, d, panel->colors[OTITLE_COL],
1448 panel->boldFont, 30, 70, 190, 20,
1449 panel->titleAlignment,
1450 _("Owner of Focused Window"));
1452 if (elements & (1 << MTITLE_COL)) {
1453 XCopyArea(dpy, pnot, d, gc, 30, 120, 90, 20, 30, 120);
1454 paintText(scr, d, panel->colors[MTITLE_COL],
1455 panel->boldFont, 30, 120, 90, 20, WALeft,
1456 _("Menu Title"));
1458 if (elements & (1 << MITEM_COL)) {
1459 XCopyArea(dpy, pnot, d, gc, 30, 140, 90, 20, 30, 140);
1460 paintText(scr, d, panel->colors[MITEM_COL],
1461 panel->normalFont, 30, 140, 90, 20, WALeft,
1462 _("Normal Item"));
1463 XCopyArea(dpy, pnot, d, gc, 30, 200, 90, 20, 30, 200);
1464 paintText(scr, d, panel->colors[MITEM_COL],
1465 panel->normalFont, 30, 200, 90, 20, WALeft,
1466 _("Normal Item"));
1468 if (elements & (1 << MDISAB_COL)) {
1469 XCopyArea(dpy, pnot, d, gc, 30, 160, 90, 20, 30, 160);
1470 paintText(scr, d, panel->colors[MDISAB_COL],
1471 panel->normalFont, 30, 160, 90, 20, WALeft,
1472 _("Disabled Item"));
1474 if (elements & (1 << MHIGH_COL)) {
1475 XFillRectangle(WMScreenDisplay(scr), d,
1476 WMColorGC(panel->colors[MHIGH_COL]),
1477 31, 181, 87, 17);
1478 XFillRectangle(WMScreenDisplay(scr), pnot,
1479 WMColorGC(panel->colors[MHIGH_COL]),
1480 31, 181, 87, 17);
1481 elements |= 1 << MHIGHT_COL;
1483 if (elements & (1 << MHIGHT_COL)) {
1484 XCopyArea(dpy, pnot, d, gc, 30, 180, 90, 20, 30, 180);
1485 paintText(scr, d, panel->colors[MHIGHT_COL],
1486 panel->normalFont, 30, 180, 90, 20, WALeft,
1487 _("Highlighted"));
1489 if (elements & (1 << FBORDER_COL)) {
1490 XDrawRectangle(dpy, pnot,
1491 WMColorGC(panel->colors[FBORDER_COL]),
1492 29, 39, 190, 20);
1493 XDrawRectangle(dpy, d,
1494 WMColorGC(panel->colors[FBORDER_COL]),
1495 29, 39, 190, 20);
1496 XDrawRectangle(dpy, pnot,
1497 WMColorGC(panel->colors[FBORDER_COL]),
1498 29, 69, 190, 20);
1499 XDrawRectangle(dpy, d,
1500 WMColorGC(panel->colors[FBORDER_COL]),
1501 29, 69, 190, 20);
1502 XDrawLine(dpy, pnot,
1503 WMColorGC(panel->colors[FBORDER_COL]),
1504 30, 100, 30, 109);
1505 XDrawLine(dpy, d,
1506 WMColorGC(panel->colors[FBORDER_COL]),
1507 30, 100, 30, 109);
1508 XDrawLine(dpy, pnot,
1509 WMColorGC(panel->colors[FBORDER_COL]),
1510 31, 109, 219, 109);
1511 XDrawLine(dpy, d,
1512 WMColorGC(panel->colors[FBORDER_COL]),
1513 31, 109, 219, 109);
1514 XDrawLine(dpy, pnot,
1515 WMColorGC(panel->colors[FBORDER_COL]),
1516 220, 100, 220, 109);
1517 XDrawLine(dpy, d,
1518 WMColorGC(panel->colors[FBORDER_COL]),
1519 220, 100, 220, 109);
1520 XDrawLine(dpy, pnot,
1521 WMColorGC(panel->colors[FBORDER_COL]),
1522 29, 120, 29, 220);
1523 XDrawLine(dpy, d,
1524 WMColorGC(panel->colors[FBORDER_COL]),
1525 29, 120, 29, 220);
1526 XDrawLine(dpy, pnot,
1527 WMColorGC(panel->colors[FBORDER_COL]),
1528 29, 119, 119, 119);
1529 XDrawLine(dpy, d,
1530 WMColorGC(panel->colors[FBORDER_COL]),
1531 29, 119, 119, 119);
1532 XDrawLine(dpy, pnot,
1533 WMColorGC(panel->colors[FBORDER_COL]),
1534 119, 120, 119, 220);
1535 XDrawLine(dpy, d,
1536 WMColorGC(panel->colors[FBORDER_COL]),
1537 119, 120, 119, 220);
1539 if (elements & (1 << FSBORDER_COL)) {
1540 XDrawRectangle(dpy, pnot,
1541 WMColorGC(panel->
1542 colors[FSBORDER_COL]),
1543 29, 9, 190, 20);
1544 XDrawRectangle(dpy, d,
1545 WMColorGC(panel->
1546 colors[FSBORDER_COL]),
1547 29, 9, 190, 20);
1551 if (elements & (1 << ICONT_COL)) {
1552 WRITE(_("Focused Window"), panel->colors[ICONT_COL],
1553 panel->boldFont,
1554 155, 130, 64);
1556 if (elements & (1 << ICONB_COL)) {
1557 WRITE(_("Focused Window"), panel->colors[ICONB_COL],
1558 panel->boldFont,
1559 0, 0, 30);
1561 if (elements & (1 << CLIP_COL)) {
1562 WRITE(_("Focused Window"), panel->colors[CLIP_COL],
1563 panel->boldFont,
1564 0, 0, 30);
1566 if (elements & (1 << CCLIP_COL)) {
1567 WRITE(_("Focused Window"), panel->colors[CCLIP_COL],
1568 panel->boldFont,
1569 0, 0, 30);
1572 WMRedisplayWidget(panel->prevL);
1575 static void colorWellObserver(void *self, WMNotification * n)
1577 _Panel *panel = (_Panel *) self;
1578 int p;
1580 /* Parameter not used, but tell the compiler that it is ok */
1581 (void) n;
1583 p = WMGetPopUpButtonSelectedItem(panel->colP);
1585 WMReleaseColor(panel->colors[p]);
1587 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1589 updateColorPreviewBox(panel, 1 << p);
1592 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item)
1594 _Panel *panel = self->data;
1595 int i;
1597 /* Parameter not used, but tell the compiler that it is ok */
1598 (void) tabView;
1600 i = WMGetTabViewItemIdentifier(item);
1601 switch (i) {
1602 case TAB_TEXTURE:
1603 switch (panel->oldTabItem) {
1604 case TAB_COLOR:
1605 changeColorPage(NULL, panel);
1606 break;
1608 changePage(panel->secP, panel);
1609 break;
1610 case TAB_COLOR:
1611 switch (panel->oldTabItem) {
1612 case TAB_TEXTURE:
1613 changePage(NULL, panel);
1614 break;
1616 changeColorPage(panel->colP, panel);
1617 break;
1618 case TAB_OPTIONS:
1619 switch (panel->oldTabItem) {
1620 case TAB_TEXTURE:
1621 changePage(NULL, panel);
1622 break;
1623 case TAB_COLOR:
1624 changeColorPage(NULL, panel);
1625 break;
1627 break;
1630 panel->oldTabItem = i;
1633 /*************************************************************************/
1635 static void menuStyleCallback(WMWidget * self, void *data)
1637 _Panel *panel = (_Panel *) data;
1639 if (self == panel->mstyB[0]) {
1640 panel->menuStyle = MSTYLE_NORMAL;
1641 updatePreviewBox(panel, 1 << PMITEM);
1643 } else if (self == panel->mstyB[1]) {
1644 panel->menuStyle = MSTYLE_SINGLE;
1645 updatePreviewBox(panel, 1 << PMITEM);
1647 } else if (self == panel->mstyB[2]) {
1648 panel->menuStyle = MSTYLE_FLAT;
1649 updatePreviewBox(panel, 1 << PMITEM);
1653 static void titleAlignCallback(WMWidget * self, void *data)
1655 _Panel *panel = (_Panel *) data;
1657 if (self == panel->taliB[0]) {
1658 panel->titleAlignment = WALeft;
1659 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1661 } else if (self == panel->taliB[1]) {
1662 panel->titleAlignment = WACenter;
1663 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1665 } else if (self == panel->taliB[2]) {
1666 panel->titleAlignment = WARight;
1667 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1671 static void createPanel(Panel * p)
1673 _Panel *panel = (_Panel *) p;
1674 WMFont *font;
1675 WMScreen *scr = WMWidgetScreen(panel->parent);
1676 WMTabViewItem *item;
1677 int i;
1678 char *tmp;
1679 Bool ok = True;
1681 panel->fprefix = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1683 if (access(panel->fprefix, F_OK) != 0) {
1684 if (mkdir(panel->fprefix, 0755) < 0) {
1685 werror("%s", panel->fprefix);
1686 ok = False;
1689 if (ok) {
1690 tmp = wstrconcat(panel->fprefix, "/WPrefs/");
1691 wfree(panel->fprefix);
1692 panel->fprefix = tmp;
1693 if (access(panel->fprefix, F_OK) != 0) {
1694 if (mkdir(panel->fprefix, 0755) < 0) {
1695 werror("%s", panel->fprefix);
1700 panel->smallFont = WMSystemFontOfSize(scr, 10);
1701 panel->normalFont = WMSystemFontOfSize(scr, 12);
1702 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1704 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1705 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1706 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1708 panel->box = WMCreateBox(panel->parent);
1709 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1711 /* preview box */
1712 panel->prevL = WMCreateLabel(panel->box);
1713 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1714 WMMoveWidget(panel->prevL, 15, 10);
1715 WMSetLabelRelief(panel->prevL, WRSunken);
1716 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1718 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask, previewClick, panel);
1720 /* tabview */
1722 tabviewDelegate.data = panel;
1724 panel->tabv = WMCreateTabView(panel->box);
1725 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1726 WMMoveWidget(panel->tabv, 265, 10);
1727 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1729 /*** texture list ***/
1731 panel->texF = WMCreateFrame(panel->box);
1732 WMSetFrameRelief(panel->texF, WRFlat);
1734 item = WMCreateTabViewItemWithIdentifier(TAB_TEXTURE);
1735 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1736 WMSetTabViewItemLabel(item, _("Texture"));
1738 WMAddItemInTabView(panel->tabv, item);
1740 panel->secP = WMCreatePopUpButton(panel->texF);
1741 WMResizeWidget(panel->secP, 228, 20);
1742 WMMoveWidget(panel->secP, 7, 7);
1743 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1744 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1745 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1746 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1747 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1748 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1749 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1750 WMAddPopUpButtonItem(panel->secP, _("Workspace Background"));
1752 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1753 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1755 panel->texLs = WMCreateList(panel->texF);
1756 WMResizeWidget(panel->texLs, 165, 155);
1757 WMMoveWidget(panel->texLs, 70, 33);
1758 WMSetListUserDrawItemHeight(panel->texLs, 35);
1759 WMSetListUserDrawProc(panel->texLs, paintListItem);
1760 WMHangData(panel->texLs, panel);
1761 WMSetListAction(panel->texLs, textureClick, panel);
1762 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1764 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1765 "for the selected item."), WMWidgetView(panel->texLs));
1767 /* command buttons */
1769 font = WMSystemFontOfSize(scr, 10);
1771 panel->newB = WMCreateCommandButton(panel->texF);
1772 WMResizeWidget(panel->newB, 57, 39);
1773 WMMoveWidget(panel->newB, 7, 33);
1774 WMSetButtonFont(panel->newB, font);
1775 WMSetButtonImagePosition(panel->newB, WIPAbove);
1776 WMSetButtonText(panel->newB, _("New"));
1777 WMSetButtonAction(panel->newB, newTexture, panel);
1778 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1780 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel->newB));
1782 panel->ripB = WMCreateCommandButton(panel->texF);
1783 WMResizeWidget(panel->ripB, 57, 39);
1784 WMMoveWidget(panel->ripB, 7, 72);
1785 WMSetButtonFont(panel->ripB, font);
1786 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1787 WMSetButtonText(panel->ripB, _("Extract..."));
1788 WMSetButtonAction(panel->ripB, extractTexture, panel);
1789 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1791 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel->ripB));
1793 WMSetButtonEnabled(panel->ripB, False);
1795 panel->editB = WMCreateCommandButton(panel->texF);
1796 WMResizeWidget(panel->editB, 57, 39);
1797 WMMoveWidget(panel->editB, 7, 111);
1798 WMSetButtonFont(panel->editB, font);
1799 WMSetButtonImagePosition(panel->editB, WIPAbove);
1800 WMSetButtonText(panel->editB, _("Edit"));
1801 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1802 WMSetButtonAction(panel->editB, editTexture, panel);
1803 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel->editB));
1805 panel->delB = WMCreateCommandButton(panel->texF);
1806 WMResizeWidget(panel->delB, 57, 38);
1807 WMMoveWidget(panel->delB, 7, 150);
1808 WMSetButtonFont(panel->delB, font);
1809 WMSetButtonImagePosition(panel->delB, WIPAbove);
1810 WMSetButtonText(panel->delB, _("Delete"));
1811 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1812 WMSetButtonEnabled(panel->delB, False);
1813 WMSetButtonAction(panel->delB, deleteTexture, panel);
1814 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel->delB));
1816 WMReleaseFont(font);
1818 WMMapSubwidgets(panel->texF);
1820 /*** colors ***/
1821 panel->colF = WMCreateFrame(panel->box);
1822 WMSetFrameRelief(panel->colF, WRFlat);
1824 item = WMCreateTabViewItemWithIdentifier(TAB_COLOR);
1825 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1826 WMSetTabViewItemLabel(item, _("Color"));
1828 WMAddItemInTabView(panel->tabv, item);
1830 panel->colP = WMCreatePopUpButton(panel->colF);
1831 WMResizeWidget(panel->colP, 228, 20);
1832 WMMoveWidget(panel->colP, 7, 7);
1833 WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1834 WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1835 WMAddPopUpButtonItem(panel->colP, _("Owner of Focused Window Title"));
1836 WMAddPopUpButtonItem(panel->colP, _("Menu Title"));
1837 WMAddPopUpButtonItem(panel->colP, _("Menu Item Text"));
1838 WMAddPopUpButtonItem(panel->colP, _("Disabled Menu Item Text"));
1839 WMAddPopUpButtonItem(panel->colP, _("Menu Highlight Color"));
1840 WMAddPopUpButtonItem(panel->colP, _("Highlighted Menu Text Color"));
1841 WMAddPopUpButtonItem(panel->colP, _("Frame Border Color"));
1842 WMAddPopUpButtonItem(panel->colP, _("Selected Frame Border Color"));
1844 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1845 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1846 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1847 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1850 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1852 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1854 panel->colW = WMCreateColorWell(panel->colF);
1855 WMResizeWidget(panel->colW, 65, 50);
1856 WMMoveWidget(panel->colW, 30, 75);
1857 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->colW);
1859 for (i = 0; i < 4; i++) {
1860 int j;
1861 for (j = 0; j < 6; j++) {
1862 panel->sampW[i + j * 4] = WMCreateColorWell(panel->colF);
1863 WMResizeWidget(panel->sampW[i + j * 4], 22, 22);
1864 WMMoveWidget(panel->sampW[i + j * 4], 130 + i * 22, 40 + j * 22);
1865 WSetColorWellBordered(panel->sampW[i + j * 4], False);
1869 WMMapSubwidgets(panel->colF);
1871 /*** options ***/
1872 panel->optF = WMCreateFrame(panel->box);
1873 WMSetFrameRelief(panel->optF, WRFlat);
1875 item = WMCreateTabViewItemWithIdentifier(TAB_OPTIONS);
1876 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1877 WMSetTabViewItemLabel(item, _("Options"));
1879 WMAddItemInTabView(panel->tabv, item);
1881 panel->mstyF = WMCreateFrame(panel->optF);
1882 WMResizeWidget(panel->mstyF, 215, 85);
1883 WMMoveWidget(panel->mstyF, 15, 10);
1884 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1886 for (i = 0; i < 3; i++) {
1887 WMPixmap *icon;
1888 char *path;
1890 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1891 WMResizeWidget(panel->mstyB[i], 54, 54);
1892 WMMoveWidget(panel->mstyB[i], 15 + i * 65, 20);
1893 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1894 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1895 switch (i) {
1896 case 0:
1897 path = LocateImage(MSTYLE1_FILE);
1898 break;
1899 case 1:
1900 path = LocateImage(MSTYLE2_FILE);
1901 break;
1902 case 2:
1903 path = LocateImage(MSTYLE3_FILE);
1904 break;
1906 if (path) {
1907 icon = WMCreatePixmapFromFile(scr, path);
1908 if (icon) {
1909 WMSetButtonImage(panel->mstyB[i], icon);
1910 WMReleasePixmap(icon);
1911 } else {
1912 wwarning(_("could not load icon file %s"), path);
1914 wfree(path);
1917 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
1918 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
1920 WMMapSubwidgets(panel->mstyF);
1922 panel->taliF = WMCreateFrame(panel->optF);
1923 WMResizeWidget(panel->taliF, 110, 80);
1924 WMMoveWidget(panel->taliF, 15, 100);
1925 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
1927 for (i = 0; i < 3; i++) {
1928 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
1929 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
1930 switch (i) {
1931 case 0:
1932 WMSetButtonText(panel->taliB[i], _("Left"));
1933 break;
1934 case 1:
1935 WMSetButtonText(panel->taliB[i], _("Center"));
1936 break;
1937 case 2:
1938 WMSetButtonText(panel->taliB[i], _("Right"));
1939 break;
1941 WMResizeWidget(panel->taliB[i], 90, 18);
1942 WMMoveWidget(panel->taliB[i], 10, 15 + 20 * i);
1944 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
1945 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
1947 WMMapSubwidgets(panel->taliF);
1949 WMMapSubwidgets(panel->optF);
1951 /**/ WMRealizeWidget(panel->box);
1952 WMMapSubwidgets(panel->box);
1954 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1956 showData(panel);
1958 changePage(panel->secP, panel);
1960 fillTextureList(panel->texLs);
1962 fillColorList(panel);
1964 panel->texturePanel = CreateTexturePanel(panel->parent);
1967 static void setupTextureFor(WMList *list, const char *key, const char *defValue, const char *title, int index)
1969 WMListItem *item;
1970 TextureListItem *titem;
1972 titem = wmalloc(sizeof(TextureListItem));
1974 titem->title = wstrdup(title);
1975 titem->prop = GetObjectForKey(key);
1976 if (!titem->prop || !WMIsPLArray(titem->prop)) {
1977 /* Maybe also give a error message to stderr that the entry is bad? */
1978 titem->prop = WMCreatePropListFromDescription(defValue);
1979 } else {
1980 WMRetainPropList(titem->prop);
1982 titem->texture = WMGetPropListDescription((WMPropList *) titem->prop, False);
1983 titem->current = 1;
1984 titem->selectedFor = 1 << index;
1986 titem->ispixmap = isPixmap(titem->prop);
1988 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1990 item = WMAddListItem(list, "");
1991 item->clientData = titem;
1994 static void showData(_Panel * panel)
1996 int i;
1997 const char *str;
1999 str = GetStringForKey("MenuStyle");
2000 if (str && strcasecmp(str, "flat") == 0) {
2001 panel->menuStyle = MSTYLE_FLAT;
2002 } else if (str && strcasecmp(str, "singletexture") == 0) {
2003 panel->menuStyle = MSTYLE_SINGLE;
2004 } else {
2005 panel->menuStyle = MSTYLE_NORMAL;
2008 str = GetStringForKey("TitleJustify");
2009 if (str && strcasecmp(str, "left") == 0) {
2010 panel->titleAlignment = WALeft;
2011 } else if (str && strcasecmp(str, "right") == 0) {
2012 panel->titleAlignment = WARight;
2013 } else {
2014 panel->titleAlignment = WACenter;
2017 for (i = 0; i < wlengthof(colorOptions); i++) {
2018 WMColor *color;
2020 str = GetStringForKey(colorOptions[i].key);
2021 if (!str)
2022 str = colorOptions[i].default_value;
2024 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->box), str, False))) {
2025 color = WMCreateNamedColor(WMWidgetScreen(panel->box), "#000000", False);
2028 panel->colors[i] = color;
2030 changeColorPage(panel->colP, panel);
2032 for (i = 0; i < wlengthof(textureOptions); i++) {
2033 setupTextureFor(panel->texLs, textureOptions[i].key,
2034 textureOptions[i].default_value, _(textureOptions[i].label), i);
2035 panel->textureIndex[i] = i;
2037 updatePreviewBox(panel, EVERYTHING);
2039 WMSetButtonSelected(panel->mstyB[panel->menuStyle], True);
2040 WMSetButtonSelected(panel->taliB[panel->titleAlignment], True);
2043 static void storeData(_Panel * panel)
2045 TextureListItem *titem;
2046 WMListItem *item;
2047 int i;
2049 for (i = 0; i < wlengthof(textureOptions); i++) {
2050 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2051 titem = (TextureListItem *) item->clientData;
2052 SetObjectForKey(titem->prop, textureOptions[i].key);
2055 for (i = 0; i < wlengthof(colorOptions); i++) {
2056 char *str;
2058 str = WMGetColorRGBDescription(panel->colors[i]);
2060 if (str) {
2061 SetStringForKey(str, colorOptions[i].key);
2062 wfree(str);
2066 switch (panel->menuStyle) {
2067 case MSTYLE_SINGLE:
2068 SetStringForKey("singletexture", "MenuStyle");
2069 break;
2070 case MSTYLE_FLAT:
2071 SetStringForKey("flat", "MenuStyle");
2072 break;
2073 default:
2074 case MSTYLE_NORMAL:
2075 SetStringForKey("normal", "MenuStyle");
2076 break;
2078 switch (panel->titleAlignment) {
2079 case WALeft:
2080 SetStringForKey("left", "TitleJustify");
2081 break;
2082 case WARight:
2083 SetStringForKey("right", "TitleJustify");
2084 break;
2085 default:
2086 case WACenter:
2087 SetStringForKey("center", "TitleJustify");
2088 break;
2092 static void prepareForClose(_Panel * panel)
2094 WMPropList *textureList;
2095 WMPropList *texture;
2096 TextureListItem *titem;
2097 WMListItem *item;
2098 WMUserDefaults *udb = WMGetStandardUserDefaults();
2099 int i;
2101 textureList = WMCreatePLArray(NULL, NULL);
2103 /* store list of textures */
2104 for (i = 8; i < WMGetListNumberOfRows(panel->texLs); i++) {
2105 item = WMGetListItem(panel->texLs, i);
2106 titem = (TextureListItem *) item->clientData;
2108 texture = WMCreatePLArray(WMCreatePLString(titem->title),
2109 WMRetainPropList(titem->prop), WMCreatePLString(titem->path), NULL);
2111 WMAddToPLArray(textureList, texture);
2114 WMSetUDObjectForKey(udb, textureList, "TextureList");
2115 WMReleasePropList(textureList);
2117 /* store list of colors */
2118 textureList = WMCreatePLArray(NULL, NULL);
2119 for (i = 0; i < 24; i++) {
2120 WMColor *color;
2121 char *str;
2123 color = WMGetColorWellColor(panel->sampW[i]);
2125 str = WMGetColorRGBDescription(color);
2126 WMAddToPLArray(textureList, WMCreatePLString(str));
2127 wfree(str);
2129 WMSetUDObjectForKey(udb, textureList, "ColorList");
2130 WMReleasePropList(textureList);
2132 WMSynchronizeUserDefaults(udb);
2135 Panel *InitAppearance(WMWidget *parent)
2137 _Panel *panel;
2139 panel = wmalloc(sizeof(_Panel));
2141 panel->sectionName = _("Appearance Preferences");
2143 panel->description = _("Background texture configuration for windows,\n" "menus and icons.");
2145 panel->parent = parent;
2147 panel->callbacks.createWidgets = createPanel;
2148 panel->callbacks.updateDomain = storeData;
2149 panel->callbacks.prepareForClose = prepareForClose;
2151 AddSection(panel, ICON_FILE);
2153 return panel;
2156 /****************************************************************************/
2158 typedef struct ExtractPanel {
2159 WMWindow *win;
2161 WMLabel *label;
2162 WMList *list;
2164 WMButton *closeB;
2165 WMButton *extrB;
2166 } ExtractPanel;
2168 static void OpenExtractPanelFor(_Panel *panel)
2170 ExtractPanel *epanel;
2171 WMColor *color;
2172 WMFont *font;
2173 WMScreen *scr = WMWidgetScreen(panel->parent);
2175 epanel = wmalloc(sizeof(ExtractPanel));
2176 epanel->win = WMCreatePanelWithStyleForWindow(panel->parent, "extract",
2177 WMTitledWindowMask | WMClosableWindowMask);
2178 WMResizeWidget(epanel->win, 245, 250);
2179 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2181 epanel->label = WMCreateLabel(epanel->win);
2182 WMResizeWidget(epanel->label, 225, 18);
2183 WMMoveWidget(epanel->label, 10, 10);
2184 WMSetLabelTextAlignment(epanel->label, WACenter);
2185 WMSetLabelRelief(epanel->label, WRSunken);
2187 color = WMDarkGrayColor(scr);
2188 WMSetWidgetBackgroundColor(epanel->label, color);
2189 WMReleaseColor(color);
2191 color = WMWhiteColor(scr);
2192 WMSetLabelTextColor(epanel->label, color);
2193 WMReleaseColor(color);
2195 font = WMBoldSystemFontOfSize(scr, 12);
2196 WMSetLabelFont(epanel->label, font);
2197 WMReleaseFont(font);
2199 WMSetLabelText(epanel->label, _("Textures"));
2201 epanel->list = WMCreateList(epanel->win);
2202 WMResizeWidget(epanel->list, 225, 165);
2203 WMMoveWidget(epanel->list, 10, 30);
2205 epanel->closeB = WMCreateCommandButton(epanel->win);
2206 WMResizeWidget(epanel->closeB, 74, 24);
2207 WMMoveWidget(epanel->closeB, 165, 215);
2208 WMSetButtonText(epanel->closeB, _("Close"));
2210 epanel->extrB = WMCreateCommandButton(epanel->win);
2211 WMResizeWidget(epanel->extrB, 74, 24);
2212 WMMoveWidget(epanel->extrB, 80, 215);
2213 WMSetButtonText(epanel->extrB, _("Extract"));
2215 WMMapSubwidgets(epanel->win);
2217 /* take textures from file */
2219 WMRealizeWidget(epanel->win);
2221 WMMapWidget(epanel->win);