2 #ifndef _GTKMM_MENU_ELEMS_H
3 #define _GTKMM_MENU_ELEMS_H
6 * Copyright (C) 1998-2002 The gtkmm Development Team
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <gdk/gdkkeysyms.h>
25 #include <gtkmm/container.h>
26 #include <gtkmm/menuitem.h>
27 #include <gtkmm/imagemenuitem.h>
28 #include <gtkmm/radiomenuitem.h>
29 #include <gtkmm/checkmenuitem.h>
30 #include <gtkmm/tearoffmenuitem.h>
31 #include <gtkmm/separatormenuitem.h>
32 #include <gtkmm/accelgroup.h>
33 #include <gtkmm/accelkey.h>
40 namespace Menu_Helpers
43 // input class (MenuItem-Factory)
48 typedef sigc::slot<void> CallSlot;
51 Element(MenuItem& child);
54 const Glib::RefPtr<MenuItem>& get_child() const;
58 void set_child(MenuItem* pChild);
59 void set_accel_key(const AccelKey& accel_key);
61 //We use a RefPtr to avoid leaks when the manage()d widget never gets added to a container.
62 //TODO: RefPtr is probably meant only for use with a create() method - see the extra reference() in set_child().
63 Glib::RefPtr<MenuItem> child_;
66 /** Use this class and its subclasses to build menu items.
69 * m_Menu_File.items().push_back( Gtk::Menu_Helpers::MenuElem("_New",
70 * sigc::mem_fun(*this, &ExampleWindow::on_menu_file_new) ) );
75 class MenuElem : public Element
79 MenuElem(MenuItem& child);
81 /** Create a labeled, non-accelerated MenuItem with a sigc::slot
82 * @param label The menu item's name
83 * @param slot Use sigc::mem_fun() to specify a signal handler
85 MenuElem(const Glib::ustring& label, const CallSlot& slot = CallSlot());
87 /** Create a labeled, accelerated MenuItem with a sigc::slot
88 * @param label The menu item's name
89 * @param key The accelerator key combination
90 * @param slot Use sigc::mem_fun() to specify a signal handler
92 MenuElem(const Glib::ustring& label, const AccelKey& key,
93 const CallSlot& slot = CallSlot());
95 /** Create a labeled, non-accelerated MenuItem with a submenu
96 * @param label The menu item's name
97 * @param submenu The sub menu
99 MenuElem(const Glib::ustring& label, Gtk::Menu& submenu);
101 /** Create a labeled, accelerated MenuItem with a submenu
102 * @param label The menu item's name
103 * @param key The accelerator key combination
104 * @param submenu The sub menu
106 MenuElem(const Glib::ustring& label,
111 class SeparatorElem : public Element
117 class ImageMenuElem : public Element
120 ImageMenuElem(ImageMenuItem& child);
122 /** Create a labeled, non-accelerated MenuItem with a sigc::slot
123 * @param label The menu item's name
124 * @param image_widget The image
125 * @param slot Use sigc::mem_fun() to specify a signal handler
127 ImageMenuElem(const Glib::ustring& label,
128 Gtk::Widget& image_widget,
129 const CallSlot& slot = CallSlot());
131 /** Create a labeled, accelerated MenuItem with a sigc::slot
132 * @param label The menu item's name
133 * @param key The accelerator key combination
134 * @param image_widget The image
135 * @param slot Use sigc::mem_fun() to specify a signal handler
137 ImageMenuElem(const Glib::ustring& label, const AccelKey& key,
138 Gtk::Widget& image_widget,
139 const CallSlot& slot = CallSlot());
141 /** Create a labeled, non-accelerated MenuItem with a submenu
142 * @param label The menu item's name
143 * @param image_widget The image
144 * @param submenu The sub menu
146 ImageMenuElem(const Glib::ustring& label,
147 Gtk::Widget& image_widget,
150 /** Create a labeled, accelerated MenuItem with a submenu
151 * @param label The menu item's name
152 * @param key The accelerator key combination
153 * @param image_widget The image
154 * @param submenu The sub menu
156 ImageMenuElem(const Glib::ustring& label, const AccelKey& key,
157 Gtk::Widget& image_widget,
161 class StockMenuElem : public Element
164 /** Create a non-accelerated MenuItem from a stock item
165 * @param stock_id The ID of the stock item
166 * @param slot Use sigc::mem_fun() to specify a signal handler
168 StockMenuElem(const Gtk::StockID& stock_id,
169 const CallSlot& slot = CallSlot());
171 /** Create an accelerated MenuItem from a stock item
172 * @param stock_id The ID of the stock item
173 * @param key The accelerator key combination
174 * @param slot Use sigc::mem_fun() to specify a signal handler
176 StockMenuElem(const Gtk::StockID& stock_id,
178 const CallSlot& slot = CallSlot());
180 /** Create a non-accelerated MenuItem from a stock item with a submenu
181 * @param stock_id The ID of the stock item
182 * @param submenu The sub menu
184 StockMenuElem(const Gtk::StockID& stock_id,
187 /** Create an accelerated MenuItem from a stock item with a submenu
188 * @param stock_id The ID of the stock item
189 * @param key The accelerator key combination
190 * @param submenu The sub menu
192 StockMenuElem(const Gtk::StockID& stock_id,
197 class CheckMenuElem : public Element
200 CheckMenuElem(CheckMenuItem& child);
202 /** Create a labeled, non-accelerated MenuItem with a sigc::slot
203 * @param label The menu item's name
204 * @param slot Use sigc::mem_fun() to specify a signal handler
206 CheckMenuElem(const Glib::ustring& label, const CallSlot& slot = CallSlot());
208 /** Create a labeled, accelerated CheckMenuItem with a sigc::slot
209 * @param label The menu item's name
210 * @param key The accelerator key combination
211 * @param slot Use sigc::mem_fun() to specify a signal handler
213 CheckMenuElem(const Glib::ustring& label, const AccelKey& key,
214 const CallSlot& slot = CallSlot());
218 class RadioMenuElem : public Element
221 RadioMenuElem(RadioMenuItem& child);
223 /** Create a labeled, non-accelerated MenuItem with a sigc::slot
224 * @param label The menu item's name
225 * @param slot Use sigc::mem_fun() to specify a signal handler
227 RadioMenuElem(RadioMenuItem::Group&, const Glib::ustring& label,
228 const CallSlot& slot = CallSlot());
230 /** Create a labeled, accelerated CheckMenuItem with a sigc::slot
231 * @param group The RadioMenuItem group in which to put this.
232 * @param label The menu item's name
233 * @param key The accelerator key combination
234 * @param slot Use sigc::mem_fun() to specify a signal handler
236 RadioMenuElem(RadioMenuItem::Group& group, const Glib::ustring& label,
238 const CallSlot& slot = CallSlot());
241 RadioMenuItem::Group* gr_;
244 class TearoffMenuElem : public Element
247 TearoffMenuElem(TearoffMenuItem& child);
249 /** Create a non-accelerated TearoffMenuItem with a sigc::slot
250 * @param slot Use sigc::mem_fun() to specify a signal handler
252 TearoffMenuElem(const CallSlot& slot = CallSlot());
254 /** Create accelerated TearoffMenuItem with a sigc::slot
255 * @param key The accelerator key combination
256 * @param slot Use sigc::mem_fun() to specify a signal handler
258 TearoffMenuElem(const AccelKey& key,
259 const CallSlot& slot = CallSlot());
262 } /* namespace Menu_Helpers */
264 } /* namespace Gtk */
266 #endif //_GTKMM_MENU_ELEMS_H