nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / frmedt / fedesc.cxx
blob41171da5db406d4d87c2025a3eff3fa1e2e90766
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <fesh.hxx>
21 #include <doc.hxx>
22 #include <IDocumentUndoRedo.hxx>
23 #include <IDocumentContentOperations.hxx>
24 #include <IDocumentStylePoolAccess.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>
37 size_t SwFEShell::GetPageDescCnt() const
39 return GetDoc()->GetPageDescCnt();
42 void SwFEShell::ChgCurPageDesc( const SwPageDesc& rDesc )
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
54 StartAllAction();
56 SwPageFrame *pPage = GetCurrFrame()->FindPageFrame();
57 const SwFrame *pFlow = nullptr;
58 ::std::optional<sal_uInt16> oPageNumOffset;
60 OSL_ENSURE( !GetCursor()->HasMark(), "ChgCurPageDesc only without selection!");
62 CurrShell aCurr( this );
63 while ( pPage )
65 pFlow = pPage->FindFirstBodyContent();
66 if ( pFlow )
68 if ( pFlow->IsInTab() )
69 pFlow = pFlow->FindTabFrame();
70 const SwFormatPageDesc& rPgDesc = pFlow->GetPageDescItem();
71 if( rPgDesc.GetPageDesc() )
73 // we found the culprit
74 oPageNumOffset = rPgDesc.GetNumOffset();
75 break;
78 pPage = static_cast<SwPageFrame*>( pPage->GetPrev() );
80 if ( !pPage )
82 pPage = static_cast<SwPageFrame*>(GetLayout()->Lower());
83 pFlow = pPage->FindFirstBodyContent();
84 if ( !pFlow )
86 pPage = static_cast<SwPageFrame*>(pPage->GetNext());
87 pFlow = pPage->FindFirstBodyContent();
88 OSL_ENSURE( pFlow, "Document without content?!?" );
92 // use pagenumber
93 SwFormatPageDesc aNew( &rDesc );
94 aNew.SetNumOffset( oPageNumOffset );
96 if ( pFlow->IsInTab() )
97 GetDoc()->SetAttr( aNew, *const_cast<SwFormat*>(static_cast<SwFormat const *>(pFlow->FindTabFrame()->GetFormat())) );
98 else
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() );
104 GetDoc()->getIDocumentContentOperations().InsertPoolItem(
105 aPaM, aNew, SetAttrMode::DEFAULT, GetLayout());
107 EndAllActionAndCall();
110 void SwFEShell::ChgPageDesc( size_t i, const SwPageDesc &rChged )
112 StartAllAction();
113 CurrShell aCurr( 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 );
118 ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
119 GetDoc()->CopyPageDesc(rChged, aDesc);
121 GetDoc()->ChgPageDesc( i, aDesc );
122 EndAllActionAndCall();
125 const SwPageDesc& SwFEShell::GetPageDesc( size_t i ) const
127 return GetDoc()->GetPageDesc( i );
130 SwPageDesc* SwFEShell::FindPageDescByName( const OUString& rName,
131 bool bGetFromPool,
132 size_t* pPos )
134 SwPageDesc* pDesc = GetDoc()->FindPageDesc(rName, pPos);
135 if( !pDesc && bGetFromPool )
137 sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( rName, SwGetPoolIdFromName::PageDesc );
138 if( USHRT_MAX != nPoolId &&
139 nullptr != (pDesc = GetDoc()->getIDocumentStylePoolAccess().GetPageDescFromPool( nPoolId ))
140 && pPos )
141 // appended always
142 *pPos = GetDoc()->GetPageDescCnt() - 1 ;
144 return pDesc;
147 size_t SwFEShell::GetMousePageDesc( const Point &rPt ) const
149 if( GetLayout() )
151 const SwPageFrame* pPage =
152 static_cast<const SwPageFrame*>( GetLayout()->Lower() );
153 if( pPage )
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;
163 return 0;
166 size_t SwFEShell::GetCurPageDesc( const bool bCalcFrame ) const
168 const SwFrame *pFrame = GetCurrFrame( bCalcFrame );
169 if ( pFrame )
171 const SwPageFrame *pPage = pFrame->FindPageFrame();
172 if ( pPage )
174 size_t nPos;
175 if (GetDoc()->ContainsPageDesc( pPage->GetPageDesc(), &nPos ))
176 return nPos;
179 return 0;
182 // if inside all selection only one PageDesc, return this.
183 // Otherwise return 0 pointer
184 const SwPageDesc* SwFEShell::GetSelectedPageDescs() const
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);
192 for(const SwPaM& rPaM : GetCursor()->GetRingContainer())
195 if( nullptr != (pCNd = rPaM.GetContentNode() ) &&
196 nullptr != (pPtFrame = pCNd->getLayoutFrame(GetLayout(), nullptr, &tmp)))
197 pPtFrame = pPtFrame->FindPageFrame();
198 else
199 pPtFrame = nullptr;
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;
208 if( !pMkFrame || !pPtFrame )
209 pFnd = nullptr;
210 else if( pMkFrame == pPtFrame )
211 pFnd = static_cast<const SwPageFrame*>(pMkFrame)->GetPageDesc();
212 else
214 // swap pointer if PtFrame before MkFrame
215 if( static_cast<const SwPageFrame*>(pMkFrame)->GetPhyPageNum() >
216 static_cast<const SwPageFrame*>(pPtFrame)->GetPhyPageNum() )
218 const SwFrame* pTmp = pMkFrame; pMkFrame = pPtFrame; pPtFrame = pTmp;
221 // now check from MkFrame to PtFrame for equal PageDescs
222 pFnd = static_cast<const SwPageFrame*>(pMkFrame)->GetPageDesc();
223 while( pFnd && pMkFrame != pPtFrame )
225 pMkFrame = pMkFrame->GetNext();
226 if( !pMkFrame || pFnd != static_cast<const SwPageFrame*>(pMkFrame)->GetPageDesc() )
227 pFnd = nullptr;
231 if( reinterpret_cast<SwPageDesc*>(sal_IntPtr(-1)) == pRetDesc )
232 pRetDesc = pFnd;
233 else if( pFnd != pRetDesc )
235 pRetDesc = nullptr;
236 break;
241 return pRetDesc;
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */