lots of tricks & tweaks related to the monitor section and All That It Uses
[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
67         visual_state = n;
68 }
69
70 /* ----------------------------------------------------------------- */
71
72 void
73 StatefulToggleButton::on_realize ()
74 {
75         ToggleButton::on_realize ();
76
77         _is_realized = true;
78         visual_state++; // to force transition
79         set_visual_state (visual_state - 1);
80 }
81
82 void
83 StatefulButton::on_realize ()
84 {
85         Button::on_realize ();
86
87         _is_realized = true;
88         visual_state++; // to force transition
89         set_visual_state (visual_state - 1);
90 }
91
92 void
93 StatefulToggleButton::on_toggled ()
94 {
95         if (!_self_managed) {
96                 if (get_active()) {
97                         set_visual_state (1);
98                 } else {
99                         set_visual_state (0);
100                 }
101         }
102 }
103
104 void
105 StatefulToggleButton::set_widget_name (const std::string& name)
106 {
107         set_name (name); 
108         Widget* w = get_child();
109
110         if (w) {
111                 w->set_name (name); 
112         } 
113 }
114
115 void
116 StatefulButton::set_widget_name (const std::string& name)
117 {
118         set_name (name); 
119         Widget* w = get_child();
120
121         if (w) {
122                 w->set_name (name); 
123         } 
124 }