X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fgtkmm2ext%2Futils.cc;h=f3c5b6795f5991369d882e0e0814d8293d8ca6f8;hb=25a6aa57a377a1ca2843563cc401a69d1453bd7d;hp=4c85f1928de5d74d203ab1a1da69752f87882db8;hpb=6acdfc69b785841ac10a324484ddd0208612a213;p=ardour.git diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc index 4c85f1928d..f3c5b6795f 100644 --- a/libs/gtkmm2ext/utils.cc +++ b/libs/gtkmm2ext/utils.cc @@ -42,6 +42,7 @@ Gtkmm2ext::init (const char* localedir) { #ifdef ENABLE_NLS (void) bindtextdomain(PACKAGE, localedir); + (void) bind_textdomain_codeset (PACKAGE, "UTF-8"); #endif } @@ -75,6 +76,51 @@ Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget &w, const gchar * w.set_size_request(width + hpadding, height + vpadding); } +/** Set width request to display given text, and height to display anything. + This is useful for setting many widgets to the same height for consistency. */ +void +Gtkmm2ext::set_size_request_to_display_given_text_width (Gtk::Widget& w, + const gchar* htext, + gint hpadding, + gint vpadding) +{ + static const gchar* vtext = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + w.ensure_style (); + + int hwidth, hheight; + get_pixel_size (w.create_pango_layout (htext), hwidth, hheight); + + int vwidth, vheight; + get_pixel_size (w.create_pango_layout (vtext), vwidth, vheight); + + w.set_size_request(hwidth + hpadding, vheight + vpadding); +} + +void +Gtkmm2ext::set_height_request_to_display_any_text (Gtk::Widget& w, gint vpadding) +{ + static const gchar* vtext = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + w.ensure_style (); + + int width, height; + get_pixel_size (w.create_pango_layout (vtext), width, height); + + w.set_size_request(-1, height + vpadding); +} + +void +Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget &w, std::string const & text, + gint hpadding, gint vpadding) +{ + int width, height; + w.ensure_style (); + + get_pixel_size (w.create_pango_layout (text), width, height); + w.set_size_request(width + hpadding, height + vpadding); +} + void Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget &w, const std::vector& strings, @@ -113,6 +159,33 @@ Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget &w, w.set_size_request(width_max + hpadding, height_max + vpadding); } +/** This version specifies horizontal padding in text to avoid assumptions + about font size. Should be used anywhere padding is used to avoid text, + like combo boxes. */ +void +Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget& w, + const std::vector& strings, + const std::string& hpadding, + gint vpadding) +{ + int width_max = 0; + int height_max = 0; + w.ensure_style (); + + for (vector::const_iterator i = strings.begin(); i != strings.end(); ++i) { + int width, height; + get_pixel_size (w.create_pango_layout (*i), width, height); + width_max = max(width_max,width); + height_max = max(height_max, height); + } + + int pad_width; + int pad_height; + get_pixel_size (w.create_pango_layout (hpadding), pad_width, pad_height); + + w.set_size_request(width_max + pad_width, height_max + vpadding); +} + static inline guint8 demultiply_alpha (guint8 src, guint8 alpha)