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

CATEditBox.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \file CATEditBox.cpp
00003 /// \brief Text edit box for GUI
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-23 01:43:25 -0600 (Wed, 23 Jan 2008) $
00011 // $Revision:   $
00012 // $NoKeywords: $
00013 //---------------------------------------------------------------------------
00014 #include "CATEditBox.h"
00015 #include "CATWindow.h"
00016 #include "CATEventDefs.h"
00017 
00018 /// ParseAttributes() parses the known attributes for an object.
00019 CATResult CATEditBox::ParseAttributes()
00020 {
00021     CATResult result = CATControlWnd::ParseAttributes();
00022     CATString attrib;
00023 
00024     fReadOnly    = GetAttribute(L"ReadOnly", fReadOnly);
00025     fNumbersOnly = GetAttribute(L"NumbersOnly", fNumbersOnly);
00026     fMaxLength   = GetAttribute(L"MaxLength", fMaxLength);
00027 
00028     if (fMaxLength > 0x7FFE)
00029         fMaxLength = 0x7FFE;
00030 
00031     return result;
00032 }
00033 
00034 void CATEditBox::SetFocused(bool focused)
00035 {
00036     if ((focused == false) && (this->fFocused))
00037     {
00038         CATString oldParam = fCmdParam;
00039         // Loosing focus... store parameter.
00040         this->OSGetText(fCmdParam);
00041 
00042         if (oldParam.Compare(fCmdParam) != 0)
00043         {
00044             ((CATGuiObj*)fParent)->OnCommand(this->GetCommand(), this);
00045         }
00046     }
00047     else if ((focused) && (!fFocused))
00048     {      
00049         this->OSSelectAll();
00050     }
00051 
00052     CATControlWnd::SetFocused(focused);
00053 }
00054 
00055 void CATEditBox::OnEscapeChange()
00056 {
00057     SetString(this->fCmdParam);
00058     this->MarkDirty();
00059 }
00060 
00061 void CATEditBox::SetString(const CATString& newString)
00062 {
00063     this->fCmdParam = newString;
00064     this->fValue    = (CATFloat32)newString;
00065     this->OSSetText(fCmdParam);
00066     this->MarkDirty();
00067 }
00068 
00069 CATString CATEditBox::GetString() const
00070 {
00071     return this->fCmdParam;
00072 }
00073 
00074 CATResult CATEditBox::OnEvent(const CATEvent& event, CATInt32& retVal)
00075 {
00076     switch (event.fEventCode)
00077     {
00078     case  CATEVENT_GUI_VAL_CHANGE:
00079         // If our command string is the same as the GUI value, then
00080         // we should ensure that our value matches the one
00081         // in the event.
00082         //
00083         // fStringParam1 - command string
00084         // fStringParam2 - String parameter of command
00085         // fStringParam3 - String value of command, or empty if none
00086         // fFloatParam1  - Value of control
00087         // fVoidParam - ptr to control that caused it, or null.
00088         if (this->fCmdString.Compare(event.fStringParam1) == 0)
00089         {
00090             // MAke sure we're not the control that sent it...
00091             if (this != (CATControl*)event.fVoidParam)
00092             {
00093                 this->SetString(event.fStringParam3);
00094                 this->SetValue(event.fFloatParam1, false);
00095                 retVal++;
00096             }
00097         }
00098         break;
00099     default:
00100         return CATControlWnd::OnEvent(event,retVal);
00101     }
00102     return CAT_SUCCESS;
00103 }
00104 
00105 CATFloat32 CATEditBox::GetValue() const
00106 {
00107     return (CATFloat32)this->GetString();
00108 }
00109 
00110 CATString CATEditBox::GetHint() const
00111 {
00112     CATString retString;
00113     retString = CATControlWnd::GetHint();
00114 
00115     if (fShowHintValue)
00116     {
00117         retString << " (" << this->GetString() << " )";
00118     }
00119     return retString;
00120 }
00121 
00122 bool CATEditBox::IsReadOnly()
00123 {
00124     return fReadOnly;
00125 }
00126 
00127 void CATEditBox::SetReadOnly(bool readOnly)
00128 {
00129     OSSetReadOnly(readOnly);
00130     fReadOnly = readOnly;
00131 }
00132 

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