merged with 1697 revision of trunk (which is post-rc1 but pre-rc2
[ardour.git] / libs / gtkmm2ext / stateful_button.cc
1 #include <string>
2 #include <iostream>
3
4 #include <gtkmm/main.h>
5
6 #include <gtkmm2ext/stateful_button.h>
7
8 using namespace Gtk;
9 using namespace Glib;
10 using namespace Gtkmm2ext;
11 using namespace std;
12
13 StateButton::StateButton ()
14 {
15         _is_realized = false;
16         visual_state = 0;
17 }
18
19 void
20 StateButton::set_visual_state (int n)
21 {
22         if (!_is_realized) {
23                 /* not yet realized */
24                 visual_state = n;
25                 return;
26         }
27
28         if (n == visual_state) {
29                 return;
30         }
31
32         string name = get_widget_name ();
33         name = name.substr (0, name.find_last_of ('-'));
34
35         switch (n) {
36         case 0:
37                 /* relax */
38                 break;
39         case 1:
40                 name += "-active";
41                 break;
42         case 2:
43                 name += "-alternate";
44                 break;
45         }
46
47         set_widget_name (name);
48         visual_state = n;
49 }
50
51 /* ----------------------------------------------------------------- */
52
53 void
54 StatefulToggleButton::on_realize ()
55 {
56         ToggleButton::on_realize ();
57
58         _is_realized = true;
59         visual_state++; // to force transition
60         set_visual_state (visual_state - 1);
61 }
62
63 void
64 StatefulButton::on_realize ()
65 {
66         Button::on_realize ();
67
68         _is_realized = true;
69         visual_state++; // to force transition
70         set_visual_state (visual_state - 1);
71 }
72
73 void
74 StatefulToggleButton::on_toggled ()
75 {
76         if (!_self_managed) {
77                 if (get_active()) {
78                         set_visual_state (1);
79                 } else {
80                         set_visual_state (0);
81                 }
82         }
83 }