summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/Button.cc66
-rw-r--r--src/FbTk/Button.hh27
2 files changed, 25 insertions, 68 deletions
diff --git a/src/FbTk/Button.cc b/src/FbTk/Button.cc
index 8b0a478..f7acb09 100644
--- a/src/FbTk/Button.cc
+++ b/src/FbTk/Button.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: Button.cc,v 1.10 2003/08/11 14:40:15 fluxgen Exp $ 22// $Id: Button.cc,v 1.11 2003/08/13 09:25:16 fluxgen Exp $
23 23
24#include "Button.hh" 24#include "Button.hh"
25 25
@@ -31,8 +31,8 @@ namespace FbTk {
31 31
32Button::Button(int screen_num, int x, int y, 32Button::Button(int screen_num, int x, int y,
33 unsigned int width, unsigned int height): 33 unsigned int width, unsigned int height):
34 m_win(screen_num, x, y, width, height, 34 FbWindow(screen_num, x, y, width, height,
35 ExposureMask | ButtonPressMask | ButtonReleaseMask), 35 ExposureMask | ButtonPressMask | ButtonReleaseMask),
36 m_foreground_pm(0), 36 m_foreground_pm(0),
37 m_background_pm(0), 37 m_background_pm(0),
38 m_pressed_pm(0), 38 m_pressed_pm(0),
@@ -40,24 +40,24 @@ Button::Button(int screen_num, int x, int y,
40 m_pressed(false) { 40 m_pressed(false) {
41 41
42 // add this to eventmanager 42 // add this to eventmanager
43 FbTk::EventManager::instance()->add(*this, m_win); 43 FbTk::EventManager::instance()->add(*this, *this);
44} 44}
45 45
46Button::Button(const FbWindow &parent, int x, int y, 46Button::Button(const FbWindow &parent, int x, int y,
47 unsigned int width, unsigned int height): 47 unsigned int width, unsigned int height):
48 m_win(parent, x, y, width, height, 48 FbWindow(parent, x, y, width, height,
49 ExposureMask | ButtonPressMask | ButtonReleaseMask), 49 ExposureMask | ButtonPressMask | ButtonReleaseMask),
50 m_foreground_pm(0), 50 m_foreground_pm(0),
51 m_background_pm(0), 51 m_background_pm(0),
52 m_pressed_pm(0), 52 m_pressed_pm(0),
53 m_gc(DefaultGC(FbTk::App::instance()->display(), m_win.screenNumber())), 53 m_gc(DefaultGC(FbTk::App::instance()->display(), screenNumber())),
54 m_pressed(false) { 54 m_pressed(false) {
55 // add this to eventmanager 55 // add this to eventmanager
56 FbTk::EventManager::instance()->add(*this, m_win); 56 FbTk::EventManager::instance()->add(*this, *this);
57} 57}
58 58
59Button::~Button() { 59Button::~Button() {
60 FbTk::EventManager::instance()->remove(m_win); 60 FbTk::EventManager::instance()->remove(*this);
61} 61}
62 62
63void Button::setOnClick(RefCount<Command> &cmd, int button) { 63void Button::setOnClick(RefCount<Command> &cmd, int button) {
@@ -68,18 +68,6 @@ void Button::setOnClick(RefCount<Command> &cmd, int button) {
68 m_onclick[button - 1] = cmd; 68 m_onclick[button - 1] = cmd;
69} 69}
70 70
71void Button::move(int x, int y) {
72 window().move(x, y);
73}
74
75void Button::resize(unsigned int w, unsigned int h) {
76 window().resize(w, h);
77}
78
79void Button::moveResize(int x, int y, unsigned int width, unsigned int height) {
80 window().moveResize(x, y, width, height);
81}
82
83void Button::setPixmap(Pixmap pm) { 71void Button::setPixmap(Pixmap pm) {
84 m_foreground_pm = pm; 72 m_foreground_pm = pm;
85} 73}
@@ -90,40 +78,28 @@ void Button::setPressedPixmap(Pixmap pm) {
90 78
91void Button::setBackgroundColor(const Color &color) { 79void Button::setBackgroundColor(const Color &color) {
92 m_background_color = color; 80 m_background_color = color;
93 window().setBackgroundColor(color); 81 FbTk::FbWindow::setBackgroundColor(color);
94 clear();
95 window().updateTransparent();
96} 82}
97 83
98void Button::setBackgroundPixmap(Pixmap pm) { 84void Button::setBackgroundPixmap(Pixmap pm) {
99 m_background_pm = pm; 85 m_background_pm = pm;
100 window().setBackgroundPixmap(pm); 86 FbTk::FbWindow::setBackgroundPixmap(pm);
101 clear();
102 window().updateTransparent();
103}
104
105void Button::show() {
106 m_win.show();
107}
108
109void Button::hide() {
110 m_win.hide();
111} 87}
112 88
113void Button::buttonPressEvent(XButtonEvent &event) { 89void Button::buttonPressEvent(XButtonEvent &event) {
114 if (m_pressed_pm != 0) 90 if (m_pressed_pm != 0)
115 m_win.setBackgroundPixmap(m_pressed_pm); 91 FbWindow::setBackgroundPixmap(m_pressed_pm);
116 m_pressed = true; 92 m_pressed = true;
117 clear(); 93 clear();
118 window().updateTransparent(); 94 FbWindow::updateTransparent();
119} 95}
120 96
121void Button::buttonReleaseEvent(XButtonEvent &event) { 97void Button::buttonReleaseEvent(XButtonEvent &event) {
122 m_pressed = false; 98 m_pressed = false;
123 if (m_background_pm) 99 if (m_background_pm)
124 m_win.setBackgroundPixmap(m_background_pm); 100 FbWindow::setBackgroundPixmap(m_background_pm);
125 else 101 else
126 m_win.setBackgroundColor(m_background_color); 102 FbWindow::setBackgroundColor(m_background_color);
127 103
128 clear(); // clear background 104 clear(); // clear background
129 105
@@ -131,26 +107,26 @@ void Button::buttonReleaseEvent(XButtonEvent &event) {
131 Display *disp = App::instance()->display(); 107 Display *disp = App::instance()->display();
132 108
133 if (m_gc == 0) // get default gc if we dont have one 109 if (m_gc == 0) // get default gc if we dont have one
134 m_gc = DefaultGC(disp, m_win.screenNumber()); 110 m_gc = DefaultGC(disp, screenNumber());
135 111
136 XCopyArea(disp, m_foreground_pm, m_win.window(), m_gc, 0, 0, width(), height(), 0, 0); 112 XCopyArea(disp, m_foreground_pm, window(), m_gc, 0, 0, width(), height(), 0, 0);
137 } 113 }
138 114
139 if (event.button > 0 && event.button <= 5 && 115 if (event.button > 0 && event.button <= 5 &&
140 m_onclick[event.button -1].get() != 0) 116 m_onclick[event.button -1].get() != 0)
141 m_onclick[event.button - 1]->execute(); 117 m_onclick[event.button - 1]->execute();
142 118
143 window().updateTransparent(); 119 FbWindow::updateTransparent();
144} 120}
145 121
146void Button::exposeEvent(XExposeEvent &event) { 122void Button::exposeEvent(XExposeEvent &event) {
147 if (m_background_pm) 123 if (m_background_pm)
148 m_win.setBackgroundPixmap(m_background_pm); 124 FbWindow::setBackgroundPixmap(m_background_pm);
149 else 125 else
150 m_win.setBackgroundColor(m_background_color); 126 FbWindow::setBackgroundColor(m_background_color);
151 127
152 clear(); 128 clear();
153 window().updateTransparent(event.x, event.y, event.width, event.height); 129 FbWindow::updateTransparent(event.x, event.y, event.width, event.height);
154} 130}
155 131
156}; // end namespace FbTk 132}; // end namespace FbTk
diff --git a/src/FbTk/Button.hh b/src/FbTk/Button.hh
index 80f8663..8aaf561 100644
--- a/src/FbTk/Button.hh
+++ b/src/FbTk/Button.hh
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: Button.hh,v 1.4 2003/04/28 22:22:25 fluxgen Exp $ 22// $Id: Button.hh,v 1.5 2003/08/13 09:25:16 fluxgen Exp $
23 23
24#ifndef FBTK_BUTTON_HH 24#ifndef FBTK_BUTTON_HH
25#define FBTK_BUTTON_HH 25#define FBTK_BUTTON_HH
@@ -36,7 +36,7 @@
36 36
37namespace FbTk { 37namespace FbTk {
38 38
39class Button:public EventHandler, 39class Button:public FbTk::FbWindow, public EventHandler,
40 private NotCopyable { 40 private NotCopyable {
41public: 41public:
42 Button(int screen_num, int x, int y, unsigned int width, unsigned int height); 42 Button(int screen_num, int x, int y, unsigned int width, unsigned int height);
@@ -46,10 +46,6 @@ public:
46 /// sets action when the button is clicked with #button mouse btn 46 /// sets action when the button is clicked with #button mouse btn
47 void setOnClick(RefCount<Command> &com, int button = 1); 47 void setOnClick(RefCount<Command> &com, int button = 1);
48 48
49 virtual void move(int x, int y);
50 virtual void resize(unsigned int width, unsigned int height);
51 virtual void moveResize(int x, int y, unsigned int width, unsigned int height);
52
53 /// sets foreground pixmap 49 /// sets foreground pixmap
54 void setPixmap(Pixmap pm); 50 void setPixmap(Pixmap pm);
55 /// sets the pixmap to be viewed when the button is pressed 51 /// sets the pixmap to be viewed when the button is pressed
@@ -60,11 +56,7 @@ public:
60 void setBackgroundPixmap(Pixmap pm); 56 void setBackgroundPixmap(Pixmap pm);
61 /// sets background color 57 /// sets background color
62 void setBackgroundColor(const Color &color); 58 void setBackgroundColor(const Color &color);
63 /// show button 59
64 void show();
65 /// hide button
66 void hide();
67 virtual void clear() { m_win.clear(); }
68 /** 60 /**
69 @name eventhandlers 61 @name eventhandlers
70 */ 62 */
@@ -76,21 +68,10 @@ public:
76 68
77 /// @return true if the button is pressed, else false 69 /// @return true if the button is pressed, else false
78 bool pressed() const { return m_pressed; } 70 bool pressed() const { return m_pressed; }
79 /** 71
80 @name position and size of the button
81 */
82 //@{
83 int x() const { return m_win.x(); }
84 int y() const { return m_win.y(); }
85 unsigned int width() const { return m_win.width(); }
86 unsigned int height() const { return m_win.height(); }
87 //@}
88 FbWindow &window() { return m_win; }
89 const FbWindow &window() const { return m_win; }
90 GC gc() const { return m_gc; } 72 GC gc() const { return m_gc; }
91 73
92private: 74private:
93 FbTk::FbWindow m_win; ///< window for button
94 Pixmap m_foreground_pm; ///< foreground pixmap 75 Pixmap m_foreground_pm; ///< foreground pixmap
95 Pixmap m_background_pm; ///< background pixmap 76 Pixmap m_background_pm; ///< background pixmap
96 Color m_background_color; ///< background color 77 Color m_background_color; ///< background color