1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 #include <tools/ref.hxx> 32 33 #include <hintids.hxx> 34 #include <fesh.hxx> 35 #include <doc.hxx> 36 #include <IDocumentUndoRedo.hxx> 37 #include <pagefrm.hxx> 38 #include <rootfrm.hxx> 39 #include <cntfrm.hxx> 40 #include <pam.hxx> 41 #include <fmtpdsc.hxx> 42 #include <pagedesc.hxx> 43 #include <tabfrm.hxx> 44 #include <edimp.hxx> 45 #include <SwStyleNameMapper.hxx> 46 47 /************************************************************************* 48 |* 49 |* SwFEShell::GetPageDescCnt() 50 |* 51 |* Ersterstellung MA 25. Jan. 93 52 |* Letzte Aenderung MA 25. Jan. 93 53 |* 54 |*************************************************************************/ 55 56 sal_uInt16 SwFEShell::GetPageDescCnt() const 57 { 58 return GetDoc()->GetPageDescCnt(); 59 } 60 61 /************************************************************************* 62 |* 63 |* SwFEShell::ChgCurPageDesc() 64 |* 65 |* Ersterstellung ST ?? 66 |* Letzte Aenderung MA 01. Aug. 94 67 |* 68 |*************************************************************************/ 69 70 void SwFEShell::ChgCurPageDesc( const SwPageDesc& rDesc ) 71 { 72 #ifdef DBG_UTIL 73 //Die SS veraendert keinen PageDesc, sondern setzt nur das Attribut. 74 //Der Pagedesc muss im Dokument vorhanden sein! 75 sal_Bool bFound = sal_False; 76 for ( sal_uInt16 nTst = 0; nTst < GetPageDescCnt(); ++nTst ) 77 if ( &rDesc == &GetPageDesc( nTst ) ) 78 bFound = sal_True; 79 ASSERT( bFound, "ChgCurPageDesc mit ungueltigem Descriptor." ); 80 #endif 81 82 StartAllAction(); 83 84 SwPageFrm *pPage = GetCurrFrm()->FindPageFrm(); 85 const SwFrm *pFlow = 0; 86 sal_uInt16 nPageNmOffset = 0; 87 88 ASSERT( !GetCrsr()->HasMark(), "ChgCurPageDesc nur ohne Selektion!"); 89 90 SET_CURR_SHELL( this ); 91 while ( pPage ) 92 { 93 pFlow = pPage->FindFirstBodyCntnt(); 94 if ( pFlow ) 95 { 96 if ( pFlow->IsInTab() ) 97 pFlow = pFlow->FindTabFrm(); 98 const SwFmtPageDesc& rPgDesc = pFlow->GetAttrSet()->GetPageDesc(); 99 if( rPgDesc.GetPageDesc() ) 100 { 101 // wir haben ihn den Schlingel 102 nPageNmOffset = rPgDesc.GetNumOffset(); 103 break; 104 } 105 } 106 pPage = (SwPageFrm*) pPage->GetPrev(); 107 } 108 if ( !pPage ) 109 { 110 pPage = (SwPageFrm*) (GetLayout()->Lower()); 111 pFlow = pPage->FindFirstBodyCntnt(); 112 if ( !pFlow ) 113 { 114 pPage = (SwPageFrm*)pPage->GetNext(); 115 pFlow = pPage->FindFirstBodyCntnt(); 116 ASSERT( pFlow, "Dokuemnt ohne Inhalt?!?" ); 117 } 118 } 119 120 // Seitennummer mitnehmen 121 SwFmtPageDesc aNew( &rDesc ); 122 aNew.SetNumOffset( nPageNmOffset ); 123 124 if ( pFlow->IsInTab() ) 125 GetDoc()->SetAttr( aNew, *(SwFmt*)pFlow->FindTabFrm()->GetFmt() ); 126 else 127 { 128 SwPaM aPaM( *((SwCntntFrm*)pFlow)->GetNode() ); 129 GetDoc()->InsertPoolItem( aPaM, aNew, 0 ); 130 } 131 EndAllActionAndCall(); 132 } 133 134 /************************************************************************* 135 |* 136 |* SwFEShell::ChgPageDesc() 137 |* 138 |* Ersterstellung MA 25. Jan. 93 139 |* Letzte Aenderung MA 24. Jan. 95 140 |* 141 |*************************************************************************/ 142 143 void SwFEShell::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged ) 144 { 145 StartAllAction(); 146 SET_CURR_SHELL( this ); 147 //Fix i64842: because Undo has a very special way to handle header/footer content 148 // we have to copy the page descriptor before calling ChgPageDesc. 149 SwPageDesc aDesc( rChged ); 150 { 151 ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo()); 152 GetDoc()->CopyPageDesc(rChged, aDesc); 153 } 154 GetDoc()->ChgPageDesc( i, aDesc ); 155 EndAllActionAndCall(); 156 } 157 158 /************************************************************************* 159 |* 160 |* SwFEShell::GetPageDesc(), GetCurPageDesc() 161 |* 162 |* Ersterstellung MA 25. Jan. 93 163 |* Letzte Aenderung MA 23. Apr. 93 164 | 165 |*************************************************************************/ 166 167 const SwPageDesc& SwFEShell::GetPageDesc( sal_uInt16 i ) const 168 { 169 return const_cast<const SwDoc *>(GetDoc())->GetPageDesc( i ); 170 } 171 172 SwPageDesc* SwFEShell::FindPageDescByName( const String& rName, 173 sal_Bool bGetFromPool, 174 sal_uInt16* pPos ) 175 { 176 SwPageDesc* pDesc = GetDoc()->FindPageDescByName( rName, pPos ); 177 if( !pDesc && bGetFromPool ) 178 { 179 sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( rName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC ); 180 if( USHRT_MAX != nPoolId && 181 0 != (pDesc = GetDoc()->GetPageDescFromPool( nPoolId )) 182 && pPos ) 183 // werden immer hinten angehaengt 184 *pPos = GetDoc()->GetPageDescCnt() - 1 ; 185 } 186 return pDesc; 187 } 188 189 sal_uInt16 SwFEShell::GetMousePageDesc( const Point &rPt ) const 190 { 191 if( GetLayout() ) 192 { 193 const SwPageFrm* pPage = 194 static_cast<const SwPageFrm*>( GetLayout()->Lower() ); 195 if( pPage ) 196 { 197 while( pPage->GetNext() && rPt.Y() > pPage->Frm().Bottom() ) 198 pPage = static_cast<const SwPageFrm*>( pPage->GetNext() ); 199 SwDoc *pMyDoc = GetDoc(); 200 for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i ) 201 { 202 if ( pPage->GetPageDesc() == &const_cast<const SwDoc *>(pMyDoc) 203 ->GetPageDesc(i) ) 204 return i; 205 } 206 } 207 } 208 return 0; 209 } 210 211 sal_uInt16 SwFEShell::GetCurPageDesc( const sal_Bool bCalcFrm ) const 212 { 213 const SwFrm *pFrm = GetCurrFrm( bCalcFrm ); 214 if ( pFrm ) 215 { 216 const SwPageFrm *pPage = pFrm->FindPageFrm(); 217 if ( pPage ) 218 { 219 SwDoc *pMyDoc = GetDoc(); 220 for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i ) 221 { 222 if ( pPage->GetPageDesc() == &const_cast<const SwDoc *>(pMyDoc) 223 ->GetPageDesc(i) ) 224 return i; 225 } 226 } 227 } 228 return 0; 229 } 230 231 // if inside all selection only one PageDesc, return this. 232 // Otherwise return 0 pointer 233 const SwPageDesc* SwFEShell::GetSelectedPageDescs() const 234 { 235 const SwCntntNode* pCNd; 236 const SwFrm* pMkFrm, *pPtFrm; 237 const SwPageDesc* pFnd, *pRetDesc = (SwPageDesc*)0xffffffff; 238 const Point aNulPt; 239 240 FOREACHPAM_START(this) 241 242 if( 0 != (pCNd = PCURCRSR->GetCntntNode() ) && 243 0 != ( pPtFrm = pCNd->getLayoutFrm( GetLayout(), &aNulPt, 0, sal_False )) ) 244 pPtFrm = pPtFrm->FindPageFrm(); 245 else 246 pPtFrm = 0; 247 248 if( PCURCRSR->HasMark() && 249 0 != (pCNd = PCURCRSR->GetCntntNode( sal_False ) ) && 250 0 != ( pMkFrm = pCNd->getLayoutFrm( GetLayout(), &aNulPt, 0, sal_False )) ) 251 pMkFrm = pMkFrm->FindPageFrm(); 252 else 253 pMkFrm = pPtFrm; 254 255 256 if( !pMkFrm || !pPtFrm ) 257 pFnd = 0; 258 else if( pMkFrm == pPtFrm ) 259 pFnd = ((SwPageFrm*)pMkFrm)->GetPageDesc(); 260 else 261 { 262 // swap pointer if PtFrm before MkFrm 263 if( ((SwPageFrm*)pMkFrm)->GetPhyPageNum() > 264 ((SwPageFrm*)pPtFrm)->GetPhyPageNum() ) 265 { 266 const SwFrm* pTmp = pMkFrm; pMkFrm = pPtFrm; pPtFrm = pTmp; 267 } 268 269 // now check from MkFrm to PtFrm for equal PageDescs 270 pFnd = ((SwPageFrm*)pMkFrm)->GetPageDesc(); 271 while( pFnd && pMkFrm != pPtFrm ) 272 { 273 pMkFrm = pMkFrm->GetNext(); 274 if( !pMkFrm || pFnd != ((SwPageFrm*)pMkFrm)->GetPageDesc() ) 275 pFnd = 0; 276 } 277 } 278 279 if( (SwPageDesc*)0xffffffff == pRetDesc ) 280 pRetDesc = pFnd; 281 else if( pFnd != pRetDesc ) 282 { 283 pRetDesc = 0; 284 break; 285 } 286 287 FOREACHPAM_END() 288 289 return pRetDesc; 290 } 291 292 293 294