merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / layout / anchoredobject.cxx
blobeed807f6f2a2ca95250bcafac487680c71d7d2e8
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: anchoredobject.cxx,v $
10 * $Revision: 1.27.212.1 $
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"
33 #include <anchoredobject.hxx>
34 #include <pam.hxx>
35 #include <frame.hxx>
36 #include <txtfrm.hxx>
37 #include <frmfmt.hxx>
38 #include <fmtanchr.hxx>
39 #include <fmtornt.hxx>
40 // --> OD 2004-06-29 #i28701#
41 #include <doc.hxx>
42 #include <fmtsrnd.hxx>
43 #include <svx/svdobj.hxx>
44 #include <dcontact.hxx>
45 #include <svx/ulspitem.hxx>
46 #include <svx/lrspitem.hxx>
47 #include <sortedobjs.hxx>
48 #include <pagefrm.hxx>
49 // <--
50 #include <frmatr.hxx>
51 // --> OD 2004-08-25 #i3317#
52 #include <colfrm.hxx>
53 // <--
54 // --> OD 2004-10-22 #i35911#
55 #include <layouter.hxx>
58 using namespace ::com::sun::star;
61 // <--
62 // ============================================================================
63 // --> OD 2004-06-30 #i28701# -
64 // implementation of helper class <SwObjPositioningInProgress>
65 // ============================================================================
66 SwObjPositioningInProgress::SwObjPositioningInProgress( SdrObject& _rSdrObj ) :
67 mpAnchoredObj( 0L ),
68 // --> OD 2005-08-09 #i52904#
69 mbOldObjPositioningInProgress( false )
70 // <--
72 mpAnchoredObj = ::GetUserCall( &_rSdrObj )->GetAnchoredObj( &_rSdrObj );
73 // --> OD 2005-08-09 #i52904#
74 mbOldObjPositioningInProgress = mpAnchoredObj->IsPositioningInProgress();
75 // <--
76 mpAnchoredObj->SetPositioningInProgress( true );
78 SwObjPositioningInProgress::SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj ) :
79 mpAnchoredObj( &_rAnchoredObj ),
80 // --> OD 2005-08-09 #i52904#
81 mbOldObjPositioningInProgress( false )
82 // <--
84 // --> OD 2005-08-09 #i52904#
85 mbOldObjPositioningInProgress = mpAnchoredObj->IsPositioningInProgress();
86 // <--
87 mpAnchoredObj->SetPositioningInProgress( true );
90 SwObjPositioningInProgress::~SwObjPositioningInProgress()
92 if ( mpAnchoredObj )
94 // --> OD 2005-08-09 #i52904#
95 mpAnchoredObj->SetPositioningInProgress( mbOldObjPositioningInProgress );
96 // <--
100 // ============================================================================
102 TYPEINIT0(SwAnchoredObject);
104 SwAnchoredObject::SwAnchoredObject() :
105 mpDrawObj( 0L ),
106 mpAnchorFrm( 0L ),
107 // --> OD 2004-06-30 #i28701#
108 mpPageFrm( 0L ),
109 // <--
110 maRelPos(),
111 maLastCharRect(),
112 mnLastTopOfLine( 0L ),
113 mpVertPosOrientFrm( 0L ),
114 // --> OD 2004-06-29 #i28701#
115 mbPositioningInProgress( false ),
116 mbConsiderForTextWrap( false ),
117 mbPositionLocked( false ),
118 // --> OD 2005-01-10 #i40147#
119 mbKeepPositionLockedForSection( false ),
120 // <--
121 mbRestartLayoutProcess( false ),
122 // <--
123 // --> OD 2004-10-22 #i35911#
124 mbClearedEnvironment( false ),
125 // <--
126 // --> OD 2004-08-25 #i3317#
127 mbTmpConsiderWrapInfluence( false ),
128 // <--
129 // --> OD 2006-08-10 #i68520#
130 maObjRectWithSpaces(),
131 mbObjRectWithSpacesValid( false ),
132 maLastObjRect()
133 // <--
137 SwAnchoredObject::~SwAnchoredObject()
141 // =============================================================================
142 // accessors for member <mpDrawObj>
143 // =============================================================================
144 void SwAnchoredObject::SetDrawObj( SdrObject& _rDrawObj )
146 mpDrawObj = &_rDrawObj;
149 const SdrObject* SwAnchoredObject::GetDrawObj() const
151 return mpDrawObj;
154 SdrObject* SwAnchoredObject::DrawObj()
156 return mpDrawObj;
159 // =============================================================================
160 // accessors for member <mpAnchorFrm>
161 // =============================================================================
162 const SwFrm* SwAnchoredObject::GetAnchorFrm() const
164 return mpAnchorFrm;
167 SwFrm* SwAnchoredObject::AnchorFrm()
169 return mpAnchorFrm;
172 void SwAnchoredObject::ChgAnchorFrm( SwFrm* _pNewAnchorFrm )
174 mpAnchorFrm = _pNewAnchorFrm;
176 if ( mpAnchorFrm )
178 ObjectAttachedToAnchorFrame();
182 /** determine anchor frame containing the anchor position
184 OD 2004-10-08 #i26945#
185 the anchor frame, which is determined, is <mpAnchorFrm>
186 for an at-page, at-frame or at-paragraph anchored object
187 and the anchor character frame for an at-character and as-character
188 anchored object.
190 @author OD
192 SwFrm* SwAnchoredObject::GetAnchorFrmContainingAnchPos()
194 SwFrm* pAnchorFrmContainingAnchPos = FindAnchorCharFrm();
195 if ( !pAnchorFrmContainingAnchPos )
197 pAnchorFrmContainingAnchPos = AnchorFrm();
200 return pAnchorFrmContainingAnchPos;
203 // =============================================================================
204 // OD 2004-06-30 #i28701# accessors for member <mpPageFrm>
205 // =============================================================================
206 SwPageFrm* SwAnchoredObject::GetPageFrm()
208 return mpPageFrm;
211 const SwPageFrm* SwAnchoredObject::GetPageFrm() const
213 return mpPageFrm;
216 void SwAnchoredObject::SetPageFrm( SwPageFrm* _pNewPageFrm )
218 // --> OD 2006-01-02 #125977#
219 if ( mpPageFrm != _pNewPageFrm )
221 // clear member, which denotes the layout frame at which the vertical
222 // position is oriented at, if it doesn't fit to the new page frame.
223 if ( GetVertPosOrientFrm() &&
224 ( !_pNewPageFrm ||
225 _pNewPageFrm != GetVertPosOrientFrm()->FindPageFrm() ) )
227 ClearVertPosOrientFrm();
230 // assign new page frame
231 mpPageFrm = _pNewPageFrm;
233 // <--
236 // =============================================================================
237 // accessors for member <maLastCharRect>
238 // =============================================================================
239 const SwRect& SwAnchoredObject::GetLastCharRect() const
241 return maLastCharRect;
244 SwTwips SwAnchoredObject::GetRelCharX( const SwFrm* pFrm ) const
246 return maLastCharRect.Left() - pFrm->Frm().Left();
249 SwTwips SwAnchoredObject::GetRelCharY( const SwFrm* pFrm ) const
251 return maLastCharRect.Bottom() - pFrm->Frm().Top();
254 void SwAnchoredObject::AddLastCharY( long nDiff )
256 maLastCharRect.Pos().Y() += nDiff;
259 void SwAnchoredObject::ResetLastCharRectHeight()
261 maLastCharRect.Height( 0 );
263 // =============================================================================
264 // accessors for member <mpVertPosOrientFrm>
265 // =============================================================================
266 void SwAnchoredObject::SetVertPosOrientFrm( const SwLayoutFrm& _rVertPosOrientFrm )
268 mpVertPosOrientFrm = &_rVertPosOrientFrm;
270 // --> OD 2004-07-02 #i28701# - take over functionality of deleted method
271 // <SwFlyAtCntFrm::AssertPage()>: assure for at-paragraph and at-character
272 // an anchored object, that it is registered at the correct page frame
273 RegisterAtCorrectPage();
276 // =============================================================================
277 // accessors for member <mnLastTopOfLine>
278 // =============================================================================
279 SwTwips SwAnchoredObject::GetLastTopOfLine() const
281 return mnLastTopOfLine;
284 // OD 2004-05-18 #i28701# - follow-up of #i22341#
285 void SwAnchoredObject::AddLastTopOfLineY( SwTwips _nDiff )
287 mnLastTopOfLine += _nDiff;
290 /** check anchor character rectangle and top of line
292 OD 2004-03-24 #i26791
293 For to-character anchored Writer fly frames the members <maLastCharRect>
294 and <maLastTopOfLine> are updated. These are checked for change and
295 depending on the applied positioning, it's decided, if the Writer fly
296 frame has to be invalidated.
297 OD 2004-07-15 #117380#
298 add parameter <_bCheckForParaPorInf>, default value <true>
300 @author OD
302 void SwAnchoredObject::CheckCharRectAndTopOfLine(
303 const bool _bCheckForParaPorInf )
305 if ( GetAnchorFrm() &&
306 GetAnchorFrm()->IsTxtFrm() )
308 const SwFmtAnchor& rAnch = GetFrmFmt().GetAnchor();
309 if ( rAnch.GetAnchorId() == FLY_AUTO_CNTNT &&
310 rAnch.GetCntntAnchor() )
312 // --> OD 2004-07-14 #117380# - if requested, assure that anchor frame,
313 // which contains the anchor character, has a paragraph portion information.
314 // The paragraph portion information is needed to determine the
315 // anchor character rectangle respectively the top of the line.
316 // Thus, a format of this frame is avoided to determine the
317 // paragraph portion information.
318 // --> OD 2004-10-04 #i26945# - use new method <FindAnchorCharFrm()>
319 const SwTxtFrm& aAnchorCharFrm = *(FindAnchorCharFrm());
320 // <--
321 if ( !_bCheckForParaPorInf || aAnchorCharFrm.HasPara() )
323 _CheckCharRect( rAnch, aAnchorCharFrm );
324 _CheckTopOfLine( rAnch, aAnchorCharFrm );
326 // <--
331 /** check anchor character rectangle
333 OD 11.11.2003 #i22341#
334 helper method for method <CheckCharRectAndTopOfLine()>
335 For to-character anchored Writer fly frames the member <maLastCharRect>
336 is updated. This is checked for change and depending on the applied
337 positioning, it's decided, if the Writer fly frame has to be invalidated.
338 OD 2004-07-14 #117380#
339 improvement - add second parameter <_rAnchorCharFrm>
341 @author OD
343 void SwAnchoredObject::_CheckCharRect( const SwFmtAnchor& _rAnch,
344 const SwTxtFrm& _rAnchorCharFrm )
346 // determine rectangle of anchor character. If not exist, abort operation
347 SwRect aCharRect;
348 if ( !_rAnchorCharFrm.GetAutoPos( aCharRect, *_rAnch.GetCntntAnchor() ) )
350 return;
352 // check, if anchor character rectangle has changed
353 if ( aCharRect != maLastCharRect )
355 // check positioning and alignment for invalidation of position
357 SWRECTFN( (&_rAnchorCharFrm) );
358 // determine positioning and alignment
359 SwFmtVertOrient aVert( GetFrmFmt().GetVertOrient() );
360 SwFmtHoriOrient aHori( GetFrmFmt().GetHoriOrient() );
361 // check for anchor character rectangle changes for certain
362 // positionings and alignments
363 // OD 07.10.2003 #110978# - add condition to invalidate position,
364 // if vertical aligned at frame/page area and vertical position
365 // of anchor character has changed.
366 const sal_Int16 eVertRelOrient = aVert.GetRelationOrient();
367 if ( ( aHori.GetRelationOrient() == text::RelOrientation::CHAR &&
368 (aCharRect.*fnRect->fnGetLeft)() !=
369 (maLastCharRect.*fnRect->fnGetLeft)() ) ||
370 ( eVertRelOrient == text::RelOrientation::CHAR &&
371 ( (aCharRect.*fnRect->fnGetTop)() !=
372 (maLastCharRect.*fnRect->fnGetTop)() ||
373 (aCharRect.*fnRect->fnGetHeight)() !=
374 (maLastCharRect.*fnRect->fnGetHeight)() ) ) ||
375 ( ( ( eVertRelOrient == text::RelOrientation::FRAME ) ||
376 ( eVertRelOrient == text::RelOrientation::PRINT_AREA ) ||
377 ( eVertRelOrient == text::RelOrientation::PAGE_FRAME ) ||
378 ( eVertRelOrient == text::RelOrientation::PAGE_PRINT_AREA ) ) &&
379 ( (aCharRect.*fnRect->fnGetTop)() !=
380 (maLastCharRect.*fnRect->fnGetTop)() ) ) )
382 // --> OD 2004-10-08 #i26945#, #i35911# - unlock position of
383 // anchored object, if it isn't registered at the page,
384 // where its anchor character frame is on.
385 if ( GetPageFrm() != _rAnchorCharFrm.FindPageFrm() )
387 UnlockPosition();
389 // <--
390 InvalidateObjPos();
393 // keep new anchor character rectangle
394 maLastCharRect = aCharRect;
398 /** check top of line
400 OD 11.11.2003 #i22341#
401 helper method for method <CheckCharRectAndTopOfLine()>
402 For to-character anchored Writer fly frames the member <mnLastTopOfLine>
403 is updated. This is checked for change and depending on the applied
404 positioning, it's decided, if the Writer fly frame has to be invalidated.
405 OD 2004-07-14 #117380#
406 improvement - add second parameter <_rAnchorCharFrm>
408 @author OD
410 void SwAnchoredObject::_CheckTopOfLine( const SwFmtAnchor& _rAnch,
411 const SwTxtFrm& _rAnchorCharFrm )
413 SwTwips nTopOfLine = 0L;
414 if ( _rAnchorCharFrm.GetTopOfLine( nTopOfLine, *_rAnch.GetCntntAnchor() ) )
416 if ( nTopOfLine != mnLastTopOfLine )
418 // check alignment for invalidation of position
419 if ( GetFrmFmt().GetVertOrient().GetRelationOrient() == text::RelOrientation::TEXT_LINE )
421 // --> OD 2004-10-08 #i26945#, #i35911# - unlock position of
422 // anchored object, if it isn't registered at the page,
423 // where its anchor character frame is on.
424 if ( GetPageFrm() != _rAnchorCharFrm.FindPageFrm() )
426 UnlockPosition();
428 // <--
429 InvalidateObjPos();
431 // keep new top of line value
432 mnLastTopOfLine = nTopOfLine;
437 void SwAnchoredObject::ClearCharRectAndTopOfLine()
439 maLastCharRect.Clear();
440 mnLastTopOfLine = 0;
443 const Point SwAnchoredObject::GetCurrRelPos() const
445 return maRelPos;
447 void SwAnchoredObject::SetCurrRelPos( Point _aRelPos )
449 maRelPos = _aRelPos;
452 void SwAnchoredObject::ObjectAttachedToAnchorFrame()
454 // default behaviour:
455 // update layout direction, the anchored object is assigned to
456 UpdateLayoutDir();
459 /** method update layout direction the layout direction, the anchored
460 object is in
462 OD 2004-07-27 #i31698#
463 method has typically to be called, if the anchored object gets its
464 anchor frame assigned.
466 @author OD
468 void SwAnchoredObject::UpdateLayoutDir()
470 SwFrmFmt::tLayoutDir nLayoutDir = SwFrmFmt::HORI_L2R;
471 const SwFrm* pAnchorFrm = GetAnchorFrm();
472 if ( pAnchorFrm )
474 const bool bVert = pAnchorFrm->IsVertical();
475 const bool bR2L = pAnchorFrm->IsRightToLeft();
476 if ( bVert )
478 nLayoutDir = SwFrmFmt::VERT_R2L;
480 else if ( bR2L )
482 nLayoutDir = SwFrmFmt::HORI_R2L;
485 GetFrmFmt().SetLayoutDir( nLayoutDir );
488 /** method to perform necessary invalidations for the positioning of
489 objects, for whose the wrapping style influence has to be considered
490 on the object positioning.
492 OD 2004-06-30 #i28701#
494 @author OD
496 void SwAnchoredObject::InvalidateObjPosForConsiderWrapInfluence(
497 const bool _bNotifyBackgrd )
499 if ( ConsiderObjWrapInfluenceOnObjPos() )
501 // indicate that object has not to be considered for text wrap
502 SetConsiderForTextWrap( false );
503 // unlock position
504 UnlockPosition();
505 // invalidate position
506 InvalidateObjPos();
507 // invalidate 'background', if requested
508 if ( _bNotifyBackgrd )
510 NotifyBackground( GetPageFrm(), GetObjRectWithSpaces(), PREP_FLY_LEAVE );
515 /** method to determine, if wrapping style influence of the anchored
516 object has to be considered on the object positioning
518 OD 2004-06-30 #i28701#
519 Note: result of this method also decides, if the booleans for the
520 layout process are of relevance.
522 @author OD
524 bool SwAnchoredObject::ConsiderObjWrapInfluenceOnObjPos() const
526 bool bRet( false );
528 const SwFrmFmt& rObjFmt = GetFrmFmt();
530 // --> OD 2004-08-25 #i3317# - add condition <IsTmpConsiderWrapInfluence()>
531 // --> OD 2005-09-29 #i55204#
532 // - correction: wrapping style influence has been considered, if condition
533 // <IsTmpConsiderWrapInfluence()> is hold, regardless of its anchor type
534 // or its wrapping style.
535 if ( IsTmpConsiderWrapInfluence() )
537 bRet = true;
539 else if ( rObjFmt.getIDocumentSettingAccess()->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) )
540 // <--
542 const SwFmtAnchor& rAnchor = rObjFmt.GetAnchor();
543 if ( ( rAnchor.GetAnchorId() == FLY_AUTO_CNTNT ||
544 rAnchor.GetAnchorId() == FLY_AT_CNTNT ) &&
545 rObjFmt.GetSurround().GetSurround() != SURROUND_THROUGHT )
547 // --> OD 2004-09-23 #i34520# - text also wraps around anchored
548 // objects in the layer Hell - see the text formatting.
549 // Thus, it hasn't to be checked here.
550 bRet = true;
551 // <--
555 return bRet;
558 /** method to determine, if other anchored objects, also attached at
559 to the anchor frame, have to consider its wrap influence.
561 // --> OD 2005-02-22 #i43255#
563 @author OD
565 bool SwAnchoredObject::ConsiderObjWrapInfluenceOfOtherObjs() const
567 bool bRet( false );
569 const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
570 if ( pObjs->Count() > 1 )
572 sal_uInt32 i = 0;
573 for ( ; i < pObjs->Count(); ++i )
575 SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
576 if ( pAnchoredObj != this &&
577 pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
579 bRet = true;
580 break;
585 return bRet;
588 // =============================================================================
589 // --> OD 2004-06-29 #i28701# - accessors to booleans for layout process
590 // =============================================================================
591 bool SwAnchoredObject::ConsiderForTextWrap() const
593 if ( ConsiderObjWrapInfluenceOnObjPos() )
594 return mbConsiderForTextWrap;
595 else
596 return true;
599 void SwAnchoredObject::SetConsiderForTextWrap( const bool _bConsiderForTextWrap )
601 mbConsiderForTextWrap = _bConsiderForTextWrap;
604 bool SwAnchoredObject::PositionLocked() const
606 if ( ConsiderObjWrapInfluenceOnObjPos() )
607 return mbPositionLocked;
608 else
609 return false;
612 bool SwAnchoredObject::RestartLayoutProcess() const
614 if ( ConsiderObjWrapInfluenceOnObjPos() )
615 return mbRestartLayoutProcess;
616 else
617 return false;
620 void SwAnchoredObject::SetRestartLayoutProcess( const bool _bRestartLayoutProcess )
622 mbRestartLayoutProcess = _bRestartLayoutProcess;
625 // --> OD 2004-10-22 #i35911#
626 bool SwAnchoredObject::ClearedEnvironment() const
628 if ( ConsiderObjWrapInfluenceOnObjPos() )
629 return mbClearedEnvironment;
630 else
631 return false;
633 void SwAnchoredObject::SetClearedEnvironment( const bool _bClearedEnvironment )
635 mbClearedEnvironment = _bClearedEnvironment;
637 // <--
639 /** method to determine, if due to anchored object size and wrapping
640 style, its layout environment is cleared.
642 OD 2004-10-22 #i35911#
644 @author OD
646 bool SwAnchoredObject::HasClearedEnvironment() const
648 bool bHasClearedEnvironment( false );
650 // --> OD 2005-03-03 #i43913# - layout frame, vertical position is orient at, has to be set.
651 ASSERT( GetVertPosOrientFrm(),
652 "<SwAnchoredObject::HasClearedEnvironment()> - layout frame missing, at which the vertical position is oriented at." );
653 if ( GetVertPosOrientFrm() &&
654 GetAnchorFrm()->IsTxtFrm() &&
655 !static_cast<const SwTxtFrm*>(GetAnchorFrm())->IsFollow() &&
656 static_cast<const SwTxtFrm*>(GetAnchorFrm())->FindPageFrm()->GetPhyPageNum() >=
657 GetPageFrm()->GetPhyPageNum() )
658 // <--
660 const SwFrm* pTmpFrm = GetVertPosOrientFrm()->Lower();
661 while ( pTmpFrm && pTmpFrm->IsLayoutFrm() && !pTmpFrm->IsTabFrm() )
663 pTmpFrm = static_cast<const SwLayoutFrm*>(pTmpFrm)->Lower();
665 if ( !pTmpFrm )
667 bHasClearedEnvironment = true;
669 else if ( pTmpFrm->IsTxtFrm() && !pTmpFrm->GetNext() )
671 const SwTxtFrm* pTmpTxtFrm = static_cast<const SwTxtFrm*>(pTmpFrm);
672 if ( pTmpTxtFrm->IsUndersized() ||
673 ( pTmpTxtFrm->GetFollow() &&
674 pTmpTxtFrm->GetFollow()->GetOfst() == 0 ) )
676 bHasClearedEnvironment = true;
681 return bHasClearedEnvironment;
684 /** method to add spacing to object area
686 OD 2004-06-30 #i28701#
687 OD 2006-08-10 #i68520# - return constant reference and use cache
689 @author OD
691 const SwRect& SwAnchoredObject::GetObjRectWithSpaces() const
693 if ( mbObjRectWithSpacesValid &&
694 maLastObjRect != GetObjRect() )
696 ASSERT( false,
697 "<SwAnchoredObject::GetObjRectWithSpaces> - cache for object rectangle inclusive spaces marked as valid, but it couldn't be. Missing invalidation of cache. Please inform OD." );
698 InvalidateObjRectWithSpaces();
700 if ( !mbObjRectWithSpacesValid )
702 // --> OD 2006-10-05 #i70122# - correction:
703 // use bounding rectangle of anchored objects.
704 // maObjRectWithSpaces = GetObjRect();
705 maObjRectWithSpaces = GetObjBoundRect();
706 // <--
707 const SwFrmFmt& rFmt = GetFrmFmt();
708 const SvxULSpaceItem& rUL = rFmt.GetULSpace();
709 const SvxLRSpaceItem& rLR = rFmt.GetLRSpace();
711 maObjRectWithSpaces.Top ( Max( maObjRectWithSpaces.Top() - long(rUL.GetUpper()), 0L ));
712 maObjRectWithSpaces.Left( Max( maObjRectWithSpaces.Left()- long(rLR.GetLeft()), 0L ));
713 maObjRectWithSpaces.SSize().Height() += rUL.GetLower();
714 maObjRectWithSpaces.SSize().Width() += rLR.GetRight();
717 mbObjRectWithSpacesValid = true;
718 maLastObjRect = GetObjRect();
721 return maObjRectWithSpaces;
724 // --> OD 2006-08-10 #i68520#
725 void SwAnchoredObject::SetObjTop( const SwTwips _nTop)
727 const bool bTopChanged( _SetObjTop( _nTop ) );
728 if ( bTopChanged )
730 mbObjRectWithSpacesValid = false;
734 void SwAnchoredObject::SetObjLeft( const SwTwips _nLeft)
736 const bool bLeftChanged( _SetObjLeft( _nLeft ) );
737 if ( bLeftChanged )
739 mbObjRectWithSpacesValid = false;
742 // <--
744 /** method to update anchored object in the <SwSortedObjs> lists
746 OD 2004-07-01 #i28701#
747 If document compatibility option 'Consider wrapping style influence
748 on object positioning' is ON, additionally all anchored objects
749 at the anchor frame and all following anchored objects on the page
750 frame are invalidated.
752 @author OD
754 void SwAnchoredObject::UpdateObjInSortedList()
756 if ( GetAnchorFrm() )
758 if ( GetFrmFmt().getIDocumentSettingAccess()->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) )
760 // invalidate position of all anchored objects at anchor frame
761 if ( GetAnchorFrm()->GetDrawObjs() )
763 const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
764 // determine start index
765 sal_uInt32 i = 0;
766 for ( ; i < pObjs->Count(); ++i )
768 SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
769 if ( pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
770 pAnchoredObj->InvalidateObjPosForConsiderWrapInfluence( true );
771 else
772 pAnchoredObj->InvalidateObjPos();
775 // invalidate all following anchored objects on the page frame
776 if ( GetPageFrm() && GetPageFrm()->GetSortedObjs() )
778 const SwSortedObjs* pObjs = GetPageFrm()->GetSortedObjs();
779 // determine start index
780 sal_uInt32 i = pObjs->ListPosOf( *this ) + 1;
781 for ( ; i < pObjs->Count(); ++i )
783 SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
784 if ( pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
785 pAnchoredObj->InvalidateObjPosForConsiderWrapInfluence( true );
786 else
787 pAnchoredObj->InvalidateObjPos();
791 // update its position in the sorted object list of its anchor frame
792 AnchorFrm()->GetDrawObjs()->Update( *this );
793 // update its position in the sorted object list of its page frame
794 // note: as-character anchored object aren't registered at a page frame
795 if ( GetFrmFmt().GetAnchor().GetAnchorId() != FLY_IN_CNTNT )
797 GetPageFrm()->GetSortedObjs()->Update( *this );
802 /** method to determine, if invalidation of position is allowed
804 OD 2004-07-01 #i28701#
806 @author OD
808 bool SwAnchoredObject::InvalidationOfPosAllowed() const
810 // --> OD 2004-11-03 #114798# - Check, if page frame layout is in progress,
811 // isn't needed, because of anchored object, whose are moved forward.
812 return !PositionLocked();
813 // <--
816 /** method to determine the page frame, on which the 'anchor' of
817 the given anchored object is.
819 OD 2004-07-02 #i28701#
820 OD 2004-09-23 #i33751#, #i34060#
821 Adjust meaning of method and thus its name: If the anchored object
822 or its anchor isn't correctly inserted in the layout, no page frame
823 can be found. Thus, the return type changed to be a pointer and can
824 be NULL.
826 @author OD
828 SwPageFrm* SwAnchoredObject::FindPageFrmOfAnchor()
830 SwPageFrm* pRetPageFrm = 0L;
832 // --> OD 2005-03-08 #i44339# - check, if anchor frame exists.
833 if ( mpAnchorFrm )
835 // --> OD 2004-10-08 #i26945# - use new method <GetAnchorFrmContainingAnchPos()>
836 pRetPageFrm = GetAnchorFrmContainingAnchPos()->FindPageFrm();
837 // <--
840 return pRetPageFrm;
843 /** get frame, which contains the anchor character, if the object
844 is anchored at-character or as-character.
846 OD 2004-10-04 #i26945#
848 @author OD
850 @return SwTxtFrm*
851 text frame containing the anchor character. It's NULL, if the object
852 isn't anchored at-character resp. as-character.
854 SwTxtFrm* SwAnchoredObject::FindAnchorCharFrm()
856 SwTxtFrm* pAnchorCharFrm( 0L );
858 // --> OD 2005-03-08 #i44339# - check, if anchor frame exists.
859 if ( mpAnchorFrm )
861 const SwFmtAnchor& rAnch = GetFrmFmt().GetAnchor();
862 if ( rAnch.GetAnchorId() == FLY_AUTO_CNTNT ||
863 rAnch.GetAnchorId() == FLY_IN_CNTNT )
865 pAnchorCharFrm = &(static_cast<SwTxtFrm*>(AnchorFrm())->
866 GetFrmAtOfst( rAnch.GetCntntAnchor()->nContent.GetIndex() ));
869 // <--
871 return pAnchorCharFrm;
874 /** method to determine, if a format on the anchored object is possible
876 OD 2004-07-23 #i28701#
877 A format is possible, if anchored object is in an invisible layer.
878 Note: method is virtual to refine the conditions for the sub-classes.
880 @author OD
882 bool SwAnchoredObject::IsFormatPossible() const
884 return GetFrmFmt().GetDoc()->IsVisibleLayerId( GetDrawObj()->GetLayer() );
887 // --> OD 2004-08-25 #i3317#
888 void SwAnchoredObject::SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence )
890 mbTmpConsiderWrapInfluence = _bTmpConsiderWrapInfluence;
891 // --> OD 2004-10-22 #i35911#
892 if ( mbTmpConsiderWrapInfluence )
894 SwLayouter::InsertObjForTmpConsiderWrapInfluence( *(GetFrmFmt().GetDoc()),
895 *this );
897 // <--
900 bool SwAnchoredObject::IsTmpConsiderWrapInfluence() const
902 return mbTmpConsiderWrapInfluence;
904 // <--
906 // --> OD 2006-07-24 #b6449874#
907 void SwAnchoredObject::SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence )
909 const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
910 if ( pObjs->Count() > 1 )
912 sal_uInt32 i = 0;
913 for ( ; i < pObjs->Count(); ++i )
915 SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
916 if ( pAnchoredObj != this )
918 pAnchoredObj->SetTmpConsiderWrapInfluence( bTmpConsiderWrapInfluence );
923 // <--
925 /** method to determine, if the anchored object is overlapping with a
926 previous column
928 OD 2004-08-25 #i3317#
929 overlapping with a previous column means, that the object overlaps
930 with a column, which is a previous one of the column its anchor
931 frame is in.
932 Only applied for at-paragraph and at-character anchored objects.
934 @author OD
936 bool SwAnchoredObject::OverlapsPrevColumn() const
938 bool bOverlapsPrevColumn( false );
940 if ( mpAnchorFrm && mpAnchorFrm->IsTxtFrm() )
942 const SwFrm* pColFrm = mpAnchorFrm->FindColFrm();
943 if ( pColFrm && pColFrm->GetPrev() )
945 const SwFrm* pTmpColFrm = pColFrm->GetPrev();
946 SwRect aChkRect;
947 while ( pTmpColFrm )
949 aChkRect.Union( pTmpColFrm->Frm() );
950 pTmpColFrm = pTmpColFrm->GetPrev();
952 bOverlapsPrevColumn = GetObjRect().IsOver( aChkRect );
956 return bOverlapsPrevColumn;
959 /** method to determine position of anchored object relative to
960 anchor frame
962 OD 2005-01-06 #i30669#
963 Usage: Needed layout information for WW8 export
965 @author OD
967 Point SwAnchoredObject::GetRelPosToAnchorFrm() const
969 Point aRelPos;
971 ASSERT( GetAnchorFrm(),
972 "<SwAnchoredObject::GetRelPosToAnchorFrm()> - missing anchor frame." );
973 aRelPos = GetObjRect().Pos();
974 aRelPos -= GetAnchorFrm()->Frm().Pos();
976 return aRelPos;
979 /** method to determine position of anchored object relative to
980 page frame
982 OD 2005-01-06 #i30669#
983 Usage: Needed layout information for WW8 export
984 OD 2005-01-27 #i33818# - add parameters <_bFollowTextFlow> and
985 <_obRelToTableCell>
986 If <_bFollowTextFlow> is set and object is anchored inside table,
987 the position relative to the table cell is determined. Output
988 parameter <_obRelToTableCell> reflects this situation
990 @author OD
992 Point SwAnchoredObject::GetRelPosToPageFrm( const bool _bFollowTextFlow,
993 bool& _obRelToTableCell ) const
995 Point aRelPos;
996 _obRelToTableCell = false;
998 ASSERT( GetAnchorFrm(),
999 "<SwAnchoredObject::GetRelPosToPageFrm()> - missing anchor frame." );
1000 ASSERT( GetAnchorFrm()->FindPageFrm(),
1001 "<SwAnchoredObject::GetRelPosToPageFrm()> - missing page frame." );
1003 aRelPos = GetObjRect().Pos();
1004 // --> OD 2005-01-27 #i33818# - search for cell frame, if object has to
1005 // follow the text flow.
1006 const SwFrm* pFrm( 0L );
1007 if ( _bFollowTextFlow && !GetAnchorFrm()->IsPageFrm() )
1009 pFrm = GetAnchorFrm()->GetUpper();
1010 while ( !pFrm->IsCellFrm() && !pFrm->IsPageFrm() )
1012 pFrm = pFrm->GetUpper();
1015 else
1017 pFrm = GetAnchorFrm()->FindPageFrm();
1019 if ( pFrm->IsCellFrm() )
1021 aRelPos -= ( pFrm->Frm().Pos() + pFrm->Prt().Pos() );
1022 _obRelToTableCell = true;
1024 else
1026 aRelPos -= pFrm->Frm().Pos();
1028 // <--
1030 return aRelPos;
1033 /** method to determine position of anchored object relative to
1034 anchor character
1036 OD 2005-01-06 #i30669#
1037 Usage: Needed layout information for WW8 export
1039 @author OD
1041 Point SwAnchoredObject::GetRelPosToChar() const
1043 Point aRelPos;
1045 aRelPos = GetObjRect().Pos();
1046 aRelPos -= GetLastCharRect().Pos();
1048 return aRelPos;
1051 /** method to determine position of anchored object relative to
1052 top of line
1054 OD 2005-01-06 #i30669#
1055 Usage: Needed layout information for WW8 export
1057 @author OD
1059 Point SwAnchoredObject::GetRelPosToLine() const
1061 Point aRelPos;
1063 aRelPos = GetObjRect().Pos();
1064 aRelPos.Y() -= GetLastTopOfLine();
1066 return aRelPos;