Add new clipboard api and support for it in the ie backend. Also extend the sample to demonstrate the new functions.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68129 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Steve Lamerton
2011-07-02 11:45:19 +00:00
parent 19fc1a2f0d
commit 4681a3ea0d
4 changed files with 114 additions and 0 deletions

View File

@@ -77,6 +77,14 @@ public:
virtual wxWebViewZoom GetZoom();
virtual void SetZoom(wxWebViewZoom zoom);
//Clipboard functions
virtual bool CanCut();
virtual bool CanCopy();
virtual bool CanPaste();
virtual void Cut();
virtual void Copy();
virtual void Paste();
// ---- IE-specific methods
// FIXME: I seem to be able to access remote webpages even in offline mode...
@@ -124,6 +132,10 @@ private:
bool m_historyLoadingFromList;
bool m_historyEnabled;
//Generic helper functions for IHtmlDocument commands
bool CanExecCommand(wxString command);
void ExecCommand(wxString command);
};
#endif // wxUSE_WEBVIEW_IE

View File

@@ -324,6 +324,14 @@ public:
* Returns whether the web control is currently busy (e.g. loading a page)
*/
virtual bool IsBusy() = 0;
//Clipboard functions
virtual bool CanCut() = 0;
virtual bool CanCopy() = 0;
virtual bool CanPaste() = 0;
virtual void Cut() = 0;
virtual void Copy() = 0;
virtual void Paste() = 0;
};
class WXDLLIMPEXP_WEB wxWebNavigationEvent : public wxCommandEvent

View File

@@ -71,6 +71,9 @@ public:
void OnSetZoom(wxCommandEvent& evt);
void OnError(wxWebNavigationEvent& evt);
void OnPrint(wxCommandEvent& evt);
void OnCut(wxCommandEvent& evt);
void OnCopy(wxCommandEvent& evt);
void OnPaste(wxCommandEvent& evt);
private:
wxTextCtrl* m_url;
@@ -92,6 +95,9 @@ private:
wxMenuItem* m_tools_handle_navigation;
wxMenuItem* m_tools_handle_new_window;
wxMenuItem* m_tools_enable_history;
wxMenuItem* m_edit_cut;
wxMenuItem* m_edit_copy;
wxMenuItem* m_edit_paste;
wxTimer* m_timer;
int m_animation_angle;
@@ -195,6 +201,15 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
wxMenuItem* clearhist = m_tools_menu->Append(wxID_ANY, _("Clear History"));
m_tools_enable_history = m_tools_menu->AppendCheckItem(wxID_ANY, _("Enable History"));
//Create an editing menu
wxMenu* editmenu = new wxMenu();
m_edit_cut = editmenu->Append(wxID_ANY, _("Cut"));
m_edit_copy = editmenu->Append(wxID_ANY, _("Copy"));
m_edit_paste = editmenu->Append(wxID_ANY, _("Paste"));
m_tools_menu->AppendSeparator();
m_tools_menu->AppendSubMenu(editmenu, "Edit");
//By default we want to handle navigation and new windows
m_tools_handle_navigation->Check();
m_tools_handle_new_window->Check();
@@ -247,6 +262,12 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
wxCommandEventHandler(WebFrame::OnClearHistory), NULL, this );
Connect(m_tools_enable_history->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnEnableHistory), NULL, this );
Connect(m_edit_cut->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnCut), NULL, this );
Connect(m_edit_copy->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnCopy), NULL, this );
Connect(m_edit_paste->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnPaste), NULL, this );
}
void WebFrame::OnAnimationTimer(wxTimerEvent& evt)
@@ -371,6 +392,21 @@ void WebFrame::OnEnableHistory(wxCommandEvent& evt)
UpdateState();
}
void WebFrame::OnCut(wxCommandEvent& evt)
{
m_browser->Cut();
}
void WebFrame::OnCopy(wxCommandEvent& evt)
{
m_browser->Copy();
}
void WebFrame::OnPaste(wxCommandEvent& evt)
{
m_browser->Paste();
}
/**
* Callback invoked when there is a request to load a new page (for instance
* when the user clicks a link)
@@ -469,6 +505,10 @@ void WebFrame::OnToolsClicked(wxCommandEvent& evt)
m_tools_largest->Check();
break;
}
m_edit_cut->Enable(m_browser->CanCut());
m_edit_copy->Enable(m_browser->CanCopy());
m_edit_paste->Enable(m_browser->CanPaste());
wxPoint position = ScreenToClient( wxGetMousePosition() );
PopupMenu(m_tools_menu, position.x, position.y);

View File

@@ -510,6 +510,60 @@ wxString wxWebViewIE::GetCurrentTitle()
return out.GetString();
}
bool wxWebViewIE::CanCut()
{
return CanExecCommand("Cut");
}
bool wxWebViewIE::CanCopy()
{
return CanExecCommand("Copy");
}
bool wxWebViewIE::CanPaste()
{
return CanExecCommand("Paste");
}
void wxWebViewIE::Cut()
{
ExecCommand("Cut");
}
void wxWebViewIE::Copy()
{
ExecCommand("Copy");
}
void wxWebViewIE::Paste()
{
ExecCommand("Paste");
}
bool wxWebViewIE::CanExecCommand(wxString command)
{
wxVariant documentVariant = m_ie.GetProperty("Document");
void* documentPtr = documentVariant.GetVoidPtr();
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
wxASSERT(documentPtr && document);
VARIANT_BOOL enabled;
document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled);
return (enabled == VARIANT_TRUE);
}
void wxWebViewIE::ExecCommand(wxString command)
{
wxVariant documentVariant = m_ie.GetProperty("Document");
void* documentPtr = documentVariant.GetVoidPtr();
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
wxASSERT(documentPtr && document);
document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL);
}
void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
{
if (m_webBrowser == NULL) return;