diff --git a/docs/changes.txt b/docs/changes.txt index b90171f09a..1fda7713ec 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -47,6 +47,7 @@ All (GUI): - Update included Scintilla to version 3.3.9 (Christian Walther). - Add support for loading old V1 BMP files to wxImage (Artur Wieczorek). - Improve auto sizing of wrapped cells in wxGrid (iwbnwif). +- Fix handling of rectangular selections in wxStyledTextCtrl (roberto). wxGTK: diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 66c978d387..fd57208748 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -251,6 +251,17 @@ ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) { sysCaretWidth = 0; sysCaretHeight = 0; #endif + +#ifdef wxHAVE_STC_RECT_FORMAT +#if defined(__WXMSW__) + m_clipRectTextFormat = wxDataFormat(wxT("MSDEVColumnSelect")); +#elif defined(__WXGTK__) + m_clipRectTextFormat = wxDataFormat(wxT("SECONDARY")); +#else + #error "Must define rectangular text selection clipboard format." +#endif +#endif // wxHAVE_STC_RECT_FORMAT + } @@ -487,7 +498,8 @@ void ScintillaWX::Copy() { void ScintillaWX::Paste() { pdoc->BeginUndoAction(); - ClearSelection(); + ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH); + bool isRectangularClipboard = false; #if wxUSE_DATAOBJ wxTextDataObject data; @@ -495,6 +507,9 @@ void ScintillaWX::Paste() { wxTheClipboard->UsePrimarySelection(false); if (wxTheClipboard->Open()) { +#ifdef wxHAVE_STC_RECT_FORMAT + isRectangularClipboard = wxTheClipboard->IsSupported(m_clipRectTextFormat); +#endif gotData = wxTheClipboard->GetData(data); wxTheClipboard->Close(); } @@ -509,9 +524,21 @@ void ScintillaWX::Paste() { text = wxEmptyString; #endif int len = strlen(buf); - int caretMain = sel.MainCaret(); - pdoc->InsertString(caretMain, buf, len); - SetEmptySelection(caretMain + len); + SelectionPosition selStart = sel.IsRectangular() ? + sel.Rectangular().Start() : + sel.Range(sel.Main()).Start(); + + // call the appropriate scintilla paste method if the + // depending on whether the text was copied FROM a rectangular selection + // or not. + if (isRectangularClipboard) + { + PasteRectangular(selStart, buf, len); + } + else + { + InsertPaste(selStart, buf, len); + } } #endif // wxUSE_DATAOBJ @@ -529,7 +556,21 @@ void ScintillaWX::CopyToClipboard(const SelectionText& st) { wxTheClipboard->UsePrimarySelection(false); if (wxTheClipboard->Open()) { wxString text = wxTextBuffer::Translate(stc2wx(st.Data(), st.Length())); - wxTheClipboard->SetData(new wxTextDataObject(text)); + +#ifdef wxHAVE_STC_RECT_FORMAT + if (st.rectangular) + { + // when copying the text to the clipboard, add extra meta-data that + // tells the Paste() method that the user copied a rectangular + // block of text, as opposed to a stream of text. + wxDataObjectComposite* composite = new wxDataObjectComposite(); + composite->Add(new wxTextDataObject(text), true); + composite->Add(new wxCustomDataObject(m_clipRectTextFormat)); + wxTheClipboard->SetData(composite); + } + else +#endif // wxHAVE_STC_RECT_FORMAT + wxTheClipboard->SetData(new wxTextDataObject(text)); wxTheClipboard->Close(); } #else diff --git a/src/stc/ScintillaWX.h b/src/stc/ScintillaWX.h index a01f8020d3..54f4bb0217 100644 --- a/src/stc/ScintillaWX.h +++ b/src/stc/ScintillaWX.h @@ -70,6 +70,12 @@ #include "wx/timer.h" #endif +// Define this if there is a standard clipboard format for rectangular +// text selection under the current platform. +#if defined(__WXMSW__) || defined(__WXGTK__) + #define wxHAVE_STC_RECT_FORMAT +#endif + //---------------------------------------------------------------------- @@ -205,7 +211,13 @@ private: int sysCaretWidth; int sysCaretHeight; #endif - + +#ifdef wxHAVE_STC_RECT_FORMAT + // The presence of this format on the clipboard indicates that the text is + // a rectangular (and not the default linear) selection. + wxDataFormat m_clipRectTextFormat; +#endif + friend class wxSTCCallTip; };