merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / layout / objectformatterlayfrm.cxx
blob5e649490730ff117c82a21ea0bd57d5245f80ba3
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: objectformatterlayfrm.cxx,v $
10 * $Revision: 1.10 $
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 <objectformatterlayfrm.hxx>
34 #include <anchoredobject.hxx>
35 #include <sortedobjs.hxx>
36 #include <layfrm.hxx>
37 #include <pagefrm.hxx>
39 // --> OD 2005-07-13 #124218#
40 #include <layact.hxx>
41 // <--
43 // =============================================================================
44 // implementation of class <SwObjectFormatterLayFrm>
45 // =============================================================================
46 SwObjectFormatterLayFrm::SwObjectFormatterLayFrm( SwLayoutFrm& _rAnchorLayFrm,
47 const SwPageFrm& _rPageFrm,
48 SwLayAction* _pLayAction )
49 : SwObjectFormatter( _rPageFrm, _pLayAction ),
50 mrAnchorLayFrm( _rAnchorLayFrm )
54 SwObjectFormatterLayFrm::~SwObjectFormatterLayFrm()
58 SwObjectFormatterLayFrm* SwObjectFormatterLayFrm::CreateObjFormatter(
59 SwLayoutFrm& _rAnchorLayFrm,
60 const SwPageFrm& _rPageFrm,
61 SwLayAction* _pLayAction )
63 if ( !_rAnchorLayFrm.IsPageFrm() &&
64 !_rAnchorLayFrm.IsFlyFrm() )
66 ASSERT( false,
67 "<SwObjectFormatterLayFrm::CreateObjFormatter(..)> - unexcepted type of anchor frame " );
68 return 0L;
71 SwObjectFormatterLayFrm* pObjFormatter = 0L;
73 // create object formatter, if floating screen objects are registered at
74 // given anchor layout frame.
75 if ( _rAnchorLayFrm.GetDrawObjs() ||
76 ( _rAnchorLayFrm.IsPageFrm() &&
77 static_cast<SwPageFrm&>(_rAnchorLayFrm).GetSortedObjs() ) )
79 pObjFormatter =
80 new SwObjectFormatterLayFrm( _rAnchorLayFrm, _rPageFrm, _pLayAction );
83 return pObjFormatter;
86 SwFrm& SwObjectFormatterLayFrm::GetAnchorFrm()
88 return mrAnchorLayFrm;
91 // --> OD 2005-01-10 #i40147# - add parameter <_bCheckForMovedFwd>.
92 // Not relevant for objects anchored at layout frame.
93 bool SwObjectFormatterLayFrm::DoFormatObj( SwAnchoredObject& _rAnchoredObj,
94 const bool )
95 // <--
97 _FormatObj( _rAnchoredObj );
99 // --> OD 2005-07-13 #124218# - consider that the layout action has to be
100 // restarted due to a deleted page frame.
101 return GetLayAction() ? !GetLayAction()->IsAgain() : true;
102 // <--
105 bool SwObjectFormatterLayFrm::DoFormatObjs()
107 bool bSuccess( true );
109 bSuccess = _FormatObjsAtFrm();
111 if ( bSuccess && GetAnchorFrm().IsPageFrm() )
113 // anchor layout frame is a page frame.
114 // Thus, format also all anchored objects, which are registered at
115 // this page frame, whose 'anchor' isn't on this page frame and whose
116 // anchor frame is valid.
117 bSuccess = _AdditionalFormatObjsOnPage();
120 return bSuccess;
123 /** method to format all anchored objects, which are registered at
124 the page frame, whose 'anchor' isn't on this page frame and whose
125 anchor frame is valid.
127 OD 2004-07-02 #i28701#
129 @author
131 bool SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()
133 if ( !GetAnchorFrm().IsPageFrm() )
135 ASSERT( false,
136 "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - mis-usage of method, call only for anchor frames of type page frame" );
137 return true;
140 // --> OD 2005-07-13 #124218# - consider, if the layout action
141 // has to be restarted due to a delete of a page frame.
142 if ( GetLayAction() && GetLayAction()->IsAgain() )
144 return false;
146 // <--
149 SwPageFrm& rPageFrm = static_cast<SwPageFrm&>(GetAnchorFrm());
151 if ( !rPageFrm.GetSortedObjs() )
153 // nothing to do, if no floating screen object is registered at the anchor frame.
154 return true;
157 bool bSuccess( true );
159 sal_uInt32 i = 0;
160 for ( ; i < rPageFrm.GetSortedObjs()->Count(); ++i )
162 SwAnchoredObject* pAnchoredObj = (*rPageFrm.GetSortedObjs())[i];
164 // --> OD 2005-08-18 #i51941# - do not format object, which are anchored
165 // inside or at fly frame.
166 if ( pAnchoredObj->GetAnchorFrm()->FindFlyFrm() )
168 continue;
170 // <--
171 // --> OD 2004-09-23 #i33751#, #i34060# - method <GetPageFrmOfAnchor()>
172 // is replaced by method <FindPageFrmOfAnchor()>. It's return value
173 // have to be checked.
174 SwPageFrm* pPageFrmOfAnchor = pAnchoredObj->FindPageFrmOfAnchor();
175 // --> OD 2004-10-08 #i26945# - check, if the page frame of the
176 // object's anchor frame isn't the given page frame
177 ASSERT( pPageFrmOfAnchor,
178 "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - missing page frame" )
179 if ( pPageFrmOfAnchor &&
180 // --> OD 2004-10-22 #i35911#
181 pPageFrmOfAnchor->GetPhyPageNum() < rPageFrm.GetPhyPageNum() )
182 // <--
183 // <--
185 // if format of object fails, stop formatting and pass fail to
186 // calling method via the return value.
187 if ( !DoFormatObj( *pAnchoredObj ) )
189 bSuccess = false;
190 break;
193 // considering changes at <GetAnchorFrm().GetDrawObjs()> during
194 // format of the object.
195 if ( !rPageFrm.GetSortedObjs() ||
196 i > rPageFrm.GetSortedObjs()->Count() )
198 break;
200 else
202 sal_uInt32 nActPosOfObj =
203 rPageFrm.GetSortedObjs()->ListPosOf( *pAnchoredObj );
204 if ( nActPosOfObj == rPageFrm.GetSortedObjs()->Count() ||
205 nActPosOfObj > i )
207 --i;
209 else if ( nActPosOfObj < i )
211 i = nActPosOfObj;
215 } // end of loop on <rPageFrm.GetSortedObjs()>
217 return bSuccess;