X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkiconfactory.c;h=b40267335b0a78c0a1ec613de399e2a2422de375;hb=32bd10bf74cd2b7f2d16432d4198dca82c386133;hp=0e6e3d8ed197eb62a1b631c62590741996886415;hpb=c7a48881c67c42179ed711f4df035a0b492d958b;p=~andy%2Fgtk
diff --git a/gtk/gtkiconfactory.c b/gtk/gtkiconfactory.c
index 0e6e3d8ed..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,24 +23,132 @@
*/
#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 "gtkalias.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;
+struct _GtkIconFactoryPrivate
+{
+ GHashTable *icons;
+};
+
typedef enum {
GTK_ICON_SOURCE_EMPTY,
GTK_ICON_SOURCE_ICON_NAME,
@@ -74,13 +180,6 @@ struct _GtkIconSource
guint any_direction : 1;
guint any_state : 1;
guint any_size : 1;
-
-#if defined (G_OS_WIN32) && !defined (_WIN64)
- /* System codepage version of filename, for DLL ABI backward
- * compatibility functions.
- */
- gchar *cp_filename;
-#endif
};
@@ -118,7 +217,14 @@ G_DEFINE_TYPE_WITH_CODE (GtkIconFactory, gtk_icon_factory, G_TYPE_OBJECT,
static void
gtk_icon_factory_init (GtkIconFactory *factory)
{
- factory->icons = g_hash_table_new (g_str_hash, g_str_equal);
+ GtkIconFactoryPrivate *priv;
+
+ factory->priv = G_TYPE_INSTANCE_GET_PRIVATE (factory,
+ GTK_TYPE_ICON_FACTORY,
+ GtkIconFactoryPrivate);
+ priv = factory->priv;
+
+ priv->icons = g_hash_table_new (g_str_hash, g_str_equal);
all_icon_factories = g_slist_prepend (all_icon_factories, factory);
}
@@ -128,6 +234,8 @@ gtk_icon_factory_class_init (GtkIconFactoryClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gtk_icon_factory_finalize;
+
+ g_type_class_add_private (klass, sizeof (GtkIconFactoryPrivate));
}
static void
@@ -148,12 +256,13 @@ static void
gtk_icon_factory_finalize (GObject *object)
{
GtkIconFactory *factory = GTK_ICON_FACTORY (object);
+ GtkIconFactoryPrivate *priv = factory->priv;
all_icon_factories = g_slist_remove (all_icon_factories, factory);
- g_hash_table_foreach (factory->icons, free_icon_set, NULL);
+ g_hash_table_foreach (priv->icons, free_icon_set, NULL);
- g_hash_table_destroy (factory->icons);
+ g_hash_table_destroy (priv->icons);
G_OBJECT_CLASS (gtk_icon_factory_parent_class)->finalize (object);
}
@@ -205,6 +314,7 @@ gtk_icon_factory_add (GtkIconFactory *factory,
const gchar *stock_id,
GtkIconSet *icon_set)
{
+ GtkIconFactoryPrivate *priv = factory->priv;
gpointer old_key = NULL;
gpointer old_value = NULL;
@@ -212,7 +322,7 @@ gtk_icon_factory_add (GtkIconFactory *factory,
g_return_if_fail (stock_id != NULL);
g_return_if_fail (icon_set != NULL);
- g_hash_table_lookup_extended (factory->icons, stock_id,
+ g_hash_table_lookup_extended (priv->icons, stock_id,
&old_key, &old_value);
if (old_value == icon_set)
@@ -222,9 +332,9 @@ gtk_icon_factory_add (GtkIconFactory *factory,
/* GHashTable key memory management is so fantastically broken. */
if (old_key)
- g_hash_table_insert (factory->icons, old_key, icon_set);
+ g_hash_table_insert (priv->icons, old_key, icon_set);
else
- g_hash_table_insert (factory->icons, g_strdup (stock_id), icon_set);
+ g_hash_table_insert (priv->icons, g_strdup (stock_id), icon_set);
if (old_value)
gtk_icon_set_unref (old_value);
@@ -241,19 +351,22 @@ 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,
const gchar *stock_id)
{
+ GtkIconFactoryPrivate *priv;
+
g_return_val_if_fail (GTK_IS_ICON_FACTORY (factory), NULL);
g_return_val_if_fail (stock_id != NULL, NULL);
- return g_hash_table_lookup (factory->icons, stock_id);
+ priv = factory->priv;
+
+ return g_hash_table_lookup (priv->icons, stock_id);
}
-static GtkIconFactory *gtk_default_icons = NULL;
static GSList *default_factories = NULL;
/**
@@ -295,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 ();
- get_default_icons (gtk_default_icons);
+ if (screen)
+ icons = g_object_get_data (G_OBJECT (screen), "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;
}
/**
@@ -316,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);
@@ -338,20 +469,24 @@ 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
register_stock_icon (GtkIconFactory *factory,
- const gchar *stock_id)
+ const gchar *stock_id,
+ const gchar *icon_name)
{
GtkIconSet *set = gtk_icon_set_new ();
GtkIconSource source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
- source.source.icon_name = (gchar *)stock_id;
+ source.source.icon_name = (gchar *)icon_name;
+ source.direction = GTK_TEXT_DIR_NONE;
gtk_icon_set_add_source (set, &source);
gtk_icon_factory_add (factory, stock_id, set);
@@ -361,19 +496,18 @@ register_stock_icon (GtkIconFactory *factory,
static void
register_bidi_stock_icon (GtkIconFactory *factory,
const gchar *stock_id,
- const gchar *stock_id_ltr,
- const gchar *stock_id_rtl)
+ const gchar *icon_name)
{
GtkIconSet *set = gtk_icon_set_new ();
GtkIconSource source = GTK_ICON_SOURCE_INIT (FALSE, TRUE, TRUE);
source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
- source.source.icon_name = (gchar *)stock_id_ltr;
+ source.source.icon_name = (gchar *)icon_name;
source.direction = GTK_TEXT_DIR_LTR;
gtk_icon_set_add_source (set, &source);
source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
- source.source.icon_name = (gchar *)stock_id_rtl;
+ source.source.icon_name = (gchar *)icon_name;
source.direction = GTK_TEXT_DIR_RTL;
gtk_icon_set_add_source (set, &source);
@@ -386,158 +520,110 @@ get_default_icons (GtkIconFactory *factory)
{
/* KEEP IN SYNC with gtkstock.c */
- register_stock_icon (factory, GTK_STOCK_DIALOG_AUTHENTICATION);
- register_stock_icon (factory, GTK_STOCK_DIALOG_ERROR);
- register_stock_icon (factory, GTK_STOCK_DIALOG_INFO);
- register_stock_icon (factory, GTK_STOCK_DIALOG_QUESTION);
- register_stock_icon (factory, GTK_STOCK_DIALOG_WARNING);
- register_stock_icon (factory, GTK_STOCK_DND);
- register_stock_icon (factory, GTK_STOCK_DND_MULTIPLE);
- register_stock_icon (factory, GTK_STOCK_APPLY);
- register_stock_icon (factory, GTK_STOCK_CANCEL);
- register_stock_icon (factory, GTK_STOCK_NO);
- register_stock_icon (factory, GTK_STOCK_OK);
- register_stock_icon (factory, GTK_STOCK_YES);
- register_stock_icon (factory, GTK_STOCK_CLOSE);
- register_stock_icon (factory, GTK_STOCK_ADD);
- register_stock_icon (factory, GTK_STOCK_JUSTIFY_CENTER);
- register_stock_icon (factory, GTK_STOCK_JUSTIFY_FILL);
- register_stock_icon (factory, GTK_STOCK_JUSTIFY_LEFT);
- register_stock_icon (factory, GTK_STOCK_JUSTIFY_RIGHT);
- register_stock_icon (factory, GTK_STOCK_GOTO_BOTTOM);
- register_stock_icon (factory, GTK_STOCK_CDROM);
- register_stock_icon (factory, GTK_STOCK_CONVERT);
- register_stock_icon (factory, GTK_STOCK_COPY);
- register_stock_icon (factory, GTK_STOCK_CUT);
- register_stock_icon (factory, GTK_STOCK_GO_DOWN);
- register_stock_icon (factory, GTK_STOCK_EXECUTE);
- register_stock_icon (factory, GTK_STOCK_QUIT);
- register_bidi_stock_icon (factory,
- GTK_STOCK_GOTO_FIRST,
- GTK_STOCK_GOTO_FIRST "-ltr",
- GTK_STOCK_GOTO_FIRST "-rtl");
- register_stock_icon (factory, GTK_STOCK_SELECT_FONT);
- register_stock_icon (factory, GTK_STOCK_FULLSCREEN);
- register_stock_icon (factory, GTK_STOCK_LEAVE_FULLSCREEN);
- register_stock_icon (factory, GTK_STOCK_HARDDISK);
- register_stock_icon (factory, GTK_STOCK_HELP);
- register_stock_icon (factory, GTK_STOCK_HOME);
- register_stock_icon (factory, GTK_STOCK_INFO);
- register_bidi_stock_icon (factory,
- GTK_STOCK_JUMP_TO,
- GTK_STOCK_JUMP_TO "-ltr",
- GTK_STOCK_JUMP_TO "-rtl");
- register_bidi_stock_icon (factory,
- GTK_STOCK_GOTO_LAST,
- GTK_STOCK_GOTO_LAST "-ltr",
- GTK_STOCK_GOTO_LAST "-rtl");
- register_bidi_stock_icon (factory,
- GTK_STOCK_GO_BACK,
- GTK_STOCK_GO_BACK "-ltr",
- GTK_STOCK_GO_BACK "-rtl");
- register_stock_icon (factory, GTK_STOCK_MISSING_IMAGE);
- register_stock_icon (factory, GTK_STOCK_NETWORK);
- register_stock_icon (factory, GTK_STOCK_NEW);
- register_stock_icon (factory, GTK_STOCK_OPEN);
- register_stock_icon (factory, GTK_STOCK_ORIENTATION_PORTRAIT);
- register_stock_icon (factory, GTK_STOCK_ORIENTATION_LANDSCAPE);
- register_stock_icon (factory, GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT);
- register_stock_icon (factory, GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE);
- register_stock_icon (factory, GTK_STOCK_PAGE_SETUP);
- register_stock_icon (factory, GTK_STOCK_PASTE);
- register_stock_icon (factory, GTK_STOCK_PREFERENCES);
- register_stock_icon (factory, GTK_STOCK_PRINT);
- register_stock_icon (factory, GTK_STOCK_PRINT_ERROR);
- register_stock_icon (factory, GTK_STOCK_PRINT_PAUSED);
- register_stock_icon (factory, GTK_STOCK_PRINT_PREVIEW);
- register_stock_icon (factory, GTK_STOCK_PRINT_REPORT);
- register_stock_icon (factory, GTK_STOCK_PRINT_WARNING);
- register_stock_icon (factory, GTK_STOCK_PROPERTIES);
- register_bidi_stock_icon (factory,
- GTK_STOCK_REDO,
- GTK_STOCK_REDO "-ltr",
- GTK_STOCK_REDO "-rtl");
- register_stock_icon (factory, GTK_STOCK_REMOVE);
- register_stock_icon (factory, GTK_STOCK_REFRESH);
- register_bidi_stock_icon (factory,
- GTK_STOCK_REVERT_TO_SAVED,
- GTK_STOCK_REVERT_TO_SAVED "-ltr",
- GTK_STOCK_REVERT_TO_SAVED "-rtl");
- register_bidi_stock_icon (factory,
- GTK_STOCK_GO_FORWARD,
- GTK_STOCK_GO_FORWARD "-ltr",
- GTK_STOCK_GO_FORWARD "-rtl");
- register_stock_icon (factory, GTK_STOCK_SAVE);
- register_stock_icon (factory, GTK_STOCK_FLOPPY);
- register_stock_icon (factory, GTK_STOCK_SAVE_AS);
- register_stock_icon (factory, GTK_STOCK_FIND);
- register_stock_icon (factory, GTK_STOCK_FIND_AND_REPLACE);
- register_stock_icon (factory, GTK_STOCK_SORT_DESCENDING);
- register_stock_icon (factory, GTK_STOCK_SORT_ASCENDING);
- register_stock_icon (factory, GTK_STOCK_SPELL_CHECK);
- register_stock_icon (factory, GTK_STOCK_STOP);
- register_stock_icon (factory, GTK_STOCK_BOLD);
- register_stock_icon (factory, GTK_STOCK_ITALIC);
- register_stock_icon (factory, GTK_STOCK_STRIKETHROUGH);
- register_stock_icon (factory, GTK_STOCK_UNDERLINE);
- register_bidi_stock_icon (factory,
- GTK_STOCK_INDENT,
- GTK_STOCK_INDENT "-ltr",
- GTK_STOCK_INDENT "-rtl");
- register_bidi_stock_icon (factory,
- GTK_STOCK_UNINDENT,
- GTK_STOCK_UNINDENT "-ltr",
- GTK_STOCK_UNINDENT "-rtl");
- register_stock_icon (factory, GTK_STOCK_GOTO_TOP);
- register_stock_icon (factory, GTK_STOCK_DELETE);
- register_bidi_stock_icon (factory,
- GTK_STOCK_UNDELETE,
- GTK_STOCK_UNDELETE "-ltr",
- GTK_STOCK_UNDELETE "-rtl");
- register_bidi_stock_icon (factory,
- GTK_STOCK_UNDO,
- GTK_STOCK_UNDO "-ltr",
- GTK_STOCK_UNDO "-rtl");
- register_stock_icon (factory, GTK_STOCK_GO_UP);
- register_stock_icon (factory, GTK_STOCK_FILE);
- register_stock_icon (factory, GTK_STOCK_DIRECTORY);
- register_stock_icon (factory, GTK_STOCK_ABOUT);
- register_stock_icon (factory, GTK_STOCK_CONNECT);
- register_stock_icon (factory, GTK_STOCK_DISCONNECT);
- register_stock_icon (factory, GTK_STOCK_EDIT);
- register_stock_icon (factory, GTK_STOCK_CAPS_LOCK_WARNING);
- register_bidi_stock_icon (factory,
- GTK_STOCK_MEDIA_FORWARD,
- GTK_STOCK_MEDIA_FORWARD "-ltr",
- GTK_STOCK_MEDIA_FORWARD "-rtl");
- register_bidi_stock_icon (factory,
- GTK_STOCK_MEDIA_NEXT,
- GTK_STOCK_MEDIA_NEXT "-ltr",
- GTK_STOCK_MEDIA_NEXT "-rtl");
- register_stock_icon (factory, GTK_STOCK_MEDIA_PAUSE);
- register_bidi_stock_icon (factory,
- GTK_STOCK_MEDIA_PLAY,
- GTK_STOCK_MEDIA_PLAY "-ltr",
- GTK_STOCK_MEDIA_PLAY "-rtl");
- register_bidi_stock_icon (factory,
- GTK_STOCK_MEDIA_PREVIOUS,
- GTK_STOCK_MEDIA_PREVIOUS "-ltr",
- GTK_STOCK_MEDIA_PREVIOUS "-rtl");
- register_stock_icon (factory, GTK_STOCK_MEDIA_RECORD);
- register_bidi_stock_icon (factory,
- GTK_STOCK_MEDIA_REWIND,
- GTK_STOCK_MEDIA_REWIND "-ltr",
- GTK_STOCK_MEDIA_REWIND "-rtl");
- register_stock_icon (factory, GTK_STOCK_MEDIA_STOP);
- register_stock_icon (factory, GTK_STOCK_INDEX);
- register_stock_icon (factory, GTK_STOCK_ZOOM_100);
- register_stock_icon (factory, GTK_STOCK_ZOOM_IN);
- register_stock_icon (factory, GTK_STOCK_ZOOM_OUT);
- register_stock_icon (factory, GTK_STOCK_ZOOM_FIT);
- register_stock_icon (factory, GTK_STOCK_SELECT_ALL);
- register_stock_icon (factory, GTK_STOCK_CLEAR);
- register_stock_icon (factory, GTK_STOCK_SELECT_COLOR);
- register_stock_icon (factory, GTK_STOCK_COLOR_PICKER);
+ register_stock_icon (factory, GTK_STOCK_DIALOG_AUTHENTICATION, "dialog-password");
+ register_stock_icon (factory, GTK_STOCK_DIALOG_ERROR, "dialog-error");
+ register_stock_icon (factory, GTK_STOCK_DIALOG_INFO, "dialog-information");
+ register_stock_icon (factory, GTK_STOCK_DIALOG_QUESTION, "dialog-question");
+ register_stock_icon (factory, GTK_STOCK_DIALOG_WARNING, "dialog-warning");
+ register_stock_icon (factory, GTK_STOCK_DND, GTK_STOCK_DND);
+ register_stock_icon (factory, GTK_STOCK_DND_MULTIPLE, GTK_STOCK_DND_MULTIPLE);
+ register_stock_icon (factory, GTK_STOCK_APPLY, GTK_STOCK_APPLY);
+ register_stock_icon (factory, GTK_STOCK_CANCEL, GTK_STOCK_CANCEL);
+ register_stock_icon (factory, GTK_STOCK_NO, GTK_STOCK_NO);
+ register_stock_icon (factory, GTK_STOCK_OK, GTK_STOCK_OK);
+ register_stock_icon (factory, GTK_STOCK_YES, GTK_STOCK_YES);
+ register_stock_icon (factory, GTK_STOCK_CLOSE, "window-close");
+ register_stock_icon (factory, GTK_STOCK_ADD, "list-add");
+ register_stock_icon (factory, GTK_STOCK_JUSTIFY_CENTER, "format-justify-center");
+ register_stock_icon (factory, GTK_STOCK_JUSTIFY_FILL, "format-justify-fill");
+ register_stock_icon (factory, GTK_STOCK_JUSTIFY_LEFT, "format-justify-left");
+ register_stock_icon (factory, GTK_STOCK_JUSTIFY_RIGHT, "format-justify-right");
+ register_stock_icon (factory, GTK_STOCK_GOTO_BOTTOM, "go-bottom");
+ register_stock_icon (factory, GTK_STOCK_CDROM, "media-optical");
+ register_stock_icon (factory, GTK_STOCK_CONVERT, GTK_STOCK_CONVERT);
+ register_stock_icon (factory, GTK_STOCK_COPY, "edit-copy");
+ register_stock_icon (factory, GTK_STOCK_CUT, "edit-cut");
+ register_stock_icon (factory, GTK_STOCK_GO_DOWN, "go-down");
+ register_stock_icon (factory, GTK_STOCK_EXECUTE, "system-run");
+ register_stock_icon (factory, GTK_STOCK_QUIT, "application-exit");
+ register_bidi_stock_icon (factory, GTK_STOCK_GOTO_FIRST, "go-first");
+ register_stock_icon (factory, GTK_STOCK_SELECT_FONT, GTK_STOCK_SELECT_FONT);
+ register_stock_icon (factory, GTK_STOCK_FULLSCREEN, "view-fullscreen");
+ register_stock_icon (factory, GTK_STOCK_LEAVE_FULLSCREEN, "view-restore");
+ register_stock_icon (factory, GTK_STOCK_HARDDISK, "drive-harddisk");
+ register_stock_icon (factory, GTK_STOCK_HELP, "help-contents");
+ register_stock_icon (factory, GTK_STOCK_HOME, "go-home");
+ register_stock_icon (factory, GTK_STOCK_INFO, "dialog-information");
+ register_bidi_stock_icon (factory, GTK_STOCK_JUMP_TO, "go-jump");
+ register_bidi_stock_icon (factory, GTK_STOCK_GOTO_LAST, "go-last");
+ register_bidi_stock_icon (factory, GTK_STOCK_GO_BACK, "go-previous");
+ register_stock_icon (factory, GTK_STOCK_MISSING_IMAGE, "image-missing");
+ register_stock_icon (factory, GTK_STOCK_NETWORK, "network-idle");
+ register_stock_icon (factory, GTK_STOCK_NEW, "document-new");
+ register_stock_icon (factory, GTK_STOCK_OPEN, "document-open");
+ register_stock_icon (factory, GTK_STOCK_ORIENTATION_PORTRAIT, GTK_STOCK_ORIENTATION_PORTRAIT);
+ register_stock_icon (factory, GTK_STOCK_ORIENTATION_LANDSCAPE, GTK_STOCK_ORIENTATION_LANDSCAPE);
+ register_stock_icon (factory, GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT, GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT);
+ register_stock_icon (factory, GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE, GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE);
+ register_stock_icon (factory, GTK_STOCK_PAGE_SETUP, GTK_STOCK_PAGE_SETUP);
+ register_stock_icon (factory, GTK_STOCK_PASTE, "edit-paste");
+ register_stock_icon (factory, GTK_STOCK_PREFERENCES, GTK_STOCK_PREFERENCES);
+ register_stock_icon (factory, GTK_STOCK_PRINT, "document-print");
+ register_stock_icon (factory, GTK_STOCK_PRINT_ERROR, "printer-error");
+ register_stock_icon (factory, GTK_STOCK_PRINT_PAUSED, "printer-paused");
+ register_stock_icon (factory, GTK_STOCK_PRINT_PREVIEW, "document-print-preview");
+ register_stock_icon (factory, GTK_STOCK_PRINT_REPORT, "printer-info");
+ register_stock_icon (factory, GTK_STOCK_PRINT_WARNING, "printer-warning");
+ register_stock_icon (factory, GTK_STOCK_PROPERTIES, "document-properties");
+ register_bidi_stock_icon (factory, GTK_STOCK_REDO, "edit-redo");
+ register_stock_icon (factory, GTK_STOCK_REMOVE, "list-remove");
+ register_stock_icon (factory, GTK_STOCK_REFRESH, "view-refresh");
+ register_bidi_stock_icon (factory, GTK_STOCK_REVERT_TO_SAVED, "document-revert");
+ register_bidi_stock_icon (factory, GTK_STOCK_GO_FORWARD, "go-next");
+ register_stock_icon (factory, GTK_STOCK_SAVE, "document-save");
+ register_stock_icon (factory, GTK_STOCK_FLOPPY, "media-floppy");
+ register_stock_icon (factory, GTK_STOCK_SAVE_AS, "document-save-as");
+ register_stock_icon (factory, GTK_STOCK_FIND, "edit-find");
+ register_stock_icon (factory, GTK_STOCK_FIND_AND_REPLACE, "edit-find-replace");
+ register_stock_icon (factory, GTK_STOCK_SORT_DESCENDING, "view-sort-descending");
+ register_stock_icon (factory, GTK_STOCK_SORT_ASCENDING, "view-sort-ascending");
+ register_stock_icon (factory, GTK_STOCK_SPELL_CHECK, "tools-check-spelling");
+ register_stock_icon (factory, GTK_STOCK_STOP, "process-stop");
+ register_stock_icon (factory, GTK_STOCK_BOLD, "format-text-bold");
+ register_stock_icon (factory, GTK_STOCK_ITALIC, "format-text-italic");
+ register_stock_icon (factory, GTK_STOCK_STRIKETHROUGH, "format-text-strikethrough");
+ register_stock_icon (factory, GTK_STOCK_UNDERLINE, "format-text-underline");
+ register_bidi_stock_icon (factory, GTK_STOCK_INDENT, "format-indent-more");
+ register_bidi_stock_icon (factory, GTK_STOCK_UNINDENT, "format-indent-less");
+ register_stock_icon (factory, GTK_STOCK_GOTO_TOP, "go-top");
+ register_stock_icon (factory, GTK_STOCK_DELETE, "edit-delete");
+ 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, "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);
+ register_stock_icon (factory, GTK_STOCK_DISCONNECT, GTK_STOCK_DISCONNECT);
+ register_stock_icon (factory, GTK_STOCK_EDIT, GTK_STOCK_EDIT);
+ register_stock_icon (factory, GTK_STOCK_CAPS_LOCK_WARNING, GTK_STOCK_CAPS_LOCK_WARNING);
+ register_bidi_stock_icon (factory, GTK_STOCK_MEDIA_FORWARD, "media-seek-forward");
+ register_bidi_stock_icon (factory, GTK_STOCK_MEDIA_NEXT, "media-skip-forward");
+ register_stock_icon (factory, GTK_STOCK_MEDIA_PAUSE, "media-playback-pause");
+ register_bidi_stock_icon (factory, GTK_STOCK_MEDIA_PLAY, "media-playback-start");
+ register_bidi_stock_icon (factory, GTK_STOCK_MEDIA_PREVIOUS, "media-skip-backward");
+ register_stock_icon (factory, GTK_STOCK_MEDIA_RECORD, "media-record");
+ register_bidi_stock_icon (factory, GTK_STOCK_MEDIA_REWIND, "media-seek-backward");
+ register_stock_icon (factory, GTK_STOCK_MEDIA_STOP, "media-playback-stop");
+ register_stock_icon (factory, GTK_STOCK_INDEX, GTK_STOCK_INDEX);
+ register_stock_icon (factory, GTK_STOCK_ZOOM_100, "zoom-original");
+ register_stock_icon (factory, GTK_STOCK_ZOOM_IN, "zoom-in");
+ register_stock_icon (factory, GTK_STOCK_ZOOM_OUT, "zoom-out");
+ register_stock_icon (factory, GTK_STOCK_ZOOM_FIT, "zoom-fit-best");
+ register_stock_icon (factory, GTK_STOCK_SELECT_ALL, "edit-select-all");
+ register_stock_icon (factory, GTK_STOCK_CLEAR, "edit-clear");
+ register_stock_icon (factory, GTK_STOCK_SELECT_COLOR, GTK_STOCK_SELECT_COLOR);
+ register_stock_icon (factory, GTK_STOCK_COLOR_PICKER, GTK_STOCK_COLOR_PICKER);
}
/************************************************************
@@ -831,7 +917,7 @@ icon_size_settings_changed (GtkSettings *settings,
{
icon_size_set_all_from_settings (settings);
- gtk_rc_reset_styles (settings);
+ gtk_style_context_reset_widgets (_gtk_settings_get_screen (settings));
}
static void
@@ -900,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
@@ -932,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
@@ -1098,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)
@@ -1118,12 +1205,12 @@ gtk_icon_size_get_name (GtkIconSize size)
static GdkPixbuf *find_in_cache (GtkIconSet *icon_set,
- GtkStyle *style,
+ GtkStyleContext *style_context,
GtkTextDirection direction,
GtkStateType state,
GtkIconSize size);
static void add_to_cache (GtkIconSet *icon_set,
- GtkStyle *style,
+ GtkStyleContext *style_context,
GtkTextDirection direction,
GtkStateType state,
GtkIconSize size,
@@ -1137,9 +1224,9 @@ static void clear_cache (GtkIconSet *icon_set,
static GSList* copy_cache (GtkIconSet *icon_set,
GtkIconSet *copy_recipient);
static void attach_to_style (GtkIconSet *icon_set,
- GtkStyle *style);
+ GtkStyleContext *style_context);
static void detach_from_style (GtkIconSet *icon_set,
- GtkStyle *style);
+ GtkStyleContext *style_context);
static void style_dnotify (gpointer data);
struct _GtkIconSet
@@ -1166,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.
@@ -1271,18 +1358,9 @@ gtk_icon_set_unref (GtkIconSet *icon_set)
}
}
-GType
-gtk_icon_set_get_type (void)
-{
- static GType our_type = 0;
-
- if (our_type == 0)
- our_type = g_boxed_type_register_static (I_("GtkIconSet"),
- (GBoxedCopyFunc) gtk_icon_set_ref,
- (GBoxedFreeFunc) gtk_icon_set_unref);
-
- return our_type;
-}
+G_DEFINE_BOXED_TYPE (GtkIconSet, gtk_icon_set,
+ gtk_icon_set_ref,
+ gtk_icon_set_unref)
/**
* gtk_icon_set_copy:
@@ -1397,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);
@@ -1413,12 +1491,8 @@ ensure_filename_pixbuf (GtkIconSet *icon_set,
static GdkPixbuf *
render_icon_name_pixbuf (GtkIconSource *icon_source,
- GtkStyle *style,
- GtkTextDirection direction,
- GtkStateType state,
- GtkIconSize size,
- GtkWidget *widget,
- const char *detail)
+ GtkStyleContext *context,
+ GtkIconSize size)
{
GdkPixbuf *pixbuf;
GdkPixbuf *tmp_pixbuf;
@@ -1430,17 +1504,7 @@ render_icon_name_pixbuf (GtkIconSource *icon_source,
gint *sizes, *s, dist;
GError *error = NULL;
- if (widget && gtk_widget_has_screen (widget))
- screen = gtk_widget_get_screen (widget);
- else if (style && style->colormap)
- screen = gdk_colormap_get_screen (style->colormap);
- else
- {
- screen = gdk_screen_get_default ();
- GTK_NOTE (MULTIHEAD,
- g_warning ("Using the default screen for gtk_icon_source_render_icon()"));
- }
-
+ screen = gtk_style_context_get_screen (context);
icon_theme = gtk_icon_theme_get_for_screen (screen);
settings = gtk_settings_get_for_screen (screen);
@@ -1488,10 +1552,35 @@ render_icon_name_pixbuf (GtkIconSource *icon_source,
pixel_size = MIN (width, height);
- tmp_pixbuf = gtk_icon_theme_load_icon (icon_theme,
- icon_source->source.icon_name,
- pixel_size, 0,
- &error);
+ if (icon_source->direction != GTK_TEXT_DIR_NONE)
+ {
+ gchar *suffix[3] = { NULL, "-ltr", "-rtl" };
+ gchar *names[3];
+ GtkIconInfo *info;
+
+ names[0] = g_strconcat (icon_source->source.icon_name, suffix[icon_source->direction], NULL);
+ names[1] = icon_source->source.icon_name;
+ names[2] = NULL;
+
+ info = gtk_icon_theme_choose_icon (icon_theme,
+ (const char **) names,
+ pixel_size, GTK_ICON_LOOKUP_USE_BUILTIN);
+ g_free (names[0]);
+ if (info)
+ {
+ tmp_pixbuf = gtk_icon_info_load_icon (info, &error);
+ g_object_unref (info);
+ }
+ else
+ tmp_pixbuf = NULL;
+ }
+ else
+ {
+ tmp_pixbuf = gtk_icon_theme_load_icon (icon_theme,
+ icon_source->source.icon_name,
+ pixel_size, 0,
+ &error);
+ }
if (!tmp_pixbuf)
{
@@ -1506,9 +1595,7 @@ render_icon_name_pixbuf (GtkIconSource *icon_source,
tmp_source.type = GTK_ICON_SOURCE_PIXBUF;
tmp_source.source.pixbuf = tmp_pixbuf;
- pixbuf = gtk_style_render_icon (style, &tmp_source,
- direction, state, -1,
- widget, detail);
+ pixbuf = gtk_render_icon_pixbuf (context, &tmp_source, -1);
if (!pixbuf)
g_warning ("Failed to render icon");
@@ -1520,12 +1607,10 @@ render_icon_name_pixbuf (GtkIconSource *icon_source,
static GdkPixbuf *
find_and_render_icon_source (GtkIconSet *icon_set,
- GtkStyle *style,
+ GtkStyleContext *context,
GtkTextDirection direction,
GtkStateType state,
- GtkIconSize size,
- GtkWidget *widget,
- const char *detail)
+ GtkIconSize size)
{
GSList *failed = NULL;
GdkPixbuf *pixbuf = NULL;
@@ -1554,9 +1639,7 @@ find_and_render_icon_source (GtkIconSet *icon_set,
break;
/* Fall through */
case GTK_ICON_SOURCE_PIXBUF:
- pixbuf = gtk_style_render_icon (style, source,
- direction, state, size,
- widget, detail);
+ pixbuf = gtk_render_icon_pixbuf (context, source, size);
if (!pixbuf)
{
g_warning ("Failed to render icon");
@@ -1565,9 +1648,7 @@ find_and_render_icon_source (GtkIconSet *icon_set,
break;
case GTK_ICON_SOURCE_ICON_NAME:
case GTK_ICON_SOURCE_STATIC_ICON_NAME:
- pixbuf = render_icon_name_pixbuf (source, style,
- direction, state, size,
- widget, detail);
+ pixbuf = render_icon_name_pixbuf (source, context, size);
if (!pixbuf)
failed = g_slist_prepend (failed, source);
break;
@@ -1584,12 +1665,10 @@ find_and_render_icon_source (GtkIconSet *icon_set,
extern GtkIconCache *_builtin_cache;
static GdkPixbuf*
-render_fallback_image (GtkStyle *style,
+render_fallback_image (GtkStyleContext *context,
GtkTextDirection direction,
GtkStateType state,
- GtkIconSize size,
- GtkWidget *widget,
- const char *detail)
+ GtkIconSize size)
{
/* This icon can be used for any direction/state/size */
static GtkIconSource fallback_source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
@@ -1602,20 +1681,79 @@ render_fallback_image (GtkStyle *style,
_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);
}
- return gtk_style_render_icon (style,
- &fallback_source,
- direction,
- state,
- size,
- widget,
- detail);
+ return gtk_render_icon_pixbuf (context, &fallback_source, size);
+}
+
+/**
+ * gtk_icon_set_render_icon_pixbuf:
+ * @icon_set: a #GtkIconSet
+ * @context: a #GtkStyleContext
+ * @size: (type int): icon size. A size of (GtkIconSize)-1
+ * 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_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
+ * image" icon will be returned instead.
+ *
+ * Return value: (transfer full): a #GdkPixbuf to be displayed
+ *
+ * Since: 3.0
+ */
+GdkPixbuf *
+gtk_icon_set_render_icon_pixbuf (GtkIconSet *icon_set,
+ GtkStyleContext *context,
+ GtkIconSize size)
+{
+ GdkPixbuf *icon = NULL;
+ GtkStateFlags flags = 0;
+ GtkStateType state;
+ GtkTextDirection direction;
+
+ g_return_val_if_fail (icon_set != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
+
+ flags = gtk_style_context_get_state (context);
+ if (flags & GTK_STATE_FLAG_INSENSITIVE)
+ state = GTK_STATE_INSENSITIVE;
+ else if (flags & GTK_STATE_FLAG_PRELIGHT)
+ state = GTK_STATE_PRELIGHT;
+ 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)
+ {
+ icon = find_in_cache (icon_set, context, direction, state, size);
+ if (icon)
+ {
+ g_object_ref (icon);
+ return icon;
+ }
+ }
+
+ if (icon_set->sources)
+ icon = find_and_render_icon_source (icon_set, context, direction, state, size);
+
+ if (icon == NULL)
+ icon = render_fallback_image (context, direction, state, size);
+
+ add_to_cache (icon_set, context, direction, state, size, icon);
+
+ return icon;
}
/**
@@ -1640,7 +1778,9 @@ render_fallback_image (GtkStyle *style,
* (perhaps because an image file fails to load), a default "missing
* image" icon will be returned instead.
*
- * Return value: a #GdkPixbuf to be displayed
+ * Return value: (transfer full): a #GdkPixbuf to be displayed
+ *
+ * Deprecated: 3.0: Use gtk_icon_set_render_icon_pixbuf() instead
*/
GdkPixbuf*
gtk_icon_set_render_icon (GtkIconSet *icon_set,
@@ -1652,34 +1792,49 @@ gtk_icon_set_render_icon (GtkIconSet *icon_set,
const char *detail)
{
GdkPixbuf *icon;
+ GtkStyleContext *context = NULL;
+ GtkStateFlags flags = 0;
g_return_val_if_fail (icon_set != NULL, NULL);
g_return_val_if_fail (style == NULL || GTK_IS_STYLE (style), NULL);
- if (icon_set->sources == NULL)
- return render_fallback_image (style, direction, state, size, widget, detail);
-
- if (detail == NULL)
+ if (style && gtk_style_has_context (style))
{
- icon = find_in_cache (icon_set, style, direction,
- state, size);
-
- if (icon)
- {
- g_object_ref (icon);
- return icon;
- }
+ g_object_get (style, "context", &context, NULL);
+ /* g_object_get returns a refed object */
+ if (context)
+ g_object_unref (context);
+ }
+ else if (widget)
+ {
+ context = gtk_widget_get_style_context (widget);
}
+ if (!context)
+ return render_fallback_image (context, direction, state, size);
- icon = find_and_render_icon_source (icon_set, style, direction, state, size,
- widget, detail);
+ gtk_style_context_save (context);
- if (icon == NULL)
- icon = render_fallback_image (style, direction, state, size, widget, detail);
+ switch (state)
+ {
+ case GTK_STATE_PRELIGHT:
+ flags |= GTK_STATE_FLAG_PRELIGHT;
+ break;
+ case GTK_STATE_INSENSITIVE:
+ flags |= GTK_STATE_FLAG_INSENSITIVE;
+ break;
+ default:
+ break;
+ }
+
+ 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);
- if (detail == NULL)
- add_to_cache (icon_set, style, direction, state, size, icon);
+ gtk_style_context_restore (context);
return icon;
}
@@ -1921,9 +2076,6 @@ gtk_icon_source_copy (const GtkIconSource *source)
break;
case GTK_ICON_SOURCE_FILENAME:
copy->source.filename = g_strdup (copy->source.filename);
-#if defined (G_OS_WIN32) && !defined (_WIN64)
- copy->cp_filename = g_strdup (copy->cp_filename);
-#endif
if (copy->filename_pixbuf)
g_object_ref (copy->filename_pixbuf);
break;
@@ -1953,18 +2105,9 @@ gtk_icon_source_free (GtkIconSource *source)
g_free (source);
}
-GType
-gtk_icon_source_get_type (void)
-{
- static GType our_type = 0;
-
- if (our_type == 0)
- our_type = g_boxed_type_register_static (I_("GtkIconSource"),
- (GBoxedCopyFunc) gtk_icon_source_copy,
- (GBoxedFreeFunc) gtk_icon_source_free);
-
- return our_type;
-}
+G_DEFINE_BOXED_TYPE (GtkIconSource, gtk_icon_source,
+ gtk_icon_source_copy,
+ gtk_icon_source_free)
static void
icon_source_clear (GtkIconSource *source)
@@ -1982,10 +2125,6 @@ icon_source_clear (GtkIconSource *source)
case GTK_ICON_SOURCE_FILENAME:
g_free (source->source.filename);
source->source.filename = NULL;
-#if defined (G_OS_WIN32) && !defined (_WIN64)
- g_free (source->cp_filename);
- source->cp_filename = NULL;
-#endif
if (source->filename_pixbuf)
g_object_unref (source->filename_pixbuf);
source->filename_pixbuf = NULL;
@@ -2004,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.
@@ -2026,14 +2165,11 @@ gtk_icon_source_set_filename (GtkIconSource *source,
{
source->type = GTK_ICON_SOURCE_FILENAME;
source->source.filename = g_strdup (filename);
-#if defined (G_OS_WIN32) && !defined (_WIN64)
- source->cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL);
-#endif
}
}
/**
- * gtk_icon_source_set_icon_name
+ * gtk_icon_source_set_icon_name:
* @source: a #GtkIconSource
* @icon_name: (allow-none): name of icon to use
*
@@ -2095,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);
@@ -2119,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);
@@ -2143,7 +2279,7 @@ gtk_icon_source_get_icon_name (const GtkIconSource *source)
* virtual function. The reference count on the pixbuf is
* not incremented.
*
- * Return value: source pixbuf
+ * Return value: (transfer none): source pixbuf
*/
GdkPixbuf*
gtk_icon_source_get_pixbuf (const GtkIconSource *source)
@@ -2414,7 +2550,7 @@ struct _CachedIcon
/* These must all match to use the cached pixbuf.
* If any don't match, we must re-render the pixbuf.
*/
- GtkStyle *style;
+ GtkStyleContext *style;
GtkTextDirection direction;
GtkStateType state;
GtkIconSize size;
@@ -2436,16 +2572,14 @@ static void
cached_icon_free (CachedIcon *icon)
{
g_object_unref (icon->pixbuf);
-
- if (icon->style)
- g_object_unref (icon->style);
+ g_object_unref (icon->style);
g_free (icon);
}
static GdkPixbuf *
find_in_cache (GtkIconSet *icon_set,
- GtkStyle *style,
+ GtkStyleContext *style_context,
GtkTextDirection direction,
GtkStateType state,
GtkIconSize size)
@@ -2461,7 +2595,7 @@ find_in_cache (GtkIconSet *icon_set,
{
CachedIcon *icon = tmp_list->data;
- if (icon->style == style &&
+ if (icon->style == style_context &&
icon->direction == direction &&
icon->state == state &&
(size == (GtkIconSize)-1 || icon->size == size))
@@ -2486,7 +2620,7 @@ find_in_cache (GtkIconSet *icon_set,
static void
add_to_cache (GtkIconSet *icon_set,
- GtkStyle *style,
+ GtkStyleContext *style_context,
GtkTextDirection direction,
GtkStateType state,
GtkIconSize size,
@@ -2498,26 +2632,16 @@ add_to_cache (GtkIconSet *icon_set,
g_object_ref (pixbuf);
- /* We have to ref the style, since if the style was finalized
- * its address could be reused by another style, creating a
- * really weird bug
- */
-
- if (style)
- g_object_ref (style);
-
icon = g_new (CachedIcon, 1);
icon_set->cache = g_slist_prepend (icon_set->cache, icon);
icon_set->cache_size++;
- icon->style = style;
+ icon->style = g_object_ref (style_context);
icon->direction = direction;
icon->state = state;
icon->size = size;
icon->pixbuf = pixbuf;
-
- if (icon->style)
- attach_to_style (icon_set, icon->style);
+ attach_to_style (icon_set, icon->style);
if (icon_set->cache_size >= NUM_CACHED_ICONS)
{
@@ -2550,7 +2674,7 @@ clear_cache (GtkIconSet *icon_set,
gboolean style_detach)
{
GSList *cache, *tmp_list;
- GtkStyle *last_style = NULL;
+ GtkStyleContext *last_style = NULL;
cache = icon_set->cache;
icon_set->cache = NULL;
@@ -2599,11 +2723,8 @@ copy_cache (GtkIconSet *icon_set,
*icon_copy = *icon;
- if (icon_copy->style)
- {
- attach_to_style (copy_recipient, icon_copy->style);
- g_object_ref (icon_copy->style);
- }
+ attach_to_style (copy_recipient, icon_copy->style);
+ g_object_ref (icon_copy->style);
g_object_ref (icon_copy->pixbuf);
@@ -2618,18 +2739,18 @@ copy_cache (GtkIconSet *icon_set,
}
static void
-attach_to_style (GtkIconSet *icon_set,
- GtkStyle *style)
+attach_to_style (GtkIconSet *icon_set,
+ GtkStyleContext *style_context)
{
GHashTable *table;
- table = g_object_get_qdata (G_OBJECT (style),
+ table = g_object_get_qdata (G_OBJECT (style_context),
g_quark_try_string ("gtk-style-icon-sets"));
if (table == NULL)
{
table = g_hash_table_new (NULL, NULL);
- g_object_set_qdata_full (G_OBJECT (style),
+ g_object_set_qdata_full (G_OBJECT (style_context),
g_quark_from_static_string ("gtk-style-icon-sets"),
table,
style_dnotify);
@@ -2639,12 +2760,12 @@ attach_to_style (GtkIconSet *icon_set,
}
static void
-detach_from_style (GtkIconSet *icon_set,
- GtkStyle *style)
+detach_from_style (GtkIconSet *icon_set,
+ GtkStyleContext *style_context)
{
GHashTable *table;
- table = g_object_get_qdata (G_OBJECT (style),
+ table = g_object_get_qdata (G_OBJECT (style_context),
g_quark_try_string ("gtk-style-icon-sets"));
if (table != NULL)
@@ -2702,16 +2823,16 @@ _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)
{
GList *these_ids;
-
GtkIconFactory *factory = GTK_ICON_FACTORY (tmp_list->data);
+ GtkIconFactoryPrivate *priv = factory->priv;
- these_ids = g_hash_table_get_keys (factory->icons);
+ these_ids = g_hash_table_get_keys (priv->icons);
ids = g_list_concat (ids, these_ids);
@@ -2737,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;
@@ -2761,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