New theme manager, with option to select between dark and light theme. Cleanups...
[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 ()
33 {
34         _is_realized = false;
35         visual_state = 0;
36 }
37
38 void
39 StateButton::set_visual_state (int n)
40 {
41         if (!_is_realized) {
42                 /* not yet realized */
43                 visual_state = n;
44                 return;
45         }
46
47         if (n == visual_state) {
48                 return;
49         }
50
51         string name = get_widget_name ();
52         name = name.substr (0, name.find_last_of ('-'));
53
54         switch (n) {
55         case 0:
56                 /* relax */
57                 break;
58         case 1:
59                 name += "-active";
60                 break;
61         case 2:
62                 name += "-alternate";
63                 break;
64         }
65
66         set_widget_name (name);
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 }