various fixes to enable MSVC build, removed crusty old Win32 ndof code
authorMike Erwin <significant.bit@gmail.com>
Wed, 6 Jul 2011 18:50:59 +0000 (18:50 +0000)
committerMike Erwin <significant.bit@gmail.com>
Wed, 6 Jul 2011 18:50:59 +0000 (18:50 +0000)
intern/ghost/intern/GHOST_DropTargetWin32.cpp
intern/ghost/intern/GHOST_NDOFManager.h
intern/ghost/intern/GHOST_SystemWin32.cpp
intern/ghost/intern/GHOST_SystemWin32.h
source/blender/editors/space_view3d/view3d_edit.c

index 2e77da42b310068ab4a88c196e81eb66e8e3f620..99990a46c2a1dd1495e6f41d524009e04da162da 100644 (file)
@@ -33,6 +33,7 @@
  
 #include "GHOST_Debug.h"
 #include "GHOST_DropTargetWin32.h"
+#include <ShellApi.h>
 
 #ifdef GHOST_DEBUG
 // utility
index ab1ad49dea1e7268b877a52773a01d660dd3fc71..155510d6d7fe5b095a4fb40d3841d6b2f44cd252 100644 (file)
@@ -29,7 +29,7 @@
 
 // --- the following type definitions will find a home somewhere else once finished ---
 
-#define DEBUG_NDOF_MOTION
+//#define DEBUG_NDOF_MOTION
 #define DEBUG_NDOF_BUTTONS
 
 typedef enum { NDOF_UnknownDevice, NDOF_SpaceNavigator, NDOF_SpaceExplorer, NDOF_SpacePilotPro } NDOF_DeviceT;
index b9e50e43000e62ac2d831837444d307087e82e61..8f7f56eb7ff8bcf7c9b68321b17434eb14c4c711 100644 (file)
 #endif
 #endif
 
-#if 0 // shouldn't be needed...
-/*
- * According to the docs the mouse wheel message is supported from windows 98 
- * upwards. Leaving WINVER at default value, the WM_MOUSEWHEEL message and the 
- * wheel detent value are undefined.
- */
-#ifndef WM_MOUSEWHEEL
-#define WM_MOUSEWHEEL 0x020A
-#endif // WM_MOUSEWHEEL
-#ifndef WHEEL_DELTA
-#define WHEEL_DELTA 120        /* Value for rolling one detent, (old convention! MS changed it) */
-#endif // WHEEL_DELTA
-
-/* 
- * Defines for mouse buttons 4 and 5 aka xbutton1 and xbutton2.
- * MSDN: Declared in Winuser.h, include Windows.h 
- * This does not seem to work with MinGW so we define our own here.
- */
-#ifndef XBUTTON1
-#define XBUTTON1 0x0001
-#endif // XBUTTON1
-#ifndef XBUTTON2
-#define XBUTTON2 0x0002
-#endif // XBUTTON2
-#ifndef WM_XBUTTONUP
-#define WM_XBUTTONUP 524
-#endif // WM_XBUTTONUP
-#ifndef WM_XBUTTONDOWN
-#define WM_XBUTTONDOWN 523
-#endif // WM_XBUTTONDOWN
-
-#endif // ^^^ removed code
-
 #include "GHOST_Debug.h"
 #include "GHOST_DisplayManagerWin32.h"
 #include "GHOST_EventButton.h"
 #include "GHOST_EventCursor.h"
 #include "GHOST_EventKey.h"
 #include "GHOST_EventWheel.h"
-//#include "GHOST_EventNDOF.h"
 #include "GHOST_TimerTask.h"
 #include "GHOST_TimerManager.h"
 #include "GHOST_WindowManager.h"
 #define VK_MEDIA_PLAY_PAUSE    0xB3
 #endif // VK_MEDIA_PLAY_PAUSE
 
