1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include <gdk/gdkkeysyms.h>
31 static GHashTable *stock_hash = NULL;
32 static void init_stock_hash (void);
35 real_add (const GtkStockItem *items,
49 gpointer old_key, old_value;
50 const GtkStockItem *item = &items[i];
52 item = gtk_stock_item_copy (item);
54 if (g_hash_table_lookup_extended (stock_hash, item->stock_id,
55 &old_key, &old_value))
57 g_hash_table_remove (stock_hash, old_key);
58 gtk_stock_item_free (old_value);
61 g_hash_table_insert (stock_hash,
62 (gchar*)item->stock_id, (GtkStockItem*)item);
69 gtk_stock_add (const GtkStockItem *items,
72 g_return_if_fail (items != NULL);
74 real_add (items, n_items, TRUE);
78 gtk_stock_add_static (const GtkStockItem *items,
81 g_return_if_fail (items != NULL);
83 real_add (items, n_items, FALSE);
87 gtk_stock_lookup (const gchar *stock_id,
90 const GtkStockItem *found;
92 g_return_val_if_fail (stock_id != NULL, FALSE);
93 g_return_val_if_fail (item != NULL, FALSE);
97 found = g_hash_table_lookup (stock_hash, stock_id);
103 item->label = dgettext (item->translation_domain, item->label);
106 return found != NULL;
110 listify_foreach (gpointer key, gpointer value, gpointer data)
112 GSList **list = data;
114 *list = g_slist_prepend (*list, value);
118 g_hash_table_get_values (GHashTable *table)
122 g_hash_table_foreach (table, listify_foreach, &list);
128 gtk_stock_list_items (void)
132 return g_hash_table_get_values (stock_hash);
136 gtk_stock_item_copy (const GtkStockItem *item)
140 g_return_val_if_fail (item != NULL, NULL);
142 copy = g_new (GtkStockItem, 1);
146 copy->stock_id = g_strdup (item->stock_id);
147 copy->label = g_strdup (item->label);
148 copy->translation_domain = g_strdup (item->translation_domain);
154 gtk_stock_item_free (GtkStockItem *item)
156 g_return_if_fail (item != NULL);
158 g_free ((gchar*)item->stock_id);
159 g_free ((gchar*)item->label);
160 g_free ((gchar*)item->translation_domain);
165 static GtkStockItem builtin_items [] =
167 /* KEEP IN SYNC with gtkiconfactory.c stock icons */
169 { GTK_STOCK_DIALOG_INFO, N_("Information"), 0, 0, GETTEXT_PACKAGE },
170 { GTK_STOCK_DIALOG_WARNING, N_("Warning"), 0, 0, GETTEXT_PACKAGE },
171 { GTK_STOCK_DIALOG_ERROR, N_("Error"), 0, 0, GETTEXT_PACKAGE },
172 { GTK_STOCK_DIALOG_QUESTION, N_("Question"), 0, 0, GETTEXT_PACKAGE },
174 { GTK_STOCK_BUTTON_APPLY, N_("_Apply"), 0, 0, GETTEXT_PACKAGE },
175 { GTK_STOCK_BUTTON_OK, N_("OK"), 0, 0, GETTEXT_PACKAGE },
176 { GTK_STOCK_BUTTON_CANCEL, N_("Cancel"), 0, 0, GETTEXT_PACKAGE },
177 { GTK_STOCK_BUTTON_CLOSE, N_("_Close"), 0, 0, GETTEXT_PACKAGE },
178 { GTK_STOCK_BUTTON_YES, N_("_Yes"), 0, 0, GETTEXT_PACKAGE },
179 { GTK_STOCK_BUTTON_NO, N_("_No"), 0, 0, GETTEXT_PACKAGE },
181 { GTK_STOCK_CLOSE, N_("Close"), GDK_CONTROL_MASK, 'w', GETTEXT_PACKAGE },
182 { GTK_STOCK_QUIT, N_("Quit"), GDK_CONTROL_MASK, 'q', GETTEXT_PACKAGE },
183 { GTK_STOCK_HELP, N_("Help"), GDK_CONTROL_MASK, 'h', GETTEXT_PACKAGE },
184 { GTK_STOCK_NEW, N_("New"), GDK_CONTROL_MASK, 'n', GETTEXT_PACKAGE },
185 { GTK_STOCK_OPEN, N_("Open"), GDK_CONTROL_MASK, 'o', GETTEXT_PACKAGE },
186 { GTK_STOCK_SAVE, N_("Save"), GDK_CONTROL_MASK, 's', GETTEXT_PACKAGE }
190 init_stock_hash (void)
192 if (stock_hash == NULL)
194 stock_hash = g_hash_table_new (g_str_hash, g_str_equal);
196 gtk_stock_add_static (builtin_items, G_N_ELEMENTS (builtin_items));