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.

323 lines
12 KiB

  1. //------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001
  5. //
  6. // File: mbBehave.h
  7. //
  8. // Contents: mediaBar player behavior
  9. //
  10. // Classes: CMediaBehavior
  11. //
  12. //------------------------------------------------------------------------
  13. #ifndef _MB_BEHAVE_H_
  14. #define _MB_BEHAVE_H_
  15. #if _MSC_VER > 1000
  16. #pragma once
  17. #endif // _MSC_VER > 1000
  18. #include "dpa.h"
  19. #include "dspsprt.h"
  20. class CMediaBand;
  21. class CMediaBehavior;
  22. interface IMediaBehaviorContentProxy : public IUnknown
  23. {
  24. STDMETHOD(IsDisableUIRequested)(BOOL *pfRequested) PURE;
  25. STDMETHOD(OnUserOverrideDisableUI)(void) PURE;
  26. STDMETHOD(IsNextEnabled)(BOOL *pfEnabled) PURE;
  27. };
  28. // {F4C74D34-AB35-4d67-A7CF-7845548F45A8}
  29. DEFINE_GUID(IID_IMediaBehaviorContentProxy, 0xf4c74d34, 0xab35, 0x4d67, 0xa7, 0xcf, 0x78, 0x45, 0x54, 0x8f, 0x45, 0xa8);
  30. /*
  31. interface IMediaHost2 : public IMediaHost
  32. {
  33. virtual STDMETHOD(DetachBehavior)(void) PURE;
  34. virtual STDMETHOD(OnDisableUIChanged)(BOOL fDisabled) PURE;
  35. };
  36. // {895EBF7E-ECA0-4ba8-B0F2-89DEBF70DE65}
  37. DEFINE_GUID(IID_IMediaHost2, 0x895ebf7e, 0xeca0, 0x4ba8, 0xb0, 0xf2, 0x89, 0xde, 0xbf, 0x70, 0xde, 0x65);
  38. */
  39. //------------------------------------------------------------------------
  40. //------------------------------------------------------------------------
  41. // need an additional operator to easily assign from VARIANTs
  42. class CComDispatchDriverEx : public CComDispatchDriver
  43. {
  44. public:
  45. IDispatch* operator=(VARIANT vt)
  46. {
  47. IDispatch *pThis = NULL;
  48. ASSERT((V_VT(&vt) == VT_UNKNOWN) || (V_VT(&vt) == VT_DISPATCH));
  49. if (V_VT(&vt) == VT_UNKNOWN)
  50. {
  51. pThis = (IDispatch*) AtlComQIPtrAssign((IUnknown**)&p, V_UNKNOWN(&vt), IID_IDispatch);
  52. }
  53. else if (V_VT(&vt) == VT_DISPATCH)
  54. {
  55. pThis = (IDispatch*)AtlComPtrAssign((IUnknown**)&p, V_DISPATCH(&vt));
  56. }
  57. // ISSUE could make more efforts to accept REF variants too
  58. return pThis;
  59. }
  60. // get a property by name with a single parameter
  61. HRESULT GetPropertyByName1(LPCOLESTR lpsz, VARIANT* pvarParam1, VARIANT* pVar)
  62. {
  63. DISPID dwDispID;
  64. HRESULT hr = GetIDOfName(lpsz, &dwDispID);
  65. if (SUCCEEDED(hr))
  66. {
  67. DISPPARAMS dispparams = { pvarParam1, NULL, 1, 0};
  68. return p->Invoke(dwDispID, IID_NULL,
  69. LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,
  70. &dispparams, pVar, NULL, NULL);
  71. }
  72. return hr;
  73. }
  74. };
  75. //------------------------------------------------------------------------
  76. //------------------------------------------------------------------------
  77. class CWMPWrapper
  78. {
  79. public:
  80. HRESULT AttachToWMP();
  81. protected:
  82. virtual HRESULT FetchWmpObject(IDispatch *pdispWmpPlayer, OUT VARIANT *pvtWrapperObj) = 0;
  83. STDMETHODIMP_(ULONG) _AddRef(void)
  84. {
  85. _cRef++;
  86. return _cRef;
  87. }
  88. STDMETHODIMP_(ULONG) _Release(void)
  89. {
  90. ASSERT(_cRef > 0);
  91. _cRef--;
  92. if (_cRef > 0) return _cRef;
  93. delete this;
  94. return 0;
  95. }
  96. HRESULT _getVariantProp(LPCOLESTR pwszPropName, VARIANT *pvtParam, VARIANT *pvtValue, BOOL fCallMethod = FALSE);
  97. HRESULT _getStringProp(LPCOLESTR pwszPropName, VARIANT *pvtParam, OUT BSTR *pbstrValue, BOOL fCallMethod = FALSE);
  98. protected:
  99. CWMPWrapper(CMediaBehavior* pHost);
  100. virtual ~CWMPWrapper();
  101. protected:
  102. CMediaBehavior * _pHost;
  103. CComDispatchDriverEx _pwmpWrapper;
  104. BOOL _fStale;
  105. private:
  106. ULONG _cRef;
  107. };
  108. //------------------------------------------------------------------------
  109. //------------------------------------------------------------------------
  110. class CMediaItem : public CWMPWrapper,
  111. public IMediaItem,
  112. protected CImpIDispatch
  113. {
  114. typedef CWMPWrapper super;
  115. public:
  116. // *** IUnknown ***
  117. STDMETHOD(QueryInterface)(REFIID riid, LPVOID * ppvObj);
  118. STDMETHODIMP_(ULONG) AddRef(void) { return _AddRef(); }
  119. STDMETHODIMP_(ULONG) Release(void) { return _Release(); }
  120. // *** IDispatch ***
  121. virtual STDMETHODIMP GetTypeInfoCount(UINT * pctinfo)
  122. { return CImpIDispatch::GetTypeInfoCount(pctinfo); }
  123. virtual STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  124. { return CImpIDispatch::GetTypeInfo(itinfo, lcid, pptinfo); }
  125. virtual STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID * rgdispid)
  126. { return CImpIDispatch::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid); }
  127. virtual STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, UINT * puArgErr)
  128. { return CImpIDispatch::Invoke(dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr); }
  129. // *** IMediaItem
  130. STDMETHOD(get_sourceURL)(BSTR *pbstrSourceURL);
  131. STDMETHOD(get_name)(BSTR *pbstrName);
  132. STDMETHOD(get_duration)(double * pDuration);
  133. STDMETHOD(get_attributeCount)(long *plCount);
  134. STDMETHOD(getAttributeName)(long lIndex, BSTR *pbstrItemName);
  135. STDMETHOD(getItemInfo)(BSTR bstrItemName, BSTR *pbstrVal);
  136. protected:
  137. virtual HRESULT FetchWmpObject(IDispatch *pdispWmpPlayer, OUT VARIANT *pvtWrapperObj);
  138. friend CMediaItem* CMediaItem_CreateInstance(CMediaBehavior* pHost);
  139. CMediaItem(CMediaBehavior* pHost);
  140. virtual ~CMediaItem();
  141. private:
  142. };
  143. //------------------------------------------------------------------------
  144. //------------------------------------------------------------------------
  145. class CMediaItemNext : public CMediaItem
  146. {
  147. public:
  148. protected:
  149. virtual HRESULT FetchWmpObject(IDispatch *pdispWmpPlayer, OUT VARIANT *pvtWrapperObj);
  150. friend CMediaItemNext* CMediaItemNext_CreateInstance(CMediaBehavior* pHost);
  151. CMediaItemNext(CMediaBehavior* pHost);
  152. virtual ~CMediaItemNext();
  153. private:
  154. };
  155. //------------------------------------------------------------------------
  156. //------------------------------------------------------------------------
  157. class CPlaylistInfo : public CWMPWrapper,
  158. public IPlaylistInfo,
  159. protected CImpIDispatch
  160. {
  161. typedef CWMPWrapper super;
  162. public:
  163. // *** IUnknown ***
  164. STDMETHOD(QueryInterface)(REFIID riid, LPVOID * ppvObj);
  165. STDMETHODIMP_(ULONG) AddRef(void) { return _AddRef(); }
  166. STDMETHODIMP_(ULONG) Release(void) { return _Release(); }
  167. // *** IDispatch ***
  168. virtual STDMETHODIMP GetTypeInfoCount(UINT * pctinfo)
  169. { return CImpIDispatch::GetTypeInfoCount(pctinfo); }
  170. virtual STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  171. { return CImpIDispatch::GetTypeInfo(itinfo, lcid, pptinfo); }
  172. virtual STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID * rgdispid)
  173. { return CImpIDispatch::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid); }
  174. virtual STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, UINT * puArgErr)
  175. { return CImpIDispatch::Invoke(dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr); }
  176. // *** IPlaylistInfo
  177. STDMETHOD(get_name)(BSTR *pbstrName);
  178. STDMETHOD(get_attributeCount)(long *plCount);
  179. STDMETHOD(getAttributeName)(long lIndex, BSTR *pbstrItemName);
  180. STDMETHOD(getItemInfo)(BSTR bstrItemName, BSTR *pbstrVal);
  181. protected:
  182. virtual HRESULT FetchWmpObject(IDispatch *pdispWmpPlayer, OUT VARIANT *pvtWrapperObj);
  183. friend CPlaylistInfo* CPlaylistInfo_CreateInstance(CMediaBehavior* pHost);
  184. CPlaylistInfo(CMediaBehavior* pHost);
  185. private:
  186. virtual ~CPlaylistInfo();
  187. private:
  188. };
  189. //------------------------------------------------------------------------
  190. //------------------------------------------------------------------------
  191. class CMediaBehavior : public IMediaBehavior,
  192. public IElementBehavior,
  193. public IContentProxy,
  194. public IMediaBehaviorContentProxy,
  195. protected CImpIDispatch
  196. {
  197. public:
  198. // *** IUnknown ***
  199. STDMETHOD(QueryInterface)(REFIID riid, LPVOID * ppvObj);
  200. STDMETHODIMP_(ULONG) AddRef(void)
  201. {
  202. _cRef++;
  203. return _cRef;
  204. }
  205. STDMETHODIMP_(ULONG) Release(void)
  206. {
  207. ASSERT(_cRef > 0);
  208. _cRef--;
  209. if (_cRef > 0) return _cRef;
  210. delete this;
  211. return 0;
  212. }
  213. // *** IDispatch ***
  214. virtual STDMETHODIMP GetTypeInfoCount(UINT * pctinfo)
  215. { return CImpIDispatch::GetTypeInfoCount(pctinfo); }
  216. virtual STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  217. { return CImpIDispatch::GetTypeInfo(itinfo, lcid, pptinfo); }
  218. virtual STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID * rgdispid)
  219. { return CImpIDispatch::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid); }
  220. virtual STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, UINT * puArgErr);
  221. // *** IElementBehavior ***
  222. STDMETHOD(Detach)(void);
  223. STDMETHOD(Init)(IElementBehaviorSite* pBehaviorSite);
  224. STDMETHOD(Notify)(LONG lEvent, VARIANT* pVar);
  225. // *** IMediaBehavior ***
  226. STDMETHOD(playURL)(BSTR bstrURL, BSTR bstrMIME);
  227. STDMETHOD(stop)();
  228. STDMETHOD(playNext)();
  229. STDMETHOD(get_currentItem)(IMediaItem **ppMediaItem);
  230. STDMETHOD(get_nextItem)(IMediaItem **ppMediaItem);
  231. STDMETHOD(get_playlistInfo)(IPlaylistInfo **ppPlaylistInfo);
  232. STDMETHOD(get_hasNextItem)(VARIANT_BOOL *pfhasNext);
  233. STDMETHOD(get_playState)(mbPlayState *pps);
  234. STDMETHOD(get_openState)(mbOpenState *pos);
  235. STDMETHOD(get_enabled)(VARIANT_BOOL *pbEnabled);
  236. STDMETHOD(put_enabled)(VARIANT_BOOL bEnabled);
  237. STDMETHOD(get_disabledUI)(VARIANT_BOOL *pbDisabled);
  238. STDMETHOD(put_disabledUI)(VARIANT_BOOL bDisable);
  239. // *** IContentProxy **
  240. STDMETHOD(fireEvent)(enum contentProxyEvent event);
  241. STDMETHOD(OnCreatedPlayer)(void);
  242. STDMETHOD(detachPlayer)(void);
  243. // *** IMediaBehaviorContentProxy **
  244. STDMETHOD(IsDisableUIRequested)(BOOL *pfRequested);
  245. STDMETHOD(OnUserOverrideDisableUI)(void);
  246. STDMETHOD(IsNextEnabled)(BOOL *pfEnabled);
  247. HRESULT getWMP(IDispatch **ppPlayer);
  248. HRESULT getPlayListIndex(LONG *plIndex, LONG *plCount);
  249. protected:
  250. friend CMediaBehavior* CMediaBehavior_CreateInstance(CMediaBand* pHost);
  251. CMediaBehavior(CMediaBand* pHost);
  252. private:
  253. virtual ~CMediaBehavior();
  254. private:
  255. HRESULT _ConnectToWmpEvents(BOOL fConnect);
  256. BOOL _ProcessEvent(DISPID dispid, long lCount, VARIANT varParams[]);
  257. private:
  258. ULONG _cRef;
  259. CMediaBand * _pHost;
  260. CComPtr<IElementBehaviorSite> _pBehaviorSite;
  261. CComPtr<IElementBehaviorSiteOM> _pBehaviorSiteOM;
  262. DWORD _dwcpCookie;
  263. BOOL _fDisabledUI;
  264. CDPA<CMediaItem> _apMediaItems;
  265. BOOL _fPlaying;
  266. };
  267. //------------------------------------------------------------------------
  268. #endif // _MB_BEHAVE_H_