-#if 0
-/*
-       Initiates WM_INPUT messages from keyboard
-       That way GHOST can retrieve true keys
-*/
-GHOST_TInt32 GHOST_SystemWin32::initKeyboardRawInput(void)
-{
-       RAWINPUTDEVICE device = {0};
-       device.usUsagePage      = 0x01; /* usUsagePage & usUsage for keyboard*/
-       device.usUsage          = 0x06; /* http://msdn.microsoft.com/en-us/windows/hardware/gg487473.aspx */
-
-       return RegisterRawInputDevices(&device, 1, sizeof(device));
-};
-#endif
-
 static void initRawInput()
 {
        RAWINPUTDEVICE devices[2];
        memset(devices, 0, 2 * sizeof(RAWINPUTDEVICE));
 
-       // multi-axis mouse (SpaceNavigator)
+       // multi-axis mouse (SpaceNavigator, etc.)
        devices[0].usUsagePage = 0x01;
        devices[0].usUsage = 0x08;
 
@@ -414,15 +365,7 @@ GHOST_TSuccess GHOST_SystemWin32::init()
                (LPFNSETPROCESSDPIAWARE)GetProcAddress(user32, "SetProcessDPIAware");
        if (SetProcessDPIAware)
                SetProcessDPIAware();
-//     #ifdef NEED_RAW_PROC
-//             pRegisterRawInputDevices = (LPFNDLLRRID)GetProcAddress(user32, "RegisterRawInputDevices");
-//             pGetRawInputData = (LPFNDLLGRID)GetProcAddress(user32, "GetRawInputData");
-//     #else
-               FreeLibrary(user32);
-//     #endif
-
-       /*      Initiates WM_INPUT messages from keyboard */
-//     initKeyboardRawInput();
+       FreeLibrary(user32);
        initRawInput();
 
        // Determine whether this system has a high frequency performance counter. */
@@ -464,17 +407,11 @@ GHOST_TSuccess GHOST_SystemWin32::init()
 
 GHOST_TSuccess GHOST_SystemWin32::exit()
 {
-//     #ifdef NEED_RAW_PROC
-//     FreeLibrary(user32);
-//     #endif
-
        return GHOST_System::exit();
 }
 
 GHOST_TKey GHOST_SystemWin32::hardKey(GHOST_IWindow *window, RAWINPUT const& raw, int * keyDown, char * vk)
 {
-//     unsigned int size = 0;
-//     char * data;
        GHOST_TKey key = GHOST_kKeyUnknown;
 
 
@@ -757,7 +694,6 @@ GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINP
        char vk;
        GHOST_SystemWin32 * system = (GHOST_SystemWin32 *)getSystem();
        GHOST_TKey key = system->hardKey(window, raw, &keyDown, &vk);
-//     GHOST_TKey key = system->hardKey(window, wParam, lParam, &keyDown, &vk);
        GHOST_EventKey* event;
        if (key != GHOST_kKeyUnknown) {
                char ascii = '\0';
@@ -832,11 +768,9 @@ bool GHOST_SystemWin32::processNDOF(RAWINPUT const& raw)
 
                GetRawInputDeviceInfo(raw.header.hDevice, RIDI_DEVICEINFO, &info, &infoSize);
                if (info.dwType == RIM_TYPEHID)
-                       {
-                       // printf("hardware ID = %04X:%04X\n", info.hid.dwVendorId, info.hid.dwProductId);
                        m_ndofManager->setDevice(info.hid.dwVendorId, info.hid.dwProductId);
-                       }
-               else puts("<!> not a HID device... mouse/kb perhaps?");
+               else
+            puts("<!> not a HID device... mouse/kb perhaps?");
 
                firstEvent = false;
                }
@@ -845,13 +779,25 @@ bool GHOST_SystemWin32::processNDOF(RAWINPUT const& raw)
        // send motion. Mark as 'sent' so motion will always get dispatched.
        eventSent = true;
 
+#ifdef _MSC_VER
+    // using Microsoft compiler & header files
+    // they invented the RawInput API, so this version is (probably) correct
+       BYTE const* data = raw.data.hid.bRawData;
+       // struct RAWHID {
+       // DWORD dwSizeHid;
+       // DWORD dwCount;
+       // BYTE  bRawData[1];
+       // };
+#else
+       // MinGW's definition (below) doesn't agree, so we need a slight
+       // workaround until it's fixed
        BYTE const* data = &raw.data.hid.bRawData;
-       // MinGW's definition (below) doesn't agree with MSDN reference for bRawData:
-       // typedef struct tagRAWHID {
-       //      DWORD dwSizeHid;
-       //      DWORD dwCount;
-       //      BYTE bRawData; // <== isn't this s'posed to be a BYTE*?
-       // } RAWHID,*PRAWHID,*LPRAWHID;
+       // struct RAWHID {
+       // DWORD dwSizeHid;
+       // DWORD dwCount;
+       // BYTE bRawData; // <== isn't this s'posed to be a BYTE*?
+       // };
+#endif
 
        BYTE packetType = data[0];
        switch (packetType)
@@ -1241,30 +1187,6 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                         * In GHOST, we let DefWindowProc call the timer callback.
                                         */
                                        break;
-#if 0 // old NDOF code
-                               case WM_BLND_NDOF_AXIS:
-                                       {
-                                               GHOST_TEventNDOFData ndofdata;
-                                               system->m_ndofManager->GHOST_NDOFGetDatas(ndofdata);
-                                               system->m_eventManager->
-                                                       pushEvent(new GHOST_EventNDOF(
-                                                               system->getMilliSeconds(), 
-                                                               GHOST_kEventNDOFMotion, 
-                                                               window, ndofdata));
-                                       }
-                                       break;
-                               case WM_BLND_NDOF_BTN:
-                                       {
-                                               GHOST_TEventNDOFData ndofdata;
-                                               system->m_ndofManager->GHOST_NDOFGetDatas(ndofdata);
-                                               system->m_eventManager->
-                                                       pushEvent(new GHOST_EventNDOF(
-                                                               system->getMilliSeconds(), 
-                                                               GHOST_kEventNDOFButton, 
-                                                               window, ndofdata));
-                                       }
-                                       break;
-#endif // old NDOF code
                        }
                }
                else {
@@ -1284,13 +1206,6 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                GHOST_PRINT("GHOST_SystemWin32::wndProc: event without window\n")
        }
 
