Files
libreoffice/sw/source/core/doc/ftnidx.cxx

337 lines
11 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 23:08:29 +00:00
#include <txtftn.hxx>
#include <fmtftn.hxx>
#include <ftninfo.hxx>
#include <doc.hxx>
#include <ftnidx.hxx>
#include <ndtxt.hxx>
#include <ndindex.hxx>
#include <section.hxx>
#include <fmtftntx.hxx>
#include <rootfrm.hxx>
bool CompareSwFtnIdxs::operator()(SwTxtFtn* const& lhs, SwTxtFtn* const& rhs) const
{
sal_uLong nIdxLHS = _SwTxtFtn_GetIndex( lhs );
sal_uLong nIdxRHS = _SwTxtFtn_GetIndex( rhs );
return ( nIdxLHS == nIdxRHS && *lhs->GetStart() < *rhs->GetStart() ) || nIdxLHS < nIdxRHS;
2000-09-18 23:08:29 +00:00
}
2001-10-18 14:41:49 +00:00
void SwFtnIdxs::UpdateFtn( const SwNodeIndex& rStt )
2000-09-18 23:08:29 +00:00
{
if( empty() )
2000-09-18 23:08:29 +00:00
return;
2012-01-20 13:16:01 +01:00
// Get the NodesArray using the first foot note's StartIndex
2000-09-18 23:08:29 +00:00
SwDoc* pDoc = rStt.GetNode().GetDoc();
if( pDoc->IsInReading() )
return ;
SwTxtFtn* pTxtFtn;
const SwEndNoteInfo& rEndInfo = pDoc->GetEndNoteInfo();
const SwFtnInfo& rFtnInfo = pDoc->GetFtnInfo();
2012-01-20 21:43:05 +01:00
// For normal foot notes we treat per-chapter and per-document numbering
// separately. For Endnotes we only have per-document numbering.
2000-09-18 23:08:29 +00:00
if( FTNNUM_CHAPTER == rFtnInfo.eNum )
{
const SwOutlineNodes& rOutlNds = pDoc->GetNodes().GetOutLineNds();
const SwNode* pCapStt = &pDoc->GetNodes().GetEndOfExtras();
sal_uLong nCapEnd = pDoc->GetNodes().GetEndOfContent().GetIndex();
if( !rOutlNds.empty() )
2000-09-18 23:08:29 +00:00
{
2012-01-20 13:16:01 +01:00
// Find the Chapter's start, which contains rStt
sal_uInt16 n;
for( n = 0; n < rOutlNds.size(); ++n )
2000-09-18 23:08:29 +00:00
if( rOutlNds[ n ]->GetIndex() > rStt.GetIndex() )
2012-01-20 13:16:01 +01:00
break; // found it!
else if ( rOutlNds[ n ]->GetTxtNode()->GetAttrOutlineLevel() == 1 )
2012-01-20 13:16:01 +01:00
pCapStt = rOutlNds[ n ]; // Beginning of a new Chapter
// now find the end of the range
for( ; n < rOutlNds.size(); ++n )
if ( rOutlNds[ n ]->GetTxtNode()->GetAttrOutlineLevel() == 1 )
2000-09-18 23:08:29 +00:00
{
2012-01-20 13:16:01 +01:00
nCapEnd = rOutlNds[ n ]->GetIndex(); // End of the found Chapter
2000-09-18 23:08:29 +00:00
break;
}
}
sal_uInt16 nPos, nFtnNo = 1;
2000-09-18 23:08:29 +00:00
if( SeekEntry( *pCapStt, &nPos ) && nPos )
{
2012-01-20 13:16:01 +01:00
// Step forward until the Index is not the same anymore
2000-09-18 23:08:29 +00:00
const SwNode* pCmpNd = &rStt.GetNode();
while( nPos && pCmpNd == &((*this)[ --nPos ]->GetTxtNode()) )
;
++nPos;
}
if( nPos == size() ) // nothing found
2000-09-18 23:08:29 +00:00
return;
if( rOutlNds.empty() )
2000-09-18 23:08:29 +00:00
nFtnNo = nPos+1;
for( ; nPos < size(); ++nPos )
2000-09-18 23:08:29 +00:00
{
pTxtFtn = (*this)[ nPos ];
if( pTxtFtn->GetTxtNode().GetIndex() >= nCapEnd )
break;
const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
if( rFtn.GetNumStr().isEmpty() && !rFtn.IsEndNote() &&
2000-09-18 23:08:29 +00:00
!SwUpdFtnEndNtAtEnd::FindSectNdWithEndAttr( *pTxtFtn ))
{
pTxtFtn->SetNumber( rFtnInfo.nFtnOffset + nFtnNo++, rFtn.GetNumStr() );
}
2000-09-18 23:08:29 +00:00
}
}
SwUpdFtnEndNtAtEnd aNumArr;
2012-01-20 21:43:05 +01:00
// unless we have per-document numbering, only look at endnotes here
const bool bEndNoteOnly = FTNNUM_DOC != rFtnInfo.eNum;
2000-09-18 23:08:29 +00:00
sal_uInt16 nPos, nFtnNo = 1, nEndNo = 1;
sal_uLong nUpdNdIdx = rStt.GetIndex();
for( nPos = 0; nPos < size(); ++nPos )
2000-09-18 23:08:29 +00:00
{
pTxtFtn = (*this)[ nPos ];
if( nUpdNdIdx <= pTxtFtn->GetTxtNode().GetIndex() )
break;
const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
if( rFtn.GetNumStr().isEmpty() )
2000-09-18 23:08:29 +00:00
{
if( !aNumArr.ChkNumber( *pTxtFtn ) )
{
if( pTxtFtn->GetFtn().IsEndNote() )
nEndNo++;
else
nFtnNo++;
}
}
}
2012-01-20 13:16:01 +01:00
// Set the array number for all footnotes starting from nPos
for( ; nPos < size(); ++nPos )
2000-09-18 23:08:29 +00:00
{
pTxtFtn = (*this)[ nPos ];
const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
if( rFtn.GetNumStr().isEmpty() )
2000-09-18 23:08:29 +00:00
{
sal_uInt16 nSectNo = aNumArr.ChkNumber( *pTxtFtn );
2000-09-18 23:08:29 +00:00
if( !nSectNo && ( rFtn.IsEndNote() || !bEndNoteOnly ))
nSectNo = rFtn.IsEndNote()
? rEndInfo.nFtnOffset + nEndNo++
: rFtnInfo.nFtnOffset + nFtnNo++;
if( nSectNo )
{
pTxtFtn->SetNumber( nSectNo, rFtn.GetNumStr() );
2000-09-18 23:08:29 +00:00
}
}
}
}
void SwFtnIdxs::UpdateAllFtn()
{
if( empty() )
2000-09-18 23:08:29 +00:00
return;
2012-02-15 13:19:06 +01:00
// Get the NodesArray via the StartIndex of the first Footnote
2000-09-18 23:08:29 +00:00
SwDoc* pDoc = (SwDoc*) (*this)[ 0 ]->GetTxtNode().GetDoc();
SwTxtFtn* pTxtFtn;
const SwEndNoteInfo& rEndInfo = pDoc->GetEndNoteInfo();
const SwFtnInfo& rFtnInfo = pDoc->GetFtnInfo();
SwUpdFtnEndNtAtEnd aNumArr;
SwRootFrm* pTmpRoot = pDoc->GetCurrentLayout();
std::set<SwRootFrm*> aAllLayouts = pDoc->GetAllLayouts();
2012-02-15 13:19:06 +01:00
// For normal Footnotes per-chapter and per-document numbering are treated separately.
// For Endnotes we only have document-wise numbering.
2000-09-18 23:08:29 +00:00
if( FTNNUM_CHAPTER == rFtnInfo.eNum )
{
const SwOutlineNodes& rOutlNds = pDoc->GetNodes().GetOutLineNds();
2012-02-15 13:19:06 +01:00
sal_uInt16 nNo = 1, // Number for the Footnotes
nFtnIdx = 0; // Index into theFtnIdx array
for( sal_uInt16 n = 0; n < rOutlNds.size(); ++n )
2000-09-18 23:08:29 +00:00
{
if ( rOutlNds[ n ]->GetTxtNode()->GetAttrOutlineLevel() == 1 )
2000-09-18 23:08:29 +00:00
{
2012-02-15 13:19:06 +01:00
sal_uLong nCapStt = rOutlNds[ n ]->GetIndex(); // Start of a new chapter
for( ; nFtnIdx < size(); ++nFtnIdx )
2000-09-18 23:08:29 +00:00
{
pTxtFtn = (*this)[ nFtnIdx ];
if( pTxtFtn->GetTxtNode().GetIndex() >= nCapStt )
break;
2012-02-15 13:19:06 +01:00
// Endnotes are per-document only
2000-09-18 23:08:29 +00:00
const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
if( !rFtn.IsEndNote() && rFtn.GetNumStr().isEmpty() &&
2000-09-18 23:08:29 +00:00
!SwUpdFtnEndNtAtEnd::FindSectNdWithEndAttr( *pTxtFtn ))
{
pTxtFtn->SetNumber( rFtnInfo.nFtnOffset + nNo++, rFtn.GetNumStr() );
}
2000-09-18 23:08:29 +00:00
}
if( nFtnIdx >= size() )
2012-02-15 13:19:06 +01:00
break; // ok, everything is updated
2000-09-18 23:08:29 +00:00
nNo = 1;
}
}
for( nNo = 1; nFtnIdx < size(); ++nFtnIdx )
2000-09-18 23:08:29 +00:00
{
2012-02-15 13:19:06 +01:00
// Endnotes are per-document
2000-09-18 23:08:29 +00:00
pTxtFtn = (*this)[ nFtnIdx ];
const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
if( !rFtn.IsEndNote() && rFtn.GetNumStr().isEmpty() &&
2000-09-18 23:08:29 +00:00
!SwUpdFtnEndNtAtEnd::FindSectNdWithEndAttr( *pTxtFtn ))
{
pTxtFtn->SetNumber( rFtnInfo.nFtnOffset + nNo++, rFtn.GetNumStr() );
}
2000-09-18 23:08:29 +00:00
}
}
// We use bool here, so that we also iterate through the Endnotes with a chapter setting.
const bool bEndNoteOnly = FTNNUM_DOC != rFtnInfo.eNum;
sal_uInt16 nFtnNo = 0, nEndNo = 0;
for( sal_uInt16 nPos = 0; nPos < size(); ++nPos )
2000-09-18 23:08:29 +00:00
{
pTxtFtn = (*this)[ nPos ];
const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
if( rFtn.GetNumStr().isEmpty() )
2000-09-18 23:08:29 +00:00
{
sal_uInt16 nSectNo = aNumArr.ChkNumber( *pTxtFtn );
2000-09-18 23:08:29 +00:00
if( !nSectNo && ( rFtn.IsEndNote() || !bEndNoteOnly ))
nSectNo = rFtn.IsEndNote()
? rEndInfo.nFtnOffset + (++nEndNo)
: rFtnInfo.nFtnOffset + (++nFtnNo);
if( nSectNo )
{
pTxtFtn->SetNumber( nSectNo, rFtn.GetNumStr() );
2000-09-18 23:08:29 +00:00
}
}
}
if( pTmpRoot && FTNNUM_PAGE == rFtnInfo.eNum )
std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::UpdateFtnNums));
2000-09-18 23:08:29 +00:00
}
SwTxtFtn* SwFtnIdxs::SeekEntry( const SwNodeIndex& rPos, sal_uInt16* pFndPos ) const
2000-09-18 23:08:29 +00:00
{
sal_uLong nIdx = rPos.GetIndex();
2000-09-18 23:08:29 +00:00
sal_uInt16 nO = size(), nM, nU = 0;
2000-09-18 23:08:29 +00:00
if( nO > 0 )
{
nO--;
while( nU <= nO )
{
nM = nU + ( nO - nU ) / 2;
sal_uLong nNdIdx = _SwTxtFtn_GetIndex( (*this)[ nM ] );
2000-09-18 23:08:29 +00:00
if( nNdIdx == nIdx )
{
if( pFndPos )
*pFndPos = nM;
return (*this)[ nM ];
}
else if( nNdIdx < nIdx )
nU = nM + 1;
else if( nM == 0 )
{
if( pFndPos )
*pFndPos = nU;
return 0;
}
else
nO = nM - 1;
}
}
if( pFndPos )
*pFndPos = nU;
return 0;
}
const SwSectionNode* SwUpdFtnEndNtAtEnd::FindSectNdWithEndAttr(
const SwTxtFtn& rTxtFtn )
{
sal_uInt16 nWh = static_cast<sal_uInt16>( rTxtFtn.GetFtn().IsEndNote() ?
RES_END_AT_TXTEND : RES_FTN_AT_TXTEND );
sal_uInt16 nVal;
2000-09-18 23:08:29 +00:00
const SwSectionNode* pNd = rTxtFtn.GetTxtNode().FindSectionNode();
while( pNd && FTNEND_ATTXTEND_OWNNUMSEQ != ( nVal =
((const SwFmtFtnAtTxtEnd&)pNd->GetSection().GetFmt()->
GetFmtAttr( nWh, sal_True )).GetValue() ) &&
2000-09-18 23:08:29 +00:00
FTNEND_ATTXTEND_OWNNUMANDFMT != nVal )
pNd = pNd->StartOfSectionNode()->FindSectionNode();
2000-09-18 23:08:29 +00:00
return pNd;
}
sal_uInt16 SwUpdFtnEndNtAtEnd::GetNumber( const SwTxtFtn& rTxtFtn,
2000-09-18 23:08:29 +00:00
const SwSectionNode& rNd )
{
sal_uInt16 nRet = 0, nWh;
std::vector<const SwSectionNode*>* pArr;
std::vector<sal_uInt16> *pNum;
2000-09-18 23:08:29 +00:00
if( rTxtFtn.GetFtn().IsEndNote() )
{
pArr = &aEndSects;
pNum = &aEndNums;
nWh = RES_END_AT_TXTEND;
}
else
{
pArr = &aFtnSects;
pNum = &aFtnNums;
nWh = RES_FTN_AT_TXTEND;
}
for( sal_uInt16 n = pArr->size(); n; )
if( (*pArr)[ --n ] == &rNd )
2000-09-18 23:08:29 +00:00
{
nRet = ++((*pNum)[ n ]);
2000-09-18 23:08:29 +00:00
break;
}
if( !nRet )
{
pArr->push_back( &rNd );
2000-09-18 23:08:29 +00:00
nRet = ((SwFmtFtnEndAtTxtEnd&)rNd.GetSection().GetFmt()->
GetFmtAttr( nWh )).GetOffset();
2000-09-18 23:08:29 +00:00
++nRet;
pNum->push_back( nRet );
2000-09-18 23:08:29 +00:00
}
return nRet;
}
sal_uInt16 SwUpdFtnEndNtAtEnd::ChkNumber( const SwTxtFtn& rTxtFtn )
2000-09-18 23:08:29 +00:00
{
const SwSectionNode* pSectNd = FindSectNdWithEndAttr( rTxtFtn );
return pSectNd ? GetNumber( rTxtFtn, *pSectNd ) : 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */