X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Futils.cc;h=91cb7ad58b21bf30c595cfbe9d3710b05428d326;hb=f535b0f4913a9c0b31ca3b21bd717c367676ebfc;hp=e0a31e584443e8573ac507eed92780411fcf3a07;hpb=8e591b058786c842c46790c96b806ad1eca6cbec;p=ardour.git diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index e0a31e5844..91cb7ad58b 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -20,186 +20,71 @@ #include #include +#include +#include #include #include #include #include #include -#include -#include -#include -#include #include #include +#include #include "ardour_ui.h" +#include "keyboard.h" #include "utils.h" #include "i18n.h" #include "rgb_macros.h" +#include "canvas_impl.h" using namespace std; 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 (string str, int pixel_width, 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 layout = foo.create_pango_layout (""); - while (namelen) { - Glib::RefPtr 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()); -} - -void -strip_whitespace_edges (string& str) -{ - string::size_type i; - string::size_type len; - string::size_type s; - - len = str.length(); - - for (i = 0; i < len; ++i) { - if (isgraph (str[i])) { + if (width < pixel_width) { + actual_width = width; break; } + + ustr.erase (last); + --last; } - s = i; - - for (i = len - 1; i >= 0; --i) { - if (isgraph (str[i])) { - break; - } - } - - str = str.substr (s, (i - s) + 1); -} - -vector -internationalize (const char **array) -{ - vector v; - - for (uint32_t i = 0; array[i]; ++i) { - v.push_back (_(array[i])); - } - - return v; + return ustr; } gint just_hide_it (GdkEventAny *ev, Gtk::Window *win) { - ARDOUR_UI::instance()->allow_focus (false); win->hide_all (); return TRUE; } -void -allow_keyboard_focus (bool yn) -{ - ARDOUR_UI::instance()->allow_focus (yn); -} - /* xpm2rgb copied from nixieclock, which bore the legend: nixieclock - a nixie desktop timepiece @@ -313,7 +198,7 @@ xpm2rgba (const char** xpm, uint32_t& w, uint32_t& h) return (savergb); } -GnomeCanvasPoints* +ArdourCanvas::Points* get_canvas_points (string who, uint32_t npoints) { // cerr << who << ": wants " << npoints << " canvas points" << endl; @@ -322,105 +207,17 @@ get_canvas_points (string who, uint32_t npoints) abort (); } #endif - return gnome_canvas_points_new (npoints); -} - -int -channel_combo_get_channel_count (Gtk::Combo& combo) -{ - string str = combo.get_entry()->get_text(); - int chns; - - if (str == _("mono")) { - return 1; - } else if (str == _("stereo")) { - return 2; - } else if ((chns = atoi (str)) != 0) { - return chns; - } else { - return 0; - } -} - -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; - } - } + return new ArdourCanvas::Points (npoints); } Pango::FontDescription get_font_for_style (string widgetname) { + Gtk::Window window (WINDOW_TOPLEVEL); Gtk::Label foobar; Glib::RefPtr