1 /* Apperance.c- color/texture for titlebar etc.
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1999 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
31 #include <sys/types.h>
38 #include "TexturePanel.h"
40 typedef struct _Panel
{
44 CallbackRec callbacks
;
68 TexturePanel
*texturePanel
;
96 static void showData(_Panel
*panel
);
99 static void OpenExtractPanelFor(_Panel
*panel
, char *path
);
101 #define ICON_FILE "appearance"
103 #define TNEW_FILE "tnew"
104 #define TDEL_FILE "tdel"
105 #define TEDIT_FILE "tedit"
106 #define TEXTR_FILE "textr"
111 static char * blueled_xpm
[] = {
141 static char *blueled2_xpm
[] = {
142 /* width height num_colors chars_per_pixel */
174 static char * hand_xpm
[] = {
196 " .))),%.......... ",
197 " .)-)),&)))))))))$. ",
198 " .-&))))))))),,,,;;. ",
199 " .=)))))))));-=***&$. ",
200 " .=)))))))),..+..... ",
218 #define FTITLE (1<<0)
219 #define UTITLE (1<<1)
220 #define OTITLE (1<<2)
221 #define MTITLE (1<<3)
225 #define EVERYTHING 0xff
230 #define TEXPREV_WIDTH 40
231 #define TEXPREV_HEIGHT 24
238 str2rcolor(RContext
*rc
, char *name
, RColor
*color
)
242 XParseColor(rc
->dpy
, rc
->cmap
, name
, &xcolor
);
245 color
->red
= xcolor
.red
>> 8;
246 color
->green
= xcolor
.green
>> 8;
247 color
->blue
= xcolor
.blue
>> 8;
253 dumpRImage(char *path
, RImage
*image
)
257 f
= fopen(path
, "w");
262 fprintf(f
, "%02x%02x%1x", image
->width
, image
->height
,
263 image
->data
[3]!=NULL
? 4 : 3);
265 fwrite(image
->data
[0], 1, image
->width
* image
->height
, f
);
266 fwrite(image
->data
[1], 1, image
->width
* image
->height
, f
);
267 fwrite(image
->data
[2], 1, image
->width
* image
->height
, f
);
269 fwrite(image
->data
[3], 1, image
->width
* image
->height
, f
);
279 isPixmap(proplist_t prop
)
284 p
= PLGetArrayElement(prop
, 0);
286 if (strcasecmp(&s
[1], "pixmap")==0)
295 renderTexture(WMScreen
*scr
, proplist_t texture
, int width
, int height
,
296 char *path
, int border
)
301 RContext
*rc
= WMScreenRContext(scr
);
306 type
= PLGetString(PLGetArrayElement(texture
, 0));
308 image
= RCreateImage(width
, height
, False
);
310 if (strcasecmp(type
, "solid")==0) {
312 str
= PLGetString(PLGetArrayElement(texture
, 1));
314 str2rcolor(rc
, str
, &rcolor
);
316 RClearImage(image
, &rcolor
);
317 } else if (strcasecmp(&type
[1], "gradient")==0) {
321 switch (toupper(type
[0])) {
323 style
= RVerticalGradient
;
326 style
= RHorizontalGradient
;
330 style
= RDiagonalGradient
;
334 str
= PLGetString(PLGetArrayElement(texture
, 1));
335 str2rcolor(rc
, str
, &rcolor
);
336 str
= PLGetString(PLGetArrayElement(texture
, 2));
337 str2rcolor(rc
, str
, &rcolor2
);
339 image
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
340 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='T') {
344 RImage
*grad
, *timage
;
347 switch (toupper(type
[1])) {
349 style
= RVerticalGradient
;
352 style
= RHorizontalGradient
;
356 style
= RDiagonalGradient
;
360 str
= PLGetString(PLGetArrayElement(texture
, 3));
361 str2rcolor(rc
, str
, &rcolor
);
362 str
= PLGetString(PLGetArrayElement(texture
, 4));
363 str2rcolor(rc
, str
, &rcolor2
);
365 str
= PLGetString(PLGetArrayElement(texture
, 1));
367 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
368 timage
= RLoadImage(rc
, path
, 0);
371 wwarning("could not load file '%s': %s", path
,
372 RMessageForError(RErrorCode
));
374 grad
= RRenderGradient(width
, height
, &rcolor
, &rcolor2
, style
);
376 image
= RMakeTiledImage(timage
, width
, height
);
377 RDestroyImage(timage
);
379 i
= atoi(PLGetString(PLGetArrayElement(texture
, 2)));
381 RCombineImagesWithOpaqueness(image
, grad
, i
);
384 } else if (strcasecmp(&type
[2], "gradient")==0 && toupper(type
[0])=='M') {
389 switch (toupper(type
[1])) {
391 style
= RVerticalGradient
;
394 style
= RHorizontalGradient
;
398 style
= RDiagonalGradient
;
402 j
= PLGetNumberOfElements(texture
);
405 colors
= wmalloc(j
* sizeof(RColor
*));
407 for (i
= 2; i
< j
; i
++) {
408 str
= PLGetString(PLGetArrayElement(texture
, i
));
409 colors
[i
-2] = wmalloc(sizeof(RColor
));
410 str2rcolor(rc
, str
, colors
[i
-2]);
414 image
= RRenderMultiGradient(width
, height
, colors
, style
);
416 for (i
= 0; colors
[i
]!=NULL
; i
++)
420 } else if (strcasecmp(&type
[1], "pixmap")==0) {
426 str
= PLGetString(PLGetArrayElement(texture
, 1));
428 path
= wfindfileinarray(GetObjectForKey("PixmapPath"), str
);
429 timage
= RLoadImage(rc
, path
, 0);
432 wwarning("could not load file '%s': %s", path
,
433 RMessageForError(RErrorCode
));
435 str
= PLGetString(PLGetArrayElement(texture
, 2));
436 str2rcolor(rc
, str
, &color
);
438 switch (toupper(type
[0])) {
440 image
= RMakeTiledImage(timage
, width
, height
);
441 RDestroyImage(timage
);
445 image
= RMakeCenteredImage(timage
, width
, height
, &color
);
446 RDestroyImage(timage
);
451 image
= RScaleImage(timage
, width
, height
);
452 RDestroyImage(timage
);
465 dumpRImage(path
, image
);
469 RBevelImage(image
, border
);
472 RConvertImage(rc
, image
, &pixmap
);
473 RDestroyImage(image
);
482 updatePreviewBox(_Panel
*panel
, int elements
)
484 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
485 Display
*dpy
= WMScreenDisplay(scr
);
486 /* RContext *rc = WMScreenRContext(scr);*/
491 TextureListItem
*titem
;
493 gc
= XCreateGC(dpy
, WMWidgetXID(panel
->win
), 0, NULL
);
496 if (!panel
->preview
) {
499 panel
->preview
= XCreatePixmap(dpy
, WMWidgetXID(panel
->win
),
500 260-4, 165-4, WMScreenDepth(scr
));
502 color
= WMGrayColor(scr
);
503 XFillRectangle(dpy
, panel
->preview
, WMColorGC(color
),
505 WMReleaseColor(color
);
510 if (elements
& FTITLE
) {
511 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
512 titem
= (TextureListItem
*)item
->clientData
;
514 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
516 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 10);
518 XFreePixmap(dpy
, pix
);
520 if (elements
& UTITLE
) {
521 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
522 titem
= (TextureListItem
*)item
->clientData
;
524 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
526 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 35);
528 XFreePixmap(dpy
, pix
);
530 if (elements
& OTITLE
) {
531 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
532 titem
= (TextureListItem
*)item
->clientData
;
534 pix
= renderTexture(scr
, titem
->prop
, 210, 20, NULL
, RBEV_RAISED2
);
536 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 210, 20, 30, 60);
538 XFreePixmap(dpy
, pix
);
540 if (elements
& MTITLE
) {
541 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
542 titem
= (TextureListItem
*)item
->clientData
;
544 pix
= renderTexture(scr
, titem
->prop
, 100, 20, NULL
, RBEV_RAISED2
);
546 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 20, 30, 95);
548 XFreePixmap(dpy
, pix
);
550 if (elements
& MITEM
) {
551 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
552 titem
= (TextureListItem
*)item
->clientData
;
554 pix
= renderTexture(scr
, titem
->prop
, 100, 18, NULL
, RBEV_RAISED2
);
556 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 18, 30, 115);
557 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 18, 30, 115 + 18);
558 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 100, 18, 30, 115 + 36);
560 XFreePixmap(dpy
, pix
);
562 if (elements
& (MITEM
|MTITLE
)) {
563 XDrawLine(dpy
, panel
->preview
, gc
, 29, 95, 29, 115+36+20);
564 XDrawLine(dpy
, panel
->preview
, gc
, 29, 94, 129, 94);
567 if (elements
& ICON
) {
568 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
569 titem
= (TextureListItem
*)item
->clientData
;
571 pix
= renderTexture(scr
, titem
->prop
, 64, 64, NULL
,
572 titem
->ispixmap
? 0 : RBEV_RAISED3
);
574 XCopyArea(dpy
, pix
, panel
->preview
, gc
, 0, 0, 64, 64, 170, 90);
576 XFreePixmap(dpy
, pix
);
582 p
= WMCreatePixmapFromXPixmaps(scr
, panel
->preview
, None
,
583 260-4, 165-4, WMScreenDepth(scr
));
585 WMSetLabelImage(panel
->prevL
, p
);
588 WMRedisplayWidget(panel
->prevL
);
598 cancelNewTexture(void *data
)
600 _Panel
*panel
= (_Panel
*)data
;
602 HideTexturePanel(panel
->texturePanel
);
609 makeFileName(char *prefix
)
613 fname
= wstrdup(prefix
);
615 while (access(fname
, F_OK
)==0) {
619 sprintf(buf
, "%08lx.cache", time(NULL
));
620 fname
= wstrappend(prefix
, buf
);
630 okNewTexture(void *data
)
632 _Panel
*panel
= (_Panel
*)data
;
637 TextureListItem
*titem
;
638 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
640 titem
= wmalloc(sizeof(TextureListItem
));
641 memset(titem
, 0, sizeof(TextureListItem
));
643 HideTexturePanel(panel
->texturePanel
);
645 name
= GetTexturePanelTextureName(panel
->texturePanel
);
647 prop
= GetTexturePanelTexture(panel
->texturePanel
);
649 str
= PLGetDescription(prop
);
653 titem
->texture
= str
;
654 titem
->selectedFor
= 0;
656 titem
->ispixmap
= isPixmap(prop
);
658 titem
->path
= makeFileName(panel
->fprefix
);
659 titem
->preview
= renderTexture(scr
, prop
, TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
662 item
= WMAddListItem(panel
->texLs
, "");
663 item
->clientData
= titem
;
665 WMSetListPosition(panel
->texLs
, WMGetListNumberOfRows(panel
->texLs
));
670 okEditTexture(void *data
)
672 _Panel
*panel
= (_Panel
*)data
;
677 TextureListItem
*titem
;
679 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
680 titem
= (TextureListItem
*)item
->clientData
;
682 HideTexturePanel(panel
->texturePanel
);
684 if (titem
->current
) {
685 name
= GetTexturePanelTextureName(panel
->texturePanel
);
691 prop
= GetTexturePanelTexture(panel
->texturePanel
);
693 str
= PLGetDescription(prop
);
695 PLRelease(titem
->prop
);
698 titem
->ispixmap
= isPixmap(prop
);
700 free(titem
->texture
);
701 titem
->texture
= str
;
703 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel
->texLs
)), titem
->preview
);
704 titem
->preview
= renderTexture(WMWidgetScreen(panel
->texLs
), titem
->prop
,
705 TEXPREV_WIDTH
, TEXPREV_HEIGHT
,
708 WMRedisplayWidget(panel
->texLs
);
710 if (titem
->selectedFor
)
711 updatePreviewBox(panel
, titem
->selectedFor
);
717 editTexture(WMWidget
*w
, void *data
)
719 _Panel
*panel
= (_Panel
*)data
;
721 TextureListItem
*titem
;
723 item
= WMGetListItem(panel
->texLs
, WMGetListSelectedItemRow(panel
->texLs
));
724 titem
= (TextureListItem
*)item
->clientData
;
726 SetTexturePanelPixmapPath(panel
->texturePanel
,
727 GetObjectForKey("PixmapPath"));
729 SetTexturePanelTexture(panel
->texturePanel
, titem
->title
, titem
->prop
);
731 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
732 SetTexturePanelOkAction(panel
->texturePanel
, okEditTexture
, panel
);
734 ShowTexturePanel(panel
->texturePanel
);
740 newTexture(WMWidget
*w
, void *data
)
742 _Panel
*panel
= (_Panel
*)data
;
744 SetTexturePanelPixmapPath(panel
->texturePanel
,
745 GetObjectForKey("PixmapPath"));
747 SetTexturePanelTexture(panel
->texturePanel
, "New Texture", NULL
);
749 SetTexturePanelCancelAction(panel
->texturePanel
, cancelNewTexture
, panel
);
751 SetTexturePanelOkAction(panel
->texturePanel
, okNewTexture
, panel
);
753 ShowTexturePanel(panel
->texturePanel
);
759 deleteTexture(WMWidget
*w
, void *data
)
761 _Panel
*panel
= (_Panel
*)data
;
763 TextureListItem
*titem
;
767 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
768 row
= WMGetListSelectedItemRow(panel
->texLs
);
769 item
= WMGetListItem(panel
->texLs
, row
);
770 titem
= (TextureListItem
*)item
->clientData
;
772 if (titem
->selectedFor
& (1 << section
)) {
773 TextureListItem
*titem2
;
775 panel
->textureIndex
[section
] = section
;
776 item
= WMGetListItem(panel
->texLs
, section
);
777 titem2
= (TextureListItem
*)item
->clientData
;
778 titem2
->selectedFor
|= 1 << section
;
782 free(titem
->texture
);
783 PLRelease(titem
->prop
);
785 if (remove(titem
->path
) < 0 && errno
!= ENOENT
) {
786 wsyserror("could not remove file %s", titem
->path
);
793 WMRemoveListItem(panel
->texLs
, row
);
794 WMSetButtonEnabled(panel
->delB
, False
);
801 extractTexture(WMWidget
*w
, void *data
)
803 _Panel
*panel
= (_Panel
*)data
;
806 WMScreen
*scr
= WMWidgetScreen(w
);
808 opanel
= WMGetOpenPanel(scr
);
809 WMSetFilePanelCanChooseDirectories(opanel
, False
);
810 WMSetFilePanelCanChooseFiles(opanel
, True
);
812 if (WMRunModalFilePanelForDirectory(opanel
, panel
->win
, wgethomedir(),
813 _("Select File"), NULL
)) {
814 path
= WMGetFilePanelFileName(opanel
);
816 OpenExtractPanelFor(panel
, path
);
826 changePage(WMWidget
*w
, void *data
)
828 _Panel
*panel
= (_Panel
*)data
;
831 TextureListItem
*titem
;
833 WMScreen
*scr
= WMWidgetScreen(w
);
834 RContext
*rc
= WMScreenRContext(scr
);
835 static WMPoint positions
[6] = {
844 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
846 WMSelectListItem(panel
->texLs
, panel
->textureIndex
[section
]);
848 WMSetListPosition(panel
->texLs
, panel
->textureIndex
[section
]
849 - WMGetListNumberOfRows(panel
->texLs
)/2);
851 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
853 titem
= (TextureListItem
*)item
->clientData
;
855 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
856 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
857 WMSetLabelText(panel
->texsL
, str
);
863 color
= WMGrayColor(scr
);
864 XFillRectangle(rc
->dpy
, panel
->preview
, WMColorGC(color
),
865 positions
[panel
->oldsection
].x
,
866 positions
[panel
->oldsection
].y
, 22, 22);
867 WMReleaseColor(color
);
869 panel
->oldsection
= section
;
870 WMDrawPixmap(panel
->hand
, panel
->preview
, positions
[section
].x
,
871 positions
[section
].y
);
873 WMRedisplayWidget(panel
->prevL
);
879 textureClick(WMWidget
*w
, void *data
)
881 _Panel
*panel
= (_Panel
*)data
;
884 TextureListItem
*titem
;
886 i
= WMGetListSelectedItemRow(panel
->texLs
);
888 item
= WMGetListItem(panel
->texLs
, i
);
890 titem
= (TextureListItem
*)item
->clientData
;
892 if (titem
->current
) {
893 WMSetButtonEnabled(panel
->delB
, False
);
895 WMSetButtonEnabled(panel
->delB
, True
);
902 textureDoubleClick(WMWidget
*w
, void *data
)
904 _Panel
*panel
= (_Panel
*)data
;
907 TextureListItem
*titem
;
910 /* unselect old texture */
911 section
= WMGetPopUpButtonSelectedItem(panel
->secP
);
913 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[section
]);
914 titem
= (TextureListItem
*)item
->clientData
;
915 titem
->selectedFor
&= ~(1 << section
);
917 /* select new texture */
918 i
= WMGetListSelectedItemRow(panel
->texLs
);
920 item
= WMGetListItem(panel
->texLs
, i
);
922 titem
= (TextureListItem
*)item
->clientData
;
924 titem
->selectedFor
|= 1<<section
;
926 panel
->textureIndex
[section
] = i
;
928 WMRedisplayWidget(panel
->texLs
);
930 str
= wmalloc(strlen(titem
->title
) + strlen(titem
->texture
) + 4);
931 sprintf(str
, "%s: %s", titem
->title
, titem
->texture
);
932 WMSetLabelText(panel
->texsL
, str
);
935 updatePreviewBox(panel
, 1<<section
);
942 paintListItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
945 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
946 WMScreen
*scr
= WMWidgetScreen(lPtr
);
947 int width
, height
, x
, y
;
948 Display
*dpy
= WMScreenDisplay(scr
);
949 WMColor
*white
= WMWhiteColor(scr
);
951 WMColor
*black
= WMBlackColor(scr
);
952 TextureListItem
*titem
;
954 width
= rect
->size
.width
;
955 height
= rect
->size
.height
;
959 if (state
& WLDSSelected
)
960 XFillRectangle(dpy
, d
, WMColorGC(white
), x
, y
, width
, height
);
962 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
964 item
= WMGetListItem(lPtr
, index
);
965 titem
= (TextureListItem
*)item
->clientData
;
968 XCopyArea(dpy
, titem
->preview
, d
, WMColorGC(black
), 0, 0, TEXPREV_WIDTH
,
969 TEXPREV_HEIGHT
, x
+ 5, y
+ 5);
971 if ((1 << WMGetPopUpButtonSelectedItem(panel
->secP
)) & titem
->selectedFor
)
972 WMDrawPixmap(panel
->onLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
973 else if (titem
->selectedFor
)
974 WMDrawPixmap(panel
->offLed
, d
, x
+ TEXPREV_WIDTH
+ 10, y
+ 6);
976 WMDrawString(scr
, d
, WMColorGC(black
), panel
->boldFont
,
977 x
+ TEXPREV_WIDTH
+ 22, y
+ 2, titem
->title
,
978 strlen(titem
->title
));
980 WMDrawString(scr
, d
, WMColorGC(black
), panel
->smallFont
,
981 x
+ TEXPREV_WIDTH
+ 14, y
+ 18, titem
->texture
,
982 strlen(titem
->texture
));
985 WMReleaseColor(white
);
986 WMReleaseColor(black
);
992 loadRImage(WMScreen
*scr
, char *path
)
1000 f
= fopen(path
, "r");
1004 fscanf(f
, "%02x%02x%1x", &w
, &h
, &d
);
1006 image
= RCreateImage(w
, h
, d
== 4);
1007 for (i
= 0; i
< d
; i
++) {
1008 fread(image
->data
[i
], 1, w
*h
, f
);
1012 RConvertImage(WMScreenRContext(scr
), image
, &pixmap
);
1013 RDestroyImage(image
);
1021 fillTextureList(WMList
*lPtr
)
1023 proplist_t textureList
;
1025 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1027 TextureListItem
*titem
;
1028 WMScreen
*scr
= WMWidgetScreen(lPtr
);
1030 textureList
= WMGetUDObjectForKey(udb
, "TextureList");
1034 for (i
= 0; i
< PLGetNumberOfElements(textureList
); i
++) {
1037 texture
= PLGetArrayElement(textureList
, i
);
1039 titem
= wmalloc(sizeof(TextureListItem
));
1040 memset(titem
, 0, sizeof(TextureListItem
));
1042 titem
->title
= wstrdup(PLGetString(PLGetArrayElement(texture
, 0)));
1043 titem
->prop
= PLRetain(PLGetArrayElement(texture
, 1));
1044 titem
->texture
= PLGetDescription(titem
->prop
);
1045 titem
->selectedFor
= 0;
1046 titem
->path
= wstrdup(PLGetString(PLGetArrayElement(texture
, 2)));
1048 titem
->preview
= loadRImage(scr
, titem
->path
);
1049 if (!titem
->preview
) {
1050 titem
->preview
= renderTexture(scr
, titem
->prop
, TEXPREV_WIDTH
,
1051 TEXPREV_HEIGHT
, NULL
, 0);
1053 item
= WMAddListItem(lPtr
, "");
1054 item
->clientData
= titem
;
1060 createPanel(Panel
*p
)
1062 _Panel
*panel
= (_Panel
*)p
;
1065 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1070 panel
->fprefix
= wstrappend(wusergnusteppath(), "/.AppInfo");
1072 if (access(panel
->fprefix
, F_OK
)!=0) {
1073 if (mkdir(panel
->fprefix
, 0755) < 0) {
1074 wsyserror(panel
->fprefix
);
1079 tmp
= wstrappend(panel
->fprefix
, "/WPrefs/");
1080 free(panel
->fprefix
);
1081 panel
->fprefix
= tmp
;
1082 if (access(panel
->fprefix
, F_OK
)!=0) {
1083 if (mkdir(panel
->fprefix
, 0755) < 0) {
1084 wsyserror(panel
->fprefix
);
1089 panel
->smallFont
= WMSystemFontOfSize(scr
, 10);
1090 panel
->normalFont
= WMSystemFontOfSize(scr
, 12);
1091 panel
->boldFont
= WMBoldSystemFontOfSize(scr
, 12);
1093 panel
->onLed
= WMCreatePixmapFromXPMData(scr
, blueled_xpm
);
1094 panel
->offLed
= WMCreatePixmapFromXPMData(scr
, blueled2_xpm
);
1095 panel
->hand
= WMCreatePixmapFromXPMData(scr
, hand_xpm
);
1097 panel
->frame
= WMCreateFrame(panel
->win
);
1098 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1099 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1102 panel
->prevL
= WMCreateLabel(panel
->frame
);
1103 WMResizeWidget(panel
->prevL
, 260, 165);
1104 WMMoveWidget(panel
->prevL
, 15, 10);
1105 WMSetLabelRelief(panel
->prevL
, WRSunken
);
1106 WMSetLabelImagePosition(panel
->prevL
, WIPImageOnly
);
1108 panel
->secP
= WMCreatePopUpButton(panel
->frame
);
1109 WMResizeWidget(panel
->secP
, 260, 20);
1110 WMMoveWidget(panel
->secP
, 15, 180);
1111 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1112 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window"));
1113 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Unfocused Windows"));
1114 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Focused Window's Owner"));
1115 WMAddPopUpButtonItem(panel
->secP
, _("Titlebar of Menus"));
1116 WMAddPopUpButtonItem(panel
->secP
, _("Menu Items"));
1117 WMAddPopUpButtonItem(panel
->secP
, _("Icon Background"));
1118 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1120 WMSetPopUpButtonAction(panel
->secP
, changePage
, panel
);
1123 panel
->texsL
= WMCreateLabel(panel
->frame
);
1124 WMResizeWidget(panel
->texsL
, 260, 20);
1125 WMMoveWidget(panel
->texsL
, 15, 205);
1126 WMSetLabelWraps(panel
->texsL
, False
);
1129 font
= WMBoldSystemFontOfSize(scr
, 12);
1131 panel
->texL
= WMCreateLabel(panel
->frame
);
1132 WMResizeWidget(panel
->texL
, 225, 18);
1133 WMMoveWidget(panel
->texL
, 285, 10);
1134 WMSetLabelFont(panel
->texL
, font
);
1135 WMSetLabelText(panel
->texL
, _("Textures"));
1136 WMSetLabelRelief(panel
->texL
, WRSunken
);
1137 WMSetLabelTextAlignment(panel
->texL
, WACenter
);
1138 color
= WMDarkGrayColor(scr
);
1139 WMSetWidgetBackgroundColor(panel
->texL
, color
);
1140 WMReleaseColor(color
);
1141 color
= WMWhiteColor(scr
);
1142 WMSetLabelTextColor(panel
->texL
, color
);
1143 WMReleaseColor(color
);
1145 WMReleaseFont(font
);
1147 panel
->texLs
= WMCreateList(panel
->frame
);
1148 WMResizeWidget(panel
->texLs
, 225, 144);
1149 WMMoveWidget(panel
->texLs
, 285, 30);
1150 WMSetListUserDrawItemHeight(panel
->texLs
, 35);
1151 WMSetListUserDrawProc(panel
->texLs
, paintListItem
);
1152 WMHangData(panel
->texLs
, panel
);
1153 WMSetListAction(panel
->texLs
, textureClick
, panel
);
1154 WMSetListDoubleAction(panel
->texLs
, textureDoubleClick
, panel
);
1156 /* command buttons */
1158 font
= WMSystemFontOfSize(scr
, 10);
1161 panel
->newB
= WMCreateCommandButton(panel
->frame
);
1162 WMResizeWidget(panel
->newB
, 56, 48);
1163 WMMoveWidget(panel
->newB
, 285, 180);
1164 WMSetButtonFont(panel
->newB
, font
);
1165 WMSetButtonImagePosition(panel
->newB
, WIPAbove
);
1166 WMSetButtonText(panel
->newB
, _("New"));
1167 WMSetButtonAction(panel
->newB
, newTexture
, panel
);
1168 SetButtonAlphaImage(scr
, panel
->newB
, TNEW_FILE
);
1170 panel
->ripB
= WMCreateCommandButton(panel
->frame
);
1171 WMResizeWidget(panel
->ripB
, 56, 48);
1172 WMMoveWidget(panel
->ripB
, 341, 180);
1173 WMSetButtonFont(panel
->ripB
, font
);
1174 WMSetButtonImagePosition(panel
->ripB
, WIPAbove
);
1175 WMSetButtonText(panel
->ripB
, _("Extract..."));
1176 WMSetButtonAction(panel
->ripB
, extractTexture
, panel
);
1177 SetButtonAlphaImage(scr
, panel
->ripB
, TEXTR_FILE
);
1179 WMSetButtonEnabled(panel
->ripB
, False
);
1181 panel
->editB
= WMCreateCommandButton(panel
->frame
);
1182 WMResizeWidget(panel
->editB
, 56, 48);
1183 WMMoveWidget(panel
->editB
, 397, 180);
1184 WMSetButtonFont(panel
->editB
, font
);
1185 WMSetButtonImagePosition(panel
->editB
, WIPAbove
);
1186 WMSetButtonText(panel
->editB
, _("Edit"));
1187 SetButtonAlphaImage(scr
, panel
->editB
, TEDIT_FILE
);
1188 WMSetButtonAction(panel
->editB
, editTexture
, panel
);
1190 panel
->delB
= WMCreateCommandButton(panel
->frame
);
1191 WMResizeWidget(panel
->delB
, 56, 48);
1192 WMMoveWidget(panel
->delB
, 453, 180);
1193 WMSetButtonFont(panel
->delB
, font
);
1194 WMSetButtonImagePosition(panel
->delB
, WIPAbove
);
1195 WMSetButtonText(panel
->delB
, _("Delete"));
1196 SetButtonAlphaImage(scr
, panel
->delB
, TDEL_FILE
);
1197 WMSetButtonEnabled(panel
->delB
, False
);
1198 WMSetButtonAction(panel
->delB
, deleteTexture
, panel
);
1200 WMReleaseFont(font
);
1204 WMRealizeWidget(panel
->frame
);
1205 WMMapSubwidgets(panel
->frame
);
1207 WMSetPopUpButtonSelectedItem(panel
->secP
, 0);
1211 changePage(panel
->secP
, panel
);
1213 fillTextureList(panel
->texLs
);
1215 panel
->texturePanel
= CreateTexturePanel(panel
->win
);
1221 setupTextureFor(WMList
*list
, char *key
, char *defValue
, char *title
,
1225 TextureListItem
*titem
;
1227 titem
= wmalloc(sizeof(TextureListItem
));
1228 memset(titem
, 0, sizeof(TextureListItem
));
1230 titem
->title
= wstrdup(title
);
1231 titem
->prop
= GetObjectForKey(key
);
1233 titem
->prop
= PLGetProplistWithDescription(defValue
);
1235 PLRetain(titem
->prop
);
1237 titem
->texture
= PLGetDescription((proplist_t
)titem
->prop
);
1239 titem
->selectedFor
= 1<<index
;
1241 titem
->ispixmap
= isPixmap(titem
->prop
);
1243 titem
->preview
= renderTexture(WMWidgetScreen(list
), titem
->prop
,
1244 TEXPREV_WIDTH
, TEXPREV_HEIGHT
, NULL
, 0);
1246 item
= WMAddListItem(list
, "");
1247 item
->clientData
= titem
;
1253 showData(_Panel
*panel
)
1257 setupTextureFor(panel
->texLs
, "FTitleBack", "(solid, black)",
1259 panel
->textureIndex
[i
] = i
++;
1261 setupTextureFor(panel
->texLs
, "UTitleBack", "(solid, gray)",
1263 panel
->textureIndex
[i
] = i
++;
1265 setupTextureFor(panel
->texLs
, "PTitleBack", "(solid, \"#616161\")",
1266 "[Owner of Focused]", i
);
1267 panel
->textureIndex
[i
] = i
++;
1269 setupTextureFor(panel
->texLs
, "MenuTitleBack", "(solid, black)",
1271 panel
->textureIndex
[i
] = i
++;
1273 setupTextureFor(panel
->texLs
, "MenuTextBack", "(solid, gray)",
1275 panel
->textureIndex
[i
] = i
++;
1277 setupTextureFor(panel
->texLs
, "IconBack", "(solid, gray)", "[Icon]", i
);
1278 panel
->textureIndex
[i
] = i
++;
1280 setupTextureFor(panel->texLs, "WorkspaceBack", "(solid, black)",
1282 panel->textureIndex[i] = i++;
1285 updatePreviewBox(panel
, EVERYTHING
);
1291 storeData(_Panel
*panel
)
1293 TextureListItem
*titem
;
1296 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[0]);
1297 titem
= (TextureListItem
*)item
->clientData
;
1298 SetObjectForKey(titem
->prop
, "FTitleBack");
1300 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[1]);
1301 titem
= (TextureListItem
*)item
->clientData
;
1302 SetObjectForKey(titem
->prop
, "UTitleBack");
1304 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[2]);
1305 titem
= (TextureListItem
*)item
->clientData
;
1306 SetObjectForKey(titem
->prop
, "PTitleBack");
1308 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[3]);
1309 titem
= (TextureListItem
*)item
->clientData
;
1310 SetObjectForKey(titem
->prop
, "MenuTitleBack");
1312 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[4]);
1313 titem
= (TextureListItem
*)item
->clientData
;
1314 SetObjectForKey(titem
->prop
, "MenuTextBack");
1316 item
= WMGetListItem(panel
->texLs
, panel
->textureIndex
[5]);
1317 titem
= (TextureListItem
*)item
->clientData
;
1318 SetObjectForKey(titem
->prop
, "IconBack");
1323 prepareForClose(_Panel
*panel
)
1325 proplist_t textureList
;
1328 TextureListItem
*titem
;
1330 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
1332 textureList
= PLMakeArrayFromElements(NULL
, NULL
);
1334 /* store list of textures */
1335 for (i
= 6; i
< WMGetListNumberOfRows(panel
->texLs
); i
++) {
1336 item
= WMGetListItem(panel
->texLs
, i
);
1337 titem
= (TextureListItem
*)item
->clientData
;
1339 texture
= PLMakeArrayFromElements(PLMakeString(titem
->title
),
1340 PLRetain(titem
->prop
),
1341 PLMakeString(titem
->path
),
1344 PLAppendArrayElement(textureList
, texture
);
1347 WMSetUDObjectForKey(udb
, textureList
, "TextureList");
1348 PLRelease(textureList
);
1350 WMSynchronizeUserDefaults(udb
);
1356 InitAppearance(WMScreen
*scr
, WMWindow
*win
)
1360 panel
= wmalloc(sizeof(_Panel
));
1361 memset(panel
, 0, sizeof(_Panel
));
1363 panel
->sectionName
= _("Appearance Preferences");
1367 panel
->callbacks
.createWidgets
= createPanel
;
1368 panel
->callbacks
.updateDomain
= storeData
;
1369 panel
->callbacks
.prepareForClose
= prepareForClose
;
1371 AddSection(panel
, ICON_FILE
);
1378 /****************************************************************************/
1382 typedef struct ExtractPanel
{
1395 OpenExtractPanelFor(_Panel
*panel
, char *path
)
1397 ExtractPanel
*epanel
;
1400 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1402 epanel
= wmalloc(sizeof(ExtractPanel
));
1403 epanel
->win
= WMCreatePanelWithStyleForWindow(panel
->win
, "extract",
1405 |WMClosableWindowMask
);
1406 WMResizeWidget(epanel
->win
, 245, 250);
1407 WMSetWindowTitle(epanel
->win
, _("Extract Texture"));
1409 epanel
->label
= WMCreateLabel(epanel
->win
);
1410 WMResizeWidget(epanel
->label
, 225, 18);
1411 WMMoveWidget(epanel
->label
, 10, 10);
1412 WMSetLabelTextAlignment(epanel
->label
, WACenter
);
1413 WMSetLabelRelief(epanel
->label
, WRSunken
);
1415 color
= WMDarkGrayColor(scr
);
1416 WMSetWidgetBackgroundColor(epanel
->label
, color
);
1417 WMReleaseColor(color
);
1419 color
= WMWhiteColor(scr
);
1420 WMSetLabelTextColor(epanel
->label
, color
);
1421 WMReleaseColor(color
);
1423 font
= WMBoldSystemFontOfSize(scr
, 12);
1424 WMSetLabelFont(epanel
->label
, font
);
1425 WMReleaseFont(font
);
1427 WMSetLabelText(epanel
->label
, _("Textures"));
1429 epanel
->list
= WMCreateList(epanel
->win
);
1430 WMResizeWidget(epanel
->list
, 225, 165);
1431 WMMoveWidget(epanel
->list
, 10, 30);
1435 epanel
->closeB
= WMCreateCommandButton(epanel
->win
);
1436 WMResizeWidget(epanel
->closeB
, 74, 24);
1437 WMMoveWidget(epanel
->closeB
, 165, 215);
1438 WMSetButtonText(epanel
->closeB
, _("Close"));
1440 epanel
->extrB
= WMCreateCommandButton(epanel
->win
);
1441 WMResizeWidget(epanel
->extrB
, 74, 24);
1442 WMMoveWidget(epanel
->extrB
, 80, 215);
1443 WMSetButtonText(epanel
->extrB
, _("Extract"));
1445 WMMapSubwidgets(epanel
->win
);
1448 /* take textures from file */
1452 WMRealizeWidget(epanel
->win
);
1454 WMMapWidget(epanel
->win
);