messagingappbase/mce/src/MceMessageListContainer.cpp
changeset 0 72b543305e3a
child 1 d09ac5c1e252
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  
       
    15 *     List container user by message view.
       
    16 *     Derived from CMceMessageListContainer.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 
       
    24 #include "mceui.h"
       
    25 #include "MceMessageListContainer.h"
       
    26 #include "MceMessageListbox.h"
       
    27 #include "MceMessageListView.h"
       
    28 #include "MceMessageListItemArray.h"
       
    29 #include "MceBitmapResolver.h"
       
    30 #include "MceCommands.hrh"
       
    31 #include "MceIds.hrh"
       
    32 #include <mce.rsg>
       
    33 #include "McePropertySubscriber.h"
       
    34 #include <PtiEngine.h>
       
    35 #include <AvkonInternalCRKeys.h> // KCRUidAvkon
       
    36 
       
    37 #include <msvids.h>
       
    38 #include <msvuids.h>      // KUidMsvMessageEntry
       
    39 
       
    40 #include <bldvariant.hrh>
       
    41 
       
    42 #include <csxhelp/mce.hlp.hrh>
       
    43 #include <csxhelp/mbxs.hlp.hrh>
       
    44 #include "MceIds.h"
       
    45 #include <MuiuMsvUiServiceUtilities.h>
       
    46 
       
    47 #include <commonphoneparser.h>
       
    48 #include <featmgr.h>
       
    49 
       
    50 // For Muiu split
       
    51 #include <muiumsvuiserviceutilitiesinternal.h>
       
    52 
       
    53 // CONSTANTS
       
    54 
       
    55 const TInt KMceTextBufferLength        = 10; // text buffer length
       
    56 const TInt KMceListContainerGranuality = 4;
       
    57 // ================= MEMBER FUNCTIONS =======================
       
    58 
       
    59 // ----------------------------------------------------
       
    60 // Constructor
       
    61 // ----------------------------------------------------
       
    62 CMceMessageListContainer::CMceMessageListContainer( 
       
    63     CMceMessageListView& aParentView ) 
       
    64     :
       
    65     CMceMessageListContainerBase( aParentView )
       
    66     {
       
    67     }
       
    68 
       
    69 // ----------------------------------------------------
       
    70 // Destructor
       
    71 // ----------------------------------------------------
       
    72 CMceMessageListContainer::~CMceMessageListContainer()
       
    73     {
       
    74     delete iT9Interface;
       
    75     delete iT9Timer;      
       
    76     
       
    77     if (iQwertyModeStatusSubscriber)
       
    78         {
       
    79         iQwertyModeStatusSubscriber->StopSubscribe();
       
    80         }
       
    81     iQwertyModeStatusProperty.Close();
       
    82     delete iQwertyModeStatusSubscriber;
       
    83     
       
    84     if ( iListBox )
       
    85         {
       
    86         // icon array is deleted by CMceUi class
       
    87         iListBox->ItemDrawer()->FormattedCellData()->SetIconArray( NULL );
       
    88         }
       
    89     
       
    90     delete iListBox;
       
    91     delete iListItems;
       
    92     delete iSelectedEntries;
       
    93     }
       
    94 
       
    95 // ----------------------------------------------------
       
    96 // CMceMessageListContainer::NewL
       
    97 // ----------------------------------------------------
       
    98 CMceMessageListContainer* CMceMessageListContainer::NewL(
       
    99     const TRect& aRect,
       
   100     CMsvSessionPtr aSession,
       
   101     TMsvId aFolderId,
       
   102     CMceBitmapResolver& aBitmapResolver,
       
   103     CMceMessageListView& aParentView )
       
   104     {
       
   105     CMceMessageListContainer* self = new (ELeave) CMceMessageListContainer(
       
   106         aParentView );
       
   107     CleanupStack::PushL(self);
       
   108     self->ConstructL( aRect, aSession, aBitmapResolver, aFolderId );
       
   109     CleanupStack::Pop(); // self
       
   110     return self;
       
   111     }
       
   112 
       
   113 // ----------------------------------------------------
       
   114 // CMceMessageListContainer::ConstructL
       
   115 // ----------------------------------------------------
       
   116 void CMceMessageListContainer::ConstructL(
       
   117     const TRect& aRect,
       
   118     CMsvSessionPtr aSession,
       
   119     CMceBitmapResolver& aBitmapResolver,
       
   120     TMsvId aFolderId )
       
   121     {
       
   122     CreateWindowL();
       
   123     SetRect( aRect );
       
   124 
       
   125     iListBox = new (ELeave) CMceMessageListBox( *this );
       
   126     iListBox->ConstructL( this, EAknListBoxStylusMarkableList );
       
   127     iListBox->ItemDrawer()->SetItemMarkReverse( ETrue );
       
   128     iListBox->EnableMSKObserver( EFalse );
       
   129 
       
   130     iListItems = CMceMessageListItemArray::NewL(
       
   131         aSession, aFolderId, EMceListTypeMessage, aBitmapResolver );
       
   132 
       
   133     iListBox->Model()->SetItemTextArray( iListItems );
       
   134     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   135     
       
   136     iListBox->SetListBoxObserver( &iOwningView );
       
   137 
       
   138     iSelectedEntries = new (ELeave) CMsvEntrySelection;
       
   139     
       
   140     iListBox->CreateScrollBarFrameL( ETrue );
       
   141     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   142         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   143 
       
   144     iListBox->ItemDrawer()->FormattedCellData()
       
   145         ->SetIconArray( aBitmapResolver.IconArray() );
       
   146     
       
   147     iPreviousInputMethod = EFalse;
       
   148     
       
   149     User::LeaveIfError( iQwertyModeStatusProperty.Attach( 
       
   150         KCRUidAvkon, KAknQwertyInputModeActive ));
       
   151   
       
   152     HandleQwertyModeChangeNotification();
       
   153     iQwertyModeStatusSubscriber = CMcePropertySubscriber::NewL(
       
   154         TCallBack( QwertyModeChangeNotification, this ), iQwertyModeStatusProperty );
       
   155 
       
   156     iQwertyModeStatusSubscriber->SubscribeL();
       
   157     iDialerEvent = EFalse ;
       
   158 
       
   159     }
       
   160     
       
   161 // ----------------------------------------------------
       
   162 // CMceMessageListContainer::MceListId
       
   163 // ----------------------------------------------------
       
   164 TInt CMceMessageListContainer::MceListId() const
       
   165     {
       
   166     return EMceListTypeTwoRow;
       
   167     }
       
   168     
       
   169 
       
   170 // ----------------------------------------------------
       
   171 // CMceMessageListContainer::CountComponentControls
       
   172 // ----------------------------------------------------
       
   173 TInt CMceMessageListContainer::CountComponentControls() const
       
   174     {
       
   175     return 1; // always only listbox
       
   176     }
       
   177 
       
   178 // ----------------------------------------------------
       
   179 // CMceMessageListContainer::ComponentControl
       
   180 // ----------------------------------------------------
       
   181 CCoeControl* CMceMessageListContainer::ComponentControl(TInt /*aIndex*/) const
       
   182     {
       
   183     return iListBox;
       
   184     }
       
   185 
       
   186 // ----------------------------------------------------
       
   187 // CMceMessageListContainer::SetFolderL
       
   188 // ----------------------------------------------------
       
   189 void CMceMessageListContainer::SetFolderL( TMsvId aFolderId )
       
   190     {
       
   191     if ( iListItems )
       
   192         {
       
   193         iListItems->SetFolderL( aFolderId );
       
   194         }
       
   195     }
       
   196     
       
   197 // ----------------------------------------------------
       
   198 // CMceMessageListContainer::Count
       
   199 // ----------------------------------------------------
       
   200 TInt CMceMessageListContainer::Count() const
       
   201     {
       
   202     return iListItems->MdcaCount();
       
   203     }
       
   204     
       
   205 // ----------------------------------------------------
       
   206 // CMceMessageListContainer::MessageCount
       
   207 // ----------------------------------------------------
       
   208 TInt CMceMessageListContainer::MessageCount() const
       
   209     {
       
   210     return iListItems->MessageCount();
       
   211     }
       
   212     
       
   213 // ----------------------------------------------------
       
   214 // CMceMessageListContainer::FolderCount
       
   215 // ----------------------------------------------------
       
   216 TInt CMceMessageListContainer::FolderCount() const
       
   217     {
       
   218     return iListItems->FolderCount();
       
   219     }
       
   220     
       
   221 // ----------------------------------------------------
       
   222 // CMceMessageListContainer::CurrentFolderId
       
   223 // ----------------------------------------------------
       
   224 TMsvId CMceMessageListContainer::CurrentFolderId() const
       
   225     {
       
   226     TMsvId folderId = 0;
       
   227     if ( iListItems )
       
   228         {
       
   229         folderId = iListItems->FolderId();
       
   230         }
       
   231     return folderId;
       
   232     }
       
   233 
       
   234 // ----------------------------------------------------
       
   235 // CMceMessageListContainer::SetCurrentItemIdL
       
   236 // ----------------------------------------------------
       
   237 TBool CMceMessageListContainer::SetCurrentItemIdL( TMsvId aEntryId )
       
   238     {
       
   239     const TInt selectedIndex = ItemIndex( aEntryId );
       
   240     if ( selectedIndex != KErrNotFound )
       
   241         {
       
   242         iAnchorItemIndex = selectedIndex; 
       
   243         iAnchorItemId = aEntryId;
       
   244         
       
   245 		//calulate the top item index
       
   246 		TInt topIndex = iListBox->View()->CalcNewTopItemIndexSoItemIsVisible( selectedIndex );
       
   247 		iListBox->SetTopItemIndex( topIndex );
       
   248 		iListBox->SetCurrentItemIndex( selectedIndex );
       
   249 		iListBox->UpdateScrollBarsL();
       
   250 		iListBox->DrawDeferred();
       
   251 //        iListBox->SetCurrentItemIndex( selectedIndex );
       
   252         }
       
   253     return (selectedIndex != KErrNotFound);
       
   254         
       
   255     }
       
   256     
       
   257 // ----------------------------------------------------
       
   258 // CMceMessageListContainer::RefreshListbox
       
   259 // ----------------------------------------------------
       
   260 void CMceMessageListContainer::RefreshListbox()
       
   261     {
       
   262     iListBox->DrawDeferred();     
       
   263     }
       
   264 
       
   265 // ----------------------------------------------------
       
   266 // CMceMessageListContainer::ItemCountChangedL
       
   267 // ----------------------------------------------------
       
   268 void CMceMessageListContainer::ItemCountChangedL( TBool aItemsAdded )
       
   269     {
       
   270     if ( aItemsAdded )
       
   271         {
       
   272         iListBox->HandleItemAdditionL();     
       
   273         }
       
   274     else
       
   275         {
       
   276         iListBox->HandleItemRemovalL();
       
   277         }
       
   278     }
       
   279     
       
   280     
       
   281 // ----------------------------------------------------
       
   282 // CMceMessageListContainer::FolderEntry
       
   283 // ----------------------------------------------------
       
   284 const TMsvEntry& CMceMessageListContainer::FolderEntry() const
       
   285     {
       
   286     return iListItems->FolderEntry();
       
   287     }
       
   288 
       
   289 // ----------------------------------------------------
       
   290 // CMceMessageListContainer::CurrentItemIndex
       
   291 // ----------------------------------------------------
       
   292 TInt CMceMessageListContainer::CurrentItemIndex() const
       
   293     {
       
   294     return iListBox->CurrentItemIndex();
       
   295     }
       
   296 
       
   297 // ----------------------------------------------------
       
   298 // CMceMessageListContainer::CurrentItemId
       
   299 // ----------------------------------------------------
       
   300 TMsvId CMceMessageListContainer::CurrentItemId() const
       
   301     {
       
   302     return iListItems->ItemId( CurrentItemIndex() );
       
   303     }
       
   304 
       
   305 // ----------------------------------------------------
       
   306 // CMceMessageListContainer::CurrentItemListItem
       
   307 // ----------------------------------------------------
       
   308 TMceListItem CMceMessageListContainer::CurrentItemListItem() const
       
   309     {
       
   310     return iListItems->Item( CurrentItemIndex() );
       
   311     }
       
   312 
       
   313 
       
   314 // ----------------------------------------------------
       
   315 // CMceMessageListContainer::CurrentItemSelectionL
       
   316 // ----------------------------------------------------
       
   317 CMsvEntrySelection* CMceMessageListContainer::CurrentItemSelectionL()
       
   318     {
       
   319     return iSelectedEntries->CopyL();
       
   320     }
       
   321 
       
   322 // ----------------------------------------------------
       
   323 // CMceMessageListContainer::CurrentItemSelectionRefreshL
       
   324 // ----------------------------------------------------
       
   325 CMsvEntrySelection* CMceMessageListContainer::CurrentItemSelectionRefreshL()
       
   326     {
       
   327     MarkItemSelectionL();
       
   328     return CurrentItemSelectionL();
       
   329     }
       
   330 
       
   331 // ----------------------------------------------------
       
   332 // CMceMessageListContainer::CurrentItemSelectionCount
       
   333 // ----------------------------------------------------
       
   334 TInt CMceMessageListContainer::CurrentItemSelectionCount() const
       
   335     {
       
   336     if ( iListItems->MdcaCount() == 0 )
       
   337         {
       
   338         return 0;
       
   339         }
       
   340     return Max( 1, iListBox->View()->SelectionIndexes()->Count() );
       
   341     }
       
   342 
       
   343 
       
   344 // ----------------------------------------------------
       
   345 // CMceOneRowMessageListContainer::SelectionCount
       
   346 // ----------------------------------------------------
       
   347 TInt CMceMessageListContainer::SelectionCount() const
       
   348     {
       
   349     return iListBox->View()->SelectionIndexes()->Count();
       
   350     }
       
   351 
       
   352 // ----------------------------------------------------
       
   353 // CMceMessageListContainer::ClearSelection
       
   354 // ----------------------------------------------------
       
   355 void CMceMessageListContainer::ClearSelection()
       
   356     {
       
   357     iSelectedEntries->Reset();
       
   358     iListBox->View()->ClearSelection();
       
   359     }
       
   360 
       
   361 // ----------------------------------------------------
       
   362 // CMceMessageListContainer::ItemIndex
       
   363 // ----------------------------------------------------
       
   364 TInt CMceMessageListContainer::ItemIndex( TMsvId aId ) const
       
   365     {
       
   366     return iListItems->ItemIndex( aId );
       
   367     }
       
   368 
       
   369 
       
   370 // ----------------------------------------------------
       
   371 // CMceMessageListContainer::MarkItemSelectionL
       
   372 // ----------------------------------------------------
       
   373 void CMceMessageListContainer::MarkItemSelectionL()
       
   374     {
       
   375     const CListBoxView::CSelectionIndexArray* selection =
       
   376         iListBox->View()->SelectionIndexes();
       
   377     TInt count = selection->Count();
       
   378     iSelectedEntries->Reset();
       
   379     if ( count != 0 )
       
   380         {
       
   381         for (TInt loop=0; loop < count; loop++ )
       
   382             {
       
   383             TMsvId id = iListItems->ItemId( (*selection)[loop] );
       
   384             if ( id != KErrNotFound )
       
   385                 {
       
   386                 iSelectedEntries->AppendL( id );
       
   387                 }
       
   388             }
       
   389         }
       
   390     else
       
   391         {
       
   392         TMsvId id = CurrentItemId();
       
   393         if ( id != KErrNotFound )
       
   394             {
       
   395             // nothing in selection so add item under "cursor"
       
   396             iSelectedEntries->AppendL( id );
       
   397             }
       
   398         }
       
   399     }
       
   400 
       
   401 // ----------------------------------------------------
       
   402 // CMceMessageListContainer::AddItemToSelectionL
       
   403 // ----------------------------------------------------
       
   404 void CMceMessageListContainer::AddItemToSelectionL( TMsvId aEntryId )
       
   405     {
       
   406     if ( aEntryId > KMsvRootIndexEntryId )
       
   407         {
       
   408         iSelectedEntries->AppendL( aEntryId );
       
   409         }
       
   410     }
       
   411 // ----------------------------------------------------
       
   412 // CMceMessageListContainer::AddCurrentItemToSelectionL
       
   413 // ----------------------------------------------------
       
   414 void CMceMessageListContainer::AddCurrentItemToSelectionL()
       
   415     {
       
   416     iListBox->View()->SelectItemL( CurrentItemIndex() );
       
   417     AddItemToSelectionL( CurrentItemId() );
       
   418     }
       
   419 
       
   420 // ----------------------------------------------------
       
   421 // CMceMessageListContainer::RemoveItemFromSelection
       
   422 // ----------------------------------------------------
       
   423 void CMceMessageListContainer::RemoveItemFromSelection( TMsvId aEntryId )
       
   424     {
       
   425     TInt index = iSelectedEntries->Find( aEntryId );
       
   426     if ( index >= 0 )
       
   427         {
       
   428         iSelectedEntries->Delete( index );
       
   429         }
       
   430     }
       
   431 
       
   432 // ----------------------------------------------------
       
   433 // CMceMessageListContainer::RemoveCurrentItemFromSelection
       
   434 // ----------------------------------------------------
       
   435 void CMceMessageListContainer::RemoveCurrentItemFromSelection()
       
   436     {
       
   437     iListBox->View()->DeselectItem( CurrentItemIndex() );
       
   438     RemoveItemFromSelection( CurrentItemId() );
       
   439     }
       
   440 
       
   441 // ----------------------------------------------------
       
   442 // CMceMessageListContainer::RefreshSelectionIndexesL
       
   443 // ----------------------------------------------------
       
   444 void CMceMessageListContainer::RefreshSelectionIndexesL( TBool aForceUpdate )
       
   445     {
       
   446     const CListBoxView::CSelectionIndexArray* selection = 
       
   447         iListBox->View()->SelectionIndexes();
       
   448 
       
   449     if ( selection->Count() > 0 || aForceUpdate )
       
   450         {
       
   451         CArrayFixFlat<TInt>* newSelection = new ( ELeave )
       
   452             CArrayFixFlat<TInt>( KMceListContainerGranuality );
       
   453         CleanupStack::PushL( newSelection );
       
   454         const TInt count = iSelectedEntries->Count();
       
   455         for ( TInt loop = count; loop >0; loop--)
       
   456             {
       
   457             TInt index = iListItems->ItemIndex( (*iSelectedEntries)[loop-1] );
       
   458             if ( index > KErrNotFound )
       
   459                 {
       
   460                 newSelection->AppendL( index );
       
   461                 }
       
   462             else
       
   463                 {
       
   464                 iSelectedEntries->Delete( loop-1 );
       
   465                 }
       
   466             }
       
   467         iListBox->SetSelectionIndexesL( newSelection );
       
   468         CleanupStack::PopAndDestroy( newSelection );
       
   469         }
       
   470     
       
   471     }
       
   472 
       
   473 // ----------------------------------------------------
       
   474 // CMceMessageListContainer::AddAllToSelectionL
       
   475 // ----------------------------------------------------
       
   476 void CMceMessageListContainer::AddAllToSelectionL()
       
   477     {
       
   478     CArrayFixFlat<TInt>* indexArray = new( ELeave ) CArrayFixFlat<TInt>(
       
   479         KMceListContainerGranuality );
       
   480     CleanupStack::PushL( indexArray );
       
   481     iSelectedEntries->Reset();
       
   482     const TInt count = iListItems->MdcaCount();
       
   483     for ( TInt loop = 0; loop < count; loop++ )
       
   484         {
       
   485         TMsvId id = iListItems->ItemId( loop );
       
   486         if ( !iListItems->IsItemFolder( id ) )
       
   487             {
       
   488             indexArray->AppendL( loop );
       
   489             iSelectedEntries->AppendL( id );
       
   490             }
       
   491         }
       
   492     iListBox->SetSelectionIndexesL( indexArray );
       
   493     CleanupStack::PopAndDestroy( indexArray );
       
   494     }
       
   495     
       
   496 
       
   497 // ----------------------------------------------------
       
   498 // CMceMessageListContainer::MarkAllReadMessagesL
       
   499 // ----------------------------------------------------
       
   500 void CMceMessageListContainer::MarkAllReadMessagesL()
       
   501     {
       
   502     CArrayFixFlat<TInt>* msgIndexArray = new( ELeave ) CArrayFixFlat<TInt>( 4 );
       
   503     CleanupStack::PushL( msgIndexArray );
       
   504     iSelectedEntries->Reset();
       
   505     iListBox->View()->ClearSelection();
       
   506 
       
   507     const TInt count = iListItems->MdcaCount();
       
   508     for ( TInt loop = 0; loop < count; loop++ )
       
   509         {
       
   510         TMsvEntry entry;
       
   511         TMsvId entryId = iListItems->ItemId( loop );
       
   512         if ( iListItems->GetEntry( entryId, entry ) == KErrNone )
       
   513             {
       
   514             if ( entry.iType == KUidMsvMessageEntry &&
       
   515                  !entry.Unread() )
       
   516                 {
       
   517                 msgIndexArray->AppendL( loop );
       
   518                 }
       
   519             }
       
   520         }
       
   521       
       
   522     if ( msgIndexArray->Count() > 0 )
       
   523         {
       
   524         iListBox->SetSelectionIndexesL( msgIndexArray );        
       
   525         iListBox->DrawDeferred();
       
   526         }    
       
   527     CleanupStack::PopAndDestroy( msgIndexArray );
       
   528     }
       
   529 
       
   530 
       
   531 // ----------------------------------------------------
       
   532 // CMceMessageListContainer::IsItemSelected
       
   533 // ----------------------------------------------------
       
   534 TBool CMceMessageListContainer::IsItemSelected( TMsvId aItemId )
       
   535     {
       
   536     // Find selected items
       
   537     const CListBoxView::CSelectionIndexArray* items =
       
   538          iListBox->SelectionIndexes();
       
   539     TInt itemIndex = iListItems->ItemIndex( aItemId );
       
   540     TKeyArrayFix key(0, ECmpTInt);
       
   541     TInt pos;
       
   542 
       
   543     // Is item in selection array
       
   544     if ( items->Find(itemIndex, key, pos) != KErrNone )
       
   545         {
       
   546         return EFalse;
       
   547         }
       
   548     else
       
   549         {
       
   550         return ETrue;        
       
   551         }
       
   552     }
       
   553 
       
   554 
       
   555 // ----------------------------------------------------
       
   556 // CMceMessageListContainer::SetMskL
       
   557 // ----------------------------------------------------
       
   558 void CMceMessageListContainer::SetMskL()
       
   559     {
       
   560     TInt currentItem = CurrentItemIndex();
       
   561     TInt resourceId = currentItem == 0 ?
       
   562         R_MCE_MSK_BUTTON_SELECT:R_MCE_MSK_BUTTON_OPEN;
       
   563 
       
   564     if ( resourceId != iCurrMskResource )
       
   565         {
       
   566         iCurrMskResource = resourceId;
       
   567         CEikButtonGroupContainer* cba;
       
   568         cba = CEikButtonGroupContainer::Current();
       
   569         const TInt KMSKPosition = 3;
       
   570         cba->SetCommandL( KMSKPosition, iCurrMskResource );
       
   571         cba->DrawDeferred();
       
   572         }
       
   573     }
       
   574 
       
   575 
       
   576 // ----------------------------------------------------
       
   577 // CMceMessageListContainer::FocusChanged
       
   578 // ----------------------------------------------------
       
   579 void CMceMessageListContainer::FocusChanged(TDrawNow /*aDrawNow*/)
       
   580     {
       
   581     if (iListBox)
       
   582         {
       
   583         iListBox->SetFocus(IsFocused());
       
   584         }
       
   585     }
       
   586 
       
   587 
       
   588 // ----------------------------------------------------
       
   589 //  CMceMessageListContainer::MarkedItemsCount()
       
   590 // ----------------------------------------------------
       
   591 TInt CMceMessageListContainer::MarkedItemsCount()
       
   592     {
       
   593     return iListBox->View()->SelectionIndexes()->Count();
       
   594     }
       
   595 
       
   596 
       
   597 // ----------------------------------------------------
       
   598 // CMceMessageListContainer::OfferKeyEventL
       
   599 // ----------------------------------------------------
       
   600 TKeyResponse CMceMessageListContainer::OfferKeyEventL(
       
   601     const TKeyEvent& aKeyEvent,
       
   602     TEventCode aType )
       
   603     {
       
   604 
       
   605     if ( !iT9Interface )
       
   606         {        
       
   607         iT9Interface = CPtiEngine::NewL();
       
   608         if ( iInputMethodQwerty )
       
   609             {
       
   610             iT9Interface->SetInputMode( EPtiEngineQwerty );
       
   611             iT9Interface->ActivateLanguageL( User::Language(), EPtiEngineQwerty );        
       
   612             }
       
   613         else
       
   614             {
       
   615             iT9Interface->SetInputMode( EPtiEngineMultitapping );
       
   616         iT9Interface->ActivateLanguageL( User::Language(), EPtiEngineMultitapping );        
       
   617             }
       
   618         iPreviousInputMethod = iInputMethodQwerty;
       
   619         }
       
   620     else
       
   621         {
       
   622         if ( iInputMethodQwerty != iPreviousInputMethod )
       
   623             {
       
   624             if ( iInputMethodQwerty )
       
   625                 {
       
   626                 iT9Interface->SetInputMode( EPtiEngineQwerty );
       
   627                 iT9Interface->ActivateLanguageL( User::Language(), EPtiEngineQwerty );        
       
   628                 }
       
   629             else
       
   630                 {
       
   631                 iT9Interface->SetInputMode( EPtiEngineMultitapping );
       
   632                 iT9Interface->ActivateLanguageL( User::Language(), EPtiEngineMultitapping );        
       
   633                 }
       
   634             iPreviousInputMethod = iInputMethodQwerty;
       
   635             }
       
   636         }
       
   637     
       
   638     if ( !iT9Timer )
       
   639         {
       
   640         iT9Timer = CMceMessageListContainerKeyTimer::NewL( *iT9Interface );
       
   641         }
       
   642 
       
   643     if ( iListBox )
       
   644         {
       
   645   
       
   646         if ( aType == EEventKeyUp )
       
   647             {
       
   648             iOwningView.SetMSKButtonL();
       
   649             iDialerEvent = EFalse ; 
       
   650             }
       
   651 
       
   652         if ( aType == EEventKeyDown && iDialerEvent )
       
   653             {
       
   654             iDialerEvent = EFalse ;
       
   655             }
       
   656         if ( aType == EEventKey )
       
   657             {
       
   658             
       
   659             iOwningView.CancelMailboxTimer();
       
   660 
       
   661             if ( aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow )
       
   662                 {
       
   663                 return EKeyWasNotConsumed;
       
   664                 }
       
   665 
       
   666             if ( aKeyEvent.iCode == EKeyBackspace )
       
   667                 {
       
   668                 MarkItemSelectionL();
       
   669                 SetAnchorItemIdL( 
       
   670                     CMceMessageListContainerBase::EMessageListOperationGeneral );
       
   671                 const TInt itemCount = CurrentItemSelectionCount();
       
   672                 if ( itemCount != 0 &&
       
   673                      ( itemCount != 1 ||
       
   674                        CurrentItemId() != KMceTemplatesEntryIdValue )
       
   675                    )
       
   676                     {
       
   677                     if ( !iListItems->DeleteDiscard( CurrentItemId() ) )
       
   678                         {
       
   679                         //if outbox and mms/sms connected, not delete
       
   680                         iOwningView.HandleCommandL( EMceCmdDelete );
       
   681                         }
       
   682                     }
       
   683                 return EKeyWasConsumed;
       
   684                 }
       
   685             else if ( aKeyEvent.iCode == EKeyOK ||  aKeyEvent.iCode == EKeyEnter )
       
   686                 {
       
   687                 if ( aKeyEvent.iModifiers & EModifierShift ||
       
   688                        aKeyEvent.iModifiers & EModifierCtrl )
       
   689                     {
       
   690                     if ( iListItems->FolderId() != KMsvGlobalOutBoxIndexEntryIdValue &&
       
   691                          IsCurrentItemFolder() )
       
   692                         {
       
   693                         return EKeyWasNotConsumed;
       
   694                         }
       
   695                     }
       
   696                 else
       
   697                     {
       
   698                     iOwningView.SetHideExitCommand( ETrue );
       
   699                     if ( iListItems->FolderId() == KMsvGlobalOutBoxIndexEntryIdValue ||
       
   700                         iOwningView.SyncMlOutboxInbox( KMsvGlobalOutBoxIndexEntryId ) ||
       
   701                         CurrentItemSelectionCount() == 0 ||
       
   702                         iOwningView.CheckMMSNotificationOpenL() )
       
   703                         {
       
   704                         if(iListItems->FolderId() == KMsvGlobalOutBoxIndexEntryIdValue)
       
   705                             {
       
   706                             iOwningView.SetContextCommandFlag(ETrue);
       
   707                             }
       
   708                         // list is empty, open options menu
       
   709                         iOwningView.ProcessCommandL( EAknSoftkeyOptions );
       
   710                         return EKeyWasConsumed;
       
   711                         }
       
   712                     }
       
   713                 }
       
   714 
       
   715             else if ( aKeyEvent.iCode == EKeyYes )
       
   716                 {
       
   717                 if (!iDialerEvent && aKeyEvent.iRepeats == 0) 
       
   718 	                {
       
   719                 // send key has been pressed in Inbox or in Documents folder
       
   720                 TMsvId folderId = iListItems->FolderId();
       
   721                 if ( folderId != KMsvDraftEntryId &&
       
   722                     folderId != KMsvGlobalOutBoxIndexEntryId &&
       
   723                     folderId != KMsvSentEntryId &&       
       
   724                     folderId != KMceTemplatesEntryId                   
       
   725                     && ( CurrentItemSelectionCount() == 1 )  )
       
   726                     {       
       
   727                     if ( !( iListItems->IsFolderRemote() ) )
       
   728                         {
       
   729                         TMsvId id = CurrentItemId();
       
   730                         TBool validNumber = EFalse;
       
   731                         TBuf<KMceVisibleTextLength> recipientstring;
       
   732                         TPhCltTelephoneNumber number;
       
   733                         CMceUi* mceUi = static_cast<CMceUi*>( iEikonEnv->AppUi() );
       
   734                         validNumber = MceUtils::ValidPhoneNumberL( id, mceUi->Session(), number, &recipientstring );
       
   735                         if (KErrNotFound != number.Match( recipientstring ))
       
   736                             {
       
   737                             recipientstring = KNullDesC;
       
   738                             }
       
   739 
       
   740                         //
       
   741                         // Callback number is supported in CDMA mode. If there isn't a phone
       
   742                         // book match for the sender, it gets confusing to display the sender's
       
   743                         // number (contained in recipientstring) and the callback number
       
   744                         // (contained in the number field) via CallToSenderQueryL.
       
   745                         // Therefore, if the recipientstring differs from the phone number
       
   746                         // to be used to call the sender and recipientstring is also a phone
       
   747                         // number, we won't display recipientstring when running in CDMA mode.
       
   748                         //
       
   749                         if ( FeatureManager::FeatureSupported( KFeatureIdProtocolCdma ) )
       
   750                             {
       
   751                             if ( CommonPhoneParser::IsValidPhoneNumber( recipientstring, CommonPhoneParser::ESMSNumber ) )
       
   752                                 {
       
   753                                 recipientstring = KNullDesC;
       
   754                                 }
       
   755                             }
       
   756 
       
   757                         if ( validNumber )
       
   758                             {                        
       
   759 	                            iAvkonAppUi->SetKeyEventFlags( CAknAppUiBase::EDisableSendKeyShort | CAknAppUiBase::EDisableSendKeyLong ); 
       
   760                             MsvUiServiceUtilitiesInternal::CallToSenderQueryL( number, recipientstring, EFalse );
       
   761 	                            iAvkonAppUi->SetKeyEventFlags( 0x00 ); 
       
   762                             }
       
   763                         }
       
   764                     else   //(iiListItems->IsFolderRemote()) Enable Sendkey in Mail List
       
   765                         {
       
   766                         iAvkonAppUi->SetKeyEventFlags( CAknAppUiBase::EDisableSendKeyShort | CAknAppUiBase::EDisableSendKeyLong );
       
   767                         iOwningView.HandleSendkeyInMailboxL( CurrentItemId() );  
       
   768                         iAvkonAppUi->SetKeyEventFlags( 0x00 );
       
   769                         }
       
   770                     }           
       
   771                 SetAnchorItemIdL( 
       
   772                     CMceMessageListContainerBase::EMessageListOperationGeneral );
       
   773 	                }
       
   774                 return EKeyWasConsumed;
       
   775                 }           
       
   776 
       
   777             else if ( IsValidSearchKey( aKeyEvent ) )
       
   778                 {
       
   779                 if ( !( FeatureManager::FeatureSupported(KFeatureIdJapanese) ||
       
   780 		    FeatureManager::FeatureSupported(KFeatureIdChinese) )  )
       
   781                     {                
       
   782                     HandleShortcutForSearchL( aKeyEvent );
       
   783                     }   
       
   784                 }
       
   785             else if (  aKeyEvent.iCode == (TUint)EPtiKeyStar )
       
   786                 {              
       
   787                 if ( HasHandleStarKeyDoneL() ) // * key
       
   788                     {
       
   789                     return EKeyWasConsumed;
       
   790                     }
       
   791                 }  
       
   792             }
       
   793 
       
   794         if ( iListItems->MdcaCount() > 0 && iListBox->View()->SelectionIndexes()->Count() == 0 )
       
   795         	{
       
   796         	iOwningView.SetHideExitCommand( EFalse );
       
   797         	}
       
   798         TKeyResponse ret = iListBox->OfferKeyEventL(aKeyEvent, aType);
       
   799         iOwningView.SetCurrentItemId();
       
   800         SetAnchorItemIdL( 
       
   801             CMceMessageListContainerBase::EMessageListOperationGeneral );
       
   802         if ( ( aKeyEvent.iModifiers & EModifierShift ||
       
   803               aKeyEvent.iModifiers & EModifierCtrl ) &&
       
   804              ( aKeyEvent.iCode == EKeyOK || 
       
   805                aKeyEvent.iCode == EKeyEnter ||
       
   806                aKeyEvent.iCode == EKeyUpArrow ||
       
   807                aKeyEvent.iCode == EKeyDownArrow ) )
       
   808             {
       
   809             MarkItemSelectionL();
       
   810             iOwningView.SetMSKButtonL();
       
   811             }
       
   812         else if ( iOwningView.IsMSKMailBox() &&
       
   813              ( aKeyEvent.iCode == EKeyUpArrow || aKeyEvent.iCode == EKeyDownArrow ) )
       
   814             {
       
   815             iOwningView.SetMSKButtonL();                    
       
   816             }
       
   817         return ret;
       
   818         }
       
   819     else
       
   820         {
       
   821         return EKeyWasNotConsumed;
       
   822         }
       
   823 
       
   824     }
       
   825 
       
   826 // ----------------------------------------------------
       
   827 // CMceMessageListContainer::IsCurrentItemFolder
       
   828 // ----------------------------------------------------
       
   829 TBool CMceMessageListContainer::IsCurrentItemFolder() const
       
   830     {
       
   831     TBool isCurrentFolder = EFalse;
       
   832     const TMsvId id = CurrentItemId();
       
   833     if ( id != KErrNotFound )
       
   834         {
       
   835         isCurrentFolder = iListItems->IsItemFolder( id );
       
   836         }
       
   837     return isCurrentFolder;
       
   838     }
       
   839     
       
   840     
       
   841 // ----------------------------------------------------
       
   842 // CMceMessageListContainer::IsCurrentItemFolder
       
   843 // ----------------------------------------------------
       
   844 TBool CMceMessageListContainer::IsItemFolder( TMsvId aItemId ) const
       
   845     {
       
   846     return iListItems->IsItemFolder( aItemId );
       
   847     }
       
   848 
       
   849 
       
   850 // ----------------------------------------------------
       
   851 // CMceMessageListContainer::IsItemFolder
       
   852 // ----------------------------------------------------
       
   853 TBool CMceMessageListContainer::IsItemFolder(TInt aIndex) const
       
   854     {
       
   855     TBool isCurrentFolder = EFalse;
       
   856     const TMsvId id = iListItems->ItemId( aIndex );
       
   857     if ( id != KErrNotFound )
       
   858         {
       
   859         isCurrentFolder = iListItems->IsItemFolder( id );
       
   860         }
       
   861     return isCurrentFolder;
       
   862     }
       
   863 
       
   864 
       
   865 // ----------------------------------------------------
       
   866 // CMceOneRowMessageListContainer::IsItemRemote
       
   867 // ----------------------------------------------------
       
   868 TBool CMceMessageListContainer::IsItemRemote( TMsvId aItemId ) const
       
   869     {
       
   870     return iListItems->IsItemRemote( aItemId );
       
   871     }
       
   872 
       
   873 
       
   874 // ----------------------------------------------------
       
   875 // CMceMessageListContainer::IsOutboxOpened
       
   876 // ----------------------------------------------------
       
   877 TBool CMceMessageListContainer::IsOutboxOpened() const
       
   878     {
       
   879     return IsOpenedFolder( KMsvGlobalOutBoxIndexEntryIdValue );
       
   880     }
       
   881 
       
   882 
       
   883 // ----------------------------------------------------
       
   884 // CMceMessageListContainer::
       
   885 // ----------------------------------------------------
       
   886 TBool CMceMessageListContainer::IsOpenedFolder( TMsvId aFolderId ) const
       
   887     {
       
   888     return ( iListItems->FolderId() == aFolderId );
       
   889     }
       
   890     
       
   891     
       
   892 // ----------------------------------------------------
       
   893 // CMceMessageListContainer::DisplayOptionsMenuFromSelectionKey
       
   894 // ----------------------------------------------------
       
   895 TBool CMceMessageListContainer::DisplayOptionsMenuFromSelectionKey() const
       
   896     {
       
   897     return ( iListItems->MdcaCount() == 0 || iListBox->View()->SelectionIndexes()->Count() );
       
   898     }
       
   899 
       
   900 
       
   901 // ----------------------------------------------------
       
   902 // CMceMessageListContainer::GetHelpContext
       
   903 // returns helpcontext as aContext
       
   904 // ----------------------------------------------------
       
   905 void CMceMessageListContainer::GetHelpContext
       
   906         (TCoeHelpContext& aContext) const
       
   907     {
       
   908     TMsvId folderId = iListItems->FolderId();
       
   909     aContext.iMajor = KMceApplicationUid;
       
   910 
       
   911     TBool isRemoteFolder = iListItems->IsFolderRemote();
       
   912 
       
   913     /*if ( iOwningView.SyncMlOutboxInbox( KMsvGlobalInBoxIndexEntryId ) )
       
   914         {
       
   915         aContext.iContext = KMCE_HLP_MESS_SYNCI;
       
   916         }
       
   917     else if ( iOwningView.SyncMlOutboxInbox( KMsvGlobalOutBoxIndexEntryId ) )
       
   918         {
       
   919         aContext.iContext = KMCE_HLP_MESS_SYNCO;
       
   920         }
       
   921 
       
   922     else if ( iOwningView.IsSyncMl() )
       
   923         {
       
   924         aContext.iContext = KMCE_HLP_MESS_SYNC;
       
   925         }
       
   926 
       
   927     else*/
       
   928     if ( folderId == KMsvDraftEntryId )
       
   929         {
       
   930         aContext.iContext = KMCE_HLP_DRAFTS;
       
   931         }
       
   932     else if ( folderId == KMsvGlobalOutBoxIndexEntryId )
       
   933         {
       
   934         aContext.iContext = KMCE_HLP_OUTBOX;
       
   935         }
       
   936     else if ( folderId == KMsvGlobalInBoxIndexEntryId )
       
   937         {
       
   938         aContext.iContext = KMCE_HLP_INBOX;
       
   939         }
       
   940     else if ( folderId == KMsvSentEntryId )
       
   941         {
       
   942         aContext.iContext = KMCE_HLP_SENT_ITEMS;
       
   943         }
       
   944     else if ( folderId == KMceDocumentsEntryId )
       
   945         {
       
   946         aContext.iContext = KMCE_HLP_DOCUMENTS;
       
   947         }
       
   948     else if ( folderId == KMceTemplatesEntryId )
       
   949         {
       
   950         aContext.iContext = KMCE_HLP_TEMPLATES;
       
   951         }
       
   952     else if ( !isRemoteFolder )
       
   953         {
       
   954         // own folder
       
   955         aContext.iContext = KMCE_HLP_FOLDER;
       
   956         }
       
   957     else
       
   958         {
       
   959         // remote account
       
   960         TBool isConnected = iListItems->IsConnected();
       
   961         if ( isConnected )
       
   962             {
       
   963             aContext.iContext = KMCE_HLP_MAILBOX_ONLINE;
       
   964             }
       
   965         else
       
   966             {
       
   967             aContext.iContext = KMCE_HLP_MAILBOX_OFFLINE;
       
   968             }
       
   969         }
       
   970 
       
   971     }
       
   972 
       
   973 // ----------------------------------------------------
       
   974 // CMceMessageListContainer::SyncMlOutboxOpened
       
   975 // ----------------------------------------------------
       
   976 TBool CMceMessageListContainer::SyncMlOutboxOpened() const
       
   977     {
       
   978     return ( iOwningView.SyncMlOutboxInbox( KMsvGlobalOutBoxIndexEntryId ) );
       
   979     }
       
   980 
       
   981 
       
   982 
       
   983 // ----------------------------------------------------
       
   984 // CMceMessageListContainer::HandleResourceChange
       
   985 // ----------------------------------------------------
       
   986 void CMceMessageListContainer::HandleResourceChange( TInt aType )
       
   987     {    
       
   988     CCoeControl::HandleResourceChange( aType );
       
   989     if ( iListBox && aType == KEikDynamicLayoutVariantSwitch )        
       
   990         {
       
   991         
       
   992 	    iListBox->ItemDrawer()->SetItemMarkReverse( ETrue );
       
   993         SetRect( iOwningView.ClientRect() );
       
   994         }        
       
   995     }
       
   996 
       
   997 
       
   998 // ----------------------------------------------------
       
   999 // CMceMessageListContainer::SizeChanged
       
  1000 // ----------------------------------------------------
       
  1001 void CMceMessageListContainer::SizeChanged()
       
  1002     {
       
  1003     if (iListBox)
       
  1004         {
       
  1005         iListBox->SetRect( Rect() );
       
  1006 	    iListBox->ItemDrawer()->SetItemMarkReverse( ETrue );
       
  1007         }
       
  1008     }
       
  1009 
       
  1010 // ----------------------------------------------------
       
  1011 // CMceMessageListContainer::ProcessCommandL
       
  1012 // ----------------------------------------------------
       
  1013 void CMceMessageListContainer::ProcessCommandL(TInt aCommand)
       
  1014     {
       
  1015     if ( aCommand == EAknSoftkeyShiftMSK )
       
  1016         {
       
  1017         // Pass the MSK marking command as a key event to controls
       
  1018         const CListBoxView::CSelectionIndexArray* items =
       
  1019             iListBox->SelectionIndexes();
       
  1020         
       
  1021         // check what state item under "cursor" is        
       
  1022         TKeyArrayFix key(0, ECmpTInt);
       
  1023         TInt pos;
       
  1024         if ( !items->Find(CurrentItemIndex(), key, pos))
       
  1025             {
       
  1026             RemoveCurrentItemFromSelection();
       
  1027             }
       
  1028         else
       
  1029             {
       
  1030             AddCurrentItemToSelectionL();
       
  1031             }
       
  1032         iOwningView.SetMSKButtonL();            
       
  1033         }
       
  1034     }
       
  1035     
       
  1036  
       
  1037 // ----------------------------------------------------
       
  1038 // CMceMessageListContainer::StateCanBeChangedByStarKeyL() const
       
  1039 // Exam if it is the situation that * key can change message state
       
  1040 // Returns ETrue if it can
       
  1041 // Public
       
  1042 // ----------------------------------------------------  
       
  1043 TBool CMceMessageListContainer::StateCanBeChangedByStarKeyL() const
       
  1044     {
       
  1045     TMsvId folderId = iListItems->FolderId();
       
  1046     TBool isRemoteFolder = iListItems->IsFolderRemote();
       
  1047     
       
  1048     if ( ( iListItems->MdcaCount() > 0 && 
       
  1049         iListBox->View()->SelectionIndexes()->Count() == 0 && 
       
  1050         !IsCurrentItemFolder() ) && 
       
  1051         ( folderId == KMsvGlobalInBoxIndexEntryId ||  //Inbox
       
  1052         folderId == KMceDocumentsEntryId ||     //Documents
       
  1053         iListItems->GetParentFolderId() == KMceDocumentsEntryId || //Subfolder of Documents
       
  1054         isRemoteFolder ) )  // Mailbox & SyncMl
       
  1055         {
       
  1056         if ( iOwningView.IsSyncMl() )
       
  1057             {            
       
  1058             return( iOwningView.ListContainer()->FolderEntry().iRelatedId  == KMsvGlobalInBoxIndexEntryId );//Inbox of SyncMail     
       
  1059             }            
       
  1060         return ETrue;
       
  1061         }
       
  1062      else 
       
  1063         {                   
       
  1064         return EFalse;           
       
  1065         }                
       
  1066     }
       
  1067  
       
  1068 // TODO: maybe worth of adding new function for these listbox->ItemDrawer()->SetItemMarkXXX function?
       
  1069 //      MarkItemSelectionL(); does selection but not mark
       
  1070 //      AddCurrentItemToSelectionL(); selects and marks
       
  1071 
       
  1072 
       
  1073 //-------------------------------------------------------------------------------
       
  1074 // CMceMessageListContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
  1075 //-------------------------------------------------------------------------------
       
  1076 void CMceMessageListContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
  1077     {
       
  1078     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
  1079         {
       
  1080         iOwningView.SetMSKButtonL();
       
  1081         iOwningView.SetCurrentItemId();
       
  1082         if ( ( iOwningView.IsMSKMailBox() || 
       
  1083         		iListItems->FolderId() == KMsvDraftEntryId ) && 
       
  1084         		iListBox->CurrentItemIndex() < 0 ) 
       
  1085             {
       
  1086             iOwningView.ProcessCommandL( EAknSoftkeyContextOptions );
       
  1087             }
       
  1088         }
       
  1089     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
  1090         {
       
  1091         if ( iOwningView.IsMSKMailBox() )
       
  1092             {
       
  1093             iOwningView.CancelMailboxTimer();
       
  1094             }
       
  1095         }
       
  1096     iListBox->HandlePointerEventL( aPointerEvent );
       
  1097     }
       
  1098 
       
  1099 
       
  1100 //-------------------------------------------------------------------------------
       
  1101 //CMceMessageListContainer::IsValidSearchKey(const TKeyEvent& aKeyEvent)
       
  1102 //-------------------------------------------------------------------------------
       
  1103 TBool CMceMessageListContainer::IsValidSearchKey( const TKeyEvent& aKeyEvent )
       
  1104     {
       
  1105     TBool response = EFalse;
       
  1106     if ( iInputMethodQwerty )
       
  1107         {
       
  1108         response = ETrue;
       
  1109         }
       
  1110     if ((( aKeyEvent.iCode >= (TUint)EPtiKey0 && 
       
  1111            aKeyEvent.iCode <= (TUint)EPtiKey9 ) ) 
       
  1112            && !aKeyEvent.iRepeats )
       
  1113         {
       
  1114         response = ETrue;
       
  1115         }
       
  1116     if ( aKeyEvent.iCode == EKeyUpArrow || 
       
  1117     	 aKeyEvent.iCode == EKeyDownArrow )
       
  1118     	{
       
  1119     	response = EFalse;
       
  1120     	}
       
  1121     return response;
       
  1122     }
       
  1123 
       
  1124 
       
  1125 //-------------------------------------------------------------------------------
       
  1126 //CMceMessageListContainer::HandleQwertyModeChangeNotification()
       
  1127 //-------------------------------------------------------------------------------
       
  1128 TInt CMceMessageListContainer::HandleQwertyModeChangeNotification()
       
  1129     {
       
  1130     TInt err = iQwertyModeStatusProperty.Get( iInputMethodQwerty );
       
  1131     if ( err )
       
  1132         {
       
  1133         // Set defaut inputmethod. 0 = No Qwerty -> EPtiEngineMultitapping
       
  1134         iInputMethodQwerty = 0; 
       
  1135         }
       
  1136     return err;        
       
  1137     }
       
  1138 
       
  1139 
       
  1140 //-------------------------------------------------------------------------------
       
  1141 //CMceMessageListContainer::QwertyModeChangeNotification(TAny* aObj)
       
  1142 //-------------------------------------------------------------------------------
       
  1143 TInt CMceMessageListContainer::QwertyModeChangeNotification( TAny* aObj )
       
  1144     {
       
  1145     TInt err = KErrArgument;
       
  1146     if ( aObj != NULL )
       
  1147         {
       
  1148         err = static_cast<CMceMessageListContainer*>(aObj)->HandleQwertyModeChangeNotification();
       
  1149         }
       
  1150     return err;        
       
  1151     }
       
  1152 
       
  1153 // ----------------------------------------------------
       
  1154 // CMceMessageListContainer::
       
  1155 // ----------------------------------------------------
       
  1156 void CMceMessageListContainer::SetSortTypeL( TInt aSortType, TBool aOrdering )
       
  1157     {
       
  1158     iListItems->SetOrderingL( aSortType, aOrdering );
       
  1159     }
       
  1160 
       
  1161 // ----------------------------------------------------
       
  1162 // CMceMessageListContainer::
       
  1163 // ----------------------------------------------------
       
  1164 void CMceMessageListContainer::SetMtmUiDataRegistry( MMtmUiDataRegistryObserver* aRegistryObserver )
       
  1165     {
       
  1166     iListItems->SetRegistryObserver( aRegistryObserver );
       
  1167     }
       
  1168     
       
  1169 // ----------------------------------------------------
       
  1170 // CMceMessageListContainer::
       
  1171 // ----------------------------------------------------
       
  1172 TMsvId CMceMessageListContainer::FindEntry( const TDesC& aMatchString ) const
       
  1173     {
       
  1174     TMsvId foundEntry = KErrNotFound;
       
  1175     TInt index = iListItems->FindEntryIndex( aMatchString );
       
  1176     if ( index >= 0 )
       
  1177         {
       
  1178         foundEntry = iListItems->ItemId( index );
       
  1179         }
       
  1180     return foundEntry;
       
  1181     
       
  1182     }
       
  1183     
       
  1184 // ----------------------------------------------------
       
  1185 // CMceMessageListContainer::
       
  1186 // ----------------------------------------------------
       
  1187 TBool CMceMessageListContainer::FindFirstUnreadMessageL( TMsvId& aEntryId ) const
       
  1188     {
       
  1189     return iListItems->FindFirstUnreadMessageL( aEntryId );
       
  1190     }
       
  1191     
       
  1192 // ----------------------------------------------------
       
  1193 // CMceMessageListContainer::
       
  1194 // ----------------------------------------------------
       
  1195 void CMceMessageListContainer::ResetCurrentItemL()
       
  1196     {
       
  1197     if ( iListItems->MdcaCount() )
       
  1198         {
       
  1199 		//calulate the top item index
       
  1200 		TInt topIndex = iListBox->View()->CalcNewTopItemIndexSoItemIsVisible( 0 );
       
  1201 		iListBox->SetTopItemIndex( topIndex );
       
  1202 		iListBox->SetCurrentItemIndex( 0 );
       
  1203         }
       
  1204     iListBox->UpdateScrollBarsL();
       
  1205     }
       
  1206     
       
  1207 // ----------------------------------------------------
       
  1208 // CMceMessageListContainer::
       
  1209 // ----------------------------------------------------
       
  1210 CMceMessageListContainerBase::TMessageListItemType CMceMessageListContainer::CurrentItemType() const
       
  1211     {
       
  1212     if ( iListItems->MdcaCount() )
       
  1213         {
       
  1214         return CMceMessageListContainerBase::EMessageListItemMsvItem;
       
  1215         }
       
  1216     return CMceMessageListContainerBase::EMessageListItemUnknown;
       
  1217     }
       
  1218     
       
  1219 // ----------------------------------------------------
       
  1220 // CMceMessageListContainer::
       
  1221 // ----------------------------------------------------
       
  1222 void CMceMessageListContainer::SetListEmptyTextL(const TDesC& aText)
       
  1223     {
       
  1224     iListBox->View()->SetListEmptyTextL( aText );
       
  1225     }
       
  1226     
       
  1227 // ----------------------------------------------------
       
  1228 // CMceMessageListContainer::
       
  1229 // ----------------------------------------------------
       
  1230 void CMceMessageListContainer::SetAnchorItemIdL( 
       
  1231     TMessageListOperationType aOperationType )  
       
  1232     {
       
  1233     if ( iListItems->MdcaCount() == 0 )
       
  1234         {
       
  1235         iAnchorItemId = KErrNotFound;
       
  1236         iAnchorItemIndex = KErrNotFound;
       
  1237         iLastOperationType = aOperationType;
       
  1238         return;
       
  1239         }
       
  1240         
       
  1241     switch ( aOperationType )
       
  1242         {
       
  1243         case EMessageListOperationGeneral:
       
  1244             iAnchorItemIndex = iListBox->CurrentItemIndex(); 
       
  1245             iAnchorItemId = iListItems->ItemId( iAnchorItemIndex );
       
  1246         break;
       
  1247         case EMessageListOperationConnect:
       
  1248             iAnchorItemIndex = iListBox->CurrentItemIndex(); 
       
  1249             iAnchorItemId = iListItems->ItemId( iAnchorItemIndex );
       
  1250         break;
       
  1251         case EMessageListOperationFetchSelected:
       
  1252             // find first from the marked messages list...? What if that is deleted when connected???
       
  1253             if ( iSelectedEntries->Count() )
       
  1254                 {
       
  1255                 // pick first one
       
  1256                 iAnchorItemId = (*iSelectedEntries)[0];
       
  1257                 iAnchorItemIndex = iListItems->ItemIndex( iAnchorItemId );
       
  1258                 }
       
  1259             else
       
  1260                 {
       
  1261                 iAnchorItemIndex = iListBox->CurrentItemIndex(); 
       
  1262                 iAnchorItemId = iListItems->ItemId( iAnchorItemIndex );
       
  1263                 }
       
  1264         break;
       
  1265         case EMessageListOperationFetchNew:
       
  1266             iAnchorItemIndex = iListBox->CurrentItemIndex(); 
       
  1267             iAnchorItemId = iListItems->ItemId( iAnchorItemIndex );
       
  1268         break;
       
  1269         case EMessageListOperationDelete:
       
  1270             iAnchorItemIndex = iListBox->CurrentItemIndex(); 
       
  1271             iAnchorItemId = iListItems->ItemId( iAnchorItemIndex );
       
  1272         break;
       
  1273         case EMessageListOperationCompleted:
       
  1274             HandleOperationCompletedL();
       
  1275         break;
       
  1276         default:
       
  1277         // assert debug ?
       
  1278         break;
       
  1279         }
       
  1280         
       
  1281 #ifdef _DEBUG
       
  1282     RDebug::Print(_L("CMceMessageListContainer1: iAnchorItemId 0x%x, iAnchorItemIndex %d"), iAnchorItemId, iAnchorItemIndex);
       
  1283 #endif    
       
  1284     if ( aOperationType != EMessageListOperationCompleted )        
       
  1285         {
       
  1286         iLastOperationType = aOperationType;
       
  1287         }
       
  1288     }
       
  1289     
       
  1290 // ----------------------------------------------------
       
  1291 // CMceMessageListContainer::
       
  1292 // ----------------------------------------------------
       
  1293 void CMceMessageListContainer::HandleOperationCompletedL()
       
  1294     {
       
  1295     if ( /*iLastOperationType == EMessageListOperationConnect &&*/
       
  1296          iAnchorItemIndex == KErrNotFound )
       
  1297         {
       
  1298         // set focus to first one...
       
  1299         if ( iListItems->MdcaCount() )
       
  1300             {
       
  1301             iListBox->SetCurrentItemIndex( 0 );
       
  1302             iAnchorItemIndex = 0;
       
  1303             iAnchorItemId = iListItems->ItemId( iAnchorItemIndex );
       
  1304             }
       
  1305         RefreshListbox();
       
  1306         }
       
  1307     SetAnchorItemIdL( EMessageListOperationGeneral );
       
  1308     }
       
  1309     
       
  1310 // ----------------------------------------------------
       
  1311 // CMceMessageListContainer::
       
  1312 // ----------------------------------------------------
       
  1313 void CMceMessageListContainer::HandleMsvSessionEventL( 
       
  1314     MMsvSessionObserver::TMsvSessionEvent aEvent,
       
  1315     CMsvEntrySelection& aSelection,
       
  1316     TBool aDraw )
       
  1317     {
       
  1318 #ifdef _DEBUG
       
  1319     RDebug::Print(_L("CMceMessageListContainer2: iAnchorItemId 0x%x, iAnchorItemIndex %d"), iAnchorItemId, iAnchorItemIndex);
       
  1320 #endif
       
  1321     switch ( aEvent )
       
  1322         {
       
  1323         case MMsvSessionObserver::EMsvEntriesDeleted:
       
  1324             {
       
  1325 /*            if ( iOwningView.IsMSKMailBox() ) // focus setting only for email
       
  1326                 {
       
  1327                 }
       
  1328             else*/
       
  1329                 {
       
  1330                 ItemCountChangedL( EFalse ); 
       
  1331                 TInt selectedIndex = ItemIndex( iAnchorItemId );
       
  1332                 if ( selectedIndex == KErrNotFound )
       
  1333                     {
       
  1334                     // we could not find anchor item, lets try to set new focus using index
       
  1335                     
       
  1336                     if ( iAnchorItemIndex > iListItems->MdcaCount() - 1 )
       
  1337                         {
       
  1338                         iAnchorItemIndex = iListItems->MdcaCount() - 1;
       
  1339                         }
       
  1340                     iAnchorItemId = iListItems->ItemId( iAnchorItemIndex );
       
  1341                     }
       
  1342                 if ( aDraw )
       
  1343                     {
       
  1344                     SetCurrentItemIdL( iAnchorItemId );
       
  1345                     }
       
  1346                 iAnchorItemIndex = iListBox->CurrentItemIndex();
       
  1347                 }
       
  1348             if ( aDraw )
       
  1349                 {
       
  1350                 RefreshListbox();
       
  1351                 }
       
  1352             }
       
  1353         break;
       
  1354         case MMsvSessionObserver::EMsvEntriesCreated:    
       
  1355         case MMsvSessionObserver::EMsvEntriesChanged:
       
  1356             {
       
  1357             
       
  1358             ItemCountChangedL( ETrue );
       
  1359             
       
  1360             if ( iLastOperationType != EMessageListOperationConnect &&
       
  1361                  iAnchorItemId != KErrNotFound )
       
  1362                 {
       
  1363                 if ( iOwningView.IsMSKMailBox() ) // focus setting only for email
       
  1364                     {
       
  1365                     TInt selectedIndex = ItemIndex( iAnchorItemId );
       
  1366                     if ( selectedIndex == KErrNotFound )
       
  1367                         {
       
  1368                         // we could not find anchor item, lets try to set new focus using index
       
  1369                         if ( iAnchorItemIndex > iListItems->MdcaCount() - 1 )
       
  1370                             {
       
  1371                             iAnchorItemIndex = iListItems->MdcaCount() - 1;
       
  1372                             }
       
  1373                         iAnchorItemId = iListItems->ItemId( iAnchorItemIndex );
       
  1374                         }
       
  1375                     if (selectedIndex != iListBox->CurrentItemIndex() && 
       
  1376                   		aEvent == MMsvSessionObserver::EMsvEntriesChanged )
       
  1377 	                    {
       
  1378 	                    iAnchorItemIndex = iListBox->CurrentItemIndex();
       
  1379 	                    iAnchorItemId = iListItems->ItemId( iAnchorItemIndex );
       
  1380 	                    }
       
  1381                     if(aEvent==MMsvSessionObserver::EMsvEntriesCreated)
       
  1382                         {
       
  1383                                TInt selectedIndex =0;
       
  1384                                iAnchorItemIndex=0;
       
  1385                                iAnchorItemId = iListItems->ItemId( iAnchorItemIndex );
       
  1386                         }
       
  1387                     if ( aDraw )
       
  1388                         {
       
  1389                         SetCurrentItemIdL( iAnchorItemId );
       
  1390                         }
       
  1391                     iAnchorItemIndex = iListBox->CurrentItemIndex();
       
  1392     #ifdef _DEBUG
       
  1393                     RDebug::Print(_L("CMceMessageListContainer3: iAnchorItemId 0x%x, iAnchorItemIndex %d"), iAnchorItemId, iAnchorItemIndex);
       
  1394     #endif
       
  1395                     //SetCurrentItemIdL( iAnchorItemId );
       
  1396                     }
       
  1397                 else
       
  1398                     {
       
  1399                     if ( aSelection.Count() )
       
  1400                         {
       
  1401                         // is this enough?
       
  1402                         SetCurrentItemIdL( aSelection.At(0) );
       
  1403                         }
       
  1404                     }
       
  1405                 }
       
  1406             }
       
  1407         
       
  1408         
       
  1409         break;
       
  1410         case MMsvSessionObserver::EMsvEntriesMoved:
       
  1411         break;
       
  1412         default:
       
  1413         break;
       
  1414         };
       
  1415     }
       
  1416 
       
  1417 // ----------------------------------------------------
       
  1418 // CMceMessageListContainer::OptionsCommandSupported
       
  1419 // ----------------------------------------------------
       
  1420 TUint CMceMessageListContainer::OptionsCommandSupported() const
       
  1421     {
       
  1422     return TMessageListCommandNone;
       
  1423     }
       
  1424     
       
  1425 // ----------------------------------------------------
       
  1426 // CMceMessageListContainer::HandleOptionsCommandL
       
  1427 // ----------------------------------------------------
       
  1428 void CMceMessageListContainer::HandleOptionsCommandL( TInt /*aCommand*/ )
       
  1429     {
       
  1430     // Should we use assert debug here?
       
  1431     }
       
  1432 
       
  1433 // ----------------------------------------------------
       
  1434 // CMceMessageListContainer::DateTimeFormatChangedL
       
  1435 // ----------------------------------------------------
       
  1436 void CMceMessageListContainer::DateTimeFormatChangedL( TInt /*aChangeFlag*/ )
       
  1437     {
       
  1438     RefreshListbox();
       
  1439     }
       
  1440 
       
  1441 // ---------------------------------------------------------------------------
       
  1442 // CMceMessageListContainer::SetMskL
       
  1443 // ---------------------------------------------------------------------------
       
  1444 //
       
  1445 TInt CMceMessageListContainer::SetSpecialMskL()
       
  1446     {
       
  1447     return NULL;
       
  1448     }
       
  1449 
       
  1450 //-------------------------------------------------------------------------------
       
  1451 //CMceMessageListContainer::HandleShortcutForSearch( const TKeyEvent& aKeyEvent )
       
  1452 //-------------------------------------------------------------------------------
       
  1453 void CMceMessageListContainer::HandleShortcutForSearchL( const TKeyEvent& aKeyEvent )
       
  1454     {
       
  1455    // in remote mailbox key has been pressed, find item if sorted
       
  1456     // by subject or sender
       
  1457     TInt Len = 0;
       
  1458     TBuf<KMceTextBufferLength> text;
       
  1459     text.Zero();
       
  1460     if ( iT9Interface->LastEnteredKey() != ( TInt ) aKeyEvent.iScanCode )
       
  1461         {                    
       
  1462         iT9Interface->ClearCurrentWord();
       
  1463         }      
       
  1464     iT9Interface->AppendKeyPress( (TPtiKey)aKeyEvent.iScanCode );                
       
  1465     Len = iT9Interface->CurrentWord().Length(); 
       
  1466     if ( Len <  KMceTextBufferLength )
       
  1467         {
       
  1468         text = iT9Interface->CurrentWord();
       
  1469         }
       
  1470     else
       
  1471         {
       
  1472         text = iT9Interface->CurrentWord().Left(KMceTextBufferLength);
       
  1473         }
       
  1474     
       
  1475     iOwningView.FindAndSelectEntryL( text );
       
  1476     iT9Timer->Start();       
       
  1477     }
       
  1478 
       
  1479 //-------------------------------------------------------------------------------
       
  1480 //CMceMessageListContainer::HasHandleStarKeyDoneL()
       
  1481 //------------------------------------------------------------------------------- 
       
  1482 TBool CMceMessageListContainer::HasHandleStarKeyDoneL()
       
  1483     {
       
  1484     TBool starkeyIsHandled = EFalse;
       
  1485     if ( StateCanBeChangedByStarKeyL() )
       
  1486         {
       
  1487         if ( IsSortByDate() )
       
  1488             {
       
  1489             MarkReadUnreadWithStarKeyL();
       
  1490             }
       
  1491         else
       
  1492             {
       
  1493             // if sort by anything else other than by Date, handle focus change
       
  1494             iListBox->SetCurrentItemIndex( 0 );
       
  1495             iListBox->DrawDeferred();            
       
  1496             }
       
  1497         starkeyIsHandled = ETrue;
       
  1498         } 
       
  1499     return starkeyIsHandled;
       
  1500     }
       
  1501     
       
  1502 //-------------------------------------------------------------------------------
       
  1503 //CMceMessageListContainer::MarkReadUnreadWithStarKeyL()
       
  1504 //------------------------------------------------------------------------------- 
       
  1505 void CMceMessageListContainer::MarkReadUnreadWithStarKeyL()
       
  1506     {             
       
  1507     MarkItemSelectionL();
       
  1508     if( iOwningView.IsItemUnread( CurrentItemId() ) ) 
       
  1509         {
       
  1510         iOwningView.HandleCommandL( EMceCmdMarkAsRead );
       
  1511         }
       
  1512     else
       
  1513         {
       
  1514         iOwningView.HandleCommandL( EMceCmdMarkAsUnread );
       
  1515         }   
       
  1516     }
       
  1517 
       
  1518 //-------------------------------------------------------------------------------
       
  1519 //CMceMessageListContainer::IsSortByDate()
       
  1520 //------------------------------------------------------------------------------- 
       
  1521 TBool CMceMessageListContainer::IsSortByDate()
       
  1522     {                               
       
  1523     TMsvSelectionOrdering ordering = iListItems->SortType();
       
  1524     return ( ( ordering.Sorting() == EMsvSortByDateReverse) || ( ordering.Sorting() == EMsvSortByDate ) );
       
  1525     }
       
  1526 
       
  1527 // ---------------------------------------------------------------------------
       
  1528 // CMceMessageListContainer::SetContainerFlag
       
  1529 // ---------------------------------------------------------------------------
       
  1530 void CMceMessageListContainer::SetContainerFlag( TMceContainerFlags /*aFlag*/, TBool /*aState*/ )
       
  1531     {
       
  1532     }
       
  1533 
       
  1534 void CMceMessageListContainer::UpdateIconArrayL()
       
  1535     {
       
  1536     // do nothing for two row list.
       
  1537     }
       
  1538 
       
  1539 //  End of File