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.

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