Example #1
0
static void
real_add (const GtkStockItem *items,
          guint               n_items,
          gboolean            copy,
          gboolean            replace_primary)
{
  int i;

  init_stock_hash ();

  if (n_items == 0)
    return;

  i = 0;
  while (i < n_items)
    {
      gpointer old_key, old_value;
      const GtkStockItem *item = &items[i];

      if (replace_primary && (guint)item->modifier == PRIMARY_MODIFIER)
        {
          item = gtk_stock_item_copy (item);
          ((GtkStockItem *)item)->modifier = (NON_STATIC_MASK |
                                              _gtk_get_primary_accel_mod ());
        }
      else
        {
          if (item->modifier & NON_STATIC_MASK)
            {
              g_warning ("Bit 29 set in stock accelerator.\n");
              copy = TRUE;
            }

          if (copy)
            {
              item = gtk_stock_item_copy (item);
              ((GtkStockItem *)item)->modifier |= NON_STATIC_MASK;
            }
        }

      if (g_hash_table_lookup_extended (stock_hash, item->stock_id,
                                        &old_key, &old_value))
        {
          g_hash_table_remove (stock_hash, old_key);
	  if (((GtkStockItem *)old_value)->modifier & NON_STATIC_MASK)
	    gtk_stock_item_free (old_value);
        }
      
      g_hash_table_insert (stock_hash,
                           (gchar*)item->stock_id, (GtkStockItem*)item);

      ++i;
    }
}
Example #2
0
File: gtkstock.c Project: BYC/gtk
/**
 * gtk_stock_list_ids:
 * 
 * Retrieves a list of all known stock IDs added to a #GtkIconFactory
 * or registered with gtk_stock_add(). The list must be freed with g_slist_free(),
 * and each string in the list must be freed with g_free().
 *
 * Return value: (element-type utf8) (transfer full): a list of known stock IDs
 **/
GSList*
gtk_stock_list_ids (void)
{
  GList *ids;
  GList *icon_ids;
  GSList *retval;
  const gchar *last_id;
  
  init_stock_hash ();

  ids = g_hash_table_get_keys (stock_hash);
  icon_ids = _gtk_icon_factory_list_ids ();
  ids = g_list_concat (ids, icon_ids);

  ids = g_list_sort (ids, (GCompareFunc)strcmp);

  last_id = NULL;
  retval = NULL;
  while (ids != NULL)
    {
      GList *next;

      next = g_list_next (ids);

      if (last_id && strcmp (ids->data, last_id) == 0)
        {
          /* duplicate, ignore */
        }
      else
        {
          retval = g_slist_prepend (retval, g_strdup (ids->data));
          last_id = ids->data;
        }

      g_list_free_1 (ids);
      
      ids = next;
    }

  return retval;
}
Example #3
0
File: gtkstock.c Project: BYC/gtk
/**
 * gtk_stock_lookup:
 * @stock_id: a stock item name
 * @item: (out): stock item to initialize with values
 * 
 * Fills @item with the registered values for @stock_id, returning %TRUE
 * if @stock_id was known.
 * 
 * 
 * Return value: %TRUE if @item was initialized
 **/
gboolean
gtk_stock_lookup (const gchar  *stock_id,
                  GtkStockItem *item)
{
  const GtkStockItem *found;

  g_return_val_if_fail (stock_id != NULL, FALSE);
  g_return_val_if_fail (item != NULL, FALSE);

  init_stock_hash ();

  found = g_hash_table_lookup (stock_hash, stock_id);

  if (found)
    {
      *item = *found;
      item->modifier &= ~NON_STATIC_MASK;
      if (item->label)
	{
	  GtkStockTranslateFunc *translate;
	  
	  if (item->translation_domain)
	    translate = (GtkStockTranslateFunc *) 
	      g_hash_table_lookup (translate_hash, item->translation_domain);
	  else
	    translate = NULL;
	  
	  if (translate != NULL && translate->func != NULL)
	    item->label = (* translate->func) (item->label, translate->data);
	  else
	    item->label = (gchar *) g_dgettext (item->translation_domain, item->label);
	}
    }

  return found != NULL;
}