emailuis/emailui/src/ncspopuplistbox.cpp
changeset 0 8466d47a6819
child 2 5253a20d2a1e
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 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: This file implements classes CNcsPopupListBox, CNcsListItemDrawer. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "emailtrace.h"
       
    21 #include <eikclbd.h>
       
    22 #include <AknsLayeredBackgroundControlContext.h>
       
    23 #include <FreestyleEmailUi.rsg>						// R_FSE_EDITOR_ADDRESS_LIST_REMOTE_LOOKUP_SEARCH
       
    24 #include <StringLoader.h>						// StringLoader
       
    25 #include <CPbkContactEngine.h>
       
    26 #include <aknnotewrappers.h>					//For LanguageNotSupported errorNote
       
    27 
       
    28 #include "ncspopuplistbox.h"
       
    29 #include "ncsemailaddressobject.h"					// CNcsEmailAddressObject
       
    30 #include "ncsconstants.h"
       
    31 #include "ncsheadercontainer.h"						// CNcsHeaderContainer
       
    32 #include "FreestyleEmailUiContactHandler.h"		// CFSEmailUiClsListsHandler
       
    33 #include "ncsutility.h"
       
    34 #include "FreestyleEmailUiUtilities.h"
       
    35 #include "FreestyleEmailUiAppui.h"
       
    36 #include "FreestyleEmailUiLayoutHandler.h"
       
    37 #include "FSDelayedLoader.h"
       
    38 #include "FreestyleEmailUiCLSItem.h"
       
    39 
       
    40 // ========================= MEMBER FUNCTIONS ==================================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CNcsPopupListBox::NewL
       
    44 // -----------------------------------------------------------------------------
       
    45 CNcsPopupListBox* CNcsPopupListBox::NewL( const CCoeControl* aParent, 
       
    46                                           CFSMailBox& aMailBox, 
       
    47                                           CNcsHeaderContainer& aHeaderContainer, 
       
    48                                           TBool aRemoteLookupSupported  )
       
    49 	{
       
    50     FUNC_LOG;
       
    51 	CNcsPopupListBox* self = 
       
    52 	    new (ELeave) CNcsPopupListBox( aHeaderContainer, aRemoteLookupSupported, aMailBox );
       
    53 	CleanupStack::PushL( self );
       
    54 	self->ConstructL( aParent );
       
    55 	CleanupStack::Pop( self );
       
    56 	return self;
       
    57 	}
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CNcsPopupListBox::CNcsPopupListBox
       
    61 // -----------------------------------------------------------------------------
       
    62 CNcsPopupListBox::CNcsPopupListBox( CNcsHeaderContainer& aHeaderContainer, 
       
    63                                     TBool aRemoteLookupSupported, 
       
    64                                     CFSMailBox& aMailBox)
       
    65 	: iHeaderContainer( aHeaderContainer ),iMailBox( aMailBox ),
       
    66 	  iRemoteLookupSupported( aRemoteLookupSupported ),iCachingInProgress( EFalse )
       
    67     {
       
    68     FUNC_LOG;
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CNcsPopupListBox::ConstructL
       
    73 // -----------------------------------------------------------------------------
       
    74 void CNcsPopupListBox::ConstructL( const CCoeControl* aParent )
       
    75     {
       
    76     FUNC_LOG;
       
    77     CEikTextListBox::ConstructL( aParent, CEikListBox::EPopout );
       
    78     CreateScrollBarFrameL();
       
    79 
       
    80 	CEikTextListBox::SetBorder( TGulBorder::ESingleGray );
       
    81 
       
    82 	const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontPrimarySmallFont );
       
    83 	CEikTextListBox::SetItemHeightL( font->HeightInPixels() + 8 );
       
    84 
       
    85     iBaseBackroundContext = CAknsBasicBackgroundControlContext::NewL( 
       
    86     	KAknsIIDQgnFsGrafEmailContent, 
       
    87     	Rect(), 
       
    88     	EFalse );
       
    89 	iContactHandler = CFsDelayedLoader::InstanceL()->GetContactHandlerL();
       
    90 	if ( !iContactHandler->IsLanguageSupportedL() )
       
    91 		{
       
    92 		iContactHandler = NULL;
       
    93 		}
       
    94 	
       
    95 	iAppUi =  static_cast<CFreestyleEmailUiAppUi*>(iEikonEnv->AppUi()); //<cmail>
       
    96 	
       
    97     // <cmail>
       
    98     SetListBoxObserver( this );
       
    99     // </cmail>
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CNcsPopupListBox::InitAndSearchL
       
   104 // -----------------------------------------------------------------------------
       
   105 void CNcsPopupListBox::InitAndSearchL( const TDesC& aText )
       
   106 	{
       
   107     FUNC_LOG;
       
   108  	SetSearchTextL( aText );
       
   109  	RPointerArray<CFSEmailUiClsItem> emptyArray;
       
   110  	CleanupClosePushL( emptyArray );
       
   111 	OperationCompleteL( ESearchContacts, emptyArray );
       
   112 	CleanupStack::PopAndDestroy( &emptyArray );
       
   113 	}
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CNcsPopupListBox::~CNcsPopupListBox
       
   117 // ---------------------------------------------------------------------------
       
   118 CNcsPopupListBox::~CNcsPopupListBox()
       
   119     {
       
   120     FUNC_LOG;
       
   121     delete iBaseBackroundContext;
       
   122 	delete iItemTextsArray;
       
   123 	delete iCurrentSearchText;
       
   124 	iMatchingItems.ResetAndDestroy();
       
   125 	}
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CNcsPopupListBox::CreateItemDrawerL
       
   129 // -----------------------------------------------------------------------------
       
   130 void CNcsPopupListBox::CreateItemDrawerL()
       
   131 	{
       
   132     FUNC_LOG;
       
   133 	CNcsListItemDrawer* drawer = new (ELeave) CNcsListItemDrawer( *this );
       
   134 	iItemDrawer = drawer;
       
   135 	}
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CNcsPopupListBox::MopSupplyObject
       
   139 // -----------------------------------------------------------------------------
       
   140 TTypeUid::Ptr CNcsPopupListBox::MopSupplyObject(TTypeUid aId)
       
   141     {
       
   142     FUNC_LOG;
       
   143     if ( aId.iUid == MAknsControlContext::ETypeId )
       
   144         {
       
   145         return MAknsControlContext::SupplyMopObject( aId, iBaseBackroundContext );
       
   146         }
       
   147     return CCoeControl::MopSupplyObject( aId );
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CNcsPopupListBox::SizeChanged
       
   152 // -----------------------------------------------------------------------------
       
   153 void CNcsPopupListBox::SizeChanged()
       
   154     {
       
   155     FUNC_LOG;
       
   156     CEikTextListBox::SizeChanged();
       
   157     iBaseBackroundContext->SetRect( Rect() );
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CNcsPopupListBox::OfferKeyEventL
       
   162 // -----------------------------------------------------------------------------
       
   163 //    
       
   164 TKeyResponse CNcsPopupListBox::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   165     {
       
   166     FUNC_LOG;
       
   167     TKeyResponse ret( EKeyWasNotConsumed );
       
   168     if( aKeyEvent.iCode == EKeyDownArrow )
       
   169         {
       
   170         MoveRemoteLookupItemL( ERemoteLookupItemDown );
       
   171         iView->MoveCursorL( CListBoxView::ECursorNextItem, CListBoxView::ENoSelection );
       
   172 		ret = EKeyWasConsumed;
       
   173         } 
       
   174     else if( aKeyEvent.iCode == EKeyUpArrow )
       
   175         {
       
   176 		TBool stay = EFalse;
       
   177         // Move cursor separator line over
       
   178 		if ( CurrentItemIndex() - 1 > 0 && CurrentItemIndex() - 1 == iRemoteLookupItemPos )
       
   179 			{
       
   180 	        MoveRemoteLookupItemL( ERemoteLookupItemUp );
       
   181 	        iView->MoveCursorL( CListBoxView::ECursorPreviousItem, CListBoxView::ENoSelection );
       
   182 			stay = ETrue;
       
   183 			}
       
   184 
       
   185         MoveRemoteLookupItemL( ERemoteLookupItemUp );
       
   186         iView->MoveCursorL( CListBoxView::ECursorPreviousItem, CListBoxView::ENoSelection );
       
   187 	    if( stay )
       
   188 			{
       
   189 	        MoveRemoteLookupItemL( ERemoteLookupItemDown );
       
   190 
       
   191 			iView->MoveCursorL( CListBoxView::ECursorNextItem, CListBoxView::ENoSelection );
       
   192 			}
       
   193 
       
   194 
       
   195     	ret = EKeyWasConsumed;
       
   196         }
       
   197        
       
   198     if( ret == EKeyWasNotConsumed )
       
   199         {
       
   200         ret = CEikListBox::OfferKeyEventL( aKeyEvent, aType );
       
   201         }
       
   202 	// call HandleItemAdditionL just in case. There might be changes on remote lookup item place.
       
   203 	// The call is here, because we don't want to have extra redraw events when the popuplist
       
   204 	// is not fully updated.
       
   205 	HandleItemAdditionL(); 
       
   206     return ret;
       
   207     }
       
   208 
       
   209 // <cmail> Touch
       
   210 // ---------------------------------------------------------------------------
       
   211 // CNcsPopupListBox::HandleListBoxEventL
       
   212 // ---------------------------------------------------------------------------
       
   213 //      
       
   214 void CNcsPopupListBox::HandleListBoxEventL( CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
   215     {
       
   216     if (aEventType == EEventItemClicked)
       
   217         {
       
   218         iHeaderContainer.DoPopupSelectL();
       
   219         }
       
   220     }
       
   221 // </cmail>
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CNcsPopupListBox::OperationComplete
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CNcsPopupListBox::OperationCompleteL( TContactHandlerCmd /*aCmd*/,
       
   228     const RPointerArray<CFSEmailUiClsItem>& aMatchingItems )
       
   229     {
       
   230     FUNC_LOG;
       
   231     iMatchingItems.ResetAndDestroy();
       
   232     // Replace old matcing items.
       
   233 
       
   234     for ( TInt ii = 0; ii < aMatchingItems.Count(); ++ii )
       
   235     	{
       
   236     	if ( aMatchingItems[ii] )
       
   237     		{
       
   238     		CFSEmailUiClsItem* item = aMatchingItems[ii]->CloneLC();  		
       
   239     		iMatchingItems.AppendL( item );
       
   240     		CleanupStack::Pop( item );
       
   241     		}
       
   242     	}
       
   243     
       
   244     UpdateListL();
       
   245     }
       
   246 
       
   247 void CNcsPopupListBox::OperationErrorL( TContactHandlerCmd aCmd, TInt aError )
       
   248 	{
       
   249     FUNC_LOG;
       
   250 	
       
   251 	if ( aCmd == ESearchContacts )
       
   252 		{
       
   253 		// KerrNotReady --> caching in progress, KErrNotFound --> caching not started yet
       
   254 		if ( (aError == KErrNotReady) || (aError == KErrNotFound) )
       
   255 			{
       
   256 			if(!iAppUi->AppUiExitOngoing()) //<cmail>
       
   257 			    TFsEmailUiUtility::ShowInfoNoteL( R_FSE_EDITOR_INFO_BUILDING_CACHE );
       
   258 			iCachingInProgress = ETrue;
       
   259 			}
       
   260 		if ( aError == KErrNone && iCachingInProgress )
       
   261 			{
       
   262 			if(!iAppUi->AppUiExitOngoing()) //<cmail>
       
   263 			    TFsEmailUiUtility::ShowInfoNoteL( R_FSE_EDITOR_INFO_CACHING_COMPLETED );
       
   264 			iCachingInProgress = EFalse;
       
   265 			}
       
   266 		}
       
   267 	}
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CNcsPopupListBox::SetSearchTextL
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 void CNcsPopupListBox::SetSearchTextL( const TDesC& aText )
       
   274     {
       
   275     FUNC_LOG;
       
   276     delete iCurrentSearchText;
       
   277     iCurrentSearchText = NULL;
       
   278     iCurrentSearchText = aText.AllocL();
       
   279     if ( !iCachingInProgress  )
       
   280         {
       
   281         if ( iContactHandler  )
       
   282             {
       
   283             iContactHandler->SearchMatchesL( aText, this, &iMailBox );
       
   284             }
       
   285         }
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CNcsPopupListBox::ReturnCurrentEmailAddressLC
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 CNcsEmailAddressObject* CNcsPopupListBox::ReturnCurrentEmailAddressLC()
       
   293 	{
       
   294     FUNC_LOG;
       
   295 	CNcsEmailAddressObject* addressObject = NULL;
       
   296 
       
   297     if ( iMatchingItems.Count() )
       
   298 		{
       
   299 		CFSEmailUiClsItem* clsItem = NULL;
       
   300 		if ( iRemoteLookupSupported )
       
   301 			{
       
   302 			clsItem = iMatchingItems[CurrentItemIndex()-1];  // -1 because of iRemoteLookupItemPos
       
   303 			}
       
   304 		else
       
   305 			{
       
   306 			clsItem = iMatchingItems[CurrentItemIndex()]; // no iRemoteLookupItemPos			
       
   307 			}
       
   308 		addressObject= CNcsEmailAddressObject::NewL( clsItem->DisplayName(), clsItem->EmailAddress() );
       
   309         CleanupStack::PushL( addressObject );			
       
   310         if ( clsItem->MultipleEmails() )
       
   311         	{
       
   312 
       
   313         	addressObject->SetDisplayFull( ETrue );
       
   314         	}
       
   315       
       
   316         }
       
   317 	return addressObject;
       
   318 	}
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // CNcsPopupListBox::SetPopupMaxRect
       
   322 // -----------------------------------------------------------------------------
       
   323 void CNcsPopupListBox::SetPopupMaxRect( const TRect& aPopupMaxRect )
       
   324 	{
       
   325     FUNC_LOG;
       
   326 	iPopupMaxRect = aPopupMaxRect;
       
   327 	SetPopupHeight();
       
   328 	TRAP_IGNORE( UpdateScrollBarsL() );
       
   329  	TRAP_IGNORE( SetScrollBarVisibilityL() );
       
   330 	}
       
   331 	
       
   332 // -----------------------------------------------------------------------------
       
   333 // CNcsPopupListBox::IsPopupEmpty
       
   334 // -----------------------------------------------------------------------------
       
   335 TBool CNcsPopupListBox::IsPopupEmpty() const
       
   336 	{
       
   337     FUNC_LOG;
       
   338 	if( Model()->NumberOfItems() > 0 )
       
   339 		return EFalse;
       
   340 	else
       
   341 		return ETrue;
       
   342 	}
       
   343 
       
   344 // -----------------------------------------------------------------------------
       
   345 // CNcsPopupListBox::IsRemoteLookupItemSelected
       
   346 // -----------------------------------------------------------------------------
       
   347 TBool CNcsPopupListBox::IsRemoteLookupItemSelected() const
       
   348 	{
       
   349     FUNC_LOG;
       
   350 	if( CurrentItemIndex() == iRemoteLookupItemPos && iRemoteLookupSupported )
       
   351 		return ETrue;
       
   352 	else
       
   353 		return EFalse;
       
   354 	}
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CNcsPopupListBox::CurrentPopupClsItemsArray
       
   358 // -----------------------------------------------------------------------------
       
   359 
       
   360 const RPointerArray<CFSEmailUiClsItem>& CNcsPopupListBox::CurrentPopupClsItemsArray() const
       
   361 	{
       
   362 	return iMatchingItems;
       
   363 	}
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CNcsPopupListBox::RemoteLookupItemPos
       
   367 // -----------------------------------------------------------------------------
       
   368 TInt CNcsPopupListBox::RemoteLookupItemPos() const
       
   369 	{
       
   370     FUNC_LOG;
       
   371 	return iRemoteLookupItemPos;
       
   372 	}
       
   373 
       
   374 // -----------------------------------------------------------------------------
       
   375 // CNcsPopupListBox::LayoutHandler
       
   376 // -----------------------------------------------------------------------------
       
   377 CFSEmailUiLayoutHandler& CNcsPopupListBox::LayoutHandler() const
       
   378     {
       
   379     FUNC_LOG;
       
   380     CFreestyleEmailUiAppUi* appUi = 
       
   381         static_cast<CFreestyleEmailUiAppUi*>( ControlEnv()->AppUi() );
       
   382     return *appUi->LayoutHandler();
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CNcsPopupListBox::SetListItemsFromArrayL
       
   387 // -----------------------------------------------------------------------------
       
   388 void CNcsPopupListBox::SetListItemsFromArrayL()
       
   389 	{
       
   390     FUNC_LOG;
       
   391 	// reset the cursor to point to the first item
       
   392     //iView->MoveCursorL( CListBoxView::ECursorFirstItem, CListBoxView::ENoSelection);
       
   393 	Reset();
       
   394 	
       
   395 	// Create totally new text array
       
   396 	CreateTextArrayAndSetToTheListboxL( ETrue );
       
   397 
       
   398 	// append texts to text array
       
   399 	for( TInt i=0; i < iMatchingItems.Count(); i++ )
       
   400 		{
       
   401 		iItemTextsArray->AppendL( iMatchingItems[i]->FullTextL() );
       
   402 		}
       
   403 
       
   404 	// Update rmlu item
       
   405 	SetRemoteLookupItemFirstToTheListL();
       
   406 	
       
   407 	SetPopupHeight();
       
   408 	SetScrollBarVisibilityL();
       
   409 	HandleItemAdditionL();
       
   410 	
       
   411 	if( iItemTextsArray && iItemTextsArray->Count() > 0 ) 
       
   412 		SetCurrentItemIndex( 0 );
       
   413 
       
   414 	if( IsVisible() )
       
   415 		DrawDeferred();
       
   416 	}
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // CNcsPopupListBox::SetPopupHeight
       
   420 // -----------------------------------------------------------------------------
       
   421 void CNcsPopupListBox::SetPopupHeight()
       
   422 	{
       
   423     FUNC_LOG;
       
   424 	TRect newRect = iPopupMaxRect;
       
   425 
       
   426 	// This is the total height in pixels needed to show all items
       
   427     TInt itemCount = Model()->NumberOfItems();
       
   428  	TInt minimumHeight = CalcHeightBasedOnNumOfItems( itemCount );
       
   429  	
       
   430  	// Shrink list size if maximum size is not needed
       
   431 	if( iPopupMaxRect.Height() > minimumHeight )
       
   432 	    {
       
   433 		newRect.SetHeight( minimumHeight );
       
   434 	    }
       
   435 	SetRect( newRect );
       
   436 	}
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // CNcsPopupListBox::SetScrollBarVisibilityL
       
   440 // -----------------------------------------------------------------------------
       
   441 void CNcsPopupListBox::SetScrollBarVisibilityL()
       
   442 	{
       
   443     FUNC_LOG;
       
   444 	// This is the total height in pixels needed to show all items
       
   445 	TInt minimumHeight = CalcHeightBasedOnNumOfItems( Model()->NumberOfItems() );
       
   446 
       
   447 	// Show scroll bar if there is more items we can show at once.
       
   448 	if( iPopupMaxRect.Height() > minimumHeight ) 
       
   449 		{
       
   450 		ScrollBarFrame()->SetScrollBarVisibilityL(
       
   451 			CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff ); 
       
   452 		}
       
   453 	else 
       
   454 		{
       
   455 		ScrollBarFrame()->SetScrollBarVisibilityL(
       
   456 			CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn ); 
       
   457 		}
       
   458 	}
       
   459 
       
   460 
       
   461 // -----------------------------------------------------------------------------
       
   462 // CNcsPopupListBox::SetRemoteLookupItemFirstToTheListL
       
   463 // -----------------------------------------------------------------------------
       
   464 void CNcsPopupListBox::SetRemoteLookupItemFirstToTheListL()
       
   465 	{
       
   466     FUNC_LOG;
       
   467 	if( iRemoteLookupSupported )
       
   468 		{
       
   469 		HBufC* rmluText = StringLoader::LoadLC( R_FSE_EDITOR_ADDRESS_LIST_REMOTE_LOOKUP_SEARCH, *iCurrentSearchText );
       
   470 		
       
   471 		iItemTextsArray->InsertL( 0, *rmluText );
       
   472 		CleanupStack::PopAndDestroy( rmluText );
       
   473 		iRemoteLookupItemPos = 0;
       
   474 		}
       
   475 	else
       
   476 		{
       
   477 		iRemoteLookupItemPos = -1;
       
   478 		}
       
   479 	}
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CNcsPopupListBox::MoveRemoteLookupItemL
       
   483 // -----------------------------------------------------------------------------
       
   484 void CNcsPopupListBox::MoveRemoteLookupItemL( TRemoteLookupItemMoveDirection aDirection )
       
   485 	{
       
   486     FUNC_LOG;
       
   487 	if( iRemoteLookupSupported )
       
   488 		{
       
   489 		TInt newRMLUItemIndex = -1;
       
   490 		TInt newCurrentItem = -1;
       
   491 		if( aDirection == ERemoteLookupItemUp &&
       
   492 			 iView->CurrentItemIndex() == iView->TopItemIndex() )
       
   493 			{
       
   494 			newRMLUItemIndex = iRemoteLookupItemPos - 1;
       
   495 			newCurrentItem = CurrentItemIndex() - 1;
       
   496 			}
       
   497 		else if( aDirection == ERemoteLookupItemDown &&
       
   498 				 iView->CurrentItemIndex() == iView->BottomItemIndex() )
       
   499 			{
       
   500 			newRMLUItemIndex = iRemoteLookupItemPos + 1;
       
   501 			newCurrentItem = CurrentItemIndex() + 1;
       
   502 			}
       
   503 
       
   504 
       
   505 		if( ItemExists ( newCurrentItem ) )
       
   506 			{
       
   507 			iItemTextsArray->Delete( iRemoteLookupItemPos );
       
   508 
       
   509 			HBufC* rmluText = StringLoader::LoadLC( R_FSE_EDITOR_ADDRESS_LIST_REMOTE_LOOKUP_SEARCH, *iCurrentSearchText );
       
   510 			
       
   511 			iItemTextsArray->InsertL( newRMLUItemIndex, *rmluText );
       
   512 			CleanupStack::PopAndDestroy( rmluText );
       
   513 			iRemoteLookupItemPos = newRMLUItemIndex;
       
   514 			}
       
   515 		}
       
   516 	}
       
   517 
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CNcsPopupListBox::CreateTextArrayAndSetToTheListboxL
       
   521 // -----------------------------------------------------------------------------
       
   522 void CNcsPopupListBox::CreateTextArrayAndSetToTheListboxL( const TBool& aResetIfExists )
       
   523 	{
       
   524     FUNC_LOG;
       
   525 	if( !iItemTextsArray )
       
   526 		{
       
   527 		iItemTextsArray = new ( ELeave ) CDesCArraySeg( 8 );
       
   528 		// Set the popup list data
       
   529 		Model()->SetItemTextArray( iItemTextsArray );
       
   530 		Model()->SetOwnershipType( ELbmDoesNotOwnItemArray  );
       
   531 		}
       
   532 		
       
   533 	if( aResetIfExists )
       
   534 		{
       
   535 		delete iItemTextsArray;
       
   536 		iItemTextsArray = NULL;
       
   537 		CreateTextArrayAndSetToTheListboxL( EFalse );
       
   538 		}
       
   539 	}
       
   540 
       
   541 
       
   542 // -----------------------------------------------------------------------------
       
   543 // CNcsListItemDrawer::CNcsListItemDrawer
       
   544 // -----------------------------------------------------------------------------
       
   545 CNcsListItemDrawer::CNcsListItemDrawer( const CNcsPopupListBox& aListBox )
       
   546 :CListItemDrawer(), iListBox(aListBox)
       
   547 	{
       
   548     FUNC_LOG;
       
   549 	// Store a GC for later use
       
   550 	iGc = &CCoeEnv::Static()->SystemGc();
       
   551 	SetGc(iGc);
       
   552 	}
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // CNcsListItemDrawer::DrawActualItem
       
   556 // -----------------------------------------------------------------------------
       
   557 void CNcsListItemDrawer::DrawActualItem(TInt aItemIndex,
       
   558 	const TRect& aActualItemRect, TBool aItemIsCurrent,
       
   559 	TBool /*aViewIsEmphasized*/, TBool /*aViewIsDimmed*/,
       
   560 	TBool /*aItemIsSelected*/) const
       
   561 	{
       
   562     FUNC_LOG;
       
   563 	// <cmail>
       
   564 	iGc->Reset();
       
   565 	// </cmail>
       
   566 	
       
   567 	// Get reference to curren popup cls item list.
       
   568 	const RPointerArray<CFSEmailUiClsItem>& clsItemArray = 	iListBox.CurrentPopupClsItemsArray();
       
   569 	TInt rmluPosition = iListBox.RemoteLookupItemPos();
       
   570 
       
   571 	// Sets all the attributes, like font, text color and background color.
       
   572 	const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontPrimarySmallFont );
       
   573 	iGc->UseFont(font);
       
   574 
       
   575 	// We have to draw the item in layered fassion in order to do the skin
       
   576 	// First clear the backround by drawing a solid white rect.	
       
   577 	iGc->SetPenColor(iBackColor);
       
   578 	iGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   579 	iGc->SetBrushColor(iBackColor);
       
   580 	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   581 
       
   582 	// Now draw the highlight
       
   583 	if( aItemIsCurrent ) 
       
   584 		{
       
   585 		TRgb highlightColor = iListBox.LayoutHandler().PcsPopupHighlightColor();
       
   586 		iGc->SetBrushColor(highlightColor);
       
   587 //	    AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), *iGc,
       
   588 //	    	aActualItemRect, aActualItemRect,
       
   589 //	    	KNcsIIDHighlightBackground, KNcsIIDHighlightBackground );
       
   590 		}
       
   591 	iGc->DrawRect(aActualItemRect);
       
   592 
       
   593 
       
   594 	iGc->SetPenColor(iTextColor);
       
   595 	iGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   596 	iGc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   597 	TInt topToBaseline = ( aActualItemRect.Height() - font->HeightInPixels() ) / 2
       
   598 						+ font->AscentInPixels();
       
   599 
       
   600 	TPtrC itemText = iListBox.Model()->ItemText( aItemIndex );
       
   601 
       
   602 	// Construct bidirectional text object
       
   603 	// <cmail> Removed leave from non-leaving function.
       
   604 	TBidiText* bidiText = NULL;
       
   605 	TRAPD( err, bidiText = TBidiText::NewL( itemText, 1 ) );
       
   606 	if ( err == KErrNone )
       
   607 		{
       
   608 		bidiText->WrapText( aActualItemRect.Width(), *font, NULL );
       
   609 		}
       
   610 		
       
   611 	TPoint leftBase = aActualItemRect.iTl + TPoint( 0, topToBaseline );
       
   612 
       
   613     if ( err != KErrNone )
       
   614         {
       
   615         bidiText = NULL; // to be on the safe side
       
   616         }
       
   617 
       
   618 	// check if we are drawing remote lookup item or contact match
       
   619 	else if ( rmluPosition == aItemIndex )
       
   620 		{
       
   621 		iGc->SetUnderlineStyle( EUnderlineOff );
       
   622 		bidiText->DrawText( *iGc, leftBase );
       
   623 		}
       
   624 	else
       
   625 		{
       
   626 		// if list has rmlu item change item index right
       
   627 		if ( rmluPosition >= 0 )
       
   628 			{
       
   629 			aItemIndex--;
       
   630 			}
       
   631 
       
   632 		// change color to gray if match doesn't have email address.
       
   633 		if( clsItemArray[aItemIndex]->EmailAddress().Compare( KNullDesC ) == 0 )
       
   634 			{
       
   635 			TRgb dimmedColor = iListBox.LayoutHandler().PcsPopupDimmedFontColor();
       
   636 			iGc->SetPenColor( dimmedColor );
       
   637 			}
       
   638 
       
   639 		// For now, we support underlining the matching part only if the
       
   640 		//       text is written completely with left-to-right script
       
   641 		
       
   642 		// We know the text contains RTL script if the display string is not just
       
   643 		// truncated version of the original string.
       
   644 		TPtrC dispText = bidiText->DisplayText();
       
   645 		TInt compLength = dispText.Length() - 1; // -1 to omit the truncation character
       
   646 		TBool textContainsRtl = 
       
   647             ( itemText.Left(compLength) != dispText.Left(compLength) );
       
   648 		
       
   649         const RArray<TPsMatchLocation>& underlines = clsItemArray[aItemIndex]->Highlights();
       
   650         
       
   651 		if ( underlines.Count() > 0 && !textContainsRtl )
       
   652 			{
       
   653 			TInt i = 0;
       
   654 			TBool partsLeft = ETrue;
       
   655 			TInt currentTextStart = 0;
       
   656 			TInt currentTextLength = 0;
       
   657 
       
   658 			while ( partsLeft )
       
   659 				{
       
   660 				if ( currentTextStart < underlines[i].index )
       
   661 					{
       
   662 					// draw letters to the start of the underlined part
       
   663 					currentTextLength = underlines[i].index - currentTextStart;
       
   664 					DrawPartOfItem( aActualItemRect, *font, currentTextStart, currentTextLength, itemText,
       
   665 									EFalse, topToBaseline );
       
   666 					}
       
   667 				else if ( currentTextStart == underlines[i].index )
       
   668 					{
       
   669 					// draw underlined letters
       
   670 					currentTextLength = underlines[i].length;
       
   671 					
       
   672 					DrawPartOfItem( aActualItemRect, *font, currentTextStart, currentTextLength, itemText,
       
   673 									ETrue, topToBaseline );
       
   674 					i++;
       
   675 					}
       
   676 				else 
       
   677 					{
       
   678 					// This is here, because PCS Engine might give you duplicate match entries,
       
   679 					// in this case we're not advancing text but we'll skip that match
       
   680 					currentTextLength = 0;
       
   681 					i++;
       
   682 					}
       
   683 					// update text start point
       
   684 					currentTextStart += currentTextLength;
       
   685 				
       
   686 				if ( i >= underlines.Count() )
       
   687 					{
       
   688 					partsLeft = EFalse;
       
   689 					// draw rest of the letters, if there are any after the last underlined part
       
   690 					if ( currentTextStart < itemText.Length() )
       
   691 						{
       
   692 						currentTextLength = itemText.Length() - currentTextStart;
       
   693 						DrawPartOfItem( aActualItemRect, *font, currentTextStart, currentTextLength, itemText,
       
   694 										EFalse, topToBaseline );
       
   695 						}
       
   696 					}
       
   697 				
       
   698 				}
       
   699 			}
       
   700 		else
       
   701 			{
       
   702 			iGc->SetUnderlineStyle( EUnderlineOff );
       
   703 			bidiText->DrawText( *iGc, leftBase );
       
   704 			}		
       
   705 		}
       
   706 		
       
   707 	delete bidiText;
       
   708 	bidiText = NULL;
       
   709 	}
       
   710 
       
   711 // -----------------------------------------------------------------------------
       
   712 // CNcsListItemDrawer::DrawPartOfItem
       
   713 // -----------------------------------------------------------------------------
       
   714 void CNcsListItemDrawer::DrawPartOfItem( const TRect& aItemRect, const CFont& aFont,
       
   715 						 TInt aStartPos, TInt aLength, const TDesC& aDes,
       
   716 						 TBool aUnderlined, TInt aBaselineOffsetFromTop  ) const
       
   717 	{
       
   718     FUNC_LOG;
       
   719 	if( aUnderlined )
       
   720 		{
       
   721 		iGc->SetUnderlineStyle( EUnderlineOn );
       
   722 		}
       
   723 	else
       
   724 		{
       
   725 		iGc->SetUnderlineStyle( EUnderlineOff );
       
   726 		}
       
   727 	TRect currentTextRect( aItemRect );
       
   728 	TInt pixels = aFont.TextWidthInPixels( aDes.Left( aStartPos ) );
       
   729 	currentTextRect.iTl.iX = currentTextRect.iTl.iX + pixels;
       
   730 	iGc->DrawText( aDes.Mid( aStartPos, aLength ), 
       
   731 	        currentTextRect, aBaselineOffsetFromTop );
       
   732 	}
       
   733 
       
   734 
       
   735 void CNcsPopupListBox::UpdateListL()
       
   736     {
       
   737     FUNC_LOG;
       
   738     SetListItemsFromArrayL();
       
   739 
       
   740     // Close the popup if it's empty and make sure it's visible if it's not empty.
       
   741     if ( IsPopupEmpty() )
       
   742         {
       
   743         iHeaderContainer.ClosePopupContactListL();
       
   744         }
       
   745     else
       
   746         {
       
   747         MakeVisible( ETrue );
       
   748         iHeaderContainer.ShowPopupMenuBarL( ETrue );
       
   749         }
       
   750     }
       
   751 
       
   752 // End of File
       
   753