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
, char *path
);
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 char *textureOptions
[] = {
296 "FTitleBack", "(solid, black)", "[Focused]",
297 "UTitleBack", "(solid, gray)", "[Unfocused]",
298 "PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
299 "ResizebarBack", "(solid, gray)", "[Resizebar]",
300 "MenuTitleBack", "(solid, black)", "[Menu Title]",
301 "MenuTextBack", "(solid, gray)", "[Menu Item]",
302 "IconBack", "(solid, gray)", "[Icon]"
305 #define RESIZEBAR_BEVEL -1
306 #define MENU_BEVEL -2
308 #define TEXPREV_WIDTH 40
309 #define TEXPREV_HEIGHT 24
311 #define MSTYLE_NORMAL 0
312 #define MSTYLE_SINGLE 1
313 #define MSTYLE_FLAT 2
315 #define FTITLE_COL (1<<0)
316 #define UTITLE_COL (1<<1)
317 #define OTITLE_COL (1<<2)
318 #define MTITLE_COL (1<<3)
319 #define MITEM_COL (1<<4)
320 #define MDISAB_COL (1<<5)
321 #define MHIGH_COL (1<<6)
322 #define MHIGHT_COL (1<<7)
323 #define ICONT_COL (1<<8)
324 #define ICONB_COL (1<<9)
325 #define CLIP_COL (1<<10)
326 #define CCLIP_COL (1<<11)
328 static char *colorOptions
[] = {
329 "FTitleColor", "white",
330 "UTitleColor", "black",
331 "PTitleColor", "white",
332 "MenuTitleColor", "white",
333 "MenuTextColor", "black",
334 "MenuDisabledColor", "#616161",
335 "HighlightColor", "white",
336 "HighlightTextColor", "black",
337 "IconTitleColor", "white",
338 "IconTitleBack", "black",
339 "ClipTitleColor", "black",
340 "CClipTitleColor", "#454045"
343 static WMRect previewPositions
[] = {
345 {{30, 10}, {190, 20}},
347 {{30, 40}, {190, 20}},
349 {{30, 70}, {190, 20}},
351 {{30, 100}, {190, 9}},
353 {{30, 120}, {90, 20}},
355 {{30, 140}, {90, 20 * 4}},
357 {{155, 130}, {64, 64}}
360 #define EVERYTHING 0xff
362 static WMRect previewColorPositions
[] = {
363 {{30, 10}, {190, 20}},
364 {{30, 40}, {190, 20}},
365 {{30, 70}, {190, 20}},
366 {{30, 120}, {90, 20}},
367 {{30, 140}, {90, 20}},
368 {{30, 160}, {90, 20}},
369 {{30, 180}, {90, 20}},
370 {{30, 200}, {90, 20}},
371 {{155, 130}, {64, 64}},
372 {{155, 130}, {64, 64}},
373 {{155, 130}, {64, 64}},
374 {{155, 130}, {64, 64}}
377 static void str2rcolor(RContext
* rc
, char *name
, RColor
* color
)
381 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
384 color
->red
= xcolor
.red
>> 8;
385 color
->green
= xcolor
.green
>> 8;
386 color
->blue
= xcolor
.blue
>> 8;
389 static void dumpRImage(char *path
, RImage
* image
)
392 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
394 f
= fopen(path
, "wb");
399 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
, channels
);
401 fwrite(image
->data
, 1, image
->width
* image
->height
* channels
, f
);
409 static int isPixmap(WMPropList
* prop
)
414 p
= WMGetFromPLArray(prop
, 0);
415 s
= WMGetFromPLString(p
);
416 if (strcasecmp(&s
[1], "pixmap") == 0)
422 /**********************************************************************/
424 static void drawResizebarBevel(RImage
* img
)
429 int width
= img
->width
;
430 int height
= img
->height
;
434 black
.red
= black
.green
= black
.blue
= 0;
437 light
.red
= light
.green
= light
.blue
= 80;
440 dark
.red
= dark
.green
= dark
.blue
= 40;
442 ROperateLine(img
, RSubtractOperation
, 0, 0, width
- 1, 0, &dark
);
443 ROperateLine(img
, RAddOperation
, 0, 1, width
- 1, 1, &light
);
445 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
- 1, &dark
);
446 ROperateLine(img
, RAddOperation
, cwidth
+ 1, 2, cwidth
+ 1, height
- 1, &light
);
448 ROperateLine(img
, RSubtractOperation
, width
- cwidth
- 2, 2, width
- cwidth
- 2, height
- 1, &dark
);
449 ROperateLine(img
, RAddOperation
, width
- cwidth
- 1, 2, width
- cwidth
- 1, height
- 1, &light
);
451 RDrawLine(img
, 0, height
- 1, width
- 1, height
- 1, &black
);
452 RDrawLine(img
, 0, 0, 0, height
- 1, &black
);
453 RDrawLine(img
, width
- 1, 0, width
- 1, height
- 1, &black
);
456 static void drawMenuBevel(RImage
* img
)
458 RColor light
, dark
, mid
;
460 int iheight
= img
->height
/ 4;
463 light
.red
= light
.green
= light
.blue
= 80;
466 dark
.red
= dark
.green
= dark
.blue
= 0;
469 mid
.red
= mid
.green
= mid
.blue
= 40;
471 for (i
= 1; i
< 4; i
++) {
472 ROperateLine(img
, RSubtractOperation
, 0, i
* iheight
- 2, img
->width
- 1, i
* iheight
- 2, &mid
);
474 RDrawLine(img
, 0, i
* iheight
- 1, img
->width
- 1, i
* iheight
- 1, &dark
);
476 ROperateLine(img
, RAddOperation
, 1, i
* iheight
, img
->width
- 2, i
* iheight
, &light
);
480 static Pixmap
renderTexture(WMScreen
* scr
, WMPropList
* texture
, int width
, int height
, char *path
, int border
)
483 RImage
*image
= NULL
;
485 RContext
*rc
= WMScreenRContext(scr
);
489 type
= WMGetFromPLString(WMGetFromPLArray(texture
, 0));
491 if (strcasecmp(type
, "solid") == 0) {
493 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
495 str2rcolor(rc
, str
, &rcolor
);
497 image
= RCreateImage(width
, height
, False
);
498 RClearImage(image
, &rcolor
);
499 } else if (strcasecmp(type
, "igradient") == 0) {
503 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
504 str2rcolor(rc
, str
, &c1
[0]);
505 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
506 str2rcolor(rc
, str
, &c1
[1]);
507 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
510 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
511 str2rcolor(rc
, str
, &c2
[0]);
512 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 5));
513 str2rcolor(rc
, str
, &c2
[1]);
514 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 6));
517 image
= RRenderInterwovenGradient(width
, height
, c1
, t1
, c2
, t2
);
518 } else if (strcasecmp(&type
[1], "gradient") == 0) {
522 switch (toupper(type
[0])) {
524 style
= RVerticalGradient
;
527 style
= RHorizontalGradient
;
531 style
= RDiagonalGradient
;
535 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
536 str2rcolor(rc
, str
, &rcolor
);
537 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
538 str2rcolor(rc
, str
, &rcolor2
);
540 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
541 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'T') {
545 RImage
*grad
, *timage
= NULL
;
548 switch (toupper(type
[1])) {
550 style
= RVerticalGradient
;
553 style
= RHorizontalGradient
;
557 style
= RDiagonalGradient
;
561 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
562 str2rcolor(rc
, str
, &rcolor
);
563 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
564 str2rcolor(rc
, str
, &rcolor2
);
566 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
568 if ((path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
)) != NULL
)
569 timage
= RLoadImage(rc
, path
, 0);
571 if (!path
|| !timage
) {
572 wwarning("could not load file '%s': %s", path
, RMessageForError(RErrorCode
));
574 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
576 image
= RMakeTiledImage(timage
, width
, height
);
577 RReleaseImage(timage
);
579 i
= atoi(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
581 RCombineImagesWithOpaqueness(image
, grad
, i
);
584 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'M') {
589 switch (toupper(type
[1])) {
591 style
= RVerticalGradient
;
594 style
= RHorizontalGradient
;
598 style
= RDiagonalGradient
;
602 j
= WMGetPropListItemCount(texture
);
605 colors
= wmalloc(j
* sizeof(RColor
*));
607 for (i
= 2; i
< j
; i
++) {
608 str
= WMGetFromPLString(WMGetFromPLArray(texture
, i
));
609 colors
[i
- 2] = wmalloc(sizeof(RColor
));
610 str2rcolor(rc
, str
, colors
[i
- 2]);
612 colors
[i
- 2] = NULL
;
614 image
= RRenderMultiGradient(width
, height
, colors
, style
);
616 for (i
= 0; colors
[i
] != NULL
; i
++)
620 } else if (strcasecmp(&type
[1], "pixmap") == 0) {
621 RImage
*timage
= NULL
;
625 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
627 if ((path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
)) != NULL
)
628 timage
= RLoadImage(rc
, path
, 0);
630 if (!path
|| !timage
) {
631 wwarning("could not load file '%s': %s", path
? path
: str
, RMessageForError(RErrorCode
));
633 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
634 str2rcolor(rc
, str
, &color
);
636 switch (toupper(type
[0])) {
638 image
= RMakeTiledImage(timage
, width
, height
);
639 RReleaseImage(timage
);
643 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
644 RReleaseImage(timage
);
649 image
= RScaleImage(timage
, width
, height
);
650 RReleaseImage(timage
);
663 dumpRImage(path
, image
);
667 if (border
== RESIZEBAR_BEVEL
) {
668 drawResizebarBevel(image
);
669 } else if (border
== MENU_BEVEL
) {
670 drawMenuBevel(image
);
671 RBevelImage(image
, RBEV_RAISED2
);
674 RBevelImage(image
, border
);
677 RConvertImage(rc
, image
, &pixmap
);
678 RReleaseImage(image
);
683 static Pixmap
renderMenu(_Panel
* panel
, WMPropList
* texture
, int width
, int iheight
)
685 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
686 Display
*dpy
= WMScreenDisplay(scr
);
688 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
691 switch (panel
->menuStyle
) {
693 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
695 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
* 4, WMScreenDepth(scr
));
696 for (i
= 0; i
< 4; i
++) {
697 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
* i
);
699 XFreePixmap(dpy
, tmp
);
702 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, MENU_BEVEL
);
705 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, RBEV_RAISED2
);
715 static void renderPreview(_Panel
* panel
, GC gc
, int part
, int relief
)
718 TextureListItem
*titem
;
720 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
722 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
723 titem
= (TextureListItem
*) item
->clientData
;
725 pix
= renderTexture(scr
, titem
->prop
,
726 previewPositions
[part
].size
.width
, previewPositions
[part
].size
.height
, NULL
, relief
);
728 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
729 previewPositions
[part
].size
.width
,
730 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
732 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->previewNoText
, gc
, 0, 0,
733 previewPositions
[part
].size
.width
,
734 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
736 XFreePixmap(WMScreenDisplay(scr
), pix
);
739 static void updatePreviewBox(_Panel
* panel
, int elements
)
741 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
742 Display
*dpy
= WMScreenDisplay(scr
);
746 WMColor
*black
= WMBlackColor(scr
);
748 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
750 if (panel
->preview
== None
) {
754 panel
->previewNoText
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
755 240 - 4, 215 - 4, WMScreenDepth(scr
));
757 p
= WMCreatePixmap(scr
, 240 - 4, 215 - 4, WMScreenDepth(scr
), False
);
758 panel
->preview
= WMGetPixmapXID(p
);
759 WMSetLabelImage(panel
->prevL
, p
);
762 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
763 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
), 0, 0, 240 - 4, 215 - 4);
764 XFillRectangle(dpy
, panel
->previewNoText
, WMColorGC(color
), 0, 0, 240 - 4, 215 - 4);
765 WMReleaseColor(color
);
768 if (elements
& (1 << PFOCUSED
)) {
769 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
770 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
771 previewPositions
[PFOCUSED
].pos
.x
- 1,
772 previewPositions
[PFOCUSED
].pos
.y
- 1,
773 previewPositions
[PFOCUSED
].size
.width
, previewPositions
[PFOCUSED
].size
.height
);
774 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
775 previewPositions
[PFOCUSED
].pos
.x
- 1,
776 previewPositions
[PFOCUSED
].pos
.y
- 1,
777 previewPositions
[PFOCUSED
].size
.width
, previewPositions
[PFOCUSED
].size
.height
);
778 colorUpdate
|= FTITLE_COL
;
780 if (elements
& (1 << PUNFOCUSED
)) {
781 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
782 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
783 previewPositions
[PUNFOCUSED
].pos
.x
- 1,
784 previewPositions
[PUNFOCUSED
].pos
.y
- 1,
785 previewPositions
[PUNFOCUSED
].size
.width
, previewPositions
[PUNFOCUSED
].size
.height
);
786 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
787 previewPositions
[PUNFOCUSED
].pos
.x
- 1,
788 previewPositions
[PUNFOCUSED
].pos
.y
- 1,
789 previewPositions
[PUNFOCUSED
].size
.width
, previewPositions
[PUNFOCUSED
].size
.height
);
790 colorUpdate
|= UTITLE_COL
;
792 if (elements
& (1 << POWNER
)) {
793 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
794 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
795 previewPositions
[POWNER
].pos
.x
- 1,
796 previewPositions
[POWNER
].pos
.y
- 1,
797 previewPositions
[POWNER
].size
.width
, previewPositions
[POWNER
].size
.height
);
798 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
799 previewPositions
[POWNER
].pos
.x
- 1,
800 previewPositions
[POWNER
].pos
.y
- 1,
801 previewPositions
[POWNER
].size
.width
, previewPositions
[POWNER
].size
.height
);
802 colorUpdate
|= OTITLE_COL
;
804 if (elements
& (1 << PRESIZEBAR
)) {
805 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
807 if (elements
& (1 << PMTITLE
)) {
808 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
809 colorUpdate
|= MTITLE_COL
;
811 if (elements
& (1 << PMITEM
)) {
813 TextureListItem
*titem
;
815 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
816 titem
= (TextureListItem
*) item
->clientData
;
818 pix
= renderMenu(panel
, titem
->prop
,
819 previewPositions
[PMITEM
].size
.width
, previewPositions
[PMITEM
].size
.height
/ 4);
821 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
822 previewPositions
[PMITEM
].size
.width
,
823 previewPositions
[PMITEM
].size
.height
,
824 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
826 XCopyArea(dpy
, pix
, panel
->previewNoText
, gc
, 0, 0,
827 previewPositions
[PMITEM
].size
.width
,
828 previewPositions
[PMITEM
].size
.height
,
829 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
831 XFreePixmap(dpy
, pix
);
833 colorUpdate
|= MITEM_COL
| MDISAB_COL
| MHIGH_COL
| MHIGHT_COL
;
835 if (elements
& (1 << PMITEM
| 1 << PMTITLE
)) {
836 XDrawLine(dpy
, panel
->preview
, gc
, 29, 120, 29, 120 + 20 * 4 + 20);
837 XDrawLine(dpy
, panel
->preview
, gc
, 29, 119, 119, 119);
839 XDrawLine(dpy
, panel
->previewNoText
, gc
, 29, 120, 29, 120 + 20 * 4 + 20);
840 XDrawLine(dpy
, panel
->previewNoText
, gc
, 29, 119, 119, 119);
842 if (elements
& (1 << PICON
)) {
844 TextureListItem
*titem
;
846 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
847 titem
= (TextureListItem
*) item
->clientData
;
849 renderPreview(panel
, gc
, PICON
, titem
->ispixmap
? 0 : RBEV_RAISED3
);
851 colorUpdate
|= ICONT_COL
| ICONB_COL
| CLIP_COL
| CCLIP_COL
;
855 updateColorPreviewBox(panel
, colorUpdate
);
857 WMRedisplayWidget(panel
->prevL
);
860 WMReleaseColor(black
);
863 static void cancelNewTexture(void *data
)
865 _Panel
*panel
= (_Panel
*) data
;
867 HideTexturePanel(panel
->texturePanel
);
870 static char *makeFileName(char *prefix
)
874 fname
= wstrdup(prefix
);
876 while (access(fname
, F_OK
) == 0) {
880 sprintf(buf
, "%08lx.cache", time(NULL
));
881 fname
= wstrconcat(prefix
, buf
);
887 static void okNewTexture(void *data
)
889 _Panel
*panel
= (_Panel
*) data
;
894 TextureListItem
*titem
;
895 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
897 titem
= wmalloc(sizeof(TextureListItem
));
898 memset(titem
, 0, sizeof(TextureListItem
));
900 HideTexturePanel(panel
->texturePanel
);
902 name
= GetTexturePanelTextureName(panel
->texturePanel
);
904 prop
= GetTexturePanelTexture(panel
->texturePanel
);
906 str
= WMGetPropListDescription(prop
, False
);
910 titem
->texture
= str
;
911 titem
->selectedFor
= 0;
913 titem
->ispixmap
= isPixmap(prop
);
915 titem
->path
= makeFileName(panel
->fprefix
);
916 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
918 item
= WMAddListItem(panel
->texLs
, "");
919 item
->clientData
= titem
;
921 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
924 static void okEditTexture(void *data
)
926 _Panel
*panel
= (_Panel
*) data
;
931 TextureListItem
*titem
;
933 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
934 titem
= (TextureListItem
*) item
->clientData
;
936 HideTexturePanel(panel
->texturePanel
);
938 if (titem
->current
) {
939 name
= GetTexturePanelTextureName(panel
->texturePanel
);
945 prop
= GetTexturePanelTexture(panel
->texturePanel
);
947 str
= WMGetPropListDescription(prop
, False
);
949 WMReleasePropList(titem
->prop
);
952 titem
->ispixmap
= isPixmap(prop
);
954 wfree(titem
->texture
);
955 titem
->texture
= str
;
957 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
958 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
959 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
961 WMRedisplayWidget(panel
->texLs
);
963 if (titem
->selectedFor
)
964 updatePreviewBox(panel
, titem
->selectedFor
);
966 changePage(panel
->secP
, panel
);
969 static void editTexture(WMWidget
* w
, void *data
)
971 _Panel
*panel
= (_Panel
*) data
;
973 TextureListItem
*titem
;
975 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
976 titem
= (TextureListItem
*) item
->clientData
;
978 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
980 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
982 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
983 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
985 ShowTexturePanel(panel
->texturePanel
);
988 static void newTexture(WMWidget
* w
, void *data
)
990 _Panel
*panel
= (_Panel
*) data
;
992 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
994 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
996 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
998 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
1000 ShowTexturePanel(panel
->texturePanel
);
1003 static void deleteTexture(WMWidget
* w
, void *data
)
1005 _Panel
*panel
= (_Panel
*) data
;
1007 TextureListItem
*titem
;
1011 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1012 row
= WMGetListSelectedItemRow(panel
->texLs
);
1013 item
= WMGetListItem(panel
->texLs
, row
);
1014 titem
= (TextureListItem
*) item
->clientData
;
1016 if (titem
->selectedFor
& (1 << section
)) {
1017 TextureListItem
*titem2
;
1019 panel
->textureIndex
[section
] = section
;
1020 item
= WMGetListItem(panel
->texLs
, section
);
1021 titem2
= (TextureListItem
*) item
->clientData
;
1022 titem2
->selectedFor
|= 1 << section
;
1025 wfree(titem
->title
);
1026 wfree(titem
->texture
);
1027 WMReleasePropList(titem
->prop
);
1029 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1030 werror("could not remove file %s", titem
->path
);
1037 WMRemoveListItem(panel
->texLs
, row
);
1038 WMSetButtonEnabled(panel
->delB
, False
);
1041 static void extractTexture(WMWidget
* w
, void *data
)
1043 _Panel
*panel
= (_Panel
*) data
;
1045 WMOpenPanel
*opanel
;
1046 WMScreen
*scr
= WMWidgetScreen(w
);
1048 opanel
= WMGetOpenPanel(scr
);
1049 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1050 WMSetFilePanelCanChooseFiles(opanel
, True
);
1052 if (WMRunModalFilePanelForDirectory(opanel
, panel
->parent
, wgethomedir(), _("Select File"), NULL
)) {
1053 path
= WMGetFilePanelFileName(opanel
);
1055 OpenExtractPanelFor(panel
, path
);
1061 static void changePage(WMWidget
* w
, void *data
)
1063 _Panel
*panel
= (_Panel
*) data
;
1065 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1066 RContext
*rc
= WMScreenRContext(scr
);
1067 static WMPoint positions
[] = {
1078 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1080 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1082 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1087 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1088 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1089 positions
[panel
->oldsection
].x
, positions
[panel
->oldsection
].y
, 22, 22);
1090 WMReleaseColor(color
);
1093 panel
->oldsection
= section
;
1094 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1096 WMRedisplayWidget(panel
->prevL
);
1099 static void previewClick(XEvent
* event
, void *clientData
)
1101 _Panel
*panel
= (_Panel
*) clientData
;
1104 switch (panel
->oldTabItem
) {
1106 for (i
= 0; i
< sizeof(previewPositions
) / sizeof(WMRect
); i
++) {
1107 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
1108 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
1109 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
1110 + previewPositions
[i
].size
.width
1111 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
+ previewPositions
[i
].size
.height
) {
1113 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1114 changePage(panel
->secP
, panel
);
1120 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1121 if (event
->xbutton
.x
>= previewColorPositions
[i
].pos
.x
1122 && event
->xbutton
.y
>= previewColorPositions
[i
].pos
.y
1123 && event
->xbutton
.x
< previewColorPositions
[i
].pos
.x
1124 + previewColorPositions
[i
].size
.width
1125 && event
->xbutton
.y
< previewColorPositions
[i
].pos
.y
1126 + previewColorPositions
[i
].size
.height
) {
1132 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1133 changeColorPage(panel
->colP
, panel
);
1141 static void textureClick(WMWidget
* w
, void *data
)
1143 _Panel
*panel
= (_Panel
*) data
;
1146 TextureListItem
*titem
;
1148 i
= WMGetListSelectedItemRow(panel
->texLs
);
1150 item
= WMGetListItem(panel
->texLs
, i
);
1152 titem
= (TextureListItem
*) item
->clientData
;
1154 if (titem
->current
) {
1155 WMSetButtonEnabled(panel
->delB
, False
);
1157 WMSetButtonEnabled(panel
->delB
, True
);
1161 static void textureDoubleClick(WMWidget
* w
, void *data
)
1163 _Panel
*panel
= (_Panel
*) data
;
1166 TextureListItem
*titem
;
1168 /* unselect old texture */
1169 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1171 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1172 titem
= (TextureListItem
*) item
->clientData
;
1173 titem
->selectedFor
&= ~(1 << section
);
1175 /* select new texture */
1176 i
= WMGetListSelectedItemRow(panel
->texLs
);
1178 item
= WMGetListItem(panel
->texLs
, i
);
1180 titem
= (TextureListItem
*) item
->clientData
;
1182 titem
->selectedFor
|= 1 << section
;
1184 panel
->textureIndex
[section
] = i
;
1186 WMRedisplayWidget(panel
->texLs
);
1188 updatePreviewBox(panel
, 1 << section
);
1191 static void paintListItem(WMList
* lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
* rect
)
1193 _Panel
*panel
= (_Panel
*) WMGetHangedData(lPtr
);
1194 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1195 int width
, height
, x
, y
;
1196 Display
*dpy
= WMScreenDisplay(scr
);
1197 WMColor
*back
= (state
& WLDSSelected
) ? WMWhiteColor(scr
) : WMGrayColor(scr
);
1199 WMColor
*black
= WMBlackColor(scr
);
1200 TextureListItem
*titem
;
1202 item
= WMGetListItem(lPtr
, index
);
1203 titem
= (TextureListItem
*) item
->clientData
;
1205 WMReleaseColor(back
);
1206 WMReleaseColor(black
);
1210 width
= rect
->size
.width
;
1211 height
= rect
->size
.height
;
1215 XFillRectangle(dpy
, d
, WMColorGC(back
), x
, y
, width
, height
);
1218 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0,
1219 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1221 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1222 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1223 else if (titem
->selectedFor
)
1224 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1226 WMDrawString(scr
, d
, black
, panel
->boldFont
,
1227 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
, strlen(titem
->title
));
1229 WMDrawString(scr
, d
, black
, panel
->smallFont
,
1230 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
, strlen(titem
->texture
));
1232 WMReleaseColor(back
);
1233 WMReleaseColor(black
);
1236 static Pixmap
loadRImage(WMScreen
* scr
, char *path
)
1243 f
= fopen(path
, "rb");
1247 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1249 image
= RCreateImage(w
, h
, d
== 4);
1250 fread(image
->data
, 1, w
* h
* d
, f
);
1253 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1254 RReleaseImage(image
);
1259 static void fillTextureList(WMList
* lPtr
)
1261 WMPropList
*textureList
;
1262 WMPropList
*texture
;
1263 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1264 TextureListItem
*titem
;
1265 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1268 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1272 for (i
= 0; i
< WMGetPropListItemCount(textureList
); i
++) {
1275 texture
= WMGetFromPLArray(textureList
, i
);
1277 titem
= wmalloc(sizeof(TextureListItem
));
1278 memset(titem
, 0, sizeof(TextureListItem
));
1280 titem
->title
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 0)));
1281 titem
->prop
= WMRetainPropList(WMGetFromPLArray(texture
, 1));
1282 titem
->texture
= WMGetPropListDescription(titem
->prop
, False
);
1283 titem
->selectedFor
= 0;
1284 titem
->path
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
1286 titem
->preview
= loadRImage(scr
, titem
->path
);
1287 if (!titem
->preview
) {
1288 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1290 item
= WMAddListItem(lPtr
, "");
1291 item
->clientData
= titem
;
1295 static void fillColorList(_Panel
* panel
)
1299 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1300 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1303 list
= WMGetUDObjectForKey(udb
, "ColorList");
1305 for (i
= 0; i
< 24; i
++) {
1306 color
= WMCreateNamedColor(scr
, sampleColors
[i
], False
);
1309 WMSetColorWellColor(panel
->sampW
[i
], color
);
1310 WMReleaseColor(color
);
1315 for (i
= 0; i
< WMIN(24, WMGetPropListItemCount(list
)); i
++) {
1316 c
= WMGetFromPLArray(list
, i
);
1317 if (!c
|| !WMIsPLString(c
))
1319 color
= WMCreateNamedColor(scr
, WMGetFromPLString(c
), False
);
1322 WMSetColorWellColor(panel
->sampW
[i
], color
);
1323 WMReleaseColor(color
);
1328 /*************************************************************************/
1330 static void changeColorPage(WMWidget
* w
, void *data
)
1332 _Panel
*panel
= (_Panel
*) data
;
1334 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1335 RContext
*rc
= WMScreenRContext(scr
);
1336 static WMPoint positions
[] = {
1351 if (panel
->preview
) {
1354 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1355 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1356 positions
[panel
->oldcsection
].x
, positions
[panel
->oldcsection
].y
, 22, 22);
1357 WMReleaseColor(color
);
1360 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1362 panel
->oldcsection
= section
;
1364 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1366 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1368 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1370 WMRedisplayWidget(panel
->prevL
);
1374 paintText(WMScreen
* scr
, Drawable d
, WMColor
* color
, WMFont
* font
,
1375 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1377 int l
= strlen(text
);
1384 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1388 x
+= (w
- WMWidthOfString(font
, text
, l
)) / 2;
1391 WMDrawString(scr
, d
, color
, font
, x
, y
+ (h
- WMFontHeight(font
)) / 2, text
, l
);
1394 static void updateColorPreviewBox(_Panel
* panel
, int elements
)
1396 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1397 Display
*dpy
= WMScreenDisplay(scr
);
1402 pnot
= panel
->previewNoText
;
1403 gc
= WMColorGC(panel
->colors
[0]);
1405 if (elements
& FTITLE_COL
) {
1406 XCopyArea(dpy
, pnot
, d
, gc
, 30, 10, 190, 20, 30, 10);
1407 paintText(scr
, d
, panel
->colors
[0], panel
->boldFont
, 30, 10, 190, 20,
1408 panel
->titleAlignment
, _("Focused Window"));
1410 if (elements
& UTITLE_COL
) {
1411 XCopyArea(dpy
, pnot
, d
, gc
, 30, 40, 190, 20, 30, 40);
1412 paintText(scr
, d
, panel
->colors
[1], panel
->boldFont
, 30, 40, 190, 20,
1413 panel
->titleAlignment
, _("Unfocused Window"));
1415 if (elements
& OTITLE_COL
) {
1416 XCopyArea(dpy
, pnot
, d
, gc
, 30, 70, 190, 20, 30, 70);
1417 paintText(scr
, d
, panel
->colors
[2], panel
->boldFont
, 30, 70, 190, 20,
1418 panel
->titleAlignment
, _("Owner of Focused Window"));
1420 if (elements
& MTITLE_COL
) {
1421 XCopyArea(dpy
, pnot
, d
, gc
, 30, 120, 90, 20, 30, 120);
1422 paintText(scr
, d
, panel
->colors
[3], panel
->boldFont
, 30, 120, 90, 20, WALeft
, _("Menu Title"));
1424 if (elements
& MITEM_COL
) {
1425 XCopyArea(dpy
, pnot
, d
, gc
, 30, 140, 90, 20, 30, 140);
1426 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 140, 90, 20, WALeft
, _("Normal Item"));
1427 XCopyArea(dpy
, pnot
, d
, gc
, 30, 200, 90, 20, 30, 200);
1428 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 200, 90, 20, WALeft
, _("Normal Item"));
1430 if (elements
& MDISAB_COL
) {
1431 XCopyArea(dpy
, pnot
, d
, gc
, 30, 160, 90, 20, 30, 160);
1432 paintText(scr
, d
, panel
->colors
[5], panel
->normalFont
, 30, 160, 90, 20,
1433 WALeft
, _("Disabled Item"));
1435 if (elements
& MHIGH_COL
) {
1436 XFillRectangle(WMScreenDisplay(scr
), d
, WMColorGC(panel
->colors
[6]), 31, 181, 87, 17);
1437 XFillRectangle(WMScreenDisplay(scr
), pnot
, WMColorGC(panel
->colors
[6]), 31, 181, 87, 17);
1438 elements
|= MHIGHT_COL
;
1440 if (elements
& MHIGHT_COL
) {
1441 XCopyArea(dpy
, pnot
, d
, gc
, 30, 180, 90, 20, 30, 180);
1442 paintText(scr
, d
, panel
->colors
[7], panel
->normalFont
, 30, 180, 90, 20, WALeft
, _("Highlighted"));
1445 if (elements & ICONT_COL) {
1446 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1449 if (elements & ICONB_COL) {
1450 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1453 if (elements & CLIP_COL) {
1454 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1457 if (elements & CCLIP_COL) {
1458 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1462 WMRedisplayWidget(panel
->prevL
);
1465 static void colorWellObserver(void *self
, WMNotification
* n
)
1467 _Panel
*panel
= (_Panel
*) self
;
1470 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1472 WMReleaseColor(panel
->colors
[p
]);
1474 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1476 updateColorPreviewBox(panel
, 1 << p
);
1479 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
)
1481 _Panel
*panel
= self
->data
;
1484 i
= WMGetTabViewItemIdentifier(item
);
1487 switch (panel
->oldTabItem
) {
1489 changeColorPage(NULL
, panel
);
1492 changePage(panel
->secP
, panel
);
1495 switch (panel
->oldTabItem
) {
1497 changePage(NULL
, panel
);
1500 changeColorPage(panel
->colP
, panel
);
1503 switch (panel
->oldTabItem
) {
1505 changePage(NULL
, panel
);
1508 changeColorPage(NULL
, panel
);
1514 panel
->oldTabItem
= i
;
1517 /*************************************************************************/
1519 static void menuStyleCallback(WMWidget
* self
, void *data
)
1521 _Panel
*panel
= (_Panel
*) data
;
1523 if (self
== panel
->mstyB
[0]) {
1524 panel
->menuStyle
= MSTYLE_NORMAL
;
1525 updatePreviewBox(panel
, 1 << PMITEM
);
1527 } else if (self
== panel
->mstyB
[1]) {
1528 panel
->menuStyle
= MSTYLE_SINGLE
;
1529 updatePreviewBox(panel
, 1 << PMITEM
);
1531 } else if (self
== panel
->mstyB
[2]) {
1532 panel
->menuStyle
= MSTYLE_FLAT
;
1533 updatePreviewBox(panel
, 1 << PMITEM
);
1537 static void titleAlignCallback(WMWidget
* self
, void *data
)
1539 _Panel
*panel
= (_Panel
*) data
;
1541 if (self
== panel
->taliB
[0]) {
1542 panel
->titleAlignment
= WALeft
;
1543 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1545 } else if (self
== panel
->taliB
[1]) {
1546 panel
->titleAlignment
= WACenter
;
1547 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1549 } else if (self
== panel
->taliB
[2]) {
1550 panel
->titleAlignment
= WARight
;
1551 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1555 static void createPanel(Panel
* p
)
1557 _Panel
*panel
= (_Panel
*) p
;
1559 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1560 WMTabViewItem
*item
;
1565 panel
->fprefix
= wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1567 if (access(panel
->fprefix
, F_OK
) != 0) {
1568 if (mkdir(panel
->fprefix
, 0755) < 0) {
1569 werror("%s", panel
->fprefix
);
1574 tmp
= wstrconcat(panel
->fprefix
, "/WPrefs/");
1575 wfree(panel
->fprefix
);
1576 panel
->fprefix
= tmp
;
1577 if (access(panel
->fprefix
, F_OK
) != 0) {
1578 if (mkdir(panel
->fprefix
, 0755) < 0) {
1579 werror("%s", panel
->fprefix
);
1584 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1585 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1586 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1588 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1589 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1590 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1592 panel
->box
= WMCreateBox(panel
->parent
);
1593 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
1596 panel
->prevL
= WMCreateLabel(panel
->box
);
1597 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1598 WMMoveWidget(panel
->prevL
, 15, 10);
1599 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1600 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1602 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
, previewClick
, panel
);
1606 tabviewDelegate
.data
= panel
;
1608 panel
->tabv
= WMCreateTabView(panel
->box
);
1609 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1610 WMMoveWidget(panel
->tabv
, 265, 10);
1611 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1613 /*** texture list ***/
1615 panel
->texF
= WMCreateFrame(panel
->box
);
1616 WMSetFrameRelief(panel
->texF
, WRFlat
);
1618 item
= WMCreateTabViewItemWithIdentifier(0);
1619 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1620 WMSetTabViewItemLabel(item
, _("Texture"));
1622 WMAddItemInTabView(panel
->tabv
, item
);
1624 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1625 WMResizeWidget(panel
->secP
, 228, 20);
1626 WMMoveWidget(panel
->secP
, 7, 7);
1627 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1628 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1629 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1630 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1631 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1632 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1633 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1634 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1636 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1637 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1639 panel
->texLs
= WMCreateList(panel
->texF
);
1640 WMResizeWidget(panel
->texLs
, 165, 155);
1641 WMMoveWidget(panel
->texLs
, 70, 33);
1642 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1643 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1644 WMHangData(panel
->texLs
, panel
);
1645 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1646 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1648 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1649 "for the selected item."), WMWidgetView(panel
->texLs
));
1651 /* command buttons */
1653 font
= WMSystemFontOfSize(scr
, 10);
1655 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1656 WMResizeWidget(panel
->newB
, 57, 39);
1657 WMMoveWidget(panel
->newB
, 7, 33);
1658 WMSetButtonFont(panel
->newB
, font
);
1659 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1660 WMSetButtonText(panel
->newB
, _("New"));
1661 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1662 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
, NULL
, NULL
);
1664 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel
->newB
));
1666 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1667 WMResizeWidget(panel
->ripB
, 57, 39);
1668 WMMoveWidget(panel
->ripB
, 7, 72);
1669 WMSetButtonFont(panel
->ripB
, font
);
1670 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1671 WMSetButtonText(panel
->ripB
, _("Extract..."));
1672 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1673 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
, NULL
, NULL
);
1675 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel
->ripB
));
1677 WMSetButtonEnabled(panel
->ripB
, False
);
1679 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1680 WMResizeWidget(panel
->editB
, 57, 39);
1681 WMMoveWidget(panel
->editB
, 7, 111);
1682 WMSetButtonFont(panel
->editB
, font
);
1683 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1684 WMSetButtonText(panel
->editB
, _("Edit"));
1685 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
, NULL
, NULL
);
1686 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1687 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel
->editB
));
1689 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1690 WMResizeWidget(panel
->delB
, 57, 38);
1691 WMMoveWidget(panel
->delB
, 7, 150);
1692 WMSetButtonFont(panel
->delB
, font
);
1693 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1694 WMSetButtonText(panel
->delB
, _("Delete"));
1695 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
, NULL
, NULL
);
1696 WMSetButtonEnabled(panel
->delB
, False
);
1697 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1698 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel
->delB
));
1700 WMReleaseFont(font
);
1702 WMMapSubwidgets(panel
->texF
);
1705 panel
->colF
= WMCreateFrame(panel
->box
);
1706 WMSetFrameRelief(panel
->colF
, WRFlat
);
1708 item
= WMCreateTabViewItemWithIdentifier(1);
1709 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1710 WMSetTabViewItemLabel(item
, _("Color"));
1712 WMAddItemInTabView(panel
->tabv
, item
);
1714 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1715 WMResizeWidget(panel
->colP
, 228, 20);
1716 WMMoveWidget(panel
->colP
, 7, 7);
1717 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Title"));
1718 WMAddPopUpButtonItem(panel
->colP
, _("Unfocused Window Title"));
1719 WMAddPopUpButtonItem(panel
->colP
, _("Owner of Focused Window Title"));
1720 WMAddPopUpButtonItem(panel
->colP
, _("Menu Title"));
1721 WMAddPopUpButtonItem(panel
->colP
, _("Menu Item Text"));
1722 WMAddPopUpButtonItem(panel
->colP
, _("Disabled Menu Item Text"));
1723 WMAddPopUpButtonItem(panel
->colP
, _("Menu Highlight Color"));
1724 WMAddPopUpButtonItem(panel
->colP
, _("Highlighted Menu Text Color"));
1726 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1727 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1728 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1729 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1732 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1734 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1736 panel
->colW
= WMCreateColorWell(panel
->colF
);
1737 WMResizeWidget(panel
->colW
, 65, 50);
1738 WMMoveWidget(panel
->colW
, 30, 75);
1739 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->colW
);
1741 for (i
= 0; i
< 4; i
++) {
1743 for (j
= 0; j
< 6; j
++) {
1744 panel
->sampW
[i
+ j
* 4] = WMCreateColorWell(panel
->colF
);
1745 WMResizeWidget(panel
->sampW
[i
+ j
* 4], 22, 22);
1746 WMMoveWidget(panel
->sampW
[i
+ j
* 4], 130 + i
* 22, 40 + j
* 22);
1747 WSetColorWellBordered(panel
->sampW
[i
+ j
* 4], False
);
1751 WMMapSubwidgets(panel
->colF
);
1756 panel
->bgF
= WMCreateFrame(panel
->box
);
1757 WMSetFrameRelief(panel
->bgF
, WRFlat
);
1759 item
= WMCreateTabViewItemWithIdentifier(2);
1760 WMSetTabViewItemView(item
, WMWidgetView(panel
->bgF
));
1761 WMSetTabViewItemLabel(item
, _("Background"));
1763 WMAddItemInTabView(panel
->tabv
, item
);
1765 panel
->bgprevL
= WMCreateLabel(panel
->bgF
);
1766 WMResizeWidget(panel
->bgprevL
, 230, 155);
1767 WMMoveWidget(panel
->bgprevL
, 5, 5);
1768 WMSetLabelRelief(panel
->bgprevL
, WRSunken
);
1770 panel
->selbgB
= WMCreateCommandButton(panel
->bgF
);
1771 WMMoveWidget(panel
->selbgB
, 5, 165);
1772 WMResizeWidget(panel
->selbgB
, 100, 24);
1773 WMSetButtonText(panel
->selbgB
, _("Browse..."));
1775 WMMapSubwidgets(panel
->bgF
);
1776 #endif /* unfinished */
1778 panel
->optF
= WMCreateFrame(panel
->box
);
1779 WMSetFrameRelief(panel
->optF
, WRFlat
);
1781 item
= WMCreateTabViewItemWithIdentifier(3);
1782 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1783 WMSetTabViewItemLabel(item
, _("Options"));
1785 WMAddItemInTabView(panel
->tabv
, item
);
1787 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1788 WMResizeWidget(panel
->mstyF
, 215, 85);
1789 WMMoveWidget(panel
->mstyF
, 15, 10);
1790 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1792 for (i
= 0; i
< 3; i
++) {
1796 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1797 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1798 WMMoveWidget(panel
->mstyB
[i
], 15 + i
* 65, 20);
1799 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1800 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1803 path
= LocateImage(MSTYLE1_FILE
);
1806 path
= LocateImage(MSTYLE2_FILE
);
1809 path
= LocateImage(MSTYLE3_FILE
);
1813 icon
= WMCreatePixmapFromFile(scr
, path
);
1815 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1816 WMReleasePixmap(icon
);
1818 wwarning(_("could not load icon file %s"), path
);
1823 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1824 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1826 WMMapSubwidgets(panel
->mstyF
);
1828 panel
->taliF
= WMCreateFrame(panel
->optF
);
1829 WMResizeWidget(panel
->taliF
, 110, 80);
1830 WMMoveWidget(panel
->taliF
, 15, 100);
1831 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
1833 for (i
= 0; i
< 3; i
++) {
1834 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
1835 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
1838 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1841 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1844 WMSetButtonText(panel
->taliB
[i
], _("Right"));
1847 WMResizeWidget(panel
->taliB
[i
], 90, 18);
1848 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20 * i
);
1850 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
1851 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
1853 WMMapSubwidgets(panel
->taliF
);
1855 WMMapSubwidgets(panel
->optF
);
1857 /**/ WMRealizeWidget(panel
->box
);
1858 WMMapSubwidgets(panel
->box
);
1860 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1864 changePage(panel
->secP
, panel
);
1866 fillTextureList(panel
->texLs
);
1868 fillColorList(panel
);
1870 panel
->texturePanel
= CreateTexturePanel(panel
->parent
);
1873 static void setupTextureFor(WMList
* list
, char *key
, char *defValue
, char *title
, int index
)
1876 TextureListItem
*titem
;
1878 titem
= wmalloc(sizeof(TextureListItem
));
1879 memset(titem
, 0, sizeof(TextureListItem
));
1881 titem
->title
= wstrdup(title
);
1882 titem
->prop
= GetObjectForKey(key
);
1883 if (!titem
->prop
|| !WMIsPLArray(titem
->prop
)) {
1884 /* Maybe also give a error message to stderr that the entry is bad? */
1885 titem
->prop
= WMCreatePropListFromDescription(defValue
);
1887 WMRetainPropList(titem
->prop
);
1889 titem
->texture
= WMGetPropListDescription((WMPropList
*) titem
->prop
, False
);
1891 titem
->selectedFor
= 1 << index
;
1893 titem
->ispixmap
= isPixmap(titem
->prop
);
1895 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1897 item
= WMAddListItem(list
, "");
1898 item
->clientData
= titem
;
1901 static void showData(_Panel
* panel
)
1906 str
= GetStringForKey("MenuStyle");
1907 if (str
&& strcasecmp(str
, "flat") == 0) {
1908 panel
->menuStyle
= MSTYLE_FLAT
;
1909 } else if (str
&& strcasecmp(str
, "singletexture") == 0) {
1910 panel
->menuStyle
= MSTYLE_SINGLE
;
1912 panel
->menuStyle
= MSTYLE_NORMAL
;
1915 str
= GetStringForKey("TitleJustify");
1916 if (str
&& strcasecmp(str
, "left") == 0) {
1917 panel
->titleAlignment
= WALeft
;
1918 } else if (str
&& strcasecmp(str
, "right") == 0) {
1919 panel
->titleAlignment
= WARight
;
1921 panel
->titleAlignment
= WACenter
;
1924 for (i
= 0; i
< sizeof(colorOptions
) / (2 * sizeof(char *)); i
++) {
1927 str
= GetStringForKey(colorOptions
[i
* 2]);
1929 str
= colorOptions
[i
* 2 + 1];
1931 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), str
, False
))) {
1932 color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), "#000000", False
);
1935 panel
->colors
[i
] = color
;
1937 changeColorPage(panel
->colP
, panel
);
1939 for (i
= 0; i
< sizeof(textureOptions
) / (3 * sizeof(char *)); i
++) {
1940 setupTextureFor(panel
->texLs
, textureOptions
[i
* 3],
1941 textureOptions
[i
* 3 + 1], textureOptions
[i
* 3 + 2], i
);
1942 panel
->textureIndex
[i
] = i
;
1944 updatePreviewBox(panel
, EVERYTHING
);
1946 WMSetButtonSelected(panel
->mstyB
[panel
->menuStyle
], True
);
1947 WMSetButtonSelected(panel
->taliB
[panel
->titleAlignment
], True
);
1950 static void storeData(_Panel
* panel
)
1952 TextureListItem
*titem
;
1956 for (i
= 0; i
< sizeof(textureOptions
) / (sizeof(char *) * 3); i
++) {
1957 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
1958 titem
= (TextureListItem
*) item
->clientData
;
1959 SetObjectForKey(titem
->prop
, textureOptions
[i
* 3]);
1962 for (i
= 0; i
< 8; i
++) {
1965 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
1968 SetStringForKey(str
, colorOptions
[i
* 2]);
1973 switch (panel
->menuStyle
) {
1975 SetStringForKey("singletexture", "MenuStyle");
1978 SetStringForKey("flat", "MenuStyle");
1982 SetStringForKey("normal", "MenuStyle");
1985 switch (panel
->titleAlignment
) {
1987 SetStringForKey("left", "TitleJustify");
1990 SetStringForKey("right", "TitleJustify");
1994 SetStringForKey("center", "TitleJustify");
1999 static void prepareForClose(_Panel
* panel
)
2001 WMPropList
*textureList
;
2002 WMPropList
*texture
;
2003 TextureListItem
*titem
;
2005 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2008 textureList
= WMCreatePLArray(NULL
, NULL
);
2010 /* store list of textures */
2011 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2012 item
= WMGetListItem(panel
->texLs
, i
);
2013 titem
= (TextureListItem
*) item
->clientData
;
2015 texture
= WMCreatePLArray(WMCreatePLString(titem
->title
),
2016 WMRetainPropList(titem
->prop
), WMCreatePLString(titem
->path
), NULL
);
2018 WMAddToPLArray(textureList
, texture
);
2021 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2022 WMReleasePropList(textureList
);
2024 /* store list of colors */
2025 textureList
= WMCreatePLArray(NULL
, NULL
);
2026 for (i
= 0; i
< 24; i
++) {
2030 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2032 str
= WMGetColorRGBDescription(color
);
2033 WMAddToPLArray(textureList
, WMCreatePLString(str
));
2036 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2037 WMReleasePropList(textureList
);
2039 WMSynchronizeUserDefaults(udb
);
2042 Panel
*InitAppearance(WMScreen
* scr
, WMWindow
* win
)
2046 panel
= wmalloc(sizeof(_Panel
));
2047 memset(panel
, 0, sizeof(_Panel
));
2049 panel
->sectionName
= _("Appearance Preferences");
2051 panel
->description
= _("Background texture configuration for windows,\n" "menus and icons.");
2053 panel
->parent
= win
;
2055 panel
->callbacks
.createWidgets
= createPanel
;
2056 panel
->callbacks
.updateDomain
= storeData
;
2057 panel
->callbacks
.prepareForClose
= prepareForClose
;
2059 AddSection(panel
, ICON_FILE
);
2064 /****************************************************************************/
2066 typedef struct ExtractPanel
{
2076 static void OpenExtractPanelFor(_Panel
* panel
, char *path
)
2078 ExtractPanel
*epanel
;
2081 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
2083 epanel
= wmalloc(sizeof(ExtractPanel
));
2084 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->parent
, "extract",
2085 WMTitledWindowMask
| WMClosableWindowMask
);
2086 WMResizeWidget(epanel
->win
, 245, 250);
2087 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2089 epanel
->label
= WMCreateLabel(epanel
->win
);
2090 WMResizeWidget(epanel
->label
, 225, 18);
2091 WMMoveWidget(epanel
->label
, 10, 10);
2092 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2093 WMSetLabelRelief(epanel
->label
, WRSunken
);
2095 color
= WMDarkGrayColor(scr
);
2096 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2097 WMReleaseColor(color
);
2099 color
= WMWhiteColor(scr
);
2100 WMSetLabelTextColor(epanel
->label
, color
);
2101 WMReleaseColor(color
);
2103 font
= WMBoldSystemFontOfSize(scr
, 12);
2104 WMSetLabelFont(epanel
->label
, font
);
2105 WMReleaseFont(font
);
2107 WMSetLabelText(epanel
->label
, _("Textures"));
2109 epanel
->list
= WMCreateList(epanel
->win
);
2110 WMResizeWidget(epanel
->list
, 225, 165);
2111 WMMoveWidget(epanel
->list
, 10, 30);
2113 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2114 WMResizeWidget(epanel
->closeB
, 74, 24);
2115 WMMoveWidget(epanel
->closeB
, 165, 215);
2116 WMSetButtonText(epanel
->closeB
, _("Close"));
2118 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2119 WMResizeWidget(epanel
->extrB
, 74, 24);
2120 WMMoveWidget(epanel
->extrB
, 80, 215);
2121 WMSetButtonText(epanel
->extrB
, _("Extract"));
2123 WMMapSubwidgets(epanel
->win
);
2125 /* take textures from file */
2127 WMRealizeWidget(epanel
->win
);
2129 WMMapWidget(epanel
->win
);