diff --git a/ui_windows.h b/ui_windows.h index 2722d04f..335b49b2 100644 --- a/ui_windows.h +++ b/ui_windows.h @@ -106,7 +106,7 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P #define uiWindowsControlDefaultSetParentHWND(type) \ static void type ## SetParentHWND(uiWindowsControl *c, HWND parent) \ { \ - uiWindowsEnsureSetParent(type(c)->hwnd, parent); \ + uiWindowsEnsureSetParentHWND(type(c)->hwnd, parent); \ } // note that there is no uiWindowsControlDefaultMinimumSize(); you MUST define this yourself! #define uiWindowsDefaultChildMinimumSizeChanged(type) \ @@ -171,7 +171,7 @@ _UI_EXTERN HWND uiWindowsEnsureCreateControlHWND(DWORD dwExStyle, LPCWSTR lpClas _UI_EXTERN void uiWindowsEnsureDestroyWindow(HWND hwnd); // TODO document -_UI_EXTERN void uiWindowsEnsureSetParent(HWND hwnd, HWND parent); +_UI_EXTERN void uiWindowsEnsureSetParentHWND(HWND hwnd, HWND parent); // TODO document _UI_EXTERN void uiWindowsEnsureAssignControlIDZOrder(HWND hwnd, LONG_PTR *controlID, HWND *insertAfter); diff --git a/windows/GNUfiles.mk b/windows/GNUfiles.mk index d88d7486..3babf0e7 100644 --- a/windows/GNUfiles.mk +++ b/windows/GNUfiles.mk @@ -44,6 +44,7 @@ CXXFILES += \ windows/utf16.cpp \ windows/utilwin.cpp \ windows/window.cpp \ + windows/winpublic.cpp \ windows/winutil.cpp HFILES += \ diff --git a/windows/winpublic.cpp b/windows/winpublic.cpp new file mode 100644 index 00000000..be1cf60c --- /dev/null +++ b/windows/winpublic.cpp @@ -0,0 +1,34 @@ +// 6 april 2015 +#include "uipriv_windows.hpp" + +void uiWindowsEnsureDestroyWindow(HWND hwnd) +{ + if (DestroyWindow(hwnd) == 0) + logLastError(L"error destroying window"); +} + +void uiWindowsEnsureSetParentHWND(HWND hwnd, HWND parent) +{ + if (parent == NULL) + parent = utilWindow; + if (SetParent(hwnd, parent) == 0) + logLastError(L"error setting window parent"); +} + +void uiWindowsEnsureAssignControlIDZOrder(HWND hwnd, LONG_PTR controlID, HWND insertAfter) +{ + SetWindowLongPtrW(hwnd, GWLP_ID, controlID); + setWindowInsertAfter(hwnd, insertAfter); +} + +void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height) +{ + RECT r; + + r.left = x; + r.top = y; + r.right = x + width; + r.bottom = y + height; + if (SetWindowPos(hwnd, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOZORDER) == 0) + logLastError(L"error moving window"); +} diff --git a/windows/winutil.cpp b/windows/winutil.cpp index c8789124..b4fa692e 100644 --- a/windows/winutil.cpp +++ b/windows/winutil.cpp @@ -76,26 +76,6 @@ void setExStyle(HWND hwnd, DWORD exstyle) SetWindowLongPtrW(hwnd, GWL_EXSTYLE, (LONG_PTR) exstyle); } -void uiWindowsEnsureDestroyWindow(HWND hwnd) -{ - if (DestroyWindow(hwnd) == 0) - logLastError(L"error destroying window"); -} - -// TODO allow passing NULL to indicate no parent -// this would allow for custom containers -void uiWindowsEnsureSetParent(HWND hwnd, HWND parent) -{ - if (SetParent(hwnd, parent) == 0) - logLastError(L"error setting window parent"); -} - -void uiWindowsEnsureAssignControlIDZOrder(HWND hwnd, LONG_PTR controlID, HWND insertAfter) -{ - SetWindowLongPtrW(hwnd, GWLP_ID, controlID); - setWindowInsertAfter(hwnd, insertAfter); -} - // see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx void clientSizeToWindowSize(HWND hwnd, intmax_t *width, intmax_t *height, BOOL hasMenubar) { @@ -135,18 +115,6 @@ HWND parentToplevel(HWND child) return GetAncestor(child, GA_ROOT); } -void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height) -{ - RECT r; - - r.left = x; - r.top = y; - r.right = x + width; - r.bottom = y + height; - if (SetWindowPos(hwnd, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOZORDER) == 0) - logLastError(L"error moving window"); -} - void setWindowInsertAfter(HWND hwnd, HWND insertAfter) { if (SetWindowPos(hwnd, insertAfter, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE) == 0)