openbox/otk/button.cc

69 lines
1.6 KiB
C++
Raw Normal View History

2002-11-11 03:47:12 +00:00
#include "button.hh"
namespace otk {
OtkButton::OtkButton(OtkWidget *parent)
2002-11-16 13:21:24 +00:00
: OtkFocusLabel(parent), _pressed(false), _pressed_focus_tx(0),
_pressed_unfocus_tx(0), _unpr_focus_tx(0), _unpr_unfocus_tx(0)
2002-11-11 03:47:12 +00:00
{
2002-11-14 11:41:50 +00:00
setTexture(getStyle()->getButtonFocus());
setUnfocusTexture(getStyle()->getButtonUnfocus());
_pressed_focus_tx = getStyle()->getButtonPressedFocus();
_pressed_unfocus_tx = getStyle()->getButtonPressedUnfocus();
2002-11-11 03:47:12 +00:00
}
OtkButton::~OtkButton()
{
2002-11-14 11:41:50 +00:00
if (_pressed_focus_tx) delete _pressed_focus_tx;
if (_pressed_unfocus_tx) delete _pressed_unfocus_tx;
}
2002-11-11 03:47:12 +00:00
2002-11-16 13:21:24 +00:00
void OtkButton::press(unsigned int mouse_button)
2002-11-14 11:41:50 +00:00
{
2002-11-16 13:21:24 +00:00
if (_pressed) return;
2002-11-14 11:41:50 +00:00
if (_pressed_focus_tx)
OtkFocusWidget::setTexture(_pressed_focus_tx);
if (_pressed_unfocus_tx)
OtkFocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
_pressed = true;
2002-11-16 13:21:24 +00:00
_mouse_button = mouse_button;
2002-11-11 03:47:12 +00:00
}
2002-11-16 13:21:24 +00:00
void OtkButton::release(unsigned int mouse_button)
2002-11-11 03:47:12 +00:00
{
2002-11-16 13:21:24 +00:00
if (_mouse_button != mouse_button) return; // wrong button
2002-11-14 11:41:50 +00:00
OtkFocusWidget::setTexture(_unpr_focus_tx);
OtkFocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
_pressed = false;
2002-11-11 03:47:12 +00:00
}
2002-11-14 11:41:50 +00:00
void OtkButton::setTexture(BTexture *texture)
2002-11-11 03:47:12 +00:00
{
2002-11-14 11:41:50 +00:00
OtkFocusWidget::setTexture(texture);
_unpr_focus_tx = texture;
}
2002-11-11 03:47:12 +00:00
2002-11-14 11:41:50 +00:00
void OtkButton::setUnfocusTexture(BTexture *texture)
{
OtkFocusWidget::setUnfocusTexture(texture);
_unpr_unfocus_tx = texture;
2002-11-11 03:47:12 +00:00
}
int OtkButton::buttonPressHandler(const XButtonEvent &e)
{
2002-11-16 13:21:24 +00:00
press(e.button);
update();
return OtkFocusWidget::buttonPressHandler(e);
}
int OtkButton::buttonReleaseHandler(const XButtonEvent &e)
{
2002-11-16 13:21:24 +00:00
release(e.button);
update();
return OtkFocusWidget::buttonReleaseHandler(e);
}
2002-11-11 03:47:12 +00:00
}