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
;
70 TexturePanel
*texturePanel
;
98 static void showData(_Panel
*panel
);
100 static void changePage(WMWidget
*w
, void *data
);
102 static void OpenExtractPanelFor(_Panel
*panel
, char *path
);
104 #define ICON_FILE "appearance"
106 #define TNEW_FILE "tnew"
107 #define TDEL_FILE "tdel"
108 #define TEDIT_FILE "tedit"
109 #define TEXTR_FILE "textr"
114 static char * blueled_xpm
[] = {
144 static char *blueled2_xpm
[] = {
145 /* width height num_colors chars_per_pixel */
177 static char * hand_xpm
[] = {
199 " .))),%.......... ",
200 " .)-)),&)))))))))$. ",
201 " .-&))))))))),,,,;;. ",
202 " .=)))))))));-=***&$. ",
203 " .=)))))))),..+..... ",
221 #define FTITLE (1<<0)
222 #define UTITLE (1<<1)
223 #define OTITLE (1<<2)
224 #define RESIZEBAR (1<<3)
225 #define MTITLE (1<<4)
229 #define EVERYTHING 0xff
232 #define RESIZEBAR_BEVEL -1
233 #define MENU_BEVEL -2
235 #define TEXPREV_WIDTH 40
236 #define TEXPREV_HEIGHT 24
243 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
247 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
250 color
->red
= xcolor
.red
>> 8;
251 color
->green
= xcolor
.green
>> 8;
252 color
->blue
= xcolor
.blue
>> 8;
258 dumpRImage(char *path
, RImage
*image
)
262 f
= fopen(path
, "w");
267 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
,
268 image
->data
[3]!=NULL
? 4 : 3);
270 fwrite(image
->data
[0], 1, image
->width
* image
->height
, f
);
271 fwrite(image
->data
[1], 1, image
->width
* image
->height
, f
);
272 fwrite(image
->data
[2], 1, image
->width
* image
->height
, f
);
274 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
284 isPixmap(proplist_t prop
)
289 p
= PLGetArrayElement(prop
, 0);
291 if (strcasecmp(&s
[1], "pixmap")==0)
299 drawResizebarBevel(RImage
*img
)
304 int width
= img
->width
;
305 int height
= img
->height
;
309 black
.red
= black
.green
= black
.blue
= 0;
312 light
.red
= light
.green
= light
.blue
= 80;
315 dark
.red
= dark
.green
= dark
.blue
= 40;
317 ROperateLine(img
, RSubtractOperation
, 0, 0, width
-1, 0, &dark
);
318 ROperateLine(img
, RAddOperation
, 0, 1, width
-1, 1, &light
);
320 ROperateLine(img
, RSubtractOperation
, cwidth
, 2, cwidth
, height
-1, &dark
);
321 ROperateLine(img
, RAddOperation
, cwidth
+1, 2, cwidth
+1, height
-1, &light
);
323 ROperateLine(img
, RSubtractOperation
, width
-cwidth
-2, 2, width
-cwidth
-2,
325 ROperateLine(img
, RAddOperation
, width
-cwidth
-1, 2, width
-cwidth
-1,
328 RDrawLine(img
, 0, height
-1, width
-1, height
-1, &black
);
329 RDrawLine(img
, 0, 0, 0, height
-1, &black
);
330 RDrawLine(img
, width
-1, 0, width
-1, height
-1, &black
);
335 drawMenuBevel(RImage
*img
)
337 RColor light
, dark
, mid
;
339 int iheight
= img
->height
/ 3;
342 light
.red
= light
.green
= light
.blue
= 80;
345 dark
.red
= dark
.green
= dark
.blue
= 0;
348 mid
.red
= mid
.green
= mid
.blue
= 40;
350 for (i
= 1; i
< 3; i
++) {
351 ROperateLine(img
, RSubtractOperation
, 0, i
*iheight
-2,
352 img
->width
-1, i
*iheight
-2, &mid
);
354 RDrawLine(img
, 0, i
*iheight
-1,
355 img
->width
-1, i
*iheight
-1, &dark
);
357 ROperateLine(img
, RAddOperation
, 0, i
*iheight
,
358 img
->width
-1, i
*iheight
, &light
);
364 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
365 char *path
, int border
)
370 RContext
*rc
= WMScreenRContext(scr
);
375 type
= PLGetString(PLGetArrayElement(texture
, 0));
377 image
= RCreateImage(width
, height
, False
);
379 if (strcasecmp(type
, "solid")==0) {
381 str
= PLGetString(PLGetArrayElement(texture
, 1));
383 str2rcolor(rc
, str
, &rcolor
);
385 RClearImage(image
, &rcolor
);
386 } else if (strcasecmp(&type
[1], "gradient")==0) {
390 switch (toupper(type
[0])) {
392 style
= RVerticalGradient
;
395 style
= RHorizontalGradient
;
399 style
= RDiagonalGradient
;
403 str
= PLGetString(PLGetArrayElement(texture
, 1));
404 str2rcolor(rc
, str
, &rcolor
);
405 str
= PLGetString(PLGetArrayElement(texture
, 2));
406 str2rcolor(rc
, str
, &rcolor2
);
408 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
409 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
413 RImage
*grad
, *timage
;
416 switch (toupper(type
[1])) {
418 style
= RVerticalGradient
;
421 style
= RHorizontalGradient
;
425 style
= RDiagonalGradient
;
429 str
= PLGetString(PLGetArrayElement(texture
, 3));
430 str2rcolor(rc
, str
, &rcolor
);
431 str
= PLGetString(PLGetArrayElement(texture
, 4));
432 str2rcolor(rc
, str
, &rcolor2
);
434 str
= PLGetString(PLGetArrayElement(texture
, 1));
436 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
437 timage
= RLoadImage(rc
, path
, 0);
440 wwarning("could not load file '%s': %s", path
,
441 RMessageForError(RErrorCode
));
443 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
445 image
= RMakeTiledImage(timage
, width
, height
);
446 RDestroyImage(timage
);
448 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
450 RCombineImagesWithOpaqueness(image
, grad
, i
);
453 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
458 switch (toupper(type
[1])) {
460 style
= RVerticalGradient
;
463 style
= RHorizontalGradient
;
467 style
= RDiagonalGradient
;
471 j
= PLGetNumberOfElements(texture
);
474 colors
= wmalloc(j
* sizeof(RColor
*));
476 for (i
= 2; i
< j
; i
++) {
477 str
= PLGetString(PLGetArrayElement(texture
, i
));
478 colors
[i
-2] = wmalloc(sizeof(RColor
));
479 str2rcolor(rc
, str
, colors
[i
-2]);
483 image
= RRenderMultiGradient(width
, height
, colors
, style
);
485 for (i
= 0; colors
[i
]!=NULL
; i
++)
489 } else if (strcasecmp(&type
[1], "pixmap")==0) {
494 str
= PLGetString(PLGetArrayElement(texture
, 1));
496 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
497 timage
= RLoadImage(rc
, path
, 0);
500 wwarning("could not load file '%s': %s", path
,
501 RMessageForError(RErrorCode
));
503 str
= PLGetString(PLGetArrayElement(texture
, 2));
504 str2rcolor(rc
, str
, &color
);
506 switch (toupper(type
[0])) {
508 image
= RMakeTiledImage(timage
, width
, height
);
509 RDestroyImage(timage
);
513 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
514 RDestroyImage(timage
);
519 image
= RScaleImage(timage
, width
, height
);
520 RDestroyImage(timage
);
533 dumpRImage(path
, image
);
537 if (border
== RESIZEBAR_BEVEL
) {
538 drawResizebarBevel(image
);
539 } else if (border
== MENU_BEVEL
) {
540 drawMenuBevel(image
);
543 RBevelImage(image
, border
);
546 RConvertImage(rc
, image
, &pixmap
);
547 RDestroyImage(image
);
554 renderMenu(_Panel
*panel
, proplist_t texture
, int width
, int iheight
)
556 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
557 Display
*dpy
= WMScreenDisplay(scr
);
560 GC gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
563 str
= GetStringForKey("MenuStyle");
564 if (!str
|| strcasecmp(str
, "normal")==0) {
567 tmp
= renderTexture(scr
, texture
, width
, iheight
, NULL
, RBEV_RAISED2
);
569 pix
= XCreatePixmap(dpy
, tmp
, width
, iheight
*3,
571 for (i
= 0; i
< 3; i
++) {
572 XCopyArea(dpy
, tmp
, pix
, gc
, 0, 0, width
, iheight
,
575 XFreePixmap(dpy
, tmp
);
576 } else if (strcasecmp(str
, "flat")==0) {
577 pix
= renderTexture(scr
, texture
, width
, iheight
*3, NULL
, RBEV_RAISED2
);
579 pix
= renderTexture(scr
, texture
, width
, iheight
*3, NULL
, MENU_BEVEL
);
589 updatePreviewBox(_Panel
*panel
, int elements
)
591 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
592 Display
*dpy
= WMScreenDisplay(scr
);
593 /* RContext *rc = WMScreenRContext(scr);*/
598 TextureListItem
*titem
;
600 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
603 if (!panel
->preview
) {
606 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
607 260-4, 165-4, WMScreenDepth(scr
));
609 color
= WMGrayColor(scr
);
610 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
612 WMReleaseColor(color
);
617 if (elements
& FTITLE
) {
618 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
619 titem
= (TextureListItem
*)item
->clientData
;
621 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
623 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 5);
625 XFreePixmap(dpy
, pix
);
627 if (elements
& UTITLE
) {
628 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
629 titem
= (TextureListItem
*)item
->clientData
;
631 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
633 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 30);
635 XFreePixmap(dpy
, pix
);
637 if (elements
& OTITLE
) {
638 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
639 titem
= (TextureListItem
*)item
->clientData
;
641 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
643 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 55);
645 XFreePixmap(dpy
, pix
);
647 if (elements
& RESIZEBAR
) {
648 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
649 titem
= (TextureListItem
*)item
->clientData
;
651 pix
= renderTexture(scr
, titem
->prop
, 210, 9, NULL
, RESIZEBAR_BEVEL
);
653 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 80);
655 XFreePixmap(dpy
, pix
);
657 if (elements
& MTITLE
) {
658 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
659 titem
= (TextureListItem
*)item
->clientData
;
661 pix
= renderTexture(scr
, titem
->prop
, 100, 20, NULL
, RBEV_RAISED2
);
663 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 20, 30, 95);
665 XFreePixmap(dpy
, pix
);
667 if (elements
& MITEM
) {
668 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
669 titem
= (TextureListItem
*)item
->clientData
;
671 pix
= renderMenu(panel
, titem
->prop
, 100, 18);
673 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 18*3, 30, 115);
675 XFreePixmap(dpy
, pix
);
677 if (elements
& (MITEM
|MTITLE
)) {
678 XDrawLine(dpy
, panel
->preview
, gc
, 29, 95, 29, 115+36+20);
679 XDrawLine(dpy
, panel
->preview
, gc
, 29, 94, 129, 94);
682 if (elements
& ICON
) {
683 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
684 titem
= (TextureListItem
*)item
->clientData
;
686 pix
= renderTexture(scr
, titem
->prop
, 64, 64, NULL
,
687 titem
->ispixmap
? 0 : RBEV_RAISED3
);
689 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 64, 64, 170, 95);
691 XFreePixmap(dpy
, pix
);
697 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
698 260-4, 165-4, WMScreenDepth(scr
));
700 WMSetLabelImage(panel
->prevL
, p
);
703 WMRedisplayWidget(panel
->prevL
);
713 cancelNewTexture(void *data
)
715 _Panel
*panel
= (_Panel
*)data
;
717 HideTexturePanel(panel
->texturePanel
);
724 makeFileName(char *prefix
)
728 fname
= wstrdup(prefix
);
730 while (access(fname
, F_OK
)==0) {
734 sprintf(buf
, "%08lx.cache", time(NULL
));
735 fname
= wstrappend(prefix
, buf
);
745 okNewTexture(void *data
)
747 _Panel
*panel
= (_Panel
*)data
;
752 TextureListItem
*titem
;
753 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
755 titem
= wmalloc(sizeof(TextureListItem
));
756 memset(titem
, 0, sizeof(TextureListItem
));
758 HideTexturePanel(panel
->texturePanel
);
760 name
= GetTexturePanelTextureName(panel
->texturePanel
);
762 prop
= GetTexturePanelTexture(panel
->texturePanel
);
764 str
= PLGetDescription(prop
);
768 titem
->texture
= str
;
769 titem
->selectedFor
= 0;
771 titem
->ispixmap
= isPixmap(prop
);
773 titem
->path
= makeFileName(panel
->fprefix
);
774 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
777 item
= WMAddListItem(panel
->texLs
, "");
778 item
->clientData
= titem
;
780 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
785 okEditTexture(void *data
)
787 _Panel
*panel
= (_Panel
*)data
;
792 TextureListItem
*titem
;
794 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
795 titem
= (TextureListItem
*)item
->clientData
;
797 HideTexturePanel(panel
->texturePanel
);
799 if (titem
->current
) {
800 name
= GetTexturePanelTextureName(panel
->texturePanel
);
806 prop
= GetTexturePanelTexture(panel
->texturePanel
);
808 str
= PLGetDescription(prop
);
810 PLRelease(titem
->prop
);
813 titem
->ispixmap
= isPixmap(prop
);
815 free(titem
->texture
);
816 titem
->texture
= str
;
818 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
819 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
820 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
823 WMRedisplayWidget(panel
->texLs
);
825 if (titem
->selectedFor
)
826 updatePreviewBox(panel
, titem
->selectedFor
);
828 changePage(panel
->secP
, panel
);
834 editTexture(WMWidget
*w
, void *data
)
836 _Panel
*panel
= (_Panel
*)data
;
838 TextureListItem
*titem
;
840 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
841 titem
= (TextureListItem
*)item
->clientData
;
843 SetTexturePanelPixmapPath(panel
->texturePanel
,
844 GetObjectForKey("PixmapPath"));
846 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
848 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
849 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
851 ShowTexturePanel(panel
->texturePanel
);
857 newTexture(WMWidget
*w
, void *data
)
859 _Panel
*panel
= (_Panel
*)data
;
861 SetTexturePanelPixmapPath(panel
->texturePanel
,
862 GetObjectForKey("PixmapPath"));
864 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
866 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
868 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
870 ShowTexturePanel(panel
->texturePanel
);
876 deleteTexture(WMWidget
*w
, void *data
)
878 _Panel
*panel
= (_Panel
*)data
;
880 TextureListItem
*titem
;
884 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
885 row
= WMGetListSelectedItemRow(panel
->texLs
);
886 item
= WMGetListItem(panel
->texLs
, row
);
887 titem
= (TextureListItem
*)item
->clientData
;
889 if (titem
->selectedFor
& (1 << section
)) {
890 TextureListItem
*titem2
;
892 panel
->textureIndex
[section
] = section
;
893 item
= WMGetListItem(panel
->texLs
, section
);
894 titem2
= (TextureListItem
*)item
->clientData
;
895 titem2
->selectedFor
|= 1 << section
;
899 free(titem
->texture
);
900 PLRelease(titem
->prop
);
902 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
903 wsyserror("could not remove file %s", titem
->path
);
910 WMRemoveListItem(panel
->texLs
, row
);
911 WMSetButtonEnabled(panel
->delB
, False
);
918 extractTexture(WMWidget
*w
, void *data
)
920 _Panel
*panel
= (_Panel
*)data
;
923 WMScreen
*scr
= WMWidgetScreen(w
);
925 opanel
= WMGetOpenPanel(scr
);
926 WMSetFilePanelCanChooseDirectories(opanel
, False
);
927 WMSetFilePanelCanChooseFiles(opanel
, True
);
929 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
930 _("Select File"), NULL
)) {
931 path
= WMGetFilePanelFileName(opanel
);
933 OpenExtractPanelFor(panel
, path
);
941 changePage(WMWidget
*w
, void *data
)
943 _Panel
*panel
= (_Panel
*)data
;
946 TextureListItem
*titem
;
948 WMScreen
*scr
= WMWidgetScreen(w
);
949 RContext
*rc
= WMScreenRContext(scr
);
950 static WMPoint positions
[] = {
960 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
962 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
964 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
] - 2);
966 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
968 titem
= (TextureListItem
*)item
->clientData
;
970 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
971 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
972 WMSetLabelText(panel
->texsL
, str
);
978 color
= WMGrayColor(scr
);
979 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
980 positions
[panel
->oldsection
].x
,
981 positions
[panel
->oldsection
].y
, 22, 22);
982 WMReleaseColor(color
);
984 panel
->oldsection
= section
;
985 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
986 positions
[section
].y
);
988 WMRedisplayWidget(panel
->prevL
);
994 previewClick(XEvent
*event
, void *clientData
)
996 _Panel
*panel
= (_Panel
*)clientData
;
998 static WMRect parts
[] = {
1004 {{30,115},{100,60}},
1008 for (i
= 0; i
< 7; i
++) {
1009 if (event
->xbutton
.x
>= parts
[i
].pos
.x
1010 && event
->xbutton
.y
>= parts
[i
].pos
.y
1011 && event
->xbutton
.x
< parts
[i
].pos
.x
+ parts
[i
].size
.width
1012 && event
->xbutton
.y
< parts
[i
].pos
.y
+ parts
[i
].size
.height
) {
1014 WMSetPopUpButtonSelectedItem(panel
->secP
, i
);
1015 changePage(panel
->secP
, panel
);
1023 textureClick(WMWidget
*w
, void *data
)
1025 _Panel
*panel
= (_Panel
*)data
;
1028 TextureListItem
*titem
;
1030 i
= WMGetListSelectedItemRow(panel
->texLs
);
1032 item
= WMGetListItem(panel
->texLs
, i
);
1034 titem
= (TextureListItem
*)item
->clientData
;
1036 if (titem
->current
) {
1037 WMSetButtonEnabled(panel
->delB
, False
);
1039 WMSetButtonEnabled(panel
->delB
, True
);
1046 textureDoubleClick(WMWidget
*w
, void *data
)
1048 _Panel
*panel
= (_Panel
*)data
;
1051 TextureListItem
*titem
;
1054 /* unselect old texture */
1055 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
1057 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
1058 titem
= (TextureListItem
*)item
->clientData
;
1059 titem
->selectedFor
&= ~(1 << section
);
1061 /* select new texture */
1062 i
= WMGetListSelectedItemRow(panel
->texLs
);
1064 item
= WMGetListItem(panel
->texLs
, i
);
1066 titem
= (TextureListItem
*)item
->clientData
;
1068 titem
->selectedFor
|= 1<<section
;
1070 panel
->textureIndex
[section
] = i
;
1072 WMRedisplayWidget(panel
->texLs
);
1074 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
1075 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
1076 WMSetLabelText(panel
->texsL
, str
);
1079 updatePreviewBox(panel
, 1<<section
);
1086 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
1089 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
1090 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1091 int width
, height
, x
, y
;
1092 Display
*dpy
= WMScreenDisplay(scr
);
1093 WMColor
*white
= WMWhiteColor(scr
);
1095 WMColor
*black
= WMBlackColor(scr
);
1096 TextureListItem
*titem
;
1098 width
= rect
->size
.width
;
1099 height
= rect
->size
.height
;
1103 if (state
& WLDSSelected
)
1104 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
1106 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
1108 item
= WMGetListItem(lPtr
, index
);
1109 titem
= (TextureListItem
*)item
->clientData
;
1112 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0, TEXPREV_WIDTH
,
1113 TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
1115 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
1116 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1117 else if (titem
->selectedFor
)
1118 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
1120 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
1121 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
1122 strlen(titem
->title
));
1124 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
1125 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
1126 strlen(titem
->texture
));
1129 WMReleaseColor(white
);
1130 WMReleaseColor(black
);
1136 loadRImage(WMScreen
*scr
, char *path
)
1144 f
= fopen(path
, "r");
1148 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1150 image
= RCreateImage(w
, h
, d
== 4);
1151 for (i
= 0; i
< d
; i
++) {
1152 fread(image
->data
[i
], 1, w
*h
, f
);
1156 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1157 RDestroyImage(image
);
1165 fillTextureList(WMList
*lPtr
)
1167 proplist_t textureList
;
1169 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1171 TextureListItem
*titem
;
1172 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1174 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1178 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1181 texture
= PLGetArrayElement(textureList
, i
);
1183 titem
= wmalloc(sizeof(TextureListItem
));
1184 memset(titem
, 0, sizeof(TextureListItem
));
1186 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1187 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1188 titem
->texture
= PLGetDescription(titem
->prop
);
1189 titem
->selectedFor
= 0;
1190 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1192 titem
->preview
= loadRImage(scr
, titem
->path
);
1193 if (!titem
->preview
) {
1194 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1195 TEXPREV_HEIGHT
, NULL
, 0);
1197 item
= WMAddListItem(lPtr
, "");
1198 item
->clientData
= titem
;
1204 createPanel(Panel
*p
)
1206 _Panel
*panel
= (_Panel
*)p
;
1209 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1214 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
1216 if (access(panel
->fprefix
, F_OK
)!=0) {
1217 if (mkdir(panel
->fprefix
, 0755) < 0) {
1218 wsyserror(panel
->fprefix
);
1223 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
1224 free(panel
->fprefix
);
1225 panel
->fprefix
= tmp
;
1226 if (access(panel
->fprefix
, F_OK
)!=0) {
1227 if (mkdir(panel
->fprefix
, 0755) < 0) {
1228 wsyserror(panel
->fprefix
);
1233 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1234 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1235 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1237 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1238 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1239 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1241 panel
->frame
= WMCreateFrame(panel
->win
);
1242 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1243 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1246 panel
->prevL
= WMCreateLabel(panel
->frame
);
1247 WMResizeWidget(panel
->prevL
, 260, 165);
1248 WMMoveWidget(panel
->prevL
, 15, 10);
1249 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1250 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1252 WMCreateEventHandler(WMWidgetView(panel
->prevL
), ButtonPressMask
,
1253 previewClick
, panel
);
1256 panel
->secP
= WMCreatePopUpButton(panel
->frame
);
1257 WMResizeWidget(panel
->secP
, 260, 20);
1258 WMMoveWidget(panel
->secP
, 15, 180);
1259 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1260 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1261 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1262 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1263 WMAddPopUpButtonItem(panel
->secP
, _("Window Resizebar"));
1264 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1265 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1266 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1267 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1269 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1272 panel
->texsL
= WMCreateLabel(panel
->frame
);
1273 WMResizeWidget(panel
->texsL
, 260, 20);
1274 WMMoveWidget(panel
->texsL
, 15, 205);
1275 WMSetLabelWraps(panel
->texsL
, False
);
1278 font
= WMBoldSystemFontOfSize(scr
, 12);
1280 panel
->texL
= WMCreateLabel(panel
->frame
);
1281 WMResizeWidget(panel
->texL
, 225, 18);
1282 WMMoveWidget(panel
->texL
, 285, 10);
1283 WMSetLabelFont(panel
->texL
, font
);
1284 WMSetLabelText(panel
->texL
, _("Textures"));
1285 WMSetLabelRelief(panel
->texL
, WRSunken
);
1286 WMSetLabelTextAlignment(panel
->texL
, WACenter
);
1287 color
= WMDarkGrayColor(scr
);
1288 WMSetWidgetBackgroundColor(panel
->texL
, color
);
1289 WMReleaseColor(color
);
1290 color
= WMWhiteColor(scr
);
1291 WMSetLabelTextColor(panel
->texL
, color
);
1292 WMReleaseColor(color
);
1294 WMReleaseFont(font
);
1296 panel
->texLs
= WMCreateList(panel
->frame
);
1297 WMResizeWidget(panel
->texLs
, 225, 144);
1298 WMMoveWidget(panel
->texLs
, 285, 30);
1299 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1300 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1301 WMHangData(panel
->texLs
, panel
);
1302 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1303 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1305 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1306 "for the selected item."),
1307 WMWidgetView(panel
->texLs
));
1309 /* command buttons */
1311 font
= WMSystemFontOfSize(scr
, 10);
1314 panel
->newB
= WMCreateCommandButton(panel
->frame
);
1315 WMResizeWidget(panel
->newB
, 56, 48);
1316 WMMoveWidget(panel
->newB
, 285, 180);
1317 WMSetButtonFont(panel
->newB
, font
);
1318 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1319 WMSetButtonText(panel
->newB
, _("New"));
1320 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1321 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1323 WMSetBalloonTextForView(_("Create a new texture."),
1324 WMWidgetView(panel
->newB
));
1326 panel
->ripB
= WMCreateCommandButton(panel
->frame
);
1327 WMResizeWidget(panel
->ripB
, 56, 48);
1328 WMMoveWidget(panel
->ripB
, 341, 180);
1329 WMSetButtonFont(panel
->ripB
, font
);
1330 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1331 WMSetButtonText(panel
->ripB
, _("Extract..."));
1332 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1333 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1335 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1336 WMWidgetView(panel
->ripB
));
1338 WMSetButtonEnabled(panel
->ripB
, False
);
1340 panel
->editB
= WMCreateCommandButton(panel
->frame
);
1341 WMResizeWidget(panel
->editB
, 56, 48);
1342 WMMoveWidget(panel
->editB
, 397, 180);
1343 WMSetButtonFont(panel
->editB
, font
);
1344 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1345 WMSetButtonText(panel
->editB
, _("Edit"));
1346 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1347 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1348 WMSetBalloonTextForView(_("Edit the highlighted texture."),
1349 WMWidgetView(panel
->editB
));
1351 panel
->delB
= WMCreateCommandButton(panel
->frame
);
1352 WMResizeWidget(panel
->delB
, 56, 48);
1353 WMMoveWidget(panel
->delB
, 453, 180);
1354 WMSetButtonFont(panel
->delB
, font
);
1355 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1356 WMSetButtonText(panel
->delB
, _("Delete"));
1357 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1358 WMSetButtonEnabled(panel
->delB
, False
);
1359 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1360 WMSetBalloonTextForView(_("Delete the highlighted texture."),
1361 WMWidgetView(panel
->delB
));
1363 WMReleaseFont(font
);
1367 WMRealizeWidget(panel
->frame
);
1368 WMMapSubwidgets(panel
->frame
);
1370 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1374 changePage(panel
->secP
, panel
);
1376 fillTextureList(panel
->texLs
);
1378 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1384 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1388 TextureListItem
*titem
;
1390 titem
= wmalloc(sizeof(TextureListItem
));
1391 memset(titem
, 0, sizeof(TextureListItem
));
1393 titem
->title
= wstrdup(title
);
1394 titem
->prop
= GetObjectForKey(key
);
1396 titem
->prop
= PLGetProplistWithDescription(defValue
);
1398 PLRetain(titem
->prop
);
1400 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1402 titem
->selectedFor
= 1<<index
;
1404 titem
->ispixmap
= isPixmap(titem
->prop
);
1406 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1407 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1409 item
= WMAddListItem(list
, "");
1410 item
->clientData
= titem
;
1416 showData(_Panel
*panel
)
1420 setupTextureFor(panel
->texLs
, "FTitleBack", "(solid, black)",
1422 panel
->textureIndex
[i
] = i
++;
1424 setupTextureFor(panel
->texLs
, "UTitleBack", "(solid, gray)",
1426 panel
->textureIndex
[i
] = i
++;
1428 setupTextureFor(panel
->texLs
, "PTitleBack", "(solid, \"#616161\")",
1429 "[Owner of Focused]", i
);
1430 panel
->textureIndex
[i
] = i
++;
1432 setupTextureFor(panel
->texLs
, "ResizebarBack", "(solid, gray)",
1434 panel
->textureIndex
[i
] = i
++;
1436 setupTextureFor(panel
->texLs
, "MenuTitleBack", "(solid, black)",
1438 panel
->textureIndex
[i
] = i
++;
1440 setupTextureFor(panel
->texLs
, "MenuTextBack", "(solid, gray)",
1442 panel
->textureIndex
[i
] = i
++;
1444 setupTextureFor(panel
->texLs
, "IconBack", "(solid, gray)", "[Icon]", i
);
1445 panel
->textureIndex
[i
] = i
++;
1447 setupTextureFor(panel->texLs, "WorkspaceBack", "(solid, black)",
1449 panel->textureIndex[i] = i++;
1452 updatePreviewBox(panel
, EVERYTHING
);
1458 storeData(_Panel
*panel
)
1460 TextureListItem
*titem
;
1463 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
1464 titem
= (TextureListItem
*)item
->clientData
;
1465 SetObjectForKey(titem
->prop
, "FTitleBack");
1467 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
1468 titem
= (TextureListItem
*)item
->clientData
;
1469 SetObjectForKey(titem
->prop
, "UTitleBack");
1471 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
1472 titem
= (TextureListItem
*)item
->clientData
;
1473 SetObjectForKey(titem
->prop
, "PTitleBack");
1475 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
1476 titem
= (TextureListItem
*)item
->clientData
;
1477 SetObjectForKey(titem
->prop
, "ResizebarBack");
1479 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
1480 titem
= (TextureListItem
*)item
->clientData
;
1481 SetObjectForKey(titem
->prop
, "MenuTitleBack");
1483 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
1484 titem
= (TextureListItem
*)item
->clientData
;
1485 SetObjectForKey(titem
->prop
, "MenuTextBack");
1487 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[6]);
1488 titem
= (TextureListItem
*)item
->clientData
;
1489 SetObjectForKey(titem
->prop
, "IconBack");
1494 prepareForClose(_Panel
*panel
)
1496 proplist_t textureList
;
1499 TextureListItem
*titem
;
1501 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1503 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
1505 /* store list of textures */
1506 for (i
= 7; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
1507 item
= WMGetListItem(panel
->texLs
, i
);
1508 titem
= (TextureListItem
*)item
->clientData
;
1510 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
1511 PLRetain(titem
->prop
),
1512 PLMakeString(titem
->path
),
1515 PLAppendArrayElement(textureList
, texture
);
1518 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
1519 PLRelease(textureList
);
1521 WMSynchronizeUserDefaults(udb
);
1527 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
1531 panel
= wmalloc(sizeof(_Panel
));
1532 memset(panel
, 0, sizeof(_Panel
));
1534 panel
->sectionName
= _("Appearance Preferences");
1536 panel
->description
= _("Background texture configuration for windows,\n"
1537 "menus and icons.");
1541 panel
->callbacks
.createWidgets
= createPanel
;
1542 panel
->callbacks
.updateDomain
= storeData
;
1543 panel
->callbacks
.prepareForClose
= prepareForClose
;
1545 AddSection(panel
, ICON_FILE
);
1552 /****************************************************************************/
1556 typedef struct ExtractPanel
{
1569 OpenExtractPanelFor(_Panel
*panel
, char *path
)
1571 ExtractPanel
*epanel
;
1574 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1576 epanel
= wmalloc(sizeof(ExtractPanel
));
1577 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
1579 |WMClosableWindowMask
);
1580 WMResizeWidget(epanel
->win
, 245, 250);
1581 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
1583 epanel
->label
= WMCreateLabel(epanel
->win
);
1584 WMResizeWidget(epanel
->label
, 225, 18);
1585 WMMoveWidget(epanel
->label
, 10, 10);
1586 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
1587 WMSetLabelRelief(epanel
->label
, WRSunken
);
1589 color
= WMDarkGrayColor(scr
);
1590 WMSetWidgetBackgroundColor(epanel
->label
, color
);
1591 WMReleaseColor(color
);
1593 color
= WMWhiteColor(scr
);
1594 WMSetLabelTextColor(epanel
->label
, color
);
1595 WMReleaseColor(color
);
1597 font
= WMBoldSystemFontOfSize(scr
, 12);
1598 WMSetLabelFont(epanel
->label
, font
);
1599 WMReleaseFont(font
);
1601 WMSetLabelText(epanel
->label
, _("Textures"));
1603 epanel
->list
= WMCreateList(epanel
->win
);
1604 WMResizeWidget(epanel
->list
, 225, 165);
1605 WMMoveWidget(epanel
->list
, 10, 30);
1609 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
1610 WMResizeWidget(epanel
->closeB
, 74, 24);
1611 WMMoveWidget(epanel
->closeB
, 165, 215);
1612 WMSetButtonText(epanel
->closeB
, _("Close"));
1614 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
1615 WMResizeWidget(epanel
->extrB
, 74, 24);
1616 WMMoveWidget(epanel
->extrB
, 80, 215);
1617 WMSetButtonText(epanel
->extrB
, _("Extract"));
1619 WMMapSubwidgets(epanel
->win
);
1622 /* take textures from file */
1626 WMRealizeWidget(epanel
->win
);
1628 WMMapWidget(epanel
->win
);