Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
This page was last modified 13:59, 14 October 2008.

CS001111 - Detecting focus change with RGA

From Forum Nokia Wiki



ID CS001111 Creation date October 1, 2008
Platform S60 3rd Edition Tested on devices Nokia N93, Nokia N95
Category Open C/C++ Subcategory RGA


Keywords (APIs, classes, methods, functions):

Overview

This code snippet shows how to handle an application's actions while it has lost or gained focus with the RGA API.

Note: In order to use this code, you need to install the Open C plug-in.

Preconditions

To use this snippet you need to inherit your class from IApplicationStateObserver and create an instance of the IApplicationState object and set an observer to you class. Also you'll need to define the FocusGained() or/and FocusLost() functions which will be called by the observer.

This example relies on RGA API ngi and examplefw frameworks.

To run this snippet you need to use the ngi and examplefw frameworks provided with Open C/C++ Plug-ins for S60 3rd Edition. Examplefw sources are located in the "\nokia_plugin\rga\s60rgaex\common\gameexfw\src\" folder after the plug-in has been installed.

MMP file

The following capabilities and libraries are required:

CAPABILITY  SwEvent
STATICLIBRARY    libcrt0.lib
LIBRARY          euser.lib
LIBRARY          runtime.lib
LIBRARY          libc.lib
LIBRARY          libm.lib
LIBRARY          libpthread.lib

Note: The snippet itself doesn't require any special capabilities, but due to the use of RGA API ngi framework, the resulting application requires SwEvent capability. (See also Open C/C++ DLL.)

Header file

#include <applicationstate.h>    // ngi
using namespace ngi;
 
class CExampleApplication : public IApplicationStateObserver
//...
{
 
//...
 
    /**
     * Application gained focus.
     *
     * Observer method for the gained focus event.
     */
    virtual void FocusGained() NO_THROW;
    /**
     * Application lost focus.
     *
     * Observer method for the lost focus event.
     */
    virtual void FocusLost() NO_THROW;
 
//...
 
    /// Pointer to the application state object.
    IApplicationState* mApplicationState;
 
//...
}

Source file

#include <errorcodes.h>         // ngi
#include <runtime.h>            // ngi
#include <standardtypes.h>      // ngi
#include "helper.h"		//examplefw
 
CExampleApplication::~CExampleApplication()
{
//...
    if( mApplicationState )
    {
        mApplicationState->SetObserver( NULL );
        mApplicationState->Release();
        mApplicationState = NULL;
    }
//...
}
 
bool32 CExampleApplication::Initialize()
{
//...
    if( CRuntime::CreateInstance( mApplicationState ) != OK)
    {
        return FALSE;
    }
 
    mApplicationState->SetObserver( this );
 
    return TRUE;
}
 
// ---------------------------------------------------------
// This method is called when application looses focus.
// ---------------------------------------------------------
void CExampleApplication::FocusLost() NO_THROW
   {
   //Do necessary action on losing of focus	
   }
 
// ---------------------------------------------------------
// This method is called when application gets focus.
// ---------------------------------------------------------
void CExampleApplication::FocusGained() NO_THROW
   {
   //Do necessary action on gaining of focus
   }

Postconditions

The observer will call FocusGained() or FocusLost() on focus load or gained events.

 
Powered by MediaWiki
RDF Facets: qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX