X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkiconfactory.c;h=b40267335b0a78c0a1ec613de399e2a2422de375;hb=dc331ccb171151d737112d8dc55b25709271d2c7;hp=5b21c62fd6d1a44e9b5211b6152d1d5bcdc93deb;hpb=0d786985a368d88e8ab4e45fc3607efc5e773732;p=~andy%2Fgtk
diff --git a/gtk/gtkiconfactory.c b/gtk/gtkiconfactory.c
index 5b21c62fd..b40267335 100644
--- a/gtk/gtkiconfactory.c
+++ b/gtk/gtkiconfactory.c
@@ -12,9 +12,7 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see .
*/
/*
@@ -25,19 +23,123 @@
*/
#include "config.h"
+
#include
#include
#include
+
#include "gtkiconfactory.h"
#include "gtkiconcache.h"
#include "gtkdebug.h"
#include "gtkicontheme.h"
-#include "gtksettings.h"
+#include "gtksettingsprivate.h"
#include "gtkstock.h"
#include "gtkwidget.h"
#include "gtkintl.h"
#include "gtkbuildable.h"
#include "gtkbuilderprivate.h"
+#include "gtktypebuiltins.h"
+#include "deprecated/gtkstyle.h"
+
+
+/**
+ * SECTION:gtkiconfactory
+ * @Short_description: Manipulating stock icons
+ * @Title: Themeable Stock Images
+ *
+ * Browse the available stock icons in the list of stock IDs found here. You can also use
+ * the gtk-demo application for this purpose.
+ *
+ * An icon factory manages a collection of #GtkIconSet; a #GtkIconSet manages a
+ * set of variants of a particular icon (i.e. a #GtkIconSet contains variants for
+ * different sizes and widget states). Icons in an icon factory are named by a
+ * stock ID, which is a simple string identifying the icon. Each #GtkStyle has a
+ * list of #GtkIconFactory derived from the current theme; those icon factories
+ * are consulted first when searching for an icon. If the theme doesn't set a
+ * particular icon, GTK+ looks for the icon in a list of default icon factories,
+ * maintained by gtk_icon_factory_add_default() and
+ * gtk_icon_factory_remove_default(). Applications with icons should add a default
+ * icon factory with their icons, which will allow themes to override the icons
+ * for the application.
+ *
+ * To display an icon, always use gtk_style_lookup_icon_set() on the widget that
+ * will display the icon, or the convenience function
+ * gtk_widget_render_icon(). These functions take the theme into account when
+ * looking up the icon to use for a given stock ID.
+ *
+ *
+ * GtkIconFactory as GtkBuildable
+ *
+ * GtkIconFactory supports a custom <sources> element, which can contain
+ * multiple <source> elements.
+ * The following attributes are allowed:
+ *
+ *
+ * stock-id
+ *
+ * The stock id of the source, a string.
+ * This attribute is mandatory
+ *
+ *
+ *
+ * filename
+ *
+ * The filename of the source, a string.
+ * This attribute is optional
+ *
+ *
+ *
+ * icon-name
+ *
+ * The icon name for the source, a string.
+ * This attribute is optional.
+ *
+ *
+ *
+ * size
+ *
+ * Size of the icon, a #GtkIconSize enum value.
+ * This attribute is optional.
+ *
+ *
+ *
+ * direction
+ *
+ * Direction of the source, a #GtkTextDirection enum value.
+ * This attribute is optional.
+ *
+ *
+ *
+ * state
+ *
+ * State of the source, a #GtkStateType enum value.
+ * This attribute is optional.
+ *
+ *
+ *
+ *
+ * A #GtkIconFactory UI definition fragment.
+ *
+ *
+ *
+ *
+ *
+ *
+ * ]]>
+ *
+ *
+ *
+ *
+ */
static GSList *all_icon_factories = NULL;
@@ -249,7 +351,7 @@ gtk_icon_factory_add (GtkIconFactory *factory,
* widget that will display the icon, instead of using this
* function directly, so that themes are taken into account.
*
- * Return value: icon set of @stock_id.
+ * Return value: (transfer none): icon set of @stock_id.
*/
GtkIconSet *
gtk_icon_factory_lookup (GtkIconFactory *factory,
@@ -265,7 +367,6 @@ gtk_icon_factory_lookup (GtkIconFactory *factory,
return g_hash_table_lookup (priv->icons, stock_id);
}
-static GtkIconFactory *gtk_default_icons = NULL;
static GSList *default_factories = NULL;
/**
@@ -307,15 +408,32 @@ gtk_icon_factory_remove_default (GtkIconFactory *factory)
g_object_unref (factory);
}
-void
-_gtk_icon_factory_ensure_default_icons (void)
+static GtkIconFactory *
+_gtk_icon_factory_get_default_icons (void)
{
- if (gtk_default_icons == NULL)
- {
- gtk_default_icons = gtk_icon_factory_new ();
+ static GtkIconFactory *default_icons = NULL;
+ GtkIconFactory *icons = NULL;
+ GdkScreen *screen = gdk_screen_get_default ();
+
+ if (screen)
+ icons = g_object_get_data (G_OBJECT (screen), "gtk-default-icons");
- get_default_icons (gtk_default_icons);
+ if (icons == NULL)
+ {
+ if (default_icons == NULL)
+ {
+ default_icons = gtk_icon_factory_new ();
+ get_default_icons (default_icons);
+ }
+ if (screen)
+ g_object_set_data_full (G_OBJECT (screen),
+ I_("gtk-default-icons"),
+ default_icons,
+ g_object_unref);
+ icons = default_icons;
}
+
+ return icons;
}
/**
@@ -328,12 +446,13 @@ _gtk_icon_factory_ensure_default_icons (void)
* using this function directly, so that themes are taken into
* account.
*
- * Return value: a #GtkIconSet, or %NULL
+ * Return value: (transfer none): a #GtkIconSet, or %NULL
*/
GtkIconSet *
gtk_icon_factory_lookup_default (const gchar *stock_id)
{
GSList *tmp_list;
+ GtkIconFactory *default_icons;
g_return_val_if_fail (stock_id != NULL, NULL);
@@ -350,9 +469,11 @@ gtk_icon_factory_lookup_default (const gchar *stock_id)
tmp_list = g_slist_next (tmp_list);
}
- _gtk_icon_factory_ensure_default_icons ();
-
- return gtk_icon_factory_lookup (gtk_default_icons, stock_id);
+ default_icons = _gtk_icon_factory_get_default_icons ();
+ if (default_icons)
+ return gtk_icon_factory_lookup (default_icons, stock_id);
+ else
+ return NULL;
}
static void
@@ -479,7 +600,7 @@ get_default_icons (GtkIconFactory *factory)
register_bidi_stock_icon (factory, GTK_STOCK_UNDELETE, GTK_STOCK_UNDELETE);
register_bidi_stock_icon (factory, GTK_STOCK_UNDO, "edit-undo");
register_stock_icon (factory, GTK_STOCK_GO_UP, "go-up");
- register_stock_icon (factory, GTK_STOCK_FILE, "document-x-generic");
+ register_stock_icon (factory, GTK_STOCK_FILE, "text-x-generic");
register_stock_icon (factory, GTK_STOCK_DIRECTORY, "folder");
register_stock_icon (factory, GTK_STOCK_ABOUT, "help-about");
register_stock_icon (factory, GTK_STOCK_CONNECT, GTK_STOCK_CONNECT);
@@ -865,14 +986,14 @@ icon_size_lookup_intern (GtkSettings *settings,
* @settings: a #GtkSettings object, used to determine
* which set of user preferences to used.
* @size: (type int): an icon size
- * @width: location to store icon width
- * @height: location to store icon height
+ * @width: (out): location to store icon width
+ * @height: (out): location to store icon height
*
* Obtains the pixel size of a semantic icon size, possibly
* modified by user preferences for a particular
* #GtkSettings. Normally @size would be
* #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc. This function
- * isn't normally needed, gtk_widget_render_icon() is the usual
+ * isn't normally needed, gtk_widget_render_icon_pixbuf() is the usual
* way to get an icon for rendering, then just look at the size of
* the rendered pixbuf. The rendered pixbuf may not even correspond to
* the width/height returned by gtk_icon_size_lookup(), because themes
@@ -897,15 +1018,15 @@ gtk_icon_size_lookup_for_settings (GtkSettings *settings,
/**
* gtk_icon_size_lookup:
* @size: (type int): an icon size
- * @width: location to store icon width
- * @height: location to store icon height
+ * @width: (out): location to store icon width
+ * @height: (out): location to store icon height
*
* Obtains the pixel size of a semantic icon size, possibly
* modified by user preferences for the default #GtkSettings.
* (See gtk_icon_size_lookup_for_settings().)
* Normally @size would be
* #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc. This function
- * isn't normally needed, gtk_widget_render_icon() is the usual
+ * isn't normally needed, gtk_widget_render_icon_pixbuf() is the usual
* way to get an icon for rendering, then just look at the size of
* the rendered pixbuf. The rendered pixbuf may not even correspond to
* the width/height returned by gtk_icon_size_lookup(), because themes
@@ -1063,12 +1184,13 @@ gtk_icon_size_from_name (const gchar *name)
/**
* gtk_icon_size_get_name:
* @size: (type int): a #GtkIconSize.
- * @returns: the name of the given icon size.
*
* Gets the canonical name of the given icon size. The returned string
* is statically allocated and should not be freed.
+ *
+ * Returns: the name of the given icon size.
*/
-G_CONST_RETURN gchar*
+const gchar*
gtk_icon_size_get_name (GtkIconSize size)
{
if (size >= icon_sizes_used)
@@ -1131,7 +1253,7 @@ static guint cache_serial = 0;
* for a given size and state on request, and automatically caches
* some of the rendered #GdkPixbuf objects.
*
- * Normally you would use gtk_widget_render_icon() instead of
+ * Normally you would use gtk_widget_render_icon_pixbuf() instead of
* using #GtkIconSet directly. The one case where you'd use
* #GtkIconSet is to create application-specific icon sets to place in
* a #GtkIconFactory.
@@ -1353,7 +1475,7 @@ ensure_filename_pixbuf (GtkIconSet *icon_set,
/* Remove this icon source so we don't keep trying to
* load it.
*/
- g_warning (_("Error loading icon: %s"), error->message);
+ g_warning ("Error loading icon: %s", error->message);
g_error_free (error);
icon_set->sources = g_slist_remove (icon_set->sources, source);
@@ -1447,7 +1569,7 @@ render_icon_name_pixbuf (GtkIconSource *icon_source,
if (info)
{
tmp_pixbuf = gtk_icon_info_load_icon (info, &error);
- gtk_icon_info_free (info);
+ g_object_unref (info);
}
else
tmp_pixbuf = NULL;
@@ -1559,9 +1681,10 @@ render_fallback_image (GtkStyleContext *context,
_gtk_icon_theme_ensure_builtin_cache ();
index = _gtk_icon_cache_get_directory_index (_builtin_cache, "24");
- pixbuf = _gtk_icon_cache_get_icon (_builtin_cache,
- GTK_STOCK_MISSING_IMAGE,
- index);
+ pixbuf = _gtk_icon_cache_get_icon (_builtin_cache, "image-missing", index);
+
+ g_return_val_if_fail(pixbuf != NULL, NULL);
+
gtk_icon_source_set_pixbuf (&fallback_source, pixbuf);
g_object_unref (pixbuf);
}
@@ -1577,7 +1700,7 @@ render_fallback_image (GtkStyleContext *context,
* means render at the size of the source and don't scale.
*
* Renders an icon using gtk_render_icon_pixbuf(). In most cases,
- * gtk_widget_render_icon() is better, since it automatically provides
+ * gtk_widget_render_icon_pixbuf() is better, since it automatically provides
* most of the arguments from the current widget settings. This
* function never returns %NULL; if the icon can't be rendered
* (perhaps because an image file fails to load), a default "missing
@@ -1608,7 +1731,9 @@ gtk_icon_set_render_icon_pixbuf (GtkIconSet *icon_set,
else
state = GTK_STATE_NORMAL;
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
direction = gtk_style_context_get_direction (context);
+G_GNUC_END_IGNORE_DEPRECATIONS;
if (icon_set->sources)
{
@@ -1703,7 +1828,9 @@ gtk_icon_set_render_icon (GtkIconSet *icon_set,
}
gtk_style_context_set_state (context, flags);
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
gtk_style_context_set_direction (context, direction);
+G_GNUC_END_IGNORE_DEPRECATIONS;
icon = gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
@@ -2016,7 +2143,7 @@ icon_source_clear (GtkIconSource *source)
/**
* gtk_icon_source_set_filename:
* @source: a #GtkIconSource
- * @filename: image file to use
+ * @filename: (type filename): image file to use
*
* Sets the name of an image file to use as a base image when creating
* icon variants for #GtkIconSet. The filename must be absolute.
@@ -2042,7 +2169,7 @@ gtk_icon_source_set_filename (GtkIconSource *source,
}
/**
- * gtk_icon_source_set_icon_name
+ * gtk_icon_source_set_icon_name:
* @source: a #GtkIconSource
* @icon_name: (allow-none): name of icon to use
*
@@ -2104,10 +2231,10 @@ gtk_icon_source_set_pixbuf (GtkIconSource *source,
* filename is not a copy, and should not be modified or expected to
* persist beyond the lifetime of the icon source.
*
- * Return value: image filename. This string must not be modified
- * or freed.
+ * Return value: (type filename): image filename. This string must not
+ * be modified or freed.
*/
-G_CONST_RETURN gchar*
+const gchar*
gtk_icon_source_get_filename (const GtkIconSource *source)
{
g_return_val_if_fail (source != NULL, NULL);
@@ -2128,7 +2255,7 @@ gtk_icon_source_get_filename (const GtkIconSource *source)
*
* Return value: icon name. This string must not be modified or freed.
*/
-G_CONST_RETURN gchar*
+const gchar*
gtk_icon_source_get_icon_name (const GtkIconSource *source)
{
g_return_val_if_fail (source != NULL, NULL);
@@ -2696,7 +2823,7 @@ _gtk_icon_factory_list_ids (void)
ids = NULL;
- _gtk_icon_factory_ensure_default_icons ();
+ _gtk_icon_factory_get_default_icons ();
tmp_list = all_icon_factories;
while (tmp_list != NULL)
@@ -2731,12 +2858,12 @@ typedef struct {
} IconSourceParserData;
static void
-icon_source_start_element (GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **names,
- const gchar **values,
- gpointer user_data,
- GError **error)
+icon_source_start_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **names,
+ const gchar **values,
+ gpointer user_data,
+ GError **error)
{
gint i;
gchar *stock_id = NULL;
@@ -2755,63 +2882,63 @@ icon_source_start_element (GMarkupParseContext *context,
if (!parser_data->in_source)
{
if (strcmp (element_name, "sources") != 0)
- {
- error_msg = g_strdup_printf ("Unexpected element %s, expected ", element_name);
- error_domain = GTK_BUILDER_ERROR_INVALID_TAG;
- goto error;
- }
+ {
+ error_msg = g_strdup_printf ("Unexpected element %s, expected ", element_name);
+ error_domain = GTK_BUILDER_ERROR_INVALID_TAG;
+ goto error;
+ }
parser_data->in_source = TRUE;
return;
}
else
{
if (strcmp (element_name, "source") != 0)
- {
- error_msg = g_strdup_printf ("Unexpected element %s, expected