Пример #1
0
static gboolean
xfce_panel_image_expose_event (GtkWidget      *widget,
                               GdkEventExpose *event)
{
  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;
  cairo_t               *cr;

  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 = widget->allocation.x + (priv->width - source_width) / 2;
      dest_y = widget->allocation.y + (priv->height - source_height) / 2;

      if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
        {
          source = gtk_icon_source_new ();
          gtk_icon_source_set_pixbuf (source, pixbuf);

          rendered = gtk_style_render_icon (widget->style,
                                            source,
                                            gtk_widget_get_direction (widget),
                                            GTK_WIDGET_STATE (widget),
                                            -1, widget, "xfce-panel-image");
          gtk_icon_source_free (source);

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

      /* draw the pixbuf */
      cr = gdk_cairo_create (gtk_widget_get_window (widget));
      if (G_LIKELY (cr != NULL))
        {
          gdk_cairo_set_source_pixbuf (cr, pixbuf, dest_x, dest_y);
          cairo_paint (cr);
          cairo_destroy (cr);
        }

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

  return FALSE;
}
Пример #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;
}
Пример #3
0
Файл: icons.c Проект: gpg/gpa
static void
register_stock_icons (void)
{
  GdkPixbuf *pixbuf;
  GtkIconFactory *icon_factory;
  GtkIconSet *icon_set;
  GtkIconSource *icon_source;
  gint i;

  icon_factory = gtk_icon_factory_new ();

  for (i = 0; xpms[i].name; i++)
    {
      icon_set = gtk_icon_set_new ();
      icon_source = gtk_icon_source_new ();

      pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) xpms[i].xpm);
      gtk_icon_source_set_pixbuf (icon_source, pixbuf);
      gtk_icon_source_set_direction_wildcarded (icon_source, TRUE);
      gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
      if (! strcmp (xpms[i].name, GPA_STOCK_PUBLIC_KEY)
	  || ! strcmp (xpms[i].name, GPA_STOCK_SECRET_KEY))
	{
	  /* FIXME: For the keylist icons, we disable scaling for now
	     for best visual results.  */
	  gtk_icon_source_set_size_wildcarded (icon_source, FALSE);
	  gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_LARGE_TOOLBAR);
	}

      gtk_icon_set_add_source (icon_set, icon_source);
      gtk_icon_source_free (icon_source);
      gtk_icon_factory_add (icon_factory, xpms[i].name, icon_set);
      gtk_icon_set_unref (icon_set);
    }

  /* Add a fake stock icon for the clipboard window.  */
  icon_set = gtk_icon_factory_lookup_default (GTK_STOCK_PASTE);
  icon_set = gtk_icon_set_copy (icon_set);
  gtk_icon_factory_add (icon_factory, GPA_STOCK_CLIPBOARD, icon_set);

  /* Add a fake stock icon for the file manager window.  */
  icon_set = gtk_icon_factory_lookup_default (GTK_STOCK_DIRECTORY);
  icon_set = gtk_icon_set_copy (icon_set);
  gtk_icon_factory_add (icon_factory, GPA_STOCK_FILEMAN, icon_set);

  gtk_icon_factory_add_default (icon_factory);

  g_object_unref (icon_factory);
}
Пример #4
0
void stock_icon_register_pixbuf(GdkPixbuf * pixbuf, gchar * stock_id)
{
    GtkIconSet *icon_set;
    GtkIconSource *icon_source;

    icon_set = gtk_icon_set_new();
    icon_source = gtk_icon_source_new();

    gtk_icon_source_set_pixbuf(icon_source, pixbuf);
    gtk_icon_set_add_source(icon_set, icon_source);
    gtk_icon_source_free(icon_source);

    gtk_icon_factory_add(icon_factory, stock_id, icon_set);

    gtk_icon_set_unref(icon_set);
}
Пример #5
0
static void
on_preview_expose_event (GtkWidget      *drawing_area,
			 GdkEventExpose *event,
			 gpointer        data)
{
  ScreenshotDialog *dialog = data;
  GdkPixbuf *pixbuf = NULL;
  gboolean free_pixbuf = FALSE;
  cairo_t *cr;

  /* Stolen from GtkImage.  I really should just make the drawing area an
   * image some day */
  if (gtk_widget_get_state (drawing_area) != GTK_STATE_NORMAL)
    {
      GtkIconSource *source;

      source = gtk_icon_source_new ();
      gtk_icon_source_set_pixbuf (source, dialog->preview_image);
      gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR);
      gtk_icon_source_set_size_wildcarded (source, FALSE);
                  
      pixbuf = gtk_style_render_icon (drawing_area->style,
				      source,
				      gtk_widget_get_direction (drawing_area),
				      gtk_widget_get_state (drawing_area),
				      (GtkIconSize) -1,
				      drawing_area,
				      "gtk-image");
      free_pixbuf = TRUE;
      gtk_icon_source_free (source);
    }
  else
    {
      pixbuf = g_object_ref (dialog->preview_image);
    }
  
  cr = gdk_cairo_create (drawing_area->window);
  gdk_cairo_region (cr, event->region);
  cairo_clip (cr);

  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
  cairo_paint (cr);

  cairo_destroy (cr);

  g_object_unref (pixbuf);
}
Пример #6
0
void stock_icon_register(gchar * filename, gchar * stock_id)
{
    GtkIconSet *icon_set;
    GtkIconSource *icon_source;

    icon_set = gtk_icon_set_new();
    icon_source = gtk_icon_source_new();

    gtk_icon_source_set_pixbuf(icon_source,
			       icon_cache_get_pixbuf(filename));
    gtk_icon_set_add_source(icon_set, icon_source);
    gtk_icon_source_free(icon_source);

    gtk_icon_factory_add(icon_factory, stock_id, icon_set);

    gtk_icon_set_unref(icon_set);
}
Пример #7
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;
}
Пример #8
0
static void accessx_applet_add_stock_icons(AccessxStatusApplet* sapplet, GtkWidget* widget)
{
    GtkIconFactory* factory = gtk_icon_factory_new();
    gint i = 0;
    GtkIconSet* icon_set;

    gtk_icon_factory_add_default(factory);

    while (i <  G_N_ELEMENTS(stock_icons))
    {
        gchar* set_name = stock_icons[i].stock_id;
        icon_set = gtk_icon_set_new();

        do {
            char* filename;
            GtkIconSource* source = gtk_icon_source_new();
            filename = g_build_filename(ACCESSX_PIXMAPS_DIR, stock_icons[i].name, NULL);

            if (g_file_test(filename, G_FILE_TEST_EXISTS) && g_file_test(filename, G_FILE_TEST_IS_REGULAR))
            {
                gtk_icon_source_set_filename(source, filename);
            }
            else
            {
                GtkIconSet* default_set = gtk_icon_factory_lookup_default(GTK_STOCK_MISSING_IMAGE);
                gtk_icon_source_set_pixbuf(source, gtk_icon_set_render_icon(default_set, gtk_widget_get_style(widget), GTK_TEXT_DIR_NONE, GTK_STATE_NORMAL, icon_size_spec, widget, NULL));
            }
            g_free(filename);
            gtk_icon_source_set_state(source, stock_icons[i].state);
            gtk_icon_source_set_state_wildcarded(source, stock_icons[i].wildcarded);
            gtk_icon_set_add_source(icon_set, source);
            gtk_icon_source_free(source);
            ++i;
        } while (set_name == stock_icons[i].stock_id);
        gtk_icon_factory_add(factory, set_name, icon_set);
        gtk_icon_set_unref(icon_set);
    }
    /* now create the stock icons for AltGr, which are internationalized */
    icon_set = accessx_status_applet_altgraph_icon_set (sapplet, widget);
    gtk_icon_factory_add(factory, ALTGRAPH_KEY_ICON, icon_set);
    gtk_icon_set_unref(icon_set);
    sapplet->icon_factory = factory;
}
Пример #9
0
static void
icon_set_from_inline (GtkIconSet       *set,
                      const guchar     *inline_data,
                      GtkIconSize       size,
                      GtkTextDirection  direction,
                      gboolean          fallback)
{
  GtkIconSource *source;
  GdkPixbuf     *pixbuf;

  source = gtk_icon_source_new ();

  if (direction != GTK_TEXT_DIR_NONE)
    {
      gtk_icon_source_set_direction (source, direction);
      gtk_icon_source_set_direction_wildcarded (source, FALSE);
    }

  gtk_icon_source_set_size (source, size);
  gtk_icon_source_set_size_wildcarded (source, FALSE);

  pixbuf = gdk_pixbuf_new_from_inline (-1, inline_data, FALSE, NULL);

  g_assert (pixbuf);

  gtk_icon_source_set_pixbuf (source, pixbuf);

  g_object_unref (pixbuf);

  gtk_icon_set_add_source (set, source);

  if (fallback)
    {
      gtk_icon_source_set_size_wildcarded (source, TRUE);
      gtk_icon_set_add_source (set, source);
    }

  gtk_icon_source_free (source);
}
Пример #10
0
static void
add_stock_icon (const gchar  *stock_id,
                GtkIconSize   size,
                const guint8 *inline_data)
{
  GtkIconSource *source;
  GtkIconSet    *set;
  GdkPixbuf     *pixbuf;
  
  source = gtk_icon_source_new ();

  gtk_icon_source_set_size (source, size);
  gtk_icon_source_set_size_wildcarded (source, FALSE);

  pixbuf = gdk_pixbuf_new_from_inline (-1, inline_data, FALSE, NULL);

  if(gap_debug)
  {
    printf("add_stock_icon stock_id:%s size:%d inline_data:%d pixbuf:%d\n"
       ,stock_id
       ,(int)size
       ,(int)inline_data
       ,(int)pixbuf
       );
  }

  gtk_icon_source_set_pixbuf (source, pixbuf);
  g_object_unref (pixbuf);

  set = gtk_icon_set_new ();

  gtk_icon_set_add_source (set, source);
  gtk_icon_source_free (source);

  gtk_icon_factory_add (gap_icon_factory, stock_id, set);

  gtk_icon_set_unref (set);
}
Пример #11
0
static void
icon_set_from_data (GtkIconSet       *set,
		    const guint8     *icon_data,
		    const guint       data_size,
		    GtkIconSize       size,
		    gboolean          fallback)
{
	GtkIconSource *source;
	GdkPixbuf     *pixbuf;
	GError        *err = NULL;

	source = gtk_icon_source_new ();

	gtk_icon_source_set_size (source, size);
	gtk_icon_source_set_size_wildcarded (source, FALSE);
	
	pixbuf = gdk_pixbuf_new_from_inline (data_size, icon_data, FALSE, &err);
	if (err) {
	    g_warning ("%s",err->message);
	    g_error_free (err);
	    err = NULL;
	    g_object_unref (source);
	    return;
	}
	
	gtk_icon_source_set_pixbuf (source, pixbuf);
	
	g_object_unref (pixbuf);
	
	gtk_icon_set_add_source (set, source);
	
	if (fallback) {
		gtk_icon_source_set_size_wildcarded (source, TRUE);
		gtk_icon_set_add_source (set, source);
	}
	
	gtk_icon_source_free (source);
}
Пример #12
0
static void
exo_cell_renderer_icon_render (GtkCellRenderer     *renderer,
                               GdkWindow           *window,
                               GtkWidget           *widget,
                               GdkRectangle        *background_area,
                               GdkRectangle        *cell_area,
                               GdkRectangle        *expose_area,
                               GtkCellRendererState flags)
{
  const ExoCellRendererIconPrivate *priv = EXO_CELL_RENDERER_ICON_GET_PRIVATE (renderer);
  GtkIconSource                    *icon_source;
  GtkIconTheme                     *icon_theme;
  GdkRectangle                      icon_area;
  GdkRectangle                      draw_area;
  GtkStateType                      state;
  const gchar                      *filename;
  GtkIconInfo                      *icon_info = NULL;
  GdkPixbuf                        *icon = NULL;
  GdkPixbuf                        *temp;
  GError                           *err = NULL;
  gchar                            *display_name = NULL;
  gint                             *icon_sizes;
  gint                              icon_size;
  gint                              n;

  /* verify that we have an icon */
  if (G_UNLIKELY (priv->icon == NULL && priv->gicon == NULL))
    return;

  /* icon may be either an image file or a named icon */
  if (priv->icon != NULL && g_path_is_absolute (priv->icon))
    {
      /* load the icon via the thumbnail database */
      icon = _exo_thumbnail_get_for_file (priv->icon, (priv->size > 128) ? EXO_THUMBNAIL_SIZE_LARGE : EXO_THUMBNAIL_SIZE_NORMAL, &err);
    }
  else if (priv->icon != NULL || priv->gicon != NULL)
    {
      /* determine the best icon size (GtkIconTheme is somewhat messy scaling up small icons) */
      icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));

      if (priv->icon != NULL)
        {
          icon_sizes = gtk_icon_theme_get_icon_sizes (icon_theme, priv->icon);
          for (icon_size = -1, n = 0; icon_sizes[n] != 0; ++n)
            {
              /* we can use any size if scalable, because we load the file directly */
              if (icon_sizes[n] == -1)
                icon_size = priv->size;
              else if (icon_sizes[n] > icon_size && icon_sizes[n] <= priv->size)
                icon_size = icon_sizes[n];
            }
          g_free (icon_sizes);

          /* if we don't know any icon sizes at all, the icon is probably not present */
          if (G_UNLIKELY (icon_size < 0))
            icon_size = priv->size;

          /* lookup the icon in the icon theme */
          icon_info = gtk_icon_theme_lookup_icon (icon_theme, priv->icon, icon_size, 0);
        }
      else if (priv->gicon != NULL)
        {
          icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme,
                                                      priv->gicon,
                                                      priv->size,
                                                      GTK_ICON_LOOKUP_USE_BUILTIN);
        }

      if (G_UNLIKELY (icon_info == NULL))
        return;

      /* check if we have an SVG icon here */
      filename = gtk_icon_info_get_filename (icon_info);
      if (filename != NULL && g_str_has_suffix (filename, ".svg"))
        {
          /* loading SVG icons is terribly slow, so we try to use thumbnail instead, and we use the
           * real available cell area directly here, because loading thumbnails involves scaling anyway
           * and this way we need to the thumbnail pixbuf scale only once.
           */
          icon = _exo_thumbnail_get_for_file (filename, (priv->size > 128) ? EXO_THUMBNAIL_SIZE_LARGE : EXO_THUMBNAIL_SIZE_NORMAL, &err);
        }
      else
        {
          /* regularly load the icon from the theme */
          icon = gtk_icon_info_load_icon (icon_info, &err);
        }
      gtk_icon_info_free (icon_info);
    }

  /* check if we failed */
  if (G_UNLIKELY (icon == NULL))
    {
      /* better let the user know whats going on, might be surprising otherwise */
      if (G_LIKELY (priv->icon != NULL))
        {
          display_name = g_filename_display_name (priv->icon);
        }
      else if (G_UNLIKELY (priv->gicon != NULL
                           && g_object_class_find_property (G_OBJECT_GET_CLASS (priv->gicon),
                                                            "name")))
        {
          g_object_get (priv->gicon, "name", &display_name, NULL);
        }

      if (display_name != NULL)
        {
          g_warning ("Failed to load \"%s\": %s", display_name, err->message);
          g_free (display_name);
        }

      g_error_free (err);
      return;
    }

  /* determine the real icon size */
  icon_area.width = gdk_pixbuf_get_width (icon);
  icon_area.height = gdk_pixbuf_get_height (icon);

  /* scale down the icon on-demand */
  if (G_UNLIKELY (icon_area.width > cell_area->width || icon_area.height > cell_area->height))
    {
      /* scale down to fit */
      temp = exo_gdk_pixbuf_scale_down (icon, TRUE, cell_area->width, cell_area->height);
      g_object_unref (G_OBJECT (icon));
      icon = temp;

      /* determine the icon dimensions again */
      icon_area.width = gdk_pixbuf_get_width (icon);
      icon_area.height = gdk_pixbuf_get_height (icon);
    }

  icon_area.x = cell_area->x + (cell_area->width - icon_area.width) / 2;
  icon_area.y = cell_area->y + (cell_area->height - icon_area.height) / 2;

  /* check whether the icon is affected by the expose event */
  if (gdk_rectangle_intersect (expose_area, &icon_area, &draw_area))
    {
      /* colorize the icon if we should follow the selection state */
      if ((flags & (GTK_CELL_RENDERER_SELECTED | GTK_CELL_RENDERER_PRELIT)) != 0 && priv->follow_state)
        {
          if ((flags & GTK_CELL_RENDERER_SELECTED) != 0)
            {
              state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE;
              temp = exo_gdk_pixbuf_colorize (icon, &widget->style->base[state]);
              g_object_unref (G_OBJECT (icon));
              icon = temp;
            }

          if ((flags & GTK_CELL_RENDERER_PRELIT) != 0)
            {
              temp = exo_gdk_pixbuf_spotlight (icon);
              g_object_unref (G_OBJECT (icon));
              icon = temp;
            }
        }

      /* check if we should render an insensitive icon */
      if (G_UNLIKELY (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE || !renderer->sensitive))
        {
          /* allocate an icon source */
          icon_source = gtk_icon_source_new ();
          gtk_icon_source_set_pixbuf (icon_source, icon);
          gtk_icon_source_set_size_wildcarded (icon_source, FALSE);
          gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_SMALL_TOOLBAR);

          /* render the insensitive icon */
          temp = gtk_style_render_icon (widget->style, icon_source, gtk_widget_get_direction (widget),
                                        GTK_STATE_INSENSITIVE, -1, widget, "gtkcellrendererpixbuf");
          g_object_unref (G_OBJECT (icon));
          icon = temp;

          /* release the icon source */
          gtk_icon_source_free (icon_source);
        }

      /* render the invalid parts of the icon */
      gdk_draw_pixbuf (window, widget->style->black_gc, icon,
                       draw_area.x - icon_area.x, draw_area.y - icon_area.y,
                       draw_area.x, draw_area.y, draw_area.width, draw_area.height,
                       GDK_RGB_DITHER_NORMAL, 0, 0);
    }

  /* release the file's icon */
  g_object_unref (G_OBJECT (icon));
}
Пример #13
0
static GtkIconSet* accessx_status_applet_altgraph_icon_set(AccessxStatusApplet* sapplet, GtkWidget* widget)
{
    GtkIconSet* icon_set = gtk_icon_set_new();
    gint i;
    GtkStateType states[3] = {GTK_STATE_NORMAL, GTK_STATE_INSENSITIVE, GTK_STATE_SELECTED};
    GtkStyle* style = gtk_widget_get_style(widget);
    GdkPixbuf* icon_base;

    gtk_widget_set_sensitive(widget, TRUE);

    for (i = 0; i < 3; ++i)
    {
        int alpha;
        GdkColor* fg;
        GdkColor* bg;
        GtkIconSource* source = gtk_icon_source_new();
        GdkPixbuf* pixbuf;
        GdkPixbuf* glyph_pixbuf;
        gboolean wildcarded = FALSE;
        fg = &style->text[states[i]];
        bg = &style->white;
        switch (states[i])
        {
        case GTK_STATE_NORMAL:
            alpha = 255;
            gtk_widget_set_sensitive(widget, TRUE);
#if GTK_CHECK_VERSION (3, 0, 0)
            gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_NORMAL, TRUE);
#else
            gtk_widget_set_state(widget, GTK_STATE_NORMAL);
#endif
            break;
        case GTK_STATE_SELECTED:
            /* FIXME: should use text/base here, for selected ? */
            fg = &style->white;
            bg = &style->black;
            alpha = 255;
            gtk_widget_set_sensitive(widget, TRUE);
#if GTK_CHECK_VERSION (3, 0, 0)
            gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, TRUE);
#else
            gtk_widget_set_state(widget, GTK_STATE_SELECTED);
#endif
            break;
        case GTK_STATE_INSENSITIVE:
        default:
            alpha = 63;
            gtk_widget_set_sensitive(widget, FALSE);
            wildcarded = TRUE;
            break;
        }

        icon_base = gtk_widget_render_icon(widget, ACCESSX_BASE_ICON, icon_size_spec, NULL);
        pixbuf = gdk_pixbuf_copy(icon_base);
        g_object_unref(icon_base);
        /*
        * should be N_("ae"));
        * need en_ locale for this.
        */
        /*
        * Translators: substitute an easily-recognized single glyph
        * from Level 2, i.e. an AltGraph character from a common keyboard
        * in your locale.
        */
        glyph_pixbuf = accessx_status_applet_get_glyph_pixbuf(sapplet, widget, pixbuf, fg, bg, ("æ"));
        gdk_pixbuf_composite(glyph_pixbuf, pixbuf, 0, 0, gdk_pixbuf_get_width(glyph_pixbuf), gdk_pixbuf_get_height(glyph_pixbuf), 0., 0., 1.0, 1.0, GDK_INTERP_NEAREST, alpha);
        g_object_unref(glyph_pixbuf);
        gtk_icon_source_set_pixbuf(source, pixbuf);
        gtk_icon_source_set_state(source, states[i]);
        gtk_icon_source_set_state_wildcarded(source, wildcarded);
        gtk_icon_set_add_source(icon_set, source);
        gtk_icon_source_free(source);
    }
    /* we mucked about with the box's state to create the icons; restore it to normal */
