toggle button: Convert to g_object_notify_by_pspec

This avoids pspec lookup overhead in g_object_notify.
This commit is contained in:
Matthias Clasen 2015-09-06 10:45:33 -04:00
parent 4c376d1a9c
commit 0e4589d902

View File

@ -119,9 +119,11 @@ enum {
PROP_0,
PROP_ACTIVE,
PROP_INCONSISTENT,
PROP_DRAW_INDICATOR
PROP_DRAW_INDICATOR,
NUM_PROPERTIES
};
static GParamSpec *toggle_button_props[NUM_PROPERTIES] = { NULL, };
static gboolean gtk_toggle_button_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling);
@ -173,29 +175,28 @@ gtk_toggle_button_class_init (GtkToggleButtonClass *class)
class->toggled = NULL;
g_object_class_install_property (gobject_class,
PROP_ACTIVE,
g_param_spec_boolean ("active",
P_("Active"),
P_("If the toggle button should be pressed in"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
toggle_button_props[PROP_ACTIVE] =
g_param_spec_boolean ("active",
P_("Active"),
P_("If the toggle button should be pressed in"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_property (gobject_class,
PROP_INCONSISTENT,
g_param_spec_boolean ("inconsistent",
P_("Inconsistent"),
P_("If the toggle button is in an \"in between\" state"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
toggle_button_props[PROP_INCONSISTENT] =
g_param_spec_boolean ("inconsistent",
P_("Inconsistent"),
P_("If the toggle button is in an \"in between\" state"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_property (gobject_class,
PROP_DRAW_INDICATOR,
g_param_spec_boolean ("draw-indicator",
P_("Draw Indicator"),
P_("If the toggle part of the button is displayed"),
FALSE,
GTK_PARAM_READWRITE));
toggle_button_props[PROP_DRAW_INDICATOR] =
g_param_spec_boolean ("draw-indicator",
P_("Draw Indicator"),
P_("If the toggle part of the button is displayed"),
FALSE,
GTK_PARAM_READWRITE);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, toggle_button_props);
/**
* GtkToggleButton::toggled:
@ -414,7 +415,7 @@ gtk_toggle_button_set_mode (GtkToggleButton *toggle_button,
if (gtk_widget_get_visible (GTK_WIDGET (toggle_button)))
gtk_widget_queue_resize (GTK_WIDGET (toggle_button));
g_object_notify (G_OBJECT (toggle_button), "draw-indicator");
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_DRAW_INDICATOR]);
/* Make toggle buttons conditionally have the "button"
* class depending on draw_indicator.
@ -471,7 +472,7 @@ gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
if (priv->active != is_active)
{
gtk_button_clicked (GTK_BUTTON (toggle_button));
g_object_notify (G_OBJECT (toggle_button), "active");
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_ACTIVE]);
}
}
@ -557,7 +558,7 @@ gtk_toggle_button_set_inconsistent (GtkToggleButton *toggle_button,
else
gtk_widget_unset_state_flags (GTK_WIDGET (toggle_button), GTK_STATE_FLAG_INCONSISTENT);
g_object_notify (G_OBJECT (toggle_button), "inconsistent");
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_INCONSISTENT]);
}
}
@ -605,7 +606,7 @@ gtk_toggle_button_clicked (GtkButton *button)
gtk_toggle_button_toggled (toggle_button);
g_object_notify (G_OBJECT (toggle_button), "active");
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_ACTIVE]);
if (GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked)
GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked (button);