📄 multiview3.cpp
字号:
//
// MultiView3.cpp - Multi-views example
//
// Copyright (C) UIQ Technology AB, 2007
//
// This material is provided "as is" without any warranty to its performance or functionality.
// In no event shall UIQ Technology be liable for any damages whatsoever arising out of the
// use or inabilty to use this material.
//
#include "MultiView3.h"
#include "MultiView3.hrh"
#include <MultiView3.rsg>
#include <QikViewBase.h>
#include <QikCommand.h>
#include <QikListBoxModel.h>
#include <QikListBox.h>
#include <MQikListBoxData.h>
#include <QikZoomDlg.h>
#include <eikstart.h>
//////////////////////////////////////////////////////////////////////////////
// The application Uid here MUST match UID3 defined in the MMP file
// This is a development UID and must NOT be used in production type software
const TUid KAppSpecificUid={0xEDEAD00A};
// internal secondary view id, must be unique amongst this applications views
const TUid KUidListView={0x00000001};
const TUid KUidDetailsView={0x00000002};
// views within applications are fully identified by the app Uid and secondary view id
#define KViewIdListView TVwsViewId(KAppSpecificUid,KUidListView)
#define KViewIdDetailsView TVwsViewId(KAppSpecificUid,KUidDetailsView)
//////////////////////////////////////////////////////////////////////////////////
const TInt KMaxListItemText=32; // we support a max of 32 chars for each text item to be displayed
class CAppEngine : public CBase
{
protected:
public:
CAppEngine(const TInt aZoomLevel);
TInt ListViewZoomState() const;
TBool SetListViewZoomState(const TInt aZoomLevel);
protected:
// The 'engine' stores 'UI' information since UI components come and go, yet we want to preserve
// UI configuration information between invocations of the view.
TInt iZoomLevel;
};
CAppEngine::CAppEngine(const TInt aZoomLevel) :
iZoomLevel(aZoomLevel)
{}
TInt CAppEngine::ListViewZoomState() const
// Report the currently stored zoom state
{
return(iZoomLevel);
}
TBool CAppEngine::SetListViewZoomState(const TInt aZoomLevel)
//
// Update list view zoom state.
// Return TRUE if zoom state set is different to current level
//
{
if (aZoomLevel==iZoomLevel)
return(EFalse);
iZoomLevel=aZoomLevel;
return(ETrue);
}
//////////////////////////////////////////////////////////////////////////////////
// Class we package some information within to tell the details view which item it is
// required to display
// The command id we pass to the view, MUST NOT be NULL
const TUid KUidDisplaySpecificEntry = {0x00000001};
class TListDetailsDnlInfo
{
public:
TInt iItemIndex;
};
// syntactic glue to cause the object to be a passed as an 8 bit descriptor whilst remaining type-safe
typedef TPckgBuf<TListDetailsDnlInfo> TListDetailsDnlInfoBuf;
//////////////////////////////////////////////////////////////////////////////////
class CAppSpecificListView : public CQikViewBase, public MQikListBoxObserver
{
protected:
// from CQikViewBase
TVwsViewId ViewId() const;
void HandleCommandL(CQikCommand& aCommand);
void ViewConstructL();
void ViewDeactivated();
void ViewActivatedL(const TVwsViewId& aPrevViewId,const TUid aCustomMessageId,const TDesC8& aCustomMessage);
// from MQikListBoxObserver
void HandleListBoxEventL(CQikListBox* aListBox,TQikListBoxEvent aEventType,TInt aItemIndex,TInt aSlotId);
// new methods
void AddItemsL();
public:
// new methods
CAppSpecificListView(CAppSpecificUi& aAppUi,CAppEngine* aEngine);
protected:
CAppEngine* iEngine;
};
CAppSpecificListView::CAppSpecificListView(CAppSpecificUi& aAppUi,CAppEngine* aEngine) :
CQikViewBase(aAppUi,KNullViewId),iEngine(aEngine)
{
}
TVwsViewId CAppSpecificListView::ViewId() const
//
// All views are uniquely identified within the entire system. A TVwsViewId consists of
// the application uid (uid3) and app specific view uid
//
{
return(KViewIdListView);
}
void CAppSpecificListView::HandleCommandL(CQikCommand& aCommand)
//
// Handle the commands coming in from the controls that can deliver cmds..
//
{
switch (aCommand.Id())
{
case EAppCmdZoom: // Launch the system std zoom dialog
CQikZoomDialog::RunDlgLD(iEngine->ListViewZoomState(),*this);
break;
case EQikCmdZoomLevel1: // delivered by the std system zoom dlg...
case EQikCmdZoomLevel2:
case EQikCmdZoomLevel3:
if (iEngine->SetListViewZoomState(aCommand.Id()))
{ // zoom state has changed
CQikViewBase::SetZoomFactorL(CQikAppUi::ZoomFactorL(aCommand.Id(),*iEikonEnv));
PerformLayout();
}
break;
default: // e.g. the back button...
CQikViewBase::HandleCommandL(aCommand);
break;
}
}
void CAppSpecificListView::HandleListBoxEventL(
//
// List box event occured - its reporting back what that might be.
//
CQikListBox* aListBox,
TQikListBoxEvent aEventType,
TInt aItemIndex,
TInt aSlotId)
{
switch (aEventType)
{
case EEventItemConfirmed:
case EEventItemTapped:
{
TListDetailsDnlInfo entry;
// we can conveniently use the passed aItemIndex otherwise we need to
// entry.iItemIndex=aListBox->CurrentItemIndex();
entry.iItemIndex=aItemIndex;
// syntactic glue to convert the class into a TDesC8
TListDetailsDnlInfoBuf bb(entry);
// then activate the details view on the indicated entry.
iQikAppUi.ActivateViewL(KViewIdDetailsView,KUidDisplaySpecificEntry,bb);
break;
}
default:
break;
}
}
const TInt KMultiView3Items=7;
void CAppSpecificListView::AddItemsL()
//
// We are a single line list box. Add each of the items to the listbox for display
//
{
CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId);
MQikListBoxModel& model(listbox->Model());
model.ModelBeginUpdateLC();
TBuf<KMaxListItemText>bb;
for (TInt i=0;i<KMultiView3Items;i++)
{
MQikListBoxData* lbData=model.NewDataL(MQikListBoxModel::EDataNormal);
CleanupClosePushL(*lbData); // alternativly use NewDataLC() to save this line of code
iEikonEnv->ReadResourceL(bb,R_STR_LIST_CONTENT_1+i);
lbData->AddTextL(bb,EQikListBoxSlotText1);
CleanupStack::PopAndDestroy(lbData);
}
model.ModelEndUpdateL();
}
void CAppSpecificListView::ViewConstructL()
{
// Loads information about the UI configurations this view supports
// together with definition of each view.
ViewConstructFromResourceL(R_LIST_VIEW_CONFIGURATIONS);
// determine zoom level last used
CQikViewBase::SetZoomFactorL(CQikAppUi::ZoomFactorL(iEngine->ListViewZoomState(),*iEikonEnv));
// we want to HandleListBoxEventL() - so observe the listbox
LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId)->SetListBoxObserver(this);
// Put some entries into the list box
AddItemsL();
// set the line below app name to be "List title"
TBuf<64>bb;
iEikonEnv->ReadResourceL(bb,R_STR_LIST_TITLE);
ViewContext()->AddTextL(1,bb);
}
void CAppSpecificListView::ViewDeactivated()
//
// In this example we have chosen not to remove the listbox data (potentially saving resource
// usage) to show its not necessary if your requirements are along such lines.
//
{
}
void CAppSpecificListView::ViewActivatedL(
//
// The view is being activated. The listboxes are always seeded with data and kept upto date.
// In this example we dont remove items when our view is Deactivated() to show that its
// entirely feasible to run with that type of model.
//
const TVwsViewId& aPrevViewId,
const TUid aCustomMessageId,
const TDesC8& aCustomMessage)
{
}
//////////////////////////////////////////////////////////////////////////////////
class CAppSpecificDetailsView : public CQikViewBase
{
protected:
// from CQikViewBase
TVwsViewId ViewId() const;
void HandleCommandL(CQikCommand& aCommand);
void ViewConstructL();
void ViewDeactivated();
void ViewActivatedL(const TVwsViewId& aPrevViewId,const TUid aCustomMessageId,const TDesC8& aCustomMessage);
public:
// new methods
CAppSpecificDetailsView(CAppSpecificUi& aAppUi,CAppEngine* aEngine);
protected:
CAppEngine* iEngine;
TListDetailsDnlInfoBuf iSavedParams;
};
CAppSpecificDetailsView::CAppSpecificDetailsView(CAppSpecificUi& aAppUi,CAppEngine* aEngine) :
CQikViewBase(aAppUi,KViewIdListView),iEngine(aEngine)
{
}
TVwsViewId CAppSpecificDetailsView::ViewId() const
{
return(KViewIdDetailsView);
}
void CAppSpecificDetailsView::HandleCommandL(CQikCommand& aCommand)
//
// Handle the commands coming in from the controls that can deliver cmds..
//
{
switch (aCommand.Id())
{
case EAppCmdHelp:
case EAppCmdAbout:
break;
default: // e.g. the back button...
CQikViewBase::HandleCommandL(aCommand);
break;
}
}
void CAppSpecificDetailsView::ViewConstructL()
{
ViewConstructFromResourceL(R_DETAILS_VIEW_CONFIGURATIONS);
TBuf<64>bb;
iEikonEnv->ReadResourceL(bb,R_STR_DETAILS_TITLE);
ViewContext()->AddTextL(2,bb);
}
void CAppSpecificDetailsView::ViewDeactivated()
{
}
void CAppSpecificDetailsView::ViewActivatedL(
const TVwsViewId& aPrevViewId,
const TUid aCustomMessageId,
const TDesC8& aCustomMessage)
{
TListDetailsDnlInfoBuf bb;
if (aCustomMessageId==KUidDisplaySpecificEntry)
{
bb.Copy(aCustomMessage);
iSavedParams.Copy(aCustomMessage);
}
else
{
bb.Copy(iSavedParams);
}
TBuf<128>buf;
iEikonEnv->Format128(buf,R_STR_ACTIVATING, bb().iItemIndex);
iEikonEnv->InfoMsg(buf);
}
//////////////////////////////////////////////////////////////////////////////
CAppSpecificUi::~CAppSpecificUi()
{
delete(iEngine);
}
void CAppSpecificUi::ConstructL()
//
// Normal primary entry point to a Symbian App
//
{
CQikAppUi::ConstructL();
iEngine=new(ELeave)CAppEngine(EQikCmdZoomLevel2);
// We create and add a details view.
CAppSpecificDetailsView* details=new(ELeave)CAppSpecificDetailsView(*this,iEngine);
CleanupStack::PushL(details);
details->ConstructL();
AddViewL(*details); // takes ownership
CleanupStack::Pop(details);
// We create and add a list view.
CAppSpecificListView* list=new(ELeave)CAppSpecificListView(*this,iEngine);
CleanupStack::PushL(list);
list->ConstructL();
AddViewL(*list); // takes ownership
CleanupStack::Pop(list);
SetDefaultViewL(*list);
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificDocument : public CQikDocument
{
protected:
CQikAppUi* CreateAppUiL();
public:
CAppSpecificDocument(CQikApplication& aApp);
static CAppSpecificDocument* NewL(CQikApplication& aApp);
protected:
};
CAppSpecificDocument::CAppSpecificDocument(CQikApplication& aApp) :
CQikDocument(aApp)
{
__DECLARE_NAME(_S("CAppSpecificDocument"));
}
CAppSpecificDocument* CAppSpecificDocument::NewL(CQikApplication& aApp)
{
return(new(ELeave)CAppSpecificDocument(aApp));
}
CQikAppUi* CAppSpecificDocument::CreateAppUiL()
{
return(new(ELeave)CAppSpecificUi);
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificApplication : public CQikApplication
{
protected:
TUid AppDllUid() const;
CApaDocument* CreateDocumentL();
};
TUid CAppSpecificApplication::AppDllUid() const
{
return(KAppSpecificUid);
}
CApaDocument* CAppSpecificApplication::CreateDocumentL()
{
return(CAppSpecificDocument::NewL(*this));
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application start up code
LOCAL_C CApaApplication* NewApplication()
{
return(new CAppSpecificApplication);
}
GLDEF_C TInt E32Main()
{
return(EikStart::RunApplication(NewApplication));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -