Add several "Raw" functions for setting/getting text from the document

buffer. They behave similarly to the same methods without the "Raw" in
the name, except they don't use wxStrings.  This can save some
conversions to/from unicode and utf-8 in a Unicode build.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33639 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2005-04-16 04:53:01 +00:00
parent 22faef6ced
commit 41a499cd92
10 changed files with 596 additions and 6 deletions

View File

@ -2305,7 +2305,7 @@ public:
bool GetUseVerticalScrollBar();
// Append a string to the end of the document without changing the selection.
void AppendText(int length, const wxString& text);
void AppendText(const wxString& text);
// Is drawing done in two phases with backgrounds drawn before foregrounds?
bool GetTwoPhaseDraw();
@ -2908,6 +2908,46 @@ public:
bool GetUseAntiAliasing();
// The following methods are nearly equivallent to their similarly named
// cousins above. The difference is that these methods bypass wxString
// and always use a char* even if used in a unicode build of wxWidgets.
// In that case the character data will be utf-8 encoded since that is
// what is used internally by Scintilla in unicode builds.
// Add text to the document at current position.
void AddTextRaw(const char* text);
// Insert string at a position.
void InsertTextRaw(int pos, const char* text);
// Retrieve the text of the line containing the caret.
// Returns the index of the caret on the line.
#ifdef SWIG
wxCharBuffer GetCurLineRaw(int* OUTPUT);
#else
wxCharBuffer GetCurLineRaw(int* linePos=NULL);
#endif
// Retrieve the contents of a line.
wxCharBuffer GetLineRaw(int line);
// Retrieve the selected text.
wxCharBuffer GetSelectedTextRaw();
// Retrieve a range of text.
wxCharBuffer GetTextRangeRaw(int startPos, int endPos);
// Replace the contents of the document with the argument text.
void SetTextRaw(const char* text);
// Retrieve all the text in the document.
wxCharBuffer GetTextRaw();
// Append a string to the end of the document without changing the selection.
void AppendTextRaw(const char* text);
//----------------------------------------------------------------------

View File

@ -93,6 +93,14 @@ methodOverrideMap = {
SendMsg(%s, data.GetDataLen(), (long)data.GetData());''',
0),
'AppendText' : (0,
'void %s(const wxString& text);',
'''void %s(const wxString& text) {
wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
0),
'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),

View File

@ -1632,8 +1632,9 @@ bool wxStyledTextCtrl::GetUseVerticalScrollBar() {
}
// Append a string to the end of the document without changing the selection.
void wxStyledTextCtrl::AppendText(int length, const wxString& text) {
SendMsg(2282, length, (long)(const char*)wx2stc(text));
void wxStyledTextCtrl::AppendText(const wxString& text) {
wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
SendMsg(2282, strlen(buf), (long)(const char*)buf);
}
// Is drawing done in two phases with backgrounds drawn before foregrounds?
@ -2675,6 +2676,109 @@ bool wxStyledTextCtrl::GetUseAntiAliasing() {
return m_swx->GetUseAntiAliasing();
}
void wxStyledTextCtrl::AddTextRaw(const char* text)
{
SendMsg(SCI_ADDTEXT, strlen(text), (long)text);
}
void wxStyledTextCtrl::InsertTextRaw(int pos, const char* text)
{
SendMsg(SCI_INSERTTEXT, pos, (long)text);
}
wxCharBuffer wxStyledTextCtrl::GetCurLineRaw(int* linePos)
{
int len = LineLength(GetCurrentLine());
if (!len) {
if (linePos) *linePos = 0;
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
int pos = SendMsg(SCI_GETCURLINE, len, (long)buf.data());
if (linePos) *linePos = pos;
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetLineRaw(int line)
{
int len = LineLength(line);
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
SendMsg(SCI_GETLINE, line, (long)buf.data());
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw()
{
int start;
int end;
GetSelection(&start, &end);
int len = end - start;
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
SendMsg(SCI_GETSELTEXT, 0, (long)buf.data());
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetTextRangeRaw(int startPos, int endPos)
{
if (endPos < startPos) {
int temp = startPos;
startPos = endPos;
endPos = temp;
}
int len = endPos - startPos;
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
TextRange tr;
tr.lpstrText = buf.data();
tr.chrg.cpMin = startPos;
tr.chrg.cpMax = endPos;
SendMsg(SCI_GETTEXTRANGE, 0, (long)&tr);
return buf;
}
void wxStyledTextCtrl::SetTextRaw(const char* text)
{
SendMsg(SCI_SETTEXT, 0, (long)text);
}
wxCharBuffer wxStyledTextCtrl::GetTextRaw()
{
int len = GetTextLength();
wxCharBuffer buf(len);
SendMsg(SCI_GETTEXT, len, (long)buf.data());
return buf;
}
void wxStyledTextCtrl::AppendTextRaw(const char* text)
{
SendMsg(SCI_APPENDTEXT, strlen(text), (long)text);
}
//----------------------------------------------------------------------
// Event handlers

View File

@ -443,6 +443,109 @@ bool wxStyledTextCtrl::GetUseAntiAliasing() {
return m_swx->GetUseAntiAliasing();
}
void wxStyledTextCtrl::AddTextRaw(const char* text)
{
SendMsg(SCI_ADDTEXT, strlen(text), (long)text);
}
void wxStyledTextCtrl::InsertTextRaw(int pos, const char* text)
{
SendMsg(SCI_INSERTTEXT, pos, (long)text);
}
wxCharBuffer wxStyledTextCtrl::GetCurLineRaw(int* linePos)
{
int len = LineLength(GetCurrentLine());
if (!len) {
if (linePos) *linePos = 0;
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
int pos = SendMsg(SCI_GETCURLINE, len, (long)buf.data());
if (linePos) *linePos = pos;
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetLineRaw(int line)
{
int len = LineLength(line);
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
SendMsg(SCI_GETLINE, line, (long)buf.data());
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw()
{
int start;
int end;
GetSelection(&start, &end);
int len = end - start;
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
SendMsg(SCI_GETSELTEXT, 0, (long)buf.data());
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetTextRangeRaw(int startPos, int endPos)
{
if (endPos < startPos) {
int temp = startPos;
startPos = endPos;
endPos = temp;
}
int len = endPos - startPos;
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
TextRange tr;
tr.lpstrText = buf.data();
tr.chrg.cpMin = startPos;
tr.chrg.cpMax = endPos;
SendMsg(SCI_GETTEXTRANGE, 0, (long)&tr);
return buf;
}
void wxStyledTextCtrl::SetTextRaw(const char* text)
{
SendMsg(SCI_SETTEXT, 0, (long)text);
}
wxCharBuffer wxStyledTextCtrl::GetTextRaw()
{
int len = GetTextLength();
wxCharBuffer buf(len);
SendMsg(SCI_GETTEXT, len, (long)buf.data());
return buf;
}
void wxStyledTextCtrl::AppendTextRaw(const char* text)
{
SendMsg(SCI_APPENDTEXT, strlen(text), (long)text);
}
//----------------------------------------------------------------------
// Event handlers

View File

@ -219,6 +219,46 @@ public:
bool GetUseAntiAliasing();
// The following methods are nearly equivallent to their similarly named
// cousins above. The difference is that these methods bypass wxString
// and always use a char* even if used in a unicode build of wxWidgets.
// In that case the character data will be utf-8 encoded since that is
// what is used internally by Scintilla in unicode builds.
// Add text to the document at current position.
void AddTextRaw(const char* text);
// Insert string at a position.
void InsertTextRaw(int pos, const char* text);
// Retrieve the text of the line containing the caret.
// Returns the index of the caret on the line.
#ifdef SWIG
wxCharBuffer GetCurLineRaw(int* OUTPUT);
#else
wxCharBuffer GetCurLineRaw(int* linePos=NULL);
#endif
// Retrieve the contents of a line.
wxCharBuffer GetLineRaw(int line);
// Retrieve the selected text.
wxCharBuffer GetSelectedTextRaw();
// Retrieve a range of text.
wxCharBuffer GetTextRangeRaw(int startPos, int endPos);
// Replace the contents of the document with the argument text.
void SetTextRaw(const char* text);
// Retrieve all the text in the document.
wxCharBuffer GetTextRaw();
// Append a string to the end of the document without changing the selection.
void AppendTextRaw(const char* text);
//----------------------------------------------------------------------

View File

@ -2305,7 +2305,7 @@ public:
bool GetUseVerticalScrollBar();
// Append a string to the end of the document without changing the selection.
void AppendText(int length, const wxString& text);
void AppendText(const wxString& text);
// Is drawing done in two phases with backgrounds drawn before foregrounds?
bool GetTwoPhaseDraw();
@ -2908,6 +2908,46 @@ public:
bool GetUseAntiAliasing();
// The following methods are nearly equivallent to their similarly named
// cousins above. The difference is that these methods bypass wxString
// and always use a char* even if used in a unicode build of wxWidgets.
// In that case the character data will be utf-8 encoded since that is
// what is used internally by Scintilla in unicode builds.
// Add text to the document at current position.
void AddTextRaw(const char* text);
// Insert string at a position.
void InsertTextRaw(int pos, const char* text);
// Retrieve the text of the line containing the caret.
// Returns the index of the caret on the line.
#ifdef SWIG
wxCharBuffer GetCurLineRaw(int* OUTPUT);
#else
wxCharBuffer GetCurLineRaw(int* linePos=NULL);
#endif
// Retrieve the contents of a line.
wxCharBuffer GetLineRaw(int line);
// Retrieve the selected text.
wxCharBuffer GetSelectedTextRaw();
// Retrieve a range of text.
wxCharBuffer GetTextRangeRaw(int startPos, int endPos);
// Replace the contents of the document with the argument text.
void SetTextRaw(const char* text);
// Retrieve all the text in the document.
wxCharBuffer GetTextRaw();
// Append a string to the end of the document without changing the selection.
void AppendTextRaw(const char* text);
//----------------------------------------------------------------------

View File

@ -93,6 +93,14 @@ methodOverrideMap = {
SendMsg(%s, data.GetDataLen(), (long)data.GetData());''',
0),
'AppendText' : (0,
'void %s(const wxString& text);',
'''void %s(const wxString& text) {
wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
0),
'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),

View File

@ -1632,8 +1632,9 @@ bool wxStyledTextCtrl::GetUseVerticalScrollBar() {
}
// Append a string to the end of the document without changing the selection.
void wxStyledTextCtrl::AppendText(int length, const wxString& text) {
SendMsg(2282, length, (long)(const char*)wx2stc(text));
void wxStyledTextCtrl::AppendText(const wxString& text) {
wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
SendMsg(2282, strlen(buf), (long)(const char*)buf);
}
// Is drawing done in two phases with backgrounds drawn before foregrounds?
@ -2675,6 +2676,109 @@ bool wxStyledTextCtrl::GetUseAntiAliasing() {
return m_swx->GetUseAntiAliasing();
}
void wxStyledTextCtrl::AddTextRaw(const char* text)
{
SendMsg(SCI_ADDTEXT, strlen(text), (long)text);
}
void wxStyledTextCtrl::InsertTextRaw(int pos, const char* text)
{
SendMsg(SCI_INSERTTEXT, pos, (long)text);
}
wxCharBuffer wxStyledTextCtrl::GetCurLineRaw(int* linePos)
{
int len = LineLength(GetCurrentLine());
if (!len) {
if (linePos) *linePos = 0;
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
int pos = SendMsg(SCI_GETCURLINE, len, (long)buf.data());
if (linePos) *linePos = pos;
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetLineRaw(int line)
{
int len = LineLength(line);
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
SendMsg(SCI_GETLINE, line, (long)buf.data());
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw()
{
int start;
int end;
GetSelection(&start, &end);
int len = end - start;
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
SendMsg(SCI_GETSELTEXT, 0, (long)buf.data());
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetTextRangeRaw(int startPos, int endPos)
{
if (endPos < startPos) {
int temp = startPos;
startPos = endPos;
endPos = temp;
}
int len = endPos - startPos;
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
TextRange tr;
tr.lpstrText = buf.data();
tr.chrg.cpMin = startPos;
tr.chrg.cpMax = endPos;
SendMsg(SCI_GETTEXTRANGE, 0, (long)&tr);
return buf;
}
void wxStyledTextCtrl::SetTextRaw(const char* text)
{
SendMsg(SCI_SETTEXT, 0, (long)text);
}
wxCharBuffer wxStyledTextCtrl::GetTextRaw()
{
int len = GetTextLength();
wxCharBuffer buf(len);
SendMsg(SCI_GETTEXT, len, (long)buf.data());
return buf;
}
void wxStyledTextCtrl::AppendTextRaw(const char* text)
{
SendMsg(SCI_APPENDTEXT, strlen(text), (long)text);
}
//----------------------------------------------------------------------
// Event handlers

View File

@ -443,6 +443,109 @@ bool wxStyledTextCtrl::GetUseAntiAliasing() {
return m_swx->GetUseAntiAliasing();
}
void wxStyledTextCtrl::AddTextRaw(const char* text)
{
SendMsg(SCI_ADDTEXT, strlen(text), (long)text);
}
void wxStyledTextCtrl::InsertTextRaw(int pos, const char* text)
{
SendMsg(SCI_INSERTTEXT, pos, (long)text);
}
wxCharBuffer wxStyledTextCtrl::GetCurLineRaw(int* linePos)
{
int len = LineLength(GetCurrentLine());
if (!len) {
if (linePos) *linePos = 0;
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
int pos = SendMsg(SCI_GETCURLINE, len, (long)buf.data());
if (linePos) *linePos = pos;
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetLineRaw(int line)
{
int len = LineLength(line);
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
SendMsg(SCI_GETLINE, line, (long)buf.data());
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw()
{
int start;
int end;
GetSelection(&start, &end);
int len = end - start;
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
SendMsg(SCI_GETSELTEXT, 0, (long)buf.data());
return buf;
}
wxCharBuffer wxStyledTextCtrl::GetTextRangeRaw(int startPos, int endPos)
{
if (endPos < startPos) {
int temp = startPos;
startPos = endPos;
endPos = temp;
}
int len = endPos - startPos;
if (!len) {
wxCharBuffer empty;
return empty;
}
wxCharBuffer buf(len);
TextRange tr;
tr.lpstrText = buf.data();
tr.chrg.cpMin = startPos;
tr.chrg.cpMax = endPos;
SendMsg(SCI_GETTEXTRANGE, 0, (long)&tr);
return buf;
}
void wxStyledTextCtrl::SetTextRaw(const char* text)
{
SendMsg(SCI_SETTEXT, 0, (long)text);
}
wxCharBuffer wxStyledTextCtrl::GetTextRaw()
{
int len = GetTextLength();
wxCharBuffer buf(len);
SendMsg(SCI_GETTEXT, len, (long)buf.data());
return buf;
}
void wxStyledTextCtrl::AppendTextRaw(const char* text)
{
SendMsg(SCI_APPENDTEXT, strlen(text), (long)text);
}
//----------------------------------------------------------------------
// Event handlers

View File

@ -219,6 +219,46 @@ public:
bool GetUseAntiAliasing();
// The following methods are nearly equivallent to their similarly named
// cousins above. The difference is that these methods bypass wxString
// and always use a char* even if used in a unicode build of wxWidgets.
// In that case the character data will be utf-8 encoded since that is
// what is used internally by Scintilla in unicode builds.
// Add text to the document at current position.
void AddTextRaw(const char* text);
// Insert string at a position.
void InsertTextRaw(int pos, const char* text);
// Retrieve the text of the line containing the caret.
// Returns the index of the caret on the line.
#ifdef SWIG
wxCharBuffer GetCurLineRaw(int* OUTPUT);
#else
wxCharBuffer GetCurLineRaw(int* linePos=NULL);
#endif
// Retrieve the contents of a line.
wxCharBuffer GetLineRaw(int line);
// Retrieve the selected text.
wxCharBuffer GetSelectedTextRaw();
// Retrieve a range of text.
wxCharBuffer GetTextRangeRaw(int startPos, int endPos);
// Replace the contents of the document with the argument text.
void SetTextRaw(const char* text);
// Retrieve all the text in the document.
wxCharBuffer GetTextRaw();
// Append a string to the end of the document without changing the selection.
void AppendTextRaw(const char* text);
//----------------------------------------------------------------------