Ardour  9.0-rc1-12-g0f3760a8d1
ardour_dropdown.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017-2018 Robin Gareus <robin@gareus.org>
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 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.
18  */
19 
20 #ifndef _WIDGETS_ARDOUR_DROPDOWN_H_
21 #define _WIDGETS_ARDOUR_DROPDOWN_H_
22 
23 #include <list>
24 #include <stdint.h>
25 
26 #include <ytkmm/action.h>
27 #include <ytkmm/menu.h>
28 #include <ytkmm/menuitem.h>
29 
30 #include "widgets/ardour_button.h"
31 #include "widgets/visibility.h"
32 
33 namespace ArdourWidgets {
34 
36 {
37 public:
38 
39  ArdourDropdown (Element e = default_elements);
40  virtual ~ArdourDropdown ();
41 
45 
46  void clear_items ();
48  void append_text_item (std::string const& text);
49  void add_separator ();
50  void append (Glib::RefPtr<Gtk::Action>);
51  void append (Gtk::Menu&, Glib::RefPtr<Gtk::Action>);
52 
54 
55  Gtk::Menu_Helpers::MenuList& items () { return _menu.items (); }
56  Gtk::Menu& menu () { return _menu; }
57 
58  void set_active (std::string const& text);
59 
60  void set_active (int);
61  int get_active_row_number () const;
62 
63 protected:
64  void default_text_handler (std::string const&);
65 
66 private:
67  class LblMenuItem : public Gtk::MenuItem
68  {
69  public:
70  LblMenuItem (std::string const& label, std::string const& menutext)
71  : Gtk::MenuItem (menutext, false)
72  , _label (label)
73  {
74  }
75 
76  std::string label () const
77  {
78  return _label;
79  }
80 
81  std::string menutext () const
82  {
83  return get_label ();
84  }
85 
86  private:
87  std::string _label;
88  };
89 
91  {
92  public:
93  LblMenuElement (Glib::RefPtr<Gtk::Action> action)
94  : Gtk::Menu_Helpers::MenuElem ("")
95  {
96  LblMenuItem* mmi = manage (new LblMenuItem (action->get_short_label(), action->get_label()));
97  child_->unreference ();
98  set_child (mmi);
99  child_->signal_activate ().connect (sigc::mem_fun (action.get(), &Gtk::Action::activate));
100  child_->show ();
101  }
102  };
103 
105 
107 };
108 
109 } /* end namespace */
110 
111 #endif
LblMenuElement(Glib::RefPtr< Gtk::Action > action)
LblMenuItem(std::string const &label, std::string const &menutext)
void default_text_handler(std::string const &)
void append(Glib::RefPtr< Gtk::Action >)
void append_text_item(std::string const &text)
bool on_button_press_event(GdkEventButton *)
This is a default handler for the signal signal_button_press_event().
void add_menu_elem(Gtk::Menu_Helpers::Element e)
void menu_size_request(Gtk::Requisition *)
Gtk::Menu_Helpers::MenuList & items()
void append(Gtk::Menu &, Glib::RefPtr< Gtk::Action >)
void set_active(std::string const &text)
bool on_scroll_event(GdkEventScroll *)
This is a default handler for the signal signal_scroll_event().
ArdourDropdown(Element e=default_elements)
void activate()
Definition: ardour_ui.h:192
T * manage(T *obj)
Definition: object.h:58
#define LIBWIDGETS_API