diff options
author | Vitaly Minko <vitaly.minko@gmail.com> | 2010-10-28 03:39:32 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-10-28 20:30:26 +0800 |
commit | 7fc61f47a6133047135b01190ad3dc8e9eed4489 (patch) | |
tree | 6640561862ffc7bf1dcc92a410ec97049046afd3 /libempathy-gtk/empathy-individual-view.c | |
parent | 8fcbe3e7f71eeb6bca559dd6c36711b7fa5078c4 (diff) | |
download | gsoc2013-empathy-7fc61f47a6133047135b01190ad3dc8e9eed4489.tar gsoc2013-empathy-7fc61f47a6133047135b01190ad3dc8e9eed4489.tar.gz gsoc2013-empathy-7fc61f47a6133047135b01190ad3dc8e9eed4489.tar.bz2 gsoc2013-empathy-7fc61f47a6133047135b01190ad3dc8e9eed4489.tar.lz gsoc2013-empathy-7fc61f47a6133047135b01190ad3dc8e9eed4489.tar.xz gsoc2013-empathy-7fc61f47a6133047135b01190ad3dc8e9eed4489.tar.zst gsoc2013-empathy-7fc61f47a6133047135b01190ad3dc8e9eed4489.zip |
Add auto scrolling when drag-and-dropping contacts (#619858).
Diffstat (limited to 'libempathy-gtk/empathy-individual-view.c')
-rw-r--r-- | libempathy-gtk/empathy-individual-view.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/libempathy-gtk/empathy-individual-view.c b/libempathy-gtk/empathy-individual-view.c index 2ad0fc0e0..2e88ac24d 100644 --- a/libempathy-gtk/empathy-individual-view.c +++ b/libempathy-gtk/empathy-individual-view.c @@ -93,6 +93,15 @@ typedef struct typedef struct { EmpathyIndividualView *view; + guint timeout_id; + /* Distance between mouse pointer and the nearby border. Negative when + scrolling updards.*/ + gint distance; +} AutoScrollData; + +typedef struct +{ + EmpathyIndividualView *view; FolksIndividual *individual; gboolean remove; } ShowActiveData; @@ -549,6 +558,32 @@ individual_view_drag_motion_cb (DragMotionData *data) return FALSE; } +/* Minimum distance between the mouse pointer and a horizontal border when we + start auto scrolling. */ +#define AUTO_SCROLL_MARGIN_SIZE 20 +/* How far to scroll per one tick. */ +#define AUTO_SCROLL_PITCH 10 + +static gboolean +individual_view_auto_scroll_cb (AutoScrollData *data) +{ + GtkAdjustment *adj; + gdouble new_value; + + adj = gtk_scrollable_get_vadjustment (GTK_TREE_VIEW (data->view)); + + if (data->distance < 0) + new_value = adj->value - AUTO_SCROLL_PITCH; + else + new_value = adj->value + AUTO_SCROLL_PITCH; + + new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size); + + gtk_adjustment_set_value (adj, new_value); + + return TRUE; +} + static gboolean individual_view_drag_motion (GtkWidget *widget, GdkDragContext *context, @@ -561,6 +596,7 @@ individual_view_drag_motion (GtkWidget *widget, GdkAtom target; GtkTreeIter iter; static DragMotionData *dm = NULL; + static AutoScrollData as; GtkTreePath *path; gboolean is_row; gboolean is_different = FALSE; @@ -570,6 +606,24 @@ individual_view_drag_motion (GtkWidget *widget, priv = GET_PRIV (EMPATHY_INDIVIDUAL_VIEW (widget)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); + if (!as.view) + as.view = EMPATHY_INDIVIDUAL_VIEW (widget); + + if (as.timeout_id) + g_source_remove (as.timeout_id); + + if (y < AUTO_SCROLL_MARGIN_SIZE || + y > (widget->allocation.height - AUTO_SCROLL_MARGIN_SIZE)) + { + if (y < AUTO_SCROLL_MARGIN_SIZE) + as.distance = MIN (-y, -1); + else + as.distance = MAX (widget->allocation.height - y, 1); + + as.timeout_id = g_timeout_add (10 * ABS (as.distance), + (GSourceFunc) individual_view_auto_scroll_cb, &as); + } + is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), x, y, &path, NULL, NULL, NULL); |