revert last fix - its not relevant to 3.0 (yet)
[ardour.git] / gtk2_ardour / port_matrix.h
1 /*
2     Copyright (C) 2002-2007 Paul Davis 
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_ui_port_matrix_h__
21 #define __ardour_ui_port_matrix_h__
22
23 #include <gtkmm/box.h>
24 #include <gtkmm/checkbutton.h>
25 #include <gtkmm/table.h>
26 #include <gtkmm/frame.h>
27 #include <gtkmm/eventbox.h>
28 #include <gtkmm/scrolledwindow.h>
29
30 #include "ardour_dialog.h"
31
32 namespace ARDOUR {
33         class Session;
34         class IO;
35         class PortInsert;
36 }
37
38 class PortMatrix;
39
40 /// A list of port names, grouped by some aspect of their type e.g. busses, tracks, system
41 class PortGroup
42 {
43   public:
44         /** PortGroup constructor.
45          * @param n Name.
46          * @param p Port name prefix.
47          * @param v true if group should be visible in the UI, otherwise false.
48          */
49         PortGroup (std::string const & n, std::string const & p, bool v) : name (n), prefix (p), visible (v) {}
50
51         void add (std::string const & p);
52
53         std::string name; ///< name for the group
54         std::string prefix; ///< prefix (before colon) e.g. "ardour:"
55         std::vector<std::string> ports; ///< port names
56         bool visible; ///< true if the group is visible in the UI
57 };
58
59 /// The UI for a PortGroup
60 class PortGroupUI
61 {
62   public:
63         PortGroupUI (PortMatrix&, PortGroup&);
64
65         Gtk::Widget& get_table ();
66         Gtk::Widget& get_visibility_checkbutton ();
67         std::pair<int, int> unit_size () const;
68         PortGroup& port_group () { return _port_group; }
69         void setup_visibility ();
70
71   private:
72         void port_checkbutton_toggled (Gtk::CheckButton*, int, int);
73         bool port_checkbutton_release (GdkEventButton* ev, Gtk::CheckButton* b, int r, int c);
74         void visibility_checkbutton_toggled ();
75
76         PortMatrix& _port_matrix; ///< the PortMatrix that we are working for
77         PortGroup& _port_group; ///< the PortGroup that we are representing
78         bool _ignore_check_button_toggle;
79         Gtk::Table _table;
80         Gtk::EventBox _table_box;
81         std::vector<std::vector<Gtk::CheckButton* > > _port_checkbuttons;
82         Gtk::CheckButton _visibility_checkbutton;
83 };
84
85 /// A list of PortGroups
86 class PortGroupList : public std::list<PortGroup*>
87 {
88   public:
89         enum Mask {
90                 BUSS = 0x1,
91                 TRACK = 0x2,
92                 SYSTEM = 0x4,
93                 OTHER = 0x8
94         };
95
96         PortGroupList (ARDOUR::Session &, ARDOUR::DataType, bool, Mask);
97
98         void refresh ();
99         int n_visible_ports () const;
100         std::string get_port_by_index (int, bool with_prefix = true) const;
101         void set_type (ARDOUR::DataType);
102         void set_offer_inputs (bool);
103         
104   private:
105         ARDOUR::Session& _session;
106         ARDOUR::DataType _type;
107         bool _offer_inputs;
108
109         PortGroup buss;
110         PortGroup track;
111         PortGroup system;
112         PortGroup other;
113 };
114
115
116 /// A widget which provides a set of rotated text labels
117 class RotatedLabelSet : public Gtk::Widget {
118   public:
119         RotatedLabelSet (PortGroupList&);
120         virtual ~RotatedLabelSet ();
121
122         void set_angle (int);
123         void set_base_width (int);
124         void update_visibility ();
125         
126   protected:
127         virtual void on_size_request (Gtk::Requisition*);
128         virtual void on_size_allocate (Gtk::Allocation&);
129         virtual void on_realize ();
130         virtual void on_unrealize ();
131         virtual bool on_expose_event (GdkEventExpose*);
132
133         Glib::RefPtr<Gdk::Window> _gdk_window;
134
135   private:
136         std::pair<int, int> setup_layout (std::string const &);
137
138         PortGroupList& _port_group_list; ///< list of ports to display
139         int _angle_degrees; ///< label rotation angle in degrees
140         double _angle_radians; ///< label rotation angle in radians
141         int _base_width; ///< width of labels; see set_base_width() for more details
142         Glib::RefPtr<Pango::Context> _pango_context;
143         Glib::RefPtr<Pango::Layout> _pango_layout;
144         Glib::RefPtr<Gdk::GC> _gc;
145         Gdk::Color _fg_colour;
146         Gdk::Color _bg_colour;
147 };
148
149
150 class PortMatrix : public Gtk::VBox {
151   public:
152         PortMatrix (ARDOUR::Session&, ARDOUR::DataType, bool, PortGroupList::Mask);
153         ~PortMatrix ();
154
155         void redisplay ();
156
157         enum Result {
158                 Cancelled,
159                 Accepted
160         };
161
162         sigc::signal<void, Result> Finished;
163
164         void set_type (ARDOUR::DataType);
165         void set_offer_inputs (bool);
166         bool offering_input() const { return _offer_inputs; }
167
168         virtual void set_state (int, std::string const &, bool, uint32_t) = 0;
169         virtual bool get_state (int, std::string const &) const = 0;
170         virtual uint32_t n_rows () const = 0;
171         virtual uint32_t maximum_rows () const = 0;
172         virtual uint32_t minimum_rows () const = 0;
173         virtual std::string row_name (int) const = 0;
174         virtual void add_row () = 0;
175         virtual void remove_row (int) = 0;
176         virtual std::string row_descriptor () const = 0;
177
178         Gtk::Widget& scrolled_window() { return _scrolled_window; }
179
180   protected:
181
182         bool _offer_inputs;
183
184   private:
185         PortGroupList _port_group_list;
186         ARDOUR::DataType _type;
187         std::vector<PortGroupUI*> _port_group_ui;
188         std::vector<Gtk::EventBox*> _row_labels;
189         Gtk::VBox* _row_labels_vbox;
190         RotatedLabelSet _column_labels;
191         Gtk::HBox _overall_hbox;
192         Gtk::VBox _side_vbox;
193         Gtk::HBox _port_group_hbox;
194         Gtk::ScrolledWindow _scrolled_window;
195         Gtk::Label* _side_vbox_pad;
196         Gtk::HBox _visibility_checkbutton_box;
197
198         void setup ();
199         void clear ();
200         void setup_dimensions ();
201         bool row_label_button_pressed (GdkEventButton*, int);
202         void reset_visibility ();
203 };
204
205 #endif