2005-12-21 16:37:18 -05:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
2007-02-08 22:36:00 -05:00
|
|
|
|
|
|
|
#include <gtkmm/main.h>
|
|
|
|
|
|
|
|
#include <gtkmm2ext/stateful_button.h>
|
2005-12-21 16:37:18 -05:00
|
|
|
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Glib;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace std;
|
|
|
|
|
2007-02-08 22:36:00 -05:00
|
|
|
StateButton::StateButton ()
|
2005-12-21 16:37:18 -05:00
|
|
|
{
|
2007-02-13 09:25:17 -05:00
|
|
|
_is_realized = false;
|
2007-02-08 22:36:00 -05:00
|
|
|
visual_state = 0;
|
2005-12-21 16:37:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-02-08 22:36:00 -05:00
|
|
|
StateButton::set_visual_state (int n)
|
2005-12-21 16:37:18 -05:00
|
|
|
{
|
2007-02-13 09:25:17 -05:00
|
|
|
if (!_is_realized) {
|
2007-02-08 22:36:00 -05:00
|
|
|
/* not yet realized */
|
|
|
|
visual_state = n;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == visual_state) {
|
|
|
|
return;
|
|
|
|
}
|
2007-02-13 09:25:17 -05:00
|
|
|
|
|
|
|
string name = get_widget_name ();
|
|
|
|
name = name.substr (0, name.find_last_of ('-'));
|
2007-02-08 22:36:00 -05:00
|
|
|
|
2007-02-13 09:25:17 -05:00
|
|
|
switch (n) {
|
|
|
|
case 0:
|
2007-02-13 11:20:11 -05:00
|
|
|
/* relax */
|
2007-02-13 09:25:17 -05:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
name += "-active";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
name += "-alternate";
|
|
|
|
break;
|
2007-02-08 22:36:00 -05:00
|
|
|
}
|
2007-02-13 11:20:11 -05:00
|
|
|
|
2007-02-13 09:25:17 -05:00
|
|
|
set_widget_name (name);
|
2007-02-08 22:36:00 -05:00
|
|
|
visual_state = n;
|
2005-12-21 16:37:18 -05:00
|
|
|
}
|
|
|
|
|
2007-02-08 22:36:00 -05:00
|
|
|
/* ----------------------------------------------------------------- */
|
|
|
|
|
2005-12-21 16:37:18 -05:00
|
|
|
void
|
2007-02-08 22:36:00 -05:00
|
|
|
StatefulToggleButton::on_realize ()
|
2005-12-21 16:37:18 -05:00
|
|
|
{
|
2007-02-08 22:36:00 -05:00
|
|
|
ToggleButton::on_realize ();
|
2005-12-21 16:37:18 -05:00
|
|
|
|
2007-02-13 09:25:17 -05:00
|
|
|
_is_realized = true;
|
2007-02-08 22:36:00 -05:00
|
|
|
visual_state++; // to force transition
|
|
|
|
set_visual_state (visual_state - 1);
|
2005-12-21 16:37:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-02-08 22:36:00 -05:00
|
|
|
StatefulButton::on_realize ()
|
2005-12-21 16:37:18 -05:00
|
|
|
{
|
2007-02-08 22:36:00 -05:00
|
|
|
Button::on_realize ();
|
2005-12-21 16:37:18 -05:00
|
|
|
|
2007-02-13 09:25:17 -05:00
|
|
|
_is_realized = true;
|
2007-02-08 22:36:00 -05:00
|
|
|
visual_state++; // to force transition
|
|
|
|
set_visual_state (visual_state - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StatefulToggleButton::on_toggled ()
|
|
|
|
{
|
2007-02-11 17:44:55 -05:00
|
|
|
if (!_self_managed) {
|
|
|
|
if (get_active()) {
|
|
|
|
set_visual_state (1);
|
|
|
|
} else {
|
|
|
|
set_visual_state (0);
|
|
|
|
}
|
2007-02-08 22:36:00 -05:00
|
|
|
}
|
2005-12-21 16:37:18 -05:00
|
|
|
}
|