LCOV - code coverage report
Current view: top level - sc/source/ui/view - viewfun3.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 255 1013 25.2 %
Date: 2014-11-03 Functions: 7 20 35.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 "scitems.hxx"
      21             : #include <svx/svdetc.hxx>
      22             : #include <svx/svditer.hxx>
      23             : #include <svx/svdoole2.hxx>
      24             : #include <svx/svdpage.hxx>
      25             : #include <sfx2/dispatch.hxx>
      26             : #include <sfx2/docfile.hxx>
      27             : #include <svl/stritem.hxx>
      28             : #include <svl/ptitem.hxx>
      29             : #include <svl/urlbmk.hxx>
      30             : #include <comphelper/classids.hxx>
      31             : #include <sot/formats.hxx>
      32             : #include <vcl/graph.hxx>
      33             : #include <vcl/virdev.hxx>
      34             : #include <vcl/msgbox.hxx>
      35             : #include <tools/urlobj.hxx>
      36             : #include <sot/exchange.hxx>
      37             : #include <memory>
      38             : 
      39             : #include "attrib.hxx"
      40             : #include "patattr.hxx"
      41             : #include "dociter.hxx"
      42             : #include "viewfunc.hxx"
      43             : #include "tabvwsh.hxx"
      44             : #include "docsh.hxx"
      45             : #include "docfunc.hxx"
      46             : #include "undoblk.hxx"
      47             : #include "refundo.hxx"
      48             : #include "globstr.hrc"
      49             : #include "global.hxx"
      50             : #include "transobj.hxx"
      51             : #include "drwtrans.hxx"
      52             : #include "rangenam.hxx"
      53             : #include "dbdata.hxx"
      54             : #include "impex.hxx"
      55             : #include "chgtrack.hxx"
      56             : #include "waitoff.hxx"
      57             : #include "scmod.hxx"
      58             : #include "sc.hrc"
      59             : #include "inputopt.hxx"
      60             : #include "warnbox.hxx"
      61             : #include "drwlayer.hxx"
      62             : #include "editable.hxx"
      63             : #include "docuno.hxx"
      64             : #include "clipparam.hxx"
      65             : #include "undodat.hxx"
      66             : #include "drawview.hxx"
      67             : #include "cliputil.hxx"
      68             : #include <gridwin.hxx>
      69             : #include <boost/scoped_ptr.hpp>
      70             : 
      71             : using namespace com::sun::star;
      72             : 
      73             : // STATIC DATA ---------------------------------------------------------------
      74             : 
      75             : //  GlobalName der Writer-DocShell kommt jetzt aus comphelper/classids.hxx
      76             : 
      77             : //      C U T
      78             : 
      79           0 : void ScViewFunc::CutToClip( ScDocument* pClipDoc, bool bIncludeObjects )
      80             : {
      81           0 :     UpdateInputLine();
      82             : 
      83           0 :     ScEditableTester aTester( this );
      84           0 :     if (!aTester.IsEditable())                  // selection editable?
      85             :     {
      86           0 :         ErrorMessage( aTester.GetMessageId() );
      87           0 :         return;
      88             :     }
      89             : 
      90           0 :     ScRange aRange;                             // zu loeschender Bereich
      91           0 :     if ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
      92             :     {
      93           0 :         ScDocument* pDoc = GetViewData().GetDocument();
      94           0 :         ScDocShell* pDocSh = GetViewData().GetDocShell();
      95           0 :         ScMarkData& rMark = GetViewData().GetMarkData();
      96           0 :         const bool bRecord(pDoc->IsUndoEnabled());                  // Undo/Redo
      97             : 
      98           0 :         ScDocShellModificator aModificator( *pDocSh );
      99             : 
     100           0 :         if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )          // mark the range if not marked yet
     101             :         {
     102           0 :             DoneBlockMode();
     103           0 :             InitOwnBlockMode();
     104           0 :             rMark.SetMarkArea( aRange );
     105           0 :             MarkDataChanged();
     106             :         }
     107             : 
     108           0 :         CopyToClip( pClipDoc, true, false, bIncludeObjects );           // Ab ins Clipboard
     109             : 
     110           0 :         ScAddress aOldEnd( aRange.aEnd );       // Zusammengefasste Zellen im Bereich?
     111           0 :         pDoc->ExtendMerge( aRange, true );
     112             : 
     113           0 :         ScDocument* pUndoDoc = NULL;
     114           0 :         if ( bRecord )
     115             :         {
     116           0 :             pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
     117           0 :             pUndoDoc->InitUndoSelected( pDoc, rMark );
     118             :             // all sheets - CopyToDocument skips those that don't exist in pUndoDoc
     119           0 :             ScRange aCopyRange = aRange;
     120           0 :             aCopyRange.aStart.SetTab(0);
     121           0 :             aCopyRange.aEnd.SetTab(pDoc->GetTableCount()-1);
     122           0 :             pDoc->CopyToDocument( aCopyRange, (IDF_ALL & ~IDF_OBJECTS) | IDF_NOCAPTIONS, false, pUndoDoc );
     123           0 :             pDoc->BeginDrawUndo();
     124             :         }
     125             : 
     126           0 :         sal_uInt16 nExtFlags = 0;
     127           0 :         pDocSh->UpdatePaintExt( nExtFlags, aRange );
     128             : 
     129           0 :         rMark.MarkToMulti();
     130           0 :         pDoc->DeleteSelection( IDF_ALL, rMark );
     131           0 :         if ( bIncludeObjects )
     132           0 :             pDoc->DeleteObjectsInSelection( rMark );
     133           0 :         rMark.MarkToSimple();
     134             : 
     135           0 :         if ( !AdjustRowHeight( aRange.aStart.Row(), aRange.aEnd.Row() ) )
     136           0 :             pDocSh->PostPaint( aRange, PAINT_GRID, nExtFlags );
     137             : 
     138           0 :         if ( bRecord )                          // erst jetzt ist Draw-Undo verfuegbar
     139           0 :             pDocSh->GetUndoManager()->AddUndoAction(
     140           0 :                 new ScUndoCut( pDocSh, aRange, aOldEnd, rMark, pUndoDoc ) );
     141             : 
     142           0 :         aModificator.SetDocumentModified();
     143           0 :         pDocSh->UpdateOle(&GetViewData());
     144             : 
     145           0 :         CellContentChanged();
     146             :     }
     147             :     else
     148           0 :         ErrorMessage( STR_NOMULTISELECT );
     149             : }
     150             : 
     151             : //      C O P Y
     152             : 
     153          22 : bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, bool bCut, bool bApi, bool bIncludeObjects, bool bStopEdit )
     154             : {
     155          22 :     ScRange aRange;
     156          22 :     ScMarkType eMarkType = GetViewData().GetSimpleArea( aRange );
     157          22 :     ScMarkData& rMark = GetViewData().GetMarkData();
     158          22 :     bool bDone = false;
     159             : 
     160          22 :     if ( eMarkType == SC_MARK_SIMPLE || eMarkType == SC_MARK_SIMPLE_FILTERED )
     161             :     {
     162          22 :        ScRangeList aRangeList;
     163          22 :        aRangeList.Append( aRange );
     164          22 :        bDone = CopyToClip( pClipDoc, aRangeList, bCut, bApi, bIncludeObjects, bStopEdit, false );
     165             :     }
     166           0 :     else if (eMarkType == SC_MARK_MULTI)
     167             :     {
     168           0 :         ScRangeList aRangeList;
     169           0 :         rMark.MarkToSimple();
     170           0 :         rMark.FillRangeListWithMarks(&aRangeList, false);
     171           0 :         bDone = CopyToClip( pClipDoc, aRangeList, bCut, bApi, bIncludeObjects, bStopEdit, false );
     172             :     }
     173             :     else
     174             :     {
     175           0 :         if (!bApi)
     176           0 :             ErrorMessage(STR_NOMULTISELECT);
     177             :     }
     178             : 
     179          22 :     return bDone;
     180             : }
     181             : 
     182             : // Copy the content of the Range into clipboard.
     183          22 : bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, const ScRangeList& rRanges, bool bCut, bool bApi, bool bIncludeObjects, bool bStopEdit, bool bUseRangeForVBA )
     184             : {
     185          22 :     if ( rRanges.empty() )
     186           0 :         return false;
     187          22 :     bool bDone = false;
     188          22 :     if ( bStopEdit )
     189          22 :         UpdateInputLine();
     190             : 
     191          22 :     ScRange aRange = *rRanges[0];
     192          22 :     ScClipParam aClipParam( aRange, bCut );
     193          22 :     aClipParam.maRanges = rRanges;
     194             : 
     195          22 :     ScDocument* pDoc = GetViewData().GetDocument();
     196          22 :     ScMarkData& rMark = GetViewData().GetMarkData();
     197             : 
     198          22 :     if ( !aClipParam.isMultiRange() )
     199             :     {
     200          22 :         if ( pDoc && ( !pDoc->HasSelectedBlockMatrixFragment( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), rMark ) ) )
     201             :         {
     202          22 :             bool bSysClip = false;
     203          22 :             if ( !pClipDoc )                                    // no clip doc specified
     204             :             {
     205             :                 // Create one (deleted by ScTransferObj).
     206          22 :                 pClipDoc = new ScDocument( SCDOCMODE_CLIP );
     207          22 :                 bSysClip = true;                                // and copy into system
     208             :             }
     209          22 :             if ( !bCut )
     210             :             {
     211          22 :                 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
     212          22 :                 if ( pChangeTrack )
     213           0 :                     pChangeTrack->ResetLastCut();
     214             :             }
     215             : 
     216          22 :             if ( bSysClip && bIncludeObjects )
     217             :             {
     218          22 :                 bool bAnyOle = pDoc->HasOLEObjectsInArea( aRange );
     219             :                 // Update ScGlobal::pDrawClipDocShellRef.
     220          22 :                 ScDrawLayer::SetGlobalDrawPersist( ScTransferObj::SetDrawClipDoc( bAnyOle ) );
     221             :             }
     222             : 
     223          22 :             if ( !bUseRangeForVBA )
     224             :                 // is this necessary?, will setting the doc id upset the
     225             :                 // following paste operation with range? would be nicer to just set this always
     226             :                 // and lose the 'if' above
     227          22 :                 aClipParam.setSourceDocID( pDoc->GetDocumentID() );
     228             : 
     229          22 :             pDoc->CopyToClip( aClipParam, pClipDoc, &rMark, false, false, bIncludeObjects, true, bUseRangeForVBA );
     230          22 :             if ( !bUseRangeForVBA && pDoc && pClipDoc )
     231             :             {
     232          22 :                 ScDrawLayer* pDrawLayer = pClipDoc->GetDrawLayer();
     233          22 :                 if ( pDrawLayer )
     234             :                 {
     235           0 :                     ScClipParam& rClipParam = pClipDoc->GetClipParam();
     236           0 :                     ScRangeListVector& rRangesVector = rClipParam.maProtectedChartRangesVector;
     237           0 :                     SCTAB nTabCount = pClipDoc->GetTableCount();
     238           0 :                     for ( SCTAB nTab = 0; nTab < nTabCount; ++nTab )
     239             :                     {
     240           0 :                         SdrPage* pPage = pDrawLayer->GetPage( static_cast< sal_uInt16 >( nTab ) );
     241           0 :                         if ( pPage )
     242             :                         {
     243           0 :                             ScChartHelper::FillProtectedChartRangesVector( rRangesVector, pDoc, pPage );
     244             :                         }
     245             :                     }
     246             :                 }
     247             :             }
     248             : 
     249          22 :             if ( bSysClip )
     250             :             {
     251          22 :                 ScDrawLayer::SetGlobalDrawPersist(NULL);
     252          22 :                 ScGlobal::SetClipDocName( pDoc->GetDocumentShell()->GetTitle( SFX_TITLE_FULLNAME ) );
     253             :             }
     254          22 :             pClipDoc->ExtendMerge( aRange, true );
     255             : 
     256          22 :             if ( bSysClip )
     257             :             {
     258          22 :                 ScDocShell* pDocSh = GetViewData().GetDocShell();
     259          22 :                 TransferableObjectDescriptor aObjDesc;
     260          22 :                 pDocSh->FillTransferableObjectDescriptor( aObjDesc );
     261          22 :                 aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
     262             :                 // maSize is set in ScTransferObj ctor
     263             : 
     264          22 :                 ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
     265          44 :                 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
     266          22 :                 if ( ScGlobal::pDrawClipDocShellRef )
     267             :                 {
     268           0 :                     SfxObjectShellRef aPersistRef( &(*ScGlobal::pDrawClipDocShellRef) );
     269           0 :                     pTransferObj->SetDrawPersist( aPersistRef );// keep persist for ole objects alive
     270             : 
     271             :                 }
     272          22 :                 pTransferObj->CopyToClipboard( GetActiveWin() );
     273          44 :                 SC_MOD()->SetClipObject( pTransferObj, NULL );
     274             :             }
     275             : 
     276          22 :             bDone = true;
     277             :         }
     278             :     }
     279             :     else
     280             :     {
     281           0 :         bool bSuccess = false;
     282           0 :         aClipParam.mbCutMode = false;
     283             : 
     284             :         do
     285             :         {
     286           0 :             if (bCut)
     287             :                 // We con't support cutting of multi-selections.
     288           0 :                 break;
     289             : 
     290           0 :             if (pClipDoc)
     291             :                 // TODO: What's this for?
     292           0 :                 break;
     293             : 
     294           0 :             ::std::unique_ptr<ScDocument> pDocClip(new ScDocument(SCDOCMODE_CLIP));
     295             : 
     296             :             // Check for geometrical feasibility of the ranges.
     297           0 :             bool bValidRanges = true;
     298           0 :             ScRange* p = aClipParam.maRanges.front();
     299           0 :             SCCOL nPrevColDelta = 0;
     300           0 :             SCROW nPrevRowDelta = 0;
     301           0 :             SCCOL nPrevCol = p->aStart.Col();
     302           0 :             SCROW nPrevRow = p->aStart.Row();
     303           0 :             SCCOL nPrevColSize = p->aEnd.Col() - p->aStart.Col() + 1;
     304           0 :             SCROW nPrevRowSize = p->aEnd.Row() - p->aStart.Row() + 1;
     305           0 :             for ( size_t i = 1; i < aClipParam.maRanges.size(); ++i )
     306             :             {
     307           0 :                 p = aClipParam.maRanges[i];
     308           0 :                 if ( pDoc->HasSelectedBlockMatrixFragment(
     309           0 :                     p->aStart.Col(), p->aStart.Row(), p->aEnd.Col(), p->aEnd.Row(), rMark) )
     310             :                 {
     311           0 :                     if (!bApi)
     312           0 :                         ErrorMessage(STR_MATRIXFRAGMENTERR);
     313           0 :                     return false;
     314             :                 }
     315             : 
     316           0 :                 SCCOL nColDelta = p->aStart.Col() - nPrevCol;
     317           0 :                 SCROW nRowDelta = p->aStart.Row() - nPrevRow;
     318             : 
     319           0 :                 if ((nColDelta && nRowDelta) || (nPrevColDelta && nRowDelta) || (nPrevRowDelta && nColDelta))
     320             :                 {
     321           0 :                     bValidRanges = false;
     322           0 :                     break;
     323             :                 }
     324             : 
     325           0 :                 if (aClipParam.meDirection == ScClipParam::Unspecified)
     326             :                 {
     327           0 :                     if (nColDelta)
     328           0 :                         aClipParam.meDirection = ScClipParam::Column;
     329           0 :                     if (nRowDelta)
     330           0 :                         aClipParam.meDirection = ScClipParam::Row;
     331             :                 }
     332             : 
     333           0 :                 SCCOL nColSize = p->aEnd.Col() - p->aStart.Col() + 1;
     334           0 :                 SCROW nRowSize = p->aEnd.Row() - p->aStart.Row() + 1;
     335             : 
     336           0 :                 if (aClipParam.meDirection == ScClipParam::Column && nRowSize != nPrevRowSize)
     337             :                 {
     338             :                     // column-oriented ranges must have identical row size.
     339           0 :                     bValidRanges = false;
     340           0 :                     break;
     341             :                 }
     342           0 :                 if (aClipParam.meDirection == ScClipParam::Row && nColSize != nPrevColSize)
     343             :                 {
     344             :                     // likewise, row-oriented ranges must have identical
     345             :                     // column size.
     346           0 :                     bValidRanges = false;
     347           0 :                     break;
     348             :                 }
     349             : 
     350           0 :                 nPrevCol = p->aStart.Col();
     351           0 :                 nPrevRow = p->aStart.Row();
     352           0 :                 nPrevColDelta = nColDelta;
     353           0 :                 nPrevRowDelta = nRowDelta;
     354           0 :                 nPrevColSize  = nColSize;
     355           0 :                 nPrevRowSize  = nRowSize;
     356             :             }
     357           0 :             if (!bValidRanges)
     358           0 :                 break;
     359           0 :             pDoc->CopyToClip(aClipParam, pDocClip.get(), &rMark, false, false, bIncludeObjects, true, bUseRangeForVBA );
     360             : 
     361           0 :             ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
     362           0 :             if ( pChangeTrack )
     363           0 :                 pChangeTrack->ResetLastCut();   // kein CutMode mehr
     364             : 
     365             :             {
     366           0 :                 ScDocShell* pDocSh = GetViewData().GetDocShell();
     367           0 :                 TransferableObjectDescriptor aObjDesc;
     368           0 :                 pDocSh->FillTransferableObjectDescriptor( aObjDesc );
     369           0 :                 aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
     370             :                 // maSize is set in ScTransferObj ctor
     371             : 
     372           0 :                 ScTransferObj* pTransferObj = new ScTransferObj( pDocClip.release(), aObjDesc );
     373           0 :                 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
     374             : 
     375           0 :                 if ( ScGlobal::pDrawClipDocShellRef )
     376             :                 {
     377           0 :                     SfxObjectShellRef aPersistRef( &(*ScGlobal::pDrawClipDocShellRef) );
     378           0 :                     pTransferObj->SetDrawPersist( aPersistRef );    // keep persist for ole objects alive
     379             :                 }
     380             : 
     381           0 :                 pTransferObj->CopyToClipboard( GetActiveWin() );    // system clipboard
     382           0 :                 SC_MOD()->SetClipObject( pTransferObj, NULL );      // internal clipboard
     383             :             }
     384             : 
     385           0 :             bSuccess = true;
     386             :         }
     387             :         while (false);
     388             : 
     389           0 :         if (!bSuccess && !bApi)
     390           0 :             ErrorMessage(STR_NOMULTISELECT);
     391             : 
     392           0 :         bDone = bSuccess;
     393             :     }
     394             : 
     395          22 :     return bDone;
     396             : }
     397             : 
     398           0 : ScTransferObj* ScViewFunc::CopyToTransferable()
     399             : {
     400           0 :     ScRange aRange;
     401           0 :     if ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
     402             :     {
     403           0 :         ScDocument* pDoc = GetViewData().GetDocument();
     404           0 :         ScMarkData& rMark = GetViewData().GetMarkData();
     405           0 :         if ( !pDoc->HasSelectedBlockMatrixFragment(
     406           0 :                         aRange.aStart.Col(), aRange.aStart.Row(),
     407           0 :                         aRange.aEnd.Col(),   aRange.aEnd.Row(),
     408           0 :                         rMark ) )
     409             :         {
     410           0 :             ScDocument *pClipDoc = new ScDocument( SCDOCMODE_CLIP );    // create one (deleted by ScTransferObj)
     411             : 
     412           0 :             bool bAnyOle = pDoc->HasOLEObjectsInArea( aRange, &rMark );
     413           0 :             ScDrawLayer::SetGlobalDrawPersist( ScTransferObj::SetDrawClipDoc( bAnyOle ) );
     414             : 
     415           0 :             ScClipParam aClipParam(aRange, false);
     416           0 :             pDoc->CopyToClip(aClipParam, pClipDoc, &rMark, false, false, true);
     417             : 
     418           0 :             ScDrawLayer::SetGlobalDrawPersist(NULL);
     419           0 :             pClipDoc->ExtendMerge( aRange, true );
     420             : 
     421           0 :             ScDocShell* pDocSh = GetViewData().GetDocShell();
     422           0 :             TransferableObjectDescriptor aObjDesc;
     423           0 :             pDocSh->FillTransferableObjectDescriptor( aObjDesc );
     424           0 :             aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
     425           0 :             ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
     426           0 :             return pTransferObj;
     427             :         }
     428             :     }
     429             : 
     430           0 :     return NULL;
     431             : }
     432             : 
     433             : //      P A S T E
     434             : 
     435           0 : void ScViewFunc::PasteDraw()
     436             : {
     437           0 :     ScViewData& rViewData = GetViewData();
     438           0 :     SCCOL nPosX = rViewData.GetCurX();
     439           0 :     SCROW nPosY = rViewData.GetCurY();
     440           0 :     vcl::Window* pWin = GetActiveWin();
     441             :     Point aPos = pWin->PixelToLogic( rViewData.GetScrPos( nPosX, nPosY,
     442           0 :                                      rViewData.GetActivePart() ) );
     443           0 :     ScDrawTransferObj* pDrawClip = ScDrawTransferObj::GetOwnClipboard( pWin );
     444           0 :     if (pDrawClip)
     445             :     {
     446           0 :         OUString aSrcShellID = pDrawClip->GetShellID();
     447           0 :         OUString aDestShellID = SfxObjectShell::CreateShellID(rViewData.GetDocShell());
     448           0 :         PasteDraw(aPos, pDrawClip->GetModel(), false, aSrcShellID, aDestShellID);
     449             :     }
     450           0 : }
     451             : 
     452           6 : void ScViewFunc::PasteFromSystem()
     453             : {
     454           6 :     UpdateInputLine();
     455             : 
     456           6 :     vcl::Window* pWin = GetActiveWin();
     457           6 :     ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
     458           6 :     ScDrawTransferObj* pDrawClip = ScDrawTransferObj::GetOwnClipboard( pWin );
     459             : 
     460           6 :     if (pOwnClip)
     461             :     {
     462             :         // keep a reference in case the clipboard is changed during PasteFromClip
     463           0 :         uno::Reference<datatransfer::XTransferable> aOwnClipRef( pOwnClip );
     464             :         PasteFromClip( IDF_ALL, pOwnClip->GetDocument(),
     465             :                         PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
     466           0 :                         true );     // allow warning dialog
     467             :     }
     468           6 :     else if (pDrawClip)
     469           0 :         PasteDraw();
     470             :     else
     471             :     {
     472           6 :         TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
     473             : 
     474             :         {
     475           6 :             sal_uLong nBiff8 = SotExchange::RegisterFormatName(OUString("Biff8"));
     476           6 :             sal_uLong nBiff5 = SotExchange::RegisterFormatName(OUString("Biff5"));
     477             : 
     478             :                 //  als erstes SvDraw-Model, dann Grafik
     479             :                 //  (Grafik darf nur bei einzelner Grafik drinstehen)
     480             : 
     481           6 :             if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ))
     482             :             {
     483             :                 // special case for tables from drawing
     484           0 :                 if( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
     485             :                 {
     486           0 :                     PasteFromSystem( FORMAT_RTF );
     487             :                 }
     488             :                 else
     489             :                 {
     490           0 :                     PasteFromSystem( SOT_FORMATSTR_ID_DRAWING );
     491             :                 }
     492             :             }
     493           6 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ))
     494           0 :                 PasteFromSystem( SOT_FORMATSTR_ID_SVXB );
     495           6 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ))
     496             :             {
     497             :                 //  If it's a Writer object, insert RTF instead of OLE
     498             : 
     499             :                 //  Else, if the class id is all-zero, and SYLK is available,
     500             :                 //  it probably is spreadsheet cells that have been put
     501             :                 //  on the clipboard by OOo, so use the SYLK. (fdo#31077)
     502             : 
     503           0 :                 bool bDoRtf = false;
     504           0 :                 TransferableObjectDescriptor aObjDesc;
     505           0 :                 if( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) )
     506             :                 {
     507           0 :                     bDoRtf = ( ( aObjDesc.maClassName == SvGlobalName( SO3_SW_CLASSID ) ||
     508           0 :                                  aObjDesc.maClassName == SvGlobalName( SO3_SWWEB_CLASSID ) )
     509           0 :                                && aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
     510             :                 }
     511           0 :                 if ( bDoRtf )
     512           0 :                     PasteFromSystem( FORMAT_RTF );
     513           0 :                 else if ( aObjDesc.maClassName == SvGlobalName( 0,0,0,0,0,0,0,0,0,0,0 )
     514           0 :                           && aDataHelper.HasFormat( SOT_FORMATSTR_ID_SYLK ))
     515           0 :                     PasteFromSystem( SOT_FORMATSTR_ID_SYLK );
     516             :                 else
     517           0 :                     PasteFromSystem( SOT_FORMATSTR_ID_EMBED_SOURCE );
     518             :             }
     519           6 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE ))
     520           0 :                 PasteFromSystem( SOT_FORMATSTR_ID_LINK_SOURCE );
     521             :             // the following format can not affect scenario from #89579#
     522           6 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ))
     523           0 :                 PasteFromSystem( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE );
     524             :             // FORMAT_PRIVATE no longer here (can't work if pOwnClip is NULL)
     525           6 :             else if (aDataHelper.HasFormat(nBiff8))      // before xxx_OLE formats
     526           0 :                 PasteFromSystem(nBiff8);
     527           6 :             else if (aDataHelper.HasFormat(nBiff5))
     528           0 :                 PasteFromSystem(nBiff5);
     529           6 :             else if (aDataHelper.HasFormat(FORMAT_RTF))
     530           0 :                 PasteFromSystem(FORMAT_RTF);
     531           6 :             else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_HTML))
     532           0 :                 PasteFromSystem(SOT_FORMATSTR_ID_HTML);
     533           6 :             else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_HTML_SIMPLE))
     534           0 :                 PasteFromSystem(SOT_FORMATSTR_ID_HTML_SIMPLE);
     535           6 :             else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_SYLK))
     536           0 :                 PasteFromSystem(SOT_FORMATSTR_ID_SYLK);
     537           6 :             else if (aDataHelper.HasFormat(FORMAT_STRING))
     538           0 :                 PasteFromSystem(FORMAT_STRING);
     539           6 :             else if (aDataHelper.HasFormat(FORMAT_GDIMETAFILE))
     540           0 :                 PasteFromSystem(FORMAT_GDIMETAFILE);
     541           6 :             else if (aDataHelper.HasFormat(FORMAT_BITMAP))
     542           0 :                 PasteFromSystem(FORMAT_BITMAP);
     543             :             // xxx_OLE formats come last, like in SotExchange tables
     544           6 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ))
     545           0 :                 PasteFromSystem( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE );
     546           6 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ))
     547           0 :                 PasteFromSystem( SOT_FORMATSTR_ID_LINK_SOURCE_OLE );
     548           6 :         }
     549             :     }
     550             :     //  keine Fehlermeldung, weil SID_PASTE in der idl das FastCall-Flag hat,
     551             :     //  also auch gerufen wird, wenn nichts im Clipboard steht (#42531#)
     552           6 : }
     553             : 
     554           0 : void ScViewFunc::PasteFromTransferable( const uno::Reference<datatransfer::XTransferable>& rxTransferable )
     555             : {
     556           0 :     ScTransferObj *pOwnClip=0;
     557           0 :     ScDrawTransferObj *pDrawClip=0;
     558           0 :     uno::Reference<lang::XUnoTunnel> xTunnel( rxTransferable, uno::UNO_QUERY );
     559           0 :     if ( xTunnel.is() )
     560             :     {
     561           0 :         sal_Int64 nHandle = xTunnel->getSomething( ScTransferObj::getUnoTunnelId() );
     562           0 :         if ( nHandle )
     563           0 :             pOwnClip = reinterpret_cast<ScTransferObj*>( (sal_IntPtr) nHandle);
     564             :         else
     565             :         {
     566           0 :             nHandle = xTunnel->getSomething( ScDrawTransferObj::getUnoTunnelId() );
     567           0 :             if ( nHandle )
     568           0 :                 pDrawClip = reinterpret_cast<ScDrawTransferObj*>( (sal_IntPtr) nHandle );
     569             :         }
     570             :     }
     571             : 
     572           0 :     if (pOwnClip)
     573             :     {
     574             :         PasteFromClip( IDF_ALL, pOwnClip->GetDocument(),
     575             :                         PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
     576           0 :                         true );     // allow warning dialog
     577             :     }
     578           0 :     else if (pDrawClip)
     579             :     {
     580           0 :         ScViewData& rViewData = GetViewData();
     581           0 :         SCCOL nPosX = rViewData.GetCurX();
     582           0 :         SCROW nPosY = rViewData.GetCurY();
     583           0 :         vcl::Window* pWin = GetActiveWin();
     584           0 :         Point aPos = pWin->PixelToLogic( rViewData.GetScrPos( nPosX, nPosY, rViewData.GetActivePart() ) );
     585             :         PasteDraw(
     586             :             aPos, pDrawClip->GetModel(), false,
     587           0 :             pDrawClip->GetShellID(), SfxObjectShell::CreateShellID(rViewData.GetDocShell()));
     588             :     }
     589             :     else
     590             :     {
     591           0 :             TransferableDataHelper aDataHelper( rxTransferable );
     592             :         {
     593           0 :             sal_uLong nBiff8 = SotExchange::RegisterFormatName(OUString("Biff8"));
     594           0 :             sal_uLong nBiff5 = SotExchange::RegisterFormatName(OUString("Biff5"));
     595           0 :             sal_uLong nFormatId = 0;
     596             :                 //  als erstes SvDraw-Model, dann Grafik
     597             :                 //  (Grafik darf nur bei einzelner Grafik drinstehen)
     598             : 
     599           0 :             if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ))
     600           0 :                 nFormatId = SOT_FORMATSTR_ID_DRAWING;
     601           0 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ))
     602           0 :                 nFormatId = SOT_FORMATSTR_ID_SVXB;
     603           0 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ))
     604             :             {
     605             :                 //  If it's a Writer object, insert RTF instead of OLE
     606           0 :                 bool bDoRtf = false;
     607           0 :                 TransferableObjectDescriptor aObjDesc;
     608           0 :                 if( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) )
     609             :                 {
     610           0 :                     bDoRtf = ( ( aObjDesc.maClassName == SvGlobalName( SO3_SW_CLASSID ) ||
     611           0 :                                  aObjDesc.maClassName == SvGlobalName( SO3_SWWEB_CLASSID ) )
     612           0 :                                && aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
     613             :                 }
     614           0 :                 if ( bDoRtf )
     615           0 :                     nFormatId = FORMAT_RTF;
     616             :                 else
     617           0 :                     nFormatId = SOT_FORMATSTR_ID_EMBED_SOURCE;
     618             :             }
     619           0 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE ))
     620           0 :                 nFormatId = SOT_FORMATSTR_ID_LINK_SOURCE;
     621             :             // the following format can not affect scenario from #89579#
     622           0 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ))
     623           0 :                 nFormatId = SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE;
     624             :             // FORMAT_PRIVATE no longer here (can't work if pOwnClip is NULL)
     625           0 :             else if (aDataHelper.HasFormat(nBiff8))      // before xxx_OLE formats
     626           0 :                 nFormatId = nBiff8;
     627           0 :             else if (aDataHelper.HasFormat(nBiff5))
     628           0 :                 nFormatId = nBiff5;
     629           0 :             else if (aDataHelper.HasFormat(FORMAT_RTF))
     630           0 :                 nFormatId = FORMAT_RTF;
     631           0 :             else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_HTML))
     632           0 :                 nFormatId = SOT_FORMATSTR_ID_HTML;
     633           0 :             else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_HTML_SIMPLE))
     634           0 :                 nFormatId = SOT_FORMATSTR_ID_HTML_SIMPLE;
     635           0 :             else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_SYLK))
     636           0 :                 nFormatId = SOT_FORMATSTR_ID_SYLK;
     637           0 :             else if (aDataHelper.HasFormat(FORMAT_STRING))
     638           0 :                 nFormatId = FORMAT_STRING;
     639           0 :             else if (aDataHelper.HasFormat(FORMAT_GDIMETAFILE))
     640           0 :                 nFormatId = FORMAT_GDIMETAFILE;
     641           0 :             else if (aDataHelper.HasFormat(FORMAT_BITMAP))
     642           0 :                 nFormatId = FORMAT_BITMAP;
     643             :             // xxx_OLE formats come last, like in SotExchange tables
     644           0 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ))
     645           0 :                 nFormatId = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE;
     646           0 :             else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ))
     647           0 :                 nFormatId = SOT_FORMATSTR_ID_LINK_SOURCE_OLE;
     648             :             else
     649           0 :                 return;
     650             : 
     651           0 :             PasteDataFormat( nFormatId, aDataHelper.GetTransferable(),
     652           0 :                 GetViewData().GetCurX(), GetViewData().GetCurY(),
     653           0 :                 NULL, false, false );
     654           0 :         }
     655           0 :     }
     656             : }
     657             : 
     658           0 : bool ScViewFunc::PasteFromSystem( sal_uLong nFormatId, bool bApi )
     659             : {
     660           0 :     UpdateInputLine();
     661             : 
     662           0 :     bool bRet = true;
     663           0 :     vcl::Window* pWin = GetActiveWin();
     664           0 :     ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
     665           0 :     if ( nFormatId == 0 && pOwnClip )
     666             :     {
     667             :         // keep a reference in case the clipboard is changed during PasteFromClip
     668           0 :         uno::Reference<datatransfer::XTransferable> aOwnClipRef( pOwnClip );
     669             :         PasteFromClip( IDF_ALL, pOwnClip->GetDocument(),
     670             :                         PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
     671           0 :                         !bApi );        // allow warning dialog
     672             :     }
     673             :     else
     674             :     {
     675           0 :         TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
     676           0 :         if ( !aDataHelper.GetTransferable().is() )
     677           0 :             return false;
     678             : 
     679           0 :         bRet = PasteDataFormat( nFormatId, aDataHelper.GetTransferable(),
     680           0 :                                 GetViewData().GetCurX(), GetViewData().GetCurY(),
     681           0 :                                 NULL, false, !bApi );       // allow warning dialog
     682             : 
     683           0 :         if ( !bRet && !bApi )
     684           0 :             ErrorMessage(STR_PASTE_ERROR);
     685             :     }
     686           0 :     return bRet;
     687             : }
     688             : 
     689             : //      P A S T E
     690             : 
     691           0 : bool ScViewFunc::PasteOnDrawObjectLinked(
     692             :     const uno::Reference<datatransfer::XTransferable>& rxTransferable,
     693             :     SdrObject& rHitObj)
     694             : {
     695           0 :     TransferableDataHelper aDataHelper( rxTransferable );
     696             : 
     697           0 :     if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) )
     698             :     {
     699           0 :         SotStorageStreamRef xStm;
     700           0 :         ScDrawView* pScDrawView = GetScDrawView();
     701             : 
     702           0 :         if( pScDrawView && aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB, xStm ) )
     703             :         {
     704           0 :             Graphic aGraphic;
     705             : 
     706           0 :             ReadGraphic( *xStm, aGraphic );
     707             : 
     708           0 :             const OUString aEmpty;
     709           0 :             const OUString aBeginUndo(ScGlobal::GetRscString(STR_UNDO_DRAGDROP));
     710             : 
     711           0 :             if(pScDrawView->ApplyGraphicToObject( rHitObj, aGraphic, aBeginUndo, aEmpty, aEmpty ))
     712             :             {
     713           0 :                 return true;
     714           0 :             }
     715           0 :         }
     716             :     }
     717           0 :     else if ( aDataHelper.HasFormat( SOT_FORMAT_GDIMETAFILE ) )
     718             :     {
     719           0 :         GDIMetaFile aMtf;
     720           0 :         ScDrawView* pScDrawView = GetScDrawView();
     721             : 
     722           0 :         if( pScDrawView && aDataHelper.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMtf ) )
     723             :         {
     724           0 :             const OUString aEmpty;
     725           0 :             const OUString aBeginUndo(ScGlobal::GetRscString(STR_UNDO_DRAGDROP));
     726             : 
     727           0 :             if(pScDrawView->ApplyGraphicToObject( rHitObj, Graphic(aMtf), aBeginUndo, aEmpty, aEmpty ))
     728             :             {
     729           0 :                 return true;
     730           0 :             }
     731           0 :         }
     732             :     }
     733           0 :     else if ( aDataHelper.HasFormat( SOT_FORMAT_BITMAP ) || aDataHelper.HasFormat( SOT_FORMATSTR_ID_PNG ) )
     734             :     {
     735           0 :         BitmapEx aBmpEx;
     736           0 :         ScDrawView* pScDrawView = GetScDrawView();
     737             : 
     738           0 :         if( pScDrawView && aDataHelper.GetBitmapEx( FORMAT_BITMAP, aBmpEx ) )
     739             :         {
     740           0 :             const OUString aEmpty;
     741           0 :             const OUString aBeginUndo(ScGlobal::GetRscString(STR_UNDO_DRAGDROP));
     742             : 
     743           0 :             if(pScDrawView->ApplyGraphicToObject( rHitObj, Graphic(aBmpEx), aBeginUndo, aEmpty, aEmpty ))
     744             :             {
     745           0 :                 return true;
     746           0 :             }
     747           0 :         }
     748             :     }
     749             : 
     750           0 :     return false;
     751             : }
     752             : 
     753           0 : static bool lcl_SelHasAttrib( ScDocument* pDoc, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
     754             :                         const ScMarkData& rTabSelection, sal_uInt16 nMask )
     755             : {
     756           0 :     ScMarkData::const_iterator itr = rTabSelection.begin(), itrEnd = rTabSelection.end();
     757           0 :     for (; itr != itrEnd; ++itr)
     758           0 :         if ( pDoc->HasAttrib( nCol1, nRow1, *itr, nCol2, nRow2, *itr, nMask ) )
     759           0 :             return true;
     760           0 :     return false;
     761             : }
     762             : 
     763             : //      Einfuegen auf Tabelle:
     764             : 
     765             : //  internes Paste
     766             : 
     767             : namespace {
     768             : 
     769           0 : bool checkDestRangeForOverwrite(const ScRangeList& rDestRanges, const ScDocument* pDoc, const ScMarkData& rMark, vcl::Window* pParentWnd)
     770             : {
     771           0 :     bool bIsEmpty = true;
     772           0 :     ScMarkData::const_iterator itrTab = rMark.begin(), itrTabEnd = rMark.end();
     773           0 :     size_t nRangeSize = rDestRanges.size();
     774           0 :     for (; itrTab != itrTabEnd && bIsEmpty; ++itrTab)
     775             :     {
     776           0 :         for (size_t i = 0; i < nRangeSize && bIsEmpty; ++i)
     777             :         {
     778           0 :             const ScRange& rRange = *rDestRanges[i];
     779             :             bIsEmpty = pDoc->IsBlockEmpty(
     780           0 :                 *itrTab, rRange.aStart.Col(), rRange.aStart.Row(),
     781           0 :                 rRange.aEnd.Col(), rRange.aEnd.Row());
     782             :         }
     783             :     }
     784             : 
     785           0 :     if (!bIsEmpty)
     786             :     {
     787           0 :         ScReplaceWarnBox aBox(pParentWnd);
     788           0 :         if (aBox.Execute() != RET_YES)
     789             :         {
     790             :             //  changing the configuration is within the ScReplaceWarnBox
     791           0 :             return false;
     792           0 :         }
     793             :     }
     794           0 :     return true;
     795             : }
     796             : 
     797             : }
     798             : 
     799          56 : bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
     800             :                                 sal_uInt16 nFunction, bool bSkipEmpty,
     801             :                                 bool bTranspose, bool bAsLink,
     802             :                                 InsCellCmd eMoveMode, InsertDeleteFlags nUndoExtraFlags,
     803             :                                 bool bAllowDialogs )
     804             : {
     805          56 :     if (!pClipDoc)
     806             :     {
     807             :         OSL_FAIL("PasteFromClip: pClipDoc=0 not allowed");
     808          24 :         return false;
     809             :     }
     810             : 
     811             :     //  fuer Undo etc. immer alle oder keine Inhalte sichern
     812          32 :     InsertDeleteFlags nContFlags = IDF_NONE;
     813          32 :     if (nFlags & IDF_CONTENTS)
     814          32 :         nContFlags |= IDF_CONTENTS;
     815          32 :     if (nFlags & IDF_ATTRIB)
     816          32 :         nContFlags |= IDF_ATTRIB;
     817             :     // evtl. Attribute ins Undo ohne sie vom Clip ins Doc zu kopieren
     818          32 :     InsertDeleteFlags nUndoFlags = nContFlags;
     819          32 :     if (nUndoExtraFlags & IDF_ATTRIB)
     820           0 :         nUndoFlags |= IDF_ATTRIB;
     821             :     // do not copy note captions into undo document
     822          32 :     nUndoFlags |= IDF_NOCAPTIONS;
     823             : 
     824          32 :     ScClipParam& rClipParam = pClipDoc->GetClipParam();
     825          32 :     if (rClipParam.isMultiRange())
     826             :     {
     827             :         // Source data is multi-range.
     828             :         return PasteMultiRangesFromClip(
     829             :             nFlags, pClipDoc, nFunction, bSkipEmpty, bTranspose, bAsLink, bAllowDialogs,
     830           0 :             eMoveMode, nUndoFlags);
     831             :     }
     832             : 
     833          32 :     ScMarkData& rMark = GetViewData().GetMarkData();
     834          32 :     if (rMark.IsMultiMarked())
     835             :     {
     836             :         // Source data is single-range but destination is multi-range.
     837             :         return PasteFromClipToMultiRanges(
     838             :             nFlags, pClipDoc, nFunction, bSkipEmpty, bTranspose, bAsLink, bAllowDialogs,
     839           0 :             eMoveMode, nUndoFlags);
     840             :     }
     841             : 
     842          32 :     bool bCutMode = pClipDoc->IsCutMode();      // if transposing, take from original clipdoc
     843          32 :     bool bIncludeFiltered = bCutMode;
     844             : 
     845             :     // paste drawing: also if IDF_NOTE is set (to create drawing layer for note captions)
     846          32 :     bool bPasteDraw = ( pClipDoc->GetDrawLayer() && ( nFlags & (IDF_OBJECTS|IDF_NOTE) ) );
     847             : 
     848          32 :     ScDocShellRef aTransShellRef;   // for objects in xTransClip - must remain valid as long as xTransClip
     849          32 :     ScDocument* pOrigClipDoc = NULL;
     850          64 :     ::std::unique_ptr< ScDocument > xTransClip;
     851          32 :     if ( bTranspose )
     852             :     {
     853             :         SCCOL nX;
     854             :         SCROW nY;
     855             :         // include filtered rows until TransposeClip can skip them
     856           0 :         bIncludeFiltered = true;
     857           0 :         pClipDoc->GetClipArea( nX, nY, true );
     858           0 :         if ( nY > static_cast<sal_Int32>(MAXCOL) )                      // zuviele Zeilen zum Transponieren
     859             :         {
     860           0 :             ErrorMessage(STR_PASTE_FULL);
     861           0 :             return false;
     862             :         }
     863           0 :         pOrigClipDoc = pClipDoc;        // fuer Referenzen
     864             : 
     865           0 :         if ( bPasteDraw )
     866             :         {
     867           0 :             aTransShellRef = new ScDocShell;        // DocShell needs a Ref immediately
     868           0 :             aTransShellRef->DoInitNew(NULL);
     869             :         }
     870           0 :         ScDrawLayer::SetGlobalDrawPersist(aTransShellRef);
     871             : 
     872           0 :         xTransClip.reset( new ScDocument( SCDOCMODE_CLIP ));
     873           0 :         pClipDoc->TransposeClip( xTransClip.get(), nFlags, bAsLink );
     874           0 :         pClipDoc = xTransClip.get();
     875             : 
     876           0 :         ScDrawLayer::SetGlobalDrawPersist(NULL);
     877             :     }
     878             : 
     879             :     SCCOL nStartCol;
     880             :     SCROW nStartRow;
     881             :     SCTAB nStartTab;
     882             :     SCCOL nEndCol;
     883             :     SCROW nEndRow;
     884             :     SCTAB nEndTab;
     885             :     SCCOL nClipSizeX;
     886             :     SCROW nClipSizeY;
     887          32 :     pClipDoc->GetClipArea( nClipSizeX, nClipSizeY, true );      // size in clipboard doc
     888             : 
     889             :     //  size in target doc: include filtered rows only if CutMode is set
     890             :     SCCOL nDestSizeX;
     891             :     SCROW nDestSizeY;
     892          32 :     pClipDoc->GetClipArea( nDestSizeX, nDestSizeY, bIncludeFiltered );
     893             : 
     894          32 :     ScDocument* pDoc = GetViewData().GetDocument();
     895          32 :     ScDocShell* pDocSh = GetViewData().GetDocShell();
     896          32 :     ::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
     897          32 :     const bool bRecord(pDoc->IsUndoEnabled());
     898             : 
     899          64 :     ScDocShellModificator aModificator( *pDocSh );
     900             : 
     901          32 :     ScRange aMarkRange;
     902          64 :     ScMarkData aFilteredMark( rMark);   // local copy for all modifications
     903          32 :     ScMarkType eMarkType = GetViewData().GetSimpleArea( aMarkRange, aFilteredMark);
     904          32 :     bool bMarkIsFiltered = (eMarkType == SC_MARK_SIMPLE_FILTERED);
     905          32 :     bool bNoPaste = ((eMarkType != SC_MARK_SIMPLE && !bMarkIsFiltered) ||
     906          32 :             (bMarkIsFiltered && (eMoveMode != INS_NONE || bAsLink)));
     907             : 
     908          32 :     if (!bNoPaste)
     909             :     {
     910          32 :         if (!rMark.IsMarked())
     911             :         {
     912             :             // Create a selection with clipboard row count and check that for
     913             :             // filtered.
     914          32 :             nStartCol = GetViewData().GetCurX();
     915          32 :             nStartRow = GetViewData().GetCurY();
     916          32 :             nStartTab = GetViewData().GetTabNo();
     917          32 :             nEndCol = nStartCol + nDestSizeX;
     918          32 :             nEndRow = nStartRow + nDestSizeY;
     919          32 :             nEndTab = nStartTab;
     920          32 :             aMarkRange = ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
     921          32 :             if (ScViewUtil::HasFiltered( aMarkRange, pDoc))
     922             :             {
     923           0 :                 bMarkIsFiltered = true;
     924             :                 // Fit to clipboard's row count unfiltered rows. If there is no
     925             :                 // fit assume that pasting is not possible. Note that nDestSizeY is
     926             :                 // size-1 (difference).
     927           0 :                 if (!ScViewUtil::FitToUnfilteredRows( aMarkRange, pDoc, nDestSizeY+1))
     928           0 :                     bNoPaste = true;
     929             :             }
     930          32 :             aFilteredMark.SetMarkArea( aMarkRange);
     931             :         }
     932             :         else
     933             :         {
     934             :             // Expand the marked area when the destination area is larger than the
     935             :             // current selection, to get the undo do the right thing. (i#106711)
     936           0 :             ScRange aRange;
     937           0 :             aFilteredMark.GetMarkArea( aRange );
     938           0 :             if( (aRange.aEnd.Col() - aRange.aStart.Col()) < nDestSizeX )
     939             :             {
     940           0 :                 aRange.aEnd.SetCol(aRange.aStart.Col() + nDestSizeX);
     941           0 :                 aFilteredMark.SetMarkArea(aRange);
     942             :             }
     943             :         }
     944             :     }
     945             : 
     946          32 :     if (bNoPaste)
     947             :     {
     948           0 :         ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
     949           0 :         return false;
     950             :     }
     951             : 
     952          32 :     SCROW nUnfilteredRows = aMarkRange.aEnd.Row() - aMarkRange.aStart.Row() + 1;
     953          64 :     ScRangeList aRangeList;
     954          32 :     if (bMarkIsFiltered)
     955             :     {
     956           0 :         ScViewUtil::UnmarkFiltered( aFilteredMark, pDoc);
     957           0 :         aFilteredMark.FillRangeListWithMarks( &aRangeList, false);
     958           0 :         nUnfilteredRows = 0;
     959           0 :         size_t ListSize = aRangeList.size();
     960           0 :         for ( size_t i = 0; i < ListSize; ++i )
     961             :         {
     962           0 :             ScRange* p = aRangeList[i];
     963           0 :             nUnfilteredRows += p->aEnd.Row() - p->aStart.Row() + 1;
     964             :         }
     965             : #if 0
     966             :         /* This isn't needed but could be a desired restriction. */
     967             :         // For filtered, destination rows have to be an exact multiple of
     968             :         // source rows. Note that nDestSizeY is size-1 (difference), so
     969             :         // nDestSizeY==0 fits always.
     970             :         if ((nUnfilteredRows % (nDestSizeY+1)) != 0)
     971             :         {
     972             :             /* FIXME: this should be a more descriptive error message then. */
     973             :             ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
     974             :             return false;
     975             :         }
     976             : #endif
     977             :     }
     978             : 
     979             :     // Also for a filtered selection the area is used, for undo et al.
     980          32 :     if ( aFilteredMark.IsMarked() || bMarkIsFiltered )
     981             :     {
     982          32 :         aMarkRange.GetVars( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
     983          32 :         SCCOL nBlockAddX = nEndCol-nStartCol;
     984          32 :         SCROW nBlockAddY = nEndRow-nStartRow;
     985             : 
     986             :         //  Nachfrage, wenn die Selektion groesser als 1 Zeile/Spalte, aber kleiner
     987             :         //  als das Clipboard ist (dann wird ueber die Selektion hinaus eingefuegt)
     988             : 
     989             :         //  ClipSize is not size, but difference
     990          32 :         if ( ( nBlockAddX != 0 && nBlockAddX < nDestSizeX ) ||
     991          32 :              ( nBlockAddY != 0 && nBlockAddY < nDestSizeY ) ||
     992           0 :              ( bMarkIsFiltered && nUnfilteredRows < nDestSizeY+1 ) )
     993             :         {
     994           0 :             ScWaitCursorOff aWaitOff( GetFrameWin() );
     995           0 :             OUString aMessage = ScGlobal::GetRscString( STR_PASTE_BIGGER );
     996           0 :             QueryBox aBox( GetViewData().GetDialogParent(),
     997           0 :                             WinBits(WB_YES_NO | WB_DEF_NO), aMessage );
     998           0 :             if ( aBox.Execute() != RET_YES )
     999             :             {
    1000           0 :                 return false;
    1001           0 :             }
    1002             :         }
    1003             : 
    1004          32 :         if (nBlockAddX <= nDestSizeX)
    1005          32 :             nEndCol = nStartCol + nDestSizeX;
    1006             : 
    1007          32 :         if (nBlockAddY <= nDestSizeY)
    1008             :         {
    1009          32 :             nEndRow = nStartRow + nDestSizeY;
    1010          32 :             if (bMarkIsFiltered || nEndRow > aMarkRange.aEnd.Row())
    1011             :             {
    1012             :                 // Same as above if nothing was marked: re-fit selection to
    1013             :                 // unfiltered rows. Extending the selection actually may
    1014             :                 // introduce filtered rows where there weren't any before, so
    1015             :                 // we also need to test for that.
    1016           0 :                 aMarkRange = ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
    1017           0 :                 if (bMarkIsFiltered || ScViewUtil::HasFiltered( aMarkRange, pDoc))
    1018             :                 {
    1019           0 :                     bMarkIsFiltered = true;
    1020             :                     // Worst case: all rows up to the end of the sheet are filtered.
    1021           0 :                     if (!ScViewUtil::FitToUnfilteredRows( aMarkRange, pDoc, nDestSizeY+1))
    1022             :                     {
    1023           0 :                         ErrorMessage(STR_PASTE_FULL);
    1024           0 :                         return false;
    1025             :                     }
    1026             :                 }
    1027           0 :                 aMarkRange.GetVars( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
    1028           0 :                 aFilteredMark.SetMarkArea( aMarkRange);
    1029           0 :                 if (bMarkIsFiltered)
    1030             :                 {
    1031           0 :                     ScViewUtil::UnmarkFiltered( aFilteredMark, pDoc);
    1032           0 :                     aFilteredMark.FillRangeListWithMarks( &aRangeList, true);
    1033             :                 }
    1034             :             }
    1035             :         }
    1036             :     }
    1037             :     else
    1038             :     {
    1039           0 :         nStartCol = GetViewData().GetCurX();
    1040           0 :         nStartRow = GetViewData().GetCurY();
    1041           0 :         nStartTab = GetViewData().GetTabNo();
    1042           0 :         nEndCol = nStartCol + nDestSizeX;
    1043           0 :         nEndRow = nStartRow + nDestSizeY;
    1044           0 :         nEndTab = nStartTab;
    1045             :     }
    1046             : 
    1047          32 :     bool bOffLimits = !ValidCol(nEndCol) || !ValidRow(nEndRow);
    1048             : 
    1049             :     //  Zielbereich, wie er angezeigt wird:
    1050          32 :     ScRange aUserRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab );
    1051             : 
    1052             :     //  Sollen Zellen eingefuegt werden?
    1053             :     //  (zu grosse nEndCol/nEndRow werden weiter unten erkannt)
    1054          32 :     bool bInsertCells = ( eMoveMode != INS_NONE && !bOffLimits );
    1055          32 :     if ( bInsertCells )
    1056             :     {
    1057             :         //  Instead of EnterListAction, the paste undo action is merged into the
    1058             :         //  insert action, so Repeat can insert the right cells
    1059             : 
    1060           0 :         MarkRange( aUserRange );            // wird vor CopyFromClip sowieso gesetzt
    1061             : 
    1062             :         // CutMode is reset on insertion of cols/rows but needed again on cell move
    1063           0 :         bool bCut = pClipDoc->IsCutMode();
    1064           0 :         if (!InsertCells( eMoveMode, bRecord, true ))   // is inserting possible?
    1065             :         {
    1066           0 :             return false;
    1067             :             //  #i21036# EnterListAction isn't used, and InsertCells doesn't insert
    1068             :             //  its undo action on failure, so no undo handling is needed here
    1069             :         }
    1070           0 :         if ( bCut )
    1071           0 :             pClipDoc->SetCutMode( bCut );
    1072             :     }
    1073          32 :     else if (!bOffLimits)
    1074             :     {
    1075           0 :         bool bAskIfNotEmpty = bAllowDialogs &&
    1076          32 :                                 ( nFlags & IDF_CONTENTS ) &&
    1077          32 :                                 nFunction == PASTE_NOFUNC &&
    1078          64 :                                 SC_MOD()->GetInputOptions().GetReplaceCellsWarn();
    1079          32 :         if ( bAskIfNotEmpty )
    1080             :         {
    1081           0 :             ScRangeList aTestRanges;
    1082           0 :             aTestRanges.Append(aUserRange);
    1083           0 :             if (!checkDestRangeForOverwrite(aTestRanges, pDoc, aFilteredMark, GetViewData().GetDialogParent()))
    1084           0 :                 return false;
    1085             :         }
    1086             :     }
    1087             : 
    1088             :     SCCOL nClipStartX;                      // Clipboard-Bereich erweitern
    1089             :     SCROW nClipStartY;
    1090          32 :     pClipDoc->GetClipStart( nClipStartX, nClipStartY );
    1091          32 :     SCCOL nUndoEndCol = nClipStartX + nClipSizeX;
    1092          32 :     SCROW nUndoEndRow = nClipStartY + nClipSizeY;   // end of source area in clipboard document
    1093          32 :     bool bClipOver = false;
    1094             :     // #i68690# ExtendMerge for the clip doc must be called with the clipboard's sheet numbers.
    1095             :     // The same end column/row can be used for all calls because the clip doc doesn't contain
    1096             :     // content outside the clip area.
    1097          64 :     for (SCTAB nClipTab=0; nClipTab < pClipDoc->GetTableCount(); nClipTab++)
    1098          32 :         if ( pClipDoc->HasTable(nClipTab) )
    1099          32 :             if ( pClipDoc->ExtendMerge( nClipStartX,nClipStartY, nUndoEndCol,nUndoEndRow, nClipTab, false ) )
    1100           0 :                 bClipOver = true;
    1101          32 :     nUndoEndCol -= nClipStartX + nClipSizeX;
    1102          32 :     nUndoEndRow -= nClipStartY + nClipSizeY;        // now contains only the difference added by ExtendMerge
    1103          32 :     nUndoEndCol = sal::static_int_cast<SCCOL>( nUndoEndCol + nEndCol );
    1104          32 :     nUndoEndRow = sal::static_int_cast<SCROW>( nUndoEndRow + nEndRow ); // destination area, expanded for merged cells
    1105             : 
    1106          32 :     if (nUndoEndCol>MAXCOL || nUndoEndRow>MAXROW)
    1107             :     {
    1108           0 :         ErrorMessage(STR_PASTE_FULL);
    1109           0 :         return false;
    1110             :     }
    1111             : 
    1112          32 :     pDoc->ExtendMergeSel( nStartCol,nStartRow, nUndoEndCol,nUndoEndRow, aFilteredMark, false );
    1113             : 
    1114             :         //  Test auf Zellschutz
    1115             : 
    1116          32 :     ScEditableTester aTester( pDoc, nStartTab, nStartCol,nStartRow, nUndoEndCol,nUndoEndRow );
    1117          32 :     if (!aTester.IsEditable())
    1118             :     {
    1119           0 :         ErrorMessage(aTester.GetMessageId());
    1120           0 :         return false;
    1121             :     }
    1122             : 
    1123             :         //! Test auf Ueberlappung
    1124             :         //! nur wirkliche Schnittmenge testen !!!!!!!
    1125             : 
    1126          32 :     ScDocFunc& rDocFunc = pDocSh->GetDocFunc();
    1127          32 :     if ( bRecord )
    1128             :     {
    1129          32 :         OUString aUndo = ScGlobal::GetRscString( pClipDoc->IsCutMode() ? STR_UNDO_MOVE : STR_UNDO_COPY );
    1130          32 :         pUndoMgr->EnterListAction( aUndo, aUndo );
    1131             :     }
    1132             : 
    1133          32 :     if (bClipOver)
    1134           0 :         if (lcl_SelHasAttrib( pDoc, nStartCol,nStartRow, nUndoEndCol,nUndoEndRow, aFilteredMark, HASATTR_OVERLAPPED ))
    1135             :         {       // "Cell merge not possible if cells already merged"
    1136           0 :             ScDocAttrIterator aIter( pDoc, nStartTab, nStartCol, nStartRow, nUndoEndCol, nUndoEndRow );
    1137           0 :             const ScPatternAttr* pPattern = NULL;
    1138           0 :             const ScMergeAttr* pMergeFlag = NULL;
    1139           0 :             const ScMergeFlagAttr* pMergeFlagAttr = NULL;
    1140           0 :             SCCOL nCol = -1;
    1141           0 :             SCROW nRow1 = -1;
    1142           0 :             SCROW nRow2 = -1;
    1143           0 :             while ( ( pPattern = aIter.GetNext( nCol, nRow1, nRow2 ) ) != NULL )
    1144             :             {
    1145           0 :                 pMergeFlag = static_cast<const ScMergeAttr*>( &pPattern->GetItem(ATTR_MERGE) );
    1146           0 :                 pMergeFlagAttr = static_cast<const ScMergeFlagAttr*>( &pPattern->GetItem(ATTR_MERGE_FLAG) );
    1147           0 :                 if( ( pMergeFlag && pMergeFlag->IsMerged() ) || ( pMergeFlagAttr && pMergeFlagAttr->IsOverlapped() ) )
    1148             :                 {
    1149           0 :                     ScRange aRange(nCol, nRow1, nStartTab);
    1150           0 :                     pDoc->ExtendOverlapped(aRange);
    1151           0 :                     pDoc->ExtendMerge(aRange, true);
    1152           0 :                     rDocFunc.UnmergeCells(aRange, bRecord);
    1153             :                 }
    1154           0 :             }
    1155             :         }
    1156             : 
    1157          32 :     if ( !bCutMode )
    1158             :     {
    1159          32 :         ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
    1160          32 :         if ( pChangeTrack )
    1161           0 :             pChangeTrack->ResetLastCut();   // kein CutMode mehr
    1162             :     }
    1163             : 
    1164          32 :     bool bColInfo = ( nStartRow==0 && nEndRow==MAXROW );
    1165          32 :     bool bRowInfo = ( nStartCol==0 && nEndCol==MAXCOL );
    1166             : 
    1167          32 :     ScDocument* pUndoDoc    = NULL;
    1168          32 :     ScDocument* pRefUndoDoc = NULL;
    1169          32 :     ScRefUndoData* pUndoData = NULL;
    1170             : 
    1171          32 :     if ( bRecord )
    1172             :     {
    1173          32 :         pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
    1174          32 :         pUndoDoc->InitUndoSelected( pDoc, aFilteredMark, bColInfo, bRowInfo );
    1175             : 
    1176             :         // all sheets - CopyToDocument skips those that don't exist in pUndoDoc
    1177          32 :         SCTAB nTabCount = pDoc->GetTableCount();
    1178             :         pDoc->CopyToDocument( nStartCol, nStartRow, 0, nUndoEndCol, nUndoEndRow, nTabCount-1,
    1179          32 :                               nUndoFlags, false, pUndoDoc );
    1180             : 
    1181          32 :         if ( bCutMode )
    1182             :         {
    1183           0 :             pRefUndoDoc = new ScDocument( SCDOCMODE_UNDO );
    1184           0 :             pRefUndoDoc->InitUndo( pDoc, 0, nTabCount-1, false, false );
    1185             : 
    1186           0 :             pUndoData = new ScRefUndoData( pDoc );
    1187             :         }
    1188             :     }
    1189             : 
    1190          32 :     sal_uInt16 nExtFlags = 0;
    1191             :     pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab,
    1192          32 :                                        nEndCol,   nEndRow,   nEndTab );     // content before the change
    1193             : 
    1194          32 :     if (GetViewData().IsActive())
    1195             :     {
    1196          32 :         DoneBlockMode();
    1197          32 :         InitOwnBlockMode();
    1198             :     }
    1199          32 :     rMark.SetMarkArea( aUserRange );
    1200          32 :     MarkDataChanged();
    1201             : 
    1202             :         //  Aus Clipboard kopieren,
    1203             :         //  wenn gerechnet werden soll, Originaldaten merken
    1204             : 
    1205          64 :     boost::scoped_ptr<ScDocument> pMixDoc;
    1206          32 :     if (nFunction)
    1207             :     {
    1208           0 :         bSkipEmpty = false;
    1209           0 :         if ( nFlags & IDF_CONTENTS )
    1210             :         {
    1211           0 :             pMixDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
    1212           0 :             pMixDoc->InitUndo( pDoc, nStartTab, nEndTab );
    1213             :             pDoc->CopyToDocument( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab,
    1214           0 :                                   IDF_CONTENTS, false, pMixDoc.get() );
    1215             :         }
    1216             :     }
    1217             : 
    1218             :     /*  Make draw layer and start drawing undo.
    1219             :         - Needed before AdjustBlockHeight to track moved drawing objects.
    1220             :         - Needed before pDoc->CopyFromClip to track inserted note caption objects.
    1221             :      */
    1222          32 :     if ( bPasteDraw )
    1223           0 :         pDocSh->MakeDrawLayer();
    1224          32 :     if ( bRecord )
    1225          32 :         pDoc->BeginDrawUndo();
    1226             : 
    1227          32 :     InsertDeleteFlags nNoObjFlags = nFlags & ~IDF_OBJECTS;
    1228          32 :     if (!bAsLink)
    1229             :     {
    1230             :         //  copy normally (original range)
    1231             :         pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags,
    1232             :                 pRefUndoDoc, pClipDoc, true, false, bIncludeFiltered,
    1233          32 :                 bSkipEmpty, (bMarkIsFiltered ? &aRangeList : NULL) );
    1234             : 
    1235             :         // bei Transpose Referenzen per Hand anpassen
    1236          32 :         if ( bTranspose && bCutMode && (nFlags & IDF_CONTENTS) )
    1237           0 :             pDoc->UpdateTranspose( aUserRange.aStart, pOrigClipDoc, aFilteredMark, pRefUndoDoc );
    1238             :     }
    1239           0 :     else if (!bTranspose)
    1240             :     {
    1241             :         //  copy with bAsLink=TRUE
    1242             :         pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags, pRefUndoDoc, pClipDoc,
    1243           0 :                                 true, true, bIncludeFiltered, bSkipEmpty );
    1244             :     }
    1245             :     else
    1246             :     {
    1247             :         //  alle Inhalte kopieren (im TransClipDoc stehen nur Formeln)
    1248           0 :         pDoc->CopyFromClip( aUserRange, aFilteredMark, nContFlags, pRefUndoDoc, pClipDoc );
    1249             :     }
    1250             : 
    1251             :     // skipped rows and merged cells don't mix
    1252          32 :     if ( !bIncludeFiltered && pClipDoc->HasClipFilteredRows() )
    1253           0 :         rDocFunc.UnmergeCells( aUserRange, false );
    1254             : 
    1255          32 :     pDoc->ExtendMergeSel( nStartCol, nStartRow, nEndCol, nEndRow, aFilteredMark, true );    // Refresh
    1256             :                                                                                     // und Bereich neu
    1257             : 
    1258          32 :     if ( pMixDoc )              // Rechenfunktionen mit Original-Daten auszufuehren ?
    1259             :     {
    1260           0 :         pDoc->MixDocument( aUserRange, nFunction, bSkipEmpty, pMixDoc.get() );
    1261             :     }
    1262          32 :     pMixDoc.reset();
    1263             : 
    1264          32 :     AdjustBlockHeight();            // update row heights before pasting objects
    1265             : 
    1266          64 :     ::std::vector< OUString > aExcludedChartNames;
    1267          32 :     SdrPage* pPage = NULL;
    1268             : 
    1269          32 :     if ( nFlags & IDF_OBJECTS )
    1270             :     {
    1271          32 :         ScDrawView* pScDrawView = GetScDrawView();
    1272          32 :         SdrModel* pModel = ( pScDrawView ? pScDrawView->GetModel() : NULL );
    1273          32 :         pPage = ( pModel ? pModel->GetPage( static_cast< sal_uInt16 >( nStartTab ) ) : NULL );
    1274          32 :         if ( pPage )
    1275             :         {
    1276          32 :             ScChartHelper::GetChartNames( aExcludedChartNames, pPage );
    1277             :         }
    1278             : 
    1279             :         //  Paste the drawing objects after the row heights have been updated.
    1280             : 
    1281             :         pDoc->CopyFromClip( aUserRange, aFilteredMark, IDF_OBJECTS, pRefUndoDoc, pClipDoc,
    1282          32 :                                 true, false, bIncludeFiltered );
    1283             :     }
    1284             : 
    1285             :     pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab,
    1286          32 :                                        nEndCol,   nEndRow,   nEndTab );     // content after the change
    1287             : 
    1288             :         //  ggf. Autofilter-Koepfe loeschen
    1289          32 :     if (bCutMode)
    1290           0 :         if (pDoc->RefreshAutoFilter( nClipStartX,nClipStartY, nClipStartX+nClipSizeX,
    1291           0 :                                         nClipStartY+nClipSizeY, nStartTab ))
    1292             :         {
    1293             :             pDocSh->PostPaint(
    1294             :                 ScRange(nClipStartX, nClipStartY, nStartTab, nClipStartX+nClipSizeX, nClipStartY, nStartTab),
    1295           0 :                 PAINT_GRID );
    1296             :         }
    1297             : 
    1298             :     //!     Block-Bereich bei RefUndoDoc weglassen !!!
    1299             : 
    1300          32 :     if ( bRecord )
    1301             :     {
    1302          32 :         ScDocument* pRedoDoc    = NULL;
    1303             :         // Redo-Daten werden erst beim ersten Undo kopiert
    1304             :         // ohne RefUndoDoc muss das Redo-Doc noch nicht angelegt werden
    1305             : 
    1306          32 :         if (pRefUndoDoc)
    1307             :         {
    1308           0 :             pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
    1309           0 :             pRedoDoc->InitUndo( pDoc, nStartTab, nEndTab, bColInfo, bRowInfo );
    1310             : 
    1311             :             //      angepasste Referenzen ins Redo-Doc
    1312             : 
    1313           0 :             SCTAB nTabCount = pDoc->GetTableCount();
    1314           0 :             pRedoDoc->AddUndoTab( 0, nTabCount-1 );
    1315           0 :             pDoc->CopyUpdated( pRefUndoDoc, pRedoDoc );
    1316             : 
    1317             :             //      alte Referenzen ins Undo-Doc
    1318             : 
    1319             :             //! Tabellen selektieren ?
    1320           0 :             pUndoDoc->AddUndoTab( 0, nTabCount-1 );
    1321           0 :             pRefUndoDoc->DeleteArea( nStartCol, nStartRow, nEndCol, nEndRow, aFilteredMark, IDF_ALL );
    1322             :             pRefUndoDoc->CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTabCount-1,
    1323           0 :                                             IDF_FORMULA, false, pUndoDoc );
    1324           0 :             delete pRefUndoDoc;
    1325             :         }
    1326             : 
    1327             :         //  DeleteUnchanged for pUndoData is in ScUndoPaste ctor,
    1328             :         //  UndoData for redo is made during first undo
    1329             : 
    1330          32 :         ScUndoPasteOptions aOptions;            // store options for repeat
    1331          32 :         aOptions.nFunction  = nFunction;
    1332          32 :         aOptions.bSkipEmpty = bSkipEmpty;
    1333          32 :         aOptions.bTranspose = bTranspose;
    1334          32 :         aOptions.bAsLink    = bAsLink;
    1335          32 :         aOptions.eMoveMode  = eMoveMode;
    1336             : 
    1337             :         SfxUndoAction* pUndo = new ScUndoPaste(
    1338             :             pDocSh, ScRange(nStartCol, nStartRow, nStartTab, nUndoEndCol, nUndoEndRow, nEndTab),
    1339          64 :             aFilteredMark, pUndoDoc, pRedoDoc, nFlags | nUndoFlags, pUndoData,
    1340          96 :             false, &aOptions );     // false = Redo data not yet copied
    1341             : 
    1342          32 :         if ( bInsertCells )
    1343             :         {
    1344             :             //  Merge the paste undo action into the insert action.
    1345             :             //  Use ScUndoWrapper so the ScUndoPaste pointer can be stored in the insert action.
    1346             : 
    1347           0 :             pUndoMgr->AddUndoAction( new ScUndoWrapper( pUndo ), true );
    1348             :         }
    1349             :         else
    1350          32 :             pUndoMgr->AddUndoAction( pUndo );
    1351          32 :         pUndoMgr->LeaveListAction();
    1352             :     }
    1353             : 
    1354          32 :     sal_uInt16 nPaint = PAINT_GRID;
    1355          32 :     if (bColInfo)
    1356             :     {
    1357           0 :         nPaint |= PAINT_TOP;
    1358           0 :         nUndoEndCol = MAXCOL;               // nur zum Zeichnen !
    1359             :     }
    1360          32 :     if (bRowInfo)
    1361             :     {
    1362           0 :         nPaint |= PAINT_LEFT;
    1363           0 :         nUndoEndRow = MAXROW;               // nur zum Zeichnen !
    1364             :     }
    1365             :     pDocSh->PostPaint(
    1366             :         ScRange(nStartCol, nStartRow, nStartTab, nUndoEndCol, nUndoEndRow, nEndTab),
    1367          32 :         nPaint, nExtFlags);
    1368             :     // AdjustBlockHeight has already been called above
    1369             : 
    1370          32 :     ResetAutoSpell();
    1371          32 :     aModificator.SetDocumentModified();
    1372          32 :     PostPasteFromClip(aUserRange, rMark);
    1373             : 
    1374          32 :     if ( nFlags & IDF_OBJECTS )
    1375             :     {
    1376          32 :         ScModelObj* pModelObj = ScModelObj::getImplementation( pDocSh->GetModel() );
    1377          32 :         if ( pPage && pModelObj )
    1378             :         {
    1379          32 :             bool bSameDoc = ( rClipParam.getSourceDocID() == pDoc->GetDocumentID() );
    1380          32 :             const ScRangeListVector& rProtectedChartRangesVector( rClipParam.maProtectedChartRangesVector );
    1381             :             ScChartHelper::CreateProtectedChartListenersAndNotify( pDoc, pPage, pModelObj, nStartTab,
    1382          32 :                 rProtectedChartRangesVector, aExcludedChartNames, bSameDoc );
    1383             :         }
    1384             :     }
    1385             : 
    1386          64 :     return true;
    1387             : }
    1388             : 
    1389           0 : bool ScViewFunc::PasteMultiRangesFromClip(
    1390             :     InsertDeleteFlags nFlags, ScDocument* pClipDoc, sal_uInt16 nFunction,
    1391             :     bool bSkipEmpty, bool bTranspose, bool bAsLink, bool bAllowDialogs,
    1392             :     InsCellCmd eMoveMode, InsertDeleteFlags nUndoFlags)
    1393             : {
    1394           0 :     ScViewData& rViewData = GetViewData();
    1395           0 :     ScDocument* pDoc = rViewData.GetDocument();
    1396           0 :     ScDocShell* pDocSh = rViewData.GetDocShell();
    1397           0 :     ScMarkData aMark(rViewData.GetMarkData());
    1398           0 :     const ScAddress& rCurPos = rViewData.GetCurPos();
    1399           0 :     ScClipParam& rClipParam = pClipDoc->GetClipParam();
    1400           0 :     SCCOL nColSize = rClipParam.getPasteColSize();
    1401           0 :     SCROW nRowSize = rClipParam.getPasteRowSize();
    1402             : 
    1403           0 :     if (bTranspose)
    1404             :     {
    1405           0 :         if (static_cast<SCROW>(rCurPos.Col()) + nRowSize-1 > static_cast<SCROW>(MAXCOL))
    1406             :         {
    1407           0 :             ErrorMessage(STR_PASTE_FULL);
    1408           0 :             return false;
    1409             :         }
    1410             : 
    1411           0 :         ::std::unique_ptr<ScDocument> pTransClip(new ScDocument(SCDOCMODE_CLIP));
    1412           0 :         pClipDoc->TransposeClip(pTransClip.get(), nFlags, bAsLink);
    1413           0 :         pClipDoc = pTransClip.release();
    1414           0 :         SCCOL nTempColSize = nColSize;
    1415           0 :         nColSize = static_cast<SCCOL>(nRowSize);
    1416           0 :         nRowSize = static_cast<SCROW>(nTempColSize);
    1417             :     }
    1418             : 
    1419           0 :     if (!ValidCol(rCurPos.Col()+nColSize-1) || !ValidRow(rCurPos.Row()+nRowSize-1))
    1420             :     {
    1421           0 :         ErrorMessage(STR_PASTE_FULL);
    1422           0 :         return false;
    1423             :     }
    1424             : 
    1425             :     // Determine the first and last selected sheet numbers.
    1426           0 :     SCTAB nTab1 = aMark.GetFirstSelected();
    1427           0 :     SCTAB nTab2 = aMark.GetLastSelected();
    1428             : 
    1429           0 :     ScDocShellModificator aModificator(*pDocSh);
    1430             : 
    1431             :     // For multi-selection paste, we don't support cell duplication for larger
    1432             :     // destination range.  In case the destination is marked, we reset it to
    1433             :     // the clip size.
    1434           0 :     ScRange aMarkedRange(rCurPos.Col(), rCurPos.Row(), nTab1,
    1435           0 :                          rCurPos.Col()+nColSize-1, rCurPos.Row()+nRowSize-1, nTab2);
    1436             : 
    1437             :     // Extend the marked range to account for filtered rows in the destination
    1438             :     // area.
    1439           0 :     if (ScViewUtil::HasFiltered(aMarkedRange, pDoc))
    1440             :     {
    1441           0 :         if (!ScViewUtil::FitToUnfilteredRows(aMarkedRange, pDoc, nRowSize))
    1442           0 :             return false;
    1443             :     }
    1444             : 
    1445             :     bool bAskIfNotEmpty =
    1446           0 :         bAllowDialogs && (nFlags & IDF_CONTENTS) &&
    1447           0 :         nFunction == PASTE_NOFUNC && SC_MOD()->GetInputOptions().GetReplaceCellsWarn();
    1448             : 
    1449           0 :     if (bAskIfNotEmpty)
    1450             :     {
    1451           0 :         ScRangeList aTestRanges;
    1452           0 :         aTestRanges.Append(aMarkedRange);
    1453           0 :         if (!checkDestRangeForOverwrite(aTestRanges, pDoc, aMark, rViewData.GetDialogParent()))
    1454           0 :             return false;
    1455             :     }
    1456             : 
    1457           0 :     aMark.SetMarkArea(aMarkedRange);
    1458           0 :     MarkRange(aMarkedRange);
    1459             : 
    1460           0 :     bool bInsertCells = (eMoveMode != INS_NONE);
    1461           0 :     if (bInsertCells)
    1462             :     {
    1463           0 :         if (!InsertCells(eMoveMode, pDoc->IsUndoEnabled(), true))
    1464           0 :             return false;
    1465             :     }
    1466             : 
    1467           0 :     ::std::unique_ptr<ScDocument> pUndoDoc;
    1468           0 :     if (pDoc->IsUndoEnabled())
    1469             :     {
    1470           0 :         pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
    1471           0 :         pUndoDoc->InitUndoSelected(pDoc, aMark, false, false);
    1472           0 :         pDoc->CopyToDocument(aMarkedRange, nUndoFlags, false, pUndoDoc.get(), &aMark, true);
    1473             :     }
    1474             : 
    1475           0 :     ::std::unique_ptr<ScDocument> pMixDoc;
    1476           0 :     if ( bSkipEmpty || nFunction )
    1477             :     {
    1478           0 :         if ( nFlags & IDF_CONTENTS )
    1479             :         {
    1480           0 :             pMixDoc.reset(new ScDocument(SCDOCMODE_UNDO));
    1481           0 :             pMixDoc->InitUndoSelected(pDoc, aMark, false, false);
    1482           0 :             pDoc->CopyToDocument(aMarkedRange, IDF_CONTENTS, false, pMixDoc.get(), &aMark, true);
    1483             :         }
    1484             :     }
    1485             : 
    1486             :     /*  Make draw layer and start drawing undo.
    1487             :         - Needed before AdjustBlockHeight to track moved drawing objects.
    1488             :         - Needed before pDoc->CopyFromClip to track inserted note caption objects.
    1489             :      */
    1490           0 :     if (nFlags & IDF_OBJECTS)
    1491           0 :         pDocSh->MakeDrawLayer();
    1492           0 :     if (pDoc->IsUndoEnabled())
    1493           0 :         pDoc->BeginDrawUndo();
    1494             : 
    1495           0 :     InsertDeleteFlags nNoObjFlags = nFlags & ~IDF_OBJECTS;
    1496             :     pDoc->CopyMultiRangeFromClip(rCurPos, aMark, nNoObjFlags, pClipDoc,
    1497           0 :                                  true, bAsLink, false, bSkipEmpty);
    1498             : 
    1499           0 :     if (pMixDoc.get())
    1500           0 :         pDoc->MixDocument(aMarkedRange, nFunction, bSkipEmpty, pMixDoc.get());
    1501             : 
    1502           0 :     AdjustBlockHeight();            // update row heights before pasting objects
    1503             : 
    1504           0 :     if (nFlags & IDF_OBJECTS)
    1505             :     {
    1506             :         //  Paste the drawing objects after the row heights have been updated.
    1507             :         pDoc->CopyMultiRangeFromClip(rCurPos, aMark, IDF_OBJECTS, pClipDoc,
    1508           0 :                                      true, false, false, true);
    1509             :     }
    1510             : 
    1511           0 :     ScRange aTmp = aMarkedRange;
    1512           0 :     aTmp.aStart.SetTab(nTab1);
    1513           0 :     aTmp.aEnd.SetTab(nTab1);
    1514           0 :     pDocSh->PostPaint(aTmp, PAINT_GRID);
    1515             : 
    1516           0 :     if (pDoc->IsUndoEnabled())
    1517             :     {
    1518           0 :         ::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
    1519             :         OUString aUndo = ScGlobal::GetRscString(
    1520           0 :             pClipDoc->IsCutMode() ? STR_UNDO_CUT : STR_UNDO_COPY);
    1521           0 :         pUndoMgr->EnterListAction(aUndo, aUndo);
    1522             : 
    1523           0 :         ScUndoPasteOptions aOptions;            // store options for repeat
    1524           0 :         aOptions.nFunction  = nFunction;
    1525           0 :         aOptions.bSkipEmpty = bSkipEmpty;
    1526           0 :         aOptions.bTranspose = bTranspose;
    1527           0 :         aOptions.bAsLink    = bAsLink;
    1528           0 :         aOptions.eMoveMode  = eMoveMode;
    1529             : 
    1530             :         ScUndoPaste* pUndo = new ScUndoPaste(pDocSh,
    1531           0 :             aMarkedRange, aMark, pUndoDoc.release(), NULL, nFlags|nUndoFlags, NULL, false, &aOptions);
    1532             : 
    1533           0 :         if (bInsertCells)
    1534           0 :             pUndoMgr->AddUndoAction(new ScUndoWrapper(pUndo), true);
    1535             :         else
    1536           0 :             pUndoMgr->AddUndoAction(pUndo, false);
    1537             : 
    1538           0 :         pUndoMgr->LeaveListAction();
    1539             :     }
    1540             : 
    1541           0 :     ResetAutoSpell();
    1542           0 :     aModificator.SetDocumentModified();
    1543           0 :     PostPasteFromClip(aMarkedRange, aMark);
    1544           0 :     return true;
    1545             : }
    1546             : 
    1547           0 : bool ScViewFunc::PasteFromClipToMultiRanges(
    1548             :     InsertDeleteFlags nFlags, ScDocument* pClipDoc, sal_uInt16 nFunction,
    1549             :     bool bSkipEmpty, bool bTranspose, bool bAsLink, bool bAllowDialogs,
    1550             :     InsCellCmd eMoveMode, InsertDeleteFlags nUndoFlags )
    1551             : {
    1552           0 :     if (bTranspose)
    1553             :     {
    1554             :         // We don't allow transpose for this yet.
    1555           0 :         ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
    1556           0 :         return false;
    1557             :     }
    1558             : 
    1559           0 :     if (eMoveMode != INS_NONE)
    1560             :     {
    1561             :         // We don't allow insertion mode either.  Too complicated.
    1562           0 :         ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
    1563           0 :         return false;
    1564             :     }
    1565             : 
    1566           0 :     ScViewData& rViewData = GetViewData();
    1567           0 :     ScClipParam& rClipParam = pClipDoc->GetClipParam();
    1568           0 :     if (rClipParam.mbCutMode)
    1569             :     {
    1570             :         // No cut and paste with this, please.
    1571           0 :         ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
    1572           0 :         return false;
    1573             :     }
    1574             : 
    1575           0 :     const ScAddress& rCurPos = rViewData.GetCurPos();
    1576           0 :     ScDocument* pDoc = rViewData.GetDocument();
    1577             : 
    1578           0 :     ScRange aSrcRange = rClipParam.getWholeRange();
    1579           0 :     SCROW nRowSize = aSrcRange.aEnd.Row() - aSrcRange.aStart.Row() + 1;
    1580           0 :     SCCOL nColSize = aSrcRange.aEnd.Col() - aSrcRange.aStart.Col() + 1;
    1581             : 
    1582           0 :     if (!ValidCol(rCurPos.Col()+nColSize-1) || !ValidRow(rCurPos.Row()+nRowSize-1))
    1583             :     {
    1584           0 :         ErrorMessage(STR_PASTE_FULL);
    1585           0 :         return false;
    1586             :     }
    1587             : 
    1588           0 :     ScMarkData aMark(rViewData.GetMarkData());
    1589             : 
    1590           0 :     ScRangeList aRanges;
    1591           0 :     aMark.MarkToSimple();
    1592           0 :     aMark.FillRangeListWithMarks(&aRanges, false);
    1593           0 :     if (!ScClipUtil::CheckDestRanges(pDoc, nColSize, nRowSize, aMark, aRanges))
    1594             :     {
    1595           0 :         ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
    1596           0 :         return false;
    1597             :     }
    1598             : 
    1599           0 :     ScDocShell* pDocSh = rViewData.GetDocShell();
    1600             : 
    1601           0 :     ScDocShellModificator aModificator(*pDocSh);
    1602             : 
    1603             :     bool bAskIfNotEmpty =
    1604           0 :         bAllowDialogs && (nFlags & IDF_CONTENTS) &&
    1605           0 :         nFunction == PASTE_NOFUNC && SC_MOD()->GetInputOptions().GetReplaceCellsWarn();
    1606             : 
    1607           0 :     if (bAskIfNotEmpty)
    1608             :     {
    1609           0 :         if (!checkDestRangeForOverwrite(aRanges, pDoc, aMark, rViewData.GetDialogParent()))
    1610           0 :             return false;
    1611             :     }
    1612             : 
    1613           0 :     std::unique_ptr<ScDocument> pUndoDoc;
    1614           0 :     if (pDoc->IsUndoEnabled())
    1615             :     {
    1616           0 :         pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
    1617           0 :         pUndoDoc->InitUndoSelected(pDoc, aMark, false, false);
    1618           0 :         for (size_t i = 0, n = aRanges.size(); i < n; ++i)
    1619             :         {
    1620             :             pDoc->CopyToDocument(
    1621           0 :                 *aRanges[i], nUndoFlags, false, pUndoDoc.get(), &aMark, true);
    1622             :         }
    1623             :     }
    1624             : 
    1625           0 :     boost::scoped_ptr<ScDocument> pMixDoc;
    1626           0 :     if (bSkipEmpty || nFunction)
    1627             :     {
    1628           0 :         if (nFlags & IDF_CONTENTS)
    1629             :         {
    1630           0 :             pMixDoc.reset(new ScDocument(SCDOCMODE_UNDO));
    1631           0 :             pMixDoc->InitUndoSelected(pDoc, aMark, false, false);
    1632           0 :             for (size_t i = 0, n = aRanges.size(); i < n; ++i)
    1633             :             {
    1634             :                 pDoc->CopyToDocument(
    1635           0 :                     *aRanges[i], IDF_CONTENTS, false, pMixDoc.get(), &aMark, true);
    1636             :             }
    1637             :         }
    1638             :     }
    1639             : 
    1640           0 :     if (nFlags & IDF_OBJECTS)
    1641           0 :         pDocSh->MakeDrawLayer();
    1642           0 :     if (pDoc->IsUndoEnabled())
    1643           0 :         pDoc->BeginDrawUndo();
    1644             : 
    1645             :     // First, paste everything but the drawing objects.
    1646           0 :     for (size_t i = 0, n = aRanges.size(); i < n; ++i)
    1647             :     {
    1648             :         pDoc->CopyFromClip(
    1649           0 :             *aRanges[i], aMark, (nFlags & ~IDF_OBJECTS), NULL, pClipDoc,
    1650           0 :             false, false, true, bSkipEmpty, NULL);
    1651             :     }
    1652             : 
    1653           0 :     if (pMixDoc.get())
    1654             :     {
    1655           0 :         for (size_t i = 0, n = aRanges.size(); i < n; ++i)
    1656           0 :             pDoc->MixDocument(*aRanges[i], nFunction, bSkipEmpty, pMixDoc.get());
    1657             :     }
    1658             : 
    1659           0 :     AdjustBlockHeight();            // update row heights before pasting objects
    1660             : 
    1661             :     // Then paste the objects.
    1662           0 :     if (nFlags & IDF_OBJECTS)
    1663             :     {
    1664           0 :         for (size_t i = 0, n = aRanges.size(); i < n; ++i)
    1665             :         {
    1666             :             pDoc->CopyFromClip(
    1667           0 :                 *aRanges[i], aMark, IDF_OBJECTS, NULL, pClipDoc,
    1668           0 :                 false, false, true, bSkipEmpty, NULL);
    1669             :         }
    1670             :     }
    1671             : 
    1672             :     // Refresh the range that includes all pasted ranges.  We only need to
    1673             :     // refresh the current sheet.
    1674           0 :     pDocSh->PostPaint(aRanges, PAINT_GRID);
    1675             : 
    1676           0 :     if (pDoc->IsUndoEnabled())
    1677             :     {
    1678           0 :         svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
    1679             :         OUString aUndo = ScGlobal::GetRscString(
    1680           0 :             pClipDoc->IsCutMode() ? STR_UNDO_CUT : STR_UNDO_COPY);
    1681           0 :         pUndoMgr->EnterListAction(aUndo, aUndo);
    1682             : 
    1683           0 :         ScUndoPasteOptions aOptions;            // store options for repeat
    1684           0 :         aOptions.nFunction  = nFunction;
    1685           0 :         aOptions.bSkipEmpty = bSkipEmpty;
    1686           0 :         aOptions.bTranspose = bTranspose;
    1687           0 :         aOptions.bAsLink    = bAsLink;
    1688           0 :         aOptions.eMoveMode  = eMoveMode;
    1689             : 
    1690             :         ScUndoPaste* pUndo = new ScUndoPaste(
    1691           0 :             pDocSh, aRanges, aMark, pUndoDoc.release(), NULL, nFlags|nUndoFlags, NULL, false, &aOptions);
    1692             : 
    1693           0 :         pUndoMgr->AddUndoAction(pUndo, false);
    1694           0 :         pUndoMgr->LeaveListAction();
    1695             :     }
    1696             : 
    1697           0 :     ResetAutoSpell();
    1698           0 :     aModificator.SetDocumentModified();
    1699           0 :     PostPasteFromClip(aRanges, aMark);
    1700             : 
    1701           0 :     return false;
    1702             : }
    1703             : 
    1704          32 : void ScViewFunc::PostPasteFromClip(const ScRangeList& rPasteRanges, const ScMarkData& rMark)
    1705             : {
    1706          32 :     ScViewData& rViewData = GetViewData();
    1707          32 :     ScDocShell* pDocSh = rViewData.GetDocShell();
    1708          32 :     pDocSh->UpdateOle(&rViewData);
    1709             : 
    1710          32 :     SelectionChanged();
    1711             : 
    1712          32 :     ScModelObj* pModelObj = HelperNotifyChanges::getMustPropagateChangesModel(*pDocSh);
    1713          32 :     if (!pModelObj)
    1714          64 :         return;
    1715             : 
    1716           0 :     ScRangeList aChangeRanges;
    1717           0 :     for (size_t i = 0, n = rPasteRanges.size(); i < n; ++i)
    1718             :     {
    1719           0 :         const ScRange& r = *rPasteRanges[i];
    1720           0 :         ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
    1721           0 :         for (; itr != itrEnd; ++itr)
    1722             :         {
    1723           0 :             ScRange aChangeRange(r);
    1724           0 :             aChangeRange.aStart.SetTab(*itr);
    1725           0 :             aChangeRange.aEnd.SetTab(*itr);
    1726           0 :             aChangeRanges.Append(aChangeRange);
    1727             :         }
    1728             :     }
    1729           0 :     HelperNotifyChanges::Notify(*pModelObj, aChangeRanges);
    1730             : }
    1731             : 
    1732             : //      D R A G   A N D   D R O P
    1733             : 
    1734             : //  innerhalb des Dokuments
    1735             : 
    1736           0 : bool ScViewFunc::MoveBlockTo( const ScRange& rSource, const ScAddress& rDestPos,
    1737             :                                 bool bCut, bool bRecord, bool bPaint, bool bApi )
    1738             : {
    1739           0 :     ScDocShell* pDocSh = GetViewData().GetDocShell();
    1740           0 :     HideAllCursors();       // wegen zusammengefassten
    1741             : 
    1742           0 :     bool bSuccess = true;
    1743           0 :     SCTAB nDestTab = rDestPos.Tab();
    1744           0 :     const ScMarkData& rMark = GetViewData().GetMarkData();
    1745           0 :     if ( rSource.aStart.Tab() == nDestTab && rSource.aEnd.Tab() == nDestTab && rMark.GetSelectCount() > 1 )
    1746             :     {
    1747             :         //  moving within one table and several tables selected -> apply to all selected tables
    1748             : 
    1749           0 :         if ( bRecord )
    1750             :         {
    1751           0 :             OUString aUndo = ScGlobal::GetRscString( bCut ? STR_UNDO_MOVE : STR_UNDO_COPY );
    1752           0 :             pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
    1753             :         }
    1754             : 
    1755             :         //  collect ranges of consecutive selected tables
    1756             : 
    1757           0 :         ScRange aLocalSource = rSource;
    1758           0 :         ScAddress aLocalDest = rDestPos;
    1759           0 :         SCTAB nTabCount = pDocSh->GetDocument().GetTableCount();
    1760           0 :         SCTAB nStartTab = 0;
    1761           0 :         while ( nStartTab < nTabCount && bSuccess )
    1762             :         {
    1763           0 :             while ( nStartTab < nTabCount && !rMark.GetTableSelect(nStartTab) )
    1764           0 :                 ++nStartTab;
    1765           0 :             if ( nStartTab < nTabCount )
    1766             :             {
    1767           0 :                 SCTAB nEndTab = nStartTab;
    1768           0 :                 while ( nEndTab+1 < nTabCount && rMark.GetTableSelect(nEndTab+1) )
    1769           0 :                     ++nEndTab;
    1770             : 
    1771           0 :                 aLocalSource.aStart.SetTab( nStartTab );
    1772           0 :                 aLocalSource.aEnd.SetTab( nEndTab );
    1773           0 :                 aLocalDest.SetTab( nStartTab );
    1774             : 
    1775           0 :                 bSuccess = pDocSh->GetDocFunc().MoveBlock(
    1776           0 :                                 aLocalSource, aLocalDest, bCut, bRecord, bPaint, bApi );
    1777             : 
    1778           0 :                 nStartTab = nEndTab + 1;
    1779             :             }
    1780             :         }
    1781             : 
    1782           0 :         if ( bRecord )
    1783           0 :             pDocSh->GetUndoManager()->LeaveListAction();
    1784             :     }
    1785             :     else
    1786             :     {
    1787             :         //  move the block as specified
    1788           0 :         bSuccess = pDocSh->GetDocFunc().MoveBlock(
    1789           0 :                                 rSource, rDestPos, bCut, bRecord, bPaint, bApi );
    1790             :     }
    1791             : 
    1792           0 :     ShowAllCursors();
    1793           0 :     if (bSuccess)
    1794             :     {
    1795             :         //  Zielbereich markieren
    1796             :         ScAddress aDestEnd(
    1797           0 :                     rDestPos.Col() + rSource.aEnd.Col() - rSource.aStart.Col(),
    1798           0 :                     rDestPos.Row() + rSource.aEnd.Row() - rSource.aStart.Row(),
    1799           0 :                     nDestTab );
    1800             : 
    1801           0 :         bool bIncludeFiltered = bCut;
    1802           0 :         if ( !bIncludeFiltered )
    1803             :         {
    1804             :             // find number of non-filtered rows
    1805           0 :             SCROW nPastedCount = pDocSh->GetDocument().CountNonFilteredRows(
    1806           0 :                 rSource.aStart.Row(), rSource.aEnd.Row(), rSource.aStart.Tab());
    1807             : 
    1808           0 :             if ( nPastedCount == 0 )
    1809           0 :                 nPastedCount = 1;
    1810           0 :             aDestEnd.SetRow( rDestPos.Row() + nPastedCount - 1 );
    1811             :         }
    1812             : 
    1813           0 :         MarkRange( ScRange( rDestPos, aDestEnd ), false );          //! sal_False ???
    1814             : 
    1815           0 :         pDocSh->UpdateOle(&GetViewData());
    1816           0 :         SelectionChanged();
    1817           0 :         ResetAutoSpell();
    1818             :     }
    1819           0 :     return bSuccess;
    1820             : }
    1821             : 
    1822             : //  Link innerhalb des Dokuments
    1823             : 
    1824           0 : bool ScViewFunc::LinkBlock( const ScRange& rSource, const ScAddress& rDestPos, bool bApi )
    1825             : {
    1826             :     //  Test auf Ueberlappung
    1827             : 
    1828           0 :     if ( rSource.aStart.Tab() == rDestPos.Tab() )
    1829             :     {
    1830           0 :         SCCOL nDestEndCol = rDestPos.Col() + ( rSource.aEnd.Col() - rSource.aStart.Col() );
    1831           0 :         SCROW nDestEndRow = rDestPos.Row() + ( rSource.aEnd.Row() - rSource.aStart.Row() );
    1832             : 
    1833           0 :         if ( rSource.aStart.Col() <= nDestEndCol && rDestPos.Col() <= rSource.aEnd.Col() &&
    1834           0 :              rSource.aStart.Row() <= nDestEndRow && rDestPos.Row() <= rSource.aEnd.Row() )
    1835             :         {
    1836           0 :             if (!bApi)
    1837           0 :                 ErrorMessage( STR_ERR_LINKOVERLAP );
    1838           0 :             return false;
    1839             :         }
    1840             :     }
    1841             : 
    1842             :     //  Ausfuehren per Paste
    1843             : 
    1844           0 :     ScDocument* pDoc = GetViewData().GetDocument();
    1845           0 :     boost::scoped_ptr<ScDocument> pClipDoc(new ScDocument( SCDOCMODE_CLIP ));
    1846           0 :     pDoc->CopyTabToClip( rSource.aStart.Col(), rSource.aStart.Row(),
    1847           0 :                             rSource.aEnd.Col(), rSource.aEnd.Row(),
    1848           0 :                          rSource.aStart.Tab(), pClipDoc.get() );
    1849             : 
    1850             :     //  Zielbereich markieren (Cursor setzen, keine Markierung)
    1851             : 
    1852           0 :     if ( GetViewData().GetTabNo() != rDestPos.Tab() )
    1853           0 :         SetTabNo( rDestPos.Tab() );
    1854             : 
    1855           0 :     MoveCursorAbs( rDestPos.Col(), rDestPos.Row(), SC_FOLLOW_NONE, false, false );
    1856             : 
    1857             :     //  Paste
    1858             : 
    1859           0 :     PasteFromClip( IDF_ALL, pClipDoc.get(), PASTE_NOFUNC, false, false, true );       // als Link
    1860             : 
    1861           0 :     return true;
    1862             : }
    1863             : 
    1864           0 : void ScViewFunc::DataFormPutData( SCROW nCurrentRow ,
    1865             :                                   SCROW nStartRow , SCCOL nStartCol ,
    1866             :                                   SCROW nEndRow , SCCOL nEndCol ,
    1867             :                                   boost::ptr_vector<boost::nullable<Edit> >& aEdits,
    1868             :                                   sal_uInt16 aColLength )
    1869             : {
    1870           0 :     ScDocument* pDoc = GetViewData().GetDocument();
    1871           0 :     ScDocShell* pDocSh = GetViewData().GetDocShell();
    1872           0 :     ScMarkData& rMark = GetViewData().GetMarkData();
    1873           0 :     ScDocShellModificator aModificator( *pDocSh );
    1874           0 :     ::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
    1875           0 :     if ( pDoc )
    1876             :     {
    1877           0 :         const bool bRecord( pDoc->IsUndoEnabled());
    1878           0 :         ScDocument* pUndoDoc = NULL;
    1879           0 :         ScDocument* pRedoDoc = NULL;
    1880           0 :         ScRefUndoData* pUndoData = NULL;
    1881           0 :         SCTAB nTab = GetViewData().GetTabNo();
    1882           0 :         SCTAB nStartTab = nTab;
    1883           0 :         SCTAB nEndTab = nTab;
    1884             : 
    1885             :         {
    1886           0 :                 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
    1887           0 :                 if ( pChangeTrack )
    1888           0 :                         pChangeTrack->ResetLastCut();   // kein CutMode mehr
    1889             :         }
    1890           0 :         ScRange aUserRange( nStartCol, nCurrentRow, nStartTab, nEndCol, nCurrentRow, nEndTab );
    1891           0 :         bool bColInfo = ( nStartRow==0 && nEndRow==MAXROW );
    1892           0 :         bool bRowInfo = ( nStartCol==0 && nEndCol==MAXCOL );
    1893           0 :         SCCOL nUndoEndCol = nStartCol+aColLength-1;
    1894           0 :         SCROW nUndoEndRow = nCurrentRow;
    1895           0 :         InsertDeleteFlags nUndoFlags = IDF_NONE;
    1896             : 
    1897           0 :         if ( bRecord )
    1898             :         {
    1899           0 :             pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
    1900           0 :             pUndoDoc->InitUndoSelected( pDoc , rMark , bColInfo , bRowInfo );
    1901           0 :             pDoc->CopyToDocument( aUserRange , IDF_VALUE , false , pUndoDoc );
    1902             :         }
    1903           0 :         sal_uInt16 nExtFlags = 0;
    1904           0 :         pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab , nEndCol, nEndRow, nEndTab ); // content before the change
    1905           0 :         pDoc->BeginDrawUndo();
    1906             : 
    1907           0 :         for(sal_uInt16 i = 0; i < aColLength; i++)
    1908             :         {
    1909           0 :             if (!aEdits.is_null(i))
    1910             :             {
    1911           0 :                 OUString  aFieldName=aEdits[i].GetText();
    1912           0 :                 pDoc->SetString( nStartCol + i, nCurrentRow, nTab, aFieldName );
    1913             :             }
    1914             :         }
    1915           0 :         pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nCurrentRow, nStartTab, nEndCol, nCurrentRow, nEndTab );  // content after the change
    1916             :         SfxUndoAction* pUndo = new ScUndoDataForm( pDocSh,
    1917             :                                                                 nStartCol, nCurrentRow, nStartTab,
    1918             :                                                                 nUndoEndCol, nUndoEndRow, nEndTab, rMark,
    1919             :                                                                 pUndoDoc, pRedoDoc, nUndoFlags,
    1920             :                                                                 pUndoData, NULL, NULL, NULL,
    1921           0 :                                                                 false );           // FALSE = Redo data not yet copied
    1922           0 :         pUndoMgr->AddUndoAction( new ScUndoWrapper( pUndo ), true );
    1923             : 
    1924           0 :         sal_uInt16 nPaint = PAINT_GRID;
    1925           0 :         if (bColInfo)
    1926             :         {
    1927           0 :                 nPaint |= PAINT_TOP;
    1928           0 :                 nUndoEndCol = MAXCOL;                           // nur zum Zeichnen !
    1929             :         }
    1930           0 :         if (bRowInfo)
    1931             :         {
    1932           0 :                 nPaint |= PAINT_LEFT;
    1933           0 :                 nUndoEndRow = MAXROW;                           // nur zum Zeichnen !
    1934             :         }
    1935             : 
    1936             :         pDocSh->PostPaint(
    1937             :             ScRange(nStartCol, nCurrentRow, nStartTab, nUndoEndCol, nUndoEndRow, nEndTab),
    1938           0 :             nPaint, nExtFlags);
    1939           0 :         pDocSh->UpdateOle(&GetViewData());
    1940           0 :     }
    1941         228 : }
    1942             : 
    1943             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10