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];
91 WMPopUpButton
*modeB
[3];
101 TexturePanel
*texturePanel
;
135 static void updateColorPreviewBox(_Panel
*panel
, int elements
);
137 static void showData(_Panel
*panel
);
139 static void changePage(WMWidget
*w
, void *data
);
141 static void changeColorPage(WMWidget
*w
, void *data
);
143 static void OpenExtractPanelFor(_Panel
*panel
, char *path
);
147 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
*tabView
,
148 WMTabViewItem
*item
);
152 static WMTabViewDelegate tabviewDelegate
= {
154 NULL
, /* didChangeNumberOfItems */
155 changedTabItem
, /* didSelectItem */
156 NULL
, /* shouldSelectItem */
157 NULL
/* willSelectItem */
161 #define ICON_FILE "appearance"
163 #define TNEW_FILE "tnew"
164 #define TDEL_FILE "tdel"
165 #define TEDIT_FILE "tedit"
166 #define TEXTR_FILE "textr"
168 #define MSTYLE1_FILE "msty1"
169 #define MSTYLE2_FILE "msty2"
170 #define MSTYLE3_FILE "msty3"
174 static char * blueled_xpm
[] = {
204 static char *blueled2_xpm
[] = {
205 /* width height num_colors chars_per_pixel */
238 static char * hand_xpm
[] = {
262 " .%%%&@.......... ",
263 " .%*%%&#%%%%%%%%%$. ",
264 " .*#%%%%%%%%%&&&&==. ",
265 " .-%%%%%%%%%=*-;;;#$. ",
266 " .-%%%%%%%%&..>..... ",
283 static char *sampleColors
[] = {
312 static char *textureOptions
[] = {
313 "FTitleBack", "(solid, black)", "[Focused]",
314 "UTitleBack", "(solid, gray)", "[Unfocused]",
315 "PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
316 "ResizebarBack", "(solid, gray)", "[Resizebar]",
317 "MenuTitleBack", "(solid, black)", "[Menu Title]",
318 "MenuTextBack", "(solid, gray)", "[Menu Item]",
319 "IconBack", "(solid, gray)", "[Icon]"
323 #define RESIZEBAR_BEVEL -1
324 #define MENU_BEVEL -2
326 #define TEXPREV_WIDTH 40
327 #define TEXPREV_HEIGHT 24
330 #define MSTYLE_NORMAL 0
331 #define MSTYLE_SINGLE 1
332 #define MSTYLE_FLAT 2
335 #define FTITLE_COL (1<<0)
336 #define UTITLE_COL (1<<1)
337 #define OTITLE_COL (1<<2)
338 #define MTITLE_COL (1<<3)
339 #define MITEM_COL (1<<4)
340 #define MDISAB_COL (1<<5)
341 #define MHIGH_COL (1<<6)
342 #define MHIGHT_COL (1<<7)
343 #define ICONT_COL (1<<8)
344 #define ICONB_COL (1<<9)
345 #define CLIP_COL (1<<10)
346 #define CCLIP_COL (1<<11)
349 static char *colorOptions
[] = {
350 "FTitleColor", "white",
351 "UTitleColor", "black",
352 "PTitleColor", "white",
353 "MenuTitleColor", "white",
354 "MenuTextColor", "black",
355 "MenuDisabledColor", "#616161",
356 "HighlightColor", "white",
357 "HighlightTextColor", "black",
358 "IconTitleColor", "white",
359 "IconTitleBack", "black",
360 "ClipTitleColor", "black",
361 "CClipTitleColor", "#454045"
367 static WMRect previewPositions
[] = {
379 {{30,140},{90,20*4}},
383 #define EVERYTHING 0xff
386 static WMRect previewColorPositions
[] = {
404 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
408 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
411 color
->red
= xcolor
.red
>> 8;
412 color
->green
= xcolor
.green
>> 8;
413 color
->blue
= xcolor
.blue
>> 8;
418 dumpRImage(char *path
, RImage
*image
)
421 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
423 f
= fopen(path
, "w");
428 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
, channels
);
430 fwrite(image
->data
, 1, image
->width
* image
->height
* channels
, f
);
440 isPixmap(proplist_t prop
)
445 p
= PLGetArrayElement(prop
, 0);
447 if (strcasecmp(&s
[1], "pixmap")==0)
454 /**********************************************************************/
457 drawResizebarBevel(RImage
*img
)
462 int width
= img
->width
;
463 int height
= img
->height
;
467 black
.red
= black
.green
= black
.blue
= 0;
470 light
.red
= light
.green
= light
.blue
= 80;
473 dark
.red
= dark
.green
= dark
.blue
= 40;
475 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
476 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
478 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
479 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
481 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
483 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
486 RDrawLine(img
, 0, height
-1, width
-1, height
-1, &black
);
487 RDrawLine(img
, 0, 0, 0, height
-1, &black
);
488 RDrawLine(img
, width
-1, 0, width
-1, height
-1, &black
);
493 drawMenuBevel(RImage
*img
)
495 RColor light
, dark
, mid
;
497 int iheight
= img
->height
/ 4;
500 light
.red
= light
.green
= light
.blue
= 80;
503 dark
.red
= dark
.green
= dark
.blue
= 0;
506 mid
.red
= mid
.green
= mid
.blue
= 40;
508 for (i
= 1; i
< 4; i
++) {
509 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
510 img
->width
-1, i
*iheight
-2, &mid
);
512 RDrawLine(img
, 0, i
*iheight
-1, img
->width
-1, i
*iheight
-1, &dark
);
514 ROperateLine(img
, RAddOperation
, 1, i
*iheight
,
515 img
->width
-2, i
*iheight
, &light
);
521 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
522 char *path
, int border
)
525 RImage
*image
= NULL
;
527 RContext
*rc
= WMScreenRContext(scr
);
532 type
= PLGetString(PLGetArrayElement(texture
, 0));
534 if (strcasecmp(type
, "solid")==0) {
536 str
= PLGetString(PLGetArrayElement(texture
, 1));
538 str2rcolor(rc
, str
, &rcolor
);
540 image
= RCreateImage(width
, height
, False
);
541 RClearImage(image
, &rcolor
);
542 } else if (strcasecmp(type
, "igradient")==0) {
546 str
= PLGetString(PLGetArrayElement(texture
, 1));
547 str2rcolor(rc
, str
, &c1
[0]);
548 str
= PLGetString(PLGetArrayElement(texture
, 2));
549 str2rcolor(rc
, str
, &c1
[1]);
550 str
= PLGetString(PLGetArrayElement(texture
, 3));
553 str
= PLGetString(PLGetArrayElement(texture
, 4));
554 str2rcolor(rc
, str
, &c2
[0]);
555 str
= PLGetString(PLGetArrayElement(texture
, 5));
556 str2rcolor(rc
, str
, &c2
[1]);
557 str
= PLGetString(PLGetArrayElement(texture
, 6));
560 image
= RRenderInterwovenGradient(width
, height
, c1
, t1
, c2
, t2
);
561 } else if (strcasecmp(&type
[1], "gradient")==0) {
565 switch (toupper(type
[0])) {
567 style
= RVerticalGradient
;
570 style
= RHorizontalGradient
;
574 style
= RDiagonalGradient
;
578 str
= PLGetString(PLGetArrayElement(texture
, 1));
579 str2rcolor(rc
, str
, &rcolor
);
580 str
= PLGetString(PLGetArrayElement(texture
, 2));
581 str2rcolor(rc
, str
, &rcolor2
);
583 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
584 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
588 RImage
*grad
, *timage
;
591 switch (toupper(type
[1])) {
593 style
= RVerticalGradient
;
596 style
= RHorizontalGradient
;
600 style
= RDiagonalGradient
;
604 str
= PLGetString(PLGetArrayElement(texture
, 3));
605 str2rcolor(rc
, str
, &rcolor
);
606 str
= PLGetString(PLGetArrayElement(texture
, 4));
607 str2rcolor(rc
, str
, &rcolor2
);
609 str
= PLGetString(PLGetArrayElement(texture
, 1));
611 if ((path
=wfindfileinarray(GetObjectForKey("PixmapPath"), str
))!=NULL
)
612 timage
= RLoadImage(rc
, path
, 0);
614 if (!path
|| !timage
) {
615 wwarning("could not load file '%s': %s", path
,
616 RMessageForError(RErrorCode
));
618 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
620 image
= RMakeTiledImage(timage
, width
, height
);
621 RReleaseImage(timage
);
623 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
625 RCombineImagesWithOpaqueness(image
, grad
, i
);
628 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
633 switch (toupper(type
[1])) {
635 style
= RVerticalGradient
;
638 style
= RHorizontalGradient
;
642 style
= RDiagonalGradient
;
646 j
= PLGetNumberOfElements(texture
);
649 colors
= wmalloc(j
* sizeof(RColor
*));
651 for (i
= 2; i
< j
; i
++) {
652 str
= PLGetString(PLGetArrayElement(texture
, i
));
653 colors
[i
-2] = wmalloc(sizeof(RColor
));
654 str2rcolor(rc
, str
, colors
[i
-2]);
658 image
= RRenderMultiGradient(width
, height
, colors
, style
);
660 for (i
= 0; colors
[i
]!=NULL
; i
++)
664 } else if (strcasecmp(&type
[1], "pixmap")==0) {
665 RImage
*timage
= NULL
;
669 str
= PLGetString(PLGetArrayElement(texture
, 1));
671 if ((path
=wfindfileinarray(GetObjectForKey("PixmapPath"), str
))!=NULL
)
672 timage
= RLoadImage(rc
, path
, 0);
674 if (!path
|| !timage
) {
675 wwarning("could not load file '%s': %s", path
? path
: str
,
676 RMessageForError(RErrorCode
));
678 str
= PLGetString(PLGetArrayElement(texture
, 2));
679 str2rcolor(rc
, str
, &color
);
681 switch (toupper(type
[0])) {
683 image
= RMakeTiledImage(timage
, width
, height
);
684 RReleaseImage(timage
);
688 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
689 RReleaseImage(timage
);
694 image
= RScaleImage(timage
, width
, height
);
695 RReleaseImage(timage
);
708 dumpRImage(path
, image
);
712 if (border
== RESIZEBAR_BEVEL
) {
713 drawResizebarBevel(image
);
714 } else if (border
== MENU_BEVEL
) {
715 drawMenuBevel(image
);
716 RBevelImage(image
, RBEV_RAISED2
);
719 RBevelImage(image
, border
);
722 RConvertImage(rc
, image
, &pixmap
);
723 RReleaseImage(image
);
730 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
732 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
733 Display
*dpy
= WMScreenDisplay(scr
);
735 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
738 switch (panel
->menuStyle
) {
740 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
742 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*4, WMScreenDepth(scr
));
743 for (i
= 0; i
< 4; i
++) {
744 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
*i
);
746 XFreePixmap(dpy
, tmp
);
749 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, MENU_BEVEL
);
752 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, RBEV_RAISED2
);
762 renderPreview(_Panel
*panel
, GC gc
, int part
, int relief
)
765 TextureListItem
*titem
;
767 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
769 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
770 titem
= (TextureListItem
*)item
->clientData
;
772 pix
= renderTexture(scr
, titem
->prop
,
773 previewPositions
[part
].size
.width
,
774 previewPositions
[part
].size
.height
,
777 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
778 previewPositions
[part
].size
.width
,
779 previewPositions
[part
].size
.height
,
780 previewPositions
[part
].pos
.x
,
781 previewPositions
[part
].pos
.y
);
783 XFreePixmap(WMScreenDisplay(scr
), pix
);
788 updatePreviewBox(_Panel
*panel
, int elements
)
790 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
791 Display
*dpy
= WMScreenDisplay(scr
);
792 /* RContext *rc = WMScreenRContext(scr);*/
797 WMColor
*black
= WMBlackColor(scr
);
799 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
802 if (panel
->preview
== None
) {
805 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
806 240-4, 215-4, WMScreenDepth(scr
));
808 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
809 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
811 WMReleaseColor(color
);
817 if (elements
& (1<<PFOCUSED
)) {
818 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
819 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
820 previewPositions
[PFOCUSED
].pos
.x
-1,
821 previewPositions
[PFOCUSED
].pos
.y
-1,
822 previewPositions
[PFOCUSED
].size
.width
,
823 previewPositions
[PFOCUSED
].size
.height
);
824 colorUpdate
|= FTITLE_COL
;
826 if (elements
& (1<<PUNFOCUSED
)) {
827 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
828 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
829 previewPositions
[PUNFOCUSED
].pos
.x
-1,
830 previewPositions
[PUNFOCUSED
].pos
.y
-1,
831 previewPositions
[PUNFOCUSED
].size
.width
,
832 previewPositions
[PUNFOCUSED
].size
.height
);
833 colorUpdate
|= UTITLE_COL
;
835 if (elements
& (1<<POWNER
)) {
836 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
837 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
838 previewPositions
[POWNER
].pos
.x
-1,
839 previewPositions
[POWNER
].pos
.y
-1,
840 previewPositions
[POWNER
].size
.width
,
841 previewPositions
[POWNER
].size
.height
);
842 colorUpdate
|= OTITLE_COL
;
844 if (elements
& (1<<PRESIZEBAR
)) {
845 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
847 if (elements
& (1<<PMTITLE
)) {
848 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
849 colorUpdate
|= MTITLE_COL
;
851 if (elements
& (1<<PMITEM
)) {
853 TextureListItem
*titem
;
855 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
856 titem
= (TextureListItem
*)item
->clientData
;
858 pix
= renderMenu(panel
, titem
->prop
,
859 previewPositions
[PMITEM
].size
.width
,
860 previewPositions
[PMITEM
].size
.height
/4);
862 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
863 previewPositions
[PMITEM
].size
.width
,
864 previewPositions
[PMITEM
].size
.height
,
865 previewPositions
[PMITEM
].pos
.x
,
866 previewPositions
[PMITEM
].pos
.y
);
868 XFreePixmap(dpy
, pix
);
870 colorUpdate
|= MITEM_COL
|MDISAB_COL
|MHIGH_COL
|MHIGHT_COL
;
872 if (elements
& (1<<PMITEM
|1<<PMTITLE
)) {
873 XDrawLine(dpy
, panel
->preview
, gc
, 29, 120, 29, 120+20*4+20);
874 XDrawLine(dpy
, panel
->preview
, gc
, 29, 119, 119, 119);
876 if (elements
& (1<<PICON
)) {
878 TextureListItem
*titem
;
880 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
881 titem
= (TextureListItem
*)item
->clientData
;
883 renderPreview(panel
, gc
, PICON
,
884 titem
->ispixmap
? 0 : RBEV_RAISED3
);
886 colorUpdate
|= ICONT_COL
|ICONB_COL
|CLIP_COL
|CCLIP_COL
;
891 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
892 240-4, 215-4, WMScreenDepth(scr
));
894 WMSetLabelImage(panel
->prevL
, p
);
898 updateColorPreviewBox(panel
, colorUpdate
);
901 updateColorPreviewBox(panel
, colorUpdate
);
903 WMRedisplayWidget(panel
->prevL
);
907 WMReleaseColor(black
);
914 cancelNewTexture(void *data
)
916 _Panel
*panel
= (_Panel
*)data
;
918 HideTexturePanel(panel
->texturePanel
);
925 makeFileName(char *prefix
)
929 fname
= wstrdup(prefix
);
931 while (access(fname
, F_OK
)==0) {
935 sprintf(buf
, "%08lx.cache", time(NULL
));
936 fname
= wstrconcat(prefix
, buf
);
946 okNewTexture(void *data
)
948 _Panel
*panel
= (_Panel
*)data
;
953 TextureListItem
*titem
;
954 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
956 titem
= wmalloc(sizeof(TextureListItem
));
957 memset(titem
, 0, sizeof(TextureListItem
));
959 HideTexturePanel(panel
->texturePanel
);
961 name
= GetTexturePanelTextureName(panel
->texturePanel
);
963 prop
= GetTexturePanelTexture(panel
->texturePanel
);
965 str
= PLGetDescription(prop
);
969 titem
->texture
= str
;
970 titem
->selectedFor
= 0;
972 titem
->ispixmap
= isPixmap(prop
);
974 titem
->path
= makeFileName(panel
->fprefix
);
975 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
978 item
= WMAddListItem(panel
->texLs
, "");
979 item
->clientData
= titem
;
981 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
986 okEditTexture(void *data
)
988 _Panel
*panel
= (_Panel
*)data
;
993 TextureListItem
*titem
;
995 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
996 titem
= (TextureListItem
*)item
->clientData
;
998 HideTexturePanel(panel
->texturePanel
);
1000 if (titem
->current
) {
1001 name
= GetTexturePanelTextureName(panel
->texturePanel
);
1003 wfree(titem
->title
);
1004 titem
->title
= name
;
1007 prop
= GetTexturePanelTexture(panel
->texturePanel
);
1009 str
= PLGetDescription(prop
);
1011 PLRelease(titem
->prop
);
1014 titem
->ispixmap
= isPixmap(prop
);
1016 wfree(titem
->texture
);
1017 titem
->texture
= str
;
1019 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
1020 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
1021 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
1024 WMRedisplayWidget(panel
->texLs
);
1026 if (titem
->selectedFor
)
1027 updatePreviewBox(panel
, titem
->selectedFor
);
1029 changePage(panel
->secP
, panel
);
1035 editTexture(WMWidget
*w
, void *data
)
1037 _Panel
*panel
= (_Panel
*)data
;
1039 TextureListItem
*titem
;
1041 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
1042 titem
= (TextureListItem
*)item
->clientData
;
1044 SetTexturePanelPixmapPath(panel
->texturePanel
,
1045 GetObjectForKey("PixmapPath"));
1047 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
1049 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
1050 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
1052 ShowTexturePanel(panel
->texturePanel
);
1058 newTexture(WMWidget
*w
, void *data
)
1060 _Panel
*panel
= (_Panel
*)data
;
1062 SetTexturePanelPixmapPath(panel
->texturePanel
,
1063 GetObjectForKey("PixmapPath"));
1065 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
1067 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
1069 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
1071 ShowTexturePanel(panel
->texturePanel
);
1077 deleteTexture(WMWidget
*w
, void *data
)
1079 _Panel
*panel
= (_Panel
*)data
;
1081 TextureListItem
*titem
;
1085 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1086 row
= WMGetListSelectedItemRow(panel
->texLs
);
1087 item
= WMGetListItem(panel
->texLs
, row
);
1088 titem
= (TextureListItem
*)item
->clientData
;
1090 if (titem
->selectedFor
& (1 << section
)) {
1091 TextureListItem
*titem2
;
1093 panel
->textureIndex
[section
] = section
;
1094 item
= WMGetListItem(panel
->texLs
, section
);
1095 titem2
= (TextureListItem
*)item
->clientData
;
1096 titem2
->selectedFor
|= 1 << section
;
1099 wfree(titem
->title
);
1100 wfree(titem
->texture
);
1101 PLRelease(titem
->prop
);
1103 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1104 wsyserror("could not remove file %s", titem
->path
);
1111 WMRemoveListItem(panel
->texLs
, row
);
1112 WMSetButtonEnabled(panel
->delB
, False
);
1119 extractTexture(WMWidget
*w
, void *data
)
1121 _Panel
*panel
= (_Panel
*)data
;
1123 WMOpenPanel
*opanel
;
1124 WMScreen
*scr
= WMWidgetScreen(w
);
1126 opanel
= WMGetOpenPanel(scr
);
1127 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1128 WMSetFilePanelCanChooseFiles(opanel
, True
);
1130 if (WMRunModalFilePanelForDirectory(opanel
, panel
->parent
, wgethomedir(),
1131 _("Select File"), NULL
)) {
1132 path
= WMGetFilePanelFileName(opanel
);
1134 OpenExtractPanelFor(panel
, path
);
1142 changePage(WMWidget
*w
, void *data
)
1144 _Panel
*panel
= (_Panel
*)data
;
1147 TextureListItem
*titem
;
1148 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1149 RContext
*rc
= WMScreenRContext(scr
);
1150 static WMPoint positions
[] = {
1161 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1163 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1165 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1167 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1169 titem
= (TextureListItem
*)item
->clientData
;
1174 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1175 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1176 positions
[panel
->oldsection
].x
,
1177 positions
[panel
->oldsection
].y
, 22, 22);
1178 WMReleaseColor(color
);
1181 panel
->oldsection
= section
;
1182 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1183 positions
[section
].y
);
1185 WMRedisplayWidget(panel
->prevL
);
1191 previewClick(XEvent
*event
, void *clientData
)
1193 _Panel
*panel
= (_Panel
*)clientData
;
1196 switch (panel
->oldTabItem
) {
1198 for (i
= 0; i
< sizeof(previewPositions
)/sizeof(WMRect
); i
++) {
1199 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
1200 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
1201 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
1202 + previewPositions
[i
].size
.width
1203 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
1204 + previewPositions
[i
].size
.height
) {
1206 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1207 changePage(panel
->secP
, panel
);
1213 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1214 if (event
->xbutton
.x
>= previewColorPositions
[i
].pos
.x
1215 && event
->xbutton
.y
>= previewColorPositions
[i
].pos
.y
1216 && event
->xbutton
.x
< previewColorPositions
[i
].pos
.x
1217 + previewColorPositions
[i
].size
.width
1218 && event
->xbutton
.y
< previewColorPositions
[i
].pos
.y
1219 + previewColorPositions
[i
].size
.height
) {
1225 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1226 changeColorPage(panel
->colP
, panel
);
1236 textureClick(WMWidget
*w
, void *data
)
1238 _Panel
*panel
= (_Panel
*)data
;
1241 TextureListItem
*titem
;
1243 i
= WMGetListSelectedItemRow(panel
->texLs
);
1245 item
= WMGetListItem(panel
->texLs
, i
);
1247 titem
= (TextureListItem
*)item
->clientData
;
1249 if (titem
->current
) {
1250 WMSetButtonEnabled(panel
->delB
, False
);
1252 WMSetButtonEnabled(panel
->delB
, True
);
1259 textureDoubleClick(WMWidget
*w
, void *data
)
1261 _Panel
*panel
= (_Panel
*)data
;
1264 TextureListItem
*titem
;
1266 /* unselect old texture */
1267 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1269 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1270 titem
= (TextureListItem
*)item
->clientData
;
1271 titem
->selectedFor
&= ~(1 << section
);
1273 /* select new texture */
1274 i
= WMGetListSelectedItemRow(panel
->texLs
);
1276 item
= WMGetListItem(panel
->texLs
, i
);
1278 titem
= (TextureListItem
*)item
->clientData
;
1280 titem
->selectedFor
|= 1<<section
;
1282 panel
->textureIndex
[section
] = i
;
1284 WMRedisplayWidget(panel
->texLs
);
1286 updatePreviewBox(panel
, 1<<section
);
1292 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
1295 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
1296 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1297 int width
, height
, x
, y
;
1298 Display
*dpy
= WMScreenDisplay(scr
);
1299 WMColor
*white
= WMWhiteColor(scr
);
1301 WMColor
*black
= WMBlackColor(scr
);
1302 TextureListItem
*titem
;
1304 item
= WMGetListItem(lPtr
, index
);
1305 titem
= (TextureListItem
*)item
->clientData
;
1307 WMReleaseColor(white
);
1308 WMReleaseColor(black
);
1312 width
= rect
->size
.width
;
1313 height
= rect
->size
.height
;
1317 if (state
& WLDSSelected
)
1318 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1320 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
1324 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0,
1325 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1327 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1328 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1329 else if (titem
->selectedFor
)
1330 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1332 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
1333 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
1334 strlen(titem
->title
));
1336 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
1337 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
1338 strlen(titem
->texture
));
1341 WMReleaseColor(white
);
1342 WMReleaseColor(black
);
1348 loadRImage(WMScreen
*scr
, char *path
)
1355 f
= fopen(path
, "r");
1359 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1361 image
= RCreateImage(w
, h
, d
== 4);
1362 fread(image
->data
, 1, w
*h
*d
, f
);
1365 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1366 RReleaseImage(image
);
1374 fillTextureList(WMList
*lPtr
)
1376 proplist_t textureList
;
1378 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1379 TextureListItem
*titem
;
1380 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1383 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1387 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1390 texture
= PLGetArrayElement(textureList
, i
);
1392 titem
= wmalloc(sizeof(TextureListItem
));
1393 memset(titem
, 0, sizeof(TextureListItem
));
1395 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1396 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1397 titem
->texture
= PLGetDescription(titem
->prop
);
1398 titem
->selectedFor
= 0;
1399 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1401 titem
->preview
= loadRImage(scr
, titem
->path
);
1402 if (!titem
->preview
) {
1403 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1404 TEXPREV_HEIGHT
, NULL
, 0);
1406 item
= WMAddListItem(lPtr
, "");
1407 item
->clientData
= titem
;
1413 fillColorList(_Panel
*panel
)
1417 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1418 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1421 list
= WMGetUDObjectForKey(udb
, "ColorList");
1423 for (i
= 0; i
< 24; i
++) {
1424 color
= WMCreateNamedColor(scr
, sampleColors
[i
], False
);
1427 WMSetColorWellColor(panel
->sampW
[i
], color
);
1428 WMReleaseColor(color
);
1433 for (i
= 0; i
< WMIN(24, PLGetNumberOfElements(list
)); i
++) {
1434 c
= PLGetArrayElement(list
, i
);
1435 if (!c
|| !PLIsString(c
))
1437 color
= WMCreateNamedColor(scr
, PLGetString(c
), False
);
1440 WMSetColorWellColor(panel
->sampW
[i
], color
);
1441 WMReleaseColor(color
);
1447 /*************************************************************************/
1451 changeColorPage(WMWidget
*w
, void *data
)
1453 _Panel
*panel
= (_Panel
*)data
;
1455 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1456 RContext
*rc
= WMScreenRContext(scr
);
1457 static WMPoint positions
[] = {
1472 if (panel
->preview
) {
1475 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1476 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1477 positions
[panel
->oldcsection
].x
,
1478 positions
[panel
->oldcsection
].y
, 22, 22);
1479 WMReleaseColor(color
);
1482 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1484 panel
->oldcsection
= section
;
1486 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1487 positions
[section
].y
);
1489 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1491 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1493 WMRedisplayWidget(panel
->prevL
);
1498 paintText(WMScreen
*scr
, Drawable d
, WMColor
*color
, WMFont
*font
,
1499 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1501 int l
= strlen(text
);
1508 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1512 x
+= (w
- WMWidthOfString(font
, text
, l
))/2;
1515 WMDrawString(scr
, d
, WMColorGC(color
), font
, x
,
1516 y
+ (h
- WMFontHeight(font
))/2, text
, l
);
1522 updateColorPreviewBox(_Panel
*panel
, int elements
)
1524 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1528 pixmap
= WMGetLabelImage(panel
->prevL
);
1529 d
= WMGetPixmapXID(pixmap
);
1531 if (elements
& FTITLE_COL
) {
1532 paintText(scr
, d
, panel
->colors
[0], panel
->boldFont
, 30, 10, 190, 20,
1533 panel
->titleAlignment
, _("Focused Window"));
1535 if (elements
& UTITLE_COL
) {
1536 paintText(scr
, d
, panel
->colors
[1], panel
->boldFont
, 30, 40, 190, 20,
1537 panel
->titleAlignment
, _("Unfocused Window"));
1539 if (elements
& OTITLE_COL
) {
1540 paintText(scr
, d
, panel
->colors
[2], panel
->boldFont
, 30, 70, 190, 20,
1541 panel
->titleAlignment
, _("Owner of Focused Window"));
1543 if (elements
& MTITLE_COL
) {
1544 paintText(scr
, d
, panel
->colors
[3], panel
->boldFont
, 30, 120, 90, 20,
1545 WALeft
, _("Menu Title"));
1547 if (elements
& MITEM_COL
) {
1548 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 140, 90, 20,
1549 WALeft
, _("Normal Item"));
1550 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 200, 90, 20,
1551 WALeft
, _("Normal Item"));
1553 if (elements
& MDISAB_COL
) {
1554 paintText(scr
, d
, panel
->colors
[5], panel
->normalFont
, 30, 160, 90, 20,
1555 WALeft
, _("Disabled Item"));
1557 if (elements
& MHIGH_COL
) {
1558 XFillRectangle(WMScreenDisplay(scr
), d
, WMColorGC(panel
->colors
[6]),
1560 elements
|= MHIGHT_COL
;
1562 if (elements
& MHIGHT_COL
) {
1563 paintText(scr
, d
, panel
->colors
[7], panel
->normalFont
, 30, 180, 90, 20,
1564 WALeft
, _("Highlighted"));
1567 if (elements & ICONT_COL) {
1568 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1571 if (elements & ICONB_COL) {
1572 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1575 if (elements & CLIP_COL) {
1576 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1579 if (elements & CCLIP_COL) {
1580 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1584 WMRedisplayWidget(panel
->prevL
);
1589 colorWellObserver(void *self
, WMNotification
*n
)
1591 _Panel
*panel
= (_Panel
*)self
;
1594 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1596 WMReleaseColor(panel
->colors
[p
]);
1598 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1600 updateColorPreviewBox(panel
, 1<<p
);
1605 changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
*tabView
,
1606 WMTabViewItem
*item
)
1608 _Panel
*panel
= self
->data
;
1611 i
= WMGetTabViewItemIdentifier(item
);
1614 switch (panel
->oldTabItem
) {
1616 changeColorPage(NULL
, panel
);
1619 changePage(panel
->secP
, panel
);
1622 switch (panel
->oldTabItem
) {
1624 changePage(NULL
, panel
);
1627 changeColorPage(panel
->colP
, panel
);
1630 switch (panel
->oldTabItem
) {
1632 changePage(NULL
, panel
);
1635 changeColorPage(NULL
, panel
);
1641 panel
->oldTabItem
= i
;
1645 /*************************************************************************/
1648 menuStyleCallback(WMWidget
*self
, void *data
)
1650 _Panel
*panel
= (_Panel
*)data
;
1652 if (self
== panel
->mstyB
[0]) {
1653 panel
->menuStyle
= MSTYLE_NORMAL
;
1654 updatePreviewBox(panel
, 1<<PMITEM
);
1656 } else if (self
== panel
->mstyB
[1]) {
1657 panel
->menuStyle
= MSTYLE_SINGLE
;
1658 updatePreviewBox(panel
, 1<<PMITEM
);
1660 } else if (self
== panel
->mstyB
[2]) {
1661 panel
->menuStyle
= MSTYLE_FLAT
;
1662 updatePreviewBox(panel
, 1<<PMITEM
);
1668 titleAlignCallback(WMWidget
*self
, void *data
)
1670 _Panel
*panel
= (_Panel
*)data
;
1672 if (self
== panel
->taliB
[0]) {
1673 panel
->titleAlignment
= WALeft
;
1674 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1676 } else if (self
== panel
->taliB
[1]) {
1677 panel
->titleAlignment
= WACenter
;
1678 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1680 } else if (self
== panel
->taliB
[2]) {
1681 panel
->titleAlignment
= WARight
;
1682 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1688 createPanel(Panel
*p
)
1690 _Panel
*panel
= (_Panel
*)p
;
1692 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1693 WMTabViewItem
*item
;
1698 panel
->fprefix
= wstrconcat(wusergnusteppath(), "/.AppInfo");
1700 if (access(panel
->fprefix
, F_OK
)!=0) {
1701 if (mkdir(panel
->fprefix
, 0755) < 0) {
1702 wsyserror(panel
->fprefix
);
1707 tmp
= wstrconcat(panel
->fprefix
, "/WPrefs/");
1708 wfree(panel
->fprefix
);
1709 panel
->fprefix
= tmp
;
1710 if (access(panel
->fprefix
, F_OK
)!=0) {
1711 if (mkdir(panel
->fprefix
, 0755) < 0) {
1712 wsyserror(panel
->fprefix
);
1717 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1718 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1719 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1721 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1722 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1723 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1725 panel
->box
= WMCreateBox(panel
->parent
);
1726 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 0, 0);
1729 panel
->prevL
= WMCreateLabel(panel
->box
);
1730 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1731 WMMoveWidget(panel
->prevL
, 15, 10);
1732 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1733 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1735 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1736 previewClick
, panel
);
1741 tabviewDelegate
.data
= panel
;
1743 panel
->tabv
= WMCreateTabView(panel
->box
);
1744 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1745 WMMoveWidget(panel
->tabv
, 265, 10);
1746 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1748 /*** texture list ***/
1750 panel
->texF
= WMCreateFrame(panel
->box
);
1751 WMSetFrameRelief(panel
->texF
, WRFlat
);
1753 item
= WMCreateTabViewItemWithIdentifier(0);
1754 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1755 WMSetTabViewItemLabel(item
, _("Texture"));
1757 WMAddItemInTabView(panel
->tabv
, item
);
1760 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1761 WMResizeWidget(panel
->secP
, 228, 20);
1762 WMMoveWidget(panel
->secP
, 7, 7);
1763 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1764 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1765 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1766 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1767 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1768 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1769 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1770 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1772 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1773 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1775 panel
->texLs
= WMCreateList(panel
->texF
);
1776 WMResizeWidget(panel
->texLs
, 165, 155);
1777 WMMoveWidget(panel
->texLs
, 70, 33);
1778 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1779 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1780 WMHangData(panel
->texLs
, panel
);
1781 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1782 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1784 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1785 "for the selected item."),
1786 WMWidgetView(panel
->texLs
));
1788 /* command buttons */
1790 font
= WMSystemFontOfSize(scr
, 10);
1793 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1794 WMResizeWidget(panel
->newB
, 57, 39);
1795 WMMoveWidget(panel
->newB
, 7, 33);
1796 WMSetButtonFont(panel
->newB
, font
);
1797 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1798 WMSetButtonText(panel
->newB
, _("New"));
1799 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1800 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
, NULL
, NULL
);
1802 WMSetBalloonTextForView(_("Create a new texture."),
1803 WMWidgetView(panel
->newB
));
1805 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1806 WMResizeWidget(panel
->ripB
, 57, 39);
1807 WMMoveWidget(panel
->ripB
, 7, 72);
1808 WMSetButtonFont(panel
->ripB
, font
);
1809 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1810 WMSetButtonText(panel
->ripB
, _("Extract..."));
1811 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1812 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
, NULL
, NULL
);
1814 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1815 WMWidgetView(panel
->ripB
));
1817 WMSetButtonEnabled(panel
->ripB
, False
);
1819 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1820 WMResizeWidget(panel
->editB
, 57, 39);
1821 WMMoveWidget(panel
->editB
, 7, 111);
1822 WMSetButtonFont(panel
->editB
, font
);
1823 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1824 WMSetButtonText(panel
->editB
, _("Edit"));
1825 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
, NULL
, NULL
);
1826 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1827 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1828 WMWidgetView(panel
->editB
));
1830 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1831 WMResizeWidget(panel
->delB
, 57, 38);
1832 WMMoveWidget(panel
->delB
, 7, 150);
1833 WMSetButtonFont(panel
->delB
, font
);
1834 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1835 WMSetButtonText(panel
->delB
, _("Delete"));
1836 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
, NULL
, NULL
);
1837 WMSetButtonEnabled(panel
->delB
, False
);
1838 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1839 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1840 WMWidgetView(panel
->delB
));
1842 WMReleaseFont(font
);
1844 WMMapSubwidgets(panel
->texF
);
1847 panel
->colF
= WMCreateFrame(panel
->box
);
1848 WMSetFrameRelief(panel
->colF
, WRFlat
);
1850 item
= WMCreateTabViewItemWithIdentifier(1);
1851 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1852 WMSetTabViewItemLabel(item
, _("Color"));
1854 WMAddItemInTabView(panel
->tabv
, item
);
1856 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1857 WMResizeWidget(panel
->colP
, 228, 20);
1858 WMMoveWidget(panel
->colP
, 7, 7);
1859 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Title"));
1860 WMAddPopUpButtonItem(panel
->colP
, _("Unfocused Window Title"));
1861 WMAddPopUpButtonItem(panel
->colP
, _("Owner of Focused Window Title"));
1862 WMAddPopUpButtonItem(panel
->colP
, _("Menu Title"));
1863 WMAddPopUpButtonItem(panel
->colP
, _("Menu Item Text"));
1864 WMAddPopUpButtonItem(panel
->colP
, _("Disabled Menu Item Text"));
1865 WMAddPopUpButtonItem(panel
->colP
, _("Menu Highlight Color"));
1866 WMAddPopUpButtonItem(panel
->colP
, _("Highlighted Menu Text Color"));
1868 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1869 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1870 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1871 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1874 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1876 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1879 panel
->colW
= WMCreateColorWell(panel
->colF
);
1880 WMResizeWidget(panel
->colW
, 65, 50);
1881 WMMoveWidget(panel
->colW
, 30, 75);
1882 WMAddNotificationObserver(colorWellObserver
, panel
,
1883 WMColorWellDidChangeNotification
, panel
->colW
);
1885 for (i
= 0; i
< 4; i
++) {
1887 for (j
= 0; j
< 6; j
++) {
1888 panel
->sampW
[i
+j
*4] = WMCreateColorWell(panel
->colF
);
1889 WMResizeWidget(panel
->sampW
[i
+j
*4], 22, 22);
1890 WMMoveWidget(panel
->sampW
[i
+j
*4], 130 + i
*22, 40 + j
*22);
1891 WSetColorWellBordered(panel
->sampW
[i
+j
*4], False
);
1895 WMMapSubwidgets(panel
->colF
);
1900 panel
->bgF
= WMCreateFrame(panel
->box
);
1901 WMSetFrameRelief(panel
->bgF
, WRFlat
);
1903 item
= WMCreateTabViewItemWithIdentifier(2);
1904 WMSetTabViewItemView(item
, WMWidgetView(panel
->bgF
));
1905 WMSetTabViewItemLabel(item
, _("Background"));
1907 WMAddItemInTabView(panel
->tabv
, item
);
1909 panel
->bgprevL
= WMCreateLabel(panel
->bgF
);
1910 WMResizeWidget(panel
->bgprevL
, 230, 155);
1911 WMMoveWidget(panel
->bgprevL
, 5, 5);
1912 WMSetLabelRelief(panel
->bgprevL
, WRSunken
);
1914 panel
->selbgB
= WMCreateCommandButton(panel
->bgF
);
1915 WMMoveWidget(panel
->selbgB
, 5, 165);
1916 WMResizeWidget(panel
->selbgB
, 100, 24);
1917 WMSetButtonText(panel
->selbgB
, _("Browse..."));
1922 WMMapSubwidgets(panel
->bgF
);
1923 #endif /* unfinished */
1925 panel
->optF
= WMCreateFrame(panel
->box
);
1926 WMSetFrameRelief(panel
->optF
, WRFlat
);
1928 item
= WMCreateTabViewItemWithIdentifier(3);
1929 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1930 WMSetTabViewItemLabel(item
, _("Options"));
1932 WMAddItemInTabView(panel
->tabv
, item
);
1934 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1935 WMResizeWidget(panel
->mstyF
, 215, 85);
1936 WMMoveWidget(panel
->mstyF
, 15, 10);
1937 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1939 for (i
= 0; i
< 3; i
++) {
1943 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1944 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1945 WMMoveWidget(panel
->mstyB
[i
], 15 + i
*65, 20);
1946 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1947 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1950 path
= LocateImage(MSTYLE1_FILE
);
1953 path
= LocateImage(MSTYLE2_FILE
);
1956 path
= LocateImage(MSTYLE3_FILE
);
1960 icon
= WMCreatePixmapFromFile(scr
, path
);
1962 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1963 WMReleasePixmap(icon
);
1965 wwarning(_("could not load icon file %s"), path
);
1970 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1971 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1973 WMMapSubwidgets(panel
->mstyF
);
1976 panel
->taliF
= WMCreateFrame(panel
->optF
);
1977 WMResizeWidget(panel
->taliF
, 110, 80);
1978 WMMoveWidget(panel
->taliF
, 15, 100);
1979 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
1981 for (i
= 0; i
< 3; i
++) {
1982 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
1983 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
1986 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1989 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1992 WMSetButtonText(panel
->taliB
[i
], _("Right"));
1995 WMResizeWidget(panel
->taliB
[i
], 90, 18);
1996 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20*i
);
1998 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
1999 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
2001 WMMapSubwidgets(panel
->taliF
);
2003 WMMapSubwidgets(panel
->optF
);
2007 WMRealizeWidget(panel
->box
);
2008 WMMapSubwidgets(panel
->box
);
2010 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
2014 changePage(panel
->secP
, panel
);
2016 fillTextureList(panel
->texLs
);
2018 fillColorList(panel
);
2020 panel
->texturePanel
= CreateTexturePanel(panel
->parent
);
2026 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
2030 TextureListItem
*titem
;
2032 titem
= wmalloc(sizeof(TextureListItem
));
2033 memset(titem
, 0, sizeof(TextureListItem
));
2035 titem
->title
= wstrdup(title
);
2036 titem
->prop
= GetObjectForKey(key
);
2037 if (!titem
->prop
|| !PLIsArray(titem
->prop
)) {
2038 /* Maybe also give a error message to stderr that the entry is bad? */
2039 titem
->prop
= PLGetProplistWithDescription(defValue
);
2041 PLRetain(titem
->prop
);
2043 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
2045 titem
->selectedFor
= 1<<index
;
2047 titem
->ispixmap
= isPixmap(titem
->prop
);
2049 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
2050 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
2052 item
= WMAddListItem(list
, "");
2053 item
->clientData
= titem
;
2059 showData(_Panel
*panel
)
2064 str
= GetStringForKey("MenuStyle");
2065 if (str
&& strcasecmp(str
, "flat")==0) {
2066 panel
->menuStyle
= MSTYLE_FLAT
;
2067 } else if (str
&& strcasecmp(str
, "singletexture")==0) {
2068 panel
->menuStyle
= MSTYLE_SINGLE
;
2070 panel
->menuStyle
= MSTYLE_NORMAL
;
2073 str
= GetStringForKey("TitleJustify");
2074 if (str
&& strcasecmp(str
, "left")==0) {
2075 panel
->titleAlignment
= WALeft
;
2076 } else if (str
&& strcasecmp(str
, "right")==0) {
2077 panel
->titleAlignment
= WARight
;
2079 panel
->titleAlignment
= WACenter
;
2082 for (i
= 0; i
< sizeof(colorOptions
)/(2*sizeof(char*)); i
++) {
2085 str
= GetStringForKey(colorOptions
[i
*2]);
2087 str
= colorOptions
[i
*2+1];
2089 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), str
, False
))) {
2090 color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), "#000000", False
);
2093 panel
->colors
[i
] = color
;
2095 changeColorPage(panel
->colP
, panel
);
2097 for (i
= 0; i
< sizeof(textureOptions
)/(3*sizeof(char*)); i
++) {
2098 setupTextureFor(panel
->texLs
, textureOptions
[i
*3],
2099 textureOptions
[i
*3+1], textureOptions
[i
*3+2], i
);
2100 panel
->textureIndex
[i
] = i
;
2102 updatePreviewBox(panel
, EVERYTHING
);
2104 WMSetButtonSelected(panel
->mstyB
[panel
->menuStyle
], True
);
2105 WMSetButtonSelected(panel
->taliB
[panel
->titleAlignment
], True
);
2110 storeData(_Panel
*panel
)
2112 TextureListItem
*titem
;
2116 for (i
= 0; i
< sizeof(textureOptions
)/(sizeof(char*)*3); i
++) {
2117 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
2118 titem
= (TextureListItem
*)item
->clientData
;
2119 SetObjectForKey(titem
->prop
, textureOptions
[i
*3]);
2122 for (i
= 0; i
< 8; i
++) {
2125 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
2128 SetStringForKey(str
, colorOptions
[i
*2]);
2133 switch (panel
->menuStyle
) {
2135 SetStringForKey("singletexture", "MenuStyle");
2138 SetStringForKey("flat", "MenuStyle");
2142 SetStringForKey("normal", "MenuStyle");
2145 switch (panel
->titleAlignment
) {
2147 SetStringForKey("left", "TitleJustify");
2150 SetStringForKey("right", "TitleJustify");
2154 SetStringForKey("center", "TitleJustify");
2161 prepareForClose(_Panel
*panel
)
2163 proplist_t textureList
;
2165 TextureListItem
*titem
;
2167 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2170 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
2172 /* store list of textures */
2173 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2174 item
= WMGetListItem(panel
->texLs
, i
);
2175 titem
= (TextureListItem
*)item
->clientData
;
2177 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
2178 PLRetain(titem
->prop
),
2179 PLMakeString(titem
->path
),
2182 PLAppendArrayElement(textureList
, texture
);
2185 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2186 PLRelease(textureList
);
2188 /* store list of colors */
2189 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
2190 for (i
= 0; i
< 24; i
++) {
2194 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2196 str
= WMGetColorRGBDescription(color
);
2197 PLAppendArrayElement(textureList
, PLMakeString(str
));
2200 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2201 PLRelease(textureList
);
2203 WMSynchronizeUserDefaults(udb
);
2209 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
2213 panel
= wmalloc(sizeof(_Panel
));
2214 memset(panel
, 0, sizeof(_Panel
));
2216 panel
->sectionName
= _("Appearance Preferences");
2218 panel
->description
= _("Background texture configuration for windows,\n"
2219 "menus and icons.");
2221 panel
->parent
= win
;
2223 panel
->callbacks
.createWidgets
= createPanel
;
2224 panel
->callbacks
.updateDomain
= storeData
;
2225 panel
->callbacks
.prepareForClose
= prepareForClose
;
2227 AddSection(panel
, ICON_FILE
);
2234 /****************************************************************************/
2238 typedef struct ExtractPanel
{
2251 OpenExtractPanelFor(_Panel
*panel
, char *path
)
2253 ExtractPanel
*epanel
;
2256 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
2258 epanel
= wmalloc(sizeof(ExtractPanel
));
2259 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->parent
, "extract",
2261 |WMClosableWindowMask
);
2262 WMResizeWidget(epanel
->win
, 245, 250);
2263 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2265 epanel
->label
= WMCreateLabel(epanel
->win
);
2266 WMResizeWidget(epanel
->label
, 225, 18);
2267 WMMoveWidget(epanel
->label
, 10, 10);
2268 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2269 WMSetLabelRelief(epanel
->label
, WRSunken
);
2271 color
= WMDarkGrayColor(scr
);
2272 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2273 WMReleaseColor(color
);
2275 color
= WMWhiteColor(scr
);
2276 WMSetLabelTextColor(epanel
->label
, color
);
2277 WMReleaseColor(color
);
2279 font
= WMBoldSystemFontOfSize(scr
, 12);
2280 WMSetLabelFont(epanel
->label
, font
);
2281 WMReleaseFont(font
);
2283 WMSetLabelText(epanel
->label
, _("Textures"));
2285 epanel
->list
= WMCreateList(epanel
->win
);
2286 WMResizeWidget(epanel
->list
, 225, 165);
2287 WMMoveWidget(epanel
->list
, 10, 30);
2291 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2292 WMResizeWidget(epanel
->closeB
, 74, 24);
2293 WMMoveWidget(epanel
->closeB
, 165, 215);
2294 WMSetButtonText(epanel
->closeB
, _("Close"));
2296 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2297 WMResizeWidget(epanel
->extrB
, 74, 24);
2298 WMMoveWidget(epanel
->extrB
, 80, 215);
2299 WMSetButtonText(epanel
->extrB
, _("Extract"));
2301 WMMapSubwidgets(epanel
->win
);
2304 /* take textures from file */
2308 WMRealizeWidget(epanel
->win
);
2310 WMMapWidget(epanel
->win
);