]> git.saurik.com Git - wxWidgets.git/commitdiff
Add several "Raw" functions for setting/getting text from the document
authorRobin Dunn <robin@alldunn.com>
Sat, 16 Apr 2005 04:53:01 +0000 (04:53 +0000)
committerRobin Dunn <robin@alldunn.com>
Sat, 16 Apr 2005 04:53:01 +0000 (04:53 +0000)
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
contrib/src/stc/gen_iface.py
contrib/src/stc/stc.cpp
contrib/src/stc/stc.cpp.in
contrib/src/stc/stc.h.in
include/wx/stc/stc.h
src/stc/gen_iface.py
src/stc/stc.cpp
src/stc/stc.cpp.in
src/stc/stc.h.in

index fd5179eee7269dfcab44c67c1a54374e2617af13..7abde48d5e7d7c68f430958f4c782f951f9dedfd 100644 (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);
+
+
 //----------------------------------------------------------------------
 
 
index 6e0a0aee90770c073644b161bfde18d911844b91..f35fb2931bb823c7a1ef9250077258b5d1d092d0 100644 (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),
 
index f0e0d86213d9a9a754252f721422122e504feeff..cb33d568a919b86afba16f16a6283b75142d9ad4 100644 (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
 
index a96666ae4fae1121d03a876b0085bad4b6f2341b..18901c41f8d9aef6018834cc572a9458e480af49 100644 (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
 
index 370fa887fd215583d21a9f55acf95208383685fd..f74a77b56c89bcd36136d2976ea44529af6ddf59 100644 (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);
+
+
 //----------------------------------------------------------------------
 
 
index fd5179eee7269dfcab44c67c1a54374e2617af13..7abde48d5e7d7c68f430958f4c782f951f9dedfd 100644 (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);
+
+
 //----------------------------------------------------------------------
 
 
index 6e0a0aee90770c073644b161bfde18d911844b91..f35fb2931bb823c7a1ef9250077258b5d1d092d0 100644 (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),
 
index f0e0d86213d9a9a754252f721422122e504feeff..cb33d568a919b86afba16f16a6283b75142d9ad4 100644 (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
 
index a96666ae4fae1121d03a876b0085bad4b6f2341b..18901c41f8d9aef6018834cc572a9458e480af49 100644 (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
 
index 370fa887fd215583d21a9f55acf95208383685fd..f74a77b56c89bcd36136d2976ea44529af6ddf59 100644 (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);
+
+
 //----------------------------------------------------------------------