Assorted doxygen fixes; no functional changes.
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / dndvbox.h
index 582696ffe5c0e81d31f6202f8b24e96922246479..e0b1c6ea1338adcf0447c6dc6ba066a5d232bcec 100644 (file)
@@ -35,6 +35,9 @@ public:
 
        /** @return Text to use in the icon that is dragged */
        virtual std::string drag_text () const = 0;
+
+       /** Set the child's visual state */
+       virtual void set_visual_state (Gtk::StateType) = 0;
 };
 
 /** A VBox whose contents can be dragged and dropped */
@@ -57,6 +60,8 @@ public:
                signal_button_release_event().connect (bind (mem_fun (*this, &DnDVBox::button_release), (T *) 0));
                signal_drag_motion().connect (mem_fun (*this, &DnDVBox::drag_motion));
                signal_drag_leave().connect (mem_fun (*this, &DnDVBox::drag_leave));
+
+               _internal_vbox.show ();
                
                drag_dest_set (_targets);
                signal_drag_data_received().connect (mem_fun (*this, &DnDVBox::drag_data_received));
@@ -82,7 +87,7 @@ public:
                _internal_vbox.pack_start (child->widget(), false, false);
                
                _children.push_back (child);
-               child->widget().show_all ();
+               child->widget().show ();
        }
 
        /** @return Children, sorted into the order that they are currently being displayed in the widget */
@@ -122,7 +127,7 @@ public:
                }
        }
 
-       /** @param Child
+       /** @param child Child
         *  @return true if the child is selected, otherwise false.
         */
        bool selected (T* child) const {
@@ -140,6 +145,7 @@ public:
                }
 
                _children.clear ();
+               _active = 0;
        }
 
        void select_all ()
@@ -276,35 +282,25 @@ private:
                _drag_source = this;
        }
 
-       /* Draw the drag icon; we go to these lengths so that we can have the icon
-        * transparent if the window system supports it.
-        */
-       bool icon_expose (GdkEventExpose *)
+       /* Draw the drag icon */
+       bool icon_expose (GdkEventExpose* ev)
        {
-               cairo_t* cr = gdk_cairo_create (_drag_icon->get_window()->gobj());
-               
-               if (_have_alpha) {
-                       cairo_set_source_rgba (cr, 0.2, 0.2, 0.2, 0.5);
-               } else {
-                       cairo_set_source_rgba (cr, 0, 0, 0, 1);
-               }
-               
-               cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-               cairo_paint (cr);
-               cairo_set_source_rgba (cr, 1, 1, 1, 0.8);
+               /* Just grab the child's widget and use that */
 
-               cairo_text_extents_t ext;
-               cairo_text_extents (cr, _drag_child->drag_text().c_str(), &ext);
-               
-               cairo_move_to (cr, 0, ext.height);
-               cairo_show_text (cr, _drag_child->drag_text().c_str ());
-               cairo_restore (cr);
-               cairo_destroy (cr);
+               int w, h;
+               _drag_icon->get_size (w, h);
 
+               cairo_t* cr = gdk_cairo_create (_drag_icon->get_window()->gobj ());
+
+               Glib::RefPtr<Gdk::Pixmap> p = _drag_child->widget().get_snapshot();
+               gdk_cairo_set_source_pixmap (cr, p->gobj(), 0, 0);
+               cairo_rectangle (cr, 0, 0, w, h);
+               cairo_fill (cr);
+               cairo_destroy (cr);
+               
                return false;
        }
        
-       
        void drag_data_get (Glib::RefPtr<Gdk::DragContext> const &, Gtk::SelectionData & selection_data, guint, guint, T* child)
        {
                selection_data.set (selection_data.get_target(), 8, (const guchar *) &child, sizeof (&child));
@@ -316,18 +312,36 @@ private:
        {
                /* work out where it was dropped */
                std::pair<T*, double> const drop = get_child_at_position (y);
+
+               
                
                if (_drag_source == this) {
 
                        /* dropped from ourselves onto ourselves */
-                       
+
                        T* child = *((T **) selection_data.get_data());
-                       
-                       /* reorder child widgets accordingly */
+
                        if (drop.first == 0) {
                                _internal_vbox.reorder_child (child->widget(), -1);
                        } else {
-                               _internal_vbox.reorder_child (child->widget(), int (drop.second));
+
+                               /* where in the list this child should be dropped */
+                               int target = drop.second + 0.5;
+                               
+                               /* find out whether the child was `picked up' from before the drop position */
+                               int n = 0;
+                               typename std::list<T*>::const_iterator i = _children.begin ();
+                               while (i != _children.end() && *i != child && n < target) {
+                                       ++i;
+                                       ++n;
+                               }
+                               
+                               /* if so, adjust the drop position to account for this */
+                               if (n < target) {
+                                       --target;
+                               }
+                               
+                               _internal_vbox.reorder_child (child->widget(), target);
                        }
                        
                } else {
@@ -504,11 +518,11 @@ private:
                assert (c);
                
                if (c == _active) {
-                       c->action_widget().set_state (Gtk::STATE_ACTIVE);
+                       c->set_visual_state (Gtk::STATE_ACTIVE);
                } else if (selected (c)) {
-                       c->action_widget().set_state (Gtk::STATE_SELECTED);
+                       c->set_visual_state (Gtk::STATE_SELECTED);
                } else {
-                       c->action_widget().set_state (Gtk::STATE_NORMAL);
+                       c->set_visual_state (Gtk::STATE_NORMAL);
                }
        }