📄 finditemtestappcontainer.cpp
字号:
/*
* ============================================================================
* Name : CFindItemTestAppContainer from FindItemTestAppContainer.h
* Part of : FindItemTestApp
* Interface :
* Description : Find Item Test application container implementation
* Version :
*
* Copyright (c) 2002-2006 Nokia Corporation.
* This material, including documentation and any related
* computer programs, is protected by copyright controlled by
* Nokia Corporation.
* ==============================================================================
*/
// INCLUDE FILES
#include <eiklabel.h> // for example label control
#include <aknlists.h>
#include <barsread.h> // for TResourceReader
#include <FindItemTestApp.rsg>
#include "FindItemTestAppContainer.h"
// CONSTANTS
const TInt KMaxLineLength(23);
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CFindItemTestAppContainer::ConstructL
// Symbian 2nd phase constructor can leave.
// ---------------------------------------------------------
//
void CFindItemTestAppContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iListBox = new(ELeave) CEikTextListBox();
iListBox->SetContainerWindowL( *this );
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC(reader, R_FINDITEMTESTAPP_LIST);
iListBox->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy();
iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EOn);
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
_LIT(KFindItemTest, "Find Item Test");
iLabel->SetTextL( KFindItemTest );
SetRect(aRect);
ActivateL();
}
// -----------------------------------------------------------------------------
// CFindItemTestAppContainer::~CFindItemTestAppContainer
// Destructor
// -----------------------------------------------------------------------------
//
CFindItemTestAppContainer::~CFindItemTestAppContainer()
{
delete iListBox;
delete iLabel;
}
// ---------------------------------------------------------
// CFindItemTestAppContainer::SizeChanged
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CFindItemTestAppContainer::SizeChanged()
{
TRect parentRect(Rect());
TSize listBoxSize(parentRect.Width(), parentRect.Height());
iListBox->SetExtent( TPoint(0,0), listBoxSize );
}
// ---------------------------------------------------------
// CFindItemTestAppContainer::CountComponentControls
// Return number of controls in container
// ---------------------------------------------------------
//
TInt CFindItemTestAppContainer::CountComponentControls() const
{
return 2; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CFindItemTestAppContainer::ComponentControl
// Return component control
// ---------------------------------------------------------
//
CCoeControl* CFindItemTestAppContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iListBox;
case 1:
return iLabel;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CFindItemTestAppContainer::Draw
// ---------------------------------------------------------
//
void CFindItemTestAppContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CFindItemTestAppContainer::HandleControlEventL
// ---------------------------------------------------------
//
void CFindItemTestAppContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
// -----------------------------------------------------------------------------
// CFindItemTestAppContainer::AddMessageL
// Add message to list box in the container
// -----------------------------------------------------------------------------
//
void CFindItemTestAppContainer::AddMessageL( const TDesC& aMsg )
{
CDesCArray* list = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
TInt pos(0);
while( aMsg.Length() > pos+KMaxLineLength )
{
list->AppendL( aMsg.Mid( pos, KMaxLineLength ) );
pos += KMaxLineLength;
}
list->AppendL( aMsg.Mid( pos ) );
iListBox->HandleItemAdditionL();
// Select the last item added
iListBox->SetCurrentItemIndexAndDraw( iListBox->Model()->NumberOfItems() - 1 );
iListBox->SetFocus( ETrue );
}
// -----------------------------------------------------------------------------
// CFindItemTestAppContainer::ResetMessage
// Reset messages of list box in the container
// -----------------------------------------------------------------------------
//
void CFindItemTestAppContainer::ResetMessage()
{
CDesCArray* list = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
// remove all items from the text array
list->Reset();
// Redraw the listbox
iListBox->DrawNow();
// Set keyboard focus to listbox if you want
iListBox->SetFocus( ETrue );
}
// -----------------------------------------------------------------------------
// CFindItemTestAppContainer::OfferKeyEventL
// Pass key event to appropriate controls
// -----------------------------------------------------------------------------
//
TKeyResponse CFindItemTestAppContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,TEventCode aType )
{
return iListBox->OfferKeyEventL( aKeyEvent, aType );
}
// ---------------------------------------------------------
// CFindItemTestAppContainer::HandleResourceChange()
// Called by framework when layout is changed.
// ---------------------------------------------------------
//
void CFindItemTestAppContainer::HandleResourceChange(TInt aType)
{
CCoeControl::HandleResourceChange(aType);
if ( aType==KEikDynamicLayoutVariantSwitch )
{
TRect rect;
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
SetRect(rect);
}
// Redraw the listbox
iListBox->DrawNow();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -