]> Pileus Git - ~andy/gtk/blob - gtk/gtkitemfactory.h
applied the undisputable and required [due to recent gtkfilesystem
[~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
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
40
41 typedef gchar * (*GtkTranslateFunc)        (const gchar         *path,
42                                             gpointer             func_data);
43
44 #if !defined (GTK_DISABLE_DEPRECATED) || defined (GTK_COMPILATION)
45
46 typedef void    (*GtkPrintFunc)            (gpointer             func_data,
47                                             const gchar         *str);
48 /* We use () here to mean unspecified arguments. This is deprecated
49  * as of C99, but we can't change it without breaking compatibility.
50  * (Note that if we are included from a C++ program () will mean
51  * (void) so an explicit cast will be needed.)
52  */
53 typedef void    (*GtkItemFactoryCallback)  ();
54 typedef void    (*GtkItemFactoryCallback1) (gpointer             callback_data,
55                                             guint                callback_action,
56                                             GtkWidget           *widget);
57
58 #define GTK_TYPE_ITEM_FACTORY            (gtk_item_factory_get_type ())
59 #define GTK_ITEM_FACTORY(object)         (G_TYPE_CHECK_INSTANCE_CAST ((object), GTK_TYPE_ITEM_FACTORY, GtkItemFactory))
60 #define GTK_ITEM_FACTORY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ITEM_FACTORY, GtkItemFactoryClass))
61 #define GTK_IS_ITEM_FACTORY(object)      (G_TYPE_CHECK_INSTANCE_TYPE ((object), GTK_TYPE_ITEM_FACTORY))
62 #define GTK_IS_ITEM_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ITEM_FACTORY))
63 #define GTK_ITEM_FACTORY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ITEM_FACTORY, GtkItemFactoryClass))
64
65
66 typedef struct  _GtkItemFactory                 GtkItemFactory;
67 typedef struct  _GtkItemFactoryClass            GtkItemFactoryClass;
68 typedef struct  _GtkItemFactoryEntry            GtkItemFactoryEntry;
69 typedef struct  _GtkItemFactoryItem             GtkItemFactoryItem;
70
71 struct _GtkItemFactory
72 {
73   GtkObject              object;
74
75   gchar                 *path;
76   GtkAccelGroup         *accel_group;
77   GtkWidget             *widget;
78   GSList                *items;
79
80   GtkTranslateFunc       translate_func;
81   gpointer               translate_data;
82   GtkDestroyNotify       translate_notify;   
83 };
84
85 struct _GtkItemFactoryClass
86 {
87   GtkObjectClass         object_class;
88
89   GHashTable            *item_ht;
90
91   /* Padding for future expansion */
92   void (*_gtk_reserved1) (void);
93   void (*_gtk_reserved2) (void);
94   void (*_gtk_reserved3) (void);
95   void (*_gtk_reserved4) (void);
96 };
97
98 struct _GtkItemFactoryEntry
99 {
100   gchar *path;
101   gchar *accelerator;
102
103   GtkItemFactoryCallback callback;
104   guint                  callback_action;
105
106   /* possible values:
107    * NULL               -> "<Item>"
108    * ""                 -> "<Item>"
109    * "<Title>"          -> create a title item
110    * "<Item>"           -> create a simple item
111    * "<ImageItem>"      -> create an item holding an image
112    * "<StockItem>"      -> create an item holding a stock image
113    * "<CheckItem>"      -> create a check item
114    * "<ToggleItem>"     -> create a toggle item
115    * "<RadioItem>"      -> create a radio item
116    * <path>             -> path of a radio item to link against
117    * "<Separator>"      -> create a separator
118    * "<Tearoff>"        -> create a tearoff separator
119    * "<Branch>"         -> create an item to hold sub items
120    * "<LastBranch>"     -> create a right justified item to hold sub items
121    */
122   gchar          *item_type;
123
124   /* Extra data for some item types:
125    *  ImageItem  -> pointer to inlined pixbuf stream
126    *  StockItem  -> name of stock item
127    */
128   gconstpointer extra_data;
129 };
130
131 struct _GtkItemFactoryItem
132 {
133   gchar *path;
134   GSList *widgets;
135 };
136
137
138 GType           gtk_item_factory_get_type           (void) G_GNUC_CONST;
139
140 /* `container_type' must be of GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,
141  * or GTK_TYPE_OPTION_MENU.
142  */
143 GtkItemFactory* gtk_item_factory_new       (GType                container_type,
144                                             const gchar         *path,
145                                             GtkAccelGroup       *accel_group);
146 void            gtk_item_factory_construct (GtkItemFactory      *ifactory,
147                                             GType                container_type,
148                                             const gchar         *path,
149                                             GtkAccelGroup       *accel_group);
150      
151 /* These functions operate on GtkItemFactoryClass basis.
152  */
153 void            gtk_item_factory_add_foreign        (GtkWidget      *accel_widget,
154                                                      const gchar    *full_path,
155                                                      GtkAccelGroup  *accel_group,
156                                                      guint           keyval,
157                                                      GdkModifierType modifiers);
158      
159 GtkItemFactory*       gtk_item_factory_from_widget      (GtkWidget *widget);
160 G_CONST_RETURN gchar* gtk_item_factory_path_from_widget (GtkWidget *widget);
161
162 GtkWidget*      gtk_item_factory_get_item             (GtkItemFactory *ifactory,
163                                                        const gchar    *path);
164 GtkWidget*      gtk_item_factory_get_widget           (GtkItemFactory *ifactory,
165                                                        const gchar    *path);
166 GtkWidget*      gtk_item_factory_get_widget_by_action (GtkItemFactory *ifactory,
167                                                        guint           action);
168 GtkWidget*      gtk_item_factory_get_item_by_action   (GtkItemFactory *ifactory,
169                                                        guint           action);
170
171 void    gtk_item_factory_create_item    (GtkItemFactory         *ifactory,
172                                          GtkItemFactoryEntry    *entry,
173                                          gpointer                callback_data,
174                                          guint                   callback_type);
175 void    gtk_item_factory_create_items   (GtkItemFactory         *ifactory,
176                                          guint                   n_entries,
177                                          GtkItemFactoryEntry    *entries,
178                                          gpointer                callback_data);
179 void    gtk_item_factory_delete_item    (GtkItemFactory         *ifactory,
180                                          const gchar            *path);
181 void    gtk_item_factory_delete_entry   (GtkItemFactory         *ifactory,
182                                          GtkItemFactoryEntry    *entry);
183 void    gtk_item_factory_delete_entries (GtkItemFactory         *ifactory,
184                                          guint                   n_entries,
185                                          GtkItemFactoryEntry    *entries);
186 void    gtk_item_factory_popup          (GtkItemFactory         *ifactory,
187                                          guint                   x,
188                                          guint                   y,
189                                          guint                   mouse_button,
190                                          guint32                 time_);
191 void    gtk_item_factory_popup_with_data(GtkItemFactory         *ifactory,
192                                          gpointer                popup_data,
193                                          GtkDestroyNotify        destroy,
194                                          guint                   x,
195                                          guint                   y,
196                                          guint                   mouse_button,
197                                          guint32                 time_);
198 gpointer gtk_item_factory_popup_data    (GtkItemFactory         *ifactory);
199 gpointer gtk_item_factory_popup_data_from_widget (GtkWidget     *widget);
200 void   gtk_item_factory_set_translate_func (GtkItemFactory      *ifactory,
201                                             GtkTranslateFunc     func,
202                                             gpointer             data,
203                                             GtkDestroyNotify     notify);
204
205 /* Compatibility functions for deprecated GtkMenuFactory code
206  */
207
208 /* Used by gtk_item_factory_create_menu_entries () */
209 typedef void (*GtkMenuCallback) (GtkWidget *widget,
210                                  gpointer   user_data);
211 typedef struct {
212   gchar *path;
213   gchar *accelerator;
214   GtkMenuCallback callback;
215   gpointer callback_data;
216   GtkWidget *widget;
217 } GtkMenuEntry;
218
219 /* Used by gtk_item_factory_callback_marshal () */
220 typedef void    (*GtkItemFactoryCallback2) (GtkWidget           *widget,
221                                             gpointer             callback_data,
222                                             guint                callback_action);
223
224 /* Used by gtk_item_factory_create_items () */
225 void    gtk_item_factory_create_items_ac (GtkItemFactory        *ifactory,
226                                           guint                  n_entries,
227                                           GtkItemFactoryEntry   *entries,
228                                           gpointer               callback_data,
229                                           guint                  callback_type);
230
231 GtkItemFactory* gtk_item_factory_from_path   (const gchar       *path);
232 void    gtk_item_factory_create_menu_entries (guint              n_entries,
233                                               GtkMenuEntry      *entries);
234 void    gtk_item_factories_path_delete     (const gchar         *ifactory_path,
235                                             const gchar         *path);
236
237 #endif /* !GTK_DISABLE_DEPRECATED || GTK_COMPILATION */
238
239
240 #ifdef __cplusplus
241 }
242 #endif /* __cplusplus */
243
244
245 #endif  /* __GTK_ITEM_FACTORY_H__ */
246