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>
32 #include "TexturePanel.h"
34 typedef struct _Panel
{
40 CallbackRec callbacks
;
67 WMColorWell
*sampW
[24];
86 TexturePanel
*texturePanel
;
102 Pixmap previewNoText
;
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
);
137 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
);
139 static WMTabViewDelegate tabviewDelegate
= {
141 NULL
, /* didChangeNumberOfItems */
142 changedTabItem
, /* didSelectItem */
143 NULL
, /* shouldSelectItem */
144 NULL
/* willSelectItem */
147 #define ICON_FILE "appearance"
149 #define TNEW_FILE "tnew"
150 #define TDEL_FILE "tdel"
151 #define TEDIT_FILE "tedit"
152 #define TEXTR_FILE "textr"
154 #define MSTYLE1_FILE "msty1"
155 #define MSTYLE2_FILE "msty2"
156 #define MSTYLE3_FILE "msty3"
159 static char *blueled_xpm
[] = {
189 static char *blueled2_xpm
[] = {
190 /* width height num_colors chars_per_pixel */
222 static char *hand_xpm
[] = {
246 " .%%%&@.......... ",
247 " .%*%%&#%%%%%%%%%$. ",
248 " .*#%%%%%%%%%&&&&==. ",
249 " .-%%%%%%%%%=*-;;;#$. ",
250 " .-%%%%%%%%&..>..... ",
266 static char *sampleColors
[] = {
294 static const struct {
296 const char *default_value
;
298 } textureOptions
[] = {
299 { "FTitleBack", "(solid, black)", N_("[Focused]") },
300 { "UTitleBack", "(solid, gray)", N_("[Unfocused]") },
301 { "PTitleBack", "(solid, \"#616161\")", N_("[Owner of Focused]") },
302 { "ResizebarBack", "(solid, gray)", N_("[Resizebar]") },
303 { "MenuTitleBack", "(solid, black)", N_("[Menu Title]") },
304 { "MenuTextBack", "(solid, gray)", N_("[Menu Item]") },
305 { "IconBack", "(solid, gray)", N_("[Icon]") },
306 { "WorkspaceBack", "(solid, black)", N_("[Background]") }
310 RESIZEBAR_BEVEL
= -1,
343 static const struct {
345 const char *default_value
;
347 { "FTitleColor", "white" },
348 { "UTitleColor", "black" },
349 { "PTitleColor", "white" },
350 { "MenuTitleColor", "white" },
351 { "MenuTextColor", "black" },
352 { "MenuDisabledColor", "#616161" },
353 { "HighlightColor", "white" },
354 { "HighlightTextColor", "black" },
355 { "FrameFocusedBorderColor", "black" },
356 { "FrameBorderColor", "black" },
357 { "FrameSelectedBorderColor", "white" }/* , */
358 /* { "IconTitleColor", "white" }, */
359 /* { "IconTitleBack", "black" }, */
360 /* { "ClipTitleColor", "black" }, */
361 /* { "CClipTitleColor", "#454045" } */
364 static WMRect previewPositions
[] = {
366 {{30, 10}, {190, 20}},
368 {{30, 40}, {190, 20}},
370 {{30, 70}, {190, 20}},
372 {{30, 100}, {190, 9}},
374 {{30, 120}, {90, 20}},
376 {{30, 140}, {90, 20 * 4}},
378 {{155, 130}, {64, 64}}
381 #define PBACKGROUND 7
382 #define EVERYTHING 0xff
384 static WMRect previewColorPositions
[] = {
385 {{30, 10}, {190, 20}},
386 {{30, 40}, {190, 20}},
387 {{30, 70}, {190, 20}},
388 {{30, 120}, {90, 20}},
389 {{30, 140}, {90, 20}},
390 {{30, 160}, {90, 20}},
391 {{30, 180}, {90, 20}},
392 {{30, 200}, {90, 20}},
396 {{155, 130}, {64, 64}},
397 {{155, 130}, {64, 64}},
398 {{155, 130}, {64, 64}},
399 {{155, 130}, {64, 64}}
402 static void str2rcolor(RContext
* rc
, const char *name
, RColor
* color
)
406 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
409 color
->red
= xcolor
.red
>> 8;
410 color
->green
= xcolor
.green
>> 8;
411 color
->blue
= xcolor
.blue
>> 8;
414 static void dumpRImage(const char *path
, RImage
* image
)
417 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
419 f
= fopen(path
, "wb");
424 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
, channels
);
426 fwrite(image
->data
, 1, image
->width
* image
->height
* channels
, f
);
434 static int isPixmap(WMPropList
* prop
)
439 p
= WMGetFromPLArray(prop
, 0);
440 s
= WMGetFromPLString(p
);
441 if (strcasecmp(&s
[1], "pixmap") == 0)
447 /**********************************************************************/
449 static void drawResizebarBevel(RImage
* img
)
453 int width
= img
->width
;
454 int height
= img
->height
;
458 light
.red
= light
.green
= light
.blue
= 80;
461 dark
.red
= dark
.green
= dark
.blue
= 40;
463 ROperateLine(img
, RSubtractOperation
, 0, 0, width
- 1, 0, &dark
);
464 ROperateLine(img
, RAddOperation
, 0, 1, width
- 1, 1, &light
);
466 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
- 1, &dark
);
467 ROperateLine(img
, RAddOperation
, cwidth
+ 1, 2, cwidth
+ 1, height
- 1, &light
);
469 ROperateLine(img
, RSubtractOperation
, width
- cwidth
- 2, 2, width
- cwidth
- 2, height
- 1, &dark
);
470 ROperateLine(img
, RAddOperation
, width
- cwidth
- 1, 2, width
- cwidth
- 1, height
- 1, &light
);
474 static void drawMenuBevel(RImage
* img
)
476 RColor light
, dark
, mid
;
478 int iheight
= img
->height
/ 4;
481 light
.red
= light
.green
= light
.blue
= 80;
484 dark
.red
= dark
.green
= dark
.blue
= 0;
487 mid
.red
= mid
.green
= mid
.blue
= 40;
489 for (i
= 1; i
< 4; i
++) {
490 ROperateLine(img
, RSubtractOperation
, 0, i
* iheight
- 2, img
->width
- 1, i
* iheight
- 2, &mid
);
492 RDrawLine(img
, 0, i
* iheight
- 1, img
->width
- 1, i
* iheight
- 1, &dark
);
494 ROperateLine(img
, RAddOperation
, 1, i
* iheight
, img
->width
- 2, i
* iheight
, &light
);
498 static Pixmap
renderTexture(WMScreen
* scr
, WMPropList
* texture
, int width
, int height
, const char *path
, int border
)
501 RImage
*image
= NULL
;
502 RImage
*timage
= NULL
;
504 RContext
*rc
= WMScreenRContext(scr
);
508 type
= WMGetFromPLString(WMGetFromPLArray(texture
, 0));
510 if (strcasecmp(&type
[1], "pixmap") == 0 ||
511 (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'T')) {
514 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
515 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
517 timage
= RLoadImage(rc
, path
, 0);
519 wwarning("could not load file '%s': %s", path
, RMessageForError(RErrorCode
));
522 wwarning("could not find file '%s' for %s of texture", str
, type
);
526 texture
= WMCreatePropListFromDescription("(solid, black)");
531 if (strcasecmp(type
, "solid") == 0) {
533 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
535 str2rcolor(rc
, str
, &rcolor
);
537 image
= RCreateImage(width
, height
, False
);
538 RClearImage(image
, &rcolor
);
539 } else if (strcasecmp(type
, "igradient") == 0) {
543 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
544 str2rcolor(rc
, str
, &c1
[0]);
545 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
546 str2rcolor(rc
, str
, &c1
[1]);
547 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
550 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
551 str2rcolor(rc
, str
, &c2
[0]);
552 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 5));
553 str2rcolor(rc
, str
, &c2
[1]);
554 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 6));
557 image
= RRenderInterwovenGradient(width
, height
, c1
, t1
, c2
, t2
);
558 } else if (strcasecmp(&type
[1], "gradient") == 0) {
562 switch (toupper(type
[0])) {
564 style
= RVerticalGradient
;
567 style
= RHorizontalGradient
;
571 style
= RDiagonalGradient
;
575 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
576 str2rcolor(rc
, str
, &rcolor
);
577 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
578 str2rcolor(rc
, str
, &rcolor2
);
580 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
581 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'T') {
587 switch (toupper(type
[1])) {
589 style
= RVerticalGradient
;
592 style
= RHorizontalGradient
;
596 style
= RDiagonalGradient
;
600 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
601 str2rcolor(rc
, str
, &rcolor
);
602 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
603 str2rcolor(rc
, str
, &rcolor2
);
605 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
607 image
= RMakeTiledImage(timage
, width
, height
);
608 RReleaseImage(timage
);
610 i
= atoi(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
612 RCombineImagesWithOpaqueness(image
, grad
, i
);
615 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'M') {
620 switch (toupper(type
[1])) {
622 style
= RVerticalGradient
;
625 style
= RHorizontalGradient
;
629 style
= RDiagonalGradient
;
633 j
= WMGetPropListItemCount(texture
);
636 colors
= wmalloc(j
* sizeof(RColor
*));
638 for (i
= 2; i
< j
; i
++) {
639 str
= WMGetFromPLString(WMGetFromPLArray(texture
, i
));
640 colors
[i
- 2] = wmalloc(sizeof(RColor
));
641 str2rcolor(rc
, str
, colors
[i
- 2]);
643 colors
[i
- 2] = NULL
;
645 image
= RRenderMultiGradient(width
, height
, colors
, style
);
647 for (i
= 0; colors
[i
] != NULL
; i
++)
651 } else if (strcasecmp(&type
[1], "pixmap") == 0) {
654 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
655 str2rcolor(rc
, str
, &color
);
657 switch (toupper(type
[0])) {
659 image
= RMakeTiledImage(timage
, width
, height
);
660 RReleaseImage(timage
);
663 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
664 RReleaseImage(timage
);
669 image
= RScaleImage(timage
, width
, height
);
670 RReleaseImage(timage
);
679 dumpRImage(path
, image
);
683 if (border
== RESIZEBAR_BEVEL
) {
684 drawResizebarBevel(image
);
685 } else if (border
== MENU_BEVEL
) {
686 drawMenuBevel(image
);
687 RBevelImage(image
, RBEV_RAISED2
);
690 RBevelImage(image
, border
);
693 RConvertImage(rc
, image
, &pixmap
);
694 RReleaseImage(image
);
699 static Pixmap
renderMenu(_Panel
* panel
, WMPropList
* texture
, int width
, int iheight
)
701 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
702 Display
*dpy
= WMScreenDisplay(scr
);
704 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
707 switch (panel
->menuStyle
) {
709 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
711 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
* 4, WMScreenDepth(scr
));
712 for (i
= 0; i
< 4; i
++) {
713 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
* i
);
715 XFreePixmap(dpy
, tmp
);
718 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, MENU_BEVEL
);
721 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, RBEV_RAISED2
);
731 static void renderPreview(_Panel
* panel
, GC gc
, int part
, int relief
)
734 TextureListItem
*titem
;
736 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
738 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
739 titem
= (TextureListItem
*) item
->clientData
;
741 pix
= renderTexture(scr
, titem
->prop
,
742 previewPositions
[part
].size
.width
, previewPositions
[part
].size
.height
, NULL
, relief
);
744 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
745 previewPositions
[part
].size
.width
,
746 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
748 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->previewNoText
, gc
, 0, 0,
749 previewPositions
[part
].size
.width
,
750 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
752 XFreePixmap(WMScreenDisplay(scr
), pix
);
755 static void updatePreviewBox(_Panel
* panel
, int elements
)
757 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
758 Display
*dpy
= WMScreenDisplay(scr
);
763 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
765 if (panel
->preview
== None
) {
768 panel
->previewNoText
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
769 240 - 4, 215 - 4, WMScreenDepth(scr
));
770 panel
->previewBack
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
771 240 - 4, 215 - 4, WMScreenDepth(scr
));
773 p
= WMCreatePixmap(scr
, 240 - 4, 215 - 4, WMScreenDepth(scr
), False
);
774 panel
->preview
= WMGetPixmapXID(p
);
775 WMSetLabelImage(panel
->prevL
, p
);
778 if (elements
& (1 << PBACKGROUND
)) {
780 TextureListItem
*titem
;
783 item
= WMGetListItem(panel
->texLs
,
784 panel
->textureIndex
[PBACKGROUND
]);
785 titem
= (TextureListItem
*) item
->clientData
;
786 tmp
= renderTexture(scr
, titem
->prop
, 240 - 4, 215 - 4, NULL
, 0);
788 XCopyArea(dpy
, tmp
, panel
->preview
, gc
, 0, 0, 240 - 4, 215 -4 , 0, 0);
789 XCopyArea(dpy
, tmp
, panel
->previewNoText
, gc
, 0, 0, 240 - 4, 215 -4 , 0, 0);
790 XCopyArea(dpy
, tmp
, panel
->previewBack
, gc
, 0, 0, 240 - 4, 215 -4 , 0, 0);
791 XFreePixmap(dpy
, tmp
);
794 if (elements
& (1 << PFOCUSED
)) {
795 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
796 colorUpdate
|= 1 << FTITLE_COL
| 1 << FFBORDER_COL
;
798 if (elements
& (1 << PUNFOCUSED
)) {
799 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
800 colorUpdate
|= 1 << UTITLE_COL
| 1 << FBORDER_COL
;
802 if (elements
& (1 << POWNER
)) {
803 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
804 colorUpdate
|= 1 << OTITLE_COL
| 1 << FBORDER_COL
;
806 if (elements
& (1 << PRESIZEBAR
)) {
807 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
808 colorUpdate
|= 1 << FBORDER_COL
;
810 if (elements
& (1 << PMTITLE
)) {
811 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
812 colorUpdate
|= 1 << MTITLE_COL
| 1 << FBORDER_COL
;
814 if (elements
& (1 << PMITEM
)) {
816 TextureListItem
*titem
;
818 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
819 titem
= (TextureListItem
*) item
->clientData
;
821 pix
= renderMenu(panel
, titem
->prop
,
822 previewPositions
[PMITEM
].size
.width
, previewPositions
[PMITEM
].size
.height
/ 4);
824 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
825 previewPositions
[PMITEM
].size
.width
,
826 previewPositions
[PMITEM
].size
.height
,
827 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
829 XCopyArea(dpy
, pix
, panel
->previewNoText
, gc
, 0, 0,
830 previewPositions
[PMITEM
].size
.width
,
831 previewPositions
[PMITEM
].size
.height
,
832 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
834 XFreePixmap(dpy
, pix
);
836 colorUpdate
|= 1 << MITEM_COL
| 1 << MDISAB_COL
|
837 1 << MHIGH_COL
| 1 << MHIGHT_COL
|
840 if (elements
& (1 << PICON
)) {
842 TextureListItem
*titem
;
844 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
845 titem
= (TextureListItem
*) item
->clientData
;
847 renderPreview(panel
, gc
, PICON
, titem
->ispixmap
? 0 : RBEV_RAISED3
);
849 colorUpdate
|= 1 << ICONT_COL
| 1 << ICONB_COL
|
850 1 << CLIP_COL
| 1 << CCLIP_COL
;
854 updateColorPreviewBox(panel
, colorUpdate
);
856 WMRedisplayWidget(panel
->prevL
);
861 static void cancelNewTexture(void *data
)
863 _Panel
*panel
= (_Panel
*) data
;
865 HideTexturePanel(panel
->texturePanel
);
868 static char *makeFileName(const char *prefix
)
872 fname
= wstrdup(prefix
);
874 while (access(fname
, F_OK
) == 0) {
878 sprintf(buf
, "%08lx.cache", time(NULL
));
879 fname
= wstrconcat(prefix
, buf
);
885 static void okNewTexture(void *data
)
887 _Panel
*panel
= (_Panel
*) data
;
892 TextureListItem
*titem
;
893 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
895 titem
= wmalloc(sizeof(TextureListItem
));
897 HideTexturePanel(panel
->texturePanel
);
899 name
= GetTexturePanelTextureName(panel
->texturePanel
);
901 prop
= GetTexturePanelTexture(panel
->texturePanel
);
903 str
= WMGetPropListDescription(prop
, False
);
907 titem
->texture
= str
;
908 titem
->selectedFor
= 0;
910 titem
->ispixmap
= isPixmap(prop
);
912 titem
->path
= makeFileName(panel
->fprefix
);
913 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
915 item
= WMAddListItem(panel
->texLs
, "");
916 item
->clientData
= titem
;
918 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
921 static void okEditTexture(void *data
)
923 _Panel
*panel
= (_Panel
*) data
;
928 TextureListItem
*titem
;
930 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
931 titem
= (TextureListItem
*) item
->clientData
;
933 HideTexturePanel(panel
->texturePanel
);
935 if (titem
->current
) {
936 name
= GetTexturePanelTextureName(panel
->texturePanel
);
942 prop
= GetTexturePanelTexture(panel
->texturePanel
);
944 str
= WMGetPropListDescription(prop
, False
);
946 WMReleasePropList(titem
->prop
);
949 titem
->ispixmap
= isPixmap(prop
);
951 wfree(titem
->texture
);
952 titem
->texture
= str
;
954 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
955 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
956 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
958 WMRedisplayWidget(panel
->texLs
);
960 if (titem
->selectedFor
) {
961 if (titem
->selectedFor
& (1 << PBACKGROUND
))
962 updatePreviewBox(panel
, EVERYTHING
);
964 updatePreviewBox(panel
, titem
->selectedFor
);
967 changePage(panel
->secP
, panel
);
970 static void editTexture(WMWidget
* w
, void *data
)
972 _Panel
*panel
= (_Panel
*) data
;
974 TextureListItem
*titem
;
976 /* Parameter not used, but tell the compiler that it is ok */
979 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
980 titem
= (TextureListItem
*) item
->clientData
;
982 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
984 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
986 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
987 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
989 ShowTexturePanel(panel
->texturePanel
);
992 static void newTexture(WMWidget
* w
, void *data
)
994 _Panel
*panel
= (_Panel
*) data
;
996 /* Parameter not used, but tell the compiler that it is ok */
999 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
1001 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
1003 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
1005 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
1007 ShowTexturePanel(panel
->texturePanel
);
1010 static void deleteTexture(WMWidget
* w
, void *data
)
1012 _Panel
*panel
= (_Panel
*) data
;
1014 TextureListItem
*titem
;
1018 /* Parameter not used, but tell the compiler that it is ok */
1021 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1022 row
= WMGetListSelectedItemRow(panel
->texLs
);
1023 item
= WMGetListItem(panel
->texLs
, row
);
1024 titem
= (TextureListItem
*) item
->clientData
;
1026 if (titem
->selectedFor
& (1 << section
)) {
1027 TextureListItem
*titem2
;
1029 panel
->textureIndex
[section
] = section
;
1030 item
= WMGetListItem(panel
->texLs
, section
);
1031 titem2
= (TextureListItem
*) item
->clientData
;
1032 titem2
->selectedFor
|= 1 << section
;
1035 wfree(titem
->title
);
1036 wfree(titem
->texture
);
1037 WMReleasePropList(titem
->prop
);
1039 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1040 werror("could not remove file %s", titem
->path
);
1047 WMRemoveListItem(panel
->texLs
, row
);
1048 WMSetButtonEnabled(panel
->delB
, False
);
1051 static void extractTexture(WMWidget
* w
, void *data
)
1053 _Panel
*panel
= (_Panel
*) data
;
1055 WMOpenPanel
*opanel
;
1056 WMScreen
*scr
= WMWidgetScreen(w
);
1058 opanel
= WMGetOpenPanel(scr
);
1059 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1060 WMSetFilePanelCanChooseFiles(opanel
, True
);
1062 if (WMRunModalFilePanelForDirectory(opanel
, panel
->parent
, wgethomedir(), _("Select File"), NULL
)) {
1063 path
= WMGetFilePanelFileName(opanel
);
1065 OpenExtractPanelFor(panel
);
1071 static void changePage(WMWidget
* w
, void *data
)
1073 _Panel
*panel
= (_Panel
*) data
;
1075 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1076 RContext
*rc
= WMScreenRContext(scr
);
1077 static WMPoint positions
[] = {
1088 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1090 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1092 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1097 gc
= XCreateGC(rc
->dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
1098 XCopyArea(rc
->dpy
, panel
->previewBack
, panel
->preview
, gc
,
1099 positions
[panel
->oldsection
].x
,
1100 positions
[panel
->oldsection
].y
, 22, 22 ,
1101 positions
[panel
->oldsection
].x
,
1102 positions
[panel
->oldsection
].y
);
1105 panel
->oldsection
= section
;
1106 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1108 WMRedisplayWidget(panel
->prevL
);
1111 static void previewClick(XEvent
* event
, void *clientData
)
1113 _Panel
*panel
= (_Panel
*) clientData
;
1116 switch (panel
->oldTabItem
) {
1118 for (i
= 0; i
< wlengthof(previewPositions
); i
++) {
1119 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
1120 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
1121 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
1122 + previewPositions
[i
].size
.width
1123 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
+ previewPositions
[i
].size
.height
) {
1125 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1126 changePage(panel
->secP
, panel
);
1132 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1133 if (event
->xbutton
.x
>= previewColorPositions
[i
].pos
.x
1134 && event
->xbutton
.y
>= previewColorPositions
[i
].pos
.y
1135 && event
->xbutton
.x
< previewColorPositions
[i
].pos
.x
1136 + previewColorPositions
[i
].size
.width
1137 && event
->xbutton
.y
< previewColorPositions
[i
].pos
.y
1138 + previewColorPositions
[i
].size
.height
) {
1144 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1145 changeColorPage(panel
->colP
, panel
);
1153 static void textureClick(WMWidget
* w
, void *data
)
1155 _Panel
*panel
= (_Panel
*) data
;
1158 TextureListItem
*titem
;
1160 /* Parameter not used, but tell the compiler that it is ok */
1163 i
= WMGetListSelectedItemRow(panel
->texLs
);
1165 item
= WMGetListItem(panel
->texLs
, i
);
1167 titem
= (TextureListItem
*) item
->clientData
;
1169 if (titem
->current
) {
1170 WMSetButtonEnabled(panel
->delB
, False
);
1172 WMSetButtonEnabled(panel
->delB
, True
);
1176 static void textureDoubleClick(WMWidget
* w
, void *data
)
1178 _Panel
*panel
= (_Panel
*) data
;
1181 TextureListItem
*titem
;
1183 /* Parameter not used, but tell the compiler that it is ok */
1186 /* unselect old texture */
1187 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1189 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1190 titem
= (TextureListItem
*) item
->clientData
;
1191 titem
->selectedFor
&= ~(1 << section
);
1193 /* select new texture */
1194 i
= WMGetListSelectedItemRow(panel
->texLs
);
1196 item
= WMGetListItem(panel
->texLs
, i
);
1198 titem
= (TextureListItem
*) item
->clientData
;
1200 titem
->selectedFor
|= 1 << section
;
1202 panel
->textureIndex
[section
] = i
;
1204 WMRedisplayWidget(panel
->texLs
);
1206 if (section
== PBACKGROUND
)
1207 updatePreviewBox(panel
, EVERYTHING
);
1209 updatePreviewBox(panel
, 1 << section
);
1212 static void paintListItem(WMList
* lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
* rect
)
1214 _Panel
*panel
= (_Panel
*) WMGetHangedData(lPtr
);
1215 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1216 int width
, height
, x
, y
;
1217 Display
*dpy
= WMScreenDisplay(scr
);
1218 WMColor
*back
= (state
& WLDSSelected
) ? WMWhiteColor(scr
) : WMGrayColor(scr
);
1220 WMColor
*black
= WMBlackColor(scr
);
1221 TextureListItem
*titem
;
1223 /* Parameter not used, but tell the compiler that it is ok */
1226 item
= WMGetListItem(lPtr
, index
);
1227 titem
= (TextureListItem
*) item
->clientData
;
1229 WMReleaseColor(back
);
1230 WMReleaseColor(black
);
1234 width
= rect
->size
.width
;
1235 height
= rect
->size
.height
;
1239 XFillRectangle(dpy
, d
, WMColorGC(back
), x
, y
, width
, height
);
1242 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0,
1243 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1245 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1246 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1247 else if (titem
->selectedFor
)
1248 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1250 WMDrawString(scr
, d
, black
, panel
->boldFont
,
1251 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
, strlen(titem
->title
));
1253 WMDrawString(scr
, d
, black
, panel
->smallFont
,
1254 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
, strlen(titem
->texture
));
1256 WMReleaseColor(back
);
1257 WMReleaseColor(black
);
1260 static Pixmap
loadRImage(WMScreen
* scr
, const char *path
)
1268 f
= fopen(path
, "rb");
1272 cnt
= fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1277 image
= RCreateImage(w
, h
, d
== 4);
1278 read_size
= w
* h
* d
;
1279 if (fread(image
->data
, 1, read_size
, f
) == read_size
)
1280 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1286 RReleaseImage(image
);
1291 static void fillTextureList(WMList
* lPtr
)
1293 WMPropList
*textureList
;
1294 WMPropList
*texture
;
1295 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1296 TextureListItem
*titem
;
1297 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1300 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1304 for (i
= 0; i
< WMGetPropListItemCount(textureList
); i
++) {
1307 texture
= WMGetFromPLArray(textureList
, i
);
1309 titem
= wmalloc(sizeof(TextureListItem
));
1311 titem
->title
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 0)));
1312 titem
->prop
= WMRetainPropList(WMGetFromPLArray(texture
, 1));
1313 titem
->texture
= WMGetPropListDescription(titem
->prop
, False
);
1314 titem
->selectedFor
= 0;
1315 titem
->path
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
1317 titem
->preview
= loadRImage(scr
, titem
->path
);
1318 if (!titem
->preview
) {
1319 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1321 item
= WMAddListItem(lPtr
, "");
1322 item
->clientData
= titem
;
1326 static void fillColorList(_Panel
* panel
)
1330 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1331 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1334 list
= WMGetUDObjectForKey(udb
, "ColorList");
1336 for (i
= 0; i
< 24; i
++) {
1337 color
= WMCreateNamedColor(scr
, sampleColors
[i
], False
);
1340 WMSetColorWellColor(panel
->sampW
[i
], color
);
1341 WMReleaseColor(color
);
1346 for (i
= 0; i
< WMIN(24, WMGetPropListItemCount(list
)); i
++) {
1347 c
= WMGetFromPLArray(list
, i
);
1348 if (!c
|| !WMIsPLString(c
))
1350 color
= WMCreateNamedColor(scr
, WMGetFromPLString(c
), False
);
1353 WMSetColorWellColor(panel
->sampW
[i
], color
);
1354 WMReleaseColor(color
);
1359 /*************************************************************************/
1361 static void changeColorPage(WMWidget
* w
, void *data
)
1363 _Panel
*panel
= (_Panel
*) data
;
1365 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1366 RContext
*rc
= WMScreenRContext(scr
);
1367 static WMPoint positions
[] = {
1385 if (panel
->preview
) {
1388 gc
= XCreateGC(rc
->dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
1389 XCopyArea(rc
->dpy
, panel
->previewBack
, panel
->preview
, gc
,
1390 positions
[panel
->oldcsection
].x
,
1391 positions
[panel
->oldcsection
].y
, 22, 22 ,
1392 positions
[panel
->oldcsection
].x
,
1393 positions
[panel
->oldcsection
].y
);
1396 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1398 panel
->oldcsection
= section
;
1400 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1402 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1404 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1406 WMRedisplayWidget(panel
->prevL
);
1410 paintText(WMScreen
* scr
, Drawable d
, WMColor
* color
, WMFont
* font
,
1411 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1413 int l
= strlen(text
);
1420 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1424 x
+= (w
- WMWidthOfString(font
, text
, l
)) / 2;
1427 WMDrawString(scr
, d
, color
, font
, x
, y
+ (h
- WMFontHeight(font
)) / 2, text
, l
);
1430 static void updateColorPreviewBox(_Panel
* panel
, int elements
)
1432 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1433 Display
*dpy
= WMScreenDisplay(scr
);
1438 pnot
= panel
->previewNoText
;
1439 gc
= WMColorGC(panel
->colors
[FTITLE_COL
]);
1441 if (elements
& (1 << FTITLE_COL
)) {
1442 XCopyArea(dpy
, pnot
, d
, gc
, 30, 10, 190, 20, 30, 10);
1443 paintText(scr
, d
, panel
->colors
[FTITLE_COL
],
1444 panel
->boldFont
, 30, 10, 190, 20,
1445 panel
->titleAlignment
, _("Focused Window"));
1447 if (elements
& (1 << UTITLE_COL
)) {
1448 XCopyArea(dpy
, pnot
, d
, gc
, 30, 40, 190, 20, 30, 40);
1449 paintText(scr
, d
, panel
->colors
[UTITLE_COL
],
1450 panel
->boldFont
, 30, 40, 190, 20,
1451 panel
->titleAlignment
,
1452 _("Unfocused Window"));
1454 if (elements
& (1 << OTITLE_COL
)) {
1455 XCopyArea(dpy
, pnot
, d
, gc
, 30, 70, 190, 20, 30, 70);
1456 paintText(scr
, d
, panel
->colors
[OTITLE_COL
],
1457 panel
->boldFont
, 30, 70, 190, 20,
1458 panel
->titleAlignment
,
1459 _("Owner of Focused Window"));
1461 if (elements
& (1 << MTITLE_COL
)) {
1462 XCopyArea(dpy
, pnot
, d
, gc
, 30, 120, 90, 20, 30, 120);
1463 paintText(scr
, d
, panel
->colors
[MTITLE_COL
],
1464 panel
->boldFont
, 30, 120, 90, 20, WALeft
,
1467 if (elements
& (1 << MITEM_COL
)) {
1468 XCopyArea(dpy
, pnot
, d
, gc
, 30, 140, 90, 20, 30, 140);
1469 paintText(scr
, d
, panel
->colors
[MITEM_COL
],
1470 panel
->normalFont
, 30, 140, 90, 20, WALeft
,
1472 XCopyArea(dpy
, pnot
, d
, gc
, 30, 200, 90, 20, 30, 200);
1473 paintText(scr
, d
, panel
->colors
[MITEM_COL
],
1474 panel
->normalFont
, 30, 200, 90, 20, WALeft
,
1477 if (elements
& (1 << MDISAB_COL
)) {
1478 XCopyArea(dpy
, pnot
, d
, gc
, 30, 160, 90, 20, 30, 160);
1479 paintText(scr
, d
, panel
->colors
[MDISAB_COL
],
1480 panel
->normalFont
, 30, 160, 90, 20, WALeft
,
1481 _("Disabled Item"));
1483 if (elements
& (1 << MHIGH_COL
)) {
1484 XFillRectangle(WMScreenDisplay(scr
), d
,
1485 WMColorGC(panel
->colors
[MHIGH_COL
]),
1487 XFillRectangle(WMScreenDisplay(scr
), pnot
,
1488 WMColorGC(panel
->colors
[MHIGH_COL
]),
1490 elements
|= 1 << MHIGHT_COL
;
1492 if (elements
& (1 << MHIGHT_COL
)) {
1493 XCopyArea(dpy
, pnot
, d
, gc
, 30, 180, 90, 20, 30, 180);
1494 paintText(scr
, d
, panel
->colors
[MHIGHT_COL
],
1495 panel
->normalFont
, 30, 180, 90, 20, WALeft
,
1498 if (elements
& (1 << FBORDER_COL
)) {
1499 XDrawRectangle(dpy
, pnot
,
1500 WMColorGC(panel
->colors
[FBORDER_COL
]),
1502 XDrawRectangle(dpy
, d
,
1503 WMColorGC(panel
->colors
[FBORDER_COL
]),
1505 XDrawRectangle(dpy
, pnot
,
1506 WMColorGC(panel
->colors
[FBORDER_COL
]),
1508 XDrawRectangle(dpy
, d
,
1509 WMColorGC(panel
->colors
[FBORDER_COL
]),
1511 XDrawLine(dpy
, pnot
,
1512 WMColorGC(panel
->colors
[FBORDER_COL
]),
1515 WMColorGC(panel
->colors
[FBORDER_COL
]),
1517 XDrawLine(dpy
, pnot
,
1518 WMColorGC(panel
->colors
[FBORDER_COL
]),
1521 WMColorGC(panel
->colors
[FBORDER_COL
]),
1523 XDrawLine(dpy
, pnot
,
1524 WMColorGC(panel
->colors
[FBORDER_COL
]),
1525 220, 100, 220, 109);
1527 WMColorGC(panel
->colors
[FBORDER_COL
]),
1528 220, 100, 220, 109);
1529 XDrawLine(dpy
, pnot
,
1530 WMColorGC(panel
->colors
[FBORDER_COL
]),
1533 WMColorGC(panel
->colors
[FBORDER_COL
]),
1535 XDrawLine(dpy
, pnot
,
1536 WMColorGC(panel
->colors
[FBORDER_COL
]),
1539 WMColorGC(panel
->colors
[FBORDER_COL
]),
1541 XDrawLine(dpy
, pnot
,
1542 WMColorGC(panel
->colors
[FBORDER_COL
]),
1543 119, 120, 119, 220);
1545 WMColorGC(panel
->colors
[FBORDER_COL
]),
1546 119, 120, 119, 220);
1549 if (elements
& (1 << FFBORDER_COL
)) {
1550 XDrawRectangle(dpy
, pnot
,
1551 WMColorGC(panel
->colors
[FFBORDER_COL
]),
1553 XDrawRectangle(dpy
, d
,
1554 WMColorGC(panel
->colors
[FFBORDER_COL
]),
1559 if (elements & (1 << ICONT_COL)) {
1560 WRITE(_("Focused Window"), panel->colors[ICONT_COL],
1564 if (elements & (1 << ICONB_COL)) {
1565 WRITE(_("Focused Window"), panel->colors[ICONB_COL],
1569 if (elements & (1 << CLIP_COL)) {
1570 WRITE(_("Focused Window"), panel->colors[CLIP_COL],
1574 if (elements & (1 << CCLIP_COL)) {
1575 WRITE(_("Focused Window"), panel->colors[CCLIP_COL],
1580 WMRedisplayWidget(panel
->prevL
);
1583 static void colorWellObserver(void *self
, WMNotification
* n
)
1585 _Panel
*panel
= (_Panel
*) self
;
1588 /* Parameter not used, but tell the compiler that it is ok */
1591 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1593 WMReleaseColor(panel
->colors
[p
]);
1595 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1597 updateColorPreviewBox(panel
, 1 << p
);
1600 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
)
1602 _Panel
*panel
= self
->data
;
1605 /* Parameter not used, but tell the compiler that it is ok */
1608 i
= WMGetTabViewItemIdentifier(item
);
1611 switch (panel
->oldTabItem
) {
1613 changeColorPage(NULL
, panel
);
1616 changePage(panel
->secP
, panel
);
1619 switch (panel
->oldTabItem
) {
1621 changePage(NULL
, panel
);
1624 changeColorPage(panel
->colP
, panel
);
1627 switch (panel
->oldTabItem
) {
1629 changePage(NULL
, panel
);
1632 changeColorPage(NULL
, panel
);
1638 panel
->oldTabItem
= i
;
1641 /*************************************************************************/
1643 static void menuStyleCallback(WMWidget
* self
, void *data
)
1645 _Panel
*panel
= (_Panel
*) data
;
1647 if (self
== panel
->mstyB
[0]) {
1648 panel
->menuStyle
= MSTYLE_NORMAL
;
1649 updatePreviewBox(panel
, 1 << PMITEM
);
1651 } else if (self
== panel
->mstyB
[1]) {
1652 panel
->menuStyle
= MSTYLE_SINGLE
;
1653 updatePreviewBox(panel
, 1 << PMITEM
);
1655 } else if (self
== panel
->mstyB
[2]) {
1656 panel
->menuStyle
= MSTYLE_FLAT
;
1657 updatePreviewBox(panel
, 1 << PMITEM
);
1661 static void titleAlignCallback(WMWidget
* self
, void *data
)
1663 _Panel
*panel
= (_Panel
*) data
;
1665 if (self
== panel
->taliB
[0]) {
1666 panel
->titleAlignment
= WALeft
;
1667 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1669 } else if (self
== panel
->taliB
[1]) {
1670 panel
->titleAlignment
= WACenter
;
1671 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1673 } else if (self
== panel
->taliB
[2]) {
1674 panel
->titleAlignment
= WARight
;
1675 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1679 static void createPanel(Panel
* p
)
1681 _Panel
*panel
= (_Panel
*) p
;
1683 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1684 WMTabViewItem
*item
;
1689 panel
->fprefix
= wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1691 if (access(panel
->fprefix
, F_OK
) != 0) {
1692 if (mkdir(panel
->fprefix
, 0755) < 0) {
1693 werror("%s", panel
->fprefix
);
1698 tmp
= wstrconcat(panel
->fprefix
, "/WPrefs/");
1699 wfree(panel
->fprefix
);
1700 panel
->fprefix
= tmp
;
1701 if (access(panel
->fprefix
, F_OK
) != 0) {
1702 if (mkdir(panel
->fprefix
, 0755) < 0) {
1703 werror("%s", panel
->fprefix
);
1708 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1709 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1710 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1712 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1713 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1714 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1716 panel
->box
= WMCreateBox(panel
->parent
);
1717 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
1720 panel
->prevL
= WMCreateLabel(panel
->box
);
1721 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1722 WMMoveWidget(panel
->prevL
, 15, 10);
1723 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1724 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1726 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
, previewClick
, panel
);
1730 tabviewDelegate
.data
= panel
;
1732 panel
->tabv
= WMCreateTabView(panel
->box
);
1733 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1734 WMMoveWidget(panel
->tabv
, 265, 10);
1735 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1737 /*** texture list ***/
1739 panel
->texF
= WMCreateFrame(panel
->box
);
1740 WMSetFrameRelief(panel
->texF
, WRFlat
);
1742 item
= WMCreateTabViewItemWithIdentifier(TAB_TEXTURE
);
1743 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1744 WMSetTabViewItemLabel(item
, _("Texture"));
1746 WMAddItemInTabView(panel
->tabv
, item
);
1748 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1749 WMResizeWidget(panel
->secP
, 228, 20);
1750 WMMoveWidget(panel
->secP
, 7, 7);
1751 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1752 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1753 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1754 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1755 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1756 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1757 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1758 WMAddPopUpButtonItem(panel
->secP
, _("Workspace Background"));
1760 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1761 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1763 panel
->texLs
= WMCreateList(panel
->texF
);
1764 WMResizeWidget(panel
->texLs
, 165, 155);
1765 WMMoveWidget(panel
->texLs
, 70, 33);
1766 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1767 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1768 WMHangData(panel
->texLs
, panel
);
1769 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1770 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1772 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1773 "for the selected item."), WMWidgetView(panel
->texLs
));
1775 /* command buttons */
1777 font
= WMSystemFontOfSize(scr
, 10);
1779 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1780 WMResizeWidget(panel
->newB
, 57, 39);
1781 WMMoveWidget(panel
->newB
, 7, 33);
1782 WMSetButtonFont(panel
->newB
, font
);
1783 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1784 WMSetButtonText(panel
->newB
, _("New"));
1785 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1786 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1788 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel
->newB
));
1790 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1791 WMResizeWidget(panel
->ripB
, 57, 39);
1792 WMMoveWidget(panel
->ripB
, 7, 72);
1793 WMSetButtonFont(panel
->ripB
, font
);
1794 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1795 WMSetButtonText(panel
->ripB
, _("Extract..."));
1796 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1797 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1799 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel
->ripB
));
1801 WMSetButtonEnabled(panel
->ripB
, False
);
1803 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1804 WMResizeWidget(panel
->editB
, 57, 39);
1805 WMMoveWidget(panel
->editB
, 7, 111);
1806 WMSetButtonFont(panel
->editB
, font
);
1807 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1808 WMSetButtonText(panel
->editB
, _("Edit"));
1809 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1810 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1811 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel
->editB
));
1813 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1814 WMResizeWidget(panel
->delB
, 57, 38);
1815 WMMoveWidget(panel
->delB
, 7, 150);
1816 WMSetButtonFont(panel
->delB
, font
);
1817 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1818 WMSetButtonText(panel
->delB
, _("Delete"));
1819 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1820 WMSetButtonEnabled(panel
->delB
, False
);
1821 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1822 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel
->delB
));
1824 WMReleaseFont(font
);
1826 WMMapSubwidgets(panel
->texF
);
1829 panel
->colF
= WMCreateFrame(panel
->box
);
1830 WMSetFrameRelief(panel
->colF
, WRFlat
);
1832 item
= WMCreateTabViewItemWithIdentifier(TAB_COLOR
);
1833 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1834 WMSetTabViewItemLabel(item
, _("Color"));
1836 WMAddItemInTabView(panel
->tabv
, item
);
1838 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1839 WMResizeWidget(panel
->colP
, 228, 20);
1840 WMMoveWidget(panel
->colP
, 7, 7);
1841 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Title"));
1842 WMAddPopUpButtonItem(panel
->colP
, _("Unfocused Window Title"));
1843 WMAddPopUpButtonItem(panel
->colP
, _("Owner of Focused Window Title"));
1844 WMAddPopUpButtonItem(panel
->colP
, _("Menu Title"));
1845 WMAddPopUpButtonItem(panel
->colP
, _("Menu Item Text"));
1846 WMAddPopUpButtonItem(panel
->colP
, _("Disabled Menu Item Text"));
1847 WMAddPopUpButtonItem(panel
->colP
, _("Menu Highlight Color"));
1848 WMAddPopUpButtonItem(panel
->colP
, _("Highlighted Menu Text Color"));
1849 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Border Color"));
1850 WMAddPopUpButtonItem(panel
->colP
, _("Window Border Color"));
1851 WMAddPopUpButtonItem(panel
->colP
, _("Selected Window Border Color"));
1853 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1854 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1855 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1856 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1859 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1861 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1863 panel
->colW
= WMCreateColorWell(panel
->colF
);
1864 WMResizeWidget(panel
->colW
, 65, 50);
1865 WMMoveWidget(panel
->colW
, 30, 75);
1866 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->colW
);
1868 for (i
= 0; i
< 4; i
++) {
1870 for (j
= 0; j
< 6; j
++) {
1871 panel
->sampW
[i
+ j
* 4] = WMCreateColorWell(panel
->colF
);
1872 WMResizeWidget(panel
->sampW
[i
+ j
* 4], 22, 22);
1873 WMMoveWidget(panel
->sampW
[i
+ j
* 4], 130 + i
* 22, 40 + j
* 22);
1874 WSetColorWellBordered(panel
->sampW
[i
+ j
* 4], False
);
1878 WMMapSubwidgets(panel
->colF
);
1881 panel
->optF
= WMCreateFrame(panel
->box
);
1882 WMSetFrameRelief(panel
->optF
, WRFlat
);
1884 item
= WMCreateTabViewItemWithIdentifier(TAB_OPTIONS
);
1885 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1886 WMSetTabViewItemLabel(item
, _("Options"));
1888 WMAddItemInTabView(panel
->tabv
, item
);
1890 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1891 WMResizeWidget(panel
->mstyF
, 215, 85);
1892 WMMoveWidget(panel
->mstyF
, 15, 10);
1893 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1895 for (i
= 0; i
< 3; i
++) {
1899 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1900 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1901 WMMoveWidget(panel
->mstyB
[i
], 15 + i
* 65, 20);
1902 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1903 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1906 path
= LocateImage(MSTYLE1_FILE
);
1909 path
= LocateImage(MSTYLE2_FILE
);
1912 path
= LocateImage(MSTYLE3_FILE
);
1916 icon
= WMCreatePixmapFromFile(scr
, path
);
1918 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1919 WMReleasePixmap(icon
);
1921 wwarning(_("could not load icon file %s"), path
);
1926 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1927 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1929 WMMapSubwidgets(panel
->mstyF
);
1931 panel
->taliF
= WMCreateFrame(panel
->optF
);
1932 WMResizeWidget(panel
->taliF
, 110, 80);
1933 WMMoveWidget(panel
->taliF
, 15, 100);
1934 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
1936 for (i
= 0; i
< 3; i
++) {
1937 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
1938 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
1941 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1944 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1947 WMSetButtonText(panel
->taliB
[i
], _("Right"));
1950 WMResizeWidget(panel
->taliB
[i
], 90, 18);
1951 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20 * i
);
1953 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
1954 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
1956 WMMapSubwidgets(panel
->taliF
);
1958 WMMapSubwidgets(panel
->optF
);
1960 /**/ WMRealizeWidget(panel
->box
);
1961 WMMapSubwidgets(panel
->box
);
1963 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1967 changePage(panel
->secP
, panel
);
1969 fillTextureList(panel
->texLs
);
1971 fillColorList(panel
);
1973 panel
->texturePanel
= CreateTexturePanel(panel
->parent
);
1976 static void setupTextureFor(WMList
*list
, const char *key
, const char *defValue
, const char *title
, int index
)
1979 TextureListItem
*titem
;
1981 titem
= wmalloc(sizeof(TextureListItem
));
1983 titem
->title
= wstrdup(title
);
1984 titem
->prop
= GetObjectForKey(key
);
1985 if (!titem
->prop
|| !WMIsPLArray(titem
->prop
)) {
1986 /* Maybe also give a error message to stderr that the entry is bad? */
1987 titem
->prop
= WMCreatePropListFromDescription(defValue
);
1989 WMRetainPropList(titem
->prop
);
1991 titem
->texture
= WMGetPropListDescription((WMPropList
*) titem
->prop
, False
);
1993 titem
->selectedFor
= 1 << index
;
1995 titem
->ispixmap
= isPixmap(titem
->prop
);
1997 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1999 item
= WMAddListItem(list
, "");
2000 item
->clientData
= titem
;
2003 static void showData(_Panel
* panel
)
2008 str
= GetStringForKey("MenuStyle");
2009 if (str
&& strcasecmp(str
, "flat") == 0) {
2010 panel
->menuStyle
= MSTYLE_FLAT
;
2011 } else if (str
&& strcasecmp(str
, "singletexture") == 0) {
2012 panel
->menuStyle
= MSTYLE_SINGLE
;
2014 panel
->menuStyle
= MSTYLE_NORMAL
;
2017 str
= GetStringForKey("TitleJustify");
2018 if (str
&& strcasecmp(str
, "left") == 0) {
2019 panel
->titleAlignment
= WALeft
;
2020 } else if (str
&& strcasecmp(str
, "right") == 0) {
2021 panel
->titleAlignment
= WARight
;
2023 panel
->titleAlignment
= WACenter
;
2026 for (i
= 0; i
< wlengthof(colorOptions
); i
++) {
2029 str
= GetStringForKey(colorOptions
[i
].key
);
2031 str
= colorOptions
[i
].default_value
;
2033 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), str
, False
))) {
2034 color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), "#000000", False
);
2037 panel
->colors
[i
] = color
;
2039 changeColorPage(panel
->colP
, panel
);
2041 for (i
= 0; i
< wlengthof(textureOptions
); i
++) {
2042 setupTextureFor(panel
->texLs
, textureOptions
[i
].key
,
2043 textureOptions
[i
].default_value
, _(textureOptions
[i
].label
), i
);
2044 panel
->textureIndex
[i
] = i
;
2046 updatePreviewBox(panel
, EVERYTHING
);
2048 WMSetButtonSelected(panel
->mstyB
[panel
->menuStyle
], True
);
2049 WMSetButtonSelected(panel
->taliB
[panel
->titleAlignment
], True
);
2052 static void storeData(_Panel
* panel
)
2054 TextureListItem
*titem
;
2058 for (i
= 0; i
< wlengthof(textureOptions
); i
++) {
2059 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
2060 titem
= (TextureListItem
*) item
->clientData
;
2061 SetObjectForKey(titem
->prop
, textureOptions
[i
].key
);
2064 for (i
= 0; i
< wlengthof(colorOptions
); i
++) {
2067 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
2070 SetStringForKey(str
, colorOptions
[i
].key
);
2075 switch (panel
->menuStyle
) {
2077 SetStringForKey("singletexture", "MenuStyle");
2080 SetStringForKey("flat", "MenuStyle");
2084 SetStringForKey("normal", "MenuStyle");
2087 switch (panel
->titleAlignment
) {
2089 SetStringForKey("left", "TitleJustify");
2092 SetStringForKey("right", "TitleJustify");
2096 SetStringForKey("center", "TitleJustify");
2101 static void prepareForClose(_Panel
* panel
)
2103 WMPropList
*textureList
;
2104 WMPropList
*texture
;
2105 TextureListItem
*titem
;
2107 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2110 textureList
= WMCreatePLArray(NULL
, NULL
);
2112 /* store list of textures */
2113 for (i
= 8; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2114 item
= WMGetListItem(panel
->texLs
, i
);
2115 titem
= (TextureListItem
*) item
->clientData
;
2117 texture
= WMCreatePLArray(WMCreatePLString(titem
->title
),
2118 WMRetainPropList(titem
->prop
), WMCreatePLString(titem
->path
), NULL
);
2120 WMAddToPLArray(textureList
, texture
);
2123 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2124 WMReleasePropList(textureList
);
2126 /* store list of colors */
2127 textureList
= WMCreatePLArray(NULL
, NULL
);
2128 for (i
= 0; i
< 24; i
++) {
2132 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2134 str
= WMGetColorRGBDescription(color
);
2135 WMAddToPLArray(textureList
, WMCreatePLString(str
));
2138 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2139 WMReleasePropList(textureList
);
2141 WMSynchronizeUserDefaults(udb
);
2144 Panel
*InitAppearance(WMWidget
*parent
)
2148 panel
= wmalloc(sizeof(_Panel
));
2150 panel
->sectionName
= _("Appearance Preferences");
2152 panel
->description
= _("Background texture configuration for windows,\n" "menus and icons.");
2154 panel
->parent
= parent
;
2156 panel
->callbacks
.createWidgets
= createPanel
;
2157 panel
->callbacks
.updateDomain
= storeData
;
2158 panel
->callbacks
.prepareForClose
= prepareForClose
;
2160 AddSection(panel
, ICON_FILE
);
2165 /****************************************************************************/
2167 typedef struct ExtractPanel
{
2177 static void OpenExtractPanelFor(_Panel
*panel
)
2179 ExtractPanel
*epanel
;
2182 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
2184 epanel
= wmalloc(sizeof(ExtractPanel
));
2185 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->parent
, "extract",
2186 WMTitledWindowMask
| WMClosableWindowMask
);
2187 WMResizeWidget(epanel
->win
, 245, 250);
2188 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2190 epanel
->label
= WMCreateLabel(epanel
->win
);
2191 WMResizeWidget(epanel
->label
, 225, 18);
2192 WMMoveWidget(epanel
->label
, 10, 10);
2193 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2194 WMSetLabelRelief(epanel
->label
, WRSunken
);
2196 color
= WMDarkGrayColor(scr
);
2197 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2198 WMReleaseColor(color
);
2200 color
= WMWhiteColor(scr
);
2201 WMSetLabelTextColor(epanel
->label
, color
);
2202 WMReleaseColor(color
);
2204 font
= WMBoldSystemFontOfSize(scr
, 12);
2205 WMSetLabelFont(epanel
->label
, font
);
2206 WMReleaseFont(font
);
2208 WMSetLabelText(epanel
->label
, _("Textures"));
2210 epanel
->list
= WMCreateList(epanel
->win
);
2211 WMResizeWidget(epanel
->list
, 225, 165);
2212 WMMoveWidget(epanel
->list
, 10, 30);
2214 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2215 WMResizeWidget(epanel
->closeB
, 74, 24);
2216 WMMoveWidget(epanel
->closeB
, 165, 215);
2217 WMSetButtonText(epanel
->closeB
, _("Close"));
2219 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2220 WMResizeWidget(epanel
->extrB
, 74, 24);
2221 WMMoveWidget(epanel
->extrB
, 80, 215);
2222 WMSetButtonText(epanel
->extrB
, _("Extract"));
2224 WMMapSubwidgets(epanel
->win
);
2226 /* take textures from file */
2228 WMRealizeWidget(epanel
->win
);
2230 WMMapWidget(epanel
->win
);