home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Enigma Amiga Life 109
/
EnigmaAmiga109CD.iso
/
software
/
varie
/
freewheel
/
cxcustom.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-12-29
|
6KB
|
248 lines
#include <exec/types.h>
#include <devices/inputevent.h>
#include <libraries/commodities.h>
#include <intuition/newmouse.h>
#include <intuition/intuitionbase.h>
#include <intuition/screens.h>
#include <graphics/clip.h>
#include <graphics/layers.h>
#include <clib/exec_protos.h>
#include <clib/commodities_protos.h>
#include <clib/alib_protos.h>
#include "WheelMouse.h"
#include "Scroll.h"
#include "Cx.h"
#include "RawKey.h"
#include "CxCustom.h"
extern struct IntuitionBase *IntuitionBase;
extern struct WheelMouseContext *MyWM;
extern struct CxContext *Cx;
int AddIntAtomic(int *a,int v);
void HandleClickToFront(struct InputEvent *ie);
BOOL InWindowBorder(struct Window *win);
void CxDepthArrange(int dy)
{
struct Window *win;
if(win=WindowUnderPointer())
{
if(win->Flags&WFLG_DEPTHGADGET)
{
if(dy<0)
WindowToBack(win);
else
WindowToFront(win);
}
}
}
void CxCustomRoutine(CxMsg *msg,CxObj *obj)
{
static int xrem=0,yrem=0,lmb;
int x,y,dx,dy,msx,msy;
BOOL send=FALSE;
struct InputEvent *e=CxMsgData(msg);
msx=MyWM->MouseSpeed;
msy=MyWM->MouseSpeed;
dx=dy=0;
if(((MyWM->ButtonState&1)&&(MyWM->MMBMode==ShiftClick))
||((MyWM->ButtonState&2)&&(MyWM->FourthButtonMode==ShiftClick)))
{
e->ie_Qualifier&=~IEQUALIFIER_MIDBUTTON;
e->ie_Qualifier|=IEQUALIFIER_LEFTBUTTON|IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT;
}
switch(e->ie_Class)
{
case IECLASS_RAWMOUSE:
x=e->ie_X; y=e->ie_Y;
if(msx>100)
if(x<3 && x>-3)
msx=100;
if(msy>100)
if(y<3 && y>-3)
msy=100;
x=e->ie_X*msx+xrem; xrem=x; x/=100; xrem-=x*100; e->ie_X=x;
y=e->ie_Y*msy+yrem; yrem=y; y/=100; yrem-=y*100; e->ie_Y=y;
switch(e->ie_Code)
{
case IECODE_MBUTTON:
MyWM->ButtonState|=1;
switch(MyWM->MMBMode)
{
case Shift:
case ShiftDepth:
e->ie_Code=RK_LShift;
e->ie_Class=IECLASS_RAWKEY;
break;
case ShiftClick:
e->ie_Code=IECODE_LBUTTON;
e->ie_Qualifier=IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT;
break;
case CycleScreens:
if(MyWM->ButtonState&1)
ScreenToBack(IntuitionBase->FirstScreen);
break;
}
break;
case IECODE_MBUTTON|IECODE_UP_PREFIX:
MyWM->ButtonState&=~1;
switch(MyWM->MMBMode)
{
case Shift:
case ShiftDepth:
e->ie_Class=IECLASS_RAWKEY;
e->ie_Code=RK_LShift|IECODE_UP_PREFIX;
break;
case ShiftClick:
e->ie_Code=IECODE_UP_PREFIX|IECODE_LBUTTON;
e->ie_Qualifier=IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT;
break;
}
break;
case IECODE_LBUTTON:
if(MyWM->ClickToFront||MyWM->ClickToBack)
HandleClickToFront(e);
break;
}
case IECLASS_RAWKEY:
switch(e->ie_Code)
{
case NM_BUTTON_FOURTH:
MyWM->ButtonState|=2;
switch(MyWM->FourthButtonMode)
{
case ShiftClick:
e->ie_Code=IECODE_LBUTTON;
e->ie_Qualifier=IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT;
break;
case CycleScreens:
if(MyWM->ButtonState&1)
ScreenToBack(IntuitionBase->FirstScreen);
break;
}
break;
case NM_BUTTON_FOURTH|IECODE_UP_PREFIX:
if(MyWM->FourthButtonMode==ShiftClick)
{
e->ie_Code=IECODE_UP_PREFIX|IECODE_LBUTTON;
e->ie_Qualifier=IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT;
}
MyWM->ButtonState&=~2;
break;
case NM_WHEEL_UP:
dy=-1;
break;
case NM_WHEEL_DOWN:
dy=1;
break;
case NM_WHEEL_LEFT:
dx=-1;
break;
case NM_WHEEL_RIGHT:
dx=1;
break;
}
if(dx||dy)
{
if(dy&&(MyWM->ButtonState&1)&&((MyWM->MMBMode==DepthArrange)||(MyWM->MMBMode==ShiftDepth)))
{
CxDepthArrange(dy);
MyWM->ButtonState&=~1;
}
else if(dy&&(MyWM->ButtonState&2)&&((MyWM->FourthButtonMode==DepthArrange)||(MyWM->FourthButtonMode==ShiftDepth)))
{
CxDepthArrange(dy);
MyWM->ButtonState&=~2;
}
else
{
/* As long as this addition is atomic, it is safe for the main
task to read the variables and this task to write them,
without semaphore protection. The main task will read the
value, and then subtract the value it has just read (again
with an atomic operation). */
AddIntAtomic(&MyWM->ScrollY,dy);
AddIntAtomic(&MyWM->ScrollX,dx);
Signal(MyWM->MainTask,MyWM->Signals);
}
}
break;
}
if(((MyWM->MMBMode==Shift)||(MyWM->MMBMode==ShiftDepth))&&(MyWM->ButtonState&1))
{
e->ie_Qualifier|=IEQUALIFIER_LSHIFT;
e->ie_Qualifier&=~IEQUALIFIER_MIDBUTTON;
}
if(((MyWM->FourthButtonMode==Shift)||(MyWM->FourthButtonMode==ShiftDepth))&&(MyWM->ButtonState&2))
e->ie_Qualifier|=IEQUALIFIER_LSHIFT;
}
void HandleClickToFront(struct InputEvent *ie)
{
static struct Window *win=0,*lastwin=0;
static long secs=0,microsecs=0,count=0;
win=WindowUnderPointer();
if(InWindowBorder(win))
{
if((count==1) && (win==lastwin) && (DoubleClick(secs,microsecs,ie->ie_TimeStamp.tv_secs,ie->ie_TimeStamp.tv_micro)))
{
struct Window *topwin=NULL;
if(win->WScreen->LayerInfo.top_layer)
topwin=win->WScreen->LayerInfo.top_layer->Window;
if((win==topwin)&&(MyWM->ClickToBack))
WindowToBack(win);
else
WindowToFront(win);
count=0;
}
else
{
count=1; lastwin=win;
secs=ie->ie_TimeStamp.tv_secs;
microsecs=ie->ie_TimeStamp.tv_micro;
}
}
}
BOOL InWindowBorder(struct Window *win)
{
int x,y;
if(!win)
return(FALSE);
x=win->MouseX; y=win->MouseY;
if((win->Flags&WFLG_BORDERLESS)&&!(win->Flags&WFLG_BACKDROP))
{
if((x>0)&&(y>0)&&(x<win->Width)&&(y<win->Height))
return(TRUE);
}
if(x<win->BorderLeft)
return(TRUE);
if(y<win->BorderTop)
return(TRUE);
if(x>(win->Width-win->BorderRight-1))
return(TRUE);
if(y>(win->Height-win->BorderBottom-1))
return(TRUE);
return(FALSE);
}