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