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:
@@ -77,6 +77,14 @@ public:
|
|||||||
virtual wxWebViewZoom GetZoom();
|
virtual wxWebViewZoom GetZoom();
|
||||||
virtual void SetZoom(wxWebViewZoom zoom);
|
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
|
// ---- 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...
|
||||||
@@ -124,6 +132,10 @@ private:
|
|||||||
bool m_historyLoadingFromList;
|
bool m_historyLoadingFromList;
|
||||||
bool m_historyEnabled;
|
bool m_historyEnabled;
|
||||||
|
|
||||||
|
//Generic helper functions for IHtmlDocument commands
|
||||||
|
bool CanExecCommand(wxString command);
|
||||||
|
void ExecCommand(wxString command);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // wxUSE_WEBVIEW_IE
|
#endif // wxUSE_WEBVIEW_IE
|
||||||
|
@@ -324,6 +324,14 @@ public:
|
|||||||
* Returns whether the web control is currently busy (e.g. loading a page)
|
* Returns whether the web control is currently busy (e.g. loading a page)
|
||||||
*/
|
*/
|
||||||
virtual bool IsBusy() = 0;
|
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
|
class WXDLLIMPEXP_WEB wxWebNavigationEvent : public wxCommandEvent
|
||||||
|
@@ -71,6 +71,9 @@ public:
|
|||||||
void OnSetZoom(wxCommandEvent& evt);
|
void OnSetZoom(wxCommandEvent& evt);
|
||||||
void OnError(wxWebNavigationEvent& evt);
|
void OnError(wxWebNavigationEvent& evt);
|
||||||
void OnPrint(wxCommandEvent& evt);
|
void OnPrint(wxCommandEvent& evt);
|
||||||
|
void OnCut(wxCommandEvent& evt);
|
||||||
|
void OnCopy(wxCommandEvent& evt);
|
||||||
|
void OnPaste(wxCommandEvent& evt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxTextCtrl* m_url;
|
wxTextCtrl* m_url;
|
||||||
@@ -92,6 +95,9 @@ private:
|
|||||||
wxMenuItem* m_tools_handle_navigation;
|
wxMenuItem* m_tools_handle_navigation;
|
||||||
wxMenuItem* m_tools_handle_new_window;
|
wxMenuItem* m_tools_handle_new_window;
|
||||||
wxMenuItem* m_tools_enable_history;
|
wxMenuItem* m_tools_enable_history;
|
||||||
|
wxMenuItem* m_edit_cut;
|
||||||
|
wxMenuItem* m_edit_copy;
|
||||||
|
wxMenuItem* m_edit_paste;
|
||||||
|
|
||||||
wxTimer* m_timer;
|
wxTimer* m_timer;
|
||||||
int m_animation_angle;
|
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"));
|
wxMenuItem* clearhist = m_tools_menu->Append(wxID_ANY, _("Clear History"));
|
||||||
m_tools_enable_history = m_tools_menu->AppendCheckItem(wxID_ANY, _("Enable 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
|
//By default we want to handle navigation and new windows
|
||||||
m_tools_handle_navigation->Check();
|
m_tools_handle_navigation->Check();
|
||||||
m_tools_handle_new_window->Check();
|
m_tools_handle_new_window->Check();
|
||||||
@@ -247,6 +262,12 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
|
|||||||
wxCommandEventHandler(WebFrame::OnClearHistory), NULL, this );
|
wxCommandEventHandler(WebFrame::OnClearHistory), NULL, this );
|
||||||
Connect(m_tools_enable_history->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
Connect(m_tools_enable_history->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
||||||
wxCommandEventHandler(WebFrame::OnEnableHistory), NULL, this );
|
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)
|
void WebFrame::OnAnimationTimer(wxTimerEvent& evt)
|
||||||
@@ -371,6 +392,21 @@ void WebFrame::OnEnableHistory(wxCommandEvent& evt)
|
|||||||
UpdateState();
|
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
|
* 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)
|
||||||
@@ -470,6 +506,10 @@ void WebFrame::OnToolsClicked(wxCommandEvent& evt)
|
|||||||
break;
|
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() );
|
wxPoint position = ScreenToClient( wxGetMousePosition() );
|
||||||
PopupMenu(m_tools_menu, position.x, position.y);
|
PopupMenu(m_tools_menu, position.x, position.y);
|
||||||
}
|
}
|
||||||
|
@@ -510,6 +510,60 @@ wxString wxWebViewIE::GetCurrentTitle()
|
|||||||
return out.GetString();
|
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)
|
void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
|
||||||
{
|
{
|
||||||
if (m_webBrowser == NULL) return;
|
if (m_webBrowser == NULL) return;
|
||||||
|
Reference in New Issue
Block a user