1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fedesc.cxx,v $
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>
39 #include <pagefrm.hxx>
40 #include <rootfrm.hxx>
43 #include <fmtpdsc.hxx>
44 #include <pagedesc.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
)
74 //Die SS veraendert keinen PageDesc, sondern setzt nur das Attribut.
75 //Der Pagedesc muss im Dokument vorhanden sein!
77 for ( USHORT nTst
= 0; nTst
< GetPageDescCnt(); ++nTst
)
78 if ( &rDesc
== &GetPageDesc( nTst
) )
80 ASSERT( bFound
, "ChgCurPageDesc mit ungueltigem Descriptor." );
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 );
94 pFlow
= pPage
->FindFirstBodyCntnt();
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();
107 pPage
= (SwPageFrm
*) pPage
->GetPrev();
111 pPage
= (SwPageFrm
*) (GetLayout()->Lower());
112 pFlow
= pPage
->FindFirstBodyCntnt();
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() );
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
)
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
,
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
))
184 // werden immer hinten angehaengt
185 *pPos
= GetDoc()->GetPageDescCnt() - 1 ;
190 USHORT
SwFEShell::GetMousePageDesc( const Point
&rPt
) const
194 const SwPageFrm
* pPage
=
195 static_cast<const SwPageFrm
*>( GetLayout()->Lower() );
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
)
212 USHORT
SwFEShell::GetCurPageDesc( const BOOL bCalcFrm
) const
214 const SwFrm
*pFrm
= GetCurrFrm( bCalcFrm
);
217 const SwPageFrm
*pPage
= pFrm
->FindPageFrm();
220 SwDoc
*pMyDoc
= GetDoc();
221 for ( USHORT i
= 0; i
< GetDoc()->GetPageDescCnt(); ++i
)
223 if ( pPage
->GetPageDesc() == &const_cast<const SwDoc
*>(pMyDoc
)
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;
241 FOREACHPAM_START(this)
243 if( 0 != (pCNd
= PCURCRSR
->GetCntntNode() ) &&
244 0 != ( pPtFrm
= pCNd
->GetFrm( &aNulPt
, 0, FALSE
)) )
245 pPtFrm
= pPtFrm
->FindPageFrm();
249 if( PCURCRSR
->HasMark() &&
250 0 != (pCNd
= PCURCRSR
->GetCntntNode( FALSE
) ) &&
251 0 != ( pMkFrm
= pCNd
->GetFrm( &aNulPt
, 0, FALSE
)) )
252 pMkFrm
= pMkFrm
->FindPageFrm();
257 if( !pMkFrm
|| !pPtFrm
)
259 else if( pMkFrm
== pPtFrm
)
260 pFnd
= ((SwPageFrm
*)pMkFrm
)->GetPageDesc();
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() )
280 if( (SwPageDesc
*)0xffffffff == pRetDesc
)
282 else if( pFnd
!= pRetDesc
)