extras/calcsoft/src/CalcView.cpp
branchRCL_3
changeset 21 10c6e6d6e4d9
equal deleted inserted replaced
20:41b775cdc0c8 21:10c6e6d6e4d9
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CCalcView is a view class of Calculator application.
       
    15 *                Base class of CCalcView is CAknView. 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <avkon.hrh>
       
    23 #include <eikon.hrh>
       
    24 #include <eikmenup.h>
       
    25 #include <aknnotewrappers.h> 
       
    26 #include <AiwServiceHandler.h>
       
    27 
       
    28 #include <aknbutton.h>
       
    29 
       
    30 #include <hlplch.h>   // For HlpLauncher 
       
    31 #include <featmgr.h>      // Feature Manager
       
    32 
       
    33 #include <Calcsoft.rsg>
       
    34 
       
    35 #include "CalcView.h"
       
    36 #include "CalcCont.h" 
       
    37 #include "CalcEdit.h"
       
    38 #include "CalcAppUi.h"
       
    39 #include "CalcDoc.h"
       
    40 #include "CalcHistory.h"
       
    41 #include "CalcOutSheet.h"
       
    42 #include "CalcFunc.h"
       
    43 #include "CalcEnv.h"
       
    44 #include "calc.hrh" 
       
    45 #include "CalcEditline.h"
       
    46 
       
    47 //#include    "CalcCmdBtn.h"
       
    48 
       
    49 #include <layoutmetadata.cdl.h>
       
    50 #include <AiwMenu.h>
       
    51 #include <AiwCommon.h>
       
    52 
       
    53 
       
    54 //  LOCAL CONSTANTS AND MACROS  
       
    55 
       
    56 
       
    57 // ================= MEMBER FUNCTIONS =======================
       
    58 
       
    59 
       
    60 // Two-phased constructor.
       
    61 CCalcView* CCalcView::NewLC()
       
    62     {
       
    63     CCalcView* self = new (ELeave) CCalcView();
       
    64     CleanupStack::PushL(self);
       
    65     self->ConstructL();
       
    66     return self;
       
    67     }
       
    68   
       
    69   // default constructor can leave.
       
    70 void CCalcView::ConstructL()
       
    71     {
       
    72     
       
    73     BaseConstructL(R_CALC_VIEW_INFO);
       
    74     
       
    75     iCalcDocument = STATIC_CAST(CCalcDocument*, AppUi()->Document());
       
    76 
       
    77     iCalcDocument->SetCalcView( this );
       
    78 
       
    79     iCalcDocument->LoadStateL();
       
    80    
       
    81     /******** Initialize the ServiceHandler in the ConstructL *****/
       
    82     
       
    83     iServiceHandler = CAiwServiceHandler::NewL();
       
    84     
       
    85     /***** Attach the Menu Items of the Calculator and also the Interest *****/
       
    86     
       
    87     iServiceHandler->AttachMenuL(R_CALC_POPUPMENU, R_AIWHELPAPP_INTEREST);
       
    88     
       
    89     this->iLastResultSetected = EFalse;
       
    90     }
       
    91 
       
    92 // Destructor
       
    93 CCalcView::~CCalcView()
       
    94     {
       
    95     if ( iContainer )
       
    96         {
       
    97         delete iContainer;
       
    98         iContainer = NULL;
       
    99         }
       
   100 
       
   101     if( iServiceHandler )
       
   102         {
       
   103         delete iServiceHandler;
       
   104         iServiceHandler = NULL;
       
   105         }
       
   106      
       
   107      }
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CCalcView::State
       
   111 // Return current state
       
   112 // (other items were commented in a header).
       
   113 // ---------------------------------------------------------
       
   114 //
       
   115 CCalcView::TStateNo CCalcView::State() const
       
   116     {
       
   117     return iState;
       
   118     }
       
   119 
       
   120 // ----------------------------------------------------
       
   121 // CCalcView::LatestInput
       
   122 // Return type of latest input
       
   123 // (other items were commented in a header).
       
   124 // ----------------------------------------------------
       
   125 //
       
   126 CCalcView::TKindOfInput CCalcView::LatestInput() const
       
   127     {
       
   128     return iLatestInput;
       
   129     }
       
   130 
       
   131 // ----------------------------------------------------
       
   132 // CCalcView::UpdateState
       
   133 // Update state by using kind of input
       
   134 // (other items were commented in a header).
       
   135 // ----------------------------------------------------
       
   136 //
       
   137 void CCalcView::UpdateState
       
   138         (const TKindOfInput& aKind)   
       
   139     {
       
   140     iLatestInput = aKind;
       
   141     
       
   142     switch (aKind)
       
   143        {
       
   144         case EOperand:
       
   145         case EMemoryRecall:
       
   146             {
       
   147             switch (iState)
       
   148                 {
       
   149                 case EInitialMode: 
       
   150                 case ESelectResult:
       
   151                     iState = EOperandOnly;
       
   152                     break;
       
   153                 case EOperandAndOperator:
       
   154                     iState = EOperandAndOperatorAndOperand;
       
   155                     break;
       
   156                 default:
       
   157                     break;
       
   158                 }
       
   159             break;
       
   160             }
       
   161         case EOperatorResult:
       
   162             {
       
   163             iState = EOperatorOnlyResult;
       
   164             break;
       
   165             }
       
   166         case EOperator:
       
   167             {
       
   168             iState = EOperandAndOperator;
       
   169             break;
       
   170             }
       
   171         case EEqual:
       
   172             {
       
   173             iState = ESelectResult;
       
   174             break;
       
   175             }
       
   176         case EMemorySave:
       
   177             {
       
   178             switch (iState)
       
   179                 {
       
   180                 case EOperandAndOperatorAndOperand:
       
   181                     iState = ESelectResult;
       
   182                     break;
       
   183                 case ESelectResult:
       
   184                     iState = EOperandOnly;
       
   185                     break;
       
   186                 default:
       
   187                     break;
       
   188                 }
       
   189             break;
       
   190             }
       
   191         case EAllClear:
       
   192             {
       
   193             iState = EOperandOnly;
       
   194             break;
       
   195             }
       
   196         default:
       
   197             {
       
   198             break;
       
   199             }
       
   200         }
       
   201     }
       
   202 
       
   203 
       
   204 // ----------------------------------------------------
       
   205 // CCalcView::ErrorMsgL
       
   206 // Display error message
       
   207 // (other items were commented in a header).
       
   208 // ----------------------------------------------------
       
   209 //
       
   210 void CCalcView::ErrorMsgL
       
   211         (TInt aErrorCode) 
       
   212     {
       
   213     TInt resourceId(0);
       
   214 
       
   215     switch (aErrorCode)
       
   216         {
       
   217         case KErrOverflow:
       
   218             {
       
   219             resourceId = R_CALC_ERROR_OUTOFRANGE;
       
   220             break;
       
   221             }
       
   222         case KErrDivideByZero:
       
   223             {
       
   224             resourceId = R_CALC_ERROR_DIVISIONBYZERO;
       
   225 
       
   226              // UpdateState( EOperator );
       
   227             break;
       
   228             }
       
   229         case KErrNotSupported:
       
   230             {
       
   231             resourceId = R_CALC_ERROR_NEGATIVEVALUESQRT;
       
   232             break;
       
   233             }
       
   234         default:
       
   235             {
       
   236             return;
       
   237             }
       
   238         }
       
   239     
       
   240     //Localisation of scalable UI.
       
   241     HBufC* message = iCoeEnv->AllocReadResourceLC(resourceId) ;
       
   242     CAknErrorNote* note = new (ELeave) CAknErrorNote();
       
   243     note->ExecuteLD(*message);
       
   244     CleanupStack::PopAndDestroy(message);
       
   245     
       
   246     }
       
   247 
       
   248 
       
   249 // ----------------------------------------------------
       
   250 // CCalcView::DynInitMainMenuPane
       
   251 // Delete meaningless items from main menu.
       
   252 // (other items were commented in a header).
       
   253 // ----------------------------------------------------
       
   254 //
       
   255 void CCalcView::DynInitMainMenuPane    
       
   256               (CEikMenuPane* aMenuPane) 
       
   257     {
       
   258     
       
   259             
       
   260 
       
   261     switch (iState)
       
   262         {
       
   263         case ESelectResult:
       
   264             {
       
   265             aMenuPane->DeleteMenuItem(ECalcCmdLastResult);
       
   266             break;
       
   267             }
       
   268         case EInitialMode:
       
   269             {
       
   270             aMenuPane->DeleteMenuItem(ECalcCmdClearCalcAndHistory);
       
   271             break;
       
   272             }
       
   273         case EOperandOnly:
       
   274             {
       
   275             if (iCalcDocument->History()->Count() == 0)
       
   276                 {
       
   277                 aMenuPane->DeleteMenuItem(ECalcCmdClearCalcAndHistory);
       
   278                 }
       
   279              if(iLastResultSetected)
       
   280                  {
       
   281                 aMenuPane->DeleteMenuItem(ECalcCmdLastResult);     
       
   282                  }
       
   283             break;
       
   284             }
       
   285         case EOperandAndOperator:
       
   286         case EOperandAndOperatorAndOperand:
       
   287              if(iLastResultSetected)
       
   288                  {
       
   289                 aMenuPane->DeleteMenuItem(ECalcCmdLastResult);     
       
   290                  }
       
   291             break;      
       
   292         default:
       
   293             {
       
   294             break;
       
   295             }
       
   296         }
       
   297     }                        
       
   298 
       
   299 
       
   300 // ----------------------------------------------------
       
   301 // CCalcView::DynInitMemoryMenuPane
       
   302 // Delete meaningless items from menu of memory 
       
   303 // (other items were commented in a header).
       
   304 // ----------------------------------------------------
       
   305 //
       
   306 void CCalcView::DynInitMemoryMenuPane
       
   307         (CEikMenuPane* aMenuPane)
       
   308     {
       
   309     if (!iCalcDocument->HasMemory())
       
   310         {
       
   311         aMenuPane->DeleteMenuItem(ECalcCmdMemoryClear);
       
   312         }    
       
   313     }
       
   314     
       
   315 // ---------------------------------------------------------
       
   316 // CCalcView::NotifyChangeDecimal
       
   317 // Call when decimal separator is changed.
       
   318 // (other items were commented in a header).
       
   319 // ---------------------------------------------------------
       
   320 //
       
   321 void CCalcView::NotifyChangeDecimal(TChar aOld, TChar aNew)
       
   322     {
       
   323     iContainer->NotifyChangeDecimal(aOld, aNew);
       
   324     }
       
   325     
       
   326 
       
   327 
       
   328 // ---------------------------------------------------------
       
   329 // CCalcView::HandleCommandL
       
   330 // Handling command.
       
   331 // (other items were commented in a header).
       
   332 // ---------------------------------------------------------
       
   333 //
       
   334 void CCalcView::HandleCommandL
       
   335         ( TInt aCommand ) 
       
   336     {
       
   337     // Handle the command generated by:
       
   338     //   1. menu item selection
       
   339     //   2. short-cut key press
       
   340    
       
   341     switch ( aCommand )
       
   342         {
       
   343         case ECalcCmdResult:
       
   344             {
       
   345             HandleResultL();
       
   346             break;
       
   347             }
       
   348         case ECalcCmdAdd:
       
   349             {
       
   350             HandleOperatorL(TCalcEditLine::ECalcAdd);
       
   351             break;
       
   352             }
       
   353         case ECalcCmdSubtract:
       
   354             {
       
   355             HandleOperatorL(TCalcEditLine::ECalcSubtract);
       
   356             break;
       
   357             }
       
   358         case ECalcCmdMultiply:
       
   359             {
       
   360             HandleOperatorL(TCalcEditLine::ECalcMultiply);
       
   361             break;
       
   362             }
       
   363         case ECalcCmdDivide:
       
   364             {
       
   365             HandleOperatorL(TCalcEditLine::ECalcDivide);
       
   366             break;
       
   367             }
       
   368         case ECalcCmdChangeSign:
       
   369             {
       
   370             this->iLastResultSetected = EFalse;
       
   371             HandleChangeSignL();
       
   372             break;
       
   373             }
       
   374         case ECalcCmdLastResult:
       
   375             {
       
   376             HandleLastResultL();
       
   377             break;
       
   378             }
       
   379         case ECalcCmdPercent:
       
   380             {
       
   381             HandleOperatorL(TCalcEditLine::ECalcPercent);
       
   382             // The result is always is displayed
       
   383             // after the percent button is pressed.
       
   384             // But if there was a error in the calculation
       
   385             // this if will enable us to not call the
       
   386             // HandleResultL and thus making sure that
       
   387             // the state of the buttons is identical to the
       
   388             // situation before the calculation.
       
   389             if (iState == EOperatorOnlyResult)
       
   390                 HandleResultL();
       
   391             break;
       
   392             }
       
   393         case ECalcCmdSqrt:
       
   394             {
       
   395 //            TRequestStatus trs;
       
   396 //            RTimer timer;
       
   397 //            timer.CreateLocal();
       
   398 //            timer.After(trs, 1000*2);
       
   399 //            while ( trs == KRequestPending) {
       
   400 //                  User::WaitForAnyRequest();
       
   401 //            }
       
   402 //            timer.Cancel();
       
   403 //            timer.Close();
       
   404             HandleOperatorL(TCalcEditLine::ECalcSqrt);
       
   405             // HandleResultL only if sqrt was pressed after single operand.
       
   406             if (iState == EOperatorOnlyResult)
       
   407                 HandleResultL();
       
   408 
       
   409             break;
       
   410             }
       
   411         case ECalcCmdMemorySave:
       
   412             {
       
   413             HandleMemorySaveL();
       
   414             break;
       
   415             }
       
   416         case ECalcCmdMemoryRecall:
       
   417             {
       
   418             this->iLastResultSetected = EFalse;
       
   419             HandleMemoryRecallL();
       
   420             break;
       
   421             }
       
   422         case ECalcCmdMemoryClear:
       
   423             {
       
   424             HandleMemoryClearL();
       
   425             break;
       
   426             }
       
   427         case ECalcCmdScrollUp:
       
   428             {
       
   429             HandleScrollUp();
       
   430             break;
       
   431             }
       
   432         case ECalcCmdScrollDown:
       
   433             {
       
   434             HandleScrollDown();
       
   435             break;
       
   436             }
       
   437         case ECalcCmdClearCalcAndHistory:
       
   438             {
       
   439             DoClearCalcAndHistoryL();
       
   440             break;
       
   441             }
       
   442         case EAknSoftkeyExit:
       
   443         case EEikCmdExit:
       
   444             {
       
   445             STATIC_CAST(CCalcAppUi*, AppUi())->ExitCalculator();
       
   446             break;
       
   447             }
       
   448         case ECalcCmdHelp: 
       
   449             {
       
   450             if (FeatureManager::FeatureSupported( KFeatureIdHelp ))
       
   451                 {
       
   452                 HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), AppUi()->AppHelpContextL());
       
   453                 }
       
   454             break;
       
   455             }
       
   456         case EAknSoftkeySelect:
       
   457             {
       
   458             iContainer->HandleMiddleSoftKey();
       
   459             break;
       
   460             }
       
   461             
       
   462         //Below cases are possible only for Touch UI Layouts
       
   463         case ECalcCmdOne:
       
   464             {
       
   465             iContainer->SetOperatorFromTouchL(1);
       
   466             }
       
   467             break;
       
   468         case ECalcCmdTwo:
       
   469             {
       
   470             iContainer->SetOperatorFromTouchL(2);
       
   471             }
       
   472             break;
       
   473         case ECalcCmdThree:
       
   474             {
       
   475             iContainer->SetOperatorFromTouchL(3);
       
   476             }
       
   477             break;
       
   478         case ECalcCmdFour:
       
   479             {
       
   480             iContainer->SetOperatorFromTouchL(4);
       
   481             }
       
   482             break;
       
   483         case ECalcCmdFive:
       
   484             {
       
   485             iContainer->SetOperatorFromTouchL(5);
       
   486             }
       
   487             break;
       
   488         case ECalcCmdSix:
       
   489             {
       
   490             iContainer->SetOperatorFromTouchL(6);
       
   491             }
       
   492             break;
       
   493         case ECalcCmdSeven:
       
   494             {
       
   495             iContainer->SetOperatorFromTouchL(7);
       
   496             }
       
   497             break;
       
   498         
       
   499         case ECalcCmdEight:
       
   500             {
       
   501             iContainer->SetOperatorFromTouchL(8);
       
   502             }
       
   503             break;
       
   504         
       
   505         case ECalcCmdNine:
       
   506             {
       
   507             iContainer->SetOperatorFromTouchL(9);
       
   508             }
       
   509             break;
       
   510         
       
   511         case ECalcCmdZero:
       
   512             {
       
   513             iContainer->SetOperatorFromTouchL(0);
       
   514             }
       
   515             break;
       
   516             
       
   517         case ECalcCmdSeparator:
       
   518             {
       
   519             iContainer->SetSeparatorFromTouchL();
       
   520             }
       
   521             break;
       
   522         case ECalcCmdCancel:
       
   523             {
       
   524             TInt repeat( iContainer->FuncmapSubPane()->IsKeyLongPressed() );           
       
   525             iContainer->ClearInputKeyL( repeat );
       
   526             }
       
   527             break; 
       
   528             
       
   529     /****** If none of the cases handle the Aiw Help then it will come to the default case ****/
       
   530         default:
       
   531             {
       
   532                  CArrayFix<TCoeHelpContext>* buf = AppUi()->AppHelpContextL();
       
   533                  TCoeHelpContext& helpContext = buf->At(0);         
       
   534                    TAiwVariant uidVariant;
       
   535                  TAiwVariant contextVariant;         
       
   536                  uidVariant.Set(helpContext.iMajor);         
       
   537                  TAiwGenericParam uidParam(EGenericParamHelpItem, uidVariant);                          contextVariant.Set(helpContext.iContext);         
       
   538                  contextVariant.Set(helpContext.iContext);         
       
   539                  TAiwGenericParam contextParam(EGenericParamHelpItem, contextVariant);     
       
   540                  CAiwGenericParamList* list = CAiwGenericParamList::NewLC();         
       
   541                  list->AppendL(uidParam);
       
   542                  list->AppendL(contextParam); 
       
   543                  iServiceHandler->ExecuteMenuCmdL(aCommand,*list,iServiceHandler->OutParamListL());     
       
   544                  CleanupStack::PopAndDestroy(list);
       
   545                  delete buf;
       
   546                  buf= NULL;
       
   547             break;
       
   548             }
       
   549         }
       
   550     }
       
   551 
       
   552 
       
   553 // C++ default constructor can NOT contain any code, that
       
   554 // might leave.
       
   555 //
       
   556 CCalcView::CCalcView():
       
   557            iState(EInitialMode),
       
   558            iLatestInput(EOperand)
       
   559     {
       
   560     }
       
   561 
       
   562 
       
   563 // ---------------------------------------------------------
       
   564 // CCalcView::CreateContainerL
       
   565 // Create CCalcContainer class
       
   566 // (other items were commented in a header).
       
   567 // ---------------------------------------------------------
       
   568 //
       
   569 void CCalcView::CreateContainerL()
       
   570     {
       
   571     iContainer = CCalcContainer::NewL(this);
       
   572     
       
   573     iContainer->SetMopParent(this);
       
   574         
       
   575     TRect mainPaneRect ;
       
   576     TRect statusPaneRect;
       
   577     
       
   578     if (Layout_Meta_Data::IsLandscapeOrientation())
       
   579       
       
   580       {
       
   581       
       
   582         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainPaneRect);
       
   583         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStatusPane,statusPaneRect);
       
   584         mainPaneRect.iTl= statusPaneRect.iTl;
       
   585           
       
   586       }
       
   587       
       
   588       else
       
   589       
       
   590       {
       
   591       
       
   592         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainPaneRect);
       
   593         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStatusPane,statusPaneRect);
       
   594        
       
   595        mainPaneRect.iTl= statusPaneRect.iTl;
       
   596                                                 
       
   597       } 
       
   598     
       
   599     
       
   600     iContainer->SetRect(mainPaneRect);    
       
   601     iEditorSubPane = iContainer->EditorPane();
       
   602     iOutputSheet = iContainer->OutputSheet();
       
   603     }
       
   604 
       
   605 
       
   606 // ---------------------------------------------------------
       
   607 // CCalcView::HandleResultL
       
   608 // Handle result command
       
   609 // (other items were commented in a header).
       
   610 // ---------------------------------------------------------
       
   611 //
       
   612 void CCalcView::HandleResultL()
       
   613     {
       
   614     if (!HandleEqualSubRoutineL())
       
   615         {
       
   616         iEditorSubPane->DrawNow();
       
   617         UpdateState(EEqual);
       
   618 
       
   619         iContainer->SetSqrtEnableL();
       
   620         iContainer->ShowPercentButton(EFalse);
       
   621         iContainer->SetClearKeyEnable();             
       
   622         }
       
   623     }
       
   624 
       
   625 
       
   626 // ---------------------------------------------------------
       
   627 // CCalcView::HandleChangeSignL
       
   628 // Handle ChangeSign command
       
   629 // (other items were commented in a header).
       
   630 // ---------------------------------------------------------
       
   631 //
       
   632 void CCalcView::HandleChangeSignL()
       
   633     {
       
   634     iEditorSubPane->DoChangeSignL(iState);        
       
   635     
       
   636     if (iState == CCalcView::EOperandAndOperator)
       
   637         {
       
   638         UpdateState(EMemoryRecall);
       
   639         }
       
   640     }
       
   641 
       
   642 // ---------------------------------------------------------
       
   643 // CCalcView::HandleLastResultL
       
   644 // Handle LastResult command
       
   645 // (other items were commented in a header).
       
   646 // ---------------------------------------------------------
       
   647 //
       
   648 void CCalcView::HandleLastResultL()
       
   649     {
       
   650     iLastResultSetected = ETrue;
       
   651     //  Recall "LastResult", which is the answer based on latest "=" input.
       
   652     iEditorSubPane->DoMemoryRecallOrLastResult(
       
   653         iCalcDocument->LastResult(), iState);
       
   654 
       
   655     UpdateState(EMemoryRecall);
       
   656     if ( iState == EOperandOnly && 
       
   657          iEditorSubPane->EditLine().CheckZeroL() )
       
   658         {
       
   659         UpdateState(EAllClear);
       
   660         }
       
   661     iContainer->SetChangeSignEnableL();
       
   662     iContainer->SetSqrtEnableL();
       
   663     iContainer->SetClearKeyEnable(); 
       
   664 
       
   665     //highlighting the sign "%".
       
   666     if ( iState == EOperandAndOperatorAndOperand )
       
   667         {
       
   668         iContainer->SetPercentEnableL();
       
   669         }        
       
   670     }
       
   671 
       
   672 // ---------------------------------------------------------
       
   673 // CCalcView::HandleMemorySaveL
       
   674 // Handle MemorySave command
       
   675 // (other items were commented in a header).
       
   676 // ---------------------------------------------------------
       
   677 //
       
   678 void CCalcView::HandleMemorySaveL()
       
   679     {
       
   680     CCalcView::TKindOfInput kindOfInput(CCalcView::EMemorySave);
       
   681     
       
   682     if (iState == EOperandAndOperatorAndOperand)
       
   683         {
       
   684         if (HandleEqualSubRoutineL()) // Calculate result
       
   685             {
       
   686             return;
       
   687             }
       
   688         }
       
   689     else
       
   690         {
       
   691         if (iState == ESelectResult)
       
   692             {
       
   693             iCalcDocument->AddEmptyLine();
       
   694             iOutputSheet->ScrollToBottomL();
       
   695             iContainer->ScrollArrowUpdate();
       
   696             iEditorSubPane->SetOperator(TCalcEditLine::ECalcOperatorNone);
       
   697             
       
   698             if (iEditorSubPane->EditLine().CheckZeroL())
       
   699                 {
       
   700                 kindOfInput = CCalcView::EAllClear;
       
   701                 }
       
   702             }
       
   703         }
       
   704     iCalcDocument->MemorySaveL(iEditorSubPane->EditorNumber());
       
   705     iEditorSubPane->DrawNow();
       
   706     UpdateState(kindOfInput);
       
   707     iContainer->SetChangeSignEnableL();
       
   708     iContainer->SetSqrtEnableL();
       
   709     }
       
   710 
       
   711 // ---------------------------------------------------------
       
   712 // CCalcView::HandleMemoryRecallL
       
   713 // Handle MemoryRecall command
       
   714 // (other items were commented in a header).
       
   715 // ---------------------------------------------------------
       
   716 //
       
   717 void CCalcView::HandleMemoryRecallL()
       
   718     {
       
   719     iEditorSubPane->DoMemoryRecallOrLastResult(
       
   720         iCalcDocument->Memory(), iState );
       
   721 
       
   722     if ( iState == ESelectResult )
       
   723         {
       
   724         iCalcDocument->AddEmptyLine();
       
   725         iOutputSheet->ScrollToBottomL();
       
   726         iContainer->ScrollArrowUpdate();
       
   727         }
       
   728         
       
   729     UpdateState( EMemoryRecall );
       
   730     if ( iState == EOperandOnly && 
       
   731          iEditorSubPane->EditLine().CheckZeroL() )
       
   732         {
       
   733         UpdateState( EAllClear );
       
   734         }
       
   735 
       
   736     iContainer->SetChangeSignEnableL();
       
   737     iContainer->SetSqrtEnableL();
       
   738 
       
   739     iContainer->SetClearKeyEnable();
       
   740 
       
   741     // highlighting the sign "%".
       
   742     if ( iState == EOperandAndOperatorAndOperand )
       
   743         {
       
   744         iContainer->SetPercentEnableL();
       
   745         }        
       
   746     }
       
   747 
       
   748 // ---------------------------------------------------------
       
   749 // CCalcView::HandleMemoryClear
       
   750 // Handle MemoryClear command
       
   751 // (other items were commented in a header).
       
   752 // ---------------------------------------------------------
       
   753 // 
       
   754 
       
   755 void CCalcView::HandleMemoryClearL()
       
   756     {
       
   757     iCalcDocument->MemoryClearL();
       
   758     iEditorSubPane->DrawNow();
       
   759     }
       
   760 
       
   761 // ---------------------------------------------------------
       
   762 // CCalcView::HandleScrollUp
       
   763 // Handle Scroll up button command
       
   764 // (other items were commented in a header).
       
   765 // ---------------------------------------------------------
       
   766 //
       
   767 void CCalcView::HandleScrollUp()
       
   768     {
       
   769     iOutputSheet->ScrollUp();
       
   770     iContainer->ScrollArrowUpdate();
       
   771     }
       
   772 
       
   773 // ---------------------------------------------------------
       
   774 // CCalcView::HandleScrollDown
       
   775 // Handle Scroll down button command
       
   776 // (other items were commented in a header).
       
   777 // ---------------------------------------------------------
       
   778 //
       
   779 void CCalcView::HandleScrollDown()
       
   780     {
       
   781     iOutputSheet->ScrollDown();
       
   782     iContainer->ScrollArrowUpdate();
       
   783     }
       
   784 
       
   785 // ---------------------------------------------------------
       
   786 // CCalcView::DoClearCalcAndHistoryL
       
   787 // Clear calculation history and clear calculation.
       
   788 // (other items were commented in a header).
       
   789 // ---------------------------------------------------------
       
   790 //
       
   791 void CCalcView::DoClearCalcAndHistoryL()
       
   792     {
       
   793     iCalcDocument->History()->ClearHistory();
       
   794     iOutputSheet->NotifyClearHistoryL();
       
   795     iContainer->ScrollArrowUpdate();
       
   796     // Clear calculation
       
   797     TKeyEvent keyEvent;
       
   798     keyEvent.iCode = EKeyBackspace;
       
   799     keyEvent.iRepeats = 1; 
       
   800     iEditorSubPane->OfferKeyEventL(keyEvent, EEventKey);
       
   801     iContainer->ShowPercentButton(EFalse);
       
   802     }
       
   803         
       
   804 
       
   805 // ---------------------------------------------------------
       
   806 // CCalcView::HandleOperatorL
       
   807 // Operator Handler common routin.
       
   808 // (other items were commented in a header).
       
   809 // ---------------------------------------------------------
       
   810 //
       
   811 void CCalcView::HandleOperatorL
       
   812         (TCalcEditLine::TCalcOperatorType aOperator) 
       
   813     {
       
   814     TCalcEditLine editLine(iEditorSubPane->EditLine());
       
   815     TReal64 editorNumber(iEditorSubPane->EditorNumber());
       
   816     TReal64 result(editorNumber);
       
   817 
       
   818     this->iLastResultSetected = EFalse;
       
   819     // User has pressed %
       
   820     if (aOperator == TCalcEditLine::ECalcPercent)
       
   821         {    
       
   822         if (iState == EOperandAndOperatorAndOperand)
       
   823             {
       
   824             editLine.TrimZeroL();
       
   825             // Save the previous operator
       
   826             TCalcEditLine::TCalcOperatorType previousOperator = editLine.Operator();
       
   827             // Set the operator to percent
       
   828             editLine.SetOperator(TCalcEditLine::ECalcPercent);
       
   829             
       
   830             
       
   831             // Calculate
       
   832             TRAPD(errorCode3, 
       
   833                 result = iCalcDocument->CalculateAndModifyHistoryL(
       
   834                 editorNumber, editLine, previousOperator));
       
   835             
       
   836             if (errorCode3)
       
   837                 {
       
   838                 iContainer->SetErrorCode(errorCode3);
       
   839                 return;
       
   840                 }
       
   841 
       
   842             iOutputSheet->ScrollToBottomL();
       
   843             // Show the correct operand in the output sheet
       
   844             aOperator = previousOperator;
       
   845             // Set the state to EOperatorResult so that the HandleResult knows what to do
       
   846             UpdateState(EOperatorResult);
       
   847             }    
       
   848         }
       
   849 
       
   850     // User has pressed sqrt
       
   851     else if (aOperator == TCalcEditLine::ECalcSqrt)
       
   852         {
       
   853         // We are in a middle of calculation chain
       
   854         if (iState == EOperandAndOperatorAndOperand)
       
   855             {
       
   856             editLine.TrimZeroL();
       
   857             // Save the previous operator
       
   858             TCalcEditLine::TCalcOperatorType previousOperator = editLine.Operator();
       
   859             // Set the operator to sqrt
       
   860             editLine.SetOperator(TCalcEditLine::ECalcSqrt);
       
   861             
       
   862             // First calculate the sqrt
       
   863             TRAPD(errorCode, 
       
   864                 result = iCalcDocument->CalculateAndNoHistoryL(
       
   865                 editorNumber, editLine));
       
   866                                                  
       
   867             if (errorCode)
       
   868                 {
       
   869                 iContainer->SetErrorCode(errorCode);
       
   870                 return;
       
   871                 }
       
   872             
       
   873             // Set the operator to previous one
       
   874             editLine.SetOperator(previousOperator);
       
   875             // Result goes to the outputsheet
       
   876             editLine.SetNumber(result);
       
   877 
       
   878             // Calculate again
       
   879             TRAPD(errorCode2, 
       
   880                 result = iCalcDocument->CalculateAndAddHistoryL(
       
   881                 result, editLine));
       
   882                                                  
       
   883             if (errorCode2)
       
   884                 {
       
   885                 iContainer->SetErrorCode(errorCode2);
       
   886                 return;
       
   887                 }
       
   888             // Set this so that we will display correct operator in the output sheet
       
   889             aOperator = previousOperator;
       
   890             iOutputSheet->ScrollToBottomL();
       
   891             UpdateState(EOperator);
       
   892             // Dimm the square root and percent
       
   893             iContainer->ShowSqrtButton(EFalse);
       
   894             iContainer->ShowPercentButton(EFalse);
       
   895             }
       
   896         // Only operand and sqrt
       
   897         else
       
   898             {
       
   899             editLine.SetOperator(aOperator);
       
   900                     
       
   901             // Trap harness, because the CalculateAndHistoryL leaves in case of negative operand
       
   902             TRAPD(errorCode,
       
   903                 result = iCalcDocument->CalculateAndAddHistoryL(
       
   904                 editorNumber, editLine));
       
   905             
       
   906             if (errorCode)
       
   907                 {
       
   908                 iContainer->SetErrorCode(errorCode);
       
   909                 return;
       
   910                 }
       
   911 
       
   912             iOutputSheet->ScrollToBottomL();
       
   913             //Set the state to EOperatorResult so that we know to call HandleResult later
       
   914             UpdateState(EOperatorResult);
       
   915             }
       
   916         }
       
   917     //  Current state is state4 and previous input is MS,
       
   918     // provisional result is get and show this the editor.
       
   919     // And a line is not added to OutputSheet because a line
       
   920     // is already added.
       
   921     
       
   922     else if (iState == ESelectResult)
       
   923         {
       
   924         iCalcDocument->AddEmptyLine();
       
   925         editLine.SetOperator(TCalcEditLine::ECalcOperatorNone);
       
   926         //  Because the state is "User has selected result",
       
   927         // this function does not occur leave.
       
   928         result = iCalcDocument->CalculateAndAddHistoryL(
       
   929                  editorNumber, editLine);
       
   930         iOutputSheet->ScrollToBottomL();
       
   931         UpdateState(EOperator);    
       
   932         iContainer->SetSqrtEnableL();
       
   933         }
       
   934         
       
   935     //  If a input is a operator and state is updated,
       
   936     // calculate and update history.
       
   937     else if (iState != EOperandAndOperator)  
       
   938         {
       
   939         editLine.TrimZeroL();
       
   940 
       
   941         // If the number in the EditLine is not a operand
       
   942         // we need to dim square root and percent buttons
       
   943         if (iState == EOperandAndOperatorAndOperand)
       
   944             {
       
   945             iContainer->ShowSqrtButton(EFalse);
       
   946             iContainer->ShowPercentButton(EFalse);
       
   947             }
       
   948         // Calculate by user's input
       
   949         TRAPD(errorCode, 
       
   950               result = iCalcDocument->CalculateAndAddHistoryL(
       
   951               editorNumber, editLine));
       
   952                                                  
       
   953         if (errorCode)
       
   954             {
       
   955             iContainer->SetErrorCode(errorCode);
       
   956             return;
       
   957             }
       
   958         iOutputSheet->ScrollToBottomL();
       
   959         UpdateState(EOperator);
       
   960         }
       
   961     
       
   962     iEditorSubPane->SetEditorNumber(result);
       
   963     iEditorSubPane->SetOperator(aOperator);
       
   964     
       
   965     if ( aOperator != TCalcEditLine::ECalcSqrt )
       
   966         {
       
   967         iEditorSubPane->DrawNow();  
       
   968         }
       
   969     iContainer->ScrollArrowUpdate();
       
   970  
       
   971     iContainer->SetClearKeyEnable(); 
       
   972     if (aOperator == TCalcEditLine::ECalcAdd ||aOperator == TCalcEditLine::ECalcSubtract ||
       
   973          aOperator == TCalcEditLine::ECalcMultiply ||aOperator == TCalcEditLine::ECalcDivide )
       
   974         {
       
   975         iContainer->SetChangeSignDisable();
       
   976         }  
       
   977     
       
   978     }
       
   979 
       
   980 
       
   981 // ---------------------------------------------------------
       
   982 // CCalcView::HandleEqualSubRoutineL
       
   983 // Common routine for select result and MemorySave on two operands
       
   984 // and operator or State4.
       
   985 // (other items were commented in a header).
       
   986 // ---------------------------------------------------------
       
   987 //
       
   988 TInt CCalcView::HandleEqualSubRoutineL()
       
   989     {
       
   990     TCalcEditLine editLine(iEditorSubPane->EditLine());
       
   991     TInt calculationError(KErrNone);
       
   992     TReal64 result(0);
       
   993 
       
   994     if (iState == EOperandAndOperator || iState == EOperatorOnlyResult)
       
   995         {
       
   996         // User has selected equal or operand and sqrt, or percent
       
   997         result = iCalcDocument->ProvisionalResult();
       
   998         }
       
   999     else 
       
  1000         {
       
  1001         editLine.TrimZeroL();
       
  1002         // We are calculating the intermediate result. 
       
  1003         // So we need to dim the sqrt and percent buttons.
       
  1004         iContainer->ShowSqrtButton(EFalse); 
       
  1005         iContainer->ShowPercentButton(EFalse);
       
  1006         
       
  1007         if (iState == ESelectResult)
       
  1008             {
       
  1009             iCalcDocument->AddEmptyLine();
       
  1010             editLine.SetOperator(TCalcEditLine::ECalcOperatorNone);
       
  1011             }
       
  1012         TRAP(calculationError,
       
  1013              result = iCalcDocument->CalculateAndAddHistoryL(
       
  1014              iEditorSubPane->EditorNumber(), editLine));
       
  1015         }
       
  1016     
       
  1017     //  If overflow or division by zero occurs,
       
  1018     // error message is displayed.
       
  1019     if (calculationError)
       
  1020         {
       
  1021         iContainer->SetErrorCode(calculationError);
       
  1022         }
       
  1023     else
       
  1024         {
       
  1025         iCalcDocument->AddEqualLineAndUpdateLastResultL();
       
  1026         iEditorSubPane->SetEditorNumber(result);
       
  1027         iEditorSubPane->SetOperator(TCalcEditLine::ECalcEqual);
       
  1028         // Show result on the sheet
       
  1029         CCalcOutputSheet* sheet = iContainer->OutputSheet();
       
  1030         sheet->ScrollToBottomL();
       
  1031         iContainer->ScrollArrowUpdate();
       
  1032         }
       
  1033     return calculationError;
       
  1034     }
       
  1035 
       
  1036 // ----------------------------------------------------
       
  1037 // CCalcView::DoActivateL
       
  1038 // This is called when CCalcView becomes active.
       
  1039 // (other items were commented in a header).
       
  1040 // ----------------------------------------------------
       
  1041 //
       
  1042 void CCalcView::DoActivateL
       
  1043                 (const TVwsViewId& /* aPrevViewId */,
       
  1044                  TUid /* aCustomMessageId */,
       
  1045                  const TDesC8& /* aCustomMessage */)
       
  1046     {
       
  1047     if ( iContainer == NULL )
       
  1048         {
       
  1049         CreateContainerL();
       
  1050         AppUi()->AddToStackL( *this, iContainer );
       
  1051         iContainer->ActivateL();
       
  1052         } 
       
  1053     
       
  1054     }
       
  1055 
       
  1056 // ----------------------------------------------------
       
  1057 // CCalcView::DoDeactivate
       
  1058 // This is called when CCalcView becomes deactive.
       
  1059 // (other items were commented in a header).
       
  1060 // ----------------------------------------------------
       
  1061 //
       
  1062 void CCalcView::DoDeactivate()
       
  1063     {
       
  1064     if ( iContainer )
       
  1065         {
       
  1066         AppUi()->RemoveFromStack( iContainer );
       
  1067         delete iContainer;
       
  1068         iContainer = NULL;
       
  1069         }
       
  1070     }
       
  1071 
       
  1072 // ---------------------------------------------------------
       
  1073 // CCalcView::Id
       
  1074 // Return UID of CCalcView
       
  1075 // (other items were commented in a header).
       
  1076 // ---------------------------------------------------------
       
  1077 //
       
  1078 TUid CCalcView::Id() const
       
  1079     {
       
  1080     return TUid::Uid(KCalcViewId);
       
  1081     }
       
  1082 
       
  1083 // ---------------------------------------------------------
       
  1084 // CCalcView::DynInitMenuPaneL
       
  1085 // This app can have only one menu.
       
  1086 // But menu of Calculator application is changed on State, memory etc.
       
  1087 // Therefore to delete meaningless items from menu, this function is defined. 
       
  1088 // (other items were commented in a header).
       
  1089 // ---------------------------------------------------------
       
  1090 //
       
  1091 void CCalcView::DynInitMenuPaneL
       
  1092         (TInt aResourceId,        
       
  1093          CEikMenuPane* aMenuPane) 
       
  1094     {
       
  1095     if(iServiceHandler->HandleSubmenuL(*aMenuPane))
       
  1096         {
       
  1097             return;
       
  1098         }
       
  1099     switch (aResourceId)
       
  1100         {
       
  1101         case (R_CALC_POPUPMENU):
       
  1102             {
       
  1103                 
       
  1104                        DynInitMainMenuPane(aMenuPane);
       
  1105                     
       
  1106                 /***** Get the context of the Help topic from here *****/
       
  1107                   CArrayFix<TCoeHelpContext>* buf= AppUi()->AppHelpContextL();
       
  1108                    TInt i= buf->Count();
       
  1109                    if(i!=0)
       
  1110                        {
       
  1111                        /***** Check whether our flag is defined or not *****/
       
  1112                        #ifdef RD_HELP_AIW_INTEGRATION
       
  1113                        
       
  1114                        /***** Call the AiwProvider's AddItemsL  to attach the mnu items********/
       
  1115                            
       
  1116                             iServiceHandler->InitializeMenuPaneL(*aMenuPane,aResourceId,
       
  1117                                         ECmdLast,iServiceHandler->InParamListL()); 
       
  1118                     /**** Set the old embedded help as dimmed one ****/ 
       
  1119                         aMenuPane->SetItemDimmed(ECalcCmdHelp, ETrue);                     
       
  1120                     #else
       
  1121                     /**** Set the Aiw Help as dimmed one as our feature flag is not defined ****/ 
       
  1122                         aMenuPane->SetItemDimmed(ECmdAiwPlaceHolder,ETrue);    
       
  1123                     #endif
       
  1124                        }
       
  1125                 else 
       
  1126                     {
       
  1127                  /**** If the Feature flag is not defined dont show the Aiw Help ****/
       
  1128                     aMenuPane->SetItemDimmed(ECmdAiwPlaceHolder,ETrue);
       
  1129                     }
       
  1130                     
       
  1131                 /******* Delete the buffer and make it to NULL *****/
       
  1132                    delete buf;
       
  1133                 buf = NULL;   
       
  1134                 if (!FeatureManager::FeatureSupported( KFeatureIdHelp ))
       
  1135                     {
       
  1136                     aMenuPane->DeleteMenuItem(ECalcCmdHelp);
       
  1137                     aMenuPane->DeleteMenuItem(ECmdAiwPlaceHolder);
       
  1138                     }  
       
  1139             break;
       
  1140             }
       
  1141 
       
  1142         case (R_CALC_MEMORY_MENU):
       
  1143             {
       
  1144             DynInitMemoryMenuPane(aMenuPane);
       
  1145             break;
       
  1146             }
       
  1147         default:
       
  1148             {
       
  1149             break;
       
  1150             }
       
  1151         }
       
  1152     }   
       
  1153 // ---------------------------------------------------------
       
  1154 // CCalcView::HandleForegroundEventL
       
  1155 //Refresh and draw display ,paper and function map Icons.
       
  1156 // ---------------------------------------------------------
       
  1157 //
       
  1158 void CCalcView::HandleForegroundEventL(TBool aForeground)
       
  1159     {
       
  1160     if( (aForeground) && (STATIC_CAST(CCalcAppUi*, AppUi())->IsSkinChanged()) )
       
  1161         {
       
  1162         iEditorSubPane->RefreshDisplaySideLBitmap();
       
  1163         iEditorSubPane->RefreshDisplayCenterBitmap();
       
  1164         iEditorSubPane->RefreshDisplaySideRBitmap();    
       
  1165         
       
  1166         iEditorSubPane->DrawNow();
       
  1167 
       
  1168         iOutputSheet->RefreshPaperBitmap();
       
  1169         iOutputSheet->RefreshScalablePaperBitmap();
       
  1170 #ifdef __SCALABLE_ICONS
       
  1171         iOutputSheet->RefreshResultsLineBitmap();
       
  1172 #endif
       
  1173         iOutputSheet->DrawNow();
       
  1174 
       
  1175         iContainer->FunctionSubPane()->RefreshButtonIcons();        
       
  1176         for(TInt i =0; i< 10; i++)
       
  1177             {
       
  1178             iContainer->FunctionSubPane()->GetButtonBitmapControl(i)->DrawNow();
       
  1179             }
       
  1180         }
       
  1181     else
       
  1182         {
       
  1183         CAknView::HandleForegroundEventL(aForeground);
       
  1184         }
       
  1185     }
       
  1186 
       
  1187 
       
  1188 //  End of File