filemanager/View/src/CFileManagerCheckBoxSettingPage.cpp
changeset 0 6a9f87576119
equal deleted inserted replaced
-1:000000000000 0:6a9f87576119
       
     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:  Checkbox setting page
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <akncheckboxsettingpage.h>
       
    22 #include "CFileManagerCheckBoxSettingPage.h"
       
    23 
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ========
       
    26 // ----------------------------------------------------------------------------
       
    27 // CFileManagerCheckBoxSettingPage::CFileManagerCheckBoxSettingPage
       
    28 // ----------------------------------------------------------------------------
       
    29 // 
       
    30 CFileManagerCheckBoxSettingPage::CFileManagerCheckBoxSettingPage(
       
    31         const TInt aResourceID,
       
    32         CSelectionItemList& aItemArray,
       
    33         const TInt aDominantItemIndex ) :
       
    34     CAknCheckBoxSettingPage( aResourceID, &aItemArray ),
       
    35     iItemsArray( aItemArray ),
       
    36     iDominantItemIndex( aDominantItemIndex )
       
    37     {
       
    38     }
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // CFileManagerCheckBoxSettingPage::~CFileManagerCheckBoxSettingPage
       
    42 // ----------------------------------------------------------------------------
       
    43 // 
       
    44 CFileManagerCheckBoxSettingPage::~CFileManagerCheckBoxSettingPage()
       
    45     {
       
    46     }
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // CFileManagerCheckBoxSettingPage::UpdateSelectionL
       
    50 // ----------------------------------------------------------------------------
       
    51 // 
       
    52 void CFileManagerCheckBoxSettingPage::UpdateSettingL()   
       
    53     {
       
    54     CAknCheckBoxSettingPage::UpdateSettingL();
       
    55     UpdateSelection();
       
    56     }
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 // CFileManagerCheckBoxSettingPage::UpdateSelection
       
    60 // ----------------------------------------------------------------------------
       
    61 // 
       
    62 void CFileManagerCheckBoxSettingPage::UpdateSelection()
       
    63     {
       
    64     TInt count( iItemsArray.Count() );
       
    65     if ( iDominantItemIndex < 0 || iDominantItemIndex > count  )
       
    66         {
       
    67         return; // Dominant item not used
       
    68         }
       
    69 
       
    70     CAknSetStyleListBox* listBox = ListBoxControl();
       
    71     CListBoxView* view = listBox->View();
       
    72 
       
    73     TInt selectedItem( listBox->CurrentItemIndex() );
       
    74     if ( selectedItem < 0 || selectedItem > count  )
       
    75         {
       
    76         return; // Invalid selection
       
    77         }
       
    78 
       
    79     TBool redraw( EFalse );
       
    80 
       
    81     // Deselect all other items if dominant item is selected
       
    82     if ( iDominantItemIndex == selectedItem &&
       
    83         iItemsArray.At( selectedItem )->SelectionStatus() )
       
    84         {
       
    85         for ( TInt i( 0 ); i < count; ++i )
       
    86             {
       
    87             if ( i != iDominantItemIndex )
       
    88                 {
       
    89                 iItemsArray.At( i )->SetSelectionStatus( EFalse );
       
    90                 view->DeselectItem( i );
       
    91                 }
       
    92             }
       
    93         redraw = ETrue;
       
    94         }
       
    95     // Deselect dominant item if any other item is selected
       
    96     else if ( iDominantItemIndex != selectedItem &&
       
    97              iItemsArray.At( iDominantItemIndex )->SelectionStatus() )
       
    98         {
       
    99         for ( TInt i( 0 ); i < count; ++i )
       
   100             {
       
   101             if ( i != iDominantItemIndex &&
       
   102                 iItemsArray.At( i )->SelectionStatus() )
       
   103                 {
       
   104                 iItemsArray.At( iDominantItemIndex )->SetSelectionStatus(
       
   105                     EFalse );
       
   106                 view->DeselectItem( iDominantItemIndex );
       
   107                 redraw = ETrue;
       
   108                 break;
       
   109                 }
       
   110             }
       
   111         }
       
   112 
       
   113     // Hide ok if selection is empty
       
   114     TBool empty( ETrue );
       
   115     for ( TInt i( 0 ); i < count; ++i )
       
   116         {
       
   117         if ( iItemsArray.At( i )->SelectionStatus() )
       
   118             {
       
   119             empty = EFalse;
       
   120             break;
       
   121             }
       
   122         }
       
   123     CEikButtonGroupContainer* cba = Cba();
       
   124     if ( empty )
       
   125         {
       
   126         cba->MakeCommandVisible( EAknSoftkeyOk, EFalse );
       
   127         }
       
   128     else
       
   129         {
       
   130         cba->MakeCommandVisible( EAknSoftkeyOk, ETrue );
       
   131         }
       
   132     cba->DrawDeferred();
       
   133 
       
   134     if ( redraw )
       
   135         {
       
   136         listBox->DrawDeferred();
       
   137         }
       
   138     }
       
   139 
       
   140 // End of File