summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-12-13 20:24:33 (GMT)
committerfluxgen <fluxgen>2002-12-13 20:24:33 (GMT)
commit560e8bdd6a1cc519d29306cec65f58f70eff0375 (patch)
treeef9b369b05c879f2839428482af6a31c3d15df69
parent3d8a063bd02a6c42414e202cce81be27415d1abb (diff)
downloadfluxbox_lack-560e8bdd6a1cc519d29306cec65f58f70eff0375.zip
fluxbox_lack-560e8bdd6a1cc519d29306cec65f58f70eff0375.tar.bz2
button
-rw-r--r--src/FbTk/Button.cc115
-rw-r--r--src/FbTk/Button.hh98
2 files changed, 213 insertions, 0 deletions
diff --git a/src/FbTk/Button.cc b/src/FbTk/Button.cc
new file mode 100644
index 0000000..9ea99ed
--- /dev/null
+++ b/src/FbTk/Button.cc
@@ -0,0 +1,115 @@
1// Button.cc for FbTk - fluxbox toolkit
2// Copyright (c) 2002 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.1 2002/12/13 20:24:33 fluxgen Exp $
23
24#include "Button.hh"
25
26#include "Command.hh"
27#include "EventManager.hh"
28
29namespace FbTk {
30
31Button::Button(int screen_num, int x, int y,
32 unsigned int width, unsigned int height):
33 m_win(screen_num, x, y, width, height,
34 ExposureMask | ButtonPressMask | ButtonReleaseMask),
35 m_foreground_pm(0),
36 m_pressed_pm(0),
37 m_gc(0) {
38 // add this to eventmanager
39 FbTk::EventManager::instance()->add(*this, m_win);
40}
41
42Button::Button(FbWindow &parent, int x, int y,
43 size_t width, size_t height):
44 m_win(parent, x, y, width, height,
45 ExposureMask | ButtonPressMask | ButtonReleaseMask),
46 m_foreground_pm(0),
47 m_pressed_pm(0),
48 m_gc(0) {
49 // add this to eventmanager
50 FbTk::EventManager::instance()->add(*this, m_win);
51}
52
53Button::~Button() {
54 FbTk::EventManager::instance()->remove(m_win);
55}
56
57void Button::move(int x, int y) {
58 m_win.move(x, y);
59}
60
61void Button::resize(unsigned int w, unsigned int h) {
62 m_win.resize(w, h);
63}
64
65void Button::moveResize(int x, int y, unsigned int width, unsigned int height) {
66 m_win.moveResize(x, y, width, height);
67}
68
69void Button::setPixmap(Pixmap pm) {
70 m_foreground_pm = pm;
71}
72
73void Button::setPressedPixmap(Pixmap pm) {
74 m_pressed_pm = pm;
75}
76
77void Button::setBackgroundColor(const Color &color) {
78 m_win.setBackgroundColor(color);
79}
80
81void Button::setBackgroundPixmap(Pixmap pm) {
82 m_win.setBackgroundPixmap(pm);
83 m_foreground_pm = pm;
84}
85
86void Button::show() {
87 m_win.show();
88}
89
90void Button::hide() {
91 m_win.hide();
92}
93
94void Button::buttonPressEvent(XButtonEvent &event) {
95 m_win.setBackgroundPixmap(m_pressed_pm);
96 m_win.clear();
97 m_pressed = true;
98}
99
100void Button::buttonReleaseEvent(XButtonEvent &event) {
101 // set normal pixmap
102 m_win.setBackgroundPixmap(m_foreground_pm);
103 m_win.clear();
104
105 if (*m_onclick != 0) // check on click action
106 m_onclick->execute(); // do on click action
107
108 m_pressed = false;
109}
110
111void Button::exposeEvent(XExposeEvent &event) {
112 m_win.clear();
113}
114
115}; // end namespace FbTk
diff --git a/src/FbTk/Button.hh b/src/FbTk/Button.hh
new file mode 100644
index 0000000..5d0842d
--- /dev/null
+++ b/src/FbTk/Button.hh
@@ -0,0 +1,98 @@
1// Button.hh for FbTk - Fluxbox Toolkit
2// Copyright (c) 2002 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.hh,v 1.1 2002/12/13 20:24:33 fluxgen Exp $
23
24#ifndef FBTK_BUTTON_HH
25#define FBTK_BUTTON_HH
26
27#include "EventHandler.hh"
28#include "NotCopyable.hh"
29#include "RefCount.hh"
30#include "FbWindow.hh"
31#include "Command.hh"
32
33#include <X11/Xlib.h>
34#include <memory>
35
36namespace FbTk {
37
38class Color;
39
40class Button:public EventHandler,
41 private NotCopyable {
42public:
43 Button(int screen_num, int x, int y, unsigned int width, unsigned int height);
44 Button(FbWindow &parent, int x, int y, unsigned int width, unsigned int height);
45 virtual ~Button();
46 /// sets action when the button is clicked
47 void setOnClick(RefCount<Command> &com) { m_onclick = com; }
48 void move(int x, int y);
49 void resize(unsigned int width, unsigned int height);
50 void moveResize(int x, int y, unsigned int width, unsigned int height);
51 /// sets the pixmap to be viewd when the button is in normal state (ie not pressed)
52 void setPixmap(Pixmap pm);
53 /// sets the pixmap to be viewed when the button is pressed
54 void setPressedPixmap(Pixmap pm);
55 void setGC(GC gc) { m_gc = gc; }
56 /// sets background pixmap, this will override background color
57 void setBackgroundPixmap(Pixmap pm);
58 /// sets background color
59 void setBackgroundColor(const Color &color);
60 /// show button
61 void show();
62 /// hide button
63 void hide();
64 virtual void clear() { m_win.clear(); }
65 /**
66 @name eventhandlers
67 */
68 //@{
69 virtual void buttonPressEvent(XButtonEvent &event);
70 virtual void buttonReleaseEvent(XButtonEvent &event);
71 virtual void exposeEvent(XExposeEvent &event);
72 //@}
73 /// @return true if the button is pressed, else false
74 bool pressed() const { return m_pressed; }
75 /**
76 @name position and size of the button
77 */
78 //@{
79 int x() const { return m_win.x(); }
80 int y() const { return m_win.y(); }
81 unsigned int width() const { return m_win.width(); }
82 unsigned int height() const { return m_win.height(); }
83 //@}
84 FbWindow &window() { return m_win; }
85 const FbWindow &window() const { return m_win; }
86 GC gc() const { return m_gc; }
87private:
88 FbTk::FbWindow m_win; ///< window for button
89 Pixmap m_foreground_pm; ///< foreground pixmap
90 Pixmap m_pressed_pm; ///< pressed pixmap
91 GC m_gc; ///< graphic context for button
92 bool m_pressed; ///< if the button is pressed
93 RefCount<Command> m_onclick; ///< what to do when this button is clicked
94};
95
96};
97
98#endif // FBTK_BUTTON_HH