libui/redo/unix/tab.c

108 lines
2.1 KiB
C
Raw Normal View History

2015-06-11 18:07:06 -05:00
// 11 june 2015
#include "uipriv_unix.h"
struct tab {
uiTab t;
2015-06-11 18:07:06 -05:00
GtkWidget *widget;
GtkContainer *container;
GtkNotebook *notebook;
2015-06-29 21:49:12 -05:00
GArray *pages;
};
struct tabPage {
uiControl *holder;
GtkWidget *holderWidget;
uiControl *c;
int margined;
2015-06-11 18:07:06 -05:00
};
uiDefineControlType(uiTab, uiTypeTab, struct tab)
static uintptr_t tabHandle(uiControl *c)
{
struct tab *t = (struct tab *) c;
return (uintptr_t) (t->widget);
}
static void tabAppend(uiTab *tt, const char *name, uiControl *child)
{
struct tab *t = (struct tab *) tt;
2015-06-29 21:49:12 -05:00
uiTabInsertAt(tt, name, t->pages->len, child);
2015-06-11 18:07:06 -05:00
}
static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *child)
{
struct tab *t = (struct tab *) tt;
2015-06-29 21:49:12 -05:00
struct tabPage page;
2015-06-11 18:07:06 -05:00
2015-06-29 21:49:12 -05:00
page.holder = newHolder();
page.c = child;
holderSetChild(page.holder, page.c);
page.holderWidget = GTK_WIDGET(uiControlHandle(page.holder));
gtk_container_add(t->container, page.holderWidget);
gtk_notebook_set_tab_label_text(t->notebook, page.holderWidget, name);
gtk_notebook_reorder_child(t->notebook, page.holderWidget, n);
2015-06-29 21:49:12 -05:00
g_array_insert_val(t->pages, n, page);
2015-06-11 18:07:06 -05:00
}
static void tabDelete(uiTab *tt, uintmax_t n)
{
struct tab *t = (struct tab *) tt;
PUT_CODE_HERE;
}
static uintmax_t tabNumPages(uiTab *tt)
{
struct tab *t = (struct tab *) tt;
2015-06-29 21:49:12 -05:00
return t->pages->len;
2015-06-11 18:07:06 -05:00
}
static int tabMargined(uiTab *tt, uintmax_t n)
{
struct tab *t = (struct tab *) tt;
return PUT_CODE_HERE;
}
static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
{
struct tab *t = (struct tab *) tt;
PUT_CODE_HERE;
}
uiTab *uiNewTab(void)
{
struct tab *t;
t = (struct tab *) uiNewControl(uiTypeTab());
2015-06-11 18:07:06 -05:00
t->widget = gtk_notebook_new();
t->container = GTK_CONTAINER(t->widget);
t->notebook = GTK_NOTEBOOK(t->widget);
uiUnixMakeSingleWidgetControl(uiControl(t), t->widget);
gtk_notebook_set_scrollable(t->notebook, TRUE);
2015-06-11 18:07:06 -05:00
2015-06-29 21:49:12 -05:00
t->pages = g_array_new(FALSE, TRUE, sizeof (struct tabPage));
2015-06-11 18:07:06 -05:00
uiControl(t)->Handle = tabHandle;
uiTab(t)->Append = tabAppend;
uiTab(t)->InsertAt = tabInsertAt;
uiTab(t)->Delete = tabDelete;
uiTab(t)->NumPages = tabNumPages;
uiTab(t)->Margined = tabMargined;
uiTab(t)->SetMargined = tabSetMargined;
return uiTab(t);
}