]> Pileus Git - ~andy/gtk/blob - gtk/gtkitemfactory.h
Fix minor typo in docs. (#378632, Hannes Mueller)
[~andy/gtk] / gtk / gtkitemfactory.h
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * GtkItemFactory: Flexible item factory with automatic rc handling
5  * Copyright (C) 1998 Tim Janik
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /*
24  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
25  * file for a list of people on the GTK+ Team.  See the ChangeLog
26  * files for a list of changes.  These files are distributed with
27  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
28  */
29
30 #ifndef __GTK_ITEM_FACTORY_H__
31 #define __GTK_ITEM_FACTORY_H__
32
33
34 #include <gtk/gtkwidget.h>
35
36 G_BEGIN_DECLS
37
38 typedef gchar * (*GtkTranslateFunc)        (const gchar         *path,
39                                             gpointer             func_data);
40
41 #if !defined (GTK_DISABLE_DEPRECATED)
42
43 typedef void    (*GtkPrintFunc)            (gpointer             func_data,
44                                             const gchar         *str);
45 /* We use () here to mean unspecified arguments. This is deprecated
46  * as of C99, but we can't change it without breaking compatibility.
47  * (Note that if we are included from a C++ program () will mean
48  * (void) so an explicit cast will be needed.)
49  */
50 typedef void    (*GtkItemFactoryCallback)  ();
51 typedef void    (*GtkItemFactoryCallback1) (gpointer             callback_data,
52                                             guint                callback_action,
53                                             GtkWidget           *widget);
54
55 #define GTK_TYPE_ITEM_FACTORY            (gtk_item_factory_get_type ())
56 #define GTK_ITEM_FACTORY(object)         (G_TYPE_CHECK_INSTANCE_CAST ((object), GTK_TYPE_ITEM_FACTORY, GtkItemFactory))
57 #define GTK_ITEM_FACTORY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ITEM_FACTORY, GtkItemFactoryClass))
58 #define GTK_IS_ITEM_FACTORY(object)      (G_TYPE_CHECK_INSTANCE_TYPE ((object), GTK_TYPE_ITEM_FACTORY))
59 #define GTK_IS_ITEM_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ITEM_FACTORY))
60 #define GTK_ITEM_FACTORY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ITEM_FACTORY, GtkItemFactoryClass))
61
62
63 typedef struct  _GtkItemFactory                 GtkItemFactory;
64 typedef struct  _GtkItemFactoryClass            GtkItemFactoryClass;
65 typedef struct  _GtkItemFactoryEntry            GtkItemFactoryEntry;
66 typedef struct  _GtkItemFactoryItem             GtkItemFactoryItem;
67
68 struct _GtkItemFactory
69 {
70   GtkObject              object;
71
72   gchar                 *path;
73   GtkAccelGroup         *accel_group;
74   GtkWidget             *widget;
75   GSList                *items;
76
77   GtkTranslateFunc       translate_func;
78   gpointer               translate_data;
79   GtkDestroyNotify       translate_notify;   
80 };
81
82 struct _GtkItemFactoryClass
83 {
84   GtkObjectClass         object_class;
85
86   GHashTable            *item_ht;
87
88   /* Padding for future expansion */
89   void (*_gtk_reserved1) (void);
90   void (*_gtk_reserved2) (void);
91   void (*_gtk_reserved3) (void);
92   void (*_gtk_reserved4) (void);
93 };
94
95 struct _GtkItemFactoryEntry
96 {
97   gchar *path;
98   gchar *accelerator;
99
100   GtkItemFactoryCallback callback;
101   guint                  callback_action;
102
103   /* possible values:
104    * NULL               -> "<Item>"
105    * ""                 -> "<Item>"
106    * "<Title>"          -> create a title item
107    * "<Item>"           -> create a simple item
108    * "<ImageItem>"      -> create an item holding an image
109    * "<StockItem>"      -> create an item holding a stock image
110    * "<CheckItem>"      -> create a check item
111    * "<ToggleItem>"     -> create a toggle item
112    * "<RadioItem>"      -> create a radio item
113    * <path>             -> path of a radio item to link against
114    * "<Separator>"      -> create a separator
115    * "<Tearoff>"        -> create a tearoff separator
116    * "<Branch>"         -> create an item to hold sub items
117    * "<LastBranch>"     -> create a right justified item to hold sub items
118    */
119   gchar          *item_type;
120
121   /* Extra data for some item types:
122    *  ImageItem  -> pointer to inlined pixbuf stream
123    *  StockItem  -> name of stock item
124    */
125   gconstpointer extra_data;
126 };
127
128 struct _GtkItemFactoryItem
129 {
130   gchar *path;
131   GSList *widgets;
132 };
133
134
135 GType           gtk_item_factory_get_type           (void) G_GNUC_CONST;
136
137 /* `container_type' must be of GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,
138  * or GTK_TYPE_OPTION_MENU.
139  */
140 GtkItemFactory* gtk_item_factory_new       (GType                container_type,
141                                             const gchar         *path,
142                                             GtkAccelGroup       *accel_group);
143 void            gtk_item_factory_construct (GtkItemFactory      *ifactory,
144                                             GType                container_type,
145                                             const gchar         *path,
146                                             GtkAccelGroup       *accel_group);
147      
148 /* These functions operate on GtkItemFactoryClass basis.
149  */
150 void            gtk_item_factory_add_foreign        (GtkWidget      *accel_widget,
151                                                      const gchar    *full_path,
152                                                      GtkAccelGroup  *accel_group,
153                                                      guint           keyval,
154                                                      GdkModifierType modifiers);
155      
156 GtkItemFactory*       gtk_item_factory_from_widget      (GtkWidget *widget);
157 G_CONST_RETURN gchar* gtk_item_factory_path_from_widget (GtkWidget *widget);
158
159 GtkWidget*      gtk_item_factory_get_item             (GtkItemFactory *ifactory,
160                                                        const gchar    *path);
161 GtkWidget*      gtk_item_factory_get_widget           (GtkItemFactory *ifactory,
162                                                        const gchar    *path);
163 GtkWidget*      gtk_item_factory_get_widget_by_action (GtkItemFactory *ifactory,
164                                                        guint           action);
165 GtkWidget*      gtk_item_factory_get_item_by_action   (GtkItemFactory *ifactory,
166                                                        guint           action);
167
168 void    gtk_item_factory_create_item    (GtkItemFactory         *ifactory,
169                                          GtkItemFactoryEntry    *entry,
170                                          gpointer                callback_data,
171                                          guint                   callback_type);
172 void    gtk_item_factory_create_items   (GtkItemFactory         *ifactory,
173                                          guint                   n_entries,
174                                          GtkItemFactoryEntry    *entries,
175                                          gpointer                callback_data);
176 void    gtk_item_factory_delete_item    (GtkItemFactory         *ifactory,
177                                          const gchar            *path);
178 void    gtk_item_factory_delete_entry   (GtkItemFactory         *ifactory,
179                                          GtkItemFactoryEntry    *entry);
180 void    gtk_item_factory_delete_entries (GtkItemFactory         *ifactory,
181                                          guint                   n_entries,
182                                          GtkItemFactoryEntry    *entries);
183 void    gtk_item_factory_popup          (GtkItemFactory         *ifactory,
184                                          guint                   x,
185                                          guint                   y,
186                                          guint                   mouse_button,
187                                          guint32                 time_);
188 void    gtk_item_factory_popup_with_data(GtkItemFactory         *ifactory,
189                                          gpointer                popup_data,
190                                          GtkDestroyNotify        destroy,
191                                          guint                   x,
192                                          guint                   y,
193                                          guint                   mouse_button,
194                                          guint32                 time_);
195 gpointer gtk_item_factory_popup_data    (GtkItemFactory         *ifactory);
196 gpointer gtk_item_factory_popup_data_from_widget (GtkWidget     *widget);
197 void   gtk_item_factory_set_translate_func (GtkItemFactory      *ifactory,
198                                             GtkTranslateFunc     func,
199                                             gpointer             data,
200                                             GtkDestroyNotify     notify);
201
202 /* Compatibility functions for deprecated GtkMenuFactory code
203  */
204
205 /* Used by gtk_item_factory_create_menu_entries () */
206 typedef void (*GtkMenuCallback) (GtkWidget *widget,
207                                  gpointer   user_data);
208 typedef struct {
209   gchar *path;
210   gchar *accelerator;
211   GtkMenuCallback callback;
212   gpointer callback_data;
213   GtkWidget *widget;
214 } GtkMenuEntry;
215
216 /* Used by gtk_item_factory_callback_marshal () */
217 typedef void    (*GtkItemFactoryCallback2) (GtkWidget           *widget,
218                                             gpointer             callback_data,
219                                             guint                callback_action);
220
221 /* Used by gtk_item_factory_create_items () */
222 void    gtk_item_factory_create_items_ac (GtkItemFactory        *ifactory,
223                                           guint                  n_entries,
224                                           GtkItemFactoryEntry   *entries,
225                                           gpointer               callback_data,
226                                           guint                  callback_type);
227
228 GtkItemFactory* gtk_item_factory_from_path   (const gchar       *path);
229 void    gtk_item_factory_create_menu_entries (guint              n_entries,
230                                               GtkMenuEntry      *entries);
231 void    gtk_item_factories_path_delete     (const gchar         *ifactory_path,
232                                             const gchar         *path);
233
234 #endif /* !GTK_DISABLE_DEPRECATED */
235
236
237 G_END_DECLS
238
239 #endif  /* __GTK_ITEM_FACTORY_H__ */
240