#include "gtkmain.h"
#include "gtksettings.h"
#include "gtkprivate.h"
-#include "gtkalias.h"
#define DEFAULT_THEME_NAME "hicolor"
/* Information about the source
*/
gchar *filename;
-#ifdef G_OS_WIN32
- /* System codepage version of filename, for DLL ABI backward
- * compatibility functions.
- */
- gchar *cp_filename;
-#endif
GLoadableIcon *loadable;
+ GSList *emblem_infos;
/* Cache pixbuf (if there is any) */
GdkPixbuf *cache_pixbuf;
*
* Gets the icon theme for the default screen. See
* gtk_icon_theme_get_for_screen().
- *
- * Return value: A unique #GtkIconTheme associated with
+ *
+ * Return value: (transfer none): A unique #GtkIconTheme associated with
* the default screen. This icon theme is associated with
* the screen and can be used as long as the screen
* is open. Do not ref or unref it.
* is usually a better choice than calling than gtk_icon_theme_new()
* and setting the screen yourself; by using this function
* a single icon theme object will be shared between users.
- *
- * Return value: A unique #GtkIconTheme associated with
+ *
+ * Return value: (transfer none): A unique #GtkIconTheme associated with
* the given screen. This icon theme is associated with
* the screen and can be used as long as the screen
* is open. Do not ref or unref it.
GtkIconThemePrivate *priv;
const gchar * const *xdg_data_dirs;
int i, j;
-
- priv = g_type_instance_get_private ((GTypeInstance *)icon_theme,
- GTK_TYPE_ICON_THEME);
+
+ priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_theme,
+ GTK_TYPE_ICON_THEME,
+ GtkIconThemePrivate);
icon_theme->priv = priv;
priv->custom_theme = FALSE;
/**
* gtk_icon_theme_get_search_path:
* @icon_theme: a #GtkIconTheme
- * @path: location to store a list of icon theme path directories or %NULL
+ * @path: (allow-none): (array length=n_elements) (out): location to store a list of icon theme path directories or %NULL
* The stored value should be freed with g_strfreev().
* @n_elements: location to store number of elements
* in @path, or %NULL
icon_info->filename = g_strdup (unthemed_icon->svg_filename);
else if (unthemed_icon->no_svg_filename)
icon_info->filename = g_strdup (unthemed_icon->no_svg_filename);
-#ifdef G_OS_WIN32
- icon_info->cp_filename = g_locale_from_utf8 (icon_info->filename,
- -1, NULL, NULL, NULL);
-#endif
icon_info->dir_type = ICON_THEME_DIR_UNTHEMED;
icon_info->dir_size = size;
* @icon_theme: a #GtkIconTheme
* @icon_name: the name of the icon to lookup
* @size: the desired icon size. The resulting icon may not be
- * exactly this size; see gtk_icon_info_load_icon().
+ * exactly this size; see gtk_icon_info_load_icon().
* @flags: flags modifying the behavior of the icon lookup
- * @error: Location to store error information on failure, or %NULL.
- *
+ * @error: (allow-none): Location to store error information on failure,
+ * or %NULL.
+ *
* Looks up an icon in an icon theme, scales it to the given size
* and renders it into a pixbuf. This is a convenience function;
* if more details about the icon are needed, use
* gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().
*
* Note that you probably want to listen for icon theme changes and
- * update the icon. This is usually done by connecting to the
+ * update the icon. This is usually done by connecting to the
* GtkWidget::style-set signal. If for some reason you do not want to
* update the icon when the icon theme changes, you should consider
* using gdk_pixbuf_copy() to make a private copy of the pixbuf
- * returned by this function. Otherwise GTK+ may need to keep the old
+ * returned by this function. Otherwise GTK+ may need to keep the old
* icon theme loaded, which would be a waste of memory.
- *
- * Return value: the rendered icon; this may be a newly created icon
- * or a new reference to an internal icon, so you must not modify
- * the icon. Use g_object_unref() to release your reference to the
- * icon. %NULL if the icon isn't found.
+ *
+ * Return value: (transfer full): the rendered icon; this may be a
+ * newly created icon or a new reference to an internal icon, so
+ * you must not modify the icon. Use g_object_unref() to release
+ * your reference to the icon. %NULL if the icon isn't found.
*
* Since: 2.4
**/
GList *l;
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), FALSE);
-
+ g_return_val_if_fail (icon_name != NULL, FALSE);
+
priv = icon_theme->priv;
ensure_valid_themes (icon_theme);
* The set of values for the context string is system dependent,
* but will typically include such values as "Applications" and
* "MimeTypes".
- *
- * Return value: a #GList list holding the names of all the
+ *
+ * Return value: (element-type utf8) (transfer none): a #GList list holding the names of all the
* icons in the theme. You must first free each element
* in the list with g_free(), then free the list itself
* with g_list_free().
* Gets the list of contexts available within the current
* hierarchy of icon themes
*
- * Return value: a #GList list holding the names of all the
+ * Return value: (element-type utf8) (transfer full): a #GList list holding the names of all the
* contexts in the theme. You must first free each element
* in the list with g_free(), then free the list itself
* with g_list_free().
file = g_strconcat (icon_name, string_from_suffix (suffix), NULL);
icon_info->filename = g_build_filename (min_dir->dir, file, NULL);
g_free (file);
-#ifdef G_OS_WIN32
- icon_info->cp_filename = g_locale_from_utf8 (icon_info->filename,
- -1, NULL, NULL, NULL);
-#endif
}
else
{
icon_info->filename = NULL;
-#ifdef G_OS_WIN32
- icon_info->cp_filename = NULL;
-#endif
}
if (min_dir->icon_data != NULL)
/*
* GtkIconInfo
*/
-GType
-gtk_icon_info_get_type (void)
-{
- static GType our_type = 0;
-
- if (our_type == 0)
- our_type = g_boxed_type_register_static (I_("GtkIconInfo"),
- (GBoxedCopyFunc) gtk_icon_info_copy,
- (GBoxedFreeFunc) gtk_icon_info_free);
-
- return our_type;
-}
+G_DEFINE_BOXED_TYPE (GtkIconInfo, gtk_icon_info,
+ gtk_icon_info_copy,
+ gtk_icon_info_free)
static GtkIconInfo *
icon_info_new (void)
return;
g_free (icon_info->filename);
-#ifdef G_OS_WIN32
- g_free (icon_info->cp_filename);
-#endif
if (icon_info->loadable)
g_object_unref (icon_info->loadable);
+ g_slist_foreach (icon_info->emblem_infos, (GFunc)gtk_icon_info_free, NULL);
+ g_slist_free (icon_info->emblem_infos);
if (icon_info->pixbuf)
g_object_unref (icon_info->pixbuf);
if (icon_info->cache_pixbuf)
* GTK+ to use built in icon images, you must pass the
* %GTK_ICON_LOOKUP_USE_BUILTIN to
* gtk_icon_theme_lookup_icon().
- *
- * Return value: the built-in image pixbuf, or %NULL. No
+ *
+ * Return value: (transfer none): the built-in image pixbuf, or %NULL. No
* extra reference is added to the returned pixbuf, so if
* you want to keep it around, you must use g_object_ref().
* The returned image must not be modified.
return icon_info->cache_pixbuf;
}
+static gboolean icon_info_ensure_scale_and_pixbuf (GtkIconInfo*, gboolean);
+
+/* Combine the icon with all emblems, the first emblem is placed
+ * in the southeast corner. Scale emblems to be at most 3/4 of the
+ * size of the icon itself.
+ */
+static void
+apply_emblems (GtkIconInfo *info)
+{
+ GdkPixbuf *icon = NULL;
+ gint w, h, pos;
+ GSList *l;
+
+ if (info->emblem_infos == NULL)
+ return;
+
+ w = gdk_pixbuf_get_width (info->pixbuf);
+ h = gdk_pixbuf_get_height (info->pixbuf);
+
+ for (l = info->emblem_infos, pos = 0; l; l = l->next, pos++)
+ {
+ GtkIconInfo *emblem_info = l->data;
+
+ if (icon_info_ensure_scale_and_pixbuf (emblem_info, FALSE))
+ {
+ GdkPixbuf *emblem = emblem_info->pixbuf;
+ gint ew, eh;
+ gint x = 0, y = 0; /* silence compiler */
+ gdouble scale;
+
+ ew = gdk_pixbuf_get_width (emblem);
+ eh = gdk_pixbuf_get_height (emblem);
+ if (ew >= w)
+ {
+ scale = 0.75;
+ ew = ew * 0.75;
+ eh = eh * 0.75;
+ }
+ else
+ scale = 1.0;
+
+ switch (pos % 4)
+ {
+ case 0:
+ x = w - ew;
+ y = h - eh;
+ break;
+ case 1:
+ x = w - ew;
+ y = 0;
+ break;
+ case 2:
+ x = 0;
+ y = h - eh;
+ break;
+ case 3:
+ x = 0;
+ y = 0;
+ break;
+ }
+
+ if (icon == NULL)
+ {
+ icon = gdk_pixbuf_copy (info->pixbuf);
+ if (icon == NULL)
+ break;
+ }
+
+ gdk_pixbuf_composite (emblem, icon, x, y, ew, eh, x, y,
+ scale, scale, GDK_INTERP_BILINEAR, 255);
+ }
+ }
+
+ if (icon)
+ {
+ g_object_unref (info->pixbuf);
+ info->pixbuf = icon;
+ }
+}
+
/* This function contains the complicated logic for deciding
* on the size at which to load the icon and loading it at
* that size.
g_object_unref (stream);
}
- return icon_info->pixbuf != NULL;
+ if (!icon_info->pixbuf)
+ return FALSE;
+
+ apply_emblems (icon_info);
+
+ return TRUE;
}
/* In many cases, the scale can be determined without actual access
g_object_unref (source_pixbuf);
}
+ apply_emblems (icon_info);
+
return TRUE;
}
/**
* gtk_icon_info_load_icon:
* @icon_info: a #GtkIconInfo structure from gtk_icon_theme_lookup_icon()
- * @error: location to store error information on failure, or %NULL.
- *
+ * @error: (allow-none): location to store error information on failure,
+ * or %NULL.
+ *
* Renders an icon previously looked up in an icon theme using
* gtk_icon_theme_lookup_icon(); the size will be based on the size
* passed to gtk_icon_theme_lookup_icon(). Note that the resulting
* up too far. (This maintains sharpness.). This behaviour can be changed
* by passing the %GTK_ICON_LOOKUP_FORCE_SIZE flag when obtaining
* the #GtkIconInfo. If this flag has been specified, the pixbuf
- * returned by this function will be scaled to the exact size.
- *
- * Return value: the rendered icon; this may be a newly created icon
- * or a new reference to an internal icon, so you must not modify
- * the icon. Use g_object_unref() to release your reference to the
- * icon.
+ * returned by this function will be scaled to the exact size.
+ *
+ * Return value: (transfer full): the rendered icon; this may be a newly
+ * created icon or a new reference to an internal icon, so you must
+ * not modify the icon. Use g_object_unref() to release your reference
+ * to the icon.
*
* Since: 2.4
**/
if (icon_info->load_error)
g_propagate_error (error, icon_info->load_error);
else
- g_set_error (error,
- GTK_ICON_THEME_ERROR,
- GTK_ICON_THEME_NOT_FOUND,
- _("Failed to load icon"));
+ g_set_error_literal (error,
+ GTK_ICON_THEME_ERROR,
+ GTK_ICON_THEME_NOT_FOUND,
+ _("Failed to load icon"));
return NULL;
}
return g_object_ref (icon_info->pixbuf);
}
+static gchar *
+gdk_color_to_css (GdkColor *color)
+{
+ return g_strdup_printf ("rgb(%d,%d,%d)",
+ color->red >> 8,
+ color->green >> 8,
+ color->blue >> 8);
+}
+
+/**
+ * gtk_icon_info_load_symbolic:
+ * @icon_info: a #GtkIconInfo
+ * @fg: a #GdkColor representing the foreground color of the icon
+ * @success_color: (allow-none): a #GdkColor representing the warning color
+ * of the icon or %NULL to use the default color
+ * @warning_color: (allow-none): a #GdkColor representing the warning color
+ * of the icon or %NULL to use the default color
+ * @error_color: (allow-none): a #GdkColor representing the error color
+ * of the icon or %NULL to use the default color (allow-none)
+ * @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.
+ *
+ * Unless you are implementing a widget, you will want to use
+ * g_themed_icon_new_with_default_fallbacks() to load the icon.
+ *
+ * As implementation details, the icon loaded needs to be of SVG type,
+ * contain the "symbolic" term as the last component of the icon name,
+ * and use the 'fg', 'success', 'warning' and 'error' CSS styles in the
+ * SVG file itself.
+ *
+ * See the <ulink url="http://www.freedesktop.org/wiki/SymbolicIcons">Symbolic Icons spec</ulink>
+ * for more information about symbolic icons.
+ *
+ * Return value: (transfer full): a #GdkPixbuf representing the loaded icon
+ *
+ * Since: 3.0
+ **/
+GdkPixbuf *
+gtk_icon_info_load_symbolic (GtkIconInfo *icon_info,
+ GdkColor *fg,
+ GdkColor *success_color,
+ GdkColor *warning_color,
+ GdkColor *error_color,
+ gboolean *was_symbolic,
+ GError **error)
+{
+ GdkPixbuf *pixbuf;
+ GInputStream *stream;
+ gchar *data;
+ gchar *css_fg;
+ gchar *css_success;
+ gchar *css_warning;
+ gchar *css_error;
+
+ g_return_val_if_fail (fg != NULL, NULL);
+
+ 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;
+
+ css_fg = gdk_color_to_css (fg);
+ if (!warning_color)
+ {
+ GdkColor warning_default_color = { 0, 0xf500, 0x7900, 0x3e00 };
+ css_warning = gdk_color_to_css (&warning_default_color);
+ }
+ else
+ css_warning = gdk_color_to_css (warning_color);
+ if (!error_color)
+ {
+ GdkColor error_default_color = { 0, 0xcc00, 0x0000, 0x0000 };
+ css_error = gdk_color_to_css (&error_default_color);
+ }
+ else
+ css_error = gdk_color_to_css (error_color);
+ if (!success_color)
+ {
+ GdkColor success_default_color = { 0, 0x4e00, 0x9a00, 0x0600 };
+ css_success = gdk_color_to_css (&success_default_color);
+ }
+ else
+ css_success = gdk_color_to_css (success_color);
+
+ data = g_strconcat (
+"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
+"<svg version=\"1.1\"\n"
+" xmlns=\"http://www.w3.org/2000/svg\"\n"
+" xmlns:xi=\"http://www.w3.org/2001/XInclude\"\n"
+" width=\"16\"\n"
+" height=\"16\">\n"
+" <style type=\"text/css\">\n"
+" rect,path {\n"
+" fill: ", css_fg," !important;\n"
+" }\n"
+" .warning {\n"
+" fill: ", css_warning," !important;\n"
+" }\n"
+" .error {\n"
+" fill: ", css_error," !important;\n"
+" }\n"
+" .success {\n"
+" fill: ", css_success," !important;\n"
+" }\n"
+" </style>\n"
+" <xi:include href=\"", icon_info->filename, "\"/>\n"
+"</svg>",
+ NULL);
+ g_free (css_fg);
+ g_free (css_warning);
+ g_free (css_success);
+ g_free (css_error);
+
+ stream = g_memory_input_stream_new_from_data (data, -1, g_free);
+
+ pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,
+ icon_info->desired_size,
+ icon_info->desired_size,
+ TRUE,
+ NULL,
+ error);
+ g_object_unref (stream);
+
+ 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: (transfer full): 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
/**
* gtk_icon_info_get_attach_points:
* @icon_info: a #GtkIconInfo
- * @points: location to store pointer to an array of points, or %NULL
+ * @points: (allow-none): (array length=n_points) (out): location to store pointer to an array of points, or %NULL
* free the array of points with g_free().
- * @n_points: location to store the number of points in @points, or %NULL
+ * @n_points: (allow-none): location to store the number of points in @points, or %NULL
*
* Fetches the set of attach points for an icon. An attach point
* is a location in the icon that can be used as anchor points for attaching
}
}
+
/**
* gtk_icon_theme_lookup_by_gicon:
* @icon_theme: a #GtkIconTheme
return info;
}
+ else if (G_IS_EMBLEMED_ICON (icon))
+ {
+ GIcon *base, *emblem;
+ GList *list, *l;
+ GtkIconInfo *emblem_info;
+
+ base = g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon));
+ info = gtk_icon_theme_lookup_by_gicon (icon_theme, base, size, flags);
+ if (info)
+ {
+ list = g_emblemed_icon_get_emblems (G_EMBLEMED_ICON (icon));
+ for (l = list; l; l = l->next)
+ {
+ emblem = g_emblem_get_icon (G_EMBLEM (l->data));
+ emblem_info = gtk_icon_theme_lookup_by_gicon (icon_theme, emblem, size / 2, flags);
+ if (emblem_info)
+ info->emblem_infos = g_slist_prepend (info->emblem_infos, emblem_info);
+ }
+ }
+
+ return info;
+ }
return NULL;
}
* @icon_theme: a #GtkIconTheme
* @pixbuf: the pixbuf to wrap in a #GtkIconInfo
*
- * Creates a #GtkIconInfo for a #GtkPixbuf.
+ * Creates a #GtkIconInfo for a #GdkPixbuf.
*
* Returns: a #GtkIconInfo
*
return info;
}
-
-#ifdef G_OS_WIN32
-
-/* DLL ABI stability backward compatibility versions */
-
-#undef gtk_icon_theme_set_search_path
-
-void
-gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme,
- const gchar *path[],
- gint n_elements)
-{
- const gchar **utf8_path;
- gint i;
-
- utf8_path = g_new (const gchar *, n_elements);
-
- for (i = 0; i < n_elements; i++)
- utf8_path[i] = g_locale_to_utf8 (path[i], -1, NULL, NULL, NULL);
-
- gtk_icon_theme_set_search_path_utf8 (icon_theme, utf8_path, n_elements);
-
- for (i = 0; i < n_elements; i++)
- g_free ((gchar *) utf8_path[i]);
-
- g_free (utf8_path);
-}
-
-#undef gtk_icon_theme_get_search_path
-
-void
-gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme,
- gchar **path[],
- gint *n_elements)
-{
- gint i, n;
-
- gtk_icon_theme_get_search_path_utf8 (icon_theme, path, &n);
-
- if (n_elements)
- *n_elements = n;
-
- if (path)
- {
- for (i = 0; i < n; i++)
- {
- gchar *tem = (*path)[i];
-
- (*path)[i] = g_locale_from_utf8 ((*path)[i], -1, NULL, NULL, NULL);
- g_free (tem);
- }
- }
-}
-
-#undef gtk_icon_theme_append_search_path
-
-void
-gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme,
- const gchar *path)
-{
- gchar *utf8_path = g_locale_from_utf8 (path, -1, NULL, NULL, NULL);
-
- gtk_icon_theme_append_search_path_utf8 (icon_theme, utf8_path);
-
- g_free (utf8_path);
-}
-
-#undef gtk_icon_theme_prepend_search_path
-
-void
-gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme,
- const gchar *path)
-{
- gchar *utf8_path = g_locale_from_utf8 (path, -1, NULL, NULL, NULL);
-
- gtk_icon_theme_prepend_search_path_utf8 (icon_theme, utf8_path);
-
- g_free (utf8_path);
-}
-
-#undef gtk_icon_info_get_filename
-
-G_CONST_RETURN gchar *
-gtk_icon_info_get_filename (GtkIconInfo *icon_info)
-{
- g_return_val_if_fail (icon_info != NULL, NULL);
-
- return icon_info->cp_filename;
-}
-
-#endif
-
-#define __GTK_ICON_THEME_C__
-#include "gtkaliasdef.c"