1 #ifdef _WIN32
2
3 #include <CtrlLib/CtrlLib.h>
4 #include "ActiveX.h"
5
6
7 namespace Upp {
8
Browse(const String & strurl)9 bool FirefoxBrowser::Browse(const String &strurl) {
10 IIWebBrowser webBrowser(this);
11 if (!webBrowser)
12 return false;
13
14 OleStr url;
15 if (!url.Set(strurl))
16 return false;
17
18 webBrowser->Navigate2(url, 0, 0, 0, 0);
19
20 return true;
21 }
22
ShowHTML(const String & html)23 bool FirefoxBrowser::ShowHTML(const String &html) {
24 IIWebBrowser webBrowser(this);
25 if (!webBrowser)
26 return false;
27
28 CBSTR pbstrLocationURL;
29 if (webBrowser->get_LocationURL((BSTR *)pbstrLocationURL) != S_OK) {
30 OleStr url;
31 url.Set("about:blank");
32 webBrowser->Navigate2(url, 0, 0, 0, 0);
33 }
34 bool ret = false;
35 LPDISPATCH lpDisp;
36 if (!webBrowser->get_Document(&lpDisp)) {
37 IHTMLDocument2 *htmDoc2;
38 if (!lpDisp->QueryInterface(IID_IHTMLDocument2, (void**)&htmDoc2)) {
39 SAFEARRAY *sfArray;
40 static const SAFEARRAYBOUND abound = {1, 0};
41 if ((sfArray = SafeArrayCreate(VT_VARIANT, 1, (SAFEARRAYBOUND*)&abound))) {
42 VARIANT *pVar;
43 if (!SafeArrayAccessData(sfArray, (void**)&pVar)) {
44 pVar->vt = VT_BSTR;
45 if(!BSTRSet(html, pVar->bstrVal))
46 ret = false;
47 else {
48 ret = true;
49 htmDoc2->write(sfArray);
50 htmDoc2->close();
51 }
52 }
53 SafeArrayDestroy(sfArray);
54 }
55 htmDoc2->Release();
56 }
57 lpDisp->Release();
58 }
59 return ret;
60 }
61
GoForward()62 bool FirefoxBrowser::GoForward() {
63 IIWebBrowser webBrowser(this);
64 if (!webBrowser)
65 return false;
66
67 if (webBrowser->GoForward() == S_OK)
68 return true;
69 return false;
70 }
71
GoBack()72 bool FirefoxBrowser::GoBack() {
73 IIWebBrowser webBrowser(this);
74 if (!webBrowser)
75 return false;
76
77 if (webBrowser->GoBack() == S_OK)
78 return true;
79 return false;
80 }
81
GetLocation()82 String FirefoxBrowser::GetLocation() {
83 IIWebBrowser webBrowser(this);
84 if (!webBrowser)
85 return "";
86
87 CBSTR pbstrLocationURL;
88 if (webBrowser->get_LocationURL((BSTR *)pbstrLocationURL) != S_OK)
89 return "";
90
91 return pbstrLocationURL.ToString();
92 }
93
GetTitle()94 String FirefoxBrowser::GetTitle() {
95 IIWebBrowser webBrowser(this);
96 if (!webBrowser)
97 return "";
98
99 CBSTR pbstrLocationURL;
100 if (webBrowser->get_LocationName((BSTR *)pbstrLocationURL) != S_OK)
101 return "";
102
103 return pbstrLocationURL.ToString();
104 }
105
GetOffline(bool & offline)106 bool FirefoxBrowser::GetOffline(bool &offline) {
107 IIWebBrowser webBrowser(this);
108 if (!webBrowser)
109 return false;
110
111 VARIANT_BOOL voffline;
112 if (webBrowser->get_Offline(&voffline) != S_OK)
113 return false;
114
115 offline = (voffline == VARIANT_TRUE) ? true : false;
116 return true;
117 }
118
GetReadyState()119 String FirefoxBrowser::GetReadyState() {
120 IIWebBrowser webBrowser(this);
121 if (!webBrowser)
122 return "";
123
124 READYSTATE readystate;
125 if (webBrowser->get_ReadyState(&readystate) != S_OK)
126 return "";
127
128 switch (readystate) {
129 case READYSTATE_UNINITIALIZED: return "Uninitialized"; // Default initialization state
130 case READYSTATE_LOADING: return "Loading"; // Object is currently loading its properties
131 case READYSTATE_LOADED: return "Loaded"; // Object was initialized
132 case READYSTATE_INTERACTIVE: return "Interactive"; // Object is interactive, but not all its data is available
133 case READYSTATE_COMPLETE: return "Complete"; // Object has received all its data
134 default: return "Unknown";
135 }
136 }
137
GoHome()138 bool FirefoxBrowser::GoHome() {
139 IIWebBrowser webBrowser(this);
140 if (!webBrowser)
141 return false;
142
143 CBSTR pbstrLocationURL;
144 if (webBrowser->GoHome() == S_OK)
145 return true;
146
147 return false;
148 }
149
RefreshPage()150 bool FirefoxBrowser::RefreshPage() {
151 IIWebBrowser webBrowser(this);
152 if (!webBrowser)
153 return false;
154
155 CBSTR pbstrLocationURL;
156 if (webBrowser->Refresh() == S_OK)
157 return true;
158
159 return false;
160 }
161
Stop()162 bool FirefoxBrowser::Stop() {
163 IIWebBrowser webBrowser(this);
164 if (!webBrowser)
165 return false;
166
167 CBSTR pbstrLocationURL;
168 if (webBrowser->Stop() == S_OK)
169 return true;
170
171 return false;
172 }
173
SetSilent(bool val)174 bool FirefoxBrowser::SetSilent(bool val) {
175 IIWebBrowser webBrowser(this);
176 if (!webBrowser)
177 return false;
178
179 VARIANT_BOOL vb = val ? VARIANT_TRUE : VARIANT_FALSE;
180 if (webBrowser->put_Silent(vb) == S_OK)
181 return true;
182
183 return false;
184 }
185
186 }
187
188 #endif
189