X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fwindows%2Fwindow.cpp;h=0e3365393e653ebdf829be465d6efb30d57ee169;hb=479298192e3e5b71a402f79520c90372a4c4b504;hp=e9989501565b303c16ae3fe9eaad4dce9d8b1ee2;hpb=ecd773e95ac440b123df5625fe71130982465097;p=libs%2Fgui.git diff --git a/source/graphics/windows/window.cpp b/source/graphics/windows/window.cpp index e998950..0e33653 100644 --- a/source/graphics/windows/window.cpp +++ b/source/graphics/windows/window.cpp @@ -1,8 +1,10 @@ +#define _WIN32_WINNT 0x0601 // Windows 7 +#include "window.h" +#include "window_private.h" #include +#include #include #include -#include "window.h" -#include "window_private.h" using namespace std; @@ -13,15 +15,16 @@ LRESULT CALLBACK wndproc_(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if(msg==WM_CREATE) { CREATESTRUCT *cs = reinterpret_cast(lparam); - SetWindowLong(hwnd, 0, reinterpret_cast(cs->lpCreateParams)); + SetWindowLongPtr(hwnd, 0, reinterpret_cast(cs->lpCreateParams)); } else { - Msp::Graphics::Window *wnd = reinterpret_cast(GetWindowLong(hwnd, 0)); + Msp::Graphics::Window *wnd = reinterpret_cast(GetWindowLongPtr(hwnd, 0)); Msp::Graphics::Window::Event ev; ev.msg = msg; ev.wparam = wparam; ev.lparam = lparam; + ev.extra = GetMessageExtraInfo(); if(wnd && wnd->event(ev)) return 0; } @@ -48,12 +51,12 @@ void Window::platform_init() wndcl.cbClsExtra = 0; wndcl.cbWndExtra = sizeof(Window *); wndcl.hInstance = reinterpret_cast(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"); @@ -74,7 +77,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, @@ -108,27 +112,48 @@ 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, 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) { } +void Window::platform_set_touch_input() +{ + if(!IsWindows7OrGreater()) + { + touch_input = false; + throw runtime_error("no touch support"); + } + + if(touch_input) + RegisterTouchWindow(priv->window, 3); // TWF_FINETOUCH|TWF_WANTPALM + else + UnregisterTouchWindow(priv->window); +} + void Window::platform_show() { ShowWindow(priv->window, SW_SHOWNORMAL); @@ -145,6 +170,10 @@ 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: @@ -153,6 +182,7 @@ bool Window::event(const Event &evnt) case WM_RBUTTONUP: case WM_MOUSEWHEEL: case WM_MOUSEMOVE: + case WM_TOUCH: signal_input_event.emit(evnt); break; case WM_SIZE: @@ -161,9 +191,41 @@ bool Window::event(const Event &evnt) resizing = false; signal_resize.emit(options.width, options.height); break; + case WM_MOVE: + options.x = static_cast(LOWORD(evnt.lparam)); + options.y = static_cast(HIWORD(evnt.lparam)); + moving = false; + signal_move.emit(options.x, options.y); + break; case WM_CLOSE: signal_close.emit(); break; + case WM_PAINT: + { + RECT update_rect; + GetUpdateRect(priv->window, &update_rect, false); + 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(nullptr); + else + return false; + break; default: return false; }