📄 mobilestorageview.cpp
字号:
/*
* Copyright (c) 2007,苏州丰达
* All rights reserved.
* 版权所有(C)2007-2008 苏州丰达
* 公司地址:中国,江苏省苏州市
* 网址:http://www.
*
* 文件名称:CM3UIQ2AppUi.cpp
* 摘 要:
*
* 产品版本:彩视 1.0
*
* 作 者:xxxx
* 创建日期:xxxxx
* 负责人:xxxxx
*
* 修改者:司治国
* 修改日期:2008.1.17
*
* 编译器或环境等描述:uiqsdk2.1
* 适用于VC2003+symbian 7.x的环境开发。
*
**/
#include <eiktxlbm.h>
#include <eikclbd.h>
#include <m3upload.mbg>
#include <M3UIQ2.rsg>
#include "MobileStorageView.h"
#include "M3UIQ2Appui.h"
#include "M3UIQ2App.h"
#include "M3UIQ2.hrh"
_LIT(KMultiBitmapFilename, "\\system\\apps\\m3uiq2\\m3upload.mbm");
CMobileStorageView::CMobileStorageView()
{
}
/**
* 析构
**/
CMobileStorageView::~CMobileStorageView()
{
if (iListBox)
{
delete iListBox;
iListBox = NULL;
}
if (iFs)
{
iFs->Close();
delete iFs;
iFs = NULL;
}
if (iDir)
{
delete iDir;
iDir = NULL;
}
}
/**
* 二步构造
* @param aRect 显示区域
**/
CMobileStorageView* CMobileStorageView::NewLC(const TRect &aRect)
{
CMobileStorageView* self = new (ELeave)CMobileStorageView();
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
/**
* 二步构造
* @param aRect 显示区域
**/
CMobileStorageView* CMobileStorageView::NewL(const TRect &aRect)
{
CMobileStorageView* self=CMobileStorageView::NewLC(aRect);
CleanupStack::Pop(); // self;
return self;
}
/**
* 二步构造
* @param aRect 显示区域
**/
void CMobileStorageView::ConstructL(const TRect &aRect)
{
//声明文件地址类
iDir = M3Directory::newL();
// 构建视图的窗体
CreateWindowL();
SetRect(aRect);
CreateListBoxL(iDir);
//iListBox->View()->CalcBottomItemIndex();
// iListBox->HandleItemAdditionL();
// iListBox->SetCurrentItemIndexAndDraw(0);
iListBox->SetFocus(ETrue);
// Views should be made invisible until ViewActivated has been called
MakeVisible(EFalse);
SetComponentsToInheritVisibility();
ActivateL();
}
/**
* 返回视图id
* @Return 视图id
**/
TVwsViewId CMobileStorageView::ViewId() const
{
return TVwsViewId(KUidM3UIQ2, ViewUid());
}
/**
* 返回视图uid
* @Return 视图uid
**/
TUid CMobileStorageView::ViewUid() const
{
return TUid::Uid(EMyStorageViewId);
}
/**
* 处理列表事件
* @param aListBox
* @param aEventType
**/
void CMobileStorageView::HandleListBoxEventL( CEikListBox *aListBox, TListBoxEvent aEventType )
{
if ((MEikListBoxObserver::EEventEnterKeyPressed == aEventType) ||
(MEikListBoxObserver::EEventItemClicked == aEventType))
{
HandleEnter();
}
}
/**
* 激活视图
* @param aTVwsViewId
* @param aCustomMessageId
* @param aCustomMessage
**/
void CMobileStorageView::ViewActivatedL( const TVwsViewId &aPrevViewId, TUid aCustomMessageId, const TDesC8 &aCustomMessage )
{
ActivateL();
MEikAppUiFactory *factory = iEikonEnv->AppUiFactory();
factory->MenuBar()->ChangeMenuBarL(0, R_M3UIQ2_MENUBAR2, ETrue);
// Switch to the detailed view's toolbar
CM3UIQ2AppUi *iAppUi = STATIC_CAST(CM3UIQ2AppUi *, iEikonEnv->EikAppUi());
iAppUi->SetToolbarL(R_BAPP_MTORAGE_TOOLBAR);
MakeVisible(ETrue);
}
/**
* 隐藏视图
**/
void CMobileStorageView::ViewDeactivated()
{
MakeVisible(EFalse);
}
/**
* 返回控件
* @param aIndex 索引
* @Return 返回控件
**/
CCoeControl * CMobileStorageView::ComponentControl( TInt aIndex ) const
{
switch (aIndex)
{
case 0:
return iListBox;
default:
return NULL;
}
}
/**
* 返回控件个数
* @param 控件个数
**/
TInt CMobileStorageView::CountComponentControls() const
{
return 1;
}
void CMobileStorageView::Draw( const TRect& /* aRect */ ) const
{
}
/**
* 创建列表框
**/
void CMobileStorageView::CreateListBoxL(M3Directory *aDir)
{
//声明控件
iListBox = new (ELeave) CEikColumnListBox();
iListBox->ConstructL(this, CEikColumnListBox::ENoExtendedSelection | CEikColumnListBox::ENoFirstLetterMatching);
iListBox->SetContainerWindowL(*this);
iListBox->SetListBoxObserver(this);
iListBox->SetRect(Rect());
iListBox->ItemDrawer()->ColumnData()->SetColumnWidthPixelL(0, 25);
iListBox->ItemDrawer()->ColumnData()->SetGraphicsColumnL(0, ETrue);
CDesCArray *aTxtArray = static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray());
//初始化内容
aDir->SetPath(_L("c:\\Documents\\Media files\\"));
aDir->GetList(aTxtArray);
//设置
// iListBox->HandleItemAdditionL();
// iListBox->SetCurrentItemIndexAndDraw(0);
iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
iListBox->SetItemHeightL(2 * 10);
iListBox->ActivateL();
//初始化图标
CArrayPtr<CGulIcon> *iconList = new (ELeave) CArrayPtrFlat<CGulIcon>(1);
CleanupStack::PushL(iconList);
iconList->AppendL(iEikonEnv->CreateIconL(KMultiBitmapFilename, EMbmM3upload7,EMbmM3upload7m));
iconList->AppendL(iEikonEnv->CreateIconL(KMultiBitmapFilename, EMbmM3upload8, EMbmM3upload8m));
iconList->AppendL(iEikonEnv->CreateIconL(KMultiBitmapFilename, EMbmM3upload9, EMbmM3upload9m));
CleanupStack::Pop();
iListBox->ItemDrawer()->ColumnData()->SetIconArray(iconList);
}
/**
* 输入事件
* @param aLine
**/
void CMobileStorageView::HandleEnter(TInt aLine)
{
TInt item = aLine;
if(aLine < 0)
{
item = iListBox->CurrentItemIndex();
}
TPtrC path = iDir->GetPath();
if(iDir->EnterItem(item))
{
// iView->SetTitle();
CDesCArray* txtArray=static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray());
iDir->ClearSelection();
iDir->GetList(txtArray);
TInt pos = iDir->FindPath(path);
RefreshList(pos,EFalse);
}
}
/**
* 刷新列表
* @param apos
* @param aGetList
**/
void CMobileStorageView::RefreshList(TInt aPos,TBool aGetList)
{
CDesCArray* txtArray=static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray());
if (aGetList)
{
iDir->GetList(txtArray);
}
iListBox->HandleItemAdditionL();
iListBox->SetCurrentItemIndexAndDraw(aPos);
}
TKeyResponse CMobileStorageView::OfferKeyEventL( const TKeyEvent &aKeyEvent, TEventCode aType )
{
return iListBox->OfferKeyEventL(aKeyEvent, aType);
}
void CMobileStorageView::SizeChanged()
{
if (iListBox)
{
iListBox->SetRect(Rect());
}
}
/**
* 得到列表框
**/
CEikColumnListBox * CMobileStorageView::ListBox()
{
return iListBox;
}
/**
* 得到被选中的文件
**/
TDesC* CMobileStorageView::FileName()
{
TInt item = iListBox->CurrentItemIndex();
TPtrC path=iDir->GetPath();
TPtrC fname=iDir->GetFile(item);
HBufC* fileName = HBufC::NewL(256);
TPtr temp = fileName->Des();
temp.Append(path);
temp.Append(fname);
return fileName;
}
/*
* 得到M3Directory
*/
M3Directory* CMobileStorageView::GetM3Directory()
{
return iDir;
}
/*
* 是否是目录
*/
TBool CMobileStorageView::IsDir()
{
TInt item = iListBox->CurrentItemIndex();
TBool res = iDir->IsDir(iDir->GetFile(item));
return res;
}
//end file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -