www.pudn.com > nokie_soundplayer.rar > soundview.cpp


/* Copyright (c) 2004, Nokia. All rights reserved */ 
 
 
// INCLUDE FILES 
#include  
#include  
#include  
#include  
 
#include "sound.pan" 
#include "SoundView.h" 
#include "SoundDoc.h" 
 
 
// ========================= MEMBER FUNCTIONS ================================== 
 
// ----------------------------------------------------------------------------- 
// CSoundView::CSoundView() 
// C++ default constructor can NOT contain any code, that might leave. 
// ----------------------------------------------------------------------------- 
// 
CSoundView::CSoundView() 
    { 
    // No implementation required 
    } 
 
// ----------------------------------------------------------------------------- 
// CSoundView::NewL() 
// Two-phased constructor. 
// ----------------------------------------------------------------------------- 
// 
CSoundView* CSoundView::NewL( const TRect& aRect, const TDesC& aMessage ) 
    { 
    CSoundView* self = CSoundView::NewLC( aRect, aMessage ); 
    CleanupStack::Pop( self ); 
    return self; 
    } 
 
// ----------------------------------------------------------------------------- 
// CSoundView::NewLC() 
// Two-phased constructor. 
// ----------------------------------------------------------------------------- 
// 
CSoundView* CSoundView::NewLC( const TRect& aRect, const TDesC& aMessage ) 
    { 
    CSoundView* self = new ( ELeave ) CSoundView(); 
    CleanupStack::PushL( self ); 
    self->ConstructL( aRect, aMessage ); 
    return self; 
    } 
 
 
// ----------------------------------------------------------------------------- 
// CSoundView::ConstructL() 
// Symbian 2nd phase constructor can leave. 
// ----------------------------------------------------------------------------- 
// 
void CSoundView::ConstructL( const TRect& aRect, const TDesC& aMessage ) 
    { 
 
    // Create a window for this application view 
    CreateWindowL(); 
 
    iBrushStyle = CGraphicsContext::ESolidBrush; 
 
    iBrushColor = iEikonEnv->ControlColor( EColorWindowBackground, *this ); 
 
    iLabel = new ( ELeave ) CEikLabel; 
    iLabel->SetContainerWindowL( *this ); 
    iLabel->SetTextL( aMessage ); 
 
    // Set the windows size 
    SetRect( aRect ); 
 
    // Activate the window, which makes it ready to be drawn 
    ActivateL(); 
    } 
 
// ----------------------------------------------------------------------------- 
// CSoundView::~CSoundView() 
// Destructor. 
// ----------------------------------------------------------------------------- 
// 
CSoundView::~CSoundView() 
    { 
    delete iLabel; 
    } 
 
// ----------------------------------------------------------------------------- 
// CSoundView::Draw()  
// Draws the display 
// ----------------------------------------------------------------------------- 
// 
void CSoundView::Draw( const TRect& /*aRect*/ ) const 
    { 
    CWindowGc& gc = SystemGc(); 
    gc.Clear( Rect() ); 
    } 
 
// ----------------------------------------------------------------------------- 
// CSoundView::CountComponentControls() 
// returns number of controls inside this container. 
// ----------------------------------------------------------------------------- 
// 
TInt CSoundView::CountComponentControls() const 
    { 
    return 1;  
    } 
 
// ----------------------------------------------------------------------------- 
// CSoundView::ComponentControl() 
// returns pointer of controls inside this container 
// ----------------------------------------------------------------------------- 
// 
CCoeControl* CSoundView::ComponentControl( TInt aIndex ) const 
    { 
    switch ( aIndex ) 
        { 
        case 0: 
            return iLabel; 
 
        default: 
            User::Panic( KSound, KSoundPanicBadParameter ); 
            return 0; 
        } 
    } 
 
// ----------------------------------------------------------------------------- 
// CSoundView::SizeChanged() 
// Called by framework when the view size is changed. 
// ----------------------------------------------------------------------------- 
// 
void CSoundView::SizeChanged() 
    { 
    TRect rect = Rect(); 
 
    TSize labelSize = iLabel->MinimumSize(); 
    rect.iTl.iX += ( rect.Width() - labelSize.iWidth ) / 2; 
    rect.iTl.iY += ( rect.Height() - labelSize.iHeight ) / 2; 
    rect.iBr = rect.iTl + labelSize; 
 
    iLabel->SetRect( rect ); 
    } 
 
 
// ----------------------------------------------------------------------------- 
// CSoundView::NotifyStatusL() 
// Notify Status 
// ----------------------------------------------------------------------------- 
// 
void CSoundView::NotifyStatusL( const TDesC& aMessage ) 
    { 
    iLabel->SetTextL( aMessage ); 
    SizeChanged(); 
    } 
 
 
// End of File