added color editing and title justification to appearance section
[wmaker-crm.git] / WPrefs.app / Appearance.c
blob71ec111f110f00d295bbb3d1bd800d63907e1e8e
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 *textureOptions[] = {
273 "FTitleBack", "(solid, black)", "[Focused]",
274 "UTitleBack", "(solid, gray)", "[Unfocused]",
275 "PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
276 "ResizebarBack", "(solid, gray)", "[Resizebar]",
277 "MenuTitleBack", "(solid, black)", "[Menu Title]",
278 "MenuTextBack", "(solid, gray)", "[Menu Item]",
279 "IconBack", "(solid, gray)", "[Icon]"
283 #define RESIZEBAR_BEVEL -1
284 #define MENU_BEVEL -2
286 #define TEXPREV_WIDTH 40
287 #define TEXPREV_HEIGHT 24
290 #define MSTYLE_NORMAL 0
291 #define MSTYLE_SINGLE 1
292 #define MSTYLE_FLAT 2
295 #define FTITLE_COL (1<<0)
296 #define UTITLE_COL (1<<1)
297 #define OTITLE_COL (1<<2)
298 #define MTITLE_COL (1<<3)
299 #define MITEM_COL (1<<4)
300 #define MDISAB_COL (1<<5)
301 #define MHIGH_COL (1<<6)
302 #define MHIGHT_COL (1<<7)
303 #define ICONT_COL (1<<8)
304 #define ICONB_COL (1<<9)
305 #define CLIP_COL (1<<10)
306 #define CCLIP_COL (1<<11)
309 static char *colorOptions[] = {
310 "FTitleColor", "white",
311 "UTitleColor", "black",
312 "PTitleColor", "white",
313 "MenuTitleColor", "white",
314 "MenuTextColor", "black",
315 "MenuDisabledColor", "#616161",
316 "HighlightColor", "white",
317 "HighlightTextColor", "black",
318 "IconTitleColor", "white",
319 "IconTitleBack", "black",
320 "ClipTitleColor", "black",
321 "CClipTitleColor", "#454045"
327 static WMRect previewPositions[] = {
328 #define PFOCUSED 0
329 {{30,10},{190, 20}},
330 #define PUNFOCUSED 1
331 {{30,40},{190,20}},
332 #define POWNER 2
333 {{30,70},{190,20}},
334 #define PRESIZEBAR 3
335 {{30,100},{190,9}},
336 #define PMTITLE 4
337 {{30,120},{90,20}},
338 #define PMITEM 5
339 {{30,140},{90,18*4}},
340 #define PICON 6
341 {{155,130},{64,64}}
343 #define EVERYTHING 0xff
346 static WMRect previewColorPositions[] = {
347 {{30,10},{190, 20}},
348 {{30,40},{190,20}},
349 {{30,70},{190,20}},
350 {{30,120},{90,20}},
351 {{30,140},{90,18}},
352 {{30,158},{90,18}},
353 {{30,176},{90,18}},
354 {{30,194},{90,18}},
355 {{155,130},{64,64}},
356 {{155,130},{64,64}},
357 {{155,130},{64,64}},
358 {{155,130},{64,64}}
363 static void
364 str2rcolor(RContext *rc, char *name, RColor *color)
366 XColor xcolor;
368 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
370 color->alpha = 255;
371 color->red = xcolor.red >> 8;
372 color->green = xcolor.green >> 8;
373 color->blue = xcolor.blue >> 8;
377 static void
378 dumpRImage(char *path, RImage *image)
380 FILE *f;
382 f = fopen(path, "w");
383 if (!f) {
384 wsyserror(path);
385 return;
387 fprintf(f, "%02x%02x%1x", image->width, image->height,
388 image->data[3]!=NULL ? 4 : 3);
390 fwrite(image->data[0], 1, image->width * image->height, f);
391 fwrite(image->data[1], 1, image->width * image->height, f);
392 fwrite(image->data[2], 1, image->width * image->height, f);
393 if (image->data[3])
394 fwrite(image->data[3], 1, image->width * image->height, f);
396 if (fclose(f) < 0) {
397 wsyserror(path);
403 static int
404 isPixmap(proplist_t prop)
406 proplist_t p;
407 char *s;
409 p = PLGetArrayElement(prop, 0);
410 s = PLGetString(p);
411 if (strcasecmp(&s[1], "pixmap")==0)
412 return 1;
413 else
414 return 0;
418 /**********************************************************************/
420 static void
421 drawResizebarBevel(RImage *img)
423 RColor light;
424 RColor dark;
425 RColor black;
426 int width = img->width;
427 int height = img->height;
428 int cwidth = 28;
430 black.alpha = 255;
431 black.red = black.green = black.blue = 0;
433 light.alpha = 0;
434 light.red = light.green = light.blue = 80;
436 dark.alpha = 0;
437 dark.red = dark.green = dark.blue = 40;
439 ROperateLine(img, RSubtractOperation, 0, 0, width-1, 0, &dark);
440 ROperateLine(img, RAddOperation, 0, 1, width-1, 1, &light);
442 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height-1, &dark);
443 ROperateLine(img, RAddOperation, cwidth+1, 2, cwidth+1, height-1, &light);
445 ROperateLine(img, RSubtractOperation, width-cwidth-2, 2, width-cwidth-2,
446 height-1, &dark);
447 ROperateLine(img, RAddOperation, width-cwidth-1, 2, width-cwidth-1,
448 height-1, &light);
450 RDrawLine(img, 0, height-1, width-1, height-1, &black);
451 RDrawLine(img, 0, 0, 0, height-1, &black);
452 RDrawLine(img, width-1, 0, width-1, height-1, &black);
456 static void
457 drawMenuBevel(RImage *img)
459 RColor light, dark, mid;
460 int i;
461 int iheight = img->height / 4;
463 light.alpha = 0;
464 light.red = light.green = light.blue = 80;
466 dark.alpha = 255;
467 dark.red = dark.green = dark.blue = 0;
469 mid.alpha = 0;
470 mid.red = mid.green = mid.blue = 40;
472 for (i = 1; i < 4; i++) {
473 ROperateLine(img, RSubtractOperation, 0, i*iheight-2,
474 img->width-1, i*iheight-2, &mid);
476 RDrawLine(img, 0, i*iheight-1,
477 img->width-1, i*iheight-1, &dark);
479 ROperateLine(img, RAddOperation, 1, i*iheight,
480 img->width-2, i*iheight, &light);
485 static Pixmap
486 renderTexture(WMScreen *scr, proplist_t texture, int width, int height,
487 char *path, int border)
489 char *type;
490 RImage *image = NULL;
491 Pixmap pixmap;
492 RContext *rc = WMScreenRContext(scr);
493 char *str;
494 RColor rcolor;
497 type = PLGetString(PLGetArrayElement(texture, 0));
499 if (strcasecmp(type, "solid")==0) {
501 str = PLGetString(PLGetArrayElement(texture, 1));
503 str2rcolor(rc, str, &rcolor);
505 image = RCreateImage(width, height, False);
506 RClearImage(image, &rcolor);
507 } else if (strcasecmp(&type[1], "gradient")==0) {
508 int style;
509 RColor rcolor2;
511 switch (toupper(type[0])) {
512 case 'V':
513 style = RVerticalGradient;
514 break;
515 case 'H':
516 style = RHorizontalGradient;
517 break;
518 default:
519 case 'D':
520 style = RDiagonalGradient;
521 break;
524 str = PLGetString(PLGetArrayElement(texture, 1));
525 str2rcolor(rc, str, &rcolor);
526 str = PLGetString(PLGetArrayElement(texture, 2));
527 str2rcolor(rc, str, &rcolor2);
529 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
530 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='T') {
531 int style;
532 RColor rcolor2;
533 int i;
534 RImage *grad, *timage;
535 char *path;
537 switch (toupper(type[1])) {
538 case 'V':
539 style = RVerticalGradient;
540 break;
541 case 'H':
542 style = RHorizontalGradient;
543 break;
544 default:
545 case 'D':
546 style = RDiagonalGradient;
547 break;
550 str = PLGetString(PLGetArrayElement(texture, 3));
551 str2rcolor(rc, str, &rcolor);
552 str = PLGetString(PLGetArrayElement(texture, 4));
553 str2rcolor(rc, str, &rcolor2);
555 str = PLGetString(PLGetArrayElement(texture, 1));
557 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
558 timage = RLoadImage(rc, path, 0);
560 if (!timage) {
561 wwarning("could not load file '%s': %s", path,
562 RMessageForError(RErrorCode));
563 } else {
564 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
566 image = RMakeTiledImage(timage, width, height);
567 RDestroyImage(timage);
569 i = atoi(PLGetString(PLGetArrayElement(texture, 2)));
571 RCombineImagesWithOpaqueness(image, grad, i);
572 RDestroyImage(grad);
574 } else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='M') {
575 int style;
576 RColor **colors;
577 int i, j;
579 switch (toupper(type[1])) {
580 case 'V':
581 style = RVerticalGradient;
582 break;
583 case 'H':
584 style = RHorizontalGradient;
585 break;
586 default:
587 case 'D':
588 style = RDiagonalGradient;
589 break;
592 j = PLGetNumberOfElements(texture);
594 if (j > 0) {
595 colors = wmalloc(j * sizeof(RColor*));
597 for (i = 2; i < j; i++) {
598 str = PLGetString(PLGetArrayElement(texture, i));
599 colors[i-2] = wmalloc(sizeof(RColor));
600 str2rcolor(rc, str, colors[i-2]);
602 colors[i-2] = NULL;
604 image = RRenderMultiGradient(width, height, colors, style);
606 for (i = 0; colors[i]!=NULL; i++)
607 free(colors[i]);
608 free(colors);
610 } else if (strcasecmp(&type[1], "pixmap")==0) {
611 RImage *timage = NULL;
612 char *path;
613 RColor color;
615 str = PLGetString(PLGetArrayElement(texture, 1));
617 path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
618 if (path)
619 timage = RLoadImage(rc, path, 0);
621 if (!timage) {
622 wwarning("could not load file '%s': %s", path ? path : str,
623 RMessageForError(RErrorCode));
624 } else {
625 str = PLGetString(PLGetArrayElement(texture, 2));
626 str2rcolor(rc, str, &color);
628 switch (toupper(type[0])) {
629 case 'T':
630 image = RMakeTiledImage(timage, width, height);
631 RDestroyImage(timage);
632 timage = image;
633 break;
634 case 'C':
635 image = RMakeCenteredImage(timage, width, height, &color);
636 RDestroyImage(timage);
637 timage = image;
638 break;
639 case 'S':
640 case 'M':
641 image = RScaleImage(timage, width, height);
642 RDestroyImage(timage);
643 timage = image;
644 break;
648 free(path);
651 if (!image)
652 return None;
654 if (path) {
655 dumpRImage(path, image);
658 if (border < 0) {
659 if (border == RESIZEBAR_BEVEL) {
660 drawResizebarBevel(image);
661 } else if (border == MENU_BEVEL) {
662 drawMenuBevel(image);
663 RBevelImage(image, RBEV_RAISED2);
665 } else if (border) {
666 RBevelImage(image, border);
669 RConvertImage(rc, image, &pixmap);
670 RDestroyImage(image);
672 return pixmap;
676 static Pixmap
677 renderMenu(_Panel *panel, proplist_t texture, int width, int iheight)
679 WMScreen *scr = WMWidgetScreen(panel->win);
680 Display *dpy = WMScreenDisplay(scr);
681 Pixmap pix, tmp;
682 GC gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
683 int i;
685 switch (panel->menuStyle) {
686 case MSTYLE_NORMAL:
687 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
689 pix = XCreatePixmap(dpy, tmp, width, iheight*4, WMScreenDepth(scr));
690 for (i = 0; i < 4; i++) {
691 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight,
692 0, iheight*i);
694 XFreePixmap(dpy, tmp);
695 break;
696 case MSTYLE_SINGLE:
697 pix = renderTexture(scr, texture, width, iheight*4, NULL, MENU_BEVEL);
698 break;
699 case MSTYLE_FLAT:
700 pix = renderTexture(scr, texture, width, iheight*4, NULL, RBEV_RAISED2);
701 break;
703 XFreeGC(dpy, gc);
705 return pix;
709 static void
710 renderPreview(_Panel *panel, GC gc, int part, int relief)
712 WMListItem *item;
713 TextureListItem *titem;
714 Pixmap pix;
715 WMScreen *scr = WMWidgetScreen(panel->frame);
717 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
718 titem = (TextureListItem*)item->clientData;
720 pix = renderTexture(scr, titem->prop,
721 previewPositions[part].size.width,
722 previewPositions[part].size.height,
723 NULL, relief);
725 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
726 previewPositions[part].size.width,
727 previewPositions[part].size.height,
728 previewPositions[part].pos.x,
729 previewPositions[part].pos.y);
731 XFreePixmap(WMScreenDisplay(scr), pix);
735 static void
736 updatePreviewBox(_Panel *panel, int elements)
738 WMScreen *scr = WMWidgetScreen(panel->win);
739 Display *dpy = WMScreenDisplay(scr);
740 /* RContext *rc = WMScreenRContext(scr);*/
741 int refresh = 0;
742 Pixmap pix;
743 GC gc;
744 WMListItem *item;
745 TextureListItem *titem;
746 int colorUpdate = 0;
748 gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
751 if (panel->preview == None) {
752 WMColor *color;
754 panel->preview = XCreatePixmap(dpy, WMWidgetXID(panel->win),
755 240-4, 215-4, WMScreenDepth(scr));
757 color = WMGrayColor(scr);
758 XFillRectangle(dpy, panel->preview, WMColorGC(color),
759 0, 0, 240-4, 215-4);
760 WMReleaseColor(color);
762 refresh = -1;
766 if (elements & (1<<PFOCUSED)) {
767 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
768 colorUpdate |= FTITLE_COL;
770 if (elements & (1<<PUNFOCUSED)) {
771 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
772 colorUpdate |= UTITLE_COL;
774 if (elements & (1<<POWNER)) {
775 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
776 colorUpdate |= OTITLE_COL;
778 if (elements & (1<<PRESIZEBAR)) {
779 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
781 if (elements & (1<<PMTITLE)) {
782 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
783 colorUpdate |= MTITLE_COL;
785 if (elements & (1<<PMITEM)) {
786 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
787 titem = (TextureListItem*)item->clientData;
789 pix = renderMenu(panel, titem->prop,
790 previewPositions[PMITEM].size.width,
791 previewPositions[PMITEM].size.height/4);
793 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
794 previewPositions[PMITEM].size.width,
795 previewPositions[PMITEM].size.height,
796 previewPositions[PMITEM].pos.x,
797 previewPositions[PMITEM].pos.y);
799 XFreePixmap(dpy, pix);
801 colorUpdate |= MITEM_COL|MDISAB_COL|MHIGH_COL|MHIGHT_COL;
803 if (elements & (1<<PMITEM|1<<PMTITLE)) {
804 XDrawLine(dpy, panel->preview, gc, 29, 120, 29, 120+18*4+20);
805 XDrawLine(dpy, panel->preview, gc, 29, 119, 119, 119);
807 if (elements & (1<<PICON)) {
808 renderPreview(panel, gc, PICON,
809 titem->ispixmap ? 0 : RBEV_RAISED3);
811 colorUpdate |= ICONT_COL|ICONB_COL|CLIP_COL|CCLIP_COL;
813 if (refresh < 0) {
814 WMPixmap *p;
816 p = WMCreatePixmapFromXPixmaps(scr, panel->preview, None,
817 240-4, 215-4, WMScreenDepth(scr));
819 WMSetLabelImage(panel->prevL, p);
820 WMReleasePixmap(p);
822 if (colorUpdate)
823 updateColorPreviewBox(panel, colorUpdate);
824 } else {
825 if (colorUpdate)
826 updateColorPreviewBox(panel, colorUpdate);
827 else
828 WMRedisplayWidget(panel->prevL);
831 XFreeGC(dpy, gc);
837 static void
838 cancelNewTexture(void *data)
840 _Panel *panel = (_Panel*)data;
842 HideTexturePanel(panel->texturePanel);
848 static char*
849 makeFileName(char *prefix)
851 char *fname;
853 fname = wstrdup(prefix);
855 while (access(fname, F_OK)==0) {
856 char buf[30];
858 free(fname);
859 sprintf(buf, "%08lx.cache", time(NULL));
860 fname = wstrappend(prefix, buf);
863 return fname;
869 static void
870 okNewTexture(void *data)
872 _Panel *panel = (_Panel*)data;
873 WMListItem *item;
874 char *name;
875 char *str;
876 proplist_t prop;
877 TextureListItem *titem;
878 WMScreen *scr = WMWidgetScreen(panel->win);
880 titem = wmalloc(sizeof(TextureListItem));
881 memset(titem, 0, sizeof(TextureListItem));
883 HideTexturePanel(panel->texturePanel);
885 name = GetTexturePanelTextureName(panel->texturePanel);
887 prop = GetTexturePanelTexture(panel->texturePanel);
889 str = PLGetDescription(prop);
891 titem->title = name;
892 titem->prop = prop;
893 titem->texture = str;
894 titem->selectedFor = 0;
896 titem->ispixmap = isPixmap(prop);
898 titem->path = makeFileName(panel->fprefix);
899 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT,
900 titem->path, 0);
902 item = WMAddListItem(panel->texLs, "");
903 item->clientData = titem;
905 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
909 static void
910 okEditTexture(void *data)
912 _Panel *panel = (_Panel*)data;
913 WMListItem *item;
914 char *name;
915 char *str;
916 proplist_t prop;
917 TextureListItem *titem;
919 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
920 titem = (TextureListItem*)item->clientData;
922 HideTexturePanel(panel->texturePanel);
924 if (titem->current) {
925 name = GetTexturePanelTextureName(panel->texturePanel);
927 free(titem->title);
928 titem->title = name;
931 prop = GetTexturePanelTexture(panel->texturePanel);
933 str = PLGetDescription(prop);
935 PLRelease(titem->prop);
936 titem->prop = prop;
938 titem->ispixmap = isPixmap(prop);
940 free(titem->texture);
941 titem->texture = str;
943 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
944 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
945 TEXPREV_WIDTH, TEXPREV_HEIGHT,
946 titem->path, 0);
948 WMRedisplayWidget(panel->texLs);
950 if (titem->selectedFor)
951 updatePreviewBox(panel, titem->selectedFor);
953 changePage(panel->secP, panel);
958 static void
959 editTexture(WMWidget *w, void *data)
961 _Panel *panel = (_Panel*)data;
962 WMListItem *item;
963 TextureListItem *titem;
965 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
966 titem = (TextureListItem*)item->clientData;
968 SetTexturePanelPixmapPath(panel->texturePanel,
969 GetObjectForKey("PixmapPath"));
971 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
973 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
974 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
976 ShowTexturePanel(panel->texturePanel);
981 static void
982 newTexture(WMWidget *w, void *data)
984 _Panel *panel = (_Panel*)data;
986 SetTexturePanelPixmapPath(panel->texturePanel,
987 GetObjectForKey("PixmapPath"));
989 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
991 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
993 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
995 ShowTexturePanel(panel->texturePanel);
1000 static void
1001 deleteTexture(WMWidget *w, void *data)
1003 _Panel *panel = (_Panel*)data;
1004 WMListItem *item;
1005 TextureListItem *titem;
1006 int row;
1007 int section;
1009 section = WMGetPopUpButtonSelectedItem(panel->secP);
1010 row = WMGetListSelectedItemRow(panel->texLs);
1011 item = WMGetListItem(panel->texLs, row);
1012 titem = (TextureListItem*)item->clientData;
1014 if (titem->selectedFor & (1 << section)) {
1015 TextureListItem *titem2;
1017 panel->textureIndex[section] = section;
1018 item = WMGetListItem(panel->texLs, section);
1019 titem2 = (TextureListItem*)item->clientData;
1020 titem2->selectedFor |= 1 << section;
1023 free(titem->title);
1024 free(titem->texture);
1025 PLRelease(titem->prop);
1026 if (titem->path) {
1027 if (remove(titem->path) < 0 && errno != ENOENT) {
1028 wsyserror("could not remove file %s", titem->path);
1030 free(titem->path);
1033 free(titem);
1035 WMRemoveListItem(panel->texLs, row);
1036 WMSetButtonEnabled(panel->delB, False);
1042 static void
1043 extractTexture(WMWidget *w, void *data)
1045 _Panel *panel = (_Panel*)data;
1046 char *path;
1047 WMOpenPanel *opanel;
1048 WMScreen *scr = WMWidgetScreen(w);
1050 opanel = WMGetOpenPanel(scr);
1051 WMSetFilePanelCanChooseDirectories(opanel, False);
1052 WMSetFilePanelCanChooseFiles(opanel, True);
1054 if (WMRunModalFilePanelForDirectory(opanel, panel->win, wgethomedir(),
1055 _("Select File"), NULL)) {
1056 path = WMGetFilePanelFileName(opanel);
1058 OpenExtractPanelFor(panel, path);
1060 free(path);
1065 static void
1066 changePage(WMWidget *w, void *data)
1068 _Panel *panel = (_Panel*)data;
1069 int section;
1070 WMListItem *item;
1071 TextureListItem *titem;
1072 WMScreen *scr = WMWidgetScreen(panel->frame);
1073 RContext *rc = WMScreenRContext(scr);
1074 static WMPoint positions[] = {
1075 {5, 10},
1076 {5, 40},
1077 {5, 70},
1078 {5, 100},
1079 {5, 120},
1080 {5, 160},
1081 {130, 150}
1084 if (w) {
1085 section = WMGetPopUpButtonSelectedItem(panel->secP);
1087 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1089 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1091 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1093 titem = (TextureListItem*)item->clientData;
1096 WMColor *color;
1098 color = WMGrayColor(scr);
1099 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1100 positions[panel->oldsection].x,
1101 positions[panel->oldsection].y, 22, 22);
1102 WMReleaseColor(color);
1104 if (w) {
1105 panel->oldsection = section;
1106 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1107 positions[section].y);
1109 WMRedisplayWidget(panel->prevL);
1114 static void
1115 previewClick(XEvent *event, void *clientData)
1117 _Panel *panel = (_Panel*)clientData;
1118 int i;
1120 switch (panel->oldTabItem) {
1121 case 0:
1122 for (i = 0; i < sizeof(previewPositions)/sizeof(WMRect); i++) {
1123 if (event->xbutton.x >= previewPositions[i].pos.x
1124 && event->xbutton.y >= previewPositions[i].pos.y
1125 && event->xbutton.x < previewPositions[i].pos.x
1126 + previewPositions[i].size.width
1127 && event->xbutton.y < previewPositions[i].pos.y
1128 + previewPositions[i].size.height) {
1130 WMSetPopUpButtonSelectedItem(panel->secP, i);
1131 changePage(panel->secP, panel);
1132 return;
1135 break;
1136 case 1:
1137 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1138 if (event->xbutton.x >= previewColorPositions[i].pos.x
1139 && event->xbutton.y >= previewColorPositions[i].pos.y
1140 && event->xbutton.x < previewColorPositions[i].pos.x
1141 + previewColorPositions[i].size.width
1142 && event->xbutton.y < previewColorPositions[i].pos.y
1143 + previewColorPositions[i].size.height) {
1145 /* yuck kluge */
1146 if (i == 7)
1147 i = 4;
1149 WMSetPopUpButtonSelectedItem(panel->colP, i);
1150 changeColorPage(panel->colP, panel);
1151 return;
1154 break;
1159 static void
1160 textureClick(WMWidget *w, void *data)
1162 _Panel *panel = (_Panel*)data;
1163 int i;
1164 WMListItem *item;
1165 TextureListItem *titem;
1167 i = WMGetListSelectedItemRow(panel->texLs);
1169 item = WMGetListItem(panel->texLs, i);
1171 titem = (TextureListItem*)item->clientData;
1173 if (titem->current) {
1174 WMSetButtonEnabled(panel->delB, False);
1175 } else {
1176 WMSetButtonEnabled(panel->delB, True);
1182 static void
1183 textureDoubleClick(WMWidget *w, void *data)
1185 _Panel *panel = (_Panel*)data;
1186 int i, section;
1187 WMListItem *item;
1188 TextureListItem *titem;
1190 /* unselect old texture */
1191 section = WMGetPopUpButtonSelectedItem(panel->secP);
1193 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1194 titem = (TextureListItem*)item->clientData;
1195 titem->selectedFor &= ~(1 << section);
1197 /* select new texture */
1198 i = WMGetListSelectedItemRow(panel->texLs);
1200 item = WMGetListItem(panel->texLs, i);
1202 titem = (TextureListItem*)item->clientData;
1204 titem->selectedFor |= 1<<section;
1206 panel->textureIndex[section] = i;
1208 WMRedisplayWidget(panel->texLs);
1210 updatePreviewBox(panel, 1<<section);
1215 static void
1216 paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
1217 WMRect *rect)
1219 _Panel *panel = (_Panel*)WMGetHangedData(lPtr);
1220 WMScreen *scr = WMWidgetScreen(lPtr);
1221 int width, height, x, y;
1222 Display *dpy = WMScreenDisplay(scr);
1223 WMColor *white = WMWhiteColor(scr);
1224 WMListItem *item;
1225 WMColor *black = WMBlackColor(scr);
1226 TextureListItem *titem;
1228 width = rect->size.width;
1229 height = rect->size.height;
1230 x = rect->pos.x;
1231 y = rect->pos.y;
1233 if (state & WLDSSelected)
1234 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
1235 else
1236 XClearArea(dpy, d, x, y, width, height, False);
1238 item = WMGetListItem(lPtr, index);
1239 titem = (TextureListItem*)item->clientData;
1241 if (titem->preview)
1242 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0, TEXPREV_WIDTH,
1243 TEXPREV_HEIGHT, x + 5, y + 5);
1245 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1246 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1247 else if (titem->selectedFor)
1248 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1250 WMDrawString(scr, d, WMColorGC(black), panel->boldFont,
1251 x + TEXPREV_WIDTH + 22, y + 2, titem->title,
1252 strlen(titem->title));
1254 WMDrawString(scr, d, WMColorGC(black), panel->smallFont,
1255 x + TEXPREV_WIDTH + 14, y + 18, titem->texture,
1256 strlen(titem->texture));
1259 WMReleaseColor(white);
1260 WMReleaseColor(black);
1265 static Pixmap
1266 loadRImage(WMScreen *scr, char *path)
1268 FILE *f;
1269 RImage *image;
1270 int w, h, d;
1271 int i;
1272 Pixmap pixmap;
1274 f = fopen(path, "r");
1275 if (!f)
1276 return None;
1278 fscanf(f, "%02x%02x%1x", &w, &h, &d);
1280 image = RCreateImage(w, h, d == 4);
1281 for (i = 0; i < d; i++) {
1282 fread(image->data[i], 1, w*h, f);
1284 fclose(f);
1286 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1287 RDestroyImage(image);
1289 return pixmap;
1294 static void
1295 fillTextureList(WMList *lPtr)
1297 proplist_t textureList;
1298 proplist_t texture;
1299 WMUserDefaults *udb = WMGetStandardUserDefaults();
1300 TextureListItem *titem;
1301 WMScreen *scr = WMWidgetScreen(lPtr);
1302 int i;
1304 textureList = WMGetUDObjectForKey(udb, "TextureList");
1305 if (!textureList)
1306 return;
1308 for (i = 0; i < PLGetNumberOfElements(textureList); i++) {
1309 WMListItem *item;
1311 texture = PLGetArrayElement(textureList, i);
1313 titem = wmalloc(sizeof(TextureListItem));
1314 memset(titem, 0, sizeof(TextureListItem));
1316 titem->title = wstrdup(PLGetString(PLGetArrayElement(texture, 0)));
1317 titem->prop = PLRetain(PLGetArrayElement(texture, 1));
1318 titem->texture = PLGetDescription(titem->prop);
1319 titem->selectedFor = 0;
1320 titem->path = wstrdup(PLGetString(PLGetArrayElement(texture, 2)));
1322 titem->preview = loadRImage(scr, titem->path);
1323 if (!titem->preview) {
1324 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH,
1325 TEXPREV_HEIGHT, NULL, 0);
1327 item = WMAddListItem(lPtr, "");
1328 item->clientData = titem;
1333 /*************************************************************************/
1336 static void
1337 changeColorPage(WMWidget *w, void *data)
1339 _Panel *panel = (_Panel*)data;
1340 int section;
1341 WMScreen *scr = WMWidgetScreen(panel->frame);
1342 RContext *rc = WMScreenRContext(scr);
1343 static WMPoint positions[] = {
1344 {5, 10},
1345 {5, 40},
1346 {5, 70},
1347 {5, 120},
1348 {5, 140},
1349 {5, 158},
1350 {5, 176},
1351 {5, 176},
1352 {130, 140},
1353 {130, 140},
1354 {130, 140},
1355 {130, 140}
1358 if (panel->preview) {
1359 WMColor *color;
1361 color = WMGrayColor(scr);
1362 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1363 positions[panel->oldcsection].x,
1364 positions[panel->oldcsection].y, 22, 22);
1365 WMReleaseColor(color);
1367 if (w) {
1368 section = WMGetPopUpButtonSelectedItem(panel->colP);
1370 panel->oldcsection = section;
1371 if (panel->preview)
1372 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1373 positions[section].y);
1375 section = WMGetPopUpButtonSelectedItem(panel->colP);
1377 WMSetColorWellColor(panel->colW, panel->colors[section]);
1379 WMRedisplayWidget(panel->prevL);
1383 static void
1384 paintText(WMScreen *scr, Drawable d, WMColor *color, WMFont *font,
1385 int x, int y, int w, int h, WMAlignment align, char *text)
1387 int l = strlen(text);
1389 switch (align) {
1390 case WALeft:
1391 x += 5;
1392 break;
1393 case WARight:
1394 x += w - 5 - WMWidthOfString(font, text, l);
1395 break;
1396 default:
1397 case WACenter:
1398 x += (w - WMWidthOfString(font, text, l))/2;
1399 break;
1401 WMDrawString(scr, d, WMColorGC(color), font, x,
1402 y + (h - WMFontHeight(font))/2, text, l);
1407 static void
1408 updateColorPreviewBox(_Panel *panel, int elements)
1410 WMScreen *scr = WMWidgetScreen(panel->frame);
1411 WMPixmap *pixmap;
1412 Pixmap d;
1414 pixmap = WMGetLabelImage(panel->prevL);
1415 d = WMGetPixmapXID(pixmap);
1417 if (elements & FTITLE_COL) {
1418 paintText(scr, d, panel->colors[0], panel->boldFont, 30, 10, 190, 20,
1419 panel->titleAlignment, _("Focused Window"));
1421 if (elements & UTITLE_COL) {
1422 paintText(scr, d, panel->colors[1], panel->boldFont, 30, 40, 190, 20,
1423 panel->titleAlignment, _("Unfocused Window"));
1425 if (elements & OTITLE_COL) {
1426 paintText(scr, d, panel->colors[2], panel->boldFont, 30, 70, 190, 20,
1427 panel->titleAlignment, _("Owner of Focused Window"));
1429 if (elements & MTITLE_COL) {
1430 paintText(scr, d, panel->colors[3], panel->boldFont, 30, 120, 90, 20,
1431 WALeft, _("Menu Title"));
1433 if (elements & MITEM_COL) {
1434 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 140, 90, 18,
1435 WALeft, _("Normal Item"));
1436 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 194, 90, 18,
1437 WALeft, _("Normal Item"));
1439 if (elements & MDISAB_COL) {
1440 paintText(scr, d, panel->colors[5], panel->normalFont, 30, 158, 90, 18,
1441 WALeft, _("Disabled Item"));
1443 if (elements & MHIGH_COL) {
1444 XFillRectangle(WMScreenDisplay(scr), d, WMColorGC(panel->colors[6]),
1445 31, 177, 87, 15);
1446 elements |= MHIGHT_COL;
1448 if (elements & MHIGHT_COL) {
1449 paintText(scr, d, panel->colors[7], panel->normalFont, 30, 176, 90, 18,
1450 WALeft, _("Highlighted"));
1453 if (elements & ICONT_COL) {
1454 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1455 155, 130, 64);
1457 if (elements & ICONB_COL) {
1458 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1459 0, 0, 30);
1461 if (elements & CLIP_COL) {
1462 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1463 0, 0, 30);
1465 if (elements & CCLIP_COL) {
1466 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1467 0, 0, 30);
1470 WMRedisplayWidget(panel->prevL);
1474 static void
1475 colorWellObserver(void *self, WMNotification *n)
1477 _Panel *panel = (_Panel*)self;
1478 int p;
1480 p = WMGetPopUpButtonSelectedItem(panel->colP);
1482 panel->colors[p] = WMGetColorWellColor(panel->colW);
1484 updateColorPreviewBox(panel, 1<<p);
1488 static void
1489 changedTabItem(struct WMTabViewDelegate *self, WMTabView *tabView,
1490 WMTabViewItem *item)
1492 _Panel *panel = self->data;
1493 int i;
1495 i = WMGetTabViewItemIdentifier(item);
1496 switch (i) {
1497 case 0:
1498 switch (panel->oldTabItem) {
1499 case 1:
1500 changeColorPage(NULL, panel);
1501 break;
1503 changePage(panel->secP, panel);
1504 break;
1505 case 1:
1506 switch (panel->oldTabItem) {
1507 case 0:
1508 changePage(NULL, panel);
1509 break;
1511 changeColorPage(panel->colP, panel);
1512 break;
1513 case 2:
1514 switch (panel->oldTabItem) {
1515 case 0:
1516 changePage(NULL, panel);
1517 break;
1518 case 1:
1519 changeColorPage(NULL, panel);
1520 break;
1522 break;
1525 panel->oldTabItem = i;
1529 /*************************************************************************/
1531 static void
1532 menuStyleCallback(WMWidget *self, void *data)
1534 _Panel *panel = (_Panel*)data;
1536 if (self == panel->mstyB[0]) {
1537 panel->menuStyle = MSTYLE_NORMAL;
1538 updatePreviewBox(panel, 1<<PMITEM);
1540 } else if (self == panel->mstyB[1]) {
1541 panel->menuStyle = MSTYLE_SINGLE;
1542 updatePreviewBox(panel, 1<<PMITEM);
1544 } else if (self == panel->mstyB[2]) {
1545 panel->menuStyle = MSTYLE_FLAT;
1546 updatePreviewBox(panel, 1<<PMITEM);
1551 static void
1552 titleAlignCallback(WMWidget *self, void *data)
1554 _Panel *panel = (_Panel*)data;
1556 if (self == panel->taliB[0]) {
1557 panel->titleAlignment = WALeft;
1558 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1560 } else if (self == panel->taliB[1]) {
1561 panel->titleAlignment = WACenter;
1562 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1564 } else if (self == panel->taliB[2]) {
1565 panel->titleAlignment = WARight;
1566 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1571 static void
1572 createPanel(Panel *p)
1574 _Panel *panel = (_Panel*)p;
1575 WMFont *font;
1576 WMScreen *scr = WMWidgetScreen(panel->win);
1577 WMTabViewItem *item;
1578 int i;
1579 char *tmp;
1580 Bool ok = True;
1582 panel->fprefix = wstrappend(wusergnusteppath(), "/.AppInfo");
1584 if (access(panel->fprefix, F_OK)!=0) {
1585 if (mkdir(panel->fprefix, 0755) < 0) {
1586 wsyserror(panel->fprefix);
1587 ok = False;
1590 if (ok) {
1591 tmp = wstrappend(panel->fprefix, "/WPrefs/");
1592 free(panel->fprefix);
1593 panel->fprefix = tmp;
1594 if (access(panel->fprefix, F_OK)!=0) {
1595 if (mkdir(panel->fprefix, 0755) < 0) {
1596 wsyserror(panel->fprefix);
1601 panel->smallFont = WMSystemFontOfSize(scr, 10);
1602 panel->normalFont = WMSystemFontOfSize(scr, 12);
1603 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1605 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1606 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1607 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1609 panel->frame = WMCreateFrame(panel->win);
1610 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
1611 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
1613 /* preview box */
1614 panel->prevL = WMCreateLabel(panel->frame);
1615 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1616 WMMoveWidget(panel->prevL, 15, 10);
1617 WMSetLabelRelief(panel->prevL, WRSunken);
1618 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1620 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask,
1621 previewClick, panel);
1624 /* tabview */
1626 tabviewDelegate.data = panel;
1628 panel->tabv = WMCreateTabView(panel->frame);
1629 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1630 WMMoveWidget(panel->tabv, 265, 10);
1631 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1633 /*** texture list ***/
1635 panel->texF = WMCreateFrame(panel->frame);
1636 WMSetFrameRelief(panel->texF, WRFlat);
1638 item = WMCreateTabViewItemWithIdentifier(0);
1639 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1640 WMSetTabViewItemLabel(item, _("Texture"));
1642 WMAddItemInTabView(panel->tabv, item);
1645 panel->secP = WMCreatePopUpButton(panel->texF);
1646 WMResizeWidget(panel->secP, 228, 20);
1647 WMMoveWidget(panel->secP, 7, 7);
1648 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1649 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1650 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1651 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1652 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1653 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1654 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1655 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1656 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1658 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1660 panel->texLs = WMCreateList(panel->texF);
1661 WMResizeWidget(panel->texLs, 165, 155);
1662 WMMoveWidget(panel->texLs, 70, 33);
1663 WMSetListUserDrawItemHeight(panel->texLs, 35);
1664 WMSetListUserDrawProc(panel->texLs, paintListItem);
1665 WMHangData(panel->texLs, panel);
1666 WMSetListAction(panel->texLs, textureClick, panel);
1667 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1669 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1670 "for the selected item."),
1671 WMWidgetView(panel->texLs));
1673 /* command buttons */
1675 font = WMSystemFontOfSize(scr, 10);
1678 panel->newB = WMCreateCommandButton(panel->texF);
1679 WMResizeWidget(panel->newB, 57, 39);
1680 WMMoveWidget(panel->newB, 7, 33);
1681 WMSetButtonFont(panel->newB, font);
1682 WMSetButtonImagePosition(panel->newB, WIPAbove);
1683 WMSetButtonText(panel->newB, _("New"));
1684 WMSetButtonAction(panel->newB, newTexture, panel);
1685 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1687 WMSetBalloonTextForView(_("Create a new texture."),
1688 WMWidgetView(panel->newB));
1690 panel->ripB = WMCreateCommandButton(panel->texF);
1691 WMResizeWidget(panel->ripB, 57, 39);
1692 WMMoveWidget(panel->ripB, 7, 72);
1693 WMSetButtonFont(panel->ripB, font);
1694 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1695 WMSetButtonText(panel->ripB, _("Extract..."));
1696 WMSetButtonAction(panel->ripB, extractTexture, panel);
1697 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1699 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1700 WMWidgetView(panel->ripB));
1702 WMSetButtonEnabled(panel->ripB, False);
1704 panel->editB = WMCreateCommandButton(panel->texF);
1705 WMResizeWidget(panel->editB, 57, 39);
1706 WMMoveWidget(panel->editB, 7, 111);
1707 WMSetButtonFont(panel->editB, font);
1708 WMSetButtonImagePosition(panel->editB, WIPAbove);
1709 WMSetButtonText(panel->editB, _("Edit"));
1710 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1711 WMSetButtonAction(panel->editB, editTexture, panel);
1712 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1713 WMWidgetView(panel->editB));
1715 panel->delB = WMCreateCommandButton(panel->texF);
1716 WMResizeWidget(panel->delB, 57, 38);
1717 WMMoveWidget(panel->delB, 7, 150);
1718 WMSetButtonFont(panel->delB, font);
1719 WMSetButtonImagePosition(panel->delB, WIPAbove);
1720 WMSetButtonText(panel->delB, _("Delete"));
1721 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1722 WMSetButtonEnabled(panel->delB, False);
1723 WMSetButtonAction(panel->delB, deleteTexture, panel);
1724 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1725 WMWidgetView(panel->delB));
1727 WMReleaseFont(font);
1729 WMMapSubwidgets(panel->texF);
1731 /*** colors ***/
1732 panel->colF = WMCreateFrame(panel->frame);
1733 WMSetFrameRelief(panel->colF, WRFlat);
1735 item = WMCreateTabViewItemWithIdentifier(1);
1736 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1737 WMSetTabViewItemLabel(item, _("Color"));
1739 WMAddItemInTabView(panel->tabv, item);
1741 panel->colP = WMCreatePopUpButton(panel->colF);
1742 WMResizeWidget(panel->colP, 228, 20);
1743 WMMoveWidget(panel->colP, 7, 7);
1744 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1745 WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1746 WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1747 WMAddPopUpButtonItem(panel->colP, _("Owner of Focused Window Title"));
1748 WMAddPopUpButtonItem(panel->colP, _("Menu Title"));
1749 WMAddPopUpButtonItem(panel->colP, _("Menu Item Text"));
1750 WMAddPopUpButtonItem(panel->colP, _("Disabled Menu Item Text"));
1751 WMAddPopUpButtonItem(panel->colP, _("Menu Highlight Color"));
1752 WMAddPopUpButtonItem(panel->colP, _("Highlighted Menu Text Color"));
1754 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1755 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1756 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1757 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1760 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1762 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1765 panel->colW = WMCreateColorWell(panel->colF);
1766 WMResizeWidget(panel->colW, 65, 50);
1767 WMMoveWidget(panel->colW, 30, 75);
1768 WMAddNotificationObserver(colorWellObserver, panel,
1769 WMColorWellDidChangeNotification, panel->colW);
1771 for (i = 0; i < 4; i++) {
1772 int j;
1773 for (j = 0; j < 6; j++) {
1774 panel->sampW[i] = WMCreateColorWell(panel->colF);
1775 WMResizeWidget(panel->sampW[i], 22, 22);
1776 WMMoveWidget(panel->sampW[i], 130 + i*22, 40 + j*22);
1777 WSetColorWellBordered(panel->sampW[i], False);
1781 WMMapSubwidgets(panel->colF);
1783 /*** options ***/
1784 panel->optF = WMCreateFrame(panel->frame);
1785 WMSetFrameRelief(panel->optF, WRFlat);
1787 item = WMCreateTabViewItemWithIdentifier(2);
1788 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1789 WMSetTabViewItemLabel(item, _("Options"));
1791 WMAddItemInTabView(panel->tabv, item);
1793 panel->mstyF = WMCreateFrame(panel->optF);
1794 WMResizeWidget(panel->mstyF, 215, 85);
1795 WMMoveWidget(panel->mstyF, 15, 10);
1796 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1798 for (i = 0; i < 3; i++) {
1799 WMPixmap *icon;
1800 char *path;
1802 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1803 WMResizeWidget(panel->mstyB[i], 54, 54);
1804 WMMoveWidget(panel->mstyB[i], 15 + i*65, 20);
1805 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1806 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1807 switch (i) {
1808 case 0:
1809 path = LocateImage(MSTYLE1_FILE);
1810 break;
1811 case 1:
1812 path = LocateImage(MSTYLE2_FILE);
1813 break;
1814 case 2:
1815 path = LocateImage(MSTYLE3_FILE);
1816 break;
1818 if (path) {
1819 icon = WMCreatePixmapFromFile(scr, path);
1820 if (icon) {
1821 WMSetButtonImage(panel->mstyB[i], icon);
1822 WMReleasePixmap(icon);
1823 } else {
1824 wwarning(_("could not load icon file %s"), path);
1826 free(path);
1829 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
1830 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
1832 WMMapSubwidgets(panel->mstyF);
1835 panel->taliF = WMCreateFrame(panel->optF);
1836 WMResizeWidget(panel->taliF, 110, 80);
1837 WMMoveWidget(panel->taliF, 15, 100);
1838 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
1840 for (i = 0; i < 3; i++) {
1841 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
1842 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
1843 switch (i) {
1844 case 0:
1845 WMSetButtonText(panel->taliB[i], _("Left"));
1846 break;
1847 case 1:
1848 WMSetButtonText(panel->taliB[i], _("Center"));
1849 break;
1850 case 2:
1851 WMSetButtonText(panel->taliB[i], _("Right"));
1852 break;
1854 WMResizeWidget(panel->taliB[i], 90, 18);
1855 WMMoveWidget(panel->taliB[i], 10, 15 + 20*i);
1857 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
1858 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
1860 WMMapSubwidgets(panel->taliB);
1862 WMMapSubwidgets(panel->optF);
1864 /**/
1866 WMRealizeWidget(panel->frame);
1867 WMMapSubwidgets(panel->frame);
1869 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1871 showData(panel);
1873 changePage(panel->secP, panel);
1875 fillTextureList(panel->texLs);
1877 panel->texturePanel = CreateTexturePanel(panel->win);
1882 static void
1883 setupTextureFor(WMList *list, char *key, char *defValue, char *title,
1884 int index)
1886 WMListItem *item;
1887 TextureListItem *titem;
1889 titem = wmalloc(sizeof(TextureListItem));
1890 memset(titem, 0, sizeof(TextureListItem));
1892 titem->title = wstrdup(title);
1893 titem->prop = GetObjectForKey(key);
1894 if (!titem->prop) {
1895 titem->prop = PLGetProplistWithDescription(defValue);
1896 } else {
1897 PLRetain(titem->prop);
1899 titem->texture = PLGetDescription((proplist_t)titem->prop);
1900 titem->current = 1;
1901 titem->selectedFor = 1<<index;
1903 titem->ispixmap = isPixmap(titem->prop);
1905 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop,
1906 TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1908 item = WMAddListItem(list, "");
1909 item->clientData = titem;
1914 static void
1915 showData(_Panel *panel)
1917 int i;
1918 char *str;
1920 str = GetStringForKey("MenuStyle");
1921 if (str && strcasecmp(str, "flat")==0) {
1922 panel->menuStyle = MSTYLE_FLAT;
1923 } else if (str && strcasecmp(str, "singletexture")==0) {
1924 panel->menuStyle = MSTYLE_SINGLE;
1925 } else {
1926 panel->menuStyle = MSTYLE_NORMAL;
1929 str = GetStringForKey("TitleJustify");
1930 if (str && strcasecmp(str, "left")==0) {
1931 panel->titleAlignment = WALeft;
1932 } else if (str && strcasecmp(str, "right")==0) {
1933 panel->titleAlignment = WARight;
1934 } else {
1935 panel->titleAlignment = WACenter;
1938 for (i = 0; i < sizeof(colorOptions)/(2*sizeof(char*)); i++) {
1939 WMColor *color;
1941 str = GetStringForKey(colorOptions[i*2]);
1942 if (!str)
1943 str = colorOptions[i*2+1];
1945 color = WMCreateNamedColor(WMWidgetScreen(panel->frame), str, False);
1947 panel->colors[i] = color;
1949 changeColorPage(panel->colP, panel);
1951 for (i = 0; i < sizeof(textureOptions)/(3*sizeof(char*)); i++) {
1952 setupTextureFor(panel->texLs, textureOptions[i*3],
1953 textureOptions[i*3+1], textureOptions[i*3+2], i);
1954 panel->textureIndex[i] = i;
1956 updatePreviewBox(panel, EVERYTHING);
1959 for (i = 0; i < 3; i++) {
1960 WMSetButtonSelected(panel->mstyB[i], i==panel->menuStyle);
1961 WMSetButtonSelected(panel->taliB[i], i==panel->titleAlignment);
1967 static void
1968 storeData(_Panel *panel)
1970 TextureListItem *titem;
1971 WMListItem *item;
1972 int i;
1974 for (i = 0; i < sizeof(textureOptions)/(sizeof(char*)*3); i++) {
1975 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
1976 titem = (TextureListItem*)item->clientData;
1977 SetObjectForKey(titem->prop, textureOptions[i*3]);
1980 for (i = 0; i < 8; i++) {
1981 SetStringForKey(WMGetColorRGBDescription(panel->colors[i]),
1982 colorOptions[i]);
1985 switch (panel->menuStyle) {
1986 case MSTYLE_SINGLE:
1987 SetStringForKey("singletexture", "MenuStyle");
1988 break;
1989 case MSTYLE_FLAT:
1990 SetStringForKey("flat", "MenuStyle");
1991 break;
1992 default:
1993 case MSTYLE_NORMAL:
1994 SetStringForKey("normal", "MenuStyle");
1995 break;
1997 switch (panel->titleAlignment) {
1998 case WALeft:
1999 SetStringForKey("left", "TitleJustify");
2000 break;
2001 case WARight:
2002 SetStringForKey("right", "TitleJustify");
2003 break;
2004 default:
2005 case WACenter:
2006 SetStringForKey("center", "TitleJustify");
2007 break;
2012 static void
2013 prepareForClose(_Panel *panel)
2015 proplist_t textureList;
2016 proplist_t texture;
2017 int i;
2018 TextureListItem *titem;
2019 WMListItem *item;
2020 WMUserDefaults *udb = WMGetStandardUserDefaults();
2022 textureList = PLMakeArrayFromElements(NULL, NULL);
2024 /* store list of textures */
2025 for (i = 7; i < WMGetListNumberOfRows(panel->texLs); i++) {
2026 item = WMGetListItem(panel->texLs, i);
2027 titem = (TextureListItem*)item->clientData;
2029 texture = PLMakeArrayFromElements(PLMakeString(titem->title),
2030 PLRetain(titem->prop),
2031 PLMakeString(titem->path),
2032 NULL);
2034 PLAppendArrayElement(textureList, texture);
2037 WMSetUDObjectForKey(udb, textureList, "TextureList");
2038 PLRelease(textureList);
2040 WMSynchronizeUserDefaults(udb);
2045 Panel*
2046 InitAppearance(WMScreen *scr, WMWindow *win)
2048 _Panel *panel;
2050 panel = wmalloc(sizeof(_Panel));
2051 memset(panel, 0, sizeof(_Panel));
2053 panel->sectionName = _("Appearance Preferences");
2055 panel->description = _("Background texture configuration for windows,\n"
2056 "menus and icons.");
2058 panel->win = win;
2060 panel->callbacks.createWidgets = createPanel;
2061 panel->callbacks.updateDomain = storeData;
2062 panel->callbacks.prepareForClose = prepareForClose;
2064 AddSection(panel, ICON_FILE);
2066 return panel;
2071 /****************************************************************************/
2075 typedef struct ExtractPanel {
2076 WMWindow *win;
2078 WMLabel *label;
2079 WMList *list;
2081 WMButton *closeB;
2082 WMButton *extrB;
2083 } ExtractPanel;
2087 static void
2088 OpenExtractPanelFor(_Panel *panel, char *path)
2090 ExtractPanel *epanel;
2091 WMColor *color;
2092 WMFont *font;
2093 WMScreen *scr = WMWidgetScreen(panel->win);
2095 epanel = wmalloc(sizeof(ExtractPanel));
2096 epanel->win = WMCreatePanelWithStyleForWindow(panel->win, "extract",
2097 WMTitledWindowMask
2098 |WMClosableWindowMask);
2099 WMResizeWidget(epanel->win, 245, 250);
2100 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2102 epanel->label = WMCreateLabel(epanel->win);
2103 WMResizeWidget(epanel->label, 225, 18);
2104 WMMoveWidget(epanel->label, 10, 10);
2105 WMSetLabelTextAlignment(epanel->label, WACenter);
2106 WMSetLabelRelief(epanel->label, WRSunken);
2108 color = WMDarkGrayColor(scr);
2109 WMSetWidgetBackgroundColor(epanel->label, color);
2110 WMReleaseColor(color);
2112 color = WMWhiteColor(scr);
2113 WMSetLabelTextColor(epanel->label, color);
2114 WMReleaseColor(color);
2116 font = WMBoldSystemFontOfSize(scr, 12);
2117 WMSetLabelFont(epanel->label, font);
2118 WMReleaseFont(font);
2120 WMSetLabelText(epanel->label, _("Textures"));
2122 epanel->list = WMCreateList(epanel->win);
2123 WMResizeWidget(epanel->list, 225, 165);
2124 WMMoveWidget(epanel->list, 10, 30);
2128 epanel->closeB = WMCreateCommandButton(epanel->win);
2129 WMResizeWidget(epanel->closeB, 74, 24);
2130 WMMoveWidget(epanel->closeB, 165, 215);
2131 WMSetButtonText(epanel->closeB, _("Close"));
2133 epanel->extrB = WMCreateCommandButton(epanel->win);
2134 WMResizeWidget(epanel->extrB, 74, 24);
2135 WMMoveWidget(epanel->extrB, 80, 215);
2136 WMSetButtonText(epanel->extrB, _("Extract"));
2138 WMMapSubwidgets(epanel->win);
2141 /* take textures from file */
2145 WMRealizeWidget(epanel->win);
2147 WMMapWidget(epanel->win);