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.

340 lines
11 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. {
  38. public:
  39. DECLARE_NO_REGISTRY();
  40. BEGIN_COM_MAP(CShellFolderViewOC)
  41. COM_INTERFACE_ENTRY(IDispatch)
  42. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  43. COM_INTERFACE_ENTRY(IProvideClassInfo)
  44. COM_INTERFACE_ENTRY(IObjectSafety)
  45. COM_INTERFACE_ENTRY(IConnectionPointContainer)
  46. COM_INTERFACE_ENTRY(IFolderViewOC)
  47. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  48. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  49. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  50. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  51. COM_INTERFACE_ENTRY(IOleControl)
  52. COM_INTERFACE_ENTRY(IOleObject)
  53. COM_INTERFACE_ENTRY(IPersistStreamInit)
  54. COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
  55. END_COM_MAP()
  56. BEGIN_CONNECTION_POINT_MAP(CShellFolderViewOC)
  57. CONNECTION_POINT_ENTRY(DIID_DShellFolderViewEvents)
  58. END_CONNECTION_POINT_MAP()
  59. BEGIN_MSG_MAP(CShellFolderViewOC)
  60. MESSAGE_HANDLER(WM_DESTROY, _ReleaseForwarderMessage)
  61. END_MSG_MAP()
  62. BEGIN_PROPERTY_MAP(CShellFolderViewOC)
  63. END_PROPERTY_MAP()
  64. // IOleWindow
  65. STDMETHODIMP GetWindow(HWND * phwnd) {return IOleInPlaceActiveObjectImpl<CShellFolderViewOC>::GetWindow(phwnd);};
  66. STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode) { return IOleInPlaceActiveObjectImpl<CShellFolderViewOC>::ContextSensitiveHelp(fEnterMode); };
  67. // IOleInPlaceObject
  68. STDMETHODIMP InPlaceDeactivate(void) {return IOleInPlaceObject_InPlaceDeactivate();};
  69. STDMETHODIMP UIDeactivate(void) { return IOleInPlaceObject_UIDeactivate(); };
  70. STDMETHODIMP SetObjectRects(LPCRECT prcPosRect, LPCRECT prcClipRect) { return IOleInPlaceObject_SetObjectRects(prcPosRect, prcClipRect); };
  71. STDMETHODIMP ReactivateAndUndo(void) { return E_NOTIMPL; };
  72. // IObjectWithSite overrides
  73. STDMETHODIMP SetClientSite(IOleClientSite *pClientSite);
  74. // IFolderViewOC
  75. STDMETHODIMP SetFolderView(IDispatch *pDisp);
  76. // IShellBrowser (same as IOleInPlaceFrame)
  77. STDMETHOD(InsertMenusSB) (THIS_ HMENU hmenuShared, LPOLEMENUGROUPWIDTHS pMenuWidths);
  78. STDMETHOD(SetMenuSB) (THIS_ HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject);
  79. STDMETHOD(RemoveMenusSB) (THIS_ HMENU hmenuShared);
  80. STDMETHOD(SetStatusTextSB) (THIS_ LPCOLESTR pszStatusText);
  81. STDMETHOD(EnableModelessSB) (THIS_ BOOL fEnable);
  82. STDMETHOD(TranslateAcceleratorSB) (THIS_ LPMSG pmsg, WORD wID);
  83. // IShellBrowser
  84. STDMETHOD(BrowseObject)(THIS_ LPCITEMIDLIST pidl, UINT wFlags);
  85. STDMETHOD(GetViewStateStream)(THIS_ DWORD grfMode, IStream **pStrm);
  86. STDMETHOD(GetControlWindow)(THIS_ UINT id, HWND *phwnd);
  87. STDMETHOD(SendControlMsg)(THIS_ UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pret);
  88. STDMETHOD(QueryActiveShellView)(THIS_ IShellView **ppshv);
  89. STDMETHOD(OnViewWindowActive)(THIS_ IShellView *pshv);
  90. STDMETHOD(SetToolbarItems)(THIS_ LPTBBUTTON pButtons, UINT nButtons, UINT uFlags);
  91. // ICommDlgBrowser
  92. STDMETHOD(OnDefaultCommand) (THIS_ IShellView *psv);
  93. STDMETHOD(OnStateChange) (THIS_ IShellView *psv, ULONG uChange);
  94. STDMETHOD(IncludeObject) (THIS_ IShellView *psv, LPCITEMIDLIST pItem);
  95. friend class CDViewEvents;
  96. protected:
  97. CShellFolderViewOC();
  98. ~CShellFolderViewOC();
  99. private:
  100. HRESULT _SetupForwarder(void);
  101. void _ReleaseForwarder(void);
  102. LRESULT _ReleaseForwarderMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
  103. IDispatch *_pFolderView; // Hold onto ShellFolderView IDispatch
  104. DWORD _dwViewEventsCookie; // Have we installed _dViewEvents in browser?
  105. CDViewEvents _dViewEvents;
  106. };
  107. CShellFolderViewOC::CShellFolderViewOC() :
  108. _dwViewEventsCookie(0), _pFolderView(NULL), _dViewEvents(this)
  109. {
  110. }
  111. CShellFolderViewOC::~CShellFolderViewOC()
  112. {
  113. ATOMICRELEASE(_pFolderView);
  114. }
  115. // IShellBrowser (same as IOleInPlaceFrame)
  116. STDMETHODIMP CShellFolderViewOC::InsertMenusSB(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS pMenuWidths)
  117. {
  118. return E_NOTIMPL;
  119. }
  120. STDMETHODIMP CShellFolderViewOC::SetMenuSB(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
  121. {
  122. return E_NOTIMPL;
  123. }
  124. STDMETHODIMP CShellFolderViewOC::RemoveMenusSB(HMENU hmenuShared)
  125. {
  126. return E_NOTIMPL;
  127. }
  128. STDMETHODIMP CShellFolderViewOC::SetStatusTextSB(LPCOLESTR pwch)
  129. {
  130. return S_OK;
  131. }
  132. STDMETHODIMP CShellFolderViewOC::EnableModelessSB(BOOL fEnable)
  133. {
  134. return S_OK;
  135. }
  136. STDMETHODIMP CShellFolderViewOC::TranslateAcceleratorSB(LPMSG pmsg, WORD wID)
  137. {
  138. return S_FALSE;
  139. }
  140. // IShellBrowser
  141. STDMETHODIMP CShellFolderViewOC::BrowseObject(LPCITEMIDLIST pidl, UINT wFlags)
  142. {
  143. return S_OK;
  144. }
  145. STDMETHODIMP CShellFolderViewOC::GetViewStateStream(DWORD grfMode, IStream **pStrm)
  146. {
  147. *pStrm = NULL;
  148. return E_FAIL;
  149. }
  150. STDMETHODIMP CShellFolderViewOC::GetControlWindow(UINT id, HWND *phwnd)
  151. {
  152. return E_NOTIMPL;
  153. }
  154. STDMETHODIMP CShellFolderViewOC::SendControlMsg(UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pret)
  155. {
  156. return E_NOTIMPL;
  157. }
  158. STDMETHODIMP CShellFolderViewOC::QueryActiveShellView(IShellView **ppsv)
  159. {
  160. *ppsv = NULL;
  161. return E_NOINTERFACE;
  162. }
  163. STDMETHODIMP CShellFolderViewOC::OnViewWindowActive(IShellView *psv)
  164. {
  165. return S_OK;
  166. }
  167. STDMETHODIMP CShellFolderViewOC::SetToolbarItems(LPTBBUTTON pButtons, UINT nButtons, UINT uFlags)
  168. {
  169. return S_OK;
  170. }
  171. STDMETHODIMP CShellFolderViewOC::OnDefaultCommand(IShellView *psv)
  172. {
  173. return S_FALSE; // we did not handle it
  174. }
  175. STDMETHODIMP CShellFolderViewOC::OnStateChange(IShellView *psv, ULONG uChange)
  176. {
  177. switch (uChange)
  178. {
  179. case CDBOSC_SETFOCUS:
  180. break;
  181. case CDBOSC_KILLFOCUS:
  182. break;
  183. case CDBOSC_SELCHANGE:
  184. break;
  185. case CDBOSC_RENAME:
  186. break;
  187. default:
  188. return E_NOTIMPL;
  189. }
  190. return S_OK;
  191. }
  192. STDMETHODIMP CShellFolderViewOC::IncludeObject(IShellView *psv, LPCITEMIDLIST pidl)
  193. {
  194. return S_OK;
  195. }
  196. // IFolderViewOC
  197. HRESULT CShellFolderViewOC::SetFolderView(IDispatch *pDisp)
  198. {
  199. HRESULT hr = S_OK;
  200. _ReleaseForwarder(); // cleanup previous state
  201. IUnknown_Set((IUnknown **)&_pFolderView, pDisp);
  202. if (_pFolderView)
  203. hr = _SetupForwarder();
  204. return hr;
  205. }
  206. STDMETHODIMP CShellFolderViewOC::SetClientSite(IOleClientSite *pClientSite)
  207. {
  208. return IOleObjectImpl<CShellFolderViewOC>::SetClientSite(pClientSite);
  209. }
  210. HRESULT CShellFolderViewOC::_SetupForwarder()
  211. {
  212. return ConnectToConnectionPoint(SAFECAST(&_dViewEvents, IDispatch *), DIID_DShellFolderViewEvents, TRUE, _pFolderView, &_dwViewEventsCookie, NULL);
  213. }
  214. void CShellFolderViewOC::_ReleaseForwarder()
  215. {
  216. ConnectToConnectionPoint(NULL, DIID_DShellFolderViewEvents, FALSE, _pFolderView, &_dwViewEventsCookie, NULL);
  217. }
  218. // ATL maintainence functions
  219. LRESULT CShellFolderViewOC::_ReleaseForwarderMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled)
  220. {
  221. bHandled = FALSE;
  222. _ReleaseForwarder();
  223. return 0;
  224. }
  225. STDMETHODIMP CDViewEvents::QueryInterface(REFIID riid, void **ppv)
  226. {
  227. static const QITAB qit[] = {
  228. QITABENTMULTI2(CDViewEvents, DIID_DShellFolderViewEvents, DShellFolderViewEvents),
  229. QITABENTMULTI(CDViewEvents, IDispatch, DShellFolderViewEvents),
  230. { 0 },
  231. };
  232. return QISearch(this, qit, riid, ppv);
  233. }
  234. ULONG CDViewEvents::AddRef()
  235. {
  236. return SAFECAST(_psfvOC, IFolderViewOC*)->AddRef();
  237. }
  238. ULONG CDViewEvents::Release()
  239. {
  240. return SAFECAST(_psfvOC, IFolderViewOC*)->Release();
  241. }
  242. STDMETHODIMP CDViewEvents::GetTypeInfoCount(UINT * pctinfo)
  243. {
  244. return E_NOTIMPL;
  245. }
  246. STDMETHODIMP CDViewEvents::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  247. {
  248. return E_NOTIMPL;
  249. }
  250. STDMETHODIMP CDViewEvents::GetIDsOfNames(REFIID riid, OLECHAR **rgszNames,
  251. UINT cNames, LCID lcid, DISPID *rgdispid)
  252. {
  253. return E_NOTIMPL;
  254. }
  255. STDMETHODIMP CDViewEvents::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
  256. DISPPARAMS *pdispparams, VARIANT *pvarResult,
  257. EXCEPINFO *pexcepinfo, UINT *puArgErr)
  258. {
  259. SHINVOKEPARAMS inv;
  260. inv.flags = 0;
  261. inv.dispidMember = dispidMember;
  262. inv.piid = &riid;
  263. inv.lcid = lcid;
  264. inv.wFlags = wFlags;
  265. inv.pdispparams = pdispparams;
  266. inv.pvarResult = pvarResult;
  267. inv.pexcepinfo = pexcepinfo;
  268. inv.puArgErr = puArgErr;
  269. return IUnknown_CPContainerInvokeIndirect(SAFECAST(_psfvOC, IFolderViewOC *), DIID_DShellFolderViewEvents, &inv);
  270. }
  271. STDAPI CShellFolderViewOC_CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppvOut)
  272. {
  273. return CComCreator< CComObject< CShellFolderViewOC > >::CreateInstance((void *)punkOuter, riid, ppvOut);
  274. }