stopped/monitor/state change bug fix from 2.X
[ardour2.git] / libs / gtkmm2ext / stateful_button.cc
blob66cc2f192aa045d6153bc1693627c4adafa0cce7
1 /*
2 Copyright (C) 2000-2007 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.
20 #include <string>
21 #include <iostream>
23 #include <gtkmm/main.h>
25 #include "pbd/stacktrace.h"
27 #include <gtkmm2ext/stateful_button.h>
29 using namespace Gtk;
30 using namespace Glib;
31 using namespace Gtkmm2ext;
32 using namespace std;
34 StateButton::StateButton () : visual_state (0), _self_managed (false), _is_realized (false)
39 void
40 StateButton::set_visual_state (int n)
42 if (!_is_realized) {
43 /* not yet realized */
44 visual_state = n;
45 return;
48 if (n == visual_state) {
49 return;
52 string name = get_widget_name ();
53 name = name.substr (0, name.find_last_of ('-'));
55 switch (n) {
56 case 0:
57 /* relax */
58 break;
59 case 1:
60 name += "-active";
61 break;
62 case 2:
63 name += "-alternate";
64 break;
67 set_widget_name (name);
68 visual_state = n;
71 /* ----------------------------------------------------------------- */
73 void
74 StatefulToggleButton::on_realize ()
76 ToggleButton::on_realize ();
78 _is_realized = true;
79 visual_state++; // to force transition
80 set_visual_state (visual_state - 1);
83 void
84 StatefulButton::on_realize ()
86 Button::on_realize ();
88 _is_realized = true;
89 visual_state++; // to force transition
90 set_visual_state (visual_state - 1);
93 void
94 StatefulToggleButton::on_toggled ()
96 if (!_self_managed) {
97 if (get_active()) {
98 set_visual_state (1);
99 } else {
100 set_visual_state (0);
105 void
106 StatefulToggleButton::set_widget_name (const std::string& name)
108 set_name (name);
109 Widget* w = get_child();
111 if (w) {
112 w->set_name (name);
113 } else {
114 cerr << "Statefull TOggle button - no child\n";
115 PBD::stacktrace (cerr, 20);
119 void
120 StatefulButton::set_widget_name (const std::string& name)
122 set_name (name);
123 Widget* w = get_child();
125 if (w) {
126 w->set_name (name);
127 } else {
128 cerr << "Stateful button - no child\n";
129 PBD::stacktrace (cerr, 20);