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