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.

262 lines
6.4 KiB

  1. #include "shellprv.h"
  2. #include <sfview.h>
  3. #include "defviewp.h"
  4. int CGenList::Add(LPVOID pv, int nInsert)
  5. {
  6. if (!_hList)
  7. {
  8. _hList = DSA_Create(_cbItem, 8);
  9. if (!_hList)
  10. {
  11. return -1;
  12. }
  13. }
  14. return DSA_InsertItem(_hList, nInsert, pv);
  15. }
  16. int CViewsList::Add(const SFVVIEWSDATA*pView, int nInsert, BOOL bCopy)
  17. {
  18. if (bCopy)
  19. {
  20. pView = CopyData(pView);
  21. if (!pView)
  22. {
  23. return -1;
  24. }
  25. }
  26. int iIndex = CGenList::Add((LPVOID)(&pView), nInsert);
  27. if (bCopy && iIndex<0)
  28. {
  29. SHFree((LPVOID)pView);
  30. }
  31. return iIndex;
  32. }
  33. void CViewsList::Empty()
  34. {
  35. _bGotDef = FALSE;
  36. for (int i=GetItemCount()-1; i>=0; --i)
  37. {
  38. SFVVIEWSDATA *sfvData = GetPtr(i);
  39. ASSERT(sfvData);
  40. if (sfvData->dwFlags & SFVF_CUSTOMIZEDVIEW)
  41. {
  42. CUSTOMVIEWSDATA *pCustomPtr = sfvData->pCustomData;
  43. if (pCustomPtr)
  44. {
  45. if (pCustomPtr->lpDataBlock)
  46. SHFree(pCustomPtr->lpDataBlock);
  47. SHFree(pCustomPtr);
  48. }
  49. }
  50. SHFree(sfvData);
  51. }
  52. CGenList::Empty();
  53. }
  54. SFVVIEWSDATA* CViewsList::CopyData(const SFVVIEWSDATA* pData)
  55. {
  56. SFVVIEWSDATA* pCopy = (SFVVIEWSDATA*)SHAlloc(sizeof(SFVVIEWSDATA));
  57. if (pCopy)
  58. {
  59. memcpy(pCopy, pData, sizeof(SFVVIEWSDATA));
  60. if ((pData->dwFlags & SFVF_CUSTOMIZEDVIEW) && pData->pCustomData)
  61. {
  62. CUSTOMVIEWSDATA *pCustomData = (CUSTOMVIEWSDATA *)SHAlloc(sizeof(CUSTOMVIEWSDATA));
  63. if (pCustomData)
  64. {
  65. memcpy(pCustomData, pData->pCustomData, sizeof(CUSTOMVIEWSDATA));
  66. pCopy->pCustomData = pCustomData;
  67. if (pCustomData->lpDataBlock)
  68. {
  69. // NOTE: DataBlock size is in WCHARs
  70. LPWSTR lpDataBlock = (LPWSTR)SHAlloc(pCustomData->cchSizeOfBlock * sizeof(WCHAR));
  71. if (lpDataBlock)
  72. {
  73. // NOTE: DataBlock size is in WCHARs
  74. memcpy(lpDataBlock, pCustomData->lpDataBlock, pCustomData->cchSizeOfBlock * sizeof(WCHAR));
  75. pCustomData->lpDataBlock = lpDataBlock;
  76. }
  77. else
  78. {
  79. SHFree(pCustomData);
  80. goto Failed;
  81. }
  82. }
  83. }
  84. else
  85. {
  86. Failed:
  87. SHFree(pCopy);
  88. pCopy = NULL;
  89. }
  90. }
  91. }
  92. return pCopy;
  93. }
  94. int CViewsList::NextUnique(int nLast)
  95. {
  96. for (int nNext = nLast + 1; ; ++nNext)
  97. {
  98. SFVVIEWSDATA* pItem = GetPtr(nNext);
  99. if (!pItem)
  100. {
  101. break;
  102. }
  103. for (int nPrev=nNext-1; nPrev>=0; --nPrev)
  104. {
  105. SFVVIEWSDATA*pPrev = GetPtr(nPrev);
  106. if (pItem->idView == pPrev->idView)
  107. {
  108. break;
  109. }
  110. }
  111. if (nPrev < 0)
  112. {
  113. return nNext;
  114. }
  115. }
  116. return -1;
  117. }
  118. void CCallback::_GetExtViews(BOOL bForce)
  119. {
  120. CDefView* pView = IToClass(CDefView, _cCallback, this);
  121. IEnumSFVViews *pev = NULL;
  122. if (bForce)
  123. {
  124. _bGotViews = FALSE;
  125. }
  126. if (_bGotViews)
  127. {
  128. return;
  129. }
  130. _lViews.Empty();
  131. SHELLVIEWID vid = VID_LargeIcons;
  132. if (FAILED(pView->CallCB(SFVM_GETVIEWS, (WPARAM)&vid, (LPARAM)&pev)) ||
  133. !pev)
  134. {
  135. return;
  136. }
  137. _lViews.SetDef(&vid);
  138. SFVVIEWSDATA *pData;
  139. ULONG uFetched;
  140. while ((pev->Next(1, &pData, &uFetched) == S_OK) && (uFetched == 1))
  141. {
  142. // The list comes to us in general to specific order, but we want
  143. // to search it in specific->general order. Inverting the list
  144. // is easiest here, even though it causes a bunch of memcpy calls.
  145. //
  146. _lViews.Prepend(pData, FALSE);
  147. }
  148. ATOMICRELEASE(pev);
  149. _bGotViews = TRUE;
  150. }
  151. HRESULT CCallback::TryLegacyGetViews(SFVM_WEBVIEW_TEMPLATE_DATA* pvit)
  152. {
  153. CDefView* pView = IToClass(CDefView, _cCallback, this);
  154. HRESULT hr = E_FAIL;
  155. CLSID clsid;
  156. HRESULT hr2 = IUnknown_GetClassID(pView->_pshf, &clsid);
  157. if (FAILED(hr2) || !(SHGetObjectCompatFlags(NULL, &clsid) & OBJCOMPATF_NOLEGACYWEBVIEW))
  158. {
  159. _GetExtViews(FALSE);
  160. if (_bGotViews)
  161. {
  162. SFVVIEWSDATA* pItem;
  163. GetViewIdFromGUID(&VID_WebView, &pItem);
  164. if (pItem)
  165. {
  166. hr = StringCchCopyW(pvit->szWebView, ARRAYSIZE(pvit->szWebView), pItem->wszMoniker);
  167. }
  168. }
  169. else if (SUCCEEDED(hr2))
  170. {
  171. // check for PersistMoniker under isf's coclass (Web Folders used this in W2K to get .htt Web View)
  172. WCHAR szCLSID[GUIDSTR_MAX];
  173. if (SHStringFromGUID(clsid, szCLSID, ARRAYSIZE(szCLSID)))
  174. {
  175. WCHAR wszSubKey[MAX_PATH];
  176. hr = StringCchPrintf(wszSubKey, ARRAYSIZE(wszSubKey), L"CLSID\\%s\\shellex\\ExtShellFolderViews\\{5984FFE0-28D4-11CF-AE66-08002B2E1262}", szCLSID);
  177. if (SUCCEEDED(hr))
  178. {
  179. DWORD cbSize = sizeof(pvit->szWebView);
  180. hr = ResultFromWin32(SHRegGetValueW(HKEY_CLASSES_ROOT, wszSubKey, L"PersistMoniker", SRRF_RT_REG_SZ, NULL, pvit->szWebView, &cbSize));
  181. }
  182. }
  183. }
  184. }
  185. return hr;
  186. }
  187. HRESULT CCallback::OnRefreshLegacy(void* pv, BOOL fPrePost)
  188. {
  189. // If we're using the SFVM_GETVIEWS layer, invalidate it
  190. if (_bGotViews)
  191. {
  192. _lViews.Empty();
  193. _bGotViews = FALSE;
  194. }
  195. return S_OK;
  196. }
  197. int CCallback::GetViewIdFromGUID(SHELLVIEWID const *pvid, SFVVIEWSDATA** ppItem)
  198. {
  199. int iView = -1;
  200. for (UINT uView=0; uView<MAX_EXT_VIEWS; ++uView)
  201. {
  202. iView = _lViews.NextUnique(iView);
  203. SFVVIEWSDATA* pItem = _lViews.GetPtr(iView);
  204. if (!pItem)
  205. {
  206. break;
  207. }
  208. if (*pvid == pItem->idView)
  209. {
  210. if (ppItem)
  211. *ppItem = pItem;
  212. return (int)uView;
  213. }
  214. }
  215. if (ppItem)
  216. *ppItem = NULL;
  217. return -1;
  218. }