+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);
+
+ }
+}
+