# HG changeset patch # User Olaf Wintermann # Date 1726426788 -7200 # Node ID a73c60adf1885fd15660ee0de4ef85881fa64f12 # Parent a362c76dbf998f53f7a630a31b19173c06e18986 port container to gtk4 diff -r a362c76dbf99 -r a73c60adf188 ui/gtk/button.c --- a/ui/gtk/button.c Sun Sep 15 20:19:52 2024 +0200 +++ b/ui/gtk/button.c Sun Sep 15 20:59:48 2024 +0200 @@ -112,13 +112,13 @@ gtk_toggle_button_set_active(button, value != 0 ? TRUE : FALSE); } -void ui_toggled_obs(GtkToggleToolButton *widget, UiVarEventData *event) { +void ui_toggled_obs(GtkToggleButton *widget, UiVarEventData *event) { UiEvent e; e.obj = event->obj; e.window = event->obj->window; e.document = event->obj->ctx->document; e.eventdata = event->var->value; - e.intval = gtk_toggle_tool_button_get_active(widget); + e.intval = gtk_toggle_button_get_active(widget); UiInteger *i = event->var->value; ui_notify_evt(i->observers, &e); diff -r a362c76dbf99 -r a73c60adf188 ui/gtk/button.h --- a/ui/gtk/button.h Sun Sep 15 20:19:52 2024 +0200 +++ b/ui/gtk/button.h Sun Sep 15 20:59:48 2024 +0200 @@ -43,13 +43,13 @@ void ui_button_clicked(GtkWidget *widget, UiEventData *event); -void ui_toggled_obs(GtkToggleToolButton *widget, UiVarEventData *event); +void ui_toggled_obs(GtkToggleButton *widget, UiVarEventData *event); UIWIDGET ui_checkbox_var(UiObject *obj, char *label, UiVar *var); UIWIDGET ui_radiobutton_var(UiObject *obj, char *label, UiVar *var); -void ui_radio_obs(GtkToggleToolButton *widget, UiVarEventData *event); +void ui_radio_obs(GtkToggleButton *widget, UiVarEventData *event); int64_t ui_radiobutton_get(UiInteger *value); void ui_radiobutton_set(UiInteger *value, int64_t i); diff -r a362c76dbf99 -r a73c60adf188 ui/gtk/container.c --- a/ui/gtk/container.c Sun Sep 15 20:19:52 2024 +0200 +++ b/ui/gtk/container.c Sun Sep 15 20:59:48 2024 +0200 @@ -52,7 +52,7 @@ } GtkWidget* ui_gtk_vbox_new(int spacing) { -#ifdef UI_GTK3 +#if GTK_MAJOR_VERSION >= 3 return gtk_box_new(GTK_ORIENTATION_VERTICAL, spacing); #else return gtk_vbox_new(FALSE, spacing); @@ -60,7 +60,7 @@ } GtkWidget* ui_gtk_hbox_new(int spacing) { -#ifdef UI_GTK3 +#if GTK_MAJOR_VERSION >= 3 return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, spacing); #else return gtk_hbox_new(FALSE, spacing); @@ -70,13 +70,14 @@ /* -------------------- Box Container -------------------- */ -UiContainer* ui_box_container(UiObject *obj, GtkWidget *box) { +UiContainer* ui_box_container(UiObject *obj, GtkWidget *box, UiSubContainerType type) { UiBoxContainer *ct = cxCalloc( obj->ctx->allocator, 1, sizeof(UiBoxContainer)); ct->container.widget = box; ct->container.add = ui_box_container_add; + ct->type = type; return (UiContainer*)ct; } @@ -95,7 +96,22 @@ } UiBool expand = fill; +#if GTK_MAJOR_VERSION >= 4 + gtk_box_append(GTK_BOX(ct->widget), widget); + GtkAlign align = expand ? GTK_ALIGN_FILL : GTK_ALIGN_START; + if(bc->type == UI_CONTAINER_VBOX) { + gtk_widget_set_valign(widget, align); + gtk_widget_set_vexpand(widget, expand); + gtk_widget_set_hexpand(widget, TRUE); + } else if(bc->type == UI_CONTAINER_HBOX) { + gtk_widget_set_halign(widget, align); + gtk_widget_set_hexpand(widget, expand); + gtk_widget_set_vexpand(widget, TRUE); + } + +#else gtk_box_pack_start(GTK_BOX(ct->widget), widget, expand, fill, 0); +#endif ui_reset_layout(ct->layout); ct->current = widget; @@ -115,7 +131,7 @@ return (UiContainer*)ct; } -#ifdef UI_GTK3 +#if GTK_MAJOR_VERSION >= 3 void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { UiGridContainer *grid = (UiGridContainer*)ct; @@ -202,7 +218,9 @@ void ui_scrolledwindow_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { // TODO: check if the widget implements GtkScrollable -#ifdef UI_GTK3 +#ifdef UI_GTK4 + gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(ct->widget), widget); +#elif defined(UI_GTK3) gtk_container_add(GTK_CONTAINER(ct->widget), widget); #else gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(ct->widget), widget); @@ -264,7 +282,7 @@ ct->add(ct, widget, TRUE); UiObject *newobj = uic_object_new(obj, box); - newobj->container = ui_box_container(obj, box); + newobj->container = ui_box_container(obj, box, type); uic_obj_add(obj, newobj); return widget; @@ -285,11 +303,11 @@ UI_APPLY_LAYOUT1(current, args); GtkWidget *widget; -#ifdef UI_GTK3 +#if GTK_MAJOR_VERSION >= 3 GtkWidget *grid = gtk_grid_new(); gtk_grid_set_column_spacing(GTK_GRID(grid), args.columnspacing); gtk_grid_set_row_spacing(GTK_GRID(grid), args.rowspacing); -#if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 12 +#if GTK_MAJOR_VERSION >= 3 && GTK_MINOR_VERSION >= 12 gtk_widget_set_margin_start(grid, args.margin); gtk_widget_set_margin_end(grid, args.margin); #else @@ -325,11 +343,16 @@ } +#if GTK_MAJOR_VERSION >= 4 +#define SCROLLEDWINDOW_NEW() gtk_scrolled_window_new() +#else +#define SCROLLEDWINDOW_NEW() gtk_scrolled_window_new(NULL, NULL) +#endif UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) { UiObject* current = uic_current_obj(obj); UI_APPLY_LAYOUT1(current, args); - GtkWidget *sw = gtk_scrolled_window_new(NULL, NULL); + GtkWidget *sw = SCROLLEDWINDOW_NEW(); UiObject *newobj = uic_object_new(obj, sw); newobj->container = ui_scrolledwindow_container(obj, sw); uic_obj_add(obj, newobj); @@ -345,7 +368,7 @@ /* -------------------- Splitpane -------------------- */ static GtkWidget* create_paned(UiOrientation orientation) { -#ifdef UI_GTK3 +#if GTK_MAJOR_VERSION >= 3 switch(orientation) { case UI_HORIZONTAL: return gtk_paned_new(GTK_ORIENTATION_HORIZONTAL); case UI_VERTICAL: return gtk_paned_new(GTK_ORIENTATION_VERTICAL); diff -r a362c76dbf99 -r a73c60adf188 ui/gtk/container.h --- a/ui/gtk/container.h Sun Sep 15 20:19:52 2024 +0200 +++ b/ui/gtk/container.h Sun Sep 15 20:59:48 2024 +0200 @@ -78,6 +78,7 @@ typedef struct UiBoxContainer { UiContainer container; + UiSubContainerType type; UiBool has_fill; } UiBoxContainer; @@ -111,7 +112,7 @@ UIWIDGET ui_box_create(UiObject *obj, UiContainerArgs args, UiSubContainerType type); -UiContainer* ui_box_container(UiObject *obj, GtkWidget *box); +UiContainer* ui_box_container(UiObject *obj, GtkWidget *box, UiSubContainerType type); void ui_box_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); UiContainer* ui_grid_container(UiObject *obj, GtkWidget *grid); diff -r a362c76dbf99 -r a73c60adf188 ui/gtk/window.c --- a/ui/gtk/window.c Sun Sep 15 20:19:52 2024 +0200 +++ b/ui/gtk/window.c Sun Sep 15 20:59:48 2024 +0200 @@ -150,7 +150,7 @@ */ GtkWidget *content_box = ui_gtk_vbox_new(0); BOX_ADD(GTK_BOX(vbox), content_box); - obj->container = ui_box_container(obj, content_box); + obj->container = ui_box_container(obj, content_box, UI_CONTAINER_VBOX); nwindows++; return obj; @@ -242,6 +242,12 @@ WINDOW_SHOW(GTK_WIDGET(dialog_w)); } + +#if GTK_MAJOR_VERSION >= 4 +static void ui_gtkfilechooser(UiObject *obj, GtkFileChooserAction action, unsigned int mode, ui_callback file_selected_callback, void *cbdata) { + // TODO +} +#else static void ui_gtkfilechooser(UiObject *obj, GtkFileChooserAction action, unsigned int mode, ui_callback file_selected_callback, void *cbdata) { char *button; char *title; @@ -282,7 +288,7 @@ if((mode & UI_FILEDIALOG_SELECT_MULTI) == UI_FILEDIALOG_SELECT_MULTI) { gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); } - + UiEvent evt; evt.obj = obj; evt.document = evt.obj->ctx->document; @@ -320,6 +326,7 @@ gtk_widget_destroy(dialog); } +#endif void ui_openfiledialog(UiObject *obj, unsigned int mode, ui_callback file_selected_callback, void *cbdata) { ui_gtkfilechooser(obj, GTK_FILE_CHOOSER_ACTION_OPEN, mode, file_selected_callback, cbdata);