?? txtlistboxcontainer.cpp
字號:
/*
* ============================================================================
* Name : CTxtListboxContainer from CCoeControl, MCoeControlObserver
* Part of : Hello
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <EveryDay.rsg>
#include "EveryDay.hrh"
#include "TxtListboxContainer.h"
#include "EveryDayDocument.h"
#include "aknlists.h"
#include "Message.h"
#include "File.h"
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
CTxtListboxContainer::CTxtListboxContainer()
{
m_pListBox = NULL;
m_pListBoxArray = NULL;
}
// EPOC default constructor can leave.
void CTxtListboxContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
//ListBox
m_pListBox = new(ELeave)CAknSingleNumberStyleListBox();
CleanupStack::PushL(m_pListBox);
m_pListBox->ConstructL(this,EAknListBoxMarkableList | EAknListBoxMultiselectionList);
m_pListBox->SetContainerWindowL(*this);
m_pListBox->SetRect(aRect);
m_pListBox->CreateScrollBarFrameL(ETrue);
m_pListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
//construct listbox item array
m_pListBoxArray = new(ELeave)CDesCArrayFlat(10);
CleanupStack::PushL(m_pListBoxArray);
CTextListBoxModel* model = m_pListBox->Model();
//set items and ownership
model->SetItemTextArray(m_pListBoxArray);
model->SetOwnershipType(ELbmDoesNotOwnItemArray);
CleanupStack::Pop(2); // !!! (2);
m_pListBox->ActivateL();
m_pListBox->SetFocus( ETrue );
//End Single ListBox
SetRect(aRect);
ActivateL();
}
// Destructor
CTxtListboxContainer::~CTxtListboxContainer()
{
MEM_FREE(m_pListBox);
MEM_FREE(m_pListBoxArray);
}
// ---------------------------------------------------------
// CTxtListboxContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CTxtListboxContainer::FocusTo(TInt aCommand)
{
}
// ---------------------------------------------------------
// CTxtListboxContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CTxtListboxContainer::SizeChanged()
{
if(m_pListBox)
{
m_pListBox->SetRect(Rect());
}
}
// ---------------------------------------------------------
// CTxtListboxContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CTxtListboxContainer::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CTxtListboxContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CTxtListboxContainer::ComponentControl(TInt aIndex) const
{
return m_pListBox;
}
// ---------------------------------------------------------
// CTxtListboxContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CTxtListboxContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CTxtListboxContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CTxtListboxContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent, TEventCode aType)
{
return m_pListBox->OfferKeyEventL(aKeyEvent, aType);
}
// ---------------------------------------------------------
// CTxtListboxContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CTxtListboxContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
//append items to the listbox
void CTxtListboxContainer::AddInfoToList(TInt aIndex, const TDesC& aText)
{
TBuf<64>sBuf;
sBuf.AppendNum(aIndex);
sBuf.Append(_L("\t"));
sBuf.Append(aText);
m_pListBoxArray->AppendL(sBuf);
//update listbox
m_pListBox->HandleItemAdditionL();
}
void CTxtListboxContainer::SubInfoToList(TInt aIndex, CArrayFixFlat<CMessage> & file)
{
if(aIndex>=0)
{
CTextListBoxModel* model = m_pListBox->Model();
if(model->NumberOfItems()>0)
{
CDesCArray* itemArray = STATIC_CAST( CDesCArray*, model->ItemTextArray() );
TInt currentItem = m_pListBox->CurrentItemIndex();
itemArray->Delete(currentItem);
// for(TInt i=currentItem; i<(file.Count()-1);i++)
// {
// file.At(i).iFileTitle.Copy(file.At(i+1).iFileTitle);
// file.At(i).iFileTitle.Copy(file.At(i+1).iFileContent);
// }
file.Delete(currentItem);
AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(m_pListBox,currentItem,ETrue);
}
}
//update listbox
m_pListBox->HandleItemAdditionL();
}
void CTxtListboxContainer::GetListNum(TInt & anum)
{
anum = m_pListBox->CurrentItemIndex();
}
// End of File
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -