1 // NumEdit.cpp : implementation file
5 #include "logic_editor.h"
11 static char THIS_FILE
[] = __FILE__
;
14 /////////////////////////////////////////////////////////////////////////////
26 BEGIN_MESSAGE_MAP(CNumEdit
, CEdit
)
27 //{{AFX_MSG_MAP(CNumEdit)
30 ON_MESSAGE(WM_PASTE
, OnPaste
)
33 /////////////////////////////////////////////////////////////////////////////
34 // CNumEdit message handlers
36 void CNumEdit::OnChar(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
38 static const CString Holder
= "`~!@#$%^&*()_+|=\\qwertyuiop[]asdfghjkl;'zxcvbnm,/QWERTYUIOP{}ASDFGHJKL:/ZXCVBNM<>?/";
40 // 1st pass on unwanted characters
41 if (Holder
.Find(nChar
) != -1)
45 // length, selection info
46 int num_typed
= CEdit::GetWindowTextLength();
47 int start_char
, end_char
;
48 GetSel(start_char
, end_char
);
52 GetWindowText(temp_str
);
55 bool bSignTyped
= false;
56 bool bPeriodTyped
= false;
59 // most of the work done in here..
60 for (int i
= 0 ; i
< temp_str
.GetLength(); ++i
)
62 // selected chars don't count..
63 if ((i
>=start_char
) && (i
<end_char
))
66 temp_char
= temp_str
[i
];
68 if ((temp_char
== '+') || (temp_char
== '-')) {
70 } else if (temp_char
== '.') {
75 // allow sign only once (first char)
76 if ((nChar
== '+') || (nChar
== '-')) {
77 if (bSignTyped
|| (start_char
!= 0))
81 // allow period only once
82 if ((nChar
== '.') && bPeriodTyped
)
86 CString old_str
= temp_str
;
87 CEdit::OnChar(nChar
, nRepCnt
, nFlags
);
89 // check validity (if the user inserted numbers before the sign for example)
90 GetWindowText(temp_str
);
91 if ( (temp_str
.GetLength() > 1) && ( (temp_str
[1] == '-') || (temp_str
[1] == '+') ) )
93 this->SetWindowText( old_str
);
99 LRESULT
CNumEdit::OnPaste(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
101 static BOOL called
= FALSE
;
104 GetWindowText( old
);
106 /// \todo Malkav : handle pasting numeric data !!!
109 if (::IsClipboardFormatAvailable(CF_TEXT
))
112 char * str=(char*)GetClipboardData(CF_TEXT);
113 temp = old + CString(*str);;
117 // check validity of new text in the edit window
119 if (checkValidity() == FALSE)
129 BOOL
CNumEdit::checkValidity()
132 GetWindowText( temp
);
135 BOOL bPeriod
= FALSE
;
137 const int size
= temp
.GetLength();
138 for ( int i
= 0 ; i
< size
; ++i
)
140 if (temp
[i
] <0 && temp
[i
]>9)
144 else if (temp
[i
] == '-' || temp
[i
] =='+')
146 if ( (i
!= 0) || bSign
== TRUE
)
151 else if (temp
[i
] == '.')