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
);
98 static void changePage(WMWidget
*w
, void *data
);
100 static void OpenExtractPanelFor(_Panel
*panel
, char *path
);
102 #define ICON_FILE "appearance"
104 #define TNEW_FILE "tnew"
105 #define TDEL_FILE "tdel"
106 #define TEDIT_FILE "tedit"
107 #define TEXTR_FILE "textr"
112 static char * blueled_xpm
[] = {
142 static char *blueled2_xpm
[] = {
143 /* width height num_colors chars_per_pixel */
175 static char * hand_xpm
[] = {
197 " .))),%.......... ",
198 " .)-)),&)))))))))$. ",
199 " .-&))))))))),,,,;;. ",
200 " .=)))))))));-=***&$. ",
201 " .=)))))))),..+..... ",
219 #define FTITLE (1<<0)
220 #define UTITLE (1<<1)
221 #define OTITLE (1<<2)
222 #define RESIZEBAR (1<<3)
223 #define MTITLE (1<<4)
227 #define EVERYTHING 0xff
230 #define RESIZEBAR_BEVEL -1
231 #define MENU_BEVEL -2
233 #define TEXPREV_WIDTH 40
234 #define TEXPREV_HEIGHT 24
241 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
245 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
248 color
->red
= xcolor
.red
>> 8;
249 color
->green
= xcolor
.green
>> 8;
250 color
->blue
= xcolor
.blue
>> 8;
256 dumpRImage(char *path
, RImage
*image
)
260 f
= fopen(path
, "w");
265 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
,
266 image
->data
[3]!=NULL
? 4 : 3);
268 fwrite(image
->data
[0], 1, image
->width
* image
->height
, f
);
269 fwrite(image
->data
[1], 1, image
->width
* image
->height
, f
);
270 fwrite(image
->data
[2], 1, image
->width
* image
->height
, f
);
272 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
282 isPixmap(proplist_t prop
)
287 p
= PLGetArrayElement(prop
, 0);
289 if (strcasecmp(&s
[1], "pixmap")==0)
297 drawResizebarBevel(RImage
*img
)
302 int width
= img
->width
;
303 int height
= img
->height
;
307 black
.red
= black
.green
= black
.blue
= 0;
310 light
.red
= light
.green
= light
.blue
= 80;
313 dark
.red
= dark
.green
= dark
.blue
= 40;
315 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
316 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
318 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
319 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
321 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
323 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
326 RDrawLine(img
, 0, height
-1, width
-1, height
-1, &black
);
327 RDrawLine(img
, 0, 0, 0, height
-1, &black
);
328 RDrawLine(img
, width
-1, 0, width
-1, height
-1, &black
);
333 drawMenuBevel(RImage
*img
)
335 RColor light
, dark
, mid
;
337 int iheight
= img
->height
/ 3;
340 light
.red
= light
.green
= light
.blue
= 80;
343 dark
.red
= dark
.green
= dark
.blue
= 0;
346 mid
.red
= mid
.green
= mid
.blue
= 40;
348 for (i
= 1; i
< 3; i
++) {
349 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
350 img
->width
-1, i
*iheight
-2, &mid
);
352 RDrawLine(img
, 0, i
*iheight
-1,
353 img
->width
-1, i
*iheight
-1, &dark
);
355 ROperateLine(img
, RAddOperation
, 0, i
*iheight
,
356 img
->width
-1, i
*iheight
, &light
);
362 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
363 char *path
, int border
)
368 RContext
*rc
= WMScreenRContext(scr
);
373 type
= PLGetString(PLGetArrayElement(texture
, 0));
375 image
= RCreateImage(width
, height
, False
);
377 if (strcasecmp(type
, "solid")==0) {
379 str
= PLGetString(PLGetArrayElement(texture
, 1));
381 str2rcolor(rc
, str
, &rcolor
);
383 RClearImage(image
, &rcolor
);
384 } else if (strcasecmp(&type
[1], "gradient")==0) {
388 switch (toupper(type
[0])) {
390 style
= RVerticalGradient
;
393 style
= RHorizontalGradient
;
397 style
= RDiagonalGradient
;
401 str
= PLGetString(PLGetArrayElement(texture
, 1));
402 str2rcolor(rc
, str
, &rcolor
);
403 str
= PLGetString(PLGetArrayElement(texture
, 2));
404 str2rcolor(rc
, str
, &rcolor2
);
406 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
407 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
411 RImage
*grad
, *timage
;
414 switch (toupper(type
[1])) {
416 style
= RVerticalGradient
;
419 style
= RHorizontalGradient
;
423 style
= RDiagonalGradient
;
427 str
= PLGetString(PLGetArrayElement(texture
, 3));
428 str2rcolor(rc
, str
, &rcolor
);
429 str
= PLGetString(PLGetArrayElement(texture
, 4));
430 str2rcolor(rc
, str
, &rcolor2
);
432 str
= PLGetString(PLGetArrayElement(texture
, 1));
434 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
435 timage
= RLoadImage(rc
, path
, 0);
438 wwarning("could not load file '%s': %s", path
,
439 RMessageForError(RErrorCode
));
441 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
443 image
= RMakeTiledImage(timage
, width
, height
);
444 RDestroyImage(timage
);
446 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
448 RCombineImagesWithOpaqueness(image
, grad
, i
);
451 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
456 switch (toupper(type
[1])) {
458 style
= RVerticalGradient
;
461 style
= RHorizontalGradient
;
465 style
= RDiagonalGradient
;
469 j
= PLGetNumberOfElements(texture
);
472 colors
= wmalloc(j
* sizeof(RColor
*));
474 for (i
= 2; i
< j
; i
++) {
475 str
= PLGetString(PLGetArrayElement(texture
, i
));
476 colors
[i
-2] = wmalloc(sizeof(RColor
));
477 str2rcolor(rc
, str
, colors
[i
-2]);
481 image
= RRenderMultiGradient(width
, height
, colors
, style
);
483 for (i
= 0; colors
[i
]!=NULL
; i
++)
487 } else if (strcasecmp(&type
[1], "pixmap")==0) {
492 str
= PLGetString(PLGetArrayElement(texture
, 1));
494 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
495 timage
= RLoadImage(rc
, path
, 0);
498 wwarning("could not load file '%s': %s", path
,
499 RMessageForError(RErrorCode
));
501 str
= PLGetString(PLGetArrayElement(texture
, 2));
502 str2rcolor(rc
, str
, &color
);
504 switch (toupper(type
[0])) {
506 image
= RMakeTiledImage(timage
, width
, height
);
507 RDestroyImage(timage
);
511 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
512 RDestroyImage(timage
);
517 image
= RScaleImage(timage
, width
, height
);
518 RDestroyImage(timage
);
531 dumpRImage(path
, image
);
535 if (border
== RESIZEBAR_BEVEL
) {
536 drawResizebarBevel(image
);
537 } else if (border
== MENU_BEVEL
) {
538 drawMenuBevel(image
);
541 RBevelImage(image
, border
);
544 RConvertImage(rc
, image
, &pixmap
);
545 RDestroyImage(image
);
552 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
554 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
555 Display
*dpy
= WMScreenDisplay(scr
);
558 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
561 str
= GetStringForKey("MenuStyle");
562 if (!str
|| strcasecmp(str
, "normal")==0) {
565 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
567 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*3,
569 for (i
= 0; i
< 3; i
++) {
570 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
,
573 XFreePixmap(dpy
, tmp
);
574 } else if (strcasecmp(str
, "flat")==0) {
575 pix
= renderTexture(scr
, texture
, width
, iheight
*3, NULL
, RBEV_RAISED2
);
577 pix
= renderTexture(scr
, texture
, width
, iheight
*3, NULL
, MENU_BEVEL
);
587 updatePreviewBox(_Panel
*panel
, int elements
)
589 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
590 Display
*dpy
= WMScreenDisplay(scr
);
591 /* RContext *rc = WMScreenRContext(scr);*/
596 TextureListItem
*titem
;
598 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
601 if (!panel
->preview
) {
604 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
605 260-4, 165-4, WMScreenDepth(scr
));
607 color
= WMGrayColor(scr
);
608 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
610 WMReleaseColor(color
);
615 if (elements
& FTITLE
) {
616 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
617 titem
= (TextureListItem
*)item
->clientData
;
619 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
621 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 5);
623 XFreePixmap(dpy
, pix
);
625 if (elements
& UTITLE
) {
626 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
627 titem
= (TextureListItem
*)item
->clientData
;
629 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
631 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 30);
633 XFreePixmap(dpy
, pix
);
635 if (elements
& OTITLE
) {
636 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
637 titem
= (TextureListItem
*)item
->clientData
;
639 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
641 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 55);
643 XFreePixmap(dpy
, pix
);
645 if (elements
& RESIZEBAR
) {
646 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
647 titem
= (TextureListItem
*)item
->clientData
;
649 pix
= renderTexture(scr
, titem
->prop
, 210, 9, NULL
, RESIZEBAR_BEVEL
);
651 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 80);
653 XFreePixmap(dpy
, pix
);
655 if (elements
& MTITLE
) {
656 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
657 titem
= (TextureListItem
*)item
->clientData
;
659 pix
= renderTexture(scr
, titem
->prop
, 100, 20, NULL
, RBEV_RAISED2
);
661 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 20, 30, 95);
663 XFreePixmap(dpy
, pix
);
665 if (elements
& MITEM
) {
666 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
667 titem
= (TextureListItem
*)item
->clientData
;
669 pix
= renderMenu(panel
, titem
->prop
, 100, 18);
671 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 18*3, 30, 115);
673 XFreePixmap(dpy
, pix
);
675 if (elements
& (MITEM
|MTITLE
)) {
676 XDrawLine(dpy
, panel
->preview
, gc
, 29, 95, 29, 115+36+20);
677 XDrawLine(dpy
, panel
->preview
, gc
, 29, 94, 129, 94);
680 if (elements
& ICON
) {
681 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
682 titem
= (TextureListItem
*)item
->clientData
;
684 pix
= renderTexture(scr
, titem
->prop
, 64, 64, NULL
,
685 titem
->ispixmap
? 0 : RBEV_RAISED3
);
687 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 64, 64, 170, 95);
689 XFreePixmap(dpy
, pix
);
695 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
696 260-4, 165-4, WMScreenDepth(scr
));
698 WMSetLabelImage(panel
->prevL
, p
);
701 WMRedisplayWidget(panel
->prevL
);
711 cancelNewTexture(void *data
)
713 _Panel
*panel
= (_Panel
*)data
;
715 HideTexturePanel(panel
->texturePanel
);
722 makeFileName(char *prefix
)
726 fname
= wstrdup(prefix
);
728 while (access(fname
, F_OK
)==0) {
732 sprintf(buf
, "%08lx.cache", time(NULL
));
733 fname
= wstrappend(prefix
, buf
);
743 okNewTexture(void *data
)
745 _Panel
*panel
= (_Panel
*)data
;
750 TextureListItem
*titem
;
751 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
753 titem
= wmalloc(sizeof(TextureListItem
));
754 memset(titem
, 0, sizeof(TextureListItem
));
756 HideTexturePanel(panel
->texturePanel
);
758 name
= GetTexturePanelTextureName(panel
->texturePanel
);
760 prop
= GetTexturePanelTexture(panel
->texturePanel
);
762 str
= PLGetDescription(prop
);
766 titem
->texture
= str
;
767 titem
->selectedFor
= 0;
769 titem
->ispixmap
= isPixmap(prop
);
771 titem
->path
= makeFileName(panel
->fprefix
);
772 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
775 item
= WMAddListItem(panel
->texLs
, "");
776 item
->clientData
= titem
;
778 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
783 okEditTexture(void *data
)
785 _Panel
*panel
= (_Panel
*)data
;
790 TextureListItem
*titem
;
792 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
793 titem
= (TextureListItem
*)item
->clientData
;
795 HideTexturePanel(panel
->texturePanel
);
797 if (titem
->current
) {
798 name
= GetTexturePanelTextureName(panel
->texturePanel
);
804 prop
= GetTexturePanelTexture(panel
->texturePanel
);
806 str
= PLGetDescription(prop
);
808 PLRelease(titem
->prop
);
811 titem
->ispixmap
= isPixmap(prop
);
813 free(titem
->texture
);
814 titem
->texture
= str
;
816 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
817 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
818 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
821 WMRedisplayWidget(panel
->texLs
);
823 if (titem
->selectedFor
)
824 updatePreviewBox(panel
, titem
->selectedFor
);
826 changePage(panel
->secP
, panel
);
832 editTexture(WMWidget
*w
, void *data
)
834 _Panel
*panel
= (_Panel
*)data
;
836 TextureListItem
*titem
;
838 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
839 titem
= (TextureListItem
*)item
->clientData
;
841 SetTexturePanelPixmapPath(panel
->texturePanel
,
842 GetObjectForKey("PixmapPath"));
844 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
846 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
847 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
849 ShowTexturePanel(panel
->texturePanel
);
855 newTexture(WMWidget
*w
, void *data
)
857 _Panel
*panel
= (_Panel
*)data
;
859 SetTexturePanelPixmapPath(panel
->texturePanel
,
860 GetObjectForKey("PixmapPath"));
862 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
864 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
866 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
868 ShowTexturePanel(panel
->texturePanel
);
874 deleteTexture(WMWidget
*w
, void *data
)
876 _Panel
*panel
= (_Panel
*)data
;
878 TextureListItem
*titem
;
882 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
883 row
= WMGetListSelectedItemRow(panel
->texLs
);
884 item
= WMGetListItem(panel
->texLs
, row
);
885 titem
= (TextureListItem
*)item
->clientData
;
887 if (titem
->selectedFor
& (1 << section
)) {
888 TextureListItem
*titem2
;
890 panel
->textureIndex
[section
] = section
;
891 item
= WMGetListItem(panel
->texLs
, section
);
892 titem2
= (TextureListItem
*)item
->clientData
;
893 titem2
->selectedFor
|= 1 << section
;
897 free(titem
->texture
);
898 PLRelease(titem
->prop
);
900 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
901 wsyserror("could not remove file %s", titem
->path
);
908 WMRemoveListItem(panel
->texLs
, row
);
909 WMSetButtonEnabled(panel
->delB
, False
);
916 extractTexture(WMWidget
*w
, void *data
)
918 _Panel
*panel
= (_Panel
*)data
;
921 WMScreen
*scr
= WMWidgetScreen(w
);
923 opanel
= WMGetOpenPanel(scr
);
924 WMSetFilePanelCanChooseDirectories(opanel
, False
);
925 WMSetFilePanelCanChooseFiles(opanel
, True
);
927 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
928 _("Select File"), NULL
)) {
929 path
= WMGetFilePanelFileName(opanel
);
931 OpenExtractPanelFor(panel
, path
);
939 changePage(WMWidget
*w
, void *data
)
941 _Panel
*panel
= (_Panel
*)data
;
944 TextureListItem
*titem
;
946 WMScreen
*scr
= WMWidgetScreen(w
);
947 RContext
*rc
= WMScreenRContext(scr
);
948 static WMPoint positions
[] = {
958 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
960 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
962 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
964 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
966 titem
= (TextureListItem
*)item
->clientData
;
968 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
969 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
970 WMSetLabelText(panel
->texsL
, str
);
976 color
= WMGrayColor(scr
);
977 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
978 positions
[panel
->oldsection
].x
,
979 positions
[panel
->oldsection
].y
, 22, 22);
980 WMReleaseColor(color
);
982 panel
->oldsection
= section
;
983 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
984 positions
[section
].y
);
986 WMRedisplayWidget(panel
->prevL
);
992 previewClick(XEvent
*event
, void *clientData
)
994 _Panel
*panel
= (_Panel
*)clientData
;
996 static WMRect parts
[] = {
1002 {{30,115},{100,60}},
1006 for (i
= 0; i
< 7; i
++) {
1007 if (event
->xbutton
.x
>= parts
[i
].pos
.x
1008 && event
->xbutton
.y
>= parts
[i
].pos
.y
1009 && event
->xbutton
.x
< parts
[i
].pos
.x
+ parts
[i
].size
.width
1010 && event
->xbutton
.y
< parts
[i
].pos
.y
+ parts
[i
].size
.height
) {
1012 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1013 changePage(panel
->secP
, panel
);
1021 textureClick(WMWidget
*w
, void *data
)
1023 _Panel
*panel
= (_Panel
*)data
;
1026 TextureListItem
*titem
;
1028 i
= WMGetListSelectedItemRow(panel
->texLs
);
1030 item
= WMGetListItem(panel
->texLs
, i
);
1032 titem
= (TextureListItem
*)item
->clientData
;
1034 if (titem
->current
) {
1035 WMSetButtonEnabled(panel
->delB
, False
);
1037 WMSetButtonEnabled(panel
->delB
, True
);
1044 textureDoubleClick(WMWidget
*w
, void *data
)
1046 _Panel
*panel
= (_Panel
*)data
;
1049 TextureListItem
*titem
;
1052 /* unselect old texture */
1053 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1055 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1056 titem
= (TextureListItem
*)item
->clientData
;
1057 titem
->selectedFor
&= ~(1 << section
);
1059 /* select new texture */
1060 i
= WMGetListSelectedItemRow(panel
->texLs
);
1062 item
= WMGetListItem(panel
->texLs
, i
);
1064 titem
= (TextureListItem
*)item
->clientData
;
1066 titem
->selectedFor
|= 1<<section
;
1068 panel
->textureIndex
[section
] = i
;
1070 WMRedisplayWidget(panel
->texLs
);
1072 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
1073 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
1074 WMSetLabelText(panel
->texsL
, str
);
1077 updatePreviewBox(panel
, 1<<section
);
1084 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
1087 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
1088 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1089 int width
, height
, x
, y
;
1090 Display
*dpy
= WMScreenDisplay(scr
);
1091 WMColor
*white
= WMWhiteColor(scr
);
1093 WMColor
*black
= WMBlackColor(scr
);
1094 TextureListItem
*titem
;
1096 width
= rect
->size
.width
;
1097 height
= rect
->size
.height
;
1101 if (state
& WLDSSelected
)
1102 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1104 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
1106 item
= WMGetListItem(lPtr
, index
);
1107 titem
= (TextureListItem
*)item
->clientData
;
1110 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0, TEXPREV_WIDTH
,
1111 TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1113 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1114 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1115 else if (titem
->selectedFor
)
1116 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1118 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
1119 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
1120 strlen(titem
->title
));
1122 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
1123 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
1124 strlen(titem
->texture
));
1127 WMReleaseColor(white
);
1128 WMReleaseColor(black
);
1134 loadRImage(WMScreen
*scr
, char *path
)
1142 f
= fopen(path
, "r");
1146 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1148 image
= RCreateImage(w
, h
, d
== 4);
1149 for (i
= 0; i
< d
; i
++) {
1150 fread(image
->data
[i
], 1, w
*h
, f
);
1154 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1155 RDestroyImage(image
);
1163 fillTextureList(WMList
*lPtr
)
1165 proplist_t textureList
;
1167 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1169 TextureListItem
*titem
;
1170 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1172 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1176 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1179 texture
= PLGetArrayElement(textureList
, i
);
1181 titem
= wmalloc(sizeof(TextureListItem
));
1182 memset(titem
, 0, sizeof(TextureListItem
));
1184 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1185 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1186 titem
->texture
= PLGetDescription(titem
->prop
);
1187 titem
->selectedFor
= 0;
1188 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1190 titem
->preview
= loadRImage(scr
, titem
->path
);
1191 if (!titem
->preview
) {
1192 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1193 TEXPREV_HEIGHT
, NULL
, 0);
1195 item
= WMAddListItem(lPtr
, "");
1196 item
->clientData
= titem
;
1202 createPanel(Panel
*p
)
1204 _Panel
*panel
= (_Panel
*)p
;
1207 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1212 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
1214 if (access(panel
->fprefix
, F_OK
)!=0) {
1215 if (mkdir(panel
->fprefix
, 0755) < 0) {
1216 wsyserror(panel
->fprefix
);
1221 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
1222 free(panel
->fprefix
);
1223 panel
->fprefix
= tmp
;
1224 if (access(panel
->fprefix
, F_OK
)!=0) {
1225 if (mkdir(panel
->fprefix
, 0755) < 0) {
1226 wsyserror(panel
->fprefix
);
1231 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1232 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1233 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1235 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1236 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1237 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1239 panel
->frame
= WMCreateFrame(panel
->win
);
1240 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1241 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1244 panel
->prevL
= WMCreateLabel(panel
->frame
);
1245 WMResizeWidget(panel
->prevL
, 260, 165);
1246 WMMoveWidget(panel
->prevL
, 15, 10);
1247 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1248 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1250 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1251 previewClick
, panel
);
1254 panel
->secP
= WMCreatePopUpButton(panel
->frame
);
1255 WMResizeWidget(panel
->secP
, 260, 20);
1256 WMMoveWidget(panel
->secP
, 15, 180);
1257 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1258 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1259 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1260 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1261 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1262 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1263 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1264 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1265 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1267 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1270 panel
->texsL
= WMCreateLabel(panel
->frame
);
1271 WMResizeWidget(panel
->texsL
, 260, 20);
1272 WMMoveWidget(panel
->texsL
, 15, 205);
1273 WMSetLabelWraps(panel
->texsL
, False
);
1276 font
= WMBoldSystemFontOfSize(scr
, 12);
1278 panel
->texL
= WMCreateLabel(panel
->frame
);
1279 WMResizeWidget(panel
->texL
, 225, 18);
1280 WMMoveWidget(panel
->texL
, 285, 10);
1281 WMSetLabelFont(panel
->texL
, font
);
1282 WMSetLabelText(panel
->texL
, _("Textures"));
1283 WMSetLabelRelief(panel
->texL
, WRSunken
);
1284 WMSetLabelTextAlignment(panel
->texL
, WACenter
);
1285 color
= WMDarkGrayColor(scr
);
1286 WMSetWidgetBackgroundColor(panel
->texL
, color
);
1287 WMReleaseColor(color
);
1288 color
= WMWhiteColor(scr
);
1289 WMSetLabelTextColor(panel
->texL
, color
);
1290 WMReleaseColor(color
);
1292 WMReleaseFont(font
);
1294 panel
->texLs
= WMCreateList(panel
->frame
);
1295 WMResizeWidget(panel
->texLs
, 225, 144);
1296 WMMoveWidget(panel
->texLs
, 285, 30);
1297 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1298 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1299 WMHangData(panel
->texLs
, panel
);
1300 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1301 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1303 /* command buttons */
1305 font
= WMSystemFontOfSize(scr
, 10);
1308 panel
->newB
= WMCreateCommandButton(panel
->frame
);
1309 WMResizeWidget(panel
->newB
, 56, 48);
1310 WMMoveWidget(panel
->newB
, 285, 180);
1311 WMSetButtonFont(panel
->newB
, font
);
1312 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1313 WMSetButtonText(panel
->newB
, _("New"));
1314 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1315 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1317 panel
->ripB
= WMCreateCommandButton(panel
->frame
);
1318 WMResizeWidget(panel
->ripB
, 56, 48);
1319 WMMoveWidget(panel
->ripB
, 341, 180);
1320 WMSetButtonFont(panel
->ripB
, font
);
1321 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1322 WMSetButtonText(panel
->ripB
, _("Extract..."));
1323 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1324 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1326 WMSetButtonEnabled(panel
->ripB
, False
);
1328 panel
->editB
= WMCreateCommandButton(panel
->frame
);
1329 WMResizeWidget(panel
->editB
, 56, 48);
1330 WMMoveWidget(panel
->editB
, 397, 180);
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
);
1337 panel
->delB
= WMCreateCommandButton(panel
->frame
);
1338 WMResizeWidget(panel
->delB
, 56, 48);
1339 WMMoveWidget(panel
->delB
, 453, 180);
1340 WMSetButtonFont(panel
->delB
, font
);
1341 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1342 WMSetButtonText(panel
->delB
, _("Delete"));
1343 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1344 WMSetButtonEnabled(panel
->delB
, False
);
1345 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1347 WMReleaseFont(font
);
1351 WMRealizeWidget(panel
->frame
);
1352 WMMapSubwidgets(panel
->frame
);
1354 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1358 changePage(panel
->secP
, panel
);
1360 fillTextureList(panel
->texLs
);
1362 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1368 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1372 TextureListItem
*titem
;
1374 titem
= wmalloc(sizeof(TextureListItem
));
1375 memset(titem
, 0, sizeof(TextureListItem
));
1377 titem
->title
= wstrdup(title
);
1378 titem
->prop
= GetObjectForKey(key
);
1380 titem
->prop
= PLGetProplistWithDescription(defValue
);
1382 PLRetain(titem
->prop
);
1384 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1386 titem
->selectedFor
= 1<<index
;
1388 titem
->ispixmap
= isPixmap(titem
->prop
);
1390 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1391 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1393 item
= WMAddListItem(list
, "");
1394 item
->clientData
= titem
;
1400 showData(_Panel
*panel
)
1404 setupTextureFor(panel
->texLs
, "FTitleBack", "(solid, black)",
1406 panel
->textureIndex
[i
] = i
++;
1408 setupTextureFor(panel
->texLs
, "UTitleBack", "(solid, gray)",
1410 panel
->textureIndex
[i
] = i
++;
1412 setupTextureFor(panel
->texLs
, "PTitleBack", "(solid, \"#616161\")",
1413 "[Owner of Focused]", i
);
1414 panel
->textureIndex
[i
] = i
++;
1416 setupTextureFor(panel
->texLs
, "ResizebarBack", "(solid, gray)",
1418 panel
->textureIndex
[i
] = i
++;
1420 setupTextureFor(panel
->texLs
, "MenuTitleBack", "(solid, black)",
1422 panel
->textureIndex
[i
] = i
++;
1424 setupTextureFor(panel
->texLs
, "MenuTextBack", "(solid, gray)",
1426 panel
->textureIndex
[i
] = i
++;
1428 setupTextureFor(panel
->texLs
, "IconBack", "(solid, gray)", "[Icon]", i
);
1429 panel
->textureIndex
[i
] = i
++;
1431 setupTextureFor(panel->texLs, "WorkspaceBack", "(solid, black)",
1433 panel->textureIndex[i] = i++;
1436 updatePreviewBox(panel
, EVERYTHING
);
1442 storeData(_Panel
*panel
)
1444 TextureListItem
*titem
;
1447 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
1448 titem
= (TextureListItem
*)item
->clientData
;
1449 SetObjectForKey(titem
->prop
, "FTitleBack");
1451 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
1452 titem
= (TextureListItem
*)item
->clientData
;
1453 SetObjectForKey(titem
->prop
, "UTitleBack");
1455 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
1456 titem
= (TextureListItem
*)item
->clientData
;
1457 SetObjectForKey(titem
->prop
, "PTitleBack");
1459 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
1460 titem
= (TextureListItem
*)item
->clientData
;
1461 SetObjectForKey(titem
->prop
, "ResizebarBack");
1463 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
1464 titem
= (TextureListItem
*)item
->clientData
;
1465 SetObjectForKey(titem
->prop
, "MenuTitleBack");
1467 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
1468 titem
= (TextureListItem
*)item
->clientData
;
1469 SetObjectForKey(titem
->prop
, "MenuTextBack");
1471 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
1472 titem
= (TextureListItem
*)item
->clientData
;
1473 SetObjectForKey(titem
->prop
, "IconBack");
1478 prepareForClose(_Panel
*panel
)
1480 proplist_t textureList
;
1483 TextureListItem
*titem
;
1485 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1487 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
1489 /* store list of textures */
1490 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
1491 item
= WMGetListItem(panel
->texLs
, i
);
1492 titem
= (TextureListItem
*)item
->clientData
;
1494 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
1495 PLRetain(titem
->prop
),
1496 PLMakeString(titem
->path
),
1499 PLAppendArrayElement(textureList
, texture
);
1502 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
1503 PLRelease(textureList
);
1505 WMSynchronizeUserDefaults(udb
);
1511 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
1515 panel
= wmalloc(sizeof(_Panel
));
1516 memset(panel
, 0, sizeof(_Panel
));
1518 panel
->sectionName
= _("Appearance Preferences");
1522 panel
->callbacks
.createWidgets
= createPanel
;
1523 panel
->callbacks
.updateDomain
= storeData
;
1524 panel
->callbacks
.prepareForClose
= prepareForClose
;
1526 AddSection(panel
, ICON_FILE
);
1533 /****************************************************************************/
1537 typedef struct ExtractPanel
{
1550 OpenExtractPanelFor(_Panel
*panel
, char *path
)
1552 ExtractPanel
*epanel
;
1555 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1557 epanel
= wmalloc(sizeof(ExtractPanel
));
1558 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
1560 |WMClosableWindowMask
);
1561 WMResizeWidget(epanel
->win
, 245, 250);
1562 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
1564 epanel
->label
= WMCreateLabel(epanel
->win
);
1565 WMResizeWidget(epanel
->label
, 225, 18);
1566 WMMoveWidget(epanel
->label
, 10, 10);
1567 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
1568 WMSetLabelRelief(epanel
->label
, WRSunken
);
1570 color
= WMDarkGrayColor(scr
);
1571 WMSetWidgetBackgroundColor(epanel
->label
, color
);
1572 WMReleaseColor(color
);
1574 color
= WMWhiteColor(scr
);
1575 WMSetLabelTextColor(epanel
->label
, color
);
1576 WMReleaseColor(color
);
1578 font
= WMBoldSystemFontOfSize(scr
, 12);
1579 WMSetLabelFont(epanel
->label
, font
);
1580 WMReleaseFont(font
);
1582 WMSetLabelText(epanel
->label
, _("Textures"));
1584 epanel
->list
= WMCreateList(epanel
->win
);
1585 WMResizeWidget(epanel
->list
, 225, 165);
1586 WMMoveWidget(epanel
->list
, 10, 30);
1590 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
1591 WMResizeWidget(epanel
->closeB
, 74, 24);
1592 WMMoveWidget(epanel
->closeB
, 165, 215);
1593 WMSetButtonText(epanel
->closeB
, _("Close"));
1595 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
1596 WMResizeWidget(epanel
->extrB
, 74, 24);
1597 WMMoveWidget(epanel
->extrB
, 80, 215);
1598 WMSetButtonText(epanel
->extrB
, _("Extract"));
1600 WMMapSubwidgets(epanel
->win
);
1603 /* take textures from file */
1607 WMRealizeWidget(epanel
->win
);
1609 WMMapWidget(epanel
->win
);