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:
@@ -4557,21 +4557,20 @@ bool wxTextCtrl::PerformAction(const wxControlAction& actionOrig,
|
|||||||
{
|
{
|
||||||
if ( IsEditable() && !strArg.empty() )
|
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 ( isTextClipped ) // text was clipped so emit wxEVT_TEXT_MAXLEN
|
||||||
|
|
||||||
if ( m_maxLength > 0 && (strArg.Length() > acceptableLength) )
|
|
||||||
{
|
{
|
||||||
wxCommandEvent event(wxEVT_TEXT_MAXLEN, m_windowId);
|
wxCommandEvent event(wxEVT_TEXT_MAXLEN, m_windowId);
|
||||||
InitCommandEvent(event);
|
InitCommandEvent(event);
|
||||||
GetEventHandler()->ProcessEvent(event);
|
GetEventHandler()->ProcessEvent(event);
|
||||||
acceptString = strArg.Left(acceptableLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( acceptString.Length() > 0 )
|
if ( !acceptedString.empty() )
|
||||||
// inserting text can be undone
|
// inserting text can be undone
|
||||||
command = new wxTextCtrlInsertCommand(acceptString);
|
command = new wxTextCtrlInsertCommand(acceptedString);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user