Mercurial > dwindows
comparison win/browser.c @ 2019:583c2d62845c
Win: Implemented the STARTED and COMPLETE signals for DW_SIGNAL_HTML_CHANGED for IE.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 08 Nov 2019 12:37:37 +0000 |
parents | 663d79f28e46 |
children | 0cce5fed4594 |
comparison
equal
deleted
inserted
replaced
2018:663d79f28e46 | 2019:583c2d62845c |
---|---|
22 | 22 |
23 | 23 |
24 #include <winsock2.h> | 24 #include <winsock2.h> |
25 #include <windows.h> | 25 #include <windows.h> |
26 #include <exdisp.h> // Defines of stuff like IWebBrowser2. This is an include file with Visual C 6 and above | 26 #include <exdisp.h> // Defines of stuff like IWebBrowser2. This is an include file with Visual C 6 and above |
27 #include <exdispid.h> | |
27 #include <mshtml.h> // Defines of stuff like IHTMLDocument2. This is an include file with Visual C 6 and above | 28 #include <mshtml.h> // Defines of stuff like IHTMLDocument2. This is an include file with Visual C 6 and above |
28 #include <mshtmhst.h> // Defines of stuff like IDocHostUIHandler. This is an include file with Visual C 6 and above | 29 #include <mshtmhst.h> // Defines of stuff like IDocHostUIHandler. This is an include file with Visual C 6 and above |
29 #include <crtdbg.h> // for _ASSERT() | 30 #include <crtdbg.h> // for _ASSERT() |
30 #include <initguid.h> | 31 #include <initguid.h> |
31 #include "dw.h" | 32 #include "dw.h" |
1094 // DWEventHandler's VTable | 1095 // DWEventHandler's VTable |
1095 #undef INTERFACE | 1096 #undef INTERFACE |
1096 #define INTERFACE DWEventHandler | 1097 #define INTERFACE DWEventHandler |
1097 DECLARE_INTERFACE_ (INTERFACE, IUnknown) | 1098 DECLARE_INTERFACE_ (INTERFACE, IUnknown) |
1098 { | 1099 { |
1099 // IUnknown functions | 1100 // Interface functions |
1100 STDMETHOD (QueryInterface) (THIS_ REFIID, void **) PURE; | 1101 STDMETHOD (QueryInterface) (THIS_ REFIID, void **) PURE; |
1101 STDMETHOD_ (ULONG, AddRef) (THIS) PURE; | 1102 STDMETHOD_ (ULONG, AddRef) (THIS) PURE; |
1102 STDMETHOD_ (ULONG, Release) (THIS) PURE; | 1103 STDMETHOD_ (ULONG, Release) (THIS) PURE; |
1103 // Extra functions | 1104 STDMETHOD_ (HRESULT, GetTypeInfoCount) (THIS_ UINT *) PURE; |
1104 STDMETHOD_ (void, DocumentComplete) (THIS_ IDispatch*, VARIANT*) PURE; | 1105 STDMETHOD_ (HRESULT, GetTypeInfo) (THIS_ UINT, LCID, ITypeInfo **) PURE; |
1106 STDMETHOD_ (HRESULT, GetIDsOfNames) (THIS_ REFIID, LPOLESTR *, UINT, LCID, DISPID *) PURE; | |
1107 STDMETHOD_ (HRESULT, Invoke) (THIS_ DISPID, REFIID, LCID, WORD, DISPPARAMS, VARIANT *, EXCEPINFO *, UINT *) PURE; | |
1105 }; | 1108 }; |
1106 | 1109 |
1107 // IWebBrowser2 supports us giving it only 1 DWEventHandler object, so for simplicity, we | 1110 // IWebBrowser2 supports us giving it only 1 DWEventHandler object, so for simplicity, we |
1108 // can just declare it as a global. That way, we don't need to allocate it, free it, | 1111 // can just declare it as a global. That way, we don't need to allocate it, free it, |
1109 // nor maintain a reference count for it. Here's our 1 DWEventHandler object. | 1112 // nor maintain a reference count for it. Here's our 1 DWEventHandler object. |
1112 | 1115 |
1113 static HRESULT STDMETHODCALLTYPE DWEventHandler_QueryInterface(DWEventHandler *this, REFIID vTableGuid, void **ppv) | 1116 static HRESULT STDMETHODCALLTYPE DWEventHandler_QueryInterface(DWEventHandler *this, REFIID vTableGuid, void **ppv) |
1114 { | 1117 { |
1115 // This is an DWEventHandler object, so we must recognize DWEventHandler VTable's GUID, | 1118 // This is an DWEventHandler object, so we must recognize DWEventHandler VTable's GUID, |
1116 // Our DWEventHandler can also masquerade as an IUnknown | 1119 // Our DWEventHandler can also masquerade as an IUnknown |
1117 if (!IsEqualIID(vTableGuid, &IID_IUnknown) && !IsEqualIID(vTableGuid, &DIID_DWEventHandler)) | 1120 if (!IsEqualIID(vTableGuid, &IID_IUnknown) && !IsEqualIID(vTableGuid, &DIID_DWebBrowserEvents2)) |
1118 { | 1121 { |
1119 *ppv = 0; | 1122 *ppv = 0; |
1120 return(E_NOINTERFACE); | 1123 return(E_NOINTERFACE); |
1121 } | 1124 } |
1122 | 1125 |
1136 | 1139 |
1137 static ULONG STDMETHODCALLTYPE DWEventHandler_Release(DWEventHandler *this) | 1140 static ULONG STDMETHODCALLTYPE DWEventHandler_Release(DWEventHandler *this) |
1138 { | 1141 { |
1139 return(1); | 1142 return(1); |
1140 } | 1143 } |
1141 | 1144 static HRESULT STDMETHODCALLTYPE DWEventHandler_GetTypeInfoCount(DWEventHandler *this, UINT * pctinfo) |
1142 // This is the extra function for DWEventHandler. | 1145 { |
1143 | 1146 return E_NOTIMPL; |
1144 static void STDMETHODCALLTYPE DWEventHandler_DocumentComplete(DWEventHandler *this, IDispatch* pDisp, VARIANT* URL) | 1147 } |
1145 { | 1148 static HRESULT STDMETHODCALLTYPE DWebBrowserEvent2_GetTypeInfo(DWEventHandler *this, UINT iTInfo, LCID lcid, ITypeInfo ** ppTInfo) |
1146 dw_debug("DocumentComplete() called!\n"); | 1149 { |
1150 return E_NOTIMPL; | |
1151 } | |
1152 static HRESULT STDMETHODCALLTYPE DWebBrowserEvent2_GetIDsOfNames(DWEventHandler *this, REFIID riid, LPOLESTR * rgszNames, UINT cNames, LCID lcid, DISPID * rgDispId) | |
1153 { | |
1154 return E_NOTIMPL; | |
1155 } | |
1156 static HRESULT STDMETHODCALLTYPE DWebBrowserEvent2_Invoke(DWEventHandler *this, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pDispParams, VARIANT * pVarResult, EXCEPINFO * pExcepInfo, UINT * puArgErr) | |
1157 { | |
1158 switch (dispIdMember) | |
1159 { | |
1160 case DISPID_BEFORENAVIGATE2: | |
1161 { | |
1162 // Params are in the variant array from right to left wrt how they are defined in the documentation. | |
1163 LPCWSTR pszURL = pDispParams->rgvarg[5].pvarVal->bstrVal; | |
1164 IWebBrowser2* pwb = (IWebBrowser2*)pDispParams->rgvarg[pDispParams->cArgs - 1].byref; | |
1165 LONG_PTR tmp; | |
1166 HWND hwnd; | |
1167 | |
1168 /* Get the window handle and URL */ | |
1169 pwb->lpVtbl->get_HWND(pwb, &tmp); | |
1170 hwnd = (HWND)tmp; | |
1171 /* Send the event for signal handling */ | |
1172 _wndproc(hwnd, WM_USER+101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), (LPARAM)WideToUTF8((LPWSTR)pszURL)); | |
1173 | |
1174 // Make sure you don't accidently cancel the navigation. | |
1175 *V_BOOLREF(&pDispParams->rgvarg[0]) = VARIANT_FALSE; | |
1176 break; | |
1177 } | |
1178 case DISPID_DOCUMENTCOMPLETE: | |
1179 { | |
1180 IWebBrowser2* pwb = (IWebBrowser2*)pDispParams->rgvarg[pDispParams->cArgs - 1].byref; | |
1181 LONG_PTR tmp; | |
1182 HWND hwnd; | |
1183 BSTR locationURL; | |
1184 | |
1185 /* Get the window handle and URL */ | |
1186 pwb->lpVtbl->get_HWND(pwb, &tmp); | |
1187 hwnd = (HWND)tmp; | |
1188 pwb->lpVtbl->get_LocationURL(pwb, &locationURL); | |
1189 /* Send the event for signal handling */ | |
1190 _wndproc(hwnd, WM_USER+101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), (LPARAM)WideToUTF8((LPWSTR)locationURL)); | |
1191 break; | |
1192 } | |
1193 default: | |
1194 return DISP_E_MEMBERNOTFOUND; | |
1195 } | |
1196 return NOERROR; | |
1147 } | 1197 } |
1148 | 1198 |
1149 | 1199 |
1150 // Our DWEventHandler VTable. We need only one of these, so we can | 1200 // Our DWEventHandler VTable. We need only one of these, so we can |
1151 // declare it static | 1201 // declare it static |
1152 static const DWEventHandlerVtbl DWEventHandler_Vtbl = { | 1202 static const DWEventHandlerVtbl DWEventHandler_Vtbl = { |
1153 DWEventHandler_QueryInterface, | 1203 DWEventHandler_QueryInterface, |
1154 DWEventHandler_AddRef, | 1204 DWEventHandler_AddRef, |
1155 DWEventHandler_Release, | 1205 DWEventHandler_Release, |
1156 DWEventHandler_DocumentComplete | 1206 DWEventHandler_GetTypeInfoCount, |
1207 DWebBrowserEvent2_GetTypeInfo, | |
1208 DWebBrowserEvent2_GetIDsOfNames, | |
1209 DWebBrowserEvent2_Invoke | |
1157 }; | 1210 }; |
1158 | 1211 |
1159 | 1212 |
1160 /*************************** UnEmbedBrowserObject() ************************ | 1213 /*************************** UnEmbedBrowserObject() ************************ |
1161 * Called to detach the browser object from our host window, and free its | 1214 * Called to detach the browser object from our host window, and free its |
1777 else | 1830 else |
1778 { | 1831 { |
1779 // Get IWebBrowser2' IConnectionPoint sub-object for specifically giving | 1832 // Get IWebBrowser2' IConnectionPoint sub-object for specifically giving |
1780 // IWebBRowser2 our DWEventHandler. We do this by calling IConnectionPointContainer's | 1833 // IWebBRowser2 our DWEventHandler. We do this by calling IConnectionPointContainer's |
1781 // FindConnectionPoint, and pass it DWEventHandler VTable's GUID | 1834 // FindConnectionPoint, and pass it DWEventHandler VTable's GUID |
1782 hr = container->lpVtbl->FindConnectionPoint(container, &DIID_DWEventHandler, &point); | 1835 hr = container->lpVtbl->FindConnectionPoint(container, &DIID_DWebBrowserEvents2, &point); |
1783 | 1836 |
1784 // We don't need the IConnectionPointContainer, now that we got the one IConnectionPoint | 1837 // We don't need the IConnectionPointContainer, now that we got the one IConnectionPoint |
1785 // we want (ie, the one we use to give IWebBrowser2 our DWEventHandler) | 1838 // we want (ie, the one we use to give IWebBrowser2 our DWEventHandler) |
1786 container->lpVtbl->Release(container); | 1839 container->lpVtbl->Release(container); |
1787 | 1840 |