]>
Commit | Line | Data |
---|---|---|
61b98a2d SL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: webview.cpp | |
3 | // Purpose: Common interface and events for web view component | |
4 | // Author: Marianne Gagnon | |
5 | // Id: $Id$ | |
153530af | 6 | // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton |
61b98a2d SL |
7 | // Licence: wxWindows licence |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
384b8d9f SL |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
88cc66f7 | 13 | #if wxUSE_WEBVIEW |
9c805dec | 14 | |
384b8d9f SL |
15 | #if defined(__BORLANDC__) |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
61b98a2d SL |
19 | #include "wx/webview.h" |
20 | ||
91614f1a | 21 | #if defined(__WXOSX_COCOA__) || defined(__WXOSX_CARBON__) |
8290e3cd | 22 | #include "wx/osx/webview_webkit.h" |
91614f1a | 23 | #elif defined(__WXGTK__) |
8290e3cd | 24 | #include "wx/gtk/webview_webkit.h" |
91614f1a | 25 | #elif defined(__WXMSW__) |
8290e3cd | 26 | #include "wx/msw/webview_ie.h" |
91614f1a | 27 | #endif |
61b98a2d | 28 | |
3544f421 SL |
29 | // DLL options compatibility check: |
30 | #include "wx/app.h" | |
467d261e | 31 | WX_CHECK_BUILD_OPTIONS("wxWEBVIEW") |
3544f421 | 32 | |
467d261e SL |
33 | extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[] = "wxWebView"; |
34 | extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[] = "about:blank"; | |
4c687fff SL |
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 | |
61b98a2d | 43 | |
cddf4541 | 44 | wxIMPLEMENT_ABSTRACT_CLASS(wxWebView, wxControl); |
04fa04d8 SL |
45 | wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewEvent, wxCommandEvent); |
46 | ||
ce7fe42e VZ |
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 ); | |
61b98a2d | 53 | |
4c687fff SL |
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 | ||
61b98a2d | 82 | // static |
4c687fff SL |
83 | void wxWebView::RegisterFactory(const wxString& backend, |
84 | wxSharedPtr<wxWebViewFactory> factory) | |
61b98a2d | 85 | { |
4c687fff | 86 | m_factoryMap[backend] = factory; |
61b98a2d SL |
87 | } |
88 | ||
4c687fff SL |
89 | // static |
90 | wxStringWebViewFactoryMap::iterator wxWebView::FindFactory(const wxString &backend) | |
91 | { | |
8fdbcf4d SL |
92 | // Initialise the map, it checks internally for existing factories |
93 | InitFactoryMap(); | |
4c687fff SL |
94 | |
95 | return m_factoryMap.find(backend); | |
96 | } | |
97 | ||
61b98a2d | 98 | // static |
4c687fff | 99 | void wxWebView::InitFactoryMap() |
61b98a2d | 100 | { |
4c687fff | 101 | #ifdef __WXMSW__ |
8fdbcf4d SL |
102 | if(m_factoryMap.find(wxWebViewBackendIE) == m_factoryMap.end()) |
103 | RegisterFactory(wxWebViewBackendIE, wxSharedPtr<wxWebViewFactory> | |
4c687fff SL |
104 | (new wxWebViewFactoryIE)); |
105 | #else | |
8fdbcf4d SL |
106 | if(m_factoryMap.find(wxWebViewBackendWebKit) == m_factoryMap.end()) |
107 | RegisterFactory(wxWebViewBackendWebKit, wxSharedPtr<wxWebViewFactory> | |
4c687fff SL |
108 | (new wxWebViewFactoryWebKit)); |
109 | #endif | |
61b98a2d | 110 | } |
9c805dec | 111 | |
88cc66f7 | 112 | #endif // wxUSE_WEBVIEW |