Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

button.h

00001 /* 00002 libwftk - Worldforge Toolkit - a widget library 00003 Copyright (C) 2002 Malcolm Walker <malcolm@worldforge.org> 00004 Based on code copyright (C) 1999-2002 Karsten Laux 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the 00018 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, SA. 00020 */ 00021 00022 #ifndef _BUTTON_H 00023 #define _BUTTON_H 00024 00025 #include <wftk/singlecontainer.h> 00026 #include <wftk/timer.h> 00027 #include <wftk/font.h> 00028 00029 namespace wftk { 00030 00033 class Button : public SingleContainer 00034 { 00035 //OBJECT 00036 00037 public: 00039 Button(); 00049 explicit Button(const std::string& text, 00050 const Font &font=Font::registry.find("button_font")); 00051 00052 // a signal with an overloaded connect() 00053 class ButtonSignal : public SigC::Signal0<void> 00054 { 00055 public: 00061 ButtonSignal(Button* b, const std::string& sample = "") : 00062 button_(b), sample_(sample) {} 00063 00064 SigC::Connection connect(const SigC::Slot0<void>& slot); 00065 SigC::Connection connect(const SigC::Slot1<void,Button*>& slot); 00066 00067 void operator()(); 00068 00069 private: 00070 Button* button_; 00071 std::string sample_; 00072 }; 00073 00078 ButtonSignal pressed; 00083 ButtonSignal released; 00087 ButtonSignal clicked; 00088 00095 void press(); 00102 void release(); 00108 void repeat(); 00112 void toggle(); 00113 00118 bool isPressed() const {return isPressed_;} 00123 void setRepeat(unsigned repeat = 100); 00124 00130 void setRepeat(bool repeat); 00131 00139 virtual bool buttonEvent(Mouse::Button button, bool pressed_val, 00140 const Point& pos); 00147 virtual bool keyEvent(const SDL_keysym& sym, bool pressed_val); 00153 virtual void lostMouse(); 00159 virtual void lostFocus() {isPressed_ = false;} 00160 00161 private: 00163 bool isPressed_; 00165 Timer autoRepeat_; 00166 }; 00167 00168 } // namespace wftk 00169 00170 #endif // _BUTTON_H

Generated Wed Jul 28 17:28:42 2004.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.