redesign toggling of editor/mixer stacking to use Gtkmm2ext::VisibilityTracker
[ardour.git] / libs / gtkmm2ext / utils.cc
index 63d7655331f3ec1c9f55c3f662b40d7653a1f911..4bc9113875c04dca7b13823b2d1af29146694586 100644 (file)
 #include <gtkmm/paned.h>
 #include <gtkmm/label.h>
 #include <gtkmm/comboboxtext.h>
+#include <gtkmm/tooltip.h>
 
 #include "i18n.h"
 
 using namespace std;
 
 void
-Gtkmm2ext::init ()
+Gtkmm2ext::init (const char* localedir)
 {
-       // Necessary for gettext
-       (void) bindtextdomain(PACKAGE, LOCALEDIR);
+#ifdef ENABLE_NLS
+       (void) bindtextdomain(PACKAGE, localedir);
+#endif
 }
 
 void
@@ -412,80 +414,76 @@ Gtkmm2ext::rounded_bottom_half_rectangle (Cairo::RefPtr<Cairo::Context> context,
 {
        rounded_bottom_half_rectangle (context->cobj(), x, y, w, h, r);
 }
+void
+Gtkmm2ext::rounded_right_half_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r)
+{
+       rounded_right_half_rectangle (context->cobj(), x, y, w, h, r);
+}
 
 void
 Gtkmm2ext::rounded_rectangle (cairo_t* cr, double x, double y, double w, double h, double r)
 {
-/*    A****BQ
-      H    C
-      *    *
-      G    D
-      F****E
-*/
-       cairo_move_to (cr, x+r,y); // Move to A
-       cairo_line_to (cr, x+w-r,y); // Straight line to B
-       cairo_curve_to (cr, x+w,y,x+w,y,x+w,y+r); // Curve to C, Control points are both at Q
-       cairo_line_to (cr, x+w,y+h-r); // Move to D
-       cairo_curve_to (cr, x+w,y+h,x+w,y+h,x+w-r,y+h); // Curve to E
-       cairo_line_to (cr, x+r,y+h); // Line to F
-       cairo_curve_to (cr, x,y+h,x,y+h,x,y+h-r); // Curve to G
-       cairo_line_to (cr, x,y+r); // Line to H
-       cairo_curve_to (cr, x,y,x,y,x+r,y); // Curve to A
+       double degrees = M_PI / 180.0;
+
+       cairo_new_sub_path (cr);
+       cairo_arc (cr, x + w - r, y + r, r, -90 * degrees, 0 * degrees);  //tr
+       cairo_arc (cr, x + w - r, y + h - r, r, 0 * degrees, 90 * degrees);  //br
+       cairo_arc (cr, x + r, y + h - r, r, 90 * degrees, 180 * degrees);  //bl
+       cairo_arc (cr, x + r, y + r, r, 180 * degrees, 270 * degrees);  //tl
+       cairo_close_path (cr);
+}
+
+void
+Gtkmm2ext::rounded_right_half_rectangle (cairo_t* cr, double x, double y, double w, double h, double r)
+{
+       double degrees = M_PI / 180.0;
+
+       cairo_new_sub_path (cr);
+       cairo_arc (cr, x + w - r, y + r, r, -90 * degrees, 0 * degrees);  //tr
+       cairo_arc (cr, x + w - r, y + h - r, r, 0 * degrees, 90 * degrees);  //br
+       cairo_line_to (cr, x, y + h); // bl
+       cairo_line_to (cr, x, y); // tl
+       cairo_close_path (cr);
 }
 
 void
 Gtkmm2ext::rounded_top_half_rectangle (cairo_t* cr, double x, double y, double w, double h, double r)
 {
-/*    A****BQ
-      H    C
-      *    *
-      G    D
-      F****E
-*/
-       cairo_move_to (cr, x+r,y); // Move to A
-       cairo_line_to (cr, x+w-r,y); // Straight line to B
-       cairo_curve_to (cr, x+w,y,x+w,y,x+w,y+r); // Curve to C, Control points are both at Q
-       cairo_line_to (cr, x+w,y+h); // Move to E
-       cairo_line_to (cr, x,y+h); // Line to F
-       cairo_line_to (cr, x,y+r); // Line to H
-       cairo_curve_to (cr, x,y,x,y,x+r,y); // Curve to A
+       double degrees = M_PI / 180.0;
+
+       cairo_new_sub_path (cr);
+       cairo_move_to (cr, x+w, y+h);
+       cairo_line_to (cr, x, y+h);
+       cairo_arc (cr, x + r, y + r, r, 180 * degrees, 270 * degrees);  //tl
+       cairo_arc (cr, x + w - r, y + r, r, -90 * degrees, 0 * degrees);  //tr
+       cairo_close_path (cr);
 }
 
 void
 Gtkmm2ext::rounded_bottom_half_rectangle (cairo_t* cr, double x, double y, double w, double h, double r)
 {
-/*    A****BQ
-      H    C
-      *    *
-      G    D
-      F****E
-*/
-       cairo_move_to (cr, x,y); // Move to A
-       cairo_line_to (cr, x+w,y); // Straight line to B
-       cairo_line_to (cr, x+w,y+h-r); // Move to D
-       cairo_curve_to (cr, x+w,y+h,x+w,y+h,x+w-r,y+h); // Curve to E
-       cairo_line_to (cr, x+r,y+h); // Line to F
-       cairo_curve_to (cr, x,y+h,x,y+h,x,y+h-r); // Curve to G
-       cairo_line_to (cr, x,y); // Line to A
+       double degrees = M_PI / 180.0;
+
+       cairo_new_sub_path (cr);
+       cairo_move_to (cr, x, y);
+       cairo_line_to (cr, x+w, y);
+       cairo_arc (cr, x + w - r, y + h - r, r, 0 * degrees, 90 * degrees);  //br
+       cairo_arc (cr, x + r, y + h - r, r, 90 * degrees, 180 * degrees);  //bl
+       cairo_close_path (cr);
 }
 
 
 void
 Gtkmm2ext::rounded_top_rectangle (cairo_t* cr, double x, double y, double w, double h, double r)
 {
-/*    A****BQ
-      H    C
-      *    *
-      *    *
-      F****E
-*/
-       cairo_move_to (cr, x+r,y); // Move to A
-       cairo_line_to (cr, x+w-r,y); // Straight line to B
-       cairo_curve_to (cr, x+w,y,x+w,y,x+w,y+r); // Curve to C, Control points are both at Q
-       cairo_line_to (cr, x+w,y+h); // Move to E
-       cairo_line_to (cr, x,y+h); // Line to F
-       cairo_line_to (cr, x,y+r); // Line to H
-       cairo_curve_to (cr, x,y,x,y,x+r,y); // Curve to A
+       double degrees = M_PI / 180.0;
+
+       cairo_new_sub_path (cr);
+       cairo_move_to (cr, x+w, y+h);
+       cairo_line_to (cr, x, y+h);
+       cairo_arc (cr, x + r, y + r, r, 180 * degrees, 270 * degrees);  //tl
+       cairo_arc (cr, x + w - r, y + r, r, -90 * degrees, 0 * degrees);  //tr
+       cairo_close_path (cr);
 }
 
 void
@@ -631,3 +629,33 @@ Gtkmm2ext::left_aligned_label (string const & t)
        l->set_alignment (0, 0.5);
        return l;
 }
+
+static bool
+make_null_tooltip (int, int, bool, const Glib::RefPtr<Gtk::Tooltip>& t)
+{
+       t->set_tip_area (Gdk::Rectangle (0, 0, 0, 0));
+       return true;
+}
+
+/** Hackily arrange for the provided widget to have no tooltip,
+ *  and also to stop any other widget from providing one while
+ * the mouse is over w.
+ */
+void
+Gtkmm2ext::set_no_tooltip_whatsoever (Gtk::Widget& w)
+{
+       w.property_has_tooltip() = true;
+       w.signal_query_tooltip().connect (sigc::ptr_fun (make_null_tooltip));
+}
+
+void
+Gtkmm2ext::enable_tooltips ()
+{
+       gtk_rc_parse_string ("gtk-enable-tooltips = 1");
+}
+
+void
+Gtkmm2ext::disable_tooltips ()
+{
+       gtk_rc_parse_string ("gtk-enable-tooltips = 0");
+}