allow use of Return, KP_Enter and more in key binding editor; better display of such...
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 17 Nov 2009 13:54:04 +0000 (13:54 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 17 Nov 2009 13:54:04 +0000 (13:54 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@6109 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/actions.cc
gtk2_ardour/actions.h
gtk2_ardour/canvas-noevent-text.h [new file with mode: 0644]
gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_canvas.cc
gtk2_ardour/keyeditor.cc
gtk2_ardour/utils.cc
gtk2_ardour/utils.h

index b446ee8569042f41bb2058b49aa99ff2bdce9934..1d70725163c2f70b9794e48a64379efe32b339f8 100644 (file)
@@ -36,6 +36,7 @@
 #include "ardour/filesystem_paths.h"
 #include "ardour/rc_configuration.h"
 
+#include "utils.h"
 #include "actions.h"
 #include "i18n.h"
 
@@ -248,14 +249,7 @@ ActionManager::get_all_actions (vector<string>& names, vector<string>& paths, ve
                        paths.push_back (accel_path);
 
                        AccelKey key;
-                       bool known = lookup_entry (accel_path, key);
-
-                       if (known) {
-                               keys.push_back (ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod())));
-                       } else {
-                               keys.push_back (unbound_string);
-                       }
-
+                       keys.push_back (get_key_representation (accel_path, key));
                        bindings.push_back (AccelKey (key.get_key(), Gdk::ModifierType (key.get_mod())));
                }
        }
@@ -442,3 +436,17 @@ ActionManager::map_some_state (const char* group, const char* action, sigc::slot
                }
        }
 }
+
+string
+ActionManager::get_key_representation (const string& accel_path, AccelKey& key)
+{
+       bool known = lookup_entry (accel_path, key);
+       
+       if (known) {
+               uint32_t k = possibly_translate_legal_accelerator_to_real_key (key.get_key());
+               key = AccelKey (k, Gdk::ModifierType (key.get_mod()));
+               return ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
+       } 
+       
+       return unbound_string;
+}
index 187168e4b4a6fe23a70a88bf9547a43c9fedcd1f..4557e7f8c4544a91b815723d74d39ffd62251322 100644 (file)
@@ -67,6 +67,8 @@ class ActionManager
 
        static void set_sensitive (std::vector<Glib::RefPtr<Gtk::Action> >& actions, bool);
 
+       static std::string get_key_representation (const std::string& accel_path, Gtk::AccelKey& key);
+
        static std::string unbound_string;  /* the key string returned if an action is not bound */
        static Glib::RefPtr<Gtk::UIManager> ui_manager;
 
diff --git a/gtk2_ardour/canvas-noevent-text.h b/gtk2_ardour/canvas-noevent-text.h
new file mode 100644 (file)
index 0000000..e897895
--- /dev/null
@@ -0,0 +1,45 @@
+/* 
+ * Copyright (C) 2009 Paul Davis <paul@linuxaudiosystems.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __gtk2_ardour_canvas_noevent_text_h__
+#define __gtk2_ardour_canvas_noevent_text_h__
+
+#include <libgnomecanvasmm/text.h>
+#include <libgnomecanvasmm/text.h>
+
+namespace Gnome { namespace Canvas {
+
+class NoEventText : public Text
+{
+  public:
+       NoEventText(Group& parent, double x, double y, const Glib::ustring& text) 
+               : Text (parent, x, y, text) {}
+        NoEventText(Group& parent)
+         : Text (parent) {}
+
+       double point_vfunc(double, double, int, int, GnomeCanvasItem**) {
+               /* return a huge value to tell the canvas that we're never the item for an event */
+               return 9999999999999.0;
+       }
+};
+
+} } /* namespaces */
+
+#endif /* __gtk2_ardour_canvas_noevent_text_h__ */
index 3bc2980e153ea58e1183021b5bb5d6310601ca31..8ec20014b552b0384d4a74ea51517efcc27f035d 100644 (file)
@@ -3329,13 +3329,6 @@ Editor::show_verbose_canvas_cursor_with (const string & txt)
        track_canvas->get_pointer (x, y);
        track_canvas->window_to_world (x, y, wx, wy);
 
-       /* move it away from the mouse pointer to avoid an
-          infinite loop of enter/leave events.
-       */
-
-       wx += 20;
-       wy += 20;
-
        /* don't get too close to the edge */
        verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (wx);
        verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (wy);
index 0ecef0b60a1aa3e213860d8fe0bda861f85fac1b..0f5b2f3edde8a5364b012548f25a595349528bb7 100644 (file)
@@ -61,6 +61,7 @@
 #include "editing.h"
 #include "enums.h"
 #include "editor_items.h"
