Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CATGUI/CATControlWnd.cpp Source File

CATControlWnd.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \file CATControlWnd.cpp
00003 /// \brief Window / OS based control class - base object for OS dependant 
00004 /// controls.
00005 /// \ingroup CATGUI
00006 /// 
00007 /// Copyright (c) 2003-2008 by Michael Ellison.
00008 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00009 ///
00010 // $Author: mikeellison $
00011 // $Date: 2008-01-23 01:43:25 -0600 (Wed, 23 Jan 2008) $
00012 // $Revision:   $
00013 // $NoKeywords: $
00014 //---------------------------------------------------------------------------
00015 
00016 #include "CATControlWnd.h"
00017 #include "CATWindow.h"
00018 #include "CATOSFuncs.h"
00019 #include "CATApp.h"
00020 #include "CATEventDefs.h"
00021 
00022 // Constructor - mirrors CATXMLObject() constructor for now.
00023 CATControlWnd::CATControlWnd(  const CATString&               element, 
00024                              const CATString&               rootDir)
00025                              : CATControl(element, rootDir)
00026 {
00027     fControlWnd = 0;
00028     fFocusSet = false;
00029     fBorderSet = false;
00030     fCaptured = false;
00031 #ifdef CAT_CONFIG_WIN32
00032     fFGBrush = 0;
00033     fBGBrush = 0;
00034     fFGDisBrush = 0;
00035     fBGDisBrush = 0;
00036     fFGFocBrush = 0;
00037     fBGFocBrush = 0;
00038     fOldWndProc = 0;
00039 #endif // CAT_CONFIG_WIN32
00040 }
00041 
00042 CATControlWnd::~CATControlWnd()
00043 {
00044     if (fControlWnd != 0)
00045     {
00046         CATASSERT(false,"Parent MUST have called onParentDestroy() previously!");
00047         this->OnParentDestroy();
00048     }
00049 }
00050 
00051 // SetFocused() sets the control's focused state.
00052 //
00053 // \param focused - if true, then the control is given focus.
00054 //                  if false, focus is removed.      
00055 void CATControlWnd::SetFocused(bool focused)
00056 {
00057     bool wasFocused = fFocused;
00058 
00059     if (focused)
00060     {
00061         if ((fControlWnd) && (!wasFocused))
00062         {
00063             this->GetWindow()->OSSetFocus(fControlWnd);
00064             this->MarkDirty();
00065         }
00066     }
00067     else if (wasFocused)
00068     {      
00069         this->GetWindow()->OSSetFocus();
00070         this->MarkDirty();
00071     }
00072 
00073     CATControl::SetFocused(focused);
00074 }
00075 
00076 // MarkDirty() marks the control as dirty (needing to be redrawn)
00077 //
00078 // \param dirtyRect - if specified, marks only part of the rectangle
00079 // as dirty. Should be in window coordinates - i.e. 0,0 is top left in window,
00080 // not control.
00081 void CATControlWnd::MarkDirty(CATRect* dirtyRect, bool force)
00082 {   
00083     CATControl::MarkDirty(dirtyRect, force);
00084     if ((this->IsVisible()) || (force))
00085     {
00086         CATRect absRect = this->GetRectAbs();
00087 
00088         CATWND wnd = this->GetWindow()->OSGetWnd();
00089         if (wnd)
00090         {  
00091             CATInvalidateRect(wnd, absRect);
00092         }
00093     }
00094 
00095 }
00096 
00097 // Draw() draws the control into the parent window
00098 // \param dirtyRect - portion of control (in window coordinates)
00099 //        that requires redrawing.
00100 void CATControlWnd::Draw(CATImage* image, const CATRect& dirtyRect)
00101 {
00102 
00103 }
00104 
00105 // Event handler
00106 CATResult CATControlWnd::OnEvent(const CATEvent& event, CATInt32& retVal)
00107 {
00108     switch (event.fEventCode)
00109     {
00110     case CATEVENT_ENABLE_CHANGE:
00111         {
00112 #ifdef _WIN32
00113             ::EnableWindow(fControlWnd, this->IsEnabled()?TRUE:FALSE);
00114 #endif
00115         }   
00116         break;
00117     case CATEVENT_TAB_SHOW:
00118         {
00119 #ifdef _WIN32
00120             if ((this->fControlWnd) && (fVisible))
00121             {
00122                 ::ShowWindow(fControlWnd,SW_SHOW);
00123             }               
00124 #endif
00125             this->MarkDirty();
00126         }
00127         break;
00128 
00129     case CATEVENT_TAB_HIDE:
00130 #ifdef _WIN32
00131         if (this->fControlWnd)
00132         {
00133             ::ShowWindow(fControlWnd,SW_HIDE);
00134         }               
00135 #endif
00136         this->MarkDirty();
00137         break;
00138     }
00139     return CATControl::OnEvent(event,retVal);
00140 }
00141 
00142 
00143 void CATControlWnd::SetVisible(bool visible)
00144 {
00145     fVisible = visible;
00146 
00147     if (fControlWnd)
00148     {
00149         ::ShowWindow(fControlWnd, IsVisible()?SW_SHOW:SW_HIDE);     
00150     }
00151 
00152     MarkDirty(0,true);
00153 }
00154 
00155 // PostDraw() draws any stuff that requires an OS-specific draw
00156 // context.
00157 void CATControlWnd::PostDraw(CATDRAWCONTEXT drawContext, const CATRect& dirtyRect)
00158 {
00159     CATControl::PostDraw(drawContext, dirtyRect);
00160 }
00161 
00162 // GetPostRects() retrieves a rect, if any, that
00163 // should be reserved for post-draw style drawing.
00164 bool CATControlWnd::GetPostRects(CATStack<CATRect>& rectStack)
00165 {
00166 
00167     rectStack.Push(fWndRect);   
00168     return true;
00169 }
00170 
00171 
00172 // OnParentCreate() is called when the parent window is created.
00173 // 
00174 // Most controls won't need this, but any that create their own
00175 // windows should do so at this point.
00176 void CATControlWnd::OnParentCreate()
00177 {
00178     CATResult result = CAT_SUCCESS;
00179     if (CATFAILED(result = this->CreateControlWnd(fWindowType, fWindowStyle)))
00180     {
00181         if (this->GetWindow() != 0)
00182             this->GetWindow()->DisplayError(result);
00183         else
00184             gApp->DisplayError(result);
00185     }
00186 
00187     if (CATFAILED(result = OSCreate()))
00188     {
00189         if (this->GetWindow() != 0)
00190             this->GetWindow()->DisplayError(result);
00191         else
00192             gApp->DisplayError(result);
00193     }
00194 
00195     if (fControlWnd)
00196     {
00197         ::ShowWindow(fControlWnd,this->IsVisible()?SW_SHOW:SW_HIDE);
00198     }
00199 }
00200 
00201 
00202 // OnParentDestroy() is called as the parent window is destroyed.
00203 //
00204 // Controls that create their own windows during OnParentCreate()
00205 // should destroy them during OnParentDestroy()
00206 void CATControlWnd::OnParentDestroy()
00207 {
00208     if (this->fControlWnd)
00209     {
00210         this->GetWindow()->OSDestroyWnd(fControlWnd);
00211         fControlWnd = 0;
00212 
00213         OSCleanup();
00214     }
00215 }
00216 
00217 // RectFromAttribs() recalculates the control's rectangle from
00218 // the attributes.  This can only be called after ParseAttributes() has
00219 // loaded the images.
00220 CATResult CATControlWnd::RectFromAttribs()
00221 {
00222     CATResult result = CATControl::RectFromAttribs();
00223 
00224     fWndRect = this->GetRectAbs();
00225 
00226     if (this->fControlWnd)
00227     {
00228         this->GetWindow()->OSMoveWnd(fWndRect, fControlWnd);      
00229     }
00230 
00231     this->MarkDirty();   
00232     return result;
00233 }
00234 CATResult CATControlWnd::Load(          CATPROGRESSCB               progressCB,
00235                               void*                         progressParam,
00236                               CATFloat32                        progMin,
00237                               CATFloat32                        progMax)
00238 {
00239     CATResult result = CATControl::Load(progressCB, progressParam, progMin, progMax);
00240     if (fFocusSet == false)
00241     {
00242         this->fBGColor_focus = this->fBackgroundColor;
00243         this->fFGColor_focus = this->fForegroundColor;
00244     }
00245 
00246     if (fBorderSet == false)
00247     {
00248         this->fFGColor_border.r = 192;
00249         this->fFGColor_border.g = 192;
00250         this->fFGColor_border.b = 192;
00251         this->fBGColor_border.r = 64;
00252         this->fBGColor_border.g = 64;
00253         this->fBGColor_border.b = 64;
00254     }
00255 
00256     this->MarkDirty();   
00257     return result;
00258 }
00259 
00260 /// ParseAttributes() parses the known attributes for an object.
00261 CATResult CATControlWnd::ParseAttributes()
00262 {
00263     CATResult result = CATControl::ParseAttributes();
00264     CATString attrib;
00265 
00266     attrib = GetAttribute(L"ColorForeFocus");
00267     if (!attrib.IsEmpty())
00268     {
00269         // Values are RGB, not RGBA
00270         CATUInt32 rawColor = attrib.FromHex();
00271         this->fFGColor_focus.r = (CATUInt8)((rawColor & 0xff0000) >>16);
00272         this->fFGColor_focus.g = (CATUInt8)((rawColor & 0xff00) >> 8);
00273         this->fFGColor_focus.b = (CATUInt8)(rawColor & 0xff);
00274         this->fFGColor_focus.a = 255;
00275         fFocusSet = true;
00276     }   
00277 
00278     attrib = GetAttribute(L"ColorBackFocus");
00279     if (!attrib.IsEmpty())
00280     {
00281         // Values are RGB, not RGBA
00282         CATUInt32 rawColor = attrib.FromHex();
00283         this->fBGColor_focus.r = (CATUInt8)((rawColor & 0xff0000) >>16);
00284         this->fBGColor_focus.g = (CATUInt8)((rawColor & 0xff00) >> 8);
00285         this->fBGColor_focus.b = (CATUInt8)(rawColor & 0xff);
00286         this->fBGColor_focus.a = 255;      
00287         fFocusSet = true;
00288     }
00289 
00290     attrib = GetAttribute(L"ColorForeBorder");
00291     if (!attrib.IsEmpty())   
00292     {
00293         // Values are RGB, not RGBA
00294         CATUInt32 rawColor = attrib.FromHex();
00295         this->fFGColor_border.r = (CATUInt8)((rawColor & 0xff0000) >>16);
00296         this->fFGColor_border.g = (CATUInt8)((rawColor & 0xff00) >> 8);
00297         this->fFGColor_border.b = (CATUInt8)(rawColor & 0xff);
00298 
00299         this->fFGColor_border.a = 255;
00300         fBorderSet = true;
00301 
00302     }
00303 
00304     attrib = GetAttribute(L"ColorBackBorder");
00305     if (!attrib.IsEmpty())   
00306     {
00307         // Values are RGB, not RGBA
00308         CATUInt32 rawColor = attrib.FromHex();
00309         this->fBGColor_border.r = (CATUInt8)((rawColor & 0xff0000) >>16);
00310         this->fBGColor_border.g = (CATUInt8)((rawColor & 0xff00) >> 8);
00311         this->fBGColor_border.b = (CATUInt8)(rawColor & 0xff);
00312         this->fBGColor_border.a = 255;      
00313         fBorderSet = true;
00314     }
00315 
00316     return result;
00317 }
00318 
00319 // GetColorFore() retrieves the foreground color for the control
00320 // \return CATColor - foreground color
00321 CATColor CATControlWnd::GetColorFore() const
00322 {
00323     if (this->fFocused)
00324     {
00325         return this->fFGColor_focus;
00326     }
00327     else if (this->IsEnabled() == false)
00328     {  
00329         return this->fFgDisColor;
00330     }
00331     else
00332     {
00333         return this->fForegroundColor;
00334     }
00335 }
00336 
00337 // GetColorBack() retrieves the background color for the control
00338 // \return CATColor - background color
00339 CATColor CATControlWnd::GetColorBack() const
00340 {
00341     if (this->fFocused)
00342     {
00343         return this->fBGColor_focus;
00344     }
00345     else if (this->IsEnabled() == false)
00346     {  
00347         return this->fBgDisColor;
00348     }
00349     else
00350     {
00351         return this->fBackgroundColor;
00352     }
00353 }
00354 
00355 void CATControlWnd::SetEnabled(bool enabled)
00356 {
00357     CATGuiObj::SetEnabled(enabled);
00358 #ifdef _WIN32
00359     if (fControlWnd != 0)
00360     {
00361         ::EnableWindow(fControlWnd,this->IsEnabled());
00362     }
00363 #endif
00364 }
00365 
00366 CATString CATControlWnd::GetHint() const
00367 {
00368     return CATControl::GetHint();
00369 }
00370 
00371 

Generated on Mon Feb 11 04:09:52 2008 for Game Accessibility Suite by doxygen 1.5.4