<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40344 >
Version 2 uses better packing parameters when switching the unit/edit info boxes. ---------------------------------------------------------------------- 偽ったら偽るほど本当の自分を忘れる。
diff --git a/client/gui-gtk-2.0/editgui.c b/client/gui-gtk-2.0/editgui.c index b96b3df..82fbe90 100644 --- a/client/gui-gtk-2.0/editgui.c +++ b/client/gui-gtk-2.0/editgui.c @@ -1225,6 +1225,15 @@ static struct editinfobox *editinfobox_create(void) gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0); ei->tool_applied_player_combobox = combo; + /* We add a ref to the editinfobox widget so that it is + * not destroyed when replaced by the unit info box when + * we leave edit mode. See editinfobox_refresh(). */ + g_object_ref(ei->widget); + + /* The edit info box starts with no parent, so we have to + * show its internal widgets manually. */ + gtk_widget_show_all(ei->widget); + return ei; } @@ -1424,6 +1433,24 @@ static GdkPixbuf *get_brush_pixbuf(void) } /**************************************************************************** + NB: Assumes that widget 'old' has enough references to not be destroyed + when removed from its parent container, and that the parent container + is a GtkBox (or is descended from it). +****************************************************************************/ +static void replace_widget(GtkWidget *old, GtkWidget *new) +{ + GtkWidget *parent; + + parent = gtk_widget_get_parent(old); + if (!parent) { + return; + } + + gtk_container_remove(GTK_CONTAINER(parent), old); + gtk_box_pack_start(GTK_BOX(parent), new, FALSE, FALSE, 0); +} + +/**************************************************************************** Refresh the given editinfobox according to the current editor state. ****************************************************************************/ static void editinfobox_refresh(struct editinfobox *ei) @@ -1439,8 +1466,7 @@ static void editinfobox_refresh(struct editinfobox *ei) } if (!editor_is_active()) { - gtk_widget_hide(ei->widget); - gtk_widget_show(unit_info_box); + replace_widget(ei->widget, unit_info_box); return; } @@ -1502,8 +1528,7 @@ static void editinfobox_refresh(struct editinfobox *ei) refresh_tool_applied_player_combo(ei); - gtk_widget_hide(unit_info_box); - gtk_widget_show(ei->widget); + replace_widget(unit_info_box, ei->widget); } /**************************************************************************** diff --git a/client/gui-gtk-2.0/gui_main.c b/client/gui-gtk-2.0/gui_main.c index 6257453..1ed2e8b 100644 --- a/client/gui-gtk-2.0/gui_main.c +++ b/client/gui-gtk-2.0/gui_main.c @@ -1204,6 +1204,12 @@ static void setup_widgets(void) unit_info_box = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(avbox), unit_info_box, FALSE, FALSE, 0); + /* In edit mode the unit_info_box widget is replaced by the + * editinfobox, so we need to add a ref here so that it is + * not destroyed when removed from its container. + * See editinfobox_refresh(). */ + g_object_ref(unit_info_box); + unit_info_frame = gtk_frame_new(""); gtk_box_pack_start(GTK_BOX(unit_info_box), unit_info_frame, FALSE, FALSE, 0); @@ -1222,11 +1228,6 @@ static void setup_widgets(void) unit_pixmap_table = table; populate_unit_pixmap_table(); - /* Editor info box */ - gtk_box_pack_start(GTK_BOX(avbox), - editgui_get_editinfobox()->widget, - FALSE, FALSE, 0); - /* Map canvas, editor toolbar, and scrollbars */ top_notebook = gtk_notebook_new();
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev