homesync/contentmanager/homesyncwizard/src/cmsmultiselectionpopup.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Multiselection popup implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <avkon.mbg>
       
    21 #include <AknsUtils.h>
       
    22 #include <cmsappwizard.rsg>
       
    23 
       
    24 #include "cmsmultiselectionpopup.h"
       
    25 #include "msdebug.h"
       
    26 
       
    27 // Format string for listbox items
       
    28 _LIT(KItemFormatString, "1\t%S");
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CMSMultiselectionPopup::NewL
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CMSMultiselectionPopup* CMSMultiselectionPopup::NewL(
       
    35     CDesCArrayFlat* aItemArray,
       
    36     CListBoxView::CSelectionIndexArray* aSelectionIndexArray,
       
    37     const TDesC& aHeading )
       
    38     {
       
    39     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup::NewL begin"));
       
    40 
       
    41     CMSMultiselectionPopup* self =
       
    42                     CMSMultiselectionPopup::NewLC( aItemArray,
       
    43                                                    aSelectionIndexArray,
       
    44                                                    aHeading );
       
    45     CleanupStack::Pop( self );
       
    46 
       
    47     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup::NewL end"));
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CMSMultiselectionPopup::NewLC
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CMSMultiselectionPopup* CMSMultiselectionPopup::NewLC(
       
    56     CDesCArrayFlat* aItemArray,
       
    57     CListBoxView::CSelectionIndexArray* aSelectionIndexArray,
       
    58     const TDesC& aHeading )
       
    59     {
       
    60     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup::NewLC begin"));
       
    61 
       
    62     CMSMultiselectionPopup* self =
       
    63                         new(ELeave) CMSMultiselectionPopup( NULL,
       
    64                                                             aHeading );
       
    65 
       
    66     CleanupStack::PushL(self);
       
    67     self->ConstructL( aItemArray, aSelectionIndexArray );
       
    68 
       
    69     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup::NewLC end"));
       
    70     return self;
       
    71     }
       
    72     
       
    73 // ---------------------------------------------------------------------------
       
    74 // CMSMultiselectionPopup::ConstructL
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CMSMultiselectionPopup::ConstructL(
       
    78     CDesCArrayFlat* aItemArray,
       
    79     CListBoxView::CSelectionIndexArray* aSelectionIndexArray )
       
    80     {
       
    81     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup::\
       
    82     ConstructL begin"));
       
    83 
       
    84     iItemArray = aItemArray;
       
    85 
       
    86     iSelectionIndexes = aSelectionIndexArray;
       
    87 
       
    88     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup::\
       
    89     ConstructL end"));
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CMSMultiselectionPopup::CMSMultiselectionPopup
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 CMSMultiselectionPopup::CMSMultiselectionPopup(
       
    97     CListBoxView::CSelectionIndexArray* aSelectionIndexArray,
       
    98     const TDesC& aHeading )
       
    99     : CAknListQueryDialog( aSelectionIndexArray ),
       
   100       iHeading( aHeading )
       
   101 
       
   102     {
       
   103     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup:: \
       
   104             CMSMultiselectionPopup"));
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CMSMultiselectionPopup::~CMSMultiselectionPopup
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 CMSMultiselectionPopup::~CMSMultiselectionPopup()
       
   112     {
       
   113     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup::\
       
   114     CMSMultiselectionPopup"));
       
   115     }
       
   116     
       
   117 // ---------------------------------------------------------------------------
       
   118 // CMSMultiselectionPopup::UpdateAndDrawPopup
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CMSMultiselectionPopup::UpdateAndDrawPopupL(
       
   122     CDesCArrayFlat* aItemArray )
       
   123     {
       
   124     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup:: \
       
   125             UpdateAndDrawPopupL begin"));
       
   126 
       
   127     iItemArray = aItemArray;
       
   128 
       
   129     if ( iItemArray->Count() )
       
   130         {
       
   131         CreateAndSetListboxItemsL();        
       
   132         }
       
   133                
       
   134     Layout();
       
   135     SizeChanged();    
       
   136     iListBox->DrawNow();
       
   137 
       
   138     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup:: \
       
   139             UpdateAndDrawPopupL ends"));
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CMSMultiselectionPopup::AppendIconToArrayL
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CMSMultiselectionPopup::AppendIconToArrayL(CAknIconArray* aArray,
       
   147                                                MAknsSkinInstance* aSkin,
       
   148                                                const TDesC& aMbmFile,
       
   149                                                const TAknsItemID& aID,
       
   150                                                TInt aBitmapId,
       
   151                                                TInt aMaskId) const
       
   152     {
       
   153     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup:: \
       
   154             AppendIconToArrayL begin"));
       
   155 
       
   156     __ASSERT_DEBUG( aArray, User::Leave(KErrArgument) );
       
   157 
       
   158     CFbsBitmap* bitmap = NULL;
       
   159     CFbsBitmap* mask = NULL;
       
   160 
       
   161     AknsUtils::CreateIconLC(aSkin, aID,
       
   162         bitmap, mask, aMbmFile, aBitmapId, aMaskId);
       
   163 
       
   164     CGulIcon* icon = CGulIcon::NewL(bitmap, mask);
       
   165     icon->SetBitmapsOwnedExternally(EFalse);
       
   166 
       
   167     // icon now owns the bitmaps, no need to keep on cleanup stack.
       
   168     CleanupStack::Pop(2); // mask, bitmap
       
   169     bitmap = NULL;
       
   170     mask = NULL;
       
   171 
       
   172     CleanupStack::PushL(icon);
       
   173 
       
   174     aArray->AppendL(icon);
       
   175 
       
   176     // aArray now owns the icon, no need to delete.
       
   177     CleanupStack::Pop(icon);
       
   178     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup:: \
       
   179             AppendIconToArrayL end"));
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CMSMultiselectionPopup::OkToExitL(TInt aButtonId)
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 TBool CMSMultiselectionPopup::OkToExitL(TInt aButtonId)
       
   187     {
       
   188     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup::\
       
   189 OkToExitL begin"));
       
   190 
       
   191     if ( aButtonId == EAknSoftkeyNext ||  aButtonId == EAknSoftkeyBack )
       
   192         {
       
   193         LOG(_L("[MSAppWizard]\t CUPnPAppMultiselectionPopup::\
       
   194 OkToExitL: Next or Back"));
       
   195 
       
   196         const CListBoxView::CSelectionIndexArray* selected =
       
   197             ListBox()->SelectionIndexes();
       
   198 
       
   199         if ( iSelectionIndexes )
       
   200             {
       
   201             TInt selectCount = selected->Count();
       
   202             iSelectionIndexes->Reset();
       
   203             for ( TInt i = 0; i < selectCount; i++ )
       
   204                 {
       
   205                 iSelectionIndexes->AppendL( selected->At( i ) );
       
   206                 }
       
   207             }
       
   208         }
       
   209 
       
   210     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup::\
       
   211 OkToExitL end"));
       
   212     return ETrue;
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // CMSMultiselectionPopup::CreateAndSetListboxItemsL()
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CMSMultiselectionPopup::CreateAndSetListboxItemsL()
       
   220     {
       
   221     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup::\
       
   222     CreateAndSetListboxItemsL"));    
       
   223     
       
   224     TInt itemCount = iItemArray->Count();
       
   225     
       
   226     CDesCArrayFlat* listItems = new (ELeave) CDesCArrayFlat( 5 );
       
   227     CleanupStack::PushL( listItems );
       
   228     
       
   229     for ( TInt i = 0; i < itemCount; i++)
       
   230         {
       
   231         TPtrC itemStr = iItemArray->MdcaPoint(i);
       
   232         HBufC* item = HBufC::NewLC( itemStr.Size() +
       
   233                                     sizeof( KItemFormatString ) );                                
       
   234         item->Des().Format( KItemFormatString, &itemStr );             
       
   235         
       
   236         listItems->AppendL( *item );
       
   237         CleanupStack::PopAndDestroy( item );        
       
   238         }
       
   239     SetItemTextArray( listItems );
       
   240     CleanupStack::Pop( listItems );
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // CMSMultiselectionPopup::PreLayoutDynInitL()
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 void CMSMultiselectionPopup::PreLayoutDynInitL()
       
   248     {
       
   249     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup:: \
       
   250             PreLayoutDynInitL begin"));
       
   251 
       
   252     // two icons
       
   253     CAknIconArray* icons = new (ELeave) CAknIconArray(2);
       
   254     CleanupStack::PushL( icons );
       
   255 
       
   256     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   257     TFileName iconsPath( AknIconUtils::AvkonIconFileName() );
       
   258 
       
   259     AppendIconToArrayL( icons, skin,
       
   260                         iconsPath,
       
   261                         KAknsIIDQgnPropCheckboxOn,
       
   262                         EMbmAvkonQgn_indi_checkbox_on,
       
   263                         EMbmAvkonQgn_indi_checkbox_on_mask );
       
   264 
       
   265     AppendIconToArrayL( icons, skin,
       
   266                         iconsPath,
       
   267                         KAknsIIDQgnPropCheckboxOff,
       
   268                         EMbmAvkonQgn_indi_checkbox_off,
       
   269                         EMbmAvkonQgn_indi_checkbox_off_mask );
       
   270 
       
   271 
       
   272     CAknListQueryDialog::SetIconArrayL(icons);
       
   273 
       
   274     CleanupStack::Pop(icons);
       
   275 
       
   276     iListBox = ListBox();
       
   277 
       
   278     CAknFilteredTextListBoxModel* model = STATIC_CAST(
       
   279             CAknFilteredTextListBoxModel*,
       
   280             iListBox->Model());
       
   281 
       
   282     // create listbox items if any
       
   283     if ( iItemArray->Count() )
       
   284         {
       
   285         CreateAndSetListboxItemsL();        
       
   286         }
       
   287     
       
   288     SetHeaderTextL( iHeading );
       
   289 
       
   290     iListBox->ActivateL();
       
   291     
       
   292     CAknListQueryDialog::PreLayoutDynInitL();
       
   293 
       
   294     LOG(_L("[MSAppWizard]\t CMSMultiselectionPopup:: \
       
   295             PreLayoutDynInitL end"));
       
   296     }
       
   297 
       
   298 // End of file
       
   299 
       
   300