1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 // DoubleEdit.cpp: implementation of the CDoubleEdit class.
27 //////////////////////////////////////////////////////////////////////
30 #include "DoubleEdit.h"
36 static char THIS_FILE[] = __FILE__;
39 //////////////////////////////////////////////////////////////////////
40 // Construction/Destruction
41 //////////////////////////////////////////////////////////////////////
43 CDoubleEdit::CDoubleEdit(double dInitialValue):
44 CCellEdit(CUtils::DoubleToStr (dInitialValue))
48 CDoubleEdit::~CDoubleEdit()
53 BEGIN_MESSAGE_MAP(CDoubleEdit, CCellEdit)
54 //{{AFX_MSG_MAP(CDoubleEdit)
55 ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate)
59 /////////////////////////////////////////////////////////////////////////////
60 // CDoubleEdit message handlers
62 void CDoubleEdit::OnUpdate()
65 GetWindowText (strValue);
67 if (strValue.IsEmpty () || CUtils::StrToDouble (strValue, dValue) || _T("-")==strValue ||
68 CUtils::StrToDouble (TrimRightNoCase (strValue, _T("e")), dValue) ||
69 CUtils::StrToDouble (TrimRightNoCase (strValue, _T("e+")), dValue) ||
70 CUtils::StrToDouble (TrimRightNoCase (strValue, _T("e-")), dValue)) // cell text is legal
72 m_strPrevText = strValue;
74 else // cell text is not legal so revert to previous text
76 MessageBeep (0xFFFFFFFF);
77 const CPoint pt (GetCaretPos ());
78 SetWindowText (m_strPrevText);
83 CString CDoubleEdit::TrimRightNoCase (const CString & strInput, LPCTSTR lpszTrimChars)
85 const CString strTrim = lpszTrimChars;
86 if (0 == strInput.Right (strTrim.GetLength ()).CompareNoCase (strTrim))
87 return strInput.Left (strInput.GetLength () - strTrim.GetLength ());
92 BOOL CDoubleEdit::PreCreateWindow(CREATESTRUCT& cs)
99 return CCellEdit::PreCreateWindow(cs);