psln/Src/PslnWallpaperContainer.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Wallpaper view's container.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 // UI framework services.
       
    23 #include <aknlists.h>
       
    24 #include <eikclbd.h>
       
    25 
       
    26 // Help context.
       
    27 #include <csxhelp/skins.hlp.hrh>
       
    28 
       
    29 // Resources
       
    30 #include <psln.rsg>
       
    31 
       
    32 // Psln specific.
       
    33 #include "PslnModel.h"
       
    34 #include "PslnWallpaperContainer.h"
       
    35 #include "PslnConst.h"
       
    36 #include "PslnDebug.h"
       
    37 #include "PslnFeatures.h"
       
    38 
       
    39 // Framework
       
    40 #include <pslnfwiconhelper.h>
       
    41 
       
    42 // CONSTANTS
       
    43 // Number of wallpaper items in listbox.
       
    44 #ifndef RD_SLIDESHOW_WALLPAPER
       
    45 const TInt KPslnWallpaperItems = 2;
       
    46 #else
       
    47 const TInt KPslnWallpaperItems = 3;
       
    48 #endif // RD_SLIDESHOW_WALLPAPER
       
    49 
       
    50 // ============================ MEMBER FUNCTIONS ===============================
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // C++ default constructor can NOT contain any code, that might leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CPslnWallpaperContainer::CPslnWallpaperContainer()
       
    57     {
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // Symbian 2nd phase constructor can leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 void CPslnWallpaperContainer::ConstructL( const TRect& aRect )
       
    65     {
       
    66     iListBox = new (ELeave) CAknSingleGraphicStyleListBox;
       
    67 
       
    68     BaseConstructL(
       
    69         aRect,
       
    70         R_PSLN_WP_VIEW_LBX );
       
    71     }
       
    72 
       
    73 // Destructor
       
    74 CPslnWallpaperContainer::~CPslnWallpaperContainer()
       
    75     {
       
    76     // iListBox is deleted in class CPslnBaseContainer.
       
    77     delete iItems;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CPslnWallpaperContainer::UpdateListBoxL
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CPslnWallpaperContainer::UpdateListBoxL()
       
    85     {
       
    86     CPslnBaseContainer::UpdateListBoxL();
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CPslnWallpaperContainer::ConstructListBoxL
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CPslnWallpaperContainer::ConstructListBoxL( TInt aResLbxId )
       
    94     {
       
    95     iItems = iCoeEnv->ReadDesC16ArrayResourceL( aResLbxId );
       
    96     CreateListBoxItemsL();
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CPslnWallpaperContainer::CreateListBoxItemsL
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CPslnWallpaperContainer::CreateListBoxItemsL()
       
   104     {
       
   105     PSLN_TRACE_DEBUG("CPslnWallpaperContainer::CreateListBoxItemsL BEGIN");
       
   106     iItemArray->Reset();
       
   107     TInt selectedItem = iModel->CurrentPropertyIndexL( KPslnBgIdleSettingId );
       
   108 
       
   109     TBool slidesetSupport = 
       
   110         PslnFeatures::IsSupported( KPslnWallpaperSlideSetDialog );
       
   111 
       
   112     // Check that returned value is meaningful. If not, assume 'none' is set.
       
   113     TInt maxIndex = KPslnWallpaperItems - 1;
       
   114     if ( selectedItem < 0 ||
       
   115          selectedItem > maxIndex )
       
   116         {
       
   117         selectedItem = 0;
       
   118         }
       
   119 
       
   120     for( TInt i = 0; i < KPslnWallpaperItems; i++ )
       
   121         {
       
   122         if ( i > iItems->Count() )
       
   123             {
       
   124             User::Leave( KErrOverflow );
       
   125             }
       
   126         HBufC* itemBuf = (*iItems)[i].AllocL();
       
   127         if ( itemBuf )
       
   128             {
       
   129             PSLN_TRACE_DEBUG("CPslnWallpaperContainer::CreateListBoxItemsL 2");
       
   130             itemBuf = itemBuf->ReAllocL( itemBuf->Length() + KPslnIconSize );
       
   131             TPtr ptr = itemBuf->Des();
       
   132             if ( selectedItem == i )
       
   133                 {
       
   134                 ptr.Insert( 0, KPslnFWActiveListItemFormat );
       
   135                 }
       
   136             else
       
   137                 {
       
   138                 ptr.Insert( 0, KPslnFWNonActiveListItemFormat );
       
   139                 }
       
   140             if ( !slidesetSupport && (i + 1) == KPslnWallpaperItems )
       
   141                 {
       
   142                 // skip
       
   143                 }
       
   144             else
       
   145                 {       
       
   146                 iItemArray->InsertL( i, ptr );
       
   147                 }
       
   148             delete itemBuf;
       
   149             }
       
   150         }
       
   151 
       
   152     // Add only 'not-selected' and 'selected' icons.
       
   153     CPslnFWIconHelper* iconHelper = CPslnFWIconHelper::NewL();
       
   154     CleanupStack::PushL( iconHelper );
       
   155     iconHelper->AddIconsToSettingItemsL(
       
   156         EFalse,
       
   157         1,
       
   158         iListBox );
       
   159     CleanupStack::PopAndDestroy( iconHelper );
       
   160     DrawDeferred();
       
   161     PSLN_TRACE_DEBUG("CPslnWallpaperContainer::CreateListBoxItemsL END");
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // Gets help context for Help application.
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CPslnWallpaperContainer::GetHelpContext(
       
   169     TCoeHelpContext& aContext ) const
       
   170     {
       
   171     aContext.iMajor = KUidPsln;
       
   172     aContext.iContext = KSKINS_HLP_WP_SETTINGS;
       
   173     }
       
   174 
       
   175 //  End of File