From: Kevin Hock Date: Thu, 2 Dec 2004 21:35:40 +0000 (+0000) Subject: Honor value of SetMaxLength, at least when typing (pasting still circumvents it)... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/bdf0c19c6e8e1adf406a647d65eae781f6417c8c Honor value of SetMaxLength, at least when typing (pasting still circumvents it). This is done by eating non-navigation/delete characters in OnChar. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30847 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index d1b9fa2325..3b06665ebf 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -791,6 +791,16 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) return ; } + // Check if we have reached the max # of chars, but still allow navigation and deletion + if ( !IsMultiLine() && GetValue().Length() >= m_maxLength && + key != WXK_LEFT && key != WXK_RIGHT && key != WXK_TAB && + key != WXK_BACK && !( key == WXK_RETURN && (m_windowStyle & wxPROCESS_ENTER) ) + ) + { + // eat it, we don't want to add more than allowed # of characters + return; + } + // assume that any key not processed yet is going to modify the control m_dirty = true;