]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkitemfactory.c
Remove unneeded Win32 stuff inside #ifdef G_OS_WIN32. (Leftover from when
[~andy/gtk] / gtk / gtkitemfactory.c
index ff3b8cdd4fb0d3742575222536ef7e16cadbb616..8f1854748ea5c8d881a67df15e07a0793ba2bbbb 100644 (file)
 #include       "gtk/gtkcheckmenuitem.h"
 #include       "gtk/gtkimagemenuitem.h"
 #include       "gtk/gtktearoffmenuitem.h"
+#include       "gtk/gtkaccelmap.h"
 #include       "gtk/gtkaccellabel.h"
 #include        "gdk/gdkkeysyms.h"
 #include       "gtk/gtkimage.h"
 #include       "gtk/gtkstock.h"
 #include       "gtk/gtkiconfactory.h"
 #include       <string.h>
-#include       <sys/stat.h>
 #include       <fcntl.h>
 #ifdef HAVE_UNISTD_H
 #include       <unistd.h>
 #endif
 #include       <stdio.h>
 
-#ifdef G_OS_WIN32
-#include       <io.h>          /* For _open and _close */
-
-#ifndef S_ISREG
-#define S_ISREG(mode) ((mode)&_S_IFREG)
-#endif
-#endif
-
-
 /* --- defines --- */
 #define                ITEM_FACTORY_STRING     ((gchar*) item_factory_string)
 #define                ITEM_BLOCK_SIZE         (128)
@@ -76,13 +67,6 @@ struct _GtkIFCBData
   gpointer               func_data;
   guint                          callback_action;
 };
-struct _GtkIFDumpData
-{
-  GtkPrintFunc  print_func;
-  gpointer      func_data;
-  guint                 modified_only : 1;
-  GPatternSpec *pspec;
-};
 
 
 /* --- prototypes --- */
@@ -115,47 +99,6 @@ static GQuark                quark_type_tearoff_item = 0;
 static GQuark           quark_type_separator_item = 0;
 static GQuark           quark_type_branch = 0;
 static GQuark           quark_type_last_branch = 0;
-static GScannerConfig  ifactory_scanner_config =
-{
-  (
-   " \t\n"
-   )                   /* cset_skip_characters */,
-  (
-   G_CSET_a_2_z
-   "_"
-   G_CSET_A_2_Z
-   )                   /* cset_identifier_first */,
-  (
-   G_CSET_a_2_z
-   "-+_0123456789"
-   G_CSET_A_2_Z
-   G_CSET_LATINS
-   G_CSET_LATINC
-   )                   /* cset_identifier_nth */,
-  ( ";\n" )            /* cpair_comment_single */,
-  
-  FALSE                        /* case_sensitive */,
-  
-  TRUE                 /* skip_comment_multi */,
-  TRUE                 /* skip_comment_single */,
-  FALSE                        /* scan_comment_multi */,
-  TRUE                 /* scan_identifier */,
-  FALSE                        /* scan_identifier_1char */,
-  FALSE                        /* scan_identifier_NULL */,
-  TRUE                 /* scan_symbols */,
-  TRUE                 /* scan_binary */,
-  TRUE                 /* scan_octal */,
-  TRUE                 /* scan_float */,
-  TRUE                 /* scan_hex */,
-  FALSE                        /* scan_hex_dollar */,
-  TRUE                 /* scan_string_sq */,
-  TRUE                 /* scan_string_dq */,
-  TRUE                 /* numbers_2_int */,
-  FALSE                        /* int_2_float */,
-  FALSE                        /* identifier_2_string */,
-  TRUE                 /* char_2_token */,
-  FALSE                        /* symbol_2_token */,
-};
 
 
 /* --- functions --- */
@@ -188,22 +131,16 @@ static void
 gtk_item_factory_class_init (GtkItemFactoryClass  *class)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
-  GtkObjectClass *object_class;
+  GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
 
   gtk_item_factory_class = class;
-
-  parent_class = gtk_type_class (GTK_TYPE_OBJECT);
-
-  object_class = (GtkObjectClass*) class;
+  parent_class = g_type_class_peek_parent (class);
 
   gobject_class->finalize = gtk_item_factory_finalize;
 
   object_class->destroy = gtk_item_factory_destroy;
 
-  class->cpair_comment_single = g_strdup (";\n");
-
   class->item_ht = g_hash_table_new (g_str_hash, g_str_equal);
-  class->dummy = NULL;
   ifactory_item_chunks =
     g_mem_chunk_new ("GtkItemFactoryItem",
                     sizeof (GtkItemFactoryItem),
@@ -228,8 +165,8 @@ gtk_item_factory_class_init (GtkItemFactoryClass  *class)
   quark_type_toggle_item       = g_quark_from_static_string ("<ToggleItem>");
   quark_type_image_item         = g_quark_from_static_string ("<ImageItem>");
   quark_type_stock_item         = g_quark_from_static_string ("<StockItem>");
-  quark_type_tearoff_item      = g_quark_from_static_string ("<Tearoff>");
   quark_type_separator_item    = g_quark_from_static_string ("<Separator>");
+  quark_type_tearoff_item      = g_quark_from_static_string ("<Tearoff>");
   quark_type_branch            = g_quark_from_static_string ("<Branch>");
   quark_type_last_branch       = g_quark_from_static_string ("<LastBranch>");
 }
@@ -250,6 +187,18 @@ gtk_item_factory_init (GtkItemFactory          *ifactory)
   ifactory->translate_notify = NULL;
 }
 
+/**
+ * gtk_item_factory_new:
+ * @container_type: the kind of menu to create; can be
+ *    #GTK_TYPE_MENU_BAR, #GTK_TYPE_MENU or #GTK_TYPE_OPTION_MENU
+ * @path: the factory path of the new item factory, a string of the form 
+ *    <literal>"&lt;name&gt;"</literal>
+ * @accel_group: a #GtkAccelGroup to which the accelerators for the
+ *    menu items will be added, or %NULL to create a new one
+ * @returns: a new #GtkItemFactory
+ * 
+ * Creates a new #GtkItemFactory.
+ */
 GtkItemFactory*
 gtk_item_factory_new (GtkType       container_type,
                      const gchar   *path,
@@ -285,125 +234,6 @@ gtk_item_factory_callback_marshal (GtkWidget *widget,
     }
 }
 
-static void
-gtk_item_factory_propagate_accelerator (GtkItemFactoryItem *item,
-                                       GtkWidget          *exclude)
-{
-  GSList *widget_list;
-  GSList *slist;
-  
-  if (item->in_propagation)
-    return;
-  
-  item->in_propagation = TRUE;
-  
-  widget_list = NULL;
-  for (slist = item->widgets; slist; slist = slist->next)
-    {
-      GtkWidget *widget;
-      
-      widget = slist->data;
-      
-      if (widget != exclude)
-       {
-         gtk_widget_ref (widget);
-         widget_list = g_slist_prepend (widget_list, widget);
-       }
-    }
-  
-  for (slist = widget_list; slist; slist = slist->next)
-    {
-      GtkWidget *widget;
-      GtkAccelGroup *accel_group;
-      guint signal_id;
-      
-      widget = slist->data;
-      
-      accel_group = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_accel_group);
-      
-      signal_id = gtk_signal_lookup ("activate", GTK_OBJECT_TYPE (widget));
-      if (signal_id && accel_group)
-       {
-         if (item->accelerator_key)
-           gtk_widget_add_accelerator (widget,
-                                       "activate",
-                                       accel_group,
-                                       item->accelerator_key,
-                                       item->accelerator_mods,
-                                       GTK_ACCEL_VISIBLE);
-         else
-           {
-             GSList *work;
-             
-             work = gtk_accel_group_entries_from_object (GTK_OBJECT (widget));
-             while (work)
-               {
-                 GtkAccelEntry *ac_entry;
-                 
-                 ac_entry = work->data;
-                 work = work->next;
-                 if (ac_entry->accel_flags & GTK_ACCEL_VISIBLE &&
-                     ac_entry->accel_group == accel_group &&
-                     ac_entry->signal_id == signal_id)
-                   gtk_widget_remove_accelerator (GTK_WIDGET (widget),
-                                                  ac_entry->accel_group,
-                                                  ac_entry->accelerator_key,
-                                                  ac_entry->accelerator_mods);
-               }
-           }
-       }
-
-      gtk_widget_unref (widget);
-    }
-  
-  g_slist_free (widget_list);
-  
-  item->in_propagation = FALSE;
-}
-
-static gint
-gtk_item_factory_item_add_accelerator (GtkWidget         *widget,
-                                      guint               accel_signal_id,
-                                      GtkAccelGroup      *accel_group,
-                                      guint               accel_key,
-                                      guint               accel_mods,
-                                      GtkAccelFlags       accel_flags,
-                                      GtkItemFactoryItem *item)
-{
-  if (!item->in_propagation &&
-      g_slist_find (item->widgets, widget) &&
-      accel_signal_id == gtk_signal_lookup ("activate", GTK_OBJECT_TYPE (widget)))
-    {
-      item->accelerator_key = accel_key;
-      item->accelerator_mods = accel_mods;
-      item->modified = TRUE;
-      
-      gtk_item_factory_propagate_accelerator (item, widget);
-    }
-
-  return TRUE;
-}
-
-static void
-gtk_item_factory_item_remove_accelerator (GtkWidget         *widget,
-                                         GtkAccelGroup      *accel_group,
-                                         guint               accel_key,
-                                         guint               accel_mods,
-                                         GtkItemFactoryItem *item)
-{
-  if (!item->in_propagation &&
-      g_slist_find (item->widgets, widget) &&
-      item->accelerator_key == accel_key &&
-      item->accelerator_mods == accel_mods)
-    {
-      item->accelerator_key = 0;
-      item->accelerator_mods = 0;
-      item->modified = TRUE;
-      
-      gtk_item_factory_propagate_accelerator (item, widget);
-    }
-}
-
 static void
 gtk_item_factory_item_remove_widget (GtkWidget         *widget,
                                     GtkItemFactoryItem *item)
@@ -413,6 +243,22 @@ gtk_item_factory_item_remove_widget (GtkWidget             *widget,
   gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_item_path);
 }
 
+/**
+ * gtk_item_factory_add_foreign:
+ * @accel_widget:     widget to install an accelerator on 
+ * @full_path:       the full path for the @accel_widget 
+ * @accel_group:      the accelerator group to install the accelerator in
+ * @keyval:           key value of the accelerator
+ * @modifiers:        modifier combination of the accelerator
+ *
+ * Installs an accelerator for @accel_widget in @accel_group, that causes
+ * the ::activate signal to be emitted if the accelerator is activated.
+ * 
+ * This function can be used to make widgets participate in the accel
+ * saving/restoring functionality provided by gtk_accel_map_save() and
+ * gtk_accel_map_load(), even if they haven't been created by an item
+ * factory. 
+ */
 void
 gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
                              const gchar    *full_path,
@@ -436,11 +282,6 @@ gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
       item = g_chunk_new (GtkItemFactoryItem, ifactory_item_chunks);
 
       item->path = g_strdup (full_path);
-      item->accelerator_key = keyval;
-      item->accelerator_mods = modifiers;
-      item->modified = FALSE;
-      item->in_propagation = FALSE;
-      item->dummy = NULL;
       item->widgets = NULL;
       
       g_hash_table_insert (class->item_ht, item->path, item);
@@ -454,7 +295,8 @@ gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
 
   /* set the item path for the widget
    */
-  gtk_object_set_data_by_id (GTK_OBJECT (accel_widget), quark_item_path, item->path);
+  gtk_object_set_data_by_id (GTK_OBJECT (accel_widget), 
+                             quark_item_path, item->path);
   gtk_widget_set_name (accel_widget, item->path);
   if (accel_group)
     {
@@ -465,35 +307,19 @@ gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
                                      (GtkDestroyNotify) gtk_accel_group_unref);
     }
   else
-    gtk_object_set_data_by_id (GTK_OBJECT (accel_widget), quark_accel_group, NULL);
+    gtk_object_set_data_by_id (GTK_OBJECT (accel_widget), 
+                               quark_accel_group, NULL);
 
   /* install defined accelerators
    */
   if (gtk_signal_lookup ("activate", GTK_OBJECT_TYPE (accel_widget)))
     {
-      if (item->accelerator_key && accel_group)
-       gtk_widget_add_accelerator (accel_widget,
-                                   "activate",
-                                   accel_group,
-                                   item->accelerator_key,
-                                   item->accelerator_mods,
-                                   GTK_ACCEL_VISIBLE);
-      else
-       gtk_widget_remove_accelerators (accel_widget,
-                                       "activate",
-                                       TRUE);
+      if (accel_group)
+       {
+         gtk_accel_map_add_entry (full_path, keyval, modifiers);
+         gtk_widget_set_accel_path (accel_widget, full_path, accel_group);
+       }
     }
-
-  /* keep track of accelerator changes
-   */
-  gtk_signal_connect_after (GTK_OBJECT (accel_widget),
-                           "add-accelerator",
-                           GTK_SIGNAL_FUNC (gtk_item_factory_item_add_accelerator),
-                           item);
-  gtk_signal_connect_after (GTK_OBJECT (accel_widget),
-                           "remove-accelerator",
-                           GTK_SIGNAL_FUNC (gtk_item_factory_item_remove_accelerator),
-                           item);
 }
 
 static void
@@ -572,6 +398,18 @@ gtk_item_factory_add_item (GtkItemFactory          *ifactory,
     ifactory->items = g_slist_prepend (ifactory->items, item);
 }
 
+/**
+ * gtk_item_factory_construct:
+ * @ifactory: a #GtkItemFactory
+ * @container_type: the kind of menu to create; can be
+ *    #GTK_TYPE_MENU_BAR, #GTK_TYPE_MENU or #GTK_TYPE_OPTION_MENU
+ * @path: the factory path of @ifactory, a string of the form 
+ *    <literal>"&lt;name&gt;"</literal>
+ * @accel_group: a #GtkAccelGroup to which the accelerators for the
+ *    menu items will be added, or %NULL to create a new one
+ * 
+ * Initializes an item factory.
+ */  
 void
 gtk_item_factory_construct (GtkItemFactory     *ifactory,
                            GtkType              container_type,
@@ -580,7 +418,6 @@ gtk_item_factory_construct (GtkItemFactory  *ifactory,
 {
   guint len;
 
-  g_return_if_fail (ifactory != NULL);
   g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
   g_return_if_fail (ifactory->accel_group == NULL);
   g_return_if_fail (path != NULL);
@@ -617,6 +454,16 @@ gtk_item_factory_construct (GtkItemFactory *ifactory,
                             ifactory->widget);
 }
 
+/**
+ * gtk_item_factory_from_path:
+ * @path: a string starting with a factory path of the form 
+ *   <literal>"&lt;name&gt;"</literal>
+ * @returns: the #GtkItemFactory created for the given factory path, or %NULL 
+ *
+ * Finds an item factory which has been constructed using the 
+ * <literal>"&lt;name&gt;"</literal> prefix of @path as the @path argument 
+ * for gtk_item_factory_new().
+ */
 GtkItemFactory*
 gtk_item_factory_from_path (const gchar      *path)
 {
@@ -659,7 +506,6 @@ gtk_item_factory_destroy (GtkObject *object)
   GtkItemFactory *ifactory;
   GSList *slist;
 
-  g_return_if_fail (object != NULL);
   g_return_if_fail (GTK_IS_ITEM_FACTORY (object));
 
   ifactory = (GtkItemFactory*) object;
@@ -698,7 +544,6 @@ gtk_item_factory_finalize (GObject *object)
 {
   GtkItemFactory *ifactory;
 
-  g_return_if_fail (object != NULL);
   g_return_if_fail (GTK_IS_ITEM_FACTORY (object));
 
   ifactory = GTK_ITEM_FACTORY (object);
@@ -713,154 +558,72 @@ gtk_item_factory_finalize (GObject *object)
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+/**
+ * gtk_item_factory_from_widget:
+ * @widget: a widget
+ * @returns: the item factory from which @widget was created, or %NULL
+ *
+ * Obtains the item factory from which a widget was created.
+ */
 GtkItemFactory*
 gtk_item_factory_from_widget (GtkWidget               *widget)
 {
-  g_return_val_if_fail (widget != NULL, NULL);
-  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
-  return gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_item_factory);
-}
+  GtkItemFactory *ifactory;
 
-gchar*
-gtk_item_factory_path_from_widget (GtkWidget       *widget)
-{
-  g_return_val_if_fail (widget != NULL, NULL);
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
-  return gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_item_path);
-}
-
-static gchar *
-item_factory_escape_path (const gchar *path)
-{
-  GString *str = g_string_new (NULL);
-
-  while (*path)
+  ifactory = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_item_factory);
+  if (ifactory == NULL && GTK_IS_MENU_ITEM (widget) &&
+      GTK_MENU_ITEM (widget)->submenu != NULL) 
     {
-      gchar c = *path;
-
-      switch (c)
-       {
-       case '\n':
-         g_string_append (str, "\\n");
-         break;
-       case '\r':
-         g_string_append (str, "\\r");
-         break;
-       case '"':
-       case '\\':
-         g_string_append_c (str, '\\');
-         /* Fall through */
-       default:
-         g_string_append_c (str, c);
-       }
-      
-      path++;
+      GtkWidget *menu = GTK_MENU_ITEM (widget)->submenu;
+      ifactory = gtk_object_get_data_by_id (GTK_OBJECT (menu), quark_item_factory);
     }
 
-  return g_string_free (str, FALSE);
-}
-
-static void
-gtk_item_factory_foreach (gpointer hash_key,
-                         gpointer value,
-                         gpointer user_data)
-{
-  GtkItemFactoryItem *item;
-  GtkIFDumpData *data;
-  gchar *string;
-  gchar *path;
-  gchar *name;
-  gchar comment_prefix[2] = "\000\000";
-
-  item = value;
-  data = user_data;
-
-  if (data->pspec && !g_pattern_match_string (data->pspec, item->path))
-    return;
-
-  comment_prefix[0] = gtk_item_factory_class->cpair_comment_single[0];
-
-  path = item_factory_escape_path (hash_key);
-  name = gtk_accelerator_name (item->accelerator_key, item->accelerator_mods);
-  string = g_strconcat (item->modified ? "" : comment_prefix,
-                       "(menu-path \"",
-                       path,
-                       "\" \"",
-                       name,
-                       "\")",
-                       NULL);
-  g_free (path);
-  g_free (name);
-
-  data->print_func (data->func_data, string);
-
-  g_free (string);
-}
-
-void
-gtk_item_factory_dump_items (GPatternSpec       *path_pspec,
-                            gboolean             modified_only,
-                            GtkPrintFunc         print_func,
-                            gpointer             func_data)
-{
-  GtkIFDumpData data;
-
-  g_return_if_fail (print_func != NULL);
-
-  if (!gtk_item_factory_class)
-    gtk_type_class (GTK_TYPE_ITEM_FACTORY);
-
-  data.print_func = print_func;
-  data.func_data = func_data;
-  data.modified_only = (modified_only != FALSE);
-  data.pspec = path_pspec;
-
-  g_hash_table_foreach (gtk_item_factory_class->item_ht, gtk_item_factory_foreach, &data);
-}
-
-void
-gtk_item_factory_print_func (gpointer     FILE_pointer,
-                            const gchar *string)
-{
-  FILE *f_out = FILE_pointer;
-
-  g_return_if_fail (FILE_pointer != NULL);
-  g_return_if_fail (string != NULL);
-  
-  fputs (string, f_out);
-  fputc ('\n', f_out);
+  return ifactory;
 }
 
-void
-gtk_item_factory_dump_rc (const gchar  *file_name,
-                         GPatternSpec *path_pspec,
-                         gboolean      modified_only)
+/**
+ * gtk_item_factory_path_from_widget:
+ * @widget: a widget
+ * @returns: the full path to @widget if it been created by an item factory, 
+ *   %NULL otherwise. This value is owned by GTK+ and must not be
+ *   modified or freed.
+ * 
+ * If @widget has been created by an item factory, returns the full path
+ * to it. (The full path of a widget is the concatenation of the factory 
+ * path specified in gtk_item_factory_new() with the path specified in the 
+ * #GtkItemFactoryEntry from which the widget was created.)
+ */
+G_CONST_RETURN gchar*
+gtk_item_factory_path_from_widget (GtkWidget       *widget)
 {
-  FILE *f_out;
+  gchar* path;
 
-  g_return_if_fail (file_name != NULL);
-
-  f_out = fopen (file_name, "w");
-  if (!f_out)
-    return;
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
-  fputs ("; ", f_out);
-  if (g_get_prgname ())
-    fputs (g_get_prgname (), f_out);
-  fputs (" GtkItemFactory rc-file         -*- scheme -*-\n", f_out);
-  fputs ("; this file is an automated menu-path dump\n", f_out);
-  fputs (";\n", f_out);
+  path = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_item_path);
 
-  gtk_item_factory_dump_items (path_pspec,
-                              modified_only,
-                              gtk_item_factory_print_func,
-                              f_out);
+  if (path == NULL && GTK_IS_MENU_ITEM (widget) &&
+      GTK_MENU_ITEM (widget)->submenu != NULL) 
+    {
+      GtkWidget *menu = GTK_MENU_ITEM (widget)->submenu;
+      path = gtk_object_get_data_by_id (GTK_OBJECT (menu), quark_item_path);
+    }
 
-  fclose (f_out);
+  return path;
 }
 
+/**
+ * gtk_item_factory_create_items:
+ * @ifactory: a #GtkItemFactory
+ * @n_entries: the length of @entries
+ * @entries: an array of #GtkItemFactoryEntry<!>s whose @callback members
+ *    must by of type #GtkItemFactoryCallback1
+ * @callback_data: data passed to the callback functions of all entries
+ *
+ * Creates the menu items from the @entries.
+ */
 void
 gtk_item_factory_create_items (GtkItemFactory     *ifactory,
                               guint                n_entries,
@@ -870,6 +633,17 @@ gtk_item_factory_create_items (GtkItemFactory         *ifactory,
   gtk_item_factory_create_items_ac (ifactory, n_entries, entries, callback_data, 1);
 }
 
+/**
+ * gtk_item_factory_create_items_ac:
+ * @ifactory: a #GtkItemFactory
+ * @n_entries: the length of @entries
+ * @entries: an array of #GtkItemFactoryEntry<!>s 
+ * @callback_data: data passed to the callback functions of all entries
+ * @callback_type: 1 if the callback functions in @entries are of type
+ *    #GtkItemFactoryCallback1, 2 if they are of type #GtkItemFactoryCallback2 
+ *
+ * Creates the menu items from the @entries.
+ */
 void
 gtk_item_factory_create_items_ac (GtkItemFactory      *ifactory,
                                  guint                n_entries,
@@ -879,7 +653,6 @@ gtk_item_factory_create_items_ac (GtkItemFactory      *ifactory,
 {
   guint i;
 
-  g_return_if_fail (ifactory != NULL);
   g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
   g_return_if_fail (callback_type >= 1 && callback_type <= 2);
 
@@ -892,6 +665,19 @@ gtk_item_factory_create_items_ac (GtkItemFactory      *ifactory,
     gtk_item_factory_create_item (ifactory, entries + i, callback_data, callback_type);
 }
 
+/**
+ * gtk_item_factory_get_widget:
+ * @ifactory: a #GtkItemFactory
+ * @path: the path to the widget
+ * @returns: the widget for the given path, or %NULL if @path doesn't lead
+ *   to a widget
+ *
+ * Obtains the widget which corresponds to @path. 
+ *
+ * If the widget corresponding to @path is a menu item which opens a 
+ * submenu, then the submenu is returned. If you are interested in the menu 
+ * item, use gtk_item_factory_get_item() instead.
+ */
 GtkWidget*
 gtk_item_factory_get_widget (GtkItemFactory *ifactory,
                             const gchar    *path)
@@ -929,6 +715,20 @@ gtk_item_factory_get_widget (GtkItemFactory *ifactory,
   return NULL;
 }
 
+/**
+ * gtk_item_factory_get_widget_by_action:
+ * @ifactory: a #GtkItemFactory
+ * @action: an action as specified in the @callback_action field
+ *   of #GtkItemFactoryEntry
+ * @returns: the widget which corresponds to the given action, or %NULL
+ *   if no widget was found
+ *
+ * Obtains the widget which was constructed from the #GtkItemFactoryEntry
+ * with the given @action.
+ *
+ * If there are multiple items with the same action, the result is 
+ * undefined.
+ */
 GtkWidget*
 gtk_item_factory_get_widget_by_action (GtkItemFactory *ifactory,
                                       guint           action)
@@ -951,6 +751,19 @@ gtk_item_factory_get_widget_by_action (GtkItemFactory *ifactory,
   return NULL;
 }
 
+/** 
+ * gtk_item_factory_get_item:
+ * @ifactory: a #GtkItemFactory
+ * @path: the path to the menu item
+ * @returns: the menu item for the given path, or %NULL if @path doesn't
+ *   lead to a menu item
+ *
+ * Obtains the menu item which corresponds to @path. 
+ *
+ * If the widget corresponding to @path is a menu item which opens a 
+ * submenu, then the item is returned. If you are interested in the submenu, 
+ * use gtk_item_factory_get_widget() instead.
+ */
 GtkWidget*
 gtk_item_factory_get_item (GtkItemFactory *ifactory,
                           const gchar    *path)
@@ -968,6 +781,18 @@ gtk_item_factory_get_item (GtkItemFactory *ifactory,
   return GTK_IS_ITEM (widget) ? widget : NULL;
 }
 
+
+/**
+ * gtk_item_factory_get_item_by_action:
+ * @ifactory: a #GtkItemFactory
+ * @action: an action as specified in the @callback_action field
+ *   of #GtkItemFactoryEntry
+ * @returns: the menu item which corresponds to the given action, or %NULL
+ *   if no menu item was found
+ *
+ * Obtains the menu item which was constructed from the first 
+ * #GtkItemFactoryEntry with the given @action.
+ */
 GtkWidget*
 gtk_item_factory_get_item_by_action (GtkItemFactory *ifactory,
                                     guint           action)
@@ -1094,6 +919,16 @@ gtk_item_factory_parse_path (GtkItemFactory *ifactory,
   return TRUE;
 }
 
+/**
+ * gtk_item_factory_create_item:
+ * @ifactory: a #GtkItemFactory
+ * @entry: the #GtkItemFactoryEntry to create an item for
+ * @callback_data: data passed to the callback function of @entry
+ * @callback_type: 1 if the callback function of @entry is of type
+ *    #GtkItemFactoryCallback1, 2 if it is of type #GtkItemFactoryCallback2 
+ *
+ * Creates an item for @entry.
+ */
 void
 gtk_item_factory_create_item (GtkItemFactory        *ifactory,
                              GtkItemFactoryEntry    *entry,
@@ -1114,7 +949,6 @@ gtk_item_factory_create_item (GtkItemFactory            *ifactory,
   gchar *item_type_path;
   GtkStockItem stock_item;
       
-  g_return_if_fail (ifactory != NULL);
   g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
   g_return_if_fail (entry != NULL);
   g_return_if_fail (entry->path != NULL);
@@ -1201,25 +1035,32 @@ gtk_item_factory_create_item (GtkItemFactory         *ifactory,
       parent = gtk_item_factory_get_widget (ifactory, parent_path);
       g_return_if_fail (parent != NULL);
     }
-  g_free (parent_path);
 
   if (GTK_IS_OPTION_MENU (parent))
     {
       option_menu = GTK_OPTION_MENU (parent);
       if (!option_menu->menu)
-       gtk_option_menu_set_menu (option_menu, gtk_widget_new (GTK_TYPE_MENU, NULL));
+       {
+         GtkWidget *menu = g_object_new (GTK_TYPE_MENU, NULL);
+         gchar *p = g_strconcat (ifactory->path, parent_path, NULL);
+
+         gtk_menu_set_accel_path (GTK_MENU (menu), p);
+         g_free (p);
+         gtk_option_menu_set_menu (option_menu, menu);
+       }
       parent = option_menu->menu;
     }
+  g_free (parent_path);
                              
   g_return_if_fail (GTK_IS_CONTAINER (parent));
 
   accelerator = entry->accelerator;
   
   widget = gtk_widget_new (type,
-                          "GtkWidget::visible", TRUE,
-                          "GtkWidget::sensitive", (type_id != quark_type_separator_item &&
-                                                   type_id != quark_type_title),
-                          "GtkWidget::parent", parent,
+                          "visible", TRUE,
+                          "sensitive", (type_id != quark_type_separator_item &&
+                                        type_id != quark_type_title),
+                          "parent", parent,
                           NULL);
   if (option_menu && !option_menu->menu_item)
     gtk_option_menu_set_history (option_menu, 0);
@@ -1228,39 +1069,37 @@ gtk_item_factory_create_item (GtkItemFactory         *ifactory,
     gtk_radio_menu_item_set_group (GTK_RADIO_MENU_ITEM (widget), radio_group);
   if (GTK_IS_CHECK_MENU_ITEM (widget))
     gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (widget), TRUE);
-  if (GTK_IS_IMAGE_MENU_ITEM (widget))
+  if (type_id == quark_type_image_item)
     {
       GdkPixbuf *pixbuf = NULL;
-      image = NULL;
 
-      pixbuf = gdk_pixbuf_new_from_inline (entry->extra_data,
+      image = NULL;
+      pixbuf = gdk_pixbuf_new_from_inline (-1,
+                                          entry->extra_data,
                                           FALSE,
-                                          entry->extra_data2,
                                           NULL);
-
       if (pixbuf)
        image = gtk_image_new_from_pixbuf (pixbuf);
-
       if (image)
-       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), image);
-
+       {
+         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), image);
+         gtk_widget_show (image);
+       }
       if (pixbuf)
        g_object_unref (G_OBJECT (pixbuf));
     }
   if (type_id == quark_type_stock_item)
     {
       image = gtk_image_new_from_stock (entry->extra_data, GTK_ICON_SIZE_MENU);
-      if (image)
-       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), image);
-      
+      gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), image);
+      gtk_widget_show (image);
+
       if (gtk_stock_lookup (entry->extra_data, &stock_item))
        {
          if (!accelerator)
            accelerator = gtk_accelerator_name (stock_item.keyval, stock_item.modifier);
        }
     }
-  
-  
 
   /* install underline accelerators for this item
    */
@@ -1271,12 +1110,11 @@ gtk_item_factory_create_item (GtkItemFactory         *ifactory,
       GtkWidget *label;
       
       label = gtk_widget_new (GTK_TYPE_ACCEL_LABEL,
-                             "GtkWidget::visible", TRUE,
-                             "GtkWidget::parent", widget,
-                             "GtkAccelLabel::accel_widget", widget,
-                             "GtkMisc::xalign", 0.0,
+                             "visible", TRUE,
+                             "parent", widget,
+                             "accel_widget", widget,
+                             "xalign", 0.0,
                              NULL);
-      
       gtk_label_set_text_with_mnemonic (GTK_LABEL (label), name);
     }
   
@@ -1285,16 +1123,19 @@ gtk_item_factory_create_item (GtkItemFactory         *ifactory,
   if (type_id == quark_type_branch ||
       type_id == quark_type_last_branch)
     {
+      gchar *p;
+
       if (entry->callback)
        g_warning ("gtk_item_factory_create_item(): Can't specify a callback on a branch: \"%s\"",
                   entry->path);
-      
       if (type_id == quark_type_last_branch)
-       gtk_menu_item_right_justify (GTK_MENU_ITEM (widget));
+       gtk_menu_item_set_right_justified (GTK_MENU_ITEM (widget), TRUE);
       
       parent = widget;
-      widget = gtk_widget_new (GTK_TYPE_MENU,
-                              NULL);
+      widget = gtk_widget_new (GTK_TYPE_MENU, NULL);
+      p = g_strconcat (ifactory->path, path, NULL);
+      gtk_menu_set_accel_path (GTK_MENU (widget), p);
+      g_free (p);
       
       gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), widget);
     }     
@@ -1308,13 +1149,18 @@ gtk_item_factory_create_item (GtkItemFactory         *ifactory,
                             callback_type,
                             item_type_path,
                             widget);
-
   if (accelerator != entry->accelerator)
     g_free (accelerator);
-  
   g_free (path);
 }
 
+/**
+ * gtk_item_factory_create_menu_entries:
+ * @n_entries: the length of @entries
+ * @entries: an array of #GtkMenuEntry<!>s 
+ *
+ * Creates the menu items from the @entries.
+ */
 void
 gtk_item_factory_create_menu_entries (guint              n_entries,
                                      GtkMenuEntry      *entries)
@@ -1391,6 +1237,14 @@ gtk_item_factory_create_menu_entries (guint              n_entries,
     }
 }
 
+/**
+ * gtk_item_factories_path_delete:
+ * @ifactory_path: a factory path to prepend to @path. May be %NULL if @path
+ *   starts with a factory path
+ * @path: a path 
+ * 
+ * Deletes all widgets constructed from the specified path.
+ */
 void
 gtk_item_factories_path_delete (const gchar *ifactory_path,
                                const gchar *path)
@@ -1442,6 +1296,14 @@ gtk_item_factories_path_delete (const gchar *ifactory_path,
     }
 }
 
+/**
+ * gtk_item_factory_delete_item:
+ * @ifactory: a #GtkItemFactory
+ * @path: a path
+ *
+ * Deletes the menu item which was created for @path by the given
+ * item factory.
+ */
 void
 gtk_item_factory_delete_item (GtkItemFactory         *ifactory,
                              const gchar            *path)
@@ -1449,7 +1311,6 @@ gtk_item_factory_delete_item (GtkItemFactory         *ifactory,
   GtkItemFactoryClass *class;
   GtkWidget *widget;
 
-  g_return_if_fail (ifactory != NULL);
   g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
   g_return_if_fail (path != NULL);
 
@@ -1466,17 +1327,47 @@ gtk_item_factory_delete_item (GtkItemFactory         *ifactory,
     }
 }
 
+/**
+ * gtk_item_factory_delete_entry:
+ * @ifactory: a #GtkItemFactory
+ * @entry: a #GtkItemFactoryEntry
+ *
+ * Deletes the menu item which was created from @entry by the given
+ * item factory.
+ */
 void
 gtk_item_factory_delete_entry (GtkItemFactory         *ifactory,
                               GtkItemFactoryEntry    *entry)
 {
-  g_return_if_fail (ifactory != NULL);
+  gchar *path;
+  gchar *parent_path;
+  gchar *name;
+
   g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
   g_return_if_fail (entry != NULL);
+  g_return_if_fail (entry->path != NULL);
+  g_return_if_fail (entry->path[0] == '/');
 
-  gtk_item_factory_delete_item (ifactory, entry->path);
+  if (!gtk_item_factory_parse_path (ifactory, entry->path, 
+                                   &path, &parent_path, &name))
+    return;
+  
+  gtk_item_factory_delete_item (ifactory, path);
+
+  g_free (path);
+  g_free (parent_path);
+  g_free (name);
 }
 
+/**
+ * gtk_item_factory_delete_entries:
+ * @ifactory: a #GtkItemFactory
+ * @n_entries: the length of @entries
+ * @entries: an array of #GtkItemFactoryEntry<!>s 
+ *
+ * Deletes the menu items which were created from the @entries by the given
+ * item factory.
+ */
 void
 gtk_item_factory_delete_entries (GtkItemFactory         *ifactory,
                                 guint                   n_entries,
@@ -1484,13 +1375,12 @@ gtk_item_factory_delete_entries (GtkItemFactory         *ifactory,
 {
   guint i;
 
-  g_return_if_fail (ifactory != NULL);
   g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
   if (n_entries > 0)
     g_return_if_fail (entries != NULL);
 
   for (i = 0; i < n_entries; i++)
-    gtk_item_factory_delete_item (ifactory, (entries + i)->path);
+    gtk_item_factory_delete_entry (ifactory, entries + i);
 }
 
 typedef struct
@@ -1512,12 +1402,22 @@ gtk_item_factory_menu_pos (GtkMenu  *menu,
   *y = mpos->y;
 }
 
+/**
+ * gtk_item_factory_popup_data_from_widget:
+ * @widget: a widget
+ * @returns: @popup_data associated with the item factory from
+ *   which @widget was created, or %NULL if @widget wasn't created
+ *   by an item factory
+ *
+ * Obtains the @popup_data which was passed to 
+ * gtk_item_factory_popup_with_data(). This data is available until the menu
+ * is popped down again.
+ */
 gpointer
-gtk_item_factory_popup_data_from_widget (GtkWidget     *widget)
+gtk_item_factory_popup_data_from_widget (GtkWidget *widget)
 {
   GtkItemFactory *ifactory;
   
-  g_return_val_if_fail (widget != NULL, NULL);
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
   ifactory = gtk_item_factory_from_widget (widget);
@@ -1527,10 +1427,18 @@ gtk_item_factory_popup_data_from_widget (GtkWidget     *widget)
   return NULL;
 }
 
+/**
+ * gtk_item_factory_popup_data:
+ * @ifactory: a #GtkItemFactory
+ * @returns: @popup_data associated with @ifactory
+ *
+ * Obtains the @popup_data which was passed to 
+ * gtk_item_factory_popup_with_data(). This data is available until the menu
+ * is popped down again.
+ */
 gpointer
 gtk_item_factory_popup_data (GtkItemFactory *ifactory)
 {
-  g_return_val_if_fail (ifactory != NULL, NULL);
   g_return_val_if_fail (GTK_IS_ITEM_FACTORY (ifactory), NULL);
 
   return gtk_object_get_data_by_id (GTK_OBJECT (ifactory), quark_popup_data);
@@ -1546,6 +1454,16 @@ ifactory_delete_popup_data (GtkObject       *object,
   gtk_object_remove_data_by_id (GTK_OBJECT (ifactory), quark_popup_data);
 }
 
+/**
+ * gtk_item_factory_popup:
+ * @ifactory: a #GtkItemFactory of type #GTK_TYPE_MENU (see gtk_item_factory_new())
+ * @x: the x position 
+ * @y: the y position
+ * @mouse_button: the mouse button which was pressed to initiate this action
+ * @time: a timestamp for this action
+ *
+ * Pops up the menu constructed from the item factory at (@x, @y).
+ */
 void
 gtk_item_factory_popup (GtkItemFactory         *ifactory,
                        guint                    x,
@@ -1556,6 +1474,21 @@ gtk_item_factory_popup (GtkItemFactory           *ifactory,
   gtk_item_factory_popup_with_data (ifactory, NULL, NULL, x, y, mouse_button, time);
 }
 
+/**
+ * gtk_item_factory_popup_with_data:
+ * @ifactory: a #GtkItemFactory of type #GTK_TYPE_MENU (see gtk_item_factory_new())
+ * @popup_data: data available for callbacks while the menu is posted
+ * @destroy: a #GtkDestroyNotify function to be called on @popup_data when
+ *  the menu is unposted
+ * @x: the x position 
+ * @y: the y position
+ * @mouse_button: the mouse button which was pressed to initiate this action
+ * @time: a timestamp for this action
+ *
+ * Pops up the menu constructed from the item factory at (@x, @y). Callbacks
+ * can access the @popup_data while the menu is posted via 
+ * gtk_item_factory_popup_data() and gtk_item_factory_popup_data_from_widget().
+ */
 void
 gtk_item_factory_popup_with_data (GtkItemFactory       *ifactory,
                                  gpointer               popup_data,
@@ -1567,7 +1500,6 @@ gtk_item_factory_popup_with_data (GtkItemFactory  *ifactory,
 {
   MenuPos *mpos;
 
-  g_return_if_fail (ifactory != NULL);
   g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
   g_return_if_fail (GTK_IS_MENU (ifactory->widget));
   
@@ -1603,192 +1535,17 @@ gtk_item_factory_popup_with_data (GtkItemFactory       *ifactory,
                  mouse_button, time);
 }
 
-static guint
-gtk_item_factory_parse_menu_path (GScanner            *scanner,
-                                 GtkItemFactoryClass *class)
-{
-  GtkItemFactoryItem *item;
-  
-  g_scanner_get_next_token (scanner);
-  if (scanner->token != G_TOKEN_STRING)
-    return G_TOKEN_STRING;
-
-  g_scanner_peek_next_token (scanner);
-  if (scanner->next_token != G_TOKEN_STRING)
-    {
-      g_scanner_get_next_token (scanner);
-      return G_TOKEN_STRING;
-    }
-
-  item = g_hash_table_lookup (class->item_ht, scanner->value.v_string);
-  if (!item)
-    {
-      item = g_chunk_new (GtkItemFactoryItem, ifactory_item_chunks);
-
-      item->path = g_strdup (scanner->value.v_string);
-      item->accelerator_key = 0;
-      item->accelerator_mods = 0;
-      item->modified = TRUE;
-      item->in_propagation = FALSE;
-      item->dummy = NULL;
-      item->widgets = NULL;
-
-      g_hash_table_insert (class->item_ht, item->path, item);
-    }
-  g_scanner_get_next_token (scanner);
-  
-  if (!item->in_propagation)
-    {
-      guint old_keyval;
-      guint old_mods;
-      
-      old_keyval = item->accelerator_key;
-      old_mods = item->accelerator_mods;
-      gtk_accelerator_parse (scanner->value.v_string,
-                            &item->accelerator_key,
-                            &item->accelerator_mods);
-      if (old_keyval != item->accelerator_key ||
-         old_mods != item->accelerator_mods)
-       {
-         item->modified = TRUE;
-         gtk_item_factory_propagate_accelerator (item, NULL);
-       }
-    }
-  
-  g_scanner_get_next_token (scanner);
-  if (scanner->token != ')')
-    return ')';
-  else
-    return G_TOKEN_NONE;
-}
-
-static void
-gtk_item_factory_parse_statement (GScanner            *scanner,
-                                 GtkItemFactoryClass *class)
-{
-  guint expected_token;
-  
-  g_scanner_get_next_token (scanner);
-  
-  if (scanner->token == G_TOKEN_SYMBOL)
-    {
-      guint (*parser_func) (GScanner*, GtkItemFactoryClass*);
-
-      parser_func = scanner->value.v_symbol;
-
-      /* check whether this is a GtkItemFactory symbol.
-       */
-      if (parser_func == gtk_item_factory_parse_menu_path)
-       expected_token = parser_func (scanner, class);
-      else
-       expected_token = G_TOKEN_SYMBOL;
-    }
-  else
-    expected_token = G_TOKEN_SYMBOL;
-
-  /* skip rest of statement on errrors
-   */
-  if (expected_token != G_TOKEN_NONE)
-    {
-      register guint level;
-
-      level = 1;
-      if (scanner->token == ')')
-       level--;
-      if (scanner->token == '(')
-       level++;
-      
-      while (!g_scanner_eof (scanner) && level > 0)
-       {
-         g_scanner_get_next_token (scanner);
-         
-         if (scanner->token == '(')
-           level++;
-         else if (scanner->token == ')')
-           level--;
-       }
-    }
-}
-
-void
-gtk_item_factory_parse_rc_string (const gchar   *rc_string)
-{
-  GScanner *scanner;
-
-  g_return_if_fail (rc_string != NULL);
-
-  if (!gtk_item_factory_class)
-    gtk_type_class (GTK_TYPE_ITEM_FACTORY);
-
-  ifactory_scanner_config.cpair_comment_single = gtk_item_factory_class->cpair_comment_single;
-  scanner = g_scanner_new (&ifactory_scanner_config);
-
-  g_scanner_input_text (scanner, rc_string, strlen (rc_string));
-
-  gtk_item_factory_parse_rc_scanner (scanner);
-
-  g_scanner_destroy (scanner);
-}
-
-void
-gtk_item_factory_parse_rc_scanner (GScanner *scanner)
-{
-  gpointer saved_symbol;
-
-  g_return_if_fail (scanner != NULL);
-
-  if (!gtk_item_factory_class)
-    gtk_type_class (GTK_TYPE_ITEM_FACTORY);
-
-  saved_symbol = g_scanner_lookup_symbol (scanner, "menu-path");
-  g_scanner_remove_symbol (scanner, "menu-path");
-  g_scanner_add_symbol (scanner, "menu-path", gtk_item_factory_parse_menu_path);
-
-  g_scanner_peek_next_token (scanner);
-
-  while (scanner->next_token == '(')
-    {
-      g_scanner_get_next_token (scanner);
-
-      gtk_item_factory_parse_statement (scanner, gtk_item_factory_class);
-
-      g_scanner_peek_next_token (scanner);
-    }
-
-  g_scanner_remove_symbol (scanner, "menu-path");
-  g_scanner_add_symbol (scanner, "menu-path", saved_symbol);
-}
-
-void
-gtk_item_factory_parse_rc (const gchar   *file_name)
-{
-  gint fd;
-  GScanner *scanner;
-
-  g_return_if_fail (file_name != NULL);
-
-  if (!S_ISREG (g_scanner_stat_mode (file_name)))
-    return;
-
-  fd = open (file_name, O_RDONLY);
-  if (fd < 0)
-    return;
-
-  if (!gtk_item_factory_class)
-    gtk_type_class (GTK_TYPE_ITEM_FACTORY);
-
-  ifactory_scanner_config.cpair_comment_single = gtk_item_factory_class->cpair_comment_single;
-  scanner = g_scanner_new (&ifactory_scanner_config);
-
-  g_scanner_input_file (scanner, fd);
-
-  gtk_item_factory_parse_rc_scanner (scanner);
-
-  g_scanner_destroy (scanner);
-
-  close (fd);
-}
-
+/**
+ * gtk_item_factory_set_translate_func:
+ * @ifactory: a #GtkItemFactory
+ * @func: the #GtkTranslateFunc function to be used to translate path elements 
+ * @data: data to pass to @func and @notify
+ * @notify: a #GtkDestroyNotify function to be called when @ifactory is 
+ *   destroyed and when the translation function is changed again
+ * 
+ * Sets a function to be used for translating the path elements before they
+ * are displayed. 
+ */ 
 void
 gtk_item_factory_set_translate_func (GtkItemFactory      *ifactory,
                                     GtkTranslateFunc     func,