Team Fortress 2 Source Code as on 22/4/2020
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.

584 lines
16 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. // CWMPEventDispatch.cpp : Implementation of the event dispatcher
  3. //
  4. #include "CWMPEventDispatch.h"
  5. #include "CWMPHost.h"
  6. extern HWND g_hBlackFadingWindow;
  7. extern CComPtr<IWMPPlayer> g_spWMPPlayer;
  8. extern CWMPHost* g_pFrame;
  9. extern double g_timeAtFadeStart;
  10. extern bool g_bFadeIn;
  11. bool g_bFadeWindowTriggered = false;
  12. bool IsFullScreen();
  13. bool SetFullScreen( bool bWantToBeFullscreen );
  14. bool IsVideoPlaying();
  15. void PlayVideo( bool bPlay );
  16. bool ShowFadeWindow( bool bShow );
  17. void LogPlayerEvent( EventType_t e, float pos );
  18. void LogPlayerEvent( EventType_t e );
  19. HRESULT CWMPEventDispatch::Invoke(
  20. DISPID dispIdMember,
  21. REFIID riid,
  22. LCID lcid,
  23. WORD wFlags,
  24. DISPPARAMS FAR* pDispParams,
  25. VARIANT FAR* pVarResult,
  26. EXCEPINFO FAR* pExcepInfo,
  27. unsigned int FAR* puArgErr )
  28. {
  29. if (!pDispParams)
  30. return E_POINTER;
  31. if (pDispParams->cNamedArgs != 0)
  32. return DISP_E_NONAMEDARGS;
  33. HRESULT hr = DISP_E_MEMBERNOTFOUND;
  34. switch (dispIdMember)
  35. {
  36. case DISPID_WMPCOREEVENT_OPENSTATECHANGE:
  37. OpenStateChange(pDispParams->rgvarg[0].lVal /* NewState */ );
  38. break;
  39. case DISPID_WMPCOREEVENT_PLAYSTATECHANGE:
  40. PlayStateChange(pDispParams->rgvarg[0].lVal /* NewState */);
  41. break;
  42. case DISPID_WMPCOREEVENT_AUDIOLANGUAGECHANGE:
  43. AudioLanguageChange(pDispParams->rgvarg[0].lVal /* LangID */);
  44. break;
  45. case DISPID_WMPCOREEVENT_STATUSCHANGE:
  46. StatusChange();
  47. break;
  48. case DISPID_WMPCOREEVENT_SCRIPTCOMMAND:
  49. ScriptCommand(pDispParams->rgvarg[1].bstrVal /* scType */, pDispParams->rgvarg[0].bstrVal /* Param */ );
  50. break;
  51. case DISPID_WMPCOREEVENT_NEWSTREAM:
  52. NewStream();
  53. break;
  54. case DISPID_WMPCOREEVENT_DISCONNECT:
  55. Disconnect(pDispParams->rgvarg[0].lVal /* Result */ );
  56. break;
  57. case DISPID_WMPCOREEVENT_BUFFERING:
  58. Buffering(pDispParams->rgvarg[0].boolVal /* Start */);
  59. break;
  60. case DISPID_WMPCOREEVENT_ERROR:
  61. Error();
  62. break;
  63. case DISPID_WMPCOREEVENT_WARNING:
  64. Warning(pDispParams->rgvarg[1].lVal /* WarningType */, pDispParams->rgvarg[0].lVal /* Param */, pDispParams->rgvarg[2].bstrVal /* Description */);
  65. break;
  66. case DISPID_WMPCOREEVENT_ENDOFSTREAM:
  67. EndOfStream(pDispParams->rgvarg[0].lVal /* Result */ );
  68. break;
  69. case DISPID_WMPCOREEVENT_POSITIONCHANGE:
  70. PositionChange(pDispParams->rgvarg[1].dblVal /* oldPosition */, pDispParams->rgvarg[0].dblVal /* newPosition */);
  71. break;
  72. case DISPID_WMPCOREEVENT_MARKERHIT:
  73. MarkerHit(pDispParams->rgvarg[0].lVal /* MarkerNum */);
  74. break;
  75. case DISPID_WMPCOREEVENT_DURATIONUNITCHANGE:
  76. DurationUnitChange(pDispParams->rgvarg[0].lVal /* NewDurationUnit */);
  77. break;
  78. case DISPID_WMPCOREEVENT_CDROMMEDIACHANGE:
  79. CdromMediaChange(pDispParams->rgvarg[0].lVal /* CdromNum */);
  80. break;
  81. case DISPID_WMPCOREEVENT_PLAYLISTCHANGE:
  82. PlaylistChange(pDispParams->rgvarg[1].pdispVal /* Playlist */, (WMPPlaylistChangeEventType) pDispParams->rgvarg[0].lVal /* change */);
  83. break;
  84. case DISPID_WMPCOREEVENT_CURRENTPLAYLISTCHANGE:
  85. CurrentPlaylistChange((WMPPlaylistChangeEventType) pDispParams->rgvarg[0].lVal /* change */);
  86. break;
  87. case DISPID_WMPCOREEVENT_CURRENTPLAYLISTITEMAVAILABLE:
  88. CurrentPlaylistItemAvailable(pDispParams->rgvarg[0].bstrVal /* bstrItemName */);
  89. break;
  90. case DISPID_WMPCOREEVENT_MEDIACHANGE:
  91. MediaChange(pDispParams->rgvarg[0].pdispVal /* Item */);
  92. break;
  93. case DISPID_WMPCOREEVENT_CURRENTMEDIAITEMAVAILABLE:
  94. CurrentMediaItemAvailable(pDispParams->rgvarg[0].bstrVal /* bstrItemName */);
  95. break;
  96. case DISPID_WMPCOREEVENT_CURRENTITEMCHANGE:
  97. CurrentItemChange(pDispParams->rgvarg[0].pdispVal /* pdispMedia */);
  98. break;
  99. case DISPID_WMPCOREEVENT_MEDIACOLLECTIONCHANGE:
  100. MediaCollectionChange();
  101. break;
  102. case DISPID_WMPCOREEVENT_MEDIACOLLECTIONATTRIBUTESTRINGADDED:
  103. MediaCollectionAttributeStringAdded(pDispParams->rgvarg[1].bstrVal /* bstrAttribName */, pDispParams->rgvarg[0].bstrVal /* bstrAttribVal */ );
  104. break;
  105. case DISPID_WMPCOREEVENT_MEDIACOLLECTIONATTRIBUTESTRINGREMOVED:
  106. MediaCollectionAttributeStringRemoved(pDispParams->rgvarg[1].bstrVal /* bstrAttribName */, pDispParams->rgvarg[0].bstrVal /* bstrAttribVal */ );
  107. break;
  108. case DISPID_WMPCOREEVENT_MEDIACOLLECTIONATTRIBUTESTRINGCHANGED:
  109. MediaCollectionAttributeStringChanged(pDispParams->rgvarg[2].bstrVal /* bstrAttribName */, pDispParams->rgvarg[1].bstrVal /* bstrOldAttribVal */, pDispParams->rgvarg[0].bstrVal /* bstrNewAttribVal */);
  110. break;
  111. case DISPID_WMPCOREEVENT_PLAYLISTCOLLECTIONCHANGE:
  112. PlaylistCollectionChange();
  113. break;
  114. case DISPID_WMPCOREEVENT_PLAYLISTCOLLECTIONPLAYLISTADDED:
  115. PlaylistCollectionPlaylistAdded(pDispParams->rgvarg[0].bstrVal /* bstrPlaylistName */ );
  116. break;
  117. case DISPID_WMPCOREEVENT_PLAYLISTCOLLECTIONPLAYLISTREMOVED:
  118. PlaylistCollectionPlaylistRemoved(pDispParams->rgvarg[0].bstrVal /* bstrPlaylistName */ );
  119. break;
  120. case DISPID_WMPCOREEVENT_PLAYLISTCOLLECTIONPLAYLISTSETASDELETED:
  121. PlaylistCollectionPlaylistSetAsDeleted(pDispParams->rgvarg[1].bstrVal /* bstrPlaylistName */, pDispParams->rgvarg[0].boolVal /* varfIsDeleted */);
  122. break;
  123. case DISPID_WMPCOREEVENT_MODECHANGE:
  124. ModeChange(pDispParams->rgvarg[1].bstrVal /* ModeName */, pDispParams->rgvarg[0].boolVal /* NewValue */);
  125. break;
  126. case DISPID_WMPCOREEVENT_MEDIAERROR:
  127. MediaError(pDispParams->rgvarg[0].pdispVal /* pMediaObject */);
  128. break;
  129. case DISPID_WMPCOREEVENT_OPENPLAYLISTSWITCH:
  130. OpenPlaylistSwitch(pDispParams->rgvarg[0].pdispVal /* pItem */);
  131. break;
  132. case DISPID_WMPCOREEVENT_DOMAINCHANGE:
  133. DomainChange(pDispParams->rgvarg[0].bstrVal /* strDomain */);
  134. break;
  135. case DISPID_WMPOCXEVENT_SWITCHEDTOPLAYERAPPLICATION:
  136. SwitchedToPlayerApplication();
  137. break;
  138. case DISPID_WMPOCXEVENT_SWITCHEDTOCONTROL:
  139. SwitchedToControl();
  140. break;
  141. case DISPID_WMPOCXEVENT_PLAYERDOCKEDSTATECHANGE:
  142. PlayerDockedStateChange();
  143. break;
  144. case DISPID_WMPOCXEVENT_PLAYERRECONNECT:
  145. PlayerReconnect();
  146. break;
  147. case DISPID_WMPOCXEVENT_CLICK:
  148. Click(pDispParams->rgvarg[3].iVal /* nButton */, pDispParams->rgvarg[2].iVal /* nShiftState */, pDispParams->rgvarg[1].lVal /* fX */, pDispParams->rgvarg[0].lVal /* fY */);
  149. break;
  150. case DISPID_WMPOCXEVENT_DOUBLECLICK:
  151. DoubleClick(pDispParams->rgvarg[3].iVal /* nButton */, pDispParams->rgvarg[2].iVal /* nShiftState */, pDispParams->rgvarg[1].lVal /* fX */, pDispParams->rgvarg[0].lVal /* fY */);
  152. break;
  153. case DISPID_WMPOCXEVENT_KEYDOWN:
  154. KeyDown(pDispParams->rgvarg[1].iVal /* nKeyCode */, pDispParams->rgvarg[0].iVal /* nShiftState */);
  155. break;
  156. case DISPID_WMPOCXEVENT_KEYPRESS:
  157. KeyPress(pDispParams->rgvarg[0].iVal /* nKeyAscii */);
  158. break;
  159. case DISPID_WMPOCXEVENT_KEYUP:
  160. KeyUp(pDispParams->rgvarg[1].iVal /* nKeyCode */, pDispParams->rgvarg[0].iVal /* nShiftState */);
  161. break;
  162. case DISPID_WMPOCXEVENT_MOUSEDOWN:
  163. MouseDown(pDispParams->rgvarg[3].iVal /* nButton */, pDispParams->rgvarg[2].iVal /* nShiftState */, pDispParams->rgvarg[1].lVal /* fX */, pDispParams->rgvarg[0].lVal /* fY */);
  164. break;
  165. case DISPID_WMPOCXEVENT_MOUSEMOVE:
  166. MouseMove(pDispParams->rgvarg[3].iVal /* nButton */, pDispParams->rgvarg[2].iVal /* nShiftState */, pDispParams->rgvarg[1].lVal /* fX */, pDispParams->rgvarg[0].lVal /* fY */);
  167. break;
  168. case DISPID_WMPOCXEVENT_MOUSEUP:
  169. MouseUp(pDispParams->rgvarg[3].iVal /* nButton */, pDispParams->rgvarg[2].iVal /* nShiftState */, pDispParams->rgvarg[1].lVal /* fX */, pDispParams->rgvarg[0].lVal /* fY */);
  170. break;
  171. }
  172. return( hr );
  173. }
  174. // Sent when the control changes OpenState
  175. void CWMPEventDispatch::OpenStateChange(long NewState)
  176. {
  177. return;
  178. }
  179. // Sent when the control changes PlayState
  180. void CWMPEventDispatch::PlayStateChange(long NewState)
  181. {
  182. WMPPlayState playstate;
  183. if ( g_spWMPPlayer->get_playState( &playstate ) == S_OK )
  184. {
  185. switch ( playstate )
  186. {
  187. case wmppsPlaying:
  188. {
  189. static bool s_first = true;
  190. if ( s_first )
  191. {
  192. s_first = false;
  193. LogPlayerEvent( ET_MEDIABEGIN );
  194. SetFullScreen( true );
  195. ShowFadeWindow( false );
  196. }
  197. else
  198. {
  199. LogPlayerEvent( ET_PLAY );
  200. }
  201. break;
  202. }
  203. case wmppsPaused:
  204. LogPlayerEvent( ET_PAUSE );
  205. break;
  206. case wmppsStopped:
  207. LogPlayerEvent( ET_STOP );
  208. break;
  209. case wmppsMediaEnded:
  210. LogPlayerEvent( ET_MEDIAEND );
  211. if ( IsFullScreen() && !g_bFadeWindowTriggered )
  212. {
  213. g_bFadeWindowTriggered = true;
  214. ShowFadeWindow( true );
  215. }
  216. break;
  217. }
  218. }
  219. }
  220. // Sent when the audio language changes
  221. void CWMPEventDispatch::AudioLanguageChange(long LangID)
  222. {
  223. return;
  224. }
  225. // Sent when the status string changes
  226. void CWMPEventDispatch::StatusChange()
  227. {
  228. }
  229. // Sent when a synchronized command or URL is received
  230. void CWMPEventDispatch::ScriptCommand(BSTR scType,BSTR Param)
  231. {
  232. return;
  233. }
  234. // Sent when a new stream is encountered (obsolete)
  235. void CWMPEventDispatch::NewStream()
  236. {
  237. return;
  238. }
  239. // Sent when the control is disconnected from the server (obsolete)
  240. void CWMPEventDispatch:: Disconnect(long Result )
  241. {
  242. return;
  243. }
  244. // Sent when the control begins or ends buffering
  245. void CWMPEventDispatch:: Buffering(VARIANT_BOOL Start)
  246. {
  247. return;
  248. }
  249. // Sent when the control has an error condition
  250. void CWMPEventDispatch::Error()
  251. {
  252. return;
  253. }
  254. // Sent when the control has an warning condition (obsolete)
  255. void CWMPEventDispatch::Warning(long WarningType, long Param, BSTR Description)
  256. {
  257. return;
  258. }
  259. // Sent when the media has reached end of stream
  260. void CWMPEventDispatch::EndOfStream(long Result)
  261. {
  262. return;
  263. }
  264. // Indicates that the current position of the movie has changed
  265. void CWMPEventDispatch::PositionChange(double oldPosition,double newPosition)
  266. {
  267. LogPlayerEvent( ET_SCRUBFROM, ( float )oldPosition );
  268. LogPlayerEvent( ET_SCRUBTO, ( float )newPosition );
  269. }
  270. // Sent when a marker is reached
  271. void CWMPEventDispatch::MarkerHit(long MarkerNum )
  272. {
  273. return;
  274. }
  275. // Indicates that the unit used to express duration and position has changed
  276. void CWMPEventDispatch::DurationUnitChange(long NewDurationUnit)
  277. {
  278. return;
  279. }
  280. // Indicates that the CD ROM media has changed
  281. void CWMPEventDispatch::CdromMediaChange(long CdromNum)
  282. {
  283. return;
  284. }
  285. // Sent when a playlist changes
  286. void CWMPEventDispatch::PlaylistChange(IDispatch * Playlist,WMPPlaylistChangeEventType change)
  287. {
  288. return;
  289. }
  290. // Sent when the current playlist changes
  291. void CWMPEventDispatch::CurrentPlaylistChange(WMPPlaylistChangeEventType change )
  292. {
  293. return;
  294. }
  295. // Sent when a current playlist item becomes available
  296. void CWMPEventDispatch::CurrentPlaylistItemAvailable(BSTR bstrItemName)
  297. {
  298. return;
  299. }
  300. // Sent when a media object changes
  301. void CWMPEventDispatch::MediaChange(IDispatch * Item)
  302. {
  303. return;
  304. }
  305. // Sent when a current media item becomes available
  306. void CWMPEventDispatch::CurrentMediaItemAvailable(BSTR bstrItemName)
  307. {
  308. return;
  309. }
  310. // Sent when the item selection on the current playlist changes
  311. void CWMPEventDispatch::CurrentItemChange(IDispatch *pdispMedia)
  312. {
  313. return;
  314. }
  315. // Sent when the media collection needs to be requeried
  316. void CWMPEventDispatch::MediaCollectionChange()
  317. {
  318. return;
  319. }
  320. // Sent when an attribute string is added in the media collection
  321. void CWMPEventDispatch::MediaCollectionAttributeStringAdded(BSTR bstrAttribName, BSTR bstrAttribVal)
  322. {
  323. return;
  324. }
  325. // Sent when an attribute string is removed from the media collection
  326. void CWMPEventDispatch::MediaCollectionAttributeStringRemoved(BSTR bstrAttribName, BSTR bstrAttribVal)
  327. {
  328. return;
  329. }
  330. // Sent when an attribute string is changed in the media collection
  331. void CWMPEventDispatch::MediaCollectionAttributeStringChanged(BSTR bstrAttribName, BSTR bstrOldAttribVal, BSTR bstrNewAttribVal)
  332. {
  333. return;
  334. }
  335. // Sent when playlist collection needs to be requeried
  336. void CWMPEventDispatch::PlaylistCollectionChange()
  337. {
  338. return;
  339. }
  340. // Sent when a playlist is added to the playlist collection
  341. void CWMPEventDispatch::PlaylistCollectionPlaylistAdded(BSTR bstrPlaylistName)
  342. {
  343. return;
  344. }
  345. // Sent when a playlist is removed from the playlist collection
  346. void CWMPEventDispatch::PlaylistCollectionPlaylistRemoved(BSTR bstrPlaylistName)
  347. {
  348. return;
  349. }
  350. // Sent when a playlist has been set or reset as deleted
  351. void CWMPEventDispatch::PlaylistCollectionPlaylistSetAsDeleted(BSTR bstrPlaylistName, VARIANT_BOOL varfIsDeleted)
  352. {
  353. return;
  354. }
  355. // Playlist playback mode has changed
  356. void CWMPEventDispatch::ModeChange(BSTR ModeName, VARIANT_BOOL NewValue)
  357. {
  358. return;
  359. }
  360. // Sent when the media object has an error condition
  361. void CWMPEventDispatch::MediaError(IDispatch * pMediaObject)
  362. {
  363. while ( ShowCursor( TRUE ) < 0 )
  364. ;
  365. ShowWindow( g_hBlackFadingWindow, SW_HIDE );
  366. if ( g_pFrame )
  367. {
  368. g_pFrame->ShowWindow( SW_HIDE );
  369. }
  370. CComPtr< IWMPMedia > spWMPMedia;
  371. if ( pMediaObject )
  372. {
  373. pMediaObject->QueryInterface( &spWMPMedia );
  374. }
  375. if ( spWMPMedia )
  376. {
  377. BSTR bstr;
  378. spWMPMedia->get_sourceURL( &bstr );
  379. char str[ 1024 ];
  380. sprintf( str, "Unable to open media: %s\n", CW2T( bstr ) );
  381. MessageBox( NULL, str, "Media Error", MB_OK | MB_ICONERROR );
  382. }
  383. else
  384. {
  385. MessageBox( NULL, "Media Error", "Media Error", MB_OK | MB_ICONERROR );
  386. }
  387. g_pFrame->PostMessage( WM_CLOSE );
  388. }
  389. // Current playlist switch with no open state change
  390. void CWMPEventDispatch::OpenPlaylistSwitch(IDispatch *pItem)
  391. {
  392. return;
  393. }
  394. // Sent when the current DVD domain changes
  395. void CWMPEventDispatch::DomainChange(BSTR strDomain)
  396. {
  397. return;
  398. }
  399. // Sent when display switches to player application
  400. void CWMPEventDispatch::SwitchedToPlayerApplication()
  401. {
  402. }
  403. // Sent when display switches to control
  404. void CWMPEventDispatch::SwitchedToControl()
  405. {
  406. }
  407. // Sent when the player docks or undocks
  408. void CWMPEventDispatch::PlayerDockedStateChange()
  409. {
  410. }
  411. // Sent when the OCX reconnects to the player
  412. void CWMPEventDispatch::PlayerReconnect()
  413. {
  414. }
  415. // Occurs when a user clicks the mouse
  416. void CWMPEventDispatch::Click( short nButton, short nShiftState, long fX, long fY )
  417. {
  418. if ( IsFullScreen() )
  419. {
  420. SetFullScreen( false );
  421. }
  422. }
  423. // Occurs when a user double-clicks the mouse
  424. void CWMPEventDispatch::DoubleClick( short nButton, short nShiftState, long fX, long fY )
  425. {
  426. // the controls are just drawn into the main window, wheras the video has its own window
  427. // this check allows us to only fullscreen on doubleclick within the video area
  428. POINT pt = { fX, fY };
  429. HWND hWnd = g_pFrame->ChildWindowFromPoint( pt );
  430. if ( ChildWindowFromPoint( hWnd, pt ) != hWnd )
  431. {
  432. SetFullScreen( !IsFullScreen() );
  433. }
  434. }
  435. // Occurs when a key is pressed
  436. void CWMPEventDispatch::KeyDown( short nKeyCode, short nShiftState )
  437. {
  438. #if 1
  439. if ( !g_pFrame )
  440. return;
  441. BOOL rval;
  442. if ( nShiftState & 4 ) // 4 is the alt keymask
  443. {
  444. g_pFrame->OnSysKeyDown( WM_KEYDOWN, nKeyCode, 0, rval );
  445. }
  446. else
  447. {
  448. g_pFrame->OnKeyDown( WM_KEYDOWN, nKeyCode, 0, rval );
  449. }
  450. #endif
  451. }
  452. // Occurs when a key is pressed and released
  453. void CWMPEventDispatch::KeyPress( short nKeyAscii )
  454. {
  455. return;
  456. }
  457. // Occurs when a key is released
  458. void CWMPEventDispatch::KeyUp( short nKeyCode, short nShiftState )
  459. {
  460. return;
  461. }
  462. // Occurs when a mouse button is pressed
  463. void CWMPEventDispatch::MouseDown( short nButton, short nShiftState, long fX, long fY )
  464. {
  465. }
  466. // Occurs when a mouse pointer is moved
  467. void CWMPEventDispatch::MouseMove( short nButton, short nShiftState, long fX, long fY )
  468. {
  469. return;
  470. }
  471. // Occurs when a mouse button is released
  472. void CWMPEventDispatch::MouseUp( short nButton, short nShiftState, long fX, long fY )
  473. {
  474. }