fix case where pane divider is not redrawn after a leave event.
[ardour.git] / libs / gtkmm2ext / utils.cc
index 7fed1b8aeebf7ce29a4e2954321ea0a6ee932be8..3210e0e63d5503e9a4625cd3e6c9abc42c9fe31e 100644 (file)
@@ -33,6 +33,7 @@
 #include <gtkmm/tooltip.h>
 
 #include "gtkmm2ext/utils.h"
+#include "gtkmm2ext/persistent_tooltip.h"
 
 #include "i18n.h"
 
@@ -272,6 +273,18 @@ Gtkmm2ext::pixbuf_from_string(const string& name, const Pango::FontDescription&
                return *empty_pixbuf;
        }
 
+       if (clip_width <= 0 || clip_height <= 0) {
+               /* negative values mean padding around natural size */
+               int width, height;
+               pixel_size (name, font, width, height);
+               if (clip_width <= 0) {
+                       clip_width = width - clip_width;
+               }
+               if (clip_height <= 0) {
+                       clip_height = height - clip_height;
+               }
+       }
+
        Glib::RefPtr<Gdk::Pixbuf> buf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, clip_width, clip_height);
 
        cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, clip_width, clip_height);
@@ -678,7 +691,7 @@ Gtkmm2ext::window_to_draw_on (Gtk::Widget& w, Gtk::Widget** parent)
 }
 
 int
-Gtkmm2ext::pixel_width (const string& str, Pango::FontDescription& font)
+Gtkmm2ext::pixel_width (const string& str, const Pango::FontDescription& font)
 {
        Glib::RefPtr<Pango::Context> context = Glib::wrap (gdk_pango_context_get());
        Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
@@ -706,7 +719,7 @@ Gtkmm2ext::pixel_width (const string& str, Pango::FontDescription& font)
 }
 
 void
-Gtkmm2ext::pixel_size (const string& str, Pango::FontDescription& font, int& width, int& height)
+Gtkmm2ext::pixel_size (const string& str, const Pango::FontDescription& font, int& width, int& height)
 {
        Gtk::Label foo;
        Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout ("");
@@ -732,9 +745,9 @@ Gtkmm2ext::fit_to_pixels (const string& str, int pixel_width, Pango::FontDescrip
        layout->set_width (pixel_width * PANGO_SCALE);
 
        if (with_ellipses) {
-               layout->set_ellipsize (Pango::ELLIPSIZE_END);
+               layout->set_ellipsize (Pango::ELLIPSIZE_END);
        } else {
-               layout->set_wrap (Pango::WRAP_CHAR);
+               layout->set_wrap (Pango::WRAP_CHAR);
        }
 
        line = layout->get_line (0);
@@ -824,12 +837,14 @@ void
 Gtkmm2ext::enable_tooltips ()
 {
        gtk_rc_parse_string ("gtk-enable-tooltips = 1");
+       PersistentTooltip::set_tooltips_enabled (true);
 }
 
 void
 Gtkmm2ext::disable_tooltips ()
 {
        gtk_rc_parse_string ("gtk-enable-tooltips = 0");
+       PersistentTooltip::set_tooltips_enabled (false);
 }
 
 bool
@@ -977,3 +992,23 @@ Gtkmm2ext::add_volume_shortcuts (Gtk::FileChooser& c)
        }
 #endif
 }
+
+float
+Gtkmm2ext::paned_position_as_fraction (Gtk::Paned& paned, bool h)
+{
+       const guint pos = gtk_paned_get_position (const_cast<GtkPaned*>(static_cast<const Gtk::Paned*>(&paned)->gobj()));
+       return (double) pos / (h ? paned.get_allocation().get_height() : paned.get_allocation().get_width());
+}
+
+void
+Gtkmm2ext::paned_set_position_as_fraction (Gtk::Paned& paned, float fraction, bool h)
+{
+       gint v = (h ? paned.get_allocation().get_height() : paned.get_allocation().get_width());
+
+       if (v < 1) {
+               return;
+       }
+
+       paned.set_position ((guint) floor (fraction * v));
+}
+