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 <txtfrm.hxx>
21 : #include <fmtornt.hxx>
22 : // --> #i28701#
23 : #include <doc.hxx>
24 : #include <fmtsrnd.hxx>
25 : #include <dcontact.hxx>
26 : #include <editeng/ulspitem.hxx>
27 : #include <editeng/lrspitem.hxx>
28 : #include <sortedobjs.hxx>
29 : #include <pagefrm.hxx>
30 : // --> #i35911#
31 : #include <layouter.hxx>
32 :
33 : using namespace ::com::sun::star;
34 :
35 : // --> #i28701# -
36 : // implementation of helper class <SwObjPositioningInProgress>
37 :
38 0 : SwObjPositioningInProgress::SwObjPositioningInProgress( SdrObject& _rSdrObj ) :
39 : mpAnchoredObj( 0L ),
40 : // --> #i52904#
41 0 : mbOldObjPositioningInProgress( false )
42 : {
43 0 : mpAnchoredObj = ::GetUserCall( &_rSdrObj )->GetAnchoredObj( &_rSdrObj );
44 : // --> #i52904#
45 0 : mbOldObjPositioningInProgress = mpAnchoredObj->IsPositioningInProgress();
46 0 : mpAnchoredObj->SetPositioningInProgress( true );
47 0 : }
48 0 : SwObjPositioningInProgress::SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj ) :
49 : mpAnchoredObj( &_rAnchoredObj ),
50 : // --> #i52904#
51 0 : mbOldObjPositioningInProgress( false )
52 : {
53 : // --> #i52904#
54 0 : mbOldObjPositioningInProgress = mpAnchoredObj->IsPositioningInProgress();
55 0 : mpAnchoredObj->SetPositioningInProgress( true );
56 0 : }
57 :
58 0 : SwObjPositioningInProgress::~SwObjPositioningInProgress()
59 : {
60 0 : if ( mpAnchoredObj )
61 : {
62 : // --> #i52904#
63 0 : mpAnchoredObj->SetPositioningInProgress( mbOldObjPositioningInProgress );
64 : }
65 0 : }
66 :
67 : // SwAnchoredObject
68 :
69 0 : TYPEINIT0(SwAnchoredObject);
70 :
71 0 : SwAnchoredObject::SwAnchoredObject() :
72 : mpDrawObj( 0L ),
73 : mpAnchorFrm( 0L ),
74 : // --> #i28701#
75 : mpPageFrm( 0L ),
76 : maRelPos(),
77 : maLastCharRect(),
78 : mnLastTopOfLine( 0L ),
79 : mpVertPosOrientFrm( 0L ),
80 : // --> #i28701#
81 : mbPositioningInProgress( false ),
82 : mbConsiderForTextWrap( false ),
83 : mbPositionLocked( false ),
84 : // --> #i40147#
85 : mbKeepPositionLockedForSection( false ),
86 : mbRestartLayoutProcess( false ),
87 : // --> #i35911#
88 : mbClearedEnvironment( false ),
89 : // --> #i3317#
90 : mbTmpConsiderWrapInfluence( false ),
91 : // --> #i68520#
92 : maObjRectWithSpaces(),
93 : mbObjRectWithSpacesValid( false ),
94 0 : maLastObjRect()
95 : {
96 0 : }
97 :
98 0 : void SwAnchoredObject::ClearVertPosOrientFrm()
99 : {
100 0 : if (mpVertPosOrientFrm)
101 : {
102 0 : const_cast<SwLayoutFrm*>(mpVertPosOrientFrm)->ClearVertPosOrientFrmFor(this);
103 0 : mpVertPosOrientFrm = NULL;
104 : }
105 0 : }
106 :
107 0 : SwAnchoredObject::~SwAnchoredObject()
108 : {
109 0 : ClearVertPosOrientFrm();
110 0 : }
111 :
112 0 : void SwAnchoredObject::SetDrawObj( SdrObject& _rDrawObj )
113 : {
114 0 : mpDrawObj = &_rDrawObj;
115 0 : }
116 :
117 0 : const SdrObject* SwAnchoredObject::GetDrawObj() const
118 : {
119 0 : return mpDrawObj;
120 : }
121 :
122 0 : SdrObject* SwAnchoredObject::DrawObj()
123 : {
124 0 : return mpDrawObj;
125 : }
126 :
127 0 : const SwFrm* SwAnchoredObject::GetAnchorFrm() const
128 : {
129 0 : return mpAnchorFrm;
130 : }
131 :
132 0 : SwFrm* SwAnchoredObject::AnchorFrm()
133 : {
134 0 : return mpAnchorFrm;
135 : }
136 :
137 0 : void SwAnchoredObject::ChgAnchorFrm( SwFrm* _pNewAnchorFrm )
138 : {
139 0 : mpAnchorFrm = _pNewAnchorFrm;
140 :
141 0 : if ( mpAnchorFrm )
142 : {
143 0 : ObjectAttachedToAnchorFrame();
144 : }
145 0 : }
146 :
147 : /** determine anchor frame containing the anchor position
148 :
149 : #i26945#
150 : the anchor frame, which is determined, is <mpAnchorFrm>
151 : for an at-page, at-frame or at-paragraph anchored object
152 : and the anchor character frame for an at-character and as-character
153 : anchored object.
154 : */
155 0 : SwFrm* SwAnchoredObject::GetAnchorFrmContainingAnchPos()
156 : {
157 0 : SwFrm* pAnchorFrmContainingAnchPos = FindAnchorCharFrm();
158 0 : if ( !pAnchorFrmContainingAnchPos )
159 : {
160 0 : pAnchorFrmContainingAnchPos = AnchorFrm();
161 : }
162 :
163 0 : return pAnchorFrmContainingAnchPos;
164 : }
165 :
166 0 : SwPageFrm* SwAnchoredObject::GetPageFrm()
167 : {
168 0 : return mpPageFrm;
169 : }
170 :
171 0 : const SwPageFrm* SwAnchoredObject::GetPageFrm() const
172 : {
173 0 : return mpPageFrm;
174 : }
175 :
176 0 : void SwAnchoredObject::SetPageFrm( SwPageFrm* _pNewPageFrm )
177 : {
178 0 : if ( mpPageFrm != _pNewPageFrm )
179 : {
180 : // clear member, which denotes the layout frame at which the vertical
181 : // position is oriented at, if it doesn't fit to the new page frame.
182 0 : if ( GetVertPosOrientFrm() &&
183 0 : ( !_pNewPageFrm ||
184 0 : _pNewPageFrm != GetVertPosOrientFrm()->FindPageFrm() ) )
185 : {
186 0 : ClearVertPosOrientFrm();
187 : }
188 :
189 : // assign new page frame
190 0 : mpPageFrm = _pNewPageFrm;
191 : }
192 0 : }
193 :
194 0 : const SwRect& SwAnchoredObject::GetLastCharRect() const
195 : {
196 0 : return maLastCharRect;
197 : }
198 :
199 0 : SwTwips SwAnchoredObject::GetRelCharX( const SwFrm* pFrm ) const
200 : {
201 0 : return maLastCharRect.Left() - pFrm->Frm().Left();
202 : }
203 :
204 0 : SwTwips SwAnchoredObject::GetRelCharY( const SwFrm* pFrm ) const
205 : {
206 0 : return maLastCharRect.Bottom() - pFrm->Frm().Top();
207 : }
208 :
209 0 : void SwAnchoredObject::AddLastCharY( long nDiff )
210 : {
211 0 : maLastCharRect.Pos().Y() += nDiff;
212 0 : }
213 :
214 0 : void SwAnchoredObject::ResetLastCharRectHeight()
215 : {
216 0 : maLastCharRect.Height( 0 );
217 0 : }
218 :
219 0 : void SwAnchoredObject::SetVertPosOrientFrm( const SwLayoutFrm& _rVertPosOrientFrm )
220 : {
221 0 : ClearVertPosOrientFrm();
222 :
223 0 : mpVertPosOrientFrm = &_rVertPosOrientFrm;
224 0 : const_cast<SwLayoutFrm*>(mpVertPosOrientFrm)->SetVertPosOrientFrmFor(this);
225 :
226 : // #i28701# - take over functionality of deleted method
227 : // <SwFlyAtCntFrm::AssertPage()>: assure for at-paragraph and at-character
228 : // an anchored object, that it is registered at the correct page frame
229 0 : RegisterAtCorrectPage();
230 0 : }
231 :
232 0 : SwTwips SwAnchoredObject::GetLastTopOfLine() const
233 : {
234 0 : return mnLastTopOfLine;
235 : }
236 :
237 : // #i28701# - follow-up of #i22341#
238 0 : void SwAnchoredObject::AddLastTopOfLineY( SwTwips _nDiff )
239 : {
240 0 : mnLastTopOfLine += _nDiff;
241 0 : }
242 :
243 : /** check anchor character rectangle and top of line
244 :
245 : #i26791
246 : For to-character anchored Writer fly frames the members <maLastCharRect>
247 : and <maLastTopOfLine> are updated. These are checked for change and
248 : depending on the applied positioning, it's decided, if the Writer fly
249 : frame has to be invalidated.
250 :
251 : add parameter <_bCheckForParaPorInf>, default value <true>
252 : */
253 0 : void SwAnchoredObject::CheckCharRectAndTopOfLine(
254 : const bool _bCheckForParaPorInf )
255 : {
256 0 : if ( GetAnchorFrm() &&
257 0 : GetAnchorFrm()->IsTxtFrm() )
258 : {
259 0 : const SwFmtAnchor& rAnch = GetFrmFmt().GetAnchor();
260 0 : if ( (rAnch.GetAnchorId() == FLY_AT_CHAR) &&
261 0 : rAnch.GetCntntAnchor() )
262 : {
263 : // --> if requested, assure that anchor frame,
264 : // which contains the anchor character, has a paragraph portion information.
265 : // The paragraph portion information is needed to determine the
266 : // anchor character rectangle respectively the top of the line.
267 : // Thus, a format of this frame is avoided to determine the
268 : // paragraph portion information.
269 : // --> #i26945# - use new method <FindAnchorCharFrm()>
270 0 : const SwTxtFrm& aAnchorCharFrm = *(FindAnchorCharFrm());
271 0 : if ( !_bCheckForParaPorInf || aAnchorCharFrm.HasPara() )
272 : {
273 0 : _CheckCharRect( rAnch, aAnchorCharFrm );
274 0 : _CheckTopOfLine( rAnch, aAnchorCharFrm );
275 : }
276 : }
277 : }
278 0 : }
279 :
280 : /** check anchor character rectangle
281 :
282 : #i22341#
283 : helper method for method <CheckCharRectAndTopOfLine()>
284 : For to-character anchored Writer fly frames the member <maLastCharRect>
285 : is updated. This is checked for change and depending on the applied
286 : positioning, it's decided, if the Writer fly frame has to be invalidated.
287 :
288 : improvement - add second parameter <_rAnchorCharFrm>
289 : */
290 0 : void SwAnchoredObject::_CheckCharRect( const SwFmtAnchor& _rAnch,
291 : const SwTxtFrm& _rAnchorCharFrm )
292 : {
293 : // determine rectangle of anchor character. If not exist, abort operation
294 0 : SwRect aCharRect;
295 0 : if ( !_rAnchorCharFrm.GetAutoPos( aCharRect, *_rAnch.GetCntntAnchor() ) )
296 : {
297 0 : return;
298 : }
299 : // check, if anchor character rectangle has changed
300 0 : if ( aCharRect != maLastCharRect )
301 : {
302 : // check positioning and alignment for invalidation of position
303 : {
304 0 : SWRECTFN( (&_rAnchorCharFrm) );
305 : // determine positioning and alignment
306 0 : SwFmtVertOrient aVert( GetFrmFmt().GetVertOrient() );
307 0 : SwFmtHoriOrient aHori( GetFrmFmt().GetHoriOrient() );
308 : // check for anchor character rectangle changes for certain
309 : // positionings and alignments
310 : // add condition to invalidate position,
311 : // if vertical aligned at frame/page area and vertical position
312 : // of anchor character has changed.
313 0 : const sal_Int16 eVertRelOrient = aVert.GetRelationOrient();
314 0 : if ( ( aHori.GetRelationOrient() == text::RelOrientation::CHAR &&
315 0 : (aCharRect.*fnRect->fnGetLeft)() !=
316 0 : (maLastCharRect.*fnRect->fnGetLeft)() ) ||
317 0 : ( eVertRelOrient == text::RelOrientation::CHAR &&
318 0 : ( (aCharRect.*fnRect->fnGetTop)() !=
319 0 : (maLastCharRect.*fnRect->fnGetTop)() ||
320 0 : (aCharRect.*fnRect->fnGetHeight)() !=
321 0 : (maLastCharRect.*fnRect->fnGetHeight)() ) ) ||
322 0 : ( ( ( eVertRelOrient == text::RelOrientation::FRAME ) ||
323 0 : ( eVertRelOrient == text::RelOrientation::PRINT_AREA ) ||
324 0 : ( eVertRelOrient == text::RelOrientation::PAGE_FRAME ) ||
325 0 : ( eVertRelOrient == text::RelOrientation::PAGE_PRINT_AREA ) ) &&
326 0 : ( (aCharRect.*fnRect->fnGetTop)() !=
327 0 : (maLastCharRect.*fnRect->fnGetTop)() ) ) )
328 : {
329 : // #i26945#, #i35911# - unlock position of
330 : // anchored object, if it isn't registered at the page,
331 : // where its anchor character frame is on.
332 0 : if ( GetPageFrm() != _rAnchorCharFrm.FindPageFrm() )
333 : {
334 0 : UnlockPosition();
335 : }
336 0 : InvalidateObjPos();
337 0 : }
338 : }
339 : // keep new anchor character rectangle
340 0 : maLastCharRect = aCharRect;
341 : }
342 : }
343 :
344 : /** check top of line
345 :
346 : #i22341#
347 : helper method for method <CheckCharRectAndTopOfLine()>
348 : For to-character anchored Writer fly frames the member <mnLastTopOfLine>
349 : is updated. This is checked for change and depending on the applied
350 : positioning, it's decided, if the Writer fly frame has to be invalidated.
351 :
352 : improvement - add second parameter <_rAnchorCharFrm>
353 : */
354 0 : void SwAnchoredObject::_CheckTopOfLine( const SwFmtAnchor& _rAnch,
355 : const SwTxtFrm& _rAnchorCharFrm )
356 : {
357 0 : SwTwips nTopOfLine = 0L;
358 0 : if ( _rAnchorCharFrm.GetTopOfLine( nTopOfLine, *_rAnch.GetCntntAnchor() ) )
359 : {
360 0 : if ( nTopOfLine != mnLastTopOfLine )
361 : {
362 : // check alignment for invalidation of position
363 0 : if ( GetFrmFmt().GetVertOrient().GetRelationOrient() == text::RelOrientation::TEXT_LINE )
364 : {
365 : // #i26945#, #i35911# - unlock position of
366 : // anchored object, if it isn't registered at the page,
367 : // where its anchor character frame is on.
368 0 : if ( GetPageFrm() != _rAnchorCharFrm.FindPageFrm() )
369 : {
370 0 : UnlockPosition();
371 : }
372 0 : InvalidateObjPos();
373 : }
374 : // keep new top of line value
375 0 : mnLastTopOfLine = nTopOfLine;
376 : }
377 : }
378 0 : }
379 :
380 0 : void SwAnchoredObject::ClearCharRectAndTopOfLine()
381 : {
382 0 : maLastCharRect.Clear();
383 0 : mnLastTopOfLine = 0;
384 0 : }
385 :
386 0 : const Point SwAnchoredObject::GetCurrRelPos() const
387 : {
388 0 : return maRelPos;
389 : }
390 0 : void SwAnchoredObject::SetCurrRelPos( Point _aRelPos )
391 : {
392 0 : maRelPos = _aRelPos;
393 0 : }
394 :
395 0 : void SwAnchoredObject::ObjectAttachedToAnchorFrame()
396 : {
397 : // default behaviour:
398 : // update layout direction, the anchored object is assigned to
399 0 : UpdateLayoutDir();
400 0 : }
401 :
402 : /** method update layout direction the layout direction, the anchored
403 : object is in
404 :
405 : #i31698#
406 : method has typically to be called, if the anchored object gets its
407 : anchor frame assigned.
408 : */
409 0 : void SwAnchoredObject::UpdateLayoutDir()
410 : {
411 0 : SwFrmFmt::tLayoutDir nLayoutDir = SwFrmFmt::HORI_L2R;
412 0 : const SwFrm* pAnchorFrm = GetAnchorFrm();
413 0 : if ( pAnchorFrm )
414 : {
415 0 : const bool bVert = pAnchorFrm->IsVertical();
416 0 : const bool bR2L = pAnchorFrm->IsRightToLeft();
417 0 : if ( bVert )
418 : {
419 0 : nLayoutDir = SwFrmFmt::VERT_R2L;
420 : }
421 0 : else if ( bR2L )
422 : {
423 0 : nLayoutDir = SwFrmFmt::HORI_R2L;
424 : }
425 : }
426 0 : GetFrmFmt().SetLayoutDir( nLayoutDir );
427 0 : }
428 :
429 : /** method to perform necessary invalidations for the positioning of
430 : objects, for whose the wrapping style influence has to be considered
431 : on the object positioning.
432 :
433 : #i28701#
434 : */
435 0 : void SwAnchoredObject::InvalidateObjPosForConsiderWrapInfluence(
436 : const bool _bNotifyBackgrd )
437 : {
438 0 : if ( ConsiderObjWrapInfluenceOnObjPos() )
439 : {
440 : // indicate that object has not to be considered for text wrap
441 0 : SetConsiderForTextWrap( false );
442 : // unlock position
443 0 : UnlockPosition();
444 : // invalidate position
445 0 : InvalidateObjPos();
446 : // invalidate 'background', if requested
447 0 : if ( _bNotifyBackgrd )
448 : {
449 0 : NotifyBackground( GetPageFrm(), GetObjRectWithSpaces(), PREP_FLY_LEAVE );
450 : }
451 : }
452 0 : }
453 :
454 : /** method to determine, if wrapping style influence of the anchored
455 : object has to be considered on the object positioning
456 :
457 : #i28701#
458 : Note: result of this method also decides, if the booleans for the
459 : layout process are of relevance.
460 : */
461 0 : bool SwAnchoredObject::ConsiderObjWrapInfluenceOnObjPos() const
462 : {
463 0 : bool bRet( false );
464 :
465 0 : const SwFrmFmt& rObjFmt = GetFrmFmt();
466 :
467 : // --> #i3317# - add condition <IsTmpConsiderWrapInfluence()>
468 : // --> #i55204#
469 : // - correction: wrapping style influence has been considered, if condition
470 : // <IsTmpConsiderWrapInfluence()> is hold, regardless of its anchor type
471 : // or its wrapping style.
472 0 : if ( IsTmpConsiderWrapInfluence() )
473 : {
474 0 : bRet = true;
475 : }
476 0 : else if ( rObjFmt.getIDocumentSettingAccess()->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) )
477 : {
478 0 : const SwFmtAnchor& rAnchor = rObjFmt.GetAnchor();
479 0 : if ( ((rAnchor.GetAnchorId() == FLY_AT_CHAR) ||
480 0 : (rAnchor.GetAnchorId() == FLY_AT_PARA)) &&
481 0 : rObjFmt.GetSurround().GetSurround() != SURROUND_THROUGHT )
482 : {
483 : // --> #i34520# - text also wraps around anchored
484 : // objects in the layer Hell - see the text formatting.
485 : // Thus, it hasn't to be checked here.
486 0 : bRet = true;
487 : }
488 : }
489 :
490 0 : return bRet;
491 : }
492 :
493 : /** method to determine, if other anchored objects, also attached at
494 : to the anchor frame, have to consider its wrap influence.
495 :
496 : // --> #i43255#
497 : */
498 0 : bool SwAnchoredObject::ConsiderObjWrapInfluenceOfOtherObjs() const
499 : {
500 0 : bool bRet( false );
501 :
502 0 : const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
503 0 : if ( pObjs->Count() > 1 )
504 : {
505 0 : sal_uInt32 i = 0;
506 0 : for ( ; i < pObjs->Count(); ++i )
507 : {
508 0 : SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
509 0 : if ( pAnchoredObj != this &&
510 0 : pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
511 : {
512 0 : bRet = true;
513 0 : break;
514 : }
515 : }
516 : }
517 :
518 0 : return bRet;
519 : }
520 :
521 0 : bool SwAnchoredObject::ConsiderForTextWrap() const
522 : {
523 0 : if ( ConsiderObjWrapInfluenceOnObjPos() )
524 0 : return mbConsiderForTextWrap;
525 : else
526 0 : return true;
527 : }
528 :
529 0 : void SwAnchoredObject::SetConsiderForTextWrap( const bool _bConsiderForTextWrap )
530 : {
531 0 : mbConsiderForTextWrap = _bConsiderForTextWrap;
532 0 : }
533 :
534 0 : bool SwAnchoredObject::PositionLocked() const
535 : {
536 0 : if ( ConsiderObjWrapInfluenceOnObjPos() )
537 0 : return mbPositionLocked;
538 : else
539 0 : return false;
540 : }
541 :
542 0 : bool SwAnchoredObject::RestartLayoutProcess() const
543 : {
544 0 : if ( ConsiderObjWrapInfluenceOnObjPos() )
545 0 : return mbRestartLayoutProcess;
546 : else
547 0 : return false;
548 : }
549 :
550 0 : void SwAnchoredObject::SetRestartLayoutProcess( const bool _bRestartLayoutProcess )
551 : {
552 0 : mbRestartLayoutProcess = _bRestartLayoutProcess;
553 0 : }
554 :
555 : // --> #i35911#
556 0 : bool SwAnchoredObject::ClearedEnvironment() const
557 : {
558 0 : if ( ConsiderObjWrapInfluenceOnObjPos() )
559 0 : return mbClearedEnvironment;
560 : else
561 0 : return false;
562 : }
563 0 : void SwAnchoredObject::SetClearedEnvironment( const bool _bClearedEnvironment )
564 : {
565 0 : mbClearedEnvironment = _bClearedEnvironment;
566 0 : }
567 :
568 : /** method to determine, if due to anchored object size and wrapping
569 : style, its layout environment is cleared.
570 :
571 : #i35911#
572 : */
573 0 : bool SwAnchoredObject::HasClearedEnvironment() const
574 : {
575 0 : bool bHasClearedEnvironment( false );
576 :
577 : // --> #i43913# - layout frame, vertical position is orient at, has to be set.
578 : OSL_ENSURE( GetVertPosOrientFrm(),
579 : "<SwAnchoredObject::HasClearedEnvironment()> - layout frame missing, at which the vertical position is oriented at." );
580 0 : if ( GetVertPosOrientFrm() &&
581 0 : GetAnchorFrm()->IsTxtFrm() &&
582 0 : !static_cast<const SwTxtFrm*>(GetAnchorFrm())->IsFollow() &&
583 0 : static_cast<const SwTxtFrm*>(GetAnchorFrm())->FindPageFrm()->GetPhyPageNum() >=
584 0 : GetPageFrm()->GetPhyPageNum() )
585 : {
586 0 : const SwFrm* pTmpFrm = GetVertPosOrientFrm()->Lower();
587 0 : while ( pTmpFrm && pTmpFrm->IsLayoutFrm() && !pTmpFrm->IsTabFrm() )
588 : {
589 0 : pTmpFrm = static_cast<const SwLayoutFrm*>(pTmpFrm)->Lower();
590 : }
591 0 : if ( !pTmpFrm )
592 : {
593 0 : bHasClearedEnvironment = true;
594 : }
595 0 : else if ( pTmpFrm->IsTxtFrm() && !pTmpFrm->GetNext() )
596 : {
597 0 : const SwTxtFrm* pTmpTxtFrm = static_cast<const SwTxtFrm*>(pTmpFrm);
598 0 : if ( pTmpTxtFrm->IsUndersized() ||
599 0 : ( pTmpTxtFrm->GetFollow() &&
600 0 : pTmpTxtFrm->GetFollow()->GetOfst() == 0 ) )
601 : {
602 0 : bHasClearedEnvironment = true;
603 : }
604 : }
605 : }
606 :
607 0 : return bHasClearedEnvironment;
608 : }
609 :
610 : /** method to add spacing to object area
611 :
612 : #i28701#
613 : #i68520# - return constant reference and use cache
614 : */
615 0 : const SwRect& SwAnchoredObject::GetObjRectWithSpaces() const
616 : {
617 0 : if ( mbObjRectWithSpacesValid &&
618 0 : maLastObjRect != GetObjRect() )
619 : {
620 : OSL_FAIL( "<SwAnchoredObject::GetObjRectWithSpaces> - cache for object rectangle inclusive spaces marked as valid, but it couldn't be. Missing invalidation of cache. Please inform OD." );
621 0 : InvalidateObjRectWithSpaces();
622 : }
623 0 : if ( !mbObjRectWithSpacesValid )
624 : {
625 0 : maObjRectWithSpaces = GetObjBoundRect();
626 0 : const SwFrmFmt& rFmt = GetFrmFmt();
627 0 : const SvxULSpaceItem& rUL = rFmt.GetULSpace();
628 0 : const SvxLRSpaceItem& rLR = rFmt.GetLRSpace();
629 : {
630 0 : maObjRectWithSpaces.Top ( std::max( maObjRectWithSpaces.Top() - long(rUL.GetUpper()), 0L ));
631 0 : maObjRectWithSpaces.Left( std::max( maObjRectWithSpaces.Left()- long(rLR.GetLeft()), 0L ));
632 0 : maObjRectWithSpaces.SSize().Height() += rUL.GetLower();
633 0 : maObjRectWithSpaces.SSize().Width() += rLR.GetRight();
634 : }
635 :
636 0 : mbObjRectWithSpacesValid = true;
637 0 : maLastObjRect = GetObjRect();
638 : }
639 :
640 0 : return maObjRectWithSpaces;
641 : }
642 :
643 : // --> #i68520#
644 0 : void SwAnchoredObject::SetObjTop( const SwTwips _nTop)
645 : {
646 0 : const bool bTopChanged( _SetObjTop( _nTop ) );
647 0 : if ( bTopChanged )
648 : {
649 0 : mbObjRectWithSpacesValid = false;
650 : }
651 0 : }
652 :
653 0 : void SwAnchoredObject::SetObjLeft( const SwTwips _nLeft)
654 : {
655 0 : const bool bLeftChanged( _SetObjLeft( _nLeft ) );
656 0 : if ( bLeftChanged )
657 : {
658 0 : mbObjRectWithSpacesValid = false;
659 : }
660 0 : }
661 :
662 : /** method to update anchored object in the <SwSortedObjs> lists
663 :
664 : #i28701#
665 : If document compatibility option 'Consider wrapping style influence
666 : on object positioning' is ON, additionally all anchored objects
667 : at the anchor frame and all following anchored objects on the page
668 : frame are invalidated.
669 : */
670 0 : void SwAnchoredObject::UpdateObjInSortedList()
671 : {
672 0 : if ( GetAnchorFrm() )
673 : {
674 0 : if ( GetFrmFmt().getIDocumentSettingAccess()->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) )
675 : {
676 : // invalidate position of all anchored objects at anchor frame
677 0 : if ( GetAnchorFrm()->GetDrawObjs() )
678 : {
679 0 : const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
680 : // determine start index
681 0 : sal_uInt32 i = 0;
682 0 : for ( ; i < pObjs->Count(); ++i )
683 : {
684 0 : SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
685 0 : if ( pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
686 0 : pAnchoredObj->InvalidateObjPosForConsiderWrapInfluence( true );
687 : else
688 0 : pAnchoredObj->InvalidateObjPos();
689 : }
690 : }
691 : // invalidate all following anchored objects on the page frame
692 0 : if ( GetPageFrm() && GetPageFrm()->GetSortedObjs() )
693 : {
694 0 : const SwSortedObjs* pObjs = GetPageFrm()->GetSortedObjs();
695 : // determine start index
696 0 : sal_uInt32 i = pObjs->ListPosOf( *this ) + 1;
697 0 : for ( ; i < pObjs->Count(); ++i )
698 : {
699 0 : SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
700 0 : if ( pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
701 0 : pAnchoredObj->InvalidateObjPosForConsiderWrapInfluence( true );
702 : else
703 0 : pAnchoredObj->InvalidateObjPos();
704 : }
705 : }
706 : }
707 : // update its position in the sorted object list of its anchor frame
708 0 : AnchorFrm()->GetDrawObjs()->Update( *this );
709 : // update its position in the sorted object list of its page frame
710 : // note: as-character anchored object aren't registered at a page frame
711 0 : if ( GetFrmFmt().GetAnchor().GetAnchorId() != FLY_AS_CHAR )
712 : {
713 0 : GetPageFrm()->GetSortedObjs()->Update( *this );
714 : }
715 : }
716 0 : }
717 :
718 : /** method to determine, if invalidation of position is allowed
719 :
720 : #i28701#
721 : */
722 0 : bool SwAnchoredObject::InvalidationOfPosAllowed() const
723 : {
724 : // --> Check, if page frame layout is in progress,
725 : // isn't needed, because of anchored object, whose are moved forward.
726 0 : return !PositionLocked();
727 : }
728 :
729 : /** method to determine the page frame, on which the 'anchor' of
730 : the given anchored object is.
731 :
732 : #i28701#
733 : #i33751#, #i34060#
734 : Adjust meaning of method and thus its name: If the anchored object
735 : or its anchor isn't correctly inserted in the layout, no page frame
736 : can be found. Thus, the return type changed to be a pointer and can
737 : be NULL.
738 : */
739 0 : SwPageFrm* SwAnchoredObject::FindPageFrmOfAnchor()
740 : {
741 0 : SwPageFrm* pRetPageFrm = 0L;
742 :
743 : // --> #i44339# - check, if anchor frame exists.
744 0 : if ( mpAnchorFrm )
745 : {
746 : // --> #i26945# - use new method <GetAnchorFrmContainingAnchPos()>
747 0 : pRetPageFrm = GetAnchorFrmContainingAnchPos()->FindPageFrm();
748 : }
749 :
750 0 : return pRetPageFrm;
751 : }
752 :
753 : /** get frame, which contains the anchor character, if the object
754 : is anchored at-character or as-character.
755 :
756 : #i26945#
757 :
758 : @return SwTxtFrm*
759 : text frame containing the anchor character. It's NULL, if the object
760 : isn't anchored at-character resp. as-character.
761 : */
762 0 : SwTxtFrm* SwAnchoredObject::FindAnchorCharFrm()
763 : {
764 0 : SwTxtFrm* pAnchorCharFrm( 0L );
765 :
766 : // --> #i44339# - check, if anchor frame exists.
767 0 : if ( mpAnchorFrm )
768 : {
769 0 : const SwFmtAnchor& rAnch = GetFrmFmt().GetAnchor();
770 0 : if ((rAnch.GetAnchorId() == FLY_AT_CHAR) ||
771 0 : (rAnch.GetAnchorId() == FLY_AS_CHAR))
772 : {
773 0 : pAnchorCharFrm = &(static_cast<SwTxtFrm*>(AnchorFrm())->
774 0 : GetFrmAtOfst( rAnch.GetCntntAnchor()->nContent.GetIndex() ));
775 : }
776 : }
777 :
778 0 : return pAnchorCharFrm;
779 : }
780 :
781 : /** method to determine, if a format on the anchored object is possible
782 :
783 : #i28701#
784 : A format is possible, if anchored object is in an invisible layer.
785 : Note: method is virtual to refine the conditions for the sub-classes.
786 : */
787 0 : bool SwAnchoredObject::IsFormatPossible() const
788 : {
789 0 : return GetFrmFmt().GetDoc()->IsVisibleLayerId( GetDrawObj()->GetLayer() );
790 : }
791 :
792 : // --> #i3317#
793 0 : void SwAnchoredObject::SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence )
794 : {
795 0 : mbTmpConsiderWrapInfluence = _bTmpConsiderWrapInfluence;
796 : // --> #i35911#
797 0 : if ( mbTmpConsiderWrapInfluence )
798 : {
799 0 : SwLayouter::InsertObjForTmpConsiderWrapInfluence( *(GetFrmFmt().GetDoc()),
800 0 : *this );
801 : }
802 0 : }
803 :
804 0 : bool SwAnchoredObject::IsTmpConsiderWrapInfluence() const
805 : {
806 0 : return mbTmpConsiderWrapInfluence;
807 : }
808 :
809 0 : void SwAnchoredObject::SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence )
810 : {
811 0 : const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
812 0 : if ( pObjs->Count() > 1 )
813 : {
814 0 : sal_uInt32 i = 0;
815 0 : for ( ; i < pObjs->Count(); ++i )
816 : {
817 0 : SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
818 0 : if ( pAnchoredObj != this )
819 : {
820 0 : pAnchoredObj->SetTmpConsiderWrapInfluence( bTmpConsiderWrapInfluence );
821 : }
822 : }
823 : }
824 0 : }
825 :
826 : /** method to determine, if the anchored object is overlapping with a
827 : previous column
828 :
829 : #i3317#
830 : overlapping with a previous column means, that the object overlaps
831 : with a column, which is a previous one of the column its anchor
832 : frame is in.
833 : Only applied for at-paragraph and at-character anchored objects.
834 : */
835 0 : bool SwAnchoredObject::OverlapsPrevColumn() const
836 : {
837 0 : bool bOverlapsPrevColumn( false );
838 :
839 0 : if ( mpAnchorFrm && mpAnchorFrm->IsTxtFrm() )
840 : {
841 0 : const SwFrm* pColFrm = mpAnchorFrm->FindColFrm();
842 0 : if ( pColFrm && pColFrm->GetPrev() )
843 : {
844 0 : const SwFrm* pTmpColFrm = pColFrm->GetPrev();
845 0 : SwRect aChkRect;
846 0 : while ( pTmpColFrm )
847 : {
848 0 : aChkRect.Union( pTmpColFrm->Frm() );
849 0 : pTmpColFrm = pTmpColFrm->GetPrev();
850 : }
851 0 : bOverlapsPrevColumn = GetObjRect().IsOver( aChkRect );
852 : }
853 : }
854 :
855 0 : return bOverlapsPrevColumn;
856 : }
857 :
858 : /** method to determine position of anchored object relative to
859 : anchor frame
860 :
861 : #i30669#
862 : Usage: Needed layout information for WW8 export
863 : */
864 0 : Point SwAnchoredObject::GetRelPosToAnchorFrm() const
865 : {
866 0 : Point aRelPos;
867 :
868 : OSL_ENSURE( GetAnchorFrm(),
869 : "<SwAnchoredObject::GetRelPosToAnchorFrm()> - missing anchor frame." );
870 0 : aRelPos = GetObjRect().Pos();
871 0 : aRelPos -= GetAnchorFrm()->Frm().Pos();
872 :
873 0 : return aRelPos;
874 : }
875 :
876 : /** method to determine position of anchored object relative to
877 : page frame
878 :
879 : #i30669#
880 : Usage: Needed layout information for WW8 export
881 : #i33818# - add parameters <_bFollowTextFlow> and
882 : <_obRelToTableCell>
883 : If <_bFollowTextFlow> is set and object is anchored inside table,
884 : the position relative to the table cell is determined. Output
885 : parameter <_obRelToTableCell> reflects this situation
886 : */
887 0 : Point SwAnchoredObject::GetRelPosToPageFrm( const bool _bFollowTextFlow,
888 : bool& _obRelToTableCell ) const
889 : {
890 0 : Point aRelPos;
891 0 : _obRelToTableCell = false;
892 :
893 : OSL_ENSURE( GetAnchorFrm(),
894 : "<SwAnchoredObject::GetRelPosToPageFrm()> - missing anchor frame." );
895 : OSL_ENSURE( GetAnchorFrm()->FindPageFrm(),
896 : "<SwAnchoredObject::GetRelPosToPageFrm()> - missing page frame." );
897 :
898 0 : aRelPos = GetObjRect().Pos();
899 : // --> #i33818# - search for cell frame, if object has to
900 : // follow the text flow.
901 0 : const SwFrm* pFrm( 0L );
902 0 : if ( _bFollowTextFlow && !GetAnchorFrm()->IsPageFrm() )
903 : {
904 0 : pFrm = GetAnchorFrm()->GetUpper();
905 0 : while ( !pFrm->IsCellFrm() && !pFrm->IsPageFrm() )
906 : {
907 0 : pFrm = pFrm->GetUpper();
908 : }
909 : }
910 : else
911 : {
912 0 : pFrm = GetAnchorFrm()->FindPageFrm();
913 : }
914 0 : if ( pFrm->IsCellFrm() )
915 : {
916 0 : aRelPos -= ( pFrm->Frm().Pos() + pFrm->Prt().Pos() );
917 0 : _obRelToTableCell = true;
918 : }
919 : else
920 : {
921 0 : aRelPos -= pFrm->Frm().Pos();
922 : }
923 :
924 0 : return aRelPos;
925 : }
926 :
927 : /** method to determine position of anchored object relative to
928 : anchor character
929 :
930 : #i30669#
931 : Usage: Needed layout information for WW8 export
932 : */
933 0 : Point SwAnchoredObject::GetRelPosToChar() const
934 : {
935 0 : Point aRelPos;
936 :
937 0 : aRelPos = GetObjRect().Pos();
938 0 : aRelPos -= GetLastCharRect().Pos();
939 :
940 0 : return aRelPos;
941 : }
942 :
943 : /** method to determine position of anchored object relative to
944 : top of line
945 :
946 : #i30669#
947 : Usage: Needed layout information for WW8 export
948 : */
949 0 : Point SwAnchoredObject::GetRelPosToLine() const
950 : {
951 0 : Point aRelPos;
952 :
953 0 : aRelPos = GetObjRect().Pos();
954 0 : aRelPos.Y() -= GetLastTopOfLine();
955 :
956 0 : return aRelPos;
957 : }
958 :
959 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|