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

CATEditBox_Win32.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \file CATEditBox_Win32.cpp
00003 /// \brief Text edit box for GUI (win32 implementation)
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 //---------------------------------------------------------------------------
00015 #include "CATEditBox.h"
00016 #include "CATWindow.h"
00017 #include "CATEventDefs.h"
00018 
00019 CATEditBox::CATEditBox(  const CATString&             element, 
00020                        const CATString&             rootDir)
00021                        : CATControlWnd(element,  rootDir)
00022 {
00023     this->fWindowStyle = WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | ES_AUTOHSCROLL;
00024     this->fWindowType = "EDIT";
00025     fReadOnly = false;
00026     fNumbersOnly = false;
00027     fFont = 0;   
00028     fMaxLength = kDefEditMaxLength;
00029 }
00030 
00031 CATEditBox::~CATEditBox()
00032 {   
00033 }
00034 
00035 bool CATEditBox::OnControlEvent( const CATEvent& event,  CATInt32& result)                                       
00036 {   
00037     switch (event.fEventCode)
00038     {      
00039     case CATEVENT_WINDOWS_EVENT:
00040         switch (event.fIntParam2)
00041         {
00042         case WM_SETFOCUS:
00043             if (event.fIntParam1 == (CATInt32)this->fControlWnd)
00044             {                  
00045                 CATInt32 retVal = 0;
00046                 // allow parent to handle event if it wishes
00047                 this->GetWindow()->OnEvent(
00048                     CATEvent(   CATEVENT_ON_EDITBOX_SELECT,
00049                     0,0,0,0,
00050                     this->fValue,
00051                     this->GetString(),
00052                     this->fCmdString,
00053                     this->fCmdParam,                                                            
00054                     this), retVal);
00055 
00056                 if (retVal == 0)
00057                 {                           
00058                     this->OSSelectAll();
00059                 }
00060                 else
00061                 {
00062                     this->GetWindow()->KillFocus();
00063                     return true;
00064                 }
00065                 result = 0;
00066                 return false;
00067             }
00068             break;
00069         }
00070         break;
00071     }
00072 
00073 
00074     return false;
00075 }
00076 
00077 
00078 void CATEditBox::OnParentCreate()
00079 {
00080     if (this->fMultiline == true)
00081     {
00082         fWindowStyle = WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | ES_MULTILINE  | WS_VSCROLL | ES_AUTOVSCROLL;
00083         fShowHintValue = false;      
00084     }
00085     else
00086     {
00087         fWindowStyle = WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | ES_AUTOHSCROLL;
00088     }
00089 
00090     if (this->fReadOnly == true)
00091     {
00092         fWindowStyle |= ES_READONLY;
00093     }
00094 
00095     if (this->fNumbersOnly)
00096     {
00097         fWindowStyle |= ES_NUMBER;
00098     }
00099 
00100     CATControlWnd::OnParentCreate();
00101 
00102     this->OSSetText(fCmdParam);
00103 
00104     fFont = GetWindow()->OSGetFont(fFontName,fFontSize);   
00105     ::SendMessage(fControlWnd,WM_SETFONT,(WPARAM)fFont,TRUE);         
00106     ::SendMessage(fControlWnd,EM_LIMITTEXT, (WPARAM)fMaxLength,0);
00107 }
00108 
00109 void CATEditBox::OnParentDestroy()
00110 {
00111     if (fFont != 0)
00112     {
00113         GetWindow()->OSReleaseFont(fFont);
00114     }
00115 
00116     CATControlWnd::OnParentDestroy();
00117 }
00118 
00119 void CATEditBox::OSSelectAll()
00120 {
00121     ::PostMessage(fControlWnd, EM_SETSEL,0,-1);
00122 }
00123 
00124 void CATEditBox::OSSetReadOnly(bool readOnly)
00125 {       
00126     SendMessage(fControlWnd, EM_SETREADONLY, readOnly?TRUE:FALSE,0);
00127 }

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