textinput/peninputcommonctrls/src/peninputselectionlist/peninputlayoutinputmodechoice.cpp
changeset 27 694fa80c203c
parent 24 fc42a86c98e3
child 35 0f326f2e628e
equal deleted inserted replaced
24:fc42a86c98e3 27:694fa80c203c
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Implement of touch input mode switch
       
    15 *
       
    16 */
       
    17  
       
    18   
       
    19 #include <peninputlayoutchoicelist.h>
       
    20 #include <peninputlayout.h>
       
    21 #include <AknIconUtils.h>
       
    22 #include <AknLayoutDef.h>
       
    23 #include <AknUtils.h>
       
    24 #include <aknlayoutscalable_avkon.cdl.h>
       
    25 #include <barsread.h>
       
    26 #include <AknsUtils.h>
       
    27 #include <peninputmodeswitchutilsnew.rsg>
       
    28 #include <bautils.h>
       
    29 #include <AknFepGlobalEnums.h> 
       
    30 #include <peninputlayoutinputmodechoice.h>
       
    31 #include <AknFepInternalCRKeys.h>
       
    32 #include <centralrepository.h>
       
    33 #include <aknappui.h> 
       
    34 
       
    35 // CONSTANT 
       
    36 const TInt KInvalidImg = -1 ;
       
    37 _LIT(KAknUtilsResourceFileName, "z:\\resource\\peninputmodeswitchutilsnew.rsc");
       
    38 const TInt KCCMask(0x00000fff);
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // C++ constructor.
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CPeninputLayoutInputmodelChoice::CPeninputLayoutInputmodelChoice(CFepUiLayout* aUiLayout, 
       
    46             TInt aControlId,TPluginInputMode aInputMode) 
       
    47 : CPeninputCommonChoiceList( aUiLayout, aControlId, KAknsIIDNone, KAknsIIDNone, EAutoFitLength )
       
    48     { 
       
    49     iConstructed = EFalse;
       
    50     iUiLayout = aUiLayout;
       
    51     iCurPluginInputMode = aInputMode;
       
    52     iInputLanguage = ELangTest;
       
    53     iSecretEditor = EFalse;       
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Symbian Constructor
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 EXPORT_C CPeninputLayoutInputmodelChoice* CPeninputLayoutInputmodelChoice::NewL(
       
    61     CFepUiLayout* aUiLayout,
       
    62     TInt aControlId, TPluginInputMode aInputMode)
       
    63     {
       
    64     CPeninputLayoutInputmodelChoice *self = new (ELeave) 
       
    65         CPeninputLayoutInputmodelChoice(aUiLayout, aControlId, aInputMode);
       
    66     
       
    67     CleanupStack::PushL(self);
       
    68     self->CustomConstructL();
       
    69     CleanupStack::Pop();
       
    70 
       
    71     return self;
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Destructor
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C CPeninputLayoutInputmodelChoice::~CPeninputLayoutInputmodelChoice()
       
    79     {
       
    80     iInputModeItems.Close();
       
    81     delete iAknFepRepository;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Pop up touch input switch list
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 EXPORT_C void CPeninputLayoutInputmodelChoice::PopUpSwitchListL( const TRect& aRtControl )
       
    89     {
       
    90     ResetListItemL();
       
    91 
       
    92     if (ItemsCount() > 0 && ItemByIndex(0))
       
    93         {
       
    94         Display(aRtControl);    
       
    95         }
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Initialize internal control
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 void CPeninputLayoutInputmodelChoice::DoInitializeControlL()
       
   103     {
       
   104     if (iConstructed)
       
   105         {
       
   106         return;
       
   107         }
       
   108     iAknFepRepository = CRepository::NewL(KCRUidAknFep);
       
   109         
       
   110     SizeChanged();
       
   111     
       
   112     RFs fsSession;
       
   113 
       
   114     User::LeaveIfError(fsSession.Connect());
       
   115     CleanupClosePushL(fsSession);
       
   116 
       
   117     RResourceFile rsFile;
       
   118     
       
   119     TFileName resourceName(KAknUtilsResourceFileName);
       
   120     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   121     BaflUtils::NearestLanguageFile(fsSession, resourceName);
       
   122     
       
   123     rsFile.OpenL(fsSession, resourceName);
       
   124     CleanupClosePushL(rsFile);
       
   125     
       
   126     // Create choice list
       
   127     TResourceReader reader;
       
   128 
       
   129     HBufC8* rBuffer = rsFile.AllocReadLC(PENINPUTMODE_SWITCH_CHOICELIST & KCCMask); 
       
   130     reader.SetBuffer(rBuffer);
       
   131 
       
   132     TPtrC bmpFileName = reader.ReadTPtrC();
       
   133     TInt32 imgMajorSkinId = reader.ReadInt32();
       
   134 
       
   135     if (CreateItemIconL(reader, &iPopupWndBgImg, bmpFileName, imgMajorSkinId))
       
   136         {
       
   137        SetBackgroundBitmapL(iPopupWndBgImg);
       
   138         }
       
   139 
       
   140     if (CreateItemIconL(reader, &iPopupWndFocusImg, bmpFileName, imgMajorSkinId))
       
   141         {
       
   142         SetFocusBmp(iPopupWndFocusImg);
       
   143         }
       
   144     	
       
   145     CleanupStack::PopAndDestroy(1); 
       
   146     
       
   147     // read name to list
       
   148     
       
   149     CreateChoiceItemL( reader, rsFile );
       
   150 /*    CreateChoiceItemL(iInputModeItem[EPenInputHwr], EPluginInputModeHwr, 
       
   151                       R_PENINPUTMODE_NAMES, reader, rsFile);
       
   152                       
       
   153     CreateChoiceItemL(iInputModeItem[EPenInputVkb], EPluginInputModeVkb, 
       
   154                       R_PENINPUTMODE_VKB, reader, rsFile);
       
   155                       
       
   156     CreateChoiceItemL(iInputModeItem[EPenInputItut], EPluginInputModeItut, 
       
   157                       R_PENINPUTMODE_FINGERITUT, reader, rsFile);
       
   158                       
       
   159     CreateChoiceItemL(iInputModeItem[EPenInputFSc], EPluginInputModeFSc,
       
   160                       R_PENINPUTMODE_FULLHWR, reader, rsFile);
       
   161     
       
   162 */
       
   163     CleanupStack::PopAndDestroy(2);
       
   164     
       
   165     iConstructed = ETrue;  
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // Application size Changed
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void CPeninputLayoutInputmodelChoice::SizeChanged()    
       
   173     {
       
   174     /*
       
   175     if ( Hiden() )
       
   176         {
       
   177         iChoiceList->CloseWindow();
       
   178         }
       
   179     */    
       
   180     TRect mainPaneRect = MainPaneRect();
       
   181         
       
   182     TAknWindowLineLayout choiceWnd = 
       
   183         AknLayoutScalable_Avkon::popup_choice_list_window(1).LayoutLine();
       
   184     
       
   185     TAknLayoutRect choiceRect;
       
   186     choiceRect.LayoutRect(mainPaneRect, choiceWnd);
       
   187 
       
   188    iItemRect = TRect(
       
   189         0, 0, choiceRect.Rect().Width(),
       
   190         AknLayoutScalable_Avkon::list_single_choice_list_pane(0).LayoutLine().iH);
       
   191 
       
   192     TAknTextLineLayout choiceTextLayout = 
       
   193         AknLayoutScalable_Avkon::list_single_choice_list_pane_t1(1).LayoutLine();
       
   194 
       
   195     const CFont* font = AknLayoutUtils::FontFromId(choiceTextLayout.iFont, NULL);
       
   196  
       
   197     SetFont(font);
       
   198     SetItemRect(iItemRect, iItemRect);
       
   199 
       
   200     const TInt leftMargin = choiceTextLayout.il;
       
   201    
       
   202     SetMarginAndBaseline(leftMargin,font->HeightInPixels());
       
   203     SetFontColor(AKN_LAF_COLOR_STATIC(choiceTextLayout.iC));
       
   204 
       
   205     if (iPopupWndBgImg)
       
   206     	{
       
   207     	AknIconUtils::SetSize(iPopupWndBgImg, 
       
   208     	                      TSize(iItemRect.Width(), iItemRect.Height() * 3), 
       
   209     	                      EAspectRatioNotPreserved);
       
   210     	}
       
   211     
       
   212     if (iPopupWndFocusImg)
       
   213     	{
       
   214     	AknIconUtils::SetSize(iPopupWndFocusImg, 
       
   215     	                      TSize(iItemRect.Width(), iItemRect.Height() * 3), 
       
   216     	                      EAspectRatioNotPreserved);
       
   217     	}
       
   218 
       
   219     iPopupItemSize = iItemRect.Size();    
       
   220     }    
       
   221     
       
   222 // ---------------------------------------------------------------------------
       
   223 // Symbian second-phase constructor
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CPeninputLayoutInputmodelChoice::CustomConstructL( )
       
   227     {
       
   228     //CFepLayoutChoiceList::NewL(iUiLayout, aControlId);
       
   229     // call base class construction
       
   230     this->ConstructL();
       
   231     
       
   232     DoInitializeControlL();
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // Insert choice item to input mode switch list
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void CPeninputLayoutInputmodelChoice::CreateChoiceItemL( TResourceReader &aReader, 
       
   240                                                          RResourceFile& aRsFile )
       
   241     {
       
   242     HBufC8* rBuffer = aRsFile.AllocReadLC( R_PENINPUTMODE_NAMES & KCCMask );
       
   243     aReader.SetBuffer(rBuffer);
       
   244     
       
   245     TInt index;
       
   246     TInt number;
       
   247     number = aReader.ReadInt16();
       
   248     
       
   249     CFepLayoutChoiceList::SItem item;
       
   250     for (index = 0; index < number ; index++)
       
   251         {
       
   252         item.iCommand = aReader.ReadInt32();
       
   253         //TPtrC ptr = aReader.ReadTPtrC();
       
   254         HBufC* buf = aReader.ReadHBufCL();
       
   255         item.iText.Copy( buf->Des() );
       
   256         delete buf;
       
   257         iInputModeItems.AppendL( item );
       
   258         }
       
   259 
       
   260     CleanupStack::PopAndDestroy(1);
       
   261     }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // Create choice item icon
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 TBool CPeninputLayoutInputmodelChoice::CreateItemIconL(TResourceReader &aReader, 
       
   268     CFbsBitmap** aImg, TPtrC& aBmpFileName, TInt32 aMajorSkinId)
       
   269     {
       
   270     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
   271     
       
   272     const TInt bmpId = aReader.ReadInt16();
       
   273     const TInt bmpMaskId = aReader.ReadInt16();
       
   274     const TInt bmpSkinId = aReader.ReadInt16();
       
   275 
       
   276     TAknsItemID id;
       
   277     id.Set(TInt(aMajorSkinId), bmpSkinId);
       
   278     
       
   279     if (bmpId != KInvalidImg)
       
   280     	{
       
   281         AknsUtils::CreateIconL(skinInstance,
       
   282                                id,
       
   283                                *aImg,
       
   284                                aBmpFileName,
       
   285                                bmpId);
       
   286                                 
       
   287         AknIconUtils::SetSize(*aImg, iPopupItemSize, EAspectRatioNotPreserved); 
       
   288     	
       
   289     	return ETrue;
       
   290     	}
       
   291     	
       
   292     return EFalse;
       
   293     }    
       
   294 
       
   295     
       
   296 // ---------------------------------------------------------------------------
       
   297 // Get main pane rect
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 TRect CPeninputLayoutInputmodelChoice::MainPaneRect()
       
   301     {
       
   302     TAknWindowLineLayout appWnd; 
       
   303     TAknWindowLineLayout mainPane;
       
   304     TAknLayoutRect mainPaneLayout;
       
   305              
       
   306     appWnd = AknLayoutScalable_Avkon::application_window( 0 ).LayoutLine();
       
   307 
       
   308     TInt id = appWnd.iW > appWnd.iH ? 4 : 1;
       
   309     
       
   310     mainPane = AknLayoutScalable_Avkon::main_pane(id).LayoutLine();
       
   311     mainPaneLayout.LayoutRect(appWnd.Rect(), mainPane);
       
   312 
       
   313     return mainPaneLayout.Rect();
       
   314     }
       
   315 
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // Reset choice list item
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 void CPeninputLayoutInputmodelChoice::ResetListItemL()
       
   322     {
       
   323     TInt layouts = iUiLayout->GetEnabledPluginMode();
       
   324         
       
   325     ClearItemsL();
       
   326     
       
   327     for ( int i = 0; i < iInputModeItems.Count(); i++ )
       
   328         {
       
   329         if ( layouts & iInputModeItems[i].iCommand  )
       
   330             {
       
   331             InsertListItemL( iInputModeItems[i], iInputModeItems[i].iCommand );
       
   332             }
       
   333         }
       
   334        
       
   335     SetListColumnNumWithLafL( ItemsCount() );
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // Insert list item
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 void CPeninputLayoutInputmodelChoice::InsertListItemL( const CFepLayoutChoiceList::SItem& item,
       
   343      TInt aInputMode)
       
   344     {
       
   345     TInt value = 0;
       
   346     if (iAknFepRepository)
       
   347         {
       
   348         iAknFepRepository->Get(KAknFepInputTxtLang, value);
       
   349         
       
   350         iInputLanguage = TLanguage(value);
       
   351         }
       
   352 
       
   353     if (iSecretEditor && (aInputMode == EPluginInputModeHwr ||
       
   354         aInputMode == EPluginInputModeFSc || aInputMode == EPluginInputModeFingerHwr))
       
   355         {
       
   356         return;
       
   357         }
       
   358 
       
   359     // Added for <Single Click>. Do not insert current input mode to the list
       
   360     if (iUiLayout && (iUiLayout->PenInputType() == aInputMode))
       
   361     	{
       
   362     	return;
       
   363     	}
       
   364     
       
   365     // if current input mode is in choice list, add item to it
       
   366     // (!ItemByCommand(aInputMode))
       
   367     if(FindCommand(aInputMode) < 0)
       
   368         {
       
   369         AddItemL( item );
       
   370         }
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // Set current editor is secure
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 EXPORT_C void CPeninputLayoutInputmodelChoice::SetSecretEditor(TBool aSecret)
       
   378     {
       
   379     iSecretEditor = aSecret;
       
   380     }    
       
   381 
       
   382 
       
   383 // ---------------------------------------------------------------------------
       
   384 // Get switch list rect
       
   385 // ---------------------------------------------------------------------------
       
   386 //
       
   387 EXPORT_C TRect CPeninputLayoutInputmodelChoice::SwitchListRect()
       
   388     {
       
   389     return TRect(0,0,iItemRect.Width(), iItemRect.Height() * ItemsCount());
       
   390     }
       
   391     
       
   392 // End Of File