<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40344 >

Strangely, this was caused by the total height of the
toplevel window being calculated as the maximum of all
its child widgets, both shown and hidden. In particular,
the "hidden" edit info box (which should be considered
as taking the place of the unit info box) height was
being added to the full height of the unit info box.

So I was mistaken in thinking it would be enough to just
hide/show widgets based on edit mode. :(

The attached patch gets rid of this assumption by
internally reparenting the unit/edit info boxes instead
of just hiding/showing them.


----------------------------------------------------------------------
信じられない、このありえないこと。
diff --git a/client/gui-gtk-2.0/editgui.c b/client/gui-gtk-2.0/editgui.c
index b96b3df..74f0640 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,23 @@ static GdkPixbuf *get_brush_pixbuf(void)
 }
 
 /****************************************************************************
+  NB: Assumes that widget 'old' has enough references to not be destroyed
+  when removed from its parent container.
+****************************************************************************/
+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_container_add(GTK_CONTAINER(parent), new);
+}
+
+/****************************************************************************
   Refresh the given editinfobox according to the current editor state.
 ****************************************************************************/
 static void editinfobox_refresh(struct editinfobox *ei)
@@ -1439,8 +1465,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 +1527,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

Reply via email to