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"
30 using namespace ARDOUR;
32 GroupTabs::GroupTabs (Editor* e)
33 : EditorComponent (e),
40 GroupTabs::connect_to_session (Session* s)
42 EditorComponent::connect_to_session (s);
44 _session_connections.push_back (_session->RouteGroupChanged.connect (mem_fun (*this, &GroupTabs::set_dirty)));
48 /** Handle a size request.
49 * @param req GTK requisition
52 GroupTabs::on_size_request (Gtk::Requisition *req)
54 /* Use a dummy, small width and the actual height that we want */
60 GroupTabs::on_button_press_event (GdkEventButton* ev)
62 using namespace Menu_Helpers;
64 double const p = primary_coordinate (ev->x, ev->y);
68 Tab* t = click_to_tab (p, &prev, &next);
70 if (ev->button == 1 && t) {
76 double const h = (t->from + t->to) / 2;
80 /* limit is the end of the previous tab */
81 _drag_limit = prev ? prev->to : 0;
83 /* limit is the start of the next tab */
84 _drag_limit = next ? next->from : extent ();
87 } else if (ev->button == 3) {
89 RouteGroup* g = t ? t->group : 0;
90 Menu* m = get_menu (g);
92 m->popup (ev->button, ev->time);
102 GroupTabs::on_motion_notify_event (GdkEventMotion* ev)
104 if (_dragging == 0) {
108 double const p = primary_coordinate (ev->x, ev->y);
110 if (p != _drag_last) {
116 double f = _dragging->from + p - _drag_last;
118 if (f < _drag_limit) {
119 /* limit drag in the `too big' direction */
123 double const t = _dragging->to - _dragging->last_ui_size;
125 /* limit drag in the `too small' direction */
133 double t = _dragging->to + p - _drag_last;
135 if (t > _drag_limit) {
136 /* limit drag in the `too big' direction */
140 double const f = _dragging->from + _dragging->first_ui_size;
142 /* limit drag in the `too small' direction */
159 GroupTabs::on_button_release_event (GdkEventButton* ev)
161 if (_dragging == 0) {
167 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
170 RouteGroupDialog d (_dragging->group, Gtk::Stock::APPLY);
175 /* toggle active state */
176 _dragging->group->set_active (!_dragging->group->is_active (), this);
184 reflect_tabs (_tabs);
193 GroupTabs::render (cairo_t* cr)
195 if (_dragging == 0) {
196 _tabs = compute_tabs ();
201 cairo_set_source_rgb (cr, 0, 0, 0);
202 cairo_rectangle (cr, 0, 0, _width, _height);
207 for (list<Tab>::const_iterator i = _tabs.begin(); i != _tabs.end(); ++i) {
213 /** Convert a click position to a tab.
214 * @param c Click position.
215 * @param prev Filled in with the previous tab to the click, or 0.
216 * @param next Filled in with the next tab after the click, or 0.
217 * @return Tab under the click, or 0.
221 GroupTabs::click_to_tab (double c, Tab** prev, Tab** next)
225 list<Tab>::iterator i = _tabs.begin ();
226 while (i != _tabs.end() && (c < i->from || c > i->to)) {
231 if (i == _tabs.end()) {
236 list<Tab>::iterator j = i;
238 if (j == _tabs.end()) {