LCOV - code coverage report
Current view: top level - sc/source/ui/view - viewfun5.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 364 0.0 %
Date: 2014-04-14 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
      21             : #include <com/sun/star/embed/Aspects.hpp>
      22             : #include <com/sun/star/embed/MSOLEObjectSystemCreator.hpp>
      23             : 
      24             : 
      25             : #include <svx/unomodel.hxx>
      26             : #include <unotools/streamwrap.hxx>
      27             : 
      28             : #include <svx/fmmodel.hxx>
      29             : #include <svx/svdetc.hxx>
      30             : #include <svx/svditer.hxx>
      31             : #include <svx/svdobj.hxx>
      32             : #include <svx/svdogrp.hxx>
      33             : #include <svx/svdouno.hxx>
      34             : #include <svx/svdoole2.hxx>
      35             : #include <svx/svdpage.hxx>
      36             : #include <sfx2/dispatch.hxx>
      37             : #include <sfx2/docfile.hxx>
      38             : #include <comphelper/classids.hxx>
      39             : #include <sot/formats.hxx>
      40             : #include <sot/filelist.hxx>
      41             : #include <unotools/pathoptions.hxx>
      42             : #include <svl/ptitem.hxx>
      43             : #include <svl/stritem.hxx>
      44             : #include <svtools/transfer.hxx>
      45             : #include <vcl/graph.hxx>
      46             : 
      47             : #include <comphelper/processfactory.hxx>
      48             : #include <comphelper/storagehelper.hxx>
      49             : #include <comphelper/string.hxx>
      50             : 
      51             : #include "viewfunc.hxx"
      52             : #include "docsh.hxx"
      53             : #include "drawview.hxx"
      54             : #include "impex.hxx"
      55             : #include "dbfunc.hxx"
      56             : #include "dbdata.hxx"
      57             : #include "sc.hrc"
      58             : #include "filter.hxx"
      59             : #include "scextopt.hxx"
      60             : #include "tabvwsh.hxx"
      61             : #include "compiler.hxx"
      62             : 
      63             : #include "asciiopt.hxx"
      64             : #include "scabstdlg.hxx"
      65             : #include "clipparam.hxx"
      66             : #include "markdata.hxx"
      67             : #include <vcl/msgbox.hxx>
      68             : #include <sfx2/viewfrm.hxx>
      69             : #include <svx/dbaexchange.hxx>
      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             : 
     107             :     //  handle individual formats
     108             : 
     109             : 
     110           0 :     if ( nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE ||
     111           0 :          nFormatId == SOT_FORMATSTR_ID_LINK_SOURCE ||
     112           0 :          nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ||
     113           0 :          nFormatId == SOT_FORMATSTR_ID_LINK_SOURCE_OLE ||
     114             :          nFormatId == SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE )
     115             :     {
     116           0 :         uno::Reference < io::XInputStream > xStm;
     117           0 :         TransferableObjectDescriptor   aObjDesc;
     118             : 
     119           0 :         if( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) &&
     120           0 :             aDataHelper.GetInputStream( nFormatId, xStm ) )
     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* pSrcDoc = xDocShRef->GetDocument();
     136           0 :                     SCTAB nSrcTab = pSrcDoc->GetVisibleTab();
     137           0 :                     if (!pSrcDoc->HasTable(nSrcTab))
     138           0 :                         nSrcTab = 0;
     139             : 
     140           0 :                     ScMarkData aSrcMark;
     141           0 :                     aSrcMark.SelectOneTable( nSrcTab );         // for CopyToClip
     142           0 :                     ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
     143             : 
     144             :                     SCCOL nFirstCol, nLastCol;
     145             :                     SCROW nFirstRow, nLastRow;
     146           0 :                     if ( pSrcDoc->GetDataStart( nSrcTab, nFirstCol, nFirstRow ) )
     147           0 :                         pSrcDoc->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 :                     pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aSrcMark);
     155           0 :                     ScGlobal::SetClipDocName( xDocShRef->GetTitle( SFX_TITLE_FULLNAME ) );
     156             : 
     157           0 :                     SetCursor( nPosX, nPosY );
     158           0 :                     Unmark();
     159             :                     PasteFromClip( IDF_ALL, pClipDoc,
     160             :                                     PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
     161           0 :                                     bAllowDialogs );
     162           0 :                     delete pClipDoc;
     163           0 :                     bRet = true;
     164             :                 }
     165             : 
     166           0 :                 xDocShRef->DoClose();
     167           0 :                 xDocShRef.Clear();
     168             :             }
     169             :             else
     170             :             {
     171           0 :                 OUString aName;
     172           0 :                 uno::Reference < embed::XEmbeddedObject > xObj = GetViewData()->GetViewShell()->GetObjectShell()->
     173           0 :                         GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
     174           0 :                 if ( xObj.is() )
     175             :                 {
     176             :                     // try to get the replacement image from the clipboard
     177           0 :                     Graphic aGraphic;
     178           0 :                     sal_uLong nGrFormat = 0;
     179             : 
     180             :                     // limit the size of the preview metafile to 100000 actions
     181           0 :                     GDIMetaFile aMetafile;
     182           0 :                     if (aDataHelper.GetGDIMetaFile(FORMAT_GDIMETAFILE, aMetafile, 100000))
     183             :                     {
     184           0 :                         nGrFormat = SOT_FORMAT_GDIMETAFILE;
     185           0 :                         aGraphic = aMetafile;
     186             :                     }
     187             : 
     188             :                     // insert replacement image ( if there is one ) into the object helper
     189           0 :                     if ( nGrFormat )
     190             :                     {
     191           0 :                         datatransfer::DataFlavor aDataFlavor;
     192           0 :                         SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
     193           0 :                         PasteObject( aPos, xObj, &aObjDesc.maSize, &aGraphic, aDataFlavor.MimeType, aObjDesc.mnViewAspect );
     194             :                     }
     195             :                     else
     196           0 :                         PasteObject( aPos, xObj, &aObjDesc.maSize );
     197             : 
     198           0 :                     bRet = true;
     199             :                 }
     200             :                 else
     201             :                 {
     202             :                     OSL_FAIL("Error in CreateAndLoad");
     203           0 :                 }
     204             :             }
     205             :         }
     206             :         else
     207             :         {
     208           0 :             if ( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE, aObjDesc ) )
     209             :             {
     210           0 :                 OUString aName;
     211           0 :                 uno::Reference < embed::XEmbeddedObject > xObj;
     212             : 
     213           0 :                 if ( aDataHelper.GetInputStream( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE, xStm )
     214           0 :                   || aDataHelper.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE, xStm ) )
     215             :                 {
     216           0 :                     xObj = GetViewData()->GetDocShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
     217             :                 }
     218             :                 else
     219             :                 {
     220             :                     try
     221             :                     {
     222           0 :                         uno::Reference< embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
     223             :                         uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator =
     224           0 :                             embed::MSOLEObjectSystemCreator::create( ::comphelper::getProcessComponentContext() );
     225             : 
     226           0 :                         embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
     227             :                                                             xTmpStor,
     228             :                                                             OUString( "DummyName" ),
     229           0 :                                                             uno::Sequence< beans::PropertyValue >() );
     230             : 
     231             :                         // TODO/LATER: in future InsertedObjectInfo will be used to get container related information
     232             :                         // for example whether the object should be an iconified one
     233           0 :                         xObj = aInfo.Object;
     234           0 :                         if ( xObj.is() )
     235           0 :                             GetViewData()->GetDocShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
     236             :                     }
     237           0 :                     catch( uno::Exception& )
     238             :                     {}
     239             :                 }
     240             : 
     241           0 :                 if ( xObj.is() )
     242             :                 {
     243             :                     // try to get the replacement image from the clipboard
     244           0 :                     Graphic aGraphic;
     245           0 :                     sal_uLong nGrFormat = 0;
     246             : 
     247             : // (wg. Selection Manager bei Trustet Solaris)
     248             : #ifndef SOLARIS
     249           0 :                     if( aDataHelper.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) )
     250           0 :                         nGrFormat = SOT_FORMATSTR_ID_SVXB;
     251           0 :                     else if( aDataHelper.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
     252           0 :                         nGrFormat = SOT_FORMAT_GDIMETAFILE;
     253           0 :                     else if( aDataHelper.GetGraphic( FORMAT_BITMAP, aGraphic ) )
     254           0 :                         nGrFormat = SOT_FORMAT_BITMAP;
     255             : #endif
     256             : 
     257             :                     // insert replacement image ( if there is one ) into the object helper
     258           0 :                     if ( nGrFormat )
     259             :                     {
     260           0 :                         datatransfer::DataFlavor aDataFlavor;
     261           0 :                         SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
     262           0 :                         PasteObject( aPos, xObj, &aObjDesc.maSize, &aGraphic, aDataFlavor.MimeType, aObjDesc.mnViewAspect );
     263             :                     }
     264             :                     else
     265           0 :                         PasteObject( aPos, xObj, &aObjDesc.maSize );
     266             : 
     267             :                     // let object stay in loaded state after insertion
     268           0 :                     SdrOle2Obj::Unload( xObj, embed::Aspects::MSOLE_CONTENT );
     269           0 :                     bRet = true;
     270             :                 }
     271             :                 else
     272             :                 {
     273             :                     OSL_FAIL("Error creating external OLE object");
     274           0 :                 }
     275             :             }
     276             :             //TODO/LATER: if format is not available, create picture
     277           0 :         }
     278             :     }
     279           0 :     else if ( nFormatId == SOT_FORMATSTR_ID_LINK )      // LINK is also in ScImportExport
     280             :     {
     281           0 :         bRet = PasteLink( rxTransferable );
     282             :     }
     283           0 :     else if ( ScImportExport::IsFormatSupported( nFormatId ) || nFormatId == SOT_FORMAT_RTF )
     284             :     {
     285           0 :         if ( nFormatId == SOT_FORMAT_RTF && aDataHelper.HasFormat( SOT_FORMATSTR_ID_EDITENGINE ) )
     286             :         {
     287             :             //  use EditView's PasteSpecial / Drop
     288           0 :             PasteRTF( nPosX, nPosY, rxTransferable );
     289           0 :             bRet = true;
     290             :         }
     291             :         else
     292             :         {
     293           0 :             ScAddress aCellPos( nPosX, nPosY, GetViewData()->GetTabNo() );
     294           0 :             ScImportExport aObj( GetViewData()->GetDocument(), aCellPos );
     295           0 :             aObj.SetImportBroadcast(true);
     296             : 
     297           0 :             OUString aStr;
     298           0 :             SotStorageStreamRef xStream;
     299           0 :             if ( aDataHelper.GetSotStorageStream( nFormatId, xStream ) && xStream.Is() )
     300             :             {
     301           0 :                 if (nFormatId == SOT_FORMATSTR_ID_HTML)
     302             :                 {
     303             :                     // Launch the text import options dialog.  For now, we do
     304             :                     // this for html pasting only, but in the future it may
     305             :                     // make sense to do it for other data types too.
     306           0 :                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
     307             :                     boost::scoped_ptr<AbstractScTextImportOptionsDlg> pDlg(
     308           0 :                         pFact->CreateScTextImportOptionsDlg(NULL));
     309             : 
     310           0 :                     if (pDlg->Execute() == RET_OK)
     311             :                     {
     312           0 :                         ScAsciiOptions aOptions;
     313           0 :                         aOptions.SetLanguage(pDlg->GetLanguageType());
     314           0 :                         aOptions.SetDetectSpecialNumber(pDlg->IsDateConversionSet());
     315           0 :                         aObj.SetExtOptions(aOptions);
     316             :                     }
     317             :                     else
     318             :                     {
     319             :                         // prevent error dialog for user cancel action
     320           0 :                         bRet = true;
     321           0 :                     }
     322             :                 }
     323           0 :                 if(!bRet)
     324           0 :                     bRet = aObj.ImportStream( *xStream, OUString(), nFormatId );
     325             :                 // mba: clipboard always must contain absolute URLs (could be from alien source)
     326             :             }
     327           0 :             else if (nFormatId == FORMAT_STRING && aDataHelper.GetString( nFormatId, aStr ))
     328             :             {
     329             :                 // Do CSV dialog if more than one line.
     330           0 :                 sal_Int32 nDelim = aStr.indexOf('\n');
     331           0 :                 if (nDelim >= 0 && nDelim != aStr.getLength () - 1)
     332             :                 {
     333           0 :                     ScImportStringStream aStrm( aStr);
     334             :                     ScAbstractDialogFactory* pFact =
     335           0 :                         ScAbstractDialogFactory::Create();
     336             :                     AbstractScImportAsciiDlg *pDlg =
     337             :                         pFact->CreateScImportAsciiDlg( NULL, OUString(), &aStrm,
     338           0 :                                 SC_PASTETEXT);
     339             : 
     340           0 :                     if (pDlg->Execute() == RET_OK)
     341             :                     {
     342           0 :                         ScAsciiOptions aOptions;
     343           0 :                         pDlg->GetOptions( aOptions );
     344           0 :                         pDlg->SaveParameters();
     345           0 :                         aObj.SetExtOptions( aOptions );
     346             : 
     347           0 :                         bRet = aObj.ImportString( aStr, nFormatId );
     348             : 
     349             :                         // TODO: what if (aObj.IsOverflow())
     350             :                         // Content was partially pasted, which can be undone by
     351             :                         // the user though.
     352           0 :                         if (aObj.IsOverflow())
     353           0 :                             bRet = false;
     354             :                     }
     355             :                     else
     356           0 :                         bRet = true;
     357             :                         // Yes, no failure, don't raise a "couldn't paste"
     358             :                         // dialog if user cancelled.
     359           0 :                     delete pDlg;
     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, SFX_CALLMODE_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 :             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, xInputStream );
     501             : 
     502             :             // set everything to right layer:
     503           0 :             sal_uLong 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, (nObjCount > 1) );     // grouped if more than 1 object
     523           0 :             delete pModel;
     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;
     533           0 :         if( aDataHelper.GetInputStream( nFormatId, xStm ) )
     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;
     634           0 :     if ( !aDataHelper.GetSequence( SOT_FORMATSTR_ID_LINK, aSequence ) )
     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           0 : }
     740             : 
     741             : 
     742             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10