Line data Source code
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 :
20 : #include <objectformatterlayfrm.hxx>
21 : #include <anchoredobject.hxx>
22 : #include <sortedobjs.hxx>
23 : #include <layfrm.hxx>
24 : #include <pagefrm.hxx>
25 :
26 : // #124218#
27 : #include <layact.hxx>
28 :
29 : // =============================================================================
30 : // implementation of class <SwObjectFormatterLayFrm>
31 : // =============================================================================
32 68 : SwObjectFormatterLayFrm::SwObjectFormatterLayFrm( SwLayoutFrm& _rAnchorLayFrm,
33 : const SwPageFrm& _rPageFrm,
34 : SwLayAction* _pLayAction )
35 : : SwObjectFormatter( _rPageFrm, _pLayAction ),
36 68 : mrAnchorLayFrm( _rAnchorLayFrm )
37 : {
38 68 : }
39 :
40 136 : SwObjectFormatterLayFrm::~SwObjectFormatterLayFrm()
41 : {
42 136 : }
43 :
44 1194 : SwObjectFormatterLayFrm* SwObjectFormatterLayFrm::CreateObjFormatter(
45 : SwLayoutFrm& _rAnchorLayFrm,
46 : const SwPageFrm& _rPageFrm,
47 : SwLayAction* _pLayAction )
48 : {
49 1934 : if ( !_rAnchorLayFrm.IsPageFrm() &&
50 740 : !_rAnchorLayFrm.IsFlyFrm() )
51 : {
52 : OSL_FAIL( "<SwObjectFormatterLayFrm::CreateObjFormatter(..)> - unexcepted type of anchor frame " );
53 0 : return 0L;
54 : }
55 :
56 1194 : SwObjectFormatterLayFrm* pObjFormatter = 0L;
57 :
58 : // create object formatter, if floating screen objects are registered at
59 : // given anchor layout frame.
60 2834 : if ( _rAnchorLayFrm.GetDrawObjs() ||
61 1190 : ( _rAnchorLayFrm.IsPageFrm() &&
62 450 : static_cast<SwPageFrm&>(_rAnchorLayFrm).GetSortedObjs() ) )
63 : {
64 : pObjFormatter =
65 68 : new SwObjectFormatterLayFrm( _rAnchorLayFrm, _rPageFrm, _pLayAction );
66 : }
67 :
68 1194 : return pObjFormatter;
69 : }
70 :
71 340 : SwFrm& SwObjectFormatterLayFrm::GetAnchorFrm()
72 : {
73 340 : return mrAnchorLayFrm;
74 : }
75 :
76 : // #i40147# - add parameter <_bCheckForMovedFwd>.
77 : // Not relevant for objects anchored at layout frame.
78 16 : bool SwObjectFormatterLayFrm::DoFormatObj( SwAnchoredObject& _rAnchoredObj,
79 : const bool )
80 : {
81 16 : _FormatObj( _rAnchoredObj );
82 :
83 : // #124218# - consider that the layout action has to be
84 : // restarted due to a deleted page frame.
85 16 : return GetLayAction() ? !GetLayAction()->IsAgain() : true;
86 : }
87 :
88 68 : bool SwObjectFormatterLayFrm::DoFormatObjs()
89 : {
90 68 : bool bSuccess( true );
91 :
92 68 : bSuccess = _FormatObjsAtFrm();
93 :
94 68 : if ( bSuccess && GetAnchorFrm().IsPageFrm() )
95 : {
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 68 : bSuccess = _AdditionalFormatObjsOnPage();
101 : }
102 :
103 68 : return bSuccess;
104 : }
105 :
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.
109 :
110 : OD 2004-07-02 #i28701#
111 :
112 : @author
113 : */
114 68 : bool SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()
115 : {
116 68 : if ( !GetAnchorFrm().IsPageFrm() )
117 : {
118 : OSL_FAIL( "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - mis-usage of method, call only for anchor frames of type page frame" );
119 0 : return true;
120 : }
121 :
122 : // #124218# - consider, if the layout action
123 : // has to be restarted due to a delete of a page frame.
124 68 : if ( GetLayAction() && GetLayAction()->IsAgain() )
125 : {
126 0 : return false;
127 : }
128 :
129 :
130 68 : SwPageFrm& rPageFrm = static_cast<SwPageFrm&>(GetAnchorFrm());
131 :
132 68 : if ( !rPageFrm.GetSortedObjs() )
133 : {
134 : // nothing to do, if no floating screen object is registered at the anchor frame.
135 0 : return true;
136 : }
137 :
138 68 : bool bSuccess( true );
139 :
140 68 : sal_uInt32 i = 0;
141 188 : for ( ; i < rPageFrm.GetSortedObjs()->Count(); ++i )
142 : {
143 120 : SwAnchoredObject* pAnchoredObj = (*rPageFrm.GetSortedObjs())[i];
144 :
145 : // #i51941# - do not format object, which are anchored
146 : // inside or at fly frame.
147 120 : if ( pAnchoredObj->GetAnchorFrm()->FindFlyFrm() )
148 : {
149 0 : continue;
150 : }
151 : // #i33751#, #i34060# - method <GetPageFrmOfAnchor()>
152 : // is replaced by method <FindPageFrmOfAnchor()>. It's return value
153 : // have to be checked.
154 120 : 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 240 : if ( pPageFrmOfAnchor &&
160 : // #i35911#
161 120 : pPageFrmOfAnchor->GetPhyPageNum() < rPageFrm.GetPhyPageNum() )
162 : {
163 : // if format of object fails, stop formatting and pass fail to
164 : // calling method via the return value.
165 0 : if ( !DoFormatObj( *pAnchoredObj ) )
166 : {
167 0 : bSuccess = false;
168 0 : break;
169 : }
170 :
171 : // considering changes at <GetAnchorFrm().GetDrawObjs()> during
172 : // format of the object.
173 0 : if ( !rPageFrm.GetSortedObjs() ||
174 0 : i > rPageFrm.GetSortedObjs()->Count() )
175 : {
176 0 : break;
177 : }
178 : else
179 : {
180 : sal_uInt32 nActPosOfObj =
181 0 : rPageFrm.GetSortedObjs()->ListPosOf( *pAnchoredObj );
182 0 : if ( nActPosOfObj == rPageFrm.GetSortedObjs()->Count() ||
183 : nActPosOfObj > i )
184 : {
185 0 : --i;
186 : }
187 0 : else if ( nActPosOfObj < i )
188 : {
189 0 : i = nActPosOfObj;
190 : }
191 : }
192 : }
193 : } // end of loop on <rPageFrm.GetSortedObjs()>
194 :
195 68 : return bSuccess;
196 : }
197 :
198 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|