Fix some unused parameter warnings.
[ardour.git] / gtk2_ardour / port_matrix_body.cc
index 3f8fcdc0c6a8bf869465afd8978b92feb0a3e138..f61593d540b671e1bcd165e02936947b8bb7d769 100644 (file)
@@ -26,6 +26,8 @@
 #include "port_matrix_row_labels.h"
 #include "port_matrix_grid.h"
 
+using namespace std;
+
 PortMatrixBody::PortMatrixBody (PortMatrix* p)
        : _matrix (p),
          _xoffset (0),
@@ -36,7 +38,6 @@ PortMatrixBody::PortMatrixBody (PortMatrix* p)
        _row_labels = new PortMatrixRowLabels (p, this);
        _grid = new PortMatrixGrid (p, this);
        
-       modify_bg (Gtk::STATE_NORMAL, Gdk::Color ("#00000"));
        add_events (Gdk::LEAVE_NOTIFY_MASK | Gdk::POINTER_MOTION_MASK);
 }
 
@@ -139,15 +140,19 @@ PortMatrixBody::on_expose_event (GdkEventExpose* event)
 void
 PortMatrixBody::on_size_request (Gtk::Requisition *req)
 {
-       std::pair<int, int> const col = _column_labels->dimensions ();
-       std::pair<int, int> const row = _row_labels->dimensions ();
-       std::pair<int, int> const grid = _grid->dimensions ();
+       pair<int, int> const col = _column_labels->dimensions ();
+       pair<int, int> const row = _row_labels->dimensions ();
+       pair<int, int> const grid = _grid->dimensions ();
 
        /* don't ask for the maximum size of our contents, otherwise GTK won't
           let the containing window shrink below this size */
 
-       req->width = std::min (512, std::max (col.first, grid.first + row.first));
-       req->height = std::min (512, col.second + grid.second);
+       /* XXX these shouldn't be hard-coded */
+       int const min_width = 512;
+       int const min_height = 512;
+
+       req->width = min (min_width, max (col.first, grid.first + row.first));
+       req->height = min (min_height / _matrix->min_height_divisor(), col.second + grid.second);
 }
 
 void
