📄 filelistcontainer.cpp
字号:
/*
* Copyright (c) 2009 Nokia Corporation.
*/
// INCLUDE FILES
#include "FileListContainer.h"
#include "FileListEngine.h"
#include "Filelist.hrh"
#include <FileList.rsg>
#include <EIKAPP.H>
#include <eikbtgpc.h>
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CFileListContainer::ConstructL(const TRect& aRect)
// Symbian two phased constructor
// ---------------------------------------------------------
//
void CFileListContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iListBox = new (ELeave) CAknDoubleNumberStyleListBox;
iListBox->SetContainerWindowL( *this );
iListBox->ConstructL( this, EAknListBoxMarkableList);
// Create the scroll indicator
iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()
->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
iListBox->ActivateL();
// Create the FileListEngine
iAppEngine = new (ELeave) CFileListEngine;
iAppEngine->ConstructL();
SetFileListL(EFileListPictures, EFileListDate);
SetRect(aRect);
ActivateL();
}
// Destructor
CFileListContainer::~CFileListContainer()
{
delete iAppEngine;
delete iListBox;
}
// ---------------------------------------------------------
// CFileListContainer::SetFileList(TInt aDirectory, TInt aSizeDate)
// This will set up filelist.
// Directory and Size can be changed. See Filelist.hrh for possible values
// This function is located in the container and not in the engine, because it
// activates the listbox.
// ---------------------------------------------------------
//
void CFileListContainer::SetFileListL(TInt aDirectory, TInt aSizeDate)
{
// Set the listbox to use the file list model
CDesCArray* items = static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray());
// If there are items, they will be removed here
if (iAppEngine->RemoveItems(items))
{
// This makes changes to the actual listbox
iListBox->HandleItemRemovalL();
}
// Let's show directory
iAppEngine->SetDirectory(aDirectory);
// Let's decide whether to show file size or modification date
iAppEngine->SetSizeDate(aSizeDate);
// Do preparations for the FileList
if(iAppEngine->StartFileList() == KErrNone)
{
// Create FileList Items in the ListBox
iAppEngine->GetFileListItemsL(items);
}
// Close FileList session
iAppEngine->EndFileList();
// Refresh the listbox due to model change
iListBox->HandleItemAdditionL();
iListBox->SetCurrentItemIndex(0);
// Set correct middle softkey
CEikButtonGroupContainer * cbaGroup = iEikonEnv->AppUiFactory()->Cba();
if( iAppEngine->IsDirListEmpty() )
{
// Don't use middle softkey at all
cbaGroup->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_EXIT );
}
else if( aDirectory==EFileListPictures )
{
cbaGroup->SetCommandSetL( R_FILELIST_SOFTKEYS_OPTIONS_EXIT__OPEN );
}
else if( aDirectory==EFileListSounds ||
aDirectory==EFileListVideos )
{
cbaGroup->SetCommandSetL( R_FILELIST_SOFTKEYS_OPTIONS_EXIT__PLAY );
}
iListBox->DrawNow();
}
// ---------------------------------------------------------
// CFileListContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CFileListContainer::SizeChanged()
{
// control resizing
TRect rect = Rect();
iListBox->SetExtent(TPoint(0,0),rect.Size());
}
// ---------------------------------------------------------
// CFileListContainer::OffeKeyEventL()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
TKeyResponse CFileListContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent,TEventCode aType)
{
TKeyResponse ret;
// See if we have a selection
TInt code = aKeyEvent.iCode;
switch(code)
{
// is navigator button pressed
case EKeyOK:
iAppEngine->LaunchCurrentL(iListBox->CurrentItemIndex());
ret = EKeyWasConsumed;
break;
default:
// Let Listbox take care of its key handling
ret = iListBox->OfferKeyEventL(aKeyEvent, aType);
break;
}
return ret;
}
// ---------------------------------------------------------
// CFileListContainer::LaunchCurrentL()
// ---------------------------------------------------------
//
void CFileListContainer::LaunchCurrentL()
{
iAppEngine->LaunchCurrentL(iListBox->CurrentItemIndex());
}
// ---------------------------------------------------------
// CFileListContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CFileListContainer::CountComponentControls() const
{
// return number of controls inside this container
return 1;
}
// ---------------------------------------------------------
// CFileListContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CFileListContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iListBox;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CFileListContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CFileListContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
// drawing code
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbGray);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CFileListContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CFileListContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -