fep/aknfep/src/AknFepLanguageManager.cpp
changeset 36 a7632c26d895
parent 35 0f326f2e628e
child 42 b3eaa440ab06
equal deleted inserted replaced
35:0f326f2e628e 36:a7632c26d895
     1 /*
       
     2 * Copyright (c) 2002-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:            Implementation of CAknFepLanguageManager class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 // INCLUDE FILES
       
    30 #include "AknFepGlobalEnums.h"
       
    31 #include "AknFepPanic.h"
       
    32 #include "AknFepManager.h"                  // CAknFepManager
       
    33 #include "AknFepManagerInterface.h"
       
    34 #include "AknFepUIManagerStateInterface.h"  // MAknFepUIManagerStateInterface
       
    35 #include "AknFepUiInputStateBase.h"         // TAknFepInputStateBase
       
    36 #include "AknFepUiManagerBase.h"            // CAknFepUIManagerBase
       
    37 #include "AknFepUIManagerJapanese.h"        // CAknFepUIManagerJapanese
       
    38 #include "AknFepUiManagerWestern.h"         // CAknFepUIManagerWestern
       
    39 #include "AknFepUiManagerChinese.h"         // CAknFepUIManagerChinese
       
    40 #include "AknFepLanguageManager.h"          // this class
       
    41 
       
    42 #include "AknFepUiManagerKorean.h"        	// CAknFepUIManagerKorean
       
    43 #include <uikon.hrh>                        // TAknEditorNumericKeymap
       
    44 #include <AknUtils.h>
       
    45 
       
    46 #include <aknfeppeninputimeplugin.h>
       
    47 #include  "AknFepPluginManager.h"
       
    48 #include <peninputcmd.h>
       
    49 #include <peninputclient.h>
       
    50 
       
    51 void Cleanup( TAny* aAny )
       
    52 	{
       
    53 	RImplInfoPtrArray* implArray = 
       
    54 		reinterpret_cast< RImplInfoPtrArray*> ( aAny );
       
    55 	implArray->ResetAndDestroy();
       
    56 	implArray->Close();
       
    57 	}
       
    58 
       
    59 /**
       
    60  * CAknFepLanguageManager
       
    61  *
       
    62  */
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CAknFepLanguageManager()
       
    67 // first phase construction.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CAknFepLanguageManager* CAknFepLanguageManager::NewL(MAknFepManagerUIInterface* aFepMan, 
       
    71                                                      CAknFepCaseManager* aCaseMan)
       
    72     {
       
    73     CAknFepLanguageManager* self = new(ELeave) CAknFepLanguageManager(aFepMan, aCaseMan);
       
    74     CleanupStack::PushL(self);
       
    75     self->ConstructL();
       
    76     CleanupStack::Pop(); // self
       
    77     return self;
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // ~CAknFepLanguageManager()
       
    82 // Destructor.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CAknFepLanguageManager::~CAknFepLanguageManager()
       
    86     {
       
    87     if (iUiManArray)
       
    88         {
       
    89         iUiManArray->ResetAndDestroy();
       
    90         }
       
    91     delete iUiManArray;
       
    92     delete iCurImePlugin;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CAknFepLanguageManager::GetFepUI()
       
    97 // get ui manager object
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 MAknFepManagerInterface* CAknFepLanguageManager::GetFepUI(TInt aMode, TWidthChar /*aCharacterWidth*/, TBool aPredictive)
       
   101     {
       
   102     MAknFepManagerInterface* uiMan = NULL;
       
   103     switch (aMode)
       
   104         {
       
   105         case EPinyin:
       
   106         case EZhuyin:
       
   107         case EStroke:
       
   108         case ECangJie:
       
   109         case EZhuyinFind:
       
   110         case EStrokeFind:
       
   111             uiMan = iUiManArray->At(EUiManChinese);
       
   112             break;
       
   113         case ELatin:
       
   114         case EHindi:
       
   115             if (iInputLanguage == ELangJapanese)
       
   116                 {
       
   117                 uiMan = iUiManArray->At((aPredictive)? EUiManWestern : EUiManJapanese);
       
   118                 }
       
   119         	else if(iInputLanguage == ELangKorean)
       
   120         		{
       
   121         		uiMan = iUiManArray->At(EUiManKorean);
       
   122         		}
       
   123             else
       
   124                 {
       
   125                 uiMan = iUiManArray->At(EUiManWestern);
       
   126                 }
       
   127             break;
       
   128         case ENumber:
       
   129         case ENativeNumber:
       
   130             if (iInputLanguage == ELangJapanese)
       
   131                 {
       
   132                 uiMan = iUiManArray->At(EUiManJapanese);
       
   133                 }
       
   134             else if(iInputLanguage == ELangKorean)
       
   135                 {
       
   136                 uiMan = iUiManArray->At(EUiManKorean);
       
   137                 }
       
   138             else
       
   139                 {
       
   140                 uiMan = iUiManArray->At(EUiManWestern);
       
   141                 }
       
   142             break;
       
   143         case EHiragana:
       
   144         case EHiraganaKanji:
       
   145         case EKatakana:
       
   146             uiMan = iUiManArray->At(EUiManJapanese);
       
   147             break;
       
   148         case EHangul:
       
   149         	uiMan = iUiManArray->At(EUiManKorean);
       
   150  			break;
       
   151         default:
       
   152             AknFepPanic(EAknFepPanicNoUiManager);
       
   153             break;
       
   154         }
       
   155     return uiMan;
       
   156     }
       
   157 
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CAknFepLanguageManager::SetInputLanguageL()
       
   161 // Set new input language.
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CAknFepLanguageManager::SetInputLanguageL(TInt aInputLanguage)
       
   165     {
       
   166     iInputLanguage = aInputLanguage;
       
   167     MAknFepManagerInterface* uiManager = NULL;
       
   168     TInt uiManagerId = UiManagerId();
       
   169     uiManager = iUiManArray->At(uiManagerId);
       
   170     
       
   171     if ( !uiManager )
       
   172         {
       
   173         // Ui manager does not exist for this language yet. We create it.
       
   174         ConstructUiManagerL();
       
   175         uiManager = iUiManArray->At(uiManagerId);
       
   176         }
       
   177     
       
   178     uiManager->SetInputLanguageL((TLanguage)iInputLanguage);
       
   179     
       
   180     if (uiManagerId != EUiManWestern)
       
   181         {
       
   182         // Western UI manager needs to know current input language also when 
       
   183         // Chinese or Japanese Ui manager is used.
       
   184         // Western UI manager needs to use English language if the 
       
   185         // input language is Chinese or Japanese.
       
   186         uiManager = iUiManArray->At(EUiManWestern);
       
   187         if (uiManager)
       
   188             {
       
   189             uiManager->SetInputLanguageL((TLanguage)iInputLanguage);
       
   190             }
       
   191         }
       
   192         
       
   193     }
       
   194 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CAknFepLanguageManager()
       
   198 // Constructor.
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 CAknFepLanguageManager::CAknFepLanguageManager(MAknFepManagerUIInterface* aFepManager, 
       
   202                                                CAknFepCaseManager* aCaseManager) 
       
   203 
       
   204 :iInputLanguage(ELangEnglish), 
       
   205  iFepManager(aFepManager), 
       
   206  iCaseManager(aCaseManager),
       
   207  iPluginManager(NULL)
       
   208     {
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CAknFepLanguageManager::ConstructL()
       
   213 // Second phase construction
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CAknFepLanguageManager::ConstructL()
       
   217     {
       
   218     iUiManArray = new(ELeave)CArrayPtrFlat<MAknFepManagerInterface>(EUiManMax);
       
   219 
       
   220     for ( TInt ii = 0; ii < EUiManMax; ii++)
       
   221         {
       
   222         iUiManArray->AppendL(NULL);
       
   223         }
       
   224 
       
   225     // Create UI manager for English language. English exists in all variants and
       
   226     // it is default language in CAknFepLanguageManager.
       
   227     ConstructUiManagerL();
       
   228     }
       
   229 
       
   230 void CAknFepLanguageManager::ConstructUiManagerL()
       
   231     {
       
   232     MAknFepManagerInterface* uiMan = NULL;
       
   233     TInt uiManagerId = UiManagerId();
       
   234     iUiManArray->Delete(uiManagerId);
       
   235     switch (uiManagerId)
       
   236         {
       
   237         case EUiManWestern:
       
   238             uiMan = CAknFepUIManagerWestern::NewL(iFepManager, iCaseManager, 
       
   239                                                  (TLanguage)iInputLanguage);
       
   240             break;
       
   241         case EUiManChinese:
       
   242             uiMan = CAknFepUIManagerChinese::NewL(iFepManager, iCaseManager, 
       
   243                                                  (TLanguage)iInputLanguage);
       
   244             break;
       
   245         case EUiManJapanese:
       
   246             uiMan = CAknFepUIManagerJapanese::NewL(iFepManager, iCaseManager, 
       
   247                                                   (TLanguage)iInputLanguage);
       
   248             break;
       
   249         case EUiManKorean:
       
   250         	uiMan = CAknFepUIManagerKorean::NewL(iFepManager, iCaseManager, (TLanguage)iInputLanguage);
       
   251         	break;
       
   252         default:
       
   253             AknFepPanic(EAknFepPanicNoUiManager);
       
   254             break;
       
   255         }
       
   256     CleanupStack::PushL(uiMan);
       
   257     iUiManArray->InsertL(uiManagerId, uiMan);
       
   258     CleanupStack::Pop(); // uiMan
       
   259     }
       
   260 
       
   261 TInt CAknFepLanguageManager::UiManagerId()
       
   262     {
       
   263     TInt uiManagerId = EUiManWestern;
       
   264     switch (iInputLanguage)
       
   265         {
       
   266         case ELangPrcChinese:
       
   267         case ELangHongKongChinese:
       
   268         case ELangTaiwanChinese:
       
   269             uiManagerId = EUiManChinese;
       
   270             break;
       
   271         case ELangJapanese:
       
   272             uiManagerId = EUiManJapanese;
       
   273             break;
       
   274         case ELangKorean:
       
   275         	uiManagerId = EUiManKorean;
       
   276         	break;
       
   277         default:
       
   278             // Western UI manager is default.
       
   279             // Thai, Arabic and Hebrew uses western UI manager.
       
   280             break;
       
   281         }
       
   282     return uiManagerId;
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CAknFepLanguageManager::GetPluginInputFepUiL
       
   287 // Get plugin UI manager object.
       
   288 // (other items were commented in a header).
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 MAknFepManagerInterface* CAknFepLanguageManager::GetPluginInputFepUiL(
       
   292                                                       TPluginInputMode aPreferedMode,
       
   293                                                       TInt aPenInputLang,
       
   294                                                       TInt aDisplayLang,
       
   295                                                       RPeninputServer* aPenServer)
       
   296     {
       
   297 
       
   298     RArray<TInt> implList;
       
   299     CleanupClosePushL(implList);
       
   300     
       
   301     TPluginInputMode secondMode = EPluginInputModeItut;
       
   302     TPluginInputMode curMode = aPreferedMode;
       
   303     TInt language = aPenInputLang;
       
   304 
       
   305     //pen input language and prefered mode
       
   306     aPenServer->GetImePluginIdListL(aPenInputLang, curMode, implList);
       
   307     
       
   308     if( implList.Count() == 0 )
       
   309         {
       
   310         //pen input language and other modes
       
   311         curMode = secondMode;
       
   312         aPenServer->GetImePluginIdListL(aPenInputLang, curMode, implList);
       
   313         }
       
   314         
       
   315     if( implList.Count() == 0 && aPenInputLang != aDisplayLang)
       
   316         {
       
   317         //display language and prefered modes
       
   318         language = aDisplayLang;
       
   319         curMode = aPreferedMode;
       
   320         aPenServer->GetImePluginIdListL(aDisplayLang, curMode, implList);
       
   321 
       
   322         if( implList.Count() == 0 )
       
   323             {
       
   324             //display language and other modes
       
   325             curMode = secondMode;
       
   326             aPenServer->GetImePluginIdListL(aDisplayLang, curMode, implList);
       
   327             }
       
   328         }
       
   329         
       
   330     CAknFepPenInputImePlugin* pIme = NULL;
       
   331     MAknFepManagerInterface* pUi = NULL;
       
   332     TInt i;
       
   333     for(i = 0; i < implList.Count(); ++i)
       
   334         {
       
   335         pIme = ActivateImePlugin(implList[i], aPenServer);
       
   336         if( pIme )
       
   337             {
       
   338             pUi = ActivateLayoutUiPluginL(pIme, language, curMode);
       
   339             if( pUi )
       
   340                 {
       
   341                 iCurUiPlugIn = pUi;
       
   342                 if( iCurImePlugin != pIme )
       
   343                     {
       
   344                     //a new IME plugin created
       
   345                     delete iCurImePlugin;
       
   346                     iCurImePlugin = pIme;
       
   347                     }
       
   348                 break;
       
   349                 }
       
   350             else
       
   351                 {
       
   352                 //Fail create UI, delete IME plugin just created
       
   353                  if( iCurImePlugin != pIme )
       
   354                      {
       
   355                      delete pIme;
       
   356                      }
       
   357                 }
       
   358             }        
       
   359         }
       
   360     
       
   361     if( i == implList.Count() )
       
   362         {
       
   363         delete iCurImePlugin;
       
   364         iCurImePlugin = NULL;
       
   365         iCurUiPlugIn = NULL;
       
   366         }
       
   367     CleanupStack::PopAndDestroy(&implList);    
       
   368     return iCurUiPlugIn;
       
   369     }
       
   370 
       
   371 TBool  CAknFepLanguageManager::IsPluginInputAvaiable(TPluginInputMode aMode, 
       
   372                                                      TInt aPenInputLang,
       
   373                                                      RPeninputServer* aPenServer)
       
   374     {
       
   375     TBool bAvail = EFalse;
       
   376     TRAP_IGNORE(bAvail = IsPluginInputAvaiableL(aMode, aPenInputLang, aPenServer));
       
   377     return bAvail;
       
   378     }
       
   379 
       
   380 TBool  CAknFepLanguageManager::IsPluginInputAvaiableL(TPluginInputMode aMode, 
       
   381                                                      TInt aPenInputLang,
       
   382                                                      RPeninputServer* aPenServer)
       
   383     {
       
   384     RArray<TInt> implList;
       
   385     CleanupClosePushL(implList);
       
   386     
       
   387     aPenServer->GetImePluginIdListL(aPenInputLang, aMode, implList);    
       
   388     TBool bAvail = implList.Count() != 0;
       
   389     CleanupStack::PopAndDestroy(&implList);    
       
   390     return bAvail;
       
   391     }
       
   392 
       
   393 // -----------------------------------------------------------------------------
       
   394 // CAknFepLanguageManager::ActivateImePlugin
       
   395 // Activate IME plugin by implemenation.
       
   396 // (other items were commented in a header).
       
   397 // -----------------------------------------------------------------------------
       
   398 //
       
   399 CAknFepPenInputImePlugin* CAknFepLanguageManager::ActivateImePlugin(
       
   400                                                  TInt aImeImplId, 
       
   401                                                  RPeninputServer* aPenServer)
       
   402     {
       
   403     if(iCurImePlugin && iCurImePlugin->ImeImplId() == aImeImplId)
       
   404         {
       
   405         return iCurImePlugin;
       
   406         }
       
   407     else
       
   408         {
       
   409         TUid dtor_ID_Key;
       
   410         CAknFepPenInputImePlugin* pIme = NULL;
       
   411 
       
   412         TRAP_IGNORE(pIme = REINTERPRET_CAST(CAknFepPenInputImePlugin*, 
       
   413               REComSession::CreateImplementationL(TUid::Uid(aImeImplId), dtor_ID_Key, aPenServer)));
       
   414 
       
   415         if( pIme )
       
   416             {
       
   417             pIme->iDtor_ID_Key = dtor_ID_Key;           
       
   418             }
       
   419 
       
   420         return pIme;
       
   421         }
       
   422     }
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CAknFepLanguageManager::ActivateLayoutUiPluginL
       
   426 // Activate IME plugin's UI by mode.
       
   427 // (other items were commented in a header).
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 MAknFepManagerInterface* CAknFepLanguageManager::ActivateLayoutUiPluginL(
       
   431                                                    CAknFepPenInputImePlugin* aImePlugin, 
       
   432                                                    TInt aPenInputLang,
       
   433                                                    TPluginInputMode aMode)
       
   434     {
       
   435     MAknFepManagerInterface* pUi = NULL;
       
   436 
       
   437     if( aImePlugin )
       
   438         {
       
   439         pUi = aImePlugin -> GetInputMethodUiL(iFepManager,
       
   440                                             (TLanguage)aPenInputLang, 
       
   441                                             aMode,
       
   442                                             KNullDesC8(),
       
   443                                             iIsSplitView);
       
   444         //set inputlanguage                                                             
       
   445         if(pUi)
       
   446             {
       
   447             pUi->SetInputLanguageL((TLanguage)aPenInputLang);
       
   448             //pUi->ActivateUI();
       
   449             }
       
   450         }
       
   451     
       
   452     return pUi;
       
   453     }
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // CAknFepLanguageManager::SetSplitView
       
   457 // Activate IME plugin's UI by mode.
       
   458 // (other items were commented in a header).
       
   459 // -----------------------------------------------------------------------------
       
   460 //
       
   461 void CAknFepLanguageManager::SetSplitView(TBool aIsSplitView)
       
   462     {
       
   463     iIsSplitView = aIsSplitView;
       
   464     }
       
   465 
       
   466 // End of File