LCOV - code coverage report
Current view: top level - sc/source/ui/view - viewfun5.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 365 0.3 %
Date: 2014-11-03 Functions: 2 4 50.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 <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
      21             : #include <com/sun/star/embed/Aspects.hpp>
      22             : #include <com/sun/star/embed/MSOLEObjectSystemCreator.hpp>
      23             : 
      24             : #include <svx/unomodel.hxx>
      25             : #include <unotools/streamwrap.hxx>
      26             : 
      27             : #include <svx/fmmodel.hxx>
      28             : #include <svx/svdetc.hxx>
      29             : #include <svx/svditer.hxx>
      30             : #include <svx/svdobj.hxx>
      31             : #include <svx/svdogrp.hxx>
      32             : #include <svx/svdouno.hxx>
      33             : #include <svx/svdoole2.hxx>
      34             : #include <svx/svdpage.hxx>
      35             : #include <sfx2/dispatch.hxx>
      36             : #include <sfx2/docfile.hxx>
      37             : #include <comphelper/classids.hxx>
      38             : #include <sot/formats.hxx>
      39             : #include <sot/filelist.hxx>
      40             : #include <unotools/pathoptions.hxx>
      41             : #include <svl/ptitem.hxx>
      42             : #include <svl/stritem.hxx>
      43             : #include <svtools/transfer.hxx>
      44             : #include <vcl/graph.hxx>
      45             : 
      46             : #include <comphelper/processfactory.hxx>
      47             : #include <comphelper/storagehelper.hxx>
      48             : #include <comphelper/string.hxx>
      49             : 
      50             : #include "viewfunc.hxx"
      51             : #include "docsh.hxx"
      52             : #include "drawview.hxx"
      53             : #include "impex.hxx"
      54             : #include "dbfunc.hxx"
      55             : #include "dbdata.hxx"
      56             : #include "sc.hrc"
      57             : #include "filter.hxx"
      58             : #include "scextopt.hxx"
      59             : #include "tabvwsh.hxx"
      60             : #include "compiler.hxx"
      61             : 
      62             : #include "asciiopt.hxx"
      63             : #include "scabstdlg.hxx"
      64             : #include "clipparam.hxx"
      65             : #include "markdata.hxx"
      66             : #include <vcl/msgbox.hxx>
      67             : #include <sfx2/viewfrm.hxx>
      68             : #include <svx/dbaexchange.hxx>
      69             : #include <boost/scoped_ptr.hpp>
      70             : 
      71             : using namespace com::sun::star;
      72             : 
      73           0 : bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
      74             :                     const uno::Reference<datatransfer::XTransferable>& rxTransferable,
      75             :                     SCCOL nPosX, SCROW nPosY, Point* pLogicPos, bool bLink, bool bAllowDialogs )
      76             : {
      77           0 :     ScDocument* pDoc = GetViewData().GetDocument();
      78           0 :     pDoc->SetPastingDrawFromOtherDoc( true );
      79             : 
      80           0 :     Point aPos;                     //  inserting position (1/100 mm)
      81           0 :     if (pLogicPos)
      82           0 :         aPos = *pLogicPos;
      83             :     else
      84             :     {
      85             :         //  inserting position isn't needed for text formats
      86           0 :         bool bIsTextFormat = ( ScImportExport::IsFormatSupported( nFormatId ) ||
      87           0 :                                 nFormatId == FORMAT_RTF );
      88           0 :         if ( !bIsTextFormat )
      89             :         {
      90             :             //  Window MapMode isn't drawing MapMode if DrawingLayer hasn't been created yet
      91             : 
      92           0 :             SCTAB nTab = GetViewData().GetTabNo();
      93           0 :             long nXT = 0;
      94           0 :             for (SCCOL i=0; i<nPosX; i++)
      95           0 :                 nXT += pDoc->GetColWidth(i,nTab);
      96           0 :             if (pDoc->IsNegativePage(nTab))
      97           0 :                 nXT = -nXT;
      98           0 :             sal_uLong nYT = pDoc->GetRowHeight( 0, nPosY-1, nTab);
      99           0 :             aPos = Point( (long)(nXT * HMM_PER_TWIPS), (long)(nYT * HMM_PER_TWIPS) );
     100             :         }
     101             :     }
     102             : 
     103           0 :     TransferableDataHelper aDataHelper( rxTransferable );
     104           0 :     bool bRet = false;
     105             : 
     106             :     //  handle individual formats
     107             : 
     108           0 :     if ( nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE ||
     109           0 :          nFormatId == SOT_FORMATSTR_ID_LINK_SOURCE ||
     110           0 :          nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ||
     111           0 :          nFormatId == SOT_FORMATSTR_ID_LINK_SOURCE_OLE ||
     112             :          nFormatId == SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE )
     113             :     {
     114           0 :         uno::Reference < io::XInputStream > xStm;
     115           0 :         TransferableObjectDescriptor   aObjDesc;
     116             : 
     117           0 :         if (aDataHelper.GetTransferableObjectDescriptor(SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc))
     118           0 :             xStm = aDataHelper.GetInputStream(nFormatId, OUString());
     119             : 
     120           0 :         if (xStm.is())
     121             :         {
     122           0 :             if ( aObjDesc.maClassName == SvGlobalName( SO3_SC_CLASSID_60 ) )
     123             :             {
     124           0 :                 uno::Reference < embed::XStorage > xStore = ::comphelper::OStorageHelper::GetStorageFromInputStream( xStm );
     125             : 
     126             :                 // mba: BaseURL doesn't make sense for clipboard
     127             :                 // #i43716# Medium must be allocated with "new".
     128             :                 // DoLoad stores the pointer and deletes it with the SfxObjectShell.
     129           0 :                 SfxMedium* pMedium = new SfxMedium( xStore, OUString() );
     130             : 
     131             :                 //  TODO/LATER: is it a problem that we don't support binary formats here?
     132           0 :                 ScDocShellRef xDocShRef = new ScDocShell(SFX_CREATE_MODE_EMBEDDED);
     133           0 :                 if (xDocShRef->DoLoad(pMedium))
     134             :                 {
     135           0 :                     ScDocument& rSrcDoc = xDocShRef->GetDocument();
     136           0 :                     SCTAB nSrcTab = rSrcDoc.GetVisibleTab();
     137           0 :                     if (!rSrcDoc.HasTable(nSrcTab))
     138           0 :                         nSrcTab = 0;
     139             : 
     140           0 :                     ScMarkData aSrcMark;
     141           0 :                     aSrcMark.SelectOneTable( nSrcTab );         // for CopyToClip
     142           0 :                     boost::scoped_ptr<ScDocument> pClipDoc(new ScDocument( SCDOCMODE_CLIP ));
     143             : 
     144             :                     SCCOL nFirstCol, nLastCol;
     145             :                     SCROW nFirstRow, nLastRow;
     146           0 :                     if ( rSrcDoc.GetDataStart( nSrcTab, nFirstCol, nFirstRow ) )
     147           0 :                         rSrcDoc.GetCellArea( nSrcTab, nLastCol, nLastRow );
     148             :                     else
     149             :                     {
     150           0 :                         nFirstCol = nLastCol = 0;
     151           0 :                         nFirstRow = nLastRow = 0;
     152             :                     }
     153           0 :                     ScClipParam aClipParam(ScRange(nFirstCol, nFirstRow, nSrcTab, nLastCol, nLastRow, nSrcTab), false);
     154           0 :                     rSrcDoc.CopyToClip(aClipParam, pClipDoc.get(), &aSrcMark);
     155           0 :                     ScGlobal::SetClipDocName( xDocShRef->GetTitle( SFX_TITLE_FULLNAME ) );
     156             : 
     157           0 :                     SetCursor( nPosX, nPosY );
     158           0 :                     Unmark();
     159             :                     PasteFromClip( IDF_ALL, pClipDoc.get(),
     160             :                                     PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
     161           0 :                                     bAllowDialogs );
     162           0 :                     bRet = true;
     163             :                 }
     164             : 
     165           0 :                 xDocShRef->DoClose();
     166           0 :                 xDocShRef.Clear();
     167             :             }
     168             :             else
     169             :             {
     170           0 :                 OUString aName;
     171           0 :                 uno::Reference < embed::XEmbeddedObject > xObj = GetViewData().GetViewShell()->GetObjectShell()->
     172           0 :                         GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
     173           0 :                 if ( xObj.is() )
     174             :                 {
     175             :                     // try to get the replacement image from the clipboard
     176           0 :                     Graphic aGraphic;
     177           0 :                     sal_uLong nGrFormat = 0;
     178             : 
     179             :                     // limit the size of the preview metafile to 100000 actions
     180           0 :                     GDIMetaFile aMetafile;
     181           0 :                     if (aDataHelper.GetGDIMetaFile(FORMAT_GDIMETAFILE, aMetafile, 100000))
     182             :                     {
     183           0 :                         nGrFormat = SOT_FORMAT_GDIMETAFILE;
     184           0 :                         aGraphic = aMetafile;
     185             :                     }
     186             : 
     187             :                     // insert replacement image ( if there is one ) into the object helper
     188           0 :                     if ( nGrFormat )
     189             :                     {
     190           0 :                         datatransfer::DataFlavor aDataFlavor;
     191           0 :                         SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
     192           0 :                         PasteObject( aPos, xObj, &aObjDesc.maSize, &aGraphic, aDataFlavor.MimeType, aObjDesc.mnViewAspect );
     193             :                     }
     194             :                     else
     195           0 :                         PasteObject( aPos, xObj, &aObjDesc.maSize );
     196             : 
     197           0 :                     bRet = true;
     198             :                 }
     199             :                 else
     200             :                 {
     201             :                     OSL_FAIL("Error in CreateAndLoad");
     202           0 :                 }
     203             :             }
     204             :         }
     205             :         else
     206             :         {
     207           0 :             if ( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE, aObjDesc ) )
     208             :             {
     209           0 :                 OUString aName;
     210           0 :                 uno::Reference < embed::XEmbeddedObject > xObj;
     211           0 :                 xStm = aDataHelper.GetInputStream(SOT_FORMATSTR_ID_EMBED_SOURCE_OLE, OUString());
     212           0 :                 if (!xStm.is())
     213           0 :                     aDataHelper.GetInputStream(SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE, OUString());
     214             : 
     215           0 :                 if (xStm.is())
     216             :                 {
     217           0 :                     xObj = GetViewData().GetDocShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
     218             :                 }
     219             :                 else
     220             :                 {
     221             :                     try
     222             :                     {
     223           0 :                         uno::Reference< embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
     224             :                         uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator =
     225           0 :                             embed::MSOLEObjectSystemCreator::create( ::comphelper::getProcessComponentContext() );
     226             : 
     227           0 :                         embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
     228             :                                                             xTmpStor,
     229             :                                                             OUString( "DummyName" ),
     230           0 :                                                             uno::Sequence< beans::PropertyValue >() );
     231             : 
     232             :                         // TODO/LATER: in future InsertedObjectInfo will be used to get container related information
     233             :                         // for example whether the object should be an iconified one
     234           0 :                         xObj = aInfo.Object;
     235           0 :                         if ( xObj.is() )
     236           0 :                             GetViewData().GetDocShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
     237             :                     }
     238           0 :                     catch( uno::Exception& )
     239             :                     {}
     240             :                 }
     241             : 
     242           0 :                 if ( xObj.is() )
     243             :                 {
     244             :                     // try to get the replacement image from the clipboard
     245           0 :                     Graphic aGraphic;
     246           0 :                     sal_uLong nGrFormat = 0;
     247             : 
     248             : // (wg. Selection Manager bei Trustet Solaris)
     249             : #ifndef SOLARIS
     250           0 :                     if( aDataHelper.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) )
     251           0 :                         nGrFormat = SOT_FORMATSTR_ID_SVXB;
     252           0 :                     else if( aDataHelper.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
     253           0 :                         nGrFormat = SOT_FORMAT_GDIMETAFILE;
     254           0 :                     else if( aDataHelper.GetGraphic( FORMAT_BITMAP, aGraphic ) )
     255           0 :                         nGrFormat = SOT_FORMAT_BITMAP;
     256             : #endif
     257             : 
     258             :                     // insert replacement image ( if there is one ) into the object helper
     259           0 :                     if ( nGrFormat )
     260             :                     {
     261           0 :                         datatransfer::DataFlavor aDataFlavor;
     262           0 :                         SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
     263           0 :                         PasteObject( aPos, xObj, &aObjDesc.maSize, &aGraphic, aDataFlavor.MimeType, aObjDesc.mnViewAspect );
     264             :                     }
     265             :                     else
     266           0 :                         PasteObject( aPos, xObj, &aObjDesc.maSize );
     267             : 
     268             :                     // let object stay in loaded state after insertion
     269           0 :                     SdrOle2Obj::Unload( xObj, embed::Aspects::MSOLE_CONTENT );
     270           0 :                     bRet = true;
     271             :                 }
     272             :                 else
     273             :                 {
     274             :                     OSL_FAIL("Error creating external OLE object");
     275           0 :                 }
     276             :             }
     277             :             //TODO/LATER: if format is not available, create picture
     278           0 :         }
     279             :     }
     280           0 :     else if ( nFormatId == SOT_FORMATSTR_ID_LINK )      // LINK is also in ScImportExport
     281             :     {
     282           0 :         bRet = PasteLink( rxTransferable );
     283             :     }
     284           0 :     else if ( ScImportExport::IsFormatSupported( nFormatId ) || nFormatId == SOT_FORMAT_RTF )
     285             :     {
     286           0 :         if ( nFormatId == SOT_FORMAT_RTF && aDataHelper.HasFormat( SOT_FORMATSTR_ID_EDITENGINE ) )
     287             :         {
     288             :             //  use EditView's PasteSpecial / Drop
     289           0 :             PasteRTF( nPosX, nPosY, rxTransferable );
     290           0 :             bRet = true;
     291             :         }
     292             :         else
     293             :         {
     294           0 :             ScAddress aCellPos( nPosX, nPosY, GetViewData().GetTabNo() );
     295           0 :             ScImportExport aObj( GetViewData().GetDocument(), aCellPos );
     296           0 :             aObj.SetImportBroadcast(true);
     297             : 
     298           0 :             OUString aStr;
     299           0 :             SotStorageStreamRef xStream;
     300           0 :             if ( aDataHelper.GetSotStorageStream( nFormatId, xStream ) && xStream.Is() )
     301             :             {
     302           0 :                 if (nFormatId == SOT_FORMATSTR_ID_HTML)
     303             :                 {
     304             :                     // Launch the text import options dialog.  For now, we do
     305             :                     // this for html pasting only, but in the future it may
     306             :                     // make sense to do it for other data types too.
     307           0 :                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
     308             :                     boost::scoped_ptr<AbstractScTextImportOptionsDlg> pDlg(
     309           0 :                         pFact->CreateScTextImportOptionsDlg(NULL));
     310             : 
     311           0 :                     if (pDlg->Execute() == RET_OK)
     312             :                     {
     313           0 :                         ScAsciiOptions aOptions;
     314           0 :                         aOptions.SetLanguage(pDlg->GetLanguageType());
     315           0 :                         aOptions.SetDetectSpecialNumber(pDlg->IsDateConversionSet());
     316           0 :                         aObj.SetExtOptions(aOptions);
     317             :                     }
     318             :                     else
     319             :                     {
     320             :                         // prevent error dialog for user cancel action
     321           0 :                         bRet = true;
     322           0 :                     }
     323             :                 }
     324           0 :                 if(!bRet)
     325           0 :                     bRet = aObj.ImportStream( *xStream, OUString(), nFormatId );
     326             :                 // mba: clipboard always must contain absolute URLs (could be from alien source)
     327             :             }
     328           0 :             else if (nFormatId == FORMAT_STRING && aDataHelper.GetString( nFormatId, aStr ))
     329             :             {
     330             :                 // Do CSV dialog if more than one line.
     331           0 :                 sal_Int32 nDelim = aStr.indexOf('\n');
     332           0 :                 if (nDelim >= 0 && nDelim != aStr.getLength () - 1)
     333             :                 {
     334           0 :                     ScImportStringStream aStrm( aStr);
     335             :                     ScAbstractDialogFactory* pFact =
     336           0 :                         ScAbstractDialogFactory::Create();
     337             :                     boost::scoped_ptr<AbstractScImportAsciiDlg> pDlg(
     338             :                         pFact->CreateScImportAsciiDlg( NULL, OUString(), &aStrm,
     339           0 :                                                        SC_PASTETEXT));
     340             : 
     341           0 :                     if (pDlg->Execute() == RET_OK)
     342             :                     {
     343           0 :                         ScAsciiOptions aOptions;
     344           0 :                         pDlg->GetOptions( aOptions );
     345           0 :                         pDlg->SaveParameters();
     346           0 :                         aObj.SetExtOptions( aOptions );
     347             : 
     348           0 :                         bRet = aObj.ImportString( aStr, nFormatId );
     349             : 
     350             :                         // TODO: what if (aObj.IsOverflow())
     351             :                         // Content was partially pasted, which can be undone by
     352             :                         // the user though.
     353           0 :                         if (aObj.IsOverflow())
     354           0 :                             bRet = false;
     355             :                     }
     356             :                     else
     357           0 :                         bRet = true;
     358             :                         // Yes, no failure, don't raise a "couldn't paste"
     359             :                         // dialog if user cancelled.
     360             :                 }
     361             :                 else
     362           0 :                     bRet = aObj.ImportString( aStr, nFormatId );
     363             :             }
     364           0 :             else if (nFormatId != FORMAT_STRING && aDataHelper.GetString( nFormatId, aStr ))
     365           0 :                 bRet = aObj.ImportString( aStr, nFormatId );
     366             : 
     367           0 :             InvalidateAttribs();
     368           0 :             GetViewData().UpdateInputHandler();
     369             :         }
     370             :     }
     371           0 :     else if (nFormatId == SOT_FORMATSTR_ID_SBA_DATAEXCHANGE)
     372             :     {
     373             :         //  import of database data into table
     374             : 
     375           0 :         const DataFlavorExVector& rVector = aDataHelper.GetDataFlavorExVector();
     376           0 :         if ( svx::ODataAccessObjectTransferable::canExtractObjectDescriptor(rVector) )
     377             :         {
     378             :             // transport the whole ODataAccessDescriptor as slot parameter
     379           0 :             svx::ODataAccessDescriptor aDesc = svx::ODataAccessObjectTransferable::extractObjectDescriptor(aDataHelper);
     380           0 :             uno::Any aDescAny;
     381           0 :             uno::Sequence<beans::PropertyValue> aProperties = aDesc.createPropertyValueSequence();
     382           0 :             aDescAny <<= aProperties;
     383           0 :             SfxUsrAnyItem aDataDesc(SID_SBA_IMPORT, aDescAny);
     384             : 
     385           0 :             ScDocShell* pDocSh = GetViewData().GetDocShell();
     386           0 :             SCTAB nTab = GetViewData().GetTabNo();
     387             : 
     388           0 :             ClickCursor(nPosX, nPosY, false);               // set cursor position
     389             : 
     390             :             //  Creation of database area "Import1" isn't here, but in the DocShell
     391             :             //  slot execute, so it can be added to the undo action
     392             : 
     393           0 :             ScDBData* pDBData = pDocSh->GetDBData( ScRange(nPosX,nPosY,nTab), SC_DB_OLD, SC_DBSEL_KEEP );
     394           0 :             OUString sTarget;
     395           0 :             if (pDBData)
     396           0 :                 sTarget = pDBData->GetName();
     397             :             else
     398             :             {
     399           0 :                 ScAddress aCellPos( nPosX,nPosY,nTab );
     400           0 :                 sTarget = aCellPos.Format(SCA_ABS_3D, pDoc, pDoc->GetAddressConvention());
     401             :             }
     402           0 :             SfxStringItem aTarget(FN_PARAM_1, sTarget);
     403             : 
     404           0 :             bool bAreaIsNew = !pDBData;
     405           0 :             SfxBoolItem aAreaNew(FN_PARAM_2, bAreaIsNew);
     406             : 
     407             :             //  asynchronous, to avoid doing the whole import in drop handler
     408           0 :             SfxDispatcher& rDisp = GetViewData().GetDispatcher();
     409             :             rDisp.Execute(SID_SBA_IMPORT, SfxCallMode::ASYNCHRON,
     410           0 :                                         &aDataDesc, &aTarget, &aAreaNew, (void*)0 );
     411             : 
     412           0 :             bRet = true;
     413             :         }
     414             :     }
     415           0 :     else if (nFormatId == SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE)
     416             :     {
     417             :         //  insert database field control
     418             : 
     419           0 :         if ( ::svx::OColumnTransferable::canExtractColumnDescriptor( aDataHelper.GetDataFlavorExVector(), CTF_COLUMN_DESCRIPTOR | CTF_CONTROL_EXCHANGE ) )
     420             :         {
     421           0 :             MakeDrawLayer();
     422           0 :             ScDrawView* pScDrawView = GetScDrawView();
     423           0 :             SdrObject* pObj = pScDrawView->CreateFieldControl( ::svx::OColumnTransferable::extractColumnDescriptor( aDataHelper ) );
     424           0 :             if (pObj)
     425             :             {
     426           0 :                 Point aInsPos = aPos;
     427           0 :                 Rectangle aRect(pObj->GetLogicRect());
     428           0 :                 aInsPos.X() -= aRect.GetSize().Width()  / 2;
     429           0 :                 aInsPos.Y() -= aRect.GetSize().Height() / 2;
     430           0 :                 if ( aInsPos.X() < 0 ) aInsPos.X() = 0;
     431           0 :                 if ( aInsPos.Y() < 0 ) aInsPos.Y() = 0;
     432           0 :                 aRect.SetPos(aInsPos);
     433           0 :                 pObj->SetLogicRect(aRect);
     434             : 
     435           0 :                 if ( pObj->ISA(SdrUnoObj) )
     436           0 :                     pObj->NbcSetLayer(SC_LAYER_CONTROLS);
     437             :                 else
     438           0 :                     pObj->NbcSetLayer(SC_LAYER_FRONT);
     439           0 :                 if (pObj->ISA(SdrObjGroup))
     440             :                 {
     441           0 :                     SdrObjListIter aIter( *pObj, IM_DEEPWITHGROUPS );
     442           0 :                     SdrObject* pSubObj = aIter.Next();
     443           0 :                     while (pSubObj)
     444             :                     {
     445           0 :                         if ( pSubObj->ISA(SdrUnoObj) )
     446           0 :                             pSubObj->NbcSetLayer(SC_LAYER_CONTROLS);
     447             :                         else
     448           0 :                             pSubObj->NbcSetLayer(SC_LAYER_FRONT);
     449           0 :                         pSubObj = aIter.Next();
     450           0 :                     }
     451             :                 }
     452             : 
     453           0 :                 pScDrawView->InsertObjectSafe(pObj, *pScDrawView->GetSdrPageView());
     454             : 
     455           0 :                 GetViewData().GetViewShell()->SetDrawShell( true );
     456           0 :                 bRet = true;
     457             :             }
     458             :         }
     459             :     }
     460           0 :     else if (nFormatId == SOT_FORMAT_BITMAP || nFormatId == SOT_FORMATSTR_ID_PNG)
     461             :     {
     462           0 :         BitmapEx aBmpEx;
     463           0 :         if( aDataHelper.GetBitmapEx( FORMAT_BITMAP, aBmpEx ) )
     464           0 :             bRet = PasteBitmapEx( aPos, aBmpEx );
     465             :     }
     466           0 :     else if (nFormatId == SOT_FORMAT_GDIMETAFILE)
     467             :     {
     468           0 :         GDIMetaFile aMtf;
     469           0 :         if( aDataHelper.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMtf ) )
     470           0 :             bRet = PasteMetaFile( aPos, aMtf );
     471             :     }
     472           0 :     else if (nFormatId == SOT_FORMATSTR_ID_SVXB)
     473             :     {
     474           0 :         SotStorageStreamRef xStm;
     475           0 :         if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB, xStm ) )
     476             :         {
     477           0 :             Graphic aGraphic;
     478           0 :             ReadGraphic( *xStm, aGraphic );
     479           0 :             bRet = PasteGraphic( aPos, aGraphic, EMPTY_OUSTRING, EMPTY_OUSTRING );
     480           0 :         }
     481             :     }
     482           0 :     else if ( nFormatId == SOT_FORMATSTR_ID_DRAWING )
     483             :     {
     484           0 :         SotStorageStreamRef xStm;
     485           0 :         if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStm ) )
     486             :         {
     487           0 :             MakeDrawLayer();    // before loading model, so 3D factory has been created
     488             : 
     489           0 :             SvtPathOptions aPathOpt;
     490           0 :             OUString aPath = aPathOpt.GetPalettePath();
     491             : 
     492           0 :             ScDocShellRef aDragShellRef( new ScDocShell );
     493           0 :             aDragShellRef->DoInitNew(NULL);
     494           0 :             boost::scoped_ptr<FmFormModel> pModel(new FmFormModel( aPath, NULL, aDragShellRef ));
     495             : 
     496           0 :             pModel->GetItemPool().FreezeIdRanges();
     497           0 :             xStm->Seek(0);
     498             : 
     499           0 :             com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) );
     500           0 :             SvxDrawingLayerImport( pModel.get(), xInputStream );
     501             : 
     502             :             // set everything to right layer:
     503           0 :             size_t nObjCount = 0;
     504           0 :             sal_uInt16 nPages = pModel->GetPageCount();
     505           0 :             for (sal_uInt16 i=0; i<nPages; i++)
     506             :             {
     507           0 :                 SdrPage* pPage = pModel->GetPage(i);
     508           0 :                 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
     509           0 :                 SdrObject* pObject = aIter.Next();
     510           0 :                 while (pObject)
     511             :                 {
     512           0 :                     if ( pObject->ISA(SdrUnoObj) )
     513           0 :                         pObject->NbcSetLayer(SC_LAYER_CONTROLS);
     514             :                     else
     515           0 :                         pObject->NbcSetLayer(SC_LAYER_FRONT);
     516           0 :                     pObject = aIter.Next();
     517             :                 }
     518             : 
     519           0 :                 nObjCount += pPage->GetObjCount();          // count group object only once
     520           0 :             }
     521             : 
     522           0 :             PasteDraw(aPos, pModel.get(), (nObjCount > 1), "A", "B");     // grouped if more than 1 object
     523           0 :             pModel.reset();
     524           0 :             aDragShellRef->DoClose();
     525           0 :             bRet = true;
     526           0 :         }
     527             :     }
     528           0 :     else if ( (nFormatId == SOT_FORMATSTR_ID_BIFF_5) || (nFormatId == SOT_FORMATSTR_ID_BIFF_8) )
     529             :     {
     530             :         //  do excel import into a clipboard document
     531             :         //TODO/MBA: testing
     532           0 :         uno::Reference <io::XInputStream> xStm = aDataHelper.GetInputStream(nFormatId, OUString());
     533           0 :         if (xStm.is())
     534             :         {
     535           0 :             ScDocument* pInsDoc = new ScDocument( SCDOCMODE_CLIP );
     536           0 :             SCTAB nSrcTab = 0;      // Biff5 in clipboard: always sheet 0
     537           0 :             pInsDoc->ResetClip( pDoc, nSrcTab );
     538             : 
     539           0 :             SfxMedium aMed;
     540           0 :             aMed.GetItemSet()->Put( SfxUsrAnyItem( SID_INPUTSTREAM, uno::makeAny( xStm ) ) );
     541           0 :             FltError eErr = ScFormatFilter::Get().ScImportExcel( aMed, pInsDoc, EIF_AUTO );
     542           0 :             if ( eErr == eERR_OK )
     543             :             {
     544           0 :                 ScRange aSource;
     545           0 :                 const ScExtDocOptions* pExtOpt = pInsDoc->GetExtDocOptions();
     546           0 :                 const ScExtTabSettings* pTabSett = pExtOpt ? pExtOpt->GetTabSettings( nSrcTab ) : 0;
     547           0 :                 if( pTabSett && pTabSett->maUsedArea.IsValid() )
     548             :                 {
     549           0 :                     aSource = pTabSett->maUsedArea;
     550             :                     // ensure correct sheet indexes
     551           0 :                     aSource.aStart.SetTab( nSrcTab );
     552           0 :                     aSource.aEnd.SetTab( nSrcTab );
     553             : // don't use selection area: if cursor is moved in Excel after Copy, selection
     554             : // represents the new cursor position and not the copied area
     555             :                 }
     556             :                 else
     557             :                 {
     558             :                     OSL_FAIL("no dimension");   //! possible?
     559             :                     SCCOL nFirstCol, nLastCol;
     560             :                     SCROW nFirstRow, nLastRow;
     561           0 :                     if ( pInsDoc->GetDataStart( nSrcTab, nFirstCol, nFirstRow ) )
     562           0 :                         pInsDoc->GetCellArea( nSrcTab, nLastCol, nLastRow );
     563             :                     else
     564             :                     {
     565           0 :                         nFirstCol = nLastCol = 0;
     566           0 :                         nFirstRow = nLastRow = 0;
     567             :                     }
     568           0 :                     aSource = ScRange( nFirstCol, nFirstRow, nSrcTab,
     569           0 :                                         nLastCol, nLastRow, nSrcTab );
     570             :                 }
     571             : 
     572           0 :                 if ( pLogicPos )
     573             :                 {
     574             :                     // position specified (Drag&Drop) - change selection
     575           0 :                     MoveCursorAbs( nPosX, nPosY, SC_FOLLOW_NONE, false, false );
     576           0 :                     Unmark();
     577             :                 }
     578             : 
     579           0 :                 pInsDoc->SetClipArea( aSource );
     580             :                 PasteFromClip( IDF_ALL, pInsDoc,
     581             :                                 PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
     582           0 :                                 bAllowDialogs );
     583           0 :                 delete pInsDoc;
     584             : 
     585           0 :                 bRet = true;
     586           0 :             }
     587           0 :         }
     588             :     }
     589           0 :     else if ( nFormatId == SOT_FORMAT_FILE )
     590             :     {
     591           0 :         OUString aFile;
     592           0 :         if ( aDataHelper.GetString( nFormatId, aFile ) )
     593           0 :             bRet = PasteFile( aPos, aFile, bLink );
     594             :     }
     595           0 :     else if ( nFormatId == SOT_FORMAT_FILE_LIST )
     596             :     {
     597           0 :         FileList aFileList;
     598           0 :         if ( aDataHelper.GetFileList( nFormatId, aFileList ) )
     599             :         {
     600           0 :             sal_uLong nCount = aFileList.Count();
     601           0 :             for( sal_uLong i = 0; i < nCount ; i++ )
     602             :             {
     603           0 :                 OUString aFile = aFileList.GetFile( i );
     604             : 
     605           0 :                 PasteFile( aPos, aFile, bLink );
     606             : 
     607           0 :                 aPos.X() += 400;
     608           0 :                 aPos.Y() += 400;
     609           0 :             }
     610           0 :             bRet = true;
     611           0 :         }
     612             :     }
     613           0 :     else if ( nFormatId == SOT_FORMATSTR_ID_SOLK ||
     614           0 :               nFormatId == SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ||
     615           0 :               nFormatId == SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ||
     616             :               nFormatId == SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR )
     617             :     {
     618           0 :         bRet = PasteBookmark( nFormatId, rxTransferable, nPosX, nPosY );
     619             :     }
     620             : 
     621           0 :     pDoc->SetPastingDrawFromOtherDoc( false );
     622             : 
     623           0 :     return bRet;
     624             : }
     625             : 
     626           0 : bool ScViewFunc::PasteLink( const uno::Reference<datatransfer::XTransferable>& rxTransferable )
     627             : {
     628           0 :     TransferableDataHelper aDataHelper( rxTransferable );
     629             : 
     630             :     //  get link data from transferable before string data,
     631             :     //  so the source knows it will be used for a link
     632             : 
     633           0 :     uno::Sequence<sal_Int8> aSequence = aDataHelper.GetSequence(SOT_FORMATSTR_ID_LINK, OUString());
     634           0 :     if (!aSequence.getLength())
     635             :     {
     636             :         OSL_FAIL("DDE Data not found.");
     637           0 :         return false;
     638             :     }
     639             : 
     640             :     //  check size (only if string is available in transferable)
     641             : 
     642           0 :     sal_uInt16 nCols = 1;
     643           0 :     sal_uInt16 nRows = 1;
     644           0 :     if ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) )
     645             :     {
     646           0 :         OUString aDataStr;
     647           0 :         if ( aDataHelper.GetString( SOT_FORMAT_STRING, aDataStr ) )
     648             :         {
     649             :             //  get size from string the same way as in ScDdeLink::DataChanged
     650             : 
     651           0 :             aDataStr = convertLineEnd(aDataStr, LINEEND_LF);
     652           0 :             sal_Int32 nLen = aDataStr.getLength();
     653           0 :             if (nLen && aDataStr[nLen-1] == '\n')
     654           0 :                 aDataStr = aDataStr.copy(0, nLen-1);
     655             : 
     656           0 :             if (!aDataStr.isEmpty())
     657             :             {
     658           0 :                 nRows = comphelper::string::getTokenCount(aDataStr, '\n');
     659           0 :                 OUString aLine = aDataStr.getToken( 0, '\n' );
     660           0 :                 if (!aLine.isEmpty())
     661           0 :                     nCols = comphelper::string::getTokenCount(aLine, '\t');
     662             :             }
     663           0 :         }
     664             :     }
     665             : 
     666             :     //  create formula
     667             : 
     668           0 :     sal_Int32 nSeqLen = aSequence.getLength();
     669           0 :     const char* p = reinterpret_cast<const char*>(aSequence.getConstArray());
     670             : 
     671           0 :     rtl_TextEncoding eSysEnc = osl_getThreadTextEncoding();
     672             : 
     673             :     // char array delimited by \0.
     674             :     // app \0 topic \0 item \0 (extra \0) where the extra is optional.
     675           0 :     ::std::vector<OUString> aStrs;
     676           0 :     const char* pStart = p;
     677           0 :     sal_Int32 nStart = 0;
     678           0 :     for (sal_Int32 i = 0; i < nSeqLen; ++i, ++p)
     679             :     {
     680           0 :         if (*p == '\0')
     681             :         {
     682           0 :             sal_Int32 nLen = i - nStart;
     683           0 :             aStrs.push_back(OUString(pStart, nLen, eSysEnc));
     684           0 :             nStart = ++i;
     685           0 :             pStart = ++p;
     686             :         }
     687             :     }
     688             : 
     689           0 :     if (aStrs.size() < 3)
     690           0 :         return false;
     691             : 
     692           0 :     const OUString* pApp   = &aStrs[0];
     693           0 :     const OUString* pTopic = &aStrs[1];
     694           0 :     const OUString* pItem  = &aStrs[2];
     695           0 :     const OUString* pExtra = NULL;
     696           0 :     if (aStrs.size() > 3)
     697           0 :         pExtra = &aStrs[3];
     698             : 
     699           0 :     if ( pExtra && *pExtra == "calc:extref" )
     700             :     {
     701             :         // Paste this as an external reference.  Note that paste link always
     702             :         // uses Calc A1 syntax even when another formula syntax is specified
     703             :         // in the UI.
     704             :         EnterMatrix("='"
     705           0 :             + OUString(ScGlobal::GetAbsDocName(*pTopic, GetViewData().GetDocument()->GetDocumentShell()))
     706           0 :             + "'#" + *pItem
     707           0 :                 , ::formula::FormulaGrammar::GRAM_NATIVE);
     708           0 :         return true;
     709             :     }
     710             :     else
     711             :     {
     712             :         // DDE in all other cases.
     713             : 
     714             :         // TODO: we could define ocQuote for "
     715           0 :         EnterMatrix("=" + OUString(ScCompiler::GetNativeSymbol(ocDde))
     716           0 :             + ScCompiler::GetNativeSymbol(ocOpen)
     717           0 :             + "\"" + *pApp + "\""
     718           0 :             + ScCompiler::GetNativeSymbol(ocSep)
     719           0 :             + "\"" + *pTopic + "\""
     720           0 :             + ScCompiler::GetNativeSymbol(ocSep)
     721           0 :             + "\"" + *pItem + "\""
     722           0 :             + ScCompiler::GetNativeSymbol(ocClose)
     723           0 :                 , ::formula::FormulaGrammar::GRAM_NATIVE);
     724             :     }
     725             : 
     726             :     //  mark range
     727             : 
     728           0 :     SCTAB nTab = GetViewData().GetTabNo();
     729           0 :     SCCOL nCurX = GetViewData().GetCurX();
     730           0 :     SCROW nCurY = GetViewData().GetCurY();
     731           0 :     HideAllCursors();
     732           0 :     DoneBlockMode();
     733           0 :     InitBlockMode( nCurX, nCurY, nTab );
     734           0 :     MarkCursor( nCurX+static_cast<SCCOL>(nCols)-1, nCurY+static_cast<SCROW>(nRows)-1, nTab );
     735           0 :     ShowAllCursors();
     736           0 :     CursorPosChanged();
     737             : 
     738           0 :     return true;
     739         228 : }
     740             : 
     741             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10