forked from AuroraMiddleware/gtk
Add a variant of gtk_icon_theme_load_symbolic that takes a style
As proposed by Owen in bug 621578 to reduce code duplication.
This commit is contained in:
parent
d53b0c200d
commit
e9fc660d7e
@ -5679,6 +5679,7 @@ gtk_icon_info_get_filename
|
||||
gtk_icon_info_get_builtin_pixbuf
|
||||
gtk_icon_info_load_icon
|
||||
gtk_icon_info_load_symbolic
|
||||
gtk_icon_info_load_symbolic_for_style
|
||||
gtk_icon_info_set_raw_coordinates
|
||||
gtk_icon_info_get_embedded_rect
|
||||
gtk_icon_info_get_attach_points
|
||||
|
@ -1626,6 +1626,7 @@ gtk_icon_info_get_filename_utf8
|
||||
gtk_icon_info_get_type G_GNUC_CONST
|
||||
gtk_icon_info_load_icon
|
||||
gtk_icon_info_load_symbolic
|
||||
gtk_icon_info_load_symbolic_for_style
|
||||
gtk_icon_info_set_raw_coordinates
|
||||
gtk_icon_theme_add_builtin_icon
|
||||
#ifndef _WIN64
|
||||
|
@ -534,31 +534,15 @@ gtk_cell_renderer_pixbuf_create_themed_pixbuf (GtkCellRendererPixbuf *cellpixbuf
|
||||
|
||||
if (info)
|
||||
{
|
||||
GdkColor error_color, warning_color, success_color;
|
||||
GdkColor *error_ptr, *warning_ptr, *success_ptr;
|
||||
GtkStyle *style;
|
||||
|
||||
style = gtk_widget_get_style (GTK_WIDGET (widget));
|
||||
if (!gtk_style_lookup_color (style, "error_color", &error_color))
|
||||
error_ptr = NULL;
|
||||
else
|
||||
error_ptr = &error_color;
|
||||
if (!gtk_style_lookup_color (style, "warning_color", &warning_color))
|
||||
warning_ptr = NULL;
|
||||
else
|
||||
warning_ptr = &warning_color;
|
||||
if (!gtk_style_lookup_color (style, "success_color", &success_color))
|
||||
success_ptr = NULL;
|
||||
else
|
||||
success_ptr = &success_color;
|
||||
|
||||
cellpixbuf->pixbuf = gtk_icon_info_load_symbolic (info,
|
||||
&style->fg[GTK_STATE_NORMAL],
|
||||
success_ptr,
|
||||
warning_ptr,
|
||||
error_ptr,
|
||||
NULL,
|
||||
NULL);
|
||||
cellpixbuf->pixbuf =
|
||||
gtk_icon_info_load_symbolic_for_style (info,
|
||||
style,
|
||||
GTK_STATE_NORMAL,
|
||||
NULL,
|
||||
NULL);
|
||||
gtk_icon_info_free (info);
|
||||
}
|
||||
|
||||
@ -568,7 +552,7 @@ gtk_cell_renderer_pixbuf_create_themed_pixbuf (GtkCellRendererPixbuf *cellpixbuf
|
||||
static GdkPixbuf *
|
||||
create_symbolic_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
|
||||
GtkWidget *widget,
|
||||
GdkColor *fg)
|
||||
GtkStateType state)
|
||||
{
|
||||
GtkCellRendererPixbufPrivate *priv;
|
||||
GdkScreen *screen;
|
||||
@ -623,34 +607,16 @@ create_symbolic_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
|
||||
|
||||
if (info)
|
||||
{
|
||||
GdkColor error_color, warning_color, success_color;
|
||||
GdkColor *error_ptr, *warning_ptr, *success_ptr;
|
||||
GtkStyle *style;
|
||||
|
||||
style = gtk_widget_get_style (GTK_WIDGET (widget));
|
||||
if (!gtk_style_lookup_color (style, "error_color", &error_color))
|
||||
error_ptr = NULL;
|
||||
else
|
||||
error_ptr = &error_color;
|
||||
if (!gtk_style_lookup_color (style, "warning_color", &warning_color))
|
||||
warning_ptr = NULL;
|
||||
else
|
||||
warning_ptr = &warning_color;
|
||||
if (!gtk_style_lookup_color (style, "success_color", &success_color))
|
||||
success_ptr = NULL;
|
||||
else
|
||||
success_ptr = &success_color;
|
||||
|
||||
pixbuf = gtk_icon_info_load_symbolic (info,
|
||||
fg,
|
||||
success_ptr,
|
||||
warning_ptr,
|
||||
error_ptr,
|
||||
NULL,
|
||||
NULL);
|
||||
pixbuf = gtk_icon_info_load_symbolic_for_style (info,
|
||||
style, state,
|
||||
NULL, NULL);
|
||||
gtk_icon_info_free (info);
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -868,7 +834,7 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
|
||||
else
|
||||
state = GTK_STATE_PRELIGHT;
|
||||
|
||||
symbolic = create_symbolic_pixbuf (cellpixbuf, widget, &widget->style->fg[state]);
|
||||
symbolic = create_symbolic_pixbuf (cellpixbuf, widget, state);
|
||||
if (!symbolic) {
|
||||
colorized = create_colorized_pixbuf (pixbuf,
|
||||
&widget->style->base[state]);
|
||||
|
@ -3219,6 +3219,55 @@ gtk_icon_info_load_symbolic (GtkIconInfo *icon_info,
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_icon_info_load_symbolic_for_style:
|
||||
* @icon_info: a #GtkIconInfo
|
||||
* @style: a #GtkStyle to take the colors from
|
||||
* @state: the widget state to use for colors
|
||||
* @was_symbolic: (allow-none): a #gboolean, returns whether the loaded icon
|
||||
* was a symbolic one and whether the @fg color was applied to it.
|
||||
* @error: (allow-none): location to store error information on failure,
|
||||
* or %NULL.
|
||||
*
|
||||
* Loads an icon, modifying it to match the system colours for the foreground,
|
||||
* success, warning and error colors provided. If the icon is not a symbolic
|
||||
* one, the function will return the result from gtk_icon_info_load_icon().
|
||||
*
|
||||
* This allows loading symbolic icons that will match the system theme.
|
||||
*
|
||||
* See gtk_icon_info_load_symbolic() for more details.
|
||||
*
|
||||
* Return value: a #GdkPixbuf representing the loaded icon
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
GdkPixbuf *
|
||||
gtk_icon_info_load_symbolic_for_style (GtkIconInfo *icon_info,
|
||||
GtkStyle *style,
|
||||
GtkStateType state,
|
||||
gboolean *was_symbolic,
|
||||
GError **error)
|
||||
{
|
||||
GdkColor success_color;
|
||||
GdkColor warning_color;
|
||||
GdkColor error_color;
|
||||
GdkColor *fg;
|
||||
GdkColor *success = NULL;
|
||||
GdkColor *warning = NULL;
|
||||
GdkColor *err = NULL;
|
||||
|
||||
fg = &style->fg[state];
|
||||
if (gtk_style_lookup_color (style, "success_color", &success_color))
|
||||
success = &success_color;
|
||||
if (gtk_style_lookup_color (style, "warning_color", &warning_color))
|
||||
warning = &warning_color;
|
||||
if (gtk_style_lookup_color (style, "error_color", &error_color))
|
||||
err = &error_color;
|
||||
|
||||
return gtk_icon_info_load_symbolic (icon_info, fg, success, warning, err,
|
||||
&was_symbolic, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_icon_info_set_raw_coordinates:
|
||||
* @icon_info: a #GtkIconInfo
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtkstyle.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -186,6 +187,11 @@ GdkPixbuf * gtk_icon_info_load_symbolic (GtkIconInfo *icon_info
|
||||
GdkColor *error_color,
|
||||
gboolean *was_symbolic,
|
||||
GError **error);
|
||||
GdkPixbuf * gtk_icon_info_load_symbolic_for_style (GtkIconInfo *icon_info,
|
||||
GtkStyle *style,
|
||||
GtkStateType state,
|
||||
gboolean *was_symbolic,
|
||||
GError **error);
|
||||
void gtk_icon_info_set_raw_coordinates (GtkIconInfo *icon_info,
|
||||
gboolean raw_coordinates);
|
||||
|
||||
|
@ -1697,32 +1697,15 @@ ensure_pixbuf_for_icon_name (GtkImage *image,
|
||||
MIN (width, height), flags);
|
||||
if (info)
|
||||
{
|
||||
GdkColor error_color, warning_color, success_color;
|
||||
GdkColor *error_ptr, *warning_ptr, *success_ptr;
|
||||
GtkStyle *style;
|
||||
gboolean was_symbolic;
|
||||
|
||||
style = gtk_widget_get_style (GTK_WIDGET (image));
|
||||
if (!gtk_style_lookup_color (style, "error_color", &error_color))
|
||||
error_ptr = NULL;
|
||||
else
|
||||
error_ptr = &error_color;
|
||||
if (!gtk_style_lookup_color (style, "warning_color", &warning_color))
|
||||
warning_ptr = NULL;
|
||||
else
|
||||
warning_ptr = &warning_color;
|
||||
if (!gtk_style_lookup_color (style, "success_color", &success_color))
|
||||
success_ptr = NULL;
|
||||
else
|
||||
success_ptr = &success_color;
|
||||
|
||||
image->data.name.pixbuf = gtk_icon_info_load_symbolic (info,
|
||||
&style->fg[state],
|
||||
success_ptr,
|
||||
warning_ptr,
|
||||
error_ptr,
|
||||
&was_symbolic,
|
||||
NULL);
|
||||
image->data.name.pixbuf =
|
||||
gtk_icon_info_load_symbolic_for_style (info,
|
||||
style, state,
|
||||
&was_symbolic,
|
||||
NULL);
|
||||
priv->was_symbolic = was_symbolic;
|
||||
gtk_icon_info_free (info);
|
||||
}
|
||||
@ -1790,32 +1773,15 @@ ensure_pixbuf_for_gicon (GtkImage *image,
|
||||
MIN (width, height), flags);
|
||||
if (info)
|
||||
{
|
||||
GdkColor error_color, warning_color, success_color;
|
||||
GdkColor *error_ptr, *warning_ptr, *success_ptr;
|
||||
GtkStyle *style;
|
||||
gboolean was_symbolic;
|
||||
|
||||
style = gtk_widget_get_style (GTK_WIDGET (image));
|
||||
if (!gtk_style_lookup_color (style, "error_color", &error_color))
|
||||
error_ptr = NULL;
|
||||
else
|
||||
error_ptr = &error_color;
|
||||
if (!gtk_style_lookup_color (style, "warning_color", &warning_color))
|
||||
warning_ptr = NULL;
|
||||
else
|
||||
warning_ptr = &warning_color;
|
||||
if (!gtk_style_lookup_color (style, "success_color", &success_color))
|
||||
success_ptr = NULL;
|
||||
else
|
||||
success_ptr = &success_color;
|
||||
|
||||
image->data.gicon.pixbuf = gtk_icon_info_load_symbolic (info,
|
||||
&style->fg[state],
|
||||
success_ptr,
|
||||
warning_ptr,
|
||||
error_ptr,
|
||||
&was_symbolic,
|
||||
NULL);
|
||||
image->data.gicon.pixbuf =
|
||||
gtk_icon_info_load_symbolic_for_style (info,
|
||||
style, state,
|
||||
&was_symbolic,
|
||||
NULL);
|
||||
priv->was_symbolic = was_symbolic;
|
||||
gtk_icon_info_free (info);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user