fix up file renaming code a little bit
[ArdourMidi.git] / libs / gtkmm2ext / grouped_buttons.cc
blobcd45840a04db5d7a68a8955e34c49906df8f0330
1 /*
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.
18 $Id$
21 #include <gtkmm.h>
23 #include <gtkmm2ext/grouped_buttons.h>
25 using namespace std;
27 GroupedButtons::GroupedButtons (vector<Gtk::ToggleButton *>& buttonset)
29 uint32_t n = 0;
31 buttons = buttonset;
33 for (vector<Gtk::ToggleButton *>::iterator i = buttons.begin(); i != buttons.end(); ++i, ++n) {
34 if ((*i)->get_active()) {
35 current_active = n;
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);
61 static gint
62 reactivate_button (void *arg)
64 Gtk::ToggleButton *b = (Gtk::ToggleButton *) arg;
65 b->set_active (true);
66 return FALSE;
69 void
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]);