#if GTK_CHECK_VERSION (3, 0, 0)
    gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_NORMAL, TRUE);
#else
    gtk_widget_set_state(widget, GTK_STATE_NORMAL);
#endif
    gtk_widget_set_sensitive(widget, TRUE);

    return icon_set;
}
Пример #14
0
void
osmo_register_stock_icons(void) {

GdkPixbuf *pixbuf;
gint i;
GtkIconFactory *factory;
GtkIconSet *icon_set;
GtkIconSource *icon_source;

GtkStockItem calendar_stock_items[] = {

    { (gchar*) OSMO_STOCK_BUTTON_ADD,              (gchar*) N_("Add"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_CLEAR,            (gchar*) N_("Clear"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_CLOSE,            (gchar*) N_("Close"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_CANCEL,           (gchar*) N_("Cancel"),                      0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_JUMPTO,           (gchar*) N_("Jump to"),                     0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_CONTACTS_EXPORT,  (gchar*) N_("Export"),                      0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_CONTACTS_IMPORT,  (gchar*) N_("Import"),                      0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_INSERT_TIMELINE,  (gchar*) N_("Insert timeline"),             0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_NEXT_YEAR,        (gchar*) N_("Next year"),                   0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_NO,               (gchar*) N_("No"),                          0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_OK,               (gchar*) N_("OK"),                          0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_OPEN,             (gchar*) N_("Browse"),                      0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_PREV_YEAR,        (gchar*) N_("Previous year"),               0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_REMOVE,           (gchar*) N_("Remove"),                      0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_SELECT_DATE,      (gchar*) N_("Select date"),                 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_SELECT_FONT,      (gchar*) N_("Select font"),                 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_TODAY,            (gchar*) N_("Today"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_YES,              (gchar*) N_("Yes"),                         0, 0, TRANSLATION_DOMAIN },

    { (gchar*) OSMO_STOCK_ABOUT,                   (gchar*) N_("About"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CALENDAR,                (gchar*) N_("Calendar"),                    0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_ADD,            (gchar*) N_("Add contact"),                 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_EDIT,           (gchar*) N_("Edit contact"),                0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_EXPORT,         (gchar*) N_("Export contact"),              0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_IMPORT,         (gchar*) N_("Import contact"),              0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_REMOVE,         (gchar*) N_("Remove contact"),              0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS,                (gchar*) N_("Contacts"),                    0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDIT_NOTE,               (gchar*) N_("Edit day note"),               0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_FULLYEAR,                (gchar*) N_("Display full-year calendar"),  0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_HELP,                    (gchar*) N_("Help"),                        0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_JUMPTO,                  (gchar*) N_("Jump to date"),                0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_LICENSE,                 (gchar*) N_("License"),                     0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_NEXT_DAY,                (gchar*) N_("Next day"),                    0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_NEXT_MONTH,              (gchar*) N_("Next month"),                  0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_NEXT_YEAR,               (gchar*) N_("Next year"),                   0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_PREFERENCES,             (gchar*) N_("Preferences"),                 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_PREV_DAY,                (gchar*) N_("Previous day"),                0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_PREV_MONTH,              (gchar*) N_("Previous month"),              0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_PREV_YEAR,               (gchar*) N_("Previous year"),               0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TASKS_ADD,               (gchar*) N_("Add task"),                    0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TASKS_EDIT,              (gchar*) N_("Edit task"),                   0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TASKS_REMOVE,            (gchar*) N_("Remove task"),                 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TASKS,                   (gchar*) N_("Tasks"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TODAY,                   (gchar*) N_("Today"),                       0, 0, TRANSLATION_DOMAIN },
};

const guint8* calendar_stock_item_data[] = {
 
    (const guint8*) osmo_stock_button_add,               
    (const guint8*) osmo_stock_button_clear,               
    (const guint8*) osmo_stock_button_close,       
    (const guint8*) osmo_stock_button_cancel,       
    (const guint8*) osmo_stock_button_jumpto,
    (const guint8*) osmo_stock_button_contacts_export,
    (const guint8*) osmo_stock_button_contacts_import,
    (const guint8*) osmo_stock_button_insert_timeline,     
    (const guint8*) osmo_stock_button_next_year,     
    (const guint8*) osmo_stock_button_no,     
    (const guint8*) osmo_stock_button_ok,     
    (const guint8*) osmo_stock_button_open,     
    (const guint8*) osmo_stock_button_prev_year,     
    (const guint8*) osmo_stock_button_remove,     
    (const guint8*) osmo_stock_button_select_date,     
    (const guint8*) osmo_stock_button_select_font,     
    (const guint8*) osmo_stock_button_today,     
    (const guint8*) osmo_stock_button_yes,     

    (const guint8*) osmo_stock_about,               
    (const guint8*) osmo_stock_calendar,    
    (const guint8*) osmo_stock_contacts_add,            
    (const guint8*) osmo_stock_contacts_edit,            
    (const guint8*) osmo_stock_contacts_export,            
    (const guint8*) osmo_stock_contacts_import,            
    (const guint8*) osmo_stock_contacts_remove,            
    (const guint8*) osmo_stock_contacts,            
    (const guint8*) osmo_stock_edit_note,
    (const guint8*) osmo_stock_fullyear,            
    (const guint8*) osmo_stock_help,        
    (const guint8*) osmo_stock_jumpto,
    (const guint8*) osmo_stock_license,             
    (const guint8*) osmo_stock_next_day,
    (const guint8*) osmo_stock_next_month,          
    (const guint8*) osmo_stock_next_year,
    (const guint8*) osmo_stock_preferences,         
    (const guint8*) osmo_stock_prev_day,
    (const guint8*) osmo_stock_prev_month,          
    (const guint8*) osmo_stock_prev_year,
    (const guint8*) osmo_stock_tasks_add,               
    (const guint8*) osmo_stock_tasks_edit,               
    (const guint8*) osmo_stock_tasks_remove,               
    (const guint8*) osmo_stock_tasks,               
    (const guint8*) osmo_stock_today,
};

    gtk_stock_add (calendar_stock_items, G_N_ELEMENTS (calendar_stock_items));

    factory = gtk_icon_factory_new ();
    gtk_icon_factory_add_default(factory);

    for(i = 0; i < G_N_ELEMENTS(calendar_stock_item_data); i++) {
        pixbuf = gdk_pixbuf_new_from_inline(-1, calendar_stock_item_data[i], FALSE, NULL);
        icon_source = gtk_icon_source_new ();
        gtk_icon_source_set_pixbuf (icon_source, pixbuf);

        icon_set = gtk_icon_set_new ();
        gtk_icon_set_add_source (icon_set, icon_source);

        gtk_icon_factory_add(factory, calendar_stock_items[i].stock_id, icon_set);
        g_object_unref(pixbuf);
        gtk_icon_source_free (icon_source);
        gtk_icon_set_unref (icon_set);
    }

    g_object_unref (factory);

}
Пример #15
0
void
osmo_register_stock_icons(void) {

GdkPixbuf *pixbuf;
gint i;
GtkIconFactory *factory;
GtkIconSet *icon_set;
GtkIconSource *icon_source;

GtkStockItem osmo_stock_items[] = {

    { (gchar*) OSMO_STOCK_BUTTON_ADD,              (gchar*) N_("Add"),                          0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_CLEAR,            (gchar*) N_("Clear"),                        0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_CLOSE,            (gchar*) N_("Close"),                        0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_CANCEL,           (gchar*) N_("Cancel"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_JUMPTO,           (gchar*) N_("Jump to"),                      0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_EDIT,             (gchar*) N_("Edit"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_DOWN,             (gchar*) N_("Go Down"),                      0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_INFO,             (gchar*) N_("Info"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_INSERT_TIMELINE,  (gchar*) N_("Insert"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_NEXT_YEAR,        (gchar*) N_("Next year"),                    0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_NO,               (gchar*) N_("No"),                           0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_OK,               (gchar*) N_("OK"),                           0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_OPEN,             (gchar*) N_("Browse"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_PREV_YEAR,        (gchar*) N_("Previous year"),                0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_REMOVE,           (gchar*) N_("Remove"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_SELECT_COLOR,     (gchar*) N_("Select color"),                 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_SELECT_DATE,      (gchar*) N_("Select date"),                  0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_SELECT_FONT,      (gchar*) N_("Select font"),                  0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_TODAY,            (gchar*) N_("Today"),                        0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_YES,              (gchar*) N_("Yes"),                          0, 0, TRANSLATION_DOMAIN },

    { (gchar*) OSMO_STOCK_SYSTRAY_NORMAL,          (gchar*) "Osmo",                             0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_SYSTRAY_NOTE,            (gchar*) N_("Note"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_SYSTRAY_MENU_CALENDAR,   (gchar*) N_("Calendar"),                     0, 0, TRANSLATION_DOMAIN },

    { (gchar*) OSMO_STOCK_ABOUT,                   (gchar*) N_("About"),                        0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CALENDAR,                (gchar*) N_("Calendar"),                     0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CLOSE,                   (gchar*) N_("Close"),                        0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CALCULATOR,              (gchar*) N_("Calculator"),                   0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDIT_NOTE,               (gchar*) N_("Edit day note"),                0, 0, TRANSLATION_DOMAIN },

#ifdef CONTACTS_ENABLED
    { (gchar*) OSMO_STOCK_CONTACTS_ADD,            (gchar*) N_("Add contact"),                  0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_BIRTHDAYS,      (gchar*) N_("Show birthdays"),               0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_EDIT,           (gchar*) N_("Edit contact"),                 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_EXPORT,         (gchar*) N_("Export contacts"),              0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_IMPORT,         (gchar*) N_("Import contacts"),              0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_MAP_LOCATION,   (gchar*) N_("Contact map location"),         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS_REMOVE,         (gchar*) N_("Remove contact"),               0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_CONTACTS_EXPORT,  (gchar*) N_("Export"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_BUTTON_CONTACTS_IMPORT,  (gchar*) N_("Import"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_CONTACTS,                (gchar*) N_("Contacts"),                     0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_SYSTRAY_BIRTHDAY,        (gchar*) N_("Birthday"),                     0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_SYSTRAY_MENU_CONTACTS,   (gchar*) N_("Contacts"),                     0, 0, TRANSLATION_DOMAIN },
#endif /* CONTACTS_ENABLED */

#ifdef NOTES_ENABLED
    { (gchar*) OSMO_STOCK_EDITOR_BOLD,             (gchar*) N_("Bold"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_CLEAR,            (gchar*) N_("Clear"),                        0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_FIND,             (gchar*) N_("Find"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_HIGHLIGHT,        (gchar*) N_("Highlight"),                    0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_INFO,             (gchar*) N_("Info"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_INSERT_DATE_TIME, (gchar*) N_("Insert current date and time"), 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_INSERT_SEPARATOR, (gchar*) N_("Insert separator"),             0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_ITALIC,           (gchar*) N_("Italic"),                       0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_SAVE,             (gchar*) N_("Save"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_SPELL_CHECKER,    (gchar*) N_("Toggle spell checker"),         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_STRIKETHROUGH,    (gchar*) N_("Strikethrough"),                0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_EDITOR_UNDERLINE,        (gchar*) N_("Underline"),                    0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_NOTES_ADD,               (gchar*) N_("Add note"),                     0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_NOTES_EDIT,              (gchar*) N_("Edit note"),                    0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_NOTES_REMOVE,            (gchar*) N_("Remove note"),                  0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_NOTES,                   (gchar*) N_("Notes"),                        0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_SYSTRAY_MENU_NOTES,      (gchar*) N_("Notes"),                        0, 0, TRANSLATION_DOMAIN },
#endif /* NOTES_ENABLED */

    { (gchar*) OSMO_STOCK_FULLYEAR,                (gchar*) N_("Display full-year calendar"),   0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_HELP,                    (gchar*) N_("Help"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_INFO_HELP,               (gchar*) N_("Help"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_JUMPTO,                  (gchar*) N_("Jump to date"),                 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_LICENSE,                 (gchar*) N_("License"),                      0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_LIST_INVALID,            (gchar*) N_("Invalid item"),                 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_LIST_VALID,              (gchar*) N_("Valid item"),                   0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_NEXT_DAY,                (gchar*) N_("Next day"),                     0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_NEXT_MONTH,              (gchar*) N_("Next month"),                   0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_NEXT_YEAR,               (gchar*) N_("Next year"),                    0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_PREFERENCES,             (gchar*) N_("Preferences"),                  0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_PREV_DAY,                (gchar*) N_("Previous day"),                 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_PREV_MONTH,              (gchar*) N_("Previous month"),               0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_PREV_YEAR,               (gchar*) N_("Previous year"),                0, 0, TRANSLATION_DOMAIN },

#ifdef TASKS_ENABLED
    { (gchar*) OSMO_STOCK_TASKS_ADD,               (gchar*) N_("Add task"),                     0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TASKS_EDIT,              (gchar*) N_("Edit task"),                    0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TASKS_REMOVE,            (gchar*) N_("Remove task"),                  0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TASKS_PREV_DAY,          (gchar*) N_("Change due date to previous day"), 0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TASKS_NEXT_DAY,          (gchar*) N_("Change due date to next day"),  0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TASKS,                   (gchar*) N_("Tasks"),                        0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_SYSTRAY_TASK,            (gchar*) N_("Task"),                         0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_SYSTRAY_MENU_TASKS,      (gchar*) N_("Tasks"),                        0, 0, TRANSLATION_DOMAIN },
#endif /* TASKS_ENABLED */

    { (gchar*) OSMO_STOCK_TODAY,                   (gchar*) N_("Today"),                        0, 0, TRANSLATION_DOMAIN },

#ifdef PRINTING_SUPPORT
    { (gchar*) OSMO_STOCK_PRINT,                   (gchar*) N_("Print"),                        0, 0, TRANSLATION_DOMAIN },
#endif /* PRINTING_SUPPORT */

	{ (gchar*) OSMO_STOCK_TYPE_NORMAL,              (gchar*) N_("Normal"),                      0, 0, TRANSLATION_DOMAIN },
	{ (gchar*) OSMO_STOCK_TYPE_ENCRYPTED,           (gchar*) N_("Encrypted"),                   0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TYPE_RECURRENT,           (gchar*) N_("Recurrent"),                   0, 0, TRANSLATION_DOMAIN },
    { (gchar*) OSMO_STOCK_TYPE_RECURRENT_INACTIVE,  (gchar*) N_("Inactive recurrent"),          0, 0, TRANSLATION_DOMAIN }
};

const guint8* osmo_stock_item_data[] = {

    (const guint8*) osmo_stock_button_add,
    (const guint8*) osmo_stock_button_clear,
    (const guint8*) osmo_stock_button_close,
    (const guint8*) osmo_stock_button_cancel,
    (const guint8*) osmo_stock_button_jumpto,
    (const guint8*) osmo_stock_button_edit,
    (const guint8*) osmo_stock_button_down,
    (const guint8*) osmo_stock_button_info,
    (const guint8*) osmo_stock_button_insert_timeline,
    (const guint8*) osmo_stock_button_next_year,
    (const guint8*) osmo_stock_button_no,
    (const guint8*) osmo_stock_button_ok,
    (const guint8*) osmo_stock_button_open,
    (const guint8*) osmo_stock_button_prev_year,
    (const guint8*) osmo_stock_button_remove,
    (const guint8*) osmo_stock_button_select_color,
    (const guint8*) osmo_stock_button_select_date,
    (const guint8*) osmo_stock_button_select_font,
    (const guint8*) osmo_stock_button_today,
    (const guint8*) osmo_stock_button_yes,

    (const guint8*) osmo_stock_systray_normal,
    (const guint8*) osmo_stock_systray_note,
    (const guint8*) osmo_stock_systray_menu_calendar,

    (const guint8*) osmo_stock_about,
    (const guint8*) osmo_stock_calendar,
    (const guint8*) osmo_stock_close,
    (const guint8*) osmo_stock_calculator,
    (const guint8*) osmo_stock_edit_note,

#ifdef CONTACTS_ENABLED
    (const guint8*) osmo_stock_contacts_add,
    (const guint8*) osmo_stock_contacts_birthdays,
    (const guint8*) osmo_stock_contacts_edit,
    (const guint8*) osmo_stock_contacts_export,
    (const guint8*) osmo_stock_contacts_import,
    (const guint8*) osmo_stock_contacts_map_location,
    (const guint8*) osmo_stock_contacts_remove,
    (const guint8*) osmo_stock_button_contacts_export,
    (const guint8*) osmo_stock_button_contacts_import,
    (const guint8*) osmo_stock_contacts,
    (const guint8*) osmo_stock_systray_birthday,
    (const guint8*) osmo_stock_systray_menu_contacts,
#endif /* CONTACTS_ENABLED */

#ifdef NOTES_ENABLED
    (const guint8*) osmo_stock_editor_bold,
    (const guint8*) osmo_stock_editor_clear,
    (const guint8*) osmo_stock_editor_find,
    (const guint8*) osmo_stock_editor_highlight,
    (const guint8*) osmo_stock_editor_info,
    (const guint8*) osmo_stock_editor_insert_date_time,
    (const guint8*) osmo_stock_editor_insert_separator,
    (const guint8*) osmo_stock_editor_italic,
    (const guint8*) osmo_stock_editor_save,
    (const guint8*) osmo_stock_editor_spell_checker,
    (const guint8*) osmo_stock_editor_strikethrough,
    (const guint8*) osmo_stock_editor_underline,
    (const guint8*) osmo_stock_notes_add,
    (const guint8*) osmo_stock_notes_edit,
    (const guint8*) osmo_stock_notes_remove,
    (const guint8*) osmo_stock_notes,
    (const guint8*) osmo_stock_systray_menu_notes,
#endif  /* NOTES_ENABLED */
 
    (const guint8*) osmo_stock_fullyear,
    (const guint8*) osmo_stock_help,
    (const guint8*) osmo_stock_info_help,
    (const guint8*) osmo_stock_jumpto,
    (const guint8*) osmo_stock_license,
    (const guint8*) osmo_stock_list_invalid,
    (const guint8*) osmo_stock_list_valid,
    (const guint8*) osmo_stock_next_day,
    (const guint8*) osmo_stock_next_month,
    (const guint8*) osmo_stock_next_year,
    (const guint8*) osmo_stock_preferences,
    (const guint8*) osmo_stock_prev_day,
    (const guint8*) osmo_stock_prev_month,
    (const guint8*) osmo_stock_prev_year,
 
#ifdef TASKS_ENABLED
    (const guint8*) osmo_stock_tasks_add,
    (const guint8*) osmo_stock_tasks_edit,
    (const guint8*) osmo_stock_tasks_remove,
    (const guint8*) osmo_stock_tasks_prev_day,
    (const guint8*) osmo_stock_tasks_next_day,
    (const guint8*) osmo_stock_tasks,
    (const guint8*) osmo_stock_systray_task,
    (const guint8*) osmo_stock_systray_menu_tasks,
#endif  /* TASKS_ENABLED */

    (const guint8*) osmo_stock_today,
#ifdef PRINTING_SUPPORT
    (const guint8*) osmo_stock_print,
#endif /* PRINTING_SUPPORT */

	(const guint8*) osmo_stock_type_normal,
	(const guint8*) osmo_stock_type_encrypted,
    (const guint8*) osmo_stock_type_recurrent,
    (const guint8*) osmo_stock_type_recurrent_inactive
};

    gtk_stock_add (osmo_stock_items, G_N_ELEMENTS (osmo_stock_items));

    factory = gtk_icon_factory_new ();
    gtk_icon_factory_add_default(factory);

    for(i = 0; i < G_N_ELEMENTS(osmo_stock_item_data); i++) {
        pixbuf = gdk_pixbuf_new_from_inline(-1, osmo_stock_item_data[i], FALSE, NULL);
        icon_source = gtk_icon_source_new ();
        gtk_icon_source_set_pixbuf (icon_source, pixbuf);

        icon_set = gtk_icon_set_new ();
        gtk_icon_set_add_source (icon_set, icon_source);

        gtk_icon_factory_add(factory, osmo_stock_items[i].stock_id, icon_set);
        g_object_unref(pixbuf);
        gtk_icon_source_free (icon_source);
        gtk_icon_set_unref (icon_set);
    }

    g_object_unref (factory);

}
/** gui_misc_init:
  *	initializes the module
  */
void gui_misc_init()
{
	GtkIconSource * source;
	GtkIconSet * set;
	struct stock_pixbuf_map * map;
	gint num_items;

	/* setup icon factory and all the icons it contains
	 */
	if(icon_factory==0) {
		/* setup icon factory and all the icons it contains */
		icon_factory = gtk_icon_factory_new();
		gtk_icon_factory_add_default(icon_factory);

		/* register icons */
		for(map = stock_pixbuf_maps; map->stock_id; map ++) {
			GdkPixbuf * pixbuf, * composite;

			g_assert(map->pixbuf);

			set = gtk_icon_set_new();

			/* create icon source for a small 16x16 icon */
			source = gtk_icon_source_new();
			gtk_icon_source_set_size(source, GTK_ICON_SIZE_MENU);

			pixbuf = gdk_pixbuf_new_from_inline(-1, map->pixbuf, TRUE, NULL);
			if(map->pixbuf1) {
				composite = gdk_pixbuf_new_from_inline(
						-1, map->pixbuf1, FALSE, NULL);

				/* add composite pixbuf */
				gdk_pixbuf_composite(
					composite, pixbuf, 0, 0,
					gdk_pixbuf_get_width(pixbuf),
					gdk_pixbuf_get_height(pixbuf),
					0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);

				/* release the composite pixbuf */
				g_object_unref(G_OBJECT(composite));
			}
			gtk_icon_source_set_pixbuf(source, pixbuf);

			gtk_icon_set_add_source(set, source);
			gtk_icon_source_free(source);	/* this will g_object_unref `pixbuf, too */

			/* create icon source for a "button" 24x24 icon (if any) */
			if(map->button_pixbuf) {
				source = gtk_icon_source_new();
				gtk_icon_source_set_size(source, GTK_ICON_SIZE_BUTTON);

				pixbuf = gdk_pixbuf_new_from_inline(
						-1, map->button_pixbuf, TRUE, NULL);
				if(map->button_pixbuf1) {
					composite = gdk_pixbuf_new_from_inline(
							-1, map->button_pixbuf1, FALSE, NULL);

					gdk_pixbuf_composite(
						composite, pixbuf, 0, 0,
						gdk_pixbuf_get_width(pixbuf),
						gdk_pixbuf_get_height(pixbuf),
						0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);

					g_object_unref(G_OBJECT(composite));
				}
				gtk_icon_source_set_pixbuf(source, pixbuf);

				gtk_icon_set_add_source(set, source);
				gtk_icon_source_free(source);	/* this will free the pixbuf, too */
			}

			/* add icon set to icon_factory & release it */
			gtk_icon_factory_add(icon_factory, map->stock_id, set);
			gtk_icon_set_unref(set);
		}
	}

	/* register stock items
	 */
	for(num_items=0; stock_items[num_items].stock_id!=NULL; num_items++) ;
	gtk_stock_add_static(stock_items, num_items);
}
Пример #17
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);
    }
}
Пример #18
0
static void register_pixmaps(void)
{
	gint idx;

	GtkIconFactory *factory = gtk_icon_factory_new();

	for (idx = 0; idx < G_N_ELEMENTS(pioneers_pixmaps); idx++) {
		gchar *filename;
		GtkIconSet *icon;

		icon = gtk_icon_set_new();
		/* determine full path to pixmap file */
		filename = g_build_filename(DATADIR, "pixmaps",
					    pioneers_pixmaps[idx], NULL);
		if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
			GtkIconSource *source;
			GdkPixbuf *pixbuf;
			GError *error = NULL;
			pixbuf =
			    gdk_pixbuf_new_from_file(filename, &error);
			if (error != NULL) {
				g_warning("Error loading pixmap %s\n",
					  filename);
				g_error_free(error);
			} else {
				source = gtk_icon_source_new();
				gtk_icon_source_set_pixbuf(source, pixbuf);
				g_object_unref(pixbuf);
				gtk_icon_set_add_source(icon, source);
				gtk_icon_source_free(source);
			}
		} else {
			/* Missing pixmap */
			g_warning("Pixmap not found: %s", filename);
		}

		gtk_icon_factory_add(factory, pioneers_pixmaps[idx], icon);
		g_free(filename);
		gtk_icon_set_unref(icon);
	}

	gtk_icon_factory_add_default(factory);
	g_object_unref(factory);

	for (idx = 0; idx < NO_RESOURCE; idx++) {
		gchar *filename;

		/* determine full path to pixmap file */
		filename = g_build_filename(DATADIR, "pixmaps",
					    resources_pixmaps[idx], NULL);
		if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
			GdkPixbuf *pixbuf;
			GError *error = NULL;
			pixbuf =
			    gdk_pixbuf_new_from_file(filename, &error);
			if (error != NULL) {
				g_warning("Error loading pixmap %s\n",
					  filename);
				g_error_free(error);
			} else {
				gdk_pixbuf_render_pixmap_and_mask(pixbuf,
								  &resource_pixmap
								  [idx].p,
								  &resource_pixmap
								  [idx].b,
								  128);
				resource_pixmap[idx].gcb =
				    gdk_gc_new(resource_pixmap[idx].b);
				gdk_gc_set_function(resource_pixmap
						    [idx].gcb, GDK_OR);
				resource_pixmap[idx].gcp =
				    gdk_gc_new(resource_pixmap[idx].p);
				gdk_gc_set_clip_mask(resource_pixmap
						     [idx].gcp,
						     resource_pixmap
						     [idx].b);
				if (!resource_pixmap_res)
					resource_pixmap_res =
					    gdk_pixbuf_get_width(pixbuf);
				g_object_unref(pixbuf);
			}
		} else {
			/* Missing pixmap */
			g_warning("Pixmap not found: %s", filename);
		}

		g_free(filename);
	}
}
Пример #19
0
static void
value_filename_edited (GtkCellRendererText * cell,
                       const gchar * path,
                       const gchar * new_text, GladeEditorProperty * eprop)
{
  GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop);
  GladeProperty *property = glade_editor_property_get_property (eprop);
  GtkTreeIter iter;
  GladeIconSources *icon_sources = NULL;
  GtkIconSource *source;
  gchar *icon_name;
  gint index = -1;
  GValue *value;
  GdkPixbuf *pixbuf;
  GList *source_list;

  if (!new_text || !new_text[0])
    {
      g_idle_add ((GSourceFunc) reload_icon_sources_idle, eprop);
      return;
    }

  if (!gtk_tree_model_get_iter_from_string
      (GTK_TREE_MODEL (eprop_sources->store), &iter, path))
    return;

  gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter,
                      COLUMN_ICON_NAME, &icon_name,
                      COLUMN_LIST_INDEX, &index, -1);

  /* get new pixbuf value... */
  value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, new_text,
                                         glade_widget_get_project (glade_property_get_widget (property)));
  pixbuf = g_value_get_object (value);


  glade_property_get (property, &icon_sources);
  if (icon_sources)
    {
      icon_sources = glade_icon_sources_copy (icon_sources);

      if (index >= 0 &&
          (source = get_icon_source (icon_sources, icon_name, index)) != NULL)
        gtk_icon_source_set_pixbuf (source, pixbuf);
      else
        {

          source = gtk_icon_source_new ();
          gtk_icon_source_set_pixbuf (source, pixbuf);

          if ((source_list = g_hash_table_lookup (icon_sources->sources,
                                                  icon_name)) != NULL)
            {
              source_list = g_list_append (source_list, source);
            }
          else
            {
              source_list = g_list_prepend (NULL, source);
              g_hash_table_insert (icon_sources->sources, g_strdup (icon_name),
                                   source_list);
            }
        }
    }
  else
    {
      icon_sources = glade_icon_sources_new ();
      source = gtk_icon_source_new ();
      gtk_icon_source_set_pixbuf (source, pixbuf);

      source_list = g_list_prepend (NULL, source);
      g_hash_table_insert (icon_sources->sources, g_strdup (icon_name),
                           source_list);
    }

  g_value_unset (value);
  g_free (value);

  update_icon_sources (eprop, icon_sources);
}
static void
thunar_icon_renderer_render (GtkCellRenderer     *renderer,
                             GdkWindow           *window,
                             GtkWidget           *widget,
                             GdkRectangle        *background_area,
                             GdkRectangle        *cell_area,
                             GdkRectangle        *expose_area,
                             GtkCellRendererState flags)
{
  ThunarClipboardManager *clipboard;
  ThunarFileIconState     icon_state;
  ThunarIconRenderer     *icon_renderer = THUNAR_ICON_RENDERER (renderer);
  ThunarIconFactory      *icon_factory;
  GtkIconSource          *icon_source;
  GtkIconTheme           *icon_theme;
  GdkRectangle            emblem_area;
  GdkRectangle            icon_area;
  GdkRectangle            draw_area;
  GtkStateType            state;
  GdkPixbuf              *emblem;
  GdkPixbuf              *icon;
  GdkPixbuf              *temp;
  GList                  *emblems;
  GList                  *lp;
  gint                    max_emblems;
  gint                    position;

  if (G_UNLIKELY (icon_renderer->file == NULL))
    return;

  /* determine the icon state */
  icon_state = (icon_renderer->drop_file != icon_renderer->file)
             ? renderer->is_expanded
              ? THUNAR_FILE_ICON_STATE_OPEN
              : THUNAR_FILE_ICON_STATE_DEFAULT
             : THUNAR_FILE_ICON_STATE_DROP;

  /* load the main icon */
  icon_theme = gtk_icon_theme_get_for_screen (gdk_drawable_get_screen (window));
  icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme);
  icon = thunar_icon_factory_load_file_icon (icon_factory, icon_renderer->file, icon_state, icon_renderer->size);
  if (G_UNLIKELY (icon == NULL))
    {
      g_object_unref (G_OBJECT (icon_factory));
      return;
    }

  /* pre-light the item if we're dragging about it */
  if (G_UNLIKELY (icon_state == THUNAR_FILE_ICON_STATE_DROP))
    flags |= GTK_CELL_RENDERER_PRELIT;

  /* determine the real icon size */
  icon_area.width = gdk_pixbuf_get_width (icon);
  icon_area.height = gdk_pixbuf_get_height (icon);

  /* scale down the icon on-demand */
  if (G_UNLIKELY (icon_area.width > cell_area->width || icon_area.height > cell_area->height))
    {
      /* scale down to fit */
      temp = exo_gdk_pixbuf_scale_down (icon, TRUE, cell_area->width, cell_area->height);
      g_object_unref (G_OBJECT (icon));
      icon = temp;

      /* determine the icon dimensions again */
      icon_area.width = gdk_pixbuf_get_width (icon);
      icon_area.height = gdk_pixbuf_get_height (icon);
    }

  icon_area.x = cell_area->x + (cell_area->width - icon_area.width) / 2;
  icon_area.y = cell_area->y + (cell_area->height - icon_area.height) / 2;

  /* check whether the icon is affected by the expose event */
  if (gdk_rectangle_intersect (expose_area, &icon_area, &draw_area))
    {
      /* use a translucent icon to represent cutted and hidden files to the user */
      clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (widget));
      if (thunar_clipboard_manager_has_cutted_file (clipboard, icon_renderer->file))
        {
          /* 50% translucent for cutted files */
          temp = exo_gdk_pixbuf_lucent (icon, 50);
          g_object_unref (G_OBJECT (icon));
          icon = temp;
        }
      else if (thunar_file_is_hidden (icon_renderer->file))
        {
          /* 75% translucent for hidden files */
          temp = exo_gdk_pixbuf_lucent (icon, 75);
          g_object_unref (G_OBJECT (icon));
          icon = temp;
        }
      g_object_unref (G_OBJECT (clipboard));

      /* colorize the icon if we should follow the selection state */
      if ((flags & (GTK_CELL_RENDERER_SELECTED | GTK_CELL_RENDERER_PRELIT)) != 0 && icon_renderer->follow_state)
        {
          if ((flags & GTK_CELL_RENDERER_SELECTED) != 0)
            {
              state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE;
              temp = exo_gdk_pixbuf_colorize (icon, &widget->style->base[state]);
              g_object_unref (G_OBJECT (icon));
              icon = temp;
            }

          if ((flags & GTK_CELL_RENDERER_PRELIT) != 0)
            {
              temp = exo_gdk_pixbuf_spotlight (icon);
              g_object_unref (G_OBJECT (icon));
              icon = temp;
            }
        }

      /* check if we should render an insensitive icon */
      if (G_UNLIKELY (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE || !renderer->sensitive))
        {
          /* allocate an icon source */
          icon_source = gtk_icon_source_new ();
          gtk_icon_source_set_pixbuf (icon_source, icon);
          gtk_icon_source_set_size_wildcarded (icon_source, FALSE);
          gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_SMALL_TOOLBAR);

          /* render the insensitive icon */
          temp = gtk_style_render_icon (widget->style, icon_source, gtk_widget_get_direction (widget),
                                        GTK_STATE_INSENSITIVE, -1, widget, "gtkcellrendererpixbuf");
          g_object_unref (G_OBJECT (icon));
          icon = temp;

          /* release the icon source */
          gtk_icon_source_free (icon_source);
        }

      /* render the invalid parts of the icon */
      gdk_draw_pixbuf (window, widget->style->black_gc, icon,
                       draw_area.x - icon_area.x, draw_area.y - icon_area.y,
                       draw_area.x, draw_area.y, draw_area.width, draw_area.height,
                       GDK_RGB_DITHER_NORMAL, 0, 0);
    }

  /* release the file's icon */
  g_object_unref (G_OBJECT (icon));

  /* check if we should render emblems as well */
  if (G_LIKELY (icon_renderer->emblems))
    {
      /* display the primary emblem as well (if any) */
      emblems = thunar_file_get_emblem_names (icon_renderer->file);
      if (G_UNLIKELY (emblems != NULL))
        {
          /* render up to four emblems for sizes from 48 onwards, else up to 2 emblems */
          max_emblems = (icon_renderer->size < 48) ? 2 : 4;

          /* render the emblems */
          for (lp = emblems, position = 0; lp != NULL && position < max_emblems; lp = lp->next)
            {
              /* check if we have the emblem in the icon theme */
              emblem = thunar_icon_factory_load_icon (icon_factory, lp->data, icon_renderer->size, NULL, FALSE);
              if (G_UNLIKELY (emblem == NULL))
                continue;

              /* determine the dimensions of the emblem */
              emblem_area.width = gdk_pixbuf_get_width (emblem);
              emblem_area.height = gdk_pixbuf_get_height (emblem);

              /* shrink insane emblems */
              if (G_UNLIKELY (MAX (emblem_area.width, emblem_area.height) > (gint) MIN ((2 * icon_renderer->size) / 3, 36)))
                {
                  /* scale down the emblem */
                  temp = exo_gdk_pixbuf_scale_ratio (emblem, MIN ((2 * icon_renderer->size) / 3, 36));
                  g_object_unref (G_OBJECT (emblem));
                  emblem = temp;

                  /* determine the size again */
                  emblem_area.width = gdk_pixbuf_get_width (emblem);
                  emblem_area.height = gdk_pixbuf_get_height (emblem);
                }

              /* determine a good position for the emblem, depending on the position index */
              switch (position)
                {
                case 0: /* right/bottom */
                  emblem_area.x = MIN (icon_area.x + icon_area.width - emblem_area.width / 2,
                                       cell_area->x + cell_area->width - emblem_area.width);
                  emblem_area.y = MIN (icon_area.y + icon_area.height - emblem_area.height / 2,
                                       cell_area->y + cell_area->height -emblem_area.height);
                  break;

                case 1: /* left/bottom */
                  emblem_area.x = MAX (icon_area.x - emblem_area.width / 2,
                                       cell_area->x);
                  emblem_area.y = MIN (icon_area.y + icon_area.height - emblem_area.height / 2,
                                       cell_area->y + cell_area->height -emblem_area.height);
                  break;

                case 2: /* left/top */
                  emblem_area.x = MAX (icon_area.x - emblem_area.width / 2,
                                       cell_area->x);
                  emblem_area.y = MAX (icon_area.y - emblem_area.height / 2,
                                       cell_area->y);
                  break;

                case 3: /* right/top */
                  emblem_area.x = MIN (icon_area.x + icon_area.width - emblem_area.width / 2,
                                       cell_area->x + cell_area->width - emblem_area.width);
                  emblem_area.y = MAX (icon_area.y - emblem_area.height / 2,
                                       cell_area->y);
                  break;

                default:
                  _thunar_assert_not_reached ();
                }

              /* render the emblem */
              if (gdk_rectangle_intersect (expose_area, &emblem_area, &draw_area))
                {
                  gdk_draw_pixbuf (window, widget->style->black_gc, emblem,
                                   draw_area.x - emblem_area.x, draw_area.y - emblem_area.y,
                                   draw_area.x, draw_area.y, draw_area.width, draw_area.height,
                                   GDK_RGB_DITHER_NORMAL, 0, 0);
                }

              /* release the emblem */
              g_object_unref (G_OBJECT (emblem));

              /* advance the position index */
              ++position;
            }

          /* release the emblem name list */
          g_list_free (emblems);
        }
    }

  /* release our reference on the icon factory */
  g_object_unref (G_OBJECT (icon_factory));
}
Пример #21
0
static void
glade_gtk_icon_factory_read_sources (GladeWidget *widget, GladeXmlNode *node)
{
  GladeIconSources *sources;
  GtkIconSource *source;
  GladeXmlNode *sources_node, *source_node;
  GValue *value;
  GList *list;
  gchar *current_icon_name = NULL;
  GdkPixbuf *pixbuf;

  if ((sources_node = glade_xml_search_child (node, GLADE_TAG_SOURCES)) == NULL)
    return;

  sources = glade_icon_sources_new ();

  /* Here we expect all icon sets to remain together in the list. */
  for (source_node = glade_xml_node_get_children (sources_node); source_node;
       source_node = glade_xml_node_next (source_node))
    {
      gchar *icon_name;
      gchar *str;

      if (!glade_xml_node_verify (source_node, GLADE_TAG_SOURCE))
        continue;

      if (!(icon_name =
            glade_xml_get_property_string_required (source_node,
                                                    GLADE_TAG_STOCK_ID, NULL)))
        continue;

      if (!
          (str =
           glade_xml_get_property_string_required (source_node,
                                                   GLADE_TAG_FILENAME, NULL)))
        {
          g_free (icon_name);
          continue;
        }

      if (!current_icon_name || strcmp (current_icon_name, icon_name) != 0)
        current_icon_name = (g_free (current_icon_name), g_strdup (icon_name));

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      source = gtk_icon_source_new ();
G_GNUC_END_IGNORE_DEPRECATIONS

      /* Deal with the filename... */
      value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, str, glade_widget_get_project (widget));
      pixbuf = g_value_dup_object (value);
      g_value_unset (value);
      g_free (value);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      gtk_icon_source_set_pixbuf (source, pixbuf);
G_GNUC_END_IGNORE_DEPRECATIONS
      g_object_unref (G_OBJECT (pixbuf));
      g_free (str);

      /* Now the attributes... */
      if ((str =
           glade_xml_get_property_string (source_node,
                                          GLADE_TAG_DIRECTION)) != NULL)
        {
          GtkTextDirection direction =
              glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION, str);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
          gtk_icon_source_set_direction_wildcarded (source, FALSE);
          gtk_icon_source_set_direction (source, direction);
G_GNUC_END_IGNORE_DEPRECATIONS
          g_free (str);
        }

      if ((str =
           glade_xml_get_property_string (source_node, GLADE_TAG_SIZE)) != NULL)
        {
          GtkIconSize size =
              glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE, str);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
          gtk_icon_source_set_size_wildcarded (source, FALSE);
          gtk_icon_source_set_size (source, size);
G_GNUC_END_IGNORE_DEPRECATIONS
          g_free (str);
        }

      if ((str =
           glade_xml_get_property_string (source_node,
                                          GLADE_TAG_STATE)) != NULL)
        {
          GtkStateType state =
              glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE, str);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
          gtk_icon_source_set_state_wildcarded (source, FALSE);
          gtk_icon_source_set_state (source, state);
G_GNUC_END_IGNORE_DEPRECATIONS
          g_free (str);
        }

      if ((list =
           g_hash_table_lookup (sources->sources,
                                g_strdup (current_icon_name))) != NULL)
        {
          GList *new_list = g_list_append (list, source);

          /* Warning: if we use g_list_prepend() the returned pointer will be different
           * so we would have to replace the list pointer in the hash table.
           * But before doing that we have to steal the old list pointer otherwise
           * we would have to make a copy then add the new icon to finally replace the hash table
           * value.
           * Anyways if we choose to prepend we would have to reverse the list outside this loop
           * so its better to append.
           */
          if (new_list != list)
            {
              /* current g_list_append() returns the same pointer so this is not needed */
              g_hash_table_steal (sources->sources, current_icon_name);
              g_hash_table_insert (sources->sources,
                                   g_strdup (current_icon_name), new_list);
            }
        }
      else
        {
          list = g_list_append (NULL, source);
          g_hash_table_insert (sources->sources, g_strdup (current_icon_name),
                               list);
        }
    }

  if (g_hash_table_size (sources->sources) > 0)
    glade_widget_property_set (widget, "sources", sources);

  glade_icon_sources_free (sources);
}