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
);
713 static void renderPreview(_Panel
* panel
, GC gc
, int part
, int relief
)
716 TextureListItem
*titem
;
718 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
720 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
721 titem
= (TextureListItem
*) item
->clientData
;
723 pix
= renderTexture(scr
, titem
->prop
,
724 previewPositions
[part
].size
.width
, previewPositions
[part
].size
.height
, NULL
, relief
);
726 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
727 previewPositions
[part
].size
.width
,
728 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
730 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->previewNoText
, gc
, 0, 0,
731 previewPositions
[part
].size
.width
,
732 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
734 XFreePixmap(WMScreenDisplay(scr
), pix
);
737 static void updatePreviewBox(_Panel
* panel
, int elements
)
739 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
740 Display
*dpy
= WMScreenDisplay(scr
);
744 WMColor
*black
= WMBlackColor(scr
);
746 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
748 if (panel
->preview
== None
) {
752 panel
->previewNoText
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
753 240 - 4, 215 - 4, WMScreenDepth(scr
));
755 p
= WMCreatePixmap(scr
, 240 - 4, 215 - 4, WMScreenDepth(scr
), False
);
756 panel
->preview
= WMGetPixmapXID(p
);
757 WMSetLabelImage(panel
->prevL
, p
);
760 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
761 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
), 0, 0, 240 - 4, 215 - 4);
762 XFillRectangle(dpy
, panel
->previewNoText
, WMColorGC(color
), 0, 0, 240 - 4, 215 - 4);
763 WMReleaseColor(color
);
766 if (elements
& (1 << PFOCUSED
)) {
767 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
768 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
769 previewPositions
[PFOCUSED
].pos
.x
- 1,
770 previewPositions
[PFOCUSED
].pos
.y
- 1,
771 previewPositions
[PFOCUSED
].size
.width
, previewPositions
[PFOCUSED
].size
.height
);
772 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
773 previewPositions
[PFOCUSED
].pos
.x
- 1,
774 previewPositions
[PFOCUSED
].pos
.y
- 1,
775 previewPositions
[PFOCUSED
].size
.width
, previewPositions
[PFOCUSED
].size
.height
);
776 colorUpdate
|= FTITLE_COL
;
778 if (elements
& (1 << PUNFOCUSED
)) {
779 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
780 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
781 previewPositions
[PUNFOCUSED
].pos
.x
- 1,
782 previewPositions
[PUNFOCUSED
].pos
.y
- 1,
783 previewPositions
[PUNFOCUSED
].size
.width
, previewPositions
[PUNFOCUSED
].size
.height
);
784 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
785 previewPositions
[PUNFOCUSED
].pos
.x
- 1,
786 previewPositions
[PUNFOCUSED
].pos
.y
- 1,
787 previewPositions
[PUNFOCUSED
].size
.width
, previewPositions
[PUNFOCUSED
].size
.height
);
788 colorUpdate
|= UTITLE_COL
;
790 if (elements
& (1 << POWNER
)) {
791 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
792 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
793 previewPositions
[POWNER
].pos
.x
- 1,
794 previewPositions
[POWNER
].pos
.y
- 1,
795 previewPositions
[POWNER
].size
.width
, previewPositions
[POWNER
].size
.height
);
796 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
797 previewPositions
[POWNER
].pos
.x
- 1,
798 previewPositions
[POWNER
].pos
.y
- 1,
799 previewPositions
[POWNER
].size
.width
, previewPositions
[POWNER
].size
.height
);
800 colorUpdate
|= OTITLE_COL
;
802 if (elements
& (1 << PRESIZEBAR
)) {
803 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
805 if (elements
& (1 << PMTITLE
)) {
806 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
807 colorUpdate
|= MTITLE_COL
;
809 if (elements
& (1 << PMITEM
)) {
811 TextureListItem
*titem
;
813 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
814 titem
= (TextureListItem
*) item
->clientData
;
816 pix
= renderMenu(panel
, titem
->prop
,
817 previewPositions
[PMITEM
].size
.width
, previewPositions
[PMITEM
].size
.height
/ 4);
819 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
820 previewPositions
[PMITEM
].size
.width
,
821 previewPositions
[PMITEM
].size
.height
,
822 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
824 XCopyArea(dpy
, pix
, panel
->previewNoText
, gc
, 0, 0,
825 previewPositions
[PMITEM
].size
.width
,
826 previewPositions
[PMITEM
].size
.height
,
827 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
829 XFreePixmap(dpy
, pix
);
831 colorUpdate
|= MITEM_COL
| MDISAB_COL
| MHIGH_COL
| MHIGHT_COL
;
833 if (elements
& (1 << PMITEM
| 1 << PMTITLE
)) {
834 XDrawLine(dpy
, panel
->preview
, gc
, 29, 120, 29, 120 + 20 * 4 + 20);
835 XDrawLine(dpy
, panel
->preview
, gc
, 29, 119, 119, 119);
837 XDrawLine(dpy
, panel
->previewNoText
, gc
, 29, 120, 29, 120 + 20 * 4 + 20);
838 XDrawLine(dpy
, panel
->previewNoText
, gc
, 29, 119, 119, 119);
840 if (elements
& (1 << PICON
)) {
842 TextureListItem
*titem
;
844 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
845 titem
= (TextureListItem
*) item
->clientData
;
847 renderPreview(panel
, gc
, PICON
, titem
->ispixmap
? 0 : RBEV_RAISED3
);
849 colorUpdate
|= ICONT_COL
| ICONB_COL
| CLIP_COL
| CCLIP_COL
;
853 updateColorPreviewBox(panel
, colorUpdate
);
855 WMRedisplayWidget(panel
->prevL
);
858 WMReleaseColor(black
);
861 static void cancelNewTexture(void *data
)
863 _Panel
*panel
= (_Panel
*) data
;
865 HideTexturePanel(panel
->texturePanel
);
868 static char *makeFileName(char *prefix
)
872 fname
= wstrdup(prefix
);
874 while (access(fname
, F_OK
) == 0) {
878 sprintf(buf
, "%08lx.cache", time(NULL
));
879 fname
= wstrconcat(prefix
, buf
);
885 static void okNewTexture(void *data
)
887 _Panel
*panel
= (_Panel
*) data
;
892 TextureListItem
*titem
;
893 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
895 titem
= wmalloc(sizeof(TextureListItem
));
896 memset(titem
, 0, sizeof(TextureListItem
));
898 HideTexturePanel(panel
->texturePanel
);
900 name
= GetTexturePanelTextureName(panel
->texturePanel
);
902 prop
= GetTexturePanelTexture(panel
->texturePanel
);
904 str
= WMGetPropListDescription(prop
, False
);
908 titem
->texture
= str
;
909 titem
->selectedFor
= 0;
911 titem
->ispixmap
= isPixmap(prop
);
913 titem
->path
= makeFileName(panel
->fprefix
);
914 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
916 item
= WMAddListItem(panel
->texLs
, "");
917 item
->clientData
= titem
;
919 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
922 static void okEditTexture(void *data
)
924 _Panel
*panel
= (_Panel
*) data
;
929 TextureListItem
*titem
;
931 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
932 titem
= (TextureListItem
*) item
->clientData
;
934 HideTexturePanel(panel
->texturePanel
);
936 if (titem
->current
) {
937 name
= GetTexturePanelTextureName(panel
->texturePanel
);
943 prop
= GetTexturePanelTexture(panel
->texturePanel
);
945 str
= WMGetPropListDescription(prop
, False
);
947 WMReleasePropList(titem
->prop
);
950 titem
->ispixmap
= isPixmap(prop
);
952 wfree(titem
->texture
);
953 titem
->texture
= str
;
955 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
956 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
957 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
959 WMRedisplayWidget(panel
->texLs
);
961 if (titem
->selectedFor
)
962 updatePreviewBox(panel
, titem
->selectedFor
);
964 changePage(panel
->secP
, panel
);
967 static void editTexture(WMWidget
* w
, void *data
)
969 _Panel
*panel
= (_Panel
*) data
;
971 TextureListItem
*titem
;
973 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
974 titem
= (TextureListItem
*) item
->clientData
;
976 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
978 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
980 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
981 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
983 ShowTexturePanel(panel
->texturePanel
);
986 static void newTexture(WMWidget
* w
, void *data
)
988 _Panel
*panel
= (_Panel
*) data
;
990 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
992 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
994 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
996 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
998 ShowTexturePanel(panel
->texturePanel
);
1001 static void deleteTexture(WMWidget
* w
, void *data
)
1003 _Panel
*panel
= (_Panel
*) data
;
1005 TextureListItem
*titem
;
1009 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1010 row
= WMGetListSelectedItemRow(panel
->texLs
);
1011 item
= WMGetListItem(panel
->texLs
, row
);
1012 titem
= (TextureListItem
*) item
->clientData
;
1014 if (titem
->selectedFor
& (1 << section
)) {
1015 TextureListItem
*titem2
;
1017 panel
->textureIndex
[section
] = section
;
1018 item
= WMGetListItem(panel
->texLs
, section
);
1019 titem2
= (TextureListItem
*) item
->clientData
;
1020 titem2
->selectedFor
|= 1 << section
;
1023 wfree(titem
->title
);
1024 wfree(titem
->texture
);
1025 WMReleasePropList(titem
->prop
);
1027 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1028 werror("could not remove file %s", titem
->path
);
1035 WMRemoveListItem(panel
->texLs
, row
);
1036 WMSetButtonEnabled(panel
->delB
, False
);
1039 static void extractTexture(WMWidget
* w
, void *data
)
1041 _Panel
*panel
= (_Panel
*) data
;
1043 WMOpenPanel
*opanel
;
1044 WMScreen
*scr
= WMWidgetScreen(w
);
1046 opanel
= WMGetOpenPanel(scr
);
1047 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1048 WMSetFilePanelCanChooseFiles(opanel
, True
);
1050 if (WMRunModalFilePanelForDirectory(opanel
, panel
->parent
, wgethomedir(), _("Select File"), NULL
)) {
1051 path
= WMGetFilePanelFileName(opanel
);
1053 OpenExtractPanelFor(panel
, path
);
1059 static void changePage(WMWidget
* w
, void *data
)
1061 _Panel
*panel
= (_Panel
*) data
;
1063 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1064 RContext
*rc
= WMScreenRContext(scr
);
1065 static WMPoint positions
[] = {
1076 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1078 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1080 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1085 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1086 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1087 positions
[panel
->oldsection
].x
, positions
[panel
->oldsection
].y
, 22, 22);
1088 WMReleaseColor(color
);
1091 panel
->oldsection
= section
;
1092 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1094 WMRedisplayWidget(panel
->prevL
);
1097 static void previewClick(XEvent
* event
, void *clientData
)
1099 _Panel
*panel
= (_Panel
*) clientData
;
1102 switch (panel
->oldTabItem
) {
1104 for (i
= 0; i
< sizeof(previewPositions
) / sizeof(WMRect
); i
++) {
1105 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
1106 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
1107 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
1108 + previewPositions
[i
].size
.width
1109 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
+ previewPositions
[i
].size
.height
) {
1111 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1112 changePage(panel
->secP
, panel
);
1118 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1119 if (event
->xbutton
.x
>= previewColorPositions
[i
].pos
.x
1120 && event
->xbutton
.y
>= previewColorPositions
[i
].pos
.y
1121 && event
->xbutton
.x
< previewColorPositions
[i
].pos
.x
1122 + previewColorPositions
[i
].size
.width
1123 && event
->xbutton
.y
< previewColorPositions
[i
].pos
.y
1124 + previewColorPositions
[i
].size
.height
) {
1130 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1131 changeColorPage(panel
->colP
, panel
);
1139 static void textureClick(WMWidget
* w
, void *data
)
1141 _Panel
*panel
= (_Panel
*) data
;
1144 TextureListItem
*titem
;
1146 i
= WMGetListSelectedItemRow(panel
->texLs
);
1148 item
= WMGetListItem(panel
->texLs
, i
);
1150 titem
= (TextureListItem
*) item
->clientData
;
1152 if (titem
->current
) {
1153 WMSetButtonEnabled(panel
->delB
, False
);
1155 WMSetButtonEnabled(panel
->delB
, True
);
1159 static void textureDoubleClick(WMWidget
* w
, void *data
)
1161 _Panel
*panel
= (_Panel
*) data
;
1164 TextureListItem
*titem
;
1166 /* unselect old texture */
1167 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1169 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1170 titem
= (TextureListItem
*) item
->clientData
;
1171 titem
->selectedFor
&= ~(1 << section
);
1173 /* select new texture */
1174 i
= WMGetListSelectedItemRow(panel
->texLs
);
1176 item
= WMGetListItem(panel
->texLs
, i
);
1178 titem
= (TextureListItem
*) item
->clientData
;
1180 titem
->selectedFor
|= 1 << section
;
1182 panel
->textureIndex
[section
] = i
;
1184 WMRedisplayWidget(panel
->texLs
);
1186 updatePreviewBox(panel
, 1 << section
);
1189 static void paintListItem(WMList
* lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
* rect
)
1191 _Panel
*panel
= (_Panel
*) WMGetHangedData(lPtr
);
1192 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1193 int width
, height
, x
, y
;
1194 Display
*dpy
= WMScreenDisplay(scr
);
1195 WMColor
*back
= (state
& WLDSSelected
) ? WMWhiteColor(scr
) : WMGrayColor(scr
);
1197 WMColor
*black
= WMBlackColor(scr
);
1198 TextureListItem
*titem
;
1200 item
= WMGetListItem(lPtr
, index
);
1201 titem
= (TextureListItem
*) item
->clientData
;
1203 WMReleaseColor(back
);
1204 WMReleaseColor(black
);
1208 width
= rect
->size
.width
;
1209 height
= rect
->size
.height
;
1213 XFillRectangle(dpy
, d
, WMColorGC(back
), x
, y
, width
, height
);
1216 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0,
1217 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1219 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1220 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1221 else if (titem
->selectedFor
)
1222 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1224 WMDrawString(scr
, d
, black
, panel
->boldFont
,
1225 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
, strlen(titem
->title
));
1227 WMDrawString(scr
, d
, black
, panel
->smallFont
,
1228 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
, strlen(titem
->texture
));
1230 WMReleaseColor(back
);
1231 WMReleaseColor(black
);
1234 static Pixmap
loadRImage(WMScreen
* scr
, char *path
)
1241 f
= fopen(path
, "rb");
1245 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1247 image
= RCreateImage(w
, h
, d
== 4);
1248 fread(image
->data
, 1, w
* h
* d
, f
);
1251 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1252 RReleaseImage(image
);
1257 static void fillTextureList(WMList
* lPtr
)
1259 WMPropList
*textureList
;
1260 WMPropList
*texture
;
1261 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1262 TextureListItem
*titem
;
1263 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1266 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1270 for (i
= 0; i
< WMGetPropListItemCount(textureList
); i
++) {
1273 texture
= WMGetFromPLArray(textureList
, i
);
1275 titem
= wmalloc(sizeof(TextureListItem
));
1276 memset(titem
, 0, sizeof(TextureListItem
));
1278 titem
->title
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 0)));
1279 titem
->prop
= WMRetainPropList(WMGetFromPLArray(texture
, 1));
1280 titem
->texture
= WMGetPropListDescription(titem
->prop
, False
);
1281 titem
->selectedFor
= 0;
1282 titem
->path
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
1284 titem
->preview
= loadRImage(scr
, titem
->path
);
1285 if (!titem
->preview
) {
1286 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1288 item
= WMAddListItem(lPtr
, "");
1289 item
->clientData
= titem
;
1293 static void fillColorList(_Panel
* panel
)
1297 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1298 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1301 list
= WMGetUDObjectForKey(udb
, "ColorList");
1303 for (i
= 0; i
< 24; i
++) {
1304 color
= WMCreateNamedColor(scr
, sampleColors
[i
], False
);
1307 WMSetColorWellColor(panel
->sampW
[i
], color
);
1308 WMReleaseColor(color
);
1313 for (i
= 0; i
< WMIN(24, WMGetPropListItemCount(list
)); i
++) {
1314 c
= WMGetFromPLArray(list
, i
);
1315 if (!c
|| !WMIsPLString(c
))
1317 color
= WMCreateNamedColor(scr
, WMGetFromPLString(c
), False
);
1320 WMSetColorWellColor(panel
->sampW
[i
], color
);
1321 WMReleaseColor(color
);
1326 /*************************************************************************/
1328 static void changeColorPage(WMWidget
* w
, void *data
)
1330 _Panel
*panel
= (_Panel
*) data
;
1332 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1333 RContext
*rc
= WMScreenRContext(scr
);
1334 static WMPoint positions
[] = {
1349 if (panel
->preview
) {
1352 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1353 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1354 positions
[panel
->oldcsection
].x
, positions
[panel
->oldcsection
].y
, 22, 22);
1355 WMReleaseColor(color
);
1358 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1360 panel
->oldcsection
= section
;
1362 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1364 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1366 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1368 WMRedisplayWidget(panel
->prevL
);
1372 paintText(WMScreen
* scr
, Drawable d
, WMColor
* color
, WMFont
* font
,
1373 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1375 int l
= strlen(text
);
1382 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1386 x
+= (w
- WMWidthOfString(font
, text
, l
)) / 2;
1389 WMDrawString(scr
, d
, color
, font
, x
, y
+ (h
- WMFontHeight(font
)) / 2, text
, l
);
1392 static void updateColorPreviewBox(_Panel
* panel
, int elements
)
1394 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1395 Display
*dpy
= WMScreenDisplay(scr
);
1400 pnot
= panel
->previewNoText
;
1401 gc
= WMColorGC(panel
->colors
[0]);
1403 if (elements
& FTITLE_COL
) {
1404 XCopyArea(dpy
, pnot
, d
, gc
, 30, 10, 190, 20, 30, 10);
1405 paintText(scr
, d
, panel
->colors
[0], panel
->boldFont
, 30, 10, 190, 20,
1406 panel
->titleAlignment
, _("Focused Window"));
1408 if (elements
& UTITLE_COL
) {
1409 XCopyArea(dpy
, pnot
, d
, gc
, 30, 40, 190, 20, 30, 40);
1410 paintText(scr
, d
, panel
->colors
[1], panel
->boldFont
, 30, 40, 190, 20,
1411 panel
->titleAlignment
, _("Unfocused Window"));
1413 if (elements
& OTITLE_COL
) {
1414 XCopyArea(dpy
, pnot
, d
, gc
, 30, 70, 190, 20, 30, 70);
1415 paintText(scr
, d
, panel
->colors
[2], panel
->boldFont
, 30, 70, 190, 20,
1416 panel
->titleAlignment
, _("Owner of Focused Window"));
1418 if (elements
& MTITLE_COL
) {
1419 XCopyArea(dpy
, pnot
, d
, gc
, 30, 120, 90, 20, 30, 120);
1420 paintText(scr
, d
, panel
->colors
[3], panel
->boldFont
, 30, 120, 90, 20, WALeft
, _("Menu Title"));
1422 if (elements
& MITEM_COL
) {
1423 XCopyArea(dpy
, pnot
, d
, gc
, 30, 140, 90, 20, 30, 140);
1424 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 140, 90, 20, WALeft
, _("Normal Item"));
1425 XCopyArea(dpy
, pnot
, d
, gc
, 30, 200, 90, 20, 30, 200);
1426 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 200, 90, 20, WALeft
, _("Normal Item"));
1428 if (elements
& MDISAB_COL
) {
1429 XCopyArea(dpy
, pnot
, d
, gc
, 30, 160, 90, 20, 30, 160);
1430 paintText(scr
, d
, panel
->colors
[5], panel
->normalFont
, 30, 160, 90, 20,
1431 WALeft
, _("Disabled Item"));
1433 if (elements
& MHIGH_COL
) {
1434 XFillRectangle(WMScreenDisplay(scr
), d
, WMColorGC(panel
->colors
[6]), 31, 181, 87, 17);
1435 XFillRectangle(WMScreenDisplay(scr
), pnot
, WMColorGC(panel
->colors
[6]), 31, 181, 87, 17);
1436 elements
|= MHIGHT_COL
;
1438 if (elements
& MHIGHT_COL
) {
1439 XCopyArea(dpy
, pnot
, d
, gc
, 30, 180, 90, 20, 30, 180);
1440 paintText(scr
, d
, panel
->colors
[7], panel
->normalFont
, 30, 180, 90, 20, WALeft
, _("Highlighted"));
1443 if (elements & ICONT_COL) {
1444 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1447 if (elements & ICONB_COL) {
1448 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1451 if (elements & CLIP_COL) {
1452 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1455 if (elements & CCLIP_COL) {
1456 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1460 WMRedisplayWidget(panel
->prevL
);
1463 static void colorWellObserver(void *self
, WMNotification
* n
)
1465 _Panel
*panel
= (_Panel
*) self
;
1468 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1470 WMReleaseColor(panel
->colors
[p
]);
1472 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1474 updateColorPreviewBox(panel
, 1 << p
);
1477 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
)
1479 _Panel
*panel
= self
->data
;
1482 i
= WMGetTabViewItemIdentifier(item
);
1485 switch (panel
->oldTabItem
) {
1487 changeColorPage(NULL
, panel
);
1490 changePage(panel
->secP
, panel
);
1493 switch (panel
->oldTabItem
) {
1495 changePage(NULL
, panel
);
1498 changeColorPage(panel
->colP
, panel
);
1501 switch (panel
->oldTabItem
) {
1503 changePage(NULL
, panel
);
1506 changeColorPage(NULL
, panel
);
1512 panel
->oldTabItem
= i
;
1515 /*************************************************************************/
1517 static void menuStyleCallback(WMWidget
* self
, void *data
)
1519 _Panel
*panel
= (_Panel
*) data
;
1521 if (self
== panel
->mstyB
[0]) {
1522 panel
->menuStyle
= MSTYLE_NORMAL
;
1523 updatePreviewBox(panel
, 1 << PMITEM
);
1525 } else if (self
== panel
->mstyB
[1]) {
1526 panel
->menuStyle
= MSTYLE_SINGLE
;
1527 updatePreviewBox(panel
, 1 << PMITEM
);
1529 } else if (self
== panel
->mstyB
[2]) {
1530 panel
->menuStyle
= MSTYLE_FLAT
;
1531 updatePreviewBox(panel
, 1 << PMITEM
);
1535 static void titleAlignCallback(WMWidget
* self
, void *data
)
1537 _Panel
*panel
= (_Panel
*) data
;
1539 if (self
== panel
->taliB
[0]) {
1540 panel
->titleAlignment
= WALeft
;
1541 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1543 } else if (self
== panel
->taliB
[1]) {
1544 panel
->titleAlignment
= WACenter
;
1545 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1547 } else if (self
== panel
->taliB
[2]) {
1548 panel
->titleAlignment
= WARight
;
1549 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1553 static void createPanel(Panel
* p
)
1555 _Panel
*panel
= (_Panel
*) p
;
1557 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1558 WMTabViewItem
*item
;
1563 panel
->fprefix
= wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1565 if (access(panel
->fprefix
, F_OK
) != 0) {
1566 if (mkdir(panel
->fprefix
, 0755) < 0) {
1567 werror("%s", panel
->fprefix
);
1572 tmp
= wstrconcat(panel
->fprefix
, "/WPrefs/");
1573 wfree(panel
->fprefix
);
1574 panel
->fprefix
= tmp
;
1575 if (access(panel
->fprefix
, F_OK
) != 0) {
1576 if (mkdir(panel
->fprefix
, 0755) < 0) {
1577 werror("%s", panel
->fprefix
);
1582 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1583 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1584 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1586 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1587 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1588 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1590 panel
->box
= WMCreateBox(panel
->parent
);
1591 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
1594 panel
->prevL
= WMCreateLabel(panel
->box
);
1595 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1596 WMMoveWidget(panel
->prevL
, 15, 10);
1597 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1598 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1600 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
, previewClick
, panel
);
1604 tabviewDelegate
.data
= panel
;
1606 panel
->tabv
= WMCreateTabView(panel
->box
);
1607 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1608 WMMoveWidget(panel
->tabv
, 265, 10);
1609 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1611 /*** texture list ***/
1613 panel
->texF
= WMCreateFrame(panel
->box
);
1614 WMSetFrameRelief(panel
->texF
, WRFlat
);
1616 item
= WMCreateTabViewItemWithIdentifier(0);
1617 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1618 WMSetTabViewItemLabel(item
, _("Texture"));
1620 WMAddItemInTabView(panel
->tabv
, item
);
1622 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1623 WMResizeWidget(panel
->secP
, 228, 20);
1624 WMMoveWidget(panel
->secP
, 7, 7);
1625 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1626 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1627 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1628 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1629 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1630 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1631 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1632 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1634 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1635 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1637 panel
->texLs
= WMCreateList(panel
->texF
);
1638 WMResizeWidget(panel
->texLs
, 165, 155);
1639 WMMoveWidget(panel
->texLs
, 70, 33);
1640 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1641 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1642 WMHangData(panel
->texLs
, panel
);
1643 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1644 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1646 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1647 "for the selected item."), WMWidgetView(panel
->texLs
));
1649 /* command buttons */
1651 font
= WMSystemFontOfSize(scr
, 10);
1653 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1654 WMResizeWidget(panel
->newB
, 57, 39);
1655 WMMoveWidget(panel
->newB
, 7, 33);
1656 WMSetButtonFont(panel
->newB
, font
);
1657 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1658 WMSetButtonText(panel
->newB
, _("New"));
1659 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1660 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
, NULL
, NULL
);
1662 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel
->newB
));
1664 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1665 WMResizeWidget(panel
->ripB
, 57, 39);
1666 WMMoveWidget(panel
->ripB
, 7, 72);
1667 WMSetButtonFont(panel
->ripB
, font
);
1668 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1669 WMSetButtonText(panel
->ripB
, _("Extract..."));
1670 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1671 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
, NULL
, NULL
);
1673 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel
->ripB
));
1675 WMSetButtonEnabled(panel
->ripB
, False
);
1677 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1678 WMResizeWidget(panel
->editB
, 57, 39);
1679 WMMoveWidget(panel
->editB
, 7, 111);
1680 WMSetButtonFont(panel
->editB
, font
);
1681 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1682 WMSetButtonText(panel
->editB
, _("Edit"));
1683 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
, NULL
, NULL
);
1684 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1685 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel
->editB
));
1687 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1688 WMResizeWidget(panel
->delB
, 57, 38);
1689 WMMoveWidget(panel
->delB
, 7, 150);
1690 WMSetButtonFont(panel
->delB
, font
);
1691 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1692 WMSetButtonText(panel
->delB
, _("Delete"));
1693 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
, NULL
, NULL
);
1694 WMSetButtonEnabled(panel
->delB
, False
);
1695 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1696 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel
->delB
));
1698 WMReleaseFont(font
);
1700 WMMapSubwidgets(panel
->texF
);
1703 panel
->colF
= WMCreateFrame(panel
->box
);
1704 WMSetFrameRelief(panel
->colF
, WRFlat
);
1706 item
= WMCreateTabViewItemWithIdentifier(1);
1707 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1708 WMSetTabViewItemLabel(item
, _("Color"));
1710 WMAddItemInTabView(panel
->tabv
, item
);
1712 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1713 WMResizeWidget(panel
->colP
, 228, 20);
1714 WMMoveWidget(panel
->colP
, 7, 7);
1715 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Title"));
1716 WMAddPopUpButtonItem(panel
->colP
, _("Unfocused Window Title"));
1717 WMAddPopUpButtonItem(panel
->colP
, _("Owner of Focused Window Title"));
1718 WMAddPopUpButtonItem(panel
->colP
, _("Menu Title"));
1719 WMAddPopUpButtonItem(panel
->colP
, _("Menu Item Text"));
1720 WMAddPopUpButtonItem(panel
->colP
, _("Disabled Menu Item Text"));
1721 WMAddPopUpButtonItem(panel
->colP
, _("Menu Highlight Color"));
1722 WMAddPopUpButtonItem(panel
->colP
, _("Highlighted Menu Text Color"));
1724 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1725 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1726 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1727 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1730 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1732 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1734 panel
->colW
= WMCreateColorWell(panel
->colF
);
1735 WMResizeWidget(panel
->colW
, 65, 50);
1736 WMMoveWidget(panel
->colW
, 30, 75);
1737 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->colW
);
1739 for (i
= 0; i
< 4; i
++) {
1741 for (j
= 0; j
< 6; j
++) {
1742 panel
->sampW
[i
+ j
* 4] = WMCreateColorWell(panel
->colF
);
1743 WMResizeWidget(panel
->sampW
[i
+ j
* 4], 22, 22);
1744 WMMoveWidget(panel
->sampW
[i
+ j
* 4], 130 + i
* 22, 40 + j
* 22);
1745 WSetColorWellBordered(panel
->sampW
[i
+ j
* 4], False
);
1749 WMMapSubwidgets(panel
->colF
);
1754 panel
->bgF
= WMCreateFrame(panel
->box
);
1755 WMSetFrameRelief(panel
->bgF
, WRFlat
);
1757 item
= WMCreateTabViewItemWithIdentifier(2);
1758 WMSetTabViewItemView(item
, WMWidgetView(panel
->bgF
));
1759 WMSetTabViewItemLabel(item
, _("Background"));
1761 WMAddItemInTabView(panel
->tabv
, item
);
1763 panel
->bgprevL
= WMCreateLabel(panel
->bgF
);
1764 WMResizeWidget(panel
->bgprevL
, 230, 155);
1765 WMMoveWidget(panel
->bgprevL
, 5, 5);
1766 WMSetLabelRelief(panel
->bgprevL
, WRSunken
);
1768 panel
->selbgB
= WMCreateCommandButton(panel
->bgF
);
1769 WMMoveWidget(panel
->selbgB
, 5, 165);
1770 WMResizeWidget(panel
->selbgB
, 100, 24);
1771 WMSetButtonText(panel
->selbgB
, _("Browse..."));
1773 WMMapSubwidgets(panel
->bgF
);
1774 #endif /* unfinished */
1776 panel
->optF
= WMCreateFrame(panel
->box
);
1777 WMSetFrameRelief(panel
->optF
, WRFlat
);
1779 item
= WMCreateTabViewItemWithIdentifier(3);
1780 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1781 WMSetTabViewItemLabel(item
, _("Options"));
1783 WMAddItemInTabView(panel
->tabv
, item
);
1785 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1786 WMResizeWidget(panel
->mstyF
, 215, 85);
1787 WMMoveWidget(panel
->mstyF
, 15, 10);
1788 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1790 for (i
= 0; i
< 3; i
++) {
1794 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1795 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1796 WMMoveWidget(panel
->mstyB
[i
], 15 + i
* 65, 20);
1797 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1798 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1801 path
= LocateImage(MSTYLE1_FILE
);
1804 path
= LocateImage(MSTYLE2_FILE
);
1807 path
= LocateImage(MSTYLE3_FILE
);
1811 icon
= WMCreatePixmapFromFile(scr
, path
);
1813 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1814 WMReleasePixmap(icon
);
1816 wwarning(_("could not load icon file %s"), path
);
1821 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1822 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1824 WMMapSubwidgets(panel
->mstyF
);
1826 panel
->taliF
= WMCreateFrame(panel
->optF
);
1827 WMResizeWidget(panel
->taliF
, 110, 80);
1828 WMMoveWidget(panel
->taliF
, 15, 100);
1829 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
1831 for (i
= 0; i
< 3; i
++) {
1832 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
1833 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
1836 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1839 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1842 WMSetButtonText(panel
->taliB
[i
], _("Right"));
1845 WMResizeWidget(panel
->taliB
[i
], 90, 18);
1846 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20 * i
);
1848 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
1849 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
1851 WMMapSubwidgets(panel
->taliF
);
1853 WMMapSubwidgets(panel
->optF
);
1855 /**/ WMRealizeWidget(panel
->box
);
1856 WMMapSubwidgets(panel
->box
);
1858 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1862 changePage(panel
->secP
, panel
);
1864 fillTextureList(panel
->texLs
);
1866 fillColorList(panel
);
1868 panel
->texturePanel
= CreateTexturePanel(panel
->parent
);
1871 static void setupTextureFor(WMList
* list
, char *key
, char *defValue
, char *title
, int index
)
1874 TextureListItem
*titem
;
1876 titem
= wmalloc(sizeof(TextureListItem
));
1877 memset(titem
, 0, sizeof(TextureListItem
));
1879 titem
->title
= wstrdup(title
);
1880 titem
->prop
= GetObjectForKey(key
);
1881 if (!titem
->prop
|| !WMIsPLArray(titem
->prop
)) {
1882 /* Maybe also give a error message to stderr that the entry is bad? */
1883 titem
->prop
= WMCreatePropListFromDescription(defValue
);
1885 WMRetainPropList(titem
->prop
);
1887 titem
->texture
= WMGetPropListDescription((WMPropList
*) titem
->prop
, False
);
1889 titem
->selectedFor
= 1 << index
;
1891 titem
->ispixmap
= isPixmap(titem
->prop
);
1893 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1895 item
= WMAddListItem(list
, "");
1896 item
->clientData
= titem
;
1899 static void showData(_Panel
* panel
)
1904 str
= GetStringForKey("MenuStyle");
1905 if (str
&& strcasecmp(str
, "flat") == 0) {
1906 panel
->menuStyle
= MSTYLE_FLAT
;
1907 } else if (str
&& strcasecmp(str
, "singletexture") == 0) {
1908 panel
->menuStyle
= MSTYLE_SINGLE
;
1910 panel
->menuStyle
= MSTYLE_NORMAL
;
1913 str
= GetStringForKey("TitleJustify");
1914 if (str
&& strcasecmp(str
, "left") == 0) {
1915 panel
->titleAlignment
= WALeft
;
1916 } else if (str
&& strcasecmp(str
, "right") == 0) {
1917 panel
->titleAlignment
= WARight
;
1919 panel
->titleAlignment
= WACenter
;
1922 for (i
= 0; i
< sizeof(colorOptions
) / (2 * sizeof(char *)); i
++) {
1925 str
= GetStringForKey(colorOptions
[i
* 2]);
1927 str
= colorOptions
[i
* 2 + 1];
1929 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), str
, False
))) {
1930 color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), "#000000", False
);
1933 panel
->colors
[i
] = color
;
1935 changeColorPage(panel
->colP
, panel
);
1937 for (i
= 0; i
< sizeof(textureOptions
) / (3 * sizeof(char *)); i
++) {
1938 setupTextureFor(panel
->texLs
, textureOptions
[i
* 3],
1939 textureOptions
[i
* 3 + 1], textureOptions
[i
* 3 + 2], i
);
1940 panel
->textureIndex
[i
] = i
;
1942 updatePreviewBox(panel
, EVERYTHING
);
1944 WMSetButtonSelected(panel
->mstyB
[panel
->menuStyle
], True
);
1945 WMSetButtonSelected(panel
->taliB
[panel
->titleAlignment
], True
);
1948 static void storeData(_Panel
* panel
)
1950 TextureListItem
*titem
;
1954 for (i
= 0; i
< sizeof(textureOptions
) / (sizeof(char *) * 3); i
++) {
1955 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
1956 titem
= (TextureListItem
*) item
->clientData
;
1957 SetObjectForKey(titem
->prop
, textureOptions
[i
* 3]);
1960 for (i
= 0; i
< 8; i
++) {
1963 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
1966 SetStringForKey(str
, colorOptions
[i
* 2]);
1971 switch (panel
->menuStyle
) {
1973 SetStringForKey("singletexture", "MenuStyle");
1976 SetStringForKey("flat", "MenuStyle");
1980 SetStringForKey("normal", "MenuStyle");
1983 switch (panel
->titleAlignment
) {
1985 SetStringForKey("left", "TitleJustify");
1988 SetStringForKey("right", "TitleJustify");
1992 SetStringForKey("center", "TitleJustify");
1997 static void prepareForClose(_Panel
* panel
)
1999 WMPropList
*textureList
;
2000 WMPropList
*texture
;
2001 TextureListItem
*titem
;
2003 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2006 textureList
= WMCreatePLArray(NULL
, NULL
);
2008 /* store list of textures */
2009 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2010 item
= WMGetListItem(panel
->texLs
, i
);
2011 titem
= (TextureListItem
*) item
->clientData
;
2013 texture
= WMCreatePLArray(WMCreatePLString(titem
->title
),
2014 WMRetainPropList(titem
->prop
), WMCreatePLString(titem
->path
), NULL
);
2016 WMAddToPLArray(textureList
, texture
);
2019 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2020 WMReleasePropList(textureList
);
2022 /* store list of colors */
2023 textureList
= WMCreatePLArray(NULL
, NULL
);
2024 for (i
= 0; i
< 24; i
++) {
2028 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2030 str
= WMGetColorRGBDescription(color
);
2031 WMAddToPLArray(textureList
, WMCreatePLString(str
));
2034 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2035 WMReleasePropList(textureList
);
2037 WMSynchronizeUserDefaults(udb
);
2040 Panel
*InitAppearance(WMScreen
* scr
, WMWindow
* win
)
2044 panel
= wmalloc(sizeof(_Panel
));
2045 memset(panel
, 0, sizeof(_Panel
));
2047 panel
->sectionName
= _("Appearance Preferences");
2049 panel
->description
= _("Background texture configuration for windows,\n" "menus and icons.");
2051 panel
->parent
= win
;
2053 panel
->callbacks
.createWidgets
= createPanel
;
2054 panel
->callbacks
.updateDomain
= storeData
;
2055 panel
->callbacks
.prepareForClose
= prepareForClose
;
2057 AddSection(panel
, ICON_FILE
);
2062 /****************************************************************************/
2064 typedef struct ExtractPanel
{
2074 static void OpenExtractPanelFor(_Panel
* panel
, char *path
)
2076 ExtractPanel
*epanel
;
2079 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
2081 epanel
= wmalloc(sizeof(ExtractPanel
));
2082 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->parent
, "extract",
2083 WMTitledWindowMask
| WMClosableWindowMask
);
2084 WMResizeWidget(epanel
->win
, 245, 250);
2085 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2087 epanel
->label
= WMCreateLabel(epanel
->win
);
2088 WMResizeWidget(epanel
->label
, 225, 18);
2089 WMMoveWidget(epanel
->label
, 10, 10);
2090 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2091 WMSetLabelRelief(epanel
->label
, WRSunken
);
2093 color
= WMDarkGrayColor(scr
);
2094 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2095 WMReleaseColor(color
);
2097 color
= WMWhiteColor(scr
);
2098 WMSetLabelTextColor(epanel
->label
, color
);
2099 WMReleaseColor(color
);
2101 font
= WMBoldSystemFontOfSize(scr
, 12);
2102 WMSetLabelFont(epanel
->label
, font
);
2103 WMReleaseFont(font
);
2105 WMSetLabelText(epanel
->label
, _("Textures"));
2107 epanel
->list
= WMCreateList(epanel
->win
);
2108 WMResizeWidget(epanel
->list
, 225, 165);
2109 WMMoveWidget(epanel
->list
, 10, 30);
2111 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2112 WMResizeWidget(epanel
->closeB
, 74, 24);
2113 WMMoveWidget(epanel
->closeB
, 165, 215);
2114 WMSetButtonText(epanel
->closeB
, _("Close"));
2116 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2117 WMResizeWidget(epanel
->extrB
, 74, 24);
2118 WMMoveWidget(epanel
->extrB
, 80, 215);
2119 WMSetButtonText(epanel
->extrB
, _("Extract"));
2121 WMMapSubwidgets(epanel
->win
);
2123 /* take textures from file */
2125 WMRealizeWidget(epanel
->win
);
2127 WMMapWidget(epanel
->win
);