X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbf28859114db0126c97c74cb8db5305f400fdf8..2b813b73cd79cfb4d275e9628811f379e8c5ee39:/src/msw/textctrl.cpp diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 0ff8cd4407..86ec3d7af8 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -378,29 +378,34 @@ wxString wxTextCtrl::GetValue() const #if wxUSE_RICHEDIT if ( m_isRich ) { - int len = GetWindowTextLength(GetHwnd()) + 1; - wxString str; - wxChar *p = str.GetWriteBuf(len); - TEXTRANGE textRange; - textRange.chrg.cpMin = 0; - textRange.chrg.cpMax = -1; - textRange.lpstrText = p; + int len = GetWindowTextLength(GetHwnd()); + if ( len ) + { + // alloc one extra WORD as needed by the control + wxChar *p = str.GetWriteBuf(++len); - (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange); + TEXTRANGE textRange; + textRange.chrg.cpMin = 0; + textRange.chrg.cpMax = -1; + textRange.lpstrText = p; - // believe it or not, but EM_GETTEXTRANGE uses just CR ('\r') for the - // newlines which is neither Unix nor Windows style (Win95 with - // riched20.dll shows this behaviour) - convert it to something - // reasonable - for ( ; *p; p++ ) - { - if ( *p == _T('\r') ) - *p = _T('\n'); - } + (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange); - str.UngetWriteBuf(); + // believe it or not, but EM_GETTEXTRANGE uses just CR ('\r') for + // the newlines which is neither Unix nor Windows style (Win95 with + // riched20.dll shows this behaviour) - convert it to something + // reasonable + for ( ; *p; p++ ) + { + if ( *p == _T('\r') ) + *p = _T('\n'); + } + + str.UngetWriteBuf(); + } + //else: no text at all, leave the string empty return str; } @@ -1074,7 +1079,7 @@ wxSize wxTextCtrl::DoGetBestSize() const int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); if ( m_windowStyle & wxTE_MULTILINE ) { - hText *= wxMin(GetNumberOfLines(), 5); + hText *= wxMax(GetNumberOfLines(), 5); } //else: for single line control everything is ok