LCOV - code coverage report
Current view: top level - sw/source/core/frmedt - fecopy.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 117 820 14.3 %
Date: 2015-06-13 12:38:46 Functions: 4 13 30.8 %
Legend: Lines: hit not hit

          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 <hintids.hxx>
      21             : 
      22             : #include <vcl/graph.hxx>
      23             : #include <sot/formats.hxx>
      24             : #include <sot/storage.hxx>
      25             : #include <unotools/pathoptions.hxx>
      26             : #include <sfx2/dispatch.hxx>
      27             : #include <sfx2/docfile.hxx>
      28             : #include <sfx2/viewsh.hxx>
      29             : #include <svx/xexch.hxx>
      30             : #include <svx/xflasit.hxx>
      31             : #include <svx/xfillit0.hxx>
      32             : #include <svx/xflclit.hxx>
      33             : #include <editeng/brushitem.hxx>
      34             : #include <svx/svdocapt.hxx>
      35             : #include <svx/svdouno.hxx>
      36             : #include <svx/xfillit.hxx>
      37             : #include <svx/svdpage.hxx>
      38             : #include <svx/svdogrp.hxx>
      39             : #include <svx/xoutbmp.hxx>
      40             : #include <svx/svdoole2.hxx>
      41             : #include <svx/fmmodel.hxx>
      42             : #include <svx/unomodel.hxx>
      43             : #include <svx/svditer.hxx>
      44             : #include <svx/svdograf.hxx>
      45             : #include <unotools/streamwrap.hxx>
      46             : #include <fmtanchr.hxx>
      47             : #include <fmtcntnt.hxx>
      48             : #include <fmtornt.hxx>
      49             : #include <fmtflcnt.hxx>
      50             : #include <frmfmt.hxx>
      51             : #include <docary.hxx>
      52             : #include <txtfrm.hxx>
      53             : #include <txtflcnt.hxx>
      54             : #include <fesh.hxx>
      55             : #include <doc.hxx>
      56             : #include <IDocumentUndoRedo.hxx>
      57             : #include <IDocumentDrawModelAccess.hxx>
      58             : #include <IDocumentRedlineAccess.hxx>
      59             : #include <DocumentFieldsManager.hxx>
      60             : #include <IDocumentLayoutAccess.hxx>
      61             : #include <rootfrm.hxx>
      62             : #include <ndtxt.hxx>
      63             : #include <pam.hxx>
      64             : #include <tblsel.hxx>
      65             : #include <swtable.hxx>
      66             : #include <flyfrm.hxx>
      67             : #include <pagefrm.hxx>
      68             : #include <fldbas.hxx>
      69             : #include <edimp.hxx>
      70             : #include <swundo.hxx>
      71             : #include <viewimp.hxx>
      72             : #include <dview.hxx>
      73             : #include <dcontact.hxx>
      74             : #include <dflyobj.hxx>
      75             : #include <docsh.hxx>
      76             : #include <pagedesc.hxx>
      77             : #include <mvsave.hxx>
      78             : #include <textboxhelper.hxx>
      79             : #include <vcl/virdev.hxx>
      80             : #include <svx/svdundo.hxx>
      81             : 
      82             : using namespace ::com::sun::star;
      83             : 
      84             : // Copy for the internal clipboard. Copies all selections to the clipboard.
      85           3 : bool SwFEShell::Copy( SwDoc* pClpDoc, const OUString* pNewClpText )
      86             : {
      87             :     OSL_ENSURE( pClpDoc, "kein Clipboard-Dokument"  );
      88             : 
      89           3 :     pClpDoc->GetIDocumentUndoRedo().DoUndo(false); // always false!
      90             : 
      91             :     // delete content if ClpDocument contains content
      92           3 :     SwNodeIndex aSttIdx( pClpDoc->GetNodes().GetEndOfExtras(), 2 );
      93           3 :     SwTextNode* pTextNd = aSttIdx.GetNode().GetTextNode();
      94           6 :     if (!pTextNd || !pTextNd->GetText().isEmpty() ||
      95           3 :         aSttIdx.GetIndex()+1 != pClpDoc->GetNodes().GetEndOfContent().GetIndex() )
      96             :     {
      97           0 :         pClpDoc->GetNodes().Delete( aSttIdx,
      98           0 :             pClpDoc->GetNodes().GetEndOfContent().GetIndex() - aSttIdx.GetIndex() );
      99           0 :         pTextNd = pClpDoc->GetNodes().MakeTextNode( aSttIdx,
     100           0 :                             pClpDoc->GetDfltTextFormatColl() );
     101           0 :         --aSttIdx;
     102             :     }
     103             : 
     104             :     // also delete surrounding FlyFrames if any
     105           3 :     for( auto pFormat : *pClpDoc->GetSpzFrameFormats() )
     106             :     {
     107           0 :         SwFlyFrameFormat* pFly = static_cast<SwFlyFrameFormat*>(pFormat);
     108           0 :         pClpDoc->getIDocumentLayoutAccess().DelLayoutFormat( pFly );
     109             :     }
     110           3 :     pClpDoc->GetDocumentFieldsManager().GCFieldTypes();        // delete the FieldTypes
     111             : 
     112             :     // if a string was passed, copy it to the clipboard-
     113             :     // document. Then also the Calculator can use the internal
     114             :     // clipboard
     115           3 :     if( pNewClpText )
     116             :     {
     117           0 :         pTextNd->InsertText( *pNewClpText, SwIndex( pTextNd ) );
     118           0 :         return true;                // das wars.
     119             :     }
     120             : 
     121           3 :     pClpDoc->getIDocumentFieldsAccess().LockExpFields();
     122           3 :     pClpDoc->getIDocumentRedlineAccess().SetRedlineMode_intern( nsRedlineMode_t::REDLINE_DELETE_REDLINES );
     123             :     bool bRet;
     124             : 
     125             :     // do we want to copy a FlyFrame?
     126           3 :     if( IsFrmSelected() )
     127             :     {
     128             :         // get the FlyFormat
     129           0 :         SwFlyFrm* pFly = FindFlyFrm();
     130           0 :         SwFrameFormat* pFlyFormat = pFly->GetFormat();
     131           0 :         SwFormatAnchor aAnchor( pFlyFormat->GetAnchor() );
     132             : 
     133           0 :         if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     134           0 :             (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     135           0 :             (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     136           0 :             (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     137             :         {
     138           0 :             SwPosition aPos( aSttIdx );
     139           0 :             if ( FLY_AS_CHAR == aAnchor.GetAnchorId() )
     140             :             {
     141           0 :                 aPos.nContent.Assign( pTextNd, 0 );
     142             :             }
     143           0 :             aAnchor.SetAnchor( &aPos );
     144             :         }
     145           0 :         pFlyFormat = pClpDoc->getIDocumentLayoutAccess().CopyLayoutFormat( *pFlyFormat, aAnchor, true, true );
     146             : 
     147             :        // assure the "RootFormat" is the first element in Spz-Array
     148             :         // (if necessary Flys were copied in Flys)
     149           0 :         SwFrameFormats& rSpzFrameFormats = *pClpDoc->GetSpzFrameFormats();
     150           0 :         if( rSpzFrameFormats[ 0 ] != pFlyFormat )
     151             :         {
     152           0 :             SwFrameFormats::iterator it = std::find( rSpzFrameFormats.begin(), rSpzFrameFormats.end(), pFlyFormat );
     153             :             OSL_ENSURE( it != rSpzFrameFormats.end(), "Fly not contained in Spz-Array" );
     154             : 
     155           0 :             rSpzFrameFormats.erase( it );
     156           0 :             rSpzFrameFormats.insert( rSpzFrameFormats.begin(), pFlyFormat );
     157             :         }
     158             : 
     159           0 :         if ( FLY_AS_CHAR == aAnchor.GetAnchorId() )
     160             :         {
     161             :             // JP 13.02.99  Bug 61863: if a frameselection is passed to the
     162             :             //              clipboard, it should be found at pasting. Therefore
     163             :             //              the copied TextAttribut should be removed in the node
     164             :             //              otherwise it will be recognised as TextSelektion
     165           0 :             const SwIndex& rIdx = pFlyFormat->GetAnchor().GetContentAnchor()->nContent;
     166             :             SwTextFlyCnt *const pTextFly = static_cast<SwTextFlyCnt *>(
     167             :                 pTextNd->GetTextAttrForCharAt(
     168           0 :                     rIdx.GetIndex(), RES_TXTATR_FLYCNT));
     169           0 :             if( pTextFly )
     170             :             {
     171           0 :                 const_cast<SwFormatFlyCnt&>(pTextFly->GetFlyCnt()).SetFlyFormat( 0 );
     172           0 :                 pTextNd->EraseText( rIdx, 1 );
     173             :             }
     174             :         }
     175           0 :         bRet = true;
     176             :     }
     177           3 :     else if ( IsObjSelected() )
     178             :     {
     179           1 :         SwPosition aPos( aSttIdx, SwIndex( pTextNd, 0 ));
     180           1 :         const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
     181           2 :         for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
     182             :         {
     183           1 :             SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
     184             : 
     185           2 :             if( Imp()->GetDrawView()->IsGroupEntered() ||
     186           1 :                 ( !pObj->GetUserCall() && pObj->GetUpGroup()) )
     187             :             {
     188           0 :                 SfxItemSet aSet( pClpDoc->GetAttrPool(), aFrameFormatSetRange );
     189             : 
     190           0 :                 SwFormatAnchor aAnchor( FLY_AT_PARA );
     191           0 :                 aAnchor.SetAnchor( &aPos );
     192           0 :                 aSet.Put( aAnchor );
     193             : 
     194             :                 SdrObject *const pNew =
     195           0 :                     pClpDoc->CloneSdrObj( *pObj, false, true );
     196             : 
     197           0 :                 SwPaM aTemp(aPos);
     198           0 :                 pClpDoc->getIDocumentContentOperations().InsertDrawObj(aTemp, *pNew, aSet );
     199             :             }
     200             :             else
     201             :             {
     202           1 :                 SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall( pObj ));
     203           1 :                 SwFrameFormat *pFormat = pContact->GetFormat();
     204           1 :                 SwFormatAnchor aAnchor( pFormat->GetAnchor() );
     205           2 :                 if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     206           0 :                     (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     207           1 :                     (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     208           0 :                     (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     209             :                 {
     210           1 :                     aAnchor.SetAnchor( &aPos );
     211             :                 }
     212             : 
     213           1 :                 pClpDoc->getIDocumentLayoutAccess().CopyLayoutFormat( *pFormat, aAnchor, true, true );
     214             :             }
     215             :         }
     216           1 :         bRet = true;
     217             :     }
     218             :     else
     219           2 :         bRet = _CopySelToDoc( pClpDoc, 0 );     // copy the selections
     220             : 
     221           3 :     pClpDoc->getIDocumentRedlineAccess().SetRedlineMode_intern((RedlineMode_t)0 );
     222           3 :     pClpDoc->getIDocumentFieldsAccess().UnlockExpFields();
     223           3 :     if( !pClpDoc->getIDocumentFieldsAccess().IsExpFieldsLocked() )
     224           2 :         pClpDoc->getIDocumentFieldsAccess().UpdateExpFields(NULL, true);
     225             : 
     226           3 :     return bRet;
     227             : }
     228             : 
     229           0 : static const Point &lcl_FindBasePos( const SwFrm *pFrm, const Point &rPt )
     230             : {
     231           0 :     const SwFrm *pF = pFrm;
     232           0 :     while ( pF && !pF->Frm().IsInside( rPt ) )
     233             :     {
     234           0 :         if ( pF->IsContentFrm() )
     235           0 :             pF = static_cast<const SwContentFrm*>(pF)->GetFollow();
     236             :         else
     237           0 :             pF = 0;
     238             :     }
     239           0 :     if ( pF )
     240           0 :         return pF->Frm().Pos();
     241             :     else
     242           0 :         return pFrm->Frm().Pos();
     243             : }
     244             : 
     245           0 : static bool lcl_SetAnchor( const SwPosition& rPos, const SwNode& rNd, SwFlyFrm* pFly,
     246             :                 const Point& rInsPt, SwFEShell& rDestShell, SwFormatAnchor& rAnchor,
     247             :                 Point& rNewPos, bool bCheckFlyRecur )
     248             : {
     249           0 :     bool bRet = true;
     250           0 :     rAnchor.SetAnchor( &rPos );
     251           0 :     SwContentFrm* pTmpFrm = rNd.GetContentNode()->getLayoutFrm( rDestShell.GetLayout(), &rInsPt, 0, false );
     252           0 :     SwFlyFrm *pTmpFly = pTmpFrm->FindFlyFrm();
     253           0 :     if( pTmpFly && bCheckFlyRecur && pFly->IsUpperOf( *pTmpFly ) )
     254             :     {
     255           0 :         bRet = false;
     256             :     }
     257           0 :     else if ( FLY_AT_FLY == rAnchor.GetAnchorId() )
     258             :     {
     259           0 :         if( pTmpFly )
     260             :         {
     261           0 :             const SwNodeIndex& rIdx = *pTmpFly->GetFormat()->GetContent().GetContentIdx();
     262           0 :             SwPosition aPos( rIdx );
     263           0 :             rAnchor.SetAnchor( &aPos );
     264           0 :             rNewPos = pTmpFly->Frm().Pos();
     265             :         }
     266             :         else
     267             :         {
     268           0 :             rAnchor.SetType( FLY_AT_PAGE );
     269           0 :             rAnchor.SetPageNum( rDestShell.GetPageNumber( rInsPt ) );
     270           0 :             const SwFrm *pPg = pTmpFrm->FindPageFrm();
     271           0 :             rNewPos = pPg->Frm().Pos();
     272             :         }
     273             :     }
     274             :     else
     275           0 :         rNewPos = ::lcl_FindBasePos( pTmpFrm, rInsPt );
     276           0 :     return bRet;
     277             : }
     278             : 
     279           0 : bool SwFEShell::CopyDrawSel( SwFEShell* pDestShell, const Point& rSttPt,
     280             :                     const Point& rInsPt, bool bIsMove, bool bSelectInsert )
     281             : {
     282           0 :     bool bRet = true;
     283             : 
     284             :     // The list should be copied, because below new objects will be selected
     285           0 :     const SdrMarkList aMrkList( Imp()->GetDrawView()->GetMarkedObjectList() );
     286           0 :     const size_t nMarkCount = aMrkList.GetMarkCount();
     287           0 :     if( !pDestShell->Imp()->GetDrawView() )
     288             :         // should create it now
     289           0 :         pDestShell->MakeDrawView();
     290           0 :     else if( bSelectInsert )
     291           0 :         pDestShell->Imp()->GetDrawView()->UnmarkAll();
     292             : 
     293           0 :     SdrPageView *pDestPgView = pDestShell->Imp()->GetPageView(),
     294           0 :                 *pSrcPgView = Imp()->GetPageView();
     295           0 :     SwDrawView *pDestDrwView = pDestShell->Imp()->GetDrawView(),
     296           0 :                 *pSrcDrwView = Imp()->GetDrawView();
     297           0 :     SwDoc* pDestDoc = pDestShell->GetDoc();
     298             : 
     299           0 :     Size aSiz( rInsPt.X() - rSttPt.X(), rInsPt.Y() - rSttPt.Y() );
     300           0 :     for( size_t i = 0; i < nMarkCount; ++i )
     301             :     {
     302           0 :         SdrObject *pObj = aMrkList.GetMark( i )->GetMarkedSdrObj();
     303             : 
     304           0 :         SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall( pObj ));
     305           0 :         SwFrameFormat *pFormat = pContact->GetFormat();
     306           0 :         const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
     307             : 
     308           0 :         bool bInsWithFormat = true;
     309             : 
     310           0 :         if( pDestDrwView->IsGroupEntered() )
     311             :         {
     312             :             // insert into the group, when it belongs to an entered group
     313             :             // or when the object is not anchored as a character
     314           0 :             if( pSrcDrwView->IsGroupEntered() ||
     315           0 :                 (FLY_AS_CHAR != rAnchor.GetAnchorId()) )
     316             : 
     317             :             {
     318           0 :                 SdrObject* pNew = pDestDoc->CloneSdrObj( *pObj, bIsMove &&
     319           0 :                                         GetDoc() == pDestDoc, false );
     320           0 :                 pNew->NbcMove( aSiz );
     321           0 :                 pDestDrwView->InsertObjectAtView( pNew, *pDestPgView );
     322           0 :                 bInsWithFormat = false;
     323             :             }
     324             :         }
     325             : 
     326           0 :         if( bInsWithFormat )
     327             :         {
     328           0 :             SwFormatAnchor aAnchor( rAnchor );
     329           0 :             Point aNewAnch;
     330             : 
     331           0 :             if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     332           0 :                 (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     333           0 :                 (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     334           0 :                 (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     335             :             {
     336           0 :                 if ( this == pDestShell )
     337             :                 {
     338             :                     // same shell? Then request the position
     339             :                     // from the passed DocumentPosition
     340           0 :                     SwPosition aPos( *GetCrsr()->GetPoint() );
     341           0 :                     Point aPt( rInsPt );
     342           0 :                     aPt -= rSttPt - pObj->GetSnapRect().TopLeft();
     343           0 :                     SwCrsrMoveState aState( MV_SETONLYTEXT );
     344           0 :                     GetLayout()->GetCrsrOfst( &aPos, aPt, &aState );
     345             :                     const SwNode *pNd;
     346           0 :                     if( (pNd = &aPos.nNode.GetNode())->IsNoTextNode() )
     347           0 :                         bRet = false;
     348             :                     else
     349             :                         bRet = ::lcl_SetAnchor( aPos, *pNd, 0, rInsPt,
     350           0 :                                 *pDestShell, aAnchor, aNewAnch, false );
     351             :                 }
     352             :                 else
     353             :                 {
     354           0 :                     SwPaM *pCrsr = pDestShell->GetCrsr();
     355           0 :                     if( pCrsr->GetNode().IsNoTextNode() )
     356           0 :                         bRet = false;
     357             :                     else
     358           0 :                         bRet = ::lcl_SetAnchor( *pCrsr->GetPoint(),
     359           0 :                                                 pCrsr->GetNode(), 0, rInsPt,
     360             :                                                 *pDestShell, aAnchor,
     361           0 :                                                 aNewAnch, false );
     362             :                 }
     363             :             }
     364           0 :             else if ( FLY_AT_PAGE == aAnchor.GetAnchorId() )
     365             :             {
     366           0 :                 aAnchor.SetPageNum( pDestShell->GetPageNumber( rInsPt ) );
     367           0 :                 const SwRootFrm* pTmpRoot = pDestShell->GetLayout();
     368           0 :                 const SwFrm* pPg = pTmpRoot->GetPageAtPos( rInsPt, 0, true );
     369           0 :                 if ( pPg )
     370           0 :                     aNewAnch = pPg->Frm().Pos();
     371             :             }
     372             : 
     373           0 :             if( bRet )
     374             :             {
     375           0 :                 if( pSrcDrwView->IsGroupEntered() ||
     376           0 :                     ( !pObj->GetUserCall() && pObj->GetUpGroup()) )
     377             :                 {
     378           0 :                     SfxItemSet aSet( pDestDoc->GetAttrPool(),aFrameFormatSetRange);
     379           0 :                     aSet.Put( aAnchor );
     380           0 :                     SdrObject* pNew = pDestDoc->CloneSdrObj( *pObj, bIsMove &&
     381           0 :                                                 GetDoc() == pDestDoc, true );
     382           0 :                     pFormat = pDestDoc->getIDocumentContentOperations().InsertDrawObj( *pDestShell->GetCrsr(), *pNew, aSet );
     383             :                 }
     384             :                 else
     385           0 :                     pFormat = pDestDoc->getIDocumentLayoutAccess().CopyLayoutFormat( *pFormat, aAnchor, true, true );
     386             : 
     387             :                 // Can be 0, as Draws are not allowed in Headers/Footers
     388           0 :                 if ( pFormat )
     389             :                 {
     390           0 :                     SdrObject* pNew = pFormat->FindSdrObject();
     391           0 :                     if ( FLY_AS_CHAR != aAnchor.GetAnchorId() )
     392             :                     {
     393           0 :                         Point aPos( rInsPt );
     394           0 :                         aPos -= aNewAnch;
     395           0 :                         aPos -= rSttPt - pObj->GetSnapRect().TopLeft();
     396             :                         // OD 2004-04-05 #i26791# - change attributes instead of
     397             :                         // direct positioning
     398           0 :                         pFormat->SetFormatAttr( SwFormatHoriOrient( aPos.getX(), text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
     399           0 :                         pFormat->SetFormatAttr( SwFormatVertOrient( aPos.getY(), text::VertOrientation::NONE, text::RelOrientation::FRAME ) );
     400             :                         // #i47455# - notify draw frame format
     401             :                         // that position attributes are already set.
     402           0 :                         if ( pFormat->ISA(SwDrawFrameFormat) )
     403             :                         {
     404           0 :                             static_cast<SwDrawFrameFormat*>(pFormat)->PosAttrSet();
     405             :                         }
     406             :                     }
     407           0 :                     if( bSelectInsert )
     408           0 :                         pDestDrwView->MarkObj( pNew, pDestPgView );
     409             :                 }
     410           0 :             }
     411             :         }
     412             :     }
     413             : 
     414           0 :     if ( bIsMove && bRet )
     415             :     {
     416           0 :         if( pDestShell == this )
     417             :         {
     418           0 :             const SdrMarkList aList( pSrcDrwView->GetMarkedObjectList() );
     419           0 :             pSrcDrwView->UnmarkAll();
     420             : 
     421           0 :             for ( size_t i = 0, nMrkCnt = aMrkList.GetMarkCount(); i < nMrkCnt; ++i )
     422             :             {
     423           0 :                 SdrObject *pObj = aMrkList.GetMark( i )->GetMarkedSdrObj();
     424           0 :                 pSrcDrwView->MarkObj( pObj, pSrcPgView );
     425             :             }
     426           0 :             DelSelectedObj();
     427           0 :             for ( size_t i = 0, nMrkCnt = aList.GetMarkCount(); i < nMrkCnt; ++i )
     428             :             {
     429           0 :                 SdrObject *pObj = aList.GetMark( i )->GetMarkedSdrObj();
     430           0 :                 pSrcDrwView->MarkObj( pObj, pSrcPgView );
     431           0 :             }
     432             :         }
     433             :         else
     434           0 :             DelSelectedObj();
     435             :     }
     436             : 
     437           0 :     return bRet;
     438             : }
     439             : 
     440           0 : bool SwFEShell::Copy( SwFEShell* pDestShell, const Point& rSttPt,
     441             :                     const Point& rInsPt, bool bIsMove, bool bSelectInsert )
     442             : {
     443           0 :     bool bRet = false;
     444             : 
     445             :     OSL_ENSURE( pDestShell, "Copy without DestShell." );
     446             :     OSL_ENSURE( this == pDestShell || !pDestShell->IsObjSelected(),
     447             :             "Dest-Shell cannot be in Obj-Mode" );
     448             : 
     449           0 :     SET_CURR_SHELL( pDestShell );
     450             : 
     451           0 :     pDestShell->StartAllAction();
     452           0 :     pDestShell->GetDoc()->getIDocumentFieldsAccess().LockExpFields();
     453             : 
     454             :     // Shift references
     455           0 :     bool bCopyIsMove = mpDoc->IsCopyIsMove();
     456           0 :     if( bIsMove )
     457             :         // set a flag in Doc, handled in TextNodes
     458           0 :         mpDoc->SetCopyIsMove( true );
     459             : 
     460           0 :     RedlineMode_t eOldRedlMode = pDestShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineMode();
     461           0 :     pDestShell->GetDoc()->getIDocumentRedlineAccess().SetRedlineMode_intern( (RedlineMode_t)(eOldRedlMode | nsRedlineMode_t::REDLINE_DELETE_REDLINES));
     462             : 
     463             :     // If there are table formulas in the area, then display the table first
     464             :     // so that the table formula can calculate a new value first
     465             :     // (individual boxes in the area are retrieved via the layout)
     466           0 :      SwFieldType* pTableFieldTyp = pDestShell->GetDoc()->getIDocumentFieldsAccess().GetSysFieldType( RES_TABLEFLD );
     467             : 
     468           0 :     if( IsFrmSelected() )
     469             :     {
     470           0 :         SwFlyFrm* pFly = FindFlyFrm();
     471           0 :         SwFrameFormat* pFlyFormat = pFly->GetFormat();
     472           0 :         SwFormatAnchor aAnchor( pFlyFormat->GetAnchor() );
     473           0 :         bRet = true;
     474           0 :         Point aNewAnch;
     475             : 
     476           0 :         if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     477           0 :             (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     478           0 :             (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     479           0 :             (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     480             :         {
     481           0 :             if ( this == pDestShell )
     482             :             {
     483             :                 // same shell? Then request the position
     484             :                 // from the passed DocumentPosition
     485           0 :                 SwPosition aPos( *GetCrsr()->GetPoint() );
     486           0 :                 Point aPt( rInsPt );
     487           0 :                 aPt -= rSttPt - pFly->Frm().Pos();
     488           0 :                 SwCrsrMoveState aState( MV_SETONLYTEXT );
     489           0 :                 GetLayout()->GetCrsrOfst( &aPos, aPt, &aState );
     490             :                 const SwNode *pNd;
     491           0 :                 if( (pNd = &aPos.nNode.GetNode())->IsNoTextNode() )
     492           0 :                     bRet = false;
     493             :                 else
     494             :                 {
     495             :                     // do not copy in itself
     496           0 :                     const SwNodeIndex *pTmp = pFlyFormat->GetContent().GetContentIdx();
     497           0 :                     if ( aPos.nNode > *pTmp && aPos.nNode <
     498           0 :                         pTmp->GetNode().EndOfSectionIndex() )
     499             :                     {
     500           0 :                         bRet = false;
     501             :                     }
     502             :                     else
     503             :                         bRet = ::lcl_SetAnchor( aPos, *pNd, pFly, rInsPt,
     504           0 :                                         *pDestShell, aAnchor, aNewAnch, true );
     505           0 :                 }
     506             :             }
     507             :             else
     508             :             {
     509           0 :                 const SwPaM *pCrsr = pDestShell->GetCrsr();
     510           0 :                 if( pCrsr->GetNode().IsNoTextNode() )
     511           0 :                     bRet = false;
     512             :                 else
     513           0 :                     bRet = ::lcl_SetAnchor( *pCrsr->GetPoint(), pCrsr->GetNode(),
     514             :                                             pFly, rInsPt, *pDestShell, aAnchor,
     515           0 :                                     aNewAnch, GetDoc() == pDestShell->GetDoc());
     516             :             }
     517             :         }
     518           0 :         else if ( FLY_AT_PAGE == aAnchor.GetAnchorId() )
     519             :         {
     520           0 :             aAnchor.SetPageNum( pDestShell->GetPageNumber( rInsPt ) );
     521           0 :             const SwRootFrm* pTmpRoot = pDestShell->GetLayout();
     522           0 :             const SwFrm* pPg = pTmpRoot->GetPageAtPos( rInsPt, 0, true );
     523           0 :             if ( pPg )
     524           0 :                 aNewAnch = pPg->Frm().Pos();
     525             :         }
     526             :         else {
     527             :             OSL_ENSURE( false, "what anchor is it?" );
     528             :         }
     529             : 
     530           0 :         if( bRet )
     531             :         {
     532           0 :             SwFrameFormat *pOldFormat = pFlyFormat;
     533           0 :             pFlyFormat = pDestShell->GetDoc()->getIDocumentLayoutAccess().CopyLayoutFormat( *pFlyFormat, aAnchor, true, true );
     534             : 
     535           0 :             if ( FLY_AS_CHAR != aAnchor.GetAnchorId() )
     536             :             {
     537           0 :                 Point aPos( rInsPt );
     538           0 :                 aPos -= aNewAnch;
     539           0 :                 aPos -= rSttPt - pFly->Frm().Pos();
     540           0 :                 pFlyFormat->SetFormatAttr( SwFormatHoriOrient( aPos.getX(),text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
     541           0 :                 pFlyFormat->SetFormatAttr( SwFormatVertOrient( aPos.getY(),text::VertOrientation::NONE, text::RelOrientation::FRAME ) );
     542             :             }
     543             : 
     544           0 :             const Point aPt( pDestShell->GetCrsrDocPos() );
     545             : 
     546           0 :             if( bIsMove )
     547           0 :                 GetDoc()->getIDocumentLayoutAccess().DelLayoutFormat( pOldFormat );
     548             : 
     549             :             // only select if it can be shifted/copied in the same shell
     550           0 :             if( bSelectInsert )
     551             :             {
     552           0 :                 SwFlyFrm* pFlyFrm = static_cast<SwFlyFrameFormat*>(pFlyFormat)->GetFrm( &aPt, false );
     553           0 :                 if( pFlyFrm )
     554             :                 {
     555             :                     //JP 12.05.98: should this be in SelectFlyFrm???
     556           0 :                     pDestShell->Imp()->GetDrawView()->UnmarkAll();
     557           0 :                     pDestShell->SelectFlyFrm( *pFlyFrm, true );
     558             :                 }
     559             :             }
     560             : 
     561           0 :             if( this != pDestShell && !pDestShell->HasShFcs() )
     562           0 :                 pDestShell->Imp()->GetDrawView()->hideMarkHandles();
     563           0 :         }
     564             :     }
     565           0 :     else if ( IsObjSelected() )
     566           0 :         bRet = CopyDrawSel( pDestShell, rSttPt, rInsPt, bIsMove, bSelectInsert );
     567           0 :     else if( IsTableMode() )
     568             :     {
     569             :         // Copy parts from a table: create a table with the same
     570             :         // width as the original and copy the selected boxes.
     571             :         // Sizes will be corrected by percentage.
     572             : 
     573             :         // find boxes via the layout
     574             :         const SwTableNode* pTableNd;
     575           0 :         SwSelBoxes aBoxes;
     576           0 :         GetTableSel( *this, aBoxes );
     577           0 :         if( !aBoxes.empty() &&
     578           0 :             0 != (pTableNd = aBoxes[0]->GetSttNd()->FindTableNode()) )
     579             :         {
     580           0 :             SwPosition* pDstPos = 0;
     581           0 :             if( this == pDestShell )
     582             :             {
     583             :                 // same shell? Then create new Crsr at the
     584             :                 // DocumentPosition passed
     585           0 :                 pDstPos = new SwPosition( *GetCrsr()->GetPoint() );
     586           0 :                 Point aPt( rInsPt );
     587           0 :                 GetLayout()->GetCrsrOfst( pDstPos, aPt );
     588           0 :                 if( !pDstPos->nNode.GetNode().IsNoTextNode() )
     589           0 :                     bRet = true;
     590             :             }
     591           0 :             else if( !pDestShell->GetCrsr()->GetNode().IsNoTextNode() )
     592             :             {
     593           0 :                 pDstPos = new SwPosition( *pDestShell->GetCrsr()->GetPoint() );
     594           0 :                 bRet = true;
     595             :             }
     596             : 
     597           0 :             if( bRet )
     598             :             {
     599           0 :                 if( GetDoc() == pDestShell->GetDoc() )
     600           0 :                     ParkTableCrsr();
     601             : 
     602             :                 bRet = pDestShell->GetDoc()->InsCopyOfTable( *pDstPos, aBoxes,0,
     603           0 :                                         bIsMove && this == pDestShell &&
     604           0 :                                         aBoxes.size() == pTableNd->GetTable().
     605           0 :                                         GetTabSortBoxes().size(),
     606           0 :                                         this != pDestShell );
     607             : 
     608           0 :                 if( this != pDestShell )
     609           0 :                     *pDestShell->GetCrsr()->GetPoint() = *pDstPos;
     610             : 
     611             :                 // create all parked Crsr?
     612           0 :                 if( GetDoc() == pDestShell->GetDoc() )
     613           0 :                     GetCrsr();
     614             : 
     615             :                 // JP 16.04.99: Bug 64908 - Set InsPos, to assure the parked
     616             :                 //              Cursor is positioned at the insert position
     617           0 :                 if( this == pDestShell )
     618           0 :                     GetCrsrDocPos() = rInsPt;
     619             :             }
     620           0 :             delete pDstPos;
     621           0 :         }
     622             :     }
     623             :     else
     624             :     {
     625           0 :         bRet = true;
     626           0 :         if( this == pDestShell )
     627             :         {
     628             :             // same shell? then request the position
     629             :             // at the passed document position
     630           0 :             SwPosition aPos( *GetCrsr()->GetPoint() );
     631           0 :             Point aPt( rInsPt );
     632           0 :             GetLayout()->GetCrsrOfst( &aPos, aPt );
     633           0 :             bRet = !aPos.nNode.GetNode().IsNoTextNode();
     634             :         }
     635           0 :         else if( pDestShell->GetCrsr()->GetNode().IsNoTextNode() )
     636           0 :             bRet = false;
     637             : 
     638           0 :         if( bRet )
     639           0 :             bRet = SwEditShell::Copy( pDestShell );
     640             :     }
     641             : 
     642           0 :     pDestShell->GetDoc()->getIDocumentRedlineAccess().SetRedlineMode_intern( eOldRedlMode );
     643           0 :     mpDoc->SetCopyIsMove( bCopyIsMove );
     644             : 
     645             :     // have new table formules been inserted?
     646           0 :     if( pTableFieldTyp->HasWriterListeners() )
     647             :     {
     648             :         // finish old actions: the table frames are created and
     649             :         // a selection can be made
     650             :         sal_uInt16 nActCnt;
     651           0 :         for( nActCnt = 0; pDestShell->ActionPend(); ++nActCnt )
     652           0 :             pDestShell->EndAllAction();
     653             : 
     654           0 :         for( ; nActCnt; --nActCnt )
     655           0 :             pDestShell->StartAllAction();
     656             :     }
     657           0 :     pDestShell->GetDoc()->getIDocumentFieldsAccess().UnlockExpFields();
     658           0 :     pDestShell->GetDoc()->getIDocumentFieldsAccess().UpdateFields(NULL, false);
     659             : 
     660           0 :     pDestShell->EndAllAction();
     661           0 :     return bRet;
     662             : }
     663             : 
     664             : // Paste for  the interal clipboard. Copy the content of the clipboard
     665             : // in the document
     666             : namespace {
     667             :     typedef boost::shared_ptr<SwPaM> PaMPtr;
     668             :     typedef boost::shared_ptr<SwPosition> PositionPtr;
     669             :     typedef std::pair< PaMPtr, PositionPtr > Insertion;
     670             : }
     671             : 
     672           2 : bool SwFEShell::Paste( SwDoc* pClpDoc, bool bIncludingPageFrames )
     673             : {
     674           2 :     SET_CURR_SHELL( this );
     675             :     OSL_ENSURE( pClpDoc, "no clipboard document"  );
     676           2 :     const sal_uInt16 nStartPageNumber = GetPhyPageNum();
     677             :     // then till end of the nodes array
     678           4 :     SwNodeIndex aIdx( pClpDoc->GetNodes().GetEndOfExtras(), 2 );
     679           4 :     SwPaM aCpyPam( aIdx ); //DocStart
     680             : 
     681             :     // If there are table formulas in the area, then display the table first
     682             :     // so that the table formula can calculate a new value first
     683             :     // (individual boxes in the area are retrieved via the layout)
     684           2 :     SwFieldType* pTableFieldTyp = GetDoc()->getIDocumentFieldsAccess().GetSysFieldType( RES_TABLEFLD );
     685             : 
     686           2 :     SwTableNode *pDestNd, *pSrcNd = aCpyPam.GetNode().GetTableNode();
     687           2 :     if( !pSrcNd )                               // TabellenNode ?
     688             :     {                                           // nicht ueberspringen!!
     689           2 :         SwContentNode* pCNd = aCpyPam.GetNode().GetContentNode();
     690           2 :         if( pCNd )
     691           2 :             aCpyPam.GetPoint()->nContent.Assign( pCNd, 0 );
     692           0 :         else if( !aCpyPam.Move( fnMoveForward, fnGoNode ))
     693           0 :             aCpyPam.Move( fnMoveBackward, fnGoNode );
     694             :     }
     695             : 
     696           2 :     aCpyPam.SetMark();
     697           2 :     aCpyPam.Move( fnMoveForward, fnGoDoc );
     698             : 
     699           2 :     bool bRet = true;
     700           2 :     StartAllAction();
     701           2 :     GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
     702           2 :     GetDoc()->getIDocumentFieldsAccess().LockExpFields();
     703             : 
     704             :     // When the clipboard content has been created by a rectangular selection
     705             :     // the pasting is more sophisticated:
     706             :     // every paragraph will be inserted into another position.
     707             :     // The first positions are given by the actual cursor ring,
     708             :     // if there are more text portions to insert than cursor in this ring,
     709             :     // the additional insert positions will be created by moving the last
     710             :     // cursor position into the next line (like pressing the cursor down key)
     711           2 :     if( pClpDoc->IsColumnSelection() && !IsTableMode() )
     712             :     {
     713             :         // Creation of the list of insert positions
     714           0 :         std::list< Insertion > aCopyList;
     715             :         // The number of text portions of the rectangular selection
     716           0 :         const sal_uInt32 nSelCount = aCpyPam.GetPoint()->nNode.GetIndex()
     717           0 :                        - aCpyPam.GetMark()->nNode.GetIndex();
     718           0 :         sal_uInt32 nCount = nSelCount;
     719           0 :         SwNodeIndex aClpIdx( aIdx );
     720           0 :         SwPaM* pStartCursor = GetCrsr();
     721           0 :         SwPaM* pCurrCrsr = pStartCursor;
     722           0 :         sal_uInt32 nCursorCount = pStartCursor->GetRingContainer().size();
     723             :         // If the target selection is a multi-selection, often the last and first
     724             :         // cursor of the ring points to identical document positions. Then
     725             :         // we should avoid double insertion of text portions...
     726           0 :         while( nCursorCount > 1 && *pCurrCrsr->GetPoint() ==
     727           0 :             *(pCurrCrsr->GetPrev()->GetPoint()) )
     728             :         {
     729           0 :             --nCursorCount;
     730           0 :             pCurrCrsr = pCurrCrsr->GetNext();
     731           0 :             pStartCursor = pCurrCrsr;
     732             :         }
     733           0 :         SwPosition aStartPos( *pStartCursor->GetPoint() );
     734           0 :         SwPosition aInsertPos( aStartPos ); // first insertion position
     735           0 :         bool bCompletePara = false;
     736           0 :         sal_uInt16 nMove = 0;
     737           0 :         while( nCount )
     738             :         {
     739           0 :             --nCount;
     740             :             OSL_ENSURE( aIdx.GetNode().GetContentNode(), "Who filled the clipboard?!" );
     741           0 :             if( aIdx.GetNode().GetContentNode() ) // robust
     742             :             {
     743           0 :                 Insertion aInsertion( PaMPtr( new SwPaM( aIdx ) ),
     744           0 :                     PositionPtr( new SwPosition( aInsertPos ) ) );
     745           0 :                 ++aIdx;
     746           0 :                 aInsertion.first->SetMark();
     747           0 :                 if( pStartCursor == pCurrCrsr->GetNext() )
     748             :                 {   // Now we have to look for insertion positions...
     749           0 :                     if( !nMove ) // Annotate the last given insert position
     750           0 :                         aStartPos = aInsertPos;
     751           0 :                     SwCursor aCrsr( aStartPos, 0, false);
     752             :                     // Check if we find another insert position by moving
     753             :                     // down the last given position
     754           0 :                     if( aCrsr.UpDown( false, ++nMove, 0, 0 ) )
     755           0 :                         aInsertPos = *aCrsr.GetPoint();
     756             :                     else // if there is no paragraph we have to create it
     757           0 :                         bCompletePara = nCount > 0;
     758           0 :                     nCursorCount = 0;
     759             :                 }
     760             :                 else // as long as we find more insert positions in the cursor ring
     761             :                 {    // we'll take them
     762           0 :                     pCurrCrsr = pCurrCrsr->GetNext();
     763           0 :                     aInsertPos = *pCurrCrsr->GetPoint();
     764           0 :                     --nCursorCount;
     765             :                 }
     766             :                 // If there are no more paragraphs e.g. at the end of a document,
     767             :                 // we insert complete paragraphs instead of text portions
     768           0 :                 if( bCompletePara )
     769           0 :                     aInsertion.first->GetPoint()->nNode = aIdx;
     770             :                 else
     771           0 :                     aInsertion.first->GetPoint()->nContent =
     772           0 :                         aInsertion.first->GetContentNode()->Len();
     773           0 :                 aCopyList.push_back( aInsertion );
     774             :             }
     775             :             // If there are no text portions left but there are some more
     776             :             // cursor positions to fill we have to restart with the first
     777             :             // text portion
     778           0 :             if( !nCount && nCursorCount )
     779             :             {
     780           0 :                 nCount = std::min( nSelCount, nCursorCount );
     781           0 :                 aIdx = aClpIdx; // Start of clipboard content
     782             :             }
     783             :         }
     784           0 :         std::list< Insertion >::const_iterator pCurr = aCopyList.begin();
     785           0 :         std::list< Insertion >::const_iterator pEnd = aCopyList.end();
     786           0 :         while( pCurr != pEnd )
     787             :         {
     788           0 :             SwPosition& rInsPos = *pCurr->second;
     789           0 :             SwPaM& rCopy = *pCurr->first;
     790           0 :             const SwStartNode* pBoxNd = rInsPos.nNode.GetNode().FindTableBoxStartNode();
     791           0 :             if( pBoxNd && 2 == pBoxNd->EndOfSectionIndex() - pBoxNd->GetIndex() &&
     792           0 :                 rCopy.GetPoint()->nNode != rCopy.GetMark()->nNode )
     793             :             {
     794             :                 // if more than one node will be copied into a cell
     795             :                 // the box attributes have to be removed
     796           0 :                 GetDoc()->ClearBoxNumAttrs( rInsPos.nNode );
     797             :             }
     798             :             {
     799           0 :                 SwNodeIndex aIndexBefore(rInsPos.nNode);
     800           0 :                 --aIndexBefore;
     801           0 :                 pClpDoc->getIDocumentContentOperations().CopyRange( rCopy, rInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true );
     802             :                 {
     803           0 :                     ++aIndexBefore;
     804             :                     SwPaM aPaM(SwPosition(aIndexBefore),
     805           0 :                                SwPosition(rInsPos.nNode));
     806           0 :                     aPaM.GetDoc()->MakeUniqueNumRules(aPaM);
     807           0 :                 }
     808             :             }
     809           0 :             SaveTableBoxContent( &rInsPos );
     810           0 :             ++pCurr;
     811           0 :         }
     812             :     }
     813             :     else
     814             :     {
     815           2 :         bool bDelTable = true;
     816             : 
     817           4 :         for(SwPaM& rPaM : GetCrsr()->GetRingContainer())
     818             :         {
     819             : 
     820           2 :             if( pSrcNd &&
     821           0 :                 0 != ( pDestNd = GetDoc()->IsIdxInTable( rPaM.GetPoint()->nNode )) &&
     822             :                 // are we at the beginning of the cell? (if not, we will insert a nested table)
     823             :                 // first paragraph of the cell?
     824           2 :                 rPaM.GetNode().GetIndex() == rPaM.GetNode().FindTableBoxStartNode()->GetIndex()+1 &&
     825             :                 // beginning of the paragraph?
     826           0 :                 !rPaM.GetPoint()->nContent.GetIndex())
     827             :             {
     828           0 :                 SwPosition aDestPos( *rPaM.GetPoint() );
     829             : 
     830           0 :                 bool bParkTableCrsr = false;
     831           0 :                 const SwStartNode* pSttNd =  rPaM.GetNode().FindTableBoxStartNode();
     832             : 
     833             :                 // TABLE IN TABLE: copy table in table
     834             :                 // search boxes via the layout
     835           0 :                 SwSelBoxes aBoxes;
     836           0 :                 if( IsTableMode() )     // table selection?
     837             :                 {
     838           0 :                     GetTableSel( *this, aBoxes );
     839           0 :                     ParkTableCrsr();
     840           0 :                     bParkTableCrsr = true;
     841             :                 }
     842           0 :                 else if( !rPaM.HasMark() && rPaM.GetNext() == &rPaM &&
     843           0 :                      ( !pSrcNd->GetTable().IsTableComplex() ||
     844           0 :                        pDestNd->GetTable().IsNewModel() ) )
     845             :                 {
     846             :                     // make relative table copy
     847           0 :                     SwTableBox* pBox = pDestNd->GetTable().GetTableBox(
     848           0 :                                         pSttNd->GetIndex() );
     849             :                     OSL_ENSURE( pBox, "Box steht nicht in dieser Tabelle" );
     850           0 :                     aBoxes.insert( pBox );
     851             :                 }
     852             : 
     853           0 :                 SwNodeIndex aNdIdx( *pDestNd->EndOfSectionNode());
     854           0 :                 if( !bParkTableCrsr )
     855             :                 {
     856             :                     // exit first the complete table
     857             :                     // ???? what about only table in a frame ?????
     858           0 :                     SwContentNode* pCNd = GetDoc()->GetNodes().GoNext( &aNdIdx );
     859           0 :                     SwPosition aPos( aNdIdx, SwIndex( pCNd, 0 ));
     860             :                     // #i59539: Don't remove all redline
     861           0 :                     SwPaM const tmpPaM(*pDestNd, *pDestNd->EndOfSectionNode());
     862           0 :                     ::PaMCorrAbs(tmpPaM, aPos);
     863             :                 }
     864             : 
     865           0 :                 bRet = GetDoc()->InsCopyOfTable( aDestPos, aBoxes, &pSrcNd->GetTable(),
     866           0 :                                             false, false );
     867             : 
     868           0 :                 if( bParkTableCrsr )
     869           0 :                     GetCrsr();
     870             :                 else
     871             :                 {
     872             :                     // return to the box
     873           0 :                     aNdIdx = *pSttNd;
     874           0 :                     SwContentNode* pCNd = GetDoc()->GetNodes().GoNext( &aNdIdx );
     875           0 :                     SwPosition aPos( aNdIdx, SwIndex( pCNd, 0 ));
     876             :                     // #i59539: Don't remove all redline
     877           0 :                     SwNode & rNode(rPaM.GetPoint()->nNode.GetNode());
     878           0 :                     SwContentNode *const pContentNode( rNode.GetContentNode() );
     879             :                     SwPaM const tmpPam(rNode, 0,
     880           0 :                                    rNode, (pContentNode) ? pContentNode->Len() : 0);
     881           0 :                     ::PaMCorrAbs(tmpPam, aPos);
     882             :                 }
     883             : 
     884           0 :                 break;      // exit the "while-loop"
     885             :             }
     886           3 :             else if( *aCpyPam.GetPoint() == *aCpyPam.GetMark() &&
     887           1 :                  pClpDoc->GetSpzFrameFormats()->size() )
     888             :             {
     889             :                 // we need a DrawView
     890           1 :                 if( !Imp()->GetDrawView() )
     891           0 :                     MakeDrawView();
     892             : 
     893           1 :                 std::set<const SwFrameFormat*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pClpDoc);
     894           3 :                 for ( auto pCpyFormat : *pClpDoc->GetSpzFrameFormats() )
     895             :                 {
     896           2 :                     bool bInsWithFormat = true;
     897             : 
     898           4 :                     if( Imp()->GetDrawView()->IsGroupEntered() &&
     899           2 :                         RES_DRAWFRMFMT == pCpyFormat->Which() &&
     900           0 :                         (FLY_AS_CHAR != pCpyFormat->GetAnchor().GetAnchorId()) )
     901             :                     {
     902           0 :                         const SdrObject* pSdrObj = pCpyFormat->FindSdrObject();
     903           0 :                         if( pSdrObj )
     904             :                         {
     905             :                             SdrObject* pNew = GetDoc()->CloneSdrObj( *pSdrObj,
     906           0 :                                                             false, false );
     907             : 
     908             :                             // Insert object sets any anchor position to 0.
     909             :                             // Therefore we calculate the absolute position here
     910             :                             // and after the insert the anchor of the object
     911             :                             // is set to the anchor of the group object.
     912           0 :                             Rectangle aSnapRect = pNew->GetSnapRect();
     913           0 :                             if( pNew->GetAnchorPos().X() || pNew->GetAnchorPos().Y() )
     914             :                             {
     915           0 :                                 const Point aPoint( 0, 0 );
     916             :                                 // OD 2004-04-05 #i26791# - direct drawing object
     917             :                                 // positioning for group members
     918           0 :                                 pNew->NbcSetAnchorPos( aPoint );
     919           0 :                                 pNew->NbcSetSnapRect( aSnapRect );
     920             :                             }
     921             : 
     922           0 :                             Imp()->GetDrawView()->InsertObjectAtView( pNew, *Imp()->GetPageView() );
     923             : 
     924           0 :                             Point aGrpAnchor( 0, 0 );
     925           0 :                             SdrObjList* pList = pNew->GetObjList();
     926           0 :                             if ( pList )
     927             :                             {
     928           0 :                                 SdrObject* pOwner = pList->GetOwnerObj();
     929           0 :                                 if ( pOwner )
     930             :                                 {
     931           0 :                                     SdrObjGroup* pThisGroup = PTR_CAST(SdrObjGroup, pOwner);
     932           0 :                                     aGrpAnchor = pThisGroup->GetAnchorPos();
     933             :                                 }
     934             :                             }
     935             : 
     936             :                             // OD 2004-04-05 #i26791# - direct drawing object
     937             :                             // positioning for group members
     938           0 :                             pNew->NbcSetAnchorPos( aGrpAnchor );
     939           0 :                             pNew->SetSnapRect( aSnapRect );
     940             : 
     941           0 :                             bInsWithFormat = false;
     942             :                         }
     943             :                     }
     944             : 
     945           2 :                     if( bInsWithFormat  )
     946             :                     {
     947           2 :                         SwFormatAnchor aAnchor( pCpyFormat->GetAnchor() );
     948           4 :                         if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     949           2 :                             (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     950           0 :                             (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     951             :                         {
     952           2 :                             SwPosition* pPos = rPaM.GetPoint();
     953             :                             // allow shapes (no controls) in header/footer
     954           3 :                             if( RES_DRAWFRMFMT == pCpyFormat->Which() &&
     955           1 :                                 GetDoc()->IsInHeaderFooter( pPos->nNode ) )
     956             :                             {
     957           0 :                                 const SdrObject *pCpyObj = pCpyFormat->FindSdrObject();
     958           0 :                                 if (pCpyObj && CheckControlLayer(pCpyObj))
     959           0 :                                     continue;
     960             :                             }
     961             : 
     962             :                             // Ignore TextBoxes, they are already handled in sw::DocumentLayoutManager::CopyLayoutFormat().
     963           2 :                             if (aTextBoxes.find(pCpyFormat) != aTextBoxes.end())
     964           1 :                                 continue;
     965             : 
     966           1 :                             aAnchor.SetAnchor( pPos );
     967             :                         }
     968           0 :                         else if ( FLY_AT_PAGE == aAnchor.GetAnchorId() )
     969             :                         {
     970           0 :                             aAnchor.SetPageNum( GetPhyPageNum() );
     971             :                         }
     972           0 :                         else if( FLY_AT_FLY == aAnchor.GetAnchorId() )
     973             :                         {
     974           0 :                             Point aPt;
     975           0 :                             (void)lcl_SetAnchor( *rPaM.GetPoint(), rPaM.GetNode(),
     976           0 :                                         0, aPt, *this, aAnchor, aPt, false );
     977             :                         }
     978             : 
     979           1 :                         SwFrameFormat * pNew = GetDoc()->getIDocumentLayoutAccess().CopyLayoutFormat( *pCpyFormat, aAnchor, true, true );
     980             : 
     981           1 :                         if( pNew )
     982             :                         {
     983           1 :                             if( RES_FLYFRMFMT == pNew->Which() )
     984             :                             {
     985           0 :                                 const Point aPt( GetCrsrDocPos() );
     986             :                                 SwFlyFrm* pFlyFrm = static_cast<SwFlyFrameFormat*>(pNew)->
     987           0 :                                                         GetFrm( &aPt, false );
     988           0 :                                 if( pFlyFrm )
     989           0 :                                     SelectFlyFrm( *pFlyFrm, true );
     990             :                                 // always pick the first FlyFrame only; the others
     991             :                                 // were copied to the clipboard via Fly in Fly
     992           0 :                                 break;
     993             :                             }
     994             :                             else
     995             :                             {
     996             :                                 OSL_ENSURE( RES_DRAWFRMFMT == pNew->Which(), "Neues Format.");
     997             :                                 // #i52780# - drawing object has
     998             :                                 // to be made visible on paste.
     999             :                                 {
    1000             :                                     SwDrawContact* pContact =
    1001           1 :                                         static_cast<SwDrawContact*>(pNew->FindContactObj());
    1002           1 :                                     pContact->MoveObjToVisibleLayer( pContact->GetMaster() );
    1003             :                                 }
    1004           1 :                                 SdrObject *pObj = pNew->FindSdrObject();
    1005           1 :                                 SwDrawView  *pDV = Imp()->GetDrawView();
    1006           1 :                                 pDV->MarkObj( pObj, pDV->GetSdrPageView() );
    1007             :                                 // #i47455# - notify draw frame format
    1008             :                                 // that position attributes are already set.
    1009           1 :                                 if ( pNew->ISA(SwDrawFrameFormat) )
    1010             :                                 {
    1011           1 :                                     static_cast<SwDrawFrameFormat*>(pNew)->PosAttrSet();
    1012             :                                 }
    1013             :                             }
    1014           1 :                         }
    1015             :                     }
    1016           1 :                 }
    1017             :             }
    1018             :             else
    1019             :             {
    1020           1 :                 if( bDelTable && IsTableMode() )
    1021             :                 {
    1022           0 :                     SwEditShell::Delete();
    1023           0 :                     bDelTable = false;
    1024             :                 }
    1025             : 
    1026           1 :                 SwPosition& rInsPos = *rPaM.GetPoint();
    1027           1 :                 const SwStartNode* pBoxNd = rInsPos.nNode.GetNode().
    1028           1 :                                                     FindTableBoxStartNode();
    1029           1 :                 if( pBoxNd && 2 == pBoxNd->EndOfSectionIndex() -
    1030           1 :                                 pBoxNd->GetIndex() &&
    1031           0 :                     aCpyPam.GetPoint()->nNode != aCpyPam.GetMark()->nNode )
    1032             :                 {
    1033             :                     // Copy more than 1 node in the current box. But
    1034             :                     // then the BoxAttribute should be removed
    1035           0 :                     GetDoc()->ClearBoxNumAttrs( rInsPos.nNode );
    1036             :                 }
    1037             : 
    1038             :                 // **
    1039             :                 // ** Update SwDoc::Append, if you change the following code **
    1040             :                 // **
    1041             : 
    1042             :                 // find out if the clipboard document starts with a table
    1043           1 :                 bool bStartWithTable = 0 != aCpyPam.Start()->nNode.GetNode().FindTableNode();
    1044           1 :                 SwPosition aInsertPosition( rInsPos );
    1045             : 
    1046             :                 {
    1047           1 :                     SwNodeIndex aIndexBefore(rInsPos.nNode);
    1048             : 
    1049           1 :                     --aIndexBefore;
    1050             : 
    1051           1 :                     pClpDoc->getIDocumentContentOperations().CopyRange( aCpyPam, rInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true );
    1052             :                     // Note: aCpyPam is invalid now
    1053             : 
    1054           1 :                     ++aIndexBefore;
    1055             :                     SwPaM aPaM(SwPosition(aIndexBefore),
    1056           2 :                            SwPosition(rInsPos.nNode));
    1057             : 
    1058           1 :                     aPaM.GetDoc()->MakeUniqueNumRules(aPaM);
    1059             : 
    1060             :                     // Update the rsid of each pasted text node.
    1061           1 :                     SwNodes &rDestNodes = GetDoc()->GetNodes();
    1062           1 :                     sal_uLong const nEndIdx = aPaM.End()->nNode.GetIndex();
    1063             : 
    1064          18 :                     for (sal_uLong nIdx = aPaM.Start()->nNode.GetIndex();
    1065             :                         nIdx <= nEndIdx; ++nIdx)
    1066             :                     {
    1067          17 :                         SwTextNode *const pTextNode = rDestNodes[nIdx]->GetTextNode();
    1068          17 :                         if ( pTextNode )
    1069             :                         {
    1070           7 :                             GetDoc()->UpdateParRsid( pTextNode );
    1071             :                         }
    1072           1 :                     }
    1073             :                 }
    1074             : 
    1075           1 :                 SaveTableBoxContent( &rInsPos );
    1076           1 :                 if(bIncludingPageFrames && bStartWithTable)
    1077             :                 {
    1078             :                     //remove the paragraph in front of the table
    1079           0 :                     SwPaM aPara(aInsertPosition);
    1080           0 :                     GetDoc()->getIDocumentContentOperations().DelFullPara(aPara);
    1081             :                 }
    1082             :                 //additionally copy page bound frames
    1083           1 :                 if( bIncludingPageFrames && pClpDoc->GetSpzFrameFormats()->size() )
    1084             :                 {
    1085             :                     // create a draw view if necessary
    1086           0 :                     if( !Imp()->GetDrawView() )
    1087           0 :                         MakeDrawView();
    1088             : 
    1089           0 :                     for ( auto pCpyFormat : *pClpDoc->GetSpzFrameFormats() )
    1090             :                     {
    1091           0 :                         SwFormatAnchor aAnchor( pCpyFormat->GetAnchor() );
    1092           0 :                         if ( FLY_AT_PAGE != aAnchor.GetAnchorId() )
    1093           0 :                             continue;
    1094           0 :                         aAnchor.SetPageNum( aAnchor.GetPageNum() + nStartPageNumber - 1 );
    1095           0 :                         GetDoc()->getIDocumentLayoutAccess().CopyLayoutFormat( *pCpyFormat, aAnchor, true, true );
    1096           0 :                     }
    1097           1 :                 }
    1098             :             }
    1099             :         }
    1100             :     }
    1101             : 
    1102           2 :     GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
    1103             : 
    1104             :     // have new table formulas been inserted?
    1105           2 :     if( pTableFieldTyp->HasWriterListeners() )
    1106             :     {
    1107             :         // finish old action: table-frames have been created
    1108             :         // a selection can be made now
    1109             :         sal_uInt16 nActCnt;
    1110           0 :         for( nActCnt = 0; ActionPend(); ++nActCnt )
    1111           0 :             EndAllAction();
    1112             : 
    1113           0 :         for( ; nActCnt; --nActCnt )
    1114           0 :             StartAllAction();
    1115             :     }
    1116           2 :     GetDoc()->getIDocumentFieldsAccess().UnlockExpFields();
    1117           2 :     GetDoc()->getIDocumentFieldsAccess().UpdateFields(NULL, false);
    1118           2 :     EndAllAction();
    1119             : 
    1120           4 :     return bRet;
    1121             : }
    1122             : 
    1123           0 : bool SwFEShell::PastePages( SwFEShell& rToFill, sal_uInt16 nStartPage, sal_uInt16 nEndPage)
    1124             : {
    1125           0 :     Push();
    1126           0 :     if(!GotoPage(nStartPage))
    1127             :     {
    1128           0 :         Pop(false);
    1129           0 :         return false;
    1130             :     }
    1131           0 :     MovePage( fnPageCurr, fnPageStart );
    1132           0 :     SwPaM aCpyPam( *GetCrsr()->GetPoint() );
    1133           0 :     OUString sStartingPageDesc = GetPageDesc( GetCurPageDesc()).GetName();
    1134           0 :     SwPageDesc* pDesc = rToFill.FindPageDescByName( sStartingPageDesc, true );
    1135           0 :     if( pDesc )
    1136           0 :         rToFill.ChgCurPageDesc( *pDesc );
    1137             : 
    1138           0 :     if(!GotoPage(nEndPage))
    1139             :     {
    1140           0 :         Pop(false);
    1141           0 :         return false;
    1142             :     }
    1143             :     //if the page starts with a table a paragraph has to be inserted before
    1144           0 :     SwNode* pTableNode = aCpyPam.GetNode().FindTableNode();
    1145           0 :     if(pTableNode)
    1146             :     {
    1147             :         //insert a paragraph
    1148           0 :         StartUndo(UNDO_INSERT);
    1149           0 :         SwNodeIndex aTableIdx(  *pTableNode, -1 );
    1150           0 :         SwPosition aBefore(aTableIdx);
    1151           0 :         if(GetDoc()->getIDocumentContentOperations().AppendTextNode( aBefore ))
    1152             :         {
    1153           0 :             SwPaM aTmp(aBefore);
    1154           0 :             aCpyPam = aTmp;
    1155             :         }
    1156           0 :         EndUndo(UNDO_INSERT);
    1157             :     }
    1158             : 
    1159           0 :     MovePage( fnPageCurr, fnPageEnd );
    1160           0 :     aCpyPam.SetMark();
    1161           0 :     *aCpyPam.GetMark() = *GetCrsr()->GetPoint();
    1162             : 
    1163           0 :     SET_CURR_SHELL( this );
    1164             : 
    1165           0 :     StartAllAction();
    1166           0 :     GetDoc()->getIDocumentFieldsAccess().LockExpFields();
    1167           0 :     SetSelection(aCpyPam);
    1168             :     // copy the text of the selection
    1169           0 :     SwEditShell::Copy(&rToFill);
    1170             : 
    1171           0 :     if(pTableNode)
    1172             :     {
    1173             :         //remove the inserted paragraph
    1174           0 :         Undo();
    1175             :         //remove the paragraph in the second doc, too
    1176           0 :         SwNodeIndex aIdx( rToFill.GetDoc()->GetNodes().GetEndOfExtras(), 2 );
    1177           0 :         SwPaM aPara( aIdx ); //DocStart
    1178           0 :         rToFill.GetDoc()->getIDocumentContentOperations().DelFullPara(aPara);
    1179             :     }
    1180             :     // now the page bound objects
    1181             :     // additionally copy page bound frames
    1182           0 :     if( GetDoc()->GetSpzFrameFormats()->size() )
    1183             :     {
    1184             :         // create a draw view if necessary
    1185           0 :         if( !rToFill.Imp()->GetDrawView() )
    1186           0 :             rToFill.MakeDrawView();
    1187             : 
    1188           0 :         for ( auto pCpyFormat : *GetDoc()->GetSpzFrameFormats() )
    1189             :         {
    1190           0 :             SwFormatAnchor aAnchor( pCpyFormat->GetAnchor() );
    1191           0 :             if ((FLY_AT_PAGE == aAnchor.GetAnchorId()) &&
    1192           0 :                     aAnchor.GetPageNum() >= nStartPage && aAnchor.GetPageNum() <= nEndPage)
    1193             :             {
    1194           0 :                 aAnchor.SetPageNum( aAnchor.GetPageNum() - nStartPage + 1);
    1195             :             }
    1196             :             else
    1197           0 :                 continue;
    1198           0 :             rToFill.GetDoc()->getIDocumentLayoutAccess().CopyLayoutFormat( *pCpyFormat, aAnchor, true, true );
    1199           0 :         }
    1200             :     }
    1201           0 :     GetDoc()->getIDocumentFieldsAccess().UnlockExpFields();
    1202           0 :     GetDoc()->getIDocumentFieldsAccess().UpdateFields(NULL, false);
    1203           0 :     Pop(false);
    1204           0 :     EndAllAction();
    1205             : 
    1206           0 :     return true;
    1207             : }
    1208             : 
    1209           0 : bool SwFEShell::GetDrawObjGraphic( SotClipboardFormatId nFormat, Graphic& rGrf ) const
    1210             : {
    1211             :     OSL_ENSURE( Imp()->HasDrawView(), "GetDrawObjGraphic without DrawView?" );
    1212           0 :     const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
    1213           0 :     bool bConvert = true;
    1214           0 :     if( rMrkList.GetMarkCount() )
    1215             :     {
    1216           0 :         if( rMrkList.GetMarkCount() == 1 &&
    1217           0 :             rMrkList.GetMark( 0 )->GetMarkedSdrObj()->ISA(SwVirtFlyDrawObj) )
    1218             :         {
    1219             :             // select frame
    1220           0 :             if( CNT_GRF == GetCntType() )
    1221             :             {
    1222           0 :                 const Graphic* pGrf( GetGraphic() );
    1223           0 :                 if ( pGrf )
    1224             :                 {
    1225           0 :                     Graphic aGrf( *pGrf );
    1226           0 :                     if( SotClipboardFormatId::GDIMETAFILE == nFormat )
    1227             :                     {
    1228           0 :                         if( GRAPHIC_BITMAP != aGrf.GetType() )
    1229             :                         {
    1230           0 :                             rGrf = aGrf;
    1231           0 :                             bConvert = false;
    1232             :                         }
    1233           0 :                         else if( GetWin() )
    1234             :                         {
    1235           0 :                             Size aSz;
    1236           0 :                             Point aPt;
    1237           0 :                             GetGrfSize( aSz );
    1238             : 
    1239           0 :                             ScopedVclPtrInstance< VirtualDevice > pVirtDev;
    1240           0 :                             pVirtDev->EnableOutput( false );
    1241             : 
    1242           0 :                             MapMode aTmp( GetWin()->GetMapMode() );
    1243           0 :                             aTmp.SetOrigin( aPt );
    1244           0 :                             pVirtDev->SetMapMode( aTmp );
    1245             : 
    1246           0 :                             GDIMetaFile aMtf;
    1247           0 :                             aMtf.Record( pVirtDev.get() );
    1248           0 :                             aGrf.Draw( pVirtDev, aPt, aSz );
    1249           0 :                             aMtf.Stop();
    1250           0 :                             aMtf.SetPrefMapMode( aTmp );
    1251           0 :                             aMtf.SetPrefSize( aSz );
    1252           0 :                             rGrf = aMtf;
    1253             :                         }
    1254             :                     }
    1255           0 :                     else if( GRAPHIC_BITMAP == aGrf.GetType() )
    1256             :                     {
    1257           0 :                         rGrf = aGrf;
    1258           0 :                         bConvert = false;
    1259             :                     }
    1260             :                     else
    1261             :                     {
    1262             :                         // fix(23806): not the origial size, but the current one.
    1263             :                         // Otherwise it could happen that for vector graphics
    1264             :                         // many MB's of memory are allocated.
    1265           0 :                         const Size aSz( FindFlyFrm()->Prt().SSize() );
    1266           0 :                         ScopedVclPtrInstance< VirtualDevice > pVirtDev(*GetWin());
    1267             : 
    1268           0 :                         MapMode aTmp( MAP_TWIP );
    1269           0 :                         pVirtDev->SetMapMode( aTmp );
    1270           0 :                         if( pVirtDev->SetOutputSize( aSz ) )
    1271             :                         {
    1272           0 :                             aGrf.Draw( pVirtDev.get(), Point(), aSz );
    1273           0 :                             rGrf = pVirtDev->GetBitmap( Point(), aSz );
    1274             :                         }
    1275             :                         else
    1276             :                         {
    1277           0 :                             rGrf = aGrf;
    1278           0 :                             bConvert = false;
    1279           0 :                         }
    1280           0 :                     }
    1281             :                 }
    1282             :             }
    1283             :         }
    1284           0 :         else if( SotClipboardFormatId::GDIMETAFILE == nFormat )
    1285           0 :             rGrf = Imp()->GetDrawView()->GetMarkedObjMetaFile();
    1286           0 :         else if( SotClipboardFormatId::BITMAP == nFormat || SotClipboardFormatId::PNG == nFormat )
    1287           0 :             rGrf = Imp()->GetDrawView()->GetMarkedObjBitmapEx();
    1288             :     }
    1289           0 :     return bConvert;
    1290             : }
    1291             : 
    1292             : // #i50824#
    1293             : // replace method <lcl_RemoveOleObjsFromSdrModel> by <lcl_ConvertSdrOle2ObjsToSdrGrafObjs>
    1294           0 : static void lcl_ConvertSdrOle2ObjsToSdrGrafObjs( SdrModel* _pModel )
    1295             : {
    1296           0 :     for ( sal_uInt16 nPgNum = 0; nPgNum < _pModel->GetPageCount(); ++nPgNum )
    1297             :     {
    1298             :         // setup object iterator in order to iterate through all objects
    1299             :         // including objects in group objects, but exclusive group objects.
    1300           0 :         SdrObjListIter aIter(*(_pModel->GetPage( nPgNum )));
    1301           0 :         while( aIter.IsMore() )
    1302             :         {
    1303           0 :             SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( aIter.Next() );
    1304           0 :             if( pOle2Obj )
    1305             :             {
    1306             :                 // found an ole2 shape
    1307           0 :                 SdrObjList* pObjList = pOle2Obj->GetObjList();
    1308             : 
    1309             :                 // get its graphic
    1310           0 :                 Graphic aGraphic;
    1311           0 :                 pOle2Obj->Connect();
    1312           0 :                 const Graphic* pGraphic = pOle2Obj->GetGraphic();
    1313           0 :                 if( pGraphic )
    1314           0 :                     aGraphic = *pGraphic;
    1315           0 :                 pOle2Obj->Disconnect();
    1316             : 
    1317             :                 // create new graphic shape with the ole graphic and shape size
    1318           0 :                 SdrGrafObj* pGraphicObj = new SdrGrafObj( aGraphic, pOle2Obj->GetCurrentBoundRect() );
    1319             :                 // apply layer of ole2 shape at graphic shape
    1320           0 :                 pGraphicObj->SetLayer( pOle2Obj->GetLayer() );
    1321             : 
    1322             :                 // replace ole2 shape with the new graphic object and delete the ol2 shape
    1323           0 :                 SdrObject* pRemovedObject = pObjList->ReplaceObject( pGraphicObj, pOle2Obj->GetOrdNum() );
    1324           0 :                 SdrObject::Free( pRemovedObject );
    1325             :             }
    1326             :         }
    1327           0 :     }
    1328           0 : }
    1329             : 
    1330           0 : void SwFEShell::Paste( SvStream& rStrm, sal_uInt16 nAction, const Point* pPt )
    1331             : {
    1332           0 :     SET_CURR_SHELL( this );
    1333           0 :     StartAllAction();
    1334           0 :     StartUndo();
    1335             : 
    1336           0 :     SvtPathOptions aPathOpt;
    1337             :     FmFormModel* pModel = new FmFormModel( aPathOpt.GetPalettePath(),
    1338           0 :                                             0, GetDoc()->GetDocShell() );
    1339           0 :     pModel->GetItemPool().FreezeIdRanges();
    1340             : 
    1341           0 :     rStrm.Seek(0);
    1342             : 
    1343           0 :     uno::Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( rStrm ) );
    1344           0 :     SvxDrawingLayerImport( pModel, xInputStream );
    1345             : 
    1346           0 :     if ( !Imp()->HasDrawView() )
    1347           0 :         Imp()->MakeDrawView();
    1348             : 
    1349           0 :     Point aPos( pPt ? *pPt : GetCharRect().Pos() );
    1350           0 :     SdrView *pView = Imp()->GetDrawView();
    1351             : 
    1352             :     // drop on the existing object: replace object or apply new attributes
    1353           0 :     if( pModel->GetPageCount() > 0 &&
    1354           0 :         1 == pModel->GetPage(0)->GetObjCount() &&
    1355           0 :         1 == pView->GetMarkedObjectList().GetMarkCount() )
    1356             :     {
    1357             :         // replace a marked 'virtual' drawing object
    1358             :         // by its corresponding 'master' drawing object in the mark list.
    1359           0 :         SwDrawView::ReplaceMarkedDrawVirtObjs( *pView );
    1360             : 
    1361           0 :         SdrObject* pClpObj = pModel->GetPage(0)->GetObj(0);
    1362           0 :         SdrObject* pOldObj = pView->GetMarkedObjectList().GetMark( 0 )->GetMarkedSdrObj();
    1363             : 
    1364           0 :         if( SW_PASTESDR_SETATTR == nAction && pOldObj->ISA(SwVirtFlyDrawObj) )
    1365           0 :             nAction = SW_PASTESDR_REPLACE;
    1366             : 
    1367           0 :         switch( nAction )
    1368             :         {
    1369             :         case SW_PASTESDR_REPLACE:
    1370             :             {
    1371           0 :                 const SwFrameFormat* pFormat(0);
    1372           0 :                 const SwFrm* pAnchor(0);
    1373           0 :                 if( pOldObj->ISA(SwVirtFlyDrawObj) )
    1374             :                 {
    1375           0 :                     pFormat = FindFrameFormat( pOldObj );
    1376             : 
    1377           0 :                     Point aNullPt;
    1378           0 :                     SwFlyFrm* pFlyFrm = static_cast<const SwFlyFrameFormat*>(pFormat)->GetFrm( &aNullPt );
    1379           0 :                     pAnchor = pFlyFrm ? pFlyFrm->GetAnchorFrm() : NULL;
    1380             : 
    1381           0 :                     if (!pAnchor || pAnchor->FindFooterOrHeader())
    1382             :                     {
    1383             :                         // if there is a textframe in the header/footer:
    1384             :                         // do not replace but insert
    1385           0 :                         nAction = SW_PASTESDR_INSERT;
    1386           0 :                         break;
    1387             :                     }
    1388             :                 }
    1389             : 
    1390           0 :                 SdrObject* pNewObj = pClpObj->Clone();
    1391           0 :                 Rectangle aOldObjRect( pOldObj->GetCurrentBoundRect() );
    1392           0 :                 Size aOldObjSize( aOldObjRect.GetSize() );
    1393           0 :                 Rectangle aNewRect( pNewObj->GetCurrentBoundRect() );
    1394           0 :                 Size aNewSize( aNewRect.GetSize() );
    1395             : 
    1396           0 :                 Fraction aScaleWidth( aOldObjSize.Width(), aNewSize.Width() );
    1397           0 :                 Fraction aScaleHeight( aOldObjSize.Height(), aNewSize.Height());
    1398           0 :                 pNewObj->NbcResize( aNewRect.TopLeft(), aScaleWidth, aScaleHeight);
    1399             : 
    1400           0 :                 Point aVec = aOldObjRect.TopLeft() - aNewRect.TopLeft();
    1401           0 :                 pNewObj->NbcMove(Size(aVec.getX(), aVec.getY()));
    1402             : 
    1403           0 :                 if( pNewObj->ISA( SdrUnoObj ) )
    1404           0 :                     pNewObj->SetLayer( GetDoc()->getIDocumentDrawModelAccess().GetControlsId() );
    1405           0 :                 else if( pOldObj->ISA( SdrUnoObj ) )
    1406           0 :                     pNewObj->SetLayer( GetDoc()->getIDocumentDrawModelAccess().GetHeavenId() );
    1407             :                 else
    1408           0 :                     pNewObj->SetLayer( pOldObj->GetLayer() );
    1409             : 
    1410           0 :                 if( pOldObj->ISA(SwVirtFlyDrawObj) )
    1411             :                 {
    1412             :                     // store attributes, then set SdrObject
    1413           0 :                     SfxItemSet aFrmSet( mpDoc->GetAttrPool(),
    1414           0 :                                             RES_SURROUND, RES_ANCHOR );
    1415           0 :                     aFrmSet.Set( pFormat->GetAttrSet() );
    1416             : 
    1417           0 :                     Point aNullPt;
    1418           0 :                     if( pAnchor->IsTextFrm() && static_cast<const SwTextFrm*>(pAnchor)->IsFollow() )
    1419             :                     {
    1420           0 :                         const SwTextFrm* pTmp = static_cast<const SwTextFrm*>(pAnchor);
    1421           0 :                         do {
    1422           0 :                             pTmp = pTmp->FindMaster();
    1423             :                             OSL_ENSURE( pTmp, "Where's my Master?" );
    1424           0 :                         } while( pTmp->IsFollow() );
    1425           0 :                         pAnchor = pTmp;
    1426             :                     }
    1427           0 :                     if( pOldObj->ISA( SdrCaptionObj ))
    1428           0 :                         aNullPt = static_cast<SdrCaptionObj*>(pOldObj)->GetTailPos();
    1429             :                     else
    1430           0 :                         aNullPt = aOldObjRect.TopLeft();
    1431             : 
    1432           0 :                     Point aNewAnchor = pAnchor->GetFrmAnchorPos( ::HasWrap( pOldObj ) );
    1433             :                     // OD 2004-04-05 #i26791# - direct positioning of Writer
    1434             :                     // fly frame object for <SwDoc::Insert(..)>
    1435           0 :                     pNewObj->NbcSetRelativePos( aNullPt - aNewAnchor );
    1436           0 :                     pNewObj->NbcSetAnchorPos( aNewAnchor );
    1437             : 
    1438           0 :                     pOldObj->GetOrdNum();
    1439             : 
    1440           0 :                     DelSelectedObj();
    1441             : 
    1442           0 :                     GetDoc()->getIDocumentContentOperations().InsertDrawObj( *GetCrsr(), *pNewObj, aFrmSet );
    1443             :                 }
    1444             :                 else
    1445             :                 {
    1446             :                     // #i123922#  for handling MasterObject and virtual ones correctly, SW
    1447             :                     // wants us to call ReplaceObject at the page, but that also
    1448             :                     // triggers the same assertion (I tried it), so stay at the view method
    1449           0 :                     pView->ReplaceObjectAtView(pOldObj, *Imp()->GetPageView(), pNewObj);
    1450           0 :                 }
    1451             :             }
    1452           0 :             break;
    1453             : 
    1454             :         case SW_PASTESDR_SETATTR:
    1455             :             {
    1456           0 :                 SfxItemSet aSet( GetAttrPool() );
    1457           0 :                 const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(pClpObj);
    1458             : 
    1459           0 :                 if(pSdrGrafObj)
    1460             :                 {
    1461           0 :                     SdrObject* pTarget = 0;
    1462             : 
    1463           0 :                     if(0 != pView->GetMarkedObjectList().GetMarkCount())
    1464             :                     {
    1465             :                         // try to get target (if it's at least one, take first)
    1466           0 :                         SdrMark* pMark = pView->GetMarkedObjectList().GetMark(0);
    1467             : 
    1468           0 :                         if(pMark)
    1469             :                         {
    1470           0 :                             pTarget = pMark->GetMarkedSdrObj();
    1471             :                         }
    1472             :                     }
    1473             : 
    1474           0 :                     if(pTarget)
    1475             :                     {
    1476             :                         // copy ItemSet from target
    1477           0 :                         aSet.Set(pTarget->GetMergedItemSet());
    1478             :                     }
    1479             : 
    1480             :                     // for SdrGrafObj, use the graphic as fill style argument
    1481           0 :                     const Graphic& rGraphic = pSdrGrafObj->GetGraphic();
    1482             : 
    1483           0 :                     if(GRAPHIC_NONE != rGraphic.GetType() && GRAPHIC_DEFAULT != rGraphic.GetType())
    1484             :                     {
    1485           0 :                         aSet.Put(XFillBitmapItem(OUString(), rGraphic));
    1486           0 :                         aSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP));
    1487             :                     }
    1488             :                 }
    1489             :                 else
    1490             :                 {
    1491           0 :                     aSet.Put(pClpObj->GetMergedItemSet());
    1492             :                 }
    1493             : 
    1494           0 :                 pView->SetAttributes( aSet, false );
    1495             :             }
    1496           0 :             break;
    1497             : 
    1498             :         default:
    1499           0 :             nAction = SW_PASTESDR_INSERT;
    1500           0 :             break;
    1501             :         }
    1502             :     }
    1503             :     else
    1504           0 :         nAction = SW_PASTESDR_INSERT;
    1505             : 
    1506           0 :     if( SW_PASTESDR_INSERT == nAction )
    1507             :     {
    1508           0 :         ::sw::DrawUndoGuard drawUndoGuard(GetDoc()->GetIDocumentUndoRedo());
    1509             : 
    1510           0 :         bool bDesignMode = pView->IsDesignMode();
    1511           0 :         if( !bDesignMode )
    1512           0 :             pView->SetDesignMode( true );
    1513             : 
    1514             :         // #i50824#
    1515             :         // method <lcl_RemoveOleObjsFromSdrModel> replaced by <lcl_ConvertSdrOle2ObjsToSdrGrafObjs>
    1516           0 :         lcl_ConvertSdrOle2ObjsToSdrGrafObjs( pModel );
    1517           0 :         pView->Paste(*pModel, aPos, NULL, SdrInsertFlags::NONE, OUString(), OUString());
    1518             : 
    1519           0 :         const size_t nCnt = pView->GetMarkedObjectList().GetMarkCount();
    1520           0 :         if( nCnt )
    1521             :         {
    1522           0 :             const Point aNull( 0, 0 );
    1523           0 :             for( size_t i=0; i < nCnt; ++i )
    1524             :             {
    1525           0 :                 SdrObject *pObj = pView->GetMarkedObjectList().GetMark(i)->GetMarkedSdrObj();
    1526           0 :                 pObj->ImpSetAnchorPos( aNull );
    1527             :             }
    1528             : 
    1529           0 :             pView->SetCurrentObj( OBJ_GRUP, SdrInventor );
    1530           0 :             if ( nCnt > 1 )
    1531           0 :                 pView->GroupMarked();
    1532           0 :             SdrObject *pObj = pView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
    1533           0 :             if( pObj->ISA( SdrUnoObj ) )
    1534             :             {
    1535           0 :                 pObj->SetLayer( GetDoc()->getIDocumentDrawModelAccess().GetControlsId() );
    1536           0 :                 bDesignMode = true;
    1537             :             }
    1538             :             else
    1539           0 :                 pObj->SetLayer( GetDoc()->getIDocumentDrawModelAccess().GetHeavenId() );
    1540           0 :             const Rectangle &rSnap = pObj->GetSnapRect();
    1541           0 :             const Size aDiff( rSnap.GetWidth()/2, rSnap.GetHeight()/2 );
    1542           0 :             pView->MoveMarkedObj( aDiff );
    1543           0 :             ImpEndCreate();
    1544           0 :             if( !bDesignMode )
    1545           0 :                 pView->SetDesignMode( false );
    1546           0 :         }
    1547             :     }
    1548           0 :     EndUndo();
    1549           0 :     EndAllAction();
    1550           0 :     delete pModel;
    1551           0 : }
    1552             : 
    1553           0 : bool SwFEShell::Paste(const Graphic &rGrf, const OUString& rURL)
    1554             : {
    1555           0 :     SET_CURR_SHELL( this );
    1556           0 :     SdrObject* pObj = 0;
    1557           0 :     SdrView *pView = Imp()->GetDrawView();
    1558             : 
    1559           0 :     bool bRet = 1 == pView->GetMarkedObjectList().GetMarkCount() &&
    1560           0 :         (pObj = pView->GetMarkedObjectList().GetMark( 0 )->GetMarkedSdrObj())->IsClosedObj() &&
    1561           0 :         !pObj->ISA( SdrOle2Obj );
    1562             : 
    1563           0 :     if( bRet && pObj )
    1564             :     {
    1565             :         // #i123922# added code to handle the two cases of SdrGrafObj and a fillable, non-
    1566             :         // OLE object in focus
    1567           0 :         SdrObject* pResult = pObj;
    1568             : 
    1569           0 :         if(dynamic_cast< SdrGrafObj* >(pObj))
    1570             :         {
    1571           0 :             SdrGrafObj* pNewGrafObj = static_cast<SdrGrafObj*>(pObj->Clone());
    1572             : 
    1573           0 :             pNewGrafObj->SetGraphic(rGrf);
    1574             : 
    1575             :             // #i123922#  for handling MasterObject and virtual ones correctly, SW
    1576             :             // wants us to call ReplaceObject at the page, but that also
    1577             :             // triggers the same assertion (I tried it), so stay at the view method
    1578           0 :             pView->ReplaceObjectAtView(pObj, *pView->GetSdrPageView(), pNewGrafObj);
    1579             : 
    1580           0 :             OUString aReferer;
    1581           0 :             SwDocShell *pDocShell = GetDoc()->GetDocShell();
    1582           0 :             if (pDocShell->HasName()) {
    1583           0 :                 aReferer = pDocShell->GetMedium()->GetName();
    1584             :             }
    1585             : 
    1586             :             // set in all cases - the Clone() will have copied an existing link (!)
    1587           0 :             pNewGrafObj->SetGraphicLink(rURL, aReferer, OUString());
    1588             : 
    1589           0 :             pResult = pNewGrafObj;
    1590             :         }
    1591             :         else
    1592             :         {
    1593           0 :             pView->AddUndo(new SdrUndoAttrObj(*pObj));
    1594             : 
    1595           0 :             SfxItemSet aSet(pView->GetModel()->GetItemPool(), XATTR_FILLSTYLE, XATTR_FILLBITMAP);
    1596             : 
    1597           0 :             aSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP));
    1598           0 :             aSet.Put(XFillBitmapItem(OUString(), rGrf));
    1599           0 :             pObj->SetMergedItemSetAndBroadcast(aSet);
    1600             :         }
    1601             : 
    1602             :         // we are done; mark the modified/new object
    1603           0 :         pView->MarkObj(pResult, pView->GetSdrPageView());
    1604             :     }
    1605             : 
    1606           0 :     return bRet;
    1607         177 : }
    1608             : 
    1609             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11