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, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
23 */
24
25#ifndef __GTK_MENU_H__
26#define __GTK_MENU_H__
27
28#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
29#error "Only <gtk/gtk.h> can be included directly."
30#endif
31
32#include <gtk/gtkaccelgroup.h>
33#include <gtk/gtkmenushell.h>
34
35G_BEGIN_DECLS
36
37#define GTK_TYPE_MENU (gtk_menu_get_type ())
38#define GTK_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_MENU, GtkMenu))
39#define GTK_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_MENU, GtkMenuClass))
40#define GTK_IS_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_MENU))
41#define GTK_IS_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MENU))
42#define GTK_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_MENU, GtkMenuClass))
43
44
45typedef struct _GtkMenu GtkMenu;
46typedef struct _GtkMenuClass GtkMenuClass;
47typedef struct _GtkMenuPrivate GtkMenuPrivate;
48
49/**
50 * GtkArrowPlacement:
51 * @GTK_ARROWS_BOTH: Place one arrow on each end of the menu.
52 * @GTK_ARROWS_START: Place both arrows at the top of the menu.
53 * @GTK_ARROWS_END: Place both arrows at the bottom of the menu.
54 *
55 * Used to specify the placement of scroll arrows in scrolling menus.
56 */
57typedef enum
58{
59 GTK_ARROWS_BOTH,
60 GTK_ARROWS_START,
61 GTK_ARROWS_END
62} GtkArrowPlacement;
63
64/**
65 * GtkMenuPositionFunc:
66 * @menu: a #GtkMenu.
67 * @x: (inout): address of the #gint representing the horizontal
68 * position where the menu shall be drawn.
69 * @y: (inout): address of the #gint representing the vertical position
70 * where the menu shall be drawn. This is an output parameter.
71 * @push_in: (out): This parameter controls how menus placed outside
72 * the monitor are handled. If this is set to %TRUE and part of
73 * the menu is outside the monitor then GTK+ pushes the window
74 * into the visible area, effectively modifying the popup
75 * position. Note that moving and possibly resizing the menu
76 * around will alter the scroll position to keep the menu items
77 * “in place”, i.e. at the same monitor position they would have
78 * been without resizing. In practice, this behavior is only
79 * useful for combobox popups or option menus and cannot be used
80 * to simply confine a menu to monitor boundaries. In that case,
81 * changing the scroll offset is not desirable.
82 * @user_data: the data supplied by the user in the gtk_menu_popup()
83 * @data parameter.
84 *
85 * A user function supplied when calling gtk_menu_popup() which
86 * controls the positioning of the menu when it is displayed. The
87 * function sets the @x and @y parameters to the coordinates where the
88 * menu is to be drawn. To make the menu appear on a different
89 * monitor than the mouse pointer, gtk_menu_set_monitor() must be
90 * called.
91 */
92typedef void (*GtkMenuPositionFunc) (GtkMenu *menu,
93 gint *x,
94 gint *y,
95 gboolean *push_in,
96 gpointer user_data);
97
98/**
99 * GtkMenuDetachFunc:
100 * @attach_widget: the #GtkWidget that the menu is being detached from.
101 * @menu: the #GtkMenu being detached.
102 *
103 * A user function supplied when calling gtk_menu_attach_to_widget() which
104 * will be called when the menu is later detached from the widget.
105 */
106typedef void (*GtkMenuDetachFunc) (GtkWidget *attach_widget,
107 GtkMenu *menu);
108
109struct _GtkMenu
110{
111 GtkMenuShell menu_shell;
112
113 /*< private >*/
114 GtkMenuPrivate *priv;
115};
116
117struct _GtkMenuClass
118{
119 GtkMenuShellClass parent_class;
120
121 /* Padding for future expansion */
122 void (*_gtk_reserved1) (void);
123 void (*_gtk_reserved2) (void);
124 void (*_gtk_reserved3) (void);
125 void (*_gtk_reserved4) (void);
126};
127
128
129GDK_AVAILABLE_IN_ALL
130GType gtk_menu_get_type (void) G_GNUC_CONST;
131GDK_AVAILABLE_IN_ALL
132GtkWidget* gtk_menu_new (void);
133GDK_AVAILABLE_IN_3_4
134GtkWidget* gtk_menu_new_from_model (GMenuModel *model);
135
136/* Display the menu onscreen */
137GDK_DEPRECATED_IN_3_22_FOR((gtk_menu_popup_at_widget, gtk_menu_popup_at_pointer, gtk_menu_popup_at_rect))
138void gtk_menu_popup (GtkMenu *menu,
139 GtkWidget *parent_menu_shell,
140 GtkWidget *parent_menu_item,
141 GtkMenuPositionFunc func,
142 gpointer data,
143 guint button,
144 guint32 activate_time);
145GDK_DEPRECATED_IN_3_22_FOR((gtk_menu_popup_at_widget, gtk_menu_popup_at_pointer, gtk_menu_popup_at_rect))
146void gtk_menu_popup_for_device (GtkMenu *menu,
147 GdkDevice *device,
148 GtkWidget *parent_menu_shell,
149 GtkWidget *parent_menu_item,
150 GtkMenuPositionFunc func,
151 gpointer data,
152 GDestroyNotify destroy,
153 guint button,
154 guint32 activate_time);
155GDK_AVAILABLE_IN_3_22
156void gtk_menu_popup_at_rect (GtkMenu *menu,
157 GdkWindow *rect_window,
158 const GdkRectangle *rect,
159 GdkGravity rect_anchor,
160 GdkGravity menu_anchor,
161 const GdkEvent *trigger_event);
162GDK_AVAILABLE_IN_3_22
163void gtk_menu_popup_at_widget (GtkMenu *menu,
164 GtkWidget *widget,
165 GdkGravity widget_anchor,
166 GdkGravity menu_anchor,
167 const GdkEvent *trigger_event);
168GDK_AVAILABLE_IN_3_22
169void gtk_menu_popup_at_pointer (GtkMenu *menu,
170 const GdkEvent *trigger_event);
171
172/* Position the menu according to its position function. Called
173 * from gtkmenuitem.c when a menu-item changes its allocation
174 */
175GDK_AVAILABLE_IN_ALL
176void gtk_menu_reposition (GtkMenu *menu);
177
178GDK_AVAILABLE_IN_ALL
179void gtk_menu_popdown (GtkMenu *menu);
180
181/* Keep track of the last menu item selected. (For the purposes
182 * of the option menu
183 */
184GDK_AVAILABLE_IN_ALL
185GtkWidget* gtk_menu_get_active (GtkMenu *menu);
186GDK_AVAILABLE_IN_ALL
187void gtk_menu_set_active (GtkMenu *menu,
188 guint index);
189
190/* set/get the accelerator group that holds global accelerators (should
191 * be added to the corresponding toplevel with gtk_window_add_accel_group().
192 */
193GDK_AVAILABLE_IN_ALL
194void gtk_menu_set_accel_group (GtkMenu *menu,
195 GtkAccelGroup *accel_group);
196GDK_AVAILABLE_IN_ALL
197GtkAccelGroup* gtk_menu_get_accel_group (GtkMenu *menu);
198GDK_AVAILABLE_IN_ALL
199void gtk_menu_set_accel_path (GtkMenu *menu,
200 const gchar *accel_path);
201GDK_AVAILABLE_IN_ALL
202const gchar* gtk_menu_get_accel_path (GtkMenu *menu);
203
204/* A reference count is kept for a widget when it is attached to
205 * a particular widget. This is typically a menu item; it may also
206 * be a widget with a popup menu - for instance, the Notebook widget.
207 */
208GDK_AVAILABLE_IN_ALL
209void gtk_menu_attach_to_widget (GtkMenu *menu,
210 GtkWidget *attach_widget,
211 GtkMenuDetachFunc detacher);
212GDK_AVAILABLE_IN_ALL
213void gtk_menu_detach (GtkMenu *menu);
214
215/* This should be dumped in favor of data set when the menu is popped
216 * up - that is currently in the ItemFactory code, but should be
217 * in the Menu code.
218 */
219GDK_AVAILABLE_IN_ALL
220GtkWidget* gtk_menu_get_attach_widget (GtkMenu *menu);
221
222GDK_DEPRECATED_IN_3_10
223void gtk_menu_set_tearoff_state (GtkMenu *menu,
224 gboolean torn_off);
225GDK_DEPRECATED_IN_3_10
226gboolean gtk_menu_get_tearoff_state (GtkMenu *menu);
227
228/* This sets the window manager title for the window that
229 * appears when a menu is torn off
230 */
231GDK_DEPRECATED_IN_3_10
232void gtk_menu_set_title (GtkMenu *menu,
233 const gchar *title);
234GDK_DEPRECATED_IN_3_10
235const gchar * gtk_menu_get_title (GtkMenu *menu);
236
237GDK_AVAILABLE_IN_ALL
238void gtk_menu_reorder_child (GtkMenu *menu,
239 GtkWidget *child,
240 gint position);
241
242GDK_AVAILABLE_IN_ALL
243void gtk_menu_set_screen (GtkMenu *menu,
244 GdkScreen *screen);
245
246GDK_AVAILABLE_IN_ALL
247void gtk_menu_attach (GtkMenu *menu,
248 GtkWidget *child,
249 guint left_attach,
250 guint right_attach,
251 guint top_attach,
252 guint bottom_attach);
253
254GDK_AVAILABLE_IN_ALL
255void gtk_menu_set_monitor (GtkMenu *menu,
256 gint monitor_num);
257GDK_AVAILABLE_IN_ALL
258gint gtk_menu_get_monitor (GtkMenu *menu);
259
260GDK_AVAILABLE_IN_3_22
261void gtk_menu_place_on_monitor (GtkMenu *menu,
262 GdkMonitor *monitor);
263
264GDK_AVAILABLE_IN_ALL
265GList* gtk_menu_get_for_attach_widget (GtkWidget *widget);
266
267GDK_AVAILABLE_IN_ALL
268void gtk_menu_set_reserve_toggle_size (GtkMenu *menu,
269 gboolean reserve_toggle_size);
270GDK_AVAILABLE_IN_ALL
271gboolean gtk_menu_get_reserve_toggle_size (GtkMenu *menu);
272
273G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMenu, g_object_unref)
274
275G_END_DECLS
276
277#endif /* __GTK_MENU_H__ */
278

source code of include/gtk-3.0/gtk/gtkmenu.h