2 Copyright (C) 2002-2007 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/label.h>
21 #include <gtkmm/enums.h>
22 #include <gtkmm/menu.h>
23 #include <gtkmm/menu_elems.h>
24 #include <gtkmm/menuitem.h>
25 #include <gtkmm/menushell.h>
26 #include <glibmm/objectbase.h>
27 #include <gtkmm2ext/doi.h>
28 #include "ardour/data_type.h"
30 #include "port_matrix.h"
34 PortMatrix::PortMatrix (ARDOUR::Session& session, ARDOUR::DataType type, bool offer_inputs, PortGroupList::Mask mask)
35 : _offer_inputs (offer_inputs), _port_group_list (session, type, offer_inputs, mask), _type (type), matrix (this)
39 _visibility_checkbutton_box.pack_start (*(manage (new Label (_("Connections displayed: ")))), false, false, 10);
40 pack_start (_visibility_checkbutton_box, false, false);
42 _scrolled_window.set_policy (POLICY_ALWAYS, POLICY_AUTOMATIC);
43 _scrolled_window.set_shadow_type (SHADOW_NONE);
45 _scrolled_window.add (matrix);
48 _overall_hbox.pack_start (_side_vbox, false, false, 6);
49 _overall_hbox.pack_start (_scrolled_window, true, true);
51 _overall_hbox.pack_start (_scrolled_window, true, true, 6);
52 _overall_hbox.pack_start (_side_vbox, false, false);
55 pack_start (_overall_hbox);
58 PortMatrix::~PortMatrix ()
64 PortMatrix::set_ports (const std::list<std::string>& ports)
66 matrix.set_ports (ports);
69 /** Clear out the things that change when the number of source or destination ports changes */
73 /* remove lurking, invisible label and padding */
75 _side_vbox.children().clear ();
77 delete _side_vbox_pad;
80 for (std::vector<PortGroupUI*>::iterator i = _port_group_ui.begin(); i != _port_group_ui.end(); ++i) {
81 _visibility_checkbutton_box.remove ((*i)->get_visibility_checkbutton());
85 _port_group_ui.clear ();
88 /** Set up the dialogue */
92 /* sort out the ports that we'll offer to connect to */
93 _port_group_list.refresh ();
97 _side_vbox_pad = new Label (""); /* unmanaged, explicitly deleted */
99 _side_vbox.pack_start (*_side_vbox_pad, false, false);
100 _side_vbox.pack_start (*manage (new Label ("")));
104 /* Matrix and visibility checkbuttons */
105 for (PortGroupList::iterator i = _port_group_list.begin(); i != _port_group_list.end(); ++i) {
107 PortGroupUI* t = new PortGroupUI (*this, **i);
109 _port_group_ui.push_back (t);
111 matrix.add_group (**i);
113 _visibility_checkbutton_box.pack_start (t->get_visibility_checkbutton(), false, false);
115 CheckButton* chk = dynamic_cast<CheckButton*>(&t->get_visibility_checkbutton());
118 chk->signal_toggled().connect (sigc::mem_fun (*this, &PortMatrix::reset_visibility));
128 PortMatrix::reset_visibility ()
130 for (std::vector<PortGroupUI*>::iterator i = _port_group_ui.begin(); i != _port_group_ui.end(); ++i) {
132 (*i)->setup_visibility ();
134 if ((*i)->port_group().visible) {
135 matrix.show_group ((*i)->port_group());
137 matrix.hide_group ((*i)->port_group());
143 /** Handle a button press on a row label */
145 PortMatrix::row_label_button_pressed (GdkEventButton* e, int r)
147 if (e->type != GDK_BUTTON_PRESS || e->button != 3) {
151 Menu* menu = manage (new Menu);
152 Menu_Helpers::MenuList& items = menu->items ();
153 menu->set_name ("ArdourContextMenu");
155 bool const can_add = maximum_rows () > n_rows ();
156 bool const can_remove = minimum_rows () < n_rows ();
157 std::string const name = row_name (r);
160 Menu_Helpers::MenuElem (string_compose(_("Add %1"), row_descriptor()), sigc::mem_fun (*this, &PortMatrix::add_row))
163 items.back().set_sensitive (can_add);
166 Menu_Helpers::MenuElem (string_compose(_("Remove %1 \"%2\""), row_descriptor(), name), sigc::bind (sigc::mem_fun (*this, &PortMatrix::remove_row), r))
169 items.back().set_sensitive (can_remove);
171 menu->popup (e->button, e->time);
177 PortMatrix::set_type (ARDOUR::DataType t)
180 _port_group_list.set_type (t);
185 PortMatrix::set_offer_inputs (bool i)
188 _port_group_list.set_offer_inputs (i);