LibreOffice Module sw (master)  1
anchoreddrawobject.cxx
Go to the documentation of this file.
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 <dcontact.hxx>
21 #include <rootfrm.hxx>
22 #include <pagefrm.hxx>
25 #include <frmtool.hxx>
26 #include <fmtornt.hxx>
27 #include <txtfrm.hxx>
28 #include <vector>
29 #include <svx/svdogrp.hxx>
30 #include <tools/fract.hxx>
32 #include <IDocumentState.hxx>
33 #include <txtfly.hxx>
34 #include <viewimp.hxx>
35 #include <textboxhelper.hxx>
36 #include <unomid.h>
37 
38 using namespace ::com::sun::star;
39 
43 {
44  private:
48 
49  public:
50  explicit SwPosNotify( SwAnchoredDrawObject* _pAnchoredDrawObj );
51  ~SwPosNotify() COVERITY_NOEXCEPT_FALSE;
52  // #i32795#
53  Point const & LastObjPos() const;
54 };
55 
57  mpAnchoredDrawObj( _pAnchoredDrawObj )
58 {
59  maOldObjRect = mpAnchoredDrawObj->GetObjRect();
60  // --> #i35640# - determine correct page frame
61  mpOldPageFrame = mpAnchoredDrawObj->GetPageFrame();
62 }
63 
64 SwPosNotify::~SwPosNotify() COVERITY_NOEXCEPT_FALSE
65 {
66  if ( maOldObjRect != mpAnchoredDrawObj->GetObjRect() )
67  {
68  if( maOldObjRect.HasArea() && mpOldPageFrame )
69  {
70  mpAnchoredDrawObj->NotifyBackground( mpOldPageFrame, maOldObjRect,
72  }
73  SwRect aNewObjRect( mpAnchoredDrawObj->GetObjRect() );
74  if( aNewObjRect.HasArea() )
75  {
76  // --> #i35640# - determine correct page frame
77  SwPageFrame* pNewPageFrame = mpAnchoredDrawObj->GetPageFrame();
78  if( pNewPageFrame )
79  mpAnchoredDrawObj->NotifyBackground( pNewPageFrame, aNewObjRect,
81  }
82 
83  ::ClrContourCache( mpAnchoredDrawObj->GetDrawObj() );
84 
85  // --> #i35640# - additional notify anchor text frame
86  // Needed for negative positioned drawing objects
87  // --> #i43255# - refine condition to avoid unneeded
88  // invalidations: anchored object had to be on the page of its anchor
89  // text frame.
90  if ( mpAnchoredDrawObj->GetAnchorFrame()->IsTextFrame() &&
91  mpOldPageFrame == mpAnchoredDrawObj->GetAnchorFrame()->FindPageFrame() )
92  {
93  mpAnchoredDrawObj->AnchorFrame()->Prepare( PREP_FLY_LEAVE );
94  }
95 
96  // indicate a restart of the layout process
97  mpAnchoredDrawObj->SetRestartLayoutProcess( true );
98  }
99  else
100  {
101  // lock position
102  mpAnchoredDrawObj->LockPosition();
103 
104  if ( !mpAnchoredDrawObj->ConsiderForTextWrap() )
105  {
106  // indicate that object has to be considered for text wrap
107  mpAnchoredDrawObj->SetConsiderForTextWrap( true );
108  // invalidate 'background' in order to allow its 'background'
109  // to wrap around it.
110  mpAnchoredDrawObj->NotifyBackground( mpAnchoredDrawObj->GetPageFrame(),
111  mpAnchoredDrawObj->GetObjRectWithSpaces(),
112  PREP_FLY_ARRIVE );
113  // invalidate position of anchor frame in order to force
114  // a re-format of the anchor frame, which also causes a
115  // re-format of the invalid previous frames of the anchor frame.
116  mpAnchoredDrawObj->AnchorFrame()->InvalidatePos();
117  }
118  }
119  // tdf#101464 notify SwAccessibleMap about new drawing object position
120  if (mpOldPageFrame && mpOldPageFrame->getRootFrame()->IsAnyShellAccessible())
121  {
122  mpOldPageFrame->getRootFrame()->GetCurrShell()->Imp()->MoveAccessible(
123  nullptr, mpAnchoredDrawObj->GetDrawObj(), maOldObjRect);
124  }
125 }
126 
127 // --> #i32795#
129 {
130  return maOldObjRect.Pos();
131 }
132 
133 // #i32795#
136 {
137  private:
139 
140  std::vector<Point> maObjPositions;
141 
142  public:
143  explicit SwObjPosOscillationControl( const SwAnchoredDrawObject& _rAnchoredDrawObj );
144 
145  bool OscillationDetected();
146 };
147 
149  const SwAnchoredDrawObject& _rAnchoredDrawObj )
150  : mpAnchoredDrawObj( &_rAnchoredDrawObj )
151 {
152 }
153 
155 {
156  bool bOscillationDetected = false;
157 
158  if ( maObjPositions.size() == 20 )
159  {
160  // position stack is full -> oscillation
161  bOscillationDetected = true;
162  }
163  else
164  {
165  Point aNewObjPos = mpAnchoredDrawObj->GetObjRect().Pos();
166  for ( auto const & pt : maObjPositions )
167  {
168  if ( aNewObjPos == pt )
169  {
170  // position already occurred -> oscillation
171  bOscillationDetected = true;
172  break;
173  }
174  }
175  if ( !bOscillationDetected )
176  {
177  maObjPositions.push_back( aNewObjPos );
178  }
179  }
180 
181  return bOscillationDetected;
182 }
183 
184 
187  mbValidPos( false ),
188  mbNotYetAttachedToAnchorFrame( true ),
189  // --> #i28749#
190  mbNotYetPositioned( true ),
191  // --> #i62875#
192  mbCaptureAfterLayoutDirChange( false )
193 {
194 }
195 
197 {
198 }
199 
200 // --> #i62875#
202 {
203  SwFrameFormat::tLayoutDir nOldLayoutDir( GetFrameFormat().GetLayoutDir() );
204 
206 
207  if ( !NotYetPositioned() &&
208  GetFrameFormat().GetLayoutDir() != nOldLayoutDir &&
209  GetFrameFormat().GetDoc()->GetDocumentSettingManager().get(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
210  !IsOutsidePage() )
211  {
213  }
214 }
215 
216 // --> #i62875#
218 {
219  bool bOutsidePage( false );
220 
221  if ( !NotYetPositioned() && GetPageFrame() )
222  {
223  SwRect aTmpRect( GetObjRect() );
224  bOutsidePage =
225  ( aTmpRect.Intersection( GetPageFrame()->getFrameArea() ) != GetObjRect() );
226  }
227 
228  return bOutsidePage;
229 }
230 
232 {
233  if ( IsPositioningInProgress() )
234  {
235  // nothing to do - positioning already in progress
236  return;
237  }
238 
239  if ( mbValidPos )
240  {
241  // nothing to do - position is valid
242  return;
243  }
244 
245  // --> #i28749# - anchored drawing object has to be attached
246  // to anchor frame
248  {
249  OSL_FAIL( "<SwAnchoredDrawObject::MakeObjPos() - drawing object not yet attached to anchor frame -> no positioning" );
250  return;
251  }
252 
253  SwDrawContact* pDrawContact =
254  static_cast<SwDrawContact*>(::GetUserCall( GetDrawObj() ));
255 
256  // --> #i28749# - if anchored drawing object hasn't been yet
257  // positioned, convert its positioning attributes, if its positioning
258  // attributes are given in horizontal left-to-right layout.
259  // --> #i36010# - Note: horizontal left-to-right layout is made
260  // the default layout direction for <SwDrawFrameFormat> instances. Thus, it has
261  // to be adjusted manually, if no adjustment of the positioning attributes
262  // have to be performed here.
263  // --> #i35635# - additionally move drawing object to the visible layer.
264  if ( mbNotYetPositioned )
265  {
266  // --> #i35635#
267  pDrawContact->MoveObjToVisibleLayer( DrawObj() );
268  // --> perform conversion of positioning
269  // attributes only for 'master' drawing objects
270  // #i44334#, #i44681# - check, if positioning
271  // attributes already have been set.
272  if ( dynamic_cast< const SwDrawVirtObj* >(GetDrawObj()) == nullptr &&
273  !static_cast<SwDrawFrameFormat&>(GetFrameFormat()).IsPosAttrSet() )
274  {
276  }
277  // -->
278  // - reset internal flag after all needed actions are performed to
279  // avoid callbacks from drawing layer
280  mbNotYetPositioned = false;
281  }
282 
283  // indicate that positioning is in progress
284  {
285  SwObjPositioningInProgress aObjPosInProgress( *this );
286 
287  // determine relative position of drawing object and set it
288  switch ( pDrawContact->GetAnchorId() )
289  {
290  case RndStdIds::FLY_AS_CHAR:
291  {
292  // indicate that position will be valid after positioning is performed
293  mbValidPos = true;
294  // nothing to do, because as-character anchored objects are positioned
295  // during the format of its anchor frame - see <SwFlyCntPortion::SetBase(..)>
296  }
297  break;
298  case RndStdIds::FLY_AT_PARA:
299  case RndStdIds::FLY_AT_CHAR:
300  {
301  // --> #i32795# - move intrinsic positioning to
302  // helper method <MakeObjPosAnchoredAtPara()>
304  }
305  break;
306  case RndStdIds::FLY_AT_PAGE:
307  case RndStdIds::FLY_AT_FLY:
308  {
309  // --> #i32795# - move intrinsic positioning to
310  // helper method <MakeObjPosAnchoredAtLayout()>
312  }
313  break;
314  default:
315  {
316  assert(!"<SwAnchoredDrawObject::MakeObjPos()> - unknown anchor type.");
317  }
318  }
319 
320  // keep, current object rectangle
321  // --> #i34748# - use new method <SetLastObjRect(..)>
322  SetLastObjRect( GetObjRect().SVRect() );
323 
324  // Assure for 'master' drawing object, that it's registered at the correct page.
325  // Perform check not for as-character anchored drawing objects and only if
326  // the anchor frame is valid.
327  if ( dynamic_cast< const SwDrawVirtObj* >(GetDrawObj()) == nullptr &&
328  !pDrawContact->ObjAnchoredAsChar() &&
330  {
331  pDrawContact->ChkPage();
332  }
333  }
334 
335  // --> #i62875#
337  GetPageFrame() )
338  {
339  SwRect aPageRect( GetPageFrame()->getFrameArea() );
340  SwRect aObjRect( GetObjRect() );
341  if ( aObjRect.Right() >= aPageRect.Right() + 10 )
342  {
343  Size aSize( aPageRect.Right() - aObjRect.Right(), 0 );
344  DrawObj()->Move( aSize );
345  aObjRect = GetObjRect();
346  }
347 
348  if ( aObjRect.Left() + 10 <= aPageRect.Left() )
349  {
350  Size aSize( aPageRect.Left() - aObjRect.Left(), 0 );
351  DrawObj()->Move( aSize );
352  }
353 
355  }
356 }
357 
364 {
365  // --> #i32795# - adopt positioning algorithm from Writer
366  // fly frames, which are anchored at paragraph|at character
367 
368  // Determine, if anchor frame can/has to be formatted.
369  // If yes, after each object positioning the anchor frame is formatted.
370  // If after the anchor frame format the object position isn't valid, the
371  // object is positioned again.
372  // --> #i43255# - refine condition: anchor frame format not
373  // allowed, if another anchored object, has to be consider its wrap influence
374  // --> #i50356# - format anchor frame containing the anchor
375  // position. E.g., for at-character anchored object this can be the follow
376  // frame of the anchor frame, which contains the anchor character.
377  bool bJoinLocked
378  = static_cast<const SwTextFrame*>(GetAnchorFrameContainingAnchPos())->IsAnyJoinLocked();
379  const bool bFormatAnchor = !bJoinLocked && !ConsiderObjWrapInfluenceOnObjPos()
381 
382  // Format of anchor is needed for (vertical) fly offsets, otherwise the
383  // lack of fly portions will result in an incorrect 0 offset.
384  bool bAddVerticalFlyOffsets = GetFrameFormat().getIDocumentSettingAccess().get(
386  bool bFormatAnchorOnce = !bJoinLocked && bAddVerticalFlyOffsets;
387 
388  if (bFormatAnchor || bFormatAnchorOnce)
389  {
390  // --> #i50356#
391  GetAnchorFrameContainingAnchPos()->Calc(GetAnchorFrameContainingAnchPos()->getRootFrame()->GetCurrShell()->GetOut());
392  }
393 
394  bool bOscillationDetected = false;
395  SwObjPosOscillationControl aObjPosOscCtrl( *this );
396  // --> #i3317# - boolean, to apply temporarily the
397  // 'straightforward positioning process' for the frame due to its
398  // overlapping with a previous column.
399  bool bConsiderWrapInfluenceDueToOverlapPrevCol( false );
400  do {
401  // indicate that position will be valid after positioning is performed
402  mbValidPos = true;
403 
404  // --> #i35640# - correct scope for <SwPosNotify> instance
405  {
406  // create instance of <SwPosNotify> for correct notification
407  SwPosNotify aPosNotify( this );
408 
409  // determine and set position
411  aObjPositioning( *DrawObj() );
412  aObjPositioning.CalcPosition();
413 
414  // get further needed results of the positioning algorithm
415  SetVertPosOrientFrame ( aObjPositioning.GetVertPosOrientFrame() );
417 
418  // check for object position oscillation, if position has changed.
419  if ( GetObjRect().Pos() != aPosNotify.LastObjPos() )
420  {
421  bOscillationDetected = aObjPosOscCtrl.OscillationDetected();
422  }
423  }
424  // format anchor frame, if requested.
425  // Note: the format of the anchor frame can cause the object position
426  // to be invalid.
427  if ( bFormatAnchor )
428  {
429  // --> #i50356#
430  GetAnchorFrameContainingAnchPos()->Calc(GetAnchorFrameContainingAnchPos()->getRootFrame()->GetCurrShell()->GetOut());
431  }
432 
433  // --> #i3317#
436  {
437  bConsiderWrapInfluenceDueToOverlapPrevCol = true;
438  }
439  } while ( !mbValidPos && !bOscillationDetected &&
440  !bConsiderWrapInfluenceDueToOverlapPrevCol );
441 
442  // --> #i3317# - consider a detected oscillation and overlapping
443  // with previous column.
444  // temporarily consider the anchored objects wrapping style influence
445  if ( bOscillationDetected || bConsiderWrapInfluenceDueToOverlapPrevCol )
446  {
448  SetRestartLayoutProcess( true );
449  }
450 }
451 
458 {
459  // indicate that position will be valid after positioning is performed
460  mbValidPos = true;
461 
462  // create instance of <SwPosNotify> for correct notification
463  SwPosNotify aPosNotify( this );
464 
465  // determine position
467  aObjPositioning( *DrawObj() );
468  aObjPositioning.CalcPosition();
469 
470  // set position
471 
472  // --> #i31698#
473  // --> #i34995# - setting anchor position needed for filters,
474  // especially for the xml-filter to the OpenOffice.org file format
475  {
476  const Point aNewAnchorPos =
478  DrawObj()->SetAnchorPos( aNewAnchorPos );
479  // --> #i70122# - missing invalidation
481  }
482  SetCurrRelPos( aObjPositioning.GetRelPos() );
483  const SwFrame* pAnchorFrame = GetAnchorFrame();
484  SwRectFnSet aRectFnSet(pAnchorFrame);
485  const Point aAnchPos( aRectFnSet.GetPos(pAnchorFrame->getFrameArea()) );
486  SetObjLeft( aAnchPos.X() + GetCurrRelPos().X() );
487  SetObjTop( aAnchPos.Y() + GetCurrRelPos().Y() );
488 }
489 
491 {
492  // new anchor position
493  // --> #i31698# -
494  Point aNewAnchorPos =
496  Point aCurrAnchorPos = GetDrawObj()->GetAnchorPos();
497  if ( aNewAnchorPos != aCurrAnchorPos )
498  {
499  // determine movement to be applied after setting the new anchor position
500  Size aMove( aCurrAnchorPos.getX() - aNewAnchorPos.getX(),
501  aCurrAnchorPos.getY() - aNewAnchorPos.getY() );
502  // set new anchor position
503  DrawObj()->SetAnchorPos( aNewAnchorPos );
504  // correct object position, caused by setting new anchor position
505  DrawObj()->Move( aMove );
506  // --> #i70122# - missing invalidation
508  }
509 }
510 
516 {
517  if ( _pPageFrame && !_pPageFrame->GetFormat()->GetDoc()->IsInDtor() )
518  {
519  if ( _pPageFrame->GetUpper() )
520  {
521  // --> #i35007# - correct invalidation for as-character
522  // anchored objects.
523  if ( GetFrameFormat().GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR )
524  {
525  _pPageFrame->InvalidateFlyInCnt();
526  }
527  else
528  {
529  _pPageFrame->InvalidateFlyLayout();
530  }
531 
532  SwRootFrame* pRootFrame = static_cast<SwRootFrame*>(_pPageFrame->GetUpper());
533  pRootFrame->DisallowTurbo();
534  if ( pRootFrame->GetTurbo() )
535  {
536  const SwContentFrame* pTmpFrame = pRootFrame->GetTurbo();
537  pRootFrame->ResetTurbo();
538  pTmpFrame->InvalidatePage();
539  }
540  pRootFrame->SetIdleFlags();
541  }
542  }
543 }
544 
546 {
547  // --> #i28701# - check, if invalidation is allowed
548  if ( mbValidPos &&
550  {
551  mbValidPos = false;
552  // --> #i68520#
554 
555  // --> #i44339# - check, if anchor frame exists.
556  if ( GetAnchorFrame() )
557  {
558  // --> #118547# - notify anchor frame of as-character
559  // anchored object, because its positioned by the format of its anchor frame.
560  // --> #i44559# - assure, that text hint is already
561  // existing in the text frame
562  if ( dynamic_cast< const SwTextFrame* >(GetAnchorFrame()) != nullptr &&
563  (GetFrameFormat().GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR) )
564  {
565  SwTextFrame* pAnchorTextFrame( static_cast<SwTextFrame*>(AnchorFrame()) );
566  if (pAnchorTextFrame->CalcFlyPos(&GetFrameFormat()) != TextFrameIndex(COMPLETE_STRING))
567  {
569  }
570  }
571 
572  SwPageFrame* pPageFrame = AnchorFrame()->FindPageFrame();
573  InvalidatePage_( pPageFrame );
574 
575  // --> #i32270# - also invalidate page frame, at which the
576  // drawing object is registered at.
577  SwPageFrame* pPageFrameRegisteredAt = GetPageFrame();
578  if ( pPageFrameRegisteredAt &&
579  pPageFrameRegisteredAt != pPageFrame )
580  {
581  InvalidatePage_( pPageFrameRegisteredAt );
582  }
583  // #i33751#, #i34060# - method <GetPageFrameOfAnchor()>
584  // is replaced by method <FindPageFrameOfAnchor()>. It's return value
585  // have to be checked.
586  SwPageFrame* pPageFrameOfAnchor = FindPageFrameOfAnchor();
587  if ( pPageFrameOfAnchor &&
588  pPageFrameOfAnchor != pPageFrame &&
589  pPageFrameOfAnchor != pPageFrameRegisteredAt )
590  {
591  InvalidatePage_( pPageFrameOfAnchor );
592  }
593  }
594  }
595 }
596 
598 {
599  assert(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFormat());
600  return *(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFormat());
601 }
603 {
604  assert(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFormat());
605  return *(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFormat());
606 }
607 
609 {
610  // use geometry of drawing object
611  //return GetDrawObj()->GetCurrentBoundRect();
612  return GetDrawObj()->GetSnapRect();
613 }
614 
615 // --> #i70122#
617 {
618  bool bGroupShape = dynamic_cast<const SdrObjGroup*>( GetDrawObj() );
619  // Resize objects with relative width or height
620  if ( !bGroupShape && GetPageFrame( ) && ( GetDrawObj( )->GetRelativeWidth( ) || GetDrawObj()->GetRelativeHeight( ) ) )
621  {
622  tools::Rectangle aCurrObjRect = GetDrawObj()->GetCurrentBoundRect();
623 
624  long nTargetWidth = aCurrObjRect.GetWidth( );
625  if ( GetDrawObj( )->GetRelativeWidth( ) )
626  {
627  tools::Rectangle aPageRect;
628  if (GetDrawObj()->GetRelativeWidthRelation() == text::RelOrientation::FRAME)
629  // Exclude margins.
630  aPageRect = GetPageFrame()->getFramePrintArea().SVRect();
631  else
632  aPageRect = GetPageFrame( )->GetBoundRect( GetPageFrame()->getRootFrame()->GetCurrShell()->GetOut() ).SVRect();
633  nTargetWidth = aPageRect.GetWidth( ) * (*GetDrawObj( )->GetRelativeWidth());
634  }
635 
636  long nTargetHeight = aCurrObjRect.GetHeight( );
637  if ( GetDrawObj( )->GetRelativeHeight( ) )
638  {
639  tools::Rectangle aPageRect;
640  if (GetDrawObj()->GetRelativeHeightRelation() == text::RelOrientation::FRAME)
641  // Exclude margins.
642  aPageRect = GetPageFrame()->getFramePrintArea().SVRect();
643  else
644  aPageRect = GetPageFrame( )->GetBoundRect( GetPageFrame()->getRootFrame()->GetCurrShell()->GetOut() ).SVRect();
645  nTargetHeight = aPageRect.GetHeight( ) * (*GetDrawObj( )->GetRelativeHeight());
646  }
647 
648  if ( nTargetWidth != aCurrObjRect.GetWidth( ) || nTargetHeight != aCurrObjRect.GetHeight( ) )
649  {
650  SwDoc* pDoc = const_cast<SwDoc*>(GetPageFrame()->GetFormat()->GetDoc());
651 
652  bool bEnableSetModified = pDoc->getIDocumentState().IsEnableSetModified();
654  auto pObject = const_cast<SdrObject*>(GetDrawObj());
655  pObject->Resize( aCurrObjRect.TopLeft(),
656  Fraction( nTargetWidth, aCurrObjRect.GetWidth() ),
657  Fraction( nTargetHeight, aCurrObjRect.GetHeight() ), false );
658 
659  if (SwFrameFormat* pFrameFormat = FindFrameFormat(pObject))
660  {
661  if (SwTextBoxHelper::isTextBox(pFrameFormat, RES_DRAWFRMFMT))
662  {
663  // Shape has relative size and also a textbox, update its text area as well.
664  uno::Reference<drawing::XShape> xShape(pObject->getUnoShape(), uno::UNO_QUERY);
666  uno::makeAny(xShape->getSize()));
667  }
668  }
669 
670  pDoc->getIDocumentState().SetEnableSetModified(bEnableSetModified);
671  }
672  }
673  return GetDrawObj()->GetCurrentBoundRect();
674 }
675 
676 // --> #i68520#
678 {
679  SwTwips nDiff = _nTop - GetObjRect().Top();
680  DrawObj()->Move( Size( 0, nDiff ) );
681 
682  return nDiff != 0;
683 }
685 {
686  SwTwips nDiff = _nLeft - GetObjRect().Left();
687  DrawObj()->Move( Size( nDiff, 0 ) );
688 
689  return nDiff != 0;
690 }
691 
697  const SwRect* _pNewObjRect )
698 {
699  SwTwips nHoriRelPos = 0;
700  SwTwips nVertRelPos = 0;
701  const Point aAnchorPos = _pNewAnchorFrame->GetFrameAnchorPos( ::HasWrap( GetDrawObj() ) );
702  // --> #i33313#
703  const SwRect aObjRect( _pNewObjRect ? *_pNewObjRect : GetObjRect() );
704  const bool bVert = _pNewAnchorFrame->IsVertical();
705  const bool bR2L = _pNewAnchorFrame->IsRightToLeft();
706  if ( bVert )
707  {
708  nHoriRelPos = aObjRect.Top() - aAnchorPos.Y();
709  nVertRelPos = aAnchorPos.X() - aObjRect.Right();
710  }
711  else if ( bR2L )
712  {
713  nHoriRelPos = aAnchorPos.X() - aObjRect.Right();
714  nVertRelPos = aObjRect.Top() - aAnchorPos.Y();
715  }
716  else
717  {
718  nHoriRelPos = aObjRect.Left() - aAnchorPos.X();
719  nVertRelPos = aObjRect.Top() - aAnchorPos.Y();
720  }
721 
722  GetFrameFormat().SetFormatAttr( SwFormatHoriOrient( nHoriRelPos, text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
723  GetFrameFormat().SetFormatAttr( SwFormatVertOrient( nVertRelPos, text::VertOrientation::NONE, text::RelOrientation::FRAME ) );
724 }
725 
726 // --> #i34748# - change return type.
727 // If member <mpLastObjRect> is NULL, create one.
729 {
730  maLastObjRect = _rNewLastRect;
731 }
732 
734 {
735  // --> #i31698#
737 
739  {
741  }
742 }
743 
754 {
755  SwDrawContact* pDrawContact =
756  static_cast<SwDrawContact*>(GetUserCall( GetDrawObj() ));
757 
758  if ( !pDrawContact->ObjAnchoredAsChar() )
759  {
760  SwRect aObjRect( GetObjRect() );
761 
762  SwTwips nHoriPos = aObjRect.Left();
763  SwTwips nVertPos = aObjRect.Top();
764  // #i44334#, #i44681#
765  // perform conversion only if position is in horizontal-left-to-right-layout.
766  if ( GetFrameFormat().GetPositionLayoutDir() ==
767  text::PositionLayoutDir::PositionInHoriL2R )
768  {
770  switch ( eLayoutDir )
771  {
773  {
774  // nothing to do
775  }
776  break;
778  {
779  nHoriPos = -aObjRect.Left() - aObjRect.Width();
780  }
781  break;
783  {
784  nHoriPos = aObjRect.Top();
785  nVertPos = -aObjRect.Left() - aObjRect.Width();
786  }
787  break;
788  default:
789  {
790  assert(!"<SwAnchoredDrawObject::SetPositioningAttr()> - unsupported layout direction");
791  }
792  }
793  }
794 
795  // --> #i71182#
796  // only change position - do not lose other attributes
797 
798  SwFormatHoriOrient aHori( GetFrameFormat().GetHoriOrient() );
799  if (nHoriPos != aHori.GetPos()) {
800  aHori.SetPos( nHoriPos );
802  GetFrameFormat().SetFormatAttr( aHori );
803  }
804 
805  SwFormatVertOrient aVert( GetFrameFormat().GetVertOrient() );
806  if (nVertPos != aVert.GetPos()) {
807  aVert.SetPos( nVertPos );
809  GetFrameFormat().SetFormatAttr( aVert );
810  }
811 
812  // --> #i36010# - set layout direction of the position
814  text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
815  }
816  // --> #i65798# - also for as-character anchored objects
817  // --> #i45952# - indicate that position
818  // attributes are set now.
819  static_cast<SwDrawFrameFormat&>(GetFrameFormat()).PosAttrSet();
820 }
821 
823  const SwRect& _rRect,
824  PrepareHint _eHint )
825 {
826  ::Notify_Background( GetDrawObj(), _pPageFrame, _rRect, _eHint, true );
827 }
828 
835 {
836  SwPageFrame* pPageFrame( nullptr );
837  if ( GetVertPosOrientFrame() )
838  {
839  pPageFrame = const_cast<SwPageFrame*>(GetVertPosOrientFrame()->FindPageFrame());
840  }
841  if ( pPageFrame && GetPageFrame() != pPageFrame )
842  {
843  if ( GetPageFrame() )
845  pPageFrame->AppendDrawObjToPage( *this );
846  }
847 }
848 
849 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwPageFrame * mpOldPageFrame
Point TopLeft() const
Base class of the Writer layout elements.
Definition: frame.hxx:295
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
bool OverlapsPrevColumn() const
method to determine, if the anchored object is overlapping with a previous column ...
long GetWidth() const
#define RES_FRM_SIZE
Definition: hintids.hxx:194
void ChkPage()
Definition: dcontact.cxx:1929
Point GetPos(const SwRect &rRect) const
Definition: frame.hxx:1359
long GetHeight() const
~SwPosNotify() COVERITY_NOEXCEPT_FALSE
class for the positioning of drawing objects
virtual const tools::Rectangle & GetCurrentBoundRect() const
virtual void NotifyBackground(SwPageFrame *_pPageFrame, const SwRect &_rRect, PrepareHint _eHint) override
method to notify background of drawing object
helper class for correct notification due to the positioning of the anchored drawing object ...
bool IsAnyShellAccessible() const
Definition: rootfrm.hxx:384
SwViewShellImp * Imp()
Definition: viewsh.hxx:185
const SwAnchoredDrawObject * mpAnchoredDrawObj
virtual void UpdateLayoutDir()
method update layout direction the layout direction, the anchored object is assigned to ...
SwTwips GetPos() const
Definition: fmtornt.hxx:92
const SwRect & getFramePrintArea() const
Definition: frame.hxx:176
void SetConsiderForTextWrap(const bool _bConsiderForTextWrap)
void RemoveDrawObjFromPage(SwAnchoredObject &_rToRemoveObj)
Definition: flylay.cxx:1095
Definition: doc.hxx:185
void InvalidatePage_(SwPageFrame *_pPageFrame)
method to invalidate the given page frame
void InvalidatePos()
Definition: frame.hxx:1019
boost::optional< tools::Rectangle > maLastObjRect
long SwTwips
Definition: swtypes.hxx:49
void Pos(const Point &rNew)
Definition: swrect.hxx:167
Helper class for notify that positioning of an anchored object is in progress.
virtual void Calc(vcl::RenderContext *pRenderContext) const
Definition: trvlfrm.cxx:1788
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
void Notify_Background(const SdrObject *pObj, SwPageFrame *pPage, const SwRect &rRect, const PrepareHint eHint, const bool bInva)
Definition: frmtool.cxx:3135
void MakeObjPosAnchoredAtLayout()
method for the intrinsic positioning of an at-page|at-frame anchored drawing object ...
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
SwContact * GetUserCall(const SdrObject *pObj)
Returns the UserCall if applicable from the group object.
Definition: dcontact.cxx:176
void InvalidateFlyInCnt() const
Definition: pagefrm.hxx:355
helper class for oscillation control on object positioning
bool isFrameAreaDefinitionValid() const
Definition: frame.hxx:167
virtual bool SetObjTop_(const SwTwips _nTop) override
virtual const tools::Rectangle & GetSnapRect() const
SwPosNotify(SwAnchoredDrawObject *_pAnchoredDrawObj)
wrapper class for the positioning of Writer fly frames and drawing objects
virtual void InvalidateObjPos() override
method to invalidate position of the anchored object
void SetCurrRelPos(Point _aRelPos)
void Top(const long nTop)
Definition: swrect.hxx:202
#define MID_FRMSIZE_SIZE
Definition: unomid.h:70
virtual void SetAnchorPos(const Point &rPnt)
SwRect & Intersection(const SwRect &rRect)
Definition: swrect.cxx:54
static bool isTextBox(const SwFrameFormat *pFormat, sal_uInt16 nType)
Is the frame format a text box?
void SetTmpConsiderWrapInfluence(const bool _bTmpConsiderWrapInfluence)
bool IsTextFrame() const
Definition: frame.hxx:1210
SwFrameFormat * FindFrameFormat(SdrObject *pObj)
The Get reverse way: seeks the format to the specified object.
Definition: dcontact.cxx:125
void Right(const long nRight)
Definition: swrect.hxx:198
virtual void ObjectAttachedToAnchorFrame()
method to indicate, that anchored object is attached to an anchor frame
SdrObject * DrawObj()
virtual bool IsEnableSetModified() const =0
void SetIdleFlags()
Definition: rootfrm.hxx:246
virtual void MoveObjToVisibleLayer(SdrObject *_pDrawObj)
method to move drawing object to corresponding visible layer
Definition: dcontact.cxx:213
SwAnchoredDrawObject * mpAnchoredDrawObj
SwFrame * AnchorFrame()
void SetObjTop(const SwTwips _nTop)
SwObjPosOscillationControl(const SwAnchoredDrawObject &_rAnchoredDrawObj)
long getY() const
virtual void RegisterAtCorrectPage() override
method to assure that anchored object is registered at the correct page frame
void ResetTurbo()
Definition: rootfrm.hxx:346
long getX() const
bool ConsiderForTextWrap() const
virtual void ObjectAttachedToAnchorFrame() override
method to indicate, that anchored object is attached to an anchor frame
bool HasWrap(const SdrObject *pObj)
Definition: dcontact.cxx:144
virtual void CalcPosition() override
calculate position of object
Point const & LastObjPos() const
Style of a layout element.
Definition: frmfmt.hxx:57
PrepareHint
Definition: swtypes.hxx:204
const SdrObject * GetDrawObj() const
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:81
virtual SwRect GetObjRect() const override
virtual SwFrameFormat::tLayoutDir GetLayoutDir() const
Definition: atrfrm.cxx:2754
SwRect GetBoundRect(OutputDevice const *pOutputDevice) const
Definition: paintfrm.cxx:6060
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:65
SwPageFrame * FindPageFrame()
Definition: frame.hxx:658
RndStdIds GetAnchorId() const
Definition: dcontact.hxx:145
void AppendDrawObjToPage(SwAnchoredObject &_rNewObj)
Definition: flylay.cxx:1046
void SetPos(SwTwips nNew)
Definition: fmtornt.hxx:60
void InvalidatePage(const SwPageFrame *pPage=nullptr) const
Invalidates the page in which the Frame is currently placed.
Definition: wsfrm.cxx:598
std::vector< Point > maObjPositions
SwLayoutFrame * GetUpper()
Definition: frame.hxx:656
bool HasArea() const
Definition: swrect.hxx:290
const SwRect & GetObjRectWithSpaces() const
method to determine object area inclusive its spacing
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:426
void SetDrawObjAnchor()
method to set internal anchor position of instance of the drawing object ...
virtual void Move(const Size &rSiz)
void SetLastObjRect(const tools::Rectangle &_rNewObjRect)
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:119
const IDocumentSettingAccess & getIDocumentSettingAccess() const
Provides access to the document settings interface.
Definition: format.cxx:757
void InvalidateFlyLayout() const
Validate, invalidate and query the Page status Layout/Content and Fly/non-Fly respectively are inspec...
Definition: pagefrm.hxx:347
A page of the document layout.
Definition: pagefrm.hxx:40
const double * GetRelativeWidth() const
long X() const
SwFrame * GetAnchorFrameContainingAnchPos()
determine anchor frame containing the anchor position
virtual ~SwAnchoredDrawObject() override
void MakeObjPosAnchoredAtPara()
method for the intrinsic positioning of an at-paragraph|at-character anchored drawing object ...
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:458
void Left(const long nLeft)
Definition: swrect.hxx:193
const SwLayoutFrame * GetVertPosOrientFrame() const
const SwContentFrame * GetTurbo()
Definition: rootfrm.hxx:347
virtual SwFrameFormat & GetFrameFormat() override
const Point & GetCurrRelPos() const
tools::Rectangle SVRect() const
Definition: swrect.hxx:282
bool ConsiderObjWrapInfluenceOnObjPos() const
method to determine, if wrapping style influence of the anchored object has to be considered on the o...
bool InvalidationOfPosAllowed() const
method to determine, if invalidation of position is allowed
SwPageFrame * FindPageFrameOfAnchor()
method to determine the page frame, on which the 'anchor' of the given anchored object is...
#define RES_DRAWFRMFMT
Definition: hintids.hxx:277
SwPageFrame * GetPageFrame()
void ClrContourCache(const SdrObject *pObj)
Definition: txtfly.cxx:140
void Width(long nNew)
Definition: swrect.hxx:185
SwTwips GetPos() const
Definition: fmtornt.hxx:59
virtual SwRect GetObjBoundRect() const override
void AdjustPositioningAttr(const SwFrame *_pNewAnchorFrame, const SwRect *_pNewObjRect=nullptr)
adjust positioning and alignment attributes for new anchor frame
bool IsRightToLeft() const
Definition: frame.hxx:963
void InvalidateObjRectWithSpaces() const
bool ObjAnchoredAsChar() const
Definition: dcontact.hxx:150
TextFrameIndex CalcFlyPos(SwFrameFormat const *pSearch)
Calculates the position of FlyInContentFrames.
Definition: porfly.cxx:186
bool ConsiderObjWrapInfluenceOfOtherObjs() const
method to determine, if other anchored objects, also attached at to the anchor frame, have to consider its wrap influence.
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
const Point & GetAnchorPos() const
void SetPos(SwTwips nNew)
Definition: fmtornt.hxx:93
void SetObjLeft(const SwTwips _nLeft)
void DisallowTurbo() const
Definition: rootfrm.hxx:342
virtual void MakeObjPos() override
method to determine position for the object and set the position at the object
bool IsVertical() const
Definition: frame.hxx:949
virtual void SetEnableSetModified(bool bEnableSetModified)=0
bool IsInDtor() const
Definition: doc.hxx:397
static void syncProperty(SwFrameFormat *pShape, sal_uInt16 nWID, sal_uInt8 nMemberID, const css::uno::Any &rValue)
Sync property of TextBox with the one of the shape.
virtual void UpdateLayoutDir() override
method update layout direction the layout direction, the anchored object is assigned to ...
void SetPositioningAttr()
method to set positioning attributes (not for as-character anchored)
const SwFrame * GetAnchorFrame() const
void SetVertPosOrientFrame(const SwLayoutFrame &_rVertPosOrientFrame)
virtual bool Prepare(const PrepareHint ePrep=PREP_CLEAR, const void *pVoid=nullptr, bool bNotify=true)
Definition: wsfrm.cxx:588
virtual void CalcPosition() override
calculate position for object
SwViewShell * GetCurrShell() const
Definition: rootfrm.hxx:204
bool IsPositioningInProgress() const
is positioning of anchored object in progress
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
Point GetFrameAnchorPos(bool bIgnoreFlysAnchoredAtThisFrame) const
returns the position for anchors based on frame direction
Definition: ssfrm.cxx:289
virtual bool SetObjLeft_(const SwTwips _nLeft) override
void SetRestartLayoutProcess(const bool _bRestartLayoutProcess)
virtual void SetPositionLayoutDir(const sal_Int16 _nPositionLayoutDir)
Definition: atrfrm.cxx:2769
const sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:61
SwRootFrame * getRootFrame()
Definition: frame.hxx:657
const Point & GetRelPos() const
calculated relative position for object
const SwLayoutFrame & GetVertPosOrientFrame() const
frame, at which the vertical position is oriented at
long Y() const
void MoveAccessible(const SwFrame *pFrame, const SdrObject *pObj, const SwRect &rOldFrame)
Move a frame's position in the accessible view.
Definition: viewimp.cxx:327
const double * GetRelativeHeight() const
virtual const SwFrameFormat * GetFormat() const
Definition: ssfrm.cxx:393