openbox/otk/button.cc

82 lines
1.7 KiB
C++
Raw Normal View History

// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif
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
{
setStyle(getStyle());
}
OtkButton::~OtkButton()
{
}
void OtkButton::setStyle(Style *style)
{
OtkFocusLabel::setStyle(style);
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
}
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
}
void OtkButton::buttonPressHandler(const XButtonEvent &e)
{
2002-11-16 13:21:24 +00:00
press(e.button);
update();
OtkFocusWidget::buttonPressHandler(e);
}
void OtkButton::buttonReleaseHandler(const XButtonEvent &e)
{
2002-11-16 13:21:24 +00:00
release(e.button);
update();
OtkFocusWidget::buttonReleaseHandler(e);
}
2002-11-11 03:47:12 +00:00
}