Namespaces
Variants
Actions

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

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): Nokia 5800 XpressMusic

Compatibility
Platform(s): S60 5th Edition

Article
Keywords: CCoeControl::EnableDragEvents()
Created: tepaa (03 Oct 2008)
Last edited: hamishwillee (14 Jun 2012)

Contents

Overview

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

private:
void ConstructL(const TRect& aRect);
void HandlePointerEventL(const TPointerEvent& aPointerEvent);
void Move(const TPoint& aPoint);
 
private:
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
CreateWindowL();
 
// Enable drag events listening
EnableDragEvents();
 
// ...

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...
Move(aPointerEvent.iPosition);
 
// Store current point
iMovePoint = aPointerEvent.iPosition;
 
// Draw this control again because we move to position of it
DrawNow();
}
 
// ...

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
rect.Move(offset);
}


Postconditions

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

This page was last modified on 14 June 2012, at 05:10.
104 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved