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