os/textandloc/textandlocutils/inlinetext/src/InlineTextCompositeSource.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2003-2007 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:  ?Description
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
// INCLUDE FILES
sl@0
    20
sl@0
    21
#include "InlineTextCompositeSource.h"
sl@0
    22
sl@0
    23
// MODULE TEMPLATES
sl@0
    24
sl@0
    25
sl@0
    26
// MODULE DATA STRUCTURES
sl@0
    27
sl@0
    28
_LIT( KBadCharacter, " " );
sl@0
    29
sl@0
    30
// ============================ MEMBER FUNCTIONS ===============================
sl@0
    31
sl@0
    32
sl@0
    33
EXPORT_C CInlineTextCompositeSource* CInlineTextCompositeSource::NewL()
sl@0
    34
    { 
sl@0
    35
    CInlineTextCompositeSource* self  = new (ELeave) CInlineTextCompositeSource();
sl@0
    36
    CleanupStack::PushL( self );
sl@0
    37
    self->ConstructL();
sl@0
    38
    CleanupStack::Pop();
sl@0
    39
    return self;
sl@0
    40
    }
sl@0
    41
sl@0
    42
CInlineTextCompositeSource::~CInlineTextCompositeSource()
sl@0
    43
    {
sl@0
    44
    // delete the pointed-to objects because this object owns them
sl@0
    45
    if (iInlineTextSourceArray)
sl@0
    46
        iInlineTextSourceArray->ResetAndDestroy();
sl@0
    47
    delete iInlineTextSourceArray;
sl@0
    48
    }
sl@0
    49
sl@0
    50
EXPORT_C void CInlineTextCompositeSource::InstallInlineTextSourceL( CInlineTextSource* aInlineTextSource )
sl@0
    51
    {
sl@0
    52
    if ( aInlineTextSource ) 
sl@0
    53
        iInlineTextSourceArray->AppendL( aInlineTextSource );
sl@0
    54
    }
sl@0
    55
sl@0
    56
sl@0
    57
TInt CInlineTextCompositeSource::GetNextInlineTextPosition(
sl@0
    58
    const TTmDocPos& aFrom, 
sl@0
    59
    TInt aMaxLength, 
sl@0
    60
    TTmDocPos& aNext)
sl@0
    61
    {
sl@0
    62
    TInt retValue = KErrNotFound;
sl@0
    63
sl@0
    64
    // For now, call CheckFormattingL() at the top of each 
sl@0
    65
    TTmDocPos to( aFrom.iPos + aMaxLength - 1, EFalse );
sl@0
    66
    if ( to < aFrom )
sl@0
    67
        {
sl@0
    68
        to = aFrom; // Makes at least a legal, if zero containing, range
sl@0
    69
        }
sl@0
    70
    TRAP_IGNORE( CheckFormattingL( aFrom, to ) );
sl@0
    71
sl@0
    72
    // The individual formatters are requested and the minimum position is returned
sl@0
    73
    TTmDocPos minDocPos(aFrom);
sl@0
    74
    minDocPos.iPos += ( aMaxLength + 2); // Ensure it is bigger than legal 
sl@0
    75
sl@0
    76
    TInt count = iInlineTextSourceArray->Count();
sl@0
    77
    for ( TInt i = 0; i < count; i++ )
sl@0
    78
        {
sl@0
    79
        TTmDocPos thisNextPos;
sl@0
    80
        TInt err = iInlineTextSourceArray->At(i)
sl@0
    81
            ->GetNextInlineTextPosition( aFrom, aMaxLength, thisNextPos );
sl@0
    82
        if ( err == KErrNone ) // one has been found
sl@0
    83
            {
sl@0
    84
            if ( thisNextPos < minDocPos )
sl@0
    85
                {
sl@0
    86
                minDocPos = thisNextPos;
sl@0
    87
                retValue = KErrNone;
sl@0
    88
                }
sl@0
    89
            }
sl@0
    90
        }
sl@0
    91
    if ( retValue == KErrNone )
sl@0
    92
        aNext = minDocPos;
sl@0
    93
    return retValue;
sl@0
    94
    }
sl@0
    95
sl@0
    96
//
sl@0
    97
//
sl@0
    98
TPtrC CInlineTextCompositeSource::GetInlineText(const TTmDocPos& aAt)
sl@0
    99
    {
sl@0
   100
    TInt count = iInlineTextSourceArray->Count();
sl@0
   101
    for ( TInt i = 0; i < count; i++ )
sl@0
   102
        {
sl@0
   103
        TPtrC retPtr;
sl@0
   104
        if ( iInlineTextSourceArray->At(i)->HasInlineTextAt( aAt, retPtr ) )
sl@0
   105
            return retPtr;
sl@0
   106
        }
sl@0
   107
  
sl@0
   108
#ifdef _DEBUG    
sl@0
   109
    TBuf<80> buf;
sl@0
   110
    buf.Format( _L("Bad fetch of inline text at Pos: %d  Trailing/Leading: %d"), 
sl@0
   111
        aAt.iPos,
sl@0
   112
        aAt.iLeadingEdge );
sl@0
   113
    RDebug::Print( buf );    
sl@0
   114
    
sl@0
   115
    __ASSERT_DEBUG( EFalse, Panic( EInlineTextBadInlineTextFetch ) );
sl@0
   116
#endif
sl@0
   117
sl@0
   118
    return KBadCharacter();
sl@0
   119
sl@0
   120
    }
sl@0
   121
sl@0
   122
//
sl@0
   123
// Formatting notification is just passed to all inline text formatters
sl@0
   124
//
sl@0
   125
void CInlineTextCompositeSource::CheckFormattingL(
sl@0
   126
    const TTmDocPos& aFrom, const TTmDocPos& aTo )
sl@0
   127
    {
sl@0
   128
    TInt count = iInlineTextSourceArray->Count();
sl@0
   129
    for ( TInt i = 0; i < count; i++ )
sl@0
   130
        {
sl@0
   131
        iInlineTextSourceArray->At(i)->CheckFormattingL( aFrom, aTo );
sl@0
   132
        }
sl@0
   133
    }
sl@0
   134
sl@0
   135
CInlineTextCompositeSource::CInlineTextCompositeSource()
sl@0
   136
    {}
sl@0
   137
sl@0
   138
void CInlineTextCompositeSource::ConstructL()
sl@0
   139
    {
sl@0
   140
    iInlineTextSourceArray = new (ELeave) CInlineTextSourceArray(1); // Unit granularity
sl@0
   141
    }
sl@0
   142
sl@0
   143
void CInlineTextCompositeSource::EditObserver( TInt aStart, TInt aExtent )
sl@0
   144
    {
sl@0
   145
    TInt count = iInlineTextSourceArray->Count();
sl@0
   146
    for ( TInt i = 0; i < count; i++ )
sl@0
   147
        {
sl@0
   148
        iInlineTextSourceArray->At(i)->EditObserver( aStart, aExtent );
sl@0
   149
        }
sl@0
   150
    }
sl@0
   151
sl@0
   152
//  End of File