home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Linux
/
Enlightenment
/
enl14.tgz
/
enl14.tar
/
enl14
/
actions.c
next >
Wrap
C/C++ Source or Header
|
1997-11-21
|
10KB
|
490 lines
#include "enl.h"
void DoSimpleAction(Action *a)
{
if (!a) return;
switch(a->id)
{
case ACTION_EXEC:
ActionExec(a->params);
break;
case ACTION_ALERT:
ActionAlert(a->params);
break;
case ACTION_ROTATE_STRIP:
ActionRotateStrip(a->params);
break;
case ACTION_MOVE_STRIP:
ActionMoveStrip(a->params);
break;
case ACTION_SAVE_STRIP:
ActionSaveStrip(a->params);
break;
case ACTION_JUSTIFY_STRIP:
ActionJustifyStrip(a->params);
break;
case ACTION_DELETE_STRIP:
ActionDeleteStrip(a->params);
break;
case ACTION_SHOW_STRIP:
ActionShowStrip(a->params);
break;
case ACTION_HIDE_STRIP:
ActionHideStrip(a->params);
break;
case ACTION_SHOW_STRIP_TOGGLE:
ActionShowStripToggle(a->params);
break;
case ACTION_LOCATE_STRIP:
ActionLocateStrip(a->params);
break;
case ACTION_DISABLE_BUTTON:
ActionDisableButton(a->params);
break;
case ACTION_ENABLE_BUTTON:
ActionEnableButton(a->params);
break;
case ACTION_DISABLE_BUTTON_TOGGLE:
ActionDisableButtonToggle(a->params);
break;
case ACTION_MOVE_BUTTON:
ActionMoveButton(a->params);
break;
case ACTION_SAVE_BUTTON:
ActionSaveButton(a->params);
break;
case ACTION_SHOW_BUTTON:
ActionShowButton(a->params);
break;
case ACTION_HIDE_BUTTON:
ActionHideButton(a->params);
break;
case ACTION_DELETE_BUTTON:
ActionDeleteButton(a->params);
break;
case ACTION_SHOW_BUTTON_TOGGLE:
ActionShowButtonToggle(a->params);
break;
case ACTION_LOCATE_BUTTON:
ActionLocateButton(a->params);
break;
case ACTION_CALLBACK:
ActionCallback(a->params);
break;
case ACTION_SLIDER_STRIP_JUSTIFY:
ActionSliderJustiyStrip(a->params);
break;
case ACTION_FLIP_STRIP:
ActionFlipStrip(a->params);
break;
default:
break;
}
}
void DoAction(XEvent *ev, ActionInit *a, int num)
{
KeyCode key;
int i,type,button,modifiers,ok,mousekey;
if ((!a)||(!ev)) return;
key=type=button=modifiers=mousekey=0;
switch (ev->type)
{
case KeyPress:
type=EVENT_KEY_DOWN;
key=ev->xkey.keycode;
modifiers=ev->xbutton.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
mousekey=0;
break;
case KeyRelease:
type=EVENT_KEY_UP;
key=ev->xkey.keycode;
modifiers=ev->xbutton.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
mousekey=0;
break;
case ButtonPress:
type=EVENT_MOUSE_DOWN;
button=ev->xbutton.button;
modifiers=ev->xbutton.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
mousekey=1;
break;
case ButtonRelease:
type=EVENT_MOUSE_UP;
button=ev->xbutton.button;
modifiers=ev->xbutton.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
mousekey=1;
break;
case EnterNotify:
type=EVENT_MOUSE_ENTER;
button=0;
modifiers=ev->xcrossing.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
mousekey=1;
break;
case LeaveNotify:
type=EVENT_MOUSE_LEAVE;
button=0;
modifiers=ev->xcrossing.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
mousekey=1;
break;
default:
break;
}
for(i=0;i<num;i++)
{
ok=1;
if (a[i].event!=type) ok=0;
if (ok)
{
if ((a[i].any==0)&&(a[i].modifiers!=modifiers)) ok=0;
}
if (ok)
{
if (mousekey)
{
if ((a[i].button!=0)&&(a[i].button!=button)) ok=0;
}
else
{
if ((a[i].anykey==0)&&(a[i].key!=key)) ok=0;
}
}
if (ok) DoSimpleAction(&a[i].action);
}
}
void ActionExec(char *p)
{
char *sh;
if (!p) return;
if (fork()) return;
setsid();
sh=usershell(getuid());
execl(sh,sh,"-c",p,NULL);
exit(0);
}
void ActionAlert(char *p)
{
char *pp;
int i;
pp=duplicate(p);
i=1;
if (!pp) return;
if (strlen(pp)<=0) return;
while(pp[i])
{
if ((pp[i-1]=='\\')&&(p[i]=='n'))
{
pp[i-1]=' ';pp[i]='\n';
}
i++;
}
Alert(pp);
Efree(pp);
}
void ActionRotateStrip(char *p)
{
if (!p)
RotateStrip(mode.strip);
else
RotateStrip(FindItem(p,LIST_TYPE_STRIP));
}
void ActionMoveStrip(char *p)
{
mode.mode=MODE_MOVE_STRIP;
}
void ActionSaveStrip(char *p)
{
}
void ActionJustifyStrip(char *p)
{
Slider *s;
Action a;
Root *r;
int x,y;
char ss[1024];
x=0;y=0;
if (p)
mode.strip=FindItem(p,LIST_TYPE_STRIP);
if (mode.strip)
{
r=(Root *)FindItem("ROOT",LIST_TYPE_ROOT);
s=FindItem("SLIDER_JUSTIFY",LIST_TYPE_SLIDER);
if (s)
{
FreeSlider(DelItem(s->name,LIST_TYPE_SLIDER));
FreeButton((Button *)DelItem("SLIDER_OK_BUTTON",LIST_TYPE_BUTTON));
return;
}
if (mode.strip->orientation==STRIP_ORIENTATION_VERTICAL)
{
s=CreateSlider("SLIDER_JUSTIFY","SLIDER_CLASS1",
STRIP_ORIENTATION_HORIZONTAL,100,100);
if (r)
{
x=(r->width>>1)-50-(s->sclass->horizontal.base.start_inset);
y=(r->height>>1)-(s->sclass->horizontal.base.thickness>>1);
}
else
{
x=0;y=0;
}
ShowButton(MakeButton("SLIDER_OK_BUTTON","DEFAULT_OK",
x-s->sclass->horizontal.base.thickness,
y,
s->sclass->horizontal.base.thickness,
s->sclass->horizontal.base.thickness));
}
else
{
s=CreateSlider("SLIDER_JUSTIFY","SLIDER_CLASS1",
STRIP_ORIENTATION_VERTICAL,100,100);
if (r)
{
x=(r->width>>1)-(s->sclass->vertical.base.thickness>>1);
y=(r->height>>1)-50-(s->sclass->vertical.base.end_inset);
}
else
{
x=0;y=0;
}
ShowButton(MakeButton("SLIDER_OK_BUTTON","DEFAULT_OK",
x,
y-s->sclass->vertical.base.thickness,
s->sclass->vertical.base.thickness,
s->sclass->vertical.base.thickness));
}
sprintf(ss,"mouse up any any justify_strip %s",mode.strip->name);
AddButtonAction((Button *)FindItem("SLIDER_OK_BUTTON",LIST_TYPE_BUTTON),ss);
AddItem((void *)s,s->name,LIST_TYPE_SLIDER);
a.id=ACTION_SLIDER_STRIP_JUSTIFY;
a.params=duplicate(mode.strip->name);
SetSliderAction(s,&a);
MoveSliderTo(s,x,y);
SetSliderValue(s,mode.strip->justification);
DrawSlider(s);ShowSlider(s);
}
}
void ActionDeleteStrip(char *p)
{
if (!p)
{
if (!mode.strip) return;
DelItem(mode.strip->name,LIST_TYPE_STRIP);
FreeStrip(mode.strip);
mode.strip=NULL;
}
else
{
Strip *s;
s=DelItem(p,LIST_TYPE_STRIP);
FreeStrip(s);
mode.strip=NULL;
}
}
void ActionShowStrip(char *p)
{
if (!p)
ShowStrip(mode.strip);
else
ShowStrip(FindItem(p,LIST_TYPE_STRIP));
}
void ActionHideStrip(char *p)
{
if (!p)
HideStrip(mode.strip);
else
HideStrip(FindItem(p,LIST_TYPE_STRIP));
}
void ActionShowStripToggle(char *p)
{
if (!p)
{
if (!mode.strip) return;
if (mode.strip->visible)
HideStrip(mode.strip);
else
ShowStrip(mode.strip);
}
else
{
Strip *s;
s=FindItem(p,LIST_TYPE_STRIP);
if (!s) return;
if (s->visible)
HideStrip(s);
else
ShowStrip(s);
}
}
void ActionLocateStrip(char *p)
{
Coord loc;
if (!p) return;
CfgParseLocLine(p,&loc);
SetStripLocation(mode.strip,&loc);
}
void ActionDisableButton(char *p)
{
if (!p)
ButtonDisable(mode.button,1);
else
ButtonDisable(FindItem(p,LIST_TYPE_BUTTON),1);
}
void ActionEnableButton(char *p)
{
if (!p)
ButtonDisable(mode.button,0);
else
ButtonDisable(FindItem(p,LIST_TYPE_BUTTON),0);
}
void ActionDisableButtonToggle(char *p)
{
if (!p)
{
if (mode.button->state==STATE_DISABLED)
ButtonDisable(mode.button,0);
else
ButtonDisable(mode.button,1);
}
else
{
Button *b;
b=FindItem(p,LIST_TYPE_BUTTON);
if (!b) return;
if (b->state==STATE_DISABLED)
ButtonDisable(b,0);
else
ButtonDisable(b,1);
}
}
void ActionMoveButton(char *p)
{
if (!mode.button) return;
if (!mode.button->strip)
mode.mode=MODE_MOVE_BUTTON;
}
void ActionSaveButton(char *p)
{
}
void ActionShowButton(char *p)
{
if (!p)
ShowButton(mode.button);
else
ShowButton(FindItem(p,LIST_TYPE_BUTTON));
}
void ActionHideButton(char *p)
{
if (!p)
HideButton(mode.button);
else
HideButton(FindItem(p,LIST_TYPE_BUTTON));
}
void ActionDeleteButton(char *p)
{
if (!p)
{
if (!mode.button) return;
DelItem(mode.button->name,LIST_TYPE_BUTTON);
FreeButton(mode.button);
mode.button=NULL;
}
else
{
Button *b;
b=DelItem(p,LIST_TYPE_BUTTON);
FreeButton(b);
mode.button=NULL;
}
}
void ActionShowButtonToggle(char *p)
{
if (!p)
{
if (!mode.button) return;
if (mode.button->visible)
HideButton(mode.button);
else
ShowButton(mode.button);
}
else
{
Button *b;
b=FindItem(p,LIST_TYPE_STRIP);
if (!b) return;
if (b->visible)
HideButton(b);
else
ShowButton(b);
}
}
void ActionLocateButton(char *p)
{
}
void ActionCallback(char *p)
{
void **pp;
void (*cb)();
if (!p) return;
pp=(void *)p;cb=(void (*)())*pp;
(*cb)();
}
void ActionSliderJustiyStrip(char *p)
{
if (!p) return;
if (!mode.slider) return;
SetStripJustification(FindItem(p,LIST_TYPE_STRIP),GetSliderValue(mode.slider));
}
void ActionFlipStrip(char *p)
{
if (p) FlipStrip((Strip *)FindItem(p,LIST_TYPE_STRIP));
else
{
if (mode.strip) FlipStrip(mode.strip);
}
}