properties for GtkImage
- From: Havoc Pennington <hp redhat com>
- To: gtk-devel-list gnome org
- Subject: properties for GtkImage
- Date: 26 Aug 2001 00:19:30 -0400
Hi,
Patch appended, will commit shortly. This is bug #59408
Havoc
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.2213
diff -u -p -u -r1.2213 ChangeLog
--- ChangeLog 2001/08/26 02:03:06 1.2213
+++ ChangeLog 2001/08/26 03:55:15
@@ -1,3 +1,13 @@
+2001-08-25 Havoc Pennington <hp pobox com>
+
+ * gtk/gtk-boxed.defs (GtkIconSet): add GtkIconSet
+
+ * gtk/gtkimage.c: Implement property support, bug #59408
+
+ * gtk/gtkcontainer.c (gtk_container_add): make the warning message
+ on reparent-without-removing-first a bit more helpful.
+ Let's just destroy this FAQ.
+
2001-08-24 Havoc Pennington <hp pobox com>
* gtk/gtkcompat.h: remove gtk_menu_* compat defines;
Index: docs/reference/gtk/tmpl/gtkimage.sgml
===================================================================
RCS file: /cvs/gnome/gtk+/docs/reference/gtk/tmpl/gtkimage.sgml,v
retrieving revision 1.8
diff -u -p -u -r1.8 gtkimage.sgml
--- docs/reference/gtk/tmpl/gtkimage.sgml 2001/08/26 02:03:09 1.8
+++ docs/reference/gtk/tmpl/gtkimage.sgml 2001/08/26 03:55:16
@@ -278,3 +278,53 @@ Gets the GtkImage
@mask: a GDKBitmap that indicates which parts of the image should be transparent.
+<!-- ##### ARG GtkImage:pixbuf ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG GtkImage:pixmap ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG GtkImage:image ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG GtkImage:mask ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG GtkImage:file ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG GtkImage:stock ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG GtkImage:icon-set ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG GtkImage:icon-size ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG GtkImage:pixbuf-animation ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG GtkImage:storage-type ##### -->
+<para>
+
+</para>
+
Index: gtk/gtk-boxed.defs
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtk-boxed.defs,v
retrieving revision 1.16
diff -u -p -u -r1.16 gtk-boxed.defs
--- gtk/gtk-boxed.defs 2001/07/25 13:36:02 1.16
+++ gtk/gtk-boxed.defs 2001/08/26 03:55:16
@@ -23,6 +23,11 @@
gtk_requisition_free
"sizeof(GtkRequisition)")
+(define-boxed GtkIconSet
+ gtk_icon_set_ref
+ gtk_icon_set_unref
+ "sizeof(GtkIconSet)")
+
;; TextView
(define-boxed GtkTextIter
Index: gtk/gtkcontainer.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcontainer.c,v
retrieving revision 1.86
diff -u -p -u -r1.86 gtkcontainer.c
--- gtk/gtkcontainer.c 2001/08/23 23:38:32 1.86
+++ gtk/gtkcontainer.c 2001/08/26 03:55:16
@@ -858,7 +858,14 @@ gtk_container_add (GtkContainer *contain
if (widget->parent != NULL)
{
g_warning ("Attempting to add a widget with type %s to a container of "
- "type %s, but the widget is already inside a container of type %s",
+ "type %s, but the widget is already inside a container of type %s, "
+ "what you want to do is:\n"
+ " g_object_ref (G_OBJECT (child));\n",
+ " gtk_container_remove (GTK_CONTAINER (old_container),\n"
+ " child);\n"
+ " gtk_container_add (GTK_CONTAINER (new_container),\n"
+ " child);\n"
+ " g_object_unref (G_OBJECT (child));",
g_type_name (G_OBJECT_TYPE (widget)),
g_type_name (G_OBJECT_TYPE (container)),
g_type_name (G_OBJECT_TYPE (widget->parent)));
Index: gtk/gtkimage.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkimage.c,v
retrieving revision 1.28
diff -u -p -u -r1.28 gtkimage.c
--- gtk/gtkimage.c 2001/08/25 03:15:26 1.28
+++ gtk/gtkimage.c 2001/08/26 03:55:16
@@ -28,8 +28,11 @@
#include "gtkimage.h"
#include "gtkiconfactory.h"
#include "gtkstock.h"
+#include "gtkintl.h"
#include <string.h>
+#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
+
static void gtk_image_class_init (GtkImageClass *klass);
static void gtk_image_init (GtkImage *image);
static gint gtk_image_expose (GtkWidget *widget,
@@ -44,8 +47,32 @@ static void gtk_image_update_size (GtkI
gint image_width,
gint image_height);
+static void gtk_image_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_image_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
static gpointer parent_class;
+enum
+{
+ PROP_0,
+ PROP_PIXBUF,
+ PROP_PIXMAP,
+ PROP_IMAGE,
+ PROP_MASK,
+ PROP_FILE,
+ PROP_STOCK,
+ PROP_ICON_SET,
+ PROP_ICON_SIZE,
+ PROP_PIXBUF_ANIMATION,
+ PROP_STORAGE_TYPE
+};
+
GtkType
gtk_image_get_type (void)
{
@@ -74,20 +101,109 @@ gtk_image_get_type (void)
static void
gtk_image_class_init (GtkImageClass *class)
{
+ GObjectClass *gobject_class;
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
parent_class = g_type_class_peek_parent (class);
- object_class = (GtkObjectClass *) class;
+ gobject_class = G_OBJECT_CLASS (class);
+
+ gobject_class->set_property = gtk_image_set_property;
+ gobject_class->get_property = gtk_image_get_property;
+ object_class = GTK_OBJECT_CLASS (class);
+
object_class->destroy = gtk_image_destroy;
-
- widget_class = (GtkWidgetClass*) class;
+ widget_class = GTK_WIDGET_CLASS (class);
+
widget_class->expose_event = gtk_image_expose;
widget_class->size_request = gtk_image_size_request;
widget_class->unmap = gtk_image_unmap;
+
+ g_object_class_install_property (gobject_class,
+ PROP_PIXBUF,
+ g_param_spec_object ("pixbuf",
+ _("Pixbuf"),
+ _("A GdkPixbuf to display."),
+ GDK_TYPE_PIXBUF,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_PIXMAP,
+ g_param_spec_object ("pixmap",
+ _("Pixmap"),
+ _("A GdkPixmap to display."),
+ GDK_TYPE_PIXMAP,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_IMAGE,
+ g_param_spec_object ("image",
+ _("Image"),
+ _("A GdkImage to display."),
+ GDK_TYPE_IMAGE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_MASK,
+ g_param_spec_object ("mask",
+ _("Mask"),
+ _("Mask bitmap to use with GdkImage or GdkPixmap"),
+ GDK_TYPE_PIXMAP,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_FILE,
+ g_param_spec_string ("file",
+ _("Filename"),
+ _("Filename to load and siplay."),
+ NULL,
+ G_PARAM_WRITABLE));
+
+
+ g_object_class_install_property (gobject_class,
+ PROP_STOCK,
+ g_param_spec_string ("stock",
+ _("Stock ID"),
+ _("Stock ID for a stock image to display."),
+ NULL,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_ICON_SET,
+ g_param_spec_boxed ("icon_set",
+ _("Icon set"),
+ _("Icon set to display."),
+ GTK_TYPE_ICON_SET,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_ICON_SIZE,
+ g_param_spec_int ("icon_size",
+ _("Icon size"),
+ _("Size to use for stock icon or icon set."),
+ 0, G_MAXINT,
+ DEFAULT_ICON_SIZE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_PIXBUF_ANIMATION,
+ g_param_spec_object ("pixbuf_animation",
+ _("Animation"),
+ _("GdkPixbufAnimation to display."),
+ GDK_TYPE_PIXBUF_ANIMATION,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_STORAGE_TYPE,
+ g_param_spec_enum ("storage_type",
+ _("Storage type"),
+ _("The representation being used for image data."),
+ GTK_TYPE_IMAGE_TYPE,
+ GTK_IMAGE_EMPTY,
+ G_PARAM_READABLE));
}
static void
@@ -108,6 +224,201 @@ gtk_image_destroy (GtkObject *object)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
+static GtkIconSize
+get_current_size (GtkImage *image)
+{
+ GtkIconSize size;
+
+ if (image->storage_type == GTK_IMAGE_STOCK)
+ size = image->data.stock.size;
+ else if (image->storage_type == GTK_IMAGE_ICON_SET)
+ size = image->data.icon_set.size;
+ else
+ size = DEFAULT_ICON_SIZE;
+
+ return size;
+}
+
+static GdkBitmap*
+get_current_mask (GtkImage *image)
+{
+ GdkBitmap *mask;
+
+ if (image->storage_type == GTK_IMAGE_PIXMAP)
+ mask = image->data.pixmap.mask;
+ else if (image->storage_type == GTK_IMAGE_IMAGE)
+ mask = image->data.image.mask;
+ else
+ mask = NULL;
+
+ return mask;
+}
+
+static void
+gtk_image_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkImage *image;
+
+ image = GTK_IMAGE (object);
+
+ switch (prop_id)
+ {
+ case PROP_PIXBUF:
+ gtk_image_set_from_pixbuf (image,
+ g_value_get_object (value));
+ break;
+ case PROP_PIXMAP:
+ gtk_image_set_from_pixmap (image,
+ g_value_get_object (value),
+ get_current_mask (image));
+ break;
+ case PROP_IMAGE:
+ gtk_image_set_from_image (image,
+ g_value_get_object (value),
+ get_current_mask (image));
+ break;
+ case PROP_MASK:
+ /* If current storage type doesn't support a mask,
+ * we switch to one that does. This allows setting
+ * mask first then the pixmap or image.
+ */
+ if (image->storage_type == GTK_IMAGE_PIXMAP)
+ gtk_image_set_from_pixmap (image,
+ image->data.pixmap.pixmap,
+ g_value_get_object (value));
+ else if (image->storage_type == GTK_IMAGE_IMAGE)
+ gtk_image_set_from_image (image,
+ image->data.image.image,
+ g_value_get_object (value));
+ else
+ gtk_image_set_from_pixmap (image,
+ NULL,
+ g_value_get_object (value));
+ break;
+ case PROP_FILE:
+ gtk_image_set_from_file (image,
+ g_value_get_string (value));
+ break;
+ case PROP_STOCK:
+ gtk_image_set_from_stock (image, g_value_get_string (value),
+ get_current_size (image));
+ break;
+ case PROP_ICON_SET:
+ gtk_image_set_from_icon_set (image, g_value_get_boxed (value),
+ get_current_size (image));
+ break;
+ case PROP_ICON_SIZE:
+ /* If current storage type doesn't support icon size,
+ * we switch to one that does. This allows setting
+ * size first then the stock ID or icon set
+ */
+ if (image->storage_type == GTK_IMAGE_STOCK)
+ gtk_image_set_from_stock (image,
+ image->data.stock.stock_id,
+ g_value_get_int (value));
+ else if (image->storage_type == GTK_IMAGE_ICON_SET)
+ gtk_image_set_from_icon_set (image,
+ image->data.icon_set.icon_set,
+ g_value_get_int (value));
+ else
+ gtk_image_set_from_stock (image,
+ GTK_STOCK_MISSING_IMAGE,
+ g_value_get_int (value));
+ break;
+ case PROP_PIXBUF_ANIMATION:
+ gtk_image_set_from_animation (image,
+ g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_image_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkImage *image;
+
+ image = GTK_IMAGE (object);
+
+ /* The "getter" functions whine if you try to get the wrong
+ * storage type. This function is instead robust against that,
+ * so that GUI builders don't have to jump through hoops
+ * to avoid g_warning
+ */
+
+ switch (prop_id)
+ {
+ case PROP_PIXBUF:
+ if (image->storage_type != GTK_IMAGE_PIXBUF)
+ g_value_set_object (value, NULL);
+ else
+ g_value_set_object (value,
+ gtk_image_get_pixbuf (image));
+ break;
+ case PROP_PIXMAP:
+ if (image->storage_type != GTK_IMAGE_PIXMAP)
+ g_value_set_object (value, NULL);
+ else
+ g_value_set_object (value,
+ image->data.pixmap.pixmap);
+ break;
+ case PROP_IMAGE:
+ if (image->storage_type != GTK_IMAGE_IMAGE)
+ g_value_set_object (value, NULL);
+ else
+ g_value_set_object (value,
+ image->data.image.image);
+ break;
+ case PROP_STOCK:
+ if (image->storage_type != GTK_IMAGE_STOCK)
+ g_value_set_string (value, NULL);
+ else
+ g_value_set_string (value,
+ image->data.stock.stock_id);
+ break;
+ case PROP_ICON_SET:
+ if (image->storage_type != GTK_IMAGE_ICON_SET)
+ g_value_set_boxed (value, NULL);
+ else
+ g_value_set_boxed (value,
+ image->data.icon_set.icon_set);
+ break;
+ case PROP_ICON_SIZE:
+ if (image->storage_type == GTK_IMAGE_ICON_SET)
+ g_value_set_int (value,
+ image->data.icon_set.size);
+ else if (image->storage_type == GTK_IMAGE_STOCK)
+ g_value_set_int (value,
+ image->data.stock.size);
+ else
+ g_value_set_int (value, DEFAULT_ICON_SIZE);
+ break;
+ case PROP_PIXBUF_ANIMATION:
+ if (image->storage_type != GTK_IMAGE_ANIMATION)
+ g_value_set_object (value, NULL);
+ else
+ g_value_set_object (value,
+ image->data.anim.anim);
+ break;
+ case PROP_STORAGE_TYPE:
+ g_value_set_enum (value, image->storage_type);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
/**
* gtk_image_new_from_pixmap:
@@ -1070,6 +1381,9 @@ gtk_image_expose (GtkWidget *widget
static void
gtk_image_clear (GtkImage *image)
{
+ if (image->storage_type != GTK_IMAGE_EMPTY)
+ g_object_notify (G_OBJECT (image), "storage_type");
+
switch (image->storage_type)
{
case GTK_IMAGE_PIXMAP:
@@ -1080,6 +1394,9 @@ gtk_image_clear (GtkImage *image)
if (image->data.pixmap.mask)
g_object_unref (G_OBJECT (image->data.pixmap.mask));
+ g_object_notify (G_OBJECT (image), "pixmap");
+ g_object_notify (G_OBJECT (image), "mask");
+
break;
case GTK_IMAGE_IMAGE:
@@ -1090,6 +1407,9 @@ gtk_image_clear (GtkImage *image)
if (image->data.image.mask)
g_object_unref (G_OBJECT (image->data.image.mask));
+ g_object_notify (G_OBJECT (image), "image");
+ g_object_notify (G_OBJECT (image), "mask");
+
break;
case GTK_IMAGE_PIXBUF:
@@ -1097,17 +1417,25 @@ gtk_image_clear (GtkImage *image)
if (image->data.pixbuf.pixbuf)
g_object_unref (G_OBJECT (image->data.pixbuf.pixbuf));
+ g_object_notify (G_OBJECT (image), "pixbuf");
+
break;
case GTK_IMAGE_STOCK:
g_free (image->data.stock.stock_id);
+
+ g_object_notify (G_OBJECT (image), "stock");
+ g_object_notify (G_OBJECT (image), "icon_size");
break;
case GTK_IMAGE_ICON_SET:
if (image->data.icon_set.icon_set)
gtk_icon_set_unref (image->data.icon_set.icon_set);
+
+ g_object_notify (G_OBJECT (image), "icon_set");
+ g_object_notify (G_OBJECT (image), "icon_size");
break;
@@ -1116,7 +1444,10 @@ gtk_image_clear (GtkImage *image)
g_source_remove (image->data.anim.frame_timeout);
if (image->data.anim.anim)
- g_object_unref (G_OBJECT (image->data.anim.anim));
+ g_object_unref (G_OBJECT (image->data.anim.anim));
+
+ g_object_notify (G_OBJECT (image), "pixbuf_animation");
+
break;
case GTK_IMAGE_EMPTY:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]