From 67192755763ef6669359623b4772c47d664c4b64 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 19 Nov 2015 16:57:15 -0500 Subject: [PATCH] Some uiTab work. --- haiku/tab.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/haiku/tab.cpp b/haiku/tab.cpp index 8933dac5..e5275b16 100644 --- a/haiku/tab.cpp +++ b/haiku/tab.cpp @@ -1,25 +1,62 @@ // 18 november 2015 +#include #include "uipriv_haiku.hpp" +using namespace std; + +struct tabPage { + BTab *tab; + BView *view; + struct singleChild *child; +}; struct uiTab { uiHaikuControl c; BTabView *tabview; + vector *pages; }; -uiHaikuDefineControl( +static void onDestroy(uiTab *); + +uiHaikuDefineControlWithOnDestroy( uiTab, // type name uiTabType, // type function - tabview // handle + tabview, // handle + onDestroy(hthis); // on destroy ) -void uiTabAppend(uiTab *t, const char *name, uiControl *c) +static void onDestroy(uiTab *t) { // TODO } +void uiTabAppend(uiTab *t, const char *name, uiControl *c) +{ + uiTabInsertAt(t, name, t->pages->size(), c); +} + +// see singlechild.cpp +static void attach(void *attachTo, BLayoutItem *what) +{ + BView *view = (BView *) attachTo; + + // TODO refine the interface around this + view->SetLayout((BLayout *) what); +} + void uiTabInsertAt(uiTab *t, const char *name, uintmax_t before, uiControl *c) { - // TODO + struct tabPage p; + + p.view = new BView(BRect(0, 0, 1, 1), NULL, + B_FOLLOW_ALL_SIDES, 0); + p.tab = new BTab(p.view); + p.child = newSingleChild(c, uiControl(t), attach, p.view); + + p.tab->SetLabel(name); + + // TODO insert in the correct place + t->tabview->AddTab(p.view, p.tab); + t->pages->push_back(p); } void uiTabDelete(uiTab *t, uintmax_t index) @@ -51,6 +88,10 @@ uiTab *uiNewTab(void) t = (uiTab *) uiNewControl(uiTabType()); t->tabview = new BTabView(BRect(0, 0, 1, 1), NULL); + // TODO scrollable + t->tabview->SetTabWidth(B_WIDTH_FROM_LABEL); + + t->pages = new vector(); uiHaikuFinishNewControl(t, uiTab);