]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/windows/window.cpp
Handle WM_SYSKEYDOWN, WM_SYSKEYUP and WM_SYSCHAR events
[libs/gui.git] / source / graphics / windows / window.cpp
index b148915d9bc94b6581037a682c3982c0bf78212f..38e7f730cd5bc6341aaeb00c30ae92fefa4d0374 100644 (file)
@@ -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;
@@ -76,7 +76,8 @@ void Window::platform_init()
                "mspgui",
                "Window",
                style,
-               CW_USEDEFAULT, CW_USEDEFAULT,
+               (options.user_position ? options.x : CW_USEDEFAULT),
+               (options.user_position ? options.y : CW_USEDEFAULT),
                rect.right-rect.left, rect.bottom-rect.top,
                0,
                0,
@@ -84,6 +85,9 @@ void Window::platform_init()
                this);
        if(!priv->window)
                throw system_error("CreateWindowEx");
+
+       priv->cursor_in_client_area = false;
+       priv->cursor_visible = true;
 }
 
 void Window::platform_cleanup()
@@ -110,21 +114,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);
+       else if(options.user_position)
+               SetWindowPos(priv->window, 0, 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);
 }
 
 void Window::show_cursor(bool s)
 {
-       ShowCursor(s);
+       priv->cursor_visible = s;
+       if(priv->cursor_in_client_area && !s)
+               SetCursor(NULL);
 }
 
 void Window::warp_pointer(int, int)
@@ -163,6 +174,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:
@@ -171,7 +185,7 @@ bool Window::event(const Event &evnt)
        case WM_RBUTTONUP:
        case WM_MOUSEWHEEL:
        case WM_MOUSEMOVE:
-       case WM_TOUCHMOVE:
+       case WM_TOUCH:
                signal_input_event.emit(evnt);
                break;
        case WM_SIZE:
@@ -183,6 +197,7 @@ bool Window::event(const Event &evnt)
        case WM_MOVE:
                options.x = static_cast<short>(LOWORD(evnt.lparam));
                options.y = static_cast<short>(HIWORD(evnt.lparam));
+               moving = false;
                signal_move.emit(options.x, options.y);
                break;
        case WM_CLOSE:
@@ -195,8 +210,25 @@ bool Window::event(const Event &evnt)
                        unsigned width = update_rect.right-update_rect.left;
                        unsigned height = update_rect.bottom-update_rect.top;
                        signal_expose.emit(update_rect.left, update_rect.top, width, height, evnt);
+
+                       PAINTSTRUCT paint;
+                       if(BeginPaint(priv->window, &paint))
+                               EndPaint(priv->window, &paint);
                }
                break;
+       case WM_SETFOCUS:
+               signal_got_focus.emit();
+               break;
+       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(NULL);
+               else
+                       return false;
+               break;
        default:
                return false;
        }