mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 22:10:08 +00:00
stylecontext: Get rid of gtk_style_context_get()
... and replace all the calls to it with gtk_style_context_peek_property(). All the calls are hacks that need to go away btw.
This commit is contained in:
parent
43339f1c1c
commit
632fab0ca7
@ -4801,12 +4801,9 @@ GtkStyleContext
|
||||
gtk_style_context_new
|
||||
gtk_style_context_add_provider
|
||||
gtk_style_context_add_provider_for_display
|
||||
gtk_style_context_get
|
||||
gtk_style_context_get_parent
|
||||
gtk_style_context_get_property
|
||||
gtk_style_context_get_display
|
||||
gtk_style_context_get_state
|
||||
gtk_style_context_get_valist
|
||||
gtk_style_context_get_color
|
||||
gtk_style_context_get_border
|
||||
gtk_style_context_get_padding
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "gtkcellrenderertext.h"
|
||||
|
||||
#include "gtkcssnumbervalueprivate.h"
|
||||
#include "gtkeditable.h"
|
||||
#include "gtkentry.h"
|
||||
#include "gtkentryprivate.h"
|
||||
@ -27,7 +28,7 @@
|
||||
#include "gtkprivate.h"
|
||||
#include "gtksizerequest.h"
|
||||
#include "gtksnapshot.h"
|
||||
#include "gtkstylecontext.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
#include "gtktreeprivate.h"
|
||||
|
||||
#include "a11y/gtktextcellaccessible.h"
|
||||
@ -1631,7 +1632,7 @@ get_size (GtkCellRenderer *cell,
|
||||
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
|
||||
gtk_style_context_get (style_context, "font", &font_desc, NULL);
|
||||
font_desc = gtk_css_style_get_pango_font (gtk_style_context_lookup_style (style_context));
|
||||
pango_font_description_merge_static (font_desc, priv->font, TRUE);
|
||||
|
||||
if (priv->scale_set)
|
||||
|
@ -80,6 +80,7 @@
|
||||
#include "gtkadjustment.h"
|
||||
#include "gtkbindings.h"
|
||||
#include "gtkcontainerprivate.h"
|
||||
#include "gtkcsscolorvalueprivate.h"
|
||||
#include "gtkcssnodeprivate.h"
|
||||
#include "gtkgesturedrag.h"
|
||||
#include "gtkgestureclick.h"
|
||||
@ -2385,7 +2386,7 @@ gtk_flow_box_snapshot (GtkWidget *widget,
|
||||
{
|
||||
cairo_path_t *path;
|
||||
GtkBorder border;
|
||||
GdkRGBA *border_color;
|
||||
const GdkRGBA *border_color;
|
||||
|
||||
if (vertical)
|
||||
path_from_vertical_line_rects (cr, (GdkRectangle *)lines->data, lines->len);
|
||||
@ -2405,13 +2406,12 @@ gtk_flow_box_snapshot (GtkWidget *widget,
|
||||
cairo_append_path (cr, path);
|
||||
cairo_path_destroy (path);
|
||||
|
||||
gtk_style_context_get (context, "border-color", &border_color, NULL);
|
||||
border_color = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_COLOR));
|
||||
gtk_style_context_get_border (context, &border);
|
||||
|
||||
cairo_set_line_width (cr, border.left);
|
||||
gdk_cairo_set_source_rgba (cr, border_color);
|
||||
cairo_stroke (cr);
|
||||
gdk_rgba_free (border_color);
|
||||
}
|
||||
g_array_free (lines, TRUE);
|
||||
|
||||
|
@ -36,8 +36,8 @@
|
||||
#include "gdk/gdkkeysyms.h"
|
||||
#include "gdk/win32/gdkwin32.h"
|
||||
#include "gtk/gtkimmodule.h"
|
||||
|
||||
#include <pango/pango.h>
|
||||
#include "gtk/gtkstylecontextprivate.h"
|
||||
#include "gtk/gtkcssstyleprivate.h"
|
||||
|
||||
/* avoid warning */
|
||||
#ifdef STRICT
|
||||
@ -869,7 +869,6 @@ gtk_im_context_ime_set_preedit_font (GtkIMContext *context)
|
||||
PangoContext *pango_context;
|
||||
PangoFont *font;
|
||||
LOGFONT *logfont;
|
||||
GtkStyleContext *style;
|
||||
PangoFontDescription *font_desc;
|
||||
|
||||
g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
|
||||
@ -923,11 +922,7 @@ gtk_im_context_ime_set_preedit_font (GtkIMContext *context)
|
||||
lang = ""; break;
|
||||
}
|
||||
|
||||
style = gtk_widget_get_style_context (widget);
|
||||
gtk_style_context_get (style,
|
||||
"font",
|
||||
&font_desc,
|
||||
NULL);
|
||||
font_desc = gtk_css_style_get_pango_font (gtk_style_context_lookup_style (gtk_widget_get_style_context (widget)));
|
||||
|
||||
if (lang[0])
|
||||
{
|
||||
|
@ -617,142 +617,6 @@ gtk_style_context_remove_provider_for_display (GdkDisplay *display,
|
||||
_gtk_style_cascade_remove_provider (cascade, provider);
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
gtk_style_context_query_func (guint id,
|
||||
gpointer values)
|
||||
{
|
||||
return gtk_css_style_get_value (values, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_context_get_property:
|
||||
* @context: a #GtkStyleContext
|
||||
* @property: style property name
|
||||
* @value: (out) (transfer full): return location for the style property value
|
||||
*
|
||||
* Gets a style property from @context for the current state.
|
||||
*
|
||||
* Note that not all CSS properties that are supported by GTK+ can be
|
||||
* retrieved in this way, since they may not be representable as #GValue.
|
||||
* GTK+ defines macros for a number of properties that can be used
|
||||
* with this function.
|
||||
*
|
||||
* When @value is no longer needed, g_value_unset() must be called
|
||||
* to free any allocated memory.
|
||||
**/
|
||||
void
|
||||
gtk_style_context_get_property (GtkStyleContext *context,
|
||||
const gchar *property,
|
||||
GValue *value)
|
||||
{
|
||||
GtkStyleContextPrivate *priv = gtk_style_context_get_instance_private (context);
|
||||
GtkStyleProperty *prop;
|
||||
|
||||
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
||||
g_return_if_fail (property != NULL);
|
||||
g_return_if_fail (value != NULL);
|
||||
|
||||
prop = _gtk_style_property_lookup (property);
|
||||
if (prop == NULL)
|
||||
{
|
||||
g_warning ("Style property \"%s\" is not registered", property);
|
||||
return;
|
||||
}
|
||||
if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
|
||||
{
|
||||
g_warning ("Style property \"%s\" is not gettable", property);
|
||||
return;
|
||||
}
|
||||
|
||||
_gtk_style_property_query (prop,
|
||||
value,
|
||||
gtk_style_context_query_func,
|
||||
gtk_css_node_get_style (priv->cssnode));
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_context_get_valist:
|
||||
* @context: a #GtkStyleContext
|
||||
* @first_property_name: Name of the first property
|
||||
* @args: va_list of property name/return location pairs, followed by %NULL
|
||||
*
|
||||
* Retrieves several style property values from @context for a given state.
|
||||
*
|
||||
* See gtk_style_context_get_property() for details.
|
||||
*
|
||||
* As with g_object_get(), a copy is made of the property contents for
|
||||
* pointer-valued properties, and the caller is responsible for freeing the
|
||||
* memory in the appropriate manner for the type. For example, by calling
|
||||
* g_free() or g_object_unref(). Non-pointer-valued properties, such as
|
||||
* integers, are returned by value and do not need to be freed.
|
||||
*/
|
||||
void
|
||||
gtk_style_context_get_valist (GtkStyleContext *context,
|
||||
const char *first_property_name,
|
||||
va_list args)
|
||||
{
|
||||
const gchar *property_name;
|
||||
|
||||
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
||||
g_return_if_fail (first_property_name != NULL);
|
||||
|
||||
property_name = first_property_name;
|
||||
|
||||
while (property_name)
|
||||
{
|
||||
gchar *error = NULL;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
gtk_style_context_get_property (context,
|
||||
property_name,
|
||||
&value);
|
||||
|
||||
G_VALUE_LCOPY (&value, args, 0, &error);
|
||||
g_value_unset (&value);
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_warning ("Could not get style property \"%s\": %s", property_name, error);
|
||||
g_free (error);
|
||||
break;
|
||||
}
|
||||
|
||||
property_name = va_arg (args, const gchar *);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_context_get:
|
||||
* @context: a #GtkStyleContext
|
||||
* @first_property_name: Name of the first property
|
||||
* @...: property name /return value pairs, followed by %NULL
|
||||
*
|
||||
* Retrieves several style property values from @context for a
|
||||
* given state.
|
||||
*
|
||||
* See gtk_style_context_get_property() for details.
|
||||
*
|
||||
* As with g_object_get(), a copy is made of the property contents for
|
||||
* pointer-valued properties, and the caller is responsible for freeing the
|
||||
* memory in the appropriate manner for the type. For example, by calling
|
||||
* g_free() or g_object_unref(). Non-pointer-valued properties, such as
|
||||
* integers, are returned by value and do not need to be freed.
|
||||
*/
|
||||
void
|
||||
gtk_style_context_get (GtkStyleContext *context,
|
||||
const char *first_property_name,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
||||
g_return_if_fail (first_property_name != NULL);
|
||||
|
||||
va_start (args, first_property_name);
|
||||
gtk_style_context_get_valist (context, first_property_name, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
/*
|
||||
* gtk_style_context_set_id:
|
||||
* @context: a #GtkStyleContext
|
||||
@ -1317,17 +1181,10 @@ void
|
||||
gtk_style_context_get_color (GtkStyleContext *context,
|
||||
GdkRGBA *color)
|
||||
{
|
||||
GdkRGBA *c;
|
||||
|
||||
g_return_if_fail (color != NULL);
|
||||
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
||||
|
||||
gtk_style_context_get (context,
|
||||
"color", &c,
|
||||
NULL);
|
||||
|
||||
*color = *c;
|
||||
gdk_rgba_free (c);
|
||||
*color = *gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1432,20 +1289,11 @@ _gtk_style_context_get_cursor_color (GtkStyleContext *context,
|
||||
GdkRGBA *primary_color,
|
||||
GdkRGBA *secondary_color)
|
||||
{
|
||||
GdkRGBA *pc, *sc;
|
||||
|
||||
gtk_style_context_get (context,
|
||||
"caret-color", &pc,
|
||||
"-gtk-secondary-caret-color", &sc,
|
||||
NULL);
|
||||
if (primary_color)
|
||||
*primary_color = *pc;
|
||||
*primary_color = *gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_CARET_COLOR));
|
||||
|
||||
if (secondary_color)
|
||||
*secondary_color = *sc;
|
||||
|
||||
gdk_rgba_free (pc);
|
||||
gdk_rgba_free (sc);
|
||||
*secondary_color = *gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_SECONDARY_CARET_COLOR));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1827,26 +1675,22 @@ AtkAttributeSet *
|
||||
_gtk_style_context_get_attributes (AtkAttributeSet *attributes,
|
||||
GtkStyleContext *context)
|
||||
{
|
||||
GdkRGBA *bg;
|
||||
GdkRGBA color;
|
||||
const GdkRGBA *color;
|
||||
gchar *value;
|
||||
|
||||
gtk_style_context_get (context, "background-color", &bg, NULL);
|
||||
color = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
|
||||
value = g_strdup_printf ("%u,%u,%u",
|
||||
(guint) ceil (bg->red * 65536 - bg->red),
|
||||
(guint) ceil (bg->green * 65536 - bg->green),
|
||||
(guint) ceil (bg->blue * 65536 - bg->blue));
|
||||
(guint) ceil (color->red * 65536 - color->red),
|
||||
(guint) ceil (color->green * 65536 - color->green),
|
||||
(guint) ceil (color->blue * 65536 - color->blue));
|
||||
attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
|
||||
g_free (value);
|
||||
gdk_rgba_free (bg);
|
||||
|
||||
gtk_style_context_get_color (context, &color);
|
||||
color = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
|
||||
value = g_strdup_printf ("%u,%u,%u",
|
||||
(guint) ceil (color.red * 65536 - color.red),
|
||||
(guint) ceil (color.green * 65536 - color.green),
|
||||
(guint) ceil (color.blue * 65536 - color.blue));
|
||||
(guint) ceil (color->red * 65536 - color->red),
|
||||
(guint) ceil (color->green * 65536 - color->green),
|
||||
(guint) ceil (color->blue * 65536 - color->blue));
|
||||
attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);
|
||||
g_free (value);
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
@ -874,19 +874,6 @@ void gtk_style_context_save (GtkStyleContext *context);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_style_context_restore (GtkStyleContext *context);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_style_context_get_property (GtkStyleContext *context,
|
||||
const gchar *property,
|
||||
GValue *value);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_style_context_get_valist (GtkStyleContext *context,
|
||||
const char *first_property_name,
|
||||
va_list args);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_style_context_get (GtkStyleContext *context,
|
||||
const char *first_property_name,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_style_context_set_state (GtkStyleContext *context,
|
||||
GtkStateFlags flags);
|
||||
|
@ -16,6 +16,8 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkcssnumbervalueprivate.h"
|
||||
#include "gtkprivatetypebuiltins.h"
|
||||
#include "gtktexthandleprivate.h"
|
||||
#include "gtkmarshalers.h"
|
||||
@ -25,6 +27,7 @@
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkgizmoprivate.h"
|
||||
#include "gtkrendericonprivate.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
#include "gtkintl.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
@ -89,11 +92,9 @@ _gtk_text_handle_get_size (GtkTextHandle *handle,
|
||||
GtkStyleContext *context;
|
||||
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
|
||||
gtk_style_context_get (context,
|
||||
"min-width", width,
|
||||
"min-height", height,
|
||||
NULL);
|
||||
|
||||
*width = _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_MIN_WIDTH), 100);
|
||||
*height = _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_MIN_HEIGHT), 100);
|
||||
}
|
||||
|
||||
static gint
|
||||
|
@ -76,9 +76,12 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtktextlayoutprivate.h"
|
||||
|
||||
#include "gtkcsscolorvalueprivate.h"
|
||||
#include "gtkmarshalers.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
#include "gtktextlayoutprivate.h"
|
||||
#include "gtktextbtree.h"
|
||||
#include "gtktextbufferprivate.h"
|
||||
#include "gtktextiterprivate.h"
|
||||
@ -3866,7 +3869,7 @@ render_para (GskPangoRenderer *crenderer,
|
||||
int byte_offset = 0;
|
||||
PangoLayoutIter *iter;
|
||||
int screen_width;
|
||||
GdkRGBA *selection = NULL;
|
||||
const GdkRGBA *selection = NULL;
|
||||
gboolean first = TRUE;
|
||||
|
||||
g_return_if_fail (GTK_IS_TEXT_VIEW (crenderer->widget));
|
||||
@ -3880,7 +3883,7 @@ render_para (GskPangoRenderer *crenderer,
|
||||
GtkCssNode *selection_node = gtk_text_view_get_selection_node ((GtkTextView*)crenderer->widget);
|
||||
gtk_style_context_save_to_node (context, selection_node);
|
||||
|
||||
gtk_style_context_get (context, "background-color", &selection, NULL);
|
||||
selection = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
|
||||
|
||||
gtk_style_context_restore (context);
|
||||
}
|
||||
@ -4066,7 +4069,6 @@ render_para (GskPangoRenderer *crenderer,
|
||||
if (offset_y)
|
||||
gtk_snapshot_restore (crenderer->snapshot);
|
||||
|
||||
gdk_rgba_free (selection);
|
||||
pango_layout_iter_free (iter);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include "gtktextview.h"
|
||||
#include "gtktextutil.h"
|
||||
|
||||
#include "gtkcsscolorvalueprivate.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
#include "gtktextbuffer.h"
|
||||
#include "gtktextlayoutprivate.h"
|
||||
#include "gtkintl.h"
|
||||
@ -139,39 +141,26 @@ gtk_text_util_create_drag_icon (GtkWidget *widget,
|
||||
return paintable;
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
query_func (guint id, gpointer values)
|
||||
{
|
||||
return gtk_css_style_get_value (values, id);
|
||||
}
|
||||
|
||||
static void
|
||||
set_attributes_from_style (GtkWidget *widget,
|
||||
GtkTextAttributes *values)
|
||||
{
|
||||
GtkCssStyle *style;
|
||||
GtkStyleContext *context;
|
||||
const GdkRGBA black = { 0, };
|
||||
const GdkRGBA *color;
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
if (!values->appearance.bg_rgba)
|
||||
values->appearance.bg_rgba = gdk_rgba_copy (&black);
|
||||
if (!values->appearance.fg_rgba)
|
||||
values->appearance.fg_rgba = gdk_rgba_copy (&black);
|
||||
|
||||
style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
|
||||
color = gtk_css_color_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
|
||||
*values->appearance.bg_rgba = *color;
|
||||
color = gtk_css_color_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
|
||||
*values->appearance.fg_rgba = *color;
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
*values->appearance.bg_rgba = *gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
|
||||
*values->appearance.fg_rgba = *gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
|
||||
|
||||
if (values->font)
|
||||
pango_font_description_free (values->font);
|
||||
|
||||
_gtk_style_property_query (_gtk_style_property_lookup ("font"), &value, query_func, style);
|
||||
|
||||
values->font = g_value_get_boxed (&value);
|
||||
g_value_unset (&value);
|
||||
values->font = gtk_css_style_get_pango_font (gtk_style_context_lookup_style (context));
|
||||
}
|
||||
|
||||
static gint
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include "gtkadjustmentprivate.h"
|
||||
#include "gtkbindings.h"
|
||||
#include "gtkcsscolorvalueprivate.h"
|
||||
#include "gtkdebug.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtkmain.h"
|
||||
@ -7437,7 +7438,7 @@ gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
const GdkRGBA black = { 0, };
|
||||
GdkRGBA *bg;
|
||||
const GdkRGBA *color;
|
||||
|
||||
if (!values->appearance.bg_rgba)
|
||||
values->appearance.bg_rgba = gdk_rgba_copy (&black);
|
||||
@ -7446,15 +7447,15 @@ gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
|
||||
|
||||
context = gtk_widget_get_style_context (GTK_WIDGET (text_view));
|
||||
|
||||
gtk_style_context_get (context, "background-color", &bg, NULL);
|
||||
*values->appearance.bg_rgba = *bg;
|
||||
gdk_rgba_free (bg);
|
||||
gtk_style_context_get_color (context, values->appearance.fg_rgba);
|
||||
color = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
|
||||
*values->appearance.bg_rgba = *color;
|
||||
color = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
|
||||
*values->appearance.fg_rgba = *color;
|
||||
|
||||
if (values->font)
|
||||
pango_font_description_free (values->font);
|
||||
|
||||
gtk_style_context_get (context, "font", &values->font, NULL);
|
||||
values->font = gtk_css_style_get_pango_font (gtk_style_context_lookup_style (context));
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user