2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gtkmm/stock.h>
21 #include "ardour/session.h"
22 #include "ardour/route_group.h"
23 #include "route_group_dialog.h"
24 #include "group_tabs.h"
29 using namespace ARDOUR;
31 GroupTabs::GroupTabs ()
40 GroupTabs::set_session (Session* s)
43 s->RouteGroupChanged.connect (mem_fun (*this, &GroupTabs::set_dirty));
47 /** Handle a size request.
48 * @param req GTK requisition
51 GroupTabs::on_size_request (Gtk::Requisition *req)
53 /* Use a dummy, small width and the actual height that we want */
59 GroupTabs::on_button_press_event (GdkEventButton* ev)
61 using namespace Menu_Helpers;
63 double const p = primary_coordinate (ev->x, ev->y);
67 Tab* t = click_to_tab (p, &prev, &next);
72 if (ev->button == 1) {
78 double const h = (t->from + t->to) / 2;
82 _drag_limit = prev ? prev->to : 0;
84 _drag_limit = next ? next->from : extent ();
87 } else if (ev->button == 3) {
91 MenuList& items = _menu->items ();
92 items.push_back (MenuElem (_("Edit..."), bind (mem_fun (*this, &GroupTabs::edit_group), t->group)));
93 items.push_back (MenuElem (_("Remove"), bind (mem_fun (*this, &GroupTabs::remove_group), t->group)));
95 _menu->popup (ev->button, ev->time);
104 GroupTabs::on_motion_notify_event (GdkEventMotion* ev)
106 if (_dragging == 0) {
110 double const p = primary_coordinate (ev->x, ev->y);
112 if (p != _drag_last) {
117 double f = _dragging->from + p - _drag_last;
118 if (f < _drag_limit) {
123 double t = _dragging->to + p - _drag_last;
124 if (t > _drag_limit) {
140 GroupTabs::on_button_release_event (GdkEventButton* ev)
142 if (_dragging == 0) {
147 _dragging->group->set_active (!_dragging->group->is_active (), this);
151 reflect_tabs (_tabs);
161 GroupTabs::edit_group (RouteGroup* g)
163 RouteGroupDialog d (g, Gtk::Stock::APPLY);
168 GroupTabs::remove_group (RouteGroup *g)
170 _session->remove_route_group (*g);
174 GroupTabs::render (cairo_t* cr)
176 if (_dragging == 0) {
177 _tabs = compute_tabs ();
182 cairo_set_source_rgb (cr, 0, 0, 0);
183 cairo_rectangle (cr, 0, 0, _width, _height);
188 for (list<Tab>::const_iterator i = _tabs.begin(); i != _tabs.end(); ++i) {
195 GroupTabs::click_to_tab (double c, Tab** prev, Tab** next)
197 list<Tab>::iterator i = _tabs.begin ();
198 while (i != _tabs.end() && (c < i->from || c > i->to)) {
203 if (i == _tabs.end()) {
208 list<Tab>::iterator j = i;
210 if (j == _tabs.end()) {