meetingrequest/mrgui/mrfieldbuildercommon/src/cmrgrid.cpp
branchRCL_3
changeset 12 4ce476e64c59
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     1 /*
       
     2 * Copyright (c) 2009 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:  MR grid impl.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cmrgrid.h"
       
    19 
       
    20 #include "nmrbitmapmanager.h"
       
    21 #include "nmrlayoutmanager.h"
       
    22 #include "esmrhelper.h"
       
    23 
       
    24 #include <stringloader.h>
       
    25 #include <akniconarray.h>
       
    26 #include <akngrid.h>
       
    27 #include <akngridm.h>
       
    28 #include <aknlists.h>
       
    29 #include <aknutils.h>
       
    30 #include <aknpopup.h>
       
    31 #include <avkon.hrh>
       
    32 #include <e32base.h>
       
    33 #include <gulicon.h>
       
    34 #include <aknlayout2scalabledef.h> 
       
    35 #include <esmrgui.mbg>
       
    36 #include <esmrgui.rsg>
       
    37 #include <data_caging_path_literals.hrh>
       
    38 
       
    39 // DEBUG
       
    40 #include "emailtrace.h"
       
    41 
       
    42 namespace { // codescanner::namespace
       
    43 
       
    44 //CONSTANTS
       
    45 const TInt KColumns( 3 );
       
    46 const TInt KRows( 2 );
       
    47 
       
    48 } // namespace
       
    49 
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CMRGrid::CMRGrid()
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CMRGrid::CMRGrid()
       
    57     {
       
    58     FUNC_LOG;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CMRGrid::NewL
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 TBool CMRGrid::ExecuteL( TInt& aSelectedOption )
       
    66     {
       
    67     FUNC_LOG;
       
    68     
       
    69     CMRGrid* self = new( ELeave )CMRGrid();
       
    70     CleanupStack::PushL ( self );
       
    71     TBool ret = self->ShowGridL( aSelectedOption );
       
    72     CleanupStack::PopAndDestroy( self );
       
    73     
       
    74     return ret;
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CMRGrid::~CMRGrid
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 CMRGrid::~CMRGrid( )
       
    82     {
       
    83     FUNC_LOG;
       
    84     delete iGrid;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CMRGrid::AddGridIconsL
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CMRGrid::AddGridIconsL()
       
    92     {
       
    93     FUNC_LOG;
       
    94     
       
    95     CArrayPtr<CGulIcon>* iconArray = new( ELeave ) CAknIconArray( 1 );
       
    96     CleanupStack::PushL( iconArray );
       
    97 
       
    98     /* 
       
    99      * 1. Item: Image
       
   100      */
       
   101     CFbsBitmap* imageBitmap = NULL;
       
   102     CFbsBitmap* imageBitmapMask = NULL;
       
   103     GetSkinBasedBitmapLC( NMRBitmapManager::EMRBitmapAttachmentTypeImage,
       
   104                                             imageBitmap,
       
   105                                             imageBitmapMask,
       
   106                                             TSize( 100, 100 ) );
       
   107 
       
   108     CGulIcon* imageIcon = CGulIcon::NewL( imageBitmap, imageBitmapMask );
       
   109     CleanupStack::Pop( 2 ); // imageBitmap, imageBitmapMask
       
   110     CleanupStack::PushL( imageIcon );
       
   111     iconArray->AppendL( imageIcon );
       
   112     CleanupStack::Pop( imageIcon );
       
   113 
       
   114     /* 
       
   115      * 2. Item: Video clip
       
   116      */
       
   117     CFbsBitmap* videoClipBitmap = NULL;
       
   118     CFbsBitmap* videoClipBitmapMask = NULL;
       
   119     GetSkinBasedBitmapLC( NMRBitmapManager::EMRBitmapAttachmentTypeVideo,
       
   120                                             videoClipBitmap,
       
   121                                             videoClipBitmapMask,
       
   122                                             TSize( 100, 100 ) );
       
   123 
       
   124     CGulIcon* videoClipIcon = CGulIcon::NewL( videoClipBitmap, videoClipBitmapMask );
       
   125     CleanupStack::Pop( 2 ); // videoClipBitmap, videoClipBitmapMask
       
   126     CleanupStack::PushL( videoClipIcon );
       
   127     iconArray->AppendL( videoClipIcon );
       
   128     CleanupStack::Pop( videoClipIcon );
       
   129 
       
   130     /* 
       
   131      * 3. Item: Sound clip
       
   132      */
       
   133     CFbsBitmap* soundClipBitmap = NULL;
       
   134     CFbsBitmap* soundClipBitmapMask = NULL;
       
   135     GetSkinBasedBitmapLC( NMRBitmapManager::EMRBitmapAttachmentTypeMusic,
       
   136                                             soundClipBitmap,
       
   137                                             soundClipBitmapMask,
       
   138                                             TSize( 100, 100 ) );
       
   139 
       
   140     CGulIcon* soundClipIcon = CGulIcon::NewL( soundClipBitmap, soundClipBitmapMask );
       
   141     CleanupStack::Pop( 2 ); // soundClipBitmap, soundClipBitmapMask
       
   142     CleanupStack::PushL( soundClipIcon );
       
   143     iconArray->AppendL( soundClipIcon );
       
   144     CleanupStack::Pop( soundClipIcon );
       
   145 
       
   146     /* 
       
   147      * 4. Item: Note
       
   148      */
       
   149     CFbsBitmap* noteBitmap = NULL;
       
   150     CFbsBitmap* noteBitmapMask = NULL;
       
   151     GetSkinBasedBitmapLC( NMRBitmapManager::EMRBitmapAttachmentTypeNote,
       
   152                                             noteBitmap,
       
   153                                             noteBitmapMask,
       
   154                                             TSize( 100, 100 ) );
       
   155 
       
   156     CGulIcon* noteIcon = CGulIcon::NewL( noteBitmap, noteBitmapMask );
       
   157     CleanupStack::Pop( 2 ); // noteBitmap, noteBitmapMask
       
   158     CleanupStack::PushL( noteIcon );
       
   159     iconArray->AppendL( noteIcon );
       
   160     CleanupStack::Pop( noteIcon );
       
   161     
       
   162     /* 
       
   163      * 5. Item: Other
       
   164      */
       
   165     CFbsBitmap* otherBitmap = NULL;
       
   166     CFbsBitmap* otherBitmapMask = NULL;
       
   167     GetSkinBasedBitmapLC( NMRBitmapManager::EMRBitmapAttachmentTypeOther,
       
   168                                             otherBitmap,
       
   169                                             otherBitmapMask,
       
   170                                             TSize( 100, 100 ) );
       
   171 
       
   172     CGulIcon* otherIcon = CGulIcon::NewL( otherBitmap, otherBitmapMask );
       
   173     CleanupStack::Pop( 2 ); // otherBitmap, otherBitmapMask
       
   174     CleanupStack::PushL( otherIcon );
       
   175     iconArray->AppendL( otherIcon );
       
   176     CleanupStack::Pop( otherIcon );
       
   177 
       
   178     iGrid->ItemDrawer()->ColumnData()->SetIconArray( iconArray );
       
   179 
       
   180     CleanupStack::Pop( iconArray );
       
   181     iGrid->HandleItemAdditionL();
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CMRGrid::ShowGridL
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 TBool CMRGrid::ShowGridL( TInt& aSelectedOption )
       
   189     {
       
   190     FUNC_LOG;
       
   191     TRect mainPaneRect( 0, 0, 0, 0 );
       
   192     AknLayoutUtils::LayoutMetricsRect( 
       
   193             AknLayoutUtils::EMainPane, mainPaneRect );
       
   194     
       
   195     TAknLayoutRect gridLayoutRect =
       
   196         NMRLayoutManager::GetLayoutRect( 
       
   197                 mainPaneRect, 
       
   198                 NMRLayoutManager::EMRLayoutAttachmentSelectionGrid );
       
   199     
       
   200     TRect gridRect( gridLayoutRect.Rect() );
       
   201     
       
   202     TAknLayoutRect cellLayoutRect =
       
   203            NMRLayoutManager::GetLayoutRect( 
       
   204                    gridRect, 
       
   205                    NMRLayoutManager::EMRLayoutAttachmentSelectionGridCell );
       
   206         
       
   207     TRect cellRect( cellLayoutRect.Rect() );
       
   208     cellRect.Move( -gridRect.iTl);    
       
   209     
       
   210     iGrid = new( ELeave ) CAknGrid;
       
   211     CAknPopupList* gridList =  CAknPopupList::NewL( 
       
   212             iGrid, R_AVKON_SOFTKEYS_SELECT_BACK );
       
   213     CleanupStack::PushL( gridList );
       
   214        
       
   215     // Load query heading
       
   216     HBufC* buf( StringLoader::LoadLC( 
       
   217             R_QTN_MEET_REQ_QUERY_HEADING_SELECT_ATTACHMENT_TYPE ) );
       
   218     gridList->SetTitleL( *buf );
       
   219     CleanupStack::PopAndDestroy( buf );
       
   220 
       
   221     iGrid->ConstructL( gridList, EAknListBoxMenuGrid );
       
   222     iGrid->SetLayoutL( 
       
   223             EFalse, ETrue, ETrue, KColumns, KRows, cellRect.Size() );
       
   224     iGrid->SetPrimaryScrollingType( 
       
   225             CAknGridView::EScrollIncrementLineAndLoops );
       
   226     iGrid->SetSecondaryScrollingType( 
       
   227             CAknGridView::EScrollIncrementLineAndLoops );
       
   228 
       
   229     iGrid->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
   230             CEikScrollBarFrame::EOff,
       
   231             CEikScrollBarFrame::EOff );
       
   232     
       
   233     CDesCArray *gridItemArray = static_cast<CDesCArray*>( 
       
   234             iGrid->Model()->ItemTextArray() );
       
   235     
       
   236     // The order of the items should be in line with 
       
   237     // CMRAttachmentUi::ResolveAttachmentTypeL switch case items.
       
   238     // TODO: update texts to be read from resource
       
   239     HBufC* textImage = StringLoader::LoadLC( 
       
   240             R_QTN_MEET_REQ_ATTACHMENT_TYPE_IMAGE );
       
   241     gridItemArray->AppendL( _L("0\tImage") /*textImage*/ );
       
   242     CleanupStack::PopAndDestroy( textImage );
       
   243     
       
   244     HBufC* textVideo = StringLoader::LoadLC( 
       
   245             R_QTN_MEET_REQ_ATTACHMENT_TYPE_VIDEO );
       
   246     gridItemArray->AppendL( _L("1\tVideo clip") /*textVideo*/ );
       
   247     CleanupStack::PopAndDestroy( textVideo );
       
   248     
       
   249     HBufC* textSound = StringLoader::LoadLC( 
       
   250             R_QTN_MEET_REQ_ATTACHMENT_TYPE_SOUNDCLIP );
       
   251     gridItemArray->AppendL( _L("2\tSound clip") /*textSound*/ );
       
   252     CleanupStack::PopAndDestroy( textSound );
       
   253 
       
   254     HBufC* textNote = StringLoader::LoadLC( 
       
   255             R_QTN_MEET_REQ_ATTACHMENT_TYPE_NOTE );
       
   256     gridItemArray->AppendL( _L("3\tNote") /*textNote*/ );
       
   257     CleanupStack::PopAndDestroy( textNote );
       
   258     
       
   259     HBufC* textOther = StringLoader::LoadLC( 
       
   260             R_QTN_MEET_REQ_ATTACHMENT_TYPE_NOTE );
       
   261     gridItemArray->AppendL( _L("4\tOther") /*textOther*/ );
       
   262     CleanupStack::PopAndDestroy( textOther );
       
   263 
       
   264     iGrid->HandleItemAdditionL();
       
   265 
       
   266     AddGridIconsL();
       
   267     
       
   268     TAknLayoutRect graphicLayoutRect =
       
   269            NMRLayoutManager::GetLayoutRect( 
       
   270                    cellRect, 
       
   271                    NMRLayoutManager::
       
   272                    EMRLayoutAttachmentSelectionGridCellGraphic );
       
   273     
       
   274     TRect graphicRect( graphicLayoutRect.Rect() );
       
   275 
       
   276     // Setup grid graphics
       
   277     AknListBoxLayouts::SetupFormGfxCell( 
       
   278             *iGrid, iGrid->ItemDrawer(), 
       
   279              0 /*Column index*/,
       
   280              graphicRect.iTl.iX /*Left pos*/, 
       
   281              graphicRect.iTl.iY /*Top pos*/,
       
   282              0 /*unused*/, 
       
   283              0 /*unused*/, 
       
   284              graphicRect.Width() /*Icon width*/, 
       
   285              graphicRect.Height() /*Icon height*/,
       
   286              graphicRect.iTl /*Start pos*/, 
       
   287              graphicRect.iBr /*End pos*/ );
       
   288     
       
   289     TAknLayoutText gridTextLayout( 
       
   290             NMRLayoutManager::GetLayoutText( 
       
   291                     cellRect, 
       
   292                     NMRLayoutManager::
       
   293                     EMRTextLayoutAttachmentSelectionGridCellText ) );
       
   294     
       
   295     TRect textRect( gridTextLayout.TextRect() );
       
   296 
       
   297     // Calculate the text baseline
       
   298     TInt baseLine( cellRect.iBr.iY - ( cellRect.iBr.iY - textRect.iBr.iY ) );
       
   299     // Reduce font's descent -> Baseline calculated
       
   300     baseLine -= gridTextLayout.Font()->DescentInPixels();
       
   301     
       
   302     // Setup grid texts
       
   303     AknListBoxLayouts::SetupFormTextCell( 
       
   304             *iGrid, iGrid->ItemDrawer(), 
       
   305              1 /*Column index*/,
       
   306              gridTextLayout.Font() /*Font type*/,
       
   307              gridTextLayout.Color().Value() /*color*/,
       
   308              0 /*Left margin*/, 
       
   309              0 /*unused*/,
       
   310              baseLine/*Baseline*/, 
       
   311              0 /*Text width*/,
       
   312              gridTextLayout.Align() /*Text alignment*/,
       
   313              textRect.iTl /*Start pos*/,
       
   314              textRect.iBr /*End pos*/);
       
   315     
       
   316     TBool popupOk = gridList->ExecuteLD();
       
   317     aSelectedOption = iGrid->CurrentDataIndex();
       
   318     CleanupStack::Pop( gridList );
       
   319     
       
   320     return popupOk;
       
   321     }
       
   322 
       
   323 //EOF