📄 pblistview.cpp.bak
字号:
/*
* ============================================================================
* Name : CPBListView from CAknView
* Part of : PBListView
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <aknviewappui.h>
#include <avkon.hrh>
#include <FunZone.rsg>
#include <FunZone.mbg>
#include <akncontext.h>
#include <akntitle.h>
#include "FunZone.hrh"
#include "PBListView.h"
#include "PBListContainer.h"
#include "FunZoneAppUi.h"
#include "MEM_FREE.H"
#include <aknlists.h>
#include "PBItemView.h"
#include "MSendMsg.h"
// ================= MEMBER FUNCTIONS =======================
CPBListView* CPBListView::NewL(MSendMsg* aSendMsg)
{
CPBListView* self = NewLC(aSendMsg);
CleanupStack::Pop(self);
return self;
}
CPBListView* CPBListView::NewLC(MSendMsg* aSendMsg)
{
CPBListView* self = new (ELeave) CPBListView(aSendMsg);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CPBListView::CPBListView(MSendMsg* aSendMsg)
{
i_nMenuFlag=0;
iContainer =NULL;
i_pPBArray =NULL;
i_pPBEngine=NULL;
i_pPBInfo =NULL;
i_pSendMsg =aSendMsg;
}
// EPOC default constructor can leave.
void CPBListView::ConstructL()
{
BaseConstructL(R_PBLIST_VIEW);
}
// Destructor
CPBListView::~CPBListView()
{
i_pPBArray->ResetAndDestroy();
MEM_FREE(i_pPBArray)
MEM_FREE(i_pPBInfo)
}
// ---------------------------------------------------------
// TUid CPBListView::Id()
// Returns Id of the view.
// ---------------------------------------------------------
TUid CPBListView::Id() const
{
return KPBListViewID;
}
// ---------------------------------------------------------
// CPBListView::HandleCommandL(TInt aCommand)
// Handles commands
// ---------------------------------------------------------
void CPBListView::HandleCommandL(TInt aCommand)
{
TInt nLstIndex = iContainer->GetSelectedIndexL();
switch(aCommand)
{
case EFZone03CMDCreate:
{
i_pPBInfo=CPBInfo::NewL();
i_pSendMsg->SendMsg(i_pPBInfo,EPBCreate);
AppUi()->ActivateLocalViewL(KPBItemViewID);
}
break;
case EFZoneCMDDelete:
{
if (nLstIndex >= 0)
{
DeleteContact();
}
}
break;
case EFZoneCMDOpen:
{
i_pSendMsg->SendMsg((*i_pPBArray)[nLstIndex],EPBOpen);
AppUi()->ActivateLocalViewL(KPBItemViewID);
}
break;
case EFZoneCMDEdit:
{
i_pSendMsg->SendMsg((*i_pPBArray)[nLstIndex],EPBEdit);
AppUi()->ActivateLocalViewL(KPBItemViewID);
}
break;
case EFZoneCMDMark:
{
}
break;
case EFZoneCMDMarkOne:
{
iContainer->HandleMarkCommandL (aCommand);
}
break;
case EFZoneCMDMarkAll:
{
iContainer->HandleMarkCommandL (aCommand);
}
break;
case EFZoneCMDMarkCancelOne:
{
iContainer->HandleMarkCommandL (aCommand);
}
break;
case EFZoneCMDMarkCancelAll:
{
iContainer->HandleMarkCommandL (aCommand);
}
break;
default:
{
AppUi()->HandleCommandL(aCommand);
break;
}
}
}
// ---------------------------------------------------------
// CPBListView::HandleClientRectChange()
// Handles client rect change.
// ---------------------------------------------------------
void CPBListView::HandleClientRectChange()
{
if (iContainer)
{
iContainer->SetRect(ClientRect());
}
}
// ---------------------------------------------------------
// CPBListView::DoActivateL(...)
// Creates the Container class object.
// ---------------------------------------------------------
void CPBListView::DoActivateL(const TVwsViewId& ,TUid,const TDesC8& )
{
EditViewInfomation();//设置视图标题、图片啥的
if(i_pPBArray==NULL)//保证只申请一次
{
i_pPBArray=new (ELeave)RPointerArray<CPBInfo>(5);//申请动态数组,用于存储数据
}
i_pPBEngine = CPBEngine::NewL();//实例化名片夹引擎
CreateNewContact();//新建名片
GetContactFromPB();
RefreshListBox(0);
iContainer->SendArray(i_pPBArray);
iContainer->SetItemToListBox(i_pPBArray);
AppUi()->AddToStackL(*this, iContainer);
}
// ---------------------------------------------------------
// CPBListView::DoDeactivate()
// Deletes the Container class object.
// ---------------------------------------------------------
void CPBListView::DoDeactivate()
{
if (iContainer)
{
AppUi()->RemoveFromStack(iContainer);
MEM_FREE(iContainer)
}
MEM_FREE(i_pPBEngine);
}
/***************************************************/
void CPBListView::GetContactFromPB()
{
i_pPBArray->ResetAndDestroy(); //删除后重置
i_pPBEngine->UpdatePhoneBook(0,i_pPBArray);
}
void CPBListView::CreateNewContact()
{
//向动态数组添加新的名片
if(i_pPBInfo&&i_pPBInfo->GetItemID()==-1)
{
i_pPBArray->Append(i_pPBInfo);
}
i_pPBEngine->UpdatePhoneBook(1, i_pPBArray); //更新名片夹
}
void CPBListView::DeleteContact()
{
if (i_pPBArray->Count() <= 0)
{
return;
}
TInt nResult;
iContainer->GetDeleteResult(nResult);
if (nResult)
{
TInt nIndex = iContainer->i_pListBox->CurrentItemIndex();
if (nIndex >= 0)
{
//从数据库中删除一个名片
i_pPBEngine->DeleteUserFromBook((*i_pPBArray)[nIndex]->GetItemID());
//更新动态数组中的名片
GetContactFromPB();
//刷新显示内容
RefreshListBox(nIndex);
}
}
}
void CPBListView::RefreshListBox(TInt aIndex)
{
if (i_pPBArray->Count() != 0)
{
iContainer->SetItemToListBox(i_pPBArray);
if (aIndex != 0)
{
iContainer->i_pListBox->SetCurrentItemIndexAndDraw(aIndex-1);
}
else
{
iContainer->i_pListBox->SetCurrentItemIndexAndDraw(0);
iContainer->ShowNoCard();
}
}
else
{
iContainer->SetItemToListBox(i_pPBArray);
}
iContainer->i_pListBox->DrawNow();
}
void CPBListView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
{
if(R_MH_PBLIST_MENU!=aResourceId)
{
return;
}
if(i_pPBArray->Count()>0)
i_nMenuFlag=1;
else
i_nMenuFlag=0;
if(0==i_nMenuFlag)
{
aMenuPane->SetItemDimmed(EFZoneCMDDelete,ETrue);
aMenuPane->SetItemDimmed(EFZoneCMDEdit,ETrue);
aMenuPane->SetItemDimmed(EFZoneCMDOpen,ETrue);
aMenuPane->SetItemDimmed(EFZoneCMDCall,ETrue);
aMenuPane->SetItemDimmed(EFZoneCMDSMS,ETrue);
aMenuPane->SetItemDimmed(EFZoneCMDMark,ETrue);
}
}
void CPBListView::EditViewInfomation()
{
TBuf<50> pathMbm;
#ifdef __WINS__
pathMbm.Copy(_L("z:\\system\\apps\\FunZone\\FunZone.mbm"));
#else
CFunZoneAppUi* pApp = (CFunZoneAppUi*)CEikonEnv::Static()->AppUi();
pApp->GetAppPath(pathMbm);
pathMbm.Append(_L("FunZone.mbm"));
#endif
TUid contextPaneUid;
contextPaneUid.iUid = EEikStatusPaneUidContext;
//get the pointer of statuspane
CEikStatusPane* statusPane = StatusPane();
CAknContextPane* contextPane = (CAknContextPane*) statusPane->ControlL(contextPaneUid);
CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(pathMbm, EMbmFunzoneFunzone_icon_03);
contextPane->SetPicture(bitmap);
//modify Chinese title
TBuf<32> sTmpTitle;//define a descriptor for read resource of title
CEikonEnv::Static()->ReadResource(sTmpTitle, R_QTN_MH_PBLIST_TITLE);
//get the pointer of titlepane
CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
//set title text
titlePane->SetTextL(sTmpTitle);
iContainer = new (ELeave) CPBListContainer(titlePane);
iContainer->SetMopParent(this);
//StatusPane()->MakeVisible(EFalse);//隐藏状态栏
TRect rc;
rc.SetRect(ClientRect().iTl, TSize(176, 144));
iContainer->ConstructL(rc);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -