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