×
Namespaces

Variants
Actions

使用CAknGlobalListQuery显示一个全局列表查询框

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

测试基于
设备:: Nokia N93

兼容于
平台: S60 3rd Edition, FP1

文章
关键词: CAknGlobalListQuery, CDesCArray, CCoeEnv, CAknGlobalListQuery::NewL(),
dougcn 在 09 Jul 2008 创建
最后由 hamishwillee 在 14 Jun 2012 编辑

Contents

概述

这个代码片段演示如何创建一个全局的列表查询框CAknGlobalListQuery。通过调用 NewL()来创建一个全局列表查询框,使用ShowListQueryL()方法来执行。此例使用通用类CGlobalQueryHandlerAO,这个类也用在其它全局查询代码片段中。类CGlobalQueryContainer用来调出查询框,也是观察者,实现了接口MGlobalQueryObserver

注意: CAknGlobalListQuery 只能含有很简单的条目。 跳格键(Tab)不能在条目中使用。

此片段能用自签名。

MMP文件

下面的库文件是必须的:

LIBRARY cone.lib            //CEikonEnv, CCoeEnv 
LIBRARY avkon.lib //Avkon resources
LIBRARY euser.lib //CActive, CleanupStack
LIBRARY bafl.lib //CDesCArray


资源文件

.rss

#include <eikon.rh>
#include <avkon.rsg>
#include <avkon.rh>
 
//...
RESOURCE ARRAY r_global_query_item_list_array
{
items=
{
LBUF {txt="<item 1>"; },
LBUF {txt="<item 2>"; },
LBUF {txt="<item 3>"; },
LBUF {txt="<item 4>"; }
};
}

头文件

  • 观察者接口
#ifndef GLOBALQUERYOBSERVER_H
#define GLOBALQUERYOBSERVER_H
 
class MGlobalQueryObserver
{
public:
//keep these methods short running because they are called
//from within an active object
virtual void ProcessOkOptionL() = 0;
virtual void ProcessCancelOptionL() = 0;
virtual void ProcessDoneOptionL() = 0;
virtual void ProcessSelectedItemL(const TInt aItem) = 0;
};
 
#endif // GLOBALQUERYOBSERVER_H
  • 处理器——活动对象
#ifndef GLOBALQUERYHANDLERAO_H
#define GLOBALQUERYHANDLERAO_H
 
#include <e32base.h> //CActive
#include "GlobalQueryObserver.h"
 
class CGlobalQueryHandlerAO : public CActive
{
public:
~CGlobalQueryHandlerAO();
static CGlobalQueryHandlerAO* NewL(MGlobalQueryObserver& aObserver);
static CGlobalQueryHandlerAO* NewLC(MGlobalQueryObserver& aObserver);
public:
void StartHandler();
private:
CGlobalQueryHandlerAO(MGlobalQueryObserver& aObserver)
: CActive (EPriorityStandard), iObserver(aObserver){};
void ConstructL();
private: // from CActive
void RunL();
void DoCancel();
private: // data
MGlobalQueryObserver& iObserver;
};
#endif //GLOBALQUERYHANDLERAO_H
  • 容器/观察者
#ifndef GLOBALQUERYCONTAINER_H
#define GLOBALQUERYCONTAINER_H
 
#include <badesca.h> // CDesCArray
#include <coecntrl.h> // CCoeControl
#include "GlobalQueryObserver.h"
#include <akngloballistquery.h> //CAknGlobalListQuery
class CGlobalQueryHandlerAO;
 
class CGlobalQueryContainer : public CCoeControl, MGlobalQueryObserver
{
public:
//...
void MakeExampleQueryL();
public: // from MGlobalQueryObserver
void ProcessOkOptionL(); //not used
void ProcessCancelOptionL(); //not used
void ProcessDoneOptionL(); //not used
void ProcessSelectedItemL(const TInt aItem);
//...
private:
CGlobalQueryHandlerAO* iQueryHandlerAO;
CAknGlobalListQuery* iGlobalListQuery;
};
#endif // GLOBALQUERYCONTAINER_H


源代码文件

  • 处理器——活动对象
#include "GlobalQueryHandlerAO.h"
#include <avkon.hrh> //EAknSoftkeyOk, EAknSoftkeyCancel, EAknSoftkeyDone
 
CGlobalQueryHandlerAO::~CGlobalQueryHandlerAO() { Cancel(); }
 
void CGlobalQueryHandlerAO::ConstructL()
{
CActiveScheduler::Add(this);
}
 
CGlobalQueryHandlerAO* CGlobalQueryHandlerAO::NewLC(MGlobalQueryObserver& aObserver)
{
CGlobalQueryHandlerAO* self = new (ELeave) CGlobalQueryHandlerAO(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
CGlobalQueryHandlerAO* CGlobalQueryHandlerAO::NewL(MGlobalQueryObserver& aObserver)
{
CGlobalQueryHandlerAO* self = CGlobalQueryHandlerAO::NewLC(aObserver);
CleanupStack::Pop(self);
return self;
}
 
void CGlobalQueryHandlerAO::DoCancel(){}
 
void CGlobalQueryHandlerAO::StartHandler() { SetActive(); }
 
void CGlobalQueryHandlerAO::RunL()
{
if (iStatus == EAknSoftkeyOk)
iObserver.ProcessOkOptionL();
else if(iStatus == EAknSoftkeyCancel)
iObserver.ProcessCancelOptionL();
else if(iStatus == EAknSoftkeyDone)
iObserver.ProcessDoneOptionL();
else
iObserver.ProcessSelectedItemL(iStatus.Int());
 
Cancel();
}
  • 容器/观察者
#include "GlobalQueryContainer.h" //CGlobalQueryContainer
#include "GlobalQueryHandlerAO.h" //CGlobalQueryHandlerAO
#include <GlobalQuery_0xED0C36BE.rsg> //Resources
 
void CGlobalQueryContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
ActivateL();
 
MakeExampleQueryL();
}
 
void CGlobalQueryContainer::MakeExampleQueryL()
{
//start the query handler and show global list query
iQueryHandlerAO = CGlobalQueryHandlerAO::NewL(*this);
iQueryHandlerAO->StartHandler();
iGlobalListQuery = CAknGlobalListQuery::NewL();
 
CDesCArray* itemArray = iCoeEnv->ReadDesCArrayResourceL(
R_GLOBAL_QUERY_ITEM_LIST_ARRAY );
CleanupStack::PushL(itemArray);
 
iGlobalListQuery->ShowListQueryL(itemArray, iQueryHandlerAO->iStatus);
 
CleanupStack::PopAndDestroy(itemArray);
}
 
CGlobalQueryContainer::~CGlobalQueryContainer()
{
//...
delete iQueryHandlerAO;
delete iGlobalListQuery;
}
 
void CGlobalQueryContainer::ProcessOkOptionL()
{
//not used
}
void CGlobalQueryContainer::ProcessCancelOptionL()
{
//not used
}
void CGlobalQueryContainer::ProcessDoneOptionL()
{
//not used
}
void CGlobalQueryContainer::ProcessSelectedItemL(const TInt aItem)
{
//Item selected, do something...
TBuf<10> item;
item.AppendNum(aItem);
iEikonEnv->InfoWinL(_L("Process Item:"),item);
}

后置条件

本例代码演示如何创建一个全局列表查询框、处理查询框的关闭、以及活动处理器如何通知观察者类对话框已关闭。

参见

This page was last modified on 14 June 2012, at 03:53.
43 page views in the last 30 days.
×