Ardour  9.0-pre0-1699-gfaebc7ab35
metabutton.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2025 Robin Gareus <robin@gareus.org>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include <ytkmm/menu.h>
22 #include <ytkmm/menuitem.h>
23 
24 #include "widgets/ardour_button.h"
25 #include "widgets/visibility.h"
26 
27 namespace ArdourWidgets {
28 
30 {
31 public:
33  virtual ~MetaButton ();
34 
35  void add_item (std::string const& label, std::string const& menutext, sigc::slot<void> const&);
36  void add_item (std::string const& label, std::string const& menutext, Gtk::Menu&, sigc::slot<void> const&);
37  void clear_items ();
38 
39  void set_active (std::string const&);
40  void set_index (guint);
41  void set_by_menutext (std::string const & mt);
42 
43  guint index () const
44  {
45  return _active;
46  }
47 
48  Gtk::Menu& menu() { return _menu; }
49 
51 
53  {
54  _scrolling_disabled = true;
55  }
56 
57 protected:
62  void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
63 
64 private:
65  class MetaMenuItem : public Gtk::MenuItem
66  {
67  public:
68  MetaMenuItem (std::string const& label, std::string const& menutext, sigc::slot<void> const& cb)
69  : Gtk::MenuItem (menutext, false)
70  , _label (label)
71  , _cb (cb)
72  {
73  }
74 
75  MetaMenuItem (std::string const& label, std::string const& menutext, sigc::slot<void> const & cb, Gtk::Menu& submenu)
76  : Gtk::MenuItem (menutext, false)
77  , _label (label)
78  , _cb (cb)
79  {
80  set_submenu (submenu);
81  }
82 
83  void activate () const
84  {
85  _cb ();
86  }
87 
88  std::string label () const
89  {
90  return _label;
91  }
92 
93  std::string menutext () const
94  {
95  return get_label ();
96  }
97 
98  private:
99  std::string _label;
100  sigc::slot<void> _cb;
101  };
102 
104  {
105  public:
106  typedef sigc::slot<void, MetaMenuItem const*> SlotActivate;
107 
108  MetaElement (std::string const& label, std::string const& menutext, sigc::slot<void> const& cb, SlotActivate const& wrap)
109  : Gtk::Menu_Helpers::MenuElem ("")
110  {
111  MetaMenuItem* mmi = manage (new MetaMenuItem (label, menutext, cb));
112  child_->unreference ();
113  set_child (mmi);
114  child_->signal_activate ().connect (sigc::bind (wrap, mmi));
115  child_->show ();
116  }
117  MetaElement (std::string const& label, std::string const & menutext, sigc::slot<void> const & cb, SlotActivate const & wrap, Gtk::Menu& submenu)
118  : Gtk::Menu_Helpers::MenuElem ("")
119  {
120  MetaMenuItem* mmi = manage (new MetaMenuItem (label, menutext, cb, submenu));
121  child_->unreference ();
122  set_child (mmi);
123  child_->signal_activate ().connect (sigc::bind (wrap, mmi));
124  child_->show ();
125  }
126 
127  };
128 
131 
133  guint _active;
136 };
137 
138 } // namespace ArdourWidgets
MetaElement(std::string const &label, std::string const &menutext, sigc::slot< void > const &cb, SlotActivate const &wrap)
Definition: metabutton.h:108
sigc::slot< void, MetaMenuItem const * > SlotActivate
Definition: metabutton.h:106
MetaElement(std::string const &label, std::string const &menutext, sigc::slot< void > const &cb, SlotActivate const &wrap, Gtk::Menu &submenu)
Definition: metabutton.h:117
MetaMenuItem(std::string const &label, std::string const &menutext, sigc::slot< void > const &cb, Gtk::Menu &submenu)
Definition: metabutton.h:75
MetaMenuItem(std::string const &label, std::string const &menutext, sigc::slot< void > const &cb)
Definition: metabutton.h:68
bool on_scroll_event(GdkEventScroll *)
This is a default handler for the signal signal_scroll_event().
void add_item(std::string const &label, std::string const &menutext, Gtk::Menu &, sigc::slot< void > const &)
void set_active(std::string const &)
bool on_motion_notify_event(GdkEventMotion *)
This is a default handler for the signal signal_motion_notify_event().
void menu_size_request(Gtk::Requisition *)
void add_item(std::string const &label, std::string const &menutext, sigc::slot< void > const &)
void set_by_menutext(std::string const &mt)
void render(Cairo::RefPtr< Cairo::Context > const &, cairo_rectangle_t *)
bool on_button_press_event(GdkEventButton *)
This is a default handler for the signal signal_button_press_event().
void update_button(MetaMenuItem const *)
void activate_item(MetaMenuItem const *)
bool is_menu_popup_event(GdkEventButton *ev) const
Definition: ardour_ui.h:192
T * manage(T *obj)
Definition: object.h:58
#define LIBWIDGETS_API