- Fixed crashing bug in menu.c
[wmaker-crm.git] / WPrefs.app / Appearance.c
blob22f98fd429e81799972978af9b8e6c122e0e82d1
1 /* Apperance.c- color/texture for titlebar etc.
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1999-2003 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 WMBox *box;
42 char *sectionName;
44 char *description;
46 CallbackRec callbacks;
48 WMWidget *parent;
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;
70 WMColor *colors[14];
72 WMColorWell *colW;
74 WMColorWell *sampW[24];
76 /* options */
77 WMFrame *optF;
79 WMFrame *mstyF;
80 WMButton *mstyB[3];
82 WMFrame *taliF;
83 WMButton *taliB[3];
85 /* root bg */
86 WMFrame *bgF;
88 WMLabel *bgprevL;
89 WMButton *selbgB;
91 WMPopUpButton *modeB[3];
93 /* */
95 int textureIndex[8];
97 WMFont *smallFont;
98 WMFont *normalFont;
99 WMFont *boldFont;
101 TexturePanel *texturePanel;
103 WMPixmap *onLed;
104 WMPixmap *offLed;
105 WMPixmap *hand;
107 int oldsection;
108 int oldcsection;
110 char oldTabItem;
112 char menuStyle;
114 char titleAlignment;
116 Pixmap preview;
117 Pixmap previewNoText;
119 char *fprefix;
120 } _Panel;
123 typedef struct {
124 char *title;
125 char *texture;
126 WMPropList *prop;
127 Pixmap preview;
129 char *path;
131 char selectedFor;
132 unsigned current:1;
133 unsigned ispixmap:1;
134 } TextureListItem;
136 static void updateColorPreviewBox(_Panel *panel, int elements);
138 static void showData(_Panel *panel);
140 static void changePage(WMWidget *w, void *data);
142 static void changeColorPage(WMWidget *w, void *data);
144 static void OpenExtractPanelFor(_Panel *panel, char *path);
148 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView *tabView,
149 WMTabViewItem *item);
153 static WMTabViewDelegate tabviewDelegate = {
154 NULL,
155 NULL, /* didChangeNumberOfItems */
156 changedTabItem, /* didSelectItem */
157 NULL, /* shouldSelectItem */
158 NULL /* willSelectItem */
162 #define ICON_FILE "appearance"
164 #define TNEW_FILE "tnew"
165 #define TDEL_FILE "tdel"
166 #define TEDIT_FILE "tedit"
167 #define TEXTR_FILE "textr"
169 #define MSTYLE1_FILE "msty1"
170 #define MSTYLE2_FILE "msty2"
171 #define MSTYLE3_FILE "msty3"
174 /* XPM */
175 static char * blueled_xpm[] = {
176 "8 8 17 1",
177 " c None",
178 ". c #020204",
179 "+ c #16B6FC",
180 "@ c #176AFC",
181 "# c #163AFC",
182 "$ c #72D2FC",
183 "% c #224CF4",
184 "& c #76D6FC",
185 "* c #16AAFC",
186 "= c #CEE9FC",
187 "- c #229EFC",
188 "; c #164CFC",
189 "> c #FAFEFC",
190 ", c #2482FC",
191 "' c #1652FC",
192 ") c #1E76FC",
193 "! c #1A60FC",
194 " .... ",
195 " .=>-@. ",
196 ".=>$@@'.",
197 ".=$@!;;.",
198 ".!@*+!#.",
199 ".#'*+*,.",
200 " .@)@,. ",
201 " .... "};
204 /* XPM */
205 static char *blueled2_xpm[] = {
206 /* width height num_colors chars_per_pixel */
207 " 8 8 17 1",
208 /* colors */
209 ". c None",
210 "# c #090909",
211 "a c #4b63a4",
212 "b c #011578",
213 "c c #264194",
214 "d c #04338c",
215 "e c #989dac",
216 "f c #011a7c",
217 "g c #465c9c",
218 "h c #03278a",
219 "i c #6175ac",
220 "j c #011e74",
221 "k c #043a90",
222 "l c #042f94",
223 "m c #0933a4",
224 "n c #022184",
225 "o c #012998",
226 /* pixels */
227 "..####..",
228 ".#aimn#.",
229 "#aechnf#",
230 "#gchnjf#",
231 "#jndknb#",
232 "#bjdddl#",
233 ".#nono#.",
234 "..####.."
238 /* XPM */
239 static char * hand_xpm[] = {
240 "22 21 19 1",
241 " c None",
242 ". c #030305",
243 "+ c #7F7F7E",
244 "@ c #B5B5B6",
245 "# c #C5C5C6",
246 "$ c #969697",
247 "% c #FDFDFB",
248 "& c #F2F2F4",
249 "* c #E5E5E4",
250 "= c #ECECEC",
251 "- c #DCDCDC",
252 "; c #D2D2D0",
253 "> c #101010",
254 ", c #767674",
255 "' c #676767",
256 ") c #535355",
257 "! c #323234",
258 "~ c #3E3C56",
259 "{ c #333147",
260 " ",
261 " ..... ",
262 " ..+@##$. ",
263 " .%%%&@.......... ",
264 " .%*%%&#%%%%%%%%%$. ",
265 " .*#%%%%%%%%%&&&&==. ",
266 " .-%%%%%%%%%=*-;;;#$. ",
267 " .-%%%%%%%%&..>..... ",
268 " >-%%%%%%%%%*#+. ",
269 " >-%%%%%%%%%*@,. ",
270 " >#%%%%%%%%%*@'. ",
271 " >$&&%%%%%%=... ",
272 " .+@@;=&%%&;$,> ",
273 " .',$@####$+). ",
274 " .!',+$++,'. ",
275 " ..>>>>>. ",
276 " ",
277 " ~~{{{~~ ",
278 " {{{{{{{{{{{ ",
279 " ~~{{{~~ ",
280 " "};
284 static char *sampleColors[] = {
285 "black",
286 "#292929",
287 "#525252",
288 "#848484",
289 "#adadad",
290 "#d6d6d6",
291 "white",
292 "#d6d68c",
293 "#d6a57b",
294 "#8cd68c",
295 "#8cd6ce",
296 "#d68c8c",
297 "#8c9cd6",
298 "#bd86d6",
299 "#d68cbd",
300 "#d64a4a",
301 "#4a5ad6",
302 "#4ad6ce",
303 "#4ad65a",
304 "#ced64a",
305 "#d6844a",
306 "#8ad631",
307 "#ce29c6",
308 "#ce2973",
309 "black"
313 static char *textureOptions[] = {
314 "FTitleBack", "(solid, black)", "[Focused]",
315 "UTitleBack", "(solid, gray)", "[Unfocused]",
316 "PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
317 "ResizebarBack", "(solid, gray)", "[Resizebar]",
318 "MenuTitleBack", "(solid, black)", "[Menu Title]",
319 "MenuTextBack", "(solid, gray)", "[Menu Item]",
320 "IconBack", "(solid, gray)", "[Icon]"
324 #define RESIZEBAR_BEVEL -1
325 #define MENU_BEVEL -2
327 #define TEXPREV_WIDTH 40
328 #define TEXPREV_HEIGHT 24
331 #define MSTYLE_NORMAL 0
332 #define MSTYLE_SINGLE 1
333 #define MSTYLE_FLAT 2
336 #define FTITLE_COL (1<<0)
337 #define UTITLE_COL (1<<1)
338 #define OTITLE_COL (1<<2)
339 #define MTITLE_COL (1<<3)
340 #define MITEM_COL (1<<4)
341 #define MDISAB_COL (1<<5)
342 #define MHIGH_COL (1<<6)
343 #define MHIGHT_COL (1<<7)
344 #define ICONT_COL (1<<8)
345 #define ICONB_COL (1<<9)
346 #define CLIP_COL (1<<10)
347 #define CCLIP_COL (1<<11)
350 static char *colorOptions[] = {
351 "FTitleColor", "white",
352 "UTitleColor", "black",
353 "PTitleColor", "white",
354 "MenuTitleColor", "white",
355 "MenuTextColor", "black",
356 "MenuDisabledColor", "#616161",
357 "HighlightColor", "white",
358 "HighlightTextColor", "black",
359 "IconTitleColor", "white",
360 "IconTitleBack", "black",
361 "ClipTitleColor", "black",
362 "CClipTitleColor", "#454045"
368 static WMRect previewPositions[] = {
369 #define PFOCUSED 0
370 {{30,10},{190, 20}},
371 #define PUNFOCUSED 1
372 {{30,40},{190,20}},
373 #define POWNER 2
374 {{30,70},{190,20}},
375 #define PRESIZEBAR 3
376 {{30,100},{190,9}},
377 #define PMTITLE 4
378 {{30,120},{90,20}},
379 #define PMITEM 5
380 {{30,140},{90,20*4}},
381 #define PICON 6
382 {{155,130},{64,64}}
384 #define EVERYTHING 0xff
387 static WMRect previewColorPositions[] = {
388 {{30,10},{190, 20}},
389 {{30,40},{190,20}},
390 {{30,70},{190,20}},
391 {{30,120},{90,20}},
392 {{30,140},{90,20}},
393 {{30,160},{90,20}},
394 {{30,180},{90,20}},
395 {{30,200},{90,20}},
396 {{155,130},{64,64}},
397 {{155,130},{64,64}},
398 {{155,130},{64,64}},
399 {{155,130},{64,64}}
404 static void
405 str2rcolor(RContext *rc, char *name, RColor *color)
407 XColor xcolor;
409 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
411 color->alpha = 255;
412 color->red = xcolor.red >> 8;
413 color->green = xcolor.green >> 8;
414 color->blue = xcolor.blue >> 8;
418 static void
419 dumpRImage(char *path, RImage *image)
421 FILE *f;
422 int channels = (image->format == RRGBAFormat ? 4 : 3);
424 f = fopen(path, "wb");
425 if (!f) {
426 wsyserror(path);
427 return;
429 fprintf(f, "%02x%02x%1x", image->width, image->height, channels);
431 fwrite(image->data, 1, image->width * image->height * channels, f);
433 if (fclose(f) < 0) {
434 wsyserror(path);
440 static int
441 isPixmap(WMPropList *prop)
443 WMPropList *p;
444 char *s;
446 p = WMGetFromPLArray(prop, 0);
447 s = WMGetFromPLString(p);
448 if (strcasecmp(&s[1], "pixmap")==0)
449 return 1;
450 else
451 return 0;
455 /**********************************************************************/
457 static void
458 drawResizebarBevel(RImage *img)
460 RColor light;
461 RColor dark;
462 RColor black;
463 int width = img->width;
464 int height = img->height;
465 int cwidth = 28;
467 black.alpha = 255;
468 black.red = black.green = black.blue = 0;
470 light.alpha = 0;
471 light.red = light.green = light.blue = 80;
473 dark.alpha = 0;
474 dark.red = dark.green = dark.blue = 40;
476 ROperateLine(img, RSubtractOperation, 0, 0, width-1, 0, &dark);
477 ROperateLine(img, RAddOperation, 0, 1, width-1, 1, &light);
479 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height-1, &dark);
480 ROperateLine(img, RAddOperation, cwidth+1, 2, cwidth+1, height-1, &light);
482 ROperateLine(img, RSubtractOperation, width-cwidth-2, 2, width-cwidth-2,
483 height-1, &dark);
484 ROperateLine(img, RAddOperation, width-cwidth-1, 2, width-cwidth-1,
485 height-1, &light);
487 RDrawLine(img, 0, height-1, width-1, height-1, &black);
488 RDrawLine(img, 0, 0, 0, height-1, &black);
489 RDrawLine(img, width-1, 0, width-1, height-1, &black);
493 static void
494 drawMenuBevel(RImage *img)
496 RColor light, dark, mid;
497 int i;
498 int iheight = img->height / 4;
500 light.alpha = 0;
501 light.red = light.green = light.blue = 80;
503 dark.alpha = 255;
504 dark.red = dark.green = dark.blue = 0;
506 mid.alpha = 0;
507 mid.red = mid.green = mid.blue = 40;
509 for (i = 1; i < 4; i++) {
510 ROperateLine(img, RSubtractOperation, 0, i*iheight-2,
511 img->width-1, i*iheight-2, &mid);
513 RDrawLine(img, 0, i*iheight-1, img->width-1, i*iheight-1, &dark);
515 ROperateLine(img, RAddOperation, 1, i*iheight,
516 img->width-2, i*iheight, &light);
521 static Pixmap
522 renderTexture(WMScreen *scr, WMPropList *texture, int width, int height,
523 char *path, int border)
525 char *type;
526 RImage *image = NULL;
527 Pixmap pixmap;
528 RContext *rc = WMScreenRContext(scr);
529 char *str;
530 RColor rcolor;
533 type = WMGetFromPLString(WMGetFromPLArray(texture, 0));
535 if (strcasecmp(type, "solid")==0) {
537 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
539 str2rcolor(rc, str, &rcolor);
541 image = RCreateImage(width, height, False);
542 RClearImage(image, &rcolor);
543 } else if (strcasecmp(type, "igradient")==0) {
544 int t1, t2;
545 RColor c1[2], c2[2];
547 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
548 str2rcolor(rc, str, &c1[0]);
549 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
550 str2rcolor(rc, str, &c1[1]);
551 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
552 t1 = atoi(str);
554 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
555 str2rcolor(rc, str, &c2[0]);
556 str = WMGetFromPLString(WMGetFromPLArray(texture, 5));
557 str2rcolor(rc, str, &c2[1]);
558 str = WMGetFromPLString(WMGetFromPLArray(texture, 6));
559 t2 = atoi(str);
561 image = RRenderInterwovenGradient(width, height, c1, t1, c2, t2);
562 } else if (strcasecmp(&type[1], "gradient")==0) {
563 int style;
564 RColor rcolor2;
566 switch (toupper(type[0])) {
567 case 'V':
568 style = RVerticalGradient;
569 break;
570 case 'H':
571 style = RHorizontalGradient;
572 break;
573 default:
574 case 'D':
575 style = RDiagonalGradient;
576 break;
579 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
580 str2rcolor(rc, str, &rcolor);
581 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
582 str2rcolor(rc, str, &rcolor2);
584 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
585 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='T') {
586 int style;
587 RColor rcolor2;
588 int i;
589 RImage *grad, *timage;
590 char *path;
592 switch (toupper(type[1])) {
593 case 'V':
594 style = RVerticalGradient;
595 break;
596 case 'H':
597 style = RHorizontalGradient;
598 break;
599 default:
600 case 'D':
601 style = RDiagonalGradient;
602 break;
605 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
606 str2rcolor(rc, str, &rcolor);
607 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
608 str2rcolor(rc, str, &rcolor2);
610 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
612 if ((path=wfindfileinarray(GetObjectForKey("PixmapPath"), str))!=NULL)
613 timage = RLoadImage(rc, path, 0);
615 if (!path || !timage) {
616 wwarning("could not load file '%s': %s", path,
617 RMessageForError(RErrorCode));
618 } else {
619 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
621 image = RMakeTiledImage(timage, width, height);
622 RReleaseImage(timage);
624 i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
626 RCombineImagesWithOpaqueness(image, grad, i);
627 RReleaseImage(grad);
629 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='M') {
630 int style;
631 RColor **colors;
632 int i, j;
634 switch (toupper(type[1])) {
635 case 'V':
636 style = RVerticalGradient;
637 break;
638 case 'H':
639 style = RHorizontalGradient;
640 break;
641 default:
642 case 'D':
643 style = RDiagonalGradient;
644 break;
647 j = WMGetPropListItemCount(texture);
649 if (j > 0) {
650 colors = wmalloc(j * sizeof(RColor*));
652 for (i = 2; i < j; i++) {
653 str = WMGetFromPLString(WMGetFromPLArray(texture, i));
654 colors[i-2] = wmalloc(sizeof(RColor));
655 str2rcolor(rc, str, colors[i-2]);
657 colors[i-2] = NULL;
659 image = RRenderMultiGradient(width, height, colors, style);
661 for (i = 0; colors[i]!=NULL; i++)
662 wfree(colors[i]);
663 wfree(colors);
665 } else if (strcasecmp(&type[1], "pixmap")==0) {
666 RImage *timage = NULL;
667 char *path;
668 RColor color;
670 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
672 if ((path=wfindfileinarray(GetObjectForKey("PixmapPath"), str))!=NULL)
673 timage = RLoadImage(rc, path, 0);
675 if (!path || !timage) {
676 wwarning("could not load file '%s': %s", path ? path : str,
677 RMessageForError(RErrorCode));
678 } else {
679 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
680 str2rcolor(rc, str, &color);
682 switch (toupper(type[0])) {
683 case 'T':
684 image = RMakeTiledImage(timage, width, height);
685 RReleaseImage(timage);
686 timage = image;
687 break;
688 case 'C':
689 image = RMakeCenteredImage(timage, width, height, &color);
690 RReleaseImage(timage);
691 timage = image;
692 break;
693 case 'S':
694 case 'M':
695 image = RScaleImage(timage, width, height);
696 RReleaseImage(timage);
697 timage = image;
698 break;
702 wfree(path);
705 if (!image)
706 return None;
708 if (path) {
709 dumpRImage(path, image);
712 if (border < 0) {
713 if (border == RESIZEBAR_BEVEL) {
714 drawResizebarBevel(image);
715 } else if (border == MENU_BEVEL) {
716 drawMenuBevel(image);
717 RBevelImage(image, RBEV_RAISED2);
719 } else if (border) {
720 RBevelImage(image, border);
723 RConvertImage(rc, image, &pixmap);
724 RReleaseImage(image);
726 return pixmap;
730 static Pixmap
731 renderMenu(_Panel *panel, WMPropList *texture, int width, int iheight)
733 WMScreen *scr = WMWidgetScreen(panel->parent);
734 Display *dpy = WMScreenDisplay(scr);
735 Pixmap pix, tmp;
736 GC gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
737 int i;
739 switch (panel->menuStyle) {
740 case MSTYLE_NORMAL:
741 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
743 pix = XCreatePixmap(dpy, tmp, width, iheight*4, WMScreenDepth(scr));
744 for (i = 0; i < 4; i++) {
745 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight*i);
747 XFreePixmap(dpy, tmp);
748 break;
749 case MSTYLE_SINGLE:
750 pix = renderTexture(scr, texture, width, iheight*4, NULL, MENU_BEVEL);
751 break;
752 case MSTYLE_FLAT:
753 pix = renderTexture(scr, texture, width, iheight*4, NULL, RBEV_RAISED2);
754 break;
756 XFreeGC(dpy, gc);
758 return pix;
762 static void
763 renderPreview(_Panel *panel, GC gc, int part, int relief)
765 WMListItem *item;
766 TextureListItem *titem;
767 Pixmap pix;
768 WMScreen *scr = WMWidgetScreen(panel->box);
770 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
771 titem = (TextureListItem*)item->clientData;
773 pix = renderTexture(scr, titem->prop,
774 previewPositions[part].size.width,
775 previewPositions[part].size.height,
776 NULL, relief);
778 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
779 previewPositions[part].size.width,
780 previewPositions[part].size.height,
781 previewPositions[part].pos.x,
782 previewPositions[part].pos.y);
784 XCopyArea(WMScreenDisplay(scr), pix, panel->previewNoText, gc, 0, 0,
785 previewPositions[part].size.width,
786 previewPositions[part].size.height,
787 previewPositions[part].pos.x,
788 previewPositions[part].pos.y);
790 XFreePixmap(WMScreenDisplay(scr), pix);
794 static void
795 updatePreviewBox(_Panel *panel, int elements)
797 WMScreen *scr = WMWidgetScreen(panel->parent);
798 Display *dpy = WMScreenDisplay(scr);
799 Pixmap pix;
800 GC gc;
801 int colorUpdate = 0;
802 WMColor *black = WMBlackColor(scr);
804 gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
807 if (panel->preview == None) {
808 WMColor *color;
809 WMPixmap *p;
811 panel->previewNoText = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
812 240-4, 215-4, WMScreenDepth(scr));
814 p = WMCreatePixmap(scr, 240-4, 215-4, WMScreenDepth(scr), False);
815 panel->preview = WMGetPixmapXID(p);
816 WMSetLabelImage(panel->prevL, p);
817 WMReleasePixmap(p);
819 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
820 XFillRectangle(dpy, panel->preview, WMColorGC(color),
821 0, 0, 240-4, 215-4);
822 XFillRectangle(dpy, panel->previewNoText, WMColorGC(color),
823 0, 0, 240-4, 215-4);
824 WMReleaseColor(color);
828 if (elements & (1<<PFOCUSED)) {
829 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
830 XDrawRectangle(dpy, panel->preview, WMColorGC(black),
831 previewPositions[PFOCUSED].pos.x-1,
832 previewPositions[PFOCUSED].pos.y-1,
833 previewPositions[PFOCUSED].size.width,
834 previewPositions[PFOCUSED].size.height);
835 XDrawRectangle(dpy, panel->previewNoText, WMColorGC(black),
836 previewPositions[PFOCUSED].pos.x-1,
837 previewPositions[PFOCUSED].pos.y-1,
838 previewPositions[PFOCUSED].size.width,
839 previewPositions[PFOCUSED].size.height);
840 colorUpdate |= FTITLE_COL;
842 if (elements & (1<<PUNFOCUSED)) {
843 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
844 XDrawRectangle(dpy, panel->preview, WMColorGC(black),
845 previewPositions[PUNFOCUSED].pos.x-1,
846 previewPositions[PUNFOCUSED].pos.y-1,
847 previewPositions[PUNFOCUSED].size.width,
848 previewPositions[PUNFOCUSED].size.height);
849 XDrawRectangle(dpy, panel->previewNoText, WMColorGC(black),
850 previewPositions[PUNFOCUSED].pos.x-1,
851 previewPositions[PUNFOCUSED].pos.y-1,
852 previewPositions[PUNFOCUSED].size.width,
853 previewPositions[PUNFOCUSED].size.height);
854 colorUpdate |= UTITLE_COL;
856 if (elements & (1<<POWNER)) {
857 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
858 XDrawRectangle(dpy, panel->preview, WMColorGC(black),
859 previewPositions[POWNER].pos.x-1,
860 previewPositions[POWNER].pos.y-1,
861 previewPositions[POWNER].size.width,
862 previewPositions[POWNER].size.height);
863 XDrawRectangle(dpy, panel->previewNoText, WMColorGC(black),
864 previewPositions[POWNER].pos.x-1,
865 previewPositions[POWNER].pos.y-1,
866 previewPositions[POWNER].size.width,
867 previewPositions[POWNER].size.height);
868 colorUpdate |= OTITLE_COL;
870 if (elements & (1<<PRESIZEBAR)) {
871 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
873 if (elements & (1<<PMTITLE)) {
874 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
875 colorUpdate |= MTITLE_COL;
877 if (elements & (1<<PMITEM)) {
878 WMListItem *item;
879 TextureListItem *titem;
881 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
882 titem = (TextureListItem*)item->clientData;
884 pix = renderMenu(panel, titem->prop,
885 previewPositions[PMITEM].size.width,
886 previewPositions[PMITEM].size.height/4);
888 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
889 previewPositions[PMITEM].size.width,
890 previewPositions[PMITEM].size.height,
891 previewPositions[PMITEM].pos.x,
892 previewPositions[PMITEM].pos.y);
894 XCopyArea(dpy, pix, panel->previewNoText, gc, 0, 0,
895 previewPositions[PMITEM].size.width,
896 previewPositions[PMITEM].size.height,
897 previewPositions[PMITEM].pos.x,
898 previewPositions[PMITEM].pos.y);
900 XFreePixmap(dpy, pix);
902 colorUpdate |= MITEM_COL|MDISAB_COL|MHIGH_COL|MHIGHT_COL;
904 if (elements & (1<<PMITEM|1<<PMTITLE)) {
905 XDrawLine(dpy, panel->preview, gc, 29, 120, 29, 120+20*4+20);
906 XDrawLine(dpy, panel->preview, gc, 29, 119, 119, 119);
908 XDrawLine(dpy, panel->previewNoText, gc, 29, 120, 29, 120+20*4+20);
909 XDrawLine(dpy, panel->previewNoText, gc, 29, 119, 119, 119);
911 if (elements & (1<<PICON)) {
912 WMListItem *item;
913 TextureListItem *titem;
915 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
916 titem = (TextureListItem*)item->clientData;
918 renderPreview(panel, gc, PICON,
919 titem->ispixmap ? 0 : RBEV_RAISED3);
921 colorUpdate |= ICONT_COL|ICONB_COL|CLIP_COL|CCLIP_COL;
924 if (colorUpdate)
925 updateColorPreviewBox(panel, colorUpdate);
926 else
927 WMRedisplayWidget(panel->prevL);
929 XFreeGC(dpy, gc);
930 WMReleaseColor(black);
936 static void
937 cancelNewTexture(void *data)
939 _Panel *panel = (_Panel*)data;
941 HideTexturePanel(panel->texturePanel);
947 static char*
948 makeFileName(char *prefix)
950 char *fname;
952 fname = wstrdup(prefix);
954 while (access(fname, F_OK)==0) {
955 char buf[30];
957 wfree(fname);
958 sprintf(buf, "%08lx.cache", time(NULL));
959 fname = wstrconcat(prefix, buf);
962 return fname;
968 static void
969 okNewTexture(void *data)
971 _Panel *panel = (_Panel*)data;
972 WMListItem *item;
973 char *name;
974 char *str;
975 WMPropList *prop;
976 TextureListItem *titem;
977 WMScreen *scr = WMWidgetScreen(panel->parent);
979 titem = wmalloc(sizeof(TextureListItem));
980 memset(titem, 0, sizeof(TextureListItem));
982 HideTexturePanel(panel->texturePanel);
984 name = GetTexturePanelTextureName(panel->texturePanel);
986 prop = GetTexturePanelTexture(panel->texturePanel);
988 str = WMGetPropListDescription(prop, False);
990 titem->title = name;
991 titem->prop = prop;
992 titem->texture = str;
993 titem->selectedFor = 0;
995 titem->ispixmap = isPixmap(prop);
997 titem->path = makeFileName(panel->fprefix);
998 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT,
999 titem->path, 0);
1001 item = WMAddListItem(panel->texLs, "");
1002 item->clientData = titem;
1004 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
1008 static void
1009 okEditTexture(void *data)
1011 _Panel *panel = (_Panel*)data;
1012 WMListItem *item;
1013 char *name;
1014 char *str;
1015 WMPropList *prop;
1016 TextureListItem *titem;
1018 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
1019 titem = (TextureListItem*)item->clientData;
1021 HideTexturePanel(panel->texturePanel);
1023 if (titem->current) {
1024 name = GetTexturePanelTextureName(panel->texturePanel);
1026 wfree(titem->title);
1027 titem->title = name;
1030 prop = GetTexturePanelTexture(panel->texturePanel);
1032 str = WMGetPropListDescription(prop, False);
1034 WMReleasePropList(titem->prop);
1035 titem->prop = prop;
1037 titem->ispixmap = isPixmap(prop);
1039 wfree(titem->texture);
1040 titem->texture = str;
1042 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
1043 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
1044 TEXPREV_WIDTH, TEXPREV_HEIGHT,
1045 titem->path, 0);
1047 WMRedisplayWidget(panel->texLs);
1049 if (titem->selectedFor)
1050 updatePreviewBox(panel, titem->selectedFor);
1052 changePage(panel->secP, panel);
1057 static void
1058 editTexture(WMWidget *w, void *data)
1060 _Panel *panel = (_Panel*)data;
1061 WMListItem *item;
1062 TextureListItem *titem;
1064 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
1065 titem = (TextureListItem*)item->clientData;
1067 SetTexturePanelPixmapPath(panel->texturePanel,
1068 GetObjectForKey("PixmapPath"));
1070 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
1072 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1073 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
1075 ShowTexturePanel(panel->texturePanel);
1080 static void
1081 newTexture(WMWidget *w, void *data)
1083 _Panel *panel = (_Panel*)data;
1085 SetTexturePanelPixmapPath(panel->texturePanel,
1086 GetObjectForKey("PixmapPath"));
1088 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1090 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1092 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1094 ShowTexturePanel(panel->texturePanel);
1099 static void
1100 deleteTexture(WMWidget *w, void *data)
1102 _Panel *panel = (_Panel*)data;
1103 WMListItem *item;
1104 TextureListItem *titem;
1105 int row;
1106 int section;
1108 section = WMGetPopUpButtonSelectedItem(panel->secP);
1109 row = WMGetListSelectedItemRow(panel->texLs);
1110 item = WMGetListItem(panel->texLs, row);
1111 titem = (TextureListItem*)item->clientData;
1113 if (titem->selectedFor & (1 << section)) {
1114 TextureListItem *titem2;
1116 panel->textureIndex[section] = section;
1117 item = WMGetListItem(panel->texLs, section);
1118 titem2 = (TextureListItem*)item->clientData;
1119 titem2->selectedFor |= 1 << section;
1122 wfree(titem->title);
1123 wfree(titem->texture);
1124 WMReleasePropList(titem->prop);
1125 if (titem->path) {
1126 if (remove(titem->path) < 0 && errno != ENOENT) {
1127 wsyserror("could not remove file %s", titem->path);
1129 wfree(titem->path);
1132 wfree(titem);
1134 WMRemoveListItem(panel->texLs, row);
1135 WMSetButtonEnabled(panel->delB, False);
1141 static void
1142 extractTexture(WMWidget *w, void *data)
1144 _Panel *panel = (_Panel*)data;
1145 char *path;
1146 WMOpenPanel *opanel;
1147 WMScreen *scr = WMWidgetScreen(w);
1149 opanel = WMGetOpenPanel(scr);
1150 WMSetFilePanelCanChooseDirectories(opanel, False);
1151 WMSetFilePanelCanChooseFiles(opanel, True);
1153 if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(),
1154 _("Select File"), NULL)) {
1155 path = WMGetFilePanelFileName(opanel);
1157 OpenExtractPanelFor(panel, path);
1159 wfree(path);
1164 static void
1165 changePage(WMWidget *w, void *data)
1167 _Panel *panel = (_Panel*)data;
1168 int section;
1169 WMListItem *item;
1170 TextureListItem *titem;
1171 WMScreen *scr = WMWidgetScreen(panel->box);
1172 RContext *rc = WMScreenRContext(scr);
1173 static WMPoint positions[] = {
1174 {5, 10},
1175 {5, 40},
1176 {5, 70},
1177 {5, 100},
1178 {5, 120},
1179 {5, 160},
1180 {130, 150}
1183 if (w) {
1184 section = WMGetPopUpButtonSelectedItem(panel->secP);
1186 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1188 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1190 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1192 titem = (TextureListItem*)item->clientData;
1195 WMColor *color;
1197 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
1198 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1199 positions[panel->oldsection].x,
1200 positions[panel->oldsection].y, 22, 22);
1201 WMReleaseColor(color);
1203 if (w) {
1204 panel->oldsection = section;
1205 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1206 positions[section].y);
1208 WMRedisplayWidget(panel->prevL);
1213 static void
1214 previewClick(XEvent *event, void *clientData)
1216 _Panel *panel = (_Panel*)clientData;
1217 int i;
1219 switch (panel->oldTabItem) {
1220 case 0:
1221 for (i = 0; i < sizeof(previewPositions)/sizeof(WMRect); i++) {
1222 if (event->xbutton.x >= previewPositions[i].pos.x
1223 && event->xbutton.y >= previewPositions[i].pos.y
1224 && event->xbutton.x < previewPositions[i].pos.x
1225 + previewPositions[i].size.width
1226 && event->xbutton.y < previewPositions[i].pos.y
1227 + previewPositions[i].size.height) {
1229 WMSetPopUpButtonSelectedItem(panel->secP, i);
1230 changePage(panel->secP, panel);
1231 return;
1234 break;
1235 case 1:
1236 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1237 if (event->xbutton.x >= previewColorPositions[i].pos.x
1238 && event->xbutton.y >= previewColorPositions[i].pos.y
1239 && event->xbutton.x < previewColorPositions[i].pos.x
1240 + previewColorPositions[i].size.width
1241 && event->xbutton.y < previewColorPositions[i].pos.y
1242 + previewColorPositions[i].size.height) {
1244 /* yuck kluge */
1245 if (i == 7)
1246 i = 4;
1248 WMSetPopUpButtonSelectedItem(panel->colP, i);
1249 changeColorPage(panel->colP, panel);
1250 return;
1253 break;
1258 static void
1259 textureClick(WMWidget *w, void *data)
1261 _Panel *panel = (_Panel*)data;
1262 int i;
1263 WMListItem *item;
1264 TextureListItem *titem;
1266 i = WMGetListSelectedItemRow(panel->texLs);
1268 item = WMGetListItem(panel->texLs, i);
1270 titem = (TextureListItem*)item->clientData;
1272 if (titem->current) {
1273 WMSetButtonEnabled(panel->delB, False);
1274 } else {
1275 WMSetButtonEnabled(panel->delB, True);
1281 static void
1282 textureDoubleClick(WMWidget *w, void *data)
1284 _Panel *panel = (_Panel*)data;
1285 int i, section;
1286 WMListItem *item;
1287 TextureListItem *titem;
1289 /* unselect old texture */
1290 section = WMGetPopUpButtonSelectedItem(panel->secP);
1292 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1293 titem = (TextureListItem*)item->clientData;
1294 titem->selectedFor &= ~(1 << section);
1296 /* select new texture */
1297 i = WMGetListSelectedItemRow(panel->texLs);
1299 item = WMGetListItem(panel->texLs, i);
1301 titem = (TextureListItem*)item->clientData;
1303 titem->selectedFor |= 1<<section;
1305 panel->textureIndex[section] = i;
1307 WMRedisplayWidget(panel->texLs);
1309 updatePreviewBox(panel, 1<<section);
1314 static void
1315 paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
1316 WMRect *rect)
1318 _Panel *panel = (_Panel*)WMGetHangedData(lPtr);
1319 WMScreen *scr = WMWidgetScreen(lPtr);
1320 int width, height, x, y;
1321 Display *dpy = WMScreenDisplay(scr);
1322 WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
1323 WMListItem *item;
1324 WMColor *black = WMBlackColor(scr);
1325 TextureListItem *titem;
1327 item = WMGetListItem(lPtr, index);
1328 titem = (TextureListItem*)item->clientData;
1329 if (!titem) {
1330 WMReleaseColor(back);
1331 WMReleaseColor(black);
1332 return;
1335 width = rect->size.width;
1336 height = rect->size.height;
1337 x = rect->pos.x;
1338 y = rect->pos.y;
1340 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
1342 if (titem->preview)
1343 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1344 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1346 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1347 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1348 else if (titem->selectedFor)
1349 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1351 WMDrawString(scr, d, black, panel->boldFont,
1352 x + TEXPREV_WIDTH + 22, y + 2, titem->title,
1353 strlen(titem->title));
1355 WMDrawString(scr, d, black, panel->smallFont,
1356 x + TEXPREV_WIDTH + 14, y + 18, titem->texture,
1357 strlen(titem->texture));
1360 WMReleaseColor(back);
1361 WMReleaseColor(black);
1366 static Pixmap
1367 loadRImage(WMScreen *scr, char *path)
1369 FILE *f;
1370 RImage *image;
1371 int w, h, d;
1372 Pixmap pixmap;
1374 f = fopen(path, "rb");
1375 if (!f)
1376 return None;
1378 fscanf(f, "%02x%02x%1x", &w, &h, &d);
1380 image = RCreateImage(w, h, d == 4);
1381 fread(image->data, 1, w*h*d, f);
1382 fclose(f);
1384 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1385 RReleaseImage(image);
1387 return pixmap;
1392 static void
1393 fillTextureList(WMList *lPtr)
1395 WMPropList *textureList;
1396 WMPropList *texture;
1397 WMUserDefaults *udb = WMGetStandardUserDefaults();
1398 TextureListItem *titem;
1399 WMScreen *scr = WMWidgetScreen(lPtr);
1400 int i;
1402 textureList = WMGetUDObjectForKey(udb, "TextureList");
1403 if (!textureList)
1404 return;
1406 for (i = 0; i < WMGetPropListItemCount(textureList); i++) {
1407 WMListItem *item;
1409 texture = WMGetFromPLArray(textureList, i);
1411 titem = wmalloc(sizeof(TextureListItem));
1412 memset(titem, 0, sizeof(TextureListItem));
1414 titem->title = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 0)));
1415 titem->prop = WMRetainPropList(WMGetFromPLArray(texture, 1));
1416 titem->texture = WMGetPropListDescription(titem->prop, False);
1417 titem->selectedFor = 0;
1418 titem->path = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
1420 titem->preview = loadRImage(scr, titem->path);
1421 if (!titem->preview) {
1422 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH,
1423 TEXPREV_HEIGHT, NULL, 0);
1425 item = WMAddListItem(lPtr, "");
1426 item->clientData = titem;
1431 static void
1432 fillColorList(_Panel *panel)
1434 WMColor *color;
1435 WMPropList *list;
1436 WMUserDefaults *udb = WMGetStandardUserDefaults();
1437 WMScreen *scr = WMWidgetScreen(panel->box);
1438 int i;
1440 list = WMGetUDObjectForKey(udb, "ColorList");
1441 if (!list) {
1442 for (i = 0; i < 24; i++) {
1443 color = WMCreateNamedColor(scr, sampleColors[i], False);
1444 if (!color)
1445 continue;
1446 WMSetColorWellColor(panel->sampW[i], color);
1447 WMReleaseColor(color);
1449 } else {
1450 WMPropList *c;
1452 for (i = 0; i < WMIN(24, WMGetPropListItemCount(list)); i++) {
1453 c = WMGetFromPLArray(list, i);
1454 if (!c || !WMIsPLString(c))
1455 continue;
1456 color = WMCreateNamedColor(scr, WMGetFromPLString(c), False);
1457 if (!color)
1458 continue;
1459 WMSetColorWellColor(panel->sampW[i], color);
1460 WMReleaseColor(color);
1466 /*************************************************************************/
1469 static void
1470 changeColorPage(WMWidget *w, void *data)
1472 _Panel *panel = (_Panel*)data;
1473 int section;
1474 WMScreen *scr = WMWidgetScreen(panel->box);
1475 RContext *rc = WMScreenRContext(scr);
1476 static WMPoint positions[] = {
1477 {5, 10},
1478 {5, 40},
1479 {5, 70},
1480 {5, 120},
1481 {5, 140},
1482 {5, 160},
1483 {5, 180},
1484 {5, 180},
1485 {130, 140},
1486 {130, 140},
1487 {130, 140},
1488 {130, 140}
1491 if (panel->preview) {
1492 WMColor *color;
1494 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
1495 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1496 positions[panel->oldcsection].x,
1497 positions[panel->oldcsection].y, 22, 22);
1498 WMReleaseColor(color);
1500 if (w) {
1501 section = WMGetPopUpButtonSelectedItem(panel->colP);
1503 panel->oldcsection = section;
1504 if (panel->preview)
1505 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1506 positions[section].y);
1508 section = WMGetPopUpButtonSelectedItem(panel->colP);
1510 WMSetColorWellColor(panel->colW, panel->colors[section]);
1512 WMRedisplayWidget(panel->prevL);
1516 static void
1517 paintText(WMScreen *scr, Drawable d, WMColor *color, WMFont *font,
1518 int x, int y, int w, int h, WMAlignment align, char *text)
1520 int l = strlen(text);
1522 switch (align) {
1523 case WALeft:
1524 x += 5;
1525 break;
1526 case WARight:
1527 x += w - 5 - WMWidthOfString(font, text, l);
1528 break;
1529 default:
1530 case WACenter:
1531 x += (w - WMWidthOfString(font, text, l))/2;
1532 break;
1534 WMDrawString(scr, d, color, font, x, y + (h - WMFontHeight(font))/2,
1535 text, l);
1540 static void
1541 updateColorPreviewBox(_Panel *panel, int elements)
1543 WMScreen *scr = WMWidgetScreen(panel->box);
1544 Display *dpy = WMScreenDisplay(scr);
1545 Pixmap d, pnot;
1546 GC gc;
1548 d = panel->preview;
1549 pnot = panel->previewNoText;
1550 gc = WMColorGC(panel->colors[0]);
1552 if (elements & FTITLE_COL) {
1553 XCopyArea(dpy, pnot, d, gc, 30, 10, 190, 20, 30, 10);
1554 paintText(scr, d, panel->colors[0], panel->boldFont, 30, 10, 190, 20,
1555 panel->titleAlignment, _("Focused Window"));
1557 if (elements & UTITLE_COL) {
1558 XCopyArea(dpy, pnot, d, gc, 30, 40, 190, 20, 30, 40);
1559 paintText(scr, d, panel->colors[1], panel->boldFont, 30, 40, 190, 20,
1560 panel->titleAlignment, _("Unfocused Window"));
1562 if (elements & OTITLE_COL) {
1563 XCopyArea(dpy, pnot, d, gc, 30, 70, 190, 20, 30, 70);
1564 paintText(scr, d, panel->colors[2], panel->boldFont, 30, 70, 190, 20,
1565 panel->titleAlignment, _("Owner of Focused Window"));
1567 if (elements & MTITLE_COL) {
1568 XCopyArea(dpy, pnot, d, gc, 30, 120, 90, 20, 30, 120);
1569 paintText(scr, d, panel->colors[3], panel->boldFont, 30, 120, 90, 20,
1570 WALeft, _("Menu Title"));
1572 if (elements & MITEM_COL) {
1573 XCopyArea(dpy, pnot, d, gc, 30, 140, 90, 20, 30, 140);
1574 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 140, 90, 20,
1575 WALeft, _("Normal Item"));
1576 XCopyArea(dpy, pnot, d, gc, 30, 200, 90, 20, 30, 200);
1577 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 200, 90, 20,
1578 WALeft, _("Normal Item"));
1580 if (elements & MDISAB_COL) {
1581 XCopyArea(dpy, pnot, d, gc, 30, 160, 90, 20, 30, 160);
1582 paintText(scr, d, panel->colors[5], panel->normalFont, 30, 160, 90, 20,
1583 WALeft, _("Disabled Item"));
1585 if (elements & MHIGH_COL) {
1586 XFillRectangle(WMScreenDisplay(scr), d, WMColorGC(panel->colors[6]),
1587 31, 181, 87, 17);
1588 XFillRectangle(WMScreenDisplay(scr), pnot, WMColorGC(panel->colors[6]),
1589 31, 181, 87, 17);
1590 elements |= MHIGHT_COL;
1592 if (elements & MHIGHT_COL) {
1593 XCopyArea(dpy, pnot, d, gc, 30, 180, 90, 20, 30, 180);
1594 paintText(scr, d, panel->colors[7], panel->normalFont, 30, 180, 90, 20,
1595 WALeft, _("Highlighted"));
1598 if (elements & ICONT_COL) {
1599 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1600 155, 130, 64);
1602 if (elements & ICONB_COL) {
1603 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1604 0, 0, 30);
1606 if (elements & CLIP_COL) {
1607 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1608 0, 0, 30);
1610 if (elements & CCLIP_COL) {
1611 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1612 0, 0, 30);
1615 WMRedisplayWidget(panel->prevL);
1619 static void
1620 colorWellObserver(void *self, WMNotification *n)
1622 _Panel *panel = (_Panel*)self;
1623 int p;
1625 p = WMGetPopUpButtonSelectedItem(panel->colP);
1627 WMReleaseColor(panel->colors[p]);
1629 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1631 updateColorPreviewBox(panel, 1<<p);
1635 static void
1636 changedTabItem(struct WMTabViewDelegate *self, WMTabView *tabView,
1637 WMTabViewItem *item)
1639 _Panel *panel = self->data;
1640 int i;
1642 i = WMGetTabViewItemIdentifier(item);
1643 switch (i) {
1644 case 0:
1645 switch (panel->oldTabItem) {
1646 case 1:
1647 changeColorPage(NULL, panel);
1648 break;
1650 changePage(panel->secP, panel);
1651 break;
1652 case 1:
1653 switch (panel->oldTabItem) {
1654 case 0:
1655 changePage(NULL, panel);
1656 break;
1658 changeColorPage(panel->colP, panel);
1659 break;
1660 case 3:
1661 switch (panel->oldTabItem) {
1662 case 0:
1663 changePage(NULL, panel);
1664 break;
1665 case 1:
1666 changeColorPage(NULL, panel);
1667 break;
1669 break;
1672 panel->oldTabItem = i;
1676 /*************************************************************************/
1678 static void
1679 menuStyleCallback(WMWidget *self, void *data)
1681 _Panel *panel = (_Panel*)data;
1683 if (self == panel->mstyB[0]) {
1684 panel->menuStyle = MSTYLE_NORMAL;
1685 updatePreviewBox(panel, 1<<PMITEM);
1687 } else if (self == panel->mstyB[1]) {
1688 panel->menuStyle = MSTYLE_SINGLE;
1689 updatePreviewBox(panel, 1<<PMITEM);
1691 } else if (self == panel->mstyB[2]) {
1692 panel->menuStyle = MSTYLE_FLAT;
1693 updatePreviewBox(panel, 1<<PMITEM);
1698 static void
1699 titleAlignCallback(WMWidget *self, void *data)
1701 _Panel *panel = (_Panel*)data;
1703 if (self == panel->taliB[0]) {
1704 panel->titleAlignment = WALeft;
1705 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1707 } else if (self == panel->taliB[1]) {
1708 panel->titleAlignment = WACenter;
1709 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1711 } else if (self == panel->taliB[2]) {
1712 panel->titleAlignment = WARight;
1713 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1718 static void
1719 createPanel(Panel *p)
1721 _Panel *panel = (_Panel*)p;
1722 WMFont *font;
1723 WMScreen *scr = WMWidgetScreen(panel->parent);
1724 WMTabViewItem *item;
1725 int i;
1726 char *tmp;
1727 Bool ok = True;
1729 panel->fprefix = wstrconcat(wusergnusteppath(), "/.AppInfo");
1731 if (access(panel->fprefix, F_OK)!=0) {
1732 if (mkdir(panel->fprefix, 0755) < 0) {
1733 wsyserror(panel->fprefix);
1734 ok = False;
1737 if (ok) {
1738 tmp = wstrconcat(panel->fprefix, "/WPrefs/");
1739 wfree(panel->fprefix);
1740 panel->fprefix = tmp;
1741 if (access(panel->fprefix, F_OK)!=0) {
1742 if (mkdir(panel->fprefix, 0755) < 0) {
1743 wsyserror(panel->fprefix);
1748 panel->smallFont = WMSystemFontOfSize(scr, 10);
1749 panel->normalFont = WMSystemFontOfSize(scr, 12);
1750 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1752 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1753 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1754 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1756 panel->box = WMCreateBox(panel->parent);
1757 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1759 /* preview box */
1760 panel->prevL = WMCreateLabel(panel->box);
1761 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1762 WMMoveWidget(panel->prevL, 15, 10);
1763 WMSetLabelRelief(panel->prevL, WRSunken);
1764 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1766 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask,
1767 previewClick, panel);
1770 /* tabview */
1772 tabviewDelegate.data = panel;
1774 panel->tabv = WMCreateTabView(panel->box);
1775 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1776 WMMoveWidget(panel->tabv, 265, 10);
1777 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1779 /*** texture list ***/
1781 panel->texF = WMCreateFrame(panel->box);
1782 WMSetFrameRelief(panel->texF, WRFlat);
1784 item = WMCreateTabViewItemWithIdentifier(0);
1785 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1786 WMSetTabViewItemLabel(item, _("Texture"));
1788 WMAddItemInTabView(panel->tabv, item);
1791 panel->secP = WMCreatePopUpButton(panel->texF);
1792 WMResizeWidget(panel->secP, 228, 20);
1793 WMMoveWidget(panel->secP, 7, 7);
1794 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1795 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1796 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1797 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1798 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1799 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1800 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1801 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1803 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1804 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1806 panel->texLs = WMCreateList(panel->texF);
1807 WMResizeWidget(panel->texLs, 165, 155);
1808 WMMoveWidget(panel->texLs, 70, 33);
1809 WMSetListUserDrawItemHeight(panel->texLs, 35);
1810 WMSetListUserDrawProc(panel->texLs, paintListItem);
1811 WMHangData(panel->texLs, panel);
1812 WMSetListAction(panel->texLs, textureClick, panel);
1813 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1815 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1816 "for the selected item."),
1817 WMWidgetView(panel->texLs));
1819 /* command buttons */
1821 font = WMSystemFontOfSize(scr, 10);
1824 panel->newB = WMCreateCommandButton(panel->texF);
1825 WMResizeWidget(panel->newB, 57, 39);
1826 WMMoveWidget(panel->newB, 7, 33);
1827 WMSetButtonFont(panel->newB, font);
1828 WMSetButtonImagePosition(panel->newB, WIPAbove);
1829 WMSetButtonText(panel->newB, _("New"));
1830 WMSetButtonAction(panel->newB, newTexture, panel);
1831 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE, NULL, NULL);
1833 WMSetBalloonTextForView(_("Create a new texture."),
1834 WMWidgetView(panel->newB));
1836 panel->ripB = WMCreateCommandButton(panel->texF);
1837 WMResizeWidget(panel->ripB, 57, 39);
1838 WMMoveWidget(panel->ripB, 7, 72);
1839 WMSetButtonFont(panel->ripB, font);
1840 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1841 WMSetButtonText(panel->ripB, _("Extract..."));
1842 WMSetButtonAction(panel->ripB, extractTexture, panel);
1843 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE, NULL, NULL);
1845 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1846 WMWidgetView(panel->ripB));
1848 WMSetButtonEnabled(panel->ripB, False);
1850 panel->editB = WMCreateCommandButton(panel->texF);
1851 WMResizeWidget(panel->editB, 57, 39);
1852 WMMoveWidget(panel->editB, 7, 111);
1853 WMSetButtonFont(panel->editB, font);
1854 WMSetButtonImagePosition(panel->editB, WIPAbove);
1855 WMSetButtonText(panel->editB, _("Edit"));
1856 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE, NULL, NULL);
1857 WMSetButtonAction(panel->editB, editTexture, panel);
1858 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1859 WMWidgetView(panel->editB));
1861 panel->delB = WMCreateCommandButton(panel->texF);
1862 WMResizeWidget(panel->delB, 57, 38);
1863 WMMoveWidget(panel->delB, 7, 150);
1864 WMSetButtonFont(panel->delB, font);
1865 WMSetButtonImagePosition(panel->delB, WIPAbove);
1866 WMSetButtonText(panel->delB, _("Delete"));
1867 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE, NULL, NULL);
1868 WMSetButtonEnabled(panel->delB, False);
1869 WMSetButtonAction(panel->delB, deleteTexture, panel);
1870 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1871 WMWidgetView(panel->delB));
1873 WMReleaseFont(font);
1875 WMMapSubwidgets(panel->texF);
1877 /*** colors ***/
1878 panel->colF = WMCreateFrame(panel->box);
1879 WMSetFrameRelief(panel->colF, WRFlat);
1881 item = WMCreateTabViewItemWithIdentifier(1);
1882 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1883 WMSetTabViewItemLabel(item, _("Color"));
1885 WMAddItemInTabView(panel->tabv, item);
1887 panel->colP = WMCreatePopUpButton(panel->colF);
1888 WMResizeWidget(panel->colP, 228, 20);
1889 WMMoveWidget(panel->colP, 7, 7);
1890 WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1891 WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1892 WMAddPopUpButtonItem(panel->colP, _("Owner of Focused Window Title"));
1893 WMAddPopUpButtonItem(panel->colP, _("Menu Title"));
1894 WMAddPopUpButtonItem(panel->colP, _("Menu Item Text"));
1895 WMAddPopUpButtonItem(panel->colP, _("Disabled Menu Item Text"));
1896 WMAddPopUpButtonItem(panel->colP, _("Menu Highlight Color"));
1897 WMAddPopUpButtonItem(panel->colP, _("Highlighted Menu Text Color"));
1899 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1900 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1901 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1902 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1905 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1907 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1910 panel->colW = WMCreateColorWell(panel->colF);
1911 WMResizeWidget(panel->colW, 65, 50);
1912 WMMoveWidget(panel->colW, 30, 75);
1913 WMAddNotificationObserver(colorWellObserver, panel,
1914 WMColorWellDidChangeNotification, panel->colW);
1916 for (i = 0; i < 4; i++) {
1917 int j;
1918 for (j = 0; j < 6; j++) {
1919 panel->sampW[i+j*4] = WMCreateColorWell(panel->colF);
1920 WMResizeWidget(panel->sampW[i+j*4], 22, 22);
1921 WMMoveWidget(panel->sampW[i+j*4], 130 + i*22, 40 + j*22);
1922 WSetColorWellBordered(panel->sampW[i+j*4], False);
1926 WMMapSubwidgets(panel->colF);
1928 #ifdef unfinished
1929 /*** root bg ***/
1931 panel->bgF = WMCreateFrame(panel->box);
1932 WMSetFrameRelief(panel->bgF, WRFlat);
1934 item = WMCreateTabViewItemWithIdentifier(2);
1935 WMSetTabViewItemView(item, WMWidgetView(panel->bgF));
1936 WMSetTabViewItemLabel(item, _("Background"));
1938 WMAddItemInTabView(panel->tabv, item);
1940 panel->bgprevL = WMCreateLabel(panel->bgF);
1941 WMResizeWidget(panel->bgprevL, 230, 155);
1942 WMMoveWidget(panel->bgprevL, 5, 5);
1943 WMSetLabelRelief(panel->bgprevL, WRSunken);
1945 panel->selbgB = WMCreateCommandButton(panel->bgF);
1946 WMMoveWidget(panel->selbgB, 5, 165);
1947 WMResizeWidget(panel->selbgB, 100, 24);
1948 WMSetButtonText(panel->selbgB, _("Browse..."));
1953 WMMapSubwidgets(panel->bgF);
1954 #endif /* unfinished */
1955 /*** options ***/
1956 panel->optF = WMCreateFrame(panel->box);
1957 WMSetFrameRelief(panel->optF, WRFlat);
1959 item = WMCreateTabViewItemWithIdentifier(3);
1960 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1961 WMSetTabViewItemLabel(item, _("Options"));
1963 WMAddItemInTabView(panel->tabv, item);
1965 panel->mstyF = WMCreateFrame(panel->optF);
1966 WMResizeWidget(panel->mstyF, 215, 85);
1967 WMMoveWidget(panel->mstyF, 15, 10);
1968 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1970 for (i = 0; i < 3; i++) {
1971 WMPixmap *icon;
1972 char *path;
1974 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1975 WMResizeWidget(panel->mstyB[i], 54, 54);
1976 WMMoveWidget(panel->mstyB[i], 15 + i*65, 20);
1977 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1978 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1979 switch (i) {
1980 case 0:
1981 path = LocateImage(MSTYLE1_FILE);
1982 break;
1983 case 1:
1984 path = LocateImage(MSTYLE2_FILE);
1985 break;
1986 case 2:
1987 path = LocateImage(MSTYLE3_FILE);
1988 break;
1990 if (path) {
1991 icon = WMCreatePixmapFromFile(scr, path);
1992 if (icon) {
1993 WMSetButtonImage(panel->mstyB[i], icon);
1994 WMReleasePixmap(icon);
1995 } else {
1996 wwarning(_("could not load icon file %s"), path);
1998 wfree(path);
2001 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
2002 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
2004 WMMapSubwidgets(panel->mstyF);
2007 panel->taliF = WMCreateFrame(panel->optF);
2008 WMResizeWidget(panel->taliF, 110, 80);
2009 WMMoveWidget(panel->taliF, 15, 100);
2010 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
2012 for (i = 0; i < 3; i++) {
2013 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
2014 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
2015 switch (i) {
2016 case 0:
2017 WMSetButtonText(panel->taliB[i], _("Left"));
2018 break;
2019 case 1:
2020 WMSetButtonText(panel->taliB[i], _("Center"));
2021 break;
2022 case 2:
2023 WMSetButtonText(panel->taliB[i], _("Right"));
2024 break;
2026 WMResizeWidget(panel->taliB[i], 90, 18);
2027 WMMoveWidget(panel->taliB[i], 10, 15 + 20*i);
2029 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
2030 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
2032 WMMapSubwidgets(panel->taliF);
2034 WMMapSubwidgets(panel->optF);
2036 /**/
2038 WMRealizeWidget(panel->box);
2039 WMMapSubwidgets(panel->box);
2041 WMSetPopUpButtonSelectedItem(panel->secP, 0);
2043 showData(panel);
2045 changePage(panel->secP, panel);
2047 fillTextureList(panel->texLs);
2049 fillColorList(panel);
2051 panel->texturePanel = CreateTexturePanel(panel->parent);
2056 static void
2057 setupTextureFor(WMList *list, char *key, char *defValue, char *title,
2058 int index)
2060 WMListItem *item;
2061 TextureListItem *titem;
2063 titem = wmalloc(sizeof(TextureListItem));
2064 memset(titem, 0, sizeof(TextureListItem));
2066 titem->title = wstrdup(title);
2067 titem->prop = GetObjectForKey(key);
2068 if (!titem->prop || !WMIsPLArray(titem->prop)) {
2069 /* Maybe also give a error message to stderr that the entry is bad? */
2070 titem->prop = WMCreatePropListFromDescription(defValue);
2071 } else {
2072 WMRetainPropList(titem->prop);
2074 titem->texture = WMGetPropListDescription((WMPropList*)titem->prop, False);
2075 titem->current = 1;
2076 titem->selectedFor = 1<<index;
2078 titem->ispixmap = isPixmap(titem->prop);
2080 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop,
2081 TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
2083 item = WMAddListItem(list, "");
2084 item->clientData = titem;
2089 static void
2090 showData(_Panel *panel)
2092 int i;
2093 char *str;
2095 str = GetStringForKey("MenuStyle");
2096 if (str && strcasecmp(str, "flat")==0) {
2097 panel->menuStyle = MSTYLE_FLAT;
2098 } else if (str && strcasecmp(str, "singletexture")==0) {
2099 panel->menuStyle = MSTYLE_SINGLE;
2100 } else {
2101 panel->menuStyle = MSTYLE_NORMAL;
2104 str = GetStringForKey("TitleJustify");
2105 if (str && strcasecmp(str, "left")==0) {
2106 panel->titleAlignment = WALeft;
2107 } else if (str && strcasecmp(str, "right")==0) {
2108 panel->titleAlignment = WARight;
2109 } else {
2110 panel->titleAlignment = WACenter;
2113 for (i = 0; i < sizeof(colorOptions)/(2*sizeof(char*)); i++) {
2114 WMColor *color;
2116 str = GetStringForKey(colorOptions[i*2]);
2117 if (!str)
2118 str = colorOptions[i*2+1];
2120 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->box), str, False))) {
2121 color = WMCreateNamedColor(WMWidgetScreen(panel->box), "#000000", False);
2124 panel->colors[i] = color;
2126 changeColorPage(panel->colP, panel);
2128 for (i = 0; i < sizeof(textureOptions)/(3*sizeof(char*)); i++) {
2129 setupTextureFor(panel->texLs, textureOptions[i*3],
2130 textureOptions[i*3+1], textureOptions[i*3+2], i);
2131 panel->textureIndex[i] = i;
2133 updatePreviewBox(panel, EVERYTHING);
2135 WMSetButtonSelected(panel->mstyB[panel->menuStyle], True);
2136 WMSetButtonSelected(panel->taliB[panel->titleAlignment], True);
2140 static void
2141 storeData(_Panel *panel)
2143 TextureListItem *titem;
2144 WMListItem *item;
2145 int i;
2147 for (i = 0; i < sizeof(textureOptions)/(sizeof(char*)*3); i++) {
2148 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2149 titem = (TextureListItem*)item->clientData;
2150 SetObjectForKey(titem->prop, textureOptions[i*3]);
2153 for (i = 0; i < 8; i++) {
2154 char *str;
2156 str = WMGetColorRGBDescription(panel->colors[i]);
2158 if (str) {
2159 SetStringForKey(str, colorOptions[i*2]);
2160 wfree(str);
2164 switch (panel->menuStyle) {
2165 case MSTYLE_SINGLE:
2166 SetStringForKey("singletexture", "MenuStyle");
2167 break;
2168 case MSTYLE_FLAT:
2169 SetStringForKey("flat", "MenuStyle");
2170 break;
2171 default:
2172 case MSTYLE_NORMAL:
2173 SetStringForKey("normal", "MenuStyle");
2174 break;
2176 switch (panel->titleAlignment) {
2177 case WALeft:
2178 SetStringForKey("left", "TitleJustify");
2179 break;
2180 case WARight:
2181 SetStringForKey("right", "TitleJustify");
2182 break;
2183 default:
2184 case WACenter:
2185 SetStringForKey("center", "TitleJustify");
2186 break;
2191 static void
2192 prepareForClose(_Panel *panel)
2194 WMPropList *textureList;
2195 WMPropList *texture;
2196 TextureListItem *titem;
2197 WMListItem *item;
2198 WMUserDefaults *udb = WMGetStandardUserDefaults();
2199 int i;
2201 textureList = WMCreatePLArray(NULL, NULL);
2203 /* store list of textures */
2204 for (i = 7; i < WMGetListNumberOfRows(panel->texLs); i++) {
2205 item = WMGetListItem(panel->texLs, i);
2206 titem = (TextureListItem*)item->clientData;
2208 texture = WMCreatePLArray(WMCreatePLString(titem->title),
2209 WMRetainPropList(titem->prop),
2210 WMCreatePLString(titem->path),
2211 NULL);
2213 WMAddToPLArray(textureList, texture);
2216 WMSetUDObjectForKey(udb, textureList, "TextureList");
2217 WMReleasePropList(textureList);
2219 /* store list of colors */
2220 textureList = WMCreatePLArray(NULL, NULL);
2221 for (i = 0; i < 24; i++) {
2222 WMColor *color;
2223 char *str;
2225 color = WMGetColorWellColor(panel->sampW[i]);
2227 str = WMGetColorRGBDescription(color);
2228 WMAddToPLArray(textureList, WMCreatePLString(str));
2229 wfree(str);
2231 WMSetUDObjectForKey(udb, textureList, "ColorList");
2232 WMReleasePropList(textureList);
2234 WMSynchronizeUserDefaults(udb);
2239 Panel*
2240 InitAppearance(WMScreen *scr, WMWindow *win)
2242 _Panel *panel;
2244 panel = wmalloc(sizeof(_Panel));
2245 memset(panel, 0, sizeof(_Panel));
2247 panel->sectionName = _("Appearance Preferences");
2249 panel->description = _("Background texture configuration for windows,\n"
2250 "menus and icons.");
2252 panel->parent = win;
2254 panel->callbacks.createWidgets = createPanel;
2255 panel->callbacks.updateDomain = storeData;
2256 panel->callbacks.prepareForClose = prepareForClose;
2258 AddSection(panel, ICON_FILE);
2260 return panel;
2265 /****************************************************************************/
2269 typedef struct ExtractPanel {
2270 WMWindow *win;
2272 WMLabel *label;
2273 WMList *list;
2275 WMButton *closeB;
2276 WMButton *extrB;
2277 } ExtractPanel;
2281 static void
2282 OpenExtractPanelFor(_Panel *panel, char *path)
2284 ExtractPanel *epanel;
2285 WMColor *color;
2286 WMFont *font;
2287 WMScreen *scr = WMWidgetScreen(panel->parent);
2289 epanel = wmalloc(sizeof(ExtractPanel));
2290 epanel->win = WMCreatePanelWithStyleForWindow(panel->parent, "extract",
2291 WMTitledWindowMask
2292 |WMClosableWindowMask);
2293 WMResizeWidget(epanel->win, 245, 250);
2294 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2296 epanel->label = WMCreateLabel(epanel->win);
2297 WMResizeWidget(epanel->label, 225, 18);
2298 WMMoveWidget(epanel->label, 10, 10);
2299 WMSetLabelTextAlignment(epanel->label, WACenter);
2300 WMSetLabelRelief(epanel->label, WRSunken);
2302 color = WMDarkGrayColor(scr);
2303 WMSetWidgetBackgroundColor(epanel->label, color);
2304 WMReleaseColor(color);
2306 color = WMWhiteColor(scr);
2307 WMSetLabelTextColor(epanel->label, color);
2308 WMReleaseColor(color);
2310 font = WMBoldSystemFontOfSize(scr, 12);
2311 WMSetLabelFont(epanel->label, font);
2312 WMReleaseFont(font);
2314 WMSetLabelText(epanel->label, _("Textures"));
2316 epanel->list = WMCreateList(epanel->win);
2317 WMResizeWidget(epanel->list, 225, 165);
2318 WMMoveWidget(epanel->list, 10, 30);
2322 epanel->closeB = WMCreateCommandButton(epanel->win);
2323 WMResizeWidget(epanel->closeB, 74, 24);
2324 WMMoveWidget(epanel->closeB, 165, 215);
2325 WMSetButtonText(epanel->closeB, _("Close"));
2327 epanel->extrB = WMCreateCommandButton(epanel->win);
2328 WMResizeWidget(epanel->extrB, 74, 24);
2329 WMMoveWidget(epanel->extrB, 80, 215);
2330 WMSetButtonText(epanel->extrB, _("Extract"));
2332 WMMapSubwidgets(epanel->win);
2335 /* take textures from file */
2339 WMRealizeWidget(epanel->win);
2341 WMMapWidget(epanel->win);