@@ -166,9 +171,10 @@ void
 PortMatrixBody::compute_rectangles ()
 {
        /* full sizes of components */
-       std::pair<uint32_t, uint32_t> const col = _column_labels->dimensions ();
-       std::pair<uint32_t, uint32_t> const row = _row_labels->dimensions ();
-       std::pair<uint32_t, uint32_t> const grid = _grid->dimensions ();
+       pair<uint32_t, uint32_t> const col = _column_labels->dimensions ();
+       uint32_t col_overhang = _column_labels->overhang ();
+       pair<uint32_t, uint32_t> const row = _row_labels->dimensions ();
+       pair<uint32_t, uint32_t> const grid = _grid->dimensions ();
 
        Gdk::Rectangle col_rect;
        Gdk::Rectangle row_rect;
@@ -176,35 +182,19 @@ PortMatrixBody::compute_rectangles ()
 
        if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
 
-               /* build from top left */
-
                col_rect.set_x (0);
                col_rect.set_y (0);
                grid_rect.set_x (0);
 
-               if (_alloc_width > col.first) {
-                       col_rect.set_width (col.first);
-               } else {
-                       col_rect.set_width (_alloc_width);
-               }
-
-               /* move down to y division */
-               
-               uint32_t y = 0;
-               if (_alloc_height > col.second) {
-                       y = col.second;
-               } else {
-                       y = _alloc_height;
-               }
+               col_rect.set_width (min (col.first, _alloc_width));
 
+               uint32_t const y = min (_alloc_height, col.second);
                col_rect.set_height (y);
                row_rect.set_y (y);
                row_rect.set_height (_alloc_height - y);
                grid_rect.set_y (y);
                grid_rect.set_height (_alloc_height - y);
 
-               /* move right to x division */
-
                uint32_t x = 0;
                if (_alloc_width > (grid.first + row.first)) {
                        x = grid.first;
@@ -219,42 +209,22 @@ PortMatrixBody::compute_rectangles ()
 
        } else if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
 
-               /* build from bottom right */
-
-               /* move left to x division */
-
-               uint32_t x = 0;
-               if (_alloc_width > (grid.first + row.first)) {
-                       x = grid.first;
-               } else if (_alloc_width > row.first) {
-                       x = _alloc_width - row.first;
-               }
+               col_rect.set_height (min (_alloc_height, col.second));
 
-               grid_rect.set_x (_alloc_width - x);
-               grid_rect.set_width (x);
-               col_rect.set_width (col.first - grid.first + x);
-               col_rect.set_x (_alloc_width - col_rect.get_width());
+               row_rect.set_x (0);
+               row_rect.set_y (0);
+               row_rect.set_width (min (_alloc_width, row.first));
+               row_rect.set_height (std::min (_alloc_height - col_rect.get_height(), row.second));
 
-               row_rect.set_width (std::min (_alloc_width - x, row.first));
-               row_rect.set_x (_alloc_width - x - row_rect.get_width());
+               grid_rect.set_x (row_rect.get_width());
+               grid_rect.set_y (0);
+               grid_rect.set_width (std::min (_alloc_width - row_rect.get_width(), grid.first));
+               grid_rect.set_height (row_rect.get_height ());
 
-               /* move up to the y division */
+               col_rect.set_width (grid_rect.get_width () + col_overhang);
+               col_rect.set_x (row_rect.get_width() + grid_rect.get_width() - col_rect.get_width());
+               col_rect.set_y (row_rect.get_height());
                
-               uint32_t y = 0;
-               if (_alloc_height > col.second) {
-                       y = col.second;
-               } else {
-                       y = _alloc_height;
-               }
-
-               col_rect.set_y (_alloc_height - y);
-               col_rect.set_height (y);
-
-               grid_rect.set_height (std::min (grid.second, _alloc_height - y));
-               grid_rect.set_y (_alloc_height - y - grid_rect.get_height());
-
-               row_rect.set_height (grid_rect.get_height());
-               row_rect.set_y (grid_rect.get_y());
        }
 
        _row_labels->set_parent_rectangle (row_rect);
