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 
40 namespace {
41 
44 class SwPosNotify
45 {
46  private:
47  SwAnchoredDrawObject* mpAnchoredDrawObj;
48  SwRect maOldObjRect;
49  SwPageFrame* mpOldPageFrame;
50 
51  public:
52  explicit SwPosNotify( SwAnchoredDrawObject* _pAnchoredDrawObj );
53  ~SwPosNotify() COVERITY_NOEXCEPT_FALSE;
54  // #i32795#
55  Point const & LastObjPos() const;
56 };
57 
58 }
59 
60 SwPosNotify::SwPosNotify( SwAnchoredDrawObject* _pAnchoredDrawObj ) :
61  mpAnchoredDrawObj( _pAnchoredDrawObj )
62 {
63  maOldObjRect = mpAnchoredDrawObj->GetObjRect();
64  // --> #i35640# - determine correct page frame
65  mpOldPageFrame = mpAnchoredDrawObj->GetPageFrame();
66 }
67 
68 SwPosNotify::~SwPosNotify() COVERITY_NOEXCEPT_FALSE
69 {
70  if ( maOldObjRect != mpAnchoredDrawObj->GetObjRect() )
71  {
72  if( maOldObjRect.HasArea() && mpOldPageFrame )
73  {
74  mpAnchoredDrawObj->NotifyBackground( mpOldPageFrame, maOldObjRect,
76  }
77  SwRect aNewObjRect( mpAnchoredDrawObj->GetObjRect() );
78  if( aNewObjRect.HasArea() )
79  {
80  // --> #i35640# - determine correct page frame
81  SwPageFrame* pNewPageFrame = mpAnchoredDrawObj->GetPageFrame();
82  if( pNewPageFrame )
83  mpAnchoredDrawObj->NotifyBackground( pNewPageFrame, aNewObjRect,
85  }
86 
87  ::ClrContourCache( mpAnchoredDrawObj->GetDrawObj() );
88 
89  // --> #i35640# - additional notify anchor text frame
90  // Needed for negative positioned drawing objects
91  // --> #i43255# - refine condition to avoid unneeded
92  // invalidations: anchored object had to be on the page of its anchor
93  // text frame.
94  if ( mpAnchoredDrawObj->GetAnchorFrame()->IsTextFrame() &&
95  mpOldPageFrame == mpAnchoredDrawObj->GetAnchorFrame()->FindPageFrame() )
96  {
97  mpAnchoredDrawObj->AnchorFrame()->Prepare( PrepareHint::FlyFrameLeave );
98  }
99 
100  // indicate a restart of the layout process
101  mpAnchoredDrawObj->SetRestartLayoutProcess( true );
102  }
103  else
104  {
105  // lock position
106  mpAnchoredDrawObj->LockPosition();
107 
108  if ( !mpAnchoredDrawObj->ConsiderForTextWrap() )
109  {
110  // indicate that object has to be considered for text wrap
111  mpAnchoredDrawObj->SetConsiderForTextWrap( true );
112  // invalidate 'background' in order to allow its 'background'
113  // to wrap around it.
114  mpAnchoredDrawObj->NotifyBackground( mpAnchoredDrawObj->GetPageFrame(),
115  mpAnchoredDrawObj->GetObjRectWithSpaces(),
117  // invalidate position of anchor frame in order to force
118  // a re-format of the anchor frame, which also causes a
119  // re-format of the invalid previous frames of the anchor frame.
120  mpAnchoredDrawObj->AnchorFrame()->InvalidatePos();
121  }
122  }
123  // tdf#101464 notify SwAccessibleMap about new drawing object position
124  if (mpOldPageFrame && mpOldPageFrame->getRootFrame()->IsAnyShellAccessible())
125  {
126  mpOldPageFrame->getRootFrame()->GetCurrShell()->Imp()->MoveAccessible(
127  nullptr, mpAnchoredDrawObj->GetDrawObj(), maOldObjRect);
128  }
129 }
130 
131 // --> #i32795#
132 Point const & SwPosNotify::LastObjPos() const
133 {
134  return maOldObjRect.Pos();
135 }
136 
137 namespace {
138 
139 // #i32795#
141 class SwObjPosOscillationControl
142 {
143  private:
144  const SwAnchoredDrawObject* mpAnchoredDrawObj;
145 
146  std::vector<Point> maObjPositions;
147 
148  public:
149  explicit SwObjPosOscillationControl( const SwAnchoredDrawObject& _rAnchoredDrawObj );
150 
151  bool OscillationDetected();
152 };
153 
154 }
155 
156 SwObjPosOscillationControl::SwObjPosOscillationControl(
157  const SwAnchoredDrawObject& _rAnchoredDrawObj )
158  : mpAnchoredDrawObj( &_rAnchoredDrawObj )
159 {
160 }
161 
162 bool SwObjPosOscillationControl::OscillationDetected()
163 {
164  bool bOscillationDetected = false;
165 
166  if ( maObjPositions.size() == 20 )
167  {
168  // position stack is full -> oscillation
169  bOscillationDetected = true;
170  }
171  else
172  {
173  Point aNewObjPos = mpAnchoredDrawObj->GetObjRect().Pos();
174  for ( auto const & pt : maObjPositions )
175  {
176  if ( aNewObjPos == pt )
177  {
178  // position already occurred -> oscillation
179  bOscillationDetected = true;
180  break;
181  }
182  }
183  if ( !bOscillationDetected )
184  {
185  maObjPositions.push_back( aNewObjPos );
186  }
187  }
188 
189  return bOscillationDetected;
190 }
191 
192 
195  mbValidPos( false ),
196  mbNotYetAttachedToAnchorFrame( true ),
197  // --> #i28749#
198  mbNotYetPositioned( true ),
199  // --> #i62875#
200  mbCaptureAfterLayoutDirChange( false )
201 {
202 }
203 
205 {
206 }
207 
208 // --> #i62875#
210 {
211  SwFrameFormat::tLayoutDir nOldLayoutDir( GetFrameFormat().GetLayoutDir() );
212 
214 
215  if ( !NotYetPositioned() &&
216  GetFrameFormat().GetLayoutDir() != nOldLayoutDir &&
217  GetFrameFormat().GetDoc()->GetDocumentSettingManager().get(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
218  !IsOutsidePage() )
219  {
221  }
222 }
223 
224 // --> #i62875#
226 {
227  bool bOutsidePage( false );
228 
229  if ( !NotYetPositioned() && GetPageFrame() )
230  {
231  SwRect aTmpRect( GetObjRect() );
232  bOutsidePage =
233  ( aTmpRect.Intersection( GetPageFrame()->getFrameArea() ) != GetObjRect() );
234  }
235 
236  return bOutsidePage;
237 }
238 
240 {
241  if ( IsPositioningInProgress() )
242  {
243  // nothing to do - positioning already in progress
244  return;
245  }
246 
247  if ( mbValidPos )
248  {
249  // nothing to do - position is valid
250  return;
251  }
252 
253  // --> #i28749# - anchored drawing object has to be attached
254  // to anchor frame
256  {
257  OSL_FAIL( "<SwAnchoredDrawObject::MakeObjPos() - drawing object not yet attached to anchor frame -> no positioning" );
258  return;
259  }
260 
261  SwDrawContact* pDrawContact =
262  static_cast<SwDrawContact*>(::GetUserCall( GetDrawObj() ));
263 
264  // --> #i28749# - if anchored drawing object hasn't been yet
265  // positioned, convert its positioning attributes, if its positioning
266  // attributes are given in horizontal left-to-right layout.
267  // --> #i36010# - Note: horizontal left-to-right layout is made
268  // the default layout direction for <SwDrawFrameFormat> instances. Thus, it has
269  // to be adjusted manually, if no adjustment of the positioning attributes
270  // have to be performed here.
271  // --> #i35635# - additionally move drawing object to the visible layer.
272  if ( mbNotYetPositioned )
273  {
274  // --> #i35635#
275  pDrawContact->MoveObjToVisibleLayer( DrawObj() );
276  // --> perform conversion of positioning
277  // attributes only for 'master' drawing objects
278  // #i44334#, #i44681# - check, if positioning
279  // attributes already have been set.
280  if ( dynamic_cast< const SwDrawVirtObj* >(GetDrawObj()) == nullptr &&
281  !static_cast<SwDrawFrameFormat&>(GetFrameFormat()).IsPosAttrSet() )
282  {
284  }
285  // -->
286  // - reset internal flag after all needed actions are performed to
287  // avoid callbacks from drawing layer
288  mbNotYetPositioned = false;
289  }
290 
291  // indicate that positioning is in progress
292  {
293  SwObjPositioningInProgress aObjPosInProgress( *this );
294 
295  // determine relative position of drawing object and set it
296  switch ( pDrawContact->GetAnchorId() )
297  {
298  case RndStdIds::FLY_AS_CHAR:
299  {
300  // indicate that position will be valid after positioning is performed
301  mbValidPos = true;
302  // nothing to do, because as-character anchored objects are positioned
303  // during the format of its anchor frame - see <SwFlyCntPortion::SetBase(..)>
304  }
305  break;
306  case RndStdIds::FLY_AT_PARA:
307  case RndStdIds::FLY_AT_CHAR:
308  {
309  // --> #i32795# - move intrinsic positioning to
310  // helper method <MakeObjPosAnchoredAtPara()>
312  }
313  break;
314  case RndStdIds::FLY_AT_PAGE:
315  case RndStdIds::FLY_AT_FLY:
316  {
317  // --> #i32795# - move intrinsic positioning to
318  // helper method <MakeObjPosAnchoredAtLayout()>
320  }
321  break;
322  default:
323  {
324  assert(!"<SwAnchoredDrawObject::MakeObjPos()> - unknown anchor type.");
325  }
326  }
327 
328  // keep, current object rectangle
329  // --> #i34748# - use new method <SetLastObjRect(..)>
330  SetLastObjRect( GetObjRect().SVRect() );
331 
332  // Assure for 'master' drawing object, that it's registered at the correct page.
333  // Perform check not for as-character anchored drawing objects and only if
334  // the anchor frame is valid.
335  if ( dynamic_cast< const SwDrawVirtObj* >(GetDrawObj()) == nullptr &&
336  !pDrawContact->ObjAnchoredAsChar() &&
338  {
339  pDrawContact->ChkPage();
340  }
341  }
342 
343  // --> #i62875#
345  GetPageFrame() )
346  {
347  SwRect aPageRect( GetPageFrame()->getFrameArea() );
348  SwRect aObjRect( GetObjRect() );
349  if ( aObjRect.Right() >= aPageRect.Right() + 10 )
350  {
351  Size aSize( aPageRect.Right() - aObjRect.Right(), 0 );
352  DrawObj()->Move( aSize );
353  aObjRect = GetObjRect();
354  }
355 
356  if ( aObjRect.Left() + 10 <= aPageRect.Left() )
357  {
358  Size aSize( aPageRect.Left() - aObjRect.Left(), 0 );
359  DrawObj()->Move( aSize );
360  }
361 
363  }
364 }
365 
372 {
373  // --> #i32795# - adopt positioning algorithm from Writer
374  // fly frames, which are anchored at paragraph|at character
375 
376  // Determine, if anchor frame can/has to be formatted.
377  // If yes, after each object positioning the anchor frame is formatted.
378  // If after the anchor frame format the object position isn't valid, the
379  // object is positioned again.
380  // --> #i43255# - refine condition: anchor frame format not
381  // allowed, if another anchored object, has to be consider its wrap influence
382  // --> #i50356# - format anchor frame containing the anchor
383  // position. E.g., for at-character anchored object this can be the follow
384  // frame of the anchor frame, which contains the anchor character.
385  bool bJoinLocked
386  = static_cast<const SwTextFrame*>(GetAnchorFrameContainingAnchPos())->IsAnyJoinLocked();
387  const bool bFormatAnchor = !bJoinLocked && !ConsiderObjWrapInfluenceOnObjPos()
389 
390  // Format of anchor is needed for (vertical) fly offsets, otherwise the
391  // lack of fly portions will result in an incorrect 0 offset.
392  bool bAddVerticalFlyOffsets = GetFrameFormat().getIDocumentSettingAccess().get(
394  bool bFormatAnchorOnce = !bJoinLocked && bAddVerticalFlyOffsets;
395 
396  if (bFormatAnchor || bFormatAnchorOnce)
397  {
398  // --> #i50356#
399  GetAnchorFrameContainingAnchPos()->Calc(GetAnchorFrameContainingAnchPos()->getRootFrame()->GetCurrShell()->GetOut());
400  }
401 
402  bool bOscillationDetected = false;
403  SwObjPosOscillationControl aObjPosOscCtrl( *this );
404  // --> #i3317# - boolean, to apply temporarily the
405  // 'straightforward positioning process' for the frame due to its
406  // overlapping with a previous column.
407  bool bConsiderWrapInfluenceDueToOverlapPrevCol( false );
408  do {
409  // indicate that position will be valid after positioning is performed
410  mbValidPos = true;
411 
412  // --> #i35640# - correct scope for <SwPosNotify> instance
413  {
414  // create instance of <SwPosNotify> for correct notification
415  SwPosNotify aPosNotify( this );
416 
417  // determine and set position
419  aObjPositioning( *DrawObj() );
420  aObjPositioning.CalcPosition();
421 
422  // get further needed results of the positioning algorithm
423  SetVertPosOrientFrame ( aObjPositioning.GetVertPosOrientFrame() );
425 
426  // check for object position oscillation, if position has changed.
427  if ( GetObjRect().Pos() != aPosNotify.LastObjPos() )
428  {
429  bOscillationDetected = aObjPosOscCtrl.OscillationDetected();
430  }
431  }
432  // format anchor frame, if requested.
433  // Note: the format of the anchor frame can cause the object position
434  // to be invalid.
435  if ( bFormatAnchor )
436  {
437  // --> #i50356#
438  GetAnchorFrameContainingAnchPos()->Calc(GetAnchorFrameContainingAnchPos()->getRootFrame()->GetCurrShell()->GetOut());
439  }
440 
441  // --> #i3317#
444  {
445  bConsiderWrapInfluenceDueToOverlapPrevCol = true;
446  }
447  } while ( !mbValidPos && !bOscillationDetected &&
448  !bConsiderWrapInfluenceDueToOverlapPrevCol );
449 
450  // --> #i3317# - consider a detected oscillation and overlapping
451  // with previous column.
452  // temporarily consider the anchored objects wrapping style influence
453  if ( bOscillationDetected || bConsiderWrapInfluenceDueToOverlapPrevCol )
454  {
456  SetRestartLayoutProcess( true );
457  }
458 }
459 
466 {
467  // indicate that position will be valid after positioning is performed
468  mbValidPos = true;
469 
470  // create instance of <SwPosNotify> for correct notification
471  SwPosNotify aPosNotify( this );
472 
473  // determine position
475  aObjPositioning( *DrawObj() );
476  aObjPositioning.CalcPosition();
477 
478  // set position
479 
480  // --> #i31698#
481  // --> #i34995# - setting anchor position needed for filters,
482  // especially for the xml-filter to the OpenOffice.org file format
483  {
484  const Point aNewAnchorPos =
486  DrawObj()->SetAnchorPos( aNewAnchorPos );
487  // --> #i70122# - missing invalidation
489  }
490  SetCurrRelPos( aObjPositioning.GetRelPos() );
491  const SwFrame* pAnchorFrame = GetAnchorFrame();
492  SwRectFnSet aRectFnSet(pAnchorFrame);
493  const Point aAnchPos( aRectFnSet.GetPos(pAnchorFrame->getFrameArea()) );
494  SetObjLeft( aAnchPos.X() + GetCurrRelPos().X() );
495  SetObjTop( aAnchPos.Y() + GetCurrRelPos().Y() );
496 }
497 
499 {
500  // new anchor position
501  // --> #i31698# -
502  Point aNewAnchorPos =
504  Point aCurrAnchorPos = GetDrawObj()->GetAnchorPos();
505  if ( aNewAnchorPos != aCurrAnchorPos )
506  {
507  // determine movement to be applied after setting the new anchor position
508  Size aMove( aCurrAnchorPos.getX() - aNewAnchorPos.getX(),
509  aCurrAnchorPos.getY() - aNewAnchorPos.getY() );
510  // set new anchor position
511  DrawObj()->SetAnchorPos( aNewAnchorPos );
512  // correct object position, caused by setting new anchor position
513  DrawObj()->Move( aMove );
514  // --> #i70122# - missing invalidation
516  }
517 }
518 
524 {
525  if ( _pPageFrame && !_pPageFrame->GetFormat()->GetDoc()->IsInDtor() )
526  {
527  if ( _pPageFrame->GetUpper() )
528  {
529  // --> #i35007# - correct invalidation for as-character
530  // anchored objects.
531  if ( GetFrameFormat().GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR )
532  {
533  _pPageFrame->InvalidateFlyInCnt();
534  }
535  else
536  {
537  _pPageFrame->InvalidateFlyLayout();
538  }
539 
540  SwRootFrame* pRootFrame = static_cast<SwRootFrame*>(_pPageFrame->GetUpper());
541  pRootFrame->DisallowTurbo();
542  if ( pRootFrame->GetTurbo() )
543  {
544  const SwContentFrame* pTmpFrame = pRootFrame->GetTurbo();
545  pRootFrame->ResetTurbo();
546  pTmpFrame->InvalidatePage();
547  }
548  pRootFrame->SetIdleFlags();
549  }
550  }
551 }
552 
554 {
555  // --> #i28701# - check, if invalidation is allowed
556  if ( mbValidPos &&
558  {
559  mbValidPos = false;
560  // --> #i68520#
562 
563  // --> #i44339# - check, if anchor frame exists.
564  if ( GetAnchorFrame() )
565  {
566  // --> #118547# - notify anchor frame of as-character
567  // anchored object, because its positioned by the format of its anchor frame.
568  // --> #i44559# - assure, that text hint is already
569  // existing in the text frame
570  if ( dynamic_cast< const SwTextFrame* >(GetAnchorFrame()) != nullptr &&
571  (GetFrameFormat().GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR) )
572  {
573  SwTextFrame* pAnchorTextFrame( static_cast<SwTextFrame*>(AnchorFrame()) );
574  if (pAnchorTextFrame->CalcFlyPos(&GetFrameFormat()) != TextFrameIndex(COMPLETE_STRING))
575  {
577  }
578  }
579 
580  SwPageFrame* pPageFrame = AnchorFrame()->FindPageFrame();
581  InvalidatePage_( pPageFrame );
582 
583  // --> #i32270# - also invalidate page frame, at which the
584  // drawing object is registered at.
585  SwPageFrame* pPageFrameRegisteredAt = GetPageFrame();
586  if ( pPageFrameRegisteredAt &&
587  pPageFrameRegisteredAt != pPageFrame )
588  {
589  InvalidatePage_( pPageFrameRegisteredAt );
590  }
591  // #i33751#, #i34060# - method <GetPageFrameOfAnchor()>
592  // is replaced by method <FindPageFrameOfAnchor()>. It's return value
593  // have to be checked.
594  SwPageFrame* pPageFrameOfAnchor = FindPageFrameOfAnchor();
595  if ( pPageFrameOfAnchor &&
596  pPageFrameOfAnchor != pPageFrame &&
597  pPageFrameOfAnchor != pPageFrameRegisteredAt )
598  {
599  InvalidatePage_( pPageFrameOfAnchor );
600  }
601  }
602  }
603 }
604 
606 {
607  assert(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFormat());
608  return *(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFormat());
609 }
611 {
612  assert(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFormat());
613  return *(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFormat());
614 }
615 
617 {
618  // use geometry of drawing object
619  //return GetDrawObj()->GetCurrentBoundRect();
620  return GetDrawObj()->GetSnapRect();
621 }
622 
623 // --> #i70122#
625 {
626  bool bGroupShape = dynamic_cast<const SdrObjGroup*>( GetDrawObj() );
627  // Resize objects with relative width or height
628  if ( !bGroupShape && GetPageFrame( ) && ( GetDrawObj( )->GetRelativeWidth( ) || GetDrawObj()->GetRelativeHeight( ) ) )
629  {
630  tools::Rectangle aCurrObjRect = GetDrawObj()->GetCurrentBoundRect();
631 
632  long nTargetWidth = aCurrObjRect.GetWidth( );
633  if ( GetDrawObj( )->GetRelativeWidth( ) )
634  {
635  tools::Rectangle aPageRect;
636  if (GetDrawObj()->GetRelativeWidthRelation() == text::RelOrientation::FRAME)
637  // Exclude margins.
638  aPageRect = GetPageFrame()->getFramePrintArea().SVRect();
639  else
640  aPageRect = GetPageFrame( )->GetBoundRect( GetPageFrame()->getRootFrame()->GetCurrShell()->GetOut() ).SVRect();
641  nTargetWidth = aPageRect.GetWidth( ) * (*GetDrawObj( )->GetRelativeWidth());
642  }
643 
644  long nTargetHeight = aCurrObjRect.GetHeight( );
645  if ( GetDrawObj( )->GetRelativeHeight( ) )
646  {
647  tools::Rectangle aPageRect;
648  if (GetDrawObj()->GetRelativeHeightRelation() == text::RelOrientation::FRAME)
649  // Exclude margins.
650  aPageRect = GetPageFrame()->getFramePrintArea().SVRect();
651  else
652  aPageRect = GetPageFrame( )->GetBoundRect( GetPageFrame()->getRootFrame()->GetCurrShell()->GetOut() ).SVRect();
653  nTargetHeight = aPageRect.GetHeight( ) * (*GetDrawObj( )->GetRelativeHeight());
654  }
655 
656  if ( nTargetWidth != aCurrObjRect.GetWidth( ) || nTargetHeight != aCurrObjRect.GetHeight( ) )
657  {
658  SwDoc* pDoc = const_cast<SwDoc*>(GetPageFrame()->GetFormat()->GetDoc());
659 
660  bool bEnableSetModified = pDoc->getIDocumentState().IsEnableSetModified();
662  auto pObject = const_cast<SdrObject*>(GetDrawObj());
663  pObject->Resize( aCurrObjRect.TopLeft(),
664  Fraction( nTargetWidth, aCurrObjRect.GetWidth() ),
665  Fraction( nTargetHeight, aCurrObjRect.GetHeight() ), false );
666 
667  if (SwFrameFormat* pFrameFormat = FindFrameFormat(pObject))
668  {
669  if (SwTextBoxHelper::isTextBox(pFrameFormat, RES_DRAWFRMFMT))
670  {
671  // Shape has relative size and also a textbox, update its text area as well.
672  uno::Reference<drawing::XShape> xShape(pObject->getUnoShape(), uno::UNO_QUERY);
674  uno::makeAny(xShape->getSize()));
675  }
676  }
677 
678  pDoc->getIDocumentState().SetEnableSetModified(bEnableSetModified);
679  }
680  }
681  return GetDrawObj()->GetCurrentBoundRect();
682 }
683 
684 // --> #i68520#
686 {
687  SwTwips nDiff = _nTop - GetObjRect().Top();
688  DrawObj()->Move( Size( 0, nDiff ) );
689 
690  return nDiff != 0;
691 }
693 {
694  SwTwips nDiff = _nLeft - GetObjRect().Left();
695  DrawObj()->Move( Size( nDiff, 0 ) );
696 
697  return nDiff != 0;
698 }
699 
705  const SwRect* _pNewObjRect )
706 {
707  SwTwips nHoriRelPos = 0;
708  SwTwips nVertRelPos = 0;
709  const Point aAnchorPos = _pNewAnchorFrame->GetFrameAnchorPos( ::HasWrap( GetDrawObj() ) );
710  // --> #i33313#
711  const SwRect aObjRect( _pNewObjRect ? *_pNewObjRect : GetObjRect() );
712  const bool bVert = _pNewAnchorFrame->IsVertical();
713  const bool bR2L = _pNewAnchorFrame->IsRightToLeft();
714  if ( bVert )
715  {
716  nHoriRelPos = aObjRect.Top() - aAnchorPos.Y();
717  nVertRelPos = aAnchorPos.X() - aObjRect.Right();
718  }
719  else if ( bR2L )
720  {
721  nHoriRelPos = aAnchorPos.X() - aObjRect.Right();
722  nVertRelPos = aObjRect.Top() - aAnchorPos.Y();
723  }
724  else
725  {
726  nHoriRelPos = aObjRect.Left() - aAnchorPos.X();
727  nVertRelPos = aObjRect.Top() - aAnchorPos.Y();
728  }
729 
730  GetFrameFormat().SetFormatAttr( SwFormatHoriOrient( nHoriRelPos, text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
731  GetFrameFormat().SetFormatAttr( SwFormatVertOrient( nVertRelPos, text::VertOrientation::NONE, text::RelOrientation::FRAME ) );
732 }
733 
734 // --> #i34748# - change return type.
735 // If member <mpLastObjRect> is NULL, create one.
737 {
738  maLastObjRect = _rNewLastRect;
739 }
740 
742 {
743  // --> #i31698#
745 
747  {
749  }
750 }
751 
762 {
763  SwDrawContact* pDrawContact =
764  static_cast<SwDrawContact*>(GetUserCall( GetDrawObj() ));
765 
766  if ( !pDrawContact->ObjAnchoredAsChar() )
767  {
768  SwRect aObjRect( GetObjRect() );
769 
770  SwTwips nHoriPos = aObjRect.Left();
771  SwTwips nVertPos = aObjRect.Top();
772  // #i44334#, #i44681#
773  // perform conversion only if position is in horizontal-left-to-right-layout.
774  if ( GetFrameFormat().GetPositionLayoutDir() ==
775  text::PositionLayoutDir::PositionInHoriL2R )
776  {
778  switch ( eLayoutDir )
779  {
781  {
782  // nothing to do
783  }
784  break;
786  {
787  nHoriPos = -aObjRect.Left() - aObjRect.Width();
788  }
789  break;
791  {
792  nHoriPos = aObjRect.Top();
793  nVertPos = -aObjRect.Left() - aObjRect.Width();
794  }
795  break;
796  default:
797  {
798  assert(!"<SwAnchoredDrawObject::SetPositioningAttr()> - unsupported layout direction");
799  }
800  }
801  }
802 
803  // --> #i71182#
804  // only change position - do not lose other attributes
805 
806  SwFormatHoriOrient aHori( GetFrameFormat().GetHoriOrient() );
807  if (nHoriPos != aHori.GetPos()) {
808  aHori.SetPos( nHoriPos );
810  GetFrameFormat().SetFormatAttr( aHori );
811  }
812 
813  SwFormatVertOrient aVert( GetFrameFormat().GetVertOrient() );
814  if (nVertPos != aVert.GetPos()) {
815  aVert.SetPos( nVertPos );
817  GetFrameFormat().SetFormatAttr( aVert );
818  }
819 
820  // --> #i36010# - set layout direction of the position
822  text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
823  }
824  // --> #i65798# - also for as-character anchored objects
825  // --> #i45952# - indicate that position
826  // attributes are set now.
827  static_cast<SwDrawFrameFormat&>(GetFrameFormat()).PosAttrSet();
828 }
829 
831  const SwRect& _rRect,
832  PrepareHint _eHint )
833 {
834  ::Notify_Background( GetDrawObj(), _pPageFrame, _rRect, _eHint, true );
835 }
836 
843 {
844  SwPageFrame* pPageFrame( nullptr );
845  if ( GetVertPosOrientFrame() )
846  {
847  pPageFrame = const_cast<SwPageFrame*>(GetVertPosOrientFrame()->FindPageFrame());
848  }
849  if ( pPageFrame && GetPageFrame() != pPageFrame )
850  {
851  if ( GetPageFrame() )
853  pPageFrame->AppendDrawObjToPage( *this );
854  }
855 }
856 
857 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:289
void ChkPage()
Definition: dcontact.cxx:1923
Point GetPos(const SwRect &rRect) const
Definition: frame.hxx:1359
long GetHeight() const
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
bool IsAnyShellAccessible() const
Definition: rootfrm.hxx:384
SwViewShellImp * Imp()
Definition: viewsh.hxx:185
virtual bool Prepare(const PrepareHint ePrep=PrepareHint::Clear, const void *pVoid=nullptr, bool bNotify=true)
Definition: wsfrm.cxx:587
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:186
void InvalidatePage_(SwPageFrame *_pPageFrame)
method to invalidate the given page frame
void InvalidatePos()
Definition: frame.hxx:1019
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:1785
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:3168
EmbeddedObjectRef * pObject
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:170
void InvalidateFlyInCnt() const
Definition: pagefrm.hxx:355
bool isFrameAreaDefinitionValid() const
Definition: frame.hxx:167
virtual bool SetObjTop_(const SwTwips _nTop) override
virtual const tools::Rectangle & GetSnapRect() const
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:119
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:207
SwFrame * AnchorFrame()
void SetObjTop(const SwTwips _nTop)
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:138
virtual void CalcPosition() override
calculate position of object
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:2768
SwRect GetBoundRect(OutputDevice const *pOutputDevice) const
Definition: paintfrm.cxx:6110
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:597
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:393
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
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:372
std::optional< tools::Rectangle > maLastObjRect
SwPageFrame * GetPageFrame()
void ClrContourCache(const SdrObject *pObj)
Definition: txtfly.cxx:133
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:182
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
const SwContentFrame * GetTurbo() const
Definition: rootfrm.hxx:347
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:399
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 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:2783
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:320
const double * GetRelativeHeight() const
virtual const SwFrameFormat * GetFormat() const
Definition: ssfrm.cxx:393