allow DnD between DnDTreeView and DnDVbox
authorRobin Gareus <robin@gareus.org>
Mon, 28 Dec 2015 03:10:39 +0000 (04:10 +0100)
committerRobin Gareus <robin@gareus.org>
Mon, 28 Dec 2015 03:10:39 +0000 (04:10 +0100)
libs/gtkmm2ext/dndtreeview.cc
libs/gtkmm2ext/gtkmm2ext/dndtreeview.h
libs/gtkmm2ext/gtkmm2ext/dndvbox.h

index be53482603d6ce13217faff6bb6048af82d1dc09..bc6745dc4f960cbf8d978bf08a1ed49a0a180b0b 100644 (file)
@@ -106,6 +106,11 @@ DnDTreeViewBase::on_drag_begin (Glib::RefPtr<Gdk::DragContext> const & context)
        start_object_drag ();
 }
 
+void
+DnDTreeViewBase::on_drag_end (Glib::RefPtr<Gdk::DragContext> const & context) {
+       Gtk::TreeView::on_drag_end (context);
+       end_object_drag ();
+}
 
 void
 DnDTreeViewBase::add_drop_targets (list<TargetEntry>& targets)
index d36d82f6ee4a4c8d50ba00d39962ce2670c8f99d..aa62166b686ccb9276809a5174df5933f2d5445d 100644 (file)
@@ -49,6 +49,7 @@ class LIBGTKMM2EXT_API DnDTreeViewBase : public Gtk::TreeView
        void add_object_drag (int column, std::string type_name);
 
        void on_drag_begin (Glib::RefPtr<Gdk::DragContext> const & context);
+       void on_drag_end (Glib::RefPtr<Gdk::DragContext> const & context);
 
        bool on_button_press_event (GdkEventButton *ev) {
                press_start_x = ev->x;
@@ -97,6 +98,12 @@ class LIBGTKMM2EXT_API DnDTreeViewBase : public Gtk::TreeView
                drag_data.data_column = data_column;
                drag_data.object_type = object_type;
        }
+
+       void end_object_drag () {
+               drag_data.source = 0;
+               drag_data.data_column = -1;
+               drag_data.object_type = "";
+       }
 };
 
 template<class DataType>
@@ -106,7 +113,7 @@ class /*LIBGTKMM2EXT_API*/ DnDTreeView : public DnDTreeViewBase
        DnDTreeView() {}
        ~DnDTreeView() {}
 
-       sigc::signal<void,const std::list<DataType>&,Gtk::TreeView*,int,int,Glib::RefPtr<Gdk::DragContext>&> signal_drop;
+       sigc::signal<void, const Glib::RefPtr<Gdk::DragContext>&, const Gtk::SelectionData&> signal_drop;
 
        void on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection_data, guint info, guint time) {
                if (selection_data.get_target() == "GTK_TREE_MODEL_ROW") {
@@ -134,14 +141,9 @@ class /*LIBGTKMM2EXT_API*/ DnDTreeView : public DnDTreeViewBase
                }
 
                if (selection_data.get_target() == "GTK_TREE_MODEL_ROW") {
-
                        TreeView::on_drag_data_received (context, x, y, selection_data, info, time);
-
-
                } else if (selection_data.get_target() == object_type) {
-
-                       end_object_drag (const_cast<Glib::RefPtr<Gdk::DragContext>& > (context), x, y);
-
+                       signal_drop (context, selection_data);
                } else {
                        /* some kind of target type added by the app, which will be handled by a signal handler */
                }
@@ -169,15 +171,6 @@ class /*LIBGTKMM2EXT_API*/ DnDTreeView : public DnDTreeViewBase
 
                *source = drag_data.source;
        }
-
-  private:
-       void end_object_drag (Glib::RefPtr<Gdk::DragContext>& context, int x, int y) {
-               std::list<DataType> l;
-               Gtk::TreeView* source;
-               get_object_drag_data (l, &source);
-               signal_drop (l, source, x, y, context);
-       }
-
 };
 
 } // namespace
index 12e63c1c7f40c2557851fbd07f4e9bfa7d153796..a5e98daf4347dd5ac64b55fc5a9427b4e83eecc6 100644 (file)
@@ -44,6 +44,8 @@ public:
 
        /** @return True if the child can be selected in the list ( if you don't want it to copy/paste/drag then turn this off ) */
        virtual bool is_selectable () const = 0;
+
+       virtual bool drag_data_get (Glib::RefPtr<Gdk::DragContext> const, Gtk::SelectionData &) { return false; }
 };
 
 /** A VBox whose contents can be dragged and dropped */
@@ -345,9 +347,11 @@ private:
                return false;
        }
 
-       void drag_data_get (Glib::RefPtr<Gdk::DragContext> const &, Gtk::SelectionData & selection_data, guint, guint, T* child)
+       void drag_data_get (Glib::RefPtr<Gdk::DragContext> const &context, Gtk::SelectionData & selection_data, guint, guint, T* child)
        {
-               selection_data.set (selection_data.get_target(), 8, (const guchar *) &child, sizeof (&child));
+               if (!child->drag_data_get(context, selection_data)) {
+                       selection_data.set (selection_data.get_target(), 8, (const guchar *) &child, sizeof (&child));
+               }
        }
 
        void drag_data_received (