📄 dircontainer.cpp
字号:
/*
* ============================================================================
* Name : CDirContainer from CCoeControl, MCoeControlObserver
* Part of : Dir
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <aknlists.h> // for CEikColumnListBox
#include <Memento.rsg>
#include <eiklabel.h> //for CEikLabel
#include <eikedwin.h> //for CEikEdit
#include "Memento.hrh"
#include "DirContainer.h"
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
CDirContainer::CDirContainer()
{
ipListBox = NULL;
ipListBoxArray = NULL;
}
// EPOC default constructor can leave.
void CDirContainer::ConstructL(const TRect& aRect, CArrayPtrSeg<CDirInfo>* aUserFileDir)
{
CreateWindowL();
iUserFileDir = aUserFileDir;
//listbox
ipListBox = new( ELeave ) CAknSingleNumberStyleListBox();
CleanupStack::PushL(ipListBox);
ipListBox->ConstructL(this, EAknListBoxMarkableList | EAknListBoxMultiselectionList);
ipListBox->SetContainerWindowL(*this);
ipListBox->SetRect(aRect);
ipListBox->CreateScrollBarFrameL( ETrue );
ipListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
// construct listbox item array
ipListBoxArray = new (ELeave) CDesCArrayFlat(10);
CleanupStack::PushL(ipListBoxArray);
CTextListBoxModel* model = ipListBox->Model();
// set items and ownership
model->SetItemTextArray( ipListBoxArray );
model->SetOwnershipType(ELbmDoesNotOwnItemArray);
CleanupStack::Pop(2); // !!! (2);
ipListBox->ActivateL();
// ipListBox->MakeVisible( EFalse );
ipListBox->SetFocus( ETrue );
// m_pListBox->DrawNow();
//End ListBox
//load chinese words//显示中文
TBuf<32> chinese;
CEikonEnv::Static()->ReadResource(chinese, R_QTN_MH_LISTBOX_HELP);
//LabelHelp
ipLabelHelp = new(ELeave) CEikLabel;
ipLabelHelp->SetContainerWindowL(*this);
ipLabelHelp->SetTextL(chinese);
ipLabelHelp->SetExtent(TPoint(0,0), ipLabelHelp->MinimumSize());
ipLabelHelp->SetExtent(TPoint(0,0), TSize(176,20));
ipLabelHelp->MakeVisible(EFalse);
//EditName
TBuf<128> chinese1;
CEikonEnv::Static()->ReadResource(chinese1, R_QTN_MH_LISTBOX_HELP_TXT);
ipEditHelp = new(ELeave) CEikEdwin;
ipEditHelp->SetContainerWindowL(*this);
ipEditHelp->ConstructL(EAknEditorFlagDefault, 10, 10, 1);
ipEditHelp->SetExtent(TPoint(0,20), TSize(176,124));
ipEditHelp->SetTextL(&chinese1);
ipEditHelp->SetReadOnly(ETrue);
ipEditHelp->SetBackgroundColorL(KRgbDarkBlue);
ipEditHelp->MakeVisible(EFalse);
TInt number = iUserFileDir->Count();
for (TInt i=0; i!=number; ++i)
{
AddInfoToList(i+1, iUserFileDir->At(i)->GetFileTitle());
}
SetRect(aRect);
ActivateL();
}
// Destructor
CDirContainer::~CDirContainer()
{
MEM_FREE(ipListBox);
MEM_FREE(ipListBoxArray);
MEM_FREE(ipEditHelp);
MEM_FREE(ipLabelHelp);
}
// ---------------------------------------------------------
// CDirContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CDirContainer::FocusTo(TInt aCommand)
{
}
// ---------------------------------------------------------
// CDirContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CDirContainer::SizeChanged()
{
if (ipListBox)
{
ipListBox->SetRect(Rect());
}
}
// ---------------------------------------------------------
// CDirContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CDirContainer::CountComponentControls() const
{
return 3; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CDirContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CDirContainer::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0:
{
return ipEditHelp;
break;
}
case 1:
{
return ipLabelHelp;
break;
}
case 2:
{
return ipListBox;
break;
}
default:
{
return NULL;
break;
}
};
}
// ---------------------------------------------------------
// CDirContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CDirContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbDarkMagenta);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CDirContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CDirContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent, TEventCode aType)
{
if (aType == EEventKey && aKeyEvent.iCode == EKeyDevice3)
{
return EKeyWasNotConsumed;
}
if (ipListBox)
{
if (ipListBox->IsFocused())
{
return ipListBox->OfferKeyEventL(aKeyEvent, aType);
}
}
return EKeyWasNotConsumed;
}
// ---------------------------------------------------------
// CDirContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CDirContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
void CDirContainer::AddInfoToList(TInt aIndex, const TDesC& aText)
{
TBuf<64> sBuf;
sBuf.AppendNum(aIndex);
sBuf.Append(_L("\t"));
sBuf.Append(aText);
ipListBoxArray->AppendL(sBuf);
// update listbox
ipListBox->HandleItemAdditionL();
}
void CDirContainer::setHelp(TBool aFlag)
{
ipEditHelp->MakeVisible(aFlag);
ipLabelHelp->MakeVisible(aFlag);
ipListBox->MakeVisible(!aFlag);
}
TInt CDirContainer::GetIndex()
{
return ipListBox->CurrentItemIndex();
}
void CDirContainer::ReLoadListBox()
{
TInt index = ipListBox->CurrentItemIndex();
ipListBoxArray->Delete(index);
ipListBox->HandleItemRemovalL();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -