]> 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 bb4790bf28ddbf6091706cc186a37de51fe38037..8f1854748ea5c8d881a67df15e07a0793ba2bbbb 100644 (file)
 #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)
@@ -200,7 +191,8 @@ gtk_item_factory_init (GtkItemFactory           *ifactory)
  * 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 path of the menu, a string of the form "<name>"
+ * @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
@@ -251,12 +243,28 @@ 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,
                              GtkAccelGroup  *accel_group,
-                             guint           accel_key,
-                             GdkModifierType accel_mods)
+                             guint           keyval,
+                             GdkModifierType modifiers)
 {
   GtkItemFactoryClass *class;
   GtkItemFactoryItem *item;
@@ -266,7 +274,7 @@ gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
 
   class = gtk_type_class (GTK_TYPE_ITEM_FACTORY);
 
-  accel_key = accel_key != GDK_VoidSymbol ? accel_key : 0;
+  keyval = keyval != GDK_VoidSymbol ? keyval : 0;
 
   item = g_hash_table_lookup (class->item_ht, full_path);
   if (!item)
@@ -287,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)
     {
@@ -298,7 +307,8 @@ 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
    */
@@ -306,8 +316,8 @@ gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
     {
       if (accel_group)
        {
-         gtk_accel_map_add_entry (full_path, accel_key, accel_mods);
-         _gtk_widget_set_accel_path (accel_widget, full_path, accel_group);
+         gtk_accel_map_add_entry (full_path, keyval, modifiers);
+         gtk_widget_set_accel_path (accel_widget, full_path, accel_group);
        }
     }
 }
@@ -393,7 +403,8 @@ gtk_item_factory_add_item (GtkItemFactory           *ifactory,
  * @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 path of the menu, a string of the form "<name>"
+ * @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
  * 
@@ -445,10 +456,13 @@ gtk_item_factory_construct (GtkItemFactory        *ifactory,
 
 /**
  * gtk_item_factory_from_path:
- * @path: a string starting with a factory path of the form <literal>"&lt;name&gt;"</literal>
+ * @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().
+ * 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)
@@ -554,28 +568,50 @@ gtk_item_factory_finalize (GObject *object)
 GtkItemFactory*
 gtk_item_factory_from_widget (GtkWidget               *widget)
 {
+  GtkItemFactory *ifactory;
+
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
-  return gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_item_factory);
+  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) 
+    {
+      GtkWidget *menu = GTK_MENU_ITEM (widget)->submenu;
+      ifactory = gtk_object_get_data_by_id (GTK_OBJECT (menu), quark_item_factory);
+    }
+
+  return ifactory;
 }
 
 /**
  * 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 
+ *   %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.)
  */
-gchar*
+G_CONST_RETURN gchar*
 gtk_item_factory_path_from_widget (GtkWidget       *widget)
 {
+  gchar* path;
+
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
-  return gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_item_path);
+  path = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_item_path);
+
+  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);
+    }
+
+  return path;
 }
 
 /**
@@ -603,7 +639,7 @@ gtk_item_factory_create_items (GtkItemFactory          *ifactory,
  * @n_entries: the length of @entries
  * @entries: an array of #GtkItemFactoryEntry<!>s 
  * @callback_data: data passed to the callback functions of all entries
- * @callback_data: 1 if the callback functions in @entries are of type
+ * @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.
@@ -687,8 +723,11 @@ gtk_item_factory_get_widget (GtkItemFactory *ifactory,
  * @returns: the widget which corresponds to the given action, or %NULL
  *   if no widget was found
  *
- * Obtains the widget which was constructed from the first #GtkItemFactoryEntry
+ * 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,
@@ -885,7 +924,7 @@ gtk_item_factory_parse_path (GtkItemFactory *ifactory,
  * @ifactory: a #GtkItemFactory
  * @entry: the #GtkItemFactoryEntry to create an item for
  * @callback_data: data passed to the callback function of @entry
- * @callback_data: 1 if the callback function of @entry is of type
+ * @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.
@@ -1300,14 +1339,29 @@ void
 gtk_item_factory_delete_entry (GtkItemFactory         *ifactory,
                               GtkItemFactoryEntry    *entry)
 {
+  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 
  *
@@ -1326,7 +1380,7 @@ gtk_item_factory_delete_entries (GtkItemFactory         *ifactory,
     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
@@ -1350,7 +1404,7 @@ gtk_item_factory_menu_pos (GtkMenu  *menu,
 
 /**
  * gtk_item_factory_popup_data_from_widget:
- * @widget a 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
@@ -1360,7 +1414,7 @@ gtk_item_factory_menu_pos (GtkMenu  *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;
   
@@ -1402,7 +1456,7 @@ ifactory_delete_popup_data (GtkObject        *object,
 
 /**
  * gtk_item_factory_popup:
- * @ifactory: a #GtkItemFactory
+ * @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
@@ -1422,7 +1476,7 @@ gtk_item_factory_popup (GtkItemFactory            *ifactory,
 
 /**
  * gtk_item_factory_popup_with_data:
- * @ifactory: a #GtkItemFactory
+ * @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
@@ -1486,10 +1540,10 @@ gtk_item_factory_popup_with_data (GtkItemFactory        *ifactory,
  * @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 @ifactory is destroyed 
- *   and when the translation function is changed again
+ * @notify: a #GtkDestroyNotify function to be called when @ifactory is 
+ *   destroyed and when the translation function is changed again
  * 
- * Sets a function to be use for translating the path elements before they
+ * Sets a function to be used for translating the path elements before they
  * are displayed. 
  */ 
 void