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