NOOP, remove trailing tabs/whitespace.
[ardour.git] / gtk2_ardour / ardour_dropdown.cc
1 /*
2     Copyright (C) 2014 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <iostream>
21 #include <cmath>
22 #include <algorithm>
23
24 #include <pangomm/layout.h>
25
26 #include "pbd/compose.h"
27 #include "pbd/error.h"
28 #include "pbd/stacktrace.h"
29
30 #include "gtkmm2ext/utils.h"
31 #include "gtkmm2ext/rgb_macros.h"
32 #include "gtkmm2ext/gui_thread.h"
33
34 #include "ardour/rc_configuration.h" // for widget prelight preference
35
36 #include "ardour_dropdown.h"
37
38 #include "i18n.h"
39
40 #define REFLECTION_HEIGHT 2
41
42 using namespace Gdk;
43 using namespace Gtk;
44 using namespace Glib;
45 using namespace PBD;
46 using std::max;
47 using std::min;
48 using namespace std;
49
50
51 ArdourDropdown::ArdourDropdown (Element e)
52 {
53 //      signal_button_press_event().connect (sigc::mem_fun(*this, &ArdourDropdown::on_mouse_pressed));
54
55         add_elements(e);
56         add_elements(ArdourButton::Menu);
57 }
58
59 ArdourDropdown::~ArdourDropdown ()
60 {
61 }
62
63 bool
64 ArdourDropdown::on_button_press_event (GdkEventButton* ev)
65 {
66         if (ev->type == GDK_BUTTON_PRESS) {
67                 _menu.popup (1, gtk_get_current_event_time());
68         }
69         return true;
70 }
71
72 bool
73 ArdourDropdown::on_scroll_event (GdkEventScroll* ev)
74 {
75         using namespace Menu_Helpers;
76
77         const MenuItem * current_active = _menu.get_active();
78         const MenuList& items = _menu.items ();
79         int c = 0;
80
81         if (!current_active) {
82                 return true;
83         }
84
85         /* work around another gtkmm API clusterfuck
86          * const MenuItem* get_active () const
87          * void set_active (guint index)
88          *
89          * also MenuList.activate_item does not actually
90          * set it as active in the menu.
91          *
92          */
93
94         switch (ev->direction) {
95                 case GDK_SCROLL_UP:
96
97                         for (MenuList::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i, ++c) {
98                                 if ( &(*i) != current_active) {
99                                         continue;
100                                 }
101                                 if (++i != items.rend()) {
102                                         c = items.size() - 2 - c;
103                                         assert(c >= 0);
104                                         _menu.set_active(c);
105                                         _menu.activate_item(*i);
106                                 }
107                                 break;
108                         }
109                         break;
110                 case GDK_SCROLL_DOWN:
111                         for (MenuList::const_iterator i = items.begin(); i != items.end(); ++i, ++c) {
112                                 if ( &(*i) != current_active) {
113                                         continue;
114                                 }
115                                 if (++i != items.end()) {
116                                         assert(c + 1 < (int) items.size());
117                                         _menu.set_active(c + 1);
118                                         _menu.activate_item(*i);
119                                 }
120                                 break;
121                         }
122                         break;
123                 default:
124                         break;
125         }
126         return true;
127 }
128
129 void
130 ArdourDropdown::clear_items ()
131 {
132         _menu.items ().clear ();
133 }
134
135 void
136 ArdourDropdown::AddMenuElem (Menu_Helpers::Element e)
137 {
138         using namespace Menu_Helpers;
139
140         MenuList& items = _menu.items ();
141
142         items.push_back (e);
143 }
144
145