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.

4438 lines
134 KiB

  1. #include "priv.h"
  2. #include "sccls.h"
  3. #include "resource.h"
  4. #include "dhuihand.h"
  5. #include <varutil.h>
  6. #include "mstimeid.h"
  7. #include <mluisupp.h>
  8. #include "mediahlpr.h"
  9. #include "mediaband.h"
  10. #include "apithk.h"
  11. #include "mbBehave.h"
  12. #define SUPERCLASS CToolBand
  13. #define MIN_WINDOW_WIDTH 145
  14. #define MIN_WINDOW_HEIGHT 60
  15. #define MIN_POPOUT_HEIGHT 300
  16. #define MIN_POPOUT_WIDTH 300
  17. #define MIN_VOLUME_WIDTH 50
  18. #define MIN_VOLUME_HEIGHT 16
  19. #define MIN_HORZ_SPACING 10
  20. #define SEEK_PART_WIDTH 18
  21. #define SEEK_PART_HEIGHT 5
  22. #define SEEK_HEIGHT 16
  23. #define VOLUME_GRIPPER_LENGTH 6
  24. #define COLOR_BKGND16 RGB(192, 192, 192)
  25. #define COLOR_BKGNDMIDDLE RGB(99, 129, 193)
  26. #define VOLUME_BITMAP_WIDTH 42
  27. #define VIDEO_MIN_HEIGHT 60
  28. #define VIEW_MARGIN_BOTTOM 7
  29. #define VIEW_MARGIN_LEFT 6
  30. #define VIEW_MARGIN_INFO_LEFT 5
  31. #define VIEW_MARGIN_RIGHT 10
  32. #define VIEW_MARGIN_TOP 5
  33. #define VIEW_MARGIN_TOP_VIDEO 6
  34. #define VIEW_MARGIN_BOTTOM 7
  35. #define VIEW_CONTROLS_HEIGHT 33
  36. #define VIEW_CONTROLS_MARGIN 2
  37. #define SCALEX(x) (_fHighDPI ? ((INT)(((float)(x))*_scaleX)) : (x))
  38. #define SCALEY(x) (_fHighDPI ? ((INT)(((float)(x))*_scaleY)) : (x))
  39. #define WZ_SMIE_MEDIA_MIME REG_MEDIA_STR TEXT("\\MimeTypes")
  40. #define REG_VALUE_MRU_INTERNET REG_MEDIA_STR TEXT("\\Internet")
  41. #define REG_VALUE_PATH TEXT("MusicPath")
  42. //
  43. // ISSUE: dilipk: these are localizable strings and need to be moved eventually !!!
  44. //
  45. #define WZ_WINDOWSMEDIA L"http://www.windowsmedia.com"
  46. #define WZ_ASX_MIMETYPE L"video/x-ms-asx"
  47. static const TCHAR c_szMediaBandProp[] = TEXT("CMediaBand_This");
  48. static const TCHAR c_szMediaBarClassName[] = TEXT("MediaPane");
  49. static const TCHAR c_szMediaBarPopupClassName[] = TEXT("MediaPopupPane");
  50. static const TCHAR c_szMediaBarLayoutClassName[] = TEXT("MediaLayoutPane");
  51. // ISSUE: these two should be deleted when reg utilities are completely moved to mediautil.cpp
  52. static const UINT MAX_REG_VALUE_LENGTH = 50;
  53. // This is the number of ticks (from MSTIME) to skip each time before polling System Time
  54. // for the navigation timeout counter
  55. #define POLL_INTERVAL 30
  56. // This is the number of milli-seconds after which navigation times out
  57. #define TIMEOUT_INTERVAL 90000
  58. static const TCHAR c_szContentUrl[] = TEXT("http://go.microsoft.com/fwlink/?LinkId=511");
  59. static const TCHAR c_szMoreMediaUrl[] = TEXT("http://go.microsoft.com/fwlink/?LinkId=512");
  60. static const TCHAR c_szRadioUrl[] = TEXT("http://go.microsoft.com/fwlink/?LinkId=822");
  61. static const TCHAR c_szOfflineURL[] = TEXT("mbOffline.htm");
  62. static const TCHAR c_szLoadingURL[] = TEXT("mbLoading.htm");
  63. static const TCHAR c_sz404URL[] = TEXT("mb404.htm");
  64. extern HBITMAP CreateMirroredBitmap( HBITMAP hbmOrig);
  65. //
  66. // ISSUE: this is a temporary guid for the content pane sync feature.
  67. //
  68. static const IID SID_SMediaBarSync = { 0x2efc8085, 0x066b, 0x4823, { 0x9d, 0xb4, 0xd1, 0xe7, 0x69, 0x16, 0xda, 0xa0 } };
  69. static const GUID SID_STimeContent = { 0x1ae98e18, 0xc527, 0x4f78, {0xb2, 0xa2, 0x6a, 0x81, 0x7f, 0x9c, 0xd4, 0xf8}};
  70. // ISSUE where could be #include this GUID from?????
  71. static const GUID CLSID_JITWMP8 = { 0x6BF52A52, 0x394A, 0x11d3, 0xb1, 0x53, 0x00, 0xc0, 0x4f, 0x79, 0xfa, 0xa6 };
  72. CMediaBand::CMediaBand() :
  73. _fPlayButton(TRUE),
  74. _fPlayEnabled(TRUE),
  75. _iCurTrack(-1),
  76. _lTickCount(-1),
  77. _iElement(-1),
  78. _dblVol(-1.0),
  79. _fHiColour(TRUE),
  80. _fUserPaused(FALSE),
  81. _iOptionsWidth(0),
  82. _hbmpBackground(NULL),
  83. _hwndContent(NULL),
  84. _dwcpCookie(0),
  85. _fContentInFocus(FALSE),
  86. _hkeyWMP(NULL),
  87. _fShow(FALSE),
  88. _fAttached(FALSE)
  89. {
  90. _sizeLayout.cx = MIN_WINDOW_WIDTH;
  91. _sizeLayout.cy = MIN_WINDOW_HEIGHT;
  92. _sizeVideo.cx = 0 ;
  93. _sizeVideo.cy = 0 ;
  94. _fCanFocus = TRUE;
  95. _scaleX = _scaleY = 1.0;
  96. // HighDPI support requires nice comctl32 6.0 functionality.
  97. if (IsOS(OS_WHISTLERORGREATER))
  98. {
  99. HDC hdcScreen = GetDC(NULL);
  100. if (hdcScreen)
  101. {
  102. _scaleX = (GetDeviceCaps(hdcScreen, LOGPIXELSX) / 96.0f);
  103. _scaleY = (GetDeviceCaps(hdcScreen, LOGPIXELSY) / 96.0f);
  104. ReleaseDC(NULL, hdcScreen);
  105. }
  106. }
  107. _fHighDPI = (_scaleX!=1.0) || (_scaleY!=1.0);
  108. }
  109. CMediaBand::~CMediaBand()
  110. {
  111. DestroyPlayer();
  112. if (_spBrowser)
  113. {
  114. _ConnectToCP(FALSE);
  115. _spBrowser.Release();
  116. _poipao.Release();
  117. }
  118. DESTROY_OBJ_WITH_HANDLE(_hwndContent, DestroyWindow);
  119. DESTROY_OBJ_WITH_HANDLE(_hwndPopup, DestroyWindow);
  120. DESTROY_OBJ_WITH_HANDLE(_hwndLayout, DestroyWindow);
  121. DESTROY_OBJ_WITH_HANDLE(_hPlayListMenu, DestroyMenu);
  122. DESTROY_OBJ_WITH_HANDLE(_himlSeekBack, ImageList_Destroy);
  123. DESTROY_OBJ_WITH_HANDLE(_himlSeekFill, ImageList_Destroy);
  124. DESTROY_OBJ_WITH_HANDLE(_himlGripper, ImageList_Destroy);
  125. DESTROY_OBJ_WITH_HANDLE(_himlVolumeBack, ImageList_Destroy);
  126. DESTROY_OBJ_WITH_HANDLE(_himlVolumeFill, ImageList_Destroy);
  127. DESTROY_OBJ_WITH_HANDLE(_hbmpBackground, DeleteObject);
  128. // need to check IsWindow because this window can also be destroyed by CMediaBarPlayer
  129. if (_hwndVideo && ::IsWindow(_hwndVideo))
  130. DestroyWindow(_hwndVideo);
  131. if (_szToolTipUrl)
  132. {
  133. delete [] _szToolTipUrl;
  134. }
  135. if (_pszStatus)
  136. {
  137. delete [] _pszStatus;
  138. }
  139. for (int i=0; i < ARRAYSIZE(_pmw); i++)
  140. {
  141. if (_pmw[i])
  142. {
  143. delete _pmw[i];
  144. }
  145. }
  146. if (_hkeyWMP)
  147. RegCloseKey(_hkeyWMP);
  148. }
  149. // helper to get up to service provider and to do register/unregister
  150. // two forms:
  151. // pService != NULL, register, pdwCookie is [out] returns cookie
  152. // pService == NULL, unregister, *pdwCookie is [in] de-registers the service
  153. STDMETHODIMP CMediaBand::ProfferService(IUnknown *punkSite, REFGUID sidWhat,
  154. IServiceProvider *pService, DWORD *pdwCookie)
  155. {
  156. IProfferService *pps;
  157. HRESULT hr = IUnknown_QueryService(punkSite, SID_SProfferService, IID_PPV_ARG(IProfferService, &pps));
  158. if (SUCCEEDED(hr))
  159. {
  160. if (pService)
  161. hr = pps->ProfferService(sidWhat, pService, pdwCookie);
  162. else
  163. {
  164. hr = pps->RevokeService(*pdwCookie);
  165. *pdwCookie = 0;
  166. }
  167. pps->Release();
  168. }
  169. return hr;
  170. }
  171. HRESULT CMediaBand::SetSite(IUnknown *punkSite)
  172. {
  173. // Make sure we proffer the service only once
  174. // This is important since we get created multiple times,
  175. CComPtr<IUnknown> spUnk;
  176. // Check if we need to revoke our service, or if our service was already proffered by
  177. // another instance of CMediaBar
  178. if ((!punkSite && _dwCookieServiceMediaBar) ||
  179. (punkSite && FAILED(IUnknown_QueryService(punkSite, SID_SMediaBar, IID_PPV_ARG(IUnknown, &spUnk)))))
  180. {
  181. // Proffer or Revoke BrandBand service as appropriate
  182. ProfferService(punkSite ? punkSite : _punkSite, SID_SMediaBar,
  183. punkSite ? SAFECAST(this, IServiceProvider *) : NULL, &_dwCookieServiceMediaBar);
  184. // Failure here does not require special handling
  185. }
  186. return SUPERCLASS::SetSite(punkSite);
  187. }
  188. HRESULT CMediaBand::QueryInterface(REFIID riid, void **ppv)
  189. {
  190. static const QITAB qit[] =
  191. {
  192. QITABENT(CMediaBand, IMediaBar),
  193. QITABENT(CMediaBand, IWinEventHandler),
  194. QITABENT(CMediaBand, IObjectWithSite),
  195. QITABENT(CMediaBand, INamespaceWalkCB),
  196. QITABENTMULTI(CMediaBand, IDispatch, DWebBrowserEvents2),
  197. QITABENTMULTI2(CMediaBand, DIID_DWebBrowserEvents2, DWebBrowserEvents2),
  198. QITABENT(CMediaBand, IElementBehaviorFactory),
  199. QITABENT(CMediaBand, IBrowserBand),
  200. QITABENT(CMediaBand, IBandNavigate),
  201. QITABENT(CMediaBand, IMediaHost),
  202. { 0 },
  203. };
  204. HRESULT hr = QISearch(this, qit, riid, ppv);
  205. if (FAILED(hr))
  206. {
  207. hr = SUPERCLASS::QueryInterface(riid, ppv);
  208. }
  209. return hr;
  210. }
  211. // *** IWinEventHandler ***
  212. HRESULT CMediaBand::IsWindowOwner(HWND hwnd)
  213. {
  214. for (int i=0; i < ARRAYSIZE(_pmw); i++)
  215. {
  216. if (_pmw[i] && (hwnd==_pmw[i]->_hwnd))
  217. {
  218. return S_OK;
  219. }
  220. }
  221. return S_FALSE;
  222. }
  223. // *** IWinEventHandler ***
  224. HRESULT CMediaBand::OnWinEvent(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plres)
  225. {
  226. CMediaBand* pmb = reinterpret_cast<CMediaBand *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
  227. switch (uMsg)
  228. {
  229. case WM_COMMAND:
  230. {
  231. HWND hwndControl = GET_WM_COMMAND_HWND(wParam, lParam);
  232. UINT idCmd = GET_WM_COMMAND_ID(wParam, lParam);
  233. if (HIWORD(wParam) == BN_CLICKED && hwndControl)
  234. {
  235. RECT rc;
  236. VARIANTARG var;
  237. var.vt = VT_I4;
  238. GetWindowRect(hwndControl, &rc);
  239. MapWindowPoints(hwndControl, HWND_DESKTOP, (LPPOINT)&rc, 2);
  240. var.lVal = MAKELONG(rc.left, rc.bottom);
  241. return Exec(&CLSID_MediaBand, idCmd, 0, &var, NULL);
  242. }
  243. }
  244. break;
  245. }
  246. return S_FALSE;
  247. }
  248. void CMediaBand::_ClearFolderItems()
  249. {
  250. if (_ppidls)
  251. {
  252. FreeIDListArray(_ppidls, _cidls);
  253. _ppidls = NULL;
  254. }
  255. _cidls = 0;
  256. }
  257. // INamespaceWalkCB methods
  258. HRESULT CMediaBand::FoundItem(IShellFolder *psf, LPCITEMIDLIST pidl)
  259. {
  260. if (NULL == _hkeyWMP)
  261. {
  262. RegOpenKey(HKEY_CLASSES_ROOT, TEXT("Applications\\mplayer2.exe\\SupportedTypes"), &_hkeyWMP);
  263. }
  264. HRESULT hr = S_FALSE; // default to no
  265. if (_hkeyWMP)
  266. {
  267. TCHAR szName[MAX_PATH];
  268. if (SUCCEEDED(DisplayNameOf(psf, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, szName, ARRAYSIZE(szName))))
  269. {
  270. if (ERROR_SUCCESS == RegQueryValueEx(_hkeyWMP, PathFindExtension(szName), NULL, NULL, NULL, NULL))
  271. {
  272. hr = S_OK;
  273. }
  274. }
  275. }
  276. return hr;
  277. }
  278. STDMETHODIMP CMediaBand::InitializeProgressDialog(LPWSTR *ppszTitle, LPWSTR *ppszCancel)
  279. {
  280. TCHAR szText[200];
  281. MLLoadString(IDS_MEDIABANDSEARCH, szText, ARRAYSIZE(szText));
  282. SHStrDup(szText, ppszTitle);
  283. *ppszCancel = NULL;
  284. return S_OK;
  285. }
  286. HRESULT CMediaBand::_GetMusicFromFolder()
  287. {
  288. _ClearFolderItems();
  289. INamespaceWalk *pnsw;
  290. HRESULT hr = CoCreateInstance(CLSID_NamespaceWalker, NULL, CLSCTX_INPROC, IID_PPV_ARG(INamespaceWalk, &pnsw));
  291. if (SUCCEEDED(hr))
  292. {
  293. hr = pnsw->Walk(_punkSite, NSWF_ONE_IMPLIES_ALL | NSWF_NONE_IMPLIES_ALL | NSWF_SHOW_PROGRESS, 10, this);
  294. if (SUCCEEDED(hr))
  295. {
  296. hr = pnsw->GetIDArrayResult(&_cidls, &_ppidls);
  297. }
  298. pnsw->Release();
  299. }
  300. return hr;
  301. }
  302. // *** IOleCommandTarget methods ***
  303. HRESULT CMediaBand::Exec(const GUID *pguidCmdGroup,
  304. DWORD nCmdID,
  305. DWORD nCmdexecopt,
  306. VARIANTARG *pvarargIn,
  307. VARIANTARG *pvarargOut)
  308. {
  309. HRESULT hr = S_OK;
  310. if (pguidCmdGroup)
  311. {
  312. if (IsEqualGUID(CLSID_MediaBand, *pguidCmdGroup))
  313. {
  314. switch (nCmdID)
  315. {
  316. case FCIDM_MEDIABAND_POPOUT:
  317. {
  318. DockMediaPlayer();
  319. }
  320. break;
  321. case FCIDM_MEDIABAND_PLAY:
  322. if (!_pMediaPlayer || _pMediaPlayer->isStopped())
  323. {
  324. _CleanupStopTimer();
  325. hr = _GetMusicFromFolder();
  326. if (S_OK == hr)
  327. {
  328. _strLastUrl.Empty(); // would be nicer to replay same local file if navigated away....
  329. PlayLocalTrack(0);
  330. }
  331. else if (HRESULT_FROM_WIN32(ERROR_CANCELLED) != hr)
  332. {
  333. // if we already played a media in this session, replay it
  334. if (_strLastUrl.Length() > 0)
  335. {
  336. if (_fLastUrlIsAutoPlay)
  337. {
  338. // repeat playing last auto-play
  339. CComVariant vtURL = _strLastUrl;
  340. CComVariant vtMime = _strLastMime;
  341. Exec(&CGID_MediaBar, MBID_PLAY, 0, &vtMime, &vtURL);
  342. }
  343. else
  344. {
  345. // replay media thru content pane and media bar behavior
  346. NavigateContentPane(_strLastUrl);
  347. }
  348. }
  349. else
  350. {
  351. NavigateMoreMedia();
  352. }
  353. }
  354. }
  355. else
  356. {
  357. _TogglePause();
  358. TogglePlayPause();
  359. }
  360. break;
  361. case FCIDM_MEDIABAND_PREVIOUS:
  362. if (EnsurePlayer())
  363. {
  364. LONG_PTR lCurTrack = _pMediaPlayer->GetPlayListItemIndex();
  365. LONG_PTR lItemCount = _pMediaPlayer->GetPlayListItemCount();
  366. if (lCurTrack > 0)
  367. {
  368. _pMediaPlayer->Prev();
  369. }
  370. else if (_iCurTrack >= 0)
  371. {
  372. int i = _iCurTrack;
  373. _iCurTrack = -1; // don't auto-step to next on finished event
  374. _pMediaPlayer->Stop(); // generates MEDIA_TRACK_FINISHED
  375. PlayLocalTrack((i - 1 >= 0) ? i - 1 : 0);
  376. }
  377. UpdateBackForwardControls();
  378. TogglePlayPause();
  379. }
  380. break;
  381. case FCIDM_MEDIABAND_NEXT:
  382. if (EnsurePlayer())
  383. {
  384. LONG_PTR lCurTrack = _pMediaPlayer->GetPlayListItemIndex();
  385. LONG_PTR lItemCount = _pMediaPlayer->GetPlayListItemCount();
  386. if ((lCurTrack >= 0) && (lCurTrack < lItemCount - 1))
  387. {
  388. _pMediaPlayer->Next();
  389. }
  390. else if (_iCurTrack >= 0)
  391. {
  392. int i = _iCurTrack;
  393. _iCurTrack = -1; // don't auto-step to next on finished event
  394. _pMediaPlayer->Stop(); // generates MEDIA_TRACK_FINISHED
  395. PlayLocalTrack(i + 1);
  396. }
  397. UpdateBackForwardControls();
  398. TogglePlayPause();
  399. }
  400. break;
  401. case FCIDM_MEDIABAND_STOP:
  402. // when player is attached thru mediaBar behavior to script in media content pane,
  403. // we want to give the user a chance to get rid of the script and return to the default media content
  404. // the first click simply stops the player, clicking again within N secs will also navigate
  405. // the content pane to the default URL
  406. if (_idStopTimer == 0)
  407. {
  408. if (_IsProxyRunning())
  409. {
  410. _idStopTimer = SetTimer(_hwnd, 747, 10000, NULL);
  411. }
  412. ResetPlayer();
  413. _OnUserOverrideDisableUI();
  414. }
  415. else
  416. {
  417. // clicked again, navigate media content to default URL
  418. _CleanupStopTimer();
  419. _NavigateContentToDefaultURL();
  420. }
  421. break;
  422. case FCIDM_MEDIABAND_MUTE:
  423. ToggleMute();
  424. break;
  425. }
  426. }
  427. else if (IsEqualGUID(CGID_MediaBar, *pguidCmdGroup))
  428. {
  429. switch (nCmdID)
  430. {
  431. case MBID_PLAY:
  432. if (pvarargIn && pvarargOut)
  433. {
  434. _CleanupStopTimer();
  435. if (_IsProxyRunning())
  436. {
  437. // user clicked on a media link in the main content pane, unfreeze controls!
  438. _OnUserOverrideDisableUI();
  439. _DetachProxies();
  440. _NavigateContentToDefaultURL();
  441. }
  442. if (V_VT(pvarargOut) == VT_BSTR)
  443. {
  444. _strLastUrl = V_BSTR(pvarargOut);
  445. }
  446. if (V_VT(pvarargIn) == VT_BSTR)
  447. {
  448. _strLastMime = V_BSTR(pvarargIn);
  449. }
  450. _fLastUrlIsAutoPlay = TRUE;
  451. // ISSUE: fix this to use the right CmdId & CmdIdGroup, not just zero, to prevent collisions.
  452. // this is an auto-play command
  453. _HandleAutoPlay(pvarargIn, pvarargOut);
  454. hr = S_OK;
  455. }
  456. break;
  457. case MBID_POPOUT:
  458. if (pvarargOut)
  459. {
  460. V_VT(pvarargOut) = VT_BOOL;
  461. V_BOOL(pvarargOut) = _hwndPopup && IsWindowVisible(_hwndPopup);
  462. hr = S_OK;
  463. }
  464. break;
  465. default:
  466. ASSERT(FALSE);
  467. break;
  468. }
  469. }
  470. else
  471. {
  472. hr = SUPERCLASS::Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvarargIn, pvarargOut);
  473. }
  474. }
  475. else
  476. {
  477. hr = SUPERCLASS::Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvarargIn, pvarargOut);
  478. }
  479. return hr;
  480. }
  481. void CMediaBand::_HandleAutoPlay(VARIANTARG *pvarargMime, VARIANTARG *pvarargUrl)
  482. {
  483. // check the mime type argument
  484. if ( (!pvarargMime)
  485. || (VT_BSTR != V_VT(pvarargMime))
  486. || (!V_BSTR(pvarargMime))
  487. || (L'' == (*V_BSTR(pvarargMime))))
  488. {
  489. goto done;
  490. }
  491. // check the Url argument
  492. if ( (!pvarargUrl)
  493. || ( VT_BSTR != V_VT(pvarargUrl))
  494. || (!V_BSTR(pvarargUrl))
  495. || (L'' == (*V_BSTR(pvarargUrl))))
  496. {
  497. goto done;
  498. }
  499. if (EnsurePlayer())
  500. {
  501. // reset this to -1 to indicate we are not playing a mymusic track
  502. _iCurTrack = -1;
  503. #ifdef _USE_MEDIA_MRU
  504. // ISSUE: temp fix for radio protocol. If this is an ASX mimetype, we know it is radio
  505. if (!SHRestricted(REST_NORECENTDOCSHISTORY))
  506. {
  507. CMediaMRU mmru;
  508. mmru.Load(REG_VALUE_MRU_INTERNET);
  509. mmru.Add(V_BSTR(pvarargUrl));
  510. }
  511. #endif // _USE_MEDIA_MRU
  512. if (0 == StrCmpNIW(V_BSTR(pvarargMime), WZ_ASX_MIMETYPE, wcslen(WZ_ASX_MIMETYPE)))
  513. {
  514. _PutUrl(V_BSTR(pvarargUrl), V_BSTR(pvarargMime));
  515. }
  516. else
  517. {
  518. _PutUrl(V_BSTR(pvarargUrl), NULL);
  519. }
  520. TogglePlayPause();
  521. // clear the url to indicate we are handling this url
  522. ::VariantClear(pvarargUrl);
  523. }
  524. else
  525. {
  526. ASSERT(FALSE);
  527. }
  528. done:
  529. ;
  530. }
  531. VOID
  532. CMediaBand::_BeginTimeOutCounter(BOOL fClear /* = TRUE */)
  533. {
  534. _dwStartTime = GetPerfTime();
  535. _lTickCount = 0;
  536. if (TRUE == fClear)
  537. {
  538. _dblLastBufProgress = 0;
  539. _dblLastPlayProgress = 0;
  540. }
  541. }
  542. VOID
  543. CMediaBand::_EndTimeOutCounter()
  544. {
  545. _lTickCount = -1;
  546. }
  547. VOID
  548. CMediaBand::_UpdateTimeOutCounter(double dblCurrBufProgress, double dblCurrPlayProgress)
  549. {
  550. BOOL fTimeOut = FALSE;
  551. // bail if the counter has not been started
  552. if (_lTickCount < 0)
  553. return;
  554. // Order of checking is important here.
  555. // If play progress is increasing then restart the counter
  556. if (dblCurrPlayProgress > _dblLastPlayProgress)
  557. {
  558. _BeginTimeOutCounter(FALSE);
  559. _dblLastPlayProgress = dblCurrPlayProgress;
  560. }
  561. // if buffering progress is increasing then restart the counter
  562. else if (dblCurrBufProgress > _dblLastBufProgress)
  563. {
  564. _BeginTimeOutCounter(FALSE);
  565. _dblLastBufProgress = dblCurrBufProgress;
  566. }
  567. else
  568. {
  569. // both play and buffering progress are stalled, so update the timeout counter
  570. // We poll the system time every POLL_INTERVAL ticks since we tick at a very high rate
  571. // (a tick is each time this function is called)
  572. if ((1 + _lTickCount) == POLL_INTERVAL)
  573. {
  574. DWORD dwCurrentTime = GetPerfTime();
  575. DWORD dwElapsedTime = (dwCurrentTime - _dwStartTime)
  576. + (dwCurrentTime < _dwStartTime ? 0xffffffff : 0); // if timer wraps around 2^32 milliseconds
  577. if (dwElapsedTime >= TIMEOUT_INTERVAL)
  578. {
  579. fTimeOut = TRUE;
  580. }
  581. }
  582. if (fTimeOut)
  583. {
  584. _OnNavigationTimeOut();
  585. }
  586. else
  587. {
  588. // update the poll interval counter and mod it by POLL_INTERVAL
  589. _lTickCount = (1 + _lTickCount) - (static_cast<long>(_lTickCount / POLL_INTERVAL) * POLL_INTERVAL);
  590. }
  591. }
  592. }
  593. VOID
  594. CMediaBand::_OnNavigationTimeOut()
  595. {
  596. _EndTimeOutCounter();
  597. // stop the player and show the timeout message
  598. if (EnsurePlayer())
  599. {
  600. if (VARIANT_FALSE == _pMediaPlayer->isStopped())
  601. {
  602. _pMediaPlayer->Stop();
  603. TogglePlayPause();
  604. // Show timeout error message
  605. TCHAR szText[200];
  606. szText[0] = TEXT('\0');
  607. MLLoadString(IDS_MEDIABAND_NAVTIMEOUT, szText, ARRAYSIZE(szText));
  608. SetStatusText(szText);
  609. }
  610. }
  611. }
  612. STDMETHODIMP
  613. CMediaBand::_PutUrl(LPWSTR pstrUrl, LPWSTR pstrMime)
  614. {
  615. HRESULT hr = E_FAIL;
  616. if (EnsurePlayer())
  617. {
  618. TCHAR szText[200];
  619. szText[0] = TEXT('\0');
  620. SetStatusText(_szConnecting);
  621. hr = _pMediaPlayer->put_type(pstrMime);
  622. if (SUCCEEDED(hr))
  623. {
  624. hr = _pMediaPlayer->put_url(pstrUrl);
  625. if (SUCCEEDED(hr))
  626. {
  627. // start the timeout counter
  628. if (_dblVol!=-1)
  629. {
  630. _pMediaPlayer->put_volume(_dblVol);
  631. }
  632. _pMediaPlayer->put_mute(_fMuted);
  633. _BeginTimeOutCounter();
  634. UpdateBackForwardControls();
  635. SetPlayPause(FALSE);
  636. SetPlayerControl(FCIDM_MEDIABAND_STOP, TRUE);
  637. // make sure we undavise from soon-to-be obsolete player object
  638. _AttachPlayerToProxies(FALSE);
  639. }
  640. }
  641. }
  642. return hr;
  643. }
  644. // *** IInputObject methods ***
  645. HRESULT CMediaBand::TranslateAcceleratorIO(LPMSG pMsg)
  646. {
  647. ASSERT(pMsg);
  648. TraceMsg(TF_ACCESSIBILITY, "CMediaBand::TranslateAcceleratorIO (hwnd=0x%08X) key=%d", _hwnd, pMsg->wParam);
  649. BOOL fHasFocus = ( (_iElement>=0)
  650. || (HasFocusIO() == S_OK)
  651. || _fContentInFocus);
  652. if (fHasFocus && IsVK_CtlTABCycler(pMsg))
  653. {
  654. // Bail on ctl-tab/F6 if one of our guys already has focus
  655. return S_FALSE;
  656. }
  657. // if any child in focus, let them have a shot at it
  658. HRESULT hr = S_FALSE;
  659. if (fHasFocus)
  660. {
  661. if (_iElement >=0)
  662. {
  663. if (_hwndPopup && IsWindowVisible(_hwndPopup) && (pMsg->message==WM_KEYDOWN) && (pMsg->wParam==VK_ESCAPE))
  664. {
  665. DockMediaPlayer();
  666. hr = S_OK;
  667. }
  668. else
  669. {
  670. hr = _pmw[_iElement]->TranslateAccelerator(pMsg);
  671. }
  672. }
  673. else if (_fContentInFocus && _poipao)
  674. {
  675. hr = _poipao->TranslateAccelerator(pMsg);
  676. }
  677. if (hr == S_OK)
  678. {
  679. return S_OK; // handled!!
  680. }
  681. }
  682. hr = S_FALSE;
  683. // try shifting focus to next element
  684. if (IsVK_TABCycler(pMsg))
  685. {
  686. BOOL fReverse = (GetKeyState(VK_SHIFT) < 0);
  687. if (fReverse)
  688. {
  689. // content pane is last tab target, move to last control widget with this backward tab
  690. if (_fContentInFocus)
  691. {
  692. _ContentActivateIO(FALSE, NULL);
  693. if (!(_hwndPopup && IsWindowVisible(_hwndPopup)))
  694. {
  695. _iElement = ARRAYSIZE(_pmw)-1;
  696. }
  697. else
  698. {
  699. return S_FALSE;
  700. }
  701. }
  702. else do
  703. {
  704. _iElement--;
  705. if (_iElement<0)
  706. {
  707. if (_fPopoutHasFocus)
  708. {
  709. _iElement = ARRAYSIZE(_pmw)-1;
  710. }
  711. break;
  712. }
  713. }
  714. while (!ISVALIDWIDGET(_pmw[_iElement]) || (!_pmw[_iElement]->IsEnabled()));
  715. }
  716. else
  717. {
  718. // content pane is last tab target, move away from mediabar with this forward tab
  719. if (_fContentInFocus)
  720. {
  721. _ContentActivateIO(FALSE, NULL);
  722. return S_FALSE;
  723. }
  724. // try next control widget
  725. if (!(_hwndPopup && IsWindowVisible(_hwndPopup)) || _fPopoutHasFocus)
  726. {
  727. if (_iElement<0)
  728. {
  729. _iElement = 0;
  730. }
  731. else do
  732. {
  733. _iElement++;
  734. if (_iElement>=ARRAYSIZE(_pmw))
  735. {
  736. _iElement = _fPopoutHasFocus ? 0 : -1;
  737. break;
  738. }
  739. }
  740. while (!ISVALIDWIDGET(_pmw[_iElement]) || (!_pmw[_iElement]->IsEnabled()));
  741. }
  742. // none of the control widgets claimed focus, try content pane
  743. if (_iElement<0)
  744. {
  745. hr = _ContentActivateIO(TRUE, pMsg);
  746. if (hr == S_OK) {
  747. return S_OK; // handled!!
  748. }
  749. }
  750. }
  751. if (_iElement<0)
  752. {
  753. return S_FALSE;
  754. }
  755. ASSERT(ISVALIDWIDGET(_pmw[_iElement]));
  756. ::SetFocus(_pmw[_iElement]->_hwnd);
  757. return S_OK;
  758. }
  759. return S_FALSE; // unhandled non-tab
  760. }
  761. //------------------------------------------------------------------------
  762. HRESULT
  763. CMediaBand::UIActivateIO(BOOL fActivate, LPMSG pMsg)
  764. {
  765. TraceMsg(TF_ACCESSIBILITY, "CMediaBand::UIActivateIO (hwnd=0x%08X) fActivate=%d", _hwnd, fActivate);
  766. HRESULT hr = S_OK;
  767. // activation:
  768. if (fActivate)
  769. {
  770. if (!(_hwndPopup && IsWindowVisible(_hwndPopup)) || _fPopoutHasFocus)
  771. {
  772. if (_iElement==-1)
  773. {
  774. _ContentActivateIO(FALSE, NULL);
  775. _iElement = 0;
  776. }
  777. if (_pmw[_iElement] && _pmw[_iElement]->_hwnd)
  778. {
  779. ::SetFocus(_pmw[_iElement]->_hwnd);
  780. }
  781. }
  782. else
  783. {
  784. _iElement = -1;
  785. _ContentActivateIO(TRUE, pMsg);
  786. }
  787. IUnknown_OnFocusChangeIS(_punkSite, SAFECAST(this, IInputObject*), TRUE);
  788. }
  789. else
  790. {
  791. _ContentActivateIO(FALSE, NULL);
  792. _iElement = -1;
  793. if (_hwndPopup && IsWindowVisible(_hwndPopup))
  794. {
  795. IUnknown_OnFocusChangeIS(_punkSite, SAFECAST(this, IInputObject*), FALSE);
  796. }
  797. }
  798. return hr;
  799. }
  800. //------------------------------------------------------------------------
  801. HRESULT
  802. CMediaBand::HasFocusIO()
  803. {
  804. HRESULT hr = SHIsChildOrSelf((_hwndPopup && IsWindowVisible(_hwndPopup)) ? _hwndPopup : _hwnd, ::GetFocus());
  805. if (hr==S_FALSE)
  806. {
  807. // Focus might be in the content pane, which won't be a child if the popout is out
  808. hr = SHIsChildOrSelf(_hwndContent, ::GetFocus());
  809. }
  810. return hr;
  811. }
  812. HRESULT CMediaBand::_ContentActivateIO(BOOL fActivate, PMSG pMsg)
  813. {
  814. ASSERT(_hwndContent);
  815. ASSERT(_poipao);
  816. if (_fContentInFocus == fActivate)
  817. {
  818. return S_OK;
  819. }
  820. _fContentInFocus = fActivate;
  821. if (fActivate)
  822. {
  823. _iElement = -1;
  824. }
  825. int iVerb = fActivate ? OLEIVERB_UIACTIVATE : OLEIVERB_INPLACEACTIVATE;
  826. HRESULT hr = S_OK;
  827. hr = OCHost_DoVerb(_hwndContent, iVerb, pMsg);
  828. // OCHost UIActivate is different than IInputObject::UIActivateIO. It
  829. // doesn't do anything with the lpMsg parameter. So, we need to pass
  830. // it to them via TranslateAccelerator. Since the only case we care
  831. // about is when they're getting tabbed into (we want them to highlight
  832. // the first/last link), just do this in the case of a tab. However,
  833. // don't give it to them if it's a ctl-tab. The rule is that you shouldn't
  834. // handle ctl-tab when UI-active (ctl-tab switches between contexts), and
  835. // since Trident is always UI-active (for perf?), they'll always reject
  836. // ctl-tab.
  837. // suppress sending any tabs
  838. if (pMsg && _poipao && IsVK_TABCycler(pMsg) && !IsVK_CtlTABCycler(pMsg))
  839. {
  840. hr = _poipao->TranslateAccelerator(pMsg);
  841. // ignore if translate of tab fails when activating!
  842. if (FAILED(hr) && fActivate) {
  843. hr = S_OK;
  844. }
  845. }
  846. return hr;
  847. }
  848. LRESULT CMediaBand::_OnNotify(LPNMHDR pnm)
  849. {
  850. switch (pnm->code)
  851. {
  852. case OCN_ONUIACTIVATE: // UIActivate
  853. ASSERT(SHIsSameObject(((LPOCNONUIACTIVATEMSG)pnm)->punk, _poipao));
  854. _fContentInFocus = TRUE;
  855. _iElement = -1;
  856. IUnknown_OnFocusChangeIS(_punkSite, SAFECAST(this, IInputObject*), TRUE);
  857. return OCNONUIACTIVATE_HANDLED;
  858. case OCN_ONSETSTATUSTEXT:
  859. {
  860. HRESULT hr = E_FAIL;
  861. IShellBrowser *psb;
  862. hr = QueryService(SID_STopLevelBrowser, IID_PPV_ARG(IShellBrowser, &psb));
  863. if (SUCCEEDED(hr)) {
  864. hr = psb->SetStatusTextSB(((LPOCNONSETSTATUSTEXTMSG)pnm)->pwszStatusText);
  865. psb->Release();
  866. }
  867. }
  868. break;
  869. default:
  870. break;
  871. }
  872. ASSERT(OCNONUIACTIVATE_HANDLED != 0);
  873. return 0;
  874. }
  875. // *** IDeskBand methods ***
  876. HRESULT
  877. CMediaBand::GetBandInfo(DWORD dwBandID, DWORD fViewMode, DESKBANDINFO* pdbi)
  878. {
  879. _dwBandID = dwBandID;
  880. pdbi->dwModeFlags = DBIMF_FIXEDBMP | DBIMF_VARIABLEHEIGHT;
  881. if (pdbi->dwMask & DBIM_MINSIZE)
  882. {
  883. pdbi->ptMinSize.x = 16;
  884. pdbi->ptMinSize.y = 16;
  885. }
  886. if (pdbi->dwMask & DBIM_MAXSIZE)
  887. {
  888. pdbi->ptMaxSize.x = 32000; // random
  889. pdbi->ptMaxSize.y = 32000; // random
  890. }
  891. if (pdbi->dwMask & DBIM_ACTUAL)
  892. {
  893. pdbi->ptActual.x = -1;
  894. pdbi->ptActual.y = -1;
  895. }
  896. if (pdbi->dwMask & DBIM_INTEGRAL)
  897. {
  898. pdbi->ptIntegral.y = 1;
  899. }
  900. MLLoadStringW(IDS_MEDIABANDTEXT, pdbi->wszTitle, ARRAYSIZE(pdbi->wszTitle));
  901. return S_OK;
  902. }
  903. /*** CMediaBand::IPersistStream::**/
  904. HRESULT CMediaBand::GetClassID(CLSID *pClassID)
  905. {
  906. *pClassID = CLSID_MediaBand;
  907. return S_OK;
  908. }
  909. // *** IPersistStream methods ***
  910. HRESULT CMediaBand::Load(IStream *pstm)
  911. {
  912. return S_OK;
  913. }
  914. // *** IPersistStream methods ***
  915. HRESULT CMediaBand::Save(IStream *pstm, BOOL fClearDirty)
  916. {
  917. return S_OK;
  918. }
  919. // *** IOleWindow methods ***
  920. HRESULT CMediaBand::GetWindow(HWND *phwnd)
  921. {
  922. if (!_hwnd)
  923. {
  924. CreateParentPane();
  925. }
  926. if (!_hwndLayout)
  927. {
  928. CreateLayoutPane();
  929. }
  930. if (!_hwndContent)
  931. {
  932. InitContentPane();
  933. }
  934. if (phwnd)
  935. {
  936. *phwnd = _hwnd ;
  937. return S_OK;
  938. }
  939. return SUPERCLASS::GetWindow(phwnd);
  940. }
  941. // *** IDockingWindow methods ***
  942. HRESULT CMediaBand::ShowDW(BOOL fShow)
  943. {
  944. if (!_hwnd)
  945. return S_FALSE; // The window needs to be created first.
  946. _fVideoAdjust = FALSE;
  947. if (fShow)
  948. {
  949. _InitializeMediaUI();
  950. // FEATURE/010228/davidjen uncomment this to suppress MediaBar's title bar
  951. #ifdef _SUPPRESS_MB_TITLEBAR
  952. // hide caption/titlebar
  953. CComQIPtr<IBandSite, &IID_IBandSite> pbs = _punkSite;
  954. if (pbs)
  955. {
  956. BANDSITEINFO bsi;
  957. bsi.dwMask = BSIM_STYLE;
  958. HRESULT hr = pbs->GetBandSiteInfo(&bsi);
  959. if (SUCCEEDED(hr))
  960. {
  961. // suppress caption
  962. bsi.dwStyle |= BSIS_NOCAPTION;
  963. hr = pbs->SetBandSiteInfo(&bsi);
  964. }
  965. }
  966. #endif // _SUPPRESS_MB_TITLEBAR
  967. if (!(_hwndPopup && IsWindowVisible(_hwndPopup)))
  968. {
  969. RECT rcParent, rc;
  970. GetClientRect(_hwnd, &rcParent);
  971. GetClientRect(_hwndLayout, &rc);
  972. if (RECTWIDTH(rcParent) > 0 || RECTHEIGHT(rcParent) > 0)
  973. {
  974. _ResizeChildWindows(_hwndLayout, RECTWIDTH(rc), RECTHEIGHT(rc), TRUE);
  975. SetWindowPos(_hwnd, NULL, 0, 0,RECTWIDTH(rcParent), RECTHEIGHT(rcParent), SWP_SHOWWINDOW | SWP_NOACTIVATE);
  976. RedrawWindow(_hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
  977. }
  978. }
  979. }
  980. else
  981. {
  982. _ShowAllWindows(fShow);
  983. }
  984. if (fShow != _fShow)
  985. {
  986. _fShow = fShow;
  987. _FireEventToProxies(_fShow ? OnShow : OnHide);
  988. }
  989. return CToolBand::ShowDW(fShow);
  990. }
  991. HRESULT CMediaBand::CloseDW(DWORD dwReserved)
  992. {
  993. if (!_hwnd)
  994. return S_FALSE; // The window needs to be created first.
  995. WTSUnRegisterSessionNotification(_hwnd);
  996. DestroyPlayer();
  997. if (_spBrowser)
  998. {
  999. _ConnectToCP(FALSE);
  1000. _spBrowser.Release();
  1001. _poipao.Release();
  1002. }
  1003. if (_hwndLayout && IsWindow(_hwndLayout))
  1004. {
  1005. DestroyWindow(_hwndLayout);
  1006. _hwndLayout = NULL;
  1007. }
  1008. if (_hwndPopup && IsWindow(_hwndPopup))
  1009. {
  1010. DestroyWindow(_hwndPopup);
  1011. _hwndPopup = NULL;
  1012. }
  1013. SUPERCLASS::CloseDW(dwReserved);
  1014. return S_OK;
  1015. }
  1016. //-------------- Interface IElementBehaviorFactory
  1017. //------------------------------------------------------------------------
  1018. STDMETHODIMP CMediaBand::FindBehavior(BSTR bstrBehavior, BSTR bstrBehaviorUrl,
  1019. IElementBehaviorSite* pSite, IElementBehavior** ppBehavior)
  1020. {
  1021. if (ppBehavior == NULL)
  1022. {
  1023. return E_POINTER;
  1024. }
  1025. *ppBehavior = NULL;
  1026. // check namespace and URL
  1027. if (StrCmpIW(bstrBehavior, TEXT("mediaBar")) != 0) {
  1028. return E_NOTIMPL; // don't know this behavior!!
  1029. }
  1030. HRESULT hr = S_OK;
  1031. // create new behavior instance for this HTML pane
  1032. IContentProxy * pProxy = NULL;
  1033. pProxy = CMediaBehavior_CreateInstance(this);
  1034. if (pProxy)
  1035. {
  1036. hr = pProxy->QueryInterface(IID_IElementBehavior, (void**)ppBehavior);
  1037. if (FAILED(hr))
  1038. {
  1039. // make sure we get rid our reference
  1040. removeProxy(pProxy);
  1041. }
  1042. }
  1043. else {
  1044. hr = E_OUTOFMEMORY;
  1045. }
  1046. return hr;
  1047. }
  1048. // IMediaHost
  1049. //------------------------------------------------------------------------
  1050. STDMETHODIMP CMediaBand::getMediaPlayer(IUnknown **ppPlayer)
  1051. {
  1052. if (ppPlayer == NULL)
  1053. return E_POINTER;
  1054. *ppPlayer = NULL;
  1055. if (_pMediaPlayer)
  1056. {
  1057. ITIMEMediaElement *pElem = NULL;
  1058. if (SUCCEEDED(_pMediaPlayer->get_mediaElement(&pElem)))
  1059. {
  1060. *ppPlayer = pElem; // no AddRef, get_mediaElement already did ref counting!!
  1061. }
  1062. }
  1063. return *ppPlayer ? S_OK : S_FALSE;
  1064. }
  1065. //------------------------------------------------------------------------
  1066. STDMETHODIMP CMediaBand::playURL(BSTR bstrURL, BSTR bstrMIME)
  1067. {
  1068. HRESULT hr = _EnsureWMPInstalled();
  1069. if (FAILED(hr))
  1070. {
  1071. return hr;
  1072. }
  1073. CComVariant varMime = bstrMIME;
  1074. CComVariant varUrl = bstrURL;
  1075. _strLastUrl = _strCurrentContentUrl;
  1076. _strLastMime.Empty();
  1077. _fLastUrlIsAutoPlay = FALSE;
  1078. _HandleAutoPlay(&varMime, &varUrl);
  1079. return S_OK;
  1080. }
  1081. //------------------------------------------------------------------------
  1082. STDMETHODIMP CMediaBand::addProxy(IUnknown *punkProxy)
  1083. {
  1084. HRESULT hr = E_POINTER;
  1085. if (punkProxy)
  1086. {
  1087. // add to our array of proxies
  1088. if (_apContentProxies == NULL) {
  1089. _apContentProxies.Create(2);
  1090. }
  1091. if (_apContentProxies == NULL)
  1092. {
  1093. return E_OUTOFMEMORY;
  1094. }
  1095. // want to be sure proxy knows our protocol, also does add ref
  1096. IContentProxy *pProxy = NULL;
  1097. hr = punkProxy->QueryInterface(IID_PPV_ARG(IContentProxy, &pProxy));
  1098. if (SUCCEEDED(hr))
  1099. {
  1100. _apContentProxies.AppendPtr(pProxy);
  1101. }
  1102. }
  1103. return hr;
  1104. }
  1105. //------------------------------------------------------------------------
  1106. STDMETHODIMP CMediaBand::removeProxy(IUnknown *punkProxy)
  1107. {
  1108. if (_apContentProxies == NULL)
  1109. return S_FALSE;
  1110. HRESULT hr = S_FALSE;
  1111. int cnt = _apContentProxies.GetPtrCount();
  1112. for (int i = 0; i < cnt; i++)
  1113. {
  1114. IContentProxy* pProxy = _apContentProxies.GetPtr(i);
  1115. ASSERT(pProxy);
  1116. if (pProxy)
  1117. {
  1118. if (SHIsSameObject(pProxy, punkProxy))
  1119. {
  1120. _apContentProxies.DeletePtr(i);
  1121. pProxy->Release();
  1122. ResetPlayer(); // privacy issue:
  1123. // make sure player is stopped and proxy/behavior in next page cannot access current media
  1124. _fAttached = FALSE; // force reattaching to player once a new behavior is up
  1125. hr = S_OK;
  1126. break;
  1127. }
  1128. }
  1129. }
  1130. return hr;
  1131. }
  1132. // IMediaHost2
  1133. //------------------------------------------------------------------------
  1134. STDMETHODIMP CMediaBand::OnDisableUIChanged(BOOL fDisabled)
  1135. {
  1136. return S_OK;
  1137. }
  1138. //------------------------------------------------------------------------
  1139. void CMediaBand::_AttachPlayerToProxies(BOOL fAttach)
  1140. {
  1141. if (_apContentProxies == NULL)
  1142. return;
  1143. if (_fAttached == fAttach)
  1144. return;
  1145. int cnt = _apContentProxies.GetPtrCount();
  1146. for (int i = 0; i < cnt; i++)
  1147. {
  1148. IContentProxy* pProxy = _apContentProxies.GetPtr(i);
  1149. ASSERT(pProxy);
  1150. if (pProxy)
  1151. {
  1152. HRESULT hr;
  1153. if (fAttach) {
  1154. hr = pProxy->OnCreatedPlayer();
  1155. }
  1156. else {
  1157. pProxy->detachPlayer();
  1158. hr = S_OK;
  1159. }
  1160. if (SUCCEEDED(hr)) {
  1161. _fAttached = fAttach;
  1162. }
  1163. }
  1164. }
  1165. }
  1166. //------------------------------------------------------------------------
  1167. void CMediaBand::_DetachProxies()
  1168. {
  1169. if (_apContentProxies == NULL)
  1170. return;
  1171. int cnt = _apContentProxies.GetPtrCount();
  1172. // need to iterate from last to first, call to removeProxy() will also remove it from DPA!
  1173. for (int i = cnt - 1; i >= 0; i--)
  1174. {
  1175. IContentProxy* pProxy = _apContentProxies.GetPtr(i);
  1176. ASSERT(pProxy);
  1177. if (pProxy)
  1178. {
  1179. removeProxy(pProxy);
  1180. }
  1181. }
  1182. _apContentProxies.Destroy();
  1183. return;
  1184. }
  1185. //------------------------------------------------------------------------
  1186. BOOL CMediaBand::_isUIDisabled()
  1187. {
  1188. if (_apContentProxies == NULL)
  1189. return FALSE;
  1190. int cnt = _apContentProxies.GetPtrCount();
  1191. BOOL fDisabled = FALSE;
  1192. for (int i = 0; i < cnt; i++)
  1193. {
  1194. CComQIPtr<IMediaBehaviorContentProxy, &IID_IMediaBehaviorContentProxy> pProxy = _apContentProxies.GetPtr(i);
  1195. if (pProxy)
  1196. {
  1197. BOOL fQueryDisabled = FALSE;
  1198. pProxy->IsDisableUIRequested(&fQueryDisabled);
  1199. if (fQueryDisabled)
  1200. {
  1201. fDisabled = TRUE;
  1202. break;
  1203. }
  1204. }
  1205. }
  1206. return fDisabled;
  1207. }
  1208. //------------------------------------------------------------------------
  1209. BOOL CMediaBand::_isProxiesNextEnabled()
  1210. {
  1211. if (_apContentProxies == NULL)
  1212. return TRUE;
  1213. int cnt = _apContentProxies.GetPtrCount();
  1214. BOOL fEnabled = TRUE;
  1215. for (int i = 0; i < cnt; i++)
  1216. {
  1217. CComQIPtr<IMediaBehaviorContentProxy, &IID_IMediaBehaviorContentProxy> pProxy = _apContentProxies.GetPtr(i);
  1218. if (pProxy)
  1219. {
  1220. BOOL fQueryEnabled = FALSE;
  1221. pProxy->IsNextEnabled(&fQueryEnabled);
  1222. if (!fQueryEnabled)
  1223. {
  1224. fEnabled = FALSE;
  1225. break;
  1226. }
  1227. }
  1228. }
  1229. return fEnabled;
  1230. }
  1231. //------------------------------------------------------------------------
  1232. void CMediaBand::_OnUserOverrideDisableUI()
  1233. {
  1234. if (_apContentProxies == NULL)
  1235. return;
  1236. int cnt = _apContentProxies.GetPtrCount();
  1237. BOOL fDisabled = FALSE;
  1238. for (int i = 0; i < cnt; i++)
  1239. {
  1240. CComQIPtr<IMediaBehaviorContentProxy, &IID_IMediaBehaviorContentProxy> pProxy = _apContentProxies.GetPtr(i);
  1241. if (pProxy)
  1242. {
  1243. pProxy->OnUserOverrideDisableUI();
  1244. }
  1245. }
  1246. }
  1247. //------------------------------------------------------------------------
  1248. void CMediaBand::_FireEventToProxies(enum contentProxyEvent event)
  1249. {
  1250. if (_apContentProxies == NULL)
  1251. return;
  1252. int cnt = _apContentProxies.GetPtrCount();
  1253. BOOL fDisabled = FALSE;
  1254. for (int i = 0; i < cnt; i++)
  1255. {
  1256. IContentProxy* pProxy = _apContentProxies.GetPtr(i);
  1257. ASSERT(pProxy);
  1258. if (pProxy)
  1259. {
  1260. pProxy->fireEvent(event);
  1261. }
  1262. }
  1263. }
  1264. //------------------------------------------------------------------------
  1265. void CMediaBand::_CleanupStopTimer()
  1266. {
  1267. if (_idStopTimer != 0)
  1268. {
  1269. KillTimer(_hwnd, _idStopTimer);
  1270. _idStopTimer = 0;
  1271. // make sure user hasn't initiated another media action yet!!!
  1272. SetPlayerControl(FCIDM_MEDIABAND_STOP, FALSE);
  1273. }
  1274. }
  1275. //------------------------------------------------------------------------
  1276. HRESULT CMediaBand::_EnsureWMPInstalled(BOOL fShowErrorMsg)
  1277. {
  1278. HRESULT hr = S_OK;
  1279. if (!CMediaBarUtil::IsWMP7OrGreaterInstalled())
  1280. {
  1281. // ISSUE: assumption that XP already has matching WMP version
  1282. if (!IsOS(OS_WHISTLERORGREATER))
  1283. {
  1284. // try to web-jit WMP8.
  1285. uCLSSPEC ucs;
  1286. QUERYCONTEXT qc = { 0 };
  1287. ucs.tyspec = TYSPEC_CLSID;
  1288. ucs.tagged_union.clsid = CLSID_JITWMP8;
  1289. hr = FaultInIEFeature(_hwnd, &ucs, &qc, FIEF_FLAG_FORCE_JITUI);
  1290. }
  1291. if (!CMediaBarUtil::IsWMP7OrGreaterInstalled())
  1292. {
  1293. // still no WMP, user might have aborted or install failed
  1294. if (fShowErrorMsg)
  1295. {
  1296. MLShellMessageBox(_hwnd, MAKEINTRESOURCE(IDS_MEDIABAND_NOWMP7), MAKEINTRESOURCE(IDS_MEDIABAND_NOWMP7TITLE), MB_OK);
  1297. }
  1298. hr = E_UNEXPECTED;
  1299. }
  1300. }
  1301. return hr;
  1302. }
  1303. // *** IBrowserBand methods ***
  1304. STDMETHODIMP CMediaBand::GetObjectBB(REFIID riid, LPVOID *ppv)
  1305. {
  1306. return _spBrowser ? _spBrowser->QueryInterface(riid, ppv) : E_UNEXPECTED;
  1307. }
  1308. // *** IBandNavigate methods ***
  1309. STDMETHODIMP CMediaBand::Select(LPCITEMIDLIST pidl)
  1310. {
  1311. _strDeferredURL.Empty(); // cancel any deferred navigation (usually during initial launch of mediabar
  1312. return NavigateContentPane(pidl);
  1313. }
  1314. HRESULT CMediaBand_CreateInstance(IUnknown *punkOuter, IUnknown **ppunk, LPCOBJECTINFO poi)
  1315. {
  1316. // aggregation checking is handled in class factory
  1317. CMediaBand * pmb = new CMediaBand();
  1318. if (!pmb)
  1319. return E_OUTOFMEMORY;
  1320. // if you change this cast, fix up CChannelBand_CreateInstance
  1321. *ppunk = SAFECAST(pmb, IDeskBand *);
  1322. return S_OK;
  1323. }
  1324. //+-------------------------------------------------------------------------
  1325. // Creates Player
  1326. //--------------------------------------------------------------------------
  1327. BOOL
  1328. CMediaBand::EnsurePlayer()
  1329. {
  1330. BOOL fResult = _pMediaPlayer ? TRUE : FALSE;
  1331. if (!fResult)
  1332. {
  1333. fResult = CreatePlayer();
  1334. }
  1335. return fResult && _pMediaPlayer;
  1336. }
  1337. BOOL
  1338. CMediaBand::CreatePlayer()
  1339. {
  1340. HRESULT hr = CMediaBarPlayer_CreateInstance(IID_PPV_ARG(IMediaBarPlayer, &_pMediaPlayer));
  1341. if (SUCCEEDED(hr))
  1342. {
  1343. hr = _pMediaPlayer->Init(_hwndLayout, SAFECAST(this, IMediaBar*));
  1344. if (SUCCEEDED(hr))
  1345. {
  1346. hr = _pMediaPlayer->GetVideoHwnd(&_hwndVideo);
  1347. }
  1348. if (FAILED(hr))
  1349. {
  1350. ASSERT(FALSE);
  1351. DestroyPlayer();
  1352. }
  1353. }
  1354. return SUCCEEDED(hr);
  1355. }
  1356. VOID CMediaBand::DestroyPlayer()
  1357. {
  1358. _AttachPlayerToProxies(FALSE);
  1359. if (_pMediaPlayer)
  1360. {
  1361. _pMediaPlayer->DeInit();
  1362. _pMediaPlayer->Release();
  1363. _pMediaPlayer = NULL;
  1364. }
  1365. _DetachProxies();
  1366. }
  1367. // notifications from the player
  1368. STDMETHODIMP CMediaBand::Notify(long lReason)
  1369. {
  1370. HRESULT hr = E_FAIL;
  1371. if (EnsurePlayer())
  1372. {
  1373. // update play/pause state
  1374. TogglePlayPause();
  1375. if (!_fAttached) {
  1376. _AttachPlayerToProxies(TRUE);
  1377. }
  1378. switch (lReason)
  1379. {
  1380. case DISPID_TIMESTATE_PROGRESS:
  1381. {
  1382. double dblProgress = _pMediaPlayer->GetTrackProgress();
  1383. if (!_fSeeking)
  1384. {
  1385. SetSeekPos(static_cast<float>(dblProgress));
  1386. }
  1387. // Update download/buffering progress, if any
  1388. {
  1389. ProgressType ProgType = PT_None;
  1390. double dblBufProg = 0.0;
  1391. hr = _pMediaPlayer->GetBufProgress(&dblBufProg, &ProgType);
  1392. // S_OK only means that there's some buffering going on
  1393. if ((hr == S_OK) && dblBufProg >= 0.0 && dblBufProg < 100.0)
  1394. {
  1395. SetStatusText(_szConnecting);
  1396. }
  1397. else
  1398. {
  1399. ShowPlayingStatus();
  1400. }
  1401. if (TRUE == _pMediaPlayer->IsStreaming())
  1402. {
  1403. // if this is streamed then substitute progress with track time
  1404. // since progress is not meaningful
  1405. dblProgress = _pMediaPlayer->GetTrackTime();
  1406. _UpdateTimeOutCounter(dblBufProg, dblProgress);
  1407. }
  1408. else
  1409. {
  1410. _UpdateTimeOutCounter(dblBufProg, dblProgress);
  1411. }
  1412. }
  1413. }
  1414. break; // case DISPID_TIMESTATE_PROGRESS
  1415. case MEDIACOMPLETE:
  1416. case TRACK_CHANGE:
  1417. _fPlaying = TRUE;
  1418. ShowPlayingStatus(TRUE);
  1419. AdjustVideoHeight(TRUE);
  1420. _EndTimeOutCounter();
  1421. SetPlayPause(_pMediaPlayer->IsPausePossible());
  1422. UpdateBackForwardControls();
  1423. if (ISVALIDWIDGET(_pmwSeek))
  1424. {
  1425. _pmwSeek->SetState(_pMediaPlayer->IsSeekPossible());
  1426. }
  1427. break;
  1428. case MEDIA_TRACK_FINISHED:
  1429. if (_iCurTrack != -1)
  1430. {
  1431. PlayNextTrack();
  1432. }
  1433. else
  1434. {
  1435. _fSeeking = FALSE;
  1436. ResetPlayer();
  1437. }
  1438. break;
  1439. case DISPID_TIMEMEDIAELEMENT_TITLE:
  1440. _OnTitleChange();
  1441. ShowPlayingStatus(TRUE);
  1442. break;
  1443. } // switch (lReason)
  1444. hr = S_OK;
  1445. } // end if
  1446. return hr;
  1447. }
  1448. STDMETHODIMP CMediaBand::OnMediaError(int iErrCode)
  1449. {
  1450. _EndTimeOutCounter();
  1451. if (-1 == iErrCode)
  1452. {
  1453. // if there is no rich erro info display the generic error message
  1454. TCHAR szText[MAX_PATH];
  1455. szText[0] = TEXT('\0');
  1456. MLLoadString(IDS_MEDIABAND_INVALIDFILE, szText, ARRAYSIZE(szText));
  1457. SetStatusText(szText);
  1458. }
  1459. else
  1460. {
  1461. // ISSUE: to do: display the appropriate error message
  1462. ASSERT(FALSE);
  1463. }
  1464. #ifdef PLAY_INDEFAULT
  1465. // delegate the playback to the default player (fix for 24146)
  1466. {
  1467. //
  1468. // ISSUE: What should we do for errors within a playlist??????
  1469. //
  1470. CComBSTR sbstrUrl;
  1471. if (EnsurePlayer() && SUCCEEDED(_pMediaPlayer->get_url(&sbstrUrl)) && (NULL != sbstrUrl.m_str))
  1472. {
  1473. _OpenInDefaultPlayer(sbstrUrl);
  1474. }
  1475. }
  1476. #endif
  1477. return S_OK;
  1478. }
  1479. //+-------------------------------------------------------------------------
  1480. // Handler for property change notification
  1481. //--------------------------------------------------------------------------
  1482. void CMediaBand::_OnTitleChange()
  1483. {
  1484. // The status text and playlist menu should be updated here
  1485. }
  1486. //+-------------------------------------------------------------------------
  1487. // Resize the video
  1488. //--------------------------------------------------------------------------
  1489. void CMediaBand::_ResizeVideo(LONG* plWidth, LONG* plHeight)
  1490. {
  1491. if (EnsurePlayer() && _hwndVideo && ::IsWindow(_hwndVideo))
  1492. {
  1493. _pMediaPlayer->Resize(plHeight, plWidth, FALSE);
  1494. }
  1495. }
  1496. //+-------------------------------------------------------------------------
  1497. // Redraw/show/hide the video window only if something has changed
  1498. //--------------------------------------------------------------------------
  1499. VOID
  1500. CMediaBand::AdjustVideoHeight(BOOL fForceResize)
  1501. {
  1502. VARIANT_BOOL vbHasVisual = VARIANT_FALSE;
  1503. CComPtr<ITIMEMediaElement> spMediaElem;
  1504. if (_pMediaPlayer && SUCCEEDED(_pMediaPlayer->get_mediaElement(&spMediaElem)))
  1505. {
  1506. // Show/hide the video display window
  1507. if (SUCCEEDED(spMediaElem->get_hasVisual(&vbHasVisual)))
  1508. {
  1509. BOOL fVideo = (VARIANT_TRUE == vbHasVisual ? TRUE : FALSE) && _fPlaying;
  1510. if (fVideo)
  1511. {
  1512. if (!IsWindowVisible(_hwndVideo) && !_fIsVideo)
  1513. {
  1514. ShowWindow(_hwndVideo, SW_SHOW);
  1515. _fVideoAdjust = TRUE;
  1516. _fIsVideo = TRUE;
  1517. }
  1518. }
  1519. else
  1520. {
  1521. if (IsWindowVisible(_hwndVideo) && _fIsVideo)
  1522. {
  1523. _fVideoAdjust = TRUE;
  1524. ShowWindow(_hwndVideo, SW_HIDE);
  1525. _fIsVideo = FALSE;
  1526. }
  1527. }
  1528. if (!_fVideoAdjust && fForceResize)
  1529. {
  1530. _fVideoAdjust = TRUE;
  1531. }
  1532. // redraw only if something has changed, so that this function can be called very often
  1533. // (e.g. from Notify) without causing excessive drawing.
  1534. if (_fVideoAdjust)
  1535. {
  1536. _fVideoAdjust = FALSE;
  1537. if (_hwndPopup && IsWindowVisible(_hwndPopup))
  1538. {
  1539. LONG lHeight = GetPopoutHeight(TRUE, _sizeVideo.cx);
  1540. SetWindowPos(_hwndPopup, HWND_TOPMOST, 0, 0, _sizeLayout.cx,
  1541. lHeight, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE);
  1542. InvalidateRect(_hwndPopup, NULL, TRUE);
  1543. ShowWindow(_hwndPopup, SW_SHOW);
  1544. UpdateWindow(_hwndPopup);
  1545. }
  1546. else
  1547. {
  1548. RECT rcParent;
  1549. GetClientRect(_hwnd, &rcParent);
  1550. LONG lHeight = RECTHEIGHT(rcParent);
  1551. lHeight = GetLayoutHeight();
  1552. AdjustLayout(RECTWIDTH(rcParent), lHeight);
  1553. SendMessage(_hwnd, WM_SIZE, (WPARAM)0, (LPARAM) MAKELONG(RECTWIDTH(rcParent), lHeight));
  1554. }
  1555. }
  1556. }
  1557. }
  1558. }
  1559. VOID
  1560. CMediaBand::AdjustLayout(LONG_PTR lWidth, LONG_PTR lHeight)
  1561. {
  1562. RECT rcClient;
  1563. if (!(_hwndPopup && IsWindowVisible(_hwndPopup)))
  1564. {
  1565. GetClientRect(_hwnd, &rcClient);
  1566. if (lWidth<=MIN_WINDOW_WIDTH)
  1567. {
  1568. if (RECTWIDTH(rcClient) < MIN_WINDOW_WIDTH)
  1569. lWidth = MIN_WINDOW_WIDTH ;
  1570. else
  1571. lWidth = RECTWIDTH(rcClient);
  1572. }
  1573. if (lHeight<=MIN_WINDOW_HEIGHT)
  1574. {
  1575. if (RECTHEIGHT(rcClient) < MIN_WINDOW_HEIGHT)
  1576. lHeight = MIN_WINDOW_HEIGHT ;
  1577. else
  1578. lHeight = RECTHEIGHT(rcClient);
  1579. }
  1580. }
  1581. _ResizeChildWindows(_hwndLayout, (LONG)lWidth, (LONG)lHeight, TRUE);
  1582. }
  1583. // IServiceProvider implementation
  1584. HRESULT CMediaBand::QueryService(REFGUID guidService, REFIID riid, void ** ppvObj)
  1585. {
  1586. HRESULT hr = E_UNEXPECTED;
  1587. if (IsEqualIID(guidService, SID_SMediaBar))
  1588. {
  1589. hr = QueryInterface(riid, ppvObj);
  1590. }
  1591. else if (IsEqualIID(guidService, SID_SMediaBarSync))
  1592. {
  1593. hr = QueryInterface(riid, ppvObj);
  1594. }
  1595. else if (IsEqualGUID(guidService, SID_SElementBehaviorFactory))
  1596. {
  1597. hr = QueryInterface(riid, ppvObj);
  1598. }
  1599. else if (IsEqualGUID(guidService, SID_STimeContent))
  1600. {
  1601. hr = QueryInterface(riid, ppvObj);
  1602. }
  1603. else
  1604. {
  1605. hr = SUPERCLASS::QueryService(guidService, riid, ppvObj);
  1606. }
  1607. return hr;
  1608. }
  1609. STDMETHODIMP
  1610. CMediaBand::_TogglePause()
  1611. {
  1612. HRESULT hr = E_FAIL;
  1613. if (EnsurePlayer())
  1614. {
  1615. if (VARIANT_TRUE == _pMediaPlayer->isPaused())
  1616. {
  1617. _fUserPaused = FALSE;
  1618. if (SUCCEEDED(_pMediaPlayer->Resume()))
  1619. {
  1620. _BeginTimeOutCounter();
  1621. hr = S_OK;
  1622. }
  1623. }
  1624. else
  1625. {
  1626. _fUserPaused = TRUE;
  1627. hr = _pMediaPlayer->Pause();
  1628. if (SUCCEEDED(hr))
  1629. {
  1630. _EndTimeOutCounter();
  1631. hr = S_OK;
  1632. }
  1633. }
  1634. TogglePlayPause();
  1635. }
  1636. return hr;
  1637. }
  1638. //+-------------------------------------------------------------------------
  1639. // Creates and shows buttons
  1640. //--------------------------------------------------------------------------
  1641. HRESULT
  1642. CMediaBand::CreateControls()
  1643. {
  1644. // _pmwPlay
  1645. _pmw[MW_PLAY] = CMediaWidgetButton_CreateInstance(_hwndLayout, 31, 33, FCIDM_MEDIABAND_PLAY, IDB_MEDIABAND_PLAY, IDB_MEDIABAND_PAUSE, IDS_MEDIABAND_PLAY, IDS_MEDIABAND_PAUSE);
  1646. // _pmwStop
  1647. _pmw[MW_STOP] = CMediaWidgetButton_CreateInstance(_hwndLayout, 18, 33, FCIDM_MEDIABAND_STOP, IDB_MEDIABAND_STOP, 0, IDS_MEDIABAND_STOP);
  1648. // _pmwBack
  1649. _pmw[MW_BACK] = CMediaWidgetButton_CreateInstance(_hwndLayout, 22, 16, FCIDM_MEDIABAND_PREVIOUS, IDB_MEDIABAND_BACK, 0, IDS_MEDIABAND_BACK);
  1650. // _pmwNext
  1651. _pmw[MW_NEXT] = CMediaWidgetButton_CreateInstance(_hwndLayout, 22, 16, FCIDM_MEDIABAND_NEXT, IDB_MEDIABAND_NEXT, 0, IDS_MEDIABAND_NEXT);
  1652. _pmw[MW_MUTE] = new CMediaWidgetToggle(_hwndLayout, 22, 16);
  1653. if (_pmwMute)
  1654. {
  1655. HRESULT hr = _pmwMute->Initialize(FCIDM_MEDIABAND_MUTE, IDS_MEDIABAND_UNMUTE, IDS_MEDIABAND_MUTE);
  1656. if (SUCCEEDED(hr))
  1657. {
  1658. hr = _pmwMute->SetImageList(IDB_MEDIABAND_MUTE);
  1659. }
  1660. if (SUCCEEDED(hr))
  1661. {
  1662. hr = _pmwMute->SetAlternateImageList(IDB_MEDIABAND_MUTE);
  1663. }
  1664. _pmwMute->SetState(FALSE);
  1665. if (FAILED(hr))
  1666. {
  1667. delete _pmwMute;
  1668. _pmw[MW_MUTE] = NULL;
  1669. }
  1670. }
  1671. _pmw[MW_OPTIONS] = new CMediaWidgetOptions(_hwndLayout, 16, 16);
  1672. if (_pmwOptions)
  1673. {
  1674. HRESULT hr = _pmwOptions->Initialize(FCIDM_MEDIABAND_MUTE, IDS_MEDIABAND_UNMUTE, IDS_MEDIABAND_MUTE);
  1675. if (FAILED(hr))
  1676. {
  1677. delete _pmwOptions;
  1678. _pmw[MW_OPTIONS] = NULL;
  1679. }
  1680. }
  1681. // _pmwPop
  1682. _pmw[MW_POP] = CMediaWidgetButton_CreateInstance(_hwndLayout, 19, 20, FCIDM_MEDIABAND_POPOUT, IDB_MEDIABAND_POPOUT, IDB_MEDIABAND_POPIN, IDS_MEDIABAND_UNDOCK, IDS_MEDIABAND_DOCK);
  1683. return S_OK;
  1684. }
  1685. HRESULT
  1686. CMediaBand::CreateSeekBar()
  1687. {
  1688. DWORD dwWindowStyles = WS_TABSTOP | WS_VISIBLE | WS_CHILD | TBS_NOTICKS | TBS_FIXEDLENGTH;
  1689. DWORD dwExStyle = WS_EX_TRANSPARENT;
  1690. _hwndSeek = CreateWindowEx(dwExStyle, TRACKBAR_CLASS, NULL, dwWindowStyles,
  1691. 0, 0, 0, 0, _hwndLayout, (HMENU) FCIDM_MEDIABAND_SEEK, HINST_THISDLL, NULL);
  1692. if (_hwndSeek)
  1693. {
  1694. if (SetProp(_hwndSeek, c_szMediaBandProp, this))
  1695. {
  1696. SetWindowLongPtr(_hwndSeek, GWLP_USERDATA, (LPARAM)(WNDPROC)(GetWindowLongPtr(_hwndSeek, GWLP_WNDPROC)));
  1697. SetWindowLongPtr(_hwndSeek, GWLP_WNDPROC, (LPARAM)s_SeekWndSubClassProc);
  1698. }
  1699. SendMessage(_hwndSeek, TBM_SETRANGE, (WPARAM)TRUE , (LPARAM)MAKELONG(0, 100)); // min. & max. positions
  1700. SendMessage(_hwndSeek, TBM_SETPAGESIZE, 0, (LPARAM)4); // new page size
  1701. SendMessage(_hwndSeek, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)0);
  1702. // ISSUE: For some reason, the length of the trackbar slider is screwed up, and the rect returned by the slider is half the actual width
  1703. SendMessage(_hwndSeek, TBM_SETTHUMBLENGTH, (WPARAM)VOLUME_GRIPPER_LENGTH*2, 0);
  1704. _himlSeekBack = ImageList_LoadImage(HINST_THISDLL, MAKEINTRESOURCE(IDB_MEDIABAND_SEEKBACK), SEEK_PART_WIDTH, 0, crMask,
  1705. IMAGE_BITMAP, LR_CREATEDIBSECTION);
  1706. _himlSeekFill = ImageList_LoadImage(HINST_THISDLL, MAKEINTRESOURCE(IDB_MEDIABAND_SEEKFILL), SEEK_PART_WIDTH, 0, crMask,
  1707. IMAGE_BITMAP, LR_CREATEDIBSECTION);
  1708. _pmw[MW_SEEK] = new CMediaWidgetSeek();
  1709. if (_pmwSeek)
  1710. {
  1711. _pmwSeek->Initialize(_hwndSeek);
  1712. }
  1713. Comctl32_SetDPIScale(_hwndSeek);
  1714. ShowWindow(_hwndSeek, SW_SHOW);
  1715. return S_OK;
  1716. }
  1717. else
  1718. {
  1719. return E_FAIL;
  1720. }
  1721. }
  1722. HRESULT
  1723. CMediaBand::CreateVolumeControl()
  1724. {
  1725. DWORD dwWindowStyles = WS_TABSTOP | WS_VISIBLE | WS_CHILD | TBS_NOTICKS | TBS_TOOLTIPS;
  1726. DWORD dwExStyle = WS_EX_TRANSPARENT;
  1727. _hwndVolume = CreateWindowEx(dwExStyle, TRACKBAR_CLASS, NULL, dwWindowStyles,
  1728. 0, 0, 0, 0, _hwndLayout, (HMENU) FCIDM_MEDIABAND_VOLUME, HINST_THISDLL, NULL);
  1729. if (_hwndVolume)
  1730. {
  1731. if (SetProp(_hwndVolume, c_szMediaBandProp, this))
  1732. {
  1733. SetWindowLongPtr(_hwndVolume, GWLP_USERDATA, (LPARAM)(WNDPROC)(GetWindowLongPtr(_hwndVolume, GWLP_WNDPROC)));
  1734. SetWindowLongPtr(_hwndVolume, GWLP_WNDPROC, (LPARAM)s_VolumeWndSubClassProc);
  1735. }
  1736. SendMessage(_hwndVolume, TBM_SETRANGE, (WPARAM)TRUE , (LPARAM)MAKELONG(0, 100)); // min. & max. positions
  1737. SendMessage(_hwndVolume, TBM_SETPAGESIZE, 0, (LPARAM) 4); // new page size
  1738. SendMessage(_hwndVolume, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)50);
  1739. ShowWindow(_hwndVolume, SW_SHOW);
  1740. _himlVolumeBack = ImageList_LoadImage(HINST_THISDLL, MAKEINTRESOURCE(IDB_MEDIABAND_VOLBKGND), VOLUME_BITMAP_WIDTH, 0, crMask,
  1741. IMAGE_BITMAP, LR_CREATEDIBSECTION);
  1742. _himlVolumeFill = ImageList_LoadImage(HINST_THISDLL, MAKEINTRESOURCE(IDB_MEDIABAND_VOLFILL), VOLUME_BITMAP_WIDTH, 0, crMask,
  1743. IMAGE_BITMAP, LR_CREATEDIBSECTION);
  1744. _himlGripper = ImageList_LoadImage(HINST_THISDLL, MAKEINTRESOURCE(IDB_MEDIABAND_VOLTAB), VOLUME_GRIPPER_LENGTH, 0, crMask,
  1745. IMAGE_BITMAP, LR_CREATEDIBSECTION);
  1746. _pmw[MW_VOLUME] = new CMediaWidgetVolume;
  1747. if (_pmwVolume)
  1748. {
  1749. _pmwVolume->Initialize(_hwndVolume);
  1750. }
  1751. return S_OK;
  1752. }
  1753. else
  1754. {
  1755. return E_FAIL;
  1756. }
  1757. }
  1758. HRESULT
  1759. CMediaBand::CreateLayoutPane()
  1760. {
  1761. if (!_hwndLayout)
  1762. {
  1763. WNDCLASS wndclass = { 0 };
  1764. wndclass.style = CS_PARENTDC; // | CS_HREDRAW | CS_VREDRAW;
  1765. wndclass.lpfnWndProc = s_LayoutWndProc;
  1766. wndclass.hInstance = MLGetHinst();
  1767. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  1768. wndclass.lpszClassName = c_szMediaBarLayoutClassName;
  1769. SHRegisterClass(&wndclass);
  1770. _hwndLayout = CreateWindowEx(WS_EX_CONTROLPARENT, c_szMediaBarLayoutClassName, NULL,
  1771. WS_TABSTOP | WS_VISIBLE | WS_CHILD,
  1772. CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, _hwnd, NULL, MLGetHinst(), (void *)this);
  1773. if (_hwndLayout == NULL)
  1774. {
  1775. ASSERT(FALSE);
  1776. return E_FAIL;
  1777. }
  1778. else
  1779. {
  1780. ::ShowWindow(_hwndLayout, SW_SHOW);
  1781. }
  1782. }
  1783. return S_OK;
  1784. }
  1785. #define BACKGROUND_WIDTH (240/3)
  1786. #define BACKGROUND_TOP 12
  1787. #define BACKGROUND_MIDDLE 2
  1788. #define BACKGROUND_BOTTOM 55
  1789. VOID CMediaBand::DrawBackground(HDC hdc, HWND hwnd)
  1790. {
  1791. if (_fHiColour)
  1792. {
  1793. HDC hdcSrc = CreateCompatibleDC(hdc);
  1794. if (hdcSrc)
  1795. {
  1796. if (_hbmpBackground)
  1797. {
  1798. RECT rc;
  1799. if (GetClientRect(hwnd, &rc))
  1800. {
  1801. SelectObject(hdcSrc, _hbmpBackground);
  1802. UINT xTra = 0;
  1803. if (g_bRunOnMemphis && IS_WINDOW_RTL_MIRRORED(_hwnd))
  1804. {
  1805. rc.right++;
  1806. xTra++;
  1807. }
  1808. // We have 9 regions to paint. First we'll bitblt the corners, and then we'll do middle sections, which can be stretched without
  1809. // loss of fidelity in a given direction.
  1810. // |A|B|C|
  1811. // |D|E|F|
  1812. // |G|H|I|
  1813. // Corners are bitblted
  1814. // A
  1815. BitBlt(hdc, rc.left, rc.top, BACKGROUND_WIDTH, BACKGROUND_TOP, hdcSrc, 0, 0, SRCCOPY);
  1816. // C
  1817. BitBlt(hdc, max(rc.right-BACKGROUND_WIDTH, rc.left+BACKGROUND_WIDTH), rc.top, BACKGROUND_WIDTH, BACKGROUND_TOP, hdcSrc, 2*BACKGROUND_WIDTH, 0, SRCCOPY);
  1818. // G
  1819. BitBlt(hdc, rc.left, max(rc.bottom-BACKGROUND_BOTTOM, rc.top+BACKGROUND_TOP), BACKGROUND_WIDTH, BACKGROUND_BOTTOM, hdcSrc, 0, BACKGROUND_TOP+BACKGROUND_MIDDLE, SRCCOPY);
  1820. // I
  1821. BitBlt(hdc, max(rc.right-BACKGROUND_WIDTH, rc.left+BACKGROUND_WIDTH), max(rc.bottom-BACKGROUND_BOTTOM, rc.top+BACKGROUND_TOP), BACKGROUND_WIDTH*2, BACKGROUND_BOTTOM, hdcSrc, BACKGROUND_WIDTH*2, BACKGROUND_TOP+BACKGROUND_MIDDLE, SRCCOPY);
  1822. // Middles are all repeated/stetched
  1823. if (rc.right-BACKGROUND_WIDTH > rc.left+BACKGROUND_WIDTH)
  1824. {
  1825. // B
  1826. StretchBlt(hdc, rc.left+BACKGROUND_WIDTH, rc.top, RECTWIDTH(rc)-2*BACKGROUND_WIDTH+xTra, BACKGROUND_TOP, hdcSrc, BACKGROUND_WIDTH, 0, BACKGROUND_WIDTH, BACKGROUND_TOP, SRCCOPY);
  1827. // H
  1828. StretchBlt(hdc, rc.left+BACKGROUND_WIDTH, max(rc.bottom-BACKGROUND_BOTTOM, rc.top+BACKGROUND_TOP), RECTWIDTH(rc)-2*BACKGROUND_WIDTH+xTra, BACKGROUND_BOTTOM, hdcSrc, BACKGROUND_WIDTH, BACKGROUND_TOP+BACKGROUND_MIDDLE, BACKGROUND_WIDTH, BACKGROUND_BOTTOM, SRCCOPY);
  1829. }
  1830. if (rc.bottom-BACKGROUND_BOTTOM > rc.top+BACKGROUND_TOP)
  1831. {
  1832. // D
  1833. StretchBlt(hdc, rc.left, rc.top+BACKGROUND_TOP, BACKGROUND_WIDTH, RECTHEIGHT(rc)-BACKGROUND_TOP-BACKGROUND_BOTTOM,
  1834. hdcSrc, 0, BACKGROUND_TOP, BACKGROUND_WIDTH, BACKGROUND_MIDDLE, SRCCOPY);
  1835. // F
  1836. StretchBlt(hdc, max(rc.right-BACKGROUND_WIDTH, rc.left+BACKGROUND_WIDTH), rc.top+BACKGROUND_TOP, BACKGROUND_WIDTH, RECTHEIGHT(rc)-BACKGROUND_TOP-BACKGROUND_BOTTOM,
  1837. hdcSrc, BACKGROUND_WIDTH*2, BACKGROUND_TOP, BACKGROUND_WIDTH, BACKGROUND_MIDDLE, SRCCOPY);
  1838. // E
  1839. // This section is one solid colour.
  1840. if (rc.right-BACKGROUND_WIDTH > rc.left+BACKGROUND_WIDTH)
  1841. {
  1842. RECT rc2;
  1843. rc2.left = rc.left+BACKGROUND_WIDTH;
  1844. rc2.right = rc.right-BACKGROUND_WIDTH;
  1845. rc2.top = rc.top+BACKGROUND_TOP;
  1846. rc2.bottom = rc.bottom-BACKGROUND_BOTTOM;
  1847. SHFillRectClr(hdc, &rc2, COLOR_BKGNDMIDDLE);
  1848. }
  1849. }
  1850. }
  1851. }
  1852. DeleteDC(hdcSrc);
  1853. }
  1854. }
  1855. else
  1856. {
  1857. RECT rc;
  1858. if (GetClientRect(hwnd, &rc))
  1859. {
  1860. SHFillRectClr(hdc, &rc, COLOR_BKGND16);
  1861. }
  1862. }
  1863. if (_hwndVideo && IsWindowVisible(_hwndVideo))
  1864. {
  1865. RedrawWindow(_hwndVideo, NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE);
  1866. }
  1867. }
  1868. // WndProc for main window to go in rebar
  1869. LRESULT CALLBACK CMediaBand::s_LayoutWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1870. {
  1871. CMediaBand* pmb = reinterpret_cast<CMediaBand *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
  1872. if (msg==WM_CREATE)
  1873. {
  1874. SetWindowLongPtr(hWnd, GWLP_USERDATA, (reinterpret_cast<LONG_PTR>((reinterpret_cast<CREATESTRUCT *>(lParam))->lpCreateParams)));
  1875. return 0;
  1876. }
  1877. else if (pmb)
  1878. {
  1879. switch (msg)
  1880. {
  1881. case WM_PAINT:
  1882. {
  1883. break;
  1884. }
  1885. case WM_ERASEBKGND:
  1886. pmb->DrawBackground((HDC)wParam, hWnd);
  1887. return TRUE;
  1888. case WM_SIZE:
  1889. if ((LONG)LOWORD(lParam) <= 0 || (LONG)HIWORD(lParam) <= 0 )
  1890. break;
  1891. pmb->AdjustLayout(LOWORD(lParam), HIWORD(lParam));
  1892. break;
  1893. case WM_SYSCOLORCHANGE:
  1894. case WM_WININICHANGE:
  1895. {
  1896. BOOL fNewColours = (SHGetCurColorRes() > 8);
  1897. if (fNewColours!=pmb->_fHiColour)
  1898. {
  1899. pmb->SwitchBitmaps(fNewColours);
  1900. }
  1901. pmb->AdjustVideoHeight(TRUE);
  1902. }
  1903. break;
  1904. case WM_VSCROLL:
  1905. case WM_HSCROLL:
  1906. if ((HWND)lParam == pmb->_hwndSeek)
  1907. {
  1908. SendMessage(pmb->_hwndSeek, msg, wParam, lParam);
  1909. }
  1910. else if ((HWND)lParam == pmb->_hwndVolume)
  1911. {
  1912. SendMessage(pmb->_hwndVolume, msg, wParam, lParam);
  1913. }
  1914. break;
  1915. case WM_NOTIFY:
  1916. {
  1917. LRESULT lres;
  1918. if (pmb->OnNotify((LPNMHDR)lParam, &lres))
  1919. {
  1920. return lres;
  1921. }
  1922. break;
  1923. }
  1924. break;
  1925. case WM_COMMAND:
  1926. {
  1927. LRESULT lres;
  1928. if (pmb->OnWinEvent(hWnd, msg, wParam, lParam, &lres) == S_OK)
  1929. return lres;
  1930. }
  1931. break;
  1932. }
  1933. }
  1934. return DefWindowProc(hWnd, msg, wParam, lParam);
  1935. }
  1936. HRESULT CMediaBand::CreateParentPane()
  1937. {
  1938. if (!_hwnd)
  1939. {
  1940. WNDCLASS wndclass = { 0 };
  1941. wndclass.style = CS_PARENTDC | CS_HREDRAW | CS_VREDRAW;
  1942. wndclass.lpfnWndProc = s_WndProc;
  1943. wndclass.hInstance = MLGetHinst();
  1944. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  1945. wndclass.lpszClassName = c_szMediaBarClassName;
  1946. SHRegisterClass(&wndclass);
  1947. _hwnd = CreateWindowEx(WS_EX_CONTROLPARENT, c_szMediaBarClassName, NULL,
  1948. WS_TABSTOP | WS_VISIBLE | WS_CHILD,
  1949. CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
  1950. _hwndParent, NULL, MLGetHinst(), (void *)this);
  1951. if (_hwnd == NULL)
  1952. {
  1953. ASSERT(FALSE);
  1954. return E_FAIL;
  1955. }
  1956. else
  1957. {
  1958. ::ShowWindow(_hwnd, SW_SHOW);
  1959. }
  1960. }
  1961. return S_OK;
  1962. }
  1963. VOID CMediaBand::Resize(HWND hwnd, LONG lWidth, LONG lHeight)
  1964. {
  1965. if (lWidth <= 0 || lHeight <= 0)
  1966. return;
  1967. RECT rcParent;
  1968. if (GetClientRect(_hwnd, &rcParent))
  1969. {
  1970. if (IsWindowVisible(_hwndPopup))
  1971. {
  1972. MoveWindow(_hwndContent, rcParent.left, rcParent.top, RECTWIDTH(rcParent), RECTHEIGHT(rcParent), FALSE);
  1973. }
  1974. else
  1975. {
  1976. LONG lPaneHeight = GetLayoutHeight();
  1977. MoveWindow(_hwndLayout, rcParent.left, rcParent.bottom-lPaneHeight, lWidth, lPaneHeight, FALSE);
  1978. MoveWindow(_hwndContent, rcParent.left, rcParent.top, lWidth, RECTHEIGHT(rcParent)-lPaneHeight, FALSE);
  1979. InvalidateRect(hwnd, NULL, TRUE);
  1980. UpdateWindow(hwnd);
  1981. }
  1982. }
  1983. }
  1984. // WndProc for main window to go in rebar
  1985. LRESULT CALLBACK CMediaBand::s_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1986. {
  1987. CMediaBand* pmb = reinterpret_cast<CMediaBand *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
  1988. switch (msg)
  1989. {
  1990. case WM_ERASEBKGND:
  1991. break;
  1992. case WM_CREATE:
  1993. SetWindowLongPtr(hWnd, GWLP_USERDATA, (reinterpret_cast<LONG_PTR>((reinterpret_cast<CREATESTRUCT *>(lParam))->lpCreateParams)));
  1994. return 0;
  1995. case WM_SIZE:
  1996. if (pmb)
  1997. {
  1998. pmb->Resize(hWnd, (LONG)LOWORD(lParam), (LONG)HIWORD(lParam));
  1999. }
  2000. break;
  2001. case WM_MB_DEFERRED_NAVIGATE:
  2002. // navigation cancelled by IBandNavigate::ISelect() call
  2003. if (pmb && (pmb->_strDeferredURL.Length() > 0))
  2004. {
  2005. pmb->NavigateContentPane(pmb->_strDeferredURL);
  2006. pmb->_strDeferredURL.Empty();
  2007. }
  2008. break;
  2009. case WM_NOTIFY:
  2010. if (pmb)
  2011. {
  2012. return pmb->_OnNotify((LPNMHDR)lParam);
  2013. }
  2014. break;
  2015. case WM_COMMAND:
  2016. {
  2017. LRESULT lres;
  2018. if (pmb->OnWinEvent(hWnd, msg, wParam, lParam, &lres) == S_OK)
  2019. return lres;
  2020. }
  2021. case WM_TIMER:
  2022. // timeout of user's second chance to click stop again and navigate to media content pane to default URL
  2023. if (pmb)
  2024. {
  2025. pmb->_CleanupStopTimer();
  2026. }
  2027. break;
  2028. case WM_WTSSESSION_CHANGE:
  2029. // stop playing media when media bar is no more in current terminal server session
  2030. // this avoids "background noise" when user does fast user switching to other login in XP
  2031. // NOTE: logging on as same user remotely will also stop stream
  2032. if (pmb && ((wParam == WTS_CONSOLE_DISCONNECT) || (wParam == WTS_REMOTE_DISCONNECT)))
  2033. {
  2034. pmb->Exec(&CLSID_MediaBand, FCIDM_MEDIABAND_STOP, 0, NULL, NULL);
  2035. }
  2036. break;
  2037. break;
  2038. }
  2039. return DefWindowProc(hWnd, msg, wParam, lParam);
  2040. }
  2041. LRESULT CALLBACK CMediaBand::s_PopupWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2042. {
  2043. CMediaBand* pmb = reinterpret_cast<CMediaBand *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
  2044. switch (uMsg)
  2045. {
  2046. case WM_CREATE:
  2047. ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) ((LPCREATESTRUCT)lParam)->lpCreateParams);
  2048. break;
  2049. case WM_ACTIVATE:
  2050. if (pmb)
  2051. {
  2052. pmb->ActivatePopout(LOWORD(wParam)!=WA_INACTIVE);
  2053. }
  2054. return 0;
  2055. case WM_KEYDOWN:
  2056. if (wParam==VK_ESCAPE)
  2057. {
  2058. pmb->DockMediaPlayer();
  2059. }
  2060. break;
  2061. case WM_GETMINMAXINFO: // prevent it from getting too small or too large
  2062. if (pmb)
  2063. {
  2064. pmb->ComputeMinMax((MINMAXINFO *)lParam);
  2065. }
  2066. break;
  2067. case WM_SIZE:
  2068. if (pmb && IsWindowVisible(hwnd))
  2069. {
  2070. SetWindowPos(pmb->_hwndLayout, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam), SWP_NOACTIVATE);
  2071. // MoveWindow(pmb->_hwndLayout, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  2072. }
  2073. break;
  2074. case WM_SYSCOMMAND :
  2075. if (wParam == SC_CLOSE)
  2076. pmb->DockMediaPlayer();
  2077. break;
  2078. }
  2079. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  2080. }
  2081. VOID CMediaBand::ActivatePopout(BOOL fState)
  2082. {
  2083. _fPopoutHasFocus = fState;
  2084. UIActivateIO(fState, NULL);
  2085. }
  2086. VOID CMediaBand::ComputeMinMax(MINMAXINFO *pMinMax)
  2087. {
  2088. pMinMax->ptMinTrackSize.x = GetMinPopoutWidth();
  2089. if (_fIsVideo)
  2090. {
  2091. pMinMax->ptMinTrackSize.y = GetPopoutHeight(FALSE) + VIDEO_MIN_HEIGHT;
  2092. }
  2093. else
  2094. {
  2095. pMinMax->ptMaxTrackSize.y = pMinMax->ptMinTrackSize.y = GetPopoutHeight(FALSE);
  2096. }
  2097. }
  2098. LRESULT CALLBACK CMediaBand::s_VolumeWndSubClassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2099. {
  2100. CMediaBand* pmb = (CMediaBand*)GetProp(hwnd, c_szMediaBandProp);
  2101. if (!pmb)
  2102. return DefWindowProcWrap(hwnd, uMsg, wParam, lParam);
  2103. WNDPROC pfnOldWndProc = (WNDPROC)(GetWindowLongPtr(hwnd, GWLP_USERDATA));
  2104. switch (uMsg)
  2105. {
  2106. case WM_HSCROLL:
  2107. case WM_VSCROLL:
  2108. {
  2109. INT_PTR lPos = SendMessage(hwnd, TBM_GETPOS, (WPARAM) 0 ,(LPARAM) 0);
  2110. switch (LOWORD(wParam))
  2111. {
  2112. case TB_THUMBPOSITION:
  2113. case TB_THUMBTRACK:
  2114. {
  2115. if (pmb != NULL)
  2116. {
  2117. pmb->_dblVol = (double)lPos;
  2118. if (pmb->_pMediaPlayer)
  2119. {
  2120. pmb->_pMediaPlayer->put_volume(pmb->_dblVol);
  2121. }
  2122. }
  2123. InvalidateRect(hwnd,NULL,TRUE);
  2124. UpdateWindow(hwnd);
  2125. }
  2126. break ;
  2127. case TB_TOP:
  2128. {
  2129. if (pmb)
  2130. {
  2131. pmb->_dblVol = 0;
  2132. if (pmb->_pMediaPlayer)
  2133. {
  2134. pmb->_pMediaPlayer->put_volume(0);
  2135. }
  2136. }
  2137. }
  2138. break;
  2139. case TB_BOTTOM:
  2140. {
  2141. if (pmb)
  2142. {
  2143. pmb->_dblVol = 100;
  2144. if (pmb->_pMediaPlayer)
  2145. {
  2146. pmb->_pMediaPlayer->put_volume(100);
  2147. }
  2148. }
  2149. }
  2150. break;
  2151. }
  2152. }
  2153. break;
  2154. case WM_DESTROY:
  2155. {
  2156. //
  2157. // Unsubclass myself.
  2158. //
  2159. RemoveProp(hwnd, c_szMediaBandProp);
  2160. if (pfnOldWndProc)
  2161. {
  2162. SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) pfnOldWndProc);
  2163. }
  2164. }
  2165. break;
  2166. }
  2167. return CallWindowProc(pfnOldWndProc, hwnd, uMsg, wParam, lParam);
  2168. }
  2169. LRESULT CALLBACK CMediaBand::s_SeekWndSubClassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2170. {
  2171. CMediaBand* pmb = (CMediaBand*)GetProp(hwnd, c_szMediaBandProp);
  2172. if (!pmb)
  2173. return DefWindowProcWrap(hwnd, uMsg, wParam, lParam);
  2174. WNDPROC pfnOldWndProc = (WNDPROC)(GetWindowLongPtr(hwnd, GWLP_USERDATA));
  2175. switch (uMsg)
  2176. {
  2177. case WM_ERASEBKGND:
  2178. break;
  2179. case WM_HSCROLL:
  2180. {
  2181. if (pmb && pmb->_pMediaPlayer && pmb->_fPlaying)
  2182. {
  2183. if (pmb->_pMediaPlayer->IsSeekPossible() && !pmb->_isUIDisabled())
  2184. {
  2185. INT_PTR lPos = SendMessage(hwnd, TBM_GETPOS, (WPARAM) 0 ,(LPARAM) 0);
  2186. switch (LOWORD(wParam))
  2187. {
  2188. case TB_THUMBPOSITION:
  2189. {
  2190. pmb->_fSeeking = FALSE;
  2191. pmb->Seek(lPos / 100.0);
  2192. if (!pmb->_fUserPaused)
  2193. {
  2194. pmb->_pMediaPlayer->Resume();
  2195. }
  2196. }
  2197. break;
  2198. case TB_THUMBTRACK:
  2199. {
  2200. pmb->_fSeeking = TRUE;
  2201. if (!pmb->_fUserPaused)
  2202. {
  2203. pmb->_pMediaPlayer->Pause();
  2204. }
  2205. pmb->Seek(lPos / 100.0);
  2206. InvalidateRect(hwnd,NULL,TRUE);
  2207. UpdateWindow(hwnd);
  2208. }
  2209. break;
  2210. case TB_PAGEUP:
  2211. case TB_TOP:
  2212. {
  2213. double dblProgress = pmb->_pMediaPlayer->GetTrackProgress();
  2214. // seek backwards by 5%
  2215. pmb->Seek(dblProgress - 0.05);
  2216. }
  2217. break;
  2218. case TB_PAGEDOWN:
  2219. case TB_BOTTOM:
  2220. {
  2221. double dblProgress = pmb->_pMediaPlayer->GetTrackProgress();
  2222. // seek ahead by 5%
  2223. pmb->Seek(dblProgress + 0.05);
  2224. }
  2225. break;
  2226. }
  2227. }
  2228. else
  2229. {
  2230. // disallow seeking by setting the seek position to what it was
  2231. double dblProgress = pmb->_pMediaPlayer->GetTrackProgress();
  2232. pmb->SetSeekPos(static_cast<float>(dblProgress));
  2233. }
  2234. }
  2235. }
  2236. break;
  2237. case WM_DESTROY:
  2238. {
  2239. //
  2240. // Unsubclass myself.
  2241. //
  2242. RemoveProp(hwnd, c_szMediaBandProp);
  2243. if (pfnOldWndProc)
  2244. {
  2245. SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) pfnOldWndProc);
  2246. }
  2247. }
  2248. break;
  2249. }
  2250. return CallWindowProc(pfnOldWndProc, hwnd, uMsg, wParam, lParam);
  2251. }
  2252. // sends appropriate resize messages to our children windows
  2253. VOID
  2254. CMediaBand::_ResizeChildWindows(HWND hwnd, LONG width, LONG height, BOOL fRepaint)
  2255. {
  2256. // Calculate the display rectangle
  2257. RECT rc;
  2258. SIZE sizeTB = {0}, sizePopout = {0};
  2259. LONG lHorzSpacing = MIN_HORZ_SPACING;
  2260. _sizeLayout.cx = width;
  2261. _sizeLayout.cy = GetLayoutHeight();
  2262. SetRect(&rc, 0, 0, width, height);
  2263. LONG lWidthOffset = rc.left+lHorzSpacing;
  2264. HDWP hdwp = BeginDeferWindowPos(10);
  2265. lWidthOffset = rc.left+lHorzSpacing;
  2266. if (_fIsVideo && _hwndVideo)
  2267. {
  2268. LONG lWidth, lHeight, lVideoStart = 0;
  2269. if (_hwndPopup && IsWindowVisible(_hwndPopup))
  2270. {
  2271. lWidth = width-rc.left-lHorzSpacing*2;
  2272. lHeight = GetVideoHeight();
  2273. }
  2274. else
  2275. {
  2276. lWidth = SCALEX(MIN_WINDOW_WIDTH-rc.left-lHorzSpacing*2);
  2277. lHeight = SCALEY(MIN_WINDOW_WIDTH-rc.left);
  2278. }
  2279. // Resize the video and try to get the video sizes
  2280. _ResizeVideo(&lWidth,&lHeight);
  2281. _sizeVideo.cx = (LONG)lWidth ;
  2282. _sizeVideo.cy = (LONG)lHeight ;
  2283. if (lWidth >= width-rc.left-lHorzSpacing*2)
  2284. lVideoStart = rc.left + lHorzSpacing;
  2285. else
  2286. lVideoStart = (width-rc.left-lHorzSpacing*2-lWidth)/2 + rc.left + lHorzSpacing ;
  2287. DeferWindowPos(hdwp, _hwndVideo, HWND_TOP, (LONG)lVideoStart, rc.top+VIEW_MARGIN_TOP_VIDEO, (LONG)lWidth, (LONG)lHeight, SWP_NOZORDER);
  2288. }
  2289. else
  2290. {
  2291. _sizeVideo.cx = 0 ;
  2292. _sizeVideo.cy = 0;
  2293. }
  2294. // Bottom-most row
  2295. LONG lHeightOffset = height - VIEW_MARGIN_BOTTOM;
  2296. lWidthOffset = rc.left + VIEW_MARGIN_LEFT;
  2297. LONG lSeekY = lHeightOffset, lSeekX = 0;
  2298. if (_pmwPlay && _pmwPlay->_hwnd)
  2299. {
  2300. GetToolbarSize(_pmwPlay->_hwnd, &sizeTB);
  2301. lSeekY = lHeightOffset-sizeTB.cy;
  2302. DeferWindowPos(hdwp, _pmwPlay->_hwnd, HWND_TOP, lWidthOffset, lHeightOffset-sizeTB.cy, sizeTB.cx, sizeTB.cy, SWP_NOZORDER);
  2303. lWidthOffset += sizeTB.cx;
  2304. }
  2305. if (_pmwStop && _pmwStop->_hwnd)
  2306. {
  2307. GetToolbarSize(_pmwStop->_hwnd, &sizeTB);
  2308. DeferWindowPos(hdwp, _pmwStop->_hwnd, HWND_TOP, lWidthOffset, lHeightOffset-sizeTB.cy, sizeTB.cx, sizeTB.cy, SWP_NOZORDER);
  2309. lWidthOffset += sizeTB.cx;
  2310. }
  2311. if (_pmwBack && _pmwBack->_hwnd)
  2312. {
  2313. GetToolbarSize(_pmwBack->_hwnd, &sizeTB);
  2314. lSeekX = lWidthOffset;
  2315. DeferWindowPos(hdwp, _pmwBack->_hwnd, HWND_TOP, lWidthOffset, lHeightOffset-sizeTB.cy, sizeTB.cx, sizeTB.cy, SWP_NOZORDER);
  2316. lWidthOffset += sizeTB.cx;
  2317. }
  2318. if (_pmwNext && _pmwNext->_hwnd)
  2319. {
  2320. GetToolbarSize(_pmwNext->_hwnd, &sizeTB);
  2321. DeferWindowPos(hdwp, _pmwNext->_hwnd, HWND_TOP, lWidthOffset, lHeightOffset-sizeTB.cy, sizeTB.cx, sizeTB.cy, SWP_NOZORDER);
  2322. lWidthOffset += sizeTB.cx;
  2323. }
  2324. if (_pmwMute && _pmwMute->_hwnd)
  2325. {
  2326. GetToolbarSize(_pmwMute->_hwnd, &sizeTB);
  2327. LONG lVolumeWidth = SCALEX(MIN_VOLUME_WIDTH);
  2328. lWidthOffset = max(lWidthOffset+lHorzSpacing, (width - sizeTB.cx - lVolumeWidth - VIEW_MARGIN_RIGHT));
  2329. DeferWindowPos(hdwp, _pmwMute->_hwnd, HWND_TOP, lWidthOffset, lHeightOffset-sizeTB.cy, sizeTB.cx, sizeTB.cy, SWP_NOZORDER);
  2330. if (_hwndVolume)
  2331. {
  2332. lWidthOffset += sizeTB.cx;
  2333. DeferWindowPos(hdwp, _hwndVolume, HWND_TOP, lWidthOffset, lHeightOffset-sizeTB.cy, lVolumeWidth, SCALEY(MIN_VOLUME_HEIGHT), SWP_NOZORDER);
  2334. }
  2335. }
  2336. lWidthOffset = rc.left + lHorzSpacing;
  2337. if (_hwndSeek)
  2338. {
  2339. LONG lSeekWidth = max(width-lHorzSpacing-lSeekX-2, 0);
  2340. DeferWindowPos(hdwp, _hwndSeek, HWND_TOP, lSeekX+2, lSeekY, lSeekWidth, SCALEY(SEEK_HEIGHT), SWP_NOZORDER);
  2341. }
  2342. lWidthOffset = rc.left + VIEW_MARGIN_INFO_LEFT;
  2343. if (ISVALIDWIDGET(_pmwPop))
  2344. {
  2345. GetToolbarSize(_pmwPop->_hwnd, &sizePopout);
  2346. DeferWindowPos(hdwp, _pmwPop->_hwnd, HWND_TOP, width-sizePopout.cx-VIEW_MARGIN_INFO_LEFT, lSeekY-sizePopout.cy-VIEW_CONTROLS_MARGIN, sizePopout.cx, sizePopout.cy, SWP_NOZORDER);
  2347. }
  2348. if (ISVALIDWIDGET(_pmwOptions))
  2349. {
  2350. GetToolbarSize(_pmwOptions->_hwnd, &sizeTB);
  2351. DeferWindowPos(hdwp, _pmwOptions->_hwnd, HWND_TOP, lWidthOffset, lSeekY-sizeTB.cy-VIEW_CONTROLS_MARGIN, width-lHorzSpacing*3-sizePopout.cx, sizeTB.cy, SWP_NOZORDER);
  2352. _iOptionsWidth = width-lHorzSpacing*3-sizePopout.cx-10;
  2353. SendMessage(_pmwOptions->_hwnd, TB_SETBUTTONWIDTH, 0, (LPARAM) MAKELONG(0, _iOptionsWidth));
  2354. SendMessage(_pmwOptions->_hwnd, TB_AUTOSIZE, 0, 0);
  2355. }
  2356. EndDeferWindowPos(hdwp);
  2357. if (fRepaint)
  2358. {
  2359. InvalidateRect(hwnd, NULL, TRUE);
  2360. UpdateWindow(hwnd);
  2361. }
  2362. else
  2363. {
  2364. InvalidateRect(hwnd, NULL, FALSE);
  2365. UpdateWindow(hwnd);
  2366. }
  2367. }
  2368. LONG CMediaBand::GetControlsHeight()
  2369. {
  2370. LONG lHeightOffset = VIEW_MARGIN_TOP;
  2371. // Compute height for options here
  2372. if (ISVALIDWIDGET(_pmwOptions))
  2373. {
  2374. SIZE sizeTB = {0};
  2375. GetToolbarSize(_pmwOptions->_hwnd, &sizeTB);
  2376. lHeightOffset += SCALEY(sizeTB.cy) + VIEW_CONTROLS_MARGIN;
  2377. }
  2378. // Rest of controls
  2379. lHeightOffset += VIEW_MARGIN_BOTTOM + SCALEY(VIEW_CONTROLS_HEIGHT);
  2380. return lHeightOffset;
  2381. }
  2382. LONG CMediaBand::GetLayoutHeight(LONG lWidth)
  2383. {
  2384. LONG lHeightOffset = GetControlsHeight();
  2385. if (_hwndVideo && (IsWindowVisible(_hwndVideo) || _fIsVideo))
  2386. {
  2387. LONG lHeight = GetVideoHeight(lWidth);
  2388. if (lHeight>0)
  2389. lHeightOffset += lHeight + VIEW_MARGIN_TOP_VIDEO;
  2390. }
  2391. return lHeightOffset;
  2392. }
  2393. float
  2394. CMediaBand::GetSeekPos()
  2395. {
  2396. INT_PTR lMax = SendMessage(_hwndSeek, TBM_GETRANGEMAX, 0, 0) ;
  2397. INT_PTR lMin = SendMessage(_hwndSeek, TBM_GETRANGEMIN, 0, 0) ;
  2398. INT_PTR lPos = SendMessage(_hwndSeek, TBM_GETPOS, 0, 0) ;
  2399. return ((float)lPos / (float)(lMax - lMin));
  2400. }
  2401. VOID
  2402. CMediaBand::SetSeekPos(float fPosition)
  2403. {
  2404. INT_PTR lMax = SendMessage(_hwndSeek, TBM_GETRANGEMAX, 0, 0) ;
  2405. INT_PTR lMin = SendMessage(_hwndSeek, TBM_GETRANGEMIN, 0, 0) ;
  2406. fPosition *= (lMax - lMin) ;
  2407. INT_PTR lPos = SendMessage(_hwndSeek, TBM_GETPOS, 0, 0) ;
  2408. if (lPos!=(LONG) fPosition)
  2409. {
  2410. SendMessage(_hwndSeek, TBM_SETPOS, TRUE, (LPARAM) (LONG) fPosition);
  2411. InvalidateRect(_hwndSeek, NULL,TRUE);
  2412. UpdateWindow(_hwndSeek);
  2413. }
  2414. }
  2415. HRESULT
  2416. CMediaBand::_InitializeMediaUI()
  2417. {
  2418. HRESULT hr = S_OK;
  2419. _fHiColour = (SHGetCurColorRes() > 8);
  2420. if (!_hwndLayout)
  2421. {
  2422. CreateLayoutPane();
  2423. }
  2424. if (!_hwndContent)
  2425. {
  2426. InitContentPane();
  2427. }
  2428. if (!_fInitialized && _hwndLayout)
  2429. {
  2430. _szConnecting[0] = TEXT('\0');
  2431. MLLoadString(IDS_MEDIABAND_NOWDOWNLOADING, _szConnecting, ARRAYSIZE(_szConnecting));
  2432. _hbmpBackground = LoadBitmap(HINST_THISDLL, MAKEINTRESOURCE(IDB_MEDIABAND_BG_BASE));
  2433. CreateControls();
  2434. CreateSeekBar();
  2435. CreateVolumeControl();
  2436. ResetPlayer();
  2437. if (!_fHiColour)
  2438. {
  2439. // Assume high colour. If not, switch to low colour versions.
  2440. SwitchBitmaps(_fHiColour);
  2441. }
  2442. // want to sink notification when fast user switch occurs:
  2443. WTSRegisterSessionNotification(_hwnd, NOTIFY_FOR_THIS_SESSION);
  2444. _fInitialized = TRUE;
  2445. }
  2446. _ShowAllWindows(TRUE);
  2447. return hr;
  2448. }
  2449. VOID
  2450. CMediaBand::_ShowAllWindows(BOOL fShow)
  2451. {
  2452. if (_hwndPopup && IsWindowVisible(_hwndPopup))
  2453. {
  2454. // SendMessage(_hwndPopup, WM_SYSCOMMAND, (WPARAM)SC_CLOSE, (LPARAM)0);
  2455. return;
  2456. }
  2457. if (_hwndLayout)
  2458. ShowWindow(_hwndLayout, fShow ? SW_SHOW : SW_HIDE);
  2459. for (int i=0; i < ARRAYSIZE(_pmw); i++)
  2460. {
  2461. if (ISVALIDWIDGET(_pmw[i]))
  2462. ShowWindow(_pmw[i]->_hwnd, fShow ? SW_SHOW : SW_HIDE);
  2463. }
  2464. if (_hwndContent)
  2465. {
  2466. ShowWindow(_hwndContent, fShow ? SW_SHOW : SW_HIDE);
  2467. }
  2468. }
  2469. VOID
  2470. CMediaBand::ToggleMute()
  2471. {
  2472. _fMuted = !_fMuted;
  2473. if (_pmwMute)
  2474. {
  2475. _pmwMute->SetState(_fMuted);
  2476. }
  2477. if (_pMediaPlayer)
  2478. {
  2479. _pMediaPlayer->put_mute(_fMuted);
  2480. }
  2481. }
  2482. VOID
  2483. CMediaBand::TogglePlayPause()
  2484. {
  2485. if (!EnsurePlayer())
  2486. {
  2487. return;
  2488. }
  2489. VARIANT_BOOL vbPaused = _pMediaPlayer->isPaused();
  2490. VARIANT_BOOL vbStopped = _pMediaPlayer->isStopped();
  2491. // if player is in paused state, show the play button and vice-versa
  2492. // _fPlayButton==FALSE means that the pause button is currently displayed
  2493. // _fPlayButton==TRUE means that the play button is currently displayed
  2494. if (vbStopped || vbPaused)
  2495. {
  2496. if (!_fPlayButton)
  2497. {
  2498. _fPlayButton = TRUE;
  2499. if (_pmwPlay)
  2500. {
  2501. _pmwPlay->SetMode(MWB_NORMAL);
  2502. _pmwPlay->SetImageSource(TRUE);
  2503. }
  2504. }
  2505. }
  2506. else
  2507. {
  2508. if (_fPlayButton)
  2509. {
  2510. _fPlayButton = FALSE;
  2511. if (_pMediaPlayer->IsPausePossible())
  2512. {
  2513. // ISSUE (akabir): The following line doesn't work correctly
  2514. // _pmwPlay->SetMode(MWB_DISABLED);
  2515. }
  2516. // change button bitmaps
  2517. if (_pmwPlay)
  2518. {
  2519. _pmwPlay->SetImageSource(FALSE);
  2520. }
  2521. }
  2522. }
  2523. }
  2524. HWND
  2525. CMediaBand::GetBrowserWindow()
  2526. {
  2527. CComPtr<IWebBrowser2> spWebBrowser;
  2528. // QS for the browser main window
  2529. if (SUCCEEDED(QueryService(SID_SWebBrowserApp, IID_PPV_ARG(IWebBrowser2, &spWebBrowser))))
  2530. {
  2531. LONG_PTR hwndApp;
  2532. if (SUCCEEDED(spWebBrowser->get_HWND(&hwndApp)))
  2533. {
  2534. return ((HWND)hwndApp);
  2535. }
  2536. }
  2537. return NULL;
  2538. }
  2539. // Called only by CMediaBand::CreateInstance
  2540. HRESULT
  2541. CMediaBand::InitPlayerPopup()
  2542. {
  2543. HRESULT hr = E_FAIL;
  2544. WNDCLASS wndclass = { 0 };
  2545. wndclass.style = CS_PARENTDC | CS_HREDRAW | CS_VREDRAW;
  2546. wndclass.lpfnWndProc = s_PopupWndProc;
  2547. wndclass.hInstance = HINST_THISDLL;
  2548. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  2549. wndclass.lpszClassName = c_szMediaBarPopupClassName;
  2550. wndclass.hIcon = (HICON)LoadIcon(HINST_THISDLL, MAKEINTRESOURCE(IDB_TB_MEDIA_HOT));
  2551. wndclass.hbrBackground = NULL;
  2552. SHRegisterClass(&wndclass);
  2553. DWORD dwStyle = (WS_OVERLAPPEDWINDOW & ~(WS_MINIMIZEBOX));
  2554. DWORD dwExStyle = WS_EX_CONTROLPARENT | (IS_BIDI_LOCALIZED_SYSTEM() ? dwExStyleRTLMirrorWnd : 0);
  2555. _hwndPopup = CreateWindowEx(dwExStyle, c_szMediaBarPopupClassName, NULL, dwStyle,
  2556. CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
  2557. GetBrowserWindow(), NULL, HINST_THISDLL, (void *)this);
  2558. hr = (_hwndPopup && _hwndLayout) ? S_OK : E_FAIL;
  2559. // modify the properties of the window as appropriate
  2560. if (SUCCEEDED(hr))
  2561. {
  2562. // set parent
  2563. SHSetParentHwnd(_hwndLayout, _hwndPopup);
  2564. WCHAR szTitle[256];
  2565. MLLoadStringW(IDS_MEDIABANDTEXT, szTitle, ARRAYSIZE(szTitle));
  2566. SetWindowText(_hwndPopup, szTitle);
  2567. if (_sizeLayout.cx < GetMinPopoutWidth())
  2568. _sizeLayout.cx = GetMinPopoutWidth();
  2569. if (_fSavedPopoutState)
  2570. {
  2571. SetWindowPlacement(_hwndPopup, &_wpPopout);
  2572. }
  2573. else
  2574. {
  2575. RECT rc = { 0 };
  2576. INT iHeight = GetPopoutHeight(TRUE, _sizeLayout.cx);
  2577. INT x = 10, y = 10;
  2578. if (GetWindowRect(_hwnd, &rc))
  2579. {
  2580. x = IS_WINDOW_RTL_MIRRORED(_hwnd) ? (rc.right - _sizeLayout.cx) : rc.left;
  2581. y = rc.bottom - iHeight;
  2582. if (y < 0)
  2583. {
  2584. y = rc.bottom;
  2585. }
  2586. }
  2587. SetWindowPos(_hwndPopup, HWND_TOPMOST, x, y, _sizeLayout.cx, iHeight, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
  2588. }
  2589. ShowWindow(_hwndPopup, SW_SHOW);
  2590. UpdateWindow(_hwndPopup);
  2591. if (_pmwPop && _pmwPop->_hwnd)
  2592. {
  2593. _pmwPop->SetImageSource(FALSE);
  2594. if (_iElement==MW_POP)
  2595. {
  2596. _fPopoutHasFocus = TRUE;
  2597. UIActivateIO(TRUE, NULL);
  2598. }
  2599. }
  2600. }
  2601. return hr;
  2602. }
  2603. HRESULT
  2604. CMediaBand::GetTrackTitle(BSTR *pbstrTitle)
  2605. {
  2606. USES_CONVERSION;
  2607. CComPtr<ITIMEMediaElement> spMediaElem;
  2608. HRESULT hr = E_FAIL;
  2609. if ( !EnsurePlayer()
  2610. || !pbstrTitle)
  2611. {
  2612. hr = E_FAIL;
  2613. goto done;
  2614. }
  2615. *pbstrTitle = NULL;
  2616. //
  2617. // if a title is available from the media element, display it
  2618. //
  2619. hr = _pMediaPlayer->get_mediaElement(&spMediaElem);
  2620. if ( FAILED(hr)
  2621. || !spMediaElem.p)
  2622. {
  2623. hr = E_FAIL;
  2624. goto done;
  2625. }
  2626. hr = spMediaElem->get_title(pbstrTitle);
  2627. if (SUCCEEDED(hr) && (*pbstrTitle != NULL))
  2628. {
  2629. if (SysStringLen(*pbstrTitle)>0)
  2630. {
  2631. goto done;
  2632. }
  2633. else
  2634. {
  2635. SysFreeString(*pbstrTitle);
  2636. *pbstrTitle = NULL;
  2637. }
  2638. }
  2639. //
  2640. // if title is not available, display the the url
  2641. //
  2642. hr = _pMediaPlayer->get_url(pbstrTitle);
  2643. if (SUCCEEDED(hr) && *pbstrTitle && (SysStringLen(*pbstrTitle)<=0))
  2644. {
  2645. SysFreeString(*pbstrTitle);
  2646. *pbstrTitle = NULL;
  2647. }
  2648. if (SUCCEEDED(hr) && (*pbstrTitle != NULL))
  2649. {
  2650. // If the url is available, display it
  2651. DWORD dwcchUnescaped;
  2652. TCHAR tszPath[MAX_PATH];
  2653. StrCpyN(tszPath, W2T(*pbstrTitle), ARRAYSIZE(tszPath));
  2654. PathStripPath(tszPath);
  2655. if (SUCCEEDED(UrlUnescape(tszPath, NULL, &dwcchUnescaped, URL_UNESCAPE_INPLACE)))
  2656. {
  2657. SysFreeString(*pbstrTitle);
  2658. *pbstrTitle = SysAllocString(tszPath);
  2659. }
  2660. }
  2661. hr = S_OK;
  2662. done:
  2663. return hr;
  2664. }
  2665. VOID
  2666. CMediaBand::ShowPlayingStatus(BOOL fInitial)
  2667. {
  2668. USES_CONVERSION;
  2669. BSTR bstrTitle = NULL;
  2670. if (EnsurePlayer() && _fPlaying)
  2671. {
  2672. if (!_isUIDisabled())
  2673. {
  2674. GetTrackTitle(&bstrTitle);
  2675. // Display the name of the title
  2676. if (bstrTitle && bstrTitle[0] != 0)
  2677. SetStatusText(W2T(bstrTitle));
  2678. }
  2679. else
  2680. {
  2681. TCHAR szText[MAX_PATH];
  2682. szText[0] = TEXT('\0');
  2683. MLLoadString(IDS_MEDIABAND_PLAYING, szText, ARRAYSIZE(szText));
  2684. SetStatusText(szText);
  2685. }
  2686. CComPtr<ITIMEMediaElement> spMediaElem;
  2687. HRESULT hr = _pMediaPlayer->get_mediaElement(&spMediaElem);
  2688. ERROREXIT(hr)
  2689. // store away the natural length of the media
  2690. hr = spMediaElem->get_mediaDur(&_dblMediaDur);
  2691. ERROREXIT(hr)
  2692. }
  2693. done :
  2694. if (bstrTitle)
  2695. SysFreeString(bstrTitle);
  2696. }
  2697. VOID
  2698. CMediaBand::SetStatusText(LPTSTR lpwStatusInfo)
  2699. {
  2700. if (ISVALIDWIDGET(_pmwOptions))
  2701. {
  2702. // change buttons
  2703. TBBUTTONINFO tbbi;
  2704. TCHAR szText[MAX_PATH];
  2705. tbbi.cbSize = sizeof(tbbi);
  2706. tbbi.dwMask = TBIF_BYINDEX | TBIF_TEXT;
  2707. tbbi.pszText = szText ;
  2708. tbbi.cchText = MAX_PATH ;
  2709. SendMessage(_pmwOptions->_hwnd, TB_GETBUTTONINFO, (WPARAM)0, (LPARAM)&tbbi);
  2710. if (StrCmpIW(tbbi.pszText,lpwStatusInfo))
  2711. {
  2712. tbbi.pszText = lpwStatusInfo;
  2713. if (_pszStatus)
  2714. {
  2715. delete [] _pszStatus;
  2716. }
  2717. _pszStatus = new TCHAR[lstrlen(lpwStatusInfo)+1];
  2718. if (_pszStatus)
  2719. {
  2720. StringCchCopy(_pszStatus, ARRAYSIZE(_pszStatus), lpwStatusInfo);
  2721. }
  2722. SendMessage(_pmwOptions->_hwnd, TB_SETBUTTONINFO, (WPARAM)0, (LPARAM)&tbbi);
  2723. // Need to force a resizing to accommodate new text
  2724. SendMessage(_pmwOptions->_hwnd, TB_SETBUTTONWIDTH, 0, (LPARAM) MAKELONG(0, _iOptionsWidth-1));
  2725. SendMessage(_pmwOptions->_hwnd, TB_SETBUTTONWIDTH, 0, (LPARAM) MAKELONG(0, _iOptionsWidth));
  2726. }
  2727. }
  2728. }
  2729. HRESULT
  2730. CMediaBand::ShowPlayListMenu(HWND hwnd, RECTL* rc)
  2731. {
  2732. if (_hPlayListMenu)
  2733. {
  2734. DestroyMenu(_hPlayListMenu);
  2735. _hPlayListMenu = NULL;
  2736. }
  2737. _hPlayListMenu = GetSubMenu(LoadMenu(MLGetHinst(), MAKEINTRESOURCE(MENU_MEDIA_GENERIC)), 0);
  2738. if (_EnumPlayItems() != S_OK)
  2739. {
  2740. DestroyMenu(_hPlayListMenu);
  2741. _hPlayListMenu = NULL;
  2742. return S_OK;
  2743. }
  2744. ASSERT(_pMediaPlayer);
  2745. UINT nID = FCIDM_PLAYITEM_START + (UINT)_pMediaPlayer->GetPlayListItemIndex();
  2746. CheckMenuRadioItem(_hPlayListMenu, FCIDM_PLAYITEM_START, FCIDM_PLAYITEM_END, nID, MF_BYCOMMAND);
  2747. UpdateMenuItems(_hPlayListMenu);
  2748. POINT pt = {rc->left ,rc->bottom};
  2749. int idCmd = TrackPopupMenu(_hPlayListMenu,
  2750. TPM_LEFTBUTTON | TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
  2751. pt.x, pt.y, 0, hwnd, NULL);
  2752. if (idCmd>=FCIDM_PLAYITEM_START && idCmd<=FCIDM_PLAYITEM_END)
  2753. {
  2754. UINT iCurTrack = idCmd - FCIDM_PLAYITEM_START ;
  2755. _pMediaPlayer->SetActiveTrack(iCurTrack);
  2756. UpdateBackForwardControls();
  2757. }
  2758. else
  2759. {
  2760. HandleMenuTasks(idCmd);
  2761. }
  2762. return S_OK;
  2763. }
  2764. STDMETHODIMP
  2765. CMediaBand::_EnumPlayItems()
  2766. {
  2767. USES_CONVERSION;
  2768. CComPtr<ITIMEMediaElement> spMediaElem;
  2769. CComPtr<ITIMEPlayList> spPlayList;
  2770. CComVariant svarIndex;
  2771. long lLength = 0;
  2772. INT i = 0;
  2773. MENUITEMINFO mii = { sizeof(mii) };
  2774. HRESULT hr = _pMediaPlayer->get_mediaElement(&spMediaElem);
  2775. ERROREXIT(hr)
  2776. hr = spMediaElem->get_playList(&spPlayList);
  2777. ERROREXIT(hr)
  2778. if (!(spPlayList.p))
  2779. return S_FALSE;
  2780. hr = spPlayList->get_length(&lLength);
  2781. ERROREXIT(hr)
  2782. svarIndex.vt = VT_I4;
  2783. mii.cbSize = sizeof(mii);
  2784. mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
  2785. mii.fType = MFT_STRING | MFT_RADIOCHECK;
  2786. mii.fState = MF_ENABLED;
  2787. for (; i < lLength; i++)
  2788. {
  2789. CComPtr<ITIMEPlayItem> spPlayItem;
  2790. CComBSTR sbstrTitle;
  2791. TCHAR wszPath[40];
  2792. V_I4(&svarIndex) = i;
  2793. hr = spPlayList->item(svarIndex, &spPlayItem);
  2794. ERROREXIT(hr)
  2795. hr = spPlayItem->get_title(&sbstrTitle);
  2796. ERROREXIT(hr)
  2797. mii.wID = i + FCIDM_PLAYITEM_START;
  2798. if (sbstrTitle.Length() != 0)
  2799. {
  2800. StrCpyN(wszPath, sbstrTitle, ARRAYSIZE(wszPath));
  2801. }
  2802. else
  2803. {
  2804. CComBSTR sbstrSrc;
  2805. if (SUCCEEDED(spPlayItem->get_src(&sbstrSrc)) && sbstrSrc.Length() != 0)
  2806. {
  2807. PWSTR psz = PathFindFileName(sbstrSrc);
  2808. StrCpyN(wszPath, psz, ARRAYSIZE(wszPath));
  2809. }
  2810. else
  2811. {
  2812. WCHAR szTemplate[64];
  2813. if (!MLLoadStringW(IDS_MEDIABAND_TRACKNUMBER, szTemplate, ARRAYSIZE(szTemplate)))
  2814. {
  2815. StrCpy(szTemplate, TEXT("%d"));
  2816. }
  2817. wnsprintf(wszPath, ARRAYSIZE(wszPath), szTemplate, i+1);
  2818. }
  2819. }
  2820. mii.dwTypeData = (LPTSTR)wszPath;
  2821. InsertMenuItem(_hPlayListMenu, i, TRUE, &mii);
  2822. }
  2823. mii.fMask = MIIM_TYPE;
  2824. mii.fType = MFT_SEPARATOR;
  2825. InsertMenuItem(_hPlayListMenu, i, TRUE, &mii);
  2826. hr = S_OK;
  2827. done:
  2828. return hr;
  2829. }
  2830. HRESULT CMediaBand::ShowGenericMenu(HWND hwnd, RECTL* rc)
  2831. {
  2832. HMENU hMenu = GetSubMenu(LoadMenu(MLGetHinst(), MAKEINTRESOURCE(MENU_MEDIA_GENERIC)), 0);
  2833. if (hMenu)
  2834. {
  2835. UpdateMenuItems(hMenu);
  2836. int idCmd = TrackPopupMenu(hMenu,
  2837. TPM_LEFTBUTTON | TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
  2838. rc->left, rc->bottom, 0, hwnd, NULL);
  2839. HandleMenuTasks(idCmd);
  2840. DestroyMenu(hMenu);
  2841. }
  2842. return S_OK;
  2843. }
  2844. HRESULT CMediaBand::HandleMenuTasks(INT idCmd)
  2845. {
  2846. switch (idCmd)
  2847. {
  2848. case IDM_MEDIA_PLAYINDEFAULT:
  2849. {
  2850. CComBSTR sbstrUrl;
  2851. if (SUCCEEDED(_pMediaPlayer->get_url(&sbstrUrl)) && (NULL != sbstrUrl.m_str))
  2852. {
  2853. _OpenInDefaultPlayer(sbstrUrl);
  2854. }
  2855. }
  2856. break;
  2857. case IDM_MEDIA_ADDTOFAVORITES:
  2858. {
  2859. BSTR bstr = NULL, bstrTitle = NULL;
  2860. if (EnsurePlayer() && !_isUIDisabled() && SUCCEEDED(_pMediaPlayer->get_url(&bstr)) && bstr && SUCCEEDED(GetTrackTitle(&bstrTitle)))
  2861. {
  2862. if (*bstr)
  2863. {
  2864. AddToFavorites(bstr, bstrTitle);
  2865. }
  2866. SysFreeString(bstr);
  2867. }
  2868. break;
  2869. }
  2870. case IDM_MEDIA_PLAYINBAR:
  2871. ToggleAutoplay(!GetAutoplay());
  2872. break;
  2873. case IDM_MEDIA_ASKTYPES:
  2874. ToggleAutoplayPrompting(!GetAutoplayPrompt());
  2875. break;
  2876. case IDM_MEDIA_RESETTYPES:
  2877. ResetMimePreferences();
  2878. break;
  2879. case IDM_MEDIA_TAKEOVERTYPES:
  2880. if (PromptSettings(IDD_MEDIA_TAKEOVERMIMEPROMPT))
  2881. {
  2882. // do take over file types here
  2883. }
  2884. break;
  2885. case IDM_MEDIA_RADIO_GOTO:
  2886. _NavigateMainWindow(c_szRadioUrl);
  2887. break;
  2888. case IDM_MEDIA_BROADBAND_GUIDE:
  2889. NavigateMoreMedia();
  2890. break;
  2891. }
  2892. return S_OK;
  2893. }
  2894. HRESULT CMediaBand::_NavigateMainWindow(LPCTSTR wstrUrl, bool fSuppressFirstAutoPlay /* = false */)
  2895. {
  2896. CComPtr<IWebBrowser2> spWB2;
  2897. // QS for the media bar
  2898. HRESULT hr = QueryService(SID_SWebBrowserApp, IID_PPV_ARG(IWebBrowser2, &spWB2));
  2899. if (SUCCEEDED(hr))
  2900. {
  2901. CComBSTR sbstrUrl(wstrUrl);
  2902. CComVariant svarEmpty;
  2903. if (fSuppressFirstAutoPlay)
  2904. {
  2905. hr = CMediaBarHelper::DisableFirstAutoPlay(spWB2);
  2906. if (FAILED(hr))
  2907. goto done;
  2908. }
  2909. if (sbstrUrl)
  2910. {
  2911. hr = spWB2->Navigate(sbstrUrl, &svarEmpty, &svarEmpty, &svarEmpty, &svarEmpty);
  2912. }
  2913. else
  2914. {
  2915. hr = E_OUTOFMEMORY;
  2916. }
  2917. }
  2918. done:
  2919. return hr;
  2920. }
  2921. HRESULT
  2922. CMediaBand::ResetMimePreferences()
  2923. {
  2924. HRESULT hr = S_OK;
  2925. if (PromptSettings(IDD_MEDIA_RESETMIMEPROMPT))
  2926. {
  2927. DWORD dwRet = SHDeleteKey(HKEY_CURRENT_USER, WZ_SMIE_MEDIA_MIME);
  2928. if (ERROR_SUCCESS != dwRet)
  2929. {
  2930. hr = E_FAIL;
  2931. }
  2932. }
  2933. return hr;
  2934. }
  2935. BOOL CMediaBand::PromptSettings(UINT IDPROMPT)
  2936. {
  2937. return (DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDPROMPT), GetBrowserWindow(), s_PromptMimeDlgProc, NULL) == IDOK);
  2938. }
  2939. INT_PTR CALLBACK
  2940. CMediaBand::s_PromptMimeDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2941. {
  2942. switch(uMsg)
  2943. {
  2944. case WM_COMMAND:
  2945. if (GET_WM_COMMAND_ID(wParam, lParam)==IDC_MEDIA_MOREINFO)
  2946. {
  2947. SHHtmlHelpOnDemandWrap(GetParent(hDlg), TEXT("iexplore.chm > iedefault"), 0, (DWORD_PTR) TEXT("mediabar_settings.htm"), ML_CROSSCODEPAGE);
  2948. }
  2949. else
  2950. {
  2951. EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  2952. }
  2953. break;
  2954. }
  2955. return FALSE;
  2956. }
  2957. HRESULT
  2958. CMediaBand::AddToFavorites(BSTR bstrUrl, BSTR bstrTitle)
  2959. {
  2960. HRESULT hr = E_FAIL;
  2961. if (_hwndPopup && IsWindowVisible(_hwndPopup))
  2962. {
  2963. DockMediaPlayer();
  2964. }
  2965. if (bstrUrl)
  2966. {
  2967. CComPtr<IShellUIHelper> spShellUIHelper;
  2968. hr = CoCreateInstance(CLSID_ShellUIHelper, NULL, CLSCTX_INPROC_SERVER, IID_IShellUIHelper, (void**) &spShellUIHelper);
  2969. if (SUCCEEDED(hr))
  2970. {
  2971. CComVariant svarTitle(bstrTitle);
  2972. hr = spShellUIHelper->AddFavorite(bstrUrl, &svarTitle);
  2973. }
  2974. }
  2975. return hr;
  2976. }
  2977. LONG
  2978. CMediaBand::GetVideoHeight(LONG lSpecifiedWidth, BOOL fNewVideo)
  2979. {
  2980. LONG lPaneWidth = lSpecifiedWidth==0 ? SCALEX(MIN_WINDOW_WIDTH) : lSpecifiedWidth;
  2981. LONG lWidth = lPaneWidth-MIN_HORZ_SPACING*2,
  2982. lHeight = lWidth; // Assumption: Video is never taller than it is wide
  2983. if (_hwndPopup && IsWindowVisible(_hwndPopup))
  2984. {
  2985. RECT rcWindow;
  2986. GetClientRect(_hwndPopup,&rcWindow);
  2987. lPaneWidth = RECTWIDTH(rcWindow);
  2988. // minimum widths as per spec
  2989. lWidth = lPaneWidth - MIN_HORZ_SPACING * 2;
  2990. // Allow for controls.
  2991. if (fNewVideo)
  2992. {
  2993. lHeight = lWidth;
  2994. }
  2995. else
  2996. {
  2997. lHeight = RECTHEIGHT(rcWindow)-GetControlsHeight()-VIEW_MARGIN_TOP_VIDEO;
  2998. }
  2999. }
  3000. // Resize the video and get video sizes
  3001. _ResizeVideo(&lWidth,&lHeight);
  3002. if (lWidth != -1 || lHeight != -1)
  3003. return (lHeight>0 ? lHeight : (lPaneWidth-MIN_HORZ_SPACING*5)) ;
  3004. else
  3005. return -1;
  3006. }
  3007. VOID
  3008. CMediaBand::DockMediaPlayer()
  3009. {
  3010. if (!_hwndPopup)
  3011. {
  3012. InitPlayerPopup();
  3013. }
  3014. else if (IsWindowVisible(_hwndPopup))
  3015. {
  3016. // map the system window close request into a redocking operation instead
  3017. // of closing
  3018. _wpPopout.length = sizeof(_wpPopout);
  3019. _fSavedPopoutState = GetWindowPlacement(_hwndPopup, &_wpPopout);
  3020. // set the parent back to embedded window
  3021. SHSetParentHwnd(_hwndLayout, _hwnd);
  3022. DestroyWindow(_hwndPopup);
  3023. _hwndPopup = NULL;
  3024. if (_pmwPop && _pmwPop->_hwnd)
  3025. {
  3026. _pmwPop->SetImageSource(TRUE);
  3027. }
  3028. }
  3029. RECT rcParent;
  3030. GetClientRect(_hwnd, &rcParent);
  3031. SendMessage(_hwnd, WM_SIZE, (WPARAM)0, (LPARAM)MAKELONG(RECTWIDTH(rcParent), RECTHEIGHT(rcParent)));
  3032. InvalidateRect(_hwnd, NULL, TRUE);
  3033. UpdateWindow(_hwnd);
  3034. }
  3035. VOID
  3036. CMediaBand::GetToolbarSize(HWND hwndTB, SIZE *pSize)
  3037. {
  3038. int nButtons = ToolBar_ButtonCount(hwndTB);
  3039. pSize->cx = 0 ;
  3040. pSize->cy = 0 ;
  3041. for (int nIndex = 0; nIndex < nButtons; nIndex++)
  3042. {
  3043. RECTL rc ;
  3044. SendMessage(hwndTB, TB_GETITEMRECT, nIndex, (LPARAM)&rc);
  3045. pSize->cx += RECTWIDTH(rc);
  3046. pSize->cy = max(RECTHEIGHT(rc),pSize->cy);
  3047. }
  3048. }
  3049. //+-------------------------------------------------------------------------
  3050. // Name: Invoke, IDispatch
  3051. //
  3052. // Abstract:
  3053. // This switches on the dispid looking for dispid's of events
  3054. // that it should handle. Note, this is called for all events
  3055. // fired from the window, only the selected events are handled.
  3056. //--------------------------------------------------------------------------
  3057. STDMETHODIMP CMediaBand::Invoke( /* [in] */ DISPID dispidMember,
  3058. /* [in] */ REFIID /*riid*/,
  3059. /* [in] */ LCID /*lcid*/,
  3060. /* [in] */ WORD /*wFlags*/,
  3061. /* [out][in] */ DISPPARAMS* pdispparams,
  3062. /* [out] */ VARIANT* pVarResult,
  3063. /* [out] */ EXCEPINFO* /*pExcepInfo*/,
  3064. /* [out] */ UINT* puArgErr)
  3065. {
  3066. USES_CONVERSION;
  3067. HRESULT hr = E_FAIL;
  3068. if (!pdispparams)
  3069. return E_INVALIDARG;
  3070. // show our friendly 404 page on navigation error:
  3071. if (dispidMember == DISPID_NAVIGATEERROR)
  3072. {
  3073. // validate expected param list
  3074. if ( (pdispparams->cArgs != 5)
  3075. || (pdispparams->rgvarg[4].vt != VT_DISPATCH) // IWebBrowser2 as IDispatch
  3076. || (pdispparams->rgvarg[3].vt != (VT_BYREF | VT_VARIANT)) // target URL as BSTR
  3077. || (pdispparams->rgvarg[2].vt != (VT_BYREF | VT_VARIANT)) // target frame as BSTR
  3078. || (pdispparams->rgvarg[1].vt != (VT_BYREF | VT_VARIANT)) // status code as VT_I4
  3079. || (pdispparams->rgvarg[0].vt != (VT_BYREF | VT_BOOL))) // Cancel as VT_BOOL, OUT param
  3080. {
  3081. ASSERTMSG(0, "unexpected param list for NavigateError");
  3082. return E_INVALIDARG;
  3083. }
  3084. LPCTSTR pszURL = W2CT(VariantToStrCast(&pdispparams->rgvarg[3]));
  3085. int iStatus = VariantToInt(pdispparams->rgvarg[1]);
  3086. // can't navigate to page, give help page
  3087. TCHAR szResURL[2*MAX_URL_STRING]; // expect URL to help page and original URL
  3088. HRESULT hr;
  3089. hr = _BuildPageURLWithParam(c_sz404URL, pszURL, szResURL, ARRAYSIZE(szResURL));
  3090. if (FAILED(hr)) {
  3091. return hr;
  3092. }
  3093. // navigate deferred, caller of this Invoke() will cancel the current navigation
  3094. _DeferredNavigate(szResURL);
  3095. // have our own page, cancel the std error page:
  3096. ASSERT(pdispparams->rgvarg[0].vt == (VT_BYREF | VT_BOOL));
  3097. *V_BOOLREF(&pdispparams->rgvarg[0]) = VARIANT_TRUE;
  3098. }
  3099. // just for additional leak protection: give up proxy refs if not done already
  3100. // before we get out of current document context
  3101. if (dispidMember == DISPID_BEFORENAVIGATE)
  3102. {
  3103. _DetachProxies();
  3104. }
  3105. return S_OK;
  3106. }
  3107. LRESULT
  3108. CMediaBand::_OnVolumeCustomDraw(LPNMCUSTOMDRAW pnm)
  3109. {
  3110. RECT rcClient;
  3111. GetClientRect(pnm->hdr.hwndFrom, &rcClient);
  3112. switch (pnm->dwDrawStage)
  3113. {
  3114. case CDDS_PREPAINT:
  3115. return CDRF_NOTIFYITEMDRAW;
  3116. case CDDS_PREERASE:
  3117. return CDRF_NOTIFYITEMDRAW;
  3118. case CDDS_ITEMPREPAINT:
  3119. {
  3120. HDC hdc = (HDC)pnm->hdc;
  3121. RECT rcFill;
  3122. SendMessage(pnm->hdr.hwndFrom, TBM_GETCHANNELRECT, (WPARAM)0, (LPARAM)(LPRECT)&rcFill);
  3123. RECT rcThumb;
  3124. SendMessage(pnm->hdr.hwndFrom, TBM_GETTHUMBRECT, 0L, (LPARAM)&rcThumb);
  3125. SHFillRectClr(hdc, &rcClient, _fHiColour ? COLOR_BKGND : COLOR_BKGND16);
  3126. UINT uFlags = ILD_TRANSPARENT | (IsOS(OS_WHISTLERORGREATER) ? ILD_DPISCALE : 0);
  3127. if (_himlVolumeBack)
  3128. {
  3129. ImageList_Draw(_himlVolumeBack, 0, hdc, rcClient.left, rcClient.top, uFlags);
  3130. }
  3131. if (_himlVolumeFill)
  3132. {
  3133. ImageList_DrawEx(_himlVolumeFill, 0, hdc, rcClient.left, rcClient.top, rcThumb.left, SEEK_HEIGHT, 0, 0, uFlags);
  3134. }
  3135. if (_himlGripper)
  3136. {
  3137. ImageList_Draw(_himlGripper, 0, hdc, rcThumb.left, 0, uFlags);
  3138. }
  3139. }
  3140. return CDRF_SKIPDEFAULT;
  3141. }
  3142. return CDRF_DODEFAULT;
  3143. }
  3144. LRESULT
  3145. CMediaBand::_OnSeekBarCustomDraw(LPNMCUSTOMDRAW pnm)
  3146. {
  3147. RECT rcClient;
  3148. GetClientRect(pnm->hdr.hwndFrom, &rcClient);
  3149. switch (pnm->dwDrawStage)
  3150. {
  3151. case CDDS_PREPAINT:
  3152. return CDRF_NOTIFYITEMDRAW;
  3153. case CDDS_PREERASE:
  3154. return CDRF_NOTIFYITEMDRAW;
  3155. case CDDS_ITEMPREPAINT:
  3156. {
  3157. HDC hdc = (HDC)pnm->hdc;
  3158. SHFillRectClr(hdc, &rcClient, _fHiColour ? COLOR_BKGND2 : COLOR_BKGND16);
  3159. RECT rcFill;
  3160. SendMessage(pnm->hdr.hwndFrom, TBM_GETCHANNELRECT, (WPARAM)0, (LPARAM)(LPRECT)&rcFill);
  3161. RECT rcThumb;
  3162. SendMessage(pnm->hdr.hwndFrom, TBM_GETTHUMBRECT, 0L, (LPARAM)&rcThumb);
  3163. int x, y = 1+(SEEK_HEIGHT-SEEK_PART_HEIGHT)/2;
  3164. UINT uFlags = ILD_TRANSPARENT | (IsOS(OS_WHISTLERORGREATER) ? ILD_DPISCALE : 0);
  3165. // always draw background with progress
  3166. if (_himlSeekBack)
  3167. {
  3168. INT lPartWidth = SCALEX(SEEK_PART_WIDTH);
  3169. x = rcFill.left;
  3170. ImageList_Draw(_himlSeekBack, 0, hdc, x, y, uFlags);
  3171. x = rcFill.right - lPartWidth;
  3172. int inx = rcFill.left + lPartWidth;
  3173. while (inx < x)
  3174. {
  3175. ImageList_Draw(_himlSeekBack, 1, hdc, inx, y, uFlags);
  3176. inx += lPartWidth;
  3177. }
  3178. ImageList_Draw(_himlSeekBack, 2, hdc, x, y, uFlags);
  3179. }
  3180. if (pnm->dwItemSpec==TBCD_THUMB)
  3181. {
  3182. if ((!(pnm->uItemState & CDIS_DISABLED)) && ISVALIDWIDGET(_pmwSeek) && _pmwSeek->IsEnabled())
  3183. {
  3184. x = rcFill.left;
  3185. int seekWidth = rcThumb.left-x;
  3186. if (_himlSeekFill && seekWidth)
  3187. {
  3188. if (seekWidth < SEEK_PART_WIDTH)
  3189. {
  3190. ImageList_DrawEx(_himlSeekFill, 0, hdc, x, y, seekWidth, SEEK_PART_HEIGHT, 0, 0, uFlags);
  3191. }
  3192. else
  3193. {
  3194. ImageList_Draw(_himlSeekFill, 0, hdc, x, y, uFlags);
  3195. x += SEEK_PART_WIDTH;
  3196. while ((rcThumb.left-x)>0)
  3197. {
  3198. ImageList_DrawEx(_himlSeekFill, 1, hdc, x, y, min(SEEK_PART_WIDTH, (rcThumb.left-x)), SEEK_PART_HEIGHT, 0, 0, uFlags);
  3199. x += SEEK_PART_WIDTH;
  3200. }
  3201. }
  3202. }
  3203. INT iState = MWB_NORMAL;
  3204. if (pnm->uItemState & CDIS_SELECTED)
  3205. {
  3206. iState = MWB_PRESSED;
  3207. }
  3208. else if (pnm->uItemState & CDIS_HOT)
  3209. {
  3210. iState = MWB_HOT;
  3211. }
  3212. if (_himlGripper)
  3213. {
  3214. ImageList_Draw(_himlGripper, iState, hdc, rcThumb.left, 0, uFlags);
  3215. }
  3216. }
  3217. }
  3218. }
  3219. return CDRF_SKIPDEFAULT;
  3220. }
  3221. return CDRF_DODEFAULT;
  3222. }
  3223. LONG
  3224. CMediaBand::GetPopoutHeight(BOOL fMeasureVideo, LONG lWidth)
  3225. {
  3226. LONG lHeight = (fMeasureVideo ? GetLayoutHeight(lWidth) : GetControlsHeight())
  3227. + GetSystemMetrics(SM_CYSIZE)
  3228. + GetSystemMetrics(SM_CYEDGE)*2
  3229. + GetSystemMetrics(SM_CYSIZEFRAME)*2;
  3230. return lHeight;
  3231. }
  3232. LONG
  3233. CMediaBand::GetMinPopoutWidth()
  3234. {
  3235. return MIN_POPOUT_WIDTH + (GetSystemMetrics(SM_CXBORDER) + GetSystemMetrics(SM_CXFRAME))*2;
  3236. }
  3237. BOOL
  3238. CMediaBand::ResetPlayer()
  3239. {
  3240. _iCurTrack = -1;
  3241. _fPlaying = FALSE;
  3242. if (ISVALIDWIDGET(_pmwSeek))
  3243. {
  3244. _pmwSeek->SetState(FALSE);
  3245. }
  3246. if (_pMediaPlayer)
  3247. {
  3248. _pMediaPlayer->Stop();
  3249. SetSeekPos(0.0);
  3250. TogglePlayPause();
  3251. if (_hwndVideo && IsWindowVisible(_hwndVideo))
  3252. {
  3253. _fIsVideo = FALSE;
  3254. ShowWindow(_hwndVideo, SW_HIDE);
  3255. }
  3256. AdjustVideoHeight(TRUE);
  3257. }
  3258. TCHAR szTitle[MAX_PATH];
  3259. MLLoadStringW(IDS_MEDIABAND_MYMUSIC, szTitle, ARRAYSIZE(szTitle));
  3260. SetStatusText(szTitle);
  3261. SetPlayerControl(FCIDM_MEDIABAND_PREVIOUS, FALSE);
  3262. SetPlayerControl(FCIDM_MEDIABAND_NEXT, FALSE);
  3263. // while timer is running , give user a second chance to click stop again and reset media content pane
  3264. if (_idStopTimer == 0)
  3265. {
  3266. SetPlayerControl(FCIDM_MEDIABAND_STOP, FALSE);
  3267. }
  3268. SetPlayPause(TRUE);
  3269. return TRUE;
  3270. }
  3271. HRESULT CMediaBand::PlayLocalTrack(int iTrackNum)
  3272. {
  3273. HRESULT hr = E_FAIL;
  3274. if (_ppidls && (iTrackNum < (int)_cidls))
  3275. {
  3276. // to avoid pot. privacy leak, unload mediabar behavior
  3277. if (_IsProxyRunning())
  3278. {
  3279. // user clicked on a media link in the main content pane, unfreeze controls!
  3280. _OnUserOverrideDisableUI();
  3281. _DetachProxies();
  3282. _NavigateContentToDefaultURL();
  3283. }
  3284. TCHAR szFile[MAX_PATH];
  3285. if (SUCCEEDED(SHGetNameAndFlags(_ppidls[iTrackNum], SHGDN_FORPARSING, szFile, ARRAYSIZE(szFile), NULL)))
  3286. {
  3287. _iCurTrack = iTrackNum;
  3288. if (EnsurePlayer())
  3289. _PutUrl(szFile, NULL);
  3290. hr = S_OK;
  3291. }
  3292. }
  3293. return hr;
  3294. }
  3295. HRESULT CMediaBand::PlayNextTrack()
  3296. {
  3297. if (EnsurePlayer() && (_iCurTrack != -1))
  3298. {
  3299. LONG_PTR lCurTrack = _pMediaPlayer->GetPlayListItemIndex();
  3300. LONG_PTR lItemCount = _pMediaPlayer->GetPlayListItemCount();
  3301. if ((lItemCount <= 1) || (lCurTrack == lItemCount - 1))
  3302. {
  3303. PlayLocalTrack(_iCurTrack + 1);
  3304. }
  3305. else
  3306. {
  3307. ResetPlayer();
  3308. }
  3309. }
  3310. return S_OK;
  3311. }
  3312. BOOL CMediaBand::SetPlayerControl(UINT ui, BOOL fState)
  3313. {
  3314. CMediaWidget* pmw = NULL;
  3315. switch (ui)
  3316. {
  3317. case FCIDM_MEDIABAND_PREVIOUS:
  3318. // while UI frozen by mediabar behavior, previous is always disabled
  3319. if (fState && _pMediaPlayer)
  3320. {
  3321. fState = _pMediaPlayer->IsSkippable();
  3322. }
  3323. if (_isUIDisabled())
  3324. {
  3325. fState = FALSE; // override to always disable
  3326. }
  3327. pmw = _pmwBack;
  3328. break;
  3329. case FCIDM_MEDIABAND_NEXT:
  3330. // only override if any of the proxies are running
  3331. if (fState && _pMediaPlayer)
  3332. {
  3333. fState = _pMediaPlayer->IsSkippable();
  3334. }
  3335. if (_apContentProxies != NULL)
  3336. {
  3337. if (_isUIDisabled() && _pMediaPlayer && !_pMediaPlayer->IsSeekPossible())
  3338. {
  3339. fState = FALSE;
  3340. }
  3341. // only force a disabled next button if stream has NOSKIP attribute set
  3342. if (!_isProxiesNextEnabled())
  3343. {
  3344. fState = FALSE;
  3345. }
  3346. }
  3347. pmw = _pmwNext;
  3348. break;
  3349. case FCIDM_MEDIABAND_STOP:
  3350. pmw = _pmwStop;
  3351. break;
  3352. default:
  3353. ASSERT(FALSE);
  3354. break;
  3355. }
  3356. if (pmw && pmw->_hwnd)
  3357. {
  3358. SendMessage(pmw->_hwnd, TB_ENABLEBUTTON, ui, MAKELONG(fState, 0));
  3359. }
  3360. return TRUE;
  3361. }
  3362. BOOL
  3363. CMediaBand::UpdateBackForwardControls()
  3364. {
  3365. BOOL fPrevious = FALSE, fNext = FALSE;
  3366. if (_iCurTrack != -1)
  3367. {
  3368. fPrevious = _iCurTrack != 0;
  3369. fNext = ((_iCurTrack + 1) < (int)_cidls);
  3370. }
  3371. else if (EnsurePlayer())
  3372. {
  3373. LONG_PTR lItemCount= _pMediaPlayer->GetPlayListItemCount();
  3374. if (lItemCount > 1)
  3375. {
  3376. LONG_PTR lCurTrack = _pMediaPlayer->GetPlayListItemIndex();
  3377. fPrevious = (lCurTrack > 0);
  3378. fNext = lCurTrack < lItemCount - 1;
  3379. }
  3380. }
  3381. SetPlayerControl(FCIDM_MEDIABAND_PREVIOUS, fPrevious);
  3382. SetPlayerControl(FCIDM_MEDIABAND_NEXT, fNext);
  3383. return TRUE;
  3384. }
  3385. HRESULT
  3386. CMediaBand::Seek(double dblProgress)
  3387. {
  3388. HRESULT hr = S_OK;
  3389. if (EnsurePlayer())
  3390. {
  3391. hr = _pMediaPlayer->Seek(dblProgress);
  3392. if (SUCCEEDED(hr))
  3393. {
  3394. // play/pause state may have been changed by Seek
  3395. TogglePlayPause();
  3396. }
  3397. }
  3398. return hr;
  3399. }
  3400. LPTSTR
  3401. CMediaBand::GetUrlForStatusBarToolTip()
  3402. {
  3403. USES_CONVERSION;
  3404. LPTSTR szRet = NULL;
  3405. if (_pMediaPlayer)
  3406. {
  3407. if (_pMediaPlayer->isStopped())
  3408. {
  3409. return _pszStatus;
  3410. }
  3411. CComBSTR sbstrUrl;
  3412. HRESULT hr = _pMediaPlayer->get_url(&sbstrUrl);
  3413. if ( SUCCEEDED(hr)
  3414. && (sbstrUrl.m_str)
  3415. && (sbstrUrl.Length()>0))
  3416. {
  3417. szRet = W2T(sbstrUrl);
  3418. if (szRet)
  3419. {
  3420. //
  3421. // The tooltip structure (NMTTDISPINFO.lpszText) requires a pointer to a private buffer.
  3422. // Store the pointer so we can free it later.
  3423. //
  3424. int len = lstrlen(szRet);
  3425. delete [] _szToolTipUrl;
  3426. _szToolTipUrl = new TCHAR[len + 1];
  3427. if (_szToolTipUrl)
  3428. {
  3429. memcpy(_szToolTipUrl, szRet, sizeof(TCHAR) * (len + 1));
  3430. }
  3431. szRet = _szToolTipUrl;
  3432. }
  3433. }
  3434. }
  3435. return szRet;
  3436. }
  3437. VOID CMediaBand::UpdateMenuItems(HMENU hmenu)
  3438. {
  3439. ASSERT(hmenu);
  3440. CComBSTR sbstrUrl;
  3441. if (GetAutoplay())
  3442. {
  3443. CheckMenuItem(hmenu, IDM_MEDIA_PLAYINBAR, MF_BYCOMMAND | MF_CHECKED);
  3444. }
  3445. if (GetAutoplayPrompt())
  3446. {
  3447. CheckMenuItem(hmenu, IDM_MEDIA_ASKTYPES, MF_BYCOMMAND | MF_CHECKED);
  3448. }
  3449. if (!_pMediaPlayer || _pMediaPlayer->isStopped() || FAILED(_pMediaPlayer->get_url(&sbstrUrl)) || !sbstrUrl.m_str || (sbstrUrl.Length()<=0) || _isUIDisabled())
  3450. {
  3451. DeleteMenu(hmenu, IDM_MEDIA_PLAYINDEFAULT, MF_BYCOMMAND);
  3452. DeleteMenu(hmenu, IDM_MEDIA_ADDTOFAVORITES, MF_BYCOMMAND);
  3453. DeleteMenu(hmenu, 0, MF_BYPOSITION);
  3454. }
  3455. }
  3456. BOOL CMediaBand::OnNotify(LPNMHDR pnm, LRESULT* plres)
  3457. {
  3458. ASSERT(plres);
  3459. BOOL fRet = FALSE;
  3460. switch (pnm->code)
  3461. {
  3462. case NM_CUSTOMDRAW:
  3463. {
  3464. LRESULT lres;
  3465. LPNMCUSTOMDRAW pnmc = (LPNMCUSTOMDRAW)pnm;
  3466. if (pnm->hwndFrom == _hwndVolume)
  3467. {
  3468. lres = _OnVolumeCustomDraw(pnmc);
  3469. }
  3470. else if (pnm->hwndFrom == _hwndSeek)
  3471. {
  3472. lres = _OnSeekBarCustomDraw(pnmc);
  3473. }
  3474. else
  3475. {
  3476. for (int i=0; i<ARRAYSIZE(_pmw); i++)
  3477. {
  3478. if (_pmw[i] && (pnm->hwndFrom == _pmw[i]->_hwnd))
  3479. {
  3480. lres = _pmw[i]->Draw((LPNMTBCUSTOMDRAW)pnm);
  3481. }
  3482. }
  3483. }
  3484. fRet = TRUE;
  3485. *plres = lres;
  3486. }
  3487. break;
  3488. case TBN_DROPDOWN:
  3489. {
  3490. LPNMTOOLBAR lpnmTB = ((LPNMTOOLBAR)pnm);
  3491. HWND hwndTB = pnm->hwndFrom;
  3492. UINT nCmdID = lpnmTB->iItem;
  3493. // figure out coordinates to use
  3494. INT_PTR iBtn = SendMessage(hwndTB, TB_GETHOTITEM, 0, 0);
  3495. RECTL rc ;
  3496. SendMessage(hwndTB, TB_GETITEMRECT, iBtn, (LPARAM)&rc);
  3497. MapWindowPoints(hwndTB, HWND_DESKTOP, (LPPOINT)&rc , 2);
  3498. if (_pmwOptions && hwndTB==_pmwOptions->_hwnd)
  3499. {
  3500. if (_pMediaPlayer && (_pMediaPlayer->GetPlayListItemCount() > 0) && !_pMediaPlayer->isStopped() && !_isUIDisabled() && _pMediaPlayer->IsSkippable())
  3501. {
  3502. ShowPlayListMenu(hwndTB, &rc);
  3503. }
  3504. else
  3505. {
  3506. ShowGenericMenu(hwndTB, &rc);
  3507. }
  3508. }
  3509. else
  3510. {
  3511. VARIANTARG var;
  3512. var.vt = VT_I4;
  3513. var.lVal = MAKELONG(rc.left, rc.bottom);
  3514. *plres = Exec(&CLSID_MediaBand, nCmdID, 0, &var, NULL);
  3515. fRet = TRUE;
  3516. } // end of else
  3517. }
  3518. break;
  3519. case TBN_GETDISPINFO:
  3520. {
  3521. LPNMTBDISPINFO lptbi = (LPNMTBDISPINFO)pnm;
  3522. if (lptbi->hdr.hwndFrom == _pmwPlay->_hwnd && lptbi->dwMask & TBNF_IMAGE)
  3523. {
  3524. TBBUTTONINFO tbbi;
  3525. tbbi.dwMask = TBIF_COMMAND | TBIF_STATE;
  3526. SendMessage(lptbi->hdr.hwndFrom, TB_GETBUTTONINFO, (WPARAM)lptbi->idCommand, (LPARAM)&tbbi);
  3527. if (_fPlayButton)
  3528. lptbi->iImage = (!(tbbi.fsState & TBSTATE_INDETERMINATE) && (tbbi.fsState & TBSTATE_PRESSED)) ? 3 : 1 ;
  3529. else
  3530. lptbi->iImage = (!(tbbi.fsState & TBSTATE_INDETERMINATE) && (tbbi.fsState & TBSTATE_PRESSED)) ? 2 : 0 ;
  3531. lptbi->dwMask |= TBNF_DI_SETITEM;
  3532. }
  3533. else if (_pmwOptions && (lptbi->hdr.hwndFrom ==_pmwOptions->_hwnd))
  3534. {
  3535. lptbi->iImage = 0;
  3536. lptbi->dwMask |= TBNF_DI_SETITEM;
  3537. }
  3538. }
  3539. break;
  3540. case TTN_GETDISPINFO:
  3541. {
  3542. LPNMTTDISPINFO pnmtt = (LPNMTTDISPINFO)pnm;
  3543. pnmtt->hinst = MLGetHinst();
  3544. switch (pnmtt->hdr.idFrom)
  3545. {
  3546. case FCIDM_MEDIABAND_POPOUT:
  3547. pnmtt->lpszText = (PTSTR)MAKEINTRESOURCE(_hwndPopup ? IDS_MEDIABAND_DOCK : IDS_MEDIABAND_UNDOCK);
  3548. break;
  3549. case FCIDM_MEDIABAND_PLAY:
  3550. pnmtt->lpszText = (PTSTR)MAKEINTRESOURCE(_fPlayButton ? IDS_MEDIABAND_PLAY : IDS_MEDIABAND_PAUSE);
  3551. break;
  3552. case FCIDM_MEDIABAND_MUTE:
  3553. pnmtt->lpszText = (PTSTR)MAKEINTRESOURCE(_fMuted ? IDS_MEDIABAND_UNMUTE : IDS_MEDIABAND_MUTE);
  3554. break;
  3555. case FCIDM_MEDIABAND_PLAYINFO:
  3556. {
  3557. if (_pMediaPlayer && !_isUIDisabled())
  3558. {
  3559. LPTSTR szUrl = GetUrlForStatusBarToolTip();
  3560. if (szUrl)
  3561. {
  3562. pnmtt->lpszText = szUrl;
  3563. }
  3564. }
  3565. break;
  3566. }
  3567. }
  3568. }
  3569. }
  3570. return fRet;
  3571. }
  3572. HRESULT
  3573. CMediaBand::_OpenInDefaultPlayer(BSTR bstrUrl)
  3574. {
  3575. HRESULT hr = E_FAIL;
  3576. if ( !bstrUrl
  3577. || !(*bstrUrl))
  3578. {
  3579. hr = E_FAIL;
  3580. goto done;
  3581. }
  3582. // suppress first autoplay and navigate main IE window
  3583. hr = _NavigateMainWindow(bstrUrl, true);
  3584. if (FAILED(hr))
  3585. {
  3586. goto done;
  3587. }
  3588. if (_hwndPopup && IsWindowVisible(_hwndPopup))
  3589. {
  3590. DockMediaPlayer();
  3591. }
  3592. // pause/stop the playback
  3593. if (_pMediaPlayer->IsPausePossible())
  3594. {
  3595. _pMediaPlayer->Pause();
  3596. }
  3597. else
  3598. {
  3599. _pMediaPlayer->Stop();
  3600. }
  3601. hr = S_OK;
  3602. done:
  3603. return hr;
  3604. }
  3605. VOID
  3606. CMediaBand::SetPlayPause(BOOL fState)
  3607. {
  3608. _fPlayEnabled = fState;
  3609. if (_pmwPlay && _pmwPlay->_hwnd)
  3610. {
  3611. SendMessage(_pmwPlay->_hwnd, TB_SETSTATE, FCIDM_MEDIABAND_PLAY, MAKELONG((_fPlayEnabled ? TBSTATE_ENABLED : 0), 0));
  3612. InvalidateRect(_pmwPlay->_hwnd, NULL, FALSE);
  3613. UpdateWindow(_pmwPlay->_hwnd);
  3614. }
  3615. }
  3616. INT idNormalHi[MW_NUMBER] =
  3617. {
  3618. IDB_MEDIABAND_PLAY, // MW_PLAY = 0,
  3619. IDB_MEDIABAND_STOP, // MW_STOP,
  3620. IDB_MEDIABAND_BACK, // MW_BACK,
  3621. IDB_MEDIABAND_NEXT, // MW_NEXT,
  3622. IDB_MEDIABAND_MUTE, // MW_MUTE,
  3623. IDB_MEDIABAND_VOLBKGND, // MW_VOLUME,
  3624. 0, // MW_OPTIONS,
  3625. IDB_MEDIABAND_POPOUT, // MW_POP,
  3626. IDB_MEDIABAND_SEEKBACK, // MW_SEEK,
  3627. };
  3628. INT idAltHi[MW_NUMBER] =
  3629. {
  3630. IDB_MEDIABAND_PAUSE, // MW_PLAY = 0,
  3631. 0, // MW_STOP,
  3632. 0, // MW_BACK,
  3633. 0, // MW_NEXT,
  3634. 0, // MW_MUTE,
  3635. IDB_MEDIABAND_VOLFILL, // MW_VOLUME,
  3636. 0, // MW_OPTIONS,
  3637. IDB_MEDIABAND_POPIN, // MW_POP,
  3638. IDB_MEDIABAND_SEEKFILL, // MW_SEEK,
  3639. };
  3640. INT idNormalLo[MW_NUMBER] =
  3641. {
  3642. IDB_MEDIABAND_PLAY16, // MW_PLAY = 0,
  3643. IDB_MEDIABAND_STOP16, // MW_STOP,
  3644. IDB_MEDIABAND_BACK16, // MW_BACK,
  3645. IDB_MEDIABAND_NEXT16, // MW_NEXT,
  3646. IDB_MEDIABAND_MUTE16, // MW_MUTE,
  3647. IDB_MEDIABAND_VOLBKGND16, // MW_VOLUME,
  3648. 0, // MW_OPTIONS,
  3649. IDB_MEDIABAND_POPOUT16, // MW_POP,
  3650. IDB_MEDIABAND_SEEKBACK16, // MW_SEEK,
  3651. };
  3652. INT idAltLo[MW_NUMBER] =
  3653. {
  3654. IDB_MEDIABAND_PAUSE16, // MW_PLAY = 0,
  3655. 0, // MW_STOP,
  3656. 0, // MW_BACK,
  3657. 0, // MW_NEXT,
  3658. 0, // MW_MUTE,
  3659. IDB_MEDIABAND_VOLFILL16, // MW_VOLUME,
  3660. 0, // MW_OPTIONS,
  3661. IDB_MEDIABAND_POPIN16, // MW_POP,
  3662. IDB_MEDIABAND_SEEKFILL16, // MW_SEEK,
  3663. };
  3664. VOID
  3665. CMediaBand::SwitchBitmaps(BOOL fNewSetting)
  3666. {
  3667. INT* idAlt = fNewSetting ? idAltHi : idAltLo;
  3668. INT* idNormal = fNewSetting ? idNormalHi : idNormalLo;
  3669. for (int i=0; i<MW_NUMBER; i++)
  3670. {
  3671. if (ISVALIDWIDGET(_pmw[i]))
  3672. {
  3673. switch (i)
  3674. {
  3675. case MW_SEEK:
  3676. DESTROY_OBJ_WITH_HANDLE(_himlSeekBack, ImageList_Destroy);
  3677. DESTROY_OBJ_WITH_HANDLE(_himlSeekFill, ImageList_Destroy);
  3678. _himlSeekBack = ImageList_LoadImage(HINST_THISDLL, MAKEINTRESOURCE(idNormal[i]), SEEK_PART_WIDTH, 0, crMask,
  3679. IMAGE_BITMAP, LR_CREATEDIBSECTION);
  3680. _himlSeekFill = ImageList_LoadImage(HINST_THISDLL, MAKEINTRESOURCE(idAlt[i]), SEEK_PART_WIDTH, 0, crMask,
  3681. IMAGE_BITMAP, LR_CREATEDIBSECTION);
  3682. break;
  3683. case MW_OPTIONS:
  3684. {
  3685. CMediaWidgetOptions* pmwb = (CMediaWidgetOptions*)_pmw[i];
  3686. pmwb->SetDepth(fNewSetting);
  3687. }
  3688. break;
  3689. case MW_VOLUME:
  3690. DESTROY_OBJ_WITH_HANDLE(_himlVolumeBack, ImageList_Destroy);
  3691. DESTROY_OBJ_WITH_HANDLE(_himlVolumeFill, ImageList_Destroy);
  3692. DESTROY_OBJ_WITH_HANDLE(_himlGripper, ImageList_Destroy);
  3693. _himlVolumeBack = ImageList_LoadImage(HINST_THISDLL, MAKEINTRESOURCE(idNormal[i]), VOLUME_BITMAP_WIDTH, 0, crMask,
  3694. IMAGE_BITMAP, LR_CREATEDIBSECTION);
  3695. _himlVolumeFill = ImageList_LoadImage(HINST_THISDLL, MAKEINTRESOURCE(idAlt[i]), VOLUME_BITMAP_WIDTH, 0, crMask,
  3696. IMAGE_BITMAP, LR_CREATEDIBSECTION);
  3697. _himlGripper = ImageList_LoadImage(HINST_THISDLL, MAKEINTRESOURCE(fNewSetting ? IDB_MEDIABAND_VOLTAB : IDB_MEDIABAND_VOLTAB16), 6, 0, crMask,
  3698. IMAGE_BITMAP, LR_CREATEDIBSECTION);
  3699. break;
  3700. default:
  3701. // The rest are buttons
  3702. {
  3703. CMediaWidgetButton* pmwb = (CMediaWidgetButton*)_pmw[i];
  3704. pmwb->SetImageList(idNormal[i]);
  3705. if (idAlt[i])
  3706. {
  3707. pmwb->SetAlternateImageList(idAlt[i]);
  3708. }
  3709. }
  3710. break;
  3711. }
  3712. }
  3713. }
  3714. _fHiColour = fNewSetting;
  3715. InvalidateRect(_hwnd, NULL, TRUE);
  3716. UpdateWindow(_hwnd);
  3717. }
  3718. VOID
  3719. CMediaBand::InitContentPane()
  3720. {
  3721. SHDRC shdrc = {sizeof(SHDRC), SHDRCF_OCHOST};
  3722. shdrc.cbSize = sizeof (SHDRC);
  3723. shdrc.dwFlags |= SHDRCF_OCHOST;
  3724. if (_hwnd && IsWindow(_hwnd) && DllRegisterWindowClasses(&shdrc))
  3725. {
  3726. // Create an OCHost window
  3727. _hwndContent = CreateWindow(OCHOST_CLASS, NULL,
  3728. WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_TABSTOP,
  3729. 0, 0, 0, 0,
  3730. _hwnd, NULL, HINST_THISDLL, NULL);
  3731. if (_hwndContent)
  3732. {
  3733. OCHINITSTRUCT ocs;
  3734. ocs.cbSize = SIZEOF(OCHINITSTRUCT);
  3735. ocs.clsidOC = CLSID_WebBrowser;
  3736. ocs.punkOwner = SAFECAST(this, IDispatch*);
  3737. if (SUCCEEDED(OCHost_InitOC(_hwndContent, (LPARAM)&ocs)))
  3738. {
  3739. OCHost_QueryInterface(_hwndContent, IID_PPV_ARG(IWebBrowser2, &_spBrowser));
  3740. OCHost_QueryInterface(_hwndContent, IID_PPV_ARG(IOleInPlaceActiveObject, &_poipao));
  3741. OCHost_DoVerb(_hwndContent, OLEIVERB_INPLACEACTIVATE, FALSE);
  3742. _ConnectToCP(TRUE);
  3743. }
  3744. _NavigateContentToDefaultURL();
  3745. }
  3746. }
  3747. }
  3748. HRESULT
  3749. CMediaBand::_ConnectToCP(BOOL fConnect)
  3750. {
  3751. // get ready to sink the OCHost's browser events
  3752. if (!_spBrowser)
  3753. {
  3754. return E_FAIL;
  3755. }
  3756. if (!fConnect && (_dwcpCookie == 0))
  3757. {
  3758. return S_FALSE; //
  3759. }
  3760. return ConnectToConnectionPoint(SAFECAST(this, IDispatch*), DIID_DWebBrowserEvents2, fConnect, _spBrowser, &_dwcpCookie, NULL);
  3761. }
  3762. HRESULT CMediaBand::NavigateContentPane(BSTR bstrUrl)
  3763. {
  3764. HRESULT hr = E_FAIL;
  3765. if (_spBrowser && bstrUrl)
  3766. {
  3767. _strCurrentContentUrl = bstrUrl;
  3768. CComVariant svarEmpty;
  3769. svarEmpty.vt = VT_NULL;
  3770. hr = _spBrowser->Navigate(bstrUrl, &svarEmpty, &svarEmpty, &svarEmpty, &svarEmpty);
  3771. }
  3772. return hr;
  3773. }
  3774. HRESULT CMediaBand::NavigateContentPane(LPCITEMIDLIST pidl)
  3775. {
  3776. HRESULT hr = E_FAIL;
  3777. if (_spBrowser && pidl)
  3778. {
  3779. TCHAR szURL[MAX_URL_STRING];
  3780. if (SUCCEEDED(::IEGetDisplayName(pidl, szURL, SHGDN_FORPARSING)))
  3781. {
  3782. _strCurrentContentUrl = szURL;
  3783. }
  3784. else
  3785. {
  3786. _strCurrentContentUrl.Empty();
  3787. }
  3788. CComVariant svarEmpty;
  3789. svarEmpty.vt = VT_NULL;
  3790. CComVariant varURL;
  3791. InitVariantFromIDList(&varURL, pidl);
  3792. hr = _spBrowser->Navigate2(&varURL, &svarEmpty, &svarEmpty, &svarEmpty, &svarEmpty);
  3793. }
  3794. return hr;
  3795. }
  3796. VOID CMediaBand::NavigateMoreMedia()
  3797. {
  3798. _NavigateMainWindow(c_szMoreMediaUrl);
  3799. }
  3800. HRESULT CMediaBand::_NavigateContentToDefaultURL()
  3801. {
  3802. TCHAR szResURL[2*MAX_URL_STRING]; // expect URL to help page and original URL
  3803. HRESULT hr;
  3804. LPCTSTR pszStartURL = NULL;
  3805. // load inital page, this is always a local resource
  3806. BOOL fSuppressOnline = SHRegGetBoolUSValue(REG_MEDIA_STR, TEXT("SuppressOnlineContent"), FALSE, FALSE);
  3807. BOOL fStayOffline = SHIsGlobalOffline()
  3808. || fSuppressOnline
  3809. || SHRestricted2W(REST_No_MediaBarOnlineContent, NULL, 0);
  3810. // ISSUE/010426/davidjen with the restriction set,
  3811. // do we need a second offline page without external links, only MyMusic???????????????
  3812. if (fStayOffline)
  3813. {
  3814. pszStartURL = c_szOfflineURL;
  3815. }
  3816. else
  3817. {
  3818. pszStartURL = c_szLoadingURL;
  3819. }
  3820. hr = _BuildPageURLWithParam(pszStartURL, NULL, szResURL, ARRAYSIZE(szResURL));
  3821. if (FAILED(hr))
  3822. {
  3823. StrCpyN(szResURL, c_szOfflineURL, ARRAYSIZE(szResURL));
  3824. hr = S_OK;
  3825. }
  3826. NavigateContentPane(szResURL);
  3827. // if online, try navigating to windowsmedia.com
  3828. if (!fStayOffline)
  3829. {
  3830. _DeferredNavigate(c_szContentUrl);
  3831. }
  3832. return S_OK;
  3833. }
  3834. HRESULT
  3835. CMediaBand::_BuildPageURLWithParam(LPCTSTR pszURL, LPCTSTR pszParam, OUT LPTSTR pszBuffer, UINT uiBufSize)
  3836. {
  3837. USES_CONVERSION;
  3838. // build a string of the form: "res://d:\winnt\system32\browselc.dll\helppage.htm#http://www.windowsmedia.com/xyz.html"
  3839. HRESULT hr = S_OK;
  3840. ASSERT(pszBuffer);
  3841. hr = MLBuildResURLWrap(TEXT("browselc.dll"), HINST_THISDLL, ML_CROSSCODEPAGE,
  3842. T2W((LPTSTR)pszURL), pszBuffer, uiBufSize, TEXT("browseui.dll"));
  3843. if (SUCCEEDED(hr) && pszParam && (lstrlen(pszParam) > 0))
  3844. {
  3845. StrCatBuff(pszBuffer, TEXT("#"), uiBufSize);
  3846. StrCatBuff(pszBuffer, pszParam, uiBufSize);
  3847. }
  3848. return hr;
  3849. }
  3850. BOOL CMediaBand::_DeferredNavigate(LPCTSTR pszURL)
  3851. {
  3852. ASSERT(_strDeferredURL.Length() == 0);
  3853. _strDeferredURL = pszURL;
  3854. return PostMessage(_hwnd, WM_MB_DEFERRED_NAVIGATE, 0, (LPARAM) _hwnd);
  3855. }