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 <hintids.hxx>
21 #include <fesh.hxx>
22 #include <doc.hxx>
23 #include <IDocumentUndoRedo.hxx>
26 #include <pagefrm.hxx>
27 #include <rootfrm.hxx>
28 #include <cntfrm.hxx>
29 #include <txtfrm.hxx>
30 #include <notxtfrm.hxx>
31 #include <pam.hxx>
32 #include <fmtpdsc.hxx>
33 #include <pagedesc.hxx>
34 #include <tabfrm.hxx>
35 #include <edimp.hxx>
36 #include <SwStyleNameMapper.hxx>
37 #include <ndtxt.hxx>
38 
40 {
41  return GetDoc()->GetPageDescCnt();
42 }
43 
45 {
46 #if OSL_DEBUG_LEVEL > 0
47  // SS does not change PageDesc, but only sets the attribute.
48  // The Pagedesc should be available in the document
49  bool bFound = false;
50  for ( size_t nTst = 0; nTst < GetPageDescCnt(); ++nTst )
51  if ( &rDesc == &GetPageDesc( nTst ) )
52  bFound = true;
53  OSL_ENSURE( bFound, "ChgCurPageDesc with invalid descriptor." );
54 #endif
55 
57 
59  const SwFrame *pFlow = nullptr;
60  ::boost::optional<sal_uInt16> oPageNumOffset;
61 
62  OSL_ENSURE( !GetCursor()->HasMark(), "ChgCurPageDesc only without selection!");
63 
64  SET_CURR_SHELL( this );
65  while ( pPage )
66  {
67  pFlow = pPage->FindFirstBodyContent();
68  if ( pFlow )
69  {
70  if ( pFlow->IsInTab() )
71  pFlow = pFlow->FindTabFrame();
72  const SwFormatPageDesc& rPgDesc = pFlow->GetPageDescItem();
73  if( rPgDesc.GetPageDesc() )
74  {
75  // we found the culprit
76  oPageNumOffset = rPgDesc.GetNumOffset();
77  break;
78  }
79  }
80  pPage = static_cast<SwPageFrame*>( pPage->GetPrev() );
81  }
82  if ( !pPage )
83  {
84  pPage = static_cast<SwPageFrame*>(GetLayout()->Lower());
85  pFlow = pPage->FindFirstBodyContent();
86  if ( !pFlow )
87  {
88  pPage = static_cast<SwPageFrame*>(pPage->GetNext());
89  pFlow = pPage->FindFirstBodyContent();
90  OSL_ENSURE( pFlow, "Document without content?!?" );
91  }
92  }
93 
94  // use pagenumber
95  SwFormatPageDesc aNew( &rDesc );
96  aNew.SetNumOffset( oPageNumOffset );
97 
98  if ( pFlow->IsInTab() )
99  GetDoc()->SetAttr( aNew, *const_cast<SwFormat*>(static_cast<SwFormat const *>(pFlow->FindTabFrame()->GetFormat())) );
100  else
101  {
102  assert(pFlow->IsContentFrame());
103  SwPaM aPaM( pFlow->IsTextFrame()
104  ? *static_cast<SwTextFrame const*>(pFlow)->GetTextNodeFirst() // first, for PAGEDESC
105  : *static_cast<const SwNoTextFrame*>(pFlow)->GetNode() );
107  aPaM, aNew, SetAttrMode::DEFAULT, GetLayout());
108  }
110 }
111 
112 void SwFEShell::ChgPageDesc( size_t i, const SwPageDesc &rChged )
113 {
114  StartAllAction();
115  SET_CURR_SHELL( this );
116  //Fix i64842: because Undo has a very special way to handle header/footer content
117  // we have to copy the page descriptor before calling ChgPageDesc.
118  SwPageDesc aDesc( rChged );
119  {
120  ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
121  GetDoc()->CopyPageDesc(rChged, aDesc);
122  }
123  GetDoc()->ChgPageDesc( i, aDesc );
125 }
126 
127 const SwPageDesc& SwFEShell::GetPageDesc( size_t i ) const
128 {
129  return GetDoc()->GetPageDesc( i );
130 }
131 
133  bool bGetFromPool,
134  size_t* pPos )
135 {
136  SwPageDesc* pDesc = GetDoc()->FindPageDesc(rName, pPos);
137  if( !pDesc && bGetFromPool )
138  {
140  if( USHRT_MAX != nPoolId &&
141  nullptr != (pDesc = GetDoc()->getIDocumentStylePoolAccess().GetPageDescFromPool( nPoolId ))
142  && pPos )
143  // appended always
144  *pPos = GetDoc()->GetPageDescCnt() - 1 ;
145  }
146  return pDesc;
147 }
148 
149 size_t SwFEShell::GetMousePageDesc( const Point &rPt ) const
150 {
151  if( GetLayout() )
152  {
153  const SwPageFrame* pPage =
154  static_cast<const SwPageFrame*>( GetLayout()->Lower() );
155  if( pPage )
156  {
157  while( pPage->GetNext() && rPt.Y() > pPage->getFrameArea().Bottom() )
158  pPage = static_cast<const SwPageFrame*>( pPage->GetNext() );
159  SwDoc *pMyDoc = GetDoc();
160  size_t nPos;
161  if (pMyDoc->ContainsPageDesc( pPage->GetPageDesc(), &nPos ) )
162  return nPos;
163  }
164  }
165  return 0;
166 }
167 
168 size_t SwFEShell::GetCurPageDesc( const bool bCalcFrame ) const
169 {
170  const SwFrame *pFrame = GetCurrFrame( bCalcFrame );
171  if ( pFrame )
172  {
173  const SwPageFrame *pPage = pFrame->FindPageFrame();
174  if ( pPage )
175  {
176  size_t nPos;
177  if (GetDoc()->ContainsPageDesc( pPage->GetPageDesc(), &nPos ))
178  return nPos;
179  }
180  }
181  return 0;
182 }
183 
184 // if inside all selection only one PageDesc, return this.
185 // Otherwise return 0 pointer
187 {
188  const SwContentNode* pCNd;
189  const SwFrame* pMkFrame, *pPtFrame;
190  const SwPageDesc* pFnd, *pRetDesc = reinterpret_cast<SwPageDesc*>(sal_IntPtr(-1));
191  const Point aNulPt;
192  std::pair<Point, bool> const tmp(aNulPt, false);
193 
194  for(SwPaM& rPaM : GetCursor()->GetRingContainer())
195  {
196 
197  if( nullptr != (pCNd = rPaM.GetContentNode() ) &&
198  nullptr != (pPtFrame = pCNd->getLayoutFrame(GetLayout(), nullptr, &tmp)))
199  pPtFrame = pPtFrame->FindPageFrame();
200  else
201  pPtFrame = nullptr;
202 
203  if( rPaM.HasMark() &&
204  nullptr != (pCNd = rPaM.GetContentNode( false ) ) &&
205  nullptr != (pMkFrame = pCNd->getLayoutFrame(GetLayout(), nullptr, &tmp)))
206  pMkFrame = pMkFrame->FindPageFrame();
207  else
208  pMkFrame = pPtFrame;
209 
210  if( !pMkFrame || !pPtFrame )
211  pFnd = nullptr;
212  else if( pMkFrame == pPtFrame )
213  pFnd = static_cast<const SwPageFrame*>(pMkFrame)->GetPageDesc();
214  else
215  {
216  // swap pointer if PtFrame before MkFrame
217  if( static_cast<const SwPageFrame*>(pMkFrame)->GetPhyPageNum() >
218  static_cast<const SwPageFrame*>(pPtFrame)->GetPhyPageNum() )
219  {
220  const SwFrame* pTmp = pMkFrame; pMkFrame = pPtFrame; pPtFrame = pTmp;
221  }
222 
223  // now check from MkFrame to PtFrame for equal PageDescs
224  pFnd = static_cast<const SwPageFrame*>(pMkFrame)->GetPageDesc();
225  while( pFnd && pMkFrame != pPtFrame )
226  {
227  pMkFrame = pMkFrame->GetNext();
228  if( !pMkFrame || pFnd != static_cast<const SwPageFrame*>(pMkFrame)->GetPageDesc() )
229  pFnd = nullptr;
230  }
231  }
232 
233  if( reinterpret_cast<SwPageDesc*>(sal_IntPtr(-1)) == pRetDesc )
234  pRetDesc = pFnd;
235  else if( pFnd != pRetDesc )
236  {
237  pRetDesc = nullptr;
238  break;
239  }
240 
241  }
242 
243  return pRetDesc;
244 }
245 
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE void EndAllActionAndCall()
Terminate actions for all shells and call ChangeLink.
Definition: fews.cxx:71
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:834
sal_uInt16 GetPhyPageNum()
Phy: real page count.
Definition: fews.cxx:336
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:756
const SwPageDesc * GetSelectedPageDescs() const
if inside all selection only one PageDesc,
Definition: fedesc.cxx:186
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:185
size_t GetPageDescCnt() const
Definition: fedesc.cxx:39
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:1150
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:347
size_t GetMousePageDesc(const Point &rPt) const
Definition: fedesc.cxx:149
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:478
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:2601
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
SwPageDesc * FindPageDesc(const OUString &rName, size_t *pPos=nullptr) const
Definition: docdesc.cxx:829
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:875
SwPageFrame * FindPageFrame()
Definition: frame.hxx:658
const SwFrame * Lower() const
Definition: layfrm.hxx:100
SwPageDesc * GetPageDesc()
Definition: pagefrm.hxx:129
SwContentNode * GetContentNode()
Definition: node.hxx:615
const SwPageDesc & GetPageDesc(size_t i) const
Definition: fedesc.cxx:127
size_t GetPageDescCnt() const
Definition: doc.hxx:874
void ChgPageDesc(const OUString &rName, const SwPageDesc &)
Definition: docdesc.cxx:860
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
bool HasMark()
Definition: crsrsh.hxx:875
IDocumentUndoRedo const & GetIDocumentUndoRedo() const
Provides access to the document undo/redo interface.
Definition: viewsh.cxx:2606
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:1427
SwContentFrame * GetCurrFrame(const bool bCalcFrame=true) const
Get current frame in which the cursor is positioned.
Definition: crsrsh.cxx:2350
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:112
SwPageDesc * GetPageDescFromPool(sal_uInt16 nId)
Definition: edfmt.cxx:136
SwPageDesc * FindPageDescByName(const OUString &rName, bool bGetFromPool=false, size_t *pPos=nullptr)
Definition: fedesc.cxx:132
void ChgCurPageDesc(const SwPageDesc &)
PageDescriptor-interface.
Definition: fedesc.cxx:44
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2072
sal_Int32 nPos
size_t GetCurPageDesc(const bool bCalcFrame=true) const
Definition: fedesc.cxx:168
long Y() const
virtual const SwFrameFormat * GetFormat() const
Definition: ssfrm.cxx:393
SwTabFrame * FindTabFrame()
Definition: frame.hxx:1075
SwFrame * GetNext()
Definition: frame.hxx:654