Fix uninitialized value _self_managed spotted by valgrind.
[ardour.git] / libs / gtkmm2ext / stateful_button.cc
1 /*
2     Copyright (C) 2000-2007 Paul Davis 
3
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <string>
21 #include <iostream>
22
23 #include <gtkmm/main.h>
24
25 #include <gtkmm2ext/stateful_button.h>
26
27 using namespace Gtk;
28 using namespace Glib;
29 using namespace Gtkmm2ext;
30 using namespace std;
31
32 StateButton::StateButton () : visual_state (0), _self_managed (false), _is_realized (false)
33 {
34   
35 }
36
37 void
38 StateButton::set_visual_state (int n)
39 {
40         if (!_is_realized) {
41                 /* not yet realized */
42                 visual_state = n;
43                 return;
44         }
45
46         if (n == visual_state) {
47                 return;
48         }
49
50         string name = get_widget_name ();
51         name = name.substr (0, name.find_last_of ('-'));
52
53         switch (n) {
54         case 0:
55                 /* relax */
56                 break;
57         case 1:
58                 name += "-active";
59                 break;
60         case 2:
61                 name += "-alternate";
62                 break;
63         }
64
65         set_widget_name (name);
66         visual_state = n;
67 }
68
69 /* ----------------------------------------------------------------- */
70
71 void
72 StatefulToggleButton::on_realize ()
73 {
74         ToggleButton::on_realize ();
75
76         _is_realized = true;
77         visual_state++; // to force transition
78         set_visual_state (visual_state - 1);
79 }
80
81 void
82 StatefulButton::on_realize ()
83 {
84         Button::on_realize ();
85
86         _is_realized = true;
87         visual_state++; // to force transition
88         set_visual_state (visual_state - 1);
89 }
90
91 void
92 StatefulToggleButton::on_toggled ()
93 {
94         if (!_self_managed) {
95                 if (get_active()) {
96                         set_visual_state (1);
97                 } else {
98                         set_visual_state (0);
99                 }
100         }
101 }