+/*
+ Copyright (C) 2000-2007 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.
+
+*/
+
#include <string>
#include <iostream>
using namespace Gtkmm2ext;
using namespace std;
-StateButton::StateButton ()
+StateButton::StateButton () : visual_state (0), _self_managed (false), _is_realized (false)
{
- visual_state = 0;
- have_saved_bg = false;
-}
-
-void
-StateButton::set_colors (const vector<Gdk::Color>& c)
-{
- colors = c;
- visual_state++; // to force transition
- set_visual_state (visual_state - 1);
+
}
void
StateButton::set_visual_state (int n)
{
- if (!have_saved_bg) {
+ if (!_is_realized) {
/* 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]);
+
+ 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;
}
{
ToggleButton::on_realize ();
- if (!have_saved_bg) {
- saved_bg = get_style()->get_bg (STATE_NORMAL);
- have_saved_bg = true;
- }
-
+ _is_realized = true;
visual_state++; // to force transition
set_visual_state (visual_state - 1);
}
{
Button::on_realize ();
- if (!have_saved_bg) {
- saved_bg = get_style()->get_bg (STATE_NORMAL);
- have_saved_bg = true;
- }
-
+ _is_realized = true;
visual_state++; // to force transition
set_visual_state (visual_state - 1);
}