diff --git a/wpf/libui.msbuild b/wpf/libui.msbuild
index a65e6249..bd602bdf 100755
--- a/wpf/libui.msbuild
+++ b/wpf/libui.msbuild
@@ -85,6 +85,7 @@
false
+
false
diff --git a/wpf/main.cpp b/wpf/main.cpp
index 68b17b57..030c7baf 100644
--- a/wpf/main.cpp
+++ b/wpf/main.cpp
@@ -21,5 +21,6 @@ void uiMain(void)
void uiQuit(void)
{
+ // TODO this executes immediately, not later
(*app)->Shutdown();
}
diff --git a/wpf/tab.cpp b/wpf/tab.cpp
new file mode 100644
index 00000000..052cceb3
--- /dev/null
+++ b/wpf/tab.cpp
@@ -0,0 +1,125 @@
+// 26 november 2015
+#include "uipriv_wpf.hpp"
+
+// TODO save child alignments?
+
+using namespace System::Collections::Generic;
+
+ref class tabPage {
+public:
+ TabItem ^item;
+ uiControl *c;
+ Border ^border; // see uiTabSetMargined()
+ int margined;
+};
+
+struct uiTab {
+ uiWindowsControl c;
+ gcroot *tab;
+ gcroot ^> *pages;
+};
+
+static void onDestroy(uiTab *);
+
+uiWindowsDefineControlWithOnDestroy(
+ uiTab, // type name
+ uiTabType, // type function
+ tab, // handle
+ onDestroy(hthis); // on destroy
+)
+
+static void onDestroy(uiTab *t)
+{
+ List ^pages;
+
+ pages = *(t->pages);
+ while (pages->Count != 0) {
+ pages[0]->border->Child = nullptr;
+ uiControlSetParent(pages[0]->c, NULL);
+ uiControlDestroy(pages[0]->c);
+ pages->RemoveAt(0);
+ (*(t->tab))->Items->RemoveAt(0);
+ }
+ delete t->pages;
+}
+
+void uiTabAppend(uiTab *t, const char *name, uiControl *c)
+{
+ uiTabInsertAt(t, name, (*(t->pages))->Count, c);
+}
+
+void uiTabInsertAt(uiTab *t, const char *name, uintmax_t before, uiControl *c)
+{
+ tabPage ^p;
+
+ p = gcnew tabPage();
+ p->c = c;
+ p->border = gcnew Border();
+ p->item = gcnew TabItem();
+
+ p->border->Child = genericHandle(p->c);
+ p->item->Content = p->border;
+ p->item->Header = fromUTF8(name);
+
+ uiControlSetParent(p->c, uiControl(t));
+ (*(t->tab))->Items->Insert(before, p->item);
+ (*(t->pages))->Insert(before, p);
+ uiControlSetParent(p->c, NULL);
+}
+
+void uiTabDelete(uiTab *t, uintmax_t index)
+{
+ tabPage ^p;
+ List ^pages;
+
+ pages = (*(t->pages));
+ p = pages[index];
+ pages->RemoveAt(index);
+ (*(t->tab))->Items->RemoveAt(index);
+ p->border->Child = nullptr;
+}
+
+uintmax_t uiTabNumPages(uiTab *t)
+{
+ return (*(t->pages))->Count;
+}
+
+int uiTabMargined(uiTab *t, uintmax_t page)
+{
+ List ^pages;
+
+ pages = (*(t->pages));
+ return pages[page]->margined;
+}
+
+void uiTabSetMargined(uiTab *t, uintmax_t page, int margined)
+{
+ List ^pages;
+
+ pages = (*(t->pages));
+ pages[page]->margined = margined;
+ // TabItem margins/padding do NOT work the way we want them to
+ // we have to use a Border here too
+ // TODO Padding?
+ if (pages[page]->margined)
+ pages[page]->border->Margin = Thickness(10, 10, 10, 10);
+ else
+ pages[page]->border->Margin = Thickness(0, 0, 0, 0);
+}
+
+uiTab *uiNewTab(void)
+{
+ uiTab *t;
+
+ t = (uiTab *) uiNewControl(uiTabType());
+
+ t->tab = new gcroot();
+ *(t->tab) = gcnew TabControl();
+
+ t->pages = new gcroot ^>();
+ *(t->pages) = gcnew List();
+
+ uiWindowsFinishNewControl(t, uiTab, tab);
+
+ return t;
+}
diff --git a/wpf/xtest.go b/wpf/xtest.go
index 06915757..dfa42afe 100644
--- a/wpf/xtest.go
+++ b/wpf/xtest.go
@@ -14,6 +14,9 @@ var uiWindowSetMargined = libui.NewProc("uiWindowSetMargined")
var uiNewVerticalBox = libui.NewProc("uiNewVerticalBox")
var uiBoxAppend = libui.NewProc("uiBoxAppend")
var uiBoxSetPadded = libui.NewProc("uiBoxSetPadded")
+var uiNewTab = libui.NewProc("uiNewTab")
+var uiTabAppend = libui.NewProc("uiTabAppend")
+var uiTabSetMargined = libui.NewProc("uiTabSetMargined")
var uiControlShow = libui.NewProc("uiControlShow")
var uiMain = libui.NewProc("uiMain")
var uiQuit = libui.NewProc("uiQuit")
@@ -34,6 +37,7 @@ func main() {
uintptr(unsafe.Pointer(&s[0])),
320, 240, 0)
uiWindowOnClosing.Call(w, syscall.NewCallbackCDecl(onClosing), 0)
+ tab, _, _ := uiNewTab.Call()
box, _, _ := uiNewVerticalBox.Call()
btn, _, _ := uiNewButton.Call(
uintptr(unsafe.Pointer(&s[0])))
@@ -50,7 +54,16 @@ func main() {
btn, _, _ = uiNewButton.Call(
uintptr(unsafe.Pointer(&s[0])))
uiBoxAppend.Call(box, btn, 0)
- uiWindowSetChild.Call(w, box)
+ uiWindowSetChild.Call(w, tab)
+ uiTabAppend.Call(tab,
+ uintptr(unsafe.Pointer(&s[0])),
+ box)
+ uiTabSetMargined.Call(tab, 0, 1)
+ btn, _, _ = uiNewButton.Call(
+ uintptr(unsafe.Pointer(&s[0])))
+ uiTabAppend.Call(tab,
+ uintptr(unsafe.Pointer(&s[0])),
+ btn)
uiBoxSetPadded.Call(box, 1)
uiWindowSetMargined.Call(w, 1)
uiControlShow.Call(w)