📄 bookdisplaycontainer.cpp
字号:
#include <gulicon.h>
#include <aknutils.h> // definition of AKN_LAF_COLOR()
#include <avkon.hrh>
#include <akntitle.h>
#include <aknnotewrappers.h>
#include <aknlists.h>
#include <eikdialg.h>
#include <aknsfld.h>
#include "BookDisplayContainer.h"
#include "BookInfo.h"
//////////////////////////////////////////////////////////////////////////
CBookDisplayContainer::CBookDisplayContainer()
{
m_pListBox = NULL;
m_pBookArray = NULL;
}
// EPOC default constructor can leave.
void CBookDisplayContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
m_pListBox = new( ELeave ) CAknSingleStyleListBox();
m_pListBox->SetContainerWindowL( *this );
m_pListBox->ConstructL(this, EAknListBoxSelectionList);
m_pListBox->CreateScrollBarFrameL( ETrue );
m_pListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
m_pBookArray = new (ELeave) CDesCArrayFlat(10);
CleanupStack::PushL(m_pBookArray);
CTextListBoxModel* textModel = m_pListBox->Model();
textModel->SetItemTextArray( m_pBookArray );
textModel->SetOwnershipType(ELbmDoesNotOwnItemArray);
CleanupStack::Pop(1);
CAknSearchField::TSearchFieldStyle style(
CAknSearchField::ESearch );
style = CAknSearchField::EPopup;
CAknFilteredTextListBoxModel* model =
STATIC_CAST( CAknFilteredTextListBoxModel*, textModel );
m_pFindBox = CAknSearchField::NewL(*this,
style,
NULL,
20);
CleanupStack::PushL(m_pFindBox);
// Creates CAknListBoxFilterItems class.
model->CreateFilterL( m_pListBox, m_pFindBox );
//Filter can get by model->Filter();
CleanupStack::Pop(m_pFindBox); // findbox
SizeChanged();
m_pFindBox->MakeVisible( EFalse );
m_pFindBox->ActivateL();
SetRect( aRect );
ActivateL();
}
// destructor
CBookDisplayContainer::~CBookDisplayContainer()
{
MEMORY_FREE(m_pListBox);
MEMORY_FREE(m_pFindBox);
MEMORY_FREE(m_pBookArray);
}
void CBookDisplayContainer::SizeChanged()
{
if(m_pFindBox)
{
SizeChangedForFindBox();
}
}
// ---------------------------------------------------------
// CBookDisplayContainer::CountComponentControls() const
// return the number of controls
// ---------------------------------------------------------
//
TInt CBookDisplayContainer::CountComponentControls() const
{
// return number of controls inside this container
return 2;
}
// ---------------------------------------------------------
// CBookDisplayContainer::ComponentControl(TInt aIndex) const
// return the pointer to specified control.
// ---------------------------------------------------------
//
CCoeControl* CBookDisplayContainer::ComponentControl( TInt aIndex ) const
{
switch (aIndex)
{
case 0:
return m_pListBox;
break;
case 1:
return m_pFindBox;
break;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CBookDisplayContainer::Draw(const TRect& aRect) const
// handle the BookDisplay when client region must be redrawn.
// ---------------------------------------------------------
//
void CBookDisplayContainer::Draw( const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetPenColor(KRgbGray);
// gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
// gc.SetBrushColor(KRgbWhite);
// gc.DrawRect(Rect());
}
// ---------------------------------------------------------
// CAknExGridContainer::OfferKeyEventL(
// const TKeyEvent& aKeyEvent, TEventCode aType )
// Handles the key events.
// ---------------------------------------------------------
//
TKeyResponse CBookDisplayContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
{
if ( m_pListBox )
{
if ( m_pFindBox )
{
TBool needRefresh( EFalse );
TBool flagsOfPopup( EFalse );
// Offers the key event to find box.
if ( AknFind::HandleFindOfferKeyEventL( aKeyEvent, aType, this,
m_pListBox, m_pFindBox,
flagsOfPopup,
needRefresh ) ==
EKeyWasConsumed )
{
if ( needRefresh )
{
SizeChangedForFindBox();
DrawNow();
}
return EKeyWasConsumed;
}
}
return m_pListBox->OfferKeyEventL( aKeyEvent, aType );
}
}
void CBookDisplayContainer::SizeChangedForFindBox()
{
TInt findWindowResourceId( R_AVKON_FIND_PANE );
TInt listAreaResourceId( R_AVKON_LIST_GEN_PANE_X );
TInt findWindowParentId( R_AVKON_MAIN_PANE_PARENT_NONE );
TBool flagsOfPopup( EFalse ); // Flag for find popup.
findWindowResourceId = R_AVKON_POPUP_FIND_WINDOW;
listAreaResourceId = R_AVKON_LIST_GEN_PANE;
findWindowParentId = R_AVKON_MAIN_PANE_WITH_STATUS_PANE;
flagsOfPopup = ETrue;
// Calls HandleFindSizeChanged after creates findbox.
AknFind::HandleFindSizeChanged(
this, m_pListBox, m_pFindBox, flagsOfPopup, findWindowResourceId,
listAreaResourceId, R_AVKON_LIST_GEN_PANE_WITH_FIND_POPUP,
findWindowParentId );
if(m_pBookArray->Count()!=0)
{
// m_pFindBox->MakeVisible(ETrue);
}
}
TInt CBookDisplayContainer::GetIndex()
{
return m_pListBox->CurrentItemIndex();
}
void CBookDisplayContainer::AddInfoToList(CBookInfo* aBookInfo)
{
TInt nLength = aBookInfo->GetFirstName()->Length()+aBookInfo->GetLastName()->Length();
HBufC* sName = HBufC::NewLC(nLength + 10);
sName->Des().Copy(_L("\t"));
if(aBookInfo->GetLastName()->Length() == 0 && aBookInfo->GetFirstName()->Length() == 0)
{
sName->Des().Append(_L("(未命名)"));
}
else
{
sName->Des().Append(aBookInfo->GetLastName()->Des());
sName->Des().Append(_L(" "));
sName->Des().Append(aBookInfo->GetFirstName()->Des());
}
m_pBookArray->AppendL(sName->Des());
m_pListBox->HandleItemAdditionL();
CleanupStack::PopAndDestroy(1);
// m_pFindBox->MakeVisible(ETrue);
}
void CBookDisplayContainer::DelInfoFromList(TInt aIndex)
{
m_pBookArray->Delete(aIndex);
m_pListBox->HandleItemRemovalL();
m_pListBox->HandleItemAdditionL();
if(m_pBookArray->Count()==0)
{
m_pFindBox->MakeVisible(EFalse);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -