home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / varie / freewheel / cxcustom.c < prev    next >
C/C++ Source or Header  |  1999-12-29  |  6KB  |  248 lines

  1.  
  2. #include <exec/types.h>
  3. #include <devices/inputevent.h>
  4. #include <libraries/commodities.h>
  5. #include <intuition/newmouse.h>
  6. #include <intuition/intuitionbase.h>
  7. #include <intuition/screens.h>
  8. #include <graphics/clip.h>
  9. #include <graphics/layers.h>
  10.  
  11. #include <clib/exec_protos.h>
  12. #include <clib/commodities_protos.h>
  13. #include <clib/alib_protos.h>
  14.  
  15. #include "WheelMouse.h"
  16. #include "Scroll.h"
  17. #include "Cx.h"
  18. #include "RawKey.h"
  19.  
  20. #include "CxCustom.h"
  21.  
  22. extern struct IntuitionBase *IntuitionBase;
  23. extern struct WheelMouseContext *MyWM;
  24. extern struct CxContext *Cx;
  25.  
  26. int AddIntAtomic(int *a,int v);
  27.  
  28. void HandleClickToFront(struct InputEvent *ie);
  29. BOOL InWindowBorder(struct Window *win);
  30.  
  31.  
  32. void CxDepthArrange(int dy)
  33. {
  34.   struct Window *win;
  35.   if(win=WindowUnderPointer())
  36.   {
  37.     if(win->Flags&WFLG_DEPTHGADGET)
  38.     {
  39.       if(dy<0)
  40.         WindowToBack(win);
  41.       else
  42.         WindowToFront(win);
  43.     }
  44.   }
  45. }
  46.  
  47.  
  48. void CxCustomRoutine(CxMsg *msg,CxObj *obj)
  49. {
  50.   static int xrem=0,yrem=0,lmb;
  51.   int x,y,dx,dy,msx,msy;
  52.   BOOL send=FALSE;
  53.   struct InputEvent *e=CxMsgData(msg);
  54.  
  55.   msx=MyWM->MouseSpeed;
  56.   msy=MyWM->MouseSpeed;
  57.  
  58.   dx=dy=0;
  59.  
  60.   if(((MyWM->ButtonState&1)&&(MyWM->MMBMode==ShiftClick))
  61.    ||((MyWM->ButtonState&2)&&(MyWM->FourthButtonMode==ShiftClick)))
  62.   {
  63.     e->ie_Qualifier&=~IEQUALIFIER_MIDBUTTON;
  64.     e->ie_Qualifier|=IEQUALIFIER_LEFTBUTTON|IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT;
  65.   }
  66.  
  67.   switch(e->ie_Class)
  68.   {
  69.     case IECLASS_RAWMOUSE:
  70.       x=e->ie_X; y=e->ie_Y;
  71.       if(msx>100)
  72.         if(x<3 && x>-3)
  73.           msx=100;
  74.       if(msy>100)
  75.         if(y<3 && y>-3)
  76.           msy=100;
  77.         x=e->ie_X*msx+xrem; xrem=x; x/=100; xrem-=x*100; e->ie_X=x;
  78.         y=e->ie_Y*msy+yrem; yrem=y; y/=100; yrem-=y*100; e->ie_Y=y;
  79.       switch(e->ie_Code)
  80.       {
  81.         case IECODE_MBUTTON:
  82.           MyWM->ButtonState|=1;
  83.           switch(MyWM->MMBMode)
  84.           {
  85.             case Shift:
  86.             case ShiftDepth:
  87.               e->ie_Code=RK_LShift;
  88.               e->ie_Class=IECLASS_RAWKEY;
  89.               break;
  90.             case ShiftClick:
  91.               e->ie_Code=IECODE_LBUTTON;
  92.               e->ie_Qualifier=IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT;
  93.               break;
  94.             case CycleScreens:
  95.               if(MyWM->ButtonState&1)
  96.                 ScreenToBack(IntuitionBase->FirstScreen);
  97.               break;
  98.           }
  99.           break;
  100.         case IECODE_MBUTTON|IECODE_UP_PREFIX:
  101.           MyWM->ButtonState&=~1;
  102.           switch(MyWM->MMBMode)
  103.           {
  104.             case Shift:
  105.             case ShiftDepth:
  106.               e->ie_Class=IECLASS_RAWKEY;
  107.               e->ie_Code=RK_LShift|IECODE_UP_PREFIX;
  108.               break;
  109.             case ShiftClick:
  110.               e->ie_Code=IECODE_UP_PREFIX|IECODE_LBUTTON;
  111.               e->ie_Qualifier=IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT;
  112.               break;
  113.           }
  114.           break;
  115.         case IECODE_LBUTTON:
  116.           if(MyWM->ClickToFront||MyWM->ClickToBack)
  117.             HandleClickToFront(e);
  118.           break;
  119.       }
  120.     case IECLASS_RAWKEY:
  121.       switch(e->ie_Code)
  122.       {
  123.         case NM_BUTTON_FOURTH:
  124.           MyWM->ButtonState|=2;
  125.           switch(MyWM->FourthButtonMode)
  126.           {
  127.             case ShiftClick:
  128.               e->ie_Code=IECODE_LBUTTON;
  129.               e->ie_Qualifier=IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT;
  130.               break;
  131.             case CycleScreens:
  132.               if(MyWM->ButtonState&1)
  133.                 ScreenToBack(IntuitionBase->FirstScreen);
  134.               break;
  135.           }
  136.           break;
  137.         case NM_BUTTON_FOURTH|IECODE_UP_PREFIX:
  138.           if(MyWM->FourthButtonMode==ShiftClick)
  139.           {
  140.             e->ie_Code=IECODE_UP_PREFIX|IECODE_LBUTTON;
  141.             e->ie_Qualifier=IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT;
  142.           }
  143.           MyWM->ButtonState&=~2;
  144.           break;
  145.         case NM_WHEEL_UP:
  146.           dy=-1;
  147.           break;
  148.         case NM_WHEEL_DOWN:
  149.           dy=1;
  150.           break;
  151.         case NM_WHEEL_LEFT:
  152.           dx=-1;
  153.           break;
  154.         case NM_WHEEL_RIGHT:
  155.           dx=1;
  156.           break;
  157.       }
  158.  
  159.     if(dx||dy)
  160.     {
  161.       if(dy&&(MyWM->ButtonState&1)&&((MyWM->MMBMode==DepthArrange)||(MyWM->MMBMode==ShiftDepth)))
  162.       {
  163.         CxDepthArrange(dy);
  164.         MyWM->ButtonState&=~1;
  165.       }
  166.       else if(dy&&(MyWM->ButtonState&2)&&((MyWM->FourthButtonMode==DepthArrange)||(MyWM->FourthButtonMode==ShiftDepth)))
  167.       {
  168.         CxDepthArrange(dy);
  169.         MyWM->ButtonState&=~2;
  170.       }
  171.       else
  172.       {
  173.         /* As long as this addition is atomic, it is safe for the main
  174.            task to read the variables and this task to write them,
  175.            without semaphore protection.  The main task will read the
  176.            value, and then subtract the value it has just read (again
  177.            with an atomic operation). */
  178.         AddIntAtomic(&MyWM->ScrollY,dy);
  179.         AddIntAtomic(&MyWM->ScrollX,dx);
  180.         Signal(MyWM->MainTask,MyWM->Signals);
  181.       }
  182.     }
  183.     break;
  184.   }
  185.  
  186.   if(((MyWM->MMBMode==Shift)||(MyWM->MMBMode==ShiftDepth))&&(MyWM->ButtonState&1))
  187.   {
  188.     e->ie_Qualifier|=IEQUALIFIER_LSHIFT;
  189.     e->ie_Qualifier&=~IEQUALIFIER_MIDBUTTON;
  190.   }
  191.  
  192.   if(((MyWM->FourthButtonMode==Shift)||(MyWM->FourthButtonMode==ShiftDepth))&&(MyWM->ButtonState&2))
  193.     e->ie_Qualifier|=IEQUALIFIER_LSHIFT;
  194. }
  195.  
  196.  
  197. void HandleClickToFront(struct InputEvent *ie)
  198. {
  199.   static struct Window *win=0,*lastwin=0;
  200.   static long secs=0,microsecs=0,count=0;
  201.  
  202.   win=WindowUnderPointer();
  203.   if(InWindowBorder(win))
  204.   {
  205.     if((count==1) && (win==lastwin) && (DoubleClick(secs,microsecs,ie->ie_TimeStamp.tv_secs,ie->ie_TimeStamp.tv_micro)))
  206.     {
  207.       struct Window *topwin=NULL;
  208.       if(win->WScreen->LayerInfo.top_layer)
  209.         topwin=win->WScreen->LayerInfo.top_layer->Window;
  210.       if((win==topwin)&&(MyWM->ClickToBack))
  211.         WindowToBack(win);
  212.       else
  213.         WindowToFront(win);
  214.       count=0;
  215.     }
  216.     else
  217.     {
  218.       count=1; lastwin=win;
  219.       secs=ie->ie_TimeStamp.tv_secs;
  220.       microsecs=ie->ie_TimeStamp.tv_micro;
  221.     }
  222.   }
  223. }
  224.  
  225.  
  226. BOOL InWindowBorder(struct Window *win)
  227. {
  228.   int x,y;
  229.   if(!win)
  230.     return(FALSE);
  231.   x=win->MouseX; y=win->MouseY;
  232.   if((win->Flags&WFLG_BORDERLESS)&&!(win->Flags&WFLG_BACKDROP))
  233.   {
  234.     if((x>0)&&(y>0)&&(x<win->Width)&&(y<win->Height))
  235.       return(TRUE);
  236.   }
  237.   if(x<win->BorderLeft)
  238.     return(TRUE);
  239.   if(y<win->BorderTop)
  240.     return(TRUE);
  241.   if(x>(win->Width-win->BorderRight-1))
  242.     return(TRUE);
  243.   if(y>(win->Height-win->BorderBottom-1))
  244.     return(TRUE);
  245.   return(FALSE);
  246. }
  247.  
  248.