#include <cstdlib>
#include <cctype>
+#include <fstream>
+#include <sys/stat.h>
#include <libart_lgpl/art_misc.h>
#include <gtkmm/window.h>
#include <gtkmm/combo.h>
#include <gtk/gtkpaned.h>
#include <gtkmm2ext/utils.h>
+#include <ardour/ardour.h>
#include "ardour_ui.h"
#include "keyboard.h"
using namespace Gtk;
using namespace sigc;
using namespace Glib;
+using namespace PBD;
-string
-short_version (string orig, string::size_type target_length)
-{
- /* this tries to create a recognizable abbreviation
- of "orig" by removing characters until we meet
- a certain target length.
-
- note that we deliberately leave digits in the result
- without modification.
- */
-
-
- string::size_type pos;
-
- /* remove white-space and punctuation, starting at end */
-
- while (orig.length() > target_length) {
- if ((pos = orig.find_last_of (_("\"\n\t ,<.>/?:;'[{}]~`!@#$%^&*()_-+="))) == string::npos) {
- break;
- }
- orig.replace (pos, 1, "");
- }
-
- /* remove lower-case vowels, starting at end */
-
- while (orig.length() > target_length) {
- if ((pos = orig.find_last_of (_("aeiou"))) == string::npos) {
- break;
- }
- orig.replace (pos, 1, "");
- }
-
- /* remove upper-case vowels, starting at end */
-
- while (orig.length() > target_length) {
- if ((pos = orig.find_last_of (_("AEIOU"))) == string::npos) {
- break;
- }
- orig.replace (pos, 1, "");
- }
-
- /* remove lower-case consonants, starting at end */
-
- while (orig.length() > target_length) {
- if ((pos = orig.find_last_of (_("bcdfghjklmnpqrtvwxyz"))) == string::npos) {
- break;
- }
- orig.replace (pos, 1, "");
- }
-
- /* remove upper-case consonants, starting at end */
-
- while (orig.length() > target_length) {
- if ((pos = orig.find_last_of (_("BCDFGHJKLMNPQRTVWXYZ"))) == string::npos) {
- break;
- }
- orig.replace (pos, 1, "");
- }
-
- /* whatever the length is now, use it */
-
- return orig;
-}
-
-string
-fit_to_pixels (const string & str, int pixel_width, const string & font)
+ustring
+fit_to_pixels (const ustring& str, int pixel_width, Pango::FontDescription& font, int& actual_width)
{
Label foo;
- int width;
- int height;
- Pango::FontDescription fontdesc (font);
-
- int namelen = str.length();
- char cstr[namelen+1];
- strcpy (cstr, str.c_str());
+ Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout ("");
- while (namelen) {
- Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (cstr);
+ layout->set_font_description (font);
- layout->set_font_description (fontdesc);
- layout->get_pixel_size (width, height);
+ actual_width = 0;
- if (width < (pixel_width)) {
- break;
- }
+ ustring ustr = str;
+ ustring::iterator last = ustr.end();
+ --last; /* now points at final entry */
- --namelen;
- cstr[namelen] = '\0';
+ while (!ustr.empty()) {
- }
+ layout->set_text (ustr);
- return cstr;
-}
+ int width, height;
+ Gtkmm2ext::get_ink_pixel_size (layout, width, height);
-int
-atoi (const string& s)
-{
- return atoi (s.c_str());
-}
-
-double
-atof (const string& s)
-{
- return atof (s.c_str());
-}
-
-vector<string>
-internationalize (const char **array)
-{
- vector<string> v;
-
- for (uint32_t i = 0; array[i]; ++i) {
- v.push_back (_(array[i]));
+ if (width < pixel_width) {
+ actual_width = width;
+ break;
+ }
+
+ ustr.erase (last--);
}
- return v;
+ return ustr;
}
gint
return new ArdourCanvas::Points (npoints);
}
-static int32_t
-int_from_hex (char hic, char loc)
-{
- int hi; /* hi byte */
- int lo; /* low byte */
-
- hi = (int) hic;
-
- if( ('0'<=hi) && (hi<='9') ) {
- hi -= '0';
- } else if( ('a'<= hi) && (hi<= 'f') ) {
- hi -= ('a'-10);
- } else if( ('A'<=hi) && (hi<='F') ) {
- hi -= ('A'-10);
- }
-
- lo = (int) loc;
-
- if( ('0'<=lo) && (lo<='9') ) {
- lo -= '0';
- } else if( ('a'<=lo) && (lo<='f') ) {
- lo -= ('a'-10);
- } else if( ('A'<=lo) && (lo<='F') ) {
- lo -= ('A'-10);
- }
-
- return lo + (16 * hi);
-}
-
-void
-url_decode (string& url)
-{
- string::iterator last;
- string::iterator next;
-
- for (string::iterator i = url.begin(); i != url.end(); ++i) {
- if ((*i) == '+') {
- *i = ' ';
- }
- }
-
- if (url.length() <= 3) {
- return;
- }
-
- last = url.end();
-
- --last; /* points at last char */
- --last; /* points at last char - 1 */
-
- for (string::iterator i = url.begin(); i != last; ) {
-
- if (*i == '%') {
-
- next = i;
-
- url.erase (i);
-
- i = next;
- ++next;
-
- if (isxdigit (*i) && isxdigit (*next)) {
- /* replace first digit with char */
- *i = int_from_hex (*i,*next);
- ++i; /* points at 2nd of 2 digits */
- url.erase (i);
- }
- } else {
- ++i;
- }
- }
-}
-
Pango::FontDescription
get_font_for_style (string widgetname)
{
Gtk::Window window (WINDOW_TOPLEVEL);
Gtk::Label foobar;
- Glib::RefPtr<Style> style;
+ Glib::RefPtr<Gtk::Style> style;
window.add (foobar);
foobar.set_name (widgetname);
key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev)
{
GtkWindow* win = window.gobj();
+ GtkWidget* focus = gtk_window_get_focus (win);
+ bool special_handling_of_unmodified_accelerators = false;
+
+ if (focus) {
+ if (GTK_IS_ENTRY(focus)) {
+ special_handling_of_unmodified_accelerators = true;
+ }
+ }
/* This exists to allow us to override the way GTK handles
key events. The normal sequence is:
all "normal text" accelerators.
*/
- if (ev->state & ~Gdk::SHIFT_MASK) {
- /* modifiers in effect, accelerate first */
+
+ if (!special_handling_of_unmodified_accelerators) {
+
+ /* pretend that certain key events that GTK does not allow
+ to be used as accelerators are actually something that
+ it does allow.
+ */
+
+ int ret = false;
+
+ switch (ev->keyval) {
+ case GDK_Up:
+ ret = gtk_accel_groups_activate(G_OBJECT(win), GDK_uparrow, GdkModifierType(ev->state));
+ break;
+
+ case GDK_Down:
+ ret = gtk_accel_groups_activate(G_OBJECT(win), GDK_downarrow, GdkModifierType(ev->state));
+ break;
+
+ case GDK_Right:
+ ret = gtk_accel_groups_activate(G_OBJECT(win), GDK_rightarrow, GdkModifierType(ev->state));
+ break;
+
+ case GDK_Left:
+ ret = gtk_accel_groups_activate(G_OBJECT(win), GDK_leftarrow, GdkModifierType(ev->state));
+ break;
+
+ default:
+ break;
+ }
+
+ if (ret) {
+ return true;
+ }
+ }
+
+ if (!special_handling_of_unmodified_accelerators ||
+ ev->state & (Gdk::MOD1_MASK|
+ Gdk::MOD3_MASK|
+ Gdk::MOD4_MASK|
+ Gdk::MOD5_MASK|
+ Gdk::CONTROL_MASK)) {
+
+ /* no special handling or modifiers in effect: accelerate first */
+
if (!gtk_window_activate_key (win, ev)) {
return gtk_window_propagate_key_event (win, ev);
} else {
}
/* no modifiers, propagate first */
-
+
if (!gtk_window_propagate_key_event (win, ev)) {
return gtk_window_activate_key (win, ev);
}
return true;
}
+Glib::RefPtr<Gdk::Pixbuf>
+get_xpm (std::string name)
+{
+ if (!xpm_map[name]) {
+ xpm_map[name] = Gdk::Pixbuf::create_from_file (ARDOUR::find_data_file(name, "pixmaps"));
+ }
+
+ return (xpm_map[name]);
+}
+
+Glib::RefPtr<Gdk::Pixbuf>
+get_icon (const char* cname)
+{
+ string name = cname;
+ name += X_(".png");
+
+ string path = ARDOUR::find_data_file (name, "icons");
+
+ if (path.empty()) {
+ fatal << string_compose (_("cannot find icon image for %1"), name) << endmsg;
+ /*NOTREACHED*/
+ }
+
+ return Gdk::Pixbuf::create_from_file (path);
+}
+
+string
+longest (vector<string>& strings)
+{
+ if (strings.empty()) {
+ return string ("");
+ }
+
+ vector<string>::iterator longest = strings.begin();
+ string::size_type longest_length = (*longest).length();
+
+ vector<string>::iterator i = longest;
+ ++i;
+
+ while (i != strings.end()) {
+
+ string::size_type len = (*i).length();
+
+ if (len > longest_length) {
+ longest = i;
+ longest_length = len;
+ }
+
+ ++i;
+ }
+
+ return *longest;
+}