1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #include <objectformatterlayfrm.hxx>
27 #include <anchoredobject.hxx>
28 #include <sortedobjs.hxx>
29 #include <layfrm.hxx>
30 #include <pagefrm.hxx>
31 
32 // --> OD 2005-07-13 #124218#
33 #include <layact.hxx>
34 // <--
35 
36 // =============================================================================
37 // implementation of class <SwObjectFormatterLayFrm>
38 // =============================================================================
SwObjectFormatterLayFrm(SwLayoutFrm & _rAnchorLayFrm,const SwPageFrm & _rPageFrm,SwLayAction * _pLayAction)39 SwObjectFormatterLayFrm::SwObjectFormatterLayFrm( SwLayoutFrm& _rAnchorLayFrm,
40                                                   const SwPageFrm& _rPageFrm,
41                                                   SwLayAction* _pLayAction )
42     : SwObjectFormatter( _rPageFrm, _pLayAction ),
43       mrAnchorLayFrm( _rAnchorLayFrm )
44 {
45 }
46 
~SwObjectFormatterLayFrm()47 SwObjectFormatterLayFrm::~SwObjectFormatterLayFrm()
48 {
49 }
50 
CreateObjFormatter(SwLayoutFrm & _rAnchorLayFrm,const SwPageFrm & _rPageFrm,SwLayAction * _pLayAction)51 SwObjectFormatterLayFrm* SwObjectFormatterLayFrm::CreateObjFormatter(
52                                                 SwLayoutFrm& _rAnchorLayFrm,
53                                                 const SwPageFrm& _rPageFrm,
54                                                 SwLayAction* _pLayAction )
55 {
56     if ( !_rAnchorLayFrm.IsPageFrm() &&
57          !_rAnchorLayFrm.IsFlyFrm() )
58     {
59         ASSERT( false,
60                 "<SwObjectFormatterLayFrm::CreateObjFormatter(..)> - unexcepted type of anchor frame " );
61         return 0L;
62     }
63 
64     SwObjectFormatterLayFrm* pObjFormatter = 0L;
65 
66     // create object formatter, if floating screen objects are registered at
67     // given anchor layout frame.
68     if ( _rAnchorLayFrm.GetDrawObjs() ||
69          ( _rAnchorLayFrm.IsPageFrm() &&
70             static_cast<SwPageFrm&>(_rAnchorLayFrm).GetSortedObjs() ) )
71     {
72         pObjFormatter =
73             new SwObjectFormatterLayFrm( _rAnchorLayFrm, _rPageFrm, _pLayAction );
74     }
75 
76     return pObjFormatter;
77 }
78 
GetAnchorFrm()79 SwFrm& SwObjectFormatterLayFrm::GetAnchorFrm()
80 {
81     return mrAnchorLayFrm;
82 }
83 
84 // --> OD 2005-01-10 #i40147# - add parameter <_bCheckForMovedFwd>.
85 // Not relevant for objects anchored at layout frame.
DoFormatObj(SwAnchoredObject & _rAnchoredObj,const bool)86 bool SwObjectFormatterLayFrm::DoFormatObj( SwAnchoredObject& _rAnchoredObj,
87                                            const bool )
88 // <--
89 {
90     _FormatObj( _rAnchoredObj );
91 
92     // --> OD 2005-07-13 #124218# - consider that the layout action has to be
93     // restarted due to a deleted page frame.
94     return GetLayAction() ? !GetLayAction()->IsAgain() : true;
95     // <--
96 }
97 
DoFormatObjs()98 bool SwObjectFormatterLayFrm::DoFormatObjs()
99 {
100     bool bSuccess( true );
101 
102     bSuccess = _FormatObjsAtFrm();
103 
104     if ( bSuccess && GetAnchorFrm().IsPageFrm() )
105     {
106         // anchor layout frame is a page frame.
107         // Thus, format also all anchored objects, which are registered at
108         // this page frame, whose 'anchor' isn't on this page frame and whose
109         // anchor frame is valid.
110         bSuccess = _AdditionalFormatObjsOnPage();
111     }
112 
113     return bSuccess;
114 }
115 
116 /** method to format all anchored objects, which are registered at
117     the page frame, whose 'anchor' isn't on this page frame and whose
118     anchor frame is valid.
119 
120     OD 2004-07-02 #i28701#
121 
122     @author
123 */
_AdditionalFormatObjsOnPage()124 bool SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()
125 {
126     if ( !GetAnchorFrm().IsPageFrm() )
127     {
128         ASSERT( false,
129                 "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - mis-usage of method, call only for anchor frames of type page frame" );
130         return true;
131     }
132 
133     // --> OD 2005-07-13 #124218# - consider, if the layout action
134     // has to be restarted due to a delete of a page frame.
135     if ( GetLayAction() && GetLayAction()->IsAgain() )
136     {
137         return false;
138     }
139     // <--
140 
141 
142     SwPageFrm& rPageFrm = static_cast<SwPageFrm&>(GetAnchorFrm());
143 
144     if ( !rPageFrm.GetSortedObjs() )
145     {
146         // nothing to do, if no floating screen object is registered at the anchor frame.
147         return true;
148     }
149 
150     bool bSuccess( true );
151 
152     sal_uInt32 i = 0;
153     for ( ; i < rPageFrm.GetSortedObjs()->Count(); ++i )
154     {
155         SwAnchoredObject* pAnchoredObj = (*rPageFrm.GetSortedObjs())[i];
156 
157         // --> OD 2005-08-18 #i51941# - do not format object, which are anchored
158         // inside or at fly frame.
159         if ( pAnchoredObj->GetAnchorFrm()->FindFlyFrm() )
160         {
161             continue;
162         }
163         // <--
164         // --> OD 2004-09-23 #i33751#, #i34060# - method <GetPageFrmOfAnchor()>
165         // is replaced by method <FindPageFrmOfAnchor()>. It's return value
166         // have to be checked.
167         SwPageFrm* pPageFrmOfAnchor = pAnchoredObj->FindPageFrmOfAnchor();
168         // --> OD 2004-10-08 #i26945# - check, if the page frame of the
169         // object's anchor frame isn't the given page frame
170         ASSERT( pPageFrmOfAnchor,
171                 "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - missing page frame" )
172         if ( pPageFrmOfAnchor &&
173              // --> OD 2004-10-22 #i35911#
174              pPageFrmOfAnchor->GetPhyPageNum() < rPageFrm.GetPhyPageNum() )
175              // <--
176         // <--
177         {
178             // if format of object fails, stop formatting and pass fail to
179             // calling method via the return value.
180             if ( !DoFormatObj( *pAnchoredObj ) )
181             {
182                 bSuccess = false;
183                 break;
184             }
185 
186             // considering changes at <GetAnchorFrm().GetDrawObjs()> during
187             // format of the object.
188             if ( !rPageFrm.GetSortedObjs() ||
189                  i > rPageFrm.GetSortedObjs()->Count() )
190             {
191                 break;
192             }
193             else
194             {
195                 sal_uInt32 nActPosOfObj =
196                     rPageFrm.GetSortedObjs()->ListPosOf( *pAnchoredObj );
197                 if ( nActPosOfObj == rPageFrm.GetSortedObjs()->Count() ||
198                      nActPosOfObj > i )
199                 {
200                     --i;
201                 }
202                 else if ( nActPosOfObj < i )
203                 {
204                     i = nActPosOfObj;
205                 }
206             }
207         }
208     } // end of loop on <rPageFrm.GetSortedObjs()>
209 
210     return bSuccess;
211 }
212