virtual bool CanGoBack() const;
virtual bool CanGoForward() const;
virtual void ClearHistory();
+ virtual void EnableContextMenu(bool enable = true);
virtual void EnableHistory(bool enable = true);
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
class DocHostUIHandler : public wxIDocHostUIHandler
{
public:
- DocHostUIHandler() {};
+ DocHostUIHandler(wxWebView* browser) { m_browser = browser; }
~DocHostUIHandler() {};
+
virtual HRESULT wxSTDCALL ShowContextMenu(DWORD dwID, POINT *ppt,
IUnknown *pcmdtReserved,
IDispatch *pdispReserved);
IDataObject **ppDORet);
//IUnknown
DECLARE_IUNKNOWN_METHODS;
+
+private:
+ wxWebView* m_browser;
};
class wxFindPointers
class WXDLLIMPEXP_WEBVIEW wxWebView : public wxControl
{
public:
+ wxWebView()
+ {
+ m_showMenu = true;
+ }
+
virtual ~wxWebView() {}
virtual bool Create(wxWindow* parent,
const wxString& name = wxWebViewNameStr);
//General methods
+ virtual void EnableContextMenu(bool enable = true)
+ {
+ m_showMenu = enable;
+ }
virtual wxString GetCurrentTitle() const = 0;
virtual wxString GetCurrentURL() const = 0;
// TODO: handle choosing a frame when calling GetPageSource()?
virtual wxString GetPageSource() const = 0;
virtual wxString GetPageText() const = 0;
virtual bool IsBusy() const = 0;
+ virtual bool IsContextMenuEnabled() const { return m_showMenu; }
virtual bool IsEditable() const = 0;
virtual void LoadURL(const wxString& url) = 0;
virtual void Print() = 0;
protected:
virtual void DoSetPage(const wxString& html, const wxString& baseUrl) = 0;
+private:
+ bool m_showMenu;
+
wxDECLARE_ABSTRACT_CLASS(wxWebView);
};
*/
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
*/
void OnFindDone(wxCommandEvent& evt);
void OnFindText(wxCommandEvent& evt);
void OnFindOptions(wxCommandEvent& evt);
+ void OnEnableContextMenu(wxCommandEvent& evt);
private:
wxTextCtrl* m_url;
wxMenuItem* m_selection_clear;
wxMenuItem* m_selection_delete;
wxMenuItem* m_find;
+ wxMenuItem* m_context_menu;
wxInfoBar *m_info;
wxStaticText* m_info_text;
wxMenuItem* loadscheme = m_tools_menu->Append(wxID_ANY, _("Custom Scheme 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
m_tools_handle_navigation->Check();
m_tools_handle_new_window->Check();
wxCommandEventHandler(WebFrame::OnUseMemoryFS), NULL, this );
Connect(m_find->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnFind), NULL, this );
+ Connect(m_context_menu->GetId(), wxEVT_COMMAND_MENU_SELECTED,
+ wxCommandEventHandler(WebFrame::OnEnableContextMenu), NULL, this );
//Connect the idle events
Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(WebFrame::OnIdle), NULL, this);
m_browser->LoadURL("memory:page1.htm");
}
+void WebFrame::OnEnableContextMenu(wxCommandEvent& evt)
+{
+ m_browser->EnableContextMenu(evt.IsChecked());
+}
+
void WebFrame::OnFind(wxCommandEvent& WXUNUSED(evt))
{
wxString value = m_browser->GetSelectedText();
m_selection_clear->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
wxMenuHistoryMap::const_iterator it;
for( it = m_histMenuItems.begin(); it != m_histMenuItems.end(); ++it )
}
}
+#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"
//-----------------------------------------------------------------------------
g_signal_connect_after(m_web_view, "resource-request-starting",
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_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)
{
bool newSearch = false;
m_webBrowser->put_RegisterAsBrowser(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);
wxUnusedVar(ppt);
wxUnusedVar(pcmdtReserved);
wxUnusedVar(pdispReserved);
- return E_NOTIMPL;
+ if(m_browser->IsContextMenuEnabled())
+ return E_NOTIMPL;
+ else
+ return S_OK;
}
HRESULT wxSTDCALL DocHostUIHandler::GetHostInfo(DOCHOSTUIINFO *pInfo)
webKitWindow->Print();
}
+
+- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element
+ defaultMenuItems:(NSArray *) defaultMenuItems
+{
+ if(webKitWindow->IsContextMenuEnabled())
+ return defaultMenuItems;
+ else
+ return nil;
+}
@end
#endif //wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT