uifw/AvKon/src/aknkeypad.cpp
changeset 0 2f259fa3e83a
child 51 fcdfafb36fe7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Avkon keypad 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknlayoutscalable_apps.cdl.h>
       
    20 #include <aknlayoutscalable_avkon.cdl.h>
       
    21 #include <layoutmetadata.cdl.h>
       
    22 #include <aknbutton.h>
       
    23 #include <AknsDrawUtils.h>
       
    24 #include <AknBidiTextUtils.h>
       
    25 #include <AknsFrameBackgroundControlContext.h>
       
    26 #include <aknappui.h>
       
    27 #include "aknkeypad.h"
       
    28 
       
    29 #include <AknTasHook.h> // for testability hooks
       
    30 #include <e32property.h>
       
    31 #include <PtiDefs.h>                //keys
       
    32 #include <featmgr.h>                //FeatureManager
       
    33 #include <AvkonInternalCRKeys.h>
       
    34 
       
    35 
       
    36 CAknKeypad* CAknKeypad::NewL( CCoeControl& aParent, TInt aQueryType )
       
    37     {
       
    38     CAknKeypad* self = new ( ELeave ) CAknKeypad;
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL( aParent, aQueryType );
       
    41     CleanupStack::Pop(); // self
       
    42     AKNTASHOOK_ADDL( self, "CAknKeypad" );
       
    43     return self;
       
    44     }
       
    45 
       
    46 CAknKeypad::~CAknKeypad()
       
    47     {
       
    48     AKNTASHOOK_REMOVE();
       
    49     }
       
    50 
       
    51 void CAknKeypad::SizeChanged()
       
    52     {
       
    53     TBool landscape = Layout_Meta_Data::IsLandscapeOrientation();
       
    54          
       
    55     TAknLayoutScalableParameterLimits limits = AknLayoutScalable_Apps::cell_vitu2_itu_pane_ParamLimits( 0 );
       
    56 
       
    57     for ( TInt row = 0; row <= limits.LastRow(); ++row )
       
    58         {
       
    59         for ( TInt column = 0; column <= limits.LastColumn(); ++column )
       
    60             {
       
    61             TAknLayoutRect layoutRect;
       
    62             layoutRect.LayoutRect( Rect(), AknLayoutScalable_Apps::cell_vitu2_itu_pane( landscape ? 1 : 0, column, row ).LayoutLine() );
       
    63   
       
    64       		TAknLayoutRect layoutRect2;
       
    65             layoutRect2.LayoutRect( layoutRect.Rect(), AknLayoutScalable_Apps::bg_button_pane_cp010( landscape ? 3 : 0 ).LayoutLine() );
       
    66         
       
    67             Components().At( row * ( limits.LastColumn() + 1 ) + column ).iControl->SetRect( layoutRect2.Rect() );
       
    68             }
       
    69         }
       
    70     }
       
    71 
       
    72 CAknKeypad::CAknKeypad()
       
    73     {
       
    74     }
       
    75 
       
    76 void CAknKeypad::ConstructL( CCoeControl& aParent, TInt aQueryType )
       
    77     {
       
    78     SetContainerWindowL( aParent );
       
    79     InitComponentArrayL();
       
    80     
       
    81     iQueryType = aQueryType;
       
    82     
       
    83     // create as many buttons as there are rows & columns
       
    84     TAknLayoutScalableParameterLimits limits = AknLayoutScalable_Apps::cell_vitu2_itu_pane_ParamLimits( 0 );
       
    85     
       
    86     TInt count = ( limits.LastRow() + 1 ) * ( limits.LastColumn() + 1 );
       
    87     
       
    88     const TChar KCharArray[] = 
       
    89     	{
       
    90     	'1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#'
       
    91     	};
       
    92     
       
    93     const TInt KScanCodeArray[] =
       
    94     	{
       
    95     	49, 50, 51, 52, 53, 54, 55, 56, 57, EStdKeyNkpAsterisk, 48, EStdKeyHash
       
    96     	};
       
    97     
       
    98     for ( TInt i = 0; i < count; ++i )
       
    99         {
       
   100         TBuf<1> keyChar;
       
   101         keyChar.Append( KCharArray[i] );
       
   102       
       
   103         TInt scanCode = KScanCodeArray[ i ];
       
   104         CAknKeypadButton* button = CAknKeypadButton::NewL( keyChar, scanCode, this );
       
   105         CleanupStack::PushL( button );
       
   106 
       
   107         button->SetFocusing( EFalse );
       
   108         
       
   109         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   110         
       
   111         TRgb color; 
       
   112         AknsUtils::GetCachedColor( skin, color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG68 );
       
   113    
       
   114   		button->OverrideColorL( EColorButtonText, color );
       
   115         button->OverrideColorL( EColorButtonTextPressed, color );
       
   116         button->OverrideColorL( EColorButtonTextDimmed, color );
       
   117         
       
   118         button->SetBackgroundIds( KAknsIIDQsnFrKeypadButtonNormal,
       
   119         	KAknsIIDQsnFrKeypadButtonPressed, KAknsIIDQsnFrKeypadButtonInactive,
       
   120         	KAknsIIDQsnFrKeypadButtonPressed, KAknsIIDQsnFrKeypadButtonInactive );
       
   121      
       
   122      	// Hack
       
   123         
       
   124         if ( i == 1)
       
   125         	{
       
   126         	button->SetUpperAndLowerTextL(_L("ABC"), _L("abc"));
       
   127        		}
       
   128         else if ( i == 2)
       
   129         	{
       
   130         	button->SetUpperAndLowerTextL(_L("DEF"), _L("def"));
       
   131         	}
       
   132         else if ( i == 3)
       
   133         	{
       
   134         	button->SetUpperAndLowerTextL(_L("GHI"), _L("ghi"));
       
   135         	}
       
   136         else if ( i == 4)
       
   137         	{
       
   138         	button->SetUpperAndLowerTextL(_L("JKL"), _L("jkl"));
       
   139         	}
       
   140         else if ( i == 5)
       
   141         	{
       
   142         	button->SetUpperAndLowerTextL(_L("MNO"), _L("mno"));
       
   143         	}	
       
   144         else if ( i == 6)
       
   145         	{
       
   146         	button->SetUpperAndLowerTextL(_L("PQRS"), _L("pqrs"));
       
   147         	}
       
   148         else if ( i == 7)
       
   149         	{
       
   150         	button->SetUpperAndLowerTextL(_L("TUV"), _L("tuv"));
       
   151         	}
       
   152         else if ( i == 8)
       
   153         	{
       
   154         	button->SetUpperAndLowerTextL(_L("WXYZ"), _L("wxyz"));
       
   155         	}
       
   156         else if ( i == 9)
       
   157         	{
       
   158         	button->SetUpperAndLowerTextL(_L("+"), _L("+"));
       
   159         	}
       
   160         else if ( i == 10)
       
   161         	{
       
   162         	TBuf<16> txt;
       
   163         	txt.Append( TChar(0xf812) );
       
   164         	button->SetUpperAndLowerTextL(txt, txt);
       
   165         	}
       
   166         else if ( i == 11)
       
   167         	{
       
   168         	TBuf<16> txt;
       
   169         	txt.Append( TChar(0x2191) );
       
   170         	button->SetUpperAndLowerTextL(txt, txt);
       
   171         	}
       
   172         	
       
   173         // End of Hack	
       
   174          
       
   175         
       
   176         if( scanCode == EStdKeyNkpAsterisk && aQueryType != ECodeLayout && aQueryType != EDataLayout)
       
   177         	{
       
   178             button->SetDimmed( ETrue );  
       
   179             }
       
   180         else if( scanCode == EStdKeyHash && aQueryType != EPinLayout && aQueryType != ECodeLayout && aQueryType != EDataLayout)
       
   181         	{
       
   182         	button->SetDimmed( ETrue );
       
   183         	}
       
   184         
       
   185         
       
   186         	
       
   187         CleanupStack::Pop(); // button
       
   188         
       
   189         Components().AppendLC( button, i );
       
   190         CleanupStack::Pop(); // button
       
   191         }
       
   192     }
       
   193     
       
   194     
       
   195 void CAknKeypad::SetState(TAknEditingState aState)
       
   196 	{
       
   197 	iState = aState;
       
   198 	Window().Invalidate( Rect() );
       
   199 	}
       
   200 	
       
   201 TAknEditingState CAknKeypad::State()
       
   202 	{
       
   203 	return iState;
       
   204 	}
       
   205 	
       
   206 TInt CAknKeypad::QueryType()
       
   207 	{
       
   208 	return iQueryType;	
       
   209 	}
       
   210     
       
   211     
       
   212 // CAknKeypadButton
       
   213         
       
   214 CAknKeypadButton* CAknKeypadButton::NewL( const TDesC& aText, const TInt aScanCode, CAknKeypad* aKeypad )
       
   215 	{
       
   216  	CAknKeypadButton* self = new (ELeave) CAknKeypadButton( KAknButtonKeyRepeat, aScanCode, aKeypad );
       
   217     CleanupStack::PushL( self );
       
   218     self->ConstructL( aText );
       
   219     CleanupStack::Pop( self );
       
   220     AKNTASHOOK_ADDL( self, "CAknKeypadButton" );
       
   221     return self;
       
   222 	}
       
   223 
       
   224 CAknKeypadButton::~CAknKeypadButton()
       
   225     {
       
   226     AKNTASHOOK_REMOVE();
       
   227     delete iUpperText;
       
   228     delete iLowerText;
       
   229     }
       
   230     
       
   231 CAknKeypadButton::CAknKeypadButton( const TInt aFlags, const TInt aScanCode, CAknKeypad* aKeypad ):
       
   232 	CAknButton( aFlags ), iScanCode(aScanCode), iKeypad(aKeypad)
       
   233     {
       
   234     }
       
   235     
       
   236 void CAknKeypadButton::ConstructL( const TDesC& aText )
       
   237     {
       
   238     CAknButton::ConstructL( NULL, NULL, NULL, NULL, aText, KNullDesC, 0 );
       
   239     }
       
   240     
       
   241     
       
   242     
       
   243 void CAknKeypadButton::SetUpperAndLowerTextL( const TDesC& aUpperText, const TDesC& aLowerText )
       
   244     {
       
   245     delete iUpperText;
       
   246     delete iLowerText;
       
   247     
       
   248     iUpperText = NULL;
       
   249     iLowerText = NULL;
       
   250 
       
   251     iUpperText = aUpperText.AllocL();
       
   252     iLowerText = aLowerText.AllocL();
       
   253     }    
       
   254 
       
   255 void CAknKeypadButton::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   256 	{
       
   257 	CAknButton::HandlePointerEventL( aPointerEvent);
       
   258 	
       
   259 	if ( AknLayoutUtils::PenEnabled() )
       
   260 		{
       
   261 		TInt activeKeypad =0;
       
   262         RProperty::Get(KCRUidAvkon, KAknKeyBoardLayout,activeKeypad);
       
   263         
       
   264         
       
   265         switch ( aPointerEvent.iType )
       
   266             {
       
   267             case TPointerEvent::EButton1Down:
       
   268                 {
       
   269                 TRawEvent event;
       
   270                	event.Set( TRawEvent::EKeyDown, iScanCode);
       
   271                	event.SetTip( ETrue );
       
   272                	
       
   273                	if (iEikonEnv->AppUi())
       
   274 					{
       
   275 					static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->DisableNextKeySound( iScanCode );
       
   276 					}
       
   277                	
       
   278                 if(activeKeypad != EPtiKeyboard12Key)
       
   279 				    {				
       
   280               	    // Security lock code add, begin:
       
   281 				    TKeyEvent keyEvent;
       
   282 				    // Fep manager need check the event, the modifiers and the event type must the same
       
   283 				    // And other parts must not use the same modifiers!!!
       
   284              	    keyEvent.iModifiers = EModifierNumLock | EModifierKeypad | EModifierSpecial;
       
   285 							ControlEnv()->SimulateKeyEventL( keyEvent, EEventKeyDown );
       
   286 				    // Security lock code add, end. 
       
   287 				    }
       
   288 
       
   289             	CCoeEnv::Static()->WsSession().SimulateRawEvent( event );
       
   290             	
       
   291             	if ( iKeypad->QueryType() != ECodeLayout && iKeypad->QueryType() != EDataLayout)
       
   292                 	{
       
   293             		TRawEvent event;
       
   294                		event.Set( TRawEvent::EKeyUp, iScanCode);
       
   295                		event.SetTip( ETrue );
       
   296             		CCoeEnv::Static()->WsSession().SimulateRawEvent( event );
       
   297                 	}
       
   298                 break;	
       
   299                 }
       
   300 
       
   301             case TPointerEvent::EButton1Up:
       
   302                 {
       
   303                 if ( iKeypad->QueryType() == ECodeLayout || iKeypad->QueryType() == EDataLayout)
       
   304                 	{
       
   305                 	TRawEvent event;
       
   306                		event.Set( TRawEvent::EKeyUp, iScanCode);
       
   307                		event.SetTip( ETrue );
       
   308             		CCoeEnv::Static()->WsSession().SimulateRawEvent( event );
       
   309                 	}
       
   310      
       
   311                 break;
       
   312                 }
       
   313 
       
   314             default:
       
   315                 break;
       
   316             }
       
   317        }	
       
   318 	}
       
   319 	
       
   320 	
       
   321 void CAknKeypadButton::Draw( const TRect& /*aRect*/ ) const
       
   322     {
       
   323     TRect rect = Rect();
       
   324 
       
   325     TAknLayoutRect centerLayout;
       
   326     centerLayout.LayoutRect( rect,
       
   327         AknLayoutScalable_Avkon::toolbar_button_pane_g1().LayoutLine() );
       
   328     TRect innerRect = centerLayout.Rect();
       
   329 
       
   330     CWindowGc& gc = SystemGc();
       
   331     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   332 
       
   333  	TAknsItemID frameId = KAknsIIDQsnFrKeypadButtonNormal;
       
   334 
       
   335     if ( iButtonPressed )
       
   336     	{
       
   337         frameId = KAknsIIDQsnFrKeypadButtonPressed;
       
   338     	}
       
   339     else if ( IsDimmed())
       
   340         {
       
   341     	frameId = KAknsIIDQsnFrKeypadButtonInactive;
       
   342         }
       
   343         
       
   344     iBgContext->SetFrame( frameId );
       
   345     iBgContext->SetCenter( frameId );
       
   346     iBgContext->SetFrameRects( rect, innerRect );
       
   347 
       
   348     if ( !AknsDrawUtils::Background( skin, iBgContext, NULL, gc, rect, KAknsDrawParamNoClearUnderImage ) )
       
   349         {
       
   350         gc.SetBrushColor( KRgbRed );
       
   351         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   352         gc.DrawRect( rect );
       
   353         }
       
   354     gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   355 
       
   356 
       
   357 	CAknButtonState* state = State();
       
   358 	TBool landscape = Layout_Meta_Data::IsLandscapeOrientation();
       
   359     
       
   360     // Draw left text
       
   361     TAknEditingState editingState = iKeypad->State();
       
   362     
       
   363     TAknTextComponentLayout leftLayout;
       
   364     leftLayout = AknLayoutScalable_Apps::cell_vitu2_itu_pane_t1( landscape ? 3 : 0  );
       
   365         
       
   366  	DrawText(gc, state->Text(), leftLayout, 1);	
       
   367  	
       
   368  	// Draw right text
       
   369  	
       
   370  	TAknTextComponentLayout rightLayout = AknLayoutScalable_Apps::cell_vitu2_itu_pane_t2( landscape ? 2 : 0 );
       
   371  	
       
   372  	if (editingState == EMultitapLower && iLowerText)
       
   373  		{
       
   374  		DrawText(gc, *iLowerText, rightLayout, 0);
       
   375  		}
       
   376  	else if ( (editingState == EMultitapUpper || 
       
   377  	           editingState == EMultitapShifted || editingState == EQwertyShift) 
       
   378  	           && iUpperText)
       
   379  		{
       
   380  		DrawText(gc, *iUpperText, rightLayout, 0);
       
   381  		}
       
   382     }
       
   383 
       
   384 
       
   385 
       
   386 
       
   387 void CAknKeypadButton::DrawText( CWindowGc& aGc, const TDesC& aText, TAknTextComponentLayout& aLayout, TInt aMargin ) const
       
   388     {
       
   389     TAknLayoutText layoutText;
       
   390     layoutText.LayoutText(Rect(), aLayout.LayoutLine() );
       
   391     
       
   392     const CFont* font = layoutText.Font();
       
   393     TRect textRect = layoutText.TextRect();
       
   394     
       
   395     aGc.UseFont( font );
       
   396     
       
   397     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   398 	TRgb color( layoutText.Color() );
       
   399 	
       
   400     if ( IsDimmed() )
       
   401         {
       
   402         color = iEikonEnv->ControlColor( EColorButtonText, *this );
       
   403         color.SetAlpha( 77 );
       
   404         }
       
   405     else if ( iButtonPressed )
       
   406         {
       
   407         color = iEikonEnv->ControlColor( EColorButtonTextPressed, *this );
       
   408         }
       
   409     else
       
   410         {
       
   411         color = iEikonEnv->ControlColor( EColorButtonText, *this );
       
   412         }
       
   413     aGc.SetPenColor( color);
       
   414     
       
   415     // NOTE: Layout data not correct, add some space for text
       
   416     textRect.iBr.iX += aMargin;
       
   417     textRect.iTl.iX -= aMargin;
       
   418     	
       
   419     
       
   420     // buffer for visually ordered text
       
   421     TBuf<255 + KAknBidiExtraSpacePerLine> visualText; 
       
   422     TInt clipWidth = textRect.Width();
       
   423 
       
   424     // bidi processing - using AknBidiTextUtils.
       
   425     AknBidiTextUtils::ConvertToVisualAndClip(
       
   426         aText,
       
   427         visualText,
       
   428         *font,
       
   429         clipWidth,
       
   430         clipWidth );
       
   431 
       
   432     TInt baselineOffset = 0;
       
   433     switch ( iVerticalAlignment )
       
   434         {
       
   435         case ETop:
       
   436             baselineOffset = font->AscentInPixels();
       
   437             break;
       
   438 
       
   439         case EBottom:
       
   440             baselineOffset = textRect.Height();
       
   441             break;
       
   442 
       
   443         default:  // centered
       
   444             baselineOffset = font->AscentInPixels() +
       
   445                            ( textRect.Height() - font->AscentInPixels() ) / 2;
       
   446         }
       
   447         
       
   448     aGc.DrawText( visualText, textRect, baselineOffset, layoutText.Align() );    
       
   449     }