emailuis/emailui/src/FSAsyncTextFormatter.cpp
branchRCL_3
changeset 17 67369d1b217f
child 18 6b8f3b30d0ec
equal deleted inserted replaced
16:b5fbb9b25d57 17:67369d1b217f
       
     1 /*
       
     2 * Copyright (c) 2008 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 the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Definition of asynchronous text formatter.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "FSAsyncTextFormatter.h"
       
    20 #include <FRMTLAY.H>
       
    21 #include <e32base.h>
       
    22 
       
    23 const TUint KCharsFormattedPerRun = 2000;
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CFSAsyncTextFormatter::CFSAsyncTextFormatter
       
    27 // Constructor.
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CFSAsyncTextFormatter::CFSAsyncTextFormatter() : CActive( EPriorityLow )
       
    31     {
       
    32     FUNC_LOG;
       
    33     CActiveScheduler::Add( this );
       
    34     }
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CFSAsyncTextFormatter::~CFSAsyncTextFormatter
       
    38 // Destructor.
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CFSAsyncTextFormatter::~CFSAsyncTextFormatter()
       
    42     {
       
    43     FUNC_LOG;
       
    44     Cancel();
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CFSAsyncTextFormatter::NewL
       
    49 // Two-phased constructor.
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CFSAsyncTextFormatter* CFSAsyncTextFormatter::NewL()
       
    53     {
       
    54     FUNC_LOG;
       
    55     CFSAsyncTextFormatter* self = new (ELeave) CFSAsyncTextFormatter();
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CFSAsyncTextFormatter::ConstructL
       
    64 // Symbian 2nd phase constructor can leave.
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CFSAsyncTextFormatter::ConstructL()
       
    68     {
       
    69     FUNC_LOG;
       
    70     iCurrentDocPos = 0;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CFSAsyncTextFormatter::FormatAll
       
    75 // Starts formatting process.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CFSAsyncTextFormatter::StartFormatting( CTextLayout* aTextLayout, 
       
    79         MAsyncTextFormatterObserver* aObserver )
       
    80     {
       
    81     FUNC_LOG;
       
    82     iTextLayout = aTextLayout;
       
    83     iObserver = aObserver;
       
    84     iCurrentDocPos = 0;
       
    85     
       
    86     if ( !IsActive() )
       
    87         {
       
    88         TRequestStatus * status = &iStatus;
       
    89         User::RequestComplete(status, 0);
       
    90         SetActive();
       
    91         }
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CFSAsyncTextFormatter::RunL
       
    96 // Handles an active object's request completion event.
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CFSAsyncTextFormatter::RunL()
       
   100     {
       
   101     FUNC_LOG;
       
   102     
       
   103     if ( iCurrentDocPos < iTextLayout->DocumentLength() )
       
   104         {
       
   105         iCurrentDocPos += KCharsFormattedPerRun;
       
   106         if ( iCurrentDocPos > iTextLayout->DocumentLength() )
       
   107             {
       
   108             iCurrentDocPos = iTextLayout->DocumentLength();
       
   109             }
       
   110         iTextLayout->ExtendFormattingToCoverPosL( iCurrentDocPos );
       
   111         
       
   112         // run again
       
   113         TRequestStatus* status = &iStatus;
       
   114         User::RequestComplete( status, KErrNone );
       
   115         SetActive();
       
   116         }
       
   117     else
       
   118         {
       
   119         if ( iObserver )
       
   120             {
       
   121             iObserver->FormatAllTextComplete();
       
   122             }
       
   123         }
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CFSAsyncTextFormatter::DoCancel
       
   128 // Implements cancellation of an outstanding request.
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CFSAsyncTextFormatter::DoCancel()
       
   132     {
       
   133     FUNC_LOG;
       
   134     if ( IsActive() && iObserver )
       
   135         {
       
   136         iObserver->FormatAllTextCancelled();
       
   137         }
       
   138     }