13
0

allow DnD between DnDTreeView and DnDVbox

This commit is contained in:
Robin Gareus 2015-12-28 04:10:39 +01:00
parent d7475e1419
commit 0aba08594c
3 changed files with 20 additions and 18 deletions

View 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)

View 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

View 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,10 +347,12 @@ 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)
{
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 (
Glib::RefPtr<Gdk::DragContext> const & context, int /*x*/, int y, Gtk::SelectionData const & selection_data, guint /*info*/, guint time