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.

378 lines
12 KiB

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. class CShellFolderViewOC;
  4. class CDViewEvents : public DShellFolderViewEvents
  5. {
  6. public:
  7. // IUnknown
  8. STDMETHOD(QueryInterface)(REFIID riid, void **ppv);
  9. STDMETHOD_(ULONG, AddRef)();
  10. STDMETHOD_(ULONG, Release)();
  11. // IDispatch
  12. STDMETHOD(GetTypeInfoCount)(UINT *pctinfo);
  13. STDMETHOD(GetTypeInfo)(UINT itinfo,LCID lcid,ITypeInfo **pptinfo);
  14. STDMETHOD(GetIDsOfNames)(REFIID riid,OLECHAR **rgszNames,UINT cNames, LCID lcid, DISPID *rgdispid);
  15. STDMETHOD(Invoke)(DISPID dispidMember,REFIID riid,LCID lcid,WORD wFlags,
  16. DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo,UINT *puArgErr);
  17. CDViewEvents(CShellFolderViewOC * psfvOC) { _psfvOC = psfvOC; };
  18. ~CDViewEvents() {};
  19. protected:
  20. CShellFolderViewOC * _psfvOC;
  21. };
  22. class ATL_NO_VTABLE CShellFolderViewOC
  23. : public CComObjectRootEx<CComSingleThreadModel>
  24. , public CComCoClass<CShellFolderViewOC, &CLSID_ShellFolderViewOC>
  25. , public IDispatchImpl<IFolderViewOC, &IID_IFolderViewOC, &LIBID_Shell32>
  26. , public IProvideClassInfo2Impl<&CLSID_ShellFolderView, NULL, &LIBID_Shell32>
  27. , public IObjectSafetyImpl<CShellFolderViewOC, INTERFACESAFE_FOR_UNTRUSTED_CALLER>
  28. , public IConnectionPointContainerImpl<CShellFolderViewOC>
  29. , public IConnectionPointImpl<CShellFolderViewOC, &DIID_DShellFolderViewEvents>
  30. , public CComControl<CShellFolderViewOC>
  31. , public IPersistStreamInitImpl<CShellFolderViewOC>
  32. , public IOleControlImpl<CShellFolderViewOC>
  33. , public IOleObjectImpl<CShellFolderViewOC>
  34. , public IOleInPlaceActiveObjectImpl<CShellFolderViewOC>
  35. , public IOleInPlaceObjectWindowlessImpl<CShellFolderViewOC>
  36. , public ICommDlgBrowser
  37. // , public IViewObjectExImpl<CShellFolderViewOC>
  38. {
  39. public:
  40. // DECLARE_POLY_AGGREGATABLE(CShellFolderViewOC);
  41. DECLARE_NO_REGISTRY();
  42. BEGIN_COM_MAP(CShellFolderViewOC)
  43. COM_INTERFACE_ENTRY(IDispatch)
  44. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  45. COM_INTERFACE_ENTRY(IProvideClassInfo)
  46. COM_INTERFACE_ENTRY(IObjectSafety)
  47. COM_INTERFACE_ENTRY(IConnectionPointContainer)
  48. COM_INTERFACE_ENTRY(IFolderViewOC)
  49. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  50. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  51. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  52. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  53. COM_INTERFACE_ENTRY(IOleControl)
  54. COM_INTERFACE_ENTRY(IOleObject)
  55. COM_INTERFACE_ENTRY(IPersistStreamInit)
  56. COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
  57. // COM_INTERFACE_ENTRY(ICommDlgBrowser)
  58. END_COM_MAP()
  59. BEGIN_CONNECTION_POINT_MAP(CShellFolderViewOC)
  60. CONNECTION_POINT_ENTRY(DIID_DShellFolderViewEvents)
  61. END_CONNECTION_POINT_MAP()
  62. BEGIN_MSG_MAP(CShellFolderViewOC)
  63. MESSAGE_HANDLER(WM_DESTROY, _ReleaseForwarderMessage)
  64. END_MSG_MAP()
  65. BEGIN_PROPERTY_MAP(CShellFolderViewOC)
  66. END_PROPERTY_MAP()
  67. // IOleWindow
  68. STDMETHODIMP GetWindow(HWND * phwnd) {return IOleInPlaceActiveObjectImpl<CShellFolderViewOC>::GetWindow(phwnd);};
  69. STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode) { return IOleInPlaceActiveObjectImpl<CShellFolderViewOC>::ContextSensitiveHelp(fEnterMode); };
  70. // IOleInPlaceObject
  71. STDMETHODIMP InPlaceDeactivate(void) {return IOleInPlaceObject_InPlaceDeactivate();};
  72. STDMETHODIMP UIDeactivate(void) { return IOleInPlaceObject_UIDeactivate(); };
  73. STDMETHODIMP SetObjectRects(LPCRECT prcPosRect, LPCRECT prcClipRect) { return IOleInPlaceObject_SetObjectRects(prcPosRect, prcClipRect); };
  74. STDMETHODIMP ReactivateAndUndo(void) { return E_NOTIMPL; };
  75. // IObjectWithSite overrides
  76. STDMETHODIMP SetClientSite(IOleClientSite *pClientSite);
  77. // IFolderViewOC
  78. STDMETHODIMP SetFolderView(IDispatch *pDisp);
  79. // IShellBrowser (same as IOleInPlaceFrame)
  80. STDMETHOD(InsertMenusSB) (THIS_ HMENU hmenuShared, LPOLEMENUGROUPWIDTHS pMenuWidths);
  81. STDMETHOD(SetMenuSB) (THIS_ HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject);
  82. STDMETHOD(RemoveMenusSB) (THIS_ HMENU hmenuShared);
  83. STDMETHOD(SetStatusTextSB) (THIS_ LPCOLESTR pszStatusText);
  84. STDMETHOD(EnableModelessSB) (THIS_ BOOL fEnable);
  85. STDMETHOD(TranslateAcceleratorSB) (THIS_ LPMSG pmsg, WORD wID);
  86. // IShellBrowser
  87. STDMETHOD(BrowseObject)(THIS_ LPCITEMIDLIST pidl, UINT wFlags);
  88. STDMETHOD(GetViewStateStream)(THIS_ DWORD grfMode, IStream **pStrm);
  89. STDMETHOD(GetControlWindow)(THIS_ UINT id, HWND *phwnd);
  90. STDMETHOD(SendControlMsg)(THIS_ UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pret);
  91. STDMETHOD(QueryActiveShellView)(THIS_ IShellView **ppshv);
  92. STDMETHOD(OnViewWindowActive)(THIS_ IShellView *pshv);
  93. STDMETHOD(SetToolbarItems)(THIS_ LPTBBUTTON pButtons, UINT nButtons, UINT uFlags);
  94. // ICommDlgBrowser
  95. STDMETHOD(OnDefaultCommand) (THIS_ IShellView *psv);
  96. STDMETHOD(OnStateChange) (THIS_ IShellView *psv, ULONG uChange);
  97. STDMETHOD(IncludeObject) (THIS_ IShellView *psv, LPCITEMIDLIST pItem);
  98. // ICommDlgBrowser2
  99. // STDMETHOD(Notify) (THIS_ IShellView *psv, DWORD dwNotifyType);
  100. // STDMETHOD(GetDefaultMenuText) (THIS_ IShellView *psv, WCHAR *pszText, INT cchMax);
  101. // STDMETHOD(GetViewFlags)(THIS_ DWORD *pdwFlags);
  102. friend class CDViewEvents;
  103. protected:
  104. CShellFolderViewOC();
  105. ~CShellFolderViewOC();
  106. private:
  107. HRESULT _SetupForwarder(void);
  108. void _ReleaseForwarder(void);
  109. LRESULT _ReleaseForwarderMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
  110. IDispatch *_pFolderView; // Hold onto ShellFolderView IDispatch
  111. DWORD _dwViewEventsCookie; // Have we installed _dViewEvents in browser?
  112. CDViewEvents _dViewEvents;
  113. };
  114. CShellFolderViewOC::CShellFolderViewOC() :
  115. _dwViewEventsCookie(0), _pFolderView(NULL), _dViewEvents(this)
  116. {
  117. }
  118. CShellFolderViewOC::~CShellFolderViewOC()
  119. {
  120. ATOMICRELEASE(_pFolderView);
  121. }
  122. // IShellBrowser (same as IOleInPlaceFrame)
  123. STDMETHODIMP CShellFolderViewOC::InsertMenusSB(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS pMenuWidths)
  124. {
  125. return E_NOTIMPL;
  126. }
  127. STDMETHODIMP CShellFolderViewOC::SetMenuSB(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
  128. {
  129. return E_NOTIMPL;
  130. }
  131. STDMETHODIMP CShellFolderViewOC::RemoveMenusSB(HMENU hmenuShared)
  132. {
  133. return E_NOTIMPL;
  134. }
  135. STDMETHODIMP CShellFolderViewOC::SetStatusTextSB(LPCOLESTR pwch)
  136. {
  137. return S_OK;
  138. }
  139. STDMETHODIMP CShellFolderViewOC::EnableModelessSB(BOOL fEnable)
  140. {
  141. return S_OK;
  142. }
  143. STDMETHODIMP CShellFolderViewOC::TranslateAcceleratorSB(LPMSG pmsg, WORD wID)
  144. {
  145. return S_FALSE;
  146. }
  147. // IShellBrowser
  148. STDMETHODIMP CShellFolderViewOC::BrowseObject(LPCITEMIDLIST pidl, UINT wFlags)
  149. {
  150. return S_OK;
  151. }
  152. STDMETHODIMP CShellFolderViewOC::GetViewStateStream(DWORD grfMode, IStream **pStrm)
  153. {
  154. *pStrm = NULL;
  155. return E_FAIL;
  156. }
  157. STDMETHODIMP CShellFolderViewOC::GetControlWindow(UINT id, HWND *phwnd)
  158. {
  159. return E_NOTIMPL;
  160. }
  161. STDMETHODIMP CShellFolderViewOC::SendControlMsg(UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pret)
  162. {
  163. return E_NOTIMPL;
  164. }
  165. STDMETHODIMP CShellFolderViewOC::QueryActiveShellView(IShellView **ppsv)
  166. {
  167. *ppsv = NULL;
  168. return E_NOINTERFACE;
  169. }
  170. STDMETHODIMP CShellFolderViewOC::OnViewWindowActive(IShellView *psv)
  171. {
  172. return S_OK;
  173. }
  174. STDMETHODIMP CShellFolderViewOC::SetToolbarItems(LPTBBUTTON pButtons, UINT nButtons, UINT uFlags)
  175. {
  176. return S_OK;
  177. }
  178. STDMETHODIMP CShellFolderViewOC::OnDefaultCommand(IShellView *psv)
  179. {
  180. HRESULT hr = S_FALSE; // we did not handle it
  181. #if 0
  182. IShellFolderView *psfv;
  183. if (SUCCEEDED(psv->QueryInterface(IID_PPV_ARG(IShellFolderView, &psfv))))
  184. {
  185. LPITEMIDLIST pidl;
  186. if (SUCCEEDED(psfv->GetObject(&pidl, (UINT)-2)))
  187. {
  188. IShellBrowser *psb;
  189. if (SUCCEEDED(IUnknown_QueryService(psv, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &psb))))
  190. {
  191. psb->BrowseObject(pidl, SBSP_RELATIVE | SBSP_OPENMODE);
  192. psb->Release();
  193. }
  194. // note, we don't free pidl as we got an alias
  195. }
  196. psfv->Release();
  197. }
  198. #endif
  199. return hr;
  200. }
  201. STDMETHODIMP CShellFolderViewOC::OnStateChange(IShellView *psv, ULONG uChange)
  202. {
  203. switch (uChange)
  204. {
  205. case CDBOSC_SETFOCUS:
  206. break;
  207. case CDBOSC_KILLFOCUS:
  208. break;
  209. case CDBOSC_SELCHANGE:
  210. break;
  211. case CDBOSC_RENAME:
  212. break;
  213. default:
  214. return E_NOTIMPL;
  215. }
  216. return S_OK;
  217. }
  218. STDMETHODIMP CShellFolderViewOC::IncludeObject(IShellView *psv, LPCITEMIDLIST pidl)
  219. {
  220. return S_OK;
  221. }
  222. // IFolderViewOC
  223. HRESULT CShellFolderViewOC::SetFolderView(IDispatch *pDisp)
  224. {
  225. HRESULT hr = S_OK;
  226. _ReleaseForwarder(); // cleanup previous state
  227. IUnknown_Set((IUnknown **)&_pFolderView, pDisp);
  228. if (_pFolderView)
  229. hr = _SetupForwarder();
  230. return hr;
  231. }
  232. #define SID_CommonDialogBrowser IID_ICommDlgBrowser
  233. STDMETHODIMP CShellFolderViewOC::SetClientSite(IOleClientSite *pClientSite)
  234. {
  235. #if 0
  236. // setup or tear down our service object
  237. if (pClientSite)
  238. IUnknown_ProfferService(pClientSite, SID_CommonDialogBrowser, SAFECAST(this, ICommDlgBrowser *), &_dwServiceCookie);
  239. else if (m_spClientSite)
  240. {
  241. SetFolderView(NULL); // break circular refs
  242. IUnknown_ProfferService(m_spClientSite, SID_CommonDialogBrowser, NULL, &_dwServiceCookie);
  243. }
  244. #endif
  245. return IOleObjectImpl<CShellFolderViewOC>::SetClientSite(pClientSite);
  246. }
  247. HRESULT CShellFolderViewOC::_SetupForwarder()
  248. {
  249. return ConnectToConnectionPoint(SAFECAST(&_dViewEvents, IDispatch *), DIID_DShellFolderViewEvents, TRUE, _pFolderView, &_dwViewEventsCookie, NULL);
  250. }
  251. void CShellFolderViewOC::_ReleaseForwarder()
  252. {
  253. ConnectToConnectionPoint(NULL, DIID_DShellFolderViewEvents, FALSE, _pFolderView, &_dwViewEventsCookie, NULL);
  254. }
  255. // ATL maintainence functions
  256. LRESULT CShellFolderViewOC::_ReleaseForwarderMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled)
  257. {
  258. bHandled = FALSE;
  259. _ReleaseForwarder();
  260. return 0;
  261. }
  262. STDMETHODIMP CDViewEvents::QueryInterface(REFIID riid, void **ppv)
  263. {
  264. static const QITAB qit[] = {
  265. QITABENTMULTI2(CDViewEvents, DIID_DShellFolderViewEvents, DShellFolderViewEvents),
  266. QITABENTMULTI(CDViewEvents, IDispatch, DShellFolderViewEvents),
  267. { 0 },
  268. };
  269. return QISearch(this, qit, riid, ppv);
  270. }
  271. ULONG CDViewEvents::AddRef()
  272. {
  273. return SAFECAST(_psfvOC, IFolderViewOC*)->AddRef();
  274. }
  275. ULONG CDViewEvents::Release()
  276. {
  277. return SAFECAST(_psfvOC, IFolderViewOC*)->Release();
  278. }
  279. STDMETHODIMP CDViewEvents::GetTypeInfoCount(UINT * pctinfo)
  280. {
  281. return E_NOTIMPL;
  282. }
  283. STDMETHODIMP CDViewEvents::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  284. {
  285. return E_NOTIMPL;
  286. }
  287. STDMETHODIMP CDViewEvents::GetIDsOfNames(REFIID riid, OLECHAR **rgszNames,
  288. UINT cNames, LCID lcid, DISPID *rgdispid)
  289. {
  290. return E_NOTIMPL;
  291. }
  292. STDMETHODIMP CDViewEvents::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
  293. DISPPARAMS *pdispparams, VARIANT *pvarResult,
  294. EXCEPINFO *pexcepinfo, UINT *puArgErr)
  295. {
  296. SHINVOKEPARAMS inv;
  297. inv.flags = 0;
  298. inv.dispidMember = dispidMember;
  299. inv.piid = &riid;
  300. inv.lcid = lcid;
  301. inv.wFlags = wFlags;
  302. inv.pdispparams = pdispparams;
  303. inv.pvarResult = pvarResult;
  304. inv.pexcepinfo = pexcepinfo;
  305. inv.puArgErr = puArgErr;
  306. return IUnknown_CPContainerInvokeIndirect(SAFECAST(_psfvOC, IFolderViewOC *), DIID_DShellFolderViewEvents, &inv);
  307. }
  308. STDAPI CShellFolderViewOC_CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppvOut)
  309. {
  310. return CComCreator< CComObject< CShellFolderViewOC > >::CreateInstance((void *)punkOuter, riid, ppvOut);
  311. }