started color page in appearance section
[wmaker-crm.git] / WPrefs.app / Appearance.c
blobd11bd963b20213df9ab61d16f48f07def27293aa
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 WMPopUpButton *colP;
71 WMColorWell *colW;
73 WMColorWell *sampW[15];
75 /* options */
76 WMFrame *optF;
78 WMFrame *mstyF;
79 WMButton *mstyB[3];
81 /* */
83 int textureIndex[8];
85 WMFont *smallFont;
86 WMFont *normalFont;
87 WMFont *boldFont;
89 TexturePanel *texturePanel;
91 WMPixmap *onLed;
92 WMPixmap *offLed;
93 WMPixmap *hand;
95 int oldsection;
97 char menuStyle;
99 Pixmap preview;
101 char *fprefix;
102 } _Panel;
105 typedef struct {
106 char *title;
107 char *texture;
108 proplist_t prop;
109 Pixmap preview;
111 char *path;
113 char selectedFor;
114 unsigned current:1;
115 unsigned ispixmap:1;
116 } TextureListItem;
119 static void showData(_Panel *panel);
121 static void changePage(WMWidget *w, void *data);
123 static void OpenExtractPanelFor(_Panel *panel, char *path);
125 #define ICON_FILE "appearance"
127 #define TNEW_FILE "tnew"
128 #define TDEL_FILE "tdel"
129 #define TEDIT_FILE "tedit"
130 #define TEXTR_FILE "textr"
132 #define MSTYLE1_FILE "msty1"
133 #define MSTYLE2_FILE "msty2"
134 #define MSTYLE3_FILE "msty3"
137 /* XPM */
138 static char * blueled_xpm[] = {
139 "8 8 17 1",
140 " c None",
141 ". c #020204",
142 "+ c #16B6FC",
143 "@ c #176AFC",
144 "# c #163AFC",
145 "$ c #72D2FC",
146 "% c #224CF4",
147 "& c #76D6FC",
148 "* c #16AAFC",
149 "= c #CEE9FC",
150 "- c #229EFC",
151 "; c #164CFC",
152 "> c #FAFEFC",
153 ", c #2482FC",
154 "' c #1652FC",
155 ") c #1E76FC",
156 "! c #1A60FC",
157 " .... ",
158 " .=>-@. ",
159 ".=>$@@'.",
160 ".=$@!;;.",
161 ".!@*+!#.",
162 ".#'*+*,.",
163 " .@)@,. ",
164 " .... "};
167 /* XPM */
168 static char *blueled2_xpm[] = {
169 /* width height num_colors chars_per_pixel */
170 " 8 8 17 1",
171 /* colors */
172 ". c None",
173 "# c #090909",
174 "a c #4b63a4",
175 "b c #011578",
176 "c c #264194",
177 "d c #04338c",
178 "e c #989dac",
179 "f c #011a7c",
180 "g c #465c9c",
181 "h c #03278a",
182 "i c #6175ac",
183 "j c #011e74",
184 "k c #043a90",
185 "l c #042f94",
186 "m c #0933a4",
187 "n c #022184",
188 "o c #012998",
189 /* pixels */
190 "..####..",
191 ".#aimn#.",
192 "#aechnf#",
193 "#gchnjf#",
194 "#jndknb#",
195 "#bjdddl#",
196 ".#nono#.",
197 "..####.."
200 /* XPM */
201 static char * hand_xpm[] = {
202 "22 21 17 1",
203 " c None",
204 ". c #030305",
205 "+ c #101010",
206 "@ c #535355",
207 "# c #7F7F7E",
208 "$ c #969697",
209 "% c #B5B5B6",
210 "& c #C5C5C6",
211 "* c #D2D2D0",
212 "= c #DCDCDC",
213 "- c #E5E5E4",
214 "; c #ECECEC",
215 "> c #767674",
216 ", c #F2F2F4",
217 "' c #676767",
218 ") c #FDFDFB",
219 "! c #323234",
220 " ",
221 " ..... ",
222 " ..#%&&$. ",
223 " .))),%.......... ",
224 " .)-)),&)))))))))$. ",
225 " .-&))))))))),,,,;;. ",
226 " .=)))))))));-=***&$. ",
227 " .=)))))))),..+..... ",
228 " +=)))))))))-&#. ",
229 " +=)))))))))-%>. ",
230 " +&)))))))))-%'. ",
231 " +$,,))))));... ",
232 " .#%%*;,)),*$>+ ",
233 " .'>$%&&&&$#@. ",
234 " .!'>#$##>'. ",
235 " ..+++++. ",
236 " ",
237 " ##@@@## ",
238 " @@@@@@@@@@@ ",
239 " >>@@@## ",
240 " "};
245 #define FTITLE (1<<0)
246 #define UTITLE (1<<1)
247 #define OTITLE (1<<2)
248 #define RESIZEBAR (1<<3)
249 #define MTITLE (1<<4)
250 #define MITEM (1<<5)
251 #define ICON (1<<6)
252 #define BACK (1<<7)
253 #define EVERYTHING 0xff
256 #define RESIZEBAR_BEVEL -1
257 #define MENU_BEVEL -2
259 #define TEXPREV_WIDTH 40
260 #define TEXPREV_HEIGHT 24
263 #define MSTYLE_NORMAL 0
264 #define MSTYLE_SINGLE 1
265 #define MSTYLE_FLAT 2
270 static void
271 str2rcolor(RContext *rc, char *name, RColor *color)
273 XColor xcolor;
275 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
277 color->alpha = 255;
278 color->red = xcolor.red >> 8;
279 color->green = xcolor.green >> 8;
280 color->blue = xcolor.blue >> 8;
285 static void
286 dumpRImage(char *path, RImage *image)
288 FILE *f;
290 f = fopen(path, "w");
291 if (!f) {
292 wsyserror(path);
293 return;
295 fprintf(f, "%02x%02x%1x", image->width, image->height,
296 image->data[3]!=NULL ? 4 : 3);
298 fwrite(image->data[0], 1, image->width * image->height, f);
299 fwrite(image->data[1], 1, image->width * image->height, f);
300 fwrite(image->data[2], 1, image->width * image->height, f);
301 if (image->data[3])
302 fwrite(image->data[3], 1, image->width * image->height, f);
304 if (fclose(f) < 0) {
305 wsyserror(path);
311 static int
312 isPixmap(proplist_t prop)
314 proplist_t p;
315 char *s;
317 p = PLGetArrayElement(prop, 0);
318 s = PLGetString(p);
319 if (strcasecmp(&s[1], "pixmap")==0)
320 return 1;
321 else
322 return 0;
326 static void
327 drawResizebarBevel(RImage *img)
329 RColor light;
330 RColor dark;
331 RColor black;
332 int width = img->width;
333 int height = img->height;
334 int cwidth = 28;
336 black.alpha = 255;
337 black.red = black.green = black.blue = 0;
339 light.alpha = 0;
340 light.red = light.green = light.blue = 80;
342 dark.alpha = 0;
343 dark.red = dark.green = dark.blue = 40;
345 ROperateLine(img, RSubtractOperation, 0, 0, width-1, 0, &dark);
346 ROperateLine(img, RAddOperation, 0, 1, width-1, 1, &light);
348 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height-1, &dark);
349 ROperateLine(img, RAddOperation, cwidth+1, 2, cwidth+1, height-1, &light);
351 ROperateLine(img, RSubtractOperation, width-cwidth-2, 2, width-cwidth-2,
352 height-1, &dark);
353 ROperateLine(img, RAddOperation, width-cwidth-1, 2, width-cwidth-1,
354 height-1, &light);
356 RDrawLine(img, 0, height-1, width-1, height-1, &black);
357 RDrawLine(img, 0, 0, 0, height-1, &black);
358 RDrawLine(img, width-1, 0, width-1, height-1, &black);
362 static void
363 drawMenuBevel(RImage *img)
365 RColor light, dark, mid;
366 int i;
367 int iheight = img->height / 4;
369 light.alpha = 0;
370 light.red = light.green = light.blue = 80;
372 dark.alpha = 255;
373 dark.red = dark.green = dark.blue = 0;
375 mid.alpha = 0;
376 mid.red = mid.green = mid.blue = 40;
378 for (i = 1; i < 4; i++) {
379 ROperateLine(img, RSubtractOperation, 0, i*iheight-2,
380 img->width-1, i*iheight-2, &mid);
382 RDrawLine(img, 0, i*iheight-1,
383 img->width-1, i*iheight-1, &dark);
385 ROperateLine(img, RAddOperation, 1, i*iheight,
386 img->width-2, i*iheight, &light);
391 static Pixmap
392 renderTexture(WMScreen *scr, proplist_t texture, int width, int height,
393 char *path, int border)
395 char *type;
396 RImage *image = NULL;
397 Pixmap pixmap;
398 RContext *rc = WMScreenRContext(scr);
399 char *str;
400 RColor rcolor;
403 type = PLGetString(PLGetArrayElement(texture, 0));
405 if (strcasecmp(type, "solid")==0) {
407 str = PLGetString(PLGetArrayElement(texture, 1));
409 str2rcolor(rc, str, &rcolor);
411 image = RCreateImage(width, height, False);
412 RClearImage(image, &rcolor);
413 } else if (strcasecmp(&type[1], "gradient")==0) {
414 int style;
415 RColor rcolor2;
417 switch (toupper(type[0])) {
418 case 'V':
419 style = RVerticalGradient;
420 break;
421 case 'H':
422 style = RHorizontalGradient;
423 break;
424 default:
425 case 'D':
426 style = RDiagonalGradient;
427 break;
430 str = PLGetString(PLGetArrayElement(texture, 1));
431 str2rcolor(rc, str, &rcolor);
432 str = PLGetString(PLGetArrayElement(texture, 2));
433 str2rcolor(rc, str, &rcolor2);
435 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
436 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='T') {
437 int style;
438 RColor rcolor2;
439 int i;
440 RImage *grad, *timage;
441 char *path;
443 switch (toupper(type[1])) {
444 case 'V':
445 style = RVerticalGradient;
446 break;
447 case 'H':
448 style = RHorizontalGradient;
449 break;
450 default:
451 case 'D':
452 style = RDiagonalGradient;
453 break;
456 str = PLGetString(PLGetArrayElement(texture, 3));
457 str2rcolor(rc, str, &rcolor);
458 str = PLGetString(PLGetArrayElement(texture, 4));
459 str2rcolor(rc, str, &rcolor2);
461 str = PLGetString(PLGetArrayElement(texture, 1));
463 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
464 timage = RLoadImage(rc, path, 0);
466 if (!timage) {
467 wwarning("could not load file '%s': %s", path,
468 RMessageForError(RErrorCode));
469 } else {
470 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
472 image = RMakeTiledImage(timage, width, height);
473 RDestroyImage(timage);
475 i = atoi(PLGetString(PLGetArrayElement(texture, 2)));
477 RCombineImagesWithOpaqueness(image, grad, i);
478 RDestroyImage(grad);
480 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='M') {
481 int style;
482 RColor **colors;
483 int i, j;
485 switch (toupper(type[1])) {
486 case 'V':
487 style = RVerticalGradient;
488 break;
489 case 'H':
490 style = RHorizontalGradient;
491 break;
492 default:
493 case 'D':
494 style = RDiagonalGradient;
495 break;
498 j = PLGetNumberOfElements(texture);
500 if (j > 0) {
501 colors = wmalloc(j * sizeof(RColor*));
503 for (i = 2; i < j; i++) {
504 str = PLGetString(PLGetArrayElement(texture, i));
505 colors[i-2] = wmalloc(sizeof(RColor));
506 str2rcolor(rc, str, colors[i-2]);
508 colors[i-2] = NULL;
510 image = RRenderMultiGradient(width, height, colors, style);
512 for (i = 0; colors[i]!=NULL; i++)
513 free(colors[i]);
514 free(colors);
516 } else if (strcasecmp(&type[1], "pixmap")==0) {
517 RImage *timage = NULL;
518 char *path;
519 RColor color;
521 str = PLGetString(PLGetArrayElement(texture, 1));
523 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
524 if (path)
525 timage = RLoadImage(rc, path, 0);
527 if (!timage) {
528 wwarning("could not load file '%s': %s", path ? path : str,
529 RMessageForError(RErrorCode));
530 } else {
531 str = PLGetString(PLGetArrayElement(texture, 2));
532 str2rcolor(rc, str, &color);
534 switch (toupper(type[0])) {
535 case 'T':
536 image = RMakeTiledImage(timage, width, height);
537 RDestroyImage(timage);
538 timage = image;
539 break;
540 case 'C':
541 image = RMakeCenteredImage(timage, width, height, &color);
542 RDestroyImage(timage);
543 timage = image;
544 break;
545 case 'S':
546 case 'M':
547 image = RScaleImage(timage, width, height);
548 RDestroyImage(timage);
549 timage = image;
550 break;
554 free(path);
557 if (!image)
558 return None;
560 if (path) {
561 dumpRImage(path, image);
564 if (border < 0) {
565 if (border == RESIZEBAR_BEVEL) {
566 drawResizebarBevel(image);
567 } else if (border == MENU_BEVEL) {
568 drawMenuBevel(image);
569 RBevelImage(image, RBEV_RAISED2);
571 } else if (border) {
572 RBevelImage(image, border);
575 RConvertImage(rc, image, &pixmap);
576 RDestroyImage(image);
578 return pixmap;
582 static Pixmap
583 renderMenu(_Panel *panel, proplist_t texture, int width, int iheight)
585 WMScreen *scr = WMWidgetScreen(panel->win);
586 Display *dpy = WMScreenDisplay(scr);
587 Pixmap pix, tmp;
588 GC gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
589 int i;
591 switch (panel->menuStyle) {
592 case MSTYLE_NORMAL:
593 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
595 pix = XCreatePixmap(dpy, tmp, width, iheight*4, WMScreenDepth(scr));
596 for (i = 0; i < 4; i++) {
597 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight,
598 0, iheight*i);
600 XFreePixmap(dpy, tmp);
601 break;
602 case MSTYLE_SINGLE:
603 pix = renderTexture(scr, texture, width, iheight*4, NULL, MENU_BEVEL);
604 break;
605 case MSTYLE_FLAT:
606 pix = renderTexture(scr, texture, width, iheight*4, NULL, RBEV_RAISED2);
607 break;
609 XFreeGC(dpy, gc);
611 return pix;
615 static void
616 updatePreviewBox(_Panel *panel, int elements)
618 WMScreen *scr = WMWidgetScreen(panel->win);
619 Display *dpy = WMScreenDisplay(scr);
620 /* RContext *rc = WMScreenRContext(scr);*/
621 int refresh = 0;
622 Pixmap pix;
623 GC gc;
624 WMListItem *item;
625 TextureListItem *titem;
627 gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
630 if (!panel->preview) {
631 WMColor *color;
633 panel->preview = XCreatePixmap(dpy, WMWidgetXID(panel->win),
634 240-4, 215-4, WMScreenDepth(scr));
636 color = WMGrayColor(scr);
637 XFillRectangle(dpy, panel->preview, WMColorGC(color),
638 0, 0, 240-4, 215-4);
639 WMReleaseColor(color);
641 refresh = -1;
644 if (elements & FTITLE) {
645 item = WMGetListItem(panel->texLs, panel->textureIndex[0]);
646 titem = (TextureListItem*)item->clientData;
648 pix = renderTexture(scr, titem->prop, 190, 20, NULL, RBEV_RAISED2);
650 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 210, 20, 30, 10);
652 XFreePixmap(dpy, pix);
654 if (elements & UTITLE) {
655 item = WMGetListItem(panel->texLs, panel->textureIndex[1]);
656 titem = (TextureListItem*)item->clientData;
658 pix = renderTexture(scr, titem->prop, 190, 20, NULL, RBEV_RAISED2);
660 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 210, 20, 30, 40);
662 XFreePixmap(dpy, pix);
664 if (elements & OTITLE) {
665 item = WMGetListItem(panel->texLs, panel->textureIndex[2]);
666 titem = (TextureListItem*)item->clientData;
668 pix = renderTexture(scr, titem->prop, 190, 20, NULL, RBEV_RAISED2);
670 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 210, 20, 30, 70);
672 XFreePixmap(dpy, pix);
674 if (elements & RESIZEBAR) {
675 item = WMGetListItem(panel->texLs, panel->textureIndex[3]);
676 titem = (TextureListItem*)item->clientData;
678 pix = renderTexture(scr, titem->prop, 190, 9, NULL, RESIZEBAR_BEVEL);
680 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 210, 20, 30, 100);
682 XFreePixmap(dpy, pix);
684 if (elements & MTITLE) {
685 item = WMGetListItem(panel->texLs, panel->textureIndex[4]);
686 titem = (TextureListItem*)item->clientData;
688 pix = renderTexture(scr, titem->prop, 90, 20, NULL, RBEV_RAISED2);
690 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 90, 20, 30, 120);
692 XFreePixmap(dpy, pix);
694 if (elements & MITEM) {
695 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
696 titem = (TextureListItem*)item->clientData;
698 pix = renderMenu(panel, titem->prop, 90, 18);
700 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 90, 18*4, 30, 140);
702 XFreePixmap(dpy, pix);
704 if (elements & (MITEM|MTITLE)) {
705 XDrawLine(dpy, panel->preview, gc, 29, 120, 29, 120+18*4+20);
706 XDrawLine(dpy, panel->preview, gc, 29, 119, 119, 119);
709 if (elements & ICON) {
710 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
711 titem = (TextureListItem*)item->clientData;
713 pix = renderTexture(scr, titem->prop, 64, 64, NULL,
714 titem->ispixmap ? 0 : RBEV_RAISED3);
716 XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 64, 64, 155, 130);
718 XFreePixmap(dpy, pix);
721 if (refresh < 0) {
722 WMPixmap *p;
723 p = WMCreatePixmapFromXPixmaps(scr, panel->preview, None,
724 240-4, 215-4, WMScreenDepth(scr));
726 WMSetLabelImage(panel->prevL, p);
727 WMReleasePixmap(p);
728 } else {
729 WMRedisplayWidget(panel->prevL);
732 XFreeGC(dpy, gc);
738 static void
739 cancelNewTexture(void *data)
741 _Panel *panel = (_Panel*)data;
743 HideTexturePanel(panel->texturePanel);
749 static char*
750 makeFileName(char *prefix)
752 char *fname;
754 fname = wstrdup(prefix);
756 while (access(fname, F_OK)==0) {
757 char buf[30];
759 free(fname);
760 sprintf(buf, "%08lx.cache", time(NULL));
761 fname = wstrappend(prefix, buf);
764 return fname;
770 static void
771 okNewTexture(void *data)
773 _Panel *panel = (_Panel*)data;
774 WMListItem *item;
775 char *name;
776 char *str;
777 proplist_t prop;
778 TextureListItem *titem;
779 WMScreen *scr = WMWidgetScreen(panel->win);
781 titem = wmalloc(sizeof(TextureListItem));
782 memset(titem, 0, sizeof(TextureListItem));
784 HideTexturePanel(panel->texturePanel);
786 name = GetTexturePanelTextureName(panel->texturePanel);
788 prop = GetTexturePanelTexture(panel->texturePanel);
790 str = PLGetDescription(prop);
792 titem->title = name;
793 titem->prop = prop;
794 titem->texture = str;
795 titem->selectedFor = 0;
797 titem->ispixmap = isPixmap(prop);
799 titem->path = makeFileName(panel->fprefix);
800 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT,
801 titem->path, 0);
803 item = WMAddListItem(panel->texLs, "");
804 item->clientData = titem;
806 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
810 static void
811 okEditTexture(void *data)
813 _Panel *panel = (_Panel*)data;
814 WMListItem *item;
815 char *name;
816 char *str;
817 proplist_t prop;
818 TextureListItem *titem;
820 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
821 titem = (TextureListItem*)item->clientData;
823 HideTexturePanel(panel->texturePanel);
825 if (titem->current) {
826 name = GetTexturePanelTextureName(panel->texturePanel);
828 free(titem->title);
829 titem->title = name;
832 prop = GetTexturePanelTexture(panel->texturePanel);
834 str = PLGetDescription(prop);
836 PLRelease(titem->prop);
837 titem->prop = prop;
839 titem->ispixmap = isPixmap(prop);
841 free(titem->texture);
842 titem->texture = str;
844 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
845 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
846 TEXPREV_WIDTH, TEXPREV_HEIGHT,
847 titem->path, 0);
849 WMRedisplayWidget(panel->texLs);
851 if (titem->selectedFor)
852 updatePreviewBox(panel, titem->selectedFor);
854 changePage(panel->secP, panel);
859 static void
860 editTexture(WMWidget *w, void *data)
862 _Panel *panel = (_Panel*)data;
863 WMListItem *item;
864 TextureListItem *titem;
866 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
867 titem = (TextureListItem*)item->clientData;
869 SetTexturePanelPixmapPath(panel->texturePanel,
870 GetObjectForKey("PixmapPath"));
872 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
874 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
875 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
877 ShowTexturePanel(panel->texturePanel);
882 static void
883 newTexture(WMWidget *w, void *data)
885 _Panel *panel = (_Panel*)data;
887 SetTexturePanelPixmapPath(panel->texturePanel,
888 GetObjectForKey("PixmapPath"));
890 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
892 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
894 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
896 ShowTexturePanel(panel->texturePanel);
901 static void
902 deleteTexture(WMWidget *w, void *data)
904 _Panel *panel = (_Panel*)data;
905 WMListItem *item;
906 TextureListItem *titem;
907 int row;
908 int section;
910 section = WMGetPopUpButtonSelectedItem(panel->secP);
911 row = WMGetListSelectedItemRow(panel->texLs);
912 item = WMGetListItem(panel->texLs, row);
913 titem = (TextureListItem*)item->clientData;
915 if (titem->selectedFor & (1 << section)) {
916 TextureListItem *titem2;
918 panel->textureIndex[section] = section;
919 item = WMGetListItem(panel->texLs, section);
920 titem2 = (TextureListItem*)item->clientData;
921 titem2->selectedFor |= 1 << section;
924 free(titem->title);
925 free(titem->texture);
926 PLRelease(titem->prop);
927 if (titem->path) {
928 if (remove(titem->path) < 0 && errno != ENOENT) {
929 wsyserror("could not remove file %s", titem->path);
931 free(titem->path);
934 free(titem);
936 WMRemoveListItem(panel->texLs, row);
937 WMSetButtonEnabled(panel->delB, False);
943 static void
944 extractTexture(WMWidget *w, void *data)
946 _Panel *panel = (_Panel*)data;
947 char *path;
948 WMOpenPanel *opanel;
949 WMScreen *scr = WMWidgetScreen(w);
951 opanel = WMGetOpenPanel(scr);
952 WMSetFilePanelCanChooseDirectories(opanel, False);
953 WMSetFilePanelCanChooseFiles(opanel, True);
955 if (WMRunModalFilePanelForDirectory(opanel, panel->win, wgethomedir(),
956 _("Select File"), NULL)) {
957 path = WMGetFilePanelFileName(opanel);
959 OpenExtractPanelFor(panel, path);
961 free(path);
966 static void
967 changePage(WMWidget *w, void *data)
969 _Panel *panel = (_Panel*)data;
970 int section;
971 WMListItem *item;
972 TextureListItem *titem;
973 WMScreen *scr = WMWidgetScreen(w);
974 RContext *rc = WMScreenRContext(scr);
975 static WMPoint positions[] = {
976 {5, 10},
977 {5, 40},
978 {5, 70},
979 {5, 100},
980 {5, 120},
981 {5, 160},
982 {130, 150}
985 section = WMGetPopUpButtonSelectedItem(panel->secP);
987 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
989 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
991 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
993 titem = (TextureListItem*)item->clientData;
996 WMColor *color;
998 color = WMGrayColor(scr);
999 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1000 positions[panel->oldsection].x,
1001 positions[panel->oldsection].y, 22, 22);
1002 WMReleaseColor(color);
1004 panel->oldsection = section;
1005 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1006 positions[section].y);
1008 WMRedisplayWidget(panel->prevL);
1013 static void
1014 previewClick(XEvent *event, void *clientData)
1016 _Panel *panel = (_Panel*)clientData;
1017 int i;
1018 static WMRect parts[] = {
1019 {{30,10},{190, 20}},
1020 {{30,40},{190,20}},
1021 {{30,70},{190,20}},
1022 {{30,100},{190,9}},
1023 {{30,120},{90,20}},
1024 {{30,140},{90,18*4}},
1025 {{155,130},{64,64}}
1028 for (i = 0; i < 7; i++) {
1029 if (event->xbutton.x >= parts[i].pos.x
1030 && event->xbutton.y >= parts[i].pos.y
1031 && event->xbutton.x < parts[i].pos.x + parts[i].size.width
1032 && event->xbutton.y < parts[i].pos.y + parts[i].size.height) {
1034 WMSetPopUpButtonSelectedItem(panel->secP, i);
1035 changePage(panel->secP, panel);
1036 return;
1042 static void
1043 textureClick(WMWidget *w, void *data)
1045 _Panel *panel = (_Panel*)data;
1046 int i;
1047 WMListItem *item;
1048 TextureListItem *titem;
1050 i = WMGetListSelectedItemRow(panel->texLs);
1052 item = WMGetListItem(panel->texLs, i);
1054 titem = (TextureListItem*)item->clientData;
1056 if (titem->current) {
1057 WMSetButtonEnabled(panel->delB, False);
1058 } else {
1059 WMSetButtonEnabled(panel->delB, True);
1065 static void
1066 textureDoubleClick(WMWidget *w, void *data)
1068 _Panel *panel = (_Panel*)data;
1069 int i, section;
1070 WMListItem *item;
1071 TextureListItem *titem;
1073 /* unselect old texture */
1074 section = WMGetPopUpButtonSelectedItem(panel->secP);
1076 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1077 titem = (TextureListItem*)item->clientData;
1078 titem->selectedFor &= ~(1 << section);
1080 /* select new texture */
1081 i = WMGetListSelectedItemRow(panel->texLs);
1083 item = WMGetListItem(panel->texLs, i);
1085 titem = (TextureListItem*)item->clientData;
1087 titem->selectedFor |= 1<<section;
1089 panel->textureIndex[section] = i;
1091 WMRedisplayWidget(panel->texLs);
1093 updatePreviewBox(panel, 1<<section);
1099 static void
1100 paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
1101 WMRect *rect)
1103 _Panel *panel = (_Panel*)WMGetHangedData(lPtr);
1104 WMScreen *scr = WMWidgetScreen(lPtr);
1105 int width, height, x, y;
1106 Display *dpy = WMScreenDisplay(scr);
1107 WMColor *white = WMWhiteColor(scr);
1108 WMListItem *item;
1109 WMColor *black = WMBlackColor(scr);
1110 TextureListItem *titem;
1112 width = rect->size.width;
1113 height = rect->size.height;
1114 x = rect->pos.x;
1115 y = rect->pos.y;
1117 if (state & WLDSSelected)
1118 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
1119 else
1120 XClearArea(dpy, d, x, y, width, height, False);
1122 item = WMGetListItem(lPtr, index);
1123 titem = (TextureListItem*)item->clientData;
1125 if (titem->preview)
1126 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0, TEXPREV_WIDTH,
1127 TEXPREV_HEIGHT, x + 5, y + 5);
1129 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1130 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1131 else if (titem->selectedFor)
1132 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1134 WMDrawString(scr, d, WMColorGC(black), panel->boldFont,
1135 x + TEXPREV_WIDTH + 22, y + 2, titem->title,
1136 strlen(titem->title));
1138 WMDrawString(scr, d, WMColorGC(black), panel->smallFont,
1139 x + TEXPREV_WIDTH + 14, y + 18, titem->texture,
1140 strlen(titem->texture));
1143 WMReleaseColor(white);
1144 WMReleaseColor(black);
1149 static Pixmap
1150 loadRImage(WMScreen *scr, char *path)
1152 FILE *f;
1153 RImage *image;
1154 int w, h, d;
1155 int i;
1156 Pixmap pixmap;
1158 f = fopen(path, "r");
1159 if (!f)
1160 return None;
1162 fscanf(f, "%02x%02x%1x", &w, &h, &d);
1164 image = RCreateImage(w, h, d == 4);
1165 for (i = 0; i < d; i++) {
1166 fread(image->data[i], 1, w*h, f);
1168 fclose(f);
1170 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1171 RDestroyImage(image);
1173 return pixmap;
1178 static void
1179 fillTextureList(WMList *lPtr)
1181 proplist_t textureList;
1182 proplist_t texture;
1183 WMUserDefaults *udb = WMGetStandardUserDefaults();
1184 int i;
1185 TextureListItem *titem;
1186 WMScreen *scr = WMWidgetScreen(lPtr);
1188 textureList = WMGetUDObjectForKey(udb, "TextureList");
1189 if (!textureList)
1190 return;
1192 for (i = 0; i < PLGetNumberOfElements(textureList); i++) {
1193 WMListItem *item;
1195 texture = PLGetArrayElement(textureList, i);
1197 titem = wmalloc(sizeof(TextureListItem));
1198 memset(titem, 0, sizeof(TextureListItem));
1200 titem->title = wstrdup(PLGetString(PLGetArrayElement(texture, 0)));
1201 titem->prop = PLRetain(PLGetArrayElement(texture, 1));
1202 titem->texture = PLGetDescription(titem->prop);
1203 titem->selectedFor = 0;
1204 titem->path = wstrdup(PLGetString(PLGetArrayElement(texture, 2)));
1206 titem->preview = loadRImage(scr, titem->path);
1207 if (!titem->preview) {
1208 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH,
1209 TEXPREV_HEIGHT, NULL, 0);
1211 item = WMAddListItem(lPtr, "");
1212 item->clientData = titem;
1217 static void
1218 menuStyleCallback(WMWidget *self, void *data)
1220 _Panel *panel = (_Panel*)data;
1222 if (self == panel->mstyB[0]) {
1223 panel->menuStyle = MSTYLE_NORMAL;
1224 updatePreviewBox(panel, MITEM);
1226 } else if (self == panel->mstyB[1]) {
1227 panel->menuStyle = MSTYLE_SINGLE;
1228 updatePreviewBox(panel, MITEM);
1230 } else if (self == panel->mstyB[2]) {
1231 panel->menuStyle = MSTYLE_FLAT;
1232 updatePreviewBox(panel, MITEM);
1237 static void
1238 createPanel(Panel *p)
1240 _Panel *panel = (_Panel*)p;
1241 WMFont *font;
1242 WMScreen *scr = WMWidgetScreen(panel->win);
1243 WMTabViewItem *item;
1244 int i;
1245 char *tmp;
1246 Bool ok = True;
1248 panel->fprefix = wstrappend(wusergnusteppath(), "/.AppInfo");
1250 if (access(panel->fprefix, F_OK)!=0) {
1251 if (mkdir(panel->fprefix, 0755) < 0) {
1252 wsyserror(panel->fprefix);
1253 ok = False;
1256 if (ok) {
1257 tmp = wstrappend(panel->fprefix, "/WPrefs/");
1258 free(panel->fprefix);
1259 panel->fprefix = tmp;
1260 if (access(panel->fprefix, F_OK)!=0) {
1261 if (mkdir(panel->fprefix, 0755) < 0) {
1262 wsyserror(panel->fprefix);
1267 panel->smallFont = WMSystemFontOfSize(scr, 10);
1268 panel->normalFont = WMSystemFontOfSize(scr, 12);
1269 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1271 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1272 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1273 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1275 panel->frame = WMCreateFrame(panel->win);
1276 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
1277 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
1279 /* preview box */
1280 panel->prevL = WMCreateLabel(panel->frame);
1281 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1282 WMMoveWidget(panel->prevL, 15, 10);
1283 WMSetLabelRelief(panel->prevL, WRSunken);
1284 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1286 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask,
1287 previewClick, panel);
1290 /* tabview */
1292 panel->tabv = WMCreateTabView(panel->frame);
1293 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1294 WMMoveWidget(panel->tabv, 265, 10);
1296 /*** texture list ***/
1298 panel->texF = WMCreateFrame(panel->frame);
1299 WMSetFrameRelief(panel->texF, WRFlat);
1301 item = WMCreateTabViewItemWithIdentifier(0);
1302 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1303 WMSetTabViewItemLabel(item, _("Texture"));
1305 WMAddItemInTabView(panel->tabv, item);
1308 panel->secP = WMCreatePopUpButton(panel->texF);
1309 WMResizeWidget(panel->secP, 228, 20);
1310 WMMoveWidget(panel->secP, 7, 7);
1311 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1312 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1313 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1314 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1315 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1316 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1317 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1318 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1319 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1321 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1323 panel->texLs = WMCreateList(panel->texF);
1324 WMResizeWidget(panel->texLs, 165, 155);
1325 WMMoveWidget(panel->texLs, 70, 33);
1326 WMSetListUserDrawItemHeight(panel->texLs, 35);
1327 WMSetListUserDrawProc(panel->texLs, paintListItem);
1328 WMHangData(panel->texLs, panel);
1329 WMSetListAction(panel->texLs, textureClick, panel);
1330 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1332 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1333 "for the selected item."),
1334 WMWidgetView(panel->texLs));
1336 /* command buttons */
1338 font = WMSystemFontOfSize(scr, 10);
1341 panel->newB = WMCreateCommandButton(panel->texF);
1342 WMResizeWidget(panel->newB, 57, 39);
1343 WMMoveWidget(panel->newB, 7, 33);
1344 WMSetButtonFont(panel->newB, font);
1345 WMSetButtonImagePosition(panel->newB, WIPAbove);
1346 WMSetButtonText(panel->newB, _("New"));
1347 WMSetButtonAction(panel->newB, newTexture, panel);
1348 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1350 WMSetBalloonTextForView(_("Create a new texture."),
1351 WMWidgetView(panel->newB));
1353 panel->ripB = WMCreateCommandButton(panel->texF);
1354 WMResizeWidget(panel->ripB, 57, 39);
1355 WMMoveWidget(panel->ripB, 7, 72);
1356 WMSetButtonFont(panel->ripB, font);
1357 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1358 WMSetButtonText(panel->ripB, _("Extract..."));
1359 WMSetButtonAction(panel->ripB, extractTexture, panel);
1360 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1362 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1363 WMWidgetView(panel->ripB));
1365 WMSetButtonEnabled(panel->ripB, False);
1367 panel->editB = WMCreateCommandButton(panel->texF);
1368 WMResizeWidget(panel->editB, 57, 39);
1369 WMMoveWidget(panel->editB, 7, 111);
1370 WMSetButtonFont(panel->editB, font);
1371 WMSetButtonImagePosition(panel->editB, WIPAbove);
1372 WMSetButtonText(panel->editB, _("Edit"));
1373 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1374 WMSetButtonAction(panel->editB, editTexture, panel);
1375 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1376 WMWidgetView(panel->editB));
1378 panel->delB = WMCreateCommandButton(panel->texF);
1379 WMResizeWidget(panel->delB, 57, 38);
1380 WMMoveWidget(panel->delB, 7, 150);
1381 WMSetButtonFont(panel->delB, font);
1382 WMSetButtonImagePosition(panel->delB, WIPAbove);
1383 WMSetButtonText(panel->delB, _("Delete"));
1384 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1385 WMSetButtonEnabled(panel->delB, False);
1386 WMSetButtonAction(panel->delB, deleteTexture, panel);
1387 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1388 WMWidgetView(panel->delB));
1390 WMReleaseFont(font);
1392 WMMapSubwidgets(panel->texF);
1394 /*** colors ***/
1395 panel->colF = WMCreateFrame(panel->frame);
1396 WMSetFrameRelief(panel->colF, WRFlat);
1398 item = WMCreateTabViewItemWithIdentifier(1);
1399 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1400 WMSetTabViewItemLabel(item, _("Color"));
1402 WMAddItemInTabView(panel->tabv, item);
1405 panel->colP = WMCreatePopUpButton(panel->colF);
1406 WMResizeWidget(panel->colP, 228, 20);
1407 WMMoveWidget(panel->colP, 7, 7);
1408 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1409 WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1410 WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1412 /* WMSetPopUpButtonAction(panel->colP, changePage, panel);
1415 panel->colW = WMCreateColorWell(panel->colF);
1416 WMResizeWidget(panel->colW, 65, 50);
1417 WMMoveWidget(panel->colW, 40, 75);
1419 for (i = 0; i < 3; i++) {
1420 int j;
1421 for (j = 0; j < 5; j++) {
1422 panel->sampW[i] = WMCreateColorWell(panel->colF);
1423 WMResizeWidget(panel->sampW[i], 28, 28);
1424 WMMoveWidget(panel->sampW[i], 140 + i*28, 40 + j*28);
1425 WSetColorWellBordered(panel->sampW[i], False);
1429 WMMapSubwidgets(panel->colF);
1431 /*** options ***/
1432 panel->optF = WMCreateFrame(panel->frame);
1433 WMSetFrameRelief(panel->optF, WRFlat);
1435 item = WMCreateTabViewItemWithIdentifier(2);
1436 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1437 WMSetTabViewItemLabel(item, _("Options"));
1439 WMAddItemInTabView(panel->tabv, item);
1441 panel->mstyF = WMCreateFrame(panel->optF);
1442 WMResizeWidget(panel->mstyF, 215, 85);
1443 WMMoveWidget(panel->mstyF, 15, 10);
1444 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1446 for (i = 0; i < 3; i++) {
1447 WMPixmap *icon;
1448 char *path;
1450 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1451 WMResizeWidget(panel->mstyB[i], 54, 54);
1452 WMMoveWidget(panel->mstyB[i], 15 + i*65, 20);
1453 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1454 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1455 switch (i) {
1456 case 0:
1457 path = LocateImage(MSTYLE1_FILE);
1458 break;
1459 case 1:
1460 path = LocateImage(MSTYLE2_FILE);
1461 break;
1462 case 2:
1463 path = LocateImage(MSTYLE3_FILE);
1464 break;
1466 if (path) {
1467 icon = WMCreatePixmapFromFile(scr, path);
1468 if (icon) {
1469 WMSetButtonImage(panel->mstyB[i], icon);
1470 WMReleasePixmap(icon);
1471 } else {
1472 wwarning(_("could not load icon file %s"), path);
1474 free(path);
1477 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
1478 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
1480 WMMapSubwidgets(panel->mstyF);
1482 WMMapSubwidgets(panel->optF);
1484 /**/
1486 WMRealizeWidget(panel->frame);
1487 WMMapSubwidgets(panel->frame);
1489 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1491 showData(panel);
1493 changePage(panel->secP, panel);
1495 fillTextureList(panel->texLs);
1497 panel->texturePanel = CreateTexturePanel(panel->win);
1502 static void
1503 setupTextureFor(WMList *list, char *key, char *defValue, char *title,
1504 int index)
1506 WMListItem *item;
1507 TextureListItem *titem;
1509 titem = wmalloc(sizeof(TextureListItem));
1510 memset(titem, 0, sizeof(TextureListItem));
1512 titem->title = wstrdup(title);
1513 titem->prop = GetObjectForKey(key);
1514 if (!titem->prop) {
1515 titem->prop = PLGetProplistWithDescription(defValue);
1516 } else {
1517 PLRetain(titem->prop);
1519 titem->texture = PLGetDescription((proplist_t)titem->prop);
1520 titem->current = 1;
1521 titem->selectedFor = 1<<index;
1523 titem->ispixmap = isPixmap(titem->prop);
1525 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop,
1526 TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1528 item = WMAddListItem(list, "");
1529 item->clientData = titem;
1534 static void
1535 showData(_Panel *panel)
1537 int i = 0;
1538 char *str;
1540 str = GetStringForKey("MenuStyle");
1541 if (str && strcasecmp(str, "flat")==0) {
1542 panel->menuStyle = MSTYLE_FLAT;
1543 } else if (str && strcasecmp(str, "singletexture")==0) {
1544 panel->menuStyle = MSTYLE_SINGLE;
1545 } else {
1546 panel->menuStyle = MSTYLE_NORMAL;
1549 setupTextureFor(panel->texLs, "FTitleBack", "(solid, black)",
1550 "[Focused]", i);
1551 panel->textureIndex[i] = i++;
1553 setupTextureFor(panel->texLs, "UTitleBack", "(solid, gray)",
1554 "[Unfocused]", i);
1555 panel->textureIndex[i] = i++;
1557 setupTextureFor(panel->texLs, "PTitleBack", "(solid, \"#616161\")",
1558 "[Owner of Focused]", i);
1559 panel->textureIndex[i] = i++;
1561 setupTextureFor(panel->texLs, "ResizebarBack", "(solid, gray)",
1562 "[Resizebar]", i);
1563 panel->textureIndex[i] = i++;
1565 setupTextureFor(panel->texLs, "MenuTitleBack", "(solid, black)",
1566 "[Menu Title]", i);
1567 panel->textureIndex[i] = i++;
1569 setupTextureFor(panel->texLs, "MenuTextBack", "(solid, gray)",
1570 "[Menu Item]", i);
1571 panel->textureIndex[i] = i++;
1573 setupTextureFor(panel->texLs, "IconBack", "(solid, gray)", "[Icon]", i);
1574 panel->textureIndex[i] = i++;
1576 setupTextureFor(panel->texLs, "WorkspaceBack", "(solid, black)",
1577 "[Workspace]", i);
1578 panel->textureIndex[i] = i++;
1581 updatePreviewBox(panel, EVERYTHING);
1583 for (i = 0; i < 3; i++) {
1584 WMSetButtonSelected(panel->mstyB[i], i==panel->menuStyle);
1590 static void
1591 storeData(_Panel *panel)
1593 TextureListItem *titem;
1594 WMListItem *item;
1596 item = WMGetListItem(panel->texLs, panel->textureIndex[0]);
1597 titem = (TextureListItem*)item->clientData;
1598 SetObjectForKey(titem->prop, "FTitleBack");
1600 item = WMGetListItem(panel->texLs, panel->textureIndex[1]);
1601 titem = (TextureListItem*)item->clientData;
1602 SetObjectForKey(titem->prop, "UTitleBack");
1604 item = WMGetListItem(panel->texLs, panel->textureIndex[2]);
1605 titem = (TextureListItem*)item->clientData;
1606 SetObjectForKey(titem->prop, "PTitleBack");
1608 item = WMGetListItem(panel->texLs, panel->textureIndex[3]);
1609 titem = (TextureListItem*)item->clientData;
1610 SetObjectForKey(titem->prop, "ResizebarBack");
1612 item = WMGetListItem(panel->texLs, panel->textureIndex[4]);
1613 titem = (TextureListItem*)item->clientData;
1614 SetObjectForKey(titem->prop, "MenuTitleBack");
1616 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
1617 titem = (TextureListItem*)item->clientData;
1618 SetObjectForKey(titem->prop, "MenuTextBack");
1620 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
1621 titem = (TextureListItem*)item->clientData;
1622 SetObjectForKey(titem->prop, "IconBack");
1624 switch (panel->menuStyle) {
1625 case MSTYLE_SINGLE:
1626 SetStringForKey("singletexture", "MenuStyle");
1627 break;
1628 case MSTYLE_FLAT:
1629 SetStringForKey("flat", "MenuStyle");
1630 break;
1631 default:
1632 case MSTYLE_NORMAL:
1633 SetStringForKey("normal", "MenuStyle");
1634 break;
1639 static void
1640 prepareForClose(_Panel *panel)
1642 proplist_t textureList;
1643 proplist_t texture;
1644 int i;
1645 TextureListItem *titem;
1646 WMListItem *item;
1647 WMUserDefaults *udb = WMGetStandardUserDefaults();
1649 textureList = PLMakeArrayFromElements(NULL, NULL);
1651 /* store list of textures */
1652 for (i = 7; i < WMGetListNumberOfRows(panel->texLs); i++) {
1653 item = WMGetListItem(panel->texLs, i);
1654 titem = (TextureListItem*)item->clientData;
1656 texture = PLMakeArrayFromElements(PLMakeString(titem->title),
1657 PLRetain(titem->prop),
1658 PLMakeString(titem->path),
1659 NULL);
1661 PLAppendArrayElement(textureList, texture);
1664 WMSetUDObjectForKey(udb, textureList, "TextureList");
1665 PLRelease(textureList);
1667 WMSynchronizeUserDefaults(udb);
1672 Panel*
1673 InitAppearance(WMScreen *scr, WMWindow *win)
1675 _Panel *panel;
1677 panel = wmalloc(sizeof(_Panel));
1678 memset(panel, 0, sizeof(_Panel));
1680 panel->sectionName = _("Appearance Preferences");
1682 panel->description = _("Background texture configuration for windows,\n"
1683 "menus and icons.");
1685 panel->win = win;
1687 panel->callbacks.createWidgets = createPanel;
1688 panel->callbacks.updateDomain = storeData;
1689 panel->callbacks.prepareForClose = prepareForClose;
1691 AddSection(panel, ICON_FILE);
1693 return panel;
1698 /****************************************************************************/
1702 typedef struct ExtractPanel {
1703 WMWindow *win;
1705 WMLabel *label;
1706 WMList *list;
1708 WMButton *closeB;
1709 WMButton *extrB;
1710 } ExtractPanel;
1714 static void
1715 OpenExtractPanelFor(_Panel *panel, char *path)
1717 ExtractPanel *epanel;
1718 WMColor *color;
1719 WMFont *font;
1720 WMScreen *scr = WMWidgetScreen(panel->win);
1722 epanel = wmalloc(sizeof(ExtractPanel));
1723 epanel->win = WMCreatePanelWithStyleForWindow(panel->win, "extract",
1724 WMTitledWindowMask
1725 |WMClosableWindowMask);
1726 WMResizeWidget(epanel->win, 245, 250);
1727 WMSetWindowTitle(epanel->win, _("Extract Texture"));
1729 epanel->label = WMCreateLabel(epanel->win);
1730 WMResizeWidget(epanel->label, 225, 18);
1731 WMMoveWidget(epanel->label, 10, 10);
1732 WMSetLabelTextAlignment(epanel->label, WACenter);
1733 WMSetLabelRelief(epanel->label, WRSunken);
1735 color = WMDarkGrayColor(scr);
1736 WMSetWidgetBackgroundColor(epanel->label, color);
1737 WMReleaseColor(color);
1739 color = WMWhiteColor(scr);
1740 WMSetLabelTextColor(epanel->label, color);
1741 WMReleaseColor(color);
1743 font = WMBoldSystemFontOfSize(scr, 12);
1744 WMSetLabelFont(epanel->label, font);
1745 WMReleaseFont(font);
1747 WMSetLabelText(epanel->label, _("Textures"));
1749 epanel->list = WMCreateList(epanel->win);
1750 WMResizeWidget(epanel->list, 225, 165);
1751 WMMoveWidget(epanel->list, 10, 30);
1755 epanel->closeB = WMCreateCommandButton(epanel->win);
1756 WMResizeWidget(epanel->closeB, 74, 24);
1757 WMMoveWidget(epanel->closeB, 165, 215);
1758 WMSetButtonText(epanel->closeB, _("Close"));
1760 epanel->extrB = WMCreateCommandButton(epanel->win);
1761 WMResizeWidget(epanel->extrB, 74, 24);
1762 WMMoveWidget(epanel->extrB, 80, 215);
1763 WMSetButtonText(epanel->extrB, _("Extract"));
1765 WMMapSubwidgets(epanel->win);
1768 /* take textures from file */
1772 WMRealizeWidget(epanel->win);
1774 WMMapWidget(epanel->win);