diff -r 7e7c05af8f3a -r 634e3ce80afe ui/gtk/container.c --- a/ui/gtk/container.c Wed Oct 09 21:43:11 2024 +0200 +++ b/ui/gtk/container.c Sun Oct 13 11:05:38 2024 +0200 @@ -361,6 +361,7 @@ } +#if GTK_MAJOR_VERSION >= 4 static int stack_set_page(GtkWidget *stack, int index) { GtkSelectionModel *pages = gtk_stack_get_pages(GTK_STACK(stack)); GListModel *list = G_LIST_MODEL(pages); @@ -416,6 +417,65 @@ i->value = value; } } +#elif GTK_MAJOR_VERSION >= 3 +static GtkWidget* stack_get_child(GtkWidget *stack, int index) { + GList *children = gtk_container_get_children(GTK_CONTAINER(stack)); + if(children) { + return g_list_nth_data(children, index); + } + return NULL; +} + +void ui_stack_tab_select(UIWIDGET tabview, int tab) { + GtkWidget *child = stack_get_child(tabview, tab); + if(child) { + gtk_stack_set_visible_child(GTK_STACK(tabview), child); + } +} + +void ui_stack_tab_remove(UIWIDGET tabview, int tab) { + GtkWidget *child = stack_get_child(tabview, tab); + if(child) { + gtk_container_remove(GTK_CONTAINER(tabview), child); + } +} + +void ui_stack_tab_add(UIWIDGET widget, int index, const char *name, UIWIDGET child) { + gtk_stack_add_titled(GTK_STACK(widget), child, name, name); +} + +int64_t ui_stack_get(UiInteger *i) { + GtkWidget *visible = gtk_stack_get_visible_child(GTK_STACK(i->obj)); + GList *children = gtk_container_get_children(GTK_CONTAINER(i->obj)); + GList *elm = children; + int n = 0; + int64_t v = -1; + while(elm) { + GtkWidget *child = elm->data; + if(child == visible) { + v = n; + break; + } + + elm = elm->next; + n++; + } + g_list_free(children); + i->value = v; + return v; +} + +void ui_stack_set(UiInteger *i, int64_t value) { + GtkWidget *child = stack_get_child(i->obj, value); + if(child) { + gtk_stack_set_visible_child(GTK_STACK(i->obj), child); + i->value = value; + } +} + +#endif + + UiGtkTabView* ui_widget_get_tabview_data(UIWIDGET tabview) { @@ -464,6 +524,7 @@ } case UI_TABVIEW_DEFAULT: /* fall through */ case UI_TABVIEW_NAVIGATION_TOP: /* fall through */ + case UI_TABVIEW_INVISIBLE: /* fall through */ case UI_TABVIEW_NAVIGATION_TOP2: { widget = gtk_notebook_new(); data_widget = widget; @@ -472,11 +533,10 @@ data->add_tab = ui_notebook_tab_add; getfunc = ui_notebook_get; setfunc = ui_notebook_set; - /* fall through */ - } - case UI_TABVIEW_INVISIBLE: { - gtk_notebook_set_show_tabs(GTK_NOTEBOOK(widget), FALSE); - gtk_notebook_set_show_border(GTK_NOTEBOOK(widget), FALSE); + if(args.tabview == UI_TABVIEW_INVISIBLE) { + gtk_notebook_set_show_tabs(GTK_NOTEBOOK(widget), FALSE); + gtk_notebook_set_show_border(GTK_NOTEBOOK(widget), FALSE); + } break; } }