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

CATAppButton.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \file CATAppButton.cpp
00003 /// \brief Specialized pushbutton for launching apps
00004 /// \ingroup CATGUI
00005 /// 
00006 /// Copyright (c) 2003-2008 by Michael Ellison.
00007 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00008 ///
00009 // $Author: mikeellison $
00010 // $Date: 2008-01-30 06:11:10 -0600 (Wed, 30 Jan 2008) $
00011 // $Revision:   $
00012 // $NoKeywords: $
00013 //---------------------------------------------------------------------------
00014 #include "CATAppButton.h"
00015 #include "CATWindow.h"
00016 #include "CATOSFuncs.h"
00017 //---------------------------------------------------------------------------
00018 /// CATAppButton constructor (inherited from CATControl->CATXMLObject)
00019 /// \param element - Type name ("Button")
00020 /// \param rootDir - root directory of skin
00021 //---------------------------------------------------------------------------
00022 CATAppButton::CATAppButton(  const CATString&             element, 
00023                              const CATString&             rootDir)
00024 : CATButton(element, rootDir)
00025 {
00026     fIconImage = 0;    
00027     fBorder = 0;
00028 }
00029 
00030 
00031 
00032 //---------------------------------------------------------------------------
00033 /// CATAppButton destructor
00034 //---------------------------------------------------------------------------
00035 CATAppButton::~CATAppButton()
00036 {
00037     if (fIconImage)
00038     {
00039 #ifdef _WIN32
00040         DeleteObject(fIconImage);  
00041 #endif
00042     }
00043 }
00044 
00045 
00046 /// ParseAttributes() parses the known attributes for an object.
00047 CATResult CATAppButton::ParseAttributes()
00048 {
00049     CATResult result = CATButton::ParseAttributes();
00050     fAppPath = GetAttribute(L"AppPath");
00051     
00052     bool found = false;
00053     if (!fAppPath.IsEmpty())
00054     {
00055         CATResult tmpResult = OSLoadIconImage(fAppPath,&fIconImage,fAppName);
00056         
00057         this->fHintText = GetAttribute(L"HintText");
00058 
00059         if (CATSUCCEEDED(tmpResult))
00060         {
00061             fHintText << fAppName;
00062             found = true;
00063         }
00064     }
00065 
00066     fBorder = GetAttribute(L"Border",fBorder);
00067 
00068     CATString uninstId = GetAttribute(L"UninstallId");
00069     CATString appFile  = GetAttribute(L"AppFile");
00070 
00071     if ( (!appFile.IsEmpty()) && (!uninstId.IsEmpty()))
00072     {
00073         fAppPath = GetInstallLoc(uninstId);        
00074         if (fAppPath.GetWChar(fAppPath.Length()-1) != '\\')
00075             fAppPath << L"\\";
00076 
00077         fAppPath << appFile;
00078         
00079         CATResult tmpResult = OSLoadIconImage(fAppPath,&fIconImage,fAppName);
00080         
00081         this->fHintText = GetAttribute(L"HintText");
00082 
00083         if (CATSUCCEEDED(tmpResult))
00084         {
00085             this->AddAttribute(L"AppPath",fAppPath);
00086             fHintText << fAppName;
00087             found = true;
00088         }
00089     }
00090 
00091     if (!found)
00092     {
00093         CATString regPath = GetAttribute(L"RegPath");
00094 
00095         if (!appFile.IsEmpty() && (!regPath.IsEmpty()))
00096         {
00097             fAppPath = GetSoftwareReg(regPath);
00098             if (fAppPath.GetWChar(fAppPath.Length()-1) != '\\')
00099                 fAppPath << L"\\";
00100 
00101             fAppPath << appFile;
00102             
00103             CATResult tmpResult = OSLoadIconImage(fAppPath,&fIconImage,fAppName);
00104             
00105             this->fHintText = GetAttribute(L"HintText");
00106 
00107             if (CATSUCCEEDED(tmpResult))
00108             {
00109                 this->AddAttribute(L"AppPath",fAppPath);
00110                 fHintText << fAppName;
00111                 found = true;
00112             }
00113         }
00114     }
00115 
00116     if (!found)
00117         this->SetEnabled(false);
00118 
00119     return CAT_SUCCESS;
00120 }
00121 
00122 /// Draw() draws the control into the parent's image
00123 /// \param image - parent image to draw into
00124 /// \param dirtyRect - portion of control (in window coordinates)
00125 ///        that requires redrawing.
00126 void CATAppButton::Draw(CATImage* image, const CATRect& dirtyRect)
00127 {
00128     CATButton::Draw(image,dirtyRect);
00129 }
00130 
00131 void CATAppButton::PostDraw(CATDRAWCONTEXT drawContext, const CATRect& dirtyRect)
00132 {
00133     if ((this->IsVisible() == false) || (!fIconImage))
00134     {
00135         return;
00136     }
00137 
00138     CATRect drawRect = fRect;
00139 
00140     this->GetWindow()->WidgetToWindow(this,drawRect);    
00141 
00142     drawRect.left   += fBorder;
00143     drawRect.right  -= fBorder;
00144     drawRect.bottom -= fBorder;
00145     drawRect.top    += fBorder;
00146 
00147     if (fPressed)
00148     {
00149         drawRect.left += fTextOffsetPressed.x;
00150         drawRect.top  += fTextOffsetPressed.y;
00151     }
00152     else
00153     {
00154         drawRect.right  -= fTextOffsetPressed.x;
00155         drawRect.bottom -= fTextOffsetPressed.y;
00156     }
00157 
00158     ::DrawIconEx(drawContext,
00159                  drawRect.left,
00160                  drawRect.top,
00161                  fIconImage,
00162                  drawRect.Width(), 
00163                  drawRect.Height(),
00164                  0,
00165                  NULL,
00166                  DI_NORMAL);
00167 
00168     CATButton::PostDraw(drawContext,dirtyRect);
00169 }

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