1 /* Apperance.c- color/texture for titlebar etc.
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1999-2003 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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <sys/types.h>
33 #include "TexturePanel.h"
38 const char *default_value
;
40 WMRect preview
; /* The rectangle where the corresponding object is displayed */
41 WMPoint hand
; /* The coordinate where the hand is drawn when pointing this item */
43 /* Related to Window titles */
44 { "FTitleColor", "white", N_("Focused Window Title"),
45 { { 30, 10 }, { 190, 20 } }, { 5, 10 } },
46 { "UTitleColor", "black", N_("Unfocused Window Title"),
47 { { 30, 40 }, { 190, 20 } }, { 5, 40 } },
48 { "PTitleColor", "white", N_("Owner of Focused Window Title"),
49 { { 30, 70 }, { 190, 20 } }, { 5, 70 } },
51 /* Related to Menus */
52 { "MenuTitleColor", "white", N_("Menu Title") ,
53 { { 30, 120 }, { 90, 20 } }, { 5, 120 } },
54 { "MenuTextColor", "black", N_("Menu Item Text") ,
55 { { 30, 140 }, { 90, 20 } }, { 5, 140 } },
56 { "MenuDisabledColor", "#616161", N_("Disabled Menu Item Text") ,
57 { { 30, 160 }, { 90, 20 } }, { 5, 160 } },
58 { "HighlightColor", "white", N_("Menu Highlight Color") ,
59 { { 30, 180 }, { 90, 20 } }, { 5, 180 } },
60 { "HighlightTextColor", "black", N_("Highlighted Menu Text Color") ,
61 { { 30, 200 }, { 90, 20 } }, { 5, 180 } },
63 * yuck kluge: the coordinate for HighlightTextColor are actually those of the last "Normal item"
64 * at the bottom when user clicks it, the "yuck kluge" in the function 'previewClick' will swap it
65 * for the MenuTextColor selection as user would expect
67 * Note that the entries are reffered by their index for performance
70 /* Related to Window's border */
71 { "FrameFocusedBorderColor", "black", N_("Focused Window Border Color") ,
72 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
73 { "FrameBorderColor", "black", N_("Window Border Color") ,
74 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
75 { "FrameSelectedBorderColor", "white", N_("Selected Window Border Color") ,
76 { { 0, 0 }, { 0, 0 } }, { -22, -21 } },
78 /* Related to Icons and Clip */
79 { "IconTitleColor", "white", N_("Miniwindow Title") ,
80 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
81 { "IconTitleBack", "black", N_("Miniwindow Title Back") ,
82 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
83 { "ClipTitleColor", "black", N_("Clip Title") ,
84 { { 155, 130 }, { 64, 64 } }, { 130, 132 } },
85 { "CClipTitleColor", "#454045", N_("Collapsed Clip Title") ,
86 { { 155, 130 }, { 64, 64 } }, { 130, 132 } }
89 /********************************************************************/
98 const char *file_name
;
100 [MSTYLE_NORMAL
] = { "normal", "msty1" },
101 [MSTYLE_SINGLE
] = { "singletexture", "msty2" },
102 [MSTYLE_FLAT
] = { "flat", "msty3" }
105 /********************************************************************/
106 static const struct {
108 const char *db_value
;
109 } wintitle_align
[] = {
110 [WALeft
] = { N_("Left"), "left" },
111 [WACenter
] = { N_("Center"), "center" },
112 [WARight
] = { N_("Right"), "right" }
115 /********************************************************************/
116 static const char *const sample_colors
[] = {
143 /********************************************************************/
144 typedef struct _Panel
{
150 CallbackRec callbacks
;
173 WMColor
*colors
[wlengthof_nocheck(colorOptions
)];
177 WMColorWell
*sampW
[wlengthof_nocheck(sample_colors
)];
183 WMButton
*mstyB
[wlengthof_nocheck(menu_style
)];
186 WMButton
*taliB
[wlengthof_nocheck(wintitle_align
)];
196 TexturePanel
*texturePanel
;
207 menu_style_index menuStyle
;
209 WMAlignment titleAlignment
;
212 Pixmap previewNoText
;
237 static void updateColorPreviewBox(_Panel
* panel
, int elements
);
239 static void showData(_Panel
* panel
);
241 static void changePage(WMWidget
* w
, void *data
);
243 static void changeColorPage(WMWidget
* w
, void *data
);
245 static void OpenExtractPanelFor(_Panel
*panel
);
247 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
);
249 static WMTabViewDelegate tabviewDelegate
= {
251 NULL
, /* didChangeNumberOfItems */
252 changedTabItem
, /* didSelectItem */
253 NULL
, /* shouldSelectItem */
254 NULL
/* willSelectItem */
257 #define ICON_FILE "appearance"
259 #define TNEW_FILE "tnew"
260 #define TDEL_FILE "tdel"
261 #define TEDIT_FILE "tedit"
262 #define TEXTR_FILE "textr"
265 static char *blueled_xpm
[] = {
295 static char *blueled2_xpm
[] = {
296 /* width height num_colors chars_per_pixel */
328 static char *hand_xpm
[] = {
352 " .%%%&@.......... ",
353 " .%*%%&#%%%%%%%%%$. ",
354 " .*#%%%%%%%%%&&&&==. ",
355 " .-%%%%%%%%%=*-;;;#$. ",
356 " .-%%%%%%%%&..>..... ",
372 static const struct {
374 const char *default_value
;
375 const char *texture_label
; /* text used when displaying the list of textures */
376 WMRect preview
; /* The rectangle where the corresponding object is displayed */
377 WMPoint hand
; /* The coordinate where the hand is drawn when pointing this item */
378 const char *popup_label
; /* text used for the popup button with the list of editable items */
379 } textureOptions
[] = {
382 { "FTitleBack", "(solid, black)", N_("[Focused]"),
383 { { 30, 10 }, { 190, 20 } }, { 5, 10 }, N_("Titlebar of Focused Window") },
386 { "UTitleBack", "(solid, gray)", N_("[Unfocused]"),
387 { { 30, 40 }, { 190, 20 } }, { 5, 40 }, N_("Titlebar of Unfocused Windows") },
390 { "PTitleBack", "(solid, \"#616161\")", N_("[Owner of Focused]"),
391 { { 30, 70 }, { 190, 20 } }, { 5, 70 }, N_("Titlebar of Focused Window's Owner") },
394 { "ResizebarBack", "(solid, gray)", N_("[Resizebar]"),
395 { { 30, 100 }, { 190, 9 } }, { 5, 100 }, N_("Window Resizebar") },
398 { "MenuTitleBack", "(solid, black)", N_("[Menu Title]"),
399 { { 30, 120 }, { 90, 20 } }, { 5, 120 }, N_("Titlebar of Menus") },
402 { "MenuTextBack", "(solid, gray)", N_("[Menu Item]"),
403 { { 30, 140 }, { 90, 20 * 4 } }, { 5, 160 }, N_("Menu Items") },
406 { "IconBack", "(solid, gray)", N_("[Icon]"),
407 { { 155, 130 }, { 64, 64 } }, { 130, 150 }, N_("Icon Background") },
409 #define PBACKGROUND 7
410 { "WorkspaceBack", "(solid, black)", N_("[Background]"),
411 { { -1, -1}, { 0, 0 } }, { -22, -21 }, N_("Workspace Background") }
413 #define EVERYTHING 0xff
417 RESIZEBAR_BEVEL
= -1,
445 static void str2rcolor(RContext
* rc
, const char *name
, RColor
* color
)
449 if (XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
) != 0) {
451 color
->red
= xcolor
.red
>> 8;
452 color
->green
= xcolor
.green
>> 8;
453 color
->blue
= xcolor
.blue
>> 8;
455 /* Color Name was not found - Return white instead */
463 static void dumpRImage(const char *path
, RImage
* image
)
466 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
468 f
= fopen(path
, "wb");
473 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
, channels
);
475 fwrite(image
->data
, 1, image
->width
* image
->height
* channels
, f
);
483 static int isPixmap(WMPropList
* prop
)
488 p
= WMGetFromPLArray(prop
, 0);
489 s
= WMGetFromPLString(p
);
490 if (strcasecmp(&s
[1], "pixmap") == 0)
496 /**********************************************************************/
498 static void drawResizebarBevel(RImage
* img
)
502 int width
= img
->width
;
503 int height
= img
->height
;
507 light
.red
= light
.green
= light
.blue
= 80;
510 dark
.red
= dark
.green
= dark
.blue
= 40;
512 ROperateLine(img
, RSubtractOperation
, 0, 0, width
- 1, 0, &dark
);
513 ROperateLine(img
, RAddOperation
, 0, 1, width
- 1, 1, &light
);
515 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
- 1, &dark
);
516 ROperateLine(img
, RAddOperation
, cwidth
+ 1, 2, cwidth
+ 1, height
- 1, &light
);
518 ROperateLine(img
, RSubtractOperation
, width
- cwidth
- 2, 2, width
- cwidth
- 2, height
- 1, &dark
);
519 ROperateLine(img
, RAddOperation
, width
- cwidth
- 1, 2, width
- cwidth
- 1, height
- 1, &light
);
523 static void drawMenuBevel(RImage
* img
)
525 RColor light
, dark
, mid
;
527 int iheight
= img
->height
/ 4;
530 light
.red
= light
.green
= light
.blue
= 80;
533 dark
.red
= dark
.green
= dark
.blue
= 0;
536 mid
.red
= mid
.green
= mid
.blue
= 40;
538 for (i
= 1; i
< 4; i
++) {
539 ROperateLine(img
, RSubtractOperation
, 0, i
* iheight
- 2, img
->width
- 1, i
* iheight
- 2, &mid
);
541 RDrawLine(img
, 0, i
* iheight
- 1, img
->width
- 1, i
* iheight
- 1, &dark
);
543 ROperateLine(img
, RAddOperation
, 1, i
* iheight
, img
->width
- 2, i
* iheight
, &light
);
547 static Pixmap
renderTexture(WMScreen
* scr
, WMPropList
* texture
, int width
, int height
, const char *path
, int border
)
550 RImage
*image
= NULL
;
551 RImage
*timage
= NULL
;
553 RContext
*rc
= WMScreenRContext(scr
);
557 type
= WMGetFromPLString(WMGetFromPLArray(texture
, 0));
559 if (strcasecmp(&type
[1], "pixmap") == 0 ||
560 (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'T')) {
563 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
564 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
566 timage
= RLoadImage(rc
, path
, 0);
568 wwarning(_("could not load file '%s': %s"), path
, RMessageForError(RErrorCode
));
571 wwarning(_("could not find file '%s' for texture type %s"), str
, type
);
575 texture
= WMCreatePropListFromDescription("(solid, black)");
580 if (strcasecmp(type
, "solid") == 0) {
582 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
584 str2rcolor(rc
, str
, &rcolor
);
586 image
= RCreateImage(width
, height
, False
);
587 RClearImage(image
, &rcolor
);
588 } else if (strcasecmp(type
, "igradient") == 0) {
592 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
593 str2rcolor(rc
, str
, &c1
[0]);
594 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
595 str2rcolor(rc
, str
, &c1
[1]);
596 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
599 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
600 str2rcolor(rc
, str
, &c2
[0]);
601 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 5));
602 str2rcolor(rc
, str
, &c2
[1]);
603 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 6));
606 image
= RRenderInterwovenGradient(width
, height
, c1
, t1
, c2
, t2
);
607 } else if (strcasecmp(&type
[1], "gradient") == 0) {
608 RGradientStyle style
;
611 switch (toupper(type
[0])) {
613 style
= RVerticalGradient
;
616 style
= RHorizontalGradient
;
619 wwarning(_("unknown direction in '%s', falling back to diagonal"), type
);
622 style
= RDiagonalGradient
;
626 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
627 str2rcolor(rc
, str
, &rcolor
);
628 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
629 str2rcolor(rc
, str
, &rcolor2
);
631 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
632 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'T') {
633 RGradientStyle style
;
638 switch (toupper(type
[1])) {
640 style
= RVerticalGradient
;
643 style
= RHorizontalGradient
;
646 wwarning(_("unknown direction in '%s', falling back to diagonal"), type
);
649 style
= RDiagonalGradient
;
653 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
654 str2rcolor(rc
, str
, &rcolor
);
655 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
656 str2rcolor(rc
, str
, &rcolor2
);
658 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
660 image
= RMakeTiledImage(timage
, width
, height
);
661 RReleaseImage(timage
);
663 i
= atoi(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
665 RCombineImagesWithOpaqueness(image
, grad
, i
);
668 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'M') {
669 RGradientStyle style
;
673 switch (toupper(type
[1])) {
675 style
= RVerticalGradient
;
678 style
= RHorizontalGradient
;
681 wwarning(_("unknown direction in '%s', falling back to diagonal"), type
);
684 style
= RDiagonalGradient
;
688 j
= WMGetPropListItemCount(texture
);
691 colors
= wmalloc(j
* sizeof(RColor
*));
693 for (i
= 2; i
< j
; i
++) {
694 str
= WMGetFromPLString(WMGetFromPLArray(texture
, i
));
695 colors
[i
- 2] = wmalloc(sizeof(RColor
));
696 str2rcolor(rc
, str
, colors
[i
- 2]);
698 colors
[i
- 2] = NULL
;
700 image
= RRenderMultiGradient(width
, height
, colors
, style
);
702 for (i
= 0; colors
[i
] != NULL
; i
++)
706 } else if (strcasecmp(&type
[1], "pixmap") == 0) {
709 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
710 str2rcolor(rc
, str
, &color
);
712 switch (toupper(type
[0])) {
714 image
= RMakeTiledImage(timage
, width
, height
);
715 RReleaseImage(timage
);
718 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
719 RReleaseImage(timage
);
724 image
= RScaleImage(timage
, width
, height
);
725 RReleaseImage(timage
);
729 wwarning(_("type '%s' is not a supported type for a texture"), type
);
730 RReleaseImage(timage
);
739 dumpRImage(path
, image
);
743 if (border
== RESIZEBAR_BEVEL
) {
744 drawResizebarBevel(image
);
745 } else if (border
== MENU_BEVEL
) {
746 drawMenuBevel(image
);
747 RBevelImage(image
, RBEV_RAISED2
);
750 RBevelImage(image
, border
);
753 RConvertImage(rc
, image
, &pixmap
);
754 RReleaseImage(image
);
759 static Pixmap
renderMenu(_Panel
* panel
, WMPropList
* texture
, int width
, int iheight
)
761 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
762 Display
*dpy
= WMScreenDisplay(scr
);
764 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
767 switch (panel
->menuStyle
) {
769 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
771 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
* 4, WMScreenDepth(scr
));
772 for (i
= 0; i
< 4; i
++) {
773 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
* i
);
775 XFreePixmap(dpy
, tmp
);
778 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, MENU_BEVEL
);
781 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, RBEV_RAISED2
);
791 static void renderPreview(_Panel
* panel
, GC gc
, int part
, int relief
)
794 TextureListItem
*titem
;
796 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
798 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
799 titem
= (TextureListItem
*) item
->clientData
;
801 pix
= renderTexture(scr
, titem
->prop
,
802 textureOptions
[part
].preview
.size
.width
, textureOptions
[part
].preview
.size
.height
,
805 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
806 textureOptions
[part
].preview
.size
.width
, textureOptions
[part
].preview
.size
.height
,
807 textureOptions
[part
].preview
.pos
.x
, textureOptions
[part
].preview
.pos
.y
);
809 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->previewNoText
, gc
, 0, 0,
810 textureOptions
[part
].preview
.size
.width
, textureOptions
[part
].preview
.size
.height
,
811 textureOptions
[part
].preview
.pos
.x
, textureOptions
[part
].preview
.pos
.y
);
813 XFreePixmap(WMScreenDisplay(scr
), pix
);
816 static void updatePreviewBox(_Panel
* panel
, int elements
)
818 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
819 Display
*dpy
= WMScreenDisplay(scr
);
824 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
826 if (panel
->preview
== None
) {
829 panel
->previewNoText
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
830 240 - 4, 215 - 4, WMScreenDepth(scr
));
831 panel
->previewBack
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
832 240 - 4, 215 - 4, WMScreenDepth(scr
));
834 p
= WMCreatePixmap(scr
, 240 - 4, 215 - 4, WMScreenDepth(scr
), False
);
835 panel
->preview
= WMGetPixmapXID(p
);
836 WMSetLabelImage(panel
->prevL
, p
);
839 if (elements
& (1 << PBACKGROUND
)) {
841 TextureListItem
*titem
;
844 item
= WMGetListItem(panel
->texLs
,
845 panel
->textureIndex
[PBACKGROUND
]);
846 titem
= (TextureListItem
*) item
->clientData
;
847 tmp
= renderTexture(scr
, titem
->prop
, 240 - 4, 215 - 4, NULL
, 0);
849 XCopyArea(dpy
, tmp
, panel
->preview
, gc
, 0, 0, 240 - 4, 215 -4 , 0, 0);
850 XCopyArea(dpy
, tmp
, panel
->previewNoText
, gc
, 0, 0, 240 - 4, 215 -4 , 0, 0);
851 XCopyArea(dpy
, tmp
, panel
->previewBack
, gc
, 0, 0, 240 - 4, 215 -4 , 0, 0);
852 XFreePixmap(dpy
, tmp
);
855 if (elements
& (1 << PFOCUSED
)) {
856 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
857 colorUpdate
|= 1 << FTITLE_COL
| 1 << FFBORDER_COL
;
859 if (elements
& (1 << PUNFOCUSED
)) {
860 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
861 colorUpdate
|= 1 << UTITLE_COL
| 1 << FBORDER_COL
;
863 if (elements
& (1 << POWNER
)) {
864 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
865 colorUpdate
|= 1 << OTITLE_COL
| 1 << FBORDER_COL
;
867 if (elements
& (1 << PRESIZEBAR
)) {
868 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
869 colorUpdate
|= 1 << FBORDER_COL
;
871 if (elements
& (1 << PMTITLE
)) {
872 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
873 colorUpdate
|= 1 << MTITLE_COL
| 1 << FBORDER_COL
;
875 if (elements
& (1 << PMITEM
)) {
877 TextureListItem
*titem
;
879 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
880 titem
= (TextureListItem
*) item
->clientData
;
882 pix
= renderMenu(panel
, titem
->prop
,
883 textureOptions
[PMITEM
].preview
.size
.width
,
884 textureOptions
[PMITEM
].preview
.size
.height
/ 4);
886 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
887 textureOptions
[PMITEM
].preview
.size
.width
, textureOptions
[PMITEM
].preview
.size
.height
,
888 textureOptions
[PMITEM
].preview
.pos
.x
, textureOptions
[PMITEM
].preview
.pos
.y
);
890 XCopyArea(dpy
, pix
, panel
->previewNoText
, gc
, 0, 0,
891 textureOptions
[PMITEM
].preview
.size
.width
, textureOptions
[PMITEM
].preview
.size
.height
,
892 textureOptions
[PMITEM
].preview
.pos
.x
, textureOptions
[PMITEM
].preview
.pos
.y
);
894 XFreePixmap(dpy
, pix
);
896 colorUpdate
|= 1 << MITEM_COL
| 1 << MDISAB_COL
|
897 1 << MHIGH_COL
| 1 << MHIGHT_COL
|
900 if (elements
& (1 << PICON
)) {
902 TextureListItem
*titem
;
904 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
905 titem
= (TextureListItem
*) item
->clientData
;
907 renderPreview(panel
, gc
, PICON
, titem
->ispixmap
? 0 : RBEV_RAISED3
);
911 updateColorPreviewBox(panel
, colorUpdate
);
913 WMRedisplayWidget(panel
->prevL
);
918 static void cancelNewTexture(void *data
)
920 _Panel
*panel
= (_Panel
*) data
;
922 HideTexturePanel(panel
->texturePanel
);
925 static char *makeFileName(const 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
);
942 static void okNewTexture(void *data
)
944 _Panel
*panel
= (_Panel
*) data
;
949 TextureListItem
*titem
;
950 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
952 titem
= wmalloc(sizeof(TextureListItem
));
954 HideTexturePanel(panel
->texturePanel
);
956 name
= GetTexturePanelTextureName(panel
->texturePanel
);
958 prop
= GetTexturePanelTexture(panel
->texturePanel
);
960 str
= WMGetPropListDescription(prop
, False
);
964 titem
->texture
= str
;
965 titem
->selectedFor
= 0;
967 titem
->ispixmap
= isPixmap(prop
);
969 titem
->path
= makeFileName(panel
->fprefix
);
970 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
972 item
= WMAddListItem(panel
->texLs
, "");
973 item
->clientData
= titem
;
975 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
978 static void okEditTexture(void *data
)
980 _Panel
*panel
= (_Panel
*) data
;
985 TextureListItem
*titem
;
987 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
988 titem
= (TextureListItem
*) item
->clientData
;
990 HideTexturePanel(panel
->texturePanel
);
992 if (titem
->current
) {
993 name
= GetTexturePanelTextureName(panel
->texturePanel
);
999 prop
= GetTexturePanelTexture(panel
->texturePanel
);
1001 str
= WMGetPropListDescription(prop
, False
);
1003 WMReleasePropList(titem
->prop
);
1006 titem
->ispixmap
= isPixmap(prop
);
1008 wfree(titem
->texture
);
1009 titem
->texture
= str
;
1011 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
1012 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
1013 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
1015 WMRedisplayWidget(panel
->texLs
);
1017 if (titem
->selectedFor
) {
1018 if (titem
->selectedFor
& (1 << PBACKGROUND
))
1019 updatePreviewBox(panel
, EVERYTHING
);
1021 updatePreviewBox(panel
, titem
->selectedFor
);
1024 changePage(panel
->secP
, panel
);
1027 static void editTexture(WMWidget
* w
, void *data
)
1029 _Panel
*panel
= (_Panel
*) data
;
1031 TextureListItem
*titem
;
1033 /* Parameter not used, but tell the compiler that it is ok */
1036 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
1037 titem
= (TextureListItem
*) item
->clientData
;
1039 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
1041 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
1043 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
1044 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
1046 ShowTexturePanel(panel
->texturePanel
);
1049 static void newTexture(WMWidget
* w
, void *data
)
1051 _Panel
*panel
= (_Panel
*) data
;
1053 /* Parameter not used, but tell the compiler that it is ok */
1056 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
1058 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
1060 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
1062 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
1064 ShowTexturePanel(panel
->texturePanel
);
1067 static void deleteTexture(WMWidget
* w
, void *data
)
1069 _Panel
*panel
= (_Panel
*) data
;
1071 TextureListItem
*titem
;
1075 /* Parameter not used, but tell the compiler that it is ok */
1078 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1079 row
= WMGetListSelectedItemRow(panel
->texLs
);
1080 item
= WMGetListItem(panel
->texLs
, row
);
1081 titem
= (TextureListItem
*) item
->clientData
;
1083 if (titem
->selectedFor
& (1 << section
)) {
1084 TextureListItem
*titem2
;
1086 panel
->textureIndex
[section
] = section
;
1087 item
= WMGetListItem(panel
->texLs
, section
);
1088 titem2
= (TextureListItem
*) item
->clientData
;
1089 titem2
->selectedFor
|= 1 << section
;
1092 wfree(titem
->title
);
1093 wfree(titem
->texture
);
1094 WMReleasePropList(titem
->prop
);
1096 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1097 werror(_("could not remove file %s"), titem
->path
);
1104 WMRemoveListItem(panel
->texLs
, row
);
1105 WMSetButtonEnabled(panel
->delB
, False
);
1108 static void extractTexture(WMWidget
* w
, void *data
)
1110 _Panel
*panel
= (_Panel
*) data
;
1112 WMOpenPanel
*opanel
;
1113 WMScreen
*scr
= WMWidgetScreen(w
);
1115 opanel
= WMGetOpenPanel(scr
);
1116 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1117 WMSetFilePanelCanChooseFiles(opanel
, True
);
1119 if (WMRunModalFilePanelForDirectory(opanel
, panel
->parent
, wgethomedir(), _("Select File"), NULL
)) {
1120 path
= WMGetFilePanelFileName(opanel
);
1122 OpenExtractPanelFor(panel
);
1128 static void changePage(WMWidget
* w
, void *data
)
1130 _Panel
*panel
= (_Panel
*) data
;
1132 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1133 RContext
*rc
= WMScreenRContext(scr
);
1136 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1138 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1140 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1145 gc
= XCreateGC(rc
->dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
1146 XCopyArea(rc
->dpy
, panel
->previewBack
, panel
->preview
, gc
,
1147 textureOptions
[panel
->oldsection
].hand
.x
, textureOptions
[panel
->oldsection
].hand
.y
, 22, 22,
1148 textureOptions
[panel
->oldsection
].hand
.x
, textureOptions
[panel
->oldsection
].hand
.y
);
1151 panel
->oldsection
= section
;
1152 WMDrawPixmap(panel
->hand
, panel
->preview
, textureOptions
[section
].hand
.x
, textureOptions
[section
].hand
.y
);
1154 WMRedisplayWidget(panel
->prevL
);
1157 static void previewClick(XEvent
* event
, void *clientData
)
1159 _Panel
*panel
= (_Panel
*) clientData
;
1162 switch (panel
->oldTabItem
) {
1164 for (i
= 0; i
< wlengthof(textureOptions
); i
++) {
1165 if (event
->xbutton
.x
>= textureOptions
[i
].preview
.pos
.x
&&
1166 event
->xbutton
.y
>= textureOptions
[i
].preview
.pos
.y
&&
1167 event
->xbutton
.x
< textureOptions
[i
].preview
.pos
.x
+ textureOptions
[i
].preview
.size
.width
&&
1168 event
->xbutton
.y
< textureOptions
[i
].preview
.pos
.y
+ textureOptions
[i
].preview
.size
.height
) {
1170 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1171 changePage(panel
->secP
, panel
);
1177 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1178 if (event
->xbutton
.x
>= colorOptions
[i
].preview
.pos
.x
&&
1179 event
->xbutton
.y
>= colorOptions
[i
].preview
.pos
.y
&&
1180 event
->xbutton
.x
< colorOptions
[i
].preview
.pos
.x
+ colorOptions
[i
].preview
.size
.width
&&
1181 event
->xbutton
.y
< colorOptions
[i
].preview
.pos
.y
+ colorOptions
[i
].preview
.size
.height
) {
1184 * yuck kluge: the entry #7 is HighlightTextColor which does not have actually a
1185 * display area, but are reused to make the last "Normal Item" menu entry actually
1186 * pick the same color item as the other similar item displayed, which corresponds
1192 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1193 changeColorPage(panel
->colP
, panel
);
1201 static void textureClick(WMWidget
* w
, void *data
)
1203 _Panel
*panel
= (_Panel
*) data
;
1206 TextureListItem
*titem
;
1208 /* Parameter not used, but tell the compiler that it is ok */
1211 i
= WMGetListSelectedItemRow(panel
->texLs
);
1213 item
= WMGetListItem(panel
->texLs
, i
);
1215 titem
= (TextureListItem
*) item
->clientData
;
1217 if (titem
->current
) {
1218 WMSetButtonEnabled(panel
->delB
, False
);
1220 WMSetButtonEnabled(panel
->delB
, True
);
1224 static void textureDoubleClick(WMWidget
* w
, void *data
)
1226 _Panel
*panel
= (_Panel
*) data
;
1229 TextureListItem
*titem
;
1231 /* Parameter not used, but tell the compiler that it is ok */
1234 /* unselect old texture */
1235 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1237 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1238 titem
= (TextureListItem
*) item
->clientData
;
1239 titem
->selectedFor
&= ~(1 << section
);
1241 /* select new texture */
1242 i
= WMGetListSelectedItemRow(panel
->texLs
);
1244 item
= WMGetListItem(panel
->texLs
, i
);
1246 titem
= (TextureListItem
*) item
->clientData
;
1248 titem
->selectedFor
|= 1 << section
;
1250 panel
->textureIndex
[section
] = i
;
1252 WMRedisplayWidget(panel
->texLs
);
1254 if (section
== PBACKGROUND
)
1255 updatePreviewBox(panel
, EVERYTHING
);
1257 updatePreviewBox(panel
, 1 << section
);
1260 static void paintListItem(WMList
* lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
* rect
)
1262 _Panel
*panel
= (_Panel
*) WMGetHangedData(lPtr
);
1263 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1264 int width
, height
, x
, y
;
1265 Display
*dpy
= WMScreenDisplay(scr
);
1266 WMColor
*back
= (state
& WLDSSelected
) ? WMWhiteColor(scr
) : WMGrayColor(scr
);
1268 WMColor
*black
= WMBlackColor(scr
);
1269 TextureListItem
*titem
;
1271 /* Parameter not used, but tell the compiler that it is ok */
1274 item
= WMGetListItem(lPtr
, index
);
1275 titem
= (TextureListItem
*) item
->clientData
;
1277 WMReleaseColor(back
);
1278 WMReleaseColor(black
);
1282 width
= rect
->size
.width
;
1283 height
= rect
->size
.height
;
1287 XFillRectangle(dpy
, d
, WMColorGC(back
), x
, y
, width
, height
);
1290 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0,
1291 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1293 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1294 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1295 else if (titem
->selectedFor
)
1296 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1298 WMDrawString(scr
, d
, black
, panel
->boldFont
,
1299 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
, strlen(titem
->title
));
1301 WMDrawString(scr
, d
, black
, panel
->smallFont
,
1302 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
, strlen(titem
->texture
));
1304 WMReleaseColor(back
);
1305 WMReleaseColor(black
);
1308 static Pixmap
loadRImage(WMScreen
* scr
, const char *path
)
1316 f
= fopen(path
, "rb");
1320 cnt
= fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1322 wwarning(_("could not read size of image from '%s', ignoring"), path
);
1326 if (d
< 3 || d
> 4) {
1327 wwarning(_("image \"%s\" has an invalid depth of %d, ignoring"), path
, d
);
1331 image
= RCreateImage(w
, h
, d
== 4);
1332 if (image
== NULL
) {
1333 wwarning(_("could not create RImage for \"%s\": %s"),
1334 path
, RMessageForError(RErrorCode
));
1338 read_size
= w
* h
* d
;
1339 if (fread(image
->data
, 1, read_size
, f
) == read_size
)
1340 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1346 RReleaseImage(image
);
1351 static void fillTextureList(WMList
* lPtr
)
1353 WMPropList
*textureList
;
1354 WMPropList
*texture
;
1355 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1356 TextureListItem
*titem
;
1357 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1360 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1364 for (i
= 0; i
< WMGetPropListItemCount(textureList
); i
++) {
1367 texture
= WMGetFromPLArray(textureList
, i
);
1369 titem
= wmalloc(sizeof(TextureListItem
));
1371 titem
->title
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 0)));
1372 titem
->prop
= WMRetainPropList(WMGetFromPLArray(texture
, 1));
1373 titem
->texture
= WMGetPropListDescription(titem
->prop
, False
);
1374 titem
->selectedFor
= 0;
1375 titem
->path
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
1377 titem
->preview
= loadRImage(scr
, titem
->path
);
1378 if (!titem
->preview
) {
1379 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1381 item
= WMAddListItem(lPtr
, "");
1382 item
->clientData
= titem
;
1386 static void fillColorList(_Panel
* panel
)
1390 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1391 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1394 list
= WMGetUDObjectForKey(udb
, "ColorList");
1396 for (i
= 0; i
< wlengthof(sample_colors
); i
++) {
1397 color
= WMCreateNamedColor(scr
, sample_colors
[i
], False
);
1400 WMSetColorWellColor(panel
->sampW
[i
], color
);
1401 WMReleaseColor(color
);
1406 for (i
= 0; i
< WMIN(wlengthof(sample_colors
), WMGetPropListItemCount(list
)); i
++) {
1407 c
= WMGetFromPLArray(list
, i
);
1408 if (!c
|| !WMIsPLString(c
))
1410 color
= WMCreateNamedColor(scr
, WMGetFromPLString(c
), False
);
1413 WMSetColorWellColor(panel
->sampW
[i
], color
);
1414 WMReleaseColor(color
);
1419 /*************************************************************************/
1421 static void changeColorPage(WMWidget
* w
, void *data
)
1423 _Panel
*panel
= (_Panel
*) data
;
1425 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1426 RContext
*rc
= WMScreenRContext(scr
);
1428 if (panel
->preview
) {
1431 gc
= XCreateGC(rc
->dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
1432 XCopyArea(rc
->dpy
, panel
->previewBack
, panel
->preview
, gc
,
1433 colorOptions
[panel
->oldcsection
].hand
.x
,
1434 colorOptions
[panel
->oldcsection
].hand
.y
, 22, 22 ,
1435 colorOptions
[panel
->oldcsection
].hand
.x
,
1436 colorOptions
[panel
->oldcsection
].hand
.y
);
1439 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1441 panel
->oldcsection
= section
;
1443 WMDrawPixmap(panel
->hand
, panel
->preview
,
1444 colorOptions
[section
].hand
.x
, colorOptions
[section
].hand
.y
);
1446 if (section
>= ICONT_COL
)
1447 updateColorPreviewBox(panel
, 1 << section
);
1449 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1451 WMRedisplayWidget(panel
->prevL
);
1455 paintText(WMScreen
* scr
, Drawable d
, WMColor
* color
, WMFont
* font
,
1456 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1458 int l
= strlen(text
);
1465 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1469 x
+= (w
- WMWidthOfString(font
, text
, l
)) / 2;
1472 WMDrawString(scr
, d
, color
, font
, x
, y
+ (h
- WMFontHeight(font
)) / 2, text
, l
);
1475 static void updateColorPreviewBox(_Panel
* panel
, int elements
)
1477 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1478 Display
*dpy
= WMScreenDisplay(scr
);
1483 pnot
= panel
->previewNoText
;
1484 gc
= WMColorGC(panel
->colors
[FTITLE_COL
]);
1486 if (elements
& (1 << FTITLE_COL
)) {
1487 XCopyArea(dpy
, pnot
, d
, gc
, 30, 10, 190, 20, 30, 10);
1488 paintText(scr
, d
, panel
->colors
[FTITLE_COL
],
1489 panel
->boldFont
, 30, 10, 190, 20,
1490 panel
->titleAlignment
, _("Focused Window"));
1492 if (elements
& (1 << UTITLE_COL
)) {
1493 XCopyArea(dpy
, pnot
, d
, gc
, 30, 40, 190, 20, 30, 40);
1494 paintText(scr
, d
, panel
->colors
[UTITLE_COL
],
1495 panel
->boldFont
, 30, 40, 190, 20,
1496 panel
->titleAlignment
,
1497 _("Unfocused Window"));
1499 if (elements
& (1 << OTITLE_COL
)) {
1500 XCopyArea(dpy
, pnot
, d
, gc
, 30, 70, 190, 20, 30, 70);
1501 paintText(scr
, d
, panel
->colors
[OTITLE_COL
],
1502 panel
->boldFont
, 30, 70, 190, 20,
1503 panel
->titleAlignment
,
1504 _("Owner of Focused Window"));
1506 if (elements
& (1 << MTITLE_COL
)) {
1507 XCopyArea(dpy
, pnot
, d
, gc
, 30, 120, 90, 20, 30, 120);
1508 paintText(scr
, d
, panel
->colors
[MTITLE_COL
],
1509 panel
->boldFont
, 30, 120, 90, 20, WALeft
,
1512 if (elements
& (1 << MITEM_COL
)) {
1513 XCopyArea(dpy
, pnot
, d
, gc
, 30, 140, 90, 20, 30, 140);
1514 paintText(scr
, d
, panel
->colors
[MITEM_COL
],
1515 panel
->normalFont
, 30, 140, 90, 20, WALeft
,
1517 XCopyArea(dpy
, pnot
, d
, gc
, 30, 200, 90, 20, 30, 200);
1518 paintText(scr
, d
, panel
->colors
[MITEM_COL
],
1519 panel
->normalFont
, 30, 200, 90, 20, WALeft
,
1522 if (elements
& (1 << MDISAB_COL
)) {
1523 XCopyArea(dpy
, pnot
, d
, gc
, 30, 160, 90, 20, 30, 160);
1524 paintText(scr
, d
, panel
->colors
[MDISAB_COL
],
1525 panel
->normalFont
, 30, 160, 90, 20, WALeft
,
1526 _("Disabled Item"));
1528 if (elements
& (1 << MHIGH_COL
)) {
1529 XFillRectangle(WMScreenDisplay(scr
), d
,
1530 WMColorGC(panel
->colors
[MHIGH_COL
]),
1532 XFillRectangle(WMScreenDisplay(scr
), pnot
,
1533 WMColorGC(panel
->colors
[MHIGH_COL
]),
1535 elements
|= 1 << MHIGHT_COL
;
1537 if (elements
& (1 << MHIGHT_COL
)) {
1538 XCopyArea(dpy
, pnot
, d
, gc
, 30, 180, 90, 20, 30, 180);
1539 paintText(scr
, d
, panel
->colors
[MHIGHT_COL
],
1540 panel
->normalFont
, 30, 180, 90, 20, WALeft
,
1543 if (elements
& (1 << FBORDER_COL
)) {
1544 XDrawRectangle(dpy
, pnot
,
1545 WMColorGC(panel
->colors
[FBORDER_COL
]),
1547 XDrawRectangle(dpy
, d
,
1548 WMColorGC(panel
->colors
[FBORDER_COL
]),
1550 XDrawRectangle(dpy
, pnot
,
1551 WMColorGC(panel
->colors
[FBORDER_COL
]),
1553 XDrawRectangle(dpy
, d
,
1554 WMColorGC(panel
->colors
[FBORDER_COL
]),
1556 XDrawLine(dpy
, pnot
,
1557 WMColorGC(panel
->colors
[FBORDER_COL
]),
1560 WMColorGC(panel
->colors
[FBORDER_COL
]),
1562 XDrawLine(dpy
, pnot
,
1563 WMColorGC(panel
->colors
[FBORDER_COL
]),
1566 WMColorGC(panel
->colors
[FBORDER_COL
]),
1568 XDrawLine(dpy
, pnot
,
1569 WMColorGC(panel
->colors
[FBORDER_COL
]),
1570 220, 100, 220, 109);
1572 WMColorGC(panel
->colors
[FBORDER_COL
]),
1573 220, 100, 220, 109);
1574 XDrawLine(dpy
, pnot
,
1575 WMColorGC(panel
->colors
[FBORDER_COL
]),
1578 WMColorGC(panel
->colors
[FBORDER_COL
]),
1580 XDrawLine(dpy
, pnot
,
1581 WMColorGC(panel
->colors
[FBORDER_COL
]),
1584 WMColorGC(panel
->colors
[FBORDER_COL
]),
1586 XDrawLine(dpy
, pnot
,
1587 WMColorGC(panel
->colors
[FBORDER_COL
]),
1588 119, 120, 119, 220);
1590 WMColorGC(panel
->colors
[FBORDER_COL
]),
1591 119, 120, 119, 220);
1594 if (elements
& (1 << FFBORDER_COL
)) {
1595 XDrawRectangle(dpy
, pnot
,
1596 WMColorGC(panel
->colors
[FFBORDER_COL
]),
1598 XDrawRectangle(dpy
, d
,
1599 WMColorGC(panel
->colors
[FFBORDER_COL
]),
1603 if (elements
& (1 << ICONT_COL
) || elements
& (1 << ICONB_COL
)) {
1605 RHSVColor hsv
, hsv2
;
1607 WMColor
*light
, *dim
;
1609 updatePreviewBox(panel
, 1 << PICON
);
1611 rgb
.red
= WMRedComponentOfColor(panel
->colors
[ICONB_COL
]) >> 8;
1612 rgb
.green
= WMGreenComponentOfColor(panel
->colors
[ICONB_COL
]) >> 8;
1613 rgb
.blue
= WMBlueComponentOfColor(panel
->colors
[ICONB_COL
]) >> 8;
1614 RRGBtoHSV(&rgb
, &hsv
);
1615 RHSVtoRGB(&hsv
, &rgb
);
1618 v
= hsv
.value
* 16 / 10;
1619 hsv
.value
= (v
> 255 ? 255 : v
);
1620 RHSVtoRGB(&hsv
, &rgb
);
1621 light
= WMCreateRGBColor(scr
, rgb
.red
<< 8, rgb
.green
<< 8, rgb
.blue
<< 8, False
);
1623 hsv2
.value
= hsv2
.value
/ 2;
1624 RHSVtoRGB(&hsv2
, &rgb
);
1625 dim
= WMCreateRGBColor(scr
, rgb
.red
<< 8, rgb
.green
<< 8, rgb
.blue
<< 8, False
);
1627 XFillRectangle(dpy
, d
, WMColorGC(panel
->colors
[ICONB_COL
]), 156, 131, 62, 11);
1628 XDrawLine(dpy
, d
, WMColorGC(light
), 155, 130, 155, 142);
1629 XDrawLine(dpy
, d
, WMColorGC(light
), 156, 130, 217, 130);
1630 XDrawLine(dpy
, d
, WMColorGC(dim
), 218, 130, 218, 142);
1632 paintText(scr
, d
, panel
->colors
[ICONT_COL
],
1633 panel
->smallFont
, 155, 130, 64, 13, WALeft
,
1636 WMReleaseColor(light
);
1637 WMReleaseColor(dim
);
1640 if (elements
& (1 << CLIP_COL
) || elements
& (1 << CCLIP_COL
)) {
1646 TextureListItem
*titem
;
1650 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[PICON
]);
1651 titem
= (TextureListItem
*) item
->clientData
;
1653 pix
= renderTexture(scr
, titem
->prop
, 64, 64, NULL
, titem
->ispixmap
? 0 : RBEV_RAISED3
);
1654 tile
= RCreateImageFromDrawable(WMScreenRContext(scr
), pix
, None
);
1657 black
.red
= black
.green
= black
.blue
= 0;
1660 dark
.red
= dark
.green
= dark
.blue
= 60;
1663 light
.red
= light
.green
= light
.blue
= 80;
1666 ROperateLine(tile
, RSubtractOperation
, 64 - 1 - 23, 0, 64 - 2, 23 - 1, &dark
);
1667 RDrawLine(tile
, 64 - 1 - 23 - 1, 0, 64 - 1, 23 + 1, &black
);
1668 ROperateLine(tile
, RAddOperation
, 64 - 1 - 23, 2, 64 - 3, 23, &light
);
1671 ROperateLine(tile
, RSubtractOperation
, 64 - 7 - (23 - 15), 4, 64 - 5, 4, &dark
);
1672 ROperateLine(tile
, RSubtractOperation
, 64 - 6 - (23 - 15), 5, 64 - 5, 6 + 23 - 15, &dark
);
1673 ROperateLine(tile
, RAddOperation
, 64 - 5, 4, 64 - 5, 6 + 23 - 15, &light
);
1676 ROperateLine(tile
, RAddOperation
, 2, 64 - 1 - 23 + 2, 23 - 2, 64 - 3, &dark
);
1677 RDrawLine(tile
, 0, 64 - 1 - 23 - 1, 23 + 1, 64 - 1, &black
);
1678 ROperateLine(tile
, RSubtractOperation
, 0, 64 - 1 - 23 - 2, 23 + 1, 64 - 2, &light
);
1681 ROperateLine(tile
, RSubtractOperation
, 4, 64 - 7 - (23 - 15), 4, 64 - 5, &dark
);
1682 ROperateLine(tile
, RSubtractOperation
, 5, 64 - 6 - (23 - 15), 6 + 23 - 15, 64 - 5, &dark
);
1683 ROperateLine(tile
, RAddOperation
, 4, 64 - 5, 6 + 23 - 15, 64 - 5, &light
);
1685 RConvertImage(WMScreenRContext(scr
), tile
, &pix
);
1686 RReleaseImage(tile
);
1688 XCopyArea(dpy
, pix
, d
, gc
, 0, 0, 64, 64, 155, 130);
1689 XFreePixmap(dpy
, pix
);
1691 /* top right arrow */
1692 p
[0].x
= p
[3].x
= 155 + 64 - 5 - (23 - 15);
1693 p
[0].y
= p
[3].y
= 130 + 5;
1694 p
[1].x
= 155 + 64 - 6;
1696 p
[2].x
= 155 + 64 - 6;
1697 p
[2].y
= 130 + 4 + 23 - 15;
1699 XFillPolygon(dpy
, d
, WMColorGC(panel
->colors
[CLIP_COL
]), p
, 3, Convex
, CoordModeOrigin
);
1700 XDrawLines(dpy
, d
, WMColorGC(panel
->colors
[CLIP_COL
]), p
, 4, CoordModeOrigin
);
1702 /* bottom left arrow */
1703 p
[0].x
= p
[3].x
= 155 + 5;
1704 p
[0].y
= p
[3].y
= 130 + 64 - 5 - (23 - 15);
1706 p
[1].y
= 130 + 64 - 6;
1707 p
[2].x
= 155 + 4 + 23 - 15;
1708 p
[2].y
= 130 + 64 - 6;
1710 XFillPolygon(dpy
, d
, WMColorGC(panel
->colors
[CLIP_COL
]), p
, 3, Convex
, CoordModeOrigin
);
1711 XDrawLines(dpy
, d
, WMColorGC(panel
->colors
[CLIP_COL
]), p
, 4, CoordModeOrigin
);
1715 if (elements
& (1 << CLIP_COL
))
1716 paintText(scr
, d
, panel
->colors
[CLIP_COL
],
1717 panel
->boldFont
, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft
,
1720 if (elements
& (1 << CCLIP_COL
)) {
1721 paintText(scr
, d
, panel
->colors
[CCLIP_COL
],
1722 panel
->boldFont
, 155+2, 130 + 2, 26, 15, WALeft
, _("Coll."));
1723 paintText(scr
, d
, panel
->colors
[CCLIP_COL
],
1724 panel
->boldFont
, 155 + 23, 130 + 64 - 15 - 3, 22, 15, WALeft
,
1728 WMRedisplayWidget(panel
->prevL
);
1731 static void colorWellObserver(void *self
, WMNotification
* n
)
1733 _Panel
*panel
= (_Panel
*) self
;
1736 /* Parameter not used, but tell the compiler that it is ok */
1739 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1741 WMReleaseColor(panel
->colors
[p
]);
1743 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1745 updateColorPreviewBox(panel
, 1 << p
);
1748 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
)
1750 _Panel
*panel
= self
->data
;
1753 /* Parameter not used, but tell the compiler that it is ok */
1756 i
= WMGetTabViewItemIdentifier(item
);
1759 switch (panel
->oldTabItem
) {
1761 changeColorPage(NULL
, panel
);
1764 changePage(panel
->secP
, panel
);
1767 switch (panel
->oldTabItem
) {
1769 changePage(NULL
, panel
);
1772 changeColorPage(panel
->colP
, panel
);
1775 switch (panel
->oldTabItem
) {
1777 changePage(NULL
, panel
);
1780 changeColorPage(NULL
, panel
);
1786 panel
->oldTabItem
= i
;
1789 /*************************************************************************/
1791 static void menuStyleCallback(WMWidget
* self
, void *data
)
1793 _Panel
*panel
= (_Panel
*) data
;
1796 for (i
= 0; i
< wlengthof(menu_style
); i
++) {
1797 if (self
== panel
->mstyB
[i
]) {
1798 panel
->menuStyle
= i
;
1803 updatePreviewBox(panel
, 1 << PMITEM
);
1806 static void titleAlignCallback(WMWidget
* self
, void *data
)
1808 _Panel
*panel
= (_Panel
*) data
;
1811 for (align
= 0; align
< wlengthof(wintitle_align
); align
++) {
1812 if (self
== panel
->taliB
[align
]) {
1813 panel
->titleAlignment
= align
;
1818 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1821 static void createPanel(Panel
* p
)
1823 _Panel
*panel
= (_Panel
*) p
;
1825 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1826 WMTabViewItem
*item
;
1831 panel
->fprefix
= wstrconcat(wuserdatapath(), "/" PACKAGE_TARNAME
);
1833 if (access(panel
->fprefix
, F_OK
) != 0) {
1834 if (mkdir(panel
->fprefix
, 0755) < 0) {
1835 werror("%s", panel
->fprefix
);
1840 tmp
= wstrconcat(panel
->fprefix
, "/WPrefs/");
1841 wfree(panel
->fprefix
);
1842 panel
->fprefix
= tmp
;
1843 if (access(panel
->fprefix
, F_OK
) != 0) {
1844 if (mkdir(panel
->fprefix
, 0755) < 0) {
1845 werror("%s", panel
->fprefix
);
1850 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1851 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1852 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1854 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1855 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1856 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1858 panel
->box
= WMCreateBox(panel
->parent
);
1859 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
1862 panel
->prevL
= WMCreateLabel(panel
->box
);
1863 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1864 WMMoveWidget(panel
->prevL
, 15, 10);
1865 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1866 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1868 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
, previewClick
, panel
);
1872 tabviewDelegate
.data
= panel
;
1874 panel
->tabv
= WMCreateTabView(panel
->box
);
1875 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1876 WMMoveWidget(panel
->tabv
, 265, 10);
1877 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1879 /*** texture list ***/
1881 panel
->texF
= WMCreateFrame(panel
->box
);
1882 WMSetFrameRelief(panel
->texF
, WRFlat
);
1884 item
= WMCreateTabViewItemWithIdentifier(TAB_TEXTURE
);
1885 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1886 WMSetTabViewItemLabel(item
, _("Texture"));
1888 WMAddItemInTabView(panel
->tabv
, item
);
1890 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1891 WMResizeWidget(panel
->secP
, 228, 20);
1892 WMMoveWidget(panel
->secP
, 7, 7);
1894 for (i
= 0; i
< wlengthof(textureOptions
); i
++)
1895 WMAddPopUpButtonItem(panel
->secP
, _(textureOptions
[i
].popup_label
));
1897 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1898 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1900 panel
->texLs
= WMCreateList(panel
->texF
);
1901 WMResizeWidget(panel
->texLs
, 165, 155);
1902 WMMoveWidget(panel
->texLs
, 70, 33);
1903 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1904 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1905 WMHangData(panel
->texLs
, panel
);
1906 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1907 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1909 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1910 "for the selected item."), WMWidgetView(panel
->texLs
));
1912 /* command buttons */
1914 font
= WMSystemFontOfSize(scr
, 10);
1916 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1917 WMResizeWidget(panel
->newB
, 57, 39);
1918 WMMoveWidget(panel
->newB
, 7, 33);
1919 WMSetButtonFont(panel
->newB
, font
);
1920 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1921 WMSetButtonText(panel
->newB
, _("New"));
1922 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1923 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1925 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel
->newB
));
1927 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1928 WMResizeWidget(panel
->ripB
, 57, 39);
1929 WMMoveWidget(panel
->ripB
, 7, 72);
1930 WMSetButtonFont(panel
->ripB
, font
);
1931 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1932 WMSetButtonText(panel
->ripB
, _("Extract..."));
1933 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1934 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1936 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel
->ripB
));
1938 WMSetButtonEnabled(panel
->ripB
, False
);
1940 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1941 WMResizeWidget(panel
->editB
, 57, 39);
1942 WMMoveWidget(panel
->editB
, 7, 111);
1943 WMSetButtonFont(panel
->editB
, font
);
1944 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1945 WMSetButtonText(panel
->editB
, _("Edit"));
1946 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1947 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1948 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel
->editB
));
1950 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1951 WMResizeWidget(panel
->delB
, 57, 38);
1952 WMMoveWidget(panel
->delB
, 7, 150);
1953 WMSetButtonFont(panel
->delB
, font
);
1954 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1955 WMSetButtonText(panel
->delB
, _("Delete"));
1956 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1957 WMSetButtonEnabled(panel
->delB
, False
);
1958 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1959 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel
->delB
));
1961 WMReleaseFont(font
);
1963 WMMapSubwidgets(panel
->texF
);
1966 panel
->colF
= WMCreateFrame(panel
->box
);
1967 WMSetFrameRelief(panel
->colF
, WRFlat
);
1969 item
= WMCreateTabViewItemWithIdentifier(TAB_COLOR
);
1970 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1971 WMSetTabViewItemLabel(item
, _("Color"));
1973 WMAddItemInTabView(panel
->tabv
, item
);
1975 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1976 WMResizeWidget(panel
->colP
, 228, 20);
1977 WMMoveWidget(panel
->colP
, 7, 7);
1979 for (i
= 0; i
< wlengthof(colorOptions
); i
++)
1980 WMAddPopUpButtonItem(panel
->colP
, _(colorOptions
[i
].label
));
1982 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1984 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1986 panel
->colW
= WMCreateColorWell(panel
->colF
);
1987 WMResizeWidget(panel
->colW
, 65, 50);
1988 WMMoveWidget(panel
->colW
, 30, 75);
1989 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->colW
);
1991 { /* Distribute the color samples regularly in the right half */
1992 const int parent_width
= 242;
1993 const int parent_height
= 195;
1994 const int available_width
= (parent_width
/ 2) - 7;
1995 const int available_height
= parent_height
- 7 - 20 - 7 - 7;
1996 const int widget_size
= 22;
1998 const int nb_x
= (int) round(sqrt(wlengthof(sample_colors
) * available_width
/ available_height
));
1999 const int nb_y
= (wlengthof(sample_colors
) + nb_x
- 1) / nb_x
;
2001 const int offset_x
= (parent_width
/ 2) + (available_width
- nb_x
* widget_size
) / 2;
2002 const int offset_y
= (7 + 20 + 7) + (available_height
- nb_y
* widget_size
) / 2;
2007 for (i
= 0; i
< wlengthof(sample_colors
); i
++) {
2008 panel
->sampW
[i
] = WMCreateColorWell(panel
->colF
);
2009 WMResizeWidget(panel
->sampW
[i
], widget_size
, widget_size
);
2010 WMMoveWidget(panel
->sampW
[i
], offset_x
+ x
* widget_size
, offset_y
+ y
* widget_size
);
2011 WSetColorWellBordered(panel
->sampW
[i
], False
);
2019 WMMapSubwidgets(panel
->colF
);
2022 panel
->optF
= WMCreateFrame(panel
->box
);
2023 WMSetFrameRelief(panel
->optF
, WRFlat
);
2025 item
= WMCreateTabViewItemWithIdentifier(TAB_OPTIONS
);
2026 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
2027 WMSetTabViewItemLabel(item
, _("Options"));
2029 WMAddItemInTabView(panel
->tabv
, item
);
2031 panel
->mstyF
= WMCreateFrame(panel
->optF
);
2032 WMResizeWidget(panel
->mstyF
, 215, 85);
2033 WMMoveWidget(panel
->mstyF
, 15, 10);
2034 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
2036 for (i
= 0; i
< wlengthof(menu_style
); i
++) {
2040 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
2041 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
2042 WMMoveWidget(panel
->mstyB
[i
], 15 + i
* 65, 20);
2043 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
2044 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
2045 path
= LocateImage(menu_style
[i
].file_name
);
2047 icon
= WMCreatePixmapFromFile(scr
, path
);
2049 WMSetButtonImage(panel
->mstyB
[i
], icon
);
2050 WMReleasePixmap(icon
);
2052 wwarning(_("could not load icon file %s"), path
);
2057 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
2058 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
2060 WMMapSubwidgets(panel
->mstyF
);
2062 panel
->taliF
= WMCreateFrame(panel
->optF
);
2063 WMResizeWidget(panel
->taliF
, 110, 80);
2064 WMMoveWidget(panel
->taliF
, 15, 100);
2065 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
2067 for (i
= 0; i
< wlengthof(wintitle_align
); i
++) {
2068 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
2069 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
2070 WMSetButtonText(panel
->taliB
[i
], _(wintitle_align
[i
].label
));
2071 WMResizeWidget(panel
->taliB
[i
], 90, 18);
2072 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20 * i
);
2074 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
2075 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
2077 WMMapSubwidgets(panel
->taliF
);
2079 WMMapSubwidgets(panel
->optF
);
2081 /**/ WMRealizeWidget(panel
->box
);
2082 WMMapSubwidgets(panel
->box
);
2084 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
2088 changePage(panel
->secP
, panel
);
2090 fillTextureList(panel
->texLs
);
2092 fillColorList(panel
);
2094 panel
->texturePanel
= CreateTexturePanel(panel
->parent
);
2097 static void setupTextureFor(WMList
*list
, const char *key
, const char *defValue
, const char *title
, int index
)
2100 TextureListItem
*titem
;
2102 titem
= wmalloc(sizeof(TextureListItem
));
2104 titem
->title
= wstrdup(title
);
2105 titem
->prop
= GetObjectForKey(key
);
2106 if (!titem
->prop
|| !WMIsPLArray(titem
->prop
)) {
2107 /* Maybe also give a error message to stderr that the entry is bad? */
2108 titem
->prop
= WMCreatePropListFromDescription(defValue
);
2110 WMRetainPropList(titem
->prop
);
2112 titem
->texture
= WMGetPropListDescription((WMPropList
*) titem
->prop
, False
);
2114 titem
->selectedFor
= 1 << index
;
2116 titem
->ispixmap
= isPixmap(titem
->prop
);
2118 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
2120 item
= WMAddListItem(list
, "");
2121 item
->clientData
= titem
;
2124 static void showData(_Panel
* panel
)
2129 str
= GetStringForKey("MenuStyle");
2130 panel
->menuStyle
= MSTYLE_NORMAL
;
2132 for (i
= 0; i
< wlengthof(menu_style
); i
++) {
2133 if (strcasecmp(str
, menu_style
[i
].db_value
) == 0) {
2134 panel
->menuStyle
= i
;
2140 str
= GetStringForKey("TitleJustify");
2141 panel
->titleAlignment
= WACenter
;
2145 for (align
= 0; align
< wlengthof(wintitle_align
); align
++) {
2146 if (strcasecmp(str
, wintitle_align
[align
].db_value
) == 0) {
2147 panel
->titleAlignment
= align
;
2153 for (i
= 0; i
< wlengthof(colorOptions
); i
++) {
2156 str
= GetStringForKey(colorOptions
[i
].key
);
2158 str
= colorOptions
[i
].default_value
;
2160 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), str
, False
))) {
2161 color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), "#000000", False
);
2164 panel
->colors
[i
] = color
;
2166 changeColorPage(panel
->colP
, panel
);
2168 for (i
= 0; i
< wlengthof(textureOptions
); i
++) {
2169 setupTextureFor(panel
->texLs
, textureOptions
[i
].key
,
2170 textureOptions
[i
].default_value
, _(textureOptions
[i
].texture_label
), i
);
2171 panel
->textureIndex
[i
] = i
;
2173 updatePreviewBox(panel
, EVERYTHING
);
2175 WMSetButtonSelected(panel
->mstyB
[panel
->menuStyle
], True
);
2176 WMSetButtonSelected(panel
->taliB
[panel
->titleAlignment
], True
);
2179 static void storeData(_Panel
* panel
)
2181 TextureListItem
*titem
;
2185 for (i
= 0; i
< wlengthof(textureOptions
); i
++) {
2186 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
2187 titem
= (TextureListItem
*) item
->clientData
;
2188 SetObjectForKey(titem
->prop
, textureOptions
[i
].key
);
2191 for (i
= 0; i
< wlengthof(colorOptions
); i
++) {
2194 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
2197 SetStringForKey(str
, colorOptions
[i
].key
);
2202 SetStringForKey(menu_style
[panel
->menuStyle
].db_value
, "MenuStyle");
2203 SetStringForKey(wintitle_align
[panel
->titleAlignment
].db_value
, "TitleJustify");
2206 static void prepareForClose(_Panel
* panel
)
2208 WMPropList
*textureList
;
2209 WMPropList
*texture
;
2210 TextureListItem
*titem
;
2212 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2215 textureList
= WMCreatePLArray(NULL
, NULL
);
2217 /* store list of textures */
2218 for (i
= 8; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2219 WMPropList
*pl_title
, *pl_path
;
2221 item
= WMGetListItem(panel
->texLs
, i
);
2222 titem
= (TextureListItem
*) item
->clientData
;
2224 pl_title
= WMCreatePLString(titem
->title
);
2225 pl_path
= WMCreatePLString(titem
->path
);
2226 texture
= WMCreatePLArray(pl_title
, titem
->prop
, pl_path
, NULL
);
2227 WMReleasePropList(pl_title
);
2228 WMReleasePropList(pl_path
);
2230 WMAddToPLArray(textureList
, texture
);
2233 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2234 WMReleasePropList(textureList
);
2236 /* store list of colors */
2237 textureList
= WMCreatePLArray(NULL
, NULL
);
2238 for (i
= 0; i
< wlengthof(sample_colors
); i
++) {
2241 WMPropList
*pl_color
;
2243 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2245 str
= WMGetColorRGBDescription(color
);
2246 pl_color
= WMCreatePLString(str
);
2247 WMAddToPLArray(textureList
, pl_color
);
2248 WMReleasePropList(pl_color
);
2251 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2252 WMReleasePropList(textureList
);
2254 WMSynchronizeUserDefaults(udb
);
2257 Panel
*InitAppearance(WMWidget
*parent
)
2261 panel
= wmalloc(sizeof(_Panel
));
2263 panel
->sectionName
= _("Appearance Preferences");
2265 panel
->description
= _("Background texture configuration for windows,\n" "menus and icons.");
2267 panel
->parent
= parent
;
2269 panel
->callbacks
.createWidgets
= createPanel
;
2270 panel
->callbacks
.updateDomain
= storeData
;
2271 panel
->callbacks
.prepareForClose
= prepareForClose
;
2273 AddSection(panel
, ICON_FILE
);
2278 /****************************************************************************/
2280 typedef struct ExtractPanel
{
2290 static void OpenExtractPanelFor(_Panel
*panel
)
2292 ExtractPanel
*epanel
;
2295 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
2297 epanel
= wmalloc(sizeof(ExtractPanel
));
2298 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->parent
, "extract",
2299 WMTitledWindowMask
| WMClosableWindowMask
);
2300 WMResizeWidget(epanel
->win
, 245, 250);
2301 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2303 epanel
->label
= WMCreateLabel(epanel
->win
);
2304 WMResizeWidget(epanel
->label
, 225, 18);
2305 WMMoveWidget(epanel
->label
, 10, 10);
2306 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2307 WMSetLabelRelief(epanel
->label
, WRSunken
);
2309 color
= WMDarkGrayColor(scr
);
2310 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2311 WMReleaseColor(color
);
2313 color
= WMWhiteColor(scr
);
2314 WMSetLabelTextColor(epanel
->label
, color
);
2315 WMReleaseColor(color
);
2317 font
= WMBoldSystemFontOfSize(scr
, 12);
2318 WMSetLabelFont(epanel
->label
, font
);
2319 WMReleaseFont(font
);
2321 WMSetLabelText(epanel
->label
, _("Textures"));
2323 epanel
->list
= WMCreateList(epanel
->win
);
2324 WMResizeWidget(epanel
->list
, 225, 165);
2325 WMMoveWidget(epanel
->list
, 10, 30);
2327 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2328 WMResizeWidget(epanel
->closeB
, 74, 24);
2329 WMMoveWidget(epanel
->closeB
, 165, 215);
2330 WMSetButtonText(epanel
->closeB
, _("Close"));
2332 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2333 WMResizeWidget(epanel
->extrB
, 74, 24);
2334 WMMoveWidget(epanel
->extrB
, 80, 215);
2335 WMSetButtonText(epanel
->extrB
, _("Extract"));
2337 WMMapSubwidgets(epanel
->win
);
2339 /* take textures from file */
2341 WMRealizeWidget(epanel
->win
);
2343 WMMapWidget(epanel
->win
);