00001 // wg_window.h 00002 // 00003 // CWindow interface 00004 // this serves as the base of all window derived classes 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_WINDOW_H_ 00026 #define _WG_WINDOW_H_ 00027 00028 #include "wg_rect.h" 00029 #include "wg_color.h" 00030 #include "wg_message_client.h" 00031 #include <string> 00032 #include <list> 00033 #include <typeinfo> 00034 #include "SDL.h" 00035 00036 00037 namespace wGui 00038 { 00039 00040 // forward declaration of the view class 00041 class CView; 00042 00043 00045 00049 00050 class CWindow : public CMessageClient 00051 { 00052 public: 00057 CWindow(const CRect& WindowRect, CWindow* pParent); 00058 00060 virtual ~CWindow(void); 00061 00064 virtual std::string GetClassName(void) const { return typeid(*this).name(); } 00065 00068 virtual void SetWindowRect(const CRect& WindowRect); 00069 00073 virtual CRect GetWindowRect(void) const { return m_WindowRect; } 00074 00077 virtual void MoveWindow(const CPoint& MoveDistance); 00078 00084 virtual CRect GetClientRect(void) const { return m_ClientRect; } 00085 00088 virtual void SetBackgroundColor(const CRGBColor& Color) { m_BackgroundColor = Color; } 00089 00092 virtual CRGBColor GetBackgroundColor(void) { return m_BackgroundColor; } 00093 00095 enum EAncestor { 00096 PARENT, 00097 ROOT 00098 }; 00102 virtual CWindow* GetAncestor(EAncestor eAncestor) const; 00103 00105 virtual std::list<CWindow*> GetChildWindows(void) const { return m_ChildWindows; } 00106 00109 virtual CView* GetView(void) const; 00110 00114 virtual bool IsChildOf(CWindow* pWindow) const; 00115 00118 virtual bool IsVisible(void) { return m_bVisible; } 00119 00122 virtual void SetVisible(bool bVisible); 00123 00126 virtual SDL_Surface* GetSDLSurface(void) { return m_pSDLSurface; } 00127 00130 virtual CRect ClientToView(const CRect& Rect) const; 00131 00134 virtual CPoint ClientToView(const CPoint& Point) const; 00135 00138 virtual CRect ViewToClient(const CRect& Rect) const; 00139 00142 virtual CPoint ViewToClient(const CPoint& Point) const; 00143 00146 virtual CRect ViewToWindow(const CRect& Rect) const; 00147 00150 virtual CPoint ViewToWindow(const CPoint& Point) const; 00151 00154 virtual void SetWindowText(const std::wstring& sText); 00155 00158 virtual std::wstring GetWindowText(void) { return m_sWindowText; } 00159 00163 virtual bool HitTest(const CPoint& Point) const; 00164 00166 virtual void Draw(void) const; 00167 00172 virtual void PaintToSurface(SDL_Surface& ScreenSurface, SDL_Surface& FloatingSurface, const CPoint& Offset) const; 00173 00176 virtual void SetNewParent(CWindow* pNewParent); 00177 00183 virtual bool OnMouseButtonDown(CPoint Point, unsigned int Button); 00184 00190 virtual bool OnMouseButtonUp(CPoint Point, unsigned int Button); 00191 00192 00193 // CMessageClient overrides 00197 virtual bool HandleMessage(CMessage* pMessage); 00198 00199 00200 protected: 00201 // Registering and Deregistering child windows is automatically handled by the constructors and destructors 00202 00205 virtual void RegisterChildWindow(CWindow* pWindow); 00206 00209 virtual void DeregisterChildWindow(CWindow* pWindow); 00210 00211 00213 std::wstring m_sWindowText; 00214 00216 CRect m_WindowRect; 00217 00219 CRGBColor m_BackgroundColor; 00220 00222 CRect m_ClientRect; 00223 00225 CWindow* m_pParentWindow; 00226 00228 std::list<CWindow*> m_ChildWindows; 00229 00231 SDL_Surface* m_pSDLSurface; 00232 00234 bool m_bVisible; 00235 00236 private: 00237 void operator=(CWindow) { } 00238 }; 00239 00240 } 00241 00242 00243 #include "unit_tests/wg_window_unittests.h" 00244 00245 #endif // _WG_WINDOW_H_ 00246