+static void
+gtk_expander_resize_toplevel (GtkExpander *expander)
+{
+ GtkExpanderPrivate *priv = expander->priv;
+ GtkWidget *child = gtk_bin_get_child (GTK_BIN (expander));
+
+ if (child && priv->resize_toplevel &&
+ gtk_widget_get_realized (GTK_WIDGET (expander)))
+ {
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (expander));
+
+ if (toplevel && gtk_widget_get_realized (toplevel))
+ {
+ GtkAllocation toplevel_allocation;
+
+ gtk_widget_get_allocation (toplevel, &toplevel_allocation);
+
+ if (priv->expanded)
+ {
+ GtkRequisition child_requisition;
+
+ gtk_widget_get_preferred_size (child, &child_requisition, NULL);
+
+ toplevel_allocation.height += child_requisition.height;
+ }
+ else
+ {
+ GtkAllocation child_allocation;
+
+ gtk_widget_get_allocation (child, &child_allocation);
+
+ toplevel_allocation.height -= child_allocation.height;
+ }
+
+ gtk_window_resize (GTK_WINDOW (toplevel),
+ toplevel_allocation.width,
+ toplevel_allocation.height);
+ }
+ }
+}
+