From: Vadim Zeitlin <vadim@wxwidgets.org> Date: Mon, 30 Oct 2006 16:18:45 +0000 (+0000) Subject: generate wxEVT_COMMAND_TEXT_COPY event in wxHtmlWindow X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/0f11c2334567bd440bb2676f43d3376badc921f2 generate wxEVT_COMMAND_TEXT_COPY event in wxHtmlWindow git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42729 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 1533e33fbe..c5d0b669d0 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/include/wx/html/htmlwin.h b/include/wx/html/htmlwin.h index d4629c9ad5..d2a55a7695 100644 --- a/include/wx/html/htmlwin.h +++ b/include/wx/html/htmlwin.h @@ -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); diff --git a/samples/html/test/test.cpp b/samples/html/test/test.cpp index 0336006f31..18dc7cdd4e 100644 --- a/samples/html/test/test.cpp +++ b/samples/html/test/test.cpp @@ -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 diff --git a/src/html/htmlwin.cpp b/src/html/htmlwin.cpp index 3311725dfc..9478914c41 100644 --- a/src/html/htmlwin.cpp +++ b/src/html/htmlwin.cpp @@ -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()