1 /*
2  * Copyright (C) 2009 Carl Hetherington <carl@carlh.net>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __gtk_ardour_port_matrix_body_h__
20 #define __gtk_ardour_port_matrix_body_h__
21 
22 #include <gtkmm/eventbox.h>
23 #include "port_group.h"
24 #include "port_matrix_types.h"
25 
26 class PortMatrix;
27 class PortMatrixColumnLabels;
28 class PortMatrixRowLabels;
29 class PortMatrixGrid;
30 class PortMatrixComponent;
31 
32 /** The main body of the port matrix.  It is made up of three parts:
33  *  column labels, grid and row labels, each drawn using cairo.
34  */
35 class PortMatrixBody : public Gtk::EventBox
36 {
37 public:
38 	PortMatrixBody (PortMatrix *);
39 	~PortMatrixBody ();
40 
41 	void setup ();
42 
43 	uint32_t full_scroll_width ();
44 	uint32_t alloc_scroll_width ();
45 	uint32_t full_scroll_height ();
46 	uint32_t alloc_scroll_height ();
47 
xoffset()48 	uint32_t xoffset () const {
49 		return _xoffset;
50 	}
51 	void set_xoffset (uint32_t);
yoffset()52 	uint32_t yoffset () const {
53 		return _yoffset;
54 	}
55 	void set_yoffset (uint32_t);
56 
57 	void rebuild_and_draw_grid ();
58 
59 	void set_mouseover (PortMatrixNode const &);
60 	void set_mouseover (std::list<PortMatrixNode> const &);
mouseover()61 	std::list<PortMatrixNode> mouseover () const {
62 		return _mouseover;
63 	}
64 
65 	void highlight_associated_channels (int, ARDOUR::BundleChannel);
66 	void component_size_changed ();
67 	std::pair<uint32_t, uint32_t> max_size () const;
68 
69 	uint32_t column_labels_border_x () const;
70 	uint32_t column_labels_height () const;
71 
72 	sigc::signal<void> DimensionsChanged;
73 
74 protected:
75 	bool on_expose_event (GdkEventExpose *);
76 	void on_size_request (Gtk::Requisition *);
77 	void on_size_allocate (Gtk::Allocation &);
78 	bool on_button_press_event (GdkEventButton *);
79 	bool on_button_release_event (GdkEventButton *);
80 	bool on_leave_notify_event (GdkEventCrossing *);
81 	bool on_motion_notify_event (GdkEventMotion *);
82 
83 private:
84 	void compute_rectangles ();
85 	void rebuild_and_draw_column_labels ();
86 	void rebuild_and_draw_row_labels ();
87 	void update_bundles ();
88 	void set_cairo_clip (cairo_t *, Gdk::Rectangle const &) const;
89 
90 	PortMatrix* _matrix;
91 	PortMatrixColumnLabels* _column_labels;
92 	PortMatrixRowLabels* _row_labels;
93 	PortMatrixGrid* _grid;
94 	std::list<PortMatrixComponent*> _components;
95 
96 	uint32_t _alloc_width; ///< allocated width
97 	uint32_t _alloc_height; ///< allocated height
98 	uint32_t _xoffset;
99 	uint32_t _yoffset;
100 	uint32_t _column_labels_border_x;
101 	uint32_t _column_labels_height;
102 
103 	std::list<PortMatrixNode> _mouseover;
104 	bool _ignore_component_size_changed;
105 
106 	PBD::ScopedConnectionList _bundle_connections;
107 };
108 
109 #endif
110