// 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
/////////////////////////////////////////////////////////////////////////////
// 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
/////////////////////////////////////////////////////////////////////////////
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&);
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_
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}
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}
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);
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,
UpdateState();
}
+void WebFrame::OnTitleChanged(wxWebNavigationEvent& evt)
+{
+ wxLogMessage("%s", "Title changed; title='" + evt.GetString() + "'");
+ UpdateState();
+}
+
/**
* Invoked when user selects the "View Source" menu item
*/
// 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
/////////////////////////////////////////////////////////////////////////////
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)
wxgtk_webview_webkit_navigation(WebKitWebView*,
WebKitWebFrame *frame,
WebKitNetworkRequest *request,
- WebKitWebNavigationAction*,
+ WebKitWebNavigationAction *,
WebKitWebPolicyDecision *policy_decision,
wxWebViewWebKit *webKitCtrl)
{
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"
//-----------------------------------------------------------------------------
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);
// 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
/////////////////////////////////////////////////////////////////////////////
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;
}
{
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