Add context menu enabling and disabling to wxWebView, all backends supported.
Closes #14789. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73326 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -63,6 +63,7 @@ public:
|
|||||||
virtual bool CanGoBack() const;
|
virtual bool CanGoBack() const;
|
||||||
virtual bool CanGoForward() const;
|
virtual bool CanGoForward() const;
|
||||||
virtual void ClearHistory();
|
virtual void ClearHistory();
|
||||||
|
virtual void EnableContextMenu(bool enable = true);
|
||||||
virtual void EnableHistory(bool enable = true);
|
virtual void EnableHistory(bool enable = true);
|
||||||
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
|
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
|
||||||
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
|
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
|
||||||
|
@@ -271,8 +271,9 @@ private:
|
|||||||
class DocHostUIHandler : public wxIDocHostUIHandler
|
class DocHostUIHandler : public wxIDocHostUIHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DocHostUIHandler() {};
|
DocHostUIHandler(wxWebView* browser) { m_browser = browser; }
|
||||||
~DocHostUIHandler() {};
|
~DocHostUIHandler() {};
|
||||||
|
|
||||||
virtual HRESULT wxSTDCALL ShowContextMenu(DWORD dwID, POINT *ppt,
|
virtual HRESULT wxSTDCALL ShowContextMenu(DWORD dwID, POINT *ppt,
|
||||||
IUnknown *pcmdtReserved,
|
IUnknown *pcmdtReserved,
|
||||||
IDispatch *pdispReserved);
|
IDispatch *pdispReserved);
|
||||||
@@ -319,6 +320,9 @@ public:
|
|||||||
IDataObject **ppDORet);
|
IDataObject **ppDORet);
|
||||||
//IUnknown
|
//IUnknown
|
||||||
DECLARE_IUNKNOWN_METHODS;
|
DECLARE_IUNKNOWN_METHODS;
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxWebView* m_browser;
|
||||||
};
|
};
|
||||||
|
|
||||||
class wxFindPointers
|
class wxFindPointers
|
||||||
|
@@ -103,6 +103,11 @@ extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[];
|
|||||||
class WXDLLIMPEXP_WEBVIEW wxWebView : public wxControl
|
class WXDLLIMPEXP_WEBVIEW wxWebView : public wxControl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
wxWebView()
|
||||||
|
{
|
||||||
|
m_showMenu = true;
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~wxWebView() {}
|
virtual ~wxWebView() {}
|
||||||
|
|
||||||
virtual bool Create(wxWindow* parent,
|
virtual bool Create(wxWindow* parent,
|
||||||
@@ -124,12 +129,17 @@ public:
|
|||||||
const wxString& name = wxWebViewNameStr);
|
const wxString& name = wxWebViewNameStr);
|
||||||
|
|
||||||
//General methods
|
//General methods
|
||||||
|
virtual void EnableContextMenu(bool enable = true)
|
||||||
|
{
|
||||||
|
m_showMenu = enable;
|
||||||
|
}
|
||||||
virtual wxString GetCurrentTitle() const = 0;
|
virtual wxString GetCurrentTitle() const = 0;
|
||||||
virtual wxString GetCurrentURL() const = 0;
|
virtual wxString GetCurrentURL() const = 0;
|
||||||
// TODO: handle choosing a frame when calling GetPageSource()?
|
// TODO: handle choosing a frame when calling GetPageSource()?
|
||||||
virtual wxString GetPageSource() const = 0;
|
virtual wxString GetPageSource() const = 0;
|
||||||
virtual wxString GetPageText() const = 0;
|
virtual wxString GetPageText() const = 0;
|
||||||
virtual bool IsBusy() const = 0;
|
virtual bool IsBusy() const = 0;
|
||||||
|
virtual bool IsContextMenuEnabled() const { return m_showMenu; }
|
||||||
virtual bool IsEditable() const = 0;
|
virtual bool IsEditable() const = 0;
|
||||||
virtual void LoadURL(const wxString& url) = 0;
|
virtual void LoadURL(const wxString& url) = 0;
|
||||||
virtual void Print() = 0;
|
virtual void Print() = 0;
|
||||||
@@ -197,6 +207,9 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void DoSetPage(const wxString& html, const wxString& baseUrl) = 0;
|
virtual void DoSetPage(const wxString& html, const wxString& baseUrl) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_showMenu;
|
||||||
|
|
||||||
wxDECLARE_ABSTRACT_CLASS(wxWebView);
|
wxDECLARE_ABSTRACT_CLASS(wxWebView);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -487,6 +487,20 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void Paste() = 0;
|
virtual void Paste() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@name Context Menu
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
Enable or disbale the right click context menu.
|
||||||
|
*/
|
||||||
|
virtual void EnableContextMenu(bool enable = true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns @true if a context menu will be shown on right click.
|
||||||
|
*/
|
||||||
|
virtual bool IsContextMenuEnabled() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@name History
|
@name History
|
||||||
*/
|
*/
|
||||||
|
@@ -143,6 +143,7 @@ public:
|
|||||||
void OnFindDone(wxCommandEvent& evt);
|
void OnFindDone(wxCommandEvent& evt);
|
||||||
void OnFindText(wxCommandEvent& evt);
|
void OnFindText(wxCommandEvent& evt);
|
||||||
void OnFindOptions(wxCommandEvent& evt);
|
void OnFindOptions(wxCommandEvent& evt);
|
||||||
|
void OnEnableContextMenu(wxCommandEvent& evt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxTextCtrl* m_url;
|
wxTextCtrl* m_url;
|
||||||
@@ -188,6 +189,7 @@ private:
|
|||||||
wxMenuItem* m_selection_clear;
|
wxMenuItem* m_selection_clear;
|
||||||
wxMenuItem* m_selection_delete;
|
wxMenuItem* m_selection_delete;
|
||||||
wxMenuItem* m_find;
|
wxMenuItem* m_find;
|
||||||
|
wxMenuItem* m_context_menu;
|
||||||
|
|
||||||
wxInfoBar *m_info;
|
wxInfoBar *m_info;
|
||||||
wxStaticText* m_info_text;
|
wxStaticText* m_info_text;
|
||||||
@@ -403,6 +405,8 @@ WebFrame::WebFrame(const wxString& url) :
|
|||||||
wxMenuItem* loadscheme = m_tools_menu->Append(wxID_ANY, _("Custom Scheme Example"));
|
wxMenuItem* loadscheme = m_tools_menu->Append(wxID_ANY, _("Custom Scheme Example"));
|
||||||
wxMenuItem* usememoryfs = m_tools_menu->Append(wxID_ANY, _("Memory File System Example"));
|
wxMenuItem* usememoryfs = m_tools_menu->Append(wxID_ANY, _("Memory File System Example"));
|
||||||
|
|
||||||
|
m_context_menu = m_tools_menu->AppendCheckItem(wxID_ANY, _("Enable Context Menu"));
|
||||||
|
|
||||||
//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();
|
||||||
@@ -509,6 +513,8 @@ WebFrame::WebFrame(const wxString& url) :
|
|||||||
wxCommandEventHandler(WebFrame::OnUseMemoryFS), NULL, this );
|
wxCommandEventHandler(WebFrame::OnUseMemoryFS), NULL, this );
|
||||||
Connect(m_find->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
Connect(m_find->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
||||||
wxCommandEventHandler(WebFrame::OnFind), NULL, this );
|
wxCommandEventHandler(WebFrame::OnFind), NULL, this );
|
||||||
|
Connect(m_context_menu->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
||||||
|
wxCommandEventHandler(WebFrame::OnEnableContextMenu), NULL, this );
|
||||||
|
|
||||||
//Connect the idle events
|
//Connect the idle events
|
||||||
Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(WebFrame::OnIdle), NULL, this);
|
Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(WebFrame::OnIdle), NULL, this);
|
||||||
@@ -659,6 +665,11 @@ void WebFrame::OnUseMemoryFS(wxCommandEvent& WXUNUSED(evt))
|
|||||||
m_browser->LoadURL("memory:page1.htm");
|
m_browser->LoadURL("memory:page1.htm");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebFrame::OnEnableContextMenu(wxCommandEvent& evt)
|
||||||
|
{
|
||||||
|
m_browser->EnableContextMenu(evt.IsChecked());
|
||||||
|
}
|
||||||
|
|
||||||
void WebFrame::OnFind(wxCommandEvent& WXUNUSED(evt))
|
void WebFrame::OnFind(wxCommandEvent& WXUNUSED(evt))
|
||||||
{
|
{
|
||||||
wxString value = m_browser->GetSelectedText();
|
wxString value = m_browser->GetSelectedText();
|
||||||
@@ -850,6 +861,8 @@ void WebFrame::OnToolsClicked(wxCommandEvent& WXUNUSED(evt))
|
|||||||
m_selection_clear->Enable(m_browser->HasSelection());
|
m_selection_clear->Enable(m_browser->HasSelection());
|
||||||
m_selection_delete->Enable(m_browser->HasSelection());
|
m_selection_delete->Enable(m_browser->HasSelection());
|
||||||
|
|
||||||
|
m_context_menu->Check(m_browser->IsContextMenuEnabled());
|
||||||
|
|
||||||
//Firstly we clear the existing menu items, then we add the current ones
|
//Firstly we clear the existing menu items, then we add the current ones
|
||||||
wxMenuHistoryMap::const_iterator it;
|
wxMenuHistoryMap::const_iterator it;
|
||||||
for( it = m_histMenuItems.begin(); it != m_histMenuItems.end(); ++it )
|
for( it = m_histMenuItems.begin(); it != m_histMenuItems.end(); ++it )
|
||||||
|
@@ -378,6 +378,23 @@ wxgtk_webview_webkit_resource_req(WebKitWebView *,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WEBKIT_CHECK_VERSION(1, 10, 0)
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
wxgtk_webview_webkit_context_menu(WebKitWebView *,
|
||||||
|
GtkWidget *,
|
||||||
|
WebKitHitTestResult *,
|
||||||
|
gboolean,
|
||||||
|
wxWebViewWebKit *webKitCtrl)
|
||||||
|
{
|
||||||
|
if(webKitCtrl->IsContextMenuEnabled())
|
||||||
|
return FALSE;
|
||||||
|
else
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -433,6 +450,11 @@ bool wxWebViewWebKit::Create(wxWindow *parent,
|
|||||||
|
|
||||||
g_signal_connect_after(m_web_view, "resource-request-starting",
|
g_signal_connect_after(m_web_view, "resource-request-starting",
|
||||||
G_CALLBACK(wxgtk_webview_webkit_resource_req), this);
|
G_CALLBACK(wxgtk_webview_webkit_resource_req), this);
|
||||||
|
|
||||||
|
#if WEBKIT_CHECK_VERSION(1, 10, 0)
|
||||||
|
g_signal_connect_after(m_web_view, "context-menu",
|
||||||
|
G_CALLBACK(wxgtk_webview_webkit_context_menu), this);
|
||||||
|
#endif
|
||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
@@ -926,6 +948,15 @@ void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
|
|||||||
m_handlerList.push_back(handler);
|
m_handlerList.push_back(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxWebViewWebKit::EnableContextMenu(bool enable)
|
||||||
|
{
|
||||||
|
#if !WEBKIT_CHECK_VERSION(1, 10, 0) //If we are using an older version
|
||||||
|
g_object_set(webkit_web_view_get_settings(m_web_view),
|
||||||
|
"enable-default-context-menu", enable, NULL);
|
||||||
|
#endif
|
||||||
|
wxWebView::EnableContextMenu(enable);
|
||||||
|
}
|
||||||
|
|
||||||
long wxWebViewWebKit::Find(const wxString& text, int flags)
|
long wxWebViewWebKit::Find(const wxString& text, int flags)
|
||||||
{
|
{
|
||||||
bool newSearch = false;
|
bool newSearch = false;
|
||||||
|
@@ -100,7 +100,7 @@ bool wxWebViewIE::Create(wxWindow* parent,
|
|||||||
m_webBrowser->put_RegisterAsBrowser(VARIANT_TRUE);
|
m_webBrowser->put_RegisterAsBrowser(VARIANT_TRUE);
|
||||||
m_webBrowser->put_RegisterAsDropTarget(VARIANT_TRUE);
|
m_webBrowser->put_RegisterAsDropTarget(VARIANT_TRUE);
|
||||||
|
|
||||||
m_uiHandler = new DocHostUIHandler;
|
m_uiHandler = new DocHostUIHandler(this);
|
||||||
|
|
||||||
m_container = new wxIEContainer(this, IID_IWebBrowser2, m_webBrowser, m_uiHandler);
|
m_container = new wxIEContainer(this, IID_IWebBrowser2, m_webBrowser, m_uiHandler);
|
||||||
|
|
||||||
@@ -1549,7 +1549,10 @@ HRESULT wxSTDCALL DocHostUIHandler::ShowContextMenu(DWORD dwID, POINT *ppt,
|
|||||||
wxUnusedVar(ppt);
|
wxUnusedVar(ppt);
|
||||||
wxUnusedVar(pcmdtReserved);
|
wxUnusedVar(pcmdtReserved);
|
||||||
wxUnusedVar(pdispReserved);
|
wxUnusedVar(pdispReserved);
|
||||||
return E_NOTIMPL;
|
if(m_browser->IsContextMenuEnabled())
|
||||||
|
return E_NOTIMPL;
|
||||||
|
else
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT wxSTDCALL DocHostUIHandler::GetHostInfo(DOCHOSTUIINFO *pInfo)
|
HRESULT wxSTDCALL DocHostUIHandler::GetHostInfo(DOCHOSTUIINFO *pInfo)
|
||||||
|
@@ -1346,6 +1346,15 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out)
|
|||||||
|
|
||||||
webKitWindow->Print();
|
webKitWindow->Print();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element
|
||||||
|
defaultMenuItems:(NSArray *) defaultMenuItems
|
||||||
|
{
|
||||||
|
if(webKitWindow->IsContextMenuEnabled())
|
||||||
|
return defaultMenuItems;
|
||||||
|
else
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif //wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT
|
#endif //wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT
|
||||||
|
Reference in New Issue
Block a user