make it possible for canvas patch changes to receive kbd events, and along the way...
authorPaul Davis <paul@linuxaudiosystems.com>
Sun, 17 Jun 2012 13:37:52 +0000 (13:37 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Sun, 17 Jun 2012 13:37:52 +0000 (13:37 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12745 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/canvas-flag.cc
gtk2_ardour/canvas-flag.h
gtk2_ardour/canvas-noevent-pixbuf.h [new file with mode: 0644]
gtk2_ardour/canvas_patch_change.cc
gtk2_ardour/midi_region_view.cc

index d77de07359135ff5d920c729694fee80ebfdd2cc..75be80fb3f34ef9061c3520c52939976be0c054e 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "ardour_ui.h"
 #include "canvas-flag.h"
+#include "canvas-noevent-pixbuf.h"
 #include "time_axis_view_item.h"
 #include "utils.h"
 
@@ -28,7 +29,6 @@ CanvasFlag::CanvasFlag (MidiRegionView& region,
        , _line(0)
        , _rect(0)
 {
-       signal_event().connect (sigc::mem_fun (*this, &CanvasFlag::on_event));
 }
 
 void
@@ -49,7 +49,7 @@ CanvasFlag::set_text (const string& text)
 {
        delete_allocated_objects();
 
-       _name_pixbuf = new ArdourCanvas::Pixbuf (*this);
+       _name_pixbuf = new ArdourCanvas::NoEventPixbuf (*this);
        name_pixbuf_width = Gtkmm2ext::pixel_width (text, TimeAxisViewItem::NAME_FONT) + 2;
        Gdk::Color c;
        set_color (c, _outline_color_rgba);
@@ -75,15 +75,6 @@ CanvasFlag::~CanvasFlag()
        delete_allocated_objects();
 }
 
-bool
-CanvasFlag::on_event(GdkEvent* /*ev*/)
-{
-       /* XXX if you change this function to actually do anything, be sure
-          to fix the connections commented out elsewhere in this file.
-       */
-       return false;
-}
-
 void
 CanvasFlag::set_height (double h)
 {
index 17edc198801f82428441fd0c1b39465709d96acb..4ad41ec8833191b4b912d0e5acb4d22b9d510c64 100644 (file)
@@ -28,8 +28,6 @@ public:
 
        virtual ~CanvasFlag();
 
-       virtual bool on_event(GdkEvent* ev);
-
        virtual void set_text(const std::string& a_text);
        virtual void set_height (double);
 
diff --git a/gtk2_ardour/canvas-noevent-pixbuf.h b/gtk2_ardour/canvas-noevent-pixbuf.h
new file mode 100644 (file)
index 0000000..4424a90
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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_pixbuf_h__
+#define __gtk2_ardour_canvas_noevent_pixbuf_h__
+
+#include <libgnomecanvasmm/pixbuf.h>
+
+namespace Gnome { namespace Canvas {
+
+class NoEventPixbuf : public Pixbuf
+{
+  public:
+    NoEventPixbuf(Group& parent) : Pixbuf (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_pixbuf_h__ */
index 2db31f1b5c7a9322da1a5337450dfb662ea06bfd..29e30e332debf4d33022ca2332d8987a26928e7b 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <boost/algorithm/string.hpp>
 
+#include "pbd/stacktrace.h"
+
 #include "gtkmm2ext/keyboard.h"
 #include "ardour/instrument_info.h"
 
@@ -144,11 +146,12 @@ CanvasPatchChange::on_patch_menu_selected(const PatchPrimaryKey& key)
 bool
 CanvasPatchChange::on_event (GdkEvent* ev)
 {
+       Editor* e;
+
        switch (ev->type) {
        case GDK_BUTTON_PRESS:
-       {
                /* XXX: icky dcast */
-               Editor* e = dynamic_cast<Editor*> (&_region.get_time_axis_view().editor());
+               e = dynamic_cast<Editor*> (&_region.get_time_axis_view().editor());
                if (e->current_mouse_mode() == Editing::MouseObject && e->internal_editing()) {
 
                        if (Gtkmm2ext::Keyboard::is_delete_event (&ev->button)) {
@@ -178,7 +181,6 @@ CanvasPatchChange::on_event (GdkEvent* ev)
                        return true;
                }
                break;
-       }
 
        case GDK_KEY_PRESS:
                switch (ev->key.keyval) {
@@ -200,15 +202,18 @@ CanvasPatchChange::on_event (GdkEvent* ev)
                                _region.next_patch (*this);
                        }
                        break;
+               case GDK_Delete:
+               case GDK_BackSpace:
+                       _region.delete_patch_change (this);
+                       break;
                default:
                        break;
                }
                break;
 
        case GDK_SCROLL:
-       {
                /* XXX: icky dcast */
-               Editor* e = dynamic_cast<Editor*> (&_region.get_time_axis_view().editor());
+               e = dynamic_cast<Editor*> (&_region.get_time_axis_view().editor());
                if (e->current_mouse_mode() == Editing::MouseObject && e->internal_editing()) {
                        if (ev->scroll.direction == GDK_SCROLL_UP) {
                                if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
@@ -216,25 +221,26 @@ CanvasPatchChange::on_event (GdkEvent* ev)
                                } else {
                                        _region.previous_patch (*this);
                                }
-                               return true;
                        } else if (ev->scroll.direction == GDK_SCROLL_DOWN) {
                                if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
                                        _region.next_bank (*this);
                                } else {
                                        _region.next_patch (*this);
                                }
-                               return true;
                        }
+                       return true;
                        break;
                }
-        }
+               break;
 
        case GDK_ENTER_NOTIFY:
                _region.patch_entered (this);
+                return true;
                break;
 
        case GDK_LEAVE_NOTIFY:
                _region.patch_left (this);
+                return true;
                break;
 
        default:
index c2d706382e37499c58c0e2ed0a8463359f76ab2d..99a7bf38f75bfefa6ab95dc5ff2338e1cdb87217 100644 (file)
@@ -277,8 +277,7 @@ MidiRegionView::init (Gdk::Color const & basic_color, bool wfd)
        reset_width_dependent_items (_pixel_width);
 
        group->raise_to_top();
-       group->signal_event().connect(
-               sigc::mem_fun(this, &MidiRegionView::canvas_event), false);
+       group->signal_event().connect (sigc::mem_fun (this, &MidiRegionView::canvas_event), false);
 
        midi_view()->signal_channel_mode_changed().connect(
                sigc::mem_fun(this, &MidiRegionView::midi_channel_mode_changed));
@@ -322,7 +321,7 @@ bool
 MidiRegionView::canvas_event(GdkEvent* ev)
 {
        bool r;
-       
+
        switch (ev->type) {
        case GDK_ENTER_NOTIFY:
        case GDK_LEAVE_NOTIFY:
@@ -714,7 +713,11 @@ MidiRegionView::key_press (GdkEventKey* ev)
 
                return true;
 
-       } else if (ev->keyval == GDK_Delete && unmodified) {
+       } else if ((ev->keyval == GDK_BackSpace || ev->keyval == GDK_Delete) && unmodified) {
+
+               if (_selection.empty()) {
+                       return false;
+               }
 
                delete_selection();
                return true;
@@ -1798,7 +1801,7 @@ MidiRegionView::add_canvas_patch_change (MidiModel::PatchChangePtr patch, const
        double const height = midi_stream_view()->contents_height();
 
        boost::shared_ptr<CanvasPatchChange> patch_change = boost::shared_ptr<CanvasPatchChange>(
-               new CanvasPatchChange(*this, *_note_group,
+               new CanvasPatchChange(*this, *group,
                                      displaytext,
                                      height,
                                      x, 1.0,
@@ -3139,18 +3142,24 @@ MidiRegionView::note_left (ArdourCanvas::CanvasNoteEvent*)
 }
 
 void
-MidiRegionView::patch_entered (ArdourCanvas::CanvasPatchChange* ev)
+MidiRegionView::patch_entered (ArdourCanvas::CanvasPatchChange* p)
 {
        ostringstream s;
        /* XXX should get patch name if we can */
-       s << _("Bank:") << (ev->patch()->bank() + MIDI_BP_ZERO) << '\n' << _("Program:") << ((int) ev->patch()->program()) + MIDI_BP_ZERO << '\n' << _("Channel:") << ((int) ev->patch()->channel() + 1);
+       s << _("Bank:") << (p->patch()->bank() + MIDI_BP_ZERO) << '\n' 
+         << _("Program:") << ((int) p->patch()->program()) + MIDI_BP_ZERO << '\n' 
+         << _("Channel:") << ((int) p->patch()->channel() + 1);
        show_verbose_cursor (s.str(), 10, 20);
+       p->grab_focus();
 }
 
 void
 MidiRegionView::patch_left (ArdourCanvas::CanvasPatchChange *)
 {
        trackview.editor().verbose_cursor()->hide ();
+       /* focus will transfer back via the enter-notify event sent to this
+        * midi region view.
+        */
 }
 
 void