[gtk+/gtk-style-context] Make gtk_style_context_lookup_color handle memory like gtk_style_context_get()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-style-context] Make gtk_style_context_lookup_color handle memory like gtk_style_context_get()
- Date: Wed, 1 Dec 2010 18:20:32 +0000 (UTC)
commit 5279095cfd14747b5ba422dd9ae6fef4d9f7c6ce
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Dec 1 19:02:54 2010 +0100
Make gtk_style_context_lookup_color handle memory like gtk_style_context_get()
docs/reference/gtk/migrating-GtkStyleContext.xml | 7 ++-----
gtk/gtkicontheme.c | 17 +++++++++++++----
gtk/gtkinfobar.c | 13 ++++++++++---
gtk/gtkstyle.c | 17 ++++++++++-------
gtk/gtkstylecontext.c | 19 +++++++++++++------
gtk/gtkstylecontext.h | 6 +++---
6 files changed, 51 insertions(+), 28 deletions(-)
---
diff --git a/docs/reference/gtk/migrating-GtkStyleContext.xml b/docs/reference/gtk/migrating-GtkStyleContext.xml
index 775fee0..c211c8c 100644
--- a/docs/reference/gtk/migrating-GtkStyleContext.xml
+++ b/docs/reference/gtk/migrating-GtkStyleContext.xml
@@ -372,7 +372,7 @@
and the code looks like this:
<informalexample><programlisting>
GdkRGBA *color1;
- GdkRGBA color2;
+ GdkRGBA *color2;
gtk_style_context_get (context, GTK_STATE_FLAG_PRELIGHT,
"background-color", &color1,
@@ -382,11 +382,8 @@
...
gdk_rgba_free (color1);
+ gdk_rgba_free (color2);
</programlisting></informalexample>
- Note that the memory handling here is different: gtk_style_context_get()
- expects the address of a GdkRGBA* and returns a newly allocated struct,
- gtk_style_context_lookup_color() expects the address of an existing
- struct, and fills it.
</para>
<para>
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index c4cefe6..765f153 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -3274,7 +3274,7 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
{
GdkPixbuf *pixbuf;
GdkRGBA *color = NULL;
- GdkRGBA rgba;
+ GdkRGBA *rgba;
gchar *css_fg = NULL, *css_success;
gchar *css_warning, *css_error;
GtkStateFlags state;
@@ -3301,13 +3301,22 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
css_success = css_warning = css_error = NULL;
if (gtk_style_context_lookup_color (context, "success_color", &rgba))
- css_success = gdk_rgba_to_css (&rgba);
+ {
+ css_success = gdk_rgba_to_css (rgba);
+ gdk_rgba_free (rgba);
+ }
if (gtk_style_context_lookup_color (context, "warning_color", &rgba))
- css_warning = gdk_rgba_to_css (&rgba);
+ {
+ css_warning = gdk_rgba_to_css (rgba);
+ gdk_rgba_free (rgba);
+ }
if (gtk_style_context_lookup_color (context, "error_color", &rgba))
- css_error = gdk_rgba_to_css (&rgba);
+ {
+ css_error = gdk_rgba_to_css (rgba);
+ gdk_rgba_free (rgba);
+ }
pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info,
css_fg, css_success,
diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c
index a787960..9346676 100644
--- a/gtk/gtkinfobar.c
+++ b/gtk/gtkinfobar.c
@@ -506,7 +506,7 @@ gtk_info_bar_update_colors (GtkInfoBar *info_bar)
GdkRGBA other_default_border_color = { 0.71, 0.67, 0.61, 1.0 };
GdkRGBA other_default_fill_color = { 0.99, 0.99, 0.74, 1.0 };
GdkRGBA *fg, *bg;
- GdkRGBA sym_fg, sym_bg;
+ GdkRGBA *sym_fg, *sym_bg;
GdkRGBA *color, *bg_color;
GtkStyleContext *context;
@@ -526,12 +526,13 @@ gtk_info_bar_update_colors (GtkInfoBar *info_bar)
};
context = gtk_widget_get_style_context (widget);
+ sym_fg = sym_bg = NULL;
if (gtk_style_context_lookup_color (context, fg_color_name[priv->message_type], &sym_fg) &&
gtk_style_context_lookup_color (context, bg_color_name[priv->message_type], &sym_bg))
{
- fg = &sym_fg;
- bg = &sym_bg;
+ fg = sym_fg;
+ bg = sym_bg;
}
else
{
@@ -580,6 +581,12 @@ gtk_info_bar_update_colors (GtkInfoBar *info_bar)
gdk_rgba_free (color);
gdk_rgba_free (bg_color);
+
+ if (sym_fg)
+ gdk_rgba_free (sym_fg);
+
+ if (sym_bg)
+ gdk_rgba_free (sym_bg);
}
static void
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index 3310ebb..e84cc14 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -1051,8 +1051,7 @@ gtk_style_lookup_color (GtkStyle *style,
GdkColor *color)
{
GtkStylePrivate *priv;
- gboolean result;
- GdkRGBA rgba;
+ GdkRGBA *rgba;
g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
g_return_val_if_fail (color_name != NULL, FALSE);
@@ -1063,17 +1062,21 @@ gtk_style_lookup_color (GtkStyle *style,
if (!priv->context)
return FALSE;
- result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
+ if (!gtk_style_context_lookup_color (priv->context, color_name, &rgba))
+ return FALSE;
if (color)
{
- color->red = (guint16) (rgba.red * 65535);
- color->green = (guint16) (rgba.green * 65535);
- color->blue = (guint16) (rgba.blue * 65535);
+ color->red = (guint16) (rgba->red * 65535);
+ color->green = (guint16) (rgba->green * 65535);
+ color->blue = (guint16) (rgba->blue * 65535);
color->pixel = 0;
}
- return result;
+ if (rgba)
+ gdk_rgba_free (rgba);
+
+ return TRUE;
}
/**
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 6525540..9f4f84b 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -2709,24 +2709,25 @@ gtk_style_context_get_junction_sides (GtkStyleContext *context)
* gtk_style_context_lookup_color:
* @context: a #GtkStyleContext
* @color_name: color name to lookup
- * @color: (out): Return location for the looked up color
+ * @color: (out) (transfer full): Return location for the looked up color
*
* Looks up and resolves a color name in the @context color map.
+ * The returned color must be freed with gdk_rgba_free().
*
* Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
**/
gboolean
-gtk_style_context_lookup_color (GtkStyleContext *context,
- const gchar *color_name,
- GdkRGBA *color)
+gtk_style_context_lookup_color (GtkStyleContext *context,
+ const gchar *color_name,
+ GdkRGBA **color)
{
GtkStyleContextPrivate *priv;
GtkSymbolicColor *sym_color;
StyleData *data;
+ GdkRGBA c;
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
g_return_val_if_fail (color_name != NULL, FALSE);
- g_return_val_if_fail (color != NULL, FALSE);
priv = context->priv;
g_return_val_if_fail (priv->widget_path != NULL, FALSE);
@@ -2737,7 +2738,13 @@ gtk_style_context_lookup_color (GtkStyleContext *context,
if (!sym_color)
return FALSE;
- return gtk_symbolic_color_resolve (sym_color, data->store, color);
+ if (!gtk_symbolic_color_resolve (sym_color, data->store, &c))
+ return FALSE;
+
+ if (color)
+ *color = gdk_rgba_copy (&c);
+
+ return TRUE;
}
/**
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index b2dd734..d24ffb4 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -407,9 +407,9 @@ void gtk_style_context_set_junction_sides (GtkStyleContext *context
GtkJunctionSides sides);
GtkJunctionSides gtk_style_context_get_junction_sides (GtkStyleContext *context);
-gboolean gtk_style_context_lookup_color (GtkStyleContext *context,
- const gchar *color_name,
- GdkRGBA *color);
+gboolean gtk_style_context_lookup_color (GtkStyleContext *context,
+ const gchar *color_name,
+ GdkRGBA **color);
void gtk_style_context_notify_state_change (GtkStyleContext *context,
GdkWindow *window,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]