chxavplayviewwindow.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:14k
源码类别:

Symbian

开发平台:

C/C++

  1. /************************************************************************
  2.  * chxavplayviewwindow.cpp
  3.  * -----------------------
  4.  *
  5.  * Synopsis:
  6.  * CHXAvPlayViewWindow implementation.  Contains site window.
  7.  *
  8.  * Target:
  9.  * Symbian OS
  10.  *
  11.  *
  12.  * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
  13.  *
  14.  ************************************************************************/
  15. // Standard Symbian includes...
  16. #include <eiklbo.h> 
  17. #include <aknlists.h>
  18. #include <coemain.h>
  19. #include <e32std.h>
  20. // Helix includes...
  21. #include "hxassert.h"
  22. // Includes from this project...
  23. #include "realplayer.hrh"
  24. #include "hxsym_debug.h"
  25. #include "chxavcleanupstack.h"
  26. #include "chxavplayviewwindow.h"
  27. #include "chxavplayer.h"
  28. #include "chxavplayerui.h"
  29. #include "chxavfileutil.h"
  30. #include "chxavplayview.h"
  31. #include "realplayer.mbg"
  32. #define BORDER_WIDTH 1
  33. /* 
  34.  * CHXAvPlayViewWindow
  35.  * --------------------
  36.  * Ctor.
  37.  *
  38.  */
  39. CHXAvPlayViewWindow::CHXAvPlayViewWindow()
  40. : m_playView(0)
  41. , m_playerUI(0)
  42. , m_bInSeekMode(FALSE)
  43. {
  44. }
  45. /* 
  46.  * ~CHXAvPlayViewWindow
  47.  * --------------------
  48.  * Dtor.
  49.  *
  50.  */
  51. CHXAvPlayViewWindow::~CHXAvPlayViewWindow()
  52. {
  53.     HX_ASSERT(m_spPlayer);
  54.     if(m_spPlayer)
  55.     {
  56.         HX_ASSERT(m_spPresentationWindow);
  57.         m_spPlayer->GetPlayerState().RemoveObserver(m_spPresentationWindow.raw_ptr());
  58.     }
  59. }
  60. /* 
  61.  * ConstructL
  62.  * ----------
  63.  */
  64. void CHXAvPlayViewWindow::ConstructL(CHXAvPlayerUI *playerUI, 
  65.                                      CHXAvPlayView *parentView, 
  66.                                      const TRect& rc)
  67. {
  68.     HX_ASSERT(playerUI != NULL);
  69.     HX_ASSERT(parentView != NULL);
  70.     m_playerUI = playerUI;
  71.     m_playView = parentView;
  72.     m_spPlayer = m_playView->GetPlayer();
  73.     HX_ASSERT(m_spPlayer);
  74.     CreateWindowL();
  75.     SetRect(rc);
  76.     // Create the presentation window....
  77.     HX_ASSERT(!m_spPresentationWindow);
  78.     
  79.     m_spPresentationWindow = new (ELeave) CHXAvPresentationWindow();
  80.     TRect childRect = rc;
  81.     childRect.Shrink(1, 1);
  82.     m_spPresentationWindow->ConstructL(this, playerUI, childRect);
  83.     m_spPlayer->GetPlayerState().AddObserver(m_spPresentationWindow.raw_ptr());
  84.     ActivateL();    
  85. }
  86. /*
  87.  * ComponentControl
  88.  * ----------------
  89.  * Return a pointer to the ith component of this control.
  90.  *
  91.  */ 
  92. CCoeControl *CHXAvPlayViewWindow::ComponentControl(TInt aIndex) const
  93. {
  94.     return m_spPresentationWindow.raw_ptr();
  95. }
  96.     
  97. /*
  98.  * CountComponentControls
  99.  * ----------------------
  100.  * Return the number of subcontrols in this control.
  101.  *
  102.  */
  103. TInt CHXAvPlayViewWindow::CountComponentControls() const
  104. {
  105.     return 1;
  106. }
  107. /*
  108.  * OfferKeyEventL
  109.  * --------------
  110.  * A key event is occurring.
  111.  *
  112.  */
  113. TKeyResponse CHXAvPlayViewWindow::OfferKeyEventL(const TKeyEvent& keyEvent, TEventCode type)
  114. {
  115.     DPRINTF(SYMP_WSEVENTS, ("CHXAvPlayViewWindow::OfferKeyEventL():  type = %dn", type));
  116.     TKeyResponse response = EKeyWasNotConsumed;
  117.     switch(type)
  118.     {
  119.     case EEventKey:
  120. response = HandleEventKeyEventL(keyEvent);
  121. break;
  122.     case EEventKeyUp:
  123. response = HandleKeyUpEventL(keyEvent);
  124. break;
  125.     case EEventKeyDown:
  126.         response = HandleKeyDownEventL(keyEvent);
  127.         break;
  128.     default:
  129.         break;
  130.     }
  131.     return response;
  132. }
  133. /*
  134.  * Draw
  135.  * ----
  136.  * This control fills in white.  The sub control, which 
  137.  * is one pixel smaller on all sides, will fill in black, which
  138.  * will give us a one pixel white border all around.
  139.  *
  140.  */
  141. void CHXAvPlayViewWindow::Draw(const TRect& aRect) const
  142. {
  143.     DPRINTF(SYMP_INFO, ("CHXAvPlayViewWindow::Draw()n"));
  144.     CWindowGc& gc = SystemGc();
  145.     gc.SetPenStyle(CGraphicsContext::ENullPen);
  146.     gc.SetBrushColor(KRgbWhite);
  147.     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
  148.     gc.DrawRect(aRect);
  149.     comptr<CHXAvPlayer> player = m_playView->GetPlayer();
  150.     HX_ASSERT(player);
  151.     player->RedrawPresentation();
  152. }
  153. /*
  154.  * HandleKeyEventL
  155.  * ---------------
  156.  * Handle key events here
  157.  *
  158.  */
  159. // EKeyXXX constants are used for key code (TKeyEvent::iCode)
  160. // EStdKeyXXX constants are used for scan code
  161. TKeyResponse 
  162. CHXAvPlayViewWindow::HandleEventKeyEventL(const TKeyEvent& event)
  163. {
  164.     TKeyResponse response = EKeyWasConsumed;
  165.     DPRINTF(SYMP_INFO, ("SYMP_WSEVENTS::HandleEventKeyEventL():  keyCode = %ld; repeat = %ld; modifier = %ldn", event.iCode, event.iRepeats, event.iModifiers));
  166.     if( event.iModifiers & EAllStdModifiers )
  167.     {
  168.         // ignore keys if shift, ctrl, alt are pressed
  169.         return EKeyWasNotConsumed;
  170.     }
  171.     switch(event.iCode)
  172.     {
  173. // see e32keys.h for scan code constants; also see uikon.hrh
  174.     case EKeyRightArrow:
  175.     case EKeyIncVolume:
  176. m_playView->HandleCommandL(EVolUp);
  177. break;
  178.     case EKeyLeftArrow:
  179.     case EKeyDecVolume:
  180. m_playView->HandleCommandL(EVolDown);
  181. break;
  182.     case EKeyOK:
  183.     case EKeyEnter:      
  184. m_playView->HandleCommandL(EShowDefaultMenu);      
  185. break;
  186.     case EKeyUpArrow:
  187.     case EKeyDownArrow:
  188. HandleSeekKeyEvent(event);
  189. break;
  190.     case EKeyApplication0: // yin-yang key
  191. // assume we will loose app focus; this makes switch to background more responsive
  192. m_playView->HandleLosePlayFocus();
  193. break;
  194.     /*case EKeyF21:
  195.         m_playView->HandleCommandL(EEnterPlaylistMode);
  196.         break;*/
  197.     default:
  198. response = EKeyWasNotConsumed;
  199. break;
  200.     }
  201.     //
  202.     // XXXNOTES
  203.     //
  204.     // The shift key works a bit differently than other keys.
  205.     //
  206.     // EKeyF21 is left shift (pencil) key. Here's how it works:
  207.     //
  208.     // 1) On press, you first get key down for left shift key
  209.     // 2) After a delay (about one second), you get a key event EKeyF21
  210.     // 3) If you release before you get the EKeyF21, you get no key up event
  211.     // 4) If you get the EKeyF21 event, you will see a key up event, unless:
  212.     //      a) a softkey is pressed
  213.     //      b) possibly if something else takes focus (a menu pops up)
  214.     //
  215.     // we work around case (a) by observing ws events in the app ui class
  216.     //
  217.     return response;
  218. }
  219. TKeyResponse CHXAvPlayViewWindow::HandleKeyDownEventL(const TKeyEvent& event)
  220. {
  221.     TKeyResponse response = EKeyWasNotConsumed;
  222.     DPRINTF(SYMP_WSEVENTS, ("CHXAvPlayViewWindow::HandleKeyDownEventL():  scanCode = %ld; repeat = %ld; modifier = %ldn", event.iScanCode, event.iRepeats, event.iModifiers));
  223.     if(event.iScanCode == EStdKeyLeftShift )
  224.     {
  225.         m_playView->HandleCommandL(EEnterPlaylistMode); //EShowPlaylistInfo;
  226.         response = EKeyWasConsumed;
  227.     }
  228.     // need to use scan code for key up/down events (as opposed to key events)
  229.     return response;
  230. }
  231. /*
  232.  * HandleKeyUpEventL
  233.  * -----------------
  234.  *
  235.  */
  236. TKeyResponse
  237. CHXAvPlayViewWindow::HandleKeyUpEventL(const TKeyEvent& event)
  238. {
  239.     TKeyResponse response = EKeyWasConsumed;
  240.     DPRINTF(SYMP_INFO, ("CHXAvPlayViewWindow::HandleKeyUpEventL():  scanCode = %ld; repeat = %ld; modifier = %ldn", event.iScanCode, event.iRepeats, event.iModifiers));
  241.     // need to use scan code for key up/down events (as opposed to key events)
  242.     switch(event.iScanCode)
  243.     {
  244.     case EStdKeyUpArrow:
  245.     case EStdKeyDownArrow:
  246.         if(m_bInSeekMode)
  247.         {
  248.             m_bInSeekMode = false;
  249.     m_playView->HandleCommandL(EEndSeek);
  250.         }
  251.         break;
  252.     case EStdKeyLeftShift:
  253.         m_playView->HandleCommandL(EExitPlaylistMode);
  254.         break;
  255.     default:
  256. response = EKeyWasNotConsumed;
  257. break;
  258.     }
  259.     return response;
  260. }
  261. /*
  262.  * HandleSeekKeyEvent
  263.  * ------------------
  264.  *
  265.  */
  266. void 
  267. CHXAvPlayViewWindow::HandleSeekKeyEvent(const TKeyEvent& event)
  268. {
  269.     DPRINTF(SYMP_INFO, ("HandleSeekKeyEvent():  seek key pressedn"));
  270.     // ignore seek unless playing/paused/already seeking
  271.     if(!m_playerUI->GetPlayer()->CanSeek())
  272.     {
  273.         DPRINTF(SYMP_INFO, ("HandleSeekKeyEvent():  seek key rejectedn"));
  274.         return;
  275.     }
  276.     
  277.     if (!m_bInSeekMode) // XXXLCM use play object state?
  278.     {
  279.         if (m_playerUI->GetPlayer()->GetClipInfo().IsLive())
  280.         {
  281.             // seek onset begins with longpress, i.e., first repeat we see (avoids accidental seek)
  282.             m_bInSeekMode = (event.iRepeats == 1);
  283.         }
  284.         else
  285.         {
  286.             // seek begins immediately, i.e., with first keypress
  287.             m_bInSeekMode = true;
  288.         }
  289.         if( m_bInSeekMode )
  290.         {
  291.             // notify handler to enter seeking mode
  292.             DPRINTF(SYMP_INFO, ("HandleSeekKeyEvent():  enter seek moden"));
  293.             m_playView->HandleCommandL(EBeginSeek);
  294.         }
  295.     }
  296.     if (m_bInSeekMode)
  297.     {
  298.         TInt command = 0;
  299.         switch(event.iScanCode)
  300.         {
  301.         case EStdKeyUpArrow:
  302.             command = ESeekForward;
  303.     break;
  304.         case EStdKeyDownArrow:
  305.             command = ESeekBack;
  306.     break;
  307.         default:
  308.             HX_ASSERT(false);
  309.         }
  310.         // notify handler of change in seek position
  311.         m_playView->HandleCommandL(command);
  312.     }
  313. }
  314. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  315. // CHXAvPresentationWindow Implementation....
  316. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  317. /*
  318.  * CHXAvPresentationWindow
  319.  * -----------------------
  320.  * Ctor
  321.  *
  322.  */
  323. CHXAvPresentationWindow::CHXAvPresentationWindow() 
  324. : m_playerUI(NULL)
  325. , m_bShowLogo(true)
  326. , m_bShowAudioIcon(false)
  327. , m_bLastClipPlayedHadVideo(false)
  328. {
  329. }
  330. /*
  331.  * ~CHXAvPresentationWindow
  332.  * ------------------------
  333.  * Dtor
  334.  *
  335.  */
  336. CHXAvPresentationWindow::~CHXAvPresentationWindow()
  337. {
  338. }
  339. /*
  340.  * ConstructL
  341.  * ----------
  342.  * Contruct this control
  343.  *
  344.  */
  345. void 
  346. CHXAvPresentationWindow::ConstructL(CCoeControl *parent, CHXAvPlayerUI *playerUI, const TRect& rc)
  347. {
  348.     m_playerUI = playerUI;
  349.     m_parent = parent;
  350.     CreateWindowL();
  351.     SetRect(rc);
  352.     ActivateL();
  353.     LoadLogoItems();
  354. }
  355. /*
  356.  * OfferKeyEvent
  357.  * -------------
  358.  * Pass it up to the parent.
  359.  *
  360.  */
  361. TKeyResponse 
  362. CHXAvPresentationWindow::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
  363. {
  364.     return m_parent->OfferKeyEventL(aKeyEvent, aType);
  365. }
  366. /*
  367.  * Draw
  368.  * ----
  369.  * Draw the background black.
  370.  *
  371.  */
  372. void 
  373. CHXAvPresentationWindow::Draw(const TRect& aRect) const
  374. {
  375.     DPRINTF(SYMP_INFO, ("CHXAvPresentationWindow::Draw()n"));
  376.     CWindowGc& gc = SystemGc();
  377.     // Fill background with black...
  378.     gc.Clear();
  379.     TRect rcDraw = Rect();
  380.     gc.SetPenStyle(CGraphicsContext::ENullPen);
  381.     gc.SetBrushColor(KRgbBlack);
  382.     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
  383.     gc.DrawRect(aRect);
  384.     // Draw logo bitmap...
  385.     if( m_bShowLogo && m_logo.Handle() )
  386.     {
  387. // draw logo centered within the window
  388. TPoint ptDraw = rcDraw.iTl;
  389. TSize szLogo = m_logo.SizeInPixels();
  390. ptDraw.iX += (rcDraw.Width() - szLogo.iWidth) / 2;
  391. ptDraw.iY += (rcDraw.Height() - szLogo.iHeight) / 2;
  392.     
  393. // Draw full logo that fits within the window
  394. gc.BitBlt(ptDraw, &m_logo);
  395.     }
  396.     // Draw audio icon...
  397.     if (m_bShowAudioIcon && m_audioIcon.Handle())
  398.     {
  399. // draw in upper left (XXXLCM make configurable/decorate)
  400. const TInt AUDIO_ICON_OFFSET  = 4;
  401. gc.BitBlt(TPoint(AUDIO_ICON_OFFSET,AUDIO_ICON_OFFSET), &m_audioIcon);
  402.     }
  403. }
  404. /*
  405.  * OnPlayInitiate
  406.  * --------------------
  407.  * Show the logo.
  408.  *
  409.  */
  410. void 
  411. CHXAvPresentationWindow::OnPlayInitiate(const char* /*url*/)
  412. {
  413.     DPRINTF(SYMP_INFO, ("CHXAvPresentationWindow::OnPlayInitiate()n"));
  414.     //
  415.     // reset video window so it shows logo
  416.     //
  417.     m_bLastClipPlayedHadVideo = false;
  418.     m_bShowLogo = true;
  419.     m_bShowAudioIcon = false;
  420.     DrawNow();
  421. }
  422. void CHXAvPresentationWindow::OnLoadSession(IHXRequest* request)
  423. {
  424.     //
  425.     // hide logo / show audio icon based on presentation content
  426.     //
  427.     CHXAvPlayer* pPlayer = m_playerUI->GetPlayer();
  428.     bool bHasVideo = pPlayer->GetClipInfo().IsVideoPresentation();
  429.     m_bShowLogo = !bHasVideo;
  430.     m_bShowAudioIcon = !bHasVideo;
  431.     m_bLastClipPlayedHadVideo = bHasVideo;
  432.     DrawNow();
  433.     
  434. }
  435. /*
  436.  * OnStop
  437.  * ------------
  438.  * If we are showing the audio icon, get rid of it.
  439.  *
  440.  */
  441. void 
  442. CHXAvPresentationWindow::OnStop()
  443. {
  444.     DPRINTF(SYMP_INFO, ("CHXAvPresentationWindow::OnStop"));
  445.     // If the last clip played had no video, then we have to make sure the audio icon is erased...
  446.     if (!m_bLastClipPlayedHadVideo)
  447.     {
  448. m_bShowAudioIcon = false;
  449. DrawNow();
  450.     }
  451. }
  452. /*
  453.  * LoadLogoItems
  454.  * -------------
  455.  * Create and set the logo icons.
  456.  *
  457.  */
  458. void 
  459. CHXAvPresentationWindow::LoadLogoItems()
  460. {
  461.     TInt idxLogo = EMbmRealplayerBackground_logo;
  462.     TInt idxAudioIcon = EMbmRealplayerAudio_icon_left;
  463.     SetBackgroundItems(m_playerUI->GetAppImageFilePath(), idxLogo, idxAudioIcon);
  464. }
  465. /*
  466.  * SetBackgroundItems
  467.  * ------------------
  468.  * If graphic images are in different files, call multiple times, masking out this or that idx by
  469.  * setting to -1.
  470.  *
  471.  */
  472. void 
  473. CHXAvPresentationWindow::SetBackgroundItems(const TDesC& fileName, TInt idxLogo, TInt idxAudioIcon)
  474. {
  475.     TFileName fullPath;
  476.     RFs fs;
  477.     fs.Connect();
  478.     TInt err = CHXAvFile::GetFullPath(fs, fileName, fullPath, false);
  479.    
  480.     if (KErrNone == err)
  481.     {
  482. if( idxLogo >= 0 )
  483. {
  484.     m_logo.Reset();
  485.     m_logo.Load(fullPath, idxLogo);
  486. }
  487. if( idxAudioIcon >= 0 )
  488. {
  489.     m_audioIcon.Reset();
  490.     m_audioIcon.Load(fullPath, idxAudioIcon);
  491. }
  492.     }
  493.     fs.Close();
  494. }