make dragging a region from the list not crash.
[ardour.git] / gtk2_ardour / sys_ex.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 #include "canvas/flag.h"
22 #include "sys_ex.h"
23 #include "ui_config.h"
24
25 using namespace std;
26
27 SysEx::SysEx (
28         MidiRegionView& region,
29         ArdourCanvas::Container* parent,
30         string&         text,
31         double          height,
32         double          x,
33         double          y)
34 {
35         _flag = new ArdourCanvas::Flag (
36                 parent,
37                 height,
38                 UIConfiguration::instance().color ("midi sysex outline"),
39                 UIConfiguration::instance().color_mod ("midi sysex fill", "midi sysex fill"),
40                 ArdourCanvas::Duple (x, y)
41                 );
42
43         _flag->set_text (text);
44 }
45
46 SysEx::~SysEx()
47 {
48         /* do not delete flag because it was added to a parent/container which
49            will delete it.
50         */
51         _flag = 0;
52 }
53
54 bool
55 SysEx::event_handler (GdkEvent* ev)
56 {
57         switch (ev->type) {
58         case GDK_BUTTON_PRESS:
59                 if (ev->button.button == 3) {
60                         return true;
61                 }
62                 break;
63
64         case GDK_SCROLL:
65                 if (ev->scroll.direction == GDK_SCROLL_UP) {
66                         return true;
67                 } else if (ev->scroll.direction == GDK_SCROLL_DOWN) {
68                         return true;
69                 }
70                 break;
71
72         default:
73                 break;
74         }
75
76         return false;
77 }
78
79 void
80 SysEx::hide ()
81 {
82         _flag->hide ();
83 }
84
85 void
86 SysEx::show ()
87 {
88         _flag->show ();
89 }