summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/gtkmm2ext/SConscript1
-rw-r--r--libs/gtkmm2ext/bindable_button.cc3
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/bindable_button.h2
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/stateful_button.h55
-rw-r--r--libs/gtkmm2ext/stateful_button.cc80
5 files changed, 138 insertions, 3 deletions
diff --git a/libs/gtkmm2ext/SConscript b/libs/gtkmm2ext/SConscript
index 91a7f6104a..9891d56dcc 100644
--- a/libs/gtkmm2ext/SConscript
+++ b/libs/gtkmm2ext/SConscript
@@ -49,6 +49,7 @@ popup.cc
prompter.cc
selector.cc
slider_controller.cc
+stateful_button.cc
tearoff.cc
textviewer.cc
utils.cc
diff --git a/libs/gtkmm2ext/bindable_button.cc b/libs/gtkmm2ext/bindable_button.cc
index fcc6093361..76b89deb02 100644
--- a/libs/gtkmm2ext/bindable_button.cc
+++ b/libs/gtkmm2ext/bindable_button.cc
@@ -32,8 +32,7 @@ using namespace Gtkmm2ext;
using namespace std;
BindableToggleButton::BindableToggleButton (MIDI::Controllable *mc)
- : ToggleButton (),
- prompter (Gtk::WIN_POS_MOUSE, 30000, false),
+ : prompter (Gtk::WIN_POS_MOUSE, 30000, false),
midi_control (mc),
bind_button (2),
bind_statemask (Gdk::CONTROL_MASK)
diff --git a/libs/gtkmm2ext/gtkmm2ext/bindable_button.h b/libs/gtkmm2ext/gtkmm2ext/bindable_button.h
index 11f5ab45e7..4b97403eee 100644
--- a/libs/gtkmm2ext/gtkmm2ext/bindable_button.h
+++ b/libs/gtkmm2ext/gtkmm2ext/bindable_button.h
@@ -21,7 +21,7 @@
#ifndef __pbd_gtkmm_bindable_button_h__
#define __pbd_gtkmm_bindable_button_h__
-#include <gtkmm.h>
+#include <gtkmm2ext/stateful_button.h>
#include <gtkmm2ext/popup.h>
diff --git a/libs/gtkmm2ext/gtkmm2ext/stateful_button.h b/libs/gtkmm2ext/gtkmm2ext/stateful_button.h
new file mode 100644
index 0000000000..227471fd01
--- /dev/null
+++ b/libs/gtkmm2ext/gtkmm2ext/stateful_button.h
@@ -0,0 +1,55 @@
+/*
+ Copyright (C) 2005 Paul Davis
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+*/
+
+#ifndef __pbd_gtkmm_abutton_h__
+#define __pbd_gtkmm_abutton_h__
+
+#include <vector>
+
+#include <gtkmm/togglebutton.h>
+
+namespace Gtkmm2ext {
+
+class StatefulButton : public Gtk::Button
+{
+ public:
+ StatefulButton();
+ explicit StatefulButton(const std::string &label);
+ virtual ~StatefulButton() {}
+
+ void set_colors (const std::vector<Gdk::Color>& colors);
+ void set_state (int);
+ int get_state () { return current_state; }
+ void set_active (bool yn) {
+ set_state (yn ? 1 : 0);
+ }
+
+ protected:
+ std::vector<Gdk::Color> colors;
+ int current_state;
+ Gdk::Color saved_bg;
+ bool have_saved_bg;
+
+ void on_realize ();
+};
+
+};
+
+#endif
diff --git a/libs/gtkmm2ext/stateful_button.cc b/libs/gtkmm2ext/stateful_button.cc
new file mode 100644
index 0000000000..074d086651
--- /dev/null
+++ b/libs/gtkmm2ext/stateful_button.cc
@@ -0,0 +1,80 @@
+#include <string>
+#include <iostream>
+#include "gtkmm2ext/stateful_button.h"
+
+using namespace Gtk;
+using namespace Glib;
+using namespace Gtkmm2ext;
+using namespace std;
+
+StatefulButton::StatefulButton ()
+{
+ current_state = 0;
+ have_saved_bg = false;
+}
+
+StatefulButton::StatefulButton (const string& label)
+ : Button (label)
+{
+ current_state = 0;
+ have_saved_bg = false;
+}
+
+void
+StatefulButton::set_colors (const vector<Gdk::Color>& c)
+{
+ colors = c;
+ current_state++; // to force transition
+ set_state (current_state - 1);
+}
+
+void
+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);
+}
+
+void
+StatefulButton::set_state (int n)
+{
+ 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);
+ }
+
+
+ } 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 */
+ }
+
+ current_state = n;
+}