X64 transport [Part 5] (Update plugins.cpp)
[xy_vsfilter.git] / src / apps / mplayerc / FloatEdit.cpp
blobf437d89eaeabeec08f4f80603f55327dafe22d49
1 /*
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)
8 * any later version.
9 *
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
22 #include "stdafx.h"
23 #include "floatedit.h"
25 // CFloatEdit
27 IMPLEMENT_DYNAMIC(CFloatEdit, CEdit)
29 bool CFloatEdit::GetFloat(float& f)
31 CString s;
32 GetWindowText(s);
33 return(_stscanf(s, _T("%f"), &f) == 1);
36 double CFloatEdit::operator = (double d)
38 CString s;
39 s.Format(_T("%.4f"), d);
40 SetWindowText(s);
41 return(d);
44 CFloatEdit::operator double()
46 CString s;
47 GetWindowText(s);
48 float f;
49 return(_stscanf(s, _T("%f"), &f) == 1 ? f : 0);
52 BEGIN_MESSAGE_MAP(CFloatEdit, CEdit)
53 ON_WM_CHAR()
54 END_MESSAGE_MAP()
56 void CFloatEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
58 if(!(nChar >= '0' && nChar <= '9' || nChar == '.' || nChar == '\b'))
59 return;
61 CString str;
62 GetWindowText(str);
64 if(nChar == '.' && (str.Find('.') >= 0 || str.IsEmpty()))
65 return;
67 int nStartChar, nEndChar;
68 GetSel(nStartChar, nEndChar);
70 if(nChar == '\b' && nStartChar <= 0)
71 return;
73 CEdit::OnChar(nChar, nRepCnt, nFlags);
76 // CIntEdit
78 IMPLEMENT_DYNAMIC(CIntEdit, CEdit)
80 BEGIN_MESSAGE_MAP(CIntEdit, CEdit)
81 ON_WM_CHAR()
82 END_MESSAGE_MAP()
84 void CIntEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
86 if(!(nChar >= '0' && nChar <= '9' || nChar == '-' || nChar == '\b'))
87 return;
89 CString str;
90 GetWindowText(str);
92 if(nChar == '-' && !str.IsEmpty() && str[0] == '-')
93 return;
95 int nStartChar, nEndChar;
96 GetSel(nStartChar, nEndChar);
98 if(nChar == '\b' && nStartChar <= 0)
99 return;
101 if(nChar == '-' && (nStartChar != 0 || nEndChar != 0))
102 return;
104 CEdit::OnChar(nChar, nRepCnt, nFlags);
107 // CHexEdit
109 IMPLEMENT_DYNAMIC(CHexEdit, CEdit)
111 bool CHexEdit::GetDWORD(DWORD& dw)
113 CString s;
114 GetWindowText(s);
115 return(_stscanf(s, _T("%x"), &dw) == 1);
118 DWORD CHexEdit::operator = (DWORD dw)
120 CString s;
121 s.Format(_T("%08x"), dw);
122 SetWindowText(s);
123 return(dw);
126 CHexEdit::operator DWORD()
128 CString s;
129 GetWindowText(s);
130 DWORD dw;
131 return(_stscanf(s, _T("%x"), &dw) == 1 ? dw : 0);
134 BEGIN_MESSAGE_MAP(CHexEdit, CEdit)
135 ON_WM_CHAR()
136 END_MESSAGE_MAP()
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'))
142 return;
144 CString str;
145 GetWindowText(str);
147 int nStartChar, nEndChar;
148 GetSel(nStartChar, nEndChar);
150 if(nChar == '\b' && nStartChar <= 0)
151 return;
153 if(nChar != '\b' && nEndChar - nStartChar == 0 && str.GetLength() >= 8)
154 return;
156 CEdit::OnChar(nChar, nRepCnt, nFlags);