xref: /AOO41X/main/sw/source/core/layout/objectformatterlayfrm.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #include <objectformatterlayfrm.hxx>
31 #include <anchoredobject.hxx>
32 #include <sortedobjs.hxx>
33 #include <layfrm.hxx>
34 #include <pagefrm.hxx>
35 
36 // --> OD 2005-07-13 #124218#
37 #include <layact.hxx>
38 // <--
39 
40 // =============================================================================
41 // implementation of class <SwObjectFormatterLayFrm>
42 // =============================================================================
43 SwObjectFormatterLayFrm::SwObjectFormatterLayFrm( SwLayoutFrm& _rAnchorLayFrm,
44                                                   const SwPageFrm& _rPageFrm,
45                                                   SwLayAction* _pLayAction )
46     : SwObjectFormatter( _rPageFrm, _pLayAction ),
47       mrAnchorLayFrm( _rAnchorLayFrm )
48 {
49 }
50 
51 SwObjectFormatterLayFrm::~SwObjectFormatterLayFrm()
52 {
53 }
54 
55 SwObjectFormatterLayFrm* SwObjectFormatterLayFrm::CreateObjFormatter(
56                                                 SwLayoutFrm& _rAnchorLayFrm,
57                                                 const SwPageFrm& _rPageFrm,
58                                                 SwLayAction* _pLayAction )
59 {
60     if ( !_rAnchorLayFrm.IsPageFrm() &&
61          !_rAnchorLayFrm.IsFlyFrm() )
62     {
63         ASSERT( false,
64                 "<SwObjectFormatterLayFrm::CreateObjFormatter(..)> - unexcepted type of anchor frame " );
65         return 0L;
66     }
67 
68     SwObjectFormatterLayFrm* pObjFormatter = 0L;
69 
70     // create object formatter, if floating screen objects are registered at
71     // given anchor layout frame.
72     if ( _rAnchorLayFrm.GetDrawObjs() ||
73          ( _rAnchorLayFrm.IsPageFrm() &&
74             static_cast<SwPageFrm&>(_rAnchorLayFrm).GetSortedObjs() ) )
75     {
76         pObjFormatter =
77             new SwObjectFormatterLayFrm( _rAnchorLayFrm, _rPageFrm, _pLayAction );
78     }
79 
80     return pObjFormatter;
81 }
82 
83 SwFrm& SwObjectFormatterLayFrm::GetAnchorFrm()
84 {
85     return mrAnchorLayFrm;
86 }
87 
88 // --> OD 2005-01-10 #i40147# - add parameter <_bCheckForMovedFwd>.
89 // Not relevant for objects anchored at layout frame.
90 bool SwObjectFormatterLayFrm::DoFormatObj( SwAnchoredObject& _rAnchoredObj,
91                                            const bool )
92 // <--
93 {
94     _FormatObj( _rAnchoredObj );
95 
96     // --> OD 2005-07-13 #124218# - consider that the layout action has to be
97     // restarted due to a deleted page frame.
98     return GetLayAction() ? !GetLayAction()->IsAgain() : true;
99     // <--
100 }
101 
102 bool SwObjectFormatterLayFrm::DoFormatObjs()
103 {
104     bool bSuccess( true );
105 
106     bSuccess = _FormatObjsAtFrm();
107 
108     if ( bSuccess && GetAnchorFrm().IsPageFrm() )
109     {
110         // anchor layout frame is a page frame.
111         // Thus, format also all anchored objects, which are registered at
112         // this page frame, whose 'anchor' isn't on this page frame and whose
113         // anchor frame is valid.
114         bSuccess = _AdditionalFormatObjsOnPage();
115     }
116 
117     return bSuccess;
118 }
119 
120 /** method to format all anchored objects, which are registered at
121     the page frame, whose 'anchor' isn't on this page frame and whose
122     anchor frame is valid.
123 
124     OD 2004-07-02 #i28701#
125 
126     @author
127 */
128 bool SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()
129 {
130     if ( !GetAnchorFrm().IsPageFrm() )
131     {
132         ASSERT( false,
133                 "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - mis-usage of method, call only for anchor frames of type page frame" );
134         return true;
135     }
136 
137     // --> OD 2005-07-13 #124218# - consider, if the layout action
138     // has to be restarted due to a delete of a page frame.
139     if ( GetLayAction() && GetLayAction()->IsAgain() )
140     {
141         return false;
142     }
143     // <--
144 
145 
146     SwPageFrm& rPageFrm = static_cast<SwPageFrm&>(GetAnchorFrm());
147 
148     if ( !rPageFrm.GetSortedObjs() )
149     {
150         // nothing to do, if no floating screen object is registered at the anchor frame.
151         return true;
152     }
153 
154     bool bSuccess( true );
155 
156     sal_uInt32 i = 0;
157     for ( ; i < rPageFrm.GetSortedObjs()->Count(); ++i )
158     {
159         SwAnchoredObject* pAnchoredObj = (*rPageFrm.GetSortedObjs())[i];
160 
161         // --> OD 2005-08-18 #i51941# - do not format object, which are anchored
162         // inside or at fly frame.
163         if ( pAnchoredObj->GetAnchorFrm()->FindFlyFrm() )
164         {
165             continue;
166         }
167         // <--
168         // --> OD 2004-09-23 #i33751#, #i34060# - method <GetPageFrmOfAnchor()>
169         // is replaced by method <FindPageFrmOfAnchor()>. It's return value
170         // have to be checked.
171         SwPageFrm* pPageFrmOfAnchor = pAnchoredObj->FindPageFrmOfAnchor();
172         // --> OD 2004-10-08 #i26945# - check, if the page frame of the
173         // object's anchor frame isn't the given page frame
174         ASSERT( pPageFrmOfAnchor,
175                 "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - missing page frame" )
176         if ( pPageFrmOfAnchor &&
177              // --> OD 2004-10-22 #i35911#
178              pPageFrmOfAnchor->GetPhyPageNum() < rPageFrm.GetPhyPageNum() )
179              // <--
180         // <--
181         {
182             // if format of object fails, stop formatting and pass fail to
183             // calling method via the return value.
184             if ( !DoFormatObj( *pAnchoredObj ) )
185             {
186                 bSuccess = false;
187                 break;
188             }
189 
190             // considering changes at <GetAnchorFrm().GetDrawObjs()> during
191             // format of the object.
192             if ( !rPageFrm.GetSortedObjs() ||
193                  i > rPageFrm.GetSortedObjs()->Count() )
194             {
195                 break;
196             }
197             else
198             {
199                 sal_uInt32 nActPosOfObj =
200                     rPageFrm.GetSortedObjs()->ListPosOf( *pAnchoredObj );
201                 if ( nActPosOfObj == rPageFrm.GetSortedObjs()->Count() ||
202                      nActPosOfObj > i )
203                 {
204                     --i;
205                 }
206                 else if ( nActPosOfObj < i )
207                 {
208                     i = nActPosOfObj;
209                 }
210             }
211         }
212     } // end of loop on <rPageFrm.GetSortedObjs()>
213 
214     return bSuccess;
215 }
216