buildingblocks3.cpp

来自「《UIQ 3 The Complete Guide》书的源代码」· C++ 代码 · 共 330 行

CPP
330
字号
//
// BuildingBlocks3.cpp - Building blocks 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 "BuildingBlocks3.h"
#include "BuildingBlocks3.hrh"
#include <BuildingBlocks3.rsg>

#include <QikMultiPageViewBase.h>
#include <QikCommand.h>
#include <QikSlider.h>
#include <QikIpEditor.h>
#include <QikNumberEditor.h>
#include <QikFloatingPointEditor.h>
#include <QikTimeAndDateEditor.h>
#include <QikDurationEditor.h>
#include <eikstart.h>
#include <eikchlst.h>
#include <eikchkbx.h>
#include <eikedwin.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={0xEDEAD007};

// 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
const TInt KMaxListItems=7;

class CChoiceListArray : public CBase, public MDesCArray
	{
protected:
	// from MDesCArray
	TInt MdcaCount() const;
	TPtrC MdcaPoint(TInt aIndex) const;
public:
	CChoiceListArray();
protected:
	TBuf<KMaxListItemText> iContent[KMaxListItems];
	};

CChoiceListArray::CChoiceListArray()
	{
	// contrary to popular opinion its perfectly reasonable to have code in an object 
	// constructor - as long as is DOES NOT leave.
	CEikonEnv* eikEnv=CEikonEnv::Static();
	for (TInt i=0;i<KMaxListItems;i++)
		eikEnv->ReadResource(iContent[i],R_STR_LIST_CONTENT_1+i);
	}

TInt CChoiceListArray::MdcaCount() const
// report number of entries in the choice list
	{
	return(KMaxListItems);
	}

TPtrC CChoiceListArray::MdcaPoint(TInt aIndex) const
	{
	return(iContent[aIndex]);
	}

//////////////////////////////////////////////////////////////////////////////////
class CAppSpecificListView : public CQikMultiPageViewBase
	{
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
	~CAppSpecificListView();
	CAppSpecificListView(CAppSpecificUi& aAppUi);

protected:
	CChoiceListArray* iAppChoiceList;
	};


CAppSpecificListView::~CAppSpecificListView()
	{
	delete(iAppChoiceList);
	}

CAppSpecificListView::CAppSpecificListView(CAppSpecificUi& aAppUi) :
	CQikMultiPageViewBase(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 EAppCmdInfo:
		{
		CCoeControl* q=FocusedControl();
		switch (q->UniqueHandle())
			{
		case EAppChoiceList1:
		case EAppChoiceList2:
		case EAppButton1:
		case EAppCheckbox1:
			_LIT(KChoiceCheckHasFocus,"Choice/check has focus");
			iEikonEnv->InfoMsg(KChoiceCheckHasFocus);
			break;

		// these should not occur since Control stand-ins get created and its those that
		// have focus and not the actual edit controls.
		case EAppSlider1:
		case EAppEdwin1:
		case EAppEdwin2:
		case EAppEdwin3:
		case EAppEdwin4:
		case EAppEdwin5:
		case EAppEdwin6:
			_LIT(KEdwinSliderHasFocus,"Edwin/slider has focus");
			iEikonEnv->InfoMsg(KEdwinSliderHasFocus);
			break;

		// these appear to be a bit odd in their usage of stand-in controls
		// Dt+time editor doesont even seem to present an 'Open' control command.. 
		case EAppDateTime1:
		case EAppDateTime2:
		case EAppDateTime3:
		case EAppDateTime4:
			_LIT(KDateTimeHasFocus,"Date/time editor has focus");
			iEikonEnv->InfoMsg(KDateTimeHasFocus);
			break;
		default:
			break;	
			}
		break;
		}

	default: // e.g. the back button...
		CQikViewBase::HandleCommandL(aCommand);
		break;
		}
	}

