1 /*
2  * The olsr.org Optimized Link-State Routing daemon (olsrd)
3  *
4  * (c) by the OLSR project
5  *
6  * See our Git repository to find out who worked on this file
7  * and thus is a copyright holder on it.
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  *   notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above copyright
18  *   notice, this list of conditions and the following disclaimer in
19  *   the documentation and/or other materials provided with the
20  *   distribution.
21  * * Neither the name of olsr.org, olsrd nor the names of its
22  *   contributors may be used to endorse or promote products derived
23  *   from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  *
38  * Visit http://www.olsr.org for more information.
39  *
40  * If you find this software useful feel free to make a donation
41  * to the project. For more information see the website or contact
42  * the copyright holders.
43  *
44  */
45 
46 #ifdef _WIN32
47 
48 #include "stdafx.h"
49 #include "frontend.h"
50 #include "MyEdit.h"
51 
52 #ifdef _DEBUG
53 #define new DEBUG_NEW
54 #undef THIS_FILE
55 static char THIS_FILE[] = __FILE__;
56 #endif /* _DEBUG */
57 
MyEdit()58 MyEdit::MyEdit()
59 {
60 }
61 
~MyEdit()62 MyEdit::~MyEdit()
63 {
64 }
65 
66 
BEGIN_MESSAGE_MAP(MyEdit,CEdit)67 BEGIN_MESSAGE_MAP(MyEdit, CEdit)
68 	//{{AFX_MSG_MAP(MyEdit)
69 	ON_WM_CHAR()
70 	ON_WM_KILLFOCUS()
71 	//}}AFX_MSG_MAP
72 END_MESSAGE_MAP()
73 
74 void MyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
75 {
76 	static unsigned char *Allowed = (unsigned char *)"0123456789.";
77 	int i;
78 	CString Text;
79 
80 	if (nChar >= 32)
81 	{
82 		for (i = 0; Allowed[i] != 0; i++)
83 			if (nChar == Allowed[i])
84 				break;
85 
86 		if (Allowed[i] == 0)
87 			return;
88 
89 		GetWindowText(Text);
90 
91 		if (nChar == '.' && Text.Find('.') >= 0)
92 			return;
93 
94 		if (Text.GetLength() > 2 && Text.Find('.') < 0 && nChar != '.')
95 			return;
96 	}
97 
98 	CEdit::OnChar(nChar, nRepCnt, nFlags);
99 }
100 
OnKillFocus(CWnd * pNewWnd)101 void MyEdit::OnKillFocus(CWnd* pNewWnd)
102 {
103 	CString Text;
104 	int Index;
105 	int Len;
106 
107 	GetWindowText(Text);
108 
109 	Index = Text.Find('.');
110 
111 	Len = Text.GetLength();
112 
113 	if (Len == 0)
114 		SetWindowText("0.0");
115 
116 	else if (Index < 0)
117 		SetWindowText(Text + ".0");
118 
119 	else if (Index == Len - 1)
120 		SetWindowText(Text + "0");
121 
122 	CEdit::OnKillFocus(pNewWnd);
123 }
124 
125 #endif /* _WIN32 */
126