uifw/AvKon/AknKeyRotator/implementation/AknKeyRotatorImpl.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Key rotation implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "AknKeyRotatorImpl.h"
       
    21 
       
    22 #include <UikonInternalPSKeys.h>
       
    23 #include <PSVariables.h>
       
    24 #include <aknpriv.rsg>
       
    25 #include <barsread.h>
       
    26 #include <barsc.h>
       
    27 #include <bautils.h>
       
    28 #include <w32adll.h>
       
    29 
       
    30 // CONSTANTS
       
    31 _LIT( KAknPrivRscFilePath,  "z:\\resource\\AknPriv.rsc");
       
    32 const TUint KAknModifiersMask = 0xFFFF0000;
       
    33 // Path to wsini.ini
       
    34 _LIT( KAknWsini, "z:\\system\\data\\wsini.ini" );
       
    35 // Keyword for key rotator compensation.
       
    36 // Syntax: S60_KEYROTATOR <value>
       
    37 //         where <value> is one of the following: -270, -180, -90, -0, 0, 90, 180, 270
       
    38 //         to specify <value> as compensation
       
    39 //         S60_KEYROTATOR DISABLED
       
    40 //         to disable key rotator
       
    41 // 
       
    42 _LIT( KAknKeyRotatorKey, "S60_KEYROTATOR" );
       
    43 _LIT( KAknKeyRotatorDisabled, "DISABLED");
       
    44 
       
    45 // Scan codes for diagonal directions 0xc9 .. 0xcc
       
    46 const TInt KAknStdLeftUpArrow = EStdKeyDevice10;
       
    47 const TInt KAknStdRightUpArrow = EStdKeyDevice11;
       
    48 const TInt KAknStdRightDownArrow = EStdKeyDevice12;
       
    49 const TInt KAknStdLeftDownArrow = EStdKeyDevice13;
       
    50 
       
    51 // Configure
       
    52 #define KAknRotateArrowKeys 1
       
    53 #define KAknRotateInKeyboardDriver 0
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS ===============================
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CAknKeyRotatorImpl::CAknKeyRotatorImpl
       
    59 // 1st phase constructor
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CAknKeyRotatorImpl::CAknKeyRotatorImpl()
       
    63     {
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CAknKeyRotatorImpl::ConstructL
       
    68 // 2nd phase constructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CAknKeyRotatorImpl::ConstructL()
       
    72     {
       
    73     if ( KAknRotateInKeyboardDriver )
       
    74         {
       
    75         LoadHwStateRotationsL();
       
    76         }
       
    77     
       
    78     User::LeaveIfError( iProperty.Attach( KPSUidUikon, KUikLayoutState ) );
       
    79     
       
    80     TRAPD( err, iKeyRotatorCompensation = GetKeyRotatorCompensationL() );
       
    81     if ( err != KErrNone )
       
    82         {
       
    83         iKeyRotatorCompensation = 0;
       
    84         }
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CAknKeyRotatorImpl::NewL
       
    89 // Two-phased constructor
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CAknKeyRotatorImpl* CAknKeyRotatorImpl::NewL()
       
    93     {
       
    94     CAknKeyRotatorImpl* self = new( ELeave ) CAknKeyRotatorImpl;
       
    95     
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL();
       
    98     CleanupStack::Pop();
       
    99 
       
   100     return self;
       
   101     }
       
   102     
       
   103 // -----------------------------------------------------------------------------
       
   104 // CAknKeyRotatorImpl::~CAknKeyRotatorImpl
       
   105 // Destruction
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CAknKeyRotatorImpl::~CAknKeyRotatorImpl()
       
   109     {
       
   110     iHwRotations.Close();
       
   111     iProperty.Close();
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CAknKeyRotatorImpl::LoadHwStateRotationsL
       
   116 // Reads the HW states from the AknPriv.rsc to an array.
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CAknKeyRotatorImpl::LoadHwStateRotationsL()
       
   120     {
       
   121     // Find the language specific resource file and then load it.
       
   122     RResourceFile resourceFile;
       
   123     RFs fsSession;
       
   124     User::LeaveIfError( fsSession.Connect() );
       
   125     CleanupClosePushL( fsSession );
       
   126     
       
   127     TFileName resourceFileName (KAknPrivRscFilePath);
       
   128     BaflUtils::NearestLanguageFile( fsSession, resourceFileName );
       
   129     resourceFile.OpenL(fsSession, resourceFileName);
       
   130 
       
   131     CleanupClosePushL( resourceFile );
       
   132     resourceFile.ConfirmSignatureL(0);
       
   133     
       
   134     // Read resources to a buffer. The resource definition for the target and
       
   135     // emulator are a bit different.
       
   136     HBufC8* res;
       
   137 #ifdef __WINS__
       
   138     res = resourceFile.AllocReadLC( R_AKNPRIV_HARDWARE_STATE_SCREEN_MAP_EMUL );
       
   139 #else
       
   140     res = resourceFile.AllocReadLC( R_AKNPRIV_HARDWARE_STATE_SCREEN_MAP );
       
   141 #endif
       
   142     
       
   143     TResourceReader reader;
       
   144     reader.SetBuffer(res);
       
   145     
       
   146     // Read the entires. We are only interrested about the hwRotation.
       
   147     TInt count = reader.ReadInt16();
       
   148     for (TInt ii=0; ii<count; ii++)
       
   149         {
       
   150         /*TInt state =*/ reader.ReadInt16(); // Assumption (state == ii)
       
   151         /*TInt width =*/ reader.ReadInt16();
       
   152         /*TInt height =*/ reader.ReadInt16();
       
   153         CFbsBitGc::TGraphicsOrientation hwRotation = 
       
   154             static_cast<CFbsBitGc::TGraphicsOrientation>(reader.ReadInt16());
       
   155         /*CFbsBitGc::TGraphicsOrientation altRotation =*/ 
       
   156             static_cast<CFbsBitGc::TGraphicsOrientation>(reader.ReadInt16());
       
   157         
       
   158         User::LeaveIfError( iHwRotations.Append( hwRotation ) );
       
   159         }
       
   160     
       
   161     CleanupStack::PopAndDestroy(res);
       
   162     CleanupStack::PopAndDestroy(&resourceFile); // resourceFile.Close();  
       
   163     CleanupStack::PopAndDestroy(&fsSession); // fsSession.Close();
       
   164     }
       
   165 
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CAknKeyRotatorImpl::CheckRotation
       
   169 // Check if this is our own generated event.
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 TBool CAknKeyRotatorImpl::CheckRotation( 
       
   173     const TRawEvent &aRawEvent,
       
   174     MAnimGeneralFunctions& aAnimGeneralFunctions )
       
   175     {
       
   176     if ( KMaxTInt == iKeyRotatorCompensation )
       
   177         {
       
   178         // Key rotator is disabled - wsini.ini contains "S60_KEYROTATOR DISABLED".
       
   179         return EFalse;
       
   180         }
       
   181 
       
   182     // Check first that we are not processing just generated event again.
       
   183     if ( iRotatedRawEvent )
       
   184         {
       
   185         // This is the generated avent from the last round. Do not modify again.
       
   186         iRotatedRawEvent = EFalse;
       
   187         }
       
   188     else if ( aRawEvent.Type() == TRawEvent::EKeyDown || 
       
   189               aRawEvent.Type() == TRawEvent::EKeyUp || 
       
   190               aRawEvent.Type() == TRawEvent::EKeyRepeat )
       
   191         {
       
   192         // We get new event. Let's see if we need to modify that.
       
   193         TRawEvent newRawEvent( aRawEvent );
       
   194         DoCheckRotation( newRawEvent, aAnimGeneralFunctions );
       
   195         if ( aRawEvent.ScanCode() != newRawEvent.ScanCode() )   
       
   196             {
       
   197             // Generate new event,
       
   198             iRotatedRawEvent = ETrue;
       
   199             aAnimGeneralFunctions.PostRawEvent( newRawEvent ); // Calls this function again!
       
   200             return ETrue;
       
   201             }
       
   202         }
       
   203     
       
   204     return EFalse;
       
   205     }
       
   206     
       
   207     
       
   208 // -----------------------------------------------------------------------------
       
   209 // CAknKeyRotatorImpl::DoCheckRotation
       
   210 // Checks the scan codes and the orientations. Decides if we need to generate
       
   211 // a new raw event.
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CAknKeyRotatorImpl::DoCheckRotation(
       
   215     TRawEvent& aNewRawEvent,
       
   216     MAnimGeneralFunctions& aAnimGeneralFunctions )
       
   217     {   
       
   218     // Current implementation is only for arrow keys
       
   219     if ( !KAknRotateArrowKeys )
       
   220         {
       
   221         return;
       
   222         }
       
   223     
       
   224     // Do not rotate external keyboard events.
       
   225     if ( aNewRawEvent.ScanCode() & EModifierKeyboardExtend )
       
   226         {
       
   227         return;
       
   228         }    
       
   229         
       
   230     // Also check only the arrow keys
       
   231     if ( !IsArrowScanCode( aNewRawEvent.ScanCode ()) )
       
   232         {
       
   233         return;
       
   234         }
       
   235     
       
   236     // If 'newCode' is changed something else than -1, 
       
   237     // a new event will be generated
       
   238     TInt newCode = KErrNotFound;
       
   239     
       
   240     // Check the rotation on down event. Use the same rotation for up event.
       
   241     
       
   242     // finalRotation variable at the end of this function is used to determine
       
   243     // the new scan code.
       
   244     CFbsBitGc::TGraphicsOrientation finalRotation = 
       
   245         CFbsBitGc::EGraphicsOrientationNormal;
       
   246     
       
   247     if ( aNewRawEvent.Type() == TRawEvent::EKeyUp || 
       
   248          aNewRawEvent.Type() == TRawEvent::EKeyRepeat )
       
   249         {
       
   250         // Use the same orintation for up event.
       
   251         finalRotation = iUsedRotationForDownEvent;
       
   252         }
       
   253     else // For down event, find out the rotation.
       
   254         {
       
   255         // Get SW screen rotation compared to the keyboard i.e. app orientation.
       
   256         CFbsBitGc::TGraphicsOrientation swRotation = 
       
   257             aAnimGeneralFunctions.ScreenDevice()->Orientation();
       
   258     
       
   259         // Get HW screen rotation
       
   260         CFbsBitGc::TGraphicsOrientation hwRotation = 
       
   261             CFbsBitGc::EGraphicsOrientationNormal;
       
   262         TInt hwState;
       
   263         if ( KAknRotateInKeyboardDriver && 
       
   264              ( iProperty.Get(hwState) == KErrNone ) )
       
   265             {
       
   266             if ( hwState < iHwRotations.Count() )
       
   267                 {
       
   268                 hwRotation = iHwRotations[hwState];
       
   269                 }
       
   270             }
       
   271     
       
   272         // Calculate the difference
       
   273         TInt finalRotationInt = swRotation*90;
       
   274     
       
   275         if ( KAknRotateInKeyboardDriver )
       
   276             {
       
   277             // If the rotation is also done in the driver level, 
       
   278             // the rotation needs to be compensated so we do not 
       
   279             // rotate twice.
       
   280             finalRotationInt -= hwRotation*90;
       
   281             }
       
   282     
       
   283         finalRotationInt += iKeyRotatorCompensation;
       
   284 
       
   285         // Keep the value between 0 and 270.
       
   286         while ( finalRotationInt < 0 )
       
   287             {
       
   288             finalRotationInt += 360;
       
   289             }
       
   290         while ( finalRotationInt > 270 )
       
   291             {
       
   292             finalRotationInt -= 360;
       
   293             }
       
   294             
       
   295         finalRotation = 
       
   296             (CFbsBitGc::TGraphicsOrientation)( finalRotationInt / 90 );
       
   297 
       
   298         iUsedRotationForDownEvent = finalRotation;
       
   299         }
       
   300     
       
   301     // Find the new scan code from the rotation.
       
   302     switch( aNewRawEvent.ScanCode() )
       
   303         {
       
   304         case EStdKeyLeftArrow:
       
   305             switch ( finalRotation )
       
   306                 {
       
   307                 case CFbsBitGc::EGraphicsOrientationRotated90:
       
   308                     newCode = EStdKeyDownArrow;
       
   309                     break;
       
   310                 case CFbsBitGc::EGraphicsOrientationRotated180:
       
   311                     newCode = EStdKeyRightArrow;
       
   312                     break;
       
   313                 case CFbsBitGc::EGraphicsOrientationRotated270:
       
   314                     newCode = EStdKeyUpArrow;
       
   315                     break;
       
   316                 default:
       
   317                     break;
       
   318                 }
       
   319             break;
       
   320         case EStdKeyDownArrow:
       
   321             switch ( finalRotation )
       
   322                 {
       
   323                 case CFbsBitGc::EGraphicsOrientationRotated90:
       
   324                     newCode = EStdKeyRightArrow;
       
   325                     break;
       
   326                 case CFbsBitGc::EGraphicsOrientationRotated180:
       
   327                     newCode = EStdKeyUpArrow;
       
   328                     break;
       
   329                 case CFbsBitGc::EGraphicsOrientationRotated270:
       
   330                     newCode = EStdKeyLeftArrow;
       
   331                     break;
       
   332                 default:
       
   333                     break;
       
   334                 }
       
   335             break;
       
   336         case EStdKeyRightArrow:
       
   337             switch ( finalRotation )
       
   338                 {
       
   339                 case CFbsBitGc::EGraphicsOrientationRotated90:
       
   340                     newCode = EStdKeyUpArrow;
       
   341                     break;
       
   342                 case CFbsBitGc::EGraphicsOrientationRotated180:
       
   343                     newCode = EStdKeyLeftArrow;
       
   344                     break;
       
   345                 case CFbsBitGc::EGraphicsOrientationRotated270:
       
   346                     newCode = EStdKeyDownArrow;
       
   347                     break;
       
   348                 default:
       
   349                     break;
       
   350                 }
       
   351             break;
       
   352         case EStdKeyUpArrow:
       
   353             switch ( finalRotation )
       
   354                 {
       
   355                 case CFbsBitGc::EGraphicsOrientationRotated90:
       
   356                     newCode = EStdKeyLeftArrow;
       
   357                     break;
       
   358                 case CFbsBitGc::EGraphicsOrientationRotated180:
       
   359                     newCode = EStdKeyDownArrow;
       
   360                     break;
       
   361                 case CFbsBitGc::EGraphicsOrientationRotated270:
       
   362                     newCode = EStdKeyRightArrow;
       
   363                     break;
       
   364                 default:
       
   365                     break;
       
   366                 }
       
   367             break;
       
   368 
       
   369         // Diagonal events
       
   370         case KAknStdLeftUpArrow:
       
   371             switch ( finalRotation )
       
   372                 {
       
   373                 case CFbsBitGc::EGraphicsOrientationRotated90:
       
   374                     newCode = KAknStdLeftDownArrow;
       
   375                     break;
       
   376                 case CFbsBitGc::EGraphicsOrientationRotated180:
       
   377                     newCode = KAknStdRightDownArrow;
       
   378                     break;
       
   379                 case CFbsBitGc::EGraphicsOrientationRotated270:
       
   380                     newCode = KAknStdRightUpArrow;
       
   381                     break;
       
   382                 default:
       
   383                     break;
       
   384                 }
       
   385             break;
       
   386 
       
   387         case KAknStdRightUpArrow:
       
   388             switch ( finalRotation )
       
   389                 {
       
   390                 case CFbsBitGc::EGraphicsOrientationRotated90:
       
   391                     newCode = KAknStdLeftUpArrow;
       
   392                     break;
       
   393                 case CFbsBitGc::EGraphicsOrientationRotated180:
       
   394                     newCode = KAknStdLeftDownArrow;
       
   395                     break;
       
   396                 case CFbsBitGc::EGraphicsOrientationRotated270:
       
   397                     newCode = KAknStdRightDownArrow;
       
   398                     break;
       
   399                 default:
       
   400                     break;
       
   401                 }
       
   402             break;
       
   403 
       
   404         case KAknStdLeftDownArrow:
       
   405             switch ( finalRotation )
       
   406                 {
       
   407                 case CFbsBitGc::EGraphicsOrientationRotated90:
       
   408                     newCode = KAknStdRightDownArrow;
       
   409                     break;
       
   410                 case CFbsBitGc::EGraphicsOrientationRotated180:
       
   411                     newCode = KAknStdRightUpArrow;
       
   412                     break;
       
   413                 case CFbsBitGc::EGraphicsOrientationRotated270:
       
   414                     newCode = KAknStdLeftUpArrow;
       
   415                     break;
       
   416                 default:
       
   417                     break;
       
   418                 }
       
   419             break;
       
   420 
       
   421         case KAknStdRightDownArrow:
       
   422             switch ( finalRotation )
       
   423                 {
       
   424                 case CFbsBitGc::EGraphicsOrientationRotated90:
       
   425                     newCode = KAknStdRightUpArrow;
       
   426                     break;
       
   427                 case CFbsBitGc::EGraphicsOrientationRotated180:
       
   428                     newCode = KAknStdLeftUpArrow;
       
   429                     break;
       
   430                 case CFbsBitGc::EGraphicsOrientationRotated270:
       
   431                     newCode = KAknStdLeftDownArrow;
       
   432                     break;
       
   433                 default:
       
   434                     break;
       
   435                 }
       
   436             break;
       
   437 
       
   438         default:
       
   439             break;    
       
   440         }
       
   441         
       
   442     // If the 'newCode' was updated, add that value as the new scancode with existing modifiers.
       
   443     if ( newCode != KErrNotFound )
       
   444         {
       
   445         aNewRawEvent.Set(
       
   446             aNewRawEvent.Type(),
       
   447             (aNewRawEvent.ScanCode()&KAknModifiersMask) + newCode);
       
   448         }
       
   449     }
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // CAknKeyRotatorImpl::IsArrowScanCode
       
   453 // Returns true if it's arrow scan code.
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 TBool CAknKeyRotatorImpl::IsArrowScanCode(TInt aScanCode)
       
   457     {
       
   458     return ( aScanCode >= EStdKeyLeftArrow && aScanCode <= EStdKeyDownArrow ) ||
       
   459            ( aScanCode >= KAknStdLeftUpArrow && aScanCode <= KAknStdLeftDownArrow );
       
   460     }
       
   461 
       
   462 // -----------------------------------------------------------------------------
       
   463 // CAknKeyRotatorImpl::GetKeyRotatorCompensationL
       
   464 // Parses wsini.ini to read key rotator compensation value.
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 TInt CAknKeyRotatorImpl::GetKeyRotatorCompensationL()
       
   468     {
       
   469     TInt result = 0;
       
   470     HBufC* wsiniText = GetWsiniLC();
       
   471     
       
   472     // Now look for keyword
       
   473     const TInt pos = wsiniText->Find( KAknKeyRotatorKey );
       
   474     if ( pos != KErrNotFound )
       
   475         {        
       
   476         // Keyword was found. Check that it is the beginning of line.
       
   477         // Three cases:
       
   478         // 1. Keyword could be at the beginning of the file.
       
   479         // 2. Keyword could be at the beginning of the file 
       
   480         //    after byte ordering marker.
       
   481         // 3. Previous character can be end of line marker.
       
   482         const TInt previousPos = pos - 1;
       
   483         if ( previousPos < 0 || 
       
   484              ( !previousPos && 
       
   485                IsByteOrderingMarker( (*wsiniText)[ previousPos ] ) ) || 
       
   486              IsEndOfLine( (*wsiniText)[ previousPos ] ) )
       
   487             {
       
   488             TLex text( wsiniText->Mid( pos + KAknKeyRotatorKey().Length() ) );
       
   489             
       
   490             // First, there must be at least a space after keyword.
       
   491             TBool fail = !( SkipSpaces( text ) & EAknWasSpace );
       
   492            
       
   493             // Case 1: Disabled
       
   494             TBool wasDisabled = EFalse;
       
   495             if ( !fail )
       
   496                 {
       
   497                 wasDisabled = 
       
   498                     !text.Remainder().Left( KAknKeyRotatorDisabled().Length() ).
       
   499                     CompareF( KAknKeyRotatorDisabled );
       
   500 
       
   501                 if ( wasDisabled )
       
   502                     {
       
   503                     // wasDisabled == True, KAknKeyRotatorDisabled was prefix
       
   504                     // of text. So skip over it
       
   505                     text.Inc( KAknKeyRotatorDisabled().Length() );
       
   506                     }
       
   507                 }
       
   508             
       
   509             // Case 2: Then follows a sequence of digits, optionally preceded by '-'.
       
   510             if ( !wasDisabled && !fail )
       
   511                 {
       
   512                 // Check optional -
       
   513                 TBool negate = EFalse;
       
   514                 if ( !text.Eos() && text.Peek() == '-' )
       
   515                     {
       
   516                     negate = ETrue;
       
   517                     text.Inc();
       
   518                     }
       
   519                     
       
   520                 // Get digit sequence and convert to integer value.
       
   521                 TPtrC token = GetDigits( text );
       
   522                 fail = !token.Length() || 
       
   523                        ( TLex( token ).Val( result ) != KErrNone );
       
   524                 
       
   525                 // Handle negation
       
   526                 if ( !fail && negate )
       
   527                     {
       
   528                     result = -result;
       
   529                     }
       
   530                 }
       
   531 
       
   532             // That sequence of digits is followed by sequence of spaces until
       
   533             // end of line or end of file.
       
   534             fail = fail || ( SkipSpaces( text ) & EAknWasCharacter );
       
   535             
       
   536             if ( !wasDisabled )
       
   537                 {
       
   538                 // Finally, that sequence of digits must represent
       
   539                 // one valid decimal value of the following: 
       
   540                 // -270, -180, -90, 0, 90, 180, 270.
       
   541                 fail = fail || !CheckCompensationValue( result );
       
   542                 }
       
   543                 
       
   544             // If any of above checks failed, use default value 0.
       
   545             if ( fail )
       
   546                 {
       
   547                 result = 0;
       
   548                 }
       
   549             else
       
   550                 {
       
   551                 if ( wasDisabled )
       
   552                     {
       
   553                     result = KMaxTInt;
       
   554                     }
       
   555                 }
       
   556             }
       
   557         }
       
   558         
       
   559     CleanupStack::PopAndDestroy( wsiniText );   
       
   560     return result;
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CAknKeyRotatorImpl::IsEndOfLine
       
   565 // Checks if specified character is end of line marker.
       
   566 // -----------------------------------------------------------------------------
       
   567 //
       
   568 inline TBool CAknKeyRotatorImpl::IsEndOfLine( TText aChar )
       
   569     {
       
   570     return aChar == '\r' || aChar == '\n';
       
   571     }
       
   572 
       
   573 // -----------------------------------------------------------------------------
       
   574 // CAknKeyRotatorImpl::IsByteOrderingMarker
       
   575 // Checks if specified character is byte ordering marker.
       
   576 // -----------------------------------------------------------------------------
       
   577 //
       
   578 inline TBool CAknKeyRotatorImpl::IsByteOrderingMarker( TText aChar )
       
   579     {
       
   580     return aChar == 0xFEFF || aChar == 0xFFFE;
       
   581     }
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // CAknKeyRotatorImpl::GetWsiniLC
       
   585 // Reads the whole wsini.ini to memory and returns in heap descriptor.
       
   586 // -----------------------------------------------------------------------------
       
   587 //
       
   588 HBufC* CAknKeyRotatorImpl::GetWsiniLC()
       
   589     {
       
   590     // Read the whole wsini.ini to memory
       
   591     RFs fs;
       
   592     User::LeaveIfError( fs.Connect() );
       
   593     CleanupClosePushL( fs );
       
   594     
       
   595     TEntry wsiniEntry;
       
   596     User::LeaveIfError( fs.Entry( KAknWsini, wsiniEntry ) );
       
   597 
       
   598     HBufC* wsiniText = HBufC::NewLC( ( wsiniEntry.iSize + 1 )/2 );
       
   599     TPtr wsiniPtr = wsiniText->Des();
       
   600     TPtr8 wsiniPtr8( (TText8*)wsiniPtr.Ptr(), 0, wsiniPtr.MaxLength()*2 );
       
   601 
       
   602     RFile wsiniFile;
       
   603     User::LeaveIfError( wsiniFile.Open( fs, KAknWsini, EFileRead | EFileShareReadersOnly ) );
       
   604     CleanupClosePushL( wsiniFile );
       
   605 
       
   606     User::LeaveIfError( wsiniFile.Read( wsiniPtr8, wsiniEntry.iSize ) );
       
   607     wsiniPtr.SetLength( wsiniPtr8.Length() / 2 );
       
   608 
       
   609     CleanupStack::PopAndDestroy( &wsiniFile );
       
   610     CleanupStack::Pop( wsiniText );
       
   611     CleanupStack::PopAndDestroy( &fs );
       
   612     CleanupStack::PushL( wsiniText );
       
   613     return wsiniText;
       
   614     }
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // CAknKeyRotatorImpl::SkipSpaces
       
   618 // Skips over spaces.
       
   619 // -----------------------------------------------------------------------------
       
   620 //
       
   621 TInt CAknKeyRotatorImpl::SkipSpaces( TLex& aLex )
       
   622     {
       
   623     TInt flags = 0;
       
   624     // Skip spaces, but stop at end of line.
       
   625     while ( !aLex.Eos() && !IsEndOfLine( aLex.Peek() ) )
       
   626         {
       
   627         if ( aLex.Peek().IsSpace() )
       
   628             {
       
   629             // There was a space, so ok for now.
       
   630             flags |= EAknWasSpace;
       
   631             aLex.Inc();
       
   632             }
       
   633         else
       
   634             {
       
   635             flags |= EAknWasCharacter;
       
   636             break;
       
   637             }
       
   638         }
       
   639     return flags;
       
   640     }
       
   641 
       
   642 // -----------------------------------------------------------------------------
       
   643 // CAknKeyRotatorImpl::SkipSpaces
       
   644 // Goes over digits and returns that sequence.
       
   645 // -----------------------------------------------------------------------------
       
   646 //
       
   647 TPtrC CAknKeyRotatorImpl::GetDigits( TLex& aLex )
       
   648     {
       
   649     // Mark current place and go over digits.
       
   650     aLex.Mark();
       
   651     while ( !aLex.Eos() && !IsEndOfLine( aLex.Peek() ) )
       
   652         {
       
   653         if ( aLex.Peek().IsDigit() )
       
   654             {
       
   655             aLex.Inc();
       
   656             }
       
   657         else
       
   658             {
       
   659             break;
       
   660             }
       
   661         }
       
   662     return aLex.MarkedToken();
       
   663     }
       
   664 
       
   665 // -----------------------------------------------------------------------------
       
   666 // CAknKeyRotatorImpl::CheckCompensationValue
       
   667 // Checks that value contains valid key rotator compensation value.
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 inline TBool CAknKeyRotatorImpl::CheckCompensationValue( TInt aValue )
       
   671     {
       
   672     // Check absolute value
       
   673     if ( aValue < 0 )
       
   674         {
       
   675         aValue = -aValue;
       
   676         }
       
   677         
       
   678     return aValue == 0 ||
       
   679            aValue == 90 ||
       
   680            aValue == 180 ||
       
   681            aValue == 270;
       
   682     }
       
   683 
       
   684 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   685 
       
   686 // -----------------------------------------------------------------------------
       
   687 // Creates a CAknKeyRotatorImpl instance.
       
   688 // Returns: new CAknKeyRotatorImpl object. Ownership is returned to the caller.
       
   689 // -----------------------------------------------------------------------------
       
   690 //
       
   691 EXPORT_C CAknKeyRotator* AknKeyRotatorFactory::CreateAknKeyRotatorL()
       
   692     {
       
   693     return CAknKeyRotatorImpl::NewL();
       
   694     }
       
   695 
       
   696 //  End of File