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 Copy();
virtual void Paste(); 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 */ /** FIXME: hack to work around signals being received too early */
bool m_ready; bool m_ready;

View File

@@ -85,6 +85,12 @@ public:
virtual void Copy(); virtual void Copy();
virtual void Paste(); virtual void Paste();
//Undo / redo functionality
virtual bool CanUndo();
virtual bool CanRedo();
virtual void Undo();
virtual void Redo();
// ---- IE-specific methods // ---- IE-specific methods
// FIXME: I seem to be able to access remote webpages even in offline mode... // 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 Cut() = 0;
virtual void Copy() = 0; virtual void Copy() = 0;
virtual void Paste() = 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 class WXDLLIMPEXP_WEB wxWebNavigationEvent : public wxCommandEvent

View File

@@ -74,6 +74,8 @@ public:
void OnCut(wxCommandEvent& evt); void OnCut(wxCommandEvent& evt);
void OnCopy(wxCommandEvent& evt); void OnCopy(wxCommandEvent& evt);
void OnPaste(wxCommandEvent& evt); void OnPaste(wxCommandEvent& evt);
void OnUndo(wxCommandEvent& evt);
void OnRedo(wxCommandEvent& evt);
private: private:
wxTextCtrl* m_url; wxTextCtrl* m_url;
@@ -98,6 +100,8 @@ private:
wxMenuItem* m_edit_cut; wxMenuItem* m_edit_cut;
wxMenuItem* m_edit_copy; wxMenuItem* m_edit_copy;
wxMenuItem* m_edit_paste; wxMenuItem* m_edit_paste;
wxMenuItem* m_edit_undo;
wxMenuItem* m_edit_redo;
wxTimer* m_timer; wxTimer* m_timer;
int m_animation_angle; 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_cut = editmenu->Append(wxID_ANY, _("Cut"));
m_edit_copy = editmenu->Append(wxID_ANY, _("Copy")); m_edit_copy = editmenu->Append(wxID_ANY, _("Copy"));
m_edit_paste = editmenu->Append(wxID_ANY, _("Paste")); 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->AppendSeparator();
m_tools_menu->AppendSubMenu(editmenu, "Edit"); m_tools_menu->AppendSubMenu(editmenu, "Edit");
@@ -268,6 +275,10 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
wxCommandEventHandler(WebFrame::OnCopy), NULL, this ); wxCommandEventHandler(WebFrame::OnCopy), NULL, this );
Connect(m_edit_paste->GetId(), wxEVT_COMMAND_MENU_SELECTED, Connect(m_edit_paste->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnPaste), NULL, this ); 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) void WebFrame::OnAnimationTimer(wxTimerEvent& evt)
@@ -407,6 +418,16 @@ void WebFrame::OnPaste(wxCommandEvent& evt)
m_browser->Paste(); 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 * Callback invoked when there is a request to load a new page (for instance
* when the user clicks a link) * when the user clicks a link)
@@ -509,6 +530,9 @@ void WebFrame::OnToolsClicked(wxCommandEvent& evt)
m_edit_cut->Enable(m_browser->CanCut()); m_edit_cut->Enable(m_browser->CanCut());
m_edit_copy->Enable(m_browser->CanCopy()); m_edit_copy->Enable(m_browser->CanCopy());
m_edit_paste->Enable(m_browser->CanPaste()); 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() ); wxPoint position = ScreenToClient( wxGetMousePosition() );
PopupMenu(m_tools_menu, position.x, position.y); 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)); 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() wxString wxWebViewWebKit::GetCurrentURL()
{ {
// FIXME: check which encoding the web kit control uses instead of // FIXME: check which encoding the web kit control uses instead of

View File

@@ -539,6 +539,25 @@ void wxWebViewIE::Paste()
ExecCommand("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) bool wxWebViewIE::CanExecCommand(wxString command)
{ {
wxVariant documentVariant = m_ie.GetProperty("Document"); wxVariant documentVariant = m_ie.GetProperty("Document");