]> Pileus Git - ~andy/gtk/blob - gtk/gtkitemfactory.h
applied patch from Andreas Persenius <ndap@swipnet.se> that updates the
[~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 #include <gtk/gtkmenufactory.h> /* for GtkMenuEntry */
36 #include <gtk/gtkbindings.h>    /* for GtkPatternSpec */
37
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif /* __cplusplus */
42
43
44 typedef void    (*GtkPrintFunc)            (gpointer             func_data,
45                                             const gchar         *str);
46 typedef gchar * (*GtkTranslateFunc)        (const gchar         *path,
47                                             gpointer             func_data);
48 typedef void    (*GtkItemFactoryCallback)  ();
49 typedef void    (*GtkItemFactoryCallback1) (gpointer             callback_data,
50                                             guint                callback_action,
51                                             GtkWidget           *widget);
52
53 #define GTK_TYPE_ITEM_FACTORY            (gtk_item_factory_get_type ())
54 #define GTK_ITEM_FACTORY(object)         (GTK_CHECK_CAST ((object), GTK_TYPE_ITEM_FACTORY, GtkItemFactory))
55 #define GTK_ITEM_FACTORY_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_ITEM_FACTORY, GtkItemFactoryClass))
56 #define GTK_IS_ITEM_FACTORY(object)      (GTK_CHECK_TYPE ((object), GTK_TYPE_ITEM_FACTORY))
57 #define GTK_IS_ITEM_FACTORY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ITEM_FACTORY))
58 #define GTK_ITEM_FACTORY_GET_CLASS(obj)  (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_ITEM_FACTORY, GtkItemFactoryClass))
59
60
61 typedef struct  _GtkItemFactory                 GtkItemFactory;
62 typedef struct  _GtkItemFactoryClass            GtkItemFactoryClass;
63 typedef struct  _GtkItemFactoryEntry            GtkItemFactoryEntry;
64 typedef struct  _GtkItemFactoryItem             GtkItemFactoryItem;
65
66 struct _GtkItemFactory
67 {
68   GtkObject              object;
69
70   gchar                 *path;
71   GtkAccelGroup         *accel_group;
72   GtkWidget             *widget;
73   GSList                *items;
74
75   GtkTranslateFunc       translate_func;
76   gpointer               translate_data;
77   GtkDestroyNotify       translate_notify;   
78 };
79
80 struct _GtkItemFactoryClass
81 {
82   GtkObjectClass         object_class;
83
84   gchar                 *cpair_comment_single;
85
86   GHashTable            *item_ht;
87
88   gpointer               dummy;
89 };
90
91 struct _GtkItemFactoryEntry
92 {
93   gchar *path;
94   gchar *accelerator;
95
96   GtkItemFactoryCallback callback;
97   guint                  callback_action;
98
99   /* possible values:
100    * NULL               -> "<Item>"
101    * ""                 -> "<Item>"
102    * "<Title>"          -> create a title item
103    * "<Item>"           -> create a simple item
104    * "<CheckItem>"      -> create a check item
105    * "<ToggleItem>"     -> create a toggle item
106    * "<RadioItem>"      -> create a radio item
107    * <path>             -> path of a radio item to link against
108    * "<Separator>"      -> create a separator
109    * "<Branch>"         -> create an item to hold sub items
110    * "<LastBranch>"     -> create a right justified item to hold sub items
111    */
112   gchar          *item_type;
113 };
114
115 struct _GtkItemFactoryItem
116 {
117   gchar *path;
118   guint  accelerator_key;
119   guint  accelerator_mods;
120   guint  modified : 1;
121   guint  in_propagation : 1;
122   gchar *dummy;
123
124   GSList *widgets;
125 };
126
127
128 GtkType         gtk_item_factory_get_type           (void);
129
130 /* `container_type' must be of GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,
131  * or GTK_TYPE_OPTION_MENU.
132  */
133 GtkItemFactory* gtk_item_factory_new       (GtkType              container_type,
134                                             const gchar         *path,
135                                             GtkAccelGroup       *accel_group);
136 void            gtk_item_factory_construct (GtkItemFactory      *ifactory,
137                                             GtkType              container_type,
138                                             const gchar         *path,
139                                             GtkAccelGroup       *accel_group);
140      
141 /* These functions operate on GtkItemFactoryClass basis.
142  */
143 void            gtk_item_factory_parse_rc           (const gchar    *file_name);
144 void            gtk_item_factory_parse_rc_string    (const gchar    *rc_string);
145 void            gtk_item_factory_parse_rc_scanner   (GScanner       *scanner);
146 void            gtk_item_factory_add_foreign        (GtkWidget      *accel_widget,
147                                                      const gchar    *full_path,
148                                                      GtkAccelGroup  *accel_group,
149                                                      guint           keyval,
150                                                      GdkModifierType modifiers);
151      
152 GtkItemFactory* gtk_item_factory_from_widget        (GtkWidget        *widget);
153 gchar*          gtk_item_factory_path_from_widget   (GtkWidget        *widget);
154
155 GtkWidget*      gtk_item_factory_get_item             (GtkItemFactory *ifactory,
156                                                        const gchar    *path);
157 GtkWidget*      gtk_item_factory_get_widget           (GtkItemFactory *ifactory,
158                                                        const gchar    *path);
159 GtkWidget*      gtk_item_factory_get_widget_by_action (GtkItemFactory *ifactory,
160                                                        guint           action);
161 GtkWidget*      gtk_item_factory_get_item_by_action   (GtkItemFactory *ifactory,
162                                                        guint           action);
163
164 /* If `path_pspec' is passed as `NULL', this function will iterate over
165  * all hash entries. otherwise only those entries will be dumped for which
166  * the pattern matches, e.g. "<Image>*...".
167  */
168 void    gtk_item_factory_dump_items     (GtkPatternSpec         *path_pspec,
169                                          gboolean                modified_only,
170                                          GtkPrintFunc            print_func,
171                                          gpointer                func_data);
172 void    gtk_item_factory_dump_rc        (const gchar            *file_name,
173                                          GtkPatternSpec         *path_pspec,
174                                          gboolean                modified_only);
175 void    gtk_item_factory_print_func     (gpointer                FILE_pointer,
176                                          const gchar            *string);
177 void    gtk_item_factory_create_item    (GtkItemFactory         *ifactory,
178                                          GtkItemFactoryEntry    *entry,
179                                          gpointer                callback_data,
180                                          guint                   callback_type);
181 void    gtk_item_factory_create_items   (GtkItemFactory         *ifactory,
182                                          guint                   n_entries,
183                                          GtkItemFactoryEntry    *entries,
184                                          gpointer                callback_data);
185 void    gtk_item_factory_delete_item    (GtkItemFactory         *ifactory,
186                                          const gchar            *path);
187 void    gtk_item_factory_delete_entry   (GtkItemFactory         *ifactory,
188                                          GtkItemFactoryEntry    *entry);
189 void    gtk_item_factory_delete_entries (GtkItemFactory         *ifactory,
190                                          guint                   n_entries,
191                                          GtkItemFactoryEntry    *entries);
192 void    gtk_item_factory_popup          (GtkItemFactory         *ifactory,
193                                          guint                   x,
194                                          guint                   y,
195                                          guint                   mouse_button,
196                                          guint32                 time);
197 void    gtk_item_factory_popup_with_data(GtkItemFactory         *ifactory,
198                                          gpointer                popup_data,
199                                          GtkDestroyNotify        destroy,
200                                          guint                   x,
201                                          guint                   y,
202                                          guint                   mouse_button,
203                                          guint32                 time);
204 gpointer gtk_item_factory_popup_data    (GtkItemFactory         *ifactory);
205 gpointer gtk_item_factory_popup_data_from_widget (GtkWidget     *widget);
206 void   gtk_item_factory_set_translate_func (GtkItemFactory      *ifactory,
207                                             GtkTranslateFunc     func,
208                                             gpointer             data,
209                                             GtkDestroyNotify     notify);
210
211 /* Compatibility functions for deprecated GtkMenuFactory code
212  */
213 GtkItemFactory* gtk_item_factory_from_path   (const gchar       *path);
214 void    gtk_item_factory_create_menu_entries (guint              n_entries,
215                                               GtkMenuEntry      *entries);
216 void    gtk_item_factories_path_delete     (const gchar         *ifactory_path,
217                                             const gchar         *path);
218 typedef void    (*GtkItemFactoryCallback2) (GtkWidget           *widget,
219                                             gpointer             callback_data,
220                                             guint                callback_action);
221 void    gtk_item_factory_create_items_ac (GtkItemFactory        *ifactory,
222                                           guint                  n_entries,
223                                           GtkItemFactoryEntry   *entries,
224                                           gpointer               callback_data,
225                                           guint                  callback_type);
226
227
228
229 #ifdef __cplusplus
230 }
231 #endif /* __cplusplus */
232
233
234 #endif  /* __GTK_ITEM_FACTORY_H__ */