fep/aknfep/src/aknfepzhuyinkeyhandler.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2009 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:                
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "aknfepzhuyinkeyhandler.h"
       
    22 
       
    23 const TInt KBTLoopLength1 = 3;
       
    24 const TInt KBTLoopLength2 = 4;
       
    25 const TInt KBTLoopLength3 = 5;
       
    26 
       
    27 const TInt KBTLoopLength = 5;
       
    28 
       
    29 const TInt KCLKCount1 = 1;
       
    30 const TInt KCLKCount2 = 2;
       
    31 const TInt KCLKCount3 = 3;
       
    32 const TInt KCLKCount4 = 4;
       
    33 const TInt KCLKCount5 = 5;
       
    34 
       
    35 const TInt KTimerOut = 700000;
       
    36 
       
    37 _LIT(KPtiKey1_1, "\x3105");
       
    38 _LIT(KPtiKey1_2, "\x3106");
       
    39 _LIT(KPtiKey1_3, "\x3107");
       
    40 _LIT(KPtiKey1_4, "\x3108");
       
    41 
       
    42 _LIT(KPtiKey2_1, "\x3109");
       
    43 _LIT(KPtiKey2_2, "\x310A");
       
    44 _LIT(KPtiKey2_3, "\x310B");
       
    45 _LIT(KPtiKey2_4, "\x310C");
       
    46 
       
    47 _LIT(KPtiKey3_1, "\x310D");
       
    48 _LIT(KPtiKey3_2, "\x310E");
       
    49 _LIT(KPtiKey3_3, "\x310F");
       
    50 
       
    51 _LIT(KPtiKey4_1, "\x3110");
       
    52 _LIT(KPtiKey4_2, "\x3111");
       
    53 _LIT(KPtiKey4_3, "\x3112");
       
    54 
       
    55 _LIT(KPtiKey5_1, "\x3113");
       
    56 _LIT(KPtiKey5_2, "\x3114");
       
    57 _LIT(KPtiKey5_3, "\x3115");
       
    58 _LIT(KPtiKey5_4, "\x3116");
       
    59 
       
    60 _LIT(KPtiKey6_1, "\x3117");
       
    61 _LIT(KPtiKey6_2, "\x3118");
       
    62 _LIT(KPtiKey6_3, "\x3119");
       
    63 
       
    64 _LIT(KPtiKey7_1, "\x311A");
       
    65 _LIT(KPtiKey7_2, "\x311B");
       
    66 _LIT(KPtiKey7_3, "\x311C");
       
    67 _LIT(KPtiKey7_4, "\x311D");
       
    68 
       
    69 _LIT(KPtiKey8_1, "\x311E");
       
    70 _LIT(KPtiKey8_2, "\x311F");
       
    71 _LIT(KPtiKey8_3, "\x3120");
       
    72 _LIT(KPtiKey8_4, "\x3121");
       
    73 
       
    74 _LIT(KPtiKey9_1, "\x3122");
       
    75 _LIT(KPtiKey9_2, "\x3123");
       
    76 _LIT(KPtiKey9_3, "\x3124");
       
    77 _LIT(KPtiKey9_4, "\x3125");
       
    78 _LIT(KPtiKey9_5, "\x3126");
       
    79 
       
    80 _LIT(KPtiKey0_1, "\x3127");
       
    81 _LIT(KPtiKey0_2, "\x3128");
       
    82 _LIT(KPtiKey0_3, "\x3129");
       
    83 
       
    84 _LIT(KPtiKeyStar_1, "\x0020");
       
    85 _LIT(KPtiKeyStar_2, "\x02CA");
       
    86 _LIT(KPtiKeyStar_3, "\x02C7");
       
    87 _LIT(KPtiKeyStar_4, "\x02CB");
       
    88 _LIT(KPtiKeyStar_5, "\x02D9");
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // C++ constructor.
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 ZhuyinKeyTable::ZhuyinKeyTable()
       
    96     {
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // Cancel and destroy.
       
   101 // ---------------------------------------------------------
       
   102 //
       
   103 ZhuyinKeyTable::~ZhuyinKeyTable()
       
   104     {
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // Get butten loop length.
       
   109 // ---------------------------------------------------------
       
   110 //
       
   111 TInt ZhuyinKeyTable::GetBtLoopLength ( TPtiKey aKey )
       
   112     {
       
   113     switch ( aKey )
       
   114         {
       
   115         case EPtiKey0:
       
   116         case EPtiKey3:
       
   117         case EPtiKey4:
       
   118         case EPtiKey6:
       
   119             {
       
   120             return KBTLoopLength1;
       
   121             }
       
   122         case EPtiKey1:
       
   123         case EPtiKey2:
       
   124         case EPtiKey5:
       
   125         case EPtiKey7:
       
   126         case EPtiKey8:
       
   127             {
       
   128             return KBTLoopLength2;
       
   129             }
       
   130         case EPtiKey9:
       
   131         case EPtiKeyStar:
       
   132             {
       
   133             return KBTLoopLength3;
       
   134             }
       
   135         default:
       
   136             return 0;
       
   137         }
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------
       
   141 // Get zhuyin symbol.
       
   142 // ---------------------------------------------------------
       
   143 //
       
   144 TBool ZhuyinKeyTable::GetUnicode ( TPtiKey aKey, TInt aClkCount, TDes& aOutput )
       
   145     {
       
   146     aOutput.Zero();
       
   147     switch ( aKey )
       
   148         {
       
   149         case EPtiKey0:
       
   150             {
       
   151             switch ( aClkCount )
       
   152                 {
       
   153                 case KCLKCount1:
       
   154                     aOutput.Append(KPtiKey0_1);
       
   155                     return ETrue;
       
   156                 case KCLKCount2:
       
   157                     aOutput.Append(KPtiKey0_2);
       
   158                     return ETrue;
       
   159                 case KCLKCount3:
       
   160                     aOutput.Append(KPtiKey0_3);
       
   161                     return ETrue;
       
   162                 default:
       
   163                     return EFalse;
       
   164                 }
       
   165             }
       
   166         case EPtiKey1:
       
   167             switch ( aClkCount )
       
   168                 {
       
   169                 case KCLKCount1:
       
   170                     aOutput.Append(KPtiKey1_1);
       
   171                     return ETrue;
       
   172                 case KCLKCount2:
       
   173                     aOutput.Append(KPtiKey1_2);
       
   174                     return ETrue;
       
   175                 case KCLKCount3:
       
   176                     aOutput.Append(KPtiKey1_3);
       
   177                     return ETrue;
       
   178                 case KCLKCount4:
       
   179                     aOutput.Append(KPtiKey1_4);
       
   180                     return ETrue;
       
   181                 default:
       
   182                     return EFalse;
       
   183                 }
       
   184         case EPtiKey2:
       
   185             switch ( aClkCount )
       
   186                 {
       
   187                 case KCLKCount1:
       
   188                     aOutput.Append(KPtiKey2_1);
       
   189                     return ETrue;
       
   190                 case KCLKCount2:
       
   191                     aOutput.Append(KPtiKey2_2);
       
   192                     return ETrue;
       
   193                 case KCLKCount3:
       
   194                     aOutput.Append(KPtiKey2_3);
       
   195                     return ETrue;
       
   196                 case KCLKCount4:
       
   197                     aOutput.Append(KPtiKey2_4);
       
   198                     return ETrue;
       
   199                 default:
       
   200                     return EFalse;
       
   201                 }
       
   202         case EPtiKey3:
       
   203             {
       
   204             switch ( aClkCount )
       
   205                 {
       
   206                 case KCLKCount1:
       
   207                     aOutput.Append(KPtiKey3_1);
       
   208                     return ETrue;
       
   209                 case KCLKCount2:
       
   210                     aOutput.Append(KPtiKey3_2);
       
   211                     return ETrue;
       
   212                 case KCLKCount3:
       
   213                     aOutput.Append(KPtiKey3_3);
       
   214                     return ETrue;
       
   215                 default:
       
   216                     return EFalse;
       
   217                 }
       
   218             }
       
   219         case EPtiKey4:
       
   220             {
       
   221             switch ( aClkCount )
       
   222                 {
       
   223                 case KCLKCount1:
       
   224                     aOutput.Append(KPtiKey4_1);
       
   225                     return ETrue;
       
   226                 case KCLKCount2:
       
   227                     aOutput.Append(KPtiKey4_2);
       
   228                     return ETrue;
       
   229                 case KCLKCount3:
       
   230                     aOutput.Append(KPtiKey4_3);
       
   231                     return ETrue;
       
   232                 default:
       
   233                     return EFalse;
       
   234                 }
       
   235             }
       
   236         case EPtiKey5:
       
   237             {
       
   238             switch ( aClkCount )
       
   239                 {
       
   240                 case KCLKCount1:
       
   241                     aOutput.Append(KPtiKey5_1);
       
   242                     return ETrue;
       
   243                 case KCLKCount2:
       
   244                     aOutput.Append(KPtiKey5_2);
       
   245                     return ETrue;
       
   246                 case KCLKCount3:
       
   247                     aOutput.Append(KPtiKey5_3);
       
   248                     return ETrue;
       
   249                 case KCLKCount4:
       
   250                     aOutput.Append(KPtiKey5_4);
       
   251                     return ETrue;
       
   252                 default:
       
   253                     return EFalse;
       
   254                 }
       
   255             }
       
   256         case EPtiKey6:
       
   257             {
       
   258             switch ( aClkCount )
       
   259                 {
       
   260                 case KCLKCount1:
       
   261                     aOutput.Append(KPtiKey6_1);
       
   262                     return ETrue;
       
   263                 case KCLKCount2:
       
   264                     aOutput.Append(KPtiKey6_2);
       
   265                     return ETrue;
       
   266                 case KCLKCount3:
       
   267                     aOutput.Append(KPtiKey6_3);
       
   268                     return ETrue;
       
   269                 default:
       
   270                     return EFalse;
       
   271                 }
       
   272             }
       
   273         case EPtiKey7:
       
   274             {
       
   275             switch ( aClkCount )
       
   276                 {
       
   277                 case KCLKCount1:
       
   278                     aOutput.Append(KPtiKey7_1);
       
   279                     return ETrue;
       
   280                 case KCLKCount2:
       
   281                     aOutput.Append(KPtiKey7_2);
       
   282                     return ETrue;
       
   283                 case KCLKCount3:
       
   284                     aOutput.Append(KPtiKey7_3);
       
   285                     return ETrue;
       
   286                 case KCLKCount4:
       
   287                     aOutput.Append(KPtiKey7_4);
       
   288                     return ETrue;
       
   289                 default:
       
   290                     return EFalse;
       
   291                 }
       
   292             }
       
   293         case EPtiKey8:
       
   294             {
       
   295             switch ( aClkCount )
       
   296                 {
       
   297                 case KCLKCount1:
       
   298                     aOutput.Append(KPtiKey8_1);
       
   299                     return ETrue;
       
   300                 case KCLKCount2:
       
   301                     aOutput.Append(KPtiKey8_2);
       
   302                     return ETrue;
       
   303                 case KCLKCount3:
       
   304                     aOutput.Append(KPtiKey8_3);
       
   305                     return ETrue;
       
   306                 case KCLKCount4:
       
   307                     aOutput.Append(KPtiKey8_4);
       
   308                     return ETrue;
       
   309                 default:
       
   310                     return EFalse;
       
   311                 }
       
   312             }
       
   313         case EPtiKey9:
       
   314             {
       
   315             switch ( aClkCount )
       
   316                 {
       
   317                 case KCLKCount1:
       
   318                     aOutput.Append(KPtiKey9_1);
       
   319                     return ETrue;
       
   320                 case KCLKCount2:
       
   321                     aOutput.Append(KPtiKey9_2);
       
   322                     return ETrue;
       
   323                 case KCLKCount3:
       
   324                     aOutput.Append(KPtiKey9_3);
       
   325                     return ETrue;
       
   326                 case KCLKCount4:
       
   327                     aOutput.Append(KPtiKey9_4);
       
   328                     return ETrue;
       
   329                 case KCLKCount5:
       
   330                     aOutput.Append(KPtiKey9_5);
       
   331                     return ETrue;
       
   332                 default:
       
   333                     return EFalse;
       
   334                 }
       
   335             }
       
   336         case EPtiKeyStar:
       
   337             {
       
   338             switch ( aClkCount )
       
   339                 {
       
   340                 case KCLKCount1:
       
   341                     aOutput.Append(KPtiKeyStar_1);
       
   342                     return ETrue;
       
   343                 case KCLKCount2:
       
   344                     aOutput.Append(KPtiKeyStar_2);
       
   345                     return ETrue;
       
   346                 case KCLKCount3:
       
   347                     aOutput.Append(KPtiKeyStar_3);
       
   348                     return ETrue;
       
   349                 case KCLKCount4:
       
   350                     aOutput.Append(KPtiKeyStar_4);
       
   351                     return ETrue;
       
   352                 case KCLKCount5:
       
   353                     aOutput.Append(KPtiKeyStar_5);
       
   354                     return ETrue;
       
   355                 default:
       
   356                     return EFalse;
       
   357                 }
       
   358             }
       
   359         default:
       
   360             return EFalse;
       
   361         }
       
   362     }
       
   363 
       
   364 // ---------------------------------------------------------
       
   365 // C++ constructor
       
   366 // ---------------------------------------------------------
       
   367 //
       
   368 CZhuyinKeyHandler::CZhuyinKeyHandler( ) :
       
   369     CActive ( EPriorityStandard ), // Standard priority
       
   370     iLastKey ( EPtiKeyNone ), 
       
   371     iTimeOut ( ETrue ),
       
   372     iBtClickNum ( 0 ),
       
   373     iBtLoopLength ( 1 ),
       
   374     iState( 0 ),
       
   375     iStatusChgFlag(EInit)
       
   376     {
       
   377     }
       
   378 
       
   379 // ---------------------------------------------------------
       
   380 // Two-phased constructor.
       
   381 // ---------------------------------------------------------
       
   382 //
       
   383 CZhuyinKeyHandler* CZhuyinKeyHandler::NewLC()
       
   384     {
       
   385     CZhuyinKeyHandler* self = new ( ELeave ) CZhuyinKeyHandler();
       
   386     CleanupStack::PushL( self );
       
   387     self->ConstructL( );
       
   388     return self;
       
   389     }
       
   390 
       
   391 // ---------------------------------------------------------
       
   392 // Two-phased constructor.
       
   393 // ---------------------------------------------------------
       
   394 //
       
   395 CZhuyinKeyHandler* CZhuyinKeyHandler::NewL()
       
   396     {
       
   397     CZhuyinKeyHandler* self = CZhuyinKeyHandler::NewLC();
       
   398     CleanupStack::Pop( self ); // self;
       
   399     return self;
       
   400     }
       
   401 
       
   402 // ---------------------------------------------------------
       
   403 // Two-phased constructor.
       
   404 // ---------------------------------------------------------
       
   405 //
       
   406 void CZhuyinKeyHandler::ConstructL( )
       
   407     {
       
   408     User::LeaveIfError( iTimer.CreateLocal( ) ); // Initialize timer
       
   409     CActiveScheduler::Add( this ); // Add to scheduler
       
   410     }
       
   411 
       
   412 // ---------------------------------------------------------
       
   413 // Cancel and destroy.
       
   414 // ---------------------------------------------------------
       
   415 //
       
   416 CZhuyinKeyHandler::~CZhuyinKeyHandler( )
       
   417     {
       
   418     Cancel( ); // Cancel any request, if outstanding
       
   419     iTimer.Close( ); // Destroy the RTimer object
       
   420     // Delete instance variables if any
       
   421     }
       
   422 
       
   423 // ---------------------------------------------------------
       
   424 // How to cancel me.
       
   425 // ---------------------------------------------------------
       
   426 //
       
   427 void CZhuyinKeyHandler::DoCancel( )
       
   428     {
       
   429     iTimer.Cancel( );
       
   430     }
       
   431 
       
   432 // ---------------------------------------------------------
       
   433 // Function for making the initial request.
       
   434 // ---------------------------------------------------------
       
   435 //
       
   436 void CZhuyinKeyHandler::Start()
       
   437     {
       
   438     Cancel(); // Cancel any request, just to be sure
       
   439     iTimer.After( iStatus, KTimerOut ); // Set for later
       
   440     SetActive(); // Tell scheduler a request is active
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------
       
   444 // Get Zhuyin symbol according to the inputting key.
       
   445 // ---------------------------------------------------------
       
   446 //
       
   447 TInt CZhuyinKeyHandler::GetZhuyinSymbol ( TPtiKey aKey, TDes& aOutBuf )
       
   448     {
       
   449     TInt ret = 0;
       
   450     Start();
       
   451     // if the same button is pressed for many times.
       
   452     if ( iLastKey == aKey
       
   453         && iTimeOut == EFalse )
       
   454         {
       
   455         if ( iBtLoopLength != 0 )
       
   456             {
       
   457             iBtClickNum++;
       
   458             if ( iBtClickNum > iBtLoopLength )
       
   459                 {
       
   460                 iBtClickNum = 1;
       
   461                 }
       
   462             }
       
   463         // Search for the corresponding unicode and value aOutBuf.
       
   464         ZhuyinKeyTable::GetUnicode(aKey,iBtClickNum,aOutBuf);
       
   465         ret = 0;
       
   466         }
       
   467     // if the pressed button is changed or time out event is happened.
       
   468     else if ( iLastKey == aKey
       
   469         && iTimeOut != EFalse )
       
   470         {
       
   471         // Update iBtClickNum
       
   472         iBtClickNum = 1;
       
   473         // Search for the corresponding unicode and value aOutBuf.
       
   474         ZhuyinKeyTable::GetUnicode(aKey,iBtClickNum,aOutBuf);
       
   475         ret = 1;
       
   476         }
       
   477     else
       
   478         {
       
   479         // Update iBtClickNum
       
   480         iBtClickNum = 1;
       
   481         // Update iBtUnicodeNum
       
   482         iBtLoopLength = ZhuyinKeyTable::GetBtLoopLength(aKey);
       
   483         // Search for the corresponding unicode and value aOutBuf.
       
   484         ZhuyinKeyTable::GetUnicode(aKey,iBtClickNum,aOutBuf);
       
   485         if ( iBtLoopLength != 0 )
       
   486             {
       
   487             ret = 1;
       
   488             }
       
   489         else
       
   490             {
       
   491             ret = -1;
       
   492             }
       
   493         }
       
   494     iLastKey = aKey;
       
   495     iTimeOut = EFalse;
       
   496     return ret;
       
   497     }
       
   498 
       
   499 // ---------------------------------------------------------
       
   500 // Set status change flag.
       
   501 // ---------------------------------------------------------
       
   502 //
       
   503 void CZhuyinKeyHandler::SetStatusChgFlag ( MZhuyinKeyHandler::TStatusChgFlag aChgFlag )
       
   504     {
       
   505     iStatusChgFlag = aChgFlag;
       
   506     }
       
   507 
       
   508 // ---------------------------------------------------------
       
   509 // Get the status change flag.
       
   510 // ---------------------------------------------------------
       
   511 //
       
   512 MZhuyinKeyHandler::TStatusChgFlag CZhuyinKeyHandler::GetStatusChgFlag ()
       
   513     {
       
   514     return iStatusChgFlag;
       
   515     }
       
   516 
       
   517 // ---------------------------------------------------------
       
   518 // Reset all the member variables.
       
   519 // ---------------------------------------------------------
       
   520 //
       
   521 void CZhuyinKeyHandler::Reset()
       
   522     {
       
   523     iLastKey = EPtiKeyNone; 
       
   524     iTimeOut = ETrue ;
       
   525     iBtClickNum = 0;
       
   526     iBtLoopLength = 1;
       
   527     }
       
   528 
       
   529 
       
   530 // ---------------------------------------------------------
       
   531 // Get tonemark according to symbol in front of cursor.
       
   532 // ---------------------------------------------------------
       
   533 //
       
   534 TInt CZhuyinKeyHandler::GetToneMark ( const TDes& aBaseSymbol, TDes& aOutBuf )
       
   535     {
       
   536     TInt ret = 0;
       
   537     iBtLoopLength = KBTLoopLength;
       
   538     iTimeOut = ETrue ;
       
   539     if ( aBaseSymbol.Compare(KPtiKeyStar_1) == 0 )
       
   540         {
       
   541         iBtClickNum = KCLKCount1;
       
   542         }
       
   543     else if ( aBaseSymbol.Compare(KPtiKeyStar_2) == 0 )
       
   544         {
       
   545         iBtClickNum = KCLKCount2;
       
   546         }
       
   547     else if ( aBaseSymbol.Compare(KPtiKeyStar_3) == 0 )
       
   548         {
       
   549         iBtClickNum = KCLKCount3;
       
   550         }
       
   551     else if ( aBaseSymbol.Compare(KPtiKeyStar_4) == 0 )
       
   552         {
       
   553         iBtClickNum = KCLKCount4;
       
   554         }
       
   555     else if ( aBaseSymbol.Compare(KPtiKeyStar_5) == 0 )
       
   556         {
       
   557         iBtClickNum = KCLKCount5;
       
   558         }
       
   559     else
       
   560         {
       
   561         iBtClickNum = 0;
       
   562         ret = 1;
       
   563         }
       
   564     iBtClickNum++;
       
   565     if ( iBtClickNum > iBtLoopLength )
       
   566         {
       
   567         iBtClickNum = 1;
       
   568         }
       
   569     ZhuyinKeyTable::GetUnicode(EPtiKeyStar,iBtClickNum,aOutBuf);
       
   570     iLastKey = EPtiKeyStar;
       
   571     iTimeOut = EFalse;
       
   572     return ret;
       
   573     }
       
   574 
       
   575 // ---------------------------------------------------------
       
   576 // Get tonemark according to symbol in front of cursor.
       
   577 // ---------------------------------------------------------
       
   578 //
       
   579 void CZhuyinKeyHandler::RunL( )
       
   580     {
       
   581     iTimeOut = ETrue;
       
   582     }
       
   583 
       
   584 // ---------------------------------------------------------
       
   585 // Override to handle leaves from RunL(). Default implementation causes.
       
   586 // ---------------------------------------------------------
       
   587 //
       
   588 TInt CZhuyinKeyHandler::RunError( TInt aError )
       
   589     {
       
   590     return aError;
       
   591     }
       
   592 
       
   593 // ---------------------------------------------------------
       
   594 // Set whether state change from entry to spelling editing is automatical.
       
   595 // ---------------------------------------------------------
       
   596 //
       
   597 void CZhuyinKeyHandler::SetState( TInt aState )
       
   598     {
       
   599     iState = aState;
       
   600     }
       
   601 
       
   602 // ---------------------------------------------------------
       
   603 // Get state change states.
       
   604 // ---------------------------------------------------------
       
   605 //
       
   606 TInt CZhuyinKeyHandler::GetState()
       
   607     {
       
   608     return iState;
       
   609     }
       
   610 
       
   611 // End of file