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 */
230 static char * hand_xpm
[] = {
254 " .%%%&@.......... ",
255 " .%*%%&#%%%%%%%%%$. ",
256 " .*#%%%%%%%%%&&&&==. ",
257 " .-%%%%%%%%%=*-;;;#$. ",
258 " .-%%%%%%%%&..>..... ",
275 static char *sampleColors
[] = {
304 static char *textureOptions
[] = {
305 "FTitleBack", "(solid, black)", "[Focused]",
306 "UTitleBack", "(solid, gray)", "[Unfocused]",
307 "PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
308 "ResizebarBack", "(solid, gray)", "[Resizebar]",
309 "MenuTitleBack", "(solid, black)", "[Menu Title]",
310 "MenuTextBack", "(solid, gray)", "[Menu Item]",
311 "IconBack", "(solid, gray)", "[Icon]"
315 #define RESIZEBAR_BEVEL -1
316 #define MENU_BEVEL -2
318 #define TEXPREV_WIDTH 40
319 #define TEXPREV_HEIGHT 24
322 #define MSTYLE_NORMAL 0
323 #define MSTYLE_SINGLE 1
324 #define MSTYLE_FLAT 2
327 #define FTITLE_COL (1<<0)
328 #define UTITLE_COL (1<<1)
329 #define OTITLE_COL (1<<2)
330 #define MTITLE_COL (1<<3)
331 #define MITEM_COL (1<<4)
332 #define MDISAB_COL (1<<5)
333 #define MHIGH_COL (1<<6)
334 #define MHIGHT_COL (1<<7)
335 #define ICONT_COL (1<<8)
336 #define ICONB_COL (1<<9)
337 #define CLIP_COL (1<<10)
338 #define CCLIP_COL (1<<11)
341 static char *colorOptions
[] = {
342 "FTitleColor", "white",
343 "UTitleColor", "black",
344 "PTitleColor", "white",
345 "MenuTitleColor", "white",
346 "MenuTextColor", "black",
347 "MenuDisabledColor", "#616161",
348 "HighlightColor", "white",
349 "HighlightTextColor", "black",
350 "IconTitleColor", "white",
351 "IconTitleBack", "black",
352 "ClipTitleColor", "black",
353 "CClipTitleColor", "#454045"
359 static WMRect previewPositions
[] = {
371 {{30,140},{90,20*4}},
375 #define EVERYTHING 0xff
378 static WMRect previewColorPositions
[] = {
396 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
400 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
403 color
->red
= xcolor
.red
>> 8;
404 color
->green
= xcolor
.green
>> 8;
405 color
->blue
= xcolor
.blue
>> 8;
410 dumpRImage(char *path
, RImage
*image
)
413 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
415 f
= fopen(path
, "w");
420 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
, channels
);
422 fwrite(image
->data
, 1, image
->width
* image
->height
* channels
, f
);
432 isPixmap(proplist_t prop
)
437 p
= PLGetArrayElement(prop
, 0);
439 if (strcasecmp(&s
[1], "pixmap")==0)
446 /**********************************************************************/
449 drawResizebarBevel(RImage
*img
)
454 int width
= img
->width
;
455 int height
= img
->height
;
459 black
.red
= black
.green
= black
.blue
= 0;
462 light
.red
= light
.green
= light
.blue
= 80;
465 dark
.red
= dark
.green
= dark
.blue
= 40;
467 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
468 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
470 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
471 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
473 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
475 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
478 RDrawLine(img
, 0, height
-1, width
-1, height
-1, &black
);
479 RDrawLine(img
, 0, 0, 0, height
-1, &black
);
480 RDrawLine(img
, width
-1, 0, width
-1, height
-1, &black
);
485 drawMenuBevel(RImage
*img
)
487 RColor light
, dark
, mid
;
489 int iheight
= img
->height
/ 4;
492 light
.red
= light
.green
= light
.blue
= 80;
495 dark
.red
= dark
.green
= dark
.blue
= 0;
498 mid
.red
= mid
.green
= mid
.blue
= 40;
500 for (i
= 1; i
< 4; i
++) {
501 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
502 img
->width
-1, i
*iheight
-2, &mid
);
504 RDrawLine(img
, 0, i
*iheight
-1, img
->width
-1, i
*iheight
-1, &dark
);
506 ROperateLine(img
, RAddOperation
, 1, i
*iheight
,
507 img
->width
-2, i
*iheight
, &light
);
513 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
514 char *path
, int border
)
517 RImage
*image
= NULL
;
519 RContext
*rc
= WMScreenRContext(scr
);
524 type
= PLGetString(PLGetArrayElement(texture
, 0));
526 if (strcasecmp(type
, "solid")==0) {
528 str
= PLGetString(PLGetArrayElement(texture
, 1));
530 str2rcolor(rc
, str
, &rcolor
);
532 image
= RCreateImage(width
, height
, False
);
533 RClearImage(image
, &rcolor
);
534 } else if (strcasecmp(&type
[1], "gradient")==0) {
538 switch (toupper(type
[0])) {
540 style
= RVerticalGradient
;
543 style
= RHorizontalGradient
;
547 style
= RDiagonalGradient
;
551 str
= PLGetString(PLGetArrayElement(texture
, 1));
552 str2rcolor(rc
, str
, &rcolor
);
553 str
= PLGetString(PLGetArrayElement(texture
, 2));
554 str2rcolor(rc
, str
, &rcolor2
);
556 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
557 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
561 RImage
*grad
, *timage
;
564 switch (toupper(type
[1])) {
566 style
= RVerticalGradient
;
569 style
= RHorizontalGradient
;
573 style
= RDiagonalGradient
;
577 str
= PLGetString(PLGetArrayElement(texture
, 3));
578 str2rcolor(rc
, str
, &rcolor
);
579 str
= PLGetString(PLGetArrayElement(texture
, 4));
580 str2rcolor(rc
, str
, &rcolor2
);
582 str
= PLGetString(PLGetArrayElement(texture
, 1));
584 if ((path
=wfindfileinarray(GetObjectForKey("PixmapPath"), str
))!=NULL
)
585 timage
= RLoadImage(rc
, path
, 0);
587 if (!path
|| !timage
) {
588 wwarning("could not load file '%s': %s", path
,
589 RMessageForError(RErrorCode
));
591 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
593 image
= RMakeTiledImage(timage
, width
, height
);
594 RDestroyImage(timage
);
596 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
598 RCombineImagesWithOpaqueness(image
, grad
, i
);
601 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
606 switch (toupper(type
[1])) {
608 style
= RVerticalGradient
;
611 style
= RHorizontalGradient
;
615 style
= RDiagonalGradient
;
619 j
= PLGetNumberOfElements(texture
);
622 colors
= wmalloc(j
* sizeof(RColor
*));
624 for (i
= 2; i
< j
; i
++) {
625 str
= PLGetString(PLGetArrayElement(texture
, i
));
626 colors
[i
-2] = wmalloc(sizeof(RColor
));
627 str2rcolor(rc
, str
, colors
[i
-2]);
631 image
= RRenderMultiGradient(width
, height
, colors
, style
);
633 for (i
= 0; colors
[i
]!=NULL
; i
++)
637 } else if (strcasecmp(&type
[1], "pixmap")==0) {
638 RImage
*timage
= NULL
;
642 str
= PLGetString(PLGetArrayElement(texture
, 1));
644 if ((path
=wfindfileinarray(GetObjectForKey("PixmapPath"), str
))!=NULL
)
645 timage
= RLoadImage(rc
, path
, 0);
647 if (!path
|| !timage
) {
648 wwarning("could not load file '%s': %s", path
? path
: str
,
649 RMessageForError(RErrorCode
));
651 str
= PLGetString(PLGetArrayElement(texture
, 2));
652 str2rcolor(rc
, str
, &color
);
654 switch (toupper(type
[0])) {
656 image
= RMakeTiledImage(timage
, width
, height
);
657 RDestroyImage(timage
);
661 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
662 RDestroyImage(timage
);
667 image
= RScaleImage(timage
, width
, height
);
668 RDestroyImage(timage
);
681 dumpRImage(path
, image
);
685 if (border
== RESIZEBAR_BEVEL
) {
686 drawResizebarBevel(image
);
687 } else if (border
== MENU_BEVEL
) {
688 drawMenuBevel(image
);
689 RBevelImage(image
, RBEV_RAISED2
);
692 RBevelImage(image
, border
);
695 RConvertImage(rc
, image
, &pixmap
);
696 RDestroyImage(image
);
703 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
705 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
706 Display
*dpy
= WMScreenDisplay(scr
);
708 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
711 switch (panel
->menuStyle
) {
713 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
715 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*4, WMScreenDepth(scr
));
716 for (i
= 0; i
< 4; i
++) {
717 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
*i
);
719 XFreePixmap(dpy
, tmp
);
722 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, MENU_BEVEL
);
725 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, RBEV_RAISED2
);
735 renderPreview(_Panel
*panel
, GC gc
, int part
, int relief
)
738 TextureListItem
*titem
;
740 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
742 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
743 titem
= (TextureListItem
*)item
->clientData
;
745 pix
= renderTexture(scr
, titem
->prop
,
746 previewPositions
[part
].size
.width
,
747 previewPositions
[part
].size
.height
,
750 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
751 previewPositions
[part
].size
.width
,
752 previewPositions
[part
].size
.height
,
753 previewPositions
[part
].pos
.x
,
754 previewPositions
[part
].pos
.y
);
756 XFreePixmap(WMScreenDisplay(scr
), pix
);
761 updatePreviewBox(_Panel
*panel
, int elements
)
763 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
764 Display
*dpy
= WMScreenDisplay(scr
);
765 /* RContext *rc = WMScreenRContext(scr);*/
770 WMColor
*black
= WMBlackColor(scr
);
772 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
775 if (panel
->preview
== None
) {
778 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
779 240-4, 215-4, WMScreenDepth(scr
));
781 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
782 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
784 WMReleaseColor(color
);
790 if (elements
& (1<<PFOCUSED
)) {
791 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
792 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
793 previewPositions
[PFOCUSED
].pos
.x
-1,
794 previewPositions
[PFOCUSED
].pos
.y
-1,
795 previewPositions
[PFOCUSED
].size
.width
,
796 previewPositions
[PFOCUSED
].size
.height
);
797 colorUpdate
|= FTITLE_COL
;
799 if (elements
& (1<<PUNFOCUSED
)) {
800 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
801 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
802 previewPositions
[PUNFOCUSED
].pos
.x
-1,
803 previewPositions
[PUNFOCUSED
].pos
.y
-1,
804 previewPositions
[PUNFOCUSED
].size
.width
,
805 previewPositions
[PUNFOCUSED
].size
.height
);
806 colorUpdate
|= UTITLE_COL
;
808 if (elements
& (1<<POWNER
)) {
809 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
810 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
811 previewPositions
[POWNER
].pos
.x
-1,
812 previewPositions
[POWNER
].pos
.y
-1,
813 previewPositions
[POWNER
].size
.width
,
814 previewPositions
[POWNER
].size
.height
);
815 colorUpdate
|= OTITLE_COL
;
817 if (elements
& (1<<PRESIZEBAR
)) {
818 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
820 if (elements
& (1<<PMTITLE
)) {
821 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
822 colorUpdate
|= MTITLE_COL
;
824 if (elements
& (1<<PMITEM
)) {
826 TextureListItem
*titem
;
828 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
829 titem
= (TextureListItem
*)item
->clientData
;
831 pix
= renderMenu(panel
, titem
->prop
,
832 previewPositions
[PMITEM
].size
.width
,
833 previewPositions
[PMITEM
].size
.height
/4);
835 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
836 previewPositions
[PMITEM
].size
.width
,
837 previewPositions
[PMITEM
].size
.height
,
838 previewPositions
[PMITEM
].pos
.x
,
839 previewPositions
[PMITEM
].pos
.y
);
841 XFreePixmap(dpy
, pix
);
843 colorUpdate
|= MITEM_COL
|MDISAB_COL
|MHIGH_COL
|MHIGHT_COL
;
845 if (elements
& (1<<PMITEM
|1<<PMTITLE
)) {
846 XDrawLine(dpy
, panel
->preview
, gc
, 29, 120, 29, 120+20*4+20);
847 XDrawLine(dpy
, panel
->preview
, gc
, 29, 119, 119, 119);
849 if (elements
& (1<<PICON
)) {
851 TextureListItem
*titem
;
853 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
854 titem
= (TextureListItem
*)item
->clientData
;
856 renderPreview(panel
, gc
, PICON
,
857 titem
->ispixmap
? 0 : RBEV_RAISED3
);
859 colorUpdate
|= ICONT_COL
|ICONB_COL
|CLIP_COL
|CCLIP_COL
;
864 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
865 240-4, 215-4, WMScreenDepth(scr
));
867 WMSetLabelImage(panel
->prevL
, p
);
871 updateColorPreviewBox(panel
, colorUpdate
);
874 updateColorPreviewBox(panel
, colorUpdate
);
876 WMRedisplayWidget(panel
->prevL
);
880 WMReleaseColor(black
);
887 cancelNewTexture(void *data
)
889 _Panel
*panel
= (_Panel
*)data
;
891 HideTexturePanel(panel
->texturePanel
);
898 makeFileName(char *prefix
)
902 fname
= wstrdup(prefix
);
904 while (access(fname
, F_OK
)==0) {
908 sprintf(buf
, "%08lx.cache", time(NULL
));
909 fname
= wstrappend(prefix
, buf
);
919 okNewTexture(void *data
)
921 _Panel
*panel
= (_Panel
*)data
;
926 TextureListItem
*titem
;
927 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
929 titem
= wmalloc(sizeof(TextureListItem
));
930 memset(titem
, 0, sizeof(TextureListItem
));
932 HideTexturePanel(panel
->texturePanel
);
934 name
= GetTexturePanelTextureName(panel
->texturePanel
);
936 prop
= GetTexturePanelTexture(panel
->texturePanel
);
938 str
= PLGetDescription(prop
);
942 titem
->texture
= str
;
943 titem
->selectedFor
= 0;
945 titem
->ispixmap
= isPixmap(prop
);
947 titem
->path
= makeFileName(panel
->fprefix
);
948 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
951 item
= WMAddListItem(panel
->texLs
, "");
952 item
->clientData
= titem
;
954 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
959 okEditTexture(void *data
)
961 _Panel
*panel
= (_Panel
*)data
;
966 TextureListItem
*titem
;
968 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
969 titem
= (TextureListItem
*)item
->clientData
;
971 HideTexturePanel(panel
->texturePanel
);
973 if (titem
->current
) {
974 name
= GetTexturePanelTextureName(panel
->texturePanel
);
980 prop
= GetTexturePanelTexture(panel
->texturePanel
);
982 str
= PLGetDescription(prop
);
984 PLRelease(titem
->prop
);
987 titem
->ispixmap
= isPixmap(prop
);
989 free(titem
->texture
);
990 titem
->texture
= str
;
992 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
993 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
994 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
997 WMRedisplayWidget(panel
->texLs
);
999 if (titem
->selectedFor
)
1000 updatePreviewBox(panel
, titem
->selectedFor
);
1002 changePage(panel
->secP
, panel
);
1008 editTexture(WMWidget
*w
, void *data
)
1010 _Panel
*panel
= (_Panel
*)data
;
1012 TextureListItem
*titem
;
1014 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
1015 titem
= (TextureListItem
*)item
->clientData
;
1017 SetTexturePanelPixmapPath(panel
->texturePanel
,
1018 GetObjectForKey("PixmapPath"));
1020 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
1022 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
1023 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
1025 ShowTexturePanel(panel
->texturePanel
);
1031 newTexture(WMWidget
*w
, void *data
)
1033 _Panel
*panel
= (_Panel
*)data
;
1035 SetTexturePanelPixmapPath(panel
->texturePanel
,
1036 GetObjectForKey("PixmapPath"));
1038 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
1040 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
1042 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
1044 ShowTexturePanel(panel
->texturePanel
);
1050 deleteTexture(WMWidget
*w
, void *data
)
1052 _Panel
*panel
= (_Panel
*)data
;
1054 TextureListItem
*titem
;
1058 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1059 row
= WMGetListSelectedItemRow(panel
->texLs
);
1060 item
= WMGetListItem(panel
->texLs
, row
);
1061 titem
= (TextureListItem
*)item
->clientData
;
1063 if (titem
->selectedFor
& (1 << section
)) {
1064 TextureListItem
*titem2
;
1066 panel
->textureIndex
[section
] = section
;
1067 item
= WMGetListItem(panel
->texLs
, section
);
1068 titem2
= (TextureListItem
*)item
->clientData
;
1069 titem2
->selectedFor
|= 1 << section
;
1073 free(titem
->texture
);
1074 PLRelease(titem
->prop
);
1076 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1077 wsyserror("could not remove file %s", titem
->path
);
1084 WMRemoveListItem(panel
->texLs
, row
);
1085 WMSetButtonEnabled(panel
->delB
, False
);
1092 extractTexture(WMWidget
*w
, void *data
)
1094 _Panel
*panel
= (_Panel
*)data
;
1096 WMOpenPanel
*opanel
;
1097 WMScreen
*scr
= WMWidgetScreen(w
);
1099 opanel
= WMGetOpenPanel(scr
);
1100 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1101 WMSetFilePanelCanChooseFiles(opanel
, True
);
1103 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
1104 _("Select File"), NULL
)) {
1105 path
= WMGetFilePanelFileName(opanel
);
1107 OpenExtractPanelFor(panel
, path
);
1115 changePage(WMWidget
*w
, void *data
)
1117 _Panel
*panel
= (_Panel
*)data
;
1120 TextureListItem
*titem
;
1121 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1122 RContext
*rc
= WMScreenRContext(scr
);
1123 static WMPoint positions
[] = {
1134 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1136 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1138 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1140 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1142 titem
= (TextureListItem
*)item
->clientData
;
1147 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1148 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1149 positions
[panel
->oldsection
].x
,
1150 positions
[panel
->oldsection
].y
, 22, 22);
1151 WMReleaseColor(color
);
1154 panel
->oldsection
= section
;
1155 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1156 positions
[section
].y
);
1158 WMRedisplayWidget(panel
->prevL
);
1164 previewClick(XEvent
*event
, void *clientData
)
1166 _Panel
*panel
= (_Panel
*)clientData
;
1169 switch (panel
->oldTabItem
) {
1171 for (i
= 0; i
< sizeof(previewPositions
)/sizeof(WMRect
); i
++) {
1172 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
1173 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
1174 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
1175 + previewPositions
[i
].size
.width
1176 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
1177 + previewPositions
[i
].size
.height
) {
1179 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1180 changePage(panel
->secP
, panel
);
1186 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1187 if (event
->xbutton
.x
>= previewColorPositions
[i
].pos
.x
1188 && event
->xbutton
.y
>= previewColorPositions
[i
].pos
.y
1189 && event
->xbutton
.x
< previewColorPositions
[i
].pos
.x
1190 + previewColorPositions
[i
].size
.width
1191 && event
->xbutton
.y
< previewColorPositions
[i
].pos
.y
1192 + previewColorPositions
[i
].size
.height
) {
1198 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1199 changeColorPage(panel
->colP
, panel
);
1209 textureClick(WMWidget
*w
, void *data
)
1211 _Panel
*panel
= (_Panel
*)data
;
1214 TextureListItem
*titem
;
1216 i
= WMGetListSelectedItemRow(panel
->texLs
);
1218 item
= WMGetListItem(panel
->texLs
, i
);
1220 titem
= (TextureListItem
*)item
->clientData
;
1222 if (titem
->current
) {
1223 WMSetButtonEnabled(panel
->delB
, False
);
1225 WMSetButtonEnabled(panel
->delB
, True
);
1232 textureDoubleClick(WMWidget
*w
, void *data
)
1234 _Panel
*panel
= (_Panel
*)data
;
1237 TextureListItem
*titem
;
1239 /* unselect old texture */
1240 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1242 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1243 titem
= (TextureListItem
*)item
->clientData
;
1244 titem
->selectedFor
&= ~(1 << section
);
1246 /* select new texture */
1247 i
= WMGetListSelectedItemRow(panel
->texLs
);
1249 item
= WMGetListItem(panel
->texLs
, i
);
1251 titem
= (TextureListItem
*)item
->clientData
;
1253 titem
->selectedFor
|= 1<<section
;
1255 panel
->textureIndex
[section
] = i
;
1257 WMRedisplayWidget(panel
->texLs
);
1259 updatePreviewBox(panel
, 1<<section
);
1265 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
1268 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
1269 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1270 int width
, height
, x
, y
;
1271 Display
*dpy
= WMScreenDisplay(scr
);
1272 WMColor
*white
= WMWhiteColor(scr
);
1274 WMColor
*black
= WMBlackColor(scr
);
1275 TextureListItem
*titem
;
1277 item
= WMGetListItem(lPtr
, index
);
1278 titem
= (TextureListItem
*)item
->clientData
;
1280 WMReleaseColor(white
);
1281 WMReleaseColor(black
);
1285 width
= rect
->size
.width
;
1286 height
= rect
->size
.height
;
1290 if (state
& WLDSSelected
)
1291 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1293 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
1297 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0,
1298 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1300 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1301 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1302 else if (titem
->selectedFor
)
1303 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1305 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
1306 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
1307 strlen(titem
->title
));
1309 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
1310 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
1311 strlen(titem
->texture
));
1314 WMReleaseColor(white
);
1315 WMReleaseColor(black
);
1321 loadRImage(WMScreen
*scr
, char *path
)
1328 f
= fopen(path
, "r");
1332 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1334 image
= RCreateImage(w
, h
, d
== 4);
1335 fread(image
->data
, 1, w
*h
*d
, f
);
1338 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1339 RDestroyImage(image
);
1347 fillTextureList(WMList
*lPtr
)
1349 proplist_t textureList
;
1351 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1352 TextureListItem
*titem
;
1353 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1356 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1360 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1363 texture
= PLGetArrayElement(textureList
, i
);
1365 titem
= wmalloc(sizeof(TextureListItem
));
1366 memset(titem
, 0, sizeof(TextureListItem
));
1368 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1369 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1370 titem
->texture
= PLGetDescription(titem
->prop
);
1371 titem
->selectedFor
= 0;
1372 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1374 titem
->preview
= loadRImage(scr
, titem
->path
);
1375 if (!titem
->preview
) {
1376 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1377 TEXPREV_HEIGHT
, NULL
, 0);
1379 item
= WMAddListItem(lPtr
, "");
1380 item
->clientData
= titem
;
1386 fillColorList(_Panel
*panel
)
1390 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1391 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1394 list
= WMGetUDObjectForKey(udb
, "ColorList");
1396 for (i
= 0; i
< 24; i
++) {
1397 color
= WMCreateNamedColor(scr
, sampleColors
[i
], False
);
1400 WMSetColorWellColor(panel
->sampW
[i
], color
);
1401 WMReleaseColor(color
);
1406 for (i
= 0; i
< WMIN(24, PLGetNumberOfElements(list
)); i
++) {
1407 c
= PLGetArrayElement(list
, i
);
1408 if (!c
|| !PLIsString(c
))
1410 color
= WMCreateNamedColor(scr
, PLGetString(c
), False
);
1413 WMSetColorWellColor(panel
->sampW
[i
], color
);
1414 WMReleaseColor(color
);
1420 /*************************************************************************/
1424 changeColorPage(WMWidget
*w
, void *data
)
1426 _Panel
*panel
= (_Panel
*)data
;
1428 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1429 RContext
*rc
= WMScreenRContext(scr
);
1430 static WMPoint positions
[] = {
1445 if (panel
->preview
) {
1448 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1449 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1450 positions
[panel
->oldcsection
].x
,
1451 positions
[panel
->oldcsection
].y
, 22, 22);
1452 WMReleaseColor(color
);
1455 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1457 panel
->oldcsection
= section
;
1459 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1460 positions
[section
].y
);
1462 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1464 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1466 WMRedisplayWidget(panel
->prevL
);
1471 paintText(WMScreen
*scr
, Drawable d
, WMColor
*color
, WMFont
*font
,
1472 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1474 int l
= strlen(text
);
1481 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1485 x
+= (w
- WMWidthOfString(font
, text
, l
))/2;
1488 WMDrawString(scr
, d
, WMColorGC(color
), font
, x
,
1489 y
+ (h
- WMFontHeight(font
))/2, text
, l
);
1495 updateColorPreviewBox(_Panel
*panel
, int elements
)
1497 WMScreen
*scr
= WMWidgetScreen(panel
->frame
);
1501 pixmap
= WMGetLabelImage(panel
->prevL
);
1502 d
= WMGetPixmapXID(pixmap
);
1504 if (elements
& FTITLE_COL
) {
1505 paintText(scr
, d
, panel
->colors
[0], panel
->boldFont
, 30, 10, 190, 20,
1506 panel
->titleAlignment
, _("Focused Window"));
1508 if (elements
& UTITLE_COL
) {
1509 paintText(scr
, d
, panel
->colors
[1], panel
->boldFont
, 30, 40, 190, 20,
1510 panel
->titleAlignment
, _("Unfocused Window"));
1512 if (elements
& OTITLE_COL
) {
1513 paintText(scr
, d
, panel
->colors
[2], panel
->boldFont
, 30, 70, 190, 20,
1514 panel
->titleAlignment
, _("Owner of Focused Window"));
1516 if (elements
& MTITLE_COL
) {
1517 paintText(scr
, d
, panel
->colors
[3], panel
->boldFont
, 30, 120, 90, 20,
1518 WALeft
, _("Menu Title"));
1520 if (elements
& MITEM_COL
) {
1521 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 140, 90, 20,
1522 WALeft
, _("Normal Item"));
1523 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 200, 90, 20,
1524 WALeft
, _("Normal Item"));
1526 if (elements
& MDISAB_COL
) {
1527 paintText(scr
, d
, panel
->colors
[5], panel
->normalFont
, 30, 160, 90, 20,
1528 WALeft
, _("Disabled Item"));
1530 if (elements
& MHIGH_COL
) {
1531 XFillRectangle(WMScreenDisplay(scr
), d
, WMColorGC(panel
->colors
[6]),
1533 elements
|= MHIGHT_COL
;
1535 if (elements
& MHIGHT_COL
) {
1536 paintText(scr
, d
, panel
->colors
[7], panel
->normalFont
, 30, 180, 90, 20,
1537 WALeft
, _("Highlighted"));
1540 if (elements & ICONT_COL) {
1541 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1544 if (elements & ICONB_COL) {
1545 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1548 if (elements & CLIP_COL) {
1549 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1552 if (elements & CCLIP_COL) {
1553 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1557 WMRedisplayWidget(panel
->prevL
);
1562 colorWellObserver(void *self
, WMNotification
*n
)
1564 _Panel
*panel
= (_Panel
*)self
;
1567 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1569 WMReleaseColor(panel
->colors
[p
]);
1571 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1573 updateColorPreviewBox(panel
, 1<<p
);
1578 changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
*tabView
,
1579 WMTabViewItem
*item
)
1581 _Panel
*panel
= self
->data
;
1584 i
= WMGetTabViewItemIdentifier(item
);
1587 switch (panel
->oldTabItem
) {
1589 changeColorPage(NULL
, panel
);
1592 changePage(panel
->secP
, panel
);
1595 switch (panel
->oldTabItem
) {
1597 changePage(NULL
, panel
);
1600 changeColorPage(panel
->colP
, panel
);
1603 switch (panel
->oldTabItem
) {
1605 changePage(NULL
, panel
);
1608 changeColorPage(NULL
, panel
);
1614 panel
->oldTabItem
= i
;
1618 /*************************************************************************/
1621 menuStyleCallback(WMWidget
*self
, void *data
)
1623 _Panel
*panel
= (_Panel
*)data
;
1625 if (self
== panel
->mstyB
[0]) {
1626 panel
->menuStyle
= MSTYLE_NORMAL
;
1627 updatePreviewBox(panel
, 1<<PMITEM
);
1629 } else if (self
== panel
->mstyB
[1]) {
1630 panel
->menuStyle
= MSTYLE_SINGLE
;
1631 updatePreviewBox(panel
, 1<<PMITEM
);
1633 } else if (self
== panel
->mstyB
[2]) {
1634 panel
->menuStyle
= MSTYLE_FLAT
;
1635 updatePreviewBox(panel
, 1<<PMITEM
);
1641 titleAlignCallback(WMWidget
*self
, void *data
)
1643 _Panel
*panel
= (_Panel
*)data
;
1645 if (self
== panel
->taliB
[0]) {
1646 panel
->titleAlignment
= WALeft
;
1647 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1649 } else if (self
== panel
->taliB
[1]) {
1650 panel
->titleAlignment
= WACenter
;
1651 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1653 } else if (self
== panel
->taliB
[2]) {
1654 panel
->titleAlignment
= WARight
;
1655 updatePreviewBox(panel
, 1<<PFOCUSED
|1<<PUNFOCUSED
|1<<POWNER
);
1661 createPanel(Panel
*p
)
1663 _Panel
*panel
= (_Panel
*)p
;
1665 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1666 WMTabViewItem
*item
;
1671 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
1673 if (access(panel
->fprefix
, F_OK
)!=0) {
1674 if (mkdir(panel
->fprefix
, 0755) < 0) {
1675 wsyserror(panel
->fprefix
);
1680 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
1681 free(panel
->fprefix
);
1682 panel
->fprefix
= tmp
;
1683 if (access(panel
->fprefix
, F_OK
)!=0) {
1684 if (mkdir(panel
->fprefix
, 0755) < 0) {
1685 wsyserror(panel
->fprefix
);
1690 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1691 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1692 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1694 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1695 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1696 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1698 panel
->frame
= WMCreateFrame(panel
->win
);
1699 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1700 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1703 panel
->prevL
= WMCreateLabel(panel
->frame
);
1704 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1705 WMMoveWidget(panel
->prevL
, 15, 10);
1706 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1707 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1709 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1710 previewClick
, panel
);
1715 tabviewDelegate
.data
= panel
;
1717 panel
->tabv
= WMCreateTabView(panel
->frame
);
1718 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1719 WMMoveWidget(panel
->tabv
, 265, 10);
1720 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1722 /*** texture list ***/
1724 panel
->texF
= WMCreateFrame(panel
->frame
);
1725 WMSetFrameRelief(panel
->texF
, WRFlat
);
1727 item
= WMCreateTabViewItemWithIdentifier(0);
1728 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1729 WMSetTabViewItemLabel(item
, _("Texture"));
1731 WMAddItemInTabView(panel
->tabv
, item
);
1734 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1735 WMResizeWidget(panel
->secP
, 228, 20);
1736 WMMoveWidget(panel
->secP
, 7, 7);
1737 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1738 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1739 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1740 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1741 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1742 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1743 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1744 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1746 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1747 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1749 panel
->texLs
= WMCreateList(panel
->texF
);
1750 WMResizeWidget(panel
->texLs
, 165, 155);
1751 WMMoveWidget(panel
->texLs
, 70, 33);
1752 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1753 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1754 WMHangData(panel
->texLs
, panel
);
1755 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1756 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1758 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1759 "for the selected item."),
1760 WMWidgetView(panel
->texLs
));
1762 /* command buttons */
1764 font
= WMSystemFontOfSize(scr
, 10);
1767 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1768 WMResizeWidget(panel
->newB
, 57, 39);
1769 WMMoveWidget(panel
->newB
, 7, 33);
1770 WMSetButtonFont(panel
->newB
, font
);
1771 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1772 WMSetButtonText(panel
->newB
, _("New"));
1773 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1774 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1776 WMSetBalloonTextForView(_("Create a new texture."),
1777 WMWidgetView(panel
->newB
));
1779 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1780 WMResizeWidget(panel
->ripB
, 57, 39);
1781 WMMoveWidget(panel
->ripB
, 7, 72);
1782 WMSetButtonFont(panel
->ripB
, font
);
1783 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1784 WMSetButtonText(panel
->ripB
, _("Extract..."));
1785 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1786 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1788 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1789 WMWidgetView(panel
->ripB
));
1791 WMSetButtonEnabled(panel
->ripB
, False
);
1793 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1794 WMResizeWidget(panel
->editB
, 57, 39);
1795 WMMoveWidget(panel
->editB
, 7, 111);
1796 WMSetButtonFont(panel
->editB
, font
);
1797 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1798 WMSetButtonText(panel
->editB
, _("Edit"));
1799 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1800 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1801 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1802 WMWidgetView(panel
->editB
));
1804 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1805 WMResizeWidget(panel
->delB
, 57, 38);
1806 WMMoveWidget(panel
->delB
, 7, 150);
1807 WMSetButtonFont(panel
->delB
, font
);
1808 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1809 WMSetButtonText(panel
->delB
, _("Delete"));
1810 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1811 WMSetButtonEnabled(panel
->delB
, False
);
1812 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1813 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1814 WMWidgetView(panel
->delB
));
1816 WMReleaseFont(font
);
1818 WMMapSubwidgets(panel
->texF
);
1821 panel
->colF
= WMCreateFrame(panel
->frame
);
1822 WMSetFrameRelief(panel
->colF
, WRFlat
);
1824 item
= WMCreateTabViewItemWithIdentifier(1);
1825 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1826 WMSetTabViewItemLabel(item
, _("Color"));
1828 WMAddItemInTabView(panel
->tabv
, item
);
1830 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1831 WMResizeWidget(panel
->colP
, 228, 20);
1832 WMMoveWidget(panel
->colP
, 7, 7);
1833 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Title"));
1834 WMAddPopUpButtonItem(panel
->colP
, _("Unfocused Window Title"));
1835 WMAddPopUpButtonItem(panel
->colP
, _("Owner of Focused Window Title"));
1836 WMAddPopUpButtonItem(panel
->colP
, _("Menu Title"));
1837 WMAddPopUpButtonItem(panel
->colP
, _("Menu Item Text"));
1838 WMAddPopUpButtonItem(panel
->colP
, _("Disabled Menu Item Text"));
1839 WMAddPopUpButtonItem(panel
->colP
, _("Menu Highlight Color"));
1840 WMAddPopUpButtonItem(panel
->colP
, _("Highlighted Menu Text Color"));
1842 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1843 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1844 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1845 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1848 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1850 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1853 panel
->colW
= WMCreateColorWell(panel
->colF
);
1854 WMResizeWidget(panel
->colW
, 65, 50);
1855 WMMoveWidget(panel
->colW
, 30, 75);
1856 WMAddNotificationObserver(colorWellObserver
, panel
,
1857 WMColorWellDidChangeNotification
, panel
->colW
);
1859 for (i
= 0; i
< 4; i
++) {
1861 for (j
= 0; j
< 6; j
++) {
1862 panel
->sampW
[i
+j
*4] = WMCreateColorWell(panel
->colF
);
1863 WMResizeWidget(panel
->sampW
[i
+j
*4], 22, 22);
1864 WMMoveWidget(panel
->sampW
[i
+j
*4], 130 + i
*22, 40 + j
*22);
1865 WSetColorWellBordered(panel
->sampW
[i
+j
*4], False
);
1869 WMMapSubwidgets(panel
->colF
);
1872 panel
->optF
= WMCreateFrame(panel
->frame
);
1873 WMSetFrameRelief(panel
->optF
, WRFlat
);
1875 item
= WMCreateTabViewItemWithIdentifier(2);
1876 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1877 WMSetTabViewItemLabel(item
, _("Options"));
1879 WMAddItemInTabView(panel
->tabv
, item
);
1881 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1882 WMResizeWidget(panel
->mstyF
, 215, 85);
1883 WMMoveWidget(panel
->mstyF
, 15, 10);
1884 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1886 for (i
= 0; i
< 3; i
++) {
1890 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1891 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1892 WMMoveWidget(panel
->mstyB
[i
], 15 + i
*65, 20);
1893 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1894 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1897 path
= LocateImage(MSTYLE1_FILE
);
1900 path
= LocateImage(MSTYLE2_FILE
);
1903 path
= LocateImage(MSTYLE3_FILE
);
1907 icon
= WMCreatePixmapFromFile(scr
, path
);
1909 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1910 WMReleasePixmap(icon
);
1912 wwarning(_("could not load icon file %s"), path
);
1917 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1918 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1920 WMMapSubwidgets(panel
->mstyF
);
1923 panel
->taliF
= WMCreateFrame(panel
->optF
);
1924 WMResizeWidget(panel
->taliF
, 110, 80);
1925 WMMoveWidget(panel
->taliF
, 15, 100);
1926 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
1928 for (i
= 0; i
< 3; i
++) {
1929 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
1930 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
1933 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1936 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1939 WMSetButtonText(panel
->taliB
[i
], _("Right"));
1942 WMResizeWidget(panel
->taliB
[i
], 90, 18);
1943 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20*i
);
1945 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
1946 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
1948 WMMapSubwidgets(panel
->taliF
);
1950 WMMapSubwidgets(panel
->optF
);
1954 WMRealizeWidget(panel
->frame
);
1955 WMMapSubwidgets(panel
->frame
);
1957 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1961 changePage(panel
->secP
, panel
);
1963 fillTextureList(panel
->texLs
);
1965 fillColorList(panel
);
1967 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1973 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1977 TextureListItem
*titem
;
1979 titem
= wmalloc(sizeof(TextureListItem
));
1980 memset(titem
, 0, sizeof(TextureListItem
));
1982 titem
->title
= wstrdup(title
);
1983 titem
->prop
= GetObjectForKey(key
);
1984 if (!titem
->prop
|| !PLIsArray(titem
->prop
)) {
1985 /* Maybe also give a error message to stderr that the entry is bad? */
1986 titem
->prop
= PLGetProplistWithDescription(defValue
);
1988 PLRetain(titem
->prop
);
1990 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1992 titem
->selectedFor
= 1<<index
;
1994 titem
->ispixmap
= isPixmap(titem
->prop
);
1996 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1997 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1999 item
= WMAddListItem(list
, "");
2000 item
->clientData
= titem
;
2006 showData(_Panel
*panel
)
2011 str
= GetStringForKey("MenuStyle");
2012 if (str
&& strcasecmp(str
, "flat")==0) {
2013 panel
->menuStyle
= MSTYLE_FLAT
;
2014 } else if (str
&& strcasecmp(str
, "singletexture")==0) {
2015 panel
->menuStyle
= MSTYLE_SINGLE
;
2017 panel
->menuStyle
= MSTYLE_NORMAL
;
2020 str
= GetStringForKey("TitleJustify");
2021 if (str
&& strcasecmp(str
, "left")==0) {
2022 panel
->titleAlignment
= WALeft
;
2023 } else if (str
&& strcasecmp(str
, "right")==0) {
2024 panel
->titleAlignment
= WARight
;
2026 panel
->titleAlignment
= WACenter
;
2029 for (i
= 0; i
< sizeof(colorOptions
)/(2*sizeof(char*)); i
++) {
2032 str
= GetStringForKey(colorOptions
[i
*2]);
2034 str
= colorOptions
[i
*2+1];
2036 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->frame
), str
, False
))) {
2037 color
= WMCreateNamedColor(WMWidgetScreen(panel
->frame
), "#000000", False
);
2040 panel
->colors
[i
] = color
;
2042 changeColorPage(panel
->colP
, panel
);
2044 for (i
= 0; i
< sizeof(textureOptions
)/(3*sizeof(char*)); i
++) {
2045 setupTextureFor(panel
->texLs
, textureOptions
[i
*3],
2046 textureOptions
[i
*3+1], textureOptions
[i
*3+2], i
);
2047 panel
->textureIndex
[i
] = i
;
2049 updatePreviewBox(panel
, EVERYTHING
);
2052 for (i
= 0; i
< 3; i
++) {
2053 WMSetButtonSelected(panel
->mstyB
[i
], i
==panel
->menuStyle
);
2054 WMSetButtonSelected(panel
->taliB
[i
], i
==panel
->titleAlignment
);
2061 storeData(_Panel
*panel
)
2063 TextureListItem
*titem
;
2067 for (i
= 0; i
< sizeof(textureOptions
)/(sizeof(char*)*3); i
++) {
2068 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
2069 titem
= (TextureListItem
*)item
->clientData
;
2070 SetObjectForKey(titem
->prop
, textureOptions
[i
*3]);
2073 for (i
= 0; i
< 8; i
++) {
2076 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
2079 SetStringForKey(str
, colorOptions
[i
*2]);
2084 switch (panel
->menuStyle
) {
2086 SetStringForKey("singletexture", "MenuStyle");
2089 SetStringForKey("flat", "MenuStyle");
2093 SetStringForKey("normal", "MenuStyle");
2096 switch (panel
->titleAlignment
) {
2098 SetStringForKey("left", "TitleJustify");
2101 SetStringForKey("right", "TitleJustify");
2105 SetStringForKey("center", "TitleJustify");
2112 prepareForClose(_Panel
*panel
)
2114 proplist_t textureList
;
2116 TextureListItem
*titem
;
2118 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2121 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
2123 /* store list of textures */
2124 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2125 item
= WMGetListItem(panel
->texLs
, i
);
2126 titem
= (TextureListItem
*)item
->clientData
;
2128 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
2129 PLRetain(titem
->prop
),
2130 PLMakeString(titem
->path
),
2133 PLAppendArrayElement(textureList
, texture
);
2136 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2137 PLRelease(textureList
);
2139 /* store list of colors */
2140 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
2141 for (i
= 0; i
< 24; i
++) {
2145 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2147 str
= WMGetColorRGBDescription(color
);
2148 PLAppendArrayElement(textureList
, PLMakeString(str
));
2151 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2152 PLRelease(textureList
);
2154 WMSynchronizeUserDefaults(udb
);
2160 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
2164 panel
= wmalloc(sizeof(_Panel
));
2165 memset(panel
, 0, sizeof(_Panel
));
2167 panel
->sectionName
= _("Appearance Preferences");
2169 panel
->description
= _("Background texture configuration for windows,\n"
2170 "menus and icons.");
2174 panel
->callbacks
.createWidgets
= createPanel
;
2175 panel
->callbacks
.updateDomain
= storeData
;
2176 panel
->callbacks
.prepareForClose
= prepareForClose
;
2178 AddSection(panel
, ICON_FILE
);
2185 /****************************************************************************/
2189 typedef struct ExtractPanel
{
2202 OpenExtractPanelFor(_Panel
*panel
, char *path
)
2204 ExtractPanel
*epanel
;
2207 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
2209 epanel
= wmalloc(sizeof(ExtractPanel
));
2210 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
2212 |WMClosableWindowMask
);
2213 WMResizeWidget(epanel
->win
, 245, 250);
2214 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2216 epanel
->label
= WMCreateLabel(epanel
->win
);
2217 WMResizeWidget(epanel
->label
, 225, 18);
2218 WMMoveWidget(epanel
->label
, 10, 10);
2219 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2220 WMSetLabelRelief(epanel
->label
, WRSunken
);
2222 color
= WMDarkGrayColor(scr
);
2223 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2224 WMReleaseColor(color
);
2226 color
= WMWhiteColor(scr
);
2227 WMSetLabelTextColor(epanel
->label
, color
);
2228 WMReleaseColor(color
);
2230 font
= WMBoldSystemFontOfSize(scr
, 12);
2231 WMSetLabelFont(epanel
->label
, font
);
2232 WMReleaseFont(font
);
2234 WMSetLabelText(epanel
->label
, _("Textures"));
2236 epanel
->list
= WMCreateList(epanel
->win
);
2237 WMResizeWidget(epanel
->list
, 225, 165);
2238 WMMoveWidget(epanel
->list
, 10, 30);
2242 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2243 WMResizeWidget(epanel
->closeB
, 74, 24);
2244 WMMoveWidget(epanel
->closeB
, 165, 215);
2245 WMSetButtonText(epanel
->closeB
, _("Close"));
2247 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2248 WMResizeWidget(epanel
->extrB
, 74, 24);
2249 WMMoveWidget(epanel
->extrB
, 80, 215);
2250 WMSetButtonText(epanel
->extrB
, _("Extract"));
2252 WMMapSubwidgets(epanel
->win
);
2255 /* take textures from file */
2259 WMRealizeWidget(epanel
->win
);
2261 WMMapWidget(epanel
->win
);