Added an example of how to create a network client using WMConnection
[wmaker-crm.git] / WPrefs.app / Appearance.c
blobca31fc6d10d78a06a51cc28af28bced117a61ab0
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 if (path = wfindfileinarray(GetObjectForKey("PixmapPath"), str))
646 timage = RLoadImage(rc, path, 0);
648 if (!path || !timage) {
649 wwarning("could not load file '%s': %s", path ? path : str,
650 RMessageForError(RErrorCode));
651 } else {
652 str = PLGetString(PLGetArrayElement(texture, 2));
653 str2rcolor(rc, str, &color);
655 switch (toupper(type[0])) {
656 case 'T':
657 image = RMakeTiledImage(timage, width, height);
658 RDestroyImage(timage);
659 timage = image;
660 break;
661 case 'C':
662 image = RMakeCenteredImage(timage, width, height, &color);
663 RDestroyImage(timage);
664 timage = image;
665 break;
666 case 'S':
667 case 'M':
668 image = RScaleImage(timage, width, height);
669 RDestroyImage(timage);
670 timage = image;
671 break;
675 free(path);
678 if (!image)
679 return None;
681 if (path) {
682 dumpRImage(path, image);
685 if (border < 0) {
686 if (border == RESIZEBAR_BEVEL) {
687 drawResizebarBevel(image);
688 } else if (border == MENU_BEVEL) {
689 drawMenuBevel(image);
690 RBevelImage(image, RBEV_RAISED2);
692 } else if (border) {
693 RBevelImage(image, border);
696 RConvertImage(rc, image, &pixmap);
697 RDestroyImage(image);
699 return pixmap;
703 static Pixmap
704 renderMenu(_Panel *panel, proplist_t texture, int width, int iheight)
706 WMScreen *scr = WMWidgetScreen(panel->win);
707 Display *dpy = WMScreenDisplay(scr);
708 Pixmap pix, tmp;
709 GC gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
710 int i;
712 switch (panel->menuStyle) {
713 case MSTYLE_NORMAL:
714 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
716 pix = XCreatePixmap(dpy, tmp, width, iheight*4, WMScreenDepth(scr));
717 for (i = 0; i < 4; i++) {
718 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight*i);
720 XFreePixmap(dpy, tmp);
721 break;
722 case MSTYLE_SINGLE:
723 pix = renderTexture(scr, texture, width, iheight*4, NULL, MENU_BEVEL);
724 break;
725 case MSTYLE_FLAT:
726 pix = renderTexture(scr, texture, width, iheight*4, NULL, RBEV_RAISED2);
727 break;
729 XFreeGC(dpy, gc);
731 return pix;
735 static void
736 renderPreview(_Panel *panel, GC gc, int part, int relief)
738 WMListItem *item;
739 TextureListItem *titem;
740 Pixmap pix;
741 WMScreen *scr = WMWidgetScreen(panel->frame);
743 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
744 titem = (TextureListItem*)item->clientData;
746 pix = renderTexture(scr, titem->prop,
747 previewPositions[part].size.width,
748 previewPositions[part].size.height,
749 NULL, relief);
751 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
752 previewPositions[part].size.width,
753 previewPositions[part].size.height,
754 previewPositions[part].pos.x,
755 previewPositions[part].pos.y);
757 XFreePixmap(WMScreenDisplay(scr), pix);
761 static void
762 updatePreviewBox(_Panel *panel, int elements)
764 WMScreen *scr = WMWidgetScreen(panel->win);
765 Display *dpy = WMScreenDisplay(scr);
766 /* RContext *rc = WMScreenRContext(scr);*/
767 int refresh = 0;
768 Pixmap pix;
769 GC gc;
770 int colorUpdate = 0;
772 gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL);
775 if (panel->preview == None) {
776 WMColor *color;
778 panel->preview = XCreatePixmap(dpy, WMWidgetXID(panel->win),
779 240-4, 215-4, WMScreenDepth(scr));
781 color = WMGrayColor(scr);
782 XFillRectangle(dpy, panel->preview, WMColorGC(color),
783 0, 0, 240-4, 215-4);
784 WMReleaseColor(color);
786 refresh = -1;
790 if (elements & (1<<PFOCUSED)) {
791 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
792 colorUpdate |= FTITLE_COL;
794 if (elements & (1<<PUNFOCUSED)) {
795 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
796 colorUpdate |= UTITLE_COL;
798 if (elements & (1<<POWNER)) {
799 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
800 colorUpdate |= OTITLE_COL;
802 if (elements & (1<<PRESIZEBAR)) {
803 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
805 if (elements & (1<<PMTITLE)) {
806 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
807 colorUpdate |= MTITLE_COL;
809 if (elements & (1<<PMITEM)) {
810 WMListItem *item;
811 TextureListItem *titem;
813 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
814 titem = (TextureListItem*)item->clientData;
816 pix = renderMenu(panel, titem->prop,
817 previewPositions[PMITEM].size.width,
818 previewPositions[PMITEM].size.height/4);
820 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
821 previewPositions[PMITEM].size.width,
822 previewPositions[PMITEM].size.height,
823 previewPositions[PMITEM].pos.x,
824 previewPositions[PMITEM].pos.y);
826 XFreePixmap(dpy, pix);
828 colorUpdate |= MITEM_COL|MDISAB_COL|MHIGH_COL|MHIGHT_COL;
830 if (elements & (1<<PMITEM|1<<PMTITLE)) {
831 XDrawLine(dpy, panel->preview, gc, 29, 120, 29, 120+20*4+20);
832 XDrawLine(dpy, panel->preview, gc, 29, 119, 119, 119);
834 if (elements & (1<<PICON)) {
835 WMListItem *item;
836 TextureListItem *titem;
838 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
839 titem = (TextureListItem*)item->clientData;
841 renderPreview(panel, gc, PICON,
842 titem->ispixmap ? 0 : RBEV_RAISED3);
844 colorUpdate |= ICONT_COL|ICONB_COL|CLIP_COL|CCLIP_COL;
846 if (refresh < 0) {
847 WMPixmap *p;
849 p = WMCreatePixmapFromXPixmaps(scr, panel->preview, None,
850 240-4, 215-4, WMScreenDepth(scr));
852 WMSetLabelImage(panel->prevL, p);
853 WMReleasePixmap(p);
855 if (colorUpdate)
856 updateColorPreviewBox(panel, colorUpdate);
857 } else {
858 if (colorUpdate)
859 updateColorPreviewBox(panel, colorUpdate);
860 else
861 WMRedisplayWidget(panel->prevL);
864 XFreeGC(dpy, gc);
870 static void
871 cancelNewTexture(void *data)
873 _Panel *panel = (_Panel*)data;
875 HideTexturePanel(panel->texturePanel);
881 static char*
882 makeFileName(char *prefix)
884 char *fname;
886 fname = wstrdup(prefix);
888 while (access(fname, F_OK)==0) {
889 char buf[30];
891 free(fname);
892 sprintf(buf, "%08lx.cache", time(NULL));
893 fname = wstrappend(prefix, buf);
896 return fname;
902 static void
903 okNewTexture(void *data)
905 _Panel *panel = (_Panel*)data;
906 WMListItem *item;
907 char *name;
908 char *str;
909 proplist_t prop;
910 TextureListItem *titem;
911 WMScreen *scr = WMWidgetScreen(panel->win);
913 titem = wmalloc(sizeof(TextureListItem));
914 memset(titem, 0, sizeof(TextureListItem));
916 HideTexturePanel(panel->texturePanel);
918 name = GetTexturePanelTextureName(panel->texturePanel);
920 prop = GetTexturePanelTexture(panel->texturePanel);
922 str = PLGetDescription(prop);
924 titem->title = name;
925 titem->prop = prop;
926 titem->texture = str;
927 titem->selectedFor = 0;
929 titem->ispixmap = isPixmap(prop);
931 titem->path = makeFileName(panel->fprefix);
932 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT,
933 titem->path, 0);
935 item = WMAddListItem(panel->texLs, "");
936 item->clientData = titem;
938 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
942 static void
943 okEditTexture(void *data)
945 _Panel *panel = (_Panel*)data;
946 WMListItem *item;
947 char *name;
948 char *str;
949 proplist_t prop;
950 TextureListItem *titem;
952 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
953 titem = (TextureListItem*)item->clientData;
955 HideTexturePanel(panel->texturePanel);
957 if (titem->current) {
958 name = GetTexturePanelTextureName(panel->texturePanel);
960 free(titem->title);
961 titem->title = name;
964 prop = GetTexturePanelTexture(panel->texturePanel);
966 str = PLGetDescription(prop);
968 PLRelease(titem->prop);
969 titem->prop = prop;
971 titem->ispixmap = isPixmap(prop);
973 free(titem->texture);
974 titem->texture = str;
976 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
977 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
978 TEXPREV_WIDTH, TEXPREV_HEIGHT,
979 titem->path, 0);
981 WMRedisplayWidget(panel->texLs);
983 if (titem->selectedFor)
984 updatePreviewBox(panel, titem->selectedFor);
986 changePage(panel->secP, panel);
991 static void
992 editTexture(WMWidget *w, void *data)
994 _Panel *panel = (_Panel*)data;
995 WMListItem *item;
996 TextureListItem *titem;
998 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
999 titem = (TextureListItem*)item->clientData;
1001 SetTexturePanelPixmapPath(panel->texturePanel,
1002 GetObjectForKey("PixmapPath"));
1004 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
1006 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1007 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
1009 ShowTexturePanel(panel->texturePanel);
1014 static void
1015 newTexture(WMWidget *w, void *data)
1017 _Panel *panel = (_Panel*)data;
1019 SetTexturePanelPixmapPath(panel->texturePanel,
1020 GetObjectForKey("PixmapPath"));
1022 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1024 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1026 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1028 ShowTexturePanel(panel->texturePanel);
1033 static void
1034 deleteTexture(WMWidget *w, void *data)
1036 _Panel *panel = (_Panel*)data;
1037 WMListItem *item;
1038 TextureListItem *titem;
1039 int row;
1040 int section;
1042 section = WMGetPopUpButtonSelectedItem(panel->secP);
1043 row = WMGetListSelectedItemRow(panel->texLs);
1044 item = WMGetListItem(panel->texLs, row);
1045 titem = (TextureListItem*)item->clientData;
1047 if (titem->selectedFor & (1 << section)) {
1048 TextureListItem *titem2;
1050 panel->textureIndex[section] = section;
1051 item = WMGetListItem(panel->texLs, section);
1052 titem2 = (TextureListItem*)item->clientData;
1053 titem2->selectedFor |= 1 << section;
1056 free(titem->title);
1057 free(titem->texture);
1058 PLRelease(titem->prop);
1059 if (titem->path) {
1060 if (remove(titem->path) < 0 && errno != ENOENT) {
1061 wsyserror("could not remove file %s", titem->path);
1063 free(titem->path);
1066 free(titem);
1068 WMRemoveListItem(panel->texLs, row);
1069 WMSetButtonEnabled(panel->delB, False);
1075 static void
1076 extractTexture(WMWidget *w, void *data)
1078 _Panel *panel = (_Panel*)data;
1079 char *path;
1080 WMOpenPanel *opanel;
1081 WMScreen *scr = WMWidgetScreen(w);
1083 opanel = WMGetOpenPanel(scr);
1084 WMSetFilePanelCanChooseDirectories(opanel, False);
1085 WMSetFilePanelCanChooseFiles(opanel, True);
1087 if (WMRunModalFilePanelForDirectory(opanel, panel->win, wgethomedir(),
1088 _("Select File"), NULL)) {
1089 path = WMGetFilePanelFileName(opanel);
1091 OpenExtractPanelFor(panel, path);
1093 free(path);
1098 static void
1099 changePage(WMWidget *w, void *data)
1101 _Panel *panel = (_Panel*)data;
1102 int section;
1103 WMListItem *item;
1104 TextureListItem *titem;
1105 WMScreen *scr = WMWidgetScreen(panel->frame);
1106 RContext *rc = WMScreenRContext(scr);
1107 static WMPoint positions[] = {
1108 {5, 10},
1109 {5, 40},
1110 {5, 70},
1111 {5, 100},
1112 {5, 120},
1113 {5, 160},
1114 {130, 150}
1117 if (w) {
1118 section = WMGetPopUpButtonSelectedItem(panel->secP);
1120 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1122 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1124 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1126 titem = (TextureListItem*)item->clientData;
1129 WMColor *color;
1131 color = WMGrayColor(scr);
1132 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1133 positions[panel->oldsection].x,
1134 positions[panel->oldsection].y, 22, 22);
1135 WMReleaseColor(color);
1137 if (w) {
1138 panel->oldsection = section;
1139 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1140 positions[section].y);
1142 WMRedisplayWidget(panel->prevL);
1147 static void
1148 previewClick(XEvent *event, void *clientData)
1150 _Panel *panel = (_Panel*)clientData;
1151 int i;
1153 switch (panel->oldTabItem) {
1154 case 0:
1155 for (i = 0; i < sizeof(previewPositions)/sizeof(WMRect); i++) {
1156 if (event->xbutton.x >= previewPositions[i].pos.x
1157 && event->xbutton.y >= previewPositions[i].pos.y
1158 && event->xbutton.x < previewPositions[i].pos.x
1159 + previewPositions[i].size.width
1160 && event->xbutton.y < previewPositions[i].pos.y
1161 + previewPositions[i].size.height) {
1163 WMSetPopUpButtonSelectedItem(panel->secP, i);
1164 changePage(panel->secP, panel);
1165 return;
1168 break;
1169 case 1:
1170 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1171 if (event->xbutton.x >= previewColorPositions[i].pos.x
1172 && event->xbutton.y >= previewColorPositions[i].pos.y
1173 && event->xbutton.x < previewColorPositions[i].pos.x
1174 + previewColorPositions[i].size.width
1175 && event->xbutton.y < previewColorPositions[i].pos.y
1176 + previewColorPositions[i].size.height) {
1178 /* yuck kluge */
1179 if (i == 7)
1180 i = 4;
1182 WMSetPopUpButtonSelectedItem(panel->colP, i);
1183 changeColorPage(panel->colP, panel);
1184 return;
1187 break;
1192 static void
1193 textureClick(WMWidget *w, void *data)
1195 _Panel *panel = (_Panel*)data;
1196 int i;
1197 WMListItem *item;
1198 TextureListItem *titem;
1200 i = WMGetListSelectedItemRow(panel->texLs);
1202 item = WMGetListItem(panel->texLs, i);
1204 titem = (TextureListItem*)item->clientData;
1206 if (titem->current) {
1207 WMSetButtonEnabled(panel->delB, False);
1208 } else {
1209 WMSetButtonEnabled(panel->delB, True);
1215 static void
1216 textureDoubleClick(WMWidget *w, void *data)
1218 _Panel *panel = (_Panel*)data;
1219 int i, section;
1220 WMListItem *item;
1221 TextureListItem *titem;
1223 /* unselect old texture */
1224 section = WMGetPopUpButtonSelectedItem(panel->secP);
1226 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1227 titem = (TextureListItem*)item->clientData;
1228 titem->selectedFor &= ~(1 << section);
1230 /* select new texture */
1231 i = WMGetListSelectedItemRow(panel->texLs);
1233 item = WMGetListItem(panel->texLs, i);
1235 titem = (TextureListItem*)item->clientData;
1237 titem->selectedFor |= 1<<section;
1239 panel->textureIndex[section] = i;
1241 WMRedisplayWidget(panel->texLs);
1243 updatePreviewBox(panel, 1<<section);
1248 static void
1249 paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
1250 WMRect *rect)
1252 _Panel *panel = (_Panel*)WMGetHangedData(lPtr);
1253 WMScreen *scr = WMWidgetScreen(lPtr);
1254 int width, height, x, y;
1255 Display *dpy = WMScreenDisplay(scr);
1256 WMColor *white = WMWhiteColor(scr);
1257 WMListItem *item;
1258 WMColor *black = WMBlackColor(scr);
1259 TextureListItem *titem;
1261 item = WMGetListItem(lPtr, index);
1262 titem = (TextureListItem*)item->clientData;
1263 if (!titem) {
1264 WMReleaseColor(white);
1265 WMReleaseColor(black);
1266 return;
1269 width = rect->size.width;
1270 height = rect->size.height;
1271 x = rect->pos.x;
1272 y = rect->pos.y;
1274 if (state & WLDSSelected)
1275 XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
1276 else
1277 XClearArea(dpy, d, x, y, width, height, False);
1280 if (titem->preview)
1281 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1282 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1284 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1285 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1286 else if (titem->selectedFor)
1287 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1289 WMDrawString(scr, d, WMColorGC(black), panel->boldFont,
1290 x + TEXPREV_WIDTH + 22, y + 2, titem->title,
1291 strlen(titem->title));
1293 WMDrawString(scr, d, WMColorGC(black), panel->smallFont,
1294 x + TEXPREV_WIDTH + 14, y + 18, titem->texture,
1295 strlen(titem->texture));
1298 WMReleaseColor(white);
1299 WMReleaseColor(black);
1304 static Pixmap
1305 loadRImage(WMScreen *scr, char *path)
1307 FILE *f;
1308 RImage *image;
1309 int w, h, d;
1310 int i;
1311 Pixmap pixmap;
1313 f = fopen(path, "r");
1314 if (!f)
1315 return None;
1317 fscanf(f, "%02x%02x%1x", &w, &h, &d);
1319 image = RCreateImage(w, h, d == 4);
1320 for (i = 0; i < d; i++) {
1321 fread(image->data[i], 1, w*h, f);
1323 fclose(f);
1325 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1326 RDestroyImage(image);
1328 return pixmap;
1333 static void
1334 fillTextureList(WMList *lPtr)
1336 proplist_t textureList;
1337 proplist_t texture;
1338 WMUserDefaults *udb = WMGetStandardUserDefaults();
1339 TextureListItem *titem;
1340 WMScreen *scr = WMWidgetScreen(lPtr);
1341 int i;
1343 textureList = WMGetUDObjectForKey(udb, "TextureList");
1344 if (!textureList)
1345 return;
1347 for (i = 0; i < PLGetNumberOfElements(textureList); i++) {
1348 WMListItem *item;
1350 texture = PLGetArrayElement(textureList, i);
1352 titem = wmalloc(sizeof(TextureListItem));
1353 memset(titem, 0, sizeof(TextureListItem));
1355 titem->title = wstrdup(PLGetString(PLGetArrayElement(texture, 0)));
1356 titem->prop = PLRetain(PLGetArrayElement(texture, 1));
1357 titem->texture = PLGetDescription(titem->prop);
1358 titem->selectedFor = 0;
1359 titem->path = wstrdup(PLGetString(PLGetArrayElement(texture, 2)));
1361 titem->preview = loadRImage(scr, titem->path);
1362 if (!titem->preview) {
1363 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH,
1364 TEXPREV_HEIGHT, NULL, 0);
1366 item = WMAddListItem(lPtr, "");
1367 item->clientData = titem;
1372 static void
1373 fillColorList(_Panel *panel)
1375 WMColor *color;
1376 proplist_t list;
1377 WMUserDefaults *udb = WMGetStandardUserDefaults();
1378 WMScreen *scr = WMWidgetScreen(panel->frame);
1379 int i;
1381 list = WMGetUDObjectForKey(udb, "ColorList");
1382 if (!list) {
1383 for (i = 0; i < 24; i++) {
1384 color = WMCreateNamedColor(scr, sampleColors[i], False);
1385 if (!color)
1386 continue;
1387 WMSetColorWellColor(panel->sampW[i], color);
1388 WMReleaseColor(color);
1390 } else {
1391 proplist_t c;
1393 for (i = 0; i < WMIN(24, PLGetNumberOfElements(list)); i++) {
1394 c = PLGetArrayElement(list, i);
1395 if (!c || !PLIsString(c))
1396 continue;
1397 color = WMCreateNamedColor(scr, PLGetString(c), False);
1398 if (!color)
1399 continue;
1400 WMSetColorWellColor(panel->sampW[i], color);
1401 WMReleaseColor(color);
1407 /*************************************************************************/
1410 static void
1411 changeColorPage(WMWidget *w, void *data)
1413 _Panel *panel = (_Panel*)data;
1414 int section;
1415 WMScreen *scr = WMWidgetScreen(panel->frame);
1416 RContext *rc = WMScreenRContext(scr);
1417 static WMPoint positions[] = {
1418 {5, 10},
1419 {5, 40},
1420 {5, 70},
1421 {5, 120},
1422 {5, 140},
1423 {5, 160},
1424 {5, 180},
1425 {5, 180},
1426 {130, 140},
1427 {130, 140},
1428 {130, 140},
1429 {130, 140}
1432 if (panel->preview) {
1433 WMColor *color;
1435 color = WMGrayColor(scr);
1436 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1437 positions[panel->oldcsection].x,
1438 positions[panel->oldcsection].y, 22, 22);
1439 WMReleaseColor(color);
1441 if (w) {
1442 section = WMGetPopUpButtonSelectedItem(panel->colP);
1444 panel->oldcsection = section;
1445 if (panel->preview)
1446 WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1447 positions[section].y);
1449 section = WMGetPopUpButtonSelectedItem(panel->colP);
1451 WMSetColorWellColor(panel->colW, panel->colors[section]);
1453 WMRedisplayWidget(panel->prevL);
1457 static void
1458 paintText(WMScreen *scr, Drawable d, WMColor *color, WMFont *font,
1459 int x, int y, int w, int h, WMAlignment align, char *text)
1461 int l = strlen(text);
1463 switch (align) {
1464 case WALeft:
1465 x += 5;
1466 break;
1467 case WARight:
1468 x += w - 5 - WMWidthOfString(font, text, l);
1469 break;
1470 default:
1471 case WACenter:
1472 x += (w - WMWidthOfString(font, text, l))/2;
1473 break;
1475 WMDrawString(scr, d, WMColorGC(color), font, x,
1476 y + (h - WMFontHeight(font))/2, text, l);
1481 static void
1482 updateColorPreviewBox(_Panel *panel, int elements)
1484 WMScreen *scr = WMWidgetScreen(panel->frame);
1485 WMPixmap *pixmap;
1486 Pixmap d;
1488 pixmap = WMGetLabelImage(panel->prevL);
1489 d = WMGetPixmapXID(pixmap);
1491 if (elements & FTITLE_COL) {
1492 paintText(scr, d, panel->colors[0], panel->boldFont, 30, 10, 190, 20,
1493 panel->titleAlignment, _("Focused Window"));
1495 if (elements & UTITLE_COL) {
1496 paintText(scr, d, panel->colors[1], panel->boldFont, 30, 40, 190, 20,
1497 panel->titleAlignment, _("Unfocused Window"));
1499 if (elements & OTITLE_COL) {
1500 paintText(scr, d, panel->colors[2], panel->boldFont, 30, 70, 190, 20,
1501 panel->titleAlignment, _("Owner of Focused Window"));
1503 if (elements & MTITLE_COL) {
1504 paintText(scr, d, panel->colors[3], panel->boldFont, 30, 120, 90, 20,
1505 WALeft, _("Menu Title"));
1507 if (elements & MITEM_COL) {
1508 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 140, 90, 20,
1509 WALeft, _("Normal Item"));
1510 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 200, 90, 20,
1511 WALeft, _("Normal Item"));
1513 if (elements & MDISAB_COL) {
1514 paintText(scr, d, panel->colors[5], panel->normalFont, 30, 160, 90, 20,
1515 WALeft, _("Disabled Item"));
1517 if (elements & MHIGH_COL) {
1518 XFillRectangle(WMScreenDisplay(scr), d, WMColorGC(panel->colors[6]),
1519 31, 181, 87, 17);
1520 elements |= MHIGHT_COL;
1522 if (elements & MHIGHT_COL) {
1523 paintText(scr, d, panel->colors[7], panel->normalFont, 30, 180, 90, 20,
1524 WALeft, _("Highlighted"));
1527 if (elements & ICONT_COL) {
1528 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1529 155, 130, 64);
1531 if (elements & ICONB_COL) {
1532 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1533 0, 0, 30);
1535 if (elements & CLIP_COL) {
1536 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1537 0, 0, 30);
1539 if (elements & CCLIP_COL) {
1540 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1541 0, 0, 30);
1544 WMRedisplayWidget(panel->prevL);
1548 static void
1549 colorWellObserver(void *self, WMNotification *n)
1551 _Panel *panel = (_Panel*)self;
1552 int p;
1554 p = WMGetPopUpButtonSelectedItem(panel->colP);
1556 WMReleaseColor(panel->colors[p]);
1558 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1560 updateColorPreviewBox(panel, 1<<p);
1564 static void
1565 changedTabItem(struct WMTabViewDelegate *self, WMTabView *tabView,
1566 WMTabViewItem *item)
1568 _Panel *panel = self->data;
1569 int i;
1571 i = WMGetTabViewItemIdentifier(item);
1572 switch (i) {
1573 case 0:
1574 switch (panel->oldTabItem) {
1575 case 1:
1576 changeColorPage(NULL, panel);
1577 break;
1579 changePage(panel->secP, panel);
1580 break;
1581 case 1:
1582 switch (panel->oldTabItem) {
1583 case 0:
1584 changePage(NULL, panel);
1585 break;
1587 changeColorPage(panel->colP, panel);
1588 break;
1589 case 2:
1590 switch (panel->oldTabItem) {
1591 case 0:
1592 changePage(NULL, panel);
1593 break;
1594 case 1:
1595 changeColorPage(NULL, panel);
1596 break;
1598 break;
1601 panel->oldTabItem = i;
1605 /*************************************************************************/
1607 static void
1608 menuStyleCallback(WMWidget *self, void *data)
1610 _Panel *panel = (_Panel*)data;
1612 if (self == panel->mstyB[0]) {
1613 panel->menuStyle = MSTYLE_NORMAL;
1614 updatePreviewBox(panel, 1<<PMITEM);
1616 } else if (self == panel->mstyB[1]) {
1617 panel->menuStyle = MSTYLE_SINGLE;
1618 updatePreviewBox(panel, 1<<PMITEM);
1620 } else if (self == panel->mstyB[2]) {
1621 panel->menuStyle = MSTYLE_FLAT;
1622 updatePreviewBox(panel, 1<<PMITEM);
1627 static void
1628 titleAlignCallback(WMWidget *self, void *data)
1630 _Panel *panel = (_Panel*)data;
1632 if (self == panel->taliB[0]) {
1633 panel->titleAlignment = WALeft;
1634 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1636 } else if (self == panel->taliB[1]) {
1637 panel->titleAlignment = WACenter;
1638 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1640 } else if (self == panel->taliB[2]) {
1641 panel->titleAlignment = WARight;
1642 updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1647 static void
1648 createPanel(Panel *p)
1650 _Panel *panel = (_Panel*)p;
1651 WMFont *font;
1652 WMScreen *scr = WMWidgetScreen(panel->win);
1653 WMTabViewItem *item;
1654 int i;
1655 char *tmp;
1656 Bool ok = True;
1658 panel->fprefix = wstrappend(wusergnusteppath(), "/.AppInfo");
1660 if (access(panel->fprefix, F_OK)!=0) {
1661 if (mkdir(panel->fprefix, 0755) < 0) {
1662 wsyserror(panel->fprefix);
1663 ok = False;
1666 if (ok) {
1667 tmp = wstrappend(panel->fprefix, "/WPrefs/");
1668 free(panel->fprefix);
1669 panel->fprefix = tmp;
1670 if (access(panel->fprefix, F_OK)!=0) {
1671 if (mkdir(panel->fprefix, 0755) < 0) {
1672 wsyserror(panel->fprefix);
1677 panel->smallFont = WMSystemFontOfSize(scr, 10);
1678 panel->normalFont = WMSystemFontOfSize(scr, 12);
1679 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1681 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1682 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1683 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1685 panel->frame = WMCreateFrame(panel->win);
1686 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
1687 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
1689 /* preview box */
1690 panel->prevL = WMCreateLabel(panel->frame);
1691 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1692 WMMoveWidget(panel->prevL, 15, 10);
1693 WMSetLabelRelief(panel->prevL, WRSunken);
1694 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1696 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask,
1697 previewClick, panel);
1700 /* tabview */
1702 tabviewDelegate.data = panel;
1704 panel->tabv = WMCreateTabView(panel->frame);
1705 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1706 WMMoveWidget(panel->tabv, 265, 10);
1707 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1709 /*** texture list ***/
1711 panel->texF = WMCreateFrame(panel->frame);
1712 WMSetFrameRelief(panel->texF, WRFlat);
1714 item = WMCreateTabViewItemWithIdentifier(0);
1715 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1716 WMSetTabViewItemLabel(item, _("Texture"));
1718 WMAddItemInTabView(panel->tabv, item);
1721 panel->secP = WMCreatePopUpButton(panel->texF);
1722 WMResizeWidget(panel->secP, 228, 20);
1723 WMMoveWidget(panel->secP, 7, 7);
1724 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1725 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1726 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1727 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1728 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1729 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1730 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1731 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1733 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1734 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1736 panel->texLs = WMCreateList(panel->texF);
1737 WMResizeWidget(panel->texLs, 165, 155);
1738 WMMoveWidget(panel->texLs, 70, 33);
1739 WMSetListUserDrawItemHeight(panel->texLs, 35);
1740 WMSetListUserDrawProc(panel->texLs, paintListItem);
1741 WMHangData(panel->texLs, panel);
1742 WMSetListAction(panel->texLs, textureClick, panel);
1743 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1745 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1746 "for the selected item."),
1747 WMWidgetView(panel->texLs));
1749 /* command buttons */
1751 font = WMSystemFontOfSize(scr, 10);
1754 panel->newB = WMCreateCommandButton(panel->texF);
1755 WMResizeWidget(panel->newB, 57, 39);
1756 WMMoveWidget(panel->newB, 7, 33);
1757 WMSetButtonFont(panel->newB, font);
1758 WMSetButtonImagePosition(panel->newB, WIPAbove);
1759 WMSetButtonText(panel->newB, _("New"));
1760 WMSetButtonAction(panel->newB, newTexture, panel);
1761 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
1763 WMSetBalloonTextForView(_("Create a new texture."),
1764 WMWidgetView(panel->newB));
1766 panel->ripB = WMCreateCommandButton(panel->texF);
1767 WMResizeWidget(panel->ripB, 57, 39);
1768 WMMoveWidget(panel->ripB, 7, 72);
1769 WMSetButtonFont(panel->ripB, font);
1770 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1771 WMSetButtonText(panel->ripB, _("Extract..."));
1772 WMSetButtonAction(panel->ripB, extractTexture, panel);
1773 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
1775 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1776 WMWidgetView(panel->ripB));
1778 WMSetButtonEnabled(panel->ripB, False);
1780 panel->editB = WMCreateCommandButton(panel->texF);
1781 WMResizeWidget(panel->editB, 57, 39);
1782 WMMoveWidget(panel->editB, 7, 111);
1783 WMSetButtonFont(panel->editB, font);
1784 WMSetButtonImagePosition(panel->editB, WIPAbove);
1785 WMSetButtonText(panel->editB, _("Edit"));
1786 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
1787 WMSetButtonAction(panel->editB, editTexture, panel);
1788 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1789 WMWidgetView(panel->editB));
1791 panel->delB = WMCreateCommandButton(panel->texF);
1792 WMResizeWidget(panel->delB, 57, 38);
1793 WMMoveWidget(panel->delB, 7, 150);
1794 WMSetButtonFont(panel->delB, font);
1795 WMSetButtonImagePosition(panel->delB, WIPAbove);
1796 WMSetButtonText(panel->delB, _("Delete"));
1797 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
1798 WMSetButtonEnabled(panel->delB, False);
1799 WMSetButtonAction(panel->delB, deleteTexture, panel);
1800 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1801 WMWidgetView(panel->delB));
1803 WMReleaseFont(font);
1805 WMMapSubwidgets(panel->texF);
1807 /*** colors ***/
1808 panel->colF = WMCreateFrame(panel->frame);
1809 WMSetFrameRelief(panel->colF, WRFlat);
1811 item = WMCreateTabViewItemWithIdentifier(1);
1812 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1813 WMSetTabViewItemLabel(item, _("Color"));
1815 WMAddItemInTabView(panel->tabv, item);
1817 panel->colP = WMCreatePopUpButton(panel->colF);
1818 WMResizeWidget(panel->colP, 228, 20);
1819 WMMoveWidget(panel->colP, 7, 7);
1820 WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1821 WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1822 WMAddPopUpButtonItem(panel->colP, _("Owner of Focused Window Title"));
1823 WMAddPopUpButtonItem(panel->colP, _("Menu Title"));
1824 WMAddPopUpButtonItem(panel->colP, _("Menu Item Text"));
1825 WMAddPopUpButtonItem(panel->colP, _("Disabled Menu Item Text"));
1826 WMAddPopUpButtonItem(panel->colP, _("Menu Highlight Color"));
1827 WMAddPopUpButtonItem(panel->colP, _("Highlighted Menu Text Color"));
1829 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1830 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1831 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1832 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1835 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1837 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1840 panel->colW = WMCreateColorWell(panel->colF);
1841 WMResizeWidget(panel->colW, 65, 50);
1842 WMMoveWidget(panel->colW, 30, 75);
1843 WMAddNotificationObserver(colorWellObserver, panel,
1844 WMColorWellDidChangeNotification, panel->colW);
1846 for (i = 0; i < 4; i++) {
1847 int j;
1848 for (j = 0; j < 6; j++) {
1849 panel->sampW[i+j*4] = WMCreateColorWell(panel->colF);
1850 WMResizeWidget(panel->sampW[i+j*4], 22, 22);
1851 WMMoveWidget(panel->sampW[i+j*4], 130 + i*22, 40 + j*22);
1852 WSetColorWellBordered(panel->sampW[i+j*4], False);
1856 WMMapSubwidgets(panel->colF);
1858 /*** options ***/
1859 panel->optF = WMCreateFrame(panel->frame);
1860 WMSetFrameRelief(panel->optF, WRFlat);
1862 item = WMCreateTabViewItemWithIdentifier(2);
1863 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1864 WMSetTabViewItemLabel(item, _("Options"));
1866 WMAddItemInTabView(panel->tabv, item);
1868 panel->mstyF = WMCreateFrame(panel->optF);
1869 WMResizeWidget(panel->mstyF, 215, 85);
1870 WMMoveWidget(panel->mstyF, 15, 10);
1871 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1873 for (i = 0; i < 3; i++) {
1874 WMPixmap *icon;
1875 char *path;
1877 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1878 WMResizeWidget(panel->mstyB[i], 54, 54);
1879 WMMoveWidget(panel->mstyB[i], 15 + i*65, 20);
1880 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1881 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1882 switch (i) {
1883 case 0:
1884 path = LocateImage(MSTYLE1_FILE);
1885 break;
1886 case 1:
1887 path = LocateImage(MSTYLE2_FILE);
1888 break;
1889 case 2:
1890 path = LocateImage(MSTYLE3_FILE);
1891 break;
1893 if (path) {
1894 icon = WMCreatePixmapFromFile(scr, path);
1895 if (icon) {
1896 WMSetButtonImage(panel->mstyB[i], icon);
1897 WMReleasePixmap(icon);
1898 } else {
1899 wwarning(_("could not load icon file %s"), path);
1901 free(path);
1904 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
1905 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
1907 WMMapSubwidgets(panel->mstyF);
1910 panel->taliF = WMCreateFrame(panel->optF);
1911 WMResizeWidget(panel->taliF, 110, 80);
1912 WMMoveWidget(panel->taliF, 15, 100);
1913 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
1915 for (i = 0; i < 3; i++) {
1916 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
1917 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
1918 switch (i) {
1919 case 0:
1920 WMSetButtonText(panel->taliB[i], _("Left"));
1921 break;
1922 case 1:
1923 WMSetButtonText(panel->taliB[i], _("Center"));
1924 break;
1925 case 2:
1926 WMSetButtonText(panel->taliB[i], _("Right"));
1927 break;
1929 WMResizeWidget(panel->taliB[i], 90, 18);
1930 WMMoveWidget(panel->taliB[i], 10, 15 + 20*i);
1932 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
1933 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
1935 WMMapSubwidgets(panel->taliF);
1937 WMMapSubwidgets(panel->optF);
1939 /**/
1941 WMRealizeWidget(panel->frame);
1942 WMMapSubwidgets(panel->frame);
1944 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1946 showData(panel);
1948 changePage(panel->secP, panel);
1950 fillTextureList(panel->texLs);
1952 fillColorList(panel);
1954 panel->texturePanel = CreateTexturePanel(panel->win);
1959 static void
1960 setupTextureFor(WMList *list, char *key, char *defValue, char *title,
1961 int index)
1963 WMListItem *item;
1964 TextureListItem *titem;
1966 titem = wmalloc(sizeof(TextureListItem));
1967 memset(titem, 0, sizeof(TextureListItem));
1969 titem->title = wstrdup(title);
1970 titem->prop = GetObjectForKey(key);
1971 if (!titem->prop || !PLIsArray(titem->prop)) {
1972 /* Maybe also give a error message to stderr that the entry is bad? */
1973 titem->prop = PLGetProplistWithDescription(defValue);
1974 } else {
1975 PLRetain(titem->prop);
1977 titem->texture = PLGetDescription((proplist_t)titem->prop);
1978 titem->current = 1;
1979 titem->selectedFor = 1<<index;
1981 titem->ispixmap = isPixmap(titem->prop);
1983 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop,
1984 TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1986 item = WMAddListItem(list, "");
1987 item->clientData = titem;
1992 static void
1993 showData(_Panel *panel)
1995 int i;
1996 char *str;
1998 str = GetStringForKey("MenuStyle");
1999 if (str && strcasecmp(str, "flat")==0) {
2000 panel->menuStyle = MSTYLE_FLAT;
2001 } else if (str && strcasecmp(str, "singletexture")==0) {
2002 panel->menuStyle = MSTYLE_SINGLE;
2003 } else {
2004 panel->menuStyle = MSTYLE_NORMAL;
2007 str = GetStringForKey("TitleJustify");
2008 if (str && strcasecmp(str, "left")==0) {
2009 panel->titleAlignment = WALeft;
2010 } else if (str && strcasecmp(str, "right")==0) {
2011 panel->titleAlignment = WARight;
2012 } else {
2013 panel->titleAlignment = WACenter;
2016 for (i = 0; i < sizeof(colorOptions)/(2*sizeof(char*)); i++) {
2017 WMColor *color;
2019 str = GetStringForKey(colorOptions[i*2]);
2020 if (!str)
2021 str = colorOptions[i*2+1];
2023 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->frame), str, False))) {
2024 color = WMCreateNamedColor(WMWidgetScreen(panel->frame), "#000000", False);
2027 panel->colors[i] = color;
2029 changeColorPage(panel->colP, panel);
2031 for (i = 0; i < sizeof(textureOptions)/(3*sizeof(char*)); i++) {
2032 setupTextureFor(panel->texLs, textureOptions[i*3],
2033 textureOptions[i*3+1], textureOptions[i*3+2], i);
2034 panel->textureIndex[i] = i;
2036 updatePreviewBox(panel, EVERYTHING);
2039 for (i = 0; i < 3; i++) {
2040 WMSetButtonSelected(panel->mstyB[i], i==panel->menuStyle);
2041 WMSetButtonSelected(panel->taliB[i], i==panel->titleAlignment);
2047 static void
2048 storeData(_Panel *panel)
2050 TextureListItem *titem;
2051 WMListItem *item;
2052 int i;
2054 for (i = 0; i < sizeof(textureOptions)/(sizeof(char*)*3); i++) {
2055 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2056 titem = (TextureListItem*)item->clientData;
2057 SetObjectForKey(titem->prop, textureOptions[i*3]);
2060 for (i = 0; i < 8; i++) {
2061 char *str;
2063 str = WMGetColorRGBDescription(panel->colors[i]);
2065 if (str) {
2066 SetStringForKey(str, colorOptions[i*2]);
2067 free(str);
2071 switch (panel->menuStyle) {
2072 case MSTYLE_SINGLE:
2073 SetStringForKey("singletexture", "MenuStyle");
2074 break;
2075 case MSTYLE_FLAT:
2076 SetStringForKey("flat", "MenuStyle");
2077 break;
2078 default:
2079 case MSTYLE_NORMAL:
2080 SetStringForKey("normal", "MenuStyle");
2081 break;
2083 switch (panel->titleAlignment) {
2084 case WALeft:
2085 SetStringForKey("left", "TitleJustify");
2086 break;
2087 case WARight:
2088 SetStringForKey("right", "TitleJustify");
2089 break;
2090 default:
2091 case WACenter:
2092 SetStringForKey("center", "TitleJustify");
2093 break;
2098 static void
2099 prepareForClose(_Panel *panel)
2101 proplist_t textureList;
2102 proplist_t texture;
2103 TextureListItem *titem;
2104 WMListItem *item;
2105 WMUserDefaults *udb = WMGetStandardUserDefaults();
2106 int i;
2108 textureList = PLMakeArrayFromElements(NULL, NULL);
2110 /* store list of textures */
2111 for (i = 7; i < WMGetListNumberOfRows(panel->texLs); i++) {
2112 item = WMGetListItem(panel->texLs, i);
2113 titem = (TextureListItem*)item->clientData;
2115 texture = PLMakeArrayFromElements(PLMakeString(titem->title),
2116 PLRetain(titem->prop),
2117 PLMakeString(titem->path),
2118 NULL);
2120 PLAppendArrayElement(textureList, texture);
2123 WMSetUDObjectForKey(udb, textureList, "TextureList");
2124 PLRelease(textureList);
2126 /* store list of colors */
2127 textureList = PLMakeArrayFromElements(NULL, NULL);
2128 for (i = 0; i < 24; i++) {
2129 WMColor *color;
2130 char *str;
2132 color = WMGetColorWellColor(panel->sampW[i]);
2134 str = WMGetColorRGBDescription(color);
2135 PLAppendArrayElement(textureList, PLMakeString(str));
2136 free(str);
2138 WMSetUDObjectForKey(udb, textureList, "ColorList");
2139 PLRelease(textureList);
2141 WMSynchronizeUserDefaults(udb);
2146 Panel*
2147 InitAppearance(WMScreen *scr, WMWindow *win)
2149 _Panel *panel;
2151 panel = wmalloc(sizeof(_Panel));
2152 memset(panel, 0, sizeof(_Panel));
2154 panel->sectionName = _("Appearance Preferences");
2156 panel->description = _("Background texture configuration for windows,\n"
2157 "menus and icons.");
2159 panel->win = win;
2161 panel->callbacks.createWidgets = createPanel;
2162 panel->callbacks.updateDomain = storeData;
2163 panel->callbacks.prepareForClose = prepareForClose;
2165 AddSection(panel, ICON_FILE);
2167 return panel;
2172 /****************************************************************************/
2176 typedef struct ExtractPanel {
2177 WMWindow *win;
2179 WMLabel *label;
2180 WMList *list;
2182 WMButton *closeB;
2183 WMButton *extrB;
2184 } ExtractPanel;
2188 static void
2189 OpenExtractPanelFor(_Panel *panel, char *path)
2191 ExtractPanel *epanel;
2192 WMColor *color;
2193 WMFont *font;
2194 WMScreen *scr = WMWidgetScreen(panel->win);
2196 epanel = wmalloc(sizeof(ExtractPanel));
2197 epanel->win = WMCreatePanelWithStyleForWindow(panel->win, "extract",
2198 WMTitledWindowMask
2199 |WMClosableWindowMask);
2200 WMResizeWidget(epanel->win, 245, 250);
2201 WMSetWindowTitle(epanel->win, _("Extract Texture"));
2203 epanel->label = WMCreateLabel(epanel->win);
2204 WMResizeWidget(epanel->label, 225, 18);
2205 WMMoveWidget(epanel->label, 10, 10);
2206 WMSetLabelTextAlignment(epanel->label, WACenter);
2207 WMSetLabelRelief(epanel->label, WRSunken);
2209 color = WMDarkGrayColor(scr);
2210 WMSetWidgetBackgroundColor(epanel->label, color);
2211 WMReleaseColor(color);
2213 color = WMWhiteColor(scr);
2214 WMSetLabelTextColor(epanel->label, color);
2215 WMReleaseColor(color);
2217 font = WMBoldSystemFontOfSize(scr, 12);
2218 WMSetLabelFont(epanel->label, font);
2219 WMReleaseFont(font);
2221 WMSetLabelText(epanel->label, _("Textures"));
2223 epanel->list = WMCreateList(epanel->win);
2224 WMResizeWidget(epanel->list, 225, 165);
2225 WMMoveWidget(epanel->list, 10, 30);
2229 epanel->closeB = WMCreateCommandButton(epanel->win);
2230 WMResizeWidget(epanel->closeB, 74, 24);
2231 WMMoveWidget(epanel->closeB, 165, 215);
2232 WMSetButtonText(epanel->closeB, _("Close"));
2234 epanel->extrB = WMCreateCommandButton(epanel->win);
2235 WMResizeWidget(epanel->extrB, 74, 24);
2236 WMMoveWidget(epanel->extrB, 80, 215);
2237 WMSetButtonText(epanel->extrB, _("Extract"));
2239 WMMapSubwidgets(epanel->win);
2242 /* take textures from file */
2246 WMRealizeWidget(epanel->win);
2248 WMMapWidget(epanel->win);