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
This commit is contained in:
Vadim Zeitlin 2006-10-30 16:18:45 +00:00
parent af3c3334cb
commit 0f11c23345
4 changed files with 52 additions and 3 deletions

View 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:

View 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);

View 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

View 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()