How to Handle Pointer Events in a Custom Control
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic.
Compatibility
Platform(s): S60 5th Edition
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: HandlePointerEventL(),Custom Control.
Created: vasant21
(26 Oct 2008)
Last edited: hamishwillee
(30 May 2013)
Contents |
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.


30 Sep
2009
Handling pointer events in custom controls is often require during developing custom GUI applications. This article demonstrates how pointer position will validated against the control rectangle and the pointer events will be routed to appropriate control. The article is well explained and useful to beginners.
This piece of code works, but logically error. CCoeControl::HandlePointerEventL(aPointerEvent); will dispatch the pointer event to proper control automatically, so the if blocks just redo the logical already provided by CCoeControl. And thus give a bad impression to developer that they have to maintain the pointer dispatching stuff by themselves in a container.(Just like the key process)
You need to do the dispatch by yourself only when the control contained by the container can't be accessed by container's CCoeControl *ComponentControl(TInt aIndex) const; function. Most time that's an error
User:bibu2651 17:10, 26 Jan 2010