Symbian3/SDK/Source/GUID-D0F6E95B-B35A-4EA1-8CC3-D86D1E0E6DD3.dita
changeset 8 ae94777fff8f
parent 0 89d6a7a84779
child 13 48780e181b38
equal deleted inserted replaced
7:51a74ef9ed63 8:ae94777fff8f
    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 <codeblock xml:space="preserve">void CMyAppView::HandlePointerEventL
    24 <p>The following code snippets explain how to create and display Stylus pop-up
    25     ( const TPointerEvent&amp; aPointerEvent )
    25 menu:<ul>
    26     {
    26 <li><p><b>Creating directly:</b></p><codeblock xml:space="preserve">// member variable point to the stylus Popup menu
    27     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
    27 CAknStylusPopUpMenu * iPopupMenu ;
    28         {
    28 _LIT(KItem1, "Item 1");
    29         if ( !iMenu )
    29 _LIT(KItem2, "Item 2");
    30             {
    30 _LIT(KItem3, "Item 3");
    31             iMenu = CAknStylusPopUpMenu::NewL( 
    31 _LIT(KItem4, "Item 4");
    32                     iMenuObserver, 
    32 enum StylusPopupMenuCommand
    33                     aPointerEvent.iParentPosition, 
    33 	{
    34                     NULL );
    34 	StylusMenuCommand1 = 0 ,
    35             TInt resourceReaderId = 0;
    35 	StylusMenuCommand2,
    36             resourceReaderId = R_MYAPP_STYLUS_MENU;
    36 	StylusMenuCommand3,
    37             TResourceReader reader;
    37 	StylusMenuCommand4
    38             iCoeEnv-&gt;CreateResourceReaderLC( 
    38 	};
    39                     reader, resourceReaderId );
    39 // create object , “this” is a object implement the interface 
    40             iMenu-&gt;ConstructFromResourceL( reader );
    40 // MEikMenuObserver
    41             CleanupStack::PopAndDestroy(); // reader
    41 iPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint( 0 , 0 ) );
    42             }
    42 // add menu item
    43         iMenu-&gt;SetPosition( aPointerEvent.iParentPosition );
    43 iPopupMenu-&gt;AddMenuItemL( KItem1 , StylusMenuCommand1 );
    44         iMenu-&gt;ShowMenu();
    44 iPopupMenu-&gt;AddMenuItemL( KItem2 , StylusMenuCommand2 );
    45         }
    45 iPopupMenu-&gt;AddMenuItemL( KItem3 , StylusMenuCommand3 );
    46     // Forward event to base class too.
    46 iPopupMenu-&gt;AddMenuItemL( KItem4 , StylusMenuCommand4 );
    47     CCoeControl::HandlePointerEventL( aPointerEvent );
    47 </codeblock></li>
    48     }
    48 <li><p><b>Creating through resource file:</b></p><codeblock xml:space="preserve">RESOURCE STYLUS_POPUP_MENU r_stylus_popup_menu
    49 
    49 	{
    50 RESOURCE STYLUS_POPUP_MENU r_myapp_stylus_menu
    50 		items =
    51     {
    51 		{
    52     items =
    52 			STYLUS_POPUP_MENU_ITEM
    53         {
    53 				{
    54         STYLUS_POPUP_MENU_ITEM 
    54 					txt = "Menu Item 1";
    55             {
    55 					command = EStylusPopupCommand1;				},
    56             txt = "Stylus Popup Menu Item 1"; 
    56 			STYLUS_POPUP_MENU_ITEM
    57             command = EMyAppMenuItemCmd1;
    57 				{
    58             },
    58 					txt = "Menu Item 2";
    59         STYLUS_POPUP_MENU_ITEM 
    59 					command = EStylusPopupCommand2;				},
    60             {
    60 			STYLUS_POPUP_MENU_ITEM
    61             txt = "Stylus Popup Menu Item 2"; 
    61 				{
    62             command = EMyAppMenuItemCmd2; 
    62 					txt = "Menu Item 3";
    63             },
    63 					command = EStylusPopupCommand3;
    64         STYLUS_POPUP_MENU_ITEM 
    64 				}
    65             { 
    65 		};
    66             txt = "Stylus Popup Menu Item 3"; 
    66 	}
    67             command = EMyAppMenuItemCmd3; 
    67 // create object
    68             }
    68 iPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint( 0 , 0 ) );
    69         };
    69 {
    70     }
    70 	TResourceReader reader;
    71 </codeblock>
    71 	iCoeEnv-&gt;CreateResourceReaderLC( 
       
    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>
    72 </conbody></concept>
    80 </conbody></concept>