diff options
author | David Robillard <d@drobilla.net> | 2011-11-24 05:36:31 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-11-24 05:36:31 +0000 |
commit | 0a71d52448f6144d5225269b378711bfba0bb37b (patch) | |
tree | d40c810164b7c6d85c80e006a08d9459564ed6fb | |
parent | 0bd3105f50f3c82586e0924a4be9977425caaf90 (diff) |
Fix key bindings in tooltips for ArdourButton buttons.
Sinced gtkmm2ext needs to get at the actions of widgets, I moved the
action to Gtkmm2ext::Activatable. Not sure if the wisest thing to
do here would be to use Gtkmm::Activatable, but figured there's
a reason Paul didn't do so (the name set_related_action is from there
so presumably it's known about), so this is the simplest change
that allows access to the action in Gtkmm2ext. The vfunc calling
stuff should probably move there as well...
git-svn-id: svn://localhost/ardour2/branches/3.0@10818 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | gtk2_ardour/ardour_button.cc | 16 | ||||
-rw-r--r-- | gtk2_ardour/ardour_button.h | 18 | ||||
-rw-r--r-- | libs/gtkmm2ext/gtk_ui.cc | 23 | ||||
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/activatable.h | 51 |
4 files changed, 82 insertions, 26 deletions
diff --git a/gtk2_ardour/ardour_button.cc b/gtk2_ardour/ardour_button.cc index ca0a1c38c0..778be28f20 100644 --- a/gtk2_ardour/ardour_button.cc +++ b/gtk2_ardour/ardour_button.cc @@ -53,7 +53,6 @@ ArdourButton::Element ArdourButton::just_led_default_elements = ArdourButton::El ArdourButton::ArdourButton (Element e) : _elements (e) , _tweaks (Tweaks (0)) - , _act_on_release (true) , _text_width (0) , _text_height (0) , _diameter (11.0) @@ -62,10 +61,11 @@ ArdourButton::ArdourButton (Element e) , fill_pattern (0) , led_inset_pattern (0) , reflection_pattern (0) + , _led_rect (0) + , _act_on_release (true) , _led_left (false) , _fixed_diameter (true) , _distinct_led_click (false) - , _led_rect (0) , _hovering (false) { ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler)); @@ -73,7 +73,6 @@ ArdourButton::ArdourButton (Element e) ArdourButton::ArdourButton (const std::string& str, Element e) : _elements (e) - , _act_on_release (true) , _text_width (0) , _text_height (0) , _diameter (11.0) @@ -82,10 +81,11 @@ ArdourButton::ArdourButton (const std::string& str, Element e) , fill_pattern (0) , led_inset_pattern (0) , reflection_pattern (0) + , _led_rect (0) + , _act_on_release (true) , _led_left (false) , _fixed_diameter (true) , _distinct_led_click (false) - , _led_rect (0) , _hovering (false) { set_text (str); @@ -535,14 +535,11 @@ ArdourButton::controllable_changed () void ArdourButton::set_related_action (RefPtr<Action> act) { - _action = act; + Gtkmm2ext::Activatable::set_related_action (act); if (_action) { - string str = _action->property_tooltip().get_value(); - if (!str.empty()) { - ARDOUR_UI::instance()->set_tip (*this, str); - } + action_tooltip_changed (); Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action); if (tact) { @@ -698,4 +695,3 @@ ArdourButton::action_tooltip_changed () string str = _action->property_tooltip().get_value(); ARDOUR_UI::instance()->set_tip (*this, str); } - diff --git a/gtk2_ardour/ardour_button.h b/gtk2_ardour/ardour_button.h index fb0f8320a1..695d31e419 100644 --- a/gtk2_ardour/ardour_button.h +++ b/gtk2_ardour/ardour_button.h @@ -27,10 +27,11 @@ #include "pbd/signals.h" #include "gtkmm2ext/binding_proxy.h" +#include "gtkmm2ext/activatable.h" #include "cairo_widget.h" -class ArdourButton : public CairoWidget +class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable { public: enum Element { @@ -76,7 +77,7 @@ class ArdourButton : public CairoWidget boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); } void set_controllable (boost::shared_ptr<PBD::Controllable> c); - void watch (); + void watch (); void set_related_action (Glib::RefPtr<Gtk::Action>); @@ -93,8 +94,8 @@ class ArdourButton : public CairoWidget bool on_enter_notify_event (GdkEventCrossing*); bool on_leave_notify_event (GdkEventCrossing*); - void controllable_changed (); - PBD::ScopedConnection watch_connection; + void controllable_changed (); + PBD::ScopedConnection watch_connection; private: Glib::RefPtr<Pango::Layout> _layout; @@ -102,8 +103,7 @@ class ArdourButton : public CairoWidget std::string _text; Element _elements; Tweaks _tweaks; - BindingProxy binding_proxy; - bool _act_on_release; + BindingProxy binding_proxy; int _text_width; int _text_height; @@ -115,6 +115,8 @@ class ArdourButton : public CairoWidget cairo_pattern_t* led_inset_pattern; cairo_pattern_t* reflection_pattern; + cairo_rectangle_t* _led_rect; + double text_r; double text_g; double text_b; @@ -125,18 +127,16 @@ class ArdourButton : public CairoWidget double led_b; double led_a; + bool _act_on_release; bool _led_left; bool _fixed_diameter; bool _distinct_led_click; - cairo_rectangle_t* _led_rect; bool _hovering; void setup_led_rect (); void set_colors (); void color_handler (); - Glib::RefPtr<Gtk::Action> _action; - void action_activated (); void action_toggled (); void action_sensitivity_changed (); diff --git a/libs/gtkmm2ext/gtk_ui.cc b/libs/gtkmm2ext/gtk_ui.cc index 35517e9604..f45fab6788 100644 --- a/libs/gtkmm2ext/gtk_ui.cc +++ b/libs/gtkmm2ext/gtk_ui.cc @@ -40,6 +40,7 @@ #include <gtkmm2ext/utils.h> #include <gtkmm2ext/window_title.h> #include <gtkmm2ext/actions.h> +#include <gtkmm2ext/activatable.h> #include "i18n.h" @@ -340,15 +341,23 @@ UI::set_tip (Widget *w, const gchar *tip, const gchar *hlp) std::string msg(tip); Glib::RefPtr<Gtk::Action> action = w->get_action(); + + if (!action) { + Gtkmm2ext::Activatable* activatable; + if ((activatable = dynamic_cast<Gtkmm2ext::Activatable*>(w))) { + action = activatable->get_related_action(); + } + } + if (action) { Gtk::AccelKey key; - ustring ap = action->get_accel_path(); - if (!ap.empty()) { - bool has_key = ActionManager::lookup_entry(ap, key); - if (has_key && key.get_abbrev() != "") { - msg.append("\n\n Key: ").append(key.get_abbrev()); - } - } + ustring ap = action->get_accel_path(); + if (!ap.empty()) { + bool has_key = ActionManager::lookup_entry(ap, key); + if (has_key && key.get_abbrev() != "") { + msg.append("\n\nKey: ").append(key.get_abbrev()); + } + } } if (req == 0) { diff --git a/libs/gtkmm2ext/gtkmm2ext/activatable.h b/libs/gtkmm2ext/gtkmm2ext/activatable.h new file mode 100644 index 0000000000..f8e2b5dd38 --- /dev/null +++ b/libs/gtkmm2ext/gtkmm2ext/activatable.h @@ -0,0 +1,51 @@ +/* + Copyright (C) 2011 Paul Davis + Author: David Robillard + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __libgtkmm2ext_activatable_h__ +#define __libgtkmm2ext_activatable_h__ + +#include <gtkmm/action.h> + +namespace Gtkmm2ext { + +/** + A Widget with an associated Action. + + Gtkmm itself has a class for this. I don't know why we don't use it. +*/ +class Activatable { +public: + virtual ~Activatable() {} + + virtual void set_related_action(Glib::RefPtr<Gtk::Action> a) { + _action = a; + } + + Glib::RefPtr<Gtk::Action> get_related_action() { + return _action; + } + +protected: + Glib::RefPtr<Gtk::Action> _action; +}; + +} /* namespace */ + +#endif /* __libgtkmm2ext_actions_h__ */ |