forked from AuroraMiddleware/gtk
Add a GtkStyleContext-variant of symbolic icon loading
This commit is contained in:
parent
091c882996
commit
f90881271f
@ -3071,6 +3071,16 @@ gdk_color_to_css (GdkColor *color)
|
||||
color->blue >> 8);
|
||||
}
|
||||
|
||||
static gchar *
|
||||
gdk_rgba_to_css (GdkRGBA *color)
|
||||
{
|
||||
return g_strdup_printf ("rgba(%d,%d,%d,%f)",
|
||||
(gint)(color->red * 255),
|
||||
(gint)(color->green * 255),
|
||||
(gint)(color->blue * 255),
|
||||
color->alpha);
|
||||
}
|
||||
|
||||
static GdkPixbuf *
|
||||
_gtk_icon_info_load_symbolic_internal (GtkIconInfo *icon_info,
|
||||
const gchar *css_fg,
|
||||
@ -3235,6 +3245,88 @@ gtk_icon_info_load_symbolic (GtkIconInfo *icon_info,
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_icon_info_load_symbolic_for_context:
|
||||
* @icon_info: a #GtkIconInfo
|
||||
* context: a #GtkStyleContext
|
||||
* @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 colors 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: (transfer full): a #GdkPixbuf representing the loaded icon
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
GdkPixbuf *
|
||||
gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
|
||||
GtkStyleContext *context,
|
||||
gboolean *was_symbolic,
|
||||
GError **error)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
GdkRGBA *color;
|
||||
gchar *css_fg, *css_success;
|
||||
gchar *css_warning, *css_error;
|
||||
|
||||
if (!icon_info->filename ||
|
||||
!g_str_has_suffix (icon_info->filename, "-symbolic.svg"))
|
||||
{
|
||||
if (was_symbolic)
|
||||
*was_symbolic = FALSE;
|
||||
return gtk_icon_info_load_icon (icon_info, error);
|
||||
}
|
||||
|
||||
if (was_symbolic)
|
||||
*was_symbolic = TRUE;
|
||||
|
||||
if (gtk_style_context_lookup_color (context, "color", color))
|
||||
{
|
||||
css_fg = gdk_rgba_to_css (color);
|
||||
gdk_rgba_free (color);
|
||||
}
|
||||
|
||||
css_success = css_warning = css_error = NULL;
|
||||
|
||||
if (gtk_style_context_lookup_color (context, "success_color", color))
|
||||
{
|
||||
css_success = gdk_rgba_to_css (color);
|
||||
gdk_rgba_free (color);
|
||||
}
|
||||
|
||||
if (gtk_style_context_lookup_color (context, "warning_color", color))
|
||||
{
|
||||
css_warning = gdk_rgba_to_css (color);
|
||||
gdk_rgba_free (color);
|
||||
}
|
||||
|
||||
if (gtk_style_context_lookup_color (context, "error_color", color))
|
||||
{
|
||||
css_error = gdk_rgba_to_css (color);
|
||||
gdk_rgba_free (color);
|
||||
}
|
||||
|
||||
pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info,
|
||||
css_fg, css_success,
|
||||
css_warning, css_error,
|
||||
error);
|
||||
|
||||
g_free (css_fg);
|
||||
g_free (css_success);
|
||||
g_free (css_warning);
|
||||
g_free (css_error);
|
||||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_icon_info_load_symbolic_for_style:
|
||||
* @icon_info: a #GtkIconInfo
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtkstyle.h>
|
||||
#include <gtk/gtkstylecontext.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -178,6 +179,10 @@ GdkPixbuf * gtk_icon_info_load_symbolic (GtkIconInfo *icon_info
|
||||
GdkRGBA *error_color,
|
||||
gboolean *was_symbolic,
|
||||
GError **error);
|
||||
GdkPixbuf * gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
|
||||
GtkStyleContext *context,
|
||||
gboolean *was_symbolic,
|
||||
GError **error);
|
||||
GdkPixbuf * gtk_icon_info_load_symbolic_for_style (GtkIconInfo *icon_info,
|
||||
GtkStyle *style,
|
||||
GtkStateType state,
|
||||
|
Loading…
Reference in New Issue
Block a user