20 #include <gtkmm/box.h>
34 virtual Gtk::Widget&
widget () = 0;
40 virtual std::string
drag_text ()
const = 0;
56 _targets.push_back (Gtk::TargetEntry (
"processor"));
60 Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK |
61 Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK |
62 Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK
86 child->action_widget().drag_source_set (
_targets);
87 child->action_widget().signal_drag_begin().connect (sigc::bind (mem_fun (*
this, &
DnDVBox::drag_begin), child));
88 child->action_widget().signal_drag_data_get().connect (sigc::bind (mem_fun (*
this, &
DnDVBox::drag_data_get), child));
89 child->action_widget().signal_drag_end().connect (sigc::bind (mem_fun (*
this, &
DnDVBox::drag_end), child));
90 child->action_widget().signal_button_press_event().connect (sigc::bind (mem_fun (*
this, &
DnDVBox::button_press), child));
91 child->action_widget().signal_button_release_event().connect (sigc::bind (mem_fun (*
this, &
DnDVBox::button_release), child));
96 child->widget().show ();
102 std::list<T*> sorted_children;
104 std::list<Gtk::Widget*> widget_children =
_internal_vbox.get_children ();
105 for (std::list<Gtk::Widget*>::iterator i = widget_children.begin(); i != widget_children.end(); ++i) {
109 sorted_children.push_back (c);
113 return sorted_children;
148 for (
typename std::list<T*>::iterator i =
_children.begin(); i !=
_children.end(); ++i) {
160 for (
typename std::list<T*>::iterator i =
_children.begin(); i !=
_children.end(); ++i) {
182 std::pair<T*, double> r;
232 Gtk::Allocation
const a = child->widget().get_allocation ();
233 double bottom = a.get_y() + a.get_height();
236 Gtk::Allocation
const b =
_placeholder->get_allocation ();
237 if (b.get_y() < a.get_y()) {
255 *before = *at = *after = 0;
261 typename std::list<T*>::const_iterator j =
_children.begin ();
270 while (y >= bottom && j !=
_children.end()) {
294 return i + ((y - top) / (bottom - top));
297 void drag_begin (Glib::RefPtr<Gdk::DragContext>
const & context, T* child)
302 _drag_icon =
new Gtk::Window (Gtk::WINDOW_POPUP);
304 Gtk::Allocation a = child->action_widget().get_allocation ();
305 _drag_icon->set_size_request (a.get_width(), a.get_height());
311 Glib::RefPtr<Gdk::Screen const> s =
_drag_icon->get_screen ();
312 Glib::RefPtr<Gdk::Colormap const> c = s->get_rgba_colormap ();
319 _drag_icon->drag_set_as_icon (context, w / 2, h / 2);
332 cairo_t* cr = gdk_cairo_create (
_drag_icon->get_window()->gobj ());
334 Glib::RefPtr<Gdk::Pixmap> p =
_drag_child->action_widget().get_snapshot();
335 gdk_cairo_set_source_pixmap (cr, p->gobj(), 0, 0);
336 cairo_rectangle (cr, 0, 0, w, h);
343 void drag_data_get (Glib::RefPtr<Gdk::DragContext>
const &, Gtk::SelectionData & selection_data, guint, guint, T* child)
345 selection_data.set (selection_data.get_target(), 8, (
const guchar *) &child,
sizeof (&child));
349 Glib::RefPtr<Gdk::DragContext>
const & context,
int ,
int y, Gtk::SelectionData
const & selection_data, guint , guint time
359 T* child = *((T *
const *) selection_data.get_data());
361 if (drop.first == 0) {
366 int target = drop.second + 0.5;
370 typename std::list<T*>::const_iterator i =
_children.begin ();
371 while (i !=
_children.end() && *i != child && n < target) {
392 context->drag_finish (
false,
false, time);
395 void drag_end (Glib::RefPtr<Gdk::DragContext>
const &, T *)
419 int const n = c < 0 ? -1 : int (c + 0.5);
424 bool drag_motion (Glib::RefPtr<Gdk::DragContext>
const &,
int ,
int y, guint)
438 bool top_half = (c - int (c)) < 0.5;
462 void drag_leave (Glib::RefPtr<Gdk::DragContext>
const &, guint)
478 if (ev->button == 1 || ev->button == 3) {
482 if ((ev->state & Gdk::SHIFT_MASK) && !
_selection.empty()) {
486 bool selecting =
false;
488 for (
typename std::list<T*>::const_iterator i =
_children.begin(); i !=
_children.end(); ++i) {
490 bool const was_selected =
selected (*i);
492 if (selecting && !was_selected) {
496 if (!selecting && !done) {
499 }
else if (*i == child) {
503 }
else if (selecting) {
504 if (was_selected || *i == child) {
513 if ((ev->state & Gdk::CONTROL_MASK) == 0) {
527 if (ev->button == 1 && (ev->state & Gdk::CONTROL_MASK)) {
564 for (
typename std::list<T*>::iterator i = old_selection.begin(); i != old_selection.end(); ++i) {
571 if ( !child->is_selectable() )
589 typename std::list<T*>::const_iterator i =
_children.begin();
590 while (i !=
_children.end() && &(*i)->widget() != w) {
virtual bool is_selectable() const =0
std::list< T * > selection() const
std::list< T * > _selection
int create_or_update_placeholder(double c)
double get_children_around_position(int y, T **before, T **at, T **after) const
std::list< Gtk::TargetEntry > _targets
void remove_from_selection(T *child)
T * child_from_widget(Gtk::Widget const *w) const
void drag_end(Glib::RefPtr< Gdk::DragContext > const &, T *)
virtual void set_visual_state(VisualState, bool onoff)=0
bool drag_motion(Glib::RefPtr< Gdk::DragContext > const &, int, int y, guint)
std::pair< T *, double > get_child_at_position(int y) const
sigc::signal< void, DnDVBox *, T *, Glib::RefPtr< Gdk::DragContext > const & > DropFromAnotherBox
virtual std::string drag_text() const =0
virtual Gtk::EventBox & action_widget()=0
bool icon_expose(GdkEventExpose *)
std::list< T * > _children
int add_placeholder(double y)
void drag_data_received(Glib::RefPtr< Gdk::DragContext > const &context, int, int y, Gtk::SelectionData const &selection_data, guint, guint time)
bool button_release(GdkEventButton *ev, T *child)
sigc::signal< void > Reordered
virtual Gtk::Widget & widget()=0
void drag_data_get(Glib::RefPtr< Gdk::DragContext > const &, Gtk::SelectionData &selection_data, guint, guint, T *child)
void drag_leave(Glib::RefPtr< Gdk::DragContext > const &, guint)
void remove_placeholder()
double bottom_of_child_ignoring_placeholder(T *child) const
std::list< T * > children()
Gtk::Label * _placeholder
bool button_press(GdkEventButton *ev, T *child)
bool _expecting_unwanted_button_event
static DnDVBox * _drag_source
void drag_begin(Glib::RefPtr< Gdk::DragContext > const &context, T *child)
sigc::signal< bool, GdkEventButton *, T * > ButtonRelease
void setup_child_state(T *c)
bool selected(T *child) const
sigc::signal< bool, GdkEventButton *, T * > ButtonPress
void add_to_selection(T *child)
sigc::signal< void > SelectionChanged