2
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; version 2 of the
9
* This program 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
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19
#ifndef _LF_RADIOBUTTON_H_
20
#define _LF_RADIOBUTTON_H_
22
#include <mforms/radiobutton.h>
31
static std::map<int, Gtk::RadioButton*> groups;
33
class RadioButtonImpl : public ButtonImpl
36
Gtk::RadioButton *_radio;
39
virtual Gtk::Widget *get_outer() const { return _radio; }
41
RadioButtonImpl(::mforms::RadioButton *self, int group_id)
42
: ButtonImpl(self), _group_id(group_id)
44
_radio= Gtk::manage(new Gtk::RadioButton());
47
if (groups.find(group_id) != groups.end())
49
Gtk::RadioButton::Group group(groups[group_id]->get_group());
50
_radio->set_group(group);
54
groups[group_id] = _radio;
57
self->add_destroy_notify_callback(reinterpret_cast<void*>(group_id), &RadioButtonImpl::unregister_group);
58
_radio->add_destroy_notify_callback(reinterpret_cast<void*>(group_id), &RadioButtonImpl::unregister_group);
60
_radio->signal_toggled().connect(sigc::bind(sigc::ptr_fun(&RadioButtonImpl::callback), self));
64
static void* unregister_group(void *data)
66
int group_id = reinterpret_cast<intptr_t>(data);
68
std::map<int, Gtk::RadioButton*>::iterator iter;
70
if ((iter=groups.find(group_id)) != groups.end())
75
static void callback(::mforms::RadioButton* self)
77
if (!self->is_updating() && self->get_data<RadioButtonImpl>()->_radio->get_active())
81
static bool create(::mforms::RadioButton *self, int group_id)
83
return new RadioButtonImpl(self, group_id);
86
static bool get_active(::mforms::RadioButton *self)
88
RadioButtonImpl* button = self->get_data<RadioButtonImpl>();
92
return button->_radio->get_active();
98
static void set_active(::mforms::RadioButton *self, bool flag)
100
RadioButtonImpl* button = self->get_data<RadioButtonImpl>();
104
button->_radio->set_active(flag);
111
::mforms::ControlFactory *f = ::mforms::ControlFactory::get_instance();
113
f->_radio_impl.create= &RadioButtonImpl::create;
114
f->_radio_impl.get_active= &RadioButtonImpl::get_active;
115
f->_radio_impl.set_active= &RadioButtonImpl::set_active;
123
#endif /* _LF_RADIOBUTTON_H_ */