wg_message.h

00001 // wg_message.h
00002 //
00003 // CMessage interface
00004 //
00005 //
00006 // Copyright (c) 2002-2004 Rob Wiskow
00007 // rob-dev@boxedchaos.com
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00022 //
00023 
00024 
00025 #ifndef _WG_MESSAGE_H_
00026 #define _WG_MESSAGE_H_
00027 
00028 #include "wg_point.h"
00029 #include "wg_rect.h"
00030 #include "SDL.h"
00031 #include <string>
00032 
00033 
00034 namespace wGui
00035 {
00036 // Forward declarations
00037 class CMessageClient;
00038 
00040 
00043 
00044 class CMessage
00045 {
00046 public:
00048      enum EMessageType
00049      {
00050           UNKNOWN = 0,  
00051           APP_DESTROY_FRAME,  
00052           APP_EXIT,  
00053           APP_PAINT,     
00054           CTRL_DOUBLELCLICK,  
00055           CTRL_DOUBLEMCLICK,  
00056           CTRL_DOUBLERCLICK,  
00057           CTRL_GAININGKEYFOCUS,  
00058           CTRL_GAININGMOUSEFOCUS,  
00059           CTRL_LOSINGKEYFOCUS,  
00060           CTRL_LOSINGMOUSEFOCUS,   
00061           CTRL_MESSAGEBOXRETURN,   
00062           CTRL_RESIZE,  
00063           CTRL_SINGLELCLICK,  
00064           CTRL_SINGLEMCLICK,  
00065           CTRL_SINGLERCLICK,  
00066           CTRL_TIMER, 
00067           CTRL_VALUECHANGE,  
00068           CTRL_VALUECHANGING,  
00069           KEYBOARD_KEYDOWN,  
00070           KEYBOARD_KEYUP,  
00071           MOUSE_BUTTONDOWN,  
00072           MOUSE_BUTTONUP,  
00073           MOUSE_MOVE,  
00074           SDL,  
00075           USER  
00076      };
00077 
00082      CMessage(const EMessageType MessageType, const CMessageClient* pDestination, const CMessageClient* pSource);
00083 
00085      virtual ~CMessage(void) { }
00086 
00089      const EMessageType MessageType(void) { return m_MessageType; }
00090 
00093      const CMessageClient* Destination(void) { return m_pDestination; }
00094 
00097      const CMessageClient* Source(void) { return m_pSource; }
00098 
00099 protected:
00101      const EMessageType m_MessageType;
00102 
00104      const CMessageClient* m_pDestination;
00105 
00107      const CMessageClient* m_pSource;
00108 
00109 private:
00110      void operator=(CMessage) { }  
00111 };
00112 
00113 
00115 
00116 class CSDLMessage : public CMessage
00117 {
00118 public:
00124      CSDLMessage(const EMessageType MessageType, const CMessageClient* pDestination, const CMessageClient* pSource, SDL_Event SDLEvent);
00125 
00126      SDL_Event SDLEvent;  
00127 };
00128 
00129 
00131 
00132 class CKeyboardMessage : public CMessage
00133 {
00134 public:
00143      CKeyboardMessage(const EMessageType MessageType, const CMessageClient* pDestination, const CMessageClient* pSource,
00144           unsigned char ScanCode, SDLMod Modifiers, SDLKey Key, Uint16 Unicode);
00145 
00146      unsigned char ScanCode;  
00147      SDLMod Modifiers;  
00148      SDLKey Key;  
00149      Uint16 Unicode;  
00150 };
00151 
00152 
00154 
00155 class CMouseMessage : public CMessage
00156 {
00157 public:
00159      enum EMouseButton
00160      {
00161           NONE = 0,                
00162           LEFT = 1,                
00163           RIGHT = 2,               
00164           MIDDLE = 4,              
00165           WHEELUP = 8,        
00166           WHEELDOWN = 16 
00167      };
00168 
00176      CMouseMessage(const EMessageType MessageType, const CMessageClient* pDestination, const CMessageClient* pSource,
00177           CPoint Point, CPoint Relative, unsigned int Button);
00178 
00180      static unsigned int TranslateSDLButton(Uint8 SDLButton);
00181 
00183      static unsigned int TranslateSDLButtonState(Uint8 SDLButtonState);
00184 
00185      CPoint Point;  
00186      CPoint Relative;  
00187      unsigned int Button;  
00188 };
00189 
00190 
00193 
00194 template<typename T>
00195 class CValueMessage : public CMessage
00196 {
00197 public:
00198 
00204      CValueMessage(const EMessageType MessageType, const CMessageClient* pDestination, const CMessageClient* pSource, const T& Value ) :
00205           CMessage(MessageType, pDestination, pSource),
00206           m_Value(Value)
00207      { }
00208 
00211      const T& Value(void) { return m_Value; }
00212 
00215      void SetValue(const T& Value) { m_Value = Value; }
00216 
00217 protected:
00218 
00220      T m_Value;
00221 };
00222 
00223 
00225 
00226 typedef CValueMessage<int> TIntMessage;  
00227 typedef CValueMessage<float> TFloatMessage;  
00228 typedef CValueMessage<double> TDoubleMessage;  
00229 typedef CValueMessage<std::wstring> TStringMessage;  
00230 typedef CValueMessage<CPoint> TPointMessage;  
00231 typedef CValueMessage<CRect> TRectMessage;  
00232 
00233 }
00234 
00235 
00236 #include "unit_tests/wg_message_unittests.h"
00237 
00238 #endif // _WG_MESSAGE_H_
00239 

Generated on Wed May 16 23:11:26 2007 for wGui by  doxygen 1.5.1