1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-08 23:04:15 +01:00

Fix some bugs, DisableMiniwindows, _KWM_WIN_ICON_GEOMETRY..

This commit is contained in:
kojima
1999-03-18 01:11:18 +00:00
parent 67a008937f
commit ea55bc5e3f
24 changed files with 658 additions and 274 deletions

View File

@@ -25,6 +25,13 @@
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
@@ -79,6 +86,7 @@ typedef struct {
char selectedFor;
unsigned current:1;
unsigned ispixmap:1;
} TextureListItem;
@@ -199,13 +207,13 @@ static void
dumpRImage(char *path, RImage *image)
{
FILE *f;
f = fopen(path, "w");
if (!f) {
wsyserror(path);
return;
}
fprintf(f, "%02x%02x%1x", image->width, image->height,
fprintf(f, "%02x%02x%1x", image->width, image->height,
image->data[3]!=NULL ? 4 : 3);
fwrite(image->data[0], 1, image->width * image->height, f);
@@ -221,6 +229,22 @@ dumpRImage(char *path, RImage *image)
static int
isPixmap(proplist_t prop)
{
proplist_t p;
char *s;
p = PLGetArrayElement(prop, 0);
s = PLGetString(p);
if (strcasecmp(&s[1], "pixmap")==0)
return 1;
else
return 0;
}
static Pixmap
renderTexture(WMScreen *scr, proplist_t texture, int width, int height,
char *path, int border)
@@ -255,6 +279,7 @@ renderTexture(WMScreen *scr, proplist_t texture, int width, int height,
case 'H':
style = RHorizontalGradient;
break;
default:
case 'D':
style = RDiagonalGradient;
break;
@@ -264,9 +289,53 @@ renderTexture(WMScreen *scr, proplist_t texture, int width, int height,
str2rcolor(rc, str, &rcolor);
str = PLGetString(PLGetArrayElement(texture, 2));
str2rcolor(rc, str, &rcolor2);
image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
} else if (strcasecmp(&type[2], "gradient")==0) {
} else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='T') {
int style;
RColor rcolor2;
int i;
RImage *grad, *timage;
char *path;
switch (toupper(type[1])) {
case 'V':
style = RVerticalGradient;
break;
case 'H':
style = RHorizontalGradient;
break;
default:
case 'D':
style = RDiagonalGradient;
break;
}
str = PLGetString(PLGetArrayElement(texture, 3));
str2rcolor(rc, str, &rcolor);
str = PLGetString(PLGetArrayElement(texture, 4));
str2rcolor(rc, str, &rcolor2);
str = PLGetString(PLGetArrayElement(texture, 1));
path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
timage = RLoadImage(rc, path, 0);
if (!timage) {
wwarning("could not load file '%s': %s", path,
RMessageForError(RErrorCode));
} else {
grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
image = RMakeTiledImage(timage, width, height);
RDestroyImage(timage);
i = atoi(PLGetString(PLGetArrayElement(texture, 2)));
RCombineImagesWithOpaqueness(image, grad, i);
RDestroyImage(grad);
}
} else if (strcasecmp(&type[2], "gradient")==0 && toupper(type[0])=='M') {
int style;
RColor **colors;
int i, j;
@@ -278,6 +347,7 @@ renderTexture(WMScreen *scr, proplist_t texture, int width, int height,
case 'H':
style = RHorizontalGradient;
break;
default:
case 'D':
style = RDiagonalGradient;
break;
@@ -302,40 +372,49 @@ renderTexture(WMScreen *scr, proplist_t texture, int width, int height,
free(colors);
}
} else if (strcasecmp(&type[1], "pixmap")==0) {
int style;
RImage *timage;
int w, h;
char *path;
RColor color;
str = PLGetString(PLGetArrayElement(texture, 1));
path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
timage = RLoadImage(rc, path, 0);
free(path);
if (toupper(type[0]) == 'T') {
if (timage->width < TEXPREV_WIDTH
|| timage->height < TEXPREV_HEIGHT) {
image = RMakeTiledImage(timage, TEXPREV_WIDTH, TEXPREV_HEIGHT);
if (!timage) {
wwarning("could not load file '%s': %s", path,
RMessageForError(RErrorCode));
} else {
str = PLGetString(PLGetArrayElement(texture, 2));
str2rcolor(rc, str, &color);
switch (toupper(type[0])) {
case 'T':
image = RMakeTiledImage(timage, width, height);
RDestroyImage(timage);
timage = image;
}
} else if (timage) {
w = timage->width;
h = timage->height;
if (w - TEXPREV_WIDTH > h - TEXPREV_HEIGHT) {
h = (w * TEXPREV_HEIGHT)/TEXPREV_WIDTH;
} else {
w = (h * TEXPREV_WIDTH)/TEXPREV_HEIGHT;
break;
case 'C':
image = RMakeCenteredImage(timage, width, height, &color);
RDestroyImage(timage);
timage = image;
break;
case 'S':
case 'M':
image = RScaleImage(timage, width, height);
RDestroyImage(timage);
timage = image;
break;
}
image = RScaleImage(timage, w, h);
RDestroyImage(timage);
timage = image;
}
free(path);
}
if (!image)
return None;
if (path) {
dumpRImage(path, image);
}
@@ -372,48 +451,48 @@ updatePreviewBox(_Panel *panel, int elements)
WMColor *color;
panel->preview = XCreatePixmap(dpy, WMWidgetXID(panel->win),
220-4, 185-4, WMScreenDepth(scr));
260-4, 165-4, WMScreenDepth(scr));
color = WMGrayColor(scr);
XFillRectangle(dpy, panel->preview, WMColorGC(color),
0, 0, 220-4, 185-4);
0, 0, 260-4, 165-4);
WMReleaseColor(color);
refresh = -1;
}
if (elements & FTITLE) {
item = WMGetListItem(panel->texLs, 0);
item = WMGetListItem(panel->texLs, panel->textureIndex[0]);
titem = (TextureListItem*)item->clientData;
pix = renderTexture(scr, titem->prop, 180, 20, NULL, RBEV_RAISED2);
pix = renderTexture(scr, titem->prop, 220, 20, NULL, RBEV_RAISED2);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 180, 20, 5, 10);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 220, 20, 5, 10);
XFreePixmap(dpy, pix);
}
if (elements & UTITLE) {
item = WMGetListItem(panel->texLs, 1);
item = WMGetListItem(panel->texLs, panel->textureIndex[1]);
titem = (TextureListItem*)item->clientData;
pix = renderTexture(scr, titem->prop, 180, 20, NULL, RBEV_RAISED2);
pix = renderTexture(scr, titem->prop, 220, 20, NULL, RBEV_RAISED2);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 180, 20, 10, 35);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 220, 20, 15, 35);
XFreePixmap(dpy, pix);
}
if (elements & OTITLE) {
item = WMGetListItem(panel->texLs, 2);
item = WMGetListItem(panel->texLs, panel->textureIndex[2]);
titem = (TextureListItem*)item->clientData;
pix = renderTexture(scr, titem->prop, 180, 20, NULL, RBEV_RAISED2);
pix = renderTexture(scr, titem->prop, 220, 20, NULL, RBEV_RAISED2);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 180, 20, 15, 60);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 220, 20, 25, 60);
XFreePixmap(dpy, pix);
}
if (elements & MTITLE) {
item = WMGetListItem(panel->texLs, 3);
item = WMGetListItem(panel->texLs, panel->textureIndex[3]);
titem = (TextureListItem*)item->clientData;
pix = renderTexture(scr, titem->prop, 100, 20, NULL, RBEV_RAISED2);
@@ -423,24 +502,30 @@ updatePreviewBox(_Panel *panel, int elements)
XFreePixmap(dpy, pix);
}
if (elements & MITEM) {
item = WMGetListItem(panel->texLs, 4);
item = WMGetListItem(panel->texLs, panel->textureIndex[4]);
titem = (TextureListItem*)item->clientData;
pix = renderTexture(scr, titem->prop, 100, 18, NULL, RBEV_RAISED2);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 100, 20, 20, 115);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 100, 20, 20, 115+18);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 100, 20, 20, 115+36);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 100, 18, 20, 115);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 100, 18, 20, 115 + 18);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 100, 18, 20, 115 + 36);
XFreePixmap(dpy, pix);
}
if (elements & (MITEM|MTITLE)) {
XDrawLine(dpy, panel->preview, gc, 19, 95, 19, 115+36+20);
XDrawLine(dpy, panel->preview, gc, 19, 94, 119, 94);
}
if (elements & ICON) {
item = WMGetListItem(panel->texLs, 5);
item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
titem = (TextureListItem*)item->clientData;
pix = renderTexture(scr, titem->prop, 64, 64, NULL, RBEV_RAISED3);
pix = renderTexture(scr, titem->prop, 64, 64, NULL,
titem->ispixmap ? 0 : RBEV_RAISED3);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 64, 64, 130, 100);
XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 64, 64, 150, 90);
XFreePixmap(dpy, pix);
}
@@ -449,7 +534,7 @@ updatePreviewBox(_Panel *panel, int elements)
if (refresh < 0) {
WMPixmap *p;
p = WMCreatePixmapFromXPixmaps(scr, panel->preview, None,
220-4, 185-4, WMScreenDepth(scr));
260-4, 165-4, WMScreenDepth(scr));
WMSetLabelImage(panel->prevL, p);
WMReleasePixmap(p);
@@ -475,23 +560,19 @@ cancelNewTexture(void *data)
static char*
makeFileName(char *prefix, char *name)
makeFileName(char *prefix)
{
char *fname, *str;
int i;
char *fname;
str = wstrappend(prefix, name);
fname = wstrdup(str);
fname = wstrdup(prefix);
i = 1;
while (access(fname, F_OK)==0) {
char buf[16];
char buf[30];
free(fname);
sprintf(buf, "%i", i++);
fname = wstrappend(str, buf);
sprintf(buf, "%08lx.cache", time(NULL));
fname = wstrappend(prefix, buf);
}
free(str);
return fname;
}
@@ -526,7 +607,9 @@ okNewTexture(void *data)
titem->texture = str;
titem->selectedFor = 0;
titem->path = makeFileName(panel->fprefix, name);
titem->ispixmap = isPixmap(prop);
titem->path = makeFileName(panel->fprefix);
titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT,
titem->path, 0);
@@ -537,7 +620,6 @@ okNewTexture(void *data)
}
static void
okEditTexture(void *data)
{
@@ -567,12 +649,14 @@ okEditTexture(void *data)
PLRelease(titem->prop);
titem->prop = prop;
titem->ispixmap = isPixmap(prop);
free(titem->texture);
titem->texture = str;
XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
TEXPREV_WIDTH, TEXPREV_HEIGHT,
TEXPREV_WIDTH, TEXPREV_HEIGHT,
titem->path, 0);
WMRedisplayWidget(panel->texLs);
@@ -593,13 +677,14 @@ editTexture(WMWidget *w, void *data)
item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
titem = (TextureListItem*)item->clientData;
SetTexturePanelPixmapPath(panel->texturePanel,
GetObjectForKey("PixmapPath"));
SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
SetTexturePanelPixmapPath(panel->texturePanel,
GetObjectForKey("PixmapPath"));
ShowTexturePanel(panel->texturePanel);
}
@@ -610,14 +695,15 @@ newTexture(WMWidget *w, void *data)
{
_Panel *panel = (_Panel*)data;
SetTexturePanelPixmapPath(panel->texturePanel,
GetObjectForKey("PixmapPath"));
SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
SetTexturePanelPixmapPath(panel->texturePanel,
GetObjectForKey("PixmapPath"));
ShowTexturePanel(panel->texturePanel);
}
@@ -681,7 +767,6 @@ extractTexture(WMWidget *w, void *data)
_("Select File"), NULL)) {
path = WMGetFilePanelFileName(opanel);
puts(path);
OpenExtractPanelFor(panel, path);
free(path);
@@ -775,6 +860,8 @@ textureDoubleClick(WMWidget *w, void *data)
sprintf(str, "%s: %s", titem->title, titem->texture);
WMSetLabelText(panel->texsL, str);
free(str);
updatePreviewBox(panel, 1<<section);
}
@@ -887,7 +974,6 @@ fillTextureList(WMList *lPtr)
titem->selectedFor = 0;
titem->path = wstrdup(PLGetString(PLGetArrayElement(texture, 2)));
puts(titem->path);
titem->preview = loadRImage(scr, titem->path);
if (!titem->preview) {
titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH,
@@ -944,6 +1030,7 @@ createPanel(Panel *p)
panel->prevL = WMCreateLabel(panel->frame);
WMResizeWidget(panel->prevL, 260, 165);
WMMoveWidget(panel->prevL, 15, 10);
WMSetLabelRelief(panel->prevL, WRSunken);
WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
panel->secP = WMCreatePopUpButton(panel->frame);
@@ -1078,6 +1165,8 @@ setupTextureFor(WMList *list, char *key, char *defValue, char *title,
titem->texture = PLGetDescription((proplist_t)titem->prop);
titem->current = 1;
titem->selectedFor = 1<<index;
titem->ispixmap = isPixmap(titem->prop);
titem->preview = renderTexture(WMWidgetScreen(list), titem->prop,
TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
@@ -1128,6 +1217,38 @@ showData(_Panel *panel)
static void
storeData(_Panel *panel)
{
TextureListItem *titem;
WMListItem *item;
item = WMGetListItem(panel->texLs, panel->textureIndex[0]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "FTitleBack");
item = WMGetListItem(panel->texLs, panel->textureIndex[1]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "UTitleBack");
item = WMGetListItem(panel->texLs, panel->textureIndex[2]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "PTitleBack");
item = WMGetListItem(panel->texLs, panel->textureIndex[3]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "MenuTitleBack");
item = WMGetListItem(panel->texLs, panel->textureIndex[4]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "MenuTextBack");
item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "IconBack");
}
static void
prepareForClose(_Panel *panel)
{
proplist_t textureList;
proplist_t texture;
@@ -1154,30 +1275,7 @@ storeData(_Panel *panel)
WMSetUDObjectForKey(udb, textureList, "TextureList");
PLRelease(textureList);
item = WMGetListItem(panel->texLs, panel->textureIndex[0]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "FTitleBack");
item = WMGetListItem(panel->texLs, panel->textureIndex[1]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "UTitleBack");
item = WMGetListItem(panel->texLs, panel->textureIndex[2]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "PTitleBack");
item = WMGetListItem(panel->texLs, panel->textureIndex[3]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "MenuTitleBack");
item = WMGetListItem(panel->texLs, panel->textureIndex[4]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "MenuTextBack");
item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
titem = (TextureListItem*)item->clientData;
SetObjectForKey(titem->prop, "IconBack");
WMSynchronizeUserDefaults(udb);
}
@@ -1196,6 +1294,7 @@ InitAppearance(WMScreen *scr, WMWindow *win)
panel->callbacks.createWidgets = createPanel;
panel->callbacks.updateDomain = storeData;
panel->callbacks.prepareForClose = prepareForClose;
AddSection(panel, ICON_FILE);

View File

@@ -31,7 +31,7 @@ typedef struct _Panel {
WMWindow *win;
WMButton *swi[4];
WMButton *swi[5];
} _Panel;
@@ -45,10 +45,11 @@ showData(_Panel *panel)
{
WMUserDefaults *udb = WMGetStandardUserDefaults();
WMSetButtonSelected(panel->swi[0], WMGetUDBoolForKey(udb, "NoXSetStuff"));
WMSetButtonSelected(panel->swi[1], GetBoolForKey("SaveSessionOnExit"));
WMSetButtonSelected(panel->swi[2], GetBoolForKey("UseSaveUnders"));
WMSetButtonSelected(panel->swi[3], GetBoolForKey("DisableBlinking"));
WMSetButtonSelected(panel->swi[0], GetBoolForKey("DisableMiniwindows"));
WMSetButtonSelected(panel->swi[1], WMGetUDBoolForKey(udb, "NoXSetStuff"));
WMSetButtonSelected(panel->swi[2], GetBoolForKey("SaveSessionOnExit"));
WMSetButtonSelected(panel->swi[3], GetBoolForKey("UseSaveUnders"));
WMSetButtonSelected(panel->swi[4], GetBoolForKey("DisableBlinking"));
}
@@ -62,15 +63,17 @@ createPanel(Panel *p)
WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
for (i=0; i<4; i++) {
for (i=0; i<5; i++) {
panel->swi[i] = WMCreateSwitchButton(panel->frame);
WMResizeWidget(panel->swi[i], FRAME_WIDTH-40, 25);
WMMoveWidget(panel->swi[i], 20, 20+i*25);
}
WMSetButtonText(panel->swi[0], _("Do not set non-WindowMaker specific parameters (do not use xset)"));
WMSetButtonText(panel->swi[1], _("Automatically save session when exiting WindowMaker"));
WMSetButtonText(panel->swi[2], _("Use SaveUnder in window frames, icons, menus and other objects"));
WMSetButtonText(panel->swi[3], _("Disable cycling color highlighting of icons."));
WMSetButtonText(panel->swi[0], _("Disable miniwindows (icons for miniaturized windows). For use with KDE/GNOME."));
WMSetButtonText(panel->swi[1], _("Do not set non-WindowMaker specific parameters (do not use xset)"));
WMSetButtonText(panel->swi[2], _("Automatically save session when exiting WindowMaker"));
WMSetButtonText(panel->swi[3], _("Use SaveUnder in window frames, icons, menus and other objects"));
WMSetButtonText(panel->swi[4], _("Disable cycling color highlighting of icons."));
WMRealizeWidget(panel->frame);
WMMapSubwidgets(panel->frame);
@@ -84,11 +87,13 @@ storeDefaults(_Panel *panel)
{
WMUserDefaults *udb = WMGetStandardUserDefaults();
WMSetUDBoolForKey(udb, WMGetButtonSelected(panel->swi[0]), "NoXSetStuff");
SetBoolForKey(WMGetButtonSelected(panel->swi[0]), "DisableMiniwindows");
SetBoolForKey(WMGetButtonSelected(panel->swi[1]), "SaveSessionOnExit");
SetBoolForKey(WMGetButtonSelected(panel->swi[2]), "UseSaveUnders");
SetBoolForKey(WMGetButtonSelected(panel->swi[3]), "DisableBlinking");
WMSetUDBoolForKey(udb, WMGetButtonSelected(panel->swi[1]), "NoXSetStuff");
SetBoolForKey(WMGetButtonSelected(panel->swi[2]), "SaveSessionOnExit");
SetBoolForKey(WMGetButtonSelected(panel->swi[3]), "UseSaveUnders");
SetBoolForKey(WMGetButtonSelected(panel->swi[4]), "DisableBlinking");
}

View File

@@ -208,6 +208,9 @@ updateTGradImage(TexturePanel *panel)
RColor to;
WMColor *color;
if (!panel->image)
return;
color = WMGetColorWellColor(panel->tcol1W);
from.red = WMRedComponentOfColor(color)>>8;
from.green = WMGreenComponentOfColor(color)>>8;
@@ -218,13 +221,32 @@ updateTGradImage(TexturePanel *panel)
to.green = WMGreenComponentOfColor(color)>>8;
to.blue = WMBlueComponentOfColor(color)>>8;
if (WMGetButtonSelected(panel->dirhB)) {
gradient = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
} else if (WMGetButtonSelected(panel->dirvB)) {
gradient = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
if (panel->image->width < 141 || panel->image->height < 91) {
image = RMakeTiledImage(panel->image, 141, 91);
} else {
gradient = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
image = RCloneImage(panel->image);
}
if (WMGetButtonSelected(panel->dirhB)) {
gradient = RRenderGradient(image->width, image->height, &from, &to,
RHorizontalGradient);
} else if (WMGetButtonSelected(panel->dirvB)) {
gradient = RRenderGradient(image->width, image->height, &from, &to,
RVerticalGradient);
} else {
gradient = RRenderGradient(image->width, image->height, &from, &to,
RDiagonalGradient);
}
RCombineImagesWithOpaqueness(image, gradient,
WMGetSliderValue(panel->topaS));
RDestroyImage(gradient);
pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->win),
image, 128);
WMSetLabelImage(panel->imageL, pixmap);
WMResizeWidget(panel->imageL, image->width, image->height);
RDestroyImage(image);
}
@@ -270,43 +292,6 @@ updateSGradButtons(TexturePanel *panel)
}
static void
changeTypeCallback(WMWidget *w, void *data)
{
TexturePanel *panel = (TexturePanel*)data;
int newType;
int i;
newType = WMGetPopUpButtonSelectedItem(w);
if (newType == panel->currentType)
return;
if (panel->currentType >= 0) {
for (i = 0; i < MAX_SECTION_PARTS; i++) {
if (panel->sectionParts[panel->currentType][i] == NULL)
break;
WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
}
}
for (i = 0; i < MAX_SECTION_PARTS; i++) {
if (panel->sectionParts[newType][i] == NULL)
break;
WMMapWidget(panel->sectionParts[newType][i]);
}
panel->currentType = newType;
switch (newType) {
case TYPE_SGRADIENT:
updateSGradButtons(panel);
break;
case TYPE_GRADIENT:
updateGradButtons(panel);
break;
}
}
/*********** Gradient ************/
static void
@@ -587,27 +572,88 @@ colorWellObserver(void *self, WMNotification *n)
}
static void
opaqChangeCallback(WMWidget *w, void *data)
{
TexturePanel *panel = (TexturePanel*)data;
updateTGradImage(panel);
}
/****************** Image ******************/
static void
updateImage(TexturePanel *panel, char *path)
{
WMScreen *scr = WMWidgetScreen(panel->win);
RImage *image, *scaled;
WMPixmap *pixmap;
WMSize size;
if (path) {
image = RLoadImage(WMScreenRContext(scr), path, 0);
if (!image) {
char *message;
message = wstrappend(_("Could not load the selected file: "),
(char*)RMessageForError(RErrorCode));
WMRunAlertPanel(scr, panel->win, _("Error"), message,
_("OK"), NULL, NULL);
return;
}
if (panel->image)
RDestroyImage(panel->image);
panel->image = image;
} else {
image = panel->image;
}
if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
pixmap = WMCreatePixmapFromRImage(scr, image, 128);
size = WMGetPixmapSize(pixmap);
WMSetLabelImage(panel->imageL, pixmap);
WMResizeWidget(panel->imageL, size.width, size.height);
WMReleasePixmap(pixmap);
} else {
updateTGradImage(panel);
}
}
static void
browseImageCallback(WMWidget *w, void *data)
{
TexturePanel *panel = (TexturePanel*)data;
WMOpenPanel *opanel;
WMScreen *scr = WMWidgetScreen(w);
static char *ipath = NULL;
opanel = WMGetOpenPanel(scr);
WMSetFilePanelCanChooseDirectories(opanel, False);
WMSetFilePanelCanChooseFiles(opanel, True);
if (WMRunModalFilePanelForDirectory(opanel, panel->win, wgethomedir(),
if (!ipath)
ipath = wstrdup(wgethomedir());
if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
"Open Image", NULL)) {
char *path, *fullpath;
char *tmp, *tmp2;
fullpath = WMGetFilePanelFileName(opanel);
if (!fullpath)
tmp = WMGetFilePanelFileName(opanel);
if (!tmp)
return;
fullpath = tmp;
free(ipath);
ipath = fullpath;
path = wstrdup(fullpath);
tmp2 = strrchr(fullpath, '/');
@@ -629,47 +675,12 @@ browseImageCallback(WMWidget *w, void *data)
_("The selected file does not contain a supported image."),
_("OK"), NULL, NULL);
free(path);
free(fullpath);
} else {
RImage *image, *scaled;
WMPixmap *pixmap;
WMSize size;
image = RLoadImage(WMScreenRContext(scr), fullpath, 0);
if (!image) {
char *message;
message = wstrappend(_("Could not load the selected file: "),
(char*)RMessageForError(RErrorCode));
WMRunAlertPanel(scr, panel->win, _("Error"), message,
_("OK"), NULL, NULL);
free(message);
free(path);
free(fullpath);
return;
}
if (panel->image)
RDestroyImage(panel->image);
panel->image = image;
if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
pixmap = WMCreatePixmapFromRImage(scr, image, 128);
size = WMGetPixmapSize(pixmap);
WMSetLabelImage(panel->imageL, pixmap);
WMResizeWidget(panel->imageL, size.width, size.height);
WMReleasePixmap(pixmap);
} else {
updateTGradImage(panel);
}
updateImage(panel, fullpath);
free(panel->imageFile);
panel->imageFile = path;
WMSetTextFieldText(panel->imageT, path);
free(fullpath);
}
}
}
@@ -689,6 +700,48 @@ buttonCallback(WMWidget *w, void *data)
}
static void
changeTypeCallback(WMWidget *w, void *data)
{
TexturePanel *panel = (TexturePanel*)data;
int newType;
int i;
newType = WMGetPopUpButtonSelectedItem(w);
if (newType == panel->currentType)
return;
if (panel->currentType >= 0) {
for (i = 0; i < MAX_SECTION_PARTS; i++) {
if (panel->sectionParts[panel->currentType][i] == NULL)
break;
WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
}
}
for (i = 0; i < MAX_SECTION_PARTS; i++) {
if (panel->sectionParts[newType][i] == NULL)
break;
WMMapWidget(panel->sectionParts[newType][i]);
}
panel->currentType = newType;
switch (newType) {
case TYPE_SGRADIENT:
updateSGradButtons(panel);
break;
case TYPE_GRADIENT:
updateGradButtons(panel);
break;
case TYPE_TGRADIENT:
case TYPE_PIXMAP:
updateImage(panel, NULL);
break;
}
}
/*
*--------------------------------------------------------------------------
* Public functions
@@ -705,10 +758,11 @@ void
ShowTexturePanel(TexturePanel *panel)
{
Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
Screen *scr = DefaultScreenOfDisplay(dpy);
WMSetWindowUPosition(panel->win,
WidthOfScreen(DefaultScreenOfDisplay(dpy))/2,
HeightOfScreen(DefaultScreenOfDisplay(dpy))/2);
(WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
(HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
WMMapWidget(panel->win);
}
@@ -818,6 +872,10 @@ SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
WMSetTextFieldText(panel->imageT,
PLGetString(PLGetArrayElement(texture, 1)));
if (panel->imageFile)
free(panel->imageFile);
panel->imageFile = wstrdup(PLGetString(PLGetArrayElement(texture, 1)));
i = 180;
sscanf(PLGetString(PLGetArrayElement(texture, 2)), "%i", &i);
@@ -847,6 +905,19 @@ SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
WMReleaseColor(color);
WMSetTextFieldText(panel->imageT,
PLGetString(PLGetArrayElement(texture, 1)));
if (panel->imageFile)
free(panel->imageFile);
panel->imageFile = wfindfileinarray(panel->pathList,
PLGetString(PLGetArrayElement(texture, 1)));
panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
updateTGradImage(panel);
updateSGradButtons(panel);
/*...............................................*/
} else if (strcasecmp(type, "mhgradient")==0
|| strcasecmp(type, "mvgradient")==0
@@ -926,6 +997,18 @@ SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
WMSetTextFieldText(panel->imageT,
PLGetString(PLGetArrayElement(texture, 1)));
if (panel->imageFile)
free(panel->imageFile);
panel->imageFile = wfindfileinarray(panel->pathList,
PLGetString(PLGetArrayElement(texture, 1)));
color = WMCreateNamedColor(scr,
PLGetString(PLGetArrayElement(texture, 2)), False);
WMSetColorWellColor(panel->defcW, color);
WMReleaseColor(color);
updateImage(panel, panel->imageFile);
}
changeTypeCallback(panel->typeP, panel);
@@ -1009,7 +1092,7 @@ GetTexturePanelTexture(TexturePanel *panel)
PLMakeString(str), NULL);
break;
case PTYPE_TILE:
prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
PLMakeString(panel->imageFile),
PLMakeString(str), NULL);
break;
@@ -1017,6 +1100,39 @@ GetTexturePanelTexture(TexturePanel *panel)
free(str);
break;
case TYPE_TGRADIENT:
color = WMGetColorWellColor(panel->tcol1W);
str = WMGetColorRGBDescription(color);
color = WMGetColorWellColor(panel->tcol2W);
str2 = WMGetColorRGBDescription(color);
sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
if (WMGetButtonSelected(panel->dirdB)) {
prop = PLMakeArrayFromElements(PLMakeString("tdgradient"),
PLMakeString(panel->imageFile),
PLMakeString(buff),
PLMakeString(str),
PLMakeString(str2), NULL);
} else if (WMGetButtonSelected(panel->dirvB)) {
prop = PLMakeArrayFromElements(PLMakeString("tvgradient"),
PLMakeString(panel->imageFile),
PLMakeString(buff),
PLMakeString(str),
PLMakeString(str2), NULL);
} else {
prop = PLMakeArrayFromElements(PLMakeString("thgradient"),
PLMakeString(panel->imageFile),
PLMakeString(buff),
PLMakeString(str),
PLMakeString(str2), NULL);
}
free(str);
free(str2);
break;
case TYPE_SGRADIENT:
color = WMGetColorWellColor(panel->tcol1W);
str = WMGetColorRGBDescription(color);
@@ -1110,6 +1226,7 @@ CreateTexturePanel(WMWindow *keyWindow)
WMResizeWidget(panel->win, 325, 423);
WMSetWindowTitle(panel->win, _("Texture Panel"));
WMSetWindowCloseAction(panel->win, buttonCallback, panel);
/* texture name */
@@ -1301,6 +1418,9 @@ CreateTexturePanel(WMWindow *keyWindow)
WMMoveWidget(panel->topaS, 15, 20);
WMSetSliderMaxValue(panel->topaS, 255);
WMSetSliderValue(panel->topaS, 200);
WMSetSliderContinuous(panel->topaS, False);
WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
WMMapSubwidgets(panel->topaF);
{
@@ -1357,10 +1477,11 @@ CreateTexturePanel(WMWindow *keyWindow)
WMSetButtonText(panel->browB, _("Browse..."));
WMSetButtonAction(panel->browB, browseImageCallback, panel);
panel->dispB = WMCreateCommandButton(panel->imageF);
/* panel->dispB = WMCreateCommandButton(panel->imageF);
WMResizeWidget(panel->dispB, 90, 24);
WMMoveWidget(panel->dispB, 190, 80);
WMSetButtonText(panel->dispB, _("Show"));
*/
panel->arrP = WMCreatePopUpButton(panel->imageF);
WMResizeWidget(panel->arrP, 90, 20);

View File

@@ -106,10 +106,13 @@ static void loadConfigurations(WMScreen *scr, WMWindow *mainw);
static void savePanelData(Panel *panel);
static void prepareForClose();
void
quit(WMWidget *w, void *data)
{
prepareForClose();
exit(0);
}
@@ -157,6 +160,7 @@ save(WMWidget *w, void *data)
}
static void
undo(WMWidget *w, void *data)
{
@@ -187,6 +191,23 @@ undoAll(WMWidget *w, void *data)
}
static void
prepareForClose()
{
int i;
for (i=0; i<WPrefs.sectionCount; i++) {
PanelRec *rec = WMGetHangedData(WPrefs.sectionB[i]);
if (rec->callbacks.prepareForClose
&& (rec->callbacks.flags & INITIALIZED_PANEL))
(*rec->callbacks.prepareForClose)((Panel*)rec);
}
}
static void
createMainWindow(WMScreen *scr)
{

View File

@@ -55,6 +55,7 @@ typedef struct {
void (*updateDomain)(Panel*); /* save the changes to the dictionary */
Bool (*requiresRestart)(Panel*); /* return True if some static option was changed */
void (*undoChanges)(Panel*); /* reset values to those in the dictionary */
void (*prepareForClose)(Panel*); /* called when exiting WPrefs */
} CallbackRec;