Move "Feedback" option to control-portocol settings
[ardour.git] / libs / gtkmm2ext / pane.cc
index 9f374c67146457e698c4f3f8611be2844b7a3989..60a6dc543c195831d6e085831e3d01b51bf8f95f 100644 (file)
@@ -20,7 +20,7 @@
 #include <gdkmm/cursor.h>
 #include "gtkmm2ext/pane.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace PBD;
 using namespace Gtk;
@@ -31,6 +31,7 @@ Pane::Pane (bool h)
        : horizontal (h)
        , did_move (false)
        , divider_width (2)
+       , check_fract (false)
 {
        using namespace Gdk;
 
@@ -47,6 +48,9 @@ Pane::Pane (bool h)
 Pane::~Pane ()
 {
        for (Children::iterator c = children.begin(); c != children.end(); ++c) {
+               c->show_con.disconnect ();
+               c->hide_con.disconnect ();
+               c->w->remove_destroy_notify_callback (&(*c));
                c->w->unparent ();
        }
 }
@@ -139,23 +143,53 @@ Pane::handle_child_visibility ()
 void
 Pane::on_add (Widget* w)
 {
-       children.push_back (Child (w, 0));
+       children.push_back (Child (this, w, 0));
+       Child& kid = children.back ();
 
        w->set_parent (*this);
+       /* Gtkmm 2.4 does not correctly arrange for ::on_remove() to be called
+          for custom containers that derive from Gtk::Container. So ... we need
+          to ensure that we hear about child destruction ourselves.
+       */
+       w->add_destroy_notify_callback (&children.back(), &Pane::notify_child_destroyed);
 
-       w->signal_show().connect (sigc::mem_fun (*this, &Pane::handle_child_visibility));
-       w->signal_hide().connect (sigc::mem_fun (*this, &Pane::handle_child_visibility));
+       kid.show_con = w->signal_show().connect (sigc::mem_fun (*this, &Pane::handle_child_visibility));
+       kid.hide_con = w->signal_hide().connect (sigc::mem_fun (*this, &Pane::handle_child_visibility));
 
        while (dividers.size() < (children.size() - 1)) {
                add_divider ();
        }
 }
 
+void*
+Pane::notify_child_destroyed (void* data)
+{
+       Child* child = reinterpret_cast<Child*> (data);
+       return child->pane->child_destroyed (child->w);
+}
+
+void*
+Pane::child_destroyed (Gtk::Widget* w)
+{
+       for (Children::iterator c = children.begin(); c != children.end(); ++c) {
+               if (c->w == w) {
+                       c->show_con.disconnect ();
+                       c->hide_con.disconnect ();
+                       children.erase (c);
+                       break;
+               }
+       }
+       return 0;
+}
+
 void
 Pane::on_remove (Widget* w)
 {
        for (Children::iterator c = children.begin(); c != children.end(); ++c) {
                if (c->w == w) {
+                       c->show_con.disconnect ();
+                       c->hide_con.disconnect ();
+                       w->remove_destroy_notify_callback (&(*c));
                        w->unparent ();
                        children.erase (c);
                        break;
@@ -304,14 +338,17 @@ Pane::on_expose_event (GdkEventExpose* ev)
        Children::iterator child;
        Dividers::iterator div;
 
-       for (child = children.begin(), div = dividers.begin(); child != children.end(); ++child, ++div) {
+       for (child = children.begin(), div = dividers.begin(); child != children.end(); ++child) {
 
                if (child->w->is_visible()) {
                        propagate_expose (*(child->w), ev);
                }
 
-               if ((div != dividers.end()) && (*div)->is_visible()) {
-                       propagate_expose (**div, ev);
+               if (div != dividers.end()) {
+                       if ((*div)->is_visible()) {
+                               propagate_expose (**div, ev);
+                       }
+                       ++div;
                }
         }
 
@@ -332,13 +369,74 @@ Pane::handle_release_event (GdkEventButton* ev, Divider* d)
 {
        d->dragging = false;
 
-       if (did_move) {
+       if (did_move && !children.empty()) {
                children.front().w->queue_resize ();
                did_move = false;
        }
 
        return false;
 }
+void
+Pane::set_check_divider_position (bool yn)
+{
+       check_fract = yn;
+}
+
+bool
+Pane::fract_is_ok (Dividers::size_type div, float fract)
+{
+#ifdef __APPLE__
+       if (!check_fract) {
+               return true;
+       }
+
+
+       if (get_allocation().get_width() == 1 && get_allocation().get_height() == 1) {
+               /* space not * allocated - * divider being set from startup code. Let it pass,
+                  since our goal is mostly to catch drags to a position that will interfere with window
+                  resizing.
+               */
+               return true;
+       }
+
+       /* On Quartz, if the pane handle (divider) gets to
+          be adjacent to the window edge, you can no longer grab it:
+          any attempt to do so is interpreted by the Quartz window
+          manager ("Finder") as a resize drag on the window edge.
+       */
+
+       if (horizontal) {
+               if (div == dividers.size() - 1) {
+                       if (get_allocation().get_width() * (1.0 - fract) < (divider_width*2)) {
+                               /* too close to right edge */
+                               return false;
+                       }
+               }
+
+               if (div == 0) {
+                       if (get_allocation().get_width() * fract < (divider_width*2)) {
+                               /* too close to left edge */
+                               return false;
+                       }
+               }
+       } else {
+               if (div == dividers.size() - 1) {
+                       if (get_allocation().get_height() * (1.0 - fract) < (divider_width*2)) {
+                               /* too close to bottom */
+                               return false;
+                       }
+               }
+
+               if (div == 0) {
+                       if (get_allocation().get_width() * fract < (divider_width*2)) {
+                               /* too close to top */
+                               return false;
+                       }
+               }
+       }
+#endif
+       return true;
+}
 
 bool
 Pane::handle_motion_event (GdkEventMotion* ev, Divider* d)
@@ -357,8 +455,9 @@ Pane::handle_motion_event (GdkEventMotion* ev, Divider* d)
        d->translate_coordinates (*this, ev->x, ev->y, px, py);
 
        Dividers::iterator prev = dividers.end();
+       Dividers::size_type div = 0;
 
-       for (Dividers::iterator di = dividers.begin(); di != dividers.end(); ++di) {
+       for (Dividers::iterator di = dividers.begin(); di != dividers.end(); ++di, ++div) {
                if (*di == d) {
                        break;
                }
@@ -388,6 +487,10 @@ Pane::handle_motion_event (GdkEventMotion* ev, Divider* d)
 
        new_fract = min (1.0f, max (0.0f, new_fract));
 
+       if (!fract_is_ok (div, new_fract)) {
+               return true;
+       }
+
        if (new_fract != d->fract) {
                d->fract = new_fract;
                reallocate (get_allocation ());
@@ -415,6 +518,10 @@ Pane::set_divider (Dividers::size_type div, float fract)
 
        fract = max (0.0f, min (1.0f, fract));
 
+       if (!fract_is_ok (div, fract)) {
+               return;
+       }
+
        if (fract != (*d)->fract) {
                (*d)->fract = fract;
                /* our size hasn't changed, but our internal allocations have */