phoneuis/dialer/src/cdialerkeypadcontainer.cpp
changeset 0 5f000ab63145
child 9 8871b09be73b
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Shows number keypad and generates keypress event when 
       
    15 *                 buttons are pressed.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32event.h>
       
    22 #include <gulicon.h>
       
    23 #include <eikapp.h>
       
    24 #include <AknUtils.h>
       
    25 #include <aknbutton.h>
       
    26 #include <AknControl.h>
       
    27 #include <AknsUtils.h>
       
    28 #include <AknsSkinInstance.h>
       
    29 #include <AknsDrawUtils.h>
       
    30 #include <AknsConstants.h>
       
    31 #include <AknLayout2Def.h>
       
    32 #include <aknlayoutscalable_apps.cdl.h>
       
    33 #include <layoutmetadata.cdl.h>
       
    34 #include <data_caging_path_literals.hrh> // for KDC_APP_RESOURCE_DIR
       
    35 #include <touchfeedback.h>
       
    36 
       
    37 #include "cdialerkeypadcontainer.h"
       
    38 #include "dialercommon.h"
       
    39 #include "dialertrace.h"
       
    40 
       
    41 #include "cdialerkeypadbutton.h"
       
    42 _LIT( KDialerMifFileName, "dialer.mif" );
       
    43 
       
    44 // Number of buttons in this container
       
    45 const TInt KNumberOfButtons = 12; 
       
    46 
       
    47 // Keypad button images
       
    48 const TMifDialer KKeyPadButtons[] =
       
    49     {
       
    50     EMbmDialerQgn_indi_dialer_one,
       
    51     EMbmDialerQgn_indi_dialer_two,
       
    52     EMbmDialerQgn_indi_dialer_three,
       
    53     EMbmDialerQgn_indi_dialer_four,
       
    54     EMbmDialerQgn_indi_dialer_five,
       
    55     EMbmDialerQgn_indi_dialer_six,
       
    56     EMbmDialerQgn_indi_dialer_seven,
       
    57     EMbmDialerQgn_indi_dialer_eight,
       
    58     EMbmDialerQgn_indi_dialer_nine,
       
    59     EMbmDialerQgn_indi_dialer_prefix,
       
    60     EMbmDialerQgn_indi_dialer_zero,
       
    61     EMbmDialerQgn_indi_dialer_hash
       
    62     };
       
    63 
       
    64 // Keypad button image masks
       
    65 const TMifDialer KKeyPadButtonsMasks[] =
       
    66     {
       
    67     EMbmDialerQgn_indi_dialer_one_mask,
       
    68     EMbmDialerQgn_indi_dialer_two_mask,
       
    69     EMbmDialerQgn_indi_dialer_three_mask,
       
    70     EMbmDialerQgn_indi_dialer_four_mask,
       
    71     EMbmDialerQgn_indi_dialer_five_mask,
       
    72     EMbmDialerQgn_indi_dialer_six_mask,
       
    73     EMbmDialerQgn_indi_dialer_seven_mask,
       
    74     EMbmDialerQgn_indi_dialer_eight_mask,
       
    75     EMbmDialerQgn_indi_dialer_nine_mask,
       
    76     EMbmDialerQgn_indi_dialer_prefix_mask,
       
    77     EMbmDialerQgn_indi_dialer_zero_mask,
       
    78     EMbmDialerQgn_indi_dialer_hash_mask
       
    79     };
       
    80 
       
    81 // Match keypresses to keyevents send to the phone
       
    82 //
       
    83 const TInt TDialerButtonToKeypadMap[12][2] = 
       
    84         {  
       
    85             { 49, // ScanCode
       
    86               49  // KeyCode
       
    87             },
       
    88             { 50,
       
    89               50
       
    90             },
       
    91             { 51,
       
    92               51
       
    93             },
       
    94             { 52,
       
    95               52
       
    96             },    
       
    97             { 53,
       
    98               53
       
    99             },
       
   100             { 54,
       
   101               54
       
   102             },
       
   103             { 55,
       
   104               55
       
   105             },
       
   106             { 56,
       
   107               56
       
   108             },
       
   109             { 57,
       
   110               57
       
   111             },                        
       
   112             { EStdKeyNkpAsterisk,
       
   113               42
       
   114             },
       
   115             { '0',
       
   116               '0'
       
   117             }, 
       
   118             { EStdKeyHash,
       
   119               35
       
   120             }                                                                                                       
       
   121         };   
       
   122 
       
   123 // Class declaration for CDialerKeyPadButton separated to cdialerkeypadbutton.h.
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // C++ default constructor
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 CDialerKeyPadButton::CDialerKeyPadButton()
       
   130     {
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // Destructor
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 CDialerKeyPadButton::~CDialerKeyPadButton()
       
   138     {
       
   139     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   140     if ( feedback )
       
   141         {
       
   142         feedback->RemoveFeedbackForControl( iButton );
       
   143         }
       
   144     delete iButton;   
       
   145     }
       
   146         
       
   147 // ---------------------------------------------------------------------------
       
   148 // Creates number keypad button
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CDialerKeyPadButton::CreateButtonL( const TInt aScanCode, 
       
   152                                          const TInt aKeyCode,
       
   153                                          const TMifDialer aButtonIcon, 
       
   154                                          const TMifDialer aButtonIconMask )
       
   155     {
       
   156     iScanCode = aScanCode;
       
   157     iKeyCode  = aKeyCode;
       
   158     iButtonIcon = aButtonIcon;
       
   159     iButtonIconMask = aButtonIconMask;
       
   160     
       
   161     TFileName mifPath( KDriveZ );
       
   162     mifPath.Append( KDC_APP_BITMAP_DIR );
       
   163     mifPath.Append( KDialerMifFileName );
       
   164 
       
   165     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   166     CFbsBitmap* bitmap (NULL);
       
   167     CFbsBitmap* mask (NULL);
       
   168 
       
   169     // Get icon ids.
       
   170     TAknsItemID skinItemId( KAknsIIDNone );  
       
   171     
       
   172     // Create button image.
       
   173     MapDialerIconToSkinIcon( aButtonIcon ,skinItemId );
       
   174     AknsUtils::CreateColorIconLC( 
       
   175         skin, 
       
   176         skinItemId,
       
   177         KAknsIIDQsnIconColors, 
       
   178         EAknsCIQsnIconColorsCG30,
       
   179         bitmap, 
       
   180         mask, 
       
   181         mifPath, 
       
   182         aButtonIcon, 
       
   183         aButtonIconMask,
       
   184         KRgbBlack
       
   185         );
       
   186 
       
   187     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   188     CleanupStack::Pop( 2 );
       
   189     CleanupStack::PushL( icon );
       
   190     iButton = CAknButton::NewL(
       
   191         icon , // ownership taken
       
   192         NULL, NULL, NULL, _L(""), _L(""), 0, 0 );
       
   193     iButton->SetButtonFlags( KAknButtonReportOnLongPress|
       
   194                             KAknButtonReportOnKeyDown  |
       
   195                             KAknButtonRequestExitOnButtonUpEvent );
       
   196     iButton->SetIconScaleMode( EAspectRatioPreserved );
       
   197     iButton->SetMargins( TMargins8(0,0,0,0) );    
       
   198     CleanupStack::Pop( icon ); 
       
   199     }
       
   200     
       
   201 // ---------------------------------------------------------------------------
       
   202 // 
       
   203 // ---------------------------------------------------------------------------
       
   204 //    
       
   205 TInt CDialerKeyPadButton::ScanCode() const
       
   206     {
       
   207     return iScanCode;
       
   208     }
       
   209     
       
   210 // ---------------------------------------------------------------------------
       
   211 // 
       
   212 // ---------------------------------------------------------------------------
       
   213 //    
       
   214 TInt CDialerKeyPadButton::KeyCode() const
       
   215     {
       
   216     return iKeyCode;
       
   217     }    
       
   218 // ---------------------------------------------------------------------------
       
   219 // 
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CDialerKeyPadButton::MapDialerIconToSkinIcon( const TInt aDialerIcon, 
       
   223                                          TAknsItemID& aItemId ) const
       
   224     {    
       
   225     switch ( aDialerIcon )
       
   226         {
       
   227         case EMbmDialerQgn_indi_dialer_one:
       
   228             aItemId = KAknsIIDQgnIndiDialerOne;
       
   229             break;
       
   230         case EMbmDialerQgn_indi_dialer_two:
       
   231             aItemId = KAknsIIDQgnIndiDialerTwo;
       
   232             break;
       
   233         case EMbmDialerQgn_indi_dialer_three:
       
   234             aItemId = KAknsIIDQgnIndiDialerThree;
       
   235             break;
       
   236         case EMbmDialerQgn_indi_dialer_four:
       
   237             aItemId = KAknsIIDQgnIndiDialerFour;
       
   238             break;
       
   239         case EMbmDialerQgn_indi_dialer_five:
       
   240             aItemId = KAknsIIDQgnIndiDialerFive;
       
   241             break;
       
   242         case EMbmDialerQgn_indi_dialer_six:
       
   243             aItemId = KAknsIIDQgnIndiDialerSix;
       
   244             break;
       
   245         case EMbmDialerQgn_indi_dialer_seven:
       
   246             aItemId = KAknsIIDQgnIndiDialerSeven;
       
   247             break;    
       
   248         case EMbmDialerQgn_indi_dialer_eight:
       
   249             aItemId = KAknsIIDQgnIndiDialerEight;
       
   250             break;
       
   251         case EMbmDialerQgn_indi_dialer_nine:
       
   252             aItemId = KAknsIIDQgnIndiDialerNine;
       
   253             break;
       
   254         case EMbmDialerQgn_indi_dialer_zero:
       
   255             aItemId = KAknsIIDQgnIndiDialerZero;
       
   256             break;
       
   257         case EMbmDialerQgn_indi_dialer_prefix:
       
   258             aItemId = KAknsIIDQgnIndiDialerPrefix;
       
   259             break;
       
   260         case EMbmDialerQgn_indi_dialer_hash:
       
   261             aItemId = KAknsIIDQgnIndiDialerHash;
       
   262             break;                        
       
   263         default:
       
   264             break;
       
   265         }
       
   266     }   
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // 
       
   270 // ---------------------------------------------------------------------------
       
   271 //   
       
   272 void CDialerKeyPadButton::SetIconSize( TSize& aSize )
       
   273     {
       
   274     iButton->SetIconSize( aSize );
       
   275     }  
       
   276     
       
   277 // ---------------------------------------------------------------------------
       
   278 // 
       
   279 // ---------------------------------------------------------------------------
       
   280 //   
       
   281 void CDialerKeyPadButton::UpdateIconL()
       
   282     {
       
   283     TFileName mifPath( KDriveZ );
       
   284     mifPath.Append( KDC_APP_BITMAP_DIR );
       
   285     mifPath.Append( KDialerMifFileName );
       
   286     
       
   287     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   288     CFbsBitmap* bitmap (NULL);
       
   289     CFbsBitmap* mask (NULL);
       
   290         
       
   291     // Get icon id.
       
   292     TAknsItemID skinItemId( KAknsIIDNone );  
       
   293     MapDialerIconToSkinIcon( iButtonIcon, skinItemId );
       
   294     
       
   295     AknsUtils::CreateColorIconLC( 
       
   296             skin, 
       
   297             skinItemId,
       
   298             KAknsIIDQsnIconColors, 
       
   299             EAknsCIQsnIconColorsCG30,
       
   300             bitmap, 
       
   301             mask, 
       
   302             mifPath, 
       
   303             iButtonIcon, 
       
   304             iButtonIconMask,
       
   305             KRgbBlack
       
   306             );
       
   307     
       
   308     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   309     CleanupStack::Pop( 2 );
       
   310     
       
   311     iButton->State()->SetIcon( icon ); // icon ownership transfered
       
   312     
       
   313     }  
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // 
       
   317 // Enable or disable audio but keep vibra feedback 
       
   318 // ---------------------------------------------------------------------------
       
   319 //   
       
   320 void CDialerKeyPadButton::EnableAudioFeedback( const TBool aEnable )
       
   321     {
       
   322     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   323     if ( feedback )
       
   324         {
       
   325         feedback->EnableFeedbackForControl( iButton, ETrue, aEnable );
       
   326         }
       
   327     }
       
   328 // ---------------------------------------------------------------------------
       
   329 // 
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 void CDialerKeyPadButton::HandleResourceChange( TInt aType )
       
   333     {
       
   334     if ( aType == KAknsMessageSkinChange )
       
   335         {
       
   336         TRAP_IGNORE( UpdateIconL() );
       
   337         iButton->HandleResourceChange( aType );
       
   338         }    
       
   339     }
       
   340 
       
   341 // ========================= MEMBER FUNCTIONS ================================
       
   342 
       
   343 // ---------------------------------------------------------------------------
       
   344 // Symbian OS two phased constructor
       
   345 // ---------------------------------------------------------------------------
       
   346 //
       
   347 CDialerKeyPadContainer* CDialerKeyPadContainer::NewL( 
       
   348     const CCoeControl& aContainer,
       
   349     TDialerOperationMode aOperatingMode
       
   350      )
       
   351     {
       
   352     CDialerKeyPadContainer* self = 
       
   353         new( ELeave )CDialerKeyPadContainer ( aContainer, aOperatingMode );
       
   354     CleanupStack::PushL( self );
       
   355     self->ConstructL();
       
   356     CleanupStack::Pop(self);
       
   357     return self;
       
   358     }
       
   359 
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // Symbian OS two phased constructor
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 void CDialerKeyPadContainer::ConstructL()
       
   366     {    
       
   367     DIALER_PRINT("KeyPadContainer::ConstructL<");
       
   368     BaseConstructL();
       
   369     CreateButtonsL();
       
   370     CCoeEnv* env = CCoeEnv::Static();
       
   371     env->AddForegroundObserverL( *this );
       
   372     DIALER_PRINT("KeyPadContainer::ConstructL>");
       
   373     }
       
   374 
       
   375 // Constructor
       
   376 CDialerKeyPadContainer::CDialerKeyPadContainer( 
       
   377     const CCoeControl& aContainer, 
       
   378     TDialerOperationMode aOperatingMode )
       
   379     : CDialerContainerBase ( 
       
   380         const_cast<CCoeControl&>(aContainer) ),
       
   381       iOperatingMode( aOperatingMode ),
       
   382       iButtonCount( KNumberOfButtons )
       
   383     {
       
   384     }
       
   385     
       
   386 // Destructor
       
   387 CDialerKeyPadContainer::~CDialerKeyPadContainer()
       
   388     {
       
   389     for ( TInt i = 0; i < iButtonCount; i++ )
       
   390         {
       
   391         AknsUtils::DeregisterControlPosition( 
       
   392                    ((CDialerKeyPadButton*)iButtons[i])->Control());   
       
   393         delete iButtons[i];
       
   394         }
       
   395     iButtons.Close();
       
   396     CCoeEnv* env = CCoeEnv::Static();
       
   397     env->RemoveForegroundObserver( *this );
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // CDialerKeyPadContainer::CountComponentControls
       
   402 //
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 TInt CDialerKeyPadContainer::CountComponentControls() const
       
   406     {
       
   407     return KNumberOfButtons;
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // CDialerKeyPadContainer::ComponentControl
       
   412 //
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 CCoeControl* CDialerKeyPadContainer::ComponentControl( TInt aIndex ) const
       
   416     {
       
   417     __ASSERT_DEBUG( aIndex < KNumberOfButtons, 
       
   418     _L("CDialerKeyPadContainer::ComponentControl, index out of range."));
       
   419     
       
   420     return ((CDialerKeyPadButton*)iButtons[aIndex])->Control();
       
   421     }
       
   422     
       
   423 // ---------------------------------------------------------------------------
       
   424 // CDialerKeyPadContainer::HandlePointerEventL
       
   425 //
       
   426 // ---------------------------------------------------------------------------
       
   427 //  
       
   428 void CDialerKeyPadContainer::HandlePointerEventL(
       
   429     const TPointerEvent& aPointerEvent )
       
   430     {
       
   431     DIALER_PRINT("KeyPadContainer::HandlePointerEventL<");    
       
   432     
       
   433     CCoeControl::HandlePointerEventL( aPointerEvent );    
       
   434 
       
   435     if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) 
       
   436         {
       
   437         iPointerEvent = aPointerEvent;    
       
   438         }
       
   439     DIALER_PRINT("KeyPadContainer::HandlePointerEventL>");     
       
   440     }
       
   441     
       
   442 // ---------------------------------------------------------------------------
       
   443 // CDialerKeyPadContainer::SetVariety
       
   444 //
       
   445 // Set variety according to current state.
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 void CDialerKeyPadContainer::SetVariety()
       
   449     {
       
   450     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   451         {
       
   452         iVariety = EVideoVarietyLandscape;
       
   453         }
       
   454     else
       
   455         {
       
   456         iVariety = EVideoVarietyPortrait;
       
   457         }
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // CDialerKeyPadContainer::SetLayout
       
   462 //
       
   463 // Set layout for video dtmf or phone dialer 
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 void CDialerKeyPadContainer::SetLayout()
       
   467     {
       
   468     if ( iOperatingMode == EModeDialer )
       
   469         {
       
   470         SetPhoneLayout();
       
   471         }
       
   472     else
       
   473         {
       
   474         SetVideoLayout();
       
   475         }
       
   476     }
       
   477 
       
   478 // ---------------------------------------------------------------------------
       
   479 // CDialerKeyPadContainer::SetPhoneLayout
       
   480 //
       
   481 // ---------------------------------------------------------------------------
       
   482 //
       
   483 void CDialerKeyPadContainer::SetPhoneLayout()
       
   484     {
       
   485     // Set Number entry layout.
       
   486     /*
       
   487 
       
   488     // LAF Table : grid_dialer2_keypad_pane
       
   489     inline TAknLayoutScalableParameterLimits cell_dialer2_keypad_pane_ParamLimits()
       
   490     inline TAknWindowComponentLayout cell_dialer2_keypad_pane()
       
   491 
       
   492     // LAF Table : cell_dialer2_keypad_pane
       
   493     inline TAknLayoutScalableParameterLimits bg_button_pane_pane_cp04_ParamLimits()
       
   494     inline TAknWindowComponentLayout bg_button_pane_pane_cp04()
       
   495     inline TAknLayoutScalableParameterLimits cell_dialer2_keypad_pane_g1_ParamLimits()
       
   496     */
       
   497     
       
   498     TRect parentRect( Rect() );
       
   499 
       
   500     // Icon size - all in same size
       
   501     TAknLayoutRect functionGraphics;  
       
   502              
       
   503     functionGraphics.LayoutRect( 
       
   504         parentRect,
       
   505         TAknWindowComponentLayout::Compose(
       
   506             AknLayoutScalable_Apps::cell_dialer2_keypad_pane( iVariety ),
       
   507             AknLayoutScalable_Apps::cell_dialer2_keypad_pane_g1( 
       
   508                                                         iVariety ) ) );
       
   509     TSize iconSize = functionGraphics.Rect().Size();
       
   510     
       
   511     // Layout buttons
       
   512     TAknLayoutScalableParameterLimits limits = 
       
   513     AknLayoutScalable_Apps::cell_dialer2_keypad_pane_ParamLimits( iVariety );
       
   514     
       
   515     TInt i = 0;
       
   516     for ( TInt row = limits.FirstRow(); row <= limits.LastRow(); row++ )
       
   517         {
       
   518         for ( TInt col = limits.FirstColumn(); 
       
   519               col <= limits.LastColumn(); col++ )
       
   520             {
       
   521             // Layout button
       
   522             AknLayoutUtils::LayoutControl(
       
   523                 ((CDialerKeyPadButton*)iButtons[i])->Control(), parentRect, 
       
   524                 TAknWindowComponentLayout::Compose( 
       
   525                     AknLayoutScalable_Apps::cell_dialer2_keypad_pane( iVariety,
       
   526                                                 col, row ), 
       
   527                     AknLayoutScalable_Apps::bg_button_pane_pane_cp04( 
       
   528                                                 iVariety ) ) );
       
   529             
       
   530             // Set icon size
       
   531             ((CDialerKeyPadButton*)iButtons[i++])->SetIconSize( iconSize );
       
   532             }
       
   533         }
       
   534     }
       
   535 
       
   536 // ---------------------------------------------------------------------------
       
   537 // CDialerKeyPadContainer::SetVideoLayout
       
   538 //
       
   539 // ---------------------------------------------------------------------------
       
   540 //
       
   541 void CDialerKeyPadContainer::SetVideoLayout()
       
   542     {
       
   543     TRect parentRect( Rect() );
       
   544     
       
   545     // Icon size - all in same size
       
   546     TAknLayoutRect functionGraphics;  
       
   547              
       
   548     functionGraphics.LayoutRect( 
       
   549         parentRect,
       
   550         TAknWindowComponentLayout::Compose(
       
   551             AknLayoutScalable_Apps::cell_video_dialer_keypad_pane( iVariety, 
       
   552                                         0, 0 ),
       
   553             AknLayoutScalable_Apps::cell_video_dialer_keypad_pane_g1( 
       
   554                                         iVariety ) ) );
       
   555     TSize iconSize = functionGraphics.Rect().Size();
       
   556     
       
   557     TAknLayoutScalableParameterLimits limits = 
       
   558         AknLayoutScalable_Apps::cell_video_dialer_keypad_pane_ParamLimits( 
       
   559                                         iVariety ) ;
       
   560     
       
   561     TInt i = 0;
       
   562     for ( TInt row = limits.FirstRow(); row <= limits.LastRow(); row++ )
       
   563         {
       
   564         for ( TInt col = limits.FirstColumn(); 
       
   565               col <= limits.LastColumn(); 
       
   566               col++ )
       
   567             {
       
   568             // Layout button
       
   569             AknLayoutUtils::LayoutControl(
       
   570                 ((CDialerKeyPadButton*)iButtons[i])->Control(), parentRect, 
       
   571                 TAknWindowComponentLayout::Compose( 
       
   572                     AknLayoutScalable_Apps::cell_video_dialer_keypad_pane( 
       
   573                         iVariety, col, row ), 
       
   574                     AknLayoutScalable_Apps::bg_button_pane_cp08( 
       
   575                                         iVariety ) ) );
       
   576             
       
   577             // Set icon size
       
   578             iButtons[i++]->SetIconSize( iconSize );
       
   579             }
       
   580         }
       
   581     }
       
   582 
       
   583 // ---------------------------------------------------------------------------
       
   584 // CDialerKeyPadContainer::CreateButtonsL
       
   585 //
       
   586 // Create buttons for this container.
       
   587 // ---------------------------------------------------------------------------
       
   588 //
       
   589 void CDialerKeyPadContainer::CreateButtonsL()
       
   590     {
       
   591     DIALER_PRINT("KeyPadContainer::CreateButtonsL<");
       
   592     
       
   593     for ( TInt i=0; i < KNumberOfButtons; i++ )
       
   594         {
       
   595         CDialerKeyPadButton* button = new (ELeave) CDialerKeyPadButton();
       
   596         CleanupStack::PushL( button );
       
   597         button->CreateButtonL( TDialerButtonToKeypadMap[i][0],
       
   598                                TDialerButtonToKeypadMap[i][1],         
       
   599                                KKeyPadButtons[i],
       
   600                                KKeyPadButtonsMasks[i] );
       
   601         CleanupStack::Pop( button );
       
   602         iButtons.Append( button );                      
       
   603         button->Control()->SetMopParent( this );
       
   604         button->Control()->SetParent( this );    
       
   605         button->Control()->SetContainerWindowL( *this );
       
   606         button->Control()->SetObserver( this );    
       
   607         button->Control()->ActivateL();
       
   608         AknsUtils::RegisterControlPosition( button->Control() );   
       
   609         }     
       
   610     DIALER_PRINT("KeyPadContainer::CreateButtonsL>");        
       
   611     }
       
   612 
       
   613 // ---------------------------------------------------------------------------
       
   614 // CDialerKeyPadContainer::HandleControlEventL
       
   615 //
       
   616 // Handles an event from an observed button item.
       
   617 // Finds the pressed button and generates key press event, which
       
   618 // is handled by parent control.
       
   619 //
       
   620 // ---------------------------------------------------------------------------
       
   621 //
       
   622 void CDialerKeyPadContainer::HandleControlEventL( CCoeControl* aControl,
       
   623                                                 TCoeEvent aEventType )
       
   624     {
       
   625     DIALER_PRINTF("KeyPadContainer::HandleControlEventL.EventType=",
       
   626                  (TInt)aEventType);
       
   627     
       
   628    if ( aEventType == EEventStateChanged   || 
       
   629         aEventType == EEventRequestCancel ||
       
   630         aEventType == EEventRequestExit)
       
   631         
       
   632         {
       
   633         // Find tapped control 
       
   634 
       
   635         CDialerKeyPadButton* tappedButton = NULL;
       
   636         for ( TInt i=0; i < iButtons.Count(); i++ )
       
   637             {
       
   638             if ( iButtons[i]->Control() == aControl )
       
   639                 {
       
   640                 tappedButton = iButtons[i];
       
   641                 break;
       
   642                 }    
       
   643             }
       
   644             
       
   645         // Send key event to phone.
       
   646         TKeyEvent keyEvent;
       
   647         keyEvent.iScanCode = tappedButton->ScanCode();
       
   648         keyEvent.iCode = tappedButton->KeyCode();
       
   649         keyEvent.iModifiers = 0;
       
   650         keyEvent.iRepeats = 0;  
       
   651              
       
   652         switch ( aEventType )
       
   653             {
       
   654             case EEventRequestExit:
       
   655             case EEventRequestCancel:
       
   656                 {
       
   657                 DIALER_PRINT("HandleControlEventL.EEventRequestExit");
       
   658                 iButtonPressedDown = EFalse;
       
   659                 keyEvent.iCode = 0;
       
   660                 ControlEnv()->SimulateKeyEventL( keyEvent, EEventKeyUp );
       
   661                 }
       
   662                 break;
       
   663             case EEventStateChanged:
       
   664                 {    
       
   665                 DIALER_PRINT("HandleControlEventL.EEventStateChanged");
       
   666                 iButtonPressedDown = ETrue;
       
   667 
       
   668                 iParentControl.PrepareForFocusGainL();
       
   669 
       
   670                 ControlEnv()->SimulateKeyEventL( keyEvent, EEventKeyDown );    
       
   671 
       
   672                 if( iButtonPressedDown )
       
   673                     {
       
   674                     // Send event key if key havent be lifted up already
       
   675                     ControlEnv()->SimulateKeyEventL( keyEvent, EEventKey );
       
   676                     }
       
   677                 }
       
   678                 break;
       
   679             default:
       
   680             break;
       
   681             }
       
   682         }
       
   683     DIALER_PRINT("KeyPadContainer::HandleControlEventL>");        
       
   684     }
       
   685     
       
   686 // ---------------------------------------------------------------------------
       
   687 // CDialerKeyPadContainer::HandleResourceChange
       
   688 //
       
   689 // Forwards skin change event to buttons
       
   690 //
       
   691 // ---------------------------------------------------------------------------
       
   692 //
       
   693 void CDialerKeyPadContainer::HandleResourceChange( TInt aType )
       
   694     {
       
   695     if ( aType == KAknsMessageSkinChange )
       
   696         {    
       
   697         for ( TInt i=0; i < iButtons.Count(); i++ )
       
   698             {
       
   699             (( CDialerKeyPadButton* )iButtons[i])->HandleResourceChange( 
       
   700                                                                     aType );
       
   701             }
       
   702         }
       
   703     }
       
   704 
       
   705 // ---------------------------------------------------------------------------
       
   706 // CDialerKeyPadContainer::MakeVisible
       
   707 //
       
   708 // Called when dialer control come visible or unvisible
       
   709 //
       
   710 // ---------------------------------------------------------------------------
       
   711 //
       
   712 void CDialerKeyPadContainer::MakeVisible( TBool aVisible )
       
   713     {
       
   714     // This is needed when dialer control disappeares during keypress. 
       
   715     // Last pressed pointer event must be forwarted to framework 
       
   716     // as pointer up event. Thus button is set to unpressed state etc. 
       
   717     // 
       
   718     if ( !aVisible && iButtonPressedDown )
       
   719         {    
       
   720         iPointerEvent.iType = TPointerEvent::EButton1Up;
       
   721         TRAP_IGNORE( HandlePointerEventL( iPointerEvent ) );
       
   722         }    
       
   723     CCoeControl::MakeVisible( aVisible );        
       
   724     }
       
   725 
       
   726 
       
   727 // ---------------------------------------------------------------------------
       
   728 // CDialerKeyPadContainer::HandleGainingForeground
       
   729 //
       
   730 //
       
   731 // ---------------------------------------------------------------------------
       
   732 //
       
   733 void CDialerKeyPadContainer::HandleGainingForeground()
       
   734     {
       
   735     
       
   736     }
       
   737     
       
   738 // ---------------------------------------------------------------------------
       
   739 // CDialerKeyPadContainer::HandleLosingForeground
       
   740 //
       
   741 //
       
   742 // ---------------------------------------------------------------------------
       
   743 //
       
   744 void CDialerKeyPadContainer::HandleLosingForeground()
       
   745     {
       
   746     // This is needed when dialer control disappeares during keypress. 
       
   747     // Last pressed pointer event must be forwarted to framework 
       
   748     // as pointer up event. Thus button is set to unpressed state etc. 
       
   749     // 
       
   750     if ( iButtonPressedDown )
       
   751         {    
       
   752         iPointerEvent.iType = TPointerEvent::EButton1Up;
       
   753         TRAP_IGNORE( HandlePointerEventL( iPointerEvent ) );
       
   754         }    
       
   755     }
       
   756 
       
   757 // ---------------------------------------------------------------------------
       
   758 // CDialerKeyPadContainer::EnableTactileFeedback
       
   759 //
       
   760 //
       
   761 // ---------------------------------------------------------------------------
       
   762 //
       
   763 void CDialerKeyPadContainer::EnableTactileFeedback( const TBool aEnable )
       
   764     {
       
   765     for ( TInt i=0; i < iButtons.Count(); i++ )
       
   766         {
       
   767         (( CDialerKeyPadButton* )iButtons[i])->EnableAudioFeedback( aEnable );
       
   768         }
       
   769 
       
   770     }
       
   771 // End of File