More tab work and tab TODOs.

This commit is contained in:
Pietro Gagliardi 2015-06-01 21:25:57 -04:00
parent c96fa44786
commit d90eeb84f7
2 changed files with 1 additions and 121 deletions

View File

@ -93,112 +93,6 @@ static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
return DefSubclassProc(hwnd, uMsg, wParam, lParam);
}
#define tabCapGrow 32
static void tabAppend(uiTab *tt, const char *name, uiControl *child)
{
struct tab *t = (struct tab *) tt;
TCITEMW item;
LRESULT n;
struct tabPage *page;
WCHAR *wname;
page = uiNew(struct tabPage);
n = SendMessageW(t->hwnd, TCM_GETITEMCOUNT, 0, 0);
page->control = child;
uiControlSetParent(page->control, uiControl(t));
if (n != 0) // if this isn't the first page, we have to hide the other controls
uiControlHide(page->control);
ptrArrayAppend(t->pages, page);
ZeroMemory(&item, sizeof (TCITEMW));
item.mask = TCIF_TEXT;
wname = toUTF16(name);
item.pszText = wname;
// MSDN's example code uses the first invalid index directly for this
if (SendMessageW(t->hwnd, TCM_INSERTITEM, (WPARAM) n, (LPARAM) (&item)) == (LRESULT) -1)
logLastError("error adding tab to Tab in uiTabAddPage()");
uiFree(wname);
// if this is the first tab, Windows will automatically show it /without/ sending a TCN_SELCHANGE notification
// so we need to manually resize the tab ourselves
// don't use uiContainerUpdate() for the same reason as in the TCN_SELCHANGE handler
uiControlQueueResize(page->control);
}
static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *child)
{
struct tab *t = (struct tab *) tt;
TCITEMW item;
struct tabPage *page;
WCHAR *wname;
page = uiNew(struct tabPage);
page->control = child;
uiControlSetParent(page->control, uiControl(t));
// always hide; the current tab doesn't change
uiControlHide(page->control);
ptrArrayInsertAt(t->pages, n, page);
ZeroMemory(&item, sizeof (TCITEMW));
item.mask = TCIF_TEXT;
wname = toUTF16(name);
item.pszText = wname;
if (SendMessageW(t->hwnd, TCM_INSERTITEM, (WPARAM) n, (LPARAM) (&item)) == (LRESULT) -1)
logLastError("error adding tab to Tab in uiTabInsertAt()");
uiFree(wname);
}
static void tabDelete(uiTab *tt, uintmax_t n)
{
struct tab *t = (struct tab *) tt;
struct tabPage *page;
// first delete the tab from the tab control
// if this is the current tab, no tab will be selected, which is good
if (SendMessageW(t->hwnd, TCM_DELETEITEM, (WPARAM) n, 0) == FALSE)
logLastError("error deleting Tab page in tabDelete()");
// now delete the page itself
page = ptrArrayIndex(t->pages, struct tabPage *, n);
ptrArrayDelete(t->pages, n);
// and keep the page control alive
uiControlSetParent(page->control, NULL);
uiFree(page);
}
static uintmax_t tabNumPages(uiTab *tt)
{
struct tab *t = (struct tab *) tt;
return t->pages->len;
}
static int tabMargined(uiTab *tt, uintmax_t n)
{
struct tab *t = (struct tab *) tt;
struct tabPage *page;
page = ptrArrayIndex(t->pages, struct tabPage *, n);
return page->margined;
}
static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
{
struct tab *t = (struct tab *) tt;
struct tabPage *page;
page = ptrArrayIndex(t->pages, struct tabPage *, n);
page->margined = margined;
uiControlQueueResize(page->control);
}
uiTab *uiNewTab(void)
{
struct tab *t;
@ -247,18 +141,3 @@ uiTab *uiNewTab(void)
return uiTab(t);
}
// unfortunately WS_TABSTOP and WS_EX_CONTROLPARENT are mutually exclusive, so we have to toggle between them
// see main.c for more details
void tabEnterTabNavigation(HWND hwnd)
{
setStyle(hwnd, getStyle(hwnd) & ~WS_TABSTOP);
setExStyle(hwnd, getExStyle(hwnd) | WS_EX_CONTROLPARENT);
}
void tabLeaveTabNavigation(HWND hwnd)
{
setExStyle(hwnd, getExStyle(hwnd) & ~WS_EX_CONTROLPARENT);
setStyle(hwnd, getStyle(hwnd) | WS_TABSTOP);
}

View File

@ -3,6 +3,7 @@
// TODO
// - test background drawing with visual styles off
// - dynamically apply the WS_TABSTOP flag based on number of tabs
struct tab {
uiTab t;