1 /* Apperance.c- color/texture for titlebar etc.
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1999 Alfredo K. Kojima
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,
31 #include <sys/types.h>
38 #include "TexturePanel.h"
40 typedef struct _Panel
{
46 CallbackRec callbacks
;
74 WMColorWell
*sampW
[24];
93 TexturePanel
*texturePanel
;
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
= {
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"
166 static char * blueled_xpm
[] = {
196 static char *blueled2_xpm
[] = {
197 /* width height num_colors chars_per_pixel */
229 static char * hand_xpm
[] = {
251 " .))),%.......... ",
252 " .)-)),&)))))))))$. ",
253 " .-&))))))))),,,,;;. ",
254 " .=)))))))));-=***&$. ",
255 " .=)))))))),..+..... ",
272 static char *sampleColors
[] = {
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
[] = {
368 {{30,140},{90,20*4}},
372 #define EVERYTHING 0xff
375 static WMRect previewColorPositions
[] = {
393 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
397 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
400 color
->red
= xcolor
.red
>> 8;
401 color
->green
= xcolor
.green
>> 8;
402 color
->blue
= xcolor
.blue
>> 8;
407 dumpRImage(char *path
, RImage
*image
)
411 f
= fopen(path
, "w");
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
);
423 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
433 isPixmap(proplist_t prop
)
438 p
= PLGetArrayElement(prop
, 0);
440 if (strcasecmp(&s
[1], "pixmap")==0)
447 /**********************************************************************/
450 drawResizebarBevel(RImage
*img
)
455 int width
= img
->width
;
456 int height
= img
->height
;
460 black
.red
= black
.green
= black
.blue
= 0;
463 light
.red
= light
.green
= light
.blue
= 80;
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,
476 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
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
);
486 drawMenuBevel(RImage
*img
)
488 RColor light
, dark
, mid
;
490 int iheight
= img
->height
/ 4;
493 light
.red
= light
.green
= light
.blue
= 80;
496 dark
.red
= dark
.green
= dark
.blue
= 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
);
514 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
515 char *path
, int border
)
518 RImage
*image
= NULL
;
520 RContext
*rc
= WMScreenRContext(scr
);
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) {
539 switch (toupper(type
[0])) {
541 style
= RVerticalGradient
;
544 style
= RHorizontalGradient
;
548 style
= RDiagonalGradient
;
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') {
562 RImage
*grad
, *timage
;
565 switch (toupper(type
[1])) {
567 style
= RVerticalGradient
;
570 style
= RHorizontalGradient
;
574 style
= RDiagonalGradient
;
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 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
586 timage
= RLoadImage(rc
, path
, 0);
589 wwarning("could not load file '%s': %s", path
,
590 RMessageForError(RErrorCode
));
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
);
602 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
607 switch (toupper(type
[1])) {
609 style
= RVerticalGradient
;
612 style
= RHorizontalGradient
;
616 style
= RDiagonalGradient
;
620 j
= PLGetNumberOfElements(texture
);
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]);
632 image
= RRenderMultiGradient(width
, height
, colors
, style
);
634 for (i
= 0; colors
[i
]!=NULL
; i
++)
638 } else if (strcasecmp(&type
[1], "pixmap")==0) {
639 RImage
*timage
= NULL
;
643 str
= PLGetString(PLGetArrayElement(texture
, 1));
645 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
647 timage
= RLoadImage(rc
, path
, 0);
650 wwarning("could not load file '%s': %s", path
? path
: str
,
651 RMessageForError(RErrorCode
));
653 str
= PLGetString(PLGetArrayElement(texture
, 2));
654 str2rcolor(rc
, str
, &color
);
656 switch (toupper(type
[0])) {
658 image
= RMakeTiledImage(timage
, width
, height
);
659 RDestroyImage(timage
);
663 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
664 RDestroyImage(timage
);
669 image
= RScaleImage(timage
, width
, height
);
670 RDestroyImage(timage
);
683 dumpRImage(path
, image
);
687 if (border
== RESIZEBAR_BEVEL
) {
688 drawResizebarBevel(image
);
689 } else if (border
== MENU_BEVEL
) {
690 drawMenuBevel(image
);
691 RBevelImage(image
, RBEV_RAISED2
);
694 RBevelImage(image
, border
);
697 RConvertImage(rc
, image
, &pixmap
);
698 RDestroyImage(image
);
705 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
707 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
708 Display
*dpy
= WMScreenDisplay(scr
);
710 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
713 switch (panel
->menuStyle
) {
715 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
717 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*4, WMScreenDepth(scr
));
718 for (i
= 0; i
< 4; i
++) {
719 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
*i
);
721 XFreePixmap(dpy
, tmp
);
724 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, MENU_BEVEL
);
727 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, RBEV_RAISED2
);
737 renderPreview(_Panel
*panel
, GC gc
, int part
, int relief
)
740 TextureListItem
*titem
;
742 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
744 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
745 titem
= (TextureListItem
*)item
->clientData
;
747 pix
= renderTexture(scr
, titem
->prop
,
748 previewPositions
[part
].size
.width
,
749 previewPositions
[part
].size
.height
,
752 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
753 previewPositions
[part
].size
.width
,
754 previewPositions
[part
].size
.height
,
755 previewPositions
[part
].pos
.x
,
756 previewPositions
[part
].pos
.y
);
758 XFreePixmap(WMScreenDisplay(scr
), pix
);
763 updatePreviewBox(_Panel
*panel
, int elements
)
765 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
766 Display
*dpy
= WMScreenDisplay(scr
);
767 /* RContext *rc = WMScreenRContext(scr);*/
773 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
776 if (panel
->preview
== None
) {
779 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
780 240-4, 215-4, WMScreenDepth(scr
));
782 color
= WMGrayColor(scr
);
783 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
785 WMReleaseColor(color
);
791 if (elements
& (1<<PFOCUSED
)) {
792 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
793 colorUpdate
|= FTITLE_COL
;
795 if (elements
& (1<<PUNFOCUSED
)) {
796 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
797 colorUpdate
|= UTITLE_COL
;
799 if (elements
& (1<<POWNER
)) {
800 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
801 colorUpdate
|= OTITLE_COL
;
803 if (elements
& (1<<PRESIZEBAR
)) {
804 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
806 if (elements
& (1<<PMTITLE
)) {
807 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
808 colorUpdate
|= MTITLE_COL
;
810 if (elements
& (1<<PMITEM
)) {
812 TextureListItem
*titem
;
814 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
815 titem
= (TextureListItem
*)item
->clientData
;
817 pix
= renderMenu(panel
, titem
->prop
,
818 previewPositions
[PMITEM
].size
.width
,
819 previewPositions
[PMITEM
].size
.height
/4);
821 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
822 previewPositions
[PMITEM
].size
.width
,
823 previewPositions
[PMITEM
].size
.height
,
824 previewPositions
[PMITEM
].pos
.x
,
825 previewPositions
[PMITEM
].pos
.y
);
827 XFreePixmap(dpy
, pix
);
829 colorUpdate
|= MITEM_COL
|MDISAB_COL
|MHIGH_COL
|MHIGHT_COL
;
831 if (elements
& (1<<PMITEM
|1<<PMTITLE
)) {
832 XDrawLine(dpy
, panel
->preview
, gc
, 29, 120, 29, 120+20*4+20);
833 XDrawLine(dpy
, panel
->preview
, gc
, 29, 119, 119, 119);
835 if (elements
& (1<<PICON
)) {
837 TextureListItem
*titem
;
839 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
840 titem
= (TextureListItem
*)item
->clientData
;
842 renderPreview(panel
, gc
, PICON
,
843 titem
->ispixmap
? 0 : RBEV_RAISED3
);
845 colorUpdate
|= ICONT_COL
|ICONB_COL
|CLIP_COL
|CCLIP_COL
;
850 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
851 240-4, 215-4, WMScreenDepth(scr
));
853 WMSetLabelImage(panel
->prevL
, p
);
857 updateColorPreviewBox(panel
, colorUpdate
);
860 updateColorPreviewBox(panel
, colorUpdate
);
862 WMRedisplayWidget(panel
->prevL
);
872 cancelNewTexture(void *data
)
874 _Panel
*panel
= (_Panel
*)data
;
876 HideTexturePanel(panel
->texturePanel
);
883 makeFileName(char *prefix
)
887 fname
= wstrdup(prefix
);
889 while (access(fname
, F_OK
)==0) {
893 sprintf(buf
, "%08lx.cache", time(NULL
));
894 fname
= wstrappend(prefix
, buf
);
904 okNewTexture(void *data
)
906 _Panel
*panel
= (_Panel
*)data
;
911 TextureListItem
*titem
;
912 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
914 titem
= wmalloc(sizeof(TextureListItem
));
915 memset(titem
, 0, sizeof(TextureListItem
));
917 HideTexturePanel(panel
->texturePanel
);
919 name
= GetTexturePanelTextureName(panel
->texturePanel
);
921 prop
= GetTexturePanelTexture(panel
->texturePanel
);
923 str
= PLGetDescription(prop
);
927 titem
->texture
= str
;
928 titem
->selectedFor
= 0;
930 titem
->ispixmap
= isPixmap(prop
);
932 titem
->path
= makeFileName(panel
->fprefix
);
933 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
936 item
= WMAddListItem(panel
->texLs
, "");
937 item
->clientData
= titem
;
939 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
944 okEditTexture(void *data
)
946 _Panel
*panel
= (_Panel
*)data
;
951 TextureListItem
*titem
;
953 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
954 titem
= (TextureListItem
*)item
->clientData
;
956 HideTexturePanel(panel
->texturePanel
);
958 if (titem
->current
) {
959 name
= GetTexturePanelTextureName(panel
->texturePanel
);
965 prop
= GetTexturePanelTexture(panel
->texturePanel
);
967 str
= PLGetDescription(prop
);
969 PLRelease(titem
->prop
);
972 titem
->ispixmap
= isPixmap(prop
);
974 free(titem
->texture
);
975 titem
->texture
= str
;
977 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
978 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
979 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
982 WMRedisplayWidget(panel
->texLs
);
984 if (titem
->selectedFor
)
985 updatePreviewBox(panel
, titem
->selectedFor
);
987 changePage(panel
->secP
, panel
);
993 editTexture(WMWidget
*w
, void *data
)
995 _Panel
*panel
= (_Panel
*)data
;
997 TextureListItem
*titem
;
999 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
1000 titem
= (TextureListItem
*)item
->clientData
;
1002 SetTexturePanelPixmapPath(panel
->texturePanel
,
1003 GetObjectForKey("PixmapPath"));
1005 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
1007 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
1008 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
1010 ShowTexturePanel(panel
->texturePanel
);
1016 newTexture(WMWidget
*w
, void *data
)
1018 _Panel
*panel
= (_Panel
*)data
;
1020 SetTexturePanelPixmapPath(panel
->texturePanel
,
1021 GetObjectForKey("PixmapPath"));
1023 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
1025 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
1027 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
1029 ShowTexturePanel(panel
->texturePanel
);
1035 deleteTexture(WMWidget
*w
, void *data
)
1037 _Panel
*panel
= (_Panel
*)data
;
1039 TextureListItem
*titem
;
1043 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1044 row
= WMGetListSelectedItemRow(panel
->texLs
);
1045 item
= WMGetListItem(panel
->texLs
, row
);
1046 titem
= (TextureListItem
*)item
->clientData
;
1048 if (titem
->selectedFor
& (1 << section
)) {
1049 TextureListItem
*titem2
;
1051 panel
->textureIndex
[section
] = section
;
1052 item
= WMGetListItem(panel
->texLs
, section
);
1053 titem2
= (TextureListItem
*)item
->clientData
;
1054 titem2
->selectedFor
|= 1 << section
;
1058 free(titem
->texture
);
1059 PLRelease(titem
->prop
);
1061 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1062 wsyserror("could not remove file %s", titem
->path
);
1069 WMRemoveListItem(panel
->texLs
, row
);
1070 WMSetButtonEnabled(panel
->delB
, False
);
1077 extractTexture(WMWidget
*w
, void *data
)
1079 _Panel
*panel
= (_Panel
*)data
;
1081 WMOpenPanel
*opanel
;
1082 WMScreen
*scr
= WMWidgetScreen(w
);
1084 opanel
= WMGetOpenPanel(scr
);
1085 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1086 WMSetFilePanelCanChooseFiles(opanel
, True
);
1088 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
1089 _("Select File"), NULL
)) {
1090 path
= WMGetFilePanelFileName(opanel
);
1092 OpenExtractPanelFor(panel
, path
);
1100 changePage(WMWidget
*w
, void *data
)
1102 _Panel
*panel
= (_Panel
*)data
;
1105 TextureListItem
*titem
;
1106 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1107 RContext
*rc
= WMScreenRContext(scr
);
1108 static WMPoint positions
[] = {
1119 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1121 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1123 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1125 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1127 titem
= (TextureListItem
*)item
->clientData
;
1132 color
= WMGrayColor(scr
);
1133 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1134 positions
[panel
->oldsection
].x
,
1135 positions
[panel
->oldsection
].y
, 22, 22);
1136 WMReleaseColor(color
);
1139 panel
->oldsection
= section
;
1140 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1141 positions
[section
].y
);
1143 WMRedisplayWidget(panel
->prevL
);
1149 previewClick(XEvent
*event
, void *clientData
)
1151 _Panel
*panel
= (_Panel
*)clientData
;
1154 switch (panel
->oldTabItem
) {
1156 for (i
= 0; i
< sizeof(previewPositions
)/sizeof(WMRect
); i
++) {
1157 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
1158 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
1159 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
1160 + previewPositions
[i
].size
.width
1161 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
1162 + previewPositions
[i
].size
.height
) {
1164 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1165 changePage(panel
->secP
, panel
);
1171 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1172 if (event
->xbutton
.x
>= previewColorPositions
[i
].pos
.x
1173 && event
->xbutton
.y
>= previewColorPositions
[i
].pos
.y
1174 && event
->xbutton
.x
< previewColorPositions
[i
].pos
.x
1175 + previewColorPositions
[i
].size
.width
1176 && event
->xbutton
.y
< previewColorPositions
[i
].pos
.y
1177 + previewColorPositions
[i
].size
.height
) {
1183 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1184 changeColorPage(panel
->colP
, panel
);
1194 textureClick(WMWidget
*w
, void *data
)
1196 _Panel
*panel
= (_Panel
*)data
;
1199 TextureListItem
*titem
;
1201 i
= WMGetListSelectedItemRow(panel
->texLs
);
1203 item
= WMGetListItem(panel
->texLs
, i
);
1205 titem
= (TextureListItem
*)item
->clientData
;
1207 if (titem
->current
) {
1208 WMSetButtonEnabled(panel
->delB
, False
);
1210 WMSetButtonEnabled(panel
->delB
, True
);
1217 textureDoubleClick(WMWidget
*w
, void *data
)
1219 _Panel
*panel
= (_Panel
*)data
;
1222 TextureListItem
*titem
;
1224 /* unselect old texture */
1225 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1227 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1228 titem
= (TextureListItem
*)item
->clientData
;
1229 titem
->selectedFor
&= ~(1 << section
);
1231 /* select new texture */
1232 i
= WMGetListSelectedItemRow(panel
->texLs
);
1234 item
= WMGetListItem(panel
->texLs
, i
);
1236 titem
= (TextureListItem
*)item
->clientData
;
1238 titem
->selectedFor
|= 1<<section
;
1240 panel
->textureIndex
[section
] = i
;
1242 WMRedisplayWidget(panel
->texLs
);
1244 updatePreviewBox(panel
, 1<<section
);
1250 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
1253 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
1254 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1255 int width
, height
, x
, y
;
1256 Display
*dpy
= WMScreenDisplay(scr
);
1257 WMColor
*white
= WMWhiteColor(scr
);
1259 WMColor
*black
= WMBlackColor(scr
);
1260 TextureListItem
*titem
;
1262 width
= rect
->size
.width
;
1263 height
= rect
->size
.height
;
1267 if (state
& WLDSSelected
)
1268 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1270 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
1272 item
= WMGetListItem(lPtr
, index
);
1273 titem
= (TextureListItem
*)item
->clientData
;
1276 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0, TEXPREV_WIDTH
,
1277 TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1279 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1280 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1281 else if (titem
->selectedFor
)
1282 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1284 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
1285 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
1286 strlen(titem
->title
));
1288 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
1289 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
1290 strlen(titem
->texture
));
1293 WMReleaseColor(white
);
1294 WMReleaseColor(black
);
1300 loadRImage(WMScreen
*scr
, char *path
)
1308 f
= fopen(path
, "r");
1312 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1314 image
= RCreateImage(w
, h
, d
== 4);
1315 for (i
= 0; i
< d
; i
++) {
1316 fread(image
->data
[i
], 1, w
*h
, f
);
1320 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1321 RDestroyImage(image
);
1329 fillTextureList(WMList
*lPtr
)
1331 proplist_t textureList
;
1333 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1334 TextureListItem
*titem
;
1335 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1338 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1342 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1345 texture
= PLGetArrayElement(textureList
, i
);
1347 titem
= wmalloc(sizeof(TextureListItem
));
1348 memset(titem
, 0, sizeof(TextureListItem
));
1350 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1351 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1352 titem
->texture
= PLGetDescription(titem
->prop
);
1353 titem
->selectedFor
= 0;
1354 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1356 titem
->preview
= loadRImage(scr
, titem
->path
);
1357 if (!titem
->preview
) {
1358 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1359 TEXPREV_HEIGHT
, NULL
, 0);
1361 item
= WMAddListItem(lPtr
, "");
1362 item
->clientData
= titem
;
1368 fillColorList(_Panel
*panel
)
1372 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1373 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1376 list
= WMGetUDObjectForKey(udb
, "ColorList");
1378 for (i
= 0; i
< 24; i
++) {
1379 color
= WMCreateNamedColor(scr
, sampleColors
[i
], False
);
1382 WMSetColorWellColor(panel
->sampW
[i
], color
);
1383 WMReleaseColor(color
);
1388 for (i
= 0; i
< WMIN(24, PLGetNumberOfElements(list
)); i
++) {
1389 c
= PLGetArrayElement(list
, i
);
1390 if (!c
|| !PLIsString(c
))
1392 color
= WMCreateNamedColor(scr
, PLGetString(c
), False
);
1395 WMSetColorWellColor(panel
->sampW
[i
], color
);
1396 WMReleaseColor(color
);
1402 /*************************************************************************/
1406 changeColorPage(WMWidget
*w
, void *data
)
1408 _Panel
*panel
= (_Panel
*)data
;
1410 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1411 RContext
*rc
= WMScreenRContext(scr
);
1412 static WMPoint positions
[] = {
1427 if (panel
->preview
) {
1430 color
= WMGrayColor(scr
);
1431 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1432 positions
[panel
->oldcsection
].x
,
1433 positions
[panel
->oldcsection
].y
, 22, 22);
1434 WMReleaseColor(color
);
1437 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1439 panel
->oldcsection
= section
;
1441 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1442 positions
[section
].y
);
1444 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1446 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1448 WMRedisplayWidget(panel
->prevL
);
1453 paintText(WMScreen
*scr
, Drawable d
, WMColor
*color
, WMFont
*font
,
1454 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1456 int l
= strlen(text
);
1463 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1467 x
+= (w
- WMWidthOfString(font
, text
, l
))/2;
1470 WMDrawString(scr
, d
, WMColorGC(color
), font
, x
,
1471 y
+ (h
- WMFontHeight(font
))/2, text
, l
);
1477 updateColorPreviewBox(_Panel
*panel
, int elements
)
1479 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1483 pixmap
= WMGetLabelImage(panel
->prevL
);
1484 d
= WMGetPixmapXID(pixmap
);
1486 if (elements
& FTITLE_COL
) {
1487 paintText(scr
, d
, panel
->colors
[0], panel
->boldFont
, 30, 10, 190, 20,
1488 panel
->titleAlignment
, _("Focused Window"));
1490 if (elements
& UTITLE_COL
) {
1491 paintText(scr
, d
, panel
->colors
[1], panel
->boldFont
, 30, 40, 190, 20,
1492 panel
->titleAlignment
, _("Unfocused Window"));
1494 if (elements
& OTITLE_COL
) {
1495 paintText(scr
, d
, panel
->colors
[2], panel
->boldFont
, 30, 70, 190, 20,
1496 panel
->titleAlignment
, _("Owner of Focused Window"));
1498 if (elements
& MTITLE_COL
) {
1499 paintText(scr
, d
, panel
->colors
[3], panel
->boldFont
, 30, 120, 90, 20,
1500 WALeft
, _("Menu Title"));
1502 if (elements
& MITEM_COL
) {
1503 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 140, 90, 20,
1504 WALeft
, _("Normal Item"));
1505 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 200, 90, 20,
1506 WALeft
, _("Normal Item"));
1508 if (elements
& MDISAB_COL
) {
1509 paintText(scr
, d
, panel
->colors
[5], panel
->normalFont
, 30, 160, 90, 20,
1510 WALeft
, _("Disabled Item"));
1512 if (elements
& MHIGH_COL
) {
1513 XFillRectangle(WMScreenDisplay(scr
), d
, WMColorGC(panel
->colors
[6]),
1515 elements
|= MHIGHT_COL
;
1517 if (elements
& MHIGHT_COL
) {
1518 paintText(scr
, d
, panel
->colors
[7], panel
->normalFont
, 30, 180, 90, 20,
1519 WALeft
, _("Highlighted"));
1522 if (elements & ICONT_COL) {
1523 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1526 if (elements & ICONB_COL) {
1527 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1530 if (elements & CLIP_COL) {
1531 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1534 if (elements & CCLIP_COL) {
1535 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1539 WMRedisplayWidget(panel
->prevL
);
1544 colorWellObserver(void *self
, WMNotification
*n
)
1546 _Panel
*panel
= (_Panel
*)self
;
1549 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1551 WMReleaseColor(panel
->colors
[p
]);
1553 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1555 updateColorPreviewBox(panel
, 1<<p
);
1560 changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
*tabView
,
1561 WMTabViewItem
*item
)
1563 _Panel
*panel
= self
->data
;
1566 i
= WMGetTabViewItemIdentifier(item
);
1569 switch (panel
->oldTabItem
) {
1571 changeColorPage(NULL
, panel
);
1574 changePage(panel
->secP
, panel
);
1577 switch (panel
->oldTabItem
) {
1579 changePage(NULL
, panel
);
1582 changeColorPage(panel
->colP
, panel
);
1585 switch (panel
->oldTabItem
) {
1587 changePage(NULL
, panel
);
1590 changeColorPage(NULL
, panel
);
1596 panel
->oldTabItem
= i
;
1600 /*************************************************************************/
1603 menuStyleCallback(WMWidget
*self
, void *data
)
1605 _Panel
*panel
= (_Panel
*)data
;
1607 if (self
== panel
->mstyB
[0]) {
1608 panel
->menuStyle
= MSTYLE_NORMAL
;
1609 updatePreviewBox(panel
, 1<<PMITEM
);
1611 } else if (self
== panel
->mstyB
[1]) {
1612 panel
->menuStyle
= MSTYLE_SINGLE
;
1613 updatePreviewBox(panel
, 1<<PMITEM
);
1615 } else if (self
== panel
->mstyB
[2]) {
1616 panel
->menuStyle
= MSTYLE_FLAT
;
1617 updatePreviewBox(panel
, 1<<PMITEM
);
1623 titleAlignCallback(WMWidget
*self
, void *data
)
1625 _Panel
*panel
= (_Panel
*)data
;
1627 if (self
== panel
->taliB
[0]) {
1628 panel
->titleAlignment
= WALeft
;
1629 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1631 } else if (self
== panel
->taliB
[1]) {
1632 panel
->titleAlignment
= WACenter
;
1633 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1635 } else if (self
== panel
->taliB
[2]) {
1636 panel
->titleAlignment
= WARight
;
1637 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1643 createPanel(Panel
*p
)
1645 _Panel
*panel
= (_Panel
*)p
;
1647 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1648 WMTabViewItem
*item
;
1653 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
1655 if (access(panel
->fprefix
, F_OK
)!=0) {
1656 if (mkdir(panel
->fprefix
, 0755) < 0) {
1657 wsyserror(panel
->fprefix
);
1662 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
1663 free(panel
->fprefix
);
1664 panel
->fprefix
= tmp
;
1665 if (access(panel
->fprefix
, F_OK
)!=0) {
1666 if (mkdir(panel
->fprefix
, 0755) < 0) {
1667 wsyserror(panel
->fprefix
);
1672 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1673 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1674 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1676 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1677 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1678 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1680 panel
->frame
= WMCreateFrame(panel
->win
);
1681 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1682 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1685 panel
->prevL
= WMCreateLabel(panel
->frame
);
1686 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1687 WMMoveWidget(panel
->prevL
, 15, 10);
1688 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1689 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1691 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1692 previewClick
, panel
);
1697 tabviewDelegate
.data
= panel
;
1699 panel
->tabv
= WMCreateTabView(panel
->frame
);
1700 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1701 WMMoveWidget(panel
->tabv
, 265, 10);
1702 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1704 /*** texture list ***/
1706 panel
->texF
= WMCreateFrame(panel
->frame
);
1707 WMSetFrameRelief(panel
->texF
, WRFlat
);
1709 item
= WMCreateTabViewItemWithIdentifier(0);
1710 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1711 WMSetTabViewItemLabel(item
, _("Texture"));
1713 WMAddItemInTabView(panel
->tabv
, item
);
1716 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1717 WMResizeWidget(panel
->secP
, 228, 20);
1718 WMMoveWidget(panel
->secP
, 7, 7);
1719 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1720 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1721 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1722 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1723 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1724 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1725 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1726 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1727 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1729 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1731 panel
->texLs
= WMCreateList(panel
->texF
);
1732 WMResizeWidget(panel
->texLs
, 165, 155);
1733 WMMoveWidget(panel
->texLs
, 70, 33);
1734 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1735 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1736 WMHangData(panel
->texLs
, panel
);
1737 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1738 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1740 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1741 "for the selected item."),
1742 WMWidgetView(panel
->texLs
));
1744 /* command buttons */
1746 font
= WMSystemFontOfSize(scr
, 10);
1749 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1750 WMResizeWidget(panel
->newB
, 57, 39);
1751 WMMoveWidget(panel
->newB
, 7, 33);
1752 WMSetButtonFont(panel
->newB
, font
);
1753 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1754 WMSetButtonText(panel
->newB
, _("New"));
1755 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1756 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1758 WMSetBalloonTextForView(_("Create a new texture."),
1759 WMWidgetView(panel
->newB
));
1761 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1762 WMResizeWidget(panel
->ripB
, 57, 39);
1763 WMMoveWidget(panel
->ripB
, 7, 72);
1764 WMSetButtonFont(panel
->ripB
, font
);
1765 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1766 WMSetButtonText(panel
->ripB
, _("Extract..."));
1767 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1768 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1770 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1771 WMWidgetView(panel
->ripB
));
1773 WMSetButtonEnabled(panel
->ripB
, False
);
1775 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1776 WMResizeWidget(panel
->editB
, 57, 39);
1777 WMMoveWidget(panel
->editB
, 7, 111);
1778 WMSetButtonFont(panel
->editB
, font
);
1779 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1780 WMSetButtonText(panel
->editB
, _("Edit"));
1781 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1782 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1783 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1784 WMWidgetView(panel
->editB
));
1786 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1787 WMResizeWidget(panel
->delB
, 57, 38);
1788 WMMoveWidget(panel
->delB
, 7, 150);
1789 WMSetButtonFont(panel
->delB
, font
);
1790 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1791 WMSetButtonText(panel
->delB
, _("Delete"));
1792 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1793 WMSetButtonEnabled(panel
->delB
, False
);
1794 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1795 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1796 WMWidgetView(panel
->delB
));
1798 WMReleaseFont(font
);
1800 WMMapSubwidgets(panel
->texF
);
1803 panel
->colF
= WMCreateFrame(panel
->frame
);
1804 WMSetFrameRelief(panel
->colF
, WRFlat
);
1806 item
= WMCreateTabViewItemWithIdentifier(1);
1807 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1808 WMSetTabViewItemLabel(item
, _("Color"));
1810 WMAddItemInTabView(panel
->tabv
, item
);
1812 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1813 WMResizeWidget(panel
->colP
, 228, 20);
1814 WMMoveWidget(panel
->colP
, 7, 7);
1815 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1816 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Title"));
1817 WMAddPopUpButtonItem(panel
->colP
, _("Unfocused Window Title"));
1818 WMAddPopUpButtonItem(panel
->colP
, _("Owner of Focused Window Title"));
1819 WMAddPopUpButtonItem(panel
->colP
, _("Menu Title"));
1820 WMAddPopUpButtonItem(panel
->colP
, _("Menu Item Text"));
1821 WMAddPopUpButtonItem(panel
->colP
, _("Disabled Menu Item Text"));
1822 WMAddPopUpButtonItem(panel
->colP
, _("Menu Highlight Color"));
1823 WMAddPopUpButtonItem(panel
->colP
, _("Highlighted Menu Text Color"));
1825 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1826 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1827 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1828 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1831 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1833 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1836 panel
->colW
= WMCreateColorWell(panel
->colF
);
1837 WMResizeWidget(panel
->colW
, 65, 50);
1838 WMMoveWidget(panel
->colW
, 30, 75);
1839 WMAddNotificationObserver(colorWellObserver
, panel
,
1840 WMColorWellDidChangeNotification
, panel
->colW
);
1842 for (i
= 0; i
< 4; i
++) {
1844 for (j
= 0; j
< 6; j
++) {
1845 panel
->sampW
[i
+j
*4] = WMCreateColorWell(panel
->colF
);
1846 WMResizeWidget(panel
->sampW
[i
+j
*4], 22, 22);
1847 WMMoveWidget(panel
->sampW
[i
+j
*4], 130 + i
*22, 40 + j
*22);
1848 WSetColorWellBordered(panel
->sampW
[i
+j
*4], False
);
1852 WMMapSubwidgets(panel
->colF
);
1855 panel
->optF
= WMCreateFrame(panel
->frame
);
1856 WMSetFrameRelief(panel
->optF
, WRFlat
);
1858 item
= WMCreateTabViewItemWithIdentifier(2);
1859 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1860 WMSetTabViewItemLabel(item
, _("Options"));
1862 WMAddItemInTabView(panel
->tabv
, item
);
1864 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1865 WMResizeWidget(panel
->mstyF
, 215, 85);
1866 WMMoveWidget(panel
->mstyF
, 15, 10);
1867 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1869 for (i
= 0; i
< 3; i
++) {
1873 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1874 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1875 WMMoveWidget(panel
->mstyB
[i
], 15 + i
*65, 20);
1876 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1877 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1880 path
= LocateImage(MSTYLE1_FILE
);
1883 path
= LocateImage(MSTYLE2_FILE
);
1886 path
= LocateImage(MSTYLE3_FILE
);
1890 icon
= WMCreatePixmapFromFile(scr
, path
);
1892 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1893 WMReleasePixmap(icon
);
1895 wwarning(_("could not load icon file %s"), path
);
1900 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1901 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1903 WMMapSubwidgets(panel
->mstyF
);
1906 panel
->taliF
= WMCreateFrame(panel
->optF
);
1907 WMResizeWidget(panel
->taliF
, 110, 80);
1908 WMMoveWidget(panel
->taliF
, 15, 100);
1909 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
1911 for (i
= 0; i
< 3; i
++) {
1912 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
1913 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
1916 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1919 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1922 WMSetButtonText(panel
->taliB
[i
], _("Right"));
1925 WMResizeWidget(panel
->taliB
[i
], 90, 18);
1926 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20*i
);
1928 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
1929 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
1931 WMMapSubwidgets(panel
->taliF
);
1933 WMMapSubwidgets(panel
->optF
);
1937 WMRealizeWidget(panel
->frame
);
1938 WMMapSubwidgets(panel
->frame
);
1940 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1944 changePage(panel
->secP
, panel
);
1946 fillTextureList(panel
->texLs
);
1948 fillColorList(panel
);
1950 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1956 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1960 TextureListItem
*titem
;
1962 titem
= wmalloc(sizeof(TextureListItem
));
1963 memset(titem
, 0, sizeof(TextureListItem
));
1965 titem
->title
= wstrdup(title
);
1966 titem
->prop
= GetObjectForKey(key
);
1968 titem
->prop
= PLGetProplistWithDescription(defValue
);
1970 PLRetain(titem
->prop
);
1972 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1974 titem
->selectedFor
= 1<<index
;
1976 titem
->ispixmap
= isPixmap(titem
->prop
);
1978 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1979 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1981 item
= WMAddListItem(list
, "");
1982 item
->clientData
= titem
;
1988 showData(_Panel
*panel
)
1993 str
= GetStringForKey("MenuStyle");
1994 if (str
&& strcasecmp(str
, "flat")==0) {
1995 panel
->menuStyle
= MSTYLE_FLAT
;
1996 } else if (str
&& strcasecmp(str
, "singletexture")==0) {
1997 panel
->menuStyle
= MSTYLE_SINGLE
;
1999 panel
->menuStyle
= MSTYLE_NORMAL
;
2002 str
= GetStringForKey("TitleJustify");
2003 if (str
&& strcasecmp(str
, "left")==0) {
2004 panel
->titleAlignment
= WALeft
;
2005 } else if (str
&& strcasecmp(str
, "right")==0) {
2006 panel
->titleAlignment
= WARight
;
2008 panel
->titleAlignment
= WACenter
;
2011 for (i
= 0; i
< sizeof(colorOptions
)/(2*sizeof(char*)); i
++) {
2014 str
= GetStringForKey(colorOptions
[i
*2]);
2016 str
= colorOptions
[i
*2+1];
2018 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->frame
), str
, False
))) {
2019 color
= WMCreateNamedColor(WMWidgetScreen(panel
->frame
), "#000000", False
);
2022 panel
->colors
[i
] = color
;
2024 changeColorPage(panel
->colP
, panel
);
2026 for (i
= 0; i
< sizeof(textureOptions
)/(3*sizeof(char*)); i
++) {
2027 setupTextureFor(panel
->texLs
, textureOptions
[i
*3],
2028 textureOptions
[i
*3+1], textureOptions
[i
*3+2], i
);
2029 panel
->textureIndex
[i
] = i
;
2031 updatePreviewBox(panel
, EVERYTHING
);
2034 for (i
= 0; i
< 3; i
++) {
2035 WMSetButtonSelected(panel
->mstyB
[i
], i
==panel
->menuStyle
);
2036 WMSetButtonSelected(panel
->taliB
[i
], i
==panel
->titleAlignment
);
2043 storeData(_Panel
*panel
)
2045 TextureListItem
*titem
;
2049 for (i
= 0; i
< sizeof(textureOptions
)/(sizeof(char*)*3); i
++) {
2050 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
2051 titem
= (TextureListItem
*)item
->clientData
;
2052 SetObjectForKey(titem
->prop
, textureOptions
[i
*3]);
2055 for (i
= 0; i
< 8; i
++) {
2058 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
2061 SetStringForKey(str
, colorOptions
[i
*2]);
2066 switch (panel
->menuStyle
) {
2068 SetStringForKey("singletexture", "MenuStyle");
2071 SetStringForKey("flat", "MenuStyle");
2075 SetStringForKey("normal", "MenuStyle");
2078 switch (panel
->titleAlignment
) {
2080 SetStringForKey("left", "TitleJustify");
2083 SetStringForKey("right", "TitleJustify");
2087 SetStringForKey("center", "TitleJustify");
2094 prepareForClose(_Panel
*panel
)
2096 proplist_t textureList
;
2098 TextureListItem
*titem
;
2100 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2103 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
2105 /* store list of textures */
2106 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2107 item
= WMGetListItem(panel
->texLs
, i
);
2108 titem
= (TextureListItem
*)item
->clientData
;
2110 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
2111 PLRetain(titem
->prop
),
2112 PLMakeString(titem
->path
),
2115 PLAppendArrayElement(textureList
, texture
);
2118 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2119 PLRelease(textureList
);
2121 /* store list of colors */
2122 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
2123 for (i
= 0; i
< 24; i
++) {
2127 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2129 str
= WMGetColorRGBDescription(color
);
2130 PLAppendArrayElement(textureList
, PLMakeString(str
));
2133 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2134 PLRelease(textureList
);
2136 WMSynchronizeUserDefaults(udb
);
2142 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
2146 panel
= wmalloc(sizeof(_Panel
));
2147 memset(panel
, 0, sizeof(_Panel
));
2149 panel
->sectionName
= _("Appearance Preferences");
2151 panel
->description
= _("Background texture configuration for windows,\n"
2152 "menus and icons.");
2156 panel
->callbacks
.createWidgets
= createPanel
;
2157 panel
->callbacks
.updateDomain
= storeData
;
2158 panel
->callbacks
.prepareForClose
= prepareForClose
;
2160 AddSection(panel
, ICON_FILE
);
2167 /****************************************************************************/
2171 typedef struct ExtractPanel
{
2184 OpenExtractPanelFor(_Panel
*panel
, char *path
)
2186 ExtractPanel
*epanel
;
2189 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
2191 epanel
= wmalloc(sizeof(ExtractPanel
));
2192 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
2194 |WMClosableWindowMask
);
2195 WMResizeWidget(epanel
->win
, 245, 250);
2196 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2198 epanel
->label
= WMCreateLabel(epanel
->win
);
2199 WMResizeWidget(epanel
->label
, 225, 18);
2200 WMMoveWidget(epanel
->label
, 10, 10);
2201 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2202 WMSetLabelRelief(epanel
->label
, WRSunken
);
2204 color
= WMDarkGrayColor(scr
);
2205 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2206 WMReleaseColor(color
);
2208 color
= WMWhiteColor(scr
);
2209 WMSetLabelTextColor(epanel
->label
, color
);
2210 WMReleaseColor(color
);
2212 font
= WMBoldSystemFontOfSize(scr
, 12);
2213 WMSetLabelFont(epanel
->label
, font
);
2214 WMReleaseFont(font
);
2216 WMSetLabelText(epanel
->label
, _("Textures"));
2218 epanel
->list
= WMCreateList(epanel
->win
);
2219 WMResizeWidget(epanel
->list
, 225, 165);
2220 WMMoveWidget(epanel
->list
, 10, 30);
2224 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2225 WMResizeWidget(epanel
->closeB
, 74, 24);
2226 WMMoveWidget(epanel
->closeB
, 165, 215);
2227 WMSetButtonText(epanel
->closeB
, _("Close"));
2229 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2230 WMResizeWidget(epanel
->extrB
, 74, 24);
2231 WMMoveWidget(epanel
->extrB
, 80, 215);
2232 WMSetButtonText(epanel
->extrB
, _("Extract"));
2234 WMMapSubwidgets(epanel
->win
);
2237 /* take textures from file */
2241 WMRealizeWidget(epanel
->win
);
2243 WMMapWidget(epanel
->win
);