LibreOffice Module sw (master)  1
objectformatterlayfrm.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 
21 #include <anchoredobject.hxx>
22 #include <sortedobjs.hxx>
23 #include <pagefrm.hxx>
24 
25 #include <layact.hxx>
26 
28  const SwPageFrame& _rPageFrame,
29  SwLayAction* _pLayAction )
30  : SwObjectFormatter( _rPageFrame, _pLayAction ),
31  mrAnchorLayFrame( _rAnchorLayFrame )
32 {
33 }
34 
36 {
37 }
38 
39 std::unique_ptr<SwObjectFormatterLayFrame> SwObjectFormatterLayFrame::CreateObjFormatter(
40  SwLayoutFrame& _rAnchorLayFrame,
41  const SwPageFrame& _rPageFrame,
42  SwLayAction* _pLayAction )
43 {
44  if ( !_rAnchorLayFrame.IsPageFrame() &&
45  !_rAnchorLayFrame.IsFlyFrame() )
46  {
47  OSL_FAIL( "<SwObjectFormatterLayFrame::CreateObjFormatter(..)> - unexpected type of anchor frame " );
48  return nullptr;
49  }
50 
51  std::unique_ptr<SwObjectFormatterLayFrame> pObjFormatter;
52 
53  // create object formatter, if floating screen objects are registered at
54  // given anchor layout frame.
55  if ( _rAnchorLayFrame.GetDrawObjs() ||
56  ( _rAnchorLayFrame.IsPageFrame() &&
57  static_cast<SwPageFrame&>(_rAnchorLayFrame).GetSortedObjs() ) )
58  {
59  pObjFormatter.reset(
60  new SwObjectFormatterLayFrame( _rAnchorLayFrame, _rPageFrame, _pLayAction ));
61  }
62 
63  return pObjFormatter;
64 }
65 
67 {
68  return mrAnchorLayFrame;
69 }
70 
71 // #i40147# - add parameter <_bCheckForMovedFwd>.
72 // Not relevant for objects anchored at layout frame.
74  const bool )
75 {
76  FormatObj_( _rAnchoredObj );
77 
78  // #124218# - consider that the layout action has to be
79  // restarted due to a deleted page frame.
80  return GetLayAction() == nullptr || !GetLayAction()->IsAgain();
81 }
82 
84 {
85  bool bSuccess = FormatObjsAtFrame_();
86 
87  if ( bSuccess && GetAnchorFrame().IsPageFrame() )
88  {
89  // anchor layout frame is a page frame.
90  // Thus, format also all anchored objects, which are registered at
91  // this page frame, whose 'anchor' isn't on this page frame and whose
92  // anchor frame is valid.
93  bSuccess = AdditionalFormatObjsOnPage();
94  }
95 
96  return bSuccess;
97 }
98 
106 {
107  if ( !GetAnchorFrame().IsPageFrame() )
108  {
109  OSL_FAIL( "<SwObjectFormatterLayFrame::AdditionalFormatObjsOnPage()> - mis-usage of method, call only for anchor frames of type page frame" );
110  return true;
111  }
112 
113  // #124218# - consider, if the layout action
114  // has to be restarted due to a delete of a page frame.
115  if ( GetLayAction() && GetLayAction()->IsAgain() )
116  {
117  return false;
118  }
119 
120  SwPageFrame& rPageFrame = static_cast<SwPageFrame&>(GetAnchorFrame());
121 
122  if ( !rPageFrame.GetSortedObjs() )
123  {
124  // nothing to do, if no floating screen object is registered at the anchor frame.
125  return true;
126  }
127 
128  bool bSuccess( true );
129 
130  for ( size_t i = 0; i < rPageFrame.GetSortedObjs()->size(); ++i )
131  {
132  SwAnchoredObject* pAnchoredObj = (*rPageFrame.GetSortedObjs())[i];
133 
134  // #i51941# - do not format object, which are anchored
135  // inside or at fly frame.
136  if ( pAnchoredObj->GetAnchorFrame()->FindFlyFrame() )
137  {
138  continue;
139  }
140  // #i33751#, #i34060# - method <GetPageFrameOfAnchor()>
141  // is replaced by method <FindPageFrameOfAnchor()>. It's return value
142  // have to be checked.
143  SwPageFrame* pPageFrameOfAnchor = pAnchoredObj->FindPageFrameOfAnchor();
144  // #i26945# - check, if the page frame of the
145  // object's anchor frame isn't the given page frame
146  OSL_ENSURE( pPageFrameOfAnchor,
147  "<SwObjectFormatterLayFrame::AdditionalFormatObjsOnPage()> - missing page frame" );
148  if ( pPageFrameOfAnchor &&
149  // #i35911#
150  pPageFrameOfAnchor->GetPhyPageNum() < rPageFrame.GetPhyPageNum() )
151  {
152  // if format of object fails, stop formatting and pass fail to
153  // calling method via the return value.
154  if ( !DoFormatObj( *pAnchoredObj ) )
155  {
156  bSuccess = false;
157  break;
158  }
159 
160  // considering changes at <GetAnchorFrame().GetDrawObjs()> during
161  // format of the object.
162  if ( !rPageFrame.GetSortedObjs() ||
163  i > rPageFrame.GetSortedObjs()->size() )
164  {
165  break;
166  }
167  else
168  {
169  const size_t nActPosOfObj =
170  rPageFrame.GetSortedObjs()->ListPosOf( *pAnchoredObj );
171  if ( nActPosOfObj == rPageFrame.GetSortedObjs()->size() ||
172  nActPosOfObj > i )
173  {
174  --i;
175  }
176  else if ( nActPosOfObj < i )
177  {
178  i = nActPosOfObj;
179  }
180  }
181  }
182  } // end of loop on <rPageFrame.GetSortedObjs()>
183 
184  return bSuccess;
185 }
186 
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool DoFormatObj(SwAnchoredObject &_rAnchoredObj, const bool _bCheckForMovedFwd=false) override
intrinsic method to format a certain floating screen object
Base class of the Writer layout elements.
Definition: frame.hxx:295
const SwSortedObjs * GetDrawObjs() const
Definition: frame.hxx:543
virtual SwFrame & GetAnchorFrame() override
SwLayAction * GetLayAction()
SwObjectFormatterLayFrame(SwLayoutFrame &_rAnchorLayFrame, const SwPageFrame &_rPageFrame, SwLayAction *_pLayAction)
sal_uInt16 GetPhyPageNum() const
Definition: pagefrm.hxx:190
bool IsFlyFrame() const
Definition: frame.hxx:1186
wrapper class for the positioning of Writer fly frames and drawing objects
SwFlyFrame * FindFlyFrame()
Definition: frame.hxx:1087
const SwSortedObjs * GetSortedObjs() const
Definition: pagefrm.hxx:118
The usage of LayAction is always the same:
Definition: layact.hxx:56
bool FormatObjsAtFrame_(SwTextFrame *_pMasterTextFrame=nullptr)
invokes the intrinsic format method for all floating screen objects, anchored at anchor frame on the ...
size_t size() const
Definition: sortedobjs.cxx:42
int i
void FormatObj_(SwAnchoredObject &_rAnchoredObj)
performs the intrinsic format of a given floating screen object and its content.
virtual ~SwObjectFormatterLayFrame() override
A page of the document layout.
Definition: pagefrm.hxx:40
virtual bool DoFormatObjs() override
intrinsic method to format all floating screen objects
SwPageFrame * FindPageFrameOfAnchor()
method to determine the page frame, on which the 'anchor' of the given anchored object is...
bool IsAgain() const
Definition: layact.hxx:160
bool IsPageFrame() const
Definition: frame.hxx:1154
static std::unique_ptr< SwObjectFormatterLayFrame > CreateObjFormatter(SwLayoutFrame &_rAnchorLayFrame, const SwPageFrame &_rPageFrame, SwLayAction *_pLayAction)
size_t ListPosOf(const SwAnchoredObject &_rAnchoredObj) const
Position of object <_rAnchoredObj> in sorted list.
Definition: sortedobjs.cxx:275
bool AdditionalFormatObjsOnPage()
method to format all anchored objects, which are registered at the page frame, whose 'anchor' isn't o...
const SwFrame * GetAnchorFrame() const