]> Pileus Git - ~andy/gtk/blob - gtk/gtkitemfactory.h
use gdk_pixbuf_new_from_stream(). fixed up item factory so inlined pixbufs
[~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   gchar                 *cpair_comment_single;
83
84   GHashTable            *item_ht;
85
86   gpointer               dummy;
87 };
88
89 struct _GtkItemFactoryEntry
90 {
91   gchar *path;
92   gchar *accelerator;
93
94   GtkItemFactoryCallback callback;
95   guint                  callback_action;
96
97   /* possible values:
98    * NULL               -> "<Item>"
99    * ""                 -> "<Item>"
100    * "<Title>"          -> create a title item
101    * "<Item>"           -> create a simple item
102    * "<ImageItem>"      -> create an item holding an image
103    * "<StockItem>"      -> create an item holding a stock image
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    * "<Tearoff>"        -> create a tearoff separator
110    * "<Branch>"         -> create an item to hold sub items
111    * "<LastBranch>"     -> create a right justified item to hold sub items
112    */
113   gchar          *item_type;
114
115   /* Extra data for some item types:
116    *  ImageItem  -> pointer to inlined pixbuf stream
117    *  StockItem  -> name of stock item
118    */
119   gconstpointer extra_data;
120 };
121
122 struct _GtkItemFactoryItem
123 {
124   gchar *path;
125   guint  accelerator_key;
126   guint  accelerator_mods;
127   guint  modified : 1;
128   guint  in_propagation : 1;
129   gchar *dummy;
130
131   GSList *widgets;
132 };
133
134
135 GtkType         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       (GtkType              container_type,
141                                             const gchar         *path,
142                                             GtkAccelGroup       *accel_group);
143 void            gtk_item_factory_construct (GtkItemFactory      *ifactory,
144                                             GtkType              container_type,
145                                             const gchar         *path,
146                                             GtkAccelGroup       *accel_group);
147      
148 /* These functions operate on GtkItemFactoryClass basis.
149  */
150 void            gtk_item_factory_parse_rc           (const gchar    *file_name);
151 void            gtk_item_factory_parse_rc_string    (const gchar    *rc_string);
152 void            gtk_item_factory_parse_rc_scanner   (GScanner       *scanner);
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 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 /* If `path_pspec' is passed as `NULL', this function will iterate over
172  * all hash entries. otherwise only those entries will be dumped for which
173  * the pattern matches, e.g. "<Image>*...".
174  */
175 void    gtk_item_factory_dump_items     (GPatternSpec           *path_pspec,
176                                          gboolean                modified_only,
177                                          GtkPrintFunc            print_func,
178                                          gpointer                func_data);
179 void    gtk_item_factory_dump_rc        (const gchar            *file_name,
180                                          GPatternSpec           *path_pspec,
181                                          gboolean                modified_only);
182 void    gtk_item_factory_print_func     (gpointer                FILE_pointer,
183                                          const gchar            *string);
184 void    gtk_item_factory_create_item    (GtkItemFactory         *ifactory,
185                                          GtkItemFactoryEntry    *entry,
186                                          gpointer                callback_data,
187                                          guint                   callback_type);
188 void    gtk_item_factory_create_items   (GtkItemFactory         *ifactory,
189                                          guint                   n_entries,
190                                          GtkItemFactoryEntry    *entries,
191                                          gpointer                callback_data);
192 void    gtk_item_factory_delete_item    (GtkItemFactory         *ifactory,
193                                          const gchar            *path);
194 void    gtk_item_factory_delete_entry   (GtkItemFactory         *ifactory,
195                                          GtkItemFactoryEntry    *entry);
196 void    gtk_item_factory_delete_entries (GtkItemFactory         *ifactory,
197                                          guint                   n_entries,
198                                          GtkItemFactoryEntry    *entries);
199 void    gtk_item_factory_popup          (GtkItemFactory         *ifactory,
200                                          guint                   x,
201                                          guint                   y,
202                                          guint                   mouse_button,
203                                          guint32                 time);
204 void    gtk_item_factory_popup_with_data(GtkItemFactory         *ifactory,
205                                          gpointer                popup_data,
206                                          GtkDestroyNotify        destroy,
207                                          guint                   x,
208                                          guint                   y,
209                                          guint                   mouse_button,
210                                          guint32                 time);
211 gpointer gtk_item_factory_popup_data    (GtkItemFactory         *ifactory);
212 gpointer gtk_item_factory_popup_data_from_widget (GtkWidget     *widget);
213 void   gtk_item_factory_set_translate_func (GtkItemFactory      *ifactory,
214                                             GtkTranslateFunc     func,
215                                             gpointer             data,
216                                             GtkDestroyNotify     notify);
217
218 /* Compatibility functions for deprecated GtkMenuFactory code
219  */
220 typedef void (*GtkMenuCallback) (GtkWidget *widget,
221                                  gpointer   user_data);
222 typedef struct {
223   gchar *path;
224   gchar *accelerator;
225   GtkMenuCallback callback;
226   gpointer callback_data;
227   GtkWidget *widget;
228 } GtkMenuEntry;
229 GtkItemFactory* gtk_item_factory_from_path   (const gchar       *path);
230 void    gtk_item_factory_create_menu_entries (guint              n_entries,
231                                               GtkMenuEntry      *entries);
232 void    gtk_item_factories_path_delete     (const gchar         *ifactory_path,
233                                             const gchar         *path);
234 typedef void    (*GtkItemFactoryCallback2) (GtkWidget           *widget,
235                                             gpointer             callback_data,
236                                             guint                callback_action);
237 void    gtk_item_factory_create_items_ac (GtkItemFactory        *ifactory,
238                                           guint                  n_entries,
239                                           GtkItemFactoryEntry   *entries,
240                                           gpointer               callback_data,
241                                           guint                  callback_type);
242
243
244
245 #ifdef __cplusplus
246 }
247 #endif /* __cplusplus */
248
249
250 #endif  /* __GTK_ITEM_FACTORY_H__ */