From 1a55d1fcb3c3552cb9f3247b184a30ff57a31ca1 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 30 May 2015 12:28:52 -0400 Subject: [PATCH] Started splitting the role of a tab page over to a new internal control. --- redo/windows/GNUmakeinc.mk | 1 + redo/windows/tab.c | 53 +++++++++++++++-------------------- redo/windows/tabpage.c | 53 +++++++++++++++++++++++++++++++++++ redo/windows/uipriv_windows.h | 3 ++ 4 files changed, 80 insertions(+), 30 deletions(-) create mode 100644 redo/windows/tabpage.c diff --git a/redo/windows/GNUmakeinc.mk b/redo/windows/GNUmakeinc.mk index 20974388..0b9b3b02 100644 --- a/redo/windows/GNUmakeinc.mk +++ b/redo/windows/GNUmakeinc.mk @@ -26,6 +26,7 @@ osCFILES = \ windows/spinbox.c \ windows/stddialogs.c \ windows/tab.c \ + windows/tabpage.c \ windows/text.c \ windows/util.c \ windows/utilwin.c \ diff --git a/redo/windows/tab.c b/redo/windows/tab.c index 168d6d9f..54c4f80b 100644 --- a/redo/windows/tab.c +++ b/redo/windows/tab.c @@ -12,11 +12,6 @@ struct tab { void (*baseCommitDestroy)(uiControl *); }; -struct tabPage { - uiControl *control; - int margined; -}; - uiDefineControlType(uiTab, uiTypeTab, struct tab) // utility functions @@ -28,17 +23,17 @@ static LRESULT curpage(struct tab *t) static void showHidePage(struct tab *t, LRESULT which, int hide) { - struct tabPage *page; + uiControl *page; if (which == (LRESULT) (-1)) return; - page = ptrArrayIndex(t->pages, struct tabPage *, which); + page = ptrArrayIndex(t->pages, uiControl *, which); if (hide) -;//TODO uiControlContainerHide(page->control); + uiControlHide(page); else { -//TODO uiControlContainerShow(page->control); + uiControlShow(page); // we only resize the current page, so we have to do this here - uiControlQueueResize(page->control); + uiControlQueueResize(page); } } @@ -128,7 +123,7 @@ static void tabAppend(uiTab *tt, const char *name, uiControl *child) static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *child) { struct tab *t = (struct tab *) tt; - struct tabPage *page; + uiControl *page; LRESULT hide, show; TCITEMW item; WCHAR *wname; @@ -136,11 +131,10 @@ static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *chi // see below hide = curpage(t); - page = uiNew(struct tabPage); - page->control = child; - uiControlSetParent(page->control, uiControl(t)); + page = newTabPage(child); + uiControlSetParent(page, uiControl(t)); // and make it invisible at first; we show it later if needed -//TODO uiControlContainerHide(page->control); + uiControlHide(page); ptrArrayInsertAt(t->pages, n, page); ZeroMemory(&item, sizeof (TCITEMW)); @@ -162,7 +156,7 @@ static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *chi static void tabDelete(uiTab *tt, uintmax_t n) { struct tab *t = (struct tab *) tt; - struct tabPage *page; + uiControl *page; // first delete the tab from the tab control // if this is the current tab, no tab will be selected, which is good @@ -170,15 +164,13 @@ static void tabDelete(uiTab *tt, uintmax_t n) logLastError("error deleting uiTab tab in tabDelete()"); // now delete the page itself - page = ptrArrayIndex(t->pages, struct tabPage *, n); + page = ptrArrayIndex(t->pages, uiControl *, n); ptrArrayDelete(t->pages, n); - // and keep the page control alive - uiControlSetParent(page->control, NULL); - // and show it again, as we don't know where it will go next -//TODO uiControlContainerShow(page->control); - - uiFree(page); + // and free the page + // this will keep the control alive + uiControlSetParent(page, NULL); + uiControlDestroy(page); } static uintmax_t tabNumPages(uiTab *tt) @@ -191,20 +183,21 @@ static uintmax_t tabNumPages(uiTab *tt) static int tabMargined(uiTab *tt, uintmax_t n) { struct tab *t = (struct tab *) tt; - struct tabPage *page; + uiControl *page; - page = ptrArrayIndex(t->pages, struct tabPage *, n); - return page->margined; + page = ptrArrayIndex(t->pages, uiControl *, n); +//TODO return page->margined; + return 0; } static void tabSetMargined(uiTab *tt, uintmax_t n, int margined) { struct tab *t = (struct tab *) tt; - struct tabPage *page; + uiControl *page; - page = ptrArrayIndex(t->pages, struct tabPage *, n); - page->margined = margined; - uiControlQueueResize(page->control); + page = ptrArrayIndex(t->pages, uiControl *, n); +//TODO page->margined = margined; +//TODO uiControlQueueResize(page->control); } uiTab *uiNewTab(void) diff --git a/redo/windows/tabpage.c b/redo/windows/tabpage.c new file mode 100644 index 00000000..c9508c7d --- /dev/null +++ b/redo/windows/tabpage.c @@ -0,0 +1,53 @@ +// 30 may 2015 +#include "uicontrol_windows.h" + +// This is a special internal control type that handles tab pages. +// This doesn't use the container class, but rather a subclassed WC_DIALOG, as that supports tab textures properly. +// The standard property sheet control oes the same thing. +// TODO (long term) figure out how to use uiContainer with this + +struct tabPage { + uiControl c; + HWND hwnd; + uiControl *control; + int margined; +}; + +uiDefineControlType(tabPage, tabPageType, struct tabPage) + +// TODO override methods +// TODO when overriding CommitDestroy, DO NOT DESTROY THE CHILD + +static uintptr_t tabPageHandle(uiControl *c) +{ + struct tabPage *t = (struct tabPage *) c; + + return (uintptr_t) (t->hwnd); +} + +uiControl *newTabPage(uiControl *child) +{ + struct tabPage *t; + HRESULT hr; + + t = (struct tabPage *) uiWindowsNewSingleHWNDControl(tabPageType()); + + t->hwnd = uiWindowsUtilCreateControlHWND(WS_EX_CONTROLPARENT, + WC_DIALOGW, L"", + 0, + hInstance, NULL, + FALSE); + + hr = EnableThemeDialogTexture(t->hwnd, ETDT_ENABLE | ETDT_USETABTEXTURE | ETDT_ENABLETAB); + if (hr != S_OK) + logHRESULT("error setting tab page background in newTabPage()", hr); + + // TODO subclass hwnd to handle events + + t->control = child; + uiControlSetParent(t->control, uiControl(t)); + + uiControl(t)->Handle = tabPageHandle; + + return uiControl(t); +} diff --git a/redo/windows/uipriv_windows.h b/redo/windows/uipriv_windows.h index ba950a41..4d1e1878 100644 --- a/redo/windows/uipriv_windows.h +++ b/redo/windows/uipriv_windows.h @@ -131,3 +131,6 @@ extern void endDialogHelper(HWND); // control.c extern void setSingleHWNDFuncs(uiControl *); + +// tabpage.c +extern uiControl *newTabPage(uiControl *);