uifw/AvKon/src/aknutils.cpp
changeset 0 2f259fa3e83a
child 3 8ca85d2f0db7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-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:  General Avkon Utilities. Includes:
       
    15 *                   - listbox utilities
       
    16 *                   - layout utilities
       
    17 *                   - text utilities
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 #include "AknUtils.h"
       
    23 #include "AknBidiTextUtils.h"
       
    24 #include <eikfrlb.h>
       
    25 #include <eikfrlbd.h>
       
    26 #include <eikclb.h>
       
    27 #include <eikclbd.h>
       
    28 #include <eikenv.h>
       
    29 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    30 #include <uikon/eikenvinterface.h>
       
    31 #endif
       
    32 #include <eikappui.h>
       
    33 #include <eikslb.h>
       
    34 #include <eikslbd.h>
       
    35 #include <gulicon.h>
       
    36 #include <AknGrid.h>
       
    37 #include <eikbtgpc.h>
       
    38 #include <eikcapc.h>
       
    39 
       
    40 #include "avkon.hrh"
       
    41 #include <avkon.rsg>
       
    42 
       
    43 #include "aknappui.h"
       
    44 #include "AknPanic.h"
       
    45 #include "aknkeys.h"
       
    46 #include <barsread.h>
       
    47 #include "AknLib.h"
       
    48 #include "akntitle.h"
       
    49 
       
    50 #include <eikedwin.h>
       
    51 #include <eikmfne.h>
       
    52 #include <eikimage.h>
       
    53 
       
    54 #include <txtfrmat.h>
       
    55 #include <txtglobl.h>
       
    56 #include <txtrich.h>
       
    57 
       
    58 #include "aknsfld.h"
       
    59 #include "AknTextWrapper.h"
       
    60 #include <eikdialg.h>
       
    61 
       
    62 
       
    63 #include <aknenv.h>
       
    64 #include <coemain.h>
       
    65 #include <eikseced.h>
       
    66 
       
    67 #include <lafpanic.h> 
       
    68 
       
    69 #include <eikmenup.h>
       
    70 
       
    71 #include "aknlists.h"
       
    72 #include <fontids.hrh>
       
    73 #include <gulfont.h>
       
    74 #include <eikapp.h>
       
    75 #include <FindUtil.h>
       
    76 
       
    77 #include <AknsDrawUtils.h>
       
    78 #include <AknsControlContext.h>
       
    79 
       
    80 #include <AknsUtils.h>
       
    81 #include <AknsListBoxBackgroundControlContext.h>
       
    82 #include <AknsConstants.h>
       
    83 
       
    84 #include <numberconversion.h>
       
    85 
       
    86 #include <linebreak.h>
       
    87 #include "AknLineBreaker.h"
       
    88 #include "AknBuildVariant.h"
       
    89 #include <biditext.h>
       
    90 #include <AknSettingCache.h>
       
    91 
       
    92 #include <featmgr.h>
       
    93 
       
    94 #include <aknlayout.cdl.h>
       
    95 #include <skinlayout.cdl.h>
       
    96 
       
    97 #include <AknTextDecorationMetrics.h>
       
    98 #include <AknFontSpecification.h>
       
    99 #include <AknLayoutFont.h>
       
   100 #include <AknFontId.h>
       
   101 #include <AknFontProvider.h>
       
   102 #include <aknlayoutscalable_avkon.cdl.h>
       
   103 #include <layoutmetadata.cdl.h>
       
   104 #include "AknFontSpecificationLayoutFont.h"
       
   105 #include <AknIconUtils.h>
       
   106 #include <languages.hrh>
       
   107 #include <AknSystemFont.h>
       
   108 #include "AvkonVariant.hrh"
       
   109 
       
   110 #include <AknStatuspaneUtils.h>
       
   111 #include <StringLoader.h>
       
   112 #include <AknSgcc.h>
       
   113 #include <centralrepository.h>
       
   114 #include <AvkonInternalCRKeys.h>
       
   115 #include <akntoolbar.h>
       
   116 #include <akntouchpane.h>
       
   117 #include "AknLayoutUtilsHelpers.h"
       
   118 
       
   119 #include "AknAdaptiveSearch.h"
       
   120 #include <PtiEngine.h>
       
   121 
       
   122 #include <akntrace.h> 
       
   123 
       
   124 #ifdef RD_HINDI_PHONETIC_INPUT
       
   125 #include <ptiindicdefs.h>
       
   126 #endif
       
   127 
       
   128 using namespace AknLayout;
       
   129 
       
   130 // CONSTANTS
       
   131 
       
   132 const TInt KAknStringBufferSize = 256;
       
   133 const TInt KTextColorNone = -1;
       
   134 const TInt KFontHeightComparisonDivisor = 20;
       
   135 const TInt KInvalidIndex = -1;
       
   136 
       
   137 enum TAknLayoutEdwinPanic
       
   138     {
       
   139     EAknLayoutEdwinPanicNoEdwin,
       
   140     EAknLayoutEdwinPanicNoLinesOverMaxNoLines,
       
   141     EAknLayoutEdwinPanicNotSupported
       
   142     };
       
   143 
       
   144 void Panic(TAknLayoutEdwinPanic aPanic)
       
   145     {
       
   146     _LIT(KAknLayoutUtilsLayoutEdwin,"AknLayoutUtils::LayoutEdwin");
       
   147     User::Panic(KAknLayoutUtilsLayoutEdwin, aPanic);
       
   148     };
       
   149 
       
   150 void Panic(TLafPanic aPanic)
       
   151     {
       
   152     _LIT(KLafEnv,"LafEnv");
       
   153     User::Panic(KLafEnv, aPanic);
       
   154     };
       
   155 
       
   156 // For debugging purposes.
       
   157 #ifdef AKNUTILS_ENABLE_TRACES
       
   158         #define LOGTEXT(AAA)                     RDebug::Print(AAA)
       
   159         #define LOGTEXT1(AAA,BBB)                RDebug::Print(AAA,BBB)
       
   160         #define LOGTEXT2(AAA,BBB,CCC)            RDebug::Print(AAA,BBB,CCC)
       
   161         #define LOGTEXT3(AAA,BBB,CCC,DDD)        RDebug::Print(AAA,BBB,CCC,DDD)
       
   162         #define LOGTEXT4(AAA,BBB,CCC,DDD,EEE)    RDebug::Print(AAA,BBB,CCC,DDD,EEE)
       
   163 #else
       
   164         #define LOGTEXT(AAA)                     NULL
       
   165         #define LOGTEXT1(AAA,BBB)                NULL
       
   166         #define LOGTEXT2(AAA,BBB,CCC)            NULL
       
   167         #define LOGTEXT3(AAA,BBB,CCC,DDD)        NULL
       
   168         #define LOGTEXT4(AAA,BBB,CCC,DDD,EEE)    NULL  
       
   169 #endif 
       
   170 
       
   171 //
       
   172 // Automatic numbering for columnlistbox.
       
   173 // CListBoxNumbers
       
   174 //
       
   175 EXPORT_C CListBoxNumbers::CListBoxNumbers(CEikTextListBox *aListBox)
       
   176     {
       
   177     iListBox = aListBox;
       
   178     }
       
   179 
       
   180 EXPORT_C void CListBoxNumbers::ConstructL()
       
   181     {
       
   182     UpdateL();
       
   183     }
       
   184 
       
   185 
       
   186 EXPORT_C void CListBoxNumbers::UpdateL()
       
   187     {
       
   188     TInt e = iListBox->Model()->NumberOfItems();
       
   189     MDesCArray* itemList = iListBox->Model()->ItemTextArray();
       
   190     CDesCArray* itemArray = STATIC_CAST(CDesCArray*,itemList);
       
   191     for (int i=0;i<e;i++)
       
   192         {
       
   193         TPtrC item = (*itemArray)[i];
       
   194         TInt pos = item.Locate('\t');
       
   195         TBuf<KAknStringBufferSize> data; 
       
   196         data.Num(i+1);
       
   197         data+=item.Right(item.Length()-pos);
       
   198         itemArray->Delete(i);
       
   199         itemArray->InsertL(i,data);
       
   200         }   
       
   201     }
       
   202 
       
   203 
       
   204 // Fonts
       
   205 
       
   206 EXPORT_C const CFont *LatinPlain12()
       
   207     { 
       
   208     switch (AknLayoutUtils::Variant())
       
   209         {
       
   210         case EEuropeanVariant:
       
   211             return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlp12)));
       
   212 
       
   213         case EApacVariant:
       
   214             // should not come here ever
       
   215             return ApacPlain12();
       
   216 
       
   217         default:
       
   218             return 0;
       
   219         }
       
   220 
       
   221     }
       
   222 
       
   223 EXPORT_C const CFont *LatinBold12() 
       
   224     { 
       
   225     return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlb12))); 
       
   226     }
       
   227 
       
   228 EXPORT_C const CFont *LatinBold13()
       
   229     { 
       
   230     return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlb13)));
       
   231     }
       
   232 EXPORT_C const CFont *LatinBold16()
       
   233     {
       
   234     return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlb16)));
       
   235     }
       
   236 
       
   237 EXPORT_C const CFont *LatinBold17()
       
   238     { 
       
   239     switch (AknLayoutUtils::Variant())
       
   240         {
       
   241         case EEuropeanVariant:
       
   242             return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlb17)));
       
   243 
       
   244         case EApacVariant:
       
   245             return LatinBold13();
       
   246 
       
   247         default:
       
   248             return 0;
       
   249         }
       
   250     }
       
   251 
       
   252 EXPORT_C const CFont *LatinBold19() 
       
   253     { 
       
   254         switch (AknLayoutUtils::Variant())
       
   255         {
       
   256         case EEuropeanVariant:
       
   257             return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlb19)));
       
   258 
       
   259         case EApacVariant:
       
   260             return LatinBold17();
       
   261 
       
   262         default:
       
   263             return 0;
       
   264         }
       
   265   
       
   266     }
       
   267 EXPORT_C const CFont *ClockBold30()
       
   268     {
       
   269     return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAcb30)));
       
   270     }
       
   271 
       
   272 EXPORT_C const CFont *NumberPlain5()
       
   273     {
       
   274     return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAcp5)));
       
   275     }
       
   276 
       
   277 EXPORT_C const CFont *LatinClock14() 
       
   278     { 
       
   279     return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAcb14)));
       
   280     }
       
   281 
       
   282 const CFont *CalcBold21() 
       
   283     { 
       
   284     return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAcalc21)));
       
   285     }
       
   286 
       
   287 const CFont *CalcOperBold21() 
       
   288     { 
       
   289     return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAco21)));
       
   290     }
       
   291 
       
   292 const CFont *CalcOperBold13() 
       
   293     { 
       
   294     return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAco13)));
       
   295     }
       
   296 
       
   297 EXPORT_C const CFont *ApacPlain12() 
       
   298     { 
       
   299     // Combined font is used for all subvariants
       
   300     if ( AknLayoutUtils::Variant() == EApacVariant )
       
   301         {
       
   302         return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidCombinedChinesePlain12)));
       
   303         }
       
   304     else
       
   305         {
       
   306         //this should not be called in Western builds
       
   307         //__ASSERT_DEBUG(0, Panic(ELafPanicUsingFontFromWrongVariant));
       
   308         return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlb13)));
       
   309         }
       
   310 
       
   311     }
       
   312 
       
   313 EXPORT_C const CFont *ApacPlain16() 
       
   314     {
       
   315     // Combined font is used for all subvariants
       
   316     if ( AknLayoutUtils::Variant() == EApacVariant )
       
   317         {
       
   318         return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidCombinedChinesePlain16)));
       
   319         }
       
   320     else
       
   321         {
       
   322         //this should not be called in Western builds
       
   323         //__ASSERT_DEBUG(0, Panic(ELafPanicUsingFontFromWrongVariant));
       
   324         return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlb13)));
       
   325         }
       
   326     }
       
   327 
       
   328 const CFont* PrimaryFont()
       
   329     {
       
   330     if ( AknLayoutUtils::Variant() == EApacVariant )
       
   331         {
       
   332         return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidCombinedChinesePlain16)));
       
   333         }
       
   334     else
       
   335         {
       
   336         return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlb13)));
       
   337         }
       
   338     }
       
   339 
       
   340 const CFont* SecondaryFont()
       
   341     {
       
   342     if ( AknLayoutUtils::Variant() == EApacVariant )
       
   343         {
       
   344         return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidCombinedChinesePlain12)));
       
   345         }
       
   346     else
       
   347         {
       
   348         return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlp12)));
       
   349         }
       
   350     }
       
   351 
       
   352 const CFont* TitleFont()
       
   353     {
       
   354     if ( AknLayoutUtils::Variant() == EApacVariant )
       
   355         {
       
   356         return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidCombinedChinesePlain16)));
       
   357         }
       
   358     else
       
   359         {
       
   360         return CEikonEnv::Static()->Font(TLogicalFont(TUid::Uid(KScreenFontUidAlb19)));
       
   361         }
       
   362     }
       
   363 
       
   364 
       
   365 //
       
   366 // Find implementation
       
   367 //
       
   368 
       
   369 EXPORT_C
       
   370 void AknFind::HandleFindPopupProcessCommandL( TInt aCommand,
       
   371                                               CEikListBox * aListBox,
       
   372                                               CAknSearchField *aSearch,
       
   373                                               CCoeControl *aParentControl )
       
   374     {
       
   375     _AKNTRACE_FUNC_ENTER;
       
   376     if ( aSearch && aCommand == EAknCmdFindPopupActivated )
       
   377         {
       
   378         if ( aListBox )
       
   379             {
       
   380             aSearch->SetOldItemIndex( aListBox->CurrentItemIndex() );
       
   381             }
       
   382         aSearch->MakeVisible( ETrue );
       
   383         aSearch->SetFocus( ETrue );
       
   384         HandlePopupFindSizeChanged( aParentControl, aListBox, aSearch );
       
   385         }
       
   386     _AKNTRACE_FUNC_EXIT;
       
   387     }
       
   388 
       
   389 EXPORT_C
       
   390 void AknFind::HandleFixedFindSizeChanged( CCoeControl *aParentControl,
       
   391                                           CAknColumnListBox *aListBox,
       
   392                                           CAknSearchField *aSearchField )
       
   393     {
       
   394     _AKNTRACE_FUNC_ENTER;
       
   395     TAknWindowLineLayout empty;
       
   396     empty.iC = 0;
       
   397     empty.il = 0;
       
   398     empty.it = 0;
       
   399     empty.ir = 0;
       
   400     empty.ib = 0;
       
   401     empty.iW = ELayoutEmpty;
       
   402     empty.iH = ELayoutEmpty;
       
   403 
       
   404     TAknWindowLineLayout findPane = AknLayoutScalable_Avkon::find_pane().LayoutLine();
       
   405     TAknWindowLineLayout listPane;
       
   406 
       
   407     // listPane should equal to parent's rect
       
   408     listPane.il = aParentControl->Rect().iTl.iX;
       
   409     listPane.ir = ELayoutEmpty;
       
   410     listPane.it = aParentControl->Rect().iTl.iY;
       
   411     listPane.ib = ELayoutEmpty;
       
   412 
       
   413     // this check is required since it's not guaranteed that listbox's SetRect
       
   414     // has been called when this code is executed
       
   415     if ( aParentControl->Size().iWidth > 0 )
       
   416         {
       
   417         listPane.iW = aParentControl->Size().iWidth;
       
   418         listPane.ir = ELayoutEmpty;
       
   419         }
       
   420     else
       
   421         {
       
   422         listPane.iW = ELayoutEmpty;
       
   423         listPane.ir = 0;
       
   424         }
       
   425     
       
   426     // but findpane's height should be subtracted
       
   427     listPane.iH = aParentControl->Size().iHeight - findPane.iH;
       
   428 
       
   429     // findPane's width should equal to listPane's width
       
   430     findPane.iW = listPane.iW;
       
   431     
       
   432     HandleFindSizeChangedLayouts( aParentControl,
       
   433                                   aListBox,
       
   434                                   aSearchField,
       
   435                                   findPane,
       
   436                                   listPane,
       
   437                                   EFalse,
       
   438                                   empty );
       
   439     _AKNTRACE_FUNC_EXIT;
       
   440     }
       
   441 
       
   442 
       
   443 EXPORT_C
       
   444 void AknFind::HandlePopupFindSizeChanged( CCoeControl *aParentControl,
       
   445                                           CEikListBox *aListBox,
       
   446                                           CAknSearchField *aSearchField )
       
   447     {
       
   448     _AKNTRACE_FUNC_ENTER;
       
   449     TAknWindowLineLayout findPane = AknLayoutScalable_Avkon::popup_find_window().LayoutLine();
       
   450     TAknWindowLineLayout listPane;
       
   451 
       
   452     // listPane should equal to parent's rect
       
   453     listPane.il = aParentControl->Rect().iTl.iX;
       
   454     listPane.it = aParentControl->Rect().iTl.iY;
       
   455     listPane.ib = 0;
       
   456     listPane.iH = ELayoutEmpty;
       
   457     
       
   458     // this check is required since it's not guaranteed that listbox's SetRect
       
   459     // has been called when this code is executed
       
   460     if ( aParentControl->Size().iWidth > 0 )
       
   461         {
       
   462         listPane.iW = aParentControl->Size().iWidth;
       
   463         listPane.ir = ELayoutEmpty;
       
   464         }
       
   465     else
       
   466         {
       
   467         listPane.iW = ELayoutEmpty;
       
   468         listPane.ir = 0;
       
   469         }
       
   470     
       
   471     // findPane's width should equal to listPane's width
       
   472     findPane.iW = listPane.iW;
       
   473     
       
   474     HandleFindSizeChangedLayouts( aParentControl,
       
   475                                   aListBox,
       
   476                                   aSearchField,
       
   477                                   findPane,
       
   478                                   listPane,
       
   479                                   ETrue,
       
   480                                   main_pane( screen().Rect(), 0, 1, 1) );
       
   481     _AKNTRACE_FUNC_EXIT;
       
   482     }
       
   483 
       
   484 
       
   485 // THIS METHOD IS DEPRECATED
       
   486 EXPORT_C void AknFind::HandleFindSizeChanged(CCoeControl *aParentControl, 
       
   487                          CEikListBox *aListBox, 
       
   488                          CAknSearchField *aSearchField, 
       
   489                          TBool ispopup, 
       
   490                          TInt aFindWindowResourceId, 
       
   491                          TInt aListAreaResourceId, 
       
   492                          TInt aListResourceIdWithFindPopup, 
       
   493                          TInt aFindWindowParentResourceId)
       
   494     {
       
   495     _AKNTRACE_FUNC_ENTER;
       
   496     if (aSearchField)
       
   497     {
       
   498     aSearchField->SetListbox(aListBox);
       
   499     aSearchField->SetParentCtrl(aParentControl);
       
   500     STATIC_CAST(CAknFilteredTextListBoxModel*,aListBox->Model())->Filter()->SetParentControl(aParentControl);
       
   501     TRect parentrect = aParentControl->Rect();
       
   502     if (ispopup)
       
   503         { // popup find position is different
       
   504         ((CAknFilteredTextListBoxModel*)aListBox->Model())->Filter()->SetPopup();
       
   505         parentrect = iAvkonAppUi->ApplicationRect();
       
   506         TBuf<KAknStringBufferSize> criteria;
       
   507         aSearchField->GetSearchText(criteria);
       
   508         if (aSearchField->IsVisible() )
       
   509         aListAreaResourceId = aListResourceIdWithFindPopup;
       
   510         } 
       
   511     else 
       
   512         { // normal find has different empty list
       
   513         CAknColumnListBoxView *view = STATIC_CAST(CAknColumnListBoxView*,aListBox->View());
       
   514         view->EnableFindEmptyList();
       
   515         }
       
   516     TAknLayoutRect lrect;
       
   517     lrect.LayoutRect(parentrect, aFindWindowParentResourceId);
       
   518     AknLayoutUtils::LayoutControl(aSearchField, lrect.Rect(), aFindWindowResourceId);
       
   519     _AKNTRACE( "[%s][%s] SearchField Rect iTl: %d,%d; iBr: %d,%d", 
       
   520                 "AknFind", __FUNCTION__, 
       
   521                 lrect.Rect().iTl.iX, lrect.Rect().iTl.iY, 
       
   522                 lrect.Rect().iBr.iX, lrect.Rect().iBr.iY 
       
   523                 );
       
   524     }
       
   525     AknLayoutUtils::LayoutControl(aListBox, aParentControl->Rect(), aListAreaResourceId);
       
   526     _AKNDEBUG(
       
   527             if ( aListBox )
       
   528                 {
       
   529     		_AKNTRACE( "[%s][%s] ListBox Rect iTl: %d,%d; iBr: %d,%d", 
       
   530     				"AknFind", __FUNCTION__, 
       
   531     				aParentControl->Rect().iTl.iX, aParentControl->Rect().iTl.iY, 
       
   532     				aParentControl->Rect().iBr.iX, aParentControl->Rect().iBr.iY 
       
   533 				);
       
   534                 }
       
   535         );
       
   536     _AKNTRACE_FUNC_EXIT;
       
   537     }
       
   538 
       
   539 EXPORT_C void AknFind::HandleFindSizeChangedLayouts(
       
   540     CCoeControl *aParentControl, 
       
   541     CEikListBox *aListBox, 
       
   542     CAknSearchField *aSearchField, 
       
   543     const TAknWindowLineLayout& aFindWindow,
       
   544     const TAknWindowLineLayout& aListArea,
       
   545     TBool aIsPopup, 
       
   546     const TAknWindowLineLayout& aFindWindowParent)
       
   547     {
       
   548     _AKNTRACE_FUNC_ENTER;
       
   549     TAknWindowLineLayout tempListArea = aListArea;
       
   550     
       
   551     if (aSearchField)
       
   552         {
       
   553         aSearchField->SetParentCtrl(aParentControl);
       
   554         aSearchField->SetListbox(aListBox);
       
   555         CAknFilteredTextListBoxModel* m = static_cast <CAknFilteredTextListBoxModel*> ( aListBox->Model() );
       
   556         if ( m->Filter() )
       
   557             {
       
   558             m->Filter()->SetParentControl( aParentControl );
       
   559             }
       
   560 
       
   561         TRect parentrect( aParentControl->Rect() );
       
   562         
       
   563         if (aIsPopup)
       
   564             { // popup find position is different
       
   565             if ( m->Filter() )
       
   566                 {
       
   567                 m->Filter()->SetPopup();
       
   568                 }
       
   569             // TPTN-7AXDMZ. For fixed toolbar.
       
   570             TRect rect;
       
   571             parentrect = AknLayoutUtils::LayoutMetricsRect( 
       
   572                 AknLayoutUtils::EApplicationWindow, rect) ? 
       
   573                 rect : 
       
   574                 iAvkonAppUi->ApplicationRect();
       
   575 
       
   576             if ( iAvkonAppUi->CurrentFixedToolbar() 
       
   577                  && AknLayoutUtils::PenEnabled() 
       
   578                  && !Layout_Meta_Data::IsLandscapeOrientation() )
       
   579                 {
       
   580                 CAknToolbar* toolbar = iAvkonAppUi->CurrentFixedToolbar();
       
   581                 TInt flags = toolbar->ToolbarFlags(); 
       
   582                 if ( flags & KAknToolbarFixed 
       
   583                      && !( flags & KAknToolbarDefault )
       
   584                      && toolbar->IsShown() ) 
       
   585                     {
       
   586                     parentrect.iBr.iY -= toolbar->Rect().Height();
       
   587                     }
       
   588                 }
       
   589             TBuf<KAknStringBufferSize> criteria;
       
   590             aSearchField->GetSearchText(criteria);
       
   591             if (aSearchField->IsVisible() )
       
   592                 {
       
   593                 if (tempListArea.iH == ELayoutEmpty) 
       
   594                     { 
       
   595                     tempListArea.iH = TInt16(ELayoutP - tempListArea.it - tempListArea.ib); 
       
   596                     }
       
   597                 
       
   598                 tempListArea.iH = 
       
   599                     TUint16(tempListArea.iH - ( AknLayoutScalable_Avkon::popup_find_window().LayoutLine().iH - 1 ) );
       
   600                 }
       
   601             } 
       
   602         else 
       
   603             { // normal find has different empty list
       
   604             CAknColumnListBoxView *view = STATIC_CAST(CAknColumnListBoxView*,aListBox->View());
       
   605             view->EnableFindEmptyList();
       
   606             }
       
   607             
       
   608         TAknLayoutRect lrect;
       
   609         lrect.LayoutRect(parentrect, aFindWindowParent);
       
   610         AknLayoutUtils::LayoutControl(aSearchField, lrect.Rect(), aFindWindow);
       
   611         _AKNTRACE( "[%s][%s] SearchField Rect iTl: %d,%d; iBr: %d,%d", 
       
   612                     "AknFind", __FUNCTION__, 
       
   613                     lrect.Rect().iTl.iX, lrect.Rect().iTl.iY, 
       
   614                     lrect.Rect().iBr.iX, lrect.Rect().iBr.iY 
       
   615                     );
       
   616         }
       
   617         
       
   618     AknLayoutUtils::LayoutControl(aListBox, aParentControl->Rect(), tempListArea);
       
   619     _AKNDEBUG(
       
   620     		if ( aListBox )
       
   621                 {
       
   622                 _AKNTRACE( "[%s][%s] ListBox Rect iTl: %d,%d; iBr: %d,%d", 
       
   623                             "AknFind", __FUNCTION__,
       
   624                             aListBox->Rect().iTl.iX, aListBox->Rect().iTl.iY, 
       
   625                             aListBox->Rect().iBr.iX, aListBox->Rect().iBr.iY 
       
   626                             );
       
   627                 }
       
   628 		);
       
   629     if ( aListBox )
       
   630         {
       
   631         aListBox->DrawNow();
       
   632         }
       
   633     _AKNTRACE_FUNC_EXIT;
       
   634     }
       
   635 
       
   636 void AknFind::HandleFindPaneVisibility(CAknSearchField *aSearchField, TBool ispopup, TBool textnotchanged, TBool &aNeedRefresh)
       
   637     {
       
   638     if (ispopup)
       
   639         {
       
   640         TBuf<KAknStringBufferSize> criteria;
       
   641         aSearchField->GetSearchText(criteria);
       
   642         TBool oldvisibility = aSearchField->IsVisible();
       
   643         TBool findboxvisible;
       
   644         TInt newlength = criteria.Length();
       
   645         
       
   646         _AKNTRACE( "[%s][%s] Text Length is: %d", 
       
   647                     "AknFind", __FUNCTION__, newlength );
       
   648                
       
   649         if (newlength == 0)
       
   650             {
       
   651             findboxvisible = EFalse;
       
   652             if (textnotchanged && oldvisibility)
       
   653                 {
       
   654                 findboxvisible=ETrue;
       
   655                 }
       
   656             }
       
   657         else
       
   658             {
       
   659             findboxvisible = ETrue;
       
   660             }
       
   661         if (findboxvisible != oldvisibility)
       
   662             {
       
   663             aSearchField->SetFocus(findboxvisible);
       
   664             aSearchField->MakeVisible(findboxvisible);            
       
   665             aNeedRefresh = ETrue;
       
   666             }
       
   667         _AKNTRACE( "[%s][%s] SearchField's visibility is: %d", 
       
   668                     "AknFind", __FUNCTION__, aNeedRefresh );
       
   669         }
       
   670     }
       
   671 
       
   672 #define ISFINDWORDSEPARATOR( aCh ) ( (aCh) == ' ' || (aCh) == '-' || (aCh) == '\t' )
       
   673 const TInt KMatchingBufferLength(256);
       
   674 const TInt KLitSpace(' ');
       
   675 const TInt KLitStar('*');
       
   676 const TInt KLitTab('\t');
       
   677 
       
   678 EXPORT_C TBool AknFind::IsFindMatch( const TDesC &aItemString, const TDesC &aSearchText )
       
   679     {
       
   680     TInt length = aItemString.Length();
       
   681     for( TInt i = 0; i < length; i++ )
       
   682         {
       
   683         if ( i==0 || ISFINDWORDSEPARATOR( aItemString[i-1] ) )
       
   684             {
       
   685             if ( aItemString.Mid(i).FindC( aSearchText ) == 0 )
       
   686                 {               
       
   687                 return ETrue;
       
   688                 }
       
   689             }
       
   690         }
       
   691     return EFalse;
       
   692     }
       
   693 
       
   694 EXPORT_C TBool AknFind::IsFindWordSeparator(TChar aCh)
       
   695     {
       
   696     return ISFINDWORDSEPARATOR( aCh );
       
   697     }
       
   698     
       
   699 // -----------------------------------------------------------------------------
       
   700 // For Vietnamese AS
       
   701 // 
       
   702 // -----------------------------------------------------------------------------
       
   703 //
       
   704 inline TChar ReplaceVietnameseChar( const TChar aCh )   
       
   705     {
       
   706     TChar Char = aCh.GetUpperCase();
       
   707     if ( (Char >= 0x00C0 && Char <= 0x00C3) || Char == 0x102  ||
       
   708          ((Char >= 0x1EA0 && Char <= 0x1EB6) && Char%2 == 0) )  
       
   709         {
       
   710         Char = 0x0041; // A
       
   711         return Char; 
       
   712         }
       
   713     if ( (Char >= 0x00C8 && Char <= 0x00CA) || 
       
   714         ((Char >= 0x1EB8 && Char <= 0x1EC6) && Char%2 == 0) )
       
   715         {
       
   716         Char = 0x0045; // E
       
   717         return Char; 
       
   718         }               
       
   719     if ( Char == 0x00CC || Char == 0x00CD || Char == 0x0128 || 
       
   720          Char == 0x1EC8 || Char == 0x1ECA  )
       
   721         {
       
   722         Char = 0x0049; // I
       
   723         return Char; 
       
   724         }    
       
   725     if ( (Char >= 0x00D2 && Char <= 0x00D5 ) || Char == 0x1ECE || Char == 0x1ECC ||
       
   726         ((Char >= 0x1ED0 && Char <= 0x1ED8) && Char%2 == 0)) 
       
   727         {
       
   728         Char = 0x004F; // O
       
   729         return Char; 
       
   730         }            
       
   731     if ( Char == 0x1EDA || Char == 0x1EDC || Char == 0x1EDE || 
       
   732          Char == 0x1EE0 || Char == 0x1EE2  )
       
   733         {
       
   734         Char = 0x01A0; // O-horn
       
   735         return Char; 
       
   736         }          
       
   737     if ( Char == 0x00DA || Char == 0x00D9 || Char == 0x0168 || 
       
   738          Char == 0x1EE4 || Char == 0x1EE6  )
       
   739         {
       
   740         Char = 0x0055; // U
       
   741         return Char; 
       
   742         }         
       
   743      if ( (Char >= 0x1EE8 && Char <= 0x1EF0) && Char%2 == 0 )
       
   744         {
       
   745         Char = 0x01AF; // U-horn        
       
   746         return Char; 
       
   747         }         
       
   748      if ( ((Char >= 0x1EF2 && Char <= 0x1EF8) && Char%2 == 0) || Char == 0x00DD ) 
       
   749         {
       
   750         Char = 0x0059; // Y
       
   751         return Char; 
       
   752         }              
       
   753     return Char;
       
   754     } 
       
   755     
       
   756  /**
       
   757  * Checks current character is it special character from Vietnamese language . 
       
   758  *
       
   759  * @since 5.0
       
   760  * @return @c ETrue If it is accent from Vietnamese language, otherwise EFalse. 
       
   761  */	
       
   762 inline TBool IsVietnameseSpecialCharacter( TChar aCh )
       
   763     {  
       
   764     if ( ( aCh >= 0x0300 && aCh <= 0x0303 ) || aCh == 0x0306 ||     
       
   765            aCh == 0x0309 || aCh == 0x0323 || aCh == 0x031B )
       
   766             {
       
   767             return ETrue;            
       
   768             }
       
   769      return EFalse;
       
   770     }
       
   771   
       
   772 // ---------------------------------------------------------------------------
       
   773 // Checks the current character for special character from Thai language . 
       
   774 // ---------------------------------------------------------------------------
       
   775 inline TBool IsThaiSpecialCharacter( TChar aCh )
       
   776     {    
       
   777     if( ( aCh > 0xE46 && aCh < 0xE4F ) ||  aCh == 0xE3A )
       
   778 		{
       
   779 		return ETrue;
       
   780 		}       
       
   781 	return EFalse;
       
   782     }
       
   783   
       
   784 // ---------------------------------------------------------------------------
       
   785 // IsAdaptiveFindMatch
       
   786 // ---------------------------------------------------------------------------
       
   787 //
       
   788 EXPORT_C TBool AknFind::IsAdaptiveFindMatch( const TDesC& aItemText, 
       
   789 										     const TDesC& aSearchText,
       
   790  										 	 HBufC*& aNextChars )
       
   791 	{	
       
   792 	HBufC16* searchText( NULL );
       
   793 	TRAPD( error, searchText = HBufC16::NewL( KMatchingBufferLength ) );
       
   794 	if ( error == KErrNone )
       
   795 	    {
       
   796 	    TInt itemStringLength = aItemText.Length();
       
   797         TInt searchTextLength = aSearchText.Length();    
       
   798         
       
   799         if ( searchTextLength < KMatchingBufferLength )
       
   800         	{
       
   801         	searchText->Des().Append( aSearchText );
       
   802         	}
       
   803         else
       
   804         	{
       
   805         	searchText->Des().Append( aSearchText.Left(KMatchingBufferLength-1) );
       
   806         	}    
       
   807     	
       
   808         searchText->Des().Append( KLitStar );
       
   809             
       
   810         TInt all_result = KErrNotFound;
       
   811         for( TInt i = 0; i < itemStringLength; i++ )
       
   812             {
       
   813             if ( i==0 || IsFindWordSeparator( aItemText[i-1] ) )
       
   814                 {
       
   815                 TInt result = aItemText.Mid(i).MatchC( searchText->Des() );
       
   816                 
       
   817                 if( result != KErrNotFound ) 
       
   818                     {
       
   819                     all_result = result;
       
   820                     if( i < (itemStringLength-searchTextLength) )                	   	       	   		
       
   821                         {                 
       
   822                 	   	 if( !(IsThaiSpecialCharacter(aItemText[i+searchTextLength])) && !(IsVietnameseSpecialCharacter( aItemText[i+searchTextLength]) ))
       
   823                                 {
       
   824                                 TRAP_IGNORE( UpdateNextCharsL( aNextChars, aItemText[i+searchTextLength]) );   
       
   825                                 }   
       
   826                         }
       
   827                     }                                                                  	   	
       
   828                 } // if (i==0 ..)        
       
   829       	    } // for	 
       
   830 	    
       
   831   	    if( all_result != KErrNotFound )
       
   832             {
       
   833             delete searchText;
       
   834             return ETrue;
       
   835            	}    
       
   836         else 
       
   837             {
       
   838             delete searchText;
       
   839             return EFalse;
       
   840             }
       
   841         	            		
       
   842          } // if (error == KErrNone)   
       
   843 
       
   844     delete searchText;                 
       
   845     return EFalse;
       
   846 	}
       
   847 	
       
   848 
       
   849 /**
       
   850  * For Devanagari AS
       
   851  * Checks if the passed string denotes one of the four special
       
   852  * Devanagari ligatures - refer UI specs for the description of special ligatures
       
   853  * @param aCharString - The string containing set of characters to be checked
       
   854  * @return ETrue if a special ligature is found EFalse otherwise.    
       
   855  */
       
   856 inline TBool IsSpecialIndicLigature(const TDesC& aCharString )
       
   857     {
       
   858     TBool ret = EFalse;
       
   859     if( aCharString.Length() >= 3 )
       
   860      {
       
   861         //First check for Devanagari special ligatures
       
   862         if(
       
   863             ( ( (aCharString[0] == 0x915) && (aCharString[1] == 0x94D)&& (aCharString[2] == 0x937) ) ||
       
   864               ( (aCharString[0] == 0x91C) && (aCharString[1] == 0x94D)&& (aCharString[2] == 0x91E) ) ||
       
   865               ( (aCharString[0] == 0x936) && (aCharString[1] == 0x94D)&& (aCharString[2] == 0x930) ) ||
       
   866               ( (aCharString[0] == 0x924) && (aCharString[1] == 0x94D)&& (aCharString[2] == 0x930) )  ))            
       
   867             {
       
   868             ret = ETrue;
       
   869             }       
       
   870         }
       
   871     return ret;
       
   872     }
       
   873 
       
   874 /**
       
   875  * For Devanagari AS
       
   876  * Checks if the given character is a Indic consonant. 
       
   877  * @param aSearchChar - Character to be checked.  
       
   878  * @return ETrue if this is an independent character EFalse otherwise.           
       
   879  */
       
   880 inline TBool IsIndicConsonant(const TChar aSearchChar)
       
   881     {    
       
   882     if  (
       
   883         ( aSearchChar >= 0x0915 && aSearchChar <= 0x0939 ) 
       
   884         || ( aSearchChar >= 0x0958 && aSearchChar <= 0x0961 )
       
   885         )
       
   886         {
       
   887         return ETrue;
       
   888         }
       
   889     else 
       
   890         {
       
   891         return EFalse;
       
   892         }
       
   893     }
       
   894 
       
   895 
       
   896 /**
       
   897  * For Devanagari AS
       
   898  * Checks if aCh denotes a consonant with nukta. 
       
   899  * @param aCh - character to be checked
       
   900  * @return ETrue if aCh is a consonant with nukta EFalse otherwise.
       
   901  */
       
   902 inline TBool IsIndicCombinedChar( const TChar aCh )
       
   903     {   
       
   904     if ( aCh < 0x0900 || aCh > 0x0980 )
       
   905         {
       
   906         return EFalse;
       
   907         }
       
   908     else
       
   909         {
       
   910         return ( aCh == 0x0929 || aCh == 0x0931 
       
   911                 || aCh == 0x0934 || (aCh >= 0x0958 && aCh <= 0x095F) );
       
   912         }
       
   913     }
       
   914 
       
   915 /**
       
   916  * For Devanagari AS
       
   917  * This is to check if the character can be displayed on the 
       
   918  * adaptive search grid or not. 
       
   919  * @param aCh character to be displayed on adaptive search grid
       
   920  * @return ETrue if the character is valid for AS Grid EFalse otherwise.    
       
   921  */
       
   922 TBool inline IsValidCharForASGrid(TChar aCh)
       
   923     {
       
   924     //first check for Devanagari character range. 
       
   925     if ( aCh < 0x0900 || aCh > 0x0980 )
       
   926         {
       
   927         return ETrue;
       
   928         }
       
   929     else 
       
   930         {
       
   931         return (
       
   932         !( (aCh >= 0x0901 && aCh <= 0x0903) || //Devanagari modifier
       
   933            (aCh >= 0x093C && aCh <= 0x094D) //Devanagari dependent vowels
       
   934          ) );
       
   935         }
       
   936     }
       
   937 
       
   938 
       
   939 /**
       
   940  * For Devanagari AS
       
   941  * Returns the correcponding character without nukta
       
   942  * @param aCh - character to be stripped of nukta * 
       
   943  * @return corresponding character with nukta
       
   944  */
       
   945 inline TChar RemoveIndicNukta( const TChar aCh )
       
   946     {
       
   947     switch (aCh)
       
   948         {
       
   949         case 0x0929 : return 0x0928; //vocallic 'nna' to 'na'
       
   950         case 0x0931 : return 0x0930; //vocallic 'rra' to 'ra'
       
   951         case 0x0934 : return 0x0933; //vocallic 'lllla' to 'lla'
       
   952         case 0x0958 : return 0x0915; //vocallic 'qa' to 'ka'
       
   953         case 0x0959 : return 0x0916; //vocallic 'khha' to 'kha'
       
   954         case 0x095A : return 0x0917; //vocallic 'ghha' to 'ga'
       
   955         case 0x095B : return 0x091C; //letter 'za' to 'ja'
       
   956         case 0x095C : return 0x0921; //vocallic 'dddha' to 'da'
       
   957         case 0x095D : return 0x0922; //vocallic 'rha' to 'ddha'
       
   958         case 0x095E : return 0x092B; //letter 'fa' to 'pha'
       
   959         case 0x095F : return 0x092F; //letter 'yya' to 'ya'
       
   960         
       
   961         default : return aCh;
       
   962         }
       
   963     }
       
   964 
       
   965 
       
   966 // -----------------------------------------------------------------------------
       
   967 // For Devanagari AS
       
   968 // Checks if the last character entered is a Indic halant character.
       
   969 // @param aCh - character to be checked  
       
   970 // @return ETrue if this is a halant character EFalse otherwise 
       
   971 // -----------------------------------------------------------------------------
       
   972 inline TBool IsIndicHalantChar(const TChar aCh)
       
   973     {    
       
   974     return ( aCh == 0x094D );
       
   975     }
       
   976 
       
   977 // ---------------------------------------------------------------------------
       
   978 // For Devanagari AS
       
   979 // AknFind::UpdateNextCharsL
       
   980 // ---------------------------------------------------------------------------
       
   981 //
       
   982 void AknFind::UpdateNextCharsL( HBufC*& aNextChars, const TDesC& aItemString )
       
   983 	{
       
   984 	_AKNTRACE_FUNC_ENTER;
       
   985 	TChar searchChar = aItemString[0];
       
   986 	    //Check if this is an Indic special ligature
       
   987 	    if ( IsIndicConsonant(searchChar) && aItemString.Length() > 2
       
   988 	            && IsSpecialIndicLigature(aItemString) 
       
   989 	            && KErrNotFound == (*aNextChars).Find(aItemString.Mid(0,3)) )
       
   990 	        {
       
   991 	        //Check if we have enough space for 3 more characters
       
   992 	        if( aNextChars->Des().Length() >= aNextChars->Des().MaxLength()-3 )
       
   993 	            {
       
   994 	            aNextChars = aNextChars->ReAllocL( aNextChars->Des().MaxLength()+10 );
       
   995 	            TInt length1 = aNextChars->Des().Length();
       
   996 	            TInt maxlength1 = aNextChars->Des().MaxLength();
       
   997 	            }       
       
   998 	        aNextChars->Des().Append( aItemString.Mid(0,3) );        
       
   999 	        }
       
  1000 	    else
       
  1001 	        {
       
  1002 	        if ( !IsValidCharForASGrid(searchChar) ) 
       
  1003 	            {
       
  1004 	            return;	            
       
  1005 	            }
       
  1006 	        //check if this is an Indic combined Char
       
  1007 	        if ( IsIndicCombinedChar(searchChar) )
       
  1008 	            {
       
  1009 	            searchChar = RemoveIndicNukta( searchChar );
       
  1010 	            }
       
  1011 	        //Now update the nextChars string
       
  1012             TInt strLength = aNextChars->Length();
       
  1013             for ( TInt i(0); i < strLength ; ++i )
       
  1014                 {
       
  1015                 if ( IsSpecialIndicLigature( (*aNextChars).Mid(i) ) )
       
  1016                     {
       
  1017                     //As aItemString is not a special ligature (checked above)
       
  1018                     //we can move directly to the 3rd character from here
       
  1019                     i+=2;
       
  1020                     continue;
       
  1021                     }
       
  1022                 else if ( searchChar.GetUpperCase() == (*aNextChars)[i] ||
       
  1023                             searchChar.GetLowerCase() == (*aNextChars)[i] )
       
  1024                     {
       
  1025                     //already exists - do nothing
       
  1026                     return;
       
  1027                     }
       
  1028                 //else continue the loop
       
  1029                 }
       
  1030             //So this character is not yet in the list of nextChars.
       
  1031             if( aNextChars->Des().Length() == aNextChars->Des().MaxLength() )
       
  1032                 {
       
  1033                 aNextChars = aNextChars->ReAllocL( aNextChars->Des().MaxLength()+10 );
       
  1034                 }       
       
  1035             aNextChars->Des().Append( searchChar );   
       
  1036 	        }
       
  1037 	    _AKNTRACE_FUNC_EXIT;
       
  1038 	}
       
  1039 
       
  1040 // -----------------------------------------------------------------------------
       
  1041 // AknFind::UpdateNextCharsL
       
  1042 // (other items were commented in a header).
       
  1043 // -----------------------------------------------------------------------------
       
  1044 //  
       
  1045 void AknFind::UpdateNextCharsL( HBufC*& aNextChars, TChar aCh )
       
  1046     {
       
  1047     TChar ch_temp = aCh;  
       
  1048     aCh = ReplaceVietnameseChar ( ch_temp );      
       
  1049     if( ( aNextChars->Locate(aCh.GetLowerCase() ) == KErrNotFound ) &&
       
  1050         ( aNextChars->Locate(aCh.GetUpperCase() ) == KErrNotFound ) )
       
  1051         {               
       
  1052         if( aNextChars->Des().Length() == aNextChars->Des().MaxLength() )
       
  1053             {
       
  1054             aNextChars = aNextChars->ReAllocL( aNextChars->Des().MaxLength()+10 );
       
  1055             TInt length1 = aNextChars->Des().Length();
       
  1056             TInt maxlength1 = aNextChars->Des().MaxLength();
       
  1057             }       
       
  1058         aNextChars->Des().Append( aCh );            
       
  1059         }
       
  1060     }
       
  1061 
       
  1062 // ---------------------------------------------------------------------------
       
  1063 // UpdateNextCharsFromString
       
  1064 // ---------------------------------------------------------------------------
       
  1065 //
       
  1066 EXPORT_C void AknFind::UpdateNextCharsFromString( HBufC*& aNextChars, const TDesC& aItemString )
       
  1067 	{
       
  1068 	TInt itemStringLength = aItemString.Length();
       
  1069 	     
       
  1070 	for( TInt i = 0; i < itemStringLength; i++ )
       
  1071 	    {
       
  1072 	    if ( i == 0 || IsFindWordSeparator( aItemString[i-1] ) )
       
  1073 	        {  
       
  1074 	        // If Indic letter
       
  1075 	        if ( aItemString[i] >= 0x0900 && aItemString[i] <= 0x0980 )
       
  1076 	            {
       
  1077 	            TRAP_IGNORE( UpdateNextCharsL( aNextChars, aItemString.Mid(i) ) );
       
  1078 	            }
       
  1079 	        else  if (!(IsVietnameseSpecialCharacter( aItemString[i])))
       
  1080 	            {
       
  1081 	            TRAP_IGNORE( UpdateNextCharsL( aNextChars, aItemString[i] ) );
       
  1082 	            }
       
  1083 	        }
       
  1084 	    }
       
  1085 	}
       
  1086 
       
  1087 // ---------------------------------------------------------------------------
       
  1088 // UpdateItemTextAccordingToFlag
       
  1089 // ---------------------------------------------------------------------------
       
  1090 //
       
  1091 EXPORT_C void AknFind::UpdateItemTextAccordingToFlag( const TDesC& aInputText, 
       
  1092                                                       TBitFlags32 aColumnFlag, 
       
  1093                                                       TDes& aOutText )
       
  1094     {
       
  1095     TInt MaxColumn = 32; 
       
  1096     TPtrC tmptext;   
       
  1097     for ( TInt column=0; column<MaxColumn; column++ )
       
  1098         {
       
  1099         if ( aColumnFlag.IsSet( column ) )
       
  1100             {
       
  1101             if( KErrNone == TextUtils::ColumnText(tmptext, column, &aInputText, KLitTab) )
       
  1102                 {  
       
  1103                 aOutText.Append( tmptext );
       
  1104                 aOutText.Append( KLitSpace );
       
  1105                 }
       
  1106             else 
       
  1107                 {
       
  1108                 // no more columns
       
  1109                 column = MaxColumn;
       
  1110                 }
       
  1111             }
       
  1112         }
       
  1113     // remove the last added space
       
  1114     TInt deleteTrailingSpace = aOutText.Length() - 1;
       
  1115     if( deleteTrailingSpace > 0 )
       
  1116         {
       
  1117         // delete the trailing whitespace
       
  1118         aOutText.Delete( (aOutText.Length()-1), 1 ); 
       
  1119         }        
       
  1120     aOutText.UpperCase(); 
       
  1121     }   
       
  1122     
       
  1123     
       
  1124 
       
  1125 EXPORT_C
       
  1126 TKeyResponse AknFind::HandleFindOfferKeyEventL( const TKeyEvent &aKeyEvent,
       
  1127                                                 TEventCode aType,
       
  1128                                                 CCoeControl * /*aListBoxParent*/,
       
  1129                                                 CEikListBox *aListBox,
       
  1130                                                 CAknSearchField *aSearchField,
       
  1131                                                 TBool ispopup,
       
  1132                                                 TBool &aNeedRefresh )
       
  1133     {
       
  1134     if (aType != EEventKey)
       
  1135         {
       
  1136         return EKeyWasNotConsumed;
       
  1137         }
       
  1138     
       
  1139     if (aKeyEvent.iCode == '#')
       
  1140         {
       
  1141         return EKeyWasNotConsumed;
       
  1142         }        
       
  1143         
       
  1144     aNeedRefresh = EFalse;
       
  1145 
       
  1146     if (!aSearchField || !aListBox)
       
  1147         {
       
  1148         return EKeyWasNotConsumed;
       
  1149         }
       
  1150 
       
  1151 
       
  1152     TBool removePopup = EFalse;
       
  1153     
       
  1154     /* THE case where normal letters come from keyboard */
       
  1155     TKeyResponse result = EKeyWasNotConsumed;
       
  1156     TBuf<256> criteria;
       
  1157     aSearchField->GetSearchText(criteria);
       
  1158     TInt oldlength = criteria.Length();
       
  1159 
       
  1160     if ( !aSearchField->IsVisible() && oldlength == 0 )
       
  1161         {
       
  1162         aSearchField->SetOldItemIndex( aListBox->CurrentItemIndex() );
       
  1163         }
       
  1164     
       
  1165     // EHLI-7PKBEJ Old code just support ITUT keypad... now we extend it
       
  1166     // to QWERTY keyboard.
       
  1167     if ( aSearchField->IsVisible() == EFalse && ispopup && oldlength == 0
       
  1168          && TChar(aKeyEvent.iCode).IsPrint())
       
  1169         {
       
  1170         aSearchField->SetFocus(ETrue);
       
  1171         aSearchField->MakeVisible(ETrue);
       
  1172         
       
  1173         ((CAknFilteredTextListBoxModel*)aListBox->Model())->Filter()->DeferredSendFullKeyEventToFepL(aKeyEvent);
       
  1174         
       
  1175         aNeedRefresh = ETrue;
       
  1176         return EKeyWasConsumed;
       
  1177         }
       
  1178     
       
  1179     if ( aSearchField->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
       
  1180         {
       
  1181         result = EKeyWasConsumed;
       
  1182         }
       
  1183     
       
  1184     ((CAknFilteredTextListBoxModel*)aListBox->Model())->Filter()->HandleOfferkeyEventL();
       
  1185 
       
  1186     // remove popup if search criteria is empty and backspace is pressed
       
  1187     if ( aSearchField->IsVisible() && ispopup
       
  1188          && aKeyEvent.iCode == EKeyBackspace && oldlength == 0 )
       
  1189         {
       
  1190         removePopup = ETrue;
       
  1191         TInt olditem = aSearchField->OldItemIndex();
       
  1192         if ( olditem >= 0 )  // when list is empty, olditem is -1
       
  1193             {
       
  1194             aListBox->SetCurrentItemIndex( olditem );
       
  1195             }
       
  1196         }
       
  1197     HandleFindPaneVisibility(aSearchField, ispopup, !removePopup, aNeedRefresh);
       
  1198     return result;
       
  1199     }  
       
  1200 
       
  1201 
       
  1202 EXPORT_C void CAknFilteredTextListBoxModel::CreateFilterL(CEikListBox *aListBox, CAknSearchField *aSearchField)
       
  1203     {
       
  1204     __ASSERT_DEBUG(iFilter==0, Panic(EAknPanicOutOfRange));
       
  1205     iFilter = new(ELeave) CAknListBoxFilterItems(aListBox, aSearchField,this, aListBox->View());
       
  1206     iFilter->ConstructL();
       
  1207     }
       
  1208 EXPORT_C void CAknFilteredTextListBoxModel::RemoveFilter()
       
  1209     {
       
  1210     delete iFilter;
       
  1211     iFilter = NULL;
       
  1212     }
       
  1213 
       
  1214 EXPORT_C CAknListBoxFilterItems *CAknFilteredTextListBoxModel::Filter() const
       
  1215     {
       
  1216     return iFilter;
       
  1217     }
       
  1218 
       
  1219 
       
  1220 EXPORT_C const MDesCArray *CAknFilteredTextListBoxModel::MatchableTextArray() const {return this; }
       
  1221 
       
  1222 EXPORT_C TInt CAknFilteredTextListBoxModel::MdcaCount() const
       
  1223     {
       
  1224     return ItemTextArray()->MdcaCount();
       
  1225     }
       
  1226 
       
  1227 EXPORT_C TPtrC CAknFilteredTextListBoxModel::MdcaPoint(TInt aIndex) const
       
  1228     {
       
  1229     if (iFilter)
       
  1230     return iFilter->DefaultMatchableItemFromItem(ItemTextArray()->MdcaPoint(aIndex));
       
  1231     else
       
  1232     return ItemTextArray()->MdcaPoint(aIndex);                            
       
  1233     }
       
  1234 
       
  1235 EXPORT_C CAknFilteredTextListBoxModel::~CAknFilteredTextListBoxModel()
       
  1236     {
       
  1237     delete iFilter;
       
  1238     }
       
  1239 
       
  1240 EXPORT_C TInt CAknFilteredTextListBoxModel::NumberOfItems() const
       
  1241     {
       
  1242     return iFilter ? iFilter->FilteredNumberOfItems() : CTextListBoxModel::NumberOfItems();
       
  1243     }
       
  1244 
       
  1245 EXPORT_C TPtrC CAknFilteredTextListBoxModel::ItemText(TInt aItemIndex) const
       
  1246     {
       
  1247     return CTextListBoxModel::ItemText(iFilter? iFilter->FilteredItemIndex(aItemIndex) : aItemIndex);
       
  1248     }
       
  1249 
       
  1250 EXPORT_C TAny*  CAknFilteredTextListBoxModel::MListBoxModel_Reserved() 
       
  1251     {
       
  1252     return NULL;
       
  1253     }
       
  1254 
       
  1255 class CFindExtension : public CBase
       
  1256     {
       
  1257 public:
       
  1258     CIdle* iIdle;
       
  1259     CFindUtil* iFindUtil;
       
  1260     HBufC16* iNextChars; // for adaptive search    
       
  1261     HBufC* iDigraphChars;  
       
  1262     TKeyEvent iKeyEvent;
       
  1263 
       
  1264     };
       
  1265 
       
  1266 EXPORT_C void CAknListBoxFilterItems::DeferredSendKeyEventToFepL(TUint aValue)
       
  1267     {
       
  1268     __ASSERT_DEBUG(iKeyValue == 0, Panic(EAknPanicOutOfRange));
       
  1269     if (iExtension)
       
  1270         {
       
  1271         iExtension->iKeyEvent.iCode = aValue;
       
  1272         iExtension->iKeyEvent.iScanCode = aValue;
       
  1273         if ( iExtension->iIdle )
       
  1274             {
       
  1275             delete iExtension->iIdle;
       
  1276             iExtension->iIdle = 0;
       
  1277             }
       
  1278         iExtension->iIdle = CIdle::New(-20);
       
  1279         if (iExtension->iIdle)
       
  1280             {
       
  1281             iExtension->iIdle->Start(TCallBack(IdleCallBack, this));
       
  1282             }
       
  1283         }
       
  1284     }
       
  1285 
       
  1286 void CAknListBoxFilterItems::DeferredSendFullKeyEventToFepL( 
       
  1287     const TKeyEvent& aEvent )
       
  1288     {
       
  1289     if ( iExtension )
       
  1290         {
       
  1291         iExtension->iKeyEvent = aEvent;
       
  1292         if ( iExtension->iIdle )
       
  1293             {
       
  1294             delete iExtension->iIdle;
       
  1295             iExtension->iIdle = 0;
       
  1296             }
       
  1297         iExtension->iIdle = CIdle::New(-20);
       
  1298         if ( iExtension->iIdle )
       
  1299             {
       
  1300             iExtension->iIdle->Start( TCallBack( IdleCallBack, this));
       
  1301             }
       
  1302         }
       
  1303     }
       
  1304 
       
  1305 TInt CAknListBoxFilterItems::IdleCallBack(TAny *aFilterItems)
       
  1306     {
       
  1307     TInt err = KErrNone;
       
  1308     CAknListBoxFilterItems *items = 
       
  1309         static_cast<CAknListBoxFilterItems*>(aFilterItems);
       
  1310     if ( items->iExtension )
       
  1311         {
       
  1312         TKeyEvent& event(items->iExtension->iKeyEvent);
       
  1313         CCoeEnv *coeEnv = CCoeEnv::Static();
       
  1314         // THE PART THAT COMMUNICATES WITH FEP.
       
  1315         TRAP_IGNORE(
       
  1316             {
       
  1317             coeEnv->SimulateKeyEventL(event,EEventKeyDown);
       
  1318             coeEnv->SimulateKeyEventL(event,EEventKey);
       
  1319             coeEnv->SimulateKeyEventL(event,EEventKeyUp);
       
  1320             }
       
  1321             );
       
  1322         delete items->iExtension->iIdle;
       
  1323         items->iExtension->iIdle = 0;
       
  1324         }
       
  1325     else
       
  1326         {
       
  1327         err = KErrArgument;
       
  1328         }
       
  1329     return err;
       
  1330     }
       
  1331 
       
  1332 EXPORT_C CAknListBoxFilterItems::CAknListBoxFilterItems(CEikListBox *aListBox, CAknSearchField *aSearchField, MListBoxModel *aModel, CListBoxView *aView) 
       
  1333     : iModel(aModel), iView(aView), iListBox(aListBox), iSearchField(aSearchField)
       
  1334     {
       
  1335     }
       
  1336 
       
  1337 EXPORT_C void CAknListBoxFilterItems::SetParentControl(CCoeControl *aControl)
       
  1338     {
       
  1339     iParentControl = aControl;
       
  1340     }
       
  1341 
       
  1342 EXPORT_C void CAknListBoxFilterItems::SetPopup()
       
  1343     {
       
  1344     iIsPopup = ETrue;
       
  1345     }
       
  1346 
       
  1347 EXPORT_C void CAknListBoxFilterItems::SetListBox(CEikListBox *aListBox)
       
  1348     {
       
  1349     iListBox = aListBox;
       
  1350     }
       
  1351 
       
  1352 EXPORT_C void CAknListBoxFilterItems::SetSearchField(CAknSearchField *aSearchField)
       
  1353     {
       
  1354     iSearchField = aSearchField;
       
  1355     if (iSearchField)
       
  1356         iSearchField->SetObserver(this);
       
  1357     }
       
  1358 
       
  1359 EXPORT_C void CAknListBoxFilterItems::SetModel(MListBoxModel *aModel)
       
  1360     {
       
  1361     iModel = aModel;
       
  1362     }
       
  1363 
       
  1364 EXPORT_C void CAknListBoxFilterItems::SetView(CListBoxView *aView)
       
  1365     {
       
  1366     iView = aView;
       
  1367     }
       
  1368 
       
  1369 EXPORT_C CCoeControl *CAknListBoxFilterItems::FindBox() const
       
  1370     {
       
  1371     return iSearchField;
       
  1372     }
       
  1373 
       
  1374 EXPORT_C void CAknListBoxFilterItems::ConstructL()
       
  1375     {
       
  1376     __ASSERT_DEBUG(iShownIndexes==0, Panic(EAknPanicOutOfRange));
       
  1377     iShownIndexes = new(ELeave) CArrayFixFlat<TInt>(5);
       
  1378     iSelectionIndexes = new(ELeave) CArrayFixFlat<TInt>(5);
       
  1379     iOldSearchCriteria = _L("").AllocL();    
       
  1380     iExtension = new(ELeave)CFindExtension;
       
  1381     
       
  1382     // Returns NULL if findutil not supported
       
  1383     iExtension->iFindUtil = CFindUtil::NewL();    
       
  1384     
       
  1385     iExtension->iNextChars = HBufC16::NewL( 10 );    
       
  1386     iExtension->iDigraphChars = StringLoader::LoadL( R_QTN_ADS_DIGRAPH );; 
       
  1387         
       
  1388     NoCriteriaL();
       
  1389     HandleItemAdditionL();  
       
  1390     if (iSearchField)
       
  1391         iSearchField->SetObserver(this);
       
  1392 
       
  1393     const MDesCArray *array = iModel->MatchableTextArray();
       
  1394     iOldItemCount = array->MdcaCount();   
       
  1395     }
       
  1396 
       
  1397 EXPORT_C CAknListBoxFilterItems::~CAknListBoxFilterItems()
       
  1398     {
       
  1399     if (iExtension)
       
  1400         {
       
  1401         delete iExtension->iIdle;
       
  1402         delete iExtension->iFindUtil;
       
  1403         delete iExtension->iNextChars;
       
  1404         delete iExtension->iDigraphChars;
       
  1405         delete iExtension;        
       
  1406         }
       
  1407     delete iShownIndexes;
       
  1408     delete iSelectionIndexes;
       
  1409     delete iOldSearchCriteria;    
       
  1410     delete iEmptyListText;    
       
  1411     }
       
  1412 
       
  1413 EXPORT_C void CAknListBoxFilterItems::HandleItemArrayChangeL()
       
  1414     {
       
  1415     HBufC16* newcriteria = HBufC16::NewL( KMatchingBufferLength ); 
       
  1416     TPtr ptr_newcriteria( newcriteria->Des() );    
       
  1417     
       
  1418     if ( iSearchField )
       
  1419         {
       
  1420         iSearchField->GetSearchText( ptr_newcriteria );
       
  1421         }
       
  1422 
       
  1423     CleanupStack::PushL( newcriteria );
       
  1424     ReleaseCriteriaL( ptr_newcriteria );
       
  1425 
       
  1426     delete iOldSearchCriteria;
       
  1427     iOldSearchCriteria = NULL;
       
  1428     iOldSearchCriteria = newcriteria->Des().AllocL();
       
  1429 
       
  1430     CleanupStack::PopAndDestroy ( newcriteria );
       
  1431     // We should redraw the listbox
       
  1432     HandleItemAdditionL();  // calls DrawDeferred()
       
  1433 
       
  1434    // If adaptive search manage with next characters
       
  1435     if( iSearchField && IsAdaptiveSearch() )
       
  1436         {
       
  1437         // Handles filtering
       
  1438         
       
  1439         // Clear next characters
       
  1440         ClearNextChars();
       
  1441         TBitFlags32 columnFlag = iSearchField->ListColumnFilterFlags();
       
  1442                 
       
  1443         HBufC16* temptext = HBufC16::NewL( KMatchingBufferLength );    
       
  1444         TPtr ptr_temptext( temptext->Des() );    
       
  1445         CleanupStack::PushL( temptext );
       
  1446         const MDesCArray *array = iModel->MatchableTextArray();
       
  1447         const CAknFilteredTextListBoxModel* arr = (CAknFilteredTextListBoxModel*)(iModel->MatchableTextArray());
       
  1448         
       
  1449         for ( TInt i = iShownIndexes->Count()-1; i>=0; i-- )
       
  1450             {           
       
  1451             TPtrC itemtext = arr->ItemText( i );   
       
  1452             AknFind::UpdateItemTextAccordingToFlag( itemtext, columnFlag, ptr_temptext );
       
  1453 
       
  1454             // this need to be done for update next characters for AdaptiveGrid
       
  1455             // ESMG-7LKAE4, use FindUtil is slow, but it is necessary for Chinese
       
  1456             if ( AknLayoutUtils::Variant() == EApacVariant )
       
  1457                 {
       
  1458                 iExtension->iFindUtil->Interface()->MatchAdaptiveRefineL(
       
  1459                     ptr_temptext, KNullDesC, iExtension->iNextChars);
       
  1460                 }
       
  1461             else
       
  1462                 {
       
  1463                 AknFind::UpdateNextCharsFromString( iExtension->iNextChars, temptext->Des() );
       
  1464                 }
       
  1465             ptr_temptext.Zero(); 
       
  1466             }
       
  1467         iSearchField->SetAdaptiveGridChars( *(iExtension->iNextChars) ); 
       
  1468         CleanupStack::PopAndDestroy ( temptext );
       
  1469         }
       
  1470     iOldItemCount = iModel->MatchableTextArray()->MdcaCount(); 
       
  1471     if ( iOldItemCount>0 && iListBox ) 
       
  1472         {
       
  1473         iListBox->SetCurrentItemIndex(0);  
       
  1474         }       
       
  1475     }  
       
  1476 
       
  1477     
       
  1478 /** 
       
  1479  * Editor sends messages to this object as control events. 
       
  1480  */
       
  1481 EXPORT_C void CAknListBoxFilterItems::HandleControlEventL(CCoeControl *aControl, TCoeEvent aEventType)
       
  1482     {
       
  1483     TBool refresh = EFalse;
       
  1484     switch(aEventType)
       
  1485     {
       
  1486     case EEventStateChanged:
       
  1487         if (iParentControl)
       
  1488             {
       
  1489             HandleOfferkeyEventL();
       
  1490         if (iSearchField)
       
  1491                 {
       
  1492                 AknFind::HandleFindPaneVisibility(iSearchField, iIsPopup, ETrue, refresh);
       
  1493                 }
       
  1494             if (refresh)
       
  1495                 {
       
  1496                 if (iListBox)
       
  1497                     {
       
  1498                     if (iIsPopup)
       
  1499                         {
       
  1500                         AknFind::HandlePopupFindSizeChanged(iParentControl, iListBox, iSearchField);
       
  1501                         }
       
  1502                     else
       
  1503                         {
       
  1504                         AknFind::HandleFixedFindSizeChanged(iParentControl, (CAknColumnListBox*)iListBox, iSearchField);
       
  1505                         }
       
  1506                     }
       
  1507                     iParentControl -> DrawDeferred();
       
  1508                 }
       
  1509             }
       
  1510         break;
       
  1511     default:
       
  1512         break;
       
  1513     }
       
  1514     if (iObserver) iObserver->HandleControlEventL(aControl, aEventType);
       
  1515     }
       
  1516 
       
  1517 void CAknListBoxFilterItems::HandleItemAdditionL()
       
  1518     {
       
  1519     iDisableChangesToShownIndexes = ETrue;
       
  1520     if (iListBox) 
       
  1521         {
       
  1522         TRAP_IGNORE(iListBox->HandleItemAdditionL());
       
  1523         }
       
  1524     iDisableChangesToShownIndexes = EFalse;
       
  1525     }
       
  1526 
       
  1527 void CAknListBoxFilterItems::HandleItemRemovalL()
       
  1528     {
       
  1529     iDisableChangesToShownIndexes = ETrue;
       
  1530     if (iListBox) 
       
  1531         {
       
  1532     TRAP_IGNORE(iListBox->HandleItemRemovalL());
       
  1533     }
       
  1534     iDisableChangesToShownIndexes = EFalse;
       
  1535     }
       
  1536 
       
  1537 EXPORT_C void CAknListBoxFilterItems::SetObserver(MCoeControlObserver *aObserver)
       
  1538     {
       
  1539     iObserver = aObserver;
       
  1540     }
       
  1541 
       
  1542 EXPORT_C void CAknListBoxFilterItems::HandleOfferkeyEventL()
       
  1543     {
       
  1544     if (!iOldSearchCriteria)
       
  1545         {
       
  1546         // This can happen if we have leaved on one of our AllocL()'s and the application resumes the execution.
       
  1547         // Thus, we'll leave and feel safe later in this method to use iOldSearchCriteria without checking it.
       
  1548         iOldSearchCriteria = _L("").AllocL(); // try to resume to valid state...
       
  1549         User::Leave(KErrNoMemory);
       
  1550         }
       
  1551     //
       
  1552     // NOTE! Order of calls to iListBox is important in this method.
       
  1553     // The SetCurrentItemIndex(0) call MUST be before HandleItemAdditionL()
       
  1554     // and handleitemremovalL() calls.
       
  1555     //
       
  1556     // Check if search string has changed.
       
  1557     TBuf<256> newcriteria;
       
  1558     if (iSearchField)
       
  1559         iSearchField->GetSearchText(newcriteria);
       
  1560 
       
  1561     // Check if item count has changed.
       
  1562     const MDesCArray *array = iModel->MatchableTextArray();
       
  1563     if (array->MdcaCount() != iOldItemCount)
       
  1564         {
       
  1565         ReleaseCriteriaL(newcriteria);
       
  1566         if (newcriteria.Compare(*iOldSearchCriteria) != 0 && iShownIndexes->Count()>0) 
       
  1567             { 
       
  1568             if (iListBox)
       
  1569                 iListBox->SetCurrentItemIndex(0);
       
  1570             }
       
  1571         HandleItemAdditionL();
       
  1572         iOldItemCount = array->MdcaCount();
       
  1573         } 
       
  1574     else
       
  1575        {    
       
  1576         if (newcriteria.Compare(*iOldSearchCriteria) == 0) return;
       
  1577         if (iShownIndexes->Count()>0) 
       
  1578             if (iListBox)
       
  1579                 iListBox->SetCurrentItemIndex(0);
       
  1580         
       
  1581         FetchSelectionIndexesFromListBoxL();
       
  1582         if (newcriteria.Length() == 0)
       
  1583             {
       
  1584             NoCriteriaL();
       
  1585             HandleItemAdditionL();
       
  1586             } 
       
  1587         else if ( newcriteria.Length() > (*iOldSearchCriteria).Length() && 
       
  1588                  newcriteria.Find(*iOldSearchCriteria) == 0 )
       
  1589             {
       
  1590             TightenCriteriaL(newcriteria);
       
  1591             HandleItemRemovalL();
       
  1592             }
       
  1593         else
       
  1594             {
       
  1595             ReleaseCriteriaL(newcriteria);
       
  1596             HandleItemAdditionL();
       
  1597             }
       
  1598         PushSelectionIndexesToListBoxL();
       
  1599         }
       
  1600         
       
  1601         delete iOldSearchCriteria;
       
  1602         iOldSearchCriteria = NULL;
       
  1603         iOldSearchCriteria = newcriteria.AllocL();
       
  1604         if (iListBox)   
       
  1605             iListBox->DrawDeferred();
       
  1606     }
       
  1607 
       
  1608 
       
  1609 EXPORT_C TPtrC CAknListBoxFilterItems::DefaultMatchableItemFromItem( TPtrC aText )
       
  1610     {   
       
  1611     // This implementation requirescolumnlistbox or formattedcelllistbox itemdrawer/data..    
       
  1612     iMatchableText = aText.Left(Min(aText.Length(), iMatchableText.MaxLength()-1));
       
  1613     AknTextUtils::ReplaceCharacters(iMatchableText, KAknReplaceListControlChars, TChar(' '));
       
  1614     _LIT(KSpace," ");
       
  1615     AknTextUtils::PackWhiteSpaces(iMatchableText, KSpace);
       
  1616     
       
  1617     if ( iMatchableText.Length() && iMatchableText[0] == ' ' )
       
  1618         {
       
  1619         // remove one space if its at beginning of the string.
       
  1620         iMatchableText = iMatchableText.Mid(1);
       
  1621         }    
       
  1622     return iMatchableText;
       
  1623     }
       
  1624 
       
  1625 EXPORT_C TInt CAknListBoxFilterItems::FilteredNumberOfItems() const
       
  1626     {
       
  1627     return iShownIndexes->Count();
       
  1628     }
       
  1629 
       
  1630 EXPORT_C TInt CAknListBoxFilterItems::FilteredItemIndex(TInt aVisibleItemIndex) const
       
  1631     {
       
  1632     return iShownIndexes->At(aVisibleItemIndex);
       
  1633     }
       
  1634 
       
  1635 EXPORT_C TInt CAknListBoxFilterItems::VisibleItemIndex(TInt aOriginalIndex) const
       
  1636     {
       
  1637     TKeyArrayFix key(0, ECmpTInt);
       
  1638     TInt pos;
       
  1639     if (!(iShownIndexes->Find(aOriginalIndex, key,pos)))
       
  1640     return pos; // found
       
  1641     else
       
  1642     return -1; // not found    
       
  1643     }
       
  1644 
       
  1645 EXPORT_C CArrayFix<TInt> *CAknListBoxFilterItems::SelectionIndexes()
       
  1646     {
       
  1647     return iSelectionIndexes;
       
  1648     }
       
  1649 
       
  1650 EXPORT_C void CAknListBoxFilterItems::UpdateSelectionIndexesL()
       
  1651     {
       
  1652     FetchSelectionIndexesFromListBoxL();
       
  1653     }
       
  1654 
       
  1655 EXPORT_C void CAknListBoxFilterItems::UpdateSelectionIndexL(TInt aVisibleIndex)
       
  1656     {
       
  1657     if (!iView) return;
       
  1658     TInt realindex = FilteredItemIndex(aVisibleIndex);
       
  1659     if (!iView->ItemIsSelected(aVisibleIndex))
       
  1660         { 
       
  1661         // Not selected - remove the item from selection indexes if it still exists there.
       
  1662         TKeyArrayFix key(0, ECmpTInt);
       
  1663         TInt pos;
       
  1664         if (!(iSelectionIndexes->Find(realindex, key,pos)))
       
  1665             {
       
  1666             iSelectionIndexes->Delete(pos);
       
  1667             }
       
  1668         }
       
  1669     else
       
  1670         { // Selected -- add the item to seletion indexes if it didnt exists there yet
       
  1671         TKeyArrayFix key(0,ECmpTInt);
       
  1672         TInt pos;
       
  1673         if (iSelectionIndexes->Find(realindex, key, pos))
       
  1674             {
       
  1675             iSelectionIndexes->AppendL(realindex);
       
  1676             }
       
  1677         }
       
  1678     }
       
  1679 
       
  1680 EXPORT_C TInt CAknListBoxFilterItems::NonFilteredNumberOfItems() const
       
  1681     {
       
  1682     if (iModel->MatchableTextArray())
       
  1683         return iModel->MatchableTextArray()->MdcaCount();
       
  1684     else 
       
  1685         return iModel->NumberOfItems();
       
  1686     }
       
  1687 
       
  1688 void CAknListBoxFilterItems::InstallEmptyTextL()
       
  1689     {
       
  1690     if (iEmptyListText) return; // Do not install, if we have one already
       
  1691     if (!iListBox ||!iListBox->View()) return; // Do not install, if we do not have listbox yet.
       
  1692  
       
  1693     iEmptyListText = iListBox->View()->EmptyListText()->AllocL();
       
  1694     TResourceReader rr;
       
  1695     CEikonEnv::Static()->CreateResourceReaderLC(rr, R_AVKON_FIND_NO_MATCHES);
       
  1696     TPtrC ptr = rr.ReadTPtrC();
       
  1697     if (iListBox && iListBox->View())
       
  1698         iListBox->View()->SetListEmptyTextL(ptr);
       
  1699     CleanupStack::PopAndDestroy(); // resourcereader rr
       
  1700     }
       
  1701 
       
  1702 void CAknListBoxFilterItems::UninstallEmptyTextL()
       
  1703     {
       
  1704     if (!iEmptyListText) return;
       
  1705     if (!iListBox || !iListBox->View()) return;
       
  1706     iListBox->View()->SetListEmptyTextL(iEmptyListText->Des());
       
  1707     delete iEmptyListText;
       
  1708     iEmptyListText = 0;
       
  1709     }
       
  1710 
       
  1711 void CAknListBoxFilterItems::FetchSelectionIndexesFromListBoxL()
       
  1712     {
       
  1713     // go through all visible items, and update 
       
  1714     //the iSelectionIndexes (of this class, not listbox) to match
       
  1715     // with all visible item selection states!
       
  1716     TInt count = FilteredNumberOfItems();
       
  1717     for(TInt i=0; i<count; i++)
       
  1718         {
       
  1719         UpdateSelectionIndexL(i);
       
  1720         }
       
  1721     }
       
  1722 
       
  1723 void CAknListBoxFilterItems::PushSelectionIndexesToListBoxL()
       
  1724     {
       
  1725     if (!iView) return;
       
  1726     // Builds a new selection indexes table for list based on 
       
  1727     // new iShownIndexes and iSelectionIndexes
       
  1728     // Go through all visible items and determine if they've been selected
       
  1729     TInt count = FilteredNumberOfItems();
       
  1730     for( TInt i=0; i<count; i++ )
       
  1731         {
       
  1732         TInt realindex = FilteredItemIndex(i);
       
  1733         TKeyArrayFix key(0,ECmpTInt);
       
  1734         TInt pos;
       
  1735         if ( iSelectionIndexes->Find(realindex,key,pos) )
       
  1736             iView->DeselectItem(i);
       
  1737         else
       
  1738             iView->SelectItemL(i);
       
  1739         }  
       
  1740     }
       
  1741 
       
  1742 EXPORT_C void CAknListBoxFilterItems::ResetFilteringL()
       
  1743     {
       
  1744     if (iDisableChangesToShownIndexes) return;
       
  1745     
       
  1746     // needs to be done or selections go broken.
       
  1747     FetchSelectionIndexesFromListBoxL(); 
       
  1748 
       
  1749     delete iOldSearchCriteria;
       
  1750     iOldSearchCriteria = NULL;
       
  1751     iOldSearchCriteria = _L("").AllocL();
       
  1752 
       
  1753     NoCriteriaL();
       
  1754     // needs to be done or scrollbar crashes
       
  1755     HandleItemAdditionL(); 
       
  1756     PushSelectionIndexesToListBoxL();
       
  1757     }
       
  1758 
       
  1759 EXPORT_C void CAknListBoxFilterItems::UpdateCachedDataL()
       
  1760     {
       
  1761     TBuf<256> newcriteria;
       
  1762     if (iSearchField)
       
  1763         iSearchField->GetSearchText(newcriteria);
       
  1764 
       
  1765     delete iOldSearchCriteria;
       
  1766     iOldSearchCriteria = NULL;
       
  1767     iOldSearchCriteria = newcriteria.AllocL();
       
  1768 
       
  1769     FetchSelectionIndexesFromListBoxL();
       
  1770     }
       
  1771 
       
  1772 
       
  1773 void CAknListBoxFilterItems::NoCriteriaL(TBool aUpdateAS)
       
  1774     {
       
  1775     if (iDisableChangesToShownIndexes) return;
       
  1776     // Handles filtering
       
  1777     TInt count =0; 
       
  1778     if (iModel->MatchableTextArray()) 
       
  1779         count = iModel->MatchableTextArray()->MdcaCount();
       
  1780     else
       
  1781         count = iModel->NumberOfItems();
       
  1782 
       
  1783     iShownIndexes->Reset();
       
  1784         
       
  1785     const MDesCArray *array = iModel->MatchableTextArray();
       
  1786     const CAknFilteredTextListBoxModel* arr = (CAknFilteredTextListBoxModel*)(iModel->MatchableTextArray());
       
  1787     
       
  1788     // If adaptive search manage with next characters
       
  1789     if( iSearchField && IsAdaptiveSearch() )
       
  1790         {
       
  1791         ClearNextChars();
       
  1792         TBitFlags32 columnFlag = iSearchField->ListColumnFilterFlags();
       
  1793         HBufC* temptext = HBufC::NewL( KMatchingBufferLength ); 
       
  1794         CleanupStack::PushL( temptext );
       
  1795         TPtr ptr_temptext( temptext->Des() );  
       
  1796 
       
  1797         for( TInt i = 0; i < count; i++ )
       
  1798             {           
       
  1799             TPtrC itemtext = arr->ItemTextArray()->MdcaPoint(i);
       
  1800             AknFind::UpdateItemTextAccordingToFlag( itemtext, columnFlag, ptr_temptext );
       
  1801  
       
  1802             // this need to be done for update iNextChars for AdaptiveGrid
       
  1803             // ESMG-7LKAE4, use FindUtil is slow, but it is necessary for Chinese
       
  1804             if ( AknLayoutUtils::Variant() == EApacVariant )
       
  1805                 {
       
  1806                 iExtension->iFindUtil->Interface()->MatchAdaptiveRefineL(
       
  1807                     ptr_temptext, KNullDesC, iExtension->iNextChars);
       
  1808                 }
       
  1809             else
       
  1810                 {
       
  1811                 AknFind::UpdateNextCharsFromString( iExtension->iNextChars, temptext->Des() );
       
  1812                 }
       
  1813             iShownIndexes->AppendL( i );
       
  1814             ptr_temptext.Zero(); 
       
  1815             }
       
  1816         if( aUpdateAS )
       
  1817             {
       
  1818             TPtr nextChars = iExtension->iNextChars->Des(); 
       
  1819             CDesCArray* array = new (ELeave) CDesCArrayFlat(10);
       
  1820             CleanupStack::PushL(array);
       
  1821             
       
  1822             TInt length = nextChars.Length();                 
       
  1823             TInt count(0);      
       
  1824               
       
  1825             for( TInt i = 0; i < length; i++ )
       
  1826                 {
       
  1827                 if ( (i < length-2) && IsIndicHalantChar( nextChars[i+1] ) )
       
  1828                    {
       
  1829                    array->AppendL( nextChars.Mid(i,3) );
       
  1830                    i+=2;
       
  1831                    ++count;
       
  1832                    }
       
  1833                else
       
  1834                    {
       
  1835                    array->AppendL( nextChars.Mid(i,1) );
       
  1836                    ++count;
       
  1837                    }
       
  1838                 }  
       
  1839             
       
  1840             // Alphabetical sort        
       
  1841             array->Sort( ECmpCollated );
       
  1842             nextChars.Delete( 0, nextChars.Length() );
       
  1843 
       
  1844             for( TInt i = 0; i < count; i++ )
       
  1845                 {
       
  1846                 nextChars.Append(array->MdcaPoint(i));
       
  1847                 }  
       
  1848             CleanupStack::PopAndDestroy(array);   
       
  1849             
       
  1850             iSearchField->SetAdaptiveGridChars( *(iExtension->iNextChars) );
       
  1851             }
       
  1852         CleanupStack::PopAndDestroy( temptext );   
       
  1853         }
       
  1854     else
       
  1855         {
       
  1856         for( TInt i = 0; i < count; i++ )
       
  1857             {
       
  1858             iShownIndexes->AppendL( i );
       
  1859             }           
       
  1860         }   
       
  1861 
       
  1862     // empty text
       
  1863     UninstallEmptyTextL();
       
  1864     }
       
  1865 
       
  1866 void CAknListBoxFilterItems::TightenCriteriaL(const TDesC &aCriteria)
       
  1867     {
       
  1868     if (iDisableChangesToShownIndexes) 
       
  1869         {
       
  1870         return;
       
  1871         }
       
  1872     // This loop goes backwards to avoid changing the indexes in the shownindexes list before we need them
       
  1873     const MDesCArray *array = iModel->MatchableTextArray();    
       
  1874     const CAknFilteredTextListBoxModel* arr = (CAknFilteredTextListBoxModel*)(iModel->MatchableTextArray());    
       
  1875     
       
  1876     // If adaptive search manage with next characters
       
  1877     if ( iExtension->iDigraphChars->Length() != 0 )
       
  1878         {
       
  1879         NoCriteriaL( EFalse );
       
  1880         }
       
  1881     
       
  1882     // an index to end of array
       
  1883     TInt indexEnd = iShownIndexes->Count();
       
  1884     // If adaptive search manage with next characters
       
  1885     if( iSearchField && IsAdaptiveSearch() )
       
  1886         {        
       
  1887         ClearNextChars();
       
  1888         TBitFlags32 columnFlag = iSearchField->ListColumnFilterFlags(); 
       
  1889         HBufC16* temptext = HBufC16::NewL( KMatchingBufferLength );  
       
  1890         CleanupStack::PushL( temptext );  
       
  1891         TPtr ptr_temptext( temptext->Des() );  
       
  1892         for ( TInt i = iShownIndexes->Count()-1; i>=0; i-- )
       
  1893            {
       
  1894            TInt realindex = iShownIndexes->At( i );        
       
  1895            TPtrC itemtext = arr->ItemTextArray()->MdcaPoint(realindex);
       
  1896            AknFind::UpdateItemTextAccordingToFlag( itemtext, columnFlag, ptr_temptext );
       
  1897            TBool isItemVisible = IsItemVisible(ptr_temptext, aCriteria);
       
  1898            TBool isItemSelected = IsItemSelected(realindex);
       
  1899            // set it as current index when found item
       
  1900            if ( isItemVisible )
       
  1901                {        
       
  1902                indexEnd = iShownIndexes->Count() - i;
       
  1903                }
       
  1904            else if ( !(isItemVisible || isItemSelected) )
       
  1905                 {
       
  1906                 iShownIndexes->Delete(i);
       
  1907                 }
       
  1908             ptr_temptext.Zero();    
       
  1909             }           
       
  1910    
       
  1911         TPtr nextChars = iExtension->iNextChars->Des(); 
       
  1912         CDesCArray* array = new (ELeave) CDesCArrayFlat(10);
       
  1913         CleanupStack::PushL(array);
       
  1914         
       
  1915         TInt length = nextChars.Length();                 
       
  1916         TInt count(0);      
       
  1917           
       
  1918         for( TInt i = 0; i < length; i++ )
       
  1919             {
       
  1920             if ( (i < length-2) && IsIndicHalantChar( nextChars[i+1] ) )
       
  1921                {
       
  1922                array->AppendL( nextChars.Mid(i,3) );
       
  1923                i+=2;
       
  1924                ++count;
       
  1925                }
       
  1926            else
       
  1927                {
       
  1928                array->AppendL( nextChars.Mid(i,1) );
       
  1929                ++count;
       
  1930                }
       
  1931             }  
       
  1932         
       
  1933         // Alphabetical sort        
       
  1934         array->Sort( ECmpCollated );
       
  1935         nextChars.Delete( 0, nextChars.Length() );
       
  1936 
       
  1937         for( TInt i = 0; i < count; i++ )
       
  1938             {
       
  1939             nextChars.Append(array->MdcaPoint(i));
       
  1940             }  
       
  1941         CleanupStack::PopAndDestroy(array);   
       
  1942 
       
  1943         iSearchField->SetAdaptiveGridChars( *(iExtension->iNextChars) ); 
       
  1944         CleanupStack::PopAndDestroy( temptext );
       
  1945         }
       
  1946     else
       
  1947         {
       
  1948         for (TInt i = iShownIndexes->Count()-1; i>=0 ; i--)
       
  1949             {
       
  1950             TInt realindex = iShownIndexes->At(i);
       
  1951             TPtrC itemtext = array->MdcaPoint(realindex);
       
  1952             TBool isItemVisible = IsItemVisible(itemtext, aCriteria);
       
  1953             TBool isItemSelected = IsItemSelected(realindex);
       
  1954             // EAJA-7SK9UC set indexToSet as current index when found item
       
  1955             if ( isItemVisible )
       
  1956                 {           
       
  1957                 indexEnd = iShownIndexes->Count() - i;
       
  1958                 }
       
  1959             else if ( !(isItemVisible || isItemSelected) )
       
  1960                 {
       
  1961                 iShownIndexes->Delete(i);
       
  1962                 }
       
  1963             }  
       
  1964         }   
       
  1965     InstallEmptyTextL();
       
  1966 
       
  1967     // Set highlight to the first match item in markable list
       
  1968     if (iListBox)
       
  1969         {
       
  1970         iListBox->SetCurrentItemIndex( Max( iShownIndexes->Count() - indexEnd, 0 ));    
       
  1971         }
       
  1972     }
       
  1973 
       
  1974 void CAknListBoxFilterItems::ReleaseCriteriaL( const TDesC &aCriteria )
       
  1975     {
       
  1976     if ( iDisableChangesToShownIndexes )
       
  1977         {
       
  1978         return;
       
  1979         }    
       
  1980     
       
  1981     // An index to set highlight after find pane updating
       
  1982     TInt indexToSet = KInvalidIndex;    
       
  1983     iShownIndexes->Reset();
       
  1984     // If adaptive search field 
       
  1985     if( iSearchField && IsAdaptiveSearch() )
       
  1986         {        
       
  1987         ClearNextChars();
       
  1988         TBitFlags32 columnFlag = iSearchField->ListColumnFilterFlags();
       
  1989         HBufC16* temptext = HBufC16::NewL( KMatchingBufferLength ); 
       
  1990         CleanupStack::PushL( temptext );
       
  1991         TPtr ptr_temptext( temptext->Des() );       
       
  1992         const MDesCArray *array = iModel->MatchableTextArray();
       
  1993         const CAknFilteredTextListBoxModel* arr = (CAknFilteredTextListBoxModel*)(iModel->MatchableTextArray());
       
  1994         TInt count = array->MdcaCount();
       
  1995         
       
  1996         for (TInt i = 0; i < count; i++)
       
  1997            {            
       
  1998             TPtrC itemtext = arr->ItemTextArray()->MdcaPoint(i);    
       
  1999             AknFind::UpdateItemTextAccordingToFlag( itemtext, columnFlag, ptr_temptext );
       
  2000             TBool isItemVisible = IsItemVisible(temptext->Des(), aCriteria);
       
  2001             // Find first match item to set highlight
       
  2002             if ( (indexToSet == KInvalidIndex) && isItemVisible )
       
  2003                 {
       
  2004                 indexToSet = iShownIndexes->Count();
       
  2005                 }
       
  2006             if ( isItemVisible || IsItemSelected(i))
       
  2007                 {
       
  2008                 iShownIndexes->AppendL(i);
       
  2009                 }
       
  2010             ptr_temptext.Zero();    
       
  2011            }                
       
  2012         iSearchField->SetAdaptiveGridChars( *(iExtension->iNextChars) ); 
       
  2013         InstallEmptyTextL(); 
       
  2014         CleanupStack::PopAndDestroy( temptext );
       
  2015         }
       
  2016     else
       
  2017         {
       
  2018         const MDesCArray *array = iModel->MatchableTextArray();
       
  2019         TInt count = array->MdcaCount();
       
  2020         TInt i;
       
  2021 
       
  2022         if ( aCriteria.Length() == 0)
       
  2023             {
       
  2024             /* If there is no search criteria - most commonly when list is
       
  2025             *  created - there is no point to test each item separately,
       
  2026             *  just append them all. This results to a HUGE performance
       
  2027             *  gain in large lists.
       
  2028             */
       
  2029             for( i = 0; i < count ; i++ )
       
  2030                 {
       
  2031                 iShownIndexes->AppendL(i);
       
  2032                 }
       
  2033             UninstallEmptyTextL();
       
  2034             }
       
  2035         else
       
  2036             {
       
  2037             for( i = 0; i < count ; i++ )
       
  2038                 {
       
  2039                 TPtrC itemtext = array->MdcaPoint(i);
       
  2040                 TBool isItemVisible = IsItemVisible(itemtext, aCriteria);
       
  2041                 
       
  2042                 // Find first match item to set highlight
       
  2043                 if ((indexToSet == KInvalidIndex) && isItemVisible)
       
  2044                     {
       
  2045                     indexToSet = iShownIndexes->Count();
       
  2046                     }
       
  2047                 if ( isItemVisible || IsItemSelected(i))
       
  2048                     {
       
  2049                     iShownIndexes->AppendL(i);
       
  2050                     }
       
  2051                 } 
       
  2052             InstallEmptyTextL();
       
  2053             }
       
  2054         }
       
  2055     
       
  2056     // Set highlight to the first match item in markable list
       
  2057     if ( iListBox && indexToSet != KInvalidIndex )
       
  2058         {
       
  2059         iListBox->SetCurrentItemIndex( Max(indexToSet, 0) );    
       
  2060         }
       
  2061     }
       
  2062 
       
  2063 void CAknListBoxFilterItems::ClearNextChars()
       
  2064     {
       
  2065     if( iExtension->iNextChars )
       
  2066         {
       
  2067         TPtr ptr = iExtension->iNextChars->Des();
       
  2068         ptr.Delete( 0, ptr.Length() );
       
  2069         ptr.Zero();
       
  2070         }
       
  2071     }
       
  2072 
       
  2073 TBool CAknListBoxFilterItems::IsAdaptiveSearch() const
       
  2074     {   
       
  2075     if ( iSearchField->SearchFieldStyle() == CAknSearchField::EAdaptiveSearch || 
       
  2076          iSearchField->SearchFieldStyle() == CAknSearchField::EAdaptive ||
       
  2077          iSearchField->SearchFieldStyle() == CAknSearchField::EPopupAdaptiveSearch ||
       
  2078          iSearchField->SearchFieldStyle() == CAknSearchField::EPopupAdaptiveSearchWindow )
       
  2079         return ETrue;
       
  2080     else
       
  2081         return EFalse;
       
  2082     }
       
  2083 
       
  2084 TBool CAknListBoxFilterItems::IsItemSelected(TInt aRealIndex) const
       
  2085     {
       
  2086     TKeyArrayFix key(0, ECmpTInt);
       
  2087     TInt pos;
       
  2088     if (iSelectionIndexes->Find(aRealIndex, key, pos))
       
  2089         return EFalse;
       
  2090     else
       
  2091         return ETrue;
       
  2092     }
       
  2093 
       
  2094 TBool CAknListBoxFilterItems::IsItemVisible(const TDesC &aItemString, const TDesC &aSearchText)
       
  2095     {
       
  2096     TBool val = ETrue;
       
  2097     // If findutil supported
       
  2098     if ( iExtension->iFindUtil )
       
  2099          {
       
  2100          if( iSearchField && IsAdaptiveSearch() )
       
  2101             {
       
  2102             TRAP_IGNORE(             
       
  2103                val = iExtension->iFindUtil->Interface()->MatchAdaptiveRefineL(aItemString, aSearchText, iExtension->iNextChars));
       
  2104             }
       
  2105          else
       
  2106             {
       
  2107             TRAP_IGNORE( 
       
  2108                 val = iExtension->iFindUtil->Interface()->MatchRefineL(aItemString, aSearchText));
       
  2109             }           
       
  2110         }
       
  2111     else
       
  2112         {
       
  2113         if( iSearchField && IsAdaptiveSearch() )
       
  2114             {
       
  2115             val = AknFind::IsAdaptiveFindMatch( aItemString, aSearchText, iExtension->iNextChars );
       
  2116             }
       
  2117         else
       
  2118             {
       
  2119             val = AknFind::IsFindMatch( aItemString, aSearchText );
       
  2120             }          
       
  2121         }
       
  2122     return val;
       
  2123     }
       
  2124 
       
  2125 TBool CAknListBoxFilterItems::IsSeparatorCharacter(TChar c)
       
  2126     {
       
  2127     return AknFind::IsFindWordSeparator(c);
       
  2128     }
       
  2129 
       
  2130 
       
  2131 EXPORT_C void AknSelectionService::HandleSelectionListProcessCommandL(TInt /*aCommand*/, 
       
  2132                               CEikListBox* /*aListBox*/) 
       
  2133     { }
       
  2134 
       
  2135 EXPORT_C void AknSelectionService::HandleMultiselectionListProcessCommandL(TInt aCommand, 
       
  2136                                CEikListBox* aListBox) 
       
  2137 {
       
  2138   switch(aCommand)
       
  2139       {
       
  2140   case EAknSoftkeyOk:
       
  2141       if (aListBox->SelectionIndexes()->Count()==0 && aListBox->View()->CurrentItemIndex()>=0)
       
  2142       {
       
  2143       aListBox->View()->SelectItemL(aListBox->View()->CurrentItemIndex());
       
  2144       }
       
  2145       }
       
  2146 }
       
  2147 
       
  2148 EXPORT_C void AknSelectionService::HandleMarkableListProcessCommandL(TInt aCommand, 
       
  2149                         CEikListBox* aListBox) 
       
  2150     {
       
  2151     switch(aCommand) 
       
  2152     {
       
  2153     
       
  2154     case EAknCmdMark:
       
  2155         aListBox->View()->SelectItemL(aListBox->View()->CurrentItemIndex());
       
  2156         aListBox->View()->DrawItem(aListBox->View()->CurrentItemIndex());
       
  2157         break;
       
  2158     case EAknCmdUnmark:
       
  2159         aListBox->View()->DeselectItem(aListBox->View()->CurrentItemIndex());
       
  2160         aListBox->View()->DrawItem(aListBox->View()->CurrentItemIndex());
       
  2161         break;
       
  2162     case EAknMarkAll:
       
  2163         {
       
  2164         aListBox->ClearSelection();
       
  2165         TInt num = aListBox->Model()->NumberOfItems();
       
  2166         if (num < 1) return;
       
  2167         TInt ii=0;
       
  2168         CArrayFixFlat<TInt>* array = new(ELeave) CArrayFixFlat<TInt>(20);
       
  2169         CleanupStack::PushL(array);
       
  2170         array->SetReserveL(num);
       
  2171         for(ii=0;ii<num;ii++) 
       
  2172         {
       
  2173         array->AppendL(ii);
       
  2174         }
       
  2175         aListBox->SetSelectionIndexesL(array);
       
  2176         CleanupStack::PopAndDestroy(); //array
       
  2177         break;
       
  2178         }
       
  2179     case EAknUnmarkAll:
       
  2180         aListBox->ClearSelection();
       
  2181         break;
       
  2182     };
       
  2183     }
       
  2184 EXPORT_C void AknSelectionService::HandleMarkableListDynInitMenuPane(TInt aResourceId, CEikMenuPane *aMenu, CEikListBox *aListBox)
       
  2185     {
       
  2186     if (aResourceId == R_AVKON_MENUPANE_MARKABLE_LIST_IMPLEMENTATION)
       
  2187     {
       
  2188     TInt currentItemIndex = aListBox->View()->CurrentItemIndex();
       
  2189     TBool markHidden = aListBox->View()->ItemIsSelected(currentItemIndex);
       
  2190     TBool unmarkHidden = !aListBox->View()->ItemIsSelected(currentItemIndex);
       
  2191     TBool markAllHidden = aListBox->Model()->NumberOfItems() == 0 || aListBox->SelectionIndexes()->Count()==aListBox->Model()->NumberOfItems();
       
  2192     TBool unmarkAllHidden = aListBox->Model()->NumberOfItems() == 0 || aListBox->SelectionIndexes()->Count() == 0;
       
  2193 
       
  2194     aMenu->SetItemDimmed(EAknCmdMark, markHidden);
       
  2195     aMenu->SetItemDimmed(EAknCmdUnmark, unmarkHidden);
       
  2196     aMenu->SetItemDimmed(EAknMarkAll, markAllHidden);
       
  2197     aMenu->SetItemDimmed(EAknUnmarkAll, unmarkAllHidden);    
       
  2198     }
       
  2199     if (aResourceId == R_AVKON_MENUPANE_MARKABLE_LIST_EDIT_LIST_IMPLEMENTATION
       
  2200             || aResourceId == R_AVKON_MENUPANE_FIND_POPUP_IMPLEMENTATION_MARKABLE
       
  2201         )
       
  2202     {
       
  2203     TBool editListHidden = aListBox->Model()->NumberOfItems()==0;
       
  2204     
       
  2205     aMenu->SetItemDimmed(EAknCmdEditListMenu, editListHidden);
       
  2206     }
       
  2207 
       
  2208     }
       
  2209 
       
  2210 EXPORT_C void AknSelectionService::HandleMarkableListDynInitMenuItem(CEikMenuPane *aMenu, CEikListBox *aListBox, TInt aCommandId, TBool aCanBeAppliedToMultipleItems)
       
  2211     {
       
  2212     TBool itemhidden = EFalse;
       
  2213     if (!aCanBeAppliedToMultipleItems && aListBox->SelectionIndexes()->Length() > 0)
       
  2214     {
       
  2215     itemhidden = ETrue;
       
  2216     } 
       
  2217     aMenu->SetItemDimmed(aCommandId, itemhidden); 
       
  2218     }
       
  2219 EXPORT_C void AknSelectionService::HandleMarkableListUpdateAfterCommandExecution(CEikListBox *aListBox)
       
  2220     {
       
  2221     aListBox->ClearSelection();
       
  2222     }
       
  2223 
       
  2224 EXPORT_C TKeyResponse AknSelectionService::HandleMenuListOfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType, CEikListBox *aListBox)
       
  2225     {
       
  2226     // Ignore number keys, clear key and shift key
       
  2227     if (AknKeys::IsNumberKey(aKeyEvent,aType)) return EKeyWasConsumed;
       
  2228     switch(aKeyEvent.iCode)
       
  2229         {
       
  2230         case EKeyDelete: 
       
  2231         case EKeyLeftShift:
       
  2232         case EKeyRightShift:
       
  2233             return EKeyWasConsumed;
       
  2234         default:
       
  2235             break;
       
  2236         };
       
  2237    
       
  2238     return aListBox->OfferKeyEventL(aKeyEvent, aType);
       
  2239     }
       
  2240 EXPORT_C void AknSelectionService::HandleItemRemovalAndPositionHighlightL(CEikListBox *aListBox, TInt aValueOfCurrentItemIndexBeforeRemoval, CArrayFix<TInt> &aIndexesToRemovedItemsBeforeRemoval)
       
  2241     {
       
  2242     AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(aListBox, aValueOfCurrentItemIndexBeforeRemoval, aIndexesToRemovedItemsBeforeRemoval);
       
  2243     }
       
  2244 
       
  2245 EXPORT_C void AknSelectionService::HandleItemRemovalAndPositionHighlightL(CEikListBox *aListBox, TInt aValueOfCurrentItemIndexBeforeRemoval, TBool aCurrentItemWasRemoved)
       
  2246     {
       
  2247     AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(aListBox, aValueOfCurrentItemIndexBeforeRemoval, aCurrentItemWasRemoved);
       
  2248     }
       
  2249 
       
  2250 EXPORT_C void AknEditUtils::ConstructEditingL(CEikEdwin *aEdwin, TInt aResourceId)
       
  2251     {
       
  2252     TResourceReader rr;
       
  2253     CEikonEnv::Static()->CreateResourceReaderLC(rr, aResourceId);
       
  2254     ConstructEditingL(aEdwin, rr);
       
  2255     CleanupStack::PopAndDestroy();
       
  2256     }
       
  2257 
       
  2258 EXPORT_C void AknEditUtils::ConstructEditingL(CEikEdwin *aEdwin, const SAknEditorParameters &aParams)
       
  2259     {
       
  2260     ConstructEditingL(aEdwin,
       
  2261               aParams.iEditingSpace,
       
  2262               aParams.iEditingWindow,
       
  2263               aParams.iCharacterCase,
       
  2264               aParams.iJustification,
       
  2265               aParams.iAllowedToMoveInsertionPoint,
       
  2266               aParams.iCursorYesNo,
       
  2267               aParams.iOverflowYesNo);
       
  2268     }
       
  2269 
       
  2270 EXPORT_C void AknEditUtils::ConstructEditingL(CEikEdwin *aEdwin, TResourceReader &aReader)
       
  2271     {
       
  2272     TInt editingSpace = aReader.ReadInt16();
       
  2273     TInt editingWindow = aReader.ReadInt16();
       
  2274     TInt characterCase = aReader.ReadInt16();
       
  2275     TInt justification = aReader.ReadInt16();
       
  2276     TInt allowedToMoveInsertionPoint = aReader.ReadInt16();
       
  2277     TInt cursorYesNo = aReader.ReadInt16();
       
  2278     TInt overflowYesNo = aReader.ReadInt16();
       
  2279     ConstructEditingL(aEdwin, editingSpace, editingWindow, characterCase, justification, allowedToMoveInsertionPoint, cursorYesNo, overflowYesNo);
       
  2280     }
       
  2281 
       
  2282 
       
  2283 EXPORT_C void AknEditUtils::ConstructEditingL(CEikEdwin* aEdwin, 
       
  2284                                               TInt aEditingSpace, 
       
  2285                                               TInt aEditingWindow, 
       
  2286                                               TInt aCharacterCase, 
       
  2287                                               TInt aJustification, 
       
  2288                                               TBool aAllowedToMoveInsertionPoint, 
       
  2289                                               TBool aCursorYesNo, 
       
  2290                                               TBool aOverflowYesNo)
       
  2291     {
       
  2292     ConstructEditingL(aEdwin,aEditingSpace,aEditingWindow,aCharacterCase,aJustification, 
       
  2293                       aAllowedToMoveInsertionPoint, aCursorYesNo, aOverflowYesNo, ETrue);
       
  2294     }
       
  2295 
       
  2296 //
       
  2297 // CAknLayoutUtils
       
  2298 //
       
  2299 EXPORT_C void AknLayoutUtils::LayoutLabel(CEikLabel* aLabel, const TRect &aLabelParent, TInt aResourceId, const CFont *aCustomFont)
       
  2300     {
       
  2301     TResourceReader rr;
       
  2302     TRAPD(error,
       
  2303       {
       
  2304       CEikonEnv::Static()->CreateResourceReaderLC(rr, aResourceId);
       
  2305       LayoutLabel(aLabel, aLabelParent, rr, aCustomFont);
       
  2306       CleanupStack::PopAndDestroy();
       
  2307       });
       
  2308     if (error != KErrNone)
       
  2309     {
       
  2310     aLabel->SetRect(TRect(aLabelParent.iTl, TSize(2,2)));
       
  2311     }
       
  2312 #ifdef AKNUTILS_ENABLE_TRACES
       
  2313     __ASSERT_DEBUG(error == KErrNone, LOGTEXT(_L("AknLayoutUtils:LayoutLabel: Resource reader failed.")));
       
  2314 #endif // AKNUTILS_ENABLE_TRACES
       
  2315     }
       
  2316 
       
  2317 EXPORT_C void AknLayoutUtils::LayoutLabel(CEikLabel* aLabel, const TRect &aLabelParent, const SAknLayoutLabel &aL, const CFont *aCustomFont)
       
  2318     {
       
  2319     LayoutLabel(aLabel,aLabelParent, aL.iFont, aL.iC, aL.iL, aL.iR, aL.iB, aL.iW, aL.iJ, aL.iNextLineB, aCustomFont);
       
  2320     }
       
  2321 
       
  2322 EXPORT_C void AknLayoutUtils::LayoutLabel(CEikLabel* aLabel, const TRect &aLabelParent, const TAknMultiLineTextLayout &aL, const CFont *aCustomFont)
       
  2323     {
       
  2324     // if we are using non-encoded fonts, baseline is top relative
       
  2325     // however for encoded fonts, at this stage baseline is actually bottom 
       
  2326     // however baseline skip is always a positive delta
       
  2327     TInt correctNextBaseline = TAknFontId::IsEncodedFont(aL.FontId()) ? aL.iB - aL.BaselineSkip() : aL.iB + aL.BaselineSkip();
       
  2328     LayoutLabel(aLabel,aLabelParent, aL.FontId(), aL.iC, aL.il, aL.ir, aL.iB, aL.iW, aL.iJ, correctNextBaseline, aCustomFont);
       
  2329     }
       
  2330 
       
  2331 EXPORT_C void AknLayoutUtils::LayoutLabel(CEikLabel* aLabel, const TRect &aLabelParent, const TAknTextLineLayout &aL, const CFont *aCustomFont)
       
  2332     {
       
  2333     LayoutLabel(aLabel,aLabelParent, aL.FontId(), aL.iC, aL.il, aL.ir, aL.iB, aL.iW, aL.iJ, aL.iB, aCustomFont);
       
  2334     }
       
  2335 
       
  2336 EXPORT_C void AknLayoutUtils::LayoutLabel(CEikLabel* aLabel, const TRect &aLabelParent, TResourceReader& aReader, const CFont *aCustomFont)
       
  2337     {
       
  2338     TInt fontid = aReader.ReadInt16();
       
  2339     TInt C = aReader.ReadInt16();
       
  2340     TInt lm = aReader.ReadInt16();
       
  2341     TInt rm = aReader.ReadInt16();
       
  2342     TInt B = aReader.ReadInt16();
       
  2343     TInt W = aReader.ReadInt16();
       
  2344     TInt J = aReader.ReadInt16();
       
  2345     TInt NB = aReader.ReadInt16();
       
  2346     if (NB == 0) NB = B;
       
  2347     LayoutLabel(aLabel, aLabelParent, fontid, C, lm, rm, B, W, J,NB, aCustomFont);
       
  2348     }
       
  2349 
       
  2350 EXPORT_C void AknLayoutUtils::LayoutLabel(CEikLabel* aLabel, const TRect &aLabelParent, TInt fontid, TInt aColor, TInt aLeftMargin, TInt aRightMargin, TInt aBaseline, TInt aWidth, TInt aJustification, TInt aNextLineB, const CFont *aCustomFont)
       
  2351     {
       
  2352     aBaseline = CorrectBaseline(aLabelParent.Height(), aBaseline, fontid);
       
  2353     aNextLineB = CorrectBaseline(aLabelParent.Height(), aNextLineB, fontid);
       
  2354 
       
  2355     TInt lastBaseLine(0);
       
  2356     if(aNextLineB!=0)
       
  2357         lastBaseLine = (aNextLineB - aBaseline) * aLabel->NumberOfLines() - (aNextLineB - aBaseline);
       
  2358 
       
  2359     const CFont *font = FontFromId(fontid, aCustomFont);
       
  2360     TRect rect = AknLayoutUtils::TextRectFromCoords(aLabelParent, font, aLeftMargin, aRightMargin, aBaseline, aWidth, lastBaseLine);    
       
  2361     // Default color is 215 and 99% of cases uses it -- and we want to avoid extra leaving function here.
       
  2362     TRAP_IGNORE(OverrideControlColorL(*aLabel, EColorLabelText, AKN_LAF_COLOR_STATIC(aColor)));
       
  2363     // The semantics of "Gap between lines" is relative to the CFont::HeightInPixels
       
  2364     // That is, the "Gap" is DEFINED to be the difference between the baseline separation and CFont::HeightInPixels
       
  2365     aLabel->SetPixelGapBetweenLines(aNextLineB - aBaseline - font->HeightInPixels());
       
  2366     aLabel->SetLabelAlignment(aJustification);
       
  2367     aLabel->SetFont(font);
       
  2368     aLabel->SetRect(rect);
       
  2369     }
       
  2370 
       
  2371 
       
  2372 EXPORT_C void AknLayoutUtils::LayoutEdwin(CEikEdwin *aEdwin, const TRect &aEdwinParent, TInt aResourceId, TInt aNumberOfLines, const CFont *aCustomFont, TBool aMinimizeEdwinView)
       
  2373     {
       
  2374     TResourceReader rr;
       
  2375     TRAPD(error,
       
  2376         {
       
  2377         CEikonEnv::Static()->CreateResourceReaderLC(rr, aResourceId);
       
  2378         LayoutEdwin(aEdwin, aEdwinParent, rr, aNumberOfLines, aCustomFont,aMinimizeEdwinView);
       
  2379         CleanupStack::PopAndDestroy();
       
  2380         });
       
  2381     if (error != KErrNone)
       
  2382         {
       
  2383         aEdwin->SetRect(TRect(aEdwinParent.iTl, TSize(2,2)));
       
  2384         }
       
  2385 #ifdef AKNUTILS_ENABLE_TRACES
       
  2386     __ASSERT_DEBUG(error == KErrNone, LOGTEXT(_L("AknLayoutUtils:LayoutEdwin: Resource reader failed.")));
       
  2387 #endif // AKNUTILS_ENABLE_TRACES
       
  2388     }
       
  2389 
       
  2390 
       
  2391 EXPORT_C void AknLayoutUtils::LayoutEdwin(CEikEdwin* aEdwin, const TRect &aEdwinParent, const SAknLayoutEdwin &aL, const CFont *aCustomFont, TBool aMinimizeEdwinView)
       
  2392     {
       
  2393     LayoutEdwin(aEdwin,aEdwinParent, aL.iFont, aL.iC, aL.iL, aL.iR, aL.iB, aL.iW, aL.iJ, aL.iNumberOfLinesShown, aL.iNextLineB, aCustomFont,aMinimizeEdwinView);
       
  2394     }
       
  2395 
       
  2396 EXPORT_C void AknLayoutUtils::LayoutEdwin( CEikEdwin* aEdwin,
       
  2397                                            const TRect &aEdwinParent,
       
  2398                                            const TAknMultiLineTextLayout &aL,
       
  2399                                            const CFont *aCustomFont,
       
  2400                                            TBool aMinimizeEdwinView )
       
  2401     {
       
  2402     LayoutEdwin( aEdwin, aEdwinParent, aL, (TAknsQsnTextColorsIndex)KTextColorNone,
       
  2403                  aCustomFont, aMinimizeEdwinView );
       
  2404     }
       
  2405 
       
  2406 
       
  2407 EXPORT_C void AknLayoutUtils::LayoutEdwin( CEikEdwin* aEdwin,
       
  2408                                            const TRect &aEdwinParent,
       
  2409                                            const TAknMultiLineTextLayout &aL,
       
  2410                                            TAknsQsnTextColorsIndex aOverrideColor,
       
  2411                                            const CFont *aCustomFont,
       
  2412                                            TBool aMinimizeEdwinView )
       
  2413     {
       
  2414     TInt B = aL.iB;
       
  2415     TInt secondBaseline = 0;
       
  2416     TInt baselineDelta =  aL.BaselineSkip();
       
  2417 
       
  2418     if (IsParentRelative(B)) 
       
  2419         B = B - ELayoutP + aEdwinParent.Height();
       
  2420     if (baselineDelta != 0) 
       
  2421         secondBaseline = TAknFontId::IsEncodedFont(aL.FontId()) ? B - baselineDelta : B + baselineDelta;
       
  2422 
       
  2423     LayoutEdwin( aEdwin,
       
  2424                  aEdwinParent,
       
  2425                  aL.FontId(),
       
  2426                  aL.iC,
       
  2427                  aL.il,
       
  2428                  aL.ir,
       
  2429                  aL.iB,
       
  2430                  aL.iW,
       
  2431                  aL.iJ,
       
  2432                  aL.NumberOfLinesShown(),
       
  2433                  secondBaseline,
       
  2434                  aOverrideColor,
       
  2435                  aCustomFont,
       
  2436                  aMinimizeEdwinView );
       
  2437 
       
  2438     }
       
  2439 
       
  2440 EXPORT_C void AknLayoutUtils::LayoutEdwin( CEikEdwin* aEdwin,
       
  2441                                            const TRect &aEdwinParent,
       
  2442                                            const TAknTextLineLayout &aL,
       
  2443                                            TAknsQsnTextColorsIndex aOverrideColor,
       
  2444                                            const CFont *aCustomFont,
       
  2445                                            TBool aMinimizeEdwinView )
       
  2446     {
       
  2447     /* 
       
  2448     Handle the different system of defaults in the layout dll and this routine:
       
  2449     In Aknlayout dll, zero baselineSkip() means that there is no 2nd baseline. 
       
  2450     So in that case, 0 should be passed as secondBaseline to the called LayoutEdwin method
       
  2451     */
       
  2452     TInt B = aL.iB;
       
  2453     TInt secondBaseline = 0;
       
  2454     TInt baselineDelta =  aL.BaselineSkip();
       
  2455 
       
  2456     if (IsParentRelative(B)) 
       
  2457         B = B - ELayoutP + aEdwinParent.Height();
       
  2458     if (baselineDelta != 0) 
       
  2459         secondBaseline = TAknFontId::IsEncodedFont(aL.FontId()) ? B - baselineDelta : B + baselineDelta;
       
  2460 
       
  2461     LayoutEdwin( aEdwin, aEdwinParent, aL.FontId(), aL.iC, aL.il, aL.ir, aL.iB,
       
  2462                  aL.iW, aL.iJ, aL.NumberOfLinesShown(), secondBaseline,
       
  2463                  aOverrideColor, aCustomFont, aMinimizeEdwinView );
       
  2464     }
       
  2465 
       
  2466 EXPORT_C void AknLayoutUtils::LayoutEdwin(CEikEdwin* aEdwin, const TRect &aEdwinParent, const TAknTextLineLayout &aL, const CFont *aCustomFont, TBool aMinimizeEdwinView)
       
  2467     {
       
  2468     LayoutEdwin( aEdwin, aEdwinParent, aL, (TAknsQsnTextColorsIndex) KTextColorNone,
       
  2469                  aCustomFont, aMinimizeEdwinView);
       
  2470     }
       
  2471 
       
  2472 EXPORT_C void AknLayoutUtils::LayoutEdwin(CEikEdwin *aEdwin, const TRect &aEdwinParent, TResourceReader &aReader, TInt aNumberOfLines, const CFont *aCustomFont, TBool aMinimizeEdwinView)
       
  2473     {
       
  2474     TInt fontid = aReader.ReadInt16();
       
  2475     TInt C = aReader.ReadInt16();
       
  2476     TInt lm = aReader.ReadInt16();
       
  2477     TInt rm = aReader.ReadInt16();
       
  2478     TInt B = aReader.ReadInt16();
       
  2479     TInt W = aReader.ReadInt16();
       
  2480     TInt J = aReader.ReadInt16();
       
  2481     TInt numberOfLinesShown = aReader.ReadInt16();
       
  2482     if ( aNumberOfLines )
       
  2483         numberOfLinesShown = aNumberOfLines ;
       
  2484     TInt aNextLineBaseline = aReader.ReadInt16();
       
  2485     LayoutEdwin(aEdwin, aEdwinParent, fontid, C, lm, rm, B, W, J, numberOfLinesShown, aNextLineBaseline, aCustomFont,aMinimizeEdwinView);
       
  2486     }
       
  2487 
       
  2488 EXPORT_C void AknLayoutUtils::LayoutEdwin( CEikEdwin *aEdwin,
       
  2489                                            const TRect &aEdwinParent,
       
  2490                                            TInt fontid,
       
  2491                                            TInt aColor,
       
  2492                                            TInt aLeftMargin,
       
  2493                                            TInt aRightMargin,
       
  2494                                            TInt aBaseline,
       
  2495                                            TInt aWidth,
       
  2496                                            TInt aJustification,
       
  2497                                            TInt aNumberOfLinesShown,
       
  2498                                            TInt aSecondLineBaseline,
       
  2499                                            const CFont *aCustomFont,
       
  2500                                            TBool aMinimizeEdwinView )
       
  2501     {
       
  2502     LayoutEdwin( aEdwin,
       
  2503                  aEdwinParent,
       
  2504                  fontid,
       
  2505                  aColor,
       
  2506                  aLeftMargin,
       
  2507                  aRightMargin,
       
  2508                  aBaseline,
       
  2509                  aWidth,
       
  2510                  aJustification,
       
  2511                  aNumberOfLinesShown,
       
  2512                  aSecondLineBaseline,
       
  2513                  (TAknsQsnTextColorsIndex) KTextColorNone,
       
  2514                  aCustomFont,
       
  2515                  aMinimizeEdwinView );
       
  2516      
       
  2517     }
       
  2518 
       
  2519 TBool IsEmpty(TInt aValue)
       
  2520     {
       
  2521     return aValue == ELayoutEmpty;
       
  2522     }
       
  2523 
       
  2524 EXPORT_C void AknLayoutUtils::LayoutEdwin( CEikEdwin *aEdwin,
       
  2525                                            const TRect &aEdwinParent,
       
  2526                                            TInt fontid,
       
  2527                                            TInt aColor,
       
  2528                                            TInt aLeftMargin,
       
  2529                                            TInt aRightMargin,
       
  2530                                            TInt aBaseline,
       
  2531                                            TInt aWidth,
       
  2532                                            TInt aJustification,
       
  2533                                            TInt aNumberOfLinesShown,
       
  2534                                            TInt aSecondLineBaseline,
       
  2535                                            TAknsQsnTextColorsIndex aOverrideColor,
       
  2536                                            const CFont *aCustomFont,
       
  2537                                            TBool aMinimizeEdwinView )
       
  2538     {
       
  2539 // Whether we test on IsEncodedFont is determined by how well the code
       
  2540 // can cope with "lay file" layouts and legacy and logical font ids.
       
  2541 // It is highly desirable that we can manage with only the layoutEdwinScalable implementation
       
  2542 //    if(TAknFontSpecification::IsEncodedFont(aFontId))
       
  2543     if ( aCustomFont )
       
  2544         {
       
  2545         __ASSERT_DEBUG( CAknLayoutFont::AsCAknLayoutFontOrNull( aCustomFont ), Panic( EAknPanicFontProvisionFailure ) ); 
       
  2546         }
       
  2547 
       
  2548     AknLayoutUtilsHelpers::LayoutEdwinScalable( aEdwin, 
       
  2549                         aEdwinParent, 
       
  2550                         fontid, 
       
  2551                         aColor, 
       
  2552                         aLeftMargin, 
       
  2553                         aRightMargin, 
       
  2554                         aBaseline, 
       
  2555                         aWidth, 
       
  2556                         aJustification, 
       
  2557                         aNumberOfLinesShown, 
       
  2558                         aSecondLineBaseline, 
       
  2559                         aOverrideColor, 
       
  2560                         static_cast<const CAknLayoutFont*>(aCustomFont), 
       
  2561                         aMinimizeEdwinView);
       
  2562     }
       
  2563 
       
  2564 EXPORT_C void AknLayoutUtils::LayoutEdwin( CEikEdwin* aEdwin,
       
  2565                          const TRect& aEdwinParent,
       
  2566                          const TAknTextLineLayout& aLayout,
       
  2567                          TInt aNumberOfLinesToShowOverride,
       
  2568                          TInt aBaselineSeparationOverride,
       
  2569                          TAknsQsnTextColorsIndex aOverrideColor,
       
  2570                          TInt& aNumberOfVisibleLines )
       
  2571     {
       
  2572     __ASSERT_DEBUG(aEdwin,Panic(EAknLayoutEdwinPanicNoEdwin));
       
  2573     
       
  2574     TInt fontId = aLayout.FontId();
       
  2575 
       
  2576     // EFontCustom id not supported
       
  2577     __ASSERT_DEBUG( fontId!=EFontCustom ,Panic(EAknLayoutEdwinPanicNotSupported));
       
  2578    
       
  2579     const CAknLayoutFont* font = AknLayoutUtils::LayoutFontFromId( fontId, NULL);
       
  2580     
       
  2581     TInt firstBaseline = CorrectBaseline(aEdwinParent.Height(), aLayout.iB, fontId);
       
  2582     firstBaseline += 1; // This puts baseline into a more natural definition
       
  2583     // baseline now refers to the distance from the top of the parent down to the baseline
       
  2584 
       
  2585     TInt leftMargin = aLayout.ir;
       
  2586     TInt rightMargin = aLayout.il;
       
  2587     TInt width = aLayout.iW;
       
  2588     if (IsParentRelative(leftMargin)) { leftMargin = aEdwinParent.Width() - ELayoutP + leftMargin; }
       
  2589     if (IsParentRelative(rightMargin)) { rightMargin = aEdwinParent.Width() - ELayoutP + rightMargin; }
       
  2590     if (IsParentRelative(width)) { width = aEdwinParent.Width() - ELayoutP + width; }
       
  2591 
       
  2592     if (IsEmpty(leftMargin)) { leftMargin = aEdwinParent.Width() - rightMargin - width; }
       
  2593     if (IsEmpty(rightMargin)) { rightMargin = aEdwinParent.Width() - leftMargin - width; }
       
  2594     if (IsEmpty(width)) { width = aEdwinParent.Width() - leftMargin - rightMargin; }
       
  2595 
       
  2596     TAknTextDecorationMetrics metrics( fontId );
       
  2597     
       
  2598     TInt numberOfLinesToShow = aLayout.NumberOfLinesShown();
       
  2599     if ( aNumberOfLinesToShowOverride > 0)
       
  2600         numberOfLinesToShow = aNumberOfLinesToShowOverride;
       
  2601     __ASSERT_DEBUG(!(aEdwin->MaximumHeightInLines())||numberOfLinesToShow<=aEdwin->MaximumHeightInLines(),Panic(EAknLayoutEdwinPanicNoLinesOverMaxNoLines));
       
  2602     
       
  2603     TInt secondBaseline = 0;
       
  2604     if ( numberOfLinesToShow < 2)
       
  2605         {
       
  2606         secondBaseline = 0;
       
  2607         }
       
  2608     else
       
  2609         {
       
  2610         TInt baselineDelta =  aLayout.BaselineSkip();
       
  2611         if ( aBaselineSeparationOverride > 0)
       
  2612             baselineDelta = aBaselineSeparationOverride;
       
  2613     
       
  2614         if (baselineDelta != 0) 
       
  2615             secondBaseline = firstBaseline + baselineDelta;
       
  2616         }   
       
  2617     
       
  2618     AknLayoutUtilsHelpers::LayoutEdwinScalableWithCorrectedParametersAndDecorationMetrics(
       
  2619                                  aEdwin, 
       
  2620                                  aEdwinParent, 
       
  2621                                  font, 
       
  2622                                  aLayout.iC, 
       
  2623                                  leftMargin, 
       
  2624                                  rightMargin, 
       
  2625                                  firstBaseline,
       
  2626                                  width, 
       
  2627                                  aLayout.iJ, 
       
  2628                                  numberOfLinesToShow, 
       
  2629                                  secondBaseline, 
       
  2630                                  aOverrideColor,
       
  2631                                  metrics,
       
  2632                                  ETrue, // Constrain to fit within parent
       
  2633                                  aNumberOfVisibleLines);
       
  2634      
       
  2635     }
       
  2636 
       
  2637 
       
  2638 EXPORT_C TRect AknLayoutUtils::MinimizedEdwinRect(const CEikEdwin *aEdwin) 
       
  2639     {
       
  2640     if (!aEdwin->TextView() || aEdwin->TextView()->AlteredViewRect().Size().iHeight == 0)
       
  2641         {
       
  2642         return aEdwin->Rect();
       
  2643         }
       
  2644     return aEdwin->TextView()->AlteredViewRect();
       
  2645     } 
       
  2646 
       
  2647 EXPORT_C void AknLayoutUtils::LayoutMfne(CEikMfne *aMfne, const TRect &aMfneParent, TInt aResourceId)
       
  2648     {
       
  2649     TResourceReader rr;
       
  2650     TRAPD(error,
       
  2651       {
       
  2652       CEikonEnv::Static()->CreateResourceReaderLC(rr, aResourceId);
       
  2653       LayoutMfne(aMfne, aMfneParent, rr);
       
  2654       CleanupStack::PopAndDestroy();
       
  2655       });
       
  2656     if (error != KErrNone)
       
  2657     {
       
  2658     aMfne->SetRect(TRect(aMfneParent.iTl, TSize(2,2)));
       
  2659     aMfne->SetMfneAlignment(-1); // nasty
       
  2660     }
       
  2661 #ifdef AKNUTILS_ENABLE_TRACES
       
  2662     __ASSERT_DEBUG(error == KErrNone, LOGTEXT(_L("AknLayoutUtils:LayoutLabel: Resource reader failed.")));
       
  2663 #endif // AKNUTILS_ENABLE_TRACES
       
  2664     }
       
  2665 
       
  2666 EXPORT_C void AknLayoutUtils::LayoutMfne(CEikMfne* aMfne, const TRect &aMfneParent, const SAknLayoutMfne &aL)
       
  2667     {
       
  2668     LayoutMfne(aMfne,aMfneParent, aL.iFont, aL.iC, aL.iL, aL.iR, aL.iB, aL.iW, aL.iJ);
       
  2669     }
       
  2670 
       
  2671 EXPORT_C void AknLayoutUtils::LayoutMfne(CEikMfne* aMfne, const TRect &aMfneParent, const TAknTextLineLayout &aL)
       
  2672     {
       
  2673     LayoutMfne(aMfne,aMfneParent, aL.FontId(), aL.iC, aL.il, aL.ir, aL.iB, aL.iW, aL.iJ);
       
  2674     }
       
  2675 
       
  2676 EXPORT_C void AknLayoutUtils::LayoutMfne(CEikMfne *aMfne, const TRect &aMfneParent, TResourceReader &aReader)
       
  2677     {
       
  2678     TInt fontid = aReader.ReadInt16();
       
  2679     TInt C = aReader.ReadInt16();
       
  2680     TInt lm = aReader.ReadInt16();
       
  2681     TInt rm = aReader.ReadInt16();
       
  2682     TInt B = aReader.ReadInt16();
       
  2683     TInt W = aReader.ReadInt16();
       
  2684     TInt J = aReader.ReadInt16();
       
  2685     LayoutMfne(aMfne, aMfneParent, fontid, C, lm, rm, B, W, J);
       
  2686     }
       
  2687 
       
  2688 EXPORT_C void AknLayoutUtils::LayoutMfne(CEikMfne *aMfne, const TRect &aMfneParent, TInt fontid, TInt /*aColor*/, TInt aLeftMargin, TInt aRightMargin, TInt aBaseline, TInt aWidth, TInt aJustification)
       
  2689     {
       
  2690     // This routine adds top, bottom and left and right margins to the text 
       
  2691 
       
  2692     // Corrects the baseline in the case of using new scalable layout data
       
  2693     aBaseline = CorrectBaseline(aMfneParent.Height(), aBaseline, fontid);
       
  2694 
       
  2695     aMfne->SetBorder(TGulBorder::ENone);
       
  2696     const CFont *font = FontFromId(fontid);  
       
  2697     aMfne->SetFont(font);
       
  2698 
       
  2699     TRect rect = TextRectFromCoords(aMfneParent, font, aLeftMargin, aRightMargin, aBaseline, aWidth );
       
  2700     // Margin correction done already at the top
       
  2701     TAknTextDecorationMetrics decoration( fontid );
       
  2702     TInt extension1(0);
       
  2703     TInt extension2(0);
       
  2704     decoration.GetLeftAndRightMargins( extension1, extension2 );
       
  2705 
       
  2706     // Since these margins are the ones drawn in by the MFNE, we expand the MFNE to include these margins
       
  2707     rect.iTl.iX -= extension1;
       
  2708     rect.iBr.iX += extension2;
       
  2709 
       
  2710     // In scalable UI, these margins are also included in the height
       
  2711     // Done by magic numbers previously
       
  2712     decoration.GetTopAndBottomMargins( extension1, extension2 );
       
  2713     rect.iTl.iY -= extension1;
       
  2714     rect.iBr.iY += extension2;
       
  2715 
       
  2716     aMfne->SetRect( rect );
       
  2717     aMfne->SetMfneAlignment(aJustification); // let MNFE realign it self
       
  2718     }
       
  2719 
       
  2720 
       
  2721 EXPORT_C void AknLayoutUtils::LayoutControl(CCoeControl *aControl, const TRect &aParent, TInt aResourceId)
       
  2722     {
       
  2723     TResourceReader rr;
       
  2724     TRAPD(error,
       
  2725       {
       
  2726       CEikonEnv::Static()->CreateResourceReaderLC(rr, aResourceId);
       
  2727       LayoutControl(aControl, aParent, rr);
       
  2728       CleanupStack::PopAndDestroy();
       
  2729       });
       
  2730     if (error != KErrNone)
       
  2731     {
       
  2732     aControl->SetRect(TRect(aParent.iTl, TSize(2,2)));
       
  2733     }
       
  2734 #ifdef AKNUTILS_ENABLE_TRACES
       
  2735     __ASSERT_DEBUG(error == KErrNone, LOGTEXT(_L("AknLayoutUtils:LayoutControl: Resource reader failed.")));
       
  2736 #endif // AKNUTILS_ENABLE_TRACES
       
  2737     }
       
  2738 
       
  2739 EXPORT_C void AknLayoutUtils::LayoutControl(CCoeControl *aControl, const TRect &aParent, const SAknLayoutControl &aL)
       
  2740     {
       
  2741     LayoutControl(aControl, aParent, aL.iC,aL.iL, aL.iT, aL.iR, aL.iB, aL.iW, aL.iH);
       
  2742     }
       
  2743 
       
  2744 EXPORT_C void AknLayoutUtils::LayoutControl(CCoeControl *aControl, const TRect &aParent, const TAknWindowLineLayout &aL)
       
  2745     {
       
  2746     LayoutControl(aControl, aParent, aL.iC,aL.il, aL.it, aL.ir, aL.ib, aL.iW, aL.iH);
       
  2747     }
       
  2748 
       
  2749 EXPORT_C void AknLayoutUtils::LayoutControl(CCoeControl *aControl, const TRect &aParent, TResourceReader &aReader)
       
  2750     {
       
  2751     TInt C = aReader.ReadInt16();
       
  2752     TInt l = aReader.ReadInt16();
       
  2753     TInt t = aReader.ReadInt16();
       
  2754     TInt r = aReader.ReadInt16();
       
  2755     TInt b = aReader.ReadInt16();
       
  2756     TInt W = aReader.ReadInt16();
       
  2757     TInt H = aReader.ReadInt16();
       
  2758     LayoutControl(aControl, aParent, C,l,t,r,b,W,H);
       
  2759     }
       
  2760 
       
  2761 EXPORT_C void AknLayoutUtils::LayoutControl(CCoeControl *aControl, const TRect &aParent, TInt /*C*/, TInt l, TInt t, TInt r, TInt b, TInt W, TInt H)
       
  2762     {
       
  2763     TRect rect = RectFromCoords(aParent, l, t, r, b, W, H);
       
  2764     aControl->SetRect(rect);
       
  2765 #ifdef AKNUTILS_ENABLE_TRACES
       
  2766     __ASSERT_DEBUG(aControl->Size() == rect.Size(), LOGTEXT(_L("AknLayoutUtils/LayoutControl: ERROR: Control changed its size in SizeChanged() - That is NOT allowed")));
       
  2767 #endif // AKNUTILS_ENABLE_TRACES
       
  2768     }
       
  2769 
       
  2770 
       
  2771 EXPORT_C void AknLayoutUtils::LayoutImage(CEikImage *aImage, const TRect &aParent, TInt aResourceId)
       
  2772     {
       
  2773     LayoutControl(aImage, aParent, aResourceId);
       
  2774     }
       
  2775 
       
  2776 EXPORT_C void AknLayoutUtils::LayoutImage(CEikImage *aImage, const TRect &aParent, const SAknLayoutControl &aL)
       
  2777     {
       
  2778     LayoutImage(aImage, aParent, aL.iC,aL.iL, aL.iT, aL.iR, aL.iB, aL.iW, aL.iH);
       
  2779     }
       
  2780 
       
  2781 EXPORT_C void AknLayoutUtils::LayoutImage(CEikImage *aImage, const TRect &aParent, const TAknWindowLineLayout &aL)
       
  2782     {
       
  2783     LayoutImage(aImage, aParent, aL.iC,aL.il, aL.it, aL.ir, aL.ib, aL.iW, aL.iH);
       
  2784     }
       
  2785 
       
  2786 EXPORT_C void AknLayoutUtils::LayoutImage(CEikImage *aImage, const TRect &aParent, TResourceReader &aReader)
       
  2787     {
       
  2788     LayoutControl(aImage,aParent,aReader);
       
  2789     }
       
  2790 
       
  2791 EXPORT_C void AknLayoutUtils::LayoutImage(CEikImage *aImage, const TRect &aParent, TInt C, TInt l, TInt t, TInt r, TInt b, TInt W, TInt H)
       
  2792     {
       
  2793     LayoutControl(aImage, aParent,C,l,t,r,b,W,H);
       
  2794     TRect rect = RectFromCoords(aParent, l, t, r, b, W, H);
       
  2795     if (aImage->Bitmap())
       
  2796        AknIconUtils::SetSize(const_cast<CFbsBitmap*>(aImage->Bitmap()), rect.Size());
       
  2797     }
       
  2798 
       
  2799 EXPORT_C void AknLayoutUtils::LayoutSecretEditor(CEikSecretEditor* aSecEd, const TRect& aParent, const SAknLayoutText &aLayout)
       
  2800     {
       
  2801     TInt left = aLayout.iL;
       
  2802     TInt right = aLayout.iR;
       
  2803     TInt baseline = AknLayoutUtils::CorrectBaseline(aParent.Height(), aLayout.iB, aLayout.iFont);
       
  2804     if (IsParentRelative(left)) { left = left - ELayoutP + aParent.Width(); }
       
  2805     if (IsParentRelative(right)) { right = right - ELayoutP + aParent.Width(); }
       
  2806     const CFont *font = FontFromId(aLayout.iFont);
       
  2807     CGraphicsContext::TTextAlign align = TextAlignFromId(aLayout.iJ);
       
  2808     aSecEd->AknSetFont(*font);
       
  2809     aSecEd->AknSetAlignment(align);
       
  2810     aSecEd->SetBorder(TGulBorder::ENone);
       
  2811     TRect rect = TextRectFromCoords(aParent, font, left, right, baseline, aLayout.iW);
       
  2812     // give secret editor margin as well in scalable
       
  2813     TAknTextDecorationMetrics decoration( font );
       
  2814     TInt extension1(0);
       
  2815     TInt extension2(0);
       
  2816 
       
  2817     decoration.GetLeftAndRightMargins( extension1, extension2 );
       
  2818     rect.iTl.iX -= extension1;
       
  2819     rect.iBr.iX += extension2;
       
  2820 
       
  2821     // In scalable UI, these margins are also included in the height
       
  2822     decoration.GetTopAndBottomMargins( extension1, extension2 );
       
  2823     rect.iTl.iY -= extension1;
       
  2824     rect.iBr.iY += extension2;
       
  2825     aSecEd->SetRect(rect);
       
  2826     }
       
  2827 
       
  2828 EXPORT_C void AknLayoutUtils::LayoutSecretEditor(CEikSecretEditor* aSecEd, const TRect& aParent, const TAknTextLineLayout &aLayout)
       
  2829     {
       
  2830     SAknLayoutText layoutStruct = { aLayout.FontId(), aLayout.iC, aLayout.il, aLayout.ir, aLayout.iB, aLayout.iW, aLayout.iJ};
       
  2831     AknLayoutUtils::LayoutSecretEditor(aSecEd, aParent, layoutStruct);
       
  2832     }
       
  2833 
       
  2834 
       
  2835 // Notice, if you use this, you must ensure that the control you use this with does not have any extra borders or
       
  2836 // other such things -> if you see fonts clipped from bottom, then you have borders somewhere.
       
  2837 EXPORT_C TRect AknLayoutUtils::TextRectFromCoords(
       
  2838     const TRect &aParent, 
       
  2839     const CFont *aFont, 
       
  2840     TInt aLeftMargin, 
       
  2841     TInt aRightMargin, 
       
  2842     TInt aBaseline,
       
  2843     TInt aWidth, 
       
  2844     TInt aLastBaseline)
       
  2845     {
       
  2846     if (IsParentRelative(aLeftMargin)) { aLeftMargin = aParent.Width() - ELayoutP + aLeftMargin; }
       
  2847     if (IsParentRelative(aRightMargin)) { aRightMargin = aParent.Width() - ELayoutP + aRightMargin; }
       
  2848     if (IsParentRelative(aWidth)) { aWidth = aParent.Width() - ELayoutP + aWidth; }
       
  2849 
       
  2850     if (IsEmpty(aLeftMargin)) { aLeftMargin = aParent.Width() - aRightMargin - aWidth; }
       
  2851     if (IsEmpty(aRightMargin)) { aRightMargin = aParent.Width() - aLeftMargin - aWidth; }
       
  2852     if (IsEmpty(aWidth)) { aWidth = aParent.Width() - aLeftMargin - aRightMargin; }
       
  2853 
       
  2854     (void)aWidth;
       
  2855     TRect rect = aParent;
       
  2856 
       
  2857     // Use these as measures of baseline -> top of pane, and baseline -> bottom of pane
       
  2858     // If its a CAknLayoutFont, then we can use exactly what we need for this
       
  2859     TInt effectiveAscent(0);
       
  2860     TInt effectiveDescent(0);
       
  2861     const CAknLayoutFont* layoutFont = CAknLayoutFont::AsCAknLayoutFontOrNull( aFont );
       
  2862     if ( layoutFont )
       
  2863         {
       
  2864         effectiveAscent = layoutFont->TextPaneTopToBaseline();
       
  2865         effectiveDescent = layoutFont->BaselineToTextPaneBottom();
       
  2866         }
       
  2867     else
       
  2868         {
       
  2869         effectiveAscent = aFont->AscentInPixels();
       
  2870         effectiveDescent = aFont->DescentInPixels();
       
  2871         }
       
  2872 
       
  2873     rect.iTl.iX += aLeftMargin;
       
  2874     rect.iBr.iX -= aRightMargin;
       
  2875     // Add one to account for the series 60 layout definition of baseline
       
  2876     rect.iTl.iY += aBaseline + 1 - effectiveAscent; 
       
  2877     // Meaning of aLastBaseline is actually (nLines-1)*baselineSeparation
       
  2878     // So bottom position is first baseline + aLastbaseline + descent + extra 
       
  2879     // An extra pixel is added in the non-scalable code above, but in scalable we decide not to 
       
  2880     // add it:
       
  2881     rect.iBr.iY = aParent.iTl.iY + aBaseline + 1 + aLastBaseline + effectiveDescent; //Vesa
       
  2882 
       
  2883 #ifdef _DEBUG
       
  2884     TInt error = 0;
       
  2885 
       
  2886     __ASSERT_DEBUG(rect.Size().iWidth > 0, (error = 1, LOGTEXT1(_L("AknLayoutUtils: Rect width %d > 0"),rect.Size().iWidth)));
       
  2887     __ASSERT_DEBUG(rect.Size().iHeight > 0, (error = 2, LOGTEXT1(_L("AknLayoutUtils: Rect height %d > 0"), rect.Size().iHeight)));
       
  2888     __ASSERT_DEBUG(rect.Size().iWidth == aWidth, (error = 3, LOGTEXT2(_L("AknLayoutUtils: Calculated rect %d different from one from LAF %d"),rect.Size().iWidth, aWidth)));
       
  2889     if (error)
       
  2890         {
       
  2891         /* a good place for a breakpoint */
       
  2892         error = error;
       
  2893         }
       
  2894 #endif
       
  2895 
       
  2896     return rect;
       
  2897     }
       
  2898 
       
  2899 
       
  2900 TBool IsParentRelative(TInt aVal)
       
  2901     {
       
  2902     return aVal > ELayoutP-ELayoutPRange && aVal <= ELayoutP;
       
  2903     }
       
  2904 
       
  2905 EXPORT_C TRect AknLayoutUtils::RectFromCoords(const TRect& aParent,  TInt l, TInt t, TInt r, TInt b, TInt W, TInt H)
       
  2906     {
       
  2907     // TP HACK
       
  2908     if (l==0&&t==0&&r==0&&b==0&&W==0&&H==0)
       
  2909         {
       
  2910 #ifdef _AKNUTILS_ENABLE_TRACES
       
  2911         LOGTEXT(_L("Error in layout data; ALL ZEROS!"));
       
  2912 #endif // AKNUTILS_ENABLE_TRACES
       
  2913         W=ELayoutEmpty;
       
  2914         H=ELayoutEmpty;
       
  2915         }
       
  2916     // END OF HACK
       
  2917     
       
  2918     TSize sz=aParent.Size();
       
  2919     if (IsParentRelative(W)) { W = sz.iWidth - ELayoutP + W; }
       
  2920     if (IsParentRelative(H)) { H = sz.iHeight - ELayoutP + H; }
       
  2921     if (IsParentRelative(r)) { r = sz.iWidth - ELayoutP + r; }
       
  2922     if (IsParentRelative(b)) { b = sz.iHeight - ELayoutP + b; }
       
  2923     if (IsParentRelative(l)) { l = sz.iWidth - ELayoutP + l; }
       
  2924     if (IsParentRelative(t)) { t = sz.iHeight - ELayoutP + t; }
       
  2925 
       
  2926 
       
  2927     if (l==ELayoutEmpty)     
       
  2928         l=sz.iWidth-W-r; 
       
  2929     else if (W==ELayoutEmpty) 
       
  2930         W=sz.iWidth-r-l;
       
  2931 
       
  2932     if (t==ELayoutEmpty)     
       
  2933         t=sz.iHeight-H-b; 
       
  2934     else if (H==ELayoutEmpty) 
       
  2935         H=sz.iHeight-b-t;
       
  2936 
       
  2937 #ifdef _DEBUG
       
  2938     TInt error = 0;
       
  2939 
       
  2940     __ASSERT_DEBUG(t>=0, 
       
  2941            (error=1,LOGTEXT1(_L("AknLayoutUtils: Layout error: t=%d < 0 "),t)));
       
  2942     __ASSERT_DEBUG(aParent.Size().iWidth >= W, 
       
  2943            (error=2,LOGTEXT2(_L("AknLayoutUtils: parent rect Width smaller than required %d >= %d"), aParent.Size().iWidth, W)));
       
  2944     __ASSERT_DEBUG(aParent.Size().iHeight >= H, 
       
  2945            (error=3, LOGTEXT2(_L("AknLayoutUtils: parent rect Height smaller than required %d >= %d"), aParent.Size().iHeight, H)));
       
  2946     __ASSERT_DEBUG(l>=0, 
       
  2947            (error=4,LOGTEXT1(_L("AknLayoutUtils: Layout error: l=%d >= 0"),l)));
       
  2948     __ASSERT_DEBUG(r==ELayoutEmpty || r>=0, 
       
  2949            (error=5,LOGTEXT1(_L("AknLayoutUtils: Layout error: r=%d <= 0"),r)));
       
  2950     if (error)
       
  2951         {
       
  2952         /* A good place for breakpoint */
       
  2953         error = error;
       
  2954         }
       
  2955 #endif
       
  2956 
       
  2957     return TRect(TPoint(aParent.iTl.iX+l, aParent.iTl.iY+t), TSize(W, H));
       
  2958     }
       
  2959 
       
  2960 EXPORT_C TGulAlignment AknLayoutUtils::GulAlignFromId(TInt aJId)
       
  2961     {
       
  2962     TGulAlignment align;
       
  2963     align.SetVAlignment(EVTop);
       
  2964     switch(aJId) {
       
  2965     case ELayoutAlignNone: align.SetHAlignment(EHLeft); break;
       
  2966     case ELayoutAlignCenter: align.SetHAlignment(EHCenter); break;
       
  2967     case ELayoutAlignLeft: align.SetHAlignment(EHLeft); break;
       
  2968     case ELayoutAlignRight: align.SetHAlignment(EHRight); break;
       
  2969     case ELayoutAlignBidi: align.SetHAlignment(EHLeft); break; // mapping onto left as there seems to be no equivalent
       
  2970     default: align.SetHAlignment(EHLeft); break;    
       
  2971     };
       
  2972     return align;
       
  2973     }
       
  2974 
       
  2975 EXPORT_C CGraphicsContext::TTextAlign AknLayoutUtils::TextAlignFromId(TInt aJId)
       
  2976     {
       
  2977     CGraphicsContext::TTextAlign align;
       
  2978     switch(aJId) 
       
  2979     {
       
  2980     case ELayoutAlignNone: align = CGraphicsContext::ELeft; break; 
       
  2981     case ELayoutAlignCenter: align = CGraphicsContext::ECenter; break; 
       
  2982     case ELayoutAlignLeft: align = CGraphicsContext::ELeft; break; 
       
  2983     case ELayoutAlignRight: align = CGraphicsContext::ERight; break; 
       
  2984     case ELayoutAlignBidi: align = CGraphicsContext::ELeft; break; // mapping onto left as there seems to be no equivalent
       
  2985     default: align = CGraphicsContext::ECenter; break;
       
  2986     };
       
  2987     return align;
       
  2988     }
       
  2989 
       
  2990 EXPORT_C const CFont* AknLayoutUtils::FontFromId(TInt aId, const CFont *aCustomFont)
       
  2991     {
       
  2992     const CFont *font = 0;
       
  2993     if ( aId == EFontCustom )
       
  2994         {
       
  2995         font = aCustomFont;
       
  2996         if (!font) 
       
  2997             { // Fall-back font when null custom font is given
       
  2998             font = CEikonEnv::Static()->
       
  2999                 Font( TLogicalFont( TUid::Uid( EAknLogicalFontSecondaryFont ) ) ); //Vesa
       
  3000             }
       
  3001         }
       
  3002     else
       
  3003         {
       
  3004         font = CEikonEnv::Static()->Font( TLogicalFont( TUid::Uid( aId ) ) );
       
  3005         }
       
  3006     return font;
       
  3007     }
       
  3008 
       
  3009 EXPORT_C const CAknLayoutFont* AknLayoutUtils::LayoutFontFromId(TInt aId, const CAknLayoutFont *aCustomFont)
       
  3010     {
       
  3011     const CAknLayoutFont *font = 0;
       
  3012     const CFont* cFont = 0;
       
  3013     if ( aId == EFontCustom )
       
  3014         {
       
  3015         cFont = aCustomFont;
       
  3016         if (!cFont)
       
  3017             { // Fall-back font when null custom font is given
       
  3018             cFont = CEikonEnv::Static()->
       
  3019                 Font( TLogicalFont( TUid::Uid( EAknLogicalFontSecondaryFont ) ) );
       
  3020             }
       
  3021         }
       
  3022     else
       
  3023         {
       
  3024         cFont = CEikonEnv::Static()->Font( TLogicalFont( TUid::Uid( aId ) ) );
       
  3025         }
       
  3026     // Ensure type of font is correct
       
  3027     __ASSERT_DEBUG( CAknLayoutFont::AsCAknLayoutFontOrNull( cFont ), Panic( EAknPanicFontProvisionFailure ) );
       
  3028     font = static_cast<const CAknLayoutFont*>(cFont);
       
  3029     return font;
       
  3030     }
       
  3031 
       
  3032 EXPORT_C CAknLayoutFont* AknLayoutUtils::CreateLayoutFontFromSpecificationL( 
       
  3033     const TAknFontSpecification& aSpec)
       
  3034     {
       
  3035     CWsScreenDevice*  aBitmapDevice = CCoeEnv::Static()->ScreenDevice();
       
  3036     return CAknFontSpecificationLayoutFont::NewL( *aBitmapDevice, aSpec );
       
  3037     }
       
  3038 
       
  3039 EXPORT_C CAknLayoutFont* AknLayoutUtils::CreateLayoutFontFromSpecificationL( 
       
  3040     const TTypeface& aTypeface, 
       
  3041     const TAknFontSpecification& aSpec )
       
  3042     {
       
  3043     CWsScreenDevice*  aBitmapDevice = CCoeEnv::Static()->ScreenDevice();
       
  3044     return CAknFontSpecificationLayoutFont::NewL( *aBitmapDevice, aTypeface, aSpec );
       
  3045     }
       
  3046 
       
  3047 
       
  3048 EXPORT_C const CFont* AknLayoutUtils::FontFromName(const TDesC& aName) 
       
  3049     {
       
  3050     _LIT(KLatinPlain12,"LatinPlain12");
       
  3051     _LIT(KLatinBold12,"LatinBold12");
       
  3052     _LIT(KLatinBold13,"LatinBold13");
       
  3053     _LIT(KLatinBold16,"LatinBold16");
       
  3054     _LIT(KLatinBold17,"LatinBold17");
       
  3055     _LIT(KLatinBold19,"LatinBold19");
       
  3056     _LIT(KNumberPlain5,"NumberPlain5");
       
  3057     _LIT(KClockBold30,"ClockBold30");
       
  3058     _LIT(KLatinClock14,"LatinClock14");
       
  3059     _LIT(KCombinedChinesePlain16,"CombinedChinesePlain16");
       
  3060     _LIT(KCombinedChinesePlain12,"CombinedChinesePlain12");
       
  3061     _LIT(KNewThai12cl,"NewThai12cl");
       
  3062     _LIT(KNewThai16g,"NewThai16g");
       
  3063     _LIT(KJapanPlain12,"JapanPlain12");
       
  3064     _LIT(KJapanPlain16,"JapanPlain16");
       
  3065     _LIT(KCalcBold21,"CalcBold21");
       
  3066     _LIT(KCalcOperBold21,"CalcOperBold21");
       
  3067     _LIT(KCalcOperBold13,"CalcOperBold13");
       
  3068 
       
  3069     TInt fontId = -1;
       
  3070     if (aName == KLatinPlain12)      fontId = ELatinPlain12;
       
  3071     else if (aName == KLatinBold12)  fontId = ELatinBold12;
       
  3072     else if (aName == KLatinBold13)  fontId = ELatinBold13;
       
  3073     else if (aName == KLatinBold16)  fontId = ELatinBold16;
       
  3074     else if (aName == KLatinBold17)  fontId = ELatinBold17;
       
  3075     else if (aName == KLatinBold19)  fontId = ELatinBold19;
       
  3076     else if (aName == KNumberPlain5) fontId = ENumberPlain5;
       
  3077     else if (aName == KClockBold30)  fontId = EClockBold30;
       
  3078     else if (aName == KLatinClock14) fontId = ELatinClock14;
       
  3079     else if (aName == KCombinedChinesePlain16) fontId = EApacPlain16;
       
  3080     else if (aName == KCombinedChinesePlain12) fontId = EApacPlain12;
       
  3081     else if (aName == KNewThai16g) fontId = EApacPlain16;
       
  3082     else if (aName == KNewThai12cl) fontId = EApacPlain12;
       
  3083     else if (aName == KJapanPlain16) fontId = EApacPlain16;
       
  3084     else if (aName == KJapanPlain12) fontId = EApacPlain12;
       
  3085     else if (aName == KCalcBold21) fontId = ECalcBold21;
       
  3086     else if (aName == KCalcOperBold21) fontId = ECalcOperBold21;
       
  3087     else if (aName == KCalcOperBold13) fontId = ECalcOperBold13;
       
  3088     return FontFromId(fontId);
       
  3089     }
       
  3090 
       
  3091 /**
       
  3092 Return cursor height.
       
  3093 Cursor height depends on font. It is 15 for font latin bold 13 and 14 for
       
  3094 font latin bold 12. This means two pixels higher than font ascent and
       
  3095 descent. For other fonts it is not specified, nevertheless the sum of font
       
  3096 ascent and descent, plus 2 is returned.
       
  3097 */
       
  3098 EXPORT_C TInt AknLayoutUtils::CursorHeightFromFont(const TFontSpec& aFont)
       
  3099     {       
       
  3100     TAknFontSpecification spec( EAknFontCategoryUndefined, aFont, NULL );
       
  3101     TInt textPaneHeight(0);
       
  3102     // First look in system font array.  Match the fontspec there
       
  3103     const CAknLayoutFont* font = AknLayoutUtils::MatchFontFromSystemFontArray( aFont, NULL );
       
  3104     if ( font )
       
  3105         textPaneHeight = font->TextPaneHeight();
       
  3106     else // Use the value that was converted in TAknFontSpecification
       
  3107         textPaneHeight = spec.TextPaneHeight();
       
  3108     TAknTextDecorationMetrics metrics( spec );
       
  3109     TInt top(0);
       
  3110     TInt bottom(0);
       
  3111     metrics.GetTopAndBottomMargins( top, bottom );
       
  3112     return top + bottom + textPaneHeight;
       
  3113     }
       
  3114 
       
  3115 /**
       
  3116 Return cursor width.
       
  3117 The cursor width depends on font. It's 2 pixels for latin bold 13 and 1
       
  3118 pixel for latin bold 12. It is not specified for any other font and therefore
       
  3119 left to 1 pixel.
       
  3120 */
       
  3121 EXPORT_C TInt AknLayoutUtils::CursorWidthFromFont (const TFontSpec& aFont)
       
  3122     {
       
  3123     TAknFontSpecification spec( EAknFontCategoryUndefined, aFont, NULL );
       
  3124     TAknTextDecorationMetrics decorationMetrics( spec );
       
  3125     return(decorationMetrics.CursorWidth());
       
  3126     }
       
  3127 /**
       
  3128 * Return cursor ascent.
       
  3129 * Cursor ascent depends on font.
       
  3130 * The cursor position is 3 pixels below the base line, the ascent is equal to
       
  3131 * the height minus 3.
       
  3132 * 
       
  3133 */
       
  3134 EXPORT_C TInt AknLayoutUtils::CursorAscentFromFont(const TFontSpec& aFont)
       
  3135     {
       
  3136     TAknFontSpecification spec( EAknFontCategoryUndefined, aFont, NULL );
       
  3137 
       
  3138     // Could address font provider for this:   
       
  3139     /*
       
  3140     TInt dummyIndex;
       
  3141     const CFont* font = AknFontProvider::CreateFontFromMetrics( EFontNone, spec, dummyIndex);
       
  3142     TInt ascent = font->AscentInPixels();
       
  3143     TAknTextDecorationMetrics metrics( spec );
       
  3144     TInt topExtension;
       
  3145     TInt bottomExtension;
       
  3146     metrics.GetTopAndBottomMargins( topExtension, bottomExtension );
       
  3147     return ascent + topExtension;
       
  3148     */
       
  3149     // ...but currently return just the height
       
  3150     return spec.TextPaneHeight();
       
  3151     }
       
  3152 
       
  3153 /**
       
  3154 * Returns cursor extensions
       
  3155 * This API takes a TFontSpec.  Height in the fontspec should be in Twips, which is the default unit.
       
  3156 * The values returned are not only the true extensions above and below the text pane, but also includes
       
  3157 * any extra height or depth that is required to account for the font's maximum drawing beyond AscentInPixels 
       
  3158 * and DescentInPixels, respectively.
       
  3159 *
       
  3160 * Thus the pixel values returned are appropriate for passing into for instance 
       
  3161 *   CTextView::SetCursorExtensions(aFirstExtension,aSecondExtension);
       
  3162 *
       
  3163 * Note that the return values are defined such that, for cursors to extend above and below the glyphs, 
       
  3164 * both values would be positive.
       
  3165 * 
       
  3166 * @param    aFont           Input. FontSpec of the font being used 
       
  3167 * @param    aFirstExtension  Output. Distance (measured upward) to extend the cursor above CFont::AscentInPixels()
       
  3168 * @param    aSecondExtension Output. Distance (measured downward) to extend the cursor below CFont::DescentInPixels()
       
  3169 */
       
  3170 EXPORT_C void AknLayoutUtils::CursorExtensionsFromFont(const TFontSpec& aFont, TInt& aFirstExtension, TInt& aSecondExtension)
       
  3171     {
       
  3172     TAknFontSpecification spec( EAknFontCategoryUndefined, aFont, NULL );
       
  3173     TAknTextDecorationMetrics metrics(spec);
       
  3174     metrics.GetTopAndBottomMargins( aFirstExtension, aSecondExtension );
       
  3175 
       
  3176     // Also, correct the numbers for any excesses/shortfalls in the font metrics
       
  3177     const CAknLayoutFont* font = AknLayoutUtils::MatchFontFromSystemFontArray( aFont, NULL );
       
  3178     if ( font )
       
  3179         {
       
  3180         aFirstExtension += font->TextPaneTopToBaseline() - font->AscentInPixels();
       
  3181         aSecondExtension += font->BaselineToTextPaneBottom() - font->DescentInPixels();
       
  3182         }
       
  3183 
       
  3184     }
       
  3185 
       
  3186 /**
       
  3187 Pixels for text highlight on the left of the text. By default there are 0 pixels
       
  3188 on the left of the text when highlighting. There should be 1 pixel regardless of
       
  3189 the font type.
       
  3190 */
       
  3191 EXPORT_C TInt AknLayoutUtils::HighlightLeftPixelsFromFont(const TFontSpec& aFont)
       
  3192     {
       
  3193     TAknFontSpecification spec( EAknFontCategoryUndefined, aFont, NULL );
       
  3194     TAknTextDecorationMetrics metrics(spec);
       
  3195     TInt left(0);
       
  3196     TInt right(0);
       
  3197     metrics.GetLeftAndRightMargins( left, right);
       
  3198     return left;
       
  3199     }
       
  3200 /**
       
  3201 Pixels for text hightlight on the right of the text. By default there are 2 pixels
       
  3202 on the right for Font 13 and 1 pixel for Font 12. There should be 1 pixel for font
       
  3203 13 and 0 for Font 12. The value returned by this method will be subtracted from the
       
  3204 default one.
       
  3205 */
       
  3206 EXPORT_C TInt AknLayoutUtils::HighlightRightPixelsFromFont(const TFontSpec& aFont)
       
  3207     {
       
  3208     TAknFontSpecification spec( EAknFontCategoryUndefined, aFont, NULL );
       
  3209     TAknTextDecorationMetrics metrics(spec);
       
  3210     TInt left(0);
       
  3211     TInt right(0);
       
  3212     metrics.GetLeftAndRightMargins( left, right);
       
  3213     return right;
       
  3214     }
       
  3215 
       
  3216 /**
       
  3217 * Highlight Extensions.
       
  3218 * The values returned DO NOT include any extra extension required to account for glyphs that extend beyond
       
  3219 * CFont::AscentInPixels and CFont::DescentInPixels()
       
  3220 * 
       
  3221 */
       
  3222 void AknLayoutUtils::HighlightExtensionsFromFont(const TInt fontid, TInt& aLeft, TInt& aRight, TInt&  aTop, TInt& aBottom)
       
  3223     {
       
  3224     TAknFontSpecification spec( fontid );
       
  3225     TAknTextDecorationMetrics decorationMetrics( spec );
       
  3226     decorationMetrics.GetLeftAndRightMargins(aLeft, aRight);
       
  3227     decorationMetrics.GetTopAndBottomMargins(aTop, aBottom);
       
  3228     }
       
  3229 
       
  3230 /**
       
  3231 * This method is used internally for matching fonts in the system font array
       
  3232 * when you only have a TFontSpec. 
       
  3233 *
       
  3234 * (If you have a CFont, you can use CAknLayoutFont::AsCAknLayoutFontOrNull
       
  3235 * to detect if the font is a CAknLayoutFont.)  
       
  3236 *
       
  3237 * This routine avoids having to go to the server to regenerate the font. Some
       
  3238 * approximations are made here.  Because the == operator used in the comparison 
       
  3239 * of TFontSpecs is not always reliable (aliases are not resolved, for instance), 
       
  3240 * the comparison here is made based upon size and boldness only. As a result, this
       
  3241 * method should only be used for operations such as the determination of cursor 
       
  3242 * and highlight metrics.
       
  3243 */
       
  3244 const CAknLayoutFont* AknLayoutUtils::MatchFontFromSystemFontArray( 
       
  3245     const TFontSpec& aSpec, MGraphicsDeviceMap* /*aMap*/ )
       
  3246     {
       
  3247     const CAknLayoutFont* font = NULL;
       
  3248 
       
  3249     CAknEnv* env = AVKONENV;
       
  3250     if ( env )
       
  3251         {
       
  3252         const CArrayPtr<CAknSystemFont>* fontArray = env->SystemFontArray();
       
  3253         if ( fontArray )
       
  3254             {
       
  3255             // Search the array
       
  3256             TInt count = fontArray->Count();
       
  3257             for (TInt index = 0; index < count; index++)
       
  3258                 {
       
  3259                 CAknSystemFont* info = fontArray->At(index);
       
  3260                 CFont* thisFont = info->Font();
       
  3261                 TFontSpec thisSpec = thisFont->FontSpecInTwips();
       
  3262                 
       
  3263                 // Need to make the twips check fuzzy because one or both of
       
  3264                 // the twips values may have been through more than one twips-pixel
       
  3265                 // or pixel-twips transformation.
       
  3266                 TInt diff = aSpec.iHeight - thisSpec.iHeight;
       
  3267                 if ( diff < 0 )
       
  3268                     diff = 0-diff;
       
  3269                 if ( diff/KFontHeightComparisonDivisor == 0 )
       
  3270                     {
       
  3271                     if ( aSpec.iFontStyle.StrokeWeight() == thisSpec.iFontStyle.StrokeWeight() )
       
  3272                         {
       
  3273                         font = static_cast<const CAknLayoutFont*>(thisFont);
       
  3274                         break;
       
  3275                         }
       
  3276                     }
       
  3277                 }
       
  3278             }
       
  3279         }
       
  3280     return font;
       
  3281     }
       
  3282 EXPORT_C TBool AknLayoutUtils::LayoutMirrored()
       
  3283     {
       
  3284     TAknLayoutId layoutId;
       
  3285     CAknEnv::Static()->GetCurrentLayoutId(layoutId);
       
  3286 
       
  3287     TInt retVal( EFalse );
       
  3288 
       
  3289     if ( layoutId == EAknLayoutIdABRW )
       
  3290         {
       
  3291         retVal = ETrue;
       
  3292         }
       
  3293     
       
  3294     return retVal;
       
  3295     }
       
  3296 
       
  3297 EXPORT_C EVariantFlag AknLayoutUtils::Variant()
       
  3298     {
       
  3299     return AknBuildVariant();
       
  3300     }
       
  3301 
       
  3302 EXPORT_C ESubVariantFlag AknLayoutUtils::SubVariant()
       
  3303     {
       
  3304     switch (Variant())
       
  3305         {
       
  3306         case EEuropeanVariant:
       
  3307             return ENoSubVariant;
       
  3308 
       
  3309         case EApacVariant:
       
  3310             {
       
  3311             // Subvariant comes from UI language:
       
  3312             switch (AknLangUtils::UserLanguage())
       
  3313                 {
       
  3314                 case ELangTaiwanChinese:
       
  3315                 return ETaiwanSubVariant;
       
  3316                 case ELangHongKongChinese:
       
  3317                 return EHongKongSubVariant;
       
  3318                 case ELangPrcChinese:
       
  3319                 return EPrcSubVariant;
       
  3320                 default:
       
  3321                 return EPrcSubVariant;
       
  3322                 }            
       
  3323             }
       
  3324         default:
       
  3325             break;
       
  3326         }
       
  3327         __ASSERT_ALWAYS(0,User::Panic(_L("Variant should only return ELAF or APAC"),0));
       
  3328         return EPrcSubVariant;
       
  3329     }
       
  3330 
       
  3331 EXPORT_C void AknLayoutUtils::OverrideControlColorL(CCoeControl& aControl, TLogicalColor aLogicalColor, TRgb aColor)
       
  3332     {
       
  3333     CEikonEnv& env = static_cast<CEikonEnv&>(*aControl.ControlEnv());
       
  3334     TRgb currentColor = env.ControlColor(aLogicalColor, aControl);
       
  3335     if (aColor == currentColor)
       
  3336         {
       
  3337         // recurse to contained controls to see if they need a color override
       
  3338         TInt count = aControl.CountComponentControls();
       
  3339         for (TInt ii=0; ii<count; ii++)
       
  3340             OverrideControlColorL(*aControl.ComponentControl(ii), aLogicalColor, aColor);
       
  3341         }
       
  3342     else
       
  3343         {
       
  3344         // OverrideColorL recurses through contained controls
       
  3345         aControl.OverrideColorL(aLogicalColor, aColor);
       
  3346         }
       
  3347     }
       
  3348 
       
  3349 EXPORT_C CEikScrollBarFrame::TScrollBarType AknLayoutUtils::DefaultScrollBarType(CAknAppUiBase* aApplication)
       
  3350     {
       
  3351     CEikScrollBarFrame::TScrollBarType preferredScrollBarType(CEikScrollBarFrame::EArrowHead);
       
  3352 
       
  3353     preferredScrollBarType = CEikScrollBarFrame::EDoubleSpan;
       
  3354 
       
  3355     if (aApplication && aApplication->IsLayoutAwareApp())
       
  3356         {
       
  3357         return preferredScrollBarType;
       
  3358         }
       
  3359     else
       
  3360         {
       
  3361         // For non-layout aware apps, arrowhead scrollbar is default. 
       
  3362         // In that case also Avkon components defaults to this.
       
  3363         return CEikScrollBarFrame::EArrowHead;
       
  3364         }
       
  3365     }
       
  3366 
       
  3367 EXPORT_C void AknLayoutUtils::LayoutVerticalScrollBar(CEikScrollBarFrame* aScrollBarFrame, const TRect& aControlParent, const TAknWindowLineLayout& aLayout)
       
  3368     {
       
  3369     if (aScrollBarFrame && aScrollBarFrame->VerticalScrollBar())
       
  3370         {
       
  3371         // Only EDoubleSpan type scrollbar layout can be set
       
  3372         if (aScrollBarFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan)
       
  3373             {
       
  3374             CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (aScrollBarFrame->VerticalScrollBar());
       
  3375             TRect rect = RectFromCoords(aControlParent, aLayout.il, aLayout.it, aLayout.ir, aLayout.ib, aLayout.iW, aLayout.iH);
       
  3376             if (scrollbar && (rect != TRect(scrollbar->Position(), scrollbar->Size())))
       
  3377                 {
       
  3378                 scrollbar->SetFixedLayoutRect(rect);
       
  3379                 scrollbar->SetRect(rect);
       
  3380                 }
       
  3381             }
       
  3382         }
       
  3383     }
       
  3384 
       
  3385 EXPORT_C void AknLayoutUtils::LayoutHorizontalScrollBar(CEikScrollBarFrame* aScrollBarFrame, const TRect& aControlParent, const TAknWindowLineLayout& aLayout)
       
  3386     {
       
  3387     if (aScrollBarFrame && aScrollBarFrame->GetScrollBarHandle(CEikScrollBar::EHorizontal))
       
  3388         {
       
  3389         // Only EDoubleSpan type scrollbar layout can be set
       
  3390         if (aScrollBarFrame->TypeOfHScrollBar() == CEikScrollBarFrame::EDoubleSpan)
       
  3391             {
       
  3392             CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (aScrollBarFrame->GetScrollBarHandle(CEikScrollBar::EHorizontal));
       
  3393             TRect rect = RectFromCoords(aControlParent, aLayout.il, aLayout.it, aLayout.ir, aLayout.ib, aLayout.iW, aLayout.iH);
       
  3394             if (scrollbar && (rect != TRect(scrollbar->Position(), scrollbar->Size())))
       
  3395                 {
       
  3396                 scrollbar->SetFixedLayoutRect(rect);
       
  3397                 scrollbar->SetRect(rect);
       
  3398                 }
       
  3399             }
       
  3400         }
       
  3401     }
       
  3402 
       
  3403 
       
  3404 
       
  3405 EXPORT_C TBool AknLayoutUtils::LayoutMetricsRect( TAknLayoutMetrics aParam,
       
  3406                                                   TRect& aRect )
       
  3407     {
       
  3408     TAknWindowComponentLayout line;
       
  3409     TAknLayoutRect rect;
       
  3410     TRect screenRect(0, 0, AKN_LAYOUT_WINDOW_screen.iW, AKN_LAYOUT_WINDOW_screen.iH);
       
  3411     aRect.SetRect( 0, 0, 0, 0 );
       
  3412     
       
  3413     // No stacon pane active etc. cheking is done here before the switch-case so that we can 
       
  3414     // have slightly better performance for some other lookups (e.g. screen).
       
  3415     
       
  3416     switch (aParam)
       
  3417         {
       
  3418         case EScreen:
       
  3419             aRect = screenRect;
       
  3420             return ETrue;
       
  3421 
       
  3422         case EApplicationWindow:
       
  3423             rect.LayoutRect(
       
  3424                 screenRect,
       
  3425                 AknLayoutScalable_Avkon::application_window( 0 ) );
       
  3426             aRect = rect.Rect();
       
  3427             return ETrue;
       
  3428 
       
  3429         case EStatusPane:
       
  3430             {
       
  3431             CEikStatusPaneBase* statusPane = CEikStatusPaneBase::Current();
       
  3432             
       
  3433             if ( statusPane )
       
  3434                 {
       
  3435                 TInt currentStatusPaneLayoutResId = statusPane->CurrentLayoutResId();
       
  3436                 
       
  3437                 if ( AknStatuspaneUtils::StaconPaneActive() )
       
  3438                     {
       
  3439                     // flat status pane in landscape mode is the whole top pane area  
       
  3440                     if ( currentStatusPaneLayoutResId == R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT ||
       
  3441                          currentStatusPaneLayoutResId == R_AVKON_STATUS_PANE_LAYOUT_IDLE_FLAT )
       
  3442                         {
       
  3443                         rect.LayoutRect( screenRect, AknLayoutScalable_Avkon::area_top_pane(8) ); // flat area_top_pane in lsc
       
  3444                         aRect = rect.Rect();
       
  3445                         return ETrue;
       
  3446                         }    
       
  3447                     else
       
  3448                         {
       
  3449                         rect.LayoutRect( screenRect, AknLayoutScalable_Avkon::area_top_pane(2) ); // classic area_top_pane in lsc
       
  3450                         aRect = rect.Rect();
       
  3451                         rect.LayoutRect( aRect, AknLayoutScalable_Avkon::stacon_top_pane() );
       
  3452                         aRect = rect.Rect();
       
  3453                         rect.LayoutRect( aRect, AknLayoutScalable_Avkon::control_top_pane_stacon(0) );
       
  3454                         aRect.iBr.iX = rect.Rect().iTl.iX;  // Status pane top = stacon top - control pane top.
       
  3455                         return ETrue;   
       
  3456                         }
       
  3457                     }
       
  3458                 else
       
  3459                     {
       
  3460                     TAknWindowComponentLayout parent;
       
  3461                         
       
  3462                     switch ( currentStatusPaneLayoutResId )
       
  3463                         {
       
  3464                         case R_AVKON_STATUS_PANE_LAYOUT_USUAL_WITH_BATTERY_PANE:
       
  3465                         case R_AVKON_STATUS_PANE_LAYOUT_USUAL:
       
  3466                         case R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE:
       
  3467                         case R_AVKON_STATUS_PANE_LAYOUT_USUAL_MIRRORED:
       
  3468                         case R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE_MIRRORED:
       
  3469                         case R_AVKON_STATUS_PANE_LAYOUT_VT:
       
  3470                         case R_AVKON_STATUS_PANE_LAYOUT_VT_MIRRORED:
       
  3471                         case R_AVKON_STATUS_PANE_LAYOUT_USUAL_EXT:
       
  3472                         default:
       
  3473                             parent = AknLayoutScalable_Avkon::area_top_pane(0);
       
  3474                             line = AknLayoutScalable_Avkon::status_pane(0); // classic status pane
       
  3475                             break;
       
  3476                         
       
  3477                         case R_AVKON_STATUS_PANE_LAYOUT_IDLE:
       
  3478                         case R_AVKON_STATUS_PANE_LAYOUT_IDLE_MIRRORED:
       
  3479                             parent = AknLayoutScalable_Avkon::area_top_pane(7);
       
  3480                             line = AknLayoutScalable_Avkon::status_idle_pane(); // idle status pane
       
  3481                             break;
       
  3482                             
       
  3483                         case R_AVKON_STATUS_PANE_LAYOUT_SMALL:
       
  3484                         case R_AVKON_STATUS_PANE_LAYOUT_SMALL_WITH_SIGNAL_PANE:
       
  3485                         case R_AVKON_STATUS_PANE_LAYOUT_SMALL_WITH_SIGNAL_PANE_MIRRORED:
       
  3486                             // Small status pane is the whole top area.
       
  3487                             parent = AknLayoutScalable_Avkon::application_window(0);
       
  3488                             if ( Layout_Meta_Data::IsLandscapeOrientation() &&
       
  3489                                  AknLayoutUtils::CbaLocation() == AknLayoutUtils::EAknCbaLocationBottom )
       
  3490                                 {
       
  3491                                 line = AknLayoutScalable_Avkon::area_top_pane(2);
       
  3492                                 }
       
  3493                             else
       
  3494                                 {
       
  3495                                 line = AknLayoutScalable_Avkon::area_top_pane(1);
       
  3496                                 }
       
  3497                                 
       
  3498                             break;
       
  3499                             
       
  3500                         case R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT:
       
  3501                         case R_AVKON_STATUS_PANE_LAYOUT_IDLE_FLAT: // fallthrough
       
  3502                             {
       
  3503                             if ( Layout_Meta_Data::IsLandscapeOrientation() &&
       
  3504                                  Layout_Meta_Data::IsPenEnabled() )
       
  3505                                 {
       
  3506                                 parent = AknLayoutScalable_Avkon::area_top_pane( 2 );
       
  3507                                 }
       
  3508                             else
       
  3509                                 {
       
  3510                                 parent = AknLayoutScalable_Avkon::area_top_pane( 6 );
       
  3511                                 }
       
  3512                             line   = AknLayoutScalable_Avkon::status_pane( 1 ); // flat status pane
       
  3513                             break;
       
  3514                             }
       
  3515 
       
  3516                         case R_AVKON_WIDESCREEN_PANE_LAYOUT_USUAL:
       
  3517                         case R_AVKON_WIDESCREEN_PANE_LAYOUT_IDLE: // fallthrough
       
  3518                             {
       
  3519                             parent = AknLayoutScalable_Avkon::area_top_pane( 8 );
       
  3520                             line   = AknLayoutScalable_Avkon::status_pane( 1 );
       
  3521                             break;
       
  3522                             }
       
  3523 
       
  3524                         case R_AVKON_WIDESCREEN_PANE_LAYOUT_USUAL_FLAT:
       
  3525                         case R_AVKON_WIDESCREEN_PANE_LAYOUT_IDLE_FLAT: // fallthrough
       
  3526                             {
       
  3527                             parent = AknLayoutScalable_Avkon::area_top_pane( 19 );
       
  3528                             line   = AknLayoutScalable_Avkon::status_pane( 4 );
       
  3529                             break;
       
  3530                             }
       
  3531                             
       
  3532                         case R_AVKON_WIDESCREEN_PANE_LAYOUT_USUAL_FLAT_NO_SOFTKEYS:
       
  3533                         case R_AVKON_WIDESCREEN_PANE_LAYOUT_IDLE_FLAT_NO_SOFTKEYS: // fallthrough
       
  3534                             {
       
  3535                             parent = AknLayoutScalable_Avkon::area_top_pane( 20 );
       
  3536                             line   = AknLayoutScalable_Avkon::status_pane( 5 );
       
  3537                             break;
       
  3538                             }
       
  3539                         }
       
  3540                         
       
  3541                     rect.LayoutRect( screenRect, TAknWindowComponentLayout::Compose( parent, line ) );
       
  3542                     aRect = rect.Rect();
       
  3543                     }
       
  3544                 return ETrue;
       
  3545                 }
       
  3546             return EFalse;
       
  3547             }
       
  3548         case EPopupParent:
       
  3549             {
       
  3550             if ( screenRect.iBr.iX == 640 && screenRect.iBr.iY == 360 )
       
  3551                 {
       
  3552                 TInt variety = 16;
       
  3553 
       
  3554                 if ( AVKONENV->StatusPaneResIdForCurrentLayout(
       
  3555                          AknStatuspaneUtils::CurrentStatusPaneLayoutResId() ) ==
       
  3556                              R_AVKON_WIDESCREEN_PANE_LAYOUT_IDLE_FLAT_NO_SOFTKEYS )
       
  3557                     {
       
  3558                     variety = 25;
       
  3559                     }
       
  3560 
       
  3561                 rect.LayoutRect( screenRect, TAknWindowComponentLayout::Compose(
       
  3562                                      AknLayoutScalable_Avkon::application_window( 0 ),
       
  3563                                      AknLayoutScalable_Avkon::main_pane( variety ) ) );
       
  3564                 aRect = rect.Rect();
       
  3565                 return ETrue;
       
  3566                 }
       
  3567             else if ( screenRect.iBr.iX == 360 && screenRect.iBr.iY == 640 )
       
  3568                 {
       
  3569                 TInt variety = 1;
       
  3570                 rect.LayoutRect( screenRect, TAknWindowComponentLayout::Compose(
       
  3571                                      AknLayoutScalable_Avkon::application_window( 0 ),
       
  3572                                      AknLayoutScalable_Avkon::main_pane( variety ) ) );
       
  3573                 aRect = rect.Rect();
       
  3574                 return ETrue;
       
  3575                 }
       
  3576             else
       
  3577                 {
       
  3578                 return LayoutMetricsRect( EMainPane, aRect );
       
  3579                 }
       
  3580             }
       
  3581         case EMainPane:
       
  3582             {
       
  3583             TInt variety = 3; // classic main pane variety by default
       
  3584             
       
  3585             TInt currentStatusPaneLayoutResId = AknStatuspaneUtils::CurrentStatusPaneLayoutResId();
       
  3586 
       
  3587             switch ( currentStatusPaneLayoutResId )
       
  3588                 {
       
  3589                 case R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_RIGHT:
       
  3590                 case R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_LEFT:
       
  3591                 case R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_RIGHT:
       
  3592                 case R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_LEFT:
       
  3593                 case R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_RIGHT:
       
  3594                 case R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_LEFT:
       
  3595                     {
       
  3596                     // This is quite awkward but necessary since the fixed
       
  3597                     // toolbar area can be used by the application main pane
       
  3598                     // if the application doesn't use toolbar.
       
  3599                     TBool toolbarVisible( EFalse );
       
  3600                     if ( iAvkonAppUi )
       
  3601                         {
       
  3602                         CAknToolbar* fixedToolbar =
       
  3603                         iAvkonAppUi->CurrentFixedToolbar();
       
  3604                         if ( fixedToolbar )
       
  3605                             {
       
  3606                             TInt toolbarFlags(  fixedToolbar->ToolbarFlags() );
       
  3607                             if ( toolbarFlags & KAknToolbarFixed &&
       
  3608                                  !( toolbarFlags & KAknToolbarDefault ) &&
       
  3609                                  fixedToolbar->IsShown() )
       
  3610                                 {
       
  3611                                 toolbarVisible = ETrue;
       
  3612                                 }
       
  3613                             }
       
  3614                         }
       
  3615 
       
  3616                     variety = toolbarVisible ? 21 : 4;
       
  3617                     }
       
  3618                     break;
       
  3619 
       
  3620                 case R_AVKON_STATUS_PANE_LAYOUT_USUAL_WITH_BATTERY_PANE:
       
  3621                 case R_AVKON_STATUS_PANE_LAYOUT_USUAL:
       
  3622                 case R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE:
       
  3623                 case R_AVKON_STATUS_PANE_LAYOUT_USUAL_MIRRORED:
       
  3624                 case R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE_MIRRORED:
       
  3625                 case R_AVKON_STATUS_PANE_LAYOUT_VT:
       
  3626                 case R_AVKON_STATUS_PANE_LAYOUT_VT_MIRRORED:
       
  3627                 case R_AVKON_STATUS_PANE_LAYOUT_USUAL_EXT:
       
  3628                     {
       
  3629                     // main pane variety for usual portrait main pane with
       
  3630                     // 'area_top_pane' and 'area_bottom_pane'
       
  3631 #ifdef RD_SCALABLE_UI_V2
       
  3632                     variety = 3; 
       
  3633                     if ( iAvkonAppUi && iAvkonAppUi->TouchPane() && iAvkonAppUi->TouchPane()->IsVisible() )
       
  3634                         {
       
  3635                         variety = 15;
       
  3636                         }
       
  3637                     else if ( iAvkonAppUi && iAvkonAppUi->CurrentFixedToolbar() )
       
  3638                         {
       
  3639                         if ( AknLayoutUtils::PenEnabled() )
       
  3640                              {
       
  3641                              CAknToolbar* toolbar = iAvkonAppUi->CurrentFixedToolbar(); 
       
  3642                              TInt flags = toolbar->ToolbarFlags(); 
       
  3643                              if ( flags & KAknToolbarFixed && !( flags & KAknToolbarDefault )
       
  3644                                 && toolbar->IsShown() ) 
       
  3645                                  {
       
  3646                                  variety = 18; 
       
  3647                                  }
       
  3648                              }
       
  3649                         }
       
  3650 #else
       
  3651                     variety = 3;
       
  3652 #endif // RD_SCALABLE_UI_V2    
       
  3653                     }
       
  3654                     break;
       
  3655 
       
  3656                 case R_AVKON_STATUS_PANE_LAYOUT_IDLE:
       
  3657                 case R_AVKON_STATUS_PANE_LAYOUT_IDLE_MIRRORED:
       
  3658                     {
       
  3659                     // main pane variety for idle state portrait main pane with
       
  3660                     // 'area_top_pane' and 'area_bottom_pane'
       
  3661                     variety = 8;                    
       
  3662                     }
       
  3663                     break;
       
  3664 
       
  3665                 case R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT:
       
  3666                 case R_AVKON_STATUS_PANE_LAYOUT_IDLE_FLAT:
       
  3667                     {                    
       
  3668                     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  3669                         {
       
  3670                         if ( PenEnabled() )
       
  3671                             {
       
  3672                             // This is quite awkward but necessary since the fixed
       
  3673                             // toolbar area can be used by the application main pane
       
  3674                             // if the application doesn't use toolbar.
       
  3675                             TBool toolbarVisible( EFalse );
       
  3676                             if ( iAvkonAppUi )
       
  3677                                 {
       
  3678                                 CAknToolbar* fixedToolbar =
       
  3679                                     iAvkonAppUi->CurrentFixedToolbar();
       
  3680                                 if ( fixedToolbar )
       
  3681                                     {
       
  3682                                     TInt toolbarFlags(  fixedToolbar->ToolbarFlags() );
       
  3683                                     if ( toolbarFlags & KAknToolbarFixed &&
       
  3684                                          !( toolbarFlags & KAknToolbarDefault ) &&
       
  3685                                          fixedToolbar->IsShown()  )
       
  3686                                         {
       
  3687                                         toolbarVisible = ETrue;
       
  3688                                         }
       
  3689                                     }
       
  3690                                 }
       
  3691 
       
  3692                             variety = toolbarVisible ? 21 : 4;
       
  3693                             }
       
  3694                         else
       
  3695                             {
       
  3696                             // main pane variety with 'area_top_pane' and 
       
  3697                             // 'area_bottom_pane' in landscape (without touch pane).
       
  3698                             variety = 9;             
       
  3699                             }                    
       
  3700                         }
       
  3701                     else
       
  3702                         {
       
  3703                         // main pane variety with thin portrait status pane 
       
  3704                         variety = 7;
       
  3705                         }                                                            
       
  3706                     break;
       
  3707                     }
       
  3708                 case R_AVKON_STATUS_PANE_LAYOUT_SMALL:
       
  3709                 case R_AVKON_STATUS_PANE_LAYOUT_SMALL_WITH_SIGNAL_PANE:
       
  3710                 case R_AVKON_STATUS_PANE_LAYOUT_SMALL_WITH_SIGNAL_PANE_MIRRORED:
       
  3711                     {
       
  3712                     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  3713                         {
       
  3714                         if ( PenEnabled() )
       
  3715                             {
       
  3716                             // main pane variety with small status pane in landscape
       
  3717                             // mode with 'area_top_pane', 'area_bottom_pane' and
       
  3718                             // touch pane
       
  3719                             variety = 4;
       
  3720                             }
       
  3721                         else
       
  3722                             {
       
  3723                             // main pane variety with 'area_top_pane' and
       
  3724                             // 'area_bottom_pane' in landscape (without touch pane)
       
  3725                             variety = 9;
       
  3726                             }
       
  3727                         }
       
  3728                     else
       
  3729                         {
       
  3730                         // main pane variety with small status pane in portrait mode
       
  3731                         // (with 'area_top_pane' and 'area_bottom_pane').
       
  3732                         variety = 6;                    
       
  3733                         }
       
  3734                     }
       
  3735                     break;
       
  3736 
       
  3737                 case R_AVKON_STATUS_PANE_EMPTY:
       
  3738                 case R_AVKON_STATUS_PANE_LAYOUT_EMPTY:
       
  3739                     if ( AknStatuspaneUtils::HDLayoutActive() )
       
  3740                         {
       
  3741                         variety = 16;
       
  3742                         }
       
  3743                     else
       
  3744                         {
       
  3745                         variety = 1; // no variety without cba
       
  3746                         }
       
  3747                     break;
       
  3748                     
       
  3749                 case R_AVKON_WIDESCREEN_PANE_LAYOUT_USUAL:
       
  3750                 case R_AVKON_WIDESCREEN_PANE_LAYOUT_IDLE:
       
  3751                     {
       
  3752                     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  3753                         {
       
  3754                         variety = 4;
       
  3755                         }
       
  3756                     break;
       
  3757                     }
       
  3758                     
       
  3759                 case R_AVKON_WIDESCREEN_PANE_LAYOUT_USUAL_FLAT:
       
  3760                 case R_AVKON_WIDESCREEN_PANE_LAYOUT_IDLE_FLAT:
       
  3761                     {
       
  3762                     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  3763                         {
       
  3764                         variety = 21;
       
  3765                         }
       
  3766                     break;
       
  3767                     }
       
  3768 
       
  3769                 case R_AVKON_WIDESCREEN_PANE_LAYOUT_USUAL_FLAT_NO_SOFTKEYS:
       
  3770                     {
       
  3771                     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  3772                         {
       
  3773                         variety = 22;
       
  3774                         }
       
  3775                     break;
       
  3776                     }
       
  3777 
       
  3778                 case R_AVKON_WIDESCREEN_PANE_LAYOUT_IDLE_FLAT_NO_SOFTKEYS:
       
  3779                     {
       
  3780                     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  3781                         {
       
  3782                         variety = 25;
       
  3783                         }
       
  3784                     break;
       
  3785                     }
       
  3786                     
       
  3787                 default:
       
  3788                     break;
       
  3789                 }
       
  3790 
       
  3791             rect.LayoutRect( screenRect, TAknWindowComponentLayout::Compose(
       
  3792                                      AknLayoutScalable_Avkon::application_window( 0 ),
       
  3793                                      AknLayoutScalable_Avkon::main_pane( variety ) ) );
       
  3794                 
       
  3795             aRect = rect.Rect();
       
  3796             return ETrue;
       
  3797             }
       
  3798 
       
  3799         case EControlPane:
       
  3800             {
       
  3801             if ( AknStatuspaneUtils::StaconPaneActive() )
       
  3802                 {
       
  3803                 rect.LayoutRect(
       
  3804                     screenRect,
       
  3805                     AknLayoutScalable_Avkon::area_top_pane( 2 ) );
       
  3806                 TRect parent( rect.Rect() );
       
  3807 
       
  3808                 rect.LayoutRect(
       
  3809                     parent,
       
  3810                     AknLayoutScalable_Avkon::stacon_top_pane() );
       
  3811                 parent = rect.Rect();
       
  3812 
       
  3813                 rect.LayoutRect(
       
  3814                     parent,
       
  3815                     AknLayoutScalable_Avkon::control_top_pane_stacon( 0 ) );
       
  3816                 
       
  3817                 aRect = rect.Rect();
       
  3818                 return ETrue;
       
  3819                 }
       
  3820             else if ( AknStatuspaneUtils::HDLayoutActive() &&
       
  3821                       AknStatuspaneUtils::CurrentStatusPaneLayoutResId() !=
       
  3822                           R_AVKON_WIDESCREEN_PANE_LAYOUT_IDLE_FLAT_NO_SOFTKEYS )
       
  3823                 {
       
  3824                 rect.LayoutRect(
       
  3825                     screenRect,
       
  3826                     AknLayoutScalable_Avkon::application_window( 0 ) );
       
  3827                 TRect parent( rect.Rect() );
       
  3828                 rect.LayoutRect(
       
  3829                     parent,
       
  3830                     AknLayoutScalable_Avkon::area_side_right_pane( 5 ) );
       
  3831                 aRect = rect.Rect();
       
  3832                 return ETrue;
       
  3833                 }
       
  3834             // Control pane in flat status pane landscape mode is the
       
  3835             // whole bottom pane area.  
       
  3836             else if ( Layout_Meta_Data::IsLandscapeOrientation() &&
       
  3837                       AknStatuspaneUtils::FlatLayoutActive() )
       
  3838                 {
       
  3839                 rect.LayoutRect(
       
  3840                     screenRect,
       
  3841                     AknLayoutScalable_Avkon::area_bottom_pane( PenEnabled() ? 2 : 6 ) );
       
  3842                 aRect = rect.Rect();
       
  3843                 return ETrue;
       
  3844                 }
       
  3845             else
       
  3846                 {
       
  3847                 rect.LayoutRect(
       
  3848                     screenRect,
       
  3849                     AknLayoutScalable_Avkon::area_bottom_pane( 0 ) );
       
  3850                 aRect = rect.Rect();
       
  3851                 return ETrue;
       
  3852                 }
       
  3853             }
       
  3854                 
       
  3855         case EControlPaneBottom:
       
  3856             if (AknStatuspaneUtils::StaconPaneActive())
       
  3857                 {
       
  3858                 rect.LayoutRect( screenRect, AknLayoutScalable_Avkon::area_bottom_pane(2) ); // area_bottom_pane in lsc
       
  3859                 TRect parent = rect.Rect();
       
  3860                 rect.LayoutRect( parent, AknLayoutScalable_Avkon::stacon_bottom_pane() );
       
  3861                 parent = rect.Rect();
       
  3862                 rect.LayoutRect( parent, AknLayoutScalable_Avkon::control_bottom_pane_stacon(0) );
       
  3863                 aRect = rect.Rect();
       
  3864                 return ETrue;
       
  3865                 }
       
  3866              return EFalse;
       
  3867              
       
  3868         case EStatusPaneBottom:
       
  3869              if (AknStatuspaneUtils::StaconPaneActive())
       
  3870                 {
       
  3871                 rect.LayoutRect( screenRect, AknLayoutScalable_Avkon::area_bottom_pane(2) ); // area_bottom_pane in lsc
       
  3872                 aRect = rect.Rect();
       
  3873                 rect.LayoutRect( aRect, AknLayoutScalable_Avkon::stacon_bottom_pane() );
       
  3874                 aRect = rect.Rect();
       
  3875                 rect.LayoutRect( aRect, AknLayoutScalable_Avkon::control_bottom_pane_stacon(0) );
       
  3876                 aRect.iBr.iX = rect.Rect().iTl.iX;  // Status pane bottom = stacon bottom - control pane bottom.
       
  3877                 return ETrue;   
       
  3878                 }
       
  3879              return EFalse;
       
  3880              
       
  3881         case EStaconTop:
       
  3882             if (AknStatuspaneUtils::StaconPaneActive())
       
  3883                 {
       
  3884                 rect.LayoutRect( screenRect, TAknWindowComponentLayout::Compose(
       
  3885                                  AknLayoutScalable_Avkon::area_top_pane(2),
       
  3886                                  AknLayoutScalable_Avkon::stacon_top_pane() ) );
       
  3887                 aRect = rect.Rect();
       
  3888                 return ETrue;
       
  3889                 }
       
  3890             return EFalse;
       
  3891 
       
  3892         case EStaconBottom:
       
  3893             if (AknStatuspaneUtils::StaconPaneActive())
       
  3894                 {
       
  3895                 rect.LayoutRect( screenRect, TAknWindowComponentLayout::Compose(
       
  3896                                  AknLayoutScalable_Avkon::area_bottom_pane(2),
       
  3897                                  AknLayoutScalable_Avkon::stacon_bottom_pane() ) );
       
  3898                 aRect = rect.Rect();
       
  3899                 return ETrue;
       
  3900                 }
       
  3901             return EFalse;
       
  3902             
       
  3903         default:
       
  3904             break;
       
  3905         }
       
  3906 
       
  3907     // Main pane descendants
       
  3908     
       
  3909     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  3910         {
       
  3911         rect.LayoutRect( screenRect, AknLayoutScalable_Avkon::main_pane(4) );
       
  3912         }
       
  3913     else
       
  3914         {
       
  3915         rect.LayoutRect( screenRect, AknLayoutScalable_Avkon::main_pane(3) );
       
  3916         }
       
  3917 
       
  3918     TRect mainpane = rect.Rect();
       
  3919 
       
  3920     switch (aParam)
       
  3921         {
       
  3922         case EFindPane:
       
  3923             rect.LayoutRect( mainpane, AknLayoutScalable_Avkon::find_pane() );
       
  3924             aRect = rect.Rect();
       
  3925             return ETrue;
       
  3926 
       
  3927         case EWallpaperPane:
       
  3928             if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  3929                 {  
       
  3930                 rect.LayoutRect( mainpane, AknLayoutScalable_Avkon::wallpaper_pane(1) );
       
  3931                 }
       
  3932             else
       
  3933                 {
       
  3934                 rect.LayoutRect( mainpane, AknLayoutScalable_Avkon::wallpaper_pane(0) );
       
  3935                 }              
       
  3936             aRect = rect.Rect();
       
  3937             return ETrue;
       
  3938 
       
  3939         case EIndicatorPane:
       
  3940             // indicator pane on the left side on landscape mode
       
  3941             if ( Layout_Meta_Data::IsLandscapeOrientation() && LayoutMirrored() )
       
  3942                 {
       
  3943                 rect.LayoutRect( mainpane, AknLayoutScalable_Avkon::indicator_pane(2) );
       
  3944                 }
       
  3945             // indicator pane on the right side on landscape mode
       
  3946             else if ( Layout_Meta_Data::IsLandscapeOrientation() && !LayoutMirrored() )
       
  3947                 {
       
  3948                 rect.LayoutRect( mainpane, AknLayoutScalable_Avkon::indicator_pane(1) );
       
  3949                 }
       
  3950             // portrait mode
       
  3951             else
       
  3952                 {
       
  3953                 rect.LayoutRect( mainpane, AknLayoutScalable_Avkon::indicator_pane(0) );
       
  3954                 }
       
  3955             aRect = rect.Rect();
       
  3956             return ETrue;
       
  3957 
       
  3958         case EAColunm:  
       
  3959             {                   
       
  3960             TAknLayoutRect listPaneRect;
       
  3961             listPaneRect.LayoutRect(mainpane, AknLayoutScalable_Avkon::bg_list_pane(0));                    
       
  3962             rect.LayoutRect(listPaneRect.Rect(), AknLayoutScalable_Avkon::bg_list_pane_g1(1));
       
  3963             aRect = rect.Rect();
       
  3964             return ETrue;
       
  3965             }
       
  3966         case EBColunm:
       
  3967             {           
       
  3968             TAknLayoutRect listPaneRect;
       
  3969             listPaneRect.LayoutRect(mainpane, AknLayoutScalable_Avkon::bg_list_pane(0));                    
       
  3970             TAknLayoutRect columnA;
       
  3971             columnA.LayoutRect(listPaneRect.Rect(), AknLayoutScalable_Avkon::bg_list_pane_g1(1));
       
  3972             // A+B column           
       
  3973             rect.LayoutRect(listPaneRect.Rect(), AknLayoutScalable_Avkon::bg_list_pane_g1(2));
       
  3974             aRect = rect.Rect();
       
  3975             // Reduce A column
       
  3976             aRect.iTl.iX += columnA.Rect().Width();
       
  3977             return ETrue;
       
  3978             }
       
  3979         case ECColunm:
       
  3980             {           
       
  3981             TAknLayoutRect listPaneRect;
       
  3982             listPaneRect.LayoutRect(mainpane, AknLayoutScalable_Avkon::bg_list_pane(0));                    
       
  3983             rect.LayoutRect(listPaneRect.Rect(), AknLayoutScalable_Avkon::bg_list_pane_g2(2));
       
  3984             aRect = rect.Rect();
       
  3985             return ETrue;
       
  3986             }
       
  3987         case EDColunm:
       
  3988             {
       
  3989             TAknLayoutRect listScrollPaneRect;
       
  3990             listScrollPaneRect.LayoutRect(mainpane, AknLayoutScalable_Avkon::listscroll_gen_pane(0));
       
  3991             TAknLayoutRect listGenPaneRect;
       
  3992             listGenPaneRect.LayoutRect(listScrollPaneRect.Rect(), AknLayoutScalable_Avkon::list_gen_pane(1));
       
  3993             TAknLayoutRect listSinglePaneRect;
       
  3994             listSinglePaneRect.LayoutRect(listGenPaneRect.Rect(), AknLayoutScalable_Avkon::list_single_pane(0));
       
  3995             TAknLayoutRect listSinglePaneG2Rect;
       
  3996             listSinglePaneG2Rect.LayoutRect(listSinglePaneRect.Rect(), AknLayoutScalable_Avkon::list_single_pane_g2(0));
       
  3997             
       
  3998             aRect = listSinglePaneRect.Rect();
       
  3999             
       
  4000             if ( LayoutMirrored() )
       
  4001                 {               
       
  4002                 aRect.iBr.iX = listSinglePaneG2Rect.Rect().iBr.iX;
       
  4003                 }
       
  4004             else
       
  4005                 {               
       
  4006                 aRect.iTl.iX = listSinglePaneG2Rect.Rect().iTl.iX;
       
  4007                 }
       
  4008             
       
  4009             // Adjust the height of the rect to match with the height of the other columns. 
       
  4010             TAknLayoutRect listPaneRect;
       
  4011             listPaneRect.LayoutRect(mainpane, AknLayoutScalable_Avkon::bg_list_pane(0));                    
       
  4012             rect.LayoutRect(listPaneRect.Rect(), AknLayoutScalable_Avkon::bg_list_pane_g1(1));
       
  4013             aRect.iTl.iY = rect.Rect().iTl.iY;
       
  4014             aRect.iBr.iY = rect.Rect().iBr.iY;
       
  4015             
       
  4016             return ETrue;
       
  4017             }
       
  4018         default:
       
  4019             break;
       
  4020         }
       
  4021 
       
  4022     // Status pane descendants
       
  4023     
       
  4024     CEikStatusPaneBase* statusPane = CEikStatusPaneBase::Current();
       
  4025     TInt err = KErrNotFound;
       
  4026    
       
  4027     if (statusPane)
       
  4028         {
       
  4029         switch (aParam)
       
  4030         {
       
  4031             case ESignalPane:
       
  4032                  TRAP(err,  aRect = statusPane->PaneRectL(TUid::Uid( EEikStatusPaneUidSignal )));                   
       
  4033                  break;
       
  4034 
       
  4035             case EContextPane:
       
  4036                  TRAP(err,  aRect = statusPane->PaneRectL(TUid::Uid( EEikStatusPaneUidContext )));                  
       
  4037                  break;
       
  4038 
       
  4039             case ETitlePane:
       
  4040                  TRAP(err,  aRect = statusPane->PaneRectL(TUid::Uid( EEikStatusPaneUidTitle )));                    
       
  4041                  break;
       
  4042 
       
  4043             case EBatteryPane:
       
  4044                  TRAP(err,  aRect = statusPane->PaneRectL(TUid::Uid( EEikStatusPaneUidBattery )));                  
       
  4045                  break;
       
  4046 
       
  4047             case EUniversalIndicatorPane:
       
  4048                  TRAP(err,  aRect = statusPane->PaneRectL(TUid::Uid( EEikStatusPaneUidIndic )));                    
       
  4049                  break;
       
  4050 
       
  4051             case ENaviPane:
       
  4052                  TRAP(err,  aRect = statusPane->PaneRectL(TUid::Uid( EEikStatusPaneUidNavi )));                 
       
  4053                  break;
       
  4054 
       
  4055             default:
       
  4056                 break;
       
  4057             }
       
  4058         }
       
  4059 
       
  4060             
       
  4061     if (err != KErrNone)    
       
  4062         {
       
  4063         aRect = TRect(TPoint(0,0), TPoint(0,0));
       
  4064         return EFalse;      
       
  4065         }
       
  4066         
       
  4067     return ETrue;
       
  4068     }
       
  4069 
       
  4070 
       
  4071 EXPORT_C TBool AknLayoutUtils::LayoutMetricsSize(TAknLayoutMetrics aParam, TSize& aSize)
       
  4072     {
       
  4073     TRect rect;
       
  4074     
       
  4075     TBool ret = LayoutMetricsRect(aParam, rect);
       
  4076     aSize = rect.Size();
       
  4077     return ret;
       
  4078     }
       
  4079 
       
  4080     
       
  4081 EXPORT_C TBool AknLayoutUtils::LayoutMetricsPosition(TAknLayoutMetrics aParam, TPoint& aPos)
       
  4082     {
       
  4083     TRect rect;
       
  4084     
       
  4085     TBool ret = LayoutMetricsRect(aParam, rect);
       
  4086     aPos = rect.iTl;
       
  4087     return ret;
       
  4088     }
       
  4089 
       
  4090 
       
  4091 TInt AknLayoutUtils::CorrectBaseline(TInt aParentHeight, TInt aBaseline, TInt aFontId)
       
  4092     {
       
  4093     TInt B = aBaseline;
       
  4094 
       
  4095     if( TAknFontId::IsEncodedFont(aFontId) && aFontId != ELayoutEmpty ) // This tells us that the font id has come from scalable layout API
       
  4096         {
       
  4097         TInt b = aBaseline;
       
  4098         if (IsParentRelative(b)) { b = aParentHeight - ELayoutP + b; }
       
  4099 
       
  4100         const CAknLayoutFont *font = LayoutFontFromId(aFontId);
       
  4101         TInt descent = font->BaselineToTextPaneBottom();
       
  4102 
       
  4103         // calculate distance down from top of parent to bottom of maximal glyph
       
  4104         TInt top2bog = aParentHeight - b;
       
  4105 
       
  4106         // distance down to baseline is distance down to bottom of glyph minus descent
       
  4107         // A further 1 is subtracted to account for the definition of baseline in the
       
  4108         // Series 60 pre-2.8 layout specifications.
       
  4109         B = top2bog - descent - 1;
       
  4110         }
       
  4111 
       
  4112     return B;
       
  4113     }
       
  4114     
       
  4115 void AknLayoutUtils::CorrectFontId(TRect aParent, TInt at, TInt /*aH*/, TInt ab, TInt &aFontId)
       
  4116 {
       
  4117     // Only ELayoutEmpty's allowed in aFontId and encoded as 0x100 in font height.
       
  4118     const static TUint heightMask = 0x7FC0;
       
  4119     TUint heightScaledBy6Bits = aFontId & heightMask;
       
  4120     if (heightScaledBy6Bits == 0x100 << 6)
       
  4121         { // ELayoutEmpty
       
  4122         TInt height = aParent.Height() - at - ab;
       
  4123         heightScaledBy6Bits = height << 6;
       
  4124         heightScaledBy6Bits &= heightMask; // truncate if over allocated area.
       
  4125         }
       
  4126     TInt fontId = aFontId;
       
  4127     fontId &= ~heightMask;
       
  4128     fontId |= heightScaledBy6Bits;
       
  4129     aFontId = fontId;
       
  4130 }
       
  4131 
       
  4132 EXPORT_C TBool AknLayoutUtils::ScalableLayoutInterfaceAvailable()
       
  4133     {
       
  4134     TBool available = ETrue;
       
  4135     
       
  4136     // Use layout.iW and .iH to find out the resolution, and check for those that
       
  4137     // do not have scalable layout interface.
       
  4138     /*
       
  4139     TAknWindowLineLayout layout = AKN_LAYOUT_WINDOW_screen;
       
  4140     if (layout.iW == 42 && layout.iH == 42)
       
  4141         {
       
  4142         available = EFalse;
       
  4143         }
       
  4144     */
       
  4145     
       
  4146     return available;
       
  4147     }
       
  4148     
       
  4149 
       
  4150 // ---------------------------------------------------------------------------
       
  4151 // AknLayoutUtils::CbaLocation
       
  4152 // Returns location of softkeys (bottom, right or left)
       
  4153 // ---------------------------------------------------------------------------
       
  4154 //
       
  4155 EXPORT_C AknLayoutUtils::TAknCbaLocation AknLayoutUtils::CbaLocation()
       
  4156     {
       
  4157     // Bottom by default.
       
  4158     AknLayoutUtils::TAknCbaLocation cbaLocation(
       
  4159         AknLayoutUtils::EAknCbaLocationBottom );
       
  4160     
       
  4161     if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  4162         {
       
  4163         //in portrait mode always bottom
       
  4164         return cbaLocation;
       
  4165         }
       
  4166     
       
  4167     TInt currentStatusPaneLayout(
       
  4168         AknStatuspaneUtils::CurrentStatusPaneLayoutResId() );
       
  4169     if ( Layout_Meta_Data::IsPenEnabled() &&
       
  4170          AknStatuspaneUtils::HDLayoutActive() )
       
  4171         {
       
  4172         if ( currentStatusPaneLayout ==
       
  4173                 R_AVKON_WIDESCREEN_PANE_LAYOUT_IDLE_FLAT_NO_SOFTKEYS )
       
  4174             {
       
  4175             // In the fullscreen width landscape flat status pane layout
       
  4176             // the softkeys are on the bottom.
       
  4177             cbaLocation = AknLayoutUtils::EAknCbaLocationBottom;
       
  4178             return cbaLocation;
       
  4179             }
       
  4180         else
       
  4181             {
       
  4182             cbaLocation = AknLayoutUtils::EAknCbaLocationRight;
       
  4183             }
       
  4184         }
       
  4185     
       
  4186     if ( iAvkonAppUi->IsFullScreenApp() )
       
  4187         {
       
  4188         //it means this is a normal application
       
  4189         if ( !iAvkonAppUi->StatusPane() )
       
  4190             {
       
  4191             //no status pane
       
  4192             return cbaLocation;
       
  4193             }
       
  4194         
       
  4195         if ( currentStatusPaneLayout == R_AVKON_STATUS_PANE_LAYOUT_EMPTY )
       
  4196             {
       
  4197             //or status pane layout is empty
       
  4198             return cbaLocation;         
       
  4199             }
       
  4200         
       
  4201         if( !AknStatuspaneUtils::StaconPaneActive() )
       
  4202             {            
       
  4203             //or Stacon not active
       
  4204             return cbaLocation;
       
  4205             }
       
  4206 
       
  4207         if ( AknStatuspaneUtils::StaconSoftKeysRight() )
       
  4208             {
       
  4209             // Softkey location is always on the right side in
       
  4210             // widescreen status pane layouts.
       
  4211             cbaLocation = AknLayoutUtils::EAknCbaLocationRight;
       
  4212             }
       
  4213         else if ( AknStatuspaneUtils::StaconSoftKeysLeft() )
       
  4214             {
       
  4215             cbaLocation = AknLayoutUtils::EAknCbaLocationLeft;
       
  4216             }
       
  4217         
       
  4218         return cbaLocation;
       
  4219         }
       
  4220 
       
  4221     //else it means this is server application
       
  4222     CAknLayoutConfig::TScreenMode screenMode = CAknSgcClient::ScreenMode();
       
  4223     
       
  4224     TAknPrivSoftkeyLocation privcba = screenMode.SoftkeyLocation();
       
  4225     
       
  4226     switch( privcba )
       
  4227         {
       
  4228         case EAknPrivSoftkeyLocationRight:
       
  4229             cbaLocation = AknLayoutUtils::EAknCbaLocationRight;
       
  4230             break;
       
  4231         case EAknPrivSoftkeyLocationLeft:
       
  4232             cbaLocation = AknLayoutUtils::EAknCbaLocationLeft;
       
  4233             break;
       
  4234         case EAknPrivSoftkeyLocationBottom:
       
  4235             cbaLocation = AknLayoutUtils::EAknCbaLocationBottom;
       
  4236             break;
       
  4237         default:
       
  4238             cbaLocation = AknLayoutUtils::EAknCbaLocationBottom;
       
  4239             break;
       
  4240         }
       
  4241      
       
  4242     return cbaLocation;
       
  4243     }
       
  4244 
       
  4245 
       
  4246 // -----------------------------------------------------------------------------
       
  4247 // AknLayoutUtils::HighlightBasedRect
       
  4248 // -----------------------------------------------------------------------------
       
  4249 //
       
  4250 TRect AknLayoutUtils::HighlightBasedRect( const TRect& aHighlightRect, 
       
  4251                                           CCoeControl* aControl )
       
  4252     {
       
  4253     TAknWindowComponentLayout unitData = AknLayoutScalable_Avkon::aid_value_unit2();
       
  4254     TInt layoytDataUnit = unitData.LayoutLine().iW / 10;
       
  4255 
       
  4256     TRect clientRect;
       
  4257     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, clientRect );
       
  4258     
       
  4259     // Control is allowed to be on top of the status pane but it cannot
       
  4260     // overlay either stacon pane or control pane.
       
  4261     if ( !AknStatuspaneUtils::StaconPaneActive() ) 
       
  4262         {
       
  4263         TRect statusPaneRect;
       
  4264         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, 
       
  4265                                            statusPaneRect );
       
  4266         clientRect.BoundingRect( statusPaneRect );
       
  4267         }
       
  4268 
       
  4269     TPoint location[4];
       
  4270     TInt count( 0 );
       
  4271             
       
  4272     TSize controlSize( aControl->MinimumSize() );
       
  4273     TInt leftX( aHighlightRect.iTl.iX + layoytDataUnit );
       
  4274     TInt rightX( aHighlightRect.iBr.iX - controlSize.iWidth - layoytDataUnit );
       
  4275 
       
  4276 
       
  4277     // If aHighlightRect's width is remarkably smaller than client rect's
       
  4278     // width then assume we're working with a grid. Otherwise list-specific 
       
  4279     // positioning rules are used.
       
  4280     if ( aHighlightRect.Width() < clientRect.Width() / 2 ) // grid
       
  4281         {
       
  4282         count = 4;
       
  4283 
       
  4284         if ( !AknLayoutUtils::LayoutMirrored() )
       
  4285             {
       
  4286             // top left
       
  4287             location[0] = TPoint( leftX, aHighlightRect.iTl.iY - 
       
  4288                                          controlSize.iHeight - layoytDataUnit );
       
  4289             
       
  4290             // bottom left
       
  4291             location[1] = TPoint( leftX, aHighlightRect.iBr.iY + layoytDataUnit );
       
  4292 
       
  4293             // top right
       
  4294             location[2] = TPoint( rightX, aHighlightRect.iTl.iY - 
       
  4295                                           controlSize.iHeight - layoytDataUnit );
       
  4296             
       
  4297             // bottom right
       
  4298             location[3] = TPoint( rightX, aHighlightRect.iBr.iY + layoytDataUnit );
       
  4299             }
       
  4300         else
       
  4301             {
       
  4302             // top right
       
  4303             location[0] = TPoint( rightX, aHighlightRect.iTl.iY - 
       
  4304                                           controlSize.iHeight - layoytDataUnit );
       
  4305             
       
  4306             // bottom right
       
  4307             location[1] = TPoint( rightX, aHighlightRect.iBr.iY + layoytDataUnit );
       
  4308 
       
  4309             // top left
       
  4310             location[2] = TPoint( leftX, aHighlightRect.iTl.iY - 
       
  4311                                          controlSize.iHeight - layoytDataUnit );
       
  4312             
       
  4313             // bottom left
       
  4314             location[3] = TPoint( leftX, aHighlightRect.iBr.iY + layoytDataUnit );
       
  4315             }
       
  4316         }
       
  4317     else // listbox
       
  4318         {
       
  4319         count = 2;
       
  4320         
       
  4321         if ( !AknLayoutUtils::LayoutMirrored() )
       
  4322             {
       
  4323             // top right
       
  4324             location[0] = TPoint( rightX, aHighlightRect.iTl.iY + layoytDataUnit );
       
  4325                 
       
  4326             // bottom right
       
  4327             location[1] = TPoint( rightX, aHighlightRect.iBr.iY - 
       
  4328                                           controlSize.iHeight - layoytDataUnit );
       
  4329             }
       
  4330         else
       
  4331             {
       
  4332             // top left
       
  4333             location[0] = TPoint( leftX, aHighlightRect.iTl.iY + layoytDataUnit );
       
  4334                 
       
  4335             // bottom left
       
  4336             location[1] = TPoint( leftX, aHighlightRect.iBr.iY - 
       
  4337                                          controlSize.iHeight - layoytDataUnit );
       
  4338             }
       
  4339         }
       
  4340 
       
  4341     // loop through all positions and pick up the first suitable one
       
  4342     for ( TInt i = 0; i < count; ++i )
       
  4343         {
       
  4344         if ( clientRect.Contains( location[i] ) &&
       
  4345              clientRect.Contains( location[i] + aControl->Size() ) )
       
  4346             {
       
  4347             return TRect( location[i], controlSize );
       
  4348             }
       
  4349         }
       
  4350 
       
  4351     // None of the possible rectangles was big enough. Simply return the primary
       
  4352     // rectangle.
       
  4353     return TRect( location[0], controlSize );
       
  4354     }
       
  4355 
       
  4356 EXPORT_C AknLayoutUtils::TAknMainPaneState AknLayoutUtils::MainPaneState()
       
  4357 {
       
  4358     AknLayoutUtils::TAknMainPaneState state = AknLayoutUtils::TAknMainPaneState(0);
       
  4359     
       
  4360     if (AknStatuspaneUtils::FlatLayoutActive() && !Layout_Meta_Data::IsLandscapeOrientation())
       
  4361         {
       
  4362         state = AknLayoutUtils::TAknMainPaneState(state | AknLayoutUtils::EAknMainPaneForTinyStatusPane);
       
  4363         }
       
  4364 
       
  4365 
       
  4366     return state;
       
  4367 
       
  4368 }
       
  4369 
       
  4370 EXPORT_C TBool AknLayoutUtils::PenEnabled()
       
  4371     {
       
  4372 #ifdef RD_SCALABLE_UI_V2
       
  4373     return Layout_Meta_Data::IsPenEnabled();
       
  4374 #else    
       
  4375     return EFalse;
       
  4376 #endif // RD_SCALABLE_UI_V2    
       
  4377     }
       
  4378 
       
  4379 EXPORT_C TBool AknLayoutUtils::MSKEnabled()
       
  4380     {
       
  4381     // Check the middle softkey status from CenRep.
       
  4382     // Value will be cached in future.
       
  4383     if ( CEikonEnv::Static()->AppUi() && iAvkonAppUiBase )
       
  4384         {
       
  4385         if ( iAvkonAppUiBase->IsMSKEnabledApp() )
       
  4386             {
       
  4387             return ETrue;
       
  4388             }
       
  4389         }
       
  4390     else // Cached value can't be used - fetch MSK value from CenRep.
       
  4391         {
       
  4392         if ( !Layout_Meta_Data::IsMSKEnabled() )
       
  4393             {
       
  4394             return EFalse; 
       
  4395             }
       
  4396 
       
  4397         TInt MSKenabled( 0 );
       
  4398         CRepository* cenRep = NULL;
       
  4399         TRAPD( err, cenRep = CRepository::NewL( KCRUidAvkon ) );
       
  4400         if ( !err )
       
  4401             {
       
  4402             err = cenRep->Get( KAknMiddleSoftkeyEnabled, MSKenabled );
       
  4403             delete cenRep;
       
  4404             }
       
  4405             
       
  4406         if ( err != KErrNone || MSKenabled == 0 )
       
  4407             {
       
  4408             return EFalse;
       
  4409             }
       
  4410             
       
  4411         return ETrue;
       
  4412         }
       
  4413 
       
  4414     return EFalse;
       
  4415     }
       
  4416 
       
  4417 
       
  4418 EXPORT_C void AknLayoutUtils::GetEdwinVerticalPositionAndHeightFromLines(
       
  4419         TInt aEdwinParent,
       
  4420         const TAknTextLineLayout& aLayout,
       
  4421         TInt aBaselineSeparationOverRide,
       
  4422         TInt aNumberOfLinesToShowOverRide,
       
  4423         TInt& aEdwinVerticalPositionRelativeToParent,
       
  4424         TInt& aEdwinHeight )
       
  4425     {
       
  4426     aEdwinHeight = AknLayoutUtilsHelpers::EdwinHeightFromLines(
       
  4427         aEdwinParent, 
       
  4428         aLayout,
       
  4429         aBaselineSeparationOverRide,
       
  4430         aNumberOfLinesToShowOverRide,
       
  4431         aEdwinVerticalPositionRelativeToParent );
       
  4432     }
       
  4433        
       
  4434 EXPORT_C TInt AknLayoutUtils::EdwinLinesWithinHeight (
       
  4435         const TAknTextLineLayout& aLayout,
       
  4436         TInt aBaselineSeparationOverride,
       
  4437         TInt aMaxHeight,
       
  4438         TInt& aUsedHeight )
       
  4439     {
       
  4440     return AknLayoutUtilsHelpers::EdwinLinesWithinHeight(
       
  4441         aLayout,
       
  4442         aBaselineSeparationOverride,
       
  4443         aMaxHeight,
       
  4444         aUsedHeight );
       
  4445     }
       
  4446 
       
  4447 EXPORT_C TAknLayoutRect::TAknLayoutRect() : iRect(-666,-666,-666,-666) { }
       
  4448 
       
  4449 EXPORT_C void TAknLayoutRect::LayoutRect(const TRect &aParent, TInt aResourceId)
       
  4450     {
       
  4451     TResourceReader rr;
       
  4452     TRAPD(error,
       
  4453       {
       
  4454       CEikonEnv::Static()->CreateResourceReaderLC(rr, aResourceId);
       
  4455       LayoutRect(aParent, rr);
       
  4456       CleanupStack::PopAndDestroy();
       
  4457       });
       
  4458     if (error != KErrNone)
       
  4459     {
       
  4460     iColor = 0;
       
  4461     iRect = TRect(aParent.iTl, TSize(2,2));
       
  4462     
       
  4463     }
       
  4464 #ifdef AKNUTILS_ENABLE_TRACES
       
  4465     __ASSERT_DEBUG(error == KErrNone, LOGTEXT(_L("TAknLayoutRect: Resource reader failed. Not everything will be drawn correctly")));
       
  4466 #endif // AKNUTILS_ENABLE_TRACES
       
  4467     }
       
  4468 
       
  4469 
       
  4470 EXPORT_C void TAknLayoutRect::LayoutRect(const TRect &aParent, const AknLayoutUtils::SAknLayoutRect &aL)
       
  4471     {
       
  4472     LayoutRect(aParent, aL.iC,aL.iL, aL.iT, aL.iR, aL.iB, aL.iW, aL.iH);
       
  4473     }
       
  4474 
       
  4475 EXPORT_C void TAknLayoutRect::LayoutRect(const TRect &aParent, const TAknWindowLineLayout &aL)
       
  4476     {
       
  4477     LayoutRect(aParent, aL.iC,aL.il, aL.it, aL.ir, aL.ib, aL.iW, aL.iH);
       
  4478     }
       
  4479 
       
  4480 EXPORT_C void TAknLayoutRect::LayoutRect(const TRect &aParent, TResourceReader &aReader)
       
  4481     {
       
  4482     TInt C = aReader.ReadInt16();
       
  4483     TInt l = aReader.ReadInt16();
       
  4484     TInt t = aReader.ReadInt16();
       
  4485     TInt r = aReader.ReadInt16();
       
  4486     TInt b = aReader.ReadInt16();
       
  4487     TInt W = aReader.ReadInt16();
       
  4488     TInt H = aReader.ReadInt16();
       
  4489     LayoutRect(aParent, C,l,t,r,b,W,H);
       
  4490     }
       
  4491 
       
  4492 EXPORT_C void TAknLayoutRect::LayoutRect(const TRect &aParent, TInt C, TInt l, TInt t, TInt r, TInt b, TInt W, TInt H)
       
  4493     {
       
  4494     if (C == ELayoutEmpty) 
       
  4495             iColor = 0;
       
  4496     else
       
  4497             iColor = C;
       
  4498     iRect = AknLayoutUtils::RectFromCoords(aParent,l,t,r,b,W,H);
       
  4499     }
       
  4500 
       
  4501  EXPORT_C TRect TAknLayoutRect::Rect() const 
       
  4502      {
       
  4503     __ASSERT_DEBUG(iRect != TRect(-666,-666,-666,-666), Panic(EAknPanicLayoutRectNotCalled));
       
  4504      return iRect;
       
  4505      }
       
  4506  TBool TAknLayoutRect::Valid() const
       
  4507      {
       
  4508     return iRect != TRect(-666,-666,-666,-666);
       
  4509      }
       
  4510 
       
  4511 EXPORT_C TRgb TAknLayoutRect::Color() const
       
  4512     {
       
  4513     __ASSERT_DEBUG(iRect != TRect(-666,-666,-666,-666), Panic(EAknPanicLayoutRectNotCalled));
       
  4514     return AKN_LAF_COLOR_STATIC(iColor);
       
  4515     }
       
  4516 
       
  4517 EXPORT_C void TAknLayoutRect::DrawRect(CWindowGc &aGc) const
       
  4518     {
       
  4519     __ASSERT_DEBUG(iRect != TRect(-666,-666,-666,-666), Panic(EAknPanicLayoutRectNotCalled));
       
  4520     aGc.SetBrushColor(AKN_LAF_COLOR_STATIC(iColor));
       
  4521     aGc.Clear(iRect);
       
  4522     }
       
  4523  
       
  4524 EXPORT_C void TAknLayoutRect::DrawOutLineRect(CWindowGc &aGc) const
       
  4525     {
       
  4526     __ASSERT_DEBUG(iRect != TRect(-666,-666,-666,-666), Panic(EAknPanicLayoutRectNotCalled));
       
  4527     aGc.SetBrushColor(0xffffff);
       
  4528     aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
  4529     aGc.SetPenColor(AKN_LAF_COLOR_STATIC(iColor));
       
  4530     aGc.DrawRect(iRect);
       
  4531     aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  4532     }
       
  4533 
       
  4534 EXPORT_C void TAknLayoutRect::DrawImage(CBitmapContext &aGc, CFbsBitmap *aBitmap, CFbsBitmap *aMask) const
       
  4535      {
       
  4536     __ASSERT_DEBUG(iRect != TRect(-666,-666,-666,-666), Panic(EAknPanicLayoutRectNotCalled));
       
  4537 #ifdef AKNUTILS_ENABLE_TRACES
       
  4538     __ASSERT_DEBUG(iRect.Size() == aBitmap->SizeInPixels(), LOGTEXT4(_L("LayoutRect/DrawImage, displayed area and image size does not match: (%d,%d) != (%d,%d)"), iRect.Size().iWidth, iRect.Size().iHeight, aBitmap->SizeInPixels().iWidth, aBitmap->SizeInPixels().iHeight));
       
  4539 #endif // AKNUTILS_ENABLE_TRACES
       
  4540     if (aMask) 
       
  4541         { 
       
  4542         TSize s = iRect.Size();
       
  4543              TRect rect(TPoint(0,0), s);
       
  4544             aGc.BitBltMasked(iRect.iTl, aBitmap, rect, aMask, ETrue); 
       
  4545         }
       
  4546      else
       
  4547         {
       
  4548         aGc.SetClippingRect(iRect);
       
  4549         aGc.BitBlt(iRect.iTl, aBitmap);
       
  4550         aGc.CancelClippingRect();
       
  4551         }
       
  4552     }
       
  4553 
       
  4554 EXPORT_C TAknLayoutText::TAknLayoutText() : iFont(0) { }
       
  4555 
       
  4556 EXPORT_C void TAknLayoutText::LayoutText(const TRect &aParent, TInt aResourceId, const CFont *aCustomFont)
       
  4557     {
       
  4558     TRAPD(error, 
       
  4559       {
       
  4560       TResourceReader rr;
       
  4561       CEikonEnv::Static()->CreateResourceReaderLC(rr, aResourceId);
       
  4562       LayoutText(aParent, rr, aCustomFont);
       
  4563       CleanupStack::PopAndDestroy();
       
  4564       });
       
  4565     if (error != KErrNone)
       
  4566     {
       
  4567     iFont = LatinPlain12();
       
  4568     iTextRect = TRect(aParent.iTl, TSize(aParent.Size().iWidth,2));
       
  4569     iColor = 0;
       
  4570     iAlign = CGraphicsContext::ECenter;
       
  4571     iOffset = 0;
       
  4572     }
       
  4573 #ifdef AKNUTILS_ENABLE_TRACES
       
  4574     __ASSERT_DEBUG(error == KErrNone, LOGTEXT(_L("TAknLayoutText: Resource reader failed. Not everything will be drawn correctly.")));
       
  4575 #endif // AKNUTILS_ENABLE_TRACES
       
  4576     }
       
  4577 
       
  4578 EXPORT_C void TAknLayoutText::LayoutText(const TRect &aParent, const AknLayoutUtils::SAknLayoutText &aL, const CFont *aCustomFont)
       
  4579     {
       
  4580     LayoutText(aParent, aL.iFont, aL.iC, aL.iL, aL.iR, aL.iB, aL.iW, aL.iJ, aCustomFont);
       
  4581     }
       
  4582 
       
  4583 EXPORT_C void TAknLayoutText::LayoutText(const TRect &aParent, const TAknTextLineLayout &aL, const CFont *aCustomFont)
       
  4584     {
       
  4585     LayoutText(aParent, aL.FontId(), aL.iC, aL.il, aL.ir, aL.iB, aL.iW, aL.iJ, aCustomFont);
       
  4586     }
       
  4587 
       
  4588 EXPORT_C void TAknLayoutText::LayoutText(const TRect &aParent, TResourceReader &aReader, const CFont *aCustomFont)
       
  4589     {
       
  4590     TInt fontid = aReader.ReadInt16();
       
  4591     TInt C = aReader.ReadInt16();
       
  4592     TInt lm = aReader.ReadInt16();
       
  4593     TInt rm = aReader.ReadInt16();
       
  4594     TInt B = aReader.ReadInt16();
       
  4595     TInt W = aReader.ReadInt16();
       
  4596     TInt J = aReader.ReadInt16();
       
  4597     LayoutText(aParent, fontid, C, lm, rm, B, W, J, aCustomFont);
       
  4598     }
       
  4599 
       
  4600 EXPORT_C void TAknLayoutText::LayoutText( const TRect &aParent,
       
  4601                                           TInt aFontId,
       
  4602                                           TInt aColor,
       
  4603                                           TInt aLeftMargin,
       
  4604                                           TInt aRightMargin,
       
  4605                                           TInt aBaseLine,
       
  4606                                           TInt aWidth,
       
  4607                                           TInt aJustification,
       
  4608                                           const CFont *aCustomFont )
       
  4609     {
       
  4610     // this is most likely broken if custon font is used!
       
  4611     aBaseLine = AknLayoutUtils::CorrectBaseline(aParent.Height(), aBaseLine, aFontId);
       
  4612 
       
  4613     if (IsParentRelative(aLeftMargin)) { aLeftMargin = aLeftMargin - ELayoutP + aParent.Width(); }
       
  4614     if (IsParentRelative(aRightMargin)) { aRightMargin = aRightMargin - ELayoutP + aParent.Width(); }
       
  4615     if (IsParentRelative(aWidth)) { aWidth = aParent.Width() - ELayoutP + aWidth; }
       
  4616     
       
  4617     if (IsEmpty(aLeftMargin)) { aLeftMargin = aParent.Width() - aRightMargin - aWidth; }
       
  4618     if (IsEmpty(aRightMargin)) { aRightMargin = aParent.Width() - aLeftMargin - aWidth; }
       
  4619     if (IsEmpty(aWidth)) { aWidth = aParent.Width() - aLeftMargin - aRightMargin; }
       
  4620 
       
  4621     TInt fontId = aCustomFont ? EFontCustom : aFontId;
       
  4622     iFont = AknLayoutUtils::FontFromId(fontId, aCustomFont);
       
  4623 
       
  4624     iTextRect = aParent;
       
  4625     iColor = aColor;
       
  4626     iAlign = AknLayoutUtils::TextAlignFromId( aJustification );
       
  4627 
       
  4628     const CAknLayoutFont* layoutFont = CAknLayoutFont::AsCAknLayoutFontOrNull( iFont );
       
  4629     TInt textPaneHeight(0);
       
  4630     TInt textPaneAscent(0);
       
  4631     if ( layoutFont )
       
  4632         {
       
  4633         textPaneHeight = layoutFont->TextPaneHeight();
       
  4634         textPaneAscent = layoutFont->TextPaneTopToBaseline();
       
  4635         }
       
  4636     else
       
  4637         {
       
  4638         textPaneHeight = iFont->HeightInPixels();
       
  4639         textPaneAscent = iFont->AscentInPixels();
       
  4640         }
       
  4641     
       
  4642     // everything is measured from the top down
       
  4643     iOffset = textPaneAscent; // Gives position of baseline relative to top of rectangle, as used in DrawText primitive
       
  4644     iTextRect.iTl.iY += aBaseLine + 1 - iOffset; // +1 for strange series 60 layout def'n of baseline
       
  4645     iTextRect.iBr.iY = iTextRect.iTl.iY + textPaneHeight; // Top to bottom is text pane height
       
  4646     iTextRect.iTl.iX += aLeftMargin;
       
  4647     iTextRect.iBr.iX -= aRightMargin;
       
  4648     }
       
  4649 
       
  4650 
       
  4651 EXPORT_C void TAknLayoutText::DrawText(CGraphicsContext &aGc, const TDesC& aText) const
       
  4652     {
       
  4653     DrawText( aGc, aText, ETrue );
       
  4654     }
       
  4655 
       
  4656 EXPORT_C void TAknLayoutText::DrawText(
       
  4657     CGraphicsContext& aGc,
       
  4658     const TDesC& aText,
       
  4659     TBool aUseLogicalToVisualConversion ) const
       
  4660     {
       
  4661     DrawText(aGc, aText, aUseLogicalToVisualConversion, Color());
       
  4662     }
       
  4663 
       
  4664 EXPORT_C void TAknLayoutText::DrawText(
       
  4665     CGraphicsContext& aGc,
       
  4666     const TDesC& aText,
       
  4667     TBool aUseLogicalToVisualConversion, 
       
  4668     const TRgb &aColor
       
  4669     ) const
       
  4670     {
       
  4671     __ASSERT_DEBUG( iFont, Panic( EAknPanicLayoutTextNotCalled ) );
       
  4672     aGc.UseFont( iFont );
       
  4673     aGc.SetPenColor( aColor );
       
  4674     if ( aText.Length() )
       
  4675         {
       
  4676         HBufC* visualBuf = NULL;
       
  4677         TPtrC text( aText );
       
  4678         
       
  4679         if ( aUseLogicalToVisualConversion )
       
  4680             {
       
  4681             visualBuf = HBufC::New( aText.Length() + KAknBidiExtraSpacePerLine );
       
  4682             
       
  4683             // In OOM, logical to visual conversion is not performed...
       
  4684             
       
  4685             if ( visualBuf )
       
  4686                 {
       
  4687                 *visualBuf = aText; // copy
       
  4688                 TPtr ptr = visualBuf->Des();
       
  4689                 
       
  4690                 TInt maxWidth = iTextRect.Size().iWidth;
       
  4691                 
       
  4692                 // Logical to visual conversion.
       
  4693                 AknBidiTextUtils::ConvertToVisualAndClip(
       
  4694                     aText,
       
  4695                     ptr,
       
  4696                     *iFont,
       
  4697                     maxWidth,
       
  4698                     maxWidth );
       
  4699 
       
  4700                 text.Set( ptr );
       
  4701                 }
       
  4702             }
       
  4703         
       
  4704         // Calculate x-offset based on the used alignment
       
  4705         TInt margin = 0;
       
  4706         if ( iAlign != CGraphicsContext::ELeft )
       
  4707             {
       
  4708             // Measure the full width of the text (ie. what DrawText needs)
       
  4709             TInt textWidth = AknBidiTextUtils::MeasureTextBoundsWidth( *iFont, text,CFont::TMeasureTextInput::EFVisualOrder );
       
  4710             
       
  4711             const TInt extraWidth = iTextRect.Width() - textWidth;
       
  4712             if ( iAlign == CGraphicsContext::ECenter )
       
  4713                 {
       
  4714                 margin = extraWidth / 2;
       
  4715                 }
       
  4716             else // right aligned
       
  4717                 {
       
  4718                 margin = extraWidth;
       
  4719                 }
       
  4720             }
       
  4721 
       
  4722         // Need to make the drawing rectangle bigger to account for underlines
       
  4723         TRect drawRect(iTextRect);
       
  4724         TInt height = drawRect.Height();
       
  4725         // The underline position is not available from the GC. The following code imitates what Symbian CFbsBitGC implements.
       
  4726         // (height-iOffset) is the part below the baseline. Check if it sufficient
       
  4727         TInt extraHeightForUnderlining =   1 + Max(1, height/10)-(height-iOffset);
       
  4728         if ( extraHeightForUnderlining > 0 )
       
  4729             drawRect.iBr.iY += extraHeightForUnderlining;
       
  4730 
       
  4731         aGc.DrawText( text, drawRect, iOffset, CGraphicsContext::ELeft, margin );
       
  4732         delete visualBuf;
       
  4733         }
       
  4734     aGc.DiscardFont(); // Release the font cache    
       
  4735     }
       
  4736 
       
  4737 EXPORT_C TRect TAknLayoutText::TextRect() const
       
  4738     {
       
  4739     __ASSERT_DEBUG(iFont, Panic(EAknPanicLayoutTextNotCalled));
       
  4740     return iTextRect;
       
  4741     }
       
  4742    
       
  4743 TInt TAknLayoutText::BaselineOffset() const
       
  4744     {
       
  4745     __ASSERT_DEBUG(iFont, Panic(EAknPanicLayoutTextNotCalled));
       
  4746     return iOffset;
       
  4747     }
       
  4748 
       
  4749 EXPORT_C void AknDrawWithSkins::DrawWindowShadow(CWindowGc &aGc, const TAknLayoutRect &aCoverRect, const TAknLayoutRect &aSecondShadowRect, const TAknLayoutRect &aFirstShadowRect, const TAknLayoutRect &aOutlineFrameRect, const TAknLayoutRect &aInsideAreaRect, CCoeControl *aControl)
       
  4750     {
       
  4751     MAknsSkinInstance *skin = AknsUtils::SkinInstance();
       
  4752     MAknsControlContext *cc = NULL;
       
  4753     if (aControl) cc = AknsDrawUtils::ControlContext( aControl );
       
  4754 
       
  4755     TBool windowFrameDrawn = EFalse;
       
  4756     TRect windowRect = aCoverRect.Rect();
       
  4757     TAknLayoutRect topLeft;
       
  4758     topLeft.LayoutRect(windowRect, SkinLayout::Popup_windows_skin_placing__frame_general__Line_2());
       
  4759     
       
  4760     TAknLayoutRect bottomRight;
       
  4761     bottomRight.LayoutRect(windowRect, SkinLayout::Popup_windows_skin_placing__frame_general__Line_5());
       
  4762     
       
  4763     TRect outerRect = TRect(topLeft.Rect().iTl, bottomRight.Rect().iBr);
       
  4764     TRect innerRect = TRect(topLeft.Rect().iBr, bottomRight.Rect().iTl);
       
  4765     aGc.SetPenStyle(CGraphicsContext::ENullPen);
       
  4766     const TAknsItemID *frameId = &KAknsIIDQsnFrPopup;
       
  4767     const TAknsItemID *frameCenterId = &KAknsIIDQsnFrPopupCenter;
       
  4768     windowFrameDrawn = AknsDrawUtils::DrawFrame(skin, aGc, outerRect, innerRect, *frameId, *frameCenterId);
       
  4769 
       
  4770     if (!windowFrameDrawn)
       
  4771         {
       
  4772 //    TInt x0 = aCoverRect.Rect().iTl.iX;
       
  4773 //    TInt x1 = aOutlineFrameRect.Rect().iTl.iX;
       
  4774         TInt x2 = aFirstShadowRect.Rect().iTl.iX;
       
  4775         TInt x3 = aSecondShadowRect.Rect().iTl.iX;
       
  4776 
       
  4777 //    TInt y0 = aCoverRect.Rect().iTl.iY;
       
  4778 //    TInt y1 = aOutlineFrameRect.Rect().iTl.iY;
       
  4779         TInt y2 = aFirstShadowRect.Rect().iTl.iY;
       
  4780         TInt y3 = aSecondShadowRect.Rect().iTl.iY;
       
  4781 
       
  4782         TInt x4 = aOutlineFrameRect.Rect().iBr.iX;
       
  4783         TInt x5 = aFirstShadowRect.Rect().iBr.iX;
       
  4784         TInt x6 = aSecondShadowRect.Rect().iBr.iX;
       
  4785 //    TInt x7 = aCoverRect.Rect().iBr.iX;
       
  4786 
       
  4787         TInt y4 = aOutlineFrameRect.Rect().iBr.iY;
       
  4788         TInt y5 = aFirstShadowRect.Rect().iBr.iY;
       
  4789         TInt y6 = aSecondShadowRect.Rect().iBr.iY;
       
  4790 //    TInt y7 = aCoverRect.Rect().iBr.iY;
       
  4791 
       
  4792         aGc.SetBrushColor(aCoverRect.Color());
       
  4793     AknsDrawUtils::Background(skin, cc, aControl, aGc, aCoverRect.Rect());
       
  4794         
       
  4795         AknsDrawUtils::BackgroundBetweenRects( skin, cc, aControl, aGc, TRect(x2,y2,x4-1,y4-1), aInsideAreaRect.Rect()); 
       
  4796         aOutlineFrameRect.DrawOutLineRect(aGc);
       
  4797         aGc.SetBrushColor(aFirstShadowRect.Color());
       
  4798         aGc.Clear(TRect(x2,y4,x5,y5));
       
  4799         aGc.Clear(TRect(x4,y2,x5,y4));
       
  4800         aGc.SetBrushColor(aSecondShadowRect.Color());
       
  4801         aGc.Clear(TRect(x3,y5,x6,y6));
       
  4802         aGc.Clear(TRect(x5,y3,x6,y5));
       
  4803         }
       
  4804     }
       
  4805 
       
  4806 EXPORT_C void AknDraw::DrawWindowShadow(CWindowGc &aGc, 
       
  4807                                         const TAknLayoutRect &aCoverRect, 
       
  4808                                         const TAknLayoutRect &aSecondShadowRect, 
       
  4809                                         const TAknLayoutRect &aFirstShadowRect, 
       
  4810                                         const TAknLayoutRect &aOutlineFrameRect, 
       
  4811                                         const TAknLayoutRect &aInsideAreaRect)
       
  4812     {
       
  4813     AknDrawWithSkins::DrawWindowShadow(aGc, aCoverRect, aSecondShadowRect, aFirstShadowRect, aOutlineFrameRect, aInsideAreaRect, NULL);
       
  4814     }
       
  4815 
       
  4816 static void DrawEmptyListImpl_real( const TRect &aClientRect,
       
  4817                                     CWindowGc &aGc,
       
  4818                                     TPtrC text,
       
  4819                                     CCoeControl *aControl = NULL,
       
  4820                                     TBool aSettingPageList = EFalse );
       
  4821                                   
       
  4822 
       
  4823 // Drawing with skins support.
       
  4824 EXPORT_C
       
  4825 void AknDrawWithSkins::DrawEmptyListWithFind( const TRect &/*aClientRect_1*/,
       
  4826                                               CWindowGc &aGc,
       
  4827                                               TPtrC text,
       
  4828                                               CCoeControl *aControl )
       
  4829     {
       
  4830     // this method is called when a list with fixed find is used.
       
  4831     // should pass info on find further on up the road, but
       
  4832     // that makes no sense since laf is brain damaged
       
  4833     DrawEmptyListImpl_real( TRect(0,0,0,0), aGc, text, aControl );
       
  4834     }
       
  4835 
       
  4836 EXPORT_C void AknDrawWithSkins::DrawEmptyListHeading(const TRect &aClientRect, CWindowGc& aGc, TPtrC aText, CCoeControl *aControl)
       
  4837     {
       
  4838     DrawEmptyListImpl_real( aClientRect, aGc, aText, aControl );
       
  4839     }
       
  4840 
       
  4841 EXPORT_C void AknDrawWithSkins::DrawEmptyListForSettingPage(const TRect &aRect, CWindowGc &aGc, TPtrC text, CCoeControl *aControl)
       
  4842     {
       
  4843     if ( aControl && aControl->FindBackground() )
       
  4844         {        
       
  4845 		DrawEmptyListImpl_real(  aRect, aGc, text, NULL, ETrue);        
       
  4846         return;
       
  4847         }
       
  4848 
       
  4849     DrawEmptyListImpl_real( aRect, aGc, text, aControl, ETrue);
       
  4850     }
       
  4851 
       
  4852 EXPORT_C void AknDrawWithSkins::DrawEmptyList(const TRect& /*aClientRect_1*/, CWindowGc &aGc, TPtrC text, CCoeControl *aControl)
       
  4853     {
       
  4854     DrawEmptyListImpl_real( TRect(0,0,0,0),
       
  4855                             aGc,
       
  4856                             text,
       
  4857                             aControl );
       
  4858     }
       
  4859 
       
  4860 
       
  4861 // Plain drawing without skins
       
  4862 
       
  4863 EXPORT_C void AknDraw::DrawEmptyListWithFind(const TRect &aClientRect_1, CWindowGc &aGc, TPtrC text)
       
  4864     {
       
  4865     AknDrawWithSkins::DrawEmptyListWithFind(aClientRect_1, aGc, text, NULL);
       
  4866     }
       
  4867 
       
  4868 EXPORT_C void AknDraw::DrawEmptyListHeading(const TRect &aClientRect, CWindowGc& aGc, TPtrC aText)
       
  4869     {
       
  4870     AknDrawWithSkins::DrawEmptyListHeading(aClientRect, aGc, aText, NULL);
       
  4871     }
       
  4872 
       
  4873 EXPORT_C void AknDraw::DrawEmptyListForSettingPage(const TRect &aRect, CWindowGc &aGc, TPtrC text)
       
  4874     {
       
  4875     AknDrawWithSkins::DrawEmptyListForSettingPage(aRect, aGc, text, NULL);
       
  4876     }
       
  4877 
       
  4878 
       
  4879 EXPORT_C void AknDraw::DrawEmptyList(const TRect &aClientRect_1, CWindowGc &aGc, TPtrC text)
       
  4880     {
       
  4881     AknDrawWithSkins::DrawEmptyList(aClientRect_1, aGc, text, NULL);
       
  4882     }
       
  4883 
       
  4884 /* should be deprecated */
       
  4885 EXPORT_C void AknDraw::DrawEmptyListImpl(const TRect &aClientRect, CWindowGc &aGc, TPtrC text, TInt /*line1layout*/, TInt /*line2layout*/)
       
  4886     {
       
  4887     DrawEmptyListImpl_real( aClientRect, aGc, text );
       
  4888     }
       
  4889 
       
  4890 TBool DrawEmptyListImpl_real_DrawBg( CWindowGc &aGc,
       
  4891                                      CCoeControl *aControl,
       
  4892                                      TBool /*aSettingPageList*/ )
       
  4893     
       
  4894     {
       
  4895     // Clearing area
       
  4896     TRect mainPane; 
       
  4897     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPane );
       
  4898     // aItemTextRect is list item's rect, width of which is smaller than width of the list
       
  4899     // with a scroll bar. List needs to draw under scroll bar anyway, so we need to
       
  4900     // modify given rect here.
       
  4901     TRect mainPaneRect( mainPane.Size() );  
       
  4902     
       
  4903     MAknsSkinInstance *skin = AknsUtils::SkinInstance();
       
  4904     MAknsControlContext *cc = NULL; 
       
  4905     TBool owned = EFalse;
       
  4906 
       
  4907     if (aControl)
       
  4908         {
       
  4909         cc = AknsDrawUtils::ControlContext( aControl );
       
  4910         }
       
  4911 
       
  4912     if (!cc) 
       
  4913         {
       
  4914         TRAPD(error,
       
  4915             {
       
  4916             const TAknsItemID *id = &KAknsIIDNone;  
       
  4917             if (AknsUtils::AvkonSkinEnabled())
       
  4918                 {
       
  4919                 cc = CAknsListBoxBackgroundControlContext::NewL(
       
  4920                     KAknsIIDQsnBgAreaMainListGene,
       
  4921                     mainPaneRect, EFalse, *id, mainPaneRect );
       
  4922                 }
       
  4923             });
       
  4924         if (error == KErrNone)
       
  4925             {
       
  4926             owned = ETrue;
       
  4927             }
       
  4928         }
       
  4929     
       
  4930     TBool isPopupList( EFalse );
       
  4931     if ( aControl )
       
  4932         {
       
  4933         // unfortunately, there is no other way to check this.
       
  4934         TAknLayoutRect lr;
       
  4935         lr.LayoutRect( mainPane, AknLayoutScalable_Avkon::popup_menu_window( 0 ) );
       
  4936         lr.LayoutRect( lr.Rect(), AknLayoutScalable_Avkon::listscroll_menu_pane( 0 ) );
       
  4937         lr.LayoutRect( lr.Rect(), AknLayoutScalable_Avkon::list_menu_pane( 0 ) );
       
  4938         lr.LayoutRect( lr.Rect(), AknLayoutScalable_Avkon::list_single_pane_cp2( 0 ) );
       
  4939 
       
  4940         if ( aControl->Size().iWidth == lr.Rect().Width() )
       
  4941             {
       
  4942             isPopupList = ETrue;
       
  4943             }
       
  4944 
       
  4945         AknsDrawUtils::Background( skin, cc, aControl, aGc, aControl->Rect(),
       
  4946                                    KAknsDrawParamNoClearUnderImage |
       
  4947                                    KAknsDrawParamBottomLevelRGBOnly );
       
  4948         }
       
  4949     
       
  4950     if (owned)
       
  4951         {
       
  4952         delete cc;
       
  4953         }
       
  4954     
       
  4955     return isPopupList;
       
  4956     }
       
  4957 
       
  4958 void DrawEmptyListImpl_real_DrawUpToTwoLines( CWindowGc &aGc,
       
  4959                                               TPtrC aText,
       
  4960                                               TAknLayoutText &aLine1,
       
  4961                                               TAknLayoutText &aLine2,
       
  4962                                               TInt aLine1length,
       
  4963                                               TInt aLine2length,
       
  4964                                               const CFont* aFont,
       
  4965                                               TRgb aColor,
       
  4966                                               TDes& aBuffer,
       
  4967                                               TBool aPopupList,
       
  4968                                               TRect aParentRect,
       
  4969                                               TBool /*aSettingPageList*/)
       
  4970     {
       
  4971     TRAPD( error,
       
  4972         {
       
  4973         CArrayFix<TInt>* wrapWidthArray = new( ELeave ) CArrayFixFlat<TInt>(10);
       
  4974         CleanupStack::PushL( wrapWidthArray );
       
  4975 
       
  4976         wrapWidthArray->AppendL( aLine1length );
       
  4977         wrapWidthArray->AppendL( aLine2length );
       
  4978         
       
  4979         AknBidiTextUtils::ConvertToVisualAndWrapToStringL( 
       
  4980             aText, *wrapWidthArray, *aFont, aBuffer, ETrue );
       
  4981         
       
  4982         CleanupStack::PopAndDestroy(); // wrapWidthArray
       
  4983         } ); // TRAP end
       
  4984     
       
  4985     if ( error != KErrNone )
       
  4986         {
       
  4987         aBuffer = aText;
       
  4988         }
       
  4989     
       
  4990     // Drawing text
       
  4991     aGc.Reset();
       
  4992     TBool oneline( EFalse );
       
  4993     TPtrC ptr = aBuffer;
       
  4994     TPtrC top = ptr;
       
  4995     TInt off = ptr.Locate('\n');
       
  4996     if ( off >= 0 )
       
  4997         {
       
  4998         top.Set(ptr.Left(off));
       
  4999         ptr.Set(ptr.Mid(off+1));
       
  5000 
       
  5001         TInt off1 = ptr.Locate('\n');
       
  5002         if ( off1 >= 0 )
       
  5003             {
       
  5004             ptr.Set(ptr.Left(off1));
       
  5005             }
       
  5006         else
       
  5007             {
       
  5008             oneline = ETrue;
       
  5009             }
       
  5010         }
       
  5011     
       
  5012     aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
  5013     aGc.SetOpaque( ETrue ); // transparency off
       
  5014 
       
  5015     // no layout exist for popup list - mainpane layout is ok for X
       
  5016     // coords, center vertically.  Also need to calculate vertical
       
  5017     // position for mainpane lists, since laf is broken as designed.
       
  5018     // If you don't believe this, try using laf values in phonebook.
       
  5019     aGc.UseFont( aFont );
       
  5020     aGc.SetPenColor( aColor );
       
  5021     
       
  5022     // center horizontally
       
  5023     CGraphicsContext::TTextAlign textAlign( CGraphicsContext::ECenter );
       
  5024     
       
  5025     // center vertically
       
  5026     TInt h = aParentRect.Height();
       
  5027     TInt lineh = aLine1.TextRect().Height();
       
  5028     TRect r1( aLine1.TextRect() );
       
  5029     TRect r2( aLine2.TextRect() );
       
  5030 
       
  5031     TInt baseLineOffset( aLine1.BaselineOffset() );
       
  5032     
       
  5033     // gap between lines - must be calculated this way, since no other
       
  5034     // way really exists. Could be calculated from layout data, but
       
  5035     // data is wrong, as 1st line is calculated from top of parent
       
  5036     // rect, and 2nd line is calculated from bottom of the parent
       
  5037     // rect. iAvkonAppUi->ClientRect() as parent rect would otherwise
       
  5038     // be ok and give nice results, but in phonebook ClientRect() is
       
  5039     // not what it should be - it is some strange amount too large.
       
  5040     // This can not be fixed unless layout data is fixed to use only
       
  5041     // top marginals.
       
  5042     TInt lineGap( lineh / 6 );
       
  5043 
       
  5044     TInt m;  // // middle point of texts
       
  5045     if ( aPopupList )
       
  5046         {
       
  5047         m = aParentRect.iTl.iY + h / 2;// + lineh + lineGap / 2;
       
  5048         if ( oneline )
       
  5049             {
       
  5050             m += lineh / 2;
       
  5051             }
       
  5052         }
       
  5053     else
       
  5054         {
       
  5055         m = aParentRect.iTl.iY + h / 3 + lineh + lineGap / 2;
       
  5056         }
       
  5057     
       
  5058     TInt b1( m - lineGap / 2 );           // bottom of 1st line
       
  5059     TInt b2( m + lineh + lineGap / 2 );   // botton of 2nd line
       
  5060     
       
  5061     // rects of texts
       
  5062     r1.iTl.iY = b1 - lineh;
       
  5063     r1.iBr.iY = b1;
       
  5064         
       
  5065     r2.iTl.iY = b2 - lineh;
       
  5066     r2.iBr.iY = b2;
       
  5067         
       
  5068     aGc.DrawText( top, r1, baseLineOffset, textAlign );
       
  5069     if ( !oneline )
       
  5070         {
       
  5071         aGc.DrawText( ptr, r2, baseLineOffset, textAlign );
       
  5072         }
       
  5073     
       
  5074     
       
  5075     aGc.DiscardFont();
       
  5076     aGc.SetOpaque( EFalse ); // transparency back on
       
  5077     }    
       
  5078 
       
  5079 void DrawEmptyListImpl_real_DrawMoreThanTwoLines( const TRect &aParentRect,
       
  5080                                                   CWindowGc &aGc,
       
  5081                                                   TPtrC aText,
       
  5082                                                   TRgb aColor,
       
  5083                                                   TDes& buffer )
       
  5084 
       
  5085     {
       
  5086     // fetch layouts
       
  5087     TAknLayoutText line[4];
       
  5088     
       
  5089     line[0].LayoutText( aParentRect, AknLayoutScalable_Avkon::main_pane_empty_t1(2) );
       
  5090     line[1].LayoutText( aParentRect, AknLayoutScalable_Avkon::main_pane_empty_t3(0) );
       
  5091     line[2].LayoutText( aParentRect, AknLayoutScalable_Avkon::main_pane_empty_t4(0) );
       
  5092     line[3].LayoutText( aParentRect, AknLayoutScalable_Avkon::main_pane_empty_t5(0) );
       
  5093 
       
  5094     TInt lineLength[4];
       
  5095     TInt i;
       
  5096     for ( i = 0; i < 4; i++ )
       
  5097         {
       
  5098         lineLength[i] = line[i].TextRect().Width();
       
  5099         }
       
  5100     
       
  5101     const CFont *bigFont = line[0].Font();
       
  5102     const CFont *smallFont = line[1].Font(); 
       
  5103 
       
  5104     // wrap text
       
  5105     TInt off = aText.Locate('\n');
       
  5106     TPtrC rest( aText );
       
  5107     rest.Set( aText.Right(aText.Length() - off - 1 ));
       
  5108 
       
  5109     HBufC* firstLine = NULL;
       
  5110     
       
  5111     TRAPD( error1, 
       
  5112             {
       
  5113             firstLine = HBufC::NewL(
       
  5114                 aText.Left(off).Length() + KAknBidiExtraSpacePerLine );
       
  5115             });
       
  5116 
       
  5117     if (error1 == KErrNone)
       
  5118         {
       
  5119         TPtr firstLinePtr = firstLine->Des();
       
  5120         AknBidiTextUtils::ConvertToVisualAndClip(
       
  5121                                 aText.Left(off),
       
  5122                                 firstLinePtr,
       
  5123                                 *bigFont,
       
  5124                                 lineLength[0],
       
  5125                                 lineLength[0] );
       
  5126         }
       
  5127     
       
  5128     TRAPD( error2,
       
  5129         {
       
  5130         CArrayFix<TInt>* wrapWidthArray = new( ELeave ) CArrayFixFlat<TInt>(10);
       
  5131         CleanupStack::PushL( wrapWidthArray );
       
  5132         
       
  5133         // wrap small font lines
       
  5134         wrapWidthArray->Reset();
       
  5135         for ( i = 1; i <= 3; i++ )
       
  5136             {
       
  5137             wrapWidthArray->AppendL( lineLength[i] );
       
  5138             }
       
  5139         
       
  5140         AknBidiTextUtils::ConvertToVisualAndWrapToStringL( 
       
  5141             rest, *wrapWidthArray, *smallFont, buffer, ETrue );
       
  5142         
       
  5143         CleanupStack::PopAndDestroy(); // wrapWidthArray
       
  5144         } ); // TRAP end
       
  5145     
       
  5146     
       
  5147     TPtrC ptr[4];
       
  5148     TInt n = 0;
       
  5149     
       
  5150     if (error1 == KErrNone)
       
  5151         {
       
  5152         ptr[0].Set( firstLine->Des() );
       
  5153         }
       
  5154     if ( error1 != KErrNone || error2 != KErrNone )
       
  5155         {
       
  5156         ptr[0].Set(aText.Left(off));
       
  5157         }
       
  5158     else
       
  5159         {
       
  5160         TInt newlines[3];
       
  5161         n = 0;
       
  5162         for ( i = 0; i < buffer.Length(); i++ )
       
  5163             {
       
  5164             if ( buffer[i] != '\n' )
       
  5165                 {
       
  5166                 continue;
       
  5167                 }
       
  5168             newlines[n] = i;
       
  5169             
       
  5170             n++;
       
  5171             if ( n >= 3 )
       
  5172                 {
       
  5173                 break;
       
  5174                 }
       
  5175             }
       
  5176         
       
  5177         if ( n >= 1 )
       
  5178             {
       
  5179             ptr[1].Set( buffer.Left( newlines[0] ) );
       
  5180             }
       
  5181         if ( n >= 2 )
       
  5182             {
       
  5183             ptr[2].Set( buffer.Mid( newlines[0] + 1, newlines[1] - newlines[0] - 1 ) );
       
  5184             }
       
  5185         if ( n >= 3 )
       
  5186             {
       
  5187             ptr[3].Set( buffer.Mid( newlines[1] + 1, newlines[2] - newlines[1] - 1 ) );
       
  5188             }
       
  5189         }
       
  5190     
       
  5191     // draw texts
       
  5192     aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
  5193     aGc.SetOpaque( ETrue ); // transparency off
       
  5194     
       
  5195     for ( i = 0; i < 4; i++ )
       
  5196         {
       
  5197         line[i].DrawText( aGc, ptr[i], EFalse, aColor );
       
  5198         }
       
  5199     aGc.SetOpaque( EFalse ); // transparency back on  
       
  5200     delete firstLine;
       
  5201     }
       
  5202 
       
  5203 void DrawEmptyListImpl_real( const TRect &aClientRect,
       
  5204                              CWindowGc &aGc,
       
  5205                              TPtrC aText,
       
  5206                              CCoeControl *aControl,
       
  5207                              TBool aSettingPageList )
       
  5208     {
       
  5209     TBool popupList = DrawEmptyListImpl_real_DrawBg( aGc, aControl, aSettingPageList );
       
  5210     if ( !aText.Length() )
       
  5211         {
       
  5212         return;
       
  5213         }
       
  5214 
       
  5215     HBufC* hbuf = HBufC::New( aText.Size() + 3 * ( KAknBidiExtraSpacePerLine  +1 )
       
  5216                               + 10 );  // reserve space for newlines
       
  5217     if ( !hbuf )
       
  5218         { // can't really do anything
       
  5219         return;
       
  5220         }
       
  5221 
       
  5222     TPtr buffer(hbuf->Des());
       
  5223     
       
  5224     TRgb color( KRgbBlack );
       
  5225     if ( AknsUtils::AvkonSkinEnabled() )
       
  5226         {
       
  5227         TRgb c;
       
  5228         MAknsSkinInstance *skin = AknsUtils::SkinInstance();
       
  5229         TInt err = AknsUtils::GetCachedColor( skin,
       
  5230                                               c,
       
  5231                                               KAknsIIDQsnTextColors,
       
  5232                                               EAknsCIQsnTextColorsCG6 );
       
  5233         if ( !err )
       
  5234             {
       
  5235             color = c;
       
  5236             }
       
  5237         }
       
  5238 
       
  5239     /*
       
  5240     * input text can be either
       
  5241     * - "line1"
       
  5242     * - "line1 which will be wrapped to 2 lines and truncated with..."
       
  5243     * - "line1\nline2"
       
  5244     * - "line1\nMany other lines which will be wrapped to several lines"
       
  5245     *
       
  5246     * there are 3 layouts
       
  5247     * - 1 line with big font,
       
  5248     * - 2 lines with big font
       
  5249     * - 1 line with big font + 1..3 lines with small font (not for popup lists)
       
  5250     *
       
  5251     *  so first we need to check if given text has a newline,
       
  5252     *  if so, then we need to check if given text fits to 2 lines or
       
  5253     *  should it be split to several small font lines
       
  5254     */
       
  5255 
       
  5256     TInt i, n;
       
  5257     n = 0;
       
  5258     for (i = 0; i < aText.Length(); i ++)
       
  5259         {
       
  5260         if ( aText[i] == '\n' )
       
  5261             {
       
  5262             n++;
       
  5263             }
       
  5264         }
       
  5265 
       
  5266     
       
  5267     TAknTextComponentLayout layout1( AknLayoutScalable_Avkon::main_pane_empty_t1( 0 ) );
       
  5268     TAknTextComponentLayout layout2( AknLayoutScalable_Avkon::main_pane_empty_t2( 0 ) );
       
  5269     TAknLayoutText line1;
       
  5270     TAknLayoutText line2;
       
  5271     TRect clientRect( iAvkonAppUi->ClientRect() );
       
  5272     TRect parentRect;
       
  5273 
       
  5274     if( aSettingPageList )
       
  5275         {
       
  5276         parentRect = aClientRect;
       
  5277         }
       
  5278     else if( aControl )
       
  5279         {
       
  5280         parentRect = aControl->Rect();
       
  5281         }
       
  5282     else
       
  5283         {
       
  5284         parentRect = TRect(0,0,clientRect.Width(),clientRect.Height());
       
  5285         }
       
  5286 
       
  5287     line1.LayoutText( parentRect, layout1 );
       
  5288     TInt line1length = line1.TextRect().Size().iWidth;
       
  5289 
       
  5290     line2.LayoutText( parentRect, layout2 ); 
       
  5291     TInt line2length = line2.TextRect().Size().iWidth;
       
  5292 
       
  5293     const CFont *font = line1.Font();
       
  5294 
       
  5295     if ( n == 0 )
       
  5296         { // one line, or one line which will be wrapped to two
       
  5297         DrawEmptyListImpl_real_DrawUpToTwoLines( aGc, aText, line1, line2,
       
  5298                                                  line1length, line2length,
       
  5299                                                  font, color, buffer,
       
  5300                                                  popupList, parentRect, aSettingPageList );
       
  5301         delete hbuf;
       
  5302         return;
       
  5303         }
       
  5304     
       
  5305     TRAPD( error,
       
  5306         {
       
  5307         CArrayFix<TInt>* wrapWidthArray = new( ELeave ) CArrayFixFlat<TInt>(10);
       
  5308         CleanupStack::PushL( wrapWidthArray );
       
  5309 
       
  5310         wrapWidthArray->AppendL( line1length );
       
  5311         wrapWidthArray->AppendL( line2length );
       
  5312         wrapWidthArray->AppendL( line2length ); // allow wrap to 3 lines
       
  5313         
       
  5314         AknBidiTextUtils::ConvertToVisualAndWrapToStringL(
       
  5315             aText, *wrapWidthArray, *font, buffer, ETrue );
       
  5316 
       
  5317         CleanupStack::PopAndDestroy(); // wrapWidthArray
       
  5318         } ); // TRAP end
       
  5319 
       
  5320     // there is no layout for empty popuplist
       
  5321     if ( error != KErrNone || popupList )
       
  5322         {
       
  5323         DrawEmptyListImpl_real_DrawUpToTwoLines( aGc, aText, line1, line2,
       
  5324                                                  line1length, line2length,
       
  5325                                                  font, color, buffer,
       
  5326                                                  popupList, parentRect, aSettingPageList );
       
  5327         }
       
  5328     else
       
  5329         { // 1 line with big font + 1..3 lines with small font
       
  5330         DrawEmptyListImpl_real_DrawMoreThanTwoLines( parentRect, aGc, aText, color, buffer );
       
  5331         }
       
  5332 
       
  5333     delete hbuf;
       
  5334     }
       
  5335 
       
  5336 
       
  5337 
       
  5338 EXPORT_C TBool AknTextUtils::ClipToFit(TDes& aBuffer, TClipDirection aDir, CEikFormattedCellListBox *aListBox, TInt aItemIndex, TInt aSubCellNumber)
       
  5339     {
       
  5340     CFormattedCellListBoxData *data = aListBox->ItemDrawer()->FormattedCellData();
       
  5341     const CFont *font = data->Font(aListBox->ItemDrawer()->Properties(aItemIndex), aSubCellNumber);
       
  5342     TSize cellsize = data->SubCellSize(aSubCellNumber);
       
  5343     TMargins margin = data->SubCellMargins(aSubCellNumber);
       
  5344     TInt width = cellsize.iWidth - margin.iLeft - margin.iRight;
       
  5345     TInt clipgap = data->SubCellTextClipGap(aSubCellNumber);
       
  5346     return ClipToFit(aBuffer, *font, width, aDir, width + clipgap);
       
  5347     }
       
  5348 
       
  5349 EXPORT_C TBool AknTextUtils::ClipToFit(TDes& aBuffer, TClipDirection aDir, CEikColumnListBox *aListBox, TInt aItemIndex, TInt aColumnNumber)
       
  5350     {
       
  5351     CColumnListBoxData *data = aListBox->ItemDrawer()->ColumnData();
       
  5352     const CFont *font = data->Font(aListBox->ItemDrawer()->Properties(aItemIndex), aColumnNumber);
       
  5353     TInt cellsize = data->ColumnWidthPixel(aColumnNumber);
       
  5354     TMargins margin = data->ColumnMargins(aColumnNumber);
       
  5355     TInt width = cellsize - margin.iLeft - margin.iRight;
       
  5356     TInt clipgap = data->ColumnTextClipGap(aColumnNumber);
       
  5357     return ClipToFit(aBuffer, *font, width, aDir, width + clipgap);
       
  5358     }
       
  5359 
       
  5360 EXPORT_C TBool AknTextUtils::ClipToFit(
       
  5361     TDes& aBuffer,
       
  5362     const CFont& aFont,
       
  5363     TInt aMaxWidthInPixels,
       
  5364     AknTextUtils::TClipDirection aDir,
       
  5365     TInt aClipWidth,
       
  5366     const TDesC& aClipString )
       
  5367     {
       
  5368     TAknLocVariant variants[KAknMaxLocVariants];
       
  5369     TInt numVariants = TAknTextWrapper::GetLocVariants( aBuffer, variants );
       
  5370 
       
  5371     TBool truncated = ETrue;
       
  5372     TInt i = 0;
       
  5373 
       
  5374     TPtr buffer( NULL, 0 );
       
  5375 
       
  5376     while ( i < numVariants && truncated )
       
  5377         {
       
  5378         buffer.Set( NULL, 0, 0 );
       
  5379         TInt length = variants[i].iEnd - variants[i].iStart;
       
  5380         if ( length )
       
  5381             {
       
  5382             buffer.Set( &(aBuffer[variants[i].iStart]), length, length );
       
  5383             }
       
  5384 
       
  5385         truncated = DoClipToFit(
       
  5386             buffer,
       
  5387             aFont,
       
  5388             aMaxWidthInPixels,
       
  5389             aDir,
       
  5390             aClipWidth,
       
  5391             aClipString );
       
  5392 
       
  5393         i++;
       
  5394         }
       
  5395 
       
  5396     // Move the selected variant in the beginning of the target buffer
       
  5397     // or if it is already, set the length correctly.
       
  5398     i--;
       
  5399 
       
  5400     TInt start = variants[i].iStart;
       
  5401 
       
  5402     if ( start > 0 )
       
  5403         {
       
  5404         TPtrC selected = aBuffer.Mid( start, buffer.Length() );
       
  5405         aBuffer.Copy( selected );
       
  5406         }
       
  5407     else
       
  5408         {
       
  5409         aBuffer.SetLength( buffer.Length() );
       
  5410         }
       
  5411 
       
  5412     return truncated;
       
  5413     }
       
  5414 
       
  5415 // -----------------------------------------------------------------------------
       
  5416 // AknTextUtils::DoClipToFit()
       
  5417 // -----------------------------------------------------------------------------
       
  5418 //
       
  5419 TBool AknTextUtils::DoClipToFit(
       
  5420     TDes& aBuffer,
       
  5421     const CFont& aFont,
       
  5422     TInt aMaxWidthInPixels,
       
  5423     AknTextUtils::TClipDirection aDir,
       
  5424     TInt aClipWidth,
       
  5425     const TDesC& aClipString )
       
  5426     {
       
  5427     if ( !aBuffer.Length() )
       
  5428         {
       
  5429         return EFalse;
       
  5430         }
       
  5431 
       
  5432     TInt textWidth = aFont.TextWidthInPixels( aBuffer );
       
  5433 
       
  5434     if ( textWidth <= aMaxWidthInPixels )
       
  5435         {
       
  5436         return EFalse;
       
  5437         }
       
  5438 
       
  5439     TText clipChar = 0;
       
  5440     TInt extraWidth = 0;
       
  5441     if ( aClipString.Length() )
       
  5442         {
       
  5443         clipChar = KDefaultClipChar;
       
  5444         extraWidth = aFont.CharWidthInPixels( clipChar );
       
  5445         }
       
  5446 
       
  5447     if ( aClipWidth == KDefaultClipWidth )
       
  5448         {
       
  5449         aClipWidth = aMaxWidthInPixels;
       
  5450         }
       
  5451 
       
  5452     // Not enough space even for clip char alone - return empty descriptor.
       
  5453     if ( aClipWidth < extraWidth )
       
  5454         {
       
  5455         aBuffer.Zero();
       
  5456         return ETrue;
       
  5457         }
       
  5458 
       
  5459     switch( aDir )
       
  5460         {
       
  5461         case AknTextUtils::EClipFromEnd:
       
  5462             {
       
  5463             TInt cutOff = aFont.TextCount( aBuffer, aClipWidth - extraWidth );
       
  5464 
       
  5465             // This is "avkon rule": should not insert ellipsis right after a space.
       
  5466             if ( cutOff > 1 && 
       
  5467                  aBuffer[cutOff - 1] == ' ' &&
       
  5468                  aBuffer[cutOff - 2] != ' ' )
       
  5469                 {
       
  5470                 cutOff--;
       
  5471                 }
       
  5472             aBuffer.SetLength( cutOff );
       
  5473             if ( aClipString.Length() )
       
  5474                 {
       
  5475                 aBuffer.Append( clipChar );
       
  5476                 }
       
  5477             break;
       
  5478             }
       
  5479 
       
  5480         case AknTextUtils::EClipFromBeginning:
       
  5481             {
       
  5482             TPtrC ptr = aBuffer;
       
  5483 
       
  5484             while ( textWidth > aClipWidth - extraWidth )
       
  5485                 {
       
  5486                 TChar c = ptr[0];
       
  5487                 textWidth -= aFont.CharWidthInPixels( c );
       
  5488                 ptr.Set( ptr.Mid( 1 ) );
       
  5489                 }
       
  5490 
       
  5491             if ( ptr.Length() && ptr[0] == ' ' )
       
  5492                 {
       
  5493                 ptr.Set( ptr.Mid( 1 ) );
       
  5494                 }
       
  5495             aBuffer.Zero();
       
  5496             if ( aClipString.Length() )
       
  5497                 {
       
  5498                 aBuffer.Append( clipChar );
       
  5499                 }
       
  5500             aBuffer.Append( ptr );
       
  5501             break;
       
  5502             }
       
  5503 
       
  5504         case AknTextUtils::EDoNotClip:
       
  5505             break;
       
  5506 
       
  5507         default:
       
  5508             __ASSERT_DEBUG( 0, User::Invariant() );
       
  5509             break;
       
  5510         };
       
  5511 
       
  5512     return ETrue;
       
  5513     }
       
  5514 
       
  5515 /**
       
  5516  *   EXPORTED TEXT WRAPPING METHODS 
       
  5517  */
       
  5518 EXPORT_C void AknTextUtils::WrapToArrayL(
       
  5519         const TDesC& aStringToWrap, 
       
  5520         const CArrayFix<TInt>& aLineWidthArray, 
       
  5521         const CFont& aFont,
       
  5522         CArrayFix<TPtrC>& aWrappedArray ) 
       
  5523     {
       
  5524     TPtr ptr(
       
  5525         (TText*)aStringToWrap.Ptr(),
       
  5526         aStringToWrap.Length(),
       
  5527         aStringToWrap.Length() );
       
  5528 
       
  5529     WrapToArrayL(
       
  5530         ptr,
       
  5531         &aLineWidthArray,
       
  5532         aFont,
       
  5533         aWrappedArray,
       
  5534         0,
       
  5535         0,
       
  5536         AknBidiTextUtils::EImplicit );
       
  5537     }
       
  5538 
       
  5539 EXPORT_C void AknTextUtils::WrapToArrayL(
       
  5540         const TDesC& aStringToWrap, 
       
  5541         TInt aLineWidth, 
       
  5542         const CFont& aFont,
       
  5543         CArrayFix<TPtrC>& aWrappedArray ) 
       
  5544     {
       
  5545     TPtr ptr(
       
  5546         (TText*)aStringToWrap.Ptr(),
       
  5547         aStringToWrap.Length(),
       
  5548         aStringToWrap.Length() );
       
  5549 
       
  5550     WrapToArrayL(
       
  5551         ptr,
       
  5552         NULL,
       
  5553         aFont,
       
  5554         aWrappedArray,
       
  5555         aLineWidth,
       
  5556         0,
       
  5557         AknBidiTextUtils::EImplicit );
       
  5558     }
       
  5559 
       
  5560 EXPORT_C void AknTextUtils::WrapToArrayAndClipL(
       
  5561         TDes& aStringToWrap,             
       
  5562         const CArrayFix<TInt>& aLineWidthArray, 
       
  5563         const CFont& aFont,                    
       
  5564         CArrayFix<TPtrC>& aWrappedArray)      
       
  5565     {
       
  5566     WrapToArrayL(
       
  5567         aStringToWrap,
       
  5568         &aLineWidthArray,
       
  5569         aFont,
       
  5570         aWrappedArray,
       
  5571         0,
       
  5572         TAknTextWrapper::EClip,
       
  5573         AknBidiTextUtils::EImplicit );
       
  5574     }
       
  5575 
       
  5576 EXPORT_C void AknTextUtils::ChopToArrayAndClipL(
       
  5577         TDes& aStringToChop,             
       
  5578         const CArrayFix<TInt>& aLineWidthArray, 
       
  5579         const CFont& aFont,                    
       
  5580         CArrayFix<TPtrC>& aChoppedArray)      
       
  5581     {
       
  5582     AknTextUtils::ChopToArrayAndClipL(
       
  5583         aStringToChop,             
       
  5584         &aLineWidthArray,
       
  5585         aFont,                 
       
  5586         aChoppedArray,
       
  5587         0 );
       
  5588     }
       
  5589 
       
  5590 EXPORT_C void AknTextUtils::ChopToArrayAndClipL(
       
  5591         TDes& aStringToChop,             
       
  5592         TInt aLineWidth, 
       
  5593         const CFont& aFont,                    
       
  5594         CArrayFix<TPtrC>& aChoppedArray )      
       
  5595     {
       
  5596     AknTextUtils::ChopToArrayAndClipL(
       
  5597         aStringToChop,             
       
  5598         NULL,
       
  5599         aFont,                 
       
  5600         aChoppedArray,
       
  5601         aLineWidth );
       
  5602     }
       
  5603 
       
  5604 EXPORT_C void AknTextUtils::WrapToStringL(
       
  5605         const TDesC& aStringToWrap, 
       
  5606         const CArrayFix<TInt>& aLineWidthArray, 
       
  5607         const CFont& aFont, 
       
  5608         TDes& aWrappedString ) 
       
  5609     {
       
  5610     WrapToStringL( 
       
  5611         aStringToWrap,
       
  5612         aLineWidthArray,
       
  5613         aFont,
       
  5614         aWrappedString,
       
  5615         0,
       
  5616         AknBidiTextUtils::EImplicit );
       
  5617     }
       
  5618 
       
  5619 
       
  5620 EXPORT_C void AknTextUtils::WrapToStringAndClipL(
       
  5621         const TDesC& aStringToWrap, 
       
  5622         const CArrayFix<TInt>& aLineWidthArray, 
       
  5623         const CFont& aFont, 
       
  5624         TDes& aWrappedString) 
       
  5625     {
       
  5626     WrapToStringL( 
       
  5627         aStringToWrap,
       
  5628         aLineWidthArray,
       
  5629         aFont,
       
  5630         aWrappedString,
       
  5631         TAknTextWrapper::EClip,
       
  5632         AknBidiTextUtils::EImplicit );
       
  5633     }
       
  5634 
       
  5635 EXPORT_C void AknTextUtils::ReplaceCharacters(TDes &aDes, const TDesC &aChars, TChar aReplacement)
       
  5636     //
       
  5637     // Running time O(aDes.Length() * aChars.Length())
       
  5638     // Does not change length of the string.
       
  5639     // 
       
  5640     {
       
  5641     TInt src = 0;
       
  5642     TInt srclength = aDes.Length();
       
  5643     while(src < srclength)
       
  5644     {
       
  5645     TChar c = aDes[src];
       
  5646     if (aChars.LocateF(c) != KErrNotFound)
       
  5647         aDes[src] = TUint16(aReplacement);
       
  5648     ++src;
       
  5649     }
       
  5650     }
       
  5651 
       
  5652 EXPORT_C void AknTextUtils::PackWhiteSpaces(TDes &aDes, const TDesC &aWhiteSpaceChars)
       
  5653     //
       
  5654     // This one finds several whitespace characters and packs them into one
       
  5655     // character. O(aDes.Length() * aChars.Length())
       
  5656     // 
       
  5657     {
       
  5658     TInt target=0;
       
  5659     TInt src = 0;
       
  5660     TInt srclength = aDes.Length();
       
  5661     TBool lastWasWhiteSpace = EFalse;
       
  5662 
       
  5663     while (src < srclength)
       
  5664     {
       
  5665     aDes[target] = aDes[src];
       
  5666     TChar c = aDes[src];
       
  5667 
       
  5668     TBool currentIsWhiteSpace = aWhiteSpaceChars.LocateF(c) != KErrNotFound;
       
  5669 
       
  5670     if (!( lastWasWhiteSpace && currentIsWhiteSpace ))
       
  5671         ++target;
       
  5672 
       
  5673     ++src;
       
  5674     lastWasWhiteSpace = currentIsWhiteSpace;
       
  5675     }
       
  5676     aDes.SetLength(target);
       
  5677     
       
  5678     }
       
  5679 
       
  5680 EXPORT_C void AknTextUtils::StripCharacters(TDes &aDes, const TDesC &aChars)
       
  5681     {
       
  5682     //
       
  5683     // This algorithm has running time of O(aDes.Length() * aChars.Length()).
       
  5684     //
       
  5685     TInt target=0;
       
  5686     TInt src = 0;
       
  5687     TInt srclength = aDes.Length();
       
  5688     while (src < srclength)
       
  5689     {
       
  5690     aDes[target] = aDes[src];
       
  5691     TChar c = aDes[src];
       
  5692     if (aChars.LocateF(c) == KErrNotFound) 
       
  5693         ++target;
       
  5694     ++src;
       
  5695     }
       
  5696     aDes.SetLength(target);
       
  5697     }
       
  5698 
       
  5699 /** 
       
  5700 * This routine scans the descriptor passed to it, searching for a character that
       
  5701 * is neither space nor ECoCategory nor ECfCategory. 
       
  5702 *
       
  5703 * Currently not exported outside Avkon
       
  5704 */ 
       
  5705 TBool AknTextUtils::IsEmptyText( const TDesC& aTextToTest )
       
  5706     {
       
  5707     TBool ret = EFalse;
       
  5708     for(TInt i = 0; i < aTextToTest.Length(); i++)
       
  5709         {
       
  5710         TChar c (aTextToTest[i]);
       
  5711 
       
  5712         TChar::TCategory cat = c.GetCategory();
       
  5713         if ( !c.IsSpace() && cat != TChar::ECoCategory && cat != TChar::ECfCategory ) 
       
  5714             { // not space and not private use char 
       
  5715             ret = ETrue;
       
  5716             break;
       
  5717             }
       
  5718         }
       
  5719 
       
  5720     return ret;
       
  5721     }
       
  5722 
       
  5723 
       
  5724 static TChar NumberToBase(TChar ch)
       
  5725     {
       
  5726     TDigitType d[] = { EDigitTypeWestern, EDigitTypeArabicIndic, EDigitTypeEasternArabicIndic, EDigitTypeDevanagari, EDigitTypeThai };
       
  5727     TInt i = 0;
       
  5728     TInt num = sizeof(d)/sizeof(d[0]);
       
  5729     while(i<num)
       
  5730         {
       
  5731         if (ch>TChar(d[i]) && ch<TChar(d[i]+10)) { return d[i]; }
       
  5732         i++;
       
  5733         }
       
  5734     return ch;
       
  5735     }
       
  5736 
       
  5737 EXPORT_C void AknTextUtils::LanguageSpecificNumberConversion(TDes &aDes)
       
  5738     {   
       
  5739     if (DigitModeQuery())
       
  5740     {
       
  5741     TLocale locale;
       
  5742     locale.Refresh();
       
  5743     TDigitType d = locale.DigitType();
       
  5744     TChar toArea = 0x030;
       
  5745     switch(d)
       
  5746         {
       
  5747         case EDigitTypeWestern:
       
  5748         case EDigitTypeArabicIndic:
       
  5749         case EDigitTypeEasternArabicIndic:
       
  5750         case EDigitTypeDevanagari:
       
  5751         case EDigitTypeThai:
       
  5752             toArea = d;
       
  5753             break;
       
  5754         case EDigitTypeUnknown:
       
  5755         case EDigitTypeAllTypes:
       
  5756             return;
       
  5757         }
       
  5758     TInt length = aDes.Length();
       
  5759     for(TInt i=0;i<length;i++)
       
  5760         {
       
  5761         TChar ch = aDes[i];
       
  5762         TChar fromArea = NumberToBase(ch);
       
  5763         TChar::TBdCategory cat = ch.GetBdCategory();
       
  5764         switch(cat)
       
  5765             {
       
  5766             case TChar::EArabicNumber:
       
  5767             case TChar::EEuropeanNumber:
       
  5768                 ch += toArea;
       
  5769                 ch -= fromArea;
       
  5770                 aDes[i] = TUint16(ch);
       
  5771                 break;
       
  5772 
       
  5773             default: ; break;
       
  5774             };
       
  5775         }
       
  5776     }
       
  5777 
       
  5778     }
       
  5779 
       
  5780 EXPORT_C void AknTextUtils::ConvertDigitsTo( TDes& aDes, TDigitType aDigitType ) 
       
  5781     {
       
  5782     TChar toArea = aDigitType;
       
  5783     TInt length = aDes.Length();
       
  5784     for(int i=0; i<length; i++) 
       
  5785         {
       
  5786         TChar ch = aDes[i];
       
  5787         TChar base = NumberToBase(ch);
       
  5788         switch (base) 
       
  5789             {
       
  5790             case EDigitTypeWestern:
       
  5791             case EDigitTypeArabicIndic:
       
  5792             case EDigitTypeEasternArabicIndic:
       
  5793             case EDigitTypeDevanagari:
       
  5794             case EDigitTypeThai:
       
  5795                 ch += toArea - base; 
       
  5796                 aDes[i] = TUint16(ch);
       
  5797                 break;
       
  5798             default:
       
  5799                 break;
       
  5800             };
       
  5801         }
       
  5802     }
       
  5803 
       
  5804 /**
       
  5805 * This implementation uses the Avkon setting cache to get the input language and 
       
  5806 * Then puts it through the method provided by the GDI component
       
  5807 *
       
  5808 */
       
  5809 EXPORT_C TBidiText::TDirectionality AknTextUtils::CurrentScriptDirectionality()
       
  5810     {
       
  5811     CAknSettingCache& cache = CAknEnv::Static()->SettingCache();
       
  5812     return TBidiText::ScriptDirectionality( cache.InputLanguage() );
       
  5813     }
       
  5814 
       
  5815 
       
  5816 /**
       
  5817 Derive the digit type for text editor display from the current locale settings and 
       
  5818 current input language.
       
  5819 The digit type should be retrieved on construction and each time the locale settings change.
       
  5820 This implementation is really only handling Arabic at the moment.
       
  5821 */
       
  5822 TDigitType AknTextUtils::InputLanguageFilteredDigitType()
       
  5823     {
       
  5824     TBool useNonLatin = DigitModeQuery(EDigitModeEditorDefault);
       
  5825     TDigitType retDigitType(EDigitTypeWestern);
       
  5826     if (useNonLatin)
       
  5827         {
       
  5828         TLocale locale;
       
  5829         retDigitType = locale.DigitType();
       
  5830         }
       
  5831     return retDigitType;    
       
  5832     }
       
  5833 
       
  5834 /**
       
  5835 Derive the digit type for umeric editors where the localized digit setting must be filtered
       
  5836 to have an appropriate display text language.
       
  5837 This implementation is pretty thorough and should be OK for Farsi, Urdu, Thai as well as Arabic.
       
  5838 */
       
  5839 TDigitType AknTextUtils::DisplayTextLanguageFilteredDigitType()
       
  5840     {
       
  5841     TBool useNonLatin = DigitModeQuery(EDigitModeNumberEditor);
       
  5842     TDigitType retDigitType(EDigitTypeWestern);
       
  5843     if (useNonLatin)
       
  5844         {
       
  5845         TLocale locale;
       
  5846         retDigitType = locale.DigitType();
       
  5847         }
       
  5848     return retDigitType;    
       
  5849     }
       
  5850 /**
       
  5851 * This implementation maps the specification issue that purely numeric editors should filter
       
  5852 * on display text language.
       
  5853 */
       
  5854 EXPORT_C TDigitType AknTextUtils::NumericEditorDigitType()
       
  5855     {
       
  5856     return DisplayTextLanguageFilteredDigitType();
       
  5857     }
       
  5858 
       
  5859 /**
       
  5860 * This implementation maps the specification issue that alphanumeric editors should filter
       
  5861 * on input language.
       
  5862 */
       
  5863 EXPORT_C TDigitType AknTextUtils::TextEditorDigitType()
       
  5864     {
       
  5865     return InputLanguageFilteredDigitType();
       
  5866     }
       
  5867 
       
  5868 /**
       
  5869 * This convenience method converts a display text to presentation form based upon the digit 
       
  5870 * type setting and the current display text language.
       
  5871 */
       
  5872 EXPORT_C void AknTextUtils::DisplayTextLanguageSpecificNumberConversion(TDes &aDes)
       
  5873     {
       
  5874     TDigitType d = DisplayTextLanguageFilteredDigitType();
       
  5875     TChar toArea = d;
       
  5876     const TChar maxDigitTypeChar(0x1000);
       
  5877 
       
  5878     TInt length = aDes.Length();
       
  5879     for(TInt i=0;i<length;i++)
       
  5880         {
       
  5881         TChar ch = aDes[i];
       
  5882         TChar fromArea = NumberToBase(ch);
       
  5883         TChar::TBdCategory cat = ch.GetBdCategory();
       
  5884         switch(cat)
       
  5885             {
       
  5886             case TChar::EArabicNumber:
       
  5887             case TChar::EEuropeanNumber:
       
  5888                 // The max range of DigitType is EDigitTypeThai(= 0x0E50) + 10.
       
  5889                 // No convert the charcter of U+1000 over unicode
       
  5890                 // (e.g. circled digits(U+2460-2473), full-width numbers?iU+FF00-FF10))
       
  5891                 if (maxDigitTypeChar > ch)
       
  5892                     {
       
  5893                     ch += toArea;
       
  5894                     ch -= fromArea;
       
  5895                     aDes[i] = TUint16(ch);
       
  5896                     }
       
  5897                 break;
       
  5898 
       
  5899             default: 
       
  5900 //                  #ifdef RD_HINDI
       
  5901                         if(ch >= 0x0966 && ch <= 0x096F) //Code range for Devanagari Number range. 
       
  5902                         {
       
  5903                             ch += toArea;
       
  5904                                         ch -= fromArea;
       
  5905                         aDes[i] = TUint16(ch);
       
  5906                         }
       
  5907 //                  #endif//RD_HINDI
       
  5908                     
       
  5909              break;
       
  5910             };
       
  5911         }
       
  5912 
       
  5913     }
       
  5914 
       
  5915 // arabic-indic digits are only available in arabic language. (not on hebrew)
       
  5916 static TBool IsArabicLanguage(TLanguage lang) 
       
  5917     {
       
  5918     lang = (TLanguage)((TInt)lang & KAknLanguageMask);
       
  5919     return ((lang == ELangArabic) || (lang == ELangUrdu) || (lang == ELangFarsi)); 
       
  5920     }
       
  5921 static TBool IsDigitTypeArabic(TDigitType dt) { return ((dt == EDigitTypeArabicIndic) || (dt == EDigitTypeEasternArabicIndic)); }
       
  5922 //#ifdef RD_HINDI
       
  5923 static TBool IsIndicLanguage(TLanguage lang)
       
  5924     {
       
  5925     lang = (TLanguage)((TInt)lang & KAknLanguageMask);
       
  5926     TBool ret = EFalse;
       
  5927     if ((lang == ELangHindi)
       
  5928 #ifdef RD_MARATHI
       
  5929         || ( lang == ELangMarathi )
       
  5930 #endif // RD_MARATHI
       
  5931     #ifdef RD_HINDI_PHONETIC_INPUT
       
  5932     || (lang == KLangHindiPhonetic)
       
  5933     #endif
       
  5934     )
       
  5935         ret = ETrue;
       
  5936     return ret;
       
  5937     }
       
  5938 static TBool IsDigitTypeIndic(TDigitType dt) { return dt == EDigitTypeDevanagari; }
       
  5939 //#endif//RD_HINDI
       
  5940 
       
  5941 
       
  5942 EXPORT_C TBool AknTextUtils::DigitModeQuery(TDigitModeQueryType t)
       
  5943     {
       
  5944     CAknSettingCache* settingsCache =   NULL;
       
  5945     // some apps call this from their own threads, so need to check CEikonEnv::Static().
       
  5946     if (CEikonEnv::Static()) settingsCache = &CAknEnv::Static()->SettingCache();
       
  5947     TLocale locale;
       
  5948     locale.Refresh();
       
  5949 
       
  5950     // Collect input for the algorithm to local variables
       
  5951     TLanguage displayLanguage = User::Language(); // UI Language
       
  5952     TLanguage inputLanguage = settingsCache ? settingsCache->InputLanguage() : displayLanguage;
       
  5953     TDigitType digitType = locale.DigitType();
       
  5954 
       
  5955     //Hindi
       
  5956     TBool inputBool;
       
  5957     TBool uiBool;
       
  5958     TBool digitBool;
       
  5959     inputBool = 
       
  5960 //                          #ifdef RD_HINDI
       
  5961                             IsIndicLanguage(inputLanguage)|
       
  5962 //                          #endif //RD_HINDI
       
  5963                             IsArabicLanguage(inputLanguage);
       
  5964     uiBool =        
       
  5965 //                          #ifdef RD_HINDI
       
  5966                             IsIndicLanguage(displayLanguage)|
       
  5967 //                          #endif  //RD_HINDI
       
  5968                             IsArabicLanguage(displayLanguage);
       
  5969     digitBool = 
       
  5970 //                          #ifdef RD_HINDI 
       
  5971                             IsDigitTypeIndic(digitType)|
       
  5972 //                          #endif  //RD_HINDI
       
  5973                             IsDigitTypeArabic(digitType);
       
  5974                             
       
  5975     // Actual work of the method starts here
       
  5976     TBool editor=EFalse, numberEditor=EFalse, changeable=EFalse, display = EFalse;
       
  5977 
       
  5978     if (!inputBool && !uiBool)             { editor = EFalse;                                         display = EFalse; }
       
  5979     if (!inputBool && uiBool && digitBool) { editor = EFalse; numberEditor = ETrue;                   display = ETrue; }
       
  5980     if (!inputBool && uiBool && !digitBool){ editor = EFalse;                                         display = EFalse; }
       
  5981     if (inputBool && uiBool && digitBool)  { editor = ETrue;  numberEditor = ETrue; changeable=ETrue; display = ETrue; }
       
  5982     if (inputBool && uiBool && !digitBool) { editor = EFalse;                       changeable=ETrue; display = EFalse; }
       
  5983     if (inputBool && !uiBool)              { editor = EFalse;                       changeable=ETrue; display = EFalse; }
       
  5984 
       
  5985     // Choose correct output depending on what the caller wants.
       
  5986     TBool result = EFalse;
       
  5987     switch(t)
       
  5988         {
       
  5989         case EDigitModeEditorDefault:
       
  5990             result = editor; 
       
  5991             break;
       
  5992 
       
  5993         case EDigitModeUserModifiableEditor:
       
  5994             result = changeable; 
       
  5995             break;
       
  5996 
       
  5997         case EDigitModeShownToUser:
       
  5998             result = display;
       
  5999             break;
       
  6000 
       
  6001         case EDigitModeNumberEditor:
       
  6002             result = numberEditor; 
       
  6003             break;
       
  6004             
       
  6005         case EDigitModeLatinNumberEditor:
       
  6006             result = EFalse; // conversion is never needed
       
  6007             break;
       
  6008         };
       
  6009     return result;
       
  6010     }
       
  6011 
       
  6012 // LRM = 200e
       
  6013 // RLM = 200f
       
  6014 // LRE = 202a // embedding
       
  6015 // RLE = 202b
       
  6016 // PDF = 202c
       
  6017 // LRO = 202d // override
       
  6018 // RLO = 202e
       
  6019 _LIT( KConvLRE, "\x202a" );
       
  6020 _LIT( KConvRLE, "\x202b" );
       
  6021 _LIT( KConvPDF, "\x202c" );
       
  6022 _LIT( KConvLRM, "\x200e" );
       
  6023 _LIT( KConvRLM, "\x200f" );
       
  6024 EXPORT_C HBufC* AknTextUtils::ConvertFileNameL(const TDesC& aDes)
       
  6025     {
       
  6026     TPtrC fileName = aDes;
       
  6027     TPtrC extension = _L("");
       
  6028     TInt pos = aDes.Locate(TChar('.'));
       
  6029     if (pos != KErrNotFound && pos > 0)
       
  6030         {
       
  6031         fileName.Set(aDes.Left(pos));
       
  6032         extension.Set(aDes.Mid(pos));
       
  6033         }
       
  6034     HBufC *buf = HBufC::NewL(fileName.Length()+extension.Length()+4);
       
  6035     TPtr bufptr = buf->Des();
       
  6036     TBool found = EFalse;
       
  6037     TBool rtl = TBidiText::TextDirectionality(fileName, &found) == TBidiText::ERightToLeft;
       
  6038     if (!found) 
       
  6039         {
       
  6040         rtl=EFalse;
       
  6041         
       
  6042         // The file name does not contain any strongly directional characters.
       
  6043         // File name is still rendered from the right to left if the
       
  6044         // file name contains arabic or arabic-indic digits with neutral characters.
       
  6045         TInt length = fileName.Length();
       
  6046         TInt ii = 0;
       
  6047         while ((ii < length) && !rtl)
       
  6048             {
       
  6049             TChar c = fileName[ii++];
       
  6050             // GetBdCategory() for arabic-indic digits return value EEuropeanNumber.
       
  6051             // For this reason this method cannot be used for arabic-indic digits.
       
  6052             // Arabic-indic digits start from unicode 0x06f0 and end to unicode 0x06f9
       
  6053             if (c.GetBdCategory() == TChar::EArabicNumber ||
       
  6054                  ( c >= 0x06f0 && c <= 0x06f9 ) )               
       
  6055                 {
       
  6056                 rtl = ETrue;
       
  6057                 }
       
  6058             }
       
  6059         }
       
  6060     
       
  6061     if (rtl) 
       
  6062         {
       
  6063         bufptr.Append(KConvRLE);
       
  6064         }
       
  6065     else 
       
  6066         { 
       
  6067         bufptr.Append(KConvLRE);
       
  6068         }
       
  6069 
       
  6070     bufptr.Append(fileName);
       
  6071     bufptr.Append(KConvPDF);
       
  6072     if (rtl) 
       
  6073         { 
       
  6074         bufptr.Append(KConvRLM);
       
  6075         }
       
  6076     else 
       
  6077         { 
       
  6078         bufptr.Append(KConvLRM);
       
  6079         }
       
  6080     bufptr.Append(extension);
       
  6081     bufptr.Append(KConvPDF); // PDF  
       
  6082     return buf;
       
  6083     }
       
  6084 
       
  6085 
       
  6086 
       
  6087 // AVKON TEXT WRAPPING
       
  6088 
       
  6089 _LIT( KWrapToStringSeparator, "\n" );
       
  6090 
       
  6091 // -----------------------------------------------------------------------------
       
  6092 // AknTextUtils::WrapToStringL()
       
  6093 // -----------------------------------------------------------------------------
       
  6094 
       
  6095 void AknTextUtils::WrapToStringL(
       
  6096     const TDesC& aStringToWrap, 
       
  6097     const CArrayFix<TInt>& aLineWidthArray, 
       
  6098     const CFont& aFont, 
       
  6099     TDes& aWrappedString,
       
  6100     TInt aFlags,
       
  6101     TInt aDirectionality )
       
  6102     {
       
  6103     if ( aWrappedString.MaxLength() < aStringToWrap.Length() )
       
  6104         {
       
  6105         User::Leave( KErrOverflow );
       
  6106         }
       
  6107 
       
  6108     aWrappedString.Copy( aStringToWrap );
       
  6109 
       
  6110     CArrayFixFlat<TPtrC>* wrappedArray =
       
  6111         new( ELeave ) CArrayFixFlat<TPtrC>( 5 );
       
  6112 
       
  6113     CleanupStack::PushL( wrappedArray );
       
  6114 
       
  6115     WrapToArrayL( 
       
  6116         aWrappedString,
       
  6117         &aLineWidthArray,
       
  6118         aFont,
       
  6119         *wrappedArray,
       
  6120         0,
       
  6121         aFlags,
       
  6122         aDirectionality );
       
  6123 
       
  6124     // Here we copy using the same descriptor as source and destination,
       
  6125     // so have to be careful not to overwrite "source" before it is copied.
       
  6126 
       
  6127     TInt count( wrappedArray->Count() );
       
  6128     aWrappedString.Zero();
       
  6129 
       
  6130     // first copy actual lines 
       
  6131 
       
  6132     for ( TInt i = 0 ; i < count ; i++ )
       
  6133         {
       
  6134         aWrappedString.Append( (*wrappedArray)[i] );
       
  6135         }
       
  6136 
       
  6137     // then add newlines
       
  6138 
       
  6139     TInt index( 0 );
       
  6140 
       
  6141     for ( TInt j = 0 ; j < count ; j++ )
       
  6142         {
       
  6143         index += (*wrappedArray)[j].Length();
       
  6144 
       
  6145         if ( index >= aWrappedString.MaxLength() )
       
  6146             {
       
  6147             User::Leave( KErrOverflow );
       
  6148             }
       
  6149 
       
  6150         aWrappedString.Insert( index, KWrapToStringSeparator );
       
  6151         index++;
       
  6152         }
       
  6153 
       
  6154     CleanupStack::PopAndDestroy(); // wrappedArray
       
  6155     }
       
  6156 
       
  6157 // -----------------------------------------------------------------------------
       
  6158 // AknTextUtils::WrapToArrayL()
       
  6159 // -----------------------------------------------------------------------------
       
  6160 
       
  6161 void AknTextUtils::WrapToArrayL( 
       
  6162     TDes& aStringToWrap,
       
  6163     const CArrayFix<TInt>* aLineWidthArray, 
       
  6164     const CFont& aFont,
       
  6165     CArrayFix<TPtrC>& aWrappedArray,
       
  6166     TInt aLineWidth,
       
  6167     TInt aFlags,
       
  6168     TInt aDirectionality )
       
  6169     {
       
  6170     TAknTextWrapper wrapper(
       
  6171         aStringToWrap,
       
  6172         aLineWidthArray,
       
  6173         aFont,
       
  6174         aWrappedArray,
       
  6175         aLineWidth,
       
  6176         aFlags,
       
  6177         (AknBidiTextUtils::TParagraphDirectionality)aDirectionality );
       
  6178 
       
  6179     wrapper.WrapToArrayL();
       
  6180     }
       
  6181 
       
  6182 // -----------------------------------------------------------------------------
       
  6183 // AknTextUtils::ChopToArrayAndClipL()
       
  6184 // -----------------------------------------------------------------------------
       
  6185 
       
  6186 void AknTextUtils::ChopToArrayAndClipL(
       
  6187     TDes& aStringToChop,             
       
  6188     const CArrayFix<TInt>* aLineWidthArray,
       
  6189     const CFont& aFont,                 
       
  6190     CArrayFix<TPtrC>& aChoppedArray,
       
  6191     TInt aLineWidth )
       
  6192     {
       
  6193     TAknTextWrapper wrapper(
       
  6194         aStringToChop,
       
  6195         aLineWidthArray,
       
  6196         aFont,
       
  6197         aChoppedArray,
       
  6198         aLineWidth,
       
  6199         TAknTextWrapper::EClip,
       
  6200         AknBidiTextUtils::EImplicit );
       
  6201 
       
  6202     wrapper.ChopToArrayAndClipL();
       
  6203     }
       
  6204 
       
  6205 EXPORT_C HBufC* AknTextUtils::LoadScalableTextL(CCoeEnv& aCoe, TInt aResourceId)
       
  6206     {   
       
  6207 #ifdef _AKNUTILS_ENABLE_TRACES
       
  6208     LOGTEXT( _L("WARNING: Deprecated method used: AknTextUtils::LoadScalableTextL") );
       
  6209 #endif // AKNUTILS_ENABLE_TRACES
       
  6210     HBufC* ret = LoadScalableTextLC(aCoe,aResourceId);
       
  6211     CleanupStack::Pop();
       
  6212     return ret;
       
  6213     }
       
  6214 
       
  6215 EXPORT_C HBufC* AknTextUtils::LoadScalableTextLC(CCoeEnv& aCoe, TInt aResourceId)
       
  6216     {
       
  6217 #ifdef AKNUTILS_ENABLE_TRACES
       
  6218     LOGTEXT( _L("WARNING: Deprecated method used: AknTextUtils::LoadScalableTextLC") );
       
  6219 #endif // AKNUTILS_ENABLE_TRACES
       
  6220     HBufC* ret = aCoe.AllocReadResourceL(aResourceId);
       
  6221     ret = ClipAccordingScreenOrientationLC(aCoe, ret);
       
  6222     return ret;
       
  6223     }
       
  6224 
       
  6225 EXPORT_C TInt AknTextUtils::LoadScalableText(CCoeEnv& aCoe, TInt aResourceId, TDes& aBuffer ) 
       
  6226     {
       
  6227 #ifdef AKNUTILS_ENABLE_TRACES
       
  6228     LOGTEXT( _L("WARNING: Deprecated method used: AknTextUtils::LoadScalableText") );
       
  6229 #endif // AKNUTILS_ENABLE_TRACES
       
  6230 
       
  6231     HBufC* temp = 0;
       
  6232     TRAPD( result, temp = LoadScalableTextL(aCoe,aResourceId) );
       
  6233     if (result == KErrNone)
       
  6234         {
       
  6235         aBuffer.Zero();
       
  6236         aBuffer.Append(temp->Length() > aBuffer.Length()?temp->Des().Left(aBuffer.Length()-1):temp->Des());
       
  6237         }
       
  6238     delete temp;
       
  6239     return result;
       
  6240     }
       
  6241 
       
  6242 EXPORT_C HBufC* AknTextUtils::ClipAccordingScreenOrientationLC(CCoeEnv& aCoe, HBufC* aBuf) 
       
  6243     {
       
  6244 #ifdef AKNUTILS_ENABLE_TRACES
       
  6245     LOGTEXT( _L("WARNING: Deprecated method used: AknTextUtils::ClipAccordingScreenOrientationLC") );
       
  6246 #endif // AKNUTILS_ENABLE_TRACES
       
  6247 
       
  6248     CleanupStack::PushL(aBuf);
       
  6249     TInt separatorPos = aBuf->Des().Locate('|');
       
  6250     if (separatorPos != KErrNotFound )
       
  6251         {
       
  6252         // solve screen orientation
       
  6253         CAknAppUiBase::TAppUiOrientation screenOrientation= ((CAknAppUiBase*)aCoe.AppUi())->Orientation();
       
  6254         if ( screenOrientation == CAknAppUiBase::EAppUiOrientationLandscape 
       
  6255              && separatorPos != aBuf->Length() )
       
  6256             {
       
  6257             aBuf=aBuf->Des().Right(separatorPos+1).AllocL();
       
  6258             }
       
  6259         else
       
  6260             {
       
  6261             aBuf=aBuf->Des().Left(separatorPos).AllocL();            
       
  6262             }
       
  6263         CleanupStack::PopAndDestroy(); // old buf
       
  6264         CleanupStack::PushL(aBuf); // resized buffer
       
  6265         }
       
  6266     return aBuf;
       
  6267     }
       
  6268 
       
  6269 // -----------------------------------------------------------------------------
       
  6270 // AknTextUtils::ChooseScalableText
       
  6271 // -----------------------------------------------------------------------------
       
  6272 //  
       
  6273 EXPORT_C TPtrC AknTextUtils::ChooseScalableText(
       
  6274     const TDesC& aText,
       
  6275     const CFont& aFont,
       
  6276     TInt aMaxWidthInPixels )
       
  6277     {
       
  6278     // Get loc variants in an array.
       
  6279     TAknLocVariant variants[KAknMaxLocVariants];
       
  6280     TInt numVariants = TAknTextWrapper::GetLocVariants( aText, variants );
       
  6281 
       
  6282     TInt chosen = KErrNotFound;
       
  6283     TInt chosenWidth = KMinTInt;
       
  6284 
       
  6285     TInt shortest = KErrNotFound;
       
  6286     TInt shortestWidth = KMaxTInt;
       
  6287 
       
  6288     TInt start;
       
  6289 
       
  6290     for ( TInt i = 0 ; i < numVariants ; i++ )
       
  6291         {
       
  6292         start = variants[i].iStart;
       
  6293 
       
  6294         TInt width = aFont.TextWidthInPixels( 
       
  6295             aText.Mid( start, variants[i].iEnd - start ) );
       
  6296 
       
  6297         // Update info of longest fitting one.
       
  6298         if ( width <= aMaxWidthInPixels && width > chosenWidth )
       
  6299             {
       
  6300             chosen = i;
       
  6301             chosenWidth = width;
       
  6302             }
       
  6303 
       
  6304         // Update info of shortest one.
       
  6305         if ( width < shortestWidth )
       
  6306             {
       
  6307             shortest = i;
       
  6308             shortestWidth = width;
       
  6309             }
       
  6310         }
       
  6311 
       
  6312     // If none of the variants fits, return the shortest one in pixels.
       
  6313     if ( chosen < 0 )
       
  6314         {
       
  6315         chosen = shortest;
       
  6316         }
       
  6317 
       
  6318     start = variants[chosen].iStart;
       
  6319     return aText.Mid( start, variants[chosen].iEnd - start );
       
  6320     }
       
  6321 
       
  6322 /**
       
  6323 * CompletePathWithAppPath
       
  6324 *   All the components that are specified in the given descriptor (drive letter,
       
  6325 *   path and file name, including extension) are put into the result;
       
  6326 *   any missing components (path and drive letter) are taken from the app's path.
       
  6327 *
       
  6328 *   Can be used e.g. to load a bitmap file when an application don't know where
       
  6329 *   it has been installed.
       
  6330 *
       
  6331 *   Example1:
       
  6332 *        TFilename fname = _L("\testdir\pics.mbm"); // Use _LIT instead
       
  6333 *        CompletePathWithAppPath( fname );
       
  6334 *        Result:
       
  6335 *            fname == "c:\testdir\pics.mbm" if application was installed to c:
       
  6336 *
       
  6337 *   Example2:
       
  6338 *        TFilename fname = _L("pics.mbm"); // Use _LIT instead
       
  6339 *        CompletePathWithAppPath( fname );
       
  6340 *        Result:
       
  6341 *            fname == "c:\system\apps\myapp\pics.mbm" if application was 
       
  6342 *                installed to c:\system\apps\myapp
       
  6343 *
       
  6344 */
       
  6345 EXPORT_C TInt CompleteWithAppPath( TDes& aFileName )
       
  6346     {
       
  6347     TParse parse;
       
  6348     TInt error = KErrNotSupported;
       
  6349     
       
  6350     CEikonEnv* env = CEikonEnv::Static(); 
       
  6351     if ( env && 
       
  6352         env->EikAppUi() && 
       
  6353         env->EikAppUi()->Document() && 
       
  6354         env->EikAppUi()->Application() )
       
  6355         {
       
  6356         TFileName appName = env->EikAppUi()->Application()->AppFullName();
       
  6357         // Remove app name and extension
       
  6358         TParsePtr appNamePtr(appName);
       
  6359         appName = appNamePtr.DriveAndPath();
       
  6360         error = parse.Set( aFileName, &appName, NULL);
       
  6361         if ( !error )
       
  6362             {
       
  6363             aFileName.Zero();
       
  6364             aFileName.Append( parse.FullName() );
       
  6365             }
       
  6366         }
       
  6367 
       
  6368     return error;
       
  6369     }
       
  6370 
       
  6371 EXPORT_C void AknEditUtils::ConstructEditingL(CEikEdwin* aEdwin, 
       
  6372                                               TInt aEditingSpace, 
       
  6373                                               TInt aEditingWindow, 
       
  6374                                               TInt aCharacterCase, 
       
  6375                                               TInt aJustification, 
       
  6376                                               TBool aAllowedToMoveInsertionPoint, 
       
  6377                                               TBool aCursorYesNo, 
       
  6378                                               TBool aOverflowYesNo,
       
  6379                                               TBool aIsResizable)
       
  6380     {
       
  6381     TMargins8 editorMargins;  
       
  6382     editorMargins.iBottom = 0;
       
  6383     editorMargins.iTop = 0;
       
  6384     editorMargins.iRight = 0;
       
  6385     editorMargins.iLeft = 0;
       
  6386 
       
  6387     aEdwin->SetBorderViewMargins(editorMargins); 
       
  6388     TInt flags = 0;
       
  6389     if (!aCursorYesNo) flags = CEikEdwin::EAvkonDisableCursor;
       
  6390     if (aIsResizable && aEditingWindow != 1) flags |= CEikEdwin::EResizable; // max one row editor should not be resizable
       
  6391 
       
  6392     aEdwin->ConstructL(CEikEdwin::EWidthInPixels|CEikEdwin::ENoAutoSelection|flags, 0, aEditingSpace, aEditingWindow);
       
  6393 
       
  6394     TCharFormat charFormat;
       
  6395     TCharFormatMask formatMask;
       
  6396     CParaFormat paraFormat;
       
  6397     TParaFormatMask paraFormatMask;
       
  6398 
       
  6399     TCursorSelection selection = aEdwin->Selection();
       
  6400     STATIC_CAST(CGlobalText*, aEdwin->Text())->ApplyParaFormatL(&paraFormat,paraFormatMask,selection.LowerPos(),selection.Length());
       
  6401     STATIC_CAST(CGlobalText*, aEdwin->Text())->ApplyCharFormatL(charFormat,formatMask,selection.LowerPos(),selection.Length());
       
  6402 
       
  6403     // Setting editor alignment must be done after
       
  6404     // other editor paragraph formatting
       
  6405     aEdwin->SetAlignment(aJustification);
       
  6406     
       
  6407     aEdwin->SetAknEditorCase( aCharacterCase ); // Argument is no longer and enum
       
  6408     
       
  6409     if ( !aAllowedToMoveInsertionPoint ) 
       
  6410         {        
       
  6411         // No implementation here
       
  6412         }
       
  6413     
       
  6414     if ( aOverflowYesNo ) 
       
  6415         {
       
  6416         // No implementation here
       
  6417         }
       
  6418     }
       
  6419 
       
  6420 static void IsAvailableLanguageL( const TInt aLanguage, TBool& aSupported )
       
  6421     {
       
  6422     aSupported = EFalse;
       
  6423     
       
  6424     CPtiEngine* ptiEngine = CPtiEngine::NewL();
       
  6425     CleanupStack::PushL( ptiEngine );
       
  6426     RArray<TInt> language(6);
       
  6427     CleanupClosePushL( language );
       
  6428     ptiEngine->GetAvailableLanguagesL( language );
       
  6429     for ( int i = 0; i < language.Count(); i++ )
       
  6430         {
       
  6431         if ( language[i] == aLanguage )
       
  6432             {
       
  6433             aSupported = ETrue;
       
  6434             break;
       
  6435             }
       
  6436         }
       
  6437     CleanupStack::PopAndDestroy( &language );
       
  6438     CleanupStack::PopAndDestroy( ptiEngine );
       
  6439     }
       
  6440 
       
  6441 EXPORT_C TInt DefaultInputLanguageFromUILanguage(const TInt aUiLanguage)
       
  6442     {
       
  6443     // Remove operator variant bits
       
  6444     TInt inputLanguage = aUiLanguage & KAknLanguageMask;
       
  6445     TBool supportedLang = EFalse;
       
  6446     
       
  6447     TRAP_IGNORE( IsAvailableLanguageL( inputLanguage, supportedLang ) );
       
  6448     if ( supportedLang )
       
  6449         {
       
  6450         return inputLanguage;
       
  6451         }
       
  6452     
       
  6453     // unknown, use default hard-coded convert code
       
  6454     switch (inputLanguage)
       
  6455         {
       
  6456         case ELangAmerican:
       
  6457         case KLangTaiwanEnglish:
       
  6458         case KLangHongKongEnglish:
       
  6459         case KLangPrcEnglish:
       
  6460         case KLangThaiEnglish:
       
  6461         case KLangApacEnglish:
       
  6462         case KLangIndicEnglish:
       
  6463              inputLanguage = ELangEnglish;
       
  6464              break;
       
  6465         case KLangJapaneseEnglish:
       
  6466              inputLanguage = ELangJapanese;
       
  6467              break;
       
  6468         case ELangBrazilianPortuguese:
       
  6469              inputLanguage = ELangPortuguese;
       
  6470              break;
       
  6471         case ELangCanadianFrench:
       
  6472              inputLanguage = ELangFrench;
       
  6473              break;
       
  6474         case ELangBelgianFlemish:
       
  6475              inputLanguage = ELangDutch;
       
  6476              break;
       
  6477         case ELangLatinAmericanSpanish:
       
  6478              inputLanguage = ELangSpanish;
       
  6479              break;
       
  6480         case KLangApacMalay:
       
  6481              inputLanguage = ELangMalay;
       
  6482              break;
       
  6483         case KLangApacIndonesian:
       
  6484              inputLanguage = ELangIndonesian;
       
  6485              break;
       
  6486         default:
       
  6487              break;
       
  6488         }
       
  6489     return inputLanguage;    
       
  6490     }
       
  6491     
       
  6492 // -----------------------------------------------------------------------------
       
  6493 // SetKeyblockMode
       
  6494 // -----------------------------------------------------------------------------
       
  6495 //
       
  6496 EXPORT_C void SetKeyblockMode( TAknKeyBlockMode aMode )
       
  6497     {
       
  6498     RAknUiServer client;
       
  6499     if ( client.Connect() == KErrNone )
       
  6500         {
       
  6501         client.SetKeyblockMode( (TAknKeySoundOpcode) aMode );
       
  6502         client.Close();
       
  6503         }
       
  6504     }
       
  6505 
       
  6506 // -----------------------------------------------------------------------------
       
  6507 // AknDateTimeUtils::ConvertUtcTimeToHomeTime
       
  6508 // -----------------------------------------------------------------------------
       
  6509 //
       
  6510 EXPORT_C void AknDateTimeUtils::ConvertUtcTimeToHomeTime( TTime& aTime )
       
  6511     {
       
  6512     TTimeIntervalSeconds universalTimeOffset( User::UTCOffset() );
       
  6513     aTime += universalTimeOffset;
       
  6514     }
       
  6515 
       
  6516 // -----------------------------------------------------------------------------
       
  6517 // AknLangUtils::DisplayLanguageTagL
       
  6518 // -----------------------------------------------------------------------------
       
  6519 //
       
  6520 EXPORT_C HBufC* AknLangUtils::DisplayLanguageTagL()
       
  6521     {
       
  6522     HBufC* tag = StringLoader::LoadL( R_QTN_LANGUAGE_RFC3066_TAG, CEikonEnv::Static() );
       
  6523     return tag;
       
  6524     }
       
  6525 
       
  6526 // -----------------------------------------------------------------------------
       
  6527 // AknLangUtils::UserLanguage
       
  6528 // -----------------------------------------------------------------------------
       
  6529 //
       
  6530 TLanguage AknLangUtils::UserLanguage()
       
  6531     {
       
  6532     return (TLanguage)(User::Language() & KAknLanguageMask);
       
  6533     }
       
  6534 
       
  6535 // -----------------------------------------------------------------------------
       
  6536 // AknPopupUtils::Position
       
  6537 // -----------------------------------------------------------------------------
       
  6538 //
       
  6539 EXPORT_C TPoint AknPopupUtils::Position( const TSize& aSize, 
       
  6540         TBool aSoftkeysVisible )
       
  6541     {
       
  6542     TAknLayoutRect layoutRect;
       
  6543     layoutRect.LayoutRect( TRect(), AknLayoutScalable_Avkon::Screen( 0 ) );
       
  6544     
       
  6545     TRect screen( layoutRect.Rect() );
       
  6546     
       
  6547     TInt x = ( screen.Width() - aSize.iWidth ) >> 1;
       
  6548     TInt y = screen.Height() - aSize.iHeight;
       
  6549 
       
  6550     // Popups are centered on y-axis if screen orientation is landscape or
       
  6551     // softkeys are not visible.
       
  6552     if ( !aSoftkeysVisible || Layout_Meta_Data::IsLandscapeOrientation() )
       
  6553         {
       
  6554         y >>= 1; 
       
  6555         }
       
  6556 
       
  6557     return TPoint( x, y );
       
  6558     }
       
  6559 
       
  6560 
       
  6561 // -----------------------------------------------------------------------------
       
  6562 // AknPopupUtils::Position
       
  6563 // -----------------------------------------------------------------------------
       
  6564 //
       
  6565 EXPORT_C TPoint AknPopupUtils::Position( const TSize& aSize, 
       
  6566         CCoeControl* aControl )
       
  6567     {
       
  6568     TBool softkeys = EFalse;
       
  6569     
       
  6570     if ( aControl )
       
  6571         {
       
  6572         CEikCba* cba = aControl->MopGetObjectNoChaining( cba );
       
  6573 
       
  6574         if ( cba )
       
  6575             {
       
  6576             softkeys = ( cba->IsVisible() && !cba->IsEmpty() );
       
  6577             }
       
  6578         }
       
  6579     
       
  6580     return Position( aSize, softkeys );
       
  6581     }
       
  6582     
       
  6583 // End of file
       
  6584