os/textandloc/textandlocutils/inlinetext/src/InlineTextCompositeSource.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2003-2007 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 "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 "InlineTextCompositeSource.h"
    22 
    23 // MODULE TEMPLATES
    24 
    25 
    26 // MODULE DATA STRUCTURES
    27 
    28 _LIT( KBadCharacter, " " );
    29 
    30 // ============================ MEMBER FUNCTIONS ===============================
    31 
    32 
    33 EXPORT_C CInlineTextCompositeSource* CInlineTextCompositeSource::NewL()
    34     { 
    35     CInlineTextCompositeSource* self  = new (ELeave) CInlineTextCompositeSource();
    36     CleanupStack::PushL( self );
    37     self->ConstructL();
    38     CleanupStack::Pop();
    39     return self;
    40     }
    41 
    42 CInlineTextCompositeSource::~CInlineTextCompositeSource()
    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 CInlineTextCompositeSource::InstallInlineTextSourceL( CInlineTextSource* aInlineTextSource )
    51     {
    52     if ( aInlineTextSource ) 
    53         iInlineTextSourceArray->AppendL( aInlineTextSource );
    54     }
    55 
    56 
    57 TInt CInlineTextCompositeSource::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     if ( to < aFrom )
    67         {
    68         to = aFrom; // Makes at least a legal, if zero containing, range
    69         }
    70     TRAP_IGNORE( CheckFormattingL( aFrom, to ) );
    71 
    72     // The individual formatters are requested and the minimum position is returned
    73     TTmDocPos minDocPos(aFrom);
    74     minDocPos.iPos += ( aMaxLength + 2); // Ensure it is bigger than legal 
    75 
    76     TInt count = iInlineTextSourceArray->Count();
    77     for ( TInt i = 0; i < count; i++ )
    78         {
    79         TTmDocPos thisNextPos;
    80         TInt err = iInlineTextSourceArray->At(i)
    81             ->GetNextInlineTextPosition( aFrom, aMaxLength, thisNextPos );
    82         if ( err == KErrNone ) // one has been found
    83             {
    84             if ( thisNextPos < minDocPos )
    85                 {
    86                 minDocPos = thisNextPos;
    87                 retValue = KErrNone;
    88                 }
    89             }
    90         }
    91     if ( retValue == KErrNone )
    92         aNext = minDocPos;
    93     return retValue;
    94     }
    95 
    96 //
    97 //
    98 TPtrC CInlineTextCompositeSource::GetInlineText(const TTmDocPos& aAt)
    99     {
   100     TInt count = iInlineTextSourceArray->Count();
   101     for ( TInt i = 0; i < count; i++ )
   102         {
   103         TPtrC retPtr;
   104         if ( iInlineTextSourceArray->At(i)->HasInlineTextAt( aAt, retPtr ) )
   105             return retPtr;
   106         }
   107   
   108 #ifdef _DEBUG    
   109     TBuf<80> buf;
   110     buf.Format( _L("Bad fetch of inline text at Pos: %d  Trailing/Leading: %d"), 
   111         aAt.iPos,
   112         aAt.iLeadingEdge );
   113     RDebug::Print( buf );    
   114     
   115     __ASSERT_DEBUG( EFalse, Panic( EInlineTextBadInlineTextFetch ) );
   116 #endif
   117 
   118     return KBadCharacter();
   119 
   120     }
   121 
   122 //
   123 // Formatting notification is just passed to all inline text formatters
   124 //
   125 void CInlineTextCompositeSource::CheckFormattingL(
   126     const TTmDocPos& aFrom, const TTmDocPos& aTo )
   127     {
   128     TInt count = iInlineTextSourceArray->Count();
   129     for ( TInt i = 0; i < count; i++ )
   130         {
   131         iInlineTextSourceArray->At(i)->CheckFormattingL( aFrom, aTo );
   132         }
   133     }
   134 
   135 CInlineTextCompositeSource::CInlineTextCompositeSource()
   136     {}
   137 
   138 void CInlineTextCompositeSource::ConstructL()
   139     {
   140     iInlineTextSourceArray = new (ELeave) CInlineTextSourceArray(1); // Unit granularity
   141     }
   142 
   143 void CInlineTextCompositeSource::EditObserver( TInt aStart, TInt aExtent )
   144     {
   145     TInt count = iInlineTextSourceArray->Count();
   146     for ( TInt i = 0; i < count; i++ )
   147         {
   148         iInlineTextSourceArray->At(i)->EditObserver( aStart, aExtent );
   149         }
   150     }
   151 
   152 //  End of File