diff --git a/docs/changes.txt b/docs/changes.txt index 4b733c3c2c..f748c2c364 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -45,6 +45,7 @@ All (GUI): - Added on-demand image loading option to wxRTC. - Add wxFont::GetBaseFont() (Melroy Tellis). - Update included Scintilla to version 3.3.9 (Christian Walther). +- Add wxStyledTextCtrl copy/paste text events (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). diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index 9b7dc649ee..f4efe2bfa6 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -5185,6 +5185,8 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_INDICATOR_RELEASE, wxStyled wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_AUTOCOMP_CANCELLED, wxStyledTextEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_AUTOCOMP_CHAR_DELETED, wxStyledTextEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_HOTSPOT_RELEASE_CLICK, wxStyledTextEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_CLIPBOARD_COPY, wxStyledTextEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_CLIPBOARD_PASTE, wxStyledTextEvent ); #else enum { wxEVT_STC_CHANGE, @@ -5217,7 +5219,9 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_HOTSPOT_RELEASE_CLICK, wxSt wxEVT_STC_INDICATOR_RELEASE, wxEVT_STC_AUTOCOMP_CANCELLED, wxEVT_STC_AUTOCOMP_CHAR_DELETED, - wxEVT_STC_HOTSPOT_RELEASE_CLICK + wxEVT_STC_HOTSPOT_RELEASE_CLICK, + wxEVT_STC_CLIPBOARD_COPY, + wxEVT_STC_CLIPBOARD_PASTE }; #endif @@ -5260,6 +5264,8 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #define EVT_STC_AUTOCOMP_CANCELLED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_AUTOCOMP_CANCELLED, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #define EVT_STC_AUTOCOMP_CHAR_DELETED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_AUTOCOMP_CHAR_DELETED, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #define EVT_STC_HOTSPOT_RELEASE_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_HOTSPOT_RELEASE_CLICK, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), +#define EVT_STC_CLIPBOARD_COPY(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_CLIPBOARD_COPY, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), +#define EVT_STC_CLIPBOARD_PASTE(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_CLIPBOARD_PASTE, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #endif diff --git a/interface/wx/stc/stc.h b/interface/wx/stc/stc.h index 8fe281ba5e..2d8a26e257 100644 --- a/interface/wx/stc/stc.h +++ b/interface/wx/stc/stc.h @@ -2618,11 +2618,11 @@ @event{EVT_STC_DWELLEND(id, fn)} TOWRITE @event{EVT_STC_START_DRAG(id, fn)} - TOWRITE + Process a @c wxEVT_STC_START_DRAG event, generated when text is being dragged from the control. Details of the drag may be altered by changing the respective fields of the event; in particular, set an empty string to prohibit the drag entirely. Valid event functions: @link wxStyledTextEvent::GetDragFlags GetDragFlags@endlink, @link wxStyledTextEvent::SetDragFlags SetDragFlags@endlink, @link wxStyledTextEvent::GetPosition GetPosition@endlink, @link wxStyledTextEvent::GetString GetString@endlink, @link wxStyledTextEvent::SetString SetString@endlink. @event{EVT_STC_DRAG_OVER(id, fn)} TOWRITE @event{EVT_STC_DO_DROP(id, fn)} - TOWRITE + Process a @c wxEVT_STC_DO_DROP event, generated when text is being dropped into the control. Details of the drag may be altered by changing the respective fields of the event. Valid event functions: @link wxStyledTextEvent::GetDragResult GetDragResult@endlink, @link wxStyledTextEvent::SetDragResult SetDragResult@endlink, @link wxStyledTextEvent::GetPosition GetPosition@endlink, @link wxStyledTextEvent::SetPosition SetPosition@endlink, @link wxStyledTextEvent::GetString GetString@endlink, @link wxStyledTextEvent::SetString SetString@endlink, @link wxStyledTextEvent::GetX GetX@endlink, @link wxStyledTextEvent::GetY GetY@endlink. @event{EVT_STC_ZOOM(id, fn)} TOWRITE @event{EVT_STC_HOTSPOT_CLICK(id, fn)} @@ -2643,6 +2643,14 @@ TOWRITE @event{EVT_STC_HOTSPOT_RELEASE_CLICK(id, fn)} TOWRITE + @event{EVT_STC_CLIPBOARD_COPY(id, fn)} + Process a @c wxEVT_STC_CLIPBOARD_COPY event, generated when text is being cut or copied to the clipboard. Use wxStyledTextEvent::SetString() to modify the text that will be placed on the clipboard. Valid event functions: @link wxStyledTextEvent::GetString GetString@endlink, @link wxStyledTextEvent::SetString SetString@endlink. + @since 3.1.0 + + @event{EVT_STC_CLIPBOARD_PASTE(id, fn)} + Process a @c wxEVT_STC_CLIPBOARD_PASTE event, generated when text is being pasted from the clipboard. Use wxStyledTextEvent::SetString() to modify the text that will be inserted into the control. Valid event functions: @link wxStyledTextEvent::GetPosition GetPosition@endlink, @link wxStyledTextEvent::GetString GetString@endlink, @link wxStyledTextEvent::SetString SetString@endlink. + @since 3.1.0 + @endEventTable @library{wxstc} @@ -6237,3 +6245,5 @@ const wxEventType wxEVT_STC_INDICATOR_RELEASE; const wxEventType wxEVT_STC_AUTOCOMP_CANCELLED; const wxEventType wxEVT_STC_AUTOCOMP_CHAR_DELETED; const wxEventType wxEVT_STC_HOTSPOT_RELEASE_CLICK; +const wxEventType wxEVT_STC_CLIPBOARD_COPY; +const wxEventType wxEVT_STC_CLIPBOARD_PASTE; diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 4ba7b9ee87..c80c7740e0 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -516,7 +516,15 @@ void ScintillaWX::Paste() { if (gotData) { wxString text = wxTextBuffer::Translate(data.GetText(), wxConvertEOLMode(pdoc->eolMode)); - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); + + // Send an event to allow the pasted text to be changed + wxStyledTextEvent evt(wxEVT_STC_CLIPBOARD_PASTE, stc->GetId()); + evt.SetEventObject(stc); + evt.SetPosition(sel.MainCaret()); + evt.SetString(text); + stc->GetEventHandler()->ProcessEvent(evt); + + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(evt.GetString()); #if wxUSE_UNICODE // free up the old character buffer in case the text is real big @@ -553,9 +561,15 @@ void ScintillaWX::CopyToClipboard(const SelectionText& st) { if ( !st.LengthWithTerminator() ) return; + // Send an event to allow the copied text to be changed + wxStyledTextEvent evt(wxEVT_STC_CLIPBOARD_COPY, stc->GetId()); + evt.SetEventObject(stc); + evt.SetString(wxTextBuffer::Translate(stc2wx(st.Data(), st.Length()))); + stc->GetEventHandler()->ProcessEvent(evt); + wxTheClipboard->UsePrimarySelection(false); if (wxTheClipboard->Open()) { - wxString text = wxTextBuffer::Translate(stc2wx(st.Data(), st.Length())); + wxString text = evt.GetString(); #ifdef wxHAVE_STC_RECT_FORMAT if (st.rectangular) diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 2396fe3b8a..f54566f4be 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -134,6 +134,8 @@ wxDEFINE_EVENT( wxEVT_STC_INDICATOR_RELEASE, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_CANCELLED, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_CHAR_DELETED, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_HOTSPOT_RELEASE_CLICK, wxStyledTextEvent ); +wxDEFINE_EVENT( wxEVT_STC_CLIPBOARD_COPY, wxStyledTextEvent ); +wxDEFINE_EVENT( wxEVT_STC_CLIPBOARD_PASTE, wxStyledTextEvent ); diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index f643b7f98a..621d8e6271 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -134,6 +134,8 @@ wxDEFINE_EVENT( wxEVT_STC_INDICATOR_RELEASE, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_CANCELLED, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_CHAR_DELETED, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_HOTSPOT_RELEASE_CLICK, wxStyledTextEvent ); +wxDEFINE_EVENT( wxEVT_STC_CLIPBOARD_COPY, wxStyledTextEvent ); +wxDEFINE_EVENT( wxEVT_STC_CLIPBOARD_PASTE, wxStyledTextEvent ); diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index 365165a280..228f4a3da5 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -679,6 +679,8 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_INDICATOR_RELEASE, wxStyled wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_AUTOCOMP_CANCELLED, wxStyledTextEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_AUTOCOMP_CHAR_DELETED, wxStyledTextEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_HOTSPOT_RELEASE_CLICK, wxStyledTextEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_CLIPBOARD_COPY, wxStyledTextEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_CLIPBOARD_PASTE, wxStyledTextEvent ); #else enum { wxEVT_STC_CHANGE, @@ -711,7 +713,9 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_HOTSPOT_RELEASE_CLICK, wxSt wxEVT_STC_INDICATOR_RELEASE, wxEVT_STC_AUTOCOMP_CANCELLED, wxEVT_STC_AUTOCOMP_CHAR_DELETED, - wxEVT_STC_HOTSPOT_RELEASE_CLICK + wxEVT_STC_HOTSPOT_RELEASE_CLICK, + wxEVT_STC_CLIPBOARD_COPY, + wxEVT_STC_CLIPBOARD_PASTE }; #endif @@ -754,6 +758,8 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #define EVT_STC_AUTOCOMP_CANCELLED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_AUTOCOMP_CANCELLED, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #define EVT_STC_AUTOCOMP_CHAR_DELETED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_AUTOCOMP_CHAR_DELETED, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #define EVT_STC_HOTSPOT_RELEASE_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_HOTSPOT_RELEASE_CLICK, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), +#define EVT_STC_CLIPBOARD_COPY(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_CLIPBOARD_COPY, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), +#define EVT_STC_CLIPBOARD_PASTE(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_CLIPBOARD_PASTE, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #endif diff --git a/src/stc/stc.interface.h.in b/src/stc/stc.interface.h.in index fabe26ac6f..c2009c94d4 100644 --- a/src/stc/stc.interface.h.in +++ b/src/stc/stc.interface.h.in @@ -83,11 +83,11 @@ @event{EVT_STC_DWELLEND(id, fn)} TOWRITE @event{EVT_STC_START_DRAG(id, fn)} - TOWRITE + Process a @c wxEVT_STC_START_DRAG event, generated when text is being dragged from the control. Details of the drag may be altered by changing the respective fields of the event; in particular, set an empty string to prohibit the drag entirely. Valid event functions: @link wxStyledTextEvent::GetDragFlags GetDragFlags@endlink, @link wxStyledTextEvent::SetDragFlags SetDragFlags@endlink, @link wxStyledTextEvent::GetPosition GetPosition@endlink, @link wxStyledTextEvent::GetString GetString@endlink, @link wxStyledTextEvent::SetString SetString@endlink. @event{EVT_STC_DRAG_OVER(id, fn)} TOWRITE @event{EVT_STC_DO_DROP(id, fn)} - TOWRITE + Process a @c wxEVT_STC_DO_DROP event, generated when text is being dropped into the control. Details of the drag may be altered by changing the respective fields of the event. Valid event functions: @link wxStyledTextEvent::GetDragResult GetDragResult@endlink, @link wxStyledTextEvent::SetDragResult SetDragResult@endlink, @link wxStyledTextEvent::GetPosition GetPosition@endlink, @link wxStyledTextEvent::SetPosition SetPosition@endlink, @link wxStyledTextEvent::GetString GetString@endlink, @link wxStyledTextEvent::SetString SetString@endlink, @link wxStyledTextEvent::GetX GetX@endlink, @link wxStyledTextEvent::GetY GetY@endlink. @event{EVT_STC_ZOOM(id, fn)} TOWRITE @event{EVT_STC_HOTSPOT_CLICK(id, fn)} @@ -108,6 +108,14 @@ TOWRITE @event{EVT_STC_HOTSPOT_RELEASE_CLICK(id, fn)} TOWRITE + @event{EVT_STC_CLIPBOARD_COPY(id, fn)} + Process a @c wxEVT_STC_CLIPBOARD_COPY event, generated when text is being cut or copied to the clipboard. Use wxStyledTextEvent::SetString() to modify the text that will be placed on the clipboard. Valid event functions: @link wxStyledTextEvent::GetString GetString@endlink, @link wxStyledTextEvent::SetString SetString@endlink. + @since 3.1.0 + + @event{EVT_STC_CLIPBOARD_PASTE(id, fn)} + Process a @c wxEVT_STC_CLIPBOARD_PASTE event, generated when text is being pasted from the clipboard. Use wxStyledTextEvent::SetString() to modify the text that will be inserted into the control. Valid event functions: @link wxStyledTextEvent::GetPosition GetPosition@endlink, @link wxStyledTextEvent::GetString GetString@endlink, @link wxStyledTextEvent::SetString SetString@endlink. + @since 3.1.0 + @endEventTable @library{wxstc} @@ -515,3 +523,5 @@ const wxEventType wxEVT_STC_INDICATOR_RELEASE; const wxEventType wxEVT_STC_AUTOCOMP_CANCELLED; const wxEventType wxEVT_STC_AUTOCOMP_CHAR_DELETED; const wxEventType wxEVT_STC_HOTSPOT_RELEASE_CLICK; +const wxEventType wxEVT_STC_CLIPBOARD_COPY; +const wxEventType wxEVT_STC_CLIPBOARD_PASTE;