added options page in appearance section
[wmaker-crm.git] / WPrefs.app / Appearance.c
blobda3a0c3f1ea05b3f7c09efd85816b01aaa2ef7f7
1 /* Apperance.c- color/texture for titlebar etc.
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1999 Alfredo K. Kojima
6 *
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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 #include "WPrefs.h"
26 #include <unistd.h>
27 #include <errno.h>
28 #include <ctype.h>
29 #include <time.h>
30 #include <sys/stat.h>
31 #include <sys/types.h>
32 #include <fcntl.h>
33 #include <unistd.h>
38 #include "TexturePanel.h"
40 typedef struct _Panel {
41 WMFrame *frame;
42 char *sectionName;
44 char *description;
46 CallbackRec callbacks;
48 WMWindow *win;
50 WMLabel *prevL;
53 WMTabView *tabv;
55 /* texture list */
56 WMFrame *texF;
57 WMList *texLs;
59 WMPopUpButton *secP;
61 WMButton *newB;
62 WMButton *editB;
63 WMButton *ripB;
64 WMButton *delB;
66 /* text color */
67 WMFrame *colF;
69 /* options */
70 WMFrame *optF;
72 WMFrame *mstyF;
73 WMButton *mstyB[3];
75 /* */
77 int textureIndex[8];
79 WMFont *smallFont;
80 WMFont *normalFont;
81 WMFont *boldFont;
83 TexturePanel *texturePanel;
85 WMPixmap *onLed;
86 WMPixmap *offLed;
87 WMPixmap *hand;
89 int oldsection;
91 char menuStyle;
93 Pixmap preview;
95 char *fprefix;
96 } _Panel;
99 typedef struct {
100 char *title;
101 char *texture;
102 proplist_t prop;
103 Pixmap preview;
105 char *path;
107 char selectedFor;
108 unsigned current:1;
109 unsigned ispixmap:1;
110 } TextureListItem;
113 static void showData(_Panel *panel);
115 static void changePage(WMWidget *w, void *data);
117 static void OpenExtractPanelFor(_Panel *panel, char *path);
119 #define ICON_FILE "appearance"
121 #define TNEW_FILE "tnew"
122 #define TDEL_FILE "tdel"
123 #define TEDIT_FILE "tedit"
124 #define TEXTR_FILE "textr"
126 #define MSTYLE1_FILE "msty1"
127 #define MSTYLE2_FILE "msty2"
128 #define MSTYLE3_FILE "msty3"
131 /* XPM */
132 static char * blueled_xpm[] = {
133 "8 8 17 1",
134 " c None",
135 ". c #020204",
136 "+ c #16B6FC",
137 "@ c #176AFC",
138 "# c #163AFC",
139 "$ c #72D2FC",
140 "% c #224CF4",
141 "& c #76D6FC",
142 "* c #16AAFC",
143 "= c #CEE9FC",
144 "- c #229EFC",
145 "; c #164CFC",
146 "> c #FAFEFC",
147 ", c #2482FC",
148 "' c #1652FC",
149 ") c #1E76FC",
150 "! c #1A60FC",
151 " .... ",
152 " .=>-@. ",
153 ".=>$@@'.",
154 ".=$@!;;.",
155 ".!@*+!#.",
156 ".#'*+*,.",
157 " .@)@,. ",
158 " .... "};
161 /* XPM */
162 static char *blueled2_xpm[] = {
163 /* width height num_colors chars_per_pixel */
164 " 8 8 17 1",
165 /* colors */
166 ". c None",
167 "# c #090909",
168 "a c #4b63a4",
169 "b c #011578",
170 "c c #264194",
171 "d c #04338c",
172 "e c #989dac",
173 "f c #011a7c",
174 "g c #465c9c",
175 "h c #03278a",
176 "i c #6175ac",
177 "j c #011e74",
178 "k c #043a90",
179 "l c #042f94",
180 "m c #0933a4",
181 "n c #022184",
182 "o c #012998",
183 /* pixels */
184 "..####..",
185 ".#aimn#.",
186 "#aechnf#",
187 "#gchnjf#",
188 "#jndknb#",
189 "#bjdddl#",
190 ".#nono#.",
191 "..####.."
194 /* XPM */
195 static char * hand_xpm[] = {
196 "22 21 17 1",
197 " c None",
198 ". c #030305",
199 "+ c #101010",
200 "@ c #535355",
201 "# c #7F7F7E",
202 "$ c #969697",
203 "% c #B5B5B6",
204 "& c #C5C5C6",
205 "* c #D2D2D0",
206 "= c #DCDCDC",
207 "- c #E5E5E4",
208 "; c #ECECEC",
209 "> c #767674",
210 ", c #F2F2F4",
211 "' c #676767",
212 ") c #FDFDFB",
213 "! c #323234",
214 " ",
215 " ..... ",
216 " ..#%&&$. ",
217 " .))),%.......... ",
218 " .)-)),&)))))))))$. ",
219 " .-&))))))))),,,,;;. ",
220 " .=)))))))));-=***&$. ",
221 " .=)))))))),..+..... ",
222 " +=)))))))))-&#. ",
223 " +=)))))))))-%>. ",
224 " +&)))))))))-%'. ",
225 " +$,,))))));... ",
226 " .#%%*;,)),*$>+ ",
227 " .'>$%&&&&$#@. ",
228 " .!'>#$##>'. ",
229 " ..+++++. ",
230 " ",
231 " ##@@@## ",
232 " @@@@@@@@@@@ ",
233 " >>@@@## ",
234 " "};
239 #define FTITLE (1<<0)
240 #define UTITLE (1<<1)
241 #define OTITLE (1<<2)
242 #define RESIZEBAR (1<<3)
243 #define MTITLE (1<<4)
244 #define MITEM (1<<5)
245 #define ICON (1<<6)
246 #define BACK (1<<7)
247 #define EVERYTHING 0xff
250 #define RESIZEBAR_BEVEL -1
251 #define MENU_BEVEL -2
253 #define TEXPREV_WIDTH 40
254 #define TEXPREV_HEIGHT 24
257 #define MSTYLE_NORMAL 0
258 #define MSTYLE_SINGLE 1
259 #define MSTYLE_FLAT 2
264 static void
265 str2rcolor(RContext *rc, char *name, RColor *color)
267 XColor xcolor;
269 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
271 color->alpha = 255;
272 color->red = xcolor.red >> 8;
273 color->green = xcolor.green >> 8;
274 color->blue = xcolor.blue >> 8;
279 static void
280 dumpRImage(char *path, RImage *image)
282 FILE *f;
284 f = fopen(path, "w");
285 if (!f) {
286 wsyserror(path);
287 return;
289 fprintf(f, "%02x%02x%1x", image->width, image->height,
290 image->data[3]!=NULL ? 4 : 3);
292 fwrite(image->data[0], 1, image->width * image->height, f);
293 fwrite(image->data[1], 1, image->width * image->height, f);
294 fwrite(image->data[2], 1, image->width * image->height, f);
295 if (image->data[3])
296 fwrite(image->data[3], 1, image->width * image->height, f);
298 if (fclose(f) < 0) {
299 wsyserror(path);
305 static int
306 isPixmap(proplist_t prop)
308 proplist_t p;
309 char *s;
311 p = PLGetArrayElement(prop, 0);
312 s = PLGetString(p);
313 if (strcasecmp(&s[1], "pixmap")==0)
314 return 1;
315 else
316 return 0;
320 static void
321 drawResizebarBevel(RImage *img)
323 RColor light;
324 RColor dark;
325 RColor black;
326 int width = img->width;
327 int height = img->height;
328 int cwidth = 28;
330 black.alpha = 255;
331 black.red = black.green = black.blue = 0;
333 light.alpha = 0;
334 light.red = light.green = light.blue = 80;
336 dark.alpha = 0;
337 dark.red = dark.green = dark.blue = 40;
339 ROperateLine(img, RSubtractOperation, 0, 0, width-1, 0, &dark);
340 ROperateLine(img, RAddOperation, 0, 1, width-1, 1, &light);
342 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height-1, &dark);
343 ROperateLine(img, RAddOperation, cwidth+1, 2, cwidth+1, height-1, &light);
345 ROperateLine(img, RSubtractOperation, width-cwidth-2, 2, width-cwidth-2,
346 height-1, &dark);
347 ROperateLine(img, RAddOperation, width-cwidth-1, 2, width-cwidth-1,
348 height-1, &light);
350 RDrawLine(img, 0, height-1, width-1, height-1, &black);
351 RDrawLine(img, 0, 0, 0, height-1, &black);
352 RDrawLine(img, width-1, 0, width-1, height-1, &black);
356 static void
357 drawMenuBevel(RImage *img)
359 RColor light, dark, mid;
360 int i;
361 int iheight = img->height / 4;
363 light.alpha = 0;
364 light.red = light.green = light.blue = 80;
366 dark.alpha = 255;
367 dark.red = dark.green = dark.blue = 0;
369 mid.alpha = 0;
370 mid.red = mid.green = mid.blue = 40;
372 for (i = 1; i < 4; i++) {
373 ROperateLine(img, RSubtractOperation, 0, i*iheight-2,
374 img->width-1, i*iheight-2, &mid);
376 RDrawLine(img, 0, i*iheight-1,
377 img->width-1, i*iheight-1, &dark);
379 ROperateLine(img, RAddOperation, 1, i*iheight,
380 img->width-2, i*iheight, &light);
385 static Pixmap
386 renderTexture(WMScreen *scr, proplist_t texture, int width, int height,
387 char *path, int border)
389 char *type;
390 RImage *image = NULL;
391 Pixmap pixmap;
392 RContext *rc = WMScreenRContext(scr);
393 char *str;
394 RColor rcolor;
397 type = PLGetString(PLGetArrayElement(texture, 0));
399 if (strcasecmp(type, "solid")==0) {
401 str = PLGetString(PLGetArrayElement(texture, 1));
403 str2rcolor(rc, str, &rcolor);
405 image = RCreateImage(width, height, False);
406 RClearImage(image, &rcolor);
407 } else if (strcasecmp(&type[1], "gradient")==0) {
408 int style;
409 RColor rcolor2;
411 switch (toupper(type[0])) {
412 case 'V':
413 style = RVerticalGradient;
414 break;
415 case 'H':
416 style = RHorizontalGradient;
417 break;
418 default:
419 case 'D':
420 style = RDiagonalGradient;
421 break;
424 str = PLGetString(PLGetArrayElement(texture, 1));
425 str2rcolor(rc, str, &rcolor);
426 str = PLGetString(PLGetArrayElement(texture, 2));
427 str2rcolor(rc, str, &rcolor2);
429 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
430 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='T') {
431 int style;
432 RColor rcolor2;
433 int i;
434 RImage *grad, *timage;
435 char *path;
437 switch (toupper(type[1])) {
438 case 'V':
439 style = RVerticalGradient;
440 break;
441 case 'H':
442 style = RHorizontalGradient;
443 break;
444 default:
445 case 'D':
446 style = RDiagonalGradient;
447 break;
450 str = PLGetString(PLGetArrayElement(texture, 3));
451 str2rcolor(rc, str, &rcolor);
452 str = PLGetString(PLGetArrayElement(texture, 4));
453 str2rcolor(rc, str, &rcolor2);
455 str = PLGetString(PLGetArrayElement(texture, 1));
457 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
458 timage = RLoadImage(rc, path, 0);
460 if (!timage) {
461 wwarning("could not load file '%s': %s", path,
462 RMessageForError(RErrorCode));
463 } else {
464 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
466 image = RMakeTiledImage(timage, width, height);
467 RDestroyImage(timage);
469 i = atoi(PLGetString(PLGetArrayElement(texture, 2)));
471 RCombineImagesWithOpaqueness(image, grad, i);
472 RDestroyImage(grad);
474 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='M') {
475 int style;
476 RColor **colors;
477 int i, j;
479 switch (toupper(type[1])) {
480 case 'V':
481 style = RVerticalGradient;
482 break;
483 case 'H':
484 style = RHorizontalGradient;
485 break;
486 default:
487 case 'D':
488 style = RDiagonalGradient;
489 break;
492 j = PLGetNumberOfElements(texture);
494 if (j > 0) {
495 colors = wmalloc(j * sizeof(RColor*));
497 for (i = 2; i < j; i++) {
498 str = PLGetString(PLGetArrayElement(texture, i));
499 colors[i-2] = wmalloc(sizeof(RColor));
500 str2rcolor(rc, str, colors[i-2]);
502 colors[i-2] = NULL;
504 image = RRenderMultiGradient(width, height, colors, style);
506 for (i = 0; colors[i]!=NULL; i++)
507 free(colors[i]);
508 free(colors);
510 } else if (strcasecmp(&type[1], "pixmap")==0) {
511 RImage *timage = NULL;
512 char *path;
513 RColor color;
515 str = PLGetString(PLGetArrayElement(texture, 1));
517 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
518 if (path)
519 timage = RLoadImage(rc, path, 0);
521 if (!timage) {
522 wwarning("could not load file '%s': %s", path ? path : str,
523 RMessageForError(RErrorCode));
524 } else {
525 str = PLGetString(PLGetArrayElement(texture, 2));
526 str2rcolor(rc, str, &color);
528 switch (toupper(type[0])) {
529 case 'T':
530 image = RMakeTiledImage(timage, width, height);
531 RDestroyImage(timage);
532 timage = image;
533 break;
534 case 'C':
535 image = RMakeCenteredImage(timage, width, height, &color);
536 RDestroyImage(timage);
537 timage = image;
538 break;
539 case 'S':
540 case 'M':
541 image = RScaleImage(timage, width, height);
542 RDestroyImage(timage);
543 timage = image;
544 break;
548 free(path);
551 if (!image)
552 return None;
554 if (path) {
555 dumpRImage(path, image);
558 if (border < 0) {
559 if (border == RESIZEBAR_BEVEL) {
560 drawResizebarBevel(image);
561 } else if (border == MENU_BEVEL) {
562 drawMenuBevel(image);
563 RBevelImage(image, RBEV_RAISED2);
565 } else if (border) {
566 RBevelImage(image, border);
569 RConvertImage(rc, image, &pixmap);
570 RDestroyImage(image);
572 return pixmap;
576 static Pixmap
577 renderMenu(_Panel *panel, proplist_t texture, int width, int iheight)
579 WMScreen *scr = WMWidgetScreen(panel->win);
580 Display *dpy = WMScreenDisplay(scr);
581 Pixmap pix, tmp;
582 GC gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
583 int i;
585 switch (panel->menuStyle) {
586 case MSTYLE_NORMAL:
587 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
589 pix = XCreatePixmap(dpy, tmp, width, iheight*4, WMScreenDepth(scr));
590 for (i = 0; i < 4; i++) {
591 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight,
592 0, iheight*i);
594 XFreePixmap(dpy, tmp);
595 break;
596 case MSTYLE_SINGLE:
597 pix = renderTexture(scr, texture, width, iheight*4, NULL, MENU_BEVEL);
598 break;
599 case MSTYLE_FLAT:
600 pix = renderTexture(scr, texture, width, iheight*4, NULL, RBEV_RAISED2);
601 break;
603 XFreeGC(dpy, gc);
605 return pix;
609 static void
610 updatePreviewBox(_Panel *panel, int elements)
612 WMScreen *scr = WMWidgetScreen(panel->win);
613 Display *dpy = WMScreenDisplay(scr);
614 /* RContext *rc = WMScreenRContext(scr);*/
615 int refresh = 0;
616 Pixmap pix;
617 GC gc;
618 WMListItem *item;
619 TextureListItem *titem;
621 gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
624 if (!panel->preview) {
625 WMColor *color;
627 panel->preview = XCreatePixmap(dpy, WMWidgetXID(panel->win),
628 240-4, 215-4, WMScreenDepth(scr));
630 color = WMGrayColor(scr);
631 XFillRectangle(dpy, panel->preview, WMColorGC(color),
632 0, 0, 240-4, 215-4);
633 WMReleaseColor(color);
635 refresh = -1;
638 if (elements & FTITLE) {
639 item = WMGetListItem(panel->texLs, panel->textureIndex[0]);
640 titem = (TextureListItem*)item->clientData;
642 pix = renderTexture(scr, titem->prop, 190, 20, NULL, RBEV_RAISED2);
644 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 210, 20, 30, 10);
646 XFreePixmap(dpy, pix);
648 if (elements & UTITLE) {
649 item = WMGetListItem(panel->texLs, panel->textureIndex[1]);
650 titem = (TextureListItem*)item->clientData;
652 pix = renderTexture(scr, titem->prop, 190, 20, NULL, RBEV_RAISED2);
654 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 210, 20, 30, 40);
656 XFreePixmap(dpy, pix);
658 if (elements & OTITLE) {
659 item = WMGetListItem(panel->texLs, panel->textureIndex[2]);
660 titem = (TextureListItem*)item->clientData;
662 pix = renderTexture(scr, titem->prop, 190, 20, NULL, RBEV_RAISED2);
664 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 210, 20, 30, 70);
666 XFreePixmap(dpy, pix);
668 if (elements & RESIZEBAR) {
669 item = WMGetListItem(panel->texLs, panel->textureIndex[3]);
670 titem = (TextureListItem*)item->clientData;
672 pix = renderTexture(scr, titem->prop, 190, 9, NULL, RESIZEBAR_BEVEL);
674 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 210, 20, 30, 100);
676 XFreePixmap(dpy, pix);
678 if (elements & MTITLE) {
679 item = WMGetListItem(panel->texLs, panel->textureIndex[4]);
680 titem = (TextureListItem*)item->clientData;
682 pix = renderTexture(scr, titem->prop, 90, 20, NULL, RBEV_RAISED2);
684 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 90, 20, 30, 120);
686 XFreePixmap(dpy, pix);
688 if (elements & MITEM) {
689 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
690 titem = (TextureListItem*)item->clientData;
692 pix = renderMenu(panel, titem->prop, 90, 18);
694 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 90, 18*4, 30, 140);
696 XFreePixmap(dpy, pix);
698 if (elements & (MITEM|MTITLE)) {
699 XDrawLine(dpy, panel->preview, gc, 29, 120, 29, 120+18*4+20);
700 XDrawLine(dpy, panel->preview, gc, 29, 119, 119, 119);
703 if (elements & ICON) {
704 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
705 titem = (TextureListItem*)item->clientData;
707 pix = renderTexture(scr, titem->prop, 64, 64, NULL,
708 titem->ispixmap ? 0 : RBEV_RAISED3);
710 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 64, 64, 155, 130);
712 XFreePixmap(dpy, pix);
715 if (refresh < 0) {
716 WMPixmap *p;
717 p = WMCreatePixmapFromXPixmaps(scr, panel->preview, None,
718 240-4, 215-4, WMScreenDepth(scr));
720 WMSetLabelImage(panel->prevL, p);
721 WMReleasePixmap(p);
722 } else {
723 WMRedisplayWidget(panel->prevL);
726 XFreeGC(dpy, gc);
732 static void
733 cancelNewTexture(void *data)
735 _Panel *panel = (_Panel*)data;
737 HideTexturePanel(panel->texturePanel);
743 static char*
744 makeFileName(char *prefix)
746 char *fname;
748 fname = wstrdup(prefix);
750 while (access(fname, F_OK)==0) {
751 char buf[30];
753 free(fname);
754 sprintf(buf, "%08lx.cache", time(NULL));
755 fname = wstrappend(prefix, buf);
758 return fname;
764 static void
765 okNewTexture(void *data)
767 _Panel *panel = (_Panel*)data;
768 WMListItem *item;
769 char *name;
770 char *str;
771 proplist_t prop;
772 TextureListItem *titem;
773 WMScreen *scr = WMWidgetScreen(panel->win);
775 titem = wmalloc(sizeof(TextureListItem));
776 memset(titem, 0, sizeof(TextureListItem));
778 HideTexturePanel(panel->texturePanel);
780 name = GetTexturePanelTextureName(panel->texturePanel);
782 prop = GetTexturePanelTexture(panel->texturePanel);
784 str = PLGetDescription(prop);
786 titem->title = name;
787 titem->prop = prop;
788 titem->texture = str;
789 titem->selectedFor = 0;
791 titem->ispixmap = isPixmap(prop);
793 titem->path = makeFileName(panel->fprefix);
794 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT,
795 titem->path, 0);
797 item = WMAddListItem(panel->texLs, "");
798 item->clientData = titem;
800 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
804 static void
805 okEditTexture(void *data)
807 _Panel *panel = (_Panel*)data;
808 WMListItem *item;
809 char *name;
810 char *str;
811 proplist_t prop;
812 TextureListItem *titem;
814 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
815 titem = (TextureListItem*)item->clientData;
817 HideTexturePanel(panel->texturePanel);
819 if (titem->current) {
820 name = GetTexturePanelTextureName(panel->texturePanel);
822 free(titem->title);
823 titem->title = name;
826 prop = GetTexturePanelTexture(panel->texturePanel);
828 str = PLGetDescription(prop);
830 PLRelease(titem->prop);
831 titem->prop = prop;
833 titem->ispixmap = isPixmap(prop);
835 free(titem->texture);
836 titem->texture = str;
838 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
839 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
840 TEXPREV_WIDTH, TEXPREV_HEIGHT,
841 titem->path, 0);
843 WMRedisplayWidget(panel->texLs);
845 if (titem->selectedFor)
846 updatePreviewBox(panel, titem->selectedFor);
848 changePage(panel->secP, panel);
853 static void
854 editTexture(WMWidget *w, void *data)
856 _Panel *panel = (_Panel*)data;
857 WMListItem *item;
858 TextureListItem *titem;
860 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
861 titem = (TextureListItem*)item->clientData;
863 SetTexturePanelPixmapPath(panel->texturePanel,
864 GetObjectForKey("PixmapPath"));
866 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
868 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
869 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
871 ShowTexturePanel(panel->texturePanel);
876 static void
877 newTexture(WMWidget *w, void *data)
879 _Panel *panel = (_Panel*)data;
881 SetTexturePanelPixmapPath(panel->texturePanel,
882 GetObjectForKey("PixmapPath"));
884 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
886 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
888 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
890 ShowTexturePanel(panel->texturePanel);
895 static void
896 deleteTexture(WMWidget *w, void *data)
898 _Panel *panel = (_Panel*)data;
899 WMListItem *item;
900 TextureListItem *titem;
901 int row;
902 int section;
904 section = WMGetPopUpButtonSelectedItem(panel->secP);
905 row = WMGetListSelectedItemRow(panel->texLs);
906 item = WMGetListItem(panel->texLs, row);
907 titem = (TextureListItem*)item->clientData;
909 if (titem->selectedFor & (1 << section)) {
910 TextureListItem *titem2;
912 panel->textureIndex[section] = section;
913 item = WMGetListItem(panel->texLs, section);
914 titem2 = (TextureListItem*)item->clientData;
915 titem2->selectedFor |= 1 << section;
918 free(titem->title);
919 free(titem->texture);
920 PLRelease(titem->prop);
921 if (titem->path) {
922 if (remove(titem->path) < 0 && errno != ENOENT) {
923 wsyserror("could not remove file %s", titem->path);
925 free(titem->path);
928 free(titem);
930 WMRemoveListItem(panel->texLs, row);
931 WMSetButtonEnabled(panel->delB, False);
937 static void
938 extractTexture(WMWidget *w, void *data)
940 _Panel *panel = (_Panel*)data;
941 char *path;
942 WMOpenPanel *opanel;
943 WMScreen *scr = WMWidgetScreen(w);
945 opanel = WMGetOpenPanel(scr);
946 WMSetFilePanelCanChooseDirectories(opanel, False);
947 WMSetFilePanelCanChooseFiles(opanel, True);
949 if (WMRunModalFilePanelForDirectory(opanel, panel->win, wgethomedir(),
950 _("Select File"), NULL)) {
951 path = WMGetFilePanelFileName(opanel);
953 OpenExtractPanelFor(panel, path);
955 free(path);
960 static void
961 changePage(WMWidget *w, void *data)
963 _Panel *panel = (_Panel*)data;
964 int section;
965 WMListItem *item;
966 TextureListItem *titem;
967 WMScreen *scr = WMWidgetScreen(w);
968 RContext *rc = WMScreenRContext(scr);
969 static WMPoint positions[] = {
970 {5, 10},
971 {5, 40},
972 {5, 70},
973 {5, 100},
974 {5, 120},
975 {5, 160},
976 {130, 150}
979 section = WMGetPopUpButtonSelectedItem(panel->secP);
981 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
983 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
985 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
987 titem = (TextureListItem*)item->clientData;
990 WMColor *color;
992 color = WMGrayColor(scr);
993 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
994 positions[panel->oldsection].x,
995 positions[panel->oldsection].y, 22, 22);
996 WMReleaseColor(color);
998 panel->oldsection = section;
999 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1000 positions[section].y);
1002 WMRedisplayWidget(panel->prevL);
1007 static void
1008 previewClick(XEvent *event, void *clientData)
1010 _Panel *panel = (_Panel*)clientData;
1011 int i;
1012 static WMRect parts[] = {
1013 {{30,10},{190, 20}},
1014 {{30,40},{190,20}},
1015 {{30,70},{190,20}},
1016 {{30,100},{190,9}},
1017 {{30,120},{90,20}},
1018 {{30,140},{90,18*4}},
1019 {{155,130},{64,64}}
1022 for (i = 0; i < 7; i++) {
1023 if (event->xbutton.x >= parts[i].pos.x
1024 && event->xbutton.y >= parts[i].pos.y
1025 && event->xbutton.x < parts[i].pos.x + parts[i].size.width
1026 && event->xbutton.y < parts[i].pos.y + parts[i].size.height) {
1028 WMSetPopUpButtonSelectedItem(panel->secP, i);
1029 changePage(panel->secP, panel);
1030 return;
1036 static void
1037 textureClick(WMWidget *w, void *data)
1039 _Panel *panel = (_Panel*)data;
1040 int i;
1041 WMListItem *item;
1042 TextureListItem *titem;
1044 i = WMGetListSelectedItemRow(panel->texLs);
1046 item = WMGetListItem(panel->texLs, i);
1048 titem = (TextureListItem*)item->clientData;
1050 if (titem->current) {
1051 WMSetButtonEnabled(panel->delB, False);
1052 } else {
1053 WMSetButtonEnabled(panel->delB, True);
1059 static void
1060 textureDoubleClick(WMWidget *w, void *data)
1062 _Panel *panel = (_Panel*)data;
1063 int i, section;
1064 WMListItem *item;
1065 TextureListItem *titem;
1067 /* unselect old texture */
1068 section = WMGetPopUpButtonSelectedItem(panel->secP);
1070 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1071 titem = (TextureListItem*)item->clientData;
1072 titem->selectedFor &= ~(1 << section);
1074 /* select new texture */
1075 i = WMGetListSelectedItemRow(panel->texLs);
1077 item = WMGetListItem(panel->texLs, i);
1079 titem = (TextureListItem*)item->clientData;
1081 titem->selectedFor |= 1<<section;
1083 panel->textureIndex[section] = i;
1085 WMRedisplayWidget(panel->texLs);
1087 updatePreviewBox(panel, 1<<section);
1093 static void
1094 paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
1095 WMRect *rect)
1097 _Panel *panel = (_Panel*)WMGetHangedData(lPtr);
1098 WMScreen *scr = WMWidgetScreen(lPtr);
1099 int width, height, x, y;
1100 Display *dpy = WMScreenDisplay(scr);
1101 WMColor *white = WMWhiteColor(scr);
1102 WMListItem *item;
1103 WMColor *black = WMBlackColor(scr);
1104 TextureListItem *titem;
1106 width = rect->size.width;
1107 height = rect->size.height;
1108 x = rect->pos.x;
1109 y = rect->pos.y;
1111 if (state & WLDSSelected)
1112 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
1113 else
1114 XClearArea(dpy, d, x, y, width, height, False);
1116 item = WMGetListItem(lPtr, index);
1117 titem = (TextureListItem*)item->clientData;
1119 if (titem->preview)
1120 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0, TEXPREV_WIDTH,
1121 TEXPREV_HEIGHT, x + 5, y + 5);
1123 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1124 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1125 else if (titem->selectedFor)
1126 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1128 WMDrawString(scr, d, WMColorGC(black), panel->boldFont,
1129 x + TEXPREV_WIDTH + 22, y + 2, titem->title,
1130 strlen(titem->title));
1132 WMDrawString(scr, d, WMColorGC(black), panel->smallFont,
1133 x + TEXPREV_WIDTH + 14, y + 18, titem->texture,
1134 strlen(titem->texture));
1137 WMReleaseColor(white);
1138 WMReleaseColor(black);
1143 static Pixmap
1144 loadRImage(WMScreen *scr, char *path)
1146 FILE *f;
1147 RImage *image;
1148 int w, h, d;
1149 int i;
1150 Pixmap pixmap;
1152 f = fopen(path, "r");
1153 if (!f)
1154 return None;
1156 fscanf(f, "%02x%02x%1x", &w, &h, &d);
1158 image = RCreateImage(w, h, d == 4);
1159 for (i = 0; i < d; i++) {
1160 fread(image->data[i], 1, w*h, f);
1162 fclose(f);
1164 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1165 RDestroyImage(image);
1167 return pixmap;
1172 static void
1173 fillTextureList(WMList *lPtr)
1175 proplist_t textureList;
1176 proplist_t texture;
1177 WMUserDefaults *udb = WMGetStandardUserDefaults();
1178 int i;
1179 TextureListItem *titem;
1180 WMScreen *scr = WMWidgetScreen(lPtr);
1182 textureList = WMGetUDObjectForKey(udb, "TextureList");
1183 if (!textureList)
1184 return;
1186 for (i = 0; i < PLGetNumberOfElements(textureList); i++) {
1187 WMListItem *item;
1189 texture = PLGetArrayElement(textureList, i);
1191 titem = wmalloc(sizeof(TextureListItem));
1192 memset(titem, 0, sizeof(TextureListItem));
1194 titem->title = wstrdup(PLGetString(PLGetArrayElement(texture, 0)));
1195 titem->prop = PLRetain(PLGetArrayElement(texture, 1));
1196 titem->texture = PLGetDescription(titem->prop);
1197 titem->selectedFor = 0;
1198 titem->path = wstrdup(PLGetString(PLGetArrayElement(texture, 2)));
1200 titem->preview = loadRImage(scr, titem->path);
1201 if (!titem->preview) {
1202 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH,
1203 TEXPREV_HEIGHT, NULL, 0);
1205 item = WMAddListItem(lPtr, "");
1206 item->clientData = titem;
1211 static void
1212 menuStyleCallback(WMWidget *self, void *data)
1214 _Panel *panel = (_Panel*)data;
1216 if (self == panel->mstyB[0]) {
1217 panel->menuStyle = MSTYLE_NORMAL;
1218 updatePreviewBox(panel, MITEM);
1220 } else if (self == panel->mstyB[1]) {
1221 panel->menuStyle = MSTYLE_SINGLE;
1222 updatePreviewBox(panel, MITEM);
1224 } else if (self == panel->mstyB[2]) {
1225 panel->menuStyle = MSTYLE_FLAT;
1226 updatePreviewBox(panel, MITEM);
1231 static void
1232 createPanel(Panel *p)
1234 _Panel *panel = (_Panel*)p;
1235 WMFont *font;
1236 WMScreen *scr = WMWidgetScreen(panel->win);
1237 WMTabViewItem *item;
1238 int i;
1239 char *tmp;
1240 Bool ok = True;
1242 panel->fprefix = wstrappend(wusergnusteppath(), "/.AppInfo");
1244 if (access(panel->fprefix, F_OK)!=0) {
1245 if (mkdir(panel->fprefix, 0755) < 0) {
1246 wsyserror(panel->fprefix);
1247 ok = False;
1250 if (ok) {
1251 tmp = wstrappend(panel->fprefix, "/WPrefs/");
1252 free(panel->fprefix);
1253 panel->fprefix = tmp;
1254 if (access(panel->fprefix, F_OK)!=0) {
1255 if (mkdir(panel->fprefix, 0755) < 0) {
1256 wsyserror(panel->fprefix);
1261 panel->smallFont = WMSystemFontOfSize(scr, 10);
1262 panel->normalFont = WMSystemFontOfSize(scr, 12);
1263 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1265 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1266 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1267 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1269 panel->frame = WMCreateFrame(panel->win);
1270 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
1271 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
1273 /* preview box */
1274 panel->prevL = WMCreateLabel(panel->frame);
1275 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1276 WMMoveWidget(panel->prevL, 15, 10);
1277 WMSetLabelRelief(panel->prevL, WRSunken);
1278 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1280 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask,
1281 previewClick, panel);
1284 /* tabview */
1286 panel->tabv = WMCreateTabView(panel->frame);
1287 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1288 WMMoveWidget(panel->tabv, 265, 10);
1290 /*** texture list ***/
1292 panel->texF = WMCreateFrame(panel->frame);
1293 WMSetFrameRelief(panel->texF, WRFlat);
1295 item = WMCreateTabViewItemWithIdentifier(0);
1296 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1297 WMSetTabViewItemLabel(item, _("Texture"));
1299 WMAddItemInTabView(panel->tabv, item);
1302 panel->secP = WMCreatePopUpButton(panel->texF);
1303 WMResizeWidget(panel->secP, 228, 20);
1304 WMMoveWidget(panel->secP, 7, 7);
1305 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1306 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1307 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1308 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1309 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1310 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1311 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1312 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1313 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1315 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1317 panel->texLs = WMCreateList(panel->texF);
1318 WMResizeWidget(panel->texLs, 165, 155);
1319 WMMoveWidget(panel->texLs, 70, 33);
1320 WMSetListUserDrawItemHeight(panel->texLs, 35);
1321 WMSetListUserDrawProc(panel->texLs, paintListItem);
1322 WMHangData(panel->texLs, panel);
1323 WMSetListAction(panel->texLs, textureClick, panel);
1324 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1326 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1327 "for the selected item."),
1328 WMWidgetView(panel->texLs));
1330 /* command buttons */
1332 font = WMSystemFontOfSize(scr, 10);
1335 panel->newB = WMCreateCommandButton(panel->texF);
1336 WMResizeWidget(panel->newB, 57, 39);
1337 WMMoveWidget(panel->newB, 7, 33);
1338 WMSetButtonFont(panel->newB, font);
1339 WMSetButtonImagePosition(panel->newB, WIPAbove);
1340 WMSetButtonText(panel->newB, _("New"));
1341 WMSetButtonAction(panel->newB, newTexture, panel);
1342 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1344 WMSetBalloonTextForView(_("Create a new texture."),
1345 WMWidgetView(panel->newB));
1347 panel->ripB = WMCreateCommandButton(panel->texF);
1348 WMResizeWidget(panel->ripB, 57, 39);
1349 WMMoveWidget(panel->ripB, 7, 72);
1350 WMSetButtonFont(panel->ripB, font);
1351 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1352 WMSetButtonText(panel->ripB, _("Extract..."));
1353 WMSetButtonAction(panel->ripB, extractTexture, panel);
1354 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1356 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1357 WMWidgetView(panel->ripB));
1359 WMSetButtonEnabled(panel->ripB, False);
1361 panel->editB = WMCreateCommandButton(panel->texF);
1362 WMResizeWidget(panel->editB, 57, 39);
1363 WMMoveWidget(panel->editB, 7, 111);
1364 WMSetButtonFont(panel->editB, font);
1365 WMSetButtonImagePosition(panel->editB, WIPAbove);
1366 WMSetButtonText(panel->editB, _("Edit"));
1367 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1368 WMSetButtonAction(panel->editB, editTexture, panel);
1369 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1370 WMWidgetView(panel->editB));
1372 panel->delB = WMCreateCommandButton(panel->texF);
1373 WMResizeWidget(panel->delB, 57, 38);
1374 WMMoveWidget(panel->delB, 7, 150);
1375 WMSetButtonFont(panel->delB, font);
1376 WMSetButtonImagePosition(panel->delB, WIPAbove);
1377 WMSetButtonText(panel->delB, _("Delete"));
1378 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1379 WMSetButtonEnabled(panel->delB, False);
1380 WMSetButtonAction(panel->delB, deleteTexture, panel);
1381 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1382 WMWidgetView(panel->delB));
1384 WMReleaseFont(font);
1386 WMMapSubwidgets(panel->texF);
1388 /*** colors ***/
1389 panel->colF = WMCreateFrame(panel->frame);
1390 WMSetFrameRelief(panel->colF, WRFlat);
1392 item = WMCreateTabViewItemWithIdentifier(1);
1393 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1394 WMSetTabViewItemLabel(item, _("Color"));
1396 WMAddItemInTabView(panel->tabv, item);
1399 /*** options ***/
1400 panel->optF = WMCreateFrame(panel->frame);
1401 WMSetFrameRelief(panel->optF, WRFlat);
1403 item = WMCreateTabViewItemWithIdentifier(2);
1404 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1405 WMSetTabViewItemLabel(item, _("Options"));
1407 WMAddItemInTabView(panel->tabv, item);
1409 panel->mstyF = WMCreateFrame(panel->optF);
1410 WMResizeWidget(panel->mstyF, 215, 85);
1411 WMMoveWidget(panel->mstyF, 15, 10);
1412 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1414 for (i = 0; i < 3; i++) {
1415 WMPixmap *icon;
1416 char *path;
1418 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1419 WMResizeWidget(panel->mstyB[i], 54, 54);
1420 WMMoveWidget(panel->mstyB[i], 15 + i*65, 20);
1421 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1422 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1423 switch (i) {
1424 case 0:
1425 path = LocateImage(MSTYLE1_FILE);
1426 break;
1427 case 1:
1428 path = LocateImage(MSTYLE2_FILE);
1429 break;
1430 case 2:
1431 path = LocateImage(MSTYLE3_FILE);
1432 break;
1434 if (path) {
1435 icon = WMCreatePixmapFromFile(scr, path);
1436 if (icon) {
1437 WMSetButtonImage(panel->mstyB[i], icon);
1438 WMReleasePixmap(icon);
1439 } else {
1440 wwarning(_("could not load icon file %s"), path);
1442 free(path);
1445 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
1446 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
1448 WMMapSubwidgets(panel->mstyF);
1450 WMMapSubwidgets(panel->optF);
1452 /**/
1454 WMRealizeWidget(panel->frame);
1455 WMMapSubwidgets(panel->frame);
1457 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1459 showData(panel);
1461 changePage(panel->secP, panel);
1463 fillTextureList(panel->texLs);
1465 panel->texturePanel = CreateTexturePanel(panel->win);
1470 static void
1471 setupTextureFor(WMList *list, char *key, char *defValue, char *title,
1472 int index)
1474 WMListItem *item;
1475 TextureListItem *titem;
1477 titem = wmalloc(sizeof(TextureListItem));
1478 memset(titem, 0, sizeof(TextureListItem));
1480 titem->title = wstrdup(title);
1481 titem->prop = GetObjectForKey(key);
1482 if (!titem->prop) {
1483 titem->prop = PLGetProplistWithDescription(defValue);
1484 } else {
1485 PLRetain(titem->prop);
1487 titem->texture = PLGetDescription((proplist_t)titem->prop);
1488 titem->current = 1;
1489 titem->selectedFor = 1<<index;
1491 titem->ispixmap = isPixmap(titem->prop);
1493 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop,
1494 TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1496 item = WMAddListItem(list, "");
1497 item->clientData = titem;
1502 static void
1503 showData(_Panel *panel)
1505 int i = 0;
1506 char *str;
1508 str = GetStringForKey("MenuStyle");
1509 if (str && strcasecmp(str, "flat")==0) {
1510 panel->menuStyle = MSTYLE_FLAT;
1511 } else if (str && strcasecmp(str, "singletexture")==0) {
1512 panel->menuStyle = MSTYLE_SINGLE;
1513 } else {
1514 panel->menuStyle = MSTYLE_NORMAL;
1517 setupTextureFor(panel->texLs, "FTitleBack", "(solid, black)",
1518 "[Focused]", i);
1519 panel->textureIndex[i] = i++;
1521 setupTextureFor(panel->texLs, "UTitleBack", "(solid, gray)",
1522 "[Unfocused]", i);
1523 panel->textureIndex[i] = i++;
1525 setupTextureFor(panel->texLs, "PTitleBack", "(solid, \"#616161\")",
1526 "[Owner of Focused]", i);
1527 panel->textureIndex[i] = i++;
1529 setupTextureFor(panel->texLs, "ResizebarBack", "(solid, gray)",
1530 "[Resizebar]", i);
1531 panel->textureIndex[i] = i++;
1533 setupTextureFor(panel->texLs, "MenuTitleBack", "(solid, black)",
1534 "[Menu Title]", i);
1535 panel->textureIndex[i] = i++;
1537 setupTextureFor(panel->texLs, "MenuTextBack", "(solid, gray)",
1538 "[Menu Item]", i);
1539 panel->textureIndex[i] = i++;
1541 setupTextureFor(panel->texLs, "IconBack", "(solid, gray)", "[Icon]", i);
1542 panel->textureIndex[i] = i++;
1544 setupTextureFor(panel->texLs, "WorkspaceBack", "(solid, black)",
1545 "[Workspace]", i);
1546 panel->textureIndex[i] = i++;
1549 updatePreviewBox(panel, EVERYTHING);
1554 static void
1555 storeData(_Panel *panel)
1557 TextureListItem *titem;
1558 WMListItem *item;
1560 item = WMGetListItem(panel->texLs, panel->textureIndex[0]);
1561 titem = (TextureListItem*)item->clientData;
1562 SetObjectForKey(titem->prop, "FTitleBack");
1564 item = WMGetListItem(panel->texLs, panel->textureIndex[1]);
1565 titem = (TextureListItem*)item->clientData;
1566 SetObjectForKey(titem->prop, "UTitleBack");
1568 item = WMGetListItem(panel->texLs, panel->textureIndex[2]);
1569 titem = (TextureListItem*)item->clientData;
1570 SetObjectForKey(titem->prop, "PTitleBack");
1572 item = WMGetListItem(panel->texLs, panel->textureIndex[3]);
1573 titem = (TextureListItem*)item->clientData;
1574 SetObjectForKey(titem->prop, "ResizebarBack");
1576 item = WMGetListItem(panel->texLs, panel->textureIndex[4]);
1577 titem = (TextureListItem*)item->clientData;
1578 SetObjectForKey(titem->prop, "MenuTitleBack");
1580 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
1581 titem = (TextureListItem*)item->clientData;
1582 SetObjectForKey(titem->prop, "MenuTextBack");
1584 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
1585 titem = (TextureListItem*)item->clientData;
1586 SetObjectForKey(titem->prop, "IconBack");
1588 switch (panel->menuStyle) {
1589 case MSTYLE_SINGLE:
1590 SetStringForKey("singletexture", "MenuStyle");
1591 break;
1592 case MSTYLE_FLAT:
1593 SetStringForKey("flat", "MenuStyle");
1594 break;
1595 default:
1596 case MSTYLE_NORMAL:
1597 SetStringForKey("normal", "MenuStyle");
1598 break;
1603 static void
1604 prepareForClose(_Panel *panel)
1606 proplist_t textureList;
1607 proplist_t texture;
1608 int i;
1609 TextureListItem *titem;
1610 WMListItem *item;
1611 WMUserDefaults *udb = WMGetStandardUserDefaults();
1613 textureList = PLMakeArrayFromElements(NULL, NULL);
1615 /* store list of textures */
1616 for (i = 7; i < WMGetListNumberOfRows(panel->texLs); i++) {
1617 item = WMGetListItem(panel->texLs, i);
1618 titem = (TextureListItem*)item->clientData;
1620 texture = PLMakeArrayFromElements(PLMakeString(titem->title),
1621 PLRetain(titem->prop),
1622 PLMakeString(titem->path),
1623 NULL);
1625 PLAppendArrayElement(textureList, texture);
1628 WMSetUDObjectForKey(udb, textureList, "TextureList");
1629 PLRelease(textureList);
1631 WMSynchronizeUserDefaults(udb);
1636 Panel*
1637 InitAppearance(WMScreen *scr, WMWindow *win)
1639 _Panel *panel;
1641 panel = wmalloc(sizeof(_Panel));
1642 memset(panel, 0, sizeof(_Panel));
1644 panel->sectionName = _("Appearance Preferences");
1646 panel->description = _("Background texture configuration for windows,\n"
1647 "menus and icons.");
1649 panel->win = win;
1651 panel->callbacks.createWidgets = createPanel;
1652 panel->callbacks.updateDomain = storeData;
1653 panel->callbacks.prepareForClose = prepareForClose;
1655 AddSection(panel, ICON_FILE);
1657 return panel;
1662 /****************************************************************************/
1666 typedef struct ExtractPanel {
1667 WMWindow *win;
1669 WMLabel *label;
1670 WMList *list;
1672 WMButton *closeB;
1673 WMButton *extrB;
1674 } ExtractPanel;
1678 static void
1679 OpenExtractPanelFor(_Panel *panel, char *path)
1681 ExtractPanel *epanel;
1682 WMColor *color;
1683 WMFont *font;
1684 WMScreen *scr = WMWidgetScreen(panel->win);
1686 epanel = wmalloc(sizeof(ExtractPanel));
1687 epanel->win = WMCreatePanelWithStyleForWindow(panel->win, "extract",
1688 WMTitledWindowMask
1689 |WMClosableWindowMask);
1690 WMResizeWidget(epanel->win, 245, 250);
1691 WMSetWindowTitle(epanel->win, _("Extract Texture"));
1693 epanel->label = WMCreateLabel(epanel->win);
1694 WMResizeWidget(epanel->label, 225, 18);
1695 WMMoveWidget(epanel->label, 10, 10);
1696 WMSetLabelTextAlignment(epanel->label, WACenter);
1697 WMSetLabelRelief(epanel->label, WRSunken);
1699 color = WMDarkGrayColor(scr);
1700 WMSetWidgetBackgroundColor(epanel->label, color);
1701 WMReleaseColor(color);
1703 color = WMWhiteColor(scr);
1704 WMSetLabelTextColor(epanel->label, color);
1705 WMReleaseColor(color);
1707 font = WMBoldSystemFontOfSize(scr, 12);
1708 WMSetLabelFont(epanel->label, font);
1709 WMReleaseFont(font);
1711 WMSetLabelText(epanel->label, _("Textures"));
1713 epanel->list = WMCreateList(epanel->win);
1714 WMResizeWidget(epanel->list, 225, 165);
1715 WMMoveWidget(epanel->list, 10, 30);
1719 epanel->closeB = WMCreateCommandButton(epanel->win);
1720 WMResizeWidget(epanel->closeB, 74, 24);
1721 WMMoveWidget(epanel->closeB, 165, 215);
1722 WMSetButtonText(epanel->closeB, _("Close"));
1724 epanel->extrB = WMCreateCommandButton(epanel->win);
1725 WMResizeWidget(epanel->extrB, 74, 24);
1726 WMMoveWidget(epanel->extrB, 80, 215);
1727 WMSetButtonText(epanel->extrB, _("Extract"));
1729 WMMapSubwidgets(epanel->win);
1732 /* take textures from file */
1736 WMRealizeWidget(epanel->win);
1738 WMMapWidget(epanel->win);