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
;
76 TexturePanel
*texturePanel
;
104 static void showData(_Panel
*panel
);
106 static void changePage(WMWidget
*w
, void *data
);
108 static void OpenExtractPanelFor(_Panel
*panel
, char *path
);
110 #define ICON_FILE "appearance"
112 #define TNEW_FILE "tnew"
113 #define TDEL_FILE "tdel"
114 #define TEDIT_FILE "tedit"
115 #define TEXTR_FILE "textr"
120 static char * blueled_xpm
[] = {
150 static char *blueled2_xpm
[] = {
151 /* width height num_colors chars_per_pixel */
183 static char * hand_xpm
[] = {
205 " .))),%.......... ",
206 " .)-)),&)))))))))$. ",
207 " .-&))))))))),,,,;;. ",
208 " .=)))))))));-=***&$. ",
209 " .=)))))))),..+..... ",
227 #define FTITLE (1<<0)
228 #define UTITLE (1<<1)
229 #define OTITLE (1<<2)
230 #define RESIZEBAR (1<<3)
231 #define MTITLE (1<<4)
235 #define EVERYTHING 0xff
238 #define RESIZEBAR_BEVEL -1
239 #define MENU_BEVEL -2
241 #define TEXPREV_WIDTH 40
242 #define TEXPREV_HEIGHT 24
249 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
253 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
256 color
->red
= xcolor
.red
>> 8;
257 color
->green
= xcolor
.green
>> 8;
258 color
->blue
= xcolor
.blue
>> 8;
264 dumpRImage(char *path
, RImage
*image
)
268 f
= fopen(path
, "w");
273 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
,
274 image
->data
[3]!=NULL
? 4 : 3);
276 fwrite(image
->data
[0], 1, image
->width
* image
->height
, f
);
277 fwrite(image
->data
[1], 1, image
->width
* image
->height
, f
);
278 fwrite(image
->data
[2], 1, image
->width
* image
->height
, f
);
280 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
290 isPixmap(proplist_t prop
)
295 p
= PLGetArrayElement(prop
, 0);
297 if (strcasecmp(&s
[1], "pixmap")==0)
305 drawResizebarBevel(RImage
*img
)
310 int width
= img
->width
;
311 int height
= img
->height
;
315 black
.red
= black
.green
= black
.blue
= 0;
318 light
.red
= light
.green
= light
.blue
= 80;
321 dark
.red
= dark
.green
= dark
.blue
= 40;
323 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
324 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
326 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
327 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
329 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
331 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
334 RDrawLine(img
, 0, height
-1, width
-1, height
-1, &black
);
335 RDrawLine(img
, 0, 0, 0, height
-1, &black
);
336 RDrawLine(img
, width
-1, 0, width
-1, height
-1, &black
);
341 drawMenuBevel(RImage
*img
)
343 RColor light
, dark
, mid
;
345 int iheight
= img
->height
/ 3;
348 light
.red
= light
.green
= light
.blue
= 80;
351 dark
.red
= dark
.green
= dark
.blue
= 0;
354 mid
.red
= mid
.green
= mid
.blue
= 40;
356 for (i
= 1; i
< 3; i
++) {
357 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
358 img
->width
-1, i
*iheight
-2, &mid
);
360 RDrawLine(img
, 0, i
*iheight
-1,
361 img
->width
-1, i
*iheight
-1, &dark
);
363 ROperateLine(img
, RAddOperation
, 0, i
*iheight
,
364 img
->width
-1, i
*iheight
, &light
);
370 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
371 char *path
, int border
)
376 RContext
*rc
= WMScreenRContext(scr
);
381 type
= PLGetString(PLGetArrayElement(texture
, 0));
383 image
= RCreateImage(width
, height
, False
);
385 if (strcasecmp(type
, "solid")==0) {
387 str
= PLGetString(PLGetArrayElement(texture
, 1));
389 str2rcolor(rc
, str
, &rcolor
);
391 RClearImage(image
, &rcolor
);
392 } else if (strcasecmp(&type
[1], "gradient")==0) {
396 switch (toupper(type
[0])) {
398 style
= RVerticalGradient
;
401 style
= RHorizontalGradient
;
405 style
= RDiagonalGradient
;
409 str
= PLGetString(PLGetArrayElement(texture
, 1));
410 str2rcolor(rc
, str
, &rcolor
);
411 str
= PLGetString(PLGetArrayElement(texture
, 2));
412 str2rcolor(rc
, str
, &rcolor2
);
414 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
415 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
419 RImage
*grad
, *timage
;
422 switch (toupper(type
[1])) {
424 style
= RVerticalGradient
;
427 style
= RHorizontalGradient
;
431 style
= RDiagonalGradient
;
435 str
= PLGetString(PLGetArrayElement(texture
, 3));
436 str2rcolor(rc
, str
, &rcolor
);
437 str
= PLGetString(PLGetArrayElement(texture
, 4));
438 str2rcolor(rc
, str
, &rcolor2
);
440 str
= PLGetString(PLGetArrayElement(texture
, 1));
442 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
443 timage
= RLoadImage(rc
, path
, 0);
446 wwarning("could not load file '%s': %s", path
,
447 RMessageForError(RErrorCode
));
449 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
451 image
= RMakeTiledImage(timage
, width
, height
);
452 RDestroyImage(timage
);
454 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
456 RCombineImagesWithOpaqueness(image
, grad
, i
);
459 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
464 switch (toupper(type
[1])) {
466 style
= RVerticalGradient
;
469 style
= RHorizontalGradient
;
473 style
= RDiagonalGradient
;
477 j
= PLGetNumberOfElements(texture
);
480 colors
= wmalloc(j
* sizeof(RColor
*));
482 for (i
= 2; i
< j
; i
++) {
483 str
= PLGetString(PLGetArrayElement(texture
, i
));
484 colors
[i
-2] = wmalloc(sizeof(RColor
));
485 str2rcolor(rc
, str
, colors
[i
-2]);
489 image
= RRenderMultiGradient(width
, height
, colors
, style
);
491 for (i
= 0; colors
[i
]!=NULL
; i
++)
495 } else if (strcasecmp(&type
[1], "pixmap")==0) {
496 RImage
*timage
= NULL
;
500 str
= PLGetString(PLGetArrayElement(texture
, 1));
502 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
504 timage
= RLoadImage(rc
, path
, 0);
507 wwarning("could not load file '%s': %s", path
? path
: str
,
508 RMessageForError(RErrorCode
));
510 str
= PLGetString(PLGetArrayElement(texture
, 2));
511 str2rcolor(rc
, str
, &color
);
513 switch (toupper(type
[0])) {
515 image
= RMakeTiledImage(timage
, width
, height
);
516 RDestroyImage(timage
);
520 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
521 RDestroyImage(timage
);
526 image
= RScaleImage(timage
, width
, height
);
527 RDestroyImage(timage
);
540 dumpRImage(path
, image
);
544 if (border
== RESIZEBAR_BEVEL
) {
545 drawResizebarBevel(image
);
546 } else if (border
== MENU_BEVEL
) {
547 drawMenuBevel(image
);
550 RBevelImage(image
, border
);
553 RConvertImage(rc
, image
, &pixmap
);
554 RDestroyImage(image
);
561 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
563 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
564 Display
*dpy
= WMScreenDisplay(scr
);
567 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
570 str
= GetStringForKey("MenuStyle");
571 if (!str
|| strcasecmp(str
, "normal")==0) {
574 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
576 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*3,
578 for (i
= 0; i
< 3; 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
*3, NULL
, RBEV_RAISED2
);
586 pix
= renderTexture(scr
, texture
, width
, iheight
*3, 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, 165-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, 5);
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, 30);
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, 55);
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, 80);
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, 95);
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*3, 30, 115);
682 XFreePixmap(dpy
, pix
);
684 if (elements
& (MITEM
|MTITLE
)) {
685 XDrawLine(dpy
, panel
->preview
, gc
, 29, 95, 29, 115+36+20);
686 XDrawLine(dpy
, panel
->preview
, gc
, 29, 94, 119, 94);
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, 95);
698 XFreePixmap(dpy
, pix
);
704 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
705 240-4, 165-4, WMScreenDepth(scr
));
707 WMSetLabelImage(panel
->prevL
, p
);
710 WMRedisplayWidget(panel
->prevL
);
720 cancelNewTexture(void *data
)
722 _Panel
*panel
= (_Panel
*)data
;
724 HideTexturePanel(panel
->texturePanel
);
731 makeFileName(char *prefix
)
735 fname
= wstrdup(prefix
);
737 while (access(fname
, F_OK
)==0) {
741 sprintf(buf
, "%08lx.cache", time(NULL
));
742 fname
= wstrappend(prefix
, buf
);
752 okNewTexture(void *data
)
754 _Panel
*panel
= (_Panel
*)data
;
759 TextureListItem
*titem
;
760 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
762 titem
= wmalloc(sizeof(TextureListItem
));
763 memset(titem
, 0, sizeof(TextureListItem
));
765 HideTexturePanel(panel
->texturePanel
);
767 name
= GetTexturePanelTextureName(panel
->texturePanel
);
769 prop
= GetTexturePanelTexture(panel
->texturePanel
);
771 str
= PLGetDescription(prop
);
775 titem
->texture
= str
;
776 titem
->selectedFor
= 0;
778 titem
->ispixmap
= isPixmap(prop
);
780 titem
->path
= makeFileName(panel
->fprefix
);
781 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
784 item
= WMAddListItem(panel
->texLs
, "");
785 item
->clientData
= titem
;
787 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
792 okEditTexture(void *data
)
794 _Panel
*panel
= (_Panel
*)data
;
799 TextureListItem
*titem
;
801 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
802 titem
= (TextureListItem
*)item
->clientData
;
804 HideTexturePanel(panel
->texturePanel
);
806 if (titem
->current
) {
807 name
= GetTexturePanelTextureName(panel
->texturePanel
);
813 prop
= GetTexturePanelTexture(panel
->texturePanel
);
815 str
= PLGetDescription(prop
);
817 PLRelease(titem
->prop
);
820 titem
->ispixmap
= isPixmap(prop
);
822 free(titem
->texture
);
823 titem
->texture
= str
;
825 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
826 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
827 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
830 WMRedisplayWidget(panel
->texLs
);
832 if (titem
->selectedFor
)
833 updatePreviewBox(panel
, titem
->selectedFor
);
835 changePage(panel
->secP
, panel
);
841 editTexture(WMWidget
*w
, void *data
)
843 _Panel
*panel
= (_Panel
*)data
;
845 TextureListItem
*titem
;
847 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
848 titem
= (TextureListItem
*)item
->clientData
;
850 SetTexturePanelPixmapPath(panel
->texturePanel
,
851 GetObjectForKey("PixmapPath"));
853 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
855 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
856 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
858 ShowTexturePanel(panel
->texturePanel
);
864 newTexture(WMWidget
*w
, void *data
)
866 _Panel
*panel
= (_Panel
*)data
;
868 SetTexturePanelPixmapPath(panel
->texturePanel
,
869 GetObjectForKey("PixmapPath"));
871 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
873 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
875 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
877 ShowTexturePanel(panel
->texturePanel
);
883 deleteTexture(WMWidget
*w
, void *data
)
885 _Panel
*panel
= (_Panel
*)data
;
887 TextureListItem
*titem
;
891 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
892 row
= WMGetListSelectedItemRow(panel
->texLs
);
893 item
= WMGetListItem(panel
->texLs
, row
);
894 titem
= (TextureListItem
*)item
->clientData
;
896 if (titem
->selectedFor
& (1 << section
)) {
897 TextureListItem
*titem2
;
899 panel
->textureIndex
[section
] = section
;
900 item
= WMGetListItem(panel
->texLs
, section
);
901 titem2
= (TextureListItem
*)item
->clientData
;
902 titem2
->selectedFor
|= 1 << section
;
906 free(titem
->texture
);
907 PLRelease(titem
->prop
);
909 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
910 wsyserror("could not remove file %s", titem
->path
);
917 WMRemoveListItem(panel
->texLs
, row
);
918 WMSetButtonEnabled(panel
->delB
, False
);
925 extractTexture(WMWidget
*w
, void *data
)
927 _Panel
*panel
= (_Panel
*)data
;
930 WMScreen
*scr
= WMWidgetScreen(w
);
932 opanel
= WMGetOpenPanel(scr
);
933 WMSetFilePanelCanChooseDirectories(opanel
, False
);
934 WMSetFilePanelCanChooseFiles(opanel
, True
);
936 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
937 _("Select File"), NULL
)) {
938 path
= WMGetFilePanelFileName(opanel
);
940 OpenExtractPanelFor(panel
, path
);
948 changePage(WMWidget
*w
, void *data
)
950 _Panel
*panel
= (_Panel
*)data
;
953 TextureListItem
*titem
;
954 WMScreen
*scr
= WMWidgetScreen(w
);
955 RContext
*rc
= WMScreenRContext(scr
);
956 static WMPoint positions
[] = {
966 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
968 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
970 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
972 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
974 titem
= (TextureListItem
*)item
->clientData
;
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},{190, 20}},
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
;
1054 /* unselect old texture */
1055 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1057 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1058 titem
= (TextureListItem
*)item
->clientData
;
1059 titem
->selectedFor
&= ~(1 << section
);
1061 /* select new texture */
1062 i
= WMGetListSelectedItemRow(panel
->texLs
);
1064 item
= WMGetListItem(panel
->texLs
, i
);
1066 titem
= (TextureListItem
*)item
->clientData
;
1068 titem
->selectedFor
|= 1<<section
;
1070 panel
->textureIndex
[section
] = i
;
1072 WMRedisplayWidget(panel
->texLs
);
1074 updatePreviewBox(panel
, 1<<section
);
1081 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
1084 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
1085 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1086 int width
, height
, x
, y
;
1087 Display
*dpy
= WMScreenDisplay(scr
);
1088 WMColor
*white
= WMWhiteColor(scr
);
1090 WMColor
*black
= WMBlackColor(scr
);
1091 TextureListItem
*titem
;
1093 width
= rect
->size
.width
;
1094 height
= rect
->size
.height
;
1098 if (state
& WLDSSelected
)
1099 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1101 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
1103 item
= WMGetListItem(lPtr
, index
);
1104 titem
= (TextureListItem
*)item
->clientData
;
1107 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0, TEXPREV_WIDTH
,
1108 TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1110 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1111 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1112 else if (titem
->selectedFor
)
1113 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1115 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
1116 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
1117 strlen(titem
->title
));
1119 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
1120 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
1121 strlen(titem
->texture
));
1124 WMReleaseColor(white
);
1125 WMReleaseColor(black
);
1131 loadRImage(WMScreen
*scr
, char *path
)
1139 f
= fopen(path
, "r");
1143 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1145 image
= RCreateImage(w
, h
, d
== 4);
1146 for (i
= 0; i
< d
; i
++) {
1147 fread(image
->data
[i
], 1, w
*h
, f
);
1151 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1152 RDestroyImage(image
);
1160 fillTextureList(WMList
*lPtr
)
1162 proplist_t textureList
;
1164 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1166 TextureListItem
*titem
;
1167 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1169 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1173 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1176 texture
= PLGetArrayElement(textureList
, i
);
1178 titem
= wmalloc(sizeof(TextureListItem
));
1179 memset(titem
, 0, sizeof(TextureListItem
));
1181 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1182 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1183 titem
->texture
= PLGetDescription(titem
->prop
);
1184 titem
->selectedFor
= 0;
1185 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1187 titem
->preview
= loadRImage(scr
, titem
->path
);
1188 if (!titem
->preview
) {
1189 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1190 TEXPREV_HEIGHT
, NULL
, 0);
1192 item
= WMAddListItem(lPtr
, "");
1193 item
->clientData
= titem
;
1199 createPanel(Panel
*p
)
1201 _Panel
*panel
= (_Panel
*)p
;
1203 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1204 WMTabViewItem
*item
;
1209 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
1211 if (access(panel
->fprefix
, F_OK
)!=0) {
1212 if (mkdir(panel
->fprefix
, 0755) < 0) {
1213 wsyserror(panel
->fprefix
);
1218 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
1219 free(panel
->fprefix
);
1220 panel
->fprefix
= tmp
;
1221 if (access(panel
->fprefix
, F_OK
)!=0) {
1222 if (mkdir(panel
->fprefix
, 0755) < 0) {
1223 wsyserror(panel
->fprefix
);
1228 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1229 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1230 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1232 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1233 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1234 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1236 panel
->frame
= WMCreateFrame(panel
->win
);
1237 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1238 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1241 panel
->prevL
= WMCreateLabel(panel
->frame
);
1242 WMResizeWidget(panel
->prevL
, 240, 165);
1243 WMMoveWidget(panel
->prevL
, 15, 10);
1244 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1245 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1247 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1248 previewClick
, panel
);
1251 panel
->secP
= WMCreatePopUpButton(panel
->frame
);
1252 WMResizeWidget(panel
->secP
, 240, 20);
1253 WMMoveWidget(panel
->secP
, 15, 180);
1254 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1255 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1256 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1257 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1258 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1259 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1260 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1261 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1262 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1264 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1269 panel
->tabv
= WMCreateTabView(panel
->frame
);
1270 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1271 WMMoveWidget(panel
->tabv
, 265, 10);
1273 /*** texture list ***/
1275 panel
->texF
= WMCreateFrame(panel
->frame
);
1276 WMSetFrameRelief(panel
->texF
, WRFlat
);
1278 item
= WMCreateTabViewItemWithIdentifier(0);
1279 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1280 WMSetTabViewItemLabel(item
, _("Texture"));
1282 WMAddItemInTabView(panel
->tabv
, item
);
1284 panel
->texLs
= WMCreateList(panel
->texF
);
1285 WMResizeWidget(panel
->texLs
, 232, 130);
1286 WMMoveWidget(panel
->texLs
, 5, 5);
1287 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1288 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1289 WMHangData(panel
->texLs
, panel
);
1290 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1291 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1293 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1294 "for the selected item."),
1295 WMWidgetView(panel
->texLs
));
1297 /* command buttons */
1299 font
= WMSystemFontOfSize(scr
, 10);
1302 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1303 WMResizeWidget(panel
->newB
, 57, 48);
1304 WMMoveWidget(panel
->newB
, 5, 142);
1305 WMSetButtonFont(panel
->newB
, font
);
1306 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1307 WMSetButtonText(panel
->newB
, _("New"));
1308 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1309 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1311 WMSetBalloonTextForView(_("Create a new texture."),
1312 WMWidgetView(panel
->newB
));
1314 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1315 WMResizeWidget(panel
->ripB
, 57, 48);
1316 WMMoveWidget(panel
->ripB
, 63, 142);
1317 WMSetButtonFont(panel
->ripB
, font
);
1318 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1319 WMSetButtonText(panel
->ripB
, _("Extract..."));
1320 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1321 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1323 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1324 WMWidgetView(panel
->ripB
));
1326 WMSetButtonEnabled(panel
->ripB
, False
);
1328 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1329 WMResizeWidget(panel
->editB
, 57, 48);
1330 WMMoveWidget(panel
->editB
, 121, 142);
1331 WMSetButtonFont(panel
->editB
, font
);
1332 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1333 WMSetButtonText(panel
->editB
, _("Edit"));
1334 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1335 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1336 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1337 WMWidgetView(panel
->editB
));
1339 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1340 WMResizeWidget(panel
->delB
, 57, 48);
1341 WMMoveWidget(panel
->delB
, 179, 142);
1342 WMSetButtonFont(panel
->delB
, font
);
1343 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1344 WMSetButtonText(panel
->delB
, _("Delete"));
1345 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1346 WMSetButtonEnabled(panel
->delB
, False
);
1347 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1348 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1349 WMWidgetView(panel
->delB
));
1351 WMReleaseFont(font
);
1353 WMMapSubwidgets(panel
->texF
);
1356 panel
->colF
= WMCreateFrame(panel
->frame
);
1357 WMSetFrameRelief(panel
->colF
, WRFlat
);
1359 item
= WMCreateTabViewItemWithIdentifier(1);
1360 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1361 WMSetTabViewItemLabel(item
, _("Color"));
1363 WMAddItemInTabView(panel
->tabv
, item
);
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
);