×
Namespaces

Variants
Actions
Revision as of 08:59, 18 September 2012 by hamishwillee (Talk | contribs)

Listening for screen orientation changes in Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N95
Compatibility
Platform(s): S60 3rd Edition, S60 5th Edition
Article
Keywords: CAknAppUi::HandleResourceChangeL(), CCoeControl::HandleResourceChange()
Created: tepaa (08 Jun 2009)
Last edited: hamishwillee (18 Sep 2012)

Contents

Overview

Layout and screen orientation change events are generated when the screen size or layout is changed. The S60 platform supports multiple screen resolutions. Handling this event can be implemented into application CAknAppUi class or application CCoeControl UI controls.


Source

Solution 1: UI control derived from CCoeControl can handle layout changes overriding the CCoeControl::HandleResourceChange() method

void CExampleControl::HandleResourceChange(TInt aType)
{
// Call base class implementation
CCoeControl::HandleResourceChange(aType);
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);
// Set new screen rect
SetRect(rect);
}
}

Solution 2: Application UI class derived from CAknAppUi can override CEikAppUi::HandleResourceChangeL() to get the KEikDynamicLayoutVariantSwitch layout change event.

void CExampleAppUi::HandleResourceChangeL(TInt aType)
{
// Call base class implementation
CAknAppUi::HandleResourceChangeL( aType );
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);
 
// Set new screen rect
// Must not call this if the iExampleControlContainer
// component is on the control stack
iExampleControlContainer->SetRect(rect);
}
 
// Must not call this if the iSomeDialog
// component is on the control stack
//iSomeDialog->HandleResourceChangeL( aType );
}


See also

Archived:Switching orientation in dialog-based Symbian C++ applications


Postconditions

A layout change event is received and the new layout size is read.

62 page views in the last 30 days.
×