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

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  friend class BasicContainer;
96  public:
102  Widget();
103 
107  virtual ~Widget();
108 
118  virtual void draw(Graphics* graphics) = 0;
119 
128  virtual void drawBorder(Graphics*) { }
129 
136  virtual void logic() { }
137 
144  virtual BasicContainer* getParent() const;
145 
151  virtual void setWidth(int width);
152 
158  virtual int getWidth() const;
159 
165  virtual void setHeight(int height);
166 
172  virtual int getHeight() const;
173 
180  virtual void setSize(int width, int height);
181 
187  virtual void setX(int x);
188 
194  virtual int getX() const;
195 
201  virtual void setY(int y);
202 
208  virtual int getY() const;
209 
216  virtual void setPosition(int x, int y);
217 
223  virtual void setDimension(const Rectangle& dimension);
224 
233  virtual void setBorderSize(unsigned int borderSize);
234 
243  virtual unsigned int getBorderSize() const;
244 
250  virtual const Rectangle& getDimension() const;
251 
257  virtual void setFocusable(bool focusable);
258 
264  virtual bool isFocusable() const;
265 
271  virtual bool hasFocus() const;
272 
279  virtual void setEnabled(bool enabled);
280 
286  virtual bool isEnabled() const;
287 
291  virtual void lostFocus() { setDirty(true); };
292 
296  virtual void gotFocus() { setDirty(true); };
297 
303  virtual bool hasMouse() const;
304 
310  virtual void setVisible(bool visible);
311 
317  virtual bool isVisible() const;
318 
325  virtual void setBaseColor(const Color& color);
326 
332  virtual const Color& getBaseColor() const;
333 
339  virtual void setForegroundColor(const Color& color);
340 
346  virtual const Color& getForegroundColor() const;
347 
353  virtual void setBackgroundColor(const Color& color);
354 
360  virtual const Color& getBackgroundColor() const;
361 
367  virtual void setDisabledColor(const Color& color);
368 
374  virtual const Color& getDisabledColor() const;
375 
385  virtual void _mouseInputMessage(const MouseInput& mouseInput);
386 
396  virtual bool _keyInputMessage(const KeyInput& keyInput);
397 
401  virtual void hotKeyPress() {}
402 
406  virtual void hotKeyRelease() {}
407 
415  virtual void _mouseInMessage();
416 
424  virtual void _mouseOutMessage();
425 
430  virtual void requestFocus();
431 
435  virtual void requestMoveToTop();
436 
440  virtual void requestMoveToBottom();
441 
451  virtual void _setFocusHandler(FocusHandler* focusHandler);
452 
462  virtual FocusHandler* _getFocusHandler();
463 
471  virtual void addActionListener(ActionListener* actionListener);
472 
478  virtual void removeActionListener(ActionListener* actionListener);
479 
486  virtual void addMouseListener(MouseListener* mouseListener);
487 
493  virtual void removeMouseListener(MouseListener* mouseListener);
494 
501  virtual void addKeyListener(KeyListener* keyListener);
502 
508  virtual void removeKeyListener(KeyListener* keyListener);
509 
521  virtual void setEventId(const std::string& eventId);
522 
528  virtual const std::string& getEventId() const;
529 
536  virtual void getAbsolutePosition(int& x, int& y) const;
537 
547  virtual void _setParent(BasicContainer* parent);
548 
557  Font *getFont() const;
558 
564  static void setGlobalFont(Font* font);
565 
571  virtual void setFont(Font* font);
572 
578  virtual void fontChanged() { }
579 
583  virtual int getHotKey() const { return mHotKey; }
584 
588  virtual void setHotKey(const int key);
589  virtual void setHotKey(const char *key);
590 
597  static bool widgetExists(const Widget* widget);
598 
607  virtual bool isTabInEnabled() const;
608 
617  virtual void setTabInEnabled(bool enabled);
618 
627  virtual bool isTabOutEnabled() const;
628 
637  virtual void setTabOutEnabled(bool enabled);
638 
646  virtual bool isDragged() const;
647 
655  virtual void requestModalFocus();
656 
661  virtual void releaseModalFocus();
662 
666  virtual bool hasModalFocus() const;
667 
668  virtual void setDirty(bool dirty);
669  virtual bool getDirty() const;
670 
671 
672  protected:
676  void generateAction();
677 
678  typedef std::list<MouseListener*> MouseListenerList;
680  typedef MouseListenerList::iterator MouseListenerIterator;
681 
682  typedef std::list<KeyListener*> KeyListenerList;
684  typedef KeyListenerList::iterator KeyListenerIterator;
685 
686  typedef std::list<ActionListener*> ActionListenerList;
688  typedef ActionListenerList::iterator ActionListenerIterator;
689 
697  unsigned int mBorderSize;
698  std::string mEventId;
702  bool mHasMouse;
704  bool mVisible;
705  bool mTabIn;
706  bool mTabOut;
707  bool mEnabled;
708 
710  int mHotKey;
712  static Font* mGlobalFont;
713  static std::list<Widget*> mWidgets;
714  bool mDirty;
715  };
716 }
717 
718 #endif // end GCN_WIDGET_HPP
719 
720 /*
721  * yakslem - "I have a really great idea! Why not have an
722  * interesting and funny quote or story at the
723  * end of every source file."
724  * finalman - "Yeah - good idea! .... do you know any funny
725  * quotes?"
726  * yakslem - "Well.. I guess not. I just thought it would be
727  * fun to tell funny quotes."
728  * finalman - "That's not a very funny quote. But i believe
729  * pointless quotes are funny in their own pointless
730  * way."
731  * yakslem - "...eh...ok..."
732  */
gcn::Widget::logic
virtual void logic()
Definition: widget.h:136
gcn::KeyListener
Definition: keylistener.h:74
gcn::Widget::mFocusHandler
FocusHandler * mFocusHandler
Definition: widget.h:694
graphics.h
mouselistener.h
gcn::Widget::drawBorder
virtual void drawBorder(Graphics *)
Definition: widget.h:128
gcn::Widget::ActionListenerList
std::list< ActionListener * > ActionListenerList
Definition: widget.h:686
GCN_CORE_DECLSPEC
#define GCN_CORE_DECLSPEC
Definition: platform.h:59
gcn::Widget::mHotKey
int mHotKey
Definition: widget.h:710
gcn::Graphics
Definition: graphics.h:97
color.h
gcn::Widget::lostFocus
virtual void lostFocus()
Definition: widget.h:291
gcn::Widget::mCurrentFont
Font * mCurrentFont
Definition: widget.h:709
gcn::Widget::mFocusable
bool mFocusable
Definition: widget.h:703
gcn::Widget::KeyListenerIterator
KeyListenerList::iterator KeyListenerIterator
Definition: widget.h:684
gcn::Widget::mForegroundColor
Color mForegroundColor
Definition: widget.h:690
mouseinput.h
gcn::Widget::mClickButton
int mClickButton
Definition: widget.h:701
keylistener.h
gcn::Widget::mMouseListeners
MouseListenerList mMouseListeners
Definition: widget.h:679
keyinput.h
gcn::MouseListener
Definition: mouselistener.h:72
gcn::ActionListener
Definition: actionlistener.h:71
gcn::Widget::mBorderSize
unsigned int mBorderSize
Definition: widget.h:697
gcn::Widget::KeyListenerList
std::list< KeyListener * > KeyListenerList
Definition: widget.h:682
gcn::FocusHandler
Definition: focushandler.h:80
gcn::Widget::mActionListeners
ActionListenerList mActionListeners
Definition: widget.h:687
gcn::Widget::mBaseColor
Color mBaseColor
Definition: widget.h:692
gcn::KeyInput
Definition: keyinput.h:67
gcn::Widget::MouseListenerList
std::list< MouseListener * > MouseListenerList
Definition: widget.h:678
gcn::Widget::mTabIn
bool mTabIn
Definition: widget.h:705
gcn::BasicContainer
Definition: basiccontainer.h:73
gcn
Definition: cliprectangle.cpp:61
gcn::Widget::mWidgets
static std::list< Widget * > mWidgets
Definition: widget.h:713
gcn::Widget::getHotKey
virtual int getHotKey() const
Definition: widget.h:583
gcn::Rectangle
Definition: rectangle.h:65
gcn::Widget::mClickTimeStamp
int mClickTimeStamp
Definition: widget.h:699
defaultfont.h
gcn::Widget::mDefaultFont
static DefaultFont mDefaultFont
Definition: widget.h:711
gcn::Widget::ActionListenerIterator
ActionListenerList::iterator ActionListenerIterator
Definition: widget.h:688
rectangle.h
gcn::Widget::gotFocus
virtual void gotFocus()
Definition: widget.h:296
gcn::Widget::mParent
BasicContainer * mParent
Definition: widget.h:695
platform.h
gcn::Widget::hotKeyPress
virtual void hotKeyPress()
Definition: widget.h:401
actionlistener.h
gcn::Widget::mGlobalFont
static Font * mGlobalFont
Definition: widget.h:712
gcn::Widget::mTabOut
bool mTabOut
Definition: widget.h:706
gcn::Color
Definition: color.h:65
gcn::Font
Definition: font.h:69
gcn::Widget::hotKeyRelease
virtual void hotKeyRelease()
Definition: widget.h:406
gcn::Widget::mKeyListeners
KeyListenerList mKeyListeners
Definition: widget.h:683
gcn::Widget::mHasMouse
bool mHasMouse
Definition: widget.h:702
gcn::Widget::mVisible
bool mVisible
Definition: widget.h:704
gcn::Widget::mDirty
bool mDirty
Definition: widget.h:714
gcn::Widget::MouseListenerIterator
MouseListenerList::iterator MouseListenerIterator
Definition: widget.h:680
gcn::Widget::mEventId
std::string mEventId
Definition: widget.h:698
gcn::DefaultFont
Definition: defaultfont.h:67
gcn::Widget::mDisabledColor
Color mDisabledColor
Definition: widget.h:693
gcn::Widget::mBackgroundColor
Color mBackgroundColor
Definition: widget.h:691
font.h
gcn::Widget::fontChanged
virtual void fontChanged()
Definition: widget.h:578
gcn::Widget::mClickCount
int mClickCount
Definition: widget.h:700
gcn::MouseInput
Definition: mouseinput.h:67
gcn::Widget
Definition: widget.h:93
gcn::Widget::mDimension
Rectangle mDimension
Definition: widget.h:696
gcn::Widget::mEnabled
bool mEnabled
Definition: widget.h:707
(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.