LibreOffice Module sw (master)  1
fedesc.cxx
Go to the documentation of this file.
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 <fesh.hxx>
21 #include <doc.hxx>
22 #include <IDocumentUndoRedo.hxx>
25 #include <pagefrm.hxx>
26 #include <rootfrm.hxx>
27 #include <cntfrm.hxx>
28 #include <txtfrm.hxx>
29 #include <notxtfrm.hxx>
30 #include <pam.hxx>
31 #include <fmtpdsc.hxx>
32 #include <pagedesc.hxx>
33 #include <tabfrm.hxx>
34 #include <SwStyleNameMapper.hxx>
35 #include <ndtxt.hxx>
36 
38 {
39  return GetDoc()->GetPageDescCnt();
40 }
41 
43 {
44 #if OSL_DEBUG_LEVEL > 0
45  // SS does not change PageDesc, but only sets the attribute.
46  // The Pagedesc should be available in the document
47  bool bFound = false;
48  for ( size_t nTst = 0; nTst < GetPageDescCnt(); ++nTst )
49  if ( &rDesc == &GetPageDesc( nTst ) )
50  bFound = true;
51  OSL_ENSURE( bFound, "ChgCurPageDesc with invalid descriptor." );
52 #endif
53 
55 
57  const SwFrame *pFlow = nullptr;
58  ::boost::optional<sal_uInt16> oPageNumOffset;
59 
60  OSL_ENSURE( !GetCursor()->HasMark(), "ChgCurPageDesc only without selection!");
61 
62  SET_CURR_SHELL( this );
63  while ( pPage )
64  {
65  pFlow = pPage->FindFirstBodyContent();
66  if ( pFlow )
67  {
68  if ( pFlow->IsInTab() )
69  pFlow = pFlow->FindTabFrame();
70  const SwFormatPageDesc& rPgDesc = pFlow->GetPageDescItem();
71  if( rPgDesc.GetPageDesc() )
72  {
73  // we found the culprit
74  oPageNumOffset = rPgDesc.GetNumOffset();
75  break;
76  }
77  }
78  pPage = static_cast<SwPageFrame*>( pPage->GetPrev() );
79  }
80  if ( !pPage )
81  {
82  pPage = static_cast<SwPageFrame*>(GetLayout()->Lower());
83  pFlow = pPage->FindFirstBodyContent();
84  if ( !pFlow )
85  {
86  pPage = static_cast<SwPageFrame*>(pPage->GetNext());
87  pFlow = pPage->FindFirstBodyContent();
88  OSL_ENSURE( pFlow, "Document without content?!?" );
89  }
90  }
91 
92  // use pagenumber
93  SwFormatPageDesc aNew( &rDesc );
94  aNew.SetNumOffset( oPageNumOffset );
95 
96  if ( pFlow->IsInTab() )
97  GetDoc()->SetAttr( aNew, *const_cast<SwFormat*>(static_cast<SwFormat const *>(pFlow->FindTabFrame()->GetFormat())) );
98  else
99  {
100  assert(pFlow->IsContentFrame());
101  SwPaM aPaM( pFlow->IsTextFrame()
102  ? *static_cast<SwTextFrame const*>(pFlow)->GetTextNodeFirst() // first, for PAGEDESC
103  : *static_cast<const SwNoTextFrame*>(pFlow)->GetNode() );
105  aPaM, aNew, SetAttrMode::DEFAULT, GetLayout());
106  }
108 }
109 
110 void SwFEShell::ChgPageDesc( size_t i, const SwPageDesc &rChged )
111 {
112  StartAllAction();
113  SET_CURR_SHELL( this );
114  //Fix i64842: because Undo has a very special way to handle header/footer content
115  // we have to copy the page descriptor before calling ChgPageDesc.
116  SwPageDesc aDesc( rChged );
117  {
118  ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
119  GetDoc()->CopyPageDesc(rChged, aDesc);
120  }
121  GetDoc()->ChgPageDesc( i, aDesc );
123 }
124 
125 const SwPageDesc& SwFEShell::GetPageDesc( size_t i ) const
126 {
127  return GetDoc()->GetPageDesc( i );
128 }
129 
131  bool bGetFromPool,
132  size_t* pPos )
133 {
134  SwPageDesc* pDesc = GetDoc()->FindPageDesc(rName, pPos);
135  if( !pDesc && bGetFromPool )
136  {
138  if( USHRT_MAX != nPoolId &&
139  nullptr != (pDesc = GetDoc()->getIDocumentStylePoolAccess().GetPageDescFromPool( nPoolId ))
140  && pPos )
141  // appended always
142  *pPos = GetDoc()->GetPageDescCnt() - 1 ;
143  }
144  return pDesc;
145 }
146 
147 size_t SwFEShell::GetMousePageDesc( const Point &rPt ) const
148 {
149  if( GetLayout() )
150  {
151  const SwPageFrame* pPage =
152  static_cast<const SwPageFrame*>( GetLayout()->Lower() );
153  if( pPage )
154  {
155  while( pPage->GetNext() && rPt.Y() > pPage->getFrameArea().Bottom() )
156  pPage = static_cast<const SwPageFrame*>( pPage->GetNext() );
157  SwDoc *pMyDoc = GetDoc();
158  size_t nPos;
159  if (pMyDoc->ContainsPageDesc( pPage->GetPageDesc(), &nPos ) )
160  return nPos;
161  }
162  }
163  return 0;
164 }
165 
166 size_t SwFEShell::GetCurPageDesc( const bool bCalcFrame ) const
167 {
168  const SwFrame *pFrame = GetCurrFrame( bCalcFrame );
169  if ( pFrame )
170  {
171  const SwPageFrame *pPage = pFrame->FindPageFrame();
172  if ( pPage )
173  {
174  size_t nPos;
175  if (GetDoc()->ContainsPageDesc( pPage->GetPageDesc(), &nPos ))
176  return nPos;
177  }
178  }
179  return 0;
180 }
181 
182 // if inside all selection only one PageDesc, return this.
183 // Otherwise return 0 pointer
185 {
186  const SwContentNode* pCNd;
187  const SwFrame* pMkFrame, *pPtFrame;
188  const SwPageDesc* pFnd, *pRetDesc = reinterpret_cast<SwPageDesc*>(sal_IntPtr(-1));
189  const Point aNulPt;
190  std::pair<Point, bool> const tmp(aNulPt, false);
191 
192  for(const SwPaM& rPaM : GetCursor()->GetRingContainer())
193  {
194 
195  if( nullptr != (pCNd = rPaM.GetContentNode() ) &&
196  nullptr != (pPtFrame = pCNd->getLayoutFrame(GetLayout(), nullptr, &tmp)))
197  pPtFrame = pPtFrame->FindPageFrame();
198  else
199  pPtFrame = nullptr;
200 
201  if( rPaM.HasMark() &&
202  nullptr != (pCNd = rPaM.GetContentNode( false ) ) &&
203  nullptr != (pMkFrame = pCNd->getLayoutFrame(GetLayout(), nullptr, &tmp)))
204  pMkFrame = pMkFrame->FindPageFrame();
205  else
206  pMkFrame = pPtFrame;
207 
208  if( !pMkFrame || !pPtFrame )
209  pFnd = nullptr;
210  else if( pMkFrame == pPtFrame )
211  pFnd = static_cast<const SwPageFrame*>(pMkFrame)->GetPageDesc();
212  else
213  {
214  // swap pointer if PtFrame before MkFrame
215  if( static_cast<const SwPageFrame*>(pMkFrame)->GetPhyPageNum() >
216  static_cast<const SwPageFrame*>(pPtFrame)->GetPhyPageNum() )
217  {
218  const SwFrame* pTmp = pMkFrame; pMkFrame = pPtFrame; pPtFrame = pTmp;
219  }
220 
221  // now check from MkFrame to PtFrame for equal PageDescs
222  pFnd = static_cast<const SwPageFrame*>(pMkFrame)->GetPageDesc();
223  while( pFnd && pMkFrame != pPtFrame )
224  {
225  pMkFrame = pMkFrame->GetNext();
226  if( !pMkFrame || pFnd != static_cast<const SwPageFrame*>(pMkFrame)->GetPageDesc() )
227  pFnd = nullptr;
228  }
229  }
230 
231  if( reinterpret_cast<SwPageDesc*>(sal_IntPtr(-1)) == pRetDesc )
232  pRetDesc = pFnd;
233  else if( pFnd != pRetDesc )
234  {
235  pRetDesc = nullptr;
236  break;
237  }
238 
239  }
240 
241  return pRetDesc;
242 }
243 
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE void EndAllActionAndCall()
Terminate actions for all shells and call ChangeLink.
Definition: fews.cxx:69
Base class of the Writer layout elements.
Definition: frame.hxx:295
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
bool ContainsPageDesc(const SwPageDesc *pDesc, size_t *pPos) const
Definition: docdesc.cxx:827
SwContentNode * GetNode(SwPaM &rPam, bool &rbFirst, SwMoveFnCollection const &fnMove, bool const bInReadOnly, SwRootFrame const *const i_pLayout)
This function returns the next node in direction of search.
Definition: pam.cxx:758
const SwPageDesc * GetSelectedPageDescs() const
if inside all selection only one PageDesc,
Definition: fedesc.cxx:184
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:35
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:184
size_t GetPageDescCnt() const
Definition: fedesc.cxx:37
SwPageDesc * GetPageDesc()
Definition: fmtpdsc.hxx:62
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1147
Definition: doc.hxx:185
sal_uInt16 sal_Char sal_Char * pDesc
SwContentFrame * FindFirstBodyContent()
Definition: pagefrm.hxx:333
virtual const SwFormatPageDesc & GetPageDescItem() const
Definition: findfrm.cxx:659
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:314
size_t GetMousePageDesc(const Point &rPt) const
Definition: fedesc.cxx:147
const SwRect & getFrameArea() const
Definition: frame.hxx:175
bool IsInTab() const
Definition: frame.hxx:931
void SetAttr(const SfxPoolItem &, SwFormat &)
Set attribute in given format.1y If Undo is enabled, the old values is added to the Undo history...
Definition: docfmt.cxx:448
bool IsTextFrame() const
Definition: frame.hxx:1210
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
void SetNumOffset(const ::boost::optional< sal_uInt16 > &oNum)
Definition: fmtpdsc.hxx:66
IDocumentStylePoolAccess & getIDocumentStylePoolAccess()
Provides access to the document style pool interface.
Definition: viewsh.cxx:2604
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
SwPageDesc * FindPageDesc(const OUString &rName, size_t *pPos=nullptr) const
Definition: docdesc.cxx:822
const ::boost::optional< sal_uInt16 > & GetNumOffset() const
Definition: fmtpdsc.hxx:65
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
bool IsContentFrame() const
Definition: frame.hxx:1206
const SwPageDesc & GetPageDesc(const size_t i) const
Definition: doc.hxx:877
SwPageFrame * FindPageFrame()
Definition: frame.hxx:658
sal_uInt16 GetPhyPageNum() const
Phy: real page count.
Definition: fews.cxx:334
const SwFrame * Lower() const
Definition: layfrm.hxx:101
bool HasMark() const
Definition: crsrsh.hxx:881
SwPageDesc * GetPageDesc()
Definition: pagefrm.hxx:129
SwContentNode * GetContentNode()
Definition: node.hxx:615
const SwPageDesc & GetPageDesc(size_t i) const
Definition: fedesc.cxx:125
size_t GetPageDescCnt() const
Definition: doc.hxx:876
void ChgPageDesc(const OUString &rName, const SwPageDesc &)
Definition: docdesc.cxx:853
SwFrame * GetPrev()
Definition: frame.hxx:655
#define SET_CURR_SHELL(shell)
Definition: swtypes.hxx:101
ring_container GetRingContainer()
A page of the document layout.
Definition: pagefrm.hxx:40
IDocumentUndoRedo const & GetIDocumentUndoRedo() const
Provides access to the document undo/redo interface.
Definition: viewsh.cxx:2609
void Bottom(const long nBottom)
Definition: swrect.hxx:207
void CopyPageDesc(const SwPageDesc &rSrcDesc, SwPageDesc &rDstDesc, bool bCopyPoolIds=true)
Copy the complete PageDesc - beyond document and "deep"! Optionally copying of PoolFormatId, -HlpId can be prevented.
Definition: docfmt.cxx:1399
SwContentFrame * GetCurrFrame(const bool bCalcFrame=true) const
Get current frame in which the cursor is positioned.
Definition: crsrsh.cxx:2426
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
virtual bool InsertPoolItem(const SwPaM &rRg, const SfxPoolItem &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr, bool bExpandCharToPara=false, SwTextAttr **ppNewTextAttr=nullptr)=0
Insert an attribute.
void ChgPageDesc(size_t i, const SwPageDesc &)
Definition: fedesc.cxx:110
SwPageDesc * GetPageDescFromPool(sal_uInt16 nId)
Definition: edfmt.cxx:134
SwPageDesc * FindPageDescByName(const OUString &rName, bool bGetFromPool=false, size_t *pPos=nullptr)
Definition: fedesc.cxx:130
void ChgCurPageDesc(const SwPageDesc &)
PageDescriptor-interface.
Definition: fedesc.cxx:42
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2075
sal_Int32 nPos
size_t GetCurPageDesc(const bool bCalcFrame=true) const
Definition: fedesc.cxx:166
long Y() const
virtual const SwFrameFormat * GetFormat() const
Definition: ssfrm.cxx:393
SwTabFrame * FindTabFrame()
Definition: frame.hxx:1075
SwFrame * GetNext()
Definition: frame.hxx:654