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,10 +378,13 @@ 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);
int len = GetWindowTextLength(GetHwnd());
if ( len )
{
// alloc one extra WORD as needed by the control
wxChar *p = str.GetWriteBuf(++len);
TEXTRANGE textRange; TEXTRANGE textRange;
textRange.chrg.cpMin = 0; textRange.chrg.cpMin = 0;
@@ -390,8 +393,8 @@ wxString wxTextCtrl::GetValue() const
(void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange); (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
// believe it or not, but EM_GETTEXTRANGE uses just CR ('\r') for the // believe it or not, but EM_GETTEXTRANGE uses just CR ('\r') for
// newlines which is neither Unix nor Windows style (Win95 with // the newlines which is neither Unix nor Windows style (Win95 with
// riched20.dll shows this behaviour) - convert it to something // riched20.dll shows this behaviour) - convert it to something
// reasonable // reasonable
for ( ; *p; p++ ) for ( ; *p; p++ )
@@ -401,6 +404,8 @@ wxString wxTextCtrl::GetValue() const
} }
str.UngetWriteBuf(); 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