diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-03-26 21:24:17 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-03-26 21:24:17 +0000 |
commit | 316fca72dbad5bae530816714de52eadc9d7f243 (patch) | |
tree | 91787da195c44cdce57587b00d2c17b328bcaabe /libs/gtkmm2ext | |
parent | ac5bbf4b99635a71093f859e233ad5fe4b07453b (diff) |
lots of work to hide prelight from most buttons, etc. etc. etc; increase range of solo boost knob; theme RC files changes need propagating to the light theme, sigh
git-svn-id: svn://localhost/ardour2/branches/3.0@6799 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/gtkmm2ext')
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/stateful_button.h | 32 | ||||
-rw-r--r-- | libs/gtkmm2ext/stateful_button.cc | 155 |
2 files changed, 171 insertions, 16 deletions
diff --git a/libs/gtkmm2ext/gtkmm2ext/stateful_button.h b/libs/gtkmm2ext/gtkmm2ext/stateful_button.h index 1ba8ddf6f5..b69dba83fc 100644 --- a/libs/gtkmm2ext/gtkmm2ext/stateful_button.h +++ b/libs/gtkmm2ext/gtkmm2ext/stateful_button.h @@ -40,42 +40,52 @@ class StateButton int visual_state; bool _self_managed; bool _is_realized; + bool style_changing; + Gtk::StateType state_before_prelight; + bool is_toggle; - virtual std::string get_widget_name() const = 0; - virtual void set_widget_name (const std::string&) = 0; - virtual int get_widget_state() = 0; + virtual std::string get_widget_name() const = 0; + virtual void set_widget_name (const std::string& name) = 0; + virtual Gtk::Widget* get_child_widget () = 0; + + void avoid_prelight_on_style_changed (const Glib::RefPtr<Gtk::Style>& style, GtkWidget* widget); + void avoid_prelight_on_state_changed (Gtk::StateType old_state, GtkWidget* widget); }; class StatefulToggleButton : public StateButton, public Gtk::ToggleButton { public: - StatefulToggleButton() {} - explicit StatefulToggleButton(const std::string &label) : Gtk::ToggleButton (label) {} + StatefulToggleButton(); + explicit StatefulToggleButton(const std::string &label); ~StatefulToggleButton() {} protected: void on_realize (); void on_toggled (); + void on_style_changed (const Glib::RefPtr<Gtk::Style>& style); + void on_state_changed (Gtk::StateType old_state); + Gtk::Widget* get_child_widget (); std::string get_widget_name() const { return get_name(); } void set_widget_name (const std::string& name); - int get_widget_state() { return get_state(); } }; class StatefulButton : public StateButton, public Gtk::Button { public: - StatefulButton() {} - explicit StatefulButton(const std::string &label) : Gtk::Button (label) {} + StatefulButton(); + explicit StatefulButton(const std::string &label); virtual ~StatefulButton() {} - + protected: void on_realize (); - + void on_style_changed (const Glib::RefPtr<Gtk::Style>& style); + void on_state_changed (Gtk::StateType old_state); + + Gtk::Widget* get_child_widget (); std::string get_widget_name() const { return get_name(); } void set_widget_name (const std::string& name); - int get_widget_state() { return get_state(); } }; }; diff --git a/libs/gtkmm2ext/stateful_button.cc b/libs/gtkmm2ext/stateful_button.cc index a4503ed863..ea6abdac43 100644 --- a/libs/gtkmm2ext/stateful_button.cc +++ b/libs/gtkmm2ext/stateful_button.cc @@ -20,6 +20,7 @@ #include <string> #include <iostream> + #include <gtkmm/main.h> #include <gtkmm2ext/stateful_button.h> @@ -29,9 +30,14 @@ using namespace Glib; using namespace Gtkmm2ext; using namespace std; -StateButton::StateButton () : visual_state (0), _self_managed (false), _is_realized (false) +StateButton::StateButton () + : visual_state (0) + , _self_managed (false) + , _is_realized (false) + , style_changing (false) + , state_before_prelight (Gtk::STATE_NORMAL) + , is_toggle (false) { - } void @@ -55,8 +61,9 @@ StateButton::set_visual_state (int n) /* relax */ break; case 1: - name += "-active"; + name += "-active"; break; + case 2: name += "-alternate"; break; @@ -67,8 +74,94 @@ StateButton::set_visual_state (int n) visual_state = n; } +void +StateButton::avoid_prelight_on_style_changed (const Glib::RefPtr<Gtk::Style>& /* old_style */, GtkWidget* widget) +{ + /* don't go into an endless recursive loop if we're changing + the style in response to an existing style change. + */ + + if (style_changing) { + return; + } + + if (gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT) { + + /* avoid PRELIGHT: make sure that the prelight colors in this new style match + the colors of the new style in whatever state we were in + before we switched to prelight. + */ + + GtkRcStyle* rcstyle = gtk_widget_get_modifier_style (widget); + GtkStyle* style = gtk_widget_get_style (widget); + + rcstyle->fg[GTK_STATE_PRELIGHT] = style->fg[state_before_prelight]; + rcstyle->bg[GTK_STATE_PRELIGHT] = style->bg[state_before_prelight]; + rcstyle->color_flags[GTK_STATE_PRELIGHT] = (GtkRcFlags) (GTK_RC_FG|GTK_RC_BG); + + style_changing = true; + g_object_ref (rcstyle); + gtk_widget_modify_style (widget, rcstyle); + + Widget* child = get_child_widget(); + if (child) { + gtk_widget_modify_style (GTK_WIDGET(child->gobj()), rcstyle); + } + + g_object_unref (rcstyle); + style_changing = false; + } +} + +void +StateButton::avoid_prelight_on_state_changed (Gtk::StateType old_state, GtkWidget* widget) +{ + GtkStateType state = gtk_widget_get_state (widget); + + if (state == GTK_STATE_PRELIGHT) { + + state_before_prelight = old_state; + + + /* avoid PRELIGHT when currently ACTIVE: + if we just went into PRELIGHT, make sure that the colors + match those of whatever state we were in before. + */ + + GtkRcStyle* rcstyle = gtk_widget_get_modifier_style (widget); + GtkStyle* style = gtk_widget_get_style (widget); + + rcstyle->fg[GTK_STATE_PRELIGHT] = style->fg[old_state]; + rcstyle->bg[GTK_STATE_PRELIGHT] = style->bg[old_state]; + rcstyle->color_flags[GTK_STATE_PRELIGHT] = (GtkRcFlags) (GTK_RC_FG|GTK_RC_BG); + + g_object_ref (rcstyle); + gtk_widget_modify_style (widget, rcstyle); + + Widget* child = get_child_widget (); + + if (child) { + gtk_widget_modify_style (GTK_WIDGET(child->gobj()), rcstyle); + } + + g_object_unref (rcstyle); + + } +} + /* ----------------------------------------------------------------- */ +StatefulToggleButton::StatefulToggleButton () +{ + is_toggle = true; +} + +StatefulToggleButton::StatefulToggleButton (const std::string& label) + : ToggleButton (label) +{ + is_toggle = true; +} + void StatefulToggleButton::on_realize () { @@ -94,13 +187,34 @@ StatefulToggleButton::on_toggled () { if (!_self_managed) { if (get_active()) { - set_visual_state (1); + set_state (Gtk::STATE_ACTIVE); } else { - set_visual_state (0); + set_state (Gtk::STATE_NORMAL); } } } + +void +StatefulToggleButton::on_style_changed (const Glib::RefPtr<Gtk::Style>& style) +{ + avoid_prelight_on_style_changed (style, GTK_WIDGET(gobj())); + Button::on_style_changed (style); +} + +void +StatefulToggleButton::on_state_changed (Gtk::StateType old_state) +{ + avoid_prelight_on_state_changed (old_state, GTK_WIDGET(gobj())); + Button::on_state_changed (old_state); +} + +Widget* +StatefulToggleButton::get_child_widget () +{ + return get_child(); +} + void StatefulToggleButton::set_widget_name (const std::string& name) { @@ -112,6 +226,37 @@ StatefulToggleButton::set_widget_name (const std::string& name) } } +/*--------------------------------------------- */ + +StatefulButton::StatefulButton () +{ +} + +StatefulButton::StatefulButton (const std::string& label) + : Button (label) +{ +} + +void +StatefulButton::on_style_changed (const Glib::RefPtr<Gtk::Style>& style) +{ + avoid_prelight_on_style_changed (style, GTK_WIDGET(gobj())); + Button::on_style_changed (style); +} + +void +StatefulButton::on_state_changed (Gtk::StateType old_state) +{ + avoid_prelight_on_state_changed (old_state, GTK_WIDGET(gobj())); + Button::on_state_changed (old_state); +} + +Widget* +StatefulButton::get_child_widget () +{ + return get_child(); +} + void StatefulButton::set_widget_name (const std::string& name) { |