📄 quickstart.cpp
字号:
//
// QuickStart.cpp - Quick Start example
//
// This material is provided "as is" without any warranty to its performance or functionality.
// In no event shall the authors or publishers be liable for any damages whatsoever arising out of the
// use or inabilty to use this material.
//
#include "QuickStart.h"
#include "QuickStart.hrh"
#include <QuickStart.rsg>
#include <QikViewBase.h>
#include <QikCommand.h>
#include <QikCommandManager.h>
#include <QikListBoxModel.h>
#include <QikListBox.h>
#include <MQikListBoxData.h>
#include <QikListBoxData.h>
#include <QikContent.h>
#include <QikSimpleDialog.h>
#include <eikstart.h>
#include <eiklabel.h>
#include <eikdialg.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={0xE00000AD};
// internal secondary view id, must be unique amongst this applications views
const TUid KUidListView={0x00000001};
// views within applications are fully identified by the app Uid and secondary view id
#define KViewIdListView TVwsViewId(KAppSpecificUid,KUidListView)
//////////////////////////////////////////////////////////////////////////////////
const TInt KMaxListItemText=32; // we support a max of 32 chars for each text item to be displayed
////////////////////////////////////////////////////////////////////////////////////////////
// Despite not actually defining a command of type EQikCommandTypeCancel the
// system code automatically adds one. Its not meaningful for this simple dialog, which is
// why one was not defined in the command list, however we have to add some code to explictly
// remove the command.
class CAboutDialog : public CQikSimpleDialog
{
protected:
void PreLayoutDynInitL();
CQikCommand* DynInitOrDeleteCommandL(CQikCommand* aCommand,const CCoeControl& aControlAddingCommands);
};
// These would normally be derived from your in-house version control, this example just
// defines them here to remove such complexity from the example.
const TInt KAppMajorVersion=1;
const TInt KAppMinorVersion=0;
const TInt KAppBuild=2;
void CAboutDialog::PreLayoutDynInitL(void)
//
// Generate the version text - e.g. Version 1.00 (02) and set the label whose id is the value
// EAppLabel1 to contain that text.
//
{
TBuf<128>bb;
iEikonEnv->Format128(bb,R_STR_VERSION,KAppMajorVersion,KAppMinorVersion,KAppBuild);
CEikLabel* lbl=LocateControlByUniqueHandle<CEikLabel>(EAppLabel1);
lbl->SetTextL(bb);
}
CQikCommand* CAboutDialog::DynInitOrDeleteCommandL(
//
// As each command is added to the dialog we get the opportunity to perform an action
//
CQikCommand* aCommand,
const CCoeControl& aControlAddingCommands )
{
// Here if we see the system adding the EQikCommandTypeCancel command we tell it to
// remove it !
if (aCommand->Type()==EQikCommandTypeCancel)
{
delete(aCommand);
return(NULL);
}
return(aCommand);
}
//////////////////////////////////////////////////////////////////////////////////
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 AddItemsToListL(void);
public:
// new methods
CAppSpecificListView(CAppSpecificUi& aAppUi);
protected:
};
CAppSpecificListView::CAppSpecificListView(CAppSpecificUi& aAppUi) :
CQikViewBase(aAppUi,KNullViewId)
{}
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 EAppCmdAbout:
(new(ELeave)CAboutDialog)->ExecuteLD(R_ABOUT_DIALOG);
break;
case EAppCmdDebugTest:
// Clearly in a real application these should perform some real actions..
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:
{
MQikListBoxData* lbData=aListBox->Model().RetrieveDataL(aItemIndex);
CleanupClosePushL(*lbData); // its retrieved in an 'Open' state
iEikonEnv->InfoMsg(lbData->Text(EQikListBoxSlotText1));
CleanupStack::PopAndDestroy(lbData); // closes the item
break;
}
default:
break;
}
}
const TInt KQuickStartItems=7;
void CAppSpecificListView::AddItemsToListL(void)
//
// We are a single line list box. Add each of the items to the listbox for display
//
{
CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EAppQuickStartList);
MQikListBoxModel& model(listbox->Model());
model.ModelBeginUpdateLC();
TBuf<KMaxListItemText> bb;
for (TInt i=0;i<KQuickStartItems;i++)
{
MQikListBoxData* lbData=model.NewDataLC(MQikListBoxModel::EDataNormal);
iCoeEnv->ReadResourceL(bb,R_STR_LIST_CONTENT_1+i);
lbData->AddTextL(bb,EQikListBoxSlotText1);
CleanupStack::PopAndDestroy(lbData);
}
model.ModelEndUpdateL();
}
void CAppSpecificListView::ViewConstructL()
{
ViewConstructFromResourceL(R_LIST_VIEW_CONFIGURATIONS);
// we want to HandleListBoxEventL() - so observe the listboxes
LocateControlByUniqueHandle<CQikListBox>(EAppQuickStartList)->SetListBoxObserver(this);
AddItemsToListL();
}
void CAppSpecificListView::ViewDeactivated()
//
// The view is being de-activated.
//
{
}
void CAppSpecificListView::ViewActivatedL(
//
// The view is being activated.
//
const TVwsViewId& aPrevViewId,
const TUid aCustomMessageId,
const TDesC8& aCustomMessage)
{
}
//////////////////////////////////////////////////////////////////////////////
CAppSpecificUi::~CAppSpecificUi()
{
}
void CAppSpecificUi::ConstructL(void)
//
// Normal primary entry point to a Symbian App
//
{
CQikAppUi::ConstructL();
CAppSpecificListView* q=new(ELeave)CAppSpecificListView(*this);
CleanupStack::PushL(q);
q->ConstructL();
AddViewL(*q); // takes ownership
CleanupStack::Pop(q);
}
/////////////////////////////////////////////////////////////////////////////////////////////
// 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(void);
};
TUid CAppSpecificApplication::AppDllUid() const
{
return(KAppSpecificUid);
}
CApaDocument* CAppSpecificApplication::CreateDocumentL(void)
{
return(CAppSpecificDocument::NewL(*this));
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application start up code
LOCAL_C CApaApplication* NewApplication(void)
{
return(new CAppSpecificApplication);
}
GLDEF_C TInt E32Main()
{
return(EikStart::RunApplication(NewApplication));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -