[egg-list-box] auto-scroll during DnD



commit fa76492117b0893bd329076aa6689c264f76bb6e
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Mon Jun 25 11:59:47 2012 +0200

    auto-scroll during DnD
    
    https://bugzilla.gnome.org/show_bug.cgi?id=678782

 egg-list-box.vala |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/egg-list-box.vala b/egg-list-box.vala
index 380602c..aa70a9d 100644
--- a/egg-list-box.vala
+++ b/egg-list-box.vala
@@ -48,7 +48,10 @@ public class Egg.ListBox : Container {
   private SelectionMode selection_mode;
   private Adjustment? adjustment;
   private bool activate_single_click;
+
+  /* DnD */
   private Widget drag_highlighted_widget;
+  private uint auto_scroll_timeout_id;
 
   construct {
     set_can_focus (true);
@@ -63,6 +66,11 @@ public class Egg.ListBox : Container {
     separator_hash = new HashTable<unowned Widget, unowned ChildInfo> (GLib.direct_hash, GLib.direct_equal);
   }
 
+  ~ListBox (){
+    if (auto_scroll_timeout_id != 0)
+      Source.remove (auto_scroll_timeout_id);
+  }
+
   public unowned Widget? get_selected_child (){
     if (selected_child != null)
       return selected_child.widget;
@@ -1044,5 +1052,47 @@ public class Egg.ListBox : Container {
 
   public override void drag_leave (Gdk.DragContext context, uint time_) {
     drag_unhighlight_widget ();
+
+    if (auto_scroll_timeout_id != 0) {
+      Source.remove (auto_scroll_timeout_id);
+      auto_scroll_timeout_id = 0;
+    }
+  }
+
+  public override bool drag_motion (Gdk.DragContext context, int x, int y, uint time_) {
+    /* Auto-scroll during Dnd if cursor is moving into the top/bottom portion of the
+     * box. */
+    if (auto_scroll_timeout_id != 0) {
+      Source.remove (auto_scroll_timeout_id);
+      auto_scroll_timeout_id = 0;
+    }
+
+    if (adjustment == null)
+     return false;
+
+    /* Part of the view triggering auto-scroll */
+    double size = 30;
+    int move = 0;
+
+    if (y < adjustment.value + size) {
+      /* Scroll up */
+      move = -1;
+    }
+    else if (y > (adjustment.value + adjustment.page_size) - size) {
+      /* Scroll down */
+      move = 1;
+    }
+
+    if (move == 0)
+      return false;
+
+    auto_scroll_timeout_id = Timeout.add (150, () =>
+      {
+        adjustment.value += (adjustment.step_increment * move);
+
+        return true;
+      });
+
+    return false;
   }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]