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 1992 : sal_uInt16 SwFEShell::GetPageDescCnt() const
37 : {
38 1992 : 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 ( sal_uInt16 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->FindFirstBodyCntnt();
65 0 : if ( pFlow )
66 : {
67 0 : if ( pFlow->IsInTab() )
68 0 : pFlow = pFlow->FindTabFrm();
69 0 : const SwFmtPageDesc& 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 = (SwPageFrm*) pPage->GetPrev();
78 : }
79 0 : if ( !pPage )
80 : {
81 0 : pPage = (SwPageFrm*) (GetLayout()->Lower());
82 0 : pFlow = pPage->FindFirstBodyCntnt();
83 0 : if ( !pFlow )
84 : {
85 0 : pPage = (SwPageFrm*)pPage->GetNext();
86 0 : pFlow = pPage->FindFirstBodyCntnt();
87 : OSL_ENSURE( pFlow, "Dokuemnt ohne Inhalt?!?" );
88 : }
89 : }
90 :
91 : // use pagenumber
92 0 : SwFmtPageDesc aNew( &rDesc );
93 0 : aNew.SetNumOffset( oPageNumOffset );
94 :
95 0 : if ( pFlow->IsInTab() )
96 0 : GetDoc()->SetAttr( aNew, *(SwFmt*)pFlow->FindTabFrm()->GetFmt() );
97 : else
98 : {
99 0 : SwPaM aPaM( *((SwCntntFrm*)pFlow)->GetNode() );
100 0 : GetDoc()->getIDocumentContentOperations().InsertPoolItem( aPaM, aNew, 0 );
101 : }
102 0 : EndAllActionAndCall();
103 0 : }
104 :
105 0 : void SwFEShell::ChgPageDesc( sal_uInt16 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 8654 : const SwPageDesc& SwFEShell::GetPageDesc( sal_uInt16 i ) const
121 : {
122 8654 : return GetDoc()->GetPageDesc( i );
123 : }
124 :
125 26 : SwPageDesc* SwFEShell::FindPageDescByName( const OUString& rName,
126 : bool bGetFromPool,
127 : sal_uInt16* pPos )
128 : {
129 26 : SwPageDesc* pDesc = GetDoc()->FindPageDesc(rName, pPos);
130 26 : 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 26 : return pDesc;
140 : }
141 :
142 0 : sal_uInt16 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 0 : for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i )
154 : {
155 0 : if ( pPage->GetPageDesc() == &pMyDoc->GetPageDesc(i) )
156 0 : return i;
157 : }
158 : }
159 : }
160 0 : return 0;
161 : }
162 :
163 8654 : sal_uInt16 SwFEShell::GetCurPageDesc( const bool bCalcFrm ) const
164 : {
165 8654 : const SwFrm *pFrm = GetCurrFrm( bCalcFrm );
166 8654 : if ( pFrm )
167 : {
168 8654 : const SwPageFrm *pPage = pFrm->FindPageFrm();
169 8654 : if ( pPage )
170 : {
171 8654 : SwDoc *pMyDoc = GetDoc();
172 8819 : for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i )
173 : {
174 8819 : if ( pPage->GetPageDesc() == &pMyDoc->GetPageDesc(i) )
175 8654 : return i;
176 : }
177 : }
178 : }
179 0 : return 0;
180 : }
181 :
182 : // if inside all selection only one PageDesc, return this.
183 : // Otherwise return 0 pointer
184 0 : const SwPageDesc* SwFEShell::GetSelectedPageDescs() const
185 : {
186 : const SwCntntNode* pCNd;
187 : const SwFrm* pMkFrm, *pPtFrm;
188 0 : const SwPageDesc* pFnd, *pRetDesc = (SwPageDesc*)0xffffffff;
189 0 : const Point aNulPt;
190 :
191 0 : FOREACHPAM_START(GetCrsr())
192 :
193 0 : if( 0 != (pCNd = PCURCRSR->GetCntntNode() ) &&
194 0 : 0 != ( pPtFrm = pCNd->getLayoutFrm( GetLayout(), &aNulPt, 0, false )) )
195 0 : pPtFrm = pPtFrm->FindPageFrm();
196 : else
197 0 : pPtFrm = 0;
198 :
199 0 : if( PCURCRSR->HasMark() &&
200 0 : 0 != (pCNd = PCURCRSR->GetCntntNode( false ) ) &&
201 0 : 0 != ( pMkFrm = pCNd->getLayoutFrm( GetLayout(), &aNulPt, 0, false )) )
202 0 : pMkFrm = pMkFrm->FindPageFrm();
203 : else
204 0 : pMkFrm = pPtFrm;
205 :
206 0 : if( !pMkFrm || !pPtFrm )
207 0 : pFnd = 0;
208 0 : else if( pMkFrm == pPtFrm )
209 0 : pFnd = ((SwPageFrm*)pMkFrm)->GetPageDesc();
210 : else
211 : {
212 : // swap pointer if PtFrm before MkFrm
213 0 : if( ((SwPageFrm*)pMkFrm)->GetPhyPageNum() >
214 0 : ((SwPageFrm*)pPtFrm)->GetPhyPageNum() )
215 : {
216 0 : const SwFrm* pTmp = pMkFrm; pMkFrm = pPtFrm; pPtFrm = pTmp;
217 : }
218 :
219 : // now check from MkFrm to PtFrm for equal PageDescs
220 0 : pFnd = ((SwPageFrm*)pMkFrm)->GetPageDesc();
221 0 : while( pFnd && pMkFrm != pPtFrm )
222 : {
223 0 : pMkFrm = pMkFrm->GetNext();
224 0 : if( !pMkFrm || pFnd != ((SwPageFrm*)pMkFrm)->GetPageDesc() )
225 0 : pFnd = 0;
226 : }
227 : }
228 :
229 0 : if( (SwPageDesc*)0xffffffff == pRetDesc )
230 0 : pRetDesc = pFnd;
231 0 : else if( pFnd != pRetDesc )
232 : {
233 0 : pRetDesc = 0;
234 0 : break;
235 : }
236 :
237 0 : FOREACHPAM_END()
238 :
239 0 : return pRetDesc;
240 270 : }
241 :
242 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|