void CAppSpecificListView::ViewConstructL()
	{
	ViewConstructFromResourceL(R_APP_VIEW_CONFIGURATIONS);

	// Create and initialize a choice list
	// here we have chosen to create and maintain the list box for the lifetime of the
	// application. As an alternative it is entirely reasonable to create the listbox in
	// ViewActivatedL(), deleting it in the ViewDeactivated().
	iAppChoiceList=new(ELeave)CChoiceListArray;

	// locate the choice list and tell it about the items available to it
	CEikChoiceList* cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList1);
	cl->SetArrayL(iAppChoiceList);
	// tell the choice list it does NOT own the array, we share it 
	cl->SetArrayExternalOwnership(ETrue);

	// this app chooses to share the app generated choice list with a second control
	cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList2);
	cl->SetArrayL(iAppChoiceList);
	cl->SetArrayExternalOwnership(ETrue);
	cl->SetCurrentItem(3);

	// locate the check box and ensure its set
	CEikCheckBox* cb=LocateControlByUniqueHandle<CEikCheckBox>(EAppCheckbox1);
	cb->SetState(CEikButtonBase::ESet);

	// locate the slider and set a default value
	CQikSlider* sl=LocateControlByUniqueHandle<CQikSlider>(EAppSlider1);
	sl->SetValue(21);

	// locate the edwins and set a default value
	_LIT(KSomeText,"Some text");
	TBuf<16> text(KSomeText);
	CEikEdwin* edwin=LocateControlByUniqueHandle<CEikEdwin>(EAppEdwin1);
	edwin->SetTextL(&text);

	_LIT(KOtherText,"Other text");
	text=KOtherText;
	edwin=LocateControlByUniqueHandle<CEikEdwin>(EAppEdwin2);
	edwin->SetTextL(&text);

	// locate the number editor and set a default value
	CQikNumberEditor* numEd=LocateControlByUniqueHandle<CQikNumberEditor>(EAppEdwin4);
	numEd->SetValueL(21);

	// locate the floating point editor and set a default value
	CQikFloatingPointEditor* fltEd=LocateControlByUniqueHandle<CQikFloatingPointEditor>(EAppEdwin5);
	fltEd->SetValueL(21.21);

	// locate and set the IP editor to a default value
	CQikIpEditor* ipEd=LocateControlByUniqueHandle<CQikIpEditor>(EAppEdwin6);
	_LIT(K10203040,"10.20.30.40");
	ipEd->SetIpAddress(K10203040);

	// locate and set the Time + Date editor to a default value.
	CQikTimeAndDateEditor* dtEd=LocateControlByUniqueHandle<CQikTimeAndDateEditor>(EAppDateTime3);
	TTime time;
	time.HomeTime(); // default value is now
	dtEd->SetTimeL(time);

	// locate and set the duration editor to a default value
	CQikDurationEditor* durEd=LocateControlByUniqueHandle<CQikDurationEditor>(EAppDateTime4);
	durEd->SetDurationL(1200); // 1200 secs = 1200/60 mins = 20 mins

	TBuf<64>bb;
	iEikonEnv->ReadResourceL(bb,R_STR_VIEW_TITLE);
	ViewContext()->AddTextL(2,bb); 
	}

void CAppSpecificListView::ViewDeactivated()
	{
	}

void CAppSpecificListView::ViewActivatedL(
	const TVwsViewId& aPrevViewId,
	const TUid aCustomMessageId,
	const TDesC8& aCustomMessage)
	{
	// If the content of the app generated list box varied outside of this view you may 
	// consider constructing the list box here and telling the controls about it. You
	// would destroy the list box in the ViewDeactivated().
	}
	
//////////////////////////////////////////////////////////////////////////////
CAppSpecificUi::~CAppSpecificUi()
	{
	}

void CAppSpecificUi::ConstructL()
//
// 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();
	}; 

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 + =
减小字号Ctrl + -
显示快捷键?