textinput/peninputfingerhwrar/src/peninputfingerhwrarnumsymboltable.cpp
branchRCL_3
changeset 19 ac7e4d1d9209
parent 12 5e18d8c489d6
equal deleted inserted replaced
18:b1ea1642412e 19:ac7e4d1d9209
    39 #include "peninputfingerhwrarevent.h"
    39 #include "peninputfingerhwrarevent.h"
    40 #include "peninputfingerhwrarcontrolid.h"
    40 #include "peninputfingerhwrarcontrolid.h"
    41 #include "peninputfingerhwrarstoreconstants.h"
    41 #include "peninputfingerhwrarstoreconstants.h"
    42 #include "peninputlayoutvkb.h"
    42 #include "peninputlayoutvkb.h"
    43 #include "peninputfingerhwrarnumsymboltable.h"
    43 #include "peninputfingerhwrarnumsymboltable.h"
    44 
    44 #include "peninputfingerhwarvkbutility.h"
    45 
    45 
       
    46 const TUint16 KInvalidChar = 0xFFFF;
    46 // ---------------------------------------------------------------------------
    47 // ---------------------------------------------------------------------------
    47 // Symbian Constructor
    48 // Symbian Constructor
    48 // ---------------------------------------------------------------------------
    49 // ---------------------------------------------------------------------------
    49 //
    50 //
    50 CPeninputArabicFingerHwrNumSymbolTable* CPeninputArabicFingerHwrNumSymbolTable::NewL( 
    51 CPeninputArabicFingerHwrNumSymbolTable* CPeninputArabicFingerHwrNumSymbolTable::NewL( 
    97 //
    98 //
    98 void CPeninputArabicFingerHwrNumSymbolTable::OpenSymbolTable()
    99 void CPeninputArabicFingerHwrNumSymbolTable::OpenSymbolTable()
    99     {
   100     {
   100     CapturePointer( ETrue );
   101     CapturePointer( ETrue );
   101     iPopupVisible = ETrue; 
   102     iPopupVisible = ETrue; 
   102     iCurrentNumSCTType = ENumSCTLatin;
   103     UiLayout()->LockArea(UiLayout()->Rect(),this);
   103 	UiLayout()->LockArea(UiLayout()->Rect(),this);  
   104     // signal server to add the pop area        
   104     UpdateNumSymbolTable(ENumSCTLatin);
   105     if(UiLayout()->NotDrawToLayoutDevice())
       
   106         {
       
   107         struct SData
       
   108             {
       
   109             TRect rr;
       
   110             TBool flag;
       
   111             } data;
       
   112             
       
   113         data.rr = iNumKeypad->Rect();
       
   114         data.flag = ETrue;
       
   115         TPtrC ptrForAdd;
       
   116         ptrForAdd.Set(reinterpret_cast<const TUint16*>(&data),sizeof(data)/sizeof(TUint16));
       
   117 
       
   118         UiLayout()->SignalOwner(ESignalPopupArea,ptrForAdd);
       
   119         }
       
   120     
       
   121     RefreshNumSymbolTable();;
   105 	}
   122 	}
   106 
   123 
   107 // ---------------------------------------------------------------------------
   124 // ---------------------------------------------------------------------------
   108 // cancel the popup.
   125 // cancel the popup.
   109 // ---------------------------------------------------------------------------
   126 // ---------------------------------------------------------------------------
   110 //
   127 //
   111 void CPeninputArabicFingerHwrNumSymbolTable::CloseSymbolTable()
   128 void CPeninputArabicFingerHwrNumSymbolTable::CloseSymbolTable()
   112     {
   129     {
   113     CapturePointer( EFalse );
   130     CapturePointer( EFalse );
   114     iPopupVisible = EFalse;
   131     iPopupVisible = EFalse;
       
   132     // signal server to remove the pop area        
       
   133     if(UiLayout()->NotDrawToLayoutDevice())
       
   134         {
       
   135         struct SData
       
   136             {
       
   137             TRect rr;
       
   138             TBool flag;
       
   139             } data;
       
   140             
       
   141         data.rr = iNumKeypad->Rect();
       
   142         data.flag = EFalse;
       
   143         TPtrC ptrForRemove;
       
   144         ptrForRemove.Set(reinterpret_cast<const TUint16*>(&data),sizeof(data)/sizeof(TUint16));
       
   145 
       
   146         UiLayout()->SignalOwner(ESignalPopupArea,ptrForRemove);
       
   147         }    
   115     UiLayout()->UnLockArea(UiLayout()->Rect(),this);
   148     UiLayout()->UnLockArea(UiLayout()->Rect(),this);
   116     }
   149     }
   117 
   150 
   118 // ---------------------------------------------------------------------------
   151 // ---------------------------------------------------------------------------
   119 // get visibility of popup.
   152 // get visibility of popup.
   208 
   241 
   209 // ---------------------------------------------------------------------------
   242 // ---------------------------------------------------------------------------
   210 // SizeChanged
   243 // SizeChanged
   211 // ---------------------------------------------------------------------------
   244 // ---------------------------------------------------------------------------
   212 //	
   245 //	
   213 void CPeninputArabicFingerHwrNumSymbolTable::SizeChanged(
   246 void CPeninputArabicFingerHwrNumSymbolTable::SizeChanged(const TRect& aVirtualKeypadRect)
   214                      const TRect aVirtualKeypadRect, const RArray<TRect> /*aBtnRects*/,
   247     {
   215                      const TInt /*aKeypadRow*/, const TInt /*aKeypadCol*/, TBool aIsLandscape)
       
   216     {
       
   217 	iIsLandscape = aIsLandscape;
       
   218 	
       
   219 	// relayout the virtual key pad
   248 	// relayout the virtual key pad
   220 	iNumKeypad->SetRect(aVirtualKeypadRect);
   249 	iNumKeypad->SetRect(aVirtualKeypadRect);
   221 	
       
   222 	}
   250 	}
   223 	
   251 	
   224 // ---------------------------------------------------------------------------
   252 // ---------------------------------------------------------------------------
   225 // create symbol table keypad.
   253 // create symbol table keypad.
   226 // ---------------------------------------------------------------------------
   254 // ---------------------------------------------------------------------------
   244     iNumKeypad->SetResourceId( KInvalidResId );
   272     iNumKeypad->SetResourceId( KInvalidResId );
   245         
   273         
   246     iNumKeypad->SetKeyTextColorGroup( EAknsCIQsnTextColorsCG68 );
   274     iNumKeypad->SetKeyTextColorGroup( EAknsCIQsnTextColorsCG68 );
   247     iNumKeypad->SetDrawOpaqueBackground( EFalse );    
   275     iNumKeypad->SetDrawOpaqueBackground( EFalse );    
   248     }
   276     }
   249 
       
   250 void CPeninputArabicFingerHwrNumSymbolTable::OnActivate()
       
   251     {
       
   252     CControlGroup::OnActivate();
       
   253 	}
       
   254 
   277 
   255 // ---------------------------------------------------------------------------
   278 // ---------------------------------------------------------------------------
   256 //  Read control's background info.
   279 //  Read control's background info.
   257 // ---------------------------------------------------------------------------
   280 // ---------------------------------------------------------------------------
   258 //	
   281 //	
   337 // Load virtual keys image
   360 // Load virtual keys image
   338 // ---------------------------------------------------------------------------
   361 // ---------------------------------------------------------------------------
   339 //	
   362 //	
   340 void CPeninputArabicFingerHwrNumSymbolTable::LoadVkbKeyImageL(TInt aResId, const TSize& aKeySize)
   363 void CPeninputArabicFingerHwrNumSymbolTable::LoadVkbKeyImageL(TInt aResId, const TSize& aKeySize)
   341     {
   364     {
   342 	TResourceReader reader;    
   365     PeninputFingerHwrArVkbUtility::LoadVkbKeyImageL(*iNumKeypad,aResId,aKeySize);
   343     CCoeEnv::Static()->CreateResourceReaderLC( reader, aResId );      
       
   344     
       
   345     TPtrC bmpFileName = reader.ReadTPtrC();
       
   346     TInt32 imgMajorSkinId = reader.ReadInt32();
       
   347     TAknsItemID id;
       
   348     
       
   349     TSize keySize = aKeySize;
       
   350     
       
   351     for ( TInt index = 0; index <= EKeyBmpLastType ; index += 2 )
       
   352         { 
       
   353         // Get the image ids and mask ids from resource
       
   354         TInt bmpId = reader.ReadInt16(); 
       
   355         TInt bmpMskId = reader.ReadInt16();
       
   356         
       
   357         // read skin item id
       
   358         const TInt skinitemid = reader.ReadInt16();
       
   359         id.Set( TInt( imgMajorSkinId ), skinitemid );
       
   360         
       
   361         if ( bmpId != KInvalidImg )
       
   362             {
       
   363             CFbsBitmap* bmp = NULL;
       
   364             CFbsBitmap* maskbmp = NULL;
       
   365 
       
   366             if ( bmpMskId != KInvalidImg )
       
   367                 {
       
   368                 AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   369                    id, bmp, maskbmp, bmpFileName, bmpId, bmpMskId );
       
   370                 
       
   371                 // set maskbmp and size
       
   372                 AknIconUtils::SetSize( maskbmp, keySize, EAspectRatioNotPreserved );
       
   373                 iNumKeypad->SetNonIrregularKeyBitmapL( 
       
   374                 TVirtualKeyBmpType( EKeyBmpNormal + index + 1 ), maskbmp );
       
   375                 }
       
   376             else
       
   377                 {
       
   378                 AknsUtils::CreateIconL( AknsUtils::SkinInstance(), id, 
       
   379                     bmp, bmpFileName, bmpId );
       
   380                 }
       
   381             // set bmp and size
       
   382             AknIconUtils::SetSize( bmp, keySize, EAspectRatioNotPreserved );
       
   383             iNumKeypad->SetNonIrregularKeyBitmapL( 
       
   384                 TVirtualKeyBmpType( EKeyBmpNormal + index ), bmp );
       
   385             }       
       
   386         }
       
   387     // Pop and destroy reader
       
   388     CleanupStack::PopAndDestroy( 1 );        
       
   389 	}
   366 	}
   390 
   367 
   391 // ---------------------------------------------------------------------------
   368 // ---------------------------------------------------------------------------
   392 // Load virtual keys
   369 // Load virtual keys
   393 // ---------------------------------------------------------------------------
   370 // ---------------------------------------------------------------------------
   394 //	
   371 //	
   395 void CPeninputArabicFingerHwrNumSymbolTable::LoadVirtualKeypadKeyL(const TInt aResId, const RArray<TRect>& aCellRects)
   372 void CPeninputArabicFingerHwrNumSymbolTable::LoadVirtualKeypadKeyL(const TInt aResId, const RArray<TRect>& aCellRects)
   396     {
   373     {
   397 	iNumKeypad->SetResourceId(aResId);
   374 	PeninputFingerHwrArVkbUtility::LoadVirtualKeypadKeyL(*iNumKeypad,aResId,aCellRects);
   398 	
   375 	}
   399 	TResourceReader reader;
       
   400     CCoeEnv::Static()->CreateResourceReaderLC( reader, aResId );
       
   401 
       
   402     // construct keys
       
   403     TInt resKeyCount = reader.ReadInt16();
       
   404     TInt existsKeyCount = iNumKeypad->KeyArray().Count();
       
   405     TInt rectCount = aCellRects.Count();
       
   406     
       
   407     for ( TInt i = 0; i < resKeyCount; i++ )
       
   408         {
       
   409         if ( i < existsKeyCount )
       
   410             {
       
   411             CVirtualKey* vk = iNumKeypad->KeyArray()[i];
       
   412             UpdateVkbKeyL( vk, reader, aCellRects[i%rectCount] );
       
   413             }
       
   414         else
       
   415             {
       
   416             CVirtualKey* vk = CreateVkbKeyL( reader, aCellRects[i%rectCount] );
       
   417             CleanupStack::PushL( vk );
       
   418             iNumKeypad->AddKeyL( vk );
       
   419             
       
   420             CleanupStack::Pop( vk );
       
   421             }
       
   422         }
       
   423     
       
   424     CleanupStack::PopAndDestroy( 1 ); // reader
       
   425     
       
   426     iNumKeypad->Draw();
       
   427     iNumKeypad->UpdateArea( iNumKeypad->Rect() );
       
   428 	}
       
   429 
       
   430 // ---------------------------------------------------------------------------
       
   431 // create virtual key.
       
   432 // ---------------------------------------------------------------------------
       
   433 //
       
   434 CVirtualKey* CPeninputArabicFingerHwrNumSymbolTable::CreateVkbKeyL( TResourceReader& aReader, 
       
   435     const TRect aKeyRect )
       
   436     {
       
   437     CHBufCArray* keytexts = CHBufCArray::NewL();
       
   438     CleanupStack::PushL( keytexts );
       
   439     
       
   440     for ( TInt i = 0; i <= EPosLast; i++ )
       
   441         {
       
   442         HBufC* unicode = aReader.ReadHBufCL();
       
   443         keytexts->Array().AppendL( unicode );
       
   444         }
       
   445 
       
   446     TInt keyscancode = aReader.ReadInt16();
       
   447 
       
   448     HBufC* text = keytexts->Array()[0];
       
   449     
       
   450     CVirtualKey* vk = NULL;
       
   451     if ( text )
       
   452         {
       
   453         vk = CVirtualKey::NewL( *text, keyscancode, aKeyRect, aKeyRect, 0 );
       
   454         }
       
   455     else 
       
   456         {
       
   457         vk = CVirtualKey::NewL( KNullDesC, keyscancode, aKeyRect, aKeyRect, 0 );
       
   458         }
       
   459 
       
   460     CleanupStack::PopAndDestroy( keytexts ); //keytexts
       
   461 
       
   462     
       
   463     TRect innerrect = aKeyRect;
       
   464     innerrect.Shrink( TSize(10, 10) );
       
   465     vk->SetInnerRect( innerrect );
       
   466     
       
   467     return vk;
       
   468     }
       
   469 
       
   470 // ---------------------------------------------------------------------------
       
   471 // update virtual key info.
       
   472 // ---------------------------------------------------------------------------
       
   473 //
       
   474 void CPeninputArabicFingerHwrNumSymbolTable::UpdateVkbKeyL( CVirtualKey* aVirtualKey, 
       
   475     TResourceReader& aReader, const TRect aKeyRect )
       
   476     {
       
   477     CHBufCArray* keytexts = CHBufCArray::NewL();
       
   478     CleanupStack::PushL( keytexts );
       
   479     
       
   480     for ( TInt i = 0; i <= EPosLast; i++ )
       
   481         {
       
   482         HBufC* unicode = aReader.ReadHBufCL();
       
   483         keytexts->Array().AppendL( unicode );
       
   484         }
       
   485 
       
   486     TInt keyscancode = aReader.ReadInt16();
       
   487 
       
   488     HBufC* text = keytexts->Array()[0];
       
   489     if ( text )
       
   490         {
       
   491         aVirtualKey->SetKeyData( *text );
       
   492         }
       
   493     else
       
   494         {
       
   495         aVirtualKey->SetKeyData( KNullDesC );
       
   496         }
       
   497     
       
   498     aVirtualKey->SetKeyScancode( keyscancode );
       
   499 
       
   500     CleanupStack::PopAndDestroy( keytexts ); //keytexts
       
   501 
       
   502     aVirtualKey->SetRect(aKeyRect);
       
   503     TRect innerrect = aKeyRect;
       
   504     innerrect.Shrink( TSize(10,10) );
       
   505     aVirtualKey->SetInnerRect( innerrect );
       
   506     }
       
   507 
   376 
   508 // ---------------------------------------------------------------------------
   377 // ---------------------------------------------------------------------------
   509 // accept editor's number mapping restriction.
   378 // accept editor's number mapping restriction.
   510 // ---------------------------------------------------------------------------
   379 // ---------------------------------------------------------------------------
   511 //
   380 //
   512 void CPeninputArabicFingerHwrNumSymbolTable::SetNumericMapping( const TDesC& aNumMapping )
   381 void CPeninputArabicFingerHwrNumSymbolTable::UpdateTableSymbol( const TDesC& aNumMapping )
   513     {
   382     {
   514     //format of aNumMapping is "0123456789******"
   383     HBufC* charTable = GenerateCharTable(aNumMapping);
       
   384     if(charTable)
       
   385     	{
       
   386     	TInt charTalbeCount = charTable->Length();
       
   387      
       
   388 	    //numberpad
       
   389 	    TInt keyCount = iNumKeypad->KeyArray().Count();
       
   390 	    for ( TInt i = 0; i < keyCount; i++ )
       
   391 	        {
       
   392 	        CVirtualKey* vk = iNumKeypad->KeyArray()[i];
       
   393 	        
       
   394 	        if(i < charTalbeCount && (*charTable)[i] != KInvalidChar)
       
   395 	            {
       
   396 	            TBuf<1> keydata;
       
   397                 TUint16 keyCode = (*charTable)[i];	            
       
   398 	            keydata.Append(keyCode);
       
   399 	            vk->SetKeyData(keydata);
       
   400 	            vk->SetKeyScancode(keyCode);
       
   401 	            vk->SetDimmed( EFalse );
       
   402 	            }
       
   403 	        else
       
   404 	            {
       
   405 	            vk->SetKeyData( KNullDesC );
       
   406 	            vk->SetKeyScancode( KInvalidChar );
       
   407 	            vk->SetDimmed( EFalse );
       
   408 	            }
       
   409 	        }
       
   410 	    
       
   411 	    delete charTable;
       
   412 	    
       
   413 	    //sync feedback
       
   414 	    UpdateAllVirtualKeysFeedback();
       
   415     	}
       
   416     }
       
   417 
       
   418 // ---------------------------------------------------------------------------
       
   419 // Get reordered char table for key pad to render them
       
   420 // ---------------------------------------------------------------------------
       
   421 //
       
   422 HBufC* CPeninputArabicFingerHwrNumSymbolTable::GenerateCharTable(const TDesC& aNumMapping)
       
   423 	{
       
   424 	//format of aNumMapping is "0123456789******"
   515     
   425     
   516     //char offset in aNumMapping
   426     //char offset in aNumMapping
   517     //cell 0 using aNumMapping[KNumOffsets[0]]
   427     //cell 0 using aNumMapping[KNumOffsets[0]]
   518     //cell 1 using aNumMapping[KNumOffsets[1]]
   428     //cell 1 using aNumMapping[KNumOffsets[1]]
   519     const TInt KNumOffsets[] = 
   429     const TInt KNumOffsets[] = 
   521          12,  1,  2, 3,
   431          12,  1,  2, 3,
   522          13,  4,  5, 6,
   432          13,  4,  5, 6,
   523          14,  7,  8, 9,
   433          14,  7,  8, 9,
   524          15,  10, 0, 11
   434          15,  10, 0, 11
   525         };
   435         };
   526     
   436     TInt tableSize = sizeof(KNumOffsets)/sizeof(TInt);
   527     TInt maxMappingItemCount = sizeof(KNumOffsets)/sizeof(TInt);
       
   528     TInt mappingItemCount = aNumMapping.Length();
   437     TInt mappingItemCount = aNumMapping.Length();
   529     
   438     
   530     //numberpad
   439     HBufC* reorderedCharTable = HBufC::New(mappingItemCount +1);
   531     TInt keyCount = iNumKeypad->KeyArray().Count();
   440     if(reorderedCharTable)
   532     for ( TInt i = 0; i < keyCount; i++ )
   441     	{
   533         {
   442     	for(TInt i = 0; i < tableSize; i++)
   534         CVirtualKey* vk = iNumKeypad->KeyArray()[i];
   443     	    {    	    
   535         
   444     	    if(KNumOffsets[i] < mappingItemCount)
   536         TInt offset = ( i < maxMappingItemCount ) ? KNumOffsets[i] : -1;
   445     	    	{
   537         
   446     	    	TUint16 unicode = aNumMapping[KNumOffsets[i]];
   538         if ( offset > -1  && offset < mappingItemCount )
   447                 TUint16 mappedCode = MapLatinNumAccordingToNumMode(unicode);	
   539             {
   448                 reorderedCharTable->Des().Append(mappedCode); 
   540             TUint16 unicode = aNumMapping[offset];
   449     	    	}
   541             TUint16 mappedCode = MapLatinNumAccordingToNumMode(unicode);
   450     	    else
   542             TBuf<1> keydata;
   451     	    	{
   543             keydata.Append(mappedCode);
   452     	        reorderedCharTable->Des().Append(KInvalidChar);
   544             vk->SetKeyData(keydata);
   453     	    	}	
   545             vk->SetKeyScancode( mappedCode);
   454     	    }
   546             vk->SetDimmed( EFalse );
   455     	}
   547             }
   456     
   548         else
   457     return reorderedCharTable;	    
   549             {
   458 	}
   550             vk->SetKeyData( KNullDesC );
   459 	
   551             vk->SetKeyScancode( 0xFFFF );
       
   552             vk->SetDimmed( EFalse );
       
   553             }
       
   554         }
       
   555     
       
   556     
       
   557     //sync feedback
       
   558     UpdateAllVirtualKeysFeedback();
       
   559     }
       
   560 
       
   561 // ---------------------------------------------------------------------------
   460 // ---------------------------------------------------------------------------
   562 // Navigate the symbol page
   461 // Navigate the symbol page
   563 // ---------------------------------------------------------------------------
   462 // ---------------------------------------------------------------------------
   564 //
   463 //
   565 void CPeninputArabicFingerHwrNumSymbolTable::UpdateNumSymbolTable( TInt aNumSctType)
   464 void CPeninputArabicFingerHwrNumSymbolTable::RefreshNumSymbolTable()
   566     {	
   465     {
   567 
       
   568     iCurrentNumSCTType = aNumSctType;
       
   569 	// Draw the symbol table 
   466 	// Draw the symbol table 
   570     Draw();
   467     Draw();
   571 	
   468 	
   572 	// Update the feedback for the virtual key
   469 	// Update the feedback for the virtual key
   573     UpdateAllVirtualKeysFeedback();
   470     UpdateAllVirtualKeysFeedback();
   580 //  update feedback state of all virtual keys.
   477 //  update feedback state of all virtual keys.
   581 // ---------------------------------------------------------------------------
   478 // ---------------------------------------------------------------------------
   582 //
   479 //
   583 void CPeninputArabicFingerHwrNumSymbolTable::UpdateAllVirtualKeysFeedback()
   480 void CPeninputArabicFingerHwrNumSymbolTable::UpdateAllVirtualKeysFeedback()
   584     {
   481     {
   585     //update sctpad keys
   482     //update numpad keys
   586     TInt keyCount = iNumKeypad->KeyArray().Count();
   483     TInt keyCount = iNumKeypad->KeyArray().Count();
   587     for ( TInt i = 0; i < keyCount; i++ )
   484     for ( TInt i = 0; i < keyCount; i++ )
   588         {
   485         {
   589         CVirtualKey* vk = iNumKeypad->KeyArray()[i];
   486         CVirtualKey* vk = iNumKeypad->KeyArray()[i];
   590         TBool enable = !vk->Dimmed();
   487         TBool enable = !vk->Dimmed();
   591         iNumKeypad->EnableKeyFeedback( vk, enable );
   488         iNumKeypad->EnableKeyFeedback( vk, enable );
   592         }
   489         }
       
   490     }
       
   491 
       
   492 // ---------------------------------------------------------------------------
       
   493 //  update rect of all virtual keys.
       
   494 // ---------------------------------------------------------------------------
       
   495 //
       
   496 void CPeninputArabicFingerHwrNumSymbolTable::UpdateAllVirtualKeysRect(const RArray<TRect> & aCellRects)
       
   497     {
       
   498     //update numpad keys rect
       
   499     TInt keyCount = iNumKeypad->KeyArray().Count();
       
   500     TInt rectCount = aCellRects.Count();
       
   501     if(keyCount != rectCount)
       
   502         {
       
   503         return;
       
   504         }
       
   505     for ( TInt i = 0; i < keyCount; i++ )
       
   506         {
       
   507         CVirtualKey* vk = iNumKeypad->KeyArray()[i];
       
   508         TRect rect = aCellRects[i%rectCount];        
       
   509         vk->SetRect(aCellRects[i%rectCount]);
       
   510         TRect innerrect = rect;
       
   511         innerrect.Shrink( TSize(10,10) );
       
   512         vk->SetInnerRect( innerrect );
       
   513         }    
   593     }
   514     }
   594 
   515 
   595 // ---------------------------------------------------------------------------
   516 // ---------------------------------------------------------------------------
   596 //  Draw new content to the screen
   517 //  Draw new content to the screen
   597 // ---------------------------------------------------------------------------
   518 // ---------------------------------------------------------------------------