Use wxStringBuffer[Length] instead of explicit calls to

wxString::get/UngetWriteBuffer.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22191 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon
2003-07-21 09:41:26 +00:00
parent 11d395f9d7
commit de564874d6
14 changed files with 60 additions and 77 deletions

View File

@@ -468,30 +468,32 @@ wxString wxTextCtrl::GetRange(long from, long to) const
int len = GetWindowTextLength(GetHwnd());
if ( len > from )
{
// alloc one extra WORD as needed by the control
wxChar *p = str.GetWriteBuf(++len);
TEXTRANGE textRange;
textRange.chrg.cpMin = from;
textRange.chrg.cpMax = to == -1 ? len : to;
textRange.lpstrText = p;
(void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
if ( m_verRichEdit > 1 )
{
// RichEdit 2.0 uses just CR ('\r') for the newlines which is
// neither Unix nor Windows style - convert it to something
// reasonable
for ( ; *p; p++ )
// alloc one extra WORD as needed by the control
wxStringBuffer tmp(str, ++len);
wxChar *p = tmp;
TEXTRANGE textRange;
textRange.chrg.cpMin = from;
textRange.chrg.cpMax = to == -1 ? len : to;
textRange.lpstrText = p;
(void)SendMessage(GetHwnd(), EM_GETTEXTRANGE,
0, (LPARAM)&textRange);
if ( m_verRichEdit > 1 )
{
if ( *p == _T('\r') )
*p = _T('\n');
// RichEdit 2.0 uses just CR ('\r') for the
// newlines which is neither Unix nor Windows
// style - convert it to something reasonable
for ( ; *p; p++ )
{
if ( *p == _T('\r') )
*p = _T('\n');
}
}
}
str.UngetWriteBuf();
if ( m_verRichEdit == 1 )
{
// convert to the canonical form - see comment below
@@ -1196,13 +1198,16 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
len += sizeof(WORD);
wxString str;
wxChar *buf = str.GetWriteBuf(len);
{
wxStringBufferLength tmp(str, len);
wxChar *buf = tmp;
*(WORD *)buf = (WORD)len;
len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
buf[len] = 0;
str.UngetWriteBuf(len);
*(WORD *)buf = (WORD)len;
len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE,
lineNo, (LPARAM)buf);
buf[len] = 0;
tmp.SetLength(len);
}
return str;
}