diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 14265e7983..1a81e44d71 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -203,11 +203,11 @@ protected: // the limit is due to a previous call to SetMaxLength() and not built in) bool HasSpaceLimit(unsigned int *len) const; - // call this to increase the size limit (will do nothing if the current - // limit is big enough) + // Used by EN_MAXTEXT handler to increase the size limit (will do nothing + // if the current limit is big enough). Should never be called directly. // - // returns true if we increased the limit to allow entering more text, - // false if we hit the limit set by SetMaxLength() and so didn't change it + // Returns true if we increased the limit to allow entering more text, + // false if we hit the limit set by SetMaxLength() and so didn't change it. bool AdjustSpaceLimit(); #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU) diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index dfdf2c6e3f..473aa0c36e 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -2149,13 +2149,23 @@ bool wxTextCtrl::AdjustSpaceLimit() unsigned int len = ::GetWindowTextLength(GetHwnd()); if ( len >= limit ) { + unsigned long increaseBy; + // We need to increase the size of the buffer and to avoid increasing // it too many times make sure that we make it at least big enough to - // fit all the text we are currently inserting into the control. - unsigned long increaseBy = gs_lenOfInsertedText.top(); + // fit all the text we are currently inserting into the control, if + // we're inserting any, i.e. if we're called from DoWriteText(). + if ( !gs_lenOfInsertedText.empty() ) + { + increaseBy = gs_lenOfInsertedText.top(); - // Indicate to the caller that we increased the limit. - gs_lenOfInsertedText.top() = -1; + // Indicate to the caller that we increased the limit. + gs_lenOfInsertedText.top() = -1; + } + else // Not inserting text, must be text actually typed by user. + { + increaseBy = 0; + } // But also increase it by at least 32KB chunks -- again, to avoid // doing it too often -- and round it up to 32KB in any case.