Finished migrating window.cpp. A few utility functions came along for the ride. Maybe child.cpp won't be needed...?

This commit is contained in:
Pietro Gagliardi 2016-04-27 00:54:22 -04:00
parent 78b49ae04d
commit 3563dd74e7
11 changed files with 91 additions and 58 deletions

View File

@ -36,7 +36,7 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
if (uMsg == WM_WINDOWPOSCHANGED) {
if ((wp->flags & SWP_NOSIZE) != 0)
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
if (GetClientRect(a->hwnd, &client) == 0)
if (getClientRect(a->hwnd, &client) == 0)
logLastError(L"error getting client rect of uiArea for WM_WINDOWPOSCHANGED handling");
areaDrawOnResize(a, &client);
areaScrollOnResize(a, &client);

View File

@ -94,7 +94,7 @@ static void onWM_PRINTCLIENT(uiArea *a)
{
RECT client;
if (GetClientRect(a->hwnd, &client) == 0)
if (getClientRect(a->hwnd, &client) == 0)
logLastError(L"error getting client rect");
//TODO doPaint(a, (HDC) wParam, &client);
}

View File

@ -85,7 +85,7 @@ static void areaMouseEvent(uiArea *a, uintmax_t down, uintmax_t up, WPARAM wPar
if (a->capturing) {
clientpt.x = GET_X_LPARAM(lParam);
clientpt.y = GET_Y_LPARAM(lParam);
if (GetClientRect(a->hwnd, &client) == 0)
if (getClientRect(a->hwnd, &client) == 0)
logLastError(L"error getting uiAreaclient rect for mouse crossing on capture on drag");
inClient = PtInRect(&client, clientpt);
if (inClient && !a->inside) {

View File

@ -128,7 +128,7 @@ static void hscrollParams(uiArea *a, struct scrollParams *p)
ZeroMemory(p, sizeof (struct scrollParams));
p->pos = &(a->hscrollpos);
// TODO get rid of these and replace with points
if (GetClientRect(a->hwnd, &r) == 0)
if (getClientRect(a->hwnd, &r) == 0)
logLastError(L"error getting area client rect");
p->pagesize = r.right - r.left;
p->length = a->scrollWidth;
@ -174,7 +174,7 @@ static void vscrollParams(uiArea *a, struct scrollParams *p)
ZeroMemory(p, sizeof (struct scrollParams));
p->pos = &(a->vscrollpos);
if (GetClientRect(a->hwnd, &r) == 0)
if (getClientRect(a->hwnd, &r) == 0)
logLastError(L"error getting area client rect");
p->pagesize = r.bottom - r.top;
p->length = a->scrollHeight;

View File

@ -50,7 +50,7 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
return 0;
// tab controls use this to draw the background of the tab area
case WM_PRINTCLIENT:
if (GetClientRect(hwnd, &r) == 0) {
if (getClientRect(hwnd, &r) == 0) {
logLastError(L"error getting client rect");
// likewise
break;

View File

@ -51,7 +51,7 @@ ID2D1HwndRenderTarget *makeHWNDRenderTarget(HWND hwnd)
if (ReleaseDC(hwnd, dc) == 0)
logLastError(L"error releasing DC for finding DPI");
if (GetClientRect(hwnd, &r) == 0)
if (getClientRect(hwnd, &r) == 0)
logLastError(L"error getting current size of window");
ZeroMemory(&hprops, sizeof (D2D1_HWND_RENDER_TARGET_PROPERTIES));

View File

@ -495,7 +495,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam)
samplePlacement = GetDlgItem(f->hwnd, rcFontSamplePlacement);
if (samplePlacement == NULL)
logLastError(L"error getting sample placement static control handle");
if (GetWindowRect(samplePlacement, &(f->sampleRect)) == 0)
if (getWindowRect(samplePlacement, &(f->sampleRect)) == 0)
logLastError(L"error getting sample placement");
mapWindowRect(NULL, f->hwnd, &(f->sampleRect));
uiWindowsEnsureDestroyWindow(samplePlacement);

View File

@ -33,7 +33,7 @@ static HRESULT parentDraw(HDC dc, HWND parent, struct parentDraw *pd)
{
RECT r;
if (GetClientRect(parent, &r) == 0)
if (getClientRect(parent, &r) == 0)
return logLastError(L"error getting parent's client rect");
pd->cdc = CreateCompatibleDC(dc);
if (pd->cdc == NULL)
@ -86,7 +86,7 @@ static HBRUSH getControlBackgroundBrush(HWND hwnd, HDC dc)
// now figure out where the control is relative to the parent so we can align the brush properly
// if anything fails, give up and return the brush as-is
if (GetWindowRect(hwnd, &hwndScreenRect) == 0) {
if (getWindowRect(hwnd, &hwndScreenRect) == 0) {
logLastError(L"error getting control window rect");
return brush;
}

View File

@ -66,6 +66,8 @@ extern void clientSizeToWindowSize(HWND hwnd, intmax_t *width, intmax_t *height,
extern HWND parentOf(HWND child);
extern HWND parentToplevel(HWND child);
extern void setWindowInsertAfter(HWND hwnd, HWND insertAfter);
extern void getClientRect(HWND, RECT *);
extern void getWindowRect(HWND, RECT *);
// text.cpp
extern WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len);

View File

@ -16,6 +16,23 @@ struct uiWindow {
BOOL hasMenubar;
};
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
#define windowMargin 7
static void windowMargins(uiWindow *w, int *mx, int *my)
{
uiWindowsSizing sizing;
*mx = 0;
*my = 0;
if (!w->margined)
return;
uiWindowsGetSizing(w->hwnd, &sizing);
*mx = windowMargin;
*my = windowMargin;
uiWindowsSizingDlgUnitsToPixels(&sizing, mx, my);
}
static void windowRelayout(uiWindow *w)
{
uiWindow *w = uiWindow(c);
@ -28,20 +45,14 @@ static void windowRelayout(uiWindow *w)
return;
x = 0;
y = 0;
if (GetClientRect(w->hwnd, &r) == 0)
/* TODO */;
getClientRect(w->hwnd, &r);
width = r.right - r.left;
height = r.bottom - r.top;
if (w->margined) {
uiWindowsGetSizing(w->hwnd, &sizing);
mx = windowMargin;
my = windowMargin;
uiWindowsSizingDlgUnitsToPixels(&sizing, &mx, &my);
x += mx;
y += my;
width -= 2 * mx;
height -= 2 * my;
}
windowMargins(w, &mx, &my);
x += mx;
y += my;
width -= 2 * mx;
height -= 2 * my;
// TODO
}
@ -202,9 +213,6 @@ uiWindowsControlDefaultSyncEnableState(uiWindow)
// TODO
uiWindowsControlDefaultSetParentHWND(uiWindow)
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
#define windowMargin 7
static void uiWindowMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *height)
{
uiWindow *w = uiWindow(c);
@ -215,15 +223,9 @@ static void uiWindowMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *
*height = 0;
if (w->child != NULL)
uiWindowsControlMinimumSize(uiWindowsControl(w->child), width, height);
if (w->margined) {
uiWindowsGetSizing(w->hwnd, &sizing);
mx = windowMargin;
my = windowMargin;
uiWindowsSizingDlgUnitsToPixels(&sizing, &mx, &my);
*width += 2 * mx;
*height += 2 * my;
}
uiWindowsFreeSizing(d);
windowMargins(w, &mx, &my);
*width += 2 * mx;
*height += 2 * my;
}
static void uiWindowChildMinimumSizeChanged(uiWindowsControl *c)
@ -232,24 +234,28 @@ static void uiWindowChildMinimumSizeChanged(uiWindowsControl *c)
intmax_t width, height;
RECT r;
BOOL needsGrowing;
int mx, my;
uiWindowsControlMinimumSize(uiWindowsControl(w->child), &width, &height);
if (GetClientRect(w->hwnd, &r) == 0)
/* TODO */;
windowMargns(w, &mx, &my);
width += 2 * mx;
height += 2 * my;
getClientRect(w->hwnd, &r);
// TODO discount margins
needsGrowing = FALSE;
if ((r.right - r.left) < width)
needsGrowing = TRUE;
if ((r.bottom - r.top) < height)
needsGrowing = TRUE;
if (needsGrowing)
/* TODO */;
if (!needsGrowing)
return;
// TODO figure out what to do with this function
// maybe split it into two so WM_GETMINMAXINFO can use it?
ensureMinimumWindowSize(w);
}
uiWindowsDefaultAssignControlIDZorder(uiWindow)
///////// TODO CONTINUE HERE
char *uiWindowTitle(uiWindow *w)
{
return uiWindowsWindowText(w->hwnd);
@ -269,12 +275,21 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
void uiWindowSetChild(uiWindow *w, uiControl *child)
{
if (w->child != NULL)
childRemove(w->child);
w->child = newChild(child, uiControl(w), w->hwnd);
LONG_PTR id;
HWND dummy;
if (w->child != NULL) {
childSetSoleControlID(w->child);
childQueueRelayout(w->child);
uiControlSetParent(w->child, NULL);
uiWindowsControlSetParentHWND(uiWindowsControl(w->child), NULL);
}
w->child = child;
if (w->child != NULL) {
uiControlSetParent(w->child, uiControl(w));
uiWindowsControlSetParentHWND(uiWindowsControl(w->child), w->hwnd);
id = 100;
dummy = NULL;
uiWindowsControlAssignControlIDZOrder(uiWindowsControl(w->child), &id, &dummy);
windowRelayout(w);
}
}
@ -286,7 +301,7 @@ int uiWindowMargined(uiWindow *w)
void uiWindowSetMargined(uiWindow *w, int margined)
{
w->margined = margined;
uiWindowsControlQueueRelayout(uiWindowsControl(w));
windowRelayout(w);
}
// 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
@ -319,7 +334,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
WCHAR *wtitle;
BOOL hasMenubarBOOL;
w = (uiWindow *) uiNewControl(uiWindow);
uiWindowsNewControl(uiWindow, w);
hasMenubarBOOL = FALSE;
if (hasMenubar)
@ -354,26 +369,17 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
uiWindowOnClosing(w, defaultOnClosing, NULL);
uiWindowsFinishNewControl(w, uiWindow);
uiControl(w)->CommitShow = windowCommitShow;
uiControl(w)->ContainerUpdateState = windowContainerUpdateState;
uiWindowsControl(w)->Relayout = windowRelayout;
uiWindowsControl(w)->ArrangeChildrenControlIDsZOrder = windowArrangeChildrenControlIDsZOrder;
return w;
}
// this cannot queue a resize because it's called by the resize handler
void ensureMinimumWindowSize(uiWindow *w)
{
uiWindowsControl *c;
intmax_t width, height;
RECT r;
c = uiWindowsControl(w);
(*(c->MinimumSize))(c, NULL, &width, &height);
if (GetClientRect(w->hwnd, &r) == 0)
logLastError(L"error getting client rect");
uiWindowsControlMinimumSize(uiWindowsControl(w), &width, &height);
getClientRect(w->hwnd, &r);
if (width < (r.right - r.left)) // preserve width if larger
width = r.right - r.left;
if (height < (r.bottom - r.top)) // preserve height if larger

View File

@ -120,3 +120,28 @@ 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");
}
// do these function even error out in any case other than invalid parameters?! I thought all windows had rects
void getClientRect(HWND hwnd, RECT *r)
{
if (GetClientRect(hwnd, r) == 0) {
logLastError(L"error getting window client rect");
// zero out the rect on error just to be safe
r->left = 0;
r->top = 0;
r->right = 0;
r->bottom = 0;
}
}
void getWindowRect(HWND hwnd, RECT *r)
{
if (GetWindowRect(hwnd, r) == 0) {
logLastError(L"error getting window rect");
// zero out the rect on error just to be safe
r->left = 0;
r->top = 0;
r->right = 0;
r->bottom = 0;
}
}