[gtk+/picture: 17/17] gtk: Add GtkIconPicture



commit b3746fd9c837d596f653a9bcb7a16b6a55fc7df7
Author: Benjamin Otte <otte redhat com>
Date:   Thu Feb 10 14:46:38 2011 +0100

    gtk: Add GtkIconPicture
    
    It' supposed to be used to get a picture for a GIcon

 gtk/Makefile.am      |    2 +
 gtk/gtk.h            |    1 +
 gtk/gtkiconpicture.c |  207 ++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkiconpicture.h |   64 +++++++++++++++
 4 files changed, 274 insertions(+), 0 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 336d579..f56a9f2 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -227,6 +227,7 @@ gtk_public_h_sources = 		\
 	gtkhseparator.h		\
 	gtkhsv.h		\
 	gtkiconfactory.h	\
+	gtkiconpicture.h	\
 	gtkiconsetpicture.h	\
 	gtkicontheme.h		\
 	gtkiconthemepicture.h	\
@@ -550,6 +551,7 @@ gtk_base_c_sources = 		\
 	gtkiconcache.c		\
 	gtkiconcachevalidator.c	\
 	gtkiconfactory.c	\
+	gtkiconpicture.c	\
 	gtkiconsetpicture.c	\
 	gtkicontheme.c		\
 	gtkiconthemepicture.c	\
diff --git a/gtk/gtk.h b/gtk/gtk.h
index ad3fab8..6fe5a5b 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -113,6 +113,7 @@
 #include <gtk/gtkhseparator.h>
 #include <gtk/gtkhsv.h>
 #include <gtk/gtkiconfactory.h>
+#include <gtk/gtkiconpicture.h>
 #include <gtk/gtkiconsetpicture.h>
 #include <gtk/gtkicontheme.h>
 #include <gtk/gtkiconthemepicture.h>
