]> Pileus Git - ~andy/gtk/blob - gtk/gtkstock.c
Fix docs build
[~andy/gtk] / gtk / gtkstock.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2000 Red Hat, Inc. 
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "config.h"
28 #include <string.h>
29
30 #include "gtkstock.h"
31 #include "gtkiconfactory.h"
32 #include "gtkintl.h"
33 #include <gdk/gdkkeysyms.h>
34 #include "gtkalias.h"
35
36 static GHashTable *translate_hash = NULL;
37 static GHashTable *stock_hash = NULL;
38 static void init_stock_hash (void);
39
40 /* We use an unused modifier bit to mark stock items which
41  * must be freed when they are removed from the hash table.
42  */
43 #define NON_STATIC_MASK (1 << 29)
44
45 typedef struct _GtkStockTranslateFunc GtkStockTranslateFunc;
46 struct _GtkStockTranslateFunc
47 {
48   GtkTranslateFunc func;
49   gpointer data;
50   GDestroyNotify notify;
51 };
52
53 static void
54 real_add (const GtkStockItem *items,
55           guint               n_items,
56           gboolean            copy)
57 {
58   int i;
59
60   init_stock_hash ();
61
62   if (n_items == 0)
63     return;
64
65   i = 0;
66   while (i < n_items)
67     {
68       gpointer old_key, old_value;
69       const GtkStockItem *item = &items[i];
70
71       if (item->modifier & NON_STATIC_MASK)
72         {
73           g_warning ("Bit 29 set in stock accelerator.\n");
74           copy = TRUE;
75         }
76
77       if (copy)
78         {
79           item = gtk_stock_item_copy (item);
80           ((GtkStockItem *)item)->modifier |= NON_STATIC_MASK;
81         }
82
83       if (g_hash_table_lookup_extended (stock_hash, item->stock_id,
84                                         &old_key, &old_value))
85         {
86           g_hash_table_remove (stock_hash, old_key);
87           if (((GtkStockItem *)old_value)->modifier & NON_STATIC_MASK)
88             gtk_stock_item_free (old_value);
89         }
90       
91       g_hash_table_insert (stock_hash,
92                            (gchar*)item->stock_id, (GtkStockItem*)item);
93
94       ++i;
95     }
96 }
97
98 /**
99  * gtk_stock_add:
100  * @items: a #GtkStockItem or array of items
101  * @n_items: number of #GtkStockItem in @items
102  *
103  * Registers each of the stock items in @items. If an item already
104  * exists with the same stock ID as one of the @items, the old item
105  * gets replaced. The stock items are copied, so GTK+ does not hold
106  * any pointer into @items and @items can be freed. Use
107  * gtk_stock_add_static() if @items is persistent and GTK+ need not
108  * copy the array.
109  * 
110  **/
111 void
112 gtk_stock_add (const GtkStockItem *items,
113                guint               n_items)
114 {
115   g_return_if_fail (items != NULL);
116
117   real_add (items, n_items, TRUE);
118 }
119
120 /**
121  * gtk_stock_add_static:
122  * @items: a #GtkStockItem or array of #GtkStockItem
123  * @n_items: number of items
124  *
125  * Same as gtk_stock_add(), but doesn't copy @items, so
126  * @items must persist until application exit.
127  * 
128  **/
129 void
130 gtk_stock_add_static (const GtkStockItem *items,
131                       guint               n_items)
132 {
133   g_return_if_fail (items != NULL);
134
135   real_add (items, n_items, FALSE);
136 }
137
138 /**
139  * gtk_stock_lookup:
140  * @stock_id: a stock item name
141  * @item: stock item to initialize with values
142  * 
143  * Fills @item with the registered values for @stock_id, returning %TRUE
144  * if @stock_id was known.
145  * 
146  * 
147  * Return value: %TRUE if @item was initialized
148  **/
149 gboolean
150 gtk_stock_lookup (const gchar  *stock_id,
151                   GtkStockItem *item)
152 {
153   const GtkStockItem *found;
154
155   g_return_val_if_fail (stock_id != NULL, FALSE);
156   g_return_val_if_fail (item != NULL, FALSE);
157
158   init_stock_hash ();
159
160   found = g_hash_table_lookup (stock_hash, stock_id);
161
162   if (found)
163     {
164       *item = *found;
165       item->modifier &= ~NON_STATIC_MASK;
166       if (item->label)
167         {
168           GtkStockTranslateFunc *translate;
169           
170           if (item->translation_domain)
171             translate = (GtkStockTranslateFunc *) 
172               g_hash_table_lookup (translate_hash, item->translation_domain);
173           else
174             translate = NULL;
175           
176           if (translate != NULL && translate->func != NULL)
177             item->label = (* translate->func) (item->label, translate->data);
178           else
179             item->label = (gchar *) g_dgettext (item->translation_domain, item->label);
180         }
181     }
182
183   return found != NULL;
184 }
185
186 /**
187  * gtk_stock_list_ids:
188  * 
189  * Retrieves a list of all known stock IDs added to a #GtkIconFactory
190  * or registered with gtk_stock_add(). The list must be freed with g_slist_free(),
191  * and each string in the list must be freed with g_free().
192  * 
193  * Return value: a list of known stock IDs
194  **/
195 GSList*
196 gtk_stock_list_ids (void)
197 {
198   GList *ids;
199   GList *icon_ids;
200   GSList *retval;
201   const gchar *last_id;
202   
203   init_stock_hash ();
204
205   ids = g_hash_table_get_keys (stock_hash);
206   icon_ids = _gtk_icon_factory_list_ids ();
207   ids = g_list_concat (ids, icon_ids);
208
209   ids = g_list_sort (ids, (GCompareFunc)strcmp);
210
211   last_id = NULL;
212   retval = NULL;
213   while (ids != NULL)
214     {
215       GList *next;
216
217       next = g_list_next (ids);
218
219       if (last_id && strcmp (ids->data, last_id) == 0)
220         {
221           /* duplicate, ignore */
222         }
223       else
224         {
225           retval = g_slist_prepend (retval, g_strdup (ids->data));
226           last_id = ids->data;
227         }
228
229       g_list_free_1 (ids);
230       
231       ids = next;
232     }
233
234   return retval;
235 }
236
237 /**
238  * gtk_stock_item_copy:
239  * @item: a #GtkStockItem
240  * 
241  * Copies a stock item, mostly useful for language bindings and not in applications.
242  * 
243  * Return value: a new #GtkStockItem
244  **/
245 GtkStockItem *
246 gtk_stock_item_copy (const GtkStockItem *item)
247 {
248   GtkStockItem *copy;
249
250   g_return_val_if_fail (item != NULL, NULL);
251
252   copy = g_new (GtkStockItem, 1);
253
254   *copy = *item;
255
256   copy->stock_id = g_strdup (item->stock_id);
257   copy->label = g_strdup (item->label);
258   copy->translation_domain = g_strdup (item->translation_domain);
259
260   return copy;
261 }
262
263 /**
264  * gtk_stock_item_free:
265  * @item: a #GtkStockItem
266  *
267  * Frees a stock item allocated on the heap, such as one returned by
268  * gtk_stock_item_copy(). Also frees the fields inside the stock item,
269  * if they are not %NULL.
270  * 
271  **/
272 void
273 gtk_stock_item_free (GtkStockItem *item)
274 {
275   g_return_if_fail (item != NULL);
276
277   g_free ((gchar*)item->stock_id);
278   g_free ((gchar*)item->label);
279   g_free ((gchar*)item->translation_domain);
280
281   g_free (item);
282 }
283
284 static const GtkStockItem builtin_items [] =
285 {
286   /* KEEP IN SYNC with gtkiconfactory.c stock icons, when appropriate */ 
287  
288   { GTK_STOCK_DIALOG_INFO, NC_("Stock label", "Information"), 0, 0, GETTEXT_PACKAGE },
289   { GTK_STOCK_DIALOG_WARNING, NC_("Stock label", "Warning"), 0, 0, GETTEXT_PACKAGE },
290   { GTK_STOCK_DIALOG_ERROR, NC_("Stock label", "Error"), 0, 0, GETTEXT_PACKAGE },
291   { GTK_STOCK_DIALOG_QUESTION, NC_("Stock label", "Question"), 0, 0, GETTEXT_PACKAGE },
292
293   /*  FIXME these need accelerators when appropriate, and
294    * need the mnemonics to be rationalized
295    */
296   { GTK_STOCK_ABOUT, NC_("Stock label", "_About"), 0, 0, GETTEXT_PACKAGE },
297   { GTK_STOCK_ADD, NC_("Stock label", "_Add"), 0, 0, GETTEXT_PACKAGE },
298   { GTK_STOCK_APPLY, NC_("Stock label", "_Apply"), 0, 0, GETTEXT_PACKAGE },
299   { GTK_STOCK_BOLD, NC_("Stock label", "_Bold"), 0, 0, GETTEXT_PACKAGE },
300   { GTK_STOCK_CANCEL, NC_("Stock label", "_Cancel"), 0, 0, GETTEXT_PACKAGE },
301   { GTK_STOCK_CDROM, NC_("Stock label", "_CD-Rom"), 0, 0, GETTEXT_PACKAGE },
302   { GTK_STOCK_CLEAR, NC_("Stock label", "_Clear"), 0, 0, GETTEXT_PACKAGE },
303   { GTK_STOCK_CLOSE, NC_("Stock label", "_Close"), GDK_CONTROL_MASK, 'w', GETTEXT_PACKAGE },
304   { GTK_STOCK_CONNECT, NC_("Stock label", "C_onnect"), 0, 0, GETTEXT_PACKAGE },
305   { GTK_STOCK_CONVERT, NC_("Stock label", "_Convert"), 0, 0, GETTEXT_PACKAGE },
306    { GTK_STOCK_COPY, NC_("Stock label", "_Copy"), GDK_CONTROL_MASK, 'c', GETTEXT_PACKAGE },
307   { GTK_STOCK_CUT, NC_("Stock label", "Cu_t"), GDK_CONTROL_MASK, 'x', GETTEXT_PACKAGE },
308   { GTK_STOCK_DELETE, NC_("Stock label", "_Delete"), 0, 0, GETTEXT_PACKAGE },
309   { GTK_STOCK_DISCARD, NC_("Stock label", "_Discard"), 0, 0, GETTEXT_PACKAGE },
310   { GTK_STOCK_DISCONNECT, NC_("Stock label", "_Disconnect"), 0, 0, GETTEXT_PACKAGE },
311   { GTK_STOCK_EXECUTE, NC_("Stock label", "_Execute"), 0, 0, GETTEXT_PACKAGE },
312   { GTK_STOCK_EDIT, NC_("Stock label", "_Edit"), 0, 0, GETTEXT_PACKAGE },
313   { GTK_STOCK_FIND, NC_("Stock label", "_Find"), GDK_CONTROL_MASK, 'f', GETTEXT_PACKAGE },
314   { GTK_STOCK_FIND_AND_REPLACE, NC_("Stock label", "Find and _Replace"), GDK_CONTROL_MASK, 'r', GETTEXT_PACKAGE },
315   { GTK_STOCK_FLOPPY, NC_("Stock label", "_Floppy"), 0, 0, GETTEXT_PACKAGE },
316   { GTK_STOCK_FULLSCREEN, NC_("Stock label", "_Fullscreen"), 0, 0, GETTEXT_PACKAGE },
317   { GTK_STOCK_LEAVE_FULLSCREEN, NC_("Stock label", "_Leave Fullscreen"), 0, 0, GETTEXT_PACKAGE },
318   /* This is a navigation label as in "go to the bottom of the page" */
319   { GTK_STOCK_GOTO_BOTTOM, NC_("Stock label, navigation", "_Bottom"), 0, 0, GETTEXT_PACKAGE "-navigation" },
320   /* This is a navigation label as in "go to the first page" */
321   { GTK_STOCK_GOTO_FIRST, NC_("Stock label, navigation", "_First"), 0, 0, GETTEXT_PACKAGE "-navigation" },
322   /* This is a navigation label as in "go to the last page" */
323   { GTK_STOCK_GOTO_LAST, NC_("Stock label, navigation", "_Last"), 0, 0, GETTEXT_PACKAGE "-navigation" },
324   /* This is a navigation label as in "go to the top of the page" */
325   { GTK_STOCK_GOTO_TOP, NC_("Stock label, navigation", "_Top"), 0, 0, GETTEXT_PACKAGE "-navigation" },
326   /* This is a navigation label as in "go back" */
327   { GTK_STOCK_GO_BACK, NC_("Stock label, navigation", "_Back"), 0, 0, GETTEXT_PACKAGE "-navigation" },
328   /* This is a navigation label as in "go down" */
329   { GTK_STOCK_GO_DOWN, NC_("Stock label, navigation", "_Down"), 0, 0, GETTEXT_PACKAGE "-navigation" },
330   /* This is a navigation label as in "go forward" */
331   { GTK_STOCK_GO_FORWARD, NC_("Stock label, navigation", "_Forward"), 0, 0, GETTEXT_PACKAGE "-navigation" },
332   /* This is a navigation label as in "go up" */
333   { GTK_STOCK_GO_UP, NC_("Stock label, navigation", "_Up"), 0, 0, GETTEXT_PACKAGE "-navigation" },
334   { GTK_STOCK_HARDDISK, NC_("Stock label", "_Harddisk"), 0, 0, GETTEXT_PACKAGE },
335   { GTK_STOCK_HELP, NC_("Stock label", "_Help"), GDK_CONTROL_MASK, 'h', GETTEXT_PACKAGE },
336   { GTK_STOCK_HOME, NC_("Stock label", "_Home"), 0, 0, GETTEXT_PACKAGE },
337   { GTK_STOCK_INDENT, NC_("Stock label", "Increase Indent"), 0, 0, GETTEXT_PACKAGE },
338   { GTK_STOCK_UNINDENT, NC_("Stock label", "Decrease Indent"), 0, 0, GETTEXT_PACKAGE },
339   { GTK_STOCK_INDEX, NC_("Stock label", "_Index"), 0, 0, GETTEXT_PACKAGE },
340   { GTK_STOCK_INFO, NC_("Stock label", "_Information"), 0, 0, GETTEXT_PACKAGE },
341   { GTK_STOCK_ITALIC, NC_("Stock label", "_Italic"), 0, 0, GETTEXT_PACKAGE },
342   { GTK_STOCK_JUMP_TO, NC_("Stock label", "_Jump to"), 0, 0, GETTEXT_PACKAGE },
343   /* This is about text justification, "centered text" */
344   { GTK_STOCK_JUSTIFY_CENTER, NC_("Stock label", "_Center"), 0, 0, GETTEXT_PACKAGE },
345   /* This is about text justification */
346   { GTK_STOCK_JUSTIFY_FILL, NC_("Stock label", "_Fill"), 0, 0, GETTEXT_PACKAGE },
347   /* This is about text justification, "left-justified text" */
348   { GTK_STOCK_JUSTIFY_LEFT, NC_("Stock label", "_Left"), 0, 0, GETTEXT_PACKAGE },
349   /* This is about text justification, "right-justified text" */
350   { GTK_STOCK_JUSTIFY_RIGHT, NC_("Stock label", "_Right"), 0, 0, GETTEXT_PACKAGE },
351
352   /* Media label, as in "fast forward" */
353   { GTK_STOCK_MEDIA_FORWARD, NC_("Stock label, media", "_Forward"), 0, 0, GETTEXT_PACKAGE "-media" },
354   /* Media label, as in "next song" */
355   { GTK_STOCK_MEDIA_NEXT, NC_("Stock label, media", "_Next"), 0, 0, GETTEXT_PACKAGE "-media" },
356   /* Media label, as in "pause music" */
357   { GTK_STOCK_MEDIA_PAUSE, NC_("Stock label, media", "P_ause"), 0, 0, GETTEXT_PACKAGE "-media" },
358   /* Media label, as in "play music" */
359   { GTK_STOCK_MEDIA_PLAY, NC_("Stock label, media", "_Play"), 0, 0, GETTEXT_PACKAGE "-media" },
360   /* Media label, as in  "previous song" */
361   { GTK_STOCK_MEDIA_PREVIOUS, NC_("Stock label, media", "Pre_vious"), 0, 0, GETTEXT_PACKAGE "-media" },
362   /* Media label */
363   { GTK_STOCK_MEDIA_RECORD, NC_("Stock label, media", "_Record"), 0, 0, GETTEXT_PACKAGE "-media" },
364   /* Media label */
365   { GTK_STOCK_MEDIA_REWIND, NC_("Stock label, media", "R_ewind"), 0, 0, GETTEXT_PACKAGE "-media" },
366   /* Media label */
367   { GTK_STOCK_MEDIA_STOP, NC_("Stock label, media", "_Stop"), 0, 0, GETTEXT_PACKAGE "-media" },
368   { GTK_STOCK_NETWORK, NC_("Stock label", "_Network"), 0, 0, GETTEXT_PACKAGE },
369   { GTK_STOCK_NEW, NC_("Stock label", "_New"), GDK_CONTROL_MASK, 'n', GETTEXT_PACKAGE },
370   { GTK_STOCK_NO, NC_("Stock label", "_No"), 0, 0, GETTEXT_PACKAGE },
371   { GTK_STOCK_OK, NC_("Stock label", "_OK"), 0, 0, GETTEXT_PACKAGE },
372   { GTK_STOCK_OPEN, NC_("Stock label", "_Open"), GDK_CONTROL_MASK, 'o', GETTEXT_PACKAGE },
373   /* Page orientation */
374   { GTK_STOCK_ORIENTATION_LANDSCAPE, NC_("Stock label", "Landscape"), 0, 0, GETTEXT_PACKAGE },
375   /* Page orientation */
376   { GTK_STOCK_ORIENTATION_PORTRAIT, NC_("Stock label", "Portrait"), 0, 0, GETTEXT_PACKAGE },
377   /* Page orientation */
378   { GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE, NC_("Stock label", "Reverse landscape"), 0, 0, GETTEXT_PACKAGE },
379   /* Page orientation */
380   { GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT, NC_("Stock label", "Reverse portrait"), 0, 0, GETTEXT_PACKAGE },
381   { GTK_STOCK_PAGE_SETUP, NC_("Stock label", "Page Set_up"), 0, 0, GETTEXT_PACKAGE },
382   { GTK_STOCK_PASTE, NC_("Stock label", "_Paste"), GDK_CONTROL_MASK, 'v', GETTEXT_PACKAGE },
383   { GTK_STOCK_PREFERENCES, NC_("Stock label", "_Preferences"), 0, 0, GETTEXT_PACKAGE },
384   { GTK_STOCK_PRINT, NC_("Stock label", "_Print"), 0, 0, GETTEXT_PACKAGE },
385   { GTK_STOCK_PRINT_PREVIEW, NC_("Stock label", "Print Pre_view"), 0, 0, GETTEXT_PACKAGE },
386   { GTK_STOCK_PROPERTIES, NC_("Stock label", "_Properties"), 0, 0, GETTEXT_PACKAGE },
387   { GTK_STOCK_QUIT, NC_("Stock label", "_Quit"), GDK_CONTROL_MASK, 'q', GETTEXT_PACKAGE },
388   { GTK_STOCK_REDO, NC_("Stock label", "_Redo"), 0, 0, GETTEXT_PACKAGE },
389   { GTK_STOCK_REFRESH, NC_("Stock label", "_Refresh"), 0, 0, GETTEXT_PACKAGE },
390   { GTK_STOCK_REMOVE, NC_("Stock label", "_Remove"), 0, 0, GETTEXT_PACKAGE },
391   { GTK_STOCK_REVERT_TO_SAVED, NC_("Stock label", "_Revert"), 0, 0, GETTEXT_PACKAGE },
392   { GTK_STOCK_SAVE, NC_("Stock label", "_Save"), GDK_CONTROL_MASK, 's', GETTEXT_PACKAGE },
393   { GTK_STOCK_SAVE_AS, NC_("Stock label", "Save _As"), 0, 0, GETTEXT_PACKAGE },
394   { GTK_STOCK_SELECT_ALL, NC_("Stock label", "Select _All"), 0, 0, GETTEXT_PACKAGE },
395   { GTK_STOCK_SELECT_COLOR, NC_("Stock label", "_Color"), 0, 0, GETTEXT_PACKAGE },
396   { GTK_STOCK_SELECT_FONT, NC_("Stock label", "_Font"), 0, 0, GETTEXT_PACKAGE },
397   /* Sorting direction */
398   { GTK_STOCK_SORT_ASCENDING, NC_("Stock label", "_Ascending"), 0, 0, GETTEXT_PACKAGE },
399   /* Sorting direction */
400   { GTK_STOCK_SORT_DESCENDING, NC_("Stock label", "_Descending"), 0, 0, GETTEXT_PACKAGE },
401   { GTK_STOCK_SPELL_CHECK, NC_("Stock label", "_Spell Check"), 0, 0, GETTEXT_PACKAGE },
402   { GTK_STOCK_STOP, NC_("Stock label", "_Stop"), 0, 0, GETTEXT_PACKAGE },
403   /* Font variant */
404   { GTK_STOCK_STRIKETHROUGH, NC_("Stock label", "_Strikethrough"), 0, 0, GETTEXT_PACKAGE },
405   { GTK_STOCK_UNDELETE, NC_("Stock label", "_Undelete"), 0, 0, GETTEXT_PACKAGE },
406   /* Font variant */
407   { GTK_STOCK_UNDERLINE, NC_("Stock label", "_Underline"), 0, 0, GETTEXT_PACKAGE },
408   { GTK_STOCK_UNDO, NC_("Stock label", "_Undo"), 0, 0, GETTEXT_PACKAGE },
409   { GTK_STOCK_YES, NC_("Stock label", "_Yes"), 0, 0, GETTEXT_PACKAGE },
410   /* Zoom */
411   { GTK_STOCK_ZOOM_100, NC_("Stock label", "_Normal Size"), 0, 0, GETTEXT_PACKAGE },
412   /* Zoom */
413   { GTK_STOCK_ZOOM_FIT, NC_("Stock label", "Best _Fit"), 0, 0, GETTEXT_PACKAGE },
414   { GTK_STOCK_ZOOM_IN, NC_("Stock label", "Zoom _In"), 0, 0, GETTEXT_PACKAGE },
415   { GTK_STOCK_ZOOM_OUT, NC_("Stock label", "Zoom _Out"), 0, 0, GETTEXT_PACKAGE }
416 };
417
418 /**
419  * gtk_stock_set_translate_func: 
420  * @domain: the translation domain for which @func shall be used
421  * @func: a #GtkTranslateFunc 
422  * @data: data to pass to @func
423  * @notify: a #GDestroyNotify that is called when @data is
424  *   no longer needed
425  *
426  * Sets a function to be used for translating the @label of 
427  * a stock item.
428  * 
429  * If no function is registered for a translation domain,
430  * g_dgettext() is used.
431  * 
432  * The function is used for all stock items whose
433  * @translation_domain matches @domain. Note that it is possible
434  * to use strings different from the actual gettext translation domain
435  * of your application for this, as long as your #GtkTranslateFunc uses
436  * the correct domain when calling dgettext(). This can be useful, e.g.
437  * when dealing with message contexts:
438  *
439  * |[
440  * GtkStockItem items[] = { 
441  *  { MY_ITEM1, NC_("odd items", "Item 1"), 0, 0, "odd-item-domain" },
442  *  { MY_ITEM2, NC_("even items", "Item 2"), 0, 0, "even-item-domain" },
443  * };
444  *
445  * gchar *
446  * my_translate_func (const gchar *msgid,
447  *                    gpointer     data)
448  * {
449  *   gchar *msgctxt = data;
450  * 
451  *   return (gchar*)g_dpgettext2 (GETTEXT_PACKAGE, msgctxt, msgid);
452  * }
453  *
454  * /&ast; ... &ast;/
455  *
456  * gtk_stock_add (items, G_N_ELEMENTS (items));
457  * gtk_stock_set_translate_func ("odd-item-domain", my_translate_func, "odd items"); 
458  * gtk_stock_set_translate_func ("even-item-domain", my_translate_func, "even items"); 
459  * ]|
460  * 
461  * Since: 2.8
462  */
463 void
464 gtk_stock_set_translate_func (const gchar      *domain,
465                               GtkTranslateFunc  func,
466                               gpointer          data,
467                               GDestroyNotify    notify)
468 {
469   GtkStockTranslateFunc *translate;
470   gchar *domainname;
471  
472   domainname = g_strdup (domain);
473
474   translate = (GtkStockTranslateFunc *) 
475     g_hash_table_lookup (translate_hash, domainname);
476
477   if (translate)
478     {
479       if (translate->notify)
480         (* translate->notify) (translate->data);
481     }
482   else
483     translate = g_new0 (GtkStockTranslateFunc, 1);
484     
485   translate->func = func;
486   translate->data = data;
487   translate->notify = notify;
488       
489   g_hash_table_insert (translate_hash, domainname, translate);
490 }
491
492 static gchar *
493 sgettext_swapped (const gchar *msgid, 
494                   gpointer     data)
495 {
496   gchar *msgctxt = data;
497
498   return (gchar *)g_dpgettext2 (GETTEXT_PACKAGE, msgctxt, msgid);
499 }
500
501 static void
502 init_stock_hash (void)
503 {
504   if (stock_hash == NULL)
505     {
506       stock_hash = g_hash_table_new (g_str_hash, g_str_equal);
507
508       gtk_stock_add_static (builtin_items, G_N_ELEMENTS (builtin_items));
509     }
510
511   if (translate_hash == NULL)
512     {
513       translate_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
514                                               g_free, NULL);
515
516       gtk_stock_set_translate_func (GETTEXT_PACKAGE, 
517                                     sgettext_swapped,
518                                     "Stock label",
519                                     NULL);
520       gtk_stock_set_translate_func (GETTEXT_PACKAGE "-navigation", 
521                                     sgettext_swapped,
522                                     "Stock label, navigation",
523                                     NULL);
524       gtk_stock_set_translate_func (GETTEXT_PACKAGE "-media", 
525                                     sgettext_swapped,
526                                     "Stock label, media",
527                                     NULL);
528     }
529 }
530
531 #define __GTK_STOCK_C__
532 #include "gtkaliasdef.c"