Friday, April 04, 2008

How to handle Layout change events

Layout change events are generated when the screen size or layout is changed. The S60 platform supports multiple screen resolutions[also called as "Scalable UI"]. Thus, layout awareness is particularly crucial for those applications to reorganize the position as required. Applications can detect the changes in layout with, for example, the following methods:

1. Controls can override the CCoeControl::HandleResourceChange() to detect the KEikDynamicLayoutVariantSwitch message.
The following example code for HandleResourceChange():

    void CMyControl::HandleResourceChange(TInt aType)
{
CCoeControl::HandleResourceChange(aType); //call base class implementation
if ( aType==KEikDynamicLayoutVariantSwitch )
{
TRect rect;
// ask where container's rectangle should be
// EMainPane equals to area returned by
//CEikAppUi::ClientRect()
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,rect);
SetRect(rect);
}
}


2. UI controllers can override the CEikAppUi::HandleResourceChangeL() to detect the KEikDynamicLayoutVariantSwitch message.

The following example code for HandleResourceChangeL():

    void CExampleAppUi::HandleResourceChangeL(TInt aType)
{
CAknAppUi::HandleResourceChangeL( aType );
if ( aType == KEikDynamicLayoutVariantSwitch )
{
// do the re-layout of the components
}
// Controls derived from CCoeControl, handled in a
// container class
iExampleControlContainer->HandleResourceChange( aType );
//Must not call this if the components are on the control stack
//iView->HandleResourceChangeL( aType );
}

No comments:

stats counter