1 #define _WIN32_WINNT 0x0601
3 #include "window_private.h"
5 #include <msp/core/application.h>
6 #include <msp/core/systemerror.h>
12 LRESULT CALLBACK wndproc_(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
16 CREATESTRUCT *cs = reinterpret_cast<CREATESTRUCT *>(lparam);
17 SetWindowLongPtr(hwnd, 0, reinterpret_cast<LONG_PTR>(cs->lpCreateParams));
21 Msp::Graphics::Window *wnd = reinterpret_cast<Msp::Graphics::Window *>(GetWindowLongPtr(hwnd, 0));
22 Msp::Graphics::Window::Event ev;
26 ev.extra = GetMessageExtraInfo();
27 if(wnd && wnd->event(ev))
31 return DefWindowProc(hwnd, msg, wparam, lparam);
39 void Window::platform_init()
41 static bool wndclass_created = false;
47 wndcl.cbSize = sizeof(WNDCLASSEX);
49 wndcl.lpfnWndProc = &wndproc_;
51 wndcl.cbWndExtra = sizeof(Window *);
52 wndcl.hInstance = reinterpret_cast<HINSTANCE>(Application::get_data());
54 wndcl.hCursor = LoadCursor(0, IDC_ARROW);
55 wndcl.hbrBackground = 0;
56 wndcl.lpszMenuName = 0;
57 wndcl.lpszClassName = "mspgui";
60 if(!RegisterClassEx(&wndcl))
61 throw system_error("RegisterClassEx");
63 wndclass_created = true;
67 SetRect(&rect, 0, 0, options.width, options.height);
69 int style = (options.fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW);
70 if(!options.resizable)
71 style &= ~WS_THICKFRAME;
72 int exstyle = (options.fullscreen ? WS_EX_APPWINDOW : WS_EX_OVERLAPPEDWINDOW);
73 AdjustWindowRectEx(&rect, style, false, exstyle);
75 priv->window = CreateWindowEx(exstyle,
79 (options.user_position ? options.x : CW_USEDEFAULT),
80 (options.user_position ? options.y : CW_USEDEFAULT),
81 rect.right-rect.left, rect.bottom-rect.top,
84 reinterpret_cast<HINSTANCE>(Application::get_data()),
87 throw system_error("CreateWindowEx");
89 priv->cursor_in_client_area = false;
90 priv->cursor_visible = true;
93 void Window::platform_cleanup()
96 CloseWindow(priv->window);
99 void Window::set_title(const string &title)
101 SetWindowText(priv->window, title.c_str());
104 void Window::platform_reconfigure(bool fullscreen_changed)
107 SetRect(&rect, 0, 0, options.width, options.height);
109 int style = (options.fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW);
110 if(!options.resizable)
111 style &= ~WS_THICKFRAME;
112 int exstyle = (options.fullscreen ? WS_EX_APPWINDOW : WS_EX_OVERLAPPEDWINDOW);
113 AdjustWindowRectEx(&rect, style, false, exstyle);
115 if(fullscreen_changed)
117 bool was_visible = visible;
120 SetWindowLongPtr(priv->window, GWL_EXSTYLE, exstyle);
121 SetWindowLongPtr(priv->window, GWL_STYLE, style);
126 if(options.fullscreen)
127 SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER);
128 else if(options.user_position)
129 SetWindowPos(priv->window, 0, options.x, options.y, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER);
131 SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOMOVE|SWP_NOZORDER);
134 void Window::show_cursor(bool s)
136 priv->cursor_visible = s;
137 if(priv->cursor_in_client_area && !s)
141 void Window::warp_pointer(int, int)
145 void Window::platform_set_touch_input()
147 WORD winver = LOWORD(GetVersion);
148 if(winver<_WIN32_WINNT)
151 throw runtime_error("no touch support");
155 RegisterTouchWindow(priv->window, 3); // TWF_FINETOUCH|TWF_WANTPALM
157 UnregisterTouchWindow(priv->window);
160 void Window::platform_show()
162 ShowWindow(priv->window, SW_SHOWNORMAL);
165 void Window::platform_hide()
167 ShowWindow(priv->window, SW_HIDE);
170 bool Window::event(const Event &evnt)
189 signal_input_event.emit(evnt);
192 options.width = LOWORD(evnt.lparam);
193 options.height = HIWORD(evnt.lparam);
195 signal_resize.emit(options.width, options.height);
198 options.x = static_cast<short>(LOWORD(evnt.lparam));
199 options.y = static_cast<short>(HIWORD(evnt.lparam));
201 signal_move.emit(options.x, options.y);
209 GetUpdateRect(priv->window, &update_rect, false);
210 unsigned width = update_rect.right-update_rect.left;
211 unsigned height = update_rect.bottom-update_rect.top;
212 signal_expose.emit(update_rect.left, update_rect.top, width, height, evnt);
215 if(BeginPaint(priv->window, &paint))
216 EndPaint(priv->window, &paint);
220 signal_got_focus.emit();
223 signal_lost_focus.emit();
226 priv->cursor_in_client_area = (LOWORD(evnt.lparam)==HTCLIENT);
227 if(priv->cursor_in_client_area && !priv->cursor_visible)
239 } // namespace Graphics