?? telbookcontainer.cpp
字號:
/*
* ============================================================================
* Name : CTelBookContainer from CCoeControl, MCoeControlObserver
* Part of : Hello
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <EveryDay.rsg>
#include "EveryDay.hrh"
#include "TelBookContainer.h"
#include <aknnotewrappers.h>
#include <eikclbd.h>
#include <eiklabel.h> // for example label control
#include <barsread.h> // for resource reader
#include <eikedwin.h> // for CEikEdwin
#include <eikgted.h> // for CEikGlobalTextEditor
#include <aknselectionlist.h> //for CAknSelectionListDialog
#include <AknQueryDialog.h> //for CAknQueryDialog
#include <eikmenub.h>
#include <aknlists.h> //for CAknSingleNumberStyleListBox
#include <StringLoader.h> //for StringLoader
#include <AknIconArray.h> //for CAknIconArray
#include "EveryDayAppUi.h"
#include "PHKServerBookEngine.h"
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
CTelBookContainer::CTelBookContainer()
{
m_pListBox = NULL;
m_pSearchBox = NULL;
m_pListBoxArray = NULL;
}
// EPOC default constructor can leave.
void CTelBookContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
MakeListBoxL();//界面
ActivateL();
}
// Destructor
CTelBookContainer::~CTelBookContainer()
{
if (m_pListBox)
{
delete m_pListBox;
m_pListBox = NULL;
}
if (m_pSearchBox)
{
delete m_pSearchBox;
m_pSearchBox = NULL;
}
if (m_pListBoxArray)
{
// m_pListBoxArray->Reset();
delete m_pListBoxArray;
m_pListBoxArray = NULL;
}
}
// ---------------------------------------------------------
// CTelBookContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CTelBookContainer::FocusTo(TInt aCommand)
{
}
// ---------------------------------------------------------
// CTelBookContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CTelBookContainer::SizeChanged()
{
if (m_pListBox)
{
if (m_pSearchBox)
{
CAknSingleNumberStyleListBox* aknListBox = STATIC_CAST(CAknSingleNumberStyleListBox*,
m_pListBox);
AknFind::HandleFixedFindSizeChanged(this, aknListBox, m_pSearchBox);
}
else
{
m_pListBox->SetRect(Rect()); // Sets rectangle of lstbox.
}
}
}
// ---------------------------------------------------------
// CTelBookContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CTelBookContainer::CountComponentControls() const
{
if(m_pListBox && m_pSearchBox) //
{
return 2;
}
else
{
return 0;
}
}
// ---------------------------------------------------------
// CTelBookContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CTelBookContainer::ComponentControl(TInt aIndex) const
{
if(m_pSearchBox && aIndex)
{
return m_pSearchBox;
}
else
{
return m_pListBox;
}
}
// ---------------------------------------------------------
// CTelBookContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CTelBookContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CTelBookContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CTelBookContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent, TEventCode aType)
{
TKeyResponse Ret = EKeyWasNotConsumed;
switch (aKeyEvent.iCode)
{
case EKeyDevice3:
break;
default:
if(m_pListBox)
{
if ( m_pSearchBox )
{
TBool needRefresh( EFalse );
// Offers the key event to find box.
if ( AknFind::HandleFindOfferKeyEventL( aKeyEvent, aType, this,
m_pListBox, m_pSearchBox,
EFalse,
needRefresh ) ==
EKeyWasConsumed )
{
if ( needRefresh )
{
SizeChanged();
DrawNow();
}
return EKeyWasConsumed;
}
}
Ret = m_pListBox->OfferKeyEventL(aKeyEvent, aType);
}
break;
}
return Ret;
}
// ---------------------------------------------------------
// CTelBookContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CTelBookContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
TInt CTelBookContainer::GetSelectedIndexL() //hahaha
{
TInt Ret(-1);
if(m_pListBox)
{
TInt CurrItemInd = m_pListBox->CurrentItemIndex();
CAknFilteredTextListBoxModel* model =
STATIC_CAST(CAknFilteredTextListBoxModel*,m_pListBox->Model());
if(model && CurrItemInd >= 0)
{
Ret = model->Filter()->FilteredItemIndex(CurrItemInd); //It is used to fetch the content of a list item after filter has been used
} //Tests if cache cleanup should be performed on a message entry.
}
return Ret;
}
void CTelBookContainer::HandleResourceChange(TInt aType)
{
TRect rect;
if ( aType==KEikDynamicLayoutVariantSwitch )
{
CWsScreenDevice* ws = CEikonEnv::Static()->ScreenDevice();
rect = ws->SizeInPixels();
SetRect(rect);
}
CCoeControl::HandleResourceChange(aType);
}
void CTelBookContainer::UpdateScrollBar(CAknSingleNumberStyleListBox* aListBox)
{
if (aListBox)
{
TInt pos(aListBox->View()->CurrentItemIndex());
if (aListBox->ScrollBarFrame())
{
aListBox->ScrollBarFrame()->MoveVertThumbTo(pos);
}
}
}
CAknSearchField* CTelBookContainer::CreateFindBoxL(CAknSingleNumberStyleListBox* aListBox,
CTextListBoxModel* aModel, CAknSearchField::TSearchFieldStyle aStyle)
{
CAknSearchField* findbox = NULL;
if (aListBox && aModel)
{
// Gets pointer of CAknFilteredTextListBoxModel.
CAknFilteredTextListBoxModel* model =
STATIC_CAST( CAknFilteredTextListBoxModel*, aModel );
// Creates FindBox.
findbox = CAknSearchField::NewL( *this, aStyle, NULL, 20);
CleanupStack::PushL(findbox);
// Creates CAknListBoxFilterItems class.
model->CreateFilterL( aListBox, findbox );
//Filter can get by model->Filter();
CleanupStack::Pop(findbox); // findbox
}
return findbox;
}
void CTelBookContainer::MakeListBoxL()
{
TInt MySetIndex(0);
if(m_pListBox)
{
MySetIndex = GetSelectedIndexL();
}
TResourceReader rReader;
iCoeEnv->CreateResourceReaderLC(rReader, R_CARDLIST_LISTBOX);
m_pListBox = new( ELeave ) CAknSingleNumberStyleListBox;
m_pListBox->SetContainerWindowL(*this);
m_pListBox->ConstructFromResourceL(rReader);
CleanupStack::PopAndDestroy();
//無名片時顯示(無名片)
ShowNoCard();
CArrayPtr<CGulIcon>* icons = new( ELeave ) CAknIconArray(2);
CleanupStack::PushL(icons);
CEveryDayAppUi* pApp = (CEveryDayAppUi*)CEikonEnv::Static()->AppUi();
icons->AppendL(pApp->LoadGraphicsL(9));
CleanupStack::Pop(icons);
m_pListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
m_pListBoxArray = new (ELeave) CDesCArrayFlat (10);
// get Model
CTextListBoxModel* model = m_pListBox->Model();
// setItemTextArray
model->SetItemTextArray( m_pListBoxArray );
// setOwnershipType NotOwn
model->SetOwnershipType(ELbmDoesNotOwnItemArray);
m_pListBox->CreateScrollBarFrameL( ETrue );
m_pListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
m_pListBox->SetRect(Rect());
m_pSearchBox = CreateFindBoxL(m_pListBox, m_pListBox->Model(),
CAknSearchField::ESearch);
SizeChanged();
m_pListBox->ActivateL();
TInt ItemsCount = m_pListBox->Model()->ItemTextArray()->MdcaCount();
if(ItemsCount > MySetIndex && MySetIndex >= 0)
m_pListBox->SetCurrentItemIndex(MySetIndex);
else if(ItemsCount > 0)
m_pListBox->SetCurrentItemIndex(0);
UpdateScrollBar(m_pListBox);
}
void CTelBookContainer::SetItemToListBox (RPointerArray<CBookInfo>& aBookInfo)
{
// m_pListBox->DrawNow();
m_pListBoxArray->Reset();
TInt i = 0;
for (i = 0; i < aBookInfo.Count(); i++)
{
TBuf<KMaxPath> szTemp;
szTemp.Copy(_L("\t"));
HBufC * sNameBuf = NULL;
sNameBuf = aBookInfo[i]->GetLastName();
// 判斷是否為空
if (sNameBuf != NULL)
{
szTemp.Append(sNameBuf->Des());
}
sNameBuf = aBookInfo[i]->GetFirstName();
if (sNameBuf != NULL)
{
szTemp.Append(sNameBuf->Des());
}
if ((aBookInfo[i]->GetLastName()==NULL) && (aBookInfo[i]->GetFirstName()==NULL))
{
szTemp.Copy(_L("\t"));
TBuf<32> szNoName;
StringLoader::Load(szNoName, R_QTN_IM_PBMAIN_NAME);
szTemp.Append(szNoName);
}
// iEikonEnv->InfoMsg(szTemp);
m_pListBoxArray->AppendL(szTemp);
}
m_pListBox->HandleItemAdditionL();
}
void CTelBookContainer::GetDeleteResult (TInt & anResult)
{
// querDialog
CAknQueryDialog* pdialog = CAknQueryDialog::NewL(CAknQueryDialog::ENoTone);
TBuf <32>szTemp;
StringLoader::Load(szTemp, R_QTN_IM_PBDELETE_NAME);
szTemp.Append(_L("\n"));
TBuf <KMaxName> sInfo;
sInfo.Copy(m_pListBox->Model()->ItemText(m_pListBox->CurrentItemIndex()));
sInfo.TrimLeft();
szTemp.Append(sInfo);
szTemp.Append(_L("?"));
pdialog->SetPromptL(szTemp);
anResult = pdialog->ExecuteLD( R_QTN_PROMPT_DIALOG1);
}
void CTelBookContainer::ShowNoCard()
{
//無名片時顯示(無名片)
TBuf<32> szNoCard;
StringLoader::Load(szNoCard, R_QTN_IM_PBMAIN_PB);
m_pListBox->View()->SetListEmptyTextL(szNoCard);
}
void CTelBookContainer::GetListNum(TInt& anum)
{
anum = m_pListBox->CurrentItemIndex();
}
void CTelBookContainer::HandleMarkCommandL(TInt aCommand)
{
if (m_pListBox)
{
AknSelectionService::HandleMarkableListProcessCommandL (aCommand, m_pListBox);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -