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 973 974 975 976 977
|
/* -*- 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 "hintids.hxx"
#include <editeng/protitem.hxx>
#include <svx/svdpagv.hxx>
#include <svx/fmmodel.hxx>
#include <sot/exchange.hxx>
#include <svx/sdrundomanager.hxx>
#include <tools/globname.hxx>
#include <editeng/outliner.hxx>
#include <com/sun/star/embed/EmbedMisc.hpp>
#include "swtypes.hxx"
#include "pagefrm.hxx"
#include "rootfrm.hxx"
#include "cntfrm.hxx"
#include "flyfrm.hxx"
#include "frmfmt.hxx"
#include "dflyobj.hxx"
#include "dcontact.hxx"
#include "textboxhelper.hxx"
#include "frmatr.hxx"
#include "viewsh.hxx"
#include "viewimp.hxx"
#include "dview.hxx"
#include "dpage.hxx"
#include "doc.hxx"
#include "mdiexp.hxx"
#include <ndole.hxx>
#include <fmtanchr.hxx>
#include "shellres.hxx"
#include <IDocumentUndoRedo.hxx>
#include <DocumentSettingManager.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <com/sun/star/embed/Aspects.hpp>
#include <vector>
#include <sortedobjs.hxx>
#include <flyfrms.hxx>
#include <UndoManager.hxx>
using namespace com::sun::star;
class SwSdrHdl : public SdrHdl
{
public:
SwSdrHdl(const Point& rPnt, bool bTopRight ) :
SdrHdl( rPnt, bTopRight ? HDL_ANCHOR_TR : HDL_ANCHOR ) {}
virtual bool IsFocusHdl() const override;
};
bool SwSdrHdl::IsFocusHdl() const
{
if( HDL_ANCHOR == eKind || HDL_ANCHOR_TR == eKind )
return true;
return SdrHdl::IsFocusHdl();
}
static const SwFrame *lcl_FindAnchor( const SdrObject *pObj, bool bAll )
{
const SwVirtFlyDrawObj *pVirt = dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) != nullptr ?
static_cast<const SwVirtFlyDrawObj*>(pObj) : nullptr;
if ( pVirt )
{
if ( bAll || !pVirt->GetFlyFrame()->IsFlyInContentFrame() )
return pVirt->GetFlyFrame()->GetAnchorFrame();
}
else
{
const SwDrawContact *pCont = static_cast<const SwDrawContact*>(GetUserCall(pObj));
if ( pCont )
return pCont->GetAnchorFrame( pObj );
}
return nullptr;
}
SwDrawView::SwDrawView( SwViewShellImp &rI, SdrModel *pMd, OutputDevice *pOutDev) :
FmFormView( static_cast<FmFormModel*>(pMd), pOutDev ),
rImp( rI )
{
SetPageVisible( false );
SetBordVisible( false );
SetGridVisible( false );
SetHlplVisible( false );
SetGlueVisible( false );
SetFrameDragSingles();
SetVirtualObjectBundling( true );
SetSwapAsynchron();
EnableExtendedKeyInputDispatcher( false );
EnableExtendedMouseEventDispatcher( false );
EnableExtendedCommandEventDispatcher( false );
SetHitTolerancePixel( GetMarkHdlSizePixel()/2 );
SetPrintPreview( rI.GetShell()->IsPreview() );
// #i73602# Use default from the configuration
SetBufferedOverlayAllowed(getOptionsDrawinglayer().IsOverlayBuffer_Writer());
// #i74769#, #i75172# Use default from the configuration
SetBufferedOutputAllowed(getOptionsDrawinglayer().IsPaintBuffer_Writer());
}
// #i99665#
bool SwDrawView::IsAntiAliasing() const
{
return getOptionsDrawinglayer().IsAntiAliasing();
}
SdrObject* impLocalHitCorrection(SdrObject* pRetval, const Point& rPnt, sal_uInt16 nTol, const SdrMarkList &rMrkList)
{
if(!nTol)
{
// the old method forced back to outer bounds test when nTol == 0, so
// do not try to correct when nTol is not set (used from HelpContent)
}
else
{
// rebuild logic from former SwVirtFlyDrawObj::CheckSdrObjectHit. This is needed since
// the SdrObject-specific CheckHit implementations are now replaced with primitives and
// 'tricks' like in the old implementation (e.g. using a view from a model-data class to
// detect if object is selected) are no longer valid.
// The standard primitive hit-test for SwVirtFlyDrawObj now is the outer bound. The old
// implementation reduced this excluding the inner bound when the object was not selected.
SwVirtFlyDrawObj* pSwVirtFlyDrawObj = dynamic_cast< SwVirtFlyDrawObj* >(pRetval);
if(pSwVirtFlyDrawObj)
{
if(pSwVirtFlyDrawObj->GetFlyFrame()->Lower() && pSwVirtFlyDrawObj->GetFlyFrame()->Lower()->IsNoTextFrame())
{
// the old method used IsNoTextFrame (should be for SW's own OLE and
// graphic's) to accept hit only based on outer bounds; nothing to do
}
else
{
// check if the object is selected in this view
const size_t nMarkCount(rMrkList.GetMarkCount());
bool bSelected(false);
for(size_t a = 0; !bSelected && a < nMarkCount; ++a)
{
if(pSwVirtFlyDrawObj == rMrkList.GetMark(a)->GetMarkedSdrObj())
{
bSelected = true;
}
}
if(!bSelected)
{
// when not selected, the object is not hit when hit position is inside
// inner range. Get and shrink inner range
basegfx::B2DRange aInnerBound(pSwVirtFlyDrawObj->getInnerBound());
aInnerBound.grow(-1.0 * nTol);
if(aInnerBound.isInside(basegfx::B2DPoint(rPnt.X(), rPnt.Y())))
{
// exclude this hit
pRetval = nullptr;
}
}
}
}
}
return pRetval;
}
SdrObject* SwDrawView::CheckSingleSdrObjectHit(const Point& rPnt, sal_uInt16 nTol, SdrObject* pObj, SdrPageView* pPV, SdrSearchOptions nOptions, const SetOfByte* pMVisLay) const
{
// call parent
SdrObject* pRetval = FmFormView::CheckSingleSdrObjectHit(rPnt, nTol, pObj, pPV, nOptions, pMVisLay);
if(pRetval)
{
// override to allow extra handling when picking SwVirtFlyDrawObj's
pRetval = impLocalHitCorrection(pRetval, rPnt, nTol, GetMarkedObjectList());
}
return pRetval;
}
/// Gets called every time the handles need to be build
void SwDrawView::AddCustomHdl()
{
const SdrMarkList &rMrkList = GetMarkedObjectList();
if(rMrkList.GetMarkCount() != 1 || !GetUserCall(rMrkList.GetMark( 0 )->GetMarkedSdrObj()))
return;
SdrObject *pObj = rMrkList.GetMark(0)->GetMarkedSdrObj();
// make code robust
SwFrameFormat* pFrameFormat( ::FindFrameFormat( pObj ) );
if ( !pFrameFormat )
{
OSL_FAIL( "<SwDrawView::AddCustomHdl()> - missing frame format!" );
return;
}
const SwFormatAnchor &rAnchor = pFrameFormat->GetAnchor();
if (FLY_AS_CHAR == rAnchor.GetAnchorId())
return;
const SwFrame* pAnch;
if(nullptr == (pAnch = CalcAnchor()))
return;
Point aPos(aAnchorPoint);
if ( FLY_AT_CHAR == rAnchor.GetAnchorId() )
{
// #i28701# - use last character rectangle saved at object
// in order to avoid a format of the anchor frame
SwAnchoredObject* pAnchoredObj = ::GetUserCall( pObj )->GetAnchoredObj( pObj );
SwRect aAutoPos = pAnchoredObj->GetLastCharRect();
if ( aAutoPos.Height() )
{
aPos = aAutoPos.Pos();
}
}
// add anchor handle:
maHdlList.AddHdl( new SwSdrHdl( aPos, ( pAnch->IsVertical() && !pAnch->IsVertLR() ) ||
pAnch->IsRightToLeft() ) );
}
SdrObject* SwDrawView::GetMaxToTopObj( SdrObject* pObj ) const
{
if ( GetUserCall(pObj) )
{
const SwFrame *pAnch = ::lcl_FindAnchor( pObj, false );
if ( pAnch )
{
//The topmost Obj within the anchor must not be overtaken.
const SwFlyFrame *pFly = pAnch->FindFlyFrame();
if ( pFly )
{
const SwPageFrame *pPage = pFly->FindPageFrame();
if ( pPage->GetSortedObjs() )
{
size_t nOrdNum = 0;
for (SwAnchoredObject* i : *pPage->GetSortedObjs())
{
const SdrObject *pO = i->GetDrawObj();
if ( pO->GetOrdNumDirect() > nOrdNum )
{
const SwFrame *pTmpAnch = ::lcl_FindAnchor( pO, false );
if ( pFly->IsAnLower( pTmpAnch ) )
{
nOrdNum = pO->GetOrdNumDirect();
}
}
}
if ( nOrdNum )
{
SdrPage *pTmpPage = GetModel()->GetPage( 0 );
++nOrdNum;
if ( nOrdNum < pTmpPage->GetObjCount() )
{
return pTmpPage->GetObj( nOrdNum );
}
}
}
}
}
}
return nullptr;
}
SdrObject* SwDrawView::GetMaxToBtmObj(SdrObject* pObj) const
{
if ( GetUserCall(pObj) )
{
const SwFrame *pAnch = ::lcl_FindAnchor( pObj, false );
if ( pAnch )
{
//The Fly of the anchor must not be "flying under".
const SwFlyFrame *pFly = pAnch->FindFlyFrame();
if ( pFly )
{
SdrObject *pRet = const_cast<SdrObject*>(static_cast<SdrObject const *>(pFly->GetVirtDrawObj()));
return pRet != pObj ? pRet : nullptr;
}
}
}
return nullptr;
}
/// determine maximal order number for a 'child' object of given 'parent' object
sal_uInt32 SwDrawView::GetMaxChildOrdNum( const SwFlyFrame& _rParentObj,
const SdrObject* _pExclChildObj )
{
sal_uInt32 nMaxChildOrdNum = _rParentObj.GetDrawObj()->GetOrdNum();
const SdrPage* pDrawPage = _rParentObj.GetDrawObj()->GetPage();
OSL_ENSURE( pDrawPage,
"<SwDrawView::GetMaxChildOrdNum(..) - missing drawing page at parent object - crash!" );
const size_t nObjCount = pDrawPage->GetObjCount();
for ( size_t i = nObjCount-1; i > _rParentObj.GetDrawObj()->GetOrdNum() ; --i )
{
const SdrObject* pObj = pDrawPage->GetObj( i );
// Don't consider 'child' object <_pExclChildObj>
if ( pObj == _pExclChildObj )
{
continue;
}
if ( pObj->GetOrdNum() > nMaxChildOrdNum &&
_rParentObj.IsAnLower( lcl_FindAnchor( pObj, true ) ) )
{
nMaxChildOrdNum = pObj->GetOrdNum();
break;
}
}
return nMaxChildOrdNum;
}
/// method to move 'repeated' objects of the given moved object to the according level
void SwDrawView::MoveRepeatedObjs( const SwAnchoredObject& _rMovedAnchoredObj,
const std::vector<SdrObject*>& _rMovedChildObjs ) const
{
// determine 'repeated' objects of already moved object <_rMovedAnchoredObj>
std::list<SwAnchoredObject*> aAnchoredObjs;
{
const SwContact* pContact = ::GetUserCall( _rMovedAnchoredObj.GetDrawObj() );
assert(pContact && "SwDrawView::MoveRepeatedObjs(..) - missing contact object -> crash.");
pContact->GetAnchoredObjs( aAnchoredObjs );
}
// check, if 'repeated' objects exists.
if ( aAnchoredObjs.size() > 1 )
{
SdrPage* pDrawPage = GetModel()->GetPage( 0 );
// move 'repeated' ones to the same order number as the already moved one.
const size_t nNewPos = _rMovedAnchoredObj.GetDrawObj()->GetOrdNum();
while ( !aAnchoredObjs.empty() )
{
SwAnchoredObject* pAnchoredObj = aAnchoredObjs.back();
if ( pAnchoredObj != &_rMovedAnchoredObj )
{
pDrawPage->SetObjectOrdNum( pAnchoredObj->GetDrawObj()->GetOrdNum(),
nNewPos );
pDrawPage->RecalcObjOrdNums();
// adjustments for accessibility API
if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) != nullptr )
{
const SwFlyFrame *pTmpFlyFrame = static_cast<SwFlyFrame*>(pAnchoredObj);
rImp.DisposeAccessibleFrame( pTmpFlyFrame );
rImp.AddAccessibleFrame( pTmpFlyFrame );
}
else
{
rImp.DisposeAccessibleObj( pAnchoredObj->GetDrawObj() );
rImp.AddAccessibleObj( pAnchoredObj->GetDrawObj() );
}
}
aAnchoredObjs.pop_back();
}
// move 'repeated' ones of 'child' objects
for ( std::vector<SdrObject*>::const_iterator aObjIter = _rMovedChildObjs.begin();
aObjIter != _rMovedChildObjs.end(); ++aObjIter )
{
SdrObject* pChildObj = (*aObjIter);
{
const SwContact* pContact = ::GetUserCall( pChildObj );
assert(pContact && "SwDrawView::MoveRepeatedObjs(..) - missing contact object -> crash.");
pContact->GetAnchoredObjs( aAnchoredObjs );
}
// move 'repeated' ones to the same order number as the already moved one.
const size_t nTmpNewPos = pChildObj->GetOrdNum();
while ( !aAnchoredObjs.empty() )
{
SwAnchoredObject* pAnchoredObj = aAnchoredObjs.back();
if ( pAnchoredObj->GetDrawObj() != pChildObj )
{
pDrawPage->SetObjectOrdNum( pAnchoredObj->GetDrawObj()->GetOrdNum(),
nTmpNewPos );
pDrawPage->RecalcObjOrdNums();
// adjustments for accessibility API
if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) != nullptr )
{
const SwFlyFrame *pTmpFlyFrame = static_cast<SwFlyFrame*>(pAnchoredObj);
rImp.DisposeAccessibleFrame( pTmpFlyFrame );
rImp.AddAccessibleFrame( pTmpFlyFrame );
}
else
{
rImp.DisposeAccessibleObj( pAnchoredObj->GetDrawObj() );
rImp.AddAccessibleObj( pAnchoredObj->GetDrawObj() );
}
}
aAnchoredObjs.pop_back();
}
}
}
}
// --> adjustment and re-factoring of method
void SwDrawView::ObjOrderChanged( SdrObject* pObj, sal_uLong nOldPos,
sal_uLong nNewPos )
{
// nothing to do for group members
if ( pObj->GetUpGroup() )
{
return;
}
// determine drawing page and assure that the order numbers are correct.
SdrPage* pDrawPage = GetModel()->GetPage( 0 );
if ( pDrawPage->IsObjOrdNumsDirty() )
pDrawPage->RecalcObjOrdNums();
const size_t nObjCount = pDrawPage->GetObjCount();
SwAnchoredObject* pMovedAnchoredObj =
::GetUserCall( pObj )->GetAnchoredObj( pObj );
const SwFlyFrame* pParentAnchoredObj =
pMovedAnchoredObj->GetAnchorFrame()->FindFlyFrame();
const bool bMovedForward = nOldPos < nNewPos;
// assure for a 'child' object, that it doesn't exceed the limits of its 'parent'
if ( pParentAnchoredObj )
{
if ( bMovedForward )
{
const size_t nMaxChildOrdNumWithoutMoved =
GetMaxChildOrdNum( *pParentAnchoredObj, pMovedAnchoredObj->GetDrawObj() );
if ( nNewPos > nMaxChildOrdNumWithoutMoved+1 )
{
// set position to the top of the 'child' object group
pDrawPage->SetObjectOrdNum( nNewPos, nMaxChildOrdNumWithoutMoved+1 );
nNewPos = nMaxChildOrdNumWithoutMoved+1;
}
}
else
{
const size_t nParentOrdNum = pParentAnchoredObj->GetDrawObj()->GetOrdNum();
if ( nNewPos < nParentOrdNum )
{
// set position to the bottom of the 'child' object group
pDrawPage->SetObjectOrdNum( nNewPos, nParentOrdNum );
nNewPos = nParentOrdNum;
}
}
if ( pDrawPage->IsObjOrdNumsDirty() )
pDrawPage->RecalcObjOrdNums();
}
// Assure, that object isn't positioned between 'repeated' ones
if ( ( bMovedForward && nNewPos < nObjCount - 1 ) ||
( !bMovedForward && nNewPos > 0 ) )
{
const SdrObject* pTmpObj =
pDrawPage->GetObj( bMovedForward ? nNewPos - 1 : nNewPos + 1 );
if ( pTmpObj )
{
size_t nTmpNewPos( nNewPos );
if ( bMovedForward )
{
// move before the top 'repeated' object
const sal_uInt32 nTmpMaxOrdNum =
::GetUserCall( pTmpObj )->GetMaxOrdNum();
if ( nTmpMaxOrdNum > nNewPos )
nTmpNewPos = nTmpMaxOrdNum;
}
else
{
// move behind the bottom 'repeated' object
const sal_uInt32 nTmpMinOrdNum =
::GetUserCall( pTmpObj )->GetMinOrdNum();
if ( nTmpMinOrdNum < nNewPos )
nTmpNewPos = nTmpMinOrdNum;
}
if ( nTmpNewPos != nNewPos )
{
pDrawPage->SetObjectOrdNum( nNewPos, nTmpNewPos );
nNewPos = nTmpNewPos;
pDrawPage->RecalcObjOrdNums();
}
}
}
// On move forward, assure that object is moved before its own children.
// Only Writer fly frames can have children.
if ( dynamic_cast< const SwFlyFrame *>( pMovedAnchoredObj ) != nullptr &&
bMovedForward && nNewPos < nObjCount - 1 )
{
sal_uInt32 nMaxChildOrdNum =
GetMaxChildOrdNum( *(static_cast<const SwFlyFrame*>(pMovedAnchoredObj)) );
if ( nNewPos < nMaxChildOrdNum )
{
// determine position before the object before its top 'child' object
const SdrObject* pTmpObj = pDrawPage->GetObj( nMaxChildOrdNum );
size_t nTmpNewPos = ::GetUserCall( pTmpObj )->GetMaxOrdNum() + 1;
if ( nTmpNewPos >= nObjCount )
{
--nTmpNewPos;
}
// assure, that determined position isn't between 'repeated' objects
pTmpObj = pDrawPage->GetObj( nTmpNewPos );
nTmpNewPos = ::GetUserCall( pTmpObj )->GetMaxOrdNum();
// apply new position
pDrawPage->SetObjectOrdNum( nNewPos, nTmpNewPos );
nNewPos = nTmpNewPos;
pDrawPage->RecalcObjOrdNums();
}
}
// Assure, that object isn't positioned between nested objects
if ( ( bMovedForward && nNewPos < nObjCount - 1 ) ||
( !bMovedForward && nNewPos > 0 ) )
{
size_t nTmpNewPos( nNewPos );
const SwFrameFormat* pParentFrameFormat =
pParentAnchoredObj ? &(pParentAnchoredObj->GetFrameFormat()) : nullptr;
const SdrObject* pTmpObj = pDrawPage->GetObj( nNewPos + 1 );
while ( pTmpObj )
{
// #i38563# - assure, that anchor frame exists.
// If object is anchored inside a invisible part of the document
// (e.g. page header, whose page style isn't applied, or hidden
// section), no anchor frame exists.
const SwFrame* pTmpAnchorFrame = lcl_FindAnchor( pTmpObj, true );
const SwFlyFrame* pTmpParentObj = pTmpAnchorFrame
? pTmpAnchorFrame->FindFlyFrame() : nullptr;
if ( pTmpParentObj &&
&(pTmpParentObj->GetFrameFormat()) != pParentFrameFormat )
{
if ( bMovedForward )
{
nTmpNewPos = ::GetUserCall( pTmpObj )->GetMaxOrdNum();
pTmpObj = pDrawPage->GetObj( nTmpNewPos + 1 );
}
else
{
nTmpNewPos = ::GetUserCall( pTmpParentObj->GetDrawObj() )
->GetMinOrdNum();
pTmpObj = pTmpParentObj->GetDrawObj();
}
}
else
break;
}
if ( nTmpNewPos != nNewPos )
{
pDrawPage->SetObjectOrdNum( nNewPos, nTmpNewPos );
nNewPos = nTmpNewPos;
pDrawPage->RecalcObjOrdNums();
}
}
// setup collection of moved 'child' objects to move its 'repeated' objects.
std::vector< SdrObject* > aMovedChildObjs;
// move 'children' accordingly
if ( dynamic_cast< const SwFlyFrame *>( pMovedAnchoredObj ) != nullptr )
{
const SwFlyFrame* pFlyFrame = static_cast<SwFlyFrame*>(pMovedAnchoredObj);
// adjustments for accessibility API
rImp.DisposeAccessibleFrame( pFlyFrame );
rImp.AddAccessibleFrame( pFlyFrame );
const sal_uInt32 nChildNewPos = bMovedForward ? nNewPos : nNewPos+1;
size_t i = bMovedForward ? nOldPos : nObjCount-1;
do
{
SdrObject* pTmpObj = pDrawPage->GetObj( i );
if ( pTmpObj == pObj )
break;
// #i38563# - assure, that anchor frame exists.
// If object is anchored inside a invisible part of the document
// (e.g. page header, whose page style isn't applied, or hidden
// section), no anchor frame exists.
const SwFrame* pTmpAnchorFrame = lcl_FindAnchor( pTmpObj, true );
const SwFlyFrame* pTmpParentObj = pTmpAnchorFrame
? pTmpAnchorFrame->FindFlyFrame() : nullptr;
if ( pTmpParentObj &&
( ( pTmpParentObj == pFlyFrame ) ||
( pFlyFrame->IsUpperOf( *pTmpParentObj ) ) ) )
{
// move child object.,
pDrawPage->SetObjectOrdNum( i, nChildNewPos );
pDrawPage->RecalcObjOrdNums();
// collect 'child' object
aMovedChildObjs.push_back( pTmpObj );
// adjustments for accessibility API
if ( dynamic_cast< const SwVirtFlyDrawObj *>( pTmpObj ) != nullptr )
{
const SwFlyFrame *pTmpFlyFrame =
static_cast<SwVirtFlyDrawObj*>(pTmpObj)->GetFlyFrame();
rImp.DisposeAccessibleFrame( pTmpFlyFrame );
rImp.AddAccessibleFrame( pTmpFlyFrame );
}
else
{
rImp.DisposeAccessibleObj( pTmpObj );
rImp.AddAccessibleObj( pTmpObj );
}
}
else
{
// adjust loop counter
if ( bMovedForward )
++i;
else if ( !bMovedForward && i > 0 )
--i;
}
} while ( ( bMovedForward && i < ( nObjCount - aMovedChildObjs.size() ) ) ||
( !bMovedForward && i > ( nNewPos + aMovedChildObjs.size() ) ) );
}
else
{
// adjustments for accessibility API
rImp.DisposeAccessibleObj( pObj );
rImp.AddAccessibleObj( pObj );
}
MoveRepeatedObjs( *pMovedAnchoredObj, aMovedChildObjs );
}
bool SwDrawView::TakeDragLimit( SdrDragMode eMode,
Rectangle& rRect ) const
{
const SdrMarkList &rMrkList = GetMarkedObjectList();
bool bRet = false;
if( 1 == rMrkList.GetMarkCount() )
{
const SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
SwRect aRect;
if( ::CalcClipRect( pObj, aRect, eMode == SDRDRAG_MOVE ) )
{
rRect = aRect.SVRect();
bRet = true;
}
}
return bRet;
}
const SwFrame* SwDrawView::CalcAnchor()
{
const SdrMarkList &rMrkList = GetMarkedObjectList();
if ( rMrkList.GetMarkCount() != 1 )
return nullptr;
SdrObject* pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
//Search for paragraph bound objects, otherwise only the
//current anchor. Search only if we currently drag.
const SwFrame* pAnch;
Rectangle aMyRect;
const bool bFly = dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) != nullptr;
if ( bFly )
{
pAnch = static_cast<SwVirtFlyDrawObj*>(pObj)->GetFlyFrame()->GetAnchorFrame();
aMyRect = static_cast<SwVirtFlyDrawObj*>(pObj)->GetFlyFrame()->Frame().SVRect();
}
else
{
SwDrawContact *pC = static_cast<SwDrawContact*>(GetUserCall(pObj));
// determine correct anchor position for 'virtual' drawing objects.
// #i26791#
pAnch = pC->GetAnchorFrame( pObj );
if( !pAnch )
{
pC->ConnectToLayout();
// determine correct anchor position for 'virtual' drawing objects.
// #i26791#
pAnch = pC->GetAnchorFrame( pObj );
}
aMyRect = pObj->GetSnapRect();
}
const bool bTopRight = pAnch && ( ( pAnch->IsVertical() &&
!pAnch->IsVertLR() ) ||
pAnch->IsRightToLeft() );
const Point aMyPt = bTopRight ? aMyRect.TopRight() : aMyRect.TopLeft();
Point aPt;
if ( IsAction() )
{
if ( !TakeDragObjAnchorPos( aPt, bTopRight ) )
return nullptr;
}
else
{
Rectangle aRect = pObj->GetSnapRect();
aPt = bTopRight ? aRect.TopRight() : aRect.TopLeft();
}
if ( aPt != aMyPt )
{
if ( pAnch && pAnch->IsContentFrame() )
{
// allow drawing objects in header/footer,
// but exclude control objects.
bool bBodyOnly = CheckControlLayer( pObj );
pAnch = ::FindAnchor( static_cast<const SwContentFrame*>(pAnch), aPt, bBodyOnly );
}
else if ( !bFly )
{
const SwRect aRect( aPt.getX(), aPt.getY(), 1, 1 );
SwDrawContact* pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
if ( pContact->GetAnchorFrame( pObj ) &&
pContact->GetAnchorFrame( pObj )->IsPageFrame() )
pAnch = pContact->GetPageFrame();
else
pAnch = pContact->FindPage( aRect );
}
}
if( pAnch && !pAnch->IsProtected() )
aAnchorPoint = pAnch->GetFrameAnchorPos( ::HasWrap( pObj ) );
else
pAnch = nullptr;
return pAnch;
}
void SwDrawView::ShowDragAnchor()
{
SdrHdl* pHdl = maHdlList.GetHdl(HDL_ANCHOR);
if ( ! pHdl )
pHdl = maHdlList.GetHdl(HDL_ANCHOR_TR);
if(pHdl)
{
CalcAnchor();
pHdl->SetPos(aAnchorPoint);
}
}
void SwDrawView::MarkListHasChanged()
{
Imp().GetShell()->DrawSelChanged();
FmFormView::MarkListHasChanged();
}
// #i7672#
void SwDrawView::ModelHasChanged()
{
// The ModelHasChanged() call in DrawingLayer also updates
// a eventually active text edit view (OutlinerView). This also leads
// to newly setting the background color for that edit view. Thus,
// this method rescues the current background color if a OutlinerView
// exists and re-establishes it then. To be more safe, the OutlinerView
// will be fetched again (maybe textedit has ended).
OutlinerView* pView = GetTextEditOutlinerView();
Color aBackColor;
bool bColorWasSaved(false);
if(pView)
{
aBackColor = pView->GetBackgroundColor();
bColorWasSaved = true;
}
// call parent
FmFormView::ModelHasChanged();
if(bColorWasSaved)
{
pView = GetTextEditOutlinerView();
if(pView)
{
pView->SetBackgroundColor(aBackColor);
}
}
}
void SwDrawView::MakeVisible( const Rectangle &rRect, vcl::Window & )
{
OSL_ENSURE( rImp.GetShell()->GetWin(), "MakeVisible, unknown Window");
rImp.GetShell()->MakeVisible( SwRect( rRect ) );
}
void SwDrawView::CheckPossibilities()
{
FmFormView::CheckPossibilities();
//In addition to the existing flags of the objects themselves,
//which are evaluated by the DrawingEngine, other circumstances
//lead to a protection.
//Objects that are anchored in frames need to be protected
//if the content of the frame is protected.
//OLE-Objects may themselves wish a resize protection (StarMath)
const SdrMarkList &rMrkList = GetMarkedObjectList();
bool bProtect = false;
bool bSzProtect = false;
for ( size_t i = 0; !bProtect && i < rMrkList.GetMarkCount(); ++i )
{
const SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
const SwFrame *pFrame = nullptr;
if ( dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) != nullptr )
{
const SwFlyFrame *pFly = static_cast<const SwVirtFlyDrawObj*>(pObj)->GetFlyFrame();
if ( pFly )
{
pFrame = pFly->GetAnchorFrame();
if ( pFly->Lower() && pFly->Lower()->IsNoTextFrame() )
{
SwOLENode *pNd = const_cast<SwContentFrame*>(static_cast<const SwContentFrame*>(pFly->Lower()))->GetNode()->GetOLENode();
if ( pNd )
{
uno::Reference < embed::XEmbeddedObject > xObj = pNd->GetOLEObj().GetOleRef();
if ( xObj.is() )
{
// --> improvement for the future, when more
// than one Writer fly frame can be selected.
// TODO/LATER: retrieve Aspect - from where?!
bSzProtect |= ( embed::EmbedMisc::EMBED_NEVERRESIZE & xObj->getStatus( embed::Aspects::MSOLE_CONTENT ) ) != 0;
// #i972: protect position if it is a Math object anchored 'as char' and baseline alignment is activated
SwDoc* pDoc = Imp().GetShell()->GetDoc();
const bool bProtectMathPos = SotExchange::IsMath( xObj->getClassID() )
&& FLY_AS_CHAR == pFly->GetFormat()->GetAnchor().GetAnchorId()
&& pDoc->GetDocumentSettingManager().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT );
if (bProtectMathPos)
bMoveProtect = true;
}
}
}
}
}
else
{
SwDrawContact *pC = static_cast<SwDrawContact*>(GetUserCall(pObj));
if ( pC )
pFrame = pC->GetAnchorFrame( pObj );
}
if ( pFrame )
bProtect = pFrame->IsProtected(); //Frames, areas etc.
{
SwFrameFormat* pFrameFormat( ::FindFrameFormat( const_cast<SdrObject*>(pObj) ) );
if ( !pFrameFormat )
{
OSL_FAIL( "<SwDrawView::CheckPossibilities()> - missing frame format" );
bProtect = true;
}
else if ((FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId()) &&
rMrkList.GetMarkCount() > 1 )
{
bProtect = true;
}
}
}
bMoveProtect |= bProtect;
bResizeProtect |= bProtect || bSzProtect;
}
/// replace marked <SwDrawVirtObj>-objects by its reference object for delete marked objects.
void SwDrawView::ReplaceMarkedDrawVirtObjs( SdrMarkView& _rMarkView )
{
SdrPageView* pDrawPageView = _rMarkView.GetSdrPageView();
const SdrMarkList& rMarkList = _rMarkView.GetMarkedObjectList();
if( rMarkList.GetMarkCount() )
{
// collect marked objects in a local data structure
std::vector<SdrObject*> aMarkedObjs;
for( size_t i = 0; i < rMarkList.GetMarkCount(); ++i )
{
SdrObject* pMarkedObj = rMarkList.GetMark( i )->GetMarkedSdrObj();
aMarkedObjs.push_back( pMarkedObj );
}
// unmark all objects
_rMarkView.UnmarkAllObj();
// re-mark objects, but for marked <SwDrawVirtObj>-objects marked its
// reference object.
while ( !aMarkedObjs.empty() )
{
SdrObject* pMarkObj = aMarkedObjs.back();
if ( dynamic_cast< const SwDrawVirtObj *>( pMarkObj ) != nullptr )
{
SdrObject* pRefObj = &(static_cast<SwDrawVirtObj*>(pMarkObj)->ReferencedObj());
if ( !_rMarkView.IsObjMarked( pRefObj ) )
{
_rMarkView.MarkObj( pRefObj, pDrawPageView );
}
}
else
{
_rMarkView.MarkObj( pMarkObj, pDrawPageView );
}
aMarkedObjs.pop_back();
}
// sort marked list in order to assure consistent state in drawing layer
_rMarkView.SortMarkedObjects();
}
}
void SwDrawView::DeleteMarked()
{
SwDoc* pDoc = Imp().GetShell()->GetDoc();
SwRootFrame *pTmpRoot = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
if ( pTmpRoot )
pTmpRoot->StartAllAction();
pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_EMPTY, nullptr);
// replace marked <SwDrawVirtObj>-objects by its reference objects.
{
SdrPageView* pDrawPageView = rImp.GetPageView();
if ( pDrawPageView )
{
SdrMarkView* pMarkView = &(pDrawPageView->GetView());
if ( pMarkView )
{
ReplaceMarkedDrawVirtObjs( *pMarkView );
}
}
}
// Check what textboxes have to be deleted afterwards.
const SdrMarkList& rMarkList = GetMarkedObjectList();
std::vector<SwFrameFormat*> aTextBoxesToDelete;
for (size_t i = 0; i < rMarkList.GetMarkCount(); ++i)
{
SdrObject *pObject = rMarkList.GetMark(i)->GetMarkedSdrObj();
SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(GetUserCall(pObject));
SwFrameFormat* pFormat = pDrawContact->GetFormat();
if (SwFrameFormat* pTextBox = SwTextBoxHelper::findTextBox(pFormat))
aTextBoxesToDelete.push_back(pTextBox);
}
if ( pDoc->DeleteSelection( *this ) )
{
FmFormView::DeleteMarked();
::FrameNotify( Imp().GetShell(), FLY_DRAG_END );
// Only delete these now: earlier deletion would clear the mark list as well.
for (std::vector<SwFrameFormat*>::iterator i = aTextBoxesToDelete.begin(); i != aTextBoxesToDelete.end(); ++i)
pDoc->getIDocumentLayoutAccess().DelLayoutFormat(*i);
}
pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_EMPTY, nullptr);
if( pTmpRoot )
pTmpRoot->EndAllAction();
}
// support enhanced text edit for draw objects
SdrUndoManager* SwDrawView::getSdrUndoManagerForEnhancedTextEdit() const
{
SwDoc* pDoc = Imp().GetShell()->GetDoc();
return pDoc ? dynamic_cast< SdrUndoManager* >(&(pDoc->GetUndoManager())) : nullptr;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|