summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext/gtkmm2ext/dndtreeview.h
blob: 82bb7651b9de3122fda2bb958ff0871c86d26d9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef __gtkmm2ext_dndtreeview_h__
#define __gtkmm2ext_dndtreeview_h__

#include <stdint.h>
#include <string>
#include <gtkmm/treeview.h>
#include <gtkmm/treeselection.h>
#include <gtkmm/selectiondata.h>

namespace Gtkmm2ext {

class DnDTreeView : public Gtk::TreeView 
{

  private:
  public:
	DnDTreeView ();
	~DnDTreeView() {}

	/* this is the structure pointed to if add_object_drag() is called
	   and a drop happens on a destination which has declared itself
	   willing to accept a target of the type named in the call
	   to add_object_drag().
	*/
	
	struct SerializedObjectPointers {
	    uint32_t size;
	    uint32_t cnt;
	    char     type[32];
	    void*    ptr[0];
	};
	
	void add_drop_targets (std::list<Gtk::TargetEntry>&);
	void add_object_drag (int column, std::string type_name);
	sigc::signal<void,std::string,uint32_t,void**> signal_object_drop;
	
	void on_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) {
		TreeView::on_drag_begin (context);
	}
	void on_drag_end(const Glib::RefPtr<Gdk::DragContext>& context) {
		TreeView::on_drag_end (context);
	}
	void on_drag_data_delete(const Glib::RefPtr<Gdk::DragContext>& context) {
		TreeView::on_drag_data_delete (context);
	}
	void on_drag_leave(const Glib::RefPtr<Gdk::DragContext>& context, guint time) {
	    suggested_action = context->get_suggested_action();
	    TreeView::on_drag_leave (context, time);
	}
	bool on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint time) {
		suggested_action = context->get_suggested_action();
		return TreeView::on_drag_motion (context, x, y, time);
	}
	bool on_drag_drop(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint time);
	void on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection_data, guint info, guint time);
	void on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time);

  private:
	std::list<Gtk::TargetEntry> draggable;
	Gdk::DragAction             suggested_action;
	int                         data_column;
	
	SerializedObjectPointers* serialize_pointers (Glib::RefPtr<Gtk::TreeModel> m, 
						      Gtk::TreeSelection::ListHandle_Path*,
						      Glib::ustring type);
};

} // namespace
 
#endif /* __gtkmm2ext_dndtreeview_h__ */