]> git.saurik.com Git - wxWidgets.git/commitdiff
wxMSW: generate wxClipboardTextEvent from wxTextCtrl with wxTE_RICH style too
authorVáclav Slavík <vslavik@fastmail.fm>
Sat, 15 Mar 2008 12:28:03 +0000 (12:28 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sat, 15 Mar 2008 12:28:03 +0000 (12:28 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52546 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/textctrl.h
interface/event.h
src/msw/textctrl.cpp

index f4119aa3eb9b6afa9a70c957628ba1bed99af4b1..c1f9cbed89442bff3fae797d5ff9ff84d22264b4 100644 (file)
@@ -256,6 +256,8 @@ private:
     // the simple EDIT controls
     virtual WXHWND GetEditHWND() const { return m_hWnd; }
 
+    void OnKeyDown(wxKeyEvent& event);
+
     DECLARE_EVENT_TABLE()
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl)
 
index beca799b220271853f236bf139f423816b8497f3..4f200e394732eb002295bbcd74a612932a2728f2 100644 (file)
@@ -676,9 +676,8 @@ public:
     @endEventTable
 
     @note
-    These events are currently only generated by wxComboBox and under Windows
-    and wxTextCtrl under Windows and GTK and are not generated for the text
-    controls with wxTE_RICH style under Windows.
+    These events are currently only generated by wxTextCtrl under GTK+. They
+    are generated by all controls under Windows.
 
     @library{wxcore}
     @category{events}
index 5007bc1d845e270dd3fa9bd54b89bacc0a519c86..780b1f89e7fec2c27812e629b035d85a036a9027 100644 (file)
@@ -248,6 +248,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
@@ -1846,6 +1847,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)
 {
     WXLRESULT lRc = wxTextCtrlBase::MSWWindowProc(nMsg, wParam, lParam);