X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6f67e6d2e46f53606af07f8a861901ce44fd18b1..2f9d19913018ec6e9e976a70bf8f90edab90f4d6:/src/stc/stc.cpp diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 4eaa62aa14..20aff095a3 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -210,7 +210,7 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, SetInitialSize(size); // Reduces flicker on GTK+/X11 - SetBackgroundStyle(wxBG_STYLE_CUSTOM); + SetBackgroundStyle(wxBG_STYLE_PAINT); // Make sure it can take the focus SetCanFocus(true); @@ -258,8 +258,8 @@ void wxStyledTextCtrl::SetHScrollBar(wxScrollBar* bar) { // Add text to the document at current position. void wxStyledTextCtrl::AddText(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - SendMsg(2001, buf.length(), (sptr_t)(const char*)buf); + const wxWX2MBbuf buf = wx2stc(text); + SendMsg(2001, wx2stclen(text, buf), (sptr_t)(const char*)buf); } // Add array of cells to document. @@ -1410,7 +1410,7 @@ int wxStyledTextCtrl::FindText(int minPos, int maxPos, TextToFind ft; ft.chrg.cpMin = minPos; ft.chrg.cpMax = maxPos; - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); + const wxWX2MBbuf buf = wx2stc(text); ft.lpstrText = (char*)(const char*)buf; return SendMsg(2150, flags, (sptr_t)&ft); @@ -1504,11 +1504,7 @@ bool wxStyledTextCtrl::GetModify() const // Retrieve the selected text. wxString wxStyledTextCtrl::GetSelectedText() { - long start; - long end; - - GetSelection(&start, &end); - int len = end - start; + const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0); if (!len) return wxEmptyString; wxMemoryBuffer mbuf(len+2); @@ -1708,8 +1704,8 @@ int wxStyledTextCtrl::GetTargetEnd() const // Returns the length of the replacement text. int wxStyledTextCtrl::ReplaceTarget(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - return SendMsg(2194, buf.length(), (sptr_t)(const char*)buf); + const wxWX2MBbuf buf = wx2stc(text); + return SendMsg(2194, wx2stclen(text, buf), (sptr_t)(const char*)buf); } // Replace the target text with the argument text after \d processing. @@ -1720,8 +1716,8 @@ int wxStyledTextCtrl::GetTargetEnd() const // caused by processing the \d patterns. int wxStyledTextCtrl::ReplaceTargetRE(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - return SendMsg(2195, buf.length(), (sptr_t)(const char*)buf); + const wxWX2MBbuf buf = wx2stc(text); + return SendMsg(2195, wx2stclen(text, buf), (sptr_t)(const char*)buf); } // Search for a counted string in the target and set the target to the found @@ -1729,8 +1725,8 @@ int wxStyledTextCtrl::GetTargetEnd() const // Returns length of range or -1 for failure in which case target is not moved. int wxStyledTextCtrl::SearchInTarget(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - return SendMsg(2197, buf.length(), (sptr_t)(const char*)buf); + const wxWX2MBbuf buf = wx2stc(text); + return SendMsg(2197, wx2stclen(text, buf), (sptr_t)(const char*)buf); } // Set the search flags used by SearchInTarget. @@ -2085,8 +2081,8 @@ bool wxStyledTextCtrl::GetUseVerticalScrollBar() const // Append a string to the end of the document without changing the selection. void wxStyledTextCtrl::AppendText(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - SendMsg(2282, buf.length(), (sptr_t)(const char*)buf); + const wxWX2MBbuf buf = wx2stc(text); + SendMsg(2282, wx2stclen(text, buf), (sptr_t)(const char*)buf); } // Is drawing done in two phases with backgrounds drawn before foregrounds? @@ -4128,16 +4124,10 @@ wxCharBuffer wxStyledTextCtrl::GetLineRaw(int line) wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw() { - long start; - long end; - - GetSelection(&start, &end); - int len = end - start; - if (!len) { - wxCharBuffer empty; - return empty; - } + // Calculate the length needed first. + const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0); + // And then really get the data. wxCharBuffer buf(len); SendMsg(SCI_GETSELTEXT, 0, (sptr_t)buf.data()); return buf;