Make "button" class depend on mode for GtkToggleButtons

This commit is contained in:
Carlos Garnacho 2010-11-19 19:56:25 +01:00
parent 84d586043e
commit 756e20f58c
2 changed files with 12 additions and 9 deletions

View File

@ -93,18 +93,9 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
static void
gtk_check_button_init (GtkCheckButton *check_button)
{
GtkStyleContext *context;
gtk_widget_set_has_window (GTK_WIDGET (check_button), FALSE);
gtk_widget_set_receives_default (GTK_WIDGET (check_button), FALSE);
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (check_button), TRUE);
/* Remove the "button" class added in GtkButton constructor,
* since this widget implementation doesn't look like a button
* at all.
*/
context = gtk_widget_get_style_context (GTK_WIDGET (check_button));
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BUTTON);
}
GtkWidget*

View File

@ -329,6 +329,8 @@ gtk_toggle_button_set_mode (GtkToggleButton *toggle_button,
if (priv->draw_indicator != draw_indicator)
{
GtkStyleContext *context;
priv->draw_indicator = draw_indicator;
GTK_BUTTON (toggle_button)->priv->depress_on_activate = !draw_indicator;
@ -336,6 +338,16 @@ gtk_toggle_button_set_mode (GtkToggleButton *toggle_button,
gtk_widget_queue_resize (GTK_WIDGET (toggle_button));
g_object_notify (G_OBJECT (toggle_button), "draw-indicator");
/* Make toggle buttons conditionally have the "button"
* class depending on draw_indicator.
*/
context = gtk_widget_get_style_context (GTK_WIDGET (toggle_button));
if (draw_indicator)
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BUTTON);
else
gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
}
}