Add a new event type for new window creation, document and implement under MSW. Update the sample to veto new window events, this means under Window we no long get Internet Explorer windows appearing for some links.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@67785 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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_
|
||||
|
@@ -119,6 +119,10 @@ enum wxWebViewBackend
|
||||
The integer associated with this event will be a wxWebNavigationError item.
|
||||
The string associated with this event may contain a backend-specific more
|
||||
precise error message/code.
|
||||
@event{EVT_WEB_VIEW_NEWWINDOW(id, func)}
|
||||
Process a @c wxEVT_COMMAND_WEB_VIEW_NEWWINDOW event, generated when a new
|
||||
window is created. This event may be vetoed to prevent a new window showing,
|
||||
for example if you want to open the url in the existing window or a new tab.
|
||||
@endEventTable
|
||||
|
||||
@library{wxweb}
|
||||
@@ -333,6 +337,10 @@ public:
|
||||
The integer associated with this event will be a wxWebNavigationError item.
|
||||
The string associated with this event may contain a backend-specific more
|
||||
precise error message/code.
|
||||
@event{EVT_WEB_VIEW_NEWWINDOW(id, func)}
|
||||
Process a @c wxEVT_COMMAND_WEB_VIEW_NEWWINDOW event, generated when a new
|
||||
window is created. This event may be vetoed to prevent a new window showing,
|
||||
for example if you want to open the url in the existing window or a new tab.
|
||||
@endEventTable
|
||||
|
||||
@library{wxweb}
|
||||
@@ -357,24 +365,25 @@ public:
|
||||
*/
|
||||
const wxString& GetTarget() const;
|
||||
|
||||
// default copy ctor, assignment operator and dtor are ok
|
||||
virtual wxEvent* Clone() const;
|
||||
|
||||
/**
|
||||
Get whether this event may be vetoed (stopped/prevented). Only
|
||||
meaningful for events fired before navigation takes place.
|
||||
meaningful for events fired before navigation takes place or new
|
||||
window events.
|
||||
*/
|
||||
bool CanVeto() const;
|
||||
|
||||
/**
|
||||
Whether this event was vetoed (stopped/prevented). Only meaningful for
|
||||
events fired before navigation takes place.
|
||||
events fired before navigation takes place or new window events.
|
||||
*/
|
||||
bool IsVetoed() const;
|
||||
|
||||
/**
|
||||
Veto (prevent/stop) this event. Only meaningful for events fired
|
||||
before navigation takes place. Only valid if CanVeto() returned true.
|
||||
before navigation takes place or new window events. Only valid
|
||||
if CanVeto() returned true.
|
||||
*/
|
||||
void Veto();
|
||||
};
|
@@ -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);
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user