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