From 5a2a7e58b0221e98466d788340710817d74fe710 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 27 Nov 2021 16:04:35 +0200 Subject: [PATCH 40/40] gtk3x: Replace gtk_bin_get_child() calls gtk_bin_get_child() goes away in gtk-3.98.4. Replace its uses in gtk3x-client with modern constructs. See osdn #43286 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/dialogs.c | 8 ++++---- client/gui-gtk-4.0/gtkcompat.h | 7 +++++++ client/gui-gtk-4.0/gui_main.c | 2 +- client/gui-gtk-4.0/gui_stuff.c | 9 +++++++++ client/gui-gtk-4.0/gui_stuff.h | 1 + client/gui-gtk-4.0/optiondlg.c | 10 +++++----- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/client/gui-gtk-4.0/dialogs.c b/client/gui-gtk-4.0/dialogs.c index 65ac7fec21..54f6fbc304 100644 --- a/client/gui-gtk-4.0/dialogs.c +++ b/client/gui-gtk-4.0/dialogs.c @@ -513,7 +513,7 @@ static void select_nation(int nation, const char *leadername, bool is_male, int style_id) { - GtkEntryBuffer *buffer = gtk_entry_get_buffer(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(races_leader)))); + GtkEntryBuffer *buffer = gtk_entry_get_buffer(GTK_ENTRY(gtk_combo_box_get_child(GTK_COMBO_BOX(races_leader)))); selected_nation = nation; @@ -969,7 +969,7 @@ static void create_races_dialog(struct player *pplayer) /* Do our best to turn the text-entry widget into something more * like a cell-view: disable editing, and focusing (which removes * the caret). */ - GtkWidget *entry = gtk_bin_get_child(GTK_BIN(nationsets_chooser)); + GtkWidget *entry = gtk_combo_box_get_child(GTK_COMBO_BOX(nationsets_chooser)); gtk_editable_set_editable(GTK_EDITABLE(entry), FALSE); gtk_widget_set_can_focus(entry, FALSE); @@ -1329,7 +1329,7 @@ static void races_leader_callback(void) const gchar *name; name = - gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(races_leader))))); + gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(gtk_combo_box_get_child(GTK_COMBO_BOX(races_leader))))); if (selected_nation != -1 &&(pleader = nation_leader_by_name(nation_by_number(selected_nation), @@ -1402,7 +1402,7 @@ static void races_response(GtkWidget *w, gint response, gpointer data) } s = gtk_entry_buffer_get_text(gtk_entry_get_buffer( - GTK_ENTRY(gtk_bin_get_child(GTK_BIN(races_leader))))); + GTK_ENTRY(gtk_combo_box_get_child(GTK_COMBO_BOX(races_leader))))); /* Perform a minimum of sanity test on the name. */ /* This could call is_allowed_player_name if it were available. */ diff --git a/client/gui-gtk-4.0/gtkcompat.h b/client/gui-gtk-4.0/gtkcompat.h index 87d119cadb..0175749c60 100644 --- a/client/gui-gtk-4.0/gtkcompat.h +++ b/client/gui-gtk-4.0/gtkcompat.h @@ -49,6 +49,13 @@ void gtk_button_set_has_frame(GtkButton *btn, bool shadow); #define gtk_button_set_child(_but_, _child_) \ gtk_container_add(GTK_CONTAINER(_but_), _child_) +#define gtk_combo_box_get_child(_box_) \ + gtk_bin_get_child(GTK_BIN(_box_)) +#define gtk_button_get_child(_but_) \ + gtk_bin_get_child(GTK_BIN(_but_)) +#define gtk_window_get_child(_win_) \ + gtk_bin_get_child(GTK_BIN(_win_)) + #endif /* GTK version < 3.98.4 */ diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 004d57ff10..9cf55c21a3 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -1592,7 +1592,7 @@ static void setup_widgets(void) /* Other things to take care of */ - gtk_widget_show(gtk_bin_get_child(GTK_BIN(toplevel))); + gtk_widget_show(gtk_window_get_child(GTK_WINDOW(toplevel))); if (GUI_GTK_OPTION(enable_tabs)) { meswin_dialog_popup(FALSE); diff --git a/client/gui-gtk-4.0/gui_stuff.c b/client/gui-gtk-4.0/gui_stuff.c index 7d414d16f4..8c01d634f9 100644 --- a/client/gui-gtk-4.0/gui_stuff.c +++ b/client/gui-gtk-4.0/gui_stuff.c @@ -1193,3 +1193,12 @@ void widget_destroyed(GtkWidget *wdg, void *data) { *(GtkWidget **)data = NULL; } + +/**********************************************************************//** + Get child widget for a widget whose own type is not known + (without further GTK_IS_...() checks) in the caller side. +**************************************************************************/ +GtkWidget *widget_get_child(GtkWidget *wdg) +{ + return gtk_widget_get_first_child(wdg); +} diff --git a/client/gui-gtk-4.0/gui_stuff.h b/client/gui-gtk-4.0/gui_stuff.h index 12541d2872..30b634d9a6 100644 --- a/client/gui-gtk-4.0/gui_stuff.h +++ b/client/gui-gtk-4.0/gui_stuff.h @@ -138,5 +138,6 @@ void enable_gobject_callback(GObject *obj, GCallback cb); gint blocking_dialog(GtkWidget *dlg); void widget_destroyed(GtkWidget *wdg, void *data); +GtkWidget *widget_get_child(GtkWidget *wdg); #endif /* FC__GUI_STUFF_H */ diff --git a/client/gui-gtk-4.0/optiondlg.c b/client/gui-gtk-4.0/optiondlg.c index 24a921057b..d6f0ba44a5 100644 --- a/client/gui-gtk-4.0/optiondlg.c +++ b/client/gui-gtk-4.0/optiondlg.c @@ -268,7 +268,7 @@ static void option_color_set_button_color(GtkButton *button, if (NULL == new_color) { if (NULL != current_color) { g_object_set_data(G_OBJECT(button), "color", NULL); - if ((child = gtk_bin_get_child(GTK_BIN(button)))) { + if ((child = gtk_button_get_child(button))) { gtk_widget_destroy(child); } } @@ -285,7 +285,7 @@ static void option_color_set_button_color(GtkButton *button, g_object_set_data_full(G_OBJECT(button), "color", current_color, option_color_destroy_notify); } - if ((child = gtk_bin_get_child(GTK_BIN(button)))) { + if ((child = gtk_button_get_child(button))) { gtk_widget_destroy(child); } @@ -717,8 +717,8 @@ static inline void option_dialog_option_str_set(struct option *poption, const char *string) { if (NULL != option_str_values(poption)) { - gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(gtk_bin_get_child(GTK_BIN - (option_get_gui_data(poption))))), string, -1); + gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(widget_get_child( + option_get_gui_data(poption)))), string, -1); } else { gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(option_get_gui_data(poption))), string, -1); @@ -905,7 +905,7 @@ static void option_dialog_option_apply(struct option *poption) if (NULL != option_str_values(poption)) { (void) option_str_set(poption, gtk_entry_buffer_get_text( gtk_entry_get_buffer( - GTK_ENTRY(gtk_bin_get_child(GTK_BIN(w)))))); + GTK_ENTRY(widget_get_child(w))))); } else { (void) option_str_set(poption, gtk_entry_buffer_get_text( gtk_entry_get_buffer(GTK_ENTRY(w)))); -- 2.33.0