WPrefs: fix memory leak in loadRImage (Coverity #50107)
[wmaker-crm.git] / WPrefs.app / Appearance.c
blob0535495251190e8f8027fe1d34153564180450fe
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 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 case 'D':
571 style = RDiagonalGradient;
572 break;
575 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
576 str2rcolor(rc, str, &rcolor);
577 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
578 str2rcolor(rc, str, &rcolor2);
580 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
581 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T') {
582 int style;
583 RColor rcolor2;
584 int i;
585 RImage *grad = NULL;
587 switch (toupper(type[1])) {
588 case 'V':
589 style = RVerticalGradient;
590 break;
591 case 'H':
592 style = RHorizontalGradient;
593 break;
594 default:
595 case 'D':
596 style = RDiagonalGradient;
597 break;
600 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
601 str2rcolor(rc, str, &rcolor);
602 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
603 str2rcolor(rc, str, &rcolor2);
605 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
607 image = RMakeTiledImage(timage, width, height);
608 RReleaseImage(timage);
610 i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
612 RCombineImagesWithOpaqueness(image, grad, i);
613 RReleaseImage(grad);
615 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'M') {
616 int style;
617 RColor **colors;
618 int i, j;
620 switch (toupper(type[1])) {
621 case 'V':
622 style = RVerticalGradient;
623 break;
624 case 'H':
625 style = RHorizontalGradient;
626 break;
627 default:
628 case 'D':
629 style = RDiagonalGradient;
630 break;
633 j = WMGetPropListItemCount(texture);
635 if (j > 0) {
636 colors = wmalloc(j * sizeof(RColor *));
638 for (i = 2; i < j; i++) {
639 str = WMGetFromPLString(WMGetFromPLArray(texture, i));
640 colors[i - 2] = wmalloc(sizeof(RColor));
641 str2rcolor(rc, str, colors[i - 2]);
643 colors[i - 2] = NULL;
645 image = RRenderMultiGradient(width, height, colors, style);
647 for (i = 0; colors[i] != NULL; i++)
648 wfree(colors[i]);
649 wfree(colors);
651 } else if (strcasecmp(&type[1], "pixmap") == 0) {
652 RColor color;
654 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
655 str2rcolor(rc, str, &color);
657 switch (toupper(type[0])) {
658 case 'T':
659 image = RMakeTiledImage(timage, width, height);
660 RReleaseImage(timage);
661 break;
662 case 'C':
663 image = RMakeCenteredImage(timage, width, height, &color);
664 RReleaseImage(timage);
665 break;
666 case 'F':
667 case 'S':
668 case 'M':
669 image = RScaleImage(timage, width, height);
670 RReleaseImage(timage);
671 break;
675 if (!image)
676 return None;
678 if (path) {
679 dumpRImage(path, image);
682 if (border < 0) {
683 if (border == RESIZEBAR_BEVEL) {
684 drawResizebarBevel(image);
685 } else if (border == MENU_BEVEL) {
686 drawMenuBevel(image);
687 RBevelImage(image, RBEV_RAISED2);
689 } else if (border) {
690 RBevelImage(image, border);
693 RConvertImage(rc, image, &pixmap);
694 RReleaseImage(image);
696 return pixmap;
699 static Pixmap renderMenu(_Panel * panel, WMPropList * texture, int width, int iheight)
701 WMScreen *scr = WMWidgetScreen(panel->parent);
702 Display *dpy = WMScreenDisplay(scr);
703 Pixmap pix, tmp;
704 GC gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
705 int i;
707 switch (panel->menuStyle) {
708 case MSTYLE_NORMAL:
709 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
711 pix = XCreatePixmap(dpy, tmp, width, iheight * 4, WMScreenDepth(scr));
712 for (i = 0; i < 4; i++) {
713 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight * i);
715 XFreePixmap(dpy, tmp);
716 break;
717 case MSTYLE_SINGLE:
718 pix = renderTexture(scr, texture, width, iheight * 4, NULL, MENU_BEVEL);
719 break;
720 case MSTYLE_FLAT:
721 pix = renderTexture(scr, texture, width, iheight * 4, NULL, RBEV_RAISED2);
722 break;
723 default:
724 pix = None;
726 XFreeGC(dpy, gc);
728 return pix;
731 static void renderPreview(_Panel * panel, GC gc, int part, int relief)
733 WMListItem *item;
734 TextureListItem *titem;
735 Pixmap pix;
736 WMScreen *scr = WMWidgetScreen(panel->box);
738 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
739 titem = (TextureListItem *) item->clientData;
741 pix = renderTexture(scr, titem->prop,
742 previewPositions[part].size.width, previewPositions[part].size.height, NULL, relief);
744 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
745 previewPositions[part].size.width,
746 previewPositions[part].size.height, previewPositions[part].pos.x, previewPositions[part].pos.y);
748 XCopyArea(WMScreenDisplay(scr), pix, panel->previewNoText, gc, 0, 0,
749 previewPositions[part].size.width,
750 previewPositions[part].size.height, previewPositions[part].pos.x, previewPositions[part].pos.y);
752 XFreePixmap(WMScreenDisplay(scr), pix);
755 static void updatePreviewBox(_Panel * panel, int elements)
757 WMScreen *scr = WMWidgetScreen(panel->parent);
758 Display *dpy = WMScreenDisplay(scr);
759 Pixmap pix;
760 GC gc;
761 int colorUpdate = 0;
763 gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
765 if (panel->preview == None) {
766 WMPixmap *p;
768 panel->previewNoText = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
769 240 - 4, 215 - 4, WMScreenDepth(scr));
770 panel->previewBack = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
771 240 - 4, 215 - 4, WMScreenDepth(scr));
773 p = WMCreatePixmap(scr, 240 - 4, 215 - 4, WMScreenDepth(scr), False);
774 panel->preview = WMGetPixmapXID(p);
775 WMSetLabelImage(panel->prevL, p);
776 WMReleasePixmap(p);
778 if (elements & (1 << PBACKGROUND)) {
779 Pixmap tmp;
780 TextureListItem *titem;
781 WMListItem *item;
783 item = WMGetListItem(panel->texLs,
784 panel->textureIndex[PBACKGROUND]);
785 titem = (TextureListItem *) item->clientData;
786 tmp = renderTexture(scr, titem->prop, 240 - 4, 215 - 4, NULL, 0);
788 XCopyArea(dpy, tmp, panel->preview, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
789 XCopyArea(dpy, tmp, panel->previewNoText, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
790 XCopyArea(dpy, tmp, panel->previewBack, gc, 0, 0, 240 - 4, 215 -4 , 0, 0);
791 XFreePixmap(dpy, tmp);
794 if (elements & (1 << PFOCUSED)) {
795 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
796 colorUpdate |= 1 << FTITLE_COL | 1 << FFBORDER_COL;
798 if (elements & (1 << PUNFOCUSED)) {
799 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
800 colorUpdate |= 1 << UTITLE_COL | 1 << FBORDER_COL;
802 if (elements & (1 << POWNER)) {
803 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
804 colorUpdate |= 1 << OTITLE_COL | 1 << FBORDER_COL;
806 if (elements & (1 << PRESIZEBAR)) {
807 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
808 colorUpdate |= 1 << FBORDER_COL;
810 if (elements & (1 << PMTITLE)) {
811 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
812 colorUpdate |= 1 << MTITLE_COL | 1 << FBORDER_COL;
814 if (elements & (1 << PMITEM)) {
815 WMListItem *item;
816 TextureListItem *titem;
818 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
819 titem = (TextureListItem *) item->clientData;
821 pix = renderMenu(panel, titem->prop,
822 previewPositions[PMITEM].size.width, previewPositions[PMITEM].size.height / 4);
824 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
825 previewPositions[PMITEM].size.width,
826 previewPositions[PMITEM].size.height,
827 previewPositions[PMITEM].pos.x, previewPositions[PMITEM].pos.y);
829 XCopyArea(dpy, pix, panel->previewNoText, gc, 0, 0,
830 previewPositions[PMITEM].size.width,
831 previewPositions[PMITEM].size.height,
832 previewPositions[PMITEM].pos.x, previewPositions[PMITEM].pos.y);
834 XFreePixmap(dpy, pix);
836 colorUpdate |= 1 << MITEM_COL | 1 << MDISAB_COL |
837 1 << MHIGH_COL | 1 << MHIGHT_COL |
838 1 << FBORDER_COL;
840 if (elements & (1 << PICON)) {
841 WMListItem *item;
842 TextureListItem *titem;
844 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
845 titem = (TextureListItem *) item->clientData;
847 renderPreview(panel, gc, PICON, titem->ispixmap ? 0 : RBEV_RAISED3);
849 colorUpdate |= 1 << ICONT_COL | 1 << ICONB_COL |
850 1 << CLIP_COL | 1 << CCLIP_COL;
853 if (colorUpdate)
854 updateColorPreviewBox(panel, colorUpdate);
855 else
856 WMRedisplayWidget(panel->prevL);
858 XFreeGC(dpy, gc);
861 static void cancelNewTexture(void *data)
863 _Panel *panel = (_Panel *) data;
865 HideTexturePanel(panel->texturePanel);
868 static char *makeFileName(const char *prefix)
870 char *fname;
872 fname = wstrdup(prefix);
874 while (access(fname, F_OK) == 0) {
875 char buf[30];
877 wfree(fname);
878 sprintf(buf, "%08lx.cache", time(NULL));
879 fname = wstrconcat(prefix, buf);
882 return fname;
885 static void okNewTexture(void *data)
887 _Panel *panel = (_Panel *) data;
888 WMListItem *item;
889 char *name;
890 char *str;
891 WMPropList *prop;
892 TextureListItem *titem;
893 WMScreen *scr = WMWidgetScreen(panel->parent);
895 titem = wmalloc(sizeof(TextureListItem));
897 HideTexturePanel(panel->texturePanel);
899 name = GetTexturePanelTextureName(panel->texturePanel);
901 prop = GetTexturePanelTexture(panel->texturePanel);
903 str = WMGetPropListDescription(prop, False);
905 titem->title = name;
906 titem->prop = prop;
907 titem->texture = str;
908 titem->selectedFor = 0;
910 titem->ispixmap = isPixmap(prop);
912 titem->path = makeFileName(panel->fprefix);
913 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
915 item = WMAddListItem(panel->texLs, "");
916 item->clientData = titem;
918 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
921 static void okEditTexture(void *data)
923 _Panel *panel = (_Panel *) data;
924 WMListItem *item;
925 char *name;
926 char *str;
927 WMPropList *prop;
928 TextureListItem *titem;
930 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
931 titem = (TextureListItem *) item->clientData;
933 HideTexturePanel(panel->texturePanel);
935 if (titem->current) {
936 name = GetTexturePanelTextureName(panel->texturePanel);
938 wfree(titem->title);
939 titem->title = name;
942 prop = GetTexturePanelTexture(panel->texturePanel);
944 str = WMGetPropListDescription(prop, False);
946 WMReleasePropList(titem->prop);
947 titem->prop = prop;
949 titem->ispixmap = isPixmap(prop);
951 wfree(titem->texture);
952 titem->texture = str;
954 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
955 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
956 TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
958 WMRedisplayWidget(panel->texLs);
960 if (titem->selectedFor) {
961 if (titem->selectedFor & (1 << PBACKGROUND))
962 updatePreviewBox(panel, EVERYTHING);
963 else
964 updatePreviewBox(panel, titem->selectedFor);
967 changePage(panel->secP, panel);
970 static void editTexture(WMWidget * w, void *data)
972 _Panel *panel = (_Panel *) data;
973 WMListItem *item;
974 TextureListItem *titem;
976 /* Parameter not used, but tell the compiler that it is ok */
977 (void) w;
979 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
980 titem = (TextureListItem *) item->clientData;
982 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
984 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
986 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
987 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
989 ShowTexturePanel(panel->texturePanel);
992 static void newTexture(WMWidget * w, void *data)
994 _Panel *panel = (_Panel *) data;
996 /* Parameter not used, but tell the compiler that it is ok */
997 (void) w;
999 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
1001 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1003 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1005 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1007 ShowTexturePanel(panel->texturePanel);
1010 static void deleteTexture(WMWidget * w, void *data)
1012 _Panel *panel = (_Panel *) data;
1013 WMListItem *item;
1014 TextureListItem *titem;
1015 int row;
1016 int section;
1018 /* Parameter not used, but tell the compiler that it is ok */
1019 (void) w;
1021 section = WMGetPopUpButtonSelectedItem(panel->secP);
1022 row = WMGetListSelectedItemRow(panel->texLs);
1023 item = WMGetListItem(panel->texLs, row);
1024 titem = (TextureListItem *) item->clientData;
1026 if (titem->selectedFor & (1 << section)) {
1027 TextureListItem *titem2;
1029 panel->textureIndex[section] = section;
1030 item = WMGetListItem(panel->texLs, section);
1031 titem2 = (TextureListItem *) item->clientData;
1032 titem2->selectedFor |= 1 << section;
1035 wfree(titem->title);
1036 wfree(titem->texture);
1037 WMReleasePropList(titem->prop);
1038 if (titem->path) {
1039 if (remove(titem->path) < 0 && errno != ENOENT) {
1040 werror("could not remove file %s", titem->path);
1042 wfree(titem->path);
1045 wfree(titem);
1047 WMRemoveListItem(panel->texLs, row);
1048 WMSetButtonEnabled(panel->delB, False);
1051 static void extractTexture(WMWidget * w, void *data)
1053 _Panel *panel = (_Panel *) data;
1054 char *path;
1055 WMOpenPanel *opanel;
1056 WMScreen *scr = WMWidgetScreen(w);
1058 opanel = WMGetOpenPanel(scr);
1059 WMSetFilePanelCanChooseDirectories(opanel, False);
1060 WMSetFilePanelCanChooseFiles(opanel, True);
1062 if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(), _("Select File"), NULL)) {
1063 path = WMGetFilePanelFileName(opanel);
1065 OpenExtractPanelFor(panel);
1067 wfree(path);
1071 static void changePage(WMWidget * w, void *data)
1073 _Panel *panel = (_Panel *) data;
1074 int section;
1075 WMScreen *scr = WMWidgetScreen(panel->box);
1076 RContext *rc = WMScreenRContext(scr);
1077 static WMPoint positions[] = {
1078 {5, 10},
1079 {5, 40},
1080 {5, 70},
1081 {5, 100},
1082 {5, 120},
1083 {5, 160},
1084 {130, 150}
1087 if (w) {
1088 section = WMGetPopUpButtonSelectedItem(panel->secP);
1090 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1092 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1095 GC gc;
1097 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1098 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1099 positions[panel->oldsection].x,
1100 positions[panel->oldsection].y, 22, 22 ,
1101 positions[panel->oldsection].x,
1102 positions[panel->oldsection].y);
1104 if (w) {
1105 panel->oldsection = section;
1106 WMDrawPixmap(panel->hand, panel->preview, positions[section].x, positions[section].y);
1108 WMRedisplayWidget(panel->prevL);
1111 static void previewClick(XEvent * event, void *clientData)
1113 _Panel *panel = (_Panel *) clientData;
1114 int i;
1116 switch (panel->oldTabItem) {
1117 case 0:
1118 for (i = 0; i < wlengthof(previewPositions); i++) {
1119 if (event->xbutton.x >= previewPositions[i].pos.x
1120 && event->xbutton.y >= previewPositions[i].pos.y
1121 && event->xbutton.x < previewPositions[i].pos.x
1122 + previewPositions[i].size.width
1123 && event->xbutton.y < previewPositions[i].pos.y + previewPositions[i].size.height) {
1125 WMSetPopUpButtonSelectedItem(panel->secP, i);
1126 changePage(panel->secP, panel);
1127 return;
1130 break;
1131 case 1:
1132 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1133 if (event->xbutton.x >= previewColorPositions[i].pos.x
1134 && event->xbutton.y >= previewColorPositions[i].pos.y
1135 && event->xbutton.x < previewColorPositions[i].pos.x
1136 + previewColorPositions[i].size.width
1137 && event->xbutton.y < previewColorPositions[i].pos.y
1138 + previewColorPositions[i].size.height) {
1140 /* yuck kluge */
1141 if (i == 7)
1142 i = 4;
1144 WMSetPopUpButtonSelectedItem(panel->colP, i);
1145 changeColorPage(panel->colP, panel);
1146 return;
1149 break;
1153 static void textureClick(WMWidget * w, void *data)
1155 _Panel *panel = (_Panel *) data;
1156 int i;
1157 WMListItem *item;
1158 TextureListItem *titem;
1160 /* Parameter not used, but tell the compiler that it is ok */
1161 (void) w;
1163 i = WMGetListSelectedItemRow(panel->texLs);
1165 item = WMGetListItem(panel->texLs, i);
1167 titem = (TextureListItem *) item->clientData;
1169 if (titem->current) {
1170 WMSetButtonEnabled(panel->delB, False);
1171 } else {
1172 WMSetButtonEnabled(panel->delB, True);
1176 static void textureDoubleClick(WMWidget * w, void *data)
1178 _Panel *panel = (_Panel *) data;
1179 int i, section;
1180 WMListItem *item;
1181 TextureListItem *titem;
1183 /* Parameter not used, but tell the compiler that it is ok */
1184 (void) w;
1186 /* unselect old texture */
1187 section = WMGetPopUpButtonSelectedItem(panel->secP);
1189 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1190 titem = (TextureListItem *) item->clientData;
1191 titem->selectedFor &= ~(1 << section);
1193 /* select new texture */
1194 i = WMGetListSelectedItemRow(panel->texLs);
1196 item = WMGetListItem(panel->texLs, i);
1198 titem = (TextureListItem *) item->clientData;
1200 titem->selectedFor |= 1 << section;
1202 panel->textureIndex[section] = i;
1204 WMRedisplayWidget(panel->texLs);
1206 if (section == PBACKGROUND)
1207 updatePreviewBox(panel, EVERYTHING);
1208 else
1209 updatePreviewBox(panel, 1 << section);
1212 static void paintListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
1214 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
1215 WMScreen *scr = WMWidgetScreen(lPtr);
1216 int width, height, x, y;
1217 Display *dpy = WMScreenDisplay(scr);
1218 WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
1219 WMListItem *item;
1220 WMColor *black = WMBlackColor(scr);
1221 TextureListItem *titem;
1223 /* Parameter not used, but tell the compiler that it is ok */
1224 (void) text;
1226 item = WMGetListItem(lPtr, index);
1227 titem = (TextureListItem *) item->clientData;
1228 if (!titem) {
1229 WMReleaseColor(back);
1230 WMReleaseColor(black);
1231 return;
1234 width = rect->size.width;
1235 height = rect->size.height;
1236 x = rect->pos.x;
1237 y = rect->pos.y;
1239 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
1241 if (titem->preview)
1242 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1243 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1245 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1246 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1247 else if (titem->selectedFor)
1248 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1250 WMDrawString(scr, d, black, panel->boldFont,
1251 x + TEXPREV_WIDTH + 22, y + 2, titem->title, strlen(titem->title));
1253 WMDrawString(scr, d, black, panel->smallFont,
1254 x + TEXPREV_WIDTH + 14, y + 18, titem->texture, strlen(titem->texture));
1256 WMReleaseColor(back);
1257 WMReleaseColor(black);
1260 static Pixmap loadRImage(WMScreen * scr, const char *path)
1262 FILE *f;
1263 RImage *image;
1264 int w, h, d, cnt;
1265 size_t read_size;
1266 Pixmap pixmap;
1268 f = fopen(path, "rb");
1269 if (!f)
1270 return None;
1272 cnt = fscanf(f, "%02x%02x%1x", &w, &h, &d);
1273 if (cnt != 3) {
1274 fclose(f);
1275 return None;
1277 image = RCreateImage(w, h, d == 4);
1278 read_size = w * h * d;
1279 if (fread(image->data, 1, read_size, f) == read_size)
1280 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1281 else
1282 pixmap = None;
1284 fclose(f);
1286 RReleaseImage(image);
1288 return pixmap;
1291 static void fillTextureList(WMList * lPtr)
1293 WMPropList *textureList;
1294 WMPropList *texture;
1295 WMUserDefaults *udb = WMGetStandardUserDefaults();
1296 TextureListItem *titem;
1297 WMScreen *scr = WMWidgetScreen(lPtr);
1298 int i;
1300 textureList = WMGetUDObjectForKey(udb, "TextureList");
1301 if (!textureList)
1302 return;
1304 for (i = 0; i < WMGetPropListItemCount(textureList); i++) {
1305 WMListItem *item;
1307 texture = WMGetFromPLArray(textureList, i);
1309 titem = wmalloc(sizeof(TextureListItem));
1311 titem->title = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 0)));
1312 titem->prop = WMRetainPropList(WMGetFromPLArray(texture, 1));
1313 titem->texture = WMGetPropListDescription(titem->prop, False);
1314 titem->selectedFor = 0;
1315 titem->path = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
1317 titem->preview = loadRImage(scr, titem->path);
1318 if (!titem->preview) {
1319 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1321 item = WMAddListItem(lPtr, "");
1322 item->clientData = titem;
1326 static void fillColorList(_Panel * panel)
1328 WMColor *color;
1329 WMPropList *list;
1330 WMUserDefaults *udb = WMGetStandardUserDefaults();
1331 WMScreen *scr = WMWidgetScreen(panel->box);
1332 int i;
1334 list = WMGetUDObjectForKey(udb, "ColorList");
1335 if (!list) {
1336 for (i = 0; i < 24; i++) {
1337 color = WMCreateNamedColor(scr, sampleColors[i], False);
1338 if (!color)
1339 continue;
1340 WMSetColorWellColor(panel->sampW[i], color);
1341 WMReleaseColor(color);
1343 } else {
1344 WMPropList *c;
1346 for (i = 0; i < WMIN(24, WMGetPropListItemCount(list)); i++) {
1347 c = WMGetFromPLArray(list, i);
1348 if (!c || !WMIsPLString(c))
1349 continue;
1350 color = WMCreateNamedColor(scr, WMGetFromPLString(c), False);
1351 if (!color)
1352 continue;
1353 WMSetColorWellColor(panel->sampW[i], color);
1354 WMReleaseColor(color);
1359 /*************************************************************************/
1361 static void changeColorPage(WMWidget * w, void *data)
1363 _Panel *panel = (_Panel *) data;
1364 int section;
1365 WMScreen *scr = WMWidgetScreen(panel->box);
1366 RContext *rc = WMScreenRContext(scr);
1367 static WMPoint positions[] = {
1368 {5, 10},
1369 {5, 40},
1370 {5, 70},
1371 {5, 120},
1372 {5, 140},
1373 {5, 160},
1374 {5, 180},
1375 {5, 180},
1376 {-22, -21},
1377 {-22, -21},
1378 {-22, -21},
1379 {130, 140},
1380 {130, 140},
1381 {130, 140},
1382 {130, 140}
1385 if (panel->preview) {
1386 GC gc;
1388 gc = XCreateGC(rc->dpy, WMWidgetXID(panel->parent), 0, NULL);
1389 XCopyArea(rc->dpy, panel->previewBack, panel->preview, gc,
1390 positions[panel->oldcsection].x,
1391 positions[panel->oldcsection].y, 22, 22 ,
1392 positions[panel->oldcsection].x,
1393 positions[panel->oldcsection].y);
1395 if (w) {
1396 section = WMGetPopUpButtonSelectedItem(panel->colP);
1398 panel->oldcsection = section;
1399 if (panel->preview)
1400 WMDrawPixmap(panel->hand, panel->preview, positions[section].x, positions[section].y);
1402 section = WMGetPopUpButtonSelectedItem(panel->colP);
1404 WMSetColorWellColor(panel->colW, panel->colors[section]);
1406 WMRedisplayWidget(panel->prevL);
1409 static void
1410 paintText(WMScreen * scr, Drawable d, WMColor * color, WMFont * font,
1411 int x, int y, int w, int h, WMAlignment align, char *text)
1413 int l = strlen(text);
1415 switch (align) {
1416 case WALeft:
1417 x += 5;
1418 break;
1419 case WARight:
1420 x += w - 5 - WMWidthOfString(font, text, l);
1421 break;
1422 default:
1423 case WACenter:
1424 x += (w - WMWidthOfString(font, text, l)) / 2;
1425 break;
1427 WMDrawString(scr, d, color, font, x, y + (h - WMFontHeight(font)) / 2, text, l);
1430 static void updateColorPreviewBox(_Panel * panel, int elements)
1432 WMScreen *scr = WMWidgetScreen(panel->box);
1433 Display *dpy = WMScreenDisplay(scr);
1434 Pixmap d, pnot;
1435 GC gc;
1437 d = panel->preview;
1438 pnot = panel->previewNoText;
1439 gc = WMColorGC(panel->colors[FTITLE_COL]);
1441 if (elements & (1 << FTITLE_COL)) {
1442 XCopyArea(dpy, pnot, d, gc, 30, 10, 190, 20, 30, 10);
1443 paintText(scr, d, panel->colors[FTITLE_COL],
1444 panel->boldFont, 30, 10, 190, 20,
1445 panel->titleAlignment, _("Focused Window"));
1447 if (elements & (1 << UTITLE_COL)) {
1448 XCopyArea(dpy, pnot, d, gc, 30, 40, 190, 20, 30, 40);
1449 paintText(scr, d, panel->colors[UTITLE_COL],
1450 panel->boldFont, 30, 40, 190, 20,
1451 panel->titleAlignment,
1452 _("Unfocused Window"));
1454 if (elements & (1 << OTITLE_COL)) {
1455 XCopyArea(dpy, pnot, d, gc, 30, 70, 190, 20, 30, 70);
1456 paintText(scr, d, panel->colors[OTITLE_COL],
1457 panel->boldFont, 30, 70, 190, 20,
1458 panel->titleAlignment,
1459 _("Owner of Focused Window"));
1461 if (elements & (1 << MTITLE_COL)) {
1462 XCopyArea(dpy, pnot, d, gc, 30, 120, 90, 20, 30, 120);
1463 paintText(scr, d, panel->colors[MTITLE_COL],
1464 panel->boldFont, 30, 120, 90, 20, WALeft,
1465 _("Menu Title"));
1467 if (elements & (1 << MITEM_COL)) {
1468 XCopyArea(dpy, pnot, d, gc, 30, 140, 90, 20, 30, 140);
1469 paintText(scr, d, panel->colors[MITEM_COL],
1470 panel->normalFont, 30, 140, 90, 20, WALeft,
1471 _("Normal Item"));
1472 XCopyArea(dpy, pnot, d, gc, 30, 200, 90, 20, 30, 200);
1473 paintText(scr, d, panel->colors[MITEM_COL],
1474 panel->normalFont, 30, 200, 90, 20, WALeft,
1475 _("Normal Item"));
1477 if (elements & (1 << MDISAB_COL)) {
1478 XCopyArea(dpy, pnot, d, gc, 30, 160, 90, 20, 30, 160);
1479 paintText(scr, d, panel->colors[MDISAB_COL],
1480 panel->normalFont, 30, 160, 90, 20, WALeft,
1481 _("Disabled Item"));
1483 if (elements & (1 << MHIGH_COL)) {
1484 XFillRectangle(WMScreenDisplay(scr), d,
1485 WMColorGC(panel->colors[MHIGH_COL]),
1486 31, 181, 87, 17);
1487 XFillRectangle(WMScreenDisplay(scr), pnot,
1488 WMColorGC(panel->colors[MHIGH_COL]),
1489 31, 181, 87, 17);
1490 elements |= 1 << MHIGHT_COL;
1492 if (elements & (1 << MHIGHT_COL)) {
1493 XCopyArea(dpy, pnot, d, gc, 30, 180, 90, 20, 30, 180);
1494 paintText(scr, d, panel->colors[MHIGHT_COL],
1495 panel->normalFont, 30, 180, 90, 20, WALeft,
1496 _("Highlighted"));
1498 if (elements & (1 << FBORDER_COL)) {
1499 XDrawRectangle(dpy, pnot,
1500 WMColorGC(panel->colors[FBORDER_COL]),
1501 29, 39, 190, 20);
1502 XDrawRectangle(dpy, d,
1503 WMColorGC(panel->colors[FBORDER_COL]),
1504 29, 39, 190, 20);
1505 XDrawRectangle(dpy, pnot,
1506 WMColorGC(panel->colors[FBORDER_COL]),
1507 29, 69, 190, 20);
1508 XDrawRectangle(dpy, d,
1509 WMColorGC(panel->colors[FBORDER_COL]),
1510 29, 69, 190, 20);
1511 XDrawLine(dpy, pnot,
1512 WMColorGC(panel->colors[FBORDER_COL]),
1513 30, 100, 30, 109);
1514 XDrawLine(dpy, d,
1515 WMColorGC(panel->colors[FBORDER_COL]),
1516 30, 100, 30, 109);
1517 XDrawLine(dpy, pnot,
1518 WMColorGC(panel->colors[FBORDER_COL]),
1519 31, 109, 219, 109);
1520 XDrawLine(dpy, d,
1521 WMColorGC(panel->colors[FBORDER_COL]),
1522 31, 109, 219, 109);
1523 XDrawLine(dpy, pnot,
1524 WMColorGC(panel->colors[FBORDER_COL]),
1525 220, 100, 220, 109);
1526 XDrawLine(dpy, d,
1527 WMColorGC(panel->colors[FBORDER_COL]),
1528 220, 100, 220, 109);
1529 XDrawLine(dpy, pnot,
1530 WMColorGC(panel->colors[FBORDER_COL]),
1531 29, 120, 29, 220);
1532 XDrawLine(dpy, d,
1533 WMColorGC(panel->colors[FBORDER_COL]),
1534 29, 120, 29, 220);
1535 XDrawLine(dpy, pnot,
1536 WMColorGC(panel->colors[FBORDER_COL]),
1537 29, 119, 119, 119);
1538 XDrawLine(dpy, d,
1539 WMColorGC(panel->colors[FBORDER_COL]),
1540 29, 119, 119, 119);
1541 XDrawLine(dpy, pnot,
1542 WMColorGC(panel->colors[FBORDER_COL]),
1543 119, 120, 119, 220);
1544 XDrawLine(dpy, d,
1545 WMColorGC(panel->colors[FBORDER_COL]),
1546 119, 120, 119, 220);
1549 if (elements & (1 << FFBORDER_COL)) {
1550 XDrawRectangle(dpy, pnot,
1551 WMColorGC(panel->colors[FFBORDER_COL]),
1552 29, 9, 190, 20);
1553 XDrawRectangle(dpy, d,
1554 WMColorGC(panel->colors[FFBORDER_COL]),
1555 29, 9, 190, 20);
1559 if (elements & (1 << ICONT_COL)) {
1560 WRITE(_("Focused Window"), panel->colors[ICONT_COL],
1561 panel->boldFont,
1562 155, 130, 64);
1564 if (elements & (1 << ICONB_COL)) {
1565 WRITE(_("Focused Window"), panel->colors[ICONB_COL],
1566 panel->boldFont,
1567 0, 0, 30);
1569 if (elements & (1 << CLIP_COL)) {
1570 WRITE(_("Focused Window"), panel->colors[CLIP_COL],
1571 panel->boldFont,
1572 0, 0, 30);
1574 if (elements & (1 << CCLIP_COL)) {
1575 WRITE(_("Focused Window"), panel->colors[CCLIP_COL],
1576 panel->boldFont,
1577 0, 0, 30);
1580 WMRedisplayWidget(panel->prevL);
1583 static void colorWellObserver(void *self, WMNotification * n)
1585 _Panel *panel = (_Panel *) self;
1586 int p;
1588 /* Parameter not used, but tell the compiler that it is ok */
1589 (void) n;
1591 p = WMGetPopUpButtonSelectedItem(panel->colP);
1593 WMReleaseColor(panel->colors[p]);
1595 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1597 updateColorPreviewBox(panel, 1 << p);
1600 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item)
1602 _Panel *panel = self->data;
1603 int i;
1605 /* Parameter not used, but tell the compiler that it is ok */
1606 (void) tabView;
1608 i = WMGetTabViewItemIdentifier(item);
1609 switch (i) {
1610 case TAB_TEXTURE:
1611 switch (panel->oldTabItem) {
1612 case TAB_COLOR:
1613 changeColorPage(NULL, panel);
1614 break;
1616 changePage(panel->secP, panel);
1617 break;
1618 case TAB_COLOR:
1619 switch (panel->oldTabItem) {
1620 case TAB_TEXTURE:
1621 changePage(NULL, panel);
1622 break;
1624 changeColorPage(panel->colP, panel);
1625 break;
1626 case TAB_OPTIONS:
1627 switch (panel->oldTabItem) {
1628 case TAB_TEXTURE:
1629 changePage(NULL, panel);
1630 break;
1631 case TAB_COLOR:
1632 changeColorPage(NULL, panel);
1633 break;
1635 break;
1638 panel->oldTabItem = i;
1641 /*************************************************************************/
1643 static void menuStyleCallback(WMWidget * self, void *data)
1645 _Panel *panel = (_Panel *) data;
1647 if (self == panel->mstyB[0]) {
1648 panel->menuStyle = MSTYLE_NORMAL;
1649 updatePreviewBox(panel, 1 << PMITEM);
1651 } else if (self == panel->mstyB[1]) {
1652 panel->menuStyle = MSTYLE_SINGLE;
1653 updatePreviewBox(panel, 1 << PMITEM);
1655 } else if (self == panel->mstyB[2]) {
1656 panel->menuStyle = MSTYLE_FLAT;
1657 updatePreviewBox(panel, 1 << PMITEM);
1661 static void titleAlignCallback(WMWidget * self, void *data)
1663 _Panel *panel = (_Panel *) data;
1665 if (self == panel->taliB[0]) {
1666 panel->titleAlignment = WALeft;
1667 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1669 } else if (self == panel->taliB[1]) {
1670 panel->titleAlignment = WACenter;
1671 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1673 } else if (self == panel->taliB[2]) {
1674 panel->titleAlignment = WARight;
1675 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1679 static void createPanel(Panel * p)
1681 _Panel *panel = (_Panel *) p;
1682 WMFont *font;
1683 WMScreen *scr = WMWidgetScreen(panel->parent);
1684 WMTabViewItem *item;
1685 int i;
1686 char *tmp;
1687 Bool ok = True;
1689 panel->fprefix = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1691 if (access(panel->fprefix, F_OK) != 0) {
1692 if (mkdir(panel->fprefix, 0755) < 0) {
1693 werror("%s", panel->fprefix);
1694 ok = False;
1697 if (ok) {
1698 tmp = wstrconcat(panel->fprefix, "/WPrefs/");
1699 wfree(panel->fprefix);
1700 panel->fprefix = tmp;
1701 if (access(panel->fprefix, F_OK) != 0) {
1702 if (mkdir(panel->fprefix, 0755) < 0) {
1703 werror("%s", panel->fprefix);
1708 panel->smallFont = WMSystemFontOfSize(scr, 10);
1709 panel->normalFont = WMSystemFontOfSize(scr, 12);
1710 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1712 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1713 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1714 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1716 panel->box = WMCreateBox(panel->parent);
1717 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1719 /* preview box */
1720 panel->prevL = WMCreateLabel(panel->box);
1721 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1722 WMMoveWidget(panel->prevL, 15, 10);
1723 WMSetLabelRelief(panel->prevL, WRSunken);
1724 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1726 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask, previewClick, panel);
1728 /* tabview */
1730 tabviewDelegate.data = panel;
1732 panel->tabv = WMCreateTabView(panel->box);
1733 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1734 WMMoveWidget(panel->tabv, 265, 10);
1735 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1737 /*** texture list ***/
1739 panel->texF = WMCreateFrame(panel->box);
1740 WMSetFrameRelief(panel->texF, WRFlat);
1742 item = WMCreateTabViewItemWithIdentifier(TAB_TEXTURE);
1743 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1744 WMSetTabViewItemLabel(item, _("Texture"));
1746 WMAddItemInTabView(panel->tabv, item);
1748 panel->secP = WMCreatePopUpButton(panel->texF);
1749 WMResizeWidget(panel->secP, 228, 20);
1750 WMMoveWidget(panel->secP, 7, 7);
1751 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1752 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1753 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1754 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1755 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1756 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1757 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1758 WMAddPopUpButtonItem(panel->secP, _("Workspace Background"));
1760 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1761 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1763 panel->texLs = WMCreateList(panel->texF);
1764 WMResizeWidget(panel->texLs, 165, 155);
1765 WMMoveWidget(panel->texLs, 70, 33);
1766 WMSetListUserDrawItemHeight(panel->texLs, 35);
1767 WMSetListUserDrawProc(panel->texLs, paintListItem);
1768 WMHangData(panel->texLs, panel);
1769 WMSetListAction(panel->texLs, textureClick, panel);
1770 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1772 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1773 "for the selected item."), WMWidgetView(panel->texLs));
1775 /* command buttons */
1777 font = WMSystemFontOfSize(scr, 10);
1779 panel->newB = WMCreateCommandButton(panel->texF);
1780 WMResizeWidget(panel->newB, 57, 39);
1781 WMMoveWidget(panel->newB, 7, 33);
1782 WMSetButtonFont(panel->newB, font);
1783 WMSetButtonImagePosition(panel->newB, WIPAbove);
1784 WMSetButtonText(panel->newB, _("New"));
1785 WMSetButtonAction(panel->newB, newTexture, panel);
1786 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1788 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel->newB));
1790 panel->ripB = WMCreateCommandButton(panel->texF);
1791 WMResizeWidget(panel->ripB, 57, 39);
1792 WMMoveWidget(panel->ripB, 7, 72);
1793 WMSetButtonFont(panel->ripB, font);
1794 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1795 WMSetButtonText(panel->ripB, _("Extract..."));
1796 WMSetButtonAction(panel->ripB, extractTexture, panel);
1797 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1799 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel->ripB));
1801 WMSetButtonEnabled(panel->ripB, False);
1803 panel->editB = WMCreateCommandButton(panel->texF);
1804 WMResizeWidget(panel->editB, 57, 39);
1805 WMMoveWidget(panel->editB, 7, 111);
1806 WMSetButtonFont(panel->editB, font);
1807 WMSetButtonImagePosition(panel->editB, WIPAbove);
1808 WMSetButtonText(panel->editB, _("Edit"));
1809 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1810 WMSetButtonAction(panel->editB, editTexture, panel);
1811 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel->editB));
1813 panel->delB = WMCreateCommandButton(panel->texF);
1814 WMResizeWidget(panel->delB, 57, 38);
1815 WMMoveWidget(panel->delB, 7, 150);
1816 WMSetButtonFont(panel->delB, font);
1817 WMSetButtonImagePosition(panel->delB, WIPAbove);
1818 WMSetButtonText(panel->delB, _("Delete"));
1819 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1820 WMSetButtonEnabled(panel->delB, False);
1821 WMSetButtonAction(panel->delB, deleteTexture, panel);
1822 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel->delB));
1824 WMReleaseFont(font);
1826 WMMapSubwidgets(panel->texF);
1828 /*** colors ***/
1829 panel->colF = WMCreateFrame(panel->box);
1830 WMSetFrameRelief(panel->colF, WRFlat);
1832 item = WMCreateTabViewItemWithIdentifier(TAB_COLOR);
1833 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1834 WMSetTabViewItemLabel(item, _("Color"));
1836 WMAddItemInTabView(panel->tabv, item);
1838 panel->colP = WMCreatePopUpButton(panel->colF);
1839 WMResizeWidget(panel->colP, 228, 20);
1840 WMMoveWidget(panel->colP, 7, 7);
1841 WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1842 WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1843 WMAddPopUpButtonItem(panel->colP, _("Owner of Focused Window Title"));
1844 WMAddPopUpButtonItem(panel->colP, _("Menu Title"));
1845 WMAddPopUpButtonItem(panel->colP, _("Menu Item Text"));
1846 WMAddPopUpButtonItem(panel->colP, _("Disabled Menu Item Text"));
1847 WMAddPopUpButtonItem(panel->colP, _("Menu Highlight Color"));
1848 WMAddPopUpButtonItem(panel->colP, _("Highlighted Menu Text Color"));
1849 WMAddPopUpButtonItem(panel->colP, _("Focused Window Border Color"));
1850 WMAddPopUpButtonItem(panel->colP, _("Window Border Color"));
1851 WMAddPopUpButtonItem(panel->colP, _("Selected Window Border Color"));
1853 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1854 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1855 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1856 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1859 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1861 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1863 panel->colW = WMCreateColorWell(panel->colF);
1864 WMResizeWidget(panel->colW, 65, 50);
1865 WMMoveWidget(panel->colW, 30, 75);
1866 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->colW);
1868 for (i = 0; i < 4; i++) {
1869 int j;
1870 for (j = 0; j < 6; j++) {
1871 panel->sampW[i + j * 4] = WMCreateColorWell(panel->colF);
1872 WMResizeWidget(panel->sampW[i + j * 4], 22, 22);
1873 WMMoveWidget(panel->sampW[i + j * 4], 130 + i * 22, 40 + j * 22);
1874 WSetColorWellBordered(panel->sampW[i + j * 4], False);
1878 WMMapSubwidgets(panel->colF);
1880 /*** options ***/
1881 panel->optF = WMCreateFrame(panel->box);
1882 WMSetFrameRelief(panel->optF, WRFlat);
1884 item = WMCreateTabViewItemWithIdentifier(TAB_OPTIONS);
1885 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1886 WMSetTabViewItemLabel(item, _("Options"));
1888 WMAddItemInTabView(panel->tabv, item);
1890 panel->mstyF = WMCreateFrame(panel->optF);
1891 WMResizeWidget(panel->mstyF, 215, 85);
1892 WMMoveWidget(panel->mstyF, 15, 10);
1893 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1895 for (i = 0; i < 3; i++) {
1896 WMPixmap *icon;
1897 char *path;
1899 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1900 WMResizeWidget(panel->mstyB[i], 54, 54);
1901 WMMoveWidget(panel->mstyB[i], 15 + i * 65, 20);
1902 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1903 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1904 switch (i) {
1905 case 0:
1906 path = LocateImage(MSTYLE1_FILE);
1907 break;
1908 case 1:
1909 path = LocateImage(MSTYLE2_FILE);
1910 break;
1911 case 2:
1912 path = LocateImage(MSTYLE3_FILE);
1913 break;
1915 if (path) {
1916 icon = WMCreatePixmapFromFile(scr, path);
1917 if (icon) {
1918 WMSetButtonImage(panel->mstyB[i], icon);
1919 WMReleasePixmap(icon);
1920 } else {
1921 wwarning(_("could not load icon file %s"), path);
1923 wfree(path);
1926 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
1927 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
1929 WMMapSubwidgets(panel->mstyF);
1931 panel->taliF = WMCreateFrame(panel->optF);
1932 WMResizeWidget(panel->taliF, 110, 80);
1933 WMMoveWidget(panel->taliF, 15, 100);
1934 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
1936 for (i = 0; i < 3; i++) {
1937 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
1938 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
1939 switch (i) {
1940 case 0:
1941 WMSetButtonText(panel->taliB[i], _("Left"));
1942 break;
1943 case 1:
1944 WMSetButtonText(panel->taliB[i], _("Center"));
1945 break;
1946 case 2:
1947 WMSetButtonText(panel->taliB[i], _("Right"));
1948 break;
1950 WMResizeWidget(panel->taliB[i], 90, 18);
1951 WMMoveWidget(panel->taliB[i], 10, 15 + 20 * i);
1953 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
1954 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
1956 WMMapSubwidgets(panel->taliF);
1958 WMMapSubwidgets(panel->optF);
1960 /**/ WMRealizeWidget(panel->box);
1961 WMMapSubwidgets(panel->box);
1963 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1965 showData(panel);
1967 changePage(panel->secP, panel);
1969 fillTextureList(panel->texLs);
1971 fillColorList(panel);
1973 panel->texturePanel = CreateTexturePanel(panel->parent);
1976 static void setupTextureFor(WMList *list, const char *key, const char *defValue, const char *title, int index)
1978 WMListItem *item;
1979 TextureListItem *titem;
1981 titem = wmalloc(sizeof(TextureListItem));
1983 titem->title = wstrdup(title);
1984 titem->prop = GetObjectForKey(key);
1985 if (!titem->prop || !WMIsPLArray(titem->prop)) {
1986 /* Maybe also give a error message to stderr that the entry is bad? */
1987 titem->prop = WMCreatePropListFromDescription(defValue);
1988 } else {
1989 WMRetainPropList(titem->prop);
1991 titem->texture = WMGetPropListDescription((WMPropList *) titem->prop, False);
1992 titem->current = 1;
1993 titem->selectedFor = 1 << index;
1995 titem->ispixmap = isPixmap(titem->prop);
1997 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1999 item = WMAddListItem(list, "");
2000 item->clientData = titem;
2003 static void showData(_Panel * panel)
2005 int i;
2006 const char *str;
2008 str = GetStringForKey("MenuStyle");
2009 if (str && strcasecmp(str, "flat") == 0) {
2010 panel->menuStyle = MSTYLE_FLAT;
2011 } else if (str && strcasecmp(str, "singletexture") == 0) {
2012 panel->menuStyle = MSTYLE_SINGLE;
2013 } else {
2014 panel->menuStyle = MSTYLE_NORMAL;
2017 str = GetStringForKey("TitleJustify");
2018 if (str && strcasecmp(str, "left") == 0) {
2019 panel->titleAlignment = WALeft;
2020 } else if (str && strcasecmp(str, "right") == 0) {
2021 panel->titleAlignment = WARight;
2022 } else {
2023 panel->titleAlignment = WACenter;
2026 for (i = 0; i < wlengthof(colorOptions); i++) {
2027 WMColor *color;
2029 str = GetStringForKey(colorOptions[i].key);
2030 if (!str)
2031 str = colorOptions[i].default_value;
2033 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->box), str, False))) {
2034 color = WMCreateNamedColor(WMWidgetScreen(panel->box), "#000000", False);
2037 panel->colors[i] = color;
2039 changeColorPage(panel->colP, panel);
2041 for (i = 0; i < wlengthof(textureOptions); i++) {
2042 setupTextureFor(panel->texLs, textureOptions[i].key,
2043 textureOptions[i].default_value, _(textureOptions[i].label), i);
2044 panel->textureIndex[i] = i;
2046 updatePreviewBox(panel, EVERYTHING);
2048 WMSetButtonSelected(panel->mstyB[panel->menuStyle], True);
2049 WMSetButtonSelected(panel->taliB[panel->titleAlignment], True);
2052 static void storeData(_Panel * panel)
2054 TextureListItem *titem;
2055 WMListItem *item;
2056 int i;
2058 for (i = 0; i < wlengthof(textureOptions); i++) {
2059 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2060 titem = (TextureListItem *) item->clientData;
2061 SetObjectForKey(titem->prop, textureOptions[i].key);
2064 for (i = 0; i < wlengthof(colorOptions); i++) {
2065 char *str;
2067 str = WMGetColorRGBDescription(panel->colors[i]);
2069 if (str) {
2070 SetStringForKey(str, colorOptions[i].key);
2071 wfree(str);
2075 switch (panel->menuStyle) {
2076 case MSTYLE_SINGLE:
2077 SetStringForKey("singletexture", "MenuStyle");
2078 break;
2079 case MSTYLE_FLAT:
2080 SetStringForKey("flat", "MenuStyle");
2081 break;
2082 default:
2083 case MSTYLE_NORMAL:
2084 SetStringForKey("normal", "MenuStyle");
2085 break;
2087 switch (panel->titleAlignment) {
2088 case WALeft:
2089 SetStringForKey("left", "TitleJustify");
2090 break;
2091 case WARight:
2092 SetStringForKey("right", "TitleJustify");
2093 break;
2094 default:
2095 case WACenter:
2096 SetStringForKey("center", "TitleJustify");
2097 break;
2101 static void prepareForClose(_Panel * panel)
2103 WMPropList *textureList;
2104 WMPropList *texture;
2105 TextureListItem *titem;
2106 WMListItem *item;
2107 WMUserDefaults *udb = WMGetStandardUserDefaults();
2108 int i;
2110 textureList = WMCreatePLArray(NULL, NULL);
2112 /* store list of textures */
2113 for (i = 8; i < WMGetListNumberOfRows(panel->texLs); i++) {
2114 item = WMGetListItem(panel->texLs, i);
2115 titem = (TextureListItem *) item->clientData;
2117 texture = WMCreatePLArray(WMCreatePLString(titem->title),
2118 WMRetainPropList(titem->prop), WMCreatePLString(titem->path), NULL);
2120 WMAddToPLArray(textureList, texture);
2123 WMSetUDObjectForKey(udb, textureList, "TextureList");
2124 WMReleasePropList(textureList);
2126 /* store list of colors */
2127 textureList = WMCreatePLArray(NULL, NULL);
2128 for (i = 0; i < 24; i++) {
2129 WMColor *color;
2130 char *str;
2132 color = WMGetColorWellColor(panel->sampW[i]);
2134 str = WMGetColorRGBDescription(color);
2135 WMAddToPLArray(textureList, WMCreatePLString(str));
2136 wfree(str);
2138 WMSetUDObjectForKey(udb, textureList, "ColorList");
2139 WMReleasePropList(textureList);
2141 WMSynchronizeUserDefaults(udb);
2144 Panel *InitAppearance(WMWidget *parent)
2146 _Panel *panel;
2148 panel = wmalloc(sizeof(_Panel));
2150 panel->sectionName = _("Appearance Preferences");
2152 panel->description = _("Background texture configuration for windows,\n" "menus and icons.");
2154 panel->parent = parent;
2156 panel->callbacks.createWidgets = createPanel;
2157 panel->callbacks.updateDomain = storeData;
2158 panel->callbacks.prepareForClose = prepareForClose;
2160 AddSection(panel, ICON_FILE);
2162 return panel;
2165 /****************************************************************************/
2167 typedef struct ExtractPanel {
2168 WMWindow *win;
2170 WMLabel *label;
2171 WMList *list;
2173 WMButton *closeB;
2174 WMButton *extrB;
2175 } ExtractPanel;
2177 static void OpenExtractPanelFor(_Panel *panel)
2179 ExtractPanel *epanel;
2180 WMColor *color;
2181 WMFont *font;
2182 WMScreen *scr = WMWidgetScreen(panel->parent);
2184 epanel = wmalloc(sizeof(ExtractPanel));
2185 epanel->win = WMCreatePanelWithStyleForWindow(panel->parent, "extract",
2186 WMTitledWindowMask | WMClosableWindowMask);
2187 WMResizeWidget(epanel->win, 245, 250);
2188 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2190 epanel->label = WMCreateLabel(epanel->win);
2191 WMResizeWidget(epanel->label, 225, 18);
2192 WMMoveWidget(epanel->label, 10, 10);
2193 WMSetLabelTextAlignment(epanel->label, WACenter);
2194 WMSetLabelRelief(epanel->label, WRSunken);
2196 color = WMDarkGrayColor(scr);
2197 WMSetWidgetBackgroundColor(epanel->label, color);
2198 WMReleaseColor(color);
2200 color = WMWhiteColor(scr);
2201 WMSetLabelTextColor(epanel->label, color);
2202 WMReleaseColor(color);
2204 font = WMBoldSystemFontOfSize(scr, 12);
2205 WMSetLabelFont(epanel->label, font);
2206 WMReleaseFont(font);
2208 WMSetLabelText(epanel->label, _("Textures"));
2210 epanel->list = WMCreateList(epanel->win);
2211 WMResizeWidget(epanel->list, 225, 165);
2212 WMMoveWidget(epanel->list, 10, 30);
2214 epanel->closeB = WMCreateCommandButton(epanel->win);
2215 WMResizeWidget(epanel->closeB, 74, 24);
2216 WMMoveWidget(epanel->closeB, 165, 215);
2217 WMSetButtonText(epanel->closeB, _("Close"));
2219 epanel->extrB = WMCreateCommandButton(epanel->win);
2220 WMResizeWidget(epanel->extrB, 74, 24);
2221 WMMoveWidget(epanel->extrB, 80, 215);
2222 WMSetButtonText(epanel->extrB, _("Extract"));
2224 WMMapSubwidgets(epanel->win);
2226 /* take textures from file */
2228 WMRealizeWidget(epanel->win);
2230 WMMapWidget(epanel->win);