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