From 4db24bff052c7a1e294dd122c423c63b1a80c7f1 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 1 Jun 2015 21:01:26 -0400 Subject: [PATCH] Implemented tabContainerUpdateState() and removed migrated code from windows/OLDtab.c. --- redo/windows/OLDtab.c | 124 ------------------------------------------ redo/windows/tab.c | 15 ++++- 2 files changed, 14 insertions(+), 125 deletions(-) diff --git a/redo/windows/OLDtab.c b/redo/windows/OLDtab.c index 9768fd4a..db0cbbd1 100644 --- a/redo/windows/OLDtab.c +++ b/redo/windows/OLDtab.c @@ -11,64 +11,6 @@ struct tab { void (*baseSysFunc)(uiControl *, uiControlSysFuncParams *); }; -struct tabPage { - uiControl *control; - int margined; -}; - -static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult) -{ - return FALSE; -} - -// we have to handle hiding and showing of tab pages ourselves -static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult) -{ - struct tab *t = (struct tab *) c; - struct tabPage *page; - LRESULT n; - - if (nm->code != TCN_SELCHANGING && nm->code != TCN_SELCHANGE) - return FALSE; - n = SendMessageW(t->hwnd, TCM_GETCURSEL, 0, 0); - if (n == (LRESULT) (-1)) // not changing from/to a page; nothing to do - return FALSE; - page = ptrArrayIndex(t->pages, struct tabPage *, n); - if (nm->code == TCN_SELCHANGING) { - // changing from a real page - uiControlContainerHide(page->control); - *lResult = FALSE; // and allow the change - return TRUE; - } - // otherwise it's TCN_SELCHANGE - // and we're changing to a real page - uiControlContainerShow(page->control); - uiControlQueueResize(page->control); - *lResult = 0; - return TRUE; -} - -static void onDestroy(void *data) -{ - struct tab *t = (struct tab *) data; - struct tabPage *page; - - // first, hide the widget to avoid flicker - ShowWindow(t->hwnd, SW_HIDE); - // because the pages don't have by a libui paent, we can simply destroy them - while (t->pages->len != 0) { - page = ptrArrayIndex(t->pages, struct tabPage *, 0); - // we do have to remove the page from the tab control, though - uiControlSetParent(page->control, NULL); - uiControlDestroy(page->control); - ptrArrayDelete(t->pages, 0); - uiFree(page); - } - // and finally destroy ourselves - ptrArrayDestroy(t->pages); - uiFree(t); -} - // from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx #define tabMargin 7 @@ -101,72 +43,6 @@ static void tabPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_ *height = r.bottom - r.top; } -static void tabResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d) -{ - struct tab *t = (struct tab *) c; - LRESULT current; - struct tabPage *curpage; - - (*(t->baseResize))(uiControl(t), x, y, width, height, d); - current = SendMessageW(t->hwnd, TCM_GETCURSEL, 0, 0); - if (current != (LRESULT) (-1)) { - curpage = ptrArrayIndex(t->pages, struct tabPage *, current); - uiControlQueueResize(curpage->control); - } -} - -static void tabComputeChildSize(uiControl *c, intmax_t *x, intmax_t *y, intmax_t *width, intmax_t *height, uiSizing *d) -{ - struct tab *t = (struct tab *) c; - LRESULT n; - RECT r; - struct tabPage *page; - - // first figure out what the content area for pages is - if (GetWindowRect(t->hwnd, &r) == 0) - logLastError("error getting tab window rect in tabComputeChildSize()"); - // convert to the display rectangle - SendMessageW(t->hwnd, TCM_ADJUSTRECT, (WPARAM) TRUE, (LPARAM) (&r)); - *x = r.left; - *y = r.top; - *width = r.right - r.left; - *height = r.bottom - r.top; - - n = SendMessageW(t->hwnd, TCM_GETCURSEL, 0, 0); - if (n == (LRESULT) (-1)) // no child selected; do nothing - return; - page = ptrArrayIndex(t->pages, struct tabPage *, n); - if (page->margined) { - // TODO - } -} - -static void tabEnable(uiControl *c) -{ - struct tab *t = (struct tab *) c; - struct tabPage *page; - uintmax_t i; - - (*(t->baseEnable))(uiControl(t)); - for (i = 0; i < t->pages->len; i++) { - page = ptrArrayIndex(t->pages, struct tabPage *, i); - uiControlContainerEnable(page->control); - } -} - -static void tabDisable(uiControl *c) -{ - struct tab *t = (struct tab *) c; - struct tabPage *page; - uintmax_t i; - - (*(t->baseDisable))(uiControl(t)); - for (i = 0; i < t->pages->len; i++) { - page = ptrArrayIndex(t->pages, struct tabPage *, i); - uiControlContainerDisable(page->control); - } -} - static void tabSysFunc(uiControl *c, uiControlSysFuncParams *p) { struct tab *t = (struct tab *) c; diff --git a/redo/windows/tab.c b/redo/windows/tab.c index 8cdd7bdb..273f76ce 100644 --- a/redo/windows/tab.c +++ b/redo/windows/tab.c @@ -2,7 +2,7 @@ #include "uipriv_windows.h" // TODO -// - container update state +// - test background drawing with visual styles off struct tab { uiTab t; @@ -112,6 +112,18 @@ static void tabResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intm uiFreeSizing(dchild); } +static void tabContainerUpdateState(uiControl *c) +{ + struct tab *t = (struct tab *) c; + uiControl *page; + uintmax_t i; + + for (i = 0; i < t->pages->len; i++) { + page = ptrArrayIndex(t->pages, uiControl *, i); + uiControlUpdateState(page); + } +} + static void tabAppend(uiTab *tt, const char *name, uiControl *child) { struct tab *t = (struct tab *) tt; @@ -221,6 +233,7 @@ uiTab *uiNewTab(void) uiControl(t)->Resize = tabResize; t->baseCommitDestroy = uiControl(t)->CommitDestroy; uiControl(t)->CommitDestroy = tabCommitDestroy; + uiControl(t)->ContainerUpdateState = tabContainerUpdateState; uiTab(t)->Append = tabAppend; uiTab(t)->InsertAt = tabInsertAt;