1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "objectformattertxtfrm.hxx"
#include <sortedobjs.hxx>
#include <rootfrm.hxx>
#include <anchoredobject.hxx>
#include <txtfrm.hxx>
#include <pagefrm.hxx>
#include <rowfrm.hxx>
#include <layouter.hxx>
#include <fmtanchr.hxx>
#include <fmtwrapinfluenceonobjpos.hxx>
#include <fmtfollowtextflow.hxx>
#include <layact.hxx>
#include <flyfrm.hxx>
#include <ftnfrm.hxx>
#include <osl/diagnose.h>
using namespace ::com::sun::star;
namespace {
// little helper class to forbid follow formatting for the given text frame
class SwForbidFollowFormat
{
private:
SwTextFrame& mrTextFrame;
const bool bOldFollowFormatAllowed;
public:
explicit SwForbidFollowFormat( SwTextFrame& _rTextFrame )
: mrTextFrame( _rTextFrame ),
bOldFollowFormatAllowed( _rTextFrame.FollowFormatAllowed() )
{
mrTextFrame.ForbidFollowFormat();
}
~SwForbidFollowFormat()
{
if ( bOldFollowFormatAllowed )
{
mrTextFrame.AllowFollowFormat();
}
}
};
}
SwObjectFormatterTextFrame::SwObjectFormatterTextFrame( SwTextFrame& _rAnchorTextFrame,
const SwPageFrame& _rPageFrame,
SwTextFrame* _pMasterAnchorTextFrame,
SwLayAction* _pLayAction )
: SwObjectFormatter( _rPageFrame, _pLayAction, true ),
mrAnchorTextFrame( _rAnchorTextFrame ),
mpMasterAnchorTextFrame( _pMasterAnchorTextFrame )
{
}
SwObjectFormatterTextFrame::~SwObjectFormatterTextFrame()
{
}
std::unique_ptr<SwObjectFormatterTextFrame> SwObjectFormatterTextFrame::CreateObjFormatter(
SwTextFrame& _rAnchorTextFrame,
const SwPageFrame& _rPageFrame,
SwLayAction* _pLayAction )
{
std::unique_ptr<SwObjectFormatterTextFrame> pObjFormatter;
// determine 'master' of <_rAnchorTextFrame>, if anchor frame is a follow text frame.
SwTextFrame* pMasterOfAnchorFrame = nullptr;
if ( _rAnchorTextFrame.IsFollow() )
{
pMasterOfAnchorFrame = _rAnchorTextFrame.FindMaster();
while ( pMasterOfAnchorFrame && pMasterOfAnchorFrame->IsFollow() )
{
pMasterOfAnchorFrame = pMasterOfAnchorFrame->FindMaster();
}
}
// create object formatter, if floating screen objects are registered
// at anchor frame (or at 'master' anchor frame)
if ( _rAnchorTextFrame.GetDrawObjs() ||
( pMasterOfAnchorFrame && pMasterOfAnchorFrame->GetDrawObjs() ) )
{
pObjFormatter.reset(
new SwObjectFormatterTextFrame( _rAnchorTextFrame, _rPageFrame,
pMasterOfAnchorFrame, _pLayAction ));
}
return pObjFormatter;
}
SwFrame& SwObjectFormatterTextFrame::GetAnchorFrame()
{
return mrAnchorTextFrame;
}
// #i40147# - add parameter <_bCheckForMovedFwd>.
bool SwObjectFormatterTextFrame::DoFormatObj( SwAnchoredObject& _rAnchoredObj,
const bool _bCheckForMovedFwd )
{
// consider, if the layout action has to be
// restarted due to a delete of a page frame.
if ( GetLayAction() && GetLayAction()->IsAgain() )
{
return false;
}
bool bSuccess( true );
if ( _rAnchoredObj.IsFormatPossible() )
{
_rAnchoredObj.SetRestartLayoutProcess( false );
FormatObj_( _rAnchoredObj );
// consider, if the layout action has to be
// restarted due to a delete of a page frame.
if ( GetLayAction() && GetLayAction()->IsAgain() )
{
return false;
}
// check, if layout process has to be restarted.
// if yes, perform needed invalidations.
// no restart of layout process,
// if anchored object is anchored inside a Writer fly frame,
// its position is already locked, and it follows the text flow.
const bool bRestart =
_rAnchoredObj.RestartLayoutProcess() &&
!( _rAnchoredObj.PositionLocked() &&
_rAnchoredObj.GetAnchorFrame()->IsInFly() &&
_rAnchoredObj.GetFrameFormat()->GetFollowTextFlow().GetValue() );
if ( bRestart )
{
bSuccess = false;
InvalidatePrevObjs( _rAnchoredObj );
InvalidateFollowObjs( _rAnchoredObj );
}
// format anchor text frame, if wrapping style influence of the object
// has to be considered and it's <NONE_SUCCESSIVE_POSITIONED>
// #i3317# - consider also anchored objects, whose
// wrapping style influence is temporarily considered.
// #i40147# - consider also anchored objects, for
// whose the check of a moved forward anchor frame is requested.
// revise decision made for i3317:
// anchored objects, whose wrapping style influence is temporarily considered,
// have to be considered in method <SwObjectFormatterTextFrame::DoFormatObjs()>
if ( bSuccess &&
_rAnchoredObj.ConsiderObjWrapInfluenceOnObjPos() &&
( _bCheckForMovedFwd ||
_rAnchoredObj.GetFrameFormat()->GetWrapInfluenceOnObjPos().
// #i35017# - handle ITERATIVE as ONCE_SUCCESSIVE
GetWrapInfluenceOnObjPos( true ) ==
// #i35017# - constant name has changed
text::WrapInfluenceOnPosition::ONCE_SUCCESSIVE ) )
{
// #i26945# - check conditions for move forward of
// anchor text frame
// determine, if anchor text frame has previous frame
const bool bDoesAnchorHadPrev = ( mrAnchorTextFrame.GetIndPrev() != nullptr );
// #i40141# - use new method - it also formats the
// section the anchor frame is in.
FormatAnchorFrameForCheckMoveFwd();
// #i35911#
if ( _rAnchoredObj.HasClearedEnvironment() )
{
_rAnchoredObj.SetClearedEnvironment( true );
// #i44049# - consider, that anchor frame
// could already been marked to move forward.
SwPageFrame* pAnchorPageFrame( mrAnchorTextFrame.FindPageFrame() );
if ( pAnchorPageFrame != _rAnchoredObj.GetPageFrame() )
{
bool bInsert( true );
sal_uInt32 nToPageNum( 0 );
const SwDoc& rDoc = *(GetPageFrame().GetFormat()->GetDoc());
if ( SwLayouter::FrameMovedFwdByObjPos(
rDoc, mrAnchorTextFrame, nToPageNum ) )
{
if ( nToPageNum < pAnchorPageFrame->GetPhyPageNum() )
SwLayouter::RemoveMovedFwdFrame( rDoc, mrAnchorTextFrame );
else
bInsert = false;
}
if ( bInsert )
{
SwLayouter::InsertMovedFwdFrame( rDoc, mrAnchorTextFrame,
pAnchorPageFrame->GetPhyPageNum() );
mrAnchorTextFrame.InvalidatePos();
bSuccess = false;
InvalidatePrevObjs( _rAnchoredObj );
InvalidateFollowObjs( _rAnchoredObj );
}
else
{
OSL_FAIL( "<SwObjectFormatterTextFrame::DoFormatObj(..)> - anchor frame not marked to move forward" );
}
}
}
else if ( !mrAnchorTextFrame.IsFollow() && bDoesAnchorHadPrev )
{
// index of anchored object in collection of page numbers and
// anchor types
sal_uInt32 nIdx( CountOfCollected() );
OSL_ENSURE( nIdx > 0,
"<SwObjectFormatterTextFrame::DoFormatObj(..)> - anchored object not collected!?" );
--nIdx;
sal_uInt32 nToPageNum( 0 );
// #i43913#
bool bDummy( false );
bool bPageHasFlysAnchoredBelowThis(false);
// see how SwObjectFormatter::FormatObjsAtFrame_() checks
// "pPageFrameOfAnchor == &mrPageFrame" - only caller relevant for
// this subclass
assert(GetPageFrame().GetPhyPageNum() == GetPgNumOfCollected(nIdx));
if ( SwObjectFormatterTextFrame::CheckMovedFwdCondition( *GetCollectedObj( nIdx ),
GetPageFrame(),
IsCollectedAnchoredAtMaster( nIdx ),
nToPageNum, bDummy,
bPageHasFlysAnchoredBelowThis))
{
// #i49987# - consider, that anchor frame
// could already been marked to move forward.
bool bInsert( true );
sal_uInt32 nMovedFwdToPageNum( 0 );
const SwDoc& rDoc = *(GetPageFrame().GetFormat()->GetDoc());
if ( SwLayouter::FrameMovedFwdByObjPos(
rDoc, mrAnchorTextFrame, nMovedFwdToPageNum ) )
{
if ( nMovedFwdToPageNum < nToPageNum )
{
if (!bPageHasFlysAnchoredBelowThis)
{
SwLayouter::RemoveMovedFwdFrame(rDoc, mrAnchorTextFrame);
}
}
else
bInsert = false;
}
if ( bInsert )
{
// Indicate that anchor text frame has to move forward and
// invalidate its position to force a re-format.
if (!bPageHasFlysAnchoredBelowThis)
{
SwLayouter::InsertMovedFwdFrame(rDoc,
mrAnchorTextFrame, nToPageNum);
}
mrAnchorTextFrame.InvalidatePos();
// Indicate restart of the layout process
bSuccess = false;
// If needed, invalidate previous objects anchored at same anchor
// text frame.
InvalidatePrevObjs( _rAnchoredObj );
// Invalidate object and following objects for the restart of the
// layout process
InvalidateFollowObjs( _rAnchoredObj );
}
else
{
OSL_FAIL( "<SwObjectFormatterTextFrame::DoFormatObj(..)> - anchor frame not marked to move forward" );
}
}
}
// i40155# - mark anchor frame not to wrap around
// objects under the condition, that its follow contains all its text.
else if ( !mrAnchorTextFrame.IsFollow() &&
mrAnchorTextFrame.GetFollow() &&
mrAnchorTextFrame.GetFollow()->GetOffset() == TextFrameIndex(0))
{
SwLayouter::RemoveMovedFwdFrame(
*(mrAnchorTextFrame.FindPageFrame()->GetFormat()->GetDoc()),
mrAnchorTextFrame );
}
}
}
return bSuccess;
}
bool SwObjectFormatterTextFrame::DoFormatObjs()
{
if ( !mrAnchorTextFrame.isFrameAreaDefinitionValid() )
{
if ( GetLayAction() &&
mrAnchorTextFrame.FindPageFrame() != &GetPageFrame() )
{
// notify layout action, thus is can restart the layout process on
// a previous page.
GetLayAction()->SetAgain(true);
}
else
{
// the anchor text frame has to be valid, thus assert.
OSL_FAIL( "<SwObjectFormatterTextFrame::DoFormatObjs()> called for invalidate anchor text frame." );
}
return false;
}
bool bSuccess( true );
if ( mrAnchorTextFrame.IsFollow() )
{
// Only floating screen objects anchored as-character are directly
// registered at a follow text frame. The other floating screen objects
// are registered at the 'master' anchor text frame.
// Thus, format the other floating screen objects through the 'master'
// anchor text frame
OSL_ENSURE( mpMasterAnchorTextFrame,
"SwObjectFormatterTextFrame::DoFormatObjs() - missing 'master' anchor text frame" );
bSuccess = FormatObjsAtFrame_( mpMasterAnchorTextFrame );
if ( bSuccess )
{
// format of as-character anchored floating screen objects - no failure
// expected on the format of these objects.
bSuccess = FormatObjsAtFrame_();
}
}
else
{
bSuccess = FormatObjsAtFrame_();
}
// consider anchored objects, whose wrapping style influence are temporarily
// considered.
if ( bSuccess &&
( ConsiderWrapOnObjPos() ||
( !mrAnchorTextFrame.IsFollow() &&
AtLeastOneObjIsTmpConsiderWrapInfluence() ) ) )
{
const bool bDoesAnchorHadPrev = ( mrAnchorTextFrame.GetIndPrev() != nullptr );
// Format anchor text frame after its objects are formatted.
// Note: The format of the anchor frame also formats the invalid
// previous frames of the anchor frame. The format of the previous
// frames is needed to get a correct result of format of the
// anchor frame for the following check for moved forward anchors
// #i40141# - use new method - it also formats the
// section the anchor frame is in.
FormatAnchorFrameForCheckMoveFwd();
sal_uInt32 nToPageNum( 0 );
// #i43913#
bool bInFollow( false );
bool bPageHasFlysAnchoredBelowThis(false);
SwAnchoredObject* pObj = nullptr;
if ( !mrAnchorTextFrame.IsFollow() )
{
pObj = GetFirstObjWithMovedFwdAnchor(
// #i35017# - constant name has changed
text::WrapInfluenceOnPosition::ONCE_CONCURRENT,
nToPageNum, bInFollow, bPageHasFlysAnchoredBelowThis );
}
// #i35911#
if ( pObj && pObj->HasClearedEnvironment() )
{
pObj->SetClearedEnvironment( true );
// #i44049# - consider, that anchor frame
// could already been marked to move forward.
SwPageFrame* pAnchorPageFrame( mrAnchorTextFrame.FindPageFrame() );
// #i43913# - consider, that anchor frame
// is a follow or is in a follow row, which will move forward.
if ( pAnchorPageFrame != pObj->GetPageFrame() ||
bInFollow )
{
bool bInsert( true );
sal_uInt32 nTmpToPageNum( 0 );
const SwDoc& rDoc = *(GetPageFrame().GetFormat()->GetDoc());
if ( SwLayouter::FrameMovedFwdByObjPos(
rDoc, mrAnchorTextFrame, nTmpToPageNum ) )
{
if ( nTmpToPageNum < pAnchorPageFrame->GetPhyPageNum() )
{
if (!bPageHasFlysAnchoredBelowThis)
{
SwLayouter::RemoveMovedFwdFrame(rDoc, mrAnchorTextFrame);
}
}
else
bInsert = false;
}
if ( bInsert )
{
if (!bPageHasFlysAnchoredBelowThis)
{
SwLayouter::InsertMovedFwdFrame(rDoc, mrAnchorTextFrame,
pAnchorPageFrame->GetPhyPageNum());
}
mrAnchorTextFrame.InvalidatePos();
bSuccess = false;
InvalidatePrevObjs( *pObj );
InvalidateFollowObjs( *pObj );
}
else
{
OSL_FAIL( "<SwObjectFormatterTextFrame::DoFormatObjs(..)> - anchor frame not marked to move forward" );
}
}
}
else if ( pObj && bDoesAnchorHadPrev )
{
// Object found, whose anchor is moved forward
// #i49987# - consider, that anchor frame
// could already been marked to move forward.
bool bInsert( true );
sal_uInt32 nMovedFwdToPageNum( 0 );
const SwDoc& rDoc = *(GetPageFrame().GetFormat()->GetDoc());
if ( SwLayouter::FrameMovedFwdByObjPos(
rDoc, mrAnchorTextFrame, nMovedFwdToPageNum ) )
{
if ( nMovedFwdToPageNum < nToPageNum )
SwLayouter::RemoveMovedFwdFrame( rDoc, mrAnchorTextFrame );
else
bInsert = false;
}
if ( bInsert )
{
// Indicate that anchor text frame has to move forward and
// invalidate its position to force a re-format.
SwLayouter::InsertMovedFwdFrame( rDoc, mrAnchorTextFrame, nToPageNum );
mrAnchorTextFrame.InvalidatePos();
// Indicate restart of the layout process
bSuccess = false;
// If needed, invalidate previous objects anchored at same anchor
// text frame.
InvalidatePrevObjs( *pObj );
// Invalidate object and following objects for the restart of the
// layout process
InvalidateFollowObjs( *pObj );
}
else
{
OSL_FAIL( "<SwObjectFormatterTextFrame::DoFormatObjs(..)> - anchor frame not marked to move forward" );
}
}
// #i40155# - mark anchor frame not to wrap around
// objects under the condition, that its follow contains all its text.
else if ( !mrAnchorTextFrame.IsFollow() &&
mrAnchorTextFrame.GetFollow() &&
mrAnchorTextFrame.GetFollow()->GetOffset() == TextFrameIndex(0))
{
SwLayouter::RemoveMovedFwdFrame(
*(mrAnchorTextFrame.FindPageFrame()->GetFormat()->GetDoc()),
mrAnchorTextFrame );
}
}
return bSuccess;
}
void SwObjectFormatterTextFrame::InvalidatePrevObjs( SwAnchoredObject& _rAnchoredObj )
{
const SwFrameFormat* pObjFormat = _rAnchoredObj.GetFrameFormat();
// invalidate all previous objects, whose wrapping influence on the object
// positioning is <NONE_CONCURRENT_POSITIONED>.
// Note: list of objects at anchor frame is sorted by this property.
if (pObjFormat->GetWrapInfluenceOnObjPos().
// #i35017# - handle ITERATIVE as ONCE_SUCCESSIVE
GetWrapInfluenceOnObjPos( true ) !=
// #i35017# - constant name has changed
text::WrapInfluenceOnPosition::ONCE_CONCURRENT )
return;
const SwSortedObjs* pObjs = GetAnchorFrame().GetDrawObjs();
if ( !pObjs )
return;
// determine start index
size_t i = pObjs->ListPosOf( _rAnchoredObj );
while (i > 0)
{
--i;
SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
if (pObjFormat->GetWrapInfluenceOnObjPos().
// #i35017# - handle ITERATIVE as ONCE_SUCCESSIVE
GetWrapInfluenceOnObjPos( true ) ==
// #i35017# - constant name has changed
text::WrapInfluenceOnPosition::ONCE_CONCURRENT )
{
pAnchoredObj->InvalidateObjPosForConsiderWrapInfluence();
}
}
}
void SwObjectFormatterTextFrame::InvalidateFollowObjs( SwAnchoredObject& _rAnchoredObj )
{
_rAnchoredObj.InvalidateObjPosForConsiderWrapInfluence();
const SwSortedObjs* pObjs = GetPageFrame().GetSortedObjs();
if ( pObjs )
{
// determine start index
for ( size_t i = pObjs->ListPosOf( _rAnchoredObj ) + 1; i < pObjs->size(); ++i )
{
SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
pAnchoredObj->InvalidateObjPosForConsiderWrapInfluence();
}
}
}
SwAnchoredObject* SwObjectFormatterTextFrame::GetFirstObjWithMovedFwdAnchor(
const sal_Int16 _nWrapInfluenceOnPosition,
sal_uInt32& _noToPageNum,
bool& _boInFollow,
bool& o_rbPageHasFlysAnchoredBelowThis)
{
// #i35017# - constant names have changed
OSL_ENSURE( _nWrapInfluenceOnPosition == text::WrapInfluenceOnPosition::ONCE_SUCCESSIVE ||
_nWrapInfluenceOnPosition == text::WrapInfluenceOnPosition::ONCE_CONCURRENT,
"<SwObjectFormatterTextFrame::GetFirstObjWithMovedFwdAnchor(..)> - invalid value for parameter <_nWrapInfluenceOnPosition>" );
SwAnchoredObject* pRetAnchoredObj = nullptr;
sal_uInt32 i = 0;
for ( ; i < CountOfCollected(); ++i )
{
SwAnchoredObject* pAnchoredObj = GetCollectedObj(i);
if ( pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() &&
pAnchoredObj->GetFrameFormat()->GetWrapInfluenceOnObjPos().
// #i35017# - handle ITERATIVE as ONCE_SUCCESSIVE
GetWrapInfluenceOnObjPos( true ) == _nWrapInfluenceOnPosition )
{
// see how SwObjectFormatter::FormatObjsAtFrame_() checks
// "pPageFrameOfAnchor == &mrPageFrame" - only caller relevant for
// this subclass
assert(GetPageFrame().GetPhyPageNum() == GetPgNumOfCollected(i));
// #i26945# - use new method <_CheckMovedFwdCondition(..)>
// #i43913#
if ( SwObjectFormatterTextFrame::CheckMovedFwdCondition( *GetCollectedObj( i ),
GetPageFrame(),
IsCollectedAnchoredAtMaster( i ),
_noToPageNum, _boInFollow,
o_rbPageHasFlysAnchoredBelowThis) )
{
pRetAnchoredObj = pAnchoredObj;
break;
}
}
}
return pRetAnchoredObj;
}
static SwRowFrame const* FindTopLevelRowFrame(SwFrame const*const pFrame)
{
SwRowFrame * pRow = const_cast<SwFrame*>(pFrame)->FindRowFrame();
// looks like SwTabFrame has mbInfTab = true so go up 2 levels
while (pRow->GetUpper()->GetUpper()->IsInTab())
{
pRow = pRow->GetUpper()->GetUpper()->FindRowFrame();
}
return pRow;
}
static SwContentFrame const* FindFrameInBody(SwAnchoredObject const& rAnchored)
{
SwFrame const*const pAnchor(rAnchored.GetAnchorFrame());
assert(pAnchor);
if (pAnchor->IsPageFrame() || pAnchor->FindFooterOrHeader())
{
return nullptr;
}
if (pAnchor->IsInFly())
{
return FindFrameInBody(*pAnchor->FindFlyFrame());
}
if (pAnchor->IsInFootnote())
{
return pAnchor->FindFootnoteFrame()->GetRef();
}
assert(pAnchor->IsInDocBody());
assert(pAnchor->IsContentFrame());
return static_cast<SwContentFrame const*>(pAnchor);
}
// #i58182#
// - replace private method by corresponding static public method
bool SwObjectFormatterTextFrame::CheckMovedFwdCondition(
SwAnchoredObject& _rAnchoredObj,
SwPageFrame const& rFromPageFrame,
const bool _bAnchoredAtMasterBeforeFormatAnchor,
sal_uInt32& _noToPageNum,
bool& _boInFollow,
bool& o_rbPageHasFlysAnchoredBelowThis)
{
const sal_uInt32 _nFromPageNum(rFromPageFrame.GetPhyPageNum());
bool bAnchorIsMovedForward( false );
SwPageFrame* pPageFrameOfAnchor = _rAnchoredObj.FindPageFrameOfAnchor();
if ( pPageFrameOfAnchor )
{
const sal_uInt32 nPageNum = pPageFrameOfAnchor->GetPhyPageNum();
if ( nPageNum > _nFromPageNum )
{
_noToPageNum = nPageNum;
// Handling of special case:
// If anchor frame is move forward into a follow flow row,
// <_noToPageNum> is set to <_nFromPageNum + 1>, because it is
// possible that the anchor page frame isn't valid, because the
// page distance between master row and follow flow row is greater
// than 1.
if ( _noToPageNum > (_nFromPageNum + 1) )
{
SwFrame* pAnchorFrame = _rAnchoredObj.GetAnchorFrameContainingAnchPos();
if ( pAnchorFrame->IsInTab() &&
pAnchorFrame->IsInFollowFlowRow() )
{
_noToPageNum = _nFromPageNum + 1;
}
}
bAnchorIsMovedForward = true;
}
}
// #i26945# - check, if an at-paragraph|at-character
// anchored object is now anchored at a follow text frame, which will be
// on the next page. Also check, if an at-character anchored object
// is now anchored at a text frame, which is in a follow flow row,
// which will be on the next page.
if ( !bAnchorIsMovedForward &&
_bAnchoredAtMasterBeforeFormatAnchor &&
((_rAnchoredObj.GetFrameFormat()->GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_CHAR) ||
(_rAnchoredObj.GetFrameFormat()->GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_PARA)))
{
SwFrame* pAnchorFrame = _rAnchoredObj.GetAnchorFrameContainingAnchPos();
OSL_ENSURE( pAnchorFrame->IsTextFrame(),
"<SwObjectFormatterTextFrame::CheckMovedFwdCondition(..) - wrong type of anchor frame>" );
SwTextFrame* pAnchorTextFrame = static_cast<SwTextFrame*>(pAnchorFrame);
bool bCheck( false );
if ( pAnchorTextFrame->IsFollow() )
{
bCheck = true;
}
else if( pAnchorTextFrame->IsInTab() )
{
const SwRowFrame* pMasterRow = pAnchorTextFrame->IsInFollowFlowRow();
if ( pMasterRow &&
pMasterRow->FindPageFrame() == pPageFrameOfAnchor )
{
bCheck = true;
}
}
if ( bCheck )
{
// check, if found text frame will be on the next page
// by checking, if it's in a column, which has no next.
SwFrame* pColFrame = pAnchorTextFrame->FindColFrame();
while ( pColFrame && !pColFrame->GetNext() )
{
pColFrame = pColFrame->FindColFrame();
}
if ( !pColFrame || !pColFrame->GetNext() )
{
_noToPageNum = _nFromPageNum + 1;
bAnchorIsMovedForward = true;
// #i43913#
_boInFollow = true;
}
}
}
if (bAnchorIsMovedForward)
{
// tdf#138518 try to determine if there is a fly on page rFromPageFrame
// which is anchored in a frame that is "below" the anchor frame
// of _rAnchoredObj, such that it should move to the next page before
// _rAnchoredObj does
if (auto * pObjs = rFromPageFrame.GetSortedObjs())
{
for (SwAnchoredObject *const pObj : *pObjs)
{
SwPageFrame const*const pObjAnchorPage(pObj->FindPageFrameOfAnchor());
assert(pObjAnchorPage);
if ((pObjAnchorPage == &rFromPageFrame
? _boInFollow // same-page but will move forward
: rFromPageFrame.GetPhyPageNum() < pObjAnchorPage->GetPhyPageNum())
&& pObj->GetFrameFormat()->GetAnchor().GetAnchorId()
!= RndStdIds::FLY_AS_CHAR)
{
if (pPageFrameOfAnchor->GetPhyPageNum() < pObjAnchorPage->GetPhyPageNum())
{
SAL_INFO("sw.layout", "SwObjectFormatterTextFrame::CheckMovedFwdCondition(): o_rbPageHasFlysAnchoredBelowThis because next page");
o_rbPageHasFlysAnchoredBelowThis = true;
break;
}
// on same page: check if it's in next-chain in the document body
// (in case both are in the same fly the flag must not be
// set because the whole fly moves at once)
SwContentFrame const*const pInBodyFrameObj(FindFrameInBody(*pObj));
SwContentFrame const*const pInBodyFrameAnchoredObj(FindFrameInBody(_rAnchoredObj));
if (pInBodyFrameObj && pInBodyFrameAnchoredObj)
{
bool isBreakMore(false);
// currently this ignores index of at-char flys
for (SwContentFrame const* pContentFrame = pInBodyFrameAnchoredObj->FindNextCnt();
pContentFrame;
pContentFrame = pContentFrame->FindNextCnt())
{
if (pInBodyFrameObj == pContentFrame)
{
// subsequent cells in a row are not automatically
// "below" and the row could potentially be split
// TODO refine check if needed
if (!pInBodyFrameAnchoredObj->IsInTab()
|| FindTopLevelRowFrame(pInBodyFrameAnchoredObj)
!= FindTopLevelRowFrame(pInBodyFrameAnchoredObj))
{ // anchored in next chain on same page
SAL_INFO("sw.layout", "SwObjectFormatterTextFrame::CheckMovedFwdCondition(): o_rbPageHasFlysAnchoredBelowThis because next chain on same page");
o_rbPageHasFlysAnchoredBelowThis = true;
isBreakMore = true;
}
break;
}
}
if (isBreakMore)
{
break;
}
}
}
}
}
}
return bAnchorIsMovedForward;
}
static void CleanupEmptyFootnoteFrame(SwFrame* pLowerFrame)
{
// Calc on a SwTextFrame in a footnote can move it to the next page -
// deletion of the SwFootnoteFrame was disabled with SwFrameDeleteGuard
// but now we have to clean up empty footnote frames to prevent crashes.
// Note: check it at this level, not lower: both container and footnote
// can be deleted at the same time!
if (!pLowerFrame->IsFootnoteContFrame())
return;
for (SwFrame * pFootnote = pLowerFrame->GetLower(); pFootnote; )
{
assert(pFootnote->IsFootnoteFrame());
SwFrame *const pNextNote = pFootnote->GetNext();
if (!pFootnote->IsDeleteForbidden() && !pFootnote->GetLower() && !pFootnote->IsColLocked() &&
!static_cast<SwFootnoteFrame*>(pFootnote)->IsBackMoveLocked())
{
pFootnote->Cut();
SwFrame::DestroyFrame(pFootnote);
}
pFootnote = pNextNote;
}
}
// #i40140# - helper method to format layout frames used by
// method <SwObjectFormatterTextFrame::FormatAnchorFrameForCheckMoveFwd()>
// #i44049# - format till a certain lower frame, if provided.
static void lcl_FormatContentOfLayoutFrame( SwLayoutFrame* pLayFrame,
SwFrame* pLastLowerFrame = nullptr )
{
SwFrame* pLowerFrame = pLayFrame->GetLower();
while ( pLowerFrame )
{
// #i44049#
if ( pLastLowerFrame && pLowerFrame == pLastLowerFrame )
{
break;
}
if ( pLowerFrame->IsLayoutFrame() )
{
SwFrameDeleteGuard aCrudeHack(pLowerFrame); // ??? any issue setting this for non-footnote frames?
lcl_FormatContentOfLayoutFrame( static_cast<SwLayoutFrame*>(pLowerFrame),
pLastLowerFrame );
}
else
pLowerFrame->Calc(pLowerFrame->getRootFrame()->GetCurrShell()->GetOut());
// Calc on a SwTextFrame in a footnote can move it to the next page -
// deletion of the SwFootnoteFrame was disabled with SwFrameDeleteGuard
// but now we have to clean up empty footnote frames to prevent crashes.
// Note: check it at this level, not lower: both container and footnote
// can be deleted at the same time!
SwFrame *const pNext = pLowerFrame->GetNext();
CleanupEmptyFootnoteFrame(pLowerFrame);
pLowerFrame = pNext;
}
}
/** method to format given anchor text frame and its previous frames
#i56300#
Usage: Needed to check, if the anchor text frame is moved forward
due to the positioning and wrapping of its anchored objects, and
to format the frames, which have become invalid due to the anchored
object formatting in the iterative object positioning algorithm
*/
void SwObjectFormatterTextFrame::FormatAnchorFrameAndItsPrevs( SwTextFrame& _rAnchorTextFrame )
{
// #i47014# - no format of section and previous columns
// for follow text frames.
if ( !_rAnchorTextFrame.IsFollow() )
{
// In case the anchor frame is in a column or section, format its
// previous frames first - but don't jump out of the current layout
// environment, e.g. from footnotes into the footnote boss.
SwFrame * pSectFrame(nullptr);
SwFrame * pColFrameOfAnchor(nullptr);
for (SwFrame* pUpper = _rAnchorTextFrame.GetUpper();
pUpper != nullptr; pUpper = pUpper->GetUpper())
{
if (pUpper->IsCellFrame())
{
break; // apparently nothing to be done?
}
if (pUpper->IsFootnoteFrame())
{
SAL_INFO_IF(pColFrameOfAnchor == nullptr && pUpper->FindColFrame(),
"sw.layout", "tdf#122894 skipping column for footnote in column");
break; // stop: prevent crash in case footnotes are being moved
}
if (pUpper->IsSctFrame())
{
pColFrameOfAnchor = nullptr;
pSectFrame = pUpper;
break;
}
if (pColFrameOfAnchor != nullptr)
{ // parent of column not a section frame => column not in section
break;
}
if (pUpper->IsColumnFrame())
{
pColFrameOfAnchor = pUpper;
}
}
// if anchor frame is directly inside a section, format this section and
// its previous frames.
// Note: It's a very simple format without formatting objects.
if (pSectFrame)
{
assert(pSectFrame->IsSctFrame());
{
SwFrameDeleteGuard aDeleteGuard(&_rAnchorTextFrame);
// #i44049#
_rAnchorTextFrame.LockJoin();
SwFrame* pFrame = pSectFrame->GetUpper()->GetLower();
// #i49605# - section frame could move forward
// by the format of its previous frame.
// Thus, check for valid <pFrame>.
while ( pFrame && pFrame != pSectFrame )
{
SwFrameDeleteGuard aDeleteFrameGuard(pFrame);
if ( pFrame->IsLayoutFrame() )
lcl_FormatContentOfLayoutFrame( static_cast<SwLayoutFrame*>(pFrame) );
else
pFrame->Calc(pFrame->getRootFrame()->GetCurrShell()->GetOut());
pFrame = pFrame->GetNext();
}
lcl_FormatContentOfLayoutFrame( static_cast<SwLayoutFrame*>(pSectFrame),
&_rAnchorTextFrame );
// #i44049#
_rAnchorTextFrame.UnlockJoin();
}
}
// #i40140# - if anchor frame is inside a column,
// format the content of the previous columns.
// Note: It's a very simple format without formatting objects.
if (pColFrameOfAnchor)
{
assert(pColFrameOfAnchor->IsColumnFrame());
// #i44049#
_rAnchorTextFrame.LockJoin();
SwFrameDeleteGuard aDeleteGuard(&_rAnchorTextFrame);
SwFrame* pColFrame = pColFrameOfAnchor->GetUpper()->GetLower();
while ( pColFrame != pColFrameOfAnchor )
{
SwFrame* pFrame = pColFrame->GetLower();
while ( pFrame )
{
if ( pFrame->IsLayoutFrame() )
lcl_FormatContentOfLayoutFrame( static_cast<SwLayoutFrame*>(pFrame) );
else
pFrame->Calc(pFrame->getRootFrame()->GetCurrShell()->GetOut());
pFrame = pFrame->GetNext();
}
pColFrame = pColFrame->GetNext();
}
// #i44049#
_rAnchorTextFrame.UnlockJoin();
}
}
// format anchor frame - format of its follow not needed
// #i43255# - forbid follow format, only if anchor text
// frame is in table
if ( _rAnchorTextFrame.IsInTab() )
{
SwForbidFollowFormat aForbidFollowFormat( _rAnchorTextFrame );
_rAnchorTextFrame.Calc(_rAnchorTextFrame.getRootFrame()->GetCurrShell()->GetOut());
}
else
{
_rAnchorTextFrame.Calc(_rAnchorTextFrame.getRootFrame()->GetCurrShell()->GetOut());
}
}
/** method to format the anchor frame for checking of the move forward condition
#i40141#
*/
void SwObjectFormatterTextFrame::FormatAnchorFrameForCheckMoveFwd()
{
SwObjectFormatterTextFrame::FormatAnchorFrameAndItsPrevs( mrAnchorTextFrame );
}
/** method to determine if at least one anchored object has state
<temporarily consider wrapping style influence> set.
*/
bool SwObjectFormatterTextFrame::AtLeastOneObjIsTmpConsiderWrapInfluence()
{
bool bRet( false );
const SwSortedObjs* pObjs = GetAnchorFrame().GetDrawObjs();
if ( pObjs && pObjs->size() > 1 )
{
for (SwAnchoredObject* pAnchoredObj : *pObjs)
{
if ( pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
{
bRet = true;
break;
}
}
}
return bRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|