⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btpointtopointappview.cpp

📁 Symbian下的p2p工程
💻 CPP
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */


// INCLUDE FILES
#include "BTPointToPointAppView.h"
#include "BTPointToPoint.pan"
#include "MessageClient.h"
#include "MessageServer.h"

// ============================ MEMBER FUNCTIONS ==============================

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::NewL()
// Two-phased constructor.
// ----------------------------------------------------------------------------
//
CBTPointToPointAppView* CBTPointToPointAppView::NewL( const TRect& aRect )
    {
    CBTPointToPointAppView* self = CBTPointToPointAppView::NewLC( aRect );
    CleanupStack::Pop( self );
    return self;
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::NewLC()
// Two-phased constructor.
// ----------------------------------------------------------------------------
//
CBTPointToPointAppView* CBTPointToPointAppView::NewLC( const TRect& aRect )
    {
    CBTPointToPointAppView* self = new ( ELeave ) CBTPointToPointAppView;
    CleanupStack::PushL( self );
    self->ConstructL( aRect );
    return self;
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// ----------------------------------------------------------------------------
//
void CBTPointToPointAppView::ConstructL( const TRect& aRect )
    {
    // Create a window for this application view
    CreateWindowL();

    // Set the windows size
    SetRect( aRect );

    // Create a control to display a list of messages
    iListBox = new ( ELeave ) CAknSingleNumberStyleListBox;
    iListBox->SetContainerWindowL( *this );
    iListBox->ConstructL( this, 0 );

    iListBox->SetRect( aRect.Size() );

    iListBox->ActivateL();
    iListBox->CreateScrollBarFrameL( ETrue );
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
        CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto );

    // Create an array to hold the messages
    iMessageList = new ( ELeave ) CDesCArrayFlat( 10 );

    // Give it to the control
    CTextListBoxModel* model = iListBox->Model();
    model->SetItemTextArray( iMessageList );

    // transfer ownership of iMessageList
    model->SetOwnershipType( ELbmOwnsItemArray );

    // Activate the window, which makes it ready to be drawn
    ActivateL();
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::CBTPointToPointAppView()
// Constructor.
// ----------------------------------------------------------------------------
//
CBTPointToPointAppView::CBTPointToPointAppView()
    {
    // no implementation required
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::~CBTPointToPointAppView()
// Destructor.
// ----------------------------------------------------------------------------
//
CBTPointToPointAppView::~CBTPointToPointAppView()
    {
    // iMessageList not deleted as it is owned by iListBox->Model()

    delete iListBox;
    iListBox = NULL;
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::ClearMessageListL()
// Clears all the entries in the list view.
// ----------------------------------------------------------------------------
//
void CBTPointToPointAppView::ClearMessageListL()
    {
    iMessageList->Reset();

    iListBox->HandleItemRemovalL();
    iListBox->Reset();

    iMsgIndex = 0;
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::CountComponentControls()
// Returns the specified component control.
// ----------------------------------------------------------------------------
//
TInt CBTPointToPointAppView::CountComponentControls() const
    {
    return 1; // Only have one Component
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::ComponentControl()
// Gets the specified component of a compound control.
// ----------------------------------------------------------------------------
//
CCoeControl* CBTPointToPointAppView::ComponentControl( TInt aIndex ) const
    {
    __ASSERT_ALWAYS( aIndex == 0, Panic( EBTPointToPointInvalidControlIndex ) );
    return iListBox;    //  Return the component
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::OfferKeyEventL()
// Offer the key event to the list box.
// ----------------------------------------------------------------------------
//
TKeyResponse CBTPointToPointAppView
::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
    {
    return iListBox->OfferKeyEventL( aKeyEvent, aType );
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::LogL()
// Add an entry to the log.
// ----------------------------------------------------------------------------
//
void CBTPointToPointAppView::LogL( const TDesC& aText )
    {
    LogL( aText, KNullDesC );
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::LogL()
// A number to append onto the entry.
// ----------------------------------------------------------------------------
//
void CBTPointToPointAppView::LogL( const TDesC& aText, TInt aNumber )
    {
    TBuf<KMaxTIntLen> numberString;

    numberString.Num( aNumber );

    LogL( aText, numberString );
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::LogL()
// Extra text to append onto the entry.
// ----------------------------------------------------------------------------
//
void CBTPointToPointAppView::LogL( const TDesC& aText,
                                   const TDesC& aExtraText )
    {
    HBufC* buffer = HBufC::NewLC( KMessageHeaderLen + aText.Length() +
                                  aExtraText.Length() );

    buffer->Des().Num( ++iMsgIndex );
    buffer->Des().Append( '\t' );
    buffer->Des().Append( aText );
    buffer->Des().Append( aExtraText );

    // add the message to the list
    iMessageList->AppendL( *buffer );
    CleanupStack::PopAndDestroy( buffer );

    // tell the control about the change
    iListBox->HandleItemAdditionL();
    }

// ----------------------------------------------------------------------------
// CBTPointToPointAppView::ContainsEntries()
// Does the view contain any log entries.
// ----------------------------------------------------------------------------
//
TBool CBTPointToPointAppView::ContainsEntries()
    {
    return iListBox->Model()->NumberOfItems() != 0;
    }

// End of File

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -