Some refactoring. Add port group headers to the port matrix.
[ardour.git] / gtk2_ardour / port_matrix_body.h
1 /*
2     Copyright (C) 2002-2009 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 __gtk_ardour_port_matrix_body_h__
21 #define __gtk_ardour_port_matrix_body_h__
22
23 #include "port_matrix_column_labels.h"
24 #include "port_matrix_row_labels.h"
25 #include "port_matrix_grid.h"
26 #include "port_group.h"
27
28 class PortMatrix;
29
30 /** The main body of the port matrix.  It is made up of three parts:
31  *  column labels, grid and row labels, each drawn using cairo.
32  *  This class handles the arrangement of these parts.
33  */
34 class PortMatrixBody : public Gtk::EventBox
35 {
36 public:
37         enum Arrangement {
38                 TOP_AND_RIGHT,
39                 BOTTOM_AND_LEFT
40         };
41
42         PortMatrixBody (PortMatrix *, Arrangement);
43
44         /** @return ports to offer for columns */
45         PortGroupList const & column_ports () {
46                 return _column_ports;
47         }
48
49         /** @return ports to offer for rows */
50         PortGroupList const & row_ports () {
51                 return _row_ports;
52         }
53         
54         void setup (PortGroupList const &, PortGroupList const &);
55
56         uint32_t full_scroll_width ();
57         uint32_t alloc_scroll_width ();
58         uint32_t full_scroll_height ();
59         uint32_t alloc_scroll_height ();
60
61         void set_xoffset (uint32_t);
62         void set_yoffset (uint32_t);
63
64         void rebuild_and_draw_grid ();
65
66 protected:
67         bool on_expose_event (GdkEventExpose *);
68         void on_size_request (Gtk::Requisition *);
69         void on_size_allocate (Gtk::Allocation &);
70         bool on_button_press_event (GdkEventButton *);
71
72 private:
73         void compute_rectangles ();
74         void rebuild_and_draw_column_labels ();
75         void rebuild_and_draw_row_labels ();
76         
77         PortMatrix* _port_matrix;
78         PortMatrixColumnLabels _column_labels;
79         PortMatrixRowLabels _row_labels;
80         PortMatrixGrid _grid;
81
82         Arrangement _arrangement;
83         uint32_t _alloc_width; ///< allocated width
84         uint32_t _alloc_height; ///< allocated height
85         Gdk::Rectangle _column_labels_rect;
86         Gdk::Rectangle _row_labels_rect;
87         Gdk::Rectangle _grid_rect;
88         uint32_t _xoffset;
89         uint32_t _yoffset;
90
91         /// bundles to offer for columns
92         PortGroupList _column_ports;
93         /// bundles to offer for rows
94         PortGroupList _row_ports;
95
96         std::list<sigc::connection> _bundle_connections;
97 };
98
99 #endif