Example #1
0
static void
register_stock_icon_bidi (GtkIconFactory * icon_factory,
                          const char * stock_id,
                          const char * icon_name_ltr,
                          const char * icon_name_rtl)
{
  GtkIconSource *source;
  GtkIconSet *set;

  set = gtk_icon_set_new ();

  source = gtk_icon_source_new ();
  gtk_icon_source_set_icon_name (source, icon_name_ltr);
  gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
  gtk_icon_source_set_direction_wildcarded (source, FALSE);
  gtk_icon_set_add_source (set, source);
  gtk_icon_source_free (source);

  source = gtk_icon_source_new ();
  gtk_icon_source_set_icon_name (source, icon_name_rtl);
  gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
  gtk_icon_source_set_direction_wildcarded (source, FALSE);
  gtk_icon_set_add_source (set, source);
  gtk_icon_source_free (source);

  gtk_icon_factory_add (icon_factory, stock_id, set);
  gtk_icon_set_unref (set);
}
Example #2
0
static void
add_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, PidginIconTheme *theme,
		const char *size, SizedStockIcon sized_icon, gboolean translucent)
{
	char *filename;
	GtkIconSource *source;
	GdkPixbuf *pixbuf;

	filename = find_icon_file(theme, size, sized_icon, FALSE);
	g_return_if_fail(filename != NULL);
	pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
	if (translucent)
		do_alphashift(pixbuf, pixbuf);

	source = gtk_icon_source_new();
	gtk_icon_source_set_pixbuf(source, pixbuf);
	gtk_icon_source_set_direction(source, GTK_TEXT_DIR_LTR);
	gtk_icon_source_set_direction_wildcarded(source, !sized_icon.rtl);
	gtk_icon_source_set_size(source, sizeid);
	gtk_icon_source_set_size_wildcarded(source, FALSE);
	gtk_icon_source_set_state_wildcarded(source, TRUE);
	gtk_icon_set_add_source(iconset, source);
	gtk_icon_source_free(source);

	if (sizeid == gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL)) {
		source = gtk_icon_source_new();
		gtk_icon_source_set_pixbuf(source, pixbuf);
		gtk_icon_source_set_direction_wildcarded(source, TRUE);
		gtk_icon_source_set_size(source, GTK_ICON_SIZE_MENU);
		gtk_icon_source_set_size_wildcarded(source, FALSE);
		gtk_icon_source_set_state_wildcarded(source, TRUE);
		gtk_icon_set_add_source(iconset, source);
		gtk_icon_source_free(source);
	}
	g_free(filename);
	g_object_unref(pixbuf);

	if (sized_icon.rtl) {
		filename = find_icon_file(theme, size, sized_icon, TRUE);
		g_return_if_fail(filename != NULL);
		pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
		if (translucent)
			do_alphashift(pixbuf, pixbuf);

		source = gtk_icon_source_new();
		gtk_icon_source_set_pixbuf(source, pixbuf);
		gtk_icon_source_set_filename(source, filename);
		gtk_icon_source_set_direction(source, GTK_TEXT_DIR_RTL);
		gtk_icon_source_set_size(source, sizeid);
		gtk_icon_source_set_size_wildcarded(source, FALSE);
		gtk_icon_source_set_state_wildcarded(source, TRUE);
		gtk_icon_set_add_source(iconset, source);
		g_free(filename);
		g_object_unref(pixbuf);
		gtk_icon_source_free(source);
	}
}
static GtkIconSource*
make_icon_source (const gchar *icon, const gchar *base, const gchar *ext, 
                  GtkIconSize size)
{
    GtkIconSource *source;
    gchar *filename;
    
    filename = g_strdup_printf ("%s/%s/%s.%s", PIXMAPSDIR, base, icon, ext);
    
    source = gtk_icon_source_new ();
    gtk_icon_source_set_filename (source, filename);
    gtk_icon_source_set_direction_wildcarded (source, TRUE);
    gtk_icon_source_set_state_wildcarded (source, TRUE);
    
    if (size == -1) {
        gtk_icon_source_set_size_wildcarded (source, TRUE);
    } else {
        gtk_icon_source_set_size_wildcarded (source, FALSE);
        gtk_icon_source_set_size (source, size);
    }
    
    g_free(filename);
    
    return source;
}
Example #4
0
void
camorama_stock_init(void) {
    GtkIconFactory* factory = gtk_icon_factory_new();
    GtkIconSet    * set = gtk_icon_set_new ();
    GtkIconSource * source = gtk_icon_source_new();

    gtk_stock_add_static(camorama_items, G_N_ELEMENTS(camorama_items));

    gtk_icon_source_set_size_wildcarded(source, TRUE);
    gtk_icon_source_set_direction_wildcarded(source, TRUE);
    gtk_icon_source_set_state_wildcarded(source, TRUE);

    gtk_icon_source_set_icon_name(source, CAMORAMA_STOCK_WEBCAM);
    gtk_icon_set_add_source(set, source);

    gtk_icon_factory_add(factory, CAMORAMA_STOCK_WEBCAM, set);

    add_default_image(CAMORAMA_STOCK_WEBCAM, 16, camorama_webcam_16);
    add_default_image(CAMORAMA_STOCK_WEBCAM, 24, camorama_webcam_24);

    gtk_icon_factory_add_default(factory);

    gtk_icon_set_unref(set);
    gtk_icon_source_free(source);
}
Example #5
0
static void
value_attribute_toggled (GtkCellRendererToggle * cell_renderer,
                         gchar * path, 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, edit_column;
  gboolean edit_column_active = FALSE;

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

  edit_column =
      GPOINTER_TO_INT (g_object_get_data
                       (G_OBJECT (cell_renderer), "attribute-column"));
  gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter,
                      COLUMN_ICON_NAME, &icon_name, COLUMN_LIST_INDEX, &index,
                      edit_column, &edit_column_active, -1);

  glade_property_get (property, &icon_sources);

  if (icon_sources)
    icon_sources = glade_icon_sources_copy (icon_sources);

  if (icon_sources &&
      (source = get_icon_source (icon_sources, icon_name, index)) != NULL)
    {
      /* Note the reverse meaning of active toggles vs. wildcarded sources... */
      switch (edit_column)
        {
          case COLUMN_DIRECTION_ACTIVE:
            gtk_icon_source_set_direction_wildcarded (source,
                                                      edit_column_active);
            break;
          case COLUMN_SIZE_ACTIVE:
            gtk_icon_source_set_size_wildcarded (source, edit_column_active);
            break;
          case COLUMN_STATE_ACTIVE:
            gtk_icon_source_set_state_wildcarded (source, edit_column_active);
            break;
          default:
            break;
        }

      update_icon_sources (eprop, icon_sources);
      g_free (icon_name);
      return;
    }

  if (icon_sources)
    glade_icon_sources_free (icon_sources);
  g_free (icon_name);
  return;
}
Example #6
0
File: icons.c Project: 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);
}
static GtkIconSource*
make_theme_source (const gchar *icon, GtkIconSize size)
{
    GtkIconSource *source;

    source = gtk_icon_source_new ();
    gtk_icon_source_set_icon_name (source, icon);
    gtk_icon_source_set_direction_wildcarded (source, TRUE);
    gtk_icon_source_set_state_wildcarded (source, TRUE);
    
    if (size == -1) {
        gtk_icon_source_set_size_wildcarded (source, TRUE);
    } else {
        gtk_icon_source_set_size_wildcarded (source, FALSE);
        gtk_icon_source_set_size (source, size);
    }
    
    return source;
}
Example #8
0
static void
register_stock_icon (GtkIconFactory *factory,
		     const gchar    *stock_id,
                     const gchar    *icon_name)
{
  GtkIconSet    *set    = gtk_icon_set_new ();
  GtkIconSource *source = gtk_icon_source_new ();

  gtk_icon_source_set_direction_wildcarded (source, TRUE);
  gtk_icon_source_set_size_wildcarded (source, TRUE);
  gtk_icon_source_set_state_wildcarded (source, TRUE);
  gtk_icon_source_set_icon_name (source, icon_name);

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

  gtk_icon_factory_add (factory, stock_id, set);
  gtk_icon_set_unref (set);
}
Example #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);
}
Example #10
0
void
pidgin_stock_load_stock_icon_theme(PidginStockIconTheme *theme)
{
	GtkIconFactory *icon_factory;
	gint i;
	GtkWidget *win;

	if (theme != NULL) {
		purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme",
		                        purple_theme_get_name(PURPLE_THEME(theme)));
		purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir",
		                      purple_theme_get_dir(PURPLE_THEME(theme)));
	}
	else {
		purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", "");
		purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", "");
	}

	icon_factory = gtk_icon_factory_new();

	gtk_icon_factory_add_default(icon_factory);

	win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_realize(win);

	/* All non-sized icons */
	for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) {
		GtkIconSource *source;
		GtkIconSet *iconset;
		gchar *filename;

		if (stock_icons[i].dir == NULL) {
			/* GTK+ Stock icon */
			iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win),
					stock_icons[i].filename);
		} else {
			filename = find_file(stock_icons[i].dir, stock_icons[i].filename);

			if (filename == NULL)
				continue;

			source = gtk_icon_source_new();
			gtk_icon_source_set_filename(source, filename);
			gtk_icon_source_set_direction_wildcarded(source, TRUE);
			gtk_icon_source_set_size_wildcarded(source, TRUE);
			gtk_icon_source_set_state_wildcarded(source, TRUE);

			iconset = gtk_icon_set_new();
			gtk_icon_set_add_source(iconset, source);

			gtk_icon_source_free(source);
			g_free(filename);
		}

		gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset);

		gtk_icon_set_unref(iconset);
	}

	/* All non-status sized icons */
	for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++)
	{
		GtkIconSet *iconset = gtk_icon_set_new();

#define ADD_SIZED_ICON(name, size) \
		if (sized_stock_icons[i].name) \
			add_sized_icon(iconset, name, PIDGIN_ICON_THEME(theme), size, sized_stock_icons[i], FALSE);
		ADD_SIZED_ICON(microscopic, "11");
		ADD_SIZED_ICON(extra_small, "16");
		ADD_SIZED_ICON(small, "22");
		ADD_SIZED_ICON(medium, "32");
		ADD_SIZED_ICON(large, "48");
		ADD_SIZED_ICON(huge, "64");
#undef ADD_SIZED_ICON

		gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset);
		gtk_icon_set_unref(iconset);
	}

	gtk_widget_destroy(win);
	g_object_unref(G_OBJECT(icon_factory));
	reload_settings();
}
Example #11
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);
}