2009-06-21 15:59:56 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2009 Paul Davis
|
2009-06-21 15:59:56 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtkmm/stock.h>
|
|
|
|
#include "ardour/session.h"
|
|
|
|
#include "ardour/route_group.h"
|
|
|
|
#include "route_group_dialog.h"
|
|
|
|
#include "group_tabs.h"
|
2009-06-22 20:27:52 -04:00
|
|
|
#include "keyboard.h"
|
2009-06-21 15:59:56 -04:00
|
|
|
#include "i18n.h"
|
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
using namespace std;
|
2009-06-21 15:59:56 -04:00
|
|
|
using namespace Gtk;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
2009-07-03 14:37:15 -04:00
|
|
|
GroupTabs::GroupTabs (Editor* e)
|
|
|
|
: EditorComponent (e),
|
2009-06-21 18:17:17 -04:00
|
|
|
_dragging (0)
|
2009-06-21 15:59:56 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-03 14:37:15 -04:00
|
|
|
GroupTabs::connect_to_session (Session* s)
|
2009-06-21 15:59:56 -04:00
|
|
|
{
|
2009-07-03 14:37:15 -04:00
|
|
|
EditorComponent::connect_to_session (s);
|
|
|
|
|
|
|
|
_session_connections.push_back (_session->RouteGroupChanged.connect (mem_fun (*this, &GroupTabs::set_dirty)));
|
2009-06-21 15:59:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Handle a size request.
|
|
|
|
* @param req GTK requisition
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
GroupTabs::on_size_request (Gtk::Requisition *req)
|
|
|
|
{
|
|
|
|
/* Use a dummy, small width and the actual height that we want */
|
|
|
|
req->width = 16;
|
|
|
|
req->height = 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GroupTabs::on_button_press_event (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
using namespace Menu_Helpers;
|
2009-06-21 18:17:17 -04:00
|
|
|
|
|
|
|
double const p = primary_coordinate (ev->x, ev->y);
|
|
|
|
|
|
|
|
Tab* prev;
|
|
|
|
Tab* next;
|
|
|
|
Tab* t = click_to_tab (p, &prev, &next);
|
|
|
|
|
2009-06-22 19:17:46 -04:00
|
|
|
if (ev->button == 1 && t) {
|
2009-06-21 18:17:17 -04:00
|
|
|
|
|
|
|
_dragging = t;
|
|
|
|
_drag_moved = false;
|
|
|
|
_drag_last = p;
|
|
|
|
|
|
|
|
double const h = (t->from + t->to) / 2;
|
|
|
|
_drag_from = p < h;
|
|
|
|
|
|
|
|
if (_drag_from) {
|
2009-06-22 11:47:48 -04:00
|
|
|
/* limit is the end of the previous tab */
|
2009-06-21 18:17:17 -04:00
|
|
|
_drag_limit = prev ? prev->to : 0;
|
|
|
|
} else {
|
2009-06-22 11:47:48 -04:00
|
|
|
/* limit is the start of the next tab */
|
2009-06-21 18:17:17 -04:00
|
|
|
_drag_limit = next ? next->from : extent ();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (ev->button == 3) {
|
2009-06-21 15:59:56 -04:00
|
|
|
|
2009-06-22 19:17:46 -04:00
|
|
|
RouteGroup* g = t ? t->group : 0;
|
2009-06-23 19:05:14 -04:00
|
|
|
Menu* m = get_menu (g);
|
|
|
|
if (m) {
|
|
|
|
m->popup (ev->button, ev->time);
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 15:59:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
bool
|
|
|
|
GroupTabs::on_motion_notify_event (GdkEventMotion* ev)
|
|
|
|
{
|
|
|
|
if (_dragging == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
double const p = primary_coordinate (ev->x, ev->y);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
if (p != _drag_last) {
|
|
|
|
_drag_moved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_drag_from) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
double f = _dragging->from + p - _drag_last;
|
2009-06-22 11:47:48 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
if (f < _drag_limit) {
|
2009-06-22 11:47:48 -04:00
|
|
|
/* limit drag in the `too big' direction */
|
2009-06-21 18:17:17 -04:00
|
|
|
f = _drag_limit;
|
|
|
|
}
|
2009-06-21 20:33:31 -04:00
|
|
|
|
|
|
|
double const t = _dragging->to - _dragging->last_ui_size;
|
|
|
|
if (f > t) {
|
2009-06-22 11:47:48 -04:00
|
|
|
/* limit drag in the `too small' direction */
|
2009-06-21 20:33:31 -04:00
|
|
|
f = t;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
_dragging->from = f;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
} else {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
double t = _dragging->to + p - _drag_last;
|
2009-06-21 20:33:31 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
if (t > _drag_limit) {
|
2009-06-22 11:47:48 -04:00
|
|
|
/* limit drag in the `too big' direction */
|
2009-06-21 18:17:17 -04:00
|
|
|
t = _drag_limit;
|
|
|
|
}
|
2009-06-21 20:33:31 -04:00
|
|
|
|
|
|
|
double const f = _dragging->from + _dragging->first_ui_size;
|
|
|
|
if (t < f) {
|
2009-06-22 11:47:48 -04:00
|
|
|
/* limit drag in the `too small' direction */
|
2009-06-21 20:33:31 -04:00
|
|
|
t = f;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
_dragging->to = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_dirty ();
|
|
|
|
queue_draw ();
|
|
|
|
|
|
|
|
_drag_last = p;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
GroupTabs::on_button_release_event (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
if (_dragging == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_drag_moved) {
|
2009-06-22 20:27:52 -04:00
|
|
|
|
|
|
|
if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
|
|
|
|
|
|
|
|
/* edit */
|
|
|
|
RouteGroupDialog d (_dragging->group, Gtk::Stock::APPLY);
|
|
|
|
d.do_run ();
|
|
|
|
|
|
|
|
} else {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-22 20:27:52 -04:00
|
|
|
/* toggle active state */
|
|
|
|
_dragging->group->set_active (!_dragging->group->is_active (), this);
|
|
|
|
_dragging = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-22 20:27:52 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
} else {
|
2009-06-22 11:47:48 -04:00
|
|
|
/* finish drag */
|
2009-06-21 18:17:17 -04:00
|
|
|
_dragging = 0;
|
|
|
|
reflect_tabs (_tabs);
|
|
|
|
set_dirty ();
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GroupTabs::render (cairo_t* cr)
|
|
|
|
{
|
|
|
|
if (_dragging == 0) {
|
|
|
|
_tabs = compute_tabs ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* background */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
cairo_set_source_rgb (cr, 0, 0, 0);
|
|
|
|
cairo_rectangle (cr, 0, 0, _width, _height);
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
/* tabs */
|
|
|
|
|
|
|
|
for (list<Tab>::const_iterator i = _tabs.begin(); i != _tabs.end(); ++i) {
|
|
|
|
draw_tab (cr, *i);
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2009-06-21 18:17:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-22 11:47:48 -04:00
|
|
|
/** Convert a click position to a tab.
|
|
|
|
* @param c Click position.
|
|
|
|
* @param prev Filled in with the previous tab to the click, or 0.
|
|
|
|
* @param next Filled in with the next tab after the click, or 0.
|
|
|
|
* @return Tab under the click, or 0.
|
|
|
|
*/
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
GroupTabs::Tab *
|
|
|
|
GroupTabs::click_to_tab (double c, Tab** prev, Tab** next)
|
|
|
|
{
|
2009-06-22 17:04:52 -04:00
|
|
|
*prev = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-06-21 18:17:17 -04:00
|
|
|
list<Tab>::iterator i = _tabs.begin ();
|
|
|
|
while (i != _tabs.end() && (c < i->from || c > i->to)) {
|
|
|
|
*prev = &(*i);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == _tabs.end()) {
|
|
|
|
*next = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
list<Tab>::iterator j = i;
|
|
|
|
++j;
|
|
|
|
if (j == _tabs.end()) {
|
|
|
|
*next = 0;
|
|
|
|
} else {
|
|
|
|
*next = &(*j);
|
|
|
|
}
|
|
|
|
|
|
|
|
return &(*i);
|
|
|
|
}
|
2009-06-21 21:01:43 -04:00
|
|
|
|