]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/windows/window.cpp
Use nullptr in place of 0 or NULL
[libs/gui.git] / source / graphics / windows / window.cpp
index cc364723d292b109dcce847122f6096881befe1d..e7ec9109c5fa16f1f19db2f5930359cd77a39d17 100644 (file)
@@ -1,9 +1,9 @@
 #define _WIN32_WINNT 0x0601
+#include "window.h"
+#include "window_private.h"
 #include <windowsx.h>
 #include <msp/core/application.h>
 #include <msp/core/systemerror.h>
-#include "window.h"
-#include "window_private.h"
 
 using namespace std;
 
@@ -14,11 +14,11 @@ LRESULT CALLBACK wndproc_(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
        if(msg==WM_CREATE)
        {
                CREATESTRUCT *cs = reinterpret_cast<CREATESTRUCT *>(lparam);
-               SetWindowLong(hwnd, 0, reinterpret_cast<LONG>(cs->lpCreateParams));
+               SetWindowLongPtr(hwnd, 0, reinterpret_cast<LONG_PTR>(cs->lpCreateParams));
        }
        else
        {
-               Msp::Graphics::Window *wnd = reinterpret_cast<Msp::Graphics::Window *>(GetWindowLong(hwnd, 0));
+               Msp::Graphics::Window *wnd = reinterpret_cast<Msp::Graphics::Window *>(GetWindowLongPtr(hwnd, 0));
                Msp::Graphics::Window::Event ev;
                ev.msg = msg;
                ev.wparam = wparam;
@@ -50,12 +50,12 @@ void Window::platform_init()
                wndcl.cbClsExtra = 0;
                wndcl.cbWndExtra = sizeof(Window *);
                wndcl.hInstance = reinterpret_cast<HINSTANCE>(Application::get_data());
-               wndcl.hIcon = 0;
-               wndcl.hCursor = LoadCursor(0, IDC_ARROW);
-               wndcl.hbrBackground = 0;
-               wndcl.lpszMenuName = 0;
+               wndcl.hIcon = nullptr;
+               wndcl.hCursor = LoadCursor(nullptr, IDC_ARROW);
+               wndcl.hbrBackground = nullptr;
+               wndcl.lpszMenuName = nullptr;
                wndcl.lpszClassName = "mspgui";
-               wndcl.hIconSm = 0;
+               wndcl.hIconSm = nullptr;
 
                if(!RegisterClassEx(&wndcl))
                        throw system_error("RegisterClassEx");
@@ -111,23 +111,28 @@ void Window::platform_reconfigure(bool fullscreen_changed)
 
        if(fullscreen_changed)
        {
-               hide();
-               SetWindowLong(priv->window, GWL_EXSTYLE, exstyle);
-               SetWindowLong(priv->window, GWL_STYLE, style);
-               show();
+               bool was_visible = visible;
+               if(was_visible)
+                       hide();
+               SetWindowLongPtr(priv->window, GWL_EXSTYLE, exstyle);
+               SetWindowLongPtr(priv->window, GWL_STYLE, style);
+               if(was_visible)
+                       show();
        }
 
        if(options.fullscreen)
-               SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER);
+               SetWindowPos(priv->window, nullptr, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER);
        else if(options.user_position)
-               SetWindowPos(priv->window, 0, options.x, options.y, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER);
+               SetWindowPos(priv->window, nullptr, options.x, options.y, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER);
        else
-               SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOMOVE|SWP_NOZORDER);
+               SetWindowPos(priv->window, nullptr, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOMOVE|SWP_NOZORDER);
 }
 
 void Window::show_cursor(bool s)
 {
-       ShowCursor(s);
+       priv->cursor_visible = s;
+       if(priv->cursor_in_client_area && !s)
+               SetCursor(nullptr);
 }
 
 void Window::warp_pointer(int, int)
@@ -166,6 +171,9 @@ bool Window::event(const Event &evnt)
        case WM_KEYDOWN:
        case WM_KEYUP:
        case WM_CHAR:
+       case WM_SYSKEYDOWN:
+       case WM_SYSKEYUP:
+       case WM_SYSCHAR:
        case WM_LBUTTONDOWN:
        case WM_LBUTTONUP:
        case WM_MBUTTONDOWN:
@@ -211,6 +219,13 @@ bool Window::event(const Event &evnt)
        case WM_KILLFOCUS:
                signal_lost_focus.emit();
                break;
+       case WM_SETCURSOR:
+               priv->cursor_in_client_area = (LOWORD(evnt.lparam)==HTCLIENT);
+               if(priv->cursor_in_client_area && !priv->cursor_visible)
+                       SetCursor(nullptr);
+               else
+                       return false;
+               break;
        default:
                return false;
        }