Correctly initialise ref count in custom scheme class factory.
[wxWidgets.git] / include / wx / msw / webview_ie.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/webviewie.h
3 // Purpose: wxMSW IE wxWebView backend
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef wxWebViewIE_H
11 #define wxWebViewIE_H
12
13 #include "wx/setup.h"
14
15 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
16
17 #include "wx/control.h"
18 #include "wx/webview.h"
19 #include "wx/msw/ole/automtn.h"
20 #include "wx/msw/ole/activex.h"
21 #include "wx/msw/missing.h"
22 #include "wx/sharedptr.h"
23 #include "wx/vector.h"
24
25 struct IHTMLDocument2;
26 class wxFSFile;
27
28 class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView
29 {
30 public:
31
32 wxWebViewIE() {}
33
34 wxWebViewIE(wxWindow* parent,
35 wxWindowID id,
36 const wxString& url = wxWebViewDefaultURLStr,
37 const wxPoint& pos = wxDefaultPosition,
38 const wxSize& size = wxDefaultSize,
39 long style = 0,
40 const wxString& name = wxWebViewNameStr)
41 {
42 Create(parent, id, url, pos, size, style, name);
43 }
44
45 bool Create(wxWindow* parent,
46 wxWindowID id,
47 const wxString& url = wxWebViewDefaultURLStr,
48 const wxPoint& pos = wxDefaultPosition,
49 const wxSize& size = wxDefaultSize,
50 long style = 0,
51 const wxString& name = wxWebViewNameStr);
52
53 virtual void LoadURL(const wxString& url);
54 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
55 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
56 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
57
58 virtual bool CanGoForward() const;
59 virtual bool CanGoBack() const;
60 virtual void GoBack();
61 virtual void GoForward();
62 virtual void ClearHistory();
63 virtual void EnableHistory(bool enable = true);
64 virtual void Stop();
65 virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
66
67 virtual wxString GetPageSource() const;
68 virtual wxString GetPageText() const;
69
70 virtual bool IsBusy() const;
71 virtual wxString GetCurrentURL() const;
72 virtual wxString GetCurrentTitle() const;
73
74 virtual void SetZoomType(wxWebViewZoomType);
75 virtual wxWebViewZoomType GetZoomType() const;
76 virtual bool CanSetZoomType(wxWebViewZoomType) const;
77
78 virtual void Print();
79
80 virtual void SetPage(const wxString& html, const wxString& baseUrl);
81
82 virtual wxWebViewZoom GetZoom() const;
83 virtual void SetZoom(wxWebViewZoom zoom);
84
85 //Clipboard functions
86 virtual bool CanCut() const;
87 virtual bool CanCopy() const;
88 virtual bool CanPaste() const;
89 virtual void Cut();
90 virtual void Copy();
91 virtual void Paste();
92
93 //Undo / redo functionality
94 virtual bool CanUndo() const;
95 virtual bool CanRedo() const;
96 virtual void Undo();
97 virtual void Redo();
98
99 //Editing functions
100 virtual void SetEditable(bool enable = true);
101 virtual bool IsEditable() const;
102
103 //Selection
104 virtual void SelectAll();
105 virtual bool HasSelection() const;
106 virtual void DeleteSelection();
107 virtual wxString GetSelectedText() const;
108 virtual wxString GetSelectedSource() const;
109 virtual void ClearSelection();
110
111 virtual void RunScript(const wxString& javascript);
112
113 //Virtual Filesystem Support
114 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
115
116 // ---- IE-specific methods
117
118 // FIXME: I seem to be able to access remote webpages even in offline mode...
119 bool IsOfflineMode();
120 void SetOfflineMode(bool offline);
121
122 wxWebViewZoom GetIETextZoom() const;
123 void SetIETextZoom(wxWebViewZoom level);
124
125 wxWebViewZoom GetIEOpticalZoom() const;
126 void SetIEOpticalZoom(wxWebViewZoom level);
127
128 void onActiveXEvent(wxActiveXEvent& evt);
129 void onEraseBg(wxEraseEvent&) {}
130
131 DECLARE_EVENT_TABLE();
132
133 private:
134 wxActiveXContainer* m_container;
135 wxAutomationObject m_ie;
136 IWebBrowser2* m_webBrowser;
137 DWORD m_dwCookie;
138
139 //We store the current zoom type;
140 wxWebViewZoomType m_zoomType;
141
142 /** The "Busy" property of IWebBrowser2 does not always return busy when
143 * we'd want it to; this variable may be set to true in cases where the
144 * Busy property is false but should be true.
145 */
146 bool m_isBusy;
147 //We manage our own history, the history list contains the history items
148 //which are added as documentcomplete events arrive, unless we are loading
149 //an item from the history. The position is stored as an int, and reflects
150 //where we are in the history list.
151 wxVector<wxSharedPtr<wxWebViewHistoryItem> > m_historyList;
152 int m_historyPosition;
153 bool m_historyLoadingFromList;
154 bool m_historyEnabled;
155
156 //Generic helper functions for IHtmlDocument commands
157 bool CanExecCommand(wxString command) const;
158 void ExecCommand(wxString command);
159 IHTMLDocument2* GetDocument() const;
160
161 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE);
162 };
163
164 class VirtualProtocol : public IInternetProtocol
165 {
166 protected:
167 ULONG m_refCount;
168 IInternetProtocolSink* m_protocolSink;
169 wxString m_html;
170 VOID * fileP;
171
172 wxFSFile* m_file;
173 wxSharedPtr<wxWebViewHandler> m_handler;
174
175 public:
176 VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler);
177 ~VirtualProtocol();
178
179 //IUnknown
180 ULONG STDMETHODCALLTYPE AddRef();
181 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
182 ULONG STDMETHODCALLTYPE Release();
183
184 //IInternetProtocolRoot
185 HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason),
186 DWORD WXUNUSED(dwOptions))
187 { return E_NOTIMPL; }
188 HRESULT STDMETHODCALLTYPE Continue(PROTOCOLDATA *WXUNUSED(pProtocolData))
189 { return S_OK; }
190 HRESULT STDMETHODCALLTYPE Resume() { return S_OK; }
191 HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl,
192 IInternetProtocolSink *pOIProtSink,
193 IInternetBindInfo *pOIBindInfo,
194 DWORD grfPI,
195 HANDLE_PTR dwReserved);
196 HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; }
197 HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; }
198
199 //IInternetProtocol
200 HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions))
201 { return S_OK; }
202 HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead);
203 HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER WXUNUSED(dlibMove),
204 DWORD WXUNUSED(dwOrigin),
205 ULARGE_INTEGER* WXUNUSED(plibNewPosition))
206 { return E_FAIL; }
207 HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; }
208 };
209
210 class ClassFactory : public IClassFactory
211 {
212 public:
213 ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_handler(handler), m_refCount(0) {}
214 //IUnknown
215 ULONG STDMETHODCALLTYPE AddRef();
216 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
217 ULONG STDMETHODCALLTYPE Release();
218
219 //IClassFactory
220 HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
221 REFIID riid, void** ppvObject);
222 HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
223 private:
224 ULONG m_refCount;
225 wxSharedPtr<wxWebViewHandler> m_handler;
226 };
227
228 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
229
230 #endif // wxWebViewIE_H