* 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
* 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",
* }
* }
* </programlisting>
- * </section>
+ * </informalexample>
+ * </refsect2>
* <refsect2 id="GtkExpander-BUILDER-UI">
* <title>GtkExpander as GtkBuildable</title>
* <para>
* ]]></programlisting>
* </example>
* </refsect2>
+ *
*/
#include "config.h"
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkdnd.h"
+#include "a11y/gtkexpanderaccessible.h"
#define DEFAULT_EXPANDER_SIZE 10
PROP_USE_MARKUP,
PROP_SPACING,
PROP_LABEL_WIDGET,
- PROP_LABEL_FILL
+ PROP_LABEL_FILL,
+ PROP_RESIZE_TOPLEVEL
};
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,
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"),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+
+ gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_EXPANDER_ACCESSIBLE);
}
static void
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);
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;
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;
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);
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)
{
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");
*
* Since: 2.4
*/
-G_CONST_RETURN char *
+const char *
gtk_expander_get_label (GtkExpander *expander)
{
GtkExpanderPrivate *priv;
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;
+}