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 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
));
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 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
));
652 str
= PLGetString(PLGetArrayElement(texture
, 2));
653 str2rcolor(rc
, str
, &color
);
655 switch (toupper(type
[0])) {
657 image
= RMakeTiledImage(timage
, width
, height
);
658 RDestroyImage(timage
);
662 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
663 RDestroyImage(timage
);
668 image
= RScaleImage(timage
, width
, height
);
669 RDestroyImage(timage
);
682 dumpRImage(path
, image
);
686 if (border
== RESIZEBAR_BEVEL
) {
687 drawResizebarBevel(image
);
688 } else if (border
== MENU_BEVEL
) {
689 drawMenuBevel(image
);
690 RBevelImage(image
, RBEV_RAISED2
);
693 RBevelImage(image
, border
);
696 RConvertImage(rc
, image
, &pixmap
);
697 RDestroyImage(image
);
704 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
706 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
707 Display
*dpy
= WMScreenDisplay(scr
);
709 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
712 switch (panel
->menuStyle
) {
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
);
723 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, MENU_BEVEL
);
726 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, RBEV_RAISED2
);
736 renderPreview(_Panel
*panel
, GC gc
, int part
, int relief
)
739 TextureListItem
*titem
;
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
,
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
);
762 updatePreviewBox(_Panel
*panel
, int elements
)
764 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
765 Display
*dpy
= WMScreenDisplay(scr
);
766 /* RContext *rc = WMScreenRContext(scr);*/
772 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
775 if (panel
->preview
== None
) {
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
),
784 WMReleaseColor(color
);
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
)) {
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
)) {
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
;
849 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
850 240-4, 215-4, WMScreenDepth(scr
));
852 WMSetLabelImage(panel
->prevL
, p
);
856 updateColorPreviewBox(panel
, colorUpdate
);
859 updateColorPreviewBox(panel
, colorUpdate
);
861 WMRedisplayWidget(panel
->prevL
);
871 cancelNewTexture(void *data
)
873 _Panel
*panel
= (_Panel
*)data
;
875 HideTexturePanel(panel
->texturePanel
);
882 makeFileName(char *prefix
)
886 fname
= wstrdup(prefix
);
888 while (access(fname
, F_OK
)==0) {
892 sprintf(buf
, "%08lx.cache", time(NULL
));
893 fname
= wstrappend(prefix
, buf
);
903 okNewTexture(void *data
)
905 _Panel
*panel
= (_Panel
*)data
;
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
);
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
,
935 item
= WMAddListItem(panel
->texLs
, "");
936 item
->clientData
= titem
;
938 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
943 okEditTexture(void *data
)
945 _Panel
*panel
= (_Panel
*)data
;
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
);
964 prop
= GetTexturePanelTexture(panel
->texturePanel
);
966 str
= PLGetDescription(prop
);
968 PLRelease(titem
->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
,
981 WMRedisplayWidget(panel
->texLs
);
983 if (titem
->selectedFor
)
984 updatePreviewBox(panel
, titem
->selectedFor
);
986 changePage(panel
->secP
, panel
);
992 editTexture(WMWidget
*w
, void *data
)
994 _Panel
*panel
= (_Panel
*)data
;
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
);
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
);
1034 deleteTexture(WMWidget
*w
, void *data
)
1036 _Panel
*panel
= (_Panel
*)data
;
1038 TextureListItem
*titem
;
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
;
1057 free(titem
->texture
);
1058 PLRelease(titem
->prop
);
1060 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1061 wsyserror("could not remove file %s", titem
->path
);
1068 WMRemoveListItem(panel
->texLs
, row
);
1069 WMSetButtonEnabled(panel
->delB
, False
);
1076 extractTexture(WMWidget
*w
, void *data
)
1078 _Panel
*panel
= (_Panel
*)data
;
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
);
1099 changePage(WMWidget
*w
, void *data
)
1101 _Panel
*panel
= (_Panel
*)data
;
1104 TextureListItem
*titem
;
1105 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1106 RContext
*rc
= WMScreenRContext(scr
);
1107 static WMPoint positions
[] = {
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
;
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
);
1138 panel
->oldsection
= section
;
1139 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1140 positions
[section
].y
);
1142 WMRedisplayWidget(panel
->prevL
);
1148 previewClick(XEvent
*event
, void *clientData
)
1150 _Panel
*panel
= (_Panel
*)clientData
;
1153 switch (panel
->oldTabItem
) {
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
);
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
) {
1182 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1183 changeColorPage(panel
->colP
, panel
);
1193 textureClick(WMWidget
*w
, void *data
)
1195 _Panel
*panel
= (_Panel
*)data
;
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
);
1209 WMSetButtonEnabled(panel
->delB
, True
);
1216 textureDoubleClick(WMWidget
*w
, void *data
)
1218 _Panel
*panel
= (_Panel
*)data
;
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
);
1249 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
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
);
1258 WMColor
*black
= WMBlackColor(scr
);
1259 TextureListItem
*titem
;
1261 item
= WMGetListItem(lPtr
, index
);
1262 titem
= (TextureListItem
*)item
->clientData
;
1264 WMReleaseColor(white
);
1265 WMReleaseColor(black
);
1269 width
= rect
->size
.width
;
1270 height
= rect
->size
.height
;
1274 if (state
& WLDSSelected
)
1275 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1277 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
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
);
1305 loadRImage(WMScreen
*scr
, char *path
)
1313 f
= fopen(path
, "r");
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
);
1325 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1326 RDestroyImage(image
);
1334 fillTextureList(WMList
*lPtr
)
1336 proplist_t textureList
;
1338 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1339 TextureListItem
*titem
;
1340 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1343 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1347 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
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
;
1373 fillColorList(_Panel
*panel
)
1377 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1378 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1381 list
= WMGetUDObjectForKey(udb
, "ColorList");
1383 for (i
= 0; i
< 24; i
++) {
1384 color
= WMCreateNamedColor(scr
, sampleColors
[i
], False
);
1387 WMSetColorWellColor(panel
->sampW
[i
], color
);
1388 WMReleaseColor(color
);
1393 for (i
= 0; i
< WMIN(24, PLGetNumberOfElements(list
)); i
++) {
1394 c
= PLGetArrayElement(list
, i
);
1395 if (!c
|| !PLIsString(c
))
1397 color
= WMCreateNamedColor(scr
, PLGetString(c
), False
);
1400 WMSetColorWellColor(panel
->sampW
[i
], color
);
1401 WMReleaseColor(color
);
1407 /*************************************************************************/
1411 changeColorPage(WMWidget
*w
, void *data
)
1413 _Panel
*panel
= (_Panel
*)data
;
1415 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1416 RContext
*rc
= WMScreenRContext(scr
);
1417 static WMPoint positions
[] = {
1432 if (panel
->preview
) {
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
);
1442 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1444 panel
->oldcsection
= section
;
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
);
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
);
1468 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1472 x
+= (w
- WMWidthOfString(font
, text
, l
))/2;
1475 WMDrawString(scr
, d
, WMColorGC(color
), font
, x
,
1476 y
+ (h
- WMFontHeight(font
))/2, text
, l
);
1482 updateColorPreviewBox(_Panel
*panel
, int elements
)
1484 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
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]),
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,
1531 if (elements & ICONB_COL) {
1532 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1535 if (elements & CLIP_COL) {
1536 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1539 if (elements & CCLIP_COL) {
1540 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1544 WMRedisplayWidget(panel
->prevL
);
1549 colorWellObserver(void *self
, WMNotification
*n
)
1551 _Panel
*panel
= (_Panel
*)self
;
1554 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1556 WMReleaseColor(panel
->colors
[p
]);
1558 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1560 updateColorPreviewBox(panel
, 1<<p
);
1565 changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
*tabView
,
1566 WMTabViewItem
*item
)
1568 _Panel
*panel
= self
->data
;
1571 i
= WMGetTabViewItemIdentifier(item
);
1574 switch (panel
->oldTabItem
) {
1576 changeColorPage(NULL
, panel
);
1579 changePage(panel
->secP
, panel
);
1582 switch (panel
->oldTabItem
) {
1584 changePage(NULL
, panel
);
1587 changeColorPage(panel
->colP
, panel
);
1590 switch (panel
->oldTabItem
) {
1592 changePage(NULL
, panel
);
1595 changeColorPage(NULL
, panel
);
1601 panel
->oldTabItem
= i
;
1605 /*************************************************************************/
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
);
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
);
1648 createPanel(Panel
*p
)
1650 _Panel
*panel
= (_Panel
*)p
;
1652 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1653 WMTabViewItem
*item
;
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
);
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
);
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
);
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
);
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
++) {
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
);
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
++) {
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
);
1884 path
= LocateImage(MSTYLE1_FILE
);
1887 path
= LocateImage(MSTYLE2_FILE
);
1890 path
= LocateImage(MSTYLE3_FILE
);
1894 icon
= WMCreatePixmapFromFile(scr
, path
);
1896 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1897 WMReleasePixmap(icon
);
1899 wwarning(_("could not load icon file %s"), 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
);
1920 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1923 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1926 WMSetButtonText(panel
->taliB
[i
], _("Right"));
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
);
1941 WMRealizeWidget(panel
->frame
);
1942 WMMapSubwidgets(panel
->frame
);
1944 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1948 changePage(panel
->secP
, panel
);
1950 fillTextureList(panel
->texLs
);
1952 fillColorList(panel
);
1954 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1960 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
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
);
1975 PLRetain(titem
->prop
);
1977 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
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
;
1993 showData(_Panel
*panel
)
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
;
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
;
2013 panel
->titleAlignment
= WACenter
;
2016 for (i
= 0; i
< sizeof(colorOptions
)/(2*sizeof(char*)); i
++) {
2019 str
= GetStringForKey(colorOptions
[i
*2]);
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
);
2048 storeData(_Panel
*panel
)
2050 TextureListItem
*titem
;
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
++) {
2063 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
2066 SetStringForKey(str
, colorOptions
[i
*2]);
2071 switch (panel
->menuStyle
) {
2073 SetStringForKey("singletexture", "MenuStyle");
2076 SetStringForKey("flat", "MenuStyle");
2080 SetStringForKey("normal", "MenuStyle");
2083 switch (panel
->titleAlignment
) {
2085 SetStringForKey("left", "TitleJustify");
2088 SetStringForKey("right", "TitleJustify");
2092 SetStringForKey("center", "TitleJustify");
2099 prepareForClose(_Panel
*panel
)
2101 proplist_t textureList
;
2103 TextureListItem
*titem
;
2105 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
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
),
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
++) {
2132 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2134 str
= WMGetColorRGBDescription(color
);
2135 PLAppendArrayElement(textureList
, PLMakeString(str
));
2138 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2139 PLRelease(textureList
);
2141 WMSynchronizeUserDefaults(udb
);
2147 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
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.");
2161 panel
->callbacks
.createWidgets
= createPanel
;
2162 panel
->callbacks
.updateDomain
= storeData
;
2163 panel
->callbacks
.prepareForClose
= prepareForClose
;
2165 AddSection(panel
, ICON_FILE
);
2172 /****************************************************************************/
2176 typedef struct ExtractPanel
{
2189 OpenExtractPanelFor(_Panel
*panel
, char *path
)
2191 ExtractPanel
*epanel
;
2194 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
2196 epanel
= wmalloc(sizeof(ExtractPanel
));
2197 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
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
);