summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext/stateful_button.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2007-04-11 13:07:51 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2007-04-11 13:07:51 +0000
commit45d3ec1437cf661533bc7750c623865def4424df (patch)
tree80cdeb58bc51a22042b91c50334bdd8ee37deed6 /libs/gtkmm2ext/stateful_button.cc
parent4bf712f501e21cbf1e555bf010553aaca55edd39 (diff)
merged with 1697 revision of trunk (which is post-rc1 but pre-rc2
git-svn-id: svn://localhost/ardour2/branches/2.1-staging@1698 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/gtkmm2ext/stateful_button.cc')
-rw-r--r--libs/gtkmm2ext/stateful_button.cc101
1 files changed, 52 insertions, 49 deletions
diff --git a/libs/gtkmm2ext/stateful_button.cc b/libs/gtkmm2ext/stateful_button.cc
index 074d086651..ffcafab123 100644
--- a/libs/gtkmm2ext/stateful_button.cc
+++ b/libs/gtkmm2ext/stateful_button.cc
@@ -1,31 +1,63 @@
#include <string>
#include <iostream>
-#include "gtkmm2ext/stateful_button.h"
+
+#include <gtkmm/main.h>
+
+#include <gtkmm2ext/stateful_button.h>
using namespace Gtk;
using namespace Glib;
using namespace Gtkmm2ext;
using namespace std;
-StatefulButton::StatefulButton ()
+StateButton::StateButton ()
{
- current_state = 0;
- have_saved_bg = false;
+ _is_realized = false;
+ visual_state = 0;
}
-StatefulButton::StatefulButton (const string& label)
- : Button (label)
+void
+StateButton::set_visual_state (int n)
{
- current_state = 0;
- have_saved_bg = false;
+ if (!_is_realized) {
+ /* not yet realized */
+ visual_state = n;
+ return;
+ }
+
+ if (n == visual_state) {
+ return;
+ }
+
+ string name = get_widget_name ();
+ name = name.substr (0, name.find_last_of ('-'));
+
+ switch (n) {
+ case 0:
+ /* relax */
+ break;
+ case 1:
+ name += "-active";
+ break;
+ case 2:
+ name += "-alternate";
+ break;
+ }
+
+ set_widget_name (name);
+ visual_state = n;
}
+/* ----------------------------------------------------------------- */
+
void
-StatefulButton::set_colors (const vector<Gdk::Color>& c)
+StatefulToggleButton::on_realize ()
{
- colors = c;
- current_state++; // to force transition
- set_state (current_state - 1);
+ ToggleButton::on_realize ();
+
+ _is_realized = true;
+ visual_state++; // to force transition
+ set_visual_state (visual_state - 1);
}
void
@@ -33,48 +65,19 @@ StatefulButton::on_realize ()
{
Button::on_realize ();
- if (!have_saved_bg) {
- saved_bg = get_style()->get_bg (STATE_NORMAL);
- have_saved_bg = true;
- }
-
- current_state++; // to force transition
- set_state (current_state - 1);
+ _is_realized = true;
+ visual_state++; // to force transition
+ set_visual_state (visual_state - 1);
}
void
-StatefulButton::set_state (int n)
+StatefulToggleButton::on_toggled ()
{
- if (is_realized()) {
-
- if (n == current_state) {
- return;
- }
-
- if (n == 0) {
-
- /* back to the default color */
-
- if (have_saved_bg) {
- modify_bg (STATE_NORMAL, saved_bg);
- modify_bg (STATE_ACTIVE, saved_bg);
- modify_bg (STATE_SELECTED, saved_bg);
- modify_bg (STATE_PRELIGHT, saved_bg);
- }
-
-
+ if (!_self_managed) {
+ if (get_active()) {
+ set_visual_state (1);
} else {
-
- int index = (n-1) % colors.size ();
-
- modify_bg (STATE_NORMAL, colors[index]);
- modify_bg (STATE_ACTIVE, colors[index]);
- modify_bg (STATE_SELECTED, colors[index]);
- modify_bg (STATE_PRELIGHT, colors[index]);
+ set_visual_state (0);
}
-
- /* leave insensitive alone */
}
-
- current_state = n;
}