]> git.saurik.com Git - wxWidgets.git/commitdiff
Add a new event type for new window creation, document and implement under MSW. Updat...
authorSteve Lamerton <steve.lamerton@gmail.com>
Thu, 26 May 2011 18:43:18 +0000 (18:43 +0000)
committerSteve Lamerton <steve.lamerton@gmail.com>
Thu, 26 May 2011 18:43:18 +0000 (18:43 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@67785 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/webview.h
interface/wx/webview.h
samples/web/web.cpp
src/common/webview.cpp
src/msw/webview_ie.cpp

index 365e7664e4ac0575550445d516054a3b7444808b..1d69d7ec60ca9d4c708175a423e1d8e0d423879e 100644 (file)
@@ -363,6 +363,7 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NAVIGATING, wx
 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebNavigationEvent );
 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebNavigationEvent );
 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebNavigationEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebNavigationEvent );
 
 typedef void (wxEvtHandler::*wxWebNavigationEventFunction)
              (wxWebNavigationEvent&);
@@ -386,6 +387,10 @@ typedef void (wxEvtHandler::*wxWebNavigationEventFunction)
     wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \
                      wxHtmlNavigatingEventHandler(fn))
 
+#define EVT_WEB_VIEW_NEWWINDOW(id, fn) \
+    wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
+                     wxHtmlNavigatingEventHandler(fn))
+
 #endif // wxUSE_WEB
 
 #endif // _WX_WEB_VIEW_H_
index aec5aac7feea3298ac7a6b1c7576981e51a1199e..f93f42d452e7e4be3e07bc293dc6ecded4ee2811 100644 (file)
@@ -119,6 +119,10 @@ enum wxWebViewBackend
        The integer associated with this event will be a wxWebNavigationError item.\r
        The string associated with this event may contain a backend-specific more\r
        precise error message/code.\r
+    @event{EVT_WEB_VIEW_NEWWINDOW(id, func)}\r
+       Process a @c wxEVT_COMMAND_WEB_VIEW_NEWWINDOW event, generated when a new\r
+       window is created. This event may be vetoed to prevent a new window showing,\r
+       for example if you want to open the url in the existing window or a new tab.\r
     @endEventTable\r
    \r
     @library{wxweb}\r
@@ -333,6 +337,10 @@ public:
        The integer associated with this event will be a wxWebNavigationError item.\r
        The string associated with this event may contain a backend-specific more\r
        precise error message/code.\r
+    @event{EVT_WEB_VIEW_NEWWINDOW(id, func)}\r
+       Process a @c wxEVT_COMMAND_WEB_VIEW_NEWWINDOW event, generated when a new\r
+       window is created. This event may be vetoed to prevent a new window showing,\r
+       for example if you want to open the url in the existing window or a new tab.\r
     @endEventTable\r
 \r
     @library{wxweb}\r
@@ -357,24 +365,25 @@ public:
     */\r
     const wxString& GetTarget() const;\r
 \r
-    // default copy ctor, assignment operator and dtor are ok\r
     virtual wxEvent* Clone() const;\r
 \r
     /** \r
         Get whether this event may be vetoed (stopped/prevented). Only\r
-        meaningful for events fired before navigation takes place.\r
+        meaningful for events fired before navigation takes place or new \r
+        window events.\r
      */\r
     bool CanVeto() const;\r
 \r
     /** \r
         Whether this event was vetoed (stopped/prevented). Only meaningful for\r
-        events fired before navigation takes place.\r
+        events fired before navigation takes place or new window events.\r
      */\r
     bool IsVetoed() const;\r
 \r
     /** \r
         Veto (prevent/stop) this event. Only meaningful for events fired\r
-        before navigation takes place. Only valid if CanVeto() returned true.\r
+        before navigation takes place or new window events. Only valid \r
+        if CanVeto() returned true.\r
      */\r
     void Veto();\r
 };
\ No newline at end of file
index a3194bb8b4132997231052f57c19805b07ef86b8..7e010be1b1cff9422112b68abb3efeb9dc22641e 100644 (file)
@@ -315,6 +315,17 @@ public:
         
         m_browser_ctrl->GetZoom();
     }
+
+    /**
+     * On new window, we veto to stop extra windows appearing
+     */
+    void onNewWindow(wxWebNavigationEvent& evt)
+    {
+        wxLogMessage("%s", "New window; url='" + evt.GetHref() + "'");
+        evt.Veto();
+
+        updateState();
+    }
     
     /**
      * Invoked when user selects the "View Source" menu item
@@ -626,6 +637,9 @@ bool wxMiniApp::OnInit()
     m_browser_ctrl->Connect(m_browser_ctrl->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR,
                       wxWebNavigationEventHandler(wxMiniApp::onError), NULL, this);
 
+    m_browser_ctrl->Connect(m_browser_ctrl->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
+                      wxWebNavigationEventHandler(wxMiniApp::onNewWindow), NULL, this);
+
     frame->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(wxMiniApp::onClose), NULL, this);
     Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(wxMiniApp::onQuitMenu), NULL, this);
 
index f9d95538034408857444b074f64db483074d668e..f575b5460b1c8a97dbd72668875f04f2a6c13d99 100644 (file)
@@ -35,6 +35,7 @@ wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_NAVIGATING, wxWebNavigationEvent );
 wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebNavigationEvent );
 wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebNavigationEvent );
 wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebNavigationEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebNavigationEvent );
 
 // static
 wxWebView* wxWebView::New(wxWebViewBackend backend)
index 7838686bccfae3349d37dc8dcc558c67e9cccb57..d51a3e7f41449250e95c78438e154d6393a4f671 100644 (file)
@@ -658,11 +658,21 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
             }
             break;
         }
-        case DISPID_NEWWINDOW2:
+        case DISPID_NEWWINDOW3:
         {
-            wxActiveXEventNativeMSW* nativeParams = evt.GetNativeParameters();
-            // Cancel the attempt to open a new window
-            *V_BOOLREF(&nativeParams->pDispParams->rgvarg[0]) = VARIANT_TRUE;
+            wxString url = evt[4].GetString();
+
+            wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
+                                       GetId(), url, wxEmptyString, true);
+            event.SetEventObject(this);
+            HandleWindowEvent(event);
+
+            //If we veto the event then we cancel the new window
+            if (event.IsVetoed())
+            {
+                wxActiveXEventNativeMSW* nativeParams = evt.GetNativeParameters();
+                *V_BOOLREF(&nativeParams->pDispParams->rgvarg[3]) = VARIANT_TRUE;
+            }
             break;
         }
     }