fix an assert crash.
[wmaker-crm.git] / WPrefs.app / Appearance.c
blobd570eba1383cd545b41e5131c4e87809dd430702
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 "..####.."
228 /* XPM */
229 static char * hand_xpm[] = {
230 "22 21 17 1",
231 " c None",
232 ". c #030305",
233 "+ c #101010",
234 "@ c #535355",
235 "# c #7F7F7E",
236 "$ c #969697",
237 "% c #B5B5B6",
238 "& c #C5C5C6",
239 "* c #D2D2D0",
240 "= c #DCDCDC",
241 "- c #E5E5E4",
242 "; c #ECECEC",
243 "> c #767674",
244 ", c #F2F2F4",
245 "' c #676767",
246 ") c #FDFDFB",
247 "! c #323234",
248 " ",
249 " ..... ",
250 " ..#%&&$. ",
251 " .))),%.......... ",
252 " .)-)),&)))))))))$. ",
253 " .-&))))))))),,,,;;. ",
254 " .=)))))))));-=***&$. ",
255 " .=)))))))),..+..... ",
256 " +=)))))))))-&#. ",
257 " +=)))))))))-%>. ",
258 " +&)))))))))-%'. ",
259 " +$,,))))));... ",
260 " .#%%*;,)),*$>+ ",
261 " .'>$%&&&&$#@. ",
262 " .!'>#$##>'. ",
263 " ..+++++. ",
264 " ",
265 " ##@@@## ",
266 " @@@@@@@@@@@ ",
267 " >>@@@## ",
268 " "};
272 static char *sampleColors[] = {
273 "black",
274 "#292929",
275 "#525252",
276 "#848484",
277 "#adadad",
278 "#d6d6d6",
279 "white",
280 "#d6d68c",
281 "#d6a57b",
282 "#8cd68c",
283 "#8cd6ce",
284 "#d68c8c",
285 "#8c9cd6",
286 "#bd86d6",
287 "#d68cbd",
288 "#d64a4a",
289 "#4a5ad6",
290 "#4ad6ce",
291 "#4ad65a",
292 "#ced64a",
293 "#d6844a",
294 "#8ad631",
295 "#ce29c6",
296 "#ce2973",
297 "black"
301 static char *textureOptions[] = {
302 "FTitleBack", "(solid, black)", "[Focused]",
303 "UTitleBack", "(solid, gray)", "[Unfocused]",
304 "PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
305 "ResizebarBack", "(solid, gray)", "[Resizebar]",
306 "MenuTitleBack", "(solid, black)", "[Menu Title]",
307 "MenuTextBack", "(solid, gray)", "[Menu Item]",
308 "IconBack", "(solid, gray)", "[Icon]"
312 #define RESIZEBAR_BEVEL -1
313 #define MENU_BEVEL -2
315 #define TEXPREV_WIDTH 40
316 #define TEXPREV_HEIGHT 24
319 #define MSTYLE_NORMAL 0
320 #define MSTYLE_SINGLE 1
321 #define MSTYLE_FLAT 2
324 #define FTITLE_COL (1<<0)
325 #define UTITLE_COL (1<<1)
326 #define OTITLE_COL (1<<2)
327 #define MTITLE_COL (1<<3)
328 #define MITEM_COL (1<<4)
329 #define MDISAB_COL (1<<5)
330 #define MHIGH_COL (1<<6)
331 #define MHIGHT_COL (1<<7)
332 #define ICONT_COL (1<<8)
333 #define ICONB_COL (1<<9)
334 #define CLIP_COL (1<<10)
335 #define CCLIP_COL (1<<11)
338 static char *colorOptions[] = {
339 "FTitleColor", "white",
340 "UTitleColor", "black",
341 "PTitleColor", "white",
342 "MenuTitleColor", "white",
343 "MenuTextColor", "black",
344 "MenuDisabledColor", "#616161",
345 "HighlightColor", "white",
346 "HighlightTextColor", "black",
347 "IconTitleColor", "white",
348 "IconTitleBack", "black",
349 "ClipTitleColor", "black",
350 "CClipTitleColor", "#454045"
356 static WMRect previewPositions[] = {
357 #define PFOCUSED 0
358 {{30,10},{190, 20}},
359 #define PUNFOCUSED 1
360 {{30,40},{190,20}},
361 #define POWNER 2
362 {{30,70},{190,20}},
363 #define PRESIZEBAR 3
364 {{30,100},{190,9}},
365 #define PMTITLE 4
366 {{30,120},{90,20}},
367 #define PMITEM 5
368 {{30,140},{90,20*4}},
369 #define PICON 6
370 {{155,130},{64,64}}
372 #define EVERYTHING 0xff
375 static WMRect previewColorPositions[] = {
376 {{30,10},{190, 20}},
377 {{30,40},{190,20}},
378 {{30,70},{190,20}},
379 {{30,120},{90,20}},
380 {{30,140},{90,20}},
381 {{30,160},{90,20}},
382 {{30,180},{90,20}},
383 {{30,200},{90,20}},
384 {{155,130},{64,64}},
385 {{155,130},{64,64}},
386 {{155,130},{64,64}},
387 {{155,130},{64,64}}
392 static void
393 str2rcolor(RContext *rc, char *name, RColor *color)
395 XColor xcolor;
397 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
399 color->alpha = 255;
400 color->red = xcolor.red >> 8;
401 color->green = xcolor.green >> 8;
402 color->blue = xcolor.blue >> 8;
406 static void
407 dumpRImage(char *path, RImage *image)
409 FILE *f;
411 f = fopen(path, "w");
412 if (!f) {
413 wsyserror(path);
414 return;
416 fprintf(f, "%02x%02x%1x", image->width, image->height,
417 image->data[3]!=NULL ? 4 : 3);
419 fwrite(image->data[0], 1, image->width * image->height, f);
420 fwrite(image->data[1], 1, image->width * image->height, f);
421 fwrite(image->data[2], 1, image->width * image->height, f);
422 if (image->data[3])
423 fwrite(image->data[3], 1, image->width * image->height, f);
425 if (fclose(f) < 0) {
426 wsyserror(path);
432 static int
433 isPixmap(proplist_t prop)
435 proplist_t p;
436 char *s;
438 p = PLGetArrayElement(prop, 0);
439 s = PLGetString(p);
440 if (strcasecmp(&s[1], "pixmap")==0)
441 return 1;
442 else
443 return 0;
447 /**********************************************************************/
449 static void
450 drawResizebarBevel(RImage *img)
452 RColor light;
453 RColor dark;
454 RColor black;
455 int width = img->width;
456 int height = img->height;
457 int cwidth = 28;
459 black.alpha = 255;
460 black.red = black.green = black.blue = 0;
462 light.alpha = 0;
463 light.red = light.green = light.blue = 80;
465 dark.alpha = 0;
466 dark.red = dark.green = dark.blue = 40;
468 ROperateLine(img, RSubtractOperation, 0, 0, width-1, 0, &dark);
469 ROperateLine(img, RAddOperation, 0, 1, width-1, 1, &light);
471 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height-1, &dark);
472 ROperateLine(img, RAddOperation, cwidth+1, 2, cwidth+1, height-1, &light);
474 ROperateLine(img, RSubtractOperation, width-cwidth-2, 2, width-cwidth-2,
475 height-1, &dark);
476 ROperateLine(img, RAddOperation, width-cwidth-1, 2, width-cwidth-1,
477 height-1, &light);
479 RDrawLine(img, 0, height-1, width-1, height-1, &black);
480 RDrawLine(img, 0, 0, 0, height-1, &black);
481 RDrawLine(img, width-1, 0, width-1, height-1, &black);
485 static void
486 drawMenuBevel(RImage *img)
488 RColor light, dark, mid;
489 int i;
490 int iheight = img->height / 4;
492 light.alpha = 0;
493 light.red = light.green = light.blue = 80;
495 dark.alpha = 255;
496 dark.red = dark.green = dark.blue = 0;
498 mid.alpha = 0;
499 mid.red = mid.green = mid.blue = 40;
501 for (i = 1; i < 4; i++) {
502 ROperateLine(img, RSubtractOperation, 0, i*iheight-2,
503 img->width-1, i*iheight-2, &mid);
505 RDrawLine(img, 0, i*iheight-1, img->width-1, i*iheight-1, &dark);
507 ROperateLine(img, RAddOperation, 1, i*iheight,
508 img->width-2, i*iheight, &light);
513 static Pixmap
514 renderTexture(WMScreen *scr, proplist_t texture, int width, int height,
515 char *path, int border)
517 char *type;
518 RImage *image = NULL;
519 Pixmap pixmap;
520 RContext *rc = WMScreenRContext(scr);
521 char *str;
522 RColor rcolor;
525 type = PLGetString(PLGetArrayElement(texture, 0));
527 if (strcasecmp(type, "solid")==0) {
529 str = PLGetString(PLGetArrayElement(texture, 1));
531 str2rcolor(rc, str, &rcolor);
533 image = RCreateImage(width, height, False);
534 RClearImage(image, &rcolor);
535 } else if (strcasecmp(&type[1], "gradient")==0) {
536 int style;
537 RColor rcolor2;
539 switch (toupper(type[0])) {
540 case 'V':
541 style = RVerticalGradient;
542 break;
543 case 'H':
544 style = RHorizontalGradient;
545 break;
546 default:
547 case 'D':
548 style = RDiagonalGradient;
549 break;
552 str = PLGetString(PLGetArrayElement(texture, 1));
553 str2rcolor(rc, str, &rcolor);
554 str = PLGetString(PLGetArrayElement(texture, 2));
555 str2rcolor(rc, str, &rcolor2);
557 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
558 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='T') {
559 int style;
560 RColor rcolor2;
561 int i;
562 RImage *grad, *timage;
563 char *path;
565 switch (toupper(type[1])) {
566 case 'V':
567 style = RVerticalGradient;
568 break;
569 case 'H':
570 style = RHorizontalGradient;
571 break;
572 default:
573 case 'D':
574 style = RDiagonalGradient;
575 break;
578 str = PLGetString(PLGetArrayElement(texture, 3));
579 str2rcolor(rc, str, &rcolor);
580 str = PLGetString(PLGetArrayElement(texture, 4));
581 str2rcolor(rc, str, &rcolor2);
583 str = PLGetString(PLGetArrayElement(texture, 1));
585 if (path = wfindfileinarray(GetObjectForKey("PixmapPath"), str))
586 timage = RLoadImage(rc, path, 0);
588 if (!path || !timage) {
589 wwarning("could not load file '%s': %s", path,
590 RMessageForError(RErrorCode));
591 } else {
592 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
594 image = RMakeTiledImage(timage, width, height);
595 RDestroyImage(timage);
597 i = atoi(PLGetString(PLGetArrayElement(texture, 2)));
599 RCombineImagesWithOpaqueness(image, grad, i);
600 RDestroyImage(grad);
602 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='M') {
603 int style;
604 RColor **colors;
605 int i, j;
607 switch (toupper(type[1])) {
608 case 'V':
609 style = RVerticalGradient;
610 break;
611 case 'H':
612 style = RHorizontalGradient;
613 break;
614 default:
615 case 'D':
616 style = RDiagonalGradient;
617 break;
620 j = PLGetNumberOfElements(texture);
622 if (j > 0) {
623 colors = wmalloc(j * sizeof(RColor*));
625 for (i = 2; i < j; i++) {
626 str = PLGetString(PLGetArrayElement(texture, i));
627 colors[i-2] = wmalloc(sizeof(RColor));
628 str2rcolor(rc, str, colors[i-2]);
630 colors[i-2] = NULL;
632 image = RRenderMultiGradient(width, height, colors, style);
634 for (i = 0; colors[i]!=NULL; i++)
635 free(colors[i]);
636 free(colors);
638 } else if (strcasecmp(&type[1], "pixmap")==0) {
639 RImage *timage = NULL;
640 char *path;
641 RColor color;
643 str = PLGetString(PLGetArrayElement(texture, 1));
645 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
646 if (path)
647 timage = RLoadImage(rc, path, 0);
649 if (!timage) {
650 wwarning("could not load file '%s': %s", path ? path : str,
651 RMessageForError(RErrorCode));
652 } else {
653 str = PLGetString(PLGetArrayElement(texture, 2));
654 str2rcolor(rc, str, &color);
656 switch (toupper(type[0])) {
657 case 'T':
658 image = RMakeTiledImage(timage, width, height);
659 RDestroyImage(timage);
660 timage = image;
661 break;
662 case 'C':
663 image = RMakeCenteredImage(timage, width, height, &color);
664 RDestroyImage(timage);
665 timage = image;
666 break;
667 case 'S':
668 case 'M':
669 image = RScaleImage(timage, width, height);
670 RDestroyImage(timage);
671 timage = image;
672 break;
676 free(path);
679 if (!image)
680 return None;
682 if (path) {
683 dumpRImage(path, image);
686 if (border < 0) {
687 if (border == RESIZEBAR_BEVEL) {
688 drawResizebarBevel(image);
689 } else if (border == MENU_BEVEL) {
690 drawMenuBevel(image);
691 RBevelImage(image, RBEV_RAISED2);
693 } else if (border) {
694 RBevelImage(image, border);
697 RConvertImage(rc, image, &pixmap);
698 RDestroyImage(image);
700 return pixmap;
704 static Pixmap
705 renderMenu(_Panel *panel, proplist_t texture, int width, int iheight)
707 WMScreen *scr = WMWidgetScreen(panel->win);
708 Display *dpy = WMScreenDisplay(scr);
709 Pixmap pix, tmp;
710 GC gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
711 int i;
713 switch (panel->menuStyle) {
714 case MSTYLE_NORMAL:
715 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
717 pix = XCreatePixmap(dpy, tmp, width, iheight*4, WMScreenDepth(scr));
718 for (i = 0; i < 4; i++) {
719 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight*i);
721 XFreePixmap(dpy, tmp);
722 break;
723 case MSTYLE_SINGLE:
724 pix = renderTexture(scr, texture, width, iheight*4, NULL, MENU_BEVEL);
725 break;
726 case MSTYLE_FLAT:
727 pix = renderTexture(scr, texture, width, iheight*4, NULL, RBEV_RAISED2);
728 break;
730 XFreeGC(dpy, gc);
732 return pix;
736 static void
737 renderPreview(_Panel *panel, GC gc, int part, int relief)
739 WMListItem *item;
740 TextureListItem *titem;
741 Pixmap pix;
742 WMScreen *scr = WMWidgetScreen(panel->frame);
744 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
745 titem = (TextureListItem*)item->clientData;
747 pix = renderTexture(scr, titem->prop,
748 previewPositions[part].size.width,
749 previewPositions[part].size.height,
750 NULL, relief);
752 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
753 previewPositions[part].size.width,
754 previewPositions[part].size.height,
755 previewPositions[part].pos.x,
756 previewPositions[part].pos.y);
758 XFreePixmap(WMScreenDisplay(scr), pix);
762 static void
763 updatePreviewBox(_Panel *panel, int elements)
765 WMScreen *scr = WMWidgetScreen(panel->win);
766 Display *dpy = WMScreenDisplay(scr);
767 /* RContext *rc = WMScreenRContext(scr);*/
768 int refresh = 0;
769 Pixmap pix;
770 GC gc;
771 int colorUpdate = 0;
773 gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
776 if (panel->preview == None) {
777 WMColor *color;
779 panel->preview = XCreatePixmap(dpy, WMWidgetXID(panel->win),
780 240-4, 215-4, WMScreenDepth(scr));
782 color = WMGrayColor(scr);
783 XFillRectangle(dpy, panel->preview, WMColorGC(color),
784 0, 0, 240-4, 215-4);
785 WMReleaseColor(color);
787 refresh = -1;
791 if (elements & (1<<PFOCUSED)) {
792 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
793 colorUpdate |= FTITLE_COL;
795 if (elements & (1<<PUNFOCUSED)) {
796 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
797 colorUpdate |= UTITLE_COL;
799 if (elements & (1<<POWNER)) {
800 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
801 colorUpdate |= OTITLE_COL;
803 if (elements & (1<<PRESIZEBAR)) {
804 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
806 if (elements & (1<<PMTITLE)) {
807 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
808 colorUpdate |= MTITLE_COL;
810 if (elements & (1<<PMITEM)) {
811 WMListItem *item;
812 TextureListItem *titem;
814 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
815 titem = (TextureListItem*)item->clientData;
817 pix = renderMenu(panel, titem->prop,
818 previewPositions[PMITEM].size.width,
819 previewPositions[PMITEM].size.height/4);
821 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
822 previewPositions[PMITEM].size.width,
823 previewPositions[PMITEM].size.height,
824 previewPositions[PMITEM].pos.x,
825 previewPositions[PMITEM].pos.y);
827 XFreePixmap(dpy, pix);
829 colorUpdate |= MITEM_COL|MDISAB_COL|MHIGH_COL|MHIGHT_COL;
831 if (elements & (1<<PMITEM|1<<PMTITLE)) {
832 XDrawLine(dpy, panel->preview, gc, 29, 120, 29, 120+20*4+20);
833 XDrawLine(dpy, panel->preview, gc, 29, 119, 119, 119);
835 if (elements & (1<<PICON)) {
836 WMListItem *item;
837 TextureListItem *titem;
839 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
840 titem = (TextureListItem*)item->clientData;
842 renderPreview(panel, gc, PICON,
843 titem->ispixmap ? 0 : RBEV_RAISED3);
845 colorUpdate |= ICONT_COL|ICONB_COL|CLIP_COL|CCLIP_COL;
847 if (refresh < 0) {
848 WMPixmap *p;
850 p = WMCreatePixmapFromXPixmaps(scr, panel->preview, None,
851 240-4, 215-4, WMScreenDepth(scr));
853 WMSetLabelImage(panel->prevL, p);
854 WMReleasePixmap(p);
856 if (colorUpdate)
857 updateColorPreviewBox(panel, colorUpdate);
858 } else {
859 if (colorUpdate)
860 updateColorPreviewBox(panel, colorUpdate);
861 else
862 WMRedisplayWidget(panel->prevL);
865 XFreeGC(dpy, gc);
871 static void
872 cancelNewTexture(void *data)
874 _Panel *panel = (_Panel*)data;
876 HideTexturePanel(panel->texturePanel);
882 static char*
883 makeFileName(char *prefix)
885 char *fname;
887 fname = wstrdup(prefix);
889 while (access(fname, F_OK)==0) {
890 char buf[30];
892 free(fname);
893 sprintf(buf, "%08lx.cache", time(NULL));
894 fname = wstrappend(prefix, buf);
897 return fname;
903 static void
904 okNewTexture(void *data)
906 _Panel *panel = (_Panel*)data;
907 WMListItem *item;
908 char *name;
909 char *str;
910 proplist_t prop;
911 TextureListItem *titem;
912 WMScreen *scr = WMWidgetScreen(panel->win);
914 titem = wmalloc(sizeof(TextureListItem));
915 memset(titem, 0, sizeof(TextureListItem));
917 HideTexturePanel(panel->texturePanel);
919 name = GetTexturePanelTextureName(panel->texturePanel);
921 prop = GetTexturePanelTexture(panel->texturePanel);
923 str = PLGetDescription(prop);
925 titem->title = name;
926 titem->prop = prop;
927 titem->texture = str;
928 titem->selectedFor = 0;
930 titem->ispixmap = isPixmap(prop);
932 titem->path = makeFileName(panel->fprefix);
933 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT,
934 titem->path, 0);
936 item = WMAddListItem(panel->texLs, "");
937 item->clientData = titem;
939 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
943 static void
944 okEditTexture(void *data)
946 _Panel *panel = (_Panel*)data;
947 WMListItem *item;
948 char *name;
949 char *str;
950 proplist_t prop;
951 TextureListItem *titem;
953 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
954 titem = (TextureListItem*)item->clientData;
956 HideTexturePanel(panel->texturePanel);
958 if (titem->current) {
959 name = GetTexturePanelTextureName(panel->texturePanel);
961 free(titem->title);
962 titem->title = name;
965 prop = GetTexturePanelTexture(panel->texturePanel);
967 str = PLGetDescription(prop);
969 PLRelease(titem->prop);
970 titem->prop = prop;
972 titem->ispixmap = isPixmap(prop);
974 free(titem->texture);
975 titem->texture = str;
977 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
978 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
979 TEXPREV_WIDTH, TEXPREV_HEIGHT,
980 titem->path, 0);
982 WMRedisplayWidget(panel->texLs);
984 if (titem->selectedFor)
985 updatePreviewBox(panel, titem->selectedFor);
987 changePage(panel->secP, panel);
992 static void
993 editTexture(WMWidget *w, void *data)
995 _Panel *panel = (_Panel*)data;
996 WMListItem *item;
997 TextureListItem *titem;
999 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
1000 titem = (TextureListItem*)item->clientData;
1002 SetTexturePanelPixmapPath(panel->texturePanel,
1003 GetObjectForKey("PixmapPath"));
1005 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
1007 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1008 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
1010 ShowTexturePanel(panel->texturePanel);
1015 static void
1016 newTexture(WMWidget *w, void *data)
1018 _Panel *panel = (_Panel*)data;
1020 SetTexturePanelPixmapPath(panel->texturePanel,
1021 GetObjectForKey("PixmapPath"));
1023 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1025 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1027 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1029 ShowTexturePanel(panel->texturePanel);
1034 static void
1035 deleteTexture(WMWidget *w, void *data)
1037 _Panel *panel = (_Panel*)data;
1038 WMListItem *item;
1039 TextureListItem *titem;
1040 int row;
1041 int section;
1043 section = WMGetPopUpButtonSelectedItem(panel->secP);
1044 row = WMGetListSelectedItemRow(panel->texLs);
1045 item = WMGetListItem(panel->texLs, row);
1046 titem = (TextureListItem*)item->clientData;
1048 if (titem->selectedFor & (1 << section)) {
1049 TextureListItem *titem2;
1051 panel->textureIndex[section] = section;
1052 item = WMGetListItem(panel->texLs, section);
1053 titem2 = (TextureListItem*)item->clientData;
1054 titem2->selectedFor |= 1 << section;
1057 free(titem->title);
1058 free(titem->texture);
1059 PLRelease(titem->prop);
1060 if (titem->path) {
1061 if (remove(titem->path) < 0 && errno != ENOENT) {
1062 wsyserror("could not remove file %s", titem->path);
1064 free(titem->path);
1067 free(titem);
1069 WMRemoveListItem(panel->texLs, row);
1070 WMSetButtonEnabled(panel->delB, False);
1076 static void
1077 extractTexture(WMWidget *w, void *data)
1079 _Panel *panel = (_Panel*)data;
1080 char *path;
1081 WMOpenPanel *opanel;
1082 WMScreen *scr = WMWidgetScreen(w);
1084 opanel = WMGetOpenPanel(scr);
1085 WMSetFilePanelCanChooseDirectories(opanel, False);
1086 WMSetFilePanelCanChooseFiles(opanel, True);
1088 if (WMRunModalFilePanelForDirectory(opanel, panel->win, wgethomedir(),
1089 _("Select File"), NULL)) {
1090 path = WMGetFilePanelFileName(opanel);
1092 OpenExtractPanelFor(panel, path);
1094 free(path);
1099 static void
1100 changePage(WMWidget *w, void *data)
1102 _Panel *panel = (_Panel*)data;
1103 int section;
1104 WMListItem *item;
1105 TextureListItem *titem;
1106 WMScreen *scr = WMWidgetScreen(panel->frame);
1107 RContext *rc = WMScreenRContext(scr);
1108 static WMPoint positions[] = {
1109 {5, 10},
1110 {5, 40},
1111 {5, 70},
1112 {5, 100},
1113 {5, 120},
1114 {5, 160},
1115 {130, 150}
1118 if (w) {
1119 section = WMGetPopUpButtonSelectedItem(panel->secP);
1121 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1123 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1125 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1127 titem = (TextureListItem*)item->clientData;
1130 WMColor *color;
1132 color = WMGrayColor(scr);
1133 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1134 positions[panel->oldsection].x,
1135 positions[panel->oldsection].y, 22, 22);
1136 WMReleaseColor(color);
1138 if (w) {
1139 panel->oldsection = section;
1140 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1141 positions[section].y);
1143 WMRedisplayWidget(panel->prevL);
1148 static void
1149 previewClick(XEvent *event, void *clientData)
1151 _Panel *panel = (_Panel*)clientData;
1152 int i;
1154 switch (panel->oldTabItem) {
1155 case 0:
1156 for (i = 0; i < sizeof(previewPositions)/sizeof(WMRect); i++) {
1157 if (event->xbutton.x >= previewPositions[i].pos.x
1158 && event->xbutton.y >= previewPositions[i].pos.y
1159 && event->xbutton.x < previewPositions[i].pos.x
1160 + previewPositions[i].size.width
1161 && event->xbutton.y < previewPositions[i].pos.y
1162 + previewPositions[i].size.height) {
1164 WMSetPopUpButtonSelectedItem(panel->secP, i);
1165 changePage(panel->secP, panel);
1166 return;
1169 break;
1170 case 1:
1171 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1172 if (event->xbutton.x >= previewColorPositions[i].pos.x
1173 && event->xbutton.y >= previewColorPositions[i].pos.y
1174 && event->xbutton.x < previewColorPositions[i].pos.x
1175 + previewColorPositions[i].size.width
1176 && event->xbutton.y < previewColorPositions[i].pos.y
1177 + previewColorPositions[i].size.height) {
1179 /* yuck kluge */
1180 if (i == 7)
1181 i = 4;
1183 WMSetPopUpButtonSelectedItem(panel->colP, i);
1184 changeColorPage(panel->colP, panel);
1185 return;
1188 break;
1193 static void
1194 textureClick(WMWidget *w, void *data)
1196 _Panel *panel = (_Panel*)data;
1197 int i;
1198 WMListItem *item;
1199 TextureListItem *titem;
1201 i = WMGetListSelectedItemRow(panel->texLs);
1203 item = WMGetListItem(panel->texLs, i);
1205 titem = (TextureListItem*)item->clientData;
1207 if (titem->current) {
1208 WMSetButtonEnabled(panel->delB, False);
1209 } else {
1210 WMSetButtonEnabled(panel->delB, True);
1216 static void
1217 textureDoubleClick(WMWidget *w, void *data)
1219 _Panel *panel = (_Panel*)data;
1220 int i, section;
1221 WMListItem *item;
1222 TextureListItem *titem;
1224 /* unselect old texture */
1225 section = WMGetPopUpButtonSelectedItem(panel->secP);
1227 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1228 titem = (TextureListItem*)item->clientData;
1229 titem->selectedFor &= ~(1 << section);
1231 /* select new texture */
1232 i = WMGetListSelectedItemRow(panel->texLs);
1234 item = WMGetListItem(panel->texLs, i);
1236 titem = (TextureListItem*)item->clientData;
1238 titem->selectedFor |= 1<<section;
1240 panel->textureIndex[section] = i;
1242 WMRedisplayWidget(panel->texLs);
1244 updatePreviewBox(panel, 1<<section);
1249 static void
1250 paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
1251 WMRect *rect)
1253 _Panel *panel = (_Panel*)WMGetHangedData(lPtr);
1254 WMScreen *scr = WMWidgetScreen(lPtr);
1255 int width, height, x, y;
1256 Display *dpy = WMScreenDisplay(scr);
1257 WMColor *white = WMWhiteColor(scr);
1258 WMListItem *item;
1259 WMColor *black = WMBlackColor(scr);
1260 TextureListItem *titem;
1262 item = WMGetListItem(lPtr, index);
1263 titem = (TextureListItem*)item->clientData;
1264 if (!titem) {
1265 WMReleaseColor(white);
1266 WMReleaseColor(black);
1267 return;
1270 width = rect->size.width;
1271 height = rect->size.height;
1272 x = rect->pos.x;
1273 y = rect->pos.y;
1275 if (state & WLDSSelected)
1276 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
1277 else
1278 XClearArea(dpy, d, x, y, width, height, False);
1281 if (titem->preview)
1282 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1283 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1285 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1286 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1287 else if (titem->selectedFor)
1288 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1290 WMDrawString(scr, d, WMColorGC(black), panel->boldFont,
1291 x + TEXPREV_WIDTH + 22, y + 2, titem->title,
1292 strlen(titem->title));
1294 WMDrawString(scr, d, WMColorGC(black), panel->smallFont,
1295 x + TEXPREV_WIDTH + 14, y + 18, titem->texture,
1296 strlen(titem->texture));
1299 WMReleaseColor(white);
1300 WMReleaseColor(black);
1305 static Pixmap
1306 loadRImage(WMScreen *scr, char *path)
1308 FILE *f;
1309 RImage *image;
1310 int w, h, d;
1311 int i;
1312 Pixmap pixmap;
1314 f = fopen(path, "r");
1315 if (!f)
1316 return None;
1318 fscanf(f, "%02x%02x%1x", &w, &h, &d);
1320 image = RCreateImage(w, h, d == 4);
1321 for (i = 0; i < d; i++) {
1322 fread(image->data[i], 1, w*h, f);
1324 fclose(f);
1326 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1327 RDestroyImage(image);
1329 return pixmap;
1334 static void
1335 fillTextureList(WMList *lPtr)
1337 proplist_t textureList;
1338 proplist_t texture;
1339 WMUserDefaults *udb = WMGetStandardUserDefaults();
1340 TextureListItem *titem;
1341 WMScreen *scr = WMWidgetScreen(lPtr);
1342 int i;
1344 textureList = WMGetUDObjectForKey(udb, "TextureList");
1345 if (!textureList)
1346 return;
1348 for (i = 0; i < PLGetNumberOfElements(textureList); i++) {
1349 WMListItem *item;
1351 texture = PLGetArrayElement(textureList, i);
1353 titem = wmalloc(sizeof(TextureListItem));
1354 memset(titem, 0, sizeof(TextureListItem));
1356 titem->title = wstrdup(PLGetString(PLGetArrayElement(texture, 0)));
1357 titem->prop = PLRetain(PLGetArrayElement(texture, 1));
1358 titem->texture = PLGetDescription(titem->prop);
1359 titem->selectedFor = 0;
1360 titem->path = wstrdup(PLGetString(PLGetArrayElement(texture, 2)));
1362 titem->preview = loadRImage(scr, titem->path);
1363 if (!titem->preview) {
1364 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH,
1365 TEXPREV_HEIGHT, NULL, 0);
1367 item = WMAddListItem(lPtr, "");
1368 item->clientData = titem;
1373 static void
1374 fillColorList(_Panel *panel)
1376 WMColor *color;
1377 proplist_t list;
1378 WMUserDefaults *udb = WMGetStandardUserDefaults();
1379 WMScreen *scr = WMWidgetScreen(panel->frame);
1380 int i;
1382 list = WMGetUDObjectForKey(udb, "ColorList");
1383 if (!list) {
1384 for (i = 0; i < 24; i++) {
1385 color = WMCreateNamedColor(scr, sampleColors[i], False);
1386 if (!color)
1387 continue;
1388 WMSetColorWellColor(panel->sampW[i], color);
1389 WMReleaseColor(color);
1391 } else {
1392 proplist_t c;
1394 for (i = 0; i < WMIN(24, PLGetNumberOfElements(list)); i++) {
1395 c = PLGetArrayElement(list, i);
1396 if (!c || !PLIsString(c))
1397 continue;
1398 color = WMCreateNamedColor(scr, PLGetString(c), False);
1399 if (!color)
1400 continue;
1401 WMSetColorWellColor(panel->sampW[i], color);
1402 WMReleaseColor(color);
1408 /*************************************************************************/
1411 static void
1412 changeColorPage(WMWidget *w, void *data)
1414 _Panel *panel = (_Panel*)data;
1415 int section;
1416 WMScreen *scr = WMWidgetScreen(panel->frame);
1417 RContext *rc = WMScreenRContext(scr);
1418 static WMPoint positions[] = {
1419 {5, 10},
1420 {5, 40},
1421 {5, 70},
1422 {5, 120},
1423 {5, 140},
1424 {5, 160},
1425 {5, 180},
1426 {5, 180},
1427 {130, 140},
1428 {130, 140},
1429 {130, 140},
1430 {130, 140}
1433 if (panel->preview) {
1434 WMColor *color;
1436 color = WMGrayColor(scr);
1437 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1438 positions[panel->oldcsection].x,
1439 positions[panel->oldcsection].y, 22, 22);
1440 WMReleaseColor(color);
1442 if (w) {
1443 section = WMGetPopUpButtonSelectedItem(panel->colP);
1445 panel->oldcsection = section;
1446 if (panel->preview)
1447 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1448 positions[section].y);
1450 section = WMGetPopUpButtonSelectedItem(panel->colP);
1452 WMSetColorWellColor(panel->colW, panel->colors[section]);
1454 WMRedisplayWidget(panel->prevL);
1458 static void
1459 paintText(WMScreen *scr, Drawable d, WMColor *color, WMFont *font,
1460 int x, int y, int w, int h, WMAlignment align, char *text)
1462 int l = strlen(text);
1464 switch (align) {
1465 case WALeft:
1466 x += 5;
1467 break;
1468 case WARight:
1469 x += w - 5 - WMWidthOfString(font, text, l);
1470 break;
1471 default:
1472 case WACenter:
1473 x += (w - WMWidthOfString(font, text, l))/2;
1474 break;
1476 WMDrawString(scr, d, WMColorGC(color), font, x,
1477 y + (h - WMFontHeight(font))/2, text, l);
1482 static void
1483 updateColorPreviewBox(_Panel *panel, int elements)
1485 WMScreen *scr = WMWidgetScreen(panel->frame);
1486 WMPixmap *pixmap;
1487 Pixmap d;
1489 pixmap = WMGetLabelImage(panel->prevL);
1490 d = WMGetPixmapXID(pixmap);
1492 if (elements & FTITLE_COL) {
1493 paintText(scr, d, panel->colors[0], panel->boldFont, 30, 10, 190, 20,
1494 panel->titleAlignment, _("Focused Window"));
1496 if (elements & UTITLE_COL) {
1497 paintText(scr, d, panel->colors[1], panel->boldFont, 30, 40, 190, 20,
1498 panel->titleAlignment, _("Unfocused Window"));
1500 if (elements & OTITLE_COL) {
1501 paintText(scr, d, panel->colors[2], panel->boldFont, 30, 70, 190, 20,
1502 panel->titleAlignment, _("Owner of Focused Window"));
1504 if (elements & MTITLE_COL) {
1505 paintText(scr, d, panel->colors[3], panel->boldFont, 30, 120, 90, 20,
1506 WALeft, _("Menu Title"));
1508 if (elements & MITEM_COL) {
1509 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 140, 90, 20,
1510 WALeft, _("Normal Item"));
1511 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 200, 90, 20,
1512 WALeft, _("Normal Item"));
1514 if (elements & MDISAB_COL) {
1515 paintText(scr, d, panel->colors[5], panel->normalFont, 30, 160, 90, 20,
1516 WALeft, _("Disabled Item"));
1518 if (elements & MHIGH_COL) {
1519 XFillRectangle(WMScreenDisplay(scr), d, WMColorGC(panel->colors[6]),
1520 31, 181, 87, 17);
1521 elements |= MHIGHT_COL;
1523 if (elements & MHIGHT_COL) {
1524 paintText(scr, d, panel->colors[7], panel->normalFont, 30, 180, 90, 20,
1525 WALeft, _("Highlighted"));
1528 if (elements & ICONT_COL) {
1529 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1530 155, 130, 64);
1532 if (elements & ICONB_COL) {
1533 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1534 0, 0, 30);
1536 if (elements & CLIP_COL) {
1537 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1538 0, 0, 30);
1540 if (elements & CCLIP_COL) {
1541 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1542 0, 0, 30);
1545 WMRedisplayWidget(panel->prevL);
1549 static void
1550 colorWellObserver(void *self, WMNotification *n)
1552 _Panel *panel = (_Panel*)self;
1553 int p;
1555 p = WMGetPopUpButtonSelectedItem(panel->colP);
1557 WMReleaseColor(panel->colors[p]);
1559 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1561 updateColorPreviewBox(panel, 1<<p);
1565 static void
1566 changedTabItem(struct WMTabViewDelegate *self, WMTabView *tabView,
1567 WMTabViewItem *item)
1569 _Panel *panel = self->data;
1570 int i;
1572 i = WMGetTabViewItemIdentifier(item);
1573 switch (i) {
1574 case 0:
1575 switch (panel->oldTabItem) {
1576 case 1:
1577 changeColorPage(NULL, panel);
1578 break;
1580 changePage(panel->secP, panel);
1581 break;
1582 case 1:
1583 switch (panel->oldTabItem) {
1584 case 0:
1585 changePage(NULL, panel);
1586 break;
1588 changeColorPage(panel->colP, panel);
1589 break;
1590 case 2:
1591 switch (panel->oldTabItem) {
1592 case 0:
1593 changePage(NULL, panel);
1594 break;
1595 case 1:
1596 changeColorPage(NULL, panel);
1597 break;
1599 break;
1602 panel->oldTabItem = i;
1606 /*************************************************************************/
1608 static void
1609 menuStyleCallback(WMWidget *self, void *data)
1611 _Panel *panel = (_Panel*)data;
1613 if (self == panel->mstyB[0]) {
1614 panel->menuStyle = MSTYLE_NORMAL;
1615 updatePreviewBox(panel, 1<<PMITEM);
1617 } else if (self == panel->mstyB[1]) {
1618 panel->menuStyle = MSTYLE_SINGLE;
1619 updatePreviewBox(panel, 1<<PMITEM);
1621 } else if (self == panel->mstyB[2]) {
1622 panel->menuStyle = MSTYLE_FLAT;
1623 updatePreviewBox(panel, 1<<PMITEM);
1628 static void
1629 titleAlignCallback(WMWidget *self, void *data)
1631 _Panel *panel = (_Panel*)data;
1633 if (self == panel->taliB[0]) {
1634 panel->titleAlignment = WALeft;
1635 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1637 } else if (self == panel->taliB[1]) {
1638 panel->titleAlignment = WACenter;
1639 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1641 } else if (self == panel->taliB[2]) {
1642 panel->titleAlignment = WARight;
1643 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1648 static void
1649 createPanel(Panel *p)
1651 _Panel *panel = (_Panel*)p;
1652 WMFont *font;
1653 WMScreen *scr = WMWidgetScreen(panel->win);
1654 WMTabViewItem *item;
1655 int i;
1656 char *tmp;
1657 Bool ok = True;
1659 panel->fprefix = wstrappend(wusergnusteppath(), "/.AppInfo");
1661 if (access(panel->fprefix, F_OK)!=0) {
1662 if (mkdir(panel->fprefix, 0755) < 0) {
1663 wsyserror(panel->fprefix);
1664 ok = False;
1667 if (ok) {
1668 tmp = wstrappend(panel->fprefix, "/WPrefs/");
1669 free(panel->fprefix);
1670 panel->fprefix = tmp;
1671 if (access(panel->fprefix, F_OK)!=0) {
1672 if (mkdir(panel->fprefix, 0755) < 0) {
1673 wsyserror(panel->fprefix);
1678 panel->smallFont = WMSystemFontOfSize(scr, 10);
1679 panel->normalFont = WMSystemFontOfSize(scr, 12);
1680 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1682 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1683 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1684 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1686 panel->frame = WMCreateFrame(panel->win);
1687 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
1688 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
1690 /* preview box */
1691 panel->prevL = WMCreateLabel(panel->frame);
1692 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1693 WMMoveWidget(panel->prevL, 15, 10);
1694 WMSetLabelRelief(panel->prevL, WRSunken);
1695 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1697 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask,
1698 previewClick, panel);
1701 /* tabview */
1703 tabviewDelegate.data = panel;
1705 panel->tabv = WMCreateTabView(panel->frame);
1706 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1707 WMMoveWidget(panel->tabv, 265, 10);
1708 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1710 /*** texture list ***/
1712 panel->texF = WMCreateFrame(panel->frame);
1713 WMSetFrameRelief(panel->texF, WRFlat);
1715 item = WMCreateTabViewItemWithIdentifier(0);
1716 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1717 WMSetTabViewItemLabel(item, _("Texture"));
1719 WMAddItemInTabView(panel->tabv, item);
1722 panel->secP = WMCreatePopUpButton(panel->texF);
1723 WMResizeWidget(panel->secP, 228, 20);
1724 WMMoveWidget(panel->secP, 7, 7);
1725 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1726 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1727 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1728 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1729 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1730 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1731 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1732 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1734 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1735 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1737 panel->texLs = WMCreateList(panel->texF);
1738 WMResizeWidget(panel->texLs, 165, 155);
1739 WMMoveWidget(panel->texLs, 70, 33);
1740 WMSetListUserDrawItemHeight(panel->texLs, 35);
1741 WMSetListUserDrawProc(panel->texLs, paintListItem);
1742 WMHangData(panel->texLs, panel);
1743 WMSetListAction(panel->texLs, textureClick, panel);
1744 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1746 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1747 "for the selected item."),
1748 WMWidgetView(panel->texLs));
1750 /* command buttons */
1752 font = WMSystemFontOfSize(scr, 10);
1755 panel->newB = WMCreateCommandButton(panel->texF);
1756 WMResizeWidget(panel->newB, 57, 39);
1757 WMMoveWidget(panel->newB, 7, 33);
1758 WMSetButtonFont(panel->newB, font);
1759 WMSetButtonImagePosition(panel->newB, WIPAbove);
1760 WMSetButtonText(panel->newB, _("New"));
1761 WMSetButtonAction(panel->newB, newTexture, panel);
1762 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1764 WMSetBalloonTextForView(_("Create a new texture."),
1765 WMWidgetView(panel->newB));
1767 panel->ripB = WMCreateCommandButton(panel->texF);
1768 WMResizeWidget(panel->ripB, 57, 39);
1769 WMMoveWidget(panel->ripB, 7, 72);
1770 WMSetButtonFont(panel->ripB, font);
1771 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1772 WMSetButtonText(panel->ripB, _("Extract..."));
1773 WMSetButtonAction(panel->ripB, extractTexture, panel);
1774 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1776 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1777 WMWidgetView(panel->ripB));
1779 WMSetButtonEnabled(panel->ripB, False);
1781 panel->editB = WMCreateCommandButton(panel->texF);
1782 WMResizeWidget(panel->editB, 57, 39);
1783 WMMoveWidget(panel->editB, 7, 111);
1784 WMSetButtonFont(panel->editB, font);
1785 WMSetButtonImagePosition(panel->editB, WIPAbove);
1786 WMSetButtonText(panel->editB, _("Edit"));
1787 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1788 WMSetButtonAction(panel->editB, editTexture, panel);
1789 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1790 WMWidgetView(panel->editB));
1792 panel->delB = WMCreateCommandButton(panel->texF);
1793 WMResizeWidget(panel->delB, 57, 38);
1794 WMMoveWidget(panel->delB, 7, 150);
1795 WMSetButtonFont(panel->delB, font);
1796 WMSetButtonImagePosition(panel->delB, WIPAbove);
1797 WMSetButtonText(panel->delB, _("Delete"));
1798 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1799 WMSetButtonEnabled(panel->delB, False);
1800 WMSetButtonAction(panel->delB, deleteTexture, panel);
1801 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1802 WMWidgetView(panel->delB));
1804 WMReleaseFont(font);
1806 WMMapSubwidgets(panel->texF);
1808 /*** colors ***/
1809 panel->colF = WMCreateFrame(panel->frame);
1810 WMSetFrameRelief(panel->colF, WRFlat);
1812 item = WMCreateTabViewItemWithIdentifier(1);
1813 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1814 WMSetTabViewItemLabel(item, _("Color"));
1816 WMAddItemInTabView(panel->tabv, item);
1818 panel->colP = WMCreatePopUpButton(panel->colF);
1819 WMResizeWidget(panel->colP, 228, 20);
1820 WMMoveWidget(panel->colP, 7, 7);
1821 WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1822 WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1823 WMAddPopUpButtonItem(panel->colP, _("Owner of Focused Window Title"));
1824 WMAddPopUpButtonItem(panel->colP, _("Menu Title"));
1825 WMAddPopUpButtonItem(panel->colP, _("Menu Item Text"));
1826 WMAddPopUpButtonItem(panel->colP, _("Disabled Menu Item Text"));
1827 WMAddPopUpButtonItem(panel->colP, _("Menu Highlight Color"));
1828 WMAddPopUpButtonItem(panel->colP, _("Highlighted Menu Text Color"));
1830 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1831 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1832 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1833 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1836 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1838 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1841 panel->colW = WMCreateColorWell(panel->colF);
1842 WMResizeWidget(panel->colW, 65, 50);
1843 WMMoveWidget(panel->colW, 30, 75);
1844 WMAddNotificationObserver(colorWellObserver, panel,
1845 WMColorWellDidChangeNotification, panel->colW);
1847 for (i = 0; i < 4; i++) {
1848 int j;
1849 for (j = 0; j < 6; j++) {
1850 panel->sampW[i+j*4] = WMCreateColorWell(panel->colF);
1851 WMResizeWidget(panel->sampW[i+j*4], 22, 22);
1852 WMMoveWidget(panel->sampW[i+j*4], 130 + i*22, 40 + j*22);
1853 WSetColorWellBordered(panel->sampW[i+j*4], False);
1857 WMMapSubwidgets(panel->colF);
1859 /*** options ***/
1860 panel->optF = WMCreateFrame(panel->frame);
1861 WMSetFrameRelief(panel->optF, WRFlat);
1863 item = WMCreateTabViewItemWithIdentifier(2);
1864 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1865 WMSetTabViewItemLabel(item, _("Options"));
1867 WMAddItemInTabView(panel->tabv, item);
1869 panel->mstyF = WMCreateFrame(panel->optF);
1870 WMResizeWidget(panel->mstyF, 215, 85);
1871 WMMoveWidget(panel->mstyF, 15, 10);
1872 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1874 for (i = 0; i < 3; i++) {
1875 WMPixmap *icon;
1876 char *path;
1878 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1879 WMResizeWidget(panel->mstyB[i], 54, 54);
1880 WMMoveWidget(panel->mstyB[i], 15 + i*65, 20);
1881 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1882 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1883 switch (i) {
1884 case 0:
1885 path = LocateImage(MSTYLE1_FILE);
1886 break;
1887 case 1:
1888 path = LocateImage(MSTYLE2_FILE);
1889 break;
1890 case 2:
1891 path = LocateImage(MSTYLE3_FILE);
1892 break;
1894 if (path) {
1895 icon = WMCreatePixmapFromFile(scr, path);
1896 if (icon) {
1897 WMSetButtonImage(panel->mstyB[i], icon);
1898 WMReleasePixmap(icon);
1899 } else {
1900 wwarning(_("could not load icon file %s"), path);
1902 free(path);
1905 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
1906 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
1908 WMMapSubwidgets(panel->mstyF);
1911 panel->taliF = WMCreateFrame(panel->optF);
1912 WMResizeWidget(panel->taliF, 110, 80);
1913 WMMoveWidget(panel->taliF, 15, 100);
1914 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
1916 for (i = 0; i < 3; i++) {
1917 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
1918 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
1919 switch (i) {
1920 case 0:
1921 WMSetButtonText(panel->taliB[i], _("Left"));
1922 break;
1923 case 1:
1924 WMSetButtonText(panel->taliB[i], _("Center"));
1925 break;
1926 case 2:
1927 WMSetButtonText(panel->taliB[i], _("Right"));
1928 break;
1930 WMResizeWidget(panel->taliB[i], 90, 18);
1931 WMMoveWidget(panel->taliB[i], 10, 15 + 20*i);
1933 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
1934 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
1936 WMMapSubwidgets(panel->taliF);
1938 WMMapSubwidgets(panel->optF);
1940 /**/
1942 WMRealizeWidget(panel->frame);
1943 WMMapSubwidgets(panel->frame);
1945 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1947 showData(panel);
1949 changePage(panel->secP, panel);
1951 fillTextureList(panel->texLs);
1953 fillColorList(panel);
1955 panel->texturePanel = CreateTexturePanel(panel->win);
1960 static void
1961 setupTextureFor(WMList *list, char *key, char *defValue, char *title,
1962 int index)
1964 WMListItem *item;
1965 TextureListItem *titem;
1967 titem = wmalloc(sizeof(TextureListItem));
1968 memset(titem, 0, sizeof(TextureListItem));
1970 titem->title = wstrdup(title);
1971 titem->prop = GetObjectForKey(key);
1972 if (!titem->prop || !PLIsArray(titem->prop)) {
1973 /* Maybe also give a error message to stderr that the entry is bad? */
1974 titem->prop = PLGetProplistWithDescription(defValue);
1975 } else {
1976 PLRetain(titem->prop);
1978 titem->texture = PLGetDescription((proplist_t)titem->prop);
1979 titem->current = 1;
1980 titem->selectedFor = 1<<index;
1982 titem->ispixmap = isPixmap(titem->prop);
1984 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop,
1985 TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1987 item = WMAddListItem(list, "");
1988 item->clientData = titem;
1993 static void
1994 showData(_Panel *panel)
1996 int i;
1997 char *str;
1999 str = GetStringForKey("MenuStyle");
2000 if (str && strcasecmp(str, "flat")==0) {
2001 panel->menuStyle = MSTYLE_FLAT;
2002 } else if (str && strcasecmp(str, "singletexture")==0) {
2003 panel->menuStyle = MSTYLE_SINGLE;
2004 } else {
2005 panel->menuStyle = MSTYLE_NORMAL;
2008 str = GetStringForKey("TitleJustify");
2009 if (str && strcasecmp(str, "left")==0) {
2010 panel->titleAlignment = WALeft;
2011 } else if (str && strcasecmp(str, "right")==0) {
2012 panel->titleAlignment = WARight;
2013 } else {
2014 panel->titleAlignment = WACenter;
2017 for (i = 0; i < sizeof(colorOptions)/(2*sizeof(char*)); i++) {
2018 WMColor *color;
2020 str = GetStringForKey(colorOptions[i*2]);
2021 if (!str)
2022 str = colorOptions[i*2+1];
2024 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->frame), str, False))) {
2025 color = WMCreateNamedColor(WMWidgetScreen(panel->frame), "#000000", False);
2028 panel->colors[i] = color;
2030 changeColorPage(panel->colP, panel);
2032 for (i = 0; i < sizeof(textureOptions)/(3*sizeof(char*)); i++) {
2033 setupTextureFor(panel->texLs, textureOptions[i*3],
2034 textureOptions[i*3+1], textureOptions[i*3+2], i);
2035 panel->textureIndex[i] = i;
2037 updatePreviewBox(panel, EVERYTHING);
2040 for (i = 0; i < 3; i++) {
2041 WMSetButtonSelected(panel->mstyB[i], i==panel->menuStyle);
2042 WMSetButtonSelected(panel->taliB[i], i==panel->titleAlignment);
2048 static void
2049 storeData(_Panel *panel)
2051 TextureListItem *titem;
2052 WMListItem *item;
2053 int i;
2055 for (i = 0; i < sizeof(textureOptions)/(sizeof(char*)*3); i++) {
2056 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2057 titem = (TextureListItem*)item->clientData;
2058 SetObjectForKey(titem->prop, textureOptions[i*3]);
2061 for (i = 0; i < 8; i++) {
2062 char *str;
2064 str = WMGetColorRGBDescription(panel->colors[i]);
2066 if (str) {
2067 SetStringForKey(str, colorOptions[i*2]);
2068 free(str);
2072 switch (panel->menuStyle) {
2073 case MSTYLE_SINGLE:
2074 SetStringForKey("singletexture", "MenuStyle");
2075 break;
2076 case MSTYLE_FLAT:
2077 SetStringForKey("flat", "MenuStyle");
2078 break;
2079 default:
2080 case MSTYLE_NORMAL:
2081 SetStringForKey("normal", "MenuStyle");
2082 break;
2084 switch (panel->titleAlignment) {
2085 case WALeft:
2086 SetStringForKey("left", "TitleJustify");
2087 break;
2088 case WARight:
2089 SetStringForKey("right", "TitleJustify");
2090 break;
2091 default:
2092 case WACenter:
2093 SetStringForKey("center", "TitleJustify");
2094 break;
2099 static void
2100 prepareForClose(_Panel *panel)
2102 proplist_t textureList;
2103 proplist_t texture;
2104 TextureListItem *titem;
2105 WMListItem *item;
2106 WMUserDefaults *udb = WMGetStandardUserDefaults();
2107 int i;
2109 textureList = PLMakeArrayFromElements(NULL, NULL);
2111 /* store list of textures */
2112 for (i = 7; i < WMGetListNumberOfRows(panel->texLs); i++) {
2113 item = WMGetListItem(panel->texLs, i);
2114 titem = (TextureListItem*)item->clientData;
2116 texture = PLMakeArrayFromElements(PLMakeString(titem->title),
2117 PLRetain(titem->prop),
2118 PLMakeString(titem->path),
2119 NULL);
2121 PLAppendArrayElement(textureList, texture);
2124 WMSetUDObjectForKey(udb, textureList, "TextureList");
2125 PLRelease(textureList);
2127 /* store list of colors */
2128 textureList = PLMakeArrayFromElements(NULL, NULL);
2129 for (i = 0; i < 24; i++) {
2130 WMColor *color;
2131 char *str;
2133 color = WMGetColorWellColor(panel->sampW[i]);
2135 str = WMGetColorRGBDescription(color);
2136 PLAppendArrayElement(textureList, PLMakeString(str));
2137 free(str);
2139 WMSetUDObjectForKey(udb, textureList, "ColorList");
2140 PLRelease(textureList);
2142 WMSynchronizeUserDefaults(udb);
2147 Panel*
2148 InitAppearance(WMScreen *scr, WMWindow *win)
2150 _Panel *panel;
2152 panel = wmalloc(sizeof(_Panel));
2153 memset(panel, 0, sizeof(_Panel));
2155 panel->sectionName = _("Appearance Preferences");
2157 panel->description = _("Background texture configuration for windows,\n"
2158 "menus and icons.");
2160 panel->win = win;
2162 panel->callbacks.createWidgets = createPanel;
2163 panel->callbacks.updateDomain = storeData;
2164 panel->callbacks.prepareForClose = prepareForClose;
2166 AddSection(panel, ICON_FILE);
2168 return panel;
2173 /****************************************************************************/
2177 typedef struct ExtractPanel {
2178 WMWindow *win;
2180 WMLabel *label;
2181 WMList *list;
2183 WMButton *closeB;
2184 WMButton *extrB;
2185 } ExtractPanel;
2189 static void
2190 OpenExtractPanelFor(_Panel *panel, char *path)
2192 ExtractPanel *epanel;
2193 WMColor *color;
2194 WMFont *font;
2195 WMScreen *scr = WMWidgetScreen(panel->win);
2197 epanel = wmalloc(sizeof(ExtractPanel));
2198 epanel->win = WMCreatePanelWithStyleForWindow(panel->win, "extract",
2199 WMTitledWindowMask
2200 |WMClosableWindowMask);
2201 WMResizeWidget(epanel->win, 245, 250);
2202 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2204 epanel->label = WMCreateLabel(epanel->win);
2205 WMResizeWidget(epanel->label, 225, 18);
2206 WMMoveWidget(epanel->label, 10, 10);
2207 WMSetLabelTextAlignment(epanel->label, WACenter);
2208 WMSetLabelRelief(epanel->label, WRSunken);
2210 color = WMDarkGrayColor(scr);
2211 WMSetWidgetBackgroundColor(epanel->label, color);
2212 WMReleaseColor(color);
2214 color = WMWhiteColor(scr);
2215 WMSetLabelTextColor(epanel->label, color);
2216 WMReleaseColor(color);
2218 font = WMBoldSystemFontOfSize(scr, 12);
2219 WMSetLabelFont(epanel->label, font);
2220 WMReleaseFont(font);
2222 WMSetLabelText(epanel->label, _("Textures"));
2224 epanel->list = WMCreateList(epanel->win);
2225 WMResizeWidget(epanel->list, 225, 165);
2226 WMMoveWidget(epanel->list, 10, 30);
2230 epanel->closeB = WMCreateCommandButton(epanel->win);
2231 WMResizeWidget(epanel->closeB, 74, 24);
2232 WMMoveWidget(epanel->closeB, 165, 215);
2233 WMSetButtonText(epanel->closeB, _("Close"));
2235 epanel->extrB = WMCreateCommandButton(epanel->win);
2236 WMResizeWidget(epanel->extrB, 74, 24);
2237 WMMoveWidget(epanel->extrB, 80, 215);
2238 WMSetButtonText(epanel->extrB, _("Extract"));
2240 WMMapSubwidgets(epanel->win);
2243 /* take textures from file */
2247 WMRealizeWidget(epanel->win);
2249 WMMapWidget(epanel->win);