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,
342 static const struct {
344 const char *default_value
;
346 { "FTitleColor", "white" },
347 { "UTitleColor", "black" },
348 { "PTitleColor", "white" },
349 { "MenuTitleColor", "white" },
350 { "MenuTextColor", "black" },
351 { "MenuDisabledColor", "#616161" },
352 { "HighlightColor", "white" },
353 { "HighlightTextColor", "black" },
354 { "FrameBorderColor", "black" },
355 { "FrameSelectedBorderColor", "white" }/* , */
356 /* { "IconTitleColor", "white" }, */
357 /* { "IconTitleBack", "black" }, */
358 /* { "ClipTitleColor", "black" }, */
359 /* { "CClipTitleColor", "#454045" } */
362 static WMRect previewPositions
[] = {
364 {{30, 10}, {190, 20}},
366 {{30, 40}, {190, 20}},
368 {{30, 70}, {190, 20}},
370 {{30, 100}, {190, 9}},
372 {{30, 120}, {90, 20}},
374 {{30, 140}, {90, 20 * 4}},
376 {{155, 130}, {64, 64}}
379 #define PBACKGROUND 7
380 #define EVERYTHING 0xff
382 static WMRect previewColorPositions
[] = {
383 {{30, 10}, {190, 20}},
384 {{30, 40}, {190, 20}},
385 {{30, 70}, {190, 20}},
386 {{30, 120}, {90, 20}},
387 {{30, 140}, {90, 20}},
388 {{30, 160}, {90, 20}},
389 {{30, 180}, {90, 20}},
390 {{30, 200}, {90, 20}},
391 {{30, 40}, {190, 20}},
392 {{30, 10}, {190, 20}},
393 {{155, 130}, {64, 64}},
394 {{155, 130}, {64, 64}},
395 {{155, 130}, {64, 64}},
396 {{155, 130}, {64, 64}}
399 static void str2rcolor(RContext
* rc
, const char *name
, RColor
* color
)
403 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
406 color
->red
= xcolor
.red
>> 8;
407 color
->green
= xcolor
.green
>> 8;
408 color
->blue
= xcolor
.blue
>> 8;
411 static void dumpRImage(const char *path
, RImage
* image
)
414 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
416 f
= fopen(path
, "wb");
421 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
, channels
);
423 fwrite(image
->data
, 1, image
->width
* image
->height
* channels
, f
);
431 static int isPixmap(WMPropList
* prop
)
436 p
= WMGetFromPLArray(prop
, 0);
437 s
= WMGetFromPLString(p
);
438 if (strcasecmp(&s
[1], "pixmap") == 0)
444 /**********************************************************************/
446 static void drawResizebarBevel(RImage
* img
)
450 int width
= img
->width
;
451 int height
= img
->height
;
455 light
.red
= light
.green
= light
.blue
= 80;
458 dark
.red
= dark
.green
= dark
.blue
= 40;
460 ROperateLine(img
, RSubtractOperation
, 0, 0, width
- 1, 0, &dark
);
461 ROperateLine(img
, RAddOperation
, 0, 1, width
- 1, 1, &light
);
463 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
- 1, &dark
);
464 ROperateLine(img
, RAddOperation
, cwidth
+ 1, 2, cwidth
+ 1, height
- 1, &light
);
466 ROperateLine(img
, RSubtractOperation
, width
- cwidth
- 2, 2, width
- cwidth
- 2, height
- 1, &dark
);
467 ROperateLine(img
, RAddOperation
, width
- cwidth
- 1, 2, width
- cwidth
- 1, height
- 1, &light
);
471 static void drawMenuBevel(RImage
* img
)
473 RColor light
, dark
, mid
;
475 int iheight
= img
->height
/ 4;
478 light
.red
= light
.green
= light
.blue
= 80;
481 dark
.red
= dark
.green
= dark
.blue
= 0;
484 mid
.red
= mid
.green
= mid
.blue
= 40;
486 for (i
= 1; i
< 4; i
++) {
487 ROperateLine(img
, RSubtractOperation
, 0, i
* iheight
- 2, img
->width
- 1, i
* iheight
- 2, &mid
);
489 RDrawLine(img
, 0, i
* iheight
- 1, img
->width
- 1, i
* iheight
- 1, &dark
);
491 ROperateLine(img
, RAddOperation
, 1, i
* iheight
, img
->width
- 2, i
* iheight
, &light
);
495 static Pixmap
renderTexture(WMScreen
* scr
, WMPropList
* texture
, int width
, int height
, const char *path
, int border
)
498 RImage
*image
= NULL
;
499 RImage
*timage
= NULL
;
501 RContext
*rc
= WMScreenRContext(scr
);
505 type
= WMGetFromPLString(WMGetFromPLArray(texture
, 0));
507 if (strcasecmp(&type
[1], "pixmap") == 0 ||
508 (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'T')) {
511 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
512 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
514 timage
= RLoadImage(rc
, path
, 0);
516 wwarning("could not load file '%s': %s", path
? path
: str
, RMessageForError(RErrorCode
));
517 texture
= WMCreatePropListFromDescription("(solid, black)");
524 if (strcasecmp(type
, "solid") == 0) {
526 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
528 str2rcolor(rc
, str
, &rcolor
);
530 image
= RCreateImage(width
, height
, False
);
531 RClearImage(image
, &rcolor
);
532 } else if (strcasecmp(type
, "igradient") == 0) {
536 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
537 str2rcolor(rc
, str
, &c1
[0]);
538 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
539 str2rcolor(rc
, str
, &c1
[1]);
540 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
543 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
544 str2rcolor(rc
, str
, &c2
[0]);
545 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 5));
546 str2rcolor(rc
, str
, &c2
[1]);
547 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 6));
550 image
= RRenderInterwovenGradient(width
, height
, c1
, t1
, c2
, t2
);
551 } else if (strcasecmp(&type
[1], "gradient") == 0) {
555 switch (toupper(type
[0])) {
557 style
= RVerticalGradient
;
560 style
= RHorizontalGradient
;
564 style
= RDiagonalGradient
;
568 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
569 str2rcolor(rc
, str
, &rcolor
);
570 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
571 str2rcolor(rc
, str
, &rcolor2
);
573 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
574 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'T') {
580 switch (toupper(type
[1])) {
582 style
= RVerticalGradient
;
585 style
= RHorizontalGradient
;
589 style
= RDiagonalGradient
;
593 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
594 str2rcolor(rc
, str
, &rcolor
);
595 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
596 str2rcolor(rc
, str
, &rcolor2
);
598 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
600 image
= RMakeTiledImage(timage
, width
, height
);
601 RReleaseImage(timage
);
603 i
= atoi(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
605 RCombineImagesWithOpaqueness(image
, grad
, i
);
608 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'M') {
613 switch (toupper(type
[1])) {
615 style
= RVerticalGradient
;
618 style
= RHorizontalGradient
;
622 style
= RDiagonalGradient
;
626 j
= WMGetPropListItemCount(texture
);
629 colors
= wmalloc(j
* sizeof(RColor
*));
631 for (i
= 2; i
< j
; i
++) {
632 str
= WMGetFromPLString(WMGetFromPLArray(texture
, i
));
633 colors
[i
- 2] = wmalloc(sizeof(RColor
));
634 str2rcolor(rc
, str
, colors
[i
- 2]);
636 colors
[i
- 2] = NULL
;
638 image
= RRenderMultiGradient(width
, height
, colors
, style
);
640 for (i
= 0; colors
[i
] != NULL
; i
++)
644 } else if (strcasecmp(&type
[1], "pixmap") == 0) {
647 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
648 str2rcolor(rc
, str
, &color
);
650 switch (toupper(type
[0])) {
652 image
= RMakeTiledImage(timage
, width
, height
);
653 RReleaseImage(timage
);
656 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
657 RReleaseImage(timage
);
661 image
= RScaleImage(timage
, width
, height
);
662 RReleaseImage(timage
);
671 dumpRImage(path
, image
);
675 if (border
== RESIZEBAR_BEVEL
) {
676 drawResizebarBevel(image
);
677 } else if (border
== MENU_BEVEL
) {
678 drawMenuBevel(image
);
679 RBevelImage(image
, RBEV_RAISED2
);
682 RBevelImage(image
, border
);
685 RConvertImage(rc
, image
, &pixmap
);
686 RReleaseImage(image
);
691 static Pixmap
renderMenu(_Panel
* panel
, WMPropList
* texture
, int width
, int iheight
)
693 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
694 Display
*dpy
= WMScreenDisplay(scr
);
696 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
699 switch (panel
->menuStyle
) {
701 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
703 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
* 4, WMScreenDepth(scr
));
704 for (i
= 0; i
< 4; i
++) {
705 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
* i
);
707 XFreePixmap(dpy
, tmp
);
710 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, MENU_BEVEL
);
713 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, RBEV_RAISED2
);
723 static void renderPreview(_Panel
* panel
, GC gc
, int part
, int relief
)
726 TextureListItem
*titem
;
728 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
730 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
731 titem
= (TextureListItem
*) item
->clientData
;
733 pix
= renderTexture(scr
, titem
->prop
,
734 previewPositions
[part
].size
.width
, previewPositions
[part
].size
.height
, NULL
, relief
);
736 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
737 previewPositions
[part
].size
.width
,
738 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
740 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->previewNoText
, gc
, 0, 0,
741 previewPositions
[part
].size
.width
,
742 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
744 XFreePixmap(WMScreenDisplay(scr
), pix
);
747 static void updatePreviewBox(_Panel
* panel
, int elements
)
749 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
750 Display
*dpy
= WMScreenDisplay(scr
);
755 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
757 if (panel
->preview
== None
) {
760 panel
->previewNoText
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
761 240 - 4, 215 - 4, WMScreenDepth(scr
));
762 panel
->previewBack
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
763 240 - 4, 215 - 4, WMScreenDepth(scr
));
765 p
= WMCreatePixmap(scr
, 240 - 4, 215 - 4, WMScreenDepth(scr
), False
);
766 panel
->preview
= WMGetPixmapXID(p
);
767 WMSetLabelImage(panel
->prevL
, p
);
770 if (elements
& (1 << PBACKGROUND
)) {
772 TextureListItem
*titem
;
775 item
= WMGetListItem(panel
->texLs
,
776 panel
->textureIndex
[PBACKGROUND
]);
777 titem
= (TextureListItem
*) item
->clientData
;
778 tmp
= renderTexture(scr
, titem
->prop
, 240 - 4, 215 - 4, NULL
, 0);
780 XCopyArea(dpy
, tmp
, panel
->preview
, gc
, 0, 0, 240 - 4, 215 -4 , 0, 0);
781 XCopyArea(dpy
, tmp
, panel
->previewNoText
, gc
, 0, 0, 240 - 4, 215 -4 , 0, 0);
782 XCopyArea(dpy
, tmp
, panel
->previewBack
, gc
, 0, 0, 240 - 4, 215 -4 , 0, 0);
783 XFreePixmap(dpy
, tmp
);
786 if (elements
& (1 << PFOCUSED
)) {
787 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
788 colorUpdate
|= 1 << FTITLE_COL
| 1 << FSBORDER_COL
;
790 if (elements
& (1 << PUNFOCUSED
)) {
791 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
792 colorUpdate
|= 1 << UTITLE_COL
| 1 << FBORDER_COL
;
794 if (elements
& (1 << POWNER
)) {
795 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
796 colorUpdate
|= 1 << OTITLE_COL
| 1 << FBORDER_COL
;
798 if (elements
& (1 << PRESIZEBAR
)) {
799 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
800 colorUpdate
|= 1 << FBORDER_COL
;
802 if (elements
& (1 << PMTITLE
)) {
803 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
804 colorUpdate
|= 1 << MTITLE_COL
| 1 << FBORDER_COL
;
806 if (elements
& (1 << PMITEM
)) {
808 TextureListItem
*titem
;
810 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
811 titem
= (TextureListItem
*) item
->clientData
;
813 pix
= renderMenu(panel
, titem
->prop
,
814 previewPositions
[PMITEM
].size
.width
, previewPositions
[PMITEM
].size
.height
/ 4);
816 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
817 previewPositions
[PMITEM
].size
.width
,
818 previewPositions
[PMITEM
].size
.height
,
819 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
821 XCopyArea(dpy
, pix
, panel
->previewNoText
, gc
, 0, 0,
822 previewPositions
[PMITEM
].size
.width
,
823 previewPositions
[PMITEM
].size
.height
,
824 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
826 XFreePixmap(dpy
, pix
);
828 colorUpdate
|= 1 << MITEM_COL
| 1 << MDISAB_COL
|
829 1 << MHIGH_COL
| 1 << MHIGHT_COL
|
832 if (elements
& (1 << PICON
)) {
834 TextureListItem
*titem
;
836 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
837 titem
= (TextureListItem
*) item
->clientData
;
839 renderPreview(panel
, gc
, PICON
, titem
->ispixmap
? 0 : RBEV_RAISED3
);
841 colorUpdate
|= 1 << ICONT_COL
| 1 << ICONB_COL
|
842 1 << CLIP_COL
| 1 << CCLIP_COL
;
846 updateColorPreviewBox(panel
, colorUpdate
);
848 WMRedisplayWidget(panel
->prevL
);
853 static void cancelNewTexture(void *data
)
855 _Panel
*panel
= (_Panel
*) data
;
857 HideTexturePanel(panel
->texturePanel
);
860 static char *makeFileName(const char *prefix
)
864 fname
= wstrdup(prefix
);
866 while (access(fname
, F_OK
) == 0) {
870 sprintf(buf
, "%08lx.cache", time(NULL
));
871 fname
= wstrconcat(prefix
, buf
);
877 static void okNewTexture(void *data
)
879 _Panel
*panel
= (_Panel
*) data
;
884 TextureListItem
*titem
;
885 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
887 titem
= wmalloc(sizeof(TextureListItem
));
889 HideTexturePanel(panel
->texturePanel
);
891 name
= GetTexturePanelTextureName(panel
->texturePanel
);
893 prop
= GetTexturePanelTexture(panel
->texturePanel
);
895 str
= WMGetPropListDescription(prop
, False
);
899 titem
->texture
= str
;
900 titem
->selectedFor
= 0;
902 titem
->ispixmap
= isPixmap(prop
);
904 titem
->path
= makeFileName(panel
->fprefix
);
905 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
907 item
= WMAddListItem(panel
->texLs
, "");
908 item
->clientData
= titem
;
910 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
913 static void okEditTexture(void *data
)
915 _Panel
*panel
= (_Panel
*) data
;
920 TextureListItem
*titem
;
922 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
923 titem
= (TextureListItem
*) item
->clientData
;
925 HideTexturePanel(panel
->texturePanel
);
927 if (titem
->current
) {
928 name
= GetTexturePanelTextureName(panel
->texturePanel
);
934 prop
= GetTexturePanelTexture(panel
->texturePanel
);
936 str
= WMGetPropListDescription(prop
, False
);
938 WMReleasePropList(titem
->prop
);
941 titem
->ispixmap
= isPixmap(prop
);
943 wfree(titem
->texture
);
944 titem
->texture
= str
;
946 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
947 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
948 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
950 WMRedisplayWidget(panel
->texLs
);
952 if (titem
->selectedFor
) {
953 if (titem
->selectedFor
& (1 << PBACKGROUND
))
954 updatePreviewBox(panel
, EVERYTHING
);
956 updatePreviewBox(panel
, titem
->selectedFor
);
959 changePage(panel
->secP
, panel
);
962 static void editTexture(WMWidget
* w
, void *data
)
964 _Panel
*panel
= (_Panel
*) data
;
966 TextureListItem
*titem
;
968 /* Parameter not used, but tell the compiler that it is ok */
971 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
972 titem
= (TextureListItem
*) item
->clientData
;
974 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
976 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
978 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
979 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
981 ShowTexturePanel(panel
->texturePanel
);
984 static void newTexture(WMWidget
* w
, void *data
)
986 _Panel
*panel
= (_Panel
*) data
;
988 /* Parameter not used, but tell the compiler that it is ok */
991 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
993 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
995 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
997 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
999 ShowTexturePanel(panel
->texturePanel
);
1002 static void deleteTexture(WMWidget
* w
, void *data
)
1004 _Panel
*panel
= (_Panel
*) data
;
1006 TextureListItem
*titem
;
1010 /* Parameter not used, but tell the compiler that it is ok */
1013 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1014 row
= WMGetListSelectedItemRow(panel
->texLs
);
1015 item
= WMGetListItem(panel
->texLs
, row
);
1016 titem
= (TextureListItem
*) item
->clientData
;
1018 if (titem
->selectedFor
& (1 << section
)) {
1019 TextureListItem
*titem2
;
1021 panel
->textureIndex
[section
] = section
;
1022 item
= WMGetListItem(panel
->texLs
, section
);
1023 titem2
= (TextureListItem
*) item
->clientData
;
1024 titem2
->selectedFor
|= 1 << section
;
1027 wfree(titem
->title
);
1028 wfree(titem
->texture
);
1029 WMReleasePropList(titem
->prop
);
1031 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1032 werror("could not remove file %s", titem
->path
);
1039 WMRemoveListItem(panel
->texLs
, row
);
1040 WMSetButtonEnabled(panel
->delB
, False
);
1043 static void extractTexture(WMWidget
* w
, void *data
)
1045 _Panel
*panel
= (_Panel
*) data
;
1047 WMOpenPanel
*opanel
;
1048 WMScreen
*scr
= WMWidgetScreen(w
);
1050 opanel
= WMGetOpenPanel(scr
);
1051 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1052 WMSetFilePanelCanChooseFiles(opanel
, True
);
1054 if (WMRunModalFilePanelForDirectory(opanel
, panel
->parent
, wgethomedir(), _("Select File"), NULL
)) {
1055 path
= WMGetFilePanelFileName(opanel
);
1057 OpenExtractPanelFor(panel
);
1063 static void changePage(WMWidget
* w
, void *data
)
1065 _Panel
*panel
= (_Panel
*) data
;
1067 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1068 RContext
*rc
= WMScreenRContext(scr
);
1069 static WMPoint positions
[] = {
1080 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1082 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1084 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1089 gc
= XCreateGC(rc
->dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
1090 XCopyArea(rc
->dpy
, panel
->previewBack
, panel
->preview
, gc
,
1091 positions
[panel
->oldsection
].x
,
1092 positions
[panel
->oldsection
].y
, 22, 22 ,
1093 positions
[panel
->oldsection
].x
,
1094 positions
[panel
->oldsection
].y
);
1097 panel
->oldsection
= section
;
1098 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1100 WMRedisplayWidget(panel
->prevL
);
1103 static void previewClick(XEvent
* event
, void *clientData
)
1105 _Panel
*panel
= (_Panel
*) clientData
;
1108 switch (panel
->oldTabItem
) {
1110 for (i
= 0; i
< wlengthof(previewPositions
); i
++) {
1111 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
1112 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
1113 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
1114 + previewPositions
[i
].size
.width
1115 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
+ previewPositions
[i
].size
.height
) {
1117 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1118 changePage(panel
->secP
, panel
);
1124 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1125 if (event
->xbutton
.x
>= previewColorPositions
[i
].pos
.x
1126 && event
->xbutton
.y
>= previewColorPositions
[i
].pos
.y
1127 && event
->xbutton
.x
< previewColorPositions
[i
].pos
.x
1128 + previewColorPositions
[i
].size
.width
1129 && event
->xbutton
.y
< previewColorPositions
[i
].pos
.y
1130 + previewColorPositions
[i
].size
.height
) {
1136 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1137 changeColorPage(panel
->colP
, panel
);
1145 static void textureClick(WMWidget
* w
, void *data
)
1147 _Panel
*panel
= (_Panel
*) data
;
1150 TextureListItem
*titem
;
1152 /* Parameter not used, but tell the compiler that it is ok */
1155 i
= WMGetListSelectedItemRow(panel
->texLs
);
1157 item
= WMGetListItem(panel
->texLs
, i
);
1159 titem
= (TextureListItem
*) item
->clientData
;
1161 if (titem
->current
) {
1162 WMSetButtonEnabled(panel
->delB
, False
);
1164 WMSetButtonEnabled(panel
->delB
, True
);
1168 static void textureDoubleClick(WMWidget
* w
, void *data
)
1170 _Panel
*panel
= (_Panel
*) data
;
1173 TextureListItem
*titem
;
1175 /* Parameter not used, but tell the compiler that it is ok */
1178 /* unselect old texture */
1179 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1181 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1182 titem
= (TextureListItem
*) item
->clientData
;
1183 titem
->selectedFor
&= ~(1 << section
);
1185 /* select new texture */
1186 i
= WMGetListSelectedItemRow(panel
->texLs
);
1188 item
= WMGetListItem(panel
->texLs
, i
);
1190 titem
= (TextureListItem
*) item
->clientData
;
1192 titem
->selectedFor
|= 1 << section
;
1194 panel
->textureIndex
[section
] = i
;
1196 WMRedisplayWidget(panel
->texLs
);
1198 if (section
== PBACKGROUND
)
1199 updatePreviewBox(panel
, EVERYTHING
);
1201 updatePreviewBox(panel
, 1 << section
);
1204 static void paintListItem(WMList
* lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
* rect
)
1206 _Panel
*panel
= (_Panel
*) WMGetHangedData(lPtr
);
1207 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1208 int width
, height
, x
, y
;
1209 Display
*dpy
= WMScreenDisplay(scr
);
1210 WMColor
*back
= (state
& WLDSSelected
) ? WMWhiteColor(scr
) : WMGrayColor(scr
);
1212 WMColor
*black
= WMBlackColor(scr
);
1213 TextureListItem
*titem
;
1215 /* Parameter not used, but tell the compiler that it is ok */
1218 item
= WMGetListItem(lPtr
, index
);
1219 titem
= (TextureListItem
*) item
->clientData
;
1221 WMReleaseColor(back
);
1222 WMReleaseColor(black
);
1226 width
= rect
->size
.width
;
1227 height
= rect
->size
.height
;
1231 XFillRectangle(dpy
, d
, WMColorGC(back
), x
, y
, width
, height
);
1234 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0,
1235 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1237 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1238 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1239 else if (titem
->selectedFor
)
1240 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1242 WMDrawString(scr
, d
, black
, panel
->boldFont
,
1243 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
, strlen(titem
->title
));
1245 WMDrawString(scr
, d
, black
, panel
->smallFont
,
1246 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
, strlen(titem
->texture
));
1248 WMReleaseColor(back
);
1249 WMReleaseColor(black
);
1252 static Pixmap
loadRImage(WMScreen
* scr
, const char *path
)
1260 f
= fopen(path
, "rb");
1264 cnt
= fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1269 image
= RCreateImage(w
, h
, d
== 4);
1270 read_size
= w
* h
* d
;
1271 if (fread(image
->data
, 1, read_size
, f
) != read_size
) {
1277 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1278 RReleaseImage(image
);
1283 static void fillTextureList(WMList
* lPtr
)
1285 WMPropList
*textureList
;
1286 WMPropList
*texture
;
1287 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1288 TextureListItem
*titem
;
1289 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1292 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1296 for (i
= 0; i
< WMGetPropListItemCount(textureList
); i
++) {
1299 texture
= WMGetFromPLArray(textureList
, i
);
1301 titem
= wmalloc(sizeof(TextureListItem
));
1303 titem
->title
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 0)));
1304 titem
->prop
= WMRetainPropList(WMGetFromPLArray(texture
, 1));
1305 titem
->texture
= WMGetPropListDescription(titem
->prop
, False
);
1306 titem
->selectedFor
= 0;
1307 titem
->path
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
1309 titem
->preview
= loadRImage(scr
, titem
->path
);
1310 if (!titem
->preview
) {
1311 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1313 item
= WMAddListItem(lPtr
, "");
1314 item
->clientData
= titem
;
1318 static void fillColorList(_Panel
* panel
)
1322 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1323 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1326 list
= WMGetUDObjectForKey(udb
, "ColorList");
1328 for (i
= 0; i
< 24; i
++) {
1329 color
= WMCreateNamedColor(scr
, sampleColors
[i
], False
);
1332 WMSetColorWellColor(panel
->sampW
[i
], color
);
1333 WMReleaseColor(color
);
1338 for (i
= 0; i
< WMIN(24, WMGetPropListItemCount(list
)); i
++) {
1339 c
= WMGetFromPLArray(list
, i
);
1340 if (!c
|| !WMIsPLString(c
))
1342 color
= WMCreateNamedColor(scr
, WMGetFromPLString(c
), False
);
1345 WMSetColorWellColor(panel
->sampW
[i
], color
);
1346 WMReleaseColor(color
);
1351 /*************************************************************************/
1353 static void changeColorPage(WMWidget
* w
, void *data
)
1355 _Panel
*panel
= (_Panel
*) data
;
1357 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1358 RContext
*rc
= WMScreenRContext(scr
);
1359 static WMPoint positions
[] = {
1376 if (panel
->preview
) {
1379 gc
= XCreateGC(rc
->dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
1380 XCopyArea(rc
->dpy
, panel
->previewBack
, panel
->preview
, gc
,
1381 positions
[panel
->oldcsection
].x
,
1382 positions
[panel
->oldcsection
].y
, 22, 22 ,
1383 positions
[panel
->oldcsection
].x
,
1384 positions
[panel
->oldcsection
].y
);
1387 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1389 panel
->oldcsection
= section
;
1391 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1393 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1395 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1397 WMRedisplayWidget(panel
->prevL
);
1401 paintText(WMScreen
* scr
, Drawable d
, WMColor
* color
, WMFont
* font
,
1402 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1404 int l
= strlen(text
);
1411 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1415 x
+= (w
- WMWidthOfString(font
, text
, l
)) / 2;
1418 WMDrawString(scr
, d
, color
, font
, x
, y
+ (h
- WMFontHeight(font
)) / 2, text
, l
);
1421 static void updateColorPreviewBox(_Panel
* panel
, int elements
)
1423 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1424 Display
*dpy
= WMScreenDisplay(scr
);
1429 pnot
= panel
->previewNoText
;
1430 gc
= WMColorGC(panel
->colors
[FTITLE_COL
]);
1432 if (elements
& (1 << FTITLE_COL
)) {
1433 XCopyArea(dpy
, pnot
, d
, gc
, 30, 10, 190, 20, 30, 10);
1434 paintText(scr
, d
, panel
->colors
[FTITLE_COL
],
1435 panel
->boldFont
, 30, 10, 190, 20,
1436 panel
->titleAlignment
, _("Focused Window"));
1438 if (elements
& (1 << UTITLE_COL
)) {
1439 XCopyArea(dpy
, pnot
, d
, gc
, 30, 40, 190, 20, 30, 40);
1440 paintText(scr
, d
, panel
->colors
[UTITLE_COL
],
1441 panel
->boldFont
, 30, 40, 190, 20,
1442 panel
->titleAlignment
,
1443 _("Unfocused Window"));
1445 if (elements
& (1 << OTITLE_COL
)) {
1446 XCopyArea(dpy
, pnot
, d
, gc
, 30, 70, 190, 20, 30, 70);
1447 paintText(scr
, d
, panel
->colors
[OTITLE_COL
],
1448 panel
->boldFont
, 30, 70, 190, 20,
1449 panel
->titleAlignment
,
1450 _("Owner of Focused Window"));
1452 if (elements
& (1 << MTITLE_COL
)) {
1453 XCopyArea(dpy
, pnot
, d
, gc
, 30, 120, 90, 20, 30, 120);
1454 paintText(scr
, d
, panel
->colors
[MTITLE_COL
],
1455 panel
->boldFont
, 30, 120, 90, 20, WALeft
,
1458 if (elements
& (1 << MITEM_COL
)) {
1459 XCopyArea(dpy
, pnot
, d
, gc
, 30, 140, 90, 20, 30, 140);
1460 paintText(scr
, d
, panel
->colors
[MITEM_COL
],
1461 panel
->normalFont
, 30, 140, 90, 20, WALeft
,
1463 XCopyArea(dpy
, pnot
, d
, gc
, 30, 200, 90, 20, 30, 200);
1464 paintText(scr
, d
, panel
->colors
[MITEM_COL
],
1465 panel
->normalFont
, 30, 200, 90, 20, WALeft
,
1468 if (elements
& (1 << MDISAB_COL
)) {
1469 XCopyArea(dpy
, pnot
, d
, gc
, 30, 160, 90, 20, 30, 160);
1470 paintText(scr
, d
, panel
->colors
[MDISAB_COL
],
1471 panel
->normalFont
, 30, 160, 90, 20, WALeft
,
1472 _("Disabled Item"));
1474 if (elements
& (1 << MHIGH_COL
)) {
1475 XFillRectangle(WMScreenDisplay(scr
), d
,
1476 WMColorGC(panel
->colors
[MHIGH_COL
]),
1478 XFillRectangle(WMScreenDisplay(scr
), pnot
,
1479 WMColorGC(panel
->colors
[MHIGH_COL
]),
1481 elements
|= 1 << MHIGHT_COL
;
1483 if (elements
& (1 << MHIGHT_COL
)) {
1484 XCopyArea(dpy
, pnot
, d
, gc
, 30, 180, 90, 20, 30, 180);
1485 paintText(scr
, d
, panel
->colors
[MHIGHT_COL
],
1486 panel
->normalFont
, 30, 180, 90, 20, WALeft
,
1489 if (elements
& (1 << FBORDER_COL
)) {
1490 XDrawRectangle(dpy
, pnot
,
1491 WMColorGC(panel
->colors
[FBORDER_COL
]),
1493 XDrawRectangle(dpy
, d
,
1494 WMColorGC(panel
->colors
[FBORDER_COL
]),
1496 XDrawRectangle(dpy
, pnot
,
1497 WMColorGC(panel
->colors
[FBORDER_COL
]),
1499 XDrawRectangle(dpy
, d
,
1500 WMColorGC(panel
->colors
[FBORDER_COL
]),
1502 XDrawLine(dpy
, pnot
,
1503 WMColorGC(panel
->colors
[FBORDER_COL
]),
1506 WMColorGC(panel
->colors
[FBORDER_COL
]),
1508 XDrawLine(dpy
, pnot
,
1509 WMColorGC(panel
->colors
[FBORDER_COL
]),
1512 WMColorGC(panel
->colors
[FBORDER_COL
]),
1514 XDrawLine(dpy
, pnot
,
1515 WMColorGC(panel
->colors
[FBORDER_COL
]),
1516 220, 100, 220, 109);
1518 WMColorGC(panel
->colors
[FBORDER_COL
]),
1519 220, 100, 220, 109);
1520 XDrawLine(dpy
, pnot
,
1521 WMColorGC(panel
->colors
[FBORDER_COL
]),
1524 WMColorGC(panel
->colors
[FBORDER_COL
]),
1526 XDrawLine(dpy
, pnot
,
1527 WMColorGC(panel
->colors
[FBORDER_COL
]),
1530 WMColorGC(panel
->colors
[FBORDER_COL
]),
1532 XDrawLine(dpy
, pnot
,
1533 WMColorGC(panel
->colors
[FBORDER_COL
]),
1534 119, 120, 119, 220);
1536 WMColorGC(panel
->colors
[FBORDER_COL
]),
1537 119, 120, 119, 220);
1539 if (elements
& (1 << FSBORDER_COL
)) {
1540 XDrawRectangle(dpy
, pnot
,
1542 colors
[FSBORDER_COL
]),
1544 XDrawRectangle(dpy
, d
,
1546 colors
[FSBORDER_COL
]),
1551 if (elements & (1 << ICONT_COL)) {
1552 WRITE(_("Focused Window"), panel->colors[ICONT_COL],
1556 if (elements & (1 << ICONB_COL)) {
1557 WRITE(_("Focused Window"), panel->colors[ICONB_COL],
1561 if (elements & (1 << CLIP_COL)) {
1562 WRITE(_("Focused Window"), panel->colors[CLIP_COL],
1566 if (elements & (1 << CCLIP_COL)) {
1567 WRITE(_("Focused Window"), panel->colors[CCLIP_COL],
1572 WMRedisplayWidget(panel
->prevL
);
1575 static void colorWellObserver(void *self
, WMNotification
* n
)
1577 _Panel
*panel
= (_Panel
*) self
;
1580 /* Parameter not used, but tell the compiler that it is ok */
1583 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1585 WMReleaseColor(panel
->colors
[p
]);
1587 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1589 updateColorPreviewBox(panel
, 1 << p
);
1592 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
)
1594 _Panel
*panel
= self
->data
;
1597 /* Parameter not used, but tell the compiler that it is ok */
1600 i
= WMGetTabViewItemIdentifier(item
);
1603 switch (panel
->oldTabItem
) {
1605 changeColorPage(NULL
, panel
);
1608 changePage(panel
->secP
, panel
);
1611 switch (panel
->oldTabItem
) {
1613 changePage(NULL
, panel
);
1616 changeColorPage(panel
->colP
, panel
);
1619 switch (panel
->oldTabItem
) {
1621 changePage(NULL
, panel
);
1624 changeColorPage(NULL
, panel
);
1630 panel
->oldTabItem
= i
;
1633 /*************************************************************************/
1635 static void menuStyleCallback(WMWidget
* self
, void *data
)
1637 _Panel
*panel
= (_Panel
*) data
;
1639 if (self
== panel
->mstyB
[0]) {
1640 panel
->menuStyle
= MSTYLE_NORMAL
;
1641 updatePreviewBox(panel
, 1 << PMITEM
);
1643 } else if (self
== panel
->mstyB
[1]) {
1644 panel
->menuStyle
= MSTYLE_SINGLE
;
1645 updatePreviewBox(panel
, 1 << PMITEM
);
1647 } else if (self
== panel
->mstyB
[2]) {
1648 panel
->menuStyle
= MSTYLE_FLAT
;
1649 updatePreviewBox(panel
, 1 << PMITEM
);
1653 static void titleAlignCallback(WMWidget
* self
, void *data
)
1655 _Panel
*panel
= (_Panel
*) data
;
1657 if (self
== panel
->taliB
[0]) {
1658 panel
->titleAlignment
= WALeft
;
1659 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1661 } else if (self
== panel
->taliB
[1]) {
1662 panel
->titleAlignment
= WACenter
;
1663 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1665 } else if (self
== panel
->taliB
[2]) {
1666 panel
->titleAlignment
= WARight
;
1667 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1671 static void createPanel(Panel
* p
)
1673 _Panel
*panel
= (_Panel
*) p
;
1675 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1676 WMTabViewItem
*item
;
1681 panel
->fprefix
= wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1683 if (access(panel
->fprefix
, F_OK
) != 0) {
1684 if (mkdir(panel
->fprefix
, 0755) < 0) {
1685 werror("%s", panel
->fprefix
);
1690 tmp
= wstrconcat(panel
->fprefix
, "/WPrefs/");
1691 wfree(panel
->fprefix
);
1692 panel
->fprefix
= tmp
;
1693 if (access(panel
->fprefix
, F_OK
) != 0) {
1694 if (mkdir(panel
->fprefix
, 0755) < 0) {
1695 werror("%s", panel
->fprefix
);
1700 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1701 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1702 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1704 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1705 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1706 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1708 panel
->box
= WMCreateBox(panel
->parent
);
1709 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
1712 panel
->prevL
= WMCreateLabel(panel
->box
);
1713 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1714 WMMoveWidget(panel
->prevL
, 15, 10);
1715 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1716 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1718 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
, previewClick
, panel
);
1722 tabviewDelegate
.data
= panel
;
1724 panel
->tabv
= WMCreateTabView(panel
->box
);
1725 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1726 WMMoveWidget(panel
->tabv
, 265, 10);
1727 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1729 /*** texture list ***/
1731 panel
->texF
= WMCreateFrame(panel
->box
);
1732 WMSetFrameRelief(panel
->texF
, WRFlat
);
1734 item
= WMCreateTabViewItemWithIdentifier(TAB_TEXTURE
);
1735 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1736 WMSetTabViewItemLabel(item
, _("Texture"));
1738 WMAddItemInTabView(panel
->tabv
, item
);
1740 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1741 WMResizeWidget(panel
->secP
, 228, 20);
1742 WMMoveWidget(panel
->secP
, 7, 7);
1743 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1744 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1745 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1746 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1747 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1748 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1749 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1750 WMAddPopUpButtonItem(panel
->secP
, _("Workspace Background"));
1752 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1753 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1755 panel
->texLs
= WMCreateList(panel
->texF
);
1756 WMResizeWidget(panel
->texLs
, 165, 155);
1757 WMMoveWidget(panel
->texLs
, 70, 33);
1758 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1759 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1760 WMHangData(panel
->texLs
, panel
);
1761 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1762 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1764 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1765 "for the selected item."), WMWidgetView(panel
->texLs
));
1767 /* command buttons */
1769 font
= WMSystemFontOfSize(scr
, 10);
1771 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1772 WMResizeWidget(panel
->newB
, 57, 39);
1773 WMMoveWidget(panel
->newB
, 7, 33);
1774 WMSetButtonFont(panel
->newB
, font
);
1775 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1776 WMSetButtonText(panel
->newB
, _("New"));
1777 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1778 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1780 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel
->newB
));
1782 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1783 WMResizeWidget(panel
->ripB
, 57, 39);
1784 WMMoveWidget(panel
->ripB
, 7, 72);
1785 WMSetButtonFont(panel
->ripB
, font
);
1786 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1787 WMSetButtonText(panel
->ripB
, _("Extract..."));
1788 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1789 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1791 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel
->ripB
));
1793 WMSetButtonEnabled(panel
->ripB
, False
);
1795 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1796 WMResizeWidget(panel
->editB
, 57, 39);
1797 WMMoveWidget(panel
->editB
, 7, 111);
1798 WMSetButtonFont(panel
->editB
, font
);
1799 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1800 WMSetButtonText(panel
->editB
, _("Edit"));
1801 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1802 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1803 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel
->editB
));
1805 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1806 WMResizeWidget(panel
->delB
, 57, 38);
1807 WMMoveWidget(panel
->delB
, 7, 150);
1808 WMSetButtonFont(panel
->delB
, font
);
1809 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1810 WMSetButtonText(panel
->delB
, _("Delete"));
1811 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1812 WMSetButtonEnabled(panel
->delB
, False
);
1813 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1814 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel
->delB
));
1816 WMReleaseFont(font
);
1818 WMMapSubwidgets(panel
->texF
);
1821 panel
->colF
= WMCreateFrame(panel
->box
);
1822 WMSetFrameRelief(panel
->colF
, WRFlat
);
1824 item
= WMCreateTabViewItemWithIdentifier(TAB_COLOR
);
1825 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1826 WMSetTabViewItemLabel(item
, _("Color"));
1828 WMAddItemInTabView(panel
->tabv
, item
);
1830 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1831 WMResizeWidget(panel
->colP
, 228, 20);
1832 WMMoveWidget(panel
->colP
, 7, 7);
1833 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Title"));
1834 WMAddPopUpButtonItem(panel
->colP
, _("Unfocused Window Title"));
1835 WMAddPopUpButtonItem(panel
->colP
, _("Owner of Focused Window Title"));
1836 WMAddPopUpButtonItem(panel
->colP
, _("Menu Title"));
1837 WMAddPopUpButtonItem(panel
->colP
, _("Menu Item Text"));
1838 WMAddPopUpButtonItem(panel
->colP
, _("Disabled Menu Item Text"));
1839 WMAddPopUpButtonItem(panel
->colP
, _("Menu Highlight Color"));
1840 WMAddPopUpButtonItem(panel
->colP
, _("Highlighted Menu Text Color"));
1841 WMAddPopUpButtonItem(panel
->colP
, _("Frame Border Color"));
1842 WMAddPopUpButtonItem(panel
->colP
, _("Selected Frame Border Color"));
1844 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1845 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1846 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1847 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1850 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1852 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1854 panel
->colW
= WMCreateColorWell(panel
->colF
);
1855 WMResizeWidget(panel
->colW
, 65, 50);
1856 WMMoveWidget(panel
->colW
, 30, 75);
1857 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->colW
);
1859 for (i
= 0; i
< 4; i
++) {
1861 for (j
= 0; j
< 6; j
++) {
1862 panel
->sampW
[i
+ j
* 4] = WMCreateColorWell(panel
->colF
);
1863 WMResizeWidget(panel
->sampW
[i
+ j
* 4], 22, 22);
1864 WMMoveWidget(panel
->sampW
[i
+ j
* 4], 130 + i
* 22, 40 + j
* 22);
1865 WSetColorWellBordered(panel
->sampW
[i
+ j
* 4], False
);
1869 WMMapSubwidgets(panel
->colF
);
1872 panel
->optF
= WMCreateFrame(panel
->box
);
1873 WMSetFrameRelief(panel
->optF
, WRFlat
);
1875 item
= WMCreateTabViewItemWithIdentifier(TAB_OPTIONS
);
1876 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1877 WMSetTabViewItemLabel(item
, _("Options"));
1879 WMAddItemInTabView(panel
->tabv
, item
);
1881 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1882 WMResizeWidget(panel
->mstyF
, 215, 85);
1883 WMMoveWidget(panel
->mstyF
, 15, 10);
1884 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1886 for (i
= 0; i
< 3; i
++) {
1890 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1891 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1892 WMMoveWidget(panel
->mstyB
[i
], 15 + i
* 65, 20);
1893 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1894 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1897 path
= LocateImage(MSTYLE1_FILE
);
1900 path
= LocateImage(MSTYLE2_FILE
);
1903 path
= LocateImage(MSTYLE3_FILE
);
1907 icon
= WMCreatePixmapFromFile(scr
, path
);
1909 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1910 WMReleasePixmap(icon
);
1912 wwarning(_("could not load icon file %s"), path
);
1917 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1918 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1920 WMMapSubwidgets(panel
->mstyF
);
1922 panel
->taliF
= WMCreateFrame(panel
->optF
);
1923 WMResizeWidget(panel
->taliF
, 110, 80);
1924 WMMoveWidget(panel
->taliF
, 15, 100);
1925 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
1927 for (i
= 0; i
< 3; i
++) {
1928 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
1929 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
1932 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1935 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1938 WMSetButtonText(panel
->taliB
[i
], _("Right"));
1941 WMResizeWidget(panel
->taliB
[i
], 90, 18);
1942 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20 * i
);
1944 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
1945 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
1947 WMMapSubwidgets(panel
->taliF
);
1949 WMMapSubwidgets(panel
->optF
);
1951 /**/ WMRealizeWidget(panel
->box
);
1952 WMMapSubwidgets(panel
->box
);
1954 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1958 changePage(panel
->secP
, panel
);
1960 fillTextureList(panel
->texLs
);
1962 fillColorList(panel
);
1964 panel
->texturePanel
= CreateTexturePanel(panel
->parent
);
1967 static void setupTextureFor(WMList
*list
, const char *key
, const char *defValue
, const char *title
, int index
)
1970 TextureListItem
*titem
;
1972 titem
= wmalloc(sizeof(TextureListItem
));
1974 titem
->title
= wstrdup(title
);
1975 titem
->prop
= GetObjectForKey(key
);
1976 if (!titem
->prop
|| !WMIsPLArray(titem
->prop
)) {
1977 /* Maybe also give a error message to stderr that the entry is bad? */
1978 titem
->prop
= WMCreatePropListFromDescription(defValue
);
1980 WMRetainPropList(titem
->prop
);
1982 titem
->texture
= WMGetPropListDescription((WMPropList
*) titem
->prop
, False
);
1984 titem
->selectedFor
= 1 << index
;
1986 titem
->ispixmap
= isPixmap(titem
->prop
);
1988 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1990 item
= WMAddListItem(list
, "");
1991 item
->clientData
= titem
;
1994 static void showData(_Panel
* panel
)
1999 str
= GetStringForKey("MenuStyle");
2000 if (str
&& strcasecmp(str
, "flat") == 0) {
2001 panel
->menuStyle
= MSTYLE_FLAT
;
2002 } else if (str
&& strcasecmp(str
, "singletexture") == 0) {
2003 panel
->menuStyle
= MSTYLE_SINGLE
;
2005 panel
->menuStyle
= MSTYLE_NORMAL
;
2008 str
= GetStringForKey("TitleJustify");
2009 if (str
&& strcasecmp(str
, "left") == 0) {
2010 panel
->titleAlignment
= WALeft
;
2011 } else if (str
&& strcasecmp(str
, "right") == 0) {
2012 panel
->titleAlignment
= WARight
;
2014 panel
->titleAlignment
= WACenter
;
2017 for (i
= 0; i
< wlengthof(colorOptions
); i
++) {
2020 str
= GetStringForKey(colorOptions
[i
].key
);
2022 str
= colorOptions
[i
].default_value
;
2024 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), str
, False
))) {
2025 color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), "#000000", False
);
2028 panel
->colors
[i
] = color
;
2030 changeColorPage(panel
->colP
, panel
);
2032 for (i
= 0; i
< wlengthof(textureOptions
); i
++) {
2033 setupTextureFor(panel
->texLs
, textureOptions
[i
].key
,
2034 textureOptions
[i
].default_value
, _(textureOptions
[i
].label
), i
);
2035 panel
->textureIndex
[i
] = i
;
2037 updatePreviewBox(panel
, EVERYTHING
);
2039 WMSetButtonSelected(panel
->mstyB
[panel
->menuStyle
], True
);
2040 WMSetButtonSelected(panel
->taliB
[panel
->titleAlignment
], True
);
2043 static void storeData(_Panel
* panel
)
2045 TextureListItem
*titem
;
2049 for (i
= 0; i
< wlengthof(textureOptions
); i
++) {
2050 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
2051 titem
= (TextureListItem
*) item
->clientData
;
2052 SetObjectForKey(titem
->prop
, textureOptions
[i
].key
);
2055 for (i
= 0; i
< wlengthof(colorOptions
); i
++) {
2058 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
2061 SetStringForKey(str
, colorOptions
[i
].key
);
2066 switch (panel
->menuStyle
) {
2068 SetStringForKey("singletexture", "MenuStyle");
2071 SetStringForKey("flat", "MenuStyle");
2075 SetStringForKey("normal", "MenuStyle");
2078 switch (panel
->titleAlignment
) {
2080 SetStringForKey("left", "TitleJustify");
2083 SetStringForKey("right", "TitleJustify");
2087 SetStringForKey("center", "TitleJustify");
2092 static void prepareForClose(_Panel
* panel
)
2094 WMPropList
*textureList
;
2095 WMPropList
*texture
;
2096 TextureListItem
*titem
;
2098 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2101 textureList
= WMCreatePLArray(NULL
, NULL
);
2103 /* store list of textures */
2104 for (i
= 8; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2105 item
= WMGetListItem(panel
->texLs
, i
);
2106 titem
= (TextureListItem
*) item
->clientData
;
2108 texture
= WMCreatePLArray(WMCreatePLString(titem
->title
),
2109 WMRetainPropList(titem
->prop
), WMCreatePLString(titem
->path
), NULL
);
2111 WMAddToPLArray(textureList
, texture
);
2114 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2115 WMReleasePropList(textureList
);
2117 /* store list of colors */
2118 textureList
= WMCreatePLArray(NULL
, NULL
);
2119 for (i
= 0; i
< 24; i
++) {
2123 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2125 str
= WMGetColorRGBDescription(color
);
2126 WMAddToPLArray(textureList
, WMCreatePLString(str
));
2129 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2130 WMReleasePropList(textureList
);
2132 WMSynchronizeUserDefaults(udb
);
2135 Panel
*InitAppearance(WMWidget
*parent
)
2139 panel
= wmalloc(sizeof(_Panel
));
2141 panel
->sectionName
= _("Appearance Preferences");
2143 panel
->description
= _("Background texture configuration for windows,\n" "menus and icons.");
2145 panel
->parent
= parent
;
2147 panel
->callbacks
.createWidgets
= createPanel
;
2148 panel
->callbacks
.updateDomain
= storeData
;
2149 panel
->callbacks
.prepareForClose
= prepareForClose
;
2151 AddSection(panel
, ICON_FILE
);
2156 /****************************************************************************/
2158 typedef struct ExtractPanel
{
2168 static void OpenExtractPanelFor(_Panel
*panel
)
2170 ExtractPanel
*epanel
;
2173 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
2175 epanel
= wmalloc(sizeof(ExtractPanel
));
2176 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->parent
, "extract",
2177 WMTitledWindowMask
| WMClosableWindowMask
);
2178 WMResizeWidget(epanel
->win
, 245, 250);
2179 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2181 epanel
->label
= WMCreateLabel(epanel
->win
);
2182 WMResizeWidget(epanel
->label
, 225, 18);
2183 WMMoveWidget(epanel
->label
, 10, 10);
2184 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2185 WMSetLabelRelief(epanel
->label
, WRSunken
);
2187 color
= WMDarkGrayColor(scr
);
2188 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2189 WMReleaseColor(color
);
2191 color
= WMWhiteColor(scr
);
2192 WMSetLabelTextColor(epanel
->label
, color
);
2193 WMReleaseColor(color
);
2195 font
= WMBoldSystemFontOfSize(scr
, 12);
2196 WMSetLabelFont(epanel
->label
, font
);
2197 WMReleaseFont(font
);
2199 WMSetLabelText(epanel
->label
, _("Textures"));
2201 epanel
->list
= WMCreateList(epanel
->win
);
2202 WMResizeWidget(epanel
->list
, 225, 165);
2203 WMMoveWidget(epanel
->list
, 10, 30);
2205 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2206 WMResizeWidget(epanel
->closeB
, 74, 24);
2207 WMMoveWidget(epanel
->closeB
, 165, 215);
2208 WMSetButtonText(epanel
->closeB
, _("Close"));
2210 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2211 WMResizeWidget(epanel
->extrB
, 74, 24);
2212 WMMoveWidget(epanel
->extrB
, 80, 215);
2213 WMSetButtonText(epanel
->extrB
, _("Extract"));
2215 WMMapSubwidgets(epanel
->win
);
2217 /* take textures from file */
2219 WMRealizeWidget(epanel
->win
);
2221 WMMapWidget(epanel
->win
);