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

Reply With Quote




