#include <gtkmm/tooltip.h>
#include "gtkmm2ext/utils.h"
+#include "gtkmm2ext/persistent_tooltip.h"
#include "i18n.h"
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<Gdk::Pixbuf> 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);
}
}
-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)
{
}
int
-Gtkmm2ext::pixel_width (const string& str, Pango::FontDescription& font)
+Gtkmm2ext::pixel_width (const string& str, const Pango::FontDescription& font)
{
Glib::RefPtr<Pango::Context> context = Glib::wrap (gdk_pango_context_get());
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
}
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<Pango::Layout> layout = foo.create_pango_layout ("");
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);
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
{
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<GtkPaned*>(static_cast<const Gtk::Paned*>(&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));
+}
+