-//     if (event) {
-//             system->pushEvent(event);
-//     }
-//     else {
-//             lResult = ::DefWindowProc(hwnd, msg, wParam, lParam);
-//     }
-
        if (event) {
                system->pushEvent(event);
                eventHandled = true;
index dae8bf9a31a56750fbae39c80ef837a46563e4fb..c5dff27dace1b98206fb0e28c0d303ed09dd621e 100644 (file)
@@ -38,7 +38,6 @@
 #error WIN32 only!
 #endif // WIN32
 
-//#undef _WIN32_WINNT
 #define _WIN32_WINNT 0x501 // require Windows XP or newer
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #      define __int64 long long
 #endif
 
-/* RawInput definitions should not be needed, due to WinXP requirement
-
-#ifndef WM_INPUT
-#define WM_INPUT 0x00FF
-#endif 
-#ifndef RID_INPUT
-#define RID_INPUT 0x10000003
-#endif
-#ifndef RIM_INPUTSINK
-#define RIM_INPUTSINK 0x1
-#endif
-#ifndef RI_KEY_BREAK
-#define RI_KEY_BREAK 0x1
-#endif
-#ifndef RI_KEY_E0
-#define RI_KEY_E0 0x2
-#endif
-#ifndef RI_KEY_E1
-#define RI_KEY_E1 0x4
-#endif
-#ifndef RIM_TYPEMOUSE
-#define RIM_TYPEMOUSE          0x0
-#define RIM_TYPEKEYBOARD       0x1
-#define RIM_TYPEHID                    0x2
-
-typedef struct tagRAWINPUTDEVICE {
-       USHORT usUsagePage;
-       USHORT usUsage;
-       DWORD dwFlags;
-       HWND hwndTarget;
-} RAWINPUTDEVICE;
-
-typedef struct tagRAWINPUTHEADER {
-       DWORD dwType;
-       DWORD dwSize;
-       HANDLE hDevice;
-       WPARAM wParam;
-} RAWINPUTHEADER;
-
-typedef struct tagRAWMOUSE {
-       USHORT usFlags;
-       union {
-               ULONG ulButtons;
-               struct  {
-                       USHORT  usButtonFlags;
-                       USHORT  usButtonData;
-               };
-       };
-       ULONG   ulRawButtons;
-       LONG    lLastX;
-       LONG    lLastY;
-       ULONG   ulExtraInformation;
-} RAWMOUSE;
-
-typedef struct tagRAWKEYBOARD {
-       USHORT  MakeCode;
-       USHORT  Flags;
-       USHORT  Reserved;
-       USHORT  VKey;
-       UINT    Message;
-       ULONG   ExtraInformation;
-} RAWKEYBOARD;
-
-typedef struct tagRAWHID {
-       DWORD   dwSizeHid;
-       DWORD   dwCount;
-       BYTE    bRawData[1];
-} RAWHID;
-
-typedef struct tagRAWINPUT {
-       RAWINPUTHEADER header;
-       union {
-               RAWMOUSE        mouse;
-               RAWKEYBOARD keyboard;
-               RAWHID      hid;
-       } data;
-} RAWINPUT;
-
-DECLARE_HANDLE(HRAWINPUT);
-#endif
-
-#ifdef FREE_WINDOWS
-#define NEED_RAW_PROC
-typedef BOOL (WINAPI * LPFNDLLRRID)(RAWINPUTDEVICE*,UINT, UINT);
-
-typedef UINT (WINAPI * LPFNDLLGRID)(HRAWINPUT, UINT, LPVOID, PUINT, UINT);
-#define GetRawInputData(hRawInput, uiCommand, pData, pcbSize, cbSizeHeader) ((pGetRawInputData)?pGetRawInputData(hRawInput, uiCommand, pData, pcbSize, cbSizeHeader):(UINT)-1)
-#endif
-*/
-
 class GHOST_EventButton;
 class GHOST_EventCursor;
 class GHOST_EventKey;
@@ -425,11 +334,6 @@ protected:
         */
        static LRESULT WINAPI s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
 
-       /**
-        * Initiates WM_INPUT messages from keyboard 
-        */
-//     GHOST_TInt32 initKeyboardRawInput(void);
-
        /**
  * Toggles console
  * @action     0 - Hides
@@ -458,15 +362,6 @@ protected:
 
        /** Console status */
        int m_consoleStatus;
-
-       /** handle for user32.dll*/
-//     HMODULE user32;
-//     #ifdef NEED_RAW_PROC
-//     /* pointer to RegisterRawInputDevices function */
-//     LPFNDLLRRID pRegisterRawInputDevices;
-//     /* pointer to GetRawInputData function */
-//     LPFNDLLGRID pGetRawInputData;
-//     #endif
 };
 
 inline void GHOST_SystemWin32::retrieveModifierKeys(GHOST_ModifierKeys& keys) const
@@ -500,4 +395,3 @@ inline void GHOST_SystemWin32::handleKeyboardChange(void)
        }
 }
 #endif // _GHOST_SYSTEM_WIN32_H_
-
index 5a0c233edfafa99dddc6516c79476eddc0f4a49a..2d8c14b29f37cd24b692bb00a53ff41bf1cb5075 100644 (file)
@@ -1002,7 +1002,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event)
                /* TODO: replace such guesswork with a flag or field from the NDOF manager */
                ndof->dt = dt = 0.0125f;
 
-       #define DEBUG_NDOF_MOTION
+       //#define DEBUG_NDOF_MOTION
        #ifdef DEBUG_NDOF_MOTION
        printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n",
                ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt);