Merge branch 'master' into blender2.8
[blender.git] / intern / ghost / intern / GHOST_SystemWin32.cpp
index ccc90e3..625a34a 100644 (file)
@@ -240,7 +240,7 @@ GHOST_TUns64 GHOST_SystemWin32::getMilliSeconds() const
        __int64 delta = 1000 * (count - m_start);
 
        GHOST_TUns64 t = (GHOST_TUns64)(delta / m_freq);
-       return t; 
+       return t;
 }
 
 
@@ -407,7 +407,7 @@ bool GHOST_SystemWin32::processEvents(bool waitForEvent)
 #else
                        GHOST_TUns64 next = timerMgr->nextFireTime();
                        GHOST_TInt64 maxSleep = next - getMilliSeconds();
-                       
+
                        if (next == GHOST_kFireTimeNever) {
                                ::WaitMessage();
                        }
@@ -469,17 +469,17 @@ GHOST_TSuccess GHOST_SystemWin32::getModifierKeys(GHOST_ModifierKeys &keys) cons
        keys.set(GHOST_kModifierKeyLeftShift, down);
        down = HIBYTE(::GetKeyState(VK_RSHIFT)) != 0;
        keys.set(GHOST_kModifierKeyRightShift, down);
-       
+
        down = HIBYTE(::GetKeyState(VK_LMENU)) != 0;
        keys.set(GHOST_kModifierKeyLeftAlt, down);
        down = HIBYTE(::GetKeyState(VK_RMENU)) != 0;
        keys.set(GHOST_kModifierKeyRightAlt, down);
-       
+
        down = HIBYTE(::GetKeyState(VK_LCONTROL)) != 0;
        keys.set(GHOST_kModifierKeyLeftControl, down);
        down = HIBYTE(::GetKeyState(VK_RCONTROL)) != 0;
        keys.set(GHOST_kModifierKeyRightControl, down);
-       
+
        bool lwindown = HIBYTE(::GetKeyState(VK_LWIN)) != 0;
        bool rwindown = HIBYTE(::GetKeyState(VK_RWIN)) != 0;
        if (lwindown || rwindown)
@@ -512,7 +512,7 @@ GHOST_TSuccess GHOST_SystemWin32::getButtons(GHOST_Buttons &buttons) const
 GHOST_TSuccess GHOST_SystemWin32::init()
 {
        GHOST_TSuccess success = GHOST_System::init();
-       
+
        /* Disable scaling on high DPI displays on Vista */
        HMODULE
            user32 = ::LoadLibraryA("user32.dll");
@@ -542,12 +542,12 @@ GHOST_TSuccess GHOST_SystemWin32::init()
                wc.cbWndExtra = 0;
                wc.hInstance = ::GetModuleHandle(0);
                wc.hIcon = ::LoadIcon(wc.hInstance, "APPICON");
-               
+
                if (!wc.hIcon) {
                        ::LoadIcon(NULL, IDI_APPLICATION);
                }
                wc.hCursor = ::LoadCursor(0, IDC_ARROW);
-               wc.hbrBackground = 
+               wc.hbrBackground =
 #ifdef INW32_COMPISITING
                        (HBRUSH)CreateSolidBrush
 #endif
@@ -560,7 +560,7 @@ GHOST_TSuccess GHOST_SystemWin32::init()
                        success = GHOST_kFailure;
                }
        }
-       
+
        return success;
 }
 
@@ -583,7 +583,7 @@ GHOST_TKey GHOST_SystemWin32::hardKey(RAWINPUT const &raw, int *keyDown, char *v
        *keyDown = !(raw.data.keyboard.Flags & RI_KEY_BREAK) && msg != WM_KEYUP && msg != WM_SYSKEYUP;
 
        key = this->convertKey(raw.data.keyboard.VKey, raw.data.keyboard.MakeCode, (raw.data.keyboard.Flags & (RI_KEY_E1 | RI_KEY_E0)));
-       
+
        // extra handling of modifier keys: don't send repeats out from GHOST
        if (key >= GHOST_kKeyLeftShift && key <= GHOST_kKeyRightAlt) {
                bool changed = false;
@@ -628,7 +628,7 @@ GHOST_TKey GHOST_SystemWin32::hardKey(RAWINPUT const &raw, int *keyDown, char *v
                        default:
                                break;
                }
-               
+
                if (changed) {
                        modifiers.set(modifier, (bool)*keyDown);
                        system->storeModifierKeys(modifiers);
@@ -637,7 +637,7 @@ GHOST_TKey GHOST_SystemWin32::hardKey(RAWINPUT const &raw, int *keyDown, char *v
                        key = GHOST_kKeyUnknown;
                }
        }
-       
+
 
        if (vk) *vk = raw.data.keyboard.VKey;
 
@@ -682,7 +682,7 @@ GHOST_TKey GHOST_SystemWin32::convertKey(short vKey, short scanCode, short exten
                switch (vKey) {
                        case VK_RETURN:
                                key = (extend) ? GHOST_kKeyNumpadEnter : GHOST_kKeyEnter; break;
-                       
+
                        case VK_BACK:     key = GHOST_kKeyBackSpace;        break;
                        case VK_TAB:      key = GHOST_kKeyTab;              break;
                        case VK_ESCAPE:   key = GHOST_kKeyEsc;              break;
@@ -782,7 +782,7 @@ GHOST_TKey GHOST_SystemWin32::convertKey(short vKey, short scanCode, short exten
                                break;
                }
        }
-       
+
        return key;
 }
 
@@ -799,7 +799,7 @@ GHOST_EventCursor *GHOST_SystemWin32::processCursorEvent(GHOST_TEventType type,
 {
        GHOST_TInt32 x_screen, y_screen;
        GHOST_SystemWin32 *system = (GHOST_SystemWin32 *) getSystem();
-       
+
        system->getCursorPosition(x_screen, y_screen);
 
        /* TODO: CHECK IF THIS IS A TABLET EVENT */
@@ -856,7 +856,7 @@ void GHOST_SystemWin32::processWheelEvent(GHOST_WindowWin32 *window, WPARAM wPar
 
        int acc = system->m_wheelDeltaAccum;
        int delta = GET_WHEEL_DELTA_WPARAM(wParam);
-       
+
        if (acc * delta < 0) {
                // scroll direction reversed.
                acc = 0;
@@ -864,7 +864,7 @@ void GHOST_SystemWin32::processWheelEvent(GHOST_WindowWin32 *window, WPARAM wPar
        acc += delta;
        int direction = (acc >= 0) ? 1 : -1;
        acc = abs(acc);
-       
+
        while (acc >= WHEEL_DELTA) {
                system->pushEvent(new GHOST_EventWheel(system->getMilliSeconds(), window, direction));
                acc -= WHEEL_DELTA;
@@ -1178,10 +1178,10 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                 */
                                case WM_DEADCHAR:
                                        /* The WM_DEADCHAR message is posted to the window with the keyboard focus when a
-                                        * WM_KEYUP message is translated by the TranslateMessage function. WM_DEADCHAR 
-                                        * specifies a character code generated by a dead key. A dead key is a key that 
-                                        * generates a character, such as the umlaut (double-dot), that is combined with 
-                                        * another character to form a composite character. For example, the umlaut-O 
+                                        * WM_KEYUP message is translated by the TranslateMessage function. WM_DEADCHAR
+                                        * specifies a character code generated by a dead key. A dead key is a key that
+                                        * generates a character, such as the umlaut (double-dot), that is combined with
+                                        * another character to form a composite character. For example, the umlaut-O
                                         * character (Ö) is generated by typing the dead key for the umlaut character, and
                                         * then typing the O key.
                                         */
@@ -1193,16 +1193,16 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                 * a dead key that is pressed while holding down the alt key.
                                 */
                                case WM_SYSCHAR:
-                                       /* The WM_SYSCHAR message is sent to the window with the keyboard focus when 
-                                        * a WM_SYSCHAR message is translated by the TranslateMessage function. 
-                                        * WM_SYSCHAR specifies the character code of a dead key - that is, 
+                                       /* The WM_SYSCHAR message is sent to the window with the keyboard focus when
+                                        * a WM_SYSCHAR message is translated by the TranslateMessage function.
+                                        * WM_SYSCHAR specifies the character code of a dead key - that is,
                                         * a dead key that is pressed while holding down the alt key.
                                         * To prevent the sound, DefWindowProc must be avoided by return
                                         */
                                        break;
                                case WM_SYSCOMMAND:
-                                       /* The WM_SYSCHAR message is sent to the window when system commands such as 
-                                        * maximize, minimize  or close the window are triggered. Also it is sent when ALT 
+                                       /* The WM_SYSCHAR message is sent to the window when system commands such as
+                                        * maximize, minimize  or close the window are triggered. Also it is sent when ALT
                                         * button is press for menu. To prevent this we must return preventing DefWindowProc.
                                         */
                                        if (wParam == SC_KEYMENU) {
@@ -1269,11 +1269,11 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                        break;
                                case WM_MOUSEWHEEL:
                                {
-                                       /* The WM_MOUSEWHEEL message is sent to the focus window 
-                                        * when the mouse wheel is rotated. The DefWindowProc 
+                                       /* The WM_MOUSEWHEEL message is sent to the focus window
+                                        * when the mouse wheel is rotated. The DefWindowProc
                                         * function propagates the message to the window's parent.
-                                        * There should be no internal forwarding of the message, 
-                                        * since DefWindowProc propagates it up the parent chain 
+                                        * There should be no internal forwarding of the message,
+                                        * since DefWindowProc propagates it up the parent chain
                                         * until it finds a window that processes it.
                                         */
 
@@ -1281,7 +1281,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                        POINT mouse_pos = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
                                        HWND mouse_hwnd = ChildWindowFromPoint(HWND_DESKTOP, mouse_pos);
                                        GHOST_WindowWin32 *mouse_window = (GHOST_WindowWin32 *)::GetWindowLongPtr(mouse_hwnd, GWLP_USERDATA);
-                                       
+
                                        processWheelEvent(mouse_window ? mouse_window : window , wParam, lParam);
                                        eventHandled = true;
 #ifdef BROKEN_PEEK_TOUCHPAD
@@ -1293,7 +1293,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                        /* The WM_SETCURSOR message is sent to a window if the mouse causes the cursor
                                         * to move within a window and mouse input is not captured.
                                         * This means we have to set the cursor shape every time the mouse moves!
-                                        * The DefWindowProc function uses this message to set the cursor to an 
+                                        * The DefWindowProc function uses this message to set the cursor to an
                                         * arrow if it is not in the client area.
                                         */
                                        if (LOWORD(lParam) == HTCLIENT) {
@@ -1301,7 +1301,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                                window->loadCursor(window->getCursorVisibility(), window->getCursorShape());
                                                // Bypass call to DefWindowProc
                                                return 0;
-                                       } 
+                                       }
                                        else {
                                                // Outside of client area show standard cursor
                                                window->loadCursor(true, GHOST_kStandardCursorDefault);
@@ -1317,10 +1317,10 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                 * that contains the cursor. If a window has captured the mouse, this message is not posted.
                                 */
                                case WM_NCHITTEST:
-                                       /* The WM_NCHITTEST message is sent to a window when the cursor moves, or 
-                                        * when a mouse button is pressed or released. If the mouse is not captured, 
-                                        * the message is sent to the window beneath the cursor. Otherwise, the message 
-                                        * is sent to the window that has captured the mouse. 
+                                       /* The WM_NCHITTEST message is sent to a window when the cursor moves, or
+                                        * when a mouse button is pressed or released. If the mouse is not captured,
+                                        * the message is sent to the window beneath the cursor. Otherwise, the message
+                                        * is sent to the window that has captured the mouse.
                                         */
                                        break;
 
@@ -1332,11 +1332,11 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                        event = processWindowEvent(GHOST_kEventWindowClose, window);
                                        break;
                                case WM_ACTIVATE:
-                                       /* The WM_ACTIVATE message is sent to both the window being activated and the window being 
-                                        * deactivated. If the windows use the same input queue, the message is sent synchronously, 
+                                       /* The WM_ACTIVATE message is sent to both the window being activated and the window being
+                                        * deactivated. If the windows use the same input queue, the message is sent synchronously,
                                         * first to the window procedure of the top-level window being deactivated, then to the window
                                         * procedure of the top-level window being activated. If the windows use different input queues,
-                                        * the message is sent asynchronously, so the window is activated immediately. 
+                                        * the message is sent asynchronously, so the window is activated immediately.
                                         */
                                {
                                        GHOST_ModifierKeys modifiers;
@@ -1353,12 +1353,12 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                        break;
                                }
                                case WM_ENTERSIZEMOVE:
-                                       /* The WM_ENTERSIZEMOVE message is sent one time to a window after it enters the moving 
-                                        * or sizing modal loop. The window enters the moving or sizing modal loop when the user 
-                                        * clicks the window's title bar or sizing border, or when the window passes the 
-                                        * WM_SYSCOMMAND message to the DefWindowProc function and the wParam parameter of the 
-                                        * message specifies the SC_MOVE or SC_SIZE value. The operation is complete when 
-                                        * DefWindowProc returns. 
+                                       /* The WM_ENTERSIZEMOVE message is sent one time to a window after it enters the moving
+                                        * or sizing modal loop. The window enters the moving or sizing modal loop when the user
+                                        * clicks the window's title bar or sizing border, or when the window passes the
+                                        * WM_SYSCOMMAND message to the DefWindowProc function and the wParam parameter of the
+                                        * message specifies the SC_MOVE or SC_SIZE value. The operation is complete when
+                                        * DefWindowProc returns.
                                         */
                                        window->m_inLiveResize = 1;
                                        break;
@@ -1366,11 +1366,11 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                        window->m_inLiveResize = 0;
                                        break;
                                case WM_PAINT:
-                                       /* An application sends the WM_PAINT message when the system or another application 
+                                       /* An application sends the WM_PAINT message when the system or another application
                                         * makes a request to paint a portion of an application's window. The message is sent
-                                        * when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage 
-                                        * function when the application obtains a WM_PAINT message by using the GetMessage or 
-                                        * PeekMessage function. 
+                                        * when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage
+                                        * function when the application obtains a WM_PAINT message by using the GetMessage or
+                                        * PeekMessage function.
                                         */
                                        if (!window->m_inLiveResize) {
                                                event = processWindowEvent(GHOST_kEventWindowUpdate, window);
@@ -1381,10 +1381,10 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                        }
                                        break;
                                case WM_GETMINMAXINFO:
-                                       /* The WM_GETMINMAXINFO message is sent to a window when the size or 
-                                        * position of the window is about to change. An application can use 
-                                        * this message to override the window's default maximized size and 
-                                        * position, or its default minimum or maximum tracking size. 
+                                       /* The WM_GETMINMAXINFO message is sent to a window when the size or
+                                        * position of the window is about to change. An application can use
+                                        * this message to override the window's default maximized size and
+                                        * position, or its default minimum or maximum tracking size.
                                         */
                                        processMinMaxInfo((MINMAXINFO *) lParam);
                                        /* Let DefWindowProc handle it. */
@@ -1392,9 +1392,9 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                case WM_SIZING:
                                case WM_SIZE:
                                        /* The WM_SIZE message is sent to a window after its size has changed.
-                                        * The WM_SIZE and WM_MOVE messages are not sent if an application handles the 
+                                        * The WM_SIZE and WM_MOVE messages are not sent if an application handles the
                                         * WM_WINDOWPOSCHANGED message without calling DefWindowProc. It is more efficient
-                                        * to perform any move or size change processing during the WM_WINDOWPOSCHANGED 
+                                        * to perform any move or size change processing during the WM_WINDOWPOSCHANGED
                                         * message without calling DefWindowProc.
                                         */
                                        /* we get first WM_SIZE before we fully init. So, do not dispatch before we continiously resizng */
@@ -1415,10 +1415,10 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                         * and, if needed, change its size or position.
                                         */
                                case WM_MOVE:
-                                       /* The WM_SIZE and WM_MOVE messages are not sent if an application handles the 
+                                       /* The WM_SIZE and WM_MOVE messages are not sent if an application handles the
                                         * WM_WINDOWPOSCHANGED message without calling DefWindowProc. It is more efficient
-                                        * to perform any move or size change processing during the WM_WINDOWPOSCHANGED 
-                                        * message without calling DefWindowProc. 
+                                        * to perform any move or size change processing during the WM_WINDOWPOSCHANGED
+                                        * message without calling DefWindowProc.
                                         */
                                        /* see WM_SIZE comment*/
                                        if (window->m_inLiveResize) {
@@ -1487,13 +1487,13 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                 * that all child windows still exist.
                                 */
                                case WM_NCDESTROY:
-                                       /* The WM_NCDESTROY message informs a window that its nonclient area is being destroyed. The 
+                                       /* The WM_NCDESTROY message informs a window that its nonclient area is being destroyed. The
                                         * DestroyWindow function sends the WM_NCDESTROY message to the window following the WM_DESTROY
-                                        * message. WM_DESTROY is used to free the allocated memory object associated with the window. 
+                                        * message. WM_DESTROY is used to free the allocated memory object associated with the window.
                                         */
                                        break;
                                case WM_KILLFOCUS:
-                                       /* The WM_KILLFOCUS message is sent to a window immediately before it loses the keyboard focus. 
+                                       /* The WM_KILLFOCUS message is sent to a window immediately before it loses the keyboard focus.
                                         * We want to prevent this if a window is still active and it loses focus to nowhere*/
                                        if (!wParam && hwnd == ::GetActiveWindow())
                                                ::SetFocus(hwnd);
@@ -1526,7 +1526,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                         * when a timer expires. You can process the message by providing a WM_TIMER
                                         * case in the window procedure. Otherwise, the default window procedure will
                                         * call the TimerProc callback function specified in the call to the SetTimer
-                                        * function used to install the timer. 
+                                        * function used to install the timer.
                                         *
                                         * In GHOST, we let DefWindowProc call the timer callback.
                                         */
@@ -1565,7 +1565,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
 GHOST_TUns8 *GHOST_SystemWin32::getClipboard(bool selection) const
 {
        char *temp_buff;
-       
+
        if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL) ) {
                wchar_t *buffer;
                HANDLE hData = GetClipboardData(CF_UNICODETEXT);
@@ -1578,14 +1578,14 @@ GHOST_TUns8 *GHOST_SystemWin32::getClipboard(bool selection) const
                        CloseClipboard();
                        return NULL;
                }
-               
+
                temp_buff = alloc_utf_8_from_16(buffer, 0);
-               
+
                /* Buffer mustn't be accessed after CloseClipboard
                 * it would like accessing free-d memory */
                GlobalUnlock(hData);
                CloseClipboard();
-               
+
                return (GHOST_TUns8 *)temp_buff;
        }
        else if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(NULL) ) {
@@ -1601,17 +1601,17 @@ GHOST_TUns8 *GHOST_SystemWin32::getClipboard(bool selection) const
                        CloseClipboard();
                        return NULL;
                }
-               
+
                len = strlen(buffer);
                temp_buff = (char *) malloc(len + 1);
                strncpy(temp_buff, buffer, len);
                temp_buff[len] = '\0';
-               
+
                /* Buffer mustn't be accessed after CloseClipboard
                 * it would like accessing free-d memory */
                GlobalUnlock(hData);
                CloseClipboard();
-               
+
                return (GHOST_TUns8 *)temp_buff;
        }
        else {
@@ -1626,11 +1626,11 @@ void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const
        if (OpenClipboard(NULL)) {
                HLOCAL clipbuffer;
                wchar_t *data;
-               
+
                if (buffer) {
                        size_t len = count_utf_16_from_8(buffer);
                        EmptyClipboard();
-                       
+
                        clipbuffer = LocalAlloc(LMEM_FIXED, sizeof(wchar_t) * len);
                        data = (wchar_t *)GlobalLock(clipbuffer);
 
@@ -1686,7 +1686,7 @@ static bool getProcessName(int pid, char *buffer, int max_len)
 static bool isStartedFromCommandPrompt()
 {
        HWND hwnd = GetConsoleWindow();
-       
+
        if (hwnd) {
                DWORD pid = (DWORD)-1;
                DWORD ppid = GetParentProcessID();