return txt;
}
+/** Try to fit a string into a given horizontal space by ellipsizing it.
+ * @param cr Cairo context in which the text will be plotted.
+ * @param name Text.
+ * @param avail Available horizontal space.
+ * @return (Text, possibly ellipsized) and (horizontal size of text)
+ */
+
+std::pair<std::string, double>
+fit_to_pixels (cairo_t* cr, std::string name, double avail)
+{
+ /* XXX hopefully there exists a more efficient way of doing this */
+
+ bool abbreviated = false;
+ uint32_t width = 0;
+
+ while (1) {
+ cairo_text_extents_t ext;
+ cairo_text_extents (cr, name.c_str(), &ext);
+
+ if (ext.width < avail || name.length() <= 4) {
+ width = ext.width;
+ break;
+ }
+
+ if (abbreviated) {
+ name = name.substr (0, name.length() - 4) + "...";
+ } else {
+ name = name.substr (0, name.length() - 3) + "...";
+ abbreviated = true;
+ }
+ }
+
+ return std::make_pair (name, width);
+}
+
+
+/** Add an element to a menu, settings its sensitivity.
+ * @param m Menu to add to.
+ * @param e Element to add.
+ * @param s true to make sensitive, false to make insensitive
+ */
+void
+add_item_with_sensitivity (Menu_Helpers::MenuList& m, Menu_Helpers::MenuElem e, bool s)
+{
+ m.push_back (e);
+ if (!s) {
+ m.back().set_sensitive (false);
+ }
+}
+
+
gint
-just_hide_it (GdkEventAny *ev, Gtk::Window *win)
+just_hide_it (GdkEventAny */*ev*/, Gtk::Window *win)
{
win->hide ();
- return TRUE;
+ return 0;
}
/* xpm2rgb copied from nixieclock, which bore the legend:
}
ArdourCanvas::Points*
-get_canvas_points (string who, uint32_t npoints)
+get_canvas_points (string /*who*/, uint32_t npoints)
{
// cerr << who << ": wants " << npoints << " canvas points" << endl;
#ifdef TRAP_EXCESSIVE_POINT_REQUESTS
return xpm_map[name];
}
-
-Glib::RefPtr<Gdk::Pixbuf>
-get_icon (const char* cname)
+Glib::ustring
+get_icon_path (const char* cname)
{
string name = cname;
name += X_(".png");
fatal << string_compose (_("cannot find icon image for %1"), name) << endmsg;
}
+ return data_file_path.to_string();
+}
+
+Glib::RefPtr<Gdk::Pixbuf>
+get_icon (const char* cname)
+{
Glib::RefPtr<Gdk::Pixbuf> img;
try {
- img = Gdk::Pixbuf::create_from_file (data_file_path.to_string());
+ img = Gdk::Pixbuf::create_from_file (get_icon_path (cname));
} catch (const Gdk::PixbufError &e) {
cerr << "Caught PixbufError: " << e.what() << endl;
} catch (...) {