]> git.saurik.com Git - wxWidgets.git/commitdiff
generate wxEVT_COMMAND_TEXT_COPY event in wxHtmlWindow
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 30 Oct 2006 16:18:45 +0000 (16:18 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 30 Oct 2006 16:18:45 +0000 (16:18 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42729 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/html/htmlwin.h
samples/html/test/test.cpp
src/html/htmlwin.cpp

index 1533e33fbefed21e8b5babaa037ae42e36da7b6c..c5d0b669d0a6c14d2bfe1e31f4f4334037d10396 100644 (file)
@@ -95,7 +95,8 @@ All (GUI):
   formatting.
 - Support for loading TGA files added (Seth Jackson)
 - Added wxTB_RIGHT style for right-aligned toolbars (Igor Korot)
-- Added events API to wxHtmlWindow (Francesco Montorsi).
+- wxHtmlWindow now generates events on link clicks (Francesco Montorsi).
+- wxHtmlWindow now also generates wxEVT_COMMAND_TEXT_COPY event
 
 Unix Ports:
 
index d4629c9ad5234abc3aeb196d124c7fe126aaf894..d2a55a7695eef4ac056abf6e042e9c350ee9dc3e 100644 (file)
@@ -409,6 +409,7 @@ protected:
     void OnKeyUp(wxKeyEvent& event);
     void OnDoubleClick(wxMouseEvent& event);
     void OnCopy(wxCommandEvent& event);
+    void OnClipboardEvent(wxClipboardTextEvent& event);
     void OnMouseEnter(wxMouseEvent& event);
     void OnMouseLeave(wxMouseEvent& event);
     void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
index 0336006f31c2a0fd4f37c76d85ba63b428bafd79..18dc7cdd4e1b63ae8812f0f10f37e6af63c8ceca 100644 (file)
@@ -28,6 +28,8 @@
 #include "wx/fs_inet.h"
 #include "wx/filedlg.h"
 #include "wx/utils.h"
+#include "wx/clipbrd.h"
+#include "wx/dataobj.h"
 
 #include "../../sample.xpm"
 
@@ -53,6 +55,11 @@ public:
                                              wxString *WXUNUSED(redirect)) const;
 
 private:
+    void OnClipboardEvent(wxClipboardTextEvent& event);
+
+#if wxUSE_CLIPBOARD
+    DECLARE_EVENT_TABLE()
+#endif // wxUSE_CLIPBOARD
     DECLARE_NO_COPY_CLASS(MyHtmlWindow)
 };
 
@@ -335,3 +342,32 @@ wxHtmlOpeningStatus MyHtmlWindow::OnOpeningURL(wxHtmlURLType WXUNUSED(type),
     GetRelatedFrame()->SetStatusText(url + _T(" lately opened"),1);
     return wxHTML_OPEN;
 }
+
+#if wxUSE_CLIPBOARD
+BEGIN_EVENT_TABLE(MyHtmlWindow, wxHtmlWindow)
+    EVT_TEXT_COPY(wxID_ANY, MyHtmlWindow::OnClipboardEvent)
+END_EVENT_TABLE()
+
+void MyHtmlWindow::OnClipboardEvent(wxClipboardTextEvent& WXUNUSED(event))
+{
+    // explicitly call wxHtmlWindow::CopySelection() method
+    // and show the first 100 characters of the text copied in the status bar
+    if ( CopySelection() )
+    {
+        wxTextDataObject data;
+        if ( wxTheClipboard && wxTheClipboard->GetData(data) )
+        {
+            const wxString text = data.GetText();
+            const size_t maxTextLength = 100;
+
+            wxLogStatus(wxString::Format(_T("Clipboard: '%s%s'"),
+                        wxString(text, maxTextLength).c_str(),
+                        (text.length() > maxTextLength) ? _T("...")
+                                                        : _T("")));
+            return;
+        }
+    }
+
+    wxLogStatus(_T("Clipboard: nothing"));
+}
+#endif // wxUSE_CLIPBOARD
index 3311725dfce147806d1308c5de76b1db060db0bf..9478914c41b99d5e5ba37d1d2a5e77dba9e1750c 100644 (file)
@@ -1394,9 +1394,14 @@ void wxHtmlWindow::OnMouseLeave(wxMouseEvent& event)
 
 void wxHtmlWindow::OnKeyUp(wxKeyEvent& event)
 {
-    if ( IsSelectionEnabled() && event.GetKeyCode() == 'C' && event.CmdDown() )
+    if ( IsSelectionEnabled() &&
+            (event.GetKeyCode() == 'C' && event.CmdDown()) )
     {
-        (void) CopySelection();
+        wxClipboardTextEvent evt(wxEVT_COMMAND_TEXT_COPY, GetId());
+
+        evt.SetEventObject(this);
+
+        GetEventHandler()->ProcessEvent(evt);
     }
 }
 
@@ -1405,6 +1410,11 @@ void wxHtmlWindow::OnCopy(wxCommandEvent& WXUNUSED(event))
     (void) CopySelection();
 }
 
+void wxHtmlWindow::OnClipboardEvent(wxClipboardTextEvent& WXUNUSED(event))
+{
+    (void) CopySelection();
+}
+
 void wxHtmlWindow::OnDoubleClick(wxMouseEvent& event)
 {
     // select word under cursor:
@@ -1545,6 +1555,7 @@ BEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow)
     EVT_MOUSE_CAPTURE_LOST(wxHtmlWindow::OnMouseCaptureLost)
     EVT_KEY_UP(wxHtmlWindow::OnKeyUp)
     EVT_MENU(wxID_COPY, wxHtmlWindow::OnCopy)
+    EVT_TEXT_COPY(wxID_ANY, wxHtmlWindow::OnClipboardEvent)
 #endif // wxUSE_CLIPBOARD
 END_EVENT_TABLE()