Vitaliy Margolen : dinput: Move SetCooperativeLevel into base class.
Alexandre Julliard
julliard at wine.codeweavers.com
Tue Oct 17 06:12:30 CDT 2006
Module: wine
Branch: master
Commit: 1dae4c683264349da217b08ee21b7fe337c6d070
URL: http://source.winehq.org/git/wine.git/?a=commit;h=1dae4c683264349da217b08ee21b7fe337c6d070
Author: Vitaliy Margolen <wine-patch at kievinfo.com>
Date: Sun Oct 15 11:30:07 2006 -0600
dinput: Move SetCooperativeLevel into base class.
---
dlls/dinput/device.c | 41 +++++++++++++++++++++++----
dlls/dinput/device_private.h | 2 +
dlls/dinput/mouse.c | 63 +++++++-----------------------------------
3 files changed, 46 insertions(+), 60 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index d10500b..7ba7177 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -463,15 +463,42 @@ HRESULT WINAPI IDirectInputDevice2AImpl_
return DI_OK;
}
+/******************************************************************************
+ * SetCooperativeLevel
+ *
+ * Set cooperative level and the source window for the events.
+ */
HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
- LPDIRECTINPUTDEVICE8A iface,HWND hwnd,DWORD dwflags
-) {
+ LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
+{
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
- TRACE("(this=%p,%p,0x%08x)\n", This, hwnd, dwflags);
- if (TRACE_ON(dinput)) {
- TRACE(" cooperative level : ");
- _dump_cooperativelevel_DI(dwflags);
- }
+
+ TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
+ TRACE(" cooperative level : ");
+ _dump_cooperativelevel_DI(dwflags);
+
+ if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
+ (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
+ (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
+ (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
+ return DIERR_INVALIDPARAM;
+
+ if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
+ hwnd = GetDesktopWindow();
+
+ if (!hwnd) return E_HANDLE;
+
+ /* For security reasons native does not allow exclusive background level
+ for mouse and keyboard only */
+ if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
+ (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
+ IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
+ return DIERR_UNSUPPORTED;
+
+ /* Store the window which asks for the mouse */
+ This->win = hwnd;
+ This->dwCoopLevel = dwflags;
+
return DI_OK;
}
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h
index e2bc197..bf787a5 100644
--- a/dlls/dinput/device_private.h
+++ b/dlls/dinput/device_private.h
@@ -34,6 +34,8 @@ struct IDirectInputDevice2AImpl
LONG ref;
GUID guid;
HANDLE hEvent;
+ DWORD dwCoopLevel;
+ HWND win;
};
/* Routines to do DataFormat / WineFormat conversions */
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index a596c7f..6e22c1c 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -124,8 +124,6 @@ struct SysMouseImpl
LONG prevX, prevY;
/* These are used in case of relative -> absolute transitions */
POINT org_coords;
- HWND win;
- DWORD dwCoopLevel;
POINT mapped_center;
DWORD win_centerX, win_centerY;
LPDIDEVICEOBJECTDATA data_queue;
@@ -250,6 +248,7 @@ static SysMouseImpl *alloc_device(REFGUI
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl));
newDevice->base.lpVtbl = mvt;
newDevice->base.ref = 1;
+ newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
InitializeCriticalSection(&(newDevice->crit));
@@ -261,7 +260,6 @@ static SysMouseImpl *alloc_device(REFGUI
newDevice->wine_df->internal_format_size = Wine_InternalMouseFormat.dwDataSize;
newDevice->wine_df->dt = NULL;
newDevice->dinput = dinput;
- newDevice->dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
return newDevice;
}
@@ -344,47 +342,6 @@ static ULONG WINAPI SysMouseAImpl_Releas
return 0;
}
-
-/******************************************************************************
- * SetCooperativeLevel : store the window in which we will do our
- * grabbing.
- */
-static HRESULT WINAPI SysMouseAImpl_SetCooperativeLevel(
- LPDIRECTINPUTDEVICE8A iface,HWND hwnd,DWORD dwflags
-)
-{
- SysMouseImpl *This = (SysMouseImpl *)iface;
-
- TRACE("(this=%p,%p,0x%08x)\n", This, hwnd, dwflags);
-
- if (TRACE_ON(dinput)) {
- TRACE(" cooperative level : ");
- _dump_cooperativelevel_DI(dwflags);
- }
-
- if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
- (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
- (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
- (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
- return DIERR_INVALIDPARAM;
-
- if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
- hwnd = GetDesktopWindow();
-
- if (!hwnd) return E_HANDLE;
-
- if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND) {
- return DIERR_UNSUPPORTED;
- }
-
- /* Store the window which asks for the mouse */
- This->win = hwnd;
- This->dwCoopLevel = dwflags;
-
- return DI_OK;
-}
-
-
/******************************************************************************
* SetDataFormat : the application can choose the format of the data
* the device driver sends back with GetDeviceState.
@@ -430,7 +387,7 @@ static LRESULT CALLBACK dinput_mouse_hoo
if (code != HC_ACTION) return CallNextHookEx( 0, code, wparam, lparam );
EnterCriticalSection(&(This->crit));
- dwCoop = This->dwCoopLevel;
+ dwCoop = This->base.dwCoopLevel;
if (wparam == WM_MOUSEMOVE) {
if (This->absolute) {
@@ -553,7 +510,7 @@ static BOOL dinput_window_check(SysMouse
DWORD centerX, centerY;
/* make sure the window hasn't moved */
- if(!GetWindowRect(This->win, &rect))
+ if(!GetWindowRect(This->base.win, &rect))
return FALSE;
centerX = (rect.right - rect.left) / 2;
centerY = (rect.bottom - rect.top ) / 2;
@@ -563,7 +520,7 @@ static BOOL dinput_window_check(SysMouse
}
This->mapped_center.x = This->win_centerX;
This->mapped_center.y = This->win_centerY;
- MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
+ MapWindowPoints(This->base.win, HWND_DESKTOP, &This->mapped_center, 1);
return TRUE;
}
@@ -605,12 +562,12 @@ static HRESULT WINAPI SysMouseAImpl_Acqu
This->m_state.rgbButtons[2] = GetKeyState(VK_MBUTTON) & 0x80;
/* Install our mouse hook */
- if (This->dwCoopLevel & DISCL_EXCLUSIVE)
+ if (This->base.dwCoopLevel & DISCL_EXCLUSIVE)
ShowCursor(FALSE); /* hide cursor */
set_dinput_hook(WH_MOUSE_LL, dinput_mouse_hook);
/* Get the window dimension and find the center */
- GetWindowRect(This->win, &rect);
+ GetWindowRect(This->base.win, &rect);
This->win_centerX = (rect.right - rect.left) / 2;
This->win_centerY = (rect.bottom - rect.top ) / 2;
@@ -618,7 +575,7 @@ static HRESULT WINAPI SysMouseAImpl_Acqu
if (This->absolute == 0) {
This->mapped_center.x = This->win_centerX;
This->mapped_center.y = This->win_centerY;
- MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
+ MapWindowPoints(This->base.win, HWND_DESKTOP, &This->mapped_center, 1);
TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
SetCursorPos( This->mapped_center.x, This->mapped_center.y );
This->last_warped = GetCurrentTime();
@@ -647,7 +604,7 @@ static HRESULT WINAPI SysMouseAImpl_Unac
}
set_dinput_hook(WH_MOUSE_LL, NULL);
- if (This->dwCoopLevel & DISCL_EXCLUSIVE)
+ if (This->base.dwCoopLevel & DISCL_EXCLUSIVE)
ShowCursor(TRUE); /* show cursor */
/* No more locks */
@@ -1091,7 +1048,7 @@ static const IDirectInputDevice8AVtbl Sy
SysMouseAImpl_GetDeviceData,
SysMouseAImpl_SetDataFormat,
IDirectInputDevice2AImpl_SetEventNotification,
- SysMouseAImpl_SetCooperativeLevel,
+ IDirectInputDevice2AImpl_SetCooperativeLevel,
IDirectInputDevice2AImpl_GetObjectInfo,
SysMouseAImpl_GetDeviceInfo,
IDirectInputDevice2AImpl_RunControlPanel,
@@ -1133,7 +1090,7 @@ static const IDirectInputDevice8WVtbl Sy
XCAST(GetDeviceData)SysMouseAImpl_GetDeviceData,
XCAST(SetDataFormat)SysMouseAImpl_SetDataFormat,
XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
- XCAST(SetCooperativeLevel)SysMouseAImpl_SetCooperativeLevel,
+ XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
IDirectInputDevice2WImpl_GetObjectInfo,
SysMouseWImpl_GetDeviceInfo,
XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
More information about the wine-cvs
mailing list