Blame gtk/gtkcellrendererpixbuf.c

Packit 98cdb6
/* gtkcellrendererpixbuf.c
Packit 98cdb6
 * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
Packit 98cdb6
 *
Packit 98cdb6
 * This library is free software; you can redistribute it and/or
Packit 98cdb6
 * modify it under the terms of the GNU Library General Public
Packit 98cdb6
 * License as published by the Free Software Foundation; either
Packit 98cdb6
 * version 2 of the License, or (at your option) any later version.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is distributed in the hope that it will be useful,
Packit 98cdb6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
 * Library General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Library General Public
Packit 98cdb6
 * License along with this library; if not, write to the
Packit 98cdb6
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
#include <stdlib.h>
Packit 98cdb6
#include "gtkcellrendererpixbuf.h"
Packit 98cdb6
#include "gtkiconfactory.h"
Packit 98cdb6
#include "gtkicontheme.h"
Packit 98cdb6
#include "gtkintl.h"
Packit 98cdb6
#include "gtkprivate.h"
Packit 98cdb6
#include "gtkalias.h"
Packit 98cdb6
Packit 98cdb6
static void gtk_cell_renderer_pixbuf_get_property  (GObject                    *object,
Packit 98cdb6
						    guint                       param_id,
Packit 98cdb6
						    GValue                     *value,
Packit 98cdb6
						    GParamSpec                 *pspec);
Packit 98cdb6
static void gtk_cell_renderer_pixbuf_set_property  (GObject                    *object,
Packit 98cdb6
						    guint                       param_id,
Packit 98cdb6
						    const GValue               *value,
Packit 98cdb6
						    GParamSpec                 *pspec);
Packit 98cdb6
static void gtk_cell_renderer_pixbuf_finalize   (GObject                    *object);
Packit 98cdb6
static void gtk_cell_renderer_pixbuf_create_stock_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
Packit 98cdb6
							  GtkWidget             *widget);
Packit 98cdb6
static void gtk_cell_renderer_pixbuf_get_size   (GtkCellRenderer            *cell,
Packit 98cdb6
						 GtkWidget                  *widget,
Packit 98cdb6
						 GdkRectangle               *rectangle,
Packit 98cdb6
						 gint                       *x_offset,
Packit 98cdb6
						 gint                       *y_offset,
Packit 98cdb6
						 gint                       *width,
Packit 98cdb6
						 gint                       *height);
Packit 98cdb6
static void gtk_cell_renderer_pixbuf_render     (GtkCellRenderer            *cell,
Packit 98cdb6
						 GdkDrawable                *window,
Packit 98cdb6
						 GtkWidget                  *widget,
Packit 98cdb6
						 GdkRectangle               *background_area,
Packit 98cdb6
						 GdkRectangle               *cell_area,
Packit 98cdb6
						 GdkRectangle               *expose_area,
Packit 98cdb6
						 GtkCellRendererState        flags);
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
enum {
Packit 98cdb6
  PROP_0,
Packit 98cdb6
  PROP_PIXBUF,
Packit 98cdb6
  PROP_PIXBUF_EXPANDER_OPEN,
Packit 98cdb6
  PROP_PIXBUF_EXPANDER_CLOSED,
Packit 98cdb6
  PROP_STOCK_ID,
Packit 98cdb6
  PROP_STOCK_SIZE,
Packit 98cdb6
  PROP_STOCK_DETAIL,
Packit 98cdb6
  PROP_FOLLOW_STATE,
Packit 98cdb6
  PROP_ICON_NAME,
Packit 98cdb6
  PROP_GICON
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
#define GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER_PIXBUF, GtkCellRendererPixbufPrivate))
Packit 98cdb6
Packit 98cdb6
typedef struct _GtkCellRendererPixbufPrivate GtkCellRendererPixbufPrivate;
Packit 98cdb6
struct _GtkCellRendererPixbufPrivate
Packit 98cdb6
{
Packit 98cdb6
  gchar *stock_id;
Packit 98cdb6
  GtkIconSize stock_size;
Packit 98cdb6
  gchar *stock_detail;
Packit 98cdb6
  gboolean follow_state;
Packit 98cdb6
  gchar *icon_name;
Packit 98cdb6
  GIcon *gicon;
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
G_DEFINE_TYPE (GtkCellRendererPixbuf, gtk_cell_renderer_pixbuf, GTK_TYPE_CELL_RENDERER)
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_cell_renderer_pixbuf_init (GtkCellRendererPixbuf *cellpixbuf)
Packit 98cdb6
{
Packit 98cdb6
  GtkCellRendererPixbufPrivate *priv;
Packit 98cdb6
Packit 98cdb6
  priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cellpixbuf);
Packit 98cdb6
  priv->stock_size = GTK_ICON_SIZE_MENU;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_cell_renderer_pixbuf_class_init (GtkCellRendererPixbufClass *class)
Packit 98cdb6
{
Packit 98cdb6
  GObjectClass *object_class = G_OBJECT_CLASS (class);
Packit 98cdb6
  GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
Packit 98cdb6
Packit 98cdb6
  object_class->finalize = gtk_cell_renderer_pixbuf_finalize;
Packit 98cdb6
Packit 98cdb6
  object_class->get_property = gtk_cell_renderer_pixbuf_get_property;
Packit 98cdb6
  object_class->set_property = gtk_cell_renderer_pixbuf_set_property;
Packit 98cdb6
Packit 98cdb6
  cell_class->get_size = gtk_cell_renderer_pixbuf_get_size;
Packit 98cdb6
  cell_class->render = gtk_cell_renderer_pixbuf_render;
Packit 98cdb6
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
				   PROP_PIXBUF,
Packit 98cdb6
				   g_param_spec_object ("pixbuf",
Packit 98cdb6
							P_("Pixbuf Object"),
Packit 98cdb6
							P_("The pixbuf to render"),
Packit 98cdb6
							GDK_TYPE_PIXBUF,
Packit 98cdb6
							GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
				   PROP_PIXBUF_EXPANDER_OPEN,
Packit 98cdb6
				   g_param_spec_object ("pixbuf-expander-open",
Packit 98cdb6
							P_("Pixbuf Expander Open"),
Packit 98cdb6
							P_("Pixbuf for open expander"),
Packit 98cdb6
							GDK_TYPE_PIXBUF,
Packit 98cdb6
							GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
				   PROP_PIXBUF_EXPANDER_CLOSED,
Packit 98cdb6
				   g_param_spec_object ("pixbuf-expander-closed",
Packit 98cdb6
							P_("Pixbuf Expander Closed"),
Packit 98cdb6
							P_("Pixbuf for closed expander"),
Packit 98cdb6
							GDK_TYPE_PIXBUF,
Packit 98cdb6
							GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
				   PROP_STOCK_ID,
Packit 98cdb6
				   g_param_spec_string ("stock-id",
Packit 98cdb6
							P_("Stock ID"),
Packit 98cdb6
							P_("The stock ID of the stock icon to render"),
Packit 98cdb6
							NULL,
Packit 98cdb6
							GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
				   PROP_STOCK_SIZE,
Packit 98cdb6
				   g_param_spec_uint ("stock-size",
Packit 98cdb6
						      P_("Size"),
Packit 98cdb6
						      P_("The GtkIconSize value that specifies the size of the rendered icon"),
Packit 98cdb6
						      0,
Packit 98cdb6
						      G_MAXUINT,
Packit 98cdb6
						      GTK_ICON_SIZE_MENU,
Packit 98cdb6
						      GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
				   PROP_STOCK_DETAIL,
Packit 98cdb6
				   g_param_spec_string ("stock-detail",
Packit 98cdb6
							P_("Detail"),
Packit 98cdb6
							P_("Render detail to pass to the theme engine"),
Packit 98cdb6
							NULL,
Packit 98cdb6
							GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  
Packit 98cdb6
  /**
Packit 98cdb6
   * GtkCellRendererPixbuf:icon-name:
Packit 98cdb6
   *
Packit 98cdb6
   * The name of the themed icon to display.
Packit 98cdb6
   * This property only has an effect if not overridden by "stock_id" 
Packit 98cdb6
   * or "pixbuf" properties.
Packit 98cdb6
   *
Packit 98cdb6
   * Since: 2.8 
Packit 98cdb6
   */
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
				   PROP_ICON_NAME,
