summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext/stateful_button.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libs/gtkmm2ext/stateful_button.cc')
-rw-r--r--libs/gtkmm2ext/stateful_button.cc114
1 files changed, 69 insertions, 45 deletions
diff --git a/libs/gtkmm2ext/stateful_button.cc b/libs/gtkmm2ext/stateful_button.cc
index 074d086651..6cc24de461 100644
--- a/libs/gtkmm2ext/stateful_button.cc
+++ b/libs/gtkmm2ext/stateful_button.cc
@@ -1,80 +1,104 @@
#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;
+ visual_state = 0;
have_saved_bg = false;
}
-StatefulButton::StatefulButton (const string& label)
- : Button (label)
+void
+StateButton::set_colors (const vector<Gdk::Color>& c)
{
- current_state = 0;
- have_saved_bg = false;
+ colors = c;
+ visual_state++; // to force transition
+ set_visual_state (visual_state - 1);
}
void
-StatefulButton::set_colors (const vector<Gdk::Color>& c)
+StateButton::set_visual_state (int n)
{
- colors = c;
- current_state++; // to force transition
- set_state (current_state - 1);
+ if (!have_saved_bg) {
+ /* not yet realized */
+ visual_state = n;
+ return;
+ }
+
+ if (n == visual_state) {
+ return;
+ }
+
+ if (n == 0) {
+
+ /* back to the default color */
+
+ if (have_saved_bg) {
+ bg_modify (STATE_NORMAL, saved_bg);
+ bg_modify (STATE_ACTIVE, saved_bg);
+ bg_modify (STATE_SELECTED, saved_bg);
+ bg_modify (STATE_PRELIGHT, saved_bg);
+ }
+
+
+ } else {
+
+ int index = (n-1) % colors.size ();
+
+ bg_modify (STATE_NORMAL, colors[index]);
+ bg_modify (STATE_ACTIVE, colors[index]);
+ bg_modify (STATE_SELECTED, colors[index]);
+ bg_modify (STATE_PRELIGHT, colors[index]);
+ }
+
+ visual_state = n;
}
+/* ----------------------------------------------------------------- */
+
void
-StatefulButton::on_realize ()
+StatefulToggleButton::on_realize ()
{
- Button::on_realize ();
+ ToggleButton::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);
+ visual_state++; // to force transition
+ set_visual_state (visual_state - 1);
}
void
-StatefulButton::set_state (int n)
+StatefulButton::on_realize ()
{
- if (is_realized()) {
+ Button::on_realize ();
- 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);
- }
-
-
- } 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]);
- }
-
- /* leave insensitive alone */
+ if (!have_saved_bg) {
+ saved_bg = get_style()->get_bg (STATE_NORMAL);
+ have_saved_bg = true;
}
- current_state = n;
+ visual_state++; // to force transition
+ set_visual_state (visual_state - 1);
+}
+
+void
+StatefulToggleButton::on_toggled ()
+{
+ if (get_active()) {
+ set_visual_state (1);
+ } else {
+ set_visual_state (0);
+ }
+
}