Ticket #15980: textctrl-append_v2.patch

File textctrl-append_v2.patch, 2.6 KB (added by awi, 4 years ago)

New patch to fix the issue.

  • \include/wx/msw/textctrl.h

    diff -uNrBb -x setup.h wxWidgets-trunk\include/wx/msw/textctrl.h wxWidgets-work\include/wx/msw/textctrl.h
    old new  
    285285    int  m_isInkEdit;
    286286#endif
    287287
     288    // store the expected length of the whole text after append/insert operation
     289    int m_expectedTextLen;
    288290};
    289291
    290292#endif // _WX_TEXTCTRL_H_
  • \src/msw/textctrl.cpp

    diff -uNrb wxWidgets-trunk\src/msw/textctrl.cpp wxWidgets-work\src/msw/textctrl.cpp
    old new  
    226226    m_privateContextMenu = NULL;
    227227    m_updatesCount = -1;
    228228    m_isNativeCaretShown = true;
     229    m_expectedTextLen = 0;
    229230}
    230231
    231232wxTextCtrl::~wxTextCtrl()
     
    11371138
    11381139        UpdatesCountFilter ucf(m_updatesCount);
    11391140
     1141        // Expected text length after the operation.
     1142        m_expectedTextLen = ::GetWindowTextLength(GetHwnd()) + valueDos.length();
    11401143        ::SendMessage(GetHwnd(), selectionOnly ? EM_REPLACESEL : WM_SETTEXT,
    11411144                      // EM_REPLACESEL takes 1 to indicate the operation should be redoable
    11421145                      selectionOnly ? 1 : 0, wxMSW_CONV_LPARAM(valueDos));
     1146        if( ::GetWindowTextLength(GetHwnd()) < m_expectedTextLen )
     1147        {
     1148            // Text size limit has been hit and added text has been truncated.
     1149            // Text buffer has been increased in the background (EN_MAXTEXT message)
     1150            // so we can undo the operation and try to add the text again.
     1151            if( selectionOnly )
     1152                Undo();
     1153            ::SendMessage(GetHwnd(), selectionOnly ? EM_REPLACESEL : WM_SETTEXT,
     1154                          // EM_REPLACESEL takes 1 to indicate the operation should be redoable
     1155                          selectionOnly ? 1 : 0, wxMSW_CONV_LPARAM(valueDos));
     1156        }
     1157        wxASSERT_MSG( ::GetWindowTextLength(GetHwnd()) >= m_expectedTextLen,
     1158                      wxT("Insufficient text buffer: appended text has been trucated") );
    11431159
    11441160        if ( !ucf.GotUpdate() && (flags & SetValue_SendEvent) )
    11451161        {
     
    21192135    unsigned int len = ::GetWindowTextLength(GetHwnd());
    21202136    if ( len >= limit )
    21212137    {
    2122         // increment in 32Kb chunks
    2123         SetMaxLength(len + 0x8000);
     2138        unsigned long chunkSize = wxMax(0x8000, m_expectedTextLen - limit);  // at least 32KB
     2139        chunkSize = (chunkSize + 0x7FFF) & ~0x7FFF; // round up to the nearest 32KB block
     2140
     2141        SetMaxLength(len + chunkSize);
    21242142    }
    21252143
    21262144    // we changed the limit