]> Pileus Git - ~andy/gtk/blob - gtk/gtkmenu.h
30c63824b8277e71d59a70e668d76edf054d08c2
[~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 #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 #define GTK_TYPE_MENU                   (gtk_menu_get_type ())
41 #define GTK_MENU(obj)                   (GTK_CHECK_CAST ((obj), GTK_TYPE_MENU, GtkMenu))
42 #define GTK_MENU_CLASS(klass)           (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_MENU, GtkMenuClass))
43 #define GTK_IS_MENU(obj)                (GTK_CHECK_TYPE ((obj), GTK_TYPE_MENU))
44 #define GTK_IS_MENU_CLASS(klass)        (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MENU))
45 #define GTK_MENU_GET_CLASS(obj)         (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_MENU, GtkMenuClass))
46
47
48 typedef struct _GtkMenu       GtkMenu;
49 typedef struct _GtkMenuClass  GtkMenuClass;
50
51 typedef void (*GtkMenuPositionFunc) (GtkMenu   *menu,
52                                      gint      *x,
53                                      gint      *y,
54                                      gboolean  *push_in,
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   guint toggle_size;
71   /* Do _not_ touch these widgets directly. We hide the reference
72    * count from the toplevel to the menu, so it must be restored
73    * before operating on these widgets
74    */
75   GtkWidget *toplevel;
76   
77   GtkWidget *tearoff_window;
78   GtkWidget *tearoff_hbox;
79   GtkWidget *tearoff_scrollbar;
80   GtkAdjustment *tearoff_adjustment;
81
82   GdkWindow *view_window;
83   GdkWindow *bin_window;
84
85   gint scroll_offset;
86   gint saved_scroll_offset;
87   gint scroll_step;
88   guint timeout_id;
89   
90   /* When a submenu of this menu is popped up, motion in this
91    * region is ignored
92    */
93   GdkRegion *navigation_region;
94   guint navigation_timeout;
95
96   guint needs_destruction_ref_count : 1;
97   guint torn_off : 1;
98   /* The tearoff is active when it is torn off and the not-torn-off
99    * menu is not popped up.
100    */
101   guint tearoff_active : 1; 
102
103   guint scroll_fast : 1;
104
105   guint upper_arrow_visible : 1;
106   guint lower_arrow_visible : 1;
107   guint upper_arrow_prelight : 1;
108   guint lower_arrow_prelight : 1;
109 };
110
111 struct _GtkMenuClass
112 {
113   GtkMenuShellClass parent_class;
114 };
115
116
117 GtkType    gtk_menu_get_type              (void) G_GNUC_CONST;
118 GtkWidget* gtk_menu_new                   (void);
119
120 /* Display the menu onscreen */
121 void       gtk_menu_popup                 (GtkMenu             *menu,
122                                            GtkWidget           *parent_menu_shell,
123                                            GtkWidget           *parent_menu_item,
124                                            GtkMenuPositionFunc  func,
125                                            gpointer             data,
126                                            guint                button,
127                                            guint32              activate_time);
128
129 /* Position the menu according to its position function. Called
130  * from gtkmenuitem.c when a menu-item changes its allocation
131  */
132 void       gtk_menu_reposition            (GtkMenu             *menu);
133
134 void       gtk_menu_popdown               (GtkMenu             *menu);
135
136 /* Keep track of the last menu item selected. (For the purposes
137  * of the option menu
138  */
139 GtkWidget* gtk_menu_get_active            (GtkMenu             *menu);
140 void       gtk_menu_set_active            (GtkMenu             *menu,
141                                            guint                index);
142
143 /* set/get the accelerator group that holds global accelerators (should
144  * be added to the corresponding toplevel with gtk_window_add_accel_group().
145  */
146 void           gtk_menu_set_accel_group   (GtkMenu             *menu,
147                                            GtkAccelGroup       *accel_group);
148 GtkAccelGroup* gtk_menu_get_accel_group   (GtkMenu             *menu);
149
150
151 /* A reference count is kept for a widget when it is attached to
152  * a particular widget. This is typically a menu item; it may also
153  * be a widget with a popup menu - for instance, the Notebook widget.
154  */
155 void       gtk_menu_attach_to_widget      (GtkMenu             *menu,
156                                            GtkWidget           *attach_widget,
157                                            GtkMenuDetachFunc    detacher);
158 void       gtk_menu_detach                (GtkMenu             *menu);
159
160 /* This should be dumped in favor of data set when the menu is popped
161  * up - that is currently in the ItemFactory code, but should be
162  * in the Menu code.
163  */
164 GtkWidget* gtk_menu_get_attach_widget     (GtkMenu             *menu);
165
166 void       gtk_menu_set_tearoff_state     (GtkMenu             *menu,
167                                            gboolean             torn_off);
168
169 /* This sets the window manager title for the window that
170  * appears when a menu is torn off
171  */
172 void       gtk_menu_set_title             (GtkMenu             *menu,
173                                            const gchar         *title);
174
175 void       gtk_menu_reorder_child         (GtkMenu             *menu,
176                                            GtkWidget           *child,
177                                            gint                position);
178
179 #ifdef __cplusplus
180 }
181 #endif /* __cplusplus */
182
183
184 #endif /* __GTK_MENU_H__ */