From 365e61dad21a240a82126938d7df179489e8bcc6 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 12 Apr 2015 22:39:36 -0400 Subject: [PATCH] Finished the Windows uiParent conversion, I think. Now to test. --- new/tab_windows.c | 43 +++++++++++++---------------------------- new/window_windows.c | 46 ++++++++++++++++---------------------------- 2 files changed, 30 insertions(+), 59 deletions(-) diff --git a/new/tab_windows.c b/new/tab_windows.c index a4696d2..5fd4989 100644 --- a/new/tab_windows.c +++ b/new/tab_windows.c @@ -8,7 +8,7 @@ struct tab { }; struct tabPage { - uiControl *child; + uiParent *content; }; static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult) @@ -26,15 +26,15 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult) case TCN_SELCHANGING: n = SendMessageW((HWND) uiControlHandle(c), TCM_GETCURSEL, 0, 0); if (n != (LRESULT) (-1)) // if we're changing to a real tab - uiControlContainerHide(t->pages[n].child); + ShowWindow((HWND) uiParentHandle(t->pages[n].content), SW_HIDE); *lResult = FALSE; // and allow the change return TRUE; case TCN_SELCHANGE: n = SendMessageW((HWND) uiControlHandle(c), TCM_GETCURSEL, 0, 0); if (n != (LRESULT) (-1)) { // if we're changing to a real tab - uiControlContainerShow(t->pages[n].child); + ShowWindow((HWND) uiParentHandle(t->pages[n].content), SW_SHOW); // because we only resize the current child on resize, we'll need to trigger an update here - updateParent(uiControlHandle(c)); + uiParentUpdate(t->pages[n].content); } *lResult = 0; return TRUE; @@ -61,7 +61,7 @@ static void resizeTab(uiControl *c, LONG width, LONG height) struct tab *t = (struct tab *) (c->data); HWND hwnd; LRESULT n; - RECT r, margin; + RECT r; hwnd = (HWND) uiControlHandle(c); @@ -78,29 +78,16 @@ static void resizeTab(uiControl *c, LONG width, LONG height) // convert to the display rectangle SendMessageW(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM) (&r)); - margin.left = 0; - margin.top = 0; - margin.right = 0; - margin.bottom = 0; -/*TODO if (w->margined) { - margin.left = windowMargin; - margin.top = windowMargin; - margin.right = windowMargin; - margin.bottom = windowMargin; - } -*/ resize(t->pages[n].child, hwnd, r, margin); + if (MoveWindow((HWND) uiParentHandle(t->pages[n].content), r.leftm r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0) + logLastError("error resizing current tab page in resizeTab()"); } -// and finally, because we are a container, we have to handle resizes and updates +// and finally, because we have to resize parents, we have to handle resizes and updates static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { uiControl *c = (uiControl *) dwRefData; - LRESULT lResult; WINDOWPOS *wp = (WINDOWPOS *) lParam; - RECT r; - if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) - return lResult; switch (uMsg) { case WM_WINDOWPOSCHANGED: if ((wp->flags & SWP_NOSIZE) != 0) @@ -110,12 +97,6 @@ static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l // we have the window rect width as part of the WINDOWPOS; resize resizeTab(c, wp->cx, wp->cy); return lResult; - case msgUpdateChild: - if (GetWindowRect((HWND) uiControlHandle(c), &r) == 0) - logLastError("error getting window rect for Tab resize in tabSubProc()"); - // though these are in screen coordinates, we only need the width and height - resizeTab(c, r.right - r.left, r.bottom - r.top); - return 0; case WM_NCDESTROY: if ((*fv_RemoveWindowSubclass)(hwnd, tabSubProc, uIdSubclass) == FALSE) logLastError("error removing Tab resize handling subclass in tabSubProc()"); @@ -162,6 +143,7 @@ void uiTabAddPage(uiControl *c, const char *name, uiControl *child) HWND hwnd; TCITEMW item; LRESULT n; + uiParent *parent; WCHAR *wname; if (t->len >= t->cap) { @@ -172,10 +154,11 @@ void uiTabAddPage(uiControl *c, const char *name, uiControl *child) hwnd = (HWND) uiControlHandle(c); n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0); - t->pages[t->len].child = child; - uiControlSetParent(t->pages[t->len].child, (uintptr_t) hwnd); + parent = uiNewParent((uintptr_t) hwnd); + uiParentSetChild(parent, child); if (n != 0) // if this isn't the first page, we have to hide the other controls - uiControlContainerHide(t->pages[t->len].child); + ShowWindow((HWND) uiParentHandle(parent), SW_HIDE); + t->pages[t->len].content = parent; t->len++; ZeroMemory(&item, sizeof (TCITEMW)); diff --git a/new/window_windows.c b/new/window_windows.c index 00d8c1a..a54fd30 100644 --- a/new/window_windows.c +++ b/new/window_windows.c @@ -3,7 +3,7 @@ struct uiWindow { HWND hwnd; - uiControl *child; + uiParent *content; BOOL shownOnce; int (*onClosing)(uiWindow *, void *); void *onClosingData; @@ -12,16 +12,11 @@ struct uiWindow { #define uiWindowClass L"uiWindowClass" -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#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, margin; w = (uiWindow *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); if (w == NULL) { @@ -30,29 +25,13 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA // fall through to DefWindowProc() anyway return DefWindowProcW(hwnd, uMsg, wParam, lParam); } - if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) - return lResult; switch (uMsg) { case WM_WINDOWPOSCHANGED: - if ((wp->flags & SWP_NOSIZE) != 0) - break; - // fall through - case msgUpdateChild: - if (w->child == NULL) - break; if (GetClientRect(w->hwnd, &r) == 0) logLastError("error getting window client rect for resize in uiWindowWndProc()"); - 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); + contenthwnd = (HWND) uiParentHandle(content); + if (MoveWindow(contenthwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0) + logLastError("error resizing window content parent in uiWindowWndProc()"); return 0; case WM_CLOSE: if (!(*(w->onClosing))(w, w->onClosingData)) @@ -114,8 +93,10 @@ uiWindow *uiNewWindow(char *title, int width, int height) NULL, NULL, hInstance, w); if (w->hwnd == NULL) logLastError("error creating window in uiWindow()"); - uiFree(wtitle); + + w->content = uiNewParent((uintptr_t) (w->hwnd)); + return w; } @@ -175,8 +156,8 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) void uiWindowSetChild(uiWindow *w, uiControl *c) { - w->child = c; - uiControlSetParent(w->child, (uintptr_t) (w->hwnd)); + uiParentSetChild(w->content, c); + uiParentUpdate(w->content); } int uiWindowMargined(uiWindow *w) @@ -184,8 +165,15 @@ int uiWindowMargined(uiWindow *w) return w->margined; } +// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing +#define windowMargin 7 + void uiWindowSetMargined(uiWindow *w, int margined) { w->margined = margined; - updateParent((uintptr_t) (w->hwnd)); + if (w->margined) + uiParentSetMargins(w->content, windowMargin, windowMargin, windowMargin, windowMargin); + else + uiParentSetMargins(w->content, 0, 0, 0, 0); + uiParentUpdate(w->content); }