LCOV - code coverage report
Current view: top level - sw/source/core/tox - txmsrt.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 107 344 31.1 %
Date: 2014-04-11 Functions: 16 45 35.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/resid.hxx>
      21             : #include <unotools/charclass.hxx>
      22             : #include <com/sun/star/i18n/CollatorOptions.hpp>
      23             : #include <editeng/unolingu.hxx>
      24             : #include <txtfld.hxx>
      25             : #include <doc.hxx>
      26             : #include <docary.hxx>
      27             : #include <cntfrm.hxx>
      28             : #include <node.hxx>
      29             : #include <frmatr.hxx>
      30             : #include <pam.hxx>
      31             : #include <txttxmrk.hxx>
      32             : #include <frmfmt.hxx>
      33             : #include <fmtfld.hxx>
      34             : #include <txmsrt.hxx>
      35             : #include <ndtxt.hxx>
      36             : #include <txtatr.hxx>
      37             : #include <swtable.hxx>
      38             : #include <expfld.hxx>
      39             : #include <authfld.hxx>
      40             : #include <toxwrap.hxx>
      41             : 
      42             : #include <comcore.hrc>
      43             : #include <numrule.hxx>
      44             : 
      45             : extern bool IsFrameBehind( const SwTxtNode& rMyNd, sal_Int32 nMySttPos,
      46             :                            const SwTxtNode& rBehindNd, sal_Int32 nSttPos );
      47             : 
      48             : using namespace ::com::sun::star;
      49             : using namespace ::com::sun::star::uno;
      50             : /*--------------------------------------------------------------------
      51             :   Initialize strings
      52             :  --------------------------------------------------------------------*/
      53             : 
      54             : sal_uInt16 SwTOXSortTabBase::nOpt = 0;
      55             : 
      56           7 : SwTOXInternational::SwTOXInternational( LanguageType nLang, sal_uInt16 nOpt,
      57             :                                         const OUString& rSortAlgorithm ) :
      58             :     eLang( nLang ),
      59             :     sSortAlgorithm(rSortAlgorithm),
      60           7 :     nOptions( nOpt )
      61             : {
      62           7 :     Init();
      63           7 : }
      64             : 
      65           0 : SwTOXInternational::SwTOXInternational( const SwTOXInternational& rIntl ) :
      66             :     eLang( rIntl.eLang ),
      67             :     sSortAlgorithm(rIntl.sSortAlgorithm),
      68           0 :     nOptions( rIntl.nOptions )
      69             : {
      70           0 :   Init();
      71           0 : }
      72             : 
      73           7 : void SwTOXInternational::Init()
      74             : {
      75           7 :     pIndexWrapper = new IndexEntrySupplierWrapper();
      76             : 
      77           7 :     const lang::Locale aLcl( LanguageTag::convertToLocale( eLang ) );
      78           7 :     pIndexWrapper->SetLocale( aLcl );
      79             : 
      80           7 :     if(sSortAlgorithm.isEmpty())
      81             :     {
      82           5 :         Sequence < OUString > aSeq( pIndexWrapper->GetAlgorithmList( aLcl ));
      83           5 :         if(aSeq.getLength())
      84           5 :             sSortAlgorithm = aSeq.getConstArray()[0];
      85             :     }
      86             : 
      87           7 :     if ( nOptions & nsSwTOIOptions::TOI_CASE_SENSITIVE )
      88           2 :         pIndexWrapper->LoadAlgorithm( aLcl, sSortAlgorithm, 0 );
      89             :     else
      90           5 :         pIndexWrapper->LoadAlgorithm( aLcl, sSortAlgorithm, SW_COLLATOR_IGNORES );
      91             : 
      92           7 :     pCharClass = new CharClass( LanguageTag( aLcl ));
      93             : 
      94           7 : }
      95             : 
      96          14 : SwTOXInternational::~SwTOXInternational()
      97             : {
      98           7 :     delete pCharClass;
      99           7 :     delete pIndexWrapper;
     100           7 : }
     101             : 
     102           1 : OUString SwTOXInternational::ToUpper( const OUString& rStr, sal_Int32 nPos ) const
     103             : {
     104           1 :     return pCharClass->uppercase( rStr, nPos, 1 );
     105             : }
     106             : 
     107           0 : inline bool SwTOXInternational::IsNumeric( const OUString& rStr ) const
     108             : {
     109           0 :     return pCharClass->isNumeric( rStr );
     110             : }
     111             : 
     112           0 : sal_Int32 SwTOXInternational::Compare( const TextAndReading& rTaR1,
     113             :                                        const lang::Locale& rLocale1,
     114             :                                        const TextAndReading& rTaR2,
     115             :                                        const lang::Locale& rLocale2 ) const
     116             : {
     117             :     return pIndexWrapper->CompareIndexEntry( rTaR1.sText, rTaR1.sReading, rLocale1,
     118           0 :                                              rTaR2.sText, rTaR2.sReading, rLocale2 );
     119             : }
     120             : 
     121           1 : OUString SwTOXInternational::GetIndexKey( const TextAndReading& rTaR,
     122             :                                         const lang::Locale& rLocale ) const
     123             : {
     124           1 :     return pIndexWrapper->GetIndexKey( rTaR.sText, rTaR.sReading, rLocale );
     125             : }
     126             : 
     127           0 : OUString SwTOXInternational::GetFollowingText( bool bMorePages ) const
     128             : {
     129           0 :     return pIndexWrapper->GetFollowingText( bMorePages );
     130             : }
     131             : 
     132             : /*--------------------------------------------------------------------
     133             :   SortElement for TOX entries
     134             :  --------------------------------------------------------------------*/
     135             : 
     136           4 : SwTOXSortTabBase::SwTOXSortTabBase( TOXSortType nTyp, const SwCntntNode* pNd,
     137             :                                     const SwTxtTOXMark* pMark,
     138             :                                     const SwTOXInternational* pInter,
     139             :                                     const lang::Locale* pLocale )
     140             :     : pTOXNd( 0 ), pTxtMark( pMark ), pTOXIntl( pInter ),
     141           4 :     nPos( 0 ), nCntPos( 0 ), nType( static_cast<sal_uInt16>(nTyp) ), bValidTxt( false )
     142             : {
     143           4 :     if ( pLocale )
     144           1 :         aLocale = *pLocale;
     145             : 
     146           4 :     if( pNd )
     147             :     {
     148           4 :         sal_Int32 n = 0;
     149           4 :         if( pTxtMark )
     150           1 :             n = *pTxtMark->GetStart();
     151           4 :         SwTOXSource aTmp( pNd, n, pTxtMark && pTxtMark->GetTOXMark().IsMainEntry() );
     152           4 :         aTOXSources.push_back(aTmp);
     153             : 
     154           4 :         nPos = pNd->GetIndex();
     155             : 
     156           4 :         switch( nTyp )
     157             :         {
     158             :         case TOX_SORT_CONTENT:
     159             :         case TOX_SORT_PARA:
     160             :         case TOX_SORT_TABLE:
     161             :             // If they are in a special areas, we should get the position at the
     162             :             // body
     163           3 :             if( nPos < pNd->GetNodes().GetEndOfExtras().GetIndex() )
     164             :             {
     165             :                 // Then get the 'anchor' (body) position
     166           0 :                 Point aPt;
     167           0 :                 const SwCntntFrm* pFrm = pNd->getLayoutFrm( pNd->GetDoc()->GetCurrentLayout(), &aPt, 0, false );
     168           0 :                 if( pFrm )
     169             :                 {
     170           0 :                     SwPosition aPos( *pNd );
     171           0 :                     const SwDoc& rDoc = *pNd->GetDoc();
     172           0 :                     bool const bResult = GetBodyTxtNode( rDoc, aPos, *pFrm );
     173             :                     OSL_ENSURE(bResult, "where is the text node");
     174             :                     (void) bResult; // unused in non-debug
     175           0 :                     nPos = aPos.nNode.GetIndex();
     176           0 :                     nCntPos = aPos.nContent.GetIndex();
     177             :                 }
     178             :             }
     179             :             else
     180           3 :                 nCntPos = n;
     181           3 :             break;
     182           1 :         default: break;
     183             :         }
     184             :     }
     185           4 : }
     186             : 
     187           0 : OUString SwTOXSortTabBase::GetURL() const
     188             : {
     189           0 :     return OUString();
     190             : }
     191             : 
     192           0 : void SwTOXSortTabBase::FillText( SwTxtNode& rNd, const SwIndex& rInsPos,
     193             :                                     sal_uInt16 ) const
     194             : {
     195           0 :     rNd.InsertText( GetTxt().sText, rInsPos );
     196           0 : }
     197             : 
     198           1 : bool SwTOXSortTabBase::operator==( const SwTOXSortTabBase& rCmp )
     199             : {
     200           1 :     bool bRet = nPos == rCmp.nPos && nCntPos == rCmp.nCntPos &&
     201           0 :             (!aTOXSources[0].pNd || !rCmp.aTOXSources[0].pNd ||
     202           1 :             aTOXSources[0].pNd == rCmp.aTOXSources[0].pNd );
     203             : 
     204           1 :     if( TOX_SORT_CONTENT == nType )
     205             :     {
     206           0 :         bRet = bRet && pTxtMark && rCmp.pTxtMark &&
     207           0 :                 *pTxtMark->GetStart() == *rCmp.pTxtMark->GetStart();
     208             : 
     209           0 :         if( bRet )
     210             :         {
     211             :             // Both pointers exist -> compare text
     212             :             // else -> compare AlternativeText
     213           0 :             const sal_Int32 *pEnd  = pTxtMark->End();
     214           0 :             const sal_Int32 *pEndCmp = rCmp.pTxtMark->End();
     215             : 
     216           0 :             bRet = ( ( pEnd && pEndCmp ) || ( !pEnd && !pEndCmp ) ) &&
     217           0 :                     pTOXIntl->IsEqual( GetTxt(), GetLocale(),
     218           0 :                                        rCmp.GetTxt(), rCmp.GetLocale() );
     219             :         }
     220             :     }
     221           1 :     return bRet;
     222             : }
     223             : 
     224           1 : bool SwTOXSortTabBase::operator<( const SwTOXSortTabBase& rCmp )
     225             : {
     226           1 :     if( nPos < rCmp.nPos )
     227           0 :         return true;
     228             : 
     229           1 :     if( nPos == rCmp.nPos )
     230             :     {
     231           0 :         if( nCntPos < rCmp.nCntPos )
     232           0 :             return true;
     233             : 
     234           0 :         if( nCntPos == rCmp.nCntPos )
     235             :         {
     236           0 :             const SwNode* pFirst = aTOXSources[0].pNd;
     237           0 :             const SwNode* pNext = rCmp.aTOXSources[0].pNd;
     238             : 
     239           0 :             if( pFirst && pFirst == pNext )
     240             :             {
     241           0 :                 if( TOX_SORT_CONTENT == nType && pTxtMark && rCmp.pTxtMark )
     242             :                 {
     243           0 :                     if( *pTxtMark->GetStart() < *rCmp.pTxtMark->GetStart() )
     244           0 :                         return true;
     245             : 
     246           0 :                     if( *pTxtMark->GetStart() == *rCmp.pTxtMark->GetStart() )
     247             :                     {
     248           0 :                         const sal_Int32 *pEnd = pTxtMark->End();
     249           0 :                         const sal_Int32 *pEndCmp = rCmp.pTxtMark->End();
     250             : 
     251             :                         // Both pointers exist -> compare text
     252             :                         // else -> compare AlternativeText
     253           0 :                         if( ( pEnd && pEndCmp ) || ( !pEnd && !pEndCmp ) )
     254           0 :                             pTOXIntl->IsEqual( GetTxt(), GetLocale(),
     255           0 :                                                rCmp.GetTxt(), rCmp.GetLocale() );
     256             : 
     257           0 :                         if( pEnd && !pEndCmp )
     258           0 :                             return true;
     259             :                     }
     260           0 :                 }
     261             :             }
     262           0 :             else if( pFirst && pFirst->IsTxtNode() &&
     263           0 :                      pNext && pNext->IsTxtNode() )
     264             :                     return ::IsFrameBehind( *(SwTxtNode*)pNext, nCntPos,
     265           0 :                                             *(SwTxtNode*)pFirst, nCntPos );
     266             :         }
     267             :     }
     268           1 :     return false;
     269             : }
     270             : 
     271             : /*--------------------------------------------------------------------
     272             :    Sorted keyword entry
     273             :  --------------------------------------------------------------------*/
     274             : 
     275           1 : SwTOXIndex::SwTOXIndex( const SwTxtNode& rNd,
     276             :                         const SwTxtTOXMark* pMark, sal_uInt16 nOptions,
     277             :                         sal_uInt8 nKyLevel,
     278             :                         const SwTOXInternational& rIntl,
     279             :                         const lang::Locale& rLocale )
     280             :     : SwTOXSortTabBase( TOX_SORT_INDEX, &rNd, pMark, &rIntl, &rLocale ),
     281           1 :     nKeyLevel(nKyLevel)
     282             : {
     283           1 :     nPos = rNd.GetIndex();
     284           1 :     nOpt = nOptions;
     285           1 : }
     286             : 
     287             : // Compare keywords. Only relates to the text.
     288             : 
     289           0 : bool SwTOXIndex::operator==( const SwTOXSortTabBase& rCmpBase )
     290             : {
     291           0 :     SwTOXIndex& rCmp = (SwTOXIndex&)rCmpBase;
     292             : 
     293             :     // Respect case taking dependencies into account
     294           0 :     if(GetLevel() != rCmp.GetLevel() || nKeyLevel != rCmp.nKeyLevel)
     295           0 :         return false;
     296             : 
     297             :     OSL_ENSURE(pTxtMark, "pTxtMark == 0, No keyword");
     298             : 
     299           0 :     bool bRet = pTOXIntl->IsEqual( GetTxt(), GetLocale(),
     300           0 :                                    rCmp.GetTxt(), rCmp.GetLocale() );
     301             : 
     302             :     // If we don't summarize we need to evaluate the Pos
     303           0 :     if(bRet && !(GetOptions() & nsSwTOIOptions::TOI_SAME_ENTRY))
     304           0 :         bRet = nPos == rCmp.nPos;
     305             : 
     306           0 :     return bRet;
     307             : }
     308             : 
     309             : // operator, only depends on the text
     310             : 
     311           0 : bool SwTOXIndex::operator<( const SwTOXSortTabBase& rCmpBase )
     312             : {
     313           0 :     SwTOXIndex& rCmp = (SwTOXIndex&)rCmpBase;
     314             : 
     315             :     OSL_ENSURE(pTxtMark, "pTxtMark == 0, No keyword");
     316             : 
     317           0 :     const TextAndReading aMyTaR(GetTxt());
     318           0 :     const TextAndReading aOtherTaR(rCmp.GetTxt());
     319             : 
     320           0 :     bool bRet = GetLevel() == rCmp.GetLevel() &&
     321           0 :                 pTOXIntl->IsLess( aMyTaR, GetLocale(),
     322           0 :                                   aOtherTaR, rCmp.GetLocale() );
     323             : 
     324             :     // If we don't summarize we need to evaluate the Pos
     325           0 :     if( !bRet && !(GetOptions() & nsSwTOIOptions::TOI_SAME_ENTRY) )
     326             :     {
     327           0 :         bRet = pTOXIntl->IsEqual( aMyTaR, GetLocale(),
     328           0 :                                   aOtherTaR, rCmp.GetLocale() ) &&
     329           0 :                nPos < rCmp.nPos;
     330             :     }
     331             : 
     332           0 :     return bRet;
     333             : }
     334             : 
     335             : // The keyword itself
     336             : 
     337           1 : TextAndReading SwTOXIndex::GetText_Impl() const
     338             : {
     339             :     OSL_ENSURE(pTxtMark, "pTxtMark == 0, No keyword");
     340           1 :     const SwTOXMark& rTOXMark = pTxtMark->GetTOXMark();
     341             : 
     342           1 :     TextAndReading aRet;
     343           1 :     switch(nKeyLevel)
     344             :     {
     345             :         case FORM_PRIMARY_KEY    :
     346             :         {
     347           0 :             aRet.sText = rTOXMark.GetPrimaryKey();
     348           0 :             aRet.sReading = rTOXMark.GetPrimaryKeyReading();
     349             :         }
     350           0 :         break;
     351             :         case FORM_SECONDARY_KEY  :
     352             :         {
     353           0 :             aRet.sText = rTOXMark.GetSecondaryKey();
     354           0 :             aRet.sReading = rTOXMark.GetSecondaryKeyReading();
     355             :         }
     356           0 :         break;
     357             :         case FORM_ENTRY          :
     358             :         {
     359           1 :             aRet.sText = rTOXMark.GetText();
     360           1 :             aRet.sReading = rTOXMark.GetTextReading();
     361             :         }
     362           1 :         break;
     363             :     }
     364             :     // if TOI_INITIAL_CAPS is set, first character is to be capitalized
     365           1 :     if( nsSwTOIOptions::TOI_INITIAL_CAPS & nOpt && pTOXIntl && !aRet.sText.isEmpty())
     366             :     {
     367           1 :         aRet.sText = pTOXIntl->ToUpper( aRet.sText, 0 ) + aRet.sText.copy(1);
     368             :     }
     369             : 
     370           1 :     return aRet;
     371             : }
     372             : 
     373           1 : void SwTOXIndex::FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
     374             : {
     375           1 :     const sal_Int32* pEnd = pTxtMark->End();
     376             : 
     377           1 :     TextAndReading aRet;
     378           2 :     if( pEnd && !pTxtMark->GetTOXMark().IsAlternativeText() &&
     379           1 :             0 == (GetOptions() & nsSwTOIOptions::TOI_KEY_AS_ENTRY))
     380             :     {
     381           0 :         aRet.sText = ((SwTxtNode*)aTOXSources[0].pNd)->GetExpandTxt(
     382           0 :                             *pTxtMark->GetStart(),
     383           0 :                             *pEnd - *pTxtMark->GetStart());
     384           0 :         if(nsSwTOIOptions::TOI_INITIAL_CAPS & nOpt && pTOXIntl && !aRet.sText.isEmpty())
     385             :         {
     386           0 :             aRet.sText = pTOXIntl->ToUpper( aRet.sText, 0 ) + aRet.sText.copy(1);
     387             :         }
     388             :     }
     389             :     else
     390           1 :         aRet = GetTxt();
     391             : 
     392           1 :     rNd.InsertText( aRet.sText, rInsPos );
     393           1 : }
     394             : 
     395           3 : sal_uInt16 SwTOXIndex::GetLevel() const
     396             : {
     397             :     OSL_ENSURE(pTxtMark, "pTxtMark == 0, No keyword");
     398             : 
     399           3 :     sal_uInt16 nForm = FORM_PRIMARY_KEY;
     400             : 
     401           9 :     if( 0 == (GetOptions() & nsSwTOIOptions::TOI_KEY_AS_ENTRY)&&
     402           3 :         !pTxtMark->GetTOXMark().GetPrimaryKey().isEmpty() )
     403             :     {
     404           0 :         nForm = FORM_SECONDARY_KEY;
     405           0 :         if( !pTxtMark->GetTOXMark().GetSecondaryKey().isEmpty() )
     406           0 :             nForm = FORM_ENTRY;
     407             :     }
     408           3 :     return nForm;
     409             : }
     410             : 
     411             : /*--------------------------------------------------------------------
     412             :   Key and separator
     413             :  --------------------------------------------------------------------*/
     414             : 
     415           0 : SwTOXCustom::SwTOXCustom(const TextAndReading& rKey,
     416             :                          sal_uInt16 nLevel,
     417             :                          const SwTOXInternational& rIntl,
     418             :                          const lang::Locale& rLocale )
     419             :     : SwTOXSortTabBase( TOX_SORT_CUSTOM, 0, 0, &rIntl, &rLocale ),
     420           0 :     m_aKey(rKey), nLev(nLevel)
     421             : {
     422           0 : }
     423             : 
     424           0 : bool SwTOXCustom::operator==(const SwTOXSortTabBase& rCmpBase)
     425             : {
     426           0 :     return GetLevel() == rCmpBase.GetLevel() &&
     427           0 :            pTOXIntl->IsEqual( GetTxt(), GetLocale(),
     428           0 :                               rCmpBase.GetTxt(), rCmpBase.GetLocale() );
     429             : }
     430             : 
     431           0 : bool SwTOXCustom::operator < (const SwTOXSortTabBase& rCmpBase)
     432             : {
     433           0 :     return  GetLevel() <= rCmpBase.GetLevel() &&
     434           0 :             pTOXIntl->IsLess( GetTxt(), GetLocale(),
     435           0 :                               rCmpBase.GetTxt(), rCmpBase.GetLocale() );
     436             : }
     437             : 
     438           0 : sal_uInt16 SwTOXCustom::GetLevel() const
     439             : {
     440           0 :     return nLev;
     441             : }
     442             : 
     443           0 : TextAndReading SwTOXCustom::GetText_Impl() const
     444             : {
     445           0 :     return m_aKey;
     446             : }
     447             : 
     448             : /*--------------------------------------------------------------------
     449             :    Sorts the TOX entries
     450             :  --------------------------------------------------------------------*/
     451             : 
     452           0 : SwTOXContent::SwTOXContent( const SwTxtNode& rNd, const SwTxtTOXMark* pMark,
     453             :                         const SwTOXInternational& rIntl)
     454           0 :     : SwTOXSortTabBase( TOX_SORT_CONTENT, &rNd, pMark, &rIntl )
     455             : {
     456           0 : }
     457             : 
     458             : // The content's text
     459             : 
     460           0 : TextAndReading SwTOXContent::GetText_Impl() const
     461             : {
     462           0 :     const sal_Int32* pEnd = pTxtMark->End();
     463           0 :     if( pEnd && !pTxtMark->GetTOXMark().IsAlternativeText() )
     464             :     {
     465             :         return TextAndReading(
     466           0 :             ((SwTxtNode*)aTOXSources[0].pNd)->GetExpandTxt(
     467           0 :                                      *pTxtMark->GetStart(),
     468           0 :                                      *pEnd - *pTxtMark->GetStart() ),
     469           0 :             pTxtMark->GetTOXMark().GetTextReading());
     470             :     }
     471             : 
     472           0 :     return TextAndReading(pTxtMark->GetTOXMark().GetAlternativeText(), OUString());
     473             : }
     474             : 
     475           0 : void SwTOXContent::FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
     476             : {
     477           0 :     const sal_Int32* pEnd = pTxtMark->End();
     478           0 :     if( pEnd && !pTxtMark->GetTOXMark().IsAlternativeText() )
     479           0 :         ((SwTxtNode*)aTOXSources[0].pNd)->GetExpandTxt( rNd, &rInsPos,
     480           0 :                                     *pTxtMark->GetStart(),
     481           0 :                                     *pEnd - *pTxtMark->GetStart() );
     482             :     else
     483             :     {
     484           0 :         rNd.InsertText( GetTxt().sText, rInsPos );
     485             :     }
     486           0 : }
     487             : 
     488             : // The level for displaying it
     489             : 
     490           0 : sal_uInt16 SwTOXContent::GetLevel() const
     491             : {
     492           0 :     return pTxtMark->GetTOXMark().GetLevel();
     493             : }
     494             : 
     495             : /*--------------------------------------------------------------------
     496             :    TOX assembled from paragraphs
     497             :    Watch out for OLE/graphics when sorting!
     498             :    The position must not come from the document, but from the "anchor"!
     499             :  --------------------------------------------------------------------*/
     500             : 
     501           3 : SwTOXPara::SwTOXPara( const SwCntntNode& rNd, SwTOXElement eT, sal_uInt16 nLevel, const OUString& sSeqName )
     502             :     : SwTOXSortTabBase( TOX_SORT_PARA, &rNd, 0, 0 ),
     503             :     eType( eT ),
     504             :     m_nLevel(nLevel),
     505             :     nStartIndex(0),
     506             :     nEndIndex(-1),
     507           3 :     m_sSequenceName( sSeqName )
     508             : {
     509           3 : }
     510             : 
     511           0 : TextAndReading SwTOXPara::GetText_Impl() const
     512             : {
     513           0 :     const SwCntntNode* pNd = aTOXSources[0].pNd;
     514           0 :     switch( eType )
     515             :     {
     516             :     case nsSwTOXElement::TOX_SEQUENCE:
     517             :     case nsSwTOXElement::TOX_TEMPLATE:
     518             :     case nsSwTOXElement::TOX_OUTLINELEVEL:
     519             :         {
     520             :             return TextAndReading(((SwTxtNode*)pNd)->GetExpandTxt(
     521             :                     nStartIndex,
     522           0 :                     nEndIndex == -1 ? -1 : nEndIndex - nStartIndex),
     523           0 :                     OUString());
     524             :         }
     525             :         break;
     526             : 
     527             :     case nsSwTOXElement::TOX_OLE:
     528             :     case nsSwTOXElement::TOX_GRAPHIC:
     529             :     case nsSwTOXElement::TOX_FRAME:
     530             :         {
     531             :             // Find the FlyFormat; the object/graphic name is there
     532           0 :             SwFrmFmt* pFly = pNd->GetFlyFmt();
     533           0 :             if( pFly )
     534           0 :                 return TextAndReading(pFly->GetName(), OUString());
     535             : 
     536             :             OSL_ENSURE( !this, "Graphic/object without name" );
     537           0 :             sal_uInt16 nId = nsSwTOXElement::TOX_OLE == eType
     538             :                             ? STR_OBJECT_DEFNAME
     539           0 :                             : nsSwTOXElement::TOX_GRAPHIC == eType
     540             :                                 ? STR_GRAPHIC_DEFNAME
     541           0 :                                 : STR_FRAME_DEFNAME;
     542           0 :             return TextAndReading(SW_RESSTR( nId ), OUString());
     543             :         }
     544             :         break;
     545           0 :     default: break;
     546             :     }
     547           0 :     return TextAndReading();
     548             : }
     549             : 
     550           3 : void SwTOXPara::FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
     551             : {
     552           3 :     if( nsSwTOXElement::TOX_TEMPLATE == eType || nsSwTOXElement::TOX_SEQUENCE == eType  || nsSwTOXElement::TOX_OUTLINELEVEL == eType)
     553             :     {
     554           3 :         SwTxtNode* pSrc = (SwTxtNode*)aTOXSources[0].pNd;
     555             :         pSrc->GetExpandTxt( rNd, &rInsPos, nStartIndex,
     556           3 :                 nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
     557           3 :                 false, false, true );
     558             :     }
     559             :     else
     560             :     {
     561           0 :         rNd.InsertText( GetTxt().sText.replace('\t', ' '), rInsPos );
     562             :     }
     563           3 : }
     564             : 
     565           6 : sal_uInt16 SwTOXPara::GetLevel() const
     566             : {
     567           6 :     sal_uInt16 nRet = m_nLevel;
     568           6 :     const SwCntntNode*  pNd = aTOXSources[0].pNd;
     569             : 
     570           6 :     if( nsSwTOXElement::TOX_OUTLINELEVEL == eType && pNd->GetTxtNode() )
     571             :     {
     572           6 :         const int nTmp = ((SwTxtNode*)pNd)->GetAttrOutlineLevel();
     573           6 :         if(nTmp != 0 )
     574           6 :             nRet = static_cast<sal_uInt16>(nTmp);
     575             :     }
     576           6 :     return nRet;
     577             : }
     578             : 
     579           3 : OUString SwTOXPara::GetURL() const
     580             : {
     581           3 :     OUString aTxt;
     582           3 :     const SwCntntNode* pNd = aTOXSources[0].pNd;
     583           3 :     switch( eType )
     584             :     {
     585             :     case nsSwTOXElement::TOX_TEMPLATE:
     586             :     case nsSwTOXElement::TOX_OUTLINELEVEL:
     587             :         {
     588           3 :             const SwTxtNode * pTxtNd = static_cast<const SwTxtNode *>(pNd);
     589             : 
     590           3 :             SwDoc* pDoc = const_cast<SwDoc*>( pTxtNd->GetDoc() );
     591           3 :             ::sw::mark::IMark const * const pMark = pDoc->getIDocumentMarkAccess()->getMarkForTxtNode(
     592             :                                 *(pTxtNd),
     593           3 :                                 IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK);
     594           3 :             aTxt = "#" + pMark->GetName();
     595             :         }
     596           3 :         break;
     597             : 
     598             :     case nsSwTOXElement::TOX_OLE:
     599             :     case nsSwTOXElement::TOX_GRAPHIC:
     600             :     case nsSwTOXElement::TOX_FRAME:
     601             :         {
     602             :             // Find the FlyFormat; the object/graphic name is there
     603           0 :             SwFrmFmt* pFly = pNd->GetFlyFmt();
     604           0 :             if( pFly )
     605             :             {
     606           0 :                 aTxt = "#" + pFly->GetName() + OUString(cMarkSeparator);
     607             :                 const sal_Char* pStr;
     608           0 :                 switch( eType )
     609             :                 {
     610           0 :                 case nsSwTOXElement::TOX_OLE:       pStr = "ole"; break;
     611           0 :                 case nsSwTOXElement::TOX_GRAPHIC:   pStr = "graphic"; break;
     612           0 :                 case nsSwTOXElement::TOX_FRAME:     pStr = "frame"; break;
     613           0 :                 default:            pStr = 0;
     614             :                 }
     615           0 :                 if( pStr )
     616           0 :                     aTxt += OUString::createFromAscii( pStr );
     617             :             }
     618             :         }
     619           0 :         break;
     620             :     case nsSwTOXElement::TOX_SEQUENCE:
     621             :         {
     622           0 :             aTxt = "#" + m_sSequenceName + OUString(cMarkSeparator)
     623           0 :                  + "sequence";
     624             :         }
     625           0 :         break;
     626           0 :     default: break;
     627             :     }
     628           3 :     return aTxt;
     629             : }
     630             : 
     631             : /*--------------------------------------------------------------------
     632             :   Table
     633             :  --------------------------------------------------------------------*/
     634             : 
     635           0 : SwTOXTable::SwTOXTable( const SwCntntNode& rNd )
     636             :     : SwTOXSortTabBase( TOX_SORT_TABLE, &rNd, 0, 0 ),
     637           0 :     nLevel(FORM_ALPHA_DELIMITTER)
     638             : {
     639           0 : }
     640             : 
     641           0 : TextAndReading SwTOXTable::GetText_Impl() const
     642             : {
     643           0 :     const SwNode* pNd = aTOXSources[0].pNd;
     644           0 :     if( pNd )
     645             :     {
     646             :         const SwTableNode* pTableNd =
     647           0 :             reinterpret_cast<const SwTableNode*>(pNd->FindTableNode());
     648           0 :         if (pTableNd)
     649             :         {
     650           0 :             return TextAndReading(pTableNd->GetTable().GetFrmFmt()->GetName(), OUString());
     651             :         }
     652             :     }
     653             : 
     654             :     OSL_ENSURE( !this, "Where's my table?" );
     655           0 :     return TextAndReading(SW_RESSTR( STR_TABLE_DEFNAME ), OUString());
     656             : }
     657             : 
     658           0 : sal_uInt16 SwTOXTable::GetLevel() const
     659             : {
     660           0 :     return nLevel;
     661             : }
     662             : 
     663           0 : OUString SwTOXTable::GetURL() const
     664             : {
     665           0 :     const SwNode* pNd = aTOXSources[0].pNd;
     666           0 :     if (!pNd)
     667           0 :         return OUString();
     668             : 
     669           0 :     pNd = pNd->FindTableNode();
     670           0 :     if (!pNd)
     671           0 :         return OUString();
     672             : 
     673           0 :     const OUString sName = ((SwTableNode*)pNd)->GetTable().GetFrmFmt()->GetName();
     674           0 :     if ( sName.isEmpty() )
     675           0 :         return OUString();
     676             : 
     677           0 :     return "#" + sName + OUString(cMarkSeparator) + "table";
     678             : }
     679             : 
     680           0 : SwTOXAuthority::SwTOXAuthority( const SwCntntNode& rNd,
     681             :                 SwFmtFld& rField, const SwTOXInternational& rIntl ) :
     682             :     SwTOXSortTabBase( TOX_SORT_AUTHORITY, &rNd, 0, &rIntl ),
     683           0 :     m_rField(rField)
     684             : {
     685           0 :     if(rField.GetTxtFld())
     686           0 :         nCntPos = *rField.GetTxtFld()->GetStart();
     687           0 : }
     688             : 
     689           0 : sal_uInt16 SwTOXAuthority::GetLevel() const
     690             : {
     691           0 :     OUString sText(((SwAuthorityField*)m_rField.GetField())->GetFieldText(AUTH_FIELD_AUTHORITY_TYPE));
     692             :     //#i18655# the level '0' is the heading level therefor the values are incremented here
     693           0 :     sal_uInt16 nRet = 1;
     694           0 :     if( pTOXIntl->IsNumeric( sText ) )
     695             :     {
     696           0 :         nRet = (sal_uInt16)sText.toInt32();
     697           0 :         nRet++;
     698             :     }
     699             :     //illegal values are also set to 'ARTICLE' as non-numeric values are
     700           0 :     if(nRet > AUTH_TYPE_END)
     701           0 :         nRet = 1;
     702           0 :     return nRet;
     703             : }
     704             : 
     705           0 : static OUString lcl_GetText(SwFmtFld const& rField)
     706             : {
     707           0 :     return rField.GetField()->ExpandField(true);
     708             : }
     709             : 
     710           0 : TextAndReading SwTOXAuthority::GetText_Impl() const
     711             : {
     712           0 :     return TextAndReading(lcl_GetText(m_rField), OUString());
     713             : }
     714             : 
     715           0 : void    SwTOXAuthority::FillText( SwTxtNode& rNd,
     716             :                         const SwIndex& rInsPos, sal_uInt16 nAuthField ) const
     717             : {
     718           0 :     SwAuthorityField* pField = (SwAuthorityField*)m_rField.GetField();
     719           0 :     OUString sText;
     720           0 :     if(AUTH_FIELD_IDENTIFIER == nAuthField)
     721             :     {
     722           0 :         sText = lcl_GetText(m_rField);
     723           0 :         const SwAuthorityFieldType* pType = (const SwAuthorityFieldType*)pField->GetTyp();
     724           0 :         sal_Unicode cChar = pType->GetPrefix();
     725           0 :         if(cChar && cChar != ' ')
     726           0 :             sText = sText.copy(1);
     727           0 :         cChar = pType->GetSuffix();
     728           0 :         if(cChar && cChar != ' ')
     729           0 :             sText = sText.copy(0, sText.getLength() - 1);
     730             :     }
     731           0 :     else if(AUTH_FIELD_AUTHORITY_TYPE == nAuthField)
     732             :     {
     733           0 :         sal_uInt16 nLevel = GetLevel();
     734           0 :         if(nLevel)
     735           0 :             sText = SwAuthorityFieldType::GetAuthTypeName((ToxAuthorityType) --nLevel);
     736             :     }
     737             :     else
     738           0 :         sText = (pField->GetFieldText((ToxAuthorityField) nAuthField));
     739           0 :     rNd.InsertText( sText, rInsPos );
     740           0 : }
     741             : 
     742           0 : bool    SwTOXAuthority::operator==( const SwTOXSortTabBase& rCmp)
     743             : {
     744           0 :     return nType == rCmp.nType &&
     745           0 :             ((SwAuthorityField*)m_rField.GetField())->GetHandle() ==
     746           0 :                 ((SwAuthorityField*)((SwTOXAuthority&)rCmp).m_rField.GetField())->GetHandle();
     747             : }
     748             : 
     749           0 : bool    SwTOXAuthority::operator<( const SwTOXSortTabBase& rBase)
     750             : {
     751           0 :     bool bRet = false;
     752           0 :     SwAuthorityField* pField = (SwAuthorityField*)m_rField.GetField();
     753             :     SwAuthorityFieldType* pType = (SwAuthorityFieldType*)
     754           0 :                                                 pField->GetTyp();
     755           0 :     if(pType->IsSortByDocument())
     756           0 :         bRet = SwTOXSortTabBase::operator<(rBase);
     757             :     else
     758             :     {
     759             :         SwAuthorityField* pCmpField =
     760           0 :             (SwAuthorityField*)((SwTOXAuthority&)rBase).m_rField.GetField();
     761             : 
     762           0 :         for(sal_uInt16 i = 0; i < pType->GetSortKeyCount(); i++)
     763             :         {
     764           0 :             const SwTOXSortKey* pKey = pType->GetSortKey(i);
     765           0 :             const TextAndReading aMy(pField->GetFieldText(pKey->eField), OUString());
     766           0 :             const TextAndReading aOther(pCmpField->GetFieldText(pKey->eField), OUString());
     767             : 
     768           0 :             sal_Int32 nComp = pTOXIntl->Compare( aMy, GetLocale(),
     769           0 :                                                  aOther, rBase.GetLocale() );
     770             : 
     771           0 :             if( nComp )
     772             :             {
     773           0 :                 bRet = (-1 == nComp) == pKey->bSortAscending;
     774           0 :                 break;
     775             :             }
     776           0 :         }
     777             :     }
     778           0 :     return bRet;
     779             : }
     780             : 
     781             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10