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.

308 lines
8.8 KiB

  1. #include "shellprv.h"
  2. #include <regstr.h>
  3. #include <shellp.h>
  4. #include "ole2dup.h"
  5. #include "ids.h"
  6. #include "defview.h"
  7. #include <perhist.h>
  8. #include "defvphst.h"
  9. // Docfind Persistent history implemention.
  10. STDMETHODIMP CDefViewPersistHistory::QueryInterface(REFIID riid, void **ppvObj)
  11. {
  12. static const QITAB qit[] = {
  13. QITABENT(CDefViewPersistHistory, IPersistHistory), //IID_IPersistHistory
  14. QITABENTMULTI(CDefViewPersistHistory, IPersist, IPersistHistory), //IID_IPersist
  15. QITABENT(CDefViewPersistHistory, IObjectWithSite), //IID_IOBjectWithSite
  16. QITABENT(CDefViewPersistHistory, IOleObject), // IID_IOleObject
  17. { 0 },
  18. };
  19. return QISearch(this, qit, riid, ppvObj);
  20. }
  21. STDMETHODIMP_(ULONG) CDefViewPersistHistory::AddRef()
  22. {
  23. return InterlockedIncrement(&m_cRef);
  24. }
  25. STDMETHODIMP_(ULONG) CDefViewPersistHistory::Release()
  26. {
  27. if (InterlockedDecrement(&m_cRef))
  28. return m_cRef;
  29. delete this;
  30. return 0;
  31. }
  32. CDefViewPersistHistory::CDefViewPersistHistory() :
  33. m_cRef(1)
  34. {
  35. }
  36. CDefViewPersistHistory::~CDefViewPersistHistory()
  37. {
  38. }
  39. STDAPI CDefViewPersistHistory_CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  40. {
  41. HRESULT hr;
  42. CDefViewPersistHistory *pdfph = new CDefViewPersistHistory();
  43. if (!pdfph)
  44. {
  45. *ppv = NULL;
  46. return E_OUTOFMEMORY;
  47. }
  48. hr = pdfph->QueryInterface(riid, ppv);
  49. pdfph->Release();
  50. return hr;
  51. }
  52. // Functions to support persisting the document into the history stream...
  53. STDMETHODIMP CDefViewPersistHistory::GetClassID(CLSID *pClassID)
  54. {
  55. *pClassID = CLSID_DefViewPersistHistory;
  56. return S_OK;
  57. }
  58. STDMETHODIMP CDefViewPersistHistory::LoadHistory(IStream *pstm, IBindCtx *pbc)
  59. {
  60. IShellView *psv;
  61. if (_punkSite && SUCCEEDED(_punkSite->QueryInterface(IID_PPV_ARG(IShellView, &psv))))
  62. {
  63. UINT cItems = 0;
  64. LPITEMIDLIST pidl = NULL; // don't free previous one
  65. UINT uFlags = SVSI_FOCUSED | SVSI_SELECT | SVSI_DESELECTOTHERS | SVSI_ENSUREVISIBLE;
  66. // read how many pidls we stored
  67. pstm->Read(&cItems, sizeof(cItems), NULL);
  68. // now read the pidls
  69. for (UINT i=0; i < cItems ; i++)
  70. {
  71. if (FAILED(ILLoadFromStream(pstm, &pidl)) || (pidl == NULL))
  72. break;
  73. if (SUCCEEDED(psv->SelectItem(pidl, uFlags)))
  74. uFlags = SVSI_SELECT;
  75. }
  76. if (pidl)
  77. ILFree(pidl); // Free the last one read in
  78. //
  79. // If we are in webview mode, we need to load the Trident persist history too
  80. //
  81. IPersistHistory * piph;
  82. if (SUCCEEDED(IUnknown_QueryService(_punkSite, SID_WebViewObject, IID_PPV_ARG(IPersistHistory, &piph))))
  83. {
  84. piph->LoadHistory(pstm, pbc);
  85. piph->Release();
  86. }
  87. psv->Release();
  88. }
  89. return S_OK;
  90. }
  91. STDMETHODIMP CDefViewPersistHistory::SaveHistory(IStream *pstm)
  92. {
  93. IShellFolderView *psfv;
  94. if (_punkSite && SUCCEEDED(_punkSite->QueryInterface(IID_PPV_ARG(IShellFolderView, &psfv))))
  95. {
  96. LPCITEMIDLIST *apidl;
  97. UINT cItems;
  98. // FEATURE: Currently this assumes the first item is focused. There are cases
  99. // where we may have unslected the focused item and we are not saving this out here.
  100. //
  101. // Need to add GetFocusedObject() to IShellFolderView interface to query this
  102. //
  103. //
  104. if (SUCCEEDED(psfv->GetSelectedObjects(&apidl, &cItems)) && cItems)
  105. {
  106. // write out how many pidls we have
  107. pstm->Write(&cItems, sizeof(cItems), NULL);
  108. // now write the pidls
  109. for (UINT i = 0; i < cItems; i++)
  110. {
  111. if (apidl[i])
  112. ILSaveToStream(pstm, apidl[i]);
  113. }
  114. LocalFree((HLOCAL)apidl);
  115. }
  116. else
  117. {
  118. cItems = 0;
  119. pstm->Write(&cItems, sizeof(cItems), NULL);
  120. }
  121. //
  122. // If we are in webview mode, we need to save the Trident persist history too
  123. //
  124. IPersistHistory * piph;
  125. if (SUCCEEDED(IUnknown_QueryService(_punkSite, SID_WebViewObject, IID_PPV_ARG(IPersistHistory, &piph))))
  126. {
  127. piph->SaveHistory(pstm);
  128. piph->Release();
  129. }
  130. psfv->Release();
  131. }
  132. return S_OK;
  133. }
  134. STDMETHODIMP CDefViewPersistHistory::SetPositionCookie(DWORD dwPositioncookie)
  135. {
  136. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::SetPositionCookie - not implemented"));
  137. return E_NOTIMPL;
  138. }
  139. STDMETHODIMP CDefViewPersistHistory::GetPositionCookie(DWORD *pdwPositioncookie)
  140. {
  141. *pdwPositioncookie = 0;
  142. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::GetPositionCookie - not implemented"));
  143. return E_NOTIMPL;
  144. }
  145. STDMETHODIMP CDefViewPersistHistory::SetClientSite(IOleClientSite *pClientSite)
  146. {
  147. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::SetClientSite - not implemented"));
  148. return E_NOTIMPL;
  149. }
  150. STDMETHODIMP CDefViewPersistHistory::GetClientSite(IOleClientSite **ppClientSite)
  151. {
  152. *ppClientSite = NULL;
  153. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::GetClientSite - not implemented"));
  154. return E_NOTIMPL;
  155. }
  156. STDMETHODIMP CDefViewPersistHistory::SetHostNames(LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
  157. {
  158. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::SetHostNames - not implemented"));
  159. return E_NOTIMPL;
  160. }
  161. STDMETHODIMP CDefViewPersistHistory::Close(DWORD dwSaveOption)
  162. {
  163. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::Close - not implemented"));
  164. return E_NOTIMPL;
  165. }
  166. STDMETHODIMP CDefViewPersistHistory::SetMoniker(DWORD dwWhichMoniker, IMoniker *pmk)
  167. {
  168. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::SetMoniker - not implemented"));
  169. return E_NOTIMPL;
  170. }
  171. STDMETHODIMP CDefViewPersistHistory::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
  172. {
  173. *ppmk = NULL;
  174. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::GetMoniker - not implemented"));
  175. return E_NOTIMPL;
  176. }
  177. STDMETHODIMP CDefViewPersistHistory::InitFromData(IDataObject *pDataObject,BOOL fCreation,DWORD dwReserved)
  178. {
  179. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::InitFromData - not implemented"));
  180. return E_NOTIMPL;
  181. }
  182. STDMETHODIMP CDefViewPersistHistory::GetClipboardData(DWORD dwReserved,IDataObject **ppDataObject)
  183. {
  184. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::GetClipboardData - not implemented"));
  185. return E_NOTIMPL;
  186. }
  187. STDMETHODIMP CDefViewPersistHistory::DoVerb(LONG iVerb,LPMSG lpmsg,IOleClientSite *pActiveSite,LONG lindex,HWND hwndParent,LPCRECT lprcPosRect)
  188. {
  189. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::DoVerb - not implemented"));
  190. return E_NOTIMPL;
  191. }
  192. STDMETHODIMP CDefViewPersistHistory::EnumVerbs(IEnumOLEVERB **ppEnumOleVerb)
  193. {
  194. *ppEnumOleVerb = NULL;
  195. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::EnumVerbs - not implemented"));
  196. return E_NOTIMPL;
  197. }
  198. STDMETHODIMP CDefViewPersistHistory::Update(void)
  199. {
  200. // Always up to date.
  201. return S_OK;
  202. }
  203. STDMETHODIMP CDefViewPersistHistory::IsUpToDate(void)
  204. {
  205. return S_OK; // say we are alwayes up to date.
  206. }
  207. STDMETHODIMP CDefViewPersistHistory::GetUserClassID(CLSID *pClsid)
  208. {
  209. return GetClassID(pClsid);
  210. }
  211. STDMETHODIMP CDefViewPersistHistory::GetUserType(DWORD dwFormOfType, LPOLESTR *pszUserType)
  212. {
  213. *pszUserType = NULL;
  214. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::GetUserType - not implemented"));
  215. return E_NOTIMPL;
  216. }
  217. STDMETHODIMP CDefViewPersistHistory::SetExtent(DWORD dwDrawAspect, SIZEL *psizel)
  218. {
  219. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::SetExtent - not implemented"));
  220. return E_NOTIMPL;
  221. }
  222. STDMETHODIMP CDefViewPersistHistory::GetExtent(DWORD dwDrawAspect, SIZEL *psizel)
  223. {
  224. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::GetExtent - not implemented"));
  225. return E_NOTIMPL;
  226. }
  227. STDMETHODIMP CDefViewPersistHistory::Advise(IAdviseSink *pAdvSink, DWORD *pdwConnection)
  228. {
  229. *pdwConnection = 0;
  230. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::Advise - not implemented"));
  231. return E_NOTIMPL;
  232. }
  233. STDMETHODIMP CDefViewPersistHistory::Unadvise(DWORD dwConnection)
  234. {
  235. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::Unadvise - not implemented"));
  236. return E_NOTIMPL;
  237. }
  238. STDMETHODIMP CDefViewPersistHistory::EnumAdvise(IEnumSTATDATA **ppenumAdvise)
  239. {
  240. *ppenumAdvise = NULL;
  241. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::EnumAdvises - not implemented"));
  242. return E_NOTIMPL;
  243. }
  244. STDMETHODIMP CDefViewPersistHistory::GetMiscStatus(DWORD dwAspect, DWORD *pdwStatus)
  245. {
  246. *pdwStatus = 0;
  247. if (dwAspect == DVASPECT_CONTENT)
  248. *pdwStatus = OLEMISC_SETCLIENTSITEFIRST;
  249. return S_OK;
  250. }
  251. STDMETHODIMP CDefViewPersistHistory::SetColorScheme(LOGPALETTE *pLogpal)
  252. {
  253. DebugMsg(DM_ERROR, TEXT("CDefViewPersistHistory::SetColorScheme - not implemented"));
  254. return E_NOTIMPL;
  255. }