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

widget.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 _WIDGET_H
00023 #define _WIDGET_H
00024 
00025 #include <list>
00026 #include <sigc++/object.h>
00027 #if SIGC_MAJOR_VERSION == 1 && SIGC_MINOR_VERSION == 0
00028 #include <sigc++/signal_system.h>
00029 #else
00030 #include <sigc++/signal.h>
00031 #endif
00032 
00033 #include <wftk/rect.h>
00034 #include <wftk/screenarea.h>
00035 #include <wftk/color.h>
00036 #include <wftk/surface.h>
00037 #include <wftk/focus.h>
00038 
00039 namespace wftk {
00040 
00043 class Widget : public ScreenArea, virtual public SigC::Object
00044 {
00045  public:
00047   Widget();
00049   explicit Widget(const Surface& backgrnd, bool tileIt = true);
00051   explicit Widget(Surface::Resource* backgrnd, bool tileIt = true);
00054   explicit Widget(const std::string& backgrnd, bool tileIt = true);
00056   virtual ~Widget();
00057 
00059   void setBackground(const Surface& backgrnd, bool tileIt = true);
00061   void setBackground(Surface::Resource* backgrnd, bool tileIt = true);
00063   void setBackground(const std::string&, bool tileIt = true);
00065   void clearBackground() {setBackground(0);}
00067   Surface::Resource* getResourceBackground() const {return backgrnd_;}
00068 
00070   void setColor(const Color &color);
00072   void setColor(const std::string&);
00074   void setColor(const char* name) {setColor(std::string(name));}
00075 
00077   void setDisabledColor(const Color& color);
00079   void setDisabledColor(const std::string&);
00081   void setDisabledColor(const char* name) {setDisabledColor(std::string(name));}
00082 
00084   void enable();
00088   void disable();
00089 
00091   virtual bool mouseEvent(const Point&, const Point&, Mouse::Button) {return false;}
00093   virtual bool buttonEvent(Mouse::Button, bool pressed, const Point&)
00094     {if (activateOnClick_) checkGrabFocus(); return false;}
00096   virtual void gainedMouse() {if (activateOnMouse_) checkGrabFocus();}
00098   virtual bool keyEvent(const SDL_keysym& sym, bool pressed) {return false;}
00100   virtual void gainedFocus() {}
00102   virtual void lostFocus() {}
00103 
00105   bool isEnabled() const;
00106 
00108   const Color& color() const {return color_;}
00109 
00111   bool hasFocus() const {return Focus::instance()->currentFocus() == this;}
00113   bool releaseFocus() {return hasFocus() && Focus::instance()->grab(0);}
00115   bool grabFocus() {return acceptsFocus() && Focus::instance()->grab(this);}
00117   void setClickToFocus(bool val = true);
00119   void setPointToFocus(bool val = true);
00121   Widget* nextFocus() {return Focus::instance()->nextFocus();}
00123   Widget* prevFocus() {return Focus::instance()->prevFocus();}
00125   bool acceptsFocus() const {return activateOnClick_ || activateOnMouse_;}
00126  
00128   void getResourceBackground(const std::string&);
00129 
00130  protected: 
00131 
00132   virtual void draw(Surface&, const Point& offset, const Region&);
00133   virtual void drawAfter(Surface&, const Point& offset, const Region&);
00134 
00135   virtual void handleResize(Uint16 w, Uint16 h);
00136 
00139   virtual bool isOpaque() const;
00140 
00141   virtual void setPackingInfo();
00142 
00143  private:
00147   Surface::Resource *backgrnd_;
00149   Surface scaled_;
00151   void setScaled();
00152 
00154   Color color_;
00155 
00156   //disable bg color
00157   Color colorDis_;
00158 
00160   bool disabled_;
00161 
00163   bool tileBackground_;
00164 
00166   bool activateOnMouse_;
00168   bool activateOnClick_;
00170   void checkGrabFocus();
00171 };
00172 
00173 } // namespace wftk
00174 
00175 #endif // _WIDGET_H

Generated Fri Mar 5 08:11:00 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.