GtkWidget: Add gtk_widget_get_style_context().

There will be one GtkStyleContext per widget, at the moment its
lifetime is tied to the widget's, but it could be narrowed down
to GTK_WIDGET_REALIZED.
This commit is contained in:
Carlos Garnacho 2010-03-10 00:55:48 +01:00
parent 2e96770e0b
commit 3f93c714ae
2 changed files with 27 additions and 0 deletions

View File

@ -58,6 +58,7 @@
#include "gtkbuildable.h"
#include "gtkbuilderprivate.h"
#include "gtksizerequest.h"
#include "gtkstylecontext.h"
#include "gtkdebug.h"
@ -670,6 +671,7 @@ static GQuark quark_tooltip_markup = 0;
static GQuark quark_has_tooltip = 0;
static GQuark quark_tooltip_window = 0;
static GQuark quark_visual = 0;
static GQuark quark_style_context = 0;
GParamSpecPool *_gtk_widget_child_property_pool = NULL;
GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
@ -783,6 +785,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
quark_visual = g_quark_from_static_string ("gtk-widget-visual");
quark_style_context = g_quark_from_static_string ("gtk-style-context");
style_property_spec_pool = g_param_spec_pool_new (FALSE);
_gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
@ -13161,3 +13164,23 @@ _gtk_widget_set_height_request_needed (GtkWidget *widget,
{
widget->priv->height_request_needed = height_request_needed;
}
GtkStyleContext *
gtk_widget_get_style_context (GtkWidget *widget)
{
GtkStyleContext *context;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
context = g_object_get_qdata (G_OBJECT (widget),
quark_style_context);
if (G_UNLIKELY (!context))
{
context = g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
g_object_set_qdata_full (widget, quark_style_context, context,
(GDestroyNotify) g_object_unref);
}
return context;
}

View File

@ -36,6 +36,7 @@
#include <gtk/gtkadjustment.h>
#include <gtk/gtkstyle.h>
#include <gtk/gtksettings.h>
#include <gtk/gtkstylecontext.h>
#include <atk/atk.h>
G_BEGIN_DECLS
@ -941,6 +942,9 @@ void _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
gboolean gtk_widget_in_destruction (GtkWidget *widget);
GtkStyleContext * gtk_widget_get_style_context (GtkWidget *widget);
G_END_DECLS
#endif /* __GTK_WIDGET_H__ */