openbox/otk/button.cc

74 lines
1.4 KiB
C++
Raw Normal View History

// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2003-02-09 23:07:54 +00:00
#include "config.h"
2002-11-11 03:47:12 +00:00
#include "button.hh"
namespace otk {
Button::Button(Widget *parent)
: Label(parent),
_pressed(false)
2002-11-11 03:47:12 +00:00
{
setHorizontalJustify(RenderStyle::CenterJustify);
setVerticalJustify(RenderStyle::CenterJustify);
styleChanged(*RenderStyle::style(screen()));
}
Button::~Button()
{
}
void Button::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
_pressed = true;
2002-11-16 13:21:24 +00:00
_mouse_button = mouse_button;
styleChanged(*RenderStyle::style(screen()));
refresh();
2002-11-11 03:47:12 +00:00
}
void Button::release(unsigned int mouse_button)
2002-11-11 03:47:12 +00:00
{
if (!_pressed || _mouse_button != mouse_button) return; // wrong button
2002-11-16 13:21:24 +00:00
2002-11-14 11:41:50 +00:00
_pressed = false;
styleChanged(*RenderStyle::style(screen()));
refresh();
2002-11-11 03:47:12 +00:00
}
void Button::buttonPressHandler(const XButtonEvent &e)
2002-11-11 03:47:12 +00:00
{
Widget::buttonPressHandler(e);
press(e.button);
2002-11-14 11:41:50 +00:00
}
2002-11-11 03:47:12 +00:00
void Button::buttonReleaseHandler(const XButtonEvent &e)
2002-11-14 11:41:50 +00:00
{
Widget::buttonReleaseHandler(e);
release(e.button);
2002-11-11 03:47:12 +00:00
}
void Button::styleChanged(const RenderStyle &style)
{
if (isHighlighted()) {
if (_pressed)
_texture = style.buttonPressFocusBackground();
else
_texture = style.buttonUnpressFocusBackground();
_forecolor = style.buttonFocusColor();
} else {
if (_pressed)
_texture = style.buttonPressUnfocusBackground();
else
_texture = style.buttonUnpressUnfocusBackground();
_forecolor = style.buttonUnfocusColor();
}
2003-02-08 08:59:24 +00:00
refresh();
}
2002-11-11 03:47:12 +00:00
}