Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

319 lines
10 KiB

  1. // Functions stolen from shdocvw\util.cpp
  2. #include "stdafx.h"
  3. #pragma hdrstop
  4. #include "dsubscri.h"
  5. //+-----------------------------------------------------------------
  6. //
  7. // Helper function for getting the TopLeft point of an element from
  8. // mshtml.dll, and have the point reported in inside relative
  9. // coordinates (inside margins, borders and padding.)
  10. //-----------------------------------------------------------------
  11. HRESULT CSSOM_TopLeft(IHTMLElement * pIElem, POINT * ppt)
  12. {
  13. HRESULT hr = E_FAIL;
  14. IHTMLStyle *pistyle;
  15. if (SUCCEEDED(pIElem->get_style(&pistyle)) && pistyle) {
  16. VARIANT var = {0};
  17. if (SUCCEEDED(pistyle->get_top(&var)) && var.bstrVal) {
  18. ppt->y = StrToIntW(var.bstrVal);
  19. VariantClear(&var);
  20. if (SUCCEEDED(pistyle->get_left(&var)) && var.bstrVal) {
  21. ppt->x = StrToIntW(var.bstrVal);
  22. VariantClear(&var);
  23. hr = S_OK;
  24. }
  25. }
  26. pistyle->Release();
  27. }
  28. return hr;
  29. }
  30. HRESULT GetHTMLElementStrMember(IHTMLElement *pielem, LPTSTR pszName, DWORD cchSize, BSTR bstrMember)
  31. {
  32. HRESULT hr;
  33. VARIANT var = {0};
  34. if (!pielem)
  35. hr = E_INVALIDARG;
  36. else if (SUCCEEDED(hr = pielem->getAttribute(bstrMember, TRUE, &var)))
  37. {
  38. if ((VT_BSTR == var.vt) && (var.bstrVal))
  39. {
  40. #ifdef UNICODE
  41. hr = StringCchCopy(pszName, cchSize, (LPCWSTR)var.bstrVal);
  42. #else // UNICODE
  43. SHUnicodeToAnsi((BSTR)var.bstrVal, pszName, cchSize);
  44. #endif // UNICODE
  45. }
  46. else
  47. hr = E_FAIL; // Try VariantChangeType?????
  48. VariantClear(&var);
  49. }
  50. return hr;
  51. }
  52. /******************************************************************\
  53. FUNCTION: IElemCheckForExistingSubscription()
  54. RETURN VALUE:
  55. S_OK - if the IHTMLElement points to a TAG that has a "subscribed_url" property
  56. that is subscribed.
  57. S_FALSE - if the IHTMLElement points to a TAG that has a
  58. "subscribed_url" property but the URL is not subscribed.
  59. E_FAIL - if the IHTMLElement points to a TAG that does not
  60. have a "subscribed_url" property.
  61. \******************************************************************/
  62. HRESULT IElemCheckForExistingSubscription(IHTMLElement *pielem)
  63. {
  64. HRESULT hr = E_FAIL;
  65. TCHAR szHTMLElementName[MAX_URL_STRING];
  66. if (!pielem)
  67. return E_INVALIDARG;
  68. if (SUCCEEDED(GetHTMLElementStrMember(pielem, szHTMLElementName, ARRAYSIZE(szHTMLElementName), (BSTR)(s_sstrSubSRCMember.wsz))))
  69. hr = (CheckForExistingSubscription(szHTMLElementName) ? S_OK : S_FALSE);
  70. return hr;
  71. }
  72. HRESULT IElemCloseDesktopComp(IHTMLElement *pielem)
  73. {
  74. HRESULT hr = E_INVALIDARG;
  75. TCHAR szHTMLElementID[MAX_URL_STRING];
  76. ASSERT(pielem);
  77. if (pielem &&
  78. SUCCEEDED(hr = GetHTMLElementStrMember(pielem, szHTMLElementID, ARRAYSIZE(szHTMLElementID), (BSTR)(s_sstrIDMember.wsz))))
  79. {
  80. hr = UpdateComponentFlags(szHTMLElementID, COMP_CHECKED | COMP_UNCHECKED, COMP_UNCHECKED) ? S_OK : E_FAIL;
  81. if (SUCCEEDED(hr))
  82. {
  83. //
  84. // This IElemCloseDesktopComp() is called from DeskMovr code when a component is
  85. // closed. If this component is the only active desktop component, then calling
  86. // REFRESHACTIVEDESKTOP() here will result in ActiveDesktop being turned off.
  87. // This will free the DeskMovr, which is an ActiveX control on the desktop web page.
  88. // So, when IElemCloseDesktopComp() returns to the caller, the DeskMovr code continues
  89. // to execute; but the object had been freed and hence a fault occurs soon.
  90. // The fix for this problem is to avoid refreshing the active desktop until a better
  91. // time. So, we post a private message to the desktop window. When that window receives
  92. // this message, we call REFRESHACTIVEDESKTOP().
  93. PostMessage(GetShellWindow(), DTM_REFRESHACTIVEDESKTOP, (WPARAM)0, (LPARAM)0);
  94. }
  95. }
  96. return hr;
  97. }
  98. HRESULT IElemGetSubscriptionsDialog(IHTMLElement *pielem, HWND hwnd)
  99. {
  100. HRESULT hr;
  101. TCHAR szHTMLElementName[MAX_URL_STRING];
  102. ASSERT(pielem);
  103. if (SUCCEEDED(hr = GetHTMLElementStrMember(pielem, szHTMLElementName, ARRAYSIZE(szHTMLElementName), (BSTR)(s_sstrSubSRCMember.wsz))))
  104. {
  105. ASSERT(CheckForExistingSubscription(szHTMLElementName)); // We should not have gotten this far.
  106. hr = ShowSubscriptionProperties(szHTMLElementName, hwnd);
  107. }
  108. return hr;
  109. }
  110. HRESULT IElemSubscribeDialog(IHTMLElement *pielem, HWND hwnd)
  111. {
  112. HRESULT hr;
  113. TCHAR szHTMLElementName[MAX_URL_STRING];
  114. ASSERT(pielem);
  115. hr = GetHTMLElementStrMember(pielem, szHTMLElementName, ARRAYSIZE(szHTMLElementName), (BSTR)(s_sstrSubSRCMember.wsz));
  116. if (SUCCEEDED(hr))
  117. {
  118. ASSERT(!CheckForExistingSubscription(szHTMLElementName)); // We should not have gotten this far.
  119. hr = CreateSubscriptionsWizard(SUBSTYPE_DESKTOPURL, szHTMLElementName, NULL, hwnd);
  120. }
  121. return hr;
  122. }
  123. HRESULT IElemUnsubscribe(IHTMLElement *pielem)
  124. {
  125. HRESULT hr;
  126. TCHAR szHTMLElementName[MAX_URL_STRING];
  127. ASSERT(pielem);
  128. hr = GetHTMLElementStrMember(pielem, szHTMLElementName, ARRAYSIZE(szHTMLElementName), (BSTR)(s_sstrSubSRCMember.wsz));
  129. if (SUCCEEDED(hr))
  130. {
  131. ASSERT(CheckForExistingSubscription(szHTMLElementName)); // We should not have gotten this far.
  132. hr = DeleteFromSubscriptionList(szHTMLElementName) ? S_OK : S_FALSE;
  133. }
  134. return hr;
  135. }
  136. HRESULT IElemUpdate(IHTMLElement *pielem)
  137. {
  138. HRESULT hr;
  139. TCHAR szHTMLElementName[MAX_URL_STRING];
  140. ASSERT(pielem);
  141. hr = GetHTMLElementStrMember(pielem, szHTMLElementName, ARRAYSIZE(szHTMLElementName), (BSTR)(s_sstrSubSRCMember.wsz));
  142. if (SUCCEEDED(hr))
  143. {
  144. ASSERT(CheckForExistingSubscription(szHTMLElementName)); // We should not have gotten this far.
  145. hr = UpdateSubscription(szHTMLElementName) ? S_OK : S_FALSE;
  146. }
  147. return hr;
  148. }
  149. void _GetDesktopNavigateURL(LPCWSTR pszUrlSrc, LPWSTR pszUrlDest, DWORD cchUrlDest)
  150. {
  151. HRESULT hr = E_FAIL;
  152. if (0 == StrCmpIW(pszUrlSrc, MY_HOMEPAGE_SOURCEW))
  153. {
  154. // it's about:home so we need to decipher it. shdocvw knows how to do this.
  155. HINSTANCE hinstShdocvw = GetModuleHandle(L"shdocvw.dll");
  156. if (hinstShdocvw)
  157. {
  158. typedef HRESULT (STDAPICALLTYPE *_GETSTDLOCATION)(LPWSTR, DWORD, UINT);
  159. _GETSTDLOCATION _GetStdLocation = (_GETSTDLOCATION)GetProcAddress(hinstShdocvw, (LPCSTR)150);
  160. if (_GetStdLocation)
  161. {
  162. hr = _GetStdLocation(pszUrlDest, cchUrlDest, DVIDM_GOHOME);
  163. }
  164. }
  165. }
  166. if (FAILED(hr))
  167. {
  168. StrCpyNW(pszUrlDest, pszUrlSrc, cchUrlDest);
  169. }
  170. }
  171. HRESULT IElemOpenInNewWindow(IHTMLElement *pielem, IOleClientSite *piOCSite, BOOL fShowFrame, LONG width, LONG height)
  172. {
  173. HRESULT hr;
  174. TCHAR szTemp[MAX_URL_STRING];
  175. BSTR bstrURL;
  176. ASSERT(pielem);
  177. hr = GetHTMLElementStrMember(pielem, szTemp, ARRAYSIZE(szTemp), (BSTR)(s_sstrSubSRCMember.wsz));
  178. if (SUCCEEDED(hr))
  179. {
  180. WCHAR szNavigateUrl[MAX_URL_STRING];
  181. _GetDesktopNavigateURL(szTemp, szNavigateUrl, ARRAYSIZE(szNavigateUrl));
  182. bstrURL = SysAllocStringT(szNavigateUrl);
  183. if (bstrURL)
  184. {
  185. if (ShouldNavigateInIE(bstrURL))
  186. {
  187. IHTMLWindow2 *pihtmlWindow2, *pihtmlWindow2New = NULL;
  188. BSTR bstrFeatures = 0;
  189. if (!fShowFrame)
  190. {
  191. hr = StringCchPrintf(szTemp, ARRAYSIZE(szTemp), TEXT("height=%li, width=%li, status=no, toolbar=no, menubar=no, location=no, resizable=no"), height, width);
  192. if (SUCCEEDED(hr))
  193. {
  194. bstrFeatures = SysAllocString((OLECHAR FAR *)szTemp);
  195. }
  196. }
  197. if (SUCCEEDED(hr))
  198. {
  199. hr = IUnknown_QueryService(piOCSite, SID_SHTMLWindow, IID_IHTMLWindow2, (LPVOID*)&pihtmlWindow2);
  200. if (SUCCEEDED(hr) && pihtmlWindow2)
  201. {
  202. pihtmlWindow2->open(bstrURL, NULL, bstrFeatures, NULL, &pihtmlWindow2New);
  203. pihtmlWindow2->Release();
  204. ATOMICRELEASE(pihtmlWindow2New);
  205. }
  206. }
  207. if (bstrFeatures)
  208. SysFreeString(bstrFeatures);
  209. }
  210. else
  211. {
  212. // IE is not the default browser so we'll ShellExecute the Url for active desktop
  213. HINSTANCE hinstRet = ShellExecuteW(NULL, NULL, bstrURL, NULL, NULL, SW_SHOWNORMAL);
  214. hr = ((UINT_PTR)hinstRet) <= 32 ? E_FAIL : S_OK;
  215. }
  216. SysFreeString(bstrURL);
  217. }
  218. }
  219. return hr;
  220. }
  221. HRESULT ShowSubscriptionProperties(LPCTSTR pszUrl, HWND hwnd)
  222. {
  223. HRESULT hr;
  224. ISubscriptionMgr *psm;
  225. if (SUCCEEDED(hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  226. CLSCTX_INPROC_SERVER, IID_ISubscriptionMgr,
  227. (void**)&psm)))
  228. {
  229. WCHAR wszUrl[MAX_URL_STRING];
  230. SHTCharToUnicode(pszUrl, wszUrl, ARRAYSIZE(wszUrl));
  231. hr = psm->ShowSubscriptionProperties(wszUrl, hwnd);
  232. psm->Release();
  233. }
  234. return hr;
  235. }
  236. HRESULT CreateSubscriptionsWizard(SUBSCRIPTIONTYPE subType, LPCTSTR pszUrl, SUBSCRIPTIONINFO *pInfo, HWND hwnd)
  237. {
  238. HRESULT hr;
  239. ISubscriptionMgr *psm;
  240. if (SUCCEEDED(hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  241. CLSCTX_INPROC_SERVER, IID_ISubscriptionMgr,
  242. (void**)&psm)))
  243. {
  244. WCHAR wzURL[MAX_URL_STRING];
  245. LPCWSTR pwzURL = wzURL;
  246. #ifndef UNICODE
  247. SHAnsiToUnicode(pszUrl, wzURL, ARRAYSIZE(wzURL));
  248. #else // UNICODE
  249. pwzURL = pszUrl;
  250. #endif // UNICODE
  251. hr = psm->CreateSubscription(hwnd, pwzURL, pwzURL, CREATESUBS_ADDTOFAVORITES, subType, pInfo);
  252. psm->UpdateSubscription(pwzURL);
  253. psm->Release();
  254. }
  255. return hr;
  256. }