GtkWindow* win = window.gobj();
GtkWidget* focus = gtk_window_get_focus (win);
bool special_handling_of_unmodified_accelerators = false;
-#ifdef GTKOSX
- bool allow_forwarding = true;
-#endif
+ bool allow_activating = true;
#undef DEBUG_ACCELERATOR_HANDLING
#ifdef DEBUG_ACCELERATOR_HANDLING
- bool debug = (getenv ("ARDOUR_DEBUG_ACCELERATOR_HANDLING") != 0);
+ //bool debug = (getenv ("ARDOUR_DEBUG_ACCELERATOR_HANDLING") != 0);
+ bool debug=true;
#endif
if (focus) {
if (GTK_IS_ENTRY(focus) || Keyboard::some_magic_widget_has_focus()) {
}
#ifdef GTKOSX
+ /* should this be universally true? */
if (Keyboard::some_magic_widget_has_focus ()) {
- allow_forwarding = false;
+ allow_activating = false;
}
#endif
if (debug) {
cerr << "Win = " << win << " Key event: code = " << ev->keyval << " state = " << hex << ev->state << dec << " special handling ? "
<< special_handling_of_unmodified_accelerators
+ << " magic widget focus ? "
+ << Keyboard::some_magic_widget_has_focus()
+ << " allow_activation ? "
+ << allow_activating
<< endl;
}
#endif
uint32_t fakekey = ev->keyval;
if (possibly_translate_keyval_to_make_legal_accelerator (fakekey)) {
- if (gtk_accel_groups_activate(G_OBJECT(win), fakekey, GdkModifierType(ev->state))) {
+ if (allow_activating && gtk_accel_groups_activate(G_OBJECT(win), fakekey, GdkModifierType(ev->state))) {
return true;
}
#ifdef GTKOSX
- int oldval = ev->keyval;
- ev->keyval = fakekey;
- if (gdk_quartz_possibly_forward ((GdkEvent*) ev)) {
- return true;
+ if (allow_activating) {
+ int oldval = ev->keyval;
+ ev->keyval = fakekey;
+ if (gdk_quartz_possibly_forward ((GdkEvent*) ev)) {
+ return true;
+ }
+ ev->keyval = oldval;
}
- ev->keyval = oldval;
#endif
}
}
}
#endif
+ if (allow_activating) {
#ifdef GTKOSX
- if (allow_forwarding && gdk_quartz_possibly_forward ((GdkEvent*) ev)) {
- return true;
- }
-#endif
- if (!gtk_window_activate_key (win, ev)) {
-#ifdef DEBUG_ACCELERATOR_HANDLING
- if (debug) {
- cerr << "\tnot accelerated, now propagate\n";
+ if (gdk_quartz_possibly_forward ((GdkEvent*) ev)) {
+ return true;
}
#endif
- return gtk_window_propagate_key_event (win, ev);
- } else {
-#ifdef DEBUG_ACCELERATOR_HANDLING
- if (debug) {
- cerr << "\taccelerated - done.\n";
+ if (gtk_window_activate_key (win, ev)) {
+ return true;
}
+ }
+
+#ifdef DEBUG_ACCELERATOR_HANDLING
+ if (debug) {
+ cerr << "\tnot accelerated, now propagate\n";
+ }
#endif
- return true;
- }
+ return gtk_window_propagate_key_event (win, ev);
}
/* no modifiers, propagate first */
cerr << "\tpropagation didn't handle, so activate\n";
}
#endif
+
+ if (allow_activating) {
+
#ifdef GTKOSX
- if (gdk_quartz_possibly_forward ((GdkEvent*) ev)) {
- return true;
- }
+ if (gdk_quartz_possibly_forward ((GdkEvent*) ev)) {
+ return true;
+ }
#endif
- return gtk_window_activate_key (win, ev);
+ return gtk_window_activate_key (win, ev);
+ }
+
} else {
#ifdef DEBUG_ACCELERATOR_HANDLING
if (debug) {
return false;
}
+inline guint8
+convert_color_channel (guint8 src,
+ guint8 alpha)
+{
+ return alpha ? ((guint (src) << 8) - src) / alpha : 0;
+}
+
+void
+convert_bgra_to_rgba (guint8 const* src,
+ guint8* dst,
+ int width,
+ int height)
+{
+ guint8 const* src_pixel = src;
+ guint8* dst_pixel = dst;
+
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ dst_pixel[0] = convert_color_channel (src_pixel[2],
+ src_pixel[3]);
+ dst_pixel[1] = convert_color_channel (src_pixel[1],
+ src_pixel[3]);
+ dst_pixel[2] = convert_color_channel (src_pixel[0],
+ src_pixel[3]);
+ dst_pixel[3] = src_pixel[3];
+
+ dst_pixel += 4;
+ src_pixel += 4;
+ }
+}
+
+Glib::RefPtr<Gdk::Pixbuf>
+pixbuf_from_ustring(const ustring& name, Pango::FontDescription* font, int clip_width, int 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);
+ cairo_t* cr = cairo_create (surface);
+ cairo_text_extents_t te;
+
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
+ cairo_select_font_face (cr, font->get_family().c_str(),
+ CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
+ cairo_set_font_size (cr, font->get_size() / Pango::SCALE);
+ cairo_text_extents (cr, name.c_str(), &te);
+
+ cairo_move_to (cr, 0.5, 0.5 - te.height / 2 - te.y_bearing + clip_height / 2);
+ cairo_show_text (cr, name.c_str());
+
+ convert_bgra_to_rgba(cairo_image_surface_get_data (surface), buf->get_pixels(), clip_width, clip_height);
+
+ cairo_destroy(cr);
+ cairo_surface_destroy(surface);
+
+ return buf;
+}