update credits
[LibreOffice.git] / sw / source / core / layout / objectformatterlayfrm.cxx
blob91552e89dcee1def3e3c3afd121e0795ce26e40c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <objectformatterlayfrm.hxx>
21 #include <anchoredobject.hxx>
22 #include <sortedobjs.hxx>
23 #include <layfrm.hxx>
24 #include <pagefrm.hxx>
26 // #124218#
27 #include <layact.hxx>
29 // =============================================================================
30 // implementation of class <SwObjectFormatterLayFrm>
31 // =============================================================================
32 SwObjectFormatterLayFrm::SwObjectFormatterLayFrm( SwLayoutFrm& _rAnchorLayFrm,
33 const SwPageFrm& _rPageFrm,
34 SwLayAction* _pLayAction )
35 : SwObjectFormatter( _rPageFrm, _pLayAction ),
36 mrAnchorLayFrm( _rAnchorLayFrm )
40 SwObjectFormatterLayFrm::~SwObjectFormatterLayFrm()
44 SwObjectFormatterLayFrm* SwObjectFormatterLayFrm::CreateObjFormatter(
45 SwLayoutFrm& _rAnchorLayFrm,
46 const SwPageFrm& _rPageFrm,
47 SwLayAction* _pLayAction )
49 if ( !_rAnchorLayFrm.IsPageFrm() &&
50 !_rAnchorLayFrm.IsFlyFrm() )
52 OSL_FAIL( "<SwObjectFormatterLayFrm::CreateObjFormatter(..)> - unexcepted type of anchor frame " );
53 return 0L;
56 SwObjectFormatterLayFrm* pObjFormatter = 0L;
58 // create object formatter, if floating screen objects are registered at
59 // given anchor layout frame.
60 if ( _rAnchorLayFrm.GetDrawObjs() ||
61 ( _rAnchorLayFrm.IsPageFrm() &&
62 static_cast<SwPageFrm&>(_rAnchorLayFrm).GetSortedObjs() ) )
64 pObjFormatter =
65 new SwObjectFormatterLayFrm( _rAnchorLayFrm, _rPageFrm, _pLayAction );
68 return pObjFormatter;
71 SwFrm& SwObjectFormatterLayFrm::GetAnchorFrm()
73 return mrAnchorLayFrm;
76 // #i40147# - add parameter <_bCheckForMovedFwd>.
77 // Not relevant for objects anchored at layout frame.
78 bool SwObjectFormatterLayFrm::DoFormatObj( SwAnchoredObject& _rAnchoredObj,
79 const bool )
81 _FormatObj( _rAnchoredObj );
83 // #124218# - consider that the layout action has to be
84 // restarted due to a deleted page frame.
85 return GetLayAction() ? !GetLayAction()->IsAgain() : true;
88 bool SwObjectFormatterLayFrm::DoFormatObjs()
90 bool bSuccess( true );
92 bSuccess = _FormatObjsAtFrm();
94 if ( bSuccess && GetAnchorFrm().IsPageFrm() )
96 // anchor layout frame is a page frame.
97 // Thus, format also all anchored objects, which are registered at
98 // this page frame, whose 'anchor' isn't on this page frame and whose
99 // anchor frame is valid.
100 bSuccess = _AdditionalFormatObjsOnPage();
103 return bSuccess;
106 /** method to format all anchored objects, which are registered at
107 the page frame, whose 'anchor' isn't on this page frame and whose
108 anchor frame is valid.
110 OD 2004-07-02 #i28701#
112 @author
114 bool SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()
116 if ( !GetAnchorFrm().IsPageFrm() )
118 OSL_FAIL( "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - mis-usage of method, call only for anchor frames of type page frame" );
119 return true;
122 // #124218# - consider, if the layout action
123 // has to be restarted due to a delete of a page frame.
124 if ( GetLayAction() && GetLayAction()->IsAgain() )
126 return false;
130 SwPageFrm& rPageFrm = static_cast<SwPageFrm&>(GetAnchorFrm());
132 if ( !rPageFrm.GetSortedObjs() )
134 // nothing to do, if no floating screen object is registered at the anchor frame.
135 return true;
138 bool bSuccess( true );
140 sal_uInt32 i = 0;
141 for ( ; i < rPageFrm.GetSortedObjs()->Count(); ++i )
143 SwAnchoredObject* pAnchoredObj = (*rPageFrm.GetSortedObjs())[i];
145 // #i51941# - do not format object, which are anchored
146 // inside or at fly frame.
147 if ( pAnchoredObj->GetAnchorFrm()->FindFlyFrm() )
149 continue;
151 // #i33751#, #i34060# - method <GetPageFrmOfAnchor()>
152 // is replaced by method <FindPageFrmOfAnchor()>. It's return value
153 // have to be checked.
154 SwPageFrm* pPageFrmOfAnchor = pAnchoredObj->FindPageFrmOfAnchor();
155 // #i26945# - check, if the page frame of the
156 // object's anchor frame isn't the given page frame
157 OSL_ENSURE( pPageFrmOfAnchor,
158 "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - missing page frame" );
159 if ( pPageFrmOfAnchor &&
160 // #i35911#
161 pPageFrmOfAnchor->GetPhyPageNum() < rPageFrm.GetPhyPageNum() )
163 // if format of object fails, stop formatting and pass fail to
164 // calling method via the return value.
165 if ( !DoFormatObj( *pAnchoredObj ) )
167 bSuccess = false;
168 break;
171 // considering changes at <GetAnchorFrm().GetDrawObjs()> during
172 // format of the object.
173 if ( !rPageFrm.GetSortedObjs() ||
174 i > rPageFrm.GetSortedObjs()->Count() )
176 break;
178 else
180 sal_uInt32 nActPosOfObj =
181 rPageFrm.GetSortedObjs()->ListPosOf( *pAnchoredObj );
182 if ( nActPosOfObj == rPageFrm.GetSortedObjs()->Count() ||
183 nActPosOfObj > i )
185 --i;
187 else if ( nActPosOfObj < i )
189 i = nActPosOfObj;
193 } // end of loop on <rPageFrm.GetSortedObjs()>
195 return bSuccess;
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */