From 41a499cd92710e3c954fa6e23ce3438cf26f5fcf Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 16 Apr 2005 04:53:01 +0000 Subject: [PATCH] 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 --- contrib/include/wx/stc/stc.h | 42 +++++++++++++- contrib/src/stc/gen_iface.py | 8 +++ contrib/src/stc/stc.cpp | 108 ++++++++++++++++++++++++++++++++++- contrib/src/stc/stc.cpp.in | 103 +++++++++++++++++++++++++++++++++ contrib/src/stc/stc.h.in | 40 +++++++++++++ include/wx/stc/stc.h | 42 +++++++++++++- src/stc/gen_iface.py | 8 +++ src/stc/stc.cpp | 108 ++++++++++++++++++++++++++++++++++- src/stc/stc.cpp.in | 103 +++++++++++++++++++++++++++++++++ src/stc/stc.h.in | 40 +++++++++++++ 10 files changed, 596 insertions(+), 6 deletions(-) diff --git a/contrib/include/wx/stc/stc.h b/contrib/include/wx/stc/stc.h index fd5179eee7..7abde48d5e 100644 --- a/contrib/include/wx/stc/stc.h +++ b/contrib/include/wx/stc/stc.h @@ -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); + + //---------------------------------------------------------------------- diff --git a/contrib/src/stc/gen_iface.py b/contrib/src/stc/gen_iface.py index 6e0a0aee90..f35fb2931b 100644 --- a/contrib/src/stc/gen_iface.py +++ b/contrib/src/stc/gen_iface.py @@ -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), diff --git a/contrib/src/stc/stc.cpp b/contrib/src/stc/stc.cpp index f0e0d86213..cb33d568a9 100644 --- a/contrib/src/stc/stc.cpp +++ b/contrib/src/stc/stc.cpp @@ -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 diff --git a/contrib/src/stc/stc.cpp.in b/contrib/src/stc/stc.cpp.in index a96666ae4f..18901c41f8 100644 --- a/contrib/src/stc/stc.cpp.in +++ b/contrib/src/stc/stc.cpp.in @@ -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 diff --git a/contrib/src/stc/stc.h.in b/contrib/src/stc/stc.h.in index 370fa887fd..f74a77b56c 100644 --- a/contrib/src/stc/stc.h.in +++ b/contrib/src/stc/stc.h.in @@ -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); + + //---------------------------------------------------------------------- diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index fd5179eee7..7abde48d5e 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -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); + + //---------------------------------------------------------------------- diff --git a/src/stc/gen_iface.py b/src/stc/gen_iface.py index 6e0a0aee90..f35fb2931b 100644 --- a/src/stc/gen_iface.py +++ b/src/stc/gen_iface.py @@ -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), diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index f0e0d86213..cb33d568a9 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -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 diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index a96666ae4f..18901c41f8 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -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 diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index 370fa887fd..f74a77b56c 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -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); + + //---------------------------------------------------------------------- -- 2.45.2