2 Copyright (C) 2002-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.
21 #include <boost/weak_ptr.hpp>
22 #include <gtkmm/menu.h>
23 #include <gtkmm/menushell.h>
24 #include <gtkmm/menu_elems.h>
25 #include <cairo/cairo.h>
26 #include "ardour/bundle.h"
27 #include "port_matrix_row_labels.h"
28 #include "port_matrix.h"
31 PortMatrixRowLabels::PortMatrixRowLabels (PortMatrix* p, PortMatrixBody* b)
32 : PortMatrixComponent (b), _port_matrix (p), _menu (0)
37 PortMatrixRowLabels::~PortMatrixRowLabels ()
43 PortMatrixRowLabels::compute_dimensions ()
45 GdkPixmap* pm = gdk_pixmap_new (NULL, 1, 1, 24);
46 gdk_drawable_set_colormap (pm, gdk_colormap_get_system());
47 cairo_t* cr = gdk_cairo_create (pm);
49 _longest_port_name = 0;
50 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
51 for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
52 cairo_text_extents_t ext;
53 cairo_text_extents (cr, (*i)->channel_name(j).c_str(), &ext);
54 if (ext.width > _longest_port_name) {
55 _longest_port_name = ext.width;
60 _longest_bundle_name = 0;
61 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
62 cairo_text_extents_t ext;
63 cairo_text_extents (cr, (*i)->name().c_str(), &ext);
64 if (ext.width > _longest_bundle_name) {
65 _longest_bundle_name = ext.width;
70 gdk_pixmap_unref (pm);
73 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
74 _height += (*i)->nchannels() * row_height();
77 _width = _longest_port_name +
79 _longest_bundle_name + name_pad() * 2;
84 PortMatrixRowLabels::render (cairo_t* cr)
88 set_source_rgb (cr, background_colour());
89 cairo_rectangle (cr, 0, 0, _width, _height);
92 /* SIDE BUNDLE NAMES */
94 uint32_t x = _longest_port_name + name_pad() * 3;
97 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
99 Gdk::Color const colour = get_a_bundle_colour (i - _body->row_bundles().begin ());
100 set_source_rgb (cr, colour);
105 _longest_port_name + name_pad() * 4 + _longest_bundle_name + name_pad() * 2,
106 row_height() * (*i)->nchannels()
108 cairo_fill_preserve (cr);
109 set_source_rgb (cr, background_colour());
110 cairo_set_line_width (cr, label_border_width ());
114 if ((*i)->nchannels () > 0) {
115 /* use the extent of our first channel name so that the bundle name is vertically aligned with it */
116 cairo_text_extents_t ext;
117 cairo_text_extents (cr, (*i)->channel_name(0).c_str(), &ext);
118 off = (row_height() - ext.height) / 2;
120 off = row_height() / 2;
123 set_source_rgb (cr, text_colour());
124 cairo_move_to (cr, x, y + name_pad() + off);
125 cairo_show_text (cr, (*i)->name().c_str());
127 y += row_height() * (*i)->nchannels ();
131 /* SIDE PORT NAMES */
134 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
135 for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
137 Gdk::Color const colour = get_a_bundle_colour (i - _body->row_bundles().begin ());
138 set_source_rgb (cr, colour);
143 _longest_port_name + (name_pad() * 2),
146 cairo_fill_preserve (cr);
147 set_source_rgb (cr, background_colour());
148 cairo_set_line_width (cr, label_border_width ());
151 cairo_text_extents_t ext;
152 cairo_text_extents (cr, (*i)->channel_name(j).c_str(), &ext);
153 uint32_t const off = (row_height() - ext.height) / 2;
155 set_source_rgb (cr, text_colour());
156 cairo_move_to (cr, name_pad(), y + name_pad() + off);
157 cairo_show_text (cr, (*i)->channel_name(j).c_str());
165 PortMatrixRowLabels::button_press (double x, double y, int b, uint32_t t)
167 if (b == 3 && x < (_longest_port_name + name_pad() * 2) ) {
171 _menu = new Gtk::Menu;
172 _menu->set_name ("ArdourContextMenu");
174 Gtk::Menu_Helpers::MenuList& items = _menu->items ();
177 uint32_t row = y / row_height ();
179 boost::shared_ptr<ARDOUR::Bundle> bundle;
182 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
183 if (row < (*i)->nchannels ()) {
188 row -= (*i)->nchannels ();
195 if (_port_matrix->can_rename_channels ()) {
196 snprintf (buf, sizeof (buf), _("Rename '%s'..."), bundle->channel_name (channel).c_str());
198 Gtk::Menu_Helpers::MenuElem (
200 sigc::bind (sigc::mem_fun (*this, &PortMatrixRowLabels::rename_channel_proxy), bundle, channel)
205 snprintf (buf, sizeof (buf), _("Remove '%s'"), bundle->channel_name (channel).c_str());
207 Gtk::Menu_Helpers::MenuElem (
209 sigc::bind (sigc::mem_fun (*this, &PortMatrixRowLabels::remove_channel_proxy), bundle, channel)
220 PortMatrixRowLabels::remove_channel_proxy (boost::weak_ptr<ARDOUR::Bundle> b, uint32_t c)
222 boost::shared_ptr<ARDOUR::Bundle> sb = b.lock ();
227 _port_matrix->remove_channel (sb, c);
232 PortMatrixRowLabels::rename_channel_proxy (boost::weak_ptr<ARDOUR::Bundle> b, uint32_t c)
234 boost::shared_ptr<ARDOUR::Bundle> sb = b.lock ();
239 _port_matrix->rename_channel (sb, c);