~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to library/forms/gtk/lf_radiobutton.h

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
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
 
7
 * License.
 
8
 * 
 
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.
 
13
 * 
 
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
 
17
 * 02110-1301  USA
 
18
 */
 
19
#ifndef _LF_RADIOBUTTON_H_
 
20
#define _LF_RADIOBUTTON_H_
 
21
 
 
22
#include <mforms/radiobutton.h>
 
23
 
 
24
 
 
25
#include "lf_view.h"
 
26
#include "lf_panel.h"
 
27
 
 
28
namespace mforms {
 
29
namespace gtk {
 
30
  
 
31
static std::map<int, Gtk::RadioButton*> groups;
 
32
 
 
33
class RadioButtonImpl : public ButtonImpl
 
34
{
 
35
 protected:
 
36
  Gtk::RadioButton *_radio;
 
37
  int _group_id;
 
38
 
 
39
  virtual Gtk::Widget *get_outer() const { return _radio; }
 
40
 
 
41
  RadioButtonImpl(::mforms::RadioButton *self, int group_id)
 
42
    : ButtonImpl(self), _group_id(group_id)
 
43
  {
 
44
    _radio= Gtk::manage(new Gtk::RadioButton());
 
45
    _button= _radio;
 
46
    
 
47
    if (groups.find(group_id) != groups.end())
 
48
    {
 
49
      Gtk::RadioButton::Group group(groups[group_id]->get_group());
 
50
      _radio->set_group(group);
 
51
    }
 
52
    else
 
53
    {
 
54
      groups[group_id] = _radio;
 
55
    }
 
56
 
 
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);
 
59
 
 
60
    _radio->signal_toggled().connect(sigc::bind(sigc::ptr_fun(&RadioButtonImpl::callback), self));
 
61
    _radio->show();
 
62
  }
 
63
  
 
64
  static void* unregister_group(void *data)
 
65
  {
 
66
    int group_id = reinterpret_cast<intptr_t>(data);
 
67
 
 
68
    std::map<int, Gtk::RadioButton*>::iterator iter;
 
69
    
 
70
    if ((iter=groups.find(group_id)) != groups.end())
 
71
      groups.erase(iter);
 
72
    return NULL;
 
73
  }
 
74
 
 
75
  static void callback(::mforms::RadioButton* self)
 
76
  {
 
77
    if (!self->is_updating() && self->get_data<RadioButtonImpl>()->_radio->get_active())
 
78
      self->callback();
 
79
  }
 
80
 
 
81
  static bool create(::mforms::RadioButton *self, int group_id)
 
82
  {
 
83
    return new RadioButtonImpl(self, group_id);
 
84
  }
 
85
 
 
86
  static bool get_active(::mforms::RadioButton *self)
 
87
  {
 
88
    RadioButtonImpl* button = self->get_data<RadioButtonImpl>();
 
89
    
 
90
    if ( button )
 
91
    {
 
92
      return button->_radio->get_active();
 
93
    }
 
94
    return false;
 
95
  }
 
96
  
 
97
  
 
98
  static void set_active(::mforms::RadioButton *self, bool flag)
 
99
  {
 
100
    RadioButtonImpl* button = self->get_data<RadioButtonImpl>();
 
101
    
 
102
    if ( button )
 
103
    {
 
104
      button->_radio->set_active(flag);
 
105
    }
 
106
  }
 
107
 
 
108
public:
 
109
  static void init()
 
110
  {
 
111
    ::mforms::ControlFactory *f = ::mforms::ControlFactory::get_instance();
 
112
 
 
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;
 
116
  }
 
117
};
 
118
 
 
119
}
 
120
}
 
121
 
 
122
 
 
123
#endif /* _LF_RADIOBUTTON_H_ */