@@ -267,26 +237,26 @@ PortMatrixBody::setup ()
 {
        /* Discard any old connections to bundles */
        
-       for (std::list<sigc::connection>::iterator i = _bundle_connections.begin(); i != _bundle_connections.end(); ++i) {
+       for (list<sigc::connection>::iterator i = _bundle_connections.begin(); i != _bundle_connections.end(); ++i) {
                i->disconnect ();
        }
        _bundle_connections.clear ();
 
        /* Connect to bundles so that we find out when their names change */
        
-       ARDOUR::BundleList r = _matrix->rows()->bundles ();
-       for (ARDOUR::BundleList::iterator i = r.begin(); i != r.end(); ++i) {
+       PortGroup::BundleList r = _matrix->rows()->bundles ();
+       for (PortGroup::BundleList::iterator i = r.begin(); i != r.end(); ++i) {
                
                _bundle_connections.push_back (
-                       (*i)->Changed.connect (sigc::hide (sigc::mem_fun (*this, &PortMatrixBody::rebuild_and_draw_row_labels)))
+                       i->bundle->Changed.connect (sigc::hide (sigc::mem_fun (*this, &PortMatrixBody::rebuild_and_draw_row_labels)))
                        );
                
        }
 
-       ARDOUR::BundleList c = _matrix->columns()->bundles ();
-       for (ARDOUR::BundleList::iterator i = c.begin(); i != c.end(); ++i) {
+       PortGroup::BundleList c = _matrix->columns()->bundles ();
+       for (PortGroup::BundleList::iterator i = c.begin(); i != c.end(); ++i) {
                _bundle_connections.push_back (
-                       (*i)->Changed.connect (sigc::hide (sigc::mem_fun (*this, &PortMatrixBody::rebuild_and_draw_column_labels)))
+                       i->bundle->Changed.connect (sigc::hide (sigc::mem_fun (*this, &PortMatrixBody::rebuild_and_draw_column_labels)))
                        );
        }
        
@@ -345,7 +315,7 @@ PortMatrixBody::on_button_press_event (GdkEventButton* ev)
                _grid->button_press (
                        _grid->parent_to_component_x (ev->x),
                        _grid->parent_to_component_y (ev->y),
-                       ev->button
+                       ev->button, ev->time
                        );
 
        } else if (Gdk::Region (_row_labels->parent_rectangle()).point_in (ev->x, ev->y)) {
@@ -377,6 +347,14 @@ PortMatrixBody::on_button_release_event (GdkEventButton* ev)
                _row_labels->clear_channel_highlights ();
                _column_labels->clear_channel_highlights ();
                
+       } else if (Gdk::Region (_grid->parent_rectangle()).point_in (ev->x, ev->y)) {
+
+               _grid->button_release (
+                       _grid->parent_to_component_x (ev->x),
+                       _grid->parent_to_component_y (ev->y),
+                       ev->button, ev->time
+                       );
+
        }
 
        return true;
@@ -417,11 +395,14 @@ bool
 PortMatrixBody::on_motion_notify_event (GdkEventMotion* ev)
 {
        if (Gdk::Region (_grid->parent_rectangle()).point_in (ev->x, ev->y)) {
-               _grid->mouseover_event (
+               
+               _grid->motion (
                        _grid->parent_to_component_x (ev->x),
                        _grid->parent_to_component_y (ev->y)
                        );
+               
                _mouse_over_grid = true;
+               
        } else {
                if (_mouse_over_grid) {
                        set_mouseover (PortMatrixNode ());
@@ -447,22 +428,11 @@ PortMatrixBody::set_mouseover (PortMatrixNode const & n)
        _column_labels->mouseover_changed (old);
 }
 
-
-
 void
-PortMatrixBody::highlight_associated_channels (int dim, uint32_t N)
+PortMatrixBody::highlight_associated_channels (int dim, ARDOUR::BundleChannel h)
 {
        ARDOUR::BundleChannel bc[2];
-       
-       ARDOUR::BundleList const a = _matrix->ports(dim)->bundles ();
-       for (ARDOUR::BundleList::const_iterator i = a.begin(); i != a.end(); ++i) {
-               if (N < (*i)->nchannels ()) {
-                       bc[dim] = ARDOUR::BundleChannel (*i, N);
-                       break;
-               } else {
-                       N -= (*i)->nchannels ();
-               }
-       }
+       bc[dim] = h;
 
        if (!bc[dim].bundle) {
                return;
@@ -474,12 +444,12 @@ PortMatrixBody::highlight_associated_channels (int dim, uint32_t N)
                _row_labels->add_channel_highlight (bc[dim]);
        }
 
-       ARDOUR::BundleList const b = _matrix->ports(1 - dim)->bundles ();
+       PortGroup::BundleList const b = _matrix->ports(1 - dim)->bundles ();
 
-       for (ARDOUR::BundleList::const_iterator i = b.begin(); i != b.end(); ++i) {
-               for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
-                       bc[1 - dim] = ARDOUR::BundleChannel (*i, j);
-                       if (_matrix->get_state (bc) == PortMatrix::ASSOCIATED) {
+       for (PortGroup::BundleList::const_iterator i = b.begin(); i != b.end(); ++i) {
+               for (uint32_t j = 0; j < i->bundle->nchannels(); ++j) {
+                       bc[1 - dim] = ARDOUR::BundleChannel (i->bundle, j);
+                       if (_matrix->get_state (bc) == PortMatrixNode::ASSOCIATED) {
                                if (dim == _matrix->column_index()) {
                                        _row_labels->add_channel_highlight (bc[1 - dim]);
                                } else {
@@ -501,6 +471,16 @@ void
 PortMatrixBody::component_size_changed ()
 {
        compute_rectangles ();
+       _matrix->setup_max_size ();
        _matrix->setup_scrollbars ();
 }
 
+pair<uint32_t, uint32_t>
+PortMatrixBody::max_size () const
+{
+       pair<uint32_t, uint32_t> const col = _column_labels->dimensions ();
+       pair<uint32_t, uint32_t> const row = _row_labels->dimensions ();
+       pair<uint32_t, uint32_t> const grid = _grid->dimensions ();
+       
+       return make_pair (std::max (row.first, _column_labels->overhang()) + grid.first, col.second + grid.second);
+}