meetingrequest/mrgui/src/cesmrlistcomponent.cpp
branchRCL_3
changeset 16 4ce476e64c59
parent 13 0396474f30f5
child 17 8592a65ad3fb
equal deleted inserted replaced
13:0396474f30f5 16:4ce476e64c59
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  ESMR policy implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include <caltime.h>
       
    20 #include <calentry.h>
       
    21 #include <layoutmetadata.cdl.h>
       
    22 #include <e32math.h>
       
    23 #include <aknphysics.h>
       
    24 
       
    25 #include "cesmrlistcomponent.h"
       
    26 #include "cesmrlayoutmgr.h"
       
    27 #include "nmrlayoutmanager.h"
       
    28 #include "mesmrfieldstorage.h"
       
    29 #include "mesmrcalentry.h"
       
    30 #include "cesmrfield.h"
       
    31 #include "cmrlistpane.h"
       
    32 // <cmail> Removed profiling. </cmail>
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CESMRListComponent::NewL()
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CESMRListComponent* CESMRListComponent::NewL( const CCoeControl* aParent,
       
    41                                              MESMRFieldStorage* aStorage,
       
    42                                              CESMRLayoutManager* aLayout )
       
    43     {
       
    44     FUNC_LOG;
       
    45     CESMRListComponent* self = new (ELeave) CESMRListComponent( aStorage,
       
    46                                                                 aLayout );
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL( aParent );
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CESMRListComponent::CESMRListComponent()
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CESMRListComponent::CESMRListComponent( MESMRFieldStorage* aFactory,
       
    58                                         CESMRLayoutManager* aLayout ) :
       
    59     iFactory( aFactory ),
       
    60     iLayout( aLayout )
       
    61     {
       
    62     FUNC_LOG;
       
    63     // Do nothing
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CESMRListComponent::~CESMRListComponent
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CESMRListComponent::~CESMRListComponent()
       
    71     {
       
    72     FUNC_LOG;
       
    73     delete iFactory;
       
    74     delete iScroll;
       
    75     delete iContainer;
       
    76     
       
    77     delete iPhysics;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CESMRListComponent::ConstructL()
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CESMRListComponent::ConstructL( const CCoeControl* aParent )
       
    85     {
       
    86     FUNC_LOG;
       
    87     CreateWindowL( aParent );
       
    88 
       
    89     iScroll = new (ELeave) CAknDoubleSpanScrollBar( this );
       
    90     iScroll->ConstructL( EFalse, this, this, CEikScrollBar::EVertical, 0 );
       
    91     iScroll->SetModel( &iScrollModel );
       
    92     iScroll->MakeVisible( ETrue );
       
    93     
       
    94     const TInt count(iFactory->Count());
       
    95     for ( TInt i = 0; i < count; i++ )
       
    96         {
       
    97         CESMRField* field = iFactory->Field(i);
       
    98         
       
    99         field->SetListObserver( this );
       
   100         field->SetLayoutManager( iLayout );
       
   101         }
       
   102     
       
   103     iContainer = CMRListPane::NewL( *this, *iFactory, iScrollModel );
       
   104     iPrevThumbPos = iScroll->ThumbPosition();
       
   105 
       
   106     if ( CAknPhysics::FeatureEnabled() )
       
   107         {
       
   108         iPhysics = CAknPhysics::NewL( *this, iContainer );
       
   109         }
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CESMRListComponent::InternalizeL()
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 void CESMRListComponent::InitializeL()
       
   117     {
       
   118     FUNC_LOG;
       
   119     const TInt count(iFactory->Count());
       
   120     for ( TInt i = 0; i < count; i++ )
       
   121         {
       
   122         iFactory->Field(i)->InitializeL();
       
   123         }
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CESMRListComponent::InternalizeL()
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CESMRListComponent::InternalizeL( MESMRCalEntry& aEntry )
       
   131     {
       
   132     FUNC_LOG;
       
   133     iFactory->InternalizeL( aEntry );
       
   134     // This is called to make sure everything is drawn correctly
       
   135     DrawDeferred();
       
   136     }
       
   137 
       
   138 void CESMRListComponent::DisableSizeChange(TBool aDisable )
       
   139     {
       
   140     FUNC_LOG;
       
   141     iDisableSizeChanged = aDisable;
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CESMRListComponent::ExternalizeL()
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CESMRListComponent::ExternalizeL( 
       
   149 		MESMRCalEntry& aEntry, 
       
   150 		TBool aForceValidation )
       
   151     {
       
   152     FUNC_LOG;
       
   153     CESMRField* currentFocus = FocusedItem();
       
   154     ASSERT( currentFocus );
       
   155     TESMREntryFieldId id = currentFocus->FieldId();
       
   156 
       
   157     if ( aForceValidation )
       
   158         {
       
   159         // force validate the values:
       
   160         TInt err = iFactory->Validate( id, aForceValidation );
       
   161         // fill the calendar entry with data in fields.
       
   162         iFactory->ExternalizeL( aEntry );
       
   163         }
       
   164     else
       
   165         {
       
   166         TInt err = iFactory->Validate( id );
       
   167         if ( err )
       
   168             {
       
   169             SetControlFocusedL( id );
       
   170             User::Leave( err );
       
   171             }
       
   172         else
       
   173             {
       
   174             // fill the calendar entry with data in fields.
       
   175             iFactory->ExternalizeL( aEntry );
       
   176             }
       
   177         }
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CESMRListComponent::CountComponentControls()
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 TInt CESMRListComponent::CountComponentControls() const
       
   185     {
       
   186     FUNC_LOG;
       
   187     return 2;
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CESMRListComponent::HandleFontChange()
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CESMRListComponent::HandleFontChange()
       
   195     {
       
   196     FUNC_LOG;
       
   197     // Disable SizeChanged handling until all fonts are updated
       
   198     iDisableSizeChanged = ETrue;
       
   199     const TInt count(iFactory->Count());
       
   200     for ( TInt i = 0; i < count; i++ )
       
   201         {
       
   202         // Updates Font depending on the type of a field
       
   203         TRAP_IGNORE( iFactory->Field(i)->FontChangedL() );
       
   204         }
       
   205     // Enable and call SizeChanged
       
   206     iDisableSizeChanged = EFalse;
       
   207     SizeChanged();
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CESMRListComponent::ComponentControl()
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 CCoeControl* CESMRListComponent::ComponentControl( TInt aInd ) const
       
   215     {
       
   216     FUNC_LOG;
       
   217     CCoeControl* control = NULL;
       
   218     switch ( aInd )
       
   219         {
       
   220         case 0:
       
   221             control = iContainer;
       
   222             break;
       
   223         case 1:
       
   224             control = iScroll;
       
   225             break;
       
   226         default:
       
   227             break;
       
   228         }
       
   229     return control;
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // CESMRListComponent::SizeChanged
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 void CESMRListComponent::SizeChanged()
       
   237     {
       
   238     FUNC_LOG;
       
   239     if ( iDisableSizeChanged || Rect() == TRect( 0, 0, 0, 0 ) )
       
   240         {
       
   241         return;
       
   242         }
       
   243 
       
   244     TRect containerRect( Rect() );
       
   245     
       
   246     TAknLayoutRect listareaLayoutRect =
       
   247         NMRLayoutManager::GetLayoutRect( containerRect, NMRLayoutManager::EMRLayoutListArea );
       
   248     TRect listareaRect( listareaLayoutRect.Rect() );
       
   249     iContainer->SetRect( listareaRect );
       
   250     
       
   251     TAknWindowComponentLayout scrollLayout =
       
   252         NMRLayoutManager::GetWindowComponentLayout( NMRLayoutManager::EMRLayoutScrollBar );
       
   253     AknLayoutUtils::LayoutControl( iScroll, containerRect, scrollLayout );
       
   254 
       
   255     ScrollItemVisible( KErrNotFound ); // Update scroll position
       
   256 
       
   257     // physics needs to be initialized before screensaver gets activated    
       
   258     TRAP_IGNORE( UpdatePhysicsL() );
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CESMRListComponent::OfferKeyEventL
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 TKeyResponse CESMRListComponent::OfferKeyEventL(
       
   266 		const TKeyEvent &aEvent, 
       
   267 		TEventCode aType )
       
   268     {
       
   269     FUNC_LOG;
       
   270     TKeyResponse response = iContainer->OfferKeyEventL( aEvent, aType );
       
   271     
       
   272     if ( EKeyWasConsumed == response )
       
   273         {
       
   274         iScroll->SetModel( &iScrollModel );
       
   275         }
       
   276     
       
   277     TInt thumbPos = iScroll->ThumbPosition();
       
   278     iPrevThumbPos = thumbPos;
       
   279 
       
   280     if( iPhysics )
       
   281         {
       
   282         iPhysics->StopPhysics();
       
   283         iPhysics->ResetFriction();
       
   284         }
       
   285 
       
   286     return response;
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CESMRListComponent::HandleScrollEventL
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CESMRListComponent::HandleScrollEventL(
       
   294     CEikScrollBar* aScrollBar,
       
   295     TEikScrollEvent /*aEventType*/ )
       
   296     {
       
   297     FUNC_LOG;
       
   298     if ( aScrollBar == iScroll )
       
   299         {
       
   300         TInt thumbPos = aScrollBar->ThumbPosition();
       
   301         TInt delta = thumbPos - iPrevThumbPos;
       
   302         if ( delta != 0 )
       
   303             {
       
   304             iPrevThumbPos = thumbPos;
       
   305             iContainer->ScrollView( delta );
       
   306             }
       
   307         }
       
   308     if( iPhysics )
       
   309         {
       
   310         iPhysics->StopPhysics();
       
   311         iPhysics->ResetFriction();
       
   312         }
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CESMRListComponent::UpdatePhysicsL
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 void CESMRListComponent::UpdatePhysicsL()
       
   320     {
       
   321     FUNC_LOG;
       
   322     if ( iPhysics )
       
   323         {
       
   324         const TSize viewSize( Size() );
       
   325         TInt wSize = iScrollModel.ScrollSpan();
       
   326         const TSize worldSize( viewSize.iWidth, wSize );
       
   327 
       
   328 
       
   329         iPhysics->StopPhysics();
       
   330         iPhysics->ResetFriction();
       
   331         iPhysics->InitPhysicsL( worldSize, viewSize, EFalse );
       
   332         }
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // CESMRListComponent::ViewPositionChanged
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 void CESMRListComponent::ViewPositionChanged(
       
   340         const TPoint& aNewPosition,
       
   341         TBool /*aDrawNow*/,
       
   342         TUint /*aFlags*/ )
       
   343     {
       
   344     // Sometimes ViewPositionChanged events come after view is already changed,
       
   345     // so adding a safety check here
       
   346     if( IsVisible() )
       
   347         {
       
   348         TPoint centerPos = iContainer->GetViewCenterPosition();
       
   349         TInt scrollOffset = aNewPosition.iY - centerPos.iY;
       
   350 
       
   351         iContainer->ScrollView( scrollOffset );
       
   352         iPrevThumbPos = iScroll->ThumbPosition();
       
   353         // updates scrollbar thumb position and does redrawing
       
   354         iScroll->SetModel( &iScrollModel );
       
   355         }
       
   356     }
       
   357 
       
   358 // ---------------------------------------------------------------------------
       
   359 // CESMRListComponent::PhysicEmulationEnded
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void CESMRListComponent::PhysicEmulationEnded()
       
   363     {
       
   364     }
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // CESMRListComponent::ViewPosition
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 TPoint CESMRListComponent::ViewPosition() const
       
   371     {
       
   372     TPoint viewPos = iContainer->GetViewCenterPosition();
       
   373     return viewPos;
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // CESMRListComponent::ScrollItemVisible()
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void CESMRListComponent::ScrollItemVisible( TInt aInd/*, TBool*/ /*aSizeChanged*/ )
       
   381     {
       
   382     FUNC_LOG;
       
   383     iContainer->ScrollItemVisible( aInd );
       
   384     UpdateScrollBar();
       
   385     DrawDeferred();
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 // CESMRListComponent::UpdateScrollBar()
       
   390 // ---------------------------------------------------------------------------
       
   391 //
       
   392 void CESMRListComponent::UpdateScrollBar()
       
   393     {
       
   394     FUNC_LOG;
       
   395     iContainer->UpdateFocusPosition();
       
   396     iScroll->SetModel( &iScrollModel );
       
   397     }
       
   398 
       
   399 // ---------------------------------------------------------------------------
       
   400 // CESMRListComponent::ListObserver
       
   401 // ---------------------------------------------------------------------------
       
   402 //
       
   403 MESMRListObserver& CESMRListComponent::ListObserver()
       
   404     {
       
   405     FUNC_LOG;
       
   406     return *this;
       
   407     }
       
   408 
       
   409 CESMRField* CESMRListComponent::FocusedItem() const
       
   410     {
       
   411     FUNC_LOG;
       
   412     return iContainer->FocusedItem();
       
   413     }
       
   414 
       
   415 // ---------------------------------------------------------------------------
       
   416 // CESMRListComponent::IsControlVisible()
       
   417 // ---------------------------------------------------------------------------
       
   418 //
       
   419 TBool CESMRListComponent::IsControlVisible( TESMREntryFieldId aField )
       
   420     {
       
   421     FUNC_LOG;
       
   422     TBool ret( EFalse );
       
   423     
       
   424     CESMRField* field = iFactory->FieldById( aField );
       
   425     if ( field && field->IsVisible() )
       
   426         {
       
   427         ret = ETrue;
       
   428         }
       
   429     
       
   430     return ret;
       
   431     }
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // CESMRListComponent::ControlSizeChanged()
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 void CESMRListComponent::ControlSizeChanged( CESMRField* aField )
       
   438     {
       
   439     FUNC_LOG;
       
   440     /* Called whenever one of the controls size changed
       
   441      * E.G. when a eik edwin expands */
       
   442     iContainer->ControlSizeChanged( aField );
       
   443     }
       
   444 
       
   445 // ---------------------------------------------------------------------------
       
   446 // CESMRListComponent::InsertControl()
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 void CESMRListComponent::InsertControl( TESMREntryFieldId aField )
       
   450     {
       
   451     FUNC_LOG;
       
   452     iContainer->InsertControl( aField );
       
   453     }
       
   454 
       
   455 // ---------------------------------------------------------------------------
       
   456 // CESMRListComponent::RemoveControl()
       
   457 // ---------------------------------------------------------------------------
       
   458 //
       
   459 void CESMRListComponent::RemoveControl( TESMREntryFieldId aField )
       
   460     {
       
   461     FUNC_LOG;
       
   462     iContainer->RemoveControl( aField );
       
   463     }
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // CESMRListComponent::SetControlFocused()
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 void CESMRListComponent::SetControlFocusedL( TESMREntryFieldId aField )
       
   470     {
       
   471     FUNC_LOG;
       
   472     iContainer->SetControlFocusedL( aField );
       
   473     UpdateScrollBar();
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------------------------
       
   477 // CESMRListComponent::MoveListAreaDownL
       
   478 // ---------------------------------------------------------------------------
       
   479 //
       
   480 void CESMRListComponent::MoveListAreaDownL( TInt aAmount )
       
   481     {
       
   482     FUNC_LOG;
       
   483     iContainer->MoveListAreaDownL( aAmount );
       
   484     
       
   485     // Do the view scrolling if needed:
       
   486     if ( aAmount )
       
   487         {
       
   488         UpdateScrollBar();
       
   489         DrawDeferred();
       
   490         }
       
   491     }
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 // CESMRListComponent::MoveListAreaUpL
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 void CESMRListComponent::MoveListAreaUpL( TInt aAmount )
       
   498     {
       
   499     FUNC_LOG;
       
   500     iContainer->MoveListAreaUpL( aAmount );
       
   501     
       
   502     // do the scrolling if needed:
       
   503     if ( aAmount > 0 )
       
   504         {
       
   505         UpdateScrollBar();
       
   506         DrawDeferred();
       
   507         }
       
   508     }
       
   509 
       
   510 // ---------------------------------------------------------------------------
       
   511 // CESMRListComponent::ListHeight()
       
   512 // ---------------------------------------------------------------------------
       
   513 //
       
   514 TInt CESMRListComponent::ListHeight()
       
   515     {
       
   516     FUNC_LOG;
       
   517     return iContainer->Size().iHeight;
       
   518     }
       
   519 
       
   520 // ---------------------------------------------------------------------------
       
   521 // CESMRListComponent::IsFieldBottomVisible()
       
   522 // ---------------------------------------------------------------------------
       
   523 //
       
   524  TBool CESMRListComponent::IsFieldBottomVisible()
       
   525     {
       
   526     FUNC_LOG;
       
   527     return iContainer->IsFieldBottomVisible();
       
   528     }
       
   529 
       
   530  // -----------------------------------------------------------------------------
       
   531  // CESMRListComponent::HandlePointerEventL
       
   532  // -----------------------------------------------------------------------------
       
   533  //
       
   534  void CESMRListComponent::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   535     {
       
   536     FUNC_LOG;
       
   537 
       
   538 
       
   539     CCoeControl::HandlePointerEventL(aPointerEvent);
       
   540     TPoint position = aPointerEvent.iPosition;
       
   541 
       
   542     switch ( aPointerEvent.iType )
       
   543         {
       
   544         case TPointerEvent::EButton1Down:
       
   545             iPreviousPosition = iOriginalPosition = aPointerEvent.iPosition;
       
   546 
       
   547             iIsScrolling = iScroll->Rect().Contains(aPointerEvent.iPosition );
       
   548             iCurrentScrollSpan = iScrollModel.ScrollSpan();
       
   549 
       
   550 
       
   551             iIsDragging = EFalse;
       
   552             if( iPhysics )
       
   553                 {
       
   554                 iStartTime.HomeTime();
       
   555                 UpdatePhysicsL();
       
   556                 }
       
   557             break;
       
   558 
       
   559         case TPointerEvent::EDrag:
       
   560             if (!iIsScrolling)
       
   561                 {
       
   562                 // if when dragging scrollbar pointer touches container rectangle, 
       
   563                 // do not activate physics!
       
   564                 iIsDragging = ETrue;
       
   565             
       
   566                 if( iPhysics )
       
   567                     {
       
   568                     TPoint delta( 0, iPreviousPosition.iY - position.iY );
       
   569                     iPhysics->RegisterPanningPosition( delta );
       
   570                     }
       
   571                 }
       
   572             // Save current position as previous pos for future calculations
       
   573             iPreviousPosition = position;
       
   574             break;
       
   575          
       
   576         case TPointerEvent::EButton1Up:
       
   577             if( iIsDragging && iPhysics )
       
   578                 {
       
   579                 TPoint drag(iOriginalPosition - aPointerEvent.iPosition);
       
   580                 iPhysics->StartPhysics(drag, iStartTime);
       
   581                 }
       
   582                 
       
   583         // some fields may change their size due to as result of click, update model if needed
       
   584         if (iCurrentScrollSpan != iScrollModel.ScrollSpan())
       
   585             {
       
   586             iScroll->SetModel( &iScrollModel );
       
   587             }
       
   588             break;
       
   589         }
       
   590      }
       
   591      
       
   592      
       
   593  // -----------------------------------------------------------------------------
       
   594  // CESMRListComponent::MakeVisible
       
   595  // -----------------------------------------------------------------------------
       
   596  //
       
   597 void CESMRListComponent::MakeVisible( TBool  aIsVisible )
       
   598     {
       
   599     if(!aIsVisible && IsVisible() )
       
   600         {
       
   601         // hiding the control, stop physics for performance gain
       
   602         if( iPhysics )
       
   603             {
       
   604             iPhysics->StopPhysics();
       
   605             iPhysics->ResetFriction();
       
   606             }
       
   607         }
       
   608     }
       
   609 // End of file
       
   610