#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)
* 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>"<name>"</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
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;
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)
/* 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)
{
(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 (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);
}
}
}
* @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>"<name>"</literal>
* @accel_group: a #GtkAccelGroup to which the accelerators for the
* menu items will be added, or %NULL to create a new one
*
/**
* gtk_item_factory_from_path:
- * @path: a string starting with a factory path of the form <literal>"<name>"</literal>
+ * @path: a string starting with a factory path of the form
+ * <literal>"<name>"</literal>
* @returns: the #GtkItemFactory created for the given factory path, or %NULL
*
- * Finds an item factory which has been constructed using the <literal>"<name>"</literal> prefix of @path as the @path argument for gtk_item_factory_new().
+ * Finds an item factory which has been constructed using the
+ * <literal>"<name>"</literal> prefix of @path as the @path argument
+ * for gtk_item_factory_new().
*/
GtkItemFactory*
gtk_item_factory_from_path (const gchar *path)
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;
}
/**
* @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.
* @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,
* @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.
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
*
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
/**
* 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
* 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;
/**
* 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
/**
* 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
* @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