extras/calcsoft/src/CalcCont.cpp
changeset 0 3ee3dfdd8d69
child 8 ebe992a85829
equal deleted inserted replaced
-1:000000000000 0:3ee3dfdd8d69
       
     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:  Source file of "CCalcContainer",  CCalcContainer class 
       
    15 *                which derived from CCoeControl class. Role of this class 
       
    16 *                is to update the calculator data and display on user's input.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include    <aknkeys.h>
       
    23 #include    <AknUtils.h>   // AknLayoutUtils::LayoutControl 
       
    24 #include    <Calcsoft.rsg>
       
    25 
       
    26 #include	<layoutmetadata.cdl.h>
       
    27 
       
    28 // For skin support. 
       
    29 #include    <AknsDrawUtils.h>
       
    30 #include    <AknsConstants.h>
       
    31 #include    <AknsUtils.h>
       
    32 #include    <AknsBasicBackgroundControlContext.h>
       
    33 #include    <applayout.cdl.h>
       
    34 #include    <aknlayoutscalable_apps.cdl.h>
       
    35 #include    <csxhelp/calc.hlp.hrh> // for help context of Calculator
       
    36 #include    "CalcApp.h" 
       
    37 
       
    38 #include    "CalcAppUi.h"
       
    39 #include    "CalcCont.h"
       
    40 #include    "CalcDoc.h"
       
    41 #include    "CalcEdit.h"
       
    42 #include    "CalcFunc.h"
       
    43 #include    "CalcOutSheet.h"
       
    44 #include    "calc.hrh"
       
    45 #include    "CalcView.h"
       
    46 #include	"CalcEnv.h"
       
    47 #include    "CalcHistory.h"
       
    48 #include    "CalcDrawingConst.laf" // for layout information
       
    49 
       
    50 
       
    51 #include <AknDef.h>
       
    52 #include <eiksbfrm.h> 
       
    53 #include <eikscrlb.h>
       
    54 
       
    55 
       
    56 #define KEY_CODE_VAL 57 //for all number inputs
       
    57 #define ASCII_ZERO 48
       
    58 
       
    59 //  LOCAL CONSTANTS AND MACROS  
       
    60 const TInt KCallBackDelay(1000000); // In microseconds
       
    61 const TInt KCallBackInterval(1000000); // In microseconds
       
    62 const TInt KCallBackPriority(CActive::EPriorityUserInput);
       
    63 
       
    64 // Count of controls in Calculator.
       
    65 // Controls are editor pane, output sheet, and function map.
       
    66 // Therefore, this count is 3.  
       
    67 const TInt KCalcCountOfControls(3);
       
    68 
       
    69 // Define index of control
       
    70 enum TCalcControlIndex
       
    71     {
       
    72     ECalcControlFunctionMap,
       
    73     ECalcControlOutputSheet,
       
    74 	ECalcControlEditorPane
       
    75     };
       
    76 
       
    77 // If const TChar is used, complie error occurs in THUMB build.
       
    78 // To avoid this, #define is used.
       
    79 #define KCalcAsteriskBtn '*'
       
    80 
       
    81 
       
    82 // ================= MEMBER FUNCTIONS =======================
       
    83 
       
    84 // Two-phased constructor.
       
    85 CCalcContainer* CCalcContainer::NewL(
       
    86                     CCalcView* aView)
       
    87     {
       
    88     CCalcContainer* self = new (ELeave) CCalcContainer();
       
    89     CleanupStack::PushL(self);
       
    90     self->ConstructL(aView);
       
    91     CleanupStack::Pop(self);
       
    92     return self;
       
    93     }
       
    94 
       
    95 
       
    96 // Destructor
       
    97 CCalcContainer::~CCalcContainer()
       
    98     {
       
    99     delete iEditorPane;
       
   100     delete iFuncmapPane;
       
   101     delete iSheetPane;
       
   102 
       
   103     delete iTimeout;
       
   104 
       
   105     if ( iTimeoutChr )
       
   106     	{
       
   107         delete iTimeoutChr;
       
   108         iTimeoutChr = NULL;
       
   109     	}
       
   110     if ( iTimeoutShift )
       
   111     	{
       
   112         delete iTimeoutShift;
       
   113         iTimeoutShift = NULL;
       
   114     	}
       
   115 
       
   116     delete iSkinContext;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CCalcContainer::ProcessPreinputL
       
   121 // This function is called when decimal point or a digit is inputted.
       
   122 // (other items were commented in a header).
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 void CCalcContainer::ProcessPreinputL()
       
   126     {
       
   127     TInt currentState = iView->State();
       
   128     CCalcView::TKindOfInput latestInput(iView->LatestInput());
       
   129 
       
   130     if (currentState == CCalcView::ESelectResult)  
       
   131                               // State 5 : User has selected result
       
   132         {
       
   133         iEditorPane->ResetL();  // Set editline "0"
       
   134         iView->UpdateState(CCalcView::EAllClear);
       
   135         iCalcDocument->AddEmptyLine();
       
   136         iSheetPane->ScrollToBottomL();
       
   137         ScrollArrowUpdate();
       
   138         }
       
   139     else if (currentState == CCalcView::EOperandAndOperator ||  
       
   140                                            // State 3 : operand and operator
       
   141              latestInput == CCalcView::EMemoryRecall  ||
       
   142              latestInput == CCalcView::EMemorySave)
       
   143         {   
       
   144         iEditorPane->ClearOperand();
       
   145         }
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------
       
   149 // CCalcContainer::InputClearL
       
   150 // This function should be called when editor is cleared.
       
   151 // (other items were commented in a header).
       
   152 // ---------------------------------------------------------
       
   153 //
       
   154 void CCalcContainer::InputClearL()
       
   155     {
       
   156     iEditorPane->ResetL();
       
   157     iView->UpdateState(CCalcView::EAllClear);
       
   158     
       
   159     const TCalcEditLine lastLine((*(iCalcDocument->History()))[0]);  
       
   160                                               // Get latest historical line.
       
   161     const TPtrC number(lastLine.NumberString());
       
   162     
       
   163     //  If latest historical line is not empty,
       
   164     // empty line is added in the history and the history is shown.
       
   165     if ( number.Length() )
       
   166         {
       
   167         iCalcDocument->AddEmptyLine();
       
   168         iSheetPane->ScrollToBottomL();
       
   169         ScrollArrowUpdate();
       
   170         }
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------
       
   174 // CCalcContainer::ScrollArrowUpdate
       
   175 // This function should be called when OutputSheet is scrolled
       
   176 // or history is added.
       
   177 // (other items were commented in a header).
       
   178 // ---------------------------------------------------------
       
   179 //
       
   180 void CCalcContainer::ScrollArrowUpdate()
       
   181     {
       
   182     iFuncmapPane->RedrawScrollButtons();
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------
       
   186 // CCalcContainer::SetChangeSignEnableL
       
   187 // This function is called when number of editor is changed.
       
   188 // (other items were commented in a header).
       
   189 // ---------------------------------------------------------
       
   190 //
       
   191 void CCalcContainer::SetChangeSignEnableL()
       
   192     {
       
   193     TCalcEditLine editLine(iEditorPane->EditLine());
       
   194     TBool changeSignEnable(ETrue);
       
   195     
       
   196     if (editLine.NumberL() == 0.0)
       
   197         {
       
   198         changeSignEnable = EFalse;    
       
   199         }
       
   200     
       
   201     iFuncmapPane->SetChangeSignEnable(changeSignEnable);
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------
       
   205 // CCalcContainer::SetClearKeyEnable
       
   206 // This function is called when number of editor is changed.
       
   207 // (other items were commented in a header).
       
   208 // ---------------------------------------------------------
       
   209 //
       
   210 void CCalcContainer::SetClearKeyEnable() 
       
   211     {
       
   212     TCalcEditLine editLine( iEditorPane->EditLine() );
       
   213     TBool clearKeyEnable( ETrue );
       
   214     
       
   215     // eitline's number is 0.0 and length is 1  and the no operator
       
   216     TRAP_IGNORE(
       
   217         {
       
   218         if ( editLine.CheckZeroL() && ( editLine.Operator() ==
       
   219             TCalcEditLine::ECalcOperatorNone ) )
       
   220             {
       
   221             clearKeyEnable = EFalse; 
       
   222             }
       
   223         }
       
   224     )
       
   225     iFuncmapPane->SetClearKeyEnable( clearKeyEnable );
       
   226     }
       
   227 
       
   228 // ---------------------------------------------------------
       
   229 // CCalcContainer::SetChangeSignDisable
       
   230 // This function is called when Operator +, - , *, / key is pressed.
       
   231 // (other items were commented in a header).
       
   232 // ---------------------------------------------------------
       
   233 //
       
   234 void CCalcContainer::SetChangeSignDisable()
       
   235     {
       
   236     
       
   237     TBool changeSignEnable(EFalse);
       
   238     iFuncmapPane->SetChangeSignEnable(changeSignEnable);
       
   239     
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------
       
   243 // CCalcContainer::SetSqrtEnableL
       
   244 // This function is called when number of editor is changed.
       
   245 // (other items were commented in a header).
       
   246 // ---------------------------------------------------------
       
   247 //
       
   248 void CCalcContainer::SetSqrtEnableL()
       
   249     {
       
   250 	TCalcEditLine editLine(iEditorPane->EditLine());
       
   251 	TBool sqrtEnable(ETrue);
       
   252     
       
   253     if (editLine.NumberL() == 0.0)
       
   254         {
       
   255         sqrtEnable = EFalse;    
       
   256 		}
       
   257 	iFuncmapPane->SetSqrtEnable(sqrtEnable);
       
   258 	}
       
   259 
       
   260 // ---------------------------------------------------------
       
   261 // CCalcContainer::SetPercentEnableL
       
   262 // This function is called when number of editor is changed.
       
   263 // (other items were commented in a header).
       
   264 // ---------------------------------------------------------
       
   265 //
       
   266 void CCalcContainer::SetPercentEnableL()
       
   267     {
       
   268 	TCalcEditLine editLine(iEditorPane->EditLine());
       
   269 	TBool percentEnable(ETrue);
       
   270     
       
   271     if (editLine.NumberL() == 0.0)
       
   272         {
       
   273         percentEnable = EFalse;    
       
   274 		}
       
   275 	iFuncmapPane->SetPercentEnable(percentEnable);
       
   276 	}
       
   277 
       
   278 
       
   279 // ---------------------------------------------------------
       
   280 // CCalcContainer::TimeoutCallbackL
       
   281 // If no key is pressed after pressing *-button and a few time
       
   282 // passes, this function is called    
       
   283 // (other items were commented in a header).
       
   284 // ---------------------------------------------------------
       
   285 //
       
   286 TInt CCalcContainer::TimeoutCallbackL(
       
   287                          TAny* aObject)
       
   288     {
       
   289     STATIC_CAST(CCalcContainer*, aObject)->DoTimeoutL();
       
   290     return 0;
       
   291     }
       
   292 
       
   293 // ---------------------------------------------------------
       
   294 // CCalcContainer::TimeoutCallbackL
       
   295 // If no key is pressed after pressing */button and a few time
       
   296 // passes, this function is called    
       
   297 // (other items were commented in a header).
       
   298 // ---------------------------------------------------------
       
   299 //
       
   300 TInt CCalcContainer::TimeoutCallbackChrL(
       
   301                          TAny* aObject)
       
   302     {
       
   303     STATIC_CAST( CCalcContainer*, aObject )->DoTimeoutChrL();
       
   304     return 0;
       
   305     }
       
   306 // ---------------------------------------------------------
       
   307 // CCalcContainer::TimeoutCallbackL
       
   308 // If no key is pressed after pressing +#button and a few time
       
   309 // passes, this function is called    
       
   310 // (other items were commented in a header).
       
   311 // ---------------------------------------------------------
       
   312 //
       
   313 TInt CCalcContainer::TimeoutCallbackShiftL(
       
   314                          TAny* aObject)
       
   315     {
       
   316     STATIC_CAST(CCalcContainer*, aObject)->DoTimeoutShiftL();
       
   317     return 0;
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------
       
   321 // CCalcContainer::NotifyChangeDecimal
       
   322 // Call when decimal separator is changed.
       
   323 // (other items were commented in a header).
       
   324 // ---------------------------------------------------------
       
   325 //
       
   326 void CCalcContainer::NotifyChangeDecimal(TChar aOld, TChar aNew)
       
   327     {
       
   328     iEditorPane->NotifyChangeDecimal(aOld, aNew);
       
   329     iSheetPane->DrawNow();
       
   330     }
       
   331 
       
   332 
       
   333 // ---------------------------------------------------------
       
   334 // CCalcContainer::GetHelpContext
       
   335 // This function is called when Help application is launched.  
       
   336 // (other items were commented in a header).
       
   337 // ---------------------------------------------------------
       
   338 //
       
   339 void CCalcContainer::GetHelpContext(
       
   340                 TCoeHelpContext& aContext) const
       
   341     {
       
   342     aContext.iMajor = KUidCalc;
       
   343     aContext.iContext = KCALC_HLP_MAIN;
       
   344     }
       
   345 
       
   346 // C++ default constructor can NOT contain any code, that
       
   347 // might leave.
       
   348 //
       
   349 CCalcContainer::CCalcContainer():
       
   350     iPrevInput(EKeyNull) 
       
   351     {
       
   352     }
       
   353 
       
   354 // Second-phase constructor
       
   355 void CCalcContainer::ConstructL(
       
   356                      CCalcView* aView)
       
   357     {
       
   358     iView = aView;
       
   359     CCalcAppUi* appui = CCalcAppEnv::Static()->AppUi();
       
   360     iCalcDocument = STATIC_CAST(CCalcDocument*, appui->Document());
       
   361     
       
   362     // Make a window-owning control.
       
   363     CreateWindowL();
       
   364     
       
   365     
       
   366     
       
   367     iFuncmapPane = CCalcFuncmapSubPane::NewL(this);
       
   368     iSheetPane = CCalcOutputSheet::NewL(this);
       
   369 	iEditorPane = CCalcEditorSubPane::NewL(this);
       
   370 
       
   371     iTimeout = CPeriodic::NewL(KCallBackPriority);
       
   372  
       
   373     iTimeoutChr = CPeriodic::NewL( KCallBackPriority );
       
   374     iTimeoutShift = CPeriodic::NewL( KCallBackPriority );
       
   375 
       
   376     TRect rect(0, 0, 0, 0); 
       
   377     // Temporary rect is passed. Correct rect is set in SizeChanged.
       
   378     iSkinContext = CAknsBasicBackgroundControlContext::NewL(
       
   379         KAknsIIDQsnBgAreaMainCalc, rect, EFalse);
       
   380         iValue = 0;
       
   381 
       
   382     // Set status pane layout usual.
       
   383     CEikonEnv::Static()->AppUiFactory()->StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL ); 
       
   384     }
       
   385     
       
   386 void CCalcContainer::ActivateL()
       
   387     {
       
   388     
       
   389     CCoeControl::ActivateL();   
       
   390     SetChangeSignEnableL();
       
   391     SetSqrtEnableL();
       
   392     SetPercentEnableL();
       
   393     ScrollArrowUpdate();
       
   394     SetClearKeyEnable(); 
       
   395     }
       
   396     
       
   397 
       
   398 // ---------------------------------------------------------
       
   399 // CCalcContainer::DoTimeoutL
       
   400 // If no key is pressed until timeout of *-key,
       
   401 // this function is called.
       
   402 // (other items were commented in a header).
       
   403 // ---------------------------------------------------------
       
   404 //
       
   405 void CCalcContainer::DoTimeoutL()
       
   406     {
       
   407     iTimeout->Cancel();
       
   408     iFuncmapPane->NotifyTimeoutL(); 
       
   409     }
       
   410 
       
   411 // ---------------------------------------------------------
       
   412 // CCalcContainer::DoTimeoutL
       
   413 // If no key is pressed until timeout of */key,
       
   414 // this function is called.
       
   415 // (other items were commented in a header).
       
   416 // ---------------------------------------------------------
       
   417 //
       
   418 void CCalcContainer::DoTimeoutChrL()
       
   419     {
       
   420     iTimeoutChr->Cancel();
       
   421     iFuncmapPane->NotifyTimeoutL(); 
       
   422     }
       
   423 // ---------------------------------------------------------
       
   424 // CCalcContainer::DoTimeoutL
       
   425 // If no key is pressed until timeout of +#key,
       
   426 // this function is called.
       
   427 // (other items were commented in a header).
       
   428 // ---------------------------------------------------------
       
   429 //
       
   430 void CCalcContainer::DoTimeoutShiftL()
       
   431     {
       
   432     iTimeoutShift->Cancel();
       
   433     iFuncmapPane->NotifyTimeoutL(); 
       
   434     }
       
   435 
       
   436 // ---------------------------------------------------------
       
   437 // CCalcContainer::HandleAsterKeyTimeoutForKeyPressL
       
   438 // Called when any key is pressed.
       
   439 // If timeout notifier for *-key is active, make calculation or
       
   440 // stop notifier according to user's input.
       
   441 // (other items were commented in a header).
       
   442 // ---------------------------------------------------------
       
   443 //
       
   444 TBool CCalcContainer::HandleAsterKeyTimeoutForKeyPressL(
       
   445      const TKeyEvent& aKeyEvent, TEventCode aType)
       
   446     {
       
   447     if (!(iTimeout->IsActive()))
       
   448         {
       
   449         return EFalse;
       
   450         }
       
   451 
       
   452     TBool ret(EFalse);
       
   453     
       
   454     if (aKeyEvent.iModifiers & EModifierShift)
       
   455         {
       
   456         // Stop timer for *-key and make calculaiton.
       
   457         DoTimeoutL();
       
   458         }
       
   459 
       
   460     if (aType == EEventKey)
       
   461         {
       
   462         switch (aKeyEvent.iCode)
       
   463             {
       
   464             // Stop timer and no calculation is made 
       
   465             // if pressed arrow or OK key.
       
   466             // This depends on spec of Editing.
       
   467             case EKeyLeftArrow:
       
   468             case EKeyRightArrow:
       
   469             case EKeyUpArrow:
       
   470             case EKeyDownArrow:
       
   471             case EKeyOK:
       
   472                 {
       
   473                 DoTimeoutL();
       
   474                 ret = ETrue;
       
   475                 break;
       
   476                 }
       
   477             // Stop timer if *-key is pressed. 
       
   478             // If release *-key, reset timer for the key.       
       
   479             case KCalcAsteriskBtn:
       
   480                 {
       
   481                 iTimeout->Cancel();
       
   482                 break;
       
   483                 }
       
   484             default:
       
   485                 {
       
   486                 // Stop timer for *-key and make calculaiton.
       
   487                 DoTimeoutL();
       
   488                 break;
       
   489                 }
       
   490             }
       
   491         }
       
   492     return ret;
       
   493     }
       
   494 
       
   495 // ---------------------------------------------------------
       
   496 // CCalcContainer::HandleAsterKeyTimeoutForKeyPressL
       
   497 // Called when any key is pressed.
       
   498 // If timeout notifier for */key is active, make calculation or
       
   499 // stop notifier according to user's input.
       
   500 // (other items were commented in a header).
       
   501 // ---------------------------------------------------------
       
   502 //
       
   503 TBool CCalcContainer::HandleChrKeyTimeoutForKeyPressL(
       
   504      const TKeyEvent& aKeyEvent, TEventCode aType )
       
   505     {
       
   506     if ( !( iTimeoutChr->IsActive() ) )
       
   507         {
       
   508         return EFalse;
       
   509         }
       
   510 
       
   511     TBool ret( EFalse );
       
   512     
       
   513     if ( aKeyEvent.iModifiers & EModifierShift )
       
   514         {
       
   515         DoTimeoutChrL();
       
   516         }
       
   517     if ( aKeyEvent.iModifiers & EModifierFunc )
       
   518         {
       
   519         // Stop timer for */key and make calculaiton.
       
   520         iTimeoutChr->Cancel();
       
   521         } 
       
   522 
       
   523     if ( aType == EEventKey )
       
   524         {
       
   525         switch ( aKeyEvent.iCode )
       
   526             {
       
   527             // Stop timer and no calculation is made 
       
   528             // if pressed arrow or OK key.
       
   529             // This depends on spec of Editing.
       
   530             case EKeyLeftArrow:
       
   531             case EKeyRightArrow:
       
   532             case EKeyUpArrow:
       
   533             case EKeyDownArrow:
       
   534             case EKeyOK:
       
   535                 {
       
   536                 DoTimeoutChrL();
       
   537                 ret = ETrue;
       
   538                 break;
       
   539                 }
       
   540             default:
       
   541                 {
       
   542                 // Stop timer for */key and make calculaiton.
       
   543                 DoTimeoutChrL();
       
   544                 break;
       
   545                 }
       
   546             }
       
   547         }
       
   548     return ret;
       
   549     }
       
   550 // ---------------------------------------------------------
       
   551 // CCalcContainer::HandleAsterKeyTimeoutForKeyPressL
       
   552 // Called when any key is pressed.
       
   553 // If timeout notifier for +#key is active, make calculation or
       
   554 // stop notifier according to user's input.
       
   555 // (other items were commented in a header).
       
   556 // ---------------------------------------------------------
       
   557 //
       
   558 TBool CCalcContainer::HandleShiftKeyTimeoutForKeyPressL(
       
   559      const TKeyEvent& aKeyEvent, TEventCode aType )
       
   560     {
       
   561     if ( !( iTimeoutShift->IsActive() ) )
       
   562         {
       
   563         return EFalse;
       
   564         }
       
   565 
       
   566     TBool ret( EFalse );
       
   567     
       
   568     if ( aKeyEvent.iModifiers & EModifierShift )
       
   569         {
       
   570         // Stop timer for +#key and make calculaiton.
       
   571         iTimeoutShift->Cancel();
       
   572         }
       
   573     if ( aKeyEvent.iModifiers & EModifierFunc )
       
   574         {
       
   575         DoTimeoutShiftL();
       
   576         }    
       
   577 
       
   578     if ( aType == EEventKey )
       
   579         {
       
   580         switch ( aKeyEvent.iCode )
       
   581             {
       
   582             // Stop timer and no calculation is made 
       
   583             // if pressed arrow or OK key.
       
   584             // This depends on spec of Editing.
       
   585             case EKeyLeftArrow:
       
   586             case EKeyRightArrow:
       
   587             case EKeyUpArrow:
       
   588             case EKeyDownArrow:
       
   589             case EKeyOK:
       
   590                 {
       
   591                 DoTimeoutShiftL();
       
   592                 ret = ETrue;
       
   593                 break;
       
   594                 }
       
   595             default:
       
   596                 {
       
   597                 // Stop timer for +#key and make calculaiton.
       
   598                 DoTimeoutShiftL();
       
   599                 break;
       
   600                 }
       
   601             }
       
   602         }
       
   603     return ret;
       
   604     }
       
   605 
       
   606 // ---------------------------------------------------------
       
   607 // CCalcContainer::CountComponentControls
       
   608 // Return count of control components.
       
   609 // (other items were commented in a header).
       
   610 // ---------------------------------------------------------
       
   611 //
       
   612 TInt CCalcContainer::CountComponentControls() const
       
   613     {
       
   614     return KCalcCountOfControls ;
       
   615     }
       
   616 
       
   617 // ---------------------------------------------------------
       
   618 // CCalcContainer::ComponentControl
       
   619 // Return control pointer which correspond to argument aIndex 
       
   620 // (other items were commented in a header).
       
   621 // ---------------------------------------------------------
       
   622 //
       
   623 CCoeControl* CCalcContainer::ComponentControl
       
   624                 ( TInt aIndex ) const   
       
   625     {
       
   626     CCoeControl* control = NULL; 
       
   627         
       
   628     switch (aIndex)
       
   629         {
       
   630         case ECalcControlEditorPane:
       
   631             {
       
   632             control = iEditorPane;
       
   633             break;
       
   634             }
       
   635         case ECalcControlFunctionMap:
       
   636             {
       
   637             control = iFuncmapPane;
       
   638             break;
       
   639             }
       
   640         case ECalcControlOutputSheet:
       
   641             {
       
   642             control = iSheetPane;
       
   643             break;
       
   644             }
       
   645         default:
       
   646             {         
       
   647             break;
       
   648             }
       
   649         }
       
   650 
       
   651     return control;
       
   652     }
       
   653 
       
   654 // ---------------------------------------------------------
       
   655 // CCalcContainer::OfferKeyEventL
       
   656 // This function is called when a key is pressed.
       
   657 // (other items were commented in a header).
       
   658 // ---------------------------------------------------------
       
   659 //
       
   660 TKeyResponse CCalcContainer::OfferKeyEventL
       
   661                 ( const TKeyEvent& aKeyEvent,  
       
   662                   TEventCode aType )           
       
   663     {
       
   664     switch (aType)
       
   665         {
       
   666         case EEventKeyDown:
       
   667         case EEventKey:
       
   668             {
       
   669             if (aKeyEvent.iScanCode != EStdKeyLeftArrow &&
       
   670             aKeyEvent.iScanCode != EStdKeyRightArrow &&
       
   671             aKeyEvent.iScanCode != EStdKeyUpArrow &&
       
   672             aKeyEvent.iScanCode != EStdKeyDownArrow &&
       
   673             aKeyEvent.iCode != EKeyOK)
       
   674                 {
       
   675                 iFuncmapPane->NotifyOtherThanOkKeyPressed();
       
   676                 }
       
   677             iPrevInput = aKeyEvent.iCode;
       
   678 
       
   679             if(!(iFuncmapPane->IsQwertyKeypadActive()))
       
   680              {
       
   681             if (HandleAsterKeyTimeoutForKeyPressL(aKeyEvent, aType))
       
   682                 {
       
   683                 return EKeyWasConsumed;
       
   684                 }
       
   685             }
       
   686 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   687             else
       
   688                 {
       
   689                 if ( iFuncmapPane->GetKeyboardType() == EPtiKeyboardHalfQwerty )
       
   690                 	{
       
   691                     if ( HandleChrKeyTimeoutForKeyPressL( aKeyEvent, aType ) )
       
   692                         {
       
   693                         return EKeyWasConsumed;
       
   694                         }  
       
   695                     if ( HandleShiftKeyTimeoutForKeyPressL( aKeyEvent, aType ) )
       
   696                         {
       
   697                         return EKeyWasConsumed;
       
   698                         } 
       
   699                     }
       
   700                 }
       
   701 #endif
       
   702 
       
   703             iValue =1 ;
       
   704             break;
       
   705             }
       
   706         case EEventKeyUp:
       
   707             {
       
   708             if(!(iFuncmapPane->IsQwertyKeypadActive()))
       
   709              {
       
   710             	
       
   711             if (iPrevInput == KCalcAsteriskBtn && !iTimeout->IsActive() && iValue ==1 )
       
   712                 {
       
   713                 TCallBack callback(TimeoutCallbackL, this);
       
   714                 iTimeout->Start((TTimeIntervalMicroSeconds32) KCallBackDelay,
       
   715                                 (TTimeIntervalMicroSeconds32) KCallBackInterval, 
       
   716                                 callback);
       
   717                 }
       
   718             }
       
   719 #ifdef RD_INTELLIGENT_TEXT_INPUT  
       
   720             else
       
   721                 {
       
   722                 if ( iFuncmapPane->GetKeyboardType() == EPtiKeyboardHalfQwerty )
       
   723                 	{
       
   724                     if ( aKeyEvent.iScanCode == EStdKeyLeftFunc && !iTimeoutChr->IsActive() && iValue == 1 )
       
   725                         {
       
   726                         TCallBack callback( TimeoutCallbackChrL, this );
       
   727                         iTimeoutChr->Start( ( TTimeIntervalMicroSeconds32 ) KCallBackDelay,
       
   728                                      ( TTimeIntervalMicroSeconds32 ) KCallBackInterval, 
       
   729                                      callback );
       
   730                         }
       
   731                     if ( aKeyEvent.iScanCode == EStdKeyLeftShift && !iTimeoutShift->IsActive() && iValue == 1 )
       
   732                         {
       
   733                         TCallBack callback( TimeoutCallbackShiftL, this );
       
   734                         iTimeoutShift->Start( ( TTimeIntervalMicroSeconds32 ) KCallBackDelay,
       
   735                                      ( TTimeIntervalMicroSeconds32 ) KCallBackInterval, 
       
   736                                      callback );
       
   737                         }
       
   738             	    }
       
   739                 }
       
   740 #endif
       
   741 
       
   742             iFuncmapPane->NotifyReleaseKeyL();
       
   743             iValue =0;
       
   744             
       
   745             DrawNow(); //redraw screen when a button up
       
   746             break;
       
   747             }
       
   748         default:
       
   749             {
       
   750             break;
       
   751             }
       
   752         }
       
   753 
       
   754     TKeyResponse keyResponse(iFuncmapPane->OfferKeyEventL(aKeyEvent, aType));
       
   755     if (keyResponse == EKeyWasNotConsumed)
       
   756         {
       
   757         if(iFuncmapPane->IsQwertyKeypadActive())
       
   758              {
       
   759              iEditorPane->IsQwertyActive();
       
   760              }
       
   761         else
       
   762         	{
       
   763         	iEditorPane->IsQwertyNotActive();	
       
   764         	}
       
   765         // Edit buffer of line
       
   766         keyResponse = iEditorPane->OfferKeyEventL(aKeyEvent, aType);
       
   767         }
       
   768     return keyResponse;
       
   769     }
       
   770 
       
   771 // ---------------------------------------------------------
       
   772 // CCalcContainer::HandleResourceChange
       
   773 // Notifier for changing language
       
   774 // (other items were commented in a header).
       
   775 // ---------------------------------------------------------
       
   776 //
       
   777 void CCalcContainer::HandleResourceChange(TInt aType)
       
   778     {
       
   779     TRAP_IGNORE( HandleResourceChangeCalSoftL( aType ) );
       
   780     }
       
   781 
       
   782 // ---------------------------------------------------------
       
   783 // CCalcContainer::HandleResourceChange
       
   784 // Notifier for changing language
       
   785 // (other items were commented in a header).
       
   786 // ---------------------------------------------------------
       
   787 //
       
   788 void CCalcContainer::HandleResourceChangeCalSoftL(TInt aType)
       
   789     {
       
   790     if ((aType == KEikDynamicLayoutVariantSwitch) || (aType == KAknsMessageSkinChange) )
       
   791         {
       
   792          	    
       
   793 	     TRect mainPaneRect ;
       
   794 	     TRect statusPaneRect;
       
   795 	     TBool signstate = EFalse;
       
   796 	     TBool sqrtstate = EFalse;
       
   797 	     TBool percentstate = EFalse;
       
   798         TBool clearstate = EFalse;
       
   799         	     
       
   800         if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   801             {
       
   802             // when calculator is in Landscape layout, the statuspane displays     
       
   803             iEikonEnv->AppUiFactory()->StatusPane()
       
   804                 ->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL );
       
   805             AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
   806             }
       
   807         else
       
   808             {
       
   809             AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
   810             AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, statusPaneRect );
       
   811             mainPaneRect.iTl = statusPaneRect.iTl;
       
   812             }
       
   813 	    
       
   814 	    
       
   815 	    //check if funcpane already exists
       
   816 
       
   817       TInt selected = 0;
       
   818 	    if(iFuncmapPane)
       
   819 	    {
       
   820 	    	//store the  states of the buttons
       
   821 	        signstate = iFuncmapPane->GetChangeSignButtonState();
       
   822 	        sqrtstate = iFuncmapPane->GetSqrtButtonState();
       
   823 	        percentstate = iFuncmapPane->GetPercentButtonState();
       
   824 
       
   825             selected = iFuncmapPane->GetSelectedButtonId();
       
   826             
       
   827             clearstate = iFuncmapPane->GetClearButtonState(); 
       
   828          	
       
   829          	//delete the function pane
       
   830 	        delete(iFuncmapPane);
       
   831 	        iFuncmapPane =  NULL;
       
   832 	        
       
   833 	    }
       
   834         //Reload the bitmaps
       
   835         (CCalcAppEnv::Static())->SetSkinChangedValue(EFalse);
       
   836         (CCalcAppEnv::Static())->UpdateAknConstArrayForFuncMap();
       
   837         (CCalcAppEnv::Static())->LoadFuncMapBitmapL();
       
   838 	    
       
   839         //Create the new pane
       
   840         iFuncmapPane = CCalcFuncmapSubPane::NewL(this); 
       
   841 
       
   842         if ( AknLayoutUtils::PenEnabled() )
       
   843         {		    
       
   844         iFuncmapPane->SetHighlightButton( 0, selected );   
       
   845         }
       
   846         
       
   847         iFuncmapPane->ActivateL();
       
   848         
       
   849         SetRect(mainPaneRect);
       
   850         iFuncmapPane->NotifyLangChange();
       
   851         DrawNow();
       
   852 
       
   853         //Restore the states of the buttons
       
   854         iFuncmapPane->SetChangeSignEnable(signstate);
       
   855         iFuncmapPane->SetSqrtEnable(sqrtstate);
       
   856         iFuncmapPane->SetPercentEnable(percentstate);
       
   857         iFuncmapPane->SetClearKeyEnable( clearstate );
       
   858         
       
   859         //Update scroll bar here
       
   860         ScrollArrowUpdate();
       
   861 				iSheetPane->HandleResourceChange(aType);
       
   862         }
       
   863     else
       
   864         {
       
   865         
       
   866         CCoeControl::HandleResourceChange(aType);
       
   867         }
       
   868       
       
   869     }
       
   870  
       
   871 
       
   872 // ---------------------------------------------------------
       
   873 // CCalcContainer::SizeChanged
       
   874 // Control size is set.
       
   875 // This function is called when the size changes.
       
   876 // (other items were commented in a header).
       
   877 // ---------------------------------------------------------
       
   878 //
       
   879 void CCalcContainer::SizeChanged()
       
   880     {
       
   881     TRect parentRect(Rect());
       
   882     
       
   883     if (iSkinContext)
       
   884         {
       
   885         iSkinContext->SetRect(parentRect);
       
   886         }
       
   887 
       
   888     
       
   889 	if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
   890 		{
       
   891     		 
       
   892     		// Set layout of function map subpane, output sheet  and editor sub pane.		
       
   893     	    if( AknLayoutUtils::PenEnabled() )
       
   894     	    {
       
   895     	        if (Layout_Meta_Data::IsLandscapeOrientation())
       
   896     	        {
       
   897     	        
       
   898     	        	AknLayoutUtils::LayoutControl(
       
   899     			    iFuncmapPane, parentRect, AknLayoutScalable_Apps::grid_calc_pane(enTouch_with_lsc).LayoutLine());
       
   900     			    
       
   901     	            AknLayoutUtils::LayoutControl(
       
   902     		    	iSheetPane, parentRect,AknLayoutScalable_Apps::calc_paper_pane(enTouch_with_lsc).LayoutLine());
       
   903     		    		
       
   904     		        AknLayoutUtils::LayoutControl(
       
   905     			    iEditorPane, parentRect,AknLayoutScalable_Apps::calc_display_pane(enTouch_with_lsc).LayoutLine());
       
   906     	        }
       
   907     	        else
       
   908     	        {
       
   909     	            AknLayoutUtils::LayoutControl(
       
   910     			    iFuncmapPane, parentRect, AknLayoutScalable_Apps::grid_calc_pane(enTouch_with_prt).LayoutLine());
       
   911     			    
       
   912     	            AknLayoutUtils::LayoutControl(
       
   913     		    	iSheetPane, parentRect,AknLayoutScalable_Apps::calc_paper_pane(enTouch_with_prt).LayoutLine());
       
   914     		    	
       
   915     		    	AknLayoutUtils::LayoutControl(
       
   916     			    iEditorPane, parentRect,AknLayoutScalable_Apps::calc_display_pane(enTouch_with_prt).LayoutLine());
       
   917     	        }
       
   918     	    }
       
   919     	    else
       
   920     	    {
       
   921     	        AknLayoutUtils::LayoutControl(
       
   922     			    iFuncmapPane, parentRect, AknLayoutScalable_Apps::grid_calc_pane(enTouch_disabled).LayoutLine());
       
   923     			    
       
   924     		    AknLayoutUtils::LayoutControl(
       
   925     			iSheetPane, parentRect,AknLayoutScalable_Apps::calc_paper_pane(enTouch_disabled).LayoutLine());
       
   926     			
       
   927     			AknLayoutUtils::LayoutControl(
       
   928     			iEditorPane, parentRect,AknLayoutScalable_Apps::calc_display_pane(enTouch_disabled).LayoutLine());
       
   929     		    
       
   930     	    }	
       
   931 
       
   932 		}
       
   933 	else
       
   934 		{
       
   935     // Set layout of function map subpane.
       
   936     AknLayoutUtils::LayoutControl(
       
   937 	iFuncmapPane, parentRect, AppLayout::grid_calc_pane());	
       
   938 	
       
   939 	
       
   940     // Set layout of output sheet.
       
   941     AknLayoutUtils::LayoutControl(
       
   942 		 iSheetPane, parentRect,AppLayout::gqn_graf_calc_paper());
       
   943 	
       
   944 	// Set layout of editor subpane.
       
   945     AknLayoutUtils::LayoutControl(
       
   946         iEditorPane, parentRect,AppLayout::Calculator_elements_Line_1());
       
   947 		}	
       
   948 	}
       
   949 
       
   950 // ---------------------------------------------------------
       
   951 // CCalcContainer::Draw
       
   952 // Clear whole screen. After this, draw editor, output sheet,
       
   953 // and function map.
       
   954 // (other items were commented in a header).
       
   955 // ---------------------------------------------------------
       
   956 //
       
   957 void CCalcContainer::Draw(const TRect& aRect) const
       
   958     {
       
   959     CWindowGc& gc = SystemGc();
       
   960     gc.Clear(aRect);
       
   961 
       
   962     // Drawing skin
       
   963     if (iSkinContext)
       
   964         {
       
   965         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   966         
       
   967         AknsDrawUtils::Background(
       
   968             skin, iSkinContext, this, gc, aRect);
       
   969         }
       
   970      
       
   971     }
       
   972 
       
   973 // ---------------------------------------------------------
       
   974 // CCalcContainer::MopSupplyObject()
       
   975 // Pass skin information if need.
       
   976 // (other items were commented in a header).
       
   977 // ---------------------------------------------------------
       
   978 //
       
   979 TTypeUid::Ptr CCalcContainer::MopSupplyObject(TTypeUid aId)
       
   980     {
       
   981     if (aId.iUid == MAknsControlContext::ETypeId && iSkinContext)
       
   982         {
       
   983         return MAknsControlContext::SupplyMopObject(aId, iSkinContext);
       
   984         }
       
   985 
       
   986     return CCoeControl::MopSupplyObject(aId);
       
   987     }
       
   988 
       
   989 // ---------------------------------------------------------
       
   990 // CCalcContainer::ShowSqrtButton()
       
   991 // Enable (or disable) the square root button.
       
   992 // (other items were commented in a header).
       
   993 // ---------------------------------------------------------
       
   994 //
       
   995 void CCalcContainer::ShowSqrtButton(TBool aEnable)
       
   996 	{
       
   997 		iFuncmapPane->SetSqrtEnable(aEnable);
       
   998 	}	
       
   999 
       
  1000 // ---------------------------------------------------------
       
  1001 // CCalcContainer::ShowPercentButton()
       
  1002 // Enable (or disable) the percent button.
       
  1003 // (other items were commented in a header).
       
  1004 // ---------------------------------------------------------
       
  1005 //
       
  1006 void CCalcContainer::ShowPercentButton(TBool aEnable)
       
  1007 	{
       
  1008 		iFuncmapPane->SetPercentEnable(aEnable);
       
  1009 	}
       
  1010 
       
  1011 // ---------------------------------------------------------
       
  1012 // CCalcContainer::GetState()
       
  1013 // Returns the state of the calculator.
       
  1014 // (other items were commented in a header).
       
  1015 // ---------------------------------------------------------
       
  1016 //
       
  1017 CCalcView::TStateNo CCalcContainer::GetState()
       
  1018 {
       
  1019 	return (iView->State());
       
  1020 }
       
  1021 
       
  1022 // ---------------------------------------------------------
       
  1023 // CCalcContainer::HandlePointerEventL
       
  1024 // Handled when pen input occured.
       
  1025 // (other items were commented in a header).
       
  1026 // ---------------------------------------------------------
       
  1027 //
       
  1028 void CCalcContainer::HandlePointerEventL
       
  1029                 ( const TPointerEvent& aPointerEvent )           
       
  1030     {
       
  1031     CCoeControl::HandlePointerEventL( aPointerEvent );
       
  1032     }
       
  1033     
       
  1034 
       
  1035 // ---------------------------------------------------------
       
  1036 // ---------------------------------------------------------
       
  1037 // CCalcContainer::HandleMiddleSoftKey()
       
  1038 // Handled when MSK is selected.
       
  1039 // ---------------------------------------------------------
       
  1040 //
       
  1041 void CCalcContainer::HandleMiddleSoftKey()
       
  1042                 
       
  1043 	{
       
  1044 	TRAP_IGNORE( iFuncmapPane->HandleMiddleSoftKeyOREKeyOKL() );
       
  1045 	}
       
  1046 
       
  1047 // ---------------------------------------------------------
       
  1048 // ---------------------------------------------------------
       
  1049 // SetOperatorFromTouchL
       
  1050 // Handle digit inputs
       
  1051 // ---------------------------------------------------------
       
  1052 //
       
  1053 void CCalcContainer::SetOperatorFromTouchL(TInt akey )
       
  1054 {
       
  1055 	  //Simulate events as events are occurring from the KB Events
       
  1056 	  TKeyEvent eventkey;
       
  1057 	  TEventCode keycode;
       
  1058     keycode = EEventKeyDown;
       
  1059     eventkey.iCode = 0;
       
  1060     eventkey.iScanCode = ASCII_ZERO + akey;
       
  1061     
       
  1062     //First send Keydown event
       
  1063    	OfferKeyEventL(eventkey,keycode);
       
  1064 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
  1065     eventkey.iCode = ASCII_ZERO + akey;
       
  1066 #else
       
  1067     eventkey.iCode = KEY_CODE_VAL;
       
  1068 #endif
       
  1069     keycode = EEventKey;
       
  1070     
       
  1071     //Next send EventKey
       
  1072     OfferKeyEventL(eventkey,keycode);
       
  1073     
       
  1074     
       
  1075     //Finally send Keyup
       
  1076     eventkey.iScanCode = ASCII_ZERO + akey;
       
  1077     keycode = EEventKeyUp;
       
  1078     OfferKeyEventL(eventkey,keycode);
       
  1079 }
       
  1080 
       
  1081 // ---------------------------------------------------------
       
  1082 // ---------------------------------------------------------
       
  1083 // ClearInputKeyL
       
  1084 // Handle 'c' input key from Touch
       
  1085 // ---------------------------------------------------------
       
  1086 //
       
  1087 void CCalcContainer::ClearInputKeyL(TInt aRepeat)
       
  1088 {
       
  1089 	  //Simulate events as events are occurring from the KB Events
       
  1090 	TKeyEvent eventkey;
       
  1091 	TEventCode keycode;
       
  1092     keycode = EEventKeyDown;
       
  1093     eventkey.iCode = 0; 
       
  1094     eventkey.iScanCode = 1; //for clear input key
       
  1095     eventkey.iRepeats = aRepeat;
       
  1096     
       
  1097     //First send Keydown event
       
  1098     OfferKeyEventL(eventkey,keycode);
       
  1099     eventkey.iCode = 8;  //clear input key icode
       
  1100     keycode = EEventKey;
       
  1101     
       
  1102     //Next send EventKey
       
  1103     OfferKeyEventL(eventkey,keycode);
       
  1104     keycode = EEventKeyUp;
       
  1105     
       
  1106      //Finally send Keyup
       
  1107     OfferKeyEventL(eventkey,keycode);    
       
  1108     
       
  1109 }
       
  1110 
       
  1111 
       
  1112 // ---------------------------------------------------------
       
  1113 // ---------------------------------------------------------
       
  1114 // SetSeparatorFromTouch
       
  1115 // Handle '.' input key from Touch
       
  1116 // ---------------------------------------------------------
       
  1117 //
       
  1118 void CCalcContainer::SetSeparatorFromTouchL()
       
  1119 {
       
  1120     // set the right iCode and iScanCode for
       
  1121     // decimal point
       
  1122     if ( iFuncmapPane->IsQwertyKeypadActive() )
       
  1123         {
       
  1124         // Simulate events as events are occurring from the KB Events
       
  1125         TKeyEvent eventkey;
       
  1126         TEventCode keycode = EEventKeyDown;
       
  1127         eventkey.iCode = 0;
       
  1128 #ifdef RD_INTELLIGENT_TEXT_INPUT  
       
  1129         if ( iFuncmapPane->GetKeyboardType() == EPtiKeyboardHalfQwerty )
       
  1130         	{
       
  1131             eventkey.iScanCode = 126;  //scan code for separator
       
  1132         	}
       
  1133         else
       
  1134 #endif
       
  1135         	{
       
  1136             eventkey.iScanCode = 122;  //scan code for separator
       
  1137         	}
       
  1138 
       
  1139         // First send Keydown event
       
  1140         OfferKeyEventL( eventkey, keycode );
       
  1141         eventkey.iCode = 46;  // icode for separator
       
  1142         keycode = EEventKey;
       
  1143 
       
  1144         // Next send EventKey
       
  1145         OfferKeyEventL( eventkey, keycode );
       
  1146         }
       
  1147     else
       
  1148         {
       
  1149         // Simulate events as events are occurring from the KB Events	
       
  1150         TKeyEvent eventkey;
       
  1151         TEventCode keycode = EEventKeyDown;
       
  1152         eventkey.iCode = 0;
       
  1153         eventkey.iScanCode = 127;  // scan code for separator
       
  1154 
       
  1155         // First send Keydown event
       
  1156         OfferKeyEventL( eventkey, keycode );
       
  1157         eventkey.iCode = 35;  // icode for separator
       
  1158         keycode = EEventKey;
       
  1159 
       
  1160         // Next send EventKey
       
  1161         OfferKeyEventL( eventkey, keycode );
       
  1162         }     
       
  1163 }
       
  1164    
       
  1165 //  End of File  CALCCONT_CPP