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 *textureOptions
[] = {
273 "FTitleBack", "(solid, black)", "[Focused]",
274 "UTitleBack", "(solid, gray)", "[Unfocused]",
275 "PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
276 "ResizebarBack", "(solid, gray)", "[Resizebar]",
277 "MenuTitleBack", "(solid, black)", "[Menu Title]",
278 "MenuTextBack", "(solid, gray)", "[Menu Item]",
279 "IconBack", "(solid, gray)", "[Icon]"
283 #define RESIZEBAR_BEVEL -1
284 #define MENU_BEVEL -2
286 #define TEXPREV_WIDTH 40
287 #define TEXPREV_HEIGHT 24
290 #define MSTYLE_NORMAL 0
291 #define MSTYLE_SINGLE 1
292 #define MSTYLE_FLAT 2
295 #define FTITLE_COL (1<<0)
296 #define UTITLE_COL (1<<1)
297 #define OTITLE_COL (1<<2)
298 #define MTITLE_COL (1<<3)
299 #define MITEM_COL (1<<4)
300 #define MDISAB_COL (1<<5)
301 #define MHIGH_COL (1<<6)
302 #define MHIGHT_COL (1<<7)
303 #define ICONT_COL (1<<8)
304 #define ICONB_COL (1<<9)
305 #define CLIP_COL (1<<10)
306 #define CCLIP_COL (1<<11)
309 static char *colorOptions
[] = {
310 "FTitleColor", "white",
311 "UTitleColor", "black",
312 "PTitleColor", "white",
313 "MenuTitleColor", "white",
314 "MenuTextColor", "black",
315 "MenuDisabledColor", "#616161",
316 "HighlightColor", "white",
317 "HighlightTextColor", "black",
318 "IconTitleColor", "white",
319 "IconTitleBack", "black",
320 "ClipTitleColor", "black",
321 "CClipTitleColor", "#454045"
327 static WMRect previewPositions
[] = {
339 {{30,140},{90,18*4}},
343 #define EVERYTHING 0xff
346 static WMRect previewColorPositions
[] = {
364 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
368 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
371 color
->red
= xcolor
.red
>> 8;
372 color
->green
= xcolor
.green
>> 8;
373 color
->blue
= xcolor
.blue
>> 8;
378 dumpRImage(char *path
, RImage
*image
)
382 f
= fopen(path
, "w");
387 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
,
388 image
->data
[3]!=NULL
? 4 : 3);
390 fwrite(image
->data
[0], 1, image
->width
* image
->height
, f
);
391 fwrite(image
->data
[1], 1, image
->width
* image
->height
, f
);
392 fwrite(image
->data
[2], 1, image
->width
* image
->height
, f
);
394 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
404 isPixmap(proplist_t prop
)
409 p
= PLGetArrayElement(prop
, 0);
411 if (strcasecmp(&s
[1], "pixmap")==0)
418 /**********************************************************************/
421 drawResizebarBevel(RImage
*img
)
426 int width
= img
->width
;
427 int height
= img
->height
;
431 black
.red
= black
.green
= black
.blue
= 0;
434 light
.red
= light
.green
= light
.blue
= 80;
437 dark
.red
= dark
.green
= dark
.blue
= 40;
439 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
440 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
442 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
443 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
445 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
447 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
450 RDrawLine(img
, 0, height
-1, width
-1, height
-1, &black
);
451 RDrawLine(img
, 0, 0, 0, height
-1, &black
);
452 RDrawLine(img
, width
-1, 0, width
-1, height
-1, &black
);
457 drawMenuBevel(RImage
*img
)
459 RColor light
, dark
, mid
;
461 int iheight
= img
->height
/ 4;
464 light
.red
= light
.green
= light
.blue
= 80;
467 dark
.red
= dark
.green
= dark
.blue
= 0;
470 mid
.red
= mid
.green
= mid
.blue
= 40;
472 for (i
= 1; i
< 4; i
++) {
473 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
474 img
->width
-1, i
*iheight
-2, &mid
);
476 RDrawLine(img
, 0, i
*iheight
-1,
477 img
->width
-1, i
*iheight
-1, &dark
);
479 ROperateLine(img
, RAddOperation
, 1, i
*iheight
,
480 img
->width
-2, i
*iheight
, &light
);
486 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
487 char *path
, int border
)
490 RImage
*image
= NULL
;
492 RContext
*rc
= WMScreenRContext(scr
);
497 type
= PLGetString(PLGetArrayElement(texture
, 0));
499 if (strcasecmp(type
, "solid")==0) {
501 str
= PLGetString(PLGetArrayElement(texture
, 1));
503 str2rcolor(rc
, str
, &rcolor
);
505 image
= RCreateImage(width
, height
, False
);
506 RClearImage(image
, &rcolor
);
507 } else if (strcasecmp(&type
[1], "gradient")==0) {
511 switch (toupper(type
[0])) {
513 style
= RVerticalGradient
;
516 style
= RHorizontalGradient
;
520 style
= RDiagonalGradient
;
524 str
= PLGetString(PLGetArrayElement(texture
, 1));
525 str2rcolor(rc
, str
, &rcolor
);
526 str
= PLGetString(PLGetArrayElement(texture
, 2));
527 str2rcolor(rc
, str
, &rcolor2
);
529 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
530 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
534 RImage
*grad
, *timage
;
537 switch (toupper(type
[1])) {
539 style
= RVerticalGradient
;
542 style
= RHorizontalGradient
;
546 style
= RDiagonalGradient
;
550 str
= PLGetString(PLGetArrayElement(texture
, 3));
551 str2rcolor(rc
, str
, &rcolor
);
552 str
= PLGetString(PLGetArrayElement(texture
, 4));
553 str2rcolor(rc
, str
, &rcolor2
);
555 str
= PLGetString(PLGetArrayElement(texture
, 1));
557 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
558 timage
= RLoadImage(rc
, path
, 0);
561 wwarning("could not load file '%s': %s", path
,
562 RMessageForError(RErrorCode
));
564 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
566 image
= RMakeTiledImage(timage
, width
, height
);
567 RDestroyImage(timage
);
569 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
571 RCombineImagesWithOpaqueness(image
, grad
, i
);
574 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
579 switch (toupper(type
[1])) {
581 style
= RVerticalGradient
;
584 style
= RHorizontalGradient
;
588 style
= RDiagonalGradient
;
592 j
= PLGetNumberOfElements(texture
);
595 colors
= wmalloc(j
* sizeof(RColor
*));
597 for (i
= 2; i
< j
; i
++) {
598 str
= PLGetString(PLGetArrayElement(texture
, i
));
599 colors
[i
-2] = wmalloc(sizeof(RColor
));
600 str2rcolor(rc
, str
, colors
[i
-2]);
604 image
= RRenderMultiGradient(width
, height
, colors
, style
);
606 for (i
= 0; colors
[i
]!=NULL
; i
++)
610 } else if (strcasecmp(&type
[1], "pixmap")==0) {
611 RImage
*timage
= NULL
;
615 str
= PLGetString(PLGetArrayElement(texture
, 1));
617 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
619 timage
= RLoadImage(rc
, path
, 0);
622 wwarning("could not load file '%s': %s", path
? path
: str
,
623 RMessageForError(RErrorCode
));
625 str
= PLGetString(PLGetArrayElement(texture
, 2));
626 str2rcolor(rc
, str
, &color
);
628 switch (toupper(type
[0])) {
630 image
= RMakeTiledImage(timage
, width
, height
);
631 RDestroyImage(timage
);
635 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
636 RDestroyImage(timage
);
641 image
= RScaleImage(timage
, width
, height
);
642 RDestroyImage(timage
);
655 dumpRImage(path
, image
);
659 if (border
== RESIZEBAR_BEVEL
) {
660 drawResizebarBevel(image
);
661 } else if (border
== MENU_BEVEL
) {
662 drawMenuBevel(image
);
663 RBevelImage(image
, RBEV_RAISED2
);
666 RBevelImage(image
, border
);
669 RConvertImage(rc
, image
, &pixmap
);
670 RDestroyImage(image
);
677 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
679 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
680 Display
*dpy
= WMScreenDisplay(scr
);
682 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
685 switch (panel
->menuStyle
) {
687 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
689 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*4, WMScreenDepth(scr
));
690 for (i
= 0; i
< 4; i
++) {
691 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
,
694 XFreePixmap(dpy
, tmp
);
697 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, MENU_BEVEL
);
700 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, RBEV_RAISED2
);
710 renderPreview(_Panel
*panel
, GC gc
, int part
, int relief
)
713 TextureListItem
*titem
;
715 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
717 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
718 titem
= (TextureListItem
*)item
->clientData
;
720 pix
= renderTexture(scr
, titem
->prop
,
721 previewPositions
[part
].size
.width
,
722 previewPositions
[part
].size
.height
,
725 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
726 previewPositions
[part
].size
.width
,
727 previewPositions
[part
].size
.height
,
728 previewPositions
[part
].pos
.x
,
729 previewPositions
[part
].pos
.y
);
731 XFreePixmap(WMScreenDisplay(scr
), pix
);
736 updatePreviewBox(_Panel
*panel
, int elements
)
738 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
739 Display
*dpy
= WMScreenDisplay(scr
);
740 /* RContext *rc = WMScreenRContext(scr);*/
745 TextureListItem
*titem
;
748 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
751 if (panel
->preview
== None
) {
754 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
755 240-4, 215-4, WMScreenDepth(scr
));
757 color
= WMGrayColor(scr
);
758 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
760 WMReleaseColor(color
);
766 if (elements
& (1<<PFOCUSED
)) {
767 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
768 colorUpdate
|= FTITLE_COL
;
770 if (elements
& (1<<PUNFOCUSED
)) {
771 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
772 colorUpdate
|= UTITLE_COL
;
774 if (elements
& (1<<POWNER
)) {
775 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
776 colorUpdate
|= OTITLE_COL
;
778 if (elements
& (1<<PRESIZEBAR
)) {
779 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
781 if (elements
& (1<<PMTITLE
)) {
782 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
783 colorUpdate
|= MTITLE_COL
;
785 if (elements
& (1<<PMITEM
)) {
786 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
787 titem
= (TextureListItem
*)item
->clientData
;
789 pix
= renderMenu(panel
, titem
->prop
,
790 previewPositions
[PMITEM
].size
.width
,
791 previewPositions
[PMITEM
].size
.height
/4);
793 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
794 previewPositions
[PMITEM
].size
.width
,
795 previewPositions
[PMITEM
].size
.height
,
796 previewPositions
[PMITEM
].pos
.x
,
797 previewPositions
[PMITEM
].pos
.y
);
799 XFreePixmap(dpy
, pix
);
801 colorUpdate
|= MITEM_COL
|MDISAB_COL
|MHIGH_COL
|MHIGHT_COL
;
803 if (elements
& (1<<PMITEM
|1<<PMTITLE
)) {
804 XDrawLine(dpy
, panel
->preview
, gc
, 29, 120, 29, 120+18*4+20);
805 XDrawLine(dpy
, panel
->preview
, gc
, 29, 119, 119, 119);
807 if (elements
& (1<<PICON
)) {
808 renderPreview(panel
, gc
, PICON
,
809 titem
->ispixmap
? 0 : RBEV_RAISED3
);
811 colorUpdate
|= ICONT_COL
|ICONB_COL
|CLIP_COL
|CCLIP_COL
;
816 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
817 240-4, 215-4, WMScreenDepth(scr
));
819 WMSetLabelImage(panel
->prevL
, p
);
823 updateColorPreviewBox(panel
, colorUpdate
);
826 updateColorPreviewBox(panel
, colorUpdate
);
828 WMRedisplayWidget(panel
->prevL
);
838 cancelNewTexture(void *data
)
840 _Panel
*panel
= (_Panel
*)data
;
842 HideTexturePanel(panel
->texturePanel
);
849 makeFileName(char *prefix
)
853 fname
= wstrdup(prefix
);
855 while (access(fname
, F_OK
)==0) {
859 sprintf(buf
, "%08lx.cache", time(NULL
));
860 fname
= wstrappend(prefix
, buf
);
870 okNewTexture(void *data
)
872 _Panel
*panel
= (_Panel
*)data
;
877 TextureListItem
*titem
;
878 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
880 titem
= wmalloc(sizeof(TextureListItem
));
881 memset(titem
, 0, sizeof(TextureListItem
));
883 HideTexturePanel(panel
->texturePanel
);
885 name
= GetTexturePanelTextureName(panel
->texturePanel
);
887 prop
= GetTexturePanelTexture(panel
->texturePanel
);
889 str
= PLGetDescription(prop
);
893 titem
->texture
= str
;
894 titem
->selectedFor
= 0;
896 titem
->ispixmap
= isPixmap(prop
);
898 titem
->path
= makeFileName(panel
->fprefix
);
899 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
902 item
= WMAddListItem(panel
->texLs
, "");
903 item
->clientData
= titem
;
905 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
910 okEditTexture(void *data
)
912 _Panel
*panel
= (_Panel
*)data
;
917 TextureListItem
*titem
;
919 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
920 titem
= (TextureListItem
*)item
->clientData
;
922 HideTexturePanel(panel
->texturePanel
);
924 if (titem
->current
) {
925 name
= GetTexturePanelTextureName(panel
->texturePanel
);
931 prop
= GetTexturePanelTexture(panel
->texturePanel
);
933 str
= PLGetDescription(prop
);
935 PLRelease(titem
->prop
);
938 titem
->ispixmap
= isPixmap(prop
);
940 free(titem
->texture
);
941 titem
->texture
= str
;
943 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
944 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
945 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
948 WMRedisplayWidget(panel
->texLs
);
950 if (titem
->selectedFor
)
951 updatePreviewBox(panel
, titem
->selectedFor
);
953 changePage(panel
->secP
, panel
);
959 editTexture(WMWidget
*w
, void *data
)
961 _Panel
*panel
= (_Panel
*)data
;
963 TextureListItem
*titem
;
965 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
966 titem
= (TextureListItem
*)item
->clientData
;
968 SetTexturePanelPixmapPath(panel
->texturePanel
,
969 GetObjectForKey("PixmapPath"));
971 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
973 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
974 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
976 ShowTexturePanel(panel
->texturePanel
);
982 newTexture(WMWidget
*w
, void *data
)
984 _Panel
*panel
= (_Panel
*)data
;
986 SetTexturePanelPixmapPath(panel
->texturePanel
,
987 GetObjectForKey("PixmapPath"));
989 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
991 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
993 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
995 ShowTexturePanel(panel
->texturePanel
);
1001 deleteTexture(WMWidget
*w
, void *data
)
1003 _Panel
*panel
= (_Panel
*)data
;
1005 TextureListItem
*titem
;
1009 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1010 row
= WMGetListSelectedItemRow(panel
->texLs
);
1011 item
= WMGetListItem(panel
->texLs
, row
);
1012 titem
= (TextureListItem
*)item
->clientData
;
1014 if (titem
->selectedFor
& (1 << section
)) {
1015 TextureListItem
*titem2
;
1017 panel
->textureIndex
[section
] = section
;
1018 item
= WMGetListItem(panel
->texLs
, section
);
1019 titem2
= (TextureListItem
*)item
->clientData
;
1020 titem2
->selectedFor
|= 1 << section
;
1024 free(titem
->texture
);
1025 PLRelease(titem
->prop
);
1027 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1028 wsyserror("could not remove file %s", titem
->path
);
1035 WMRemoveListItem(panel
->texLs
, row
);
1036 WMSetButtonEnabled(panel
->delB
, False
);
1043 extractTexture(WMWidget
*w
, void *data
)
1045 _Panel
*panel
= (_Panel
*)data
;
1047 WMOpenPanel
*opanel
;
1048 WMScreen
*scr
= WMWidgetScreen(w
);
1050 opanel
= WMGetOpenPanel(scr
);
1051 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1052 WMSetFilePanelCanChooseFiles(opanel
, True
);
1054 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
1055 _("Select File"), NULL
)) {
1056 path
= WMGetFilePanelFileName(opanel
);
1058 OpenExtractPanelFor(panel
, path
);
1066 changePage(WMWidget
*w
, void *data
)
1068 _Panel
*panel
= (_Panel
*)data
;
1071 TextureListItem
*titem
;
1072 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1073 RContext
*rc
= WMScreenRContext(scr
);
1074 static WMPoint positions
[] = {
1085 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1087 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1089 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1091 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1093 titem
= (TextureListItem
*)item
->clientData
;
1098 color
= WMGrayColor(scr
);
1099 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1100 positions
[panel
->oldsection
].x
,
1101 positions
[panel
->oldsection
].y
, 22, 22);
1102 WMReleaseColor(color
);
1105 panel
->oldsection
= section
;
1106 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1107 positions
[section
].y
);
1109 WMRedisplayWidget(panel
->prevL
);
1115 previewClick(XEvent
*event
, void *clientData
)
1117 _Panel
*panel
= (_Panel
*)clientData
;
1120 switch (panel
->oldTabItem
) {
1122 for (i
= 0; i
< sizeof(previewPositions
)/sizeof(WMRect
); i
++) {
1123 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
1124 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
1125 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
1126 + previewPositions
[i
].size
.width
1127 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
1128 + previewPositions
[i
].size
.height
) {
1130 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1131 changePage(panel
->secP
, panel
);
1137 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1138 if (event
->xbutton
.x
>= previewColorPositions
[i
].pos
.x
1139 && event
->xbutton
.y
>= previewColorPositions
[i
].pos
.y
1140 && event
->xbutton
.x
< previewColorPositions
[i
].pos
.x
1141 + previewColorPositions
[i
].size
.width
1142 && event
->xbutton
.y
< previewColorPositions
[i
].pos
.y
1143 + previewColorPositions
[i
].size
.height
) {
1149 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1150 changeColorPage(panel
->colP
, panel
);
1160 textureClick(WMWidget
*w
, void *data
)
1162 _Panel
*panel
= (_Panel
*)data
;
1165 TextureListItem
*titem
;
1167 i
= WMGetListSelectedItemRow(panel
->texLs
);
1169 item
= WMGetListItem(panel
->texLs
, i
);
1171 titem
= (TextureListItem
*)item
->clientData
;
1173 if (titem
->current
) {
1174 WMSetButtonEnabled(panel
->delB
, False
);
1176 WMSetButtonEnabled(panel
->delB
, True
);
1183 textureDoubleClick(WMWidget
*w
, void *data
)
1185 _Panel
*panel
= (_Panel
*)data
;
1188 TextureListItem
*titem
;
1190 /* unselect old texture */
1191 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1193 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1194 titem
= (TextureListItem
*)item
->clientData
;
1195 titem
->selectedFor
&= ~(1 << section
);
1197 /* select new texture */
1198 i
= WMGetListSelectedItemRow(panel
->texLs
);
1200 item
= WMGetListItem(panel
->texLs
, i
);
1202 titem
= (TextureListItem
*)item
->clientData
;
1204 titem
->selectedFor
|= 1<<section
;
1206 panel
->textureIndex
[section
] = i
;
1208 WMRedisplayWidget(panel
->texLs
);
1210 updatePreviewBox(panel
, 1<<section
);
1216 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
1219 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
1220 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1221 int width
, height
, x
, y
;
1222 Display
*dpy
= WMScreenDisplay(scr
);
1223 WMColor
*white
= WMWhiteColor(scr
);
1225 WMColor
*black
= WMBlackColor(scr
);
1226 TextureListItem
*titem
;
1228 width
= rect
->size
.width
;
1229 height
= rect
->size
.height
;
1233 if (state
& WLDSSelected
)
1234 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1236 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
1238 item
= WMGetListItem(lPtr
, index
);
1239 titem
= (TextureListItem
*)item
->clientData
;
1242 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0, TEXPREV_WIDTH
,
1243 TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1245 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1246 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1247 else if (titem
->selectedFor
)
1248 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1250 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
1251 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
1252 strlen(titem
->title
));
1254 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
1255 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
1256 strlen(titem
->texture
));
1259 WMReleaseColor(white
);
1260 WMReleaseColor(black
);
1266 loadRImage(WMScreen
*scr
, char *path
)
1274 f
= fopen(path
, "r");
1278 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1280 image
= RCreateImage(w
, h
, d
== 4);
1281 for (i
= 0; i
< d
; i
++) {
1282 fread(image
->data
[i
], 1, w
*h
, f
);
1286 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1287 RDestroyImage(image
);
1295 fillTextureList(WMList
*lPtr
)
1297 proplist_t textureList
;
1299 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1300 TextureListItem
*titem
;
1301 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1304 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1308 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1311 texture
= PLGetArrayElement(textureList
, i
);
1313 titem
= wmalloc(sizeof(TextureListItem
));
1314 memset(titem
, 0, sizeof(TextureListItem
));
1316 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1317 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1318 titem
->texture
= PLGetDescription(titem
->prop
);
1319 titem
->selectedFor
= 0;
1320 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1322 titem
->preview
= loadRImage(scr
, titem
->path
);
1323 if (!titem
->preview
) {
1324 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1325 TEXPREV_HEIGHT
, NULL
, 0);
1327 item
= WMAddListItem(lPtr
, "");
1328 item
->clientData
= titem
;
1333 /*************************************************************************/
1337 changeColorPage(WMWidget
*w
, void *data
)
1339 _Panel
*panel
= (_Panel
*)data
;
1341 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1342 RContext
*rc
= WMScreenRContext(scr
);
1343 static WMPoint positions
[] = {
1358 if (panel
->preview
) {
1361 color
= WMGrayColor(scr
);
1362 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1363 positions
[panel
->oldcsection
].x
,
1364 positions
[panel
->oldcsection
].y
, 22, 22);
1365 WMReleaseColor(color
);
1368 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1370 panel
->oldcsection
= section
;
1372 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1373 positions
[section
].y
);
1375 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1377 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1379 WMRedisplayWidget(panel
->prevL
);
1384 paintText(WMScreen
*scr
, Drawable d
, WMColor
*color
, WMFont
*font
,
1385 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1387 int l
= strlen(text
);
1394 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1398 x
+= (w
- WMWidthOfString(font
, text
, l
))/2;
1401 WMDrawString(scr
, d
, WMColorGC(color
), font
, x
,
1402 y
+ (h
- WMFontHeight(font
))/2, text
, l
);
1408 updateColorPreviewBox(_Panel
*panel
, int elements
)
1410 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1414 pixmap
= WMGetLabelImage(panel
->prevL
);
1415 d
= WMGetPixmapXID(pixmap
);
1417 if (elements
& FTITLE_COL
) {
1418 paintText(scr
, d
, panel
->colors
[0], panel
->boldFont
, 30, 10, 190, 20,
1419 panel
->titleAlignment
, _("Focused Window"));
1421 if (elements
& UTITLE_COL
) {
1422 paintText(scr
, d
, panel
->colors
[1], panel
->boldFont
, 30, 40, 190, 20,
1423 panel
->titleAlignment
, _("Unfocused Window"));
1425 if (elements
& OTITLE_COL
) {
1426 paintText(scr
, d
, panel
->colors
[2], panel
->boldFont
, 30, 70, 190, 20,
1427 panel
->titleAlignment
, _("Owner of Focused Window"));
1429 if (elements
& MTITLE_COL
) {
1430 paintText(scr
, d
, panel
->colors
[3], panel
->boldFont
, 30, 120, 90, 20,
1431 WALeft
, _("Menu Title"));
1433 if (elements
& MITEM_COL
) {
1434 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 140, 90, 18,
1435 WALeft
, _("Normal Item"));
1436 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 194, 90, 18,
1437 WALeft
, _("Normal Item"));
1439 if (elements
& MDISAB_COL
) {
1440 paintText(scr
, d
, panel
->colors
[5], panel
->normalFont
, 30, 158, 90, 18,
1441 WALeft
, _("Disabled Item"));
1443 if (elements
& MHIGH_COL
) {
1444 XFillRectangle(WMScreenDisplay(scr
), d
, WMColorGC(panel
->colors
[6]),
1446 elements
|= MHIGHT_COL
;
1448 if (elements
& MHIGHT_COL
) {
1449 paintText(scr
, d
, panel
->colors
[7], panel
->normalFont
, 30, 176, 90, 18,
1450 WALeft
, _("Highlighted"));
1453 if (elements & ICONT_COL) {
1454 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1457 if (elements & ICONB_COL) {
1458 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1461 if (elements & CLIP_COL) {
1462 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1465 if (elements & CCLIP_COL) {
1466 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1470 WMRedisplayWidget(panel
->prevL
);
1475 colorWellObserver(void *self
, WMNotification
*n
)
1477 _Panel
*panel
= (_Panel
*)self
;
1480 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1482 panel
->colors
[p
] = WMGetColorWellColor(panel
->colW
);
1484 updateColorPreviewBox(panel
, 1<<p
);
1489 changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
*tabView
,
1490 WMTabViewItem
*item
)
1492 _Panel
*panel
= self
->data
;
1495 i
= WMGetTabViewItemIdentifier(item
);
1498 switch (panel
->oldTabItem
) {
1500 changeColorPage(NULL
, panel
);
1503 changePage(panel
->secP
, panel
);
1506 switch (panel
->oldTabItem
) {
1508 changePage(NULL
, panel
);
1511 changeColorPage(panel
->colP
, panel
);
1514 switch (panel
->oldTabItem
) {
1516 changePage(NULL
, panel
);
1519 changeColorPage(NULL
, panel
);
1525 panel
->oldTabItem
= i
;
1529 /*************************************************************************/
1532 menuStyleCallback(WMWidget
*self
, void *data
)
1534 _Panel
*panel
= (_Panel
*)data
;
1536 if (self
== panel
->mstyB
[0]) {
1537 panel
->menuStyle
= MSTYLE_NORMAL
;
1538 updatePreviewBox(panel
, 1<<PMITEM
);
1540 } else if (self
== panel
->mstyB
[1]) {
1541 panel
->menuStyle
= MSTYLE_SINGLE
;
1542 updatePreviewBox(panel
, 1<<PMITEM
);
1544 } else if (self
== panel
->mstyB
[2]) {
1545 panel
->menuStyle
= MSTYLE_FLAT
;
1546 updatePreviewBox(panel
, 1<<PMITEM
);
1552 titleAlignCallback(WMWidget
*self
, void *data
)
1554 _Panel
*panel
= (_Panel
*)data
;
1556 if (self
== panel
->taliB
[0]) {
1557 panel
->titleAlignment
= WALeft
;
1558 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1560 } else if (self
== panel
->taliB
[1]) {
1561 panel
->titleAlignment
= WACenter
;
1562 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1564 } else if (self
== panel
->taliB
[2]) {
1565 panel
->titleAlignment
= WARight
;
1566 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1572 createPanel(Panel
*p
)
1574 _Panel
*panel
= (_Panel
*)p
;
1576 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1577 WMTabViewItem
*item
;
1582 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
1584 if (access(panel
->fprefix
, F_OK
)!=0) {
1585 if (mkdir(panel
->fprefix
, 0755) < 0) {
1586 wsyserror(panel
->fprefix
);
1591 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
1592 free(panel
->fprefix
);
1593 panel
->fprefix
= tmp
;
1594 if (access(panel
->fprefix
, F_OK
)!=0) {
1595 if (mkdir(panel
->fprefix
, 0755) < 0) {
1596 wsyserror(panel
->fprefix
);
1601 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1602 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1603 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1605 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1606 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1607 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1609 panel
->frame
= WMCreateFrame(panel
->win
);
1610 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1611 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1614 panel
->prevL
= WMCreateLabel(panel
->frame
);
1615 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1616 WMMoveWidget(panel
->prevL
, 15, 10);
1617 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1618 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1620 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1621 previewClick
, panel
);
1626 tabviewDelegate
.data
= panel
;
1628 panel
->tabv
= WMCreateTabView(panel
->frame
);
1629 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1630 WMMoveWidget(panel
->tabv
, 265, 10);
1631 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1633 /*** texture list ***/
1635 panel
->texF
= WMCreateFrame(panel
->frame
);
1636 WMSetFrameRelief(panel
->texF
, WRFlat
);
1638 item
= WMCreateTabViewItemWithIdentifier(0);
1639 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1640 WMSetTabViewItemLabel(item
, _("Texture"));
1642 WMAddItemInTabView(panel
->tabv
, item
);
1645 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1646 WMResizeWidget(panel
->secP
, 228, 20);
1647 WMMoveWidget(panel
->secP
, 7, 7);
1648 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1649 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1650 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1651 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1652 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1653 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1654 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1655 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1656 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1658 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1660 panel
->texLs
= WMCreateList(panel
->texF
);
1661 WMResizeWidget(panel
->texLs
, 165, 155);
1662 WMMoveWidget(panel
->texLs
, 70, 33);
1663 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1664 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1665 WMHangData(panel
->texLs
, panel
);
1666 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1667 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1669 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1670 "for the selected item."),
1671 WMWidgetView(panel
->texLs
));
1673 /* command buttons */
1675 font
= WMSystemFontOfSize(scr
, 10);
1678 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1679 WMResizeWidget(panel
->newB
, 57, 39);
1680 WMMoveWidget(panel
->newB
, 7, 33);
1681 WMSetButtonFont(panel
->newB
, font
);
1682 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1683 WMSetButtonText(panel
->newB
, _("New"));
1684 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1685 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1687 WMSetBalloonTextForView(_("Create a new texture."),
1688 WMWidgetView(panel
->newB
));
1690 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1691 WMResizeWidget(panel
->ripB
, 57, 39);
1692 WMMoveWidget(panel
->ripB
, 7, 72);
1693 WMSetButtonFont(panel
->ripB
, font
);
1694 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1695 WMSetButtonText(panel
->ripB
, _("Extract..."));
1696 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1697 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1699 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1700 WMWidgetView(panel
->ripB
));
1702 WMSetButtonEnabled(panel
->ripB
, False
);
1704 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1705 WMResizeWidget(panel
->editB
, 57, 39);
1706 WMMoveWidget(panel
->editB
, 7, 111);
1707 WMSetButtonFont(panel
->editB
, font
);
1708 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1709 WMSetButtonText(panel
->editB
, _("Edit"));
1710 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1711 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1712 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1713 WMWidgetView(panel
->editB
));
1715 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1716 WMResizeWidget(panel
->delB
, 57, 38);
1717 WMMoveWidget(panel
->delB
, 7, 150);
1718 WMSetButtonFont(panel
->delB
, font
);
1719 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1720 WMSetButtonText(panel
->delB
, _("Delete"));
1721 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1722 WMSetButtonEnabled(panel
->delB
, False
);
1723 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1724 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1725 WMWidgetView(panel
->delB
));
1727 WMReleaseFont(font
);
1729 WMMapSubwidgets(panel
->texF
);
1732 panel
->colF
= WMCreateFrame(panel
->frame
);
1733 WMSetFrameRelief(panel
->colF
, WRFlat
);
1735 item
= WMCreateTabViewItemWithIdentifier(1);
1736 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1737 WMSetTabViewItemLabel(item
, _("Color"));
1739 WMAddItemInTabView(panel
->tabv
, item
);
1741 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1742 WMResizeWidget(panel
->colP
, 228, 20);
1743 WMMoveWidget(panel
->colP
, 7, 7);
1744 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1745 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Title"));
1746 WMAddPopUpButtonItem(panel
->colP
, _("Unfocused Window Title"));
1747 WMAddPopUpButtonItem(panel
->colP
, _("Owner of Focused Window Title"));
1748 WMAddPopUpButtonItem(panel
->colP
, _("Menu Title"));
1749 WMAddPopUpButtonItem(panel
->colP
, _("Menu Item Text"));
1750 WMAddPopUpButtonItem(panel
->colP
, _("Disabled Menu Item Text"));
1751 WMAddPopUpButtonItem(panel
->colP
, _("Menu Highlight Color"));
1752 WMAddPopUpButtonItem(panel
->colP
, _("Highlighted Menu Text Color"));
1754 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1755 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1756 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1757 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1760 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1762 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1765 panel
->colW
= WMCreateColorWell(panel
->colF
);
1766 WMResizeWidget(panel
->colW
, 65, 50);
1767 WMMoveWidget(panel
->colW
, 30, 75);
1768 WMAddNotificationObserver(colorWellObserver
, panel
,
1769 WMColorWellDidChangeNotification
, panel
->colW
);
1771 for (i
= 0; i
< 4; i
++) {
1773 for (j
= 0; j
< 6; j
++) {
1774 panel
->sampW
[i
] = WMCreateColorWell(panel
->colF
);
1775 WMResizeWidget(panel
->sampW
[i
], 22, 22);
1776 WMMoveWidget(panel
->sampW
[i
], 130 + i
*22, 40 + j
*22);
1777 WSetColorWellBordered(panel
->sampW
[i
], False
);
1781 WMMapSubwidgets(panel
->colF
);
1784 panel
->optF
= WMCreateFrame(panel
->frame
);
1785 WMSetFrameRelief(panel
->optF
, WRFlat
);
1787 item
= WMCreateTabViewItemWithIdentifier(2);
1788 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1789 WMSetTabViewItemLabel(item
, _("Options"));
1791 WMAddItemInTabView(panel
->tabv
, item
);
1793 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1794 WMResizeWidget(panel
->mstyF
, 215, 85);
1795 WMMoveWidget(panel
->mstyF
, 15, 10);
1796 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1798 for (i
= 0; i
< 3; i
++) {
1802 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1803 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1804 WMMoveWidget(panel
->mstyB
[i
], 15 + i
*65, 20);
1805 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1806 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1809 path
= LocateImage(MSTYLE1_FILE
);
1812 path
= LocateImage(MSTYLE2_FILE
);
1815 path
= LocateImage(MSTYLE3_FILE
);
1819 icon
= WMCreatePixmapFromFile(scr
, path
);
1821 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1822 WMReleasePixmap(icon
);
1824 wwarning(_("could not load icon file %s"), path
);
1829 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1830 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1832 WMMapSubwidgets(panel
->mstyF
);
1835 panel
->taliF
= WMCreateFrame(panel
->optF
);
1836 WMResizeWidget(panel
->taliF
, 110, 80);
1837 WMMoveWidget(panel
->taliF
, 15, 100);
1838 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
1840 for (i
= 0; i
< 3; i
++) {
1841 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
1842 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
1845 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1848 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1851 WMSetButtonText(panel
->taliB
[i
], _("Right"));
1854 WMResizeWidget(panel
->taliB
[i
], 90, 18);
1855 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20*i
);
1857 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
1858 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
1860 WMMapSubwidgets(panel
->taliB
);
1862 WMMapSubwidgets(panel
->optF
);
1866 WMRealizeWidget(panel
->frame
);
1867 WMMapSubwidgets(panel
->frame
);
1869 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1873 changePage(panel
->secP
, panel
);
1875 fillTextureList(panel
->texLs
);
1877 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1883 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1887 TextureListItem
*titem
;
1889 titem
= wmalloc(sizeof(TextureListItem
));
1890 memset(titem
, 0, sizeof(TextureListItem
));
1892 titem
->title
= wstrdup(title
);
1893 titem
->prop
= GetObjectForKey(key
);
1895 titem
->prop
= PLGetProplistWithDescription(defValue
);
1897 PLRetain(titem
->prop
);
1899 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1901 titem
->selectedFor
= 1<<index
;
1903 titem
->ispixmap
= isPixmap(titem
->prop
);
1905 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1906 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1908 item
= WMAddListItem(list
, "");
1909 item
->clientData
= titem
;
1915 showData(_Panel
*panel
)
1920 str
= GetStringForKey("MenuStyle");
1921 if (str
&& strcasecmp(str
, "flat")==0) {
1922 panel
->menuStyle
= MSTYLE_FLAT
;
1923 } else if (str
&& strcasecmp(str
, "singletexture")==0) {
1924 panel
->menuStyle
= MSTYLE_SINGLE
;
1926 panel
->menuStyle
= MSTYLE_NORMAL
;
1929 str
= GetStringForKey("TitleJustify");
1930 if (str
&& strcasecmp(str
, "left")==0) {
1931 panel
->titleAlignment
= WALeft
;
1932 } else if (str
&& strcasecmp(str
, "right")==0) {
1933 panel
->titleAlignment
= WARight
;
1935 panel
->titleAlignment
= WACenter
;
1938 for (i
= 0; i
< sizeof(colorOptions
)/(2*sizeof(char*)); i
++) {
1941 str
= GetStringForKey(colorOptions
[i
*2]);
1943 str
= colorOptions
[i
*2+1];
1945 color
= WMCreateNamedColor(WMWidgetScreen(panel
->frame
), str
, False
);
1947 panel
->colors
[i
] = color
;
1949 changeColorPage(panel
->colP
, panel
);
1951 for (i
= 0; i
< sizeof(textureOptions
)/(3*sizeof(char*)); i
++) {
1952 setupTextureFor(panel
->texLs
, textureOptions
[i
*3],
1953 textureOptions
[i
*3+1], textureOptions
[i
*3+2], i
);
1954 panel
->textureIndex
[i
] = i
;
1956 updatePreviewBox(panel
, EVERYTHING
);
1959 for (i
= 0; i
< 3; i
++) {
1960 WMSetButtonSelected(panel
->mstyB
[i
], i
==panel
->menuStyle
);
1961 WMSetButtonSelected(panel
->taliB
[i
], i
==panel
->titleAlignment
);
1968 storeData(_Panel
*panel
)
1970 TextureListItem
*titem
;
1974 for (i
= 0; i
< sizeof(textureOptions
)/(sizeof(char*)*3); i
++) {
1975 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
1976 titem
= (TextureListItem
*)item
->clientData
;
1977 SetObjectForKey(titem
->prop
, textureOptions
[i
*3]);
1980 for (i
= 0; i
< 8; i
++) {
1981 SetStringForKey(WMGetColorRGBDescription(panel
->colors
[i
]),
1985 switch (panel
->menuStyle
) {
1987 SetStringForKey("singletexture", "MenuStyle");
1990 SetStringForKey("flat", "MenuStyle");
1994 SetStringForKey("normal", "MenuStyle");
1997 switch (panel
->titleAlignment
) {
1999 SetStringForKey("left", "TitleJustify");
2002 SetStringForKey("right", "TitleJustify");
2006 SetStringForKey("center", "TitleJustify");
2013 prepareForClose(_Panel
*panel
)
2015 proplist_t textureList
;
2018 TextureListItem
*titem
;
2020 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2022 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
2024 /* store list of textures */
2025 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2026 item
= WMGetListItem(panel
->texLs
, i
);
2027 titem
= (TextureListItem
*)item
->clientData
;
2029 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
2030 PLRetain(titem
->prop
),
2031 PLMakeString(titem
->path
),
2034 PLAppendArrayElement(textureList
, texture
);
2037 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2038 PLRelease(textureList
);
2040 WMSynchronizeUserDefaults(udb
);
2046 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
2050 panel
= wmalloc(sizeof(_Panel
));
2051 memset(panel
, 0, sizeof(_Panel
));
2053 panel
->sectionName
= _("Appearance Preferences");
2055 panel
->description
= _("Background texture configuration for windows,\n"
2056 "menus and icons.");
2060 panel
->callbacks
.createWidgets
= createPanel
;
2061 panel
->callbacks
.updateDomain
= storeData
;
2062 panel
->callbacks
.prepareForClose
= prepareForClose
;
2064 AddSection(panel
, ICON_FILE
);
2071 /****************************************************************************/
2075 typedef struct ExtractPanel
{
2088 OpenExtractPanelFor(_Panel
*panel
, char *path
)
2090 ExtractPanel
*epanel
;
2093 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
2095 epanel
= wmalloc(sizeof(ExtractPanel
));
2096 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
2098 |WMClosableWindowMask
);
2099 WMResizeWidget(epanel
->win
, 245, 250);
2100 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2102 epanel
->label
= WMCreateLabel(epanel
->win
);
2103 WMResizeWidget(epanel
->label
, 225, 18);
2104 WMMoveWidget(epanel
->label
, 10, 10);
2105 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2106 WMSetLabelRelief(epanel
->label
, WRSunken
);
2108 color
= WMDarkGrayColor(scr
);
2109 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2110 WMReleaseColor(color
);
2112 color
= WMWhiteColor(scr
);
2113 WMSetLabelTextColor(epanel
->label
, color
);
2114 WMReleaseColor(color
);
2116 font
= WMBoldSystemFontOfSize(scr
, 12);
2117 WMSetLabelFont(epanel
->label
, font
);
2118 WMReleaseFont(font
);
2120 WMSetLabelText(epanel
->label
, _("Textures"));
2122 epanel
->list
= WMCreateList(epanel
->win
);
2123 WMResizeWidget(epanel
->list
, 225, 165);
2124 WMMoveWidget(epanel
->list
, 10, 30);
2128 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2129 WMResizeWidget(epanel
->closeB
, 74, 24);
2130 WMMoveWidget(epanel
->closeB
, 165, 215);
2131 WMSetButtonText(epanel
->closeB
, _("Close"));
2133 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2134 WMResizeWidget(epanel
->extrB
, 74, 24);
2135 WMMoveWidget(epanel
->extrB
, 80, 215);
2136 WMSetButtonText(epanel
->extrB
, _("Extract"));
2138 WMMapSubwidgets(epanel
->win
);
2141 /* take textures from file */
2145 WMRealizeWidget(epanel
->win
);
2147 WMMapWidget(epanel
->win
);