+void
+ArdourButton::set_layout_ellipsize_width (int w)
+{
+ if (_layout_ellipsize_width == w) {
+ return;
+ }
+ _layout_ellipsize_width = w;
+ if (!_layout) {
+ return;
+ }
+ if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
+ _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE);
+ }
+ if (is_realized ()) {
+ queue_resize ();
+ }
+}
+
+void
+ArdourButton::set_text_ellipsize (Pango::EllipsizeMode e)
+{
+ if (_ellipsis == e) {
+ return;
+ }
+ _ellipsis = e;
+ if (!_layout) {
+ return;
+ }
+ _layout->set_ellipsize(_ellipsis);
+ if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
+ _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE);
+ }
+ if (is_realized ()) {
+ queue_resize ();
+ }
+}
+
+void
+ArdourButton::ensure_layout ()
+{
+ if (!_layout) {
+ ensure_style ();
+ _layout = Pango::Layout::create (get_pango_context());
+ _layout->set_ellipsize(_ellipsis);
+ if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
+ _layout->set_width (_layout_ellipsize_width - 3* PANGO_SCALE);
+ }
+ }
+}
+
+void
+ArdourButton::recalc_char_pixel_geometry ()
+{
+ if (_char_pixel_height > 0 && _char_pixel_width > 0) {
+ return;
+ }
+ ensure_layout();
+ // NB. this is not static, since the geometry is different
+ // depending on the font used.
+ int w, h;
+ std::string x = _("ABCDEFGHIJLKMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
+ _layout->set_text (x);
+ _layout->get_pixel_size (w, h);
+ _char_pixel_height = std::max(4, h);
+ // number of actual chars in the string (not bytes)
+ // Glib to the rescue.
+ Glib::ustring gx(x);
+ _char_avg_pixel_width = w / (float)gx.size();
+ _char_pixel_width = std::max(4, (int) ceil (_char_avg_pixel_width));
+ _layout->set_text (_text);
+}