Implemented uiTabInsertPageBefore() on Windows.

This commit is contained in:
Pietro Gagliardi 2015-05-06 14:09:20 -04:00
parent 84114f4913
commit d247e76866
3 changed files with 33 additions and 1 deletions

View File

@ -71,3 +71,7 @@ notes to self
- explicitly document label position at top-left corner
- mark that uiControlShow() on a uiWindow() will bring to front and give keyboard focus because of OS X
- make sure ShowWindow() is sufficient for zorder on Windows
- document that you can't use InsertBefore functions to insert before a nonexistent index (that includes if an array is empty)
- reconsider this, as the pointer array code does work with the first invalid index...
- we would need to test everything else with it
- note that uiTabInsertPageBefore() does NOT change the current tab page (it may change its index if inserting before the current page)

View File

@ -26,8 +26,9 @@ static void movePage1(uiButton *b, void *data)
{
if (moveBack) {
uiBoxDelete(mainBox, 1);
uiTabInsertPageBefore(mainTab, 0, uiControl(page1));
uiTabInsertPageBefore(mainTab, "Page 1", 0, uiControl(page1));
uiButtonSetText(b, moveOutText);
moveBack = 0;
return;
}
uiTabDeletePage(mainTab, 0);

View File

@ -233,6 +233,32 @@ static void tabAppendPage(uiTab *tt, const char *name, uiControl *child)
SendMessageW(t->hwnd, msgUpdateChild, 0, 0);
}
static void tabInsertPageBefore(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->bin = newBin();
binSetMainControl(page->bin, child);
binSetParent(page->bin, (uintptr_t) (t->hwnd));
// always hide; the current tab doesn't change
uiControlHide(uiControl(page->bin));
ptrArrayInsertBefore(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 uiTabInsertPageBefore()");
uiFree(wname);
}
static void tabDeletePage(uiTab *tt, uintmax_t n)
{
struct tab *t = (struct tab *) tt;
@ -322,6 +348,7 @@ uiTab *uiNewTab(void)
uiControl(t)->SysFunc = tabSysFunc;
uiTab(t)->AppendPage = tabAppendPage;
uiTab(t)->InsertPageBefore = tabInsertPageBefore;
uiTab(t)->DeletePage = tabDeletePage;
uiTab(t)->NumPages = tabNumPages;
uiTab(t)->Margined = tabMargined;