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
;
77 TexturePanel
*texturePanel
;
105 static void showData(_Panel
*panel
);
107 static void changePage(WMWidget
*w
, void *data
);
109 static void OpenExtractPanelFor(_Panel
*panel
, char *path
);
111 #define ICON_FILE "appearance"
113 #define TNEW_FILE "tnew"
114 #define TDEL_FILE "tdel"
115 #define TEDIT_FILE "tedit"
116 #define TEXTR_FILE "textr"
121 static char * blueled_xpm
[] = {
151 static char *blueled2_xpm
[] = {
152 /* width height num_colors chars_per_pixel */
184 static char * hand_xpm
[] = {
206 " .))),%.......... ",
207 " .)-)),&)))))))))$. ",
208 " .-&))))))))),,,,;;. ",
209 " .=)))))))));-=***&$. ",
210 " .=)))))))),..+..... ",
228 #define FTITLE (1<<0)
229 #define UTITLE (1<<1)
230 #define OTITLE (1<<2)
231 #define RESIZEBAR (1<<3)
232 #define MTITLE (1<<4)
236 #define EVERYTHING 0xff
239 #define RESIZEBAR_BEVEL -1
240 #define MENU_BEVEL -2
242 #define TEXPREV_WIDTH 40
243 #define TEXPREV_HEIGHT 24
250 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
254 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
257 color
->red
= xcolor
.red
>> 8;
258 color
->green
= xcolor
.green
>> 8;
259 color
->blue
= xcolor
.blue
>> 8;
265 dumpRImage(char *path
, RImage
*image
)
269 f
= fopen(path
, "w");
274 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
,
275 image
->data
[3]!=NULL
? 4 : 3);
277 fwrite(image
->data
[0], 1, image
->width
* image
->height
, f
);
278 fwrite(image
->data
[1], 1, image
->width
* image
->height
, f
);
279 fwrite(image
->data
[2], 1, image
->width
* image
->height
, f
);
281 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
291 isPixmap(proplist_t prop
)
296 p
= PLGetArrayElement(prop
, 0);
298 if (strcasecmp(&s
[1], "pixmap")==0)
306 drawResizebarBevel(RImage
*img
)
311 int width
= img
->width
;
312 int height
= img
->height
;
316 black
.red
= black
.green
= black
.blue
= 0;
319 light
.red
= light
.green
= light
.blue
= 80;
322 dark
.red
= dark
.green
= dark
.blue
= 40;
324 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
325 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
327 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
328 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
330 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
332 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
335 RDrawLine(img
, 0, height
-1, width
-1, height
-1, &black
);
336 RDrawLine(img
, 0, 0, 0, height
-1, &black
);
337 RDrawLine(img
, width
-1, 0, width
-1, height
-1, &black
);
342 drawMenuBevel(RImage
*img
)
344 RColor light
, dark
, mid
;
346 int iheight
= img
->height
/ 3;
349 light
.red
= light
.green
= light
.blue
= 80;
352 dark
.red
= dark
.green
= dark
.blue
= 0;
355 mid
.red
= mid
.green
= mid
.blue
= 40;
357 for (i
= 1; i
< 4; i
++) {
358 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
359 img
->width
-1, i
*iheight
-2, &mid
);
361 RDrawLine(img
, 0, i
*iheight
-1,
362 img
->width
-1, i
*iheight
-1, &dark
);
364 ROperateLine(img
, RAddOperation
, 0, i
*iheight
,
365 img
->width
-1, i
*iheight
, &light
);
371 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
372 char *path
, int border
)
377 RContext
*rc
= WMScreenRContext(scr
);
382 type
= PLGetString(PLGetArrayElement(texture
, 0));
384 image
= RCreateImage(width
, height
, False
);
386 if (strcasecmp(type
, "solid")==0) {
388 str
= PLGetString(PLGetArrayElement(texture
, 1));
390 str2rcolor(rc
, str
, &rcolor
);
392 RClearImage(image
, &rcolor
);
393 } else if (strcasecmp(&type
[1], "gradient")==0) {
397 switch (toupper(type
[0])) {
399 style
= RVerticalGradient
;
402 style
= RHorizontalGradient
;
406 style
= RDiagonalGradient
;
410 str
= PLGetString(PLGetArrayElement(texture
, 1));
411 str2rcolor(rc
, str
, &rcolor
);
412 str
= PLGetString(PLGetArrayElement(texture
, 2));
413 str2rcolor(rc
, str
, &rcolor2
);
415 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
416 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
420 RImage
*grad
, *timage
;
423 switch (toupper(type
[1])) {
425 style
= RVerticalGradient
;
428 style
= RHorizontalGradient
;
432 style
= RDiagonalGradient
;
436 str
= PLGetString(PLGetArrayElement(texture
, 3));
437 str2rcolor(rc
, str
, &rcolor
);
438 str
= PLGetString(PLGetArrayElement(texture
, 4));
439 str2rcolor(rc
, str
, &rcolor2
);
441 str
= PLGetString(PLGetArrayElement(texture
, 1));
443 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
444 timage
= RLoadImage(rc
, path
, 0);
447 wwarning("could not load file '%s': %s", path
,
448 RMessageForError(RErrorCode
));
450 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
452 image
= RMakeTiledImage(timage
, width
, height
);
453 RDestroyImage(timage
);
455 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
457 RCombineImagesWithOpaqueness(image
, grad
, i
);
460 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
465 switch (toupper(type
[1])) {
467 style
= RVerticalGradient
;
470 style
= RHorizontalGradient
;
474 style
= RDiagonalGradient
;
478 j
= PLGetNumberOfElements(texture
);
481 colors
= wmalloc(j
* sizeof(RColor
*));
483 for (i
= 2; i
< j
; i
++) {
484 str
= PLGetString(PLGetArrayElement(texture
, i
));
485 colors
[i
-2] = wmalloc(sizeof(RColor
));
486 str2rcolor(rc
, str
, colors
[i
-2]);
490 image
= RRenderMultiGradient(width
, height
, colors
, style
);
492 for (i
= 0; colors
[i
]!=NULL
; i
++)
496 } else if (strcasecmp(&type
[1], "pixmap")==0) {
497 RImage
*timage
= NULL
;
501 str
= PLGetString(PLGetArrayElement(texture
, 1));
503 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
505 timage
= RLoadImage(rc
, path
, 0);
508 wwarning("could not load file '%s': %s", path
? path
: str
,
509 RMessageForError(RErrorCode
));
511 str
= PLGetString(PLGetArrayElement(texture
, 2));
512 str2rcolor(rc
, str
, &color
);
514 switch (toupper(type
[0])) {
516 image
= RMakeTiledImage(timage
, width
, height
);
517 RDestroyImage(timage
);
521 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
522 RDestroyImage(timage
);
527 image
= RScaleImage(timage
, width
, height
);
528 RDestroyImage(timage
);
541 dumpRImage(path
, image
);
545 if (border
== RESIZEBAR_BEVEL
) {
546 drawResizebarBevel(image
);
547 } else if (border
== MENU_BEVEL
) {
548 drawMenuBevel(image
);
551 RBevelImage(image
, border
);
554 RConvertImage(rc
, image
, &pixmap
);
555 RDestroyImage(image
);
562 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
564 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
565 Display
*dpy
= WMScreenDisplay(scr
);
568 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
571 str
= GetStringForKey("MenuStyle");
572 if (!str
|| strcasecmp(str
, "normal")==0) {
575 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
577 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*4, WMScreenDepth(scr
));
578 for (i
= 0; i
< 4; i
++) {
579 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
,
582 XFreePixmap(dpy
, tmp
);
583 } else if (strcasecmp(str
, "flat")==0) {
584 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, RBEV_RAISED2
);
586 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, MENU_BEVEL
);
596 updatePreviewBox(_Panel
*panel
, int elements
)
598 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
599 Display
*dpy
= WMScreenDisplay(scr
);
600 /* RContext *rc = WMScreenRContext(scr);*/
605 TextureListItem
*titem
;
607 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
610 if (!panel
->preview
) {
613 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
614 240-4, 215-4, WMScreenDepth(scr
));
616 color
= WMGrayColor(scr
);
617 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
619 WMReleaseColor(color
);
624 if (elements
& FTITLE
) {
625 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
626 titem
= (TextureListItem
*)item
->clientData
;
628 pix
= renderTexture(scr
, titem
->prop
, 190, 20, NULL
, RBEV_RAISED2
);
630 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 10);
632 XFreePixmap(dpy
, pix
);
634 if (elements
& UTITLE
) {
635 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
636 titem
= (TextureListItem
*)item
->clientData
;
638 pix
= renderTexture(scr
, titem
->prop
, 190, 20, NULL
, RBEV_RAISED2
);
640 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 40);
642 XFreePixmap(dpy
, pix
);
644 if (elements
& OTITLE
) {
645 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
646 titem
= (TextureListItem
*)item
->clientData
;
648 pix
= renderTexture(scr
, titem
->prop
, 190, 20, NULL
, RBEV_RAISED2
);
650 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 70);
652 XFreePixmap(dpy
, pix
);
654 if (elements
& RESIZEBAR
) {
655 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
656 titem
= (TextureListItem
*)item
->clientData
;
658 pix
= renderTexture(scr
, titem
->prop
, 190, 9, NULL
, RESIZEBAR_BEVEL
);
660 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 100);
662 XFreePixmap(dpy
, pix
);
664 if (elements
& MTITLE
) {
665 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
666 titem
= (TextureListItem
*)item
->clientData
;
668 pix
= renderTexture(scr
, titem
->prop
, 90, 20, NULL
, RBEV_RAISED2
);
670 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 90, 20, 30, 120);
672 XFreePixmap(dpy
, pix
);
674 if (elements
& MITEM
) {
675 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
676 titem
= (TextureListItem
*)item
->clientData
;
678 pix
= renderMenu(panel
, titem
->prop
, 90, 18);
680 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 90, 18*4, 30, 140);
682 XFreePixmap(dpy
, pix
);
684 if (elements
& (MITEM
|MTITLE
)) {
685 XDrawLine(dpy
, panel
->preview
, gc
, 29, 120, 29, 120+18*4+20);
686 XDrawLine(dpy
, panel
->preview
, gc
, 29, 119, 119, 119);
689 if (elements
& ICON
) {
690 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
691 titem
= (TextureListItem
*)item
->clientData
;
693 pix
= renderTexture(scr
, titem
->prop
, 64, 64, NULL
,
694 titem
->ispixmap
? 0 : RBEV_RAISED3
);
696 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 64, 64, 155, 130);
698 XFreePixmap(dpy
, pix
);
703 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
704 240-4, 215-4, WMScreenDepth(scr
));
706 WMSetLabelImage(panel
->prevL
, p
);
709 WMRedisplayWidget(panel
->prevL
);
719 cancelNewTexture(void *data
)
721 _Panel
*panel
= (_Panel
*)data
;
723 HideTexturePanel(panel
->texturePanel
);
730 makeFileName(char *prefix
)
734 fname
= wstrdup(prefix
);
736 while (access(fname
, F_OK
)==0) {
740 sprintf(buf
, "%08lx.cache", time(NULL
));
741 fname
= wstrappend(prefix
, buf
);
751 okNewTexture(void *data
)
753 _Panel
*panel
= (_Panel
*)data
;
758 TextureListItem
*titem
;
759 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
761 titem
= wmalloc(sizeof(TextureListItem
));
762 memset(titem
, 0, sizeof(TextureListItem
));
764 HideTexturePanel(panel
->texturePanel
);
766 name
= GetTexturePanelTextureName(panel
->texturePanel
);
768 prop
= GetTexturePanelTexture(panel
->texturePanel
);
770 str
= PLGetDescription(prop
);
774 titem
->texture
= str
;
775 titem
->selectedFor
= 0;
777 titem
->ispixmap
= isPixmap(prop
);
779 titem
->path
= makeFileName(panel
->fprefix
);
780 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
783 item
= WMAddListItem(panel
->texLs
, "");
784 item
->clientData
= titem
;
786 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
791 okEditTexture(void *data
)
793 _Panel
*panel
= (_Panel
*)data
;
798 TextureListItem
*titem
;
800 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
801 titem
= (TextureListItem
*)item
->clientData
;
803 HideTexturePanel(panel
->texturePanel
);
805 if (titem
->current
) {
806 name
= GetTexturePanelTextureName(panel
->texturePanel
);
812 prop
= GetTexturePanelTexture(panel
->texturePanel
);
814 str
= PLGetDescription(prop
);
816 PLRelease(titem
->prop
);
819 titem
->ispixmap
= isPixmap(prop
);
821 free(titem
->texture
);
822 titem
->texture
= str
;
824 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
825 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
826 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
829 WMRedisplayWidget(panel
->texLs
);
831 if (titem
->selectedFor
)
832 updatePreviewBox(panel
, titem
->selectedFor
);
834 changePage(panel
->secP
, panel
);
840 editTexture(WMWidget
*w
, void *data
)
842 _Panel
*panel
= (_Panel
*)data
;
844 TextureListItem
*titem
;
846 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
847 titem
= (TextureListItem
*)item
->clientData
;
849 SetTexturePanelPixmapPath(panel
->texturePanel
,
850 GetObjectForKey("PixmapPath"));
852 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
854 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
855 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
857 ShowTexturePanel(panel
->texturePanel
);
863 newTexture(WMWidget
*w
, void *data
)
865 _Panel
*panel
= (_Panel
*)data
;
867 SetTexturePanelPixmapPath(panel
->texturePanel
,
868 GetObjectForKey("PixmapPath"));
870 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
872 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
874 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
876 ShowTexturePanel(panel
->texturePanel
);
882 deleteTexture(WMWidget
*w
, void *data
)
884 _Panel
*panel
= (_Panel
*)data
;
886 TextureListItem
*titem
;
890 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
891 row
= WMGetListSelectedItemRow(panel
->texLs
);
892 item
= WMGetListItem(panel
->texLs
, row
);
893 titem
= (TextureListItem
*)item
->clientData
;
895 if (titem
->selectedFor
& (1 << section
)) {
896 TextureListItem
*titem2
;
898 panel
->textureIndex
[section
] = section
;
899 item
= WMGetListItem(panel
->texLs
, section
);
900 titem2
= (TextureListItem
*)item
->clientData
;
901 titem2
->selectedFor
|= 1 << section
;
905 free(titem
->texture
);
906 PLRelease(titem
->prop
);
908 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
909 wsyserror("could not remove file %s", titem
->path
);
916 WMRemoveListItem(panel
->texLs
, row
);
917 WMSetButtonEnabled(panel
->delB
, False
);
924 extractTexture(WMWidget
*w
, void *data
)
926 _Panel
*panel
= (_Panel
*)data
;
929 WMScreen
*scr
= WMWidgetScreen(w
);
931 opanel
= WMGetOpenPanel(scr
);
932 WMSetFilePanelCanChooseDirectories(opanel
, False
);
933 WMSetFilePanelCanChooseFiles(opanel
, True
);
935 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
936 _("Select File"), NULL
)) {
937 path
= WMGetFilePanelFileName(opanel
);
939 OpenExtractPanelFor(panel
, path
);
947 changePage(WMWidget
*w
, void *data
)
949 _Panel
*panel
= (_Panel
*)data
;
952 TextureListItem
*titem
;
953 WMScreen
*scr
= WMWidgetScreen(w
);
954 RContext
*rc
= WMScreenRContext(scr
);
955 static WMPoint positions
[] = {
965 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
967 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
969 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
971 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
973 titem
= (TextureListItem
*)item
->clientData
;
978 color
= WMGrayColor(scr
);
979 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
980 positions
[panel
->oldsection
].x
,
981 positions
[panel
->oldsection
].y
, 22, 22);
982 WMReleaseColor(color
);
984 panel
->oldsection
= section
;
985 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
986 positions
[section
].y
);
988 WMRedisplayWidget(panel
->prevL
);
994 previewClick(XEvent
*event
, void *clientData
)
996 _Panel
*panel
= (_Panel
*)clientData
;
998 static WMRect parts
[] = {
1004 {{30,140},{90,18*4}},
1008 for (i
= 0; i
< 7; i
++) {
1009 if (event
->xbutton
.x
>= parts
[i
].pos
.x
1010 && event
->xbutton
.y
>= parts
[i
].pos
.y
1011 && event
->xbutton
.x
< parts
[i
].pos
.x
+ parts
[i
].size
.width
1012 && event
->xbutton
.y
< parts
[i
].pos
.y
+ parts
[i
].size
.height
) {
1014 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1015 changePage(panel
->secP
, panel
);
1023 textureClick(WMWidget
*w
, void *data
)
1025 _Panel
*panel
= (_Panel
*)data
;
1028 TextureListItem
*titem
;
1030 i
= WMGetListSelectedItemRow(panel
->texLs
);
1032 item
= WMGetListItem(panel
->texLs
, i
);
1034 titem
= (TextureListItem
*)item
->clientData
;
1036 if (titem
->current
) {
1037 WMSetButtonEnabled(panel
->delB
, False
);
1039 WMSetButtonEnabled(panel
->delB
, True
);
1046 textureDoubleClick(WMWidget
*w
, void *data
)
1048 _Panel
*panel
= (_Panel
*)data
;
1051 TextureListItem
*titem
;
1053 /* unselect old texture */
1054 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1056 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1057 titem
= (TextureListItem
*)item
->clientData
;
1058 titem
->selectedFor
&= ~(1 << section
);
1060 /* select new texture */
1061 i
= WMGetListSelectedItemRow(panel
->texLs
);
1063 item
= WMGetListItem(panel
->texLs
, i
);
1065 titem
= (TextureListItem
*)item
->clientData
;
1067 titem
->selectedFor
|= 1<<section
;
1069 panel
->textureIndex
[section
] = i
;
1071 WMRedisplayWidget(panel
->texLs
);
1073 updatePreviewBox(panel
, 1<<section
);
1080 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
1083 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
1084 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1085 int width
, height
, x
, y
;
1086 Display
*dpy
= WMScreenDisplay(scr
);
1087 WMColor
*white
= WMWhiteColor(scr
);
1089 WMColor
*black
= WMBlackColor(scr
);
1090 TextureListItem
*titem
;
1092 width
= rect
->size
.width
;
1093 height
= rect
->size
.height
;
1097 if (state
& WLDSSelected
)
1098 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1100 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
1102 item
= WMGetListItem(lPtr
, index
);
1103 titem
= (TextureListItem
*)item
->clientData
;
1106 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0, TEXPREV_WIDTH
,
1107 TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1109 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1110 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1111 else if (titem
->selectedFor
)
1112 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1114 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
1115 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
1116 strlen(titem
->title
));
1118 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
1119 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
1120 strlen(titem
->texture
));
1123 WMReleaseColor(white
);
1124 WMReleaseColor(black
);
1130 loadRImage(WMScreen
*scr
, char *path
)
1138 f
= fopen(path
, "r");
1142 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1144 image
= RCreateImage(w
, h
, d
== 4);
1145 for (i
= 0; i
< d
; i
++) {
1146 fread(image
->data
[i
], 1, w
*h
, f
);
1150 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1151 RDestroyImage(image
);
1159 fillTextureList(WMList
*lPtr
)
1161 proplist_t textureList
;
1163 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1165 TextureListItem
*titem
;
1166 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1168 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1172 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1175 texture
= PLGetArrayElement(textureList
, i
);
1177 titem
= wmalloc(sizeof(TextureListItem
));
1178 memset(titem
, 0, sizeof(TextureListItem
));
1180 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1181 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1182 titem
->texture
= PLGetDescription(titem
->prop
);
1183 titem
->selectedFor
= 0;
1184 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1186 titem
->preview
= loadRImage(scr
, titem
->path
);
1187 if (!titem
->preview
) {
1188 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1189 TEXPREV_HEIGHT
, NULL
, 0);
1191 item
= WMAddListItem(lPtr
, "");
1192 item
->clientData
= titem
;
1198 createPanel(Panel
*p
)
1200 _Panel
*panel
= (_Panel
*)p
;
1202 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1203 WMTabViewItem
*item
;
1208 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
1210 if (access(panel
->fprefix
, F_OK
)!=0) {
1211 if (mkdir(panel
->fprefix
, 0755) < 0) {
1212 wsyserror(panel
->fprefix
);
1217 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
1218 free(panel
->fprefix
);
1219 panel
->fprefix
= tmp
;
1220 if (access(panel
->fprefix
, F_OK
)!=0) {
1221 if (mkdir(panel
->fprefix
, 0755) < 0) {
1222 wsyserror(panel
->fprefix
);
1227 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1228 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1229 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1231 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1232 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1233 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1235 panel
->frame
= WMCreateFrame(panel
->win
);
1236 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1237 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1240 panel
->prevL
= WMCreateLabel(panel
->frame
);
1241 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1242 WMMoveWidget(panel
->prevL
, 15, 10);
1243 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1244 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1246 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1247 previewClick
, panel
);
1252 panel
->tabv
= WMCreateTabView(panel
->frame
);
1253 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1254 WMMoveWidget(panel
->tabv
, 265, 10);
1256 /*** texture list ***/
1258 panel
->texF
= WMCreateFrame(panel
->frame
);
1259 WMSetFrameRelief(panel
->texF
, WRFlat
);
1261 item
= WMCreateTabViewItemWithIdentifier(0);
1262 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1263 WMSetTabViewItemLabel(item
, _("Texture"));
1265 WMAddItemInTabView(panel
->tabv
, item
);
1268 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1269 WMResizeWidget(panel
->secP
, 228, 20);
1270 WMMoveWidget(panel
->secP
, 7, 7);
1271 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1272 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1273 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1274 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1275 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1276 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1277 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1278 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1279 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1281 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1283 panel
->texLs
= WMCreateList(panel
->texF
);
1284 WMResizeWidget(panel
->texLs
, 165, 155);
1285 WMMoveWidget(panel
->texLs
, 70, 33);
1286 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1287 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1288 WMHangData(panel
->texLs
, panel
);
1289 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1290 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1292 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1293 "for the selected item."),
1294 WMWidgetView(panel
->texLs
));
1296 /* command buttons */
1298 font
= WMSystemFontOfSize(scr
, 10);
1301 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1302 WMResizeWidget(panel
->newB
, 57, 39);
1303 WMMoveWidget(panel
->newB
, 7, 33);
1304 WMSetButtonFont(panel
->newB
, font
);
1305 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1306 WMSetButtonText(panel
->newB
, _("New"));
1307 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1308 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1310 WMSetBalloonTextForView(_("Create a new texture."),
1311 WMWidgetView(panel
->newB
));
1313 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1314 WMResizeWidget(panel
->ripB
, 57, 39);
1315 WMMoveWidget(panel
->ripB
, 7, 72);
1316 WMSetButtonFont(panel
->ripB
, font
);
1317 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1318 WMSetButtonText(panel
->ripB
, _("Extract..."));
1319 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1320 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1322 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1323 WMWidgetView(panel
->ripB
));
1325 WMSetButtonEnabled(panel
->ripB
, False
);
1327 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1328 WMResizeWidget(panel
->editB
, 57, 39);
1329 WMMoveWidget(panel
->editB
, 7, 111);
1330 WMSetButtonFont(panel
->editB
, font
);
1331 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1332 WMSetButtonText(panel
->editB
, _("Edit"));
1333 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1334 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1335 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1336 WMWidgetView(panel
->editB
));
1338 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1339 WMResizeWidget(panel
->delB
, 57, 38);
1340 WMMoveWidget(panel
->delB
, 7, 150);
1341 WMSetButtonFont(panel
->delB
, font
);
1342 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1343 WMSetButtonText(panel
->delB
, _("Delete"));
1344 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1345 WMSetButtonEnabled(panel
->delB
, False
);
1346 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1347 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1348 WMWidgetView(panel
->delB
));
1350 WMReleaseFont(font
);
1352 WMMapSubwidgets(panel
->texF
);
1355 panel
->colF
= WMCreateFrame(panel
->frame
);
1356 WMSetFrameRelief(panel
->colF
, WRFlat
);
1358 item
= WMCreateTabViewItemWithIdentifier(1);
1359 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1360 WMSetTabViewItemLabel(item
, _("Color"));
1362 WMAddItemInTabView(panel
->tabv
, item
);
1367 WMRealizeWidget(panel
->frame
);
1368 WMMapSubwidgets(panel
->frame
);
1370 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1374 changePage(panel
->secP
, panel
);
1376 fillTextureList(panel
->texLs
);
1378 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1384 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1388 TextureListItem
*titem
;
1390 titem
= wmalloc(sizeof(TextureListItem
));
1391 memset(titem
, 0, sizeof(TextureListItem
));
1393 titem
->title
= wstrdup(title
);
1394 titem
->prop
= GetObjectForKey(key
);
1396 titem
->prop
= PLGetProplistWithDescription(defValue
);
1398 PLRetain(titem
->prop
);
1400 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1402 titem
->selectedFor
= 1<<index
;
1404 titem
->ispixmap
= isPixmap(titem
->prop
);
1406 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1407 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1409 item
= WMAddListItem(list
, "");
1410 item
->clientData
= titem
;
1416 showData(_Panel
*panel
)
1420 setupTextureFor(panel
->texLs
, "FTitleBack", "(solid, black)",
1422 panel
->textureIndex
[i
] = i
++;
1424 setupTextureFor(panel
->texLs
, "UTitleBack", "(solid, gray)",
1426 panel
->textureIndex
[i
] = i
++;
1428 setupTextureFor(panel
->texLs
, "PTitleBack", "(solid, \"#616161\")",
1429 "[Owner of Focused]", i
);
1430 panel
->textureIndex
[i
] = i
++;
1432 setupTextureFor(panel
->texLs
, "ResizebarBack", "(solid, gray)",
1434 panel
->textureIndex
[i
] = i
++;
1436 setupTextureFor(panel
->texLs
, "MenuTitleBack", "(solid, black)",
1438 panel
->textureIndex
[i
] = i
++;
1440 setupTextureFor(panel
->texLs
, "MenuTextBack", "(solid, gray)",
1442 panel
->textureIndex
[i
] = i
++;
1444 setupTextureFor(panel
->texLs
, "IconBack", "(solid, gray)", "[Icon]", i
);
1445 panel
->textureIndex
[i
] = i
++;
1447 setupTextureFor(panel->texLs, "WorkspaceBack", "(solid, black)",
1449 panel->textureIndex[i] = i++;
1452 updatePreviewBox(panel
, EVERYTHING
);
1458 storeData(_Panel
*panel
)
1460 TextureListItem
*titem
;
1463 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
1464 titem
= (TextureListItem
*)item
->clientData
;
1465 SetObjectForKey(titem
->prop
, "FTitleBack");
1467 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
1468 titem
= (TextureListItem
*)item
->clientData
;
1469 SetObjectForKey(titem
->prop
, "UTitleBack");
1471 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
1472 titem
= (TextureListItem
*)item
->clientData
;
1473 SetObjectForKey(titem
->prop
, "PTitleBack");
1475 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
1476 titem
= (TextureListItem
*)item
->clientData
;
1477 SetObjectForKey(titem
->prop
, "ResizebarBack");
1479 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
1480 titem
= (TextureListItem
*)item
->clientData
;
1481 SetObjectForKey(titem
->prop
, "MenuTitleBack");
1483 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
1484 titem
= (TextureListItem
*)item
->clientData
;
1485 SetObjectForKey(titem
->prop
, "MenuTextBack");
1487 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
1488 titem
= (TextureListItem
*)item
->clientData
;
1489 SetObjectForKey(titem
->prop
, "IconBack");
1494 prepareForClose(_Panel
*panel
)
1496 proplist_t textureList
;
1499 TextureListItem
*titem
;
1501 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1503 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
1505 /* store list of textures */
1506 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
1507 item
= WMGetListItem(panel
->texLs
, i
);
1508 titem
= (TextureListItem
*)item
->clientData
;
1510 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
1511 PLRetain(titem
->prop
),
1512 PLMakeString(titem
->path
),
1515 PLAppendArrayElement(textureList
, texture
);
1518 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
1519 PLRelease(textureList
);
1521 WMSynchronizeUserDefaults(udb
);
1527 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
1531 panel
= wmalloc(sizeof(_Panel
));
1532 memset(panel
, 0, sizeof(_Panel
));
1534 panel
->sectionName
= _("Appearance Preferences");
1536 panel
->description
= _("Background texture configuration for windows,\n"
1537 "menus and icons.");
1541 panel
->callbacks
.createWidgets
= createPanel
;
1542 panel
->callbacks
.updateDomain
= storeData
;
1543 panel
->callbacks
.prepareForClose
= prepareForClose
;
1545 AddSection(panel
, ICON_FILE
);
1552 /****************************************************************************/
1556 typedef struct ExtractPanel
{
1569 OpenExtractPanelFor(_Panel
*panel
, char *path
)
1571 ExtractPanel
*epanel
;
1574 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1576 epanel
= wmalloc(sizeof(ExtractPanel
));
1577 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
1579 |WMClosableWindowMask
);
1580 WMResizeWidget(epanel
->win
, 245, 250);
1581 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
1583 epanel
->label
= WMCreateLabel(epanel
->win
);
1584 WMResizeWidget(epanel
->label
, 225, 18);
1585 WMMoveWidget(epanel
->label
, 10, 10);
1586 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
1587 WMSetLabelRelief(epanel
->label
, WRSunken
);
1589 color
= WMDarkGrayColor(scr
);
1590 WMSetWidgetBackgroundColor(epanel
->label
, color
);
1591 WMReleaseColor(color
);
1593 color
= WMWhiteColor(scr
);
1594 WMSetLabelTextColor(epanel
->label
, color
);
1595 WMReleaseColor(color
);
1597 font
= WMBoldSystemFontOfSize(scr
, 12);
1598 WMSetLabelFont(epanel
->label
, font
);
1599 WMReleaseFont(font
);
1601 WMSetLabelText(epanel
->label
, _("Textures"));
1603 epanel
->list
= WMCreateList(epanel
->win
);
1604 WMResizeWidget(epanel
->list
, 225, 165);
1605 WMMoveWidget(epanel
->list
, 10, 30);
1609 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
1610 WMResizeWidget(epanel
->closeB
, 74, 24);
1611 WMMoveWidget(epanel
->closeB
, 165, 215);
1612 WMSetButtonText(epanel
->closeB
, _("Close"));
1614 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
1615 WMResizeWidget(epanel
->extrB
, 74, 24);
1616 WMMoveWidget(epanel
->extrB
, 80, 215);
1617 WMSetButtonText(epanel
->extrB
, _("Extract"));
1619 WMMapSubwidgets(epanel
->win
);
1622 /* take textures from file */
1626 WMRealizeWidget(epanel
->win
);
1628 WMMapWidget(epanel
->win
);