Packit 98cdb6
				   g_param_spec_string ("icon-name",
Packit 98cdb6
							P_("Icon Name"),
Packit 98cdb6
							P_("The name of the icon from the icon theme"),
Packit 98cdb6
							NULL,
Packit 98cdb6
							GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  /**
Packit 98cdb6
   * GtkCellRendererPixbuf:follow-state:
Packit 98cdb6
   *
Packit 98cdb6
   * Specifies whether the rendered pixbuf should be colorized
Packit 98cdb6
   * according to the #GtkCellRendererState.
Packit 98cdb6
   *
Packit 98cdb6
   * Since: 2.8
Packit 98cdb6
   */
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
				   PROP_FOLLOW_STATE,
Packit 98cdb6
				   g_param_spec_boolean ("follow-state",
Packit 98cdb6
 							 P_("Follow State"),
Packit 98cdb6
 							 P_("Whether the rendered pixbuf should be "
Packit 98cdb6
							    "colorized according to the state"),
Packit 98cdb6
 							 FALSE,
Packit 98cdb6
 							 GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  /**
Packit 98cdb6
   * GtkCellRendererPixbuf:gicon:
Packit 98cdb6
   *
Packit 98cdb6
   * The GIcon representing the icon to display.
Packit 98cdb6
   * If the icon theme is changed, the image will be updated
Packit 98cdb6
   * automatically.
Packit 98cdb6
   *
Packit 98cdb6
   * Since: 2.14
Packit 98cdb6
   */
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
                                   PROP_GICON,
Packit 98cdb6
                                   g_param_spec_object ("gicon",
Packit 98cdb6
                                                        P_("Icon"),
Packit 98cdb6
                                                        P_("The GIcon being displayed"),
Packit 98cdb6
                                                        G_TYPE_ICON,
Packit 98cdb6
                                                        GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
  g_type_class_add_private (object_class, sizeof (GtkCellRendererPixbufPrivate));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_cell_renderer_pixbuf_finalize (GObject *object)
Packit 98cdb6
{
Packit 98cdb6
  GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
Packit 98cdb6
  GtkCellRendererPixbufPrivate *priv;
Packit 98cdb6
Packit 98cdb6
  priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (object);
Packit 98cdb6
  
Packit 98cdb6
  if (cellpixbuf->pixbuf)
Packit 98cdb6
    g_object_unref (cellpixbuf->pixbuf);
Packit 98cdb6
  if (cellpixbuf->pixbuf_expander_open)
Packit 98cdb6
    g_object_unref (cellpixbuf->pixbuf_expander_open);
Packit 98cdb6
  if (cellpixbuf->pixbuf_expander_closed)
Packit 98cdb6
    g_object_unref (cellpixbuf->pixbuf_expander_closed);
Packit 98cdb6
Packit 98cdb6
  g_free (priv->stock_id);
Packit 98cdb6
  g_free (priv->stock_detail);
Packit 98cdb6
  g_free (priv->icon_name);
Packit 98cdb6
Packit 98cdb6
  if (priv->gicon)
Packit 98cdb6
    g_object_unref (priv->gicon);
Packit 98cdb6
Packit 98cdb6
  G_OBJECT_CLASS (gtk_cell_renderer_pixbuf_parent_class)->finalize (object);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_cell_renderer_pixbuf_get_property (GObject        *object,
Packit 98cdb6
				       guint           param_id,
Packit 98cdb6
				       GValue         *value,
Packit 98cdb6
				       GParamSpec     *pspec)
Packit 98cdb6
{
Packit 98cdb6
  GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
Packit 98cdb6
  GtkCellRendererPixbufPrivate *priv;
Packit 98cdb6
Packit 98cdb6
  priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (object);
Packit 98cdb6
  
Packit 98cdb6
  switch (param_id)
Packit 98cdb6
    {
Packit 98cdb6
    case PROP_PIXBUF:
Packit 98cdb6
      g_value_set_object (value, cellpixbuf->pixbuf);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_PIXBUF_EXPANDER_OPEN:
Packit 98cdb6
      g_value_set_object (value, cellpixbuf->pixbuf_expander_open);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_PIXBUF_EXPANDER_CLOSED:
Packit 98cdb6
      g_value_set_object (value, cellpixbuf->pixbuf_expander_closed);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_STOCK_ID:
Packit 98cdb6
      g_value_set_string (value, priv->stock_id);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_STOCK_SIZE:
Packit 98cdb6
      g_value_set_uint (value, priv->stock_size);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_STOCK_DETAIL:
Packit 98cdb6
      g_value_set_string (value, priv->stock_detail);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_FOLLOW_STATE:
Packit 98cdb6
      g_value_set_boolean (value, priv->follow_state);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_ICON_NAME:
Packit 98cdb6
      g_value_set_string (value, priv->icon_name);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_GICON:
Packit 98cdb6
      g_value_set_object (value, priv->gicon);
Packit 98cdb6
      break;
Packit 98cdb6
    default:
Packit 98cdb6
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_cell_renderer_pixbuf_set_property (GObject      *object,
Packit 98cdb6
				       guint         param_id,
Packit 98cdb6
				       const GValue *value,
Packit 98cdb6
				       GParamSpec   *pspec)
Packit 98cdb6
{
Packit 98cdb6
  GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
Packit 98cdb6
  GtkCellRendererPixbufPrivate *priv;
Packit 98cdb6
Packit 98cdb6
  priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (object);
Packit 98cdb6
  
Packit 98cdb6
  switch (param_id)
Packit 98cdb6
    {
Packit 98cdb6
    case PROP_PIXBUF:
Packit 98cdb6
      if (cellpixbuf->pixbuf)
Packit 98cdb6
	g_object_unref (cellpixbuf->pixbuf);
Packit 98cdb6
      cellpixbuf->pixbuf = (GdkPixbuf*) g_value_dup_object (value);
Packit 98cdb6
      if (cellpixbuf->pixbuf)
Packit 98cdb6
        {
Packit 98cdb6
          if (priv->stock_id)
Packit 98cdb6
            {
Packit 98cdb6
              g_free (priv->stock_id);
Packit 98cdb6
              priv->stock_id = NULL;
Packit 98cdb6
              g_object_notify (object, "stock-id");
Packit 98cdb6
            }
Packit 98cdb6
          if (priv->icon_name)
Packit 98cdb6
            {
Packit 98cdb6
              g_free (priv->icon_name);
Packit 98cdb6
              priv->icon_name = NULL;
Packit 98cdb6
              g_object_notify (object, "icon-name");
Packit 98cdb6
            }
Packit 98cdb6
          if (priv->gicon)
Packit 98cdb6
            {
Packit 98cdb6
              g_object_unref (priv->gicon);
Packit 98cdb6
              priv->gicon = NULL;
Packit 98cdb6
              g_object_notify (object, "gicon");
Packit 98cdb6
            }
Packit 98cdb6
        }
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_PIXBUF_EXPANDER_OPEN:
Packit 98cdb6
      if (cellpixbuf->pixbuf_expander_open)
Packit 98cdb6
	g_object_unref (cellpixbuf->pixbuf_expander_open);
Packit 98cdb6
      cellpixbuf->pixbuf_expander_open = (GdkPixbuf*) g_value_dup_object (value);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_PIXBUF_EXPANDER_CLOSED:
Packit 98cdb6
      if (cellpixbuf->pixbuf_expander_closed)
Packit 98cdb6
	g_object_unref (cellpixbuf->pixbuf_expander_closed);
Packit 98cdb6
      cellpixbuf->pixbuf_expander_closed = (GdkPixbuf*) g_value_dup_object (value);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_STOCK_ID:
Packit 98cdb6
      if (priv->stock_id)
Packit 98cdb6
        {
Packit 98cdb6
          if (cellpixbuf->pixbuf)
Packit 98cdb6
            {
Packit 98cdb6
              g_object_unref (cellpixbuf->pixbuf);
Packit 98cdb6
              cellpixbuf->pixbuf = NULL;
Packit 98cdb6
              g_object_notify (object, "pixbuf");
Packit 98cdb6
            }
Packit 98cdb6
          g_free (priv->stock_id);
Packit 98cdb6
        }
Packit 98cdb6
      priv->stock_id = g_value_dup_string (value);
Packit 98cdb6
      if (priv->stock_id)
Packit 98cdb6
        {
Packit 98cdb6
          if (cellpixbuf->pixbuf)
Packit 98cdb6
            {
Packit 98cdb6
              g_object_unref (cellpixbuf->pixbuf);
Packit 98cdb6
              cellpixbuf->pixbuf = NULL;
Packit 98cdb6
              g_object_notify (object, "pixbuf");
Packit 98cdb6
            }
Packit 98cdb6
          if (priv->icon_name)
Packit 98cdb6
            {
Packit 98cdb6
              g_free (priv->icon_name);
Packit 98cdb6
              priv->icon_name = NULL;
Packit 98cdb6
              g_object_notify (object, "icon-name");
Packit 98cdb6
            }
Packit 98cdb6
          if (priv->gicon)
Packit 98cdb6
            {
Packit 98cdb6
              g_object_unref (priv->gicon);
Packit 98cdb6
              priv->gicon = NULL;
Packit 98cdb6
              g_object_notify (object, "gicon");
Packit 98cdb6
            }
Packit 98cdb6
        }
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_STOCK_SIZE:
Packit 98cdb6
      priv->stock_size = g_value_get_uint (value);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_STOCK_DETAIL:
Packit 98cdb6
      g_free (priv->stock_detail);
Packit 98cdb6
      priv->stock_detail = g_value_dup_string (value);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_ICON_NAME:
Packit 98cdb6
      if (priv->icon_name)
Packit 98cdb6
	{
Packit 98cdb6
	  if (cellpixbuf->pixbuf)
Packit 98cdb6
	    {
Packit 98cdb6
	      g_object_unref (cellpixbuf->pixbuf);
Packit 98cdb6
	      cellpixbuf->pixbuf = NULL;
Packit 98cdb6
              g_object_notify (object, "pixbuf");
Packit 98cdb6
	    }
Packit 98cdb6
	  g_free (priv->icon_name);
Packit 98cdb6
	}
Packit 98cdb6
      priv->icon_name = g_value_dup_string (value);
Packit 98cdb6
      if (priv->icon_name)
Packit 98cdb6
        {
Packit 98cdb6
	  if (cellpixbuf->pixbuf)
Packit 98cdb6
	    {
Packit 98cdb6
              g_object_unref (cellpixbuf->pixbuf);
Packit 98cdb6
              cellpixbuf->pixbuf = NULL;
Packit 98cdb6
              g_object_notify (object, "pixbuf");
Packit 98cdb6
	    }
Packit 98cdb6
          if (priv->stock_id)
Packit 98cdb6
            {
Packit 98cdb6
              g_free (priv->stock_id);
Packit 98cdb6
              priv->stock_id = NULL;
Packit 98cdb6
              g_object_notify (object, "stock-id");
Packit 98cdb6
            }
Packit 98cdb6
          if (priv->gicon)
Packit 98cdb6
            {
Packit 98cdb6
              g_object_unref (priv->gicon);
Packit 98cdb6
              priv->gicon = NULL;
Packit 98cdb6
              g_object_notify (object, "gicon");
Packit 98cdb6
            }
Packit 98cdb6
        }
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_FOLLOW_STATE:
Packit 98cdb6
      priv->follow_state = g_value_get_boolean (value);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_GICON:
Packit 98cdb6
      if (priv->gicon)
Packit 98cdb6
	{
Packit 98cdb6
	  if (cellpixbuf->pixbuf)
Packit 98cdb6
	    {
Packit 98cdb6
	      g_object_unref (cellpixbuf->pixbuf);
Packit 98cdb6
	      cellpixbuf->pixbuf = NULL;
Packit 98cdb6
              g_object_notify (object, "pixbuf");
Packit 98cdb6
	    }
Packit 98cdb6
	  g_object_unref (priv->gicon);
Packit 98cdb6
	}
Packit 98cdb6
      priv->gicon = (GIcon *) g_value_dup_object (value);
Packit 98cdb6
      if (priv->gicon)
Packit 98cdb6
        {
Packit 98cdb6
	  if (cellpixbuf->pixbuf)
Packit 98cdb6
	    {
Packit 98cdb6
              g_object_unref (cellpixbuf->pixbuf);
Packit 98cdb6
              cellpixbuf->pixbuf = NULL;
Packit 98cdb6
              g_object_notify (object, "pixbuf");
Packit 98cdb6
	    }
Packit 98cdb6
          if (priv->stock_id)
Packit 98cdb6
            {
Packit 98cdb6
              g_free (priv->stock_id);
Packit 98cdb6
              priv->stock_id = NULL;
Packit 98cdb6
              g_object_notify (object, "stock-id");
Packit 98cdb6
            }
Packit 98cdb6
          if (priv->icon_name)
Packit 98cdb6
            {
Packit 98cdb6
              g_free (priv->icon_name);
Packit 98cdb6
              priv->icon_name = NULL;
Packit 98cdb6
              g_object_notify (object, "icon-name");
Packit 98cdb6
            }
Packit 98cdb6
        }
Packit 98cdb6
      break;
Packit 98cdb6
    default:
Packit 98cdb6
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_cell_renderer_pixbuf_new:
Packit 98cdb6
 * 
Packit 98cdb6
 * Creates a new #GtkCellRendererPixbuf. Adjust rendering
Packit 98cdb6
 * parameters using object properties. Object properties can be set
Packit 98cdb6
 * globally (with g_object_set()). Also, with #GtkTreeViewColumn, you
Packit 98cdb6
 * can bind a property to a value in a #GtkTreeModel. For example, you
Packit 98cdb6
 * can bind the "pixbuf" property on the cell renderer to a pixbuf value
Packit 98cdb6
 * in the model, thus rendering a different image in each row of the
Packit 98cdb6
 * #GtkTreeView.
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the new cell renderer
Packit 98cdb6
 **/
Packit 98cdb6
GtkCellRenderer *
Packit 98cdb6
gtk_cell_renderer_pixbuf_new (void)
Packit 98cdb6
{
Packit 98cdb6
  return g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF, NULL);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_cell_renderer_pixbuf_create_stock_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
Packit 98cdb6
                                              GtkWidget             *widget)
Packit 98cdb6
{
Packit 98cdb6
  GtkCellRendererPixbufPrivate *priv;
Packit 98cdb6
Packit 98cdb6
  priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cellpixbuf);
Packit 98cdb6
Packit 98cdb6
  if (cellpixbuf->pixbuf)
Packit 98cdb6
    g_object_unref (cellpixbuf->pixbuf);
Packit 98cdb6
Packit 98cdb6
  cellpixbuf->pixbuf = gtk_widget_render_icon (widget,
Packit 98cdb6
                                               priv->stock_id,
Packit 98cdb6
                                               priv->stock_size,
Packit 98cdb6
                                               priv->stock_detail);
Packit 98cdb6
Packit 98cdb6
  g_object_notify (G_OBJECT (cellpixbuf), "pixbuf");
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void 
Packit 98cdb6
gtk_cell_renderer_pixbuf_create_themed_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
Packit 98cdb6
					       GtkWidget             *widget)
Packit 98cdb6
{
Packit 98cdb6
  GtkCellRendererPixbufPrivate *priv;
Packit 98cdb6
  GdkScreen *screen;
Packit 98cdb6
  GtkIconTheme *icon_theme;
Packit 98cdb6
  GtkSettings *settings;
Packit 98cdb6
  gint width, height;
Packit 98cdb6
Packit 98cdb6
  priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cellpixbuf);
Packit 98cdb6
Packit 98cdb6
  if (cellpixbuf->pixbuf)
Packit 98cdb6
    {
Packit 98cdb6
      g_object_unref (cellpixbuf->pixbuf);
Packit 98cdb6
      cellpixbuf->pixbuf = NULL;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  screen = gtk_widget_get_screen (GTK_WIDGET (widget));
Packit 98cdb6
  icon_theme = gtk_icon_theme_get_for_screen (screen);
Packit 98cdb6
  settings = gtk_settings_get_for_screen (screen);
Packit 98cdb6
Packit 98cdb6
  if (!gtk_icon_size_lookup_for_settings (settings,
Packit 98cdb6
					  priv->stock_size,
Packit 98cdb6
					  &width, &height))
Packit 98cdb6
    {
Packit 98cdb6
      g_warning ("Invalid icon size %u\n", priv->stock_size);
Packit 98cdb6
      width = height = 24;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (priv->icon_name)
Packit 98cdb6
    cellpixbuf->pixbuf = gtk_icon_theme_load_icon (icon_theme,
Packit 98cdb6
			                           priv->icon_name,
Packit 98cdb6
			                           MIN (width, height), 
Packit 98cdb6
                                                   GTK_ICON_LOOKUP_USE_BUILTIN,
Packit 98cdb6
                                                   NULL);
Packit 98cdb6
  else if (priv->gicon)
Packit 98cdb6
    {
Packit 98cdb6
      GtkIconInfo *info;
Packit 98cdb6
Packit 98cdb6
      info = gtk_icon_theme_lookup_by_gicon (icon_theme,
Packit 98cdb6
                                             priv->gicon,
Packit 98cdb6
			                     MIN (width, height), 
Packit 98cdb6
                                             GTK_ICON_LOOKUP_USE_BUILTIN);
Packit 98cdb6
      if (info)
Packit 98cdb6
        {
Packit 98cdb6
          cellpixbuf->pixbuf = gtk_icon_info_load_icon (info, NULL);
Packit 98cdb6
          gtk_icon_info_free (info);
Packit 98cdb6
        }
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  g_object_notify (G_OBJECT (cellpixbuf), "pixbuf");
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static GdkPixbuf *
Packit 98cdb6
create_colorized_pixbuf (GdkPixbuf *src, 
Packit 98cdb6
			 GdkColor  *new_color)
Packit 98cdb6
{
Packit 98cdb6
  gint i, j;
Packit 98cdb6
  gint width, height, has_alpha, src_row_stride, dst_row_stride;
Packit 98cdb6
  gint red_value, green_value, blue_value;
Packit 98cdb6
  guchar *target_pixels;
Packit 98cdb6
  guchar *original_pixels;
Packit 98cdb6
  guchar *pixsrc;
Packit 98cdb6
  guchar *pixdest;
Packit 98cdb6
  GdkPixbuf *dest;
Packit 98cdb6
  
Packit 98cdb6
  red_value = new_color->red / 255.0;
Packit 98cdb6
  green_value = new_color->green / 255.0;
Packit 98cdb6
  blue_value = new_color->blue / 255.0;
Packit 98cdb6
  
Packit 98cdb6
  dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
Packit 98cdb6
			 gdk_pixbuf_get_has_alpha (src),
Packit 98cdb6
			 gdk_pixbuf_get_bits_per_sample (src),
Packit 98cdb6
			 gdk_pixbuf_get_width (src),
Packit 98cdb6
			 gdk_pixbuf_get_height (src));
Packit 98cdb6
  
Packit 98cdb6
  has_alpha = gdk_pixbuf_get_has_alpha (src);
Packit 98cdb6
  width = gdk_pixbuf_get_width (src);
Packit 98cdb6
  height = gdk_pixbuf_get_height (src);
Packit 98cdb6
  src_row_stride = gdk_pixbuf_get_rowstride (src);
Packit 98cdb6
  dst_row_stride = gdk_pixbuf_get_rowstride (dest);
Packit 98cdb6
  target_pixels = gdk_pixbuf_get_pixels (dest);
Packit 98cdb6
  original_pixels = gdk_pixbuf_get_pixels (src);
Packit 98cdb6
  
Packit 98cdb6
  for (i = 0; i < height; i++) {
Packit 98cdb6
    pixdest = target_pixels + i*dst_row_stride;
Packit 98cdb6
    pixsrc = original_pixels + i*src_row_stride;
Packit 98cdb6
    for (j = 0; j < width; j++) {		
Packit 98cdb6
      *pixdest++ = (*pixsrc++ * red_value) >> 8;
Packit 98cdb6
      *pixdest++ = (*pixsrc++ * green_value) >> 8;
Packit 98cdb6
      *pixdest++ = (*pixsrc++ * blue_value) >> 8;
Packit 98cdb6
      if (has_alpha) {
Packit 98cdb6
	*pixdest++ = *pixsrc++;
Packit 98cdb6
      }
Packit 98cdb6
    }
Packit 98cdb6
  }
Packit 98cdb6
  return dest;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
Packit 98cdb6
				   GtkWidget       *widget,
Packit 98cdb6
				   GdkRectangle    *cell_area,
Packit 98cdb6
				   gint            *x_offset,
Packit 98cdb6
				   gint            *y_offset,
Packit 98cdb6
				   gint            *width,
Packit 98cdb6
				   gint            *height)
Packit 98cdb6
{
Packit 98cdb6
  GtkCellRendererPixbuf *cellpixbuf = (GtkCellRendererPixbuf *) cell;
Packit 98cdb6
  GtkCellRendererPixbufPrivate *priv;
Packit 98cdb6
  gint pixbuf_width  = 0;
Packit 98cdb6
  gint pixbuf_height = 0;
Packit 98cdb6
  gint calc_width;
Packit 98cdb6
  gint calc_height;
Packit 98cdb6
Packit 98cdb6
  priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cell);
Packit 98cdb6
Packit 98cdb6
  if (!cellpixbuf->pixbuf)
Packit 98cdb6
    {
Packit 98cdb6
      if (priv->stock_id)
Packit 98cdb6
	gtk_cell_renderer_pixbuf_create_stock_pixbuf (cellpixbuf, widget);
Packit 98cdb6
      else if (priv->icon_name || priv->gicon)
Packit 98cdb6
	gtk_cell_renderer_pixbuf_create_themed_pixbuf (cellpixbuf, widget);
Packit 98cdb6
    }
Packit 98cdb6
  
Packit 98cdb6
  if (cellpixbuf->pixbuf)
Packit 98cdb6
    {
Packit 98cdb6
      pixbuf_width  = gdk_pixbuf_get_width (cellpixbuf->pixbuf);
Packit 98cdb6
      pixbuf_height = gdk_pixbuf_get_height (cellpixbuf->pixbuf);
Packit 98cdb6
    }
Packit 98cdb6
  if (cellpixbuf->pixbuf_expander_open)
Packit 98cdb6
    {
Packit 98cdb6
      pixbuf_width  = MAX (pixbuf_width, gdk_pixbuf_get_width (cellpixbuf->pixbuf_expander_open));
Packit 98cdb6
      pixbuf_height = MAX (pixbuf_height, gdk_pixbuf_get_height (cellpixbuf->pixbuf_expander_open));
Packit 98cdb6
    }
Packit 98cdb6
  if (cellpixbuf->pixbuf_expander_closed)
Packit 98cdb6
    {
Packit 98cdb6
      pixbuf_width  = MAX (pixbuf_width, gdk_pixbuf_get_width (cellpixbuf->pixbuf_expander_closed));
Packit 98cdb6
      pixbuf_height = MAX (pixbuf_height, gdk_pixbuf_get_height (cellpixbuf->pixbuf_expander_closed));
Packit 98cdb6
    }
Packit 98cdb6
  
Packit 98cdb6
  calc_width  = (gint) cell->xpad * 2 + pixbuf_width;
Packit 98cdb6
  calc_height = (gint) cell->ypad * 2 + pixbuf_height;
Packit 98cdb6
  
Packit 98cdb6
  if (cell_area && pixbuf_width > 0 && pixbuf_height > 0)
Packit 98cdb6
    {
Packit 98cdb6
      if (x_offset)
Packit 98cdb6
	{
Packit 98cdb6
	  *x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
Packit 98cdb6
                        (1.0 - cell->xalign) : cell->xalign) * 
Packit 98cdb6
                       (cell_area->width - calc_width));
Packit 98cdb6
	  *x_offset = MAX (*x_offset, 0);
Packit 98cdb6
	}
Packit 98cdb6
      if (y_offset)
Packit 98cdb6
	{
Packit 98cdb6
	  *y_offset = (cell->yalign *
Packit 98cdb6
                       (cell_area->height - calc_height));
Packit 98cdb6
          *y_offset = MAX (*y_offset, 0);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      if (x_offset) *x_offset = 0;
Packit 98cdb6
      if (y_offset) *y_offset = 0;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (width)
Packit 98cdb6
    *width = calc_width;
Packit 98cdb6
  
Packit 98cdb6
  if (height)
Packit 98cdb6
    *height = calc_height;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_cell_renderer_pixbuf_render (GtkCellRenderer      *cell,
Packit 98cdb6
				 GdkWindow            *window,
Packit 98cdb6
				 GtkWidget            *widget,
Packit 98cdb6
				 GdkRectangle         *background_area,
Packit 98cdb6
				 GdkRectangle         *cell_area,
Packit 98cdb6
				 GdkRectangle         *expose_area,
Packit 98cdb6
				 GtkCellRendererState  flags)
Packit 98cdb6
Packit 98cdb6
{
Packit 98cdb6
  GtkCellRendererPixbuf *cellpixbuf = (GtkCellRendererPixbuf *) cell;
Packit 98cdb6
  GtkCellRendererPixbufPrivate *priv;
Packit 98cdb6
  GdkPixbuf *pixbuf;
Packit 98cdb6
  GdkPixbuf *invisible = NULL;
Packit 98cdb6
  GdkPixbuf *colorized = NULL;
Packit 98cdb6
  GdkRectangle pix_rect;
Packit 98cdb6
  GdkRectangle draw_rect;
Packit 98cdb6
  cairo_t *cr;
Packit 98cdb6
Packit 98cdb6
  priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cell);
Packit 98cdb6
Packit 98cdb6
  gtk_cell_renderer_pixbuf_get_size (cell, widget, cell_area,
Packit 98cdb6
				     &pix_rect.x,
Packit 98cdb6
				     &pix_rect.y,
Packit 98cdb6
				     &pix_rect.width,
Packit 98cdb6
				     &pix_rect.height);
Packit 98cdb6
Packit 98cdb6
  pix_rect.x += cell_area->x + cell->xpad;
Packit 98cdb6
  pix_rect.y += cell_area->y + cell->ypad;
Packit 98cdb6
  pix_rect.width  -= cell->xpad * 2;
Packit 98cdb6
  pix_rect.height -= cell->ypad * 2;
Packit 98cdb6
Packit 98cdb6
  if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect) ||
Packit 98cdb6
      !gdk_rectangle_intersect (expose_area, &draw_rect, &draw_rect))
Packit 98cdb6
    return;
Packit 98cdb6
Packit 98cdb6
  pixbuf = cellpixbuf->pixbuf;
Packit 98cdb6
Packit 98cdb6
  if (cell->is_expander)
Packit 98cdb6
    {
Packit 98cdb6
      if (cell->is_expanded &&
Packit 98cdb6
	  cellpixbuf->pixbuf_expander_open != NULL)
Packit 98cdb6
	pixbuf = cellpixbuf->pixbuf_expander_open;
Packit 98cdb6
      else if (!cell->is_expanded &&
Packit 98cdb6
	       cellpixbuf->pixbuf_expander_closed != NULL)
Packit 98cdb6
	pixbuf = cellpixbuf->pixbuf_expander_closed;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (!pixbuf)
Packit 98cdb6
    return;
Packit 98cdb6
Packit 98cdb6
  if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE || !cell->sensitive)
Packit 98cdb6
    {
Packit 98cdb6
      GtkIconSource *source;
Packit 98cdb6
      
Packit 98cdb6
      source = gtk_icon_source_new ();
Packit 98cdb6
      gtk_icon_source_set_pixbuf (source, pixbuf);
Packit 98cdb6
      /* The size here is arbitrary; since size isn't
Packit 98cdb6
       * wildcarded in the source, it isn't supposed to be
Packit 98cdb6
       * scaled by the engine function
Packit 98cdb6
       */
Packit 98cdb6
      gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR);
Packit 98cdb6
      gtk_icon_source_set_size_wildcarded (source, FALSE);
Packit 98cdb6
      
Packit 98cdb6
     invisible = gtk_style_render_icon (widget->style,
Packit 98cdb6
					source,
Packit 98cdb6
					gtk_widget_get_direction (widget),
Packit 98cdb6
					GTK_STATE_INSENSITIVE,
Packit 98cdb6
					/* arbitrary */
Packit 98cdb6
					(GtkIconSize)-1,
Packit 98cdb6
					widget,
Packit 98cdb6
					"gtkcellrendererpixbuf");
Packit 98cdb6
     
Packit 98cdb6
     gtk_icon_source_free (source);
Packit 98cdb6
     
Packit 98cdb6
     pixbuf = invisible;
Packit 98cdb6
    }
Packit 98cdb6
  else if (priv->follow_state && 
Packit 98cdb6
	   (flags & (GTK_CELL_RENDERER_SELECTED|GTK_CELL_RENDERER_PRELIT)) != 0)
Packit 98cdb6
    {
Packit 98cdb6
      GtkStateType state;
Packit 98cdb6
Packit 98cdb6
      if ((flags & GTK_CELL_RENDERER_SELECTED) != 0)
Packit 98cdb6
	{
Packit 98cdb6
	  if (gtk_widget_has_focus (widget))
Packit 98cdb6
	    state = GTK_STATE_SELECTED;
Packit 98cdb6
	  else
Packit 98cdb6
	    state = GTK_STATE_ACTIVE;
Packit 98cdb6
	}
Packit 98cdb6
      else
Packit 98cdb6
	state = GTK_STATE_PRELIGHT;
Packit 98cdb6
Packit 98cdb6
      colorized = create_colorized_pixbuf (pixbuf,
Packit 98cdb6
					   &widget->style->base[state]);
Packit 98cdb6
Packit 98cdb6
      pixbuf = colorized;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  cr = gdk_cairo_create (window);
Packit 98cdb6
  
Packit 98cdb6
  gdk_cairo_set_source_pixbuf (cr, pixbuf, pix_rect.x, pix_rect.y);
Packit 98cdb6
  gdk_cairo_rectangle (cr, &draw_rect);
Packit 98cdb6
  cairo_fill (cr);
Packit 98cdb6
Packit 98cdb6
  cairo_destroy (cr);
Packit 98cdb6
  
Packit 98cdb6
  if (invisible)
Packit 98cdb6
    g_object_unref (invisible);
Packit 98cdb6
Packit 98cdb6
  if (colorized)
Packit 98cdb6
    g_object_unref (colorized);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GTK_CELL_RENDERER_PIXBUF_C__
Packit 98cdb6
#include "gtkaliasdef.c"