refine the wxEVT_TEXT_MAXLEN event handle implementation

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77823 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-09-23 17:42:23 +00:00
parent 55eed80313
commit cc93948936

View File

@@ -4557,21 +4557,20 @@ bool wxTextCtrl::PerformAction(const wxControlAction& actionOrig,
{
if ( IsEditable() && !strArg.empty() )
{
wxString acceptString = strArg;
bool isTextClipped = m_maxLength && (m_value.length() + strArg.length() > m_maxLength);
const wxString& acceptedString = isTextClipped ? strArg.Left(m_maxLength - m_value.length())
: strArg;
unsigned long acceptableLength = m_maxLength - m_value.Length();
if ( m_maxLength > 0 && (strArg.Length() > acceptableLength) )
if ( isTextClipped ) // text was clipped so emit wxEVT_TEXT_MAXLEN
{
wxCommandEvent event(wxEVT_TEXT_MAXLEN, m_windowId);
InitCommandEvent(event);
GetEventHandler()->ProcessEvent(event);
acceptString = strArg.Left(acceptableLength);
}
if ( acceptString.Length() > 0 )
// inserting text can be undone
command = new wxTextCtrlInsertCommand(acceptString);
if ( !acceptedString.empty() )
// inserting text can be undone
command = new wxTextCtrlInsertCommand(acceptedString);
}
}