phonebookui/Phonebook2/UIControls/src/CPbk2ContactViewListBox.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 85 38bb213f60ba
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Phonebook 2 contact view list box.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2ContactViewListBox.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "MPbk2ContactViewListBoxModel.h"
       
    24 #include "CPbk2IconArray.h"
       
    25 #include "MPbk2NamesListState.h"
       
    26 #include "cpbk2contactviewdoublelistboxmodel.h"
       
    27 #include <CPbk2UIExtensionManager.h>
       
    28 #include <MPbk2UIExtensionIconSupport.h>
       
    29 #include <MPbk2UIExtensionFactory.h>
       
    30 #include <MPbk2ContactUiControlExtension.h>
       
    31 #include "CPbk2ListboxModelCmdDecorator.h"
       
    32 #include <CPbk2ContactIconsUtils.h>
       
    33 #include <Pbk2UIControls.hrh>
       
    34 
       
    35 // Virtual Phonebook
       
    36 #include <CVPbkContactManager.h>
       
    37 
       
    38 // System includes
       
    39 #include <barsread.h>
       
    40 #include <eikclbd.h>
       
    41 
       
    42 #include <aknappui.h>
       
    43 #include <aknViewAppUi.h>
       
    44 #include <aknlayoutscalable_avkon.cdl.h>
       
    45 
       
    46 // Debugging headers
       
    47 #include <Pbk2Debug.h>
       
    48 #include <featmgr.h>
       
    49 
       
    50 #include <skinlayout.cdl.h>
       
    51 #include <aknlayoutscalable_apps.cdl.h>
       
    52 #include "cpbk2contactviewcustomlistboxitemdrawer.h"
       
    53 #include "cpbk2contactviewcustomlistboxdata.h"
       
    54 #include "CPbk2NamesListControl.h"
       
    55 
       
    56 
       
    57 /// Unnamed namespace for local definitions
       
    58 namespace {
       
    59 
       
    60 // LOCAL FUNCTIONS
       
    61 
       
    62 _LIT( KTabChar, "\t" );
       
    63 const TInt KCheckboxMargin = 1; // Checkbox margin pixels
       
    64 
       
    65 /**
       
    66  * Returns icon array from given list box.
       
    67  *
       
    68  * @param aListBox  List box.
       
    69  * @return  Icon array in Phonebook 2 format.
       
    70  */
       
    71 inline CPbk2IconArray* IconArray( CEikColumnListBox& aListBox )
       
    72     {
       
    73     return static_cast<CPbk2IconArray*>(
       
    74         aListBox.ItemDrawer()->ColumnData()->IconArray() );
       
    75     }
       
    76 
       
    77 /**
       
    78  * Sets given icon array as given listbox's icon array.
       
    79  *
       
    80  * @param aListBox      List box.
       
    81  * @param aIconArray    Icon array.
       
    82  */
       
    83 inline void SetIconArray( CEikColumnListBox& aListBox,
       
    84         CPbk2IconArray* aIconArray )
       
    85     {
       
    86     aListBox.ItemDrawer()->ColumnData()->SetIconArray( aIconArray );
       
    87     }
       
    88 
       
    89 #ifdef _DEBUG
       
    90 enum TPanicCode
       
    91     {
       
    92     EPanicPreCond_CreateListBoxModelL = 1
       
    93     };
       
    94 
       
    95 void Panic(TInt aReason)
       
    96     {
       
    97     _LIT(KPanicText, "CPbk2ContactViewListBox");
       
    98     User::Panic(KPanicText, aReason);
       
    99     }
       
   100 #endif // _DEBUG
       
   101 } /// namespace
       
   102 
       
   103 // --------------------------------------------------------------------------
       
   104 // CPbk2ContactViewListBox::CPbk2ContactViewListBox
       
   105 // --------------------------------------------------------------------------
       
   106 //
       
   107 CPbk2ContactViewListBox::CPbk2ContactViewListBox
       
   108             (   CCoeControl& aContainer,
       
   109                 MPbk2ContactUiControlExtension* aUiExtension,
       
   110                 CPbk2PredictiveSearchFilter &aSearchFilter ) :
       
   111                 iContainer(aContainer), 
       
   112                 iChangedIndexes( 1 ), // allocation granularity
       
   113                 iUiExtension( aUiExtension ),
       
   114                 iSearchFilter( aSearchFilter ),
       
   115                 iMarkingModeOn( EFalse )
       
   116     {
       
   117     }
       
   118 
       
   119 // --------------------------------------------------------------------------
       
   120 // CPbk2ContactViewListBox::~CPbk2ContactViewListBox
       
   121 // --------------------------------------------------------------------------
       
   122 //
       
   123 CPbk2ContactViewListBox::~CPbk2ContactViewListBox()
       
   124     {
       
   125     delete iListboxModelDecorator;
       
   126     delete iModel;
       
   127     FeatureManager::UnInitializeLib();
       
   128     CCoeEnv::Static()->RemoveForegroundObserver( *this );
       
   129     }
       
   130 
       
   131 // --------------------------------------------------------------------------
       
   132 // CPbk2ContactViewListBox::ConstructL
       
   133 // --------------------------------------------------------------------------
       
   134 //
       
   135 void CPbk2ContactViewListBox::ConstructL(
       
   136         CCoeControl& aContainer, TResourceReader& aResourceReader,
       
   137         const CVPbkContactManager& aManager, MVPbkContactViewBase& aView,
       
   138         MPbk2ContactNameFormatter& aNameFormatter,
       
   139         CPbk2StorePropertyArray& aStoreProperties )
       
   140     {
       
   141     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   142         ("CPbk2ContactViewListBox::ConstructL"));
       
   143 
       
   144     FeatureManager::InitializeLibL();
       
   145 
       
   146     // Preallocate space for the one required integer
       
   147     iChangedIndexes.AppendL( KErrNotFound );
       
   148 
       
   149     // Read flags from resources
       
   150     iResourceData.iFlags = aResourceReader.ReadUint32();    // flags
       
   151 
       
   152     SetContainerWindowL( aContainer );
       
   153 
       
   154     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   155         ("CPbk2ContactViewListBox::ConstructL about to resource construct"));
       
   156 
       
   157     // Let Avkon read it's share of the resources
       
   158     ConstructFromResourceL( aResourceReader );
       
   159 
       
   160     // Remove the platform default "No data" text
       
   161     View()->SetListEmptyTextL( KNullDesC );
       
   162 
       
   163     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   164         ("CPbk2ContactViewListBox::ConstructL about to create icon array"));
       
   165 
       
   166     CPbk2IconArray* iconArray =
       
   167         CPbk2ContactIconsUtils::CreateListboxIconArrayL(
       
   168                 aResourceReader.ReadInt32());
       
   169 
       
   170     SetIconArray( *this, iconArray );
       
   171 
       
   172     iResourceData.iEmptyIconId =
       
   173         TPbk2IconId( aResourceReader ); // empty icon
       
   174     iResourceData.iDefaultIconId =
       
   175         TPbk2IconId( aResourceReader ); // default icon
       
   176 
       
   177     CreateScrollBarFrameL( ETrue );
       
   178     ScrollBarFrame()->SetScrollBarVisibilityL(
       
   179         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   180 
       
   181     MakeVisible( EFalse );
       
   182 
       
   183     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   184         ("CPbk2ContactViewListBox::ConstructL about to create model"));
       
   185 
       
   186     CreateListBoxModelL( aManager, aView,
       
   187         aNameFormatter, aStoreProperties );
       
   188     
       
   189     CCoeEnv::Static()->AddForegroundObserverL( *this );
       
   190     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   191         ("CPbk2ContactViewListBox::ConstructL end"));
       
   192     }
       
   193 
       
   194 // --------------------------------------------------------------------------
       
   195 // CPbk2ContactViewListBox::NewL
       
   196 // --------------------------------------------------------------------------
       
   197 //
       
   198 CPbk2ContactViewListBox* CPbk2ContactViewListBox::NewL(
       
   199         CCoeControl& aContainer, TResourceReader& aResourceReader,
       
   200         const CVPbkContactManager& aManager, MVPbkContactViewBase& aView,
       
   201         MPbk2ContactNameFormatter& aNameFormatter,
       
   202         CPbk2StorePropertyArray& aStoreProperties,
       
   203         MPbk2ContactUiControlExtension* aUiExtension,
       
   204         CPbk2PredictiveSearchFilter &aSearchFilter )
       
   205     {
       
   206     CPbk2ContactViewListBox* self =
       
   207         new ( ELeave ) CPbk2ContactViewListBox( aContainer, aUiExtension, aSearchFilter );
       
   208     CleanupStack::PushL( self );
       
   209     self->ConstructL( aContainer, aResourceReader, aManager,
       
   210         aView, aNameFormatter, aStoreProperties );
       
   211     CleanupStack::Pop( self );
       
   212     return self;
       
   213     }
       
   214 
       
   215 // --------------------------------------------------------------------------
       
   216 // CPbk2ContactViewListBox::NumberOfItems
       
   217 // --------------------------------------------------------------------------
       
   218 //
       
   219 TInt CPbk2ContactViewListBox::NumberOfItems() const
       
   220     {
       
   221     TInt result = 0;
       
   222     if ( iListboxModelDecorator )
       
   223         {
       
   224         result = iListboxModelDecorator->MdcaCount();
       
   225         }
       
   226     return result;
       
   227     }
       
   228 
       
   229 // --------------------------------------------------------------------------
       
   230 // CPbk2ContactViewListBox::ContactsMarked
       
   231 // --------------------------------------------------------------------------
       
   232 //
       
   233 TBool CPbk2ContactViewListBox::ContactsMarked() const
       
   234     {
       
   235     const CListBoxView::CSelectionIndexArray* selections =
       
   236         View()->SelectionIndexes();
       
   237     TBool notEmpty = selections && selections->Count() > 0;
       
   238     TBool containsContacts = EFalse;
       
   239     for (TInt n = 0; notEmpty && n < selections->Count() && !containsContacts; ++n )
       
   240         {
       
   241         const TInt index = selections->At( n );
       
   242         // The item is either a contact or a command.
       
   243         containsContacts = IsContact( index );
       
   244         }
       
   245     return containsContacts;
       
   246     }
       
   247 
       
   248 // --------------------------------------------------------------------------
       
   249 // CPbk2ContactViewListBox::HandleContactViewEventL
       
   250 // --------------------------------------------------------------------------
       
   251 //
       
   252 void CPbk2ContactViewListBox::HandleEventL
       
   253         ( TInt aEvent, TInt aIndex )
       
   254     {
       
   255     switch ( aEvent )
       
   256         {
       
   257         case MPbk2NamesListState::EItemAdded:
       
   258             {
       
   259             iChangedIndexes[0] = aIndex;
       
   260             HandleItemAdditionL( iChangedIndexes );
       
   261             break;
       
   262             }
       
   263         case MPbk2NamesListState::EItemRemoved:
       
   264             {
       
   265             // Deselect item
       
   266             CListBoxView& listBoxView = *View();
       
   267             listBoxView.SetDisableRedraw( ETrue );
       
   268             listBoxView.DeselectItem( aIndex );
       
   269             listBoxView.SetDisableRedraw( EFalse );
       
   270 
       
   271             TInt focusIndex = CurrentItemIndex();
       
   272             TInt topIndex = TopItemIndex();
       
   273             iChangedIndexes[0] = aIndex;
       
   274             HandleItemRemovalL( iChangedIndexes );
       
   275 
       
   276             // The deduction of 1 is for adapting with the different bases
       
   277             const TInt lastIndex = Model()->NumberOfItems() - 1;
       
   278             if ( lastIndex == KErrNotFound )
       
   279                 {
       
   280                 Reset();
       
   281                 }
       
   282             else
       
   283                 {
       
   284                 if ( aIndex < focusIndex )
       
   285                     {
       
   286                     // If item was removed above focused item, maintain
       
   287                     // focus by moving it up by one
       
   288                     --focusIndex;
       
   289                     }
       
   290                 if ( focusIndex > lastIndex || focusIndex < 0 )
       
   291                     {
       
   292                     focusIndex = lastIndex;
       
   293                     }
       
   294                 const TInt numVisibleItems =
       
   295                     View()->NumberOfItemsThatFitInRect(
       
   296                         View()->ViewRect() );
       
   297                 if ( topIndex + numVisibleItems > lastIndex )
       
   298                     {
       
   299                     topIndex = Max( lastIndex - numVisibleItems + 1, 0 );
       
   300                     }
       
   301                 if ( topIndex >= 0 )
       
   302                     {
       
   303                     SetTopItemIndex( topIndex );
       
   304                     }
       
   305                 if ( focusIndex >= 0 )
       
   306                     {
       
   307                     SetCurrentItemIndex( focusIndex );
       
   308                     }
       
   309                 }
       
   310             break;
       
   311             }
       
   312         default:
       
   313             {
       
   314             // Do nothing
       
   315             break;
       
   316             }
       
   317         }
       
   318     }
       
   319 
       
   320 // --------------------------------------------------------------------------
       
   321 // CPbk2ContactViewListBox::FixTopItemIndex
       
   322 // --------------------------------------------------------------------------
       
   323 //
       
   324 void CPbk2ContactViewListBox::FixTopItemIndex()
       
   325     {
       
   326     TInt index = TopItemIndex();
       
   327     const TInt height = View()->NumberOfItemsThatFitInRect(
       
   328         View()->ViewRect() );
       
   329     const TInt numItems = Model()->NumberOfItems();
       
   330     if ( index + height > numItems )
       
   331         {
       
   332         index += numItems - ( height + index );
       
   333         if ( index < 0 )
       
   334             {
       
   335             index = 0;
       
   336             }
       
   337         if ( index != TopItemIndex() )
       
   338             {
       
   339             SetTopItemIndex( index );
       
   340             }
       
   341         }
       
   342     }
       
   343 
       
   344 // --------------------------------------------------------------------------
       
   345 // CPbk2ContactViewListBox::CheckFocusIndex
       
   346 // --------------------------------------------------------------------------
       
   347 //
       
   348 void CPbk2ContactViewListBox::CheckFocusIndex()
       
   349     {
       
   350     if ( CurrentItemIndex() == KErrNotFound )
       
   351         {
       
   352         SetCurrentItemIndex( 0 );
       
   353         }
       
   354     }
       
   355 
       
   356 // --------------------------------------------------------------------------
       
   357 // CPbk2ContactViewListBox::HandlePointerEventL
       
   358 // --------------------------------------------------------------------------
       
   359 //
       
   360 void CPbk2ContactViewListBox::HandlePointerEventL
       
   361         ( const TPointerEvent& aPointerEvent )
       
   362     {
       
   363     TInt oldIndex = CurrentItemIndex();
       
   364 
       
   365     // Base class handles the pointer event
       
   366     CAknSingleGraphicStyleListBox::HandlePointerEventL( aPointerEvent );
       
   367 
       
   368     switch( aPointerEvent.iType )
       
   369         {
       
   370         case TPointerEvent::EButton1Down:
       
   371             {
       
   372             TInt pointedItemIndex;
       
   373             iFocusableContactPointed = View()->XYPosToItemIndex(
       
   374                 aPointerEvent.iPosition, pointedItemIndex );
       
   375             
       
   376             //no prior focus needed
       
   377             iFocusedContactPointed = iFocusableContactPointed;
       
   378             break;
       
   379             }
       
   380         default:
       
   381             {
       
   382             // Do nothing
       
   383             break;
       
   384             }
       
   385         };
       
   386     }
       
   387 
       
   388 // --------------------------------------------------------------------------
       
   389 // CPbk2ContactViewListBox::Flags
       
   390 // --------------------------------------------------------------------------
       
   391 //
       
   392 TUint CPbk2ContactViewListBox::Flags() const
       
   393     {
       
   394     return iResourceData.iFlags;
       
   395     }
       
   396 
       
   397 // --------------------------------------------------------------------------
       
   398 // CPbk2ContactViewListBox::SetScrollEventObserver
       
   399 // --------------------------------------------------------------------------
       
   400 //
       
   401 void CPbk2ContactViewListBox::SetScrollEventObserver(MEikScrollBarObserver* aObserver)
       
   402     {
       
   403     iScrollEventObserver = aObserver;
       
   404     }
       
   405 
       
   406 // --------------------------------------------------------------------------
       
   407 // CPbk2ContactViewListBox::IsSelectionListBox
       
   408 // This function is non const because IsMultiselection is non const.
       
   409 // --------------------------------------------------------------------------
       
   410 //
       
   411 TBool CPbk2ContactViewListBox::IsSelectionListBox()
       
   412     {
       
   413     // Try firs the CEikListBox method for multiselection
       
   414     TBool result = IsMultiselection();
       
   415 
       
   416     if ( !result )
       
   417         {
       
   418         // Then try other flags
       
   419         TUint32 markableFlags =
       
   420             EAknListBoxStylusMarkableList |
       
   421             EAknListBoxStylusMultiselectionList |
       
   422             EAknListBoxMarkableList |
       
   423             EAknListBoxMultiselectionList;
       
   424 
       
   425         // Compare CEikListBox flags to Avkon markable list flags
       
   426         result = iListBoxFlags & markableFlags;
       
   427         }
       
   428     return result;
       
   429     }
       
   430 
       
   431 void CPbk2ContactViewListBox::SetListCommands(
       
   432     const RPointerArray<MPbk2UiControlCmdItem>* aCommands )
       
   433     {
       
   434     iListboxModelDecorator->SetListCommands( aCommands );
       
   435     if( iColumnData )
       
   436         {
       
   437         iColumnData->SetListCommands( aCommands );
       
   438         }
       
   439     }
       
   440 
       
   441 // --------------------------------------------------------------------------
       
   442 // CPbk2ContactViewListBox::ClipFromBeginning
       
   443 // --------------------------------------------------------------------------
       
   444 //
       
   445 TBool CPbk2ContactViewListBox::ClipFromBeginning
       
   446         ( TDes& aBuffer, TInt aItemIndex, TInt aSubCellNumber )
       
   447     {
       
   448     CColumnListBoxData *data = ItemDrawer()->ColumnData();
       
   449     const CFont *font =
       
   450         data->Font(ItemDrawer()->Properties(aItemIndex), aSubCellNumber);
       
   451     // The width of the subcell displaying the characters.
       
   452     TInt cellWidth = data->ColumnWidthPixel(aSubCellNumber);
       
   453     // The margin of the subcell.
       
   454     TMargins margin = data->ColumnMargins(aSubCellNumber);
       
   455     // The valid width width displaying the characters.
       
   456     TInt width = cellWidth - margin.iLeft - margin.iRight;
       
   457     // If Marking mode is active, recalculate the valid width displaying characters.
       
   458     // contact entry of name list view in marking mode
       
   459     //
       
   460     // |checkbox|Icon|name  |
       
   461     // |        |    |number|
       
   462     if( iMarkingModeOn )
       
   463         {
       
   464         RecalcWidthInMarkingMode(width, *font, aBuffer[0]);
       
   465         }
       
   466     TInt clipGap = data->ColumnTextClipGap(aSubCellNumber);
       
   467     
       
   468     return AknTextUtils::ClipToFit(
       
   469         aBuffer, *font, width, AknTextUtils::EClipFromBeginning, width + clipGap);
       
   470     }
       
   471 
       
   472 // --------------------------------------------------------------------------
       
   473 // CPbk2ContactViewListBox::FocusedItemPointed
       
   474 // --------------------------------------------------------------------------
       
   475 //
       
   476 TBool CPbk2ContactViewListBox::FocusedItemPointed()
       
   477     {
       
   478     return iFocusedContactPointed;
       
   479     }
       
   480 
       
   481 // --------------------------------------------------------------------------
       
   482 // CPbk2ContactViewListBox::FocusableItemPointed
       
   483 // --------------------------------------------------------------------------
       
   484 //
       
   485 TBool CPbk2ContactViewListBox::FocusableItemPointed()
       
   486     {
       
   487     return iFocusableContactPointed;
       
   488     }
       
   489 
       
   490 // --------------------------------------------------------------------------
       
   491 // CPbk2ContactViewListBox::SearchFieldPointed
       
   492 // --------------------------------------------------------------------------
       
   493 //
       
   494 TBool CPbk2ContactViewListBox::SearchFieldPointed()
       
   495     {
       
   496     return EFalse;
       
   497     }
       
   498 
       
   499 // --------------------------------------------------------------------------
       
   500 // CPbk2ContactViewListBox::HandleScrollEventL
       
   501 // --------------------------------------------------------------------------
       
   502 //
       
   503 void CPbk2ContactViewListBox::HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType)
       
   504     {   
       
   505     // Handle showing of popupcharacter when user scrolls list using using scroll bar
       
   506     TBool prevState = iShowPopupChar;
       
   507 
       
   508     iShowPopupChar = ( aEventType == EEikScrollThumbDragHoriz || aEventType == EEikScrollThumbDragVert );
       
   509     
       
   510     if( prevState != iShowPopupChar )
       
   511         {
       
   512         DrawDeferred();
       
   513         }
       
   514 
       
   515     CAknSingleGraphicStyleListBox::HandleScrollEventL( aScrollBar, aEventType );
       
   516     if( iScrollEventObserver )
       
   517         {
       
   518         iScrollEventObserver->HandleScrollEventL( aScrollBar, aEventType );
       
   519         }
       
   520     }
       
   521 
       
   522 // --------------------------------------------------------------------------
       
   523 // CPbk2ContactViewListBox::CreateListBoxModelL
       
   524 // --------------------------------------------------------------------------
       
   525 //
       
   526 void CPbk2ContactViewListBox::CreateListBoxModelL
       
   527         ( const CVPbkContactManager& aManager, MVPbkContactViewBase& aView,
       
   528         MPbk2ContactNameFormatter& aNameFormatter,
       
   529         CPbk2StorePropertyArray& aStoreProperties )
       
   530     {
       
   531     __ASSERT_DEBUG( !iModel && !iListboxModelDecorator,
       
   532         Panic( EPanicPreCond_CreateListBoxModelL ) );
       
   533 
       
   534     // Set up listbox model
       
   535     CPbk2ContactViewListBoxModel::TParams params;
       
   536     params.iContactManager = &aManager;
       
   537     params.iView = &aView;
       
   538     params.iStoreProperties = &aStoreProperties;
       
   539     params.iNameFormatter = &aNameFormatter;
       
   540     params.iIconArray = IconArray( *this );
       
   541     params.iEmptyId = iResourceData.iEmptyIconId;
       
   542     params.iDefaultId = iResourceData.iDefaultIconId;
       
   543     params.iClipListBoxText = this;
       
   544     params.iUiExtension = iUiExtension;
       
   545     params.iMultiselection = IsMultiselection();
       
   546     CPbk2ContactViewListBoxModel* model = DoCreateModelL( params );
       
   547     model->SetUnnamedText( iResourceData.iUnnamedText );
       
   548     iModel = model;
       
   549 
       
   550     if( iColumnData )
       
   551         {
       
   552         iColumnData->SetDataModel( iModel );
       
   553         }
       
   554     // Wrap the original model.
       
   555     iListboxModelDecorator = DoCreateDecoratorL( 
       
   556             *IconArray( *this ),
       
   557             iResourceData.iEmptyIconId,
       
   558             iResourceData.iDefaultIconId );
       
   559     
       
   560     
       
   561     iListboxModelDecorator->SetDecoratedModel( *iModel );
       
   562     Model()->SetItemTextArray( iListboxModelDecorator );
       
   563     Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   564     }
       
   565 
       
   566 // --------------------------------------------------------------------------
       
   567 // CPbk2ContactViewListBox::DoCreateModelL
       
   568 // --------------------------------------------------------------------------
       
   569 //
       
   570 CPbk2ContactViewListBoxModel* CPbk2ContactViewListBox::DoCreateModelL(
       
   571                 CPbk2ContactViewListBoxModel::TParams params )
       
   572     {
       
   573     return CPbk2ContactViewListBoxModel::NewL( params );
       
   574     }
       
   575 
       
   576 
       
   577 // --------------------------------------------------------------------------
       
   578 // CPbk2ContactViewListBox::DoCreateDecoratorL
       
   579 // --------------------------------------------------------------------------
       
   580 //
       
   581 CPbk2ListboxModelCmdDecorator* CPbk2ContactViewListBox::DoCreateDecoratorL( 
       
   582                 const CPbk2IconArray& aIconArray,
       
   583                 TPbk2IconId aEmptyIconId,
       
   584                 TPbk2IconId aDefaultIconId )
       
   585     {
       
   586     return CPbk2ListboxModelCmdDecorator::NewL(
       
   587                 aIconArray,
       
   588                 aEmptyIconId,
       
   589                 aDefaultIconId );
       
   590     }
       
   591 
       
   592 
       
   593 // --------------------------------------------------------------------------
       
   594 // CPbk2ContactViewListBox::IsContact
       
   595 // --------------------------------------------------------------------------
       
   596 //
       
   597 TBool CPbk2ContactViewListBox::IsContact( TInt aIndex ) const
       
   598     {
       
   599     // The command items are always at the top of the list.
       
   600     return aIndex >= iListboxModelDecorator->NumberOfEnabledCommands();
       
   601     }
       
   602 
       
   603 // --------------------------------------------------------------------------
       
   604 // CPbk2ContactViewListBox::Draw
       
   605 // --------------------------------------------------------------------------
       
   606 //
       
   607 void CPbk2ContactViewListBox::Draw( const TRect& aRect ) const
       
   608     {
       
   609     CAknSingleGraphicStyleListBox::Draw(aRect);
       
   610     HandlePopupCharacter(NULL, Rect());
       
   611     }
       
   612 
       
   613 // --------------------------------------------------------------------------
       
   614 // CPbk2ContactViewListBox::CreateItemDrawerL
       
   615 // --------------------------------------------------------------------------
       
   616 //
       
   617 void CPbk2ContactViewListBox::CreateItemDrawerL()
       
   618     {
       
   619     // Use custom drawer only if predictive search is enabled
       
   620     if( FeatureManager::FeatureSupported(KFeatureIdFfContactsPredictiveSearch) )
       
   621         {
       
   622         CPbk2ContactViewCustomListBoxData* columnData =
       
   623                         CPbk2ContactViewCustomListBoxData::NewL( iSearchFilter );
       
   624     
       
   625         CleanupStack::PushL( columnData );
       
   626     
       
   627         iItemDrawer=new(ELeave) CPbk2ContactViewCustomListBoxItemDrawer(
       
   628                 static_cast<MTextListBoxModel*>(Model()), iCoeEnv->NormalFont(),
       
   629                 columnData);
       
   630         CleanupStack::Pop( columnData );
       
   631     
       
   632         //Ownership has been transferred to iItemDrawer
       
   633         iColumnData = columnData;
       
   634         }
       
   635     else
       
   636         {
       
   637         CAknSingleGraphicStyleListBox::CreateItemDrawerL();
       
   638         }
       
   639     }
       
   640 
       
   641 // --------------------------------------------------------------------------
       
   642 // CPbk2ContactViewListBox::HandleGainingForeground
       
   643 // --------------------------------------------------------------------------
       
   644 //
       
   645 void CPbk2ContactViewListBox::HandleGainingForeground()
       
   646     {
       
   647     DrawDeferred();
       
   648     }
       
   649 
       
   650 // --------------------------------------------------------------------------
       
   651 // CPbk2ContactViewListBox::HandleLosingForeground
       
   652 // --------------------------------------------------------------------------
       
   653 //
       
   654 void CPbk2ContactViewListBox::HandleLosingForeground()
       
   655     {
       
   656     if ( iShowPopupChar )
       
   657         {
       
   658         //Simulate an EButton1Up event to force a DrawDeferred() calling
       
   659         //in case of the scrollbar¡¯s at the background that can¡¯t receive the EButton1Up event.
       
   660         TPointerEvent PointEvent;
       
   661         PointEvent.iType = TPointerEvent::EButton1Up ;
       
   662         TRAP_IGNORE( ScrollBarFrame()->VerticalScrollBar()->HandlePointerEventL( PointEvent ) );
       
   663         DrawDeferred();
       
   664         }
       
   665     }
       
   666 
       
   667 // --------------------------------------------------------------------------
       
   668 // CPbk2ContactViewListBox::HandlePopupCharacter
       
   669 // --------------------------------------------------------------------------
       
   670 //
       
   671 void CPbk2ContactViewListBox::HandlePopupCharacter( CWindowGc* aGc, const TRect& aRectOfListBoxItem ) const
       
   672     {
       
   673     CPbk2NamesListControl& listControl = static_cast<CPbk2NamesListControl&>(iContainer);
       
   674     TInt itemIndex = TopItemIndex() - listControl.CommandItemCount();
       
   675    
       
   676     // itemIndex >= 0 filter out command item
       
   677     if ( itemIndex >= 0 && iShowPopupChar )
       
   678         {
       
   679         TAknLayoutRect layout;
       
   680         layout.LayoutRect(Rect(), AknLayoutScalable_Apps::popup_navstr_preview_pane(0));
       
   681         
       
   682         if (!layout.Rect().Intersects(aRectOfListBoxItem))
       
   683             {
       
   684             // If the rect of PopupCharacter not overlapped
       
   685             // with aRectOfListBoxItem, do nothing.
       
   686             return;
       
   687             }
       
   688 
       
   689         // Handle showing of popupcharacter when user scrolls list using using scroll bar
       
   690         CWindowGc* gc = aGc;
       
   691         if (!gc)
       
   692             {
       
   693             gc = &SystemGc();
       
   694             }
       
   695 
       
   696         TRgb normal;
       
   697         AknsUtils::GetCachedColor(AknsUtils::SkinInstance(),
       
   698                 normal,
       
   699                 KAknsIIDQsnTextColors,
       
   700                 EAknsCIQsnTextColorsCG6 );
       
   701 
       
   702         TAknLayoutRect cornerRect;
       
   703         // skinned draw uses submenu popup window skin (skinned border)
       
   704         cornerRect.LayoutRect(
       
   705             layout.Rect(),
       
   706             SkinLayout::Submenu_skin_placing_Line_2() );
       
   707 
       
   708         TRect innerRect( layout.Rect() );
       
   709         innerRect.Shrink( cornerRect.Rect().Width(), cornerRect.Rect().Height() );
       
   710 
       
   711         if ( !AknsDrawUtils::DrawFrame(
       
   712                 AknsUtils::SkinInstance(),
       
   713                 *gc,
       
   714                 layout.Rect(),
       
   715                 innerRect,
       
   716                 KAknsIIDQsnFrPopupSub,
       
   717                 KAknsIIDQsnFrPopupCenterSubmenu ) )
       
   718             {
       
   719             // skinned border failed -> black border
       
   720             gc->SetPenStyle( CGraphicsContext::ESolidPen );
       
   721             gc->SetBrushColor( KRgbBlack );
       
   722             gc->DrawRect( layout.Rect() );
       
   723             }
       
   724 
       
   725         TAknLayoutText textLayout;
       
   726         textLayout.LayoutText(layout.Rect(), AknLayoutScalable_Apps::popup_navstr_preview_pane_t1(0).LayoutLine());
       
   727 
       
   728         TPtrC desc(Model()->ItemTextArray()->MdcaPoint(View()->TopItemIndex()));
       
   729         
       
   730         //Add "if-clause" to avaid the error that argument of Mid() out of range.
       
   731         TInt index = desc.Find( KTabChar );
       
   732         if ( index != KErrNotFound && index < desc.Length()-1 )
       
   733             {
       
   734             HBufC* buf = desc.Mid( index + 1, 1 ).AllocL();           
       
   735 
       
   736             TPtr textPtr = buf->Des();
       
   737             textPtr.UpperCase();
       
   738 
       
   739             textLayout.DrawText( *gc, textPtr, ETrue, normal );
       
   740 
       
   741             delete buf;
       
   742             }
       
   743         }
       
   744     }
       
   745 
       
   746 // --------------------------------------------------------------------------
       
   747 // CPbk2ContactViewListBox::RecalcWidthInMarkingMode
       
   748 // Recalculate the width of space displaying the third column of the schema
       
   749 // below when Marking Mode is active.
       
   750 // contact entry of name list view in marking mode
       
   751 // The schema:
       
   752 // |checkbox|Icon|name  |
       
   753 // |        |    |number|
       
   754 // --------------------------------------------------------------------------
       
   755 //
       
   756 void CPbk2ContactViewListBox::RecalcWidthInMarkingMode(
       
   757                               TInt& aWidth,
       
   758                               const CFont& aFont,
       
   759                               TChar aChar )
       
   760     {
       
   761     if( aWidth > 0 )
       
   762         {
       
   763         aWidth -= KCheckboxMargin;
       
   764         // Get the coordinate for the right margin of the checkbox.
       
   765         TInt checkBoxRight = AknLayoutScalable_Avkon::list_single_graphic_pane_t1( 0 ).r();
       
   766         // Get the coordinate for the left margin of the checkbox.
       
   767         TInt checkBoxLeft = AknLayoutScalable_Avkon::list_single_graphic_pane_t1( 0 ).l();
       
   768         // The width to display one char.
       
   769         TInt charWidth = aFont.CharWidthInPixels(aChar);
       
   770         TInt checkBoxWidth = checkBoxRight - checkBoxLeft;
       
   771         if( 0 > checkBoxWidth )
       
   772             {
       
   773             checkBoxWidth *= -1; // To make sure the value is positive.
       
   774             }
       
   775         if( charWidth > 0 && checkBoxWidth > 0 )
       
   776             {
       
   777             // The width of the characters which should be dropped, when marking
       
   778             // mode is active.
       
   779             TInt width;
       
   780             if( 0 == checkBoxWidth%charWidth )
       
   781                 {
       
   782                 width = checkBoxWidth;
       
   783                 }
       
   784             else
       
   785                 {
       
   786                 // The width should be divisible by charWidth.
       
   787                 width = ( checkBoxWidth/charWidth + 1 ) * charWidth;
       
   788                 }
       
   789             // When marking mode is on,
       
   790             // the width should minus the part of checkbox in the front of
       
   791             // a listbox item.
       
   792             aWidth -= width;
       
   793             }
       
   794         }
       
   795     }
       
   796 
       
   797 // End of File