home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Enlightenment / enl14.tgz / enl14.tar / enl14 / actions.c next >
C/C++ Source or Header  |  1997-11-21  |  10KB  |  490 lines

  1. #include "enl.h"
  2.  
  3. void DoSimpleAction(Action *a)
  4. {
  5.    if (!a) return;
  6.    
  7.    switch(a->id)
  8.      {
  9.       case ACTION_EXEC:
  10.          ActionExec(a->params);
  11.          break;
  12.       case ACTION_ALERT:
  13.          ActionAlert(a->params);
  14.          break;
  15.       case ACTION_ROTATE_STRIP:
  16.          ActionRotateStrip(a->params);
  17.          break;
  18.       case ACTION_MOVE_STRIP:
  19.          ActionMoveStrip(a->params);
  20.          break;
  21.       case ACTION_SAVE_STRIP:
  22.          ActionSaveStrip(a->params);
  23.          break;
  24.       case ACTION_JUSTIFY_STRIP:
  25.          ActionJustifyStrip(a->params);
  26.          break;
  27.       case ACTION_DELETE_STRIP:
  28.          ActionDeleteStrip(a->params);
  29.          break;
  30.       case ACTION_SHOW_STRIP:
  31.          ActionShowStrip(a->params);
  32.          break;
  33.       case ACTION_HIDE_STRIP:
  34.          ActionHideStrip(a->params);
  35.          break;
  36.       case ACTION_SHOW_STRIP_TOGGLE:
  37.          ActionShowStripToggle(a->params);
  38.          break;
  39.       case ACTION_LOCATE_STRIP:
  40.          ActionLocateStrip(a->params);
  41.          break;
  42.       case ACTION_DISABLE_BUTTON:
  43.          ActionDisableButton(a->params);
  44.          break;
  45.       case ACTION_ENABLE_BUTTON:
  46.          ActionEnableButton(a->params);
  47.          break;
  48.       case ACTION_DISABLE_BUTTON_TOGGLE:
  49.          ActionDisableButtonToggle(a->params);
  50.          break;
  51.       case ACTION_MOVE_BUTTON:
  52.          ActionMoveButton(a->params);
  53.          break;
  54.       case ACTION_SAVE_BUTTON:
  55.          ActionSaveButton(a->params);
  56.          break;
  57.       case ACTION_SHOW_BUTTON:
  58.          ActionShowButton(a->params);
  59.          break;
  60.       case ACTION_HIDE_BUTTON:
  61.          ActionHideButton(a->params);
  62.          break;
  63.       case ACTION_DELETE_BUTTON:
  64.          ActionDeleteButton(a->params);
  65.          break;
  66.       case ACTION_SHOW_BUTTON_TOGGLE:
  67.          ActionShowButtonToggle(a->params);
  68.          break;
  69.       case ACTION_LOCATE_BUTTON:
  70.          ActionLocateButton(a->params);
  71.          break;
  72.       case ACTION_CALLBACK:
  73.          ActionCallback(a->params);
  74.          break;
  75.       case ACTION_SLIDER_STRIP_JUSTIFY:
  76.          ActionSliderJustiyStrip(a->params);
  77.          break;
  78.       case ACTION_FLIP_STRIP:
  79.          ActionFlipStrip(a->params);
  80.          break;
  81.       default:
  82.          break;
  83.      }
  84. }
  85.  
  86. void DoAction(XEvent *ev, ActionInit *a, int num)
  87. {
  88.    KeyCode key;
  89.    int i,type,button,modifiers,ok,mousekey;
  90.    
  91.    if ((!a)||(!ev)) return;
  92.    key=type=button=modifiers=mousekey=0;
  93.    switch (ev->type)
  94.      {  
  95.       case KeyPress:
  96.          type=EVENT_KEY_DOWN;
  97.          key=ev->xkey.keycode;
  98.          modifiers=ev->xbutton.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
  99.                                                 Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
  100.          mousekey=0;
  101.          break;
  102.       case KeyRelease:
  103.          type=EVENT_KEY_UP;
  104.          key=ev->xkey.keycode;
  105.          modifiers=ev->xbutton.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
  106.                                                 Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
  107.          mousekey=0;
  108.          break;
  109.       case ButtonPress:
  110.          type=EVENT_MOUSE_DOWN;
  111.          button=ev->xbutton.button;
  112.          modifiers=ev->xbutton.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
  113.                                                 Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
  114.          mousekey=1;
  115.          break;
  116.       case ButtonRelease:
  117.          type=EVENT_MOUSE_UP;
  118.          button=ev->xbutton.button;
  119.          modifiers=ev->xbutton.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
  120.                                                 Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
  121.          mousekey=1;
  122.          break;
  123.       case EnterNotify:
  124.          type=EVENT_MOUSE_ENTER;
  125.          button=0;
  126.          modifiers=ev->xcrossing.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
  127.                                                   Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
  128.          mousekey=1;
  129.          break;
  130.       case LeaveNotify:
  131.          type=EVENT_MOUSE_LEAVE;
  132.          button=0;
  133.          modifiers=ev->xcrossing.state&(ShiftMask|LockMask|ControlMask|Mod1Mask|
  134.                                                   Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask);
  135.          mousekey=1;
  136.          break;
  137.       default:
  138.          break;
  139.      }
  140.    for(i=0;i<num;i++)
  141.      {
  142.          ok=1;
  143.          if (a[i].event!=type) ok=0;
  144.          if (ok)
  145.           {
  146.               if ((a[i].any==0)&&(a[i].modifiers!=modifiers)) ok=0;
  147.           }
  148.          if (ok)
  149.           {
  150.               if (mousekey)
  151.                 {
  152.                     if ((a[i].button!=0)&&(a[i].button!=button)) ok=0;
  153.                 }
  154.               else
  155.                 {
  156.                     if ((a[i].anykey==0)&&(a[i].key!=key)) ok=0;
  157.                 }
  158.           }
  159.          if (ok) DoSimpleAction(&a[i].action);
  160.      }
  161. }
  162.  
  163. void ActionExec(char *p)
  164. {
  165.    char *sh;
  166.    
  167.    if (!p) return;
  168.    if (fork()) return;
  169.    setsid();
  170.    sh=usershell(getuid());
  171.    execl(sh,sh,"-c",p,NULL);
  172.    exit(0);
  173. }
  174.  
  175. void ActionAlert(char *p)
  176. {
  177.    char *pp;
  178.    int i;
  179.    
  180.    pp=duplicate(p);
  181.    i=1;
  182.    if (!pp) return;
  183.    if (strlen(pp)<=0) return;
  184.    while(pp[i])
  185.      {
  186.          if ((pp[i-1]=='\\')&&(p[i]=='n'))
  187.           {
  188.               pp[i-1]=' ';pp[i]='\n';
  189.           }
  190.          i++;
  191.      }
  192.    Alert(pp);
  193.    Efree(pp);
  194. }
  195.  
  196. void ActionRotateStrip(char *p)
  197. {
  198.    if (!p)
  199.      RotateStrip(mode.strip);
  200.    else
  201.      RotateStrip(FindItem(p,LIST_TYPE_STRIP));
  202. }
  203.  
  204. void ActionMoveStrip(char *p)
  205. {
  206.    mode.mode=MODE_MOVE_STRIP;
  207. }
  208.  
  209. void ActionSaveStrip(char *p)
  210. {
  211. }
  212.  
  213. void ActionJustifyStrip(char *p)
  214. {
  215.    Slider *s;
  216.    Action a;
  217.    Root *r;
  218.    int x,y;
  219.    char ss[1024];
  220.     
  221.    x=0;y=0;
  222.    if (p)
  223.      mode.strip=FindItem(p,LIST_TYPE_STRIP);
  224.    if (mode.strip)
  225.      {
  226.          r=(Root *)FindItem("ROOT",LIST_TYPE_ROOT);
  227.          s=FindItem("SLIDER_JUSTIFY",LIST_TYPE_SLIDER);
  228.          if (s) 
  229.           {
  230.               FreeSlider(DelItem(s->name,LIST_TYPE_SLIDER));
  231.               FreeButton((Button *)DelItem("SLIDER_OK_BUTTON",LIST_TYPE_BUTTON));
  232.               return;
  233.           }
  234.          if (mode.strip->orientation==STRIP_ORIENTATION_VERTICAL)
  235.           {
  236.               s=CreateSlider("SLIDER_JUSTIFY","SLIDER_CLASS1",
  237.                                   STRIP_ORIENTATION_HORIZONTAL,100,100);
  238.               if (r)
  239.                 {
  240.                     x=(r->width>>1)-50-(s->sclass->horizontal.base.start_inset);
  241.                     y=(r->height>>1)-(s->sclass->horizontal.base.thickness>>1);
  242.                 }
  243.               else
  244.                 {
  245.                     x=0;y=0;
  246.                 }
  247.               ShowButton(MakeButton("SLIDER_OK_BUTTON","DEFAULT_OK",
  248.                                             x-s->sclass->horizontal.base.thickness,
  249.                                             y,
  250.                                             s->sclass->horizontal.base.thickness,
  251.                                             s->sclass->horizontal.base.thickness));
  252.           }
  253.          else
  254.           {
  255.               s=CreateSlider("SLIDER_JUSTIFY","SLIDER_CLASS1",
  256.                                   STRIP_ORIENTATION_VERTICAL,100,100);
  257.               if (r)
  258.                 {
  259.                     x=(r->width>>1)-(s->sclass->vertical.base.thickness>>1);
  260.                     y=(r->height>>1)-50-(s->sclass->vertical.base.end_inset);
  261.                 }
  262.               else
  263.                 {
  264.                     x=0;y=0;
  265.                 }
  266.               ShowButton(MakeButton("SLIDER_OK_BUTTON","DEFAULT_OK",
  267.                                             x,
  268.                                             y-s->sclass->vertical.base.thickness,
  269.                                             s->sclass->vertical.base.thickness,
  270.                                             s->sclass->vertical.base.thickness));
  271.           }
  272.          sprintf(ss,"mouse up any any justify_strip %s",mode.strip->name);
  273.          AddButtonAction((Button *)FindItem("SLIDER_OK_BUTTON",LIST_TYPE_BUTTON),ss);
  274.          AddItem((void *)s,s->name,LIST_TYPE_SLIDER);
  275.          a.id=ACTION_SLIDER_STRIP_JUSTIFY;
  276.          a.params=duplicate(mode.strip->name);
  277.          SetSliderAction(s,&a);
  278.          MoveSliderTo(s,x,y);
  279.          SetSliderValue(s,mode.strip->justification);
  280.          DrawSlider(s);ShowSlider(s);
  281.      }
  282. }
  283.  
  284. void ActionDeleteStrip(char *p)
  285. {
  286.    if (!p)
  287.      {
  288.          if (!mode.strip) return;
  289.          DelItem(mode.strip->name,LIST_TYPE_STRIP);
  290.          FreeStrip(mode.strip);
  291.          mode.strip=NULL;
  292.      }
  293.    else
  294.      {
  295.          Strip *s;
  296.          
  297.          s=DelItem(p,LIST_TYPE_STRIP);
  298.          FreeStrip(s);
  299.          mode.strip=NULL;
  300.      }
  301.     
  302. }
  303.  
  304. void ActionShowStrip(char *p)
  305. {
  306.    if (!p)
  307.      ShowStrip(mode.strip);
  308.    else
  309.      ShowStrip(FindItem(p,LIST_TYPE_STRIP));
  310. }
  311.  
  312. void ActionHideStrip(char *p)
  313. {
  314.    if (!p)
  315.      HideStrip(mode.strip);
  316.    else
  317.      HideStrip(FindItem(p,LIST_TYPE_STRIP));
  318. }
  319.  
  320. void ActionShowStripToggle(char *p)
  321. {
  322.    if (!p)
  323.      {
  324.          if (!mode.strip) return;
  325.          if (mode.strip->visible)
  326.             HideStrip(mode.strip);
  327.          else
  328.             ShowStrip(mode.strip);
  329.      }
  330.    else
  331.      {
  332.          Strip *s;
  333.          
  334.          s=FindItem(p,LIST_TYPE_STRIP);
  335.          if (!s) return;
  336.          if (s->visible)
  337.             HideStrip(s);
  338.          else
  339.             ShowStrip(s);
  340.      }
  341. }
  342.  
  343. void ActionLocateStrip(char *p)
  344. {
  345.    Coord loc;
  346.    
  347.    if (!p) return;
  348.    
  349.    CfgParseLocLine(p,&loc);
  350.    SetStripLocation(mode.strip,&loc);
  351. }
  352.  
  353. void ActionDisableButton(char *p)
  354. {
  355.    if (!p)
  356.      ButtonDisable(mode.button,1);
  357.    else
  358.      ButtonDisable(FindItem(p,LIST_TYPE_BUTTON),1);
  359. }
  360.  
  361. void ActionEnableButton(char *p)
  362. {
  363.    if (!p)
  364.      ButtonDisable(mode.button,0);
  365.    else
  366.      ButtonDisable(FindItem(p,LIST_TYPE_BUTTON),0);
  367. }
  368.  
  369. void ActionDisableButtonToggle(char *p)
  370. {
  371.    if (!p)
  372.      {
  373.          if (mode.button->state==STATE_DISABLED)
  374.             ButtonDisable(mode.button,0);
  375.          else
  376.             ButtonDisable(mode.button,1);
  377.      }
  378.    else
  379.      {
  380.          Button *b;
  381.          
  382.          b=FindItem(p,LIST_TYPE_BUTTON);
  383.          if (!b) return;
  384.          if (b->state==STATE_DISABLED)
  385.             ButtonDisable(b,0);
  386.          else
  387.             ButtonDisable(b,1);
  388.      }
  389. }
  390.  
  391. void ActionMoveButton(char *p)
  392. {
  393.    if (!mode.button) return;
  394.    if (!mode.button->strip)
  395.      mode.mode=MODE_MOVE_BUTTON;
  396. }
  397.  
  398. void ActionSaveButton(char *p)
  399. {
  400. }
  401.  
  402. void ActionShowButton(char *p)
  403. {
  404.    if (!p)
  405.      ShowButton(mode.button);
  406.    else
  407.      ShowButton(FindItem(p,LIST_TYPE_BUTTON));
  408. }
  409.  
  410. void ActionHideButton(char *p)
  411. {
  412.    if (!p)
  413.      HideButton(mode.button);
  414.    else
  415.      HideButton(FindItem(p,LIST_TYPE_BUTTON));
  416. }
  417.  
  418. void ActionDeleteButton(char *p)
  419. {
  420.    if (!p)
  421.      {
  422.          if (!mode.button) return;
  423.          DelItem(mode.button->name,LIST_TYPE_BUTTON);
  424.          FreeButton(mode.button);
  425.          mode.button=NULL;
  426.      }
  427.    else
  428.      {
  429.          Button *b;
  430.          
  431.          b=DelItem(p,LIST_TYPE_BUTTON);
  432.          FreeButton(b);
  433.          mode.button=NULL;
  434.      }
  435. }
  436.  
  437. void ActionShowButtonToggle(char *p)
  438. {
  439.    if (!p)
  440.      {
  441.          if (!mode.button) return;
  442.          if (mode.button->visible)
  443.             HideButton(mode.button);
  444.          else
  445.             ShowButton(mode.button);
  446.      }
  447.    else
  448.      {
  449.          Button *b;
  450.          
  451.          b=FindItem(p,LIST_TYPE_STRIP);
  452.          if (!b) return;
  453.          if (b->visible)
  454.             HideButton(b);
  455.          else
  456.             ShowButton(b);
  457.      }
  458. }
  459.  
  460. void ActionLocateButton(char *p)
  461. {
  462. }
  463.  
  464. void ActionCallback(char *p)
  465. {
  466.    void **pp;
  467.    void (*cb)();
  468.  
  469.    if (!p) return;
  470.    pp=(void *)p;cb=(void (*)())*pp;
  471.    (*cb)();
  472. }
  473.  
  474. void ActionSliderJustiyStrip(char *p)
  475. {
  476.    if (!p) return;
  477.    if (!mode.slider) return;
  478.    SetStripJustification(FindItem(p,LIST_TYPE_STRIP),GetSliderValue(mode.slider));
  479. }
  480.  
  481. void ActionFlipStrip(char *p)
  482. {
  483.    if (p) FlipStrip((Strip *)FindItem(p,LIST_TYPE_STRIP));
  484.    else
  485.      {
  486.          if (mode.strip) FlipStrip(mode.strip);
  487.      }
  488. }
  489.  
  490.