From: <sag...@us...> - 2015-06-02 15:09:23
|
Revision: 5238 http://sourceforge.net/p/modplug/code/5238 Author: saga-games Date: 2015-06-02 15:09:17 +0000 (Tue, 02 Jun 2015) Log Message: ----------- [Fix] Properly handle pasted characters in CDecimalSupport Modified Paths: -------------- trunk/OpenMPT/mptrack/CDecimalSupport.cpp trunk/OpenMPT/mptrack/CDecimalSupport.h Modified: trunk/OpenMPT/mptrack/CDecimalSupport.cpp =================================================================== --- trunk/OpenMPT/mptrack/CDecimalSupport.cpp 2015-06-02 14:23:15 UTC (rev 5237) +++ trunk/OpenMPT/mptrack/CDecimalSupport.cpp 2015-06-02 15:09:17 UTC (rev 5238) @@ -16,6 +16,7 @@ BEGIN_MESSAGE_MAP(CNumberEdit, CEdit) ON_WM_CHAR() + ON_MESSAGE(WM_PASTE, OnPaste) END_MESSAGE_MAP() @@ -43,4 +44,16 @@ if(!bHandled) CEdit::OnChar(nChar , nRepCnt, nFlags); } + +LPARAM CNumberEdit::OnPaste(WPARAM wParam, LPARAM lParam) +//------------------------------------------------------- +{ + bool bHandled = false; + CDecimalSupport<CNumberEdit>::OnPaste(0, wParam, lParam, bHandled); + if(!bHandled) + return CEdit::DefWindowProc(WM_PASTE, wParam, lParam); + else + return 0; +} + OPENMPT_NAMESPACE_END \ No newline at end of file Modified: trunk/OpenMPT/mptrack/CDecimalSupport.h =================================================================== --- trunk/OpenMPT/mptrack/CDecimalSupport.h 2015-06-02 14:23:15 UTC (rev 5237) +++ trunk/OpenMPT/mptrack/CDecimalSupport.h 2015-06-02 15:09:17 UTC (rev 5238) @@ -51,7 +51,7 @@ /// the locale dependant negative sign TCHAR m_NegativeSign[6]; - bool allowNegative, allowFractions; + bool m_allowNegative, m_allowFractions; public: @@ -67,8 +67,8 @@ /// \brief Initialize m_DecimalSeparator and m_NegativeSign /// \remarks calls InitDecimalSeparator and InitNegativeSign CDecimalSupport() - : allowNegative(true) - , allowFractions(true) + : m_allowNegative(true) + , m_allowFractions(true) { InitDecimalSeparator(); InitNegativeSign(); @@ -99,7 +99,7 @@ /// \param lParam /// \param[out] bHandled true, if the text is a valid number /// \return 0 - LRESULT OnPaste(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/,BOOL& bHandled) + LRESULT OnPaste(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, bool &bHandled) { bHandled = false; int neg_sign = 0; @@ -108,15 +108,15 @@ T* pT = static_cast<T*>(this); int nStartChar; int nEndChar; - pT->GetSel(nStartChar , nEndChar); + pT->GetSel(nStartChar, nEndChar); TCHAR buffer[limit]; pT->GetWindowText(buffer, limit); - // Check if the texr already contains a decimal point + // Check if the text already contains a decimal point for (TCHAR* x = buffer; *x; ++x) { if (x - buffer == nStartChar) x += nEndChar - nStartChar; - if (*x == m_DecimalSeparator[0]) ++dec_point; + if (*x == m_DecimalSeparator[0] ||*x == _T('.')) ++dec_point; if (*x == m_NegativeSign[0]) ++neg_sign; } @@ -138,6 +138,7 @@ LPTSTR lptstr = reinterpret_cast<TCHAR*>(GlobalLock(hglb)); if (lptstr != NULL) { + bHandled = true; for (TCHAR* s = lptstr; *s; ++s) { if (*s == m_NegativeSign[0]) @@ -150,14 +151,14 @@ if (neg_sign || nStartChar > 0) { - bHandled = true; + bHandled = false; break; } ++neg_sign; continue; } - if (*s == m_DecimalSeparator[0]) + if (*s == m_DecimalSeparator[0] || *s == _T('.')) { for (TCHAR* t = m_DecimalSeparator + 1; *t ; ++t, ++s) { @@ -166,7 +167,7 @@ if (dec_point) { - bHandled = true; + bHandled = false; break; } ++dec_point; @@ -175,11 +176,12 @@ if (*s < _T('0') || *s > _T('9')) { - bHandled = true; + bHandled = false; break; } } + if(bHandled) pT->ReplaceSel(lptstr, true); GlobalUnlock(hglb); @@ -200,7 +202,7 @@ LRESULT OnChar(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) { bHandled = false; - if (static_cast<TCHAR>(wParam) == m_DecimalSeparator[0] || wParam == _T('.') && allowFractions) + if (static_cast<TCHAR>(wParam) == m_DecimalSeparator[0] || wParam == _T('.') && m_allowFractions) { T* pT = static_cast<T*>(this); int nStartChar; @@ -219,7 +221,7 @@ bHandled = true; } - if (static_cast<TCHAR>(wParam) == m_NegativeSign[0] && allowNegative) + if (static_cast<TCHAR>(wParam) == m_NegativeSign[0] && m_allowNegative) { T* pT = static_cast<T*>(this); int nStartChar; @@ -357,17 +359,17 @@ szBuff[pos] = digits[i]; if (digits[i] != '0') last_nonzero = pos+1; } - szBuff[std::min(buflen - 1,last_nonzero)] = _T('\0'); + szBuff[std::min(buflen - 1, last_nonzero)] = _T('\0'); } void AllowNegative(bool allow) { - allowNegative = allow; + m_allowNegative = allow; } void AllowFractions(bool allow) { - allowFractions = allow; + m_allowFractions = allow; } }; @@ -381,6 +383,7 @@ protected: afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); + afx_msg LPARAM OnPaste(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |