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.
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SetFocus() and EDrawNow Semantics. | colinlawrence | Symbian User Interface | 0 | 2003-09-29 15:15 |
| MIDP 2.0 ItemStateListener on Nokia Emulator | dave@smartphonebet.co.uk | Mobile Java General | 5 | 2004-01-24 18:27 |
| bluetooth devices not detecting in mobile | kissh_k | Mobile Java Networking & Messaging & Security | 8 | 2008-02-05 06:46 |
| Can we set textbox focus to the last character? | dhanyap | Mobile Java General | 1 | 2006-11-17 08:07 |
| Form not drawn when application regains focus after losing focus | mew1979 | General Symbian C++ | 0 | 2008-03-25 12:33 |

