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
This commit is contained in:
Steve Lamerton
2011-07-02 15:07:46 +00:00
parent ae26e17b93
commit 97e49559fb
6 changed files with 81 additions and 0 deletions

View File

@@ -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;

View File

@@ -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...

View File

@@ -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

View File

@@ -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)
@@ -510,6 +531,9 @@ void WebFrame::OnToolsClicked(wxCommandEvent& evt)
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);
}

View File

@@ -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

View File

@@ -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");