From 2b662dd993c1cce712148765c953dfaf92390a01 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 9 Jun 2008 19:58:15 +0000 Subject: Fix Ctrl 'editable' patch modifier (for control twiddling) ceasing to work in various scenarios (ticket #120). git-svn-id: http://svn.drobilla.net/lad/ingen@1259 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/gui/PatchCanvas.cpp | 48 +++++++++++++++++++++++++++++++++----------- src/libs/gui/PatchCanvas.hpp | 2 ++ src/libs/gui/PatchWindow.cpp | 30 +++++++++++++++++++-------- src/libs/gui/PatchWindow.hpp | 1 + 4 files changed, 61 insertions(+), 20 deletions(-) (limited to 'src/libs/gui') diff --git a/src/libs/gui/PatchCanvas.cpp b/src/libs/gui/PatchCanvas.cpp index b26c5737..a787b1ae 100644 --- a/src/libs/gui/PatchCanvas.cpp +++ b/src/libs/gui/PatchCanvas.cpp @@ -447,7 +447,7 @@ PatchCanvas::canvas_event(GdkEvent* event) { assert(event); - static bool control_modded = false; + bool ret = false; switch (event->type) { @@ -456,34 +456,58 @@ PatchCanvas::canvas_event(GdkEvent* event) _last_click_x = (int)event->button.x; _last_click_y = (int)event->button.y; show_menu(event); + ret = true; } break; case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Delete) { + case GDK_KEY_RELEASE: + ret = canvas_key_event(&event->key); + + default: + break; + } + + return (ret ? true : Canvas::canvas_event(event)); +} + + +bool +PatchCanvas::canvas_key_event(GdkEventKey* event) +{ + static bool control_modded = false; + + switch (event->type) { + case GDK_KEY_PRESS: + switch (event->keyval) { + case GDK_Delete: destroy_selection(); - } else if (event->key.keyval == GDK_Control_L || event->key.keyval == GDK_Control_R) { + return true; + case GDK_Control_L: + case GDK_Control_R: if (_patch->get_editable() == true) { control_modded = true; _patch->set_editable(false); } + return true; + default: + return false; } - break; - case GDK_KEY_RELEASE: - if (event->key.keyval == GDK_Control_L || event->key.keyval == GDK_Control_R) { - if (_patch->get_editable() == false &&control_modded) { + switch (event->keyval) { + case GDK_Control_L: + case GDK_Control_R: + if (_patch->get_editable() == false && control_modded) { control_modded = false; _patch->set_editable(true); } + return true; + default: + return false; } - break; - default: - break; + return false; } - - return Canvas::canvas_event(event); } diff --git a/src/libs/gui/PatchCanvas.hpp b/src/libs/gui/PatchCanvas.hpp index dfebab7e..bb766314 100644 --- a/src/libs/gui/PatchCanvas.hpp +++ b/src/libs/gui/PatchCanvas.hpp @@ -82,6 +82,8 @@ public: void show_menu(GdkEvent* event) { _menu->popup(event->button.button, event->button.time); } + bool canvas_key_event(GdkEventKey* event); + private: enum ControlType { NUMBER, BUTTON }; void menu_add_control(ControlType type); diff --git a/src/libs/gui/PatchWindow.cpp b/src/libs/gui/PatchWindow.cpp index 84c60fc9..865cc9eb 100644 --- a/src/libs/gui/PatchWindow.cpp +++ b/src/libs/gui/PatchWindow.cpp @@ -419,17 +419,31 @@ PatchWindow::on_hide() bool PatchWindow::on_key_press_event(GdkEventKey* event) { - if (event->keyval == GDK_Delete) { - if (_view) { - _view->canvas()->destroy_selection(); - } - return true; - } else { - return Gtk::Window::on_key_press_event(event); - } + bool ret = false; + + ret = _view->canvas()->canvas_key_event(event); + + if (!ret) + ret = Gtk::Window::on_key_press_event(event); + + return ret; } + +bool +PatchWindow::on_key_release_event(GdkEventKey* event) +{ + bool ret = false; + + ret = _view->canvas()->canvas_key_event(event); + + if (!ret) + ret = Gtk::Window::on_key_release_event(event); + + return ret; +} + void PatchWindow::event_quit() { diff --git a/src/libs/gui/PatchWindow.hpp b/src/libs/gui/PatchWindow.hpp index 5120ba5a..def419fe 100644 --- a/src/libs/gui/PatchWindow.hpp +++ b/src/libs/gui/PatchWindow.hpp @@ -77,6 +77,7 @@ protected: void on_show(); void on_hide(); bool on_key_press_event(GdkEventKey* event); + bool on_key_release_event(GdkEventKey* event); private: -- cgit v1.2.1