phonebookui/Phonebook2/UIControls/src/CPbk2ContactViewListBox.cpp
branchRCL_3
changeset 85 38bb213f60ba
parent 63 f4a778e096c2
equal deleted inserted replaced
74:6b5524b4f673 85:38bb213f60ba
    39 #include <barsread.h>
    39 #include <barsread.h>
    40 #include <eikclbd.h>
    40 #include <eikclbd.h>
    41 
    41 
    42 #include <aknappui.h>
    42 #include <aknappui.h>
    43 #include <aknViewAppUi.h>
    43 #include <aknViewAppUi.h>
    44 #include <aknlayoutscalable_avkon.cdl.h>
       
    45 
    44 
    46 // Debugging headers
    45 // Debugging headers
    47 #include <Pbk2Debug.h>
    46 #include <Pbk2Debug.h>
    48 #include <featmgr.h>
    47 #include <featmgr.h>
    49 
    48 
    58 namespace {
    57 namespace {
    59 
    58 
    60 // LOCAL FUNCTIONS
    59 // LOCAL FUNCTIONS
    61 
    60 
    62 _LIT( KTabChar, "\t" );
    61 _LIT( KTabChar, "\t" );
    63 const TInt KCheckboxMargin = 1; // Checkbox margin pixels
       
    64 
    62 
    65 /**
    63 /**
    66  * Returns icon array from given list box.
    64  * Returns icon array from given list box.
    67  *
    65  *
    68  * @param aListBox  List box.
    66  * @param aListBox  List box.
   109                 MPbk2ContactUiControlExtension* aUiExtension,
   107                 MPbk2ContactUiControlExtension* aUiExtension,
   110                 CPbk2PredictiveSearchFilter &aSearchFilter ) :
   108                 CPbk2PredictiveSearchFilter &aSearchFilter ) :
   111                 iContainer(aContainer), 
   109                 iContainer(aContainer), 
   112                 iChangedIndexes( 1 ), // allocation granularity
   110                 iChangedIndexes( 1 ), // allocation granularity
   113                 iUiExtension( aUiExtension ),
   111                 iUiExtension( aUiExtension ),
   114                 iSearchFilter( aSearchFilter ),
   112                 iSearchFilter( aSearchFilter )
   115                 iMarkingModeOn( EFalse )
       
   116     {
   113     {
   117     }
   114     }
   118 
   115 
   119 // --------------------------------------------------------------------------
   116 // --------------------------------------------------------------------------
   120 // CPbk2ContactViewListBox::~CPbk2ContactViewListBox
   117 // CPbk2ContactViewListBox::~CPbk2ContactViewListBox
   443 // --------------------------------------------------------------------------
   440 // --------------------------------------------------------------------------
   444 //
   441 //
   445 TBool CPbk2ContactViewListBox::ClipFromBeginning
   442 TBool CPbk2ContactViewListBox::ClipFromBeginning
   446         ( TDes& aBuffer, TInt aItemIndex, TInt aSubCellNumber )
   443         ( TDes& aBuffer, TInt aItemIndex, TInt aSubCellNumber )
   447     {
   444     {
   448     CColumnListBoxData *data = ItemDrawer()->ColumnData();
   445     return AknTextUtils::ClipToFit( aBuffer,
   449     const CFont *font =
   446         AknTextUtils::EClipFromBeginning, this,  aItemIndex,
   450         data->Font(ItemDrawer()->Properties(aItemIndex), aSubCellNumber);
   447         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     }
   448     }
   471 
   449 
   472 // --------------------------------------------------------------------------
   450 // --------------------------------------------------------------------------
   473 // CPbk2ContactViewListBox::FocusedItemPointed
   451 // CPbk2ContactViewListBox::FocusedItemPointed
   474 // --------------------------------------------------------------------------
   452 // --------------------------------------------------------------------------
   551         {
   529         {
   552         iColumnData->SetDataModel( iModel );
   530         iColumnData->SetDataModel( iModel );
   553         }
   531         }
   554     // Wrap the original model.
   532     // Wrap the original model.
   555     iListboxModelDecorator = DoCreateDecoratorL( 
   533     iListboxModelDecorator = DoCreateDecoratorL( 
   556             *IconArray( *this ),
   534     		*IconArray( *this ),
   557             iResourceData.iEmptyIconId,
   535 			iResourceData.iEmptyIconId,
   558             iResourceData.iDefaultIconId );
   536 			iResourceData.iDefaultIconId );
   559     
   537     
   560     
   538     
   561     iListboxModelDecorator->SetDecoratedModel( *iModel );
   539     iListboxModelDecorator->SetDecoratedModel( *iModel );
   562     Model()->SetItemTextArray( iListboxModelDecorator );
   540     Model()->SetItemTextArray( iListboxModelDecorator );
   563     Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
   541     Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
   577 // --------------------------------------------------------------------------
   555 // --------------------------------------------------------------------------
   578 // CPbk2ContactViewListBox::DoCreateDecoratorL
   556 // CPbk2ContactViewListBox::DoCreateDecoratorL
   579 // --------------------------------------------------------------------------
   557 // --------------------------------------------------------------------------
   580 //
   558 //
   581 CPbk2ListboxModelCmdDecorator* CPbk2ContactViewListBox::DoCreateDecoratorL( 
   559 CPbk2ListboxModelCmdDecorator* CPbk2ContactViewListBox::DoCreateDecoratorL( 
   582                 const CPbk2IconArray& aIconArray,
   560         		const CPbk2IconArray& aIconArray,
   583                 TPbk2IconId aEmptyIconId,
   561         		TPbk2IconId aEmptyIconId,
   584                 TPbk2IconId aDefaultIconId )
   562         		TPbk2IconId aDefaultIconId )
   585     {
   563 	{
   586     return CPbk2ListboxModelCmdDecorator::NewL(
   564 	return CPbk2ListboxModelCmdDecorator::NewL(
   587                 aIconArray,
   565 				aIconArray,
   588                 aEmptyIconId,
   566 				aEmptyIconId,
   589                 aDefaultIconId );
   567 				aDefaultIconId );
   590     }
   568 	}
   591 
   569 
   592 
   570 
   593 // --------------------------------------------------------------------------
   571 // --------------------------------------------------------------------------
   594 // CPbk2ContactViewListBox::IsContact
   572 // CPbk2ContactViewListBox::IsContact
   595 // --------------------------------------------------------------------------
   573 // --------------------------------------------------------------------------
   642 // CPbk2ContactViewListBox::HandleGainingForeground
   620 // CPbk2ContactViewListBox::HandleGainingForeground
   643 // --------------------------------------------------------------------------
   621 // --------------------------------------------------------------------------
   644 //
   622 //
   645 void CPbk2ContactViewListBox::HandleGainingForeground()
   623 void CPbk2ContactViewListBox::HandleGainingForeground()
   646     {
   624     {
   647     DrawDeferred();
   625 	DrawDeferred();
   648     }
   626     }
   649 
   627 
   650 // --------------------------------------------------------------------------
   628 // --------------------------------------------------------------------------
   651 // CPbk2ContactViewListBox::HandleLosingForeground
   629 // CPbk2ContactViewListBox::HandleLosingForeground
   652 // --------------------------------------------------------------------------
   630 // --------------------------------------------------------------------------
   724 
   702 
   725         TAknLayoutText textLayout;
   703         TAknLayoutText textLayout;
   726         textLayout.LayoutText(layout.Rect(), AknLayoutScalable_Apps::popup_navstr_preview_pane_t1(0).LayoutLine());
   704         textLayout.LayoutText(layout.Rect(), AknLayoutScalable_Apps::popup_navstr_preview_pane_t1(0).LayoutLine());
   727 
   705 
   728         TPtrC desc(Model()->ItemTextArray()->MdcaPoint(View()->TopItemIndex()));
   706         TPtrC desc(Model()->ItemTextArray()->MdcaPoint(View()->TopItemIndex()));
   729         
   707 		
   730         //Add "if-clause" to avaid the error that argument of Mid() out of range.
   708         //Add "if-clause" to avaid the error that argument of Mid() out of range.
   731         TInt index = desc.Find( KTabChar );
   709         TInt index = desc.Find( KTabChar );
   732         if ( index != KErrNotFound && index < desc.Length()-1 )
   710         if ( index != KErrNotFound && index < desc.Length()-1 )
   733             {
   711             {
   734             HBufC* buf = desc.Mid( index + 1, 1 ).AllocL();           
   712             HBufC* buf = desc.Mid( index + 1, 1 ).AllocL();           
   740 
   718 
   741             delete buf;
   719             delete buf;
   742             }
   720             }
   743         }
   721         }
   744     }
   722     }
   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
   723 // End of File