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 : #include <editeng/pbinitem.hxx>
21 : #include <editeng/ulspitem.hxx>
22 : #include <editeng/boxitem.hxx>
23 : #include <editeng/brshitem.hxx>
24 : #include <editeng/shaditem.hxx>
25 : #include "editeng/frmdiritem.hxx"
26 : #include <fmtclds.hxx>
27 : #include <fmtfsize.hxx>
28 : #include <pagefrm.hxx>
29 : #include <pagedesc.hxx>
30 : #include <swtable.hxx>
31 : #include <frmtool.hxx>
32 : #include <doc.hxx> // for GetAttrPool
33 : #include <poolfmt.hxx>
34 : #include <switerator.hxx>
35 :
36 :
37 : using namespace ::com::sun::star;
38 :
39 : /*************************************************************************
40 : |*
41 : |* SwPageDesc::SwPageDesc()
42 : |*
43 : |*************************************************************************/
44 :
45 :
46 :
47 774 : SwPageDesc::SwPageDesc( const String& rName, SwFrmFmt *pFmt, SwDoc *pDc ) :
48 : SwModify( 0 ),
49 : aDescName( rName ),
50 774 : aMaster( pDc->GetAttrPool(), rName, pFmt ),
51 774 : aLeft( pDc->GetAttrPool(), rName, pFmt ),
52 774 : aFirst( pDc->GetAttrPool(), rName, pFmt ),
53 : aDepend( this, 0 ),
54 : pFollow( this ),
55 : nRegHeight( 0 ),
56 : nRegAscent( 0 ),
57 : eUse( (UseOnPage)(nsUseOnPage::PD_ALL | nsUseOnPage::PD_HEADERSHARE | nsUseOnPage::PD_FOOTERSHARE | nsUseOnPage::PD_FIRSTSHARE ) ),
58 : bLandscape( sal_False ),
59 : bHidden( sal_False ),
60 3096 : aFtnInfo()
61 : {
62 774 : }
63 :
64 830 : SwPageDesc::SwPageDesc( const SwPageDesc &rCpy ) :
65 : SwModify( 0 ),
66 830 : aDescName( rCpy.GetName() ),
67 830 : aNumType( rCpy.GetNumType() ),
68 830 : aMaster( rCpy.GetMaster() ),
69 830 : aLeft( rCpy.GetLeft() ),
70 830 : aFirst( rCpy.GetFirst() ),
71 830 : aDepend( this, (SwModify*)rCpy.aDepend.GetRegisteredIn() ),
72 : pFollow( rCpy.pFollow ),
73 830 : nRegHeight( rCpy.GetRegHeight() ),
74 830 : nRegAscent( rCpy.GetRegAscent() ),
75 830 : eUse( rCpy.ReadUseOn() ),
76 830 : bLandscape( rCpy.GetLandscape() ),
77 830 : bHidden( rCpy.IsHidden() ),
78 9960 : aFtnInfo( rCpy.GetFtnInfo() )
79 : {
80 830 : }
81 :
82 0 : SwPageDesc & SwPageDesc::operator = (const SwPageDesc & rSrc)
83 : {
84 0 : aDescName = rSrc.aDescName;
85 0 : aNumType = rSrc.aNumType;
86 0 : aMaster = rSrc.aMaster;
87 0 : aLeft = rSrc.aLeft;
88 0 : aFirst = rSrc.aFirst;
89 :
90 0 : if (rSrc.pFollow == &rSrc)
91 0 : pFollow = this;
92 : else
93 0 : pFollow = rSrc.pFollow;
94 :
95 0 : nRegHeight = rSrc.nRegHeight;
96 0 : nRegAscent = rSrc.nRegAscent;
97 0 : eUse = rSrc.eUse;
98 0 : bLandscape = rSrc.bLandscape;
99 0 : return *this;
100 : }
101 :
102 2132 : SwPageDesc::~SwPageDesc()
103 : {
104 2132 : }
105 :
106 : /*************************************************************************
107 : |*
108 : |* SwPageDesc::Mirror()
109 : |*
110 : |* Description Only the margin is mirrored.
111 : |* Attributes like borders and so on are copied 1:1.
112 : |*
113 : |*************************************************************************/
114 :
115 :
116 :
117 0 : void SwPageDesc::Mirror()
118 : {
119 : //Only the margins are mirrored, all other values are just copied.
120 0 : SvxLRSpaceItem aLR( RES_LR_SPACE );
121 0 : const SvxLRSpaceItem &rLR = aMaster.GetLRSpace();
122 0 : aLR.SetLeft( rLR.GetRight() );
123 0 : aLR.SetRight( rLR.GetLeft() );
124 :
125 0 : SfxItemSet aSet( *aMaster.GetAttrSet().GetPool(),
126 0 : aMaster.GetAttrSet().GetRanges() );
127 0 : aSet.Put( aLR );
128 0 : aSet.Put( aMaster.GetFrmSize() );
129 0 : aSet.Put( aMaster.GetPaperBin() );
130 0 : aSet.Put( aMaster.GetULSpace() );
131 0 : aSet.Put( aMaster.GetBox() );
132 0 : aSet.Put( aMaster.GetBackground() );
133 0 : aSet.Put( aMaster.GetShadow() );
134 0 : aSet.Put( aMaster.GetCol() );
135 0 : aSet.Put( aMaster.GetFrmDir() ); // #112217#
136 0 : aLeft.SetFmtAttr( aSet );
137 0 : }
138 :
139 75 : void SwPageDesc::ResetAllAttr( sal_Bool bLeft )
140 : {
141 75 : SwFrmFmt& rFmt = bLeft ? GetLeft() : GetMaster();
142 :
143 : // #i73790# - method renamed
144 75 : rFmt.ResetAllFmtAttr();
145 75 : rFmt.SetFmtAttr( SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP, RES_FRAMEDIR) );
146 75 : }
147 :
148 : /*************************************************************************
149 : |*
150 : |* SwPageDesc::GetInfo()
151 : |*
152 : |* Description retrieves information
153 : |*
154 : *************************************************************************/
155 :
156 :
157 : // gets information from Modify
158 117 : bool SwPageDesc::GetInfo( SfxPoolItem & rInfo ) const
159 : {
160 117 : if( !aMaster.GetInfo( rInfo ) )
161 4 : return false; // found
162 113 : return aLeft.GetInfo( rInfo );
163 : }
164 :
165 : /*************************************************************************
166 : |*
167 : |* SwPageDesc::SetRegisterFmtColl()
168 : |*
169 : |* Description sets the style for the grid alignment
170 : |*
171 : *************************************************************************/
172 :
173 :
174 1875 : void SwPageDesc::SetRegisterFmtColl( const SwTxtFmtColl* pFmt )
175 : {
176 1875 : if( pFmt != GetRegisterFmtColl() )
177 : {
178 0 : if( pFmt )
179 0 : ((SwTxtFmtColl*)pFmt)->Add( &aDepend );
180 : else
181 0 : ((SwTxtFmtColl*)GetRegisterFmtColl())->Remove( &aDepend );
182 :
183 0 : RegisterChange();
184 : }
185 1875 : }
186 :
187 : /*************************************************************************
188 : |*
189 : |* SwPageDesc::GetRegisterFmtColl()
190 : |*
191 : |* Description retrieves the style for the grid alignment
192 : |*
193 : *************************************************************************/
194 :
195 :
196 5052 : const SwTxtFmtColl* SwPageDesc::GetRegisterFmtColl() const
197 : {
198 5052 : const SwModify* pReg = aDepend.GetRegisteredIn();
199 5052 : return (SwTxtFmtColl*)pReg;
200 : }
201 :
202 : /*************************************************************************
203 : |*
204 : |* SwPageDesc::RegisterChange()
205 : |*
206 : |* Description notifies all affected page frames
207 : |*
208 : *************************************************************************/
209 :
210 :
211 0 : void SwPageDesc::RegisterChange()
212 : {
213 : // #117072# - During destruction of the document <SwDoc>
214 : // the page description is modified. Thus, do nothing, if the document
215 : // is in destruction respectively if no viewshell exists.
216 0 : SwDoc* pDoc = GetMaster().GetDoc();
217 0 : if ( !pDoc || pDoc->IsInDtor() )
218 : {
219 : return;
220 : }
221 0 : ViewShell* pSh = 0L;
222 0 : pDoc->GetEditShell( &pSh );
223 0 : if ( !pSh )
224 : {
225 : return;
226 : }
227 :
228 0 : nRegHeight = 0;
229 : {
230 0 : SwIterator<SwFrm,SwFmt> aIter( GetMaster() );
231 0 : for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
232 : {
233 0 : if( pLast->IsPageFrm() )
234 0 : ((SwPageFrm*)pLast)->PrepareRegisterChg();
235 0 : }
236 : }
237 : {
238 0 : SwIterator<SwFrm,SwFmt> aIter( GetLeft() );
239 0 : for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
240 : {
241 0 : if( pLast->IsPageFrm() )
242 0 : ((SwPageFrm*)pLast)->PrepareRegisterChg();
243 0 : }
244 : }
245 : {
246 0 : SwIterator<SwFrm,SwFmt> aIter( GetFirst() );
247 0 : for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
248 : {
249 0 : if( pLast->IsPageFrm() )
250 0 : ((SwPageFrm*)pLast)->PrepareRegisterChg();
251 0 : }
252 : }
253 : }
254 :
255 : /*************************************************************************
256 : |*
257 : |* SwPageDesc::Modify()
258 : |*
259 : |* special handling if the style of the grid alignment changes
260 : |*
261 : *************************************************************************/
262 :
263 :
264 0 : void SwPageDesc::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
265 : {
266 0 : const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
267 0 : NotifyClients( pOld, pNew );
268 :
269 0 : if ( (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich)
270 0 : || isCHRATR(nWhich) || (RES_PARATR_LINESPACING == nWhich) )
271 : {
272 0 : RegisterChange();
273 : }
274 0 : }
275 :
276 20 : static const SwFrm* lcl_GetFrmOfNode( const SwNode& rNd )
277 : {
278 : SwModify* pMod;
279 20 : sal_uInt16 nFrmType = FRM_CNTNT;
280 :
281 20 : if( rNd.IsCntntNode() )
282 : {
283 20 : pMod = &(SwCntntNode&)rNd;
284 : }
285 0 : else if( rNd.IsTableNode() )
286 : {
287 0 : pMod = ((SwTableNode&)rNd).GetTable().GetFrmFmt();
288 0 : nFrmType = FRM_TAB;
289 : }
290 : else
291 0 : pMod = 0;
292 :
293 20 : Point aNullPt;
294 20 : return pMod ? ::GetFrmOfModify( 0, *pMod, nFrmType, &aNullPt, 0, sal_False )
295 40 : : 0;
296 : }
297 :
298 8 : const SwPageDesc* SwPageDesc::GetPageDescOfNode(const SwNode& rNd)
299 : {
300 8 : const SwPageDesc* pRet = 0;
301 8 : const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
302 8 : if (pChkFrm && 0 != (pChkFrm = pChkFrm->FindPageFrm()))
303 8 : pRet = ((const SwPageFrm*)pChkFrm)->GetPageDesc();
304 8 : return pRet;
305 : }
306 :
307 4 : const SwFrmFmt* SwPageDesc::GetPageFmtOfNode( const SwNode& rNd,
308 : sal_Bool bCheckForThisPgDc ) const
309 : {
310 : // which PageDescFormat is valid for this node?
311 : const SwFrmFmt* pRet;
312 4 : const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
313 :
314 4 : if( pChkFrm && 0 != ( pChkFrm = pChkFrm->FindPageFrm() ))
315 : {
316 : const SwPageDesc* pPd = bCheckForThisPgDc ? this :
317 4 : ((SwPageFrm*)pChkFrm)->GetPageDesc();
318 4 : pRet = &pPd->GetMaster();
319 : OSL_ENSURE( ((SwPageFrm*)pChkFrm)->GetPageDesc() == pPd, "Wrong node for detection of page format!" );
320 : // this page is assigned to which format?
321 4 : if( !pChkFrm->KnowsFormat(*pRet) )
322 : {
323 4 : pRet = &pPd->GetLeft();
324 : OSL_ENSURE( pChkFrm->KnowsFormat(*pRet), "Wrong node for detection of page format!" );
325 : }
326 : }
327 : else
328 0 : pRet = &GetMaster();
329 4 : return pRet;
330 : }
331 :
332 8 : sal_Bool SwPageDesc::IsFollowNextPageOfNode( const SwNode& rNd ) const
333 : {
334 8 : sal_Bool bRet = sal_False;
335 8 : if( GetFollow() && this != GetFollow() )
336 : {
337 8 : const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
338 32 : if( pChkFrm && 0 != ( pChkFrm = pChkFrm->FindPageFrm() ) &&
339 8 : pChkFrm->IsPageFrm() &&
340 16 : ( !pChkFrm->GetNext() || GetFollow() ==
341 8 : ((SwPageFrm*)pChkFrm->GetNext())->GetPageDesc() ))
342 : // the page on which the follow points was found
343 8 : bRet = sal_True;
344 : }
345 8 : return bRet;
346 : }
347 :
348 6529 : sal_Bool SwPageDesc::IsFirstShared() const
349 : {
350 6529 : return eUse & nsUseOnPage::PD_FIRSTSHARE ? sal_True : sal_False;
351 : }
352 :
353 1253 : void SwPageDesc::ChgFirstShare( sal_Bool bNew )
354 : {
355 1253 : if ( bNew )
356 1141 : eUse = (UseOnPage) (eUse | nsUseOnPage::PD_FIRSTSHARE);
357 : else
358 112 : eUse = (UseOnPage) (eUse & nsUseOnPage::PD_NOFIRSTSHARE);
359 1253 : }
360 :
361 : /*************************************************************************
362 : |*
363 : |* SwPageFtnInfo::SwPageFtnInfo()
364 : |*
365 : |*************************************************************************/
366 :
367 :
368 :
369 774 : SwPageFtnInfo::SwPageFtnInfo() :
370 : nMaxHeight( 0 ),
371 : nLineWidth(10),
372 : eLineStyle( table::BorderLineStyle::SOLID ),
373 : aWidth( 25, 100 ),
374 : nTopDist( 57 ), //1mm
375 774 : nBottomDist( 57 )
376 : {
377 774 : eAdj = FRMDIR_HORI_RIGHT_TOP == GetDefaultFrameDirection(GetAppLanguage()) ?
378 : FTNADJ_RIGHT :
379 774 : FTNADJ_LEFT;
380 774 : }
381 :
382 :
383 :
384 7427 : SwPageFtnInfo::SwPageFtnInfo( const SwPageFtnInfo &rCpy ) :
385 7427 : nMaxHeight( rCpy.GetHeight() ),
386 : nLineWidth(rCpy.nLineWidth),
387 : eLineStyle(rCpy.eLineStyle),
388 : aLineColor(rCpy.aLineColor),
389 7427 : aWidth( rCpy.GetWidth() ),
390 7427 : eAdj( rCpy.GetAdj() ),
391 7427 : nTopDist( rCpy.GetTopDist() ),
392 29708 : nBottomDist( rCpy.GetBottomDist() )
393 : {
394 7427 : }
395 :
396 : /*************************************************************************
397 : |*
398 : |* SwPageFtnInfo::operator=
399 : |*
400 : |*************************************************************************/
401 :
402 :
403 :
404 849 : SwPageFtnInfo &SwPageFtnInfo::operator=( const SwPageFtnInfo& rCpy )
405 : {
406 849 : nMaxHeight = rCpy.GetHeight();
407 849 : nLineWidth = rCpy.nLineWidth;
408 849 : eLineStyle = rCpy.eLineStyle;
409 849 : aLineColor = rCpy.aLineColor;
410 849 : aWidth = rCpy.GetWidth();
411 849 : eAdj = rCpy.GetAdj();
412 849 : nTopDist = rCpy.GetTopDist();
413 849 : nBottomDist = rCpy.GetBottomDist();
414 849 : return *this;
415 : }
416 : /*************************************************************************
417 : |*
418 : |* SwPageFtnInfo::operator==
419 : |*
420 : |*************************************************************************/
421 :
422 :
423 :
424 2550 : sal_Bool SwPageFtnInfo::operator==( const SwPageFtnInfo& rCmp ) const
425 : {
426 2550 : return ( nMaxHeight == rCmp.GetHeight() &&
427 : nLineWidth == rCmp.nLineWidth &&
428 : eLineStyle == rCmp.eLineStyle &&
429 2400 : aLineColor == rCmp.aLineColor &&
430 2400 : aWidth == rCmp.GetWidth() &&
431 2400 : eAdj == rCmp.GetAdj() &&
432 2400 : nTopDist == rCmp.GetTopDist() &&
433 14700 : nBottomDist== rCmp.GetBottomDist() );
434 : }
435 :
436 0 : SwPageDescExt::SwPageDescExt(const SwPageDesc & rPageDesc, SwDoc * _pDoc)
437 0 : : aPageDesc(rPageDesc), pDoc(_pDoc)
438 : {
439 0 : SetPageDesc(rPageDesc);
440 0 : }
441 :
442 0 : SwPageDescExt::SwPageDescExt(const SwPageDescExt & rSrc)
443 0 : : aPageDesc(rSrc.aPageDesc), pDoc(rSrc.pDoc)
444 : {
445 0 : SetPageDesc(rSrc.aPageDesc);
446 0 : }
447 :
448 0 : SwPageDescExt::~SwPageDescExt()
449 : {
450 0 : }
451 :
452 0 : const String & SwPageDescExt::GetName() const
453 : {
454 0 : return aPageDesc.GetName();
455 : }
456 :
457 0 : void SwPageDescExt::SetPageDesc(const SwPageDesc & _aPageDesc)
458 : {
459 0 : aPageDesc = _aPageDesc;
460 :
461 0 : if (aPageDesc.GetFollow())
462 0 : sFollow = aPageDesc.GetFollow()->GetName();
463 0 : }
464 :
465 0 : SwPageDescExt & SwPageDescExt::operator = (const SwPageDesc & rSrc)
466 : {
467 0 : SetPageDesc(rSrc);
468 :
469 0 : return *this;
470 : }
471 :
472 0 : SwPageDescExt & SwPageDescExt::operator = (const SwPageDescExt & rSrc)
473 : {
474 0 : SetPageDesc(rSrc.aPageDesc);
475 :
476 0 : return *this;
477 : }
478 :
479 0 : SwPageDescExt::operator SwPageDesc() const
480 : {
481 0 : SwPageDesc aResult(aPageDesc);
482 :
483 0 : SwPageDesc * pPageDesc = pDoc->GetPageDesc(sFollow);
484 :
485 0 : if ( 0 != pPageDesc )
486 0 : aResult.SetFollow(pPageDesc);
487 :
488 0 : return aResult;
489 : }
490 :
491 300 : SwPageDescs::~SwPageDescs()
492 : {
493 150 : for(const_iterator it = begin(); it != end(); ++it)
494 0 : delete *it;
495 150 : }
496 :
497 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|