21 #include "gtk2ardour-config.h"
24 #include <pango/pangoft2.h>
25 #include <pango/pangocairo.h>
36 #include <gtkmm/window.h>
37 #include <gtkmm/combo.h>
38 #include <gtkmm/label.h>
39 #include <gtkmm/paned.h>
40 #include <gtk/gtkpaned.h>
41 #include <boost/algorithm/string.hpp>
49 #include "canvas/item.h"
50 #include "canvas/utils.h"
71 #ifdef PLATFORM_WINDOWS
72 #define random() rand()
86 m.back().set_sensitive (
false);
109 static long vals[256], val;
110 uint32_t t, x, y, colors, cpp;
112 unsigned char *savergb, *rgb;
116 if ( sscanf(xpm[0],
"%u%u%u%u", &w, &h, &colors, &cpp) != 4 ) {
122 savergb = rgb = (
unsigned char*) malloc (h * w * 3);
125 for (t = 0; t < colors; ++t) {
126 sscanf (xpm[t+1],
"%c c #%lx", &c, &val);
135 for (y = h-1; y > 0; --y) {
137 for (p = xpm[1+colors+(h-y-1)], x = 0; x < w; x++, rgb += 3) {
138 val = vals[(int)*p++];
139 *(rgb+2) = val & 0xff; val >>= 8;
140 *(rgb+1) = val & 0xff; val >>= 8;
141 *(rgb+0) = val & 0xff;
151 static long vals[256], val;
152 uint32_t t, x, y, colors, cpp;
154 unsigned char *savergb, *rgb;
159 if ( sscanf(xpm[0],
"%u%u%u%u", &w, &h, &colors, &cpp) != 4 ) {
165 savergb = rgb = (
unsigned char*) malloc (h * w * 4);
169 if (strstr (xpm[1],
"None")) {
170 sscanf (xpm[1],
"%c", &transparent);
177 for (; t < colors; ++t) {
178 sscanf (xpm[t+1],
"%c c #%lx", &c, &val);
187 for (y = h-1; y > 0; --y) {
191 for (p = xpm[1+colors+(h-y-1)], x = 0; x < w; x++, rgb += 4) {
193 if (transparent && (*p++ == transparent)) {
202 *(rgb+2) = val & 0xff; val >>= 8;
203 *(rgb+1) = val & 0xff; val >>= 8;
204 *(rgb+0) = val & 0xff;
225 Pango::FontDescription
228 Pango::FontDescription fd (name);
230 if (fd.get_family().empty()) {
231 fd.set_family (
"Sans");
237 Pango::FontDescription
240 Gtk::Window window (WINDOW_TOPLEVEL);
242 Glib::RefPtr<Gtk::Style> style;
245 foobar.set_name (widgetname);
246 foobar.ensure_style();
248 style = foobar.get_style ();
250 Glib::RefPtr<const Pango::Layout> layout = foobar.get_layout();
252 PangoFontDescription *pfd =
const_cast<PangoFontDescription *
> (pango_layout_get_font_description(const_cast<PangoLayout *>(layout->gobj())));
258 PangoContext* ctxt = (PangoContext*) pango_layout_get_context (const_cast<PangoLayout*>(layout->gobj()));
259 pfd = pango_context_get_font_description (ctxt);
260 return Pango::FontDescription (pfd);
263 return Pango::FontDescription (pfd);
272 c.set_rgb ((rgb >> 16)*256, ((rgb & 0xff00) >> 8)*256, (rgb & 0xff)*256);
281 c.set_rgb ((rgba >> 24)*256, ((rgba & 0xff0000) >> 16)*256, ((rgba & 0xff00) >> 8)*256);
291 const uint32_t r = c.get_red_p () * 255.0;
292 const uint32_t g = c.get_green_p () * 255.0;
293 const uint32_t b = c.get_blue_p () * 255.0;
294 const uint32_t a = 0xff;
310 return ed.on_key_press_event(ev);
325 GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET(w->gobj()));
326 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
327 GdkKeymapKey *keymapkey = NULL;
330 if (!gdk_keymap_get_entries_for_keyval(keymap, keyval, &keymapkey, &n_keys))
return false;
331 if (n_keys !=1) { g_free(keymapkey);
return false;}
334 ev.type = GDK_KEY_PRESS;
335 ev.window = gtk_widget_get_window(GTK_WIDGET(w->gobj()));
336 ev.send_event = FALSE;
341 ev.string =
const_cast<gchar*
> (
"");
342 ev.hardware_keycode = keymapkey[0].keycode;
343 ev.group = keymapkey[0].group;
347 ev.type = GDK_KEY_RELEASE;
355 if (state & GDK_SHIFT_MASK) {
358 if (state & GDK_LOCK_MASK) {
361 if (state & GDK_CONTROL_MASK) {
364 if (state & GDK_MOD1_MASK) {
367 if (state & GDK_MOD2_MASK) {
370 if (state & GDK_MOD3_MASK) {
373 if (state & GDK_MOD4_MASK) {
376 if (state & GDK_MOD5_MASK) {
379 if (state & GDK_BUTTON1_MASK) {
382 if (state & GDK_BUTTON2_MASK) {
385 if (state & GDK_BUTTON3_MASK) {
388 if (state & GDK_BUTTON4_MASK) {
391 if (state & GDK_BUTTON5_MASK) {
394 if (state & GDK_SUPER_MASK) {
397 if (state & GDK_HYPER_MASK) {
400 if (state & GDK_META_MASK) {
403 if (state & GDK_RELEASE_MASK) {
412 GtkWindow* win = window.gobj();
413 GtkWidget* focus = gtk_window_get_focus (win);
414 bool special_handling_of_unmodified_accelerators =
false;
415 bool allow_activating =
true;
417 const guint mask = (Keyboard::RelevantModifierKeyMask & ~(Gdk::SHIFT_MASK|Gdk::LOCK_MASK));
418 GdkModifierType
modifier = GdkModifierType (ev->state);
419 modifier = GdkModifierType (modifier & gtk_accelerator_get_default_mod_mask());
423 if (GTK_IS_ENTRY(focus) || Keyboard::some_magic_widget_has_focus()) {
424 special_handling_of_unmodified_accelerators =
true;
434 if (Keyboard::some_magic_widget_has_focus ()) {
435 allow_activating =
false;
445 special_handling_of_unmodified_accelerators,
446 Keyboard::some_magic_widget_has_focus(),
449 (focus ? gtk_widget_get_name (focus) :
"no focus widget")));
482 if (!special_handling_of_unmodified_accelerators) {
506 uint32_t fakekey = ev->keyval;
510 ev->keyval, fakekey));
514 if (allow_activating && gtk_accel_groups_activate(G_OBJECT(win), fakekey, modifier)) {
521 if (!special_handling_of_unmodified_accelerators || (ev->state & mask)) {
527 ev->send_event, ev->time, ev->length, ev->string, ev->hardware_keycode, ev->group, gdk_keyval_name (ev->keyval)));
529 if (allow_activating) {
531 if (gtk_accel_groups_activate (G_OBJECT(win), ev->keyval, modifier)) {
541 return gtk_window_propagate_key_event (win, ev);
548 if (!gtk_window_propagate_key_event (win, ev)) {
550 if (allow_activating) {
551 return gtk_accel_groups_activate (G_OBJECT(win), ev->keyval, modifier);
565 Glib::RefPtr<Gdk::Pixbuf>
574 std::string data_file_path;
576 if(!
find_file (spath, name, data_file_path)) {
581 xpm_map[
name] = Gdk::Pixbuf::create_from_file (data_file_path);
582 }
catch(
const Glib::Error& e) {
597 r.push_back (
_(
"default"));
599 for (vector<string>::iterator s = spath.begin(); s != spath.end(); ++s) {
601 vector<string> entries;
605 for (vector<string>::iterator e = entries.begin(); e != entries.end(); ++e) {
606 if (Glib::file_test (*e, Glib::FILE_TEST_IS_DIR)) {
607 r.push_back (Glib::filename_to_utf8 (Glib::path_get_basename(*e)));
618 std::string data_file_path;
627 if (!icon_set.empty() && icon_set !=
_(
"default")) {
630 spath.add_subdirectory_to_paths (
"icons");
631 spath.add_subdirectory_to_paths (icon_set);
635 spath.add_subdirectory_to_paths (
"icons");
639 if (is_image && data_file_path.empty()) {
641 if (!icon_set.empty() && icon_set !=
_(
"default")) {
646 def.add_subdirectory_to_paths (
"icons");
648 if (!
find_file (def, name, data_file_path)) {
654 return data_file_path;
657 Glib::RefPtr<Gdk::Pixbuf>
660 Glib::RefPtr<Gdk::Pixbuf> img;
662 img = Gdk::Pixbuf::create_from_file (
get_icon_path (cname, icon_set));
663 }
catch (
const Gdk::PixbufError &e) {
664 cerr <<
"Caught PixbufError: " << e.what() << endl;
673 Glib::RefPtr<Gdk::Pixbuf>
676 Glib::RefPtr<Gdk::Pixbuf> img;
679 }
catch (
const Gdk::PixbufError &e) {
680 cerr <<
"Caught PixbufError: " << e.what() << endl;
692 if (strings.empty()) {
696 vector<string>::iterator
longest = strings.begin();
697 string::size_type longest_length = (*longest).length();
699 vector<string>::iterator i =
longest;
702 while (i != strings.end()) {
704 string::size_type len = (*i).length();
706 if (len > longest_length) {
708 longest_length = len;
723 static int comma_decimal = -1;
728 if (comma_decimal < 0) {
729 std::lconv* lc = std::localeconv();
730 if (strchr (lc->decimal_point,
',') != 0) {
742 case GDK_decimalpoint:
743 case GDK_KP_Separator:
773 case GDK_KP_Subtract:
809 #ifndef PLATFORM_WINDOWS
810 pango_ft2_font_map_set_resolution ((PangoFT2FontMap*) pango_ft2_font_map_new(), val/1024, val/1024);
815 pango_cairo_font_map_set_resolution ((PangoCairoFontMap*) pango_cairo_font_map_get_default(), val/1024);
825 gtk_settings_set_long_property (gtk_settings_get_default(),
826 "gtk-xft-dpi", val,
"ardour");
833 Glib::RefPtr<Gdk::Screen> screen = window->get_screen ();
834 Gdk::Rectangle monitor_rect;
835 screen->get_monitor_geometry (0, monitor_rect);
837 int const w = std::min (
int (monitor_rect.get_width() * 0.8), max_width);
838 int const h = std::min (
int (monitor_rect.get_height() * 0.8), max_height);
840 window->resize (w, h);
849 string::size_type
const N = s.length ();
851 for (string::size_type i = 0; i <
N; ++i) {
881 h = fmod (random(), 360.0);
882 s = (random() % 65535) / 65535.0;
883 v = (random() % 65535) / 65535.0;
887 newcolor.set_hsv (h, s, v);
889 if (used_colors.size() == 0) {
890 used_colors.push_back (newcolor);
894 for (list<Gdk::Color>::iterator i = used_colors.begin(); i != used_colors.end(); ++i) {
896 float rdelta, bdelta, gdelta;
898 rdelta = newcolor.get_red() - c.get_red();
899 bdelta = newcolor.get_blue() - c.get_blue();
900 gdelta = newcolor.get_green() - c.get_green();
902 if (sqrt (rdelta*rdelta + bdelta*bdelta + gdelta*gdelta) > 25.0) {
904 used_colors.push_back (newcolor);
917 if (fmod (r, 1000.0
f)) {
918 snprintf (buf,
sizeof (buf),
"%.1f kHz", r/1000.0);
920 snprintf (buf,
sizeof (buf),
"%.0f kHz", r/1000.0);
bool relay_key_press(GdkEventKey *ev, Gtk::Window *win)
Gdk::Color unique_random_color(std::list< Gdk::Color > &)
LIBPBD_API Transmitter fatal
unsigned char * xpm2rgba(const char **xpm, uint32_t &w, uint32_t &h)
static std::map< std::string, Glib::RefPtr< Gdk::Pixbuf > > xpm_map
void resize_window_to_proportion_of_monitor(Gtk::Window *, int, int)
Pango::FontDescription sanitized_font(std::string const &)
bool emulate_key_event(Gtk::Widget *, unsigned int)
LIBGTKMM2EXT_API bool possibly_translate_mod_to_make_legal_accelerator(GdkModifierType &mod)
sigc::signal< void > DPIReset
Pango::FontDescription get_font_for_style(std::string widgetname)
bool forward_key_press(GdkEventKey *ev)
bool key_press_focus_accelerator_handler(Gtk::Window &window, GdkEventKey *ev)
std::vector< std::string > get_icon_sets()
static string show_gdk_event_state(int state)
unsigned char * xpm2rgb(const char **xpm, uint32_t &w, uint32_t &h)
Representation of the interface of the Editor class.
LIBPBD_API Transmitter error
LIBPBD_API Transmitter warning
std::ostream & endmsg(std::ostream &ostr)
void add_item_with_sensitivity(Gtk::Menu_Helpers::MenuList &, Gtk::Menu_Helpers::MenuElem, bool)
LIBPBD_API int replace_all(std::string &str, const std::string &target, const std::string &replacement)
bool find_file(const Searchpath &search_path, const string &filename, std::string &result)
LIBPBD_TEMPLATE_MEMBER_API Searchpath & add_subdirectory_to_paths(const std::string &subdir)
gint just_hide_it(GdkEventAny *, Gtk::Window *)
LIBGTKMM2EXT_API uint64_t Keyboard
uint32_t gdk_color_to_rgba(Gdk::Color const &)
void set_color_from_rgba(Gdk::Color &, uint32_t)
std::string longest(std::vector< std::string > &)
std::string rate_as_string(float r)
#define DEBUG_TRACE(bits, str)
void set_color_from_rgb(Gdk::Color &, uint32_t)
bool key_is_legal_for_numeric_entry(guint keyval)
void set_pango_fontsize()
LIBGTKMM2EXT_API bool possibly_translate_keyval_to_make_legal_accelerator(uint32_t &keyval)
static PublicEditor & instance()
void get_paths(vector< string > &result, const Searchpath &paths, bool files_only, bool recurse)
static UIConfiguration * config()
Glib::RefPtr< Gdk::Pixbuf > get_xpm(std::string)
std::string get_icon_path(const char *, std::string icon_set=std::string(), bool is_image=true)
#define RGBA_TO_UINT(r, g, b, a)
std::string escape_underscores(std::string const &)
LIBARDOUR_API PBD::Searchpath ardour_data_search_path()
Glib::RefPtr< Gdk::Pixbuf > get_icon(const char *cname)
std::string string_compose(const std::string &fmt, const T1 &o1)
std::string escape_angled_brackets(std::string const &)