]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkexpander.c
gtktreemodelfilter: child levels of the root level must remain cached
[~andy/gtk] / gtk / gtkexpander.c
index 7e173bcdca135f33ecc37fe2877f8182f24855cd..4485454222e748158062b3307ff24fdc84c68f51 100644 (file)
@@ -34,7 +34,7 @@
  * to add it to the expander. When the expander is toggled, it will take
  * care of showing and hiding the child automatically.
  *
- * <section id="expander-special-usage">
+ * <refsect2 id="expander-special-usage">
  * <title>Special Usage</title>
  * <para>
  * There are situations in which you may prefer to show and hide the
@@ -45,6 +45,7 @@
  * its expansion state. You should watch this property with a signal
  * connection as follows:
  * </para>
+ * <informalexample>
  * <programlisting id="expander-callback-example">
  * expander = gtk_expander_new_with_mnemonic ("_More Options");
  * g_signal_connect (expander, "notify::expanded",
@@ -71,7 +72,8 @@
  *     }
  * }
  * </programlisting>
- * </section>
+ * </informalexample>
+ * </refsect2>
  * <refsect2 id="GtkExpander-BUILDER-UI">
  * <title>GtkExpander as GtkBuildable</title>
  * <para>
@@ -95,6 +97,7 @@
  * ]]></programlisting>
  * </example>
  * </refsect2>
+ *
  */
 
 #include "config.h"
 #include "gtkintl.h"
 #include "gtkprivate.h"
 #include "gtkdnd.h"
+#include "a11y/gtkexpanderaccessible.h"
 
 
 #define DEFAULT_EXPANDER_SIZE 10
@@ -125,7 +129,8 @@ enum
   PROP_USE_MARKUP,
   PROP_SPACING,
   PROP_LABEL_WIDGET,
-  PROP_LABEL_FILL
+  PROP_LABEL_FILL,
+  PROP_RESIZE_TOPLEVEL
 };
 
 struct _GtkExpanderPrivate
@@ -142,6 +147,7 @@ struct _GtkExpanderPrivate
   guint             button_down : 1;
   guint             prelight : 1;
   guint             label_fill : 1;
+  guint             resize_toplevel : 1;
 };
 
 static void gtk_expander_set_property (GObject          *object,
@@ -328,6 +334,22 @@ gtk_expander_class_init (GtkExpanderClass *klass)
                                                          FALSE,
                                                          GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
+  /**
+   * GtkExpander:resize-toplevel:
+   *
+   * When this property is %TRUE, the expander will resize the toplevel
+   * widget containing the expander upon expanding and collapsing.
+   *
+   * Since: 3.2
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_RESIZE_TOPLEVEL,
+                                   g_param_spec_boolean ("resize-toplevel",
+                                                         P_("Resize toplevel"),
+                                                         P_("Whether the expander will resize the toplevel window upon expanding and collapsing"),
+                                                         FALSE,
+                                                         GTK_PARAM_READWRITE));
+
   gtk_widget_class_install_style_property (widget_class,
                                            g_param_spec_int ("expander-size",
                                                              P_("Expander Size"),
@@ -354,6 +376,8 @@ gtk_expander_class_init (GtkExpanderClass *klass)
                   NULL, NULL,
                   _gtk_marshal_VOID__VOID,
                   G_TYPE_NONE, 0);
+
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_EXPANDER_ACCESSIBLE);
 }
 
 static void
@@ -379,6 +403,7 @@ gtk_expander_init (GtkExpander *expander)
   priv->prelight = FALSE;
   priv->label_fill = FALSE;
   priv->expand_timer = 0;
+  priv->resize_toplevel = 0;
 
   gtk_drag_dest_set (GTK_WIDGET (expander), 0, NULL, 0, 0);
   gtk_drag_dest_set_track_motion (GTK_WIDGET (expander), TRUE);
@@ -435,6 +460,9 @@ gtk_expander_set_property (GObject      *object,
     case PROP_LABEL_FILL:
       gtk_expander_set_label_fill (expander, g_value_get_boolean (value));
       break;
+    case PROP_RESIZE_TOPLEVEL:
+      gtk_expander_set_resize_toplevel (expander, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -475,6 +503,9 @@ gtk_expander_get_property (GObject    *object,
     case PROP_LABEL_FILL:
       g_value_set_boolean (value, priv->label_fill);
       break;
+    case PROP_RESIZE_TOPLEVEL:
+      g_value_set_boolean (value, gtk_expander_get_resize_toplevel (expander));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -985,7 +1016,7 @@ gtk_expander_draw (GtkWidget *widget,
 
   gtk_expander_paint (expander, cr);
 
-  if (gtk_widget_has_focus (widget))
+  if (gtk_widget_has_visible_focus (widget))
     gtk_expander_paint_focus (expander, cr);
 
   GTK_WIDGET_CLASS (gtk_expander_parent_class)->draw (widget, cr);
@@ -1272,6 +1303,47 @@ get_next_site (GtkExpander      *expander,
   return FOCUS_NONE;
 }
 
+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);
+        }
+    }
+}
+
 static gboolean
 gtk_expander_focus (GtkWidget        *widget,
                     GtkDirectionType  direction)
@@ -1665,6 +1737,7 @@ gtk_expander_set_expanded (GtkExpander *expander,
         {
           gtk_widget_set_child_visible (child, priv->expanded);
           gtk_widget_queue_resize (widget);
+          gtk_expander_resize_toplevel (expander);
         }
 
       g_object_notify (G_OBJECT (expander), "expanded");
@@ -1794,7 +1867,7 @@ gtk_expander_set_label (GtkExpander *expander,
  *
  * Since: 2.4
  */
-G_CONST_RETURN char *
+const char *
 gtk_expander_get_label (GtkExpander *expander)
 {
   GtkExpanderPrivate *priv;
@@ -2045,3 +2118,45 @@ gtk_expander_get_label_fill (GtkExpander *expander)
 
   return expander->priv->label_fill;
 }
+
+/**
+ * gtk_expander_set_resize_toplevel:
+ * @expander: a #GtkExpander
+ * @resize_toplevel: whether to resize the toplevel
+ *
+ * Sets whether the expander will resize the toplevel widget
+ * containing the expander upon resizing and collpasing.
+ *
+ * Since: 3.2
+ */
+void
+gtk_expander_set_resize_toplevel (GtkExpander *expander,
+                                  gboolean     resize_toplevel)
+{
+  g_return_if_fail (GTK_IS_EXPANDER (expander));
+
+  if (expander->priv->resize_toplevel != resize_toplevel)
+    {
+      expander->priv->resize_toplevel = resize_toplevel ? TRUE : FALSE;
+      g_object_notify (G_OBJECT (expander), "resize-toplevel");
+    }
+}
+
+/**
+ * gtk_expander_get_resize_toplevel:
+ * @expander: a #GtkExpander
+ *
+ * Returns whether the expander will resize the toplevel widget
+ * containing the expander upon resizing and collpasing.
+ *
+ * Return value: the "resize toplevel" setting.
+ *
+ * Since: 3.2
+ */
+gboolean
+gtk_expander_get_resize_toplevel (GtkExpander *expander)
+{
+  g_return_val_if_fail (GTK_IS_EXPANDER (expander), FALSE);
+
+  return expander->priv->resize_toplevel;
+}