⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpstest.cpp

📁 symbian s60上的GPS
💻 CPP
字号:
/*
============================================================================
 Name        : GPSTest.cpp
 Author      : Fox Jiang
 Version     :
 Copyright   : Kodak Mobile Team
 Description : Application source file
============================================================================

The following steps are taken when starting an application:
1. <Entry Point>::NewApplication() --> CGPSTestApplication
2. CGPSTestApplication::CreateDocument() --> CGPSTestDocument
3. CGPSTestDocument::CreateAppUiL() --> CGPSTestAppUi
4. CGPSTestAppUi::ConstructL() --> CGPSTestContainer

Symbian GUI applications follow the Model-View-Controller (MVC) pattern.
- CGPSTestDocument is the Model that holds the application data
- CGPSTestContainer is the View that displays the application data
- CGPSTestAppUi is the Controller that coordinates user actions/views
While the naming may seem a bit misleading (the names are according to the
current Symbian conventions), it is important to understand how they relate
to the MVC pattern.

Note! Normally you would have a separate file for each of these classes, but
here, for the sake of simplicity, they are all put in the same file. Having
the classes defined in separate files makes the source code easier to maintain.

*/
#include <eikmenup.h> 

// INCLUDES
#include "GPSTest.h"
#include <GPSTest.rsg>

// CONSTANTS
const TUid KUidGPSTestApp = { 0x0a3ffe82 }; // Application UID

// MEMBER FUNCTIONS

//----------------------------------------------------------------------------
// Application entry point
//----------------------------------------------------------------------------

// GLOBAL FUNCTIONS

// DLL entry point, needed for DLL initialization.
// Usually there is no need to initialize anything, so we just
// return that everything is ok
GLDEF_C TInt E32Dll(TDllReason /*aReason*/) {
    return KErrNone;
}

// EXPORTED FUNCTIONS

// Static function for instantiating a new application object.
// Called by the Symbian application framework.
EXPORT_C CApaApplication* NewApplication() {
    return new CGPSTestApplication;
}

//----------------------------------------------------------------------------
// CGPSTestApplication
//----------------------------------------------------------------------------

// Creates the application document (model)
// Called by the Symbian application framework when the application is started.
// Needed for all Symbian applications.
CApaDocument* CGPSTestApplication::CreateDocumentL() {
    return new (ELeave) CGPSTestDocument(*this);
}

// Specifies the application UID, needed for all Symbian applications.
TUid CGPSTestApplication::AppDllUid() const {
    return KUidGPSTestApp;
}

//----------------------------------------------------------------------------
// CGPSTestDocument (The Model of the MVC)
//----------------------------------------------------------------------------

// Creates the application document (Symbian terminology for model).
// Needed for all Symbian applications, even if the application doesn't
// save or load files.
CGPSTestDocument::CGPSTestDocument(CEikApplication& aApp) : CEikDocument(aApp) {
}

// Creates the application UI class.
// Called by the application framework when the application needs to start
// handling events.
// Needed for all Symbian GUI applications.
CEikAppUi* CGPSTestDocument::CreateAppUiL() {
    return new (ELeave) CGPSTestAppUi;
}

//----------------------------------------------------------------------------
// CGPSTestAppUi (The Controller of the MVC)
//----------------------------------------------------------------------------

// Second-phase construction function.
// Called by the Symbian application framework after calling
// the constructor from CGPSTestDocument::CreateAppUiL().
// Needed for initialising the application views.
void CGPSTestAppUi::ConstructL(void) {
    // Load the application resources defined in the GPSTest.rss, e.g.
    // application menus, dialogs etc.
    BaseConstructL();

    iAppContainer = new (ELeave) CGPSTestContainer;
    iAppContainer->SetMopParent( this );
    iAppContainer->ConstructL( ClientRect() );
    AddToStackL( iAppContainer );

	
}

// Releases resources used by the application UI.
// Called when shutting down the application.
CGPSTestAppUi::~CGPSTestAppUi() {
    if (iAppContainer)
    {
        RemoveFromStack( iAppContainer );
        delete iAppContainer;
    }
}

