Line data Source code
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>
24 : #include <IDocumentContentOperations.hxx>
25 : #include <IDocumentStylePoolAccess.hxx>
26 : #include <pagefrm.hxx>
27 : #include <rootfrm.hxx>
28 : #include <cntfrm.hxx>
29 : #include <pam.hxx>
30 : #include <fmtpdsc.hxx>
31 : #include <pagedesc.hxx>
32 : #include <tabfrm.hxx>
33 : #include <edimp.hxx>
34 : #include <SwStyleNameMapper.hxx>
35 :
36 1661 : size_t SwFEShell::GetPageDescCnt() const
37 : {
38 1661 : return GetDoc()->GetPageDescCnt();
39 : }
40 :
41 0 : void SwFEShell::ChgCurPageDesc( const SwPageDesc& rDesc )
42 : {
43 : #if OSL_DEBUG_LEVEL > 0
44 : // SS does not change PageDesc, but only sets the attibute.
45 : // The Pagedesc should be available in the document
46 : bool bFound = false;
47 : for ( size_t nTst = 0; nTst < GetPageDescCnt(); ++nTst )
48 : if ( &rDesc == &GetPageDesc( nTst ) )
49 : bFound = true;
50 : OSL_ENSURE( bFound, "ChgCurPageDesc with invalid descriptor." );
51 : #endif
52 :
53 0 : StartAllAction();
54 :
55 0 : SwPageFrm *pPage = GetCurrFrm()->FindPageFrm();
56 0 : const SwFrm *pFlow = 0;
57 0 : ::boost::optional<sal_uInt16> oPageNumOffset;
58 :
59 : OSL_ENSURE( !GetCrsr()->HasMark(), "ChgCurPageDesc only without selection!");
60 :
61 0 : SET_CURR_SHELL( this );
62 0 : while ( pPage )
63 : {
64 0 : pFlow = pPage->FindFirstBodyContent();
65 0 : if ( pFlow )
66 : {
67 0 : if ( pFlow->IsInTab() )
68 0 : pFlow = pFlow->FindTabFrm();
69 0 : const SwFormatPageDesc& rPgDesc = pFlow->GetAttrSet()->GetPageDesc();
70 0 : if( rPgDesc.GetPageDesc() )
71 : {
72 : // wir haben ihn den Schlingel
73 0 : oPageNumOffset = rPgDesc.GetNumOffset();
74 0 : break;
75 : }
76 : }
77 0 : pPage = static_cast<SwPageFrm*>( pPage->GetPrev() );
78 : }
79 0 : if ( !pPage )
80 : {
81 0 : pPage = static_cast<SwPageFrm*>(GetLayout()->Lower());
82 0 : pFlow = pPage->FindFirstBodyContent();
83 0 : if ( !pFlow )
84 : {
85 0 : pPage = static_cast<SwPageFrm*>(pPage->GetNext());
86 0 : pFlow = pPage->FindFirstBodyContent();
87 : OSL_ENSURE( pFlow, "Dokuemnt ohne Inhalt?!?" );
88 : }
89 : }
90 :
91 : // use pagenumber
92 0 : SwFormatPageDesc aNew( &rDesc );
93 0 : aNew.SetNumOffset( oPageNumOffset );
94 :
95 0 : if ( pFlow->IsInTab() )
96 0 : GetDoc()->SetAttr( aNew, *const_cast<SwFormat*>(static_cast<SwFormat const *>(pFlow->FindTabFrm()->GetFormat())) );
97 : else
98 : {
99 0 : SwPaM aPaM( *static_cast<const SwContentFrm*>(pFlow)->GetNode() );
100 0 : GetDoc()->getIDocumentContentOperations().InsertPoolItem( aPaM, aNew );
101 : }
102 0 : EndAllActionAndCall();
103 0 : }
104 :
105 0 : void SwFEShell::ChgPageDesc( size_t i, const SwPageDesc &rChged )
106 : {
107 0 : StartAllAction();
108 0 : SET_CURR_SHELL( this );
109 : //Fix i64842: because Undo has a very special way to handle header/footer content
110 : // we have to copy the page descriptor before calling ChgPageDesc.
111 0 : SwPageDesc aDesc( rChged );
112 : {
113 0 : ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
114 0 : GetDoc()->CopyPageDesc(rChged, aDesc);
115 : }
116 0 : GetDoc()->ChgPageDesc( i, aDesc );
117 0 : EndAllActionAndCall();
118 0 : }
119 :
120 8705 : const SwPageDesc& SwFEShell::GetPageDesc( size_t i ) const
121 : {
122 8705 : return GetDoc()->GetPageDesc( i );
123 : }
124 :
125 93 : SwPageDesc* SwFEShell::FindPageDescByName( const OUString& rName,
126 : bool bGetFromPool,
127 : size_t* pPos )
128 : {
129 93 : SwPageDesc* pDesc = GetDoc()->FindPageDesc(rName, pPos);
130 93 : if( !pDesc && bGetFromPool )
131 : {
132 0 : sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( rName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC );
133 0 : if( USHRT_MAX != nPoolId &&
134 0 : 0 != (pDesc = GetDoc()->getIDocumentStylePoolAccess().GetPageDescFromPool( nPoolId ))
135 0 : && pPos )
136 : // appended always
137 0 : *pPos = GetDoc()->GetPageDescCnt() - 1 ;
138 : }
139 93 : return pDesc;
140 : }
141 :
142 0 : size_t SwFEShell::GetMousePageDesc( const Point &rPt ) const
143 : {
144 0 : if( GetLayout() )
145 : {
146 : const SwPageFrm* pPage =
147 0 : static_cast<const SwPageFrm*>( GetLayout()->Lower() );
148 0 : if( pPage )
149 : {
150 0 : while( pPage->GetNext() && rPt.Y() > pPage->Frm().Bottom() )
151 0 : pPage = static_cast<const SwPageFrm*>( pPage->GetNext() );
152 0 : SwDoc *pMyDoc = GetDoc();
153 : size_t nPos;
154 0 : if (pMyDoc->ContainsPageDesc( pPage->GetPageDesc(), &nPos ) )
155 0 : return nPos;
156 : }
157 : }
158 0 : return 0;
159 : }
160 :
161 8705 : size_t SwFEShell::GetCurPageDesc( const bool bCalcFrm ) const
162 : {
163 8705 : const SwFrm *pFrm = GetCurrFrm( bCalcFrm );
164 8705 : if ( pFrm )
165 : {
166 8705 : const SwPageFrm *pPage = pFrm->FindPageFrm();
167 8705 : if ( pPage )
168 : {
169 : size_t nPos;
170 8705 : if (GetDoc()->ContainsPageDesc( pPage->GetPageDesc(), &nPos ))
171 8705 : return nPos;
172 : }
173 : }
174 0 : return 0;
175 : }
176 :
177 : // if inside all selection only one PageDesc, return this.
178 : // Otherwise return 0 pointer
179 0 : const SwPageDesc* SwFEShell::GetSelectedPageDescs() const
180 : {
181 : const SwContentNode* pCNd;
182 : const SwFrm* pMkFrm, *pPtFrm;
183 0 : const SwPageDesc* pFnd, *pRetDesc = reinterpret_cast<SwPageDesc*>(sal_IntPtr(-1));
184 0 : const Point aNulPt;
185 :
186 0 : for(SwPaM& rPaM : GetCrsr()->GetRingContainer())
187 : {
188 :
189 0 : if( 0 != (pCNd = rPaM.GetContentNode() ) &&
190 0 : 0 != ( pPtFrm = pCNd->getLayoutFrm( GetLayout(), &aNulPt, 0, false )) )
191 0 : pPtFrm = pPtFrm->FindPageFrm();
192 : else
193 0 : pPtFrm = 0;
194 :
195 0 : if( rPaM.HasMark() &&
196 0 : 0 != (pCNd = rPaM.GetContentNode( false ) ) &&
197 0 : 0 != ( pMkFrm = pCNd->getLayoutFrm( GetLayout(), &aNulPt, 0, false )) )
198 0 : pMkFrm = pMkFrm->FindPageFrm();
199 : else
200 0 : pMkFrm = pPtFrm;
201 :
202 0 : if( !pMkFrm || !pPtFrm )
203 0 : pFnd = 0;
204 0 : else if( pMkFrm == pPtFrm )
205 0 : pFnd = static_cast<const SwPageFrm*>(pMkFrm)->GetPageDesc();
206 : else
207 : {
208 : // swap pointer if PtFrm before MkFrm
209 0 : if( static_cast<const SwPageFrm*>(pMkFrm)->GetPhyPageNum() >
210 0 : static_cast<const SwPageFrm*>(pPtFrm)->GetPhyPageNum() )
211 : {
212 0 : const SwFrm* pTmp = pMkFrm; pMkFrm = pPtFrm; pPtFrm = pTmp;
213 : }
214 :
215 : // now check from MkFrm to PtFrm for equal PageDescs
216 0 : pFnd = static_cast<const SwPageFrm*>(pMkFrm)->GetPageDesc();
217 0 : while( pFnd && pMkFrm != pPtFrm )
218 : {
219 0 : pMkFrm = pMkFrm->GetNext();
220 0 : if( !pMkFrm || pFnd != static_cast<const SwPageFrm*>(pMkFrm)->GetPageDesc() )
221 0 : pFnd = 0;
222 : }
223 : }
224 :
225 0 : if( reinterpret_cast<SwPageDesc*>(sal_IntPtr(-1)) == pRetDesc )
226 0 : pRetDesc = pFnd;
227 0 : else if( pFnd != pRetDesc )
228 : {
229 0 : pRetDesc = 0;
230 0 : break;
231 : }
232 :
233 : }
234 :
235 0 : return pRetDesc;
236 177 : }
237 :
238 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|