<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License
"Eclipse Public License v1.0" which accompanies this distribution,
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
Nokia Corporation - initial contribution.
Contributors:
-->
<!DOCTYPE concept
PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-D0F6E95B-B35A-4EA1-8CC3-D86D1E0E6DD3" xml:lang="en"><title>Creating
stylus pop-up menu</title><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>Construct the menu using the method <xref href="jar:GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6.jar!/html/classCAknStylusPopUpMenu.html#9dda70f72d42d0877cbbf9ca299649af" format="application/java-archive"><codeph>NewL()</codeph></xref>in the class <xref href="jar:GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6.jar!/html/classCAknStylusPopUpMenu.html" format="application/java-archive"><codeph>CAknStylusPopUpMenu</codeph></xref>.</p>
<note> <p>The last parameter in the constructor is a pointer to the preview
pop-up from which the stylus pop-up menu is launched. If you are not constructing
a pop-up menu for a preview pop-up, set the parameter as <codeph>NULL</codeph>.</p></note>
<p>To construct the menu from a resource, use the method <xref href="jar:GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6.jar!/html/classCAknStylusPopUpMenu.html#75cd95c35a6ed4734b93713596bb51d5" format="application/java-archive"><codeph>CAknStylusPopUpMenu::ConstructFromResourceL()</codeph></xref>.</p>
<p>The following example illustrates a stylus pop-up menu opened in the location
(not a preview pop-up) where the user taps with the stylus as well as the
resource that defines the menu items:</p>
<note><p>The menu is constructed only once: when <codeph>HandlePointerEventL</codeph> runs
for the first time. Later the already constructed menu is shown again.</p></note>
<p>The following code snippets explain how to create and display Stylus pop-up
menu:<ul>
<li><p><b>Creating directly:</b></p><codeblock xml:space="preserve">// member variable point to the stylus Popup menu
CAknStylusPopUpMenu * iPopupMenu ;
_LIT(KItem1, "Item 1");
_LIT(KItem2, "Item 2");
_LIT(KItem3, "Item 3");
_LIT(KItem4, "Item 4");
enum StylusPopupMenuCommand
{
StylusMenuCommand1 = 0 ,
StylusMenuCommand2,
StylusMenuCommand3,
StylusMenuCommand4
};
// create object , “this” is a object implement the interface
// MEikMenuObserver
iPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint( 0 , 0 ) );
// add menu item
iPopupMenu->AddMenuItemL( KItem1 , StylusMenuCommand1 );
iPopupMenu->AddMenuItemL( KItem2 , StylusMenuCommand2 );
iPopupMenu->AddMenuItemL( KItem3 , StylusMenuCommand3 );
iPopupMenu->AddMenuItemL( KItem4 , StylusMenuCommand4 );
</codeblock></li>
<li><p><b>Creating through resource file:</b></p><codeblock xml:space="preserve">RESOURCE STYLUS_POPUP_MENU r_stylus_popup_menu
{
items =
{
STYLUS_POPUP_MENU_ITEM
{
txt = "Menu Item 1";
command = EStylusPopupCommand1; },
STYLUS_POPUP_MENU_ITEM
{
txt = "Menu Item 2";
command = EStylusPopupCommand2; },
STYLUS_POPUP_MENU_ITEM
{
txt = "Menu Item 3";
command = EStylusPopupCommand3;
}
};
}
// create object
iPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint( 0 , 0 ) );
{
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(
reader ,
R_STYLUS_POPUP_MENU );
iPopupMenu->ConstructFromResourceL( reader );
// destroy reader
CleanupStack::PopAndDestroy();
}
</codeblock></li>
</ul></p>
</conbody></concept>