2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 #include "floatedit.h"
27 IMPLEMENT_DYNAMIC(CFloatEdit
, CEdit
)
29 bool CFloatEdit::GetFloat(float& f
)
33 return(_stscanf(s
, _T("%f"), &f
) == 1);
36 double CFloatEdit::operator = (double d
)
39 s
.Format(_T("%.4f"), d
);
44 CFloatEdit::operator double()
49 return(_stscanf(s
, _T("%f"), &f
) == 1 ? f
: 0);
52 BEGIN_MESSAGE_MAP(CFloatEdit
, CEdit
)
56 void CFloatEdit::OnChar(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
58 if(!(nChar
>= '0' && nChar
<= '9' || nChar
== '.' || nChar
== '\b'))
64 if(nChar
== '.' && (str
.Find('.') >= 0 || str
.IsEmpty()))
67 int nStartChar
, nEndChar
;
68 GetSel(nStartChar
, nEndChar
);
70 if(nChar
== '\b' && nStartChar
<= 0)
73 CEdit::OnChar(nChar
, nRepCnt
, nFlags
);
78 IMPLEMENT_DYNAMIC(CIntEdit
, CEdit
)
80 BEGIN_MESSAGE_MAP(CIntEdit
, CEdit
)
84 void CIntEdit::OnChar(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
86 if(!(nChar
>= '0' && nChar
<= '9' || nChar
== '-' || nChar
== '\b'))
92 if(nChar
== '-' && !str
.IsEmpty() && str
[0] == '-')
95 int nStartChar
, nEndChar
;
96 GetSel(nStartChar
, nEndChar
);
98 if(nChar
== '\b' && nStartChar
<= 0)
101 if(nChar
== '-' && (nStartChar
!= 0 || nEndChar
!= 0))
104 CEdit::OnChar(nChar
, nRepCnt
, nFlags
);
109 IMPLEMENT_DYNAMIC(CHexEdit
, CEdit
)
111 bool CHexEdit::GetDWORD(DWORD
& dw
)
115 return(_stscanf(s
, _T("%x"), &dw
) == 1);
118 DWORD
CHexEdit::operator = (DWORD dw
)
121 s
.Format(_T("%08x"), dw
);
126 CHexEdit::operator DWORD()
131 return(_stscanf(s
, _T("%x"), &dw
) == 1 ? dw
: 0);
134 BEGIN_MESSAGE_MAP(CHexEdit
, CEdit
)
138 void CHexEdit::OnChar(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
140 if(!(nChar
>= 'A' && nChar
<= 'F' || nChar
>= 'a' && nChar
<= 'f'
141 || nChar
>= '0' && nChar
<= '9' || nChar
== '\b'))
147 int nStartChar
, nEndChar
;
148 GetSel(nStartChar
, nEndChar
);
150 if(nChar
== '\b' && nStartChar
<= 0)
153 if(nChar
!= '\b' && nEndChar
- nStartChar
== 0 && str
.GetLength() >= 8)
156 CEdit::OnChar(nChar
, nRepCnt
, nFlags
);