Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 02:10, 14 June 2012 by hamishwillee (Talk | contribs)

Enabling drag events in Symbian C++ on touch-enabled devices

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Platform(s): S60 5th Edition
Keywords: CCoeControl::EnableDragEvents()
Created: tepaa (03 Oct 2008)
Last edited: hamishwillee (14 Jun 2012)



S60 5th Edition supports touch events. All AVKON UI controls handle touch UI events and you do not need to implement anything new.

If you want to listen for drag events in your custom CCoeControl UI control, use CCoeControl::EnableDragEvents().

MMP file

The following libraries are required:

LIBRARY cone.lib

Header file

void ConstructL(const TRect& aRect);
void HandlePointerEventL(const TPointerEvent& aPointerEvent);
void Move(const TPoint& aPoint);
TPoint iMovePoint;

Source file

Enable drag event listening in the container control ConstructL().

EnableDragEvents() needs to be called only once in the entire application.
void CMyControl::ConstructL(const TRect& /*aRect*/)
// Create window of this container control
// Enable drag events listening
// ...

Drag events are received.

void CMyControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
if (aPointerEvent.iType == TPointerEvent::EButton1Down)
iMovePoint = aPointerEvent.iPosition;
else if (aPointerEvent.iType == TPointerEvent::EDrag)
// Drag events received, what to do with it?
// We could move this control...
// Store current point
iMovePoint = aPointerEvent.iPosition;
// Draw this control again because we move to position of it
// ...

Moving control to dragging point:

void CMyControl::Move(const TPoint& aPoint)
TPoint offset;
// Calculate moving offset
offset.iX = aPoint.iX - iMovePoint.iX;
offset.iY = aPoint.iY - iMovePoint.iY;
TRect rect = Rect();
// Move this control


Drag events are received and control is moved to the pointer location.

See also

S60 5th Edition: Solitaire Game Example

S60 Platform: Image Converter Example

Handling pointer events in Symbian C++

CS001145 - Pointer capturing in touch-enabled devices

71 page views in the last 30 days.