fixed wxTextCtrl::GetValue() bug for empty richedit ctrls (Marvin Aviles)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8766 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-11-21 18:01:27 +00:00
parent e5f56a004e
commit 3988b155d7

View File

@@ -378,29 +378,34 @@ wxString wxTextCtrl::GetValue() const
#if wxUSE_RICHEDIT #if wxUSE_RICHEDIT
if ( m_isRich ) if ( m_isRich )
{ {
int len = GetWindowTextLength(GetHwnd()) + 1;
wxString str; wxString str;
wxChar *p = str.GetWriteBuf(len);
TEXTRANGE textRange; int len = GetWindowTextLength(GetHwnd());
textRange.chrg.cpMin = 0; if ( len )
textRange.chrg.cpMax = -1;
textRange.lpstrText = p;
(void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
// 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') ) // alloc one extra WORD as needed by the control
*p = _T('\n'); wxChar *p = str.GetWriteBuf(++len);
}
str.UngetWriteBuf(); TEXTRANGE textRange;
textRange.chrg.cpMin = 0;
textRange.chrg.cpMax = -1;
textRange.lpstrText = p;
(void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
// 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; return str;
} }
@@ -1074,7 +1079,7 @@ wxSize wxTextCtrl::DoGetBestSize() const
int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
if ( m_windowStyle & wxTE_MULTILINE ) if ( m_windowStyle & wxTE_MULTILINE )
{ {
hText *= wxMin(GetNumberOfLines(), 5); hText *= wxMax(GetNumberOfLines(), 5);
} }
//else: for single line control everything is ok //else: for single line control everything is ok