summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2017-03-23 20:56:21 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2017-03-26 19:41:05 +0200
commit2497577c09b13a55430a95fcf311448fda11cae3 (patch)
tree3431b8f0d83b8890eeab14813fb367d084b9e500
parentb0cf022ea75b763531e6ae63abccadf2bfa7a84b (diff)
Fix resize event in win32 backend.
-rw-r--r--configure.ac2
-rw-r--r--plugin/Makefile.mingw32.in2
-rw-r--r--plugingui/nativewindow_win32.cc53
-rw-r--r--plugingui/nativewindow_win32.h2
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 <cstring>
#include <algorithm>
+#include <commctrl.h>
#include "window.h"
@@ -54,8 +55,8 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg,
auto resizeEvent = std::make_shared<ResizeEvent>();
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<std::size_t, std::size_t> 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;