Install ardour as a binary, a script and a set of shared
[ardour.git] / libs / gtkmm2 / gtk / gtkmm / menu_elems.h
1 /* $Id$ */
2 #ifndef _GTKMM_MENU_ELEMS_H
3 #define _GTKMM_MENU_ELEMS_H
4 /* menu_elems.h
5  * 
6  * Copyright (C) 1998-2002 The gtkmm Development Team
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 #include <gdk/gdkkeysyms.h>
24
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>
34
35 namespace Gtk
36 {
37
38 class Menu;
39
40 namespace Menu_Helpers
41 {
42
43 // input class (MenuItem-Factory)
44
45 class Element
46 {
47 public:
48   typedef sigc::slot<void> CallSlot;
49
50   Element();
51   Element(MenuItem& child);
52   ~Element();
53
54   const Glib::RefPtr<MenuItem>& get_child() const;
55
56 protected:
57
58   void set_child(MenuItem* pChild);
59   void set_accel_key(const AccelKey& accel_key);
60
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_;
64 };
65
66 /** Use this class and its subclasses to build menu items.
67  * For example,
68  * @code
69  * m_Menu_File.items().push_back( Gtk::Menu_Helpers::MenuElem("_New",
70  *   sigc::mem_fun(*this, &ExampleWindow::on_menu_file_new) ) );
71  * @endcode
72  *
73  * @ingroup Menus
74  */
75 class MenuElem : public Element
76 {
77 public:
78
79   MenuElem(MenuItem& child);
80
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
84    */
85   MenuElem(const Glib::ustring& label, const CallSlot& slot = CallSlot());
86
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
91    */
92   MenuElem(const Glib::ustring& label, const AccelKey& key,
93            const CallSlot& slot = CallSlot());
94
95   /** Create a labeled, non-accelerated MenuItem with a submenu
96    * @param label The menu item's name
97    * @param submenu The sub menu
98    */
99   MenuElem(const Glib::ustring& label, Gtk::Menu& submenu);
100
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
105    */
106   MenuElem(const Glib::ustring& label,
107            const AccelKey& key,
108            Gtk::Menu& submenu);
109 };
110
111 class SeparatorElem : public Element
112 {
113 public:
114   SeparatorElem();
115 };
116
117 class ImageMenuElem : public Element
118 {
119 public:
120   ImageMenuElem(ImageMenuItem& child);
121
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
126    */
127   ImageMenuElem(const Glib::ustring& label,
128                 Gtk::Widget& image_widget,
129                 const CallSlot& slot = CallSlot());
130
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
136    */
137   ImageMenuElem(const Glib::ustring& label, const AccelKey& key,
138                 Gtk::Widget& image_widget,
139                 const CallSlot& slot = CallSlot());
140
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
145    */
146   ImageMenuElem(const Glib::ustring& label,
147                 Gtk::Widget& image_widget,
148                 Gtk::Menu& submenu);
149
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
155    */
156   ImageMenuElem(const Glib::ustring& label, const AccelKey& key,
157                 Gtk::Widget& image_widget,
158                 Gtk::Menu& submenu);
159 };
160
161 class StockMenuElem : public Element
162 {
163 public:
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
167    */
168   StockMenuElem(const Gtk::StockID& stock_id,
169                 const CallSlot& slot = CallSlot());
170
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
175    */
176   StockMenuElem(const Gtk::StockID& stock_id,
177                 const AccelKey& key,
178                 const CallSlot& slot = CallSlot());
179
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
183    */
184   StockMenuElem(const Gtk::StockID& stock_id,
185                 Gtk::Menu& submenu);
186
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
191    */
192   StockMenuElem(const Gtk::StockID& stock_id,
193                 const AccelKey& key,
194                 Gtk::Menu& submenu);
195 };
196
197 class CheckMenuElem : public Element
198 {
199 public:
200   CheckMenuElem(CheckMenuItem& child);
201
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
205    */
206   CheckMenuElem(const Glib::ustring& label, const CallSlot& slot = CallSlot());
207
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
212    */
213   CheckMenuElem(const Glib::ustring& label, const AccelKey& key,
214                 const CallSlot& slot = CallSlot());
215 };
216
217
218 class RadioMenuElem : public Element
219 {
220 public:
221   RadioMenuElem(RadioMenuItem& child);
222
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
226    */
227   RadioMenuElem(RadioMenuItem::Group&, const Glib::ustring& label,
228                 const CallSlot& slot = CallSlot());
229
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
235    */
236   RadioMenuElem(RadioMenuItem::Group& group, const Glib::ustring& label,
237                 const AccelKey& key,
238                 const CallSlot& slot = CallSlot());
239
240 protected:
241   RadioMenuItem::Group* gr_;
242 };
243
244 class TearoffMenuElem : public Element
245 {
246 public:
247   TearoffMenuElem(TearoffMenuItem& child);
248
249   /** Create a non-accelerated TearoffMenuItem with a sigc::slot
250    * @param slot Use sigc::mem_fun() to specify a signal handler
251    */
252   TearoffMenuElem(const CallSlot& slot = CallSlot());
253
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
257    */
258   TearoffMenuElem(const AccelKey& key,
259                   const CallSlot& slot = CallSlot());
260 };
261
262 } /* namespace Menu_Helpers */
263
264 } /* namespace Gtk */
265
266 #endif //_GTKMM_MENU_ELEMS_H