aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Button.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/Button.cc')
-rw-r--r--src/FbTk/Button.cc132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/FbTk/Button.cc b/src/FbTk/Button.cc
new file mode 100644
index 0000000..ed1a920
--- /dev/null
+++ b/src/FbTk/Button.cc
@@ -0,0 +1,132 @@
1// Button.cc for FbTk - fluxbox toolkit
2// Copyright (c) 2002-2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3//
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:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
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.
21
22// $Id: Button.cc,v 1.12 2003/08/15 13:58:56 fluxgen Exp $
23
24#include "Button.hh"
25
26#include "Command.hh"
27#include "EventManager.hh"
28#include "App.hh"
29
30namespace FbTk {
31
32Button::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),
36 m_foreground_pm(0),
37 m_background_pm(0),
38 m_pressed_pm(0),
39 m_gc(DefaultGC(FbTk::App::instance()->display(), screen_num)),
40 m_pressed(false) {
41
42 // add this to eventmanager
43 FbTk::EventManager::instance()->add(*this, *this);
44}
45
46Button::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),
50 m_foreground_pm(0),
51 m_background_pm(0),
52 m_pressed_pm(0),
53 m_gc(DefaultGC(FbTk::App::instance()->display(), screenNumber())),
54 m_pressed(false) {
55 // add this to eventmanager
56 FbTk::EventManager::instance()->add(*this, *this);
57}
58
59Button::~Button() {
60 FbTk::EventManager::instance()->remove(*this);
61}
62
63void Button::setOnClick(RefCount<Command> &cmd, int button) {
64 // we only handle buttons 1 to 5
65 if (button > 5 || button == 0)
66 return;
67 //set on click command for the button
68 m_onclick[button - 1] = cmd;
69}
70
71void Button::setPixmap(Pixmap pm) {
72 m_foreground_pm = pm;
73}
74
75void Button::setPressedPixmap(Pixmap pm) {
76 m_pressed_pm = pm;
77}
78
79void Button::setBackgroundColor(const Color &color) {
80 m_background_color = color;
81 FbTk::FbWindow::setBackgroundColor(color);
82}
83
84void Button::setBackgroundPixmap(Pixmap pm) {
85 m_background_pm = pm;
86 FbTk::FbWindow::setBackgroundPixmap(pm);
87}
88
89void Button::buttonPressEvent(XButtonEvent &event) {
90 if (m_pressed_pm != 0)
91 FbWindow::setBackgroundPixmap(m_pressed_pm);
92 m_pressed = true;
93 clear();
94 FbWindow::updateTransparent();
95}
96
97void Button::buttonReleaseEvent(XButtonEvent &event) {
98 m_pressed = false;
99 if (m_background_pm)
100 FbWindow::setBackgroundPixmap(m_background_pm);
101 else
102 FbWindow::setBackgroundColor(m_background_color);
103
104 clear(); // clear background
105
106 if (m_foreground_pm) { // draw foreground pixmap
107 Display *disp = App::instance()->display();
108
109 if (m_gc == 0) // get default gc if we dont have one
110 m_gc = DefaultGC(disp, screenNumber());
111
112 XCopyArea(disp, m_foreground_pm, window(), m_gc, 0, 0, width(), height(), 0, 0);
113 }
114
115 if (event.button > 0 && event.button <= 5 &&
116 m_onclick[event.button -1].get() != 0)
117 m_onclick[event.button - 1]->execute();
118
119 FbWindow::updateTransparent();
120}
121
122void Button::exposeEvent(XExposeEvent &event) {
123 if (m_background_pm)
124 FbWindow::setBackgroundPixmap(m_background_pm);
125 else
126 FbWindow::setBackgroundColor(m_background_color);
127
128 clear();
129 FbWindow::updateTransparent(event.x, event.y, event.width, event.height);
130}
131
132}; // end namespace FbTk