Add new wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED event. Implement for all backends, extend the sample to demonstrate it and document. Also update some copyright notices.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68458 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
e1efca6528
commit
153530afb5
@ -3,7 +3,7 @@
|
|||||||
// Purpose: wxMSW IE wxWebView backend
|
// Purpose: wxMSW IE wxWebView backend
|
||||||
// Author: Marianne Gagnon
|
// Author: Marianne Gagnon
|
||||||
// Id: $Id$
|
// Id: $Id$
|
||||||
// Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
|
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// Purpose: Common interface and events for web view component
|
// Purpose: Common interface and events for web view component
|
||||||
// Author: Marianne Gagnon
|
// Author: Marianne Gagnon
|
||||||
// Id: $Id$
|
// Id: $Id$
|
||||||
// Copyright: (c) 2010 Marianne Gagnon
|
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -421,6 +421,7 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxW
|
|||||||
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_LOADED, 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_ERROR, wxWebNavigationEvent );
|
||||||
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebNavigationEvent );
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebNavigationEvent );
|
||||||
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebNavigationEvent );
|
||||||
|
|
||||||
typedef void (wxEvtHandler::*wxWebNavigationEventFunction)
|
typedef void (wxEvtHandler::*wxWebNavigationEventFunction)
|
||||||
(wxWebNavigationEvent&);
|
(wxWebNavigationEvent&);
|
||||||
@ -448,6 +449,10 @@ typedef void (wxEvtHandler::*wxWebNavigationEventFunction)
|
|||||||
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
|
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
|
||||||
wxHtmlNavigatingEventHandler(fn))
|
wxHtmlNavigatingEventHandler(fn))
|
||||||
|
|
||||||
|
#define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \
|
||||||
|
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \
|
||||||
|
wxHtmlNavigatingEventHandler(fn))
|
||||||
|
|
||||||
#endif // wxUSE_WEB
|
#endif // wxUSE_WEB
|
||||||
|
|
||||||
#endif // _WX_WEB_VIEW_H_
|
#endif // _WX_WEB_VIEW_H_
|
||||||
|
@ -157,6 +157,9 @@ public:
|
|||||||
Process a @c wxEVT_COMMAND_WEB_VIEW_NEWWINDOW event, generated when a new
|
Process a @c wxEVT_COMMAND_WEB_VIEW_NEWWINDOW event, generated when a new
|
||||||
window is created. You must handle this event if you want anything to
|
window is created. You must handle this event if you want anything to
|
||||||
happen, for example to load the page in a new window or tab.
|
happen, for example to load the page in a new window or tab.
|
||||||
|
@event{EVT_WEB_VIEW_TITLE_CHANGED(id, func)}
|
||||||
|
Process a @c wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED event, generated when
|
||||||
|
the page title changes. Use GetString to get the title.
|
||||||
@endEventTable
|
@endEventTable
|
||||||
|
|
||||||
@library{wxweb}
|
@library{wxweb}
|
||||||
@ -521,6 +524,9 @@ public:
|
|||||||
Process a @c wxEVT_COMMAND_WEB_VIEW_NEWWINDOW event, generated when a new
|
Process a @c wxEVT_COMMAND_WEB_VIEW_NEWWINDOW event, generated when a new
|
||||||
window is created. You must handle this event if you want anything to
|
window is created. You must handle this event if you want anything to
|
||||||
happen, for example to load the page in a new window or tab.
|
happen, for example to load the page in a new window or tab.
|
||||||
|
@event{EVT_WEB_VIEW_TITLE_CHANGED(id, func)}
|
||||||
|
Process a @c wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED event, generated when
|
||||||
|
the page title changes. Use GetString to get the title.
|
||||||
@endEventTable
|
@endEventTable
|
||||||
|
|
||||||
@library{wxweb}
|
@library{wxweb}
|
||||||
|
@ -68,6 +68,7 @@ public:
|
|||||||
void OnNavigationComplete(wxWebNavigationEvent& evt);
|
void OnNavigationComplete(wxWebNavigationEvent& evt);
|
||||||
void OnDocumentLoaded(wxWebNavigationEvent& evt);
|
void OnDocumentLoaded(wxWebNavigationEvent& evt);
|
||||||
void OnNewWindow(wxWebNavigationEvent& evt);
|
void OnNewWindow(wxWebNavigationEvent& evt);
|
||||||
|
void OnTitleChanged(wxWebNavigationEvent& evt);
|
||||||
void OnViewSourceRequest(wxCommandEvent& evt);
|
void OnViewSourceRequest(wxCommandEvent& evt);
|
||||||
void OnToolsClicked(wxCommandEvent& evt);
|
void OnToolsClicked(wxCommandEvent& evt);
|
||||||
void OnSetZoom(wxCommandEvent& evt);
|
void OnSetZoom(wxCommandEvent& evt);
|
||||||
@ -266,6 +267,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
|
|||||||
wxWebNavigationEventHandler(WebFrame::OnError), NULL, this);
|
wxWebNavigationEventHandler(WebFrame::OnError), NULL, this);
|
||||||
Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
|
Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
|
||||||
wxWebNavigationEventHandler(WebFrame::OnNewWindow), NULL, this);
|
wxWebNavigationEventHandler(WebFrame::OnNewWindow), NULL, this);
|
||||||
|
Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED,
|
||||||
|
wxWebNavigationEventHandler(WebFrame::OnTitleChanged), NULL, this);
|
||||||
|
|
||||||
// Connect the menu events
|
// Connect the menu events
|
||||||
Connect(viewSource->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
Connect(viewSource->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
||||||
@ -509,6 +512,12 @@ void WebFrame::OnNewWindow(wxWebNavigationEvent& evt)
|
|||||||
UpdateState();
|
UpdateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebFrame::OnTitleChanged(wxWebNavigationEvent& evt)
|
||||||
|
{
|
||||||
|
wxLogMessage("%s", "Title changed; title='" + evt.GetString() + "'");
|
||||||
|
UpdateState();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when user selects the "View Source" menu item
|
* Invoked when user selects the "View Source" menu item
|
||||||
*/
|
*/
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// Purpose: Common interface and events for web view component
|
// Purpose: Common interface and events for web view component
|
||||||
// Author: Marianne Gagnon
|
// Author: Marianne Gagnon
|
||||||
// Id: $Id$
|
// Id: $Id$
|
||||||
// Copyright: (c) 2010 Marianne Gagnon
|
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -38,6 +38,7 @@ wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebNavigationEvent );
|
|||||||
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebNavigationEvent );
|
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebNavigationEvent );
|
||||||
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebNavigationEvent );
|
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebNavigationEvent );
|
||||||
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebNavigationEvent );
|
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebNavigationEvent );
|
||||||
|
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebNavigationEvent );
|
||||||
|
|
||||||
//Taken from wx/filesys.cpp
|
//Taken from wx/filesys.cpp
|
||||||
static wxString EscapeFileNameCharsInURL(const char *in)
|
static wxString EscapeFileNameCharsInURL(const char *in)
|
||||||
|
@ -65,7 +65,7 @@ static gboolean
|
|||||||
wxgtk_webview_webkit_navigation(WebKitWebView*,
|
wxgtk_webview_webkit_navigation(WebKitWebView*,
|
||||||
WebKitWebFrame *frame,
|
WebKitWebFrame *frame,
|
||||||
WebKitNetworkRequest *request,
|
WebKitNetworkRequest *request,
|
||||||
WebKitWebNavigationAction*,
|
WebKitWebNavigationAction *,
|
||||||
WebKitWebPolicyDecision *policy_decision,
|
WebKitWebPolicyDecision *policy_decision,
|
||||||
wxWebViewWebKit *webKitCtrl)
|
wxWebViewWebKit *webKitCtrl)
|
||||||
{
|
{
|
||||||
@ -263,6 +263,24 @@ wxgtk_webview_webkit_new_window(WebKitWebView*,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wxgtk_webview_webkit_title_changed(WebKitWebView *webView,
|
||||||
|
WebKitWebFrame *frame,
|
||||||
|
gchar *title,
|
||||||
|
wxWebViewWebKit *webKitCtrl)
|
||||||
|
{
|
||||||
|
wxWebNavigationEvent thisEvent(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED,
|
||||||
|
webKitCtrl->GetId(),
|
||||||
|
webKitCtrl->GetCurrentURL(),
|
||||||
|
"",
|
||||||
|
true);
|
||||||
|
thisEvent.SetString(wxString(title, wxConvUTF8));
|
||||||
|
|
||||||
|
if (webKitCtrl && webKitCtrl->GetEventHandler())
|
||||||
|
webKitCtrl->GetEventHandler()->ProcessEvent(thisEvent);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -314,6 +332,9 @@ bool wxWebViewWebKit::Create(wxWindow *parent,
|
|||||||
g_signal_connect_after(web_view, "new-window-policy-decision-requested",
|
g_signal_connect_after(web_view, "new-window-policy-decision-requested",
|
||||||
G_CALLBACK(wxgtk_webview_webkit_new_window), this);
|
G_CALLBACK(wxgtk_webview_webkit_new_window), this);
|
||||||
|
|
||||||
|
g_signal_connect_after(web_view, "title-changed",
|
||||||
|
G_CALLBACK(wxgtk_webview_webkit_title_changed), this);
|
||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
PostCreation(size);
|
PostCreation(size);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// Purpose: wxMSW wxWebViewIE class implementation for web view component
|
// Purpose: wxMSW wxWebViewIE class implementation for web view component
|
||||||
// Author: Marianne Gagnon
|
// Author: Marianne Gagnon
|
||||||
// Id: $Id$
|
// Id: $Id$
|
||||||
// Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
|
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -803,6 +803,13 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
|
|||||||
|
|
||||||
case DISPID_TITLECHANGE:
|
case DISPID_TITLECHANGE:
|
||||||
{
|
{
|
||||||
|
wxString title = evt[0].GetString();
|
||||||
|
|
||||||
|
wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED,
|
||||||
|
GetId(), GetCurrentURL(), wxEmptyString, true);
|
||||||
|
event.SetString(title);
|
||||||
|
event.SetEventObject(this);
|
||||||
|
HandleWindowEvent(event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1132,6 +1132,16 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebNavigationError* out)
|
|||||||
{
|
{
|
||||||
webKitWindow->SetPageTitle(wxStringWithNSString( title ));
|
webKitWindow->SetPageTitle(wxStringWithNSString( title ));
|
||||||
}
|
}
|
||||||
|
wxString target = wxStringWithNSString([frame name]);
|
||||||
|
wxWebNavigationEvent thisEvent(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED,
|
||||||
|
wx_webviewctrls[sender]->GetId(),
|
||||||
|
wx_webviewctrls[sender]->GetCurrentURL(),
|
||||||
|
target, true);
|
||||||
|
|
||||||
|
thisEvent.SetString(wxStringWithNSString(title));
|
||||||
|
|
||||||
|
if (webKitWindow && webKitWindow->GetEventHandler())
|
||||||
|
webKitWindow->GetEventHandler()->ProcessEvent(thisEvent);
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user