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.

362 lines
12 KiB

  1. // mediabar.h : Declaration of the CMediaBand
  2. #ifndef __MEDIABAND_H_
  3. #define __MEDIABAND_H_
  4. #include "dpa.h"
  5. #include "bands.h"
  6. #include "player.h"
  7. #include "mediautil.h"
  8. #include "mbutil.h"
  9. #include "mbBehave.h"
  10. #include "iface.h"
  11. #define ERROREXIT(hr) if(FAILED(hr)){hr = E_FAIL; goto done;}
  12. enum
  13. {
  14. MW_PLAY = 0,
  15. MW_STOP,
  16. MW_BACK,
  17. MW_NEXT,
  18. MW_MUTE,
  19. MW_VOLUME,
  20. MW_OPTIONS,
  21. MW_POP,
  22. MW_SEEK,
  23. MW_NUMBER
  24. };
  25. #define WM_MB_DEFERRED_NAVIGATE (WM_USER + 700) // lParam: hwnd of window sending this message (used for reflection)
  26. class CMediaBand : public CToolBand,
  27. public IMediaBar,
  28. public IWinEventHandler,
  29. public INamespaceWalkCB,
  30. public IElementBehaviorFactory,
  31. public IBrowserBand,
  32. public IBandNavigate,
  33. public IMediaHost,
  34. public IDispatchImpl<DWebBrowserEvents2, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw>,
  35. public CMediaBarUtil
  36. {
  37. public:
  38. CMediaBand();
  39. // IUnknown
  40. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  41. STDMETHODIMP_(ULONG) AddRef(void) { return CToolBand::AddRef(); };
  42. STDMETHODIMP_(ULONG) Release(void) { return CToolBand::Release(); };
  43. // IOleCommandTarget
  44. STDMETHODIMP Exec(const GUID *pguidCmdGroup,
  45. DWORD nCmdID,
  46. DWORD nCmdexecopt,
  47. VARIANTARG *pvarargIn,
  48. VARIANTARG *pvarargOut);
  49. // IOleWindow
  50. // (overriding CNSCBand implementation
  51. STDMETHODIMP GetWindow(HWND *phwnd);
  52. // IServiceProvider
  53. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, VOID ** ppvObj);
  54. // IInputObject
  55. // (overriding CNSCBand/CToolBand's implementation)
  56. STDMETHODIMP TranslateAcceleratorIO(LPMSG lpMsg);
  57. STDMETHODIMP UIActivateIO(BOOL fActivate, LPMSG lpMsg);
  58. STDMETHODIMP HasFocusIO();
  59. // IDockingWindow
  60. STDMETHODIMP ShowDW(BOOL fShow);
  61. STDMETHODIMP CloseDW(DWORD dwReserved);
  62. // IElementBehaviorFactory
  63. STDMETHODIMP FindBehavior(BSTR bstrBehavior, BSTR bstrBehaviorUrl, IElementBehaviorSite* pSite, IElementBehavior** ppBehavior);
  64. // IBrowserBand
  65. STDMETHOD(GetObjectBB)(THIS_ REFIID riid, LPVOID *ppv);
  66. STDMETHODIMP SetBrowserBandInfo(THIS_ DWORD dwMask, PBROWSERBANDINFO pbbi) { ASSERT(FALSE); return E_NOTIMPL; }
  67. STDMETHODIMP GetBrowserBandInfo(THIS_ DWORD dwMask, PBROWSERBANDINFO pbbi) { ASSERT(FALSE); return E_NOTIMPL; }
  68. // IBandNavigate
  69. STDMETHOD(Select)(LPCITEMIDLIST pidl);
  70. // IMediaHost
  71. STDMETHOD(getMediaPlayer)(IUnknown **ppPlayer);
  72. STDMETHOD(playURL)(BSTR bstrURL, BSTR bstrMIME);
  73. STDMETHOD(addProxy)(IUnknown *pProxy);
  74. STDMETHOD(removeProxy)(IUnknown *pProxy);
  75. // IMediaHost2
  76. STDMETHOD(OnDisableUIChanged)(BOOL fDisabled);
  77. // IObjectWithSite
  78. STDMETHODIMP SetSite(IUnknown* punkSite);
  79. // IWinEventHandler
  80. STDMETHODIMP OnWinEvent(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plres);
  81. STDMETHODIMP IsWindowOwner(HWND hwnd);
  82. // IMediaBar
  83. STDMETHOD(Notify)(long lReason);
  84. STDMETHOD(OnMediaError)(int iErrCode);
  85. // IDeskBand
  86. STDMETHODIMP GetBandInfo(DWORD dwBandID, DWORD fViewMode,
  87. DESKBANDINFO* pdbi);
  88. // IPersistStream
  89. STDMETHODIMP GetClassID(CLSID *pClassID);
  90. STDMETHODIMP Load(IStream *pStm);
  91. STDMETHODIMP Save(IStream *pStm, BOOL fClearDirty);
  92. // IDispatch
  93. STDMETHODIMP Invoke(
  94. /* [in] */ DISPID dispIdMember,
  95. /* [in] */ REFIID riid,
  96. /* [in] */ LCID lcid,
  97. /* [in] */ WORD wFlags,
  98. /* [out][in] */ DISPPARAMS *pDispParams,
  99. /* [out] */ VARIANT *pVarResult,
  100. /* [out] */ EXCEPINFO *pExcepInfo,
  101. /* [out] */ UINT *puArgErr);
  102. // INamespaceWalkCB
  103. STDMETHODIMP FoundItem(IShellFolder *psf, LPCITEMIDLIST pidl);
  104. STDMETHODIMP EnterFolder(IShellFolder *psf, LPCITEMIDLIST pidl) { return S_OK; }
  105. STDMETHODIMP LeaveFolder(IShellFolder *psf, LPCITEMIDLIST pidl) { return S_OK; }
  106. STDMETHODIMP InitializeProgressDialog(LPWSTR *ppszTitle, LPWSTR *ppszCancel);
  107. private:
  108. ~CMediaBand();
  109. LRESULT _OnVolumeCustomDraw(LPNMCUSTOMDRAW pnm);
  110. LRESULT _OnSeekBarCustomDraw(LPNMCUSTOMDRAW pnm);
  111. BOOL EnsurePlayer();
  112. BOOL CreatePlayer();
  113. VOID DestroyPlayer();
  114. STDMETHOD(_TogglePause)();
  115. STDMETHOD(_PutUrl)(LPWSTR pstrUrl, LPWSTR pstrMime);
  116. STDMETHOD(_EnumPlayItems)(VOID);
  117. HRESULT CreateControls();
  118. HRESULT CreateSeekBar();
  119. HRESULT CreateVolumeControl();
  120. HRESULT CreateParentPane();
  121. HRESULT CreateLayoutPane();
  122. HRESULT _NavigateMainWindow(LPCTSTR lpstrUrl, bool fSuppressFirstAutoPlay = false);
  123. HRESULT InitPlayerPopup();
  124. HWND GetBrowserWindow();
  125. VOID _ResizeChildWindows(HWND hwnd, LONG width, LONG height, BOOL fRepaint);
  126. HRESULT _InitializeMediaUI();
  127. VOID _ResizeVideo(LONG* lWidth, LONG* lHeight);
  128. VOID AdjustLayout(LONG_PTR lWidth=0,LONG_PTR lHeight=0);
  129. VOID DrawBackground(HDC hdc, HWND hwnd);
  130. LPTSTR GetUrlForStatusBarToolTip();
  131. HRESULT _OpenInDefaultPlayer(BSTR bstrUrl);
  132. VOID _ShowAllWindows(BOOL fShow);
  133. HRESULT ShowPlayListMenu(HWND hwnd,RECTL* rc);
  134. HRESULT ShowGenericMenu(HWND hwnd, RECTL* rc);
  135. HRESULT HandleMenuTasks(INT iTask);
  136. VOID ComputeMinMax(MINMAXINFO *pMinMax);
  137. VOID DockMediaPlayer();
  138. static INT_PTR CALLBACK s_PopupDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  139. static LRESULT CALLBACK s_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  140. static LRESULT CALLBACK s_LayoutWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  141. static LRESULT CALLBACK s_SeekWndSubClassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  142. static LRESULT CALLBACK s_VolumeWndSubClassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  143. static INT_PTR CALLBACK s_PromptMimeDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  144. HRESULT GetTrackTitle (BSTR* pbstrTitle);
  145. VOID GetToolbarSize(HWND hwndTB, SIZE* pSize);
  146. float GetSeekPos() ;
  147. VOID SetSeekPos(float fPosition) ;
  148. HRESULT Seek(double dblProgress);
  149. VOID SetStatusText(LPWSTR lpwStatusInfo);
  150. VOID ShowPlayingStatus(BOOL fInitial=FALSE);
  151. VOID AdjustVideoHeight(BOOL fForceResize=FALSE);
  152. VOID TogglePlayPause();
  153. VOID ToggleMute();
  154. LONG GetLayoutHeight(LONG lWidth=0);
  155. LONG GetVideoHeight(LONG lWidth=0, BOOL fNewVideo=FALSE);
  156. LONG GetControlsHeight();
  157. // Menu helpers
  158. HRESULT AddToFavorites(BSTR bstrUrl, BSTR bstrTitle);
  159. HRESULT ResetMimePreferences();
  160. BOOL PromptSettings(UINT IDPROMPT);
  161. // Handler for property change notifications
  162. VOID _OnTitleChange();
  163. // Navigation timeout helpers
  164. VOID _OnNavigationTimeOut();
  165. VOID _UpdateTimeOutCounter(double dblCurrBufProgress, double dblCurrPlayProgress);
  166. VOID _EndTimeOutCounter();
  167. VOID _BeginTimeOutCounter(BOOL fClear = TRUE);
  168. // per mime type checking stuff
  169. VOID _HandleAutoPlay(VARIANTARG *pvarargMime, VARIANTARG *pvarargUrl);
  170. STDMETHODIMP ProfferService(IUnknown *punkSite,
  171. REFGUID sidWhat,
  172. IServiceProvider *pService,
  173. DWORD *pdwCookie);
  174. public:
  175. // mediabar behavior
  176. // non-COM public calls
  177. private:
  178. HRESULT _AddProxyToList(IUnknown *punkProxy);
  179. void _AttachPlayerToProxies(BOOL fAttach);
  180. void _DetachProxies();
  181. BOOL _isUIDisabled();
  182. BOOL _isProxiesNextEnabled();
  183. void _OnUserOverrideDisableUI();
  184. void _FireEventToProxies(enum contentProxyEvent event);
  185. void _CleanupStopTimer();
  186. BOOL _IsProxyRunning(void) { return (_apContentProxies && (_apContentProxies.GetPtrCount() > 0)); }
  187. HRESULT _EnsureWMPInstalled(BOOL fShowErrorMsg = TRUE);
  188. BOOL _fAttached;
  189. UINT_PTR _idStopTimer;
  190. private:
  191. double _dblMediaDur; // natural length of the media
  192. int _iCurTrack;
  193. PTSTR _pszStatus;
  194. HWND _hwndVolume;
  195. HWND _hwndSeek;
  196. HWND _hwndPopup;
  197. HWND _hwndVideo ;
  198. HWND _hwndLayout;
  199. HMENU _hPlayListMenu;
  200. IMediaBarPlayer *_pMediaPlayer;
  201. DWORD _dwCookieServiceMediaBar;
  202. // navigation timeout
  203. DWORD _dwStartTime;
  204. LONG _lTickCount;
  205. double _dblLastBufProgress;
  206. double _dblLastPlayProgress;
  207. SIZE _sizeLayout;
  208. SIZE _sizeVideo ;
  209. BOOL _fPlayButton:1 ;
  210. BOOL _fSeeking:1; // We are seeking, so don't update the seekbar position while we seek.
  211. BOOL _fIsVideo:1;
  212. BOOL _fMuted:1;
  213. BOOL _fVideoAdjust:1;
  214. BOOL _fPlaying:1;
  215. BOOL _fPlayEnabled:1;
  216. BOOL _fInitialized:1;
  217. BOOL _fHiColour:1;
  218. BOOL _fUserPaused:1;
  219. BOOL _fHighDPI:1;
  220. float _scaleX, _scaleY;
  221. CMediaWidget* _pmw[MW_NUMBER];
  222. HIMAGELIST _himlGripper;
  223. HBITMAP _hbmpBackground;
  224. HIMAGELIST _himlVolumeBack, _himlVolumeFill;
  225. HIMAGELIST _himlSeekBack, _himlSeekFill;
  226. HBRUSH _hbrSeekBrush;
  227. VOID Resize(HWND hwnd, LONG lWidth, LONG lHeight);
  228. LONG GetPopoutHeight(BOOL fVideo=FALSE, LONG lWidth=0);
  229. LONG GetMinPopoutWidth();
  230. BOOL ResetPlayer();
  231. HRESULT PlayLocalTrack(INT iTrackNum);
  232. HRESULT PlayNextTrack();
  233. BOOL SetPlayerControl(UINT ui, BOOL fState);
  234. BOOL UpdateBackForwardControls();
  235. VOID UpdateMenuItems(HMENU hmenu);
  236. LPTSTR _szToolTipUrl;
  237. BOOL OnNotify(LPNMHDR pnm, LRESULT* plres);
  238. VOID SetPlayPause(BOOL fState);
  239. VOID SwitchBitmaps(BOOL fNewSetting);
  240. HRESULT _GetMusicFromFolder();
  241. void _ClearFolderItems();
  242. LPITEMIDLIST *_ppidls;
  243. UINT _cidls;
  244. INT _iElement;
  245. double _dblVol;
  246. TCHAR _szConnecting[MAX_PATH];
  247. INT _iOptionsWidth;
  248. CComBSTR _strLastUrl;
  249. CComBSTR _strLastMime;
  250. BOOL _fLastUrlIsAutoPlay;
  251. // Content pane
  252. HWND _hwndContent;
  253. DWORD _dwcpCookie;
  254. CComPtr<IWebBrowser2> _spBrowser;
  255. CComBSTR _strDeferredURL;
  256. CComBSTR _strCurrentContentUrl;
  257. CComPtr<IOleInPlaceActiveObject> _poipao;
  258. BOOL _fContentInFocus;
  259. VOID InitContentPane();
  260. HRESULT NavigateContentPane(BSTR bstrUrl);
  261. HRESULT NavigateContentPane(LPCITEMIDLIST pidl);
  262. VOID NavigateMoreMedia();
  263. HRESULT _NavigateContentToDefaultURL(void);
  264. HRESULT _ConnectToCP(BOOL fConnect);
  265. HRESULT _BuildPageURLWithParam(LPCTSTR pszURL, LPCTSTR pszParam, OUT LPTSTR pszBuffer, UINT uiBufSize);
  266. BOOL _DeferredNavigate(LPCTSTR pszURL);
  267. HRESULT _ContentActivateIO(BOOL fActivate, PMSG pMsg);
  268. LRESULT _OnNotify(LPNMHDR pnm);
  269. BOOL _fSavedPopoutState;
  270. WINDOWPLACEMENT _wpPopout;
  271. BOOL _fPopoutHasFocus;
  272. void ActivatePopout(BOOL fState);
  273. HKEY _hkeyWMP;
  274. BOOL _fShow;
  275. // mediaBehavior
  276. CDPA<IContentProxy> _apContentProxies;
  277. };
  278. #define _pmwPlay ((CMediaWidgetButton*)_pmw[MW_PLAY])
  279. #define _pmwStop ((CMediaWidgetButton*)_pmw[MW_STOP])
  280. #define _pmwBack ((CMediaWidgetButton*)_pmw[MW_BACK])
  281. #define _pmwNext ((CMediaWidgetButton*)_pmw[MW_NEXT])
  282. #define _pmwMute ((CMediaWidgetToggle*)_pmw[MW_MUTE])
  283. #define _pmwVolume ((CMediaWidgetVolume*)_pmw[MW_VOLUME])
  284. #define _pmwOptions ((CMediaWidgetOptions*)_pmw[MW_OPTIONS])
  285. #define _pmwPop ((CMediaWidgetButton*)_pmw[MW_POP])
  286. #define _pmwSeek ((CMediaWidgetSeek*)_pmw[MW_SEEK])
  287. #define ISVALIDWIDGET(x) (x && x->_hwnd)
  288. #endif // __MEDIABAND_H_