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&);
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_
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
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
*/\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
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
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);
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)
}
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;
}
}