Replace positioning function with popup helper
authorJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Mon, 15 Aug 2016 23:57:58 +0000 (01:57 +0200)
committerJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Tue, 16 Aug 2016 23:45:47 +0000 (01:45 +0200)
Because all uses of the function positioning menus anchored to a widget
were as callback argument to Gtk::Menu::popup() where the caller needed
to correctly bind arguments, this led to repeated and a bit obscure code.

Wrap the logic into an helper function that takes care of all that, and
update the callers.

gtk2_ardour/ardour_dropdown.cc
gtk2_ardour/ardour_dropdown.h
gtk2_ardour/generic_pluginui.cc
libs/gtkmm2ext/gtkmm2ext/utils.h
libs/gtkmm2ext/utils.cc

index 741db8c2ce3fc85466374511b12db8a033c37396..6c527f2d27b356721bbc7cd71ab5c51fa24ba5db 100644 (file)
@@ -67,17 +67,11 @@ ArdourDropdown::menu_size_request(Requisition *req) {
        req->width = max(req->width, get_allocation().get_width());
 }
 
-void
-ArdourDropdown::position_menu(int& x, int& y, bool& push_in) {
-    Gtkmm2ext::position_menu_anchored (&_menu, this, get_text(), x, y, push_in);
-}
-
 bool
 ArdourDropdown::on_button_press_event (GdkEventButton* ev)
 {
        if (ev->type == GDK_BUTTON_PRESS) {
-               _menu.popup (sigc::mem_fun(this, &ArdourDropdown::position_menu),
-                            1, ev->time);
+               Gtkmm2ext::anchored_menu_popup(&_menu, this, get_text(), 1, ev->time);
        }
        return true;
 }
index 5a710ec539c8d8350e5074f9f043fe923b48bf2e..c50304046dcd1ec5b1230eb0bb3a0977d6310adb 100644 (file)
@@ -38,7 +38,6 @@ class ArdourDropdown : public ArdourButton
 
        bool on_button_press_event (GdkEventButton*);
        bool on_scroll_event (GdkEventScroll*);
-       void position_menu(int&, int&, bool&);
        void menu_size_request(Gtk::Requisition*);
 
        void clear_items ();
index 7832dcfbfeb18205cf53fbf0fc795734e62e03e9..d1accfdd12539f63b6eadc13f898b000376d4a35 100644 (file)
@@ -955,9 +955,7 @@ GenericPluginUI::astate_clicked (ControlUI* cui)
        items.push_back (MenuElem (_("Touch"),
                                   sigc::bind (sigc::mem_fun(*this, &GenericPluginUI::set_automation_state), (AutoState) Touch, cui)));
 
-       automation_menu->popup (
-               boost::bind (&Gtkmm2ext::position_menu_anchored, automation_menu, &cui->automate_button, "", _1, _2, _3),
-               1, gtk_get_current_event_time());
+       anchored_menu_popup(automation_menu, &cui->automate_button, "", 1, gtk_get_current_event_time());
 }
 
 void
index bd09e299123cdc0a8c12ecf1be152921a8a61c67..188da0862d3a01df075c52c7cc6a8124c2c28ef3 100644 (file)
@@ -97,10 +97,10 @@ namespace Gtkmm2ext {
                                                                       int clip_height,
                                                                       Gdk::Color fg);
 
-       LIBGTKMM2EXT_API void position_menu_anchored (const Gtk::Menu* const menu,
-                                                     Gtk::Widget* const anchor,
-                                                     const std::string& selected,
-                                                     int& x, int& y, bool& push_in);
+       LIBGTKMM2EXT_API void anchored_menu_popup (Gtk::Menu* const menu,
+                                                  Gtk::Widget* const anchor,
+                                                  const std::string& selected,
+                                                  guint button, guint32 time);
 
        LIBGTKMM2EXT_API void set_popdown_strings (Gtk::ComboBoxText&,
                                  const std::vector<std::string>&);
index 2b3a29fc0dcff0be39c666bab7e5fae8aabbf8df..4ba85e2f25250ee3bde55bb13653abe3456f31ed 100644 (file)
@@ -310,10 +310,10 @@ Gtkmm2ext::pixbuf_from_string(const string& name, const Pango::FontDescription&
 }
 
 void
-Gtkmm2ext::position_menu_anchored (const Gtk::Menu* const menu,
+_position_menu_anchored (int& x, int& y, bool& push_in,
+                                   const Gtk::Menu* const menu,
                                    Gtk::Widget* const anchor,
-                                   const std::string& selected,
-                                   int& x, int& y, bool& push_in) {
+                                   const std::string& selected) {
        using namespace Gdk;
        using namespace Gtk;
        using namespace Gtk::Menu_Helpers;
@@ -416,6 +416,18 @@ Gtkmm2ext::position_menu_anchored (const Gtk::Menu* const menu,
        push_in = false;
 }
 
+void
+Gtkmm2ext::anchored_menu_popup (Gtk::Menu* const menu,
+                                Gtk::Widget* const anchor,
+                                const std::string& selected,
+                                guint button, guint32 time) {
+       menu->popup(
+               sigc::bind (sigc::ptr_fun(&_position_menu_anchored),
+                           menu, anchor, selected),
+               button,
+               time);
+}
+
 void
 Gtkmm2ext::set_popdown_strings (Gtk::ComboBoxText& cr, const vector<string>& strings)
 {