diff --git a/gtk/gtkiconpicture.c b/gtk/gtkiconpicture.c
new file mode 100644
index 0000000..7f5ea66
--- /dev/null
+++ b/gtk/gtkiconpicture.c
@@ -0,0 +1,207 @@
+/* GTK - The GIMP Drawing Kit
+ * Copyright (C) 2010 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * 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.
+ */
+
+#include "config.h"
+
+#include "gtkiconpicture.h"
+
+#include "gtkintl.h"
+#include "gtkprivate.h"
+
+struct _GtkIconPicturePrivate {
+  GIcon *icon;
+};
+
+enum {
+  PROP_0,
+  PROP_ICON
+};
+
+G_DEFINE_TYPE (GtkIconPicture, gtk_icon_picture, GTK_TYPE_ICON_THEME_PICTURE)
+
+/**
+ * SECTION:gtkiconsetpicture
+ * @Short_description: Pictures for #GtkIcons
+ * @Title: GtkIconPicture
+ * @See_also: #GtkIcon
+ *
+ * A #GtkIconPicture is an implementation of #GdkPicture for icon sets.
+ */
+
+static void
+gtk_icon_picture_get_property (GObject    *object,
+                                   guint       prop_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
+{
+  GtkIconPicture *picture = GTK_ICON_PICTURE (object);
+  GtkIconPicturePrivate *priv = picture->priv;
+
+  switch (prop_id)
+    {
+    case PROP_ICON:
+      g_value_set_object (value, priv->icon);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gtk_icon_picture_set_property (GObject      *object,
+                                   guint         prop_id,
+                                   const GValue *value,
+                                   GParamSpec   *pspec)
+{
+  GtkIconPicture *picture = GTK_ICON_PICTURE (object);
+
+  switch (prop_id)
+    {
+    case PROP_ICON:
+      gtk_icon_picture_set_icon (picture, g_value_get_object (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gtk_icon_picture_dispose (GObject *object)
+{
+  GtkIconPicture *icon = GTK_ICON_PICTURE (object);
+  GtkIconPicturePrivate *priv = icon->priv;
+
+  if (priv->icon) {
+    g_object_unref (priv->icon);
+    priv->icon = NULL;
+  }
+
+  G_OBJECT_CLASS (gtk_icon_picture_parent_class)->dispose (object);
+}
+
+GtkIconInfo *
+gtk_icon_picture_lookup (GtkIconThemePicture * picture,
+                         GtkIconTheme *        theme,
+                         int                   size,
+                         GtkIconLookupFlags    flags)
+{
+  GtkIconPicture *icon = GTK_ICON_PICTURE (picture);
+  GtkIconPicturePrivate *priv = icon->priv;
+
+  if (priv->icon == NULL)
+    return NULL;
+
+  return gtk_icon_theme_lookup_by_gicon (theme,
+                                         priv->icon,
+                                         size,
+                                         flags);
+}
+
+static void
+gtk_icon_picture_class_init (GtkIconPictureClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkIconThemePictureClass *icon_theme_picture_class = GTK_ICON_THEME_PICTURE_CLASS (klass);
+
+  object_class->get_property = gtk_icon_picture_get_property;
+  object_class->set_property = gtk_icon_picture_set_property;
+  object_class->dispose = gtk_icon_picture_dispose;
+
+  icon_theme_picture_class->lookup = gtk_icon_picture_lookup;
+
+  /**
+   * GtkIconPicture:icon:
+   *
+   * The icon to display.
+   *
+   * Since: 3.2
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_ICON,
+                                   g_param_spec_object ("icon",
+                                                        P_("Icon"),
+                                                        P_("Icon to display"),
+                                                        G_TYPE_ICON,
+                                                        GTK_PARAM_READWRITE));
+
+  g_type_class_add_private (klass, sizeof (GtkIconPicturePrivate));
+}
+
+static void
+gtk_icon_picture_init (GtkIconPicture *picture)
+{
+  picture->priv = G_TYPE_INSTANCE_GET_PRIVATE (picture,
+                                               GTK_TYPE_ICON_PICTURE,
+                                               GtkIconPicturePrivate);
+}
+
+/**
+ * gtk_icon_picture_new:
+ * @icon_name: the name of the icon to display
+ * @size: The icon size to use or -1 for default
+ *
+ * Creates a new #GtkIconPicture displaying the given @icon.
+ *
+ * Returns: a new picture
+ **/
+GdkPicture *
+gtk_icon_picture_new (GIcon *     icon,
+                      GtkIconSize size)
+{
+  return g_object_new (GTK_TYPE_ICON_PICTURE,
+                       "icon", icon,
+                       "size", size,
+                       NULL);
+}
+
+GIcon *
+gtk_icon_picture_get_icon (GtkIconPicture * picture)
+{
+  g_return_val_if_fail (GTK_IS_ICON_PICTURE (picture), NULL);
+
+  return picture->priv->icon;
+}
+
+void
+gtk_icon_picture_set_icon (GtkIconPicture *picture,
+                           GIcon *         icon)
+{
+  GtkIconPicturePrivate *priv;
+
+  g_return_if_fail (GTK_IS_ICON_PICTURE (picture));
+
+  priv = picture->priv;
+
+  if (icon == priv->icon)
+    return;
+
+  if (icon)
+    g_object_ref (icon);
+
+  if (priv->icon)
+    g_object_unref (priv->icon);
+  
+  priv->icon = icon;
+
+  gtk_icon_theme_picture_update (GTK_ICON_THEME_PICTURE (picture));
+  g_object_notify (G_OBJECT (picture), "icon");
+}
+
diff --git a/gtk/gtkiconpicture.h b/gtk/gtkiconpicture.h
new file mode 100644
index 0000000..c415c07
--- /dev/null
+++ b/gtk/gtkiconpicture.h
@@ -0,0 +1,64 @@
+/* GTK - The GIMP Drawing Kit
+ * Copyright (C) 2010 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * 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.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_ICON_PICTURE_H__
+#define __GTK_ICON_PICTURE_H__
+
+#include <gtk/gtkiconthemepicture.h>
+
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_ICON_PICTURE              (gtk_icon_picture_get_type ())
+#define GTK_ICON_PICTURE(o)                (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_ICON_PICTURE, GtkIconPicture))
+#define GTK_ICON_PICTURE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ICON_PICTURE, GtkIconPictureClass))
+#define GTK_IS_ICON_PICTURE(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GTK_TYPE_ICON_PICTURE))
+#define GTK_IS_ICON_PICTURE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ICON_PICTURE))
+#define GTK_ICON_PICTURE_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ICON_PICTURE, GtkIconPictureClass))
+
+typedef struct _GtkIconPicture        GtkIconPicture;
+typedef struct _GtkIconPicturePrivate GtkIconPicturePrivate;
+typedef struct _GtkIconPictureClass   GtkIconPictureClass;
+
+struct _GtkIconPicture {
+  GtkIconThemePicture      parent_picture;
+
+  GtkIconPicturePrivate *  priv;
+};
+
+struct _GtkIconPictureClass {
+  GtkIconThemePictureClass parent_class;
+};
+
+GType           gtk_icon_picture_get_type       (void) G_GNUC_CONST;
+
+GdkPicture *    gtk_icon_picture_new            (GIcon *          icon,
+                                                 GtkIconSize      size);
+
+GIcon *         gtk_icon_picture_get_icon       (GtkIconPicture * picture);
+void            gtk_icon_picture_set_icon       (GtkIconPicture * picture,
+                                                 GIcon *          icon);
+
+G_END_DECLS
+
+#endif /* __GTK_ICON_PICTURE_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]