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
;
83 TexturePanel
*texturePanel
;
113 static void showData(_Panel
*panel
);
115 static void changePage(WMWidget
*w
, void *data
);
117 static void OpenExtractPanelFor(_Panel
*panel
, char *path
);
119 #define ICON_FILE "appearance"
121 #define TNEW_FILE "tnew"
122 #define TDEL_FILE "tdel"
123 #define TEDIT_FILE "tedit"
124 #define TEXTR_FILE "textr"
126 #define MSTYLE1_FILE "msty1"
127 #define MSTYLE2_FILE "msty2"
128 #define MSTYLE3_FILE "msty3"
132 static char * blueled_xpm
[] = {
162 static char *blueled2_xpm
[] = {
163 /* width height num_colors chars_per_pixel */
195 static char * hand_xpm
[] = {
217 " .))),%.......... ",
218 " .)-)),&)))))))))$. ",
219 " .-&))))))))),,,,;;. ",
220 " .=)))))))));-=***&$. ",
221 " .=)))))))),..+..... ",
239 #define FTITLE (1<<0)
240 #define UTITLE (1<<1)
241 #define OTITLE (1<<2)
242 #define RESIZEBAR (1<<3)
243 #define MTITLE (1<<4)
247 #define EVERYTHING 0xff
250 #define RESIZEBAR_BEVEL -1
251 #define MENU_BEVEL -2
253 #define TEXPREV_WIDTH 40
254 #define TEXPREV_HEIGHT 24
257 #define MSTYLE_NORMAL 0
258 #define MSTYLE_SINGLE 1
259 #define MSTYLE_FLAT 2
265 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
269 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
272 color
->red
= xcolor
.red
>> 8;
273 color
->green
= xcolor
.green
>> 8;
274 color
->blue
= xcolor
.blue
>> 8;
280 dumpRImage(char *path
, RImage
*image
)
284 f
= fopen(path
, "w");
289 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
,
290 image
->data
[3]!=NULL
? 4 : 3);
292 fwrite(image
->data
[0], 1, image
->width
* image
->height
, f
);
293 fwrite(image
->data
[1], 1, image
->width
* image
->height
, f
);
294 fwrite(image
->data
[2], 1, image
->width
* image
->height
, f
);
296 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
306 isPixmap(proplist_t prop
)
311 p
= PLGetArrayElement(prop
, 0);
313 if (strcasecmp(&s
[1], "pixmap")==0)
321 drawResizebarBevel(RImage
*img
)
326 int width
= img
->width
;
327 int height
= img
->height
;
331 black
.red
= black
.green
= black
.blue
= 0;
334 light
.red
= light
.green
= light
.blue
= 80;
337 dark
.red
= dark
.green
= dark
.blue
= 40;
339 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
340 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
342 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
343 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
345 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
347 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
350 RDrawLine(img
, 0, height
-1, width
-1, height
-1, &black
);
351 RDrawLine(img
, 0, 0, 0, height
-1, &black
);
352 RDrawLine(img
, width
-1, 0, width
-1, height
-1, &black
);
357 drawMenuBevel(RImage
*img
)
359 RColor light
, dark
, mid
;
361 int iheight
= img
->height
/ 4;
364 light
.red
= light
.green
= light
.blue
= 80;
367 dark
.red
= dark
.green
= dark
.blue
= 0;
370 mid
.red
= mid
.green
= mid
.blue
= 40;
372 for (i
= 1; i
< 4; i
++) {
373 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
374 img
->width
-1, i
*iheight
-2, &mid
);
376 RDrawLine(img
, 0, i
*iheight
-1,
377 img
->width
-1, i
*iheight
-1, &dark
);
379 ROperateLine(img
, RAddOperation
, 1, i
*iheight
,
380 img
->width
-2, i
*iheight
, &light
);
386 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
387 char *path
, int border
)
390 RImage
*image
= NULL
;
392 RContext
*rc
= WMScreenRContext(scr
);
397 type
= PLGetString(PLGetArrayElement(texture
, 0));
399 if (strcasecmp(type
, "solid")==0) {
401 str
= PLGetString(PLGetArrayElement(texture
, 1));
403 str2rcolor(rc
, str
, &rcolor
);
405 image
= RCreateImage(width
, height
, False
);
406 RClearImage(image
, &rcolor
);
407 } else if (strcasecmp(&type
[1], "gradient")==0) {
411 switch (toupper(type
[0])) {
413 style
= RVerticalGradient
;
416 style
= RHorizontalGradient
;
420 style
= RDiagonalGradient
;
424 str
= PLGetString(PLGetArrayElement(texture
, 1));
425 str2rcolor(rc
, str
, &rcolor
);
426 str
= PLGetString(PLGetArrayElement(texture
, 2));
427 str2rcolor(rc
, str
, &rcolor2
);
429 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
430 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
434 RImage
*grad
, *timage
;
437 switch (toupper(type
[1])) {
439 style
= RVerticalGradient
;
442 style
= RHorizontalGradient
;
446 style
= RDiagonalGradient
;
450 str
= PLGetString(PLGetArrayElement(texture
, 3));
451 str2rcolor(rc
, str
, &rcolor
);
452 str
= PLGetString(PLGetArrayElement(texture
, 4));
453 str2rcolor(rc
, str
, &rcolor2
);
455 str
= PLGetString(PLGetArrayElement(texture
, 1));
457 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
458 timage
= RLoadImage(rc
, path
, 0);
461 wwarning("could not load file '%s': %s", path
,
462 RMessageForError(RErrorCode
));
464 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
466 image
= RMakeTiledImage(timage
, width
, height
);
467 RDestroyImage(timage
);
469 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
471 RCombineImagesWithOpaqueness(image
, grad
, i
);
474 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
479 switch (toupper(type
[1])) {
481 style
= RVerticalGradient
;
484 style
= RHorizontalGradient
;
488 style
= RDiagonalGradient
;
492 j
= PLGetNumberOfElements(texture
);
495 colors
= wmalloc(j
* sizeof(RColor
*));
497 for (i
= 2; i
< j
; i
++) {
498 str
= PLGetString(PLGetArrayElement(texture
, i
));
499 colors
[i
-2] = wmalloc(sizeof(RColor
));
500 str2rcolor(rc
, str
, colors
[i
-2]);
504 image
= RRenderMultiGradient(width
, height
, colors
, style
);
506 for (i
= 0; colors
[i
]!=NULL
; i
++)
510 } else if (strcasecmp(&type
[1], "pixmap")==0) {
511 RImage
*timage
= NULL
;
515 str
= PLGetString(PLGetArrayElement(texture
, 1));
517 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
519 timage
= RLoadImage(rc
, path
, 0);
522 wwarning("could not load file '%s': %s", path
? path
: str
,
523 RMessageForError(RErrorCode
));
525 str
= PLGetString(PLGetArrayElement(texture
, 2));
526 str2rcolor(rc
, str
, &color
);
528 switch (toupper(type
[0])) {
530 image
= RMakeTiledImage(timage
, width
, height
);
531 RDestroyImage(timage
);
535 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
536 RDestroyImage(timage
);
541 image
= RScaleImage(timage
, width
, height
);
542 RDestroyImage(timage
);
555 dumpRImage(path
, image
);
559 if (border
== RESIZEBAR_BEVEL
) {
560 drawResizebarBevel(image
);
561 } else if (border
== MENU_BEVEL
) {
562 drawMenuBevel(image
);
563 RBevelImage(image
, RBEV_RAISED2
);
566 RBevelImage(image
, border
);
569 RConvertImage(rc
, image
, &pixmap
);
570 RDestroyImage(image
);
577 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
579 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
580 Display
*dpy
= WMScreenDisplay(scr
);
582 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
585 switch (panel
->menuStyle
) {
587 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
589 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*4, WMScreenDepth(scr
));
590 for (i
= 0; i
< 4; i
++) {
591 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
,
594 XFreePixmap(dpy
, tmp
);
597 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, MENU_BEVEL
);
600 pix
= renderTexture(scr
, texture
, width
, iheight
*4, NULL
, RBEV_RAISED2
);
610 updatePreviewBox(_Panel
*panel
, int elements
)
612 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
613 Display
*dpy
= WMScreenDisplay(scr
);
614 /* RContext *rc = WMScreenRContext(scr);*/
619 TextureListItem
*titem
;
621 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
624 if (!panel
->preview
) {
627 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
628 240-4, 215-4, WMScreenDepth(scr
));
630 color
= WMGrayColor(scr
);
631 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
633 WMReleaseColor(color
);
638 if (elements
& FTITLE
) {
639 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
640 titem
= (TextureListItem
*)item
->clientData
;
642 pix
= renderTexture(scr
, titem
->prop
, 190, 20, NULL
, RBEV_RAISED2
);
644 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 10);
646 XFreePixmap(dpy
, pix
);
648 if (elements
& UTITLE
) {
649 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
650 titem
= (TextureListItem
*)item
->clientData
;
652 pix
= renderTexture(scr
, titem
->prop
, 190, 20, NULL
, RBEV_RAISED2
);
654 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 40);
656 XFreePixmap(dpy
, pix
);
658 if (elements
& OTITLE
) {
659 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
660 titem
= (TextureListItem
*)item
->clientData
;
662 pix
= renderTexture(scr
, titem
->prop
, 190, 20, NULL
, RBEV_RAISED2
);
664 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 70);
666 XFreePixmap(dpy
, pix
);
668 if (elements
& RESIZEBAR
) {
669 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
670 titem
= (TextureListItem
*)item
->clientData
;
672 pix
= renderTexture(scr
, titem
->prop
, 190, 9, NULL
, RESIZEBAR_BEVEL
);
674 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 100);
676 XFreePixmap(dpy
, pix
);
678 if (elements
& MTITLE
) {
679 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
680 titem
= (TextureListItem
*)item
->clientData
;
682 pix
= renderTexture(scr
, titem
->prop
, 90, 20, NULL
, RBEV_RAISED2
);
684 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 90, 20, 30, 120);
686 XFreePixmap(dpy
, pix
);
688 if (elements
& MITEM
) {
689 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
690 titem
= (TextureListItem
*)item
->clientData
;
692 pix
= renderMenu(panel
, titem
->prop
, 90, 18);
694 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 90, 18*4, 30, 140);
696 XFreePixmap(dpy
, pix
);
698 if (elements
& (MITEM
|MTITLE
)) {
699 XDrawLine(dpy
, panel
->preview
, gc
, 29, 120, 29, 120+18*4+20);
700 XDrawLine(dpy
, panel
->preview
, gc
, 29, 119, 119, 119);
703 if (elements
& ICON
) {
704 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
705 titem
= (TextureListItem
*)item
->clientData
;
707 pix
= renderTexture(scr
, titem
->prop
, 64, 64, NULL
,
708 titem
->ispixmap
? 0 : RBEV_RAISED3
);
710 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 64, 64, 155, 130);
712 XFreePixmap(dpy
, pix
);
717 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
718 240-4, 215-4, WMScreenDepth(scr
));
720 WMSetLabelImage(panel
->prevL
, p
);
723 WMRedisplayWidget(panel
->prevL
);
733 cancelNewTexture(void *data
)
735 _Panel
*panel
= (_Panel
*)data
;
737 HideTexturePanel(panel
->texturePanel
);
744 makeFileName(char *prefix
)
748 fname
= wstrdup(prefix
);
750 while (access(fname
, F_OK
)==0) {
754 sprintf(buf
, "%08lx.cache", time(NULL
));
755 fname
= wstrappend(prefix
, buf
);
765 okNewTexture(void *data
)
767 _Panel
*panel
= (_Panel
*)data
;
772 TextureListItem
*titem
;
773 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
775 titem
= wmalloc(sizeof(TextureListItem
));
776 memset(titem
, 0, sizeof(TextureListItem
));
778 HideTexturePanel(panel
->texturePanel
);
780 name
= GetTexturePanelTextureName(panel
->texturePanel
);
782 prop
= GetTexturePanelTexture(panel
->texturePanel
);
784 str
= PLGetDescription(prop
);
788 titem
->texture
= str
;
789 titem
->selectedFor
= 0;
791 titem
->ispixmap
= isPixmap(prop
);
793 titem
->path
= makeFileName(panel
->fprefix
);
794 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
797 item
= WMAddListItem(panel
->texLs
, "");
798 item
->clientData
= titem
;
800 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
805 okEditTexture(void *data
)
807 _Panel
*panel
= (_Panel
*)data
;
812 TextureListItem
*titem
;
814 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
815 titem
= (TextureListItem
*)item
->clientData
;
817 HideTexturePanel(panel
->texturePanel
);
819 if (titem
->current
) {
820 name
= GetTexturePanelTextureName(panel
->texturePanel
);
826 prop
= GetTexturePanelTexture(panel
->texturePanel
);
828 str
= PLGetDescription(prop
);
830 PLRelease(titem
->prop
);
833 titem
->ispixmap
= isPixmap(prop
);
835 free(titem
->texture
);
836 titem
->texture
= str
;
838 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
839 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
840 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
843 WMRedisplayWidget(panel
->texLs
);
845 if (titem
->selectedFor
)
846 updatePreviewBox(panel
, titem
->selectedFor
);
848 changePage(panel
->secP
, panel
);
854 editTexture(WMWidget
*w
, void *data
)
856 _Panel
*panel
= (_Panel
*)data
;
858 TextureListItem
*titem
;
860 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
861 titem
= (TextureListItem
*)item
->clientData
;
863 SetTexturePanelPixmapPath(panel
->texturePanel
,
864 GetObjectForKey("PixmapPath"));
866 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
868 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
869 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
871 ShowTexturePanel(panel
->texturePanel
);
877 newTexture(WMWidget
*w
, void *data
)
879 _Panel
*panel
= (_Panel
*)data
;
881 SetTexturePanelPixmapPath(panel
->texturePanel
,
882 GetObjectForKey("PixmapPath"));
884 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
886 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
888 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
890 ShowTexturePanel(panel
->texturePanel
);
896 deleteTexture(WMWidget
*w
, void *data
)
898 _Panel
*panel
= (_Panel
*)data
;
900 TextureListItem
*titem
;
904 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
905 row
= WMGetListSelectedItemRow(panel
->texLs
);
906 item
= WMGetListItem(panel
->texLs
, row
);
907 titem
= (TextureListItem
*)item
->clientData
;
909 if (titem
->selectedFor
& (1 << section
)) {
910 TextureListItem
*titem2
;
912 panel
->textureIndex
[section
] = section
;
913 item
= WMGetListItem(panel
->texLs
, section
);
914 titem2
= (TextureListItem
*)item
->clientData
;
915 titem2
->selectedFor
|= 1 << section
;
919 free(titem
->texture
);
920 PLRelease(titem
->prop
);
922 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
923 wsyserror("could not remove file %s", titem
->path
);
930 WMRemoveListItem(panel
->texLs
, row
);
931 WMSetButtonEnabled(panel
->delB
, False
);
938 extractTexture(WMWidget
*w
, void *data
)
940 _Panel
*panel
= (_Panel
*)data
;
943 WMScreen
*scr
= WMWidgetScreen(w
);
945 opanel
= WMGetOpenPanel(scr
);
946 WMSetFilePanelCanChooseDirectories(opanel
, False
);
947 WMSetFilePanelCanChooseFiles(opanel
, True
);
949 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
950 _("Select File"), NULL
)) {
951 path
= WMGetFilePanelFileName(opanel
);
953 OpenExtractPanelFor(panel
, path
);
961 changePage(WMWidget
*w
, void *data
)
963 _Panel
*panel
= (_Panel
*)data
;
966 TextureListItem
*titem
;
967 WMScreen
*scr
= WMWidgetScreen(w
);
968 RContext
*rc
= WMScreenRContext(scr
);
969 static WMPoint positions
[] = {
979 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
981 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
983 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
985 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
987 titem
= (TextureListItem
*)item
->clientData
;
992 color
= WMGrayColor(scr
);
993 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
994 positions
[panel
->oldsection
].x
,
995 positions
[panel
->oldsection
].y
, 22, 22);
996 WMReleaseColor(color
);
998 panel
->oldsection
= section
;
999 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
1000 positions
[section
].y
);
1002 WMRedisplayWidget(panel
->prevL
);
1008 previewClick(XEvent
*event
, void *clientData
)
1010 _Panel
*panel
= (_Panel
*)clientData
;
1012 static WMRect parts
[] = {
1013 {{30,10},{190, 20}},
1018 {{30,140},{90,18*4}},
1022 for (i
= 0; i
< 7; i
++) {
1023 if (event
->xbutton
.x
>= parts
[i
].pos
.x
1024 && event
->xbutton
.y
>= parts
[i
].pos
.y
1025 && event
->xbutton
.x
< parts
[i
].pos
.x
+ parts
[i
].size
.width
1026 && event
->xbutton
.y
< parts
[i
].pos
.y
+ parts
[i
].size
.height
) {
1028 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1029 changePage(panel
->secP
, panel
);
1037 textureClick(WMWidget
*w
, void *data
)
1039 _Panel
*panel
= (_Panel
*)data
;
1042 TextureListItem
*titem
;
1044 i
= WMGetListSelectedItemRow(panel
->texLs
);
1046 item
= WMGetListItem(panel
->texLs
, i
);
1048 titem
= (TextureListItem
*)item
->clientData
;
1050 if (titem
->current
) {
1051 WMSetButtonEnabled(panel
->delB
, False
);
1053 WMSetButtonEnabled(panel
->delB
, True
);
1060 textureDoubleClick(WMWidget
*w
, void *data
)
1062 _Panel
*panel
= (_Panel
*)data
;
1065 TextureListItem
*titem
;
1067 /* unselect old texture */
1068 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1070 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1071 titem
= (TextureListItem
*)item
->clientData
;
1072 titem
->selectedFor
&= ~(1 << section
);
1074 /* select new texture */
1075 i
= WMGetListSelectedItemRow(panel
->texLs
);
1077 item
= WMGetListItem(panel
->texLs
, i
);
1079 titem
= (TextureListItem
*)item
->clientData
;
1081 titem
->selectedFor
|= 1<<section
;
1083 panel
->textureIndex
[section
] = i
;
1085 WMRedisplayWidget(panel
->texLs
);
1087 updatePreviewBox(panel
, 1<<section
);
1094 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
1097 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
1098 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1099 int width
, height
, x
, y
;
1100 Display
*dpy
= WMScreenDisplay(scr
);
1101 WMColor
*white
= WMWhiteColor(scr
);
1103 WMColor
*black
= WMBlackColor(scr
);
1104 TextureListItem
*titem
;
1106 width
= rect
->size
.width
;
1107 height
= rect
->size
.height
;
1111 if (state
& WLDSSelected
)
1112 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1114 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
1116 item
= WMGetListItem(lPtr
, index
);
1117 titem
= (TextureListItem
*)item
->clientData
;
1120 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0, TEXPREV_WIDTH
,
1121 TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1123 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1124 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1125 else if (titem
->selectedFor
)
1126 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1128 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
1129 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
1130 strlen(titem
->title
));
1132 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
1133 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
1134 strlen(titem
->texture
));
1137 WMReleaseColor(white
);
1138 WMReleaseColor(black
);
1144 loadRImage(WMScreen
*scr
, char *path
)
1152 f
= fopen(path
, "r");
1156 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1158 image
= RCreateImage(w
, h
, d
== 4);
1159 for (i
= 0; i
< d
; i
++) {
1160 fread(image
->data
[i
], 1, w
*h
, f
);
1164 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1165 RDestroyImage(image
);
1173 fillTextureList(WMList
*lPtr
)
1175 proplist_t textureList
;
1177 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1179 TextureListItem
*titem
;
1180 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1182 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1186 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1189 texture
= PLGetArrayElement(textureList
, i
);
1191 titem
= wmalloc(sizeof(TextureListItem
));
1192 memset(titem
, 0, sizeof(TextureListItem
));
1194 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1195 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1196 titem
->texture
= PLGetDescription(titem
->prop
);
1197 titem
->selectedFor
= 0;
1198 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1200 titem
->preview
= loadRImage(scr
, titem
->path
);
1201 if (!titem
->preview
) {
1202 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1203 TEXPREV_HEIGHT
, NULL
, 0);
1205 item
= WMAddListItem(lPtr
, "");
1206 item
->clientData
= titem
;
1212 menuStyleCallback(WMWidget
*self
, void *data
)
1214 _Panel
*panel
= (_Panel
*)data
;
1216 if (self
== panel
->mstyB
[0]) {
1217 panel
->menuStyle
= MSTYLE_NORMAL
;
1218 updatePreviewBox(panel
, MITEM
);
1220 } else if (self
== panel
->mstyB
[1]) {
1221 panel
->menuStyle
= MSTYLE_SINGLE
;
1222 updatePreviewBox(panel
, MITEM
);
1224 } else if (self
== panel
->mstyB
[2]) {
1225 panel
->menuStyle
= MSTYLE_FLAT
;
1226 updatePreviewBox(panel
, MITEM
);
1232 createPanel(Panel
*p
)
1234 _Panel
*panel
= (_Panel
*)p
;
1236 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1237 WMTabViewItem
*item
;
1242 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
1244 if (access(panel
->fprefix
, F_OK
)!=0) {
1245 if (mkdir(panel
->fprefix
, 0755) < 0) {
1246 wsyserror(panel
->fprefix
);
1251 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
1252 free(panel
->fprefix
);
1253 panel
->fprefix
= tmp
;
1254 if (access(panel
->fprefix
, F_OK
)!=0) {
1255 if (mkdir(panel
->fprefix
, 0755) < 0) {
1256 wsyserror(panel
->fprefix
);
1261 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1262 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1263 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1265 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1266 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1267 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1269 panel
->frame
= WMCreateFrame(panel
->win
);
1270 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1271 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1274 panel
->prevL
= WMCreateLabel(panel
->frame
);
1275 WMResizeWidget(panel
->prevL
, 240, FRAME_HEIGHT
- 20);
1276 WMMoveWidget(panel
->prevL
, 15, 10);
1277 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1278 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1280 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1281 previewClick
, panel
);
1286 panel
->tabv
= WMCreateTabView(panel
->frame
);
1287 WMResizeWidget(panel
->tabv
, 245, FRAME_HEIGHT
- 20);
1288 WMMoveWidget(panel
->tabv
, 265, 10);
1290 /*** texture list ***/
1292 panel
->texF
= WMCreateFrame(panel
->frame
);
1293 WMSetFrameRelief(panel
->texF
, WRFlat
);
1295 item
= WMCreateTabViewItemWithIdentifier(0);
1296 WMSetTabViewItemView(item
, WMWidgetView(panel
->texF
));
1297 WMSetTabViewItemLabel(item
, _("Texture"));
1299 WMAddItemInTabView(panel
->tabv
, item
);
1302 panel
->secP
= WMCreatePopUpButton(panel
->texF
);
1303 WMResizeWidget(panel
->secP
, 228, 20);
1304 WMMoveWidget(panel
->secP
, 7, 7);
1305 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1306 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1307 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1308 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1309 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1310 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1311 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1312 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1313 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1315 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1317 panel
->texLs
= WMCreateList(panel
->texF
);
1318 WMResizeWidget(panel
->texLs
, 165, 155);
1319 WMMoveWidget(panel
->texLs
, 70, 33);
1320 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1321 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1322 WMHangData(panel
->texLs
, panel
);
1323 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1324 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1326 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1327 "for the selected item."),
1328 WMWidgetView(panel
->texLs
));
1330 /* command buttons */
1332 font
= WMSystemFontOfSize(scr
, 10);
1335 panel
->newB
= WMCreateCommandButton(panel
->texF
);
1336 WMResizeWidget(panel
->newB
, 57, 39);
1337 WMMoveWidget(panel
->newB
, 7, 33);
1338 WMSetButtonFont(panel
->newB
, font
);
1339 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1340 WMSetButtonText(panel
->newB
, _("New"));
1341 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1342 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1344 WMSetBalloonTextForView(_("Create a new texture."),
1345 WMWidgetView(panel
->newB
));
1347 panel
->ripB
= WMCreateCommandButton(panel
->texF
);
1348 WMResizeWidget(panel
->ripB
, 57, 39);
1349 WMMoveWidget(panel
->ripB
, 7, 72);
1350 WMSetButtonFont(panel
->ripB
, font
);
1351 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1352 WMSetButtonText(panel
->ripB
, _("Extract..."));
1353 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1354 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1356 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1357 WMWidgetView(panel
->ripB
));
1359 WMSetButtonEnabled(panel
->ripB
, False
);
1361 panel
->editB
= WMCreateCommandButton(panel
->texF
);
1362 WMResizeWidget(panel
->editB
, 57, 39);
1363 WMMoveWidget(panel
->editB
, 7, 111);
1364 WMSetButtonFont(panel
->editB
, font
);
1365 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1366 WMSetButtonText(panel
->editB
, _("Edit"));
1367 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1368 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1369 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1370 WMWidgetView(panel
->editB
));
1372 panel
->delB
= WMCreateCommandButton(panel
->texF
);
1373 WMResizeWidget(panel
->delB
, 57, 38);
1374 WMMoveWidget(panel
->delB
, 7, 150);
1375 WMSetButtonFont(panel
->delB
, font
);
1376 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1377 WMSetButtonText(panel
->delB
, _("Delete"));
1378 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1379 WMSetButtonEnabled(panel
->delB
, False
);
1380 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1381 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1382 WMWidgetView(panel
->delB
));
1384 WMReleaseFont(font
);
1386 WMMapSubwidgets(panel
->texF
);
1389 panel
->colF
= WMCreateFrame(panel
->frame
);
1390 WMSetFrameRelief(panel
->colF
, WRFlat
);
1392 item
= WMCreateTabViewItemWithIdentifier(1);
1393 WMSetTabViewItemView(item
, WMWidgetView(panel
->colF
));
1394 WMSetTabViewItemLabel(item
, _("Color"));
1396 WMAddItemInTabView(panel
->tabv
, item
);
1400 panel
->optF
= WMCreateFrame(panel
->frame
);
1401 WMSetFrameRelief(panel
->optF
, WRFlat
);
1403 item
= WMCreateTabViewItemWithIdentifier(2);
1404 WMSetTabViewItemView(item
, WMWidgetView(panel
->optF
));
1405 WMSetTabViewItemLabel(item
, _("Options"));
1407 WMAddItemInTabView(panel
->tabv
, item
);
1409 panel
->mstyF
= WMCreateFrame(panel
->optF
);
1410 WMResizeWidget(panel
->mstyF
, 215, 85);
1411 WMMoveWidget(panel
->mstyF
, 15, 10);
1412 WMSetFrameTitle(panel
->mstyF
, _("Menu Style"));
1414 for (i
= 0; i
< 3; i
++) {
1418 panel
->mstyB
[i
] = WMCreateButton(panel
->mstyF
, WBTOnOff
);
1419 WMResizeWidget(panel
->mstyB
[i
], 54, 54);
1420 WMMoveWidget(panel
->mstyB
[i
], 15 + i
*65, 20);
1421 WMSetButtonImagePosition(panel
->mstyB
[i
], WIPImageOnly
);
1422 WMSetButtonAction(panel
->mstyB
[i
], menuStyleCallback
, panel
);
1425 path
= LocateImage(MSTYLE1_FILE
);
1428 path
= LocateImage(MSTYLE2_FILE
);
1431 path
= LocateImage(MSTYLE3_FILE
);
1435 icon
= WMCreatePixmapFromFile(scr
, path
);
1437 WMSetButtonImage(panel
->mstyB
[i
], icon
);
1438 WMReleasePixmap(icon
);
1440 wwarning(_("could not load icon file %s"), path
);
1445 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[1]);
1446 WMGroupButtons(panel
->mstyB
[0], panel
->mstyB
[2]);
1448 WMMapSubwidgets(panel
->mstyF
);
1450 WMMapSubwidgets(panel
->optF
);
1454 WMRealizeWidget(panel
->frame
);
1455 WMMapSubwidgets(panel
->frame
);
1457 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1461 changePage(panel
->secP
, panel
);
1463 fillTextureList(panel
->texLs
);
1465 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1471 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1475 TextureListItem
*titem
;
1477 titem
= wmalloc(sizeof(TextureListItem
));
1478 memset(titem
, 0, sizeof(TextureListItem
));
1480 titem
->title
= wstrdup(title
);
1481 titem
->prop
= GetObjectForKey(key
);
1483 titem
->prop
= PLGetProplistWithDescription(defValue
);
1485 PLRetain(titem
->prop
);
1487 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1489 titem
->selectedFor
= 1<<index
;
1491 titem
->ispixmap
= isPixmap(titem
->prop
);
1493 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1494 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1496 item
= WMAddListItem(list
, "");
1497 item
->clientData
= titem
;
1503 showData(_Panel
*panel
)
1508 str
= GetStringForKey("MenuStyle");
1509 if (str
&& strcasecmp(str
, "flat")==0) {
1510 panel
->menuStyle
= MSTYLE_FLAT
;
1511 } else if (str
&& strcasecmp(str
, "singletexture")==0) {
1512 panel
->menuStyle
= MSTYLE_SINGLE
;
1514 panel
->menuStyle
= MSTYLE_NORMAL
;
1517 setupTextureFor(panel
->texLs
, "FTitleBack", "(solid, black)",
1519 panel
->textureIndex
[i
] = i
++;
1521 setupTextureFor(panel
->texLs
, "UTitleBack", "(solid, gray)",
1523 panel
->textureIndex
[i
] = i
++;
1525 setupTextureFor(panel
->texLs
, "PTitleBack", "(solid, \"#616161\")",
1526 "[Owner of Focused]", i
);
1527 panel
->textureIndex
[i
] = i
++;
1529 setupTextureFor(panel
->texLs
, "ResizebarBack", "(solid, gray)",
1531 panel
->textureIndex
[i
] = i
++;
1533 setupTextureFor(panel
->texLs
, "MenuTitleBack", "(solid, black)",
1535 panel
->textureIndex
[i
] = i
++;
1537 setupTextureFor(panel
->texLs
, "MenuTextBack", "(solid, gray)",
1539 panel
->textureIndex
[i
] = i
++;
1541 setupTextureFor(panel
->texLs
, "IconBack", "(solid, gray)", "[Icon]", i
);
1542 panel
->textureIndex
[i
] = i
++;
1544 setupTextureFor(panel->texLs, "WorkspaceBack", "(solid, black)",
1546 panel->textureIndex[i] = i++;
1549 updatePreviewBox(panel
, EVERYTHING
);
1555 storeData(_Panel
*panel
)
1557 TextureListItem
*titem
;
1560 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
1561 titem
= (TextureListItem
*)item
->clientData
;
1562 SetObjectForKey(titem
->prop
, "FTitleBack");
1564 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
1565 titem
= (TextureListItem
*)item
->clientData
;
1566 SetObjectForKey(titem
->prop
, "UTitleBack");
1568 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
1569 titem
= (TextureListItem
*)item
->clientData
;
1570 SetObjectForKey(titem
->prop
, "PTitleBack");
1572 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
1573 titem
= (TextureListItem
*)item
->clientData
;
1574 SetObjectForKey(titem
->prop
, "ResizebarBack");
1576 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
1577 titem
= (TextureListItem
*)item
->clientData
;
1578 SetObjectForKey(titem
->prop
, "MenuTitleBack");
1580 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
1581 titem
= (TextureListItem
*)item
->clientData
;
1582 SetObjectForKey(titem
->prop
, "MenuTextBack");
1584 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
1585 titem
= (TextureListItem
*)item
->clientData
;
1586 SetObjectForKey(titem
->prop
, "IconBack");
1588 switch (panel
->menuStyle
) {
1590 SetStringForKey("singletexture", "MenuStyle");
1593 SetStringForKey("flat", "MenuStyle");
1597 SetStringForKey("normal", "MenuStyle");
1604 prepareForClose(_Panel
*panel
)
1606 proplist_t textureList
;
1609 TextureListItem
*titem
;
1611 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1613 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
1615 /* store list of textures */
1616 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
1617 item
= WMGetListItem(panel
->texLs
, i
);
1618 titem
= (TextureListItem
*)item
->clientData
;
1620 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
1621 PLRetain(titem
->prop
),
1622 PLMakeString(titem
->path
),
1625 PLAppendArrayElement(textureList
, texture
);
1628 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
1629 PLRelease(textureList
);
1631 WMSynchronizeUserDefaults(udb
);
1637 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
1641 panel
= wmalloc(sizeof(_Panel
));
1642 memset(panel
, 0, sizeof(_Panel
));
1644 panel
->sectionName
= _("Appearance Preferences");
1646 panel
->description
= _("Background texture configuration for windows,\n"
1647 "menus and icons.");
1651 panel
->callbacks
.createWidgets
= createPanel
;
1652 panel
->callbacks
.updateDomain
= storeData
;
1653 panel
->callbacks
.prepareForClose
= prepareForClose
;
1655 AddSection(panel
, ICON_FILE
);
1662 /****************************************************************************/
1666 typedef struct ExtractPanel
{
1679 OpenExtractPanelFor(_Panel
*panel
, char *path
)
1681 ExtractPanel
*epanel
;
1684 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1686 epanel
= wmalloc(sizeof(ExtractPanel
));
1687 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
1689 |WMClosableWindowMask
);
1690 WMResizeWidget(epanel
->win
, 245, 250);
1691 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
1693 epanel
->label
= WMCreateLabel(epanel
->win
);
1694 WMResizeWidget(epanel
->label
, 225, 18);
1695 WMMoveWidget(epanel
->label
, 10, 10);
1696 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
1697 WMSetLabelRelief(epanel
->label
, WRSunken
);
1699 color
= WMDarkGrayColor(scr
);
1700 WMSetWidgetBackgroundColor(epanel
->label
, color
);
1701 WMReleaseColor(color
);
1703 color
= WMWhiteColor(scr
);
1704 WMSetLabelTextColor(epanel
->label
, color
);
1705 WMReleaseColor(color
);
1707 font
= WMBoldSystemFontOfSize(scr
, 12);
1708 WMSetLabelFont(epanel
->label
, font
);
1709 WMReleaseFont(font
);
1711 WMSetLabelText(epanel
->label
, _("Textures"));
1713 epanel
->list
= WMCreateList(epanel
->win
);
1714 WMResizeWidget(epanel
->list
, 225, 165);
1715 WMMoveWidget(epanel
->list
, 10, 30);
1719 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
1720 WMResizeWidget(epanel
->closeB
, 74, 24);
1721 WMMoveWidget(epanel
->closeB
, 165, 215);
1722 WMSetButtonText(epanel
->closeB
, _("Close"));
1724 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
1725 WMResizeWidget(epanel
->extrB
, 74, 24);
1726 WMMoveWidget(epanel
->extrB
, 80, 215);
1727 WMSetButtonText(epanel
->extrB
, _("Extract"));
1729 WMMapSubwidgets(epanel
->win
);
1732 /* take textures from file */
1736 WMRealizeWidget(epanel
->win
);
1738 WMMapWidget(epanel
->win
);