1
/* Apperance.c- color/texture for titlebar etc.
3
* WPrefs - Window Maker Preferences Program
5
* Copyright (c) 1999-2003 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;
74
WMColorWell *sampW[24];
91
WMPopUpButton *modeB[3];
101
TexturePanel *texturePanel;
117
Pixmap previewNoText;
136
static void updateColorPreviewBox(_Panel *panel, int elements);
138
static void showData(_Panel *panel);
140
static void changePage(WMWidget *w, void *data);
142
static void changeColorPage(WMWidget *w, void *data);
144
static void OpenExtractPanelFor(_Panel *panel, char *path);
148
static void changedTabItem(struct WMTabViewDelegate *self, WMTabView *tabView,
149
WMTabViewItem *item);
153
static WMTabViewDelegate tabviewDelegate = {
155
NULL, /* didChangeNumberOfItems */
156
changedTabItem, /* didSelectItem */
157
NULL, /* shouldSelectItem */
158
NULL /* willSelectItem */
162
#define ICON_FILE "appearance"
164
#define TNEW_FILE "tnew"
165
#define TDEL_FILE "tdel"
166
#define TEDIT_FILE "tedit"
167
#define TEXTR_FILE "textr"
169
#define MSTYLE1_FILE "msty1"
170
#define MSTYLE2_FILE "msty2"
171
#define MSTYLE3_FILE "msty3"
175
static char * blueled_xpm[] = {
205
static char *blueled2_xpm[] = {
206
/* width height num_colors chars_per_pixel */
239
static char * hand_xpm[] = {
263
" .%%%&@.......... ",
264
" .%*%%&#%%%%%%%%%$. ",
265
" .*#%%%%%%%%%&&&&==. ",
266
" .-%%%%%%%%%=*-;;;#$. ",
267
" .-%%%%%%%%&..>..... ",
284
static char *sampleColors[] = {
313
static char *textureOptions[] = {
314
"FTitleBack", "(solid, black)", "[Focused]",
315
"UTitleBack", "(solid, gray)", "[Unfocused]",
316
"PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
317
"ResizebarBack", "(solid, gray)", "[Resizebar]",
318
"MenuTitleBack", "(solid, black)", "[Menu Title]",
319
"MenuTextBack", "(solid, gray)", "[Menu Item]",
320
"IconBack", "(solid, gray)", "[Icon]"
324
#define RESIZEBAR_BEVEL -1
325
#define MENU_BEVEL -2
327
#define TEXPREV_WIDTH 40
328
#define TEXPREV_HEIGHT 24
331
#define MSTYLE_NORMAL 0
332
#define MSTYLE_SINGLE 1
333
#define MSTYLE_FLAT 2
336
#define FTITLE_COL (1<<0)
337
#define UTITLE_COL (1<<1)
338
#define OTITLE_COL (1<<2)
339
#define MTITLE_COL (1<<3)
340
#define MITEM_COL (1<<4)
341
#define MDISAB_COL (1<<5)
342
#define MHIGH_COL (1<<6)
343
#define MHIGHT_COL (1<<7)
344
#define ICONT_COL (1<<8)
345
#define ICONB_COL (1<<9)
346
#define CLIP_COL (1<<10)
347
#define CCLIP_COL (1<<11)
350
static char *colorOptions[] = {
351
"FTitleColor", "white",
352
"UTitleColor", "black",
353
"PTitleColor", "white",
354
"MenuTitleColor", "white",
355
"MenuTextColor", "black",
356
"MenuDisabledColor", "#616161",
357
"HighlightColor", "white",
358
"HighlightTextColor", "black",
359
"IconTitleColor", "white",
360
"IconTitleBack", "black",
361
"ClipTitleColor", "black",
362
"CClipTitleColor", "#454045"
368
static WMRect previewPositions[] = {
380
{{30,140},{90,20*4}},
384
#define EVERYTHING 0xff
387
static WMRect previewColorPositions[] = {
405
str2rcolor(RContext *rc, char *name, RColor *color)
409
XParseColor(rc->dpy, rc->cmap, name, &xcolor);
412
color->red = xcolor.red >> 8;
413
color->green = xcolor.green >> 8;
414
color->blue = xcolor.blue >> 8;
419
dumpRImage(char *path, RImage *image)
422
int channels = (image->format == RRGBAFormat ? 4 : 3);
424
f = fopen(path, "wb");
429
fprintf(f, "%02x%02x%1x", image->width, image->height, channels);
431
fwrite(image->data, 1, image->width * image->height * channels, f);
441
isPixmap(WMPropList *prop)
446
p = WMGetFromPLArray(prop, 0);
447
s = WMGetFromPLString(p);
448
if (strcasecmp(&s[1], "pixmap")==0)
455
/**********************************************************************/
458
drawResizebarBevel(RImage *img)
463
int width = img->width;
464
int height = img->height;
468
black.red = black.green = black.blue = 0;
471
light.red = light.green = light.blue = 80;
474
dark.red = dark.green = dark.blue = 40;
476
ROperateLine(img, RSubtractOperation, 0, 0, width-1, 0, &dark);
477
ROperateLine(img, RAddOperation, 0, 1, width-1, 1, &light);
479
ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height-1, &dark);
480
ROperateLine(img, RAddOperation, cwidth+1, 2, cwidth+1, height-1, &light);
482
ROperateLine(img, RSubtractOperation, width-cwidth-2, 2, width-cwidth-2,
484
ROperateLine(img, RAddOperation, width-cwidth-1, 2, width-cwidth-1,
487
RDrawLine(img, 0, height-1, width-1, height-1, &black);
488
RDrawLine(img, 0, 0, 0, height-1, &black);
489
RDrawLine(img, width-1, 0, width-1, height-1, &black);
494
drawMenuBevel(RImage *img)
496
RColor light, dark, mid;
498
int iheight = img->height / 4;
501
light.red = light.green = light.blue = 80;
504
dark.red = dark.green = dark.blue = 0;
507
mid.red = mid.green = mid.blue = 40;
509
for (i = 1; i < 4; i++) {
510
ROperateLine(img, RSubtractOperation, 0, i*iheight-2,
511
img->width-1, i*iheight-2, &mid);
513
RDrawLine(img, 0, i*iheight-1, img->width-1, i*iheight-1, &dark);
515
ROperateLine(img, RAddOperation, 1, i*iheight,
516
img->width-2, i*iheight, &light);
522
renderTexture(WMScreen *scr, WMPropList *texture, int width, int height,
523
char *path, int border)
526
RImage *image = NULL;
528
RContext *rc = WMScreenRContext(scr);
533
type = WMGetFromPLString(WMGetFromPLArray(texture, 0));
535
if (strcasecmp(type, "solid")==0) {
537
str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
539
str2rcolor(rc, str, &rcolor);
541
image = RCreateImage(width, height, False);
542
RClearImage(image, &rcolor);
543
} else if (strcasecmp(type, "igradient")==0) {
547
str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
548
str2rcolor(rc, str, &c1[0]);
549
str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
550
str2rcolor(rc, str, &c1[1]);
551
str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
554
str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
555
str2rcolor(rc, str, &c2[0]);
556
str = WMGetFromPLString(WMGetFromPLArray(texture, 5));
557
str2rcolor(rc, str, &c2[1]);
558
str = WMGetFromPLString(WMGetFromPLArray(texture, 6));
561
image = RRenderInterwovenGradient(width, height, c1, t1, c2, t2);
562
} else if (strcasecmp(&type[1], "gradient")==0) {
566
switch (toupper(type[0])) {
568
style = RVerticalGradient;
571
style = RHorizontalGradient;
575
style = RDiagonalGradient;
579
str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
580
str2rcolor(rc, str, &rcolor);
581
str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
582
str2rcolor(rc, str, &rcolor2);
584
image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
585
} else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='T') {
589
RImage *grad, *timage;
592
switch (toupper(type[1])) {
594
style = RVerticalGradient;
597
style = RHorizontalGradient;
601
style = RDiagonalGradient;
605
str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
606
str2rcolor(rc, str, &rcolor);
607
str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
608
str2rcolor(rc, str, &rcolor2);
610
str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
612
if ((path=wfindfileinarray(GetObjectForKey("PixmapPath"), str))!=NULL)
613
timage = RLoadImage(rc, path, 0);
615
if (!path || !timage) {
616
wwarning("could not load file '%s': %s", path,
617
RMessageForError(RErrorCode));
619
grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
621
image = RMakeTiledImage(timage, width, height);
622
RReleaseImage(timage);
624
i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
626
RCombineImagesWithOpaqueness(image, grad, i);
629
} else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='M') {
634
switch (toupper(type[1])) {
636
style = RVerticalGradient;
639
style = RHorizontalGradient;
643
style = RDiagonalGradient;
647
j = WMGetPropListItemCount(texture);
650
colors = wmalloc(j * sizeof(RColor*));
652
for (i = 2; i < j; i++) {
653
str = WMGetFromPLString(WMGetFromPLArray(texture, i));
654
colors[i-2] = wmalloc(sizeof(RColor));
655
str2rcolor(rc, str, colors[i-2]);
659
image = RRenderMultiGradient(width, height, colors, style);
661
for (i = 0; colors[i]!=NULL; i++)
665
} else if (strcasecmp(&type[1], "pixmap")==0) {
666
RImage *timage = NULL;
670
str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
672
if ((path=wfindfileinarray(GetObjectForKey("PixmapPath"), str))!=NULL)
673
timage = RLoadImage(rc, path, 0);
675
if (!path || !timage) {
676
wwarning("could not load file '%s': %s", path ? path : str,
677
RMessageForError(RErrorCode));
679
str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
680
str2rcolor(rc, str, &color);
682
switch (toupper(type[0])) {
684
image = RMakeTiledImage(timage, width, height);
685
RReleaseImage(timage);
689
image = RMakeCenteredImage(timage, width, height, &color);
690
RReleaseImage(timage);
695
image = RScaleImage(timage, width, height);
696
RReleaseImage(timage);
709
dumpRImage(path, image);
713
if (border == RESIZEBAR_BEVEL) {
714
drawResizebarBevel(image);
715
} else if (border == MENU_BEVEL) {
716
drawMenuBevel(image);
717
RBevelImage(image, RBEV_RAISED2);
720
RBevelImage(image, border);
723
RConvertImage(rc, image, &pixmap);
724
RReleaseImage(image);
731
renderMenu(_Panel *panel, WMPropList *texture, int width, int iheight)
733
WMScreen *scr = WMWidgetScreen(panel->parent);
734
Display *dpy = WMScreenDisplay(scr);
736
GC gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
739
switch (panel->menuStyle) {
741
tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
743
pix = XCreatePixmap(dpy, tmp, width, iheight*4, WMScreenDepth(scr));
744
for (i = 0; i < 4; i++) {
745
XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight*i);
747
XFreePixmap(dpy, tmp);
750
pix = renderTexture(scr, texture, width, iheight*4, NULL, MENU_BEVEL);
753
pix = renderTexture(scr, texture, width, iheight*4, NULL, RBEV_RAISED2);
763
renderPreview(_Panel *panel, GC gc, int part, int relief)
766
TextureListItem *titem;
768
WMScreen *scr = WMWidgetScreen(panel->box);
770
item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
771
titem = (TextureListItem*)item->clientData;
773
pix = renderTexture(scr, titem->prop,
774
previewPositions[part].size.width,
775
previewPositions[part].size.height,
778
XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
779
previewPositions[part].size.width,
780
previewPositions[part].size.height,
781
previewPositions[part].pos.x,
782
previewPositions[part].pos.y);
784
XCopyArea(WMScreenDisplay(scr), pix, panel->previewNoText, gc, 0, 0,
785
previewPositions[part].size.width,
786
previewPositions[part].size.height,
787
previewPositions[part].pos.x,
788
previewPositions[part].pos.y);
790
XFreePixmap(WMScreenDisplay(scr), pix);
795
updatePreviewBox(_Panel *panel, int elements)
797
WMScreen *scr = WMWidgetScreen(panel->parent);
798
Display *dpy = WMScreenDisplay(scr);
802
WMColor *black = WMBlackColor(scr);
804
gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
807
if (panel->preview == None) {
811
panel->previewNoText = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
812
240-4, 215-4, WMScreenDepth(scr));
814
p = WMCreatePixmap(scr, 240-4, 215-4, WMScreenDepth(scr), False);
815
panel->preview = WMGetPixmapXID(p);
816
WMSetLabelImage(panel->prevL, p);
819
color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
820
XFillRectangle(dpy, panel->preview, WMColorGC(color),
822
XFillRectangle(dpy, panel->previewNoText, WMColorGC(color),
824
WMReleaseColor(color);
828
if (elements & (1<<PFOCUSED)) {
829
renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
830
XDrawRectangle(dpy, panel->preview, WMColorGC(black),
831
previewPositions[PFOCUSED].pos.x-1,
832
previewPositions[PFOCUSED].pos.y-1,
833
previewPositions[PFOCUSED].size.width,
834
previewPositions[PFOCUSED].size.height);
835
XDrawRectangle(dpy, panel->previewNoText, WMColorGC(black),
836
previewPositions[PFOCUSED].pos.x-1,
837
previewPositions[PFOCUSED].pos.y-1,
838
previewPositions[PFOCUSED].size.width,
839
previewPositions[PFOCUSED].size.height);
840
colorUpdate |= FTITLE_COL;
842
if (elements & (1<<PUNFOCUSED)) {
843
renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
844
XDrawRectangle(dpy, panel->preview, WMColorGC(black),
845
previewPositions[PUNFOCUSED].pos.x-1,
846
previewPositions[PUNFOCUSED].pos.y-1,
847
previewPositions[PUNFOCUSED].size.width,
848
previewPositions[PUNFOCUSED].size.height);
849
XDrawRectangle(dpy, panel->previewNoText, WMColorGC(black),
850
previewPositions[PUNFOCUSED].pos.x-1,
851
previewPositions[PUNFOCUSED].pos.y-1,
852
previewPositions[PUNFOCUSED].size.width,
853
previewPositions[PUNFOCUSED].size.height);
854
colorUpdate |= UTITLE_COL;
856
if (elements & (1<<POWNER)) {
857
renderPreview(panel, gc, POWNER, RBEV_RAISED2);
858
XDrawRectangle(dpy, panel->preview, WMColorGC(black),
859
previewPositions[POWNER].pos.x-1,
860
previewPositions[POWNER].pos.y-1,
861
previewPositions[POWNER].size.width,
862
previewPositions[POWNER].size.height);
863
XDrawRectangle(dpy, panel->previewNoText, WMColorGC(black),
864
previewPositions[POWNER].pos.x-1,
865
previewPositions[POWNER].pos.y-1,
866
previewPositions[POWNER].size.width,
867
previewPositions[POWNER].size.height);
868
colorUpdate |= OTITLE_COL;
870
if (elements & (1<<PRESIZEBAR)) {
871
renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
873
if (elements & (1<<PMTITLE)) {
874
renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
875
colorUpdate |= MTITLE_COL;
877
if (elements & (1<<PMITEM)) {
879
TextureListItem *titem;
881
item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
882
titem = (TextureListItem*)item->clientData;
884
pix = renderMenu(panel, titem->prop,
885
previewPositions[PMITEM].size.width,
886
previewPositions[PMITEM].size.height/4);
888
XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
889
previewPositions[PMITEM].size.width,
890
previewPositions[PMITEM].size.height,
891
previewPositions[PMITEM].pos.x,
892
previewPositions[PMITEM].pos.y);
894
XCopyArea(dpy, pix, panel->previewNoText, gc, 0, 0,
895
previewPositions[PMITEM].size.width,
896
previewPositions[PMITEM].size.height,
897
previewPositions[PMITEM].pos.x,
898
previewPositions[PMITEM].pos.y);
900
XFreePixmap(dpy, pix);
902
colorUpdate |= MITEM_COL|MDISAB_COL|MHIGH_COL|MHIGHT_COL;
904
if (elements & (1<<PMITEM|1<<PMTITLE)) {
905
XDrawLine(dpy, panel->preview, gc, 29, 120, 29, 120+20*4+20);
906
XDrawLine(dpy, panel->preview, gc, 29, 119, 119, 119);
908
XDrawLine(dpy, panel->previewNoText, gc, 29, 120, 29, 120+20*4+20);
909
XDrawLine(dpy, panel->previewNoText, gc, 29, 119, 119, 119);
911
if (elements & (1<<PICON)) {
913
TextureListItem *titem;
915
item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
916
titem = (TextureListItem*)item->clientData;
918
renderPreview(panel, gc, PICON,
919
titem->ispixmap ? 0 : RBEV_RAISED3);
921
colorUpdate |= ICONT_COL|ICONB_COL|CLIP_COL|CCLIP_COL;
925
updateColorPreviewBox(panel, colorUpdate);
927
WMRedisplayWidget(panel->prevL);
930
WMReleaseColor(black);
937
cancelNewTexture(void *data)
939
_Panel *panel = (_Panel*)data;
941
HideTexturePanel(panel->texturePanel);
948
makeFileName(char *prefix)
952
fname = wstrdup(prefix);
954
while (access(fname, F_OK)==0) {
958
sprintf(buf, "%08lx.cache", time(NULL));
959
fname = wstrconcat(prefix, buf);
969
okNewTexture(void *data)
971
_Panel *panel = (_Panel*)data;
976
TextureListItem *titem;
977
WMScreen *scr = WMWidgetScreen(panel->parent);
979
titem = wmalloc(sizeof(TextureListItem));
980
memset(titem, 0, sizeof(TextureListItem));
982
HideTexturePanel(panel->texturePanel);
984
name = GetTexturePanelTextureName(panel->texturePanel);
986
prop = GetTexturePanelTexture(panel->texturePanel);
988
str = WMGetPropListDescription(prop, False);
992
titem->texture = str;
993
titem->selectedFor = 0;
995
titem->ispixmap = isPixmap(prop);
997
titem->path = makeFileName(panel->fprefix);
998
titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT,
1001
item = WMAddListItem(panel->texLs, "");
1002
item->clientData = titem;
1004
WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
1009
okEditTexture(void *data)
1011
_Panel *panel = (_Panel*)data;
1016
TextureListItem *titem;
1018
item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
1019
titem = (TextureListItem*)item->clientData;
1021
HideTexturePanel(panel->texturePanel);
1023
if (titem->current) {
1024
name = GetTexturePanelTextureName(panel->texturePanel);
1026
wfree(titem->title);
1027
titem->title = name;
1030
prop = GetTexturePanelTexture(panel->texturePanel);
1032
str = WMGetPropListDescription(prop, False);
1034
WMReleasePropList(titem->prop);
1037
titem->ispixmap = isPixmap(prop);
1039
wfree(titem->texture);
1040
titem->texture = str;
1042
XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
1043
titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
1044
TEXPREV_WIDTH, TEXPREV_HEIGHT,
1047
WMRedisplayWidget(panel->texLs);
1049
if (titem->selectedFor)
1050
updatePreviewBox(panel, titem->selectedFor);
1052
changePage(panel->secP, panel);
1058
editTexture(WMWidget *w, void *data)
1060
_Panel *panel = (_Panel*)data;
1062
TextureListItem *titem;
1064
item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
1065
titem = (TextureListItem*)item->clientData;
1067
SetTexturePanelPixmapPath(panel->texturePanel,
1068
GetObjectForKey("PixmapPath"));
1070
SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
1072
SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1073
SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
1075
ShowTexturePanel(panel->texturePanel);
1081
newTexture(WMWidget *w, void *data)
1083
_Panel *panel = (_Panel*)data;
1085
SetTexturePanelPixmapPath(panel->texturePanel,
1086
GetObjectForKey("PixmapPath"));
1088
SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
1090
SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
1092
SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
1094
ShowTexturePanel(panel->texturePanel);
1100
deleteTexture(WMWidget *w, void *data)
1102
_Panel *panel = (_Panel*)data;
1104
TextureListItem *titem;
1108
section = WMGetPopUpButtonSelectedItem(panel->secP);
1109
row = WMGetListSelectedItemRow(panel->texLs);
1110
item = WMGetListItem(panel->texLs, row);
1111
titem = (TextureListItem*)item->clientData;
1113
if (titem->selectedFor & (1 << section)) {
1114
TextureListItem *titem2;
1116
panel->textureIndex[section] = section;
1117
item = WMGetListItem(panel->texLs, section);
1118
titem2 = (TextureListItem*)item->clientData;
1119
titem2->selectedFor |= 1 << section;
1122
wfree(titem->title);
1123
wfree(titem->texture);
1124
WMReleasePropList(titem->prop);
1126
if (remove(titem->path) < 0 && errno != ENOENT) {
1127
wsyserror("could not remove file %s", titem->path);
1134
WMRemoveListItem(panel->texLs, row);
1135
WMSetButtonEnabled(panel->delB, False);
1142
extractTexture(WMWidget *w, void *data)
1144
_Panel *panel = (_Panel*)data;
1146
WMOpenPanel *opanel;
1147
WMScreen *scr = WMWidgetScreen(w);
1149
opanel = WMGetOpenPanel(scr);
1150
WMSetFilePanelCanChooseDirectories(opanel, False);
1151
WMSetFilePanelCanChooseFiles(opanel, True);
1153
if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(),
1154
_("Select File"), NULL)) {
1155
path = WMGetFilePanelFileName(opanel);
1157
OpenExtractPanelFor(panel, path);
1165
changePage(WMWidget *w, void *data)
1167
_Panel *panel = (_Panel*)data;
1170
TextureListItem *titem;
1171
WMScreen *scr = WMWidgetScreen(panel->box);
1172
RContext *rc = WMScreenRContext(scr);
1173
static WMPoint positions[] = {
1184
section = WMGetPopUpButtonSelectedItem(panel->secP);
1186
WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1188
WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1190
item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1192
titem = (TextureListItem*)item->clientData;
1197
color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
1198
XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1199
positions[panel->oldsection].x,
1200
positions[panel->oldsection].y, 22, 22);
1201
WMReleaseColor(color);
1204
panel->oldsection = section;
1205
WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1206
positions[section].y);
1208
WMRedisplayWidget(panel->prevL);
1214
previewClick(XEvent *event, void *clientData)
1216
_Panel *panel = (_Panel*)clientData;
1219
switch (panel->oldTabItem) {
1221
for (i = 0; i < sizeof(previewPositions)/sizeof(WMRect); i++) {
1222
if (event->xbutton.x >= previewPositions[i].pos.x
1223
&& event->xbutton.y >= previewPositions[i].pos.y
1224
&& event->xbutton.x < previewPositions[i].pos.x
1225
+ previewPositions[i].size.width
1226
&& event->xbutton.y < previewPositions[i].pos.y
1227
+ previewPositions[i].size.height) {
1229
WMSetPopUpButtonSelectedItem(panel->secP, i);
1230
changePage(panel->secP, panel);
1236
for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1237
if (event->xbutton.x >= previewColorPositions[i].pos.x
1238
&& event->xbutton.y >= previewColorPositions[i].pos.y
1239
&& event->xbutton.x < previewColorPositions[i].pos.x
1240
+ previewColorPositions[i].size.width
1241
&& event->xbutton.y < previewColorPositions[i].pos.y
1242
+ previewColorPositions[i].size.height) {
1248
WMSetPopUpButtonSelectedItem(panel->colP, i);
1249
changeColorPage(panel->colP, panel);
1259
textureClick(WMWidget *w, void *data)
1261
_Panel *panel = (_Panel*)data;
1264
TextureListItem *titem;
1266
i = WMGetListSelectedItemRow(panel->texLs);
1268
item = WMGetListItem(panel->texLs, i);
1270
titem = (TextureListItem*)item->clientData;
1272
if (titem->current) {
1273
WMSetButtonEnabled(panel->delB, False);
1275
WMSetButtonEnabled(panel->delB, True);
1282
textureDoubleClick(WMWidget *w, void *data)
1284
_Panel *panel = (_Panel*)data;
1287
TextureListItem *titem;
1289
/* unselect old texture */
1290
section = WMGetPopUpButtonSelectedItem(panel->secP);
1292
item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1293
titem = (TextureListItem*)item->clientData;
1294
titem->selectedFor &= ~(1 << section);
1296
/* select new texture */
1297
i = WMGetListSelectedItemRow(panel->texLs);
1299
item = WMGetListItem(panel->texLs, i);
1301
titem = (TextureListItem*)item->clientData;
1303
titem->selectedFor |= 1<<section;
1305
panel->textureIndex[section] = i;
1307
WMRedisplayWidget(panel->texLs);
1309
updatePreviewBox(panel, 1<<section);
1315
paintListItem(WMList *lPtr, int index, Drawable d, char *text, int state,
1318
_Panel *panel = (_Panel*)WMGetHangedData(lPtr);
1319
WMScreen *scr = WMWidgetScreen(lPtr);
1320
int width, height, x, y;
1321
Display *dpy = WMScreenDisplay(scr);
1322
WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
1324
WMColor *black = WMBlackColor(scr);
1325
TextureListItem *titem;
1327
item = WMGetListItem(lPtr, index);
1328
titem = (TextureListItem*)item->clientData;
1330
WMReleaseColor(back);
1331
WMReleaseColor(black);
1335
width = rect->size.width;
1336
height = rect->size.height;
1340
XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
1343
XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1344
TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1346
if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1347
WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1348
else if (titem->selectedFor)
1349
WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1351
WMDrawString(scr, d, black, panel->boldFont,
1352
x + TEXPREV_WIDTH + 22, y + 2, titem->title,
1353
strlen(titem->title));
1355
WMDrawString(scr, d, black, panel->smallFont,
1356
x + TEXPREV_WIDTH + 14, y + 18, titem->texture,
1357
strlen(titem->texture));
1360
WMReleaseColor(back);
1361
WMReleaseColor(black);
1367
loadRImage(WMScreen *scr, char *path)
1374
f = fopen(path, "rb");
1378
fscanf(f, "%02x%02x%1x", &w, &h, &d);
1380
image = RCreateImage(w, h, d == 4);
1381
fread(image->data, 1, w*h*d, f);
1384
RConvertImage(WMScreenRContext(scr), image, &pixmap);
1385
RReleaseImage(image);
1393
fillTextureList(WMList *lPtr)
1395
WMPropList *textureList;
1396
WMPropList *texture;
1397
WMUserDefaults *udb = WMGetStandardUserDefaults();
1398
TextureListItem *titem;
1399
WMScreen *scr = WMWidgetScreen(lPtr);
1402
textureList = WMGetUDObjectForKey(udb, "TextureList");
1406
for (i = 0; i < WMGetPropListItemCount(textureList); i++) {
1409
texture = WMGetFromPLArray(textureList, i);
1411
titem = wmalloc(sizeof(TextureListItem));
1412
memset(titem, 0, sizeof(TextureListItem));
1414
titem->title = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 0)));
1415
titem->prop = WMRetainPropList(WMGetFromPLArray(texture, 1));
1416
titem->texture = WMGetPropListDescription(titem->prop, False);
1417
titem->selectedFor = 0;
1418
titem->path = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
1420
titem->preview = loadRImage(scr, titem->path);
1421
if (!titem->preview) {
1422
titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH,
1423
TEXPREV_HEIGHT, NULL, 0);
1425
item = WMAddListItem(lPtr, "");
1426
item->clientData = titem;
1432
fillColorList(_Panel *panel)
1436
WMUserDefaults *udb = WMGetStandardUserDefaults();
1437
WMScreen *scr = WMWidgetScreen(panel->box);
1440
list = WMGetUDObjectForKey(udb, "ColorList");
1442
for (i = 0; i < 24; i++) {
1443
color = WMCreateNamedColor(scr, sampleColors[i], False);
1446
WMSetColorWellColor(panel->sampW[i], color);
1447
WMReleaseColor(color);
1452
for (i = 0; i < WMIN(24, WMGetPropListItemCount(list)); i++) {
1453
c = WMGetFromPLArray(list, i);
1454
if (!c || !WMIsPLString(c))
1456
color = WMCreateNamedColor(scr, WMGetFromPLString(c), False);
1459
WMSetColorWellColor(panel->sampW[i], color);
1460
WMReleaseColor(color);
1466
/*************************************************************************/
1470
changeColorPage(WMWidget *w, void *data)
1472
_Panel *panel = (_Panel*)data;
1474
WMScreen *scr = WMWidgetScreen(panel->box);
1475
RContext *rc = WMScreenRContext(scr);
1476
static WMPoint positions[] = {
1491
if (panel->preview) {
1494
color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
1495
XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1496
positions[panel->oldcsection].x,
1497
positions[panel->oldcsection].y, 22, 22);
1498
WMReleaseColor(color);
1501
section = WMGetPopUpButtonSelectedItem(panel->colP);
1503
panel->oldcsection = section;
1505
WMDrawPixmap(panel->hand, panel->preview, positions[section].x,
1506
positions[section].y);
1508
section = WMGetPopUpButtonSelectedItem(panel->colP);
1510
WMSetColorWellColor(panel->colW, panel->colors[section]);
1512
WMRedisplayWidget(panel->prevL);
1517
paintText(WMScreen *scr, Drawable d, WMColor *color, WMFont *font,
1518
int x, int y, int w, int h, WMAlignment align, char *text)
1520
int l = strlen(text);
1527
x += w - 5 - WMWidthOfString(font, text, l);
1531
x += (w - WMWidthOfString(font, text, l))/2;
1534
WMDrawString(scr, d, color, font, x, y + (h - WMFontHeight(font))/2,
1541
updateColorPreviewBox(_Panel *panel, int elements)
1543
WMScreen *scr = WMWidgetScreen(panel->box);
1544
Display *dpy = WMScreenDisplay(scr);
1549
pnot = panel->previewNoText;
1550
gc = WMColorGC(panel->colors[0]);
1552
if (elements & FTITLE_COL) {
1553
XCopyArea(dpy, pnot, d, gc, 30, 10, 190, 20, 30, 10);
1554
paintText(scr, d, panel->colors[0], panel->boldFont, 30, 10, 190, 20,
1555
panel->titleAlignment, _("Focused Window"));
1557
if (elements & UTITLE_COL) {
1558
XCopyArea(dpy, pnot, d, gc, 30, 40, 190, 20, 30, 40);
1559
paintText(scr, d, panel->colors[1], panel->boldFont, 30, 40, 190, 20,
1560
panel->titleAlignment, _("Unfocused Window"));
1562
if (elements & OTITLE_COL) {
1563
XCopyArea(dpy, pnot, d, gc, 30, 70, 190, 20, 30, 70);
1564
paintText(scr, d, panel->colors[2], panel->boldFont, 30, 70, 190, 20,
1565
panel->titleAlignment, _("Owner of Focused Window"));
1567
if (elements & MTITLE_COL) {
1568
XCopyArea(dpy, pnot, d, gc, 30, 120, 90, 20, 30, 120);
1569
paintText(scr, d, panel->colors[3], panel->boldFont, 30, 120, 90, 20,
1570
WALeft, _("Menu Title"));
1572
if (elements & MITEM_COL) {
1573
XCopyArea(dpy, pnot, d, gc, 30, 140, 90, 20, 30, 140);
1574
paintText(scr, d, panel->colors[4], panel->normalFont, 30, 140, 90, 20,
1575
WALeft, _("Normal Item"));
1576
XCopyArea(dpy, pnot, d, gc, 30, 200, 90, 20, 30, 200);
1577
paintText(scr, d, panel->colors[4], panel->normalFont, 30, 200, 90, 20,
1578
WALeft, _("Normal Item"));
1580
if (elements & MDISAB_COL) {
1581
XCopyArea(dpy, pnot, d, gc, 30, 160, 90, 20, 30, 160);
1582
paintText(scr, d, panel->colors[5], panel->normalFont, 30, 160, 90, 20,
1583
WALeft, _("Disabled Item"));
1585
if (elements & MHIGH_COL) {
1586
XFillRectangle(WMScreenDisplay(scr), d, WMColorGC(panel->colors[6]),
1588
XFillRectangle(WMScreenDisplay(scr), pnot, WMColorGC(panel->colors[6]),
1590
elements |= MHIGHT_COL;
1592
if (elements & MHIGHT_COL) {
1593
XCopyArea(dpy, pnot, d, gc, 30, 180, 90, 20, 30, 180);
1594
paintText(scr, d, panel->colors[7], panel->normalFont, 30, 180, 90, 20,
1595
WALeft, _("Highlighted"));
1598
if (elements & ICONT_COL) {
1599
WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1602
if (elements & ICONB_COL) {
1603
WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1606
if (elements & CLIP_COL) {
1607
WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1610
if (elements & CCLIP_COL) {
1611
WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1615
WMRedisplayWidget(panel->prevL);
1620
colorWellObserver(void *self, WMNotification *n)
1622
_Panel *panel = (_Panel*)self;
1625
p = WMGetPopUpButtonSelectedItem(panel->colP);
1627
WMReleaseColor(panel->colors[p]);
1629
panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
1631
updateColorPreviewBox(panel, 1<<p);
1636
changedTabItem(struct WMTabViewDelegate *self, WMTabView *tabView,
1637
WMTabViewItem *item)
1639
_Panel *panel = self->data;
1642
i = WMGetTabViewItemIdentifier(item);
1645
switch (panel->oldTabItem) {
1647
changeColorPage(NULL, panel);
1650
changePage(panel->secP, panel);
1653
switch (panel->oldTabItem) {
1655
changePage(NULL, panel);
1658
changeColorPage(panel->colP, panel);
1661
switch (panel->oldTabItem) {
1663
changePage(NULL, panel);
1666
changeColorPage(NULL, panel);
1672
panel->oldTabItem = i;
1676
/*************************************************************************/
1679
menuStyleCallback(WMWidget *self, void *data)
1681
_Panel *panel = (_Panel*)data;
1683
if (self == panel->mstyB[0]) {
1684
panel->menuStyle = MSTYLE_NORMAL;
1685
updatePreviewBox(panel, 1<<PMITEM);
1687
} else if (self == panel->mstyB[1]) {
1688
panel->menuStyle = MSTYLE_SINGLE;
1689
updatePreviewBox(panel, 1<<PMITEM);
1691
} else if (self == panel->mstyB[2]) {
1692
panel->menuStyle = MSTYLE_FLAT;
1693
updatePreviewBox(panel, 1<<PMITEM);
1699
titleAlignCallback(WMWidget *self, void *data)
1701
_Panel *panel = (_Panel*)data;
1703
if (self == panel->taliB[0]) {
1704
panel->titleAlignment = WALeft;
1705
updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1707
} else if (self == panel->taliB[1]) {
1708
panel->titleAlignment = WACenter;
1709
updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1711
} else if (self == panel->taliB[2]) {
1712
panel->titleAlignment = WARight;
1713
updatePreviewBox(panel, 1<<PFOCUSED|1<<PUNFOCUSED|1<<POWNER);
1719
createPanel(Panel *p)
1721
_Panel *panel = (_Panel*)p;
1723
WMScreen *scr = WMWidgetScreen(panel->parent);
1724
WMTabViewItem *item;
1729
panel->fprefix = wstrconcat(wusergnusteppath(), "/.AppInfo");
1731
if (access(panel->fprefix, F_OK)!=0) {
1732
if (mkdir(panel->fprefix, 0755) < 0) {
1733
wsyserror(panel->fprefix);
1738
tmp = wstrconcat(panel->fprefix, "/WPrefs/");
1739
wfree(panel->fprefix);
1740
panel->fprefix = tmp;
1741
if (access(panel->fprefix, F_OK)!=0) {
1742
if (mkdir(panel->fprefix, 0755) < 0) {
1743
wsyserror(panel->fprefix);
1748
panel->smallFont = WMSystemFontOfSize(scr, 10);
1749
panel->normalFont = WMSystemFontOfSize(scr, 12);
1750
panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1752
panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1753
panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1754
panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1756
panel->box = WMCreateBox(panel->parent);
1757
WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1760
panel->prevL = WMCreateLabel(panel->box);
1761
WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1762
WMMoveWidget(panel->prevL, 15, 10);
1763
WMSetLabelRelief(panel->prevL, WRSunken);
1764
WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1766
WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask,
1767
previewClick, panel);
1772
tabviewDelegate.data = panel;
1774
panel->tabv = WMCreateTabView(panel->box);
1775
WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1776
WMMoveWidget(panel->tabv, 265, 10);
1777
WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
1779
/*** texture list ***/
1781
panel->texF = WMCreateFrame(panel->box);
1782
WMSetFrameRelief(panel->texF, WRFlat);
1784
item = WMCreateTabViewItemWithIdentifier(0);
1785
WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1786
WMSetTabViewItemLabel(item, _("Texture"));
1788
WMAddItemInTabView(panel->tabv, item);
1791
panel->secP = WMCreatePopUpButton(panel->texF);
1792
WMResizeWidget(panel->secP, 228, 20);
1793
WMMoveWidget(panel->secP, 7, 7);
1794
WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1795
WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1796
WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1797
WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1798
WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1799
WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1800
WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1801
/* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1803
WMSetPopUpButtonSelectedItem(panel->secP, 0);
1804
WMSetPopUpButtonAction(panel->secP, changePage, panel);
1806
panel->texLs = WMCreateList(panel->texF);
1807
WMResizeWidget(panel->texLs, 165, 155);
1808
WMMoveWidget(panel->texLs, 70, 33);
1809
WMSetListUserDrawItemHeight(panel->texLs, 35);
1810
WMSetListUserDrawProc(panel->texLs, paintListItem);
1811
WMHangData(panel->texLs, panel);
1812
WMSetListAction(panel->texLs, textureClick, panel);
1813
WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1815
WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1816
"for the selected item."),
1817
WMWidgetView(panel->texLs));
1819
/* command buttons */
1821
font = WMSystemFontOfSize(scr, 10);
1824
panel->newB = WMCreateCommandButton(panel->texF);
1825
WMResizeWidget(panel->newB, 57, 39);
1826
WMMoveWidget(panel->newB, 7, 33);
1827
WMSetButtonFont(panel->newB, font);
1828
WMSetButtonImagePosition(panel->newB, WIPAbove);
1829
WMSetButtonText(panel->newB, _("New"));
1830
WMSetButtonAction(panel->newB, newTexture, panel);
1831
SetButtonAlphaImage(scr, panel->newB, TNEW_FILE, NULL, NULL);
1833
WMSetBalloonTextForView(_("Create a new texture."),
1834
WMWidgetView(panel->newB));
1836
panel->ripB = WMCreateCommandButton(panel->texF);
1837
WMResizeWidget(panel->ripB, 57, 39);
1838
WMMoveWidget(panel->ripB, 7, 72);
1839
WMSetButtonFont(panel->ripB, font);
1840
WMSetButtonImagePosition(panel->ripB, WIPAbove);
1841
WMSetButtonText(panel->ripB, _("Extract..."));
1842
WMSetButtonAction(panel->ripB, extractTexture, panel);
1843
SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE, NULL, NULL);
1845
WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."),
1846
WMWidgetView(panel->ripB));
1848
WMSetButtonEnabled(panel->ripB, False);
1850
panel->editB = WMCreateCommandButton(panel->texF);
1851
WMResizeWidget(panel->editB, 57, 39);
1852
WMMoveWidget(panel->editB, 7, 111);
1853
WMSetButtonFont(panel->editB, font);
1854
WMSetButtonImagePosition(panel->editB, WIPAbove);
1855
WMSetButtonText(panel->editB, _("Edit"));
1856
SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE, NULL, NULL);
1857
WMSetButtonAction(panel->editB, editTexture, panel);
1858
WMSetBalloonTextForView(_("Edit the highlighted texture."),
1859
WMWidgetView(panel->editB));
1861
panel->delB = WMCreateCommandButton(panel->texF);
1862
WMResizeWidget(panel->delB, 57, 38);
1863
WMMoveWidget(panel->delB, 7, 150);
1864
WMSetButtonFont(panel->delB, font);
1865
WMSetButtonImagePosition(panel->delB, WIPAbove);
1866
WMSetButtonText(panel->delB, _("Delete"));
1867
SetButtonAlphaImage(scr, panel->delB, TDEL_FILE, NULL, NULL);
1868
WMSetButtonEnabled(panel->delB, False);
1869
WMSetButtonAction(panel->delB, deleteTexture, panel);
1870
WMSetBalloonTextForView(_("Delete the highlighted texture."),
1871
WMWidgetView(panel->delB));
1873
WMReleaseFont(font);
1875
WMMapSubwidgets(panel->texF);
1878
panel->colF = WMCreateFrame(panel->box);
1879
WMSetFrameRelief(panel->colF, WRFlat);
1881
item = WMCreateTabViewItemWithIdentifier(1);
1882
WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1883
WMSetTabViewItemLabel(item, _("Color"));
1885
WMAddItemInTabView(panel->tabv, item);
1887
panel->colP = WMCreatePopUpButton(panel->colF);
1888
WMResizeWidget(panel->colP, 228, 20);
1889
WMMoveWidget(panel->colP, 7, 7);
1890
WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1891
WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1892
WMAddPopUpButtonItem(panel->colP, _("Owner of Focused Window Title"));
1893
WMAddPopUpButtonItem(panel->colP, _("Menu Title"));
1894
WMAddPopUpButtonItem(panel->colP, _("Menu Item Text"));
1895
WMAddPopUpButtonItem(panel->colP, _("Disabled Menu Item Text"));
1896
WMAddPopUpButtonItem(panel->colP, _("Menu Highlight Color"));
1897
WMAddPopUpButtonItem(panel->colP, _("Highlighted Menu Text Color"));
1899
WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1900
WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1901
WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1902
WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1905
WMSetPopUpButtonSelectedItem(panel->colP, 0);
1907
WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1910
panel->colW = WMCreateColorWell(panel->colF);
1911
WMResizeWidget(panel->colW, 65, 50);
1912
WMMoveWidget(panel->colW, 30, 75);
1913
WMAddNotificationObserver(colorWellObserver, panel,
1914
WMColorWellDidChangeNotification, panel->colW);
1916
for (i = 0; i < 4; i++) {
1918
for (j = 0; j < 6; j++) {
1919
panel->sampW[i+j*4] = WMCreateColorWell(panel->colF);
1920
WMResizeWidget(panel->sampW[i+j*4], 22, 22);
1921
WMMoveWidget(panel->sampW[i+j*4], 130 + i*22, 40 + j*22);
1922
WSetColorWellBordered(panel->sampW[i+j*4], False);
1926
WMMapSubwidgets(panel->colF);
1931
panel->bgF = WMCreateFrame(panel->box);
1932
WMSetFrameRelief(panel->bgF, WRFlat);
1934
item = WMCreateTabViewItemWithIdentifier(2);
1935
WMSetTabViewItemView(item, WMWidgetView(panel->bgF));
1936
WMSetTabViewItemLabel(item, _("Background"));
1938
WMAddItemInTabView(panel->tabv, item);
1940
panel->bgprevL = WMCreateLabel(panel->bgF);
1941
WMResizeWidget(panel->bgprevL, 230, 155);
1942
WMMoveWidget(panel->bgprevL, 5, 5);
1943
WMSetLabelRelief(panel->bgprevL, WRSunken);
1945
panel->selbgB = WMCreateCommandButton(panel->bgF);
1946
WMMoveWidget(panel->selbgB, 5, 165);
1947
WMResizeWidget(panel->selbgB, 100, 24);
1948
WMSetButtonText(panel->selbgB, _("Browse..."));
1953
WMMapSubwidgets(panel->bgF);
1954
#endif /* unfinished */
1956
panel->optF = WMCreateFrame(panel->box);
1957
WMSetFrameRelief(panel->optF, WRFlat);
1959
item = WMCreateTabViewItemWithIdentifier(3);
1960
WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1961
WMSetTabViewItemLabel(item, _("Options"));
1963
WMAddItemInTabView(panel->tabv, item);
1965
panel->mstyF = WMCreateFrame(panel->optF);
1966
WMResizeWidget(panel->mstyF, 215, 85);
1967
WMMoveWidget(panel->mstyF, 15, 10);
1968
WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1970
for (i = 0; i < 3; i++) {
1974
panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1975
WMResizeWidget(panel->mstyB[i], 54, 54);
1976
WMMoveWidget(panel->mstyB[i], 15 + i*65, 20);
1977
WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1978
WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1981
path = LocateImage(MSTYLE1_FILE);
1984
path = LocateImage(MSTYLE2_FILE);
1987
path = LocateImage(MSTYLE3_FILE);
1991
icon = WMCreatePixmapFromFile(scr, path);
1993
WMSetButtonImage(panel->mstyB[i], icon);
1994
WMReleasePixmap(icon);
1996
wwarning(_("could not load icon file %s"), path);
2001
WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
2002
WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
2004
WMMapSubwidgets(panel->mstyF);
2007
panel->taliF = WMCreateFrame(panel->optF);
2008
WMResizeWidget(panel->taliF, 110, 80);
2009
WMMoveWidget(panel->taliF, 15, 100);
2010
WMSetFrameTitle(panel->taliF, _("Title Alignment"));
2012
for (i = 0; i < 3; i++) {
2013
panel->taliB[i] = WMCreateRadioButton(panel->taliF);
2014
WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
2017
WMSetButtonText(panel->taliB[i], _("Left"));
2020
WMSetButtonText(panel->taliB[i], _("Center"));
2023
WMSetButtonText(panel->taliB[i], _("Right"));
2026
WMResizeWidget(panel->taliB[i], 90, 18);
2027
WMMoveWidget(panel->taliB[i], 10, 15 + 20*i);
2029
WMGroupButtons(panel->taliB[0], panel->taliB[1]);
2030
WMGroupButtons(panel->taliB[0], panel->taliB[2]);
2032
WMMapSubwidgets(panel->taliF);
2034
WMMapSubwidgets(panel->optF);
2038
WMRealizeWidget(panel->box);
2039
WMMapSubwidgets(panel->box);
2041
WMSetPopUpButtonSelectedItem(panel->secP, 0);
2045
changePage(panel->secP, panel);
2047
fillTextureList(panel->texLs);
2049
fillColorList(panel);
2051
panel->texturePanel = CreateTexturePanel(panel->parent);
2057
setupTextureFor(WMList *list, char *key, char *defValue, char *title,
2061
TextureListItem *titem;
2063
titem = wmalloc(sizeof(TextureListItem));
2064
memset(titem, 0, sizeof(TextureListItem));
2066
titem->title = wstrdup(title);
2067
titem->prop = GetObjectForKey(key);
2068
if (!titem->prop || !WMIsPLArray(titem->prop)) {
2069
/* Maybe also give a error message to stderr that the entry is bad? */
2070
titem->prop = WMCreatePropListFromDescription(defValue);
2072
WMRetainPropList(titem->prop);
2074
titem->texture = WMGetPropListDescription((WMPropList*)titem->prop, False);
2076
titem->selectedFor = 1<<index;
2078
titem->ispixmap = isPixmap(titem->prop);
2080
titem->preview = renderTexture(WMWidgetScreen(list), titem->prop,
2081
TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
2083
item = WMAddListItem(list, "");
2084
item->clientData = titem;
2090
showData(_Panel *panel)
2095
str = GetStringForKey("MenuStyle");
2096
if (str && strcasecmp(str, "flat")==0) {
2097
panel->menuStyle = MSTYLE_FLAT;
2098
} else if (str && strcasecmp(str, "singletexture")==0) {
2099
panel->menuStyle = MSTYLE_SINGLE;
2101
panel->menuStyle = MSTYLE_NORMAL;
2104
str = GetStringForKey("TitleJustify");
2105
if (str && strcasecmp(str, "left")==0) {
2106
panel->titleAlignment = WALeft;
2107
} else if (str && strcasecmp(str, "right")==0) {
2108
panel->titleAlignment = WARight;
2110
panel->titleAlignment = WACenter;
2113
for (i = 0; i < sizeof(colorOptions)/(2*sizeof(char*)); i++) {
2116
str = GetStringForKey(colorOptions[i*2]);
2118
str = colorOptions[i*2+1];
2120
if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->box), str, False))) {
2121
color = WMCreateNamedColor(WMWidgetScreen(panel->box), "#000000", False);
2124
panel->colors[i] = color;
2126
changeColorPage(panel->colP, panel);
2128
for (i = 0; i < sizeof(textureOptions)/(3*sizeof(char*)); i++) {
2129
setupTextureFor(panel->texLs, textureOptions[i*3],
2130
textureOptions[i*3+1], textureOptions[i*3+2], i);
2131
panel->textureIndex[i] = i;
2133
updatePreviewBox(panel, EVERYTHING);
2135
WMSetButtonSelected(panel->mstyB[panel->menuStyle], True);
2136
WMSetButtonSelected(panel->taliB[panel->titleAlignment], True);
2141
storeData(_Panel *panel)
2143
TextureListItem *titem;
2147
for (i = 0; i < sizeof(textureOptions)/(sizeof(char*)*3); i++) {
2148
item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
2149
titem = (TextureListItem*)item->clientData;
2150
SetObjectForKey(titem->prop, textureOptions[i*3]);
2153
for (i = 0; i < 8; i++) {
2156
str = WMGetColorRGBDescription(panel->colors[i]);
2159
SetStringForKey(str, colorOptions[i*2]);
2164
switch (panel->menuStyle) {
2166
SetStringForKey("singletexture", "MenuStyle");
2169
SetStringForKey("flat", "MenuStyle");
2173
SetStringForKey("normal", "MenuStyle");
2176
switch (panel->titleAlignment) {
2178
SetStringForKey("left", "TitleJustify");
2181
SetStringForKey("right", "TitleJustify");
2185
SetStringForKey("center", "TitleJustify");
2192
prepareForClose(_Panel *panel)
2194
WMPropList *textureList;
2195
WMPropList *texture;
2196
TextureListItem *titem;
2198
WMUserDefaults *udb = WMGetStandardUserDefaults();
2201
textureList = WMCreatePLArray(NULL, NULL);
2203
/* store list of textures */
2204
for (i = 7; i < WMGetListNumberOfRows(panel->texLs); i++) {
2205
item = WMGetListItem(panel->texLs, i);
2206
titem = (TextureListItem*)item->clientData;
2208
texture = WMCreatePLArray(WMCreatePLString(titem->title),
2209
WMRetainPropList(titem->prop),
2210
WMCreatePLString(titem->path),
2213
WMAddToPLArray(textureList, texture);
2216
WMSetUDObjectForKey(udb, textureList, "TextureList");
2217
WMReleasePropList(textureList);
2219
/* store list of colors */
2220
textureList = WMCreatePLArray(NULL, NULL);
2221
for (i = 0; i < 24; i++) {
2225
color = WMGetColorWellColor(panel->sampW[i]);
2227
str = WMGetColorRGBDescription(color);
2228
WMAddToPLArray(textureList, WMCreatePLString(str));
2231
WMSetUDObjectForKey(udb, textureList, "ColorList");
2232
WMReleasePropList(textureList);
2234
WMSynchronizeUserDefaults(udb);
2240
InitAppearance(WMScreen *scr, WMWindow *win)
2244
panel = wmalloc(sizeof(_Panel));
2245
memset(panel, 0, sizeof(_Panel));
2247
panel->sectionName = _("Appearance Preferences");
2249
panel->description = _("Background texture configuration for windows,\n"
2250
"menus and icons.");
2252
panel->parent = win;
2254
panel->callbacks.createWidgets = createPanel;
2255
panel->callbacks.updateDomain = storeData;
2256
panel->callbacks.prepareForClose = prepareForClose;
2258
AddSection(panel, ICON_FILE);
2265
/****************************************************************************/
2269
typedef struct ExtractPanel {
2282
OpenExtractPanelFor(_Panel *panel, char *path)
2284
ExtractPanel *epanel;
2287
WMScreen *scr = WMWidgetScreen(panel->parent);
2289
epanel = wmalloc(sizeof(ExtractPanel));
2290
epanel->win = WMCreatePanelWithStyleForWindow(panel->parent, "extract",
2292
|WMClosableWindowMask);
2293
WMResizeWidget(epanel->win, 245, 250);
2294
WMSetWindowTitle(epanel->win, _("Extract Texture"));
2296
epanel->label = WMCreateLabel(epanel->win);
2297
WMResizeWidget(epanel->label, 225, 18);
2298
WMMoveWidget(epanel->label, 10, 10);
2299
WMSetLabelTextAlignment(epanel->label, WACenter);
2300
WMSetLabelRelief(epanel->label, WRSunken);
2302
color = WMDarkGrayColor(scr);
2303
WMSetWidgetBackgroundColor(epanel->label, color);
2304
WMReleaseColor(color);
2306
color = WMWhiteColor(scr);
2307
WMSetLabelTextColor(epanel->label, color);
2308
WMReleaseColor(color);
2310
font = WMBoldSystemFontOfSize(scr, 12);
2311
WMSetLabelFont(epanel->label, font);
2312
WMReleaseFont(font);
2314
WMSetLabelText(epanel->label, _("Textures"));
2316
epanel->list = WMCreateList(epanel->win);
2317
WMResizeWidget(epanel->list, 225, 165);
2318
WMMoveWidget(epanel->list, 10, 30);
2322
epanel->closeB = WMCreateCommandButton(epanel->win);
2323
WMResizeWidget(epanel->closeB, 74, 24);
2324
WMMoveWidget(epanel->closeB, 165, 215);
2325
WMSetButtonText(epanel->closeB, _("Close"));
2327
epanel->extrB = WMCreateCommandButton(epanel->win);
2328
WMResizeWidget(epanel->extrB, 74, 24);
2329
WMMoveWidget(epanel->extrB, 80, 215);
2330
WMSetButtonText(epanel->extrB, _("Extract"));
2332
WMMapSubwidgets(epanel->win);
2335
/* take textures from file */
2339
WMRealizeWidget(epanel->win);
2341
WMMapWidget(epanel->win);