widget.hpp

00001 /*      _______   __   __   __   ______   __   __   _______   __   __
00002  *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
00003  *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
00004  *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
00005  *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
00006  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
00007  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
00008  *
00009  * Copyright (c) 2004, 2005, 2006 Olof Naessén and Per Larsson
00010  *
00011  *                                                         Js_./
00012  * Per Larsson a.k.a finalman                          _RqZ{a<^_aa
00013  * Olof Naessén a.k.a jansem/yakslem                _asww7!uY`>  )\a//
00014  *                                                 _Qhm`] _f "'c  1!5m
00015  * Visit: http://guichan.darkbits.org             )Qk<P ` _: :+' .'  "{[
00016  *                                               .)j(] .d_/ '-(  P .   S
00017  * License: (BSD)                                <Td/Z <fP"5(\"??"\a.  .L
00018  * Redistribution and use in source and          _dV>ws?a-?'      ._/L  #'
00019  * binary forms, with or without                 )4d[#7r, .   '     )d`)[
00020  * modification, are permitted provided         _Q-5'5W..j/?'   -?!\)cam'
00021  * that the following conditions are met:       j<<WP+k/);.        _W=j f
00022  * 1. Redistributions of source code must       .$%w\/]Q  . ."'  .  mj$
00023  *    retain the above copyright notice,        ]E.pYY(Q]>.   a     J@\
00024  *    this list of conditions and the           j(]1u<sE"L,. .   ./^ ]{a
00025  *    following disclaimer.                     4'_uomm\.  )L);-4     (3=
00026  * 2. Redistributions in binary form must        )_]X{Z('a_"a7'<a"a,  ]"[
00027  *    reproduce the above copyright notice,       #}<]m7`Za??4,P-"'7. ).m
00028  *    this list of conditions and the            ]d2e)Q(<Q(  ?94   b-  LQ/
00029  *    following disclaimer in the                <B!</]C)d_, '(<' .f. =C+m
00030  *    documentation and/or other materials      .Z!=J ]e []('-4f _ ) -.)m]'
00031  *    provided with the distribution.          .w[5]' _[ /.)_-"+?   _/ <W"
00032  * 3. Neither the name of Guichan nor the      :$we` _! + _/ .        j?
00033  *    names of its contributors may be used     =3)= _f  (_yQmWW$#(    "
00034  *    to endorse or promote products derived     -   W,  sQQQQmZQ#Wwa]..
00035  *    from this software without specific        (js, \[QQW$QWW#?!V"".
00036  *    prior written permission.                    ]y:.<\..          .
00037  *                                                 -]n w/ '         [.
00038  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT       )/ )/           !
00039  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY         <  (; sac    ,    '
00040  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,               ]^ .-  %
00041  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF            c <   r
00042  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR            aga<  <La
00043  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE          5%  )P'-3L
00044  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR        _bQf` y`..)a
00045  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,          ,J?4P'.P"_(\?d'.,
00046  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES               _Pa,)!f/<[]/  ?"
00047  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT      _2-..:. .r+_,.. .
00048  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     ?a.<%"'  " -'.a_ _,
00049  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION)                     ^
00050  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00051  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00052  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00053  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00054  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00055  */
00056 
00057 #ifndef GCN_WIDGET_HPP
00058 #define GCN_WIDGET_HPP
00059 
00060 #include <list>
00061 #include <string>
00062 
00063 #include "guichan/color.hpp"
00064 #include "guichan/rectangle.hpp"
00065 
00066 namespace gcn
00067 {
00068     class ActionListener;
00069     class BasicContainer;
00070     class DefaultFont;
00071     class FocusHandler;
00072     class Font;
00073     class Graphics;
00074     class KeyInput;
00075     class KeyListener;
00076     class MouseInput;
00077     class MouseListener;
00078 
00087     class GCN_CORE_DECLSPEC Widget
00088     {
00089     public:
00095         Widget();
00096 
00100         virtual ~Widget();
00101 
00111         virtual void draw(Graphics* graphics) = 0;
00112 
00121         virtual void drawBorder(Graphics* graphics) { }
00122 
00129         virtual void logic() { }
00130 
00137         virtual BasicContainer* getParent() const;
00138 
00144         virtual void setWidth(int width);
00145 
00151         virtual int getWidth() const;
00152 
00158         virtual void setHeight(int height);
00159 
00165         virtual int getHeight() const;
00166 
00173         virtual void setSize(int width, int height);
00174 
00180         virtual void setX(int x);
00181 
00187         virtual int getX() const;
00188 
00194         virtual void setY(int y);
00195 
00201         virtual int getY() const;
00202 
00209         virtual void setPosition(int x, int y);
00210 
00216         virtual void setDimension(const Rectangle& dimension);
00217 
00226         virtual void setBorderSize(unsigned int borderSize);
00227 
00236         virtual unsigned int getBorderSize() const;
00237 
00243         virtual const Rectangle& getDimension() const;
00244 
00250         virtual void setFocusable(bool focusable);
00251 
00257         virtual bool isFocusable() const;
00258 
00264         virtual bool isFocused() const;
00265 
00272         virtual void setEnabled(bool enabled);
00273 
00279         virtual bool isEnabled() const;
00280 
00284         virtual void lostFocus() { };
00285 
00289         virtual void gotFocus() { };
00290 
00296         virtual bool hasMouse() const;
00297 
00303         virtual void setVisible(bool visible);
00304 
00310         virtual bool isVisible() const;
00311 
00318         virtual void setBaseColor(const Color& color);
00319 
00325         virtual const Color& getBaseColor() const;
00326 
00332         virtual void setForegroundColor(const Color& color);
00333 
00339         virtual const Color& getForegroundColor() const;
00340 
00346         virtual void setBackgroundColor(const Color& color);
00347 
00353         virtual const Color& getBackgroundColor() const;
00354 
00364         virtual void _mouseInputMessage(const MouseInput& mouseInput);
00365 
00375         virtual void _keyInputMessage(const KeyInput& keyInput);
00376 
00384         virtual void _mouseInMessage();
00385 
00393         virtual void _mouseOutMessage();
00394 
00399         virtual void requestFocus();
00400 
00404         virtual void requestMoveToTop();
00405 
00409         virtual void requestMoveToBottom();
00410 
00420         virtual void _setFocusHandler(FocusHandler* focusHandler);
00421 
00431         virtual FocusHandler* _getFocusHandler();
00432 
00440         virtual void addActionListener(ActionListener* actionListener);
00441 
00447         virtual    void removeActionListener(ActionListener* actionListener);
00448 
00455         virtual    void addMouseListener(MouseListener* mouseListener);
00456 
00462         virtual    void removeMouseListener(MouseListener* mouseListener);
00463 
00470         virtual    void addKeyListener(KeyListener* keyListener);
00471 
00477         virtual    void removeKeyListener(KeyListener* keyListener);
00478 
00490         virtual    void setEventId(const std::string& eventId);
00491 
00497         virtual const std::string& getEventId() const;
00498 
00505         virtual    void getAbsolutePosition(int& x, int& y) const;
00506 
00516         virtual    void _setParent(BasicContainer* parent);
00517 
00526         Font *getFont() const;
00527 
00533         static void setGlobalFont(Font* font);
00534 
00540         virtual void setFont(Font* font);
00541 
00547         virtual void fontChanged() { }
00548 
00555         static bool widgetExists(const Widget* widget);
00556 
00565         virtual bool isTabInEnabled() const;
00566 
00575         virtual void setTabInEnabled(bool enabled);
00576 
00585         virtual bool isTabOutEnabled() const;
00586 
00595         virtual void setTabOutEnabled(bool enabled);
00596 
00604         virtual bool isDragged() const;
00605 
00613         virtual void requestModalFocus();
00614 
00619         virtual void releaseModalFocus();
00620 
00624         virtual bool hasModalFocus() const;
00625 
00626 
00627     protected:
00631         void generateAction();
00632 
00633         typedef std::list<MouseListener*> MouseListenerList;
00634         MouseListenerList mMouseListeners;
00635         typedef MouseListenerList::iterator MouseListenerIterator;
00636 
00637         typedef std::list<KeyListener*> KeyListenerList;
00638         KeyListenerList mKeyListeners;
00639         typedef KeyListenerList::iterator KeyListenerIterator;
00640 
00641         typedef std::list<ActionListener*> ActionListenerList;
00642         ActionListenerList mActionListeners;
00643         typedef ActionListenerList::iterator ActionListenerIterator;
00644 
00645         Color mForegroundColor;
00646         Color mBackgroundColor;
00647         Color mBaseColor;
00648         FocusHandler* mFocusHandler;
00649         BasicContainer* mParent;
00650         Rectangle mDimension;
00651         unsigned int mBorderSize;
00652         std::string mEventId;
00653         int mClickTimeStamp;
00654         int mClickCount;
00655         int mClickButton;
00656         bool mHasMouse;
00657         bool mFocusable;
00658         bool mVisible;
00659         bool mTabIn;
00660         bool mTabOut;
00661         bool mEnabled;
00662 
00663         Font* mCurrentFont;
00664         static DefaultFont mDefaultFont;
00665         static Font* mGlobalFont;
00666         static std::list<Widget*> mWidgets;
00667     };
00668 }
00669 
00670 #endif // end GCN_WIDGET_HPP
00671 
00672 /*
00673  * yakslem  - "I have a really great idea! Why not have an
00674  *             interesting and funny quote or story at the
00675  *             end of every source file."
00676  * finalman - "Yeah - good idea! .... do you know any funny
00677  *             quotes?"
00678  * yakslem  - "Well.. I guess not. I just thought it would be
00679  *             fun to tell funny quotes."
00680  * finalman - "That's not a very funny quote. But i believe
00681  *             pointless quotes are funny in their own pointless
00682  *             way."
00683  * yakslem  - "...eh...ok..."
00684  */

Generated on Sat Jul 29 19:38:48 2006 for Guichan by  doxygen 1.4.7