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 <anchoredobjectposition.hxx>
30 : : #ifndef _ENVIRONMENTOFANCHOREDOBJECT
31 : : #include <environmentofanchoredobject.hxx>
32 : : #endif
33 : : #include <flyfrm.hxx>
34 : : #include <flyfrms.hxx>
35 : : #include <txtfrm.hxx>
36 : : #include <pagefrm.hxx>
37 : : #include <frmtool.hxx>
38 : : #include <svx/svdobj.hxx>
39 : : #include <dflyobj.hxx>
40 : : #include <dcontact.hxx>
41 : : #include <frmfmt.hxx>
42 : : #include <fmtornt.hxx>
43 : : // #i62875#
44 : : #include <fmtfollowtextflow.hxx>
45 : : #include <editeng/lrspitem.hxx>
46 : : #include <editeng/ulspitem.hxx>
47 : : #include <ndtxt.hxx>
48 : : #include <IDocumentSettingAccess.hxx>
49 : :
50 : : using namespace ::com::sun::star;
51 : : using namespace objectpositioning;
52 : :
53 : : // **************************************************************************
54 : : // constructor, destructor, initialization
55 : : // **************************************************************************
56 : 4616 : SwAnchoredObjectPosition::SwAnchoredObjectPosition( SdrObject& _rDrawObj )
57 : : : mrDrawObj( _rDrawObj ),
58 : : mbIsObjFly( false ),
59 : : mpAnchoredObj( 0 ),
60 : : mpAnchorFrm( 0 ),
61 : : mpContact( 0 ),
62 : : // #i62875#
63 : : mbFollowTextFlow( false ),
64 : 4616 : mbDoNotCaptureAnchoredObj( false )
65 : : {
66 : : #if OSL_DEBUG_LEVEL > 0
67 : : // assert, if object isn't of excepted type
68 : : const bool bObjOfExceptedType =
69 : : mrDrawObj.ISA(SwVirtFlyDrawObj) || // object representing fly frame
70 : : mrDrawObj.ISA(SwDrawVirtObj) || // 'virtual' drawing object
71 : : ( !mrDrawObj.ISA(SdrVirtObj) && // 'master' drawing object
72 : : !mrDrawObj.ISA(SwFlyDrawObj) ); // - indirectly checked
73 : : (void) bObjOfExceptedType;
74 : : OSL_ENSURE( bObjOfExceptedType,
75 : : "SwAnchoredObjectPosition(..) - object of unexcepted type!" );
76 : : #endif
77 : :
78 : 4616 : _GetInfoAboutObj();
79 : 4616 : }
80 : :
81 : : /** determine information about object
82 : :
83 : : members <mbIsObjFly>, <mpFrmOfObj>, <mpAnchorFrm>, <mpContact>,
84 : : <mbFollowTextFlow> and <mbDoNotCaptureAnchoredObj> are set
85 : :
86 : : @author OD
87 : : */
88 : 4616 : void SwAnchoredObjectPosition::_GetInfoAboutObj()
89 : : {
90 : : // determine, if object represents a fly frame
91 : : {
92 : 4616 : mbIsObjFly = mrDrawObj.ISA(SwVirtFlyDrawObj);
93 : : }
94 : :
95 : : // determine contact object
96 : : {
97 : 4616 : mpContact = static_cast<SwContact*>(GetUserCall( &mrDrawObj ));
98 : : OSL_ENSURE( mpContact,
99 : : "SwAnchoredObjectPosition::_GetInfoAboutObj() - missing SwContact-object." );
100 : : }
101 : :
102 : : // determine anchored object, the object belongs to
103 : : {
104 : : // #i26791#
105 : 4616 : mpAnchoredObj = mpContact->GetAnchoredObj( &mrDrawObj );
106 : : OSL_ENSURE( mpAnchoredObj,
107 : : "SwAnchoredObjectPosition::_GetInfoAboutObj() - missing anchored object." );
108 : : }
109 : :
110 : : // determine frame, the object is anchored at
111 : : {
112 : : // #i26791#
113 : 4616 : mpAnchorFrm = mpAnchoredObj->AnchorFrm();
114 : : OSL_ENSURE( mpAnchorFrm,
115 : : "SwAnchoredObjectPosition::_GetInfoAboutObj() - missing anchor frame." );
116 : : }
117 : :
118 : : // determine format the object belongs to
119 : : {
120 : : // #i28701#
121 : 4616 : mpFrmFmt = &mpAnchoredObj->GetFrmFmt();
122 : : OSL_ENSURE( mpFrmFmt,
123 : : "<SwAnchoredObjectPosition::_GetInfoAboutObj() - missing frame format." );
124 : : }
125 : :
126 : : // #i62875# - determine attribute value of <Follow-Text-Flow>
127 : : {
128 : 4616 : mbFollowTextFlow = mpFrmFmt->GetFollowTextFlow().GetValue();
129 : : }
130 : :
131 : : // determine, if anchored object has not to be captured on the page.
132 : : // the following conditions must be hold to *not* capture it:
133 : : // - corresponding document compatibility flag is set
134 : : // - it's a drawing object
135 : : // - it doesn't follow the text flow
136 : : {
137 : 6868 : mbDoNotCaptureAnchoredObj = !mbIsObjFly && !mbFollowTextFlow &&
138 [ + - ][ - + ]: 4616 : mpFrmFmt->getIDocumentSettingAccess()->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE);
[ + + ]
139 : : }
140 : 4616 : }
141 : :
142 : 4616 : SwAnchoredObjectPosition::~SwAnchoredObjectPosition()
143 [ - + ]: 4616 : {}
144 : :
145 : 0 : bool SwAnchoredObjectPosition::IsAnchoredToChar() const
146 : : {
147 : 0 : return false;
148 : : }
149 : :
150 : 0 : const SwFrm* SwAnchoredObjectPosition::ToCharOrientFrm() const
151 : : {
152 : 0 : return NULL;
153 : : }
154 : :
155 : 0 : const SwRect* SwAnchoredObjectPosition::ToCharRect() const
156 : : {
157 : 0 : return NULL;
158 : : }
159 : :
160 : : // #i22341#
161 : 0 : SwTwips SwAnchoredObjectPosition::ToCharTopOfLine() const
162 : : {
163 : 0 : return 0L;
164 : : }
165 : :
166 : : /** helper method to determine top of a frame for the vertical
167 : : object positioning
168 : :
169 : : #i11860#
170 : :
171 : : @author OD
172 : : */
173 : 1665 : SwTwips SwAnchoredObjectPosition::_GetTopForObjPos( const SwFrm& _rFrm,
174 : : const SwRectFn& _fnRect,
175 : : const bool _bVert ) const
176 : : {
177 [ + - ]: 1665 : SwTwips nTopOfFrmForObjPos = (_rFrm.Frm().*_fnRect->fnGetTop)();
178 : :
179 [ + + ]: 1665 : if ( _rFrm.IsTxtFrm() )
180 : : {
181 : 1575 : const SwTxtFrm& rTxtFrm = static_cast<const SwTxtFrm&>(_rFrm);
182 [ - + ]: 1575 : if ( _bVert )
183 : : {
184 : : nTopOfFrmForObjPos -=
185 : 0 : rTxtFrm.GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid();
186 : : }
187 : : else
188 : : {
189 : : nTopOfFrmForObjPos +=
190 : 1575 : rTxtFrm.GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid();
191 : : }
192 : : }
193 : :
194 : 1665 : return nTopOfFrmForObjPos;
195 : : }
196 : :
197 : 255 : void SwAnchoredObjectPosition::_GetVertAlignmentValues(
198 : : const SwFrm& _rVertOrientFrm,
199 : : const SwFrm& _rPageAlignLayFrm,
200 : : const sal_Int16 _eRelOrient,
201 : : SwTwips& _orAlignAreaHeight,
202 : : SwTwips& _orAlignAreaOffset ) const
203 : : {
204 : 255 : SwTwips nHeight = 0;
205 : 255 : SwTwips nOffset = 0;
206 [ + - ][ - + ]: 255 : SWRECTFN( (&_rVertOrientFrm) )
[ # # ][ # # ]
[ - + ]
207 : : // #i11860# - top of <_rVertOrientFrm> for object positioning
208 [ + - ]: 255 : const SwTwips nVertOrientTop = _GetTopForObjPos( _rVertOrientFrm, fnRect, bVert );
209 : : // #i11860# - upper space amount of <_rVertOrientFrm> considered
210 : : // for previous frame
211 : : const SwTwips nVertOrientUpperSpaceForPrevFrmAndPageGrid =
212 : 255 : _rVertOrientFrm.IsTxtFrm()
213 : : ? static_cast<const SwTxtFrm&>(_rVertOrientFrm).
214 : 165 : GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid()
215 [ + - ][ + + ]: 255 : : 0;
216 [ + + + - : 255 : switch ( _eRelOrient )
- - - ]
217 : : {
218 : : case text::RelOrientation::FRAME:
219 : : {
220 : : // #i11860# - consider upper space of previous frame
221 [ + - ][ + - ]: 59 : nHeight = (_rVertOrientFrm.Frm().*fnRect->fnGetHeight)() -
222 : 59 : nVertOrientUpperSpaceForPrevFrmAndPageGrid;
223 : 59 : nOffset = 0;
224 : : }
225 : 59 : break;
226 : : case text::RelOrientation::PRINT_AREA:
227 : : {
228 [ + - ][ + - ]: 186 : nHeight = (_rVertOrientFrm.Prt().*fnRect->fnGetHeight)();
229 : : // #i11860# - consider upper space of previous frame
230 [ + - ][ + - ]: 186 : nOffset = (_rVertOrientFrm.*fnRect->fnGetTopMargin)() -
231 : 186 : nVertOrientUpperSpaceForPrevFrmAndPageGrid;
232 : : // if aligned to page in horizontal layout, consider header and
233 : : // footer frame height appropriately.
234 [ + + ][ + - ]: 186 : if( _rVertOrientFrm.IsPageFrm() && !bVert )
[ + + ]
235 : : {
236 : : const SwFrm* pPrtFrm =
237 : 72 : static_cast<const SwPageFrm&>(_rVertOrientFrm).Lower();
238 [ + + ]: 148 : while( pPrtFrm )
239 : : {
240 [ - + ]: 76 : if( pPrtFrm->IsHeaderFrm() )
241 : : {
242 : 0 : nHeight -= pPrtFrm->Frm().Height();
243 : 0 : nOffset += pPrtFrm->Frm().Height();
244 : : }
245 [ - + ]: 76 : else if( pPrtFrm->IsFooterFrm() )
246 : : {
247 : 0 : nHeight -= pPrtFrm->Frm().Height();
248 : : }
249 : 76 : pPrtFrm = pPrtFrm->GetNext();
250 : : }
251 : : }
252 : : }
253 : 186 : break;
254 : : case text::RelOrientation::PAGE_FRAME:
255 : : {
256 [ + - ][ + - ]: 10 : nHeight = (_rPageAlignLayFrm.Frm().*fnRect->fnGetHeight)();
257 : : nOffset = (*fnRect->fnYDiff)(
258 : 10 : (_rPageAlignLayFrm.Frm().*fnRect->fnGetTop)(),
259 [ + - ][ + - ]: 10 : nVertOrientTop );
[ + - ]
260 : : }
261 : 10 : break;
262 : : case text::RelOrientation::PAGE_PRINT_AREA:
263 : : {
264 [ # # ][ # # ]: 0 : nHeight = (_rPageAlignLayFrm.Prt().*fnRect->fnGetHeight)();
265 [ # # ][ # # ]: 0 : nOffset = (_rPageAlignLayFrm.*fnRect->fnGetTopMargin)() +
266 : : (*fnRect->fnYDiff)(
267 : 0 : (_rPageAlignLayFrm.Frm().*fnRect->fnGetTop)(),
268 [ # # ][ # # ]: 0 : nVertOrientTop );
[ # # ]
269 : : // if aligned to page in horizontal layout, consider header and
270 : : // footer frame height appropriately.
271 [ # # ][ # # ]: 0 : if( _rPageAlignLayFrm.IsPageFrm() && !bVert )
[ # # ]
272 : : {
273 : : const SwFrm* pPrtFrm =
274 : 0 : static_cast<const SwPageFrm&>(_rPageAlignLayFrm).Lower();
275 [ # # ]: 0 : while( pPrtFrm )
276 : : {
277 [ # # ]: 0 : if( pPrtFrm->IsHeaderFrm() )
278 : : {
279 : 0 : nHeight -= pPrtFrm->Frm().Height();
280 : 0 : nOffset += pPrtFrm->Frm().Height();
281 : : }
282 [ # # ]: 0 : else if( pPrtFrm->IsFooterFrm() )
283 : : {
284 : 0 : nHeight -= pPrtFrm->Frm().Height();
285 : : }
286 : 0 : pPrtFrm = pPrtFrm->GetNext();
287 : : }
288 : : }
289 : : }
290 : 0 : break;
291 : : // #i22341# - vertical alignment at top of line
292 : : case text::RelOrientation::TEXT_LINE:
293 : : {
294 [ # # ][ # # ]: 0 : if ( IsAnchoredToChar() )
295 : : {
296 : 0 : nHeight = 0;
297 [ # # ][ # # ]: 0 : nOffset = (*fnRect->fnYDiff)( ToCharTopOfLine(), nVertOrientTop );
298 : : }
299 : : else
300 : : {
301 : : OSL_FAIL( "<SwAnchoredObjectPosition::_GetVertAlignmentValues(..)> - invalid relative alignment" );
302 : : }
303 : : }
304 : 0 : break;
305 : : case text::RelOrientation::CHAR:
306 : : {
307 [ # # ][ # # ]: 0 : if ( IsAnchoredToChar() )
308 : : {
309 [ # # ][ # # ]: 0 : nHeight = (ToCharRect()->*fnRect->fnGetHeight)();
[ # # ]
310 [ # # ]: 0 : nOffset = (*fnRect->fnYDiff)( (ToCharRect()->*fnRect->fnGetTop)(),
311 [ # # ][ # # ]: 0 : nVertOrientTop );
[ # # ]
312 : : }
313 : : else
314 : : {
315 : : OSL_FAIL( "<SwAnchoredObjectPosition::_GetVertAlignmentValues(..)> - invalid relative alignment" );
316 : : }
317 : : }
318 : 0 : break;
319 : : // no break here, because text::RelOrientation::CHAR is invalid, if !mbAnchorToChar
320 : : default:
321 : : {
322 : : OSL_FAIL( "<SwAnchoredObjectPosition::_GetVertAlignmentValues(..)> - invalid relative alignment" );
323 : : }
324 : : }
325 : :
326 : 255 : _orAlignAreaHeight = nHeight;
327 : 255 : _orAlignAreaOffset = nOffset;
328 : 255 : }
329 : :
330 : : // #i26791# - add output parameter <_roVertOffsetToFrmAnchorPos>
331 : 90 : SwTwips SwAnchoredObjectPosition::_GetVertRelPos(
332 : : const SwFrm& _rVertOrientFrm,
333 : : const SwFrm& _rPageAlignLayFrm,
334 : : const sal_Int16 _eVertOrient,
335 : : const sal_Int16 _eRelOrient,
336 : : const SwTwips _nVertPos,
337 : : const SvxLRSpaceItem& _rLRSpacing,
338 : : const SvxULSpaceItem& _rULSpacing,
339 : : SwTwips& _roVertOffsetToFrmAnchorPos ) const
340 : : {
341 : 90 : SwTwips nRelPosY = 0;
342 [ + - ][ - + ]: 90 : SWRECTFN( (&_rVertOrientFrm) );
[ # # ][ # # ]
[ - + ]
343 : :
344 : : SwTwips nAlignAreaHeight;
345 : : SwTwips nAlignAreaOffset;
346 : : _GetVertAlignmentValues( _rVertOrientFrm, _rPageAlignLayFrm,
347 [ + - ]: 90 : _eRelOrient, nAlignAreaHeight, nAlignAreaOffset );
348 : :
349 : 90 : nRelPosY = nAlignAreaOffset;
350 [ + - ]: 90 : const SwRect aObjBoundRect( GetAnchoredObj().GetObjRect() );
351 [ + - ][ + - ]: 90 : const SwTwips nObjHeight = (aObjBoundRect.*fnRect->fnGetHeight)();
352 : :
353 [ + + + - : 90 : switch ( _eVertOrient )
- ]
354 : : {
355 : : case text::VertOrientation::NONE:
356 : : {
357 : : // 'manual' vertical position
358 : 16 : nRelPosY += _nVertPos;
359 : : }
360 : 16 : break;
361 : : case text::VertOrientation::TOP:
362 : : {
363 : : //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
364 : : nRelPosY += bVert
365 : : ? ( bVertL2R
366 : : ? _rLRSpacing.GetLeft()
367 : : : _rLRSpacing.GetRight() )
368 [ - + ][ # # ]: 72 : : _rULSpacing.GetUpper();
369 : : }
370 : 72 : break;
371 : : case text::VertOrientation::CENTER:
372 : : {
373 : 2 : nRelPosY += (nAlignAreaHeight / 2) - (nObjHeight / 2);
374 : : }
375 : 2 : break;
376 : : case text::VertOrientation::BOTTOM:
377 : : {
378 : : //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
379 : : nRelPosY += nAlignAreaHeight -
380 : : ( nObjHeight + ( bVert
381 : : ? ( bVertL2R
382 : : ? _rLRSpacing.GetRight()
383 : : : _rLRSpacing.GetLeft() )
384 [ # # ][ # # ]: 0 : : _rULSpacing.GetLower() ) );
385 : : }
386 : 0 : break;
387 : : default:
388 : : {
389 : : OSL_FAIL( "<SwAnchoredObjectPosition::_GetVertRelPos(..) - invalid vertical positioning" );
390 : : }
391 : : }
392 : :
393 : : // #i26791#
394 : 90 : _roVertOffsetToFrmAnchorPos = nAlignAreaOffset;
395 : :
396 : 90 : return nRelPosY;
397 : : }
398 : :
399 : : /** adjust calculated vertical in order to keep object inside
400 : : 'page' alignment layout frame.
401 : :
402 : : #i28701# - parameter <_nTopOfAnch> and <_bVert> added
403 : : #i31805# - add parameter <_bCheckBottom>
404 : : #i26945# - add parameter <_bFollowTextFlow>
405 : : #i62875# - method now private and renamed.
406 : : OD 2009-09-01 #mongolianlayout# - add parameter <bVertL2R>
407 : :
408 : : @author OD
409 : : */
410 : 315 : SwTwips SwAnchoredObjectPosition::_ImplAdjustVertRelPos( const SwTwips nTopOfAnch,
411 : : const bool bVert,
412 : : const bool bVertL2R,
413 : : const SwFrm& rPageAlignLayFrm,
414 : : const SwTwips nProposedRelPosY,
415 : : const bool bFollowTextFlow,
416 : : const bool bCheckBottom ) const
417 : : {
418 : 315 : SwTwips nAdjustedRelPosY = nProposedRelPosY;
419 : :
420 [ + - ]: 315 : const Size aObjSize( GetAnchoredObj().GetObjRect().SSize() );
421 : :
422 : : // determine the area of 'page' alignment frame, to which the vertical
423 : : // position is restricted.
424 : : // #i28701# - Extend restricted area for the vertical
425 : : // position to area of the page frame, if wrapping style influence is
426 : : // considered on object positioning. Needed to avoid layout loops in the
427 : : // object positioning algorithm considering the wrapping style influence
428 : : // caused by objects, which follow the text flow and thus are restricted
429 : : // to its environment (e.g. page header/footer).
430 : 315 : SwRect aPgAlignArea;
431 : : {
432 : : // #i26945# - no extension of restricted area, if
433 : : // object's attribute follow text flow is set and its inside a table
434 [ + - ][ + + ]: 315 : if ( GetFrmFmt().getIDocumentSettingAccess()->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) &&
[ - + ][ # # ]
[ + + ][ + - ]
435 : 24 : ( !bFollowTextFlow ||
436 [ # # ][ # # ]: 0 : !GetAnchoredObj().GetAnchorFrm()->IsInTab() ) )
437 : : {
438 [ + - ]: 24 : aPgAlignArea = rPageAlignLayFrm.FindPageFrm()->Frm();
439 : : }
440 : : else
441 : : {
442 : 291 : aPgAlignArea = rPageAlignLayFrm.Frm();
443 : : }
444 : : }
445 : :
446 [ - + ]: 315 : if ( bVert )
447 : : {
448 : : // #i31805# - consider value of <_bCheckBottom>
449 [ # # ]: 0 : if ( !bVertL2R )
450 : : {
451 [ # # # # ]: 0 : if ( bCheckBottom &&
[ # # ]
452 : 0 : nTopOfAnch - nAdjustedRelPosY - aObjSize.Width() <
453 : 0 : aPgAlignArea.Left() )
454 : : {
455 : 0 : nAdjustedRelPosY = aPgAlignArea.Left() +
456 : : nTopOfAnch -
457 : 0 : aObjSize.Width();
458 : : }
459 : : // #i32964# - correction
460 [ # # ]: 0 : if ( nTopOfAnch - nAdjustedRelPosY > aPgAlignArea.Right() )
461 : : {
462 : 0 : nAdjustedRelPosY = nTopOfAnch - aPgAlignArea.Right();
463 : : }
464 : : }
465 : : else
466 : : {
467 [ # # # # ]: 0 : if ( bCheckBottom &&
[ # # ]
468 : 0 : nTopOfAnch + nAdjustedRelPosY + aObjSize.Width() >
469 : 0 : aPgAlignArea.Right() )
470 : : {
471 : 0 : nAdjustedRelPosY = aPgAlignArea.Right() -
472 : : nTopOfAnch -
473 : 0 : aObjSize.Width();
474 : : }
475 [ # # ]: 0 : if ( nTopOfAnch + nAdjustedRelPosY < aPgAlignArea.Left() )
476 : : {
477 : 0 : nAdjustedRelPosY = aPgAlignArea.Left() - nTopOfAnch;
478 : : }
479 : : }
480 : : }
481 : : else
482 : : {
483 : : // #i31805# - consider value of <bCheckBottom>
484 [ + - + + ]: 630 : if ( bCheckBottom &&
[ + + ]
485 : 315 : nTopOfAnch + nAdjustedRelPosY + aObjSize.Height() >
486 : 315 : aPgAlignArea.Top() + aPgAlignArea.Height() )
487 : : {
488 : 12 : nAdjustedRelPosY = aPgAlignArea.Top() + aPgAlignArea.Height() -
489 : : nTopOfAnch -
490 : 12 : aObjSize.Height();
491 : : }
492 [ - + ]: 315 : if ( nTopOfAnch + nAdjustedRelPosY < aPgAlignArea.Top() )
493 : : {
494 : 0 : nAdjustedRelPosY = aPgAlignArea.Top() - nTopOfAnch;
495 : : }
496 : : }
497 : :
498 : 315 : return nAdjustedRelPosY;
499 : : }
500 : :
501 : : /** adjust calculated horizontal in order to keep object inside
502 : : 'page' alignment layout frame.
503 : :
504 : : #i62875# - method now private and renamed.
505 : :
506 : : @author OD
507 : : */
508 : 315 : SwTwips SwAnchoredObjectPosition::_ImplAdjustHoriRelPos(
509 : : const SwFrm& _rPageAlignLayFrm,
510 : : const SwTwips _nProposedRelPosX ) const
511 : : {
512 : 315 : SwTwips nAdjustedRelPosX = _nProposedRelPosX;
513 : :
514 : 315 : const SwFrm& rAnchorFrm = GetAnchorFrm();
515 [ + - ]: 315 : const bool bVert = rAnchorFrm.IsVertical();
516 : :
517 [ + - ]: 315 : const Size aObjSize( GetAnchoredObj().GetObjRect().SSize() );
518 : :
519 [ - + ]: 315 : if( bVert )
520 : : {
521 [ # # ]: 0 : if ( rAnchorFrm.Frm().Top() + nAdjustedRelPosX + aObjSize.Height() >
522 : 0 : _rPageAlignLayFrm.Frm().Bottom() )
523 : : {
524 : 0 : nAdjustedRelPosX = _rPageAlignLayFrm.Frm().Bottom() -
525 : 0 : rAnchorFrm.Frm().Top() -
526 : 0 : aObjSize.Height();
527 : : }
528 [ # # ]: 0 : if ( rAnchorFrm.Frm().Top() + nAdjustedRelPosX <
529 : 0 : _rPageAlignLayFrm.Frm().Top() )
530 : : {
531 : 0 : nAdjustedRelPosX = _rPageAlignLayFrm.Frm().Top() -
532 : 0 : rAnchorFrm.Frm().Top();
533 : : }
534 : : }
535 : : else
536 : : {
537 [ + + ]: 630 : if ( rAnchorFrm.Frm().Left() + nAdjustedRelPosX + aObjSize.Width() >
538 : 315 : _rPageAlignLayFrm.Frm().Right() )
539 : : {
540 : 12 : nAdjustedRelPosX = _rPageAlignLayFrm.Frm().Right() -
541 : 12 : rAnchorFrm.Frm().Left() -
542 : 12 : aObjSize.Width();
543 : : }
544 [ - + ]: 630 : if ( rAnchorFrm.Frm().Left() + nAdjustedRelPosX <
545 : 315 : _rPageAlignLayFrm.Frm().Left() )
546 : : {
547 : 0 : nAdjustedRelPosX = _rPageAlignLayFrm.Frm().Left() -
548 : 0 : rAnchorFrm.Frm().Left();
549 : : }
550 : : }
551 : :
552 : 315 : return nAdjustedRelPosX;
553 : : }
554 : :
555 : : /** determine alignment value for horizontal position of object
556 : :
557 : : @author OD
558 : : */
559 : 405 : void SwAnchoredObjectPosition::_GetHoriAlignmentValues( const SwFrm& _rHoriOrientFrm,
560 : : const SwFrm& _rPageAlignLayFrm,
561 : : const sal_Int16 _eRelOrient,
562 : : const bool _bObjWrapThrough,
563 : : SwTwips& _orAlignAreaWidth,
564 : : SwTwips& _orAlignAreaOffset,
565 : : bool& _obAlignedRelToPage ) const
566 : : {
567 : 405 : SwTwips nWidth = 0;
568 : 405 : SwTwips nOffset = 0;
569 [ - + ][ # # ]: 405 : SWRECTFN( (&_rHoriOrientFrm) )
[ # # ][ - + ]
570 [ + - - - : 405 : switch ( _eRelOrient )
- + + +
+ ]
571 : : {
572 : : case text::RelOrientation::PRINT_AREA:
573 : : {
574 [ + - ]: 202 : nWidth = (_rHoriOrientFrm.Prt().*fnRect->fnGetWidth)();
575 [ + - ]: 202 : nOffset = (_rHoriOrientFrm.*fnRect->fnGetLeftMargin)();
576 [ + + ]: 202 : if ( _rHoriOrientFrm.IsTxtFrm() )
577 : : {
578 : : // consider movement of text frame left
579 : 130 : nOffset += static_cast<const SwTxtFrm&>(_rHoriOrientFrm).GetBaseOfstForFly( !_bObjWrapThrough );
580 : : }
581 [ + - ][ - + ]: 72 : else if ( _rHoriOrientFrm.IsPageFrm() && bVert )
[ - + ]
582 : : {
583 : : // for to-page anchored objects, consider header/footer frame
584 : : // in vertical layout
585 : : const SwFrm* pPrtFrm =
586 : 0 : static_cast<const SwPageFrm&>(_rHoriOrientFrm).Lower();
587 [ # # ]: 0 : while( pPrtFrm )
588 : : {
589 [ # # ]: 0 : if( pPrtFrm->IsHeaderFrm() )
590 : : {
591 : 0 : nWidth -= pPrtFrm->Frm().Height();
592 : 0 : nOffset += pPrtFrm->Frm().Height();
593 : : }
594 [ # # ]: 0 : else if( pPrtFrm->IsFooterFrm() )
595 : : {
596 : 0 : nWidth -= pPrtFrm->Frm().Height();
597 : : }
598 : 0 : pPrtFrm = pPrtFrm->GetNext();
599 : : }
600 : : }
601 : 202 : break;
602 : : }
603 : : case text::RelOrientation::PAGE_LEFT:
604 : : {
605 : : // align at left border of page frame/fly frame/cell frame
606 [ # # ]: 0 : nWidth = (_rPageAlignLayFrm.*fnRect->fnGetLeftMargin)();
607 : : nOffset = (*fnRect->fnXDiff)(
608 : 0 : (_rPageAlignLayFrm.Frm().*fnRect->fnGetLeft)(),
609 [ # # ][ # # ]: 0 : (_rHoriOrientFrm.Frm().*fnRect->fnGetLeft)() );
610 : 0 : _obAlignedRelToPage = true;
611 : : }
612 : 0 : break;
613 : : case text::RelOrientation::PAGE_RIGHT:
614 : : {
615 : : // align at right border of page frame/fly frame/cell frame
616 [ # # ]: 0 : nWidth = (_rPageAlignLayFrm.*fnRect->fnGetRightMargin)();
617 : : nOffset = (*fnRect->fnXDiff)(
618 : 0 : (_rPageAlignLayFrm.*fnRect->fnGetPrtRight)(),
619 [ # # ][ # # ]: 0 : (_rHoriOrientFrm.Frm().*fnRect->fnGetLeft)() );
620 : 0 : _obAlignedRelToPage = true;
621 : : }
622 : 0 : break;
623 : : case text::RelOrientation::FRAME_LEFT:
624 : : {
625 : : // align at left border of anchor frame
626 [ # # ]: 0 : nWidth = (_rHoriOrientFrm.*fnRect->fnGetLeftMargin)();
627 : 0 : nOffset = 0;
628 : : }
629 : 0 : break;
630 : : case text::RelOrientation::FRAME_RIGHT:
631 : : {
632 : : // align at right border of anchor frame
633 : : // Unify and simplify
634 [ # # ]: 0 : nWidth = (_rHoriOrientFrm.*fnRect->fnGetRightMargin)();
635 [ # # ]: 0 : nOffset = (_rHoriOrientFrm.Prt().*fnRect->fnGetRight)();
636 : : }
637 : 0 : break;
638 : : case text::RelOrientation::CHAR:
639 : : {
640 : : // alignment relative to character - assure, that corresponding
641 : : // character rectangle is set.
642 [ + - ]: 33 : if ( IsAnchoredToChar() )
643 : : {
644 : 33 : nWidth = 0;
645 : : nOffset = (*fnRect->fnXDiff)(
646 : 33 : (ToCharRect()->*fnRect->fnGetLeft)(),
647 [ + - ][ + - ]: 66 : (ToCharOrientFrm()->Frm().*fnRect->fnGetLeft)() );
648 : 33 : break;
649 : : }
650 : : // no break!
651 : : }
652 : : case text::RelOrientation::PAGE_PRINT_AREA:
653 : : {
654 [ + - ]: 3 : nWidth = (_rPageAlignLayFrm.Prt().*fnRect->fnGetWidth)();
655 : : nOffset = (*fnRect->fnXDiff)(
656 : 6 : (_rPageAlignLayFrm.*fnRect->fnGetPrtLeft)(),
657 [ + - ][ + - ]: 3 : (_rHoriOrientFrm.Frm().*fnRect->fnGetLeft)() );
658 [ # # ][ - + ]: 3 : if ( _rHoriOrientFrm.IsPageFrm() && bVert )
[ - + ]
659 : : {
660 : : // for to-page anchored objects, consider header/footer frame
661 : : // in vertical layout
662 : : const SwFrm* pPrtFrm =
663 : 0 : static_cast<const SwPageFrm&>(_rHoriOrientFrm).Lower();
664 [ # # ]: 0 : while( pPrtFrm )
665 : : {
666 [ # # ]: 0 : if( pPrtFrm->IsHeaderFrm() )
667 : : {
668 : 0 : nWidth -= pPrtFrm->Frm().Height();
669 : 0 : nOffset += pPrtFrm->Frm().Height();
670 : : }
671 [ # # ]: 0 : else if( pPrtFrm->IsFooterFrm() )
672 : : {
673 : 0 : nWidth -= pPrtFrm->Frm().Height();
674 : : }
675 : 0 : pPrtFrm = pPrtFrm->GetNext();
676 : : }
677 : : }
678 : 3 : _obAlignedRelToPage = true;
679 : 3 : break;
680 : : }
681 : : case text::RelOrientation::PAGE_FRAME:
682 : : {
683 [ + - ]: 23 : nWidth = (_rPageAlignLayFrm.Frm().*fnRect->fnGetWidth)();
684 : : nOffset = (*fnRect->fnXDiff)(
685 : 23 : (_rPageAlignLayFrm.Frm().*fnRect->fnGetLeft)(),
686 [ + - ][ + - ]: 46 : (_rHoriOrientFrm.Frm().*fnRect->fnGetLeft)() );
687 : 23 : _obAlignedRelToPage = true;
688 : 23 : break;
689 : : }
690 : : default:
691 : : {
692 [ + - ]: 144 : nWidth = (_rHoriOrientFrm.Frm().*fnRect->fnGetWidth)();
693 : 144 : nOffset = _rHoriOrientFrm.IsTxtFrm() ?
694 : 128 : static_cast<const SwTxtFrm&>(_rHoriOrientFrm).GetBaseOfstForFly( !_bObjWrapThrough ) :
695 [ + + ]: 144 : 0;
696 : 144 : break;
697 : : }
698 : : }
699 : :
700 : 405 : _orAlignAreaWidth = nWidth;
701 : 405 : _orAlignAreaOffset = nOffset;
702 : 405 : }
703 : :
704 : : /** toggle given horizontal orientation and relative alignment
705 : :
706 : : @author OD
707 : : */
708 : 405 : void SwAnchoredObjectPosition::_ToggleHoriOrientAndAlign(
709 : : const bool _bToggleLeftRight,
710 : : sal_Int16& _ioeHoriOrient,
711 : : sal_Int16& _iopeRelOrient
712 : : ) const
713 : : {
714 [ - + ]: 405 : if( _bToggleLeftRight )
715 : : {
716 : : // toggle orientation
717 [ # # # ]: 0 : switch ( _ioeHoriOrient )
718 : : {
719 : : case text::HoriOrientation::RIGHT :
720 : : {
721 : 0 : _ioeHoriOrient = text::HoriOrientation::LEFT;
722 : : }
723 : 0 : break;
724 : : case text::HoriOrientation::LEFT :
725 : : {
726 : 0 : _ioeHoriOrient = text::HoriOrientation::RIGHT;
727 : : }
728 : 0 : break;
729 : : default:
730 : 0 : break;
731 : : }
732 : :
733 : : // toggle relative alignment
734 [ # # # # : 0 : switch ( _iopeRelOrient )
# ]
735 : : {
736 : : case text::RelOrientation::PAGE_RIGHT :
737 : : {
738 : 0 : _iopeRelOrient = text::RelOrientation::PAGE_LEFT;
739 : : }
740 : 0 : break;
741 : : case text::RelOrientation::PAGE_LEFT :
742 : : {
743 : 0 : _iopeRelOrient = text::RelOrientation::PAGE_RIGHT;
744 : : }
745 : 0 : break;
746 : : case text::RelOrientation::FRAME_RIGHT :
747 : : {
748 : 0 : _iopeRelOrient = text::RelOrientation::FRAME_LEFT;
749 : : }
750 : 0 : break;
751 : : case text::RelOrientation::FRAME_LEFT :
752 : : {
753 : 0 : _iopeRelOrient = text::RelOrientation::FRAME_RIGHT;
754 : : }
755 : 0 : break;
756 : : default:
757 : 0 : break;
758 : : }
759 : : }
760 : 405 : }
761 : :
762 : : /** calculate relative horizontal position
763 : :
764 : : @author OD
765 : : */
766 : 315 : SwTwips SwAnchoredObjectPosition::_CalcRelPosX(
767 : : const SwFrm& _rHoriOrientFrm,
768 : : const SwEnvironmentOfAnchoredObject& _rEnvOfObj,
769 : : const SwFmtHoriOrient& _rHoriOrient,
770 : : const SvxLRSpaceItem& _rLRSpacing,
771 : : const SvxULSpaceItem& _rULSpacing,
772 : : const bool _bObjWrapThrough,
773 : : const SwTwips _nRelPosY,
774 : : SwTwips& _roHoriOffsetToFrmAnchorPos
775 : : ) const
776 : : {
777 : : // determine 'page' alignment layout frame
778 : : const SwFrm& rPageAlignLayFrm =
779 [ + - ]: 315 : _rEnvOfObj.GetHoriEnvironmentLayoutFrm( _rHoriOrientFrm );
780 : :
781 [ + - ]: 315 : const bool bEvenPage = !rPageAlignLayFrm.OnRightPage();
782 [ - + ][ # # ]: 315 : const bool bToggle = _rHoriOrient.IsPosToggle() && bEvenPage;
783 : :
784 : : // determine orientation and relative alignment
785 : 315 : sal_Int16 eHoriOrient = _rHoriOrient.GetHoriOrient();
786 : 315 : sal_Int16 eRelOrient = _rHoriOrient.GetRelationOrient();
787 : : // toggle orientation and relative alignment
788 : 315 : _ToggleHoriOrientAndAlign( bToggle, eHoriOrient, eRelOrient );
789 : :
790 : : // determine alignment parameter
791 : : // <nWidth>: 'width' of alignment area
792 : : // <nOffset>: offset of alignment area, relative to 'left' of anchor frame
793 : 315 : SwTwips nWidth = 0;
794 : 315 : SwTwips nOffset = 0;
795 : 315 : bool bAlignedRelToPage = false;
796 : : _GetHoriAlignmentValues( _rHoriOrientFrm, rPageAlignLayFrm,
797 : : eRelOrient, _bObjWrapThrough,
798 [ + - ]: 315 : nWidth, nOffset, bAlignedRelToPage );
799 : :
800 : 315 : const SwFrm& rAnchorFrm = GetAnchorFrm();
801 [ - + ][ # # ]: 315 : SWRECTFN( (&_rHoriOrientFrm) )
[ # # ][ - + ]
[ + - ]
802 [ + - ][ + - ]: 315 : SwTwips nObjWidth = (GetAnchoredObj().GetObjRect().*fnRect->fnGetWidth)();
[ + - ]
803 : 315 : SwTwips nRelPosX = nOffset;
804 [ + + ]: 315 : if ( _rHoriOrient.GetHoriOrient() == text::HoriOrientation::NONE )
805 : : {
806 : : // 'manual' horizonal position
807 [ + - ]: 147 : const bool bR2L = rAnchorFrm.IsRightToLeft();
808 [ + - ][ + + ]: 147 : if( IsAnchoredToChar() && text::RelOrientation::CHAR == eRelOrient )
[ + + ][ + + ]
809 : : {
810 [ - + ]: 33 : if( bR2L )
811 : 0 : nRelPosX -= _rHoriOrient.GetPos();
812 : : else
813 : 33 : nRelPosX += _rHoriOrient.GetPos();
814 : : }
815 [ + - ][ + - ]: 114 : else if ( bToggle || ( !_rHoriOrient.IsPosToggle() && bR2L ) )
[ - + ][ - + ]
816 : : {
817 : : // Correction: consider <nOffset> also for
818 : : // toggling from left to right.
819 : 0 : nRelPosX += nWidth - nObjWidth - _rHoriOrient.GetPos();
820 : : }
821 : : else
822 : : {
823 : 114 : nRelPosX += _rHoriOrient.GetPos();
824 : : }
825 : : }
826 [ + - ]: 168 : else if ( text::HoriOrientation::CENTER == eHoriOrient )
827 : 168 : nRelPosX += (nWidth / 2) - (nObjWidth / 2);
828 [ # # ]: 0 : else if ( text::HoriOrientation::RIGHT == eHoriOrient )
829 : : nRelPosX += nWidth -
830 : : ( nObjWidth +
831 [ # # ]: 0 : ( bVert ? _rULSpacing.GetLower() : _rLRSpacing.GetRight() ) );
832 : : else
833 [ # # ]: 0 : nRelPosX += bVert ? _rULSpacing.GetUpper() : _rLRSpacing.GetLeft();
834 : :
835 : : // adjust relative position by distance between anchor frame and
836 : : // the frame, the object is oriented at.
837 [ - + ]: 315 : if ( &rAnchorFrm != &_rHoriOrientFrm )
838 : : {
839 [ # # ][ # # ]: 0 : SwTwips nLeftOrient = (_rHoriOrientFrm.Frm().*fnRect->fnGetLeft)();
840 [ # # ][ # # ]: 0 : SwTwips nLeftAnchor = (rAnchorFrm.Frm().*fnRect->fnGetLeft)();
841 [ # # ]: 0 : nRelPosX += (*fnRect->fnXDiff)( nLeftOrient, nLeftAnchor );
842 : : }
843 : :
844 : : // adjust calculated relative horizontal position, in order to
845 : : // keep object inside 'page' alignment layout frame
846 : : const SwFrm& rEnvironmentLayFrm =
847 [ + - ]: 315 : _rEnvOfObj.GetHoriEnvironmentLayoutFrm( _rHoriOrientFrm );
848 [ + - ]: 315 : nRelPosX = _AdjustHoriRelPos( rEnvironmentLayFrm, nRelPosX );
849 : :
850 : : // if object is a Writer fly frame and it's anchored to a content and
851 : : // it is horizontal positioned left or right, but not relative to character,
852 : : // it has to be drawn aside another object, which have the same horizontal
853 : : // position and lay below it.
854 [ + - ][ + - ]: 741 : if ( GetAnchoredObj().ISA(SwFlyFrm) &&
[ + + ][ + + ]
[ + - ][ + - ]
[ - + ][ # # ]
[ - + ]
855 [ + - ][ + - ]: 426 : ( GetContact().ObjAnchoredAtPara() || GetContact().ObjAnchoredAtChar() ) &&
856 : : ( eHoriOrient == text::HoriOrientation::LEFT || eHoriOrient == text::HoriOrientation::RIGHT ) &&
857 : : eRelOrient != text::RelOrientation::CHAR )
858 : : {
859 : : nRelPosX = _AdjustHoriRelPosForDrawAside( _rHoriOrientFrm,
860 : : nRelPosX, _nRelPosY,
861 : : eHoriOrient, eRelOrient,
862 : : _rLRSpacing, _rULSpacing,
863 [ # # ]: 0 : bEvenPage );
864 : : }
865 : :
866 : : // #i26791#
867 : 315 : _roHoriOffsetToFrmAnchorPos = nOffset;
868 : :
869 : 315 : return nRelPosX;
870 : : }
871 : :
872 : : // **************************************************************************
873 : : // method incl. helper methods for adjusting proposed horizontal position,
874 : : // if object has to draw aside another object.
875 : : // **************************************************************************
876 : : /** adjust calculated horizontal position in order to draw object
877 : : aside other objects with same positioning
878 : :
879 : : @author OD
880 : : */
881 : 0 : SwTwips SwAnchoredObjectPosition::_AdjustHoriRelPosForDrawAside(
882 : : const SwFrm& _rHoriOrientFrm,
883 : : const SwTwips _nProposedRelPosX,
884 : : const SwTwips _nRelPosY,
885 : : const sal_Int16 _eHoriOrient,
886 : : const sal_Int16 _eRelOrient,
887 : : const SvxLRSpaceItem& _rLRSpacing,
888 : : const SvxULSpaceItem& _rULSpacing,
889 : : const bool _bEvenPage
890 : : ) const
891 : : {
892 : : // #i26791#
893 [ # # ][ # # ]: 0 : if ( !GetAnchorFrm().ISA(SwTxtFrm) ||
[ # # ][ # # ]
[ # # ]
894 [ # # ][ # # ]: 0 : !GetAnchoredObj().ISA(SwFlyAtCntFrm) )
895 : : {
896 : : OSL_FAIL( "<SwAnchoredObjectPosition::_AdjustHoriRelPosForDrawAside(..) - usage for wrong anchor type" );
897 : 0 : return _nProposedRelPosX;
898 : : }
899 : :
900 : 0 : const SwTxtFrm& rAnchorTxtFrm = static_cast<const SwTxtFrm&>(GetAnchorFrm());
901 : : // #i26791#
902 : : const SwFlyAtCntFrm& rFlyAtCntFrm =
903 [ # # ]: 0 : static_cast<const SwFlyAtCntFrm&>(GetAnchoredObj());
904 [ # # ]: 0 : const SwRect aObjBoundRect( GetAnchoredObj().GetObjRect() );
905 [ # # ][ # # ]: 0 : SWRECTFN( (&_rHoriOrientFrm) )
[ # # ][ # # ]
[ # # ]
906 : :
907 : 0 : SwTwips nAdjustedRelPosX = _nProposedRelPosX;
908 : :
909 : : // determine proposed object bound rectangle
910 [ # # ][ # # ]: 0 : Point aTmpPos = (rAnchorTxtFrm.Frm().*fnRect->fnGetPos)();
911 [ # # ]: 0 : if( bVert )
912 : : {
913 : 0 : aTmpPos.X() -= _nRelPosY + aObjBoundRect.Width();
914 : 0 : aTmpPos.Y() += nAdjustedRelPosX;
915 : : }
916 : : else
917 : : {
918 : 0 : aTmpPos.X() += nAdjustedRelPosX;
919 : 0 : aTmpPos.Y() += _nRelPosY;
920 : : }
921 : 0 : SwRect aTmpObjRect( aTmpPos, aObjBoundRect.SSize() );
922 : :
923 [ # # ]: 0 : const sal_uInt32 nObjOrdNum = GetObject().GetOrdNum();
924 [ # # ]: 0 : const SwPageFrm* pObjPage = rFlyAtCntFrm.FindPageFrm();
925 [ # # ]: 0 : const SwFrm* pObjContext = ::FindKontext( &rAnchorTxtFrm, FRM_COLUMN );
926 : 0 : sal_uLong nObjIndex = rAnchorTxtFrm.GetTxtNode()->GetIndex();
927 [ # # ]: 0 : SwOrderIter aIter( pObjPage, sal_True );
928 [ # # ]: 0 : const SwFlyFrm* pFly = ((SwVirtFlyDrawObj*)aIter.Bottom())->GetFlyFrm();
929 [ # # ][ # # ]: 0 : while ( pFly && nObjOrdNum > pFly->GetVirtDrawObj()->GetOrdNumDirect() )
[ # # ][ # # ]
[ # # ]
930 : : {
931 [ # # ][ # # ]: 0 : if ( _DrawAsideFly( pFly, aTmpObjRect, pObjContext, nObjIndex,
932 : 0 : _bEvenPage, _eHoriOrient, _eRelOrient ) )
933 : : {
934 [ # # ]: 0 : if( bVert )
935 : : {
936 [ # # ][ # # ]: 0 : const SvxULSpaceItem& rOtherUL = pFly->GetFmt()->GetULSpace();
937 : 0 : const SwTwips nOtherTop = pFly->Frm().Top() - rOtherUL.GetUpper();
938 : 0 : const SwTwips nOtherBot = pFly->Frm().Bottom() + rOtherUL.GetLower();
939 [ # # ]: 0 : if ( nOtherTop <= aTmpObjRect.Bottom() + _rULSpacing.GetLower() &&
[ # # # # ]
940 : 0 : nOtherBot >= aTmpObjRect.Top() - _rULSpacing.GetUpper() )
941 : : {
942 [ # # ]: 0 : if ( _eHoriOrient == text::HoriOrientation::LEFT )
943 : : {
944 : 0 : SwTwips nTmp = nOtherBot + 1 + _rULSpacing.GetUpper() -
945 : 0 : rAnchorTxtFrm.Frm().Top();
946 [ # # ]: 0 : if ( nTmp > nAdjustedRelPosX &&
[ # # # # ]
947 : 0 : rAnchorTxtFrm.Frm().Top() + nTmp +
948 : 0 : aObjBoundRect.Height() + _rULSpacing.GetLower()
949 : 0 : <= pObjPage->Frm().Height() + pObjPage->Frm().Top() )
950 : : {
951 : 0 : nAdjustedRelPosX = nTmp;
952 : : }
953 : : }
954 [ # # ]: 0 : else if ( _eHoriOrient == text::HoriOrientation::RIGHT )
955 : : {
956 : 0 : SwTwips nTmp = nOtherTop - 1 - _rULSpacing.GetLower() -
957 : 0 : aObjBoundRect.Height() -
958 : 0 : rAnchorTxtFrm.Frm().Top();
959 [ # # ]: 0 : if ( nTmp < nAdjustedRelPosX &&
[ # # # # ]
960 : 0 : rAnchorTxtFrm.Frm().Top() + nTmp - _rULSpacing.GetUpper()
961 : 0 : >= pObjPage->Frm().Top() )
962 : : {
963 : 0 : nAdjustedRelPosX = nTmp;
964 : : }
965 : : }
966 : 0 : aTmpObjRect.Pos().Y() = rAnchorTxtFrm.Frm().Top() +
967 : 0 : nAdjustedRelPosX;
968 : : }
969 : : }
970 : : else
971 : : {
972 [ # # ][ # # ]: 0 : const SvxLRSpaceItem& rOtherLR = pFly->GetFmt()->GetLRSpace();
973 : 0 : const SwTwips nOtherLeft = pFly->Frm().Left() - rOtherLR.GetLeft();
974 : 0 : const SwTwips nOtherRight = pFly->Frm().Right() + rOtherLR.GetRight();
975 [ # # ]: 0 : if( nOtherLeft <= aTmpObjRect.Right() + _rLRSpacing.GetRight() &&
[ # # # # ]
976 : 0 : nOtherRight >= aTmpObjRect.Left() - _rLRSpacing.GetLeft() )
977 : : {
978 [ # # ]: 0 : if ( _eHoriOrient == text::HoriOrientation::LEFT )
979 : : {
980 : 0 : SwTwips nTmp = nOtherRight + 1 + _rLRSpacing.GetLeft() -
981 : 0 : rAnchorTxtFrm.Frm().Left();
982 [ # # ]: 0 : if ( nTmp > nAdjustedRelPosX &&
[ # # # # ]
983 : 0 : rAnchorTxtFrm.Frm().Left() + nTmp +
984 : 0 : aObjBoundRect.Width() + _rLRSpacing.GetRight()
985 : 0 : <= pObjPage->Frm().Width() + pObjPage->Frm().Left() )
986 : : {
987 : 0 : nAdjustedRelPosX = nTmp;
988 : : }
989 : : }
990 [ # # ]: 0 : else if ( _eHoriOrient == text::HoriOrientation::RIGHT )
991 : : {
992 : 0 : SwTwips nTmp = nOtherLeft - 1 - _rLRSpacing.GetRight() -
993 : 0 : aObjBoundRect.Width() -
994 : 0 : rAnchorTxtFrm.Frm().Left();
995 [ # # ]: 0 : if ( nTmp < nAdjustedRelPosX &&
[ # # # # ]
996 : 0 : rAnchorTxtFrm.Frm().Left() + nTmp - _rLRSpacing.GetLeft()
997 : 0 : >= pObjPage->Frm().Left() )
998 : : {
999 : 0 : nAdjustedRelPosX = nTmp;
1000 : : }
1001 : : }
1002 : 0 : aTmpObjRect.Pos().X() = rAnchorTxtFrm.Frm().Left() +
1003 : 0 : nAdjustedRelPosX;
1004 : : }
1005 : : } // end of <if (bVert)>
1006 : : } // end of <if _DrawAsideFly(..)>
1007 : :
1008 [ # # ]: 0 : pFly = ((SwVirtFlyDrawObj*)aIter.Next())->GetFlyFrm();
1009 : : } // end of <loop on fly frames
1010 : :
1011 : 0 : return nAdjustedRelPosX;
1012 : : }
1013 : :
1014 : : /** detemine, if object has to draw aside given fly frame
1015 : :
1016 : : method used by <_AdjustHoriRelPosForDrawAside(..)>
1017 : :
1018 : : @author OD
1019 : : */
1020 : 0 : bool SwAnchoredObjectPosition::_DrawAsideFly( const SwFlyFrm* _pFly,
1021 : : const SwRect& _rObjRect,
1022 : : const SwFrm* _pObjContext,
1023 : : const sal_uLong _nObjIndex,
1024 : : const bool _bEvenPage,
1025 : : const sal_Int16 _eHoriOrient,
1026 : : const sal_Int16 _eRelOrient
1027 : : ) const
1028 : : {
1029 : 0 : bool bRetVal = false;
1030 : :
1031 [ # # ][ # # ]: 0 : SWRECTFN( (&GetAnchorFrm()) )
[ # # ][ # # ]
1032 : :
1033 [ # # # # : 0 : if ( _pFly->IsFlyAtCntFrm() &&
# # # # ]
[ # # ]
1034 [ # # ][ # # ]: 0 : (_pFly->Frm().*fnRect->fnBottomDist)( (_rObjRect.*fnRect->fnGetTop)() ) < 0 &&
1035 [ # # ][ # # ]: 0 : (_rObjRect.*fnRect->fnBottomDist)( (_pFly->Frm().*fnRect->fnGetTop)() ) < 0 &&
1036 : 0 : ::FindKontext( _pFly->GetAnchorFrm(), FRM_COLUMN ) == _pObjContext )
1037 : : {
1038 : : sal_uLong nOtherIndex =
1039 : 0 : static_cast<const SwTxtFrm*>(_pFly->GetAnchorFrm())->GetTxtNode()->GetIndex();
1040 [ # # ]: 0 : if( _nObjIndex >= nOtherIndex )
1041 : : {
1042 [ # # ][ # # ]: 0 : const SwFmtHoriOrient& rHori = _pFly->GetFmt()->GetHoriOrient();
1043 : 0 : sal_Int16 eOtherRelOrient = rHori.GetRelationOrient();
1044 [ # # ]: 0 : if( text::RelOrientation::CHAR != eOtherRelOrient )
1045 : : {
1046 : 0 : sal_Int16 eOtherHoriOrient = rHori.GetHoriOrient();
1047 : 0 : _ToggleHoriOrientAndAlign( _bEvenPage && rHori.IsPosToggle(),
1048 : : eOtherHoriOrient,
1049 [ # # # # ]: 0 : eOtherRelOrient );
1050 [ # # ]: 0 : if ( eOtherHoriOrient == _eHoriOrient &&
[ # # # # ]
1051 : 0 : _Minor( _eRelOrient, eOtherRelOrient, text::HoriOrientation::LEFT == _eHoriOrient ) )
1052 : : {
1053 : 0 : bRetVal = true;
1054 : : }
1055 : : }
1056 : : }
1057 : : }
1058 : :
1059 : 0 : return bRetVal;
1060 : : }
1061 : :
1062 : : /** determine, if object has to draw aside another object
1063 : :
1064 : : the different alignments of the objects determines, if one has
1065 : : to draw aside another one. Thus, the given alignment are checked
1066 : : against each other, which one has to be drawn aside the other one.
1067 : : depending on parameter _bLeft check is done for left or right
1068 : : positioning.
1069 : : method used by <_DrawAsideFly(..)>
1070 : :
1071 : : @author OD
1072 : : */
1073 : 0 : bool SwAnchoredObjectPosition::_Minor( sal_Int16 _eRelOrient1,
1074 : : sal_Int16 _eRelOrient2,
1075 : : bool _bLeft ) const
1076 : : {
1077 : : bool bRetVal;
1078 : :
1079 : : // draw aside order for left horizontal position
1080 : : //! one array entry for each value in text::RelOrientation
1081 : : static sal_uInt16 const aLeft[ 10 ] =
1082 : : { 5, 6, 0, 1, 8, 4, 7, 2, 3, 9 };
1083 : : // draw aside order for right horizontal position
1084 : : //! one array entry for each value in text::RelOrientation
1085 : : static sal_uInt16 const aRight[ 10 ] =
1086 : : { 5, 6, 0, 8, 1, 7, 4, 2, 3, 9 };
1087 : :
1088 : : // decide depending on given order, which frame has to draw aside another frame
1089 [ # # ]: 0 : if( _bLeft )
1090 : 0 : bRetVal = aLeft[ _eRelOrient1 ] >= aLeft[ _eRelOrient2 ];
1091 : : else
1092 : 0 : bRetVal = aRight[ _eRelOrient1 ] >= aRight[ _eRelOrient2 ];
1093 : :
1094 : 0 : return bRetVal;
1095 : : }
1096 : :
1097 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|