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