LCOV - code coverage report
Current view: top level - sw/source/core/frmedt - fecopy.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 817 0.0 %
Date: 2014-04-14 Functions: 0 11 0.0 %
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 <rootfrm.hxx>
      58             : #include <ndtxt.hxx>
      59             : #include <pam.hxx>
      60             : #include <tblsel.hxx>
      61             : #include <swtable.hxx>
      62             : #include <flyfrm.hxx>
      63             : #include <pagefrm.hxx>
      64             : #include <fldbas.hxx>
      65             : #include <edimp.hxx>
      66             : #include <swundo.hxx>
      67             : #include <viewimp.hxx>
      68             : #include <dview.hxx>
      69             : #include <dcontact.hxx>
      70             : #include <dflyobj.hxx>
      71             : #include <docsh.hxx>
      72             : #include <pagedesc.hxx>
      73             : #include <mvsave.hxx>
      74             : #include <vcl/virdev.hxx>
      75             : #include <svx/svdundo.hxx>
      76             : 
      77             : using namespace ::com::sun::star;
      78             : 
      79             : /*************************************************************************
      80             : |*
      81             : |*  SwFEShell::Copy()   copy for the internal clipboard.
      82             : |*      Copies all selections to the clipboard.
      83             : |*
      84             : |*************************************************************************/
      85             : 
      86           0 : sal_Bool SwFEShell::Copy( SwDoc* pClpDoc, const OUString* pNewClpTxt )
      87             : {
      88             :     OSL_ENSURE( pClpDoc, "kein Clipboard-Dokument"  );
      89             : 
      90           0 :     pClpDoc->GetIDocumentUndoRedo().DoUndo(false); // always false!
      91             : 
      92             :     // delete content if ClpDocument contains content
      93           0 :     SwNodeIndex aSttIdx( pClpDoc->GetNodes().GetEndOfExtras(), 2 );
      94           0 :     SwTxtNode* pTxtNd = aSttIdx.GetNode().GetTxtNode();
      95           0 :     if (!pTxtNd || !pTxtNd->GetTxt().isEmpty() ||
      96           0 :         aSttIdx.GetIndex()+1 != pClpDoc->GetNodes().GetEndOfContent().GetIndex() )
      97             :     {
      98           0 :         pClpDoc->GetNodes().Delete( aSttIdx,
      99           0 :             pClpDoc->GetNodes().GetEndOfContent().GetIndex() - aSttIdx.GetIndex() );
     100           0 :         pTxtNd = pClpDoc->GetNodes().MakeTxtNode( aSttIdx,
     101           0 :                             (SwTxtFmtColl*)pClpDoc->GetDfltTxtFmtColl() );
     102           0 :         aSttIdx--;
     103             :     }
     104             : 
     105             :     // also delete surrounding FlyFrames if any
     106           0 :     for( sal_uInt16 n = 0; n < pClpDoc->GetSpzFrmFmts()->size(); ++n )
     107             :     {
     108           0 :         SwFlyFrmFmt* pFly = (SwFlyFrmFmt*)(*pClpDoc->GetSpzFrmFmts())[n];
     109           0 :         pClpDoc->DelLayoutFmt( pFly );
     110             :     }
     111           0 :     pClpDoc->GCFieldTypes();        // delete the FieldTypes
     112             : 
     113             :     // if a string was passed, copy it to the clipboard-
     114             :     // document. Then also the Calculator can use the internal
     115             :     // clipboard
     116           0 :     if( pNewClpTxt )
     117             :     {
     118           0 :         pTxtNd->InsertText( *pNewClpTxt, SwIndex( pTxtNd ) );
     119           0 :         return sal_True;                // das wars.
     120             :     }
     121             : 
     122           0 :     pClpDoc->LockExpFlds();
     123           0 :     pClpDoc->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_DELETE_REDLINES );
     124             :     sal_Bool bRet;
     125             : 
     126             :     // do we want to copy a FlyFrame?
     127           0 :     if( IsFrmSelected() )
     128             :     {
     129             :         // get the FlyFormat
     130           0 :         SwFlyFrm* pFly = FindFlyFrm();
     131           0 :         SwFrmFmt* pFlyFmt = pFly->GetFmt();
     132           0 :         SwFmtAnchor aAnchor( pFlyFmt->GetAnchor() );
     133             : 
     134           0 :         if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     135           0 :             (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     136           0 :             (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     137           0 :             (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     138             :         {
     139           0 :             SwPosition aPos( aSttIdx );
     140           0 :             if ( FLY_AS_CHAR == aAnchor.GetAnchorId() )
     141             :             {
     142           0 :                 aPos.nContent.Assign( pTxtNd, 0 );
     143             :             }
     144           0 :             aAnchor.SetAnchor( &aPos );
     145             :         }
     146           0 :         pFlyFmt = pClpDoc->CopyLayoutFmt( *pFlyFmt, aAnchor, true, true );
     147             : 
     148             :        // assure the "RootFmt" is the first element in Spz-Array
     149             :         // (if necessary Flys were copied in Flys)
     150           0 :         SwFrmFmts& rSpzFrmFmts = *(SwFrmFmts*)pClpDoc->GetSpzFrmFmts();
     151           0 :         if( rSpzFrmFmts[ 0 ] != pFlyFmt )
     152             :         {
     153           0 :             SwFrmFmts::iterator it = std::find( rSpzFrmFmts.begin(), rSpzFrmFmts.end(), pFlyFmt );
     154             :             OSL_ENSURE( it != rSpzFrmFmts.end(), "Fly not contained in Spz-Array" );
     155             : 
     156           0 :             rSpzFrmFmts.erase( it );
     157           0 :             rSpzFrmFmts.insert( rSpzFrmFmts.begin(), pFlyFmt );
     158             :         }
     159             : 
     160           0 :         if ( FLY_AS_CHAR == aAnchor.GetAnchorId() )
     161             :         {
     162             :             // JP 13.02.99  Bug 61863: if a frameselection is passed to the
     163             :             //              clipboard, it should be found at pasting. Therefore
     164             :             //              the copied TextAttribut should be removed in the node
     165             :             //              otherwise it will be recognised as TextSelektion
     166           0 :             const SwIndex& rIdx = pFlyFmt->GetAnchor().GetCntntAnchor()->nContent;
     167             :             SwTxtFlyCnt *const pTxtFly = static_cast<SwTxtFlyCnt *>(
     168             :                 pTxtNd->GetTxtAttrForCharAt(
     169           0 :                     rIdx.GetIndex(), RES_TXTATR_FLYCNT));
     170           0 :             if( pTxtFly )
     171             :             {
     172           0 :                 ((SwFmtFlyCnt&)pTxtFly->GetFlyCnt()).SetFlyFmt( 0 );
     173           0 :                 pTxtNd->EraseText( rIdx, 1 );
     174             :             }
     175             :         }
     176           0 :         bRet = sal_True;
     177             :     }
     178           0 :     else if ( IsObjSelected() )
     179             :     {
     180           0 :         SwPosition aPos( aSttIdx, SwIndex( pTxtNd, 0 ));
     181           0 :         const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
     182           0 :         for ( sal_uInt16 i = 0; i < rMrkList.GetMarkCount(); ++i )
     183             :         {
     184           0 :             SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
     185             : 
     186           0 :             if( Imp()->GetDrawView()->IsGroupEntered() ||
     187           0 :                 ( !pObj->GetUserCall() && pObj->GetUpGroup()) )
     188             :             {
     189           0 :                 SfxItemSet aSet( pClpDoc->GetAttrPool(), aFrmFmtSetRange );
     190             : 
     191           0 :                 SwFmtAnchor aAnchor( FLY_AT_PARA );
     192           0 :                 aAnchor.SetAnchor( &aPos );
     193           0 :                 aSet.Put( aAnchor );
     194             : 
     195             :                 SdrObject *const pNew =
     196           0 :                     pClpDoc->CloneSdrObj( *pObj, false, true );
     197             : 
     198           0 :                 SwPaM aTemp(aPos);
     199           0 :                 pClpDoc->InsertDrawObj(aTemp, *pNew, aSet );
     200             :             }
     201             :             else
     202             :             {
     203           0 :                 SwDrawContact *pContact = (SwDrawContact*)GetUserCall( pObj );
     204           0 :                 SwFrmFmt *pFmt = pContact->GetFmt();
     205           0 :                 SwFmtAnchor aAnchor( pFmt->GetAnchor() );
     206           0 :                 if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     207           0 :                     (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     208           0 :                     (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     209           0 :                     (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     210             :                 {
     211           0 :                     aAnchor.SetAnchor( &aPos );
     212             :                 }
     213             : 
     214           0 :                 pClpDoc->CopyLayoutFmt( *pFmt, aAnchor, true, true );
     215             :             }
     216             :         }
     217           0 :         bRet = sal_True;
     218             :     }
     219             :     else
     220           0 :         bRet = _CopySelToDoc( pClpDoc, 0 );     // copy the selections
     221             : 
     222           0 :     pClpDoc->SetRedlineMode_intern((RedlineMode_t)0 );
     223           0 :     pClpDoc->UnlockExpFlds();
     224           0 :     if( !pClpDoc->IsExpFldsLocked() )
     225           0 :         pClpDoc->UpdateExpFlds(NULL, true);
     226             : 
     227           0 :     return bRet;
     228             : }
     229             : 
     230           0 : static const Point &lcl_FindBasePos( const SwFrm *pFrm, const Point &rPt )
     231             : {
     232           0 :     const SwFrm *pF = pFrm;
     233           0 :     while ( pF && !pF->Frm().IsInside( rPt ) )
     234             :     {
     235           0 :         if ( pF->IsCntntFrm() )
     236           0 :             pF = ((SwCntntFrm*)pF)->GetFollow();
     237             :         else
     238           0 :             pF = 0;
     239             :     }
     240           0 :     if ( pF )
     241           0 :         return pF->Frm().Pos();
     242             :     else
     243           0 :         return pFrm->Frm().Pos();
     244             : }
     245             : 
     246           0 : static sal_Bool lcl_SetAnchor( const SwPosition& rPos, const SwNode& rNd, SwFlyFrm* pFly,
     247             :                 const Point& rInsPt, SwFEShell& rDestShell, SwFmtAnchor& rAnchor,
     248             :                 Point& rNewPos, bool bCheckFlyRecur )
     249             : {
     250           0 :     sal_Bool bRet = sal_True;
     251           0 :     rAnchor.SetAnchor( &rPos );
     252           0 :     SwCntntFrm* pTmpFrm = rNd.GetCntntNode()->getLayoutFrm( rDestShell.GetLayout(), &rInsPt, 0, false );
     253           0 :     SwFlyFrm *pTmpFly = pTmpFrm->FindFlyFrm();
     254           0 :     if( pTmpFly && bCheckFlyRecur && pFly->IsUpperOf( *pTmpFly ) )
     255             :     {
     256           0 :         bRet = sal_False;
     257             :     }
     258           0 :     else if ( FLY_AT_FLY == rAnchor.GetAnchorId() )
     259             :     {
     260           0 :         if( pTmpFly )
     261             :         {
     262           0 :             const SwNodeIndex& rIdx = *pTmpFly->GetFmt()->GetCntnt().GetCntntIdx();
     263           0 :             SwPosition aPos( rIdx );
     264           0 :             rAnchor.SetAnchor( &aPos );
     265           0 :             rNewPos = pTmpFly->Frm().Pos();
     266             :         }
     267             :         else
     268             :         {
     269           0 :             rAnchor.SetType( FLY_AT_PAGE );
     270           0 :             rAnchor.SetPageNum( rDestShell.GetPageNumber( rInsPt ) );
     271           0 :             const SwFrm *pPg = pTmpFrm->FindPageFrm();
     272           0 :             rNewPos = pPg->Frm().Pos();
     273             :         }
     274             :     }
     275             :     else
     276           0 :         rNewPos = ::lcl_FindBasePos( pTmpFrm, rInsPt );
     277           0 :     return bRet;
     278             : }
     279             : 
     280           0 : sal_Bool SwFEShell::CopyDrawSel( SwFEShell* pDestShell, const Point& rSttPt,
     281             :                     const Point& rInsPt, sal_Bool bIsMove, sal_Bool bSelectInsert )
     282             : {
     283           0 :     sal_Bool bRet = sal_True;
     284             : 
     285             :     // The list should be copied, because below new objects will be selected
     286           0 :     const SdrMarkList aMrkList( Imp()->GetDrawView()->GetMarkedObjectList() );
     287           0 :     sal_uLong nMarkCount = aMrkList.GetMarkCount();
     288           0 :     if( !pDestShell->Imp()->GetDrawView() )
     289             :         // should create it now
     290           0 :         pDestShell->MakeDrawView();
     291           0 :     else if( bSelectInsert )
     292           0 :         pDestShell->Imp()->GetDrawView()->UnmarkAll();
     293             : 
     294           0 :     SdrPageView *pDestPgView = pDestShell->Imp()->GetPageView(),
     295           0 :                 *pSrcPgView = Imp()->GetPageView();
     296           0 :     SwDrawView *pDestDrwView = pDestShell->Imp()->GetDrawView(),
     297           0 :                 *pSrcDrwView = Imp()->GetDrawView();
     298           0 :     SwDoc* pDestDoc = pDestShell->GetDoc();
     299             : 
     300           0 :     Size aSiz( rInsPt.X() - rSttPt.X(), rInsPt.Y() - rSttPt.Y() );
     301           0 :     for( sal_uInt16 i = 0; i < nMarkCount; ++i )
     302             :     {
     303           0 :         SdrObject *pObj = aMrkList.GetMark( i )->GetMarkedSdrObj();
     304             : 
     305           0 :         SwDrawContact *pContact = (SwDrawContact*)GetUserCall( pObj );
     306           0 :         SwFrmFmt *pFmt = pContact->GetFmt();
     307           0 :         const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
     308             : 
     309           0 :         bool bInsWithFmt = true;
     310             : 
     311           0 :         if( pDestDrwView->IsGroupEntered() )
     312             :         {
     313             :             // insert into the group, when it belongs to an entered group
     314             :             // or when the object is not anchored as a character
     315           0 :             if( pSrcDrwView->IsGroupEntered() ||
     316           0 :                 (FLY_AS_CHAR != rAnchor.GetAnchorId()) )
     317             : 
     318             :             {
     319           0 :                 SdrObject* pNew = pDestDoc->CloneSdrObj( *pObj, bIsMove &&
     320           0 :                                         GetDoc() == pDestDoc, false );
     321           0 :                 pNew->NbcMove( aSiz );
     322           0 :                 pDestDrwView->InsertObjectAtView( pNew, *pDestPgView );
     323           0 :                 bInsWithFmt = false;
     324             :             }
     325             :         }
     326             : 
     327           0 :         if( bInsWithFmt )
     328             :         {
     329           0 :             SwFmtAnchor aAnchor( rAnchor );
     330           0 :             Point aNewAnch;
     331             : 
     332           0 :             if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     333           0 :                 (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     334           0 :                 (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     335           0 :                 (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     336             :             {
     337           0 :                 if ( this == pDestShell )
     338             :                 {
     339             :                     // same shell? Then request the position
     340             :                     // from the passed DocumentPosition
     341           0 :                     SwPosition aPos( *GetCrsr()->GetPoint() );
     342           0 :                     Point aPt( rInsPt );
     343           0 :                     aPt -= rSttPt - pObj->GetSnapRect().TopLeft();
     344           0 :                     SwCrsrMoveState aState( MV_SETONLYTEXT );
     345           0 :                     GetLayout()->GetCrsrOfst( &aPos, aPt, &aState );
     346             :                     const SwNode *pNd;
     347           0 :                     if( (pNd = &aPos.nNode.GetNode())->IsNoTxtNode() )
     348           0 :                         bRet = sal_False;
     349             :                     else
     350             :                         bRet = ::lcl_SetAnchor( aPos, *pNd, 0, rInsPt,
     351           0 :                                 *pDestShell, aAnchor, aNewAnch, false );
     352             :                 }
     353             :                 else
     354             :                 {
     355           0 :                     SwPaM *pCrsr = pDestShell->GetCrsr();
     356           0 :                     if( pCrsr->GetNode()->IsNoTxtNode() )
     357           0 :                         bRet = sal_False;
     358             :                     else
     359           0 :                         bRet = ::lcl_SetAnchor( *pCrsr->GetPoint(),
     360           0 :                                                 *pCrsr->GetNode(), 0, rInsPt,
     361             :                                                 *pDestShell, aAnchor,
     362           0 :                                                 aNewAnch, false );
     363             :                 }
     364             :             }
     365           0 :             else if ( FLY_AT_PAGE == aAnchor.GetAnchorId() )
     366             :             {
     367           0 :                 aAnchor.SetPageNum( pDestShell->GetPageNumber( rInsPt ) );
     368           0 :                 const SwRootFrm* pTmpRoot = pDestShell->GetLayout();
     369           0 :                 const SwFrm* pPg = pTmpRoot->GetPageAtPos( rInsPt, 0, true );
     370           0 :                 if ( pPg )
     371           0 :                     aNewAnch = pPg->Frm().Pos();
     372             :             }
     373             : 
     374           0 :             if( bRet )
     375             :             {
     376           0 :                 if( pSrcDrwView->IsGroupEntered() ||
     377           0 :                     ( !pObj->GetUserCall() && pObj->GetUpGroup()) )
     378             :                 {
     379           0 :                     SfxItemSet aSet( pDestDoc->GetAttrPool(),aFrmFmtSetRange);
     380           0 :                     aSet.Put( aAnchor );
     381           0 :                     SdrObject* pNew = pDestDoc->CloneSdrObj( *pObj, bIsMove &&
     382           0 :                                                 GetDoc() == pDestDoc, true );
     383           0 :                     pFmt = pDestDoc->InsertDrawObj( *pDestShell->GetCrsr(), *pNew, aSet );
     384             :                 }
     385             :                 else
     386           0 :                     pFmt = pDestDoc->CopyLayoutFmt( *pFmt, aAnchor, true, true );
     387             : 
     388             :                 // Can be 0, as Draws are not allowed in Headers/Footers
     389           0 :                 if ( pFmt )
     390             :                 {
     391           0 :                     SdrObject* pNew = pFmt->FindSdrObject();
     392           0 :                     if ( FLY_AS_CHAR != aAnchor.GetAnchorId() )
     393             :                     {
     394           0 :                         Point aPos( rInsPt );
     395           0 :                         aPos -= aNewAnch;
     396           0 :                         aPos -= rSttPt - pObj->GetSnapRect().TopLeft();
     397             :                         // OD 2004-04-05 #i26791# - change attributes instead of
     398             :                         // direct positioning
     399           0 :                         pFmt->SetFmtAttr( SwFmtHoriOrient( aPos.getX(), text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
     400           0 :                         pFmt->SetFmtAttr( SwFmtVertOrient( aPos.getY(), text::VertOrientation::NONE, text::RelOrientation::FRAME ) );
     401             :                         // #i47455# - notify draw frame format
     402             :                         // that position attributes are already set.
     403           0 :                         if ( pFmt->ISA(SwDrawFrmFmt) )
     404             :                         {
     405           0 :                             static_cast<SwDrawFrmFmt*>(pFmt)->PosAttrSet();
     406             :                         }
     407             :                     }
     408           0 :                     if( bSelectInsert )
     409           0 :                         pDestDrwView->MarkObj( pNew, pDestPgView );
     410             :                 }
     411           0 :             }
     412             :         }
     413             :     }
     414             : 
     415           0 :     if ( bIsMove && bRet )
     416             :     {
     417           0 :         if( pDestShell == this )
     418             :         {
     419           0 :             const SdrMarkList aList( pSrcDrwView->GetMarkedObjectList() );
     420           0 :             pSrcDrwView->UnmarkAll();
     421             : 
     422           0 :             sal_uLong nMrkCnt = aMrkList.GetMarkCount();
     423             :             sal_uInt16 i;
     424           0 :             for ( i = 0; i < nMrkCnt; ++i )
     425             :             {
     426           0 :                 SdrObject *pObj = aMrkList.GetMark( i )->GetMarkedSdrObj();
     427           0 :                 pSrcDrwView->MarkObj( pObj, pSrcPgView );
     428             :             }
     429           0 :             DelSelectedObj();
     430           0 :             nMrkCnt = aList.GetMarkCount();
     431           0 :             for ( i = 0; i < nMrkCnt; ++i )
     432             :             {
     433           0 :                 SdrObject *pObj = aList.GetMark( i )->GetMarkedSdrObj();
     434           0 :                 pSrcDrwView->MarkObj( pObj, pSrcPgView );
     435           0 :             }
     436             :         }
     437             :         else
     438           0 :             DelSelectedObj();
     439             :     }
     440             : 
     441           0 :     return bRet;
     442             : }
     443             : 
     444           0 : sal_Bool SwFEShell::Copy( SwFEShell* pDestShell, const Point& rSttPt,
     445             :                     const Point& rInsPt, sal_Bool bIsMove, sal_Bool bSelectInsert )
     446             : {
     447           0 :     sal_Bool bRet = sal_False;
     448             : 
     449             :     OSL_ENSURE( pDestShell, "Copy without DestShell." );
     450             :     OSL_ENSURE( this == pDestShell || !pDestShell->IsObjSelected(),
     451             :             "Dest-Shell cannot be in Obj-Mode" );
     452             : 
     453           0 :     SET_CURR_SHELL( pDestShell );
     454             : 
     455           0 :     pDestShell->StartAllAction();
     456           0 :     pDestShell->GetDoc()->LockExpFlds();
     457             : 
     458             :     // Shift references
     459           0 :     sal_Bool bCopyIsMove = mpDoc->IsCopyIsMove();
     460           0 :     if( bIsMove )
     461             :         // set a flag in Doc, handled in TextNodes
     462           0 :         mpDoc->SetCopyIsMove( true );
     463             : 
     464           0 :     RedlineMode_t eOldRedlMode = pDestShell->GetDoc()->GetRedlineMode();
     465           0 :     pDestShell->GetDoc()->SetRedlineMode_intern( (RedlineMode_t)(eOldRedlMode | nsRedlineMode_t::REDLINE_DELETE_REDLINES));
     466             : 
     467             :     // If there are table formulas in the area, then display the table first
     468             :     // so that the table formula can calculate a new value first
     469             :     // (individual boxes in the area are retrieved via the layout)
     470           0 :      SwFieldType* pTblFldTyp = pDestShell->GetDoc()->GetSysFldType( RES_TABLEFLD );
     471             : 
     472           0 :     if( IsFrmSelected() )
     473             :     {
     474           0 :         SwFlyFrm* pFly = FindFlyFrm();
     475           0 :         SwFrmFmt* pFlyFmt = pFly->GetFmt();
     476           0 :         SwFmtAnchor aAnchor( pFlyFmt->GetAnchor() );
     477           0 :         bRet = sal_True;
     478           0 :         Point aNewAnch;
     479             : 
     480           0 :         if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     481           0 :             (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     482           0 :             (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     483           0 :             (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     484             :         {
     485           0 :             if ( this == pDestShell )
     486             :             {
     487             :                 // same shell? Then request the position
     488             :                 // from the passed DocumentPosition
     489           0 :                 SwPosition aPos( *GetCrsr()->GetPoint() );
     490           0 :                 Point aPt( rInsPt );
     491           0 :                 aPt -= rSttPt - pFly->Frm().Pos();
     492           0 :                 SwCrsrMoveState aState( MV_SETONLYTEXT );
     493           0 :                 GetLayout()->GetCrsrOfst( &aPos, aPt, &aState );
     494             :                 const SwNode *pNd;
     495           0 :                 if( (pNd = &aPos.nNode.GetNode())->IsNoTxtNode() )
     496           0 :                     bRet = sal_False;
     497             :                 else
     498             :                 {
     499             :                     // do not copy in itself
     500           0 :                     const SwNodeIndex *pTmp = pFlyFmt->GetCntnt().GetCntntIdx();
     501           0 :                     if ( aPos.nNode > *pTmp && aPos.nNode <
     502           0 :                         pTmp->GetNode().EndOfSectionIndex() )
     503             :                     {
     504           0 :                         bRet = sal_False;
     505             :                     }
     506             :                     else
     507             :                         bRet = ::lcl_SetAnchor( aPos, *pNd, pFly, rInsPt,
     508           0 :                                         *pDestShell, aAnchor, aNewAnch, true );
     509           0 :                 }
     510             :             }
     511             :             else
     512             :             {
     513           0 :                 const SwPaM *pCrsr = pDestShell->GetCrsr();
     514           0 :                 if( pCrsr->GetNode()->IsNoTxtNode() )
     515           0 :                     bRet = sal_False;
     516             :                 else
     517           0 :                     bRet = ::lcl_SetAnchor( *pCrsr->GetPoint(), *pCrsr->GetNode(),
     518             :                                             pFly, rInsPt, *pDestShell, aAnchor,
     519           0 :                                     aNewAnch, GetDoc() == pDestShell->GetDoc());
     520             :             }
     521             :         }
     522           0 :         else if ( FLY_AT_PAGE == aAnchor.GetAnchorId() )
     523             :         {
     524           0 :             aAnchor.SetPageNum( pDestShell->GetPageNumber( rInsPt ) );
     525           0 :             const SwRootFrm* pTmpRoot = pDestShell->GetLayout();
     526           0 :             const SwFrm* pPg = pTmpRoot->GetPageAtPos( rInsPt, 0, true );
     527           0 :             if ( pPg )
     528           0 :                 aNewAnch = pPg->Frm().Pos();
     529             :         }
     530             :         else {
     531             :             OSL_ENSURE( !this, "what anchor is it?" );
     532             :         }
     533             : 
     534           0 :         if( bRet )
     535             :         {
     536           0 :             SwFrmFmt *pOldFmt = pFlyFmt;
     537           0 :             pFlyFmt = pDestShell->GetDoc()->CopyLayoutFmt( *pFlyFmt, aAnchor, true, true );
     538             : 
     539           0 :             if ( FLY_AS_CHAR != aAnchor.GetAnchorId() )
     540             :             {
     541           0 :                 Point aPos( rInsPt );
     542           0 :                 aPos -= aNewAnch;
     543           0 :                 aPos -= rSttPt - pFly->Frm().Pos();
     544           0 :                 pFlyFmt->SetFmtAttr( SwFmtHoriOrient( aPos.getX(),text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
     545           0 :                 pFlyFmt->SetFmtAttr( SwFmtVertOrient( aPos.getY(),text::VertOrientation::NONE, text::RelOrientation::FRAME ) );
     546             :             }
     547             : 
     548           0 :             const Point aPt( pDestShell->GetCrsrDocPos() );
     549             : 
     550           0 :             if( bIsMove )
     551           0 :                 GetDoc()->DelLayoutFmt( pOldFmt );
     552             : 
     553             :             // only select if it can be shifted/copied in the same shell
     554           0 :             if( bSelectInsert )
     555             :             {
     556           0 :                 SwFlyFrm* pFlyFrm = ((SwFlyFrmFmt*)pFlyFmt)->GetFrm( &aPt, sal_False );
     557           0 :                 if( pFlyFrm )
     558             :                 {
     559             :                     //JP 12.05.98: should this be in SelectFlyFrm???
     560           0 :                     pDestShell->Imp()->GetDrawView()->UnmarkAll();
     561           0 :                     pDestShell->SelectFlyFrm( *pFlyFrm, sal_True );
     562             :                 }
     563             :             }
     564             : 
     565           0 :             if( this != pDestShell && !pDestShell->HasShFcs() )
     566           0 :                 pDestShell->Imp()->GetDrawView()->hideMarkHandles();
     567           0 :         }
     568             :     }
     569           0 :     else if ( IsObjSelected() )
     570           0 :         bRet = CopyDrawSel( pDestShell, rSttPt, rInsPt, bIsMove, bSelectInsert );
     571           0 :     else if( IsTableMode() )
     572             :     {
     573             :         // Copy parts from a table: create a table with the same
     574             :         // width as the original and copy the selected boxes.
     575             :         // Sizes will be corrected by percentage.
     576             : 
     577             :         // find boxes via the layout
     578             :         const SwTableNode* pTblNd;
     579           0 :         SwSelBoxes aBoxes;
     580           0 :         GetTblSel( *this, aBoxes );
     581           0 :         if( !aBoxes.empty() &&
     582           0 :             0 != (pTblNd = aBoxes[0]->GetSttNd()->FindTableNode()) )
     583             :         {
     584           0 :             SwPosition* pDstPos = 0;
     585           0 :             if( this == pDestShell )
     586             :             {
     587             :                 // same shell? Then create new Crsr at the
     588             :                 // DocumentPosition passed
     589           0 :                 pDstPos = new SwPosition( *GetCrsr()->GetPoint() );
     590           0 :                 Point aPt( rInsPt );
     591           0 :                 GetLayout()->GetCrsrOfst( pDstPos, aPt );
     592           0 :                 if( !pDstPos->nNode.GetNode().IsNoTxtNode() )
     593           0 :                     bRet = sal_True;
     594             :             }
     595           0 :             else if( !pDestShell->GetCrsr()->GetNode()->IsNoTxtNode() )
     596             :             {
     597           0 :                 pDstPos = new SwPosition( *pDestShell->GetCrsr()->GetPoint() );
     598           0 :                 bRet = sal_True;
     599             :             }
     600             : 
     601           0 :             if( bRet )
     602             :             {
     603           0 :                 if( GetDoc() == pDestShell->GetDoc() )
     604           0 :                     ParkTblCrsr();
     605             : 
     606             :                 bRet = pDestShell->GetDoc()->InsCopyOfTbl( *pDstPos, aBoxes,0,
     607           0 :                                         bIsMove && this == pDestShell &&
     608           0 :                                         aBoxes.size() == pTblNd->GetTable().
     609           0 :                                         GetTabSortBoxes().size(),
     610           0 :                                         this != pDestShell );
     611             : 
     612           0 :                 if( this != pDestShell )
     613           0 :                     *pDestShell->GetCrsr()->GetPoint() = *pDstPos;
     614             : 
     615             :                 // create all parked Crsr?
     616           0 :                 if( GetDoc() == pDestShell->GetDoc() )
     617           0 :                     GetCrsr();
     618             : 
     619             :                 // JP 16.04.99: Bug 64908 - Set InsPos, to assure the parked
     620             :                 //              Cursor is positioned at the insert position
     621           0 :                 if( this == pDestShell )
     622           0 :                     GetCrsrDocPos() = rInsPt;
     623             :             }
     624           0 :             delete pDstPos;
     625           0 :         }
     626             :     }
     627             :     else
     628             :     {
     629           0 :         bRet = sal_True;
     630           0 :         if( this == pDestShell )
     631             :         {
     632             :             // same shell? then request the postion
     633             :             // at the passed document position
     634           0 :             SwPosition aPos( *GetCrsr()->GetPoint() );
     635           0 :             Point aPt( rInsPt );
     636           0 :             GetLayout()->GetCrsrOfst( &aPos, aPt );
     637           0 :             bRet = !aPos.nNode.GetNode().IsNoTxtNode();
     638             :         }
     639           0 :         else if( pDestShell->GetCrsr()->GetNode()->IsNoTxtNode() )
     640           0 :             bRet = sal_False;
     641             : 
     642           0 :         if( bRet )
     643           0 :             bRet = 0 != SwEditShell::Copy( pDestShell );
     644             :     }
     645             : 
     646           0 :     pDestShell->GetDoc()->SetRedlineMode_intern( eOldRedlMode );
     647           0 :     mpDoc->SetCopyIsMove( bCopyIsMove );
     648             : 
     649             :     // have new table formules been inserted?
     650           0 :     if( pTblFldTyp->GetDepends() )
     651             :     {
     652             :         // finish old actions: the table frames are created and
     653             :         // a selection can be made
     654             :         sal_uInt16 nActCnt;
     655           0 :         for( nActCnt = 0; pDestShell->ActionPend(); ++nActCnt )
     656           0 :             pDestShell->EndAllAction();
     657             : 
     658           0 :         for( ; nActCnt; --nActCnt )
     659           0 :             pDestShell->StartAllAction();
     660             :     }
     661           0 :     pDestShell->GetDoc()->UnlockExpFlds();
     662           0 :     pDestShell->GetDoc()->UpdateFlds(NULL, false);
     663             : 
     664           0 :     pDestShell->EndAllAction();
     665           0 :     return bRet;
     666             : }
     667             : 
     668             : /*************************************************************************
     669             : |*
     670             : |*  SwFEShell::Paste()  Paste for  the interal clipboard.
     671             : |*      Copy the content of the clipboard in the document
     672             : |*
     673             : |*************************************************************************/
     674             : 
     675             : namespace {
     676             :     typedef boost::shared_ptr<SwPaM> PaMPtr;
     677             :     typedef boost::shared_ptr<SwPosition> PositionPtr;
     678             :     typedef std::pair< PaMPtr, PositionPtr > Insertion;
     679             : }
     680             : 
     681           0 : sal_Bool SwFEShell::Paste( SwDoc* pClpDoc, sal_Bool bIncludingPageFrames )
     682             : {
     683           0 :     SET_CURR_SHELL( this );
     684             :     OSL_ENSURE( pClpDoc, "no clipboard document"  );
     685           0 :     const sal_uInt16 nStartPageNumber = GetPhyPageNum();
     686             :     // then till end of the nodes array
     687           0 :     SwNodeIndex aIdx( pClpDoc->GetNodes().GetEndOfExtras(), 2 );
     688           0 :     SwPaM aCpyPam( aIdx ); //DocStart
     689             : 
     690             :     // If there are table formulas in the area, then display the table first
     691             :     // so that the table formula can calculate a new value first
     692             :     // (individual boxes in the area are retrieved via the layout)
     693           0 :      SwFieldType* pTblFldTyp = GetDoc()->GetSysFldType( RES_TABLEFLD );
     694             : 
     695           0 :     SwTableNode *pDestNd, *pSrcNd = aCpyPam.GetNode()->GetTableNode();
     696           0 :     if( !pSrcNd )                               // TabellenNode ?
     697             :     {                                           // nicht ueberspringen!!
     698           0 :         SwCntntNode* pCNd = aCpyPam.GetNode()->GetCntntNode();
     699           0 :         if( pCNd )
     700           0 :             aCpyPam.GetPoint()->nContent.Assign( pCNd, 0 );
     701           0 :         else if( !aCpyPam.Move( fnMoveForward, fnGoNode ))
     702           0 :             aCpyPam.Move( fnMoveBackward, fnGoNode );
     703             :     }
     704             : 
     705           0 :     aCpyPam.SetMark();
     706           0 :     aCpyPam.Move( fnMoveForward, fnGoDoc );
     707             : 
     708           0 :     sal_Bool bRet = sal_True, bDelTbl = sal_True;
     709           0 :     StartAllAction();
     710           0 :     GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
     711           0 :     GetDoc()->LockExpFlds();
     712             : 
     713             :     // When the clipboard content has been created by a rectangular selection
     714             :     // the pasting is more sophisticated:
     715             :     // every paragraph will be inserted into another position.
     716             :     // The first positions are given by the actual cursor ring,
     717             :     // if there are more text portions to insert than cursor in this ring,
     718             :     // the additional insert positions will be created by moving the last
     719             :     // cursor position into the next line (like pressing the cursor down key)
     720           0 :     if( pClpDoc->IsColumnSelection() && !IsTableMode() )
     721             :     {
     722             :         // Creation of the list of insert positions
     723           0 :         std::list< Insertion > aCopyList;
     724             :         // The number of text portions of the rectangular selection
     725           0 :         const sal_uInt32 nSelCount = aCpyPam.GetPoint()->nNode.GetIndex()
     726           0 :                        - aCpyPam.GetMark()->nNode.GetIndex();
     727           0 :         sal_uInt32 nCount = nSelCount;
     728           0 :         SwNodeIndex aClpIdx( aIdx );
     729           0 :         SwPaM* pStartCursor = GetCrsr();
     730           0 :         SwPaM* pCurrCrsr = pStartCursor;
     731           0 :         sal_uInt32 nCursorCount = pStartCursor->numberOf();
     732             :         // If the target selection is a multi-selection, often the last and first
     733             :         // cursor of the ring points to identical document positions. Then
     734             :         // we should avoid double insertion of text portions...
     735           0 :         while( nCursorCount > 1 && *pCurrCrsr->GetPoint() ==
     736           0 :             *(dynamic_cast<SwPaM*>(pCurrCrsr->GetPrev())->GetPoint()) )
     737             :         {
     738           0 :             --nCursorCount;
     739           0 :             pCurrCrsr = dynamic_cast<SwPaM*>(pCurrCrsr->GetNext());
     740           0 :             pStartCursor = pCurrCrsr;
     741             :         }
     742           0 :         SwPosition aStartPos( *pStartCursor->GetPoint() );
     743           0 :         SwPosition aInsertPos( aStartPos ); // first insertion position
     744           0 :         bool bCompletePara = false;
     745           0 :         sal_uInt16 nMove = 0;
     746           0 :         while( nCount )
     747             :         {
     748           0 :             --nCount;
     749             :             OSL_ENSURE( aIdx.GetNode().GetCntntNode(), "Who filled the clipboard?!" );
     750           0 :             if( aIdx.GetNode().GetCntntNode() ) // robust
     751             :             {
     752           0 :                 Insertion aInsertion( PaMPtr( new SwPaM( aIdx ) ),
     753           0 :                     PositionPtr( new SwPosition( aInsertPos ) ) );
     754           0 :                 ++aIdx;
     755           0 :                 aInsertion.first->SetMark();
     756           0 :                 if( pStartCursor == pCurrCrsr->GetNext() )
     757             :                 {   // Now we have to look for insertion positions...
     758           0 :                     if( !nMove ) // Annotate the last given insert position
     759           0 :                         aStartPos = aInsertPos;
     760           0 :                     SwCursor aCrsr( aStartPos, 0, false);
     761             :                     // Check if we find another insert position by moving
     762             :                     // down the last given position
     763           0 :                     if( aCrsr.UpDown( false, ++nMove, 0, 0 ) )
     764           0 :                         aInsertPos = *aCrsr.GetPoint();
     765             :                     else // if there is no paragraph we have to create it
     766           0 :                         bCompletePara = nCount > 0;
     767           0 :                     nCursorCount = 0;
     768             :                 }
     769             :                 else // as long as we find more insert positions in the cursor ring
     770             :                 {    // we'll take them
     771           0 :                     pCurrCrsr = dynamic_cast<SwPaM*>(pCurrCrsr->GetNext());
     772           0 :                     aInsertPos = *pCurrCrsr->GetPoint();
     773           0 :                     --nCursorCount;
     774             :                 }
     775             :                 // If there are no more paragraphs e.g. at the end of a document,
     776             :                 // we insert complete paragraphs instead of text portions
     777           0 :                 if( bCompletePara )
     778           0 :                     aInsertion.first->GetPoint()->nNode = aIdx;
     779             :                 else
     780           0 :                     aInsertion.first->GetPoint()->nContent =
     781           0 :                         aInsertion.first->GetCntntNode()->Len();
     782           0 :                 aCopyList.push_back( aInsertion );
     783             :             }
     784             :             // If there are no text portions left but there are some more
     785             :             // cursor positions to fill we have to restart with the first
     786             :             // text portion
     787           0 :             if( !nCount && nCursorCount )
     788             :             {
     789           0 :                 nCount = std::min( nSelCount, nCursorCount );
     790           0 :                 aIdx = aClpIdx; // Start of clipboard content
     791             :             }
     792             :         }
     793           0 :         std::list< Insertion >::const_iterator pCurr = aCopyList.begin();
     794           0 :         std::list< Insertion >::const_iterator pEnd = aCopyList.end();
     795           0 :         while( pCurr != pEnd )
     796             :         {
     797           0 :             SwPosition& rInsPos = *pCurr->second;
     798           0 :             SwPaM& rCopy = *pCurr->first;
     799           0 :             const SwStartNode* pBoxNd = rInsPos.nNode.GetNode().FindTableBoxStartNode();
     800           0 :             if( pBoxNd && 2 == pBoxNd->EndOfSectionIndex() - pBoxNd->GetIndex() &&
     801           0 :                 rCopy.GetPoint()->nNode != rCopy.GetMark()->nNode )
     802             :             {
     803             :                 // if more than one node will be copied into a cell
     804             :                 // the box attributes have to be removed
     805           0 :                 GetDoc()->ClearBoxNumAttrs( rInsPos.nNode );
     806             :             }
     807             :             {
     808           0 :                 SwNodeIndex aIndexBefore(rInsPos.nNode);
     809           0 :                 aIndexBefore--;
     810           0 :                 pClpDoc->CopyRange( rCopy, rInsPos, false );
     811             :                 {
     812           0 :                     ++aIndexBefore;
     813             :                     SwPaM aPaM(SwPosition(aIndexBefore),
     814           0 :                                SwPosition(rInsPos.nNode));
     815           0 :                     aPaM.GetDoc()->MakeUniqueNumRules(aPaM);
     816           0 :                 }
     817             :             }
     818           0 :             SaveTblBoxCntnt( &rInsPos );
     819           0 :             ++pCurr;
     820           0 :         }
     821             :     }
     822             :     else
     823             :     {
     824           0 :         FOREACHPAM_START(GetCrsr())
     825             : 
     826           0 :         if( pSrcNd &&
     827           0 :             0 != ( pDestNd = GetDoc()->IsIdxInTbl( PCURCRSR->GetPoint()->nNode )))
     828             :         {
     829           0 :             SwPosition aDestPos( *PCURCRSR->GetPoint() );
     830             : 
     831           0 :             bool bParkTblCrsr = false;
     832           0 :             const SwStartNode* pSttNd =  PCURCRSR->GetNode()->FindTableBoxStartNode();
     833             : 
     834             :             // TABLE IN TABLE: copy table in table
     835             :             // search boxes via the layout
     836           0 :             SwSelBoxes aBoxes;
     837           0 :             if( IsTableMode() )     // table selection?
     838             :             {
     839           0 :                 GetTblSel( *this, aBoxes );
     840           0 :                 ParkTblCrsr();
     841           0 :                 bParkTblCrsr = true;
     842             :             }
     843           0 :             else if( !PCURCRSR->HasMark() && PCURCRSR->GetNext() == PCURCRSR &&
     844           0 :                      ( !pSrcNd->GetTable().IsTblComplex() ||
     845           0 :                        pDestNd->GetTable().IsNewModel() ) )
     846             :             {
     847             :                 // make relative table copy
     848           0 :                 SwTableBox* pBox = pDestNd->GetTable().GetTblBox(
     849           0 :                                         pSttNd->GetIndex() );
     850             :                 OSL_ENSURE( pBox, "Box steht nicht in dieser Tabelle" );
     851           0 :                 aBoxes.insert( pBox );
     852             :             }
     853             : 
     854           0 :             SwNodeIndex aNdIdx( *pDestNd->EndOfSectionNode());
     855           0 :             if( !bParkTblCrsr )
     856             :             {
     857             :                 // exit first the complete table
     858             :                 // ???? what about only table in a frame ?????
     859           0 :                 SwCntntNode* pCNd = GetDoc()->GetNodes().GoNext( &aNdIdx );
     860           0 :                 SwPosition aPos( aNdIdx, SwIndex( pCNd, 0 ));
     861             :                 // #i59539: Don't remove all redline
     862           0 :                 SwPaM const tmpPaM(*pDestNd, *pDestNd->EndOfSectionNode());
     863           0 :                 ::PaMCorrAbs(tmpPaM, aPos);
     864             :             }
     865             : 
     866           0 :             bRet = GetDoc()->InsCopyOfTbl( aDestPos, aBoxes, &pSrcNd->GetTable(),
     867           0 :                                             sal_False, sal_False );
     868             : 
     869           0 :             if( bParkTblCrsr )
     870           0 :                 GetCrsr();
     871             :             else
     872             :             {
     873             :                 // return to the box
     874           0 :                 aNdIdx = *pSttNd;
     875           0 :                 SwCntntNode* pCNd = GetDoc()->GetNodes().GoNext( &aNdIdx );
     876           0 :                 SwPosition aPos( aNdIdx, SwIndex( pCNd, 0 ));
     877             :                 // #i59539: Don't remove all redline
     878           0 :                 SwNode & rNode(PCURCRSR->GetPoint()->nNode.GetNode());
     879           0 :                 SwCntntNode *const pCntntNode( rNode.GetCntntNode() );
     880             :                 SwPaM const tmpPam(rNode, 0,
     881           0 :                                    rNode, (pCntntNode) ? pCntntNode->Len() : 0);
     882           0 :                 ::PaMCorrAbs(tmpPam, aPos);
     883             :             }
     884             : 
     885           0 :             break;      // exit the "while-loop"
     886             :         }
     887           0 :         else if( *aCpyPam.GetPoint() == *aCpyPam.GetMark() &&
     888           0 :                  pClpDoc->GetSpzFrmFmts()->size() )
     889             :         {
     890             :             // we need a DrawView
     891           0 :             if( !Imp()->GetDrawView() )
     892           0 :                 MakeDrawView();
     893             : 
     894           0 :             for ( sal_uInt16 i = 0; i < pClpDoc->GetSpzFrmFmts()->size(); ++i )
     895             :             {
     896           0 :                 bool bInsWithFmt = true;
     897           0 :                 const SwFrmFmt& rCpyFmt = *(*pClpDoc->GetSpzFrmFmts())[i];
     898             : 
     899           0 :                 if( Imp()->GetDrawView()->IsGroupEntered() &&
     900           0 :                     RES_DRAWFRMFMT == rCpyFmt.Which() &&
     901           0 :                     (FLY_AS_CHAR != rCpyFmt.GetAnchor().GetAnchorId()) )
     902             :                 {
     903           0 :                     const SdrObject* pSdrObj = rCpyFmt.FindSdrObject();
     904           0 :                     if( pSdrObj )
     905             :                     {
     906             :                         SdrObject* pNew = GetDoc()->CloneSdrObj( *pSdrObj,
     907           0 :                                                             false, false );
     908             : 
     909             :                         // Insert object sets any anchor position to 0.
     910             :                         // Therefore we calculate the absolute position here
     911             :                         // and after the insert the anchor of the object
     912             :                         // is set to the anchor of the group object.
     913           0 :                         Rectangle aSnapRect = pNew->GetSnapRect();
     914           0 :                         if( pNew->GetAnchorPos().X() || pNew->GetAnchorPos().Y() )
     915             :                         {
     916           0 :                             const Point aPoint( 0, 0 );
     917             :                             // OD 2004-04-05 #i26791# - direct drawing object
     918             :                             // positioning for group members
     919           0 :                             pNew->NbcSetAnchorPos( aPoint );
     920           0 :                             pNew->NbcSetSnapRect( aSnapRect );
     921             :                         }
     922             : 
     923           0 :                         Imp()->GetDrawView()->InsertObjectAtView( pNew, *Imp()->GetPageView() );
     924             : 
     925           0 :                         Point aGrpAnchor( 0, 0 );
     926           0 :                         SdrObjList* pList = pNew->GetObjList();
     927           0 :                         if ( pList )
     928             :                         {
     929           0 :                             SdrObject* pOwner = pList->GetOwnerObj();
     930           0 :                             if ( pOwner )
     931             :                             {
     932           0 :                                 SdrObjGroup* pThisGroup = PTR_CAST(SdrObjGroup, pOwner);
     933           0 :                                 aGrpAnchor = pThisGroup->GetAnchorPos();
     934             :                             }
     935             :                         }
     936             : 
     937             :                         // OD 2004-04-05 #i26791# - direct drawing object
     938             :                         // positioning for group members
     939           0 :                         pNew->NbcSetAnchorPos( aGrpAnchor );
     940           0 :                         pNew->SetSnapRect( aSnapRect );
     941             : 
     942           0 :                         bInsWithFmt = false;
     943             :                     }
     944             :                 }
     945             : 
     946           0 :                 if( bInsWithFmt  )
     947             :                 {
     948           0 :                     SwFmtAnchor aAnchor( rCpyFmt.GetAnchor() );
     949           0 :                     if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     950           0 :                         (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     951           0 :                         (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     952             :                     {
     953           0 :                         SwPosition* pPos = PCURCRSR->GetPoint();
     954             :                         // allow shapes (no controls) in header/footer
     955           0 :                         if( RES_DRAWFRMFMT == rCpyFmt.Which() &&
     956           0 :                             GetDoc()->IsInHeaderFooter( pPos->nNode ) &&
     957           0 :                             CheckControlLayer( rCpyFmt.FindSdrObject() ) )
     958           0 :                             continue;
     959             : 
     960           0 :                         aAnchor.SetAnchor( pPos );
     961             :                     }
     962           0 :                     else if ( FLY_AT_PAGE == aAnchor.GetAnchorId() )
     963             :                     {
     964           0 :                         aAnchor.SetPageNum( GetPhyPageNum() );
     965             :                     }
     966           0 :                     else if( FLY_AT_FLY == aAnchor.GetAnchorId() )
     967             :                     {
     968           0 :                         Point aPt;
     969           0 :                         lcl_SetAnchor( *PCURCRSR->GetPoint(), *PCURCRSR->GetNode(),
     970           0 :                                         0, aPt, *this, aAnchor, aPt, false );
     971             :                     }
     972             : 
     973           0 :                     SwFrmFmt * pNew = GetDoc()->CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
     974             : 
     975           0 :                     if( pNew )
     976             :                     {
     977           0 :                         if( RES_FLYFRMFMT == pNew->Which() )
     978             :                         {
     979           0 :                             const Point aPt( GetCrsrDocPos() );
     980             :                             SwFlyFrm* pFlyFrm = ((SwFlyFrmFmt*)pNew)->
     981           0 :                                                         GetFrm( &aPt, sal_False );
     982           0 :                             if( pFlyFrm )
     983           0 :                                 SelectFlyFrm( *pFlyFrm, sal_True );
     984             :                             // always pick the first FlyFrame only; the others
     985             :                             // were copied to the clipboard via Fly in Fly
     986           0 :                             break;
     987             :                         }
     988             :                         else
     989             :                         {
     990             :                             OSL_ENSURE( RES_DRAWFRMFMT == pNew->Which(), "Neues Format.");
     991             :                             // #i52780# - drawing object has
     992             :                             // to be made visible on paste.
     993             :                             {
     994             :                                 SwDrawContact* pContact =
     995           0 :                                     static_cast<SwDrawContact*>(pNew->FindContactObj());
     996           0 :                                 pContact->MoveObjToVisibleLayer( pContact->GetMaster() );
     997             :                             }
     998           0 :                             SdrObject *pObj = pNew->FindSdrObject();
     999           0 :                             SwDrawView  *pDV = Imp()->GetDrawView();
    1000           0 :                             pDV->MarkObj( pObj, pDV->GetSdrPageView() );
    1001             :                             // #i47455# - notify draw frame format
    1002             :                             // that position attributes are already set.
    1003           0 :                             if ( pNew->ISA(SwDrawFrmFmt) )
    1004             :                             {
    1005           0 :                                 static_cast<SwDrawFrmFmt*>(pNew)->PosAttrSet();
    1006             :                             }
    1007             :                         }
    1008           0 :                     }
    1009             :                 }
    1010             :             }
    1011             :         }
    1012             :         else
    1013             :         {
    1014           0 :             if( bDelTbl && IsTableMode() )
    1015             :             {
    1016           0 :                 SwEditShell::Delete();
    1017           0 :                 bDelTbl = sal_False;
    1018             :             }
    1019             : 
    1020           0 :             SwPosition& rInsPos = *PCURCRSR->GetPoint();
    1021           0 :             const SwStartNode* pBoxNd = rInsPos.nNode.GetNode().
    1022           0 :                                                     FindTableBoxStartNode();
    1023           0 :             if( pBoxNd && 2 == pBoxNd->EndOfSectionIndex() -
    1024           0 :                                 pBoxNd->GetIndex() &&
    1025           0 :                 aCpyPam.GetPoint()->nNode != aCpyPam.GetMark()->nNode )
    1026             :             {
    1027             :                 // Copy more than 1 node in the current box. But
    1028             :                 // then the BoxAttribute should be removed
    1029           0 :                 GetDoc()->ClearBoxNumAttrs( rInsPos.nNode );
    1030             :             }
    1031             : 
    1032             :             // find out if the clipboard document starts with a table
    1033           0 :             bool bStartWithTable = 0 != aCpyPam.Start()->nNode.GetNode().FindTableNode();
    1034           0 :             SwPosition aInsertPosition( rInsPos );
    1035             : 
    1036             :             {
    1037           0 :                 SwNodeIndex aIndexBefore(rInsPos.nNode);
    1038             : 
    1039           0 :                 aIndexBefore--;
    1040             : 
    1041           0 :                 pClpDoc->CopyRange( aCpyPam, rInsPos, false );
    1042             :                 // Note: aCpyPam is invalid now
    1043             : 
    1044           0 :                 ++aIndexBefore;
    1045             :                 SwPaM aPaM(SwPosition(aIndexBefore),
    1046           0 :                            SwPosition(rInsPos.nNode));
    1047             : 
    1048           0 :                 aPaM.GetDoc()->MakeUniqueNumRules(aPaM);
    1049             : 
    1050             :                 // Update the rsid of each pasted text node.
    1051           0 :                 SwNodes &rDestNodes = GetDoc()->GetNodes();
    1052           0 :                 sal_uLong const nEndIdx = aPaM.End()->nNode.GetIndex();
    1053             : 
    1054           0 :                 for (sal_uLong nIdx = aPaM.Start()->nNode.GetIndex();
    1055             :                         nIdx <= nEndIdx; ++nIdx)
    1056             :                 {
    1057           0 :                     SwTxtNode *const pTxtNode = rDestNodes[nIdx]->GetTxtNode();
    1058           0 :                     if ( pTxtNode )
    1059             :                     {
    1060           0 :                         GetDoc()->UpdateParRsid( pTxtNode );
    1061             :                     }
    1062           0 :                 }
    1063             :             }
    1064             : 
    1065           0 :             SaveTblBoxCntnt( &rInsPos );
    1066           0 :             if(bIncludingPageFrames && bStartWithTable)
    1067             :             {
    1068             :                 //remove the paragraph in front of the table
    1069           0 :                 SwPaM aPara(aInsertPosition);
    1070           0 :                 GetDoc()->DelFullPara(aPara);
    1071             :             }
    1072             :             //additionally copy page bound frames
    1073           0 :             if( bIncludingPageFrames && pClpDoc->GetSpzFrmFmts()->size() )
    1074             :             {
    1075             :                 // create a draw view if necessary
    1076           0 :                 if( !Imp()->GetDrawView() )
    1077           0 :                     MakeDrawView();
    1078             : 
    1079           0 :                 for ( sal_uInt16 i = 0; i < pClpDoc->GetSpzFrmFmts()->size(); ++i )
    1080             :                 {
    1081           0 :                     bool bInsWithFmt = true;
    1082           0 :                     const SwFrmFmt& rCpyFmt = *(*pClpDoc->GetSpzFrmFmts())[i];
    1083           0 :                     if( bInsWithFmt  )
    1084             :                     {
    1085           0 :                         SwFmtAnchor aAnchor( rCpyFmt.GetAnchor() );
    1086           0 :                         if ( FLY_AT_PAGE == aAnchor.GetAnchorId() )
    1087             :                         {
    1088           0 :                             aAnchor.SetPageNum( aAnchor.GetPageNum() + nStartPageNumber - 1 );
    1089             :                         }
    1090             :                         else
    1091           0 :                             continue;
    1092           0 :                         GetDoc()->CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
    1093             :                     }
    1094             :                 }
    1095           0 :             }
    1096             :         }
    1097             : 
    1098           0 :         FOREACHPAM_END()
    1099             :     }
    1100             : 
    1101           0 :     GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
    1102             : 
    1103             :     // have new table formulas been inserted?
    1104           0 :     if( pTblFldTyp->GetDepends() )
    1105             :     {
    1106             :         // finish old action: table-frames have been created
    1107             :         // a selection can be made now
    1108             :         sal_uInt16 nActCnt;
    1109           0 :         for( nActCnt = 0; ActionPend(); ++nActCnt )
    1110           0 :             EndAllAction();
    1111             : 
    1112           0 :         for( ; nActCnt; --nActCnt )
    1113           0 :             StartAllAction();
    1114             :     }
    1115           0 :     GetDoc()->UnlockExpFlds();
    1116           0 :     GetDoc()->UpdateFlds(NULL, false);
    1117           0 :     EndAllAction();
    1118             : 
    1119           0 :     return bRet;
    1120             : }
    1121             : 
    1122           0 : sal_Bool SwFEShell::PastePages( SwFEShell& rToFill, sal_uInt16 nStartPage, sal_uInt16 nEndPage)
    1123             : {
    1124           0 :     Push();
    1125           0 :     if(!GotoPage(nStartPage))
    1126             :     {
    1127           0 :         Pop(sal_False);
    1128           0 :         return sal_False;
    1129             :     }
    1130           0 :     MovePage( fnPageCurr, fnPageStart );
    1131           0 :     SwPaM aCpyPam( *GetCrsr()->GetPoint() );
    1132           0 :     OUString sStartingPageDesc = GetPageDesc( GetCurPageDesc()).GetName();
    1133           0 :     SwPageDesc* pDesc = rToFill.FindPageDescByName( sStartingPageDesc, sal_True );
    1134           0 :     if( pDesc )
    1135           0 :         rToFill.ChgCurPageDesc( *pDesc );
    1136             : 
    1137           0 :     if(!GotoPage(nEndPage))
    1138             :     {
    1139           0 :         Pop(sal_False);
    1140           0 :         return sal_False;
    1141             :     }
    1142             :     //if the page starts with a table a paragraph has to be inserted before
    1143           0 :     SwNode* pTableNode = aCpyPam.GetNode()->FindTableNode();
    1144           0 :     if(pTableNode)
    1145             :     {
    1146             :         //insert a paragraph
    1147           0 :         StartUndo(UNDO_INSERT);
    1148           0 :         SwNodeIndex aTblIdx(  *pTableNode, -1 );
    1149           0 :         SwPosition aBefore(aTblIdx);
    1150           0 :         if(GetDoc()->AppendTxtNode( aBefore ))
    1151             :         {
    1152           0 :             SwPaM aTmp(aBefore);
    1153           0 :             aCpyPam = aTmp;
    1154             :         }
    1155           0 :         EndUndo(UNDO_INSERT);
    1156             :     }
    1157             : 
    1158           0 :     MovePage( fnPageCurr, fnPageEnd );
    1159           0 :     aCpyPam.SetMark();
    1160           0 :     *aCpyPam.GetMark() = *GetCrsr()->GetPoint();
    1161             : 
    1162           0 :     SET_CURR_SHELL( this );
    1163             : 
    1164           0 :     StartAllAction();
    1165           0 :     GetDoc()->LockExpFlds();
    1166           0 :     SetSelection(aCpyPam);
    1167             :     // copy the text of the selection
    1168           0 :     SwEditShell::Copy(&rToFill);
    1169             : 
    1170           0 :     if(pTableNode)
    1171             :     {
    1172             :         //remove the inserted paragraph
    1173           0 :         Undo();
    1174             :         //remove the paragraph in the second doc, too
    1175           0 :         SwNodeIndex aIdx( rToFill.GetDoc()->GetNodes().GetEndOfExtras(), 2 );
    1176           0 :         SwPaM aPara( aIdx ); //DocStart
    1177           0 :         rToFill.GetDoc()->DelFullPara(aPara);
    1178             :     }
    1179             :     // now the page bound objects
    1180             :     // additionally copy page bound frames
    1181           0 :     if( GetDoc()->GetSpzFrmFmts()->size() )
    1182             :     {
    1183             :         // create a draw view if necessary
    1184           0 :         if( !rToFill.Imp()->GetDrawView() )
    1185           0 :             rToFill.MakeDrawView();
    1186             : 
    1187           0 :         for ( sal_uInt16 i = 0; i < GetDoc()->GetSpzFrmFmts()->size(); ++i )
    1188             :         {
    1189           0 :             const SwFrmFmt& rCpyFmt = *(*GetDoc()->GetSpzFrmFmts())[i];
    1190           0 :             SwFmtAnchor aAnchor( rCpyFmt.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()->CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
    1199           0 :         }
    1200             :     }
    1201           0 :     GetDoc()->UnlockExpFlds();
    1202           0 :     GetDoc()->UpdateFlds(NULL, false);
    1203           0 :     Pop(sal_False);
    1204           0 :     EndAllAction();
    1205             : 
    1206           0 :     return sal_True;
    1207             : }
    1208             : 
    1209           0 : sal_Bool SwFEShell::GetDrawObjGraphic( sal_uLong nFmt, Graphic& rGrf ) const
    1210             : {
    1211             :     OSL_ENSURE( Imp()->HasDrawView(), "GetDrawObjGraphic without DrawView?" );
    1212           0 :     const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
    1213           0 :     sal_Bool bConvert = sal_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( SOT_FORMAT_GDIMETAFILE == nFmt )
    1227             :                     {
    1228           0 :                         if( GRAPHIC_BITMAP != aGrf.GetType() )
    1229             :                         {
    1230           0 :                             rGrf = aGrf;
    1231           0 :                             bConvert = sal_False;
    1232             :                         }
    1233           0 :                         else if( GetWin() )
    1234             :                         {
    1235           0 :                             Size aSz;
    1236           0 :                             Point aPt;
    1237           0 :                             GetGrfSize( aSz );
    1238             : 
    1239           0 :                             VirtualDevice aVirtDev;
    1240           0 :                             aVirtDev.EnableOutput( false );
    1241             : 
    1242           0 :                             MapMode aTmp( GetWin()->GetMapMode() );
    1243           0 :                             aTmp.SetOrigin( aPt );
    1244           0 :                             aVirtDev.SetMapMode( aTmp );
    1245             : 
    1246           0 :                             GDIMetaFile aMtf;
    1247           0 :                             aMtf.Record( &aVirtDev );
    1248           0 :                             aGrf.Draw( &aVirtDev, 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 = sal_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 :                         VirtualDevice aVirtDev( *GetWin() );
    1267             : 
    1268           0 :                         MapMode aTmp( MAP_TWIP );
    1269           0 :                         aVirtDev.SetMapMode( aTmp );
    1270           0 :                         if( aVirtDev.SetOutputSize( aSz ) )
    1271             :                         {
    1272           0 :                             aGrf.Draw( &aVirtDev, Point(), aSz );
    1273           0 :                             rGrf = aVirtDev.GetBitmap( Point(), aSz );
    1274             :                         }
    1275             :                         else
    1276             :                         {
    1277           0 :                             rGrf = aGrf;
    1278           0 :                             bConvert = sal_False;
    1279           0 :                         }
    1280           0 :                     }
    1281             :                 }
    1282             :             }
    1283             :         }
    1284           0 :         else if( SOT_FORMAT_GDIMETAFILE == nFmt )
    1285           0 :             rGrf = Imp()->GetDrawView()->GetMarkedObjMetaFile();
    1286           0 :         else if( SOT_FORMAT_BITMAP == nFmt || SOT_FORMATSTR_ID_PNG == nFmt )
    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 SwFrmFmt* pFmt(0);
    1372           0 :                 const SwFrm* pAnchor(0);
    1373           0 :                 if( pOldObj->ISA(SwVirtFlyDrawObj) )
    1374             :                 {
    1375           0 :                     pFmt = FindFrmFmt( pOldObj );
    1376             : 
    1377           0 :                     Point aNullPt;
    1378           0 :                     SwFlyFrm* pFlyFrm = ((SwFlyFrmFmt*)pFmt)->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()->GetControlsId() );
    1405           0 :                 else if( pOldObj->ISA( SdrUnoObj ) )
    1406           0 :                     pNewObj->SetLayer( GetDoc()->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( pFmt->GetAttrSet() );
    1416             : 
    1417           0 :                     Point aNullPt;
    1418           0 :                     if( pAnchor->IsTxtFrm() && ((SwTxtFrm*)pAnchor)->IsFollow() )
    1419             :                     {
    1420           0 :                         const SwTxtFrm* pTmp = (SwTxtFrm*)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 = ((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()->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             :                 }
    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(XFILL_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 :         sal_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 );
    1518             : 
    1519           0 :         sal_uLong nCnt = pView->GetMarkedObjectList().GetMarkCount();
    1520           0 :         if( nCnt )
    1521             :         {
    1522           0 :             const Point aNull( 0, 0 );
    1523           0 :             for( sal_uLong 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()->GetControlsId() );
    1536           0 :                 bDesignMode = sal_True;
    1537             :             }
    1538             :             else
    1539           0 :                 pObj->SetLayer( GetDoc()->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 :     sal_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 = (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(XFILL_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             : }
    1608             : 
    1609             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10