]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkitemfactory.c
Updated Bulgarian translation by Alexander Shopov <ash@contact.bg>
[~andy/gtk] / gtk / gtkitemfactory.c
index 0992e3e7d31591650b9d59f8f6c946ea894396e1..98145a9c7f6c2c60d3f6df92edd6ec923094ae35 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include       "config.h"
+#include       <config.h>
 
+#undef GTK_DISABLE_DEPRECATED
 #include       "gtkitemfactory.h"
-#include       "gtk/gtkoptionmenu.h"
-#include       "gtk/gtkmenubar.h"
-#include       "gtk/gtkmenu.h"
-#include       "gtk/gtkmenuitem.h"
-#include       "gtk/gtkradiomenuitem.h"
-#include       "gtk/gtkcheckmenuitem.h"
-#include       "gtk/gtkimagemenuitem.h"
-#include       "gtk/gtktearoffmenuitem.h"
-#include       "gtk/gtkaccelmap.h"
-#include       "gtk/gtkaccellabel.h"
+#include       "gtkoptionmenu.h"
+#define GTK_DISABLE_DEPRECATED
+#include       "gtkmenubar.h"
+#include       "gtkmenu.h"
+#include       "gtkmenuitem.h"
+#include       "gtkradiomenuitem.h"
+#include       "gtkcheckmenuitem.h"
+#include       "gtkimagemenuitem.h"
+#include       "gtktearoffmenuitem.h"
+#include       "gtkaccelmap.h"
+#include       "gtkaccellabel.h"
 #include        "gdk/gdkkeysyms.h"
-#include       "gtk/gtkimage.h"
-#include       "gtk/gtkstock.h"
-#include       "gtk/gtkiconfactory.h"
+#include       "gtkimage.h"
+#include       "gtkstock.h"
+#include       "gtkiconfactory.h"
+#include       "gtkintl.h"
 #include       <string.h>
 #include       <fcntl.h>
 #ifdef HAVE_UNISTD_H
@@ -51,6 +54,8 @@
 #endif
 #include       <stdio.h>
 
+#include       "gtkalias.h"
+
 /* --- defines --- */
 #define                ITEM_FACTORY_STRING     ((gchar*) item_factory_string)
 #define                ITEM_BLOCK_SIZE         (128)
@@ -69,18 +74,12 @@ struct _GtkIFCBData
 
 
 /* --- prototypes --- */
-static void    gtk_item_factory_class_init             (GtkItemFactoryClass  *klass);
-static void    gtk_item_factory_init                   (GtkItemFactory       *ifactory);
 static void    gtk_item_factory_destroy                (GtkObject            *object);
 static void    gtk_item_factory_finalize               (GObject              *object);
 
 
 /* --- static variables --- */
-static GtkItemFactoryClass *gtk_item_factory_class = NULL;
-static gpointer          parent_class = NULL;
-static const gchar     *item_factory_string = "Gtk-<ItemFactory>";
-static GMemChunk       *ifactory_item_chunks = NULL;
-static GMemChunk       *ifactory_cb_data_chunks = NULL;
+static const gchar      item_factory_string[] = "Gtk-<ItemFactory>";
 static GQuark           quark_popup_data = 0;
 static GQuark           quark_if_menu_pos = 0;
 static GQuark           quark_item_factory = 0;
@@ -99,60 +98,20 @@ static GQuark                quark_type_separator_item = 0;
 static GQuark           quark_type_branch = 0;
 static GQuark           quark_type_last_branch = 0;
 
+G_DEFINE_TYPE (GtkItemFactory, gtk_item_factory, GTK_TYPE_OBJECT)
 
 /* --- functions --- */
-GType
-gtk_item_factory_get_type (void)
-{
-  static GType item_factory_type = 0;
-  
-  if (!item_factory_type)
-    {
-      static const GTypeInfo item_factory_info =
-      {
-       sizeof (GtkItemFactoryClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_item_factory_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkItemFactory),
-       0,
-       (GInstanceInitFunc) gtk_item_factory_init,
-      };
-      
-      item_factory_type =
-       g_type_register_static (GTK_TYPE_OBJECT, "GtkItemFactory",
-                               &item_factory_info, 0);
-    }
-  
-  return item_factory_type;
-}
-
 static void
 gtk_item_factory_class_init (GtkItemFactoryClass  *class)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
   GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
 
-  gtk_item_factory_class = class;
-  parent_class = g_type_class_peek_parent (class);
-
   gobject_class->finalize = gtk_item_factory_finalize;
 
   object_class->destroy = gtk_item_factory_destroy;
 
   class->item_ht = g_hash_table_new (g_str_hash, g_str_equal);
