Symbian3/SDK/Source/GUID-D0F6E95B-B35A-4EA1-8CC3-D86D1E0E6DD3.dita
changeset 13 48780e181b38
parent 8 ae94777fff8f
equal deleted inserted replaced
12:80ef3a206772 13:48780e181b38
    19 <p>The following example illustrates a stylus pop-up menu opened in the location
    19 <p>The following example illustrates a stylus pop-up menu opened in the location
    20 (not a preview pop-up) where the user taps with the stylus as well as the
    20 (not a preview pop-up) where the user taps with the stylus as well as the
    21 resource that defines the menu items:</p>
    21 resource that defines the menu items:</p>
    22 <note><p>The menu is constructed only once: when <codeph>HandlePointerEventL</codeph> runs
    22 <note><p>The menu is constructed only once: when <codeph>HandlePointerEventL</codeph> runs
    23 for the first time. Later the already constructed menu is shown again.</p></note>
    23 for the first time. Later the already constructed menu is shown again.</p></note>
    24 <p>The following code snippets explain how to create and display Stylus pop-up
    24 <codeblock xml:space="preserve">void CMyAppView::HandlePointerEventL
    25 menu:<ul>
    25     ( const TPointerEvent&amp; aPointerEvent )
    26 <li><p><b>Creating directly:</b></p><codeblock xml:space="preserve">// member variable point to the stylus Popup menu
    26     {
    27 CAknStylusPopUpMenu * iPopupMenu ;
    27     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
    28 _LIT(KItem1, "Item 1");
    28         {
    29 _LIT(KItem2, "Item 2");
    29         if ( !iMenu )
    30 _LIT(KItem3, "Item 3");
    30             {
    31 _LIT(KItem4, "Item 4");
    31             iMenu = CAknStylusPopUpMenu::NewL( 
    32 enum StylusPopupMenuCommand
    32                     iMenuObserver, 
    33 	{
    33                     aPointerEvent.iParentPosition, 
    34 	StylusMenuCommand1 = 0 ,
    34                     NULL );
    35 	StylusMenuCommand2,
    35             TInt resourceReaderId = 0;
    36 	StylusMenuCommand3,
    36             resourceReaderId = R_MYAPP_STYLUS_MENU;
    37 	StylusMenuCommand4
    37             TResourceReader reader;
    38 	};
    38             iCoeEnv-&gt;CreateResourceReaderLC( 
    39 // create object , “this” is a object implement the interface 
    39                     reader, resourceReaderId );
    40 // MEikMenuObserver
    40             iMenu-&gt;ConstructFromResourceL( reader );
    41 iPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint( 0 , 0 ) );
    41             CleanupStack::PopAndDestroy(); // reader
    42 // add menu item
    42             }
    43 iPopupMenu-&gt;AddMenuItemL( KItem1 , StylusMenuCommand1 );
    43         iMenu-&gt;SetPosition( aPointerEvent.iParentPosition );
    44 iPopupMenu-&gt;AddMenuItemL( KItem2 , StylusMenuCommand2 );
    44         iMenu-&gt;ShowMenu();
    45 iPopupMenu-&gt;AddMenuItemL( KItem3 , StylusMenuCommand3 );
    45         }
    46 iPopupMenu-&gt;AddMenuItemL( KItem4 , StylusMenuCommand4 );
    46     // Forward event to base class too.
    47 </codeblock></li>
    47     CCoeControl::HandlePointerEventL( aPointerEvent );
    48 <li><p><b>Creating through resource file:</b></p><codeblock xml:space="preserve">RESOURCE STYLUS_POPUP_MENU r_stylus_popup_menu
    48     }
    49 	{
    49 
    50 		items =
    50 RESOURCE STYLUS_POPUP_MENU r_myapp_stylus_menu
    51 		{
    51     {
    52 			STYLUS_POPUP_MENU_ITEM
    52     items =
    53 				{
    53         {
    54 					txt = "Menu Item 1";
    54         STYLUS_POPUP_MENU_ITEM 
    55 					command = EStylusPopupCommand1;				},
    55             {
    56 			STYLUS_POPUP_MENU_ITEM
    56             txt = "Stylus Popup Menu Item 1"; 
    57 				{
    57             command = EMyAppMenuItemCmd1;
    58 					txt = "Menu Item 2";
    58             },
    59 					command = EStylusPopupCommand2;				},
    59         STYLUS_POPUP_MENU_ITEM 
    60 			STYLUS_POPUP_MENU_ITEM
    60             {
    61 				{
    61             txt = "Stylus Popup Menu Item 2"; 
    62 					txt = "Menu Item 3";
    62             command = EMyAppMenuItemCmd2; 
    63 					command = EStylusPopupCommand3;
    63             },
    64 				}
    64         STYLUS_POPUP_MENU_ITEM 
    65 		};
    65             { 
    66 	}
    66             txt = "Stylus Popup Menu Item 3"; 
    67 // create object
    67             command = EMyAppMenuItemCmd3; 
    68 iPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint( 0 , 0 ) );
    68             }
    69 {
    69         };
    70 	TResourceReader reader;
    70     }
    71 	iCoeEnv-&gt;CreateResourceReaderLC( 
    71 </codeblock>
    72                        reader , 
       
    73                        R_STYLUS_POPUP_MENU );
       
    74 	iPopupMenu-&gt;ConstructFromResourceL( reader );
       
    75 		// destroy reader
       
    76 	CleanupStack::PopAndDestroy();
       
    77 }
       
    78 </codeblock></li>
       
    79 </ul></p>
       
    80 </conbody></concept>
    72 </conbody></concept>