From 97e49559fb0e1dfc43d66e8784ec47182f5507e9 Mon Sep 17 00:00:00 2001 From: Steve Lamerton Date: Sat, 2 Jul 2011 15:07:46 +0000 Subject: [PATCH] Implement undo and redo for the ie and gtk webkit backends. Extend the sample to show their use. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68135 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/webview_webkit.h | 6 ++++++ include/wx/msw/webview_ie.h | 6 ++++++ include/wx/webview.h | 6 ++++++ samples/web/web.cpp | 24 ++++++++++++++++++++++++ src/gtk/webview_webkit.cpp | 20 ++++++++++++++++++++ src/msw/webview_ie.cpp | 19 +++++++++++++++++++ 6 files changed, 81 insertions(+) diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h index 69fef706f8..07d71e2310 100644 --- a/include/wx/gtk/webview_webkit.h +++ b/include/wx/gtk/webview_webkit.h @@ -128,6 +128,12 @@ public: virtual void Copy(); virtual void Paste(); + //Undo / redo functionality + virtual bool CanUndo(); + virtual bool CanRedo(); + virtual void Undo(); + virtual void Redo(); + /** FIXME: hack to work around signals being received too early */ bool m_ready; diff --git a/include/wx/msw/webview_ie.h b/include/wx/msw/webview_ie.h index c288314f03..522690c88e 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -85,6 +85,12 @@ public: virtual void Copy(); virtual void Paste(); + //Undo / redo functionality + virtual bool CanUndo(); + virtual bool CanRedo(); + virtual void Undo(); + virtual void Redo(); + // ---- IE-specific methods // FIXME: I seem to be able to access remote webpages even in offline mode... diff --git a/include/wx/webview.h b/include/wx/webview.h index 3dadea6a32..0eeb5c1acf 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -333,6 +333,12 @@ public: virtual void Cut() = 0; virtual void Copy() = 0; virtual void Paste() = 0; + + //Undo / redo functionality + virtual bool CanUndo() = 0; + virtual bool CanRedo() = 0; + virtual void Undo() = 0; + virtual void Redo() = 0; }; class WXDLLIMPEXP_WEB wxWebNavigationEvent : public wxCommandEvent diff --git a/samples/web/web.cpp b/samples/web/web.cpp index f2f8f6a04b..4e99892b4c 100644 --- a/samples/web/web.cpp +++ b/samples/web/web.cpp @@ -74,6 +74,8 @@ public: void OnCut(wxCommandEvent& evt); void OnCopy(wxCommandEvent& evt); void OnPaste(wxCommandEvent& evt); + void OnUndo(wxCommandEvent& evt); + void OnRedo(wxCommandEvent& evt); private: wxTextCtrl* m_url; @@ -98,6 +100,8 @@ private: wxMenuItem* m_edit_cut; wxMenuItem* m_edit_copy; wxMenuItem* m_edit_paste; + wxMenuItem* m_edit_undo; + wxMenuItem* m_edit_redo; wxTimer* m_timer; int m_animation_angle; @@ -206,6 +210,9 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") m_edit_cut = editmenu->Append(wxID_ANY, _("Cut")); m_edit_copy = editmenu->Append(wxID_ANY, _("Copy")); m_edit_paste = editmenu->Append(wxID_ANY, _("Paste")); + editmenu->AppendSeparator(); + m_edit_undo = editmenu->Append(wxID_ANY, _("Undo")); + m_edit_redo = editmenu->Append(wxID_ANY, _("Redo")); m_tools_menu->AppendSeparator(); m_tools_menu->AppendSubMenu(editmenu, "Edit"); @@ -268,6 +275,10 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") wxCommandEventHandler(WebFrame::OnCopy), NULL, this ); Connect(m_edit_paste->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WebFrame::OnPaste), NULL, this ); + Connect(m_edit_undo->GetId(), wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(WebFrame::OnUndo), NULL, this ); + Connect(m_edit_redo->GetId(), wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(WebFrame::OnRedo), NULL, this ); } void WebFrame::OnAnimationTimer(wxTimerEvent& evt) @@ -407,6 +418,16 @@ void WebFrame::OnPaste(wxCommandEvent& evt) m_browser->Paste(); } +void WebFrame::OnUndo(wxCommandEvent& evt) +{ + m_browser->Undo(); +} + +void WebFrame::OnRedo(wxCommandEvent& evt) +{ + m_browser->Redo(); +} + /** * Callback invoked when there is a request to load a new page (for instance * when the user clicks a link) @@ -509,6 +530,9 @@ void WebFrame::OnToolsClicked(wxCommandEvent& evt) m_edit_cut->Enable(m_browser->CanCut()); m_edit_copy->Enable(m_browser->CanCopy()); m_edit_paste->Enable(m_browser->CanPaste()); + + m_edit_undo->Enable(m_browser->CanUndo()); + m_edit_redo->Enable(m_browser->CanRedo()); wxPoint position = ScreenToClient( wxGetMousePosition() ); PopupMenu(m_tools_menu, position.x, position.y); diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index 3e53beaa25..d4f0c20071 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -519,6 +519,26 @@ void wxWebViewWebKit::Paste() webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(web_view)); } +bool wxWebViewWebKit::CanUndo() +{ + return webkit_web_view_can_undo(WEBKIT_WEB_VIEW(web_view)); +} + +bool wxWebViewWebKit::CanRedo() +{ + return webkit_web_view_can_redo(WEBKIT_WEB_VIEW(web_view)); +} + +void wxWebViewWebKit::Undo() +{ + webkit_web_view_undo(WEBKIT_WEB_VIEW(web_view)); +} + +void wxWebViewWebKit::Redo() +{ + webkit_web_view_redo(WEBKIT_WEB_VIEW(web_view)); +} + wxString wxWebViewWebKit::GetCurrentURL() { // FIXME: check which encoding the web kit control uses instead of diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index dcb8437654..c3b53be9d8 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -539,6 +539,25 @@ void wxWebViewIE::Paste() ExecCommand("Paste"); } +bool wxWebViewIE::CanUndo() +{ + return CanExecCommand("Undo"); +} +bool wxWebViewIE::CanRedo() +{ + return CanExecCommand("Redo"); +} + +void wxWebViewIE::Undo() +{ + ExecCommand("Undo"); +} + +void wxWebViewIE::Redo() +{ + ExecCommand("Redo"); +} + bool wxWebViewIE::CanExecCommand(wxString command) { wxVariant documentVariant = m_ie.GetProperty("Document"); -- 2.45.2