_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
widget.h
Go to the documentation of this file.
1 /* _______ __ __ __ ______ __ __ _______ __ __
2  * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
3  * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
4  * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
5  * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
6  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
7  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
8  *
9  * Copyright (c) 2004, 2005 darkbits Js_./
10  * Per Larsson a.k.a finalman _RqZ{a<^_aa
11  * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a//
12  * _Qhm`] _f "'c 1!5m
13  * Visit: http://guichan.darkbits.org )Qk<P ` _: :+' .' "{[
14  * .)j(] .d_/ '-( P . S
15  * License: (BSD) <Td/Z <fP"5(\"??"\a. .L
16  * Redistribution and use in source and _dV>ws?a-?' ._/L #'
17  * binary forms, with or without )4d[#7r, . ' )d`)[
18  * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam'
19  * that the following conditions are met: j<<WP+k/);. _W=j f
20  * 1. Redistributions of source code must .$%w\/]Q . ."' . mj$
21  * retain the above copyright notice, ]E.pYY(Q]>. a J@\
22  * this list of conditions and the j(]1u<sE"L,. . ./^ ]{a
23  * following disclaimer. 4'_uomm\. )L);-4 (3=
24  * 2. Redistributions in binary form must )_]X{Z('a_"a7'<a"a, ]"[
25  * reproduce the above copyright notice, #}<]m7`Za??4,P-"'7. ).m
26  * this list of conditions and the ]d2e)Q(<Q( ?94 b- LQ/
27  * following disclaimer in the <B!</]C)d_, '(<' .f. =C+m
28  * documentation and/or other materials .Z!=J ]e []('-4f _ ) -.)m]'
29  * provided with the distribution. .w[5]' _[ /.)_-"+? _/ <W"
30  * 3. Neither the name of Guichan nor the :$we` _! + _/ . j?
31  * names of its contributors may be used =3)= _f (_yQmWW$#( "
32  * to endorse or promote products derived - W, sQQQQmZQ#Wwa]..
33  * from this software without specific (js, \[QQW$QWW#?!V"".
34  * prior written permission. ]y:.<\.. .
35  * -]n w/ ' [.
36  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT )/ )/ !
37  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY < (; sac , '
38  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ]^ .- %
39  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF c < r
40  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR aga< <La
41  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 5% )P'-3L
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR _bQf` y`..)a
43  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ,J?4P'.P"_(\?d'.,
44  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES _Pa,)!f/<[]/ ?"
45  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT _2-..:. .r+_,.. .
46  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ?a.<%"' " -'.a_ _,
47  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ^
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
51  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
52  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53  */
54 
55 #ifndef GCN_WIDGET_HPP
56 #define GCN_WIDGET_HPP
57 
58 #include <list>
59 #include <string>
60 
61 #include "guichan/actionlistener.h"
62 #include "guichan/color.h"
63 #include "guichan/defaultfont.h"
64 #include "guichan/font.h"
65 #include "guichan/graphics.h"
66 #include "guichan/keyinput.h"
67 #include "guichan/keylistener.h"
68 #include "guichan/mouseinput.h"
69 #include "guichan/mouselistener.h"
70 #include "guichan/rectangle.h"
71 #include "guichan/platform.h"
72 
73 namespace gcn
74 {
75  /*
76  * Exists for the widget class to compile.
77  */
78  class FocusHandler;
79 
80  /*
81  * Exists for the widget class to compile.
82  */
83  class BasicContainer;
84 
94  {
95  public:
101  Widget();
102 
106  virtual ~Widget();
107 
117  virtual void draw(Graphics* graphics) = 0;
118 
127  virtual void drawBorder(Graphics*) { }
128 
135  virtual void logic() { }
136 
143  virtual BasicContainer* getParent() const;
144 
150  virtual void setWidth(int width);
151 
157  virtual int getWidth() const;
158 
164  virtual void setHeight(int height);
165 
171  virtual int getHeight() const;
172 
179  virtual void setSize(int width, int height);
180 
186  virtual void setX(int x);
187 
193  virtual int getX() const;
194 
200  virtual void setY(int y);
201 
207  virtual int getY() const;
208 
215  virtual void setPosition(int x, int y);
216 
222  virtual void setDimension(const Rectangle& dimension);
223 
232  virtual void setBorderSize(unsigned int borderSize);
233 
242  virtual unsigned int getBorderSize() const;
243 
249  virtual const Rectangle& getDimension() const;
250 
256  virtual void setFocusable(bool focusable);
257 
263  virtual bool isFocusable() const;
264 
270  virtual bool hasFocus() const;
271 
278  virtual void setEnabled(bool enabled);
279 
285  virtual bool isEnabled() const;
286 
290  virtual void lostFocus() { setDirty(true); };
291 
295  virtual void gotFocus() { setDirty(true); };
296 
302  virtual bool hasMouse() const;
303 
309  virtual void setVisible(bool visible);
310 
316  virtual bool isVisible() const;
317 
324  virtual void setBaseColor(const Color& color);
325 
331  virtual const Color& getBaseColor() const;
332 
338  virtual void setForegroundColor(const Color& color);
339 
345  virtual const Color& getForegroundColor() const;
346 
352  virtual void setBackgroundColor(const Color& color);
353 
359  virtual const Color& getBackgroundColor() const;
360 
366  virtual void setDisabledColor(const Color& color);
367 
373  virtual const Color& getDisabledColor() const;
374 
384  virtual void _mouseInputMessage(const MouseInput& mouseInput);
385 
395  virtual bool _keyInputMessage(const KeyInput& keyInput);
396 
400  virtual void hotKeyPress() {}
401 
405  virtual void hotKeyRelease() {}
406 
414  virtual void _mouseInMessage();
415 
423  virtual void _mouseOutMessage();
424 
429  virtual void requestFocus();
430 
434  virtual void requestMoveToTop();
435 
439  virtual void requestMoveToBottom();
440 
450  virtual void _setFocusHandler(FocusHandler* focusHandler);
451 
461  virtual FocusHandler* _getFocusHandler();
462 
470  virtual void addActionListener(ActionListener* actionListener);
471 
477  virtual void removeActionListener(ActionListener* actionListener);
478 
485  virtual void addMouseListener(MouseListener* mouseListener);
486 
492  virtual void removeMouseListener(MouseListener* mouseListener);
493 
500  virtual void addKeyListener(KeyListener* keyListener);
501 
507  virtual void removeKeyListener(KeyListener* keyListener);
508 
520  virtual void setEventId(const std::string& eventId);
521 
527  virtual const std::string& getEventId() const;
528 
535  virtual void getAbsolutePosition(int& x, int& y) const;
536 
546  virtual void _setParent(BasicContainer* parent);
547 
556  Font *getFont() const;
557 
563  static void setGlobalFont(Font* font);
564 
570  virtual void setFont(Font* font);
571 
577  virtual void fontChanged() { }
578 
582  virtual int getHotKey() const { return mHotKey; }
583 
587  virtual void setHotKey(const int key);
588  virtual void setHotKey(const char *key);
589 
596  static bool widgetExists(const Widget* widget);
597 
606  virtual bool isTabInEnabled() const;
607 
616  virtual void setTabInEnabled(bool enabled);
617 
626  virtual bool isTabOutEnabled() const;
627 
636  virtual void setTabOutEnabled(bool enabled);
637 
645  virtual bool isDragged() const;
646 
654  virtual void requestModalFocus();
655 
660  virtual void releaseModalFocus();
661 
665  virtual bool hasModalFocus() const;
666 
667  virtual void setDirty(bool dirty);
668  virtual bool getDirty() const;
669 
670 
671  protected:
675  void generateAction();
676 
677  typedef std::list<MouseListener*> MouseListenerList;
678  MouseListenerList mMouseListeners;
679  typedef MouseListenerList::iterator MouseListenerIterator;
680 
681  typedef std::list<KeyListener*> KeyListenerList;
682  KeyListenerList mKeyListeners;
683  typedef KeyListenerList::iterator KeyListenerIterator;
684 
685  typedef std::list<ActionListener*> ActionListenerList;
686  ActionListenerList mActionListeners;
687  typedef ActionListenerList::iterator ActionListenerIterator;
688 
696  unsigned int mBorderSize;
697  std::string mEventId;
701  bool mHasMouse;
703  bool mVisible;
704  bool mTabIn;
705  bool mTabOut;
706  bool mEnabled;
707 
709  int mHotKey;
711  static Font* mGlobalFont;
712  static std::list<Widget*> mWidgets;
713  bool mDirty;
714  };
715 }
716 
717 #endif // end GCN_WIDGET_HPP
718 
719 /*
720  * yakslem - "I have a really great idea! Why not have an
721  * interesting and funny quote or story at the
722  * end of every source file."
723  * finalman - "Yeah - good idea! .... do you know any funny
724  * quotes?"
725  * yakslem - "Well.. I guess not. I just thought it would be
726  * fun to tell funny quotes."
727  * finalman - "That's not a very funny quote. But i believe
728  * pointless quotes are funny in their own pointless
729  * way."
730  * yakslem - "...eh...ok..."
731  */
bool mFocusable
Definition: widget.h:702
std::list< MouseListener * > MouseListenerList
Definition: widget.h:677
MouseListenerList mMouseListeners
Definition: widget.h:678
int mClickButton
Definition: widget.h:700
BasicContainer * mParent
Definition: widget.h:694
Color mDisabledColor
Definition: widget.h:692
Definition: keylistener.h:74
Color mBackgroundColor
Definition: widget.h:690
virtual void hotKeyRelease()
Definition: widget.h:405
bool mTabOut
Definition: widget.h:705
int mClickTimeStamp
Definition: widget.h:698
KeyListenerList mKeyListeners
Definition: widget.h:682
std::list< ActionListener * > ActionListenerList
Definition: widget.h:685
bool mHasMouse
Definition: widget.h:701
int mClickCount
Definition: widget.h:699
virtual void fontChanged()
Definition: widget.h:577
bool mTabIn
Definition: widget.h:704
Definition: mouseinput.h:67
Definition: graphics.h:97
Rectangle mDimension
Definition: widget.h:695
ActionListenerList::iterator ActionListenerIterator
Definition: widget.h:687
virtual int getHotKey() const
Definition: widget.h:582
Definition: actionlistener.h:71
virtual void hotKeyPress()
Definition: widget.h:400
Definition: font.h:69
Definition: keyinput.h:67
virtual void drawBorder(Graphics *)
Definition: widget.h:127
static DefaultFont mDefaultFont
Definition: widget.h:710
int mHotKey
Definition: widget.h:709
Font * mCurrentFont
Definition: widget.h:708
Definition: basiccontainer.h:73
Definition: widget.h:93
Color mForegroundColor
Definition: widget.h:689
bool mEnabled
Definition: widget.h:706
Definition: defaultfont.h:67
FocusHandler * mFocusHandler
Definition: widget.h:693
ActionListenerList mActionListeners
Definition: widget.h:686
MouseListenerList::iterator MouseListenerIterator
Definition: widget.h:679
Color mBaseColor
Definition: widget.h:691
KeyListenerList::iterator KeyListenerIterator
Definition: widget.h:683
bool mDirty
Definition: widget.h:713
Definition: cliprectangle.cpp:61
#define GCN_CORE_DECLSPEC
Definition: platform.h:59
unsigned int mBorderSize
Definition: widget.h:696
Definition: rectangle.h:65
Definition: focushandler.h:80
static Font * mGlobalFont
Definition: widget.h:711
Definition: color.h:65
std::string mEventId
Definition: widget.h:697
Definition: mouselistener.h:72
virtual void lostFocus()
Definition: widget.h:290
static std::list< Widget * > mWidgets
Definition: widget.h:712
virtual void logic()
Definition: widget.h:135
virtual void gotFocus()
Definition: widget.h:295
std::list< KeyListener * > KeyListenerList
Definition: widget.h:681
bool mVisible
Definition: widget.h:703
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.