--- np2/win9xc/mousemng.cpp 2003/10/16 17:59:21 1.1.1.1 +++ np2/win9xc/mousemng.cpp 2004/02/13 20:31:55 1.2 @@ -3,13 +3,33 @@ #include "mousemng.h" -static BYTE mouserunning = 0; -static BYTE lastmouse = 0; -static short mousex = 0; -static short mousey = 0; -static BYTE mouseb = 0xa0; +#define MOUSEMNG_RANGE 128 +typedef struct { + SINT16 x; + SINT16 y; + BYTE btn; + UINT flag; +} MOUSEMNG; + +static MOUSEMNG mousemng; + + +BYTE mousemng_getstat(SINT16 *x, SINT16 *y, int clear) { + + *x = mousemng.x; + *y = mousemng.y; + if (clear) { + mousemng.x = 0; + mousemng.y = 0; + } + return(mousemng.btn); +} + + +// ---- + static void getmaincenter(POINT *cp) { RECT rct; @@ -19,111 +39,108 @@ static void getmaincenter(POINT *cp) { cp->y = (rct.bottom + rct.top) / 2; } +static void mousecapture(BOOL capture) { -void mouseonoff(BYTE flg) { - + LONG style; POINT cp; RECT rct; - if ((lastmouse ^ flg) & 1) { - lastmouse = (flg & 1); - if (lastmouse & 1) { - ShowCursor(FALSE); - getmaincenter(&cp); - rct.left = cp.x - 200; - rct.right = cp.x + 200; - rct.top = cp.y - 200; - rct.bottom = cp.y + 200; - SetCursorPos(cp.x, cp.y); - ClipCursor(&rct); - } - else { - ShowCursor(TRUE); - ClipCursor(NULL); - } + style = GetClassLong(hWndMain, GCL_STYLE); + if (capture) { + ShowCursor(FALSE); + getmaincenter(&cp); + rct.left = cp.x - MOUSEMNG_RANGE; + rct.right = cp.x + MOUSEMNG_RANGE; + rct.top = cp.y - MOUSEMNG_RANGE; + rct.bottom = cp.y + MOUSEMNG_RANGE; + SetCursorPos(cp.x, cp.y); + ClipCursor(&rct); + style &= ~(CS_DBLCLKS); } + else { + ShowCursor(TRUE); + ClipCursor(NULL); + style |= CS_DBLCLKS; + } + SetClassLong(hWndMain, GCL_STYLE, style); } -// --------------------------------------------------------------------------- - -BYTE mouse_flag(void) { +void mousemng_initialize(void) { - return(mouserunning); + ZeroMemory(&mousemng, sizeof(mousemng)); + mousemng.btn = uPD8255A_LEFTBIT | uPD8255A_RIGHTBIT; + mousemng.flag = (1 << MOUSEPROC_SYSTEM); } +void mousemng_sync(void) { -void mouse_running(BYTE flg) { - - BYTE mf = mouserunning; + POINT p; + POINT cp; - switch(flg & 0xc0) { - case 0x00: - mf &= ~(1 << (flg & 7)); - break; - case 0x40: - mf ^= (1 << (flg & 7)); - break; - default: - mf |= (1 << (flg & 7)); - break; - } - if ((mf ^ mouserunning) & MOUSE_MASK) { - mouserunning = (mf & MOUSE_MASK); - if (mouserunning == 1) { - mouseonoff(1); - } - else { - mouseonoff(0); - } + if ((!mousemng.flag) && (GetCursorPos(&p))) { + getmaincenter(&cp); + mousemng.x += (SINT16)((p.x - cp.x) / 2); + mousemng.y += (SINT16)((p.y - cp.y) / 2); + SetCursorPos(cp.x, cp.y); } } +BOOL mousemng_buttonevent(UINT event) { -void mouse_callback(void) { - - POINT p, cp; - - if ((lastmouse & 1) && (GetCursorPos(&p))) { - getmaincenter(&cp); - mousex += (short)((p.x - cp.x) / 2); - mousey += (short)((p.y - cp.y) / 2); - SetCursorPos(cp.x, cp.y); + if (!mousemng.flag) { + switch(event) { + case MOUSEMNG_LEFTDOWN: + mousemng.btn &= ~(uPD8255A_LEFTBIT); + break; + + case MOUSEMNG_LEFTUP: + mousemng.btn |= uPD8255A_LEFTBIT; + break; + + case MOUSEMNG_RIGHTDOWN: + mousemng.btn &= ~(uPD8255A_RIGHTBIT); + break; + + case MOUSEMNG_RIGHTUP: + mousemng.btn |= uPD8255A_RIGHTBIT; + break; + } + return(TRUE); + } + else { + return(FALSE); } } +void mousemng_enable(UINT proc) { -BYTE mousemng_getstat(short *x, short *y, int clear) { + UINT bit; - *x = mousex; - *y = mousey; - if (clear) { - mousex = 0; - mousey = 0; + bit = 1 << proc; + if (mousemng.flag & bit) { + mousemng.flag &= ~bit; + if (!mousemng.flag) { + mousecapture(TRUE); + } } - return(mouseb); } +void mousemng_disable(UINT proc) { + if (!mousemng.flag) { + mousecapture(FALSE); + } + mousemng.flag |= (1 << proc); +} -BYTE mouse_btn(BYTE btn) { +void mousemng_toggle(UINT proc) { - if (!(lastmouse & 1)) { - return(0); + if (!mousemng.flag) { + mousecapture(FALSE); } - switch(btn) { - case MOUSE_LEFTDOWN: - mouseb &= 0x7f; - break; - case MOUSE_LEFTUP: - mouseb |= 0x80; - break; - case MOUSE_RIGHTDOWN: - mouseb &= 0xdf; - break; - case MOUSE_RIGHTUP: - mouseb |= 0x20; - break; + mousemng.flag ^= (1 << proc); + if (!mousemng.flag) { + mousecapture(TRUE); } - return(1); }