Ejemplo n.º 1
0
static GdkPixbuf *
ensure_stated_pixbuf_from_pixbuf (GtkIconHelper   *self,
				  GtkStyleContext *context,
				  GdkPixbuf       *pixbuf)
{
  GdkPixbuf *rendered;
  GtkIconSource *source;

  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;

  /* FIXME: use gtk_icon_info_load_icon? */

  source = gtk_icon_source_new ();
  gtk_icon_source_set_pixbuf (source, pixbuf);
  /* The size here is arbitrary; since size isn't
   * wildcarded in the source, it isn't supposed to be
   * scaled by the engine function
   */
  gtk_icon_source_set_size (source,
			    GTK_ICON_SIZE_SMALL_TOOLBAR);
  gtk_icon_source_set_size_wildcarded (source, FALSE);

  rendered = gtk_render_icon_pixbuf (context, source, (GtkIconSize) -1);
  gtk_icon_source_free (source);

  G_GNUC_END_IGNORE_DEPRECATIONS;

  return rendered;
}
Ejemplo n.º 2
0
static GdkPixbuf *
ensure_stated_icon_from_info (GtkIconHelper *self,
                              GtkStyleContext *context,
			      GtkIconInfo *info)
{
  GdkPixbuf *destination = NULL;
  gboolean symbolic;

  symbolic = FALSE;

  if (info)
    destination =
      gtk_icon_info_load_symbolic_for_context (info,
					       context,
					       &symbolic,
					       NULL);

  if (destination == NULL)
    {
      GtkIconSet *icon_set;
      icon_set = gtk_style_context_lookup_icon_set (context, GTK_STOCK_MISSING_IMAGE);

      destination =
        gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size);
    }
  else if (!symbolic)
    {
      GtkIconSource *source;
      GdkPixbuf *rendered;

      source = gtk_icon_source_new ();
      gtk_icon_source_set_pixbuf (source, destination);
      /* The size here is arbitrary; since size isn't
       * wildcarded in the source, it isn't supposed to be
       * scaled by the engine function
       */
      gtk_icon_source_set_size (source,
				GTK_ICON_SIZE_SMALL_TOOLBAR);
      gtk_icon_source_set_size_wildcarded (source, FALSE);

      rendered = gtk_render_icon_pixbuf (context, source, (GtkIconSize) -1);
      gtk_icon_source_free (source);

      g_object_unref (destination);
      destination = rendered;
    }

  return destination;
}
Ejemplo n.º 3
0
static gboolean
xfce_panel_image_draw (GtkWidget *widget,
                       cairo_t   *cr)
{
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;
  gint                   source_width, source_height;
  gint                   dest_x, dest_y;
  GtkIconSource         *source;
  GdkPixbuf             *rendered = NULL;
  GdkPixbuf             *pixbuf = priv->cache;
  GtkStyleContext       *context;

  if (G_LIKELY (pixbuf != NULL))
    {
      /* get the size of the cache pixbuf */
      source_width = gdk_pixbuf_get_width (pixbuf);
      source_height = gdk_pixbuf_get_height (pixbuf);

      /* position */
      dest_x = (priv->width - source_width) / 2;
      dest_y = (priv->height - source_height) / 2;

      context = gtk_widget_get_style_context (widget);

      if (!gtk_widget_is_sensitive (widget))
        {
          source = gtk_icon_source_new ();
          gtk_icon_source_set_pixbuf (source, pixbuf);
          rendered = gtk_render_icon_pixbuf (context, source, -1);
          gtk_icon_source_free (source);

          if (G_LIKELY (rendered != NULL))
            pixbuf = rendered;
        }

      /* draw the icon */
      gtk_render_icon (context, cr, pixbuf, dest_x, dest_y);

      if (rendered != NULL)
        g_object_unref (G_OBJECT (rendered));
    }

  return FALSE;
}
Ejemplo n.º 4
0
static void
gimp_cell_renderer_toggle_render (GtkCellRenderer      *cell,
                                  cairo_t              *cr,
                                  GtkWidget            *widget,
                                  const GdkRectangle   *background_area,
                                  const GdkRectangle   *cell_area,
                                  GtkCellRendererState  flags)
{
  GimpCellRendererToggle *toggle = GIMP_CELL_RENDERER_TOGGLE (cell);
  GdkRectangle            toggle_rect;
  GdkRectangle            draw_rect;
  GtkStyleContext        *context = gtk_widget_get_style_context (widget);
  GdkRectangle            clip_rect;
  GtkStateFlags           state;
  gboolean                active;
  gint                    xpad;
  gint                    ypad;

  if (! toggle->stock_id)
    {
      GTK_CELL_RENDERER_CLASS (parent_class)->render (cell,
                                                      cr,
                                                      widget,
                                                      background_area,
                                                      cell_area,
                                                      flags);
      return;
    }

  gtk_cell_renderer_get_size (cell, widget, cell_area,
                              &toggle_rect.x,
                              &toggle_rect.y,
                              &toggle_rect.width,
                              &toggle_rect.height);

  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
  toggle_rect.x      += cell_area->x + xpad;
  toggle_rect.y      += cell_area->y + ypad;
  toggle_rect.width  -= xpad * 2;
  toggle_rect.height -= ypad * 2;

  if (toggle_rect.width <= 0 || toggle_rect.height <= 0)
    return;

  active =
    gtk_cell_renderer_toggle_get_active (GTK_CELL_RENDERER_TOGGLE (cell));

  if (!gtk_cell_renderer_get_sensitive (cell))
    {
      state = GTK_STATE_FLAG_INSENSITIVE;
    }
  else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
    {
      if (gtk_widget_has_focus (widget))
        state = GTK_STATE_FLAG_SELECTED;
      else
        state = GTK_STATE_FLAG_ACTIVE;
    }
  else
    {
      if (gtk_cell_renderer_toggle_get_activatable (GTK_CELL_RENDERER_TOGGLE (cell)))
        state = GTK_STATE_FLAG_NORMAL;
      else
        state = GTK_STATE_FLAG_INSENSITIVE;
    }

  if ((flags & GTK_CELL_RENDERER_PRELIT) &&
      gdk_cairo_get_clip_rectangle(cr, &clip_rect) &&
      gdk_rectangle_intersect (&clip_rect, cell_area, &draw_rect))
    {
      cairo_save (cr);
      gdk_cairo_rectangle (cr, &draw_rect);
      cairo_clip (cr);
      gtk_render_frame (context, //gtk_widget_get_style_context (widget),
                        cr,
                        toggle_rect.x, toggle_rect.y,
                        toggle_rect.width, toggle_rect.height);
      gtk_style_context_restore (context);
      cairo_restore (cr);
    }

  if (active)
    {
      GdkPixbuf *insensitive = NULL;
      GdkPixbuf *pixbuf = toggle->pixbuf;

      GtkBorder  border = { 1, 1, 1, 1 };

#if 0
      /* FIXME: for some reason calling gtk_style_context_get_border
       * makes the icon only visible on hover, so use border = 1
       * for now as a workaround
       */
      gtk_style_context_get_border (context, state, &border);
#endif

      toggle_rect.x      += border.left;
      toggle_rect.y      += border.top;
      toggle_rect.width  -= (border.left + border.right);
      toggle_rect.height -= (border.top + border.bottom);

      if (state & GTK_STATE_FLAG_INSENSITIVE)
        {
	  GtkIconSource *source;

	  source = gtk_icon_source_new ();
	  gtk_icon_source_set_pixbuf (source, pixbuf);
	  /* The size here is arbitrary; since size isn't
	   * wildcarded in the source, it isn't supposed to be
	   * scaled by the engine function
	   */
	  gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR);
	  gtk_icon_source_set_size_wildcarded (source, FALSE);

          gtk_style_context_save (context);
          gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
          insensitive = gtk_render_icon_pixbuf (context, source, (GtkIconSize)-1);
          gtk_style_context_restore (context);

	  gtk_icon_source_free (source);

	  pixbuf = insensitive;
	}

      if (gdk_rectangle_intersect (&draw_rect, &toggle_rect, &draw_rect))
        {
	  gdk_cairo_set_source_pixbuf (cr, pixbuf, toggle_rect.x, toggle_rect.y);
	  gdk_cairo_rectangle (cr, &draw_rect);
	  cairo_fill (cr);
	}
	      
      if (insensitive)
        g_object_unref (insensitive);
    }
}