update dev300-m58
[ooovba.git] / sw / source / core / frmedt / fedesc.cxx
blobe46453630889216d7e50865149b1d4673ccc201d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fedesc.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <tools/ref.hxx>
37 #include <fesh.hxx>
38 #include <doc.hxx>
39 #include <pagefrm.hxx>
40 #include <rootfrm.hxx>
41 #include <cntfrm.hxx>
42 #include <pam.hxx>
43 #include <fmtpdsc.hxx>
44 #include <pagedesc.hxx>
45 #include <tabfrm.hxx>
46 #include <edimp.hxx>
47 #include <SwStyleNameMapper.hxx>
48 /*************************************************************************
50 |* SwFEShell::GetPageDescCnt()
52 |* Ersterstellung MA 25. Jan. 93
53 |* Letzte Aenderung MA 25. Jan. 93
55 |*************************************************************************/
57 USHORT SwFEShell::GetPageDescCnt() const
59 return GetDoc()->GetPageDescCnt();
62 /*************************************************************************
64 |* SwFEShell::ChgCurPageDesc()
66 |* Ersterstellung ST ??
67 |* Letzte Aenderung MA 01. Aug. 94
69 |*************************************************************************/
71 void SwFEShell::ChgCurPageDesc( const SwPageDesc& rDesc )
73 #ifndef PRODUCT
74 //Die SS veraendert keinen PageDesc, sondern setzt nur das Attribut.
75 //Der Pagedesc muss im Dokument vorhanden sein!
76 BOOL bFound = FALSE;
77 for ( USHORT nTst = 0; nTst < GetPageDescCnt(); ++nTst )
78 if ( &rDesc == &GetPageDesc( nTst ) )
79 bFound = TRUE;
80 ASSERT( bFound, "ChgCurPageDesc mit ungueltigem Descriptor." );
81 #endif
83 StartAllAction();
85 SwPageFrm *pPage = GetCurrFrm()->FindPageFrm();
86 const SwFrm *pFlow = 0;
87 USHORT nPageNmOffset = 0;
89 ASSERT( !GetCrsr()->HasMark(), "ChgCurPageDesc nur ohne Selektion!");
91 SET_CURR_SHELL( this );
92 while ( pPage )
94 pFlow = pPage->FindFirstBodyCntnt();
95 if ( pFlow )
97 if ( pFlow->IsInTab() )
98 pFlow = pFlow->FindTabFrm();
99 const SwFmtPageDesc& rPgDesc = pFlow->GetAttrSet()->GetPageDesc();
100 if( rPgDesc.GetPageDesc() )
102 // wir haben ihn den Schlingel
103 nPageNmOffset = rPgDesc.GetNumOffset();
104 break;
107 pPage = (SwPageFrm*) pPage->GetPrev();
109 if ( !pPage )
111 pPage = (SwPageFrm*) (GetLayout()->Lower());
112 pFlow = pPage->FindFirstBodyCntnt();
113 if ( !pFlow )
115 pPage = (SwPageFrm*)pPage->GetNext();
116 pFlow = pPage->FindFirstBodyCntnt();
117 ASSERT( pFlow, "Dokuemnt ohne Inhalt?!?" );
121 // Seitennummer mitnehmen
122 SwFmtPageDesc aNew( &rDesc );
123 aNew.SetNumOffset( nPageNmOffset );
125 if ( pFlow->IsInTab() )
126 GetDoc()->SetAttr( aNew, *(SwFmt*)pFlow->FindTabFrm()->GetFmt() );
127 else
129 SwPaM aPaM( *((SwCntntFrm*)pFlow)->GetNode() );
130 GetDoc()->Insert( aPaM, aNew, 0 );
132 EndAllActionAndCall();
135 /*************************************************************************
137 |* SwFEShell::ChgPageDesc()
139 |* Ersterstellung MA 25. Jan. 93
140 |* Letzte Aenderung MA 24. Jan. 95
142 |*************************************************************************/
144 void SwFEShell::ChgPageDesc( USHORT i, const SwPageDesc &rChged )
146 StartAllAction();
147 SET_CURR_SHELL( this );
148 //Fix i64842: because Undo has a very special way to handle header/footer content
149 // we have to copy the page descriptor before calling ChgPageDesc.
150 const sal_Bool bDoesUndo( GetDoc()->DoesUndo() );
151 SwPageDesc aDesc( rChged );
152 GetDoc()->DoUndo( sal_False );
153 GetDoc()->CopyPageDesc(rChged, aDesc);
154 GetDoc()->DoUndo( bDoesUndo );
155 GetDoc()->ChgPageDesc( i, aDesc );
156 EndAllActionAndCall();
159 /*************************************************************************
161 |* SwFEShell::GetPageDesc(), GetCurPageDesc()
163 |* Ersterstellung MA 25. Jan. 93
164 |* Letzte Aenderung MA 23. Apr. 93
166 |*************************************************************************/
168 const SwPageDesc& SwFEShell::GetPageDesc( USHORT i ) const
170 return const_cast<const SwDoc *>(GetDoc())->GetPageDesc( i );
173 SwPageDesc* SwFEShell::FindPageDescByName( const String& rName,
174 BOOL bGetFromPool,
175 USHORT* pPos )
177 SwPageDesc* pDesc = GetDoc()->FindPageDescByName( rName, pPos );
178 if( !pDesc && bGetFromPool )
180 USHORT nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( rName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC );
181 if( USHRT_MAX != nPoolId &&
182 0 != (pDesc = GetDoc()->GetPageDescFromPool( nPoolId ))
183 && pPos )
184 // werden immer hinten angehaengt
185 *pPos = GetDoc()->GetPageDescCnt() - 1 ;
187 return pDesc;
190 USHORT SwFEShell::GetMousePageDesc( const Point &rPt ) const
192 if( GetLayout() )
194 const SwPageFrm* pPage =
195 static_cast<const SwPageFrm*>( GetLayout()->Lower() );
196 if( pPage )
198 while( pPage->GetNext() && rPt.Y() > pPage->Frm().Bottom() )
199 pPage = static_cast<const SwPageFrm*>( pPage->GetNext() );
200 SwDoc *pMyDoc = GetDoc();
201 for ( USHORT i = 0; i < GetDoc()->GetPageDescCnt(); ++i )
203 if ( pPage->GetPageDesc() == &const_cast<const SwDoc *>(pMyDoc)
204 ->GetPageDesc(i) )
205 return i;
209 return 0;
212 USHORT SwFEShell::GetCurPageDesc( const BOOL bCalcFrm ) const
214 const SwFrm *pFrm = GetCurrFrm( bCalcFrm );
215 if ( pFrm )
217 const SwPageFrm *pPage = pFrm->FindPageFrm();
218 if ( pPage )
220 SwDoc *pMyDoc = GetDoc();
221 for ( USHORT i = 0; i < GetDoc()->GetPageDescCnt(); ++i )
223 if ( pPage->GetPageDesc() == &const_cast<const SwDoc *>(pMyDoc)
224 ->GetPageDesc(i) )
225 return i;
229 return 0;
232 // if inside all selection only one PageDesc, return this.
233 // Otherwise return 0 pointer
234 const SwPageDesc* SwFEShell::GetSelectedPageDescs() const
236 const SwCntntNode* pCNd;
237 const SwFrm* pMkFrm, *pPtFrm;
238 const SwPageDesc* pFnd, *pRetDesc = (SwPageDesc*)0xffffffff;
239 const Point aNulPt;
241 FOREACHPAM_START(this)
243 if( 0 != (pCNd = PCURCRSR->GetCntntNode() ) &&
244 0 != ( pPtFrm = pCNd->GetFrm( &aNulPt, 0, FALSE )) )
245 pPtFrm = pPtFrm->FindPageFrm();
246 else
247 pPtFrm = 0;
249 if( PCURCRSR->HasMark() &&
250 0 != (pCNd = PCURCRSR->GetCntntNode( FALSE ) ) &&
251 0 != ( pMkFrm = pCNd->GetFrm( &aNulPt, 0, FALSE )) )
252 pMkFrm = pMkFrm->FindPageFrm();
253 else
254 pMkFrm = pPtFrm;
257 if( !pMkFrm || !pPtFrm )
258 pFnd = 0;
259 else if( pMkFrm == pPtFrm )
260 pFnd = ((SwPageFrm*)pMkFrm)->GetPageDesc();
261 else
263 // swap pointer if PtFrm before MkFrm
264 if( ((SwPageFrm*)pMkFrm)->GetPhyPageNum() >
265 ((SwPageFrm*)pPtFrm)->GetPhyPageNum() )
267 const SwFrm* pTmp = pMkFrm; pMkFrm = pPtFrm; pPtFrm = pTmp;
270 // now check from MkFrm to PtFrm for equal PageDescs
271 pFnd = ((SwPageFrm*)pMkFrm)->GetPageDesc();
272 while( pFnd && pMkFrm != pPtFrm )
274 pMkFrm = pMkFrm->GetNext();
275 if( !pMkFrm || pFnd != ((SwPageFrm*)pMkFrm)->GetPageDesc() )
276 pFnd = 0;
280 if( (SwPageDesc*)0xffffffff == pRetDesc )
281 pRetDesc = pFnd;
282 else if( pFnd != pRetDesc )
284 pRetDesc = 0;
285 break;
288 FOREACHPAM_END()
290 return pRetDesc;