home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Linux
/
Enlightenment
/
enl14.tgz
/
enl14.tar
/
enl14
/
buttons.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-11-21
|
31KB
|
1,283 lines
#include "enl.h"
void FreeStrip(Strip *item)
{
int i;
if (item->name) Efree(item->name);
if (item->strip) DelStripFromStrip(item,item->strip);
if (item->list)
{
for(i=0;i<item->num;i++)
{
if (item->list[i].item)
{
if (item->list[i].type==LIST_TYPE_BUTTON)
{
DelItem(((Button *)(item->list[i].item))->name,
LIST_TYPE_BUTTON);
FreeButton((Button *)item->list[i].item);
}
else if (item->list[i].type==LIST_TYPE_STRIP)
{
DelItem(((Strip *)(item->list[i].item))->name,
LIST_TYPE_STRIP);
FreeStrip((Strip *)item->list[i].item);
}
}
}
Efree(item->list);
}
Efree(item);
}
Strip *CfgReadStrip()
{
Strip *s;
char st[256],*w;
s=Emalloc(sizeof(Strip));
if (!s) return NULL;
s->loc.handle_macro=COORD_MACRO_TOPLEFT;
s->loc.from_macro=COORD_MACRO_TOPLEFT;
s->loc.x_handle=0;
s->loc.y_handle=0;
s->loc.x_handle_at=0;
s->loc.y_handle_at=0;
s->loc.x_from=0;
s->loc.y_from=0;
s->loc.x_from_at=0;
s->loc.x_from_at=0;
s->loc.x=0;
s->loc.y=0;
s->name=NULL;
s->orientation=STRIP_ORIENTATION_VERTICAL;
s->justification=0;
s->strip=NULL;
s->strip_loc=STRIP_LOCATION_END;
s->num=0;
s->list=NULL;
s->X.x=0;
s->X.y=0;
s->X.width=0;
s->X.height=0;
while (CfgGetLine(NULL))
{
word(line,1,st);
if (!strcmp(st,"name"))
{
word(line,2,st);s->name=duplicate(st);
}
else if (!strcmp(st,"orientation"))
{
word(line,2,st);
if (!strcmp(st,"vertical"))
s->orientation=STRIP_ORIENTATION_VERTICAL;
else
s->orientation=STRIP_ORIENTATION_HORIZONTAL;
}
else if (!strcmp(st,"location"))
{
CfgParseLocLine(line,&s->loc);
}
else if (!strcmp(st,"strip"))
{
word(line,2,st);s->strip=(Strip *)FindItem(st,LIST_TYPE_STRIP);
word(line,3,st);
if (!strcmp(st,"end"))
s->strip_loc=STRIP_LOCATION_END;
else if (!strcmp(st,"start"))
s->strip_loc=STRIP_LOCATION_START;
AddStripToStrip(s,s->strip,s->strip_loc);
}
else if (!strcmp(st,"justification"))
{
word(line,2,st);
w=atchar(st,'%');
if (w) *w=0;
s->justification=atoi(st);
}
else if (!strcmp(st,"end"))
{
return s;
}
}
if (s->name) Efree(s->name);
Efree(s);
return NULL;
}
void CfgLoadStrip()
{
Strip *s;
s=CfgReadStrip();
if (s) AddItem((void *)s,s->name,LIST_TYPE_STRIP);
}
void FreeButton(Button *item)
{
Strip *s;
if (!item) return;
if (item->name) Efree(item->name);
if (item->strip)
{
s=item->strip;
DelButtonFromStrip(item,s);
DrawStrip(s);
}
if (item->actions) Efree(item->actions);
if (item->X.pmap) ImlibFreePixmap(imd,item->X.pmap);
if (item->X.mask) ImlibFreePixmap(imd,item->X.mask);
if (item->X.win) XDestroyWindow(disp,item->X.win);
Efree(item);
}
Button *MakeButton(char *name, char *iclass, int x, int y, int width, int height)
{
Button *b;
int mask;
XSetWindowAttributes att;
if (!name) return NULL;
if (!iclass) return NULL;
b=Emalloc(sizeof(Button));
if (!b) return NULL;
b->loc.handle_macro=COORD_MACRO_TOPLEFT;
b->loc.from_macro=COORD_MACRO_TOPLEFT;
b->loc.x_handle=0;
b->loc.y_handle=0;
b->loc.x_handle_at=0;
b->loc.y_handle_at=0;
b->loc.x_from=0;
b->loc.y_from=0;
b->loc.x_from_at=0;
b->loc.x_from_at=0;
b->loc.x=x;
b->loc.y=y;
b->width.min=0;
b->width.max=0;
b->height.min=0;
b->height.max=0;
b->name=duplicate(name);
b->iclass=(ImageClass *)FindItem(iclass,LIST_TYPE_IMAGECLASS);
b->pstate=-1;
b->state=STATE_NORMAL;
b->strip=NULL;
b->strip_loc=STRIP_LOCATION_END;
b->num=0;
b->actions=NULL;
b->pX.x=-1;
b->pX.y=-1;
b->pX.width=-1;
b->pX.height=-1;
b->pX.pmap=0;
b->pX.mask=0;
b->X.x=10;
b->X.y=10;
b->X.width=20;
b->X.height=20;
b->X.pmap=0;
b->X.mask=0;
b->size.x=width;b->size.x_at=0;
b->size.y=height;b->size.y_at=0;
if (!width)
b->size.x=b->iclass->normal->im->rgb_width;
if (!height)
b->size.y=b->iclass->normal->im->rgb_height;
att.backing_store=NotUseful;/* NotUseful WhenMapped Always */
att.save_under=False;
att.override_redirect=True;
mask=CWOverrideRedirect|CWSaveUnder|CWBackingStore;
b->X.win=XCreateWindow(disp,DefaultRootWindow(disp),-10,-10,5,5,0,
imd->x.depth,InputOutput,imd->x.visual,mask,&att);
XSelectInput(disp,b->X.win,ButtonPressMask|ButtonReleaseMask|EnterWindowMask
|LeaveWindowMask|ButtonMotionMask|KeyPressMask|KeyReleaseMask);
AddItem((void *)b,b->name,LIST_TYPE_BUTTON);
CalcButton(b);
DrawButton(b);
return b;
}
Button *CfgReadButton()
{
Button *b;
int mask;
XSetWindowAttributes att;
char s[1024];
b=Emalloc(sizeof(Button));
if (!b) return NULL;
b->loc.handle_macro=COORD_MACRO_TOPLEFT;
b->loc.from_macro=COORD_MACRO_TOPLEFT;
b->loc.x_handle=0;
b->loc.y_handle=0;
b->loc.x_handle_at=0;
b->loc.y_handle_at=0;
b->loc.x_from=0;
b->loc.y_from=0;
b->loc.x_from_at=0;
b->loc.x_from_at=0;
b->loc.x=0;
b->loc.y=0;
b->width.min=0;
b->width.max=0;
b->height.min=0;
b->height.max=0;
b->name=NULL;
b->iclass=NULL;
b->pstate=-1;
b->state=STATE_NORMAL;
b->strip=NULL;
b->strip_loc=STRIP_LOCATION_END;
b->num=0;
b->actions=NULL;
b->pX.x=-1;
b->pX.y=-1;
b->pX.width=-1;
b->pX.height=-1;
b->pX.pmap=0;
b->pX.mask=0;
b->X.x=10;
b->X.y=10;
b->X.width=20;
b->X.height=20;
b->X.pmap=0;
b->X.mask=0;
b->size.x=0;b->size.x_at=0;
b->size.y=0;b->size.y_at=0;
att.backing_store=NotUseful;/* NotUseful WhenMapped Always */
att.save_under=False;
att.override_redirect=True;
mask=CWOverrideRedirect|CWSaveUnder|CWBackingStore;
b->X.win=XCreateWindow(disp,DefaultRootWindow(disp),-10,-10,5,5,0,
imd->x.depth,InputOutput,imd->x.visual,mask,&att);
XSelectInput(disp,b->X.win,ButtonPressMask|ButtonReleaseMask|EnterWindowMask
|LeaveWindowMask|ButtonMotionMask|KeyPressMask|KeyReleaseMask);
while(CfgGetLine(NULL))
{
word(line,1,s);
if (!strcmp(s,"name"))
{
word(line,2,s);
b->name=duplicate(s);
}
else if (!strcmp(s,"image_class"))
{
word(line,2,s);
b->iclass=(ImageClass *)FindItem(s,LIST_TYPE_IMAGECLASS);
b->X.width=b->iclass->normal->im->rgb_width;
b->X.height=b->iclass->normal->im->rgb_height;
}
else if (!strcmp(s,"begin"))
{
word(line,2,s);
if (!strcmp(s,"geometry"))
CfgReadGeometry(b);
if (!strcmp(s,"actions"))
CfgReadActions(&b->actions,&b->num);
}
else if (!strcmp(s,"end"))
{
return b;
}
}
if (b->name) Efree(b->name);
if (b->strip) DelButtonFromStrip(b,b->strip);
Efree(b);
return NULL;
}
void CfgLoadButton()
{
Button *b;
b=CfgReadButton();
if (b) AddItem((void *)b,b->name,LIST_TYPE_BUTTON);
}
void CfgReadGeometry(Button *b)
{
char s[256];
while (CfgGetLine(NULL))
{
word(line,1,s);
if (!strcmp(s,"size"))
CfgParseSizeLine(line,&b->size);
else if (!strcmp(s,"location"))
CfgParseLocLine(line,&b->loc);
else if (!strcmp(s,"strip"))
{
word(line,2,s);b->strip=(Strip *)FindItem(s,LIST_TYPE_STRIP);
word(line,3,s);
if (!strcmp(s,"end"))
b->strip_loc=STRIP_LOCATION_END;
else if (!strcmp(s,"start"))
b->strip_loc=STRIP_LOCATION_START;
AddButtonToStrip(b,b->strip,b->strip_loc);
}
else if (!strcmp(s,"constrain"))
{
word(line,2,s);
if (!strcmp(s,"width"))
CfgParseConstrain(line,&b->width);
else if (!strcmp(s,"height"))
CfgParseConstrain(line,&b->height);
}
else if (!strcmp(s,"end"))
{
return;
}
}
}
void CfgReadActions(ActionInit **a, int *num)
{
char s[256];
int n;
ActionInit *aa;
n=0;
*a=NULL;
while (CfgGetLine(NULL))
{
word(line,1,s);
if (!strcmp(s,"mouse"))
{
n++;
*a=Erealloc(*a,n*sizeof(ActionInit));
aa=*a;
CfgParseMouseAction(line,&aa[n-1]);
}
else if (!strcmp(s,"key"))
{
n++;
*a=Erealloc(*a,n*sizeof(ActionInit));
aa=*a;
CfgParseKeyAction(line,&aa[n-1]);
}
else if (!strcmp(s,"end"))
{
*num=n;
return;
}
}
}
void AddButtonAction(Button *b, char *line)
{
ActionInit *aa;
char s[256];
if (!b) return;
if (!line) return;
word(line,1,s);
if (!strcmp(s,"mouse"))
{
b->num++;
b->actions=Erealloc(b->actions,b->num*sizeof(ActionInit));
aa=b->actions;
CfgParseMouseAction(line,&aa[b->num-1]);
}
else if (!strcmp(s,"key"))
{
b->num++;
b->actions=Erealloc(b->actions,b->num*sizeof(ActionInit));
aa=b->actions;
CfgParseKeyAction(line,&aa[b->num-1]);
}
}
void AddButtonActionCallback(Button *b, char *line, void (*cb)())
{
ActionInit *aa;
char s[256];
void (**ptr)();
if (!b) return;
if (!line) return;
word(line,1,s);
aa=NULL;
if (!strcmp(s,"mouse"))
{
b->num++;
b->actions=Erealloc(b->actions,b->num*sizeof(ActionInit));
aa=b->actions;
CfgParseMouseAction(line,&aa[b->num-1]);
}
else if (!strcmp(s,"key"))
{
b->num++;
b->actions=Erealloc(b->actions,b->num*sizeof(ActionInit));
aa=b->actions;
CfgParseKeyAction(line,&aa[b->num-1]);
}
if (aa)
{
aa[b->num-1].action.id=ACTION_CALLBACK;
aa[b->num-1].action.params=(char *)malloc(sizeof(void (*)()));
ptr=((void (**)())aa[b->num-1].action.params);
*ptr=cb;
}
}
void CfgParseMouseAction(char *lin, ActionInit *a)
{
char s[256],ss[256],*w;
int cnt,i;
a->event=0;
a->any=0;
a->anykey=0;
a->modifiers=0;
a->button=0;
a->key=0;
a->action.id=0;
a->action.params=NULL;
word(lin,2,s);
if (!strcmp(s,"down")) a->event=EVENT_MOUSE_DOWN;
else if (!strcmp(s,"up")) a->event=EVENT_MOUSE_UP;
else if (!strcmp(s,"enter")) a->event=EVENT_MOUSE_ENTER;
else if (!strcmp(s,"leave")) a->event=EVENT_MOUSE_LEAVE;
word(lin,3,s);
cnt=1;
while ((w=atchar(s,'+'))!=NULL)
{
*w=' ';cnt++;
}
for(i=0;i<cnt;i++)
{
word(s,i+1,ss);
if (!strcmp(ss,"shift")) a->modifiers|=ShiftMask;
else if (!strcmp(ss,"lock")) a->modifiers|=LockMask;
else if (!strcmp(ss,"ctrl")) a->modifiers|=ControlMask;
else if (!strcmp(ss,"alt")) a->modifiers|=Mod1Mask;
else if (!strcmp(ss,"meta1")) a->modifiers|=Mod1Mask;
else if (!strcmp(ss,"meta2")) a->modifiers|=Mod2Mask;
else if (!strcmp(ss,"meta3")) a->modifiers|=Mod3Mask;
else if (!strcmp(ss,"meta4")) a->modifiers|=Mod4Mask;
else if (!strcmp(ss,"meta5")) a->modifiers|=Mod5Mask;
else if (!strcmp(ss,"any")) a->any=1;
}
word(lin,4,s);
if (!strcmp(s,"any")) a->button=0;
else a->button=atoi(s);
word(lin,5,s);
if (!strcmp(s,"exec")) a->action.id=ACTION_EXEC;
else if (!strcmp(s,"alert")) a->action.id=ACTION_ALERT;
else if (!strcmp(s,"rotate_strip")) a->action.id=ACTION_ROTATE_STRIP;
else if (!strcmp(s,"move_strip")) a->action.id=ACTION_MOVE_STRIP;
else if (!strcmp(s,"save_strip")) a->action.id=ACTION_SAVE_STRIP;
else if (!strcmp(s,"justify_strip")) a->action.id=ACTION_JUSTIFY_STRIP;
else if (!strcmp(s,"delete_strip")) a->action.id=ACTION_DELETE_STRIP;
else if (!strcmp(s,"show_strip")) a->action.id=ACTION_SHOW_STRIP;
else if (!strcmp(s,"hide_strip")) a->action.id=ACTION_HIDE_STRIP;
else if (!strcmp(s,"show_strip_toggle")) a->action.id=ACTION_SHOW_STRIP_TOGGLE;
else if (!strcmp(s,"disable_button")) a->action.id=ACTION_DISABLE_BUTTON;
else if (!strcmp(s,"enable_button")) a->action.id=ACTION_ENABLE_BUTTON;
else if (!strcmp(s,"disable_button_toggle")) a->action.id=ACTION_DISABLE_BUTTON_TOGGLE;
else if (!strcmp(s,"move_button")) a->action.id=ACTION_MOVE_BUTTON;
else if (!strcmp(s,"save_button")) a->action.id=ACTION_SAVE_BUTTON;
else if (!strcmp(s,"show_button")) a->action.id=ACTION_SHOW_BUTTON;
else if (!strcmp(s,"hide_button")) a->action.id=ACTION_HIDE_BUTTON;
else if (!strcmp(s,"delete_button")) a->action.id=ACTION_DELETE_BUTTON;
else if (!strcmp(s,"show_button_toggle")) a->action.id=ACTION_SHOW_BUTTON_TOGGLE;
else if (!strcmp(s,"locate_button")) a->action.id=ACTION_LOCATE_BUTTON;
else if (!strcmp(s,"flip_strip")) a->action.id=ACTION_FLIP_STRIP;
a->action.params=duplicate(atword(lin,6));
}
void CfgParseKeyAction(char *lin, ActionInit *a)
{
char s[256],ss[256],*w;
int cnt,i;
a->event=0;
a->any=0;
a->anykey=0;
a->modifiers=0;
a->button=0;
a->key=0;
a->action.id=0;
a->action.params=NULL;
word(lin,2,s);
if (!strcmp(s,"down")) a->event=EVENT_KEY_DOWN;
else if (!strcmp(s,"up")) a->event=EVENT_KEY_UP;
word(lin,3,s);
cnt=1;
while ((w=atchar(s,'+'))!=NULL)
{
*w=' ';cnt++;
}
for(i=0;i<cnt;i++)
{
word(s,i+1,ss);
if (!strcmp(ss,"shift")) a->modifiers|=ShiftMask;
else if (!strcmp(ss,"lock")) a->modifiers|=LockMask;
else if (!strcmp(ss,"ctrl")) a->modifiers|=ControlMask;
else if (!strcmp(ss,"alt")) a->modifiers|=Mod1Mask;
else if (!strcmp(ss,"meta1")) a->modifiers|=Mod1Mask;
else if (!strcmp(ss,"meta2")) a->modifiers|=Mod2Mask;
else if (!strcmp(ss,"meta3")) a->modifiers|=Mod3Mask;
else if (!strcmp(ss,"meta4")) a->modifiers|=Mod4Mask;
else if (!strcmp(ss,"meta5")) a->modifiers|=Mod5Mask;
else if (!strcmp(ss,"any")) a->any=1;
}
word(lin,4,s);
if (!strcmp(s,"any")) a->anykey=1;
else a->key=XKeysymToKeycode(disp,XStringToKeysym(s));
word(lin,5,s);
if (!strcmp(s,"exec")) a->action.id=ACTION_EXEC;
else if (!strcmp(s,"alert")) a->action.id=ACTION_ALERT;
else if (!strcmp(s,"rotate_strip")) a->action.id=ACTION_ROTATE_STRIP;
else if (!strcmp(s,"move_strip")) a->action.id=ACTION_MOVE_STRIP;
else if (!strcmp(s,"save_strip")) a->action.id=ACTION_SAVE_STRIP;
else if (!strcmp(s,"justify_strip")) a->action.id=ACTION_JUSTIFY_STRIP;
else if (!strcmp(s,"delete_strip")) a->action.id=ACTION_DELETE_STRIP;
else if (!strcmp(s,"show_strip")) a->action.id=ACTION_SHOW_STRIP;
else if (!strcmp(s,"hide_strip")) a->action.id=ACTION_HIDE_STRIP;
else if (!strcmp(s,"show_strip_toggle")) a->action.id=ACTION_SHOW_STRIP_TOGGLE;
else if (!strcmp(s,"disable_button")) a->action.id=ACTION_DISABLE_BUTTON;
else if (!strcmp(s,"enable_button")) a->action.id=ACTION_ENABLE_BUTTON;
else if (!strcmp(s,"disable_button_toggle")) a->action.id=ACTION_DISABLE_BUTTON_TOGGLE;
else if (!strcmp(s,"move_button")) a->action.id=ACTION_MOVE_BUTTON;
else if (!strcmp(s,"save_button")) a->action.id=ACTION_SAVE_BUTTON;
else if (!strcmp(s,"show_button")) a->action.id=ACTION_SHOW_BUTTON;
else if (!strcmp(s,"hide_button")) a->action.id=ACTION_HIDE_BUTTON;
else if (!strcmp(s,"delete_button")) a->action.id=ACTION_DELETE_BUTTON;
else if (!strcmp(s,"show_button_toggle")) a->action.id=ACTION_SHOW_BUTTON_TOGGLE;
else if (!strcmp(s,"locate_button")) a->action.id=ACTION_LOCATE_BUTTON;
else if (!strcmp(s,"flip_strip")) a->action.id=ACTION_FLIP_STRIP;
a->action.params=duplicate(atword(lin,6));
}
void AddButtonToStrip(Button *b, Strip *s, int loc)
{
int i;
if ((!b)||(!s)) return;
b->strip=s;
b->strip_loc=loc;
s->num++;
s->list=Erealloc(s->list,s->num*(sizeof(Item)));
if (loc==STRIP_LOCATION_END)
{
s->list[s->num-1].item=(void *)b;
s->list[s->num-1].type=LIST_TYPE_BUTTON;
}
else
{
for (i=s->num-1;i>0;i--)
{
s->list[i].type=s->list[i-1].type;
s->list[i].item=s->list[i-1].item;
}
s->list[0].item=(void *)b;
s->list[0].type=LIST_TYPE_BUTTON;
}
}
void DelButtonFromStrip(Button *b, Strip *s)
{
int i;
for(i=0;i<s->num;i++)
{
if ((s->list[i].item==(void *)b)&&(s->list[i].type==LIST_TYPE_BUTTON))
{
for(i++;i<s->num;i++)
{
s->list[i-1].type=s->list[i].type;
s->list[i-1].item=s->list[i].item;
}
}
}
s->num--;
s->list=Erealloc(s->list,s->num*(sizeof(Item)));
b->strip=NULL;
}
void AddStripToStrip(Strip *b, Strip *s, int loc)
{
int i;
if ((!b)||(!s)) return;
b->strip=s;
b->strip_loc=loc;
s->num++;
s->list=Erealloc(s->list,s->num*(sizeof(Item)));
if (loc==STRIP_LOCATION_END)
{
s->list[s->num-1].item=(void *)b;
s->list[s->num-1].type=LIST_TYPE_STRIP;
}
else
{
for (i=s->num-1;i>0;i--)
{
s->list[i].type=s->list[i-1].type;
s->list[i].item=s->list[i-1].item;
}
s->list[0].item=(void *)b;
s->list[0].type=LIST_TYPE_STRIP;
}
}
void DelStripFromStrip(Strip *b, Strip *s)
{
int i;
for(i=0;i<s->num;i++)
{
if ((s->list[i].item==(void *)b)&&(s->list[i].type==LIST_TYPE_STRIP))
{
for(i++;i<s->num;i++)
{
s->list[i-1].type=s->list[i].type;
s->list[i-1].item=s->list[i].item;
}
}
}
s->num--;
s->list=Erealloc(s->list,s->num*(sizeof(Item)));
b->strip=NULL;
}
void CalculateSize(Size *size, ScrBit *X, Constrain *width, Constrain *height)
{
int w,h,nw,nh;
w=DisplayWidth(disp,DefaultScreen(disp));
h=DisplayHeight(disp,DefaultScreen(disp));
if (size->x<=0) nw=X->width;
else
{
if (size->x_at) nw=size->x*w/size->x_at;
else nw=size->x;
}
if (size->y<=0) nh=X->height;
else
{
if (size->y_at) nh=size->y*h/size->y_at;
else nh=size->y;
}
if (width->max)
{
if (nw>width->max) nw=width->max;
}
if (width->min)
{
if (nw<width->min) nw=width->min;
}
if (height->max)
{
if (nh>height->max) nh=height->max;
}
if (height->min)
{
if (nh<height->min) nh=height->min;
}
X->width=nw;
X->height=nh;
}
void CalculateLoc(Coord *loc, int width, int height, ScrBit *X)
{
int w,h,nx,ny,fx,fy,hx,hy;
w=DisplayWidth(disp,DefaultScreen(disp));
h=DisplayHeight(disp,DefaultScreen(disp));
fx=0;fy=0;hx=0;hy=0;
if (loc->handle_macro==COORD_MACRO_CUSTOM)
{
if (loc->x_handle_at) hx=loc->x_handle*width/loc->x_handle_at;
else hx=loc->x_handle;
if (loc->y_handle_at) hy=loc->x_handle*height/loc->y_handle_at;
else hy=loc->y_handle;
}
else if (loc->handle_macro==COORD_MACRO_TOPLEFT)
{
hx=0;hy=0;
}
else if (loc->handle_macro==COORD_MACRO_TOPRIGHT)
{
hx=width-1;hy=0;
}
else if (loc->handle_macro==COORD_MACRO_BOTTOMLEFT)
{
hx=0;hy=height-1;
}
else if (loc->handle_macro==COORD_MACRO_BOTTOMRIGHT)
{
hx=width-1;hy=height-1;
}
else if (loc->handle_macro==COORD_MACRO_MIDDLE)
{
hx=width>>1;hy=height>>1;
}
if (loc->from_macro==COORD_MACRO_CUSTOM)
{
if (loc->x_from_at) fx=loc->x_from*w/loc->x_from_at;
else fx=loc->x_from;
if (loc->y_from_at) fy=loc->y_from*h/loc->y_from_at;
else fy=loc->x_from;
}
else if (loc->from_macro==COORD_MACRO_TOPLEFT)
{
fx=0;fy=0;
}
else if (loc->from_macro==COORD_MACRO_TOPRIGHT)
{
fx=w-1;fy=0;
}
else if (loc->from_macro==COORD_MACRO_BOTTOMLEFT)
{
fx=0;fy=h-1;
}
else if (loc->from_macro==COORD_MACRO_BOTTOMRIGHT)
{
fx=w-1;fy=h-1;
}
else if (loc->from_macro==COORD_MACRO_MIDDLE)
{
fx=w>>1;fy=h>>1;
}
nx=fx-hx+loc->x;
ny=fy-hy+loc->y;
X->x=nx;X->y=ny;
}
void CalcButton(Button *b)
{
CalculateSize(&b->size,&b->X,&b->width,&b->height);
CalculateLoc(&b->loc,b->X.width,b->X.height,&b->X);
}
void DrawButton(Button *b)
{
int draw,move;
Image *im;
ImageEntry *ie;
if (!b) return;
draw=0;move=0;
if (b->state==STATE_NORMAL) ie=b->iclass->normal;
else if (b->state==STATE_HILITED) ie=b->iclass->hilited;
else if (b->state==STATE_CLICKED) ie=b->iclass->clicked;
else if (b->state==STATE_DISABLED) ie=b->iclass->disabled;
else ie=b->iclass->normal;
im=ie->im;
if (b->size.x<=0)
{
if (im) b->X.width=im->rgb_width;
else b->X.width=ie->width;
}
if (b->size.y<=0)
{
if (im) b->X.height=im->rgb_height;
else b->X.height=ie->height;
}
if (b->pstate!=b->state) draw=1;
if (b->pX.width!=b->X.width) draw=1;
if (b->pX.height!=b->X.height) draw=1;
if (b->pX.x!=b->X.x) move=1;
if (b->pX.y!=b->X.y) move=1;
if (move)
{
XMoveWindow(disp,b->X.win,b->X.x,b->X.y);
}
if (draw)
{
if (b->X.pmap) ImlibFreePixmap(imd,b->X.pmap);
if (b->X.mask) ImlibFreePixmap(imd,b->X.mask);
GetPixmaps(b->iclass,b->state,b->X.width,b->X.height,&b->X.pmap,&b->X.mask);
XResizeWindow(disp,b->X.win,b->X.width,b->X.height);
if (b->X.pmap)
XSetWindowBackgroundPixmap(disp,b->X.win,b->X.pmap);
if (b->X.mask)
XShapeCombineMask(disp,b->X.win,ShapeBounding,0,0,b->X.mask,ShapeSet);
XClearWindow(disp,b->X.win);
}
if (move||draw) XSync(disp,False);
b->pstate=b->state;
b->pX.x=b->X.x;
b->pX.y=b->X.y;
b->pX.width=b->X.width;
b->pX.height=b->X.height;
}
void ShowButton(Button *b)
{
XMapWindow(disp,b->X.win);
XSync(disp,False);
}
void HideButton(Button *b)
{
XUnmapWindow(disp,b->X.win);
XSync(disp,False);
}
void MoveButtonTo(Button *b, int x, int y)
{
if (!b) return;
b->loc.x=x;
b->loc.y=y;
CalcButton(b);
DrawButton(b);
}
void MoveButtonBy(Button *b, int x, int y)
{
if (!b) return;
b->loc.x+=x;
b->loc.y+=y;
CalcButton(b);
DrawButton(b);
}
void ButtonHilite(Button *b, char onoff)
{
if (!b) return;
if (b->state==STATE_DISABLED) return;
if (onoff)
{
if (b->state!=STATE_CLICKED)
b->state=STATE_HILITED;
}
else
{
if (b->state!=STATE_CLICKED)
b->state=STATE_NORMAL;
}
DrawButton(b);
}
void ButtonClick(Button *b, char onoff)
{
if (!b) return;
if (b->state==STATE_DISABLED) return;
if (onoff)
b->state=STATE_CLICKED;
else
{
if (b->state==STATE_NORMAL)
b->state=STATE_NORMAL;
else
b->state=STATE_HILITED;
}
DrawButton(b);
}
void ButtonDisable(Button *b, char onoff)
{
if (!b) return;
if (onoff)
b->state=STATE_DISABLED;
else
b->state=STATE_NORMAL;
DrawButton(b);
}
void SetButtonImageClass(Button *b, char *name)
{
ImageClass *ic;
if (!b) return;
if (!name) return;
ic=(ImageClass *)FindItem(name,LIST_TYPE_IMAGECLASS);
if (!ic) return;
b->iclass=ic;
CalcButton(b);
DrawButton(b);
}
void SetButtonLocation(Button *b, Coord *loc)
{
if ((!b)||(!loc)) return;
b->loc.handle_macro=loc->handle_macro;
b->loc.x_handle=loc->x_handle;
b->loc.y_handle=loc->y_handle;
b->loc.x_handle_at=loc->x_handle_at;
b->loc.y_handle_at=loc->y_handle_at;
b->loc.from_macro=loc->from_macro;
b->loc.x_from=loc->x_from;
b->loc.y_from=loc->y_from;
b->loc.x_from_at=loc->x_from_at;
b->loc.y_from_at=loc->y_from_at;
b->loc.x=loc->x;
b->loc.y=loc->y;
CalcButton(b);
DrawButton(b);
}
void SetButtonSize(Button *b, Size *siz)
{
if ((!b)||(!siz)) return;
b->size.x=siz->x;
b->size.x_at=siz->x_at;
b->size.y=siz->y;
b->size.y_at=siz->y_at;
CalcButton(b);
DrawButton(b);
}
void SetButtonContraints(Button *b, Constrain *w, Constrain *h)
{
if ((!b)||(!w)||(!h)) return;
b->width.min=w->min;
b->width.max=w->max;
b->height.min=h->min;
b->height.max=h->max;
CalcButton(b);
DrawButton(b);
}
void DrawStrip(Strip *s)
{
int i,x,y,w,h;
ScrBit *sb;
if (!s->num) return;
sb=NULL;
for(i=0;i<s->num;i++)
{
if (s->list[i].type==LIST_TYPE_BUTTON)
{
CalculateSize(&((Button *)(s->list[i].item))->size,
&((Button *)(s->list[i].item))->X,
&((Button *)(s->list[i].item))->width,
&((Button *)(s->list[i].item))->height);
}
else if (s->list[i].type==LIST_TYPE_STRIP)
{
DrawStrip((Strip *)(s->list[i].item));
}
}
if (s->orientation==STRIP_ORIENTATION_VERTICAL)
{
h=0;
if (s->list[0].type==LIST_TYPE_BUTTON)
sb=&((Button *)(s->list[0].item))->X;
else if (s->list[0].type==LIST_TYPE_STRIP)
sb=&((Strip *)(s->list[0].item))->X;
w=sb->width;
for(i=0;i<s->num;i++)
{
if (s->list[i].type==LIST_TYPE_BUTTON)
sb=&((Button *)(s->list[i].item))->X;
else if (s->list[i].type==LIST_TYPE_STRIP)
sb=&((Strip *)(s->list[i].item))->X;
h+=sb->height;
if (sb->width>w) w=sb->width;
}
s->X.width=w;s->X.height=h;
x=0;y=0;
if (!s->strip)
{
CalculateLoc(&s->loc,w,h,&s->X);
y=s->X.y;x=s->X.x;
}
else
{
y=s->X.y;
x=s->X.x;
}
for(i=0;i<s->num;i++)
{
if (s->list[i].type==LIST_TYPE_BUTTON)
sb=&((Button *)(s->list[i].item))->X;
else if (s->list[i].type==LIST_TYPE_STRIP)
sb=&((Strip *)(s->list[i].item))->X;
sb->x=x+(((w-sb->width)*s->justification)/100);
sb->y=y;y+=sb->height;
}
}
else
{
w=0;
if (s->list[0].type==LIST_TYPE_BUTTON)
sb=&((Button *)(s->list[0].item))->X;
else if (s->list[0].type==LIST_TYPE_STRIP)
sb=&((Strip *)(s->list[0].item))->X;
h=sb->height;
for(i=0;i<s->num;i++)
{
if (s->list[i].type==LIST_TYPE_BUTTON)
sb=&((Button *)(s->list[i].item))->X;
else if (s->list[i].type==LIST_TYPE_STRIP)
sb=&((Strip *)(s->list[i].item))->X;
w+=sb->width;
if (sb->height>h) h=sb->height;
}
s->X.width=w;s->X.height=h;
x=0;y=0;
if (!s->strip)
{
CalculateLoc(&s->loc,w,h,&s->X);
y=s->X.y;x=s->X.x;
}
else
{
y=s->X.y;
x=s->X.x;
}
for(i=0;i<s->num;i++)
{
if (s->list[i].type==LIST_TYPE_BUTTON)
sb=&((Button *)(s->list[i].item))->X;
else if (s->list[i].type==LIST_TYPE_STRIP)
sb=&((Strip *)(s->list[i].item))->X;
sb->y=y+(((h-sb->height)*s->justification)/100);
sb->x=x;x+=sb->width;
}
}
for(i=0;i<s->num;i++)
{
if (s->list[i].type==LIST_TYPE_BUTTON)
DrawButton((Button *)s->list[i].item);
else if (s->list[i].type==LIST_TYPE_STRIP)
DrawStrip((Strip *)s->list[i].item);
}
}
void HideStrip(Strip *s)
{
int i;
for(i=0;i<s->num;i++)
{
if (s->list[i].type==LIST_TYPE_BUTTON)
HideButton((Button *)s->list[i].item);
else if (s->list[i].type==LIST_TYPE_STRIP)
HideStrip((Strip *)s->list[i].item);
}
s->visible=0;
}
void ShowStrip(Strip *s)
{
int i;
for(i=0;i<s->num;i++)
{
if (s->list[i].type==LIST_TYPE_BUTTON)
ShowButton((Button *)s->list[i].item);
else if (s->list[i].type==LIST_TYPE_STRIP)
ShowStrip((Strip *)s->list[i].item);
}
s->visible=1;
}
void RotateStrip(Strip *s)
{
int i;
if (!s) return;
if (s->orientation==STRIP_ORIENTATION_VERTICAL)
s->orientation=STRIP_ORIENTATION_HORIZONTAL;
else
s->orientation=STRIP_ORIENTATION_VERTICAL;
for(i=0;i<s->num;i++)
{
if (s->list[i].type==LIST_TYPE_STRIP)
{
RotateStrip((Strip *)s->list[i].item);
}
}
if (s->strip) DrawStrip(s->strip);
else DrawStrip(s);
}
void FlipStrip(Strip *s)
{
int i;
Item it;
if (!s) return;
if (s->num<2) return;
for(i=0;i<s->num>>1;i++)
{
it.type=s->list[i].type;
it.item=s->list[i].item;
s->list[i].type=s->list[s->num-i-1].type;
s->list[i].item=s->list[s->num-i-1].item;
s->list[s->num-i-1].type=it.type;
s->list[s->num-i-1].item=it.item;
}
DrawStrip(s);
}
void SetStripJustification(Strip *s, int just)
{
if (!s) return;
s->justification=just;
DrawStrip(s);
}
void MoveStripTo(Strip *s, int x, int y)
{
if (!s) return;
if (s->strip)
{
MoveStripTo(s->strip,x,y);
}
else
{
s->loc.x=x;
s->loc.y=y;
DrawStrip(s);
}
}
void MoveStripBy(Strip *s, int x, int y)
{
if (!s) return;
if (s->strip)
{
MoveStripBy(s->strip,x,y);
}
else
{
s->loc.x+=x;
s->loc.y+=y;
DrawStrip(s);
}
}
void SetStripLocation(Strip *s, Coord *loc)
{
if ((!s)||(!loc)) return;
s->loc.handle_macro=loc->handle_macro;
s->loc.x_handle=loc->x_handle;
s->loc.y_handle=loc->y_handle;
s->loc.x_handle_at=loc->x_handle_at;
s->loc.y_handle_at=loc->y_handle_at;
s->loc.from_macro=loc->from_macro;
s->loc.x_from=loc->x_from;
s->loc.y_from=loc->y_from;
s->loc.x_from_at=loc->x_from_at;
s->loc.y_from_at=loc->y_from_at;
s->loc.x=loc->x;
s->loc.y=loc->y;
DrawStrip(s);
}
void CfgParseLocLine(char *lin, Coord *loc)
{
char s[256],*ww;
int wd;
wd=1;
word(lin,wd++,s);
if (strcmp(s,"location")) return;
word(lin,wd++,s);
if (strcmp(s,"handle")) return;
word(lin,wd++,s);
if (!strcmp(s,"topleft")) loc->handle_macro=COORD_MACRO_TOPLEFT;
else if (!strcmp(s,"topright")) loc->handle_macro=COORD_MACRO_TOPRIGHT;
else if (!strcmp(s,"bottomleft")) loc->handle_macro=COORD_MACRO_BOTTOMLEFT;
else if (!strcmp(s,"bottomright")) loc->handle_macro=COORD_MACRO_BOTTOMRIGHT;
else if (!strcmp(s,"middle")) loc->handle_macro=COORD_MACRO_MIDDLE;
else
{
loc->handle_macro=COORD_MACRO_CUSTOM;
ww=atchar(s,'@');
if (ww)
{
*ww=' ';
sscanf(s,"%i",&loc->x_handle);
sscanf(s,"%*i %i",&loc->x_handle_at);
}
else
sscanf(s,"%i",&loc->x_handle);
word(lin,wd++,s);
ww=atchar(s,'@');
if (ww)
{
*ww=' ';
sscanf(s,"%i",&loc->y_handle);
sscanf(s,"%*i %i",&loc->y_handle_at);
}
else
sscanf(s,"%i",&loc->y_handle);
}
word(lin,wd++,s);
if (strcmp(s,"from")) return;
word(lin,wd++,s);
if (!strcmp(s,"topleft")) loc->from_macro=COORD_MACRO_TOPLEFT;
else if (!strcmp(s,"topright")) loc->from_macro=COORD_MACRO_TOPRIGHT;
else if (!strcmp(s,"bottomleft")) loc->from_macro=COORD_MACRO_BOTTOMLEFT;
else if (!strcmp(s,"bottomright")) loc->from_macro=COORD_MACRO_BOTTOMRIGHT;
else if (!strcmp(s,"middle")) loc->from_macro=COORD_MACRO_MIDDLE;
else
{
loc->from_macro=COORD_MACRO_CUSTOM;
ww=atchar(s,'@');
if (ww)
{
*ww=' ';
sscanf(s,"%i",&loc->x_from);
sscanf(s,"%*i %i",&loc->x_from_at);
}
else
sscanf(s,"%i",&loc->x_from);
word(lin,wd++,s);
ww=atchar(s,'@');
if (ww)
{
*ww=' ';
sscanf(s,"%i",&loc->y_from);
sscanf(s,"%*i %i",&loc->y_from_at);
}
else
sscanf(s,"%i",&loc->y_from);
}
word(lin,wd++,s);
if (strcmp(s,"at")) return;
word(lin,wd++,s);loc->x=atoi(s);
word(lin,wd++,s);loc->y=atoi(s);
}
void CfgParseSizeLine(char *lin, Size *size)
{
char s[256],*w,*ww;
int wd;
wd=1;
s[0]=0;w=atword(lin,wd++);sscanf(w,"%s",s);
if (strcmp(s,"size")) return;
{
s[0]=0;w=atword(lin,wd++);sscanf(w,"%s",s);
ww=atchar(s,'@');
if (ww)
{
*ww=' ';
sscanf(s,"%i",&size->x);
sscanf(s,"%*i %i",&size->x_at);
}
else
sscanf(s,"%i",&size->x);
s[0]=0;w=atword(lin,wd++);sscanf(w,"%s",s);
ww=atchar(s,'@');
if (ww)
{
*ww=' ';
sscanf(s,"%i",&size->y);
sscanf(s,"%*i %i",&size->y_at);
}
else
sscanf(s,"%i",&size->y);
}
}
void CfgParseConstrain(char *lin, Constrain *c)
{
sscanf(lin,"%*s %*s %*s %i %*s %i",&c->min,&c->max);
}