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
{
44 CallbackRec callbacks
;
68 TexturePanel
*texturePanel
;
96 static void showData(_Panel
*panel
);
99 static void OpenExtractPanelFor(_Panel
*panel
, char *path
);
101 #define ICON_FILE "appearance"
103 #define TNEW_FILE "tnew"
104 #define TDEL_FILE "tdel"
105 #define TEDIT_FILE "tedit"
106 #define TEXTR_FILE "textr"
111 static char * blueled_xpm
[] = {
141 static char *blueled2_xpm
[] = {
142 /* width height num_colors chars_per_pixel */
174 static char * hand_xpm
[] = {
196 " .))),%.......... ",
197 " .)-)),&)))))))))$. ",
198 " .-&))))))))),,,,;;. ",
199 " .=)))))))));-=***&$. ",
200 " .=)))))))),..+..... ",
218 #define FTITLE (1<<0)
219 #define UTITLE (1<<1)
220 #define OTITLE (1<<2)
221 #define RESIZEBAR (1<<3)
222 #define MTITLE (1<<4)
226 #define EVERYTHING 0xff
229 #define RESIZEBAR_BEVEL -1
230 #define MENU_BEVEL -2
232 #define TEXPREV_WIDTH 40
233 #define TEXPREV_HEIGHT 24
240 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
244 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
247 color
->red
= xcolor
.red
>> 8;
248 color
->green
= xcolor
.green
>> 8;
249 color
->blue
= xcolor
.blue
>> 8;
255 dumpRImage(char *path
, RImage
*image
)
259 f
= fopen(path
, "w");
264 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
,
265 image
->data
[3]!=NULL
? 4 : 3);
267 fwrite(image
->data
[0], 1, image
->width
* image
->height
, f
);
268 fwrite(image
->data
[1], 1, image
->width
* image
->height
, f
);
269 fwrite(image
->data
[2], 1, image
->width
* image
->height
, f
);
271 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
281 isPixmap(proplist_t prop
)
286 p
= PLGetArrayElement(prop
, 0);
288 if (strcasecmp(&s
[1], "pixmap")==0)
296 drawResizebarBevel(RImage
*img
)
301 int width
= img
->width
;
302 int height
= img
->height
;
306 black
.red
= black
.green
= black
.blue
= 0;
309 light
.red
= light
.green
= light
.blue
= 80;
312 dark
.red
= dark
.green
= dark
.blue
= 40;
314 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
315 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
317 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
318 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
320 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
322 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
325 RDrawLine(img
, 0, height
-1, width
-1, height
-1, &black
);
326 RDrawLine(img
, 0, 0, 0, height
-1, &black
);
327 RDrawLine(img
, width
-1, 0, width
-1, height
-1, &black
);
332 drawMenuBevel(RImage
*img
)
334 RColor light
, dark
, mid
;
336 int iheight
= img
->height
/ 3;
339 light
.red
= light
.green
= light
.blue
= 80;
342 dark
.red
= dark
.green
= dark
.blue
= 0;
345 mid
.red
= mid
.green
= mid
.blue
= 40;
347 for (i
= 1; i
< 3; i
++) {
348 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
349 img
->width
-1, i
*iheight
-2, &mid
);
351 RDrawLine(img
, 0, i
*iheight
-1,
352 img
->width
-1, i
*iheight
-1, &dark
);
354 ROperateLine(img
, RAddOperation
, 0, i
*iheight
,
355 img
->width
-1, i
*iheight
, &light
);
361 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
362 char *path
, int border
)
367 RContext
*rc
= WMScreenRContext(scr
);
372 type
= PLGetString(PLGetArrayElement(texture
, 0));
374 image
= RCreateImage(width
, height
, False
);
376 if (strcasecmp(type
, "solid")==0) {
378 str
= PLGetString(PLGetArrayElement(texture
, 1));
380 str2rcolor(rc
, str
, &rcolor
);
382 RClearImage(image
, &rcolor
);
383 } else if (strcasecmp(&type
[1], "gradient")==0) {
387 switch (toupper(type
[0])) {
389 style
= RVerticalGradient
;
392 style
= RHorizontalGradient
;
396 style
= RDiagonalGradient
;
400 str
= PLGetString(PLGetArrayElement(texture
, 1));
401 str2rcolor(rc
, str
, &rcolor
);
402 str
= PLGetString(PLGetArrayElement(texture
, 2));
403 str2rcolor(rc
, str
, &rcolor2
);
405 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
406 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
410 RImage
*grad
, *timage
;
413 switch (toupper(type
[1])) {
415 style
= RVerticalGradient
;
418 style
= RHorizontalGradient
;
422 style
= RDiagonalGradient
;
426 str
= PLGetString(PLGetArrayElement(texture
, 3));
427 str2rcolor(rc
, str
, &rcolor
);
428 str
= PLGetString(PLGetArrayElement(texture
, 4));
429 str2rcolor(rc
, str
, &rcolor2
);
431 str
= PLGetString(PLGetArrayElement(texture
, 1));
433 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
434 timage
= RLoadImage(rc
, path
, 0);
437 wwarning("could not load file '%s': %s", path
,
438 RMessageForError(RErrorCode
));
440 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
442 image
= RMakeTiledImage(timage
, width
, height
);
443 RDestroyImage(timage
);
445 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
447 RCombineImagesWithOpaqueness(image
, grad
, i
);
450 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
455 switch (toupper(type
[1])) {
457 style
= RVerticalGradient
;
460 style
= RHorizontalGradient
;
464 style
= RDiagonalGradient
;
468 j
= PLGetNumberOfElements(texture
);
471 colors
= wmalloc(j
* sizeof(RColor
*));
473 for (i
= 2; i
< j
; i
++) {
474 str
= PLGetString(PLGetArrayElement(texture
, i
));
475 colors
[i
-2] = wmalloc(sizeof(RColor
));
476 str2rcolor(rc
, str
, colors
[i
-2]);
480 image
= RRenderMultiGradient(width
, height
, colors
, style
);
482 for (i
= 0; colors
[i
]!=NULL
; i
++)
486 } else if (strcasecmp(&type
[1], "pixmap")==0) {
491 str
= PLGetString(PLGetArrayElement(texture
, 1));
493 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
494 timage
= RLoadImage(rc
, path
, 0);
497 wwarning("could not load file '%s': %s", path
,
498 RMessageForError(RErrorCode
));
500 str
= PLGetString(PLGetArrayElement(texture
, 2));
501 str2rcolor(rc
, str
, &color
);
503 switch (toupper(type
[0])) {
505 image
= RMakeTiledImage(timage
, width
, height
);
506 RDestroyImage(timage
);
510 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
511 RDestroyImage(timage
);
516 image
= RScaleImage(timage
, width
, height
);
517 RDestroyImage(timage
);
530 dumpRImage(path
, image
);
534 if (border
== RESIZEBAR_BEVEL
) {
535 drawResizebarBevel(image
);
536 } else if (border
== MENU_BEVEL
) {
537 drawMenuBevel(image
);
540 RBevelImage(image
, border
);
543 RConvertImage(rc
, image
, &pixmap
);
544 RDestroyImage(image
);
551 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
553 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
554 Display
*dpy
= WMScreenDisplay(scr
);
557 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
560 str
= GetStringForKey("MenuStyle");
561 if (!str
|| strcasecmp(str
, "normal")==0) {
564 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
566 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*3,
568 for (i
= 0; i
< 3; i
++) {
569 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
,
572 XFreePixmap(dpy
, tmp
);
573 } else if (strcasecmp(str
, "flat")==0) {
574 pix
= renderTexture(scr
, texture
, width
, iheight
*3, NULL
, RBEV_RAISED2
);
576 pix
= renderTexture(scr
, texture
, width
, iheight
*3, NULL
, MENU_BEVEL
);
586 updatePreviewBox(_Panel
*panel
, int elements
)
588 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
589 Display
*dpy
= WMScreenDisplay(scr
);
590 /* RContext *rc = WMScreenRContext(scr);*/
595 TextureListItem
*titem
;
597 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
600 if (!panel
->preview
) {
603 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
604 260-4, 165-4, WMScreenDepth(scr
));
606 color
= WMGrayColor(scr
);
607 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
609 WMReleaseColor(color
);
614 if (elements
& FTITLE
) {
615 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
616 titem
= (TextureListItem
*)item
->clientData
;
618 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
620 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 5);
622 XFreePixmap(dpy
, pix
);
624 if (elements
& UTITLE
) {
625 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
626 titem
= (TextureListItem
*)item
->clientData
;
628 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
630 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 30);
632 XFreePixmap(dpy
, pix
);
634 if (elements
& OTITLE
) {
635 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
636 titem
= (TextureListItem
*)item
->clientData
;
638 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
640 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 55);
642 XFreePixmap(dpy
, pix
);
644 if (elements
& RESIZEBAR
) {
645 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
646 titem
= (TextureListItem
*)item
->clientData
;
648 pix
= renderTexture(scr
, titem
->prop
, 210, 9, NULL
, RESIZEBAR_BEVEL
);
650 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 80);
652 XFreePixmap(dpy
, pix
);
654 if (elements
& MTITLE
) {
655 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
656 titem
= (TextureListItem
*)item
->clientData
;
658 pix
= renderTexture(scr
, titem
->prop
, 100, 20, NULL
, RBEV_RAISED2
);
660 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 20, 30, 95);
662 XFreePixmap(dpy
, pix
);
664 if (elements
& MITEM
) {
665 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
666 titem
= (TextureListItem
*)item
->clientData
;
668 pix
= renderMenu(panel
, titem
->prop
, 100, 18);
670 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 18*3, 30, 115);
672 XFreePixmap(dpy
, pix
);
674 if (elements
& (MITEM
|MTITLE
)) {
675 XDrawLine(dpy
, panel
->preview
, gc
, 29, 95, 29, 115+36+20);
676 XDrawLine(dpy
, panel
->preview
, gc
, 29, 94, 129, 94);
679 if (elements
& ICON
) {
680 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
681 titem
= (TextureListItem
*)item
->clientData
;
683 pix
= renderTexture(scr
, titem
->prop
, 64, 64, NULL
,
684 titem
->ispixmap
? 0 : RBEV_RAISED3
);
686 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 64, 64, 170, 95);
688 XFreePixmap(dpy
, pix
);
694 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
695 260-4, 165-4, WMScreenDepth(scr
));
697 WMSetLabelImage(panel
->prevL
, p
);
700 WMRedisplayWidget(panel
->prevL
);
710 cancelNewTexture(void *data
)
712 _Panel
*panel
= (_Panel
*)data
;
714 HideTexturePanel(panel
->texturePanel
);
721 makeFileName(char *prefix
)
725 fname
= wstrdup(prefix
);
727 while (access(fname
, F_OK
)==0) {
731 sprintf(buf
, "%08lx.cache", time(NULL
));
732 fname
= wstrappend(prefix
, buf
);
742 okNewTexture(void *data
)
744 _Panel
*panel
= (_Panel
*)data
;
749 TextureListItem
*titem
;
750 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
752 titem
= wmalloc(sizeof(TextureListItem
));
753 memset(titem
, 0, sizeof(TextureListItem
));
755 HideTexturePanel(panel
->texturePanel
);
757 name
= GetTexturePanelTextureName(panel
->texturePanel
);
759 prop
= GetTexturePanelTexture(panel
->texturePanel
);
761 str
= PLGetDescription(prop
);
765 titem
->texture
= str
;
766 titem
->selectedFor
= 0;
768 titem
->ispixmap
= isPixmap(prop
);
770 titem
->path
= makeFileName(panel
->fprefix
);
771 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
774 item
= WMAddListItem(panel
->texLs
, "");
775 item
->clientData
= titem
;
777 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
782 okEditTexture(void *data
)
784 _Panel
*panel
= (_Panel
*)data
;
789 TextureListItem
*titem
;
791 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
792 titem
= (TextureListItem
*)item
->clientData
;
794 HideTexturePanel(panel
->texturePanel
);
796 if (titem
->current
) {
797 name
= GetTexturePanelTextureName(panel
->texturePanel
);
803 prop
= GetTexturePanelTexture(panel
->texturePanel
);
805 str
= PLGetDescription(prop
);
807 PLRelease(titem
->prop
);
810 titem
->ispixmap
= isPixmap(prop
);
812 free(titem
->texture
);
813 titem
->texture
= str
;
815 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
816 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
817 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
820 WMRedisplayWidget(panel
->texLs
);
822 if (titem
->selectedFor
)
823 updatePreviewBox(panel
, titem
->selectedFor
);
829 editTexture(WMWidget
*w
, void *data
)
831 _Panel
*panel
= (_Panel
*)data
;
833 TextureListItem
*titem
;
835 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
836 titem
= (TextureListItem
*)item
->clientData
;
838 SetTexturePanelPixmapPath(panel
->texturePanel
,
839 GetObjectForKey("PixmapPath"));
841 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
843 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
844 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
846 ShowTexturePanel(panel
->texturePanel
);
852 newTexture(WMWidget
*w
, void *data
)
854 _Panel
*panel
= (_Panel
*)data
;
856 SetTexturePanelPixmapPath(panel
->texturePanel
,
857 GetObjectForKey("PixmapPath"));
859 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
861 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
863 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
865 ShowTexturePanel(panel
->texturePanel
);
871 deleteTexture(WMWidget
*w
, void *data
)
873 _Panel
*panel
= (_Panel
*)data
;
875 TextureListItem
*titem
;
879 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
880 row
= WMGetListSelectedItemRow(panel
->texLs
);
881 item
= WMGetListItem(panel
->texLs
, row
);
882 titem
= (TextureListItem
*)item
->clientData
;
884 if (titem
->selectedFor
& (1 << section
)) {
885 TextureListItem
*titem2
;
887 panel
->textureIndex
[section
] = section
;
888 item
= WMGetListItem(panel
->texLs
, section
);
889 titem2
= (TextureListItem
*)item
->clientData
;
890 titem2
->selectedFor
|= 1 << section
;
894 free(titem
->texture
);
895 PLRelease(titem
->prop
);
897 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
898 wsyserror("could not remove file %s", titem
->path
);
905 WMRemoveListItem(panel
->texLs
, row
);
906 WMSetButtonEnabled(panel
->delB
, False
);
913 extractTexture(WMWidget
*w
, void *data
)
915 _Panel
*panel
= (_Panel
*)data
;
918 WMScreen
*scr
= WMWidgetScreen(w
);
920 opanel
= WMGetOpenPanel(scr
);
921 WMSetFilePanelCanChooseDirectories(opanel
, False
);
922 WMSetFilePanelCanChooseFiles(opanel
, True
);
924 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
925 _("Select File"), NULL
)) {
926 path
= WMGetFilePanelFileName(opanel
);
928 OpenExtractPanelFor(panel
, path
);
936 changePage(WMWidget
*w
, void *data
)
938 _Panel
*panel
= (_Panel
*)data
;
941 TextureListItem
*titem
;
943 WMScreen
*scr
= WMWidgetScreen(w
);
944 RContext
*rc
= WMScreenRContext(scr
);
945 static WMPoint positions
[] = {
955 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
957 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
959 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
961 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
963 titem
= (TextureListItem
*)item
->clientData
;
965 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
966 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
967 WMSetLabelText(panel
->texsL
, str
);
973 color
= WMGrayColor(scr
);
974 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
975 positions
[panel
->oldsection
].x
,
976 positions
[panel
->oldsection
].y
, 22, 22);
977 WMReleaseColor(color
);
979 panel
->oldsection
= section
;
980 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
981 positions
[section
].y
);
983 WMRedisplayWidget(panel
->prevL
);
989 previewClick(XEvent
*event
, void *clientData
)
991 _Panel
*panel
= (_Panel
*)clientData
;
993 static WMRect parts
[] = {
1003 for (i
= 0; i
< 7; i
++) {
1004 if (event
->xbutton
.x
>= parts
[i
].pos
.x
1005 && event
->xbutton
.y
>= parts
[i
].pos
.y
1006 && event
->xbutton
.x
< parts
[i
].pos
.x
+ parts
[i
].size
.width
1007 && event
->xbutton
.y
< parts
[i
].pos
.y
+ parts
[i
].size
.height
) {
1009 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1010 changePage(panel
->secP
, panel
);
1018 textureClick(WMWidget
*w
, void *data
)
1020 _Panel
*panel
= (_Panel
*)data
;
1023 TextureListItem
*titem
;
1025 i
= WMGetListSelectedItemRow(panel
->texLs
);
1027 item
= WMGetListItem(panel
->texLs
, i
);
1029 titem
= (TextureListItem
*)item
->clientData
;
1031 if (titem
->current
) {
1032 WMSetButtonEnabled(panel
->delB
, False
);
1034 WMSetButtonEnabled(panel
->delB
, True
);
1041 textureDoubleClick(WMWidget
*w
, void *data
)
1043 _Panel
*panel
= (_Panel
*)data
;
1046 TextureListItem
*titem
;
1049 /* unselect old texture */
1050 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1052 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1053 titem
= (TextureListItem
*)item
->clientData
;
1054 titem
->selectedFor
&= ~(1 << section
);
1056 /* select new texture */
1057 i
= WMGetListSelectedItemRow(panel
->texLs
);
1059 item
= WMGetListItem(panel
->texLs
, i
);
1061 titem
= (TextureListItem
*)item
->clientData
;
1063 titem
->selectedFor
|= 1<<section
;
1065 panel
->textureIndex
[section
] = i
;
1067 WMRedisplayWidget(panel
->texLs
);
1069 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
1070 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
1071 WMSetLabelText(panel
->texsL
, str
);
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
;
1204 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
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
, 260, 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
, 260, 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
);
1267 panel
->texsL
= WMCreateLabel(panel
->frame
);
1268 WMResizeWidget(panel
->texsL
, 260, 20);
1269 WMMoveWidget(panel
->texsL
, 15, 205);
1270 WMSetLabelWraps(panel
->texsL
, False
);
1273 font
= WMBoldSystemFontOfSize(scr
, 12);
1275 panel
->texL
= WMCreateLabel(panel
->frame
);
1276 WMResizeWidget(panel
->texL
, 225, 18);
1277 WMMoveWidget(panel
->texL
, 285, 10);
1278 WMSetLabelFont(panel
->texL
, font
);
1279 WMSetLabelText(panel
->texL
, _("Textures"));
1280 WMSetLabelRelief(panel
->texL
, WRSunken
);
1281 WMSetLabelTextAlignment(panel
->texL
, WACenter
);
1282 color
= WMDarkGrayColor(scr
);
1283 WMSetWidgetBackgroundColor(panel
->texL
, color
);
1284 WMReleaseColor(color
);
1285 color
= WMWhiteColor(scr
);
1286 WMSetLabelTextColor(panel
->texL
, color
);
1287 WMReleaseColor(color
);
1289 WMReleaseFont(font
);
1291 panel
->texLs
= WMCreateList(panel
->frame
);
1292 WMResizeWidget(panel
->texLs
, 225, 144);
1293 WMMoveWidget(panel
->texLs
, 285, 30);
1294 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1295 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1296 WMHangData(panel
->texLs
, panel
);
1297 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1298 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1300 /* command buttons */
1302 font
= WMSystemFontOfSize(scr
, 10);
1305 panel
->newB
= WMCreateCommandButton(panel
->frame
);
1306 WMResizeWidget(panel
->newB
, 56, 48);
1307 WMMoveWidget(panel
->newB
, 285, 180);
1308 WMSetButtonFont(panel
->newB
, font
);
1309 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1310 WMSetButtonText(panel
->newB
, _("New"));
1311 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1312 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1314 panel
->ripB
= WMCreateCommandButton(panel
->frame
);
1315 WMResizeWidget(panel
->ripB
, 56, 48);
1316 WMMoveWidget(panel
->ripB
, 341, 180);
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 WMSetButtonEnabled(panel
->ripB
, False
);
1325 panel
->editB
= WMCreateCommandButton(panel
->frame
);
1326 WMResizeWidget(panel
->editB
, 56, 48);
1327 WMMoveWidget(panel
->editB
, 397, 180);
1328 WMSetButtonFont(panel
->editB
, font
);
1329 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1330 WMSetButtonText(panel
->editB
, _("Edit"));
1331 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1332 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1334 panel
->delB
= WMCreateCommandButton(panel
->frame
);
1335 WMResizeWidget(panel
->delB
, 56, 48);
1336 WMMoveWidget(panel
->delB
, 453, 180);
1337 WMSetButtonFont(panel
->delB
, font
);
1338 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1339 WMSetButtonText(panel
->delB
, _("Delete"));
1340 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1341 WMSetButtonEnabled(panel
->delB
, False
);
1342 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1344 WMReleaseFont(font
);
1348 WMRealizeWidget(panel
->frame
);
1349 WMMapSubwidgets(panel
->frame
);
1351 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1355 changePage(panel
->secP
, panel
);
1357 fillTextureList(panel
->texLs
);
1359 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1365 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1369 TextureListItem
*titem
;
1371 titem
= wmalloc(sizeof(TextureListItem
));
1372 memset(titem
, 0, sizeof(TextureListItem
));
1374 titem
->title
= wstrdup(title
);
1375 titem
->prop
= GetObjectForKey(key
);
1377 titem
->prop
= PLGetProplistWithDescription(defValue
);
1379 PLRetain(titem
->prop
);
1381 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1383 titem
->selectedFor
= 1<<index
;
1385 titem
->ispixmap
= isPixmap(titem
->prop
);
1387 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1388 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1390 item
= WMAddListItem(list
, "");
1391 item
->clientData
= titem
;
1397 showData(_Panel
*panel
)
1401 setupTextureFor(panel
->texLs
, "FTitleBack", "(solid, black)",
1403 panel
->textureIndex
[i
] = i
++;
1405 setupTextureFor(panel
->texLs
, "UTitleBack", "(solid, gray)",
1407 panel
->textureIndex
[i
] = i
++;
1409 setupTextureFor(panel
->texLs
, "PTitleBack", "(solid, \"#616161\")",
1410 "[Owner of Focused]", i
);
1411 panel
->textureIndex
[i
] = i
++;
1413 setupTextureFor(panel
->texLs
, "ResizebarBack", "(solid, gray)",
1415 panel
->textureIndex
[i
] = i
++;
1417 setupTextureFor(panel
->texLs
, "MenuTitleBack", "(solid, black)",
1419 panel
->textureIndex
[i
] = i
++;
1421 setupTextureFor(panel
->texLs
, "MenuTextBack", "(solid, gray)",
1423 panel
->textureIndex
[i
] = i
++;
1425 setupTextureFor(panel
->texLs
, "IconBack", "(solid, gray)", "[Icon]", i
);
1426 panel
->textureIndex
[i
] = i
++;
1428 setupTextureFor(panel->texLs, "WorkspaceBack", "(solid, black)",
1430 panel->textureIndex[i] = i++;
1433 updatePreviewBox(panel
, EVERYTHING
);
1439 storeData(_Panel
*panel
)
1441 TextureListItem
*titem
;
1444 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
1445 titem
= (TextureListItem
*)item
->clientData
;
1446 SetObjectForKey(titem
->prop
, "FTitleBack");
1448 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
1449 titem
= (TextureListItem
*)item
->clientData
;
1450 SetObjectForKey(titem
->prop
, "UTitleBack");
1452 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
1453 titem
= (TextureListItem
*)item
->clientData
;
1454 SetObjectForKey(titem
->prop
, "PTitleBack");
1456 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
1457 titem
= (TextureListItem
*)item
->clientData
;
1458 SetObjectForKey(titem
->prop
, "ResizebarBack");
1460 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
1461 titem
= (TextureListItem
*)item
->clientData
;
1462 SetObjectForKey(titem
->prop
, "MenuTitleBack");
1464 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
1465 titem
= (TextureListItem
*)item
->clientData
;
1466 SetObjectForKey(titem
->prop
, "MenuTextBack");
1468 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
1469 titem
= (TextureListItem
*)item
->clientData
;
1470 SetObjectForKey(titem
->prop
, "IconBack");
1475 prepareForClose(_Panel
*panel
)
1477 proplist_t textureList
;
1480 TextureListItem
*titem
;
1482 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1484 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
1486 /* store list of textures */
1487 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
1488 item
= WMGetListItem(panel
->texLs
, i
);
1489 titem
= (TextureListItem
*)item
->clientData
;
1491 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
1492 PLRetain(titem
->prop
),
1493 PLMakeString(titem
->path
),
1496 PLAppendArrayElement(textureList
, texture
);
1499 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
1500 PLRelease(textureList
);
1502 WMSynchronizeUserDefaults(udb
);
1508 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
1512 panel
= wmalloc(sizeof(_Panel
));
1513 memset(panel
, 0, sizeof(_Panel
));
1515 panel
->sectionName
= _("Appearance Preferences");
1519 panel
->callbacks
.createWidgets
= createPanel
;
1520 panel
->callbacks
.updateDomain
= storeData
;
1521 panel
->callbacks
.prepareForClose
= prepareForClose
;
1523 AddSection(panel
, ICON_FILE
);
1530 /****************************************************************************/
1534 typedef struct ExtractPanel
{
1547 OpenExtractPanelFor(_Panel
*panel
, char *path
)
1549 ExtractPanel
*epanel
;
1552 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1554 epanel
= wmalloc(sizeof(ExtractPanel
));
1555 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
1557 |WMClosableWindowMask
);
1558 WMResizeWidget(epanel
->win
, 245, 250);
1559 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
1561 epanel
->label
= WMCreateLabel(epanel
->win
);
1562 WMResizeWidget(epanel
->label
, 225, 18);
1563 WMMoveWidget(epanel
->label
, 10, 10);
1564 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
1565 WMSetLabelRelief(epanel
->label
, WRSunken
);
1567 color
= WMDarkGrayColor(scr
);
1568 WMSetWidgetBackgroundColor(epanel
->label
, color
);
1569 WMReleaseColor(color
);
1571 color
= WMWhiteColor(scr
);
1572 WMSetLabelTextColor(epanel
->label
, color
);
1573 WMReleaseColor(color
);
1575 font
= WMBoldSystemFontOfSize(scr
, 12);
1576 WMSetLabelFont(epanel
->label
, font
);
1577 WMReleaseFont(font
);
1579 WMSetLabelText(epanel
->label
, _("Textures"));
1581 epanel
->list
= WMCreateList(epanel
->win
);
1582 WMResizeWidget(epanel
->list
, 225, 165);
1583 WMMoveWidget(epanel
->list
, 10, 30);
1587 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
1588 WMResizeWidget(epanel
->closeB
, 74, 24);
1589 WMMoveWidget(epanel
->closeB
, 165, 215);
1590 WMSetButtonText(epanel
->closeB
, _("Close"));
1592 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
1593 WMResizeWidget(epanel
->extrB
, 74, 24);
1594 WMMoveWidget(epanel
->extrB
, 80, 215);
1595 WMSetButtonText(epanel
->extrB
, _("Extract"));
1597 WMMapSubwidgets(epanel
->win
);
1600 /* take textures from file */
1604 WMRealizeWidget(epanel
->win
);
1606 WMMapWidget(epanel
->win
);