diff --git a/docs/changes.txt b/docs/changes.txt index a5b9f504f3..34a6b29480 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -157,6 +157,7 @@ wxMSW: SmartPhone. - Fixed rendering of borders for wxTextCtrl with wxTE_RICH(2) style when using Windows XP's Classic UI theme. +- Text controls with wxTE_RICH style now also generate wxClipboardTextEvents. wxGTK: diff --git a/docs/latex/wx/clipevent.tex b/docs/latex/wx/clipevent.tex index de6e3ba0eb..293fc053ec 100644 --- a/docs/latex/wx/clipevent.tex +++ b/docs/latex/wx/clipevent.tex @@ -30,10 +30,10 @@ was copied or cut. \wxheading{Remarks} -These events are currently only generated by \helpref{wxComboBox}{wxcombobox} and -under Windows and \helpref{wxTextCtrl}{wxtextctrl} under Windows and GTK and -are not generated for the text controls with \texttt{wxTE\_RICH} style under -Windows. +These events are currently only generated by \helpref{wxTextCtrl}{wxtextctrl} +under GTK. They are generated by all controls under Windows. (Prior to version +2.8.8, only wxComboBox and wxTextCtrl without wxTE\_RICH style generated them +under Windows.) \wxheading{Derived from} diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 8b3c71f485..a3d7844d06 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -272,6 +272,8 @@ protected: int m_updatesCount; private: + void OnKeyDown(wxKeyEvent& event); + DECLARE_EVENT_TABLE() DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl) diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 7ed60c54fd..e7b1e32ef4 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -238,6 +238,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) EVT_CHAR(wxTextCtrl::OnChar) + EVT_KEY_DOWN(wxTextCtrl::OnKeyDown) EVT_DROP_FILES(wxTextCtrl::OnDropFiles) #if wxUSE_RICHEDIT @@ -1968,6 +1969,35 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) event.Skip(); } +void wxTextCtrl::OnKeyDown(wxKeyEvent& event) +{ + // richedit control doesn't send WM_PASTE, WM_CUT and WM_COPY messages + // when Ctrl-V, X or C is pressed and this prevents wxClipboardTextEvent + // from working. So we work around it by intercepting these shortcuts + // ourselves and emitting clipboard events (which richedit will handle, + // so everything works as before, including pasting of rich text): + if ( event.GetModifiers() == wxMOD_CONTROL && IsRich() ) + { + switch ( event.GetKeyCode() ) + { + case 'C': + Copy(); + return; + case 'X': + Cut(); + return; + case 'V': + Paste(); + return; + default: + break; + } + } + + // no, we didn't process it + event.Skip(); +} + WXLRESULT wxTextCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { // we must handle clipboard events before calling MSWWindowProc, otherwise