]> Pileus Git - ~andy/gtk/blob - gtk/gtkmenu.h
557949dfdba1a310cfd661b9d662dec5941bb648
[~andy/gtk] / gtk / gtkmenu.h
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25  */
26
27 #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
28 #error "Only <gtk/gtk.h> can be included directly."
29 #endif
30
31 #ifndef __GTK_MENU_H__
32 #define __GTK_MENU_H__
33
34
35 #include <gtk/gtkaccelgroup.h>
36 #include <gtk/gtkmenushell.h>
37
38
39 G_BEGIN_DECLS
40
41 #define GTK_TYPE_MENU                   (gtk_menu_get_type ())
42 #define GTK_MENU(obj)                   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_MENU, GtkMenu))
43 #define GTK_MENU_CLASS(klass)           (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_MENU, GtkMenuClass))
44 #define GTK_IS_MENU(obj)                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_MENU))
45 #define GTK_IS_MENU_CLASS(klass)        (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MENU))
46 #define GTK_MENU_GET_CLASS(obj)         (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_MENU, GtkMenuClass))
47
48
49 typedef struct _GtkMenu        GtkMenu;
50 typedef struct _GtkMenuClass   GtkMenuClass;
51 typedef struct _GtkMenuPrivate GtkMenuPrivate;
52
53 /**
54  * GtkMenuPositionFunc:
55  * @menu: a #GtkMenu.
56  * @x: (out): address of the #gint representing the horizontal
57  *     position where the menu shall be drawn.
58  * @y: (out): address of the #gint representing the vertical position
59  *     where the menu shall be drawn.  This is an output parameter.
60  * @push_in: (out): This parameter controls how menus placed outside
61  *     the monitor are handled.  If this is set to %TRUE and part of
62  *     the menu is outside the monitor then GTK+ pushes the window
63  *     into the visible area, effectively modifying the popup
64  *     position.  Note that moving and possibly resizing the menu
65  *     around will alter the scroll position to keep the menu items
66  *     "in place", i.e. at the same monitor position they would have
67  *     been without resizing.  In practice, this behavior is only
68  *     useful for combobox popups or option menus and cannot be used
69  *     to simply confine a menu to monitor boundaries.  In that case,
70  *     changing the scroll offset is not desirable.
71  * @user_data: the data supplied by the user in the gtk_menu_popup()
72  *     @data parameter.
73  *
74  * A user function supplied when calling gtk_menu_popup() which
75  * controls the positioning of the menu when it is displayed.  The
76  * function sets the @x and @y parameters to the coordinates where the
77  * menu is to be drawn.  To make the menu appear on a different
78  * monitor than the mouse pointer, gtk_menu_set_monitor() must be
79  * called.
80  */
81 typedef void (*GtkMenuPositionFunc) (GtkMenu   *menu,
82                                      gint      *x,
83                                      gint      *y,
84                                      gboolean  *push_in,
85                                      gpointer   user_data);
86
87 /**
88  * GtkMenuDetachFunc:
89  * @attach_widget: the #GtkWidget that the menu is being detached from.
90  * @menu: the #GtkMenu being detached.
91  *
92  * A user function supplied when calling gtk_menu_attach_to_widget() which 
93  * will be called when the menu is later detached from the widget.
94  */
95 typedef void (*GtkMenuDetachFunc)   (GtkWidget *attach_widget,
96                                      GtkMenu   *menu);
97
98 struct _GtkMenu
99 {
100   GtkMenuShell menu_shell;
101
102   /*< private >*/
103   GtkMenuPrivate *priv;
104 };
105
106 struct _GtkMenuClass
107 {
108   GtkMenuShellClass parent_class;
109
110   /* Padding for future expansion */
111   void (*_gtk_reserved1) (void);
112   void (*_gtk_reserved2) (void);
113   void (*_gtk_reserved3) (void);
114   void (*_gtk_reserved4) (void);
115 };
116
117
118 GType      gtk_menu_get_type              (void) G_GNUC_CONST;
119 GtkWidget* gtk_menu_new                   (void);
120 GtkWidget* gtk_menu_new_from_model        (GMenuModel *model);
121
122 /* Display the menu onscreen */
123 void       gtk_menu_popup                 (GtkMenu             *menu,
124                                            GtkWidget           *parent_menu_shell,
125                                            GtkWidget           *parent_menu_item,
126                                            GtkMenuPositionFunc  func,
127                                            gpointer             data,
128                                            guint                button,
129                                            guint32              activate_time);
130 void       gtk_menu_popup_for_device      (GtkMenu             *menu,
131                                            GdkDevice           *device,
132                                            GtkWidget           *parent_menu_shell,
133                                            GtkWidget           *parent_menu_item,
134                                            GtkMenuPositionFunc  func,
135                                            gpointer             data,
136                                            GDestroyNotify       destroy,
137                                            guint                button,
138                                            guint32              activate_time);
139
140 /* Position the menu according to its position function. Called
141  * from gtkmenuitem.c when a menu-item changes its allocation
142  */
143 void       gtk_menu_reposition            (GtkMenu             *menu);
144
145 void       gtk_menu_popdown               (GtkMenu             *menu);
146
147 /* Keep track of the last menu item selected. (For the purposes
148  * of the option menu
149  */
150 GtkWidget* gtk_menu_get_active            (GtkMenu             *menu);
151 void       gtk_menu_set_active            (GtkMenu             *menu,
152                                            guint                index);
153
154 /* set/get the accelerator group that holds global accelerators (should
155  * be added to the corresponding toplevel with gtk_window_add_accel_group().
156  */
157 void           gtk_menu_set_accel_group   (GtkMenu             *menu,
158                                            GtkAccelGroup       *accel_group);
159 GtkAccelGroup* gtk_menu_get_accel_group   (GtkMenu             *menu);
160 void           gtk_menu_set_accel_path    (GtkMenu             *menu,
161                                            const gchar         *accel_path);
162 const gchar*   gtk_menu_get_accel_path    (GtkMenu             *menu);
163
164 /* A reference count is kept for a widget when it is attached to
165  * a particular widget. This is typically a menu item; it may also
166  * be a widget with a popup menu - for instance, the Notebook widget.
167  */
168 void       gtk_menu_attach_to_widget      (GtkMenu             *menu,
169                                            GtkWidget           *attach_widget,
170                                            GtkMenuDetachFunc    detacher);
171 void       gtk_menu_detach                (GtkMenu             *menu);
172
173 /* This should be dumped in favor of data set when the menu is popped
174  * up - that is currently in the ItemFactory code, but should be
175  * in the Menu code.
176  */
177 GtkWidget* gtk_menu_get_attach_widget     (GtkMenu             *menu);
178
179 void       gtk_menu_set_tearoff_state     (GtkMenu             *menu,
180                                            gboolean             torn_off);
181 gboolean   gtk_menu_get_tearoff_state     (GtkMenu             *menu);
182
183 /* This sets the window manager title for the window that
184  * appears when a menu is torn off
185  */
186 void          gtk_menu_set_title          (GtkMenu             *menu,
187                                            const gchar         *title);
188 const gchar * gtk_menu_get_title          (GtkMenu             *menu);
189
190 void       gtk_menu_reorder_child         (GtkMenu             *menu,
191                                            GtkWidget           *child,
192                                            gint                position);
193
194 void       gtk_menu_set_screen            (GtkMenu             *menu,
195                                            GdkScreen           *screen);
196
197 void       gtk_menu_attach                (GtkMenu             *menu,
198                                            GtkWidget           *child,
199                                            guint                left_attach,
200                                            guint                right_attach,
201                                            guint                top_attach,
202                                            guint                bottom_attach);
203
204 void       gtk_menu_set_monitor           (GtkMenu             *menu,
205                                            gint                 monitor_num);
206 gint       gtk_menu_get_monitor           (GtkMenu             *menu);
207 GList*     gtk_menu_get_for_attach_widget (GtkWidget           *widget); 
208
209 void     gtk_menu_set_reserve_toggle_size (GtkMenu  *menu,
210                                           gboolean   reserve_toggle_size);
211 gboolean gtk_menu_get_reserve_toggle_size (GtkMenu  *menu);
212
213
214 G_END_DECLS
215
216 #endif /* __GTK_MENU_H__ */