1 /* Apperance.c- color/texture for titlebar etc.
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1999 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,
31 #include <sys/types.h>
38 #include "TexturePanel.h"
40 typedef struct _Panel
{
46 CallbackRec callbacks
;
70 TexturePanel
*texturePanel
;
98 static void showData(_Panel
*panel
);
100 static void changePage(WMWidget
*w
, void *data
);
102 static void OpenExtractPanelFor(_Panel
*panel
, char *path
);
104 #define ICON_FILE "appearance"
106 #define TNEW_FILE "tnew"
107 #define TDEL_FILE "tdel"
108 #define TEDIT_FILE "tedit"
109 #define TEXTR_FILE "textr"
114 static char * blueled_xpm
[] = {
144 static char *blueled2_xpm
[] = {
145 /* width height num_colors chars_per_pixel */
177 static char * hand_xpm
[] = {
199 " .))),%.......... ",
200 " .)-)),&)))))))))$. ",
201 " .-&))))))))),,,,;;. ",
202 " .=)))))))));-=***&$. ",
203 " .=)))))))),..+..... ",
221 #define FTITLE (1<<0)
222 #define UTITLE (1<<1)
223 #define OTITLE (1<<2)
224 #define RESIZEBAR (1<<3)
225 #define MTITLE (1<<4)
229 #define EVERYTHING 0xff
232 #define RESIZEBAR_BEVEL -1
233 #define MENU_BEVEL -2
235 #define TEXPREV_WIDTH 40
236 #define TEXPREV_HEIGHT 24
243 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
247 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
250 color
->red
= xcolor
.red
>> 8;
251 color
->green
= xcolor
.green
>> 8;
252 color
->blue
= xcolor
.blue
>> 8;
258 dumpRImage(char *path
, RImage
*image
)
262 f
= fopen(path
, "w");
267 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
,
268 image
->data
[3]!=NULL
? 4 : 3);
270 fwrite(image
->data
[0], 1, image
->width
* image
->height
, f
);
271 fwrite(image
->data
[1], 1, image
->width
* image
->height
, f
);
272 fwrite(image
->data
[2], 1, image
->width
* image
->height
, f
);
274 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
284 isPixmap(proplist_t prop
)
289 p
= PLGetArrayElement(prop
, 0);
291 if (strcasecmp(&s
[1], "pixmap")==0)
299 drawResizebarBevel(RImage
*img
)
304 int width
= img
->width
;
305 int height
= img
->height
;
309 black
.red
= black
.green
= black
.blue
= 0;
312 light
.red
= light
.green
= light
.blue
= 80;
315 dark
.red
= dark
.green
= dark
.blue
= 40;
317 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
318 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
320 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
321 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
323 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
325 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
328 RDrawLine(img
, 0, height
-1, width
-1, height
-1, &black
);
329 RDrawLine(img
, 0, 0, 0, height
-1, &black
);
330 RDrawLine(img
, width
-1, 0, width
-1, height
-1, &black
);
335 drawMenuBevel(RImage
*img
)
337 RColor light
, dark
, mid
;
339 int iheight
= img
->height
/ 3;
342 light
.red
= light
.green
= light
.blue
= 80;
345 dark
.red
= dark
.green
= dark
.blue
= 0;
348 mid
.red
= mid
.green
= mid
.blue
= 40;
350 for (i
= 1; i
< 3; i
++) {
351 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
352 img
->width
-1, i
*iheight
-2, &mid
);
354 RDrawLine(img
, 0, i
*iheight
-1,
355 img
->width
-1, i
*iheight
-1, &dark
);
357 ROperateLine(img
, RAddOperation
, 0, i
*iheight
,
358 img
->width
-1, i
*iheight
, &light
);
364 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
365 char *path
, int border
)
370 RContext
*rc
= WMScreenRContext(scr
);
375 type
= PLGetString(PLGetArrayElement(texture
, 0));
377 image
= RCreateImage(width
, height
, False
);
379 if (strcasecmp(type
, "solid")==0) {
381 str
= PLGetString(PLGetArrayElement(texture
, 1));
383 str2rcolor(rc
, str
, &rcolor
);
385 RClearImage(image
, &rcolor
);
386 } else if (strcasecmp(&type
[1], "gradient")==0) {
390 switch (toupper(type
[0])) {
392 style
= RVerticalGradient
;
395 style
= RHorizontalGradient
;
399 style
= RDiagonalGradient
;
403 str
= PLGetString(PLGetArrayElement(texture
, 1));
404 str2rcolor(rc
, str
, &rcolor
);
405 str
= PLGetString(PLGetArrayElement(texture
, 2));
406 str2rcolor(rc
, str
, &rcolor2
);
408 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
409 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
413 RImage
*grad
, *timage
;
416 switch (toupper(type
[1])) {
418 style
= RVerticalGradient
;
421 style
= RHorizontalGradient
;
425 style
= RDiagonalGradient
;
429 str
= PLGetString(PLGetArrayElement(texture
, 3));
430 str2rcolor(rc
, str
, &rcolor
);
431 str
= PLGetString(PLGetArrayElement(texture
, 4));
432 str2rcolor(rc
, str
, &rcolor2
);
434 str
= PLGetString(PLGetArrayElement(texture
, 1));
436 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
437 timage
= RLoadImage(rc
, path
, 0);
440 wwarning("could not load file '%s': %s", path
,
441 RMessageForError(RErrorCode
));
443 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
445 image
= RMakeTiledImage(timage
, width
, height
);
446 RDestroyImage(timage
);
448 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
450 RCombineImagesWithOpaqueness(image
, grad
, i
);
453 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
458 switch (toupper(type
[1])) {
460 style
= RVerticalGradient
;
463 style
= RHorizontalGradient
;
467 style
= RDiagonalGradient
;
471 j
= PLGetNumberOfElements(texture
);
474 colors
= wmalloc(j
* sizeof(RColor
*));
476 for (i
= 2; i
< j
; i
++) {
477 str
= PLGetString(PLGetArrayElement(texture
, i
));
478 colors
[i
-2] = wmalloc(sizeof(RColor
));
479 str2rcolor(rc
, str
, colors
[i
-2]);
483 image
= RRenderMultiGradient(width
, height
, colors
, style
);
485 for (i
= 0; colors
[i
]!=NULL
; i
++)
489 } else if (strcasecmp(&type
[1], "pixmap")==0) {
490 RImage
*timage
= NULL
;
494 str
= PLGetString(PLGetArrayElement(texture
, 1));
496 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
498 timage
= RLoadImage(rc
, path
, 0);
501 wwarning("could not load file '%s': %s", path
? path
: str
,
502 RMessageForError(RErrorCode
));
504 str
= PLGetString(PLGetArrayElement(texture
, 2));
505 str2rcolor(rc
, str
, &color
);
507 switch (toupper(type
[0])) {
509 image
= RMakeTiledImage(timage
, width
, height
);
510 RDestroyImage(timage
);
514 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
515 RDestroyImage(timage
);
520 image
= RScaleImage(timage
, width
, height
);
521 RDestroyImage(timage
);
534 dumpRImage(path
, image
);
538 if (border
== RESIZEBAR_BEVEL
) {
539 drawResizebarBevel(image
);
540 } else if (border
== MENU_BEVEL
) {
541 drawMenuBevel(image
);
544 RBevelImage(image
, border
);
547 RConvertImage(rc
, image
, &pixmap
);
548 RDestroyImage(image
);
555 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
557 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
558 Display
*dpy
= WMScreenDisplay(scr
);
561 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
564 str
= GetStringForKey("MenuStyle");
565 if (!str
|| strcasecmp(str
, "normal")==0) {
568 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
570 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*3,
572 for (i
= 0; i
< 3; i
++) {
573 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
,
576 XFreePixmap(dpy
, tmp
);
577 } else if (strcasecmp(str
, "flat")==0) {
578 pix
= renderTexture(scr
, texture
, width
, iheight
*3, NULL
, RBEV_RAISED2
);
580 pix
= renderTexture(scr
, texture
, width
, iheight
*3, NULL
, MENU_BEVEL
);
590 updatePreviewBox(_Panel
*panel
, int elements
)
592 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
593 Display
*dpy
= WMScreenDisplay(scr
);
594 /* RContext *rc = WMScreenRContext(scr);*/
599 TextureListItem
*titem
;
601 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
604 if (!panel
->preview
) {
607 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
608 260-4, 165-4, WMScreenDepth(scr
));
610 color
= WMGrayColor(scr
);
611 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
613 WMReleaseColor(color
);
618 if (elements
& FTITLE
) {
619 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
620 titem
= (TextureListItem
*)item
->clientData
;
622 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
624 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 5);
626 XFreePixmap(dpy
, pix
);
628 if (elements
& UTITLE
) {
629 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
630 titem
= (TextureListItem
*)item
->clientData
;
632 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
634 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 30);
636 XFreePixmap(dpy
, pix
);
638 if (elements
& OTITLE
) {
639 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
640 titem
= (TextureListItem
*)item
->clientData
;
642 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
644 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 55);
646 XFreePixmap(dpy
, pix
);
648 if (elements
& RESIZEBAR
) {
649 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
650 titem
= (TextureListItem
*)item
->clientData
;
652 pix
= renderTexture(scr
, titem
->prop
, 210, 9, NULL
, RESIZEBAR_BEVEL
);
654 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 80);
656 XFreePixmap(dpy
, pix
);
658 if (elements
& MTITLE
) {
659 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
660 titem
= (TextureListItem
*)item
->clientData
;
662 pix
= renderTexture(scr
, titem
->prop
, 100, 20, NULL
, RBEV_RAISED2
);
664 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 20, 30, 95);
666 XFreePixmap(dpy
, pix
);
668 if (elements
& MITEM
) {
669 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
670 titem
= (TextureListItem
*)item
->clientData
;
672 pix
= renderMenu(panel
, titem
->prop
, 100, 18);
674 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 18*3, 30, 115);
676 XFreePixmap(dpy
, pix
);
678 if (elements
& (MITEM
|MTITLE
)) {
679 XDrawLine(dpy
, panel
->preview
, gc
, 29, 95, 29, 115+36+20);
680 XDrawLine(dpy
, panel
->preview
, gc
, 29, 94, 129, 94);
683 if (elements
& ICON
) {
684 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
685 titem
= (TextureListItem
*)item
->clientData
;
687 pix
= renderTexture(scr
, titem
->prop
, 64, 64, NULL
,
688 titem
->ispixmap
? 0 : RBEV_RAISED3
);
690 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 64, 64, 170, 95);
692 XFreePixmap(dpy
, pix
);
698 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
699 260-4, 165-4, WMScreenDepth(scr
));
701 WMSetLabelImage(panel
->prevL
, p
);
704 WMRedisplayWidget(panel
->prevL
);
714 cancelNewTexture(void *data
)
716 _Panel
*panel
= (_Panel
*)data
;
718 HideTexturePanel(panel
->texturePanel
);
725 makeFileName(char *prefix
)
729 fname
= wstrdup(prefix
);
731 while (access(fname
, F_OK
)==0) {
735 sprintf(buf
, "%08lx.cache", time(NULL
));
736 fname
= wstrappend(prefix
, buf
);
746 okNewTexture(void *data
)
748 _Panel
*panel
= (_Panel
*)data
;
753 TextureListItem
*titem
;
754 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
756 titem
= wmalloc(sizeof(TextureListItem
));
757 memset(titem
, 0, sizeof(TextureListItem
));
759 HideTexturePanel(panel
->texturePanel
);
761 name
= GetTexturePanelTextureName(panel
->texturePanel
);
763 prop
= GetTexturePanelTexture(panel
->texturePanel
);
765 str
= PLGetDescription(prop
);
769 titem
->texture
= str
;
770 titem
->selectedFor
= 0;
772 titem
->ispixmap
= isPixmap(prop
);
774 titem
->path
= makeFileName(panel
->fprefix
);
775 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
778 item
= WMAddListItem(panel
->texLs
, "");
779 item
->clientData
= titem
;
781 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
786 okEditTexture(void *data
)
788 _Panel
*panel
= (_Panel
*)data
;
793 TextureListItem
*titem
;
795 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
796 titem
= (TextureListItem
*)item
->clientData
;
798 HideTexturePanel(panel
->texturePanel
);
800 if (titem
->current
) {
801 name
= GetTexturePanelTextureName(panel
->texturePanel
);
807 prop
= GetTexturePanelTexture(panel
->texturePanel
);
809 str
= PLGetDescription(prop
);
811 PLRelease(titem
->prop
);
814 titem
->ispixmap
= isPixmap(prop
);
816 free(titem
->texture
);
817 titem
->texture
= str
;
819 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
820 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
821 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
824 WMRedisplayWidget(panel
->texLs
);
826 if (titem
->selectedFor
)
827 updatePreviewBox(panel
, titem
->selectedFor
);
829 changePage(panel
->secP
, panel
);
835 editTexture(WMWidget
*w
, void *data
)
837 _Panel
*panel
= (_Panel
*)data
;
839 TextureListItem
*titem
;
841 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
842 titem
= (TextureListItem
*)item
->clientData
;
844 SetTexturePanelPixmapPath(panel
->texturePanel
,
845 GetObjectForKey("PixmapPath"));
847 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
849 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
850 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
852 ShowTexturePanel(panel
->texturePanel
);
858 newTexture(WMWidget
*w
, void *data
)
860 _Panel
*panel
= (_Panel
*)data
;
862 SetTexturePanelPixmapPath(panel
->texturePanel
,
863 GetObjectForKey("PixmapPath"));
865 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
867 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
869 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
871 ShowTexturePanel(panel
->texturePanel
);
877 deleteTexture(WMWidget
*w
, void *data
)
879 _Panel
*panel
= (_Panel
*)data
;
881 TextureListItem
*titem
;
885 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
886 row
= WMGetListSelectedItemRow(panel
->texLs
);
887 item
= WMGetListItem(panel
->texLs
, row
);
888 titem
= (TextureListItem
*)item
->clientData
;
890 if (titem
->selectedFor
& (1 << section
)) {
891 TextureListItem
*titem2
;
893 panel
->textureIndex
[section
] = section
;
894 item
= WMGetListItem(panel
->texLs
, section
);
895 titem2
= (TextureListItem
*)item
->clientData
;
896 titem2
->selectedFor
|= 1 << section
;
900 free(titem
->texture
);
901 PLRelease(titem
->prop
);
903 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
904 wsyserror("could not remove file %s", titem
->path
);
911 WMRemoveListItem(panel
->texLs
, row
);
912 WMSetButtonEnabled(panel
->delB
, False
);
919 extractTexture(WMWidget
*w
, void *data
)
921 _Panel
*panel
= (_Panel
*)data
;
924 WMScreen
*scr
= WMWidgetScreen(w
);
926 opanel
= WMGetOpenPanel(scr
);
927 WMSetFilePanelCanChooseDirectories(opanel
, False
);
928 WMSetFilePanelCanChooseFiles(opanel
, True
);
930 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
931 _("Select File"), NULL
)) {
932 path
= WMGetFilePanelFileName(opanel
);
934 OpenExtractPanelFor(panel
, path
);
942 changePage(WMWidget
*w
, void *data
)
944 _Panel
*panel
= (_Panel
*)data
;
947 TextureListItem
*titem
;
949 WMScreen
*scr
= WMWidgetScreen(w
);
950 RContext
*rc
= WMScreenRContext(scr
);
951 static WMPoint positions
[] = {
961 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
963 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
965 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
967 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
969 titem
= (TextureListItem
*)item
->clientData
;
971 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
972 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
973 WMSetLabelText(panel
->texsL
, str
);
979 color
= WMGrayColor(scr
);
980 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
981 positions
[panel
->oldsection
].x
,
982 positions
[panel
->oldsection
].y
, 22, 22);
983 WMReleaseColor(color
);
985 panel
->oldsection
= section
;
986 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
987 positions
[section
].y
);
989 WMRedisplayWidget(panel
->prevL
);
995 previewClick(XEvent
*event
, void *clientData
)
997 _Panel
*panel
= (_Panel
*)clientData
;
999 static WMRect parts
[] = {
1000 {{30, 5},{210, 20}},
1005 {{30,115},{100,60}},
1009 for (i
= 0; i
< 7; i
++) {
1010 if (event
->xbutton
.x
>= parts
[i
].pos
.x
1011 && event
->xbutton
.y
>= parts
[i
].pos
.y
1012 && event
->xbutton
.x
< parts
[i
].pos
.x
+ parts
[i
].size
.width
1013 && event
->xbutton
.y
< parts
[i
].pos
.y
+ parts
[i
].size
.height
) {
1015 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1016 changePage(panel
->secP
, panel
);
1024 textureClick(WMWidget
*w
, void *data
)
1026 _Panel
*panel
= (_Panel
*)data
;
1029 TextureListItem
*titem
;
1031 i
= WMGetListSelectedItemRow(panel
->texLs
);
1033 item
= WMGetListItem(panel
->texLs
, i
);
1035 titem
= (TextureListItem
*)item
->clientData
;
1037 if (titem
->current
) {
1038 WMSetButtonEnabled(panel
->delB
, False
);
1040 WMSetButtonEnabled(panel
->delB
, True
);
1047 textureDoubleClick(WMWidget
*w
, void *data
)
1049 _Panel
*panel
= (_Panel
*)data
;
1052 TextureListItem
*titem
;
1055 /* unselect old texture */
1056 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1058 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1059 titem
= (TextureListItem
*)item
->clientData
;
1060 titem
->selectedFor
&= ~(1 << section
);
1062 /* select new texture */
1063 i
= WMGetListSelectedItemRow(panel
->texLs
);
1065 item
= WMGetListItem(panel
->texLs
, i
);
1067 titem
= (TextureListItem
*)item
->clientData
;
1069 titem
->selectedFor
|= 1<<section
;
1071 panel
->textureIndex
[section
] = i
;
1073 WMRedisplayWidget(panel
->texLs
);
1075 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
1076 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
1077 WMSetLabelText(panel
->texsL
, str
);
1080 updatePreviewBox(panel
, 1<<section
);
1087 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
1090 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
1091 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1092 int width
, height
, x
, y
;
1093 Display
*dpy
= WMScreenDisplay(scr
);
1094 WMColor
*white
= WMWhiteColor(scr
);
1096 WMColor
*black
= WMBlackColor(scr
);
1097 TextureListItem
*titem
;
1099 width
= rect
->size
.width
;
1100 height
= rect
->size
.height
;
1104 if (state
& WLDSSelected
)
1105 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1107 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
1109 item
= WMGetListItem(lPtr
, index
);
1110 titem
= (TextureListItem
*)item
->clientData
;
1113 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0, TEXPREV_WIDTH
,
1114 TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1116 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1117 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1118 else if (titem
->selectedFor
)
1119 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1121 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
1122 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
1123 strlen(titem
->title
));
1125 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
1126 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
1127 strlen(titem
->texture
));
1130 WMReleaseColor(white
);
1131 WMReleaseColor(black
);
1137 loadRImage(WMScreen
*scr
, char *path
)
1145 f
= fopen(path
, "r");
1149 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1151 image
= RCreateImage(w
, h
, d
== 4);
1152 for (i
= 0; i
< d
; i
++) {
1153 fread(image
->data
[i
], 1, w
*h
, f
);
1157 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1158 RDestroyImage(image
);
1166 fillTextureList(WMList
*lPtr
)
1168 proplist_t textureList
;
1170 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1172 TextureListItem
*titem
;
1173 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1175 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1179 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1182 texture
= PLGetArrayElement(textureList
, i
);
1184 titem
= wmalloc(sizeof(TextureListItem
));
1185 memset(titem
, 0, sizeof(TextureListItem
));
1187 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1188 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1189 titem
->texture
= PLGetDescription(titem
->prop
);
1190 titem
->selectedFor
= 0;
1191 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1193 titem
->preview
= loadRImage(scr
, titem
->path
);
1194 if (!titem
->preview
) {
1195 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1196 TEXPREV_HEIGHT
, NULL
, 0);
1198 item
= WMAddListItem(lPtr
, "");
1199 item
->clientData
= titem
;
1205 createPanel(Panel
*p
)
1207 _Panel
*panel
= (_Panel
*)p
;
1210 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1215 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
1217 if (access(panel
->fprefix
, F_OK
)!=0) {
1218 if (mkdir(panel
->fprefix
, 0755) < 0) {
1219 wsyserror(panel
->fprefix
);
1224 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
1225 free(panel
->fprefix
);
1226 panel
->fprefix
= tmp
;
1227 if (access(panel
->fprefix
, F_OK
)!=0) {
1228 if (mkdir(panel
->fprefix
, 0755) < 0) {
1229 wsyserror(panel
->fprefix
);
1234 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1235 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1236 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1238 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1239 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1240 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1242 panel
->frame
= WMCreateFrame(panel
->win
);
1243 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1244 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1247 panel
->prevL
= WMCreateLabel(panel
->frame
);
1248 WMResizeWidget(panel
->prevL
, 260, 165);
1249 WMMoveWidget(panel
->prevL
, 15, 10);
1250 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1251 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1253 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1254 previewClick
, panel
);
1257 panel
->secP
= WMCreatePopUpButton(panel
->frame
);
1258 WMResizeWidget(panel
->secP
, 260, 20);
1259 WMMoveWidget(panel
->secP
, 15, 180);
1260 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1261 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1262 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1263 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1264 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1265 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1266 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1267 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1268 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1270 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1273 panel
->texsL
= WMCreateLabel(panel
->frame
);
1274 WMResizeWidget(panel
->texsL
, 260, 20);
1275 WMMoveWidget(panel
->texsL
, 15, 205);
1276 WMSetLabelWraps(panel
->texsL
, False
);
1279 font
= WMBoldSystemFontOfSize(scr
, 12);
1281 panel
->texL
= WMCreateLabel(panel
->frame
);
1282 WMResizeWidget(panel
->texL
, 225, 18);
1283 WMMoveWidget(panel
->texL
, 285, 10);
1284 WMSetLabelFont(panel
->texL
, font
);
1285 WMSetLabelText(panel
->texL
, _("Textures"));
1286 WMSetLabelRelief(panel
->texL
, WRSunken
);
1287 WMSetLabelTextAlignment(panel
->texL
, WACenter
);
1288 color
= WMDarkGrayColor(scr
);
1289 WMSetWidgetBackgroundColor(panel
->texL
, color
);
1290 WMReleaseColor(color
);
1291 color
= WMWhiteColor(scr
);
1292 WMSetLabelTextColor(panel
->texL
, color
);
1293 WMReleaseColor(color
);
1295 WMReleaseFont(font
);
1297 panel
->texLs
= WMCreateList(panel
->frame
);
1298 WMResizeWidget(panel
->texLs
, 225, 144);
1299 WMMoveWidget(panel
->texLs
, 285, 30);
1300 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1301 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1302 WMHangData(panel
->texLs
, panel
);
1303 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1304 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1306 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1307 "for the selected item."),
1308 WMWidgetView(panel
->texLs
));
1310 /* command buttons */
1312 font
= WMSystemFontOfSize(scr
, 10);
1315 panel
->newB
= WMCreateCommandButton(panel
->frame
);
1316 WMResizeWidget(panel
->newB
, 56, 48);
1317 WMMoveWidget(panel
->newB
, 285, 180);
1318 WMSetButtonFont(panel
->newB
, font
);
1319 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1320 WMSetButtonText(panel
->newB
, _("New"));
1321 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1322 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1324 WMSetBalloonTextForView(_("Create a new texture."),
1325 WMWidgetView(panel
->newB
));
1327 panel
->ripB
= WMCreateCommandButton(panel
->frame
);
1328 WMResizeWidget(panel
->ripB
, 56, 48);
1329 WMMoveWidget(panel
->ripB
, 341, 180);
1330 WMSetButtonFont(panel
->ripB
, font
);
1331 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1332 WMSetButtonText(panel
->ripB
, _("Extract..."));
1333 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1334 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1336 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1337 WMWidgetView(panel
->ripB
));
1339 WMSetButtonEnabled(panel
->ripB
, False
);
1341 panel
->editB
= WMCreateCommandButton(panel
->frame
);
1342 WMResizeWidget(panel
->editB
, 56, 48);
1343 WMMoveWidget(panel
->editB
, 397, 180);
1344 WMSetButtonFont(panel
->editB
, font
);
1345 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1346 WMSetButtonText(panel
->editB
, _("Edit"));
1347 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1348 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1349 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1350 WMWidgetView(panel
->editB
));
1352 panel
->delB
= WMCreateCommandButton(panel
->frame
);
1353 WMResizeWidget(panel
->delB
, 56, 48);
1354 WMMoveWidget(panel
->delB
, 453, 180);
1355 WMSetButtonFont(panel
->delB
, font
);
1356 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1357 WMSetButtonText(panel
->delB
, _("Delete"));
1358 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1359 WMSetButtonEnabled(panel
->delB
, False
);
1360 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1361 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1362 WMWidgetView(panel
->delB
));
1364 WMReleaseFont(font
);
1368 WMRealizeWidget(panel
->frame
);
1369 WMMapSubwidgets(panel
->frame
);
1371 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1375 changePage(panel
->secP
, panel
);
1377 fillTextureList(panel
->texLs
);
1379 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1385 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1389 TextureListItem
*titem
;
1391 titem
= wmalloc(sizeof(TextureListItem
));
1392 memset(titem
, 0, sizeof(TextureListItem
));
1394 titem
->title
= wstrdup(title
);
1395 titem
->prop
= GetObjectForKey(key
);
1397 titem
->prop
= PLGetProplistWithDescription(defValue
);
1399 PLRetain(titem
->prop
);
1401 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1403 titem
->selectedFor
= 1<<index
;
1405 titem
->ispixmap
= isPixmap(titem
->prop
);
1407 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1408 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1410 item
= WMAddListItem(list
, "");
1411 item
->clientData
= titem
;
1417 showData(_Panel
*panel
)
1421 setupTextureFor(panel
->texLs
, "FTitleBack", "(solid, black)",
1423 panel
->textureIndex
[i
] = i
++;
1425 setupTextureFor(panel
->texLs
, "UTitleBack", "(solid, gray)",
1427 panel
->textureIndex
[i
] = i
++;
1429 setupTextureFor(panel
->texLs
, "PTitleBack", "(solid, \"#616161\")",
1430 "[Owner of Focused]", i
);
1431 panel
->textureIndex
[i
] = i
++;
1433 setupTextureFor(panel
->texLs
, "ResizebarBack", "(solid, gray)",
1435 panel
->textureIndex
[i
] = i
++;
1437 setupTextureFor(panel
->texLs
, "MenuTitleBack", "(solid, black)",
1439 panel
->textureIndex
[i
] = i
++;
1441 setupTextureFor(panel
->texLs
, "MenuTextBack", "(solid, gray)",
1443 panel
->textureIndex
[i
] = i
++;
1445 setupTextureFor(panel
->texLs
, "IconBack", "(solid, gray)", "[Icon]", i
);
1446 panel
->textureIndex
[i
] = i
++;
1448 setupTextureFor(panel->texLs, "WorkspaceBack", "(solid, black)",
1450 panel->textureIndex[i] = i++;
1453 updatePreviewBox(panel
, EVERYTHING
);
1459 storeData(_Panel
*panel
)
1461 TextureListItem
*titem
;
1464 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
1465 titem
= (TextureListItem
*)item
->clientData
;
1466 SetObjectForKey(titem
->prop
, "FTitleBack");
1468 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
1469 titem
= (TextureListItem
*)item
->clientData
;
1470 SetObjectForKey(titem
->prop
, "UTitleBack");
1472 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
1473 titem
= (TextureListItem
*)item
->clientData
;
1474 SetObjectForKey(titem
->prop
, "PTitleBack");
1476 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
1477 titem
= (TextureListItem
*)item
->clientData
;
1478 SetObjectForKey(titem
->prop
, "ResizebarBack");
1480 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
1481 titem
= (TextureListItem
*)item
->clientData
;
1482 SetObjectForKey(titem
->prop
, "MenuTitleBack");
1484 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
1485 titem
= (TextureListItem
*)item
->clientData
;
1486 SetObjectForKey(titem
->prop
, "MenuTextBack");
1488 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
1489 titem
= (TextureListItem
*)item
->clientData
;
1490 SetObjectForKey(titem
->prop
, "IconBack");
1495 prepareForClose(_Panel
*panel
)
1497 proplist_t textureList
;
1500 TextureListItem
*titem
;
1502 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1504 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
1506 /* store list of textures */
1507 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
1508 item
= WMGetListItem(panel
->texLs
, i
);
1509 titem
= (TextureListItem
*)item
->clientData
;
1511 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
1512 PLRetain(titem
->prop
),
1513 PLMakeString(titem
->path
),
1516 PLAppendArrayElement(textureList
, texture
);
1519 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
1520 PLRelease(textureList
);
1522 WMSynchronizeUserDefaults(udb
);
1528 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
1532 panel
= wmalloc(sizeof(_Panel
));
1533 memset(panel
, 0, sizeof(_Panel
));
1535 panel
->sectionName
= _("Appearance Preferences");
1537 panel
->description
= _("Background texture configuration for windows,\n"
1538 "menus and icons.");
1542 panel
->callbacks
.createWidgets
= createPanel
;
1543 panel
->callbacks
.updateDomain
= storeData
;
1544 panel
->callbacks
.prepareForClose
= prepareForClose
;
1546 AddSection(panel
, ICON_FILE
);
1553 /****************************************************************************/
1557 typedef struct ExtractPanel
{
1570 OpenExtractPanelFor(_Panel
*panel
, char *path
)
1572 ExtractPanel
*epanel
;
1575 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1577 epanel
= wmalloc(sizeof(ExtractPanel
));
1578 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
1580 |WMClosableWindowMask
);
1581 WMResizeWidget(epanel
->win
, 245, 250);
1582 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
1584 epanel
->label
= WMCreateLabel(epanel
->win
);
1585 WMResizeWidget(epanel
->label
, 225, 18);
1586 WMMoveWidget(epanel
->label
, 10, 10);
1587 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
1588 WMSetLabelRelief(epanel
->label
, WRSunken
);
1590 color
= WMDarkGrayColor(scr
);
1591 WMSetWidgetBackgroundColor(epanel
->label
, color
);
1592 WMReleaseColor(color
);
1594 color
= WMWhiteColor(scr
);
1595 WMSetLabelTextColor(epanel
->label
, color
);
1596 WMReleaseColor(color
);
1598 font
= WMBoldSystemFontOfSize(scr
, 12);
1599 WMSetLabelFont(epanel
->label
, font
);
1600 WMReleaseFont(font
);
1602 WMSetLabelText(epanel
->label
, _("Textures"));
1604 epanel
->list
= WMCreateList(epanel
->win
);
1605 WMResizeWidget(epanel
->list
, 225, 165);
1606 WMMoveWidget(epanel
->list
, 10, 30);
1610 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
1611 WMResizeWidget(epanel
->closeB
, 74, 24);
1612 WMMoveWidget(epanel
->closeB
, 165, 215);
1613 WMSetButtonText(epanel
->closeB
, _("Close"));
1615 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
1616 WMResizeWidget(epanel
->extrB
, 74, 24);
1617 WMMoveWidget(epanel
->extrB
, 80, 215);
1618 WMSetButtonText(epanel
->extrB
, _("Extract"));
1620 WMMapSubwidgets(epanel
->win
);
1623 /* take textures from file */
1627 WMRealizeWidget(epanel
->win
);
1629 WMMapWidget(epanel
->win
);