extras/calcsoft/inc/CalcDoc.h
branchRCL_3
changeset 23 41b775cdc0c8
parent 22 0f21a5ec0db7
child 24 10c6e6d6e4d9
equal deleted inserted replaced
22:0f21a5ec0db7 23:41b775cdc0c8
     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:  Document class, CCalcDocument
       
    15 *                Derived from CEikDocument
       
    16 *                The history of inputted data is held.
       
    17 *                The memory of four-arithmetical-operations operation 
       
    18 *                or a calculation result is held.
       
    19 *                The last result and memory are saved at a file and 
       
    20 *                it restores.
       
    21 *
       
    22 */
       
    23 
       
    24 
       
    25 #ifndef     CALCDOC_H
       
    26 #define     CALCDOC_H
       
    27 
       
    28 
       
    29 //  INCLUDES
       
    30 #include <eikdoc.h>
       
    31 
       
    32 #include "CalcEditline.h"
       
    33 
       
    34 #include "CalcView.h"
       
    35 //  CONSTANTS
       
    36 const TInt KCalcErrEditorSpaceFull(-10000); 
       
    37 
       
    38 //  FORWARD DECLARATIONS
       
    39 
       
    40 class  CEikAppUi;
       
    41 class  CCalcHistory;
       
    42 class  CCalcAppEnv;
       
    43 
       
    44 //  CLASS DEFINITIONS 
       
    45 
       
    46 /**
       
    47 CCalcDocument : 'Document' class
       
    48 */
       
    49 class   CCalcDocument 
       
    50         :public CEikDocument
       
    51     {
       
    52     public:  // Constructors and destructor  
       
    53         /**
       
    54         * Two-phased constructor.
       
    55         * @param aApp : Reference of CEikApplication class 
       
    56         */
       
    57         static CCalcDocument* NewL(CEikApplication& aApp);
       
    58 
       
    59         /**
       
    60         * Destructor.
       
    61         */
       
    62         virtual ~CCalcDocument();
       
    63 
       
    64         
       
    65     public:  // New functions
       
    66 		/**
       
    67         * Set the pointer to CalcAppEnv. 
       
    68         */
       
    69 		void SetAppEnv(CCalcAppEnv* aCalcAppEnv);
       
    70 
       
    71         /**
       
    72         * Set the pointer to CalcAppEnv. 
       
    73         */		
       
    74         void SetCalcView( CCalcView* aCCalcView );
       
    75         
       
    76 		/**
       
    77         * Make calculation, and add result to calcluation history.
       
    78         * Leave may occur, causes KErrOverflow or KErrDivideByZero or KErrNotSupported (negative value with square root).
       
    79         * @param aOperand : operand.
       
    80         * @param aLine : inputted edit line
       
    81         * @return TReal64: Provisional result.
       
    82         */
       
    83         TReal64 CalculateAndAddHistoryL(
       
    84                 TReal64 aOperand,
       
    85                const TCalcEditLine& aLine);  
       
    86 		
       
    87 		/**
       
    88         * Make calculation, nothing is added to the calculation history.
       
    89         * Leave may occur, causes KErrOverflow or KErrDivideByZero or KErrNotSupported (negative value with square root).
       
    90         * @param aOperand : operand.
       
    91         * @param aLine : inputted edit line
       
    92         * @return TReal64: Provisional result.
       
    93         */
       
    94 		TReal64 CalculateAndNoHistoryL(
       
    95 				TReal64 aOperand,
       
    96                const TCalcEditLine& aLine);  
       
    97 
       
    98 		/**
       
    99         * Make calculation, and modify the operator
       
   100 		* before adding anything to the calculation history.
       
   101         * Leave may occur, causes KErrOverflow or KErrDivideByZero or KErrNotSupported (negative value with square root).
       
   102         * @param aOperand : operand.
       
   103         * @param aLine : inputted edit line
       
   104         * @return TReal64: Provisional result.
       
   105         */
       
   106 		TReal64 CalculateAndModifyHistoryL(
       
   107 				TReal64 aOperand,
       
   108                TCalcEditLine& aLine,
       
   109 			   TCalcEditLine::TCalcOperatorType aOperator); 
       
   110 
       
   111         /**
       
   112         * Add a line which is "= (provisional result)" to calculation history.
       
   113         * And Last Result is updated to provisional result
       
   114         */
       
   115         void AddEqualLineAndUpdateLastResultL();
       
   116 
       
   117         /**
       
   118         * Empty line is added to calculation history.
       
   119         */
       
   120         void AddEmptyLine();
       
   121         
       
   122         /**
       
   123         * Memory is saved.
       
   124         * @param aNewMemory : New memory, current operand.
       
   125         */
       
   126         void MemorySaveL(TReal64 aNewMemory); 
       
   127 
       
   128         /**
       
   129         * Memory is saved.
       
   130         * @param aLine : Current value of editor
       
   131         */
       
   132         TBool HasMemory() const;
       
   133 
       
   134         /**
       
   135         * Return current memory.
       
   136         * @return TReal64 : current memory.
       
   137         */
       
   138         TReal64 Memory() const; 
       
   139 
       
   140         /**
       
   141         * Clear memory.
       
   142         */
       
   143         void MemoryClearL();
       
   144         
       
   145         /**
       
   146         * Return last result
       
   147         * @param TReal64 : Last result.
       
   148         */
       
   149         TReal64 LastResult() const;  
       
   150 
       
   151         /**
       
   152         * Return provisional result
       
   153         * @param aLine : For getting provisional result.
       
   154         */
       
   155         TReal64 ProvisionalResult() const;
       
   156 
       
   157         /**
       
   158         * Return pointer of CCalcHistory class. 
       
   159         * @return Pointer of CCalcHistory class
       
   160         */
       
   161         CCalcHistory* History() const;
       
   162         
       
   163         /**
       
   164         * Restore memory and last result
       
   165         */
       
   166         void LoadStateL();
       
   167         
       
   168         /**
       
   169         * Store memory and last result
       
   170         */
       
   171 		void SaveStateL();
       
   172         
       
   173     private:   //  New functions
       
   174         /**
       
   175         * By default constructor is private.
       
   176         * @param aApp: Reference of CEikApplication class
       
   177         */
       
   178         CCalcDocument(CEikApplication& aApp); 
       
   179 
       
   180         /**
       
   181         * Second-phase constructor
       
   182         */
       
   183         void ConstructL();
       
   184 
       
   185         /**
       
   186         * Make calculation by using argument aLine 
       
   187         * Leave may occur, causes KErrOverflow or KErrDivideByZero.
       
   188         * @param aOperand : operand
       
   189         * @param aOperator : Operator type enum.
       
   190         * @return Result of calculation
       
   191         */
       
   192         TReal64 CalculateL(TReal64 aOperand,
       
   193             TCalcEditLine::TCalcOperatorType aOperator);
       
   194         
       
   195         /**
       
   196         * Check overflow and underflow 
       
   197         * Leave may occur, causes KErrOverflow
       
   198         * @param aResult : result of calculation
       
   199         */
       
   200         void CheckResultL(TReal64* aResult);  
       
   201 
       
   202         /**
       
   203         * Write last result and memory to document file.
       
   204         * @param aStream : Interface of write steam
       
   205         */
       
   206         void ExternalizeL(RWriteStream& aStream) const;
       
   207         
       
   208         /**
       
   209         * Read last result and memory from document file.
       
   210         * @param aStream : Interface of read steam
       
   211         */
       
   212         void InternalizeL(RReadStream& aStream);
       
   213 
       
   214         
       
   215     private:  // Functions from base classes  
       
   216         /**
       
   217         * From CEikDocument : Create CCalcAppUi object
       
   218         */
       
   219         CEikAppUi* CreateAppUiL();  
       
   220 
       
   221     private:    // Data
       
   222 	    CCalcAppEnv* iCalcAppEnv;  // Not own
       
   223         TReal64 iProvisionalResult; // Provisional result
       
   224         TReal64 iMemory;        // Memory
       
   225         TReal64 iLastResult;    // Last result
       
   226         CCalcHistory* iHistory; // History
       
   227         CCalcView* iCCalcView;  // Not own
       
   228     };
       
   229 
       
   230 #endif      //  CALCDOC_H
       
   231             
       
   232 // End of File
       
   233