-  ifactory_item_chunks =
-    g_mem_chunk_new ("GtkItemFactoryItem",
-                    sizeof (GtkItemFactoryItem),
-                    sizeof (GtkItemFactoryItem) * ITEM_BLOCK_SIZE,
-                    G_ALLOC_ONLY);
-  ifactory_cb_data_chunks =
-    g_mem_chunk_new ("GtkIFCBData",
-                    sizeof (GtkIFCBData),
-                    sizeof (GtkIFCBData) * ITEM_BLOCK_SIZE,
-                    G_ALLOC_AND_FREE);
 
   quark_popup_data             = g_quark_from_static_string ("GtkItemFactory-popup-data");
   quark_if_menu_pos            = g_quark_from_static_string ("GtkItemFactory-menu-position");
@@ -176,10 +135,6 @@ gtk_item_factory_class_init (GtkItemFactoryClass  *class)
 static void
 gtk_item_factory_init (GtkItemFactory      *ifactory)
 {
-  GtkObject *object;
-
-  object = GTK_OBJECT (ifactory);
-
   ifactory->path = NULL;
   ifactory->accel_group = NULL;
   ifactory->widget = NULL;
@@ -200,6 +155,10 @@ gtk_item_factory_init (GtkItemFactory          *ifactory)
  * @returns: a new #GtkItemFactory
  * 
  * Creates a new #GtkItemFactory.
+ *
+ * Beware that the returned object does not have a floating reference.
+ *
+ * Deprecated: 2.4:    
  */
 GtkItemFactory*
 gtk_item_factory_new (GType         container_type,
@@ -259,7 +218,9 @@ gtk_item_factory_item_remove_widget (GtkWidget              *widget,
  * 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. The recommended API for this purpose are the functions 
+ * factory. 
+ *
+ * Deprecated: 2.4: The recommended API for this purpose are the functions 
  * gtk_menu_item_set_accel_path() and gtk_widget_set_accel_path(); don't 
  * use gtk_item_factory_add_foreign() in new code, since it is likely to
  * be removed in the future.
@@ -284,7 +245,7 @@ gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
   item = g_hash_table_lookup (class->item_ht, full_path);
   if (!item)
     {
-      item = g_chunk_new (GtkItemFactoryItem, ifactory_item_chunks);
+      item = g_slice_new (GtkItemFactoryItem);
 
       item->path = g_strdup (full_path);
       item->widgets = NULL;
@@ -328,7 +289,7 @@ gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
 static void
 ifactory_cb_data_free (gpointer mem)
 {
-  g_mem_chunk_free (ifactory_cb_data_chunks, mem);
+  g_slice_free (GtkIFCBData, mem);
 }
 
 static void
@@ -358,13 +319,13 @@ gtk_item_factory_add_item (GtkItemFactory         *ifactory,
   if (GTK_IS_MENU (widget))
     gtk_menu_set_accel_group ((GtkMenu*) widget, ifactory->accel_group);
 
-  /* connect callback if neccessary
+  /* connect callback if necessary
    */
   if (callback)
     {
       GtkIFCBData *data;
 
-      data = g_chunk_new (GtkIFCBData, ifactory_cb_data_chunks);
+      data = g_slice_new (GtkIFCBData);
       data->func = callback;
       data->callback_type = callback_type;
       data->func_data = callback_data;
@@ -413,6 +374,8 @@ gtk_item_factory_add_item (GtkItemFactory           *ifactory,
  *    menu items will be added, or %NULL to create a new one
  * 
  * Initializes an item factory.
+ *
+ * Deprecated: 2.4:
  */  
 void
 gtk_item_factory_construct (GtkItemFactory     *ifactory,
@@ -448,8 +411,7 @@ gtk_item_factory_construct (GtkItemFactory  *ifactory,
   ifactory->widget = g_object_connect (gtk_widget_new (container_type, NULL),
                                       "signal::destroy", gtk_widget_destroyed, &ifactory->widget,
                                       NULL);
-  g_object_ref (ifactory);
-  gtk_object_sink (GTK_OBJECT (ifactory));
+  g_object_ref_sink (ifactory);
 
   gtk_item_factory_add_item (ifactory,
                             "", NULL,
@@ -467,6 +429,8 @@ gtk_item_factory_construct (GtkItemFactory  *ifactory,
  * 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().
+ *
+ * Deprecated: 2.4:
  */
 GtkItemFactory*
 gtk_item_factory_from_path (const gchar      *path)
@@ -520,8 +484,7 @@ gtk_item_factory_destroy (GtkObject *object)
 
       dobj = GTK_OBJECT (ifactory->widget);
 
-      g_object_ref (dobj);
-      gtk_object_sink (dobj);
+      g_object_ref_sink (dobj);
       gtk_object_destroy (dobj);
       g_object_unref (dobj);
 
@@ -540,7 +503,7 @@ gtk_item_factory_destroy (GtkObject *object)
   g_slist_free (ifactory->items);
   ifactory->items = NULL;
 
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);
+  GTK_OBJECT_CLASS (gtk_item_factory_parent_class)->destroy (object);
 }
 
 static void
@@ -559,7 +522,7 @@ gtk_item_factory_finalize (GObject *object)
   if (ifactory->translate_notify)
     ifactory->translate_notify (ifactory->translate_data);
   
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_item_factory_parent_class)->finalize (object);
 }
 
 /**
@@ -568,6 +531,8 @@ gtk_item_factory_finalize (GObject *object)
  * @returns: the item factory from which @widget was created, or %NULL
  *
  * Obtains the item factory from which a widget was created.
+ *
+ * Deprecated: 2.4
  */
 GtkItemFactory*
 gtk_item_factory_from_widget (GtkWidget               *widget)
@@ -599,6 +564,8 @@ gtk_item_factory_from_widget (GtkWidget            *widget)
  * 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.)
+ *
+ * Deprecated: 2.4:
  */
 G_CONST_RETURN gchar*
 gtk_item_factory_path_from_widget (GtkWidget       *widget)
@@ -628,6 +595,8 @@ gtk_item_factory_path_from_widget (GtkWidget            *widget)
  * @callback_data: data passed to the callback functions of all entries
  *
  * Creates the menu items from the @entries.
+ *
+ * Deprecated: 2.4:
  */
 void
 gtk_item_factory_create_items (GtkItemFactory     *ifactory,
@@ -648,6 +617,8 @@ gtk_item_factory_create_items (GtkItemFactory          *ifactory,
  *    #GtkItemFactoryCallback1, 2 if they are of type #GtkItemFactoryCallback2 
  *
  * Creates the menu items from the @entries.
+ *
+ * Deprecated: 2.4:
  */
 void
 gtk_item_factory_create_items_ac (GtkItemFactory      *ifactory,
@@ -682,6 +653,8 @@ gtk_item_factory_create_items_ac (GtkItemFactory      *ifactory,
  * 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.
+ *
+ * Deprecated: 2.4:
  */
 GtkWidget*
 gtk_item_factory_get_widget (GtkItemFactory *ifactory,
@@ -733,6 +706,8 @@ gtk_item_factory_get_widget (GtkItemFactory *ifactory,
  *
  * If there are multiple items with the same action, the result is 
  * undefined.
+ *
+ * Deprecated: 2.4:
  */
 GtkWidget*
 gtk_item_factory_get_widget_by_action (GtkItemFactory *ifactory,
@@ -768,6 +743,8 @@ gtk_item_factory_get_widget_by_action (GtkItemFactory *ifactory,
  * 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.
+ *
+ * Deprecated: 2.4:
  */
 GtkWidget*
 gtk_item_factory_get_item (GtkItemFactory *ifactory,
@@ -797,6 +774,8 @@ gtk_item_factory_get_item (GtkItemFactory *ifactory,
  *
  * Obtains the menu item which was constructed from the first 
  * #GtkItemFactoryEntry with the given @action.
+ *
+ * Deprecated: 2.4:
  */
 GtkWidget*
 gtk_item_factory_get_item_by_action (GtkItemFactory *ifactory,
@@ -933,6 +912,8 @@ gtk_item_factory_parse_path (GtkItemFactory *ifactory,
  *    #GtkItemFactoryCallback1, 2 if it is of type #GtkItemFactoryCallback2 
  *
  * Creates an item for @entry.
+ *
+ * Deprecated: 2.4:
  */
 void
 gtk_item_factory_create_item (GtkItemFactory        *ifactory,
@@ -1072,26 +1053,19 @@ gtk_item_factory_create_item (GtkItemFactory         *ifactory,
 
   if (GTK_IS_RADIO_MENU_ITEM (widget))
     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 (type_id == quark_type_image_item)
     {
-      GError *error = NULL;
       GdkPixbuf *pixbuf = NULL;
-
       image = NULL;
-      pixbuf = gdk_pixbuf_new_from_inline (-1,
-                                          entry->extra_data,
-                                          FALSE,
-                                          &error);
-      if (pixbuf)
-       image = gtk_image_new_from_pixbuf (pixbuf);
-      else
+      if (entry->extra_data)
        {
-         g_warning ("Error loading menu image: %s", error->message);
-         g_error_free (error);
+         pixbuf = gdk_pixbuf_new_from_inline (-1,
+                                              entry->extra_data,
+                                              FALSE,
+                                              NULL);
+         if (pixbuf)
+           image = gtk_image_new_from_pixbuf (pixbuf);
        }
-           
       if (image)
        {
          gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), image);
@@ -1124,7 +1098,7 @@ gtk_item_factory_create_item (GtkItemFactory           *ifactory,
       label = gtk_widget_new (GTK_TYPE_ACCEL_LABEL,
                              "visible", TRUE,
                              "parent", widget,
-                             "accel_widget", widget,
+                             "accel-widget", widget,
                              "xalign", 0.0,
                              NULL);
       gtk_label_set_text_with_mnemonic (GTK_LABEL (label), name);
@@ -1172,6 +1146,8 @@ gtk_item_factory_create_item (GtkItemFactory           *ifactory,
  * @entries: an array of #GtkMenuEntry<!-- -->s 
  *
  * Creates the menu items from the @entries.
+ *
+ * Deprecated: 2.4:
  */
 void
 gtk_item_factory_create_menu_entries (guint              n_entries,
@@ -1256,6 +1232,8 @@ gtk_item_factory_create_menu_entries (guint              n_entries,
  * @path: a path 
  * 
  * Deletes all widgets constructed from the specified path.
+ *
+ * Deprecated: 2.4:
  */
 void
 gtk_item_factories_path_delete (const gchar *ifactory_path,
@@ -1315,19 +1293,18 @@ gtk_item_factories_path_delete (const gchar *ifactory_path,
  *
  * Deletes the menu item which was created for @path by the given
  * item factory.
+ *
+ * Deprecated: 2.4:
  */
 void
 gtk_item_factory_delete_item (GtkItemFactory         *ifactory,
                              const gchar            *path)
 {
-  GtkItemFactoryClass *class;
   GtkWidget *widget;
 
   g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
   g_return_if_fail (path != NULL);
 
-  class = GTK_ITEM_FACTORY_GET_CLASS (ifactory);
-
   widget = gtk_item_factory_get_widget (ifactory, path);
 
   if (widget)
@@ -1346,6 +1323,8 @@ gtk_item_factory_delete_item (GtkItemFactory         *ifactory,
  *
  * Deletes the menu item which was created from @entry by the given
  * item factory.
+ *
+ * Deprecated: 2.4:
  */
 void
 gtk_item_factory_delete_entry (GtkItemFactory         *ifactory,
@@ -1379,6 +1358,8 @@ gtk_item_factory_delete_entry (GtkItemFactory         *ifactory,
  *
  * Deletes the menu items which were created from the @entries by the given
  * item factory.
+ *
+ * Deprecated: 2.4:
  */
 void
 gtk_item_factory_delete_entries (GtkItemFactory         *ifactory,
@@ -1424,6 +1405,8 @@ gtk_item_factory_menu_pos (GtkMenu  *menu,
  * 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.
+ *
+ * Deprecated: 2.4:
  */
 gpointer
 gtk_item_factory_popup_data_from_widget (GtkWidget *widget)
@@ -1447,6 +1430,8 @@ gtk_item_factory_popup_data_from_widget (GtkWidget *widget)
  * 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.
+ *
+ * Deprecated: 2.4:
  */
 gpointer
 gtk_item_factory_popup_data (GtkItemFactory *ifactory)
@@ -1487,6 +1472,8 @@ ifactory_delete_popup_data (GtkObject        *object,
  *
  * The operation of the @mouse_button and the @time_ parameter is the same
  * as the @button and @activation_time parameters for gtk_menu_popup().
+ *
+ * Deprecated: 2.4:
  */
 void
 gtk_item_factory_popup (GtkItemFactory         *ifactory,
@@ -1524,6 +1511,8 @@ gtk_item_factory_popup (GtkItemFactory            *ifactory,
  *
  * The operation of the @mouse_button and the @time_ parameters is the same
  * as the @button and @activation_time parameters for gtk_menu_popup().
+ *
+ * Deprecated: 2.4:
  */
 void
 gtk_item_factory_popup_with_data (GtkItemFactory       *ifactory,
@@ -1581,6 +1570,8 @@ gtk_item_factory_popup_with_data (GtkItemFactory  *ifactory,
  * 
  * Sets a function to be used for translating the path elements before they
  * are displayed. 
+ *
+ * Deprecated: 2.4:
  */ 
 void
 gtk_item_factory_set_translate_func (GtkItemFactory      *ifactory,
@@ -1597,3 +1588,6 @@ gtk_item_factory_set_translate_func (GtkItemFactory      *ifactory,
   ifactory->translate_data = data;
   ifactory->translate_notify = notify;
 }
+
+#define __GTK_ITEM_FACTORY_C__
+#include "gtkaliasdef.c"