chxavplayviewwindow.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:14k
- /************************************************************************
- * chxavplayviewwindow.cpp
- * -----------------------
- *
- * Synopsis:
- * CHXAvPlayViewWindow implementation. Contains site window.
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- ************************************************************************/
- // Standard Symbian includes...
- #include <eiklbo.h>
- #include <aknlists.h>
- #include <coemain.h>
- #include <e32std.h>
- // Helix includes...
- #include "hxassert.h"
- // Includes from this project...
- #include "realplayer.hrh"
- #include "hxsym_debug.h"
- #include "chxavcleanupstack.h"
- #include "chxavplayviewwindow.h"
- #include "chxavplayer.h"
- #include "chxavplayerui.h"
- #include "chxavfileutil.h"
- #include "chxavplayview.h"
- #include "realplayer.mbg"
- #define BORDER_WIDTH 1
- /*
- * CHXAvPlayViewWindow
- * --------------------
- * Ctor.
- *
- */
- CHXAvPlayViewWindow::CHXAvPlayViewWindow()
- : m_playView(0)
- , m_playerUI(0)
- , m_bInSeekMode(FALSE)
- {
- }
- /*
- * ~CHXAvPlayViewWindow
- * --------------------
- * Dtor.
- *
- */
- CHXAvPlayViewWindow::~CHXAvPlayViewWindow()
- {
- HX_ASSERT(m_spPlayer);
- if(m_spPlayer)
- {
- HX_ASSERT(m_spPresentationWindow);
- m_spPlayer->GetPlayerState().RemoveObserver(m_spPresentationWindow.raw_ptr());
- }
- }
- /*
- * ConstructL
- * ----------
- */
- void CHXAvPlayViewWindow::ConstructL(CHXAvPlayerUI *playerUI,
- CHXAvPlayView *parentView,
- const TRect& rc)
- {
- HX_ASSERT(playerUI != NULL);
- HX_ASSERT(parentView != NULL);
- m_playerUI = playerUI;
- m_playView = parentView;
- m_spPlayer = m_playView->GetPlayer();
- HX_ASSERT(m_spPlayer);
- CreateWindowL();
- SetRect(rc);
- // Create the presentation window....
- HX_ASSERT(!m_spPresentationWindow);
-
- m_spPresentationWindow = new (ELeave) CHXAvPresentationWindow();
- TRect childRect = rc;
- childRect.Shrink(1, 1);
- m_spPresentationWindow->ConstructL(this, playerUI, childRect);
- m_spPlayer->GetPlayerState().AddObserver(m_spPresentationWindow.raw_ptr());
- ActivateL();
- }
- /*
- * ComponentControl
- * ----------------
- * Return a pointer to the ith component of this control.
- *
- */
- CCoeControl *CHXAvPlayViewWindow::ComponentControl(TInt aIndex) const
- {
- return m_spPresentationWindow.raw_ptr();
- }
-
- /*
- * CountComponentControls
- * ----------------------
- * Return the number of subcontrols in this control.
- *
- */
- TInt CHXAvPlayViewWindow::CountComponentControls() const
- {
- return 1;
- }
- /*
- * OfferKeyEventL
- * --------------
- * A key event is occurring.
- *
- */
- TKeyResponse CHXAvPlayViewWindow::OfferKeyEventL(const TKeyEvent& keyEvent, TEventCode type)
- {
- DPRINTF(SYMP_WSEVENTS, ("CHXAvPlayViewWindow::OfferKeyEventL(): type = %dn", type));
- TKeyResponse response = EKeyWasNotConsumed;
- switch(type)
- {
- case EEventKey:
- response = HandleEventKeyEventL(keyEvent);
- break;
- case EEventKeyUp:
- response = HandleKeyUpEventL(keyEvent);
- break;
- case EEventKeyDown:
- response = HandleKeyDownEventL(keyEvent);
- break;
- default:
- break;
- }
- return response;
- }
- /*
- * Draw
- * ----
- * This control fills in white. The sub control, which
- * is one pixel smaller on all sides, will fill in black, which
- * will give us a one pixel white border all around.
- *
- */
- void CHXAvPlayViewWindow::Draw(const TRect& aRect) const
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayViewWindow::Draw()n"));
- CWindowGc& gc = SystemGc();
- gc.SetPenStyle(CGraphicsContext::ENullPen);
- gc.SetBrushColor(KRgbWhite);
- gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
- gc.DrawRect(aRect);
- comptr<CHXAvPlayer> player = m_playView->GetPlayer();
- HX_ASSERT(player);
- player->RedrawPresentation();
- }
- /*
- * HandleKeyEventL
- * ---------------
- * Handle key events here
- *
- */
- // EKeyXXX constants are used for key code (TKeyEvent::iCode)
- // EStdKeyXXX constants are used for scan code
- TKeyResponse
- CHXAvPlayViewWindow::HandleEventKeyEventL(const TKeyEvent& event)
- {
- TKeyResponse response = EKeyWasConsumed;
- DPRINTF(SYMP_INFO, ("SYMP_WSEVENTS::HandleEventKeyEventL(): keyCode = %ld; repeat = %ld; modifier = %ldn", event.iCode, event.iRepeats, event.iModifiers));
- if( event.iModifiers & EAllStdModifiers )
- {
- // ignore keys if shift, ctrl, alt are pressed
- return EKeyWasNotConsumed;
- }
- switch(event.iCode)
- {
- // see e32keys.h for scan code constants; also see uikon.hrh
- case EKeyRightArrow:
- case EKeyIncVolume:
- m_playView->HandleCommandL(EVolUp);
- break;
- case EKeyLeftArrow:
- case EKeyDecVolume:
- m_playView->HandleCommandL(EVolDown);
- break;
- case EKeyOK:
- case EKeyEnter:
- m_playView->HandleCommandL(EShowDefaultMenu);
- break;
- case EKeyUpArrow:
- case EKeyDownArrow:
- HandleSeekKeyEvent(event);
- break;
- case EKeyApplication0: // yin-yang key
- // assume we will loose app focus; this makes switch to background more responsive
- m_playView->HandleLosePlayFocus();
- break;
- /*case EKeyF21:
- m_playView->HandleCommandL(EEnterPlaylistMode);
- break;*/
- default:
- response = EKeyWasNotConsumed;
- break;
- }
- //
- // XXXNOTES
- //
- // The shift key works a bit differently than other keys.
- //
- // EKeyF21 is left shift (pencil) key. Here's how it works:
- //
- // 1) On press, you first get key down for left shift key
- // 2) After a delay (about one second), you get a key event EKeyF21
- // 3) If you release before you get the EKeyF21, you get no key up event
- // 4) If you get the EKeyF21 event, you will see a key up event, unless:
- // a) a softkey is pressed
- // b) possibly if something else takes focus (a menu pops up)
- //
- // we work around case (a) by observing ws events in the app ui class
- //
- return response;
- }
- TKeyResponse CHXAvPlayViewWindow::HandleKeyDownEventL(const TKeyEvent& event)
- {
- TKeyResponse response = EKeyWasNotConsumed;
- DPRINTF(SYMP_WSEVENTS, ("CHXAvPlayViewWindow::HandleKeyDownEventL(): scanCode = %ld; repeat = %ld; modifier = %ldn", event.iScanCode, event.iRepeats, event.iModifiers));
- if(event.iScanCode == EStdKeyLeftShift )
- {
- m_playView->HandleCommandL(EEnterPlaylistMode); //EShowPlaylistInfo;
- response = EKeyWasConsumed;
- }
- // need to use scan code for key up/down events (as opposed to key events)
- return response;
- }
- /*
- * HandleKeyUpEventL
- * -----------------
- *
- */
- TKeyResponse
- CHXAvPlayViewWindow::HandleKeyUpEventL(const TKeyEvent& event)
- {
- TKeyResponse response = EKeyWasConsumed;
- DPRINTF(SYMP_INFO, ("CHXAvPlayViewWindow::HandleKeyUpEventL(): scanCode = %ld; repeat = %ld; modifier = %ldn", event.iScanCode, event.iRepeats, event.iModifiers));
- // need to use scan code for key up/down events (as opposed to key events)
- switch(event.iScanCode)
- {
- case EStdKeyUpArrow:
- case EStdKeyDownArrow:
- if(m_bInSeekMode)
- {
- m_bInSeekMode = false;
- m_playView->HandleCommandL(EEndSeek);
- }
- break;
- case EStdKeyLeftShift:
- m_playView->HandleCommandL(EExitPlaylistMode);
- break;
- default:
- response = EKeyWasNotConsumed;
- break;
- }
- return response;
- }
- /*
- * HandleSeekKeyEvent
- * ------------------
- *
- */
- void
- CHXAvPlayViewWindow::HandleSeekKeyEvent(const TKeyEvent& event)
- {
- DPRINTF(SYMP_INFO, ("HandleSeekKeyEvent(): seek key pressedn"));
- // ignore seek unless playing/paused/already seeking
- if(!m_playerUI->GetPlayer()->CanSeek())
- {
- DPRINTF(SYMP_INFO, ("HandleSeekKeyEvent(): seek key rejectedn"));
- return;
- }
-
- if (!m_bInSeekMode) // XXXLCM use play object state?
- {
- if (m_playerUI->GetPlayer()->GetClipInfo().IsLive())
- {
- // seek onset begins with longpress, i.e., first repeat we see (avoids accidental seek)
- m_bInSeekMode = (event.iRepeats == 1);
- }
- else
- {
- // seek begins immediately, i.e., with first keypress
- m_bInSeekMode = true;
- }
- if( m_bInSeekMode )
- {
- // notify handler to enter seeking mode
- DPRINTF(SYMP_INFO, ("HandleSeekKeyEvent(): enter seek moden"));
- m_playView->HandleCommandL(EBeginSeek);
- }
- }
- if (m_bInSeekMode)
- {
- TInt command = 0;
- switch(event.iScanCode)
- {
- case EStdKeyUpArrow:
- command = ESeekForward;
- break;
- case EStdKeyDownArrow:
- command = ESeekBack;
- break;
- default:
- HX_ASSERT(false);
- }
- // notify handler of change in seek position
- m_playView->HandleCommandL(command);
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // CHXAvPresentationWindow Implementation....
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /*
- * CHXAvPresentationWindow
- * -----------------------
- * Ctor
- *
- */
- CHXAvPresentationWindow::CHXAvPresentationWindow()
- : m_playerUI(NULL)
- , m_bShowLogo(true)
- , m_bShowAudioIcon(false)
- , m_bLastClipPlayedHadVideo(false)
- {
- }
- /*
- * ~CHXAvPresentationWindow
- * ------------------------
- * Dtor
- *
- */
- CHXAvPresentationWindow::~CHXAvPresentationWindow()
- {
- }
- /*
- * ConstructL
- * ----------
- * Contruct this control
- *
- */
- void
- CHXAvPresentationWindow::ConstructL(CCoeControl *parent, CHXAvPlayerUI *playerUI, const TRect& rc)
- {
- m_playerUI = playerUI;
- m_parent = parent;
- CreateWindowL();
- SetRect(rc);
- ActivateL();
- LoadLogoItems();
- }
- /*
- * OfferKeyEvent
- * -------------
- * Pass it up to the parent.
- *
- */
- TKeyResponse
- CHXAvPresentationWindow::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
- {
- return m_parent->OfferKeyEventL(aKeyEvent, aType);
- }
- /*
- * Draw
- * ----
- * Draw the background black.
- *
- */
- void
- CHXAvPresentationWindow::Draw(const TRect& aRect) const
- {
- DPRINTF(SYMP_INFO, ("CHXAvPresentationWindow::Draw()n"));
- CWindowGc& gc = SystemGc();
- // Fill background with black...
- gc.Clear();
- TRect rcDraw = Rect();
- gc.SetPenStyle(CGraphicsContext::ENullPen);
- gc.SetBrushColor(KRgbBlack);
- gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
- gc.DrawRect(aRect);
- // Draw logo bitmap...
- if( m_bShowLogo && m_logo.Handle() )
- {
- // draw logo centered within the window
- TPoint ptDraw = rcDraw.iTl;
- TSize szLogo = m_logo.SizeInPixels();
- ptDraw.iX += (rcDraw.Width() - szLogo.iWidth) / 2;
- ptDraw.iY += (rcDraw.Height() - szLogo.iHeight) / 2;
-
- // Draw full logo that fits within the window
- gc.BitBlt(ptDraw, &m_logo);
- }
- // Draw audio icon...
- if (m_bShowAudioIcon && m_audioIcon.Handle())
- {
- // draw in upper left (XXXLCM make configurable/decorate)
- const TInt AUDIO_ICON_OFFSET = 4;
- gc.BitBlt(TPoint(AUDIO_ICON_OFFSET,AUDIO_ICON_OFFSET), &m_audioIcon);
- }
- }
- /*
- * OnPlayInitiate
- * --------------------
- * Show the logo.
- *
- */
- void
- CHXAvPresentationWindow::OnPlayInitiate(const char* /*url*/)
- {
- DPRINTF(SYMP_INFO, ("CHXAvPresentationWindow::OnPlayInitiate()n"));
- //
- // reset video window so it shows logo
- //
- m_bLastClipPlayedHadVideo = false;
- m_bShowLogo = true;
- m_bShowAudioIcon = false;
- DrawNow();
- }
- void CHXAvPresentationWindow::OnLoadSession(IHXRequest* request)
- {
- //
- // hide logo / show audio icon based on presentation content
- //
- CHXAvPlayer* pPlayer = m_playerUI->GetPlayer();
- bool bHasVideo = pPlayer->GetClipInfo().IsVideoPresentation();
- m_bShowLogo = !bHasVideo;
- m_bShowAudioIcon = !bHasVideo;
- m_bLastClipPlayedHadVideo = bHasVideo;
- DrawNow();
-
- }
- /*
- * OnStop
- * ------------
- * If we are showing the audio icon, get rid of it.
- *
- */
- void
- CHXAvPresentationWindow::OnStop()
- {
- DPRINTF(SYMP_INFO, ("CHXAvPresentationWindow::OnStop"));
- // If the last clip played had no video, then we have to make sure the audio icon is erased...
- if (!m_bLastClipPlayedHadVideo)
- {
- m_bShowAudioIcon = false;
- DrawNow();
- }
- }
- /*
- * LoadLogoItems
- * -------------
- * Create and set the logo icons.
- *
- */
- void
- CHXAvPresentationWindow::LoadLogoItems()
- {
- TInt idxLogo = EMbmRealplayerBackground_logo;
- TInt idxAudioIcon = EMbmRealplayerAudio_icon_left;
- SetBackgroundItems(m_playerUI->GetAppImageFilePath(), idxLogo, idxAudioIcon);
- }
- /*
- * SetBackgroundItems
- * ------------------
- * If graphic images are in different files, call multiple times, masking out this or that idx by
- * setting to -1.
- *
- */
- void
- CHXAvPresentationWindow::SetBackgroundItems(const TDesC& fileName, TInt idxLogo, TInt idxAudioIcon)
- {
- TFileName fullPath;
- RFs fs;
- fs.Connect();
- TInt err = CHXAvFile::GetFullPath(fs, fileName, fullPath, false);
-
- if (KErrNone == err)
- {
- if( idxLogo >= 0 )
- {
- m_logo.Reset();
- m_logo.Load(fullPath, idxLogo);
- }
- if( idxAudioIcon >= 0 )
- {
- m_audioIcon.Reset();
- m_audioIcon.Load(fullPath, idxAudioIcon);
- }
- }
- fs.Close();
- }