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