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

widget.hpp

00001 /*      _______   __   __   __   ______   __   __   _______   __   __                 
00002  *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\                
00003  *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /                 
00004  *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /                  
00005  *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /                   
00006  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /                    
00007  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/                      
00008  *
00009  * Copyright (c) 2004, 2005 darkbits                        Js_./
00010  * Per Larsson a.k.a finalman                          _RqZ{a<^_aa
00011  * Olof Naessén a.k.a jansem/yakslem                _asww7!uY`>  )\a//
00012  *                                                 _Qhm`] _f "'c  1!5m
00013  * Visit: http://guichan.darkbits.org             )Qk<P ` _: :+' .'  "{[
00014  *                                               .)j(] .d_/ '-(  P .   S
00015  * License: (BSD)                                <Td/Z <fP"5(\"??"\a.  .L
00016  * Redistribution and use in source and          _dV>ws?a-?'      ._/L  #'
00017  * binary forms, with or without                 )4d[#7r, .   '     )d`)[
00018  * modification, are permitted provided         _Q-5'5W..j/?'   -?!\)cam'
00019  * that the following conditions are met:       j<<WP+k/);.        _W=j f
00020  * 1. Redistributions of source code must       .$%w\/]Q  . ."'  .  mj$
00021  *    retain the above copyright notice,        ]E.pYY(Q]>.   a     J@\
00022  *    this list of conditions and the           j(]1u<sE"L,. .   ./^ ]{a
00023  *    following disclaimer.                     4'_uomm\.  )L);-4     (3=
00024  * 2. Redistributions in binary form must        )_]X{Z('a_"a7'<a"a,  ]"[
00025  *    reproduce the above copyright notice,       #}<]m7`Za??4,P-"'7. ).m
00026  *    this list of conditions and the            ]d2e)Q(<Q(  ?94   b-  LQ/
00027  *    following disclaimer in the                <B!</]C)d_, '(<' .f. =C+m
00028  *    documentation and/or other materials      .Z!=J ]e []('-4f _ ) -.)m]'
00029  *    provided with the distribution.          .w[5]' _[ /.)_-"+?   _/ <W"
00030  * 3. Neither the name of Guichan nor the      :$we` _! + _/ .        j?
00031  *    names of its contributors may be used     =3)= _f  (_yQmWW$#(    "
00032  *    to endorse or promote products derived     -   W,  sQQQQmZQ#Wwa]..
00033  *    from this software without specific        (js, \[QQW$QWW#?!V"".
00034  *    prior written permission.                    ]y:.<\..          .
00035  *                                                 -]n w/ '         [.
00036  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT       )/ )/           !
00037  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY         <  (; sac    ,    '
00038  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,               ]^ .-  %
00039  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF            c <   r
00040  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR            aga<  <La
00041  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE          5%  )P'-3L
00042  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR        _bQf` y`..)a
00043  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,          ,J?4P'.P"_(\?d'.,
00044  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES               _Pa,)!f/<[]/  ?"
00045  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT      _2-..:. .r+_,.. .
00046  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     ?a.<%"'  " -'.a_ _,
00047  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION)                     ^
00048  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00049  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00050  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00051  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00052  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00053  */
00054 
00055 #ifndef GCN_WIDGET_HPP
00056 #define GCN_WIDGET_HPP
00057 
00058 #include <list>
00059 #include <string>
00060 
00061 #include "guichan/actionlistener.hpp"
00062 #include "guichan/color.hpp"
00063 #include "guichan/defaultfont.hpp"
00064 #include "guichan/font.hpp"
00065 #include "guichan/graphics.hpp"
00066 #include "guichan/keyinput.hpp"
00067 #include "guichan/keylistener.hpp"
00068 #include "guichan/mouseinput.hpp"
00069 #include "guichan/mouselistener.hpp"
00070 #include "guichan/rectangle.hpp"
00071 #include "guichan/platform.hpp"
00072 
00073 namespace gcn
00074 {
00075     /*
00076      * Exists for the widget class to compile.
00077      */
00078     class FocusHandler;
00079 
00080     /*
00081      * Exists for the widget class to compile.
00082      */
00083     class BasicContainer;
00084 
00093     class GCN_CORE_DECLSPEC Widget
00094     {
00095     public:
00101         Widget();
00102     
00106         virtual ~Widget();
00107 
00117         virtual void draw(Graphics* graphics) = 0;
00118         
00127         virtual void drawBorder(Graphics* graphics) { }
00128         
00135         virtual void logic() { }
00136     
00143         virtual BasicContainer* getParent() const;
00144     
00150         virtual void setWidth(int width);
00151 
00157         virtual int getWidth() const;
00158     
00164         virtual void setHeight(int height);
00165 
00171         virtual int getHeight() const;
00172 
00179         virtual void setSize(int width, int height);
00180         
00186         virtual void setX(int x);
00187 
00193         virtual int getX() const;
00194 
00200         virtual void setY(int y);
00201 
00207         virtual int getY() const;
00208 
00215         virtual void setPosition(int x, int y);
00216     
00222         virtual void setDimension(const Rectangle& dimension);
00223 
00232         virtual void setBorderSize(unsigned int borderSize);
00233 
00242         virtual unsigned int getBorderSize() const;
00243         
00249         virtual const Rectangle& getDimension() const;
00250 
00256         virtual void setFocusable(bool focusable);
00257 
00263         virtual bool isFocusable() const;
00264         
00270         virtual bool hasFocus() const;
00271 
00278         virtual void setEnabled(bool enabled);
00279 
00285         virtual bool isEnabled() const; 
00286         
00290         virtual void lostFocus() { };
00291     
00295         virtual void gotFocus() { };
00296     
00302         virtual bool hasMouse() const;
00303     
00309         virtual void setVisible(bool visible);
00310 
00316         virtual bool isVisible() const;
00317 
00324         virtual void setBaseColor(const Color& color);
00325 
00331         virtual const Color& getBaseColor() const;
00332     
00338         virtual void setForegroundColor(const Color& color);
00339 
00345         virtual const Color& getForegroundColor() const;
00346     
00352         virtual void setBackgroundColor(const Color& color);
00353 
00359         virtual const Color& getBackgroundColor() const;    
00360             
00370         virtual void _mouseInputMessage(const MouseInput& mouseInput);
00371 
00381         virtual void _keyInputMessage(const KeyInput& keyInput);
00382 
00390         virtual void _mouseInMessage();
00391 
00399         virtual void _mouseOutMessage();
00400     
00405         virtual void requestFocus();
00406 
00410         virtual void requestMoveToTop();
00411 
00415         virtual void requestMoveToBottom();
00416 
00426         virtual void _setFocusHandler(FocusHandler* focusHandler);
00427 
00437         virtual FocusHandler* _getFocusHandler();
00438 
00446         virtual void addActionListener(ActionListener* actionListener);
00447     
00453         virtual    void removeActionListener(ActionListener* actionListener);
00454 
00461         virtual    void addMouseListener(MouseListener* mouseListener);
00462     
00468         virtual    void removeMouseListener(MouseListener* mouseListener);
00469 
00476         virtual    void addKeyListener(KeyListener* keyListener);
00477 
00483         virtual    void removeKeyListener(KeyListener* keyListener);
00484 
00496         virtual    void setEventId(const std::string& eventId);
00497 
00503         virtual const std::string& getEventId() const;
00504 
00511         virtual    void getAbsolutePosition(int& x, int& y) const;
00512     
00522         virtual    void _setParent(BasicContainer* parent);
00523 
00532         Font *getFont() const;
00533     
00539         static void setGlobalFont(Font* font);
00540     
00546         virtual void setFont(Font* font);
00547 
00553         virtual void fontChanged() { }
00554 
00561         static bool widgetExists(const Widget* widget);
00562 
00571         virtual bool isTabInEnabled() const;
00572         
00581         virtual void setTabInEnabled(bool enabled);
00582 
00591         virtual bool isTabOutEnabled() const;
00592         
00601         virtual void setTabOutEnabled(bool enabled);
00602 
00610         virtual bool isDragged() const;
00611 
00619         virtual void requestModalFocus();
00620 
00625         virtual void releaseModalFocus();
00626         
00630         virtual bool hasModalFocus() const;
00631 
00632         
00633     protected:
00637         void generateAction();
00638         
00639         typedef std::list<MouseListener*> MouseListenerList;
00640         MouseListenerList mMouseListeners;
00641         typedef MouseListenerList::iterator MouseListenerIterator;
00642     
00643         typedef std::list<KeyListener*> KeyListenerList;
00644         KeyListenerList mKeyListeners;
00645         typedef KeyListenerList::iterator KeyListenerIterator;
00646         
00647         typedef std::list<ActionListener*> ActionListenerList;
00648         ActionListenerList mActionListeners;
00649         typedef ActionListenerList::iterator ActionListenerIterator;
00650         
00651         Color mForegroundColor;
00652         Color mBackgroundColor;
00653         Color mBaseColor;
00654         FocusHandler* mFocusHandler;
00655         BasicContainer* mParent;
00656         Rectangle mDimension;
00657         unsigned int mBorderSize;
00658         std::string mEventId;
00659         int mClickTimeStamp;
00660         int mClickCount;
00661         int mClickButton;
00662         bool mHasMouse;
00663         bool mFocusable;
00664         bool mVisible;
00665         bool mTabIn;
00666         bool mTabOut;
00667         bool mEnabled;
00668         
00669         Font* mCurrentFont;
00670         static DefaultFont mDefaultFont;
00671         static Font* mGlobalFont;
00672         static std::list<Widget*> mWidgets;
00673     };  
00674 }
00675 
00676 #endif // end GCN_WIDGET_HPP
00677 
00678 /*
00679  * yakslem  - "I have a really great idea! Why not have an
00680  *             interesting and funny quote or story at the
00681  *             end of every source file."
00682  * finalman - "Yeah - good idea! .... do you know any funny
00683  *             quotes?"
00684  * yakslem  - "Well.. I guess not. I just thought it would be
00685  *             fun to tell funny quotes."
00686  * finalman - "That's not a very funny quote. But i believe
00687  *             pointless quotes are funny in their own pointless
00688  *             way."
00689  * yakslem  - "...eh...ok..."
00690  */

Generated on Tue May 17 21:23:26 2005 for Guichan by  doxygen 1.4.1