wxTextCtrl::GetLineText() fixes:

a) doesn't crash
 b) more efficient
 c) works in Unicode mode


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7145 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-04-12 23:38:20 +00:00
parent bea6a318d9
commit 8b3b778f3d

View File

@@ -810,24 +810,20 @@ int wxTextCtrl::GetLineLength(long lineNo) const
wxString wxTextCtrl::GetLineText(long lineNo) const
{
// TODO this should probably be optimized by using GetWriteBuf()
size_t len = (size_t)GetLineLength(lineNo) + 1;
if ( len < sizeof(WORD) )
{
// there must be at least enough place for the length WORD in the
// buffer
len += sizeof(WORD);
}
char *buf = (char *)malloc(len);
// there must be at least enough place for the length WORD in the
// buffer
len += sizeof(WORD);
wxString str;
wxChar *buf = str.GetWriteBuf(len);
*(WORD *)buf = len;
int noChars = (int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
buf[noChars] = 0;
len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
buf[len] = 0;
wxString str(buf);
free(buf);
str.UngetWriteBuf(len);
return str;
}