+#include "canvas-noevent-text.h"
 #include "region_selection.h"
 #include "canvas.h"
 #include "editor_summary.h"
@@ -626,7 +627,7 @@ class Editor : public PublicEditor
 
        ArdourCanvas::Canvas* track_canvas;
 
-       ArdourCanvas::Text* verbose_canvas_cursor;
+       ArdourCanvas::NoEventText* verbose_canvas_cursor;
        bool                 verbose_cursor_visible;
 
        void parameter_changed (std::string);
index 9342387dbe210ef8f238acb541b39f1d0b0990b5..f3a59f2c57b86bd670f07c9ca1a441176a7e86dc 100644 (file)
@@ -116,7 +116,7 @@ Editor::initialize_canvas ()
 
        Pango::FontDescription* font = get_font_for_style (N_("VerboseCanvasCursor"));
 
-       verbose_canvas_cursor = new ArdourCanvas::Text (*track_canvas->root());
+       verbose_canvas_cursor = new ArdourCanvas::NoEventText (*track_canvas->root());
        verbose_canvas_cursor->property_font_desc() = *font;
        verbose_canvas_cursor->property_anchor() = ANCHOR_NW;
 
index b909812f107117aaa2292f5f7619b11736b6528c..b8bfb5677b06f37247ed5e8d5b65b93dd9a6475d 100644 (file)
@@ -86,6 +86,8 @@ KeyEditor::unbind ()
 
        unbind_button.set_sensitive (false);
 
+       cerr << "trying to unbind\n";
+
        if (i != model->children().end()) {
                string path = (*i)[columns.path];
 
@@ -168,24 +170,21 @@ KeyEditor::on_key_release_event (GdkEventKey* ev)
                        goto out;
                }
 
+               cerr << "real lkeyval: " << ev->keyval << endl;
                possibly_translate_keyval_to_make_legal_accelerator (ev->keyval);
+               cerr << "using keyval = " << ev->keyval << endl;
+
 
                bool result = AccelMap::change_entry (path,
                                                      ev->keyval,
                                                      ModifierType (Keyboard::RelevantModifierKeyMask & ev->state),
                                                      true);
 
+               cerr << "New binding to " << ev->keyval << " worked: " << result << endl;
+
                if (result) {
-                       bool known;
                        AccelKey key;
-
-                       known = ActionManager::lookup_entry (path, key);
-
-                       if (known) {
-                               (*i)[columns.binding] = ActionManager::ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
-                       } else {
-                               (*i)[columns.binding] = string();
-                       }
+                       (*i)[columns.binding] = ActionManager::get_key_representation (path, key);
                }
        }
 
index 0f53b0912f27f05232eef85a7d603c119a1617f4..e50a39b397d193135fc5ffbb0bd3d301c882288d 100644 (file)
@@ -879,6 +879,14 @@ possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval)
                fakekey = GDK_leftarrow;
                break;
 
+       case GDK_Return:
+               fakekey = GDK_3270_Enter;
+               break;
+
+       case GDK_KP_Enter:
+               fakekey = GDK_F35;
+               break;
+
        default:
                break;
        }
@@ -891,6 +899,42 @@ possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval)
        return false;
 }
 
+uint32_t
+possibly_translate_legal_accelerator_to_real_key (uint32_t keyval)
+{
+       switch (keyval) {
+       case GDK_nabla:
+               return GDK_Tab;
+               break;
+
+       case GDK_uparrow:
+               return GDK_Up;
+               break;
+
+       case GDK_downarrow:
+               return GDK_Down;
+               break;
+
+       case GDK_rightarrow:
+               return GDK_Right;
+               break;
+
+       case GDK_leftarrow:
+               return GDK_Left;
+               break;
+
+       case GDK_3270_Enter:
+               return GDK_Return;
+
+       case GDK_F35:
+               return GDK_KP_Enter;
+               break;
+       }
+
+       return keyval;
+}
+
+
 
 inline guint8
 convert_color_channel (guint8 src,
index 18c4e860b84ec6b33746401fb106bd295db9d488..a7da5cc997d509f27efc5ad5ed4e0e11bd6f2d47 100644 (file)
@@ -85,6 +85,7 @@ void set_color (Gdk::Color&, int);
 bool relay_key_press (GdkEventKey* ev, Gtk::Window* win);
 bool key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev);
 bool possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval);
+uint32_t possibly_translate_legal_accelerator_to_real_key (uint32_t keyval);
 
 Glib::RefPtr<Gdk::Pixbuf> get_xpm (std::string);
 Glib::ustring get_icon_path (const char*);