Source code of Windows XP (NT5)
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.

266 lines
8.4 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. StrCpyNW(pszName, (LPCWSTR)var.bstrVal, cchSize);
  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, SIZECHARS(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, SIZECHARS(szHTMLElementID), (BSTR)(s_sstrIDMember.wsz))))
  79. {
  80. hr = UpdateComponentFlags(szHTMLElementID, COMP_CHECKED | COMP_UNCHECKED, COMP_UNCHECKED) ? S_OK : E_FAIL;
  81. ASSERT(SUCCEEDED(hr));
  82. if (SUCCEEDED(hr))
  83. {
  84. //
  85. // This IElemCloseDesktopComp() is called from DeskMovr code when a component is
  86. // closed. If this component is the only active desktop component, then calling
  87. // REFRESHACTIVEDESKTOP() here will result in ActiveDesktop being turned off.
  88. // This will free the DeskMovr, which is an ActiveX control on the desktop web page.
  89. // So, when IElemCloseDesktopComp() returns to the caller, the DeskMovr code continues
  90. // to execute; but the object had been freed and hence a fault occurs soon.
  91. // The fix for this problem is to avoid refreshing the active desktop until a better
  92. // time. So, we post a private message to the desktop window. When that window receives
  93. // this message, we call REFRESHACTIVEDESKTOP().
  94. PostMessage(GetShellWindow(), DTM_REFRESHACTIVEDESKTOP, (WPARAM)0, (LPARAM)0);
  95. }
  96. }
  97. return hr;
  98. }
  99. HRESULT IElemGetSubscriptionsDialog(IHTMLElement *pielem, HWND hwnd)
  100. {
  101. HRESULT hr;
  102. TCHAR szHTMLElementName[MAX_URL_STRING];
  103. ASSERT(pielem);
  104. if (SUCCEEDED(hr = GetHTMLElementStrMember(pielem, szHTMLElementName, SIZECHARS(szHTMLElementName), (BSTR)(s_sstrSubSRCMember.wsz))))
  105. {
  106. ASSERT(CheckForExistingSubscription(szHTMLElementName)); // We should not have gotten this far.
  107. hr = ShowSubscriptionProperties(szHTMLElementName, hwnd);
  108. }
  109. return hr;
  110. }
  111. HRESULT IElemSubscribeDialog(IHTMLElement *pielem, HWND hwnd)
  112. {
  113. HRESULT hr;
  114. TCHAR szHTMLElementName[MAX_URL_STRING];
  115. ASSERT(pielem);
  116. hr = GetHTMLElementStrMember(pielem, szHTMLElementName, SIZECHARS(szHTMLElementName), (BSTR)(s_sstrSubSRCMember.wsz));
  117. if (SUCCEEDED(hr))
  118. {
  119. ASSERT(!CheckForExistingSubscription(szHTMLElementName)); // We should not have gotten this far.
  120. hr = CreateSubscriptionsWizard(SUBSTYPE_DESKTOPURL, szHTMLElementName, NULL, hwnd);
  121. }
  122. return hr;
  123. }
  124. HRESULT IElemUnsubscribe(IHTMLElement *pielem)
  125. {
  126. HRESULT hr;
  127. TCHAR szHTMLElementName[MAX_URL_STRING];
  128. ASSERT(pielem);
  129. hr = GetHTMLElementStrMember(pielem, szHTMLElementName, SIZECHARS(szHTMLElementName), (BSTR)(s_sstrSubSRCMember.wsz));
  130. if (SUCCEEDED(hr))
  131. {
  132. ASSERT(CheckForExistingSubscription(szHTMLElementName)); // We should not have gotten this far.
  133. hr = DeleteFromSubscriptionList(szHTMLElementName) ? S_OK : S_FALSE;
  134. }
  135. return hr;
  136. }
  137. HRESULT IElemUpdate(IHTMLElement *pielem)
  138. {
  139. HRESULT hr;
  140. TCHAR szHTMLElementName[MAX_URL_STRING];
  141. ASSERT(pielem);
  142. hr = GetHTMLElementStrMember(pielem, szHTMLElementName, SIZECHARS(szHTMLElementName), (BSTR)(s_sstrSubSRCMember.wsz));
  143. if (SUCCEEDED(hr))
  144. {
  145. ASSERT(CheckForExistingSubscription(szHTMLElementName)); // We should not have gotten this far.
  146. hr = UpdateSubscription(szHTMLElementName) ? S_OK : S_FALSE;
  147. }
  148. return hr;
  149. }
  150. HRESULT IElemOpenInNewWindow(IHTMLElement *pielem, IOleClientSite *piOCSite, BOOL fShowFrame, LONG width, LONG height)
  151. {
  152. HRESULT hr;
  153. TCHAR szTemp[MAX_URL_STRING];
  154. BSTR bstrURL;
  155. ASSERT(pielem);
  156. hr = GetHTMLElementStrMember(pielem, szTemp, SIZECHARS(szTemp), (BSTR)(s_sstrSubSRCMember.wsz));
  157. if (SUCCEEDED(hr) && (bstrURL = SysAllocStringT(szTemp)))
  158. {
  159. IHTMLWindow2 *pihtmlWindow2, *pihtmlWindow2New = NULL;
  160. BSTR bstrFeatures = 0;
  161. if (!fShowFrame)
  162. {
  163. wnsprintf(szTemp, ARRAYSIZE(szTemp), TEXT("height=%li, width=%li, status=no, toolbar=no, menubar=no, location=no, resizable=no"), height, width);
  164. bstrFeatures = SysAllocString((OLECHAR FAR *)szTemp);
  165. }
  166. hr = IUnknown_QueryService(piOCSite, SID_SHTMLWindow, IID_IHTMLWindow2, (LPVOID*)&pihtmlWindow2);
  167. if (SUCCEEDED(hr) && pihtmlWindow2)
  168. {
  169. pihtmlWindow2->open(bstrURL, NULL, bstrFeatures, NULL, &pihtmlWindow2New);
  170. pihtmlWindow2->Release();
  171. ATOMICRELEASE(pihtmlWindow2New);
  172. }
  173. SysFreeString(bstrURL);
  174. if (bstrFeatures)
  175. SysFreeString(bstrFeatures);
  176. }
  177. return hr;
  178. }
  179. HRESULT ShowSubscriptionProperties(LPCTSTR pszUrl, HWND hwnd)
  180. {
  181. HRESULT hr;
  182. ISubscriptionMgr *psm;
  183. if (SUCCEEDED(hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  184. CLSCTX_INPROC_SERVER, IID_ISubscriptionMgr,
  185. (void**)&psm)))
  186. {
  187. WCHAR wszUrl[MAX_URL_STRING];
  188. SHTCharToUnicode(pszUrl, wszUrl, ARRAYSIZE(wszUrl));
  189. hr = psm->ShowSubscriptionProperties(wszUrl, hwnd);
  190. psm->Release();
  191. }
  192. return hr;
  193. }
  194. HRESULT CreateSubscriptionsWizard(SUBSCRIPTIONTYPE subType, LPCTSTR pszUrl, SUBSCRIPTIONINFO *pInfo, HWND hwnd)
  195. {
  196. HRESULT hr;
  197. ISubscriptionMgr *psm;
  198. if (SUCCEEDED(hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  199. CLSCTX_INPROC_SERVER, IID_ISubscriptionMgr,
  200. (void**)&psm)))
  201. {
  202. WCHAR wzURL[MAX_URL_STRING];
  203. LPCWSTR pwzURL = wzURL;
  204. #ifndef UNICODE
  205. SHAnsiToUnicode(pszUrl, wzURL, ARRAYSIZE(wzURL));
  206. #else // UNICODE
  207. pwzURL = pszUrl;
  208. #endif // UNICODE
  209. hr = psm->CreateSubscription(hwnd, pwzURL, pwzURL, CREATESUBS_ADDTOFAVORITES, subType, pInfo);
  210. psm->UpdateSubscription(pwzURL);
  211. psm->Release();
  212. }
  213. return hr;
  214. }