From ae8bb69385743f065add1f2de26ce47efd94c2d5 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 27 Apr 2015 20:02:33 -0400 Subject: [PATCH] More uiWindow work. --- new/windows/OLDwindow.c | 77 ----------------------------------------- new/windows/window.c | 73 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 79 deletions(-) diff --git a/new/windows/OLDwindow.c b/new/windows/OLDwindow.c index 1000523b..b839bb6e 100644 --- a/new/windows/OLDwindow.c +++ b/new/windows/OLDwindow.c @@ -84,83 +84,6 @@ static int defaultOnClosing(uiWindow *w, void *data) return 1; } -static char *windowTitle(uiWindow *ww) -{ - struct window *w = (struct window *) ww; - WCHAR *wtext; - char *text; - - wtext = windowText(w->hwnd); - text = toUTF8(wtext); - uiFree(wtext); - return text; -} - -static void windowSetTitle(uiWindow *ww, const char *text) -{ - struct window *w = (struct window *) ww; - WCHAR *wtext; - - wtext = toUTF16(text); - if (SetWindowTextW(w->hwnd, wtext) == 0) - logLastError("error setting window title in uiWindowSetTitle()"); - uiFree(wtext); -} - -static void windowShow(uiWindow *ww) -{ - struct window *w = (struct window *) ww; - - if (w->shownOnce) { - ShowWindow(w->hwnd, SW_SHOW); - return; - } - w->shownOnce = TRUE; - ShowWindow(w->hwnd, nCmdShow); - if (UpdateWindow(w->hwnd) == 0) - logLastError("error calling UpdateWindow() after showing uiWindow for the first time"); -} - -static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data) -{ - struct window *w = (struct window *) ww; - - w->onClosing = f; - w->onClosingData = data; -} - -static void windowSetChild(uiWindow *ww, uiControl *c) -{ - struct window *w = (struct window *) ww; - - uiOSContainerSetMainControl(w->content, c); - // don't call uiOSContainerUpdate(); instead, synthesize a resize - // otherwise, we'll have a 0x0 content area at first - SendMessageW(w->hwnd, msgUpdateChild, 0, 0); -} - -static int windowMargined(uiWindow *ww) -{ - struct window *w = (struct window *) ww; - - return w->margined; -} - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define windowMargin 7 - -static void windowSetMargined(uiWindow *ww, int margined) -{ - struct window *w = (struct window *) ww; - - w->margined = margined; - if (w->margined) - uiOSContainerSetMargins(w->content, windowMargin, windowMargin, windowMargin, windowMargin); - else - uiOSContainerSetMargins(w->content, 0, 0, 0, 0); - uiOSContainerUpdate(w->content); -} - uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) { struct window *w; diff --git a/new/windows/window.c b/new/windows/window.c index 340ee6d8..221fdaa7 100644 --- a/new/windows/window.c +++ b/new/windows/window.c @@ -6,6 +6,9 @@ struct window { HWND hwnd; uiContainer *bin; int hidden; + BOOL shownOnce; + int (*onClosing)(uiWindow *, void *); + void *onClosingData; int margined; }; @@ -60,8 +63,15 @@ static void windowShow(uiControl *w) { struct window *w = (struct window *) c; - // TODO first show logic - ShowWindow(w->hwnd, SW_SHOW); + if (w->shownOnce) { + ShowWindow(w->hwnd, SW_SHOW); + w->hidden = 0; + return; + } + w->shownOnce = TRUE; + ShowWindow(w->hwnd, nCmdShow); + if (UpdateWindow(w->hwnd) == 0) + logLastError("error calling UpdateWindow() after showing uiWindow for the first time in windowShow()"); w->hidden = 0; } @@ -86,3 +96,62 @@ static void windowDisable(uiControl *c) EnableWindow(w->hwnd, FALSE); } + +static char *windowTitle(uiWindow *ww) +{ + struct window *w = (struct window *) ww; + WCHAR *wtext; + char *text; + + wtext = windowText(w->hwnd); + text = toUTF8(wtext); + uiFree(wtext); + return text; +} + +static void windowSetTitle(uiWindow *ww, const char *title) +{ + struct window *w = (struct window *) ww; + WCHAR *wtext; + + wtext = toUTF16(text); + if (SetWindowTextW(w->hwnd, wtext) == 0) + logLastError("error setting window title in uiWindowSetTitle()"); + uiFree(wtext); +} + +static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data) +{ + struct window *w = (struct window *) ww; + + w->onClosing = f; + w->onClosingData = data; +} + +static void windowSetChild(uiWindow *ww, uiControl *child) +{ + struct window *w = (struct window *) ww; + + binSetMainControl(w->bin, child); +} + +static int windowMargined(uiWindow *ww) +{ + struct window *w = (struct window *) ww; + + return w->margined; +} + +// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing +#define windowMargin 7 + +static void windowSetMargined(uiWindow *ww, int margined) +{ + struct window *w = (struct window *) ww; + + w->margined = margined; + if (w->margined) + binSetMargins(w->bin, windowMargin, windowMargin, windowMargin, windowMargin); + else + binSetMargins(w->bin, 0, 0, 0, 0); +}