widget: Reshuffle code for style context getter

The intention of this patch is to make the code clearer, shorter and
most of all to avoid recreating the widget path and setting it path
twice on the style context when the style context was recreated.
This commit is contained in:
Benjamin Otte 2011-03-26 16:07:54 +01:00
parent 757087e9b4
commit 963c0905f2

View File

@ -14330,15 +14330,23 @@ style_context_changed (GtkStyleContext *context,
GtkStyleContext *
gtk_widget_get_style_context (GtkWidget *widget)
{
GtkWidgetPrivate *priv;
GtkWidgetPath *path;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
if (G_UNLIKELY (!widget->priv->context))
priv = widget->priv;
/* updates style context if it exists already */
path = gtk_widget_get_path (widget);
if (G_UNLIKELY (priv->context == NULL))
{
GdkScreen *screen;
widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
"direction", gtk_widget_get_direction (widget),
NULL);
priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
"direction", gtk_widget_get_direction (widget),
NULL);
g_signal_connect (widget->priv->context, "changed",
G_CALLBACK (style_context_changed), widget);
@ -14346,18 +14354,9 @@ gtk_widget_get_style_context (GtkWidget *widget)
screen = gtk_widget_get_screen (widget);
if (screen)
gtk_style_context_set_screen (widget->priv->context, screen);
gtk_style_context_set_screen (priv->context, screen);
_gtk_widget_update_path (widget);
gtk_style_context_set_path (widget->priv->context,
widget->priv->path);
}
else
{
/* Force widget path regeneration if needed, the
* context will be updated within this function.
*/
gtk_widget_get_path (widget);
gtk_style_context_set_path (priv->context, path);
}
return widget->priv->context;