2 Copyright (C) 2001 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <gtkmm2ext/grouped_buttons.h>
27 GroupedButtons::GroupedButtons (vector
<Gtk::ToggleButton
*>& buttonset
)
33 for (vector
<Gtk::ToggleButton
*>::iterator i
= buttons
.begin(); i
!= buttons
.end(); ++i
, ++n
) {
34 if ((*i
)->get_active()) {
37 (*i
)->signal_clicked().connect (sigc::bind (mem_fun (*this, &GroupedButtons::one_clicked
), n
));
41 GroupedButtons::GroupedButtons (uint32_t nbuttons
, uint32_t first_active
)
43 buttons
.reserve (nbuttons
);
44 current_active
= first_active
;
46 for (uint32_t n
= 0; n
< nbuttons
; ++n
) {
48 Gtk::ToggleButton
*button
;
50 button
= manage (new (Gtk::ToggleButton
));
52 if (n
== current_active
) {
53 button
->set_active (true);
56 button
->signal_clicked().connect (sigc::bind (mem_fun (*this, &GroupedButtons::one_clicked
), n
));
57 buttons
.push_back (button
);
62 reactivate_button (void *arg
)
64 Gtk::ToggleButton
*b
= (Gtk::ToggleButton
*) arg
;
70 GroupedButtons::one_clicked (uint32_t which
)
72 if (buttons
[which
]->get_active()) {
74 if (which
!= current_active
) {
75 uint32_t old
= current_active
;
76 current_active
= which
;
77 buttons
[old
]->set_active (false);
80 } else if (which
== current_active
) {
82 /* Someobody tried to unset the current active
83 button by clicking on it. This caused
84 set_active (false) to be called. We don't
85 allow that, so just reactivate it.
87 Don't try this right here, because of some
88 design glitches with GTK+ toggle buttons.
89 Setting the button back to active from
90 within the signal emission that marked
91 it as inactive causes a segfault ...
94 g_idle_add (reactivate_button
, buttons
[which
]);