×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    41

    Question How to Override the Menu Options in the UI Form View

    Hi,

    I am new in mobile development...

    I have created a simple S60 application with "Form" option of UI design. I also made the "Form View" in "Edit Only" mode type ("edit mode only" = "true"). Now as you know, in the "Menu" of "Form View" class, there is a "Save" option, and what I want is to override this option and use my own one. Actually, I want to remove the "Save" option and put an "Exit" option, also I want to rename the "Back" option to "Exit" option (the "Back" option is on the right-side and it apears as "Back" option immediately when the application starts because the "Form View" is on "Edit Only" mode type).

    Below is the code:

    Code:
    #include <avkon.hrh>
    #include <avkon.rsg>
    #include <eikmenup.h>
    #include <aknappui.h>
    #include <eikcmobs.h>
    #include <barsread.h>
    #include <stringloader.h>
    #include <eikfpne.h>
    #include <eikenv.h>
    #include <MyFirstUI.rsg>
    #include "MyFirstUIForm.h"
    #include "MyFirstUI.hrh"
    #include "MyFirstUIForm.hrh"
    
    _LIT( KFloatingPointEditor1TextValue, "0" );
    _LIT( KFloatingPointEditor2TextValue, "0" );
    _LIT( KFloatingPointEditor3TextValue, "0" );
    _LIT( KFloatingPointEditor4TextValue, "0" );
    
    /**
     * Construct the CMyFirstUIForm instance
     * @param aCommandObserver command observer
     */ 
    CMyFirstUIForm::CMyFirstUIForm( MEikCommandObserver* aCommandObserver )
    	{
    	iCommandObserver = aCommandObserver;
    	iFloatingPointEditor1 = NULL;
    	iFloatingPointEditor2 = NULL;
    	iFloatingPointEditor3 = NULL;
    	iFloatingPointEditor4 = NULL;	
    	}
    
    CMyFirstUIForm* CMyFirstUIForm::NewL( MEikCommandObserver* aCommandObserver )
    	{
    	CMyFirstUIForm* self = CMyFirstUIForm::NewLC( aCommandObserver );
    	CleanupStack::Pop( self );
    	return self;
    	}
    
    /**
     *  Creates an instance and initializes it.
     *  Instance is left on cleanup stack.
     * @param aCommandObserver command observer
     * @return new instance of CMyFirstUIForm
     */
    CMyFirstUIForm* CMyFirstUIForm::NewLC( MEikCommandObserver* aCommandObserver )
    	{
    	CMyFirstUIForm* self = new ( ELeave ) CMyFirstUIForm( aCommandObserver );
    	CleanupStack::PushL( self );
    	self->ConstructL();
    	return self;
    	}
    			
    /** 
     * Handle key event (override)
     * @param aKeyEvent key event
     * @param aType event code
     * @return EKeyWasConsumed if the event was handled, else EKeyWasNotConsumed
     */
    TKeyResponse CMyFirstUIForm::OfferKeyEventL( 
    		const TKeyEvent& aKeyEvent, 
    		TEventCode aType )
    	{
    	// [[[ begin generated region: do not modify [Generated Contents]
    	// ]]] end generated region [Generated Contents]
    	
    	if ( ( aKeyEvent.iCode == EKeyLeftArrow 
    		|| aKeyEvent.iCode == EKeyRightArrow )
    		&& !IsEditable() )
    		{
    		// allow the tab control to get the arrow keys
    		return EKeyWasNotConsumed;
    		}
    	
    	return CAknForm::OfferKeyEventL( aKeyEvent, aType );
    	}
    
    /**
     * Called to handle "Save" menu item. Displays save query.
     * @return TBool ETrue if the form data is to be saved, EFalse otherwise
     */
    TBool CMyFirstUIForm::QuerySaveChangesL()
    	{
    	TBool isAnsYes( CAknForm::QuerySaveChangesL() );
    	
    	if ( isAnsYes )
    		{
    		SaveFormDataL();
    		}
    	else
    		{
    		DoNotSaveFormDataL();
    		}
    
    	return isAnsYes;
    	}
    
    /**
     * Called from QuerySaveChangesL when changes made to the form are to be saved.
     * @return TBool ETrue if the form data has been saved, EFalse otherwise
     */
    TBool CMyFirstUIForm::SaveFormDataL()
    	{
    	// TODO save values
    	return ETrue;
    	}
    
    /**
     * Called from QuerySaveChangesL when changes made to the form are discarded.
     */
    void CMyFirstUIForm::DoNotSaveFormDataL()
    	{
    	LoadFromDataL();
    	}
    
    /**
     * Called from DoNotSaveFormDataL when changes are cancelled.
     * Called from PreLayoutDynInitL to load initial values if needed.
     */
    void CMyFirstUIForm::LoadFromDataL()
    	{
    	// TODO load saved values	
    
    	}
    
    /**
     * Initialize controls and settings before a Form is laid out.  (override)
     */
    void CMyFirstUIForm::PreLayoutDynInitL()
    	{
    	// [[[ begin generated region: do not modify [Generated Contents]
    	iFloatingPointEditor1 = static_cast< CEikFloatingPointEditor* >( 
    		ControlOrNull( EMyFirstUIFormViewFloatingPointEditor1 ) );
    		{
    		TReal value = 0;
    		iFloatingPointEditor1->SetValueL( &value );
    		iFloatingPointEditor1->SetTextL( &KFloatingPointEditor1TextValue );
    		}
    	AddControlEventHandlerL( 
    			iFloatingPointEditor1, 
    			EEventStateChanged, 
    			&CMyFirstUIForm::HandleFloatingPointEditor1StateChangedL );
    	iFloatingPointEditor2 = static_cast< CEikFloatingPointEditor* >( 
    		ControlOrNull( EMyFirstUIFormViewFloatingPointEditor2 ) );
    		{
    		TReal value = 0;
    		iFloatingPointEditor2->SetValueL( &value );
    		iFloatingPointEditor2->SetTextL( &KFloatingPointEditor2TextValue );
    		}
    	iFloatingPointEditor3 = static_cast< CEikFloatingPointEditor* >( 
    		ControlOrNull( EMyFirstUIFormViewFloatingPointEditor3 ) );
    		{
    		TReal value = 0;
    		iFloatingPointEditor3->SetValueL( &value );
    		iFloatingPointEditor3->SetTextL( &KFloatingPointEditor3TextValue );
    		}
    	iFloatingPointEditor4 = static_cast< CEikFloatingPointEditor* >( 
    		ControlOrNull( EMyFirstUIFormViewFloatingPointEditor4 ) );
    		{
    		TReal value = 0;
    		iFloatingPointEditor4->SetValueL( &value );
    		iFloatingPointEditor4->SetTextL( &KFloatingPointEditor4TextValue );
    		}
    	// ]]] end generated region [Generated Contents]
    	
    	LoadFromDataL();
    	}
    				
    /**
     * Called when built-in menu is displayed.  (override)
     * CAknForm has a built-in menu. In view mode, the only menu item is "Edit" that switches the form to edit mode.
     * In edit mode, the items are "Add field" "Save" "Edit label" and "Delete field"
     * The code below removes all edit mode items except for "Save"
     * To use these items, remove the appropriate lines and override the appropriate CAknForm methods.
     * (E.g., to handle "Add field" remove the line for EAknFormCmdAdd and override CAknForm::AddItemL())
     */
    void CMyFirstUIForm::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
    	{
    	CAknForm::DynInitMenuPaneL( aResourceId, aMenuPane );
    	
    	if ( aResourceId == R_AVKON_FORM_MENUPANE )
    		{
    		aMenuPane->SetItemDimmed( EAknFormCmdAdd, ETrue );
    		aMenuPane->SetItemDimmed( EAknFormCmdLabel, ETrue );
    		aMenuPane->SetItemDimmed( EAknFormCmdDelete, ETrue );
    
    		/* 
    		// sample code to add a custom item with command id 'myCommandId'
    		TInt pos;
    		if ( !aMenuPane->MenuItemExists( myCommandId, pos ) )
    			{
    			CEikMenuPaneItem::SData menuItem;
    			menuItem.iCommandId = myCommandId;
    			menuItem.iCascadeId = 0;	// set for submenus
    			menuItem.iFlags = 0;		// e.g. EEikMenuItemDimmed
    			menuItem.iText = KMyCommandIdText;
    			menuItem.iExtraText = _L("");
    			aMenuPane->AddMenuItemL( menuItem );
    			}
    		*/
    		}
    	// [[[ begin generated region: do not modify [Generated Code]
    	
    	// ]]] end generated region [Generated Code]
    	
    	}
    				
    /**
     * Handle a button press and tell whether it closes the dialog.  (override)  
     * @param aButtonId the identifier for the button (avkon.hrh)
     */
    TBool CMyFirstUIForm::OkToExitL( TInt aButtonId )
    	{
    	// [[[ begin generated region: do not modify [Generated Code]
    	
    	if ( aButtonId == EAknSoftkeyBack )
    		{
    		if ( CAknForm::OkToExitL( EAknSoftkeyBack ) )
    			{
    			iAvkonAppUi->ProcessCommandL( EEikCmdExit );
    			}
    		else
    			{
    			return EFalse;
    			}
    		}
    	// ]]] end generated region [Generated Code]
    	
    	// The 'exit application on close' property automatically adds code to exit the 
    	// application when the right soft key is pressed. If this property is set to false, 
    	// and AddToStackL has been called on the Form object (e.g., it was not shown as a dialog), 
    	// code must be added manually to avoid a panic when exiting the application.
    	return CAknForm::OkToExitL( aButtonId );
    	}
    
    /** 
     * Override of the HandleEdwinEventL virtual function
     */
    void CMyFirstUIForm::HandleEdwinEventL( 
    		CEikEdwin* anEdwin, 
    		TEdwinEvent anEventType )
    	{
    	for (int i = 0; i < iEdwinEventDispatch.Count(); i++)
    		{
    		const TEdwinEventDispatch& currEntry = iEdwinEventDispatch[i];
    		if ( currEntry.src == anEdwin && currEntry.event == anEventType )
    			{
    			( this->*currEntry.handler )( anEdwin, anEventType );
    			break;
    			}
    		}
    	}
    
    /** 
     * Override of the HandleControlEventL virtual function
     */
    void CMyFirstUIForm::HandleControlEventL( 
    		CCoeControl* aControl, 
    		TCoeEvent anEventType )
    	{
    	CAknForm::HandleControlEventL( aControl, anEventType );
    
    	for (int i = 0; i < iControlEventDispatch.Count(); i++)
    		{
    		const TControlEventDispatch& currEntry = iControlEventDispatch[i];
    		if ( currEntry.src == aControl && currEntry.event == anEventType )
    			{
    			( this->*currEntry.handler )( aControl, anEventType );
    			break;
    			}
    		}
    	}
    
    /** 
     * Handle the EEventStateChanged event.
     */
    void CMyFirstUIForm::HandleFloatingPointEditor1StateChangedL( 
    		CCoeControl* /* aControl */, 
    		TCoeEvent /* anEvent */ )
    	{
    	// TODO: implement stateChanged event handler
    	
    	HBufC *text = NULL;
    	 
    	text = iFloatingPointEditor1->GetTextInHBufL();
    	 
    	if ((text != NULL) && (text->Length() > 0))
    	{
    		// There is some text, do what you want with it	
    		
    		iFloatingPointEditor2->SetTextL(text);
    		iFloatingPointEditor2->DrawNow();
    		
    		iFloatingPointEditor3->SetTextL(text);
    		iFloatingPointEditor3->DrawNow();
    		
    		iFloatingPointEditor4->SetTextL(text);
    		iFloatingPointEditor4->DrawNow();
    	}
    	 
    	// Don't forget to delete the object afterwards!
    	delete text;
    	}

    So, how to do this?

    I am using Carbide.c++ v1.2 Professional Edition with S60 2nd Edition FP2 SDK. I am using the old version of Carbide.c++ because it supports the old 2nd Edition (v8.0a) SDK.


    Thanks in advance,
    Salan

  2. #2
    Regular Contributor
    Join Date
    May 2008
    Location
    Budapest, Hungary
    Posts
    84

    Re: How to Override the Menu Options in the UI Form View

    For changing the menu items, check out the generated DynInitMenuPaneL method. There's even a sample of how to create your own item. I'm not sure how you can hide the Save item though.

    You can change the softkey labels (and associated commands) in the .RSS file of your application. There's a structure for that, look for R_AVKON_SOFTKEYS_OPTIONS_BACK. Changing it to R_AVKON_SOFTKEYS_OPTIONS_EXIT will switch your right softkey to Exit.

  3. #3
    Registered User
    Join Date
    May 2007
    Location
    Poland
    Posts
    606

    Re: How to Override the Menu Options in the UI Form View

    and HandleCommandL of CAknView class function should help you in Handling commands for this view

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    41

    Re: How to Override the Menu Options in the UI Form View

    Quote Originally Posted by VaradiZsolt View Post
    For changing the menu items, check out the generated DynInitMenuPaneL method. There's even a sample of how to create your own item. I'm not sure how you can hide the Save item though.

    You can change the softkey labels (and associated commands) in the .RSS file of your application. There's a structure for that, look for R_AVKON_SOFTKEYS_OPTIONS_BACK. Changing it to R_AVKON_SOFTKEYS_OPTIONS_EXIT will switch your right softkey to Exit.
    Ok, I have changed the "R_AVKON_SOFTKEYS_OPTIONS_BACK" to "R_AVKON_SOFTKEYS_OPTIONS_EXIT" and the "Back" text became as "Exit". But the problem is that the "Exit" itself is not working (can't exit from the application when I press the right soft key)!!!

  5. #5
    Regular Contributor
    Join Date
    May 2008
    Location
    Budapest, Hungary
    Posts
    84

    Re: How to Override the Menu Options in the UI Form View

    Quote Originally Posted by salanalani View Post
    Ok, I have changed the "R_AVKON_SOFTKEYS_OPTIONS_BACK" to "R_AVKON_SOFTKEYS_OPTIONS_EXIT" and the "Back" text became as "Exit". But the problem is that the "Exit" itself is not working (can't exit from the application when I press the right soft key)!!!
    You still have to handle the generated EAknCmdExit command manually.

    Here's an example:

    Code:
    void CMyAppUi::HandleCommandL(TInt aCommand)
        {
        switch(aCommand)
            {
            ...
            case EAknCmdExit:
               Exit();
               break;
            }
        }

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    41

    Re: How to Override the Menu Options in the UI Form View

    How about the "Save" option? Can we remove it? If not, then what shall I do? Shall I create a new project with empty "Container"?

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    41

    Re: How to Override the Menu Options in the UI Form View

    Quote Originally Posted by salanalani View Post
    How about the "Save" option? Can we remove it? If not, then what shall I do? Shall I create a new project with empty "Container"?
    Or at least to rename it...

  8. #8
    Registered User
    Join Date
    Mar 2009
    Posts
    41

    Thumbs up Re: How to Override the Menu Options in the UI Form View

    Ok, I solved it; you just have to update the "DynInitMenuPaneL" function to be like this:

    Code:
    void CMyFirstUIForm::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
    	{
    	CAknForm::DynInitMenuPaneL( aResourceId, aMenuPane );
    	
    	if ( aResourceId == R_AVKON_FORM_MENUPANE )
    		{
    		aMenuPane->SetItemDimmed( EAknFormCmdAdd, ETrue );
    		aMenuPane->SetItemDimmed( EAknFormCmdLabel, ETrue );
    		aMenuPane->SetItemDimmed( EAknFormCmdDelete, ETrue );
    		aMenuPane->SetItemDimmed( EAknFormCmdSave, ETrue ); // This is the added code
    		}

    Thanks for the help...

  9. #9
    Registered User
    Join Date
    Mar 2009
    Posts
    41

    Exclamation Re: How to Override the Menu Options in the UI Form View

    Quote Originally Posted by VaradiZsolt View Post
    For changing the menu items, check out the generated DynInitMenuPaneL method. There's even a sample of how to create your own item. I'm not sure how you can hide the Save item though.

    You can change the softkey labels (and associated commands) in the .RSS file of your application. There's a structure for that, look for R_AVKON_SOFTKEYS_OPTIONS_BACK. Changing it to R_AVKON_SOFTKEYS_OPTIONS_EXIT will switch your right softkey to Exit.

    I failed to create a custom menu item, can you please help? Below is the code I did in the "DynInitMenuPaneL" method:

    Code:
    TInt pos;
    		if ( !aMenuPane->MenuItemExists( TMyFirstUIViewExitMenuItemCommand, pos ) )
    			{
    			_LIT( KTMyFirstUIViewExitMenuItemCommand, "Exit" );
    			CEikMenuPaneItem::SData menuItem;
    			menuItem.iCommandId = TMyFirstUIViewExitMenuItemCommand;
    			menuItem.iCascadeId = 0;	// set for submenus
    			menuItem.iFlags = EEikMenuItemDimmed;		// e.g. EEikMenuItemDimmed
    			menuItem.iText = KTMyFirstUIViewExitMenuItemCommand;
    			menuItem.iExtraText = _L("");
    			aMenuPane->AddMenuItemL( menuItem );
    The problem that the custom menu item is not appearing!!!

    Also when I put anything on the iExtraText parameter, like:

    Code:
    menuItem.iExtraText = _L("Exit");
    The application will through an error when pressing the Option key!!!

    Please tell me if I have to do something out of the Form.cpp file. The only thing I did is putting the following code in the .hrh file:

    Code:
    enum TMyFirstUIViewMenuItems
    	{
    	TMyFirstUIViewExitMenuItemCommand = 0x6000
    	};

    Thanks in advance,
    Salan

  10. #10
    Super Contributor
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,037

    Re: How to Override the Menu Options in the UI Form View

    Hi Salan,

    Did you try to debug your code? where are you reaching in the if condition? you code seems looks fine.

    Please try to debug it.

  11. #11
    Registered User
    Join Date
    Mar 2009
    Posts
    41

    Re: How to Override the Menu Options in the UI Form View

    I did debug and put also a breakpoint inside the if condition, the debug will hit the breakpoint when I press the Option key. But my Exit custom menu item is not appearing on the Option menu???

    Also, what is the "iExtraText" parameter will do? Because whenever I assigned a value to it the debug will through an error?

    And shall I put a value for the TInt "pos" variable??

Similar Threads

  1. Switvhing from Form to other view
    By songoku83 in forum Symbian User Interface
    Replies: 5
    Last Post: 2012-04-08, 23:11
  2. Touch UI and pop-up menu options
    By nicholso in forum Mobile Java General
    Replies: 2
    Last Post: 2009-12-22, 10:56
  3. Adding Menu pane to the form
    By Saritha Reddy in forum Symbian User Interface
    Replies: 13
    Last Post: 2008-03-17, 13:07
  4. Menu in Form Run-time Error
    By mubx2000 in forum Symbian User Interface
    Replies: 52
    Last Post: 2007-04-25, 12:24
  5. How to add a menu item in the Options menu of a Nokia 7650 ?
    By nmittal in forum Symbian User Interface
    Replies: 1
    Last Post: 2002-08-07, 08:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •