fix computation of Text bounding box to respect _clamped_width
[ardour.git] / gtk2_ardour / group_tabs.cc
index 94caf5993684fe0dc385a7d144aa7aa83d3b369e..2394b9a6c5f29cff7a43e05efa737fab619fd45f 100644 (file)
@@ -42,7 +42,7 @@ GroupTabs::GroupTabs ()
        , _dragging (0)
        , _dragging_new_tab (0)
 {
-
+       add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
 }
 
 GroupTabs::~GroupTabs ()
@@ -175,12 +175,14 @@ GroupTabs::on_motion_notify_event (GdkEventMotion* ev)
        set_dirty ();
        queue_draw ();
 
+       gdk_event_request_motions(ev);
+
        return true;
 }
 
 
 bool
-GroupTabs::on_button_release_event (GdkEventButton* ev)
+GroupTabs::on_button_release_event (GdkEventButton*)
 {
        if (_dragging == 0) {
                return false;
@@ -243,10 +245,12 @@ GroupTabs::render (cairo_t* cr)
 
        /* background */
 
-       cairo_set_source_rgb (cr, 0, 0, 0);
-       cairo_rectangle (cr, 0, 0, _width, _height);
-       cairo_fill (cr);
+       Gdk::Color c = get_style()->get_base (Gtk::STATE_NORMAL);
 
+       cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
+       cairo_rectangle (cr, 0, 0, get_width(), get_height());
+       cairo_fill (cr);
+       
        /* tabs */
 
        for (list<Tab>::const_iterator i = _tabs.begin(); i != _tabs.end(); ++i) {
@@ -309,23 +313,28 @@ GroupTabs::get_menu (RouteGroup* g)
        _menu->set_name ("ArdourContextMenu");
        MenuList& items = _menu->items();
 
-       items.push_back (MenuElem (_("New..."), hide_return (sigc::mem_fun(*this, &GroupTabs::create_and_add_group))));
-       items.push_back (MenuElem (_("New From"), *new_from));
+       items.push_back (MenuElem (_("Create New Group ..."), hide_return (sigc::mem_fun(*this, &GroupTabs::create_and_add_group))));
+       items.push_back (MenuElem (_("Create New Group From"), *new_from));
 
        if (g) {
-               items.push_back (MenuElem (_("Edit..."), sigc::bind (sigc::mem_fun (*this, &GroupTabs::edit_group), g)));
-               items.push_back (MenuElem (_("Add New Subgroup Bus"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::subgroup), g, false, PreFader)));
+               items.push_back (MenuElem (_("Edit Group..."), sigc::bind (sigc::mem_fun (*this, &GroupTabs::edit_group), g)));
+               items.push_back (MenuElem (_("Collect Group"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::collect), g)));
+               items.push_back (MenuElem (_("Remove Group"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::remove_group), g)));
+               items.push_back (SeparatorElem());
+               if (g->has_subgroup()) {
+                       items.push_back (MenuElem (_("Remove Subgroup Bus"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::un_subgroup), g)));
+               } else {
+                       items.push_back (MenuElem (_("Add New Subgroup Bus"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::subgroup), g, false, PreFader)));
+               }
                items.push_back (MenuElem (_("Add New Aux Bus (pre-fader)"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::subgroup), g, true, PreFader)));
                items.push_back (MenuElem (_("Add New Aux Bus (post-fader)"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::subgroup), g, true, PostFader)));
-               items.push_back (MenuElem (_("Collect"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::collect), g)));
-               items.push_back (MenuElem (_("Remove"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::remove_group), g)));
        }
 
        add_menu_items (_menu, g);
 
        items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Activate All"), sigc::mem_fun(*this, &GroupTabs::activate_all)));
-       items.push_back (MenuElem (_("Disable All"), sigc::mem_fun(*this, &GroupTabs::disable_all)));
+       items.push_back (MenuElem (_("Enable All Groups"), sigc::mem_fun(*this, &GroupTabs::activate_all)));
+       items.push_back (MenuElem (_("Disable All Groups"), sigc::mem_fun(*this, &GroupTabs::disable_all)));
 
        return _menu;
 
@@ -431,14 +440,22 @@ GroupTabs::subgroup (RouteGroup* g, bool aux, Placement placement)
        g->make_subgroup (aux, placement);
 }
 
-struct CollectSorter {
-       CollectSorter (std::string const & key) : _key (key) {}
+void
+GroupTabs::un_subgroup (RouteGroup* g)
+{
+       g->destroy_subgroup ();
+}
 
+struct CollectSorter {
        bool operator () (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
-               return a->order_key (_key) < b->order_key (_key);
+               return a->order_key () < b->order_key ();
        }
+};
 
-       std::string _key;
+struct OrderSorter {
+       bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
+               return a->order_key () < b->order_key ();
+       }
 };
 
 /** Collect all members of a RouteGroup so that they are together in the Editor or Mixer.
@@ -448,18 +465,19 @@ void
 GroupTabs::collect (RouteGroup* g)
 {
        boost::shared_ptr<RouteList> group_routes = g->route_list ();
-       group_routes->sort (CollectSorter (order_key ()));
+       group_routes->sort (CollectSorter ());
        int const N = group_routes->size ();
 
        RouteList::iterator i = group_routes->begin ();
        boost::shared_ptr<RouteList> routes = _session->get_routes ();
+       routes->sort (OrderSorter ());
        RouteList::const_iterator j = routes->begin ();
 
        int diff = 0;
        int coll = -1;
        while (i != group_routes->end() && j != routes->end()) {
 
-               int const k = (*j)->order_key (order_key ());
+               int const k = (*j)->order_key ();
 
                if (*i == *j) {
 
@@ -470,14 +488,14 @@ GroupTabs::collect (RouteGroup* g)
                                --diff;
                        }
 
-                       (*j)->set_order_key (order_key (), coll);
+                       (*j)->set_order_key (coll);
 
                        ++coll;
                        ++i;
 
                } else {
 
-                       (*j)->set_order_key (order_key (), k + diff);
+                       (*j)->set_order_key (k + diff);
 
                }
 
@@ -530,7 +548,13 @@ GroupTabs::set_group_color (RouteGroup* group, Gdk::Color color)
 
        char buf[64];
        snprintf (buf, sizeof (buf), "%d:%d:%d", color.get_red(), color.get_green(), color.get_blue());
-       gui_state.set (group_gui_id (group), "color", buf);
+       gui_state.set_property (group_gui_id (group), "color", buf);
+       
+       /* the group color change notification */
+       
+       PBD::PropertyChange change;
+       change.add (Properties::color);
+       group->PropertyChanged (change);
 
        /* This is a bit of a hack, but this might change
           our route's effective color, so emit gui_changed