X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fgtkmm2ext%2Futils.cc;h=b1be7c9c921f1878fbc7a038d34d73fa218e18af;hb=cf52d6e4b40111eb04b244ec054055a4ec15dbe0;hp=4cfc0b26a02a5537c59cf76a62418878280417ed;hpb=22b07e0233a29d9633ffa825a79503befaf2e16e;p=ardour.git diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc index 4cfc0b26a0..b1be7c9c92 100644 --- a/libs/gtkmm2ext/utils.cc +++ b/libs/gtkmm2ext/utils.cc @@ -33,8 +33,9 @@ #include #include "gtkmm2ext/utils.h" +#include "gtkmm2ext/persistent_tooltip.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; @@ -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 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); @@ -381,30 +394,6 @@ Gtkmm2ext::detach_menu (Gtk::Menu& menu) } } -bool -Gtkmm2ext::possibly_translate_mod_to_make_legal_accelerator (GdkModifierType& mod) -{ -#ifdef GTKOSX - /* GTK on OS X is currently (February 2012) setting both - the Meta and Mod2 bits in the event modifier state if - the Command key is down. - - gtk_accel_groups_activate() does not invoke any of the logic - that gtk_window_activate_key() will that sorts out that stupid - state of affairs, and as a result it fails to find a match - for the key event and the current set of accelerators. - - to fix this, if the meta bit is set, remove the mod2 bit - from the modifier. this assumes that our bindings use Primary - which will have set the meta bit in the accelerator entry. - */ - if (mod & GDK_META_MASK) { - mod = GdkModifierType (mod & ~GDK_MOD2_MASK); - } -#endif - return true; -} - bool Gtkmm2ext::possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval) { @@ -702,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 context = Glib::wrap (gdk_pango_context_get()); Glib::RefPtr layout = Pango::Layout::create (context); @@ -730,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 layout = foo.create_pango_layout (""); @@ -756,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); @@ -848,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 @@ -967,3 +958,57 @@ Gtkmm2ext::event_type_string (int event_type) return "unknown"; } + +std::string +Gtkmm2ext::markup_escape_text (std::string const& s) +{ + return Glib::Markup::escape_text (s); +} + +void +Gtkmm2ext::add_volume_shortcuts (Gtk::FileChooser& c) +{ +#ifdef __APPLE__ + try { + /* This is a first order approach, listing all mounted volumes (incl network). + * One could use `diskutil` or `mount` to query local disks only, or + * something even fancier if deemed appropriate. + */ + Glib::Dir dir("/Volumes"); + for (Glib::DirIterator di = dir.begin(); di != dir.end(); di++) { + string fullpath = Glib::build_filename ("/Volumes", *di); + if (!Glib::file_test (fullpath, Glib::FILE_TEST_IS_DIR)) continue; + + try { /* add_shortcut_folder throws an exception if the folder being added already has a shortcut */ + c.add_shortcut_folder (fullpath); + } + catch (Glib::Error& e) { + std::cerr << "add_shortcut_folder() threw Glib::Error: " << e.what() << std::endl; + } + } + } + catch (Glib::FileError& e) { + std::cerr << "listing /Volumnes failed: " << e.what() << std::endl; + } +#endif +} + +float +Gtkmm2ext::paned_position_as_fraction (Gtk::Paned& paned, bool h) +{ + const guint pos = gtk_paned_get_position (const_cast(static_cast(&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)); +} +