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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30 #include <sys/types.h>
34 #include "TexturePanel.h"
36 typedef struct _Panel
{
42 CallbackRec callbacks
;
69 WMColorWell
*sampW
[24];
86 WMPopUpButton
*modeB
[3];
96 TexturePanel
*texturePanel
;
112 Pixmap previewNoText
;
130 static void updateColorPreviewBox(_Panel
* panel
, int elements
);
132 static void showData(_Panel
* panel
);
134 static void changePage(WMWidget
* w
, void *data
);
136 static void changeColorPage(WMWidget
* w
, void *data
);
138 static void OpenExtractPanelFor(_Panel
* panel
, char *path
);
140 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
);
142 static WMTabViewDelegate tabviewDelegate
= {
144 NULL
, /* didChangeNumberOfItems */
145 changedTabItem
, /* didSelectItem */
146 NULL
, /* shouldSelectItem */
147 NULL
/* willSelectItem */
150 #define ICON_FILE "appearance"
152 #define TNEW_FILE "tnew"
153 #define TDEL_FILE "tdel"
154 #define TEDIT_FILE "tedit"
155 #define TEXTR_FILE "textr"
157 #define MSTYLE1_FILE "msty1"
158 #define MSTYLE2_FILE "msty2"
159 #define MSTYLE3_FILE "msty3"
162 static char *blueled_xpm
[] = {
192 static char *blueled2_xpm
[] = {
193 /* width height num_colors chars_per_pixel */
225 static char *hand_xpm
[] = {
249 " .%%%&@.......... ",
250 " .%*%%&#%%%%%%%%%$. ",
251 " .*#%%%%%%%%%&&&&==. ",
252 " .-%%%%%%%%%=*-;;;#$. ",
253 " .-%%%%%%%%&..>..... ",
269 static char *sampleColors
[] = {
297 static char *textureOptions
[] = {
298 "FTitleBack", "(solid, black)", "[Focused]",
299 "UTitleBack", "(solid, gray)", "[Unfocused]",
300 "PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
301 "ResizebarBack", "(solid, gray)", "[Resizebar]",
302 "MenuTitleBack", "(solid, black)", "[Menu Title]",
303 "MenuTextBack", "(solid, gray)", "[Menu Item]",
304 "IconBack", "(solid, gray)", "[Icon]"
307 #define RESIZEBAR_BEVEL -1
308 #define MENU_BEVEL -2
310 #define TEXPREV_WIDTH 40
311 #define TEXPREV_HEIGHT 24
313 #define MSTYLE_NORMAL 0
314 #define MSTYLE_SINGLE 1
315 #define MSTYLE_FLAT 2
317 #define FTITLE_COL (1<<0)
318 #define UTITLE_COL (1<<1)
319 #define OTITLE_COL (1<<2)
320 #define MTITLE_COL (1<<3)
321 #define MITEM_COL (1<<4)
322 #define MDISAB_COL (1<<5)
323 #define MHIGH_COL (1<<6)
324 #define MHIGHT_COL (1<<7)
325 #define ICONT_COL (1<<8)
326 #define ICONB_COL (1<<9)
327 #define CLIP_COL (1<<10)
328 #define CCLIP_COL (1<<11)
330 static char *colorOptions
[] = {
331 "FTitleColor", "white",
332 "UTitleColor", "black",
333 "PTitleColor", "white",
334 "MenuTitleColor", "white",
335 "MenuTextColor", "black",
336 "MenuDisabledColor", "#616161",
337 "HighlightColor", "white",
338 "HighlightTextColor", "black",
339 "IconTitleColor", "white",
340 "IconTitleBack", "black",
341 "ClipTitleColor", "black",
342 "CClipTitleColor", "#454045"
345 static WMRect previewPositions
[] = {
347 {{30, 10}, {190, 20}},
349 {{30, 40}, {190, 20}},
351 {{30, 70}, {190, 20}},
353 {{30, 100}, {190, 9}},
355 {{30, 120}, {90, 20}},
357 {{30, 140}, {90, 20 * 4}},
359 {{155, 130}, {64, 64}}
362 #define EVERYTHING 0xff
364 static WMRect previewColorPositions
[] = {
365 {{30, 10}, {190, 20}},
366 {{30, 40}, {190, 20}},
367 {{30, 70}, {190, 20}},
368 {{30, 120}, {90, 20}},
369 {{30, 140}, {90, 20}},
370 {{30, 160}, {90, 20}},
371 {{30, 180}, {90, 20}},
372 {{30, 200}, {90, 20}},
373 {{155, 130}, {64, 64}},
374 {{155, 130}, {64, 64}},
375 {{155, 130}, {64, 64}},
376 {{155, 130}, {64, 64}}
379 static void str2rcolor(RContext
* rc
, char *name
, RColor
* color
)
383 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
386 color
->red
= xcolor
.red
>> 8;
387 color
->green
= xcolor
.green
>> 8;
388 color
->blue
= xcolor
.blue
>> 8;
391 static void dumpRImage(char *path
, RImage
* image
)
394 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
396 f
= fopen(path
, "wb");
401 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
, channels
);
403 fwrite(image
->data
, 1, image
->width
* image
->height
* channels
, f
);
410 static int isPixmap(WMPropList
* prop
)
415 p
= WMGetFromPLArray(prop
, 0);
416 s
= WMGetFromPLString(p
);
417 if (strcasecmp(&s
[1], "pixmap") == 0)
423 /**********************************************************************/
425 static void drawResizebarBevel(RImage
* img
)
430 int width
= img
->width
;
431 int height
= img
->height
;
435 black
.red
= black
.green
= black
.blue
= 0;
438 light
.red
= light
.green
= light
.blue
= 80;
441 dark
.red
= dark
.green
= dark
.blue
= 40;
443 ROperateLine(img
, RSubtractOperation
, 0, 0, width
- 1, 0, &dark
);
444 ROperateLine(img
, RAddOperation
, 0, 1, width
- 1, 1, &light
);
446 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
- 1, &dark
);
447 ROperateLine(img
, RAddOperation
, cwidth
+ 1, 2, cwidth
+ 1, height
- 1, &light
);
449 ROperateLine(img
, RSubtractOperation
, width
- cwidth
- 2, 2, width
- cwidth
- 2, height
- 1, &dark
);
450 ROperateLine(img
, RAddOperation
, width
- cwidth
- 1, 2, width
- cwidth
- 1, height
- 1, &light
);
452 RDrawLine(img
, 0, height
- 1, width
- 1, height
- 1, &black
);
453 RDrawLine(img
, 0, 0, 0, height
- 1, &black
);
454 RDrawLine(img
, width
- 1, 0, width
- 1, height
- 1, &black
);
457 static void drawMenuBevel(RImage
* img
)
459 RColor light
, dark
, mid
;
461 int iheight
= img
->height
/ 4;
464 light
.red
= light
.green
= light
.blue
= 80;
467 dark
.red
= dark
.green
= dark
.blue
= 0;
470 mid
.red
= mid
.green
= mid
.blue
= 40;
472 for (i
= 1; i
< 4; i
++) {
473 ROperateLine(img
, RSubtractOperation
, 0, i
* iheight
- 2, img
->width
- 1, i
* iheight
- 2, &mid
);
475 RDrawLine(img
, 0, i
* iheight
- 1, img
->width
- 1, i
* iheight
- 1, &dark
);
477 ROperateLine(img
, RAddOperation
, 1, i
* iheight
, img
->width
- 2, i
* iheight
, &light
);
481 static Pixmap
renderTexture(WMScreen
* scr
, WMPropList
* texture
, int width
, int height
, char *path
, int border
)
484 RImage
*image
= NULL
;
486 RContext
*rc
= WMScreenRContext(scr
);
490 type
= WMGetFromPLString(WMGetFromPLArray(texture
, 0));
492 if (strcasecmp(type
, "solid") == 0) {
494 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
496 str2rcolor(rc
, str
, &rcolor
);
498 image
= RCreateImage(width
, height
, False
);
499 RClearImage(image
, &rcolor
);
500 } else if (strcasecmp(type
, "igradient") == 0) {
504 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
505 str2rcolor(rc
, str
, &c1
[0]);
506 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
507 str2rcolor(rc
, str
, &c1
[1]);
508 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
511 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
512 str2rcolor(rc
, str
, &c2
[0]);
513 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 5));
514 str2rcolor(rc
, str
, &c2
[1]);
515 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 6));
518 image
= RRenderInterwovenGradient(width
, height
, c1
, t1
, c2
, t2
);
519 } else if (strcasecmp(&type
[1], "gradient") == 0) {
523 switch (toupper(type
[0])) {
525 style
= RVerticalGradient
;
528 style
= RHorizontalGradient
;
532 style
= RDiagonalGradient
;
536 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
537 str2rcolor(rc
, str
, &rcolor
);
538 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
539 str2rcolor(rc
, str
, &rcolor2
);
541 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
542 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'T') {
546 RImage
*grad
, *timage
;
549 switch (toupper(type
[1])) {
551 style
= RVerticalGradient
;
554 style
= RHorizontalGradient
;
558 style
= RDiagonalGradient
;
562 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 3));
563 str2rcolor(rc
, str
, &rcolor
);
564 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 4));
565 str2rcolor(rc
, str
, &rcolor2
);
567 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
569 if ((path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
)) != NULL
)
570 timage
= RLoadImage(rc
, path
, 0);
572 if (!path
|| !timage
) {
573 wwarning("could not load file '%s': %s", path
, RMessageForError(RErrorCode
));
575 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
577 image
= RMakeTiledImage(timage
, width
, height
);
578 RReleaseImage(timage
);
580 i
= atoi(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
582 RCombineImagesWithOpaqueness(image
, grad
, i
);
585 } else if (strcasecmp(&type
[2], "gradient") == 0 && toupper(type
[0]) == 'M') {
590 switch (toupper(type
[1])) {
592 style
= RVerticalGradient
;
595 style
= RHorizontalGradient
;
599 style
= RDiagonalGradient
;
603 j
= WMGetPropListItemCount(texture
);
606 colors
= wmalloc(j
* sizeof(RColor
*));
608 for (i
= 2; i
< j
; i
++) {
609 str
= WMGetFromPLString(WMGetFromPLArray(texture
, i
));
610 colors
[i
- 2] = wmalloc(sizeof(RColor
));
611 str2rcolor(rc
, str
, colors
[i
- 2]);
613 colors
[i
- 2] = NULL
;
615 image
= RRenderMultiGradient(width
, height
, colors
, style
);
617 for (i
= 0; colors
[i
] != NULL
; i
++)
621 } else if (strcasecmp(&type
[1], "pixmap") == 0) {
622 RImage
*timage
= NULL
;
626 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 1));
628 if ((path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
)) != NULL
)
629 timage
= RLoadImage(rc
, path
, 0);
631 if (!path
|| !timage
) {
632 wwarning("could not load file '%s': %s", path
? path
: str
, RMessageForError(RErrorCode
));
634 str
= WMGetFromPLString(WMGetFromPLArray(texture
, 2));
635 str2rcolor(rc
, str
, &color
);
637 switch (toupper(type
[0])) {
639 image
= RMakeTiledImage(timage
, width
, height
);
640 RReleaseImage(timage
);
644 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
645 RReleaseImage(timage
);
650 image
= RScaleImage(timage
, width
, height
);
651 RReleaseImage(timage
);
664 dumpRImage(path
, image
);
668 if (border
== RESIZEBAR_BEVEL
) {
669 drawResizebarBevel(image
);
670 } else if (border
== MENU_BEVEL
) {
671 drawMenuBevel(image
);
672 RBevelImage(image
, RBEV_RAISED2
);
675 RBevelImage(image
, border
);
678 RConvertImage(rc
, image
, &pixmap
);
679 RReleaseImage(image
);
684 static Pixmap
renderMenu(_Panel
* panel
, WMPropList
* texture
, int width
, int iheight
)
686 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
687 Display
*dpy
= WMScreenDisplay(scr
);
689 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
692 switch (panel
->menuStyle
) {
694 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
696 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
* 4, WMScreenDepth(scr
));
697 for (i
= 0; i
< 4; i
++) {
698 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
, 0, iheight
* i
);
700 XFreePixmap(dpy
, tmp
);
703 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, MENU_BEVEL
);
706 pix
= renderTexture(scr
, texture
, width
, iheight
* 4, NULL
, RBEV_RAISED2
);
714 static void renderPreview(_Panel
* panel
, GC gc
, int part
, int relief
)
717 TextureListItem
*titem
;
719 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
721 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[part
]);
722 titem
= (TextureListItem
*) item
->clientData
;
724 pix
= renderTexture(scr
, titem
->prop
,
725 previewPositions
[part
].size
.width
, previewPositions
[part
].size
.height
, NULL
, relief
);
727 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->preview
, gc
, 0, 0,
728 previewPositions
[part
].size
.width
,
729 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
731 XCopyArea(WMScreenDisplay(scr
), pix
, panel
->previewNoText
, gc
, 0, 0,
732 previewPositions
[part
].size
.width
,
733 previewPositions
[part
].size
.height
, previewPositions
[part
].pos
.x
, previewPositions
[part
].pos
.y
);
735 XFreePixmap(WMScreenDisplay(scr
), pix
);
738 static void updatePreviewBox(_Panel
* panel
, int elements
)
740 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
741 Display
*dpy
= WMScreenDisplay(scr
);
745 WMColor
*black
= WMBlackColor(scr
);
747 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->parent
), 0, NULL
);
749 if (panel
->preview
== None
) {
753 panel
->previewNoText
= XCreatePixmap(dpy
, WMWidgetXID(panel
->parent
),
754 240 - 4, 215 - 4, WMScreenDepth(scr
));
756 p
= WMCreatePixmap(scr
, 240 - 4, 215 - 4, WMScreenDepth(scr
), False
);
757 panel
->preview
= WMGetPixmapXID(p
);
758 WMSetLabelImage(panel
->prevL
, p
);
761 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
762 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
), 0, 0, 240 - 4, 215 - 4);
763 XFillRectangle(dpy
, panel
->previewNoText
, WMColorGC(color
), 0, 0, 240 - 4, 215 - 4);
764 WMReleaseColor(color
);
767 if (elements
& (1 << PFOCUSED
)) {
768 renderPreview(panel
, gc
, PFOCUSED
, RBEV_RAISED2
);
769 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
770 previewPositions
[PFOCUSED
].pos
.x
- 1,
771 previewPositions
[PFOCUSED
].pos
.y
- 1,
772 previewPositions
[PFOCUSED
].size
.width
, previewPositions
[PFOCUSED
].size
.height
);
773 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
774 previewPositions
[PFOCUSED
].pos
.x
- 1,
775 previewPositions
[PFOCUSED
].pos
.y
- 1,
776 previewPositions
[PFOCUSED
].size
.width
, previewPositions
[PFOCUSED
].size
.height
);
777 colorUpdate
|= FTITLE_COL
;
779 if (elements
& (1 << PUNFOCUSED
)) {
780 renderPreview(panel
, gc
, PUNFOCUSED
, RBEV_RAISED2
);
781 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
782 previewPositions
[PUNFOCUSED
].pos
.x
- 1,
783 previewPositions
[PUNFOCUSED
].pos
.y
- 1,
784 previewPositions
[PUNFOCUSED
].size
.width
, previewPositions
[PUNFOCUSED
].size
.height
);
785 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
786 previewPositions
[PUNFOCUSED
].pos
.x
- 1,
787 previewPositions
[PUNFOCUSED
].pos
.y
- 1,
788 previewPositions
[PUNFOCUSED
].size
.width
, previewPositions
[PUNFOCUSED
].size
.height
);
789 colorUpdate
|= UTITLE_COL
;
791 if (elements
& (1 << POWNER
)) {
792 renderPreview(panel
, gc
, POWNER
, RBEV_RAISED2
);
793 XDrawRectangle(dpy
, panel
->preview
, WMColorGC(black
),
794 previewPositions
[POWNER
].pos
.x
- 1,
795 previewPositions
[POWNER
].pos
.y
- 1,
796 previewPositions
[POWNER
].size
.width
, previewPositions
[POWNER
].size
.height
);
797 XDrawRectangle(dpy
, panel
->previewNoText
, WMColorGC(black
),
798 previewPositions
[POWNER
].pos
.x
- 1,
799 previewPositions
[POWNER
].pos
.y
- 1,
800 previewPositions
[POWNER
].size
.width
, previewPositions
[POWNER
].size
.height
);
801 colorUpdate
|= OTITLE_COL
;
803 if (elements
& (1 << PRESIZEBAR
)) {
804 renderPreview(panel
, gc
, PRESIZEBAR
, RESIZEBAR_BEVEL
);
806 if (elements
& (1 << PMTITLE
)) {
807 renderPreview(panel
, gc
, PMTITLE
, RBEV_RAISED2
);
808 colorUpdate
|= MTITLE_COL
;
810 if (elements
& (1 << PMITEM
)) {
812 TextureListItem
*titem
;
814 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
815 titem
= (TextureListItem
*) item
->clientData
;
817 pix
= renderMenu(panel
, titem
->prop
,
818 previewPositions
[PMITEM
].size
.width
, previewPositions
[PMITEM
].size
.height
/ 4);
820 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0,
821 previewPositions
[PMITEM
].size
.width
,
822 previewPositions
[PMITEM
].size
.height
,
823 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
825 XCopyArea(dpy
, pix
, panel
->previewNoText
, gc
, 0, 0,
826 previewPositions
[PMITEM
].size
.width
,
827 previewPositions
[PMITEM
].size
.height
,
828 previewPositions
[PMITEM
].pos
.x
, previewPositions
[PMITEM
].pos
.y
);
830 XFreePixmap(dpy
, pix
);
832 colorUpdate
|= MITEM_COL
| MDISAB_COL
| MHIGH_COL
| MHIGHT_COL
;
834 if (elements
& (1 << PMITEM
| 1 << PMTITLE
)) {
835 XDrawLine(dpy
, panel
->preview
, gc
, 29, 120, 29, 120 + 20 * 4 + 20);
836 XDrawLine(dpy
, panel
->preview
, gc
, 29, 119, 119, 119);
838 XDrawLine(dpy
, panel
->previewNoText
, gc
, 29, 120, 29, 120 + 20 * 4 + 20);
839 XDrawLine(dpy
, panel
->previewNoText
, gc
, 29, 119, 119, 119);
841 if (elements
& (1 << PICON
)) {
843 TextureListItem
*titem
;
845 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
846 titem
= (TextureListItem
*) item
->clientData
;
848 renderPreview(panel
, gc
, PICON
, titem
->ispixmap
? 0 : RBEV_RAISED3
);
850 colorUpdate
|= ICONT_COL
| ICONB_COL
| CLIP_COL
| CCLIP_COL
;
854 updateColorPreviewBox(panel
, colorUpdate
);
856 WMRedisplayWidget(panel
->prevL
);
859 WMReleaseColor(black
);
862 static void cancelNewTexture(void *data
)
864 _Panel
*panel
= (_Panel
*) data
;
866 HideTexturePanel(panel
->texturePanel
);
869 static char *makeFileName(char *prefix
)
873 fname
= wstrdup(prefix
);
875 while (access(fname
, F_OK
) == 0) {
879 sprintf(buf
, "%08lx.cache", time(NULL
));
880 fname
= wstrconcat(prefix
, buf
);
886 static void okNewTexture(void *data
)
888 _Panel
*panel
= (_Panel
*) data
;
893 TextureListItem
*titem
;
894 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
896 titem
= wmalloc(sizeof(TextureListItem
));
897 memset(titem
, 0, sizeof(TextureListItem
));
899 HideTexturePanel(panel
->texturePanel
);
901 name
= GetTexturePanelTextureName(panel
->texturePanel
);
903 prop
= GetTexturePanelTexture(panel
->texturePanel
);
905 str
= WMGetPropListDescription(prop
, False
);
909 titem
->texture
= str
;
910 titem
->selectedFor
= 0;
912 titem
->ispixmap
= isPixmap(prop
);
914 titem
->path
= makeFileName(panel
->fprefix
);
915 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
917 item
= WMAddListItem(panel
->texLs
, "");
918 item
->clientData
= titem
;
920 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
923 static void okEditTexture(void *data
)
925 _Panel
*panel
= (_Panel
*) data
;
930 TextureListItem
*titem
;
932 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
933 titem
= (TextureListItem
*) item
->clientData
;
935 HideTexturePanel(panel
->texturePanel
);
937 if (titem
->current
) {
938 name
= GetTexturePanelTextureName(panel
->texturePanel
);
944 prop
= GetTexturePanelTexture(panel
->texturePanel
);
946 str
= WMGetPropListDescription(prop
, False
);
948 WMReleasePropList(titem
->prop
);
951 titem
->ispixmap
= isPixmap(prop
);
953 wfree(titem
->texture
);
954 titem
->texture
= str
;
956 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
957 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
958 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, titem
->path
, 0);
960 WMRedisplayWidget(panel
->texLs
);
962 if (titem
->selectedFor
)
963 updatePreviewBox(panel
, titem
->selectedFor
);
965 changePage(panel
->secP
, panel
);
968 static void editTexture(WMWidget
* w
, void *data
)
970 _Panel
*panel
= (_Panel
*) data
;
972 TextureListItem
*titem
;
974 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
975 titem
= (TextureListItem
*) item
->clientData
;
977 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
979 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
981 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
982 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
984 ShowTexturePanel(panel
->texturePanel
);
987 static void newTexture(WMWidget
* w
, void *data
)
989 _Panel
*panel
= (_Panel
*) data
;
991 SetTexturePanelPixmapPath(panel
->texturePanel
, GetObjectForKey("PixmapPath"));
993 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
995 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
997 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
999 ShowTexturePanel(panel
->texturePanel
);
1002 static void deleteTexture(WMWidget
* w
, void *data
)
1004 _Panel
*panel
= (_Panel
*) data
;
1006 TextureListItem
*titem
;
1010 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1011 row
= WMGetListSelectedItemRow(panel
->texLs
);
1012 item
= WMGetListItem(panel
->texLs
, row
);
1013 titem
= (TextureListItem
*) item
->clientData
;
1015 if (titem
->selectedFor
& (1 << section
)) {
1016 TextureListItem
*titem2
;
1018 panel
->textureIndex
[section
] = section
;
1019 item
= WMGetListItem(panel
->texLs
, section
);
1020 titem2
= (TextureListItem
*) item
->clientData
;
1021 titem2
->selectedFor
|= 1 << section
;
1024 wfree(titem
->title
);
1025 wfree(titem
->texture
);
1026 WMReleasePropList(titem
->prop
);
1028 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
1029 wsyserror("could not remove file %s", titem
->path
);
1036 WMRemoveListItem(panel
->texLs
, row
);
1037 WMSetButtonEnabled(panel
->delB
, False
);
1040 static void extractTexture(WMWidget
* w
, void *data
)
1042 _Panel
*panel
= (_Panel
*) data
;
1044 WMOpenPanel
*opanel
;
1045 WMScreen
*scr
= WMWidgetScreen(w
);
1047 opanel
= WMGetOpenPanel(scr
);
1048 WMSetFilePanelCanChooseDirectories(opanel
, False
);
1049 WMSetFilePanelCanChooseFiles(opanel
, True
);
1051 if (WMRunModalFilePanelForDirectory(opanel
, panel
->parent
, wgethomedir(), _("Select File"), NULL
)) {
1052 path
= WMGetFilePanelFileName(opanel
);
1054 OpenExtractPanelFor(panel
, path
);
1060 static void changePage(WMWidget
* w
, void *data
)
1062 _Panel
*panel
= (_Panel
*) data
;
1065 TextureListItem
*titem
;
1066 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1067 RContext
*rc
= WMScreenRContext(scr
);
1068 static WMPoint positions
[] = {
1079 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1081 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1083 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
1085 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1087 titem
= (TextureListItem
*) item
->clientData
;
1092 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1093 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1094 positions
[panel
->oldsection
].x
, positions
[panel
->oldsection
].y
, 22, 22);
1095 WMReleaseColor(color
);
1098 panel
->oldsection
= section
;
1099 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1101 WMRedisplayWidget(panel
->prevL
);
1104 static void previewClick(XEvent
* event
, void *clientData
)
1106 _Panel
*panel
= (_Panel
*) clientData
;
1109 switch (panel
->oldTabItem
) {
1111 for (i
= 0; i
< sizeof(previewPositions
) / sizeof(WMRect
); i
++) {
1112 if (event
->xbutton
.x
>= previewPositions
[i
].pos
.x
1113 && event
->xbutton
.y
>= previewPositions
[i
].pos
.y
1114 && event
->xbutton
.x
< previewPositions
[i
].pos
.x
1115 + previewPositions
[i
].size
.width
1116 && event
->xbutton
.y
< previewPositions
[i
].pos
.y
+ previewPositions
[i
].size
.height
) {
1118 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1119 changePage(panel
->secP
, panel
);
1125 for (i
= 0; i
< WMGetPopUpButtonNumberOfItems(panel
->colP
); i
++) {
1126 if (event
->xbutton
.x
>= previewColorPositions
[i
].pos
.x
1127 && event
->xbutton
.y
>= previewColorPositions
[i
].pos
.y
1128 && event
->xbutton
.x
< previewColorPositions
[i
].pos
.x
1129 + previewColorPositions
[i
].size
.width
1130 && event
->xbutton
.y
< previewColorPositions
[i
].pos
.y
1131 + previewColorPositions
[i
].size
.height
) {
1137 WMSetPopUpButtonSelectedItem(panel
->colP
, i
);
1138 changeColorPage(panel
->colP
, panel
);
1146 static void textureClick(WMWidget
* w
, void *data
)
1148 _Panel
*panel
= (_Panel
*) data
;
1151 TextureListItem
*titem
;
1153 i
= WMGetListSelectedItemRow(panel
->texLs
);
1155 item
= WMGetListItem(panel
->texLs
, i
);
1157 titem
= (TextureListItem
*) item
->clientData
;
1159 if (titem
->current
) {
1160 WMSetButtonEnabled(panel
->delB
, False
);
1162 WMSetButtonEnabled(panel
->delB
, True
);
1166 static void textureDoubleClick(WMWidget
* w
, void *data
)
1168 _Panel
*panel
= (_Panel
*) data
;
1171 TextureListItem
*titem
;
1173 /* unselect old texture */
1174 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1176 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1177 titem
= (TextureListItem
*) item
->clientData
;
1178 titem
->selectedFor
&= ~(1 << section
);
1180 /* select new texture */
1181 i
= WMGetListSelectedItemRow(panel
->texLs
);
1183 item
= WMGetListItem(panel
->texLs
, i
);
1185 titem
= (TextureListItem
*) item
->clientData
;
1187 titem
->selectedFor
|= 1 << section
;
1189 panel
->textureIndex
[section
] = i
;
1191 WMRedisplayWidget(panel
->texLs
);
1193 updatePreviewBox(panel
, 1 << section
);
1196 static void paintListItem(WMList
* lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
* rect
)
1198 _Panel
*panel
= (_Panel
*) WMGetHangedData(lPtr
);
1199 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1200 int width
, height
, x
, y
;
1201 Display
*dpy
= WMScreenDisplay(scr
);
1202 WMColor
*back
= (state
& WLDSSelected
) ? WMWhiteColor(scr
) : WMGrayColor(scr
);
1204 WMColor
*black
= WMBlackColor(scr
);
1205 TextureListItem
*titem
;
1207 item
= WMGetListItem(lPtr
, index
);
1208 titem
= (TextureListItem
*) item
->clientData
;
1210 WMReleaseColor(back
);
1211 WMReleaseColor(black
);
1215 width
= rect
->size
.width
;
1216 height
= rect
->size
.height
;
1220 XFillRectangle(dpy
, d
, WMColorGC(back
), x
, y
, width
, height
);
1223 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0,
1224 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1226 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1227 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1228 else if (titem
->selectedFor
)
1229 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1231 WMDrawString(scr
, d
, black
, panel
->boldFont
,
1232 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
, strlen(titem
->title
));
1234 WMDrawString(scr
, d
, black
, panel
->smallFont
,
1235 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
, strlen(titem
->texture
));
1237 WMReleaseColor(back
);
1238 WMReleaseColor(black
);
1241 static Pixmap
loadRImage(WMScreen
* scr
, char *path
)
1248 f
= fopen(path
, "rb");
1252 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1254 image
= RCreateImage(w
, h
, d
== 4);
1255 fread(image
->data
, 1, w
* h
* d
, f
);
1258 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1259 RReleaseImage(image
);
1264 static void fillTextureList(WMList
* lPtr
)
1266 WMPropList
*textureList
;
1267 WMPropList
*texture
;
1268 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1269 TextureListItem
*titem
;
1270 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1273 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1277 for (i
= 0; i
< WMGetPropListItemCount(textureList
); i
++) {
1280 texture
= WMGetFromPLArray(textureList
, i
);
1282 titem
= wmalloc(sizeof(TextureListItem
));
1283 memset(titem
, 0, sizeof(TextureListItem
));
1285 titem
->title
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 0)));
1286 titem
->prop
= WMRetainPropList(WMGetFromPLArray(texture
, 1));
1287 titem
->texture
= WMGetPropListDescription(titem
->prop
, False
);
1288 titem
->selectedFor
= 0;
1289 titem
->path
= wstrdup(WMGetFromPLString(WMGetFromPLArray(texture
, 2)));
1291 titem
->preview
= loadRImage(scr
, titem
->path
);
1292 if (!titem
->preview
) {
1293 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1295 item
= WMAddListItem(lPtr
, "");
1296 item
->clientData
= titem
;
1300 static void fillColorList(_Panel
* panel
)
1304 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1305 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1308 list
= WMGetUDObjectForKey(udb
, "ColorList");
1310 for (i
= 0; i
< 24; i
++) {
1311 color
= WMCreateNamedColor(scr
, sampleColors
[i
], False
);
1314 WMSetColorWellColor(panel
->sampW
[i
], color
);
1315 WMReleaseColor(color
);
1320 for (i
= 0; i
< WMIN(24, WMGetPropListItemCount(list
)); i
++) {
1321 c
= WMGetFromPLArray(list
, i
);
1322 if (!c
|| !WMIsPLString(c
))
1324 color
= WMCreateNamedColor(scr
, WMGetFromPLString(c
), False
);
1327 WMSetColorWellColor(panel
->sampW
[i
], color
);
1328 WMReleaseColor(color
);
1333 /*************************************************************************/
1335 static void changeColorPage(WMWidget
* w
, void *data
)
1337 _Panel
*panel
= (_Panel
*) data
;
1339 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1340 RContext
*rc
= WMScreenRContext(scr
);
1341 static WMPoint positions
[] = {
1356 if (panel
->preview
) {
1359 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
1360 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
1361 positions
[panel
->oldcsection
].x
, positions
[panel
->oldcsection
].y
, 22, 22);
1362 WMReleaseColor(color
);
1365 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1367 panel
->oldcsection
= section
;
1369 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
, positions
[section
].y
);
1371 section
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1373 WMSetColorWellColor(panel
->colW
, panel
->colors
[section
]);
1375 WMRedisplayWidget(panel
->prevL
);
1379 paintText(WMScreen
* scr
, Drawable d
, WMColor
* color
, WMFont
* font
,
1380 int x
, int y
, int w
, int h
, WMAlignment align
, char *text
)
1382 int l
= strlen(text
);
1389 x
+= w
- 5 - WMWidthOfString(font
, text
, l
);
1393 x
+= (w
- WMWidthOfString(font
, text
, l
)) / 2;
1396 WMDrawString(scr
, d
, color
, font
, x
, y
+ (h
- WMFontHeight(font
)) / 2, text
, l
);
1399 static void updateColorPreviewBox(_Panel
* panel
, int elements
)
1401 WMScreen
*scr
= WMWidgetScreen(panel
->box
);
1402 Display
*dpy
= WMScreenDisplay(scr
);
1407 pnot
= panel
->previewNoText
;
1408 gc
= WMColorGC(panel
->colors
[0]);
1410 if (elements
& FTITLE_COL
) {
1411 XCopyArea(dpy
, pnot
, d
, gc
, 30, 10, 190, 20, 30, 10);
1412 paintText(scr
, d
, panel
->colors
[0], panel
->boldFont
, 30, 10, 190, 20,
1413 panel
->titleAlignment
, _("Focused Window"));
1415 if (elements
& UTITLE_COL
) {
1416 XCopyArea(dpy
, pnot
, d
, gc
, 30, 40, 190, 20, 30, 40);
1417 paintText(scr
, d
, panel
->colors
[1], panel
->boldFont
, 30, 40, 190, 20,
1418 panel
->titleAlignment
, _("Unfocused Window"));
1420 if (elements
& OTITLE_COL
) {
1421 XCopyArea(dpy
, pnot
, d
, gc
, 30, 70, 190, 20, 30, 70);
1422 paintText(scr
, d
, panel
->colors
[2], panel
->boldFont
, 30, 70, 190, 20,
1423 panel
->titleAlignment
, _("Owner of Focused Window"));
1425 if (elements
& MTITLE_COL
) {
1426 XCopyArea(dpy
, pnot
, d
, gc
, 30, 120, 90, 20, 30, 120);
1427 paintText(scr
, d
, panel
->colors
[3], panel
->boldFont
, 30, 120, 90, 20, WALeft
, _("Menu Title"));
1429 if (elements
& MITEM_COL
) {
1430 XCopyArea(dpy
, pnot
, d
, gc
, 30, 140, 90, 20, 30, 140);
1431 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 140, 90, 20, WALeft
, _("Normal Item"));
1432 XCopyArea(dpy
, pnot
, d
, gc
, 30, 200, 90, 20, 30, 200);
1433 paintText(scr
, d
, panel
->colors
[4], panel
->normalFont
, 30, 200, 90, 20, WALeft
, _("Normal Item"));
1435 if (elements
& MDISAB_COL
) {
1436 XCopyArea(dpy
, pnot
, d
, gc
, 30, 160, 90, 20, 30, 160);
1437 paintText(scr
, d
, panel
->colors
[5], panel
->normalFont
, 30, 160, 90, 20,
1438 WALeft
, _("Disabled Item"));
1440 if (elements
& MHIGH_COL
) {
1441 XFillRectangle(WMScreenDisplay(scr
), d
, WMColorGC(panel
->colors
[6]), 31, 181, 87, 17);
1442 XFillRectangle(WMScreenDisplay(scr
), pnot
, WMColorGC(panel
->colors
[6]), 31, 181, 87, 17);
1443 elements
|= MHIGHT_COL
;
1445 if (elements
& MHIGHT_COL
) {
1446 XCopyArea(dpy
, pnot
, d
, gc
, 30, 180, 90, 20, 30, 180);
1447 paintText(scr
, d
, panel
->colors
[7], panel
->normalFont
, 30, 180, 90, 20, WALeft
, _("Highlighted"));
1450 if (elements & ICONT_COL) {
1451 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1454 if (elements & ICONB_COL) {
1455 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1458 if (elements & CLIP_COL) {
1459 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1462 if (elements & CCLIP_COL) {
1463 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1467 WMRedisplayWidget(panel
->prevL
);
1470 static void colorWellObserver(void *self
, WMNotification
* n
)
1472 _Panel
*panel
= (_Panel
*) self
;
1475 p
= WMGetPopUpButtonSelectedItem(panel
->colP
);
1477 WMReleaseColor(panel
->colors
[p
]);
1479 panel
->colors
[p
] = WMRetainColor(WMGetColorWellColor(panel
->colW
));
1481 updateColorPreviewBox(panel
, 1 << p
);
1484 static void changedTabItem(struct WMTabViewDelegate
*self
, WMTabView
* tabView
, WMTabViewItem
* item
)
1486 _Panel
*panel
= self
->data
;
1489 i
= WMGetTabViewItemIdentifier(item
);
1492 switch (panel
->oldTabItem
) {
1494 changeColorPage(NULL
, panel
);
1497 changePage(panel
->secP
, panel
);
1500 switch (panel
->oldTabItem
) {
1502 changePage(NULL
, panel
);
1505 changeColorPage(panel
->colP
, panel
);
1508 switch (panel
->oldTabItem
) {
1510 changePage(NULL
, panel
);
1513 changeColorPage(NULL
, panel
);
1519 panel
->oldTabItem
= i
;
1522 /*************************************************************************/
1524 static void menuStyleCallback(WMWidget
* self
, void *data
)
1526 _Panel
*panel
= (_Panel
*) data
;
1528 if (self
== panel
->mstyB
[0]) {
1529 panel
->menuStyle
= MSTYLE_NORMAL
;
1530 updatePreviewBox(panel
, 1 << PMITEM
);
1532 } else if (self
== panel
->mstyB
[1]) {
1533 panel
->menuStyle
= MSTYLE_SINGLE
;
1534 updatePreviewBox(panel
, 1 << PMITEM
);
1536 } else if (self
== panel
->mstyB
[2]) {
1537 panel
->menuStyle
= MSTYLE_FLAT
;
1538 updatePreviewBox(panel
, 1 << PMITEM
);
1542 static void titleAlignCallback(WMWidget
* self
, void *data
)
1544 _Panel
*panel
= (_Panel
*) data
;
1546 if (self
== panel
->taliB
[0]) {
1547 panel
->titleAlignment
= WALeft
;
1548 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1550 } else if (self
== panel
->taliB
[1]) {
1551 panel
->titleAlignment
= WACenter
;
1552 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1554 } else if (self
== panel
->taliB
[2]) {
1555 panel
->titleAlignment
= WARight
;
1556 updatePreviewBox(panel
, 1 << PFOCUSED
| 1 << PUNFOCUSED
| 1 << POWNER
);
1560 static void createPanel(Panel
* p
)
1562 _Panel
*panel
= (_Panel
*) p
;
1564 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1565 WMTabViewItem
*item
;
1570 panel
->fprefix
= wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1572 if (access(panel
->fprefix
, F_OK
) != 0) {
1573 if (mkdir(panel
->fprefix
, 0755) < 0) {
1574 wsyserror(panel
->fprefix
);
1579 tmp
= wstrconcat(panel
->fprefix
, "/WPrefs/");
1580 wfree(panel
->fprefix
);
1581 panel
->fprefix
= tmp
;
1582 if (access(panel
->fprefix
, F_OK
) != 0) {
1583 if (mkdir(panel
->fprefix
, 0755) < 0) {
1584 wsyserror(panel
->fprefix
);
1589 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1590 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1591 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1593 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1594 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1595 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1597 panel
->box
= WMCreateBox(panel
->parent
);
1598 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
1601 panel
->prevL
= WMCreateLabel(panel
->box
);
1602 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1603 WMMoveWidget(panel
->prevL
, 15, 10);
1604 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1605 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1607 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
, previewClick
, panel
);
1611 tabviewDelegate
.data
= panel
;
1613 panel
->tabv
= WMCreateTabView(panel
->box
);
1614 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1615 WMMoveWidget(panel
->tabv
, 265, 10);
1616 WMSetTabViewDelegate(panel
->tabv
, &tabviewDelegate
);
1618 /*** texture list ***/
1620 panel
->texF
= WMCreateFrame(panel
->box
);
1621 WMSetFrameRelief(panel
->texF
, WRFlat
);
1623 item
= WMCreateTabViewItemWithIdentifier(0);
1624 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1625 WMSetTabViewItemLabel(item
, _("Texture"));
1627 WMAddItemInTabView(panel
->tabv
, item
);
1629 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1630 WMResizeWidget(panel
->secP
, 228, 20);
1631 WMMoveWidget(panel
->secP
, 7, 7);
1632 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1633 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1634 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1635 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1636 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1637 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1638 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1639 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1641 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1642 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1644 panel
->texLs
= WMCreateList(panel
->texF
);
1645 WMResizeWidget(panel
->texLs
, 165, 155);
1646 WMMoveWidget(panel
->texLs
, 70, 33);
1647 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1648 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1649 WMHangData(panel
->texLs
, panel
);
1650 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1651 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1653 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1654 "for the selected item."), WMWidgetView(panel
->texLs
));
1656 /* command buttons */
1658 font
= WMSystemFontOfSize(scr
, 10);
1660 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1661 WMResizeWidget(panel
->newB
, 57, 39);
1662 WMMoveWidget(panel
->newB
, 7, 33);
1663 WMSetButtonFont(panel
->newB
, font
);
1664 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1665 WMSetButtonText(panel
->newB
, _("New"));
1666 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1667 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
, NULL
, NULL
);
1669 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel
->newB
));
1671 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1672 WMResizeWidget(panel
->ripB
, 57, 39);
1673 WMMoveWidget(panel
->ripB
, 7, 72);
1674 WMSetButtonFont(panel
->ripB
, font
);
1675 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1676 WMSetButtonText(panel
->ripB
, _("Extract..."));
1677 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1678 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
, NULL
, NULL
);
1680 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel
->ripB
));
1682 WMSetButtonEnabled(panel
->ripB
, False
);
1684 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1685 WMResizeWidget(panel
->editB
, 57, 39);
1686 WMMoveWidget(panel
->editB
, 7, 111);
1687 WMSetButtonFont(panel
->editB
, font
);
1688 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1689 WMSetButtonText(panel
->editB
, _("Edit"));
1690 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
, NULL
, NULL
);
1691 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1692 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel
->editB
));
1694 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1695 WMResizeWidget(panel
->delB
, 57, 38);
1696 WMMoveWidget(panel
->delB
, 7, 150);
1697 WMSetButtonFont(panel
->delB
, font
);
1698 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1699 WMSetButtonText(panel
->delB
, _("Delete"));
1700 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
, NULL
, NULL
);
1701 WMSetButtonEnabled(panel
->delB
, False
);
1702 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1703 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel
->delB
));
1705 WMReleaseFont(font
);
1707 WMMapSubwidgets(panel
->texF
);
1710 panel
->colF
= WMCreateFrame(panel
->box
);
1711 WMSetFrameRelief(panel
->colF
, WRFlat
);
1713 item
= WMCreateTabViewItemWithIdentifier(1);
1714 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1715 WMSetTabViewItemLabel(item
, _("Color"));
1717 WMAddItemInTabView(panel
->tabv
, item
);
1719 panel
->colP
= WMCreatePopUpButton(panel
->colF
);
1720 WMResizeWidget(panel
->colP
, 228, 20);
1721 WMMoveWidget(panel
->colP
, 7, 7);
1722 WMAddPopUpButtonItem(panel
->colP
, _("Focused Window Title"));
1723 WMAddPopUpButtonItem(panel
->colP
, _("Unfocused Window Title"));
1724 WMAddPopUpButtonItem(panel
->colP
, _("Owner of Focused Window Title"));
1725 WMAddPopUpButtonItem(panel
->colP
, _("Menu Title"));
1726 WMAddPopUpButtonItem(panel
->colP
, _("Menu Item Text"));
1727 WMAddPopUpButtonItem(panel
->colP
, _("Disabled Menu Item Text"));
1728 WMAddPopUpButtonItem(panel
->colP
, _("Menu Highlight Color"));
1729 WMAddPopUpButtonItem(panel
->colP
, _("Highlighted Menu Text Color"));
1731 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1732 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1733 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1734 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1737 WMSetPopUpButtonSelectedItem(panel
->colP
, 0);
1739 WMSetPopUpButtonAction(panel
->colP
, changeColorPage
, panel
);
1741 panel
->colW
= WMCreateColorWell(panel
->colF
);
1742 WMResizeWidget(panel
->colW
, 65, 50);
1743 WMMoveWidget(panel
->colW
, 30, 75);
1744 WMAddNotificationObserver(colorWellObserver
, panel
, WMColorWellDidChangeNotification
, panel
->colW
);
1746 for (i
= 0; i
< 4; i
++) {
1748 for (j
= 0; j
< 6; j
++) {
1749 panel
->sampW
[i
+ j
* 4] = WMCreateColorWell(panel
->colF
);
1750 WMResizeWidget(panel
->sampW
[i
+ j
* 4], 22, 22);
1751 WMMoveWidget(panel
->sampW
[i
+ j
* 4], 130 + i
* 22, 40 + j
* 22);
1752 WSetColorWellBordered(panel
->sampW
[i
+ j
* 4], False
);
1756 WMMapSubwidgets(panel
->colF
);
1761 panel
->bgF
= WMCreateFrame(panel
->box
);
1762 WMSetFrameRelief(panel
->bgF
, WRFlat
);
1764 item
= WMCreateTabViewItemWithIdentifier(2);
1765 WMSetTabViewItemView(item
, WMWidgetView(panel
->bgF
));
1766 WMSetTabViewItemLabel(item
, _("Background"));
1768 WMAddItemInTabView(panel
->tabv
, item
);
1770 panel
->bgprevL
= WMCreateLabel(panel
->bgF
);
1771 WMResizeWidget(panel
->bgprevL
, 230, 155);
1772 WMMoveWidget(panel
->bgprevL
, 5, 5);
1773 WMSetLabelRelief(panel
->bgprevL
, WRSunken
);
1775 panel
->selbgB
= WMCreateCommandButton(panel
->bgF
);
1776 WMMoveWidget(panel
->selbgB
, 5, 165);
1777 WMResizeWidget(panel
->selbgB
, 100, 24);
1778 WMSetButtonText(panel
->selbgB
, _("Browse..."));
1780 WMMapSubwidgets(panel
->bgF
);
1781 #endif /* unfinished */
1783 panel
->optF
= WMCreateFrame(panel
->box
);
1784 WMSetFrameRelief(panel
->optF
, WRFlat
);
1786 item
= WMCreateTabViewItemWithIdentifier(3);
1787 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1788 WMSetTabViewItemLabel(item
, _("Options"));
1790 WMAddItemInTabView(panel
->tabv
, item
);
1792 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1793 WMResizeWidget(panel
->mstyF
, 215, 85);
1794 WMMoveWidget(panel
->mstyF
, 15, 10);
1795 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1797 for (i
= 0; i
< 3; i
++) {
1801 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1802 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1803 WMMoveWidget(panel
->mstyB
[i
], 15 + i
* 65, 20);
1804 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1805 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1808 path
= LocateImage(MSTYLE1_FILE
);
1811 path
= LocateImage(MSTYLE2_FILE
);
1814 path
= LocateImage(MSTYLE3_FILE
);
1818 icon
= WMCreatePixmapFromFile(scr
, path
);
1820 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1821 WMReleasePixmap(icon
);
1823 wwarning(_("could not load icon file %s"), path
);
1828 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1829 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1831 WMMapSubwidgets(panel
->mstyF
);
1833 panel
->taliF
= WMCreateFrame(panel
->optF
);
1834 WMResizeWidget(panel
->taliF
, 110, 80);
1835 WMMoveWidget(panel
->taliF
, 15, 100);
1836 WMSetFrameTitle(panel
->taliF
, _("Title Alignment"));
1838 for (i
= 0; i
< 3; i
++) {
1839 panel
->taliB
[i
] = WMCreateRadioButton(panel
->taliF
);
1840 WMSetButtonAction(panel
->taliB
[i
], titleAlignCallback
, panel
);
1843 WMSetButtonText(panel
->taliB
[i
], _("Left"));
1846 WMSetButtonText(panel
->taliB
[i
], _("Center"));
1849 WMSetButtonText(panel
->taliB
[i
], _("Right"));
1852 WMResizeWidget(panel
->taliB
[i
], 90, 18);
1853 WMMoveWidget(panel
->taliB
[i
], 10, 15 + 20 * i
);
1855 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[1]);
1856 WMGroupButtons(panel
->taliB
[0], panel
->taliB
[2]);
1858 WMMapSubwidgets(panel
->taliF
);
1860 WMMapSubwidgets(panel
->optF
);
1862 /**/ WMRealizeWidget(panel
->box
);
1863 WMMapSubwidgets(panel
->box
);
1865 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1869 changePage(panel
->secP
, panel
);
1871 fillTextureList(panel
->texLs
);
1873 fillColorList(panel
);
1875 panel
->texturePanel
= CreateTexturePanel(panel
->parent
);
1878 static void setupTextureFor(WMList
* list
, char *key
, char *defValue
, char *title
, int index
)
1881 TextureListItem
*titem
;
1883 titem
= wmalloc(sizeof(TextureListItem
));
1884 memset(titem
, 0, sizeof(TextureListItem
));
1886 titem
->title
= wstrdup(title
);
1887 titem
->prop
= GetObjectForKey(key
);
1888 if (!titem
->prop
|| !WMIsPLArray(titem
->prop
)) {
1889 /* Maybe also give a error message to stderr that the entry is bad? */
1890 titem
->prop
= WMCreatePropListFromDescription(defValue
);
1892 WMRetainPropList(titem
->prop
);
1894 titem
->texture
= WMGetPropListDescription((WMPropList
*) titem
->prop
, False
);
1896 titem
->selectedFor
= 1 << index
;
1898 titem
->ispixmap
= isPixmap(titem
->prop
);
1900 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1902 item
= WMAddListItem(list
, "");
1903 item
->clientData
= titem
;
1906 static void showData(_Panel
* panel
)
1911 str
= GetStringForKey("MenuStyle");
1912 if (str
&& strcasecmp(str
, "flat") == 0) {
1913 panel
->menuStyle
= MSTYLE_FLAT
;
1914 } else if (str
&& strcasecmp(str
, "singletexture") == 0) {
1915 panel
->menuStyle
= MSTYLE_SINGLE
;
1917 panel
->menuStyle
= MSTYLE_NORMAL
;
1920 str
= GetStringForKey("TitleJustify");
1921 if (str
&& strcasecmp(str
, "left") == 0) {
1922 panel
->titleAlignment
= WALeft
;
1923 } else if (str
&& strcasecmp(str
, "right") == 0) {
1924 panel
->titleAlignment
= WARight
;
1926 panel
->titleAlignment
= WACenter
;
1929 for (i
= 0; i
< sizeof(colorOptions
) / (2 * sizeof(char *)); i
++) {
1932 str
= GetStringForKey(colorOptions
[i
* 2]);
1934 str
= colorOptions
[i
* 2 + 1];
1936 if (!(color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), str
, False
))) {
1937 color
= WMCreateNamedColor(WMWidgetScreen(panel
->box
), "#000000", False
);
1940 panel
->colors
[i
] = color
;
1942 changeColorPage(panel
->colP
, panel
);
1944 for (i
= 0; i
< sizeof(textureOptions
) / (3 * sizeof(char *)); i
++) {
1945 setupTextureFor(panel
->texLs
, textureOptions
[i
* 3],
1946 textureOptions
[i
* 3 + 1], textureOptions
[i
* 3 + 2], i
);
1947 panel
->textureIndex
[i
] = i
;
1949 updatePreviewBox(panel
, EVERYTHING
);
1951 WMSetButtonSelected(panel
->mstyB
[panel
->menuStyle
], True
);
1952 WMSetButtonSelected(panel
->taliB
[panel
->titleAlignment
], True
);
1955 static void storeData(_Panel
* panel
)
1957 TextureListItem
*titem
;
1961 for (i
= 0; i
< sizeof(textureOptions
) / (sizeof(char *) * 3); i
++) {
1962 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[i
]);
1963 titem
= (TextureListItem
*) item
->clientData
;
1964 SetObjectForKey(titem
->prop
, textureOptions
[i
* 3]);
1967 for (i
= 0; i
< 8; i
++) {
1970 str
= WMGetColorRGBDescription(panel
->colors
[i
]);
1973 SetStringForKey(str
, colorOptions
[i
* 2]);
1978 switch (panel
->menuStyle
) {
1980 SetStringForKey("singletexture", "MenuStyle");
1983 SetStringForKey("flat", "MenuStyle");
1987 SetStringForKey("normal", "MenuStyle");
1990 switch (panel
->titleAlignment
) {
1992 SetStringForKey("left", "TitleJustify");
1995 SetStringForKey("right", "TitleJustify");
1999 SetStringForKey("center", "TitleJustify");
2004 static void prepareForClose(_Panel
* panel
)
2006 WMPropList
*textureList
;
2007 WMPropList
*texture
;
2008 TextureListItem
*titem
;
2010 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
2013 textureList
= WMCreatePLArray(NULL
, NULL
);
2015 /* store list of textures */
2016 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
2017 item
= WMGetListItem(panel
->texLs
, i
);
2018 titem
= (TextureListItem
*) item
->clientData
;
2020 texture
= WMCreatePLArray(WMCreatePLString(titem
->title
),
2021 WMRetainPropList(titem
->prop
), WMCreatePLString(titem
->path
), NULL
);
2023 WMAddToPLArray(textureList
, texture
);
2026 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
2027 WMReleasePropList(textureList
);
2029 /* store list of colors */
2030 textureList
= WMCreatePLArray(NULL
, NULL
);
2031 for (i
= 0; i
< 24; i
++) {
2035 color
= WMGetColorWellColor(panel
->sampW
[i
]);
2037 str
= WMGetColorRGBDescription(color
);
2038 WMAddToPLArray(textureList
, WMCreatePLString(str
));
2041 WMSetUDObjectForKey(udb
, textureList
, "ColorList");
2042 WMReleasePropList(textureList
);
2044 WMSynchronizeUserDefaults(udb
);
2047 Panel
*InitAppearance(WMScreen
* scr
, WMWindow
* win
)
2051 panel
= wmalloc(sizeof(_Panel
));
2052 memset(panel
, 0, sizeof(_Panel
));
2054 panel
->sectionName
= _("Appearance Preferences");
2056 panel
->description
= _("Background texture configuration for windows,\n" "menus and icons.");
2058 panel
->parent
= win
;
2060 panel
->callbacks
.createWidgets
= createPanel
;
2061 panel
->callbacks
.updateDomain
= storeData
;
2062 panel
->callbacks
.prepareForClose
= prepareForClose
;
2064 AddSection(panel
, ICON_FILE
);
2069 /****************************************************************************/
2071 typedef struct ExtractPanel
{
2081 static void OpenExtractPanelFor(_Panel
* panel
, char *path
)
2083 ExtractPanel
*epanel
;
2086 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
2088 epanel
= wmalloc(sizeof(ExtractPanel
));
2089 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->parent
, "extract",
2090 WMTitledWindowMask
| WMClosableWindowMask
);
2091 WMResizeWidget(epanel
->win
, 245, 250);
2092 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
2094 epanel
->label
= WMCreateLabel(epanel
->win
);
2095 WMResizeWidget(epanel
->label
, 225, 18);
2096 WMMoveWidget(epanel
->label
, 10, 10);
2097 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
2098 WMSetLabelRelief(epanel
->label
, WRSunken
);
2100 color
= WMDarkGrayColor(scr
);
2101 WMSetWidgetBackgroundColor(epanel
->label
, color
);
2102 WMReleaseColor(color
);
2104 color
= WMWhiteColor(scr
);
2105 WMSetLabelTextColor(epanel
->label
, color
);
2106 WMReleaseColor(color
);
2108 font
= WMBoldSystemFontOfSize(scr
, 12);
2109 WMSetLabelFont(epanel
->label
, font
);
2110 WMReleaseFont(font
);
2112 WMSetLabelText(epanel
->label
, _("Textures"));
2114 epanel
->list
= WMCreateList(epanel
->win
);
2115 WMResizeWidget(epanel
->list
, 225, 165);
2116 WMMoveWidget(epanel
->list
, 10, 30);
2118 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
2119 WMResizeWidget(epanel
->closeB
, 74, 24);
2120 WMMoveWidget(epanel
->closeB
, 165, 215);
2121 WMSetButtonText(epanel
->closeB
, _("Close"));
2123 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
2124 WMResizeWidget(epanel
->extrB
, 74, 24);
2125 WMMoveWidget(epanel
->extrB
, 80, 215);
2126 WMSetButtonText(epanel
->extrB
, _("Extract"));
2128 WMMapSubwidgets(epanel
->win
);
2130 /* take textures from file */
2132 WMRealizeWidget(epanel
->win
);
2134 WMMapWidget(epanel
->win
);