How_to_Handle_Pointer_Events_in_a_Custom_Control(转)

This page was last modified on 30 September 2009, at 06:05.

ID...Creation date26.10.2008
PlatformS60 5th EditionTested on devicesNokia 5800 XpressMusic.
CategorySymbian C++SubcategoryTouch UI

Keywords (APIs, classes, methods, functions): HandlePointerEventL(),Custom Control.

Overview

This snippet shows how to handle Pointer events in a custom control and route them to a proper component control by validating the pointer area against the control rect.

This snippet can be self-signed.

Preconditions

Here we assume that we already have a working code for custom control, and we also assume that we have two components: iEdwin1 and iEdwin2 in a custom control.

MMP file

The following capabilities and libraries are required:

CAPABILITY  None
 
LIBRARY cone.lib

#include <COECNTRL.H> 
 
void CCustomContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
// Validate pointer position.
if( iEdwin1->Rect().Contains( aPointerEvent.iPosition ) )
{
// click on edwin1 pass the pointer event. //
iEdwin1->HandlePointerEventL( aPointerEvent );
}
else if( iEdwin2->Rect().Contains( aPointerEvent.iPosition ) )
{
// click on edwin2 pass the pointer event. //
iEdwin2->HandlePointerEventL( aPointerEvent );
}
else
{
// simply calling the base class implementation //
CCoeControl::HandlePointerEventL(aPointerEvent);
}
}

Postconditions

Pointer position will validated against the control rectangle and the pointer events will be routed to appropriate control.

posted @ 2010-12-15 11:32  冰岛  阅读(206)  评论(0编辑  收藏  举报