uifw/EikStd/coctlsrc/AknCompositeInlineTextSource.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2003 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "AknCompositeInlineTextSource.h"
       
    22 
       
    23 // MODULE TEMPLATES
       
    24 
       
    25 
       
    26 // MODULE DATA STRUCTURES
       
    27 
       
    28 _LIT( KBadCharacter, " " );
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 
       
    33 CAknCompositeInlineTextSource* CAknCompositeInlineTextSource::NewL()
       
    34     { 
       
    35     CAknCompositeInlineTextSource* self  = new (ELeave) CAknCompositeInlineTextSource();
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop();
       
    39     return self;
       
    40     }
       
    41 
       
    42 CAknCompositeInlineTextSource::~CAknCompositeInlineTextSource()
       
    43     {
       
    44     // delete the pointed-to objects because this object owns them
       
    45     if (iInlineTextSourceArray)
       
    46         iInlineTextSourceArray->ResetAndDestroy();
       
    47     delete iInlineTextSourceArray;
       
    48     }
       
    49 
       
    50 EXPORT_C void CAknCompositeInlineTextSource::InstallInlineTextSourceL( CAknInlineTextSource* aInlineTextSource )
       
    51     {
       
    52     if ( aInlineTextSource ) 
       
    53         iInlineTextSourceArray->AppendL( aInlineTextSource );
       
    54     }
       
    55 
       
    56 
       
    57 TInt CAknCompositeInlineTextSource::GetNextInlineTextPosition(
       
    58     const TTmDocPos& aFrom, 
       
    59     TInt aMaxLength, 
       
    60     TTmDocPos& aNext)
       
    61     {
       
    62     TInt retValue = KErrNotFound;
       
    63 
       
    64     // For now, call CheckFormattingL() at the top of each 
       
    65     TTmDocPos to( aFrom.iPos + aMaxLength - 1, EFalse );
       
    66     TRAP_IGNORE( CheckFormattingL( aFrom, to ) );
       
    67 
       
    68     // The individual formatters are requested and the minimum position is returned
       
    69     TTmDocPos minDocPos(aFrom);
       
    70     minDocPos.iPos += ( aMaxLength + 2); // Ensure it is bigger than legal 
       
    71 
       
    72     TInt count = iInlineTextSourceArray->Count();
       
    73     for ( TInt i = 0; i < count; i++ )
       
    74         {
       
    75         TTmDocPos thisNextPos;
       
    76         TInt err = iInlineTextSourceArray->At(i)
       
    77             ->GetNextInlineTextPosition( aFrom, aMaxLength, thisNextPos );
       
    78         if ( err == KErrNone ) // one has been found
       
    79             {
       
    80             if ( thisNextPos < minDocPos )
       
    81                 {
       
    82                 minDocPos = thisNextPos;
       
    83                 retValue = KErrNone;
       
    84                 }
       
    85             }
       
    86         }
       
    87     if ( retValue == KErrNone )
       
    88         aNext = minDocPos;
       
    89     return retValue;
       
    90     }
       
    91 
       
    92 //
       
    93 //
       
    94 TPtrC CAknCompositeInlineTextSource::GetInlineText(const TTmDocPos& aAt)
       
    95     {
       
    96     TInt count = iInlineTextSourceArray->Count();
       
    97     for ( TInt i = 0; i < count; i++ )
       
    98         {
       
    99         TPtrC retPtr;
       
   100         if ( iInlineTextSourceArray->At(i)->HasInlineTextAt( aAt, retPtr ) )
       
   101             return retPtr;
       
   102         }
       
   103   
       
   104 #ifdef _DEBUG    
       
   105     TBuf<80> buf;
       
   106     buf.Format( _L("Bad fetch of inline text at Pos: %d  Trailing/Leading: %d"), 
       
   107         aAt.iPos,
       
   108         aAt.iLeadingEdge );
       
   109     RDebug::Print( buf );    
       
   110     
       
   111     __ASSERT_DEBUG( EFalse, Panic( EAknInlineTextFormattingBadInlineTextFetch ) );
       
   112 #endif
       
   113 
       
   114     return KBadCharacter();
       
   115 
       
   116     }
       
   117 
       
   118 //
       
   119 // Formatting notification is just passed to all inline text formatters
       
   120 //
       
   121 void CAknCompositeInlineTextSource::CheckFormattingL(
       
   122     const TTmDocPos& aFrom, const TTmDocPos& aTo )
       
   123     {
       
   124     TInt count = iInlineTextSourceArray->Count();
       
   125     for ( TInt i = 0; i < count; i++ )
       
   126         {
       
   127         iInlineTextSourceArray->At(i)->CheckFormattingL( aFrom, aTo );
       
   128         }
       
   129     }
       
   130 
       
   131 CAknCompositeInlineTextSource::CAknCompositeInlineTextSource()
       
   132     {}
       
   133 
       
   134 void CAknCompositeInlineTextSource::ConstructL()
       
   135     {
       
   136     iInlineTextSourceArray = new (ELeave) CAknInlineTextSourceArray(1); // Unit granularity
       
   137     }
       
   138 
       
   139 void CAknCompositeInlineTextSource::EditObserver( TInt aStart, TInt aExtent )
       
   140     {
       
   141     TInt count = iInlineTextSourceArray->Count();
       
   142     for ( TInt i = 0; i < count; i++ )
       
   143         {
       
   144         iInlineTextSourceArray->At(i)->EditObserver( aStart, aExtent );
       
   145         }
       
   146     }
       
   147 
       
   148 //  End of File