How to handle Focus On Controls on Down and Up Errow in Nokia Series60 Platform

Platforms:

As Nokia Series 60 platform uses model view controller pattern for user Interface, each view is activated and deactivated by framework; now how we can handle focus events on multiple controls on key up and key down events and set the focus ? Because in Nokia Series60 Avkon Environment all the controls are derived from base class CCoeControl here is how we can solve this problem...

Suppose there are Three controls in one Appview container two are edit windows and one is secret editor as follows

Define the following data member in your view or container class:

#define KNumOfEdwin            2
#define KNumofSecretEditors    1
#define KTotalNumberOfControls 3

class CYourView: public CCoeControl
{
...
private:
CEikEdwin*        iPtrEditorWindows[KNumofEdwin];
CEikSecretEditor* iPtrSecretEditor;//Only One
CCoeControl*      iPtrToFocusControls[KTotalNumberOfControls];
}

In the second phase constructor of your class, after initializaing editor and secret editor controls just write the code:

for(TInt iIndex = 0;iIndex < KNumberOfEdwin;iIndex++)
{
 iPtrToFocusControls[iIndex] = iPtrEditorWindows[Index];
}
iPtrToFocusControls[iIndex] = iPtrSecretEditor;

Now in function OfferKeyEventL, we can handle focus control events like this:

for (TInt iIndex = 0; iIndex < KTotalNumberofControls; iIndex++)
{
 if (iPtrToFocusControls[iIndex]->IsFocused())
 {
   // Move focus to previous control.
   if ((aType == EEventKey) && (aKeyEvent.iCode == KeyUpArrow))
   {
     iPtrToFocusControls[iIndex]->SetFocus(EFalse);
     if (iIndex == 0)    // if first control, move focus to last.
     {
       iIndex = KTotalNumberofControls;
     }
     iPtrToFocusControls[iIndex - 1]->SetFocus(ETrue);
     return EKeyWasConsumed;
   }
   // Move focus to next control.
   else if((aType == EEventKey)&&(aKeyEvent.iCode == EKeyDownArrow))
   {
     iPtrToFocusControls[iIndex]->SetFocus(EFalse);
     if(iIndex == KTotalNumberofControls - 1)
     {
       iIndex = -1;    // if last control, move focus to first.
     }
     iPtrToFocusControls[iIndex + 1]->SetFocus(ETrue);
     return EKeyWasConsumed;
   }
   // default action.
   else
   {
      return iPtrToFocusControls[iIndex]->OfferKeyEventL(aKeyEvent, aType);  
   }
 }
}
return EKeyWasNotConsumed;

This will focus on control on down and up error keys: Isn't it so simple.

Bhuvnesh Joshi.
joshi_bhuvnesh@yahoo.com


How to handle Focus On Controls on Down and Up Errow in Nokia Se

Really good article , keep writing in future also.

Best of luck

How to handle Focus On Controls on Down and Up Errow in Nokia Se

Do you know how to highlight any of the mentioned controls? thanks...