2 Copyright (C) 2014 Paul Davis
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.
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.
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.
24 #include <pangomm/layout.h>
26 #include "pbd/compose.h"
27 #include "pbd/error.h"
28 #include "pbd/stacktrace.h"
30 #include "gtkmm2ext/utils.h"
31 #include "gtkmm2ext/rgb_macros.h"
32 #include "gtkmm2ext/gui_thread.h"
34 #include "ardour/rc_configuration.h" // for widget prelight preference
36 #include "ardour_dropdown.h"
40 #define REFLECTION_HEIGHT 2
49 ArdourDropdown::ArdourDropdown (Element e)
50 : _scrolling_disabled(false)
52 // signal_button_press_event().connect (sigc::mem_fun(*this, &ArdourDropdown::on_mouse_pressed));
53 _menu.signal_size_request().connect (sigc::mem_fun(*this, &ArdourDropdown::menu_size_request));
55 _menu.set_reserve_toggle_size(false);
58 add_elements(ArdourButton::Menu);
61 ArdourDropdown::~ArdourDropdown ()
66 ArdourDropdown::menu_size_request(Requisition *req) {
67 req->width = max(req->width, get_allocation().get_width());
71 ArdourDropdown::on_button_press_event (GdkEventButton* ev)
73 if (ev->type == GDK_BUTTON_PRESS) {
74 Gtkmm2ext::anchored_menu_popup(&_menu, this, get_text(), 1, ev->time);
80 ArdourDropdown::on_scroll_event (GdkEventScroll* ev)
82 using namespace Menu_Helpers;
84 if (_scrolling_disabled) {
88 const MenuItem * current_active = _menu.get_active();
89 const MenuList& items = _menu.items ();
92 if (!current_active) {
96 /* work around another gtkmm API clusterfuck
97 * const MenuItem* get_active () const
98 * void set_active (guint index)
100 * also MenuList.activate_item does not actually
101 * set it as active in the menu.
105 switch (ev->direction) {
108 for (MenuList::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i, ++c) {
109 if ( &(*i) != current_active) {
112 if (++i != items.rend()) {
113 c = items.size() - 2 - c;
116 _menu.activate_item(*i);
121 case GDK_SCROLL_DOWN:
122 for (MenuList::const_iterator i = items.begin(); i != items.end(); ++i, ++c) {
123 if ( &(*i) != current_active) {
126 if (++i != items.end()) {
127 assert(c + 1 < (int) items.size());
128 _menu.set_active(c + 1);
129 _menu.activate_item(*i);
141 ArdourDropdown::clear_items ()
143 _menu.items ().clear ();
147 ArdourDropdown::AddMenuElem (Menu_Helpers::Element e)
149 using namespace Menu_Helpers;
151 MenuList& items = _menu.items ();
157 ArdourDropdown::disable_scrolling()
159 _scrolling_disabled = true;