button.h

Go to the documentation of this file.
00001 /*
00002   libwt - Vassilis Virvilis Toolkit - a widget library
00003   Copyright (C) 2006 Vassilis Virvilis <vasvir2@fastmail.fm>
00004  
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014   
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the
00017   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018   Boston, MA  02111-1307, SA.
00019 */
00020 
00021 #ifndef WT_BUTTON_H
00022 #define WT_BUTTON_H
00023 
00024 #include <wt/widget.h>
00025 #include <wt/sound.h>
00026 
00027 namespace Wt {
00028 
00029 //! \todo implement button groups
00030 class ButtonGroup {
00031 public:
00032 };
00033 
00034 /** Button Class
00035 */
00036 class Button : public Widget {
00037 public:
00038     Button(Widget *parent = 0, const std::string &name = "Button::anon", int wflags = 0);
00039     const std::string& text() const {
00040         return text_;
00041     }
00042     virtual void setText(const std::string &text);
00043 
00044     const Pixmap& pixmap() const {
00045         return pixmap_;
00046     }
00047     virtual void setPixmap(const Pixmap& pixmap);
00048 
00049     void setSound(const Sound& click_snd = Sound());
00050 
00051     bool isExclusiveToggle() const;
00052     ButtonGroup *group() const;
00053 
00054     void animateClick();
00055 
00056     //Signals
00057     sigc::signal<void> pressed;
00058     sigc::signal<void> canceled;
00059     sigc::signal<void> released;
00060     sigc::signal<void> clicked;
00061 
00062 protected:
00063     virtual bool hitButton(const Point &pos) const;
00064     virtual void draw(Painter *p, const Region& region);
00065     virtual void drawButton(Painter *p) = 0;
00066     virtual void drawButtonLabel(Painter *p) = 0;
00067 
00068     virtual void mousePressEvent(MouseEvent *);
00069     virtual void mouseReleaseEvent(MouseEvent *);
00070     virtual void focusInEvent(FocusEvent *);
00071     virtual void focusOutEvent(FocusEvent *);
00072     virtual void keyPressEvent(KeyEvent *);
00073     virtual void keyReleaseEvent(KeyEvent *);
00074     virtual void enterEvent(Event *);
00075     virtual void leaveEvent(Event *);
00076 
00077     virtual void setButtonSize() = 0;
00078 
00079     //reimplementation from Widget::update()
00080     void update();
00081 
00082     //button specific events
00083     virtual void buttonPressEvent();
00084     virtual void buttonCancelEvent();
00085     virtual void buttonReleaseEvent();
00086     virtual void buttonClickEvent();
00087 
00088 private:
00089     void init();
00090 
00091     std::string text_;
00092     Pixmap pixmap_;
00093     bool mousepress_in;
00094     bool keypress_in;
00095     Sound click_snd;
00096 };
00097 
00098 } // namespace Wt
00099 
00100 #endif // WT_BUTTON_H

Generated Fri Jul 28 19:22:59 2006.
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.