2 * Copyright (C) 2014 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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/menu_elems.h"
32 #include "gtkmm2ext/rgb_macros.h"
33 #include "gtkmm2ext/gui_thread.h"
35 #include "widgets/ardour_dropdown.h"
39 #define REFLECTION_HEIGHT 2
45 using namespace ArdourWidgets;
49 ArdourDropdown::ArdourDropdown (Element e)
50 : _scrolling_disabled(false)
52 _menu.signal_size_request().connect (sigc::mem_fun(*this, &ArdourDropdown::menu_size_request));
54 _menu.set_reserve_toggle_size(false);
57 add_elements(ArdourButton::Menu);
60 ArdourDropdown::~ArdourDropdown ()
65 ArdourDropdown::menu_size_request(Requisition *req) {
66 req->width = max(req->width, get_allocation().get_width());
70 ArdourDropdown::on_button_press_event (GdkEventButton* ev)
72 if (binding_proxy.button_press_handler (ev)) {
76 if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) {
77 Gtkmm2ext::anchored_menu_popup(&_menu, this, get_text(), 1, ev->time);
84 ArdourDropdown::on_scroll_event (GdkEventScroll* ev)
86 using namespace Menu_Helpers;
88 if (_scrolling_disabled) {
92 const MenuItem * current_active = _menu.get_active();
93 const MenuList& items = _menu.items ();
96 if (!current_active) {
100 /* work around another gtkmm API clusterfuck
101 * const MenuItem* get_active () const
102 * void set_active (guint index)
104 * also MenuList.activate_item does not actually
105 * set it as active in the menu.
109 switch (ev->direction) {
112 for (MenuList::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i, ++c) {
113 if ( &(*i) != current_active) {
116 if (++i != items.rend()) {
117 c = items.size() - 2 - c;
120 _menu.activate_item(*i);
125 case GDK_SCROLL_DOWN:
126 for (MenuList::const_iterator i = items.begin(); i != items.end(); ++i, ++c) {
127 if ( &(*i) != current_active) {
130 if (++i != items.end()) {
131 assert(c + 1 < (int) items.size());
132 _menu.set_active(c + 1);
133 _menu.activate_item(*i);
145 ArdourDropdown::clear_items ()
147 _menu.items ().clear ();
151 ArdourDropdown::AddMenuElem (Menu_Helpers::Element e)
153 using namespace Menu_Helpers;
155 MenuList& items = _menu.items ();
161 ArdourDropdown::disable_scrolling()
163 _scrolling_disabled = true;
167 ArdourDropdown::append_text_item (std::string const& text) {
168 using namespace Gtkmm2ext;
169 AddMenuElem (MenuElemNoMnemonic (text, sigc::bind (sigc::mem_fun (*this, &ArdourDropdown::default_text_handler), text)));
173 ArdourDropdown::default_text_handler (std::string const& text) {
175 StateChanged (); /* EMIT SIGNAL */