6
* Copyright 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 <gtk/gtkimagemenuitem.h>
25
#include <gtkmm/menu_elems.h>
26
#include <gtkmm/label.h>
30
#endif // GLIBMM_WIN32
35
namespace Menu_Helpers
42
Element::Element(MenuItem& child)
44
//TODO: Can't we avoid using RefPtr<> with a widget. It's not what it's meant for, and apparently it doesn't work well. murrayc.
45
child_ = Glib::RefPtr<MenuItem>(&child);
46
child_->reference(); //It's normally used with a create(), which starts with a refcount of 1.
52
void Element::set_child(MenuItem* pChild)
54
child_ = Glib::RefPtr<MenuItem>(pChild);
55
child_->reference(); //TODO. We used to use the old RefPtr::operator=(), and this is what it did.
58
void Element::set_accel_key(const AccelKey& accel_key)
61
child_->set_accel_key(accel_key);
64
const Glib::RefPtr<MenuItem>& Element::get_child() const
69
MenuElem::MenuElem(MenuItem& child)
73
MenuElem::MenuElem(const Glib::ustring& label,
76
set_child( manage(new MenuItem(label, true)) );
78
child_->signal_activate().connect(slot);
82
MenuElem::MenuElem(const Glib::ustring& label,
83
const AccelKey& accel_key,
86
set_child( manage(new MenuItem(label, true)) );
88
child_->signal_activate().connect(slot);
89
set_accel_key(accel_key);
93
MenuElem::MenuElem(const Glib::ustring& label, Menu& submenu)
95
set_child( manage(new MenuItem(label, true)) );
96
child_->set_submenu(submenu);
100
MenuElem::MenuElem(const Glib::ustring& label,
101
const AccelKey& accel_key,
104
set_child( manage(new MenuItem(label, true)) );
105
child_->set_submenu(submenu);
106
set_accel_key(accel_key);
110
SeparatorElem::SeparatorElem()
112
set_child( manage(new SeparatorMenuItem()) );
116
ImageMenuElem::ImageMenuElem(ImageMenuItem& child)
120
ImageMenuElem::ImageMenuElem(const Glib::ustring& label,
121
Gtk::Widget& image_widget,
122
const CallSlot& slot)
124
image_widget.show(); //We assume that the coder wants to actually show the widget.
125
set_child( manage(new ImageMenuItem(image_widget, label, true)) );
127
child_->signal_activate().connect(slot);
131
ImageMenuElem::ImageMenuElem(const Glib::ustring& label,
132
const AccelKey& accel_key,
133
Gtk::Widget& image_widget,
134
const CallSlot& slot)
136
image_widget.show(); //We assume that the coder wants to actually show the widget.
137
set_child( manage(new ImageMenuItem(image_widget, label, true)) );
139
child_->signal_activate().connect(slot);
140
set_accel_key(accel_key);
144
ImageMenuElem::ImageMenuElem(const Glib::ustring& label,
145
Gtk::Widget& image_widget,
148
image_widget.show(); //We assume that the coder wants to actually show the widget.
149
set_child( manage(new ImageMenuItem(image_widget, label, true)) );
150
child_->set_submenu(submenu);
154
ImageMenuElem::ImageMenuElem(const Glib::ustring& label,
155
const AccelKey& accel_key,
156
Gtk::Widget& image_widget,
159
image_widget.show(); //We assume that the coder wants to actually show the widget.
160
set_child( manage(new ImageMenuItem(image_widget, label, true)) );
161
set_accel_key(accel_key);
162
child_->set_submenu(submenu);
166
StockMenuElem::StockMenuElem(const Gtk::StockID& stock_id,
167
const CallSlot& slot)
169
set_child( manage(new ImageMenuItem(stock_id)) );
171
child_->signal_activate().connect(slot);
175
StockMenuElem::StockMenuElem(const Gtk::StockID& stock_id,
176
const AccelKey& accel_key,
177
const CallSlot& slot)
179
set_child( manage(new ImageMenuItem(stock_id)) );
181
child_->signal_activate().connect(slot);
182
set_accel_key(accel_key);
186
StockMenuElem::StockMenuElem(const Gtk::StockID& stock_id,
189
set_child( manage(new ImageMenuItem(stock_id)) );
190
child_->set_submenu(submenu);
194
StockMenuElem::StockMenuElem(const Gtk::StockID& stock_id,
195
const AccelKey& accel_key,
198
set_child( manage(new ImageMenuItem(stock_id)) );
199
set_accel_key(accel_key);
200
child_->set_submenu(submenu);
204
CheckMenuElem::CheckMenuElem(CheckMenuItem& child)
208
CheckMenuElem::CheckMenuElem(const Glib::ustring& label,
209
const CallSlot& slot)
211
CheckMenuItem* item = manage(new CheckMenuItem(label, true));
214
item->signal_toggled().connect(slot);
218
CheckMenuElem::CheckMenuElem(const Glib::ustring& label,
219
const AccelKey& accel_key,
220
const CallSlot& slot)
222
CheckMenuItem* item = manage(new CheckMenuItem(label, true));
224
set_accel_key(accel_key);
226
item->signal_toggled().connect(slot);
231
RadioMenuElem::RadioMenuElem(RadioMenuItem& child)
232
: Element(child), gr_(0)
235
RadioMenuElem::RadioMenuElem(RadioMenuItem::Group& group,
236
const Glib::ustring& label,
237
const CallSlot& slot)
240
CheckMenuItem* item = manage(new RadioMenuItem(*gr_, label, true));
243
item->signal_toggled().connect(slot);
247
RadioMenuElem::RadioMenuElem(RadioMenuItem::Group& gr,
248
const Glib::ustring& label,
249
const AccelKey& accel_key,
250
const CallSlot& slot)
253
CheckMenuItem* item = manage(new RadioMenuItem(*gr_, label, true));
255
set_accel_key(accel_key);
257
item->signal_toggled().connect(slot);
261
TearoffMenuElem::TearoffMenuElem(TearoffMenuItem& child)
265
TearoffMenuElem::TearoffMenuElem(const CallSlot& slot)
267
set_child( manage(new TearoffMenuItem()) );
269
child_->signal_activate().connect(slot);
273
TearoffMenuElem::TearoffMenuElem(const AccelKey& accel_key,
274
const CallSlot& slot)
276
set_child( manage(new TearoffMenuItem()) );
277
set_accel_key(accel_key);
279
child_->signal_activate().connect(slot);
283
} /* namespace Menu_Helpers */
285
} /* namespace Gtk */