]> Pileus Git - ~andy/gtk/blob - gtk/gtkmenu.h
cd51c1e551d0f4df01a04e6b4d59623cbc00eff7
[~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 Library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library 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-1999.  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 #ifndef __GTK_MENU_H__
28 #define __GTK_MENU_H__
29
30
31 #include <gdk/gdk.h>
32 #include <gtk/gtkaccelgroup.h>
33 #include <gtk/gtkmenushell.h>
34
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39
40
41 #define GTK_TYPE_MENU                   (gtk_menu_get_type ())
42 #define GTK_MENU(obj)                   (GTK_CHECK_CAST ((obj), GTK_TYPE_MENU, GtkMenu))
43 #define GTK_MENU_CLASS(klass)           (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_MENU, GtkMenuClass))
44 #define GTK_IS_MENU(obj)                (GTK_CHECK_TYPE ((obj), GTK_TYPE_MENU))
45 #define GTK_IS_MENU_CLASS(klass)        (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MENU))
46 #define GTK_MENU_GET_CLASS(obj)         (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_MENU, GtkMenuClass))
47
48
49 typedef struct _GtkMenu       GtkMenu;
50 typedef struct _GtkMenuClass  GtkMenuClass;
51
52 typedef void (*GtkMenuPositionFunc) (GtkMenu   *menu,
53                                      gint      *x,
54                                      gint      *y,
55                                      gpointer   user_data);
56 typedef void (*GtkMenuDetachFunc)   (GtkWidget *attach_widget,
57                                      GtkMenu   *menu);
58
59 struct _GtkMenu
60 {
61   GtkMenuShell menu_shell;
62   
63   GtkWidget *parent_menu_item;
64   GtkWidget *old_active_menu_item;
65   
66   GtkAccelGroup *accel_group;
67   GtkMenuPositionFunc position_func;
68   gpointer position_func_data;
69
70   /* Do _not_ touch these widgets directly. We hide the reference
71    * count from the toplevel to the menu, so it must be restored
72    * before operating on these widgets
73    */
74   GtkWidget *toplevel;
75   GtkWidget *tearoff_window;
76
77   guint torn_off : 1;
78 };
79
80 struct _GtkMenuClass
81 {
82   GtkMenuShellClass parent_class;
83 };
84
85
86 GtkType    gtk_menu_get_type              (void);
87 GtkWidget* gtk_menu_new                   (void);
88
89 /* Wrappers for the Menu Shell operations */
90 void       gtk_menu_append                (GtkMenu             *menu,
91                                            GtkWidget           *child);
92 void       gtk_menu_prepend               (GtkMenu             *menu,
93                                            GtkWidget           *child);
94 void       gtk_menu_insert                (GtkMenu             *menu,
95                                            GtkWidget           *child,
96                                            gint                 position);
97
98 /* Display the menu onscreen */
99 void       gtk_menu_popup                 (GtkMenu             *menu,
100                                            GtkWidget           *parent_menu_shell,
101                                            GtkWidget           *parent_menu_item,
102                                            GtkMenuPositionFunc  func,
103                                            gpointer             data,
104                                            guint                button,
105                                            guint32              activate_time);
106
107 /* Position the menu according to its position function. Called
108  * from gtkmenuitem.c when a menu-item changes its allocation
109  */
110 void       gtk_menu_reposition            (GtkMenu             *menu);
111
112 void       gtk_menu_popdown               (GtkMenu             *menu);
113
114 /* Keep track of the last menu item selected. (For the purposes
115  * of the option menu
116  */
117 GtkWidget* gtk_menu_get_active            (GtkMenu             *menu);
118 void       gtk_menu_set_active            (GtkMenu             *menu,
119                                            guint                index);
120
121 /* set/get the acclerator group that holds global accelerators (should
122  * be added to the corresponding toplevel with gtk_window_add_accel_group().
123  */
124 void           gtk_menu_set_accel_group   (GtkMenu             *menu,
125                                            GtkAccelGroup       *accel_group);
126 GtkAccelGroup* gtk_menu_get_accel_group   (GtkMenu             *menu);
127
128 /* get the accelerator group that is used internally by the menu for
129  * underline accelerators while the menu is popped up.
130  */
131 GtkAccelGroup* gtk_menu_get_uline_accel_group    (GtkMenu         *menu);
132 GtkAccelGroup* gtk_menu_ensure_uline_accel_group (GtkMenu         *menu);
133
134
135 /* A reference count is kept for a widget when it is attached to
136  * a particular widget. This is typically a menu item; it may also
137  * be a widget with a popup menu - for instance, the Notebook widget.
138  */
139 void       gtk_menu_attach_to_widget      (GtkMenu             *menu,
140                                            GtkWidget           *attach_widget,
141                                            GtkMenuDetachFunc    detacher);
142 void       gtk_menu_detach                (GtkMenu             *menu);
143
144 /* This should be dumped in favor of data set when the menu is popped
145  * up - that is currently in the ItemFactory code, but should be
146  * in the Menu code.
147  */
148 GtkWidget* gtk_menu_get_attach_widget     (GtkMenu             *menu);
149
150 void       gtk_menu_set_tearoff_state     (GtkMenu             *menu,
151                                            gboolean             torn_off);
152
153 /* This sets the window manager title for the window that
154  * appears when a menu is torn off
155  */
156 void       gtk_menu_set_title             (GtkMenu             *menu,
157                                            const gchar         *title);
158
159 void       gtk_menu_reorder_child         (GtkMenu             *menu,
160                                            GtkWidget           *child,
161                                            gint                position);
162
163 #ifdef __cplusplus
164 }
165 #endif /* __cplusplus */
166
167
168 #endif /* __GTK_MENU_H__ */