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 ()
39 GroupTabs::set_session (Session* s)
42 s->RouteGroupChanged.connect (mem_fun (*this, &GroupTabs::set_dirty));
46 /** Handle a size request.
47 * @param req GTK requisition
50 GroupTabs::on_size_request (Gtk::Requisition *req)
52 /* Use a dummy, small width and the actual height that we want */
58 GroupTabs::on_button_press_event (GdkEventButton* ev)
60 using namespace Menu_Helpers;
62 double const p = primary_coordinate (ev->x, ev->y);
66 Tab* t = click_to_tab (p, &prev, &next);
68 if (ev->button == 1 && t) {
74 double const h = (t->from + t->to) / 2;
78 /* limit is the end of the previous tab */
79 _drag_limit = prev ? prev->to : 0;
81 /* limit is the start of the next tab */
82 _drag_limit = next ? next->from : extent ();
85 } else if (ev->button == 3) {
87 RouteGroup* g = t ? t->group : 0;
88 get_menu(g)->popup (ev->button, ev->time);
97 GroupTabs::on_motion_notify_event (GdkEventMotion* ev)
103 double const p = primary_coordinate (ev->x, ev->y);
105 if (p != _drag_last) {
111 double f = _dragging->from + p - _drag_last;
113 if (f < _drag_limit) {
114 /* limit drag in the `too big' direction */
118 double const t = _dragging->to - _dragging->last_ui_size;
120 /* limit drag in the `too small' direction */
128 double t = _dragging->to + p - _drag_last;
130 if (t > _drag_limit) {
131 /* limit drag in the `too big' direction */
135 double const f = _dragging->from + _dragging->first_ui_size;
137 /* limit drag in the `too small' direction */
154 GroupTabs::on_button_release_event (GdkEventButton* ev)
156 if (_dragging == 0) {
161 /* toggle active state */
162 _dragging->group->set_active (!_dragging->group->is_active (), this);
167 reflect_tabs (_tabs);
176 GroupTabs::render (cairo_t* cr)
178 if (_dragging == 0) {
179 _tabs = compute_tabs ();
184 cairo_set_source_rgb (cr, 0, 0, 0);
185 cairo_rectangle (cr, 0, 0, _width, _height);
190 for (list<Tab>::const_iterator i = _tabs.begin(); i != _tabs.end(); ++i) {
196 /** Convert a click position to a tab.
197 * @param c Click position.
198 * @param prev Filled in with the previous tab to the click, or 0.
199 * @param next Filled in with the next tab after the click, or 0.
200 * @return Tab under the click, or 0.
204 GroupTabs::click_to_tab (double c, Tab** prev, Tab** next)
208 list<Tab>::iterator i = _tabs.begin ();
209 while (i != _tabs.end() && (c < i->from || c > i->to)) {
214 if (i == _tabs.end()) {
219 list<Tab>::iterator j = i;
221 if (j == _tabs.end()) {