📄 btobjectexchangeappview.cpp
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */
// INCLUDE FILES
#include "BTObjectExchangeAppView.h"
#include "BTObjectExchange.pan"
#include "BTObjectExchangeAppUi.h"
// ============================ MEMBER FUNCTIONS ==============================
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::NewL()
// Two-phased constructor.
// ----------------------------------------------------------------------------
//
CBTObjectExchangeAppView* CBTObjectExchangeAppView::NewL( const TRect& aRect )
{
CBTObjectExchangeAppView* self = CBTObjectExchangeAppView::NewLC( aRect );
CleanupStack::Pop( self );
return self;
}
// -----------------------------------------------------------------------------
// CBTObjectExchangeAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CBTObjectExchangeAppView* CBTObjectExchangeAppView::NewLC( const TRect& aRect )
{
CBTObjectExchangeAppView* self = new ( ELeave ) CBTObjectExchangeAppView;
CleanupStack::PushL( self );
self->ConstructL( aRect );
return self;
}
// -----------------------------------------------------------------------------
// CBTObjectExchangeAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CBTObjectExchangeAppView::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();
}
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::CBTObjectExchangeAppView()
// Constructor.
// ----------------------------------------------------------------------------
//
CBTObjectExchangeAppView::CBTObjectExchangeAppView()
: iMsgIndex( 0 )
{
// No implementation required.
}
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::~CBTObjectExchangeAppView()
// Destructor.
// ----------------------------------------------------------------------------
//
CBTObjectExchangeAppView::~CBTObjectExchangeAppView()
{
// iMessageList is not deleted as it is owned by iListBox->Model()
delete iListBox;
iListBox = NULL;
}
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::CountComponentControls()
// Return the number of component controls.
// ----------------------------------------------------------------------------
//
TInt CBTObjectExchangeAppView::CountComponentControls() const
{
return 1; // Only have one Component
}
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::ComponentControl()
// Gets the specified component of a compound control.
// ----------------------------------------------------------------------------
//
CCoeControl* CBTObjectExchangeAppView::ComponentControl( TInt aIndex ) const
{
__ASSERT_ALWAYS( aIndex == 0,
Panic( EBTObjectExchangeInvalidControlIndex ) );
return iListBox;
}
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::OfferKeyEventL()
// Offer the key event to the list box.
// ----------------------------------------------------------------------------
//
TKeyResponse CBTObjectExchangeAppView
::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
{
//capture keyevent, if it is 'OK' key then get current
//text and try to launch the file using document handler
if ( aType == EEventKey )
{
switch ( aKeyEvent.iScanCode )
{
case 167: //joystick key press
{
TPtrC16 textRow = (*iMessageList)[iListBox->CurrentItemIndex()];
//The row of text is like '1\ttest.txt'
TInt tabIndex = textRow.Find(KTabulator) + 2;
TPtrC fileName = textRow.Right( textRow.Length() - tabIndex + 1 );
if ( HandleJoystickPressL(fileName) )
return EKeyWasConsumed;
}
};
}
return iListBox->OfferKeyEventL( aKeyEvent, aType );
}
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::LogL( const TDesC& aText )
// Add an entry to the log.
// ----------------------------------------------------------------------------
//
void CBTObjectExchangeAppView::LogL( const TDesC& aText )
{
LogL( aText, KNullDesC );
}
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::LogL( const TDesC& aText, TInt aNumber )
// A number to append onto the entry.
// ----------------------------------------------------------------------------
//
void CBTObjectExchangeAppView::LogL( const TDesC& aText, TInt aNumber )
{
TBuf<KMaxTIntLen> numberString;
numberString.Num( aNumber );
LogL( aText, numberString );
}
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::LogL( const TDesC& aText, const TDesC& aExtraText)
// Extra text to append onto the entry.
// ----------------------------------------------------------------------------
//
void CBTObjectExchangeAppView::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();
//Set last item current so the recently added log is visible
iListBox->SetCurrentItemIndex ( iMessageList->Count()-1 );
DrawDeferred();
}
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::ClearMessageListL()
// Clears all the entries in the list view.
// ----------------------------------------------------------------------------
//
void CBTObjectExchangeAppView::ClearMessageListL()
{
iMessageList->Reset();
iListBox->HandleItemRemovalL();
iListBox->Reset();
iMsgIndex = 0;
}
// ----------------------------------------------------------------------------
// CBTObjectExchangeAppView::ContainsEntries()
// Does the view contain any log entries.
// ----------------------------------------------------------------------------
//
TBool CBTObjectExchangeAppView::ContainsEntries()
{
return iListBox->Model()->NumberOfItems() != 0;
}
TBool CBTObjectExchangeAppView::HandleJoystickPressL(TDesC& aLine)
{
CBTObjectExchangeAppUi * appui = static_cast<CBTObjectExchangeAppUi *> (CCoeEnv::Static()->AppUi() );
return appui->HandleJoystickPressL(aLine);
}
// Called by framework when the view size is changed
void CBTObjectExchangeAppView::SizeChanged()
{
if(iListBox)
{
// Resize the list control
iListBox->SetRect( Rect() );
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -