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
|
||||
// Author: Marianne Gagnon
|
||||
// Id: $Id$
|
||||
// Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
|
||||
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
// Purpose: Common interface and events for web view component
|
||||
// Author: Marianne Gagnon
|
||||
// Id: $Id$
|
||||
// Copyright: (c) 2010 Marianne Gagnon
|
||||
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
|
||||
// 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_ERROR, 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)
|
||||
(wxWebNavigationEvent&);
|
||||
@ -448,6 +449,10 @@ typedef void (wxEvtHandler::*wxWebNavigationEventFunction)
|
||||
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
|
||||
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 // _WX_WEB_VIEW_H_
|
||||
|
@ -157,6 +157,9 @@ public:
|
||||
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
|
||||
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
|
||||
|
||||
@library{wxweb}
|
||||
@ -521,6 +524,9 @@ public:
|
||||
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
|
||||
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
|
||||
|
||||
@library{wxweb}
|
||||
|
@ -68,6 +68,7 @@ public:
|
||||
void OnNavigationComplete(wxWebNavigationEvent& evt);
|
||||
void OnDocumentLoaded(wxWebNavigationEvent& evt);
|
||||
void OnNewWindow(wxWebNavigationEvent& evt);
|
||||
void OnTitleChanged(wxWebNavigationEvent& evt);
|
||||
void OnViewSourceRequest(wxCommandEvent& evt);
|
||||
void OnToolsClicked(wxCommandEvent& evt);
|
||||
void OnSetZoom(wxCommandEvent& evt);
|
||||
@ -266,6 +267,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
|
||||
wxWebNavigationEventHandler(WebFrame::OnError), NULL, this);
|
||||
Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
|
||||
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(viewSource->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
||||
@ -509,6 +512,12 @@ void WebFrame::OnNewWindow(wxWebNavigationEvent& evt)
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
void WebFrame::OnTitleChanged(wxWebNavigationEvent& evt)
|
||||
{
|
||||
wxLogMessage("%s", "Title changed; title='" + evt.GetString() + "'");
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when user selects the "View Source" menu item
|
||||
*/
|
||||
|
@ -3,7 +3,7 @@
|
||||
// Purpose: Common interface and events for web view component
|
||||
// Author: Marianne Gagnon
|
||||
// Id: $Id$
|
||||
// Copyright: (c) 2010 Marianne Gagnon
|
||||
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
|
||||
// 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_ERROR, wxWebNavigationEvent );
|
||||
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebNavigationEvent );
|
||||
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebNavigationEvent );
|
||||
|
||||
//Taken from wx/filesys.cpp
|
||||
static wxString EscapeFileNameCharsInURL(const char *in)
|
||||
|
@ -65,7 +65,7 @@ static gboolean
|
||||
wxgtk_webview_webkit_navigation(WebKitWebView*,
|
||||
WebKitWebFrame *frame,
|
||||
WebKitNetworkRequest *request,
|
||||
WebKitWebNavigationAction*,
|
||||
WebKitWebNavigationAction *,
|
||||
WebKitWebPolicyDecision *policy_decision,
|
||||
wxWebViewWebKit *webKitCtrl)
|
||||
{
|
||||
@ -263,6 +263,24 @@ wxgtk_webview_webkit_new_window(WebKitWebView*,
|
||||
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"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -314,6 +332,9 @@ bool wxWebViewWebKit::Create(wxWindow *parent,
|
||||
g_signal_connect_after(web_view, "new-window-policy-decision-requested",
|
||||
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 );
|
||||
|
||||
PostCreation(size);
|
||||
|
@ -3,7 +3,7 @@
|
||||
// Purpose: wxMSW wxWebViewIE class implementation for web view component
|
||||
// Author: Marianne Gagnon
|
||||
// Id: $Id$
|
||||
// Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
|
||||
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -803,6 +803,13 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1132,6 +1132,16 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebNavigationError* out)
|
||||
{
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user