From 2497577c09b13a55430a95fcf311448fda11cae3 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 23 Mar 2017 20:56:21 +0100 Subject: Fix resize event in win32 backend. --- configure.ac | 2 +- plugin/Makefile.mingw32.in | 2 +- plugingui/nativewindow_win32.cc | 53 ++++++++++++++++++++++++++++++++++++----- plugingui/nativewindow_win32.h | 2 ++ 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index a56fd39..070f380 100644 --- a/configure.ac +++ b/configure.ac @@ -164,7 +164,7 @@ AS_IF( [test "x$enable_gui" = "xwin32"], [AC_MSG_RESULT([Setting gui backend to Win32]) GUI_CPPFLAGS="-DUI_WIN32" - GUI_LIBS="-lgdi32 -lsetupapi -lws2_32"], + GUI_LIBS="-lgdi32 -lsetupapi -lws2_32 -lcomctl32"], [test "x$enable_gui" = "xpugl"], [AC_MSG_RESULT([Setting gui backend to Pugl]) diff --git a/plugin/Makefile.mingw32.in b/plugin/Makefile.mingw32.in index 575a8a2..cab3e0c 100644 --- a/plugin/Makefile.mingw32.in +++ b/plugin/Makefile.mingw32.in @@ -86,7 +86,7 @@ GUI_SRC = \ @top_srcdir@/plugingui/lodepng/lodepng.cpp GUI_CPPFLAGS=-I@top_srcdir@/plugingui/ -DUSE_THREAD @GUI_CPPFLAGS@ -GUI_LIBS=-lgdi32 -lsetupapi -lws2_32 +GUI_LIBS=@GUI_LIBS@ DBG_SRC = \ @top_srcdir@/hugin/hugin.c \ diff --git a/plugingui/nativewindow_win32.cc b/plugingui/nativewindow_win32.cc index 6297b23..80dcf7d 100644 --- a/plugingui/nativewindow_win32.cc +++ b/plugingui/nativewindow_win32.cc @@ -28,6 +28,7 @@ #include #include +#include #include "window.h" @@ -54,8 +55,8 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, auto resizeEvent = std::make_shared(); resizeEvent->width = LOWORD(lp); resizeEvent->height = HIWORD(lp); - //native->event_queue.push_back(resizeEvent); - native->window.resized(resizeEvent->width, resizeEvent->height); + native->event_queue.push_back(resizeEvent); + //native->window.resized(resizeEvent->width, resizeEvent->height); } break; @@ -296,6 +297,36 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, return DefWindowProc(hwnd, msg, wp, lp); } +LRESULT CALLBACK NativeWindowWin32::subClassProc(HWND hwnd, UINT msg, + WPARAM wp, LPARAM lp, + UINT_PTR id, DWORD_PTR data) +{ + NativeWindowWin32* native = (NativeWindowWin32*)data; + + // NOTE: 'native' is nullptr intil the WM_CREATE message has been handled. + if(!native) + { + return DefWindowProc(hwnd, msg, wp, lp); + } + + switch(msg) { + case WM_SIZE: + { + int width = LOWORD(lp); + int height = HIWORD(lp); + SetWindowPos(native->m_hwnd, nullptr, -1, -1, width, height, SWP_NOMOVE); + RECT rect; + GetClientRect(native->m_hwnd, &rect); + int w = width - rect.right; + int h = height - rect.bottom; + SetWindowPos(native->m_hwnd, nullptr, -1, -1, width + w, height + h, SWP_NOMOVE); + } + break; + } + + return DefWindowProc(hwnd, msg, wp, lp); +} + NativeWindowWin32::NativeWindowWin32(void* native_window, Window& window) : window(window) { @@ -337,6 +368,12 @@ NativeWindowWin32::NativeWindowWin32(void* native_window, Window& window) GetModuleHandle(nullptr), nullptr); SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)this); + + if(parent_window) + { + // Listen in on parent size changes. + SetWindowSubclass(parent_window, subClassProc, 42, (LONG_PTR)this); + } } NativeWindowWin32::~NativeWindowWin32() @@ -355,13 +392,17 @@ void NativeWindowWin32::setFixedSize(std::size_t width, std::size_t height) void NativeWindowWin32::resize(std::size_t width, std::size_t height) { - SetWindowPos(m_hwnd, nullptr, -1, -1, (int)width, (int)height, SWP_NOMOVE); + auto hwnd = m_hwnd; + if(parent_window) + { + hwnd = parent_window; + } + SetWindowPos(hwnd, nullptr, -1, -1, (int)width, (int)height, SWP_NOMOVE); RECT rect; - GetClientRect(m_hwnd, &rect); + GetClientRect(hwnd, &rect); int w = width - rect.right; int h = height - rect.bottom; - - SetWindowPos(m_hwnd, nullptr, -1, -1, width + w, height + h, SWP_NOMOVE); + SetWindowPos(hwnd, nullptr, -1, -1, width + w, height + h, SWP_NOMOVE); } std::pair NativeWindowWin32::getSize() diff --git a/plugingui/nativewindow_win32.h b/plugingui/nativewindow_win32.h index 2299189..c7d412a 100644 --- a/plugingui/nativewindow_win32.h +++ b/plugingui/nativewindow_win32.h @@ -59,6 +59,8 @@ public: private: static LRESULT CALLBACK dialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp); + static LRESULT CALLBACK subClassProc(HWND hwnd, UINT msg, WPARAM wp, + LPARAM lp, UINT_PTR id, DWORD_PTR data); HWND parent_window; Window& window; -- cgit v1.2.3