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 <libxml/xmlwriter.h>
21 
22 #include <editeng/pbinitem.hxx>
23 #include <editeng/ulspitem.hxx>
24 #include <editeng/boxitem.hxx>
25 #include <editeng/brushitem.hxx>
26 #include <editeng/shaditem.hxx>
27 #include <editeng/frmdiritem.hxx>
28 #include <sal/log.hxx>
29 #include <fmtclds.hxx>
30 #include <fmtfsize.hxx>
31 #include <pagefrm.hxx>
32 #include <pagedesc.hxx>
33 #include <swtable.hxx>
34 #include <frmatr.hxx>
35 #include <frmtool.hxx>
36 #include <doc.hxx>
37 #include <node.hxx>
38 #include <strings.hrc>
39 #include <IDocumentLayoutAccess.hxx>
40 #include <IDocumentStylePoolAccess.hxx>
41 #include <poolfmt.hxx>
42 #include <calbck.hxx>
43 #include <hints.hxx>
44 
SwPageDesc(const OUString & rName,SwFrameFormat * pFormat,SwDoc * const pDoc)45 SwPageDesc::SwPageDesc(const OUString& rName, SwFrameFormat *pFormat, SwDoc *const pDoc)
46     : SwModify()
47     , m_StyleName( rName )
48     , m_Master( pDoc->GetAttrPool(), rName, pFormat )
49     , m_Left( pDoc->GetAttrPool(), rName, pFormat )
50     , m_FirstMaster( pDoc->GetAttrPool(), rName, pFormat )
51     , m_FirstLeft( pDoc->GetAttrPool(), rName, pFormat )
52     , m_aDepends(*this)
53     , m_pTextFormatColl(nullptr)
54     , m_pFollow( this )
55     , m_nRegHeight( 0 )
56     , m_nRegAscent( 0 )
57     , m_nVerticalAdjustment( drawing::TextVerticalAdjust_TOP )
58     , m_eUse( UseOnPage::All | UseOnPage::HeaderShare | UseOnPage::FooterShare | UseOnPage::FirstShare )
59     , m_IsLandscape( false )
60     , m_IsHidden( false )
61     , m_pdList( nullptr )
62 {
63 }
64 
SwPageDesc(const SwPageDesc & rCpy)65 SwPageDesc::SwPageDesc( const SwPageDesc &rCpy )
66     : SwModify()
67     , BroadcasterMixin()
68     , m_StyleName( rCpy.GetName() )
69     , m_NumType( rCpy.GetNumType() )
70     , m_Master( rCpy.GetMaster() )
71     , m_Left( rCpy.GetLeft() )
72     , m_FirstMaster( rCpy.GetFirstMaster() )
73     , m_FirstLeft( rCpy.GetFirstLeft() )
74     , m_aDepends(*this)
75     , m_pTextFormatColl(nullptr)
76     , m_pFollow( rCpy.m_pFollow )
77     , m_nRegHeight( rCpy.GetRegHeight() )
78     , m_nRegAscent( rCpy.GetRegAscent() )
79     , m_nVerticalAdjustment( rCpy.GetVerticalAdjustment() )
80     , m_eUse( rCpy.ReadUseOn() )
81     , m_IsLandscape( rCpy.GetLandscape() )
82     , m_IsHidden( rCpy.IsHidden() )
83     , m_IsFootnoteInfo( rCpy.GetFootnoteInfo() )
84     , m_pdList( nullptr )
85 {
86     if (rCpy.m_pTextFormatColl && rCpy.m_aDepends.IsListeningTo(rCpy.m_pTextFormatColl))
87     {
88         m_pTextFormatColl = rCpy.m_pTextFormatColl;
89         m_aDepends.StartListening(const_cast<SwTextFormatColl*>(m_pTextFormatColl));
90     }
91 }
92 
operator =(const SwPageDesc & rSrc)93 SwPageDesc & SwPageDesc::operator = (const SwPageDesc & rSrc)
94 {
95     if(this == &rSrc)
96         return *this;
97 
98     m_StyleName = rSrc.m_StyleName;
99     m_NumType = rSrc.m_NumType;
100     m_Master = rSrc.m_Master;
101     m_Left = rSrc.m_Left;
102     m_FirstMaster = rSrc.m_FirstMaster;
103     m_FirstLeft = rSrc.m_FirstLeft;
104     m_aDepends.EndListeningAll();
105     if (rSrc.m_pTextFormatColl && rSrc.m_aDepends.IsListeningTo(rSrc.m_pTextFormatColl))
106     {
107         m_pTextFormatColl = rSrc.m_pTextFormatColl;
108         m_aDepends.StartListening(const_cast<SwTextFormatColl*>(m_pTextFormatColl));
109     }
110     else
111         m_pTextFormatColl = nullptr;
112 
113     if (rSrc.m_pFollow == &rSrc)
114         m_pFollow = this;
115     else
116         m_pFollow = rSrc.m_pFollow;
117 
118     m_nRegHeight = rSrc.m_nRegHeight;
119     m_nRegAscent = rSrc.m_nRegAscent;
120     m_nVerticalAdjustment = rSrc.m_nVerticalAdjustment;
121     m_eUse = rSrc.m_eUse;
122     m_IsLandscape = rSrc.m_IsLandscape;
123     return *this;
124 }
125 
~SwPageDesc()126 SwPageDesc::~SwPageDesc()
127 {
128 }
129 
SetName(const OUString & rNewName)130 bool SwPageDesc::SetName( const OUString& rNewName )
131 {
132     bool renamed = true;
133     if (m_pdList) {
134         SwPageDescs::iterator it = m_pdList->find_( m_StyleName );
135         if( m_pdList->end() == it ) {
136             SAL_WARN( "sw", "SwPageDesc not found in expected m_pdList" );
137             return false;
138         }
139         renamed = m_pdList->m_PosIndex.modify( it,
140             change_name( rNewName ), change_name( m_StyleName ) );
141     }
142     else
143         m_StyleName = rNewName;
144     return renamed;
145 }
146 
147 /// Only the margin is mirrored.
148 /// Attributes like borders and so on are copied 1:1.
Mirror()149 void SwPageDesc::Mirror()
150 {
151     //Only the margins are mirrored, all other values are just copied.
152     SvxLRSpaceItem aLR( RES_LR_SPACE );
153     const SvxLRSpaceItem &rLR = m_Master.GetLRSpace();
154     aLR.SetLeft(  rLR.GetRight() );
155     aLR.SetRight( rLR.GetLeft() );
156 
157     SfxItemSet aSet( *m_Master.GetAttrSet().GetPool(),
158                      m_Master.GetAttrSet().GetRanges() );
159     aSet.Put( aLR );
160     aSet.Put( m_Master.GetFrameSize() );
161     aSet.Put( m_Master.GetPaperBin() );
162     aSet.Put( m_Master.GetULSpace() );
163     aSet.Put( m_Master.GetBox() );
164     aSet.Put( *m_Master.makeBackgroundBrushItem() );
165     aSet.Put( m_Master.GetShadow() );
166     aSet.Put( m_Master.GetCol() );
167     aSet.Put( m_Master.GetFrameDir() );
168     m_Left.SetFormatAttr( aSet );
169 }
170 
ResetAllAttr()171 void SwPageDesc::ResetAllAttr()
172 {
173     SwFrameFormat& rFormat = GetMaster();
174 
175     // #i73790# - method renamed
176     rFormat.ResetAllFormatAttr();
177     rFormat.SetFormatAttr( SvxFrameDirectionItem(SvxFrameDirection::Horizontal_LR_TB, RES_FRAMEDIR) );
178 }
179 
180 // gets information from Modify
GetInfo(SfxPoolItem & rInfo) const181 bool SwPageDesc::GetInfo( SfxPoolItem & rInfo ) const
182 {
183     if (!m_Master.GetInfo(rInfo))
184         return false;       // found
185     if (!m_Left.GetInfo(rInfo))
186         return false ;
187     if ( !m_FirstMaster.GetInfo( rInfo ) )
188         return false;
189     return m_FirstLeft.GetInfo( rInfo );
190 }
191 
192 /// set the style for the grid alignment
SetRegisterFormatColl(const SwTextFormatColl * pFormat)193 void SwPageDesc::SetRegisterFormatColl(const SwTextFormatColl* pFormat)
194 {
195     if(pFormat != m_pTextFormatColl)
196     {
197         m_aDepends.EndListeningAll();
198         m_pTextFormatColl = pFormat;
199         m_aDepends.StartListening(const_cast<SwTextFormatColl*>(m_pTextFormatColl));
200         RegisterChange();
201     }
202 }
203 
204 /// retrieve the style for the grid alignment
GetRegisterFormatColl() const205 const SwTextFormatColl* SwPageDesc::GetRegisterFormatColl() const
206 {
207     if (!m_aDepends.IsListeningTo(m_pTextFormatColl))
208         m_pTextFormatColl = nullptr;
209     return m_pTextFormatColl;
210 }
211 
212 /// notify all affected page frames
RegisterChange()213 void SwPageDesc::RegisterChange()
214 {
215     // #117072# - During destruction of the document <SwDoc>
216     // the page description is modified. Thus, do nothing, if the document
217     // is in destruction respectively if no viewshell exists.
218     SwDoc* pDoc = GetMaster().GetDoc();
219     if ( !pDoc || pDoc->IsInDtor() )
220     {
221         return;
222     }
223     SwViewShell* pSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
224     if ( !pSh )
225     {
226         return;
227     }
228 
229     m_nRegHeight = 0;
230     {
231         SwIterator<SwFrame,SwFormat> aIter( GetMaster() );
232         for( SwFrame* pLast = aIter.First(); pLast; pLast = aIter.Next() )
233         {
234             if( pLast->IsPageFrame() )
235                 static_cast<SwPageFrame*>(pLast)->PrepareRegisterChg();
236         }
237     }
238     {
239         SwIterator<SwFrame,SwFormat> aIter( GetLeft() );
240         for( SwFrame* pLast = aIter.First(); pLast; pLast = aIter.Next() )
241         {
242             if( pLast->IsPageFrame() )
243                 static_cast<SwPageFrame*>(pLast)->PrepareRegisterChg();
244         }
245     }
246     {
247         SwIterator<SwFrame,SwFormat> aIter( GetFirstMaster() );
248         for( SwFrame* pLast = aIter.First(); pLast; pLast = aIter.Next() )
249         {
250             if( pLast->IsPageFrame() )
251                 static_cast<SwPageFrame*>(pLast)->PrepareRegisterChg();
252         }
253     }
254     {
255         SwIterator<SwFrame,SwFormat> aIter( GetFirstLeft() );
256         for( SwFrame* pLast = aIter.First(); pLast; pLast = aIter.Next() )
257         {
258             if( pLast->IsPageFrame() )
259                 static_cast<SwPageFrame*>(pLast)->PrepareRegisterChg();
260         }
261     }
262 }
263 
264 /// special handling if the style of the grid alignment changes
SwClientNotify(const SwModify & rModify,const SfxHint & rHint)265 void SwPageDesc::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
266 {
267     if(auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
268     {
269         const sal_uInt16 nWhich = pLegacyHint->m_pOld
270                 ? pLegacyHint->m_pOld->Which()
271                 : pLegacyHint->m_pNew
272                 ? pLegacyHint->m_pNew->Which()
273                 : 0;
274         NotifyClients(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
275         if((RES_ATTRSET_CHG == nWhich)
276                 || (RES_FMT_CHG == nWhich)
277                 || isCHRATR(nWhich)
278                 || (RES_PARATR_LINESPACING == nWhich))
279             RegisterChange();
280     }
281     else if (auto pModifyChangedHint = dynamic_cast<const sw::ModifyChangedHint*>(&rHint))
282     {
283         if(m_pTextFormatColl == &rModify)
284             m_pTextFormatColl = static_cast<const SwTextFormatColl*>(pModifyChangedHint->m_pNew);
285         else
286             assert(false);
287     }
288 }
289 
lcl_GetFrameOfNode(const SwNode & rNd)290 static const SwFrame* lcl_GetFrameOfNode( const SwNode& rNd )
291 {
292     const SwModify* pMod;
293     SwFrameType nFrameType = FRM_CNTNT;
294 
295     if( rNd.IsContentNode() )
296     {
297         pMod = &static_cast<const SwContentNode&>(rNd);
298     }
299     else if( rNd.IsTableNode() )
300     {
301         pMod = static_cast<const SwTableNode&>(rNd).GetTable().GetFrameFormat();
302         nFrameType = SwFrameType::Tab;
303     }
304     else
305         pMod = nullptr;
306 
307     Point aNullPt;
308     std::pair<Point, bool> const tmp(aNullPt, false);
309     return pMod ? ::GetFrameOfModify(nullptr, *pMod, nFrameType, nullptr, &tmp)
310                 : nullptr;
311 }
312 
GetPageDescOfNode(const SwNode & rNd)313 const SwPageDesc* SwPageDesc::GetPageDescOfNode(const SwNode& rNd)
314 {
315     const SwPageDesc* pRet = nullptr;
316     const SwFrame* pChkFrame = lcl_GetFrameOfNode( rNd );
317     if (pChkFrame && nullptr != (pChkFrame = pChkFrame->FindPageFrame()))
318         pRet = static_cast<const SwPageFrame*>(pChkFrame)->GetPageDesc();
319     return pRet;
320 }
321 
GetPageFormatOfNode(const SwNode & rNd,bool bCheckForThisPgDc) const322 const SwFrameFormat* SwPageDesc::GetPageFormatOfNode( const SwNode& rNd,
323                                               bool bCheckForThisPgDc ) const
324 {
325     // which PageDescFormat is valid for this node?
326     const SwFrameFormat* pRet;
327     const SwFrame* pChkFrame = lcl_GetFrameOfNode( rNd );
328 
329     if( pChkFrame && nullptr != ( pChkFrame = pChkFrame->FindPageFrame() ))
330     {
331         const SwPageDesc* pPd = bCheckForThisPgDc ? this :
332                                 static_cast<const SwPageFrame*>(pChkFrame)->GetPageDesc();
333         pRet = &pPd->GetMaster();
334         OSL_ENSURE( static_cast<const SwPageFrame*>(pChkFrame)->GetPageDesc() == pPd, "Wrong node for detection of page format!" );
335         // this page is assigned to which format?
336         if( !pChkFrame->KnowsFormat(*pRet) )
337         {
338             pRet = &pPd->GetLeft();
339             OSL_ENSURE( pChkFrame->KnowsFormat(*pRet), "Wrong node for detection of page format!" );
340         }
341     }
342     else
343         pRet = &GetMaster();
344     return pRet;
345 }
346 
IsFollowNextPageOfNode(const SwNode & rNd) const347 bool SwPageDesc::IsFollowNextPageOfNode( const SwNode& rNd ) const
348 {
349     bool bRet = false;
350     if( GetFollow() && this != GetFollow() )
351     {
352         const SwFrame* pChkFrame = lcl_GetFrameOfNode( rNd );
353         if( pChkFrame && nullptr != ( pChkFrame = pChkFrame->FindPageFrame() ) &&
354             pChkFrame->IsPageFrame() &&
355             ( !pChkFrame->GetNext() || GetFollow() ==
356                         static_cast<const SwPageFrame*>(pChkFrame->GetNext())->GetPageDesc() ))
357             // the page on which the follow points was found
358             bRet = true;
359     }
360     return bRet;
361 }
362 
GetLeftFormat(bool const bFirst)363 SwFrameFormat *SwPageDesc::GetLeftFormat(bool const bFirst)
364 {
365     return (UseOnPage::Left & m_eUse)
366             ? (bFirst ? &m_FirstLeft : &m_Left)
367             : nullptr;
368 }
369 
GetRightFormat(bool const bFirst)370 SwFrameFormat *SwPageDesc::GetRightFormat(bool const bFirst)
371 {
372     return (UseOnPage::Right & m_eUse)
373             ? (bFirst ? &m_FirstMaster : &m_Master)
374             : nullptr;
375 }
376 
IsFirstShared() const377 bool SwPageDesc::IsFirstShared() const
378 {
379     return bool(m_eUse & UseOnPage::FirstShare);
380 }
381 
ChgFirstShare(bool bNew)382 void SwPageDesc::ChgFirstShare( bool bNew )
383 {
384     if ( bNew )
385         m_eUse |= UseOnPage::FirstShare;
386     else
387         m_eUse &= UseOnPage::NoFirstShare;
388 }
389 
390 // Page styles
391 static const char* STR_POOLPAGE[] =
392 {
393     STR_POOLPAGE_STANDARD,
394     STR_POOLPAGE_FIRST,
395     STR_POOLPAGE_LEFT,
396     STR_POOLPAGE_RIGHT,
397     STR_POOLPAGE_JAKET,
398     STR_POOLPAGE_REGISTER,
399     STR_POOLPAGE_HTML,
400     STR_POOLPAGE_FOOTNOTE,
401     STR_POOLPAGE_ENDNOTE,
402     STR_POOLPAGE_LANDSCAPE
403 };
404 
GetByName(SwDoc & rDoc,const OUString & rName)405 SwPageDesc* SwPageDesc::GetByName(SwDoc& rDoc, const OUString& rName)
406 {
407     const size_t nDCount = rDoc.GetPageDescCnt();
408 
409     for( size_t i = 0; i < nDCount; i++ )
410     {
411         SwPageDesc* pDsc = &rDoc.GetPageDesc( i );
412         if(pDsc->GetName() == rName)
413         {
414             return pDsc;
415         }
416     }
417 
418     for (size_t i = 0; i < SAL_N_ELEMENTS(STR_POOLPAGE); ++i)
419     {
420         if (rName == SwResId(STR_POOLPAGE[i]))
421         {
422             return rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool( static_cast< sal_uInt16 >(
423                         i + RES_POOLPAGE_BEGIN) );
424         }
425     }
426 
427     return nullptr;
428 }
429 
dumpAsXml(xmlTextWriterPtr pWriter) const430 void SwPageDesc::dumpAsXml(xmlTextWriterPtr pWriter) const
431 {
432     xmlTextWriterStartElement(pWriter, BAD_CAST("SwPageDesc"));
433     xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
434     xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("m_StyleName"), "%s",
435                                       BAD_CAST(m_StyleName.toUtf8().getStr()));
436     xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("m_pFollow"), "%p", m_pFollow);
437     xmlTextWriterWriteFormatAttribute(
438         pWriter, BAD_CAST("m_eUse"), "0x%s",
439         BAD_CAST(OString::number(static_cast<int>(m_eUse), 16).getStr()));
440 
441     xmlTextWriterStartElement(pWriter, BAD_CAST("m_Master"));
442     m_Master.dumpAsXml(pWriter);
443     xmlTextWriterEndElement(pWriter);
444 
445     xmlTextWriterStartElement(pWriter, BAD_CAST("m_Left"));
446     m_Left.dumpAsXml(pWriter);
447     xmlTextWriterEndElement(pWriter);
448 
449     xmlTextWriterStartElement(pWriter, BAD_CAST("m_FirstMaster"));
450     m_FirstMaster.dumpAsXml(pWriter);
451     xmlTextWriterEndElement(pWriter);
452 
453     xmlTextWriterStartElement(pWriter, BAD_CAST("m_FirstLeft"));
454     m_FirstLeft.dumpAsXml(pWriter);
455     xmlTextWriterEndElement(pWriter);
456 
457     xmlTextWriterEndElement(pWriter);
458 }
459 
SwPageFootnoteInfo()460 SwPageFootnoteInfo::SwPageFootnoteInfo()
461     : m_nMaxHeight( 0 )
462     , m_nLineWidth(10)
463     , m_eLineStyle( SvxBorderLineStyle::SOLID )
464     , m_Width( 25, 100 )
465     , m_nTopDist( 57 )         //1mm
466     , m_nBottomDist( 57 )
467 {
468     m_eAdjust = SvxFrameDirection::Horizontal_RL_TB == GetDefaultFrameDirection(GetAppLanguage()) ?
469            css::text::HorizontalAdjust_RIGHT :
470            css::text::HorizontalAdjust_LEFT;
471 }
472 
SwPageFootnoteInfo(const SwPageFootnoteInfo & rCpy)473 SwPageFootnoteInfo::SwPageFootnoteInfo( const SwPageFootnoteInfo &rCpy )
474     : m_nMaxHeight(rCpy.GetHeight())
475     , m_nLineWidth(rCpy.m_nLineWidth)
476     , m_eLineStyle(rCpy.m_eLineStyle)
477     , m_LineColor(rCpy.m_LineColor)
478     , m_Width(rCpy.GetWidth())
479     , m_eAdjust(rCpy.GetAdj())
480     , m_nTopDist(rCpy.GetTopDist())
481     , m_nBottomDist(rCpy.GetBottomDist())
482 {
483 }
484 
operator =(const SwPageFootnoteInfo & rCpy)485 SwPageFootnoteInfo &SwPageFootnoteInfo::operator=( const SwPageFootnoteInfo& rCpy )
486 {
487     m_nMaxHeight  = rCpy.GetHeight();
488     m_nLineWidth  = rCpy.m_nLineWidth;
489     m_eLineStyle  = rCpy.m_eLineStyle;
490     m_LineColor   = rCpy.m_LineColor;
491     m_Width       = rCpy.GetWidth();
492     m_eAdjust     = rCpy.GetAdj();
493     m_nTopDist    = rCpy.GetTopDist();
494     m_nBottomDist = rCpy.GetBottomDist();
495     return *this;
496 }
497 
operator ==(const SwPageFootnoteInfo & rCmp) const498 bool SwPageFootnoteInfo::operator==( const SwPageFootnoteInfo& rCmp ) const
499 {
500     return m_nMaxHeight == rCmp.GetHeight()
501         && m_nLineWidth == rCmp.m_nLineWidth
502         && m_eLineStyle == rCmp.m_eLineStyle
503         && m_LineColor  == rCmp.m_LineColor
504         && m_Width      == rCmp.GetWidth()
505         && m_eAdjust    == rCmp.GetAdj()
506         && m_nTopDist   == rCmp.GetTopDist()
507         && m_nBottomDist== rCmp.GetBottomDist();
508 }
509 
SwPageDescExt(const SwPageDesc & rPageDesc,SwDoc * const pDoc)510 SwPageDescExt::SwPageDescExt(const SwPageDesc & rPageDesc, SwDoc *const pDoc)
511     : m_PageDesc(rPageDesc)
512     , m_pDoc(pDoc)
513 {
514     SetPageDesc(rPageDesc);
515 }
516 
SwPageDescExt(const SwPageDescExt & rSrc)517 SwPageDescExt::SwPageDescExt(const SwPageDescExt & rSrc)
518     : m_PageDesc(rSrc.m_PageDesc)
519     , m_pDoc(rSrc.m_pDoc)
520 {
521     SetPageDesc(rSrc.m_PageDesc);
522 }
523 
~SwPageDescExt()524 SwPageDescExt::~SwPageDescExt()
525 {
526 }
527 
GetName() const528 OUString const & SwPageDescExt::GetName() const
529 {
530     return m_PageDesc.GetName();
531 }
532 
SetPageDesc(const SwPageDesc & rPageDesc)533 void SwPageDescExt::SetPageDesc(const SwPageDesc & rPageDesc)
534 {
535     m_PageDesc = rPageDesc;
536 
537     if (m_PageDesc.GetFollow())
538         m_sFollow = m_PageDesc.GetFollow()->GetName();
539 }
540 
operator =(const SwPageDesc & rSrc)541 SwPageDescExt & SwPageDescExt::operator = (const SwPageDesc & rSrc)
542 {
543     SetPageDesc(rSrc);
544 
545     return *this;
546 }
547 
operator =(const SwPageDescExt & rSrc)548 SwPageDescExt & SwPageDescExt::operator = (const SwPageDescExt & rSrc)
549 {
550     operator=(rSrc.m_PageDesc);
551     return *this;
552 }
553 
operator SwPageDesc() const554 SwPageDescExt::operator SwPageDesc() const
555 {
556     SwPageDesc aResult(m_PageDesc);
557 
558     SwPageDesc * pPageDesc = m_pDoc->FindPageDesc(m_sFollow);
559 
560     if ( nullptr != pPageDesc )
561         aResult.SetFollow(pPageDesc);
562 
563     return aResult;
564 }
565 
SwPageDescs()566 SwPageDescs::SwPageDescs()
567     : m_PosIndex( m_Array.get<0>() )
568     , m_NameIndex( m_Array.get<1>() )
569 {
570 }
571 
~SwPageDescs()572 SwPageDescs::~SwPageDescs()
573 {
574     for(const_iterator it = begin(); it != end(); ++it)
575         delete *it;
576 }
577 
find_(const OUString & name) const578 SwPageDescs::iterator SwPageDescs::find_(const OUString &name) const
579 {
580     ByName::iterator it = m_NameIndex.find( name );
581     return m_Array.iterator_to( *it );
582 }
583 
push_back(const value_type & x)584 std::pair<SwPageDescs::const_iterator,bool> SwPageDescs::push_back( const value_type& x )
585 {
586     // SwPageDesc is not already in a SwPageDescs list!
587     assert( x->m_pdList == nullptr );
588 
589     std::pair<iterator,bool> res = m_PosIndex.push_back( x );
590     if( res.second )
591         x->m_pdList = this;
592     return res;
593 }
594 
erase(const value_type & x)595 void SwPageDescs::erase( const value_type& x )
596 {
597     // SwPageDesc is not in this SwPageDescs list!
598     assert( x->m_pdList == this );
599 
600     iterator const ret = find_( x->GetName() );
601     if (ret != end())
602         m_PosIndex.erase( ret );
603     else
604         SAL_WARN( "sw", "SwPageDesc is not in SwPageDescs m_pdList!" );
605     x->m_pdList = nullptr;
606 }
607 
erase(const_iterator const & position)608 void SwPageDescs::erase( const_iterator const& position )
609 {
610     // SwPageDesc is not in this SwPageDescs list!
611     assert( (*position)->m_pdList == this );
612 
613     (*position)->m_pdList = nullptr;
614     m_PosIndex.erase( position );
615 }
616 
erase(size_type index_)617 void SwPageDescs::erase( size_type index_ )
618 {
619     erase( begin() + index_ );
620 }
621 
dumpAsXml(xmlTextWriterPtr pWriter) const622 void SwPageDescs::dumpAsXml(xmlTextWriterPtr pWriter) const
623 {
624     xmlTextWriterStartElement(pWriter, BAD_CAST("SwPageDescs"));
625 
626     for (const auto& pPageDesc : m_PosIndex)
627     {
628         pPageDesc->dumpAsXml(pWriter);
629     }
630 
631     xmlTextWriterEndElement(pWriter);
632 }
633 
634 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
635