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>
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
48 for ( size_t nTst
= 0; nTst
< GetPageDescCnt(); ++nTst
)
49 if ( &rDesc
== &GetPageDesc( nTst
) )
51 OSL_ENSURE( bFound
, "ChgCurPageDesc with invalid descriptor." );
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 );
65 pFlow
= pPage
->FindFirstBodyContent();
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();
78 pPage
= static_cast<SwPageFrame
*>( pPage
->GetPrev() );
82 pPage
= static_cast<SwPageFrame
*>(GetLayout()->Lower());
83 pFlow
= pPage
->FindFirstBodyContent();
86 pPage
= static_cast<SwPageFrame
*>(pPage
->GetNext());
87 pFlow
= pPage
->FindFirstBodyContent();
88 OSL_ENSURE( pFlow
, "Document without content?!?" );
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())) );
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
)
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
,
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
))
142 *pPos
= GetDoc()->GetPageDescCnt() - 1 ;
147 size_t SwFEShell::GetMousePageDesc( const Point
&rPt
) const
151 const SwPageFrame
* pPage
=
152 static_cast<const SwPageFrame
*>( GetLayout()->Lower() );
155 while( pPage
->GetNext() && rPt
.Y() > pPage
->getFrameArea().Bottom() )
156 pPage
= static_cast<const SwPageFrame
*>( pPage
->GetNext() );
157 SwDoc
*pMyDoc
= GetDoc();
159 if (pMyDoc
->ContainsPageDesc( pPage
->GetPageDesc(), &nPos
) )
166 size_t SwFEShell::GetCurPageDesc( const bool bCalcFrame
) const
168 const SwFrame
*pFrame
= GetCurrFrame( bCalcFrame
);
171 const SwPageFrame
*pPage
= pFrame
->FindPageFrame();
175 if (GetDoc()->ContainsPageDesc( pPage
->GetPageDesc(), &nPos
))
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));
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();
201 if( rPaM
.HasMark() &&
202 nullptr != (pCNd
= rPaM
.GetContentNode( false ) ) &&
203 nullptr != (pMkFrame
= pCNd
->getLayoutFrame(GetLayout(), nullptr, &tmp
)))
204 pMkFrame
= pMkFrame
->FindPageFrame();
208 if( !pMkFrame
|| !pPtFrame
)
210 else if( pMkFrame
== pPtFrame
)
211 pFnd
= static_cast<const SwPageFrame
*>(pMkFrame
)->GetPageDesc();
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() )
231 if( reinterpret_cast<SwPageDesc
*>(sal_IntPtr(-1)) == pRetDesc
)
233 else if( pFnd
!= pRetDesc
)
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */