Debian Codegraph @

gtk/src/menushell.hg

raw
1 /* Copyright (C) 1998-2002 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 #include <gdk/gdkkeysyms.h>
18 _DEFS(gtkmm,gtk)
19 _PINCLUDE(gtkmm/private/container_p.h)
20 _PINCLUDE(gtkmm/menu.h)
21 _PINCLUDE(gtkmm/menubar.h)
22 _PINCLUDE(gtkmm/window.h)
23
24 #include <gtkmm/container.h>
25 #include <gtkmm/menuitem.h>
26 #include <giomm/menumodel.h>
27
28 namespace Gtk
29 {
30
31 class GTKMM_API Menu;
32 class GTKMM_API Window;
33
34
35 /** The abstract base class for Gtk::Menu and Gtk::MenuBar.
36 * It is a container of Gtk::MenuItem objects arranged in a list which can be navigated, selected, and activated by the user to perform application functions.
37 * It can have a submenu associated with it, allowing for nested hierarchical menus.
38 * Use append(), prepend() and insert() to add Gtk::MenuItem widgets.
39 * @ingroup Widgets
40 * @ingroup Containers
41 * @ingroup Menus
42 */
43 class GTKMM_API MenuShell : public Container
44 {
45 _CLASS_GTKOBJECT(MenuShell,GtkMenuShell,GTK_MENU_SHELL,Gtk::Container,GtkContainer,,,GTKMM_API)
46
47 public:
48 _CUSTOM_DTOR()
49
50 _WRAP_METHOD(void append(MenuItem& child), gtk_menu_shell_append)
51 _WRAP_METHOD(void prepend(MenuItem& child), gtk_menu_shell_prepend)
52 _WRAP_METHOD(void insert(MenuItem& child, int position), gtk_menu_shell_insert)
53
54 _WRAP_METHOD(void select_item(MenuItem& menu_item), gtk_menu_shell_select_item)
55 _WRAP_METHOD(void deselect(), gtk_menu_shell_deselect)
56
57 //TODO: Is force_deactivate = false a good default?
58 _WRAP_METHOD(void activate_item(MenuItem& menu_item, bool force_deactivate = false), gtk_menu_shell_activate_item)
59 _WRAP_METHOD(void select_first(bool search_sensitive = true), gtk_menu_shell_select_first)
60 _WRAP_METHOD(void deactivate(), gtk_menu_shell_deactivate)
61 _WRAP_METHOD(void cancel(), gtk_menu_shell_cancel)
62
63 _WRAP_SIGNAL(void deactivate(), "deactivate")
64 _WRAP_SIGNAL(void selection_done(), "selection_done")
65 _WRAP_SIGNAL(gboolean move_selected(int distance), "move-selected")
66
67 //TODO: Remove no_default_handler when we can break ABI.
68 _WRAP_SIGNAL(void insert(Widget* child, int position), "insert", no_default_handler)
69
70 //Keybinding signals:
71 _IGNORE_SIGNAL("move_current")
72 _IGNORE_SIGNAL("activate_current")
73 _IGNORE_SIGNAL("cancel")
74 _IGNORE_SIGNAL("cycle-focus")
75
76 /**
77 * Initializes menu accelerators.
78 * This method initializes the menu accelerators. Therefore an
79 * AccelGroup object is needed which is stored in each Window object
80 * in the Gtkmm library implementation.
81 *
82 * When using MenuBar and OptionMenu objects this method is called
83 * automatically when the menus are realized. Because most likely the
84 * MenuBar and OptionMenu is attached to a window at this time and
85 * the window object can be found automatically.
86 *
87 * Important note when using popup menus:
88 * If you are using accelerated menu entries inside a popup
89 * menu you have to call the accelerate() method manually. This is
90 * because the popup menu is not connected to any window and the
91 * accelerators should be initialized even before the popup menu is
92 * shown. The right place to call the accelerate() method is right
93 * after the popup menu has been build.
94 *
95 * @param window Window where the menu is shown. Inside this window
96 * the AccelGroup object is stored that will be used to initialize
97 * the accelerators.
98 */
99 void accelerate(Window& window);
100
101 /**
102 * Initializes menu accelerators.
103 * Does the same as the accelerate(Window& window) method. But you can
104 * use any parent widget where the menu is used. This method then gets
105 * the toplevel window using Widget::get_toplevel() and uses this
106 * window for registering the menu accelerators.
107 *
108 * @param parent Parent widget used as starting point for searching
109 * the toplevel window.
110 */
111 void accelerate(Widget& parent);
112
113 _WRAP_METHOD(bool get_take_focus() const, gtk_menu_shell_get_take_focus)
114 _WRAP_METHOD(void set_take_focus(bool take_focus = true), gtk_menu_shell_set_take_focus)
115
116 _WRAP_METHOD(Widget* get_selected_item(), gtk_menu_shell_get_selected_item)
117 _WRAP_METHOD(const Widget* get_selected_item() const, gtk_menu_shell_get_selected_item)
118
119 _WRAP_METHOD(Widget* get_parent_shell(), gtk_menu_shell_get_parent_shell)
120 _WRAP_METHOD(const Widget* get_parent_shell() const, gtk_menu_shell_get_parent_shell)
121
122 _WRAP_METHOD(void bind_model(const Glib::RefPtr<Gio::MenuModel>& model, const Glib::ustring& action_namespace{?}, bool with_separators), gtk_menu_shell_bind_model)
123
124 _WRAP_PROPERTY("take-focus", bool)
125
126 protected:
127 MenuShell();
128 _CUSTOM_CTOR_CAST()
129
130 private:
131
132 #m4begin
133 dnl // Override GtkMenuItem::insert, in order to accelerate all menu items automagically.
134 _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
135 klass->insert = &insert_vfunc_callback;
136 _SECTION(SECTION_PH_VFUNCS)
137 static void insert_vfunc_callback(GtkMenuShell* self, GtkWidget* child, int position);
138 _POP()
139 #m4end
140
141 Gtk::Window* accel_window_;
142 };
143
144 } // namespace Gtk