cmmanager/cmmgr/Framework/Src/cmlistbox.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 CCmListbox
       
    15 *
       
    16 */
       
    17 
       
    18 #include <eikclbd.h>
       
    19 #include <avkon.mbg>
       
    20 #include <aknkeys.h>
       
    21 #include <data_caging_path_literals.hrh>
       
    22 
       
    23 #include "cmlistbox.h"
       
    24 #include "cmlistboxmodel.h"
       
    25 #include "cmlistitem.h"
       
    26 
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // CCmListbox::NewL
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CCmListbox* CCmListbox::NewL( const CCoeControl* aParent )
       
    33     {
       
    34     CCmListbox* listbox = new ( ELeave ) CCmListbox();
       
    35     CleanupStack::PushL( listbox );
       
    36     listbox->ConstructL( aParent, EAknListBoxSelectionList );
       
    37     CleanupStack::Pop( listbox );    
       
    38     return listbox;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CCmListbox::CCmListbox
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CCmListbox::CCmListbox()
       
    46     {
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CCmListbox::~CCmListbox
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CCmListbox::~CCmListbox()
       
    54     {
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CCmListbox::OfferKeyEventL
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 TKeyResponse CCmListbox::OfferKeyEventL
       
    62 ( const TKeyEvent& aKeyEvent, TEventCode aType )
       
    63     {
       
    64     if ( aKeyEvent.iCode == EKeyOK &&
       
    65          !( aKeyEvent.iModifiers & EModifierShift ) )
       
    66         {
       
    67         // Enter pressed (not Shift-Enter). This will report an
       
    68         // EEnterKeyPressed event sent to the observer (the view), which may
       
    69         // delete this listbox. The code which processes keypresses by
       
    70         // default, will continue (on the already deleted listbox), and
       
    71         // will crash. So we grab this keypress here, and generate the
       
    72         // same event, but after that, quit immediately!
       
    73         ReportListBoxEventL( MEikListBoxObserver::EEventEnterKeyPressed );
       
    74         // By now the listbox may have been deleted!
       
    75         // Do not access it after this point!
       
    76         return EKeyWasConsumed;
       
    77         }
       
    78     else
       
    79         {
       
    80         return CAknDoubleGraphicStyleListBox::OfferKeyEventL
       
    81             ( aKeyEvent, aType );
       
    82         }
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CCmListbox::FocusChanged
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CCmListbox::FocusChanged( TDrawNow aDrawNow )
       
    90     {
       
    91     // Do nothing until the listbox is fully constructed
       
    92     // The dialogpage sets the focus before calling ConstructL
       
    93     if ( iView )
       
    94         {
       
    95         CAknDoubleGraphicStyleListBox::FocusChanged( aDrawNow );
       
    96         }
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CCmListbox::Uid4Item
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 TUint32 CCmListbox::Uid4Item( TInt aItem ) const
       
   104     {
       
   105     CCmListboxModel* lbmodel =
       
   106         STATIC_CAST( CCmListboxModel*, Model()->ItemTextArray() );
       
   107     return lbmodel->At( aItem )->Uid();
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CCmListbox::CurrentItemUid
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 TUint32 CCmListbox::CurrentItemUid() const
       
   115     {
       
   116     CCmListboxModel* lbmodel =
       
   117         STATIC_CAST( CCmListboxModel*, Model()->ItemTextArray() );
       
   118     TInt idx = CurrentItemIndex();
       
   119     TUint32 retval( 0 );
       
   120     if ( idx >= 0 )
       
   121         {
       
   122         retval = lbmodel->At( idx )->Uid();
       
   123         }
       
   124     return retval;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CCmListbox::CurrentItemNameL
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 const TDesC& CCmListbox::CurrentItemNameL()
       
   132     {
       
   133     CCmListboxModel* lbmodel = new( ELeave )CCmListboxModel;
       
   134     lbmodel = STATIC_CAST( CCmListboxModel*, Model()->ItemTextArray() );
       
   135     return lbmodel->At( CurrentItemIndex() )->Name();
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CCmListbox::HandleResourceChange
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CCmListbox::HandleResourceChange(TInt aType)
       
   143     {
       
   144     if ( aType == KAknsMessageSkinChange )
       
   145         {
       
   146         SizeChanged();
       
   147         }
       
   148         
       
   149     CAknDoubleGraphicStyleListBox::HandleResourceChange( aType );     
       
   150     }