From 885ddd9322ea4a175e992e4a6fe757d19e8e86e2 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Wed, 25 Dec 2002 11:28:43 +0000 Subject: using number for buttons and max five buttons --- src/FbTk/Button.cc | 30 ++++++++++++------------------ src/FbTk/Button.hh | 17 ++++++----------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/FbTk/Button.cc b/src/FbTk/Button.cc index b415724..0c568a2 100644 --- a/src/FbTk/Button.cc +++ b/src/FbTk/Button.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Button.cc,v 1.2 2002/12/16 11:05:35 fluxgen Exp $ +// $Id: Button.cc,v 1.3 2002/12/25 11:27:29 fluxgen Exp $ #include "Button.hh" @@ -56,6 +56,14 @@ Button::~Button() { FbTk::EventManager::instance()->remove(m_win); } +void Button::setOnClick(RefCount &cmd, int button) { + // we only handle buttons 1 to 5 + if (button > 5 || button == 0) + return; + //set on click command for the button + m_onclick[button - 1] = cmd; +} + void Button::move(int x, int y) { m_win.move(x, y); } @@ -124,23 +132,9 @@ void Button::buttonReleaseEvent(XButtonEvent &event) { event.x > width() || event.y > height()) return; - // call commands - switch (event.button) { - case Button1: - if (*m_onclick_left != 0) - m_onclick_left->execute(); - break; - case Button2: - if (*m_onclick_middle != 0) - m_onclick_middle->execute(); - break; - case Button3: - if (*m_onclick_right != 0) - m_onclick_right->execute(); - break; - }; - - + if (event.button > 0 && event.button <= 5) + m_onclick[event.button - 1]->execute(); + } void Button::exposeEvent(XExposeEvent &event) { diff --git a/src/FbTk/Button.hh b/src/FbTk/Button.hh index c49815d..a96dcd8 100644 --- a/src/FbTk/Button.hh +++ b/src/FbTk/Button.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Button.hh,v 1.2 2002/12/16 11:02:41 fluxgen Exp $ +// $Id: Button.hh,v 1.3 2002/12/25 11:28:43 fluxgen Exp $ #ifndef FBTK_BUTTON_HH #define FBTK_BUTTON_HH @@ -41,13 +41,10 @@ class Button:public EventHandler, public: Button(int screen_num, int x, int y, unsigned int width, unsigned int height); Button(const FbWindow &parent, int x, int y, unsigned int width, unsigned int height); - virtual ~Button(); - /// sets action when the button is clicked with left mouse btn - void setOnClick(RefCount &com) { m_onclick_left = com; } - /// sets action when the button is clicked with middle mouse btn - void setOnClickMiddle(RefCount &com) { m_onclick_middle = com; } - /// sets action when the button is clicked with right mouse btn - void setOnClickRight(RefCount &com) { m_onclick_right = com; } + virtual ~Button(); + + /// sets action when the button is clicked with #button mouse btn + void setOnClick(RefCount &com, int button = 1); void move(int x, int y); void resize(unsigned int width, unsigned int height); @@ -100,9 +97,7 @@ private: Pixmap m_pressed_pm; ///< pressed pixmap GC m_gc; ///< graphic context for button bool m_pressed; ///< if the button is pressed - RefCount m_onclick_left; ///< what to do when this button is clicked with lmb - RefCount m_onclick_middle; ///< what to do when this button is clicked with mmb - RefCount m_onclick_right; ///< what to do when this button is clicked with rmb + RefCount m_onclick[5]; ///< what to do when this button is clicked with button num }; }; -- cgit v0.11.2