Migrated resize.c.
This commit is contained in:
parent
027d1f15ee
commit
1ada1b346c
|
@ -67,8 +67,6 @@ const char *uiInit(uiInitOptions *o)
|
|||
|
||||
initAlloc();
|
||||
|
||||
initResizes();
|
||||
|
||||
nCmdShow = SW_SHOWDEFAULT;
|
||||
GetStartupInfoW(&si);
|
||||
if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0)
|
||||
|
@ -153,7 +151,6 @@ void uiUninit(void)
|
|||
unregisterWindowClass();
|
||||
// no need to delete the default icon or cursor; see http://stackoverflow.com/questions/30603077/
|
||||
uninitUtilWindow();
|
||||
uninitResizes();
|
||||
uninitTypes();
|
||||
uninitAlloc();
|
||||
}
|
||||
|
|
|
@ -1,38 +1,20 @@
|
|||
// 14 may 2015
|
||||
#include "uipriv_windows.h"
|
||||
#include "uipriv_windows.hpp"
|
||||
|
||||
static struct ptrArray *resizes;
|
||||
|
||||
void initResizes(void)
|
||||
{
|
||||
resizes = newPtrArray();
|
||||
}
|
||||
|
||||
void uninitResizes(void)
|
||||
{
|
||||
while (resizes->len != 0)
|
||||
ptrArrayDelete(resizes, 0);
|
||||
ptrArrayDestroy(resizes);
|
||||
}
|
||||
static std::map<uiWindowsControl *, bool> resizes;
|
||||
|
||||
void uiWindowsControlQueueRelayout(uiWindowsControl *c)
|
||||
{
|
||||
uiControl *cc;
|
||||
uintmax_t i;
|
||||
uiWindowsControl *d;
|
||||
|
||||
// resizing a control requires us to reocmpute the sizes of everything in the top-level window
|
||||
// TODO get rid of this call, make one for finding the root through the HWND
|
||||
cc = toplevelOwning(uiControl(c));
|
||||
if (cc == NULL)
|
||||
return;
|
||||
c = uiWindowsControl(cc);
|
||||
// make sure we're only queued once
|
||||
for (i = 0 ; i < resizes->len; i++) {
|
||||
d = ptrArrayIndex(resizes, uiWindowsControl *, i);
|
||||
if (c == d)
|
||||
return;
|
||||
}
|
||||
ptrArrayAppend(resizes, c);
|
||||
resizes[c] = true;
|
||||
}
|
||||
|
||||
void doResizes(void)
|
||||
|
@ -41,40 +23,31 @@ void doResizes(void)
|
|||
HWND hwnd;
|
||||
RECT r;
|
||||
|
||||
while (resizes->len != 0) {
|
||||
w = ptrArrayIndex(resizes, uiWindowsControl *, 0);
|
||||
for (const auto &iter : resizes) {
|
||||
w = iter.first;
|
||||
// don't clip content if content dynamically changed (tab page changed, etc.)
|
||||
// do this BEFORE removing w from the queue list to avoid double queueing
|
||||
ensureMinimumWindowSize(uiWindow(w));
|
||||
ptrArrayDelete(resizes, 0);
|
||||
hwnd = (HWND) uiControlHandle(uiControl(w));
|
||||
if (GetClientRect(hwnd, &r) == 0)
|
||||
logLastError("error getting uiWindow client rect in doResizes()");
|
||||
if (GetClientRect(hwnd, &r) == 0) {
|
||||
logLastError(L"error getting uiWindow client rect");
|
||||
// give up on this one; move on to the next one
|
||||
continue;
|
||||
}
|
||||
(*(w->Relayout))(w, r.left, r.top, r.right - r.left, r.bottom - r.top);
|
||||
// we used SWP_NOREDRAW; we need to queue a redraw ourselves
|
||||
// force all controls to be redrawn; this fixes things like the date-time picker's up-down not showing up until hovered over (and bypasses complications caused by WS_CLIPCHILDREN and WS_CLIPSIBLINGS, which we don't use but other controls might)
|
||||
if (RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN) == 0)
|
||||
logLastError("error redrawing controls after a resize in doResizes()");
|
||||
logLastError(L"error redrawing controls after a resize"); // and keep going anyway
|
||||
}
|
||||
// and wipe the list
|
||||
resizes.clear();
|
||||
}
|
||||
|
||||
void uiWindowsEnsureMoveWindow(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("error moving window in moveWindow()");
|
||||
}
|
||||
|
||||
void setWindowInsertAfter(HWND hwnd, HWND insertAfter)
|
||||
{
|
||||
if (SetWindowPos(hwnd, insertAfter, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE) == 0)
|
||||
logLastError("error reordering window in setWindowInsertAfter()");
|
||||
}
|
||||
///////////////////////
|
||||
// TODO REEVALUATE EVERYTHING BEYOND THIS POINT
|
||||
// if we do have to keep, verify the error handling
|
||||
///////////////////////
|
||||
|
||||
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing and https://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx
|
||||
// this X value is really only for buttons but I don't see a better one :/
|
||||
|
@ -93,25 +66,25 @@ uiWindowsSizing *uiWindowsNewSizing(HWND hwnd)
|
|||
|
||||
dc = GetDC(hwnd);
|
||||
if (dc == NULL)
|
||||
logLastError("error getting DC in uiWindowsNewSizing()");
|
||||
logLastError(L"error getting DC");
|
||||
prevfont = (HFONT) SelectObject(dc, hMessageFont);
|
||||
if (prevfont == NULL)
|
||||
logLastError("error loading control font into device context in uiWindowsNewSizing()");
|
||||
logLastError(L"error loading control font into device context");
|
||||
|
||||
ZeroMemory(&tm, sizeof (TEXTMETRICW));
|
||||
if (GetTextMetricsW(dc, &tm) == 0)
|
||||
logLastError("error getting text metrics in uiWindowsNewSizing()");
|
||||
logLastError(L"error getting text metrics");
|
||||
if (GetTextExtentPoint32W(dc, L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size) == 0)
|
||||
logLastError("error getting text extent point in uiWindowsNewSizing()");
|
||||
logLastError(L"error getting text extent point");
|
||||
|
||||
d->BaseX = (int) ((size.cx / 26 + 1) / 2);
|
||||
d->BaseY = (int) tm.tmHeight;
|
||||
d->InternalLeading = tm.tmInternalLeading;
|
||||
|
||||
if (SelectObject(dc, prevfont) != hMessageFont)
|
||||
logLastError("error restoring previous font into device context in uiWindowsSizing()");
|
||||
logLastError(L"error restoring previous font into device context");
|
||||
if (ReleaseDC(hwnd, dc) == 0)
|
||||
logLastError("error releasing DC in uiWindowsSizing()");
|
||||
logLastError(L"error releasing DC");
|
||||
|
||||
d->XPadding = uiWindowsDlgUnitsToX(winXPadding, d->BaseX);
|
||||
d->YPadding = uiWindowsDlgUnitsToY(winYPadding, d->BaseY);
|
|
@ -19,6 +19,14 @@ _UI_EXTERN void uiWindowsSetWindowText(HWND hwnd, const char *text);
|
|||
// TODO document
|
||||
_UI_EXTERN intmax_t uiWindowsWindowTextWidth(HWND hwnd);
|
||||
|
||||
// TODO document
|
||||
// TODO keep uiWindowsControl?
|
||||
_UI_EXTERN void uiWindowsControlQueueRelayout(uiWindowsControl *c);
|
||||
|
||||
// TODO document
|
||||
// TODO point out this should only be used in a resize cycle
|
||||
_UI_EXTERN void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height);
|
||||
|
||||
// TODO document
|
||||
_UI_EXTERN void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c);
|
||||
_UI_EXTERN void uiWindowsUnregisterWM_COMMANDHandler(HWND hwnd);
|
||||
|
|
|
@ -42,6 +42,7 @@ extern void setExStyle(HWND hwnd, DWORD exstyle);
|
|||
extern void clientSizeToWindowSize(HWND hwnd, intmax_t *width, intmax_t *height, BOOL hasMenubar);
|
||||
extern HWND parentOf(HWND child);
|
||||
extern HWND parentToplevel(HWND child);
|
||||
extern void setWindowInsertAfter(HWND hwnd, HWND insertAfter);
|
||||
|
||||
// text.cpp
|
||||
extern WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len);
|
||||
|
@ -67,3 +68,6 @@ extern void unregisterMessageFilter(void);
|
|||
// parent.cpp
|
||||
extern void paintContainerBackground(HWND hwnd, HDC dc, RECT *paintRect);
|
||||
extern BOOL handleParentMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult);
|
||||
|
||||
// resize.cpp
|
||||
extern void doResizes(void);
|
||||
|
|
|
@ -134,3 +134,23 @@ 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)
|
||||
logLastError(L"error reordering window");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue