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:
@@ -810,24 +810,20 @@ int wxTextCtrl::GetLineLength(long lineNo) const
|
|||||||
|
|
||||||
wxString wxTextCtrl::GetLineText(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;
|
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;
|
*(WORD *)buf = len;
|
||||||
int noChars = (int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
|
len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
|
||||||
buf[noChars] = 0;
|
buf[len] = 0;
|
||||||
|
|
||||||
wxString str(buf);
|
str.UngetWriteBuf(len);
|
||||||
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user