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 "ardour/bundle.h"
22 #include "port_matrix_body.h"
23 #include "port_matrix.h"
25 PortMatrixBody::PortMatrixBody (PortMatrix* p)
27 _column_labels (this),
28 _row_labels (p, this),
42 PortMatrixBody::on_expose_event (GdkEventExpose* event)
44 Gdk::Rectangle const exposure (
45 event->area.x, event->area.y, event->area.width, event->area.height
48 Gdk::Rectangle const col (0, 0, _alloc_width, _alloc_ydiv);
49 Gdk::Rectangle const row (_alloc_xdiv, _alloc_ydiv, _alloc_width - _alloc_xdiv, _alloc_height - _alloc_ydiv);
50 Gdk::Rectangle const grid (0, _alloc_ydiv, _alloc_xdiv, _alloc_height - _alloc_ydiv);
53 Gdk::Rectangle r = exposure;
54 r.intersect (col, intersects);
59 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
60 _column_labels.get_pixmap (get_window()->gobj()),
71 r.intersect (row, intersects);
76 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
77 _row_labels.get_pixmap (get_window()->gobj()),
78 r.get_x() - _alloc_xdiv,
79 r.get_y() + _yoffset - _alloc_ydiv,
88 r.intersect (grid, intersects);
93 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
94 _grid.get_pixmap (get_window()->gobj()),
96 r.get_y() + _yoffset - _alloc_ydiv,
108 PortMatrixBody::on_size_request (Gtk::Requisition *req)
110 std::pair<int, int> const col = _column_labels.dimensions ();
111 std::pair<int, int> const row = _row_labels.dimensions ();
112 std::pair<int, int> const grid = _grid.dimensions ();
114 req->width = std::max (col.first, grid.first + row.first);
115 req->height = col.second + grid.second;
119 PortMatrixBody::on_size_allocate (Gtk::Allocation& alloc)
121 Gtk::EventBox::on_size_allocate (alloc);
122 set_allocation (alloc);
124 _alloc_width = alloc.get_width ();
125 _alloc_height = alloc.get_height ();
128 _port_matrix->setup_scrollbars ();
132 PortMatrixBody::compute_divs ()
134 std::pair<uint32_t, uint32_t> const col = _column_labels.dimensions ();
135 if (_alloc_height > col.second) {
136 /* allocated height is enough for the column labels */
137 _alloc_ydiv = col.second;
139 /* not enough space for the column labels */
140 _alloc_ydiv = _alloc_height;
143 std::pair<uint32_t, uint32_t> const grid = _grid.dimensions ();
144 std::pair<uint32_t, uint32_t> const row = _row_labels.dimensions ();
146 if (_alloc_width > (grid.first + row.first)) {
147 /* allocated width is larger than we need, so
148 put the x division at the extent of the grid */
149 _alloc_xdiv = grid.first;
150 } else if (_alloc_width > row.first) {
151 /* allocated width is large enough for the row labels
152 but not for the whole grid, so display the whole
153 row label section and cut part of the grid off */
154 _alloc_xdiv = _alloc_width - row.first;
156 /* allocated width isn't even enough for the row labels */
162 PortMatrixBody::setup (
163 std::vector<boost::shared_ptr<ARDOUR::Bundle> > const & row,
164 std::vector<boost::shared_ptr<ARDOUR::Bundle> > const & column
167 for (std::list<sigc::connection>::iterator i = _bundle_connections.begin(); i != _bundle_connections.end(); ++i) {
171 _bundle_connections.clear ();
174 _column_bundles = column;
176 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::iterator i = _row_bundles.begin(); i != _row_bundles.end(); ++i) {
178 _bundle_connections.push_back (
179 (*i)->NameChanged.connect (sigc::mem_fun (*this, &PortMatrixBody::repaint_row_labels))
184 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::iterator i = _column_bundles.begin(); i != _column_bundles.end(); ++i) {
185 _bundle_connections.push_back (
186 (*i)->NameChanged.connect (sigc::mem_fun (*this, &PortMatrixBody::repaint_column_labels))
190 _column_labels.setup ();
191 _row_labels.setup ();
198 PortMatrixBody::full_scroll_width ()
200 return _grid.dimensions().first;
205 PortMatrixBody::alloc_scroll_width ()
211 PortMatrixBody::full_scroll_height ()
213 return _grid.dimensions().second;
217 PortMatrixBody::alloc_scroll_height ()
219 return _alloc_height - _alloc_ydiv;
223 PortMatrixBody::set_xoffset (uint32_t xo)
230 PortMatrixBody::set_yoffset (uint32_t yo)
237 PortMatrixBody::on_button_press_event (GdkEventButton* ev)
239 if (ev->x < _alloc_xdiv && ev->y > _alloc_ydiv) {
240 _grid.button_press (ev->x + _xoffset, ev->y + _yoffset - _alloc_ydiv, ev->button);
241 } else if (ev->x > _alloc_xdiv && ev->y > _alloc_ydiv) {
242 _row_labels.button_press (ev->x - _alloc_xdiv, ev->y + _yoffset - _alloc_ydiv, ev->button, ev->time);
251 PortMatrixBody::repaint_grid ()
253 _grid.require_render ();
258 PortMatrixBody::repaint_column_labels ()
260 _column_labels.require_render ();
265 PortMatrixBody::repaint_row_labels ()
267 _row_labels.require_render ();