- Added a test in configure for the version of libPropList that is installed
[wmaker-crm.git] / WPrefs.app / Appearance.c
blob0932759f8e9643ba861ad18bd52cfdc676debb10
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;
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 /* */
87 int textureIndex[8];
89 WMFont *smallFont;
90 WMFont *normalFont;
91 WMFont *boldFont;
93 TexturePanel *texturePanel;
95 WMPixmap *onLed;
96 WMPixmap *offLed;
97 WMPixmap *hand;
99 int oldsection;
100 int oldcsection;
102 char oldTabItem;
104 char menuStyle;
106 char titleAlignment;
108 Pixmap preview;
110 char *fprefix;
111 } _Panel;
114 typedef struct {
115 char *title;
116 char *texture;
117 proplist_t prop;
118 Pixmap preview;
120 char *path;
122 char selectedFor;
123 unsigned current:1;
124 unsigned ispixmap:1;
125 } TextureListItem;
127 static void updateColorPreviewBox(_Panel *panel, int elements);
129 static void showData(_Panel *panel);
131 static void changePage(WMWidget *w, void *data);
133 static void changeColorPage(WMWidget *w, void *data);
135 static void OpenExtractPanelFor(_Panel *panel, char *path);
139 static void changedTabItem(struct WMTabViewDelegate *self, WMTabView *tabView,
140 WMTabViewItem *item);
144 static WMTabViewDelegate tabviewDelegate = {
145 NULL,
146 NULL, /* didChangeNumberOfItems */
147 changedTabItem, /* didSelectItem */
148 NULL, /* shouldSelectItem */
149 NULL /* willSelectItem */
153 #define ICON_FILE "appearance"
155 #define TNEW_FILE "tnew"
156 #define TDEL_FILE "tdel"
157 #define TEDIT_FILE "tedit"
158 #define TEXTR_FILE "textr"
160 #define MSTYLE1_FILE "msty1"
161 #define MSTYLE2_FILE "msty2"
162 #define MSTYLE3_FILE "msty3"
165 /* XPM */
166 static char * blueled_xpm[] = {
167 "8 8 17 1",
168 " c None",
169 ". c #020204",
170 "+ c #16B6FC",
171 "@ c #176AFC",
172 "# c #163AFC",
173 "$ c #72D2FC",
174 "% c #224CF4",
175 "& c #76D6FC",
176 "* c #16AAFC",
177 "= c #CEE9FC",
178 "- c #229EFC",
179 "; c #164CFC",
180 "> c #FAFEFC",
181 ", c #2482FC",
182 "' c #1652FC",
183 ") c #1E76FC",
184 "! c #1A60FC",
185 " .... ",
186 " .=>-@. ",
187 ".=>$@@'.",
188 ".=$@!;;.",
189 ".!@*+!#.",
190 ".#'*+*,.",
191 " .@)@,. ",
192 " .... "};
195 /* XPM */
196 static char *blueled2_xpm[] = {
197 /* width height num_colors chars_per_pixel */
198 " 8 8 17 1",
199 /* colors */
200 ". c None",
201 "# c #090909",
202 "a c #4b63a4",
203 "b c #011578",
204 "c c #264194",
205 "d c #04338c",
206 "e c #989dac",
207 "f c #011a7c",
208 "g c #465c9c",
209 "h c #03278a",
210 "i c #6175ac",
211 "j c #011e74",
212 "k c #043a90",
213 "l c #042f94",
214 "m c #0933a4",
215 "n c #022184",
216 "o c #012998",
217 /* pixels */
218 "..####..",
219 ".#aimn#.",
220 "#aechnf#",
221 "#gchnjf#",
222 "#jndknb#",
223 "#bjdddl#",
224 ".#nono#.",
225 "..####.."
229 /* XPM */
230 static char * hand_xpm[] = {
231 "22 21 19 1",
232 " c None",
233 ". c #030305",
234 "+ c #7F7F7E",
235 "@ c #B5B5B6",
236 "# c #C5C5C6",
237 "$ c #969697",
238 "% c #FDFDFB",
239 "& c #F2F2F4",
240 "* c #E5E5E4",
241 "= c #ECECEC",
242 "- c #DCDCDC",
243 "; c #D2D2D0",
244 "> c #101010",
245 ", c #767674",
246 "' c #676767",
247 ") c #535355",
248 "! c #323234",
249 "~ c #3E3C56",
250 "{ c #333147",
251 " ",
252 " ..... ",
253 " ..+@##$. ",
254 " .%%%&@.......... ",
255 " .%*%%&#%%%%%%%%%$. ",
256 " .*#%%%%%%%%%&&&&==. ",
257 " .-%%%%%%%%%=*-;;;#$. ",
258 " .-%%%%%%%%&..>..... ",
259 " >-%%%%%%%%%*#+. ",
260 " >-%%%%%%%%%*@,. ",
261 " >#%%%%%%%%%*@'. ",
262 " >$&&%%%%%%=... ",
263 " .+@@;=&%%&;$,> ",
264 " .',$@####$+). ",
265 " .!',+$++,'. ",
266 " ..>>>>>. ",
267 " ",
268 " ~~{{{~~ ",
269 " {{{{{{{{{{{ ",
270 " ~~{{{~~ ",
271 " "};
275 static char *sampleColors[] = {
276 "black",
277 "#292929",
278 "#525252",
279 "#848484",
280 "#adadad",
281 "#d6d6d6",
282 "white",
283 "#d6d68c",
284 "#d6a57b",
285 "#8cd68c",
286 "#8cd6ce",
287 "#d68c8c",
288 "#8c9cd6",
289 "#bd86d6",
290 "#d68cbd",
291 "#d64a4a",
292 "#4a5ad6",
293 "#4ad6ce",
294 "#4ad65a",
295 "#ced64a",
296 "#d6844a",
297 "#8ad631",
298 "#ce29c6",
299 "#ce2973",
300 "black"
304 static char *textureOptions[] = {
305 "FTitleBack", "(solid, black)", "[Focused]",
306 "UTitleBack", "(solid, gray)", "[Unfocused]",
307 "PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
308 "ResizebarBack", "(solid, gray)", "[Resizebar]",
309 "MenuTitleBack", "(solid, black)", "[Menu Title]",
310 "MenuTextBack", "(solid, gray)", "[Menu Item]",
311 "IconBack", "(solid, gray)", "[Icon]"
315 #define RESIZEBAR_BEVEL -1
316 #define MENU_BEVEL -2
318 #define TEXPREV_WIDTH 40
319 #define TEXPREV_HEIGHT 24
322 #define MSTYLE_NORMAL 0
323 #define MSTYLE_SINGLE 1
324 #define MSTYLE_FLAT 2
327 #define FTITLE_COL (1<<0)
328 #define UTITLE_COL (1<<1)
329 #define OTITLE_COL (1<<2)
330 #define MTITLE_COL (1<<3)
331 #define MITEM_COL (1<<4)
332 #define MDISAB_COL (1<<5)
333 #define MHIGH_COL (1<<6)
334 #define MHIGHT_COL (1<<7)
335 #define ICONT_COL (1<<8)
336 #define ICONB_COL (1<<9)
337 #define CLIP_COL (1<<10)
338 #define CCLIP_COL (1<<11)
341 static char *colorOptions[] = {
342 "FTitleColor", "white",
343 "UTitleColor", "black",
344 "PTitleColor", "white",
345 "MenuTitleColor", "white",
346 "MenuTextColor", "black",
347 "MenuDisabledColor", "#616161",
348 "HighlightColor", "white",
349 "HighlightTextColor", "black",
350 "IconTitleColor", "white",
351 "IconTitleBack", "black",
352 "ClipTitleColor", "black",
353 "CClipTitleColor", "#454045"
359 static WMRect previewPositions[] = {
360 #define PFOCUSED 0
361 {{30,10},{190, 20}},
362 #define PUNFOCUSED 1
363 {{30,40},{190,20}},
364 #define POWNER 2
365 {{30,70},{190,20}},
366 #define PRESIZEBAR 3
367 {{30,100},{190,9}},
368 #define PMTITLE 4
369 {{30,120},{90,20}},
370 #define PMITEM 5
371 {{30,140},{90,20*4}},
372 #define PICON 6
373 {{155,130},{64,64}}
375 #define EVERYTHING 0xff
378 static WMRect previewColorPositions[] = {
379 {{30,10},{190, 20}},
380 {{30,40},{190,20}},
381 {{30,70},{190,20}},
382 {{30,120},{90,20}},
383 {{30,140},{90,20}},
384 {{30,160},{90,20}},
385 {{30,180},{90,20}},
386 {{30,200},{90,20}},
387 {{155,130},{64,64}},
388 {{155,130},{64,64}},
389 {{155,130},{64,64}},
390 {{155,130},{64,64}}
395 static void
396 str2rcolor(RContext *rc, char *name, RColor *color)
398 XColor xcolor;
400 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
402 color->alpha = 255;
403 color->red = xcolor.red >> 8;
404 color->green = xcolor.green >> 8;
405 color->blue = xcolor.blue >> 8;
409 static void
410 dumpRImage(char *path, RImage *image)
412 FILE *f;
413 int channels = (image->format == RRGBAFormat ? 4 : 3);
415 f = fopen(path, "w");
416 if (!f) {
417 wsyserror(path);
418 return;
420 fprintf(f, "%02x%02x%1x", image->width, image->height, channels);
422 fwrite(image->data, 1, image->width * image->height * channels, f);
424 if (fclose(f) < 0) {
425 wsyserror(path);
431 static int
432 isPixmap(proplist_t prop)
434 proplist_t p;
435 char *s;
437 p = PLGetArrayElement(prop, 0);
438 s = PLGetString(p);
439 if (strcasecmp(&s[1], "pixmap")==0)
440 return 1;
441 else
442 return 0;
446 /**********************************************************************/
448 static void
449 drawResizebarBevel(RImage *img)
451 RColor light;
452 RColor dark;
453 RColor black;
454 int width = img->width;
455 int height = img->height;
456 int cwidth = 28;
458 black.alpha = 255;
459 black.red = black.green = black.blue = 0;
461 light.alpha = 0;
462 light.red = light.green = light.blue = 80;
464 dark.alpha = 0;
465 dark.red = dark.green = dark.blue = 40;
467 ROperateLine(img, RSubtractOperation, 0, 0, width-1, 0, &dark);
468 ROperateLine(img, RAddOperation, 0, 1, width-1, 1, &light);
470 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height-1, &dark);
471 ROperateLine(img, RAddOperation, cwidth+1, 2, cwidth+1, height-1, &light);
473 ROperateLine(img, RSubtractOperation, width-cwidth-2, 2, width-cwidth-2,
474 height-1, &dark);
475 ROperateLine(img, RAddOperation, width-cwidth-1, 2, width-cwidth-1,
476 height-1, &light);
478 RDrawLine(img, 0, height-1, width-1, height-1, &black);
479 RDrawLine(img, 0, 0, 0, height-1, &black);
480 RDrawLine(img, width-1, 0, width-1, height-1, &black);
484 static void
485 drawMenuBevel(RImage *img)
487 RColor light, dark, mid;
488 int i;
489 int iheight = img->height / 4;
491 light.alpha = 0;
492 light.red = light.green = light.blue = 80;
494 dark.alpha = 255;
495 dark.red = dark.green = dark.blue = 0;
497 mid.alpha = 0;
498 mid.red = mid.green = mid.blue = 40;
500 for (i = 1; i < 4; i++) {
501 ROperateLine(img, RSubtractOperation, 0, i*iheight-2,
502 img->width-1, i*iheight-2, &mid);
504 RDrawLine(img, 0, i*iheight-1, img->width-1, i*iheight-1, &dark);
506 ROperateLine(img, RAddOperation, 1, i*iheight,
507 img->width-2, i*iheight, &light);
512 static Pixmap
513 renderTexture(WMScreen *scr, proplist_t texture, int width, int height,
514 char *path, int border)
516 char *type;
517 RImage *image = NULL;
518 Pixmap pixmap;
519 RContext *rc = WMScreenRContext(scr);
520 char *str;
521 RColor rcolor;
524 type = PLGetString(PLGetArrayElement(texture, 0));
526 if (strcasecmp(type, "solid")==0) {
528 str = PLGetString(PLGetArrayElement(texture, 1));
530 str2rcolor(rc, str, &rcolor);
532 image = RCreateImage(width, height, False);
533 RClearImage(image, &rcolor);
534 } else if (strcasecmp(&type[1], "gradient")==0) {
535 int style;
536 RColor rcolor2;
538 switch (toupper(type[0])) {
539 case 'V':
540 style = RVerticalGradient;
541 break;
542 case 'H':
543 style = RHorizontalGradient;
544 break;
545 default:
546 case 'D':
547 style = RDiagonalGradient;
548 break;
551 str = PLGetString(PLGetArrayElement(texture, 1));
552 str2rcolor(rc, str, &rcolor);
553 str = PLGetString(PLGetArrayElement(texture, 2));
554 str2rcolor(rc, str, &rcolor2);
556 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
557 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='T') {
558 int style;
559 RColor rcolor2;
560 int i;
561 RImage *grad, *timage;
562 char *path;
564 switch (toupper(type[1])) {
565 case 'V':
566 style = RVerticalGradient;
567 break;
568 case 'H':
569 style = RHorizontalGradient;
570 break;
571 default:
572 case 'D':
573 style = RDiagonalGradient;
574 break;
577 str = PLGetString(PLGetArrayElement(texture, 3));
578 str2rcolor(rc, str, &rcolor);
579 str = PLGetString(PLGetArrayElement(texture, 4));
580 str2rcolor(rc, str, &rcolor2);
582 str = PLGetString(PLGetArrayElement(texture, 1));
584 if ((path=wfindfileinarray(GetObjectForKey("PixmapPath"), str))!=NULL)
585 timage = RLoadImage(rc, path, 0);
587 if (!path || !timage) {
588 wwarning("could not load file '%s': %s", path,
589 RMessageForError(RErrorCode));
590 } else {
591 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
593 image = RMakeTiledImage(timage, width, height);
594 RDestroyImage(timage);
596 i = atoi(PLGetString(PLGetArrayElement(texture, 2)));
598 RCombineImagesWithOpaqueness(image, grad, i);
599 RDestroyImage(grad);
601 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='M') {
602 int style;
603 RColor **colors;
604 int i, j;
606 switch (toupper(type[1])) {
607 case 'V':
608 style = RVerticalGradient;
609 break;
610 case 'H':
611 style = RHorizontalGradient;
612 break;
613 default:
614 case 'D':
615 style = RDiagonalGradient;
616 break;
619 j = PLGetNumberOfElements(texture);
621 if (j > 0) {
622 colors = wmalloc(j * sizeof(RColor*));
624 for (i = 2; i < j; i++) {
625 str = PLGetString(PLGetArrayElement(texture, i));
626 colors[i-2] = wmalloc(sizeof(RColor));
627 str2rcolor(rc, str, colors[i-2]);
629 colors[i-2] = NULL;
631 image = RRenderMultiGradient(width, height, colors, style);
633 for (i = 0; colors[i]!=NULL; i++)
634 free(colors[i]);
635 free(colors);
637 } else if (strcasecmp(&type[1], "pixmap")==0) {
638 RImage *timage = NULL;
639 char *path;
640 RColor color;
642 str = PLGetString(PLGetArrayElement(texture, 1));
644 if ((path=wfindfileinarray(GetObjectForKey("PixmapPath"), str))!=NULL)
645 timage = RLoadImage(rc, path, 0);
647 if (!path || !timage) {
648 wwarning("could not load file '%s': %s", path ? path : str,
649 RMessageForError(RErrorCode));
650 } else {
651 str = PLGetString(PLGetArrayElement(texture, 2));
652 str2rcolor(rc, str, &color);
654 switch (toupper(type[0])) {
655 case 'T':
656 image = RMakeTiledImage(timage, width, height);
657 RDestroyImage(timage);
658 timage = image;
659 break;
660 case 'C':
661 image = RMakeCenteredImage(timage, width, height, &color);
662 RDestroyImage(timage);
663 timage = image;
664 break;
665 case 'S':
666 case 'M':
667 image = RScaleImage(timage, width, height);
668 RDestroyImage(timage);
669 timage = image;
670 break;
674 free(path);
677 if (!image)
678 return None;
680 if (path) {
681 dumpRImage(path, image);
684 if (border < 0) {
685 if (border == RESIZEBAR_BEVEL) {
686 drawResizebarBevel(image);
687 } else if (border == MENU_BEVEL) {
688 drawMenuBevel(image);
689 RBevelImage(image, RBEV_RAISED2);
691 } else if (border) {
692 RBevelImage(image, border);
695 RConvertImage(rc, image, &pixmap);
696 RDestroyImage(image);
698 return pixmap;
702 static Pixmap
703 renderMenu(_Panel *panel, proplist_t texture, int width, int iheight)
705 WMScreen *scr = WMWidgetScreen(panel->win);
706 Display *dpy = WMScreenDisplay(scr);
707 Pixmap pix, tmp;
708 GC gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
709 int i;
711 switch (panel->menuStyle) {
712 case MSTYLE_NORMAL:
713 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
715 pix = XCreatePixmap(dpy, tmp, width, iheight*4, WMScreenDepth(scr));
716 for (i = 0; i < 4; i++) {
717 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight*i);
719 XFreePixmap(dpy, tmp);
720 break;
721 case MSTYLE_SINGLE:
722 pix = renderTexture(scr, texture, width, iheight*4, NULL, MENU_BEVEL);
723 break;
724 case MSTYLE_FLAT:
725 pix = renderTexture(scr, texture, width, iheight*4, NULL, RBEV_RAISED2);
726 break;
728 XFreeGC(dpy, gc);
730 return pix;
734 static void
735 renderPreview(_Panel *panel, GC gc, int part, int relief)
737 WMListItem *item;
738 TextureListItem *titem;
739 Pixmap pix;
740 WMScreen *scr = WMWidgetScreen(panel->frame);
742 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
743 titem = (TextureListItem*)item->clientData;
745 pix = renderTexture(scr, titem->prop,
746 previewPositions[part].size.width,
747 previewPositions[part].size.height,
748 NULL, relief);
750 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
751 previewPositions[part].size.width,
752 previewPositions[part].size.height,
753 previewPositions[part].pos.x,
754 previewPositions[part].pos.y);
756 XFreePixmap(WMScreenDisplay(scr), pix);
760 static void
761 updatePreviewBox(_Panel *panel, int elements)
763 WMScreen *scr = WMWidgetScreen(panel->win);
764 Display *dpy = WMScreenDisplay(scr);
765 /* RContext *rc = WMScreenRContext(scr);*/
766 int refresh = 0;
767 Pixmap pix;
768 GC gc;
769 int colorUpdate = 0;
770 WMColor *black = WMBlackColor(scr);
772 gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
775 if (panel->preview == None) {
776 WMColor *color;
778 panel->preview = XCreatePixmap(dpy, WMWidgetXID(panel->win),
779 240-4, 215-4, WMScreenDepth(scr));
781 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
782 XFillRectangle(dpy, panel->preview, WMColorGC(color),
783 0, 0, 240-4, 215-4);
784 WMReleaseColor(color);
786 refresh = -1;
790 if (elements & (1<<PFOCUSED)) {
791 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
792 XDrawRectangle(dpy, panel->preview, WMColorGC(black),
793 previewPositions[PFOCUSED].pos.x-1,
794 previewPositions[PFOCUSED].pos.y-1,
795 previewPositions[PFOCUSED].size.width,
796 previewPositions[PFOCUSED].size.height);
797 colorUpdate |= FTITLE_COL;
799 if (elements & (1<<PUNFOCUSED)) {
800 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
801 XDrawRectangle(dpy, panel->preview, WMColorGC(black),
802 previewPositions[PUNFOCUSED].pos.x-1,
803 previewPositions[PUNFOCUSED].pos.y-1,
804 previewPositions[PUNFOCUSED].size.width,
805 previewPositions[PUNFOCUSED].size.height);
806 colorUpdate |= UTITLE_COL;
808 if (elements & (1<<POWNER)) {
809 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
810 XDrawRectangle(dpy, panel->preview, WMColorGC(black),
811 previewPositions[POWNER].pos.x-1,
812 previewPositions[POWNER].pos.y-1,
813 previewPositions[POWNER].size.width,
814 previewPositions[POWNER].size.height);
815 colorUpdate |= OTITLE_COL;
817 if (elements & (1<<PRESIZEBAR)) {
818 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
820 if (elements & (1<<PMTITLE)) {
821 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
822 colorUpdate |= MTITLE_COL;
824 if (elements & (1<<PMITEM)) {
825 WMListItem *item;
826 TextureListItem *titem;
828 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
829 titem = (TextureListItem*)item->clientData;
831 pix = renderMenu(panel, titem->prop,
832 previewPositions[PMITEM].size.width,
833 previewPositions[PMITEM].size.height/4);
835 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
836 previewPositions[PMITEM].size.width,
837 previewPositions[PMITEM].size.height,
838 previewPositions[PMITEM].pos.x,
839 previewPositions[PMITEM].pos.y);
841 XFreePixmap(dpy, pix);
843 colorUpdate |= MITEM_COL|MDISAB_COL|MHIGH_COL|MHIGHT_COL;
845 if (elements & (1<<PMITEM|1<<PMTITLE)) {
846 XDrawLine(dpy, panel->preview, gc, 29, 120, 29, 120+20*4+20);
847 XDrawLine(dpy, panel->preview, gc, 29, 119, 119, 119);
849 if (elements & (1<<PICON)) {
850 WMListItem *item;
851 TextureListItem *titem;
853 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
854 titem = (TextureListItem*)item->clientData;
856 renderPreview(panel, gc, PICON,
857 titem->ispixmap ? 0 : RBEV_RAISED3);
859 colorUpdate |= ICONT_COL|ICONB_COL|CLIP_COL|CCLIP_COL;
861 if (refresh < 0) {
862 WMPixmap *p;
864 p = WMCreatePixmapFromXPixmaps(scr, panel->preview, None,
865 240-4, 215-4, WMScreenDepth(scr));
867 WMSetLabelImage(panel->prevL, p);
868 WMReleasePixmap(p);
870 if (colorUpdate)
871 updateColorPreviewBox(panel, colorUpdate);
872 } else {
873 if (colorUpdate)
874 updateColorPreviewBox(panel, colorUpdate);
875 else
876 WMRedisplayWidget(panel->prevL);
879 XFreeGC(dpy, gc);
880 WMReleaseColor(black);
886 static void
887 cancelNewTexture(void *data)
889 _Panel *panel = (_Panel*)data;
891 HideTexturePanel(panel->texturePanel);
897 static char*
898 makeFileName(char *prefix)
900 char *fname;
902 fname = wstrdup(prefix);
904 while (access(fname, F_OK)==0) {
905 char buf[30];
907 free(fname);
908 sprintf(buf, "%08lx.cache", time(NULL));
909 fname = wstrappend(prefix, buf);
912 return fname;
918 static void
919 okNewTexture(void *data)
921 _Panel *panel = (_Panel*)data;
922 WMListItem *item;
923 char *name;
924 char *str;
925 proplist_t prop;
926 TextureListItem *titem;
927 WMScreen *scr = WMWidgetScreen(panel->win);
929 titem = wmalloc(sizeof(TextureListItem));
930 memset(titem, 0, sizeof(TextureListItem));
932 HideTexturePanel(panel->texturePanel);
934 name = GetTexturePanelTextureName(panel->texturePanel);
936 prop = GetTexturePanelTexture(panel->texturePanel);
938 str = PLGetDescription(prop);
940 titem->title = name;
941 titem->prop = prop;
942 titem->texture = str;
943 titem->selectedFor = 0;
945 titem->ispixmap = isPixmap(prop);
947 titem->path = makeFileName(panel->fprefix);
948 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT,
949 titem->path, 0);
951 item = WMAddListItem(panel->texLs, "");
952 item->clientData = titem;
954 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
958 static void
959 okEditTexture(void *data)
961 _Panel *panel = (_Panel*)data;
962 WMListItem *item;
963 char *name;
964 char *str;
965 proplist_t prop;
966 TextureListItem *titem;
968 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
969 titem = (TextureListItem*)item->clientData;
971 HideTexturePanel(panel->texturePanel);
973 if (titem->current) {
974 name = GetTexturePanelTextureName(panel->texturePanel);
976 free(titem->title);
977 titem->title = name;
980 prop = GetTexturePanelTexture(panel->texturePanel);
982 str = PLGetDescription(prop);
984 PLRelease(titem->prop);
985 titem->prop = prop;
987 titem->ispixmap = isPixmap(prop);
989 free(titem->texture);
990 titem->texture = str;
992 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
993 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
994 TEXPREV_WIDTH, TEXPREV_HEIGHT,
995 titem->path, 0);
997 WMRedisplayWidget(panel->texLs);
999 if (titem->selectedFor)
1000 updatePreviewBox(panel, titem->selectedFor);
1002 changePage(panel->secP, panel);
1007 static void
1008 editTexture(WMWidget *w, void *data)
1010 _Panel *panel = (_Panel*)data;
1011 WMListItem *item;
1012 TextureListItem *titem;
1014 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
1015 titem = (TextureListItem*)item->clientData;
1017 SetTexturePanelPixmapPath(panel->texturePanel,
1018 GetObjectForKey("PixmapPath"));
1020 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
1022 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1023 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
1025 ShowTexturePanel(panel->texturePanel);
1030 static void
1031 newTexture(WMWidget *w, void *data)
1033 _Panel *panel = (_Panel*)data;
1035 SetTexturePanelPixmapPath(panel->texturePanel,
1036 GetObjectForKey("PixmapPath"));
1038 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1040 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1042 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1044 ShowTexturePanel(panel->texturePanel);
1049 static void
1050 deleteTexture(WMWidget *w, void *data)
1052 _Panel *panel = (_Panel*)data;
1053 WMListItem *item;
1054 TextureListItem *titem;
1055 int row;
1056 int section;
1058 section = WMGetPopUpButtonSelectedItem(panel->secP);
1059 row = WMGetListSelectedItemRow(panel->texLs);
1060 item = WMGetListItem(panel->texLs, row);
1061 titem = (TextureListItem*)item->clientData;
1063 if (titem->selectedFor & (1 << section)) {
1064 TextureListItem *titem2;
1066 panel->textureIndex[section] = section;
1067 item = WMGetListItem(panel->texLs, section);
1068 titem2 = (TextureListItem*)item->clientData;
1069 titem2->selectedFor |= 1 << section;
1072 free(titem->title);
1073 free(titem->texture);
1074 PLRelease(titem->prop);
1075 if (titem->path) {
1076 if (remove(titem->path) < 0 && errno != ENOENT) {
1077 wsyserror("could not remove file %s", titem->path);
1079 free(titem->path);
1082 free(titem);
1084 WMRemoveListItem(panel->texLs, row);
1085 WMSetButtonEnabled(panel->delB, False);
1091 static void
1092 extractTexture(WMWidget *w, void *data)
1094 _Panel *panel = (_Panel*)data;
1095 char *path;
1096 WMOpenPanel *opanel;
1097 WMScreen *scr = WMWidgetScreen(w);
1099 opanel = WMGetOpenPanel(scr);
1100 WMSetFilePanelCanChooseDirectories(opanel, False);
1101 WMSetFilePanelCanChooseFiles(opanel, True);
1103 if (WMRunModalFilePanelForDirectory(opanel, panel->win, wgethomedir(),
1104 _("Select File"), NULL)) {
1105 path = WMGetFilePanelFileName(opanel);
1107 OpenExtractPanelFor(panel, path);
1109 free(path);
1114 static void
1115 changePage(WMWidget *w, void *data)
1117 _Panel *panel = (_Panel*)data;
1118 int section;
1119 WMListItem *item;
1120 TextureListItem *titem;
1121 WMScreen *scr = WMWidgetScreen(panel->frame);
1122 RContext *rc = WMScreenRContext(scr);
1123 static WMPoint positions[] = {
1124 {5, 10},
1125 {5, 40},
1126 {5, 70},
1127 {5, 100},
1128 {5, 120},
1129 {5, 160},
1130 {130, 150}
1133 if (w) {
1134 section = WMGetPopUpButtonSelectedItem(panel->secP);
1136 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1138 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1140 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1142 titem = (TextureListItem*)item->clientData;
1145 WMColor *color;
1147 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
1148 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1149 positions[panel->oldsection].x,
1150 positions[panel->oldsection].y, 22, 22);
1151 WMReleaseColor(color);
1153 if (w) {
1154 panel->oldsection = section;
1155 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1156 positions[section].y);
1158 WMRedisplayWidget(panel->prevL);
1163 static void
1164 previewClick(XEvent *event, void *clientData)
1166 _Panel *panel = (_Panel*)clientData;
1167 int i;
1169 switch (panel->oldTabItem) {
1170 case 0:
1171 for (i = 0; i < sizeof(previewPositions)/sizeof(WMRect); i++) {
1172 if (event->xbutton.x >= previewPositions[i].pos.x
1173 && event->xbutton.y >= previewPositions[i].pos.y
1174 && event->xbutton.x < previewPositions[i].pos.x
1175 + previewPositions[i].size.width
1176 && event->xbutton.y < previewPositions[i].pos.y
1177 + previewPositions[i].size.height) {
1179 WMSetPopUpButtonSelectedItem(panel->secP, i);
1180 changePage(panel->secP, panel);
1181 return;
1184 break;
1185 case 1:
1186 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1187 if (event->xbutton.x >= previewColorPositions[i].pos.x
1188 && event->xbutton.y >= previewColorPositions[i].pos.y
1189 && event->xbutton.x < previewColorPositions[i].pos.x
1190 + previewColorPositions[i].size.width
1191 && event->xbutton.y < previewColorPositions[i].pos.y
1192 + previewColorPositions[i].size.height) {
1194 /* yuck kluge */
1195 if (i == 7)
1196 i = 4;
1198 WMSetPopUpButtonSelectedItem(panel->colP, i);
1199 changeColorPage(panel->colP, panel);
1200 return;
1203 break;
1208 static void
1209 textureClick(WMWidget *w, void *data)
1211 _Panel *panel = (_Panel*)data;
1212 int i;
1213 WMListItem *item;
1214 TextureListItem *titem;
1216 i = WMGetListSelectedItemRow(panel->texLs);
1218 item = WMGetListItem(panel->texLs, i);
1220 titem = (TextureListItem*)item->clientData;
1222 if (titem->current) {
1223 WMSetButtonEnabled(panel->delB, False);
1224 } else {
1225 WMSetButtonEnabled(panel->delB, True);
1231 static void
1232 textureDoubleClick(WMWidget *w, void *data)
1234 _Panel *panel = (_Panel*)data;
1235 int i, section;
1236 WMListItem *item;
1237 TextureListItem *titem;
1239 /* unselect old texture */
1240 section = WMGetPopUpButtonSelectedItem(panel->secP);
1242 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1243 titem = (TextureListItem*)item->clientData;
1244 titem->selectedFor &= ~(1 << section);
1246 /* select new texture */
1247 i = WMGetListSelectedItemRow(panel->texLs);
1249 item = WMGetListItem(panel->texLs, i);
1251 titem = (TextureListItem*)item->clientData;
1253 titem->selectedFor |= 1<<section;
1255 panel->textureIndex[section] = i;
1257 WMRedisplayWidget(panel->texLs);
1259 updatePreviewBox(panel, 1<<section);
1264 static void
1265 paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
1266 WMRect *rect)
1268 _Panel *panel = (_Panel*)WMGetHangedData(lPtr);
1269 WMScreen *scr = WMWidgetScreen(lPtr);
1270 int width, height, x, y;
1271 Display *dpy = WMScreenDisplay(scr);
1272 WMColor *white = WMWhiteColor(scr);
1273 WMListItem *item;
1274 WMColor *black = WMBlackColor(scr);
1275 TextureListItem *titem;
1277 item = WMGetListItem(lPtr, index);
1278 titem = (TextureListItem*)item->clientData;
1279 if (!titem) {
1280 WMReleaseColor(white);
1281 WMReleaseColor(black);
1282 return;
1285 width = rect->size.width;
1286 height = rect->size.height;
1287 x = rect->pos.x;
1288 y = rect->pos.y;
1290 if (state & WLDSSelected)
1291 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
1292 else
1293 XClearArea(dpy, d, x, y, width, height, False);
1296 if (titem->preview)
1297 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1298 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1300 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1301 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1302 else if (titem->selectedFor)
1303 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1305 WMDrawString(scr, d, WMColorGC(black), panel->boldFont,
1306 x + TEXPREV_WIDTH + 22, y + 2, titem->title,
1307 strlen(titem->title));
1309 WMDrawString(scr, d, WMColorGC(black), panel->smallFont,
1310 x + TEXPREV_WIDTH + 14, y + 18, titem->texture,
1311 strlen(titem->texture));
1314 WMReleaseColor(white);
1315 WMReleaseColor(black);
1320 static Pixmap
1321 loadRImage(WMScreen *scr, char *path)
1323 FILE *f;
1324 RImage *image;
1325 int w, h, d;
1326 Pixmap pixmap;
1328 f = fopen(path, "r");
1329 if (!f)
1330 return None;
1332 fscanf(f, "%02x%02x%1x", &w, &h, &d);
1334 image = RCreateImage(w, h, d == 4);
1335 fread(image->data, 1, w*h*d, f);
1336 fclose(f);
1338 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1339 RDestroyImage(image);
1341 return pixmap;
1346 static void
1347 fillTextureList(WMList *lPtr)
1349 proplist_t textureList;
1350 proplist_t texture;
1351 WMUserDefaults *udb = WMGetStandardUserDefaults();
1352 TextureListItem *titem;
1353 WMScreen *scr = WMWidgetScreen(lPtr);
1354 int i;
1356 textureList = WMGetUDObjectForKey(udb, "TextureList");
1357 if (!textureList)
1358 return;
1360 for (i = 0; i < PLGetNumberOfElements(textureList); i++) {
1361 WMListItem *item;
1363 texture = PLGetArrayElement(textureList, i);
1365 titem = wmalloc(sizeof(TextureListItem));
1366 memset(titem, 0, sizeof(TextureListItem));
1368 titem->title = wstrdup(PLGetString(PLGetArrayElement(texture, 0)));
1369 titem->prop = PLRetain(PLGetArrayElement(texture, 1));
1370 titem->texture = PLGetDescription(titem->prop);
1371 titem->selectedFor = 0;
1372 titem->path = wstrdup(PLGetString(PLGetArrayElement(texture, 2)));
1374 titem->preview = loadRImage(scr, titem->path);
1375 if (!titem->preview) {
1376 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH,
1377 TEXPREV_HEIGHT, NULL, 0);
1379 item = WMAddListItem(lPtr, "");
1380 item->clientData = titem;
1385 static void
1386 fillColorList(_Panel *panel)
1388 WMColor *color;
1389 proplist_t list;
1390 WMUserDefaults *udb = WMGetStandardUserDefaults();
1391 WMScreen *scr = WMWidgetScreen(panel->frame);
1392 int i;
1394 list = WMGetUDObjectForKey(udb, "ColorList");
1395 if (!list) {
1396 for (i = 0; i < 24; i++) {
1397 color = WMCreateNamedColor(scr, sampleColors[i], False);
1398 if (!color)
1399 continue;
1400 WMSetColorWellColor(panel->sampW[i], color);
1401 WMReleaseColor(color);
1403 } else {
1404 proplist_t c;
1406 for (i = 0; i < WMIN(24, PLGetNumberOfElements(list)); i++) {
1407 c = PLGetArrayElement(list, i);
1408 if (!c || !PLIsString(c))
1409 continue;
1410 color = WMCreateNamedColor(scr, PLGetString(c), False);
1411 if (!color)
1412 continue;
1413 WMSetColorWellColor(panel->sampW[i], color);
1414 WMReleaseColor(color);
1420 /*************************************************************************/
1423 static void
1424 changeColorPage(WMWidget *w, void *data)
1426 _Panel *panel = (_Panel*)data;
1427 int section;
1428 WMScreen *scr = WMWidgetScreen(panel->frame);
1429 RContext *rc = WMScreenRContext(scr);
1430 static WMPoint positions[] = {
1431 {5, 10},
1432 {5, 40},
1433 {5, 70},
1434 {5, 120},
1435 {5, 140},
1436 {5, 160},
1437 {5, 180},
1438 {5, 180},
1439 {130, 140},
1440 {130, 140},
1441 {130, 140},
1442 {130, 140}
1445 if (panel->preview) {
1446 WMColor *color;
1448 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
1449 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1450 positions[panel->oldcsection].x,
1451 positions[panel->oldcsection].y, 22, 22);
1452 WMReleaseColor(color);
1454 if (w) {
1455 section = WMGetPopUpButtonSelectedItem(panel->colP);
1457 panel->oldcsection = section;
1458 if (panel->preview)
1459 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1460 positions[section].y);
1462 section = WMGetPopUpButtonSelectedItem(panel->colP);
1464 WMSetColorWellColor(panel->colW, panel->colors[section]);
1466 WMRedisplayWidget(panel->prevL);
1470 static void
1471 paintText(WMScreen *scr, Drawable d, WMColor *color, WMFont *font,
1472 int x, int y, int w, int h, WMAlignment align, char *text)
1474 int l = strlen(text);
1476 switch (align) {
1477 case WALeft:
1478 x += 5;
1479 break;
1480 case WARight:
1481 x += w - 5 - WMWidthOfString(font, text, l);
1482 break;
1483 default:
1484 case WACenter:
1485 x += (w - WMWidthOfString(font, text, l))/2;
1486 break;
1488 WMDrawString(scr, d, WMColorGC(color), font, x,
1489 y + (h - WMFontHeight(font))/2, text, l);
1494 static void
1495 updateColorPreviewBox(_Panel *panel, int elements)
1497 WMScreen *scr = WMWidgetScreen(panel->frame);
1498 WMPixmap *pixmap;
1499 Pixmap d;
1501 pixmap = WMGetLabelImage(panel->prevL);
1502 d = WMGetPixmapXID(pixmap);
1504 if (elements & FTITLE_COL) {
1505 paintText(scr, d, panel->colors[0], panel->boldFont, 30, 10, 190, 20,
1506 panel->titleAlignment, _("Focused Window"));
1508 if (elements & UTITLE_COL) {
1509 paintText(scr, d, panel->colors[1], panel->boldFont, 30, 40, 190, 20,
1510 panel->titleAlignment, _("Unfocused Window"));
1512 if (elements & OTITLE_COL) {
1513 paintText(scr, d, panel->colors[2], panel->boldFont, 30, 70, 190, 20,
1514 panel->titleAlignment, _("Owner of Focused Window"));
1516 if (elements & MTITLE_COL) {
1517 paintText(scr, d, panel->colors[3], panel->boldFont, 30, 120, 90, 20,
1518 WALeft, _("Menu Title"));
1520 if (elements & MITEM_COL) {
1521 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 140, 90, 20,
1522 WALeft, _("Normal Item"));
1523 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 200, 90, 20,
1524 WALeft, _("Normal Item"));
1526 if (elements & MDISAB_COL) {
1527 paintText(scr, d, panel->colors[5], panel->normalFont, 30, 160, 90, 20,
1528 WALeft, _("Disabled Item"));
1530 if (elements & MHIGH_COL) {
1531 XFillRectangle(WMScreenDisplay(scr), d, WMColorGC(panel->colors[6]),
1532 31, 181, 87, 17);
1533 elements |= MHIGHT_COL;
1535 if (elements & MHIGHT_COL) {
1536 paintText(scr, d, panel->colors[7], panel->normalFont, 30, 180, 90, 20,
1537 WALeft, _("Highlighted"));
1540 if (elements & ICONT_COL) {
1541 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1542 155, 130, 64);
1544 if (elements & ICONB_COL) {
1545 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1546 0, 0, 30);
1548 if (elements & CLIP_COL) {
1549 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1550 0, 0, 30);
1552 if (elements & CCLIP_COL) {
1553 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1554 0, 0, 30);
1557 WMRedisplayWidget(panel->prevL);
1561 static void
1562 colorWellObserver(void *self, WMNotification *n)
1564 _Panel *panel = (_Panel*)self;
1565 int p;
1567 p = WMGetPopUpButtonSelectedItem(panel->colP);
1569 WMReleaseColor(panel->colors[p]);
1571 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1573 updateColorPreviewBox(panel, 1<<p);
1577 static void
1578 changedTabItem(struct WMTabViewDelegate *self, WMTabView *tabView,
1579 WMTabViewItem *item)
1581 _Panel *panel = self->data;
1582 int i;
1584 i = WMGetTabViewItemIdentifier(item);
1585 switch (i) {
1586 case 0:
1587 switch (panel->oldTabItem) {
1588 case 1:
1589 changeColorPage(NULL, panel);
1590 break;
1592 changePage(panel->secP, panel);
1593 break;
1594 case 1:
1595 switch (panel->oldTabItem) {
1596 case 0:
1597 changePage(NULL, panel);
1598 break;
1600 changeColorPage(panel->colP, panel);
1601 break;
1602 case 2:
1603 switch (panel->oldTabItem) {
1604 case 0:
1605 changePage(NULL, panel);
1606 break;
1607 case 1:
1608 changeColorPage(NULL, panel);
1609 break;
1611 break;
1614 panel->oldTabItem = i;
1618 /*************************************************************************/
1620 static void
1621 menuStyleCallback(WMWidget *self, void *data)
1623 _Panel *panel = (_Panel*)data;
1625 if (self == panel->mstyB[0]) {
1626 panel->menuStyle = MSTYLE_NORMAL;
1627 updatePreviewBox(panel, 1<<PMITEM);
1629 } else if (self == panel->mstyB[1]) {
1630 panel->menuStyle = MSTYLE_SINGLE;
1631 updatePreviewBox(panel, 1<<PMITEM);
1633 } else if (self == panel->mstyB[2]) {
1634 panel->menuStyle = MSTYLE_FLAT;
1635 updatePreviewBox(panel, 1<<PMITEM);
1640 static void
1641 titleAlignCallback(WMWidget *self, void *data)
1643 _Panel *panel = (_Panel*)data;
1645 if (self == panel->taliB[0]) {
1646 panel->titleAlignment = WALeft;
1647 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1649 } else if (self == panel->taliB[1]) {
1650 panel->titleAlignment = WACenter;
1651 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1653 } else if (self == panel->taliB[2]) {
1654 panel->titleAlignment = WARight;
1655 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1660 static void
1661 createPanel(Panel *p)
1663 _Panel *panel = (_Panel*)p;
1664 WMFont *font;
1665 WMScreen *scr = WMWidgetScreen(panel->win);
1666 WMTabViewItem *item;
1667 int i;
1668 char *tmp;
1669 Bool ok = True;
1671 panel->fprefix = wstrappend(wusergnusteppath(), "/.AppInfo");
1673 if (access(panel->fprefix, F_OK)!=0) {
1674 if (mkdir(panel->fprefix, 0755) < 0) {
1675 wsyserror(panel->fprefix);
1676 ok = False;
1679 if (ok) {
1680 tmp = wstrappend(panel->fprefix, "/WPrefs/");
1681 free(panel->fprefix);
1682 panel->fprefix = tmp;
1683 if (access(panel->fprefix, F_OK)!=0) {
1684 if (mkdir(panel->fprefix, 0755) < 0) {
1685 wsyserror(panel->fprefix);
1690 panel->smallFont = WMSystemFontOfSize(scr, 10);
1691 panel->normalFont = WMSystemFontOfSize(scr, 12);
1692 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1694 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1695 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1696 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1698 panel->frame = WMCreateFrame(panel->win);
1699 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
1700 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
1702 /* preview box */
1703 panel->prevL = WMCreateLabel(panel->frame);
1704 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1705 WMMoveWidget(panel->prevL, 15, 10);
1706 WMSetLabelRelief(panel->prevL, WRSunken);
1707 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1709 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask,
1710 previewClick, panel);
1713 /* tabview */
1715 tabviewDelegate.data = panel;
1717 panel->tabv = WMCreateTabView(panel->frame);
1718 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1719 WMMoveWidget(panel->tabv, 265, 10);
1720 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1722 /*** texture list ***/
1724 panel->texF = WMCreateFrame(panel->frame);
1725 WMSetFrameRelief(panel->texF, WRFlat);
1727 item = WMCreateTabViewItemWithIdentifier(0);
1728 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1729 WMSetTabViewItemLabel(item, _("Texture"));
1731 WMAddItemInTabView(panel->tabv, item);
1734 panel->secP = WMCreatePopUpButton(panel->texF);
1735 WMResizeWidget(panel->secP, 228, 20);
1736 WMMoveWidget(panel->secP, 7, 7);
1737 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1738 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1739 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1740 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1741 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1742 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1743 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1744 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1746 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1747 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1749 panel->texLs = WMCreateList(panel->texF);
1750 WMResizeWidget(panel->texLs, 165, 155);
1751 WMMoveWidget(panel->texLs, 70, 33);
1752 WMSetListUserDrawItemHeight(panel->texLs, 35);
1753 WMSetListUserDrawProc(panel->texLs, paintListItem);
1754 WMHangData(panel->texLs, panel);
1755 WMSetListAction(panel->texLs, textureClick, panel);
1756 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1758 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1759 "for the selected item."),
1760 WMWidgetView(panel->texLs));
1762 /* command buttons */
1764 font = WMSystemFontOfSize(scr, 10);
1767 panel->newB = WMCreateCommandButton(panel->texF);
1768 WMResizeWidget(panel->newB, 57, 39);
1769 WMMoveWidget(panel->newB, 7, 33);
1770 WMSetButtonFont(panel->newB, font);
1771 WMSetButtonImagePosition(panel->newB, WIPAbove);
1772 WMSetButtonText(panel->newB, _("New"));
1773 WMSetButtonAction(panel->newB, newTexture, panel);
1774 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1776 WMSetBalloonTextForView(_("Create a new texture."),
1777 WMWidgetView(panel->newB));
1779 panel->ripB = WMCreateCommandButton(panel->texF);
1780 WMResizeWidget(panel->ripB, 57, 39);
1781 WMMoveWidget(panel->ripB, 7, 72);
1782 WMSetButtonFont(panel->ripB, font);
1783 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1784 WMSetButtonText(panel->ripB, _("Extract..."));
1785 WMSetButtonAction(panel->ripB, extractTexture, panel);
1786 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1788 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1789 WMWidgetView(panel->ripB));
1791 WMSetButtonEnabled(panel->ripB, False);
1793 panel->editB = WMCreateCommandButton(panel->texF);
1794 WMResizeWidget(panel->editB, 57, 39);
1795 WMMoveWidget(panel->editB, 7, 111);
1796 WMSetButtonFont(panel->editB, font);
1797 WMSetButtonImagePosition(panel->editB, WIPAbove);
1798 WMSetButtonText(panel->editB, _("Edit"));
1799 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1800 WMSetButtonAction(panel->editB, editTexture, panel);
1801 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1802 WMWidgetView(panel->editB));
1804 panel->delB = WMCreateCommandButton(panel->texF);
1805 WMResizeWidget(panel->delB, 57, 38);
1806 WMMoveWidget(panel->delB, 7, 150);
1807 WMSetButtonFont(panel->delB, font);
1808 WMSetButtonImagePosition(panel->delB, WIPAbove);
1809 WMSetButtonText(panel->delB, _("Delete"));
1810 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1811 WMSetButtonEnabled(panel->delB, False);
1812 WMSetButtonAction(panel->delB, deleteTexture, panel);
1813 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1814 WMWidgetView(panel->delB));
1816 WMReleaseFont(font);
1818 WMMapSubwidgets(panel->texF);
1820 /*** colors ***/
1821 panel->colF = WMCreateFrame(panel->frame);
1822 WMSetFrameRelief(panel->colF, WRFlat);
1824 item = WMCreateTabViewItemWithIdentifier(1);
1825 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1826 WMSetTabViewItemLabel(item, _("Color"));
1828 WMAddItemInTabView(panel->tabv, item);
1830 panel->colP = WMCreatePopUpButton(panel->colF);
1831 WMResizeWidget(panel->colP, 228, 20);
1832 WMMoveWidget(panel->colP, 7, 7);
1833 WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1834 WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1835 WMAddPopUpButtonItem(panel->colP, _("Owner of Focused Window Title"));
1836 WMAddPopUpButtonItem(panel->colP, _("Menu Title"));
1837 WMAddPopUpButtonItem(panel->colP, _("Menu Item Text"));
1838 WMAddPopUpButtonItem(panel->colP, _("Disabled Menu Item Text"));
1839 WMAddPopUpButtonItem(panel->colP, _("Menu Highlight Color"));
1840 WMAddPopUpButtonItem(panel->colP, _("Highlighted Menu Text Color"));
1842 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1843 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1844 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1845 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1848 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1850 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1853 panel->colW = WMCreateColorWell(panel->colF);
1854 WMResizeWidget(panel->colW, 65, 50);
1855 WMMoveWidget(panel->colW, 30, 75);
1856 WMAddNotificationObserver(colorWellObserver, panel,
1857 WMColorWellDidChangeNotification, panel->colW);
1859 for (i = 0; i < 4; i++) {
1860 int j;
1861 for (j = 0; j < 6; j++) {
1862 panel->sampW[i+j*4] = WMCreateColorWell(panel->colF);
1863 WMResizeWidget(panel->sampW[i+j*4], 22, 22);
1864 WMMoveWidget(panel->sampW[i+j*4], 130 + i*22, 40 + j*22);
1865 WSetColorWellBordered(panel->sampW[i+j*4], False);
1869 WMMapSubwidgets(panel->colF);
1871 /*** options ***/
1872 panel->optF = WMCreateFrame(panel->frame);
1873 WMSetFrameRelief(panel->optF, WRFlat);
1875 item = WMCreateTabViewItemWithIdentifier(2);
1876 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1877 WMSetTabViewItemLabel(item, _("Options"));
1879 WMAddItemInTabView(panel->tabv, item);
1881 panel->mstyF = WMCreateFrame(panel->optF);
1882 WMResizeWidget(panel->mstyF, 215, 85);
1883 WMMoveWidget(panel->mstyF, 15, 10);
1884 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1886 for (i = 0; i < 3; i++) {
1887 WMPixmap *icon;
1888 char *path;
1890 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1891 WMResizeWidget(panel->mstyB[i], 54, 54);
1892 WMMoveWidget(panel->mstyB[i], 15 + i*65, 20);
1893 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1894 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1895 switch (i) {
1896 case 0:
1897 path = LocateImage(MSTYLE1_FILE);
1898 break;
1899 case 1:
1900 path = LocateImage(MSTYLE2_FILE);
1901 break;
1902 case 2:
1903 path = LocateImage(MSTYLE3_FILE);
1904 break;
1906 if (path) {
1907 icon = WMCreatePixmapFromFile(scr, path);
1908 if (icon) {
1909 WMSetButtonImage(panel->mstyB[i], icon);
1910 WMReleasePixmap(icon);
1911 } else {
1912 wwarning(_("could not load icon file %s"), path);
1914 free(path);
1917 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
1918 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
1920 WMMapSubwidgets(panel->mstyF);
1923 panel->taliF = WMCreateFrame(panel->optF);
1924 WMResizeWidget(panel->taliF, 110, 80);
1925 WMMoveWidget(panel->taliF, 15, 100);
1926 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
1928 for (i = 0; i < 3; i++) {
1929 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
1930 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
1931 switch (i) {
1932 case 0:
1933 WMSetButtonText(panel->taliB[i], _("Left"));
1934 break;
1935 case 1:
1936 WMSetButtonText(panel->taliB[i], _("Center"));
1937 break;
1938 case 2:
1939 WMSetButtonText(panel->taliB[i], _("Right"));
1940 break;
1942 WMResizeWidget(panel->taliB[i], 90, 18);
1943 WMMoveWidget(panel->taliB[i], 10, 15 + 20*i);
1945 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
1946 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
1948 WMMapSubwidgets(panel->taliF);
1950 WMMapSubwidgets(panel->optF);
1952 /**/
1954 WMRealizeWidget(panel->frame);
1955 WMMapSubwidgets(panel->frame);
1957 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1959 showData(panel);
1961 changePage(panel->secP, panel);
1963 fillTextureList(panel->texLs);
1965 fillColorList(panel);
1967 panel->texturePanel = CreateTexturePanel(panel->win);
1972 static void
1973 setupTextureFor(WMList *list, char *key, char *defValue, char *title,
1974 int index)
1976 WMListItem *item;
1977 TextureListItem *titem;
1979 titem = wmalloc(sizeof(TextureListItem));
1980 memset(titem, 0, sizeof(TextureListItem));
1982 titem->title = wstrdup(title);
1983 titem->prop = GetObjectForKey(key);
1984 if (!titem->prop || !PLIsArray(titem->prop)) {
1985 /* Maybe also give a error message to stderr that the entry is bad? */
1986 titem->prop = PLGetProplistWithDescription(defValue);
1987 } else {
1988 PLRetain(titem->prop);
1990 titem->texture = PLGetDescription((proplist_t)titem->prop);
1991 titem->current = 1;
1992 titem->selectedFor = 1<<index;
1994 titem->ispixmap = isPixmap(titem->prop);
1996 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop,
1997 TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1999 item = WMAddListItem(list, "");
2000 item->clientData = titem;
2005 static void
2006 showData(_Panel *panel)
2008 int i;
2009 char *str;
2011 str = GetStringForKey("MenuStyle");
2012 if (str && strcasecmp(str, "flat")==0) {
2013 panel->menuStyle = MSTYLE_FLAT;
2014 } else if (str && strcasecmp(str, "singletexture")==0) {
2015 panel->menuStyle = MSTYLE_SINGLE;
2016 } else {
2017 panel->menuStyle = MSTYLE_NORMAL;
2020 str = GetStringForKey("TitleJustify");
2021 if (str && strcasecmp(str, "left")==0) {
2022 panel->titleAlignment = WALeft;
2023 } else if (str && strcasecmp(str, "right")==0) {
2024 panel->titleAlignment = WARight;
2025 } else {
2026 panel->titleAlignment = WACenter;
2029 for (i = 0; i < sizeof(colorOptions)/(2*sizeof(char*)); i++) {
2030 WMColor *color;
2032 str = GetStringForKey(colorOptions[i*2]);
2033 if (!str)
2034 str = colorOptions[i*2+1];
2036 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->frame), str, False))) {
2037 color = WMCreateNamedColor(WMWidgetScreen(panel->frame), "#000000", False);
2040 panel->colors[i] = color;
2042 changeColorPage(panel->colP, panel);
2044 for (i = 0; i < sizeof(textureOptions)/(3*sizeof(char*)); i++) {
2045 setupTextureFor(panel->texLs, textureOptions[i*3],
2046 textureOptions[i*3+1], textureOptions[i*3+2], i);
2047 panel->textureIndex[i] = i;
2049 updatePreviewBox(panel, EVERYTHING);
2052 for (i = 0; i < 3; i++) {
2053 WMSetButtonSelected(panel->mstyB[i], i==panel->menuStyle);
2054 WMSetButtonSelected(panel->taliB[i], i==panel->titleAlignment);
2060 static void
2061 storeData(_Panel *panel)
2063 TextureListItem *titem;
2064 WMListItem *item;
2065 int i;
2067 for (i = 0; i < sizeof(textureOptions)/(sizeof(char*)*3); i++) {
2068 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2069 titem = (TextureListItem*)item->clientData;
2070 SetObjectForKey(titem->prop, textureOptions[i*3]);
2073 for (i = 0; i < 8; i++) {
2074 char *str;
2076 str = WMGetColorRGBDescription(panel->colors[i]);
2078 if (str) {
2079 SetStringForKey(str, colorOptions[i*2]);
2080 free(str);
2084 switch (panel->menuStyle) {
2085 case MSTYLE_SINGLE:
2086 SetStringForKey("singletexture", "MenuStyle");
2087 break;
2088 case MSTYLE_FLAT:
2089 SetStringForKey("flat", "MenuStyle");
2090 break;
2091 default:
2092 case MSTYLE_NORMAL:
2093 SetStringForKey("normal", "MenuStyle");
2094 break;
2096 switch (panel->titleAlignment) {
2097 case WALeft:
2098 SetStringForKey("left", "TitleJustify");
2099 break;
2100 case WARight:
2101 SetStringForKey("right", "TitleJustify");
2102 break;
2103 default:
2104 case WACenter:
2105 SetStringForKey("center", "TitleJustify");
2106 break;
2111 static void
2112 prepareForClose(_Panel *panel)
2114 proplist_t textureList;
2115 proplist_t texture;
2116 TextureListItem *titem;
2117 WMListItem *item;
2118 WMUserDefaults *udb = WMGetStandardUserDefaults();
2119 int i;
2121 textureList = PLMakeArrayFromElements(NULL, NULL);
2123 /* store list of textures */
2124 for (i = 7; i < WMGetListNumberOfRows(panel->texLs); i++) {
2125 item = WMGetListItem(panel->texLs, i);
2126 titem = (TextureListItem*)item->clientData;
2128 texture = PLMakeArrayFromElements(PLMakeString(titem->title),
2129 PLRetain(titem->prop),
2130 PLMakeString(titem->path),
2131 NULL);
2133 PLAppendArrayElement(textureList, texture);
2136 WMSetUDObjectForKey(udb, textureList, "TextureList");
2137 PLRelease(textureList);
2139 /* store list of colors */
2140 textureList = PLMakeArrayFromElements(NULL, NULL);
2141 for (i = 0; i < 24; i++) {
2142 WMColor *color;
2143 char *str;
2145 color = WMGetColorWellColor(panel->sampW[i]);
2147 str = WMGetColorRGBDescription(color);
2148 PLAppendArrayElement(textureList, PLMakeString(str));
2149 free(str);
2151 WMSetUDObjectForKey(udb, textureList, "ColorList");
2152 PLRelease(textureList);
2154 WMSynchronizeUserDefaults(udb);
2159 Panel*
2160 InitAppearance(WMScreen *scr, WMWindow *win)
2162 _Panel *panel;
2164 panel = wmalloc(sizeof(_Panel));
2165 memset(panel, 0, sizeof(_Panel));
2167 panel->sectionName = _("Appearance Preferences");
2169 panel->description = _("Background texture configuration for windows,\n"
2170 "menus and icons.");
2172 panel->win = win;
2174 panel->callbacks.createWidgets = createPanel;
2175 panel->callbacks.updateDomain = storeData;
2176 panel->callbacks.prepareForClose = prepareForClose;
2178 AddSection(panel, ICON_FILE);
2180 return panel;
2185 /****************************************************************************/
2189 typedef struct ExtractPanel {
2190 WMWindow *win;
2192 WMLabel *label;
2193 WMList *list;
2195 WMButton *closeB;
2196 WMButton *extrB;
2197 } ExtractPanel;
2201 static void
2202 OpenExtractPanelFor(_Panel *panel, char *path)
2204 ExtractPanel *epanel;
2205 WMColor *color;
2206 WMFont *font;
2207 WMScreen *scr = WMWidgetScreen(panel->win);
2209 epanel = wmalloc(sizeof(ExtractPanel));
2210 epanel->win = WMCreatePanelWithStyleForWindow(panel->win, "extract",
2211 WMTitledWindowMask
2212 |WMClosableWindowMask);
2213 WMResizeWidget(epanel->win, 245, 250);
2214 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2216 epanel->label = WMCreateLabel(epanel->win);
2217 WMResizeWidget(epanel->label, 225, 18);
2218 WMMoveWidget(epanel->label, 10, 10);
2219 WMSetLabelTextAlignment(epanel->label, WACenter);
2220 WMSetLabelRelief(epanel->label, WRSunken);
2222 color = WMDarkGrayColor(scr);
2223 WMSetWidgetBackgroundColor(epanel->label, color);
2224 WMReleaseColor(color);
2226 color = WMWhiteColor(scr);
2227 WMSetLabelTextColor(epanel->label, color);
2228 WMReleaseColor(color);
2230 font = WMBoldSystemFontOfSize(scr, 12);
2231 WMSetLabelFont(epanel->label, font);
2232 WMReleaseFont(font);
2234 WMSetLabelText(epanel->label, _("Textures"));
2236 epanel->list = WMCreateList(epanel->win);
2237 WMResizeWidget(epanel->list, 225, 165);
2238 WMMoveWidget(epanel->list, 10, 30);
2242 epanel->closeB = WMCreateCommandButton(epanel->win);
2243 WMResizeWidget(epanel->closeB, 74, 24);
2244 WMMoveWidget(epanel->closeB, 165, 215);
2245 WMSetButtonText(epanel->closeB, _("Close"));
2247 epanel->extrB = WMCreateCommandButton(epanel->win);
2248 WMResizeWidget(epanel->extrB, 74, 24);
2249 WMMoveWidget(epanel->extrB, 80, 215);
2250 WMSetButtonText(epanel->extrB, _("Extract"));
2252 WMMapSubwidgets(epanel->win);
2255 /* take textures from file */
2259 WMRealizeWidget(epanel->win);
2261 WMMapWidget(epanel->win);