Namespaces

Variants
Actions

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 over the next few weeks. Thanks for all your past and future contributions.

Working with Stylus Pop-up Menu API - S60 Touch UI

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleCompatibility
Platform(s):
S60 5th Edition
Article
Created: kiran10182 (02 Nov 2008)
Last edited: hamishwillee (08 Feb 2012)

Contents

Overview

Stylus Pop-up Menu is a new component introduced in S60 5th edition Touch UI concept. In this article we will learn how to play with Stylus Pop-up Menu API with different methods.

What is Stylus Pop-up Menu API

  • It is a floating component.
  • Generally it is used with the long tap detection event.
  • It pops up near the tap position.
  • When the Item within pop-up menu is tapped, it should be handled in the ProcessCommandL.

StylusPopupMenu.png

Preface of the example

  • In this example we will use Stylus Pop-up Menu in conjunction with LongTapDetector API.
  • We will inherit from MAknLongTapDetectorCallBack and implement HandleLongTapEventL()
  • We will inherit from MEikMenuObserver and implement ProcessCommandL to handle Stylus Pop-up Menu item commands.

Creating Stylus Pop-up Menu resource

RESOURCE STYLUS_POPUP_MENU r_stylus_popup_menu
{
items =
{
STYLUS_POPUP_MENU_ITEM
{
txt = "Add menu item";
command = ECommand1; // In this example we are using the same set of commands which are handled in AppUi::HandleCommandL
},
STYLUS_POPUP_MENU_ITEM
{
txt = "Remove menu item";
command = ECommand2; // In this example we are using the same set of commands which are handled in AppUi::HandleCommandL
},
STYLUS_POPUP_MENU_ITEM
{
txt = "Exit Application";
command = EAknSoftkeyExit;
}
};
}

Implementing Stylus Pop-up Menu in the code

StylusPopupAppView.h

.....
#include <aknlongtapdetector.h>
#include <aknstyluspopupmenu.h>
#include <EIKMOBS.H>
 
// CLASS DECLARATION
class CStylusPopupAppView : public CCoeControl, public MAknLongTapDetectorCallBack, public MEikMenuObserver
{
....
....
// From MAknLongTapDetectorCallBack
virtual void HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation );
 
//From MEikMenuObserver
void ProcessCommandL(TInt aCommandId);
void SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/)
{
}
 
//Example logic helper function
void AddMenuItemRuntime(TInt aId);
void RemoveMenuItemRuntime(TInt aId);
....
....
private:
CAknLongTapDetector* iLongTapDetector;
CAknStylusPopUpMenu* iStylusPopupMenu;
TInt iCount;
.....
.....
};

StylusPopupAppView.cpp

  • Set "this" class to receive long tap detection events in the ConstructL() as shown below.
// -----------------------------------------------------------------------------
// CStylusPopupAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CStylusPopupAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
 
iLongTapDetector = CAknLongTapDetector::NewL(this);
.....
}


  • Handle pointer events in HandlePointerEventL as shown below.
// -----------------------------------------------------------------------------
// CStylusPopupAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// -----------------------------------------------------------------------------
//
void CStylusPopupAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
// Pass the pointer event to Long tap detector component
iLongTapDetector->PointerEventL(aPointerEvent);
 
// Call base class HandlePointerEventL()
CCoeControl::HandlePointerEventL(aPointerEvent);
}
  • Long tap events should be handled in the following callback function from MAknLongTapDetectorCallBack
  • In this example we will create/show Stylus Pop-up Menu when the Long trap event is detected.
  • Both the arguments in the HandleLongTapEventL will give points of the event occurrence with respect to the following points:
    • aPenEventLocation gives Long tap event location relative to parent control.
    • aPenEventScreenLocation gives Long tap event location relative to screen.
void CStylusPopupAppView::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation )
{
if(!iStylusPopupMenu)
{
iStylusPopupMenu = CAknStylusPopUpMenu::NewL( this , aPenEventLocation);
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader,R_STYLUS_POPUP_MENU);
iStylusPopupMenu->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy();
}
iStylusPopupMenu->ShowMenu();
iStylusPopupMenu->SetPosition(aPenEventLocation);
}
  • Application's logic helper functions which help in adding and removing items in the Stylus Pop-up Menu.
  • AddMenuItemRuntime() will add item at runtime to the Stylus Pop-up Menu.
  • RemoveMenuItemRuntime() will remove item at runtime from the Stylus Pop-up Menu.
  • ProcessCommandL() will handle item selected from the Stylus Pop-up Menu. In this example we are using the same enumeration that is used in AppUi::HandleCommandL but with different implementation.

StylusPopupMenuAddRemoveItem.png

void CStylusPopupAppView::AddMenuItemRuntime(TInt aId)
{
_LIT(KMenuItem,"Item %d");
TBuf<20> buf;
buf.Format(KMenuItem(), aId);
iStylusPopupMenu->AddMenuItemL(buf,aId);
iStylusPopupMenu->ShowMenu();
}
 
void CStylusPopupAppView::RemoveMenuItemRuntime(TInt aId)
{
iStylusPopupMenu->RemoveMenuItem(aId);
iStylusPopupMenu->ShowMenu();
}
 
void CStylusPopupAppView::ProcessCommandL(TInt aCommand)
{
switch(aCommand)
{
case ECommand1:
AddMenuItemRuntime(iCount++);
break;
 
case ECommand2:
if(iCount>0)
RemoveMenuItemRuntime(--iCount);
break;
 
 
case EAknSoftkeyExit:
User::Exit(0);
break;
 
default:
CAknInformationNote* info = new (ELeave) CAknInformationNote;
info->ExecuteLD(_L("Runtime added command pressed!"));
break;
}
}
  • Make sure to delete iLongTapDetector in the destructor of the class.
  • Make sure to delete iStylusPopupMenu in the destructor of the class.
 
// -----------------------------------------------------------------------------
// CStylusPopupAppView::~CStylusPopupAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CStylusPopupAppView::~CStylusPopupAppView()
{
.....
.....
if(iLongTapDetector)
delete iLongTapDetector, iLongTapDetector = NULL;
 
if(iStylusPopupMenu)
delete iStylusPopupMenu, iStylusPopupMenu = NULL;
.....
}

Useful functions

CAknStylusPopUpMenu

  • ShowMenu()
  • AddMenuItemL()
  • RemoveMenuItem()
  • SetPosition()

MAknLongTapDetectorCallBack

  • HandleLongTapEventL()

Keywords

Headers

  • #include <AknToolbarObserver.h>
  • #include <AknToolbar.h>
  • #include <Aknstyluspopupmenu.h>

Classes

  • CAknStylusPopUpMenu
  • CAknToolbar
  • MAknToolbarObserver

Libraries

  • eikcoctl.lib

Example Application

Related links

Reference list

This page was last modified on 8 February 2012, at 04:25.
61 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×