Merge branch 'master' into windows
[ardour.git] / gtk2_ardour / canvas-sysex.cc
1 /*
2     Copyright (C) 2009 Paul Davis
3     Author: Hans Baier
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <iostream>
21
22 #include "ardour_ui.h"
23
24 #include "midi_region_view.h"
25 #include "canvas-sysex.h"
26
27 using namespace Gnome::Canvas;
28 using namespace std;
29
30 CanvasSysEx::CanvasSysEx(
31                 MidiRegionView& region,
32                 Group&          parent,
33                 string&         text,
34                 double          height,
35                 double          x,
36                 double          y,
37                 const ARDOUR::MidiModel::SysExPtr sysex)
38         : CanvasFlag(
39                         region,
40                         parent,
41                         height,
42                         ARDOUR_UI::config()->canvasvar_MidiSysExOutline.get(),
43                         ARDOUR_UI::config()->canvasvar_MidiSysExFill.get(),
44                         x,
45                         y),
46         _sysex(sysex)
47 {
48         _text = text;
49         set_text(text);
50 }
51
52 CanvasSysEx::~CanvasSysEx()
53 {
54 }
55
56 bool
57 CanvasSysEx::on_event(GdkEvent* ev)
58 {
59         switch (ev->type) {
60         case GDK_BUTTON_PRESS:
61                 if (ev->button.button == 3) {
62                         return true;
63                 }
64                 break;
65
66         case GDK_SCROLL:
67                 if (ev->scroll.direction == GDK_SCROLL_UP) {
68                         return true;
69                 } else if (ev->scroll.direction == GDK_SCROLL_DOWN) {
70                         return true;
71                 }
72                 break;
73
74         case GDK_KEY_PRESS:
75                 switch (ev->key.keyval) {
76
77                 case GDK_Delete:
78                 case GDK_BackSpace:
79                         _region.delete_sysex (this);
80                         break;
81                 default:
82                         break;
83                 }
84                 break;
85
86         case GDK_ENTER_NOTIFY:
87                 _region.sysex_entered (this);
88                 return true;
89                 break;
90
91         case GDK_LEAVE_NOTIFY:
92                 _region.sysex_left (this);
93                 return true;
94         break;
95
96         default:
97                 break;
98         }
99
100         return false;
101 }
102