]> git.saurik.com Git - wxWidgets.git/blob - src/common/webview.cpp
4b2e7dc8ce36fe05d7771a1098d7964761f9121d
[wxWidgets.git] / src / common / webview.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: webview.cpp
3 // Purpose: Common interface and events for web view component
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #if wxUSE_WEBVIEW
14
15 #if defined(__BORLANDC__)
16 #pragma hdrstop
17 #endif
18
19 #include "wx/webview.h"
20
21 #if defined(__WXOSX_COCOA__) || defined(__WXOSX_CARBON__)
22 #include "wx/osx/webview_webkit.h"
23 #elif defined(__WXGTK__)
24 #include "wx/gtk/webview_webkit.h"
25 #elif defined(__WXMSW__)
26 #include "wx/msw/webview_ie.h"
27 #endif
28
29 // DLL options compatibility check:
30 #include "wx/app.h"
31 WX_CHECK_BUILD_OPTIONS("wxWEBVIEW")
32
33 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[] = "wxWebView";
34 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[] = "about:blank";
35 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendIE[] = "wxWebViewIE";
36 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendWebKit[] = "wxWebViewWebKit";
37
38 #ifdef __WXMSW__
39 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = "wxWebViewIE";
40 #else
41 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = "wxWebViewWebKit";
42 #endif
43
44 wxIMPLEMENT_ABSTRACT_CLASS(wxWebView, wxControl);
45 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewEvent, wxCommandEvent);
46
47 wxDEFINE_EVENT( wxEVT_WEBVIEW_NAVIGATING, wxWebViewEvent );
48 wxDEFINE_EVENT( wxEVT_WEBVIEW_NAVIGATED, wxWebViewEvent );
49 wxDEFINE_EVENT( wxEVT_WEBVIEW_LOADED, wxWebViewEvent );
50 wxDEFINE_EVENT( wxEVT_WEBVIEW_ERROR, wxWebViewEvent );
51 wxDEFINE_EVENT( wxEVT_WEBVIEW_NEWWINDOW, wxWebViewEvent );
52 wxDEFINE_EVENT( wxEVT_WEBVIEW_TITLE_CHANGED, wxWebViewEvent );
53
54 wxStringWebViewFactoryMap wxWebView::m_factoryMap;
55
56 // static
57 wxWebView* wxWebView::New(const wxString& backend)
58 {
59 wxStringWebViewFactoryMap::iterator iter = FindFactory(backend);
60
61 if(iter == m_factoryMap.end())
62 return NULL;
63 else
64 return (*iter).second->Create();
65 }
66
67 // static
68 wxWebView* wxWebView::New(wxWindow* parent, wxWindowID id, const wxString& url,
69 const wxPoint& pos, const wxSize& size,
70 const wxString& backend, long style,
71 const wxString& name)
72 {
73 wxStringWebViewFactoryMap::iterator iter = FindFactory(backend);
74
75 if(iter == m_factoryMap.end())
76 return NULL;
77 else
78 return (*iter).second->Create(parent, id, url, pos, size, style, name);
79
80 }
81
82 // static
83 void wxWebView::RegisterFactory(const wxString& backend,
84 wxSharedPtr<wxWebViewFactory> factory)
85 {
86 m_factoryMap[backend] = factory;
87 }
88
89 // static
90 wxStringWebViewFactoryMap::iterator wxWebView::FindFactory(const wxString &backend)
91 {
92 // Initialise the map, it checks internally for existing factories
93 InitFactoryMap();
94
95 return m_factoryMap.find(backend);
96 }
97
98 // static
99 void wxWebView::InitFactoryMap()
100 {
101 #ifdef __WXMSW__
102 if(m_factoryMap.find(wxWebViewBackendIE) == m_factoryMap.end())
103 RegisterFactory(wxWebViewBackendIE, wxSharedPtr<wxWebViewFactory>
104 (new wxWebViewFactoryIE));
105 #else
106 if(m_factoryMap.find(wxWebViewBackendWebKit) == m_factoryMap.end())
107 RegisterFactory(wxWebViewBackendWebKit, wxSharedPtr<wxWebViewFactory>
108 (new wxWebViewFactoryWebKit));
109 #endif
110 }
111
112 #endif // wxUSE_WEBVIEW