textinput/peninputarc/src/peninputlayoutcontrol/peninputtapsettingmanager.cpp
branchRCL_3
changeset 56 8152b1f1763a
parent 50 5a1685599b76
child 57 9eb76adaa71f
equal deleted inserted replaced
50:5a1685599b76 56:8152b1f1763a
     1 /*
       
     2 * Copyright (c) 2010 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:  Implementation for CFepUiLayout
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "peninputtapsettingmanager.h"
       
    20 
       
    21 #include <centralrepository.h>
       
    22 #include <AknFepGlobalEnums.h>
       
    23 #include <AknFepInternalCRKeys.h>
       
    24 
       
    25 _LIT( KSeparatorComma, "," );
       
    26 
       
    27 const TInt KTextBufferLength = 128;
       
    28 
       
    29 const TInt KDefaultMovement = 5;
       
    30 const TInt KDefaultTimeout = 200000;
       
    31 const TInt KDefaultMargin = 9;
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 //  Symbian Constructor
       
    35 // ---------------------------------------------------------------------------
       
    36 // 
       
    37 CPeninputTapSettingManager* CPeninputTapSettingManager::NewL()
       
    38     {
       
    39     CPeninputTapSettingManager* self = CPeninputTapSettingManager::NewLC();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 //  Symbian Constructor
       
    46 // ---------------------------------------------------------------------------
       
    47 // 
       
    48 CPeninputTapSettingManager* CPeninputTapSettingManager::NewLC()
       
    49     {
       
    50     CPeninputTapSettingManager* self = new ( ELeave ) CPeninputTapSettingManager();
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 //  c++ destructor
       
    58 // ---------------------------------------------------------------------------
       
    59 // 
       
    60 CPeninputTapSettingManager::~CPeninputTapSettingManager()
       
    61     {
       
    62 
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Load all parameters of tap accuracy enhancement for specified layout
       
    67 // ---------------------------------------------------------------------------
       
    68 // 
       
    69 void CPeninputTapSettingManager::Load( TInt aLayoutType )
       
    70     {
       
    71     TRAPD( err, LoadFromRepositoryL( aLayoutType ) );
       
    72     if ( err != KErrNone )
       
    73         {
       
    74         LoadDefault();
       
    75         }
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // Load all parameters of tap accuracy enhancement for specified layout
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 void CPeninputTapSettingManager::Load( TInt aLayoutType, const TDesC& aFileName )
       
    83     {
       
    84     TRAPD( err, LoadFromFileL( aLayoutType, aFileName ) );
       
    85     if ( err != KErrNone )
       
    86         {
       
    87         LoadDefault();
       
    88         }
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // Get configuration of PointerMove event suppressor
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void CPeninputTapSettingManager::GetPointerMoveSuppressor( TSize& aMaxMovement, 
       
    96                                                            TInt& aTimeout )
       
    97     {
       
    98     aMaxMovement = iPointerMoveMaxMovement;
       
    99     aTimeout = iPointerMoveTimeout; 
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // Get configuration of PointerUp event suppressor
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CPeninputTapSettingManager::GetPointerUpSuppressor( TSize& aMaxMovement, 
       
   107                                                          TInt& aTimeout )
       
   108     {
       
   109     aMaxMovement = iPointerUpMaxMovement;
       
   110     aTimeout = iPointerUpTimeout;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // Get extra response area of virtual key controls.
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CPeninputTapSettingManager::GetKeyExtResponseArea( TMargins& aMargins )
       
   118     {
       
   119     aMargins = iKeyMargins;
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // Get extra response area of button controls.
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CPeninputTapSettingManager::GetButtonExtResponseArea( TMargins& aMargins )
       
   127     {
       
   128     aMargins = iButtonMargins;
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // C++ constructor.
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 CPeninputTapSettingManager::CPeninputTapSettingManager()
       
   136     {
       
   137     
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // Symbian second-phase constructor.
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CPeninputTapSettingManager::ConstructL()
       
   145     {
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // Load all parameters of tap accuracy enhancement for specified layout.
       
   150 // From Repository.
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CPeninputTapSettingManager::LoadFromRepositoryL( TInt aLayoutType )
       
   154     {
       
   155     TUint32 uidButtonExtMargins   = 0;
       
   156     TUint32 uidKeyCtrlExtMargins  = 0;
       
   157     TUint32 uidPointerMoveMaxMove = 0;
       
   158     TUint32 uidPointerMoveTimeout = 0;
       
   159     TUint32 uidPointerUpMaxMove   = 0;
       
   160     TUint32 uidPointerUpTimeout   = 0;
       
   161 
       
   162     switch( aLayoutType )
       
   163         {
       
   164         case EPluginInputModeFSQ:
       
   165             {
       
   166             uidButtonExtMargins   = KAknFepTapAccuracyFsqButtonExtMargins;
       
   167             uidKeyCtrlExtMargins  = KAknFepTapAccuracyFsqKeyCtrlExtMargins;
       
   168             uidPointerMoveMaxMove = KAknFepTapAccuracyFsqPointerMoveMaxMovement;
       
   169             uidPointerMoveTimeout = KAknFepTapAccuracyFsqPointerMoveTimeout;
       
   170             uidPointerUpMaxMove   = KAknFepTapAccuracyFsqPointerUpMaxMovement;
       
   171             uidPointerUpTimeout   = KAknFepTapAccuracyFsqPointerUpTimeout;
       
   172             }
       
   173             break;
       
   174         case EPluginInputModePortraitFSQ:
       
   175             {
       
   176             uidButtonExtMargins   = KAknFepTapAccuracyPFsqButtonExtMargins;
       
   177             uidKeyCtrlExtMargins  = KAknFepTapAccuracyPFsqKeyCtrlExtMargins;
       
   178             uidPointerMoveMaxMove = KAknFepTapAccuracyPFsqPointerMoveMaxMovement;
       
   179             uidPointerMoveTimeout = KAknFepTapAccuracyPFsqPointerMoveTimeout;
       
   180             uidPointerUpMaxMove   = KAknFepTapAccuracyPFsqPointerUpMaxMovement;
       
   181             uidPointerUpTimeout   = KAknFepTapAccuracyPFsqPointerUpTimeout;
       
   182             }
       
   183             break;
       
   184         case EPluginInputModeFingerHwr:
       
   185             {
       
   186             uidButtonExtMargins   = KAknFepTapAccuracyFhwrButtonExtMargins;
       
   187             uidKeyCtrlExtMargins  = KAknFepTapAccuracyFhwrKeyCtrlExtMargins;
       
   188             uidPointerMoveMaxMove = KAknFepTapAccuracyFhwrPointerMoveMaxMovement;
       
   189             uidPointerMoveTimeout = KAknFepTapAccuracyFhwrPointerMoveTimeout;
       
   190             uidPointerUpMaxMove   = KAknFepTapAccuracyFhwrPointerUpMaxMovement;
       
   191             uidPointerUpTimeout   = KAknFepTapAccuracyFhwrPointerUpTimeout;
       
   192             }
       
   193             break;            
       
   194         default:
       
   195             {
       
   196             uidButtonExtMargins   = KAknFepTapAccuracyDefaultButtonExtMargins;
       
   197             uidKeyCtrlExtMargins  = KAknFepTapAccuracyDefaultKeyCtrlExtMargins;
       
   198             uidPointerMoveMaxMove = KAknFepTapAccuracyDefaultPointerMoveMaxMovement;
       
   199             uidPointerMoveTimeout = KAknFepTapAccuracyDefaultPointerMoveTimeout;
       
   200             uidPointerUpMaxMove   = KAknFepTapAccuracyDefaultPointerUpMaxMovement;
       
   201             uidPointerUpTimeout   = KAknFepTapAccuracyDefaultPointerUpTimeout;
       
   202             }
       
   203         }
       
   204     
       
   205     CRepository* repository = CRepository::NewL( KCRUidAknFep );
       
   206     TBuf<KTextBufferLength> str;
       
   207     TInt num = 0;
       
   208     TPoint point;
       
   209     TMargins margins;
       
   210     
       
   211     //pointer move event
       
   212     repository->Get( uidPointerMoveTimeout, num );
       
   213     repository->Get( uidPointerMoveMaxMove, str );
       
   214     ParsePoints( point, str );
       
   215     
       
   216     iPointerMoveTimeout = num;
       
   217     iPointerMoveMaxMovement.iWidth = point.iX;
       
   218     iPointerMoveMaxMovement.iHeight = point.iY;
       
   219     
       
   220     //pointer up event
       
   221     repository->Get( uidPointerUpTimeout, num );
       
   222     repository->Get( uidPointerUpMaxMove, str );
       
   223     ParsePoints( point, str );
       
   224     
       
   225     iPointerUpTimeout = num;
       
   226     iPointerUpMaxMovement.iWidth = point.iX;
       
   227     iPointerUpMaxMovement.iHeight = point.iY;   
       
   228     
       
   229     //key control
       
   230     repository->Get( uidKeyCtrlExtMargins, str );
       
   231     ParseMargins( margins, str );
       
   232     iKeyMargins = margins;
       
   233     
       
   234     //button control
       
   235     repository->Get( uidButtonExtMargins, str );
       
   236     ParseMargins( margins, str );
       
   237     iButtonMargins = margins;
       
   238     
       
   239     delete repository;
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // Load all parameters of tap accuracy enhancement for specified layout.
       
   244 // From file.
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 void CPeninputTapSettingManager::LoadFromFileL( TInt /*aLayoutType*/, 
       
   248                                                 const TDesC& /*aFileName*/ )
       
   249     {
       
   250     //reserved
       
   251     }
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // Load default parameters.
       
   255 // ---------------------------------------------------------------------------
       
   256 //
       
   257 void CPeninputTapSettingManager::LoadDefault()
       
   258     {
       
   259     iPointerMoveMaxMovement = TSize( KDefaultMovement, KDefaultMovement );
       
   260     iPointerMoveTimeout     = KDefaultTimeout;
       
   261     
       
   262     iPointerUpMaxMovement   = TSize( KDefaultMovement, KDefaultMovement );
       
   263     iPointerUpTimeout       = KDefaultTimeout;
       
   264     
       
   265     iKeyMargins.iTop        = KDefaultMargin;
       
   266     iKeyMargins.iLeft       = KDefaultMargin;
       
   267     iKeyMargins.iBottom     = KDefaultMargin;
       
   268     iKeyMargins.iRight      = KDefaultMargin;
       
   269     
       
   270     iButtonMargins.iTop     = KDefaultMargin;
       
   271     iButtonMargins.iLeft    = KDefaultMargin;
       
   272     iButtonMargins.iBottom  = KDefaultMargin;
       
   273     iButtonMargins.iRight   = KDefaultMargin;
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // parse a TPoint from a comma separated values string.
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 TInt CPeninputTapSettingManager::ParsePoints( TPoint& aPoint, const TDesC& aText )
       
   281     {
       
   282     TPtrC tokenizer( aText );
       
   283     TInt pos = tokenizer.Find( KSeparatorComma );
       
   284     if ( pos == KErrNotFound )
       
   285         {
       
   286         TInt value = 0;
       
   287         TLex converter( tokenizer );
       
   288         TInt error = converter.Val( value );
       
   289         aPoint.iX = ( KErrNone == error ? value : 0 );
       
   290         aPoint.iY = aPoint.iX;
       
   291         return 0;
       
   292         }
       
   293 
       
   294     TInt value = 0;
       
   295    
       
   296     TLex converter( tokenizer.Left( pos ) );
       
   297     TInt error = converter.Val( value );
       
   298     aPoint.iX = ( KErrNone == error ? value : 0 );
       
   299     
       
   300     converter = TLex( tokenizer.Mid( pos + 1 ) );
       
   301     error = converter.Val( value );
       
   302     aPoint.iY = ( KErrNone == error ? value : 0 );
       
   303     
       
   304     return 0;
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // parse a TMargins from a comma separated values string.
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 TInt CPeninputTapSettingManager::ParseMargins( TMargins& aMargins, const TDesC& aText )
       
   312     {
       
   313     RArray<TInt> values;
       
   314     
       
   315     TPtrC tokenizer( aText );
       
   316     TInt pos = 0;
       
   317     while ( pos != KErrNotFound )
       
   318         {
       
   319         pos = tokenizer.Find( KSeparatorComma );
       
   320             
       
   321         TPtrC substr = ( pos == KErrNotFound ) ? tokenizer : tokenizer.Left( pos );
       
   322         TInt value = 0;
       
   323         TLex converter( substr );
       
   324         TInt error = converter.Val( value );
       
   325         values.Append( KErrNone == error ? value : 0 );
       
   326         
       
   327         if ( pos != KErrNotFound )
       
   328             {
       
   329             TPtrC right = tokenizer.Mid( pos + 1 );
       
   330             tokenizer.Set( right );
       
   331             }
       
   332         }
       
   333     
       
   334     TInt count = values.Count();
       
   335     
       
   336     //one value, applies to all sides
       
   337     if(  count == 1  )
       
   338         {
       
   339         aMargins.iTop    = values[0];
       
   340         aMargins.iLeft   = values[0];
       
   341         aMargins.iBottom = values[0];
       
   342         aMargins.iRight  = values[0];
       
   343         }
       
   344     
       
   345     //two values, first one specifies margins of top and bottom,
       
   346     //the second specifies left and right. 
       
   347     else if(  count == 2 )
       
   348         {
       
   349         aMargins.iTop    = values[0];
       
   350         aMargins.iLeft   = values[1];
       
   351         aMargins.iBottom = values[0];
       
   352         aMargins.iRight  = values[1];
       
   353         }
       
   354 
       
   355     //three values, first is top, second is the left and right, last is bottom. 
       
   356     else if(  count == 3 )
       
   357         {
       
   358         aMargins.iTop    = values[0];
       
   359         aMargins.iLeft   = values[1];
       
   360         aMargins.iBottom = values[1];
       
   361         aMargins.iRight  = values[2];
       
   362         }
       
   363     
       
   364     //four values, specify top,left,bottom and right respectively
       
   365     else if ( count >= 4 )
       
   366         {
       
   367         aMargins.iTop    = values[0];
       
   368         aMargins.iLeft   = values[1];
       
   369         aMargins.iBottom = values[2];
       
   370         aMargins.iRight  = values[3];
       
   371         }
       
   372     
       
   373     else
       
   374         {
       
   375         aMargins.iTop    = 0;
       
   376         aMargins.iLeft   = 0;
       
   377         aMargins.iBottom = 0;
       
   378         aMargins.iRight  = 0;
       
   379         }
       
   380     
       
   381     values.Close();
       
   382     return count;
       
   383     }
       
   384 
       
   385 //end of file