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

Symbian

开发平台:

C/C++

  1. /*============================================================================*
  2.  *
  3.  * (c) 1995-2002 RealNetworks, Inc. Patents pending. All rights reserved.
  4.  *
  5.  *============================================================================*/
  6. /*
  7.    Description: 
  8.    draws and manages navi pane area shown during playlist navigate state
  9. */
  10. #include <aknutils.h>
  11. #include "chxavmisc.h"
  12. #include "chxavcleanupstack.h"
  13. #include "chxavcleanstring.h"
  14. #include "hxsym_debug.h"
  15. #include "chxavplaylistnavicontrol.h"
  16. ////////////////////////////////
  17. //
  18. CHXAvPlaylistNaviControl* CHXAvPlaylistNaviControl::NewL(CHXAvPlayer* pPlayer, const CCoeControl& parent)
  19. {
  20.     CHXAvPlaylistNaviControl* pSelf = new(ELeave) CHXAvPlaylistNaviControl();
  21.     AUTO_PUSH_POP(pSelf);
  22.     pSelf->ConstructL(pPlayer, parent);
  23.     return pSelf;
  24. }
  25. ///////////////////////////////////
  26. // ctor
  27. CHXAvPlaylistNaviControl::CHXAvPlaylistNaviControl()
  28. {
  29. }
  30. ///////////////////////////////////
  31. // dtor
  32. CHXAvPlaylistNaviControl::~CHXAvPlaylistNaviControl()
  33. {
  34.     if(m_spPlayer)
  35.     {
  36.         m_spPlayer->GetPlayerState().RemoveObserver(this);
  37.     }
  38. }
  39. ////////////////////////////
  40. //
  41. void CHXAvPlaylistNaviControl::ConstructL(CHXAvPlayer* pPlayer, const CCoeControl& parent)
  42. {
  43.     m_spPlayer = pPlayer;
  44.     m_spPlayer->GetPlayerState().AddObserver(this);
  45.     SetContainerWindowL(parent);
  46.     TRect rc(parent.Rect());
  47.     SetRect(rc);
  48.     // save this; we want to draw over whole navi control (see SizeChanged)
  49.     m_rcParent = rc;
  50.     //
  51.     // playlist text
  52.     //
  53.     const TInt CID_PLAYLIST_TEXT = 1;
  54.     m_spPlaylistText = CHXAvTextControl::NewL(*this, CID_PLAYLIST_TEXT);
  55.     m_spPlaylistText->SetTextColor(KRgbWhite);
  56.     m_spPlaylistText->UpdateFont(LatinBold12());
  57.     m_spPlaylistText->MakeVisible(ETrue);
  58.     m_spPlaylistText->SetRect(rc); // for now
  59.     UpdatePlaylistTextL();
  60. }
  61. //////////////////////////////////////////////
  62. // hide or show playlist menu items depending
  63. // on whether or not a playlist is loaded
  64. void CHXAvPlaylistNaviControl::UpdatePlaylistTextL()
  65.     bool bHaveRam = m_spPlayer->IsPlaylistLoaded(); 
  66.     if( bHaveRam )
  67.     {
  68.         // 1-based indexes
  69.         TInt idxCount = m_spPlayer->GetPlaylistItemCount();
  70.         TInt idxCurrent = m_spPlayer->GetPlaylistCurrentIndex() + 1;
  71.         CHXAvCleanString playUrl(m_spPlayer->GetPlayURL());
  72.         bool bLocal = CHXAvUtil::IsLocal(playUrl());
  73.         HX_ASSERT(idxCount >= 1 && idxCurrent >= 1);
  74.         if( idxCount > 1 )
  75.         {
  76.             //XXXLCM resource
  77.             _LIT(KLocalClipFormat, "Local clip %d/%d");
  78.             _LIT(KRemoteClipFormat, "Remote clip %d/%d");
  79.             TBuf<40> buf;
  80.             if( bLocal )
  81.             {
  82.                 buf.Format(KLocalClipFormat, idxCurrent, idxCount);
  83.             }
  84.             else
  85.             {
  86.                 buf.Format(KRemoteClipFormat, idxCurrent, idxCount);
  87.             }
  88.             // determine width needed
  89.             const CFont* pFont = m_spPlaylistText->GetFont();
  90.             TInt cxText = pFont->TextWidthInPixels(buf);
  91.             const TUint CX_RIGHT_BORDER = 2;
  92.             // size rect so text just fits
  93.             TRect rcText = m_rcParent;
  94.             rcText.iBr.iX -= CX_RIGHT_BORDER;
  95.             rcText.iTl.iX = rcText.iBr.iX - cxText;
  96.             if(rcText.iTl.iX < m_rcParent.iTl.iX )
  97.             {
  98.                 rcText.iTl.iX = m_rcParent.iTl.iX;
  99.             }    
  100.             m_spPlaylistText->SetRect(rcText);
  101.             m_spPlaylistText->SetText(buf);         
  102.         }
  103.         
  104.     }
  105. }
  106. ////////////////////////////////////////
  107. //IHXSymPlayerStateObserver
  108. void CHXAvPlaylistNaviControl::OnAdvancePlaylist()
  109. {      
  110.     UpdatePlaylistTextL();    
  111.     m_spRefreshCmd->Execute();
  112. }
  113. ////////////////////////////////////////
  114. //
  115. void 
  116. CHXAvPlaylistNaviControl::Draw(const TRect& /* rect */) const
  117. {
  118.     // don't draw background; navi pane container draws background for us
  119. }
  120. //////////////////////////////
  121. //
  122. // CCoeControl
  123. //
  124. TInt CHXAvPlaylistNaviControl::CountComponentControls() const
  125.     return 1;
  126. }
  127. //////////////////////////////
  128. //
  129. // CCoeControl
  130. //
  131. CCoeControl* CHXAvPlaylistNaviControl::ComponentControl(TInt aIndex) const
  132. {
  133.     HX_ASSERT(aIndex == 0);
  134.     return m_spPlaylistText.Ptr();
  135. }