[gtk: 1/2] expander: Check for an existing child when adding



commit a207ab610588b2a7608f501e2ff01c562ec5eb8a
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue Mar 6 14:26:08 2018 -0500

    expander: Check for an existing child when adding
    
    Now that GtkExpander subclasses GtkContainer instead of GtkBin, it needs
    its own guard against adding more than one child.
    
    Also, the documentation should no longer describe adding a child as if
    it is descended from GtkBin.

 gtk/gtkexpander.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c
index 4b7fb14909..1756682561 100644
--- a/gtk/gtkexpander.c
+++ b/gtk/gtkexpander.c
@@ -27,7 +27,7 @@
  * A #GtkExpander allows the user to hide or show its child by clicking
  * on an expander triangle similar to the triangles used in a #GtkTreeView.
  *
- * Normally you use an expander as you would use any other descendant
+ * Normally you use an expander as you would use a descendant
  * of #GtkBin; you create the child widget and use gtk_container_add()
  * to add it to the expander. When the expander is toggled, it will take
  * care of showing and hiding the child automatically.
@@ -786,6 +786,18 @@ gtk_expander_add (GtkContainer *container,
   GtkExpander *expander = GTK_EXPANDER (container);
   GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
 
+  if (priv->child != NULL)
+    {
+      g_warning ("Attempting to add a widget with type %s to a %s, "
+                 "but a %s can only contain one widget at a time; "
+                 "it already contains a widget of type %s",
+                 g_type_name (G_OBJECT_TYPE (widget)),
+                 g_type_name (G_OBJECT_TYPE (container)),
+                 g_type_name (G_OBJECT_TYPE (container)),
+                 g_type_name (G_OBJECT_TYPE (priv->child)));
+      return;
+    }
+
   if (priv->expanded)
     {
       gtk_container_add (GTK_CONTAINER (priv->box), widget);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]