// Handles user commands such as those associated to the menu entries.
// Called by CEikAppUi::ProcessCommandL().
// Application commands are defined in the GPSTest.hrh file.
// Common commands are defined for instance in the uikon.hrh file, located
// under the system include directory (%EPOCROOT%\epoc32\include).
void CGPSTestAppUi::HandleCommandL(TInt aCommand) {
    switch (aCommand)
    {
	case EEikCmdStartGPS:
		{
			iAppContainer->StartGPS();
			break;
		}
	case EEikCmdStopGPS:
		{
			iAppContainer->StopGPS();
			break;
		}
    case EEikCmdFileOpen:
        {
        iEikonEnv->InfoMsg(_L("Open"));
        CAknInformationNote* note = new (ELeave) CAknInformationNote;
        note->ExecuteLD(_L("Hello world!"));
        break;
        }
    case EAknSoftkeyBack:
    case EEikCmdExit:
        {
        Exit();
        break;
        }
    default:
        break;
    }
}

void CGPSTestAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
{	
	if( aResourceId == R_GPSTEST_FILE_MENU  )
	{
		if( iAppContainer->GetStatus() )
		{
			aMenuPane->SetItemDimmed( EEikCmdStartGPS,ETrue );
			aMenuPane->SetItemDimmed( EEikCmdStopGPS,EFalse );
		}
		else
		{
			aMenuPane->SetItemDimmed( EEikCmdStartGPS,EFalse );
			aMenuPane->SetItemDimmed( EEikCmdStopGPS,ETrue );
		}
	}
}
//----------------------------------------------------------------------------
// CGPSTestContainer (The View of the MVC)
//----------------------------------------------------------------------------

// Second-phase construction function.
// Initializes the container (creates a window, sets its bounds and activates
// it) and creates the child/nested controls (if any).
// Called from the AppUi after creating a new container object.
void CGPSTestContainer::ConstructL(const TRect& aRect) {
    CreateWindowL();

    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
    iLabel->SetTextL( _L("GPS Test") );

    iToDoLabel = new (ELeave) CEikLabel;
    iToDoLabel->SetContainerWindowL( *this );
    iToDoLabel->SetTextL( _L("                            ") );

    SetRect(aRect);
    ActivateL();

	iGPS = NULL;
	iGPS = CGPSLib::NewL( this );

	iIsStart = EFalse;
}

// Destructor used for releasing the resources used by his container.
// Called from the AppUi's destructor.
CGPSTestContainer::~CGPSTestContainer() {
    delete iLabel;
    delete iToDoLabel;
	delete iGPS;
}

// Lays out the child controls (if any).
// Called when the control is resized.
void CGPSTestContainer::SizeChanged() {
    // TODO: Add here control resize code etc.
    iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
    iToDoLabel->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
}

// Returns the number of child controls, 0 if none.
TInt CGPSTestContainer::CountComponentControls() const {
    return 2; // return nbr of controls inside this container
}

// Returns the child control at the given index, NULL if none.
CCoeControl* CGPSTestContainer::ComponentControl(TInt aIndex) const {
    switch ( aIndex )
    {
    case 0:
        return iLabel;
    case 1:
        return iToDoLabel;
    default:
        return NULL;
    }
}

// Draws to this controls canvas using graphics primitives.
// Note that the UI framework takes care of drawing the child controls.
void CGPSTestContainer::Draw(const TRect& aRect) const {
    CWindowGc& gc = SystemGc();
    // TODO: Add your drawing code here
    // example code...
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
}

// Handles events generated by the child controls.
void CGPSTestContainer::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) {
    // TODO: Add your control event handler code here
}

void CGPSTestContainer::StartGPS( void )
{
	iGPS->StartGPSL();
	iIsStart = ETrue;
}

void CGPSTestContainer::StopGPS( void )
{
	iGPS->StopGPS();
	iIsStart = EFalse;
}

void CGPSTestContainer::GpsUpdate( const TGpsPosition & aNewPosition )
{
	//GPS信息回溃
	iToDoLabel->MakeVisible( EFalse );
	iToDoLabel->SetTextL( aNewPosition.ToStringL() );
	iToDoLabel->MakeVisible( ETrue );
	iToDoLabel->DrawNow();
}

TBool CGPSTestContainer::GetStatus( void )
{
	return iIsStart;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -