1
// Button.cc for FbTk - fluxbox toolkit
2
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
4
// Permission is hereby granted, free of charge, to any person obtaining a
5
// copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
// DEALINGS IN THE SOFTWARE.
22
// $Id: Button.cc 3933 2005-04-13 14:39:25Z simonb $
27
#include "EventManager.hh"
32
Button::Button(int screen_num, int x, int y,
33
unsigned int width, unsigned int height):
34
FbWindow(screen_num, x, y, width, height,
35
ExposureMask | ButtonPressMask | ButtonReleaseMask),
39
m_gc(DefaultGC(FbTk::App::instance()->display(), screen_num)),
42
// add this to eventmanager
43
FbTk::EventManager::instance()->add(*this, *this);
46
Button::Button(const FbWindow &parent, int x, int y,
47
unsigned int width, unsigned int height):
48
FbWindow(parent, x, y, width, height,
49
ExposureMask | ButtonPressMask | ButtonReleaseMask),
53
m_gc(DefaultGC(FbTk::App::instance()->display(), screenNumber())),
55
// add this to eventmanager
56
FbTk::EventManager::instance()->add(*this, *this);
63
void Button::setOnClick(RefCount<Command> &cmd, int button) {
64
// we only handle buttons 1 to 5
65
if (button > 5 || button == 0)
67
//set on click command for the button
68
m_onclick[button - 1] = cmd;
71
void Button::setPressedPixmap(Pixmap pm) {
75
void Button::setPressedColor(const FbTk::Color &color) {
77
m_pressed_color = color;
80
void Button::setBackgroundColor(const Color &color) {
81
m_background_pm = 0; // we're using background color now
82
m_background_color = color;
83
FbTk::FbWindow::setBackgroundColor(color);
86
void Button::setBackgroundPixmap(Pixmap pm) {
88
FbTk::FbWindow::setBackgroundPixmap(pm);
91
void Button::buttonPressEvent(XButtonEvent &event) {
93
if (m_pressed_pm != 0) {
95
FbTk::FbWindow::setBackgroundPixmap(m_pressed_pm);
96
} else if (m_pressed_color.isAllocated()) {
98
FbTk::FbWindow::setBackgroundColor(m_pressed_color);
107
void Button::buttonReleaseEvent(XButtonEvent &event) {
110
if (m_background_pm) {
111
if (m_pressed_pm != 0) {
113
setBackgroundPixmap(m_background_pm);
115
} else if (m_pressed_color.isAllocated()) {
117
setBackgroundColor(m_background_color);
121
clear(); // clear background
123
// finaly, execute command (this must be done last since this object might be deleted by the command)
124
if (event.button > 0 && event.button <= 5 &&
125
event.x > 0 && event.x < static_cast<signed>(width()) &&
126
event.y > 0 && event.y < static_cast<signed>(height()) &&
127
m_onclick[event.button -1].get() != 0)
128
m_onclick[event.button - 1]->execute();
133
void Button::exposeEvent(XExposeEvent &event) {
134
clearArea(event.x, event.y, event.width, event.height);
137
}; // end namespace FbTk