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];
84 WMPopUpButton
*modeB
[3];
94 TexturePanel
*texturePanel
;
110 Pixmap previewNoText
;
128 static void updateColorPreviewBox(_Panel
* panel
, int elements
);
130 static void showData(_Panel
* panel
);
132 static void changePage(WMWidget
* w
, void *data
);
134 static void changeColorPage(WMWidget
* w
, void *data
);
136 static void OpenExtractPanelFor(_Panel
*panel
);
138 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
);
140 static WMTabViewDelegate tabviewDelegate
= {
142 NULL
, /* didChangeNumberOfItems */
143 changedTabItem
, /* didSelectItem */
144 NULL
, /* shouldSelectItem */
145 NULL
/* willSelectItem */
148 #define ICON_FILE "appearance"
150 #define TNEW_FILE "tnew"
151 #define TDEL_FILE "tdel"
152 #define TEDIT_FILE "tedit"
153 #define TEXTR_FILE "textr"
155 #define MSTYLE1_FILE "msty1"
156 #define MSTYLE2_FILE "msty2"
157 #define MSTYLE3_FILE "msty3"
160 static char *blueled_xpm
[] = {
190 static char *blueled2_xpm
[] = {
191 /* width height num_colors chars_per_pixel */
223 static char *hand_xpm
[] = {
247 " .%%%&@.......... ",
248 " .%*%%&#%%%%%%%%%$. ",
249 " .*#%%%%%%%%%&&&&==. ",
250 " .-%%%%%%%%%=*-;;;#$. ",
251 " .-%%%%%%%%&..>..... ",
267 static char *sampleColors
[] = {
295 static const struct {
297 const char *default_value
;
299 } textureOptions
[] = {
300 { "FTitleBack", "(solid, black)", N_("[Focused]") },
301 { "UTitleBack", "(solid, gray)", N_("[Unfocused]") },
302 { "PTitleBack", "(solid, \"#616161\")", N_("[Owner of Focused]") },
303 { "ResizebarBack", "(solid, gray)", N_("[Resizebar]") },
304 { "MenuTitleBack", "(solid, black)", N_("[Menu Title]") },
305 { "MenuTextBack", "(solid, gray)", N_("[Menu Item]") },
306 { "IconBack", "(solid, gray)", N_("[Icon]") }
309 #define RESIZEBAR_BEVEL -1
310 #define MENU_BEVEL -2
312 #define TEXPREV_WIDTH 40
313 #define TEXPREV_HEIGHT 24
315 #define MSTYLE_NORMAL 0
316 #define MSTYLE_SINGLE 1
317 #define MSTYLE_FLAT 2
319 #define FTITLE_COL (1<<0)
320 #define UTITLE_COL (1<<1)
321 #define OTITLE_COL (1<<2)
322 #define MTITLE_COL (1<<3)
323 #define MITEM_COL (1<<4)
324 #define MDISAB_COL (1<<5)
325 #define MHIGH_COL (1<<6)
326 #define MHIGHT_COL (1<<7)
327 #define ICONT_COL (1<<8)
328 #define ICONB_COL (1<<9)
329 #define CLIP_COL (1<<10)
330 #define CCLIP_COL (1<<11)
332 static const struct {
334 const char *default_value
;
336 { "FTitleColor", "white" },
337 { "UTitleColor", "black" },
338 { "PTitleColor", "white" },
339 { "MenuTitleColor", "white" },
340 { "MenuTextColor", "black" },
341 { "MenuDisabledColor", "#616161" },
342 { "HighlightColor", "white" },
343 { "HighlightTextColor", "black" },
344 { "IconTitleColor", "white" },
345 { "IconTitleBack", "black" },
346 { "ClipTitleColor", "black" },
347 { "CClipTitleColor", "#454045" }
350 static WMRect previewPositions
[] = {
352 {{30, 10}, {190, 20}},
354 {{30, 40}, {190, 20}},
356 {{30, 70}, {190, 20}},
358 {{30, 100}, {190, 9}},
360 {{30, 120}, {90, 20}},
362 {{30, 140}, {90, 20 * 4}},
364 {{155, 130}, {64, 64}}
367 #define EVERYTHING 0xff
369 static WMRect previewColorPositions
[] = {
370 {{30, 10}, {190, 20}},
371 {{30, 40}, {190, 20}},
372 {{30, 70}, {190, 20}},
373 {{30, 120}, {90, 20}},
374 {{30, 140}, {90, 20}},
375 {{30, 160}, {90, 20}},
376 {{30, 180}, {90, 20}},
377 {{30, 200}, {90, 20}},
378 {{155, 130}, {64, 64}},
379 {{155, 130}, {64, 64}},
380 {{155, 130}, {64, 64}},
381 {{155, 130}, {64, 64}}
384 static void str2rcolor(RContext
* rc
, const char *name
, RColor
* color
)
388 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
391 color
->red
= xcolor
.red
>> 8;
392 color
->green
= xcolor
.green
>> 8;
393 color
->blue
= xcolor
.blue
>> 8;
396 static void dumpRImage(const char *path
, RImage
* image
)
399 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
401 f
= fopen(path
, "wb");
406 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
, channels
);
408 fwrite(image
->data
, 1, image
->width
* image
->height
* channels
, f
);
416 static int isPixmap(WMPropList
* prop
)
421 p
= WMGetFromPLArray(prop
, 0);
422 s
= WMGetFromPLString(p
);
423 if (strcasecmp(&s
[1], "pixmap") == 0)
429 /**********************************************************************/
431 static void drawResizebarBevel(RImage
* img
)
436 int width
= img
->width
;
437 int height
= img
->height
;
441 black
.red
= black
.green
= black
.blue
= 0;
444 light
.red
= light
.green
= light
.blue
= 80;
447 dark
.red
= dark
.green
= dark
.blue
= 40;
449 ROperateLine(img
, RSubtractOperation
, 0, 0, width
- 1, 0, &dark
);
450 ROperateLine(img
, RAddOperation
, 0, 1, width
- 1, 1, &light
);
452 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
- 1, &dark
);
453 ROperateLine(img
, RAddOperation
, cwidth
+ 1, 2, cwidth
+ 1, height
- 1, &light
);
455 ROperateLine(img
, RSubtractOperation
, width
- cwidth
- 2, 2, width
- cwidth
- 2, height
- 1, &dark
);
456 ROperateLine(img
, RAddOperation
, width
- cwidth
- 1, 2, width
- cwidth
- 1, height
- 1, &light
);
458 RDrawLine(img
, 0, height
- 1, width
- 1, height
- 1, &black
);
459 RDrawLine(img
, 0, 0, 0, height
- 1, &black
);
460 RDrawLine(img
, width
- 1, 0, width
- 1, height
- 1, &black
);
463 static void drawMenuBevel(RImage
* img
)
465 RColor light
, dark
, mid
;
467 int iheight
= img
->height
/ 4;
470 light
.red
= light
.green
= light
.blue
= 80;
473 dark
.red
= dark
.green
= dark
.blue
= 0;
476 mid
.red
= mid
.green
= mid
.blue
= 40;
478 for (i
= 1; i
< 4; i
++) {
479 ROperateLine(img
, RSubtractOperation
, 0, i
* iheight
- 2, img
->width
- 1, i
* iheight
- 2, &mid
);
481 RDrawLine(img
, 0, i
* iheight
- 1, img
->width
- 1, i
* iheight
- 1, &dark
);
483 ROperateLine(img
, RAddOperation
, 1, i
* iheight
, img
->width
- 2, i
* iheight
, &light
);
487 static Pixmap
renderTexture(WMScreen
* scr
, WMPropList
* texture
, int width
, int height
, const char *path
, int border
)
490 RImage
*image
= NULL
;
492 RContext
*rc
= WMScreenRContext(scr
);
496 type
= WMGetFromPLString(WMGetFromPLArray(texture
, 0));
498 if (strcasecmp(type
, "solid") == 0) {
500 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
502 str2rcolor(rc
, str
, &rcolor
);
504 image
= RCreateImage(width
, height
, False
);
505 RClearImage(image
, &rcolor
);
506 } else if (strcasecmp(type
, "igradient") == 0) {
510 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
511 str2rcolor(rc
, str
, &c1
[0]);
512 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
513 str2rcolor(rc
, str
, &c1
[1]);
514 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
517 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
518 str2rcolor(rc
, str
, &c2
[0]);
519 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 5));
520 str2rcolor(rc
, str
, &c2
[1]);
521 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 6));
524 image
= RRenderInterwovenGradient(width
, height
, c1
, t1
, c2
, t2
);
525 } else if (strcasecmp(&type
[1], "gradient") == 0) {
529 switch (toupper(type
[0])) {
531 style
= RVerticalGradient
;
534 style
= RHorizontalGradient
;
538 style
= RDiagonalGradient
;
542 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
543 str2rcolor(rc
, str
, &rcolor
);
544 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
545 str2rcolor(rc
, str
, &rcolor2
);
547 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
548 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'T') {
552 RImage
*grad
, *timage
= NULL
;
555 switch (toupper(type
[1])) {
557 style
= RVerticalGradient
;
560 style
= RHorizontalGradient
;
564 style
= RDiagonalGradient
;
568 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
569 str2rcolor(rc
, str
, &rcolor
);
570 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
571 str2rcolor(rc
, str
, &rcolor2
);
573 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
575 if ((path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
)) != NULL
)
576 timage
= RLoadImage(rc
, path
, 0);
578 if (!path
|| !timage
) {
579 wwarning("could not load file '%s': %s", path
, RMessageForError(RErrorCode
));
581 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
583 image
= RMakeTiledImage(timage
, width
, height
);
584 RReleaseImage(timage
);
586 i
= atoi(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
588 RCombineImagesWithOpaqueness(image
, grad
, i
);
591 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'M') {
596 switch (toupper(type
[1])) {
598 style
= RVerticalGradient
;
601 style
= RHorizontalGradient
;
605 style
= RDiagonalGradient
;
609 j
= WMGetPropListItemCount(texture
);
612 colors
= wmalloc(j
* sizeof(RColor
*));
614 for (i
= 2; i
< j
; i
++) {
615 str
= WMGetFromPLString(WMGetFromPLArray(texture
, i
));
616 colors
[i
- 2] = wmalloc(sizeof(RColor
));
617 str2rcolor(rc
, str
, colors
[i
- 2]);
619 colors
[i
- 2] = NULL
;
621 image
= RRenderMultiGradient(width
, height
, colors
, style
);
623 for (i
= 0; colors
[i
] != NULL
; i
++)
627 } else if (strcasecmp(&type
[1], "pixmap") == 0) {
628 RImage
*timage
= NULL
;
632 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
634 if ((path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
)) != NULL
)
635 timage
= RLoadImage(rc
, path
, 0);
637 if (!path
|| !timage
) {
638 wwarning("could not load file '%s': %s", path
? path
: str
, RMessageForError(RErrorCode
));
640 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
641 str2rcolor(rc
, str
, &color
);
643 switch (toupper(type
[0])) {
645 image
= RMakeTiledImage(timage
, width
, height
);
646 RReleaseImage(timage
);
650 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
651 RReleaseImage(timage
);
656 image
= RScaleImage(timage
, width
, height
);
657 RReleaseImage(timage
);
670 dumpRImage(path
, image
);
674 if (border
== RESIZEBAR_BEVEL
) {
675 drawResizebarBevel(image
);
676 } else if (border
== MENU_BEVEL
) {
677 drawMenuBevel(image
);
678 RBevelImage(image
, RBEV_RAISED2
);
681 RBevelImage(image
, border
);
684 RConvertImage(rc
, image
, &pixmap
);
685 RReleaseImage(image
);
690 static Pixmap
renderMenu(_Panel
* panel
, WMPropList
* texture
, int width
, int iheight
)
692 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
693 Display
*dpy
= WMScreenDisplay(scr
);
695 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
698 switch (panel
->menuStyle
) {
700 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
702 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
* 4, WMScreenDepth(scr
));
703 for (i
= 0; i
< 4; i
++) {
704 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
* i
);
706 XFreePixmap(dpy
, tmp
);
709 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, MENU_BEVEL
);
712 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, RBEV_RAISED2
);
722 static void renderPreview(_Panel
* panel
, GC gc
, int part
, int relief
)
725 TextureListItem
*titem
;
727 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
729 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
730 titem
= (TextureListItem
*) item
->clientData
;
732 pix
= renderTexture(scr
, titem
->prop
,
733 previewPositions
[part
].size
.width
, previewPositions
[part
].size
.height
, NULL
, relief
);
735 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
736 previewPositions
[part
].size
.width
,
737 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
739 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->previewNoText
, gc
, 0, 0,
740 previewPositions
[part
].size
.width
,
741 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
743 XFreePixmap(WMScreenDisplay(scr
), pix
);
746 static void updatePreviewBox(_Panel
* panel
, int elements
)
748 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
749 Display
*dpy
= WMScreenDisplay(scr
);
753 WMColor
*black
= WMBlackColor(scr
);
755 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
757 if (panel
->preview
== None
) {
761 panel
->previewNoText
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
762 240 - 4, 215 - 4, WMScreenDepth(scr
));
764 p
= WMCreatePixmap(scr
, 240 - 4, 215 - 4, WMScreenDepth(scr
), False
);
765 panel
->preview
= WMGetPixmapXID(p
);
766 WMSetLabelImage(panel
->prevL
, p
);
769 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
770 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
), 0, 0, 240 - 4, 215 - 4);
771 XFillRectangle(dpy
, panel
->previewNoText
, WMColorGC(color
), 0, 0, 240 - 4, 215 - 4);
772 WMReleaseColor(color
);
775 if (elements
& (1 << PFOCUSED
)) {
776 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
777 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
778 previewPositions
[PFOCUSED
].pos
.x
- 1,
779 previewPositions
[PFOCUSED
].pos
.y
- 1,
780 previewPositions
[PFOCUSED
].size
.width
, previewPositions
[PFOCUSED
].size
.height
);
781 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
782 previewPositions
[PFOCUSED
].pos
.x
- 1,
783 previewPositions
[PFOCUSED
].pos
.y
- 1,
784 previewPositions
[PFOCUSED
].size
.width
, previewPositions
[PFOCUSED
].size
.height
);
785 colorUpdate
|= FTITLE_COL
;
787 if (elements
& (1 << PUNFOCUSED
)) {
788 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
789 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
790 previewPositions
[PUNFOCUSED
].pos
.x
- 1,
791 previewPositions
[PUNFOCUSED
].pos
.y
- 1,
792 previewPositions
[PUNFOCUSED
].size
.width
, previewPositions
[PUNFOCUSED
].size
.height
);
793 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
794 previewPositions
[PUNFOCUSED
].pos
.x
- 1,
795 previewPositions
[PUNFOCUSED
].pos
.y
- 1,
796 previewPositions
[PUNFOCUSED
].size
.width
, previewPositions
[PUNFOCUSED
].size
.height
);
797 colorUpdate
|= UTITLE_COL
;
799 if (elements
& (1 << POWNER
)) {
800 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
801 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
802 previewPositions
[POWNER
].pos
.x
- 1,
803 previewPositions
[POWNER
].pos
.y
- 1,
804 previewPositions
[POWNER
].size
.width
, previewPositions
[POWNER
].size
.height
);
805 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
806 previewPositions
[POWNER
].pos
.x
- 1,
807 previewPositions
[POWNER
].pos
.y
- 1,
808 previewPositions
[POWNER
].size
.width
, previewPositions
[POWNER
].size
.height
);
809 colorUpdate
|= OTITLE_COL
;
811 if (elements
& (1 << PRESIZEBAR
)) {
812 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
814 if (elements
& (1 << PMTITLE
)) {
815 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
816 colorUpdate
|= MTITLE_COL
;
818 if (elements
& (1 << PMITEM
)) {
820 TextureListItem
*titem
;
822 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
823 titem
= (TextureListItem
*) item
->clientData
;
825 pix
= renderMenu(panel
, titem
->prop
,
826 previewPositions
[PMITEM
].size
.width
, previewPositions
[PMITEM
].size
.height
/ 4);
828 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
829 previewPositions
[PMITEM
].size
.width
,
830 previewPositions
[PMITEM
].size
.height
,
831 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
833 XCopyArea(dpy
, pix
, panel
->previewNoText
, gc
, 0, 0,
834 previewPositions
[PMITEM
].size
.width
,
835 previewPositions
[PMITEM
].size
.height
,
836 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
838 XFreePixmap(dpy
, pix
);
840 colorUpdate
|= MITEM_COL
| MDISAB_COL
| MHIGH_COL
| MHIGHT_COL
;
842 if (elements
& (1 << PMITEM
| 1 << PMTITLE
)) {
843 XDrawLine(dpy
, panel
->preview
, gc
, 29, 120, 29, 120 + 20 * 4 + 20);
844 XDrawLine(dpy
, panel
->preview
, gc
, 29, 119, 119, 119);
846 XDrawLine(dpy
, panel
->previewNoText
, gc
, 29, 120, 29, 120 + 20 * 4 + 20);
847 XDrawLine(dpy
, panel
->previewNoText
, gc
, 29, 119, 119, 119);
849 if (elements
& (1 << PICON
)) {
851 TextureListItem
*titem
;
853 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
854 titem
= (TextureListItem
*) item
->clientData
;
856 renderPreview(panel
, gc
, PICON
, titem
->ispixmap
? 0 : RBEV_RAISED3
);
858 colorUpdate
|= ICONT_COL
| ICONB_COL
| CLIP_COL
| CCLIP_COL
;
862 updateColorPreviewBox(panel
, colorUpdate
);
864 WMRedisplayWidget(panel
->prevL
);
867 WMReleaseColor(black
);
870 static void cancelNewTexture(void *data
)
872 _Panel
*panel
= (_Panel
*) data
;
874 HideTexturePanel(panel
->texturePanel
);
877 static char *makeFileName(const char *prefix
)
881 fname
= wstrdup(prefix
);
883 while (access(fname
, F_OK
) == 0) {
887 sprintf(buf
, "%08lx.cache", time(NULL
));
888 fname
= wstrconcat(prefix
, buf
);
894 static void okNewTexture(void *data
)
896 _Panel
*panel
= (_Panel
*) data
;
901 TextureListItem
*titem
;
902 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
904 titem
= wmalloc(sizeof(TextureListItem
));
906 HideTexturePanel(panel
->texturePanel
);
908 name
= GetTexturePanelTextureName(panel
->texturePanel
);
910 prop
= GetTexturePanelTexture(panel
->texturePanel
);
912 str
= WMGetPropListDescription(prop
, False
);
916 titem
->texture
= str
;
917 titem
->selectedFor
= 0;
919 titem
->ispixmap
= isPixmap(prop
);
921 titem
->path
= makeFileName(panel
->fprefix
);
922 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
924 item
= WMAddListItem(panel
->texLs
, "");
925 item
->clientData
= titem
;
927 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
930 static void okEditTexture(void *data
)
932 _Panel
*panel
= (_Panel
*) data
;
937 TextureListItem
*titem
;
939 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
940 titem
= (TextureListItem
*) item
->clientData
;
942 HideTexturePanel(panel
->texturePanel
);
944 if (titem
->current
) {
945 name
= GetTexturePanelTextureName(panel
->texturePanel
);
951 prop
= GetTexturePanelTexture(panel
->texturePanel
);
953 str
= WMGetPropListDescription(prop
, False
);
955 WMReleasePropList(titem
->prop
);
958 titem
->ispixmap
= isPixmap(prop
);
960 wfree(titem
->texture
);
961 titem
->texture
= str
;
963 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
964 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
965 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
967 WMRedisplayWidget(panel
->texLs
);
969 if (titem
->selectedFor
)
970 updatePreviewBox(panel
, titem
->selectedFor
);
972 changePage(panel
->secP
, panel
);
975 static void editTexture(WMWidget
* w
, void *data
)
977 _Panel
*panel
= (_Panel
*) data
;
979 TextureListItem
*titem
;
981 /* Parameter not used, but tell the compiler that it is ok */
984 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
985 titem
= (TextureListItem
*) item
->clientData
;
987 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
989 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
991 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
992 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
994 ShowTexturePanel(panel
->texturePanel
);
997 static void newTexture(WMWidget
* w
, void *data
)
999 _Panel
*panel
= (_Panel
*) data
;
1001 /* Parameter not used, but tell the compiler that it is ok */
1004 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
1006 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
1008 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
1010 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
1012 ShowTexturePanel(panel
->texturePanel
);
1015 static void deleteTexture(WMWidget
* w
, void *data
)
1017 _Panel
*panel
= (_Panel
*) data
;
1019 TextureListItem
*titem
;
1023 /* Parameter not used, but tell the compiler that it is ok */
1026 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1027 row
= WMGetListSelectedItemRow(panel
->texLs
);
1028 item
= WMGetListItem(panel
->texLs
, row
);
1029 titem
= (TextureListItem
*) item
->clientData
;
1031 if (titem
->selectedFor
& (1 << section
)) {
1032 TextureListItem
*titem2
;
1034 panel
->textureIndex
[section
] = section
;
1035 item
= WMGetListItem(panel
->texLs
, section
);
1036 titem2
= (TextureListItem
*) item
->clientData
;
1037 titem2
->selectedFor
|= 1 << section
;
1040 wfree(titem
->title
);
1041 wfree(titem
->texture
);
1042 WMReleasePropList(titem
->prop
);
1044 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1045 werror("could not remove file %s", titem
->path
);
1052 WMRemoveListItem(panel
->texLs
, row
);
1053 WMSetButtonEnabled(panel
->delB
, False
);
1056 static void extractTexture(WMWidget
* w
, void *data
)
1058 _Panel
*panel
= (_Panel
*) data
;
1060 WMOpenPanel
*opanel
;
1061 WMScreen
*scr
= WMWidgetScreen(w
);
1063 opanel
= WMGetOpenPanel(scr
);
1064 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1065 WMSetFilePanelCanChooseFiles(opanel
, True
);
1067 if (WMRunModalFilePanelForDirectory(opanel
, panel
->parent
, wgethomedir(), _("Select File"), NULL
)) {
1068 path
= WMGetFilePanelFileName(opanel
);
1070 OpenExtractPanelFor(panel
);
1076 static void changePage(WMWidget
* w
, void *data
)
1078 _Panel
*panel
= (_Panel
*) data
;
1080 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1081 RContext
*rc
= WMScreenRContext(scr
);
1082 static WMPoint positions
[] = {
1093 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1095 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1097 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1102 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1103 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1104 positions
[panel
->oldsection
].x
, positions
[panel
->oldsection
].y
, 22, 22);
1105 WMReleaseColor(color
);
1108 panel
->oldsection
= section
;
1109 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1111 WMRedisplayWidget(panel
->prevL
);
1114 static void previewClick(XEvent
* event
, void *clientData
)
1116 _Panel
*panel
= (_Panel
*) clientData
;
1119 switch (panel
->oldTabItem
) {
1121 for (i
= 0; i
< wlengthof(previewPositions
); i
++) {
1122 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
1123 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
1124 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
1125 + previewPositions
[i
].size
.width
1126 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
+ previewPositions
[i
].size
.height
) {
1128 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1129 changePage(panel
->secP
, panel
);
1135 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1136 if (event
->xbutton
.x
>= previewColorPositions
[i
].pos
.x
1137 && event
->xbutton
.y
>= previewColorPositions
[i
].pos
.y
1138 && event
->xbutton
.x
< previewColorPositions
[i
].pos
.x
1139 + previewColorPositions
[i
].size
.width
1140 && event
->xbutton
.y
< previewColorPositions
[i
].pos
.y
1141 + previewColorPositions
[i
].size
.height
) {
1147 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1148 changeColorPage(panel
->colP
, panel
);
1156 static void textureClick(WMWidget
* w
, void *data
)
1158 _Panel
*panel
= (_Panel
*) data
;
1161 TextureListItem
*titem
;
1163 /* Parameter not used, but tell the compiler that it is ok */
1166 i
= WMGetListSelectedItemRow(panel
->texLs
);
1168 item
= WMGetListItem(panel
->texLs
, i
);
1170 titem
= (TextureListItem
*) item
->clientData
;
1172 if (titem
->current
) {
1173 WMSetButtonEnabled(panel
->delB
, False
);
1175 WMSetButtonEnabled(panel
->delB
, True
);
1179 static void textureDoubleClick(WMWidget
* w
, void *data
)
1181 _Panel
*panel
= (_Panel
*) data
;
1184 TextureListItem
*titem
;
1186 /* Parameter not used, but tell the compiler that it is ok */
1189 /* unselect old texture */
1190 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1192 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1193 titem
= (TextureListItem
*) item
->clientData
;
1194 titem
->selectedFor
&= ~(1 << section
);
1196 /* select new texture */
1197 i
= WMGetListSelectedItemRow(panel
->texLs
);
1199 item
= WMGetListItem(panel
->texLs
, i
);
1201 titem
= (TextureListItem
*) item
->clientData
;
1203 titem
->selectedFor
|= 1 << section
;
1205 panel
->textureIndex
[section
] = i
;
1207 WMRedisplayWidget(panel
->texLs
);
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
)
1267 f
= fopen(path
, "rb");
1271 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1273 image
= RCreateImage(w
, h
, d
== 4);
1274 fread(image
->data
, 1, w
* h
* d
, f
);
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
[] = {
1374 if (panel
->preview
) {
1377 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1378 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1379 positions
[panel
->oldcsection
].x
, positions
[panel
->oldcsection
].y
, 22, 22);
1380 WMReleaseColor(color
);
1383 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1385 panel
->oldcsection
= section
;
1387 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1389 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1391 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1393 WMRedisplayWidget(panel
->prevL
);
1397 paintText(WMScreen
* scr
, Drawable d
, WMColor
* color
, WMFont
* font
,
1398 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1400 int l
= strlen(text
);
1407 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1411 x
+= (w
- WMWidthOfString(font
, text
, l
)) / 2;
1414 WMDrawString(scr
, d
, color
, font
, x
, y
+ (h
- WMFontHeight(font
)) / 2, text
, l
);
1417 static void updateColorPreviewBox(_Panel
* panel
, int elements
)
1419 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1420 Display
*dpy
= WMScreenDisplay(scr
);
1425 pnot
= panel
->previewNoText
;
1426 gc
= WMColorGC(panel
->colors
[0]);
1428 if (elements
& FTITLE_COL
) {
1429 XCopyArea(dpy
, pnot
, d
, gc
, 30, 10, 190, 20, 30, 10);
1430 paintText(scr
, d
, panel
->colors
[0], panel
->boldFont
, 30, 10, 190, 20,
1431 panel
->titleAlignment
, _("Focused Window"));
1433 if (elements
& UTITLE_COL
) {
1434 XCopyArea(dpy
, pnot
, d
, gc
, 30, 40, 190, 20, 30, 40);
1435 paintText(scr
, d
, panel
->colors
[1], panel
->boldFont
, 30, 40, 190, 20,
1436 panel
->titleAlignment
, _("Unfocused Window"));
1438 if (elements
& OTITLE_COL
) {
1439 XCopyArea(dpy
, pnot
, d
, gc
, 30, 70, 190, 20, 30, 70);
1440 paintText(scr
, d
, panel
->colors
[2], panel
->boldFont
, 30, 70, 190, 20,
1441 panel
->titleAlignment
, _("Owner of Focused Window"));
1443 if (elements
& MTITLE_COL
) {
1444 XCopyArea(dpy
, pnot
, d
, gc
, 30, 120, 90, 20, 30, 120);
1445 paintText(scr
, d
, panel
->colors
[3], panel
->boldFont
, 30, 120, 90, 20, WALeft
, _("Menu Title"));
1447 if (elements
& MITEM_COL
) {
1448 XCopyArea(dpy
, pnot
, d
, gc
, 30, 140, 90, 20, 30, 140);
1449 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 140, 90, 20, WALeft
, _("Normal Item"));
1450 XCopyArea(dpy
, pnot
, d
, gc
, 30, 200, 90, 20, 30, 200);
1451 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 200, 90, 20, WALeft
, _("Normal Item"));
1453 if (elements
& MDISAB_COL
) {
1454 XCopyArea(dpy
, pnot
, d
, gc
, 30, 160, 90, 20, 30, 160);
1455 paintText(scr
, d
, panel
->colors
[5], panel
->normalFont
, 30, 160, 90, 20,
1456 WALeft
, _("Disabled Item"));
1458 if (elements
& MHIGH_COL
) {
1459 XFillRectangle(WMScreenDisplay(scr
), d
, WMColorGC(panel
->colors
[6]), 31, 181, 87, 17);
1460 XFillRectangle(WMScreenDisplay(scr
), pnot
, WMColorGC(panel
->colors
[6]), 31, 181, 87, 17);
1461 elements
|= MHIGHT_COL
;
1463 if (elements
& MHIGHT_COL
) {
1464 XCopyArea(dpy
, pnot
, d
, gc
, 30, 180, 90, 20, 30, 180);
1465 paintText(scr
, d
, panel
->colors
[7], panel
->normalFont
, 30, 180, 90, 20, WALeft
, _("Highlighted"));
1468 if (elements & ICONT_COL) {
1469 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1472 if (elements & ICONB_COL) {
1473 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1476 if (elements & CLIP_COL) {
1477 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1480 if (elements & CCLIP_COL) {
1481 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1485 WMRedisplayWidget(panel
->prevL
);
1488 static void colorWellObserver(void *self
, WMNotification
* n
)
1490 _Panel
*panel
= (_Panel
*) self
;
1493 /* Parameter not used, but tell the compiler that it is ok */
1496 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1498 WMReleaseColor(panel
->colors
[p
]);
1500 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1502 updateColorPreviewBox(panel
, 1 << p
);
1505 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
)
1507 _Panel
*panel
= self
->data
;
1510 /* Parameter not used, but tell the compiler that it is ok */
1513 i
= WMGetTabViewItemIdentifier(item
);
1516 switch (panel
->oldTabItem
) {
1518 changeColorPage(NULL
, panel
);
1521 changePage(panel
->secP
, panel
);
1524 switch (panel
->oldTabItem
) {
1526 changePage(NULL
, panel
);
1529 changeColorPage(panel
->colP
, panel
);
1532 switch (panel
->oldTabItem
) {
1534 changePage(NULL
, panel
);
1537 changeColorPage(NULL
, panel
);
1543 panel
->oldTabItem
= i
;
1546 /*************************************************************************/
1548 static void menuStyleCallback(WMWidget
* self
, void *data
)
1550 _Panel
*panel
= (_Panel
*) data
;
1552 if (self
== panel
->mstyB
[0]) {
1553 panel
->menuStyle
= MSTYLE_NORMAL
;
1554 updatePreviewBox(panel
, 1 << PMITEM
);
1556 } else if (self
== panel
->mstyB
[1]) {
1557 panel
->menuStyle
= MSTYLE_SINGLE
;
1558 updatePreviewBox(panel
, 1 << PMITEM
);
1560 } else if (self
== panel
->mstyB
[2]) {
1561 panel
->menuStyle
= MSTYLE_FLAT
;
1562 updatePreviewBox(panel
, 1 << PMITEM
);
1566 static void titleAlignCallback(WMWidget
* self
, void *data
)
1568 _Panel
*panel
= (_Panel
*) data
;
1570 if (self
== panel
->taliB
[0]) {
1571 panel
->titleAlignment
= WALeft
;
1572 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1574 } else if (self
== panel
->taliB
[1]) {
1575 panel
->titleAlignment
= WACenter
;
1576 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1578 } else if (self
== panel
->taliB
[2]) {
1579 panel
->titleAlignment
= WARight
;
1580 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1584 static void createPanel(Panel
* p
)
1586 _Panel
*panel
= (_Panel
*) p
;
1588 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1589 WMTabViewItem
*item
;
1594 panel
->fprefix
= wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1596 if (access(panel
->fprefix
, F_OK
) != 0) {
1597 if (mkdir(panel
->fprefix
, 0755) < 0) {
1598 werror("%s", panel
->fprefix
);
1603 tmp
= wstrconcat(panel
->fprefix
, "/WPrefs/");
1604 wfree(panel
->fprefix
);
1605 panel
->fprefix
= tmp
;
1606 if (access(panel
->fprefix
, F_OK
) != 0) {
1607 if (mkdir(panel
->fprefix
, 0755) < 0) {
1608 werror("%s", panel
->fprefix
);
1613 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1614 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1615 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1617 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1618 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1619 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1621 panel
->box
= WMCreateBox(panel
->parent
);
1622 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
1625 panel
->prevL
= WMCreateLabel(panel
->box
);
1626 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1627 WMMoveWidget(panel
->prevL
, 15, 10);
1628 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1629 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1631 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
, previewClick
, panel
);
1635 tabviewDelegate
.data
= panel
;
1637 panel
->tabv
= WMCreateTabView(panel
->box
);
1638 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1639 WMMoveWidget(panel
->tabv
, 265, 10);
1640 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1642 /*** texture list ***/
1644 panel
->texF
= WMCreateFrame(panel
->box
);
1645 WMSetFrameRelief(panel
->texF
, WRFlat
);
1647 item
= WMCreateTabViewItemWithIdentifier(0);
1648 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1649 WMSetTabViewItemLabel(item
, _("Texture"));
1651 WMAddItemInTabView(panel
->tabv
, item
);
1653 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1654 WMResizeWidget(panel
->secP
, 228, 20);
1655 WMMoveWidget(panel
->secP
, 7, 7);
1656 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1657 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1658 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1659 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1660 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1661 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1662 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1663 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1665 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1666 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1668 panel
->texLs
= WMCreateList(panel
->texF
);
1669 WMResizeWidget(panel
->texLs
, 165, 155);
1670 WMMoveWidget(panel
->texLs
, 70, 33);
1671 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1672 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1673 WMHangData(panel
->texLs
, panel
);
1674 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1675 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1677 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1678 "for the selected item."), WMWidgetView(panel
->texLs
));
1680 /* command buttons */
1682 font
= WMSystemFontOfSize(scr
, 10);
1684 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1685 WMResizeWidget(panel
->newB
, 57, 39);
1686 WMMoveWidget(panel
->newB
, 7, 33);
1687 WMSetButtonFont(panel
->newB
, font
);
1688 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1689 WMSetButtonText(panel
->newB
, _("New"));
1690 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1691 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
, NULL
, NULL
);
1693 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel
->newB
));
1695 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1696 WMResizeWidget(panel
->ripB
, 57, 39);
1697 WMMoveWidget(panel
->ripB
, 7, 72);
1698 WMSetButtonFont(panel
->ripB
, font
);
1699 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1700 WMSetButtonText(panel
->ripB
, _("Extract..."));
1701 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1702 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
, NULL
, NULL
);
1704 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel
->ripB
));
1706 WMSetButtonEnabled(panel
->ripB
, False
);
1708 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1709 WMResizeWidget(panel
->editB
, 57, 39);
1710 WMMoveWidget(panel
->editB
, 7, 111);
1711 WMSetButtonFont(panel
->editB
, font
);
1712 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1713 WMSetButtonText(panel
->editB
, _("Edit"));
1714 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
, NULL
, NULL
);
1715 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1716 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel
->editB
));
1718 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1719 WMResizeWidget(panel
->delB
, 57, 38);
1720 WMMoveWidget(panel
->delB
, 7, 150);
1721 WMSetButtonFont(panel
->delB
, font
);
1722 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1723 WMSetButtonText(panel
->delB
, _("Delete"));
1724 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
, NULL
, NULL
);
1725 WMSetButtonEnabled(panel
->delB
, False
);
1726 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1727 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel
->delB
));
1729 WMReleaseFont(font
);
1731 WMMapSubwidgets(panel
->texF
);
1734 panel
->colF
= WMCreateFrame(panel
->box
);
1735 WMSetFrameRelief(panel
->colF
, WRFlat
);
1737 item
= WMCreateTabViewItemWithIdentifier(1);
1738 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1739 WMSetTabViewItemLabel(item
, _("Color"));
1741 WMAddItemInTabView(panel
->tabv
, item
);
1743 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1744 WMResizeWidget(panel
->colP
, 228, 20);
1745 WMMoveWidget(panel
->colP
, 7, 7);
1746 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Title"));
1747 WMAddPopUpButtonItem(panel
->colP
, _("Unfocused Window Title"));
1748 WMAddPopUpButtonItem(panel
->colP
, _("Owner of Focused Window Title"));
1749 WMAddPopUpButtonItem(panel
->colP
, _("Menu Title"));
1750 WMAddPopUpButtonItem(panel
->colP
, _("Menu Item Text"));
1751 WMAddPopUpButtonItem(panel
->colP
, _("Disabled Menu Item Text"));
1752 WMAddPopUpButtonItem(panel
->colP
, _("Menu Highlight Color"));
1753 WMAddPopUpButtonItem(panel
->colP
, _("Highlighted Menu Text Color"));
1755 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1756 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1757 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1758 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1761 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1763 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1765 panel
->colW
= WMCreateColorWell(panel
->colF
);
1766 WMResizeWidget(panel
->colW
, 65, 50);
1767 WMMoveWidget(panel
->colW
, 30, 75);
1768 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->colW
);
1770 for (i
= 0; i
< 4; i
++) {
1772 for (j
= 0; j
< 6; j
++) {
1773 panel
->sampW
[i
+ j
* 4] = WMCreateColorWell(panel
->colF
);
1774 WMResizeWidget(panel
->sampW
[i
+ j
* 4], 22, 22);
1775 WMMoveWidget(panel
->sampW
[i
+ j
* 4], 130 + i
* 22, 40 + j
* 22);
1776 WSetColorWellBordered(panel
->sampW
[i
+ j
* 4], False
);
1780 WMMapSubwidgets(panel
->colF
);
1785 panel
->bgF
= WMCreateFrame(panel
->box
);
1786 WMSetFrameRelief(panel
->bgF
, WRFlat
);
1788 item
= WMCreateTabViewItemWithIdentifier(2);
1789 WMSetTabViewItemView(item
, WMWidgetView(panel
->bgF
));
1790 WMSetTabViewItemLabel(item
, _("Background"));
1792 WMAddItemInTabView(panel
->tabv
, item
);
1794 panel
->bgprevL
= WMCreateLabel(panel
->bgF
);
1795 WMResizeWidget(panel
->bgprevL
, 230, 155);
1796 WMMoveWidget(panel
->bgprevL
, 5, 5);
1797 WMSetLabelRelief(panel
->bgprevL
, WRSunken
);
1799 panel
->selbgB
= WMCreateCommandButton(panel
->bgF
);
1800 WMMoveWidget(panel
->selbgB
, 5, 165);
1801 WMResizeWidget(panel
->selbgB
, 100, 24);
1802 WMSetButtonText(panel
->selbgB
, _("Browse..."));
1804 WMMapSubwidgets(panel
->bgF
);
1805 #endif /* unfinished */
1807 panel
->optF
= WMCreateFrame(panel
->box
);
1808 WMSetFrameRelief(panel
->optF
, WRFlat
);
1810 item
= WMCreateTabViewItemWithIdentifier(3);
1811 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1812 WMSetTabViewItemLabel(item
, _("Options"));
1814 WMAddItemInTabView(panel
->tabv
, item
);
1816 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1817 WMResizeWidget(panel
->mstyF
, 215, 85);
1818 WMMoveWidget(panel
->mstyF
, 15, 10);
1819 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1821 for (i
= 0; i
< 3; i
++) {
1825 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1826 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1827 WMMoveWidget(panel
->mstyB
[i
], 15 + i
* 65, 20);
1828 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1829 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1832 path
= LocateImage(MSTYLE1_FILE
);
1835 path
= LocateImage(MSTYLE2_FILE
);
1838 path
= LocateImage(MSTYLE3_FILE
);
1842 icon
= WMCreatePixmapFromFile(scr
, path
);
1844 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1845 WMReleasePixmap(icon
);
1847 wwarning(_("could not load icon file %s"), path
);
1852 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1853 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1855 WMMapSubwidgets(panel
->mstyF
);
1857 panel
->taliF
= WMCreateFrame(panel
->optF
);
1858 WMResizeWidget(panel
->taliF
, 110, 80);
1859 WMMoveWidget(panel
->taliF
, 15, 100);
1860 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
1862 for (i
= 0; i
< 3; i
++) {
1863 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
1864 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
1867 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1870 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1873 WMSetButtonText(panel
->taliB
[i
], _("Right"));
1876 WMResizeWidget(panel
->taliB
[i
], 90, 18);
1877 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20 * i
);
1879 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
1880 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
1882 WMMapSubwidgets(panel
->taliF
);
1884 WMMapSubwidgets(panel
->optF
);
1886 /**/ WMRealizeWidget(panel
->box
);
1887 WMMapSubwidgets(panel
->box
);
1889 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1893 changePage(panel
->secP
, panel
);
1895 fillTextureList(panel
->texLs
);
1897 fillColorList(panel
);
1899 panel
->texturePanel
= CreateTexturePanel(panel
->parent
);
1902 static void setupTextureFor(WMList
*list
, const char *key
, const char *defValue
, const char *title
, int index
)
1905 TextureListItem
*titem
;
1907 titem
= wmalloc(sizeof(TextureListItem
));
1909 titem
->title
= wstrdup(title
);
1910 titem
->prop
= GetObjectForKey(key
);
1911 if (!titem
->prop
|| !WMIsPLArray(titem
->prop
)) {
1912 /* Maybe also give a error message to stderr that the entry is bad? */
1913 titem
->prop
= WMCreatePropListFromDescription(defValue
);
1915 WMRetainPropList(titem
->prop
);
1917 titem
->texture
= WMGetPropListDescription((WMPropList
*) titem
->prop
, False
);
1919 titem
->selectedFor
= 1 << index
;
1921 titem
->ispixmap
= isPixmap(titem
->prop
);
1923 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1925 item
= WMAddListItem(list
, "");
1926 item
->clientData
= titem
;
1929 static void showData(_Panel
* panel
)
1934 str
= GetStringForKey("MenuStyle");
1935 if (str
&& strcasecmp(str
, "flat") == 0) {
1936 panel
->menuStyle
= MSTYLE_FLAT
;
1937 } else if (str
&& strcasecmp(str
, "singletexture") == 0) {
1938 panel
->menuStyle
= MSTYLE_SINGLE
;
1940 panel
->menuStyle
= MSTYLE_NORMAL
;
1943 str
= GetStringForKey("TitleJustify");
1944 if (str
&& strcasecmp(str
, "left") == 0) {
1945 panel
->titleAlignment
= WALeft
;
1946 } else if (str
&& strcasecmp(str
, "right") == 0) {
1947 panel
->titleAlignment
= WARight
;
1949 panel
->titleAlignment
= WACenter
;
1952 for (i
= 0; i
< wlengthof(colorOptions
); i
++) {
1955 str
= GetStringForKey(colorOptions
[i
].key
);
1957 str
= colorOptions
[i
].default_value
;
1959 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), str
, False
))) {
1960 color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), "#000000", False
);
1963 panel
->colors
[i
] = color
;
1965 changeColorPage(panel
->colP
, panel
);
1967 for (i
= 0; i
< wlengthof(textureOptions
); i
++) {
1968 setupTextureFor(panel
->texLs
, textureOptions
[i
].key
,
1969 textureOptions
[i
].default_value
, _(textureOptions
[i
].label
), i
);
1970 panel
->textureIndex
[i
] = i
;
1972 updatePreviewBox(panel
, EVERYTHING
);
1974 WMSetButtonSelected(panel
->mstyB
[panel
->menuStyle
], True
);
1975 WMSetButtonSelected(panel
->taliB
[panel
->titleAlignment
], True
);
1978 static void storeData(_Panel
* panel
)
1980 TextureListItem
*titem
;
1984 for (i
= 0; i
< wlengthof(textureOptions
); i
++) {
1985 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
1986 titem
= (TextureListItem
*) item
->clientData
;
1987 SetObjectForKey(titem
->prop
, textureOptions
[i
].key
);
1990 for (i
= 0; i
< 8; i
++) {
1993 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
1996 SetStringForKey(str
, colorOptions
[i
].key
);
2001 switch (panel
->menuStyle
) {
2003 SetStringForKey("singletexture", "MenuStyle");
2006 SetStringForKey("flat", "MenuStyle");
2010 SetStringForKey("normal", "MenuStyle");
2013 switch (panel
->titleAlignment
) {
2015 SetStringForKey("left", "TitleJustify");
2018 SetStringForKey("right", "TitleJustify");
2022 SetStringForKey("center", "TitleJustify");
2027 static void prepareForClose(_Panel
* panel
)
2029 WMPropList
*textureList
;
2030 WMPropList
*texture
;
2031 TextureListItem
*titem
;
2033 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2036 textureList
= WMCreatePLArray(NULL
, NULL
);
2038 /* store list of textures */
2039 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2040 item
= WMGetListItem(panel
->texLs
, i
);
2041 titem
= (TextureListItem
*) item
->clientData
;
2043 texture
= WMCreatePLArray(WMCreatePLString(titem
->title
),
2044 WMRetainPropList(titem
->prop
), WMCreatePLString(titem
->path
), NULL
);
2046 WMAddToPLArray(textureList
, texture
);
2049 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2050 WMReleasePropList(textureList
);
2052 /* store list of colors */
2053 textureList
= WMCreatePLArray(NULL
, NULL
);
2054 for (i
= 0; i
< 24; i
++) {
2058 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2060 str
= WMGetColorRGBDescription(color
);
2061 WMAddToPLArray(textureList
, WMCreatePLString(str
));
2064 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2065 WMReleasePropList(textureList
);
2067 WMSynchronizeUserDefaults(udb
);
2070 Panel
*InitAppearance(WMWidget
*parent
)
2074 panel
= wmalloc(sizeof(_Panel
));
2076 panel
->sectionName
= _("Appearance Preferences");
2078 panel
->description
= _("Background texture configuration for windows,\n" "menus and icons.");
2080 panel
->parent
= parent
;
2082 panel
->callbacks
.createWidgets
= createPanel
;
2083 panel
->callbacks
.updateDomain
= storeData
;
2084 panel
->callbacks
.prepareForClose
= prepareForClose
;
2086 AddSection(panel
, ICON_FILE
);
2091 /****************************************************************************/
2093 typedef struct ExtractPanel
{
2103 static void OpenExtractPanelFor(_Panel
*panel
)
2105 ExtractPanel
*epanel
;
2108 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
2110 epanel
= wmalloc(sizeof(ExtractPanel
));
2111 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->parent
, "extract",
2112 WMTitledWindowMask
| WMClosableWindowMask
);
2113 WMResizeWidget(epanel
->win
, 245, 250);
2114 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2116 epanel
->label
= WMCreateLabel(epanel
->win
);
2117 WMResizeWidget(epanel
->label
, 225, 18);
2118 WMMoveWidget(epanel
->label
, 10, 10);
2119 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2120 WMSetLabelRelief(epanel
->label
, WRSunken
);
2122 color
= WMDarkGrayColor(scr
);
2123 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2124 WMReleaseColor(color
);
2126 color
= WMWhiteColor(scr
);
2127 WMSetLabelTextColor(epanel
->label
, color
);
2128 WMReleaseColor(color
);
2130 font
= WMBoldSystemFontOfSize(scr
, 12);
2131 WMSetLabelFont(epanel
->label
, font
);
2132 WMReleaseFont(font
);
2134 WMSetLabelText(epanel
->label
, _("Textures"));
2136 epanel
->list
= WMCreateList(epanel
->win
);
2137 WMResizeWidget(epanel
->list
, 225, 165);
2138 WMMoveWidget(epanel
->list
, 10, 30);
2140 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2141 WMResizeWidget(epanel
->closeB
, 74, 24);
2142 WMMoveWidget(epanel
->closeB
, 165, 215);
2143 WMSetButtonText(epanel
->closeB
, _("Close"));
2145 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2146 WMResizeWidget(epanel
->extrB
, 74, 24);
2147 WMMoveWidget(epanel
->extrB
, 80, 215);
2148 WMSetButtonText(epanel
->extrB
, _("Extract"));
2150 WMMapSubwidgets(epanel
->win
);
2152 /* take textures from file */
2154 WMRealizeWidget(epanel
->win
);
2156 WMMapWidget(epanel
->win
);