LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/frmedt - fecopy.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 788 0.0 %
Date: 2012-12-27 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/viewsh.hxx>
      28             : #include <svx/xexch.hxx>
      29             : #include <svx/xflasit.hxx>
      30             : #include <svx/xfillit0.hxx>
      31             : #include <svx/xflclit.hxx>
      32             : #include <editeng/brshitem.hxx>
      33             : #include <svx/svdocapt.hxx>
      34             : #include <svx/svdouno.hxx>
      35             : #include <svx/xfillit.hxx>
      36             : #include <svx/svdpage.hxx>
      37             : #include <svx/svdogrp.hxx>
      38             : #include <svx/xoutbmp.hxx>
      39             : #include <svx/svdoole2.hxx>
      40             : #include <svx/fmmodel.hxx>
      41             : #include <svx/unomodel.hxx>
      42             : #include <svx/svditer.hxx> // #i50824#
      43             : #include <svx/svdograf.hxx>
      44             : #include <unotools/streamwrap.hxx>
      45             : #include <fmtanchr.hxx>
      46             : #include <fmtcntnt.hxx>
      47             : #include <fmtornt.hxx>
      48             : #include <fmtflcnt.hxx>
      49             : #include <frmfmt.hxx>
      50             : #include <docary.hxx>
      51             : #include <txtfrm.hxx>
      52             : #include <txtflcnt.hxx>
      53             : #include <fesh.hxx>
      54             : #include <doc.hxx>
      55             : #include <IDocumentUndoRedo.hxx>
      56             : #include <rootfrm.hxx>
      57             : #include <ndtxt.hxx>
      58             : #include <pam.hxx>
      59             : #include <tblsel.hxx>
      60             : #include <swtable.hxx>
      61             : #include <flyfrm.hxx>
      62             : #include <pagefrm.hxx>
      63             : #include <fldbas.hxx>
      64             : #include <edimp.hxx>
      65             : #include <swundo.hxx>
      66             : #include <viewimp.hxx>
      67             : #include <dview.hxx>
      68             : #include <dcontact.hxx>
      69             : #include <dflyobj.hxx>
      70             : #include <docsh.hxx>
      71             : #include <pagedesc.hxx>
      72             : #include <mvsave.hxx>
      73             : #include <vcl/virdev.hxx>
      74             : 
      75             : 
      76             : using namespace ::com::sun::star;
      77             : 
      78             : /*************************************************************************
      79             : |*
      80             : |*  SwFEShell::Copy()   copy for the internal clipboard.
      81             : |*      Copies all selections to the clipboard.
      82             : |*
      83             : |*************************************************************************/
      84             : 
      85           0 : sal_Bool SwFEShell::Copy( SwDoc* pClpDoc, const String* pNewClpTxt )
      86             : {
      87             :     OSL_ENSURE( pClpDoc, "kein Clipboard-Dokument"  );
      88             : 
      89           0 :     pClpDoc->GetIDocumentUndoRedo().DoUndo(false); // always false!
      90             : 
      91             :     // delete content if ClpDocument contains content
      92           0 :     SwNodeIndex aSttIdx( pClpDoc->GetNodes().GetEndOfExtras(), 2 );
      93           0 :     SwTxtNode* pTxtNd = aSttIdx.GetNode().GetTxtNode();
      94           0 :     if( !pTxtNd || pTxtNd->GetTxt().Len() ||
      95           0 :         aSttIdx.GetIndex()+1 != pClpDoc->GetNodes().GetEndOfContent().GetIndex() )
      96             :     {
      97           0 :         pClpDoc->GetNodes().Delete( aSttIdx,
      98           0 :             pClpDoc->GetNodes().GetEndOfContent().GetIndex() - aSttIdx.GetIndex() );
      99           0 :         pTxtNd = pClpDoc->GetNodes().MakeTxtNode( aSttIdx,
     100           0 :                             (SwTxtFmtColl*)pClpDoc->GetDfltTxtFmtColl() );
     101           0 :         aSttIdx--;
     102             :     }
     103             : 
     104             :     // also delete surrounding FlyFrames if any
     105           0 :     for( sal_uInt16 n = 0; n < pClpDoc->GetSpzFrmFmts()->size(); ++n )
     106             :     {
     107           0 :         SwFlyFrmFmt* pFly = (SwFlyFrmFmt*)(*pClpDoc->GetSpzFrmFmts())[n];
     108           0 :         pClpDoc->DelLayoutFmt( pFly );
     109             :     }
     110           0 :     pClpDoc->GCFieldTypes();        // delete the FieldTypes
     111             : 
     112             :     // if a string was passed, copy it to the clipboard-
     113             :     // document. Then also the Calculator can use the internal
     114             :     // clipboard
     115           0 :     if( pNewClpTxt )
     116             :     {
     117           0 :         pTxtNd->InsertText( *pNewClpTxt, SwIndex( pTxtNd ) );
     118           0 :         return sal_True;                // das wars.
     119             :     }
     120             : 
     121           0 :     pClpDoc->LockExpFlds();
     122           0 :     pClpDoc->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_DELETE_REDLINES );
     123             :     sal_Bool bRet;
     124             : 
     125             :     // do we want to copy a FlyFrame?
     126           0 :     if( IsFrmSelected() )
     127             :     {
     128             :         // get the FlyFormat
     129           0 :         SwFlyFrm* pFly = FindFlyFrm();
     130           0 :         SwFrmFmt* pFlyFmt = pFly->GetFmt();
     131           0 :         SwFmtAnchor aAnchor( pFlyFmt->GetAnchor() );
     132             : 
     133           0 :         if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     134           0 :             (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     135           0 :             (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     136           0 :             (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     137             :         {
     138           0 :             SwPosition aPos( aSttIdx );
     139           0 :             if ( FLY_AS_CHAR == aAnchor.GetAnchorId() )
     140             :             {
     141           0 :                 aPos.nContent.Assign( pTxtNd, 0 );
     142             :             }
     143           0 :             aAnchor.SetAnchor( &aPos );
     144             :         }
     145           0 :         pFlyFmt = pClpDoc->CopyLayoutFmt( *pFlyFmt, aAnchor, true, true );
     146             : 
     147             :        // assure the "RootFmt" is the first element in Spz-Array
     148             :         // (if necessary Flys were copied in Flys)
     149           0 :         SwFrmFmts& rSpzFrmFmts = *(SwFrmFmts*)pClpDoc->GetSpzFrmFmts();
     150           0 :         if( rSpzFrmFmts[ 0 ] != pFlyFmt )
     151             :         {
     152           0 :             SwFrmFmts::iterator it = std::find( rSpzFrmFmts.begin(), rSpzFrmFmts.end(), pFlyFmt );
     153             :             OSL_ENSURE( it != rSpzFrmFmts.end(), "Fly not contained in Spz-Array" );
     154             : 
     155           0 :             rSpzFrmFmts.erase( it );
     156           0 :             rSpzFrmFmts.insert( rSpzFrmFmts.begin(), pFlyFmt );
     157             :         }
     158             : 
     159           0 :         if ( FLY_AS_CHAR == aAnchor.GetAnchorId() )
     160             :         {
     161             :             // JP 13.02.99  Bug 61863: if a frameselection is passed to the
     162             :             //              clipboard, it should be found at pasting. Therefore
     163             :             //              the copied TextAttribut should be removed in the node
     164             :             //              otherwise it will be recognised as TextSelektion
     165           0 :             const SwIndex& rIdx = pFlyFmt->GetAnchor().GetCntntAnchor()->nContent;
     166             :             SwTxtFlyCnt *const pTxtFly = static_cast<SwTxtFlyCnt *>(
     167             :                 pTxtNd->GetTxtAttrForCharAt(
     168           0 :                     rIdx.GetIndex(), RES_TXTATR_FLYCNT));
     169           0 :             if( pTxtFly )
     170             :             {
     171           0 :                 ((SwFmtFlyCnt&)pTxtFly->GetFlyCnt()).SetFlyFmt( 0 );
     172           0 :                 pTxtNd->EraseText( rIdx, 1 );
     173             :             }
     174             :         }
     175           0 :         bRet = sal_True;
     176             :     }
     177           0 :     else if ( IsObjSelected() )
     178             :     {
     179           0 :         SwPosition aPos( aSttIdx, SwIndex( pTxtNd, 0 ));
     180           0 :         const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
     181           0 :         for ( sal_uInt16 i = 0; i < rMrkList.GetMarkCount(); ++i )
     182             :         {
     183           0 :             SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
     184             : 
     185           0 :             if( Imp()->GetDrawView()->IsGroupEntered() ||
     186           0 :                 ( !pObj->GetUserCall() && pObj->GetUpGroup()) )
     187             :             {
     188           0 :                 SfxItemSet aSet( pClpDoc->GetAttrPool(), aFrmFmtSetRange );
     189             : 
     190           0 :                 SwFmtAnchor aAnchor( FLY_AT_PARA );
     191           0 :                 aAnchor.SetAnchor( &aPos );
     192           0 :                 aSet.Put( aAnchor );
     193             : 
     194             :                 SdrObject *const pNew =
     195           0 :                     pClpDoc->CloneSdrObj( *pObj, false, true );
     196             : 
     197           0 :                 SwPaM aTemp(aPos);
     198           0 :                 pClpDoc->Insert(aTemp, *pNew, &aSet, NULL);
     199             :             }
     200             :             else
     201             :             {
     202           0 :                 SwDrawContact *pContact = (SwDrawContact*)GetUserCall( pObj );
     203           0 :                 SwFrmFmt *pFmt = pContact->GetFmt();
     204           0 :                 SwFmtAnchor aAnchor( pFmt->GetAnchor() );
     205           0 :                 if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     206           0 :                     (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     207           0 :                     (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     208           0 :                     (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     209             :                 {
     210           0 :                     aAnchor.SetAnchor( &aPos );
     211             :                 }
     212             : 
     213           0 :                 pClpDoc->CopyLayoutFmt( *pFmt, aAnchor, true, true );
     214             :             }
     215             :         }
     216           0 :         bRet = sal_True;
     217             :     }
     218             :     else
     219           0 :         bRet = _CopySelToDoc( pClpDoc, 0 );     // copy the selections
     220             : 
     221           0 :     pClpDoc->SetRedlineMode_intern((RedlineMode_t)0 );
     222           0 :     pClpDoc->UnlockExpFlds();
     223           0 :     if( !pClpDoc->IsExpFldsLocked() )
     224           0 :         pClpDoc->UpdateExpFlds(NULL, true);
     225             : 
     226           0 :     return bRet;
     227             : }
     228             : 
     229           0 : static const Point &lcl_FindBasePos( const SwFrm *pFrm, const Point &rPt )
     230             : {
     231           0 :     const SwFrm *pF = pFrm;
     232           0 :     while ( pF && !pF->Frm().IsInside( rPt ) )
     233             :     {
     234           0 :         if ( pF->IsCntntFrm() )
     235           0 :             pF = ((SwCntntFrm*)pF)->GetFollow();
     236             :         else
     237           0 :             pF = 0;
     238             :     }
     239           0 :     if ( pF )
     240           0 :         return pF->Frm().Pos();
     241             :     else
     242           0 :         return pFrm->Frm().Pos();
     243             : }
     244             : 
     245           0 : static sal_Bool lcl_SetAnchor( const SwPosition& rPos, const SwNode& rNd, SwFlyFrm* pFly,
     246             :                 const Point& rInsPt, SwFEShell& rDestShell, SwFmtAnchor& rAnchor,
     247             :                 Point& rNewPos, bool bCheckFlyRecur )
     248             : {
     249           0 :     sal_Bool bRet = sal_True;
     250           0 :     rAnchor.SetAnchor( &rPos );
     251           0 :     SwCntntFrm* pTmpFrm = rNd.GetCntntNode()->getLayoutFrm( rDestShell.GetLayout(), &rInsPt, 0, sal_False );
     252           0 :     SwFlyFrm *pTmpFly = pTmpFrm->FindFlyFrm();
     253           0 :     if( pTmpFly && bCheckFlyRecur && pFly->IsUpperOf( *pTmpFly ) )
     254             :     {
     255           0 :         bRet = sal_False;
     256             :     }
     257           0 :     else if ( FLY_AT_FLY == rAnchor.GetAnchorId() )
     258             :     {
     259           0 :         if( pTmpFly )
     260             :         {
     261           0 :             const SwNodeIndex& rIdx = *pTmpFly->GetFmt()->GetCntnt().GetCntntIdx();
     262           0 :             SwPosition aPos( rIdx );
     263           0 :             rAnchor.SetAnchor( &aPos );
     264           0 :             rNewPos = pTmpFly->Frm().Pos();
     265             :         }
     266             :         else
     267             :         {
     268           0 :             rAnchor.SetType( FLY_AT_PAGE );
     269           0 :             rAnchor.SetPageNum( rDestShell.GetPageNumber( rInsPt ) );
     270           0 :             const SwFrm *pPg = pTmpFrm->FindPageFrm();
     271           0 :             rNewPos = pPg->Frm().Pos();
     272             :         }
     273             :     }
     274             :     else
     275           0 :         rNewPos = ::lcl_FindBasePos( pTmpFrm, rInsPt );
     276           0 :     return bRet;
     277             : }
     278             : 
     279           0 : sal_Bool SwFEShell::CopyDrawSel( SwFEShell* pDestShell, const Point& rSttPt,
     280             :                     const Point& rInsPt, sal_Bool bIsMove, sal_Bool bSelectInsert )
     281             : {
     282           0 :     sal_Bool bRet = sal_True;
     283             : 
     284             :     // The list should be copied, because below new objects will be selected
     285           0 :     const SdrMarkList aMrkList( Imp()->GetDrawView()->GetMarkedObjectList() );
     286           0 :     sal_uLong nMarkCount = aMrkList.GetMarkCount();
     287           0 :     if( !pDestShell->Imp()->GetDrawView() )
     288             :         // should create it now
     289           0 :         pDestShell->MakeDrawView();
     290           0 :     else if( bSelectInsert )
     291           0 :         pDestShell->Imp()->GetDrawView()->UnmarkAll();
     292             : 
     293           0 :     SdrPageView *pDestPgView = pDestShell->Imp()->GetPageView(),
     294           0 :                 *pSrcPgView = Imp()->GetPageView();
     295           0 :     SwDrawView *pDestDrwView = pDestShell->Imp()->GetDrawView(),
     296           0 :                 *pSrcDrwView = Imp()->GetDrawView();
     297           0 :     SwDoc* pDestDoc = pDestShell->GetDoc();
     298             : 
     299           0 :     Size aSiz( rInsPt.X() - rSttPt.X(), rInsPt.Y() - rSttPt.Y() );
     300           0 :     for( sal_uInt16 i = 0; i < nMarkCount; ++i )
     301             :     {
     302           0 :         SdrObject *pObj = aMrkList.GetMark( i )->GetMarkedSdrObj();
     303             : 
     304           0 :         SwDrawContact *pContact = (SwDrawContact*)GetUserCall( pObj );
     305           0 :         SwFrmFmt *pFmt = pContact->GetFmt();
     306           0 :         const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
     307             : 
     308           0 :         bool bInsWithFmt = true;
     309             : 
     310           0 :         if( pDestDrwView->IsGroupEntered() )
     311             :         {
     312             :             // insert into the group, when it belongs to an entered group
     313             :             // or when the object is not anchored as a character
     314           0 :             if( pSrcDrwView->IsGroupEntered() ||
     315           0 :                 (FLY_AS_CHAR != rAnchor.GetAnchorId()) )
     316             : 
     317             :             {
     318             :                 SdrObject* pNew = pDestDoc->CloneSdrObj( *pObj, bIsMove &&
     319           0 :                                         GetDoc() == pDestDoc, false );
     320           0 :                 pNew->NbcMove( aSiz );
     321           0 :                 pDestDrwView->InsertObjectAtView( pNew, *pDestPgView );
     322           0 :                 bInsWithFmt = false;
     323             :             }
     324             :         }
     325             : 
     326           0 :         if( bInsWithFmt )
     327             :         {
     328           0 :             SwFmtAnchor aAnchor( rAnchor );
     329           0 :             Point aNewAnch;
     330             : 
     331           0 :             if ((FLY_AT_PARA == aAnchor.GetAnchorId()) ||
     332           0 :                 (FLY_AT_CHAR == aAnchor.GetAnchorId()) ||
     333           0 :                 (FLY_AT_FLY  == aAnchor.GetAnchorId()) ||
     334           0 :                 (FLY_AS_CHAR == aAnchor.GetAnchorId()))
     335             :             {
     336           0 :                 if ( this == pDestShell )
     337             :                 {
     338             :                     // same shell? Then request the position
     339             :                     // from the passed DocumentPosition
     340           0 :                     SwPosition aPos( *GetCrsr()->GetPoint() );
     341           0 :                     Point aPt( rInsPt );
     342           0 :                     aPt -= rSttPt - pObj->GetSnapRect().TopLeft();
     343           0 :                     SwCrsrMoveState aState( MV_SETONLYTEXT );
     344           0 :                     GetLayout()->GetCrsrOfst( &aPos, aPt, &aState );
     345             :                     const SwNode *pNd;
     346           0 :                     if( (pNd = &aPos.nNode.GetNode())->IsNoTxtNode() )
     347           0 :                         bRet = sal_False;
     348             :                     else
     349             :                         bRet = ::lcl_SetAnchor( aPos, *pNd, 0, rInsPt,
     350           0 :                                 *pDestShell, aAnchor, aNewAnch, false );
     351             :                 }
     352             :                 else
     353             :                 {
     354           0 :                     SwPaM *pCrsr = pDestShell->GetCrsr();
     355           0 :                     if( pCrsr->GetNode()->IsNoTxtNode() )
     356           0 :                         bRet = sal_False;
     357             :                     else
     358           0 :                         bRet = ::lcl_SetAnchor( *pCrsr->GetPoint(),
     359           0 :                                                 *pCrsr->GetNode(), 0, rInsPt,
     360             :                                                 *pDestShell, aAnchor,
     361           0 :                                                 aNewAnch, false );
     362             :                 }
     363             :             }
     364           0 :             else if ( FLY_AT_PAGE == aAnchor.GetAnchorId() )
     365             :             {
     366           0 :                 aAnchor.SetPageNum( pDestShell->GetPageNumber( rInsPt ) );
     367           0 :                 const SwRootFrm* pTmpRoot = pDestShell->GetLayout();
     368           0 :                 const SwFrm* pPg = pTmpRoot->GetPageAtPos( rInsPt, 0, true );
     369           0 :                 if ( pPg )
     370           0 :                     aNewAnch = pPg->Frm().Pos();
     371             :             }
     372             : 
     373           0 :             if( bRet )
     374             :             {
     375           0 :                 if( pSrcDrwView->IsGroupEntered() ||
     376           0 :                     ( !pObj->GetUserCall() && pObj->GetUpGroup()) )
     377             :                 {
     378           0 :                     SfxItemSet aSet( pDestDoc->GetAttrPool(),aFrmFmtSetRange);
     379           0 :                     aSet.Put( aAnchor );
     380             :                     SdrObject* pNew = pDestDoc->CloneSdrObj( *pObj, bIsMove &&
     381           0 :                                                 GetDoc() == pDestDoc, true );
     382           0 :                     pFmt = pDestDoc->Insert( *pDestShell->GetCrsr(),
     383           0 :                                             *pNew, &aSet, NULL );
     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.X(), text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
     400           0 :                         pFmt->SetFmtAttr( SwFmtVertOrient( aPos.Y(), 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 = pDoc->IsCopyIsMove();
     460           0 :     if( bIsMove )
     461             :         // set a flag in Doc, handled in TextNodes
     462           0 :         pDoc->SetCopyIsMove( sal_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.X(),text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
     545           0 :                 pFlyFmt->SetFmtAttr( SwFmtVertOrient( aPos.Y(),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             :                                         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 :     pDoc->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( sal_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(this)
     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             :                             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             : 
    1043             :                 {
    1044           0 :                     ++aIndexBefore;
    1045             :                     SwPaM aPaM(SwPosition(aIndexBefore),
    1046           0 :                                SwPosition(rInsPos.nNode));
    1047             : 
    1048           0 :                     aPaM.GetDoc()->MakeUniqueNumRules(aPaM);
    1049           0 :                 }
    1050             :             }
    1051             : 
    1052             :             // Update the rsid of each pasted text node.
    1053             :             {
    1054           0 :                 xub_StrLen nNodesCnt = aCpyPam.End()->nNode.GetIndex() - aCpyPam.Start()->nNode.GetIndex();
    1055           0 :                 SwNodes &rDestNodes = GetDoc()->GetNodes();
    1056           0 :                 xub_StrLen nDestStart = PCURCRSR->GetPoint()->nNode.GetIndex() - nNodesCnt;
    1057             : 
    1058           0 :                 for ( sal_uInt64 nIdx = 0; nIdx <= nNodesCnt; nIdx++ )
    1059             :                 {
    1060           0 :                     SwTxtNode *pTxtNode = rDestNodes[ nDestStart + nIdx ]->GetTxtNode();
    1061           0 :                     if ( pTxtNode )
    1062             :                     {
    1063           0 :                         GetDoc()->UpdateParRsid( pTxtNode );
    1064             :                     }
    1065             :                 }
    1066             :             }
    1067             : 
    1068           0 :             SaveTblBoxCntnt( &rInsPos );
    1069           0 :             if(bIncludingPageFrames && bStartWithTable)
    1070             :             {
    1071             :                 //remove the paragraph in front of the table
    1072           0 :                 SwPaM aPara(aInsertPosition);
    1073           0 :                 GetDoc()->DelFullPara(aPara);
    1074             :             }
    1075             :             //additionally copy page bound frames
    1076           0 :             if( bIncludingPageFrames && pClpDoc->GetSpzFrmFmts()->size() )
    1077             :             {
    1078             :                 // create a draw view if necessary
    1079           0 :                 if( !Imp()->GetDrawView() )
    1080           0 :                     MakeDrawView();
    1081             : 
    1082           0 :                 for ( sal_uInt16 i = 0; i < pClpDoc->GetSpzFrmFmts()->size(); ++i )
    1083             :                 {
    1084           0 :                     bool bInsWithFmt = true;
    1085           0 :                     const SwFrmFmt& rCpyFmt = *(*pClpDoc->GetSpzFrmFmts())[i];
    1086           0 :                     if( bInsWithFmt  )
    1087             :                     {
    1088           0 :                         SwFmtAnchor aAnchor( rCpyFmt.GetAnchor() );
    1089           0 :                         if ( FLY_AT_PAGE == aAnchor.GetAnchorId() )
    1090             :                         {
    1091           0 :                             aAnchor.SetPageNum( aAnchor.GetPageNum() + nStartPageNumber - 1 );
    1092             :                         }
    1093             :                         else
    1094           0 :                             continue;
    1095           0 :                         GetDoc()->CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
    1096             :                     }
    1097             :                 }
    1098           0 :             }
    1099             :         }
    1100             : 
    1101           0 :         FOREACHPAM_END()
    1102             :     }
    1103             : 
    1104           0 :     GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
    1105             : 
    1106             :     // have new table formulas been inserted?
    1107           0 :     if( pTblFldTyp->GetDepends() )
    1108             :     {
    1109             :         // finish old action: table-frames have been created
    1110             :         // a selection can be made now
    1111             :         sal_uInt16 nActCnt;
    1112           0 :         for( nActCnt = 0; ActionPend(); ++nActCnt )
    1113           0 :             EndAllAction();
    1114             : 
    1115           0 :         for( ; nActCnt; --nActCnt )
    1116           0 :             StartAllAction();
    1117             :     }
    1118           0 :     GetDoc()->UnlockExpFlds();
    1119           0 :     GetDoc()->UpdateFlds(NULL, false);
    1120           0 :     EndAllAction();
    1121             : 
    1122           0 :     return bRet;
    1123             : }
    1124             : 
    1125           0 : sal_Bool SwFEShell::PastePages( SwFEShell& rToFill, sal_uInt16 nStartPage, sal_uInt16 nEndPage)
    1126             : {
    1127           0 :     Push();
    1128           0 :     if(!GotoPage(nStartPage))
    1129             :     {
    1130           0 :         Pop(sal_False);
    1131           0 :         return sal_False;
    1132             :     }
    1133           0 :     MovePage( fnPageCurr, fnPageStart );
    1134           0 :     SwPaM aCpyPam( *GetCrsr()->GetPoint() );
    1135           0 :     String sStartingPageDesc = GetPageDesc( GetCurPageDesc()).GetName();
    1136           0 :     SwPageDesc* pDesc = rToFill.FindPageDescByName( sStartingPageDesc, sal_True );
    1137           0 :     if( pDesc )
    1138           0 :         rToFill.ChgCurPageDesc( *pDesc );
    1139             : 
    1140           0 :     if(!GotoPage(nEndPage))
    1141             :     {
    1142           0 :         Pop(sal_False);
    1143           0 :         return sal_False;
    1144             :     }
    1145             :     //if the page starts with a table a paragraph has to be inserted before
    1146           0 :     SwNode* pTableNode = aCpyPam.GetNode()->FindTableNode();
    1147           0 :     if(pTableNode)
    1148             :     {
    1149             :         //insert a paragraph
    1150           0 :         StartUndo(UNDO_INSERT);
    1151           0 :         SwNodeIndex aTblIdx(  *pTableNode, -1 );
    1152           0 :         SwPosition aBefore(aTblIdx);
    1153           0 :         if(GetDoc()->AppendTxtNode( aBefore ))
    1154             :         {
    1155           0 :             SwPaM aTmp(aBefore);
    1156           0 :             aCpyPam = aTmp;
    1157             :         }
    1158           0 :         EndUndo(UNDO_INSERT);
    1159             :     }
    1160             : 
    1161           0 :     MovePage( fnPageCurr, fnPageEnd );
    1162           0 :     aCpyPam.SetMark();
    1163           0 :     *aCpyPam.GetMark() = *GetCrsr()->GetPoint();
    1164             : 
    1165           0 :     SET_CURR_SHELL( this );
    1166             : 
    1167           0 :     StartAllAction();
    1168           0 :     GetDoc()->LockExpFlds();
    1169           0 :     SetSelection(aCpyPam);
    1170             :     // copy the text of the selection
    1171           0 :     SwEditShell::Copy(&rToFill);
    1172             : 
    1173           0 :     if(pTableNode)
    1174             :     {
    1175             :         //remove the inserted paragraph
    1176           0 :         Undo();
    1177             :         //remove the paragraph in the second doc, too
    1178           0 :         SwNodeIndex aIdx( rToFill.GetDoc()->GetNodes().GetEndOfExtras(), 2 );
    1179           0 :         SwPaM aPara( aIdx ); //DocStart
    1180           0 :         rToFill.GetDoc()->DelFullPara(aPara);
    1181             :     }
    1182             :     // now the page bound objects
    1183             :     // additionally copy page bound frames
    1184           0 :     if( GetDoc()->GetSpzFrmFmts()->size() )
    1185             :     {
    1186             :         // create a draw view if necessary
    1187           0 :         if( !rToFill.Imp()->GetDrawView() )
    1188           0 :             rToFill.MakeDrawView();
    1189             : 
    1190           0 :         for ( sal_uInt16 i = 0; i < GetDoc()->GetSpzFrmFmts()->size(); ++i )
    1191             :         {
    1192           0 :             const SwFrmFmt& rCpyFmt = *(*GetDoc()->GetSpzFrmFmts())[i];
    1193           0 :             SwFmtAnchor aAnchor( rCpyFmt.GetAnchor() );
    1194           0 :             if ((FLY_AT_PAGE == aAnchor.GetAnchorId()) &&
    1195           0 :                     aAnchor.GetPageNum() >= nStartPage && aAnchor.GetPageNum() <= nEndPage)
    1196             :             {
    1197           0 :                 aAnchor.SetPageNum( aAnchor.GetPageNum() - nStartPage + 1);
    1198             :             }
    1199             :             else
    1200           0 :                 continue;
    1201           0 :             rToFill.GetDoc()->CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
    1202           0 :         }
    1203             :     }
    1204           0 :     GetDoc()->UnlockExpFlds();
    1205           0 :     GetDoc()->UpdateFlds(NULL, false);
    1206           0 :     Pop(sal_False);
    1207           0 :     EndAllAction();
    1208             : 
    1209           0 :     return sal_True;
    1210             : }
    1211             : 
    1212           0 : sal_Bool SwFEShell::GetDrawObjGraphic( sal_uLong nFmt, Graphic& rGrf ) const
    1213             : {
    1214             :     OSL_ENSURE( Imp()->HasDrawView(), "GetDrawObjGraphic without DrawView?" );
    1215           0 :     const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
    1216           0 :     sal_Bool bConvert = sal_True;
    1217           0 :     if( rMrkList.GetMarkCount() )
    1218             :     {
    1219           0 :         if( rMrkList.GetMarkCount() == 1 &&
    1220           0 :             rMrkList.GetMark( 0 )->GetMarkedSdrObj()->ISA(SwVirtFlyDrawObj) )
    1221             :         {
    1222             :             // select frame
    1223           0 :             if( CNT_GRF == GetCntType() )
    1224             :             {
    1225           0 :                 const Graphic* pGrf( GetGraphic() );
    1226           0 :                 if ( pGrf )
    1227             :                 {
    1228           0 :                     Graphic aGrf( *pGrf );
    1229           0 :                     if( SOT_FORMAT_GDIMETAFILE == nFmt )
    1230             :                     {
    1231           0 :                         if( GRAPHIC_BITMAP != aGrf.GetType() )
    1232             :                         {
    1233           0 :                             rGrf = aGrf;
    1234           0 :                             bConvert = sal_False;
    1235             :                         }
    1236           0 :                         else if( GetWin() )
    1237             :                         {
    1238           0 :                             Size aSz;
    1239           0 :                             Point aPt;
    1240           0 :                             GetGrfSize( aSz );
    1241             : 
    1242           0 :                             VirtualDevice aVirtDev;
    1243           0 :                             aVirtDev.EnableOutput( sal_False );
    1244             : 
    1245           0 :                             MapMode aTmp( GetWin()->GetMapMode() );
    1246           0 :                             aTmp.SetOrigin( aPt );
    1247           0 :                             aVirtDev.SetMapMode( aTmp );
    1248             : 
    1249           0 :                             GDIMetaFile aMtf;
    1250           0 :                             aMtf.Record( &aVirtDev );
    1251           0 :                             aGrf.Draw( &aVirtDev, aPt, aSz );
    1252           0 :                             aMtf.Stop();
    1253           0 :                             aMtf.SetPrefMapMode( aTmp );
    1254           0 :                             aMtf.SetPrefSize( aSz );
    1255           0 :                             rGrf = aMtf;
    1256             :                         }
    1257             :                     }
    1258           0 :                     else if( GRAPHIC_BITMAP == aGrf.GetType() )
    1259             :                     {
    1260           0 :                         rGrf = aGrf;
    1261           0 :                         bConvert = sal_False;
    1262             :                     }
    1263             :                     else
    1264             :                     {
    1265             :                         // fix(23806): not the origial size, but the current one.
    1266             :                         // Otherwise it could happen that for vector graphics
    1267             :                         // many MB's of memory are allocated.
    1268           0 :                         const Size aSz( FindFlyFrm()->Prt().SSize() );
    1269           0 :                         VirtualDevice aVirtDev( *GetWin() );
    1270             : 
    1271           0 :                         MapMode aTmp( MAP_TWIP );
    1272           0 :                         aVirtDev.SetMapMode( aTmp );
    1273           0 :                         if( aVirtDev.SetOutputSize( aSz ) )
    1274             :                         {
    1275           0 :                             aGrf.Draw( &aVirtDev, Point(), aSz );
    1276           0 :                             rGrf = aVirtDev.GetBitmap( Point(), aSz );
    1277             :                         }
    1278             :                         else
    1279             :                         {
    1280           0 :                             rGrf = aGrf;
    1281           0 :                             bConvert = sal_False;
    1282           0 :                         }
    1283           0 :                     }
    1284             :                 }
    1285             :             }
    1286             :         }
    1287           0 :         else if( SOT_FORMAT_GDIMETAFILE == nFmt )
    1288           0 :             rGrf = Imp()->GetDrawView()->GetMarkedObjMetaFile();
    1289           0 :         else if( SOT_FORMAT_BITMAP == nFmt )
    1290           0 :             rGrf = Imp()->GetDrawView()->GetMarkedObjBitmapEx();
    1291             :     }
    1292           0 :     return bConvert;
    1293             : }
    1294             : 
    1295             : // #i50824#
    1296             : // replace method <lcl_RemoveOleObjsFromSdrModel> by <lcl_ConvertSdrOle2ObjsToSdrGrafObjs>
    1297           0 : static void lcl_ConvertSdrOle2ObjsToSdrGrafObjs( SdrModel* _pModel )
    1298             : {
    1299           0 :     for ( sal_uInt16 nPgNum = 0; nPgNum < _pModel->GetPageCount(); ++nPgNum )
    1300             :     {
    1301             :         // setup object iterator in order to iterate through all objects
    1302             :         // including objects in group objects, but exclusive group objects.
    1303           0 :         SdrObjListIter aIter(*(_pModel->GetPage( nPgNum )));
    1304           0 :         while( aIter.IsMore() )
    1305             :         {
    1306           0 :             SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( aIter.Next() );
    1307           0 :             if( pOle2Obj )
    1308             :             {
    1309             :                 // found an ole2 shape
    1310           0 :                 SdrObjList* pObjList = pOle2Obj->GetObjList();
    1311             : 
    1312             :                 // get its graphic
    1313           0 :                 Graphic aGraphic;
    1314           0 :                 pOle2Obj->Connect();
    1315           0 :                 Graphic* pGraphic = pOle2Obj->GetGraphic();
    1316           0 :                 if( pGraphic )
    1317           0 :                     aGraphic = *pGraphic;
    1318           0 :                 pOle2Obj->Disconnect();
    1319             : 
    1320             :                 // create new graphic shape with the ole graphic and shape size
    1321           0 :                 SdrGrafObj* pGraphicObj = new SdrGrafObj( aGraphic, pOle2Obj->GetCurrentBoundRect() );
    1322             :                 // apply layer of ole2 shape at graphic shape
    1323           0 :                 pGraphicObj->SetLayer( pOle2Obj->GetLayer() );
    1324             : 
    1325             :                 // replace ole2 shape with the new graphic object and delete the ol2 shape
    1326           0 :                 SdrObject* pRemovedObject = pObjList->ReplaceObject( pGraphicObj, pOle2Obj->GetOrdNum() );
    1327           0 :                 SdrObject::Free( pRemovedObject );
    1328             :             }
    1329             :         }
    1330           0 :     }
    1331           0 : }
    1332             : 
    1333           0 : void SwFEShell::Paste( SvStream& rStrm, sal_uInt16 nAction, const Point* pPt )
    1334             : {
    1335           0 :     SET_CURR_SHELL( this );
    1336           0 :     StartAllAction();
    1337           0 :     StartUndo();
    1338             : 
    1339           0 :     SvtPathOptions aPathOpt;
    1340             :     FmFormModel* pModel = new FmFormModel( aPathOpt.GetPalettePath(),
    1341           0 :                                             0, GetDoc()->GetDocShell() );
    1342           0 :     pModel->GetItemPool().FreezeIdRanges();
    1343             : 
    1344           0 :     rStrm.Seek(0);
    1345             : 
    1346           0 :     uno::Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( rStrm ) );
    1347           0 :     SvxDrawingLayerImport( pModel, xInputStream );
    1348             : 
    1349           0 :     if ( !Imp()->HasDrawView() )
    1350           0 :         Imp()->MakeDrawView();
    1351             : 
    1352           0 :     Point aPos( pPt ? *pPt : GetCharRect().Pos() );
    1353           0 :     SdrView *pView = Imp()->GetDrawView();
    1354             : 
    1355             :     // drop on the existing object: replace object or apply new attributes
    1356           0 :     if( pModel->GetPageCount() > 0 &&
    1357           0 :         1 == pModel->GetPage(0)->GetObjCount() &&
    1358           0 :         1 == pView->GetMarkedObjectList().GetMarkCount() )
    1359             :     {
    1360             :         // replace a marked 'virtual' drawing object
    1361             :         // by its corresponding 'master' drawing object in the mark list.
    1362           0 :         SwDrawView::ReplaceMarkedDrawVirtObjs( *pView );
    1363             : 
    1364           0 :         SdrObject* pClpObj = pModel->GetPage(0)->GetObj(0);
    1365           0 :         SdrObject* pOldObj = pView->GetMarkedObjectList().GetMark( 0 )->GetMarkedSdrObj();
    1366             : 
    1367           0 :         if( SW_PASTESDR_SETATTR == nAction && pOldObj->ISA(SwVirtFlyDrawObj) )
    1368           0 :             nAction = SW_PASTESDR_REPLACE;
    1369             : 
    1370           0 :         switch( nAction )
    1371             :         {
    1372             :         case SW_PASTESDR_REPLACE:
    1373             :             {
    1374           0 :                 const SwFrmFmt* pFmt(0);
    1375           0 :                 const SwFrm* pAnchor(0);
    1376           0 :                 if( pOldObj->ISA(SwVirtFlyDrawObj) )
    1377             :                 {
    1378           0 :                     pFmt = FindFrmFmt( pOldObj );
    1379             : 
    1380           0 :                     Point aNullPt;
    1381           0 :                     SwFlyFrm* pFlyFrm = ((SwFlyFrmFmt*)pFmt)->GetFrm( &aNullPt );
    1382           0 :                     pAnchor = pFlyFrm->GetAnchorFrm();
    1383             : 
    1384           0 :                     if( pAnchor->FindFooterOrHeader() )
    1385             :                     {
    1386             :                         // if there is a textframe in the header/footer:
    1387             :                         // do not replace but insert
    1388           0 :                         nAction = SW_PASTESDR_INSERT;
    1389             :                         break;
    1390             :                     }
    1391             :                 }
    1392             : 
    1393           0 :                 SdrObject* pNewObj = pClpObj->Clone();
    1394           0 :                 Rectangle aOldObjRect( pOldObj->GetCurrentBoundRect() );
    1395           0 :                 Size aOldObjSize( aOldObjRect.GetSize() );
    1396           0 :                 Rectangle aNewRect( pNewObj->GetCurrentBoundRect() );
    1397           0 :                 Size aNewSize( aNewRect.GetSize() );
    1398             : 
    1399           0 :                 Fraction aScaleWidth( aOldObjSize.Width(), aNewSize.Width() );
    1400           0 :                 Fraction aScaleHeight( aOldObjSize.Height(), aNewSize.Height());
    1401           0 :                 pNewObj->NbcResize( aNewRect.TopLeft(), aScaleWidth, aScaleHeight);
    1402             : 
    1403           0 :                 Point aVec = aOldObjRect.TopLeft() - aNewRect.TopLeft();
    1404           0 :                 pNewObj->NbcMove(Size(aVec.X(), aVec.Y()));
    1405             : 
    1406           0 :                 if( pNewObj->ISA( SdrUnoObj ) )
    1407           0 :                     pNewObj->SetLayer( GetDoc()->GetControlsId() );
    1408           0 :                 else if( pOldObj->ISA( SdrUnoObj ) )
    1409           0 :                     pNewObj->SetLayer( GetDoc()->GetHeavenId() );
    1410             :                 else
    1411           0 :                     pNewObj->SetLayer( pOldObj->GetLayer() );
    1412             : 
    1413           0 :                 if( pOldObj->ISA(SwVirtFlyDrawObj) )
    1414             :                 {
    1415             :                     // store attributes, then set SdrObject
    1416           0 :                     SfxItemSet aFrmSet( pDoc->GetAttrPool(),
    1417           0 :                                             RES_SURROUND, RES_ANCHOR );
    1418           0 :                     aFrmSet.Set( pFmt->GetAttrSet() );
    1419             : 
    1420           0 :                     Point aNullPt;
    1421           0 :                     if( pAnchor->IsTxtFrm() && ((SwTxtFrm*)pAnchor)->IsFollow() )
    1422             :                     {
    1423           0 :                         const SwTxtFrm* pTmp = (SwTxtFrm*)pAnchor;
    1424           0 :                         do {
    1425           0 :                             pTmp = pTmp->FindMaster();
    1426             :                             OSL_ENSURE( pTmp, "Where's my Master?" );
    1427           0 :                         } while( pTmp->IsFollow() );
    1428           0 :                         pAnchor = pTmp;
    1429             :                     }
    1430           0 :                     if( pOldObj->ISA( SdrCaptionObj ))
    1431           0 :                         aNullPt = ((SdrCaptionObj*)pOldObj)->GetTailPos();
    1432             :                     else
    1433           0 :                         aNullPt = aOldObjRect.TopLeft();
    1434             : 
    1435           0 :                     Point aNewAnchor = pAnchor->GetFrmAnchorPos( ::HasWrap( pOldObj ) );
    1436             :                     // OD 2004-04-05 #i26791# - direct positioning of Writer
    1437             :                     // fly frame object for <SwDoc::Insert(..)>
    1438           0 :                     pNewObj->NbcSetRelativePos( aNullPt - aNewAnchor );
    1439           0 :                     pNewObj->NbcSetAnchorPos( aNewAnchor );
    1440             : 
    1441           0 :                     pOldObj->GetOrdNum();
    1442             : 
    1443           0 :                     DelSelectedObj();
    1444             : 
    1445           0 :                     pFmt = GetDoc()->Insert( *GetCrsr(), *pNewObj, &aFrmSet, NULL );
    1446             :                 }
    1447             :                 else
    1448           0 :                     pView->ReplaceObjectAtView( pOldObj, *Imp()->GetPageView(), pNewObj, sal_True );
    1449             :             }
    1450           0 :             break;
    1451             : 
    1452             :         case SW_PASTESDR_SETATTR:
    1453             :             {
    1454           0 :                 SfxItemSet aSet( GetAttrPool() );
    1455           0 :                 aSet.Put(pClpObj->GetMergedItemSet());
    1456           0 :                 pView->SetAttributes( aSet, sal_False );
    1457             :             }
    1458           0 :             break;
    1459             : 
    1460             :         default:
    1461           0 :             nAction = SW_PASTESDR_INSERT;
    1462           0 :             break;
    1463             :         }
    1464             :     }
    1465             :     else
    1466           0 :         nAction = SW_PASTESDR_INSERT;
    1467             : 
    1468           0 :     if( SW_PASTESDR_INSERT == nAction )
    1469             :     {
    1470           0 :         ::sw::DrawUndoGuard drawUndoGuard(GetDoc()->GetIDocumentUndoRedo());
    1471             : 
    1472           0 :         sal_Bool bDesignMode = pView->IsDesignMode();
    1473           0 :         if( !bDesignMode )
    1474           0 :             pView->SetDesignMode( sal_True );
    1475             : 
    1476             :         // #i50824#
    1477             :         // method <lcl_RemoveOleObjsFromSdrModel> replaced by <lcl_ConvertSdrOle2ObjsToSdrGrafObjs>
    1478           0 :         lcl_ConvertSdrOle2ObjsToSdrGrafObjs( pModel );
    1479           0 :         pView->Paste( *pModel, aPos );
    1480             : 
    1481           0 :         sal_uLong nCnt = pView->GetMarkedObjectList().GetMarkCount();
    1482           0 :         if( nCnt )
    1483             :         {
    1484           0 :             const Point aNull( 0, 0 );
    1485           0 :             for( sal_uLong i=0; i < nCnt; ++i )
    1486             :             {
    1487           0 :                 SdrObject *pObj = pView->GetMarkedObjectList().GetMark(i)->GetMarkedSdrObj();
    1488           0 :                 pObj->ImpSetAnchorPos( aNull );
    1489             :             }
    1490             : 
    1491           0 :             pView->SetCurrentObj( OBJ_GRUP, SdrInventor );
    1492           0 :             if ( nCnt > 1 )
    1493           0 :                 pView->GroupMarked();
    1494           0 :             SdrObject *pObj = pView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
    1495           0 :             if( pObj->ISA( SdrUnoObj ) )
    1496             :             {
    1497           0 :                 pObj->SetLayer( GetDoc()->GetControlsId() );
    1498           0 :                 bDesignMode = sal_True;
    1499             :             }
    1500             :             else
    1501           0 :                 pObj->SetLayer( GetDoc()->GetHeavenId() );
    1502           0 :             const Rectangle &rSnap = pObj->GetSnapRect();
    1503           0 :             const Size aDiff( rSnap.GetWidth()/2, rSnap.GetHeight()/2 );
    1504           0 :             pView->MoveMarkedObj( aDiff );
    1505           0 :             ImpEndCreate();
    1506           0 :             if( !bDesignMode )
    1507           0 :                 pView->SetDesignMode( sal_False );
    1508           0 :         }
    1509             :     }
    1510           0 :     EndUndo();
    1511           0 :     EndAllAction();
    1512           0 :     delete pModel;
    1513           0 : }
    1514             : 
    1515           0 : sal_Bool SwFEShell::Paste( const Graphic &rGrf )
    1516             : {
    1517           0 :     SET_CURR_SHELL( this );
    1518             :     SdrObject* pObj;
    1519           0 :     SdrView *pView = Imp()->GetDrawView();
    1520             : 
    1521           0 :     sal_Bool bRet = 1 == pView->GetMarkedObjectList().GetMarkCount() &&
    1522           0 :         (pObj = pView->GetMarkedObjectList().GetMark( 0 )->GetMarkedSdrObj())->IsClosedObj() &&
    1523           0 :         !pObj->ISA( SdrOle2Obj );
    1524             : 
    1525           0 :     if( bRet )
    1526             :     {
    1527           0 :         XOBitmap aXOBitmap( rGrf.GetBitmap() );
    1528           0 :         SfxItemSet aSet( GetAttrPool(), XATTR_FILLSTYLE, XATTR_FILLBITMAP );
    1529           0 :         aSet.Put( XFillStyleItem( XFILL_BITMAP ));
    1530           0 :         aSet.Put( XFillBitmapItem( aEmptyStr, aXOBitmap ));
    1531           0 :         pView->SetAttributes( aSet, sal_False );
    1532             :     }
    1533           0 :     return bRet;
    1534             : }
    1535             : 
    1536             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10