--- a/ui/motif/container.c Thu Feb 06 22:36:29 2025 +0100 +++ b/ui/motif/container.c Fri Feb 07 21:57:32 2025 +0100 @@ -317,6 +317,7 @@ Widget content = XmCreateFrame(form, "tabviewcontent", xargs, n); // setup tabview object, that holds all relevant objects + tabview->obj = obj; tabview->form = form; tabview->tabbar = tabbar; tabview->content = content; @@ -325,7 +326,7 @@ tabview->select = ui_motif_tabview_select; tabview->add = ui_motif_tabview_add_tab; tabview->remove = ui_motif_tabview_remove; - tabview->tabs = cxArrayListCreateSimple(sizeof(UiTab), 8); + tabview->tabs = cxArrayListCreate(obj->ctx->allocator, NULL, sizeof(UiTab), 8); UiTabViewContainer *ct = ui_malloc(obj->ctx, sizeof(UiTabViewContainer)); ct->container.widget = form; @@ -364,8 +365,59 @@ tabview->add(tabview, -1, title, child); } +void ui_tabview_select(UIWIDGET tabview, int tab) { + UiMotifTabView *tabviewdata = NULL; + XtVaGetValues(tabview, XmNuserData, &tabviewdata, NULL); + if(tabviewdata) { + ui_motif_tabview_select(tabviewdata, tab); + } else { + fprintf(stderr, "ui_tabview_select: widget is not a tabview\n"); + } +} + +void ui_tabview_remove(UIWIDGET tabview, int tab) { + UiMotifTabView *tabviewdata = NULL; + XtVaGetValues(tabview, XmNuserData, &tabviewdata, NULL); + if(tabviewdata) { + ui_motif_tabview_remove(tabviewdata, tab); + } else { + fprintf(stderr, "ui_tabview_select: widget is not a tabview\n"); + } +} + +UiObject* ui_tabview_add(UIWIDGET tabview, const char *name, int tab_index) { + UiMotifTabView *tabviewdata = NULL; + XtVaGetValues(tabview, XmNuserData, &tabviewdata, NULL); + if(tabviewdata) { + Arg args[16]; + int n = 0; + + XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; + XtSetArg(args[n], XmNtopWidget, tabviewdata->tabbar); n++; + + Widget grid = XtCreateManagedWidget("vbox", gridClass, tabviewdata->content, args, n); + + UiObject *newobj = ui_calloc(tabviewdata->obj->ctx, 1, sizeof(UiObject)); + newobj->ctx = tabviewdata->obj->ctx; + newobj->widget = grid; + UiContainerX *container = ui_box_container(newobj, grid, UI_BOX_VERTICAL); + newobj->container_begin = container; + newobj->container_end = container; + return newobj; + } else { + fprintf(stderr, "ui_tabview_select: widget is not a tabview\n"); + return NULL; + } +} + void ui_motif_tabview_select(UiMotifTabView *tabview, int tab) { - + UiTab *t = cxListAt(tabview->tabs, tab); + if(t) { + ui_motif_tabview_change_tab(tabview, t); + } } static void ui_tab_button_callback(Widget widget, UiTab *tab, XtPointer d) { @@ -427,7 +479,23 @@ } void ui_motif_tabview_remove(UiMotifTabView *tabview, int index) { - + UiTab *tab = cxListAt(tabview->tabs, index); + if(tab) { + if(tab == tabview->current_tab) { + if(index > 0) { + ui_motif_tabview_select(tabview, index-1); + } else { + if(index < cxListSize(tabview->tabs)) { + ui_motif_tabview_select(tabview, index+1); + } else { + tabview->current_tab = NULL; + } + } + } + XtDestroyWidget(tab->tab_button); + XtDestroyWidget(tab->child); + cxListRemove(tabview->tabs, index); + } } void ui_motif_tabview_change_tab(UiMotifTabView *tabview, UiTab *tab) {