1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <IDocumentUndoRedo.hxx>
23 #include <IDocumentContentOperations.hxx>
24 #include <IDocumentStylePoolAccess.hxx>
25 #include <pagefrm.hxx>
26 #include <rootfrm.hxx>
29 #include <notxtfrm.hxx>
31 #include <fmtpdsc.hxx>
32 #include <pagedesc.hxx>
34 #include <SwStyleNameMapper.hxx>
36 #include <osl/diagnose.h>
38 size_t SwFEShell::GetPageDescCnt() const
40 return GetDoc()->GetPageDescCnt();
43 void SwFEShell::ChgCurPageDesc( const SwPageDesc
& rDesc
)
45 #if OSL_DEBUG_LEVEL > 0
46 // SS does not change PageDesc, but only sets the attribute.
47 // The Pagedesc should be available in the document
49 for ( size_t nTst
= 0; nTst
< GetPageDescCnt(); ++nTst
)
50 if ( &rDesc
== &GetPageDesc( nTst
) )
52 OSL_ENSURE( bFound
, "ChgCurPageDesc with invalid descriptor." );
57 SwPageFrame
*pPage
= GetCurrFrame()->FindPageFrame();
58 const SwFrame
*pFlow
= nullptr;
59 ::std::optional
<sal_uInt16
> oPageNumOffset
;
61 OSL_ENSURE( !GetCursor()->HasMark(), "ChgCurPageDesc only without selection!");
63 CurrShell
aCurr( this );
66 pFlow
= pPage
->FindFirstBodyContent();
69 if ( pFlow
->IsInTab() )
70 pFlow
= pFlow
->FindTabFrame();
71 const SwFormatPageDesc
& rPgDesc
= pFlow
->GetPageDescItem();
72 if( rPgDesc
.GetPageDesc() )
74 // we found the culprit
75 oPageNumOffset
= rPgDesc
.GetNumOffset();
79 pPage
= static_cast<SwPageFrame
*>( pPage
->GetPrev() );
83 pPage
= static_cast<SwPageFrame
*>(GetLayout()->Lower());
84 pFlow
= pPage
->FindFirstBodyContent();
87 pPage
= static_cast<SwPageFrame
*>(pPage
->GetNext());
88 pFlow
= pPage
->FindFirstBodyContent();
89 assert(pFlow
&& "Document without content?!?");
94 SwFormatPageDesc
aNew( &rDesc
);
95 aNew
.SetNumOffset( oPageNumOffset
);
97 if ( pFlow
->IsInTab() )
98 GetDoc()->SetAttr( aNew
, *const_cast<SwFormat
*>(static_cast<SwFormat
const *>(pFlow
->FindTabFrame()->GetFormat())) );
101 assert(pFlow
->IsContentFrame());
102 SwPaM
aPaM( pFlow
->IsTextFrame()
103 ? *static_cast<SwTextFrame
const*>(pFlow
)->GetTextNodeFirst() // first, for PAGEDESC
104 : *static_cast<const SwNoTextFrame
*>(pFlow
)->GetNode() );
105 GetDoc()->getIDocumentContentOperations().InsertPoolItem(
106 aPaM
, aNew
, SetAttrMode::DEFAULT
, GetLayout());
108 EndAllActionAndCall();
111 void SwFEShell::ChgPageDesc( size_t i
, const SwPageDesc
&rChged
)
114 CurrShell
aCurr( this );
115 //Fix i64842: because Undo has a very special way to handle header/footer content
116 // we have to copy the page descriptor before calling ChgPageDesc.
117 SwPageDesc
aDesc( rChged
);
119 ::sw::UndoGuard
const undoGuard(GetDoc()->GetIDocumentUndoRedo());
120 GetDoc()->CopyPageDesc(rChged
, aDesc
);
122 GetDoc()->ChgPageDesc( i
, aDesc
);
123 EndAllActionAndCall();
126 const SwPageDesc
& SwFEShell::GetPageDesc( size_t i
) const
128 return GetDoc()->GetPageDesc( i
);
131 SwPageDesc
* SwFEShell::FindPageDescByName( const OUString
& rName
,
135 SwPageDesc
* pDesc
= GetDoc()->FindPageDesc(rName
, pPos
);
136 if( !pDesc
&& bGetFromPool
)
138 sal_uInt16 nPoolId
= SwStyleNameMapper::GetPoolIdFromUIName( rName
, SwGetPoolIdFromName::PageDesc
);
139 if( USHRT_MAX
!= nPoolId
&&
140 nullptr != (pDesc
= GetDoc()->getIDocumentStylePoolAccess().GetPageDescFromPool( nPoolId
))
143 *pPos
= GetDoc()->GetPageDescCnt() - 1 ;
148 size_t SwFEShell::GetMousePageDesc( const Point
&rPt
) const
152 const SwPageFrame
* pPage
=
153 static_cast<const SwPageFrame
*>( GetLayout()->Lower() );
156 while( pPage
->GetNext() && rPt
.Y() > pPage
->getFrameArea().Bottom() )
157 pPage
= static_cast<const SwPageFrame
*>( pPage
->GetNext() );
158 SwDoc
*pMyDoc
= GetDoc();
160 if (pMyDoc
->ContainsPageDesc( pPage
->GetPageDesc(), &nPos
) )
167 size_t SwFEShell::GetCurPageDesc( const bool bCalcFrame
) const
169 const SwFrame
*pFrame
= GetCurrFrame( bCalcFrame
);
172 const SwPageFrame
*pPage
= pFrame
->FindPageFrame();
176 if (GetDoc()->ContainsPageDesc( pPage
->GetPageDesc(), &nPos
))
183 // if inside all selection only one PageDesc, return this.
184 // Otherwise return 0 pointer
185 const SwPageDesc
* SwFEShell::GetSelectedPageDescs() const
187 const SwContentNode
* pCNd
;
188 const SwFrame
* pMkFrame
, *pPtFrame
;
189 const SwPageDesc
* pFnd
, *pRetDesc
= reinterpret_cast<SwPageDesc
*>(sal_IntPtr(-1));
191 std::pair
<Point
, bool> const tmp(aNulPt
, false);
193 for(const SwPaM
& rPaM
: GetCursor()->GetRingContainer())
196 if( nullptr != (pCNd
= rPaM
.GetPointContentNode() ) &&
197 nullptr != (pPtFrame
= pCNd
->getLayoutFrame(GetLayout(), nullptr, &tmp
)))
198 pPtFrame
= pPtFrame
->FindPageFrame();
202 if( rPaM
.HasMark() &&
203 nullptr != (pCNd
= rPaM
.GetMarkContentNode() ) &&
204 nullptr != (pMkFrame
= pCNd
->getLayoutFrame(GetLayout(), nullptr, &tmp
)))
205 pMkFrame
= pMkFrame
->FindPageFrame();
209 if( !pMkFrame
|| !pPtFrame
)
211 else if( pMkFrame
== pPtFrame
)
212 pFnd
= static_cast<const SwPageFrame
*>(pMkFrame
)->GetPageDesc();
215 // swap pointer if PtFrame before MkFrame
216 if( static_cast<const SwPageFrame
*>(pMkFrame
)->GetPhyPageNum() >
217 static_cast<const SwPageFrame
*>(pPtFrame
)->GetPhyPageNum() )
219 const SwFrame
* pTmp
= pMkFrame
; pMkFrame
= pPtFrame
; pPtFrame
= pTmp
;
222 // now check from MkFrame to PtFrame for equal PageDescs
223 pFnd
= static_cast<const SwPageFrame
*>(pMkFrame
)->GetPageDesc();
224 while( pFnd
&& pMkFrame
!= pPtFrame
)
226 pMkFrame
= pMkFrame
->GetNext();
227 if( !pMkFrame
|| pFnd
!= static_cast<const SwPageFrame
*>(pMkFrame
)->GetPageDesc() )
232 if( reinterpret_cast<SwPageDesc
*>(sal_IntPtr(-1)) == pRetDesc
)
234 else if( pFnd
!= pRetDesc
)
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */