emailcontacts/contactactionmenu/src/cfsccontactactionmenulist.cpp
changeset 0 8466d47a6819
child 17 8592a65ad3fb
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation of the class CFscContactActionMenuList.
       
    15 *
       
    16 */
       
    17 //<cmail> Layout changes
       
    18 
       
    19 
       
    20 // INCUDES
       
    21 #include "emailtrace.h"
       
    22 #include <e32std.h>
       
    23 #include <e32base.h>
       
    24 #include <eikclbd.h>
       
    25 #include <aknlayoutscalable_avkon.cdl.h>
       
    26 #include <gulicon.h>
       
    27 #include <coeaui.h>
       
    28 #include <coefontprovider.h>
       
    29 #include <gulfont.h>
       
    30 #include <AknBidiTextUtils.h> 
       
    31 #include <AknLayoutFont.h> 
       
    32 #include <AknLayout2ScalableDataDef.h>
       
    33 #include <AknLayout2ScalableDef.h>
       
    34 #include <layoutmetadata.cdl.h>
       
    35 #include <CdlEngine.h>
       
    36 #include <coemain.h>
       
    37 #include <AknsListBoxBackgroundControlContext.h> 
       
    38 
       
    39 #include <aknlayoutscalable_apps.cdl.h>
       
    40 #include <layoutmetadata.cdl.h>
       
    41 
       
    42 #include "cfsccontactactionmenulist.h"
       
    43 #include "mfsccontactactionmenulistobserver.h"
       
    44 #include "mfsccontactactionmenumodel.h"
       
    45 #include "cfsccontactactionmenuitem.h"
       
    46 #include "cfsccontactactionmenulistbox.h"
       
    47 #include "fsccontactactionmenuuidefines.h"
       
    48 
       
    49 //_LIT( KListItemTextFormat, "%d\t%S" );
       
    50 _LIT( KListItemTextFormat, "\t%d\t\t%S" );
       
    51 
       
    52 const TInt KPeriodicDelay = 0; // immediately
       
    53 const TInt KPeriodicInterval = 20*1000; // 20ms
       
    54 
       
    55 // ======== LOCAL FUNCTIONS ========
       
    56 
       
    57 // ======== MEMBER FUNCTIONS ========
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CFscContactActionMenuList::NewL
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CFscContactActionMenuList* CFscContactActionMenuList::NewL(
       
    64     MFscContactActionMenuListObserver* aObserver, 
       
    65     MFscContactActionMenuModel* aModel,
       
    66     TBool aAiMode, 
       
    67     MFsActionMenuPositionGiver* aPositionGiver,
       
    68     TBool aOpenedFromMR )
       
    69     {
       
    70     FUNC_LOG;
       
    71 
       
    72     CFscContactActionMenuList* self = new (ELeave) CFscContactActionMenuList( 
       
    73             aObserver, aModel, aAiMode, aPositionGiver, aOpenedFromMR );
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL();
       
    76     CleanupStack::Pop( self );
       
    77         
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CFscContactActionMenuList::~CFscContactActionMenuList
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CFscContactActionMenuList::~CFscContactActionMenuList()
       
    86     {
       
    87     FUNC_LOG;
       
    88     Hide( EFalse );
       
    89     delete iPeriodic;
       
    90     ClearControls();
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CFscContactActionMenuList::OfferKeyEventL
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 TKeyResponse CFscContactActionMenuList::OfferKeyEventL(
       
    98     const TKeyEvent& aKeyEvent, TEventCode aType )
       
    99     {
       
   100     FUNC_LOG;
       
   101 
       
   102     TKeyResponse ret = ( EKeyWasConsumed );
       
   103     
       
   104     if ( iObserver->IsOperationCompleted() )
       
   105         {
       
   106         ret = EKeyWasNotConsumed;
       
   107         TInt closeKey = AknLayoutUtils::LayoutMirrored() ? 
       
   108             EStdKeyRightArrow : EStdKeyLeftArrow;
       
   109         if ( aType == EEventKey && aKeyEvent.iScanCode == closeKey )
       
   110             {
       
   111             iObserver->HandleListEvent( 
       
   112                 MFscContactActionMenuListObserver::EFscMenuEventCloseKey );
       
   113             ret = EKeyWasConsumed;
       
   114             }
       
   115         else if ( aType == EEventKey && aKeyEvent.iCode == EKeyEscape )
       
   116             {
       
   117             ret = EKeyWasConsumed;
       
   118             // Handle application exit
       
   119             iObserver->HandleListEvent( 
       
   120                 MFscContactActionMenuListObserver::EFscMenuEventExitKey );
       
   121             }
       
   122         else if ( aType == EEventKey && aKeyEvent.iCode == EKeyYes )
       
   123         	{
       
   124         	// Send key is not active in the action menu
       
   125         	ret = EKeyWasConsumed;
       
   126         	}
       
   127         else if ( !iAiMode ||
       
   128                   aKeyEvent.iScanCode == EStdKeyRightArrow || 
       
   129                   aKeyEvent.iScanCode == EStdKeyUpArrow || 
       
   130                   aKeyEvent.iScanCode == EStdKeyDownArrow ||  
       
   131                   aKeyEvent.iScanCode == EStdKeyEnter ||
       
   132                   aKeyEvent.iScanCode == EStdKeyDevice0 || //RSK 
       
   133                   aKeyEvent.iScanCode == EStdKeyDevice1 || //LSK
       
   134                   aKeyEvent.iScanCode == EStdKeyDevice3  ) //
       
   135             {
       
   136             ret = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   137             }
       
   138         else if ( aType == EEventKey )
       
   139             {
       
   140             // iAiMode == ETrue && some special key pressed
       
   141             // Inform observer and remove menu from stack
       
   142             iObserver->HandleListEvent( 
       
   143                 MFscContactActionMenuListObserver::EFscMenuEventExitKey );
       
   144             }    
       
   145         }
       
   146     
       
   147     return ret;     
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // <cmail> Touch
       
   152 // CFscContactActionMenuList::HandlePointerEventL
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CFscContactActionMenuList::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   156     {
       
   157     iListHasConsumedPointed = EFalse;
       
   158     iListBox->HandlePointerEventL(aPointerEvent);
       
   159     if (!iListHasConsumedPointed && aPointerEvent.iType == TPointerEvent::EButton1Up)
       
   160         {
       
   161         Hide(ETrue);
       
   162         }
       
   163     }
       
   164 
       
   165 // </cmail>
       
   166 // ---------------------------------------------------------------------------
       
   167 // CFscContactActionMenuList::HandleResourceChange
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CFscContactActionMenuList::HandleResourceChange( TInt aType )
       
   171     {
       
   172     FUNC_LOG;
       
   173     CCoeControl::HandleResourceChange( aType );
       
   174     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   175         {
       
   176         //This code was commented out because of ELLO-7PDHT2
       
   177         //but perhaps error related to switching layout may be fixed, so
       
   178         //code is left here for future use
       
   179         if ( iOpenedFromMR )
       
   180             {
       
   181             iObserver->HandleListEvent( 
       
   182                 MFscContactActionMenuListObserver::EFscMenuLayoutChanged );
       
   183             }
       
   184         else
       
   185             {
       
   186             LayoutPopupWindow( ETrue );
       
   187             }
       
   188         }
       
   189     else if ( aType == KAknsMessageSkinChange ||
       
   190               aType == KEikMessageColorSchemeChange )
       
   191         {
       
   192         UpdateColors();
       
   193         DrawDeferred();
       
   194         }
       
   195            
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // CFscContactActionMenuList::CountComponentControls
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 TInt CFscContactActionMenuList::CountComponentControls() const
       
   203     {
       
   204     FUNC_LOG;
       
   205     TInt result = 1;
       
   206     return result;
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CFscContactActionMenuList::ComponentControl
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 CCoeControl* CFscContactActionMenuList::ComponentControl( TInt aIndex ) const
       
   214     {
       
   215     FUNC_LOG;
       
   216     CCoeControl* control = NULL;
       
   217 
       
   218     if ( aIndex == 0 && iListBox != NULL )
       
   219         {
       
   220         control = iListBox;
       
   221         } // No need for else block  
       
   222 
       
   223     return control;
       
   224     }
       
   225     
       
   226 // ---------------------------------------------------------------------------
       
   227 // CFscContactActionMenuList::HandleListBoxEventL
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 void CFscContactActionMenuList::HandleListBoxEventL(
       
   231     CEikListBox* aListBox, TListBoxEvent aEventType )
       
   232     {
       
   233     FUNC_LOG;
       
   234     if( aListBox == iListBox )
       
   235         {
       
   236 // <cmail> Touch
       
   237     // Handle pointer events
       
   238        TBool executeAction = EFalse;
       
   239        if ( aEventType == EEventItemDraggingActioned )
       
   240            {
       
   241            iHasBeenDragged = ETrue;
       
   242            }
       
   243        else if ( aEventType == EEventItemClicked )
       
   244            {
       
   245            if (!iHasBeenDragged)
       
   246                {
       
   247                executeAction = ETrue;
       
   248                }
       
   249            else
       
   250                {
       
   251                iHasBeenDragged = EFalse;
       
   252                }
       
   253            }
       
   254        else if ( aEventType == EEventEnterKeyPressed)
       
   255            {
       
   256            executeAction = ETrue;
       
   257            iHasBeenDragged = EFalse;
       
   258            }
       
   259        iListHasConsumedPointed = ETrue;
       
   260        if ( executeAction )
       
   261            {
       
   262            iObserver->HandleListEvent( 
       
   263                            MFscContactActionMenuListObserver::EFscMenuEventItemClicked 
       
   264                            );
       
   265            }
       
   266         
       
   267         /*
       
   268         if ( aEventType == EEventItemClicked || 
       
   269             aEventType == EEventEnterKeyPressed )
       
   270             {
       
   271             iObserver->HandleListEvent( 
       
   272                 MFscContactActionMenuListObserver::EFscMenuEventItemClicked 
       
   273                 );
       
   274             }*/
       
   275 // </cmail>
       
   276         }
       
   277     
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // CFscContactActionMenuList::ShowL
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 // <cmail> Touch
       
   285 void CFscContactActionMenuList::ShowL( 
       
   286     TFscContactActionMenuPosition aPosition,
       
   287     TInt aIndex )
       
   288     {
       
   289     FUNC_LOG;
       
   290       
       
   291     iPosition = aPosition;
       
   292 // </cmail>    
       
   293 
       
   294     //UpdateListContentL();
       
   295     //UpdateWindowL();
       
   296     UpdateColors();
       
   297     
       
   298     DrawableWindow()->SetOrdinalPosition( KZero, KZero );
       
   299     SetupMenuOffset();
       
   300     iState = ESlidingIn;
       
   301     iMenuOffset.SetWithSpeed( KZero, KMenuSlideSpeed );
       
   302     if ( iMenuOffset.Interpolating() && !iPeriodic->IsActive() )
       
   303         {
       
   304         TCallBack callback( UpdateWindowPosition, this );
       
   305         iPeriodic->Start( KPeriodicDelay, KPeriodicInterval, callback );
       
   306         }
       
   307     
       
   308     iEikonEnv->EikAppUi()->AddToStackL( this, ECoeStackPriorityDialog );
       
   309     MakeVisible( ETrue );
       
   310     SetFocus( ETrue, EDrawNow ); 
       
   311     iListBox->SetCurrentItemIndex( aIndex );
       
   312         
       
   313     DrawDeferred();
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CFscContactActionMenuList::Hide
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 void CFscContactActionMenuList::Hide( TBool aSlide )
       
   321     {
       
   322     FUNC_LOG;
       
   323     
       
   324     if ( aSlide && ( iState == EIn || iState == ESlidingIn ) )
       
   325         {
       
   326         // Start sliding out when menu is fully or partialy shown
       
   327         iState = ESlidingOut;
       
   328         const TInt windowWidth( Rect().Width() );
       
   329         TInt newPos = 
       
   330             AknLayoutUtils::LayoutMirrored() ? 
       
   331                 -windowWidth : windowWidth;
       
   332         iMenuOffset.SetWithSpeed( newPos, KMenuSlideSpeed );
       
   333         if ( iMenuOffset.Interpolating() && !iPeriodic->IsActive() )
       
   334             {
       
   335             TCallBack callback( UpdateWindowPosition, this );
       
   336             iPeriodic->Start( KPeriodicDelay, KPeriodicInterval, callback );
       
   337             }
       
   338         }
       
   339     else
       
   340         {
       
   341         // Hide menu now
       
   342         SetFocus( EFalse );
       
   343         MakeVisible( EFalse );
       
   344         iEikonEnv->EikAppUi()->RemoveFromStack( this );
       
   345         
       
   346         // If periodic running, stop it
       
   347         iPeriodic->Cancel();  
       
   348         
       
   349         if ( iState != EOut )
       
   350             {
       
   351             iState = EOut;
       
   352             // Inform observer         
       
   353             iObserver->HandleListEvent( 
       
   354                 MFscContactActionMenuListObserver::EFscMenuEventMenuHidden
       
   355                 );  
       
   356             }
       
   357         }
       
   358     
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // CFscContactActionMenuList::SelectedItemIndex
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 TInt CFscContactActionMenuList::SelectedItemIndex()
       
   366     {
       
   367     FUNC_LOG;
       
   368     return iListBox->CurrentItemIndex();
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // CFscContactActionMenuList::ItemCount
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 TInt CFscContactActionMenuList::ItemCount()
       
   376     {
       
   377     FUNC_LOG;
       
   378     return iListBox->Model()->ItemTextArray()->MdcaCount();
       
   379     }   
       
   380 
       
   381 // ---------------------------------------------------------------------------
       
   382 // CFscContactActionMenuList::CFscContactActionMenuList
       
   383 // ---------------------------------------------------------------------------
       
   384 //
       
   385 // <cmail>
       
   386 CFscContactActionMenuList::CFscContactActionMenuList(
       
   387     MFscContactActionMenuListObserver* aObserver, 
       
   388     MFscContactActionMenuModel* aModel,
       
   389     TBool aAiMode,
       
   390     MFsActionMenuPositionGiver* aPositionGiver,
       
   391     TBool aOpenedFromMR )
       
   392     : iState( EOut ), iObserver( aObserver ), iModel( aModel ),
       
   393       iAiMode( aAiMode ), iPositionGiver(aPositionGiver),
       
   394       iOpenedFromMR( aOpenedFromMR )
       
   395     {
       
   396 // </cmail>
       
   397     FUNC_LOG;
       
   398     ASSERT( aObserver != NULL && aModel != NULL);
       
   399     
       
   400     iListItemId = KAknsIIDQgnFsGrafContactsContent;
       
   401     iListBottomId = KAknsIIDQsnBgColumnA;  
       
   402     iHighlightId = KAknsIIDQgnFsList;
       
   403     iHighlightCenterId = KAknsIIDQgnFsListCenter;   
       
   404     
       
   405     }
       
   406 
       
   407 // ---------------------------------------------------------------------------
       
   408 // CFscContactActionMenuList::ConstructL
       
   409 // ---------------------------------------------------------------------------
       
   410 //
       
   411 void CFscContactActionMenuList::ConstructL()
       
   412     {
       
   413     FUNC_LOG;
       
   414     
       
   415     iPeriodic = CPeriodic::NewL( CActive::EPriorityUserInput );
       
   416     
       
   417     CreateWindowL();
       
   418 
       
   419     SetNonFocusing();
       
   420     SetBlank();    // This control need not draw
       
   421 #ifndef FF_CMAIL_INTEGRATION
       
   422     EnableWindowTransparency(); //Needed to draw background correctly Not supported in 5.0
       
   423 #endif
       
   424     
       
   425     // <cmail> Touch
       
   426     Window().SetPointerCapture(RWindowBase::TCaptureFlagEnabled | RWindowBase::TCaptureFlagAllGroups);
       
   427     // </cmail>
       
   428     
       
   429     //InitializeLayoutL();    
       
   430     ConstructControlsL();    
       
   431     
       
   432     // Finalize construct
       
   433     MakeVisible(ETrue);
       
   434     ActivateL();
       
   435 
       
   436     }   
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // CFscContactActionMenuList::LayoutList
       
   440 // ---------------------------------------------------------------------------
       
   441 //
       
   442 TInt CFscContactActionMenuList::LayoutList()
       
   443     {
       
   444     FUNC_LOG;
       
   445     TRAPD( error, LayoutListL() );
       
   446     return error;
       
   447     }
       
   448 
       
   449 // ---------------------------------------------------------------------------
       
   450 // CFscContactActionMenuList::LayoutListL
       
   451 // ---------------------------------------------------------------------------
       
   452 //
       
   453 void CFscContactActionMenuList::LayoutListL()
       
   454     {
       
   455     FUNC_LOG;
       
   456 
       
   457     const TRect menuPaneRect( Rect() );
       
   458 
       
   459     // Menu list pane
       
   460     TAknLayoutRect menuListPane;
       
   461     menuListPane.LayoutRect( menuPaneRect, 
       
   462             AknLayoutScalable_Apps::sp_fs_action_menu_list_pane( 
       
   463                     Max( 0, iModel->ItemCount() - 1 ) ) );
       
   464     const TRect menuPaneListRect( menuListPane.Rect() );
       
   465 
       
   466     // Menu gene pane
       
   467     TAknLayoutRect menuGenePane;
       
   468     menuGenePane.LayoutRect( menuPaneListRect, 
       
   469             AknLayoutScalable_Apps::sp_fs_action_menu_list_gene_pane( 0 ) );
       
   470     const TRect menuGenePaneRect( menuGenePane.Rect() );
       
   471            
       
   472     // Menu gene pane g1
       
   473     TAknLayoutRect menuGenePaneG1;
       
   474     menuGenePaneG1.LayoutRect( menuGenePaneRect, 
       
   475             AknLayoutScalable_Apps::sp_fs_action_menu_list_gene_pane_g1( 0 ) );
       
   476     const TRect menuGenePaneG1Rect( menuGenePaneG1.Rect() );
       
   477 
       
   478     // Menu gene pane t1
       
   479     TAknLayoutText menuGenePaneT1;
       
   480     menuGenePaneT1.LayoutText( menuGenePaneRect, 
       
   481             AknLayoutScalable_Apps::sp_fs_action_menu_list_gene_pane_t1( 0 ) );
       
   482     const TRect menuGenePaneT1Rect( menuGenePaneT1.TextRect() );
       
   483     iFont = menuGenePaneT1.Font();
       
   484 
       
   485     iListBox->SetRect( menuPaneListRect );
       
   486    
       
   487     // Setup listbox columns
       
   488     CColumnListBoxData& columnData( *iListBox->ItemDrawer()->ColumnData() );
       
   489     columnData.SetColumnWidthPixelL( ELeftMarginColumn, 
       
   490             LeftMargin( menuGenePaneRect, menuGenePaneG1Rect ) );        
       
   491     columnData.SetColumnWidthPixelL( EIconColumn, menuGenePaneG1Rect.Width() );
       
   492     columnData.SetColumnWidthPixelL( EMidleMarginColumn, 
       
   493             MiddleMargin( menuGenePaneG1Rect, menuGenePaneT1Rect ) );
       
   494     columnData.SetColumnWidthPixelL( ETextColumn, menuGenePaneT1Rect.Width() );    
       
   495     columnData.SetGraphicsColumnL( EIconColumn, ETrue );
       
   496     columnData.SetColumnFontL( ETextColumn, iFont );         
       
   497     columnData.SetColumnBaselinePosL( ETextColumn,
       
   498             iFont->HeightInPixels() + 
       
   499             (menuGenePaneRect.Height() - iFont->HeightInPixels() - iFont->FontMaxDescent()) / 2 );
       
   500         
       
   501     AknLayoutUtils::LayoutMirrored() ? 
       
   502         columnData.SetColumnAlignmentL( ETextColumn, CGraphicsContext::ERight ) : 
       
   503         columnData.SetColumnAlignmentL( ETextColumn, CGraphicsContext::ELeft );
       
   504 
       
   505     // Setup item height
       
   506     columnData.SetItemCellSize( menuGenePaneRect.Size() );    
       
   507     iListBox->SetItemHeightL( menuGenePaneRect.Height() );    
       
   508     iListBox->SetBackgroundRect( menuPaneRect );  
       
   509 
       
   510     UpdateListContentL( menuGenePaneG1Rect.Size() );
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------------------------
       
   514 // CFscContactActionMenuList::LeftMargin
       
   515 // ---------------------------------------------------------------------------
       
   516 //
       
   517 TInt CFscContactActionMenuList::LeftMargin( const TRect& aMenuPane, 
       
   518         const TRect& aG1 ) const
       
   519     {
       
   520     FUNC_LOG;
       
   521     if ( AknLayoutUtils::LayoutMirrored() )
       
   522         {
       
   523         return Abs( aMenuPane.iBr.iX - aG1.iBr.iX );
       
   524         }
       
   525     return Abs( aG1.iTl.iX - aMenuPane.iTl.iX );
       
   526     }
       
   527 
       
   528 // ---------------------------------------------------------------------------
       
   529 // CFscContactActionMenuList::MiddleMargin
       
   530 // ---------------------------------------------------------------------------
       
   531 //
       
   532 TInt CFscContactActionMenuList::MiddleMargin( const TRect& aG1, 
       
   533         const TRect& aT1 ) const
       
   534     {
       
   535     FUNC_LOG;
       
   536     if ( AknLayoutUtils::LayoutMirrored() )
       
   537         {
       
   538         return Abs( aG1.iTl.iX - aT1.iBr.iX );
       
   539         }
       
   540     return Abs( aG1.iBr.iX - aT1.iTl.iX );
       
   541     }
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // CFscContactActionMenuList::RightMargin
       
   545 // ---------------------------------------------------------------------------
       
   546 //
       
   547 TInt CFscContactActionMenuList::RightMargin( const TRect& aMenuPane, 
       
   548         const TRect& aT1 ) const
       
   549     {
       
   550     FUNC_LOG;
       
   551     if ( AknLayoutUtils::LayoutMirrored() )
       
   552         {
       
   553         return Abs( aT1.iTl.iX - aMenuPane.iTl.iX );
       
   554         }
       
   555     return Abs( aMenuPane.iBr.iX - aT1.iBr.iX );    
       
   556     }
       
   557 
       
   558 // ---------------------------------------------------------------------------
       
   559 // CFscContactActionMenuList::ConstructControlsL
       
   560 // ---------------------------------------------------------------------------
       
   561 //
       
   562 void CFscContactActionMenuList::ConstructControlsL()
       
   563     {
       
   564     FUNC_LOG;
       
   565         
       
   566     // Create list control
       
   567     iListBox = new ( ELeave ) CFscContactActionMenuListBox();
       
   568     iListBox->ConstructL( this );
       
   569     iListBox->HandleItemAdditionL();
       
   570     iListBox->SetFocus( ETrue );
       
   571     iListBox->SetContainerWindowL( *this );
       
   572     iListBox->SetListBoxObserver( this );           
       
   573     // Set icon array
       
   574     CArrayPtrFlat<CGulIcon>* iconArray = 
       
   575         new (ELeave) CArrayPtrFlat<CGulIcon>( KGranularity );
       
   576     iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray );
       
   577     LayoutPopupWindow();
       
   578     }   
       
   579 
       
   580 // ---------------------------------------------------------------------------
       
   581 // CFscContactActionMenuList::ClearControls
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 void CFscContactActionMenuList::ClearControls()
       
   585     {
       
   586     FUNC_LOG;
       
   587     
       
   588     if ( iListBox )
       
   589         {
       
   590         delete iListBox;
       
   591         iListBox = NULL;
       
   592         }
       
   593 
       
   594     }  
       
   595 
       
   596 // ---------------------------------------------------------------------------
       
   597 // CFscContactActionMenuList::UpdateListL
       
   598 // ---------------------------------------------------------------------------
       
   599 //
       
   600 void CFscContactActionMenuList::UpdateListContentL( const TSize& aIconSize )
       
   601     {
       
   602     FUNC_LOG;
       
   603 
       
   604     CDesCArray* desArray =
       
   605         static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
       
   606     desArray->Reset();
       
   607 
       
   608     CArrayPtr<CGulIcon>* iconArray = 
       
   609         iListBox->ItemDrawer()->ColumnData()->IconArray();
       
   610     iconArray->ResetAndDestroy(); // Remove old icons  
       
   611     
       
   612     TInt itemCount = iModel->VisibleItemCount();
       
   613     for ( TInt i = 0; i < itemCount; i++ )
       
   614         {
       
   615         CFscContactActionMenuItem& item = iModel->VisibleItemL( i );
       
   616         
       
   617         const CGulIcon* origIcon = item.Icon();
       
   618         ASSERT( origIcon != NULL );
       
   619         
       
   620         CGulIcon* icon = CGulIcon::NewL( 
       
   621             origIcon->Bitmap(), origIcon->Mask() );
       
   622         CleanupStack::PushL( icon );
       
   623         icon->SetBitmapsOwnedExternally( ETrue );
       
   624             
       
   625         AknIconUtils::SetSize( icon->Bitmap(), aIconSize );
       
   626         AknIconUtils::SetSize( icon->Mask(), aIconSize );
       
   627         iconArray->AppendL(icon);
       
   628         CleanupStack::Pop( icon );  
       
   629         
       
   630         const TDesC& text = item.MenuText();
       
   631         HBufC* tempDes = HBufC::NewLC( 
       
   632                 text.Length() + KListItemTextFormat().Length() );
       
   633         tempDes->Des().Format( KListItemTextFormat, i, &text );
       
   634         desArray->AppendL( *tempDes );
       
   635         CleanupStack::PopAndDestroy( tempDes );         
       
   636         }
       
   637                 
       
   638     iListBox->HandleItemAdditionL();
       
   639     iListBox->UpdateScrollBarsL();
       
   640 
       
   641     }
       
   642    
       
   643 // ---------------------------------------------------------------------------
       
   644 // CFscContactActionMenuList::SetupMenuOffset
       
   645 // ---------------------------------------------------------------------------
       
   646 //
       
   647 void CFscContactActionMenuList::SetupMenuOffset()
       
   648     {
       
   649     FUNC_LOG;
       
   650 
       
   651     switch( iState )
       
   652         {
       
   653         case EOut:
       
   654         case ESlidingOut:
       
   655             {
       
   656             const TInt windowWidth( Rect().Width() );
       
   657             // Menu is out of the screen
       
   658             TInt newPos = 
       
   659             AknLayoutUtils::LayoutMirrored() ? 
       
   660                 -windowWidth : windowWidth;
       
   661             iMenuOffset.Set( newPos );    
       
   662             }
       
   663             break;
       
   664         case EIn:
       
   665         case ESlidingIn:
       
   666             {
       
   667             // Menu is visible
       
   668             iMenuOffset.Set( 0 );
       
   669             }
       
   670             break;    
       
   671         default:
       
   672             {
       
   673             //Nothing to do
       
   674             break;
       
   675             }  
       
   676         }
       
   677     
       
   678     }
       
   679     
       
   680     
       
   681 // ---------------------------------------------------------------------------
       
   682 // CFscContactActionMenuList::UpdateColors
       
   683 // ---------------------------------------------------------------------------
       
   684 //
       
   685 void CFscContactActionMenuList::UpdateColors()
       
   686     {
       
   687     FUNC_LOG;
       
   688     
       
   689     MAknsSkinInstance* skin = AknsUtils::SkinInstance(); 
       
   690     TRgb color;    
       
   691         
       
   692     // Highlight text color    
       
   693     TInt error = AknsUtils::GetCachedColor( 
       
   694         skin, color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG10 );    
       
   695     if ( !error )
       
   696         {
       
   697         iListBox->ItemDrawer()->SetHighlightedTextColor( color );
       
   698         }
       
   699     else
       
   700         {
       
   701         error = AknsUtils::GetCachedColor( 
       
   702             skin, color, KAknsIIDFsHighlightColors, EAknsCIFsHighlightColorsCG1 );
       
   703         if ( !error )
       
   704             {
       
   705             iListBox->ItemDrawer()->SetHighlightedTextColor( color );
       
   706             }
       
   707         }
       
   708         
       
   709     // Text color
       
   710     error = AknsUtils::GetCachedColor( 
       
   711         skin, color, KAknsIIDFsTextColors, EAknsCIQsnTextColorsCG19 ); 
       
   712     if ( !error )
       
   713         { 
       
   714         iListBox->ItemDrawer()->SetTextColor( color );
       
   715         }
       
   716     else
       
   717         {
       
   718         // if colors are not found from the skins, set the default values
       
   719         error = AknsUtils::GetCachedColor( 
       
   720             skin, color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
       
   721         if ( !error )
       
   722             {
       
   723             iListBox->ItemDrawer()->SetTextColor( color );
       
   724             }
       
   725         }
       
   726                
       
   727     }    
       
   728     
       
   729 // ---------------------------------------------------------------------------
       
   730 // CFscContactActionMenuList::MaxListTextWidth
       
   731 // ---------------------------------------------------------------------------
       
   732 //
       
   733 TInt CFscContactActionMenuList::MaxListTextWidth()
       
   734     {
       
   735     FUNC_LOG;
       
   736     TPtrC itemText;
       
   737     TInt maxLength( 0 );
       
   738     for ( TInt i = 0; i < iModel->VisibleItemCount(); i++ )
       
   739         {
       
   740         TRAPD( error, itemText.Set( iModel->VisibleItemL( i ).MenuText() ) );
       
   741         if ( !error )
       
   742             {
       
   743             TInt offset( itemText.LocateReverse( TChar('\t') ) );        
       
   744             if ( offset != KErrNotFound && ++offset < itemText.Length() )
       
   745                 {
       
   746                 itemText.Set( itemText.Mid( offset ) );            
       
   747                 }        
       
   748             const TInt length( AknBidiTextUtils::MeasureTextBoundsWidth(
       
   749                 *iFont, itemText, CFont::TMeasureTextInput::EFVisualOrder ) );
       
   750             maxLength = length > maxLength ? length : maxLength;
       
   751             }
       
   752         }
       
   753     return maxLength;
       
   754     }
       
   755 
       
   756 // ---------------------------------------------------------------------------
       
   757 // CFscContactActionMenuList::UpdateWindowPosition
       
   758 // ---------------------------------------------------------------------------
       
   759 //   
       
   760 TInt CFscContactActionMenuList::UpdateWindowPosition( TAny *aPtr )
       
   761     {
       
   762     FUNC_LOG;
       
   763     CFscContactActionMenuList* list = 
       
   764         static_cast<CFscContactActionMenuList*>( aPtr );
       
   765     
       
   766     TRect newRect( list->iOrigMenuRect ); 
       
   767     newRect.Move( list->iMenuOffset.Now(), 0 ); 
       
   768     list->SetPosition( newRect.iTl );
       
   769 
       
   770     if ( !list->iMenuOffset.Interpolating() )
       
   771         {
       
   772         // Stop timer
       
   773         list->iPeriodic->Cancel();
       
   774         if ( list->iState == ESlidingOut )
       
   775             { 
       
   776             // Hide window totally
       
   777             list->iState = EOut;
       
   778             list->SetFocus( EFalse );
       
   779             list->MakeVisible( EFalse );
       
   780             static_cast< CEikonEnv* >
       
   781                 ( list->iCoeEnv )->EikAppUi()->RemoveFromStack( list );
       
   782                 
       
   783             // Inform observer        
       
   784             list->iObserver->HandleListEvent( 
       
   785                 MFscContactActionMenuListObserver::EFscMenuEventMenuHidden 
       
   786                 );        
       
   787             }
       
   788         else if ( list->iState == ESlidingIn )
       
   789             {
       
   790             list->iState = EIn;
       
   791             }
       
   792         }  
       
   793               
       
   794     return KErrNone;
       
   795     }
       
   796 
       
   797 // ---------------------------------------------------------------------------
       
   798 // CFscContactActionMenuList::LayoutPopupWindow
       
   799 // ---------------------------------------------------------------------------
       
   800 //   
       
   801 void CFscContactActionMenuList::LayoutPopupWindow( const TBool aLayoutChange )
       
   802     {
       
   803     FUNC_LOG;
       
   804     // Application window
       
   805     TRect applicationRect;
       
   806     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EApplicationWindow,
       
   807         applicationRect );
       
   808 
       
   809     // Main 2 pane. This is the main pane that is used as parent layout
       
   810     // for the popup menup pane in the layout data, but using this would
       
   811     // make popup to overlap with the cba area.
       
   812     TAknLayoutRect main2Pane;
       
   813     main2Pane.LayoutRect( applicationRect, AknLayoutScalable_Apps::main2_pane(
       
   814         Layout_Meta_Data::IsLandscapeOrientation() ? 2 : 3 ) );
       
   815     TRect main2PaneRect = main2Pane.Rect();
       
   816 
       
   817     // Main pane
       
   818     TRect mainPaneRect;
       
   819     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
   820 
       
   821     // Menu pane
       
   822     TAknLayoutRect menuPane;
       
   823     menuPane.LayoutRect( mainPaneRect,
       
   824         AknLayoutScalable_Apps::popup_sp_fs_action_menu_pane(
       
   825             iModel->ItemCount() + 1 ) );
       
   826 
       
   827     iOrigMenuRect = menuPane.Rect();
       
   828     AdjustByContent( iOrigMenuRect );
       
   829     if ( iPositionGiver )
       
   830         {
       
   831         TPoint customPos = iPositionGiver->ActionMenuPosition();
       
   832         iOrigMenuRect.Move( 0, -iOrigMenuRect.iTl.iY + mainPaneRect.iTl.iY
       
   833             + customPos.iY );
       
   834         }
       
   835 
       
   836     // Adjust menu pane position to keep it fully visible. The main2pane is
       
   837     // used here to enable menu pane to overlap with status pane area.
       
   838     if ( iOrigMenuRect.iTl.iY < main2PaneRect.iTl.iY )
       
   839         {
       
   840         iOrigMenuRect.Move( 0, main2PaneRect.iTl.iY - iOrigMenuRect.iTl.iY );
       
   841         }
       
   842     else if ( iOrigMenuRect.iBr.iY > main2PaneRect.iBr.iY )
       
   843         {
       
   844         iOrigMenuRect.Move( 0, main2PaneRect.iBr.iY - iOrigMenuRect.iBr.iY );
       
   845         }
       
   846 
       
   847     SetRect( iOrigMenuRect );
       
   848 
       
   849     if ( !aLayoutChange )
       
   850         {
       
   851         const TInt width( iOrigMenuRect.Width() );
       
   852         TPoint tl( iOrigMenuRect.iTl );
       
   853         tl.iX += AknLayoutUtils::LayoutMirrored() ? -width : width;
       
   854         SetPosition( tl );
       
   855         }
       
   856     }
       
   857 
       
   858 // ---------------------------------------------------------------------------
       
   859 // CFscContactActionMenuList::AdjustByContent
       
   860 // ---------------------------------------------------------------------------
       
   861 //   
       
   862 void CFscContactActionMenuList::AdjustByContent( TRect& aRect )
       
   863     {
       
   864     FUNC_LOG;
       
   865     // Menu list pane
       
   866     TAknLayoutRect menuListPane;
       
   867     menuListPane.LayoutRect( aRect, 
       
   868             AknLayoutScalable_Apps::sp_fs_action_menu_list_pane( 
       
   869                     Max( 0, iModel->ItemCount() - 1 ) ) );
       
   870     const TRect menuPaneListRect( menuListPane.Rect() );
       
   871 
       
   872     // Menu gene pane
       
   873     TAknLayoutRect menuGenePane;
       
   874     menuGenePane.LayoutRect( menuPaneListRect, 
       
   875             AknLayoutScalable_Apps::sp_fs_action_menu_list_gene_pane( 0 ) );
       
   876     const TRect menuGenePaneRect( menuGenePane.Rect() );
       
   877            
       
   878     // Menu gene pane g1
       
   879     TAknLayoutRect menuGenePaneG1;
       
   880     menuGenePaneG1.LayoutRect( menuGenePaneRect, 
       
   881             AknLayoutScalable_Apps::sp_fs_action_menu_list_gene_pane_g1( 0 ) );
       
   882     const TRect menuGenePaneG1Rect( menuGenePaneG1.Rect() );
       
   883     
       
   884     // Menu gene pane t1
       
   885     TAknLayoutText menuGenePaneT1;
       
   886     menuGenePaneT1.LayoutText( menuGenePaneRect, 
       
   887             AknLayoutScalable_Apps::sp_fs_action_menu_list_gene_pane_t1( 0 ) );
       
   888     const TRect menuGenePaneT1Rect( menuGenePaneT1.TextRect() );
       
   889     iFont = menuGenePaneT1.Font();
       
   890 
       
   891     const TInt textColumnWidth( menuGenePaneT1Rect.Width() );    
       
   892     const TInt maxTextWidth( MaxListTextWidth() + 
       
   893             RightMargin( menuGenePaneRect, menuGenePaneT1Rect ) );
       
   894 
       
   895     if ( maxTextWidth < textColumnWidth )
       
   896         {
       
   897         const TInt widthAdjustment( textColumnWidth - maxTextWidth );
       
   898         if ( !AknLayoutUtils::LayoutMirrored() )
       
   899             {
       
   900             aRect.Move( widthAdjustment, 0 );
       
   901             }
       
   902         aRect.Resize( -widthAdjustment, 0 );
       
   903         }
       
   904     }
       
   905 
       
   906 // ---------------------------------------------------------------------------
       
   907 // CFscContactActionMenuList::SizeChanged
       
   908 // ---------------------------------------------------------------------------
       
   909 //   
       
   910 void CFscContactActionMenuList::SizeChanged()
       
   911     {
       
   912     FUNC_LOG;
       
   913     LayoutList();
       
   914     }
       
   915 
       
   916 //</cmail>
       
   917