From 62e8551fa0e23df08ae689af918a836e095a3881 Mon Sep 17 00:00:00 2001 From: Steve Lamerton Date: Wed, 29 Jun 2011 12:03:36 +0000 Subject: [PATCH] Update the sample to show how to block navigation and new window events git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68091 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/web/web.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/samples/web/web.cpp b/samples/web/web.cpp index 81b6de1354..225bd90a13 100644 --- a/samples/web/web.cpp +++ b/samples/web/web.cpp @@ -87,6 +87,8 @@ private: wxMenuItem* m_tools_medium; wxMenuItem* m_tools_large; wxMenuItem* m_tools_largest; + wxMenuItem* m_tools_handle_navigation; + wxMenuItem* m_tools_handle_new_window; wxTimer* m_timer; int m_animation_angle; @@ -180,6 +182,13 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") m_tools_medium = m_tools_menu->AppendCheckItem(wxID_ANY, _("Medium")); m_tools_large = m_tools_menu->AppendCheckItem(wxID_ANY, _("Large")); m_tools_largest = m_tools_menu->AppendCheckItem(wxID_ANY, _("Largest")); + m_tools_menu->AppendSeparator(); + m_tools_handle_navigation = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle Navigation")); + m_tools_handle_new_window = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle New Windows")); + + //By default we want to handle naigation and new windows + m_tools_handle_navigation->Check(); + m_tools_handle_new_window->Check(); // Connect the toolbar events @@ -346,14 +355,12 @@ void WebFrame::OnNavigationRequest(wxWebNavigationEvent& evt) evt.GetTarget() + "')"); wxASSERT(m_browser->IsBusy()); - - // Uncomment this to see how to block navigation requests - //int answer = wxMessageBox("Proceed with navigation to '" + evt.GetHref() + "'?", - // "Proceed with navigation?", wxYES_NO ); - //if (answer != wxYES) - //{ - // evt.Veto(); - //} + + //If we don't want to handle navigation then veto the event and navigation + //will not take place + if(!m_tools_handle_navigation->IsChecked()) + evt.Veto(); + UpdateState(); } @@ -381,6 +388,14 @@ void WebFrame::OnDocumentLoaded(wxWebNavigationEvent& evt) void WebFrame::OnNewWindow(wxWebNavigationEvent& evt) { wxLogMessage("%s", "New window; url='" + evt.GetHref() + "'"); + + //If we handle new window events then just load them in this window as we + //are a single window browser + if(m_tools_handle_new_window->IsChecked()) + m_browser->LoadUrl(evt.GetHref()); + + //We always veto because we handle the event, otherwise under windows a new + //internet explorer windowis created evt.Veto(); UpdateState(); -- 2.45.2