From 73f68412726f294ff4668e468fb595bb77d50e7e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 9 Apr 2015 13:51:01 -0400 Subject: [PATCH] Implemented uiWindowSetMargined() on Windows. --- new/container_windows.c | 6 +++++- new/uipriv_windows.h | 2 +- new/window_windows.c | 26 ++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/new/container_windows.c b/new/container_windows.c index a8e28a0..f4d00ba 100644 --- a/new/container_windows.c +++ b/new/container_windows.c @@ -55,7 +55,7 @@ BOOL sharedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT * return FALSE; } -void resize(uiControl *control, HWND parent, RECT r) +void resize(uiControl *control, HWND parent, RECT r, RECT margin) { uiSizing d; HDC dc; @@ -83,6 +83,10 @@ void resize(uiControl *control, HWND parent, RECT r) logLastError("error restoring previous font into device context in resize()"); if (ReleaseDC(parent, dc) == 0) logLastError("error releasing DC in resize()"); + r.left += uiDlgUnitToX(margin.left, d.baseX); + r.top += uiDlgUnitToY(margin.top, d.baseY); + r.right -= uiDlgUnitToX(margin.right, d.baseX); + r.bottom -= uiDlgUnitToY(margin.bottom, d.baseY); (*(control->resize))(control, r.left, r.top, r.right - r.left, r.bottom - r.top, &d); } diff --git a/new/uipriv_windows.h b/new/uipriv_windows.h index 2baa7e8..180937e 100644 --- a/new/uipriv_windows.h +++ b/new/uipriv_windows.h @@ -59,7 +59,7 @@ struct uiSizing { int baseY; LONG internalLeading; }; -extern void resize(uiControl *, HWND, RECT); +extern void resize(uiControl *, HWND, RECT, RECT); // comctl32_windows.c extern BOOL (*WINAPI fv_SetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR); diff --git a/new/window_windows.c b/new/window_windows.c index 2a5603f..4e87d3e 100644 --- a/new/window_windows.c +++ b/new/window_windows.c @@ -7,17 +7,21 @@ struct uiWindow { BOOL shownOnce; int (*onClosing)(uiWindow *, void *); void *onClosingData; + int margined; }; #define uiWindowClass L"uiWindowClass" +// TODO get source +#define windowMargin 7 + static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { uiWindow *w; CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; LRESULT lResult; WINDOWPOS *wp = (WINDOWPOS *) lParam; - RECT r; + RECT r, margin; w = (uiWindow *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); if (w == NULL) { @@ -38,7 +42,17 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA break; if (GetClientRect(w->hwnd, &r) == 0) logLastError("error getting window client rect for resize in uiWindowWndProc()"); - resize(w->child, w->hwnd, r); + margin.left = 0; + margin.top = 0; + margin.right = 0; + margin.bottom = 0; + if (w->margined) { + margin.left = windowMargin; + margin.top = windowMargin; + margin.right = windowMargin; + margin.bottom = windowMargin; + } + resize(w->child, w->hwnd, r, margin); return 0; case WM_CLOSE: if (!(*(w->onClosing))(w, w->onClosingData)) @@ -165,3 +179,11 @@ void uiWindowSetChild(uiWindow *w, uiControl *c) w->child = c; (*(w->child->setParent))(w->child, (uintptr_t) (w->hwnd)); } + +// TODO uiWindowMargined + +void uiWindowSetMargined(uiWindow *w, int margined) +{ + w->margined = margined; + updateParent((uintptr_t) (w->hwnd)); +}