Migrated the Windows backend to the new bin.
This commit is contained in:
parent
a2cf4908a3
commit
24d63adb51
6
bin.c
6
bin.c
|
@ -1,5 +1,6 @@
|
|||
// 27 april 2015
|
||||
#include "uipriv_windows.h"
|
||||
#include "ui.h"
|
||||
#include "uipriv.h"
|
||||
|
||||
struct bin {
|
||||
uiBin b;
|
||||
|
@ -14,7 +15,6 @@ struct bin {
|
|||
static void binDestroy(uiControl *c)
|
||||
{
|
||||
struct bin *b = (struct bin *) c;
|
||||
HWND hwnd;
|
||||
|
||||
// ensure clean removal by making sure the bin has no OS parent
|
||||
if (uiBinHasOSParent(uiBin(b)))
|
||||
|
@ -127,7 +127,7 @@ uiBin *newBin(void)
|
|||
uiBin(b)->HasOSParent = binHasOSParent;
|
||||
uiBin(b)->SetOSParent = binSetOSParent;
|
||||
uiBin(b)->RemoveOSParent = binRemoveOSParent;
|
||||
uiBin(b)->ResizeRoot = binResizeRoot;
|
||||
uiBin(b)->ResizeRootAndUpdate = binResizeRootAndUpdate;
|
||||
uiBin(b)->TranslateMargins = binTranslateMargins;
|
||||
|
||||
return uiBin(b);
|
||||
|
|
2
ui.idl
2
ui.idl
|
@ -66,7 +66,7 @@ interface Bin from Container {
|
|||
func HasOSParent(void) int;
|
||||
func SetOSParent(parent uintptr_t);
|
||||
func RemoveOSParent(void);
|
||||
func ResizeRoot(x intmax_t, y intmax_t, width intmax_t, height intmax_t);
|
||||
func ResizeRootAndUpdate(x intmax_t, y intmax_t, width intmax_t, height intmax_t);
|
||||
func TranslateMargins(left *intmax_t, top *intmax_t, right *intmax_t, bottom *intmax_t, d *Sizing);
|
||||
};
|
||||
|
||||
|
|
2
uipriv.h
2
uipriv.h
|
@ -14,7 +14,7 @@ extern uiBin *newBin(void);
|
|||
extern int binHasOSParent(uiBin *);
|
||||
extern void binSetOSParent(uiBin *, uintptr_t);
|
||||
extern void binRemoveOSParent(uiBin *);
|
||||
extern void binResizeRoot(uiBin *, intmax_t, intmax_t, intmax_t, intmax_t);
|
||||
extern void binResizeRootAndUpdate(uiBin *, intmax_t, intmax_t, intmax_t, intmax_t);
|
||||
extern void binTranslateMargins(uiBin *, intmax_t *, intmax_t *, intmax_t *, intmax_t *, uiSizing *);
|
||||
|
||||
// array.c
|
||||
|
|
|
@ -24,7 +24,7 @@ void binRemoveOSParent(uiBin *b)
|
|||
binSetOSParent(b, (uintptr_t) initialParent);
|
||||
}
|
||||
|
||||
void binResizeRoot(uiBin *b, intmax_t x, intmax_t y, intmax_t width, intmax_t height)
|
||||
void binResizeRootAndUpdate(uiBin *b, intmax_t x, intmax_t y, intmax_t width, intmax_t height)
|
||||
{
|
||||
HWND hwnd;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ struct tab {
|
|||
};
|
||||
|
||||
struct tabPage {
|
||||
uiContainer *bin;
|
||||
uiBin *bin;
|
||||
int margined;
|
||||
};
|
||||
|
||||
|
@ -61,7 +61,7 @@ static void onDestroy(void *data)
|
|||
while (t->pages->len != 0) {
|
||||
p = ptrArrayIndex(t->pages, struct tabPage *, 0);
|
||||
// we do have to remove the page from the tab control, though
|
||||
binSetParent(p->bin, 0);
|
||||
uiBinRemoveOSParent(p->bin);
|
||||
uiControlDestroy(uiControl(p->bin));
|
||||
ptrArrayDelete(t->pages, 0);
|
||||
uiFree(p);
|
||||
|
@ -153,8 +153,7 @@ static void resizeTab(struct tab *t, LONG width, LONG height)
|
|||
{
|
||||
LRESULT n;
|
||||
RECT r;
|
||||
struct tabPage *p;
|
||||
HWND binHWND;
|
||||
struct tabPage *page;
|
||||
|
||||
n = SendMessageW(t->hwnd, TCM_GETCURSEL, 0, 0);
|
||||
if (n == (LRESULT) (-1)) // no child selected; do nothing
|
||||
|
@ -169,9 +168,8 @@ static void resizeTab(struct tab *t, LONG width, LONG height)
|
|||
// convert to the display rectangle
|
||||
SendMessageW(t->hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM) (&r));
|
||||
|
||||
p = ptrArrayIndex(t->pages, struct tabPage *, n);
|
||||
binHWND = (HWND) uiControlHandle(uiControl(p->bin));
|
||||
moveWindow(binHWND, r.left, r.top, r.right - r.left, r.bottom - r.top);
|
||||
page = ptrArrayIndex(t->pages, struct tabPage *, n);
|
||||
uiBinResizeRootAndUpdate(page->bin, r.left, r.top, r.right - r.left, r.bottom - r.top);
|
||||
}
|
||||
|
||||
// and finally, because we have to resize parents, we have to handle resizes and updates
|
||||
|
@ -232,8 +230,8 @@ static void tabAppendPage(uiTab *tt, const char *name, uiControl *child)
|
|||
n = SendMessageW(t->hwnd, TCM_GETITEMCOUNT, 0, 0);
|
||||
|
||||
page->bin = newBin();
|
||||
binSetMainControl(page->bin, child);
|
||||
binSetParent(page->bin, (uintptr_t) (t->hwnd));
|
||||
uiBinSetMainControl(page->bin, child);
|
||||
uiBinSetOSParent(page->bin, (uintptr_t) (t->hwnd));
|
||||
if (n != 0) // if this isn't the first page, we have to hide the other controls
|
||||
uiControlHide(uiControl(page->bin));
|
||||
|
||||
|
@ -264,8 +262,8 @@ static void tabInsertPageBefore(uiTab *tt, const char *name, uintmax_t n, uiCont
|
|||
page = uiNew(struct tabPage);
|
||||
|
||||
page->bin = newBin();
|
||||
binSetMainControl(page->bin, child);
|
||||
binSetParent(page->bin, (uintptr_t) (t->hwnd));
|
||||
uiBinSetMainControl(page->bin, child);
|
||||
uiBinSetOSParent(page->bin, (uintptr_t) (t->hwnd));
|
||||
// always hide; the current tab doesn't change
|
||||
uiControlHide(uiControl(page->bin));
|
||||
|
||||
|
@ -295,10 +293,10 @@ static void tabDeletePage(uiTab *tt, uintmax_t n)
|
|||
ptrArrayDelete(t->pages, n);
|
||||
|
||||
// make sure the page's control isn't destroyed
|
||||
binSetMainControl(page->bin, NULL);
|
||||
uiBinSetMainControl(page->bin, NULL);
|
||||
|
||||
// see tabDestroy() above for details
|
||||
binSetParent(page->bin, 0);
|
||||
uiBinRemoveOSParent(page->bin);
|
||||
uiControlDestroy(uiControl(page->bin));
|
||||
uiFree(page);
|
||||
}
|
||||
|
@ -330,9 +328,9 @@ static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
|
|||
page = ptrArrayIndex(t->pages, struct tabPage *, n);
|
||||
page->margined = margined;
|
||||
if (page->margined)
|
||||
binSetMargins(page->bin, tabMargin, tabMargin, tabMargin, tabMargin);
|
||||
uiBinSetMargins(page->bin, tabMargin, tabMargin, tabMargin, tabMargin);
|
||||
else
|
||||
binSetMargins(page->bin, 0, 0, 0, 0);
|
||||
uiBinSetMargins(page->bin, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
uiTab *uiNewTab(void)
|
||||
|
|
|
@ -7,7 +7,7 @@ struct window {
|
|||
uiWindow w;
|
||||
HWND hwnd;
|
||||
HMENU menubar;
|
||||
uiContainer *bin;
|
||||
uiBin *bin;
|
||||
int hidden;
|
||||
BOOL shownOnce;
|
||||
int (*onClosing)(uiWindow *, void *);
|
||||
|
@ -21,7 +21,6 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
|
|||
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
|
||||
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
||||
RECT r;
|
||||
HWND binhwnd;
|
||||
|
||||
w = (struct window *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
||||
if (w == NULL) {
|
||||
|
@ -46,8 +45,7 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
|
|||
case msgUpdateChild:
|
||||
if (GetClientRect(w->hwnd, &r) == 0)
|
||||
logLastError("error getting window client rect for resize in windowWndProc()");
|
||||
binhwnd = (HWND) uiControlHandle(uiControl(w->bin));
|
||||
moveWindow(binhwnd, r.left, r.top, r.right - r.left, r.bottom - r.top);
|
||||
uiBinResizeRootAndUpdate(w->bin, r.left, r.top, r.right - r.left, r.bottom - r.top);
|
||||
return 0;
|
||||
case WM_CLOSE:
|
||||
if ((*(w->onClosing))(uiWindow(w), w->onClosingData))
|
||||
|
@ -90,7 +88,7 @@ static void windowDestroy(uiControl *c)
|
|||
ShowWindow(w->hwnd, SW_HIDE);
|
||||
// now destroy the bin
|
||||
// we need to remove the OS parent first
|
||||
binSetParent(w->bin, 0);
|
||||
uiBinRemoveOSParent(w->bin);
|
||||
uiControlDestroy(uiControl(w->bin));
|
||||
// now free the menubar, if any
|
||||
if (w->menubar != NULL)
|
||||
|
@ -207,7 +205,7 @@ static void windowSetChild(uiWindow *ww, uiControl *child)
|
|||
{
|
||||
struct window *w = (struct window *) ww;
|
||||
|
||||
binSetMainControl(w->bin, child);
|
||||
uiBinSetMainControl(w->bin, child);
|
||||
}
|
||||
|
||||
static int windowMargined(uiWindow *ww)
|
||||
|
@ -226,9 +224,9 @@ static void windowSetMargined(uiWindow *ww, int margined)
|
|||
|
||||
w->margined = margined;
|
||||
if (w->margined)
|
||||
binSetMargins(w->bin, windowMargin, windowMargin, windowMargin, windowMargin);
|
||||
uiBinSetMargins(w->bin, windowMargin, windowMargin, windowMargin, windowMargin);
|
||||
else
|
||||
binSetMargins(w->bin, 0, 0, 0, 0);
|
||||
uiBinSetMargins(w->bin, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -284,7 +282,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
|||
uiFree(wtitle);
|
||||
|
||||
w->bin = newBin();
|
||||
binSetParent(w->bin, (uintptr_t) (w->hwnd));
|
||||
uiBinSetOSParent(w->bin, (uintptr_t) (w->hwnd));
|
||||
|
||||
if (hasMenubar) {
|
||||
w->menubar = makeMenubar();
|
||||
|
|
Loading…
Reference in New Issue