cmmanager/cmmgr/Framework/Src/cmdesticonmap.cpp
changeset 20 9c97ad6591ae
parent 18 fcbbe021d614
child 21 b8e8e15e80f2
child 23 7ec726f93df1
child 28 860702281757
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
     1 /*
       
     2 * Copyright (c) 2006 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 CCmDestinationIconMap
       
    15 *
       
    16 */
       
    17 
       
    18 #include <eikenv.h>
       
    19 #include <eiksbfrm.h>
       
    20 #include <eikscrlb.h>
       
    21 #include <bidivisual.h>
       
    22 #include <avkon.rsg>
       
    23 #include <AknPanic.h>
       
    24 #include <avkon.hrh>
       
    25 #include <AknUtils.h>
       
    26 #include <aknlayoutscalable_avkon.cdl.h>
       
    27 #include <layoutmetadata.cdl.h>
       
    28 #include <AknLayout.lag>
       
    29 #include <data_caging_path_literals.hrh>
       
    30 #include <aknappui.h>
       
    31 #include <aknconsts.h>
       
    32 #include <AknDef.h>
       
    33 #include <PUAcodes.hrh>
       
    34 #include <s32file.h>
       
    35 #include <eikscrlb.h>   // TEikScrollBarModelType
       
    36 #include <AknsDrawUtils.h>
       
    37 #include <featmgr.h>
       
    38 #include <AknsFrameBackgroundControlContext.h>
       
    39 #include <cmmanager.mbg>
       
    40 #include <cmcommonconstants.h>
       
    41 #include <touchfeedback.h>
       
    42 #include "cmdesticonmap.h"
       
    43 #include "cmmanagerimpl.h"
       
    44 
       
    45 // The offset because of CEikDialogPage
       
    46 const TInt KHorizontalDialogMargin = 0;
       
    47 const TInt KVerticalDialogMargin = 0;
       
    48 const TInt KAknSctCBaButtonDirections = 3; // bottom, right and left
       
    49 
       
    50 /**
       
    51  * Extension class to CCmDestinationIconMap
       
    52  *
       
    53  * @since S60 v3.2
       
    54  */
       
    55 NONSHARABLE_CLASS( CCmDestinationIconMapExtension ) : public CBase, 
       
    56                                                       public MObjectProvider
       
    57     {
       
    58     public:
       
    59     
       
    60         CCmDestinationIconMapExtension();
       
    61         ~CCmDestinationIconMapExtension();
       
    62     
       
    63     protected:
       
    64     
       
    65         TTypeUid::Ptr MopSupplyObject( TTypeUid aId );
       
    66         MObjectProvider* MopNext();
       
    67     
       
    68     public: // data
       
    69         
       
    70         MCoeControlObserver *iObserver;
       
    71         
       
    72         TUint iFlags;
       
    73         MObjectProvider* iIconMap;       
       
    74         TInt iMaxVisibleRows;
       
    75         CAknsFrameBackgroundControlContext* iBgContext;
       
    76     };
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CCmDestinationIconMapExtension::CCmDestinationIconMapExtension
       
    80 // C++ default constructor can NOT contain any code, that
       
    81 // might leave.
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CCmDestinationIconMapExtension::CCmDestinationIconMapExtension()
       
    85     : iMaxVisibleRows( 0 )
       
    86     {
       
    87     iObserver = NULL;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CCmDestinationIconMapExtension::MopSupplyObject()
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 TTypeUid::Ptr CCmDestinationIconMapExtension::MopSupplyObject( TTypeUid aId )
       
    95     {
       
    96     return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CCmDestinationIconMapExtension::MopNext()
       
   101 // -----------------------------------------------------------------------------
       
   102 //    
       
   103 MObjectProvider* CCmDestinationIconMapExtension::MopNext()
       
   104     {
       
   105     return iIconMap;
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CCmDestinationIconMapExtension::~CCmDestinationIconMapExtension()
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 CCmDestinationIconMapExtension::~CCmDestinationIconMapExtension()
       
   113     {
       
   114     delete iBgContext;
       
   115     iBgContext = NULL;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CCmDestinationIconMap::CCmDestinationIconMap
       
   120 // C++ default constructor can NOT contain any code, that
       
   121 // might leave.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CCmDestinationIconMap::CCmDestinationIconMap() 
       
   125     : iCursorPos( TPoint( 0,0 ) )
       
   126     , iOldCursorPos( TPoint( 0,0 ) )
       
   127     , iMaxColumns( -1 )
       
   128     , iDragAlreadyActive( EFalse )
       
   129     {
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CCmDestinationIconMap::NewL
       
   134 // Two-phased constructor.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 CCmDestinationIconMap* CCmDestinationIconMap::NewL()
       
   138     {
       
   139     CCmDestinationIconMap* self = new( ELeave ) CCmDestinationIconMap();
       
   140 
       
   141     CleanupStack::PushL( self );
       
   142     self->ConstructL();
       
   143     CleanupStack::Pop( self ); //self
       
   144     return self;    
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CCmDestinationIconMap::ConstructL
       
   149 // Symbian 2nd phase constructor can leave.
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CCmDestinationIconMap::ConstructL()
       
   153     {
       
   154     // Must be created here to get the member variables available
       
   155     iExtension = new ( ELeave ) CCmDestinationIconMapExtension;
       
   156     iExtension->iIconMap = this;
       
   157         
       
   158     iConsArray = new( ELeave ) CAknIconArray( KNumOfIcons );
       
   159     
       
   160     iExtension->iFlags = 0x00;
       
   161         
       
   162     DoLayout();
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CCmDestinationIconMap::~CCmDestinationIconMap()
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 CCmDestinationIconMap::~CCmDestinationIconMap()
       
   170     {
       
   171     delete iSBFrame; iSBFrame = NULL;
       
   172     
       
   173     delete iOffscreenBg;
       
   174     delete iBitmapDevice;
       
   175     delete iBitmapGc;
       
   176 
       
   177     delete iExtension; 
       
   178     iExtension = ( CCmDestinationIconMapExtension* )NULL;
       
   179     
       
   180     if ( iConsArray )
       
   181         {
       
   182         iConsArray->ResetAndDestroy();
       
   183         delete iConsArray;
       
   184         iConsArray = NULL;
       
   185         }
       
   186    }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CCmDestinationIconMap::DoLayout()
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CCmDestinationIconMap::DoLayout() 
       
   193     {
       
   194     TRAPD( err,LoadIconL() );
       
   195     if ( err )
       
   196         {
       
   197         return;
       
   198         }
       
   199     
       
   200     iIsMirrored = AknLayoutUtils::LayoutMirrored();
       
   201     iDrawnBefore = EFalse;
       
   202     CountMaxColumnsAndCellSizes();
       
   203     SizeChanged();
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CCmDestinationIconMap::ConstructFromResourceL()
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CCmDestinationIconMap::ConstructFromResourceL( 
       
   211                                                 TResourceReader& /*aReader*/ )
       
   212     {
       
   213     LoadIconL();
       
   214     CreateScrollBarAndIconRowL();
       
   215 
       
   216     iExtension->iBgContext = CAknsFrameBackgroundControlContext::NewL( 
       
   217                                                             KAknsIIDQsnFrPopup, 
       
   218                                                             TRect( 0, 0, 1, 1 ), 
       
   219                                                             TRect( 0, 0, 1, 1 ), 
       
   220                                                             EFalse );
       
   221 
       
   222     if ( DrawableWindow() && AknLayoutUtils::PenEnabled() )
       
   223         {
       
   224         EnableDragEvents();       
       
   225         SetGloballyCapturing( ETrue );
       
   226         SetPointerCapture( ETrue );
       
   227         }
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CCmDestinationIconMap::LoadIcons()
       
   232 // This actually load the all icons to be shown on dialog from icon file
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CCmDestinationIconMap::LoadIconL()
       
   236     { 
       
   237     iConsArray->ResetAndDestroy();
       
   238     // Draw all the Icons.
       
   239     TParse mbmFile;
       
   240     User::LeaveIfError( mbmFile.Set( KManagerIconFilename, 
       
   241                                      &KDC_APP_BITMAP_DIR, NULL ) );
       
   242         
       
   243     // Create icon bitmap and mask.
       
   244     for ( TInt i( 0 ); i < ( KNumOfIcons * 2 ); i++ )
       
   245         {
       
   246         CFbsBitmap* bitmap = NULL;
       
   247         CFbsBitmap* bitmapMask = NULL;
       
   248         AknIconUtils::CreateIconLC( 
       
   249                    bitmap, 
       
   250                    bitmapMask, mbmFile.FullName(),
       
   251                    EMbmCmmanagerQgn_prop_set_conn_dest_internet_small + i, 
       
   252                    EMbmCmmanagerQgn_prop_set_conn_dest_internet_small + i + 1 );
       
   253         i++;
       
   254         AknIconUtils::SetSize( bitmap, 
       
   255                                TSize( iGridItemWidth, iGridItemHeight ) );
       
   256         AknIconUtils::SetSize( bitmapMask, 
       
   257                                TSize( iGridItemWidth, iGridItemHeight ) );
       
   258         CGulIcon* icon = CGulIcon::NewL( bitmap, bitmapMask );
       
   259         CleanupStack::PushL( icon );
       
   260         iConsArray->AppendL( icon );       
       
   261         CleanupStack::Pop( 3, bitmap );
       
   262         }        
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CCmDestinationIconMap::HeightInRows()
       
   267 // This actually returns the no of rows to be shown on a page
       
   268 // Depends upon the Layout size
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 TInt CCmDestinationIconMap::HeightInRows()
       
   272     {
       
   273     return ( iRows );
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CCmDestinationIconMap::CreateScrollBarAndIconRowL()
       
   278 // This actually creates the scroll bar sets the number of 
       
   279 // pages and rows on a page to be shown
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CCmDestinationIconMap::CreateScrollBarAndIconRowL()
       
   283     {
       
   284     iRows = ( ( iConsArray->Count() - 1 ) / iMaxColumns ) + 1 ;
       
   285     iFirstVisibleRow = 0;
       
   286     iAnimated = EFalse;
       
   287     iCursorPos = TPoint( 0, 0 );
       
   288     iNumPages = ( iRows / iExtension->iMaxVisibleRows ) + 
       
   289                 ( iRows % iExtension->iMaxVisibleRows ? 1 : 0 );
       
   290     iCurrentPage = 1;
       
   291     
       
   292     // Create and set the scb visible even though there is nothing to scroll   
       
   293     delete iSBFrame; iSBFrame=NULL;
       
   294 
       
   295     if ( AknLayoutUtils::PenEnabled() )
       
   296         {
       
   297         iSBFrame=new( ELeave ) CEikScrollBarFrame( this, this, ETrue ); 
       
   298         }
       
   299     else
       
   300         {
       
   301         iSBFrame=new( ELeave ) CEikScrollBarFrame( this, NULL, ETrue );
       
   302         }
       
   303     // Decide which type of scrollbar is shown
       
   304     CAknAppUi* appUi = iAvkonAppUi;
       
   305     if ( AknLayoutUtils::DefaultScrollBarType( appUi ) == 
       
   306          CEikScrollBarFrame::EDoubleSpan )
       
   307         {
       
   308         // For EDoubleSpan type scrollbar
       
   309         if ( AknLayoutUtils::PenEnabled() )
       
   310             {
       
   311             // window owning scrollbar
       
   312             iSBFrame->CreateDoubleSpanScrollBarsL( ETrue, 
       
   313                                                    EFalse, 
       
   314                                                    ETrue, 
       
   315                                                    EFalse );
       
   316             }
       
   317         else
       
   318             {
       
   319             // non-window owning scrollbar
       
   320             iSBFrame->CreateDoubleSpanScrollBarsL( EFalse, 
       
   321                                                    EFalse, 
       
   322                                                    ETrue, 
       
   323                                                    EFalse ); 
       
   324             }
       
   325         iSBFrame->SetTypeOfVScrollBar( CEikScrollBarFrame::EDoubleSpan );
       
   326         }
       
   327     else
       
   328         {
       
   329         // For EArrowHead type scrollbar
       
   330         iSBFrame->SetTypeOfVScrollBar( CEikScrollBarFrame::EArrowHead );
       
   331         }
       
   332     
       
   333     iSBFrame->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
   334                                        CEikScrollBarFrame::EAuto );
       
   335     iSBFrame->VerticalScrollBar()->SetMopParent( iExtension );
       
   336     UpdateScrollIndicatorL();
       
   337     }
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 // CCmDestinationIconMap::SetIndex
       
   341 // set the reference of the selected icon index from the table
       
   342 // -----------------------------------------------------------------------------
       
   343 // 
       
   344 void CCmDestinationIconMap::SetIndex( TInt& aIconIndex )
       
   345     {
       
   346     iIconIndex = &aIconIndex;
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CCmDestinationIconMap::MinimumSize
       
   351 // 
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 TSize CCmDestinationIconMap::MinimumSize()
       
   355     {    
       
   356     iIsMirrored = AknLayoutUtils::LayoutMirrored();
       
   357     CountMaxColumnsAndCellSizes();
       
   358 
       
   359     TRect rect;
       
   360     // Used the set rect, but resolution changes cannot be handled when it is used
       
   361               
       
   362     TAknLayoutRect dialogLayRect;
       
   363         
       
   364     // Main pane without softkeys
       
   365     TRect mainPaneRect;
       
   366     if ( !AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect ) )
       
   367     {
       
   368     mainPaneRect = iAvkonAppUi->ClientRect();
       
   369     }
       
   370     
       
   371     // Dialog layout, check variety first
       
   372     TAknLayoutScalableParameterLimits iconMapDialogVariety = 
       
   373                AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits();
       
   374     
       
   375     // Calc the variety
       
   376     TInt maxVariety = iconMapDialogVariety.LastVariety();
       
   377     
       
   378     // Check the CBA, if the orientation is not landscape 
       
   379     // there is not so much varieties
       
   380     AknLayoutUtils::TAknCbaLocation location = AknLayoutUtils::CbaLocation();
       
   381     // the offset for the certain cba location variety
       
   382     TInt maxVarietyOffset = 0; 
       
   383     // the number of varieties
       
   384     TInt varietyOffset = maxVariety + 1;
       
   385     
       
   386     // landscape variety number must be calculated offset == number of varieties
       
   387     // same applies to the variety number for the biggest sized layout for the 
       
   388     // variety
       
   389     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   390        {
       
   391        // the offset for one variety
       
   392        varietyOffset = ( maxVariety + 1 ) / KAknSctCBaButtonDirections;
       
   393        }
       
   394     
       
   395     // for right and left cba buttons the max variety is not zero
       
   396     // the varities are ordered by the location of the cba and the descending order
       
   397     // e.g the biggest sized layout first, the smallest last
       
   398     if ( location == AknLayoutUtils::EAknCbaLocationRight )
       
   399        {
       
   400        maxVarietyOffset = varietyOffset;
       
   401        }
       
   402     else if ( location == AknLayoutUtils::EAknCbaLocationLeft )
       
   403        {
       
   404        maxVarietyOffset = varietyOffset + varietyOffset; // 2*
       
   405        }
       
   406     
       
   407     TInt varietyNumber = varietyOffset - iRows - 1; 
       
   408     
       
   409     // if more lines than possible to show, use the default 
       
   410     // ( the biggest grid ) variety
       
   411     if ( varietyNumber < 0 )
       
   412        varietyNumber = 0;
       
   413     // if zero rows, use the minimum
       
   414     else if ( iRows<=0 )
       
   415        varietyNumber -= 1;
       
   416     
       
   417     //add the varietyoffset
       
   418     varietyNumber += maxVarietyOffset;
       
   419 
       
   420     if ( Layout_Meta_Data::IsLandscapeOrientation() && 
       
   421         location == AknLayoutUtils::EAknCbaLocationRight )
       
   422        {
       
   423        varietyNumber = 10;
       
   424        }
       
   425     else
       
   426         {
       
   427         if( iRows == 0 )
       
   428             {
       
   429             varietyNumber = 5;
       
   430             }
       
   431         else
       
   432             {
       
   433             varietyNumber = 3;
       
   434             }
       
   435         }       
       
   436     // Layout the dialog size
       
   437     dialogLayRect.LayoutRect( mainPaneRect, 
       
   438        AknLayoutScalable_Avkon::popup_grid_graphic_window( varietyNumber ) );
       
   439        
       
   440     // Layout the grid
       
   441     TAknLayoutRect gridWithScrollLayRect;
       
   442     gridWithScrollLayRect.LayoutRect( dialogLayRect.Rect(), 
       
   443        AknLayoutScalable_Avkon::listscroll_popup_graphic_pane() );
       
   444     
       
   445     return TSize( dialogLayRect.Rect().Width(), 
       
   446         gridWithScrollLayRect.Rect().Height() );
       
   447     }
       
   448 
       
   449 // -----------------------------------------------------------------------------
       
   450 // CCmDestinationIconMap::ActivateL()
       
   451 // This method is needed to set correct initial value to scroll indicator.
       
   452 // -----------------------------------------------------------------------------
       
   453 //
       
   454  void CCmDestinationIconMap::ActivateL()
       
   455     {
       
   456     CCoeControl::ActivateL();
       
   457     if ( iRows > iExtension->iMaxVisibleRows )
       
   458         {
       
   459         UpdateScrollIndicatorL();
       
   460         }
       
   461     }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CCmDestinationIconMap::OfferKeyEventL
       
   465 // Handles all the Keypad events
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 TKeyResponse CCmDestinationIconMap::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   469                                                     TEventCode /*aModifiers*/ )
       
   470     {
       
   471     TUint code=aKeyEvent.iCode;
       
   472     
       
   473     switch ( code )
       
   474         {
       
   475         case EKeyLeftArrow:
       
   476         case '4':
       
   477             MoveCursorL( -1,0 );
       
   478             break;
       
   479         case EKeyRightArrow:
       
   480         case '6':
       
   481             MoveCursorL( 1,0 );
       
   482             break;
       
   483         case EKeyUpArrow:
       
   484         case '2':
       
   485             MoveCursorL( 0,-1 );
       
   486             break;
       
   487         case EKeyDownArrow:
       
   488         case '8':
       
   489             MoveCursorL( 0,1 );
       
   490             break;
       
   491         case EKeyOK:
       
   492         case '5':  
       
   493         case EKeySpace:
       
   494             {
       
   495             if ( iConsArray )
       
   496                 {
       
   497                 TInt ret = iMaxColumns * 
       
   498                            ( iFirstVisibleRow + iCursorPos.iY ) + 
       
   499                            iCursorPos.iX;
       
   500                 if ( ret <= iConsArray->Count() )
       
   501                     {
       
   502                     *iIconIndex = ret;    
       
   503                     }
       
   504                 else
       
   505                     {
       
   506                     *iIconIndex = -1;
       
   507                     }
       
   508                 }
       
   509                
       
   510             }
       
   511             break;
       
   512         default:
       
   513             return EKeyWasNotConsumed;
       
   514 
       
   515         }
       
   516     return EKeyWasConsumed;
       
   517     }
       
   518 
       
   519 #ifdef RD_SCALABLE_UI_V2 
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CCmDestinationIconMap::HandlePointerEventL
       
   523 // Handles all the Keypad events
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 void CCmDestinationIconMap::HandlePointerEventL(
       
   527                                 const TPointerEvent& aPointerEvent )
       
   528     {
       
   529     if ( AknLayoutUtils::PenEnabled() )
       
   530         {
       
   531         TInt newGridX; // For the whole
       
   532         TInt newGridY; // For the whole grid.
       
   533         TInt yInPixels = aPointerEvent.iPosition.iY - iGridTopLeft.iY;
       
   534         newGridY = yInPixels / iGridItemHeight;
       
   535         if ( ( aPointerEvent.iPosition.iX - iGridTopLeft.iX ) < 0 )
       
   536             {
       
   537             newGridX = -1;
       
   538             }
       
   539         else
       
   540             {
       
   541             newGridX = ( aPointerEvent.iPosition.iX - iGridTopLeft.iX )
       
   542                                                         / iGridItemWidth;
       
   543             }
       
   544 
       
   545         // The pointer has been set down or dragged into the area of the grid. 
       
   546         // (it might be in the "white space" at the end of the grid)
       
   547         if ( ( yInPixels >= 0 && yInPixels < iGridItemHeight 
       
   548                 * iExtension->iMaxVisibleRows) &&
       
   549             // When the pointer is in rows except the recent icon row
       
   550                 ( ( ( ( newGridY + iFirstVisibleRow ) != 0 ) && 
       
   551                 newGridX < iMaxColumns && newGridX >= 0 ) ||
       
   552             // When the pointer is in the recent icon row
       
   553                 ( ( newGridY + iFirstVisibleRow == 0 ) && 
       
   554                 ( newGridX < iMaxColumns ) ) ) )
       
   555             {
       
   556             TUint globalY = newGridY + iFirstVisibleRow;
       
   557             // For any action to be taken, the pointer event must either be a
       
   558             // Button1Down or a drag event which has originated from a
       
   559             // Button1Down in to the grid.
       
   560             if ( aPointerEvent.iType == TPointerEvent::EButton1Down ||
       
   561                  aPointerEvent.iType == TPointerEvent::EDrag )
       
   562                 {
       
   563                 if ( aPointerEvent.iType == TPointerEvent::EDrag ) 
       
   564                     {
       
   565                     iDragAlreadyActive = ETrue;
       
   566                     }
       
   567 
       
   568                 // The user tapps a cell which has no icon. it is ignored.
       
   569                 if ( iConsArray->Count() > globalY * iMaxColumns + newGridX )
       
   570                     {
       
   571               	    // If icon is already selected then on single tap it
       
   572               	    // should select the icon.
       
   573                     if( iCursorPos.iY == newGridY && 
       
   574                         iCursorPos.iX == newGridX &&
       
   575                         aPointerEvent.iType != TPointerEvent::EDrag )
       
   576                         {
       
   577                         if ( iExtension->iObserver )
       
   578                             {
       
   579                             iExtension->iObserver->HandleControlEventL( 
       
   580                                   this, 
       
   581                                   MCoeControlObserver::EEventStateChanged );
       
   582                             } 
       
   583                         }
       
   584                     else if ( iCursorPos.iX + ( iCursorPos.iY + 
       
   585                               iFirstVisibleRow ) * iMaxColumns  < 
       
   586                               iConsArray->Count() )
       
   587                         {
       
   588                         iOldCursorPos = iCursorPos;
       
   589                         iCursorPos.iY = newGridY;
       
   590                         iCursorPos.iX = newGridX;
       
   591                         DrawCursor();
       
   592                         }
       
   593                     else
       
   594                         {
       
   595                         iOldCursorPos.iX = 0;
       
   596                         iOldCursorPos.iY = 0;
       
   597                         }
       
   598 				    }
       
   599                 }
       
   600             else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   601                 {
       
   602                 // The pointer has been set and dragged into the area of 
       
   603                 // the grid.
       
   604                 if ( yInPixels >= 0 && yInPixels < iGridItemHeight * 
       
   605                      iExtension->iMaxVisibleRows && 
       
   606                      iDragAlreadyActive && 
       
   607                      iOldCursorPos == iCursorPos &&
       
   608                      (iConsArray->Count() > (globalY * iMaxColumns + newGridX)))
       
   609                     {
       
   610                     if ( iExtension->iObserver )
       
   611                         {
       
   612                         iExtension->iObserver->HandleControlEventL( 
       
   613                                 this, 
       
   614                                 MCoeControlObserver::EEventStateChanged );
       
   615                         }
       
   616                 	iDragAlreadyActive = EFalse;    
       
   617                     }
       
   618                 }
       
   619 
       
   620             MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   621         
       
   622             if ( feedback )
       
   623                 {
       
   624                 if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   625                     {
       
   626                     feedback->InstantFeedback( this, ETouchFeedbackBasic );
       
   627                     }
       
   628                 else if ( aPointerEvent.iType == TPointerEvent::EDrag && iCursorPos != iOldCursorPos )
       
   629                     {
       
   630                     feedback->InstantFeedback( this, ETouchFeedbackSensitive );	
       
   631                     }
       
   632                 }
       
   633             }
       
   634         else // For a non window owning scrollbar.
       
   635             {
       
   636             if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   637                 {
       
   638                 iDragAlreadyActive = EFalse;
       
   639                 }
       
   640             }
       
   641         
       
   642         CCoeControl::HandlePointerEventL( aPointerEvent );
       
   643         }
       
   644     }
       
   645     
       
   646 // -----------------------------------------------------------------------------
       
   647 // CCmDestinationIconMap::SetObserver
       
   648 // Sets the observer.
       
   649 // -----------------------------------------------------------------------------
       
   650 //
       
   651 void CCmDestinationIconMap::SetObserver( MCoeControlObserver* aObserver  )
       
   652     {
       
   653     if ( iExtension )
       
   654         {
       
   655         iExtension->iObserver = aObserver;
       
   656         }
       
   657     }
       
   658 
       
   659 #endif //RD_SCALABLE_UI_V2    
       
   660 
       
   661 // -----------------------------------------------------------------------------
       
   662 // CCmDestinationIconMap::InputCapabilities()
       
   663 //
       
   664 // -----------------------------------------------------------------------------
       
   665 //
       
   666 TCoeInputCapabilities CCmDestinationIconMap::InputCapabilities() const
       
   667     {
       
   668     return TCoeInputCapabilities( TCoeInputCapabilities::EAllText );
       
   669     }
       
   670 
       
   671 // -----------------------------------------------------------------------------
       
   672 // CCmDestinationIconMap::SizeChanged()
       
   673 // Control position of this control is registered for skin library when 
       
   674 // necessary in CEikDialogPage::SetDataPosition, so we do not do that in this 
       
   675 // method.
       
   676 // -----------------------------------------------------------------------------
       
   677 //
       
   678 void CCmDestinationIconMap::SizeChanged()
       
   679     {
       
   680     // Get the layout
       
   681     
       
   682     // Main pane without softkeys
       
   683     TRect mainPaneRect;
       
   684    
       
   685     if ( !AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
       
   686                                              mainPaneRect ) )
       
   687        {
       
   688        mainPaneRect = iAvkonAppUi->ClientRect();
       
   689        }
       
   690     
       
   691     // Dialog layout, check variety first
       
   692     TAknLayoutScalableParameterLimits iconMapDialogVariety = 
       
   693                AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits();
       
   694     
       
   695     TInt maxVariety = iconMapDialogVariety.LastVariety();
       
   696     
       
   697     // Check the CBA, if the orientation is not landscape 
       
   698     // there is not so much varieties
       
   699     AknLayoutUtils::TAknCbaLocation location = AknLayoutUtils::CbaLocation();
       
   700     // the offset for the certain cba location variety
       
   701     TInt maxVarietyOffset = 0;
       
   702     TInt varietyOffset = maxVariety + 1;
       
   703     
       
   704     // landscape variety number must be calculated offset == number of varieties
       
   705     // same applies to the variety number for the biggest sized layout for the 
       
   706     // variety
       
   707     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   708        {
       
   709        // the offset for one variety
       
   710        varietyOffset = ( maxVariety + 1 ) / KAknSctCBaButtonDirections;
       
   711        }
       
   712     
       
   713     // for right and left cba buttons the max variety is not zero
       
   714     // the varities are ordered by the location of the cba and the descending 
       
   715     // order e.g the biggest sized layout first, the smallest last
       
   716     if ( location == AknLayoutUtils::EAknCbaLocationRight )
       
   717        {
       
   718        maxVarietyOffset = varietyOffset;
       
   719        }
       
   720     else if ( location == AknLayoutUtils::EAknCbaLocationLeft )
       
   721        {
       
   722        maxVarietyOffset = varietyOffset + varietyOffset; // 2*
       
   723        }
       
   724     
       
   725     TInt varietyNumber = varietyOffset - iRows - 1; 
       
   726     
       
   727     // if more lines than possible to show, use the default 
       
   728     // ( the biggest grid ) variety
       
   729     if ( varietyNumber < 0 )
       
   730        varietyNumber = 0;
       
   731     // if zero rows, use the minimum
       
   732     else if ( iRows<=0 )
       
   733        varietyNumber -= 1;
       
   734     
       
   735     //add the varietyoffset
       
   736     varietyNumber += maxVarietyOffset;
       
   737     
       
   738     if ( Layout_Meta_Data::IsLandscapeOrientation() && 
       
   739          location == AknLayoutUtils::EAknCbaLocationRight )
       
   740        {
       
   741        varietyNumber = 10;
       
   742        }
       
   743     else
       
   744         {
       
   745         if ( iRows == 0 )
       
   746             {
       
   747             varietyNumber = 5;
       
   748             }
       
   749         else
       
   750             {
       
   751             varietyNumber = 3;
       
   752             }            
       
   753         
       
   754         }       
       
   755     
       
   756     TAknLayoutRect popupGridLayRect;
       
   757     popupGridLayRect.LayoutRect( mainPaneRect, 
       
   758           AknLayoutScalable_Avkon::popup_grid_graphic_window( varietyNumber ) );
       
   759     
       
   760     // Calculate the size relatively
       
   761     TRect relativeDialog( TPoint( 0,0 ),popupGridLayRect.Rect().Size() );
       
   762     
       
   763     // Get the layout of the actual icon grid with scrollbar
       
   764     TAknLayoutRect gridWithScrollLayRect;
       
   765     gridWithScrollLayRect.LayoutRect( relativeDialog, 
       
   766        AknLayoutScalable_Avkon::listscroll_popup_graphic_pane() );
       
   767             
       
   768     // Then the grid area without scrollbar
       
   769     // NOTE: The grid with scroll bar is used as reference
       
   770     TAknLayoutRect gridLayRect;
       
   771     gridLayRect.LayoutRect( gridWithScrollLayRect.Rect(), 
       
   772        AknLayoutScalable_Avkon::grid_graphic_popup_pane( 0 ) );
       
   773 
       
   774     // Different parent if SCT inside editing menu.
       
   775     TRect contentRect = gridLayRect.Rect();
       
   776 
       
   777     // The x coordinate is 3 pixels to right and y coordinate 3 pixels up 
       
   778     // so substract from x coordinate and add to y coordinate
       
   779     if ( iIsMirrored ) 
       
   780         {
       
   781         iOffset = TPoint( 
       
   782             contentRect.iBr.iX - KHorizontalDialogMargin - iGridItemWidth + 1,  
       
   783             contentRect.iTl.iY - KVerticalDialogMargin + 1 );
       
   784         
       
   785         iGridTopLeft.iX = contentRect.iBr.iX - 
       
   786                           KHorizontalDialogMargin - 
       
   787                           ( iMaxColumns * iGridItemWidth );
       
   788         iGridTopLeft.iY = contentRect.iTl.iY - KVerticalDialogMargin;
       
   789         }
       
   790     else  // not mirrored
       
   791         {
       
   792         iOffset = TPoint( contentRect.iTl.iX - KHorizontalDialogMargin + 1, 
       
   793                          contentRect.iTl.iY - KVerticalDialogMargin + 1 );
       
   794         iGridTopLeft.iX = contentRect.iTl.iX - KHorizontalDialogMargin;
       
   795         iGridTopLeft.iY = contentRect.iTl.iY - KVerticalDialogMargin;
       
   796         }
       
   797     
       
   798        
       
   799     // The last, update background context
       
   800     if ( iExtension->iBgContext )
       
   801        {            
       
   802         TInt bgVariety = 0;
       
   803         if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   804             {
       
   805             bgVariety = 1;
       
   806             }
       
   807             
       
   808         TAknLayoutRect innerRect;
       
   809         innerRect.LayoutRect( 
       
   810                 relativeDialog, 
       
   811                 AknLayoutScalable_Avkon::bg_popup_window_pane_g1( bgVariety ) );
       
   812 
       
   813        iExtension->iBgContext->SetFrameRects( relativeDialog, 
       
   814                                               innerRect.Rect() );
       
   815        }
       
   816     
       
   817     TRAPD( err,UpdateScrollIndicatorL() );
       
   818     if ( err )
       
   819         {
       
   820         return;
       
   821         }
       
   822     }
       
   823 
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CCmDestinationIconMap::HandleResourceChange()
       
   827 // -----------------------------------------------------------------------------
       
   828 //
       
   829 void CCmDestinationIconMap::HandleResourceChange( TInt aType )
       
   830     {
       
   831     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   832         {
       
   833         // save the old info for the magnitudes of the SCT grid
       
   834         TInt oldMaxColumns = iMaxColumns;
       
   835         //TInt oldMaxRows = 0;
       
   836         //oldMaxRows = iRows;
       
   837         // calculate the new magnitudes
       
   838         DoLayout();
       
   839         
       
   840         // then calculate the index position of the cursor in the icon table
       
   841         // and update the x and y positions for the new grid with it
       
   842         
       
   843         TInt oldCursorPosition = ( iFirstVisibleRow + iOldCursorPos.iY ) * 
       
   844                                  oldMaxColumns +
       
   845                                  iOldCursorPos.iX;
       
   846         
       
   847         TInt currentCursorPosition = ( iFirstVisibleRow + iCursorPos.iY ) * 
       
   848                                      oldMaxColumns +
       
   849                                      iCursorPos.iX;
       
   850         
       
   851         // the new first row is the top row on the page where the new focus is
       
   852         iFirstVisibleRow = iExtension->iMaxVisibleRows * 
       
   853                            ( currentCursorPosition / 
       
   854                            ( iMaxColumns * iExtension->iMaxVisibleRows ) );
       
   855         
       
   856         // the cursor positions are relative to current page
       
   857         iCursorPos.iY = ( currentCursorPosition - 
       
   858                         ( iMaxColumns * iFirstVisibleRow ) ) / 
       
   859                         iMaxColumns;
       
   860         iCursorPos.iX = currentCursorPosition - 
       
   861                         ( iMaxColumns * iFirstVisibleRow ) - 
       
   862                         ( iMaxColumns * iCursorPos.iY );
       
   863            
       
   864         iOldCursorPos.iY = ( oldCursorPosition - 
       
   865                            ( iMaxColumns * iFirstVisibleRow ) ) / 
       
   866                            iMaxColumns;
       
   867         iOldCursorPos.iX = oldCursorPosition - 
       
   868                            ( iMaxColumns * iFirstVisibleRow ) - 
       
   869                            ( iMaxColumns * iOldCursorPos.iY );
       
   870         }
       
   871 
       
   872     if ( aType == KAknsMessageSkinChange )
       
   873         {
       
   874         iOffscreenBgDrawn = EFalse;
       
   875         }
       
   876         
       
   877     CCoeControl::HandleResourceChange( aType );   
       
   878     }
       
   879 
       
   880 // -----------------------------------------------------------------------------
       
   881 // CCmDestinationIconMap::Draw()
       
   882 // -----------------------------------------------------------------------------
       
   883 //
       
   884 void CCmDestinationIconMap::Draw( const TRect& /*aRect*/ ) const
       
   885     {    
       
   886     TInt cursorPos = 0;
       
   887     CWindowGc& gc=SystemGc();
       
   888     
       
   889     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   890     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   891     
       
   892     TRect rect = Rect();
       
   893     
       
   894     // Main pane without softkeys
       
   895     TRect mainPaneRect;
       
   896     if ( !AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
       
   897                                              mainPaneRect ) )
       
   898        {
       
   899        mainPaneRect = iAvkonAppUi->ClientRect();
       
   900        }
       
   901     
       
   902     // Dialog layout, check variety first
       
   903     TAknLayoutScalableParameterLimits iconMapDialogVariety = 
       
   904        AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits();
       
   905        
       
   906     // The variety starts from 0 so add +1
       
   907     TInt maxVariety = iconMapDialogVariety.LastVariety();
       
   908     
       
   909     // Check the CBA, if the orientation is not landscape 
       
   910     // there is not so much varieties
       
   911     AknLayoutUtils::TAknCbaLocation location = AknLayoutUtils::CbaLocation();
       
   912     // the offset for the certain cba location variety
       
   913     TInt maxVarietyOffset = 0;
       
   914     TInt varietyOffset = maxVariety + 1;
       
   915     
       
   916     // landscape variety number must be calculated offset == number of varieties
       
   917     // same applies to the variety number for the biggest sized layout for the 
       
   918     // variety
       
   919     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   920        {
       
   921        // the offset for one variety
       
   922        varietyOffset = ( maxVariety + 1 )/KAknSctCBaButtonDirections;
       
   923        }
       
   924     
       
   925     // for right and left cba buttons the max variety is not zero
       
   926     // the varities are ordered by the location of the cba and the descending 
       
   927     // order e.g the biggest sized layout first, the smallest last
       
   928     if ( location == AknLayoutUtils::EAknCbaLocationRight )
       
   929        {
       
   930        maxVarietyOffset = varietyOffset;
       
   931        }
       
   932     else if ( location == AknLayoutUtils::EAknCbaLocationLeft )
       
   933        {
       
   934        maxVarietyOffset = varietyOffset + varietyOffset; // 2*
       
   935        }
       
   936     
       
   937     TInt varietyNumber = varietyOffset - iRows - 1; 
       
   938     
       
   939     // if more lines than possible to show, use the default 
       
   940     // ( the biggest grid ) variety
       
   941     if ( varietyNumber < 0 )
       
   942         {
       
   943         varietyNumber = 0;
       
   944         }
       
   945     // if zero rows, use the minimum
       
   946     else if ( iRows<=0 )
       
   947         {
       
   948         varietyNumber -= 1;
       
   949         }
       
   950     
       
   951     //add the varietyoffset
       
   952     varietyNumber += maxVarietyOffset;
       
   953 
       
   954     if ( Layout_Meta_Data::IsLandscapeOrientation() && 
       
   955          location == AknLayoutUtils::EAknCbaLocationRight )
       
   956         {
       
   957         varietyNumber = 10;
       
   958         }
       
   959     else
       
   960         {
       
   961         varietyNumber = 3;
       
   962         }    
       
   963     // Layout the dialog size
       
   964     TAknLayoutRect dialogLayRect;
       
   965     dialogLayRect.LayoutRect( 
       
   966            mainPaneRect, 
       
   967           AknLayoutScalable_Avkon::popup_grid_graphic_window( varietyNumber ) );
       
   968     
       
   969     // Get the missing height for the background
       
   970     TInt backgroundHeightOffset = dialogLayRect.Rect().Height() - rect.iBr.iY;
       
   971     
       
   972     rect.iBr.iY += backgroundHeightOffset;
       
   973 
       
   974     // Check if we got an offscreen bitmap allocated for skin background and
       
   975     // there is bitmap background in the current skin.
       
   976     if ( iOffscreenBg && iHasBitmapBackground )
       
   977         {
       
   978         DrawOffscreenBackgroundIfRequired();
       
   979         gc.BitBlt( rect.iTl, iOffscreenBg );
       
   980         }
       
   981     else
       
   982         {
       
   983         AknsDrawUtils::Background( skin, cc, this, gc, rect );
       
   984         }
       
   985 
       
   986     TInt numberOfIconsToBeDrawn = iConsArray->Count();
       
   987     numberOfIconsToBeDrawn -= ( iFirstVisibleRow * iMaxColumns );
       
   988     if ( numberOfIconsToBeDrawn > 0 )
       
   989         {
       
   990         if ( numberOfIconsToBeDrawn > 
       
   991             ( iExtension->iMaxVisibleRows * iMaxColumns ) )
       
   992             {
       
   993             numberOfIconsToBeDrawn = iExtension->iMaxVisibleRows * iMaxColumns;
       
   994             }
       
   995 
       
   996         gc.SetPenStyle( CGraphicsContext::ESolidPen );    
       
   997         gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   998         gc.SetPenSize( TSize( 1,1 ) );
       
   999 
       
  1000         // 2 ) Draw the grid
       
  1001         const TSize gridItemRectSize( iGridItemWidth + 1, iGridItemHeight + 1 );
       
  1002              
       
  1003         TInt numberOfGridCellsToBeDrawn = numberOfIconsToBeDrawn;
       
  1004 
       
  1005         TRgb colorLine = AKN_LAF_COLOR( 219 );
       
  1006         AknsUtils::GetCachedColor( skin, 
       
  1007                                    colorLine, 
       
  1008                                    KAknsIIDQsnLineColors, 
       
  1009                                    EAknsCIQsnLineColorsCG5 );
       
  1010         TRgb colorRecentLine = AKN_LAF_COLOR( 215 );
       
  1011         AknsUtils::GetCachedColor( skin, 
       
  1012                                    colorRecentLine, 
       
  1013                                    KAknsIIDQsnLineColors, 
       
  1014                                    EAknsCIQsnLineColorsCG7 );
       
  1015 
       
  1016         // default pen color
       
  1017         gc.SetPenColor( colorLine );
       
  1018         
       
  1019         TInt fullRows = numberOfGridCellsToBeDrawn / iMaxColumns;
       
  1020 
       
  1021         // how many left after the full rows
       
  1022         numberOfGridCellsToBeDrawn -= fullRows * iMaxColumns;
       
  1023 
       
  1024         TPoint pos = iGridTopLeft;
       
  1025 
       
  1026         TInt endX = pos.iX + iGridItemWidth * iMaxColumns + 1;
       
  1027         TInt endY = pos.iY + iGridItemHeight * fullRows;
       
  1028 
       
  1029         TInt ii = 0;
       
  1030 
       
  1031         if ( fullRows )
       
  1032             {
       
  1033             // Draw full vertical lines
       
  1034             for ( ii = 0 ; ii <= iMaxColumns ; ii++ )
       
  1035                 {
       
  1036                 gc.SetPenColor( colorLine );
       
  1037                 gc.SetPenSize( TSize( 1,1 ) );
       
  1038                 gc.DrawLine( pos, TPoint( pos.iX, endY ) );
       
  1039                 pos.iX += iGridItemWidth;
       
  1040                 }
       
  1041 
       
  1042                 pos = iGridTopLeft;
       
  1043 
       
  1044             // Draw full horizontal lines
       
  1045             for ( ii = 0 ; ii <= fullRows ; ii++ )
       
  1046                 {
       
  1047                 gc.SetPenSize( TSize( 1,1 ) );    
       
  1048                 gc.SetPenColor( colorLine );
       
  1049                 gc.DrawLine( pos, TPoint( endX, pos.iY ) );
       
  1050                 pos.iY += iGridItemHeight;
       
  1051                 }
       
  1052             gc.SetPenColor( colorLine );
       
  1053             gc.SetPenSize( TSize( 1,1 ) );    
       
  1054             }
       
  1055 
       
  1056         if ( numberOfGridCellsToBeDrawn )
       
  1057             {
       
  1058             // Remaining cells in the last, non-full row
       
  1059             pos = iOffset;
       
  1060             // iOffset is cell area topLeft, grid is not included in it
       
  1061             pos.iX--;
       
  1062             pos.iY--;
       
  1063 
       
  1064             pos.iY += iGridItemHeight * fullRows;
       
  1065 
       
  1066             for ( ii = 0 ; ii < numberOfGridCellsToBeDrawn ; ii++ )
       
  1067                 {
       
  1068                 gc.DrawRect( TRect( pos, gridItemRectSize ) );
       
  1069 
       
  1070                 if ( iIsMirrored ) 
       
  1071                     pos.iX -= iGridItemWidth;
       
  1072                 else // not mirrored
       
  1073                     pos.iX += iGridItemWidth; 
       
  1074                 }
       
  1075             }
       
  1076         
       
  1077         TInt iconIndex = ( iCurrentPage - 1 ) * 
       
  1078                          ( iMaxColumns * iExtension->iMaxVisibleRows );
       
  1079         TInt lCnt =  iConsArray->Count(); 
       
  1080         cursorPos = iCursorPos.iX + iCursorPos.iY * iMaxColumns;
       
  1081         if ( lCnt > 0 )
       
  1082             {
       
  1083             TRect cellRect( TPoint( 0,0 ), 
       
  1084                             TSize( iGridItemWidth - 1, iGridItemHeight - 1 ) );
       
  1085             for ( TInt j = iconIndex, i = 0; 
       
  1086                   j < lCnt && i < numberOfIconsToBeDrawn;
       
  1087                   j++, i++ )
       
  1088                 {
       
  1089                 DrawItem( gc, CursorRect( i ), j, cursorPos == i, EFalse );        
       
  1090                 }     
       
  1091             }
       
  1092             
       
  1093         }
       
  1094     iDrawnBefore = ETrue;
       
  1095     gc.DiscardFont();
       
  1096     }
       
  1097 
       
  1098 // -----------------------------------------------------------------------------
       
  1099 // CCmDestinationIconMap::DrawItem()
       
  1100 // -----------------------------------------------------------------------------
       
  1101 //
       
  1102 void CCmDestinationIconMap::DrawItem( 
       
  1103     CWindowGc& aGc,
       
  1104     const TRect& aSctPosition,
       
  1105     TInt aIconIndex,
       
  1106     TBool aHighlighted,
       
  1107     TBool aDrawBackground ) const
       
  1108     {
       
  1109     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  1110     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
  1111     
       
  1112     TBool skins = AknsDrawUtils::Background( skin,cc,aGc, aSctPosition );    
       
  1113     TRgb color;
       
  1114     if ( !skins )
       
  1115         aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
  1116     if ( aHighlighted )
       
  1117         {
       
  1118         TRgb colorHightLightRect = AKN_LAF_COLOR( 215 );
       
  1119         AknsUtils::GetCachedColor( skin, 
       
  1120                                    colorHightLightRect, 
       
  1121                                    KAknsIIDQsnLineColors, 
       
  1122                                    EAknsCIQsnLineColorsCG7 );
       
  1123         aGc.SetPenColor( colorHightLightRect );
       
  1124         aGc.DrawRect( aSctPosition );
       
  1125 
       
  1126         // Shrink by one pixel in all directions.
       
  1127         TRect innerRect = aSctPosition;
       
  1128         innerRect.Shrink( 1,1 );
       
  1129 
       
  1130         color = AKN_LAF_COLOR( 210 );
       
  1131         AknsUtils::GetCachedColor( skin, 
       
  1132                                    color, 
       
  1133                                    KAknsIIDQsnHighlightColors, 
       
  1134                                    EAknsCIQsnHighlightColorsCG1 ); 
       
  1135         aGc.SetBrushColor( color );       
       
  1136         aGc.Clear( innerRect );
       
  1137         }
       
  1138     else if ( aDrawBackground )
       
  1139         {
       
  1140         TRect innerRect = aSctPosition;
       
  1141         aGc.SetBrushColor( AKN_LAF_COLOR( 0 ) );
       
  1142         if ( !skins )
       
  1143             {
       
  1144             aGc.Clear( innerRect );
       
  1145             }
       
  1146         else 
       
  1147             {
       
  1148             AknsDrawUtils::Background( skin, cc, this, aGc, innerRect );
       
  1149             }
       
  1150         }
       
  1151     
       
  1152     if ( iConsArray )
       
  1153         {
       
  1154         TInt lCnt =  iConsArray->Count(); 
       
  1155         if ( lCnt > 0 && aIconIndex < lCnt && aIconIndex >= 0 )
       
  1156             {
       
  1157             TRect cellRect( TPoint( 0,0 ), 
       
  1158                             TSize( iGridItemWidth - 1, iGridItemHeight - 1 ) );
       
  1159 
       
  1160             CGulIcon* bitmap = NULL;
       
  1161             bitmap = iConsArray->At( aIconIndex );
       
  1162             TInt numIconsInaPage = iExtension->iMaxVisibleRows * iMaxColumns;
       
  1163             TInt cellIndex = aIconIndex;
       
  1164             if ( aIconIndex >= numIconsInaPage )
       
  1165                 {
       
  1166                 cellIndex = aIconIndex % numIconsInaPage;
       
  1167                 }
       
  1168             aGc.BitBltMasked( CursorPoint( cellIndex ),
       
  1169                             bitmap->Bitmap(),
       
  1170                             cellRect,
       
  1171                             bitmap->Mask(),
       
  1172                             EFalse );
       
  1173             }
       
  1174         }
       
  1175     }
       
  1176 
       
  1177 // -----------------------------------------------------------------------------
       
  1178 // CCmDestinationIconMap::DrawCursor()
       
  1179 // Optimizes drawing. Only cursor is drawn.
       
  1180 // -----------------------------------------------------------------------------
       
  1181 void CCmDestinationIconMap::DrawCursor() const
       
  1182     {
       
  1183     // Whole Icon Map has to be drawn at least once. 
       
  1184     // If the user presses arrow key before Icon Map has been drawn,
       
  1185     // only cursor position is drawn without this check.
       
  1186     if ( !iDrawnBefore )
       
  1187         {
       
  1188         DrawNow();
       
  1189         }
       
  1190     // Only redraw old and new cursor position cells
       
  1191     ActivateGc();
       
  1192     CWindowGc& gc = SystemGc();
       
  1193 
       
  1194     TInt cursorPos = iOldCursorPos.iX + iOldCursorPos.iY * iMaxColumns;   
       
  1195     DrawCell( cursorPos, EFalse );
       
  1196 
       
  1197     cursorPos = iCursorPos.iX + iCursorPos.iY * iMaxColumns;
       
  1198     DrawCell( cursorPos, ETrue );
       
  1199 
       
  1200     gc.DiscardFont();
       
  1201     DeactivateGc();
       
  1202     }
       
  1203 
       
  1204 // -----------------------------------------------------------------------------
       
  1205 // CCmDestinationIconMap::DrawCell
       
  1206 // -----------------------------------------------------------------------------
       
  1207 //
       
  1208 void CCmDestinationIconMap::DrawCell( 
       
  1209     TInt aCursorPos,
       
  1210     TBool aHighlighted ) const
       
  1211     {
       
  1212     // calculate icon index
       
  1213     TInt iconIndex = aCursorPos + iFirstVisibleRow * iMaxColumns;
       
  1214 
       
  1215     // If we are only redrawing for animations, no need to draw non-animated
       
  1216     // items.
       
  1217     TRect rect = CursorRect( aCursorPos );
       
  1218 
       
  1219     Window().Invalidate( rect );
       
  1220     Window().BeginRedraw( rect );
       
  1221     DrawItem( SystemGc(), rect, iconIndex, aHighlighted, ETrue );
       
  1222     Window().EndRedraw();
       
  1223     SystemGc().DiscardFont();
       
  1224     }
       
  1225 
       
  1226 // -----------------------------------------------------------------------------
       
  1227 // CCmDestinationIconMap::CursorRect
       
  1228 // -----------------------------------------------------------------------------
       
  1229 //
       
  1230 TRect CCmDestinationIconMap::CursorRect( TInt aCursorPos ) const
       
  1231     {
       
  1232     TPoint pos = iOffset;
       
  1233 
       
  1234     if ( iIsMirrored )
       
  1235         {
       
  1236         pos.iX -= ( aCursorPos % iMaxColumns ) * iGridItemWidth;
       
  1237         }
       
  1238     else // Not mirrored
       
  1239         {
       
  1240         pos.iX += ( aCursorPos % iMaxColumns ) * iGridItemWidth;
       
  1241         }
       
  1242 
       
  1243     pos.iY += ( aCursorPos / iMaxColumns ) * iGridItemHeight; 
       
  1244     return TRect( pos, TSize( iGridItemWidth - 1, iGridItemHeight - 1 ) );
       
  1245     }
       
  1246 
       
  1247 // -----------------------------------------------------------------------------
       
  1248 // CCmDestinationIconMap::CursorPoint
       
  1249 // -----------------------------------------------------------------------------
       
  1250 //
       
  1251 TPoint CCmDestinationIconMap::CursorPoint( TInt aCursorPos ) const
       
  1252     {
       
  1253     TPoint pos = iOffset;
       
  1254 
       
  1255     if ( iIsMirrored )
       
  1256         {
       
  1257         pos.iX -= ( aCursorPos % iMaxColumns ) * iGridItemWidth;
       
  1258         }
       
  1259     else // Not mirrored
       
  1260         {
       
  1261         pos.iX += ( aCursorPos % iMaxColumns ) * iGridItemWidth;
       
  1262         }
       
  1263 
       
  1264     pos.iY += ( aCursorPos / iMaxColumns ) * iGridItemHeight; 
       
  1265     return pos;
       
  1266     }
       
  1267 
       
  1268 // -----------------------------------------------------------------------------
       
  1269 // CCmDestinationIconMap::MoveCursorL
       
  1270 // -----------------------------------------------------------------------------
       
  1271 //
       
  1272 void CCmDestinationIconMap::MoveCursorL( TInt aDeltaX, TInt aDeltaY )
       
  1273     {           
       
  1274     if ( iIsMirrored )
       
  1275         aDeltaX = -aDeltaX;
       
  1276     
       
  1277     if ( ( iConsArray->Count() < 8 ) )
       
  1278        return;
       
  1279 
       
  1280     iOldCursorPos = iCursorPos;
       
  1281     TInt oldFirstVisibleRow = iFirstVisibleRow;
       
  1282 
       
  1283     TInt globalYPos = iCursorPos.iY + iFirstVisibleRow;
       
  1284     TInt lastColumnOnLastRow = ( ( iConsArray->Count() - 1 ) % iMaxColumns );
       
  1285 
       
  1286     TInt skipicon = aDeltaX != 0 ? 1: 0;
       
  1287 
       
  1288     if ( aDeltaX < 0 )
       
  1289         {
       
  1290         // Cursor was moved to left.
       
  1291         if ( iCursorPos.iX > skipicon - 1 )
       
  1292             {
       
  1293             iCursorPos.iX -= skipicon;
       
  1294             }
       
  1295         else
       
  1296             {
       
  1297             if ( skipicon > iMaxColumns )
       
  1298                 {
       
  1299                 globalYPos--;
       
  1300                 iCursorPos.iX = iMaxColumns;
       
  1301                 }
       
  1302             // Go to previous line
       
  1303             globalYPos--;
       
  1304             if ( globalYPos < 0 )
       
  1305                 {
       
  1306                 // Cursor was on the first line - go to last line.
       
  1307                 globalYPos = iRows - 1;
       
  1308                 // x - position to the last item on the last row.
       
  1309                 iCursorPos.iX = lastColumnOnLastRow;
       
  1310                 }
       
  1311             else
       
  1312                 {
       
  1313                 // x - position to last column.
       
  1314                 iCursorPos.iX = iMaxColumns - skipicon;
       
  1315                 }
       
  1316             }
       
  1317         }
       
  1318 
       
  1319     if ( aDeltaX > 0 )
       
  1320         {
       
  1321         // Cursor was moved to right.
       
  1322         if ( globalYPos < iRows - 1 )
       
  1323             {
       
  1324             // Not in the last row.
       
  1325             if ( iCursorPos.iX < iMaxColumns - skipicon )
       
  1326                 {
       
  1327                 // If not on the last columns, move cursor to next column.
       
  1328                 iCursorPos.iX += skipicon;
       
  1329                 }
       
  1330             else
       
  1331                 {
       
  1332                 // Cursor was on last column,
       
  1333                 // move to first column of the next line.
       
  1334                 iCursorPos.iX = 0;
       
  1335                 globalYPos++;
       
  1336                 }
       
  1337             }
       
  1338         else
       
  1339             {
       
  1340             // Currently on the last row.
       
  1341             if ( iCursorPos.iX < lastColumnOnLastRow )
       
  1342                 {
       
  1343                 // If there are more items on this row, move cursor to next item.
       
  1344                 iCursorPos.iX++;
       
  1345                 }
       
  1346             else
       
  1347                 {
       
  1348                 // No more item on the current row.
       
  1349                 // Move to first item on the first row.
       
  1350                 iCursorPos.iX = 0;
       
  1351                 globalYPos = 0;
       
  1352                 }
       
  1353             }
       
  1354         }
       
  1355 
       
  1356     if ( aDeltaY < 0 )
       
  1357         {
       
  1358         iCursorPos.iX -= skipicon;
       
  1359         if ( iCursorPos.iX < 0 )
       
  1360             {
       
  1361             iCursorPos.iX += ( iMaxColumns - 1 );
       
  1362             globalYPos--;
       
  1363             }
       
  1364         // Cursor was moved to up.
       
  1365         if ( globalYPos > 0 )
       
  1366             {
       
  1367             // Cursor was not on the first line - move it to previous row.
       
  1368             globalYPos--;
       
  1369             }
       
  1370         else
       
  1371             {
       
  1372             // Move cursot to last to row.
       
  1373             globalYPos = iRows - 1;
       
  1374             if ( iCursorPos.iX > lastColumnOnLastRow )
       
  1375                 {
       
  1376                 // No items in the current column on the last row - 
       
  1377                 // move cursor to last item on the row.
       
  1378                 iCursorPos.iX = lastColumnOnLastRow;
       
  1379                 }
       
  1380             }
       
  1381         }
       
  1382     
       
  1383     if ( aDeltaY > 0 )
       
  1384         {
       
  1385         iCursorPos.iX = ( iCursorPos.iX + skipicon ) % iMaxColumns;
       
  1386         globalYPos += ( iCursorPos.iX + skipicon ) / iMaxColumns;
       
  1387         // Cursor was moved to down.
       
  1388         if ( globalYPos < iRows - 1 )
       
  1389             {
       
  1390             // Cursor is not on the last row. Move cursor to next row.
       
  1391             globalYPos++;
       
  1392             if ( globalYPos == iRows - 1 && 
       
  1393                  iCursorPos.iX > lastColumnOnLastRow )
       
  1394                 {
       
  1395                 // No items in the current column on the last row - 
       
  1396                 // move cursor to last item on the row.
       
  1397                 iCursorPos.iX = lastColumnOnLastRow;
       
  1398                 }
       
  1399             }
       
  1400         else 
       
  1401             {
       
  1402             // Cursor was at the last row - move it to the first row.
       
  1403             globalYPos = 0;
       
  1404             }        
       
  1405         }
       
  1406     iCursorPos.iY = globalYPos - iFirstVisibleRow;
       
  1407 
       
  1408     if ( globalYPos < iFirstVisibleRow )
       
  1409         {
       
  1410         // Cursor was moved from the top row.
       
  1411         if ( globalYPos <= 0 )
       
  1412             {
       
  1413             iFirstVisibleRow = 0;
       
  1414             iCursorPos = TPoint( iCursorPos.iX, 0 );
       
  1415             }
       
  1416         else
       
  1417             {
       
  1418             // If cursor was moved up out of the visible area - show it again.
       
  1419             iFirstVisibleRow -= iExtension->iMaxVisibleRows;
       
  1420             iCursorPos = TPoint( iCursorPos.iX, 
       
  1421                                  iExtension->iMaxVisibleRows - 1 );
       
  1422             }
       
  1423         }
       
  1424     
       
  1425     if ( globalYPos > iFirstVisibleRow + iExtension->iMaxVisibleRows - 1 )
       
  1426         {
       
  1427         if ( globalYPos == iRows - 1 )
       
  1428             {
       
  1429             // When cursor has moved from the top line,
       
  1430             // it is adjusted to a page boundary.
       
  1431             iCursorPos = TPoint( 
       
  1432                 iCursorPos.iX,
       
  1433                 ( iRows - 1 ) % iExtension->iMaxVisibleRows
       
  1434                 );
       
  1435             iFirstVisibleRow = ( ( iRows - 1 ) / iExtension->iMaxVisibleRows ) * 
       
  1436                                iExtension->iMaxVisibleRows;
       
  1437             }
       
  1438         else
       
  1439             {
       
  1440             // If cursor was moved down out of the visible area - show it again.
       
  1441             iFirstVisibleRow += iExtension->iMaxVisibleRows;
       
  1442             iCursorPos = TPoint( iCursorPos.iX, 0 );
       
  1443             }
       
  1444         }
       
  1445        
       
  1446     //TInt increment( 1 );
       
  1447     //if ( aDeltaY < 0 || aDeltaX < 0 )
       
  1448     //    {
       
  1449     ////    increment = -1;
       
  1450     //    }
       
  1451     if ( iRows > iExtension->iMaxVisibleRows && 
       
  1452         ( iOldCursorPos.iY + oldFirstVisibleRow != 
       
  1453           iCursorPos.iY + iFirstVisibleRow ) )
       
  1454         {
       
  1455         UpdateScrollIndicatorL();
       
  1456         }
       
  1457 
       
  1458     if ( oldFirstVisibleRow == iFirstVisibleRow )
       
  1459         {
       
  1460         // Draw only cursor if the view to the content was not scrolled.
       
  1461         DrawCursor();
       
  1462         }
       
  1463     else
       
  1464         {
       
  1465         DrawNow();
       
  1466         }
       
  1467 
       
  1468     }
       
  1469 
       
  1470 // -----------------------------------------------------------------------------
       
  1471 // CCmDestinationIconMap::UpdateScrollIndicatorL()
       
  1472 // -----------------------------------------------------------------------------
       
  1473 //
       
  1474 void CCmDestinationIconMap::UpdateScrollIndicatorL()
       
  1475     {    
       
  1476     if ( !iSBFrame )
       
  1477         {
       
  1478         return;
       
  1479         }
       
  1480     TEikScrollBarModel hSbarModel;
       
  1481     TEikScrollBarModel vSbarModel;
       
  1482     
       
  1483     TEikScrollBarFrameLayout layout;
       
  1484     
       
  1485     // Main pane without softkeys
       
  1486     TRect mainPaneRect;
       
  1487     if ( !AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
       
  1488                                              mainPaneRect ) )
       
  1489        {
       
  1490        mainPaneRect = iAvkonAppUi->ClientRect();
       
  1491        }
       
  1492         
       
  1493     // Dialog layout, check variety first
       
  1494     TAknLayoutScalableParameterLimits iconMapDialogVariety = 
       
  1495        AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits();
       
  1496     
       
  1497     TInt maxVariety = iconMapDialogVariety.LastVariety();
       
  1498     
       
  1499     // Check the CBA, if the orientation is not landscape 
       
  1500     // there is not so much varieties
       
  1501     AknLayoutUtils::TAknCbaLocation location = AknLayoutUtils::CbaLocation();
       
  1502     // the offset for the certain cba location variety
       
  1503     TInt maxVarietyOffset = 0;
       
  1504     TInt varietyOffset = maxVariety + 1;
       
  1505     
       
  1506     // landscape variety number must be calculated offset == number of varieties
       
  1507     // same applies to the variety number for the biggest sized layout for the 
       
  1508     // variety
       
  1509     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  1510        {
       
  1511        // the offset for one variety
       
  1512        varietyOffset = ( maxVariety + 1 )/KAknSctCBaButtonDirections;
       
  1513        }
       
  1514     
       
  1515     // for right and left cba buttons the max variety is not zero
       
  1516     // the varities are ordered by the location of the cba and the descending 
       
  1517     // order e.g the biggest sized layout first, the smallest last
       
  1518     if ( location == AknLayoutUtils::EAknCbaLocationRight )
       
  1519        {
       
  1520        maxVarietyOffset = varietyOffset;
       
  1521        }
       
  1522     else if ( location == AknLayoutUtils::EAknCbaLocationLeft )
       
  1523        {
       
  1524        maxVarietyOffset = varietyOffset + varietyOffset; // 2*
       
  1525        }
       
  1526     
       
  1527     TInt varietyNumber = varietyOffset - iRows - 1; 
       
  1528     
       
  1529     // if more lines than possible to show, use the default 
       
  1530     // ( the biggest grid ) variety
       
  1531     if ( varietyNumber < 0 )
       
  1532         {
       
  1533         varietyNumber = 0;
       
  1534         }
       
  1535     // if zero rows, use the minimum
       
  1536     else if ( iRows <= 0 )
       
  1537         {
       
  1538         varietyNumber -= 1;
       
  1539         }
       
  1540     
       
  1541     //add the varietyoffset
       
  1542     varietyNumber += maxVarietyOffset;
       
  1543 
       
  1544     if ( Layout_Meta_Data::IsLandscapeOrientation() && 
       
  1545          location == AknLayoutUtils::EAknCbaLocationRight )
       
  1546        {
       
  1547        varietyNumber = 10;
       
  1548        }
       
  1549     else
       
  1550         {
       
  1551         varietyNumber = 3;
       
  1552         }     
       
  1553     // Layout the dialog size
       
  1554     TAknLayoutRect dialogLayRect;
       
  1555     dialogLayRect.LayoutRect( mainPaneRect, 
       
  1556        AknLayoutScalable_Avkon::popup_grid_graphic_window( varietyNumber ) );
       
  1557     
       
  1558     TRect dialogRect = dialogLayRect.Rect();
       
  1559     
       
  1560     // Get the layout of the actual icon grid with scrollbar
       
  1561     TAknLayoutRect gridWithScrollLayRect;
       
  1562        
       
  1563     gridWithScrollLayRect.LayoutRect( 
       
  1564                     TRect( TPoint( 0,0 ),
       
  1565                     TSize( dialogRect.Size() ) ), 
       
  1566                     AknLayoutScalable_Avkon::listscroll_popup_graphic_pane() );
       
  1567 
       
  1568     // Calculate the relative rect for the grid
       
  1569     TRect parent = gridWithScrollLayRect.Rect();
       
  1570     
       
  1571     TAknWindowComponentLayout scrollbarLayout = 
       
  1572                                     AknLayoutScalable_Avkon::scroll_pane_cp5();
       
  1573     
       
  1574     iCurrentPage = ( iFirstVisibleRow / iExtension->iMaxVisibleRows ) + 1;
       
  1575 
       
  1576     vSbarModel.iScrollSpan = iNumPages * iExtension->iMaxVisibleRows;
       
  1577     vSbarModel.iThumbSpan = iExtension->iMaxVisibleRows;
       
  1578     
       
  1579     if ( iSBFrame && iSBFrame->TypeOfVScrollBar() == 
       
  1580          CEikScrollBarFrame::EDoubleSpan )
       
  1581         {    
       
  1582         // For EDoubleSpan type scrollbar
       
  1583         vSbarModel.iThumbPosition = ( iCurrentPage - 1 ) * 
       
  1584                                     iExtension->iMaxVisibleRows;
       
  1585         TAknDoubleSpanScrollBarModel hDsSbarModel( hSbarModel );
       
  1586         TAknDoubleSpanScrollBarModel vDsSbarModel( vSbarModel );
       
  1587         
       
  1588         // The y coordinate must be sifted 3 pixels up and x 3 to left
       
  1589         parent.iTl.iY -= KVerticalDialogMargin;
       
  1590         parent.iBr.iY -= KVerticalDialogMargin;        
       
  1591         parent.iTl.iX -= KHorizontalDialogMargin;
       
  1592         parent.iBr.iX -= KHorizontalDialogMargin;
       
  1593         
       
  1594         layout.iTilingMode = TEikScrollBarFrameLayout::EInclusiveRectConstant;
       
  1595         iSBFrame->Tile( &vDsSbarModel ); 
       
  1596         AknLayoutUtils::LayoutVerticalScrollBar( iSBFrame, 
       
  1597                                                  parent, 
       
  1598                                                  scrollbarLayout );       
       
  1599         iSBFrame->SetVFocusPosToThumbPos( vDsSbarModel.FocusPosition() );
       
  1600         }
       
  1601     else
       
  1602         {
       
  1603         // For EArrowHead type scrollbar
       
  1604         vSbarModel.iThumbPosition = iCursorPos.iY + iFirstVisibleRow;
       
  1605         iSBFrame->TileL( &hSbarModel,&vSbarModel,parent,parent,layout );        
       
  1606         iSBFrame->SetVFocusPosToThumbPos( vSbarModel.iThumbPosition );
       
  1607         }
       
  1608     }
       
  1609 
       
  1610 
       
  1611 // -----------------------------------------------------------------------------
       
  1612 // CCmDestinationIconMap::Reserved_1()
       
  1613 // -----------------------------------------------------------------------------
       
  1614 //
       
  1615 void CCmDestinationIconMap::Reserved_1()
       
  1616     {
       
  1617     }
       
  1618 
       
  1619 // -----------------------------------------------------------------------------
       
  1620 // CCmDestinationIconMap::Reserved_2()
       
  1621 // -----------------------------------------------------------------------------
       
  1622 //
       
  1623 void CCmDestinationIconMap::Reserved_2()
       
  1624     {
       
  1625     }
       
  1626 
       
  1627 // -----------------------------------------------------------------------------
       
  1628 // CCmDestinationIconMap::DrawOffscreenBackgroundIfRequired
       
  1629 // 
       
  1630 // -----------------------------------------------------------------------------
       
  1631 //
       
  1632 void CCmDestinationIconMap::DrawOffscreenBackgroundIfRequired() const
       
  1633     {
       
  1634     if ( iOffscreenBg && iHasBitmapBackground )
       
  1635         {
       
  1636         if ( !iOffscreenBgDrawn )
       
  1637             {
       
  1638             TRect mainPaneRect;
       
  1639             if ( !AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
       
  1640                                                      mainPaneRect ) )
       
  1641                {
       
  1642                mainPaneRect = iAvkonAppUi->ClientRect();
       
  1643                }
       
  1644             
       
  1645             // Dialog layout, check variety first
       
  1646             TAknLayoutScalableParameterLimits iconMapDialogVariety = 
       
  1647                AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits();
       
  1648             
       
  1649             TInt maxVariety = iconMapDialogVariety.LastVariety();
       
  1650             
       
  1651             // Check the CBA, if the orientation is not landscape 
       
  1652             // there is not so much varieties
       
  1653             AknLayoutUtils::TAknCbaLocation location = 
       
  1654                                                   AknLayoutUtils::CbaLocation();
       
  1655             // the offset for the certain cba location variety
       
  1656             TInt maxVarietyOffset = 0;
       
  1657             TInt varietyOffset = maxVariety + 1;
       
  1658             
       
  1659             // landscape variety number must be calculated offset == number of 
       
  1660             // varieties same applies to the variety number for the biggest 
       
  1661             // sized layout for the variety
       
  1662             if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  1663                {
       
  1664                // the offset for one variety
       
  1665                varietyOffset = ( maxVariety + 1 )/KAknSctCBaButtonDirections;
       
  1666                }
       
  1667             
       
  1668             // for right and left cba buttons the max variety is not zero
       
  1669             // the varities are ordered by the location of the cba and the 
       
  1670             // descending order e.g the biggest sized layout first, the smallest last
       
  1671             if ( location == AknLayoutUtils::EAknCbaLocationRight )
       
  1672                {
       
  1673                maxVarietyOffset = varietyOffset;
       
  1674                }
       
  1675             else if ( location == AknLayoutUtils::EAknCbaLocationLeft )
       
  1676                {
       
  1677                maxVarietyOffset = varietyOffset + varietyOffset; // 2*
       
  1678                }   
       
  1679             TInt varietyNumber = varietyOffset - iRows - 1; 
       
  1680             
       
  1681             // if more lines than possible to show, use the default 
       
  1682             // ( the biggest grid ) variety
       
  1683             if ( varietyNumber < 0 )
       
  1684                 {
       
  1685                 varietyNumber = 0;
       
  1686                 }
       
  1687             // if zero rows, use the minimum
       
  1688             else if ( iRows<=0 )
       
  1689                 {
       
  1690                 varietyNumber -= 1;
       
  1691                 }
       
  1692             
       
  1693             //add the varietyoffset
       
  1694             varietyNumber += maxVarietyOffset;
       
  1695                    
       
  1696             TAknLayoutRect popupGridLayRect;
       
  1697             popupGridLayRect.LayoutRect( mainPaneRect, 
       
  1698                AknLayoutScalable_Avkon::popup_grid_graphic_window( 5 ) );
       
  1699             
       
  1700             TRect popupGridRect = popupGridLayRect.Rect();
       
  1701             
       
  1702             // set the top left height as the control starting point
       
  1703             popupGridRect.iTl.iY = Rect().iTl.iY;
       
  1704             
       
  1705             //if ( popupGridRect.iBr.iY < mainPaneRect.iBr.iY )
       
  1706             //    popupGridRect.iBr.iY = mainPaneRect.iBr.iY
       
  1707             MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  1708             MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
  1709             
       
  1710             // draw to upper left corner, and normalize the retangle to 
       
  1711             // fact that the dialog starts from coordinates ( 0,0 ), 
       
  1712             // so the y-coordinate is correct ( heading pane ) 
       
  1713             // but x must be set to zero
       
  1714             TPoint point = TPoint( 0, 0 );
       
  1715             popupGridRect.Move( -popupGridRect.iTl.iX,0 );
       
  1716             
       
  1717             AknsDrawUtils::DrawBackground( skin,
       
  1718                                            cc,
       
  1719                                            this,
       
  1720                                            *iBitmapGc,
       
  1721                                            point,
       
  1722                                            popupGridRect,
       
  1723                                            KAknsDrawParamDefault );
       
  1724 
       
  1725             iOffscreenBgDrawn = ETrue;
       
  1726             }
       
  1727         }
       
  1728     }
       
  1729 
       
  1730 // -----------------------------------------------------------------------------
       
  1731 // CCmDestinationIconMap::ComponentControl( TInt aIndex ) const
       
  1732 // Return the controll pointer
       
  1733 // -----------------------------------------------------------------------------
       
  1734 //
       
  1735 CCoeControl* CCmDestinationIconMap::ComponentControl( TInt aIndex ) const
       
  1736     {
       
  1737     if ( aIndex == 0 && 
       
  1738          iSBFrame && 
       
  1739          iSBFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan )
       
  1740         {    
       
  1741         return iSBFrame->VerticalScrollBar();
       
  1742         }
       
  1743     else
       
  1744         {
       
  1745         return NULL;
       
  1746         }
       
  1747     }
       
  1748 
       
  1749 // -----------------------------------------------------------------------------
       
  1750 // CCmDestinationIconMap::CountComponentControls()
       
  1751 // Return no of controll to be placed on the container control
       
  1752 // -----------------------------------------------------------------------------
       
  1753 // 
       
  1754 TInt CCmDestinationIconMap::CountComponentControls() const
       
  1755     {
       
  1756     if ( iSBFrame && 
       
  1757          iSBFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan )
       
  1758         {    
       
  1759         return 1;
       
  1760         }
       
  1761     else
       
  1762         {
       
  1763         return 0;
       
  1764         }
       
  1765     }
       
  1766 
       
  1767 // -----------------------------------------------------------------------------
       
  1768 // CCmDestinationIconMap::CountMaxColumnsAndCellSizes
       
  1769 // Counts no of columns and the cell size will be displayed in the icon table
       
  1770 // -----------------------------------------------------------------------------
       
  1771 //
       
  1772 void CCmDestinationIconMap::CountMaxColumnsAndCellSizes()
       
  1773     {    
       
  1774     TRect cellRect; // retangle of one item in grid
       
  1775     TRect gridRect; // retangle of the grid contaning the items
       
  1776     
       
  1777     // 1. Get the layout 
       
  1778     
       
  1779     // Get the parent rect
       
  1780     TRect mainPaneRect;
       
  1781     if ( !AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
       
  1782                                              mainPaneRect ) )
       
  1783        {
       
  1784        mainPaneRect = iAvkonAppUi->ClientRect();
       
  1785        }
       
  1786     
       
  1787     // Calculate the layout of the whole popup with the biggest possible -> 0
       
  1788     // Dialog layout, check variety first
       
  1789     
       
  1790     // Get the layout rect of the dialog
       
  1791     
       
  1792     // Check variety first
       
  1793     TAknLayoutScalableParameterLimits iconMapDialogVariety = 
       
  1794         AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits();
       
  1795     
       
  1796     TInt maxVariety = iconMapDialogVariety.LastVariety();
       
  1797     
       
  1798     // Check the CBA, if the orientation is not landscape 
       
  1799     // there is not so much varieties
       
  1800     AknLayoutUtils::TAknCbaLocation location = AknLayoutUtils::CbaLocation();
       
  1801     // the offset for the certain cba location variety
       
  1802     TInt maxVarietyOffset = 0;
       
  1803     TInt varietyOffset = maxVariety + 1; // the number of varieties
       
  1804         
       
  1805     // landscape variety number must be calculated offset == number of varieties
       
  1806     // same applies to the variety number for the biggest sized layout for the 
       
  1807     // variety
       
  1808     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  1809        {
       
  1810        // the offset for one variety
       
  1811        varietyOffset = ( maxVariety + 1 ) / KAknSctCBaButtonDirections;
       
  1812        }
       
  1813        
       
  1814     if ( location == AknLayoutUtils::EAknCbaLocationRight )
       
  1815        {
       
  1816        maxVarietyOffset = varietyOffset;
       
  1817        }
       
  1818     else if ( location == AknLayoutUtils::EAknCbaLocationLeft )
       
  1819        {
       
  1820        maxVarietyOffset = varietyOffset + varietyOffset; // 2*
       
  1821        }
       
  1822     
       
  1823     TAknLayoutRect popupGridLayRect;
       
  1824     popupGridLayRect.LayoutRect( mainPaneRect,
       
  1825        AknLayoutScalable_Avkon::popup_grid_graphic_window( maxVarietyOffset ) );
       
  1826     
       
  1827     // Get the layout of the actual icon grid with scrollbar
       
  1828     TAknLayoutRect gridWithScrollLayRect;
       
  1829     gridWithScrollLayRect.LayoutRect( popupGridLayRect.Rect(), 
       
  1830        AknLayoutScalable_Avkon::listscroll_popup_graphic_pane() );
       
  1831     
       
  1832     // Then the grid area without scrollbar
       
  1833     // NOTE: The grid with scroll bar is used as reference
       
  1834     TAknLayoutRect gridLayRect;
       
  1835     gridLayRect.LayoutRect( gridWithScrollLayRect.Rect(), 
       
  1836        AknLayoutScalable_Avkon::grid_graphic_popup_pane( 0 ) );
       
  1837 
       
  1838     // Different parent if SCT inside editing menu.
       
  1839     TRect rect = Rect();
       
  1840     gridRect = gridLayRect.Rect();
       
  1841     // cell size, AGAIN 7 item
       
  1842     TAknLayoutRect cellLayRect;
       
  1843     cellLayRect.LayoutRect( 
       
  1844                     gridRect, 
       
  1845                     AknLayoutScalable_Avkon::cell_graphic_popup_pane( 0,0,0 ) );
       
  1846 
       
  1847     cellRect = cellLayRect.Rect();
       
  1848         
       
  1849     // 2. Calculate width related
       
  1850     // - item width
       
  1851     // - max number of columns
       
  1852     
       
  1853     // Width of the items area
       
  1854     TInt gridWidth = gridRect.Width();
       
  1855     
       
  1856     // Width of one item
       
  1857     TInt cellWidth = cellRect.Width();
       
  1858   
       
  1859      // ensure the item width and store it
       
  1860     TAknLayoutRect secondCellLayRect;
       
  1861     secondCellLayRect.LayoutRect( gridRect, 
       
  1862                     AknLayoutScalable_Avkon::cell_graphic_popup_pane( 0,1,0 ) );
       
  1863        
       
  1864     iGridItemWidth = secondCellLayRect.Rect().iTl.iX - 
       
  1865                      cellLayRect.Rect().iTl.iX;
       
  1866     
       
  1867     if ( iGridItemWidth < 0 )
       
  1868         {
       
  1869         // The result is negative with lay file data if the layout is mirrored.
       
  1870         iGridItemWidth = -iGridItemWidth;
       
  1871         }
       
  1872     
       
  1873     // Calculate the amount of columns
       
  1874     iMaxColumns = gridWidth / cellWidth;
       
  1875     
       
  1876     
       
  1877     // 2. Calculate height related
       
  1878     // - item height
       
  1879     // - max number of rows
       
  1880         
       
  1881     // Get the grid height
       
  1882     // NOTE: in landscape the LAF is wrong so use the main panes height
       
  1883     TInt gridHeight = gridRect.Height();
       
  1884     
       
  1885     // get the item height
       
  1886     TInt cellHeight = cellRect.Height();
       
  1887     
       
  1888     // calculate the number of items fitting to grid
       
  1889     iExtension->iMaxVisibleRows = 3;//gridHeight / cellHeight;
       
  1890     
       
  1891     // Store the item height
       
  1892     TAknLayoutRect secondRowLayRect;
       
  1893     secondRowLayRect.LayoutRect( gridLayRect.Rect(), 
       
  1894        AknLayoutScalable_Avkon::cell_graphic_popup_pane( 0,0,1 ) );
       
  1895 
       
  1896     iGridItemHeight = secondRowLayRect.Rect().iTl.iY - 
       
  1897                       cellLayRect.Rect().iTl.iY;
       
  1898     }
       
  1899 
       
  1900 // -----------------------------------------------------------------------------
       
  1901 // CCmDestinationIconMap::HandleScrollEventL
       
  1902 // Handles the different scroll events so that the map reacts accordingly.
       
  1903 // -----------------------------------------------------------------------------
       
  1904 // 
       
  1905 void CCmDestinationIconMap::HandleScrollEventL( CEikScrollBar* aScrollBar, 
       
  1906                                                 TEikScrollEvent aEventType )
       
  1907     {
       
  1908     TBool update = EFalse;
       
  1909     
       
  1910     switch ( aEventType )
       
  1911         {       
       
  1912         case EEikScrollUp:
       
  1913         case EEikScrollPageUp:
       
  1914             {           
       
  1915             // nothing done if we are already on the first page.
       
  1916             if ( iFirstVisibleRow != 0 )
       
  1917                 {               
       
  1918                 iFirstVisibleRow -= iExtension->iMaxVisibleRows;             
       
  1919                 update = ETrue;
       
  1920                 }
       
  1921             UpdateScrollIndicatorL();
       
  1922             }
       
  1923             break;
       
  1924         
       
  1925         case EEikScrollDown:
       
  1926         case EEikScrollPageDown:
       
  1927             {           
       
  1928             // nothing done if we are already on the last page.
       
  1929             if ( iFirstVisibleRow != iRows/iExtension->iMaxVisibleRows * 
       
  1930                                      iExtension->iMaxVisibleRows )
       
  1931                 {
       
  1932                 iFirstVisibleRow += iExtension->iMaxVisibleRows;
       
  1933                 update = ETrue;
       
  1934                 }
       
  1935             UpdateScrollIndicatorL();
       
  1936             }
       
  1937             break;   
       
  1938                
       
  1939         case EEikScrollThumbDragVert:
       
  1940             {           
       
  1941             TInt thumbPosition;         
       
  1942             TInt halfPage = iExtension->iMaxVisibleRows/2;
       
  1943             // Ask which type of scrollbar is shown
       
  1944             //CAknAppUi* appUi = iAvkonAppUi;            
       
  1945             TBool isDoubleSpan = 
       
  1946                 CEikScrollBarFrame::EDoubleSpan == iSBFrame->TypeOfVScrollBar();
       
  1947             if ( isDoubleSpan )
       
  1948                 {
       
  1949                 thumbPosition = static_cast <const TAknDoubleSpanScrollBarModel*>( 
       
  1950                                             aScrollBar->Model() )->FocusPosition();
       
  1951                 }
       
  1952             else
       
  1953                 {
       
  1954                 thumbPosition = aScrollBar->Model()->iThumbPosition;
       
  1955                 }
       
  1956 
       
  1957             // If the slider is in the range of less then a half page from a 
       
  1958             // possible correct thumb position. thus 0 <= iFirstVisibleRow - 
       
  1959             // thumbPosition < halfPage. Or in the other direction:
       
  1960             // 0 <= thumbPosition - iFirstVisibleRow < halfPage
       
  1961             if ( !( ( 0 <= iFirstVisibleRow - thumbPosition &&
       
  1962                         iFirstVisibleRow - thumbPosition < halfPage )||                         
       
  1963                   ( 0 <= thumbPosition - iFirstVisibleRow && 
       
  1964                         thumbPosition - iFirstVisibleRow < halfPage ) ) )
       
  1965                 {               
       
  1966                 TReal toRound = thumbPosition / 
       
  1967                                 ( TReal )iExtension->iMaxVisibleRows;
       
  1968                 if ( toRound * 2 > ( TInt )toRound * 2 + 1 )
       
  1969                     {
       
  1970                     toRound++;
       
  1971                     }                  
       
  1972                 iFirstVisibleRow = ( TInt )toRound * 
       
  1973                                    iExtension->iMaxVisibleRows;
       
  1974                 update = ETrue;
       
  1975                 }
       
  1976             }
       
  1977             break;
       
  1978         
       
  1979         case EEikScrollThumbReleaseVert:
       
  1980             {
       
  1981             UpdateScrollIndicatorL();
       
  1982             }
       
  1983             break;
       
  1984         
       
  1985         case EEikScrollLeft: // flow through            
       
  1986         case EEikScrollRight: // flow through
       
  1987         case EEikScrollPageLeft: // flow through
       
  1988         case EEikScrollPageRight: // flow through
       
  1989         case EEikScrollThumbDragHoriz: // flow through
       
  1990         case EEikScrollThumbReleaseHoriz: // flow through
       
  1991             // do nothing
       
  1992             break;  
       
  1993             
       
  1994         default: 
       
  1995             // do nothing
       
  1996             break; 
       
  1997         }
       
  1998         
       
  1999     // If we have moved down to the last page we check that the cursor is in 
       
  2000     // a place where it can be drawn.       
       
  2001     if ( iFirstVisibleRow == 
       
  2002          iRows/iExtension->iMaxVisibleRows * iExtension->iMaxVisibleRows )
       
  2003         {
       
  2004         // the old cursor is set to a "safe" position where it at least can be.
       
  2005         iOldCursorPos.iX = 0;
       
  2006         iOldCursorPos.iY = 0;                                                    
       
  2007         // if the last page has only one line which isn't filled complitely.
       
  2008         if ( ( iConsArray->Count() % iMaxColumns - 1 < iCursorPos.iX ) && 
       
  2009              ( iRows % iExtension->iMaxVisibleRows ) == 1 )
       
  2010             {
       
  2011             iCursorPos.iX = iConsArray->Count()%iMaxColumns - 1;
       
  2012             }                        
       
  2013         // If the cursor is in a position where it would go unto a spot without 
       
  2014         // a icon when scrolled.
       
  2015         if ( iCursorPos.iY + iFirstVisibleRow >= iRows )
       
  2016             {                        
       
  2017             if ( iConsArray->Count() % iMaxColumns > iCursorPos.iX )
       
  2018                 {                                                      
       
  2019                 iCursorPos.iY = iRows - 1 - iFirstVisibleRow;                             
       
  2020                 }
       
  2021             else
       
  2022                 {                            
       
  2023                 iCursorPos.iY = iRows - 2 - iFirstVisibleRow;
       
  2024                 } 
       
  2025             }
       
  2026         // If the cursor is actually on the last row, but is still in the
       
  2027         // area where there is now icons. ( the rest of the last row )
       
  2028         if ( ( iConsArray->Count() <= ( iFirstVisibleRow + iCursorPos.iY ) 
       
  2029                                         * iMaxColumns + iCursorPos.iX ) &&
       
  2030              ( iCursorPos.iY + iFirstVisibleRow + 1 == iRows ) )
       
  2031             {
       
  2032             iCursorPos.iY--;
       
  2033             }
       
  2034         // if the corrections did not help and the cursor is in the area
       
  2035         // where there is a valid row, but no icons anymore
       
  2036         }
       
  2037         
       
  2038     // to avoid flicker we draw only if there really was something new to draw.
       
  2039     if ( update )
       
  2040         {              
       
  2041         if ( iExtension->iObserver )
       
  2042             {
       
  2043             iExtension->iObserver->HandleControlEventL( 
       
  2044                                       this, 
       
  2045                                       MCoeControlObserver::EEventRequestFocus );
       
  2046             } 
       
  2047         DrawDeferred();    
       
  2048         }
       
  2049     }
       
  2050 
       
  2051 // -----------------------------------------------------------------------------
       
  2052 // CCmDestinationIconMap::Extension
       
  2053 // -----------------------------------------------------------------------------
       
  2054 //
       
  2055 CCmDestinationIconMapExtension* CCmDestinationIconMap::Extension() const
       
  2056     {
       
  2057     return iExtension;
       
  2058     }