[gtk+/wip/baedert/drawing] expander: Inherit from GtkContainer
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/drawing] expander: Inherit from GtkContainer
- Date: Sat, 6 May 2017 10:40:26 +0000 (UTC)
commit 3796553068d211b07ec8bc6e4669adac736d4eca
Author: Timm Bäder <mail baedert org>
Date: Sat May 6 12:41:50 2017 +0200
expander: Inherit from GtkContainer
This fixes the expansion not working. As a GtkBin, GtkExpander can only
have one child and if that's a GtkBox (and not the one added through
gtk_expander_add), things go wrong.
gtk/gtkexpander.c | 54 ++++++++++++++++++++++++++++++++++++++++++++--------
gtk/gtkexpander.h | 4 +-
2 files changed, 47 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c
index 4785f72..700f9b8 100644
--- a/gtk/gtkexpander.c
+++ b/gtk/gtkexpander.c
@@ -147,6 +147,7 @@ struct _GtkExpanderPrivate
GtkWidget *box;
GtkWidget *title_widget;
GtkWidget *arrow_widget;
+ GtkWidget *child;
GtkGesture *multipress_gesture;
gint spacing;
@@ -227,7 +228,7 @@ static void gesture_multipress_released_cb (GtkGestureMultiPress *gesture,
gdouble y,
GtkExpander *expander);
-G_DEFINE_TYPE_WITH_CODE (GtkExpander, gtk_expander, GTK_TYPE_BIN,
+G_DEFINE_TYPE_WITH_CODE (GtkExpander, gtk_expander, GTK_TYPE_CONTAINER,
G_ADD_PRIVATE (GtkExpander)
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_expander_buildable_init))
@@ -237,12 +238,26 @@ gtk_expander_finalize (GObject *obj)
{
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (GTK_EXPANDER (obj));
- gtk_widget_unparent (priv->box);
+ /*gtk_widget_unparent (priv->box);*/
G_OBJECT_CLASS (gtk_expander_parent_class)->finalize (obj);
}
static void
+gtk_expander_forall (GtkContainer *container,
+ GtkCallback callback,
+ gpointer user_data)
+{
+ GtkExpanderPrivate *priv = gtk_expander_get_instance_private (GTK_EXPANDER (container));
+
+ if (priv->child)
+ (*callback) (priv->child, user_data);
+
+ if (priv->label_widget)
+ (*callback) (priv->label_widget, user_data);
+}
+
+static void
gtk_expander_class_init (GtkExpanderClass *klass)
{
GObjectClass *gobject_class;
@@ -273,6 +288,7 @@ gtk_expander_class_init (GtkExpanderClass *klass)
container_class->add = gtk_expander_add;
container_class->remove = gtk_expander_remove;
+ container_class->forall = gtk_expander_forall;
klass->activate = gtk_expander_activate;
@@ -510,6 +526,15 @@ gtk_expander_destroy (GtkWidget *widget)
priv->expand_timer = 0;
}
+ if (priv->box)
+ {
+ gtk_widget_unparent (priv->box);
+ priv->box = NULL;
+ priv->child = NULL;
+ priv->label_widget = NULL;
+ priv->arrow_widget = NULL;
+ }
+
g_clear_object (&priv->multipress_gesture);
GTK_WIDGET_CLASS (gtk_expander_parent_class)->destroy (widget);
@@ -773,7 +798,7 @@ focus_in_site (GtkExpander *expander,
return FALSE;
case FOCUS_CHILD:
{
- GtkWidget *child = gtk_bin_get_child (GTK_BIN (expander));
+ GtkWidget *child = expander->priv->child;
if (child && gtk_widget_get_child_visible (child))
return gtk_widget_child_focus (child, direction);
@@ -865,7 +890,7 @@ static void
gtk_expander_resize_toplevel (GtkExpander *expander)
{
GtkExpanderPrivate *priv = expander->priv;
- GtkWidget *child = gtk_bin_get_child (GTK_BIN (expander));
+ GtkWidget *child = priv->child;
if (child && priv->resize_toplevel &&
gtk_widget_get_realized (GTK_WIDGET (expander)))
@@ -944,6 +969,8 @@ gtk_expander_add (GtkContainer *container,
if (priv->expanded)
gtk_container_add (GTK_CONTAINER (priv->box), widget);
+
+ priv->child = widget;
}
static void
@@ -958,6 +985,11 @@ gtk_expander_remove (GtkContainer *container,
else
{
gtk_container_remove (GTK_CONTAINER (priv->box), widget);
+ if (!priv->expanded)
+ {
+ /* We hold an extra ref */
+ g_object_unref (widget);
+ }
GTK_CONTAINER_CLASS (gtk_expander_parent_class)->remove (container, widget);
}
}
@@ -1059,16 +1091,20 @@ gtk_expander_set_expanded (GtkExpander *expander,
update_node_state (expander);
- child = gtk_bin_get_child (GTK_BIN (expander));
+ child = priv->child;
if (child)
{
if (priv->expanded)
- gtk_container_add (GTK_CONTAINER (priv->box), child);
+ {
+ gtk_container_add (GTK_CONTAINER (priv->box), child);
+ g_object_unref (priv->child);
+ }
else
- gtk_container_remove (GTK_CONTAINER (priv->box), child);
- /* TODO: Yeah, I don't think this will work... */
-
+ {
+ g_object_ref (priv->child);
+ gtk_container_remove (GTK_CONTAINER (priv->box), child);
+ }
gtk_expander_resize_toplevel (expander);
}
diff --git a/gtk/gtkexpander.h b/gtk/gtkexpander.h
index 69a3fec..a0024d0 100644
--- a/gtk/gtkexpander.h
+++ b/gtk/gtkexpander.h
@@ -43,7 +43,7 @@ typedef struct _GtkExpanderPrivate GtkExpanderPrivate;
struct _GtkExpander
{
- GtkBin bin;
+ GtkContainer parent_instance;
GtkExpanderPrivate *priv;
};
@@ -55,7 +55,7 @@ struct _GtkExpander
*/
struct _GtkExpanderClass
{
- GtkBinClass parent_class;
+ GtkContainerClass parent_class;
/*< public >*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]