From 502d44e50369ccd1ee70823f0c7125ef3f2537f4 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 22 Mar 2006 21:09:01 +0000 Subject: [PATCH] Make it to expand when hovering during DnD 2006-03-22 Carlos Garnacho * gtk/gtkexpander.c: Make it to expand when hovering during DnD --- ChangeLog | 4 +++ ChangeLog.pre-2-10 | 4 +++ gtk/gtkexpander.c | 68 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f66998098d..506a691387 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-03-22 Carlos Garnacho + + * gtk/gtkexpander.c: Make it to expand when hovering during DnD + 2006-03-22 Matthias Clasen Improved DND support for GtkNotebook (#332991, Carlos Garnacho) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index f66998098d..506a691387 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,7 @@ +2006-03-22 Carlos Garnacho + + * gtk/gtkexpander.c: Make it to expand when hovering during DnD + 2006-03-22 Matthias Clasen Improved DND support for GtkNotebook (#332991, Carlos Garnacho) diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c index a5688806c1..c658340b79 100644 --- a/gtk/gtkexpander.c +++ b/gtk/gtkexpander.c @@ -33,6 +33,7 @@ #include "gtkprivate.h" #include #include "gtkalias.h" +#include "gtkdnd.h" #define GTK_EXPANDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_EXPANDER, GtkExpanderPrivate)) @@ -58,6 +59,7 @@ struct _GtkExpanderPrivate GtkExpanderStyle expander_style; guint animation_timeout; + guint expand_timer; guint expanded : 1; guint use_underline : 1; @@ -104,6 +106,14 @@ static void gtk_expander_grab_notify (GtkWidget *widget, gboolean was_grabbed); static void gtk_expander_state_changed (GtkWidget *widget, GtkStateType previous_state); +static gboolean gtk_expander_drag_motion (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time); +static void gtk_expander_drag_leave (GtkWidget *widget, + GdkDragContext *context, + guint time); static void gtk_expander_add (GtkContainer *container, GtkWidget *widget); @@ -183,6 +193,8 @@ gtk_expander_class_init (GtkExpanderClass *klass) widget_class->focus = gtk_expander_focus; widget_class->grab_notify = gtk_expander_grab_notify; widget_class->state_changed = gtk_expander_state_changed; + widget_class->drag_motion = gtk_expander_drag_motion; + widget_class->drag_leave = gtk_expander_drag_leave; container_class->add = gtk_expander_add; container_class->remove = gtk_expander_remove; @@ -292,6 +304,10 @@ gtk_expander_init (GtkExpander *expander) priv->use_markup = FALSE; priv->button_down = FALSE; priv->prelight = FALSE; + priv->expand_timer = 0; + + gtk_drag_dest_set (GTK_WIDGET (expander), 0, NULL, 0, 0); + gtk_drag_dest_set_track_motion (GTK_WIDGET (expander), TRUE); } static void @@ -978,6 +994,57 @@ gtk_expander_leave_notify (GtkWidget *widget, return FALSE; } +static gboolean +expand_timeout (gpointer data) +{ + GtkExpander *expander = GTK_EXPANDER (data); + GtkExpanderPrivate *priv = expander->priv; + + priv->expand_timer = 0; + gtk_expander_set_expanded (expander, TRUE); + + return FALSE; +} + +static gboolean +gtk_expander_drag_motion (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time) +{ + GtkExpander *expander = GTK_EXPANDER (widget); + GtkExpanderPrivate *priv = expander->priv; + + if (!priv->expanded && !priv->expand_timer) + { + GtkSettings *settings; + guint timeout; + + settings = gtk_widget_get_settings (widget); + g_object_get (settings, "gtk-timeout-expand", &timeout, NULL); + + priv->expand_timer = g_timeout_add (timeout, (GSourceFunc) expand_timeout, expander); + } + + return TRUE; +} + +static void +gtk_expander_drag_leave (GtkWidget *widget, + GdkDragContext *context, + guint time) +{ + GtkExpander *expander = GTK_EXPANDER (widget); + GtkExpanderPrivate *priv = expander->priv; + + if (priv->expand_timer) + { + g_source_remove (priv->expand_timer); + priv->expand_timer = 0; + } +} + typedef enum { FOCUS_NONE, @@ -1181,7 +1248,6 @@ gtk_expander_activate (GtkExpander *expander) gtk_expander_set_expanded (expander, !expander->priv->expanded); } - /** * gtk_expander_new: * @label: the text of the label