LCOV - code coverage report
Current view: top level - sw/source/uibase/dochdl - swdtflvr.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 249 1840 13.5 %
Date: 2015-06-13 12:38:46 Functions: 26 66 39.4 %
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 <config_features.h>
      21             : 
      22             : #include <com/sun/star/embed/XVisualObject.hpp>
      23             : #include <com/sun/star/embed/XTransactedObject.hpp>
      24             : #include <com/sun/star/embed/Aspects.hpp>
      25             : #include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
      26             : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
      27             : #include <com/sun/star/embed/MSOLEObjectSystemCreator.hpp>
      28             : 
      29             : #include <svtools/embedtransfer.hxx>
      30             : #include <svtools/insdlg.hxx>
      31             : #include <unotools/tempfile.hxx>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <comphelper/servicehelper.hxx>
      34             : #include <comphelper/storagehelper.hxx>
      35             : #include <comphelper/string.hxx>
      36             : #include <unotools/ucbstreamhelper.hxx>
      37             : #include <sot/filelist.hxx>
      38             : #include <svx/svxdlg.hxx>
      39             : #include <toolkit/helper/vclunohelper.hxx>
      40             : #include <osl/endian.h>
      41             : #include <sfx2/linkmgr.hxx>
      42             : #include <tools/urlobj.hxx>
      43             : #include <vcl/wrkwin.hxx>
      44             : #include <vcl/layout.hxx>
      45             : #include <vcl/msgbox.hxx>
      46             : #include <sfx2/dispatch.hxx>
      47             : #include <svl/stritem.hxx>
      48             : #include <svtools/imap.hxx>
      49             : #include <sot/storage.hxx>
      50             : #include <vcl/graph.hxx>
      51             : #include <svl/urihelper.hxx>
      52             : #include <svx/svdmodel.hxx>
      53             : #include <svx/xexch.hxx>
      54             : #include <svx/xmlexchg.hxx>
      55             : #include <svx/dbaexchange.hxx>
      56             : #include <svx/clipfmtitem.hxx>
      57             : #include <sfx2/mieclip.hxx>
      58             : #include <svx/svdetc.hxx>
      59             : #include <svx/xoutbmp.hxx>
      60             : #include <svl/urlbmk.hxx>
      61             : #include <svtools/htmlout.hxx>
      62             : #include <svx/hlnkitem.hxx>
      63             : #include <svtools/inetimg.hxx>
      64             : #include <editeng/paperinf.hxx>
      65             : #include <svx/fmview.hxx>
      66             : #include <editeng/scripttypeitem.hxx>
      67             : #include <sfx2/docfilt.hxx>
      68             : #include <svtools/imapobj.hxx>
      69             : #include <sfx2/docfile.hxx>
      70             : #include <unotools/transliterationwrapper.hxx>
      71             : #include <unotools/streamwrap.hxx>
      72             : #include <vcl/graphicfilter.hxx>
      73             : 
      74             : #include <svx/unomodel.hxx>
      75             : #include <fmturl.hxx>
      76             : #include <fmtinfmt.hxx>
      77             : #include <fmtfsize.hxx>
      78             : #include <swdtflvr.hxx>
      79             : #include <shellio.hxx>
      80             : #include <ddefld.hxx>
      81             : #include <doc.hxx>
      82             : #include <IDocumentUndoRedo.hxx>
      83             : #include <IDocumentSettingAccess.hxx>
      84             : #include <IDocumentDeviceAccess.hxx>
      85             : #include <IDocumentDrawModelAccess.hxx>
      86             : #include <IDocumentFieldsAccess.hxx>
      87             : #include <IDocumentState.hxx>
      88             : #include <pagedesc.hxx>
      89             : #include <IMark.hxx>
      90             : #include <docary.hxx>
      91             : #include <section.hxx>
      92             : #include <ndtxt.hxx>
      93             : #include <edtwin.hxx>
      94             : #include <navicont.hxx>
      95             : #include <swcont.hxx>
      96             : #include <wrtsh.hxx>
      97             : #include <swmodule.hxx>
      98             : #include <view.hxx>
      99             : #include <docsh.hxx>
     100             : #include <wdocsh.hxx>
     101             : #include <fldbas.hxx>
     102             : #include <swundo.hxx>
     103             : #include <pam.hxx>
     104             : #include <ndole.hxx>
     105             : #include <swwait.hxx>
     106             : #include <viewopt.hxx>
     107             : #include <swerror.h>
     108             : #include <SwCapObjType.hxx>
     109             : #include <cmdid.h>
     110             : #include <dochdl.hrc>
     111             : #include <comcore.hrc>
     112             : #include <sot/stg.hxx>
     113             : #include <svx/svditer.hxx>
     114             : #include <editeng/eeitem.hxx>
     115             : #include <editeng/fhgtitem.hxx>
     116             : #include <svx/svdpage.hxx>
     117             : #include <avmedia/mediawindow.hxx>
     118             : #include <swcrsr.hxx>
     119             : #include <SwRewriter.hxx>
     120             : #include <globals.hrc>
     121             : #include <app.hrc>
     122             : #include <osl/mutex.hxx>
     123             : #include <vcl/svapp.hxx>
     124             : #include <swserv.hxx>
     125             : #include <calbck.hxx>
     126             : 
     127             : #include <vcl/GraphicNativeTransform.hxx>
     128             : #include <vcl/GraphicNativeMetadata.hxx>
     129             : 
     130             : #include <boost/scoped_array.hpp>
     131             : #include <boost/scoped_ptr.hpp>
     132             : 
     133             : extern bool g_bFrmDrag;
     134             : extern bool g_bDDINetAttr;
     135             : extern bool g_bExecuteDrag;
     136             : 
     137             : #define OLESIZE 11905 - 2 * lMinBorder, 6 * MM50
     138             : 
     139             : #define SWTRANSFER_OBJECTTYPE_DRAWMODEL         static_cast<SotClipboardFormatId>(0x00000001)
     140             : #define SWTRANSFER_OBJECTTYPE_HTML              static_cast<SotClipboardFormatId>(0x00000002)
     141             : #define SWTRANSFER_OBJECTTYPE_RTF               static_cast<SotClipboardFormatId>(0x00000004)
     142             : #define SWTRANSFER_OBJECTTYPE_STRING            static_cast<SotClipboardFormatId>(0x00000008)
     143             : #define SWTRANSFER_OBJECTTYPE_SWOLE             static_cast<SotClipboardFormatId>(0x00000010)
     144             : #define SWTRANSFER_OBJECTTYPE_DDE               static_cast<SotClipboardFormatId>(0x00000020)
     145             : 
     146             : using namespace ::svx;
     147             : using namespace ::com::sun::star;
     148             : using namespace ::com::sun::star::uno;
     149             : using namespace ::com::sun::star::datatransfer;
     150             : using namespace nsTransferBufferType;
     151             : 
     152             : #define DDE_TXT_ENCODING    osl_getThreadTextEncoding()
     153             : 
     154             : class SwTrnsfrDdeLink : public ::sfx2::SvBaseLink
     155             : {
     156             :     OUString sName;
     157             :     ::sfx2::SvLinkSourceRef refObj;
     158             :     SwTransferable& rTrnsfr;
     159             :     SwDocShell* pDocShell;
     160             :     sal_uLong nOldTimeOut;
     161             :     bool bDelBookmrk : 1;
     162             :     bool bInDisconnect : 1;
     163             : 
     164             :     bool FindDocShell();
     165             : 
     166             :     using sfx2::SvBaseLink::Disconnect;
     167             : 
     168             : protected:
     169             :     virtual ~SwTrnsfrDdeLink();
     170             : 
     171             : public:
     172             :     SwTrnsfrDdeLink( SwTransferable& rTrans, SwWrtShell& rSh );
     173             : 
     174             :     virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
     175             :         const OUString& rMimeType, const ::com::sun::star::uno::Any & rValue ) SAL_OVERRIDE;
     176             :     virtual void Closed() SAL_OVERRIDE;
     177             : 
     178             :     bool WriteData( SvStream& rStrm );
     179             : 
     180             :     void Disconnect( bool bRemoveDataAdvise );
     181             : };
     182             : 
     183             : // helper class for Action and Undo enclosing
     184             : class SwTrnsfrActionAndUndo
     185             : {
     186             :     SwWrtShell *pSh;
     187             :     SwUndoId eUndoId;
     188             : public:
     189           1 :     SwTrnsfrActionAndUndo( SwWrtShell *pS, SwUndoId nId,
     190             :                            const SwRewriter * pRewriter = 0,
     191             :                            bool bDelSel = false)
     192           1 :         : pSh( pS ), eUndoId( nId )
     193             :     {
     194           1 :         pSh->StartUndo( eUndoId, pRewriter );
     195           1 :         if( bDelSel )
     196           0 :             pSh->DelRight();
     197           1 :         pSh->StartAllAction();
     198           1 :     }
     199           1 :     ~SwTrnsfrActionAndUndo()
     200             :     {
     201           1 :         pSh->EndUndo();
     202           1 :         pSh->EndAllAction();
     203           1 :     }
     204             : };
     205             : 
     206          51 : SwTransferable::SwTransferable( SwWrtShell& rSh )
     207             :     : pWrtShell( &rSh ),
     208             :     pCreatorView( 0 ),
     209             :     pClpDocFac( 0 ),
     210             :     pClpGraphic( 0 ),
     211             :     pClpBitmap( 0 ),
     212             :     pOrigGrf( 0 ),
     213             :     pBkmk( 0 ),
     214             :     pImageMap( 0 ),
     215             :     pTargetURL( 0 ),
     216          51 :     eBufferType( TRNSFR_NONE )
     217             : {
     218          51 :     rSh.GetView().AddTransferable(*this);
     219          51 :     SwDocShell* pDShell = rSh.GetDoc()->GetDocShell();
     220          51 :     if( pDShell )
     221             :     {
     222          51 :         pDShell->FillTransferableObjectDescriptor( aObjDesc );
     223          51 :         if( pDShell->GetMedium() )
     224             :         {
     225          51 :             const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject();
     226         102 :             aObjDesc.maDisplayName = URIHelper::removePassword(
     227             :                                 rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
     228             :                                 INetURLObject::WAS_ENCODED,
     229          51 :                                 INetURLObject::DECODE_UNAMBIGUOUS );
     230             :         }
     231             : 
     232          51 :         PrepareOLE( aObjDesc );
     233             :     }
     234          51 : }
     235             : 
     236         150 : SwTransferable::~SwTransferable()
     237             : {
     238          50 :     Application::GetSolarMutex().acquire();
     239             : 
     240             :     // the DDELink still needs the WrtShell!
     241          50 :     if( refDdeLink.Is() )
     242             :     {
     243           0 :         static_cast<SwTrnsfrDdeLink*>(&refDdeLink)->Disconnect( true );
     244           0 :         refDdeLink.Clear();
     245             :     }
     246             : 
     247          50 :     pWrtShell = 0;
     248             : 
     249             :     // release reference to the document so that aDocShellRef will delete
     250             :     // it (if aDocShellRef is set). Otherwise, the OLE nodes keep references
     251             :     // to their sub-storage when the storage is already dead.
     252          50 :     delete pClpDocFac;
     253             : 
     254             :     // first close, then the Ref. can be cleared as well, so that
     255             :     // the DocShell really gets deleted!
     256          50 :     if( aDocShellRef.Is() )
     257             :     {
     258           0 :         SfxObjectShell * pObj = aDocShellRef;
     259           0 :         SwDocShell* pDocSh = static_cast<SwDocShell*>(pObj);
     260           0 :         pDocSh->DoClose();
     261             :     }
     262          50 :     aDocShellRef.Clear();
     263             : 
     264          50 :     SwModule* pMod = SW_MOD();
     265          50 :     if(pMod)
     266             :     {
     267          50 :         if ( pMod->pDragDrop == this )
     268           0 :             pMod->pDragDrop = 0;
     269          50 :         else if ( pMod->pXSelection == this )
     270           0 :             pMod->pXSelection = 0;
     271             :     }
     272             : 
     273          50 :     delete pClpGraphic;
     274          50 :     delete pClpBitmap;
     275          50 :     delete pImageMap;
     276          50 :     delete pTargetURL;
     277          50 :     delete pBkmk;
     278             : 
     279          50 :     eBufferType = TRNSFR_NONE;
     280             : 
     281          50 :     Application::GetSolarMutex().release();
     282         100 : }
     283             : 
     284           1 : static SwDoc * lcl_GetDoc(SwDocFac & rDocFac)
     285             : {
     286           1 :     SwDoc *const pDoc = rDocFac.GetDoc();
     287             :     OSL_ENSURE( pDoc, "Document not found" );
     288           1 :     if (pDoc)
     289             :     {
     290           1 :         pDoc->SetClipBoard( true );
     291             :     }
     292           1 :     return pDoc;
     293             : }
     294             : 
     295          50 : void SwTransferable::ObjectReleased()
     296             : {
     297          50 :     SwModule *pMod = SW_MOD();
     298          50 :     if( this == pMod->pDragDrop )
     299           0 :         pMod->pDragDrop = 0;
     300          50 :     else if( this == pMod->pXSelection )
     301          46 :         pMod->pXSelection = 0;
     302          50 : }
     303             : 
     304           0 : void SwTransferable::AddSupportedFormats()
     305             : {
     306             :     // only need if we are the current XSelection Object
     307           0 :     SwModule *pMod = SW_MOD();
     308           0 :     if( this == pMod->pXSelection )
     309             :     {
     310           0 :         SetDataForDragAndDrop( Point( 0,0) );
     311             :     }
     312           0 : }
     313             : 
     314         124 : void SwTransferable::InitOle( SfxObjectShell* pDoc, SwDoc& rDoc )
     315             : {
     316             :     //set OleVisArea. Upper left corner of the page and size of
     317             :     //RealSize in Twips.
     318         124 :     const Size aSz( OLESIZE );
     319         124 :     SwRect aVis( Point( DOCUMENTBORDER, DOCUMENTBORDER ), aSz );
     320         124 :     pDoc->SetVisArea( aVis.SVRect() );
     321         124 :     rDoc.getIDocumentSettingAccess().set(DocumentSettingId::BROWSE_MODE, true );
     322         124 : }
     323             : 
     324           0 : uno::Reference < embed::XEmbeddedObject > SwTransferable::FindOLEObj( sal_Int64& nAspect ) const
     325             : {
     326           0 :     uno::Reference < embed::XEmbeddedObject > xObj;
     327           0 :     if( pClpDocFac )
     328             :     {
     329           0 :         SwIterator<SwContentNode,SwFormatColl> aIter( *pClpDocFac->GetDoc()->GetDfltGrfFormatColl() );
     330           0 :         for( SwContentNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
     331           0 :             if( ND_OLENODE == pNd->GetNodeType() )
     332             :             {
     333           0 :                 xObj = static_cast<SwOLENode*>(pNd)->GetOLEObj().GetOleRef();
     334           0 :                 nAspect = static_cast<SwOLENode*>(pNd)->GetAspect();
     335           0 :                 break;
     336           0 :             }
     337             :     }
     338           0 :     return xObj;
     339             : }
     340             : 
     341           0 : const Graphic* SwTransferable::FindOLEReplacementGraphic() const
     342             : {
     343           0 :     if( pClpDocFac )
     344             :     {
     345           0 :         SwIterator<SwContentNode,SwFormatColl> aIter( *pClpDocFac->GetDoc()->GetDfltGrfFormatColl() );
     346           0 :         for( SwContentNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
     347           0 :             if( ND_OLENODE == pNd->GetNodeType() )
     348             :             {
     349           0 :                 return static_cast<SwOLENode*>(pNd)->GetGraphic();
     350           0 :             }
     351             :     }
     352             : 
     353           0 :     return NULL;
     354             : }
     355             : 
     356           0 : void SwTransferable::RemoveDDELinkFormat( const vcl::Window& rWin )
     357             : {
     358           0 :     RemoveFormat( SotClipboardFormatId::LINK );
     359           0 :     CopyToClipboard( const_cast<vcl::Window*>(&rWin) );
     360           0 : }
     361             : 
     362             : namespace
     363             : {
     364             :     //Resolves: fdo#40717 surely when we create a clipboard document we should
     365             :     //overwrite the clipboard documents styles and settings with that of the
     366             :     //source, so that we can WYSIWYG paste. If we want that the destinations
     367             :     //styles are used over the source styles, that's a matter of the
     368             :     //destination paste code to handle, not the source paste code.
     369           1 :     void lclOverWriteDoc(SwWrtShell &rSrcWrtShell, SwDoc &rDest)
     370             :     {
     371           1 :         const SwDoc &rSrc = *rSrcWrtShell.GetDoc();
     372             : 
     373           1 :         rDest.ReplaceCompatibilityOptions(rSrc);
     374           1 :         rDest.ReplaceDefaults(rSrc);
     375             : 
     376             :         //It would probably make most sense here to only insert the styles used
     377             :         //by the selection, e.g. apply SwDoc::IsUsed on styles ?
     378           1 :         rDest.ReplaceStyles(rSrc, false);
     379             : 
     380           1 :         rSrcWrtShell.Copy(&rDest);
     381           1 :     }
     382             : 
     383           0 :     void lclCheckAndPerformRotation(Graphic& aGraphic)
     384             :     {
     385           0 :         GraphicNativeMetadata aMetadata;
     386           0 :         if ( aMetadata.read(aGraphic) )
     387             :         {
     388           0 :             sal_uInt16 aRotation = aMetadata.getRotation();
     389           0 :             if (aRotation != 0)
     390             :             {
     391             :                 ScopedVclPtrInstance< MessageDialog > aQueryBox(
     392             :                         nullptr, "QueryRotateIntoStandardOrientationDialog",
     393           0 :                         "modules/swriter/ui/queryrotateintostandarddialog.ui");
     394           0 :                 if (aQueryBox->Execute() == RET_YES)
     395             :                 {
     396           0 :                     GraphicNativeTransform aTransform( aGraphic );
     397           0 :                     aTransform.rotate( aRotation );
     398           0 :                 }
     399             :             }
     400           0 :         }
     401           0 :     }
     402             : }
     403             : 
     404           0 : bool SwTransferable::GetData( const DataFlavor& rFlavor, const OUString& rDestDoc )
     405             : {
     406           0 :     SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor );
     407             : 
     408             :     // we can only fullfil the request if
     409             :     // 1) we have data for this format
     410             :     // 2) we have either a clipboard document (pClpDocFac), or
     411             :     //    we have a SwWrtShell (so we can generate a new clipboard document)
     412           0 :     if( !HasFormat( nFormat ) || ( pClpDocFac == NULL && pWrtShell == NULL ) )
     413           0 :         return false;
     414             : 
     415           0 :     if( !pClpDocFac )
     416             :     {
     417           0 :         SelectionType nSelectionType = pWrtShell->GetSelectionType();
     418             : 
     419             :         // when pending we will not get the correct type, but nsSelectionType::SEL_TXT
     420             :         // as fallback. This *happens* durning D&D, so we need to check if we are in
     421             :         // the fallback and just try to get a graphic
     422           0 :         const bool bPending(pWrtShell->BasicActionPend());
     423             : 
     424             :         // SEL_GRF is from ContentType of editsh
     425           0 :         if(bPending || ((nsSelectionType::SEL_GRF | nsSelectionType::SEL_DRW_FORM) & nSelectionType))
     426             :         {
     427           0 :             pClpGraphic = new Graphic;
     428           0 :             if( !pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *pClpGraphic ))
     429           0 :                 pOrigGrf = pClpGraphic;
     430           0 :             pClpBitmap = new Graphic;
     431           0 :             if( !pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *pClpBitmap ))
     432           0 :                 pOrigGrf = pClpBitmap;
     433             : 
     434             :             // is it an URL-Button ?
     435           0 :             OUString sURL;
     436           0 :             OUString sDesc;
     437           0 :             if( pWrtShell->GetURLFromButton( sURL, sDesc ) )
     438             :             {
     439           0 :                 pBkmk = new INetBookmark( sURL, sDesc );
     440           0 :                 eBufferType = TRNSFR_INETFLD;
     441           0 :             }
     442             :         }
     443             : 
     444           0 :         pClpDocFac = new SwDocFac;
     445           0 :         SwDoc *const pTmpDoc = lcl_GetDoc(*pClpDocFac);
     446             : 
     447           0 :         pTmpDoc->getIDocumentFieldsAccess().LockExpFields();     // never update fields - leave text as it is
     448           0 :         lclOverWriteDoc(*pWrtShell, *pTmpDoc);
     449             : 
     450             :         // in CORE a new one was created (OLE-Objekte copied!)
     451           0 :         aDocShellRef = pTmpDoc->GetTmpDocShell();
     452           0 :         if( aDocShellRef.Is() )
     453           0 :             SwTransferable::InitOle( aDocShellRef, *pTmpDoc );
     454           0 :         pTmpDoc->SetTmpDocShell( nullptr );
     455             : 
     456           0 :         if( nSelectionType & nsSelectionType::SEL_TXT && !pWrtShell->HasMark() )
     457             :         {
     458           0 :             SwContentAtPos aContentAtPos( SwContentAtPos::SW_INETATTR );
     459             : 
     460           0 :             Point aPos( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY());
     461             : 
     462           0 :             bool bSelect = g_bExecuteDrag &&
     463           0 :                             pWrtShell->GetView().GetDocShell() &&
     464           0 :                             !pWrtShell->GetView().GetDocShell()->IsReadOnly();
     465           0 :             if( pWrtShell->GetContentAtPos( aPos, aContentAtPos, bSelect ) )
     466             :             {
     467             :                 pBkmk = new INetBookmark(
     468           0 :                         static_cast<const SwFormatINetFormat*>(aContentAtPos.aFnd.pAttr)->GetValue(),
     469           0 :                         aContentAtPos.sStr );
     470           0 :                 eBufferType = TRNSFR_INETFLD;
     471           0 :                 if( bSelect )
     472           0 :                     pWrtShell->SelectTextAttr( RES_TXTATR_INETFMT );
     473           0 :             }
     474             :         }
     475           0 :         if( pWrtShell->IsFrmSelected() )
     476             :         {
     477           0 :              SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL );
     478           0 :             pWrtShell->GetFlyFrmAttr( aSet );
     479           0 :             const SwFormatURL& rURL = static_cast<const SwFormatURL&>(aSet.Get( RES_URL ));
     480           0 :             if( rURL.GetMap() )
     481           0 :                 pImageMap = new ImageMap( *rURL.GetMap() );
     482           0 :             else if( !rURL.GetURL().isEmpty() )
     483             :                 pTargetURL = new INetImage( aEmptyOUStr, rURL.GetURL(),
     484             :                                             rURL.GetTargetFrameName(),
     485           0 :                                             aEmptyOUStr, Size() );
     486             :         }
     487             :     }
     488             : 
     489           0 :     bool bOK = false;
     490           0 :     if( TRNSFR_OLE == eBufferType )
     491             :     {
     492             :         //TODO/MBA: testing - is this the "single OLE object" case?!
     493             :         // get OLE-Object from ClipDoc and get the data from that.
     494           0 :         sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; // will be set in the next statement
     495           0 :         uno::Reference < embed::XEmbeddedObject > xObj = FindOLEObj( nAspect );
     496           0 :         const Graphic* pOLEGraph = FindOLEReplacementGraphic();
     497           0 :         if( xObj.is() )
     498             :         {
     499           0 :             TransferableDataHelper aD( new SvEmbedTransferHelper( xObj, pOLEGraph, nAspect ) );
     500           0 :             uno::Any aAny = aD.GetAny(rFlavor, rDestDoc);
     501           0 :             if( aAny.hasValue() )
     502           0 :                 bOK = SetAny( aAny, rFlavor );
     503             :         }
     504             : 
     505             :         // the following solution will be used in the case when the object can not generate the image
     506             :         // TODO/LATER: in future the transferhelper must probably be created based on object and the replacement stream
     507             :         // TODO: Block not required now, SvEmbedTransferHelper should be able to handle GDIMetaFile format
     508           0 :         if ( nFormat == SotClipboardFormatId::GDIMETAFILE )
     509             :         {
     510           0 :             pOLEGraph = FindOLEReplacementGraphic();
     511           0 :             if ( pOLEGraph )
     512           0 :                 bOK = SetGDIMetaFile( pOLEGraph->GetGDIMetaFile(), rFlavor );
     513           0 :         }
     514             :     }
     515             :     else
     516             :     {
     517           0 :         switch( nFormat )
     518             :         {
     519             :         case SotClipboardFormatId::LINK:
     520           0 :             if( refDdeLink.Is() )
     521           0 :                 bOK = SetObject( &refDdeLink, SWTRANSFER_OBJECTTYPE_DDE, rFlavor );
     522           0 :             break;
     523             : 
     524             :         case SotClipboardFormatId::OBJECTDESCRIPTOR:
     525             :         case SotClipboardFormatId::LINKSRCDESCRIPTOR:
     526           0 :             bOK = SetTransferableObjectDescriptor( aObjDesc, rFlavor );
     527           0 :             break;
     528             : 
     529             :         case SotClipboardFormatId::DRAWING:
     530             :             {
     531           0 :                 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
     532           0 :                 bOK = SetObject( pDoc->getIDocumentDrawModelAccess().GetDrawModel(),
     533           0 :                                 SWTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
     534             :             }
     535           0 :             break;
     536             : 
     537             :         case SotClipboardFormatId::STRING:
     538             :         {
     539           0 :             SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
     540           0 :             bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_STRING, rFlavor );
     541             :         }
     542           0 :         break;
     543             :         case SotClipboardFormatId::RTF:
     544             :         {
     545           0 :             SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
     546           0 :             bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_RTF, rFlavor );
     547             :         }
     548           0 :             break;
     549             : 
     550             :         case SotClipboardFormatId::HTML:
     551             :         {
     552           0 :             SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
     553           0 :             bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_HTML, rFlavor );
     554             :         }
     555           0 :             break;
     556             : 
     557             :         case SotClipboardFormatId::SVXB:
     558           0 :             if( eBufferType & TRNSFR_GRAPHIC && pOrigGrf )
     559           0 :                 bOK = SetGraphic( *pOrigGrf, rFlavor );
     560           0 :             break;
     561             : 
     562             :         case SotClipboardFormatId::GDIMETAFILE:
     563           0 :             if( eBufferType & TRNSFR_GRAPHIC )
     564           0 :                 bOK = SetGDIMetaFile( pClpGraphic->GetGDIMetaFile(), rFlavor );
     565           0 :             break;
     566             :         case SotClipboardFormatId::BITMAP:
     567             :         case SotClipboardFormatId::PNG:
     568             :             // Neither pClpBitmap nor pClpGraphic are necessarily set
     569           0 :             if( (eBufferType & TRNSFR_GRAPHIC) && (pClpBitmap != 0 || pClpGraphic != 0))
     570           0 :                 bOK = SetBitmapEx( (pClpBitmap ? pClpBitmap : pClpGraphic)->GetBitmapEx(), rFlavor );
     571           0 :             break;
     572             : 
     573             :         case SotClipboardFormatId::SVIM:
     574           0 :             if( pImageMap )
     575           0 :                 bOK = SetImageMap( *pImageMap, rFlavor );
     576           0 :             break;
     577             : 
     578             :         case SotClipboardFormatId::INET_IMAGE:
     579           0 :             if( pTargetURL )
     580           0 :                 bOK = SetINetImage( *pTargetURL, rFlavor );
     581           0 :             break;
     582             : 
     583             :         case SotClipboardFormatId::SOLK:
     584             :         case SotClipboardFormatId::NETSCAPE_BOOKMARK:
     585             :         case SotClipboardFormatId::FILEGRPDESCRIPTOR:
     586             :         case SotClipboardFormatId::FILECONTENT:
     587             :         case SotClipboardFormatId::UNIFORMRESOURCELOCATOR:
     588             :         case SotClipboardFormatId::SIMPLE_FILE:
     589           0 :             if( (TRNSFR_INETFLD & eBufferType) && pBkmk )
     590           0 :                 bOK = SetINetBookmark( *pBkmk, rFlavor );
     591           0 :             break;
     592             : 
     593             :         case SotClipboardFormatId::EMBED_SOURCE:
     594           0 :             if( !aDocShellRef.Is() )
     595             :             {
     596           0 :                 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
     597             :                 SwDocShell* pNewDocSh = new SwDocShell( pDoc,
     598           0 :                                          SfxObjectCreateMode::EMBEDDED );
     599           0 :                 aDocShellRef = pNewDocSh;
     600           0 :                 aDocShellRef->DoInitNew( NULL );
     601           0 :                 SwTransferable::InitOle( aDocShellRef, *pDoc );
     602             :             }
     603           0 :             bOK = SetObject( &aDocShellRef, SWTRANSFER_OBJECTTYPE_SWOLE,
     604           0 :                             rFlavor );
     605           0 :             break;
     606           0 :          default: break;
     607             :         }
     608             :     }
     609           0 :     return bOK;
     610             : }
     611             : 
     612           0 : bool SwTransferable::WriteObject( tools::SvRef<SotStorageStream>& xStream,
     613             :                                     void* pObject, SotClipboardFormatId nObjectType,
     614             :                                     const DataFlavor& /*rFlavor*/ )
     615             : {
     616           0 :     bool bRet = false;
     617           0 :     WriterRef xWrt;
     618             : 
     619           0 :     switch( nObjectType )
     620             :     {
     621             :     case SWTRANSFER_OBJECTTYPE_DRAWMODEL:
     622             :         {
     623             :             // don't change the sequence of commands
     624           0 :             SdrModel *pModel = static_cast<SdrModel*>(pObject);
     625           0 :             xStream->SetBufferSize( 16348 );
     626             : 
     627             :             // for the changed pool defaults from drawing layer pool set those
     628             :             // attributes as hard attributes to preserve them for saving
     629           0 :             const SfxItemPool& rItemPool = pModel->GetItemPool();
     630           0 :             const SvxFontHeightItem& rDefaultFontHeight = static_cast<const SvxFontHeightItem&>(rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT));
     631             : 
     632             :             // SW should have no MasterPages
     633             :             OSL_ENSURE(0L == pModel->GetMasterPageCount(), "SW with MasterPages (!)");
     634             : 
     635           0 :             for(sal_uInt16 a(0); a < pModel->GetPageCount(); a++)
     636             :             {
     637           0 :                 const SdrPage* pPage = pModel->GetPage(a);
     638           0 :                 SdrObjListIter aIter(*pPage, IM_DEEPNOGROUPS);
     639             : 
     640           0 :                 while(aIter.IsMore())
     641             :                 {
     642           0 :                     SdrObject* pObj = aIter.Next();
     643           0 :                     const SvxFontHeightItem& rItem = static_cast<const SvxFontHeightItem&>(pObj->GetMergedItem(EE_CHAR_FONTHEIGHT));
     644             : 
     645           0 :                     if(rItem.GetHeight() == rDefaultFontHeight.GetHeight())
     646             :                     {
     647           0 :                         pObj->SetMergedItem(rDefaultFontHeight);
     648             :                     }
     649             :                 }
     650           0 :             }
     651             : 
     652             :             {
     653           0 :                 uno::Reference<io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *xStream ) );
     654           0 :                 if( SvxDrawingLayerExport( pModel, xDocOut ) )
     655           0 :                     xStream->Commit();
     656             :             }
     657             : 
     658           0 :             bRet = ERRCODE_NONE == xStream->GetError();
     659             :         }
     660           0 :         break;
     661             : 
     662             :     case SWTRANSFER_OBJECTTYPE_SWOLE:
     663             :         {
     664           0 :             SfxObjectShell*   pEmbObj = static_cast<SfxObjectShell*>(pObject);
     665             :             try
     666             :             {
     667           0 :                 ::utl::TempFile     aTempFile;
     668           0 :                 aTempFile.EnableKillingFile();
     669             :                 uno::Reference< embed::XStorage > xWorkStore =
     670           0 :                     ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
     671             : 
     672             :                 // write document storage
     673           0 :                 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false );
     674             :                 // mba: no BaseURL for clipboard
     675           0 :                 SfxMedium aMedium( xWorkStore, OUString() );
     676           0 :                 bRet = pEmbObj->DoSaveObjectAs( aMedium, false );
     677           0 :                 pEmbObj->DoSaveCompleted();
     678             : 
     679           0 :                 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
     680           0 :                 if ( xTransact.is() )
     681           0 :                     xTransact->commit();
     682             : 
     683           0 :                 boost::scoped_ptr<SvStream> pSrcStm(::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ ));
     684           0 :                 if( pSrcStm )
     685             :                 {
     686           0 :                     xStream->SetBufferSize( 0xff00 );
     687           0 :                     xStream->WriteStream( *pSrcStm );
     688           0 :                     pSrcStm.reset();
     689             :                 }
     690             : 
     691           0 :                 bRet = true;
     692             : 
     693           0 :                 xWorkStore->dispose();
     694           0 :                 xWorkStore = uno::Reference < embed::XStorage >();
     695           0 :                 xStream->Commit();
     696             :             }
     697           0 :             catch (const uno::Exception&)
     698             :             {
     699             :             }
     700             : 
     701           0 :             bRet = ( xStream->GetError() == ERRCODE_NONE );
     702             :         }
     703           0 :         break;
     704             : 
     705             :     case SWTRANSFER_OBJECTTYPE_DDE:
     706             :         {
     707           0 :             xStream->SetBufferSize( 1024 );
     708           0 :             SwTrnsfrDdeLink* pDdeLnk = static_cast<SwTrnsfrDdeLink*>(pObject);
     709           0 :             if( pDdeLnk->WriteData( *xStream ) )
     710             :             {
     711           0 :                 xStream->Commit();
     712           0 :                 bRet = ERRCODE_NONE == xStream->GetError();
     713             :             }
     714             :         }
     715           0 :         break;
     716             : 
     717             :     case SWTRANSFER_OBJECTTYPE_HTML:
     718           0 :         GetHTMLWriter( aEmptyOUStr, OUString(), xWrt );
     719           0 :         break;
     720             : 
     721             :     case SWTRANSFER_OBJECTTYPE_RTF:
     722           0 :         GetRTFWriter( aEmptyOUStr, OUString(), xWrt );
     723           0 :         break;
     724             : 
     725             :     case SWTRANSFER_OBJECTTYPE_STRING:
     726           0 :         GetASCWriter( aEmptyOUStr, OUString(), xWrt );
     727           0 :         if( xWrt.Is() )
     728             :         {
     729           0 :             SwAsciiOptions aAOpt;
     730           0 :             aAOpt.SetCharSet( RTL_TEXTENCODING_UTF8 );
     731           0 :             xWrt->SetAsciiOptions( aAOpt );
     732             : 
     733             :             // no start char for clipboard
     734           0 :             xWrt->bUCS2_WithStartChar = false;
     735             :         }
     736           0 :         break;
     737           0 :     default: break;
     738             :     }
     739             : 
     740           0 :     if( xWrt.Is() )
     741             :     {
     742           0 :         SwDoc* pDoc = static_cast<SwDoc*>(pObject);
     743           0 :         xWrt->bWriteClipboardDoc = true;
     744           0 :         xWrt->bWriteOnlyFirstTable = 0 != (TRNSFR_TABELLE & eBufferType);
     745           0 :         xWrt->SetShowProgress( false );
     746             : 
     747             : #if defined(DEBUGPASTE)
     748             :         SvFileStream aPasteDebug(OUString(
     749             :             "PASTEBUFFER.debug"), StreamMode::WRITE|StreamMode::TRUNC);
     750             :         SwWriter aDbgWrt( aPasteDebug, *pDoc );
     751             :         aDbgWrt.Write( xWrt );
     752             : #endif
     753             : 
     754           0 :         SwWriter aWrt( *xStream, *pDoc );
     755           0 :         if( !IsError( aWrt.Write( xWrt )) )
     756             :         {
     757           0 :             xStream->WriteChar( '\0' );               // terminate with a zero
     758           0 :             xStream->Commit();
     759           0 :             bRet = true;
     760           0 :         }
     761             :     }
     762             : 
     763           0 :     return bRet;
     764             : }
     765             : 
     766           0 : int SwTransferable::Cut()
     767             : {
     768           0 :     int nRet = Copy( true );
     769           0 :     if( nRet )
     770           0 :         DeleteSelection();
     771           0 :     return nRet;
     772             : }
     773             : 
     774           0 : void SwTransferable::DeleteSelection()
     775             : {
     776           0 :     if(!pWrtShell)
     777           0 :         return;
     778             :     // ask for type of selection before action-bracketing
     779           0 :     const int nSelection = pWrtShell->GetSelectionType();
     780           0 :     pWrtShell->StartUndo( UNDO_DELETE );
     781           0 :     if( ( nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL ) & nSelection )
     782           0 :         pWrtShell->IntelligentCut( nSelection );
     783           0 :     pWrtShell->DelRight();
     784           0 :     pWrtShell->EndUndo( UNDO_DELETE );
     785             : }
     786             : 
     787           1 : int SwTransferable::PrepareForCopy( bool bIsCut )
     788             : {
     789           1 :     int nRet = 1;
     790           1 :     if(!pWrtShell)
     791           0 :         return 0;
     792             : 
     793           1 :     OUString sGrfNm;
     794           1 :     const int nSelection = pWrtShell->GetSelectionType();
     795           1 :     if( nSelection == nsSelectionType::SEL_GRF )
     796             :     {
     797           0 :         pClpGraphic = new Graphic;
     798           0 :         if( !pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *pClpGraphic ))
     799           0 :             pOrigGrf = pClpGraphic;
     800           0 :         pClpBitmap = new Graphic;
     801           0 :         if( !pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *pClpBitmap ))
     802           0 :             pOrigGrf = pClpBitmap;
     803             : 
     804           0 :         pClpDocFac = new SwDocFac;
     805           0 :         SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
     806           0 :         pWrtShell->Copy( pDoc );
     807             : 
     808           0 :         if (pOrigGrf && !pOrigGrf->GetBitmap().IsEmpty())
     809           0 :           AddFormat( SotClipboardFormatId::SVXB );
     810             : 
     811           0 :         PrepareOLE( aObjDesc );
     812           0 :         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
     813             : 
     814           0 :         const Graphic* pGrf = pWrtShell->GetGraphic();
     815           0 :         if( pGrf && pGrf->IsSupportedGraphic() )
     816             :         {
     817           0 :             AddFormat( SotClipboardFormatId::GDIMETAFILE );
     818           0 :             AddFormat( SotClipboardFormatId::PNG );
     819           0 :             AddFormat( SotClipboardFormatId::BITMAP );
     820             :         }
     821           0 :         eBufferType = TRNSFR_GRAPHIC;
     822           0 :         pWrtShell->GetGrfNms( &sGrfNm, 0 );
     823             :     }
     824           1 :     else if ( nSelection == nsSelectionType::SEL_OLE )
     825             :     {
     826           0 :         pClpDocFac = new SwDocFac;
     827           0 :         SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
     828           0 :         aDocShellRef = new SwDocShell( pDoc, SfxObjectCreateMode::EMBEDDED);
     829           0 :         aDocShellRef->DoInitNew( NULL );
     830           0 :         pWrtShell->Copy( pDoc );
     831             : 
     832           0 :         AddFormat( SotClipboardFormatId::EMBED_SOURCE );
     833             : 
     834             :         // --> OD #i98753#
     835             :         // set size of embedded object at the object description structure
     836           0 :         aObjDesc.maSize = OutputDevice::LogicToLogic( pWrtShell->GetObjSize(), MAP_TWIP, MAP_100TH_MM );
     837             :         // <--
     838           0 :         PrepareOLE( aObjDesc );
     839           0 :         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
     840             : 
     841           0 :         AddFormat( SotClipboardFormatId::GDIMETAFILE );
     842             : 
     843             :         // Fetch the formats supported via embedtransferhelper as well
     844           0 :         sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     845           0 :         uno::Reference < embed::XEmbeddedObject > xObj = FindOLEObj( nAspect );
     846           0 :         const Graphic* pOLEGraph = FindOLEReplacementGraphic();
     847           0 :         if( xObj.is() )
     848             :         {
     849           0 :             TransferableDataHelper aD( new SvEmbedTransferHelper( xObj, pOLEGraph, nAspect ) );
     850           0 :             if ( aD.GetTransferable().is() )
     851             :             {
     852           0 :                 DataFlavorExVector              aVector( aD.GetDataFlavorExVector() );
     853           0 :                 DataFlavorExVector::iterator    aIter( aVector.begin() ), aEnd( aVector.end() );
     854             : 
     855           0 :                 while( aIter != aEnd )
     856           0 :                     AddFormat( *aIter++ );
     857           0 :             }
     858             :         }
     859           0 :         eBufferType = TRNSFR_OLE;
     860             :     }
     861             :     // Is there anything to provide anyway?
     862           1 :     else if ( pWrtShell->IsSelection() || pWrtShell->IsFrmSelected() ||
     863           0 :               pWrtShell->IsObjSelected() )
     864             :     {
     865           1 :         boost::scoped_ptr<SwWait> pWait;
     866           1 :         if( pWrtShell->ShouldWait() )
     867           1 :             pWait.reset(new SwWait( *pWrtShell->GetView().GetDocShell(), true ));
     868             : 
     869           1 :         pClpDocFac = new SwDocFac;
     870             : 
     871             :         // create additional cursor so that equal treatment of keyboard
     872             :         // and mouse selection is possible.
     873             :         // In AddMode with keyboard selection, the new cursor is not created
     874             :         // before the cursor is moved after end of selection.
     875           1 :         if( pWrtShell->IsAddMode() && pWrtShell->SwCrsrShell::HasSelection() )
     876           0 :             pWrtShell->CreateCrsr();
     877             : 
     878           1 :         SwDoc *const pTmpDoc = lcl_GetDoc(*pClpDocFac);
     879             : 
     880           1 :         pTmpDoc->getIDocumentFieldsAccess().LockExpFields();     // Never update fields - leave text as is
     881           1 :         lclOverWriteDoc(*pWrtShell, *pTmpDoc);
     882             : 
     883             :         {
     884           1 :             IDocumentMarkAccess* const pMarkAccess = pTmpDoc->getIDocumentMarkAccess();
     885           1 :             ::std::vector< ::sw::mark::IMark* > vDdeMarks;
     886             :             // find all DDE-Bookmarks
     887           3 :             for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAllMarksBegin();
     888           2 :                 ppMark != pMarkAccess->getAllMarksEnd();
     889             :                 ++ppMark)
     890             :             {
     891           0 :                 if(IDocumentMarkAccess::MarkType::DDE_BOOKMARK == IDocumentMarkAccess::GetType(**ppMark))
     892           0 :                     vDdeMarks.push_back(ppMark->get());
     893             :             }
     894             :             // remove all DDE-Bookmarks, they are invalid inside the clipdoc!
     895           3 :             for(::std::vector< ::sw::mark::IMark* >::iterator ppMark = vDdeMarks.begin();
     896           2 :                 ppMark != vDdeMarks.end();
     897             :                 ++ppMark)
     898           1 :                 pMarkAccess->deleteMark(*ppMark);
     899             :         }
     900             : 
     901             :         // a new one was created in CORE (OLE objects copied!)
     902           1 :         aDocShellRef = pTmpDoc->GetTmpDocShell();
     903           1 :         if( aDocShellRef.Is() )
     904           0 :             SwTransferable::InitOle( aDocShellRef, *pTmpDoc );
     905           1 :         pTmpDoc->SetTmpDocShell( nullptr );
     906             : 
     907           1 :         if( pWrtShell->IsObjSelected() )
     908           0 :             eBufferType = TRNSFR_DRAWING;
     909             :         else
     910             :         {
     911           1 :             eBufferType = TRNSFR_DOCUMENT;
     912           1 :             if (pWrtShell->IntelligentCut(nSelection, false) != SwWrtShell::NO_WORD)
     913           0 :                 eBufferType = (TransferBufferType)(TRNSFR_DOCUMENT_WORD | eBufferType);
     914             :         }
     915             : 
     916           1 :         bool bDDELink = pWrtShell->IsSelection();
     917           1 :         if( nSelection & nsSelectionType::SEL_TBL_CELLS )
     918             :         {
     919           0 :             eBufferType = (TransferBufferType)(TRNSFR_TABELLE | eBufferType);
     920           0 :             bDDELink = pWrtShell->HasWholeTabSelection();
     921             :         }
     922             : 
     923             :         //When someone needs it, we 'OLE' him something
     924           1 :         AddFormat( SotClipboardFormatId::EMBED_SOURCE );
     925             : 
     926             :         //put RTF ahead of  the OLE's Metafile to have less loss
     927           1 :         if( !pWrtShell->IsObjSelected() )
     928             :         {
     929           1 :             AddFormat( SotClipboardFormatId::RTF );
     930           1 :             AddFormat( SotClipboardFormatId::HTML );
     931             :         }
     932           1 :         if( pWrtShell->IsSelection() )
     933           1 :             AddFormat( SotClipboardFormatId::STRING );
     934             : 
     935           1 :         if( nSelection & ( nsSelectionType::SEL_DRW | nsSelectionType::SEL_DRW_FORM ))
     936             :         {
     937           0 :             AddFormat( SotClipboardFormatId::DRAWING );
     938           0 :             if ( nSelection & nsSelectionType::SEL_DRW )
     939             :             {
     940           0 :                 AddFormat( SotClipboardFormatId::GDIMETAFILE );
     941           0 :                 AddFormat( SotClipboardFormatId::PNG );
     942           0 :                 AddFormat( SotClipboardFormatId::BITMAP );
     943             :             }
     944           0 :             eBufferType = (TransferBufferType)( TRNSFR_GRAPHIC | eBufferType );
     945             : 
     946           0 :             pClpGraphic = new Graphic;
     947           0 :             if( !pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *pClpGraphic ))
     948           0 :                 pOrigGrf = pClpGraphic;
     949           0 :             pClpBitmap = new Graphic;
     950           0 :             if( !pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *pClpBitmap ))
     951           0 :                 pOrigGrf = pClpBitmap;
     952             : 
     953             :             // is it an URL-Button ?
     954           0 :             OUString sURL;
     955           0 :             OUString sDesc;
     956           0 :             if( pWrtShell->GetURLFromButton( sURL, sDesc ) )
     957             :             {
     958           0 :                 AddFormat( SotClipboardFormatId::STRING );
     959           0 :                 AddFormat( SotClipboardFormatId::SOLK );
     960           0 :                 AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
     961           0 :                 AddFormat( SotClipboardFormatId::FILECONTENT );
     962           0 :                 AddFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR );
     963           0 :                 AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR );
     964           0 :                 eBufferType = (TransferBufferType)( TRNSFR_INETFLD | eBufferType );
     965           0 :                 nRet = 1;
     966           0 :             }
     967             :         }
     968             : 
     969             :         // at Cut, DDE-Link doesn't make sense!!
     970             :         SwDocShell* pDShell;
     971           4 :         if( !bIsCut && bDDELink &&
     972           3 :             0 != ( pDShell = pWrtShell->GetDoc()->GetDocShell()) &&
     973           1 :             SfxObjectCreateMode::STANDARD == pDShell->GetCreateMode() )
     974             :         {
     975           1 :             AddFormat( SotClipboardFormatId::LINK );
     976           1 :             refDdeLink = new SwTrnsfrDdeLink( *this, *pWrtShell );
     977             :         }
     978             : 
     979             :         //ObjectDescriptor was already filly from the old DocShell.
     980             :         //Now adjust it. Thus in GetData the first query can still
     981             :         //be answered with delayed rendering.
     982           1 :         aObjDesc.mbCanLink = false;
     983           1 :         Size aSz( OLESIZE );
     984           1 :         aObjDesc.maSize = OutputDevice::LogicToLogic( aSz, MAP_TWIP, MAP_100TH_MM );
     985             : 
     986           1 :         PrepareOLE( aObjDesc );
     987           1 :         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
     988             :     }
     989             :     else
     990           0 :         nRet = 0;
     991             : 
     992           1 :     if( pWrtShell->IsFrmSelected() )
     993             :     {
     994           0 :         SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL );
     995           0 :         pWrtShell->GetFlyFrmAttr( aSet );
     996           0 :         const SwFormatURL& rURL = static_cast<const SwFormatURL&>(aSet.Get( RES_URL ));
     997           0 :         if( rURL.GetMap() )
     998             :         {
     999           0 :             pImageMap = new ImageMap( *rURL.GetMap() );
    1000           0 :             AddFormat( SotClipboardFormatId::SVIM );
    1001             :         }
    1002           0 :         else if( !rURL.GetURL().isEmpty() )
    1003             :         {
    1004             :             pTargetURL = new INetImage( sGrfNm, rURL.GetURL(),
    1005             :                                         rURL.GetTargetFrameName(),
    1006           0 :                                         aEmptyOUStr, Size() );
    1007           0 :             AddFormat( SotClipboardFormatId::INET_IMAGE );
    1008           0 :         }
    1009             :     }
    1010             : 
    1011           1 :     return nRet;
    1012             : }
    1013             : 
    1014           1 : int SwTransferable::Copy( bool bIsCut )
    1015             : {
    1016           1 :     int nRet = PrepareForCopy( bIsCut );
    1017           1 :     if ( nRet )
    1018             :     {
    1019           1 :         CopyToClipboard( &pWrtShell->GetView().GetEditWin() );
    1020             :     }
    1021           1 :     return nRet;
    1022             : }
    1023             : 
    1024           0 : int SwTransferable::CalculateAndCopy()
    1025             : {
    1026           0 :     if(!pWrtShell)
    1027           0 :         return 0;
    1028           0 :     SwWait aWait( *pWrtShell->GetView().GetDocShell(), true );
    1029             : 
    1030           0 :     OUString aStr( pWrtShell->Calculate() );
    1031             : 
    1032           0 :     pClpDocFac = new SwDocFac;
    1033           0 :     SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
    1034           0 :     pWrtShell->Copy(pDoc, & aStr);
    1035           0 :     eBufferType = TRNSFR_DOCUMENT;
    1036           0 :     AddFormat( SotClipboardFormatId::STRING );
    1037             : 
    1038           0 :     CopyToClipboard( &pWrtShell->GetView().GetEditWin() );
    1039             : 
    1040           0 :     return 1;
    1041             : }
    1042             : 
    1043           0 : int SwTransferable::CopyGlossary( SwTextBlocks& rGlossary, const OUString& rStr )
    1044             : {
    1045           0 :     if(!pWrtShell)
    1046           0 :         return 0;
    1047           0 :     SwWait aWait( *pWrtShell->GetView().GetDocShell(), true );
    1048             : 
    1049           0 :     pClpDocFac = new SwDocFac;
    1050           0 :     SwDoc *const pCDoc = lcl_GetDoc(*pClpDocFac);
    1051             : 
    1052           0 :     SwNodes& rNds = pCDoc->GetNodes();
    1053           0 :     SwNodeIndex aNodeIdx( *rNds.GetEndOfContent().StartOfSectionNode() );
    1054           0 :     SwContentNode* pCNd = rNds.GoNext( &aNodeIdx ); // go to 1st ContentNode
    1055           0 :     SwPaM aPam( *pCNd );
    1056             : 
    1057           0 :     pCDoc->getIDocumentFieldsAccess().LockExpFields();   // never update fields - leave text as it is
    1058             : 
    1059           0 :     pCDoc->InsertGlossary( rGlossary, rStr, aPam, 0 );
    1060             : 
    1061             :     // a new one was created in CORE (OLE-Objects copied!)
    1062           0 :     aDocShellRef = pCDoc->GetTmpDocShell();
    1063           0 :     if( aDocShellRef.Is() )
    1064           0 :         SwTransferable::InitOle( aDocShellRef, *pCDoc );
    1065           0 :     pCDoc->SetTmpDocShell( nullptr );
    1066             : 
    1067           0 :     eBufferType = TRNSFR_DOCUMENT;
    1068             : 
    1069             :     //When someone needs it, we 'OLE' her something.
    1070           0 :     AddFormat( SotClipboardFormatId::EMBED_SOURCE );
    1071           0 :     AddFormat( SotClipboardFormatId::RTF );
    1072           0 :     AddFormat( SotClipboardFormatId::HTML );
    1073           0 :     AddFormat( SotClipboardFormatId::STRING );
    1074             : 
    1075             :     //ObjectDescriptor was already filled from the old DocShell.
    1076             :     //Now adjust it. Thus in GetData the first query can still
    1077             :     //be answered with delayed rendering.
    1078           0 :     aObjDesc.mbCanLink = false;
    1079           0 :     Size aSz( OLESIZE );
    1080           0 :     aObjDesc.maSize = OutputDevice::LogicToLogic( aSz, MAP_TWIP, MAP_100TH_MM );
    1081             : 
    1082           0 :     PrepareOLE( aObjDesc );
    1083           0 :     AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
    1084             : 
    1085           0 :     CopyToClipboard( &pWrtShell->GetView().GetEditWin() );
    1086             : 
    1087           0 :     return 1;
    1088             : }
    1089             : 
    1090           0 : static inline uno::Reference < XTransferable > * lcl_getTransferPointer ( uno::Reference < XTransferable > &xRef )
    1091             : {
    1092           0 :     return &xRef;
    1093             : }
    1094             : 
    1095           0 : bool SwTransferable::IsPaste( const SwWrtShell& rSh,
    1096             :                               const TransferableDataHelper& rData )
    1097             : {
    1098             :     // Check the common case first: We can always paste our own data!
    1099             :     // If _only_ the internal format can be pasted, this check will
    1100             :     // yield 'true', while the one below would give a (wrong) result 'false'.
    1101             : 
    1102           0 :     bool bIsPaste = ( GetSwTransferable( rData ) != NULL );
    1103             : 
    1104             :     // if it's not our own data, we need to have a closer look:
    1105           0 :     if( ! bIsPaste )
    1106             :     {
    1107             :         // determine the proper paste action, and return true if we find one
    1108           0 :         uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
    1109             : 
    1110           0 :         SotExchangeDest nDestination = SwTransferable::GetSotDestination( rSh );
    1111             :         sal_uInt16 nSourceOptions =
    1112           0 :                     (( SotExchangeDest::DOC_TEXTFRAME == nDestination ||
    1113           0 :                        SotExchangeDest::SWDOC_FREE_AREA == nDestination ||
    1114           0 :                        SotExchangeDest::DOC_TEXTFRAME_WEB == nDestination ||
    1115             :                        SotExchangeDest::SWDOC_FREE_AREA_WEB == nDestination )
    1116             :                                     ? EXCHG_IN_ACTION_COPY
    1117           0 :                      : EXCHG_IN_ACTION_MOVE);
    1118             : 
    1119             :         SotClipboardFormatId nFormat;          // output param for GetExchangeAction
    1120             :         sal_uInt16 nEventAction;    // output param for GetExchangeAction
    1121             :         sal_uInt16 nAction = SotExchange::GetExchangeAction(
    1122           0 :                                 rData.GetDataFlavorExVector(),
    1123             :                                 nDestination,
    1124             :                                 nSourceOptions,             /* ?? */
    1125             :                                 EXCHG_IN_ACTION_DEFAULT,    /* ?? */
    1126             :                                 nFormat, nEventAction, SotClipboardFormatId::NONE,
    1127           0 :                                 lcl_getTransferPointer ( xTransferable ) );
    1128             : 
    1129             :         // if we find a suitable action, we can paste!
    1130           0 :         bIsPaste = (EXCHG_INOUT_ACTION_NONE != nAction);
    1131             :     }
    1132             : 
    1133           0 :     return bIsPaste;
    1134             : }
    1135             : 
    1136           1 : bool SwTransferable::Paste( SwWrtShell& rSh, TransferableDataHelper& rData )
    1137             : {
    1138           1 :     sal_uInt16 nEventAction, nAction=0;
    1139           1 :     SotExchangeDest nDestination = SwTransferable::GetSotDestination( rSh );
    1140           1 :     SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
    1141             : 
    1142           1 :     if( GetSwTransferable( rData ) )
    1143             :     {
    1144           1 :         nAction = EXCHG_OUT_ACTION_INSERT_PRIVATE;
    1145             :     }
    1146             :     else
    1147             :     {
    1148             :         sal_uInt16 nSourceOptions =
    1149           0 :                     (( SotExchangeDest::DOC_TEXTFRAME == nDestination ||
    1150           0 :                     SotExchangeDest::SWDOC_FREE_AREA == nDestination ||
    1151           0 :                     SotExchangeDest::DOC_TEXTFRAME_WEB == nDestination ||
    1152             :                     SotExchangeDest::SWDOC_FREE_AREA_WEB == nDestination )
    1153             :                                     ? EXCHG_IN_ACTION_COPY
    1154           0 :                                     : EXCHG_IN_ACTION_MOVE);
    1155           0 :         uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
    1156             :         nAction = SotExchange::GetExchangeAction(
    1157           0 :                                     rData.GetDataFlavorExVector(),
    1158             :                                     nDestination,
    1159             :                                     nSourceOptions,             /* ?? */
    1160             :                                     EXCHG_IN_ACTION_DEFAULT,    /* ?? */
    1161             :                                     nFormat, nEventAction, SotClipboardFormatId::NONE,
    1162           0 :                                     lcl_getTransferPointer ( xTransferable ) );
    1163             :     }
    1164             : 
    1165             :     // special case for tables from draw application
    1166           1 :     if( EXCHG_OUT_ACTION_INSERT_DRAWOBJ == (nAction & EXCHG_ACTION_MASK) )
    1167             :     {
    1168           0 :         if( rData.HasFormat( SotClipboardFormatId::RTF ) )
    1169             :         {
    1170           0 :             nAction = EXCHG_OUT_ACTION_INSERT_STRING | (nAction & ~EXCHG_ACTION_MASK);
    1171           0 :             nFormat = SotClipboardFormatId::RTF;
    1172             :         }
    1173             :     }
    1174             : 
    1175           2 :     return EXCHG_INOUT_ACTION_NONE != nAction &&
    1176             :             SwTransferable::PasteData( rData, rSh, nAction, nFormat,
    1177           2 :                                         nDestination, false, false );
    1178             : }
    1179             : 
    1180           1 : bool SwTransferable::PasteData( TransferableDataHelper& rData,
    1181             :                             SwWrtShell& rSh, sal_uInt16 nAction, SotClipboardFormatId nFormat,
    1182             :                             SotExchangeDest nDestination, bool bIsPasteFormat,
    1183             :                             bool bIsDefault,
    1184             :                             const Point* pPt, sal_Int8 nDropAction,
    1185             :                             bool bPasteSelection )
    1186             : {
    1187           1 :     SwWait aWait( *rSh.GetView().GetDocShell(), false );
    1188           2 :     boost::scoped_ptr<SwTrnsfrActionAndUndo> pAction;
    1189           1 :     SwModule* pMod = SW_MOD();
    1190             : 
    1191           1 :     bool nRet = false;
    1192           1 :     bool bCallAutoCaption = false;
    1193             : 
    1194           1 :     if( pPt )
    1195             :     {
    1196             :         // external Drop
    1197           0 :         if( bPasteSelection ? !pMod->pXSelection : !pMod->pDragDrop )
    1198             :         {
    1199           0 :             switch( nDestination )
    1200             :             {
    1201             :             case SotExchangeDest::DOC_LNKD_GRAPH_W_IMAP:
    1202             :             case SotExchangeDest::DOC_LNKD_GRAPHOBJ:
    1203             :             case SotExchangeDest::DOC_GRAPH_W_IMAP:
    1204             :             case SotExchangeDest::DOC_GRAPHOBJ:
    1205             :             case SotExchangeDest::DOC_OLEOBJ:
    1206             :             case SotExchangeDest::DOC_DRAWOBJ:
    1207             :             case SotExchangeDest::DOC_URLBUTTON:
    1208             :             case SotExchangeDest::DOC_GROUPOBJ:
    1209             :                 // select frames/objects
    1210           0 :                 SwTransferable::SetSelInShell( rSh, true, pPt );
    1211           0 :                 break;
    1212             : 
    1213             :             default:
    1214           0 :                 SwTransferable::SetSelInShell( rSh, false, pPt );
    1215           0 :                 break;
    1216             :             }
    1217             :         }
    1218             :     }
    1219           3 :     else if( ( !GetSwTransferable( rData ) || bIsPasteFormat ) &&
    1220           1 :             !rSh.IsTableMode() && rSh.HasSelection() )
    1221             :     {
    1222             :         // then delete the selections
    1223             : 
    1224             :         //don't delete selected content
    1225             :         // - at table-selection
    1226             :         // - at ReRead of a graphic/DDEData
    1227             :         // - at D&D, for the right selection was taken care of
    1228             :         //      in Drop-Handler
    1229           0 :         bool bDelSel = false;
    1230           0 :         switch( nDestination )
    1231             :         {
    1232             :         case SotExchangeDest::DOC_TEXTFRAME:
    1233             :         case SotExchangeDest::SWDOC_FREE_AREA:
    1234             :         case SotExchangeDest::DOC_TEXTFRAME_WEB:
    1235             :         case SotExchangeDest::SWDOC_FREE_AREA_WEB:
    1236           0 :             bDelSel = true;
    1237           0 :             break;
    1238             :         default:
    1239           0 :             break;
    1240             :         }
    1241             : 
    1242           0 :         if( bDelSel )
    1243             :             // #i34830#
    1244             :             pAction.reset(new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD, NULL,
    1245           0 :                                                      true ));
    1246             :     }
    1247             : 
    1248           1 :     SwTransferable *pTrans=0, *pTunneledTrans=GetSwTransferable( rData );
    1249             : 
    1250             :     // check for private drop
    1251           1 :     bool bPrivateDrop(pPt && (bPasteSelection ? 0 != (pTrans = pMod->pXSelection) : 0 != (pTrans = pMod->pDragDrop)));
    1252           1 :     bool bNeedToSelectBeforePaste(false);
    1253             : 
    1254           1 :     if(bPrivateDrop && DND_ACTION_LINK == nDropAction)
    1255             :     {
    1256             :         // internal drop on object, suppress bPrivateDrop to change internal fill
    1257           0 :         bPrivateDrop = false;
    1258           0 :         bNeedToSelectBeforePaste = true;
    1259             :     }
    1260             : 
    1261           1 :     if(bPrivateDrop && pPt && DND_ACTION_MOVE == nDropAction)
    1262             :     {
    1263             :         // check if dragged over a useful target. If yes, use as content exchange
    1264             :         // drop as if from external
    1265           0 :         const SwFrameFormat* pSwFrameFormat = rSh.GetFormatFromObj(*pPt);
    1266             : 
    1267           0 :         if(pSwFrameFormat && 0 != dynamic_cast< const SwDrawFrameFormat* >(pSwFrameFormat))
    1268             :         {
    1269           0 :             bPrivateDrop = false;
    1270           0 :             bNeedToSelectBeforePaste = true;
    1271             :         }
    1272             :     }
    1273             : 
    1274           1 :     if(bPrivateDrop)
    1275             :     {
    1276             :         // then internal Drag & Drop or XSelection
    1277             :         nRet = pTrans->PrivateDrop( rSh, *pPt, DND_ACTION_MOVE == nDropAction,
    1278           0 :                                     bPasteSelection );
    1279             :     }
    1280           1 :     else if( !pPt && pTunneledTrans &&
    1281             :             EXCHG_OUT_ACTION_INSERT_PRIVATE == nAction )
    1282             :     {
    1283             :         // then internal paste
    1284           1 :         nRet = pTunneledTrans->PrivatePaste( rSh );
    1285             :     }
    1286           0 :     else if( EXCHG_INOUT_ACTION_NONE != nAction )
    1287             :     {
    1288           0 :         if( !pAction )
    1289             :         {
    1290           0 :             pAction.reset(new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD));
    1291             :         }
    1292             : 
    1293             :         // in Drag&Drop MessageBoxes must not be showed
    1294           0 :         bool bMsg = 0 == pPt;
    1295           0 :         sal_uInt8 nActionFlags = static_cast< sal_uInt8 >(( nAction >> 8 ) & 0xFF);
    1296             : 
    1297           0 :         sal_uInt16 nClearedAction = ( nAction & EXCHG_ACTION_MASK );
    1298             :         // delete selections
    1299             : 
    1300           0 :         switch( nClearedAction )
    1301             :         {
    1302             :         case EXCHG_OUT_ACTION_INSERT_PRIVATE:
    1303             :             OSL_ENSURE( pPt, "EXCHG_OUT_ACTION_INSERT_PRIVATE: what should happen here?" );
    1304           0 :             break;
    1305             : 
    1306             :         case EXCHG_OUT_ACTION_MOVE_PRIVATE:
    1307             :             OSL_ENSURE( pPt, "EXCHG_OUT_ACTION_MOVE_PRIVATE: what should happen here?" );
    1308           0 :             break;
    1309             : 
    1310             :         case EXCHG_IN_ACTION_MOVE:
    1311             :         case EXCHG_IN_ACTION_COPY:
    1312             :         case EXCHG_IN_ACTION_LINK:
    1313             :         case EXCHG_OUT_ACTION_INSERT_HTML:
    1314             :         case EXCHG_OUT_ACTION_INSERT_STRING:
    1315             :         case EXCHG_OUT_ACTION_INSERT_IMAGEMAP:
    1316             :         case EXCHG_OUT_ACTION_REPLACE_IMAGEMAP:
    1317             : 
    1318             :             // then we have to use the format
    1319           0 :             switch( nFormat )
    1320             :             {
    1321             :             case SotClipboardFormatId::DRAWING:
    1322             :                 nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
    1323             :                                                 SW_PASTESDR_INSERT, pPt,
    1324           0 :                                                 nActionFlags, bNeedToSelectBeforePaste);
    1325           0 :                 break;
    1326             : 
    1327             :             case SotClipboardFormatId::HTML:
    1328             :             case SotClipboardFormatId::HTML_SIMPLE:
    1329             :             case SotClipboardFormatId::HTML_NO_COMMENT:
    1330             :             case SotClipboardFormatId::RTF:
    1331             :             case SotClipboardFormatId::STRING:
    1332             :                 nRet = SwTransferable::_PasteFileContent( rData, rSh,
    1333           0 :                                                             nFormat, bMsg );
    1334           0 :                 break;
    1335             : 
    1336             :             case SotClipboardFormatId::NETSCAPE_BOOKMARK:
    1337             :                 {
    1338           0 :                     INetBookmark aBkmk;
    1339           0 :                     if( rData.GetINetBookmark( nFormat, aBkmk ) )
    1340             :                     {
    1341           0 :                         SwFormatINetFormat aFormat( aBkmk.GetURL(), OUString() );
    1342           0 :                         rSh.InsertURL( aFormat, aBkmk.GetDescription() );
    1343           0 :                         nRet = true;
    1344           0 :                     }
    1345             :                 }
    1346           0 :                 break;
    1347             : 
    1348             :             case SotClipboardFormatId::SD_OLE:
    1349             :                 nRet = SwTransferable::_PasteOLE( rData, rSh, nFormat,
    1350           0 :                                                     nActionFlags, bMsg );
    1351           0 :                 break;
    1352             : 
    1353             :             case SotClipboardFormatId::SVIM:
    1354           0 :                 nRet = SwTransferable::_PasteImageMap( rData, rSh );
    1355           0 :                 break;
    1356             : 
    1357             :             case SotClipboardFormatId::SVXB:
    1358             :             case SotClipboardFormatId::BITMAP:
    1359             :             case SotClipboardFormatId::PNG:
    1360             :             case SotClipboardFormatId::GDIMETAFILE:
    1361             :                 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
    1362             :                                                 SW_PASTESDR_INSERT,pPt,
    1363           0 :                                                 nActionFlags, nDropAction, bNeedToSelectBeforePaste);
    1364           0 :                 break;
    1365             : 
    1366             :             case SotClipboardFormatId::XFORMS:
    1367             :             case SotClipboardFormatId::SBA_FIELDDATAEXCHANGE:
    1368             :             case SotClipboardFormatId::SBA_DATAEXCHANGE:
    1369             :             case SotClipboardFormatId::SBA_CTRLDATAEXCHANGE:
    1370             :                 nRet = SwTransferable::_PasteDBData( rData, rSh, nFormat,
    1371             :                                             EXCHG_IN_ACTION_LINK == nClearedAction,
    1372           0 :                                             pPt, bMsg );
    1373           0 :                 break;
    1374             : 
    1375             :             case SotClipboardFormatId::SIMPLE_FILE:
    1376             :                 nRet = SwTransferable::_PasteFileName( rData, rSh, nFormat,
    1377             :                                 ( EXCHG_IN_ACTION_MOVE == nClearedAction
    1378             :                                     ? SW_PASTESDR_REPLACE
    1379             :                                     : EXCHG_IN_ACTION_LINK == nClearedAction
    1380             :                                         ? SW_PASTESDR_SETATTR
    1381             :                                         : SW_PASTESDR_INSERT),
    1382           0 :                                 pPt, nActionFlags, bMsg, 0 );
    1383           0 :                 break;
    1384             : 
    1385             :             case SotClipboardFormatId::FILE_LIST:
    1386             :                 // then insert as graphics only
    1387             :                 nRet = SwTransferable::_PasteFileList( rData, rSh,
    1388             :                                     EXCHG_IN_ACTION_LINK == nClearedAction,
    1389           0 :                                     pPt, bMsg );
    1390           0 :                 break;
    1391             : 
    1392             :             case SotClipboardFormatId::SONLK:
    1393           0 :                 if( pPt )
    1394             :                 {
    1395           0 :                     NaviContentBookmark aBkmk;
    1396           0 :                     if( aBkmk.Paste( rData ) )
    1397             :                     {
    1398           0 :                         if(bIsDefault)
    1399             :                         {
    1400           0 :                             switch(aBkmk.GetDefaultDragType())
    1401             :                             {
    1402           0 :                                 case REGION_MODE_NONE: nClearedAction = EXCHG_IN_ACTION_COPY; break;
    1403           0 :                                 case REGION_MODE_EMBEDDED: nClearedAction = EXCHG_IN_ACTION_MOVE; break;
    1404           0 :                                 case REGION_MODE_LINK: nClearedAction = EXCHG_IN_ACTION_LINK; break;
    1405             :                             }
    1406             :                         }
    1407           0 :                         rSh.NavigatorPaste( aBkmk, nClearedAction );
    1408           0 :                         nRet = true;
    1409           0 :                     }
    1410             :                 }
    1411           0 :                 break;
    1412             : 
    1413             :             case SotClipboardFormatId::INET_IMAGE:
    1414             :             case SotClipboardFormatId::NETSCAPE_IMAGE:
    1415             :                 nRet = SwTransferable::_PasteTargetURL( rData, rSh,
    1416             :                                                         SW_PASTESDR_INSERT,
    1417           0 :                                                         pPt, true );
    1418           0 :                 break;
    1419             : 
    1420             :             default:
    1421             :                 OSL_ENSURE( pPt, "unknown format" );
    1422             :             }
    1423           0 :             break;
    1424             : 
    1425             :         case EXCHG_OUT_ACTION_INSERT_FILE:
    1426             :             {
    1427             :                 bool graphicInserted;
    1428             :                 nRet = SwTransferable::_PasteFileName( rData, rSh, nFormat,
    1429             :                                             SW_PASTESDR_INSERT, pPt,
    1430             :                                             nActionFlags, bMsg,
    1431           0 :                                             &graphicInserted );
    1432           0 :                 if( graphicInserted )
    1433           0 :                     bCallAutoCaption = true;
    1434             :             }
    1435           0 :             break;
    1436             : 
    1437             :         case EXCHG_OUT_ACTION_INSERT_OLE:
    1438             :             nRet = SwTransferable::_PasteOLE( rData, rSh, nFormat,
    1439           0 :                                                 nActionFlags,bMsg );
    1440           0 :             break;
    1441             : 
    1442             :         case EXCHG_OUT_ACTION_INSERT_DDE:
    1443             :             {
    1444           0 :                 bool bReRead = 0 != CNT_HasGrf( rSh.GetCntType() );
    1445           0 :                 nRet = SwTransferable::_PasteDDE( rData, rSh, bReRead, bMsg );
    1446             :             }
    1447           0 :             break;
    1448             : 
    1449             :         case EXCHG_OUT_ACTION_INSERT_HYPERLINK:
    1450             :             {
    1451           0 :                 OUString sURL, sDesc;
    1452           0 :                 if( SotClipboardFormatId::SIMPLE_FILE == nFormat )
    1453             :                 {
    1454           0 :                     if( rData.GetString( nFormat, sURL ) && !sURL.isEmpty() )
    1455             :                     {
    1456           0 :                         SwTransferable::_CheckForURLOrLNKFile( rData, sURL, &sDesc );
    1457           0 :                         if( sDesc.isEmpty() )
    1458           0 :                             sDesc = sURL;
    1459           0 :                         nRet = true;
    1460             :                     }
    1461             :                 }
    1462             :                 else
    1463             :                 {
    1464           0 :                     INetBookmark aBkmk;
    1465           0 :                     if( rData.GetINetBookmark( nFormat, aBkmk ) )
    1466             :                     {
    1467           0 :                         sURL = aBkmk.GetURL();
    1468           0 :                         sDesc = aBkmk.GetDescription();
    1469           0 :                         nRet = true;
    1470           0 :                     }
    1471             :                 }
    1472             : 
    1473           0 :                 if( nRet )
    1474             :                 {
    1475           0 :                     SwFormatINetFormat aFormat( sURL, OUString() );
    1476           0 :                     rSh.InsertURL( aFormat, sDesc );
    1477           0 :                 }
    1478             :             }
    1479           0 :             break;
    1480             : 
    1481             :         case EXCHG_OUT_ACTION_GET_ATTRIBUTES:
    1482           0 :             switch( nFormat )
    1483             :             {
    1484             :             case SotClipboardFormatId::DRAWING:
    1485             :                 nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
    1486             :                                                 SW_PASTESDR_SETATTR, pPt,
    1487           0 :                                                 nActionFlags, bNeedToSelectBeforePaste);
    1488           0 :                 break;
    1489             :             case SotClipboardFormatId::SVXB:
    1490             :             case SotClipboardFormatId::GDIMETAFILE:
    1491             :             case SotClipboardFormatId::BITMAP:
    1492             :             case SotClipboardFormatId::PNG:
    1493             :             case SotClipboardFormatId::NETSCAPE_BOOKMARK:
    1494             :             case SotClipboardFormatId::SIMPLE_FILE:
    1495             :             case SotClipboardFormatId::FILEGRPDESCRIPTOR:
    1496             :             case SotClipboardFormatId::UNIFORMRESOURCELOCATOR:
    1497             :                 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
    1498             :                                                 SW_PASTESDR_SETATTR, pPt,
    1499           0 :                                                 nActionFlags, nDropAction, bNeedToSelectBeforePaste);
    1500           0 :                 break;
    1501             :             default:
    1502             :                 OSL_FAIL( "unknown format" );
    1503             :             }
    1504             : 
    1505           0 :             break;
    1506             : 
    1507             :         case EXCHG_OUT_ACTION_INSERT_DRAWOBJ:
    1508             :             nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
    1509             :                                                 SW_PASTESDR_INSERT, pPt,
    1510           0 :                                                 nActionFlags, bNeedToSelectBeforePaste);
    1511           0 :             break;
    1512             :         case EXCHG_OUT_ACTION_INSERT_SVXB:
    1513             :         case EXCHG_OUT_ACTION_INSERT_GDIMETAFILE:
    1514             :         case EXCHG_OUT_ACTION_INSERT_BITMAP:
    1515             :         case EXCHG_OUT_ACTION_INSERT_GRAPH:
    1516             :             nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
    1517             :                                                 SW_PASTESDR_INSERT, pPt,
    1518           0 :                                                 nActionFlags, nDropAction, bNeedToSelectBeforePaste);
    1519           0 :             break;
    1520             : 
    1521             :         case EXCHG_OUT_ACTION_REPLACE_DRAWOBJ:
    1522             :             nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
    1523             :                                                 SW_PASTESDR_REPLACE, pPt,
    1524           0 :                                                 nActionFlags, bNeedToSelectBeforePaste);
    1525           0 :             break;
    1526             : 
    1527             :         case EXCHG_OUT_ACTION_REPLACE_SVXB:
    1528             :         case EXCHG_OUT_ACTION_REPLACE_GDIMETAFILE:
    1529             :         case EXCHG_OUT_ACTION_REPLACE_BITMAP:
    1530             :         case EXCHG_OUT_ACTION_REPLACE_GRAPH:
    1531             :             nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
    1532             :                                                 SW_PASTESDR_REPLACE,pPt,
    1533           0 :                                                 nActionFlags, nDropAction, bNeedToSelectBeforePaste);
    1534           0 :             break;
    1535             : 
    1536             :         case EXCHG_OUT_ACTION_INSERT_INTERACTIVE:
    1537           0 :             nRet = SwTransferable::_PasteAsHyperlink( rData, rSh, nFormat );
    1538           0 :             break;
    1539             : 
    1540             :         default:
    1541             :             OSL_FAIL("unknown action" );
    1542             :         }
    1543             :     }
    1544             : 
    1545           1 :     if( !bPasteSelection && rSh.IsFrmSelected() )
    1546             :     {
    1547           0 :         rSh.EnterSelFrmMode();
    1548             :         //force ::SelectShell
    1549           0 :         rSh.GetView().StopShellTimer();
    1550             :     }
    1551             : 
    1552           1 :     pAction.reset();
    1553           1 :     if( bCallAutoCaption )
    1554           0 :         rSh.GetView().AutoCaption( GRAPHIC_CAP );
    1555             : 
    1556           2 :     return nRet;
    1557             : }
    1558             : 
    1559        2647 : SotExchangeDest SwTransferable::GetSotDestination( const SwWrtShell& rSh,
    1560             :                                             const Point* pPt )
    1561             : {
    1562        2647 :     SotExchangeDest nRet = SotExchangeDest::NONE;
    1563             : 
    1564             :     ObjCntType eOType;
    1565        2647 :     if( pPt )
    1566             :     {
    1567           0 :         SdrObject *pObj = 0;
    1568           0 :         eOType = rSh.GetObjCntType( *pPt, pObj );
    1569             :     }
    1570             :     else
    1571        2647 :         eOType = rSh.GetObjCntTypeOfSelection();
    1572             : 
    1573        2647 :     switch( eOType )
    1574             :     {
    1575             :     case OBJCNT_GRF:
    1576             :         {
    1577             :             bool bIMap, bLink;
    1578           0 :             if( pPt )
    1579             :             {
    1580           0 :                 bIMap = 0 != rSh.GetFormatFromObj( *pPt )->GetURL().GetMap();
    1581           0 :                 OUString aDummy;
    1582           0 :                 rSh.GetGrfAtPos( *pPt, aDummy, bLink );
    1583             :             }
    1584             :             else
    1585             :             {
    1586           0 :                 bIMap = 0 != rSh.GetFlyFrameFormat()->GetURL().GetMap();
    1587           0 :                 OUString aDummy;
    1588           0 :                 rSh.GetGrfNms( &aDummy, 0 );
    1589           0 :                 bLink = !aDummy.isEmpty();
    1590             :             }
    1591             : 
    1592           0 :             if( bLink && bIMap )
    1593           0 :                 nRet = SotExchangeDest::DOC_LNKD_GRAPH_W_IMAP;
    1594           0 :             else if( bLink )
    1595           0 :                 nRet = SotExchangeDest::DOC_LNKD_GRAPHOBJ;
    1596           0 :             else if( bIMap )
    1597           0 :                 nRet = SotExchangeDest::DOC_GRAPH_W_IMAP;
    1598             :             else
    1599           0 :                 nRet = SotExchangeDest::DOC_GRAPHOBJ;
    1600             :         }
    1601           0 :         break;
    1602             : 
    1603             :     case OBJCNT_FLY:
    1604           0 :         if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
    1605           0 :             nRet = SotExchangeDest::DOC_TEXTFRAME_WEB;
    1606             :         else
    1607           0 :             nRet = SotExchangeDest::DOC_TEXTFRAME;
    1608           0 :         break;
    1609           0 :     case OBJCNT_OLE:        nRet = SotExchangeDest::DOC_OLEOBJ;       break;
    1610             : 
    1611             :     case OBJCNT_CONTROL:    /* no Action avail */
    1612           0 :     case OBJCNT_SIMPLE:     nRet = SotExchangeDest::DOC_DRAWOBJ;      break;
    1613           0 :     case OBJCNT_URLBUTTON:  nRet = SotExchangeDest::DOC_URLBUTTON;    break;
    1614           0 :     case OBJCNT_GROUPOBJ:   nRet = SotExchangeDest::DOC_GROUPOBJ;     break;
    1615             : 
    1616             :     // what do we do at multiple selections???
    1617             :     default:
    1618             :         {
    1619        2647 :             if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
    1620           2 :                 nRet = SotExchangeDest::SWDOC_FREE_AREA_WEB;
    1621             :             else
    1622        2645 :                 nRet = SotExchangeDest::SWDOC_FREE_AREA;
    1623             :         }
    1624             :     }
    1625             : 
    1626        2647 :     return nRet;
    1627             : }
    1628             : 
    1629           0 : bool SwTransferable::_PasteFileContent( TransferableDataHelper& rData,
    1630             :                                     SwWrtShell& rSh, SotClipboardFormatId nFormat, bool bMsg )
    1631             : {
    1632           0 :     sal_uInt16 nResId = STR_CLPBRD_FORMAT_ERROR;
    1633           0 :     bool nRet = false;
    1634             : 
    1635           0 :     MSE40HTMLClipFormatObj aMSE40ClpObj;
    1636             : 
    1637           0 :     tools::SvRef<SotStorageStream> xStrm;
    1638           0 :     SvStream* pStream = 0;
    1639           0 :     SwRead pRead = 0;
    1640           0 :     OUString sData;
    1641           0 :     switch( nFormat )
    1642             :     {
    1643             :     case SotClipboardFormatId::STRING:
    1644             :         {
    1645           0 :             pRead = ReadAscii;
    1646           0 :             if( rData.GetString( nFormat, sData ) )
    1647             :             {
    1648             :                 pStream = new SvMemoryStream( const_cast<sal_Unicode *>(sData.getStr()),
    1649           0 :                             sData.getLength() * sizeof( sal_Unicode ),
    1650           0 :                             StreamMode::READ );
    1651             : #ifdef OSL_BIGENDIAN
    1652             :                 pStream->SetEndian( SvStreamEndian::BIG );
    1653             : #else
    1654           0 :                 pStream->SetEndian( SvStreamEndian::LITTLE );
    1655             : #endif
    1656             : 
    1657           0 :                 SwAsciiOptions aAOpt;
    1658           0 :                 aAOpt.SetCharSet( RTL_TEXTENCODING_UCS2 );
    1659           0 :                 pRead->GetReaderOpt().SetASCIIOpts( aAOpt );
    1660           0 :                 break;
    1661             :             }
    1662             :         }
    1663             :         // no break - because then test if we get a stream
    1664             : 
    1665             :     default:
    1666           0 :         if( rData.GetSotStorageStream( nFormat, xStrm ) )
    1667             :         {
    1668           0 :             if( ( SotClipboardFormatId::HTML_SIMPLE == nFormat ) ||
    1669             :                 ( SotClipboardFormatId::HTML_NO_COMMENT == nFormat ) )
    1670             :             {
    1671           0 :                 pStream = aMSE40ClpObj.IsValid( *xStrm );
    1672           0 :                 pRead = ReadHTML;
    1673           0 :                 pRead->SetReadUTF8( true );
    1674             : 
    1675             :                 bool bNoComments =
    1676           0 :                     ( nFormat == SotClipboardFormatId::HTML_NO_COMMENT );
    1677           0 :                 pRead->SetIgnoreHTMLComments( bNoComments );
    1678             :             }
    1679             :             else
    1680             :             {
    1681           0 :                 pStream = &xStrm;
    1682           0 :                 if( SotClipboardFormatId::RTF == nFormat )
    1683           0 :                     pRead = SwReaderWriter::GetReader( READER_WRITER_RTF );
    1684           0 :                 else if( !pRead )
    1685             :                 {
    1686           0 :                     pRead = ReadHTML;
    1687           0 :                     pRead->SetReadUTF8( true );
    1688             :                 }
    1689             :             }
    1690             :         }
    1691           0 :         break;
    1692             :     }
    1693             : 
    1694           0 :     if( pStream && pRead )
    1695             :     {
    1696           0 :         Link<> aOldLink( rSh.GetChgLnk() );
    1697           0 :         rSh.SetChgLnk( Link<>() );
    1698             : 
    1699           0 :         const SwPosition& rInsPos = *rSh.GetCrsr()->Start();
    1700           0 :         SwReader aReader( *pStream, aEmptyOUStr, OUString(), *rSh.GetCrsr() );
    1701           0 :         rSh.SaveTableBoxContent( &rInsPos );
    1702           0 :         if( IsError( aReader.Read( *pRead )) )
    1703           0 :             nResId = STR_ERROR_CLPBRD_READ;
    1704             :         else
    1705           0 :             nResId = 0, nRet = true;
    1706             : 
    1707           0 :         rSh.SetChgLnk( aOldLink );
    1708           0 :         if( nRet )
    1709           0 :             rSh.CallChgLnk();
    1710             :     }
    1711             :     else
    1712           0 :         nResId = STR_CLPBRD_FORMAT_ERROR;
    1713             : 
    1714             :     // Exist a SvMemoryStream? (data in the OUString and xStrm is empty)
    1715           0 :     if( pStream && !xStrm.Is() )
    1716           0 :         delete pStream;
    1717             : 
    1718           0 :     if( bMsg && nResId )
    1719             :     {
    1720           0 :         ScopedVclPtrInstance<MessageDialog>::Create( nullptr, SW_RES( nResId ), VCL_MESSAGE_INFO)->Execute();
    1721             :     }
    1722           0 :     return nRet;
    1723             : }
    1724             : 
    1725           0 : bool SwTransferable::_PasteOLE( TransferableDataHelper& rData, SwWrtShell& rSh,
    1726             :                                 SotClipboardFormatId nFormat, sal_uInt8 nActionFlags, bool bMsg )
    1727             : {
    1728           0 :     bool nRet = false;
    1729           0 :     TransferableObjectDescriptor aObjDesc;
    1730           0 :     uno::Reference < io::XInputStream > xStrm;
    1731           0 :     uno::Reference < embed::XStorage > xStore;
    1732           0 :     Reader* pRead = 0;
    1733             : 
    1734             :     // Get the preferred format
    1735             :     SotClipboardFormatId nId;
    1736           0 :     if( rData.HasFormat( SotClipboardFormatId::EMBEDDED_OBJ ) )
    1737           0 :         nId = SotClipboardFormatId::EMBEDDED_OBJ;
    1738           0 :     else if( rData.HasFormat( SotClipboardFormatId::EMBED_SOURCE ) &&
    1739           0 :              rData.HasFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ))
    1740           0 :         nId = SotClipboardFormatId::EMBED_SOURCE;
    1741             :     else
    1742           0 :         nId = SotClipboardFormatId::NONE;
    1743             : 
    1744           0 :     if (nId != SotClipboardFormatId::NONE)
    1745             :     {
    1746           0 :         SwDocShell* pDocSh = rSh.GetDoc()->GetDocShell();
    1747           0 :         xStrm = rData.GetInputStream(nId, SfxObjectShell::CreateShellID(pDocSh));
    1748             :     }
    1749             : 
    1750           0 :     if (xStrm.is())
    1751             :     {
    1752             :         // if there is an embedded object, first try if it's a writer object
    1753             :         // this will be inserted into the document by using a Reader
    1754             :         try
    1755             :         {
    1756           0 :             xStore = comphelper::OStorageHelper::GetStorageFromInputStream( xStrm );
    1757           0 :             switch( SotStorage::GetFormatID( xStore ) )
    1758             :             {
    1759             :                 case SotClipboardFormatId::STARWRITER_60:
    1760             :                 case SotClipboardFormatId::STARWRITERWEB_60:
    1761             :                 case SotClipboardFormatId::STARWRITERGLOB_60:
    1762             :                 case SotClipboardFormatId::STARWRITER_8:
    1763             :                 case SotClipboardFormatId::STARWRITERWEB_8:
    1764             :                 case SotClipboardFormatId::STARWRITERGLOB_8:
    1765           0 :                     pRead = ReadXML;
    1766           0 :                     break;
    1767             :                 default:
    1768             :                     try
    1769             :                     {
    1770           0 :                         uno::Reference < lang::XComponent > xComp( xStore, uno::UNO_QUERY );
    1771           0 :                         xComp->dispose();
    1772           0 :                         xStore = 0;
    1773             :                     }
    1774           0 :                     catch (const uno::Exception&)
    1775             :                     {
    1776             :                     }
    1777             : 
    1778           0 :                     break;
    1779             :             }
    1780             :         }
    1781           0 :         catch (const uno::Exception&)
    1782             :         {
    1783             :             // it wasn't a storage, but maybe it's a useful stream
    1784             :         }
    1785             : 
    1786           0 :         nFormat = nId;
    1787             :     }
    1788             : 
    1789           0 :     if( pRead )
    1790             :     {
    1791           0 :         SwPaM &rPAM = *rSh.GetCrsr();
    1792           0 :         SwReader aReader( xStore, aEmptyOUStr, rPAM );
    1793           0 :         if( !IsError( aReader.Read( *pRead )) )
    1794           0 :             nRet = true;
    1795           0 :         else if( bMsg )
    1796           0 :             ScopedVclPtrInstance<MessageDialog>::Create( nullptr, SW_RES(STR_ERROR_CLPBRD_READ), VCL_MESSAGE_INFO )->Execute();
    1797             :     }
    1798             :     else
    1799             :     {
    1800             :         // temporary storage until the object is inserted
    1801           0 :         uno::Reference< embed::XStorage > xTmpStor;
    1802           0 :         uno::Reference < embed::XEmbeddedObject > xObj;
    1803           0 :         OUString aName;
    1804           0 :            comphelper::EmbeddedObjectContainer aCnt;
    1805             : 
    1806           0 :         if ( xStrm.is() )
    1807             :         {
    1808           0 :             if ( !rData.GetTransferableObjectDescriptor( SotClipboardFormatId::OBJECTDESCRIPTOR, aObjDesc ) )
    1809             :             {
    1810             :                 OSL_ENSURE( !xStrm.is(), "An object without descriptor in clipboard!");
    1811             :             }
    1812             :         }
    1813             :         else
    1814             :         {
    1815           0 :             if( rData.HasFormat( nFormat = SotClipboardFormatId::OBJECTDESCRIPTOR_OLE ) && rData.GetTransferableObjectDescriptor( nFormat, aObjDesc ) )
    1816             :              {
    1817           0 :                 xStrm = rData.GetInputStream(SotClipboardFormatId::EMBED_SOURCE_OLE, OUString());
    1818           0 :                 if (!xStrm.is())
    1819           0 :                     xStrm = rData.GetInputStream(SotClipboardFormatId::EMBEDDED_OBJ_OLE, OUString());
    1820             : 
    1821           0 :                 if ( !xStrm.is() )
    1822             :                 {
    1823             :                     // This is MSOLE object that should be created by direct using of system clipboard
    1824             :                     try
    1825             :                     {
    1826           0 :                         xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
    1827             :                         uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator =
    1828           0 :                             embed::MSOLEObjectSystemCreator::create( ::comphelper::getProcessComponentContext() );
    1829             : 
    1830           0 :                         embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
    1831             :                                                             xTmpStor,
    1832             :                                                             OUString( "DummyName" ),
    1833           0 :                                                             uno::Sequence< beans::PropertyValue >() );
    1834             : 
    1835             :                         // TODO/LATER: in future InsertedObjectInfo will be used to get container related information
    1836             :                         // for example whether the object should be an iconified one
    1837           0 :                         xObj = aInfo.Object;
    1838             :                     }
    1839           0 :                     catch (const uno::Exception&)
    1840             :                     {
    1841             :                     }
    1842             :                 }
    1843             :             }
    1844             :         }
    1845             : 
    1846           0 :         if ( xStrm.is() && !xObj.is() )
    1847           0 :             xObj = aCnt.InsertEmbeddedObject( xStrm, aName );
    1848             : 
    1849           0 :         if( xObj.is() )
    1850             :         {
    1851           0 :             svt::EmbeddedObjectRef xObjRef( xObj, aObjDesc.mnViewAspect );
    1852             : 
    1853             :             // try to get the replacement image from the clipboard
    1854           0 :             Graphic aGraphic;
    1855           0 :             SotClipboardFormatId nGrFormat = SotClipboardFormatId::NONE;
    1856             : 
    1857             :             // limit the size of the preview metafile to 100000 actions
    1858           0 :             GDIMetaFile aMetafile;
    1859           0 :             if (rData.GetGDIMetaFile(SotClipboardFormatId::GDIMETAFILE, aMetafile, 100000))
    1860             :             {
    1861           0 :                 nGrFormat = SotClipboardFormatId::GDIMETAFILE;
    1862           0 :                 aGraphic = aMetafile;
    1863             :             }
    1864             : 
    1865             :             // insert replacement image ( if there is one ) into the object helper
    1866           0 :             if ( nGrFormat != SotClipboardFormatId::NONE )
    1867             :             {
    1868           0 :                 DataFlavor aDataFlavor;
    1869           0 :                 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
    1870           0 :                 xObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType );
    1871             :             }
    1872           0 :             else if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
    1873             :             {
    1874             :                 // it is important to have an icon, let an empty graphic be used
    1875             :                 // if no other graphic is provided
    1876             :                 // TODO/LATER: in future a default bitmap could be used
    1877           0 :                 OUString aMimeType;
    1878           0 :                 MapMode aMapMode( MAP_100TH_MM );
    1879           0 :                 aGraphic.SetPrefSize( Size( 2500, 2500 ) );
    1880           0 :                 aGraphic.SetPrefMapMode( aMapMode );
    1881           0 :                 xObjRef.SetGraphic( aGraphic, aMimeType );
    1882             :             }
    1883             : 
    1884             :             //set size. This is a hack because of handing over, size should be
    1885             :             //passed to the InsertOle!!!!!!!!!!
    1886           0 :             Size aSize;
    1887           0 :             if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
    1888             :             {
    1889           0 :                 if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
    1890           0 :                     aSize = aObjDesc.maSize;
    1891             :                 else
    1892             :                 {
    1893           0 :                     MapMode aMapMode( MAP_100TH_MM );
    1894           0 :                     aSize = xObjRef.GetSize( &aMapMode );
    1895             :                 }
    1896             :             }
    1897           0 :             else if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
    1898             :             {
    1899           0 :                 aSize = Size( aObjDesc.maSize );    //always 100TH_MM
    1900           0 :                 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) );
    1901           0 :                 aSize = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
    1902           0 :                 awt::Size aSz;
    1903             :                 try
    1904             :                 {
    1905           0 :                     aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
    1906             :                 }
    1907           0 :                 catch (const embed::NoVisualAreaSizeException&)
    1908             :                 {
    1909             :                     // in this case the provided size is used
    1910             :                 }
    1911             : 
    1912           0 :                 if ( aSz.Width != aSize.Width() || aSz.Height != aSize.Height() )
    1913             :                 {
    1914           0 :                     aSz.Width = aSize.Width();
    1915           0 :                     aSz.Height = aSize.Height();
    1916           0 :                     xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
    1917             :                 }
    1918             :             }
    1919             :             else
    1920             :             {
    1921             :                 // the descriptor contains the wrong object size
    1922             :                 // the following call will let the MSOLE objects cache the size if it is possible
    1923             :                 // it should be done while the object is running
    1924             :                 try
    1925             :                 {
    1926           0 :                     xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
    1927             :                 }
    1928           0 :                 catch (const uno::Exception&)
    1929             :                 {
    1930             :                 }
    1931             :             }
    1932             :             //End of Hack!
    1933             : 
    1934           0 :             rSh.InsertOleObject( xObjRef );
    1935           0 :             nRet = true;
    1936             : 
    1937           0 :             if( nRet && ( nActionFlags &
    1938             :                 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) ))
    1939           0 :                 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, false );
    1940             : 
    1941             :             // let the object be unloaded if possible
    1942           0 :             SwOLEObj::UnloadObject( xObj, rSh.GetDoc(), embed::Aspects::MSOLE_CONTENT );
    1943           0 :         }
    1944             :     }
    1945           0 :     return nRet;
    1946             : }
    1947             : 
    1948           0 : bool SwTransferable::_PasteTargetURL( TransferableDataHelper& rData,
    1949             :                                     SwWrtShell& rSh, sal_uInt16 nAction,
    1950             :                                     const Point* pPt, bool bInsertGRF )
    1951             : {
    1952           0 :     bool nRet = false;
    1953           0 :     INetImage aINetImg;
    1954           0 :     if( ( rData.HasFormat( SotClipboardFormatId::INET_IMAGE ) &&
    1955           0 :           rData.GetINetImage( SotClipboardFormatId::INET_IMAGE, aINetImg )) ||
    1956           0 :         ( rData.HasFormat( SotClipboardFormatId::NETSCAPE_IMAGE ) &&
    1957           0 :           rData.GetINetImage( SotClipboardFormatId::NETSCAPE_IMAGE, aINetImg )) )
    1958             :     {
    1959           0 :         if( !aINetImg.GetImageURL().isEmpty() && bInsertGRF )
    1960             :         {
    1961           0 :             OUString sURL( aINetImg.GetImageURL() );
    1962           0 :             SwTransferable::_CheckForURLOrLNKFile( rData, sURL );
    1963             : 
    1964             :             //!!! check at FileSystem - only then it make sense to test graphics !!!
    1965           0 :             Graphic aGraphic;
    1966           0 :             GraphicFilter &rFlt = GraphicFilter::GetGraphicFilter();
    1967           0 :             nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( sURL, aEmptyOUStr, aGraphic, &rFlt );
    1968             : 
    1969           0 :             if( nRet )
    1970             :             {
    1971             :                 //Check and Perform rotation if needed
    1972           0 :                 lclCheckAndPerformRotation(aGraphic);
    1973             : 
    1974           0 :                 switch( nAction )
    1975             :                 {
    1976             :                 case SW_PASTESDR_INSERT:
    1977           0 :                     SwTransferable::SetSelInShell( rSh, false, pPt );
    1978           0 :                     rSh.Insert( sURL, aEmptyOUStr, aGraphic );
    1979           0 :                     break;
    1980             : 
    1981             :                 case SW_PASTESDR_REPLACE:
    1982           0 :                     if( rSh.IsObjSelected() )
    1983             :                     {
    1984           0 :                         rSh.ReplaceSdrObj( sURL, aEmptyOUStr, &aGraphic );
    1985           0 :                         Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() );
    1986           0 :                         SwTransferable::SetSelInShell( rSh, true, &aPt );
    1987             :                     }
    1988             :                     else
    1989           0 :                         rSh.ReRead( sURL, aEmptyOUStr, &aGraphic );
    1990           0 :                     break;
    1991             : 
    1992             :                 case SW_PASTESDR_SETATTR:
    1993           0 :                     if( rSh.IsObjSelected() )
    1994           0 :                         rSh.Paste( aGraphic, OUString() );
    1995           0 :                     else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() )
    1996           0 :                         rSh.ReRead( sURL, aEmptyOUStr, &aGraphic );
    1997             :                     else
    1998             :                     {
    1999           0 :                         SwTransferable::SetSelInShell( rSh, false, pPt );
    2000           0 :                         rSh.Insert( sURL, aEmptyOUStr, aGraphic );
    2001             :                     }
    2002           0 :                     break;
    2003             :                 default:
    2004           0 :                     nRet = false;
    2005             :                 }
    2006           0 :             }
    2007             :         }
    2008             :         else
    2009           0 :             nRet = true;
    2010             :     }
    2011             : 
    2012           0 :     if( nRet )
    2013             :     {
    2014           0 :         SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
    2015           0 :         rSh.GetFlyFrmAttr( aSet );
    2016           0 :         SwFormatURL aURL( static_cast<const SwFormatURL&>(aSet.Get( RES_URL )) );
    2017             : 
    2018           0 :         if( aURL.GetURL() != aINetImg.GetTargetURL() ||
    2019           0 :             aURL.GetTargetFrameName() != aINetImg.GetTargetFrame() )
    2020             :         {
    2021           0 :             aURL.SetURL( aINetImg.GetTargetURL(), false );
    2022           0 :             aURL.SetTargetFrameName( aINetImg.GetTargetFrame() );
    2023           0 :             aSet.Put( aURL );
    2024           0 :             rSh.SetFlyFrmAttr( aSet );
    2025           0 :         }
    2026             :     }
    2027           0 :     return nRet;
    2028             : }
    2029             : 
    2030           0 : void SwTransferable::SetSelInShell( SwWrtShell& rSh, bool bSelectFrm,
    2031             :                                         const Point* pPt )
    2032             : {
    2033           0 :     if( bSelectFrm )
    2034             :     {
    2035             :         // select frames/objects
    2036           0 :         if( pPt && !rSh.GetView().GetViewFrame()->GetDispatcher()->IsLocked() )
    2037             :         {
    2038           0 :             rSh.GetView().NoRotate();
    2039           0 :             if( rSh.SelectObj( *pPt ))
    2040             :             {
    2041           0 :                 rSh.HideCrsr();
    2042           0 :                 rSh.EnterSelFrmMode( pPt );
    2043           0 :                 g_bFrmDrag = true;
    2044             :             }
    2045             :         }
    2046             :     }
    2047             :     else
    2048             :     {
    2049           0 :         if( rSh.IsFrmSelected() || rSh.IsObjSelected() )
    2050             :         {
    2051           0 :             rSh.UnSelectFrm();
    2052           0 :             rSh.LeaveSelFrmMode();
    2053           0 :             rSh.GetView().GetEditWin().StopInsFrm();
    2054           0 :             g_bFrmDrag = false;
    2055             :         }
    2056           0 :         else if( rSh.GetView().GetDrawFuncPtr() )
    2057           0 :             rSh.GetView().GetEditWin().StopInsFrm();
    2058             : 
    2059           0 :         rSh.EnterStdMode();
    2060           0 :         if( pPt )
    2061           0 :             rSh.SwCrsrShell::SetCrsr( *pPt, true );
    2062             :     }
    2063           0 : }
    2064             : 
    2065           0 : bool SwTransferable::_PasteDDE( TransferableDataHelper& rData,
    2066             :                                 SwWrtShell& rWrtShell, bool bReReadGrf,
    2067             :                                 bool bMsg )
    2068             : {
    2069             :     // data from Clipboardformat
    2070           0 :     OUString aApp, aTopic, aItem;
    2071             : 
    2072             :     {
    2073           0 :         tools::SvRef<SotStorageStream> xStrm;
    2074           0 :         if( !rData.GetSotStorageStream( SotClipboardFormatId::LINK, xStrm ))
    2075             :         {
    2076             :             OSL_ENSURE( false, "DDE Data not found." );
    2077           0 :             return false;
    2078             :         }   // report useful error!!
    2079             : 
    2080           0 :         rtl_TextEncoding eEncoding = DDE_TXT_ENCODING;
    2081           0 :         aApp = read_zeroTerminated_uInt8s_ToOUString(*xStrm, eEncoding);
    2082           0 :         aTopic = read_zeroTerminated_uInt8s_ToOUString(*xStrm, eEncoding);
    2083           0 :         aItem = read_zeroTerminated_uInt8s_ToOUString(*xStrm, eEncoding);
    2084             :     }
    2085             : 
    2086           0 :     OUString aCmd;
    2087           0 :     sfx2::MakeLnkName( aCmd, &aApp, aTopic, aItem );
    2088             : 
    2089             :     // do we want to read in a graphic now?
    2090             :     SotClipboardFormatId nFormat;
    2091           0 :     if( !rData.HasFormat( SotClipboardFormatId::RTF ) &&
    2092           0 :         !rData.HasFormat( SotClipboardFormatId::HTML ) &&
    2093           0 :         !rData.HasFormat( SotClipboardFormatId::STRING ) &&
    2094           0 :         (rData.HasFormat( nFormat = SotClipboardFormatId::GDIMETAFILE ) ||
    2095           0 :          rData.HasFormat( nFormat = SotClipboardFormatId::BITMAP )) )
    2096             :     {
    2097           0 :         Graphic aGrf;
    2098           0 :         bool nRet = rData.GetGraphic( nFormat, aGrf );
    2099           0 :         if( nRet )
    2100             :         {
    2101           0 :             OUString sLnkTyp("DDE");
    2102           0 :             if ( bReReadGrf )
    2103           0 :                 rWrtShell.ReRead( aCmd, sLnkTyp, &aGrf );
    2104             :             else
    2105           0 :                 rWrtShell.Insert( aCmd, sLnkTyp, aGrf );
    2106             :         }
    2107           0 :         return nRet;
    2108             :     }
    2109             : 
    2110           0 :     SwFieldType* pTyp = 0;
    2111           0 :     size_t i = 1;
    2112             :     size_t j;
    2113           0 :     OUString aName;
    2114           0 :     bool bDoublePaste = false;
    2115           0 :     const size_t nSize = rWrtShell.GetFieldTypeCount();
    2116           0 :     const ::utl::TransliterationWrapper& rColl = ::GetAppCmpStrIgnore();
    2117             : 
    2118           0 :     do {
    2119           0 :         aName = aApp;
    2120           0 :         aName += OUString::number( i );
    2121           0 :         for( j = INIT_FLDTYPES; j < nSize; j++ )
    2122             :         {
    2123           0 :             pTyp = rWrtShell.GetFieldType( j );
    2124           0 :             if( RES_DDEFLD == pTyp->Which() )
    2125             :             {
    2126           0 :                 OUString sTmp( static_cast<SwDDEFieldType*>(pTyp)->GetCmd() );
    2127           0 :                 if( rColl.isEqual( sTmp, aCmd ) &&
    2128           0 :                     SfxLinkUpdateMode::ALWAYS == static_cast<SwDDEFieldType*>(pTyp)->GetType() )
    2129             :                 {
    2130           0 :                     aName = pTyp->GetName();
    2131           0 :                     bDoublePaste = true;
    2132           0 :                     break;
    2133             :                 }
    2134           0 :                 else if( rColl.isEqual( aName, pTyp->GetName() ) )
    2135           0 :                     break;
    2136             :             }
    2137             :         }
    2138           0 :         if( j == nSize )
    2139           0 :             break;
    2140           0 :         ++i;
    2141             :     }
    2142           0 :     while( !bDoublePaste );
    2143             : 
    2144           0 :     if( !bDoublePaste )
    2145             :     {
    2146           0 :         SwDDEFieldType aType( aName, aCmd, SfxLinkUpdateMode::ALWAYS );
    2147           0 :         pTyp = rWrtShell.InsertFieldType( aType );
    2148             :     }
    2149             : 
    2150           0 :     SwDDEFieldType* pDDETyp = static_cast<SwDDEFieldType*>(pTyp);
    2151             : 
    2152           0 :     OUString aExpand;
    2153           0 :     if( rData.GetString( SotClipboardFormatId::STRING, aExpand ))
    2154             :     {
    2155             :         do {            // middle checked loop
    2156             : 
    2157             :             // When data comes from a spreadsheet, we add a DDE-table
    2158           0 :             if( ( rData.HasFormat( SotClipboardFormatId::SYLK ) ||
    2159           0 :                   rData.HasFormat( SotClipboardFormatId::SYLK_BIGCAPS ) ) &&
    2160           0 :                 !aExpand.isEmpty() &&
    2161           0 :                  ( 1 < comphelper::string::getTokenCount(aExpand, '\n') ||
    2162           0 :                        comphelper::string::getTokenCount(aExpand, '\t') ) )
    2163             :             {
    2164           0 :                 OUString sTmp( aExpand );
    2165           0 :                 sal_Int32 nRows = comphelper::string::getTokenCount(sTmp, '\n');
    2166           0 :                 if( nRows )
    2167           0 :                     --nRows;
    2168           0 :                 sTmp = sTmp.getToken( 0, '\n' );
    2169           0 :                 sal_Int32 nCols = comphelper::string::getTokenCount(sTmp, '\t');
    2170             : 
    2171             :                 // at least one column & row must be there
    2172           0 :                 if( !nRows || !nCols )
    2173             :                 {
    2174           0 :                     if( bMsg )
    2175           0 :                         ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SW_RESSTR(STR_NO_TABLE), VCL_MESSAGE_INFO)->Execute();
    2176           0 :                     pDDETyp = 0;
    2177           0 :                     break;
    2178             :                 }
    2179             : 
    2180             :                 rWrtShell.InsertDDETable(
    2181             :                     SwInsertTableOptions( tabopts::SPLIT_LAYOUT, 1 ), // TODO MULTIHEADER
    2182           0 :                     pDDETyp, nRows, nCols );
    2183             :             }
    2184           0 :             else if( 1 < comphelper::string::getTokenCount(aExpand, '\n') )
    2185             :             {
    2186             :                 // multiple paragraphs -> insert a protected section
    2187           0 :                 if( rWrtShell.HasSelection() )
    2188           0 :                     rWrtShell.DelRight();
    2189             : 
    2190           0 :                 SwSectionData aSect( DDE_LINK_SECTION, aName );
    2191           0 :                 aSect.SetLinkFileName( aCmd );
    2192           0 :                 aSect.SetProtectFlag(true);
    2193           0 :                 rWrtShell.InsertSection( aSect );
    2194             : 
    2195           0 :                 pDDETyp = 0;                // remove FieldTypes again
    2196             :             }
    2197             :             else
    2198             :             {
    2199             :                 // Einfuegen
    2200           0 :                 SwDDEField aSwDDEField( pDDETyp );
    2201           0 :                 rWrtShell.Insert( aSwDDEField );
    2202             :             }
    2203             : 
    2204             :         } while( false );
    2205             :     }
    2206             :     else
    2207           0 :         pDDETyp = 0;                        // remove FieldTypes again
    2208             : 
    2209           0 :     if( !pDDETyp && !bDoublePaste )
    2210             :     {
    2211             :         // remove FieldType again - error occurred!
    2212           0 :         for( j = nSize; j >= INIT_FLDTYPES; --j )
    2213           0 :             if( pTyp == rWrtShell.GetFieldType( j ) )
    2214             :             {
    2215           0 :                 rWrtShell.RemoveFieldType( j );
    2216           0 :                 break;
    2217             :             }
    2218             :     }
    2219             : 
    2220           0 :     return true;
    2221             : }
    2222             : 
    2223           0 : bool SwTransferable::_PasteSdrFormat(  TransferableDataHelper& rData,
    2224             :                                     SwWrtShell& rSh, sal_uInt16 nAction,
    2225             :                                     const Point* pPt, sal_uInt8 nActionFlags, bool bNeedToSelectBeforePaste)
    2226             : {
    2227           0 :     bool nRet = false;
    2228           0 :     tools::SvRef<SotStorageStream> xStrm;
    2229           0 :     if( rData.GetSotStorageStream( SotClipboardFormatId::DRAWING, xStrm ))
    2230             :     {
    2231           0 :         xStrm->SetVersion( SOFFICE_FILEFORMAT_50 );
    2232             : 
    2233           0 :         if(bNeedToSelectBeforePaste && pPt)
    2234             :         {
    2235             :             // if this is an internal drag, need to set the target right (select it), else
    2236             :             // still the source will be selected
    2237           0 :             SwTransferable::SetSelInShell( rSh, true, pPt );
    2238             :         }
    2239             : 
    2240           0 :         rSh.Paste( *xStrm, nAction, pPt );
    2241           0 :         nRet = true;
    2242             : 
    2243           0 :         if( nRet && ( nActionFlags &
    2244             :             ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) ))
    2245           0 :             SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, false );
    2246             :     }
    2247           0 :     return nRet;
    2248             : }
    2249             : 
    2250           0 : bool SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
    2251             :                                 SotClipboardFormatId nFormat, sal_uInt16 nAction, const Point* pPt,
    2252             :                                 sal_uInt8 nActionFlags, sal_Int8 nDropAction, bool bNeedToSelectBeforePaste)
    2253             : {
    2254           0 :     bool nRet = false;
    2255             : 
    2256           0 :     Graphic aGraphic;
    2257           0 :     INetBookmark aBkmk;
    2258           0 :     bool bCheckForGrf = false, bCheckForImageMap = false;
    2259             : 
    2260           0 :     switch( nFormat )
    2261             :     {
    2262             :     case SotClipboardFormatId::BITMAP:
    2263             :     case SotClipboardFormatId::PNG:
    2264             :     case SotClipboardFormatId::GDIMETAFILE:
    2265           0 :         nRet = rData.GetGraphic( nFormat, aGraphic );
    2266           0 :         break;
    2267             : 
    2268             :     case SotClipboardFormatId::SVXB:
    2269             :     {
    2270           0 :         tools::SvRef<SotStorageStream> xStm;
    2271             : 
    2272           0 :         if(rData.GetSotStorageStream(SotClipboardFormatId::SVXB, xStm))
    2273             :         {
    2274           0 :             ReadGraphic( *xStm, aGraphic );
    2275           0 :             nRet = (GRAPHIC_NONE != aGraphic.GetType() && GRAPHIC_DEFAULT != aGraphic.GetType());
    2276             :         }
    2277             : 
    2278           0 :         break;
    2279             :     }
    2280             : 
    2281             :     case SotClipboardFormatId::NETSCAPE_BOOKMARK:
    2282             :     case SotClipboardFormatId::FILEGRPDESCRIPTOR:
    2283             :     case SotClipboardFormatId::UNIFORMRESOURCELOCATOR:
    2284           0 :         if( ( nRet = rData.GetINetBookmark( nFormat, aBkmk ) ))
    2285             :         {
    2286           0 :             if( SW_PASTESDR_SETATTR == nAction )
    2287           0 :                 nFormat = SotClipboardFormatId::NETSCAPE_BOOKMARK;
    2288             :             else
    2289           0 :                 bCheckForGrf = true;
    2290             :         }
    2291           0 :         break;
    2292             : 
    2293             :     case SotClipboardFormatId::SIMPLE_FILE:
    2294             :         {
    2295           0 :             OUString sText;
    2296           0 :             if( ( nRet = rData.GetString( nFormat, sText ) ) )
    2297             :             {
    2298           0 :                 OUString sDesc;
    2299           0 :                 SwTransferable::_CheckForURLOrLNKFile( rData, sText, &sDesc );
    2300             : 
    2301           0 :                 aBkmk = INetBookmark(
    2302             :                         URIHelper::SmartRel2Abs(INetURLObject(), sText, Link<OUString *, bool>(), false ),
    2303           0 :                         sDesc );
    2304           0 :                 bCheckForGrf = true;
    2305           0 :                 bCheckForImageMap = SW_PASTESDR_REPLACE == nAction;
    2306           0 :             }
    2307             :         }
    2308           0 :         break;
    2309             : 
    2310             :     default:
    2311           0 :         nRet = rData.GetGraphic( nFormat, aGraphic );
    2312           0 :         break;
    2313             :     }
    2314             : 
    2315           0 :     if( bCheckForGrf )
    2316             :     {
    2317             :         //!!! check at FileSystem - only then it makes sense to test the graphics !!!
    2318           0 :         GraphicFilter &rFlt = GraphicFilter::GetGraphicFilter();
    2319           0 :         nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( aBkmk.GetURL(), aEmptyOUStr,
    2320           0 :                                             aGraphic, &rFlt );
    2321             : 
    2322           0 :         if( !nRet && SW_PASTESDR_SETATTR == nAction &&
    2323           0 :             SotClipboardFormatId::SIMPLE_FILE == nFormat &&
    2324             :             // only at frame selection
    2325           0 :             rSh.IsFrmSelected() )
    2326             :         {
    2327             :             // then set as hyperlink after the graphic
    2328           0 :             nFormat = SotClipboardFormatId::NETSCAPE_BOOKMARK;
    2329           0 :             nRet = true;
    2330             :         }
    2331             :     }
    2332             : 
    2333           0 :     if(pPt && bNeedToSelectBeforePaste)
    2334             :     {
    2335             :         // when using internal D&Ds, still the source object is selected and
    2336             :         // this is necessary to get the correct source data which is also
    2337             :         // dependent from selection. After receiving the drag data it is
    2338             :         // now tiime to select the correct target object
    2339           0 :         SwTransferable::SetSelInShell( rSh, true, pPt );
    2340             :     }
    2341             : 
    2342           0 :     if( nRet )
    2343             :     {
    2344             :         //Check and Perform rotation if needed
    2345           0 :         lclCheckAndPerformRotation(aGraphic);
    2346             : 
    2347           0 :         OUString sURL;
    2348           0 :         if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell)
    2349             :             // #i123922# if link action is noted, also take URL
    2350           0 :             || DND_ACTION_LINK == nDropAction)
    2351             :         {
    2352           0 :             sURL = aBkmk.GetURL();
    2353             :         }
    2354             : 
    2355           0 :         switch( nAction )
    2356             :         {
    2357             :             case SW_PASTESDR_INSERT:
    2358             :             {
    2359           0 :                 SwTransferable::SetSelInShell( rSh, false, pPt );
    2360           0 :                 rSh.Insert( sURL, aEmptyOUStr, aGraphic );
    2361           0 :                 break;
    2362             :             }
    2363             : 
    2364             :             case SW_PASTESDR_REPLACE:
    2365             :             {
    2366           0 :                 if( rSh.IsObjSelected() )
    2367             :                 {
    2368             :                     // #i123922# for D&D on draw objects, do for now the same for
    2369             :                     // SW_PASTESDR_REPLACE (D&D) as for SW_PASTESDR_SETATTR (D&D and
    2370             :                     // CTRL+SHIFT). The code below replaces the draw object with
    2371             :                     // a writer graphic; maybe this is an option later again if wanted
    2372           0 :                     rSh.Paste( aGraphic, sURL );
    2373             : 
    2374             :                     // rSh.ReplaceSdrObj( sURL, aEmptyOUStr, &aGraphic );
    2375             :                     // Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() );
    2376             :                     // SwTransferable::SetSelInShell( rSh, true, &aPt );
    2377             :                 }
    2378             :                 else
    2379             :                 {
    2380             :                     // set graphic at writer graphic without link
    2381           0 :                     rSh.ReRead( sURL, aEmptyOUStr, &aGraphic );
    2382             :                 }
    2383             : 
    2384           0 :                 break;
    2385             :             }
    2386             : 
    2387             :             case SW_PASTESDR_SETATTR:
    2388             :             {
    2389           0 :                 if( SotClipboardFormatId::NETSCAPE_BOOKMARK == nFormat )
    2390             :                 {
    2391           0 :                     if( rSh.IsFrmSelected() )
    2392             :                     {
    2393           0 :                         SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
    2394           0 :                         rSh.GetFlyFrmAttr( aSet );
    2395           0 :                         SwFormatURL aURL( static_cast<const SwFormatURL&>(aSet.Get( RES_URL )) );
    2396           0 :                         aURL.SetURL( aBkmk.GetURL(), false );
    2397           0 :                         aSet.Put( aURL );
    2398           0 :                         rSh.SetFlyFrmAttr( aSet );
    2399             :                     }
    2400             :                 }
    2401           0 :                 else if( rSh.IsObjSelected() )
    2402             :                 {
    2403             :                     // set as attribute at DrawObject
    2404           0 :                     rSh.Paste( aGraphic, sURL );
    2405             :                 }
    2406           0 :                 else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() )
    2407             :                 {
    2408             :                     // set as linked graphic at writer graphic frame
    2409           0 :                     rSh.ReRead( sURL, aEmptyOUStr, &aGraphic );
    2410             :                 }
    2411             :                 else
    2412             :                 {
    2413           0 :                     SwTransferable::SetSelInShell( rSh, false, pPt );
    2414           0 :                     rSh.Insert( aBkmk.GetURL(), aEmptyOUStr, aGraphic );
    2415             :                 }
    2416           0 :                 break;
    2417             :             }
    2418             :             default:
    2419             :             {
    2420           0 :                 nRet = false;
    2421           0 :                 break;
    2422             :             }
    2423           0 :         }
    2424             :     }
    2425             : 
    2426           0 :     if( nRet )
    2427             :     {
    2428             : 
    2429           0 :         if( nActionFlags &
    2430             :             (( EXCHG_OUT_ACTION_FLAG_INSERT_IMAGEMAP |
    2431             :                 EXCHG_OUT_ACTION_FLAG_REPLACE_IMAGEMAP ) >> 8) )
    2432           0 :             SwTransferable::_PasteImageMap( rData, rSh );
    2433             : 
    2434           0 :         if( nActionFlags &
    2435             :             ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) )
    2436           0 :             SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, false );
    2437             :     }
    2438           0 :     else if( bCheckForImageMap )
    2439             :     {
    2440             :         // or should the file be an ImageMap-File?
    2441           0 :         ImageMap aMap;
    2442           0 :         SfxMedium aMed( INetURLObject(aBkmk.GetURL()).GetFull(),
    2443           0 :                             STREAM_STD_READ );
    2444           0 :         SvStream* pStream = aMed.GetInStream();
    2445           0 :         if( pStream != NULL  &&
    2446           0 :             !pStream->GetError()  &&
    2447             :             // mba: no BaseURL for clipboard functionality
    2448           0 :             aMap.Read( *pStream, IMAP_FORMAT_DETECT, OUString() ) == IMAP_ERR_OK &&
    2449           0 :             aMap.GetIMapObjectCount() )
    2450             :         {
    2451           0 :             SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
    2452           0 :             rSh.GetFlyFrmAttr( aSet );
    2453           0 :             SwFormatURL aURL( static_cast<const SwFormatURL&>(aSet.Get( RES_URL )) );
    2454           0 :             aURL.SetMap( &aMap );
    2455           0 :             aSet.Put( aURL );
    2456           0 :             rSh.SetFlyFrmAttr( aSet );
    2457           0 :             nRet = true;
    2458           0 :         }
    2459             :     }
    2460             : 
    2461           0 :     return nRet;
    2462             : }
    2463             : 
    2464           0 : bool SwTransferable::_PasteImageMap( TransferableDataHelper& rData,
    2465             :                                     SwWrtShell& rSh )
    2466             : {
    2467           0 :     bool nRet = false;
    2468           0 :     if( rData.HasFormat( SotClipboardFormatId::SVIM ))
    2469             :     {
    2470           0 :         SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
    2471           0 :         rSh.GetFlyFrmAttr( aSet );
    2472           0 :         SwFormatURL aURL( static_cast<const SwFormatURL&>(aSet.Get( RES_URL )) );
    2473           0 :         const ImageMap* pOld = aURL.GetMap();
    2474             : 
    2475             :         // set or replace, that is the question
    2476           0 :         ImageMap aImageMap;
    2477           0 :         if( rData.GetImageMap( SotClipboardFormatId::SVIM, aImageMap ) &&
    2478           0 :             ( !pOld || aImageMap != *pOld ))
    2479             :         {
    2480           0 :             aURL.SetMap( &aImageMap );
    2481           0 :             aSet.Put( aURL );
    2482           0 :             rSh.SetFlyFrmAttr( aSet );
    2483             :         }
    2484           0 :         nRet = true;
    2485             :     }
    2486           0 :     return nRet;
    2487             : }
    2488             : 
    2489           0 : bool SwTransferable::_PasteAsHyperlink( TransferableDataHelper& rData,
    2490             :                                         SwWrtShell& rSh, SotClipboardFormatId nFormat )
    2491             : {
    2492           0 :     bool nRet = false;
    2493           0 :     OUString sFile;
    2494           0 :     if( rData.GetString( nFormat, sFile ) && !sFile.isEmpty() )
    2495             :     {
    2496           0 :         OUString sDesc;
    2497           0 :         SwTransferable::_CheckForURLOrLNKFile( rData, sFile, &sDesc );
    2498             : 
    2499             :         // first, make the URL absolute
    2500           0 :         INetURLObject aURL;
    2501           0 :         aURL.SetSmartProtocol( INetProtocol::File );
    2502           0 :         aURL.SetSmartURL( sFile );
    2503           0 :         sFile = aURL.GetMainURL( INetURLObject::NO_DECODE );
    2504             : 
    2505           0 :         switch( rSh.GetObjCntTypeOfSelection() )
    2506             :         {
    2507             :         case OBJCNT_FLY:
    2508             :         case OBJCNT_GRF:
    2509             :         case OBJCNT_OLE:
    2510             :             {
    2511           0 :                 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
    2512           0 :                 rSh.GetFlyFrmAttr( aSet );
    2513           0 :                 SwFormatURL aURL2( static_cast<const SwFormatURL&>(aSet.Get( RES_URL )) );
    2514           0 :                 aURL2.SetURL( sFile, false );
    2515           0 :                 if( aURL2.GetName().isEmpty() )
    2516           0 :                     aURL2.SetName( sFile );
    2517           0 :                 aSet.Put( aURL2 );
    2518           0 :                 rSh.SetFlyFrmAttr( aSet );
    2519             :             }
    2520           0 :             break;
    2521             : 
    2522             :         default:
    2523             :             {
    2524             :                 rSh.InsertURL( SwFormatINetFormat( sFile, OUString() ),
    2525           0 :                                 sDesc.isEmpty() ? sFile : sDesc);
    2526             :             }
    2527             :         }
    2528           0 :         nRet = true;
    2529             :     }
    2530           0 :     return nRet;
    2531             : }
    2532             : 
    2533           0 : bool SwTransferable::_PasteFileName( TransferableDataHelper& rData,
    2534             :                                     SwWrtShell& rSh, SotClipboardFormatId nFormat,
    2535             :                                     sal_uInt16 nAction, const Point* pPt,
    2536             :                     sal_uInt8 nActionFlags, bool /* bMsg */,
    2537             :                     bool * graphicInserted)
    2538             : {
    2539             :     bool nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat, nAction,
    2540           0 :                                             pPt, nActionFlags, 0, false);
    2541           0 :     if (graphicInserted != 0) {
    2542           0 :         *graphicInserted = nRet;
    2543             :     }
    2544           0 :     if( !nRet )
    2545             :     {
    2546           0 :         OUString sFile, sDesc;
    2547           0 :         if( rData.GetString( nFormat, sFile ) && !sFile.isEmpty() )
    2548             :         {
    2549             : #if HAVE_FEATURE_AVMEDIA
    2550           0 :             INetURLObject aMediaURL;
    2551             : 
    2552           0 :             aMediaURL.SetSmartURL( sFile );
    2553           0 :             const OUString aMediaURLStr( aMediaURL.GetMainURL( INetURLObject::NO_DECODE ) );
    2554             : 
    2555           0 :             if( ::avmedia::MediaWindow::isMediaURL( aMediaURLStr, ""/*TODO?*/ ) )
    2556             :             {
    2557           0 :                 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aMediaURLStr );
    2558           0 :                 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(
    2559             :                                 SID_INSERT_AVMEDIA, SfxCallMode::SYNCHRON,
    2560           0 :                                 &aMediaURLItem, 0L );
    2561             :             }
    2562             : #else
    2563             :             if (false)
    2564             :             {
    2565             :             }
    2566             : #endif
    2567             :             else
    2568             :             {
    2569           0 :                 bool bIsURLFile = SwTransferable::_CheckForURLOrLNKFile( rData, sFile, &sDesc );
    2570             : 
    2571             :                 //Own FileFormat? --> insert, not for StarWriter/Web
    2572           0 :                 OUString sFileURL = URIHelper::SmartRel2Abs(INetURLObject(), sFile, Link<OUString *, bool>(), false );
    2573             :                 const SfxFilter* pFlt = SW_PASTESDR_SETATTR == nAction
    2574           0 :                         ? 0 : SwIoSystem::GetFileFilter(sFileURL);
    2575           0 :                 if( pFlt && !rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
    2576             :                 {
    2577             :                 // and then pull up the insert-region-dialog by PostUser event
    2578             :                     SwSectionData * pSect = new SwSectionData(
    2579             :                                     FILE_LINK_SECTION,
    2580           0 :                                     rSh.GetDoc()->GetUniqueSectionName() );
    2581           0 :                     pSect->SetLinkFileName( sFileURL );
    2582           0 :                     pSect->SetProtectFlag( true );
    2583             : 
    2584             :                     Application::PostUserEvent( LINK( &rSh, SwWrtShell,
    2585           0 :                                                       InsertRegionDialog ), pSect );
    2586           0 :                     nRet = true;
    2587             :                     }
    2588           0 :                 else if( SW_PASTESDR_SETATTR == nAction ||
    2589           0 :                         ( bIsURLFile && SW_PASTESDR_INSERT == nAction ))
    2590             :                 {
    2591             :                     //we can insert foreign files as links after all
    2592             : 
    2593             :                     // first, make the URL absolute
    2594           0 :                     INetURLObject aURL;
    2595           0 :                     aURL.SetSmartProtocol( INetProtocol::File );
    2596           0 :                     aURL.SetSmartURL( sFile );
    2597           0 :                     sFile = aURL.GetMainURL( INetURLObject::NO_DECODE );
    2598             : 
    2599           0 :                     switch( rSh.GetObjCntTypeOfSelection() )
    2600             :                     {
    2601             :                     case OBJCNT_FLY:
    2602             :                     case OBJCNT_GRF:
    2603             :                     case OBJCNT_OLE:
    2604             :                         {
    2605           0 :                             SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
    2606           0 :                             rSh.GetFlyFrmAttr( aSet );
    2607           0 :                             SwFormatURL aURL2( static_cast<const SwFormatURL&>(aSet.Get( RES_URL )) );
    2608           0 :                             aURL2.SetURL( sFile, false );
    2609           0 :                             if( aURL2.GetName().isEmpty() )
    2610           0 :                                 aURL2.SetName( sFile );
    2611           0 :                             aSet.Put( aURL2 );
    2612           0 :                             rSh.SetFlyFrmAttr( aSet );
    2613             :                         }
    2614           0 :                         break;
    2615             : 
    2616             :                     default:
    2617             :                         {
    2618             :                             rSh.InsertURL( SwFormatINetFormat( sFile, OUString() ),
    2619           0 :                                             sDesc.isEmpty() ? sFile : sDesc );
    2620             :                         }
    2621             :                     }
    2622           0 :                     nRet = true;
    2623           0 :                 }
    2624           0 :             }
    2625           0 :         }
    2626             :     }
    2627           0 :     return nRet;
    2628             : }
    2629             : 
    2630           0 : bool SwTransferable::_PasteDBData( TransferableDataHelper& rData,
    2631             :                                     SwWrtShell& rSh, SotClipboardFormatId nFormat, bool bLink,
    2632             :                                     const Point* pDragPt, bool bMsg )
    2633             : {
    2634           0 :     bool nRet = false;
    2635           0 :     OUString sText;
    2636           0 :     if( rData.GetString( nFormat, sText ) && !sText.isEmpty() )
    2637             :     {
    2638             :         sal_uInt16 nWh = SotClipboardFormatId::SBA_CTRLDATAEXCHANGE == nFormat
    2639             :                     ? 0
    2640             :                     : SotClipboardFormatId::SBA_DATAEXCHANGE == nFormat
    2641             :                                 ? (bLink
    2642             :                                     ? FN_QRY_MERGE_FIELD
    2643             :                                     : FN_QRY_INSERT)
    2644             :                                 : (bLink
    2645             :                                     ? 0
    2646           0 :                                     : FN_QRY_INSERT_FIELD );
    2647           0 :         DataFlavorExVector& rVector = rData.GetDataFlavorExVector();
    2648           0 :         bool bHaveColumnDescriptor = OColumnTransferable::canExtractColumnDescriptor(rVector, ColumnTransferFormatFlags::COLUMN_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE);
    2649           0 :         if ( SotClipboardFormatId::XFORMS == nFormat )
    2650             :         {
    2651           0 :             rSh.MakeDrawView();
    2652           0 :             FmFormView* pFmView = PTR_CAST( FmFormView, rSh.GetDrawView() );
    2653           0 :             if(pFmView) {
    2654           0 :                 const OXFormsDescriptor &rDesc = OXFormsTransferable::extractDescriptor(rData);
    2655           0 :                 SdrObject* pObj = pFmView->CreateXFormsControl(rDesc);
    2656           0 :                 if(0 != pObj)
    2657             :                 {
    2658           0 :                     rSh.SwFEShell::InsertDrawObj( *pObj, *pDragPt );
    2659             :                 }
    2660             :             }
    2661             :         }
    2662           0 :         else if( nWh )
    2663             :         {
    2664           0 :             boost::scoped_ptr<SfxUsrAnyItem> pConnectionItem;
    2665           0 :             boost::scoped_ptr<SfxUsrAnyItem> pCursorItem;
    2666           0 :             boost::scoped_ptr<SfxUsrAnyItem> pColumnItem;
    2667           0 :             boost::scoped_ptr<SfxUsrAnyItem> pSourceItem;
    2668           0 :             boost::scoped_ptr<SfxUsrAnyItem> pCommandItem;
    2669           0 :             boost::scoped_ptr<SfxUsrAnyItem> pCommandTypeItem;
    2670           0 :             boost::scoped_ptr<SfxUsrAnyItem> pColumnNameItem;
    2671           0 :             boost::scoped_ptr<SfxUsrAnyItem> pSelectionItem;
    2672             : 
    2673           0 :             bool bDataAvailable = true;
    2674           0 :             ODataAccessDescriptor aDesc;
    2675           0 :             if(bHaveColumnDescriptor)
    2676           0 :                 aDesc = OColumnTransferable::extractColumnDescriptor(rData);
    2677           0 :             else if(ODataAccessObjectTransferable::canExtractObjectDescriptor(rVector) )
    2678           0 :                 aDesc = ODataAccessObjectTransferable::extractObjectDescriptor(rData);
    2679             :             else
    2680           0 :                 bDataAvailable = false;
    2681             : 
    2682           0 :             if ( bDataAvailable )
    2683             :             {
    2684           0 :                 pConnectionItem.reset(new SfxUsrAnyItem(FN_DB_CONNECTION_ANY, aDesc[daConnection]));
    2685           0 :                 pColumnItem.reset(new SfxUsrAnyItem(FN_DB_COLUMN_ANY, aDesc[daColumnObject]));
    2686           0 :                 pSourceItem.reset(new SfxUsrAnyItem(FN_DB_DATA_SOURCE_ANY, makeAny(aDesc.getDataSource())));
    2687           0 :                 pCommandItem.reset(new SfxUsrAnyItem(FN_DB_DATA_COMMAND_ANY, aDesc[daCommand]));
    2688           0 :                 pCommandTypeItem.reset(new SfxUsrAnyItem(FN_DB_DATA_COMMAND_TYPE_ANY, aDesc[daCommandType]));
    2689           0 :                 pColumnNameItem.reset(new SfxUsrAnyItem(FN_DB_DATA_COLUMN_NAME_ANY, aDesc[daColumnName]));
    2690           0 :                 pSelectionItem.reset(new SfxUsrAnyItem(FN_DB_DATA_SELECTION_ANY, aDesc[daSelection]));
    2691           0 :                 pCursorItem.reset(new SfxUsrAnyItem(FN_DB_DATA_CURSOR_ANY, aDesc[daCursor]));
    2692             :             }
    2693             : 
    2694           0 :             SwView& rView = rSh.GetView();
    2695             :             //force ::SelectShell
    2696           0 :             rView.StopShellTimer();
    2697             : 
    2698           0 :             SfxStringItem aDataDesc( nWh, sText );
    2699             :             rView.GetViewFrame()->GetDispatcher()->Execute(
    2700             :                                 nWh, SfxCallMode::ASYNCHRON, &aDataDesc,
    2701             :                                 pConnectionItem.get(), pColumnItem.get(),
    2702             :                                 pSourceItem.get(), pCommandItem.get(), pCommandTypeItem.get(),
    2703           0 :                                 pColumnNameItem.get(), pSelectionItem.get(), pCursorItem.get(), 0L);
    2704             :         }
    2705             :         else
    2706             :         {
    2707           0 :             rSh.MakeDrawView();
    2708           0 :             FmFormView* pFmView = PTR_CAST( FmFormView, rSh.GetDrawView() );
    2709           0 :             if (pFmView && bHaveColumnDescriptor)
    2710             :             {
    2711           0 :                 SdrObject* pObj = pFmView->CreateFieldControl( OColumnTransferable::extractColumnDescriptor(rData) );
    2712           0 :                 if ( 0 != pObj)
    2713           0 :                     rSh.SwFEShell::InsertDrawObj( *pObj, *pDragPt );
    2714             :             }
    2715             :         }
    2716           0 :         nRet = true;
    2717             :     }
    2718           0 :     else if( bMsg )
    2719             :     {
    2720           0 :         ScopedVclPtrInstance<MessageDialog>::Create( nullptr, SW_RES(STR_CLPBRD_FORMAT_ERROR), VCL_MESSAGE_INFO)->Execute();
    2721             :     }
    2722           0 :     return nRet;
    2723             : }
    2724             : 
    2725           0 : bool SwTransferable::_PasteFileList( TransferableDataHelper& rData,
    2726             :                                     SwWrtShell& rSh, bool bLink,
    2727             :                                     const Point* pPt, bool bMsg )
    2728             : {
    2729           0 :     bool nRet = false;
    2730           0 :     FileList aFileList;
    2731           0 :     if( rData.GetFileList( SotClipboardFormatId::FILE_LIST, aFileList ) &&
    2732           0 :         aFileList.Count() )
    2733             :     {
    2734           0 :         sal_uInt16 nAct = bLink ? SW_PASTESDR_SETATTR : SW_PASTESDR_INSERT;
    2735           0 :         OUString sFlyNm;
    2736             :         // iterate over the filelist
    2737           0 :         for( sal_uLong n = 0, nEnd = aFileList.Count(); n < nEnd; ++n )
    2738             :         {
    2739           0 :             TransferDataContainer* pHlp = new TransferDataContainer;
    2740           0 :             pHlp->CopyString( SotClipboardFormatId::SIMPLE_FILE, aFileList.GetFile( n ));
    2741           0 :             TransferableDataHelper aData( pHlp );
    2742             : 
    2743           0 :             if( SwTransferable::_PasteFileName( aData, rSh, SotClipboardFormatId::SIMPLE_FILE, nAct,
    2744           0 :                                             pPt, 0, bMsg, 0 ))
    2745             :             {
    2746           0 :                 if( bLink )
    2747             :                 {
    2748           0 :                     sFlyNm = rSh.GetFlyName();
    2749           0 :                     SwTransferable::SetSelInShell( rSh, false, pPt );
    2750             :                 }
    2751           0 :                 nRet = true;
    2752             :             }
    2753           0 :         }
    2754           0 :         if( !sFlyNm.isEmpty() )
    2755           0 :             rSh.GotoFly( sFlyNm );
    2756             :     }
    2757           0 :     else if( bMsg )
    2758             :     {
    2759           0 :         ScopedVclPtrInstance<MessageDialog>::Create( nullptr, SW_RES(STR_CLPBRD_FORMAT_ERROR), VCL_MESSAGE_INFO)->Execute();
    2760             :     }
    2761           0 :     return nRet;
    2762             : }
    2763             : 
    2764           0 : bool SwTransferable::_CheckForURLOrLNKFile( TransferableDataHelper& rData,
    2765             :                                         OUString& rFileName, OUString* pTitle )
    2766             : {
    2767           0 :     bool bIsURLFile = false;
    2768           0 :     INetBookmark aBkmk;
    2769           0 :     if( rData.GetINetBookmark( SotClipboardFormatId::SOLK, aBkmk ) )
    2770             :     {
    2771           0 :         rFileName = aBkmk.GetURL();
    2772           0 :         if( pTitle )
    2773           0 :             *pTitle = aBkmk.GetDescription();
    2774           0 :         bIsURLFile = true;
    2775             :     }
    2776             :     else
    2777             :     {
    2778           0 :         sal_Int32 nLen = rFileName.getLength();
    2779           0 :         if( 4 < nLen && '.' == rFileName[ nLen - 4 ])
    2780             :         {
    2781           0 :             OUString sExt( rFileName.copy( nLen - 3 ));
    2782           0 :             if( sExt.equalsIgnoreAsciiCase( "url" ))
    2783             :             {
    2784             :                 OSL_ENSURE( false, "how do we read today .URL - Files?" );
    2785           0 :             }
    2786             :         }
    2787             :     }
    2788           0 :     return bIsURLFile;
    2789             : }
    2790             : 
    2791           0 : bool SwTransferable::IsPasteSpecial( const SwWrtShell& rWrtShell,
    2792             :                                      const TransferableDataHelper& rData )
    2793             : {
    2794             :     // we can paste-special if there's an entry in the paste-special-format list
    2795           0 :     SvxClipboardFormatItem aClipboardFormatItem(0);
    2796           0 :     FillClipFormatItem( rWrtShell, rData, aClipboardFormatItem);
    2797           0 :     return aClipboardFormatItem.Count() > 0;
    2798             : }
    2799             : 
    2800           0 : bool SwTransferable::PasteFormat( SwWrtShell& rSh,
    2801             :                                     TransferableDataHelper& rData,
    2802             :                                     SotClipboardFormatId nFormat )
    2803             : {
    2804           0 :     SwWait aWait( *rSh.GetView().GetDocShell(), false );
    2805           0 :     bool nRet = false;
    2806             : 
    2807           0 :     SotClipboardFormatId nPrivateFormat = SotClipboardFormatId::PRIVATE;
    2808           0 :     SwTransferable *pClipboard = GetSwTransferable( rData );
    2809           0 :     if( pClipboard &&
    2810           0 :         ((TRNSFR_DOCUMENT|TRNSFR_GRAPHIC|TRNSFR_OLE) & pClipboard->eBufferType ))
    2811           0 :         nPrivateFormat = SotClipboardFormatId::EMBED_SOURCE;
    2812             : 
    2813           0 :     if( pClipboard && nPrivateFormat == nFormat )
    2814           0 :         nRet = pClipboard->PrivatePaste( rSh );
    2815           0 :     else if( rData.HasFormat( nFormat ) )
    2816             :     {
    2817           0 :         uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
    2818             :         sal_uInt16      nEventAction;
    2819           0 :         SotExchangeDest nDestination = SwTransferable::GetSotDestination( rSh );
    2820             :         sal_uInt16      nSourceOptions =
    2821           0 :                     (( SotExchangeDest::DOC_TEXTFRAME == nDestination ||
    2822           0 :                        SotExchangeDest::SWDOC_FREE_AREA == nDestination ||
    2823           0 :                        SotExchangeDest::DOC_TEXTFRAME_WEB == nDestination ||
    2824             :                        SotExchangeDest::SWDOC_FREE_AREA_WEB == nDestination )
    2825             :                                         ? EXCHG_IN_ACTION_COPY
    2826           0 :                                         : EXCHG_IN_ACTION_MOVE);
    2827             :         sal_uInt16      nAction = SotExchange::GetExchangeAction(
    2828           0 :                                     rData.GetDataFlavorExVector(),
    2829             :                                     nDestination,
    2830             :                                     nSourceOptions,             /* ?? */
    2831             :                                     EXCHG_IN_ACTION_DEFAULT,    /* ?? */
    2832             :                                     nFormat, nEventAction, nFormat,
    2833           0 :                                     lcl_getTransferPointer ( xTransferable ) );
    2834             : 
    2835           0 :         if( EXCHG_INOUT_ACTION_NONE != nAction )
    2836             :             nRet = SwTransferable::PasteData( rData, rSh, nAction, nFormat,
    2837           0 :                                                 nDestination, true, false );
    2838             :     }
    2839           0 :     return nRet;
    2840             : }
    2841             : 
    2842       20944 : bool SwTransferable::_TestAllowedFormat( const TransferableDataHelper& rData,
    2843             :                                         SotClipboardFormatId nFormat, SotExchangeDest nDestination )
    2844             : {
    2845       20944 :     sal_uInt16 nAction = EXCHG_INOUT_ACTION_NONE, nEventAction;
    2846       20944 :     if( rData.HasFormat( nFormat )) {
    2847           0 :         uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
    2848             :         nAction = SotExchange::GetExchangeAction(
    2849           0 :                         rData.GetDataFlavorExVector(),
    2850             :                         nDestination, EXCHG_IN_ACTION_COPY,
    2851             :                         EXCHG_IN_ACTION_COPY, nFormat,
    2852             :                         nEventAction, nFormat,
    2853           0 :                         lcl_getTransferPointer ( xTransferable ) );
    2854             :     }
    2855       20944 :     return EXCHG_INOUT_ACTION_NONE != nAction;
    2856             : }
    2857             : 
    2858             : /**
    2859             :  * the list of formats which will be offered to the user in the 'Paste
    2860             :  * Special...' dialog and the paste button menu
    2861             :  */
    2862             : static SotClipboardFormatId aPasteSpecialIds[] =
    2863             : {
    2864             :     SotClipboardFormatId::HTML,
    2865             :     SotClipboardFormatId::HTML_SIMPLE,
    2866             :     SotClipboardFormatId::HTML_NO_COMMENT,
    2867             :     SotClipboardFormatId::RTF,
    2868             :     SotClipboardFormatId::STRING,
    2869             :     SotClipboardFormatId::SONLK,
    2870             :     SotClipboardFormatId::NETSCAPE_BOOKMARK,
    2871             :     SotClipboardFormatId::DRAWING,
    2872             :     SotClipboardFormatId::SVXB,
    2873             :     SotClipboardFormatId::GDIMETAFILE,
    2874             :     SotClipboardFormatId::BITMAP,
    2875             :     SotClipboardFormatId::SVIM,
    2876             :     SotClipboardFormatId::FILEGRPDESCRIPTOR,
    2877             :     SotClipboardFormatId::NONE
    2878             : };
    2879             : 
    2880           0 : bool SwTransferable::PasteUnformatted( SwWrtShell& rSh, TransferableDataHelper& rData )
    2881             : {
    2882             :     // Plain text == unformatted
    2883           0 :     return SwTransferable::PasteFormat( rSh, rData, SotClipboardFormatId::STRING );
    2884             : }
    2885             : 
    2886           0 : bool SwTransferable::PasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rData, SotClipboardFormatId& rFormatUsed )
    2887             : {
    2888           0 :     bool nRet = false;
    2889           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    2890           0 :     boost::scoped_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( &rSh.GetView().GetEditWin() ));
    2891             : 
    2892           0 :     DataFlavorExVector aFormats( rData.GetDataFlavorExVector() );
    2893           0 :     TransferableObjectDescriptor aDesc;
    2894             : 
    2895           0 :     SotExchangeDest nDest = SwTransferable::GetSotDestination( rSh );
    2896             : 
    2897           0 :     SwTransferable *pClipboard = GetSwTransferable( rData );
    2898           0 :     if( pClipboard )
    2899             :     {
    2900           0 :         aDesc = pClipboard->aObjDesc;
    2901             :         sal_uInt16 nResId;
    2902           0 :         if( pClipboard->eBufferType & TRNSFR_DOCUMENT )
    2903           0 :             nResId = STR_PRIVATETEXT;
    2904           0 :         else if( pClipboard->eBufferType & TRNSFR_GRAPHIC )
    2905           0 :             nResId = STR_PRIVATEGRAPHIC;
    2906           0 :         else if( pClipboard->eBufferType == TRNSFR_OLE )
    2907           0 :             nResId = STR_PRIVATEOLE;
    2908             :         else
    2909           0 :             nResId = 0;
    2910             : 
    2911           0 :         if( nResId )
    2912             :         {
    2913           0 :             if( STR_PRIVATEOLE == nResId || STR_PRIVATEGRAPHIC == nResId )
    2914             :             {
    2915             :                 // add SotClipboardFormatId::EMBED_SOURCE to the formats. This
    2916             :                 // format display then the private format name.
    2917           0 :                 DataFlavorEx aFlavorEx;
    2918           0 :                 aFlavorEx.mnSotId = SotClipboardFormatId::EMBED_SOURCE;
    2919           0 :                 aFormats.insert( aFormats.begin(), aFlavorEx );
    2920             :             }
    2921           0 :             pDlg->SetObjName( pClipboard->aObjDesc.maClassName,
    2922           0 :                                 SW_RES( nResId ) );
    2923           0 :             pDlg->Insert( SotClipboardFormatId::EMBED_SOURCE, aEmptyOUStr );
    2924             :         }
    2925             :     }
    2926             :     else
    2927             :     {
    2928           0 :         if( rData.HasFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ) )
    2929             :         {
    2930             :             (void)rData.GetTransferableObjectDescriptor(
    2931           0 :                                 SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc );
    2932             :         }
    2933             : 
    2934           0 :         if( SwTransferable::_TestAllowedFormat( rData, SotClipboardFormatId::EMBED_SOURCE, nDest ))
    2935           0 :             pDlg->Insert( SotClipboardFormatId::EMBED_SOURCE, aEmptyOUStr );
    2936           0 :         if( SwTransferable::_TestAllowedFormat( rData, SotClipboardFormatId::LINK_SOURCE, nDest ))
    2937           0 :             pDlg->Insert( SotClipboardFormatId::LINK_SOURCE, aEmptyOUStr );
    2938             :     }
    2939             : 
    2940           0 :     if( SwTransferable::_TestAllowedFormat( rData, SotClipboardFormatId::LINK, nDest ))
    2941           0 :         pDlg->Insert( SotClipboardFormatId::LINK, SW_RES(STR_DDEFORMAT) );
    2942             : 
    2943           0 :     for( SotClipboardFormatId* pIds = aPasteSpecialIds; *pIds != SotClipboardFormatId::NONE; ++pIds )
    2944           0 :         if( SwTransferable::_TestAllowedFormat( rData, *pIds, nDest ))
    2945           0 :             pDlg->Insert( *pIds, aEmptyOUStr );
    2946             : 
    2947           0 :     SotClipboardFormatId nFormat = pDlg->GetFormat( rData.GetTransferable() );
    2948             : 
    2949           0 :     if( nFormat != SotClipboardFormatId::NONE )
    2950           0 :         nRet = SwTransferable::PasteFormat( rSh, rData, nFormat );
    2951             : 
    2952           0 :     if ( nRet )
    2953           0 :         rFormatUsed = nFormat;
    2954             : 
    2955           0 :     return nRet;
    2956             : }
    2957             : 
    2958        1309 : void SwTransferable::FillClipFormatItem( const SwWrtShell& rSh,
    2959             :                                 const TransferableDataHelper& rData,
    2960             :                                 SvxClipboardFormatItem & rToFill )
    2961             : {
    2962        1309 :     SotExchangeDest nDest = SwTransferable::GetSotDestination( rSh );
    2963             : 
    2964        1309 :     SwTransferable *pClipboard = GetSwTransferable( rData );
    2965        1309 :     if( pClipboard )
    2966             :     {
    2967             :         sal_uInt16 nResId;
    2968           0 :         if( pClipboard->eBufferType & TRNSFR_DOCUMENT )
    2969           0 :             nResId = STR_PRIVATETEXT;
    2970           0 :         else if( pClipboard->eBufferType & TRNSFR_GRAPHIC )
    2971           0 :             nResId = STR_PRIVATEGRAPHIC;
    2972           0 :         else if( pClipboard->eBufferType == TRNSFR_OLE )
    2973           0 :             nResId = STR_PRIVATEOLE;
    2974             :         else
    2975           0 :             nResId = 0;
    2976             : 
    2977           0 :         if( nResId )
    2978             :             rToFill.AddClipbrdFormat( SotClipboardFormatId::EMBED_SOURCE,
    2979           0 :                                         SW_RESSTR( nResId ) );
    2980             :     }
    2981             :     else
    2982             :     {
    2983        1309 :         TransferableObjectDescriptor aDesc;
    2984        1309 :         if (rData.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR))
    2985             :         {
    2986             :             (void)const_cast<TransferableDataHelper&>(rData).GetTransferableObjectDescriptor(
    2987           0 :                                 SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc);
    2988             :         }
    2989             : 
    2990        1309 :         if( SwTransferable::_TestAllowedFormat( rData, SotClipboardFormatId::EMBED_SOURCE, nDest ))
    2991             :             rToFill.AddClipbrdFormat( SotClipboardFormatId::EMBED_SOURCE,
    2992           0 :                                             aDesc.maTypeName );
    2993        1309 :         if( SwTransferable::_TestAllowedFormat( rData, SotClipboardFormatId::LINK_SOURCE, nDest ))
    2994           0 :             rToFill.AddClipbrdFormat( SotClipboardFormatId::LINK_SOURCE );
    2995             : 
    2996             :         SotClipboardFormatId nFormat;
    2997        1309 :         if ( rData.HasFormat(nFormat = SotClipboardFormatId::EMBED_SOURCE_OLE) || rData.HasFormat(nFormat = SotClipboardFormatId::EMBEDDED_OBJ_OLE) )
    2998             :         {
    2999           0 :             OUString sName,sSource;
    3000           0 :             if ( SvPasteObjectHelper::GetEmbeddedName(rData,sName,sSource,nFormat) )
    3001           0 :                 rToFill.AddClipbrdFormat( nFormat, sName );
    3002        1309 :         }
    3003             :     }
    3004             : 
    3005        1309 :     if( SwTransferable::_TestAllowedFormat( rData, SotClipboardFormatId::LINK, nDest ))
    3006           0 :         rToFill.AddClipbrdFormat( SotClipboardFormatId::LINK, SW_RESSTR(STR_DDEFORMAT) );
    3007             : 
    3008       18326 :     for( SotClipboardFormatId* pIds = aPasteSpecialIds; *pIds != SotClipboardFormatId::NONE; ++pIds )
    3009       17017 :         if( SwTransferable::_TestAllowedFormat( rData, *pIds, nDest ))
    3010           0 :             rToFill.AddClipbrdFormat( *pIds, aEmptyOUStr );
    3011        1309 : }
    3012             : 
    3013           0 : void SwTransferable::SetDataForDragAndDrop( const Point& rSttPos )
    3014             : {
    3015           0 :     if(!pWrtShell)
    3016           0 :         return;
    3017           0 :     OUString sGrfNm;
    3018           0 :     const int nSelection = pWrtShell->GetSelectionType();
    3019           0 :     if( nsSelectionType::SEL_GRF == nSelection)
    3020             :     {
    3021           0 :         AddFormat( SotClipboardFormatId::SVXB );
    3022           0 :         const Graphic* pGrf = pWrtShell->GetGraphic();
    3023           0 :         if ( pGrf && pGrf->IsSupportedGraphic() )
    3024             :         {
    3025           0 :             AddFormat( SotClipboardFormatId::GDIMETAFILE );
    3026           0 :             AddFormat( SotClipboardFormatId::PNG );
    3027           0 :             AddFormat( SotClipboardFormatId::BITMAP );
    3028             :         }
    3029           0 :         eBufferType = TRNSFR_GRAPHIC;
    3030           0 :         pWrtShell->GetGrfNms( &sGrfNm, 0 );
    3031             :     }
    3032           0 :     else if( nsSelectionType::SEL_OLE == nSelection )
    3033             :     {
    3034           0 :         AddFormat( SotClipboardFormatId::EMBED_SOURCE );
    3035           0 :         PrepareOLE( aObjDesc );
    3036           0 :         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
    3037           0 :         AddFormat( SotClipboardFormatId::GDIMETAFILE );
    3038           0 :         eBufferType = TRNSFR_OLE;
    3039             :     }
    3040             :     //Is there anything to provide anyway?
    3041           0 :     else if ( pWrtShell->IsSelection() || pWrtShell->IsFrmSelected() ||
    3042           0 :               pWrtShell->IsObjSelected() )
    3043             :     {
    3044           0 :         if( pWrtShell->IsObjSelected() )
    3045           0 :             eBufferType = TRNSFR_DRAWING;
    3046             :         else
    3047             :         {
    3048           0 :             eBufferType = TRNSFR_DOCUMENT;
    3049           0 :             if( SwWrtShell::NO_WORD !=
    3050           0 :                 pWrtShell->IntelligentCut( nSelection, false ))
    3051             :                 eBufferType = TransferBufferType( TRNSFR_DOCUMENT_WORD
    3052           0 :                                                     | eBufferType);
    3053             :         }
    3054             : 
    3055           0 :         if( nSelection & nsSelectionType::SEL_TBL_CELLS )
    3056           0 :             eBufferType = (TransferBufferType)(TRNSFR_TABELLE | eBufferType);
    3057             : 
    3058           0 :         AddFormat( SotClipboardFormatId::EMBED_SOURCE );
    3059             : 
    3060             :         //put RTF ahead of the OLE's Metafile for less loss
    3061           0 :         if( !pWrtShell->IsObjSelected() )
    3062             :         {
    3063           0 :             AddFormat( SotClipboardFormatId::RTF );
    3064           0 :             AddFormat( SotClipboardFormatId::HTML );
    3065             :         }
    3066           0 :         if( pWrtShell->IsSelection() )
    3067           0 :             AddFormat( SotClipboardFormatId::STRING );
    3068             : 
    3069           0 :         if( nSelection & ( nsSelectionType::SEL_DRW | nsSelectionType::SEL_DRW_FORM ))
    3070             :         {
    3071           0 :             AddFormat( SotClipboardFormatId::DRAWING );
    3072           0 :             if ( nSelection & nsSelectionType::SEL_DRW )
    3073             :             {
    3074           0 :                 AddFormat( SotClipboardFormatId::GDIMETAFILE );
    3075           0 :                 AddFormat( SotClipboardFormatId::PNG );
    3076           0 :                 AddFormat( SotClipboardFormatId::BITMAP );
    3077             :             }
    3078           0 :             eBufferType = (TransferBufferType)( TRNSFR_GRAPHIC | eBufferType );
    3079             : 
    3080           0 :             pClpGraphic = new Graphic;
    3081           0 :             if( !pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *pClpGraphic ))
    3082           0 :                 pOrigGrf = pClpGraphic;
    3083           0 :             pClpBitmap = new Graphic;
    3084           0 :             if( !pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *pClpBitmap ))
    3085           0 :                 pOrigGrf = pClpBitmap;
    3086             : 
    3087             :             // is it an URL-Button ?
    3088           0 :             OUString sURL;
    3089           0 :             OUString sDesc;
    3090           0 :             if( pWrtShell->GetURLFromButton( sURL, sDesc ) )
    3091             :             {
    3092           0 :                 AddFormat( SotClipboardFormatId::STRING );
    3093           0 :                 AddFormat( SotClipboardFormatId::SOLK );
    3094           0 :                 AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
    3095           0 :                 AddFormat( SotClipboardFormatId::FILECONTENT );
    3096           0 :                 AddFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR );
    3097           0 :                 AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR );
    3098           0 :                 eBufferType = (TransferBufferType)( TRNSFR_INETFLD | eBufferType );
    3099           0 :             }
    3100             :         }
    3101             : 
    3102             :         //ObjectDescriptor was already filled from the old DocShell.
    3103             :         //Now adjust it. Thus in GetData the first query can still
    3104             :         //be answered with delayed rendering.
    3105           0 :         aObjDesc.mbCanLink = false;
    3106           0 :         aObjDesc.maDragStartPos = rSttPos;
    3107             :         aObjDesc.maSize = OutputDevice::LogicToLogic( Size( OLESIZE ),
    3108           0 :                                                 MAP_TWIP, MAP_100TH_MM );
    3109           0 :         PrepareOLE( aObjDesc );
    3110           0 :         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
    3111             :     }
    3112           0 :     else if( nSelection & nsSelectionType::SEL_TXT && !pWrtShell->HasMark() )
    3113             :     {
    3114             :         // is only one field - selected?
    3115           0 :         SwContentAtPos aContentAtPos( SwContentAtPos::SW_INETATTR );
    3116           0 :         Point aPos( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY());
    3117             : 
    3118           0 :         if( pWrtShell->GetContentAtPos( aPos, aContentAtPos ) )
    3119             :         {
    3120           0 :             AddFormat( SotClipboardFormatId::STRING );
    3121           0 :             AddFormat( SotClipboardFormatId::SOLK );
    3122           0 :             AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
    3123           0 :             AddFormat( SotClipboardFormatId::FILECONTENT );
    3124           0 :             AddFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR );
    3125           0 :             AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR );
    3126           0 :             eBufferType = TRNSFR_INETFLD;
    3127           0 :         }
    3128             :     }
    3129             : 
    3130           0 :     if( pWrtShell->IsFrmSelected() )
    3131             :     {
    3132           0 :         SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL );
    3133           0 :         pWrtShell->GetFlyFrmAttr( aSet );
    3134           0 :         const SwFormatURL& rURL = static_cast<const SwFormatURL&>(aSet.Get( RES_URL ));
    3135           0 :         if( rURL.GetMap() )
    3136             :         {
    3137           0 :             pImageMap = new ImageMap( *rURL.GetMap() );
    3138           0 :             AddFormat( SotClipboardFormatId::SVIM );
    3139             :         }
    3140           0 :         else if( !rURL.GetURL().isEmpty() )
    3141             :         {
    3142             :             pTargetURL = new INetImage( sGrfNm, rURL.GetURL(),
    3143             :                                         rURL.GetTargetFrameName(),
    3144           0 :                                         aEmptyOUStr, Size() );
    3145           0 :             AddFormat( SotClipboardFormatId::INET_IMAGE );
    3146           0 :         }
    3147           0 :     }
    3148             : }
    3149             : 
    3150           0 : void SwTransferable::StartDrag( vcl::Window* pWin, const Point& rPos )
    3151             : {
    3152           0 :     if(!pWrtShell)
    3153           0 :         return;
    3154           0 :     bOldIdle = pWrtShell->GetViewOptions()->IsIdle();
    3155           0 :     bCleanUp = true;
    3156             : 
    3157           0 :     pWrtShell->GetViewOptions()->SetIdle( false );
    3158             : 
    3159           0 :     if( pWrtShell->IsSelFrmMode() )
    3160           0 :         pWrtShell->ShowCrsr();
    3161             : 
    3162           0 :     SW_MOD()->pDragDrop = this;
    3163             : 
    3164           0 :     SetDataForDragAndDrop( rPos );
    3165             : 
    3166           0 :     sal_Int8 nDragOptions = DND_ACTION_COPYMOVE | DND_ACTION_LINK;
    3167           0 :     SwDocShell* pDShell = pWrtShell->GetView().GetDocShell();
    3168           0 :     if( ( pDShell && pDShell->IsReadOnly() ) || pWrtShell->HasReadonlySel() )
    3169           0 :         nDragOptions &= ~DND_ACTION_MOVE;
    3170             : 
    3171           0 :     TransferableHelper::StartDrag( pWin, nDragOptions );
    3172             : }
    3173             : 
    3174           0 : void SwTransferable::DragFinished( sal_Int8 nAction )
    3175             : {
    3176             :     //And the last finishing work so that all statuses are right
    3177           0 :     if( DND_ACTION_MOVE == nAction  )
    3178             :     {
    3179           0 :         if( bCleanUp )
    3180             :         {
    3181             :             //It was dropped outside of Writer. We still have to
    3182             :             //delete.
    3183             : 
    3184           0 :             pWrtShell->StartAllAction();
    3185           0 :             pWrtShell->StartUndo( UNDO_UI_DRAG_AND_MOVE );
    3186           0 :             if ( pWrtShell->IsTableMode() )
    3187           0 :                 pWrtShell->DeleteTableSel();
    3188             :             else
    3189             :             {
    3190           0 :                 if ( !(pWrtShell->IsSelFrmMode() || pWrtShell->IsObjSelected()) )
    3191             :                     //SmartCut, take one of the blanks along
    3192           0 :                     pWrtShell->IntelligentCut( pWrtShell->GetSelectionType(), true );
    3193           0 :                 pWrtShell->DelRight();
    3194             :             }
    3195           0 :             pWrtShell->EndUndo( UNDO_UI_DRAG_AND_MOVE );
    3196           0 :             pWrtShell->EndAllAction();
    3197             :         }
    3198             :         else
    3199             :         {
    3200           0 :             const int nSelection = pWrtShell->GetSelectionType();
    3201           0 :             if( ( nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF |
    3202           0 :                  nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW ) & nSelection )
    3203             :             {
    3204           0 :                 pWrtShell->EnterSelFrmMode();
    3205             :             }
    3206             :         }
    3207             :     }
    3208           0 :     pWrtShell->GetView().GetEditWin().DragFinished();
    3209             : 
    3210           0 :     if( pWrtShell->IsSelFrmMode() )
    3211           0 :         pWrtShell->HideCrsr();
    3212             :     else
    3213           0 :         pWrtShell->ShowCrsr();
    3214             : 
    3215           0 :     pWrtShell->GetViewOptions()->SetIdle( bOldIdle );
    3216           0 : }
    3217             : 
    3218           1 : bool SwTransferable::PrivatePaste( SwWrtShell& rShell )
    3219             : {
    3220             :     // first, ask for the SelectionType, then action-bracketing !!!!
    3221             :     // (otherwise it's not pasted into a TableSelection!!!)
    3222             :     OSL_ENSURE( !rShell.ActionPend(), "Paste must never have an ActionPend" );
    3223           1 :     if ( !pClpDocFac )
    3224           0 :         return false; // the return value of the SwFEShell::Paste also is bool!
    3225             : 
    3226           1 :     const int nSelection = rShell.GetSelectionType();
    3227             : 
    3228           1 :     SwRewriter aRewriter;
    3229             : 
    3230           2 :     SwTrnsfrActionAndUndo aAction( &rShell, UNDO_PASTE_CLIPBOARD);
    3231             : 
    3232           1 :     bool bKillPaMs = false;
    3233             : 
    3234             :     //Delete selected content, not at table-selection and table in Clipboard, and dont delete hovering graphics.
    3235           1 :     if( rShell.HasSelection() && !( nSelection & nsSelectionType::SEL_TBL_CELLS) && !( nSelection & nsSelectionType::SEL_DRW))
    3236             :     {
    3237           0 :         bKillPaMs = true;
    3238           0 :         rShell.SetRetainSelection( true );
    3239           0 :         rShell.DelRight();
    3240             :         // when a Fly was selected, a valid cursor position has to be found now
    3241             :         // (parked Cursor!)
    3242           0 :         if( ( nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF |
    3243             :             nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW |
    3244           0 :             nsSelectionType::SEL_DRW_FORM ) & nSelection )
    3245             :         {
    3246             :             // position the cursor again
    3247           0 :             Point aPt( rShell.GetCharRect().Pos() );
    3248           0 :             rShell.SwCrsrShell::SetCrsr( aPt, true );
    3249             :         }
    3250           0 :         rShell.SetRetainSelection( false );
    3251             :     }
    3252           1 :     if ( nSelection & nsSelectionType::SEL_DRW) //unselect hovering graphics
    3253             :     {
    3254           0 :         rShell.ResetSelect(NULL,false);
    3255             :     }
    3256             : 
    3257           1 :     bool bInWrd = false, bEndWrd = false, bSttWrd = false,
    3258           1 :          bSmart = 0 != (TRNSFR_DOCUMENT_WORD & eBufferType);
    3259           1 :     if( bSmart )
    3260             :     {
    3261             :             // Why not for other Scripts? If TRNSFR_DOCUMENT_WORD is set, we have a word
    3262             :             // in the buffer, word in this context means 'something with spaces at beginning
    3263             :             // and end'. In this case we definitely want these spaces to be inserted here.
    3264           0 :             bInWrd = rShell.IsInWrd();
    3265           0 :             bEndWrd = rShell.IsEndWrd();
    3266           0 :             bSmart = bInWrd || bEndWrd;
    3267           0 :             if( bSmart )
    3268             :             {
    3269           0 :                 bSttWrd = rShell.IsSttWrd();
    3270           0 :                 if( bSmart && !bSttWrd && (bInWrd || bEndWrd) )
    3271           0 :                     rShell.SwEditShell::Insert(' ');
    3272             :             }
    3273             :     }
    3274             : 
    3275           1 :     bool nRet = rShell.Paste( pClpDocFac->GetDoc() );
    3276             : 
    3277           1 :     if( bKillPaMs )
    3278           0 :         rShell.KillPams();
    3279             : 
    3280             :     // If Smart Paste then insert blank
    3281           1 :     if( nRet && bSmart && ((bInWrd && !bEndWrd )|| bSttWrd) )
    3282           0 :         rShell.SwEditShell::Insert(' ');
    3283             : 
    3284           2 :     return nRet;
    3285             : }
    3286             : 
    3287           0 : bool SwTransferable::PrivateDrop( SwWrtShell& rSh, const Point& rDragPt,
    3288             :                                 bool bMove, bool bIsXSelection )
    3289             : {
    3290           0 :     int cWord    = 0;
    3291           0 :     bool bInWrd  = false;
    3292           0 :     bool bEndWrd = false;
    3293           0 :     bool bSttWrd = false;
    3294           0 :     bool bSttPara = false;
    3295           0 :     bool bTableSel = false;
    3296           0 :     bool bFrmSel = false;
    3297             : 
    3298           0 :     SwWrtShell& rSrcSh = *GetShell();
    3299             : 
    3300           0 :     rSh.UnSetVisCrsr();
    3301             : 
    3302           0 :     if( TRNSFR_INETFLD == eBufferType )
    3303             :     {
    3304           0 :         if( rSh.GetFormatFromObj( rDragPt ) )
    3305             :         {
    3306           0 :             INetBookmark aTmp;
    3307           0 :             if( (TRNSFR_INETFLD & eBufferType) && pBkmk )
    3308           0 :                 aTmp = *pBkmk;
    3309             : 
    3310             :             // select target graphic
    3311           0 :             if( rSh.SelectObj( rDragPt ) )
    3312             :             {
    3313           0 :                 rSh.HideCrsr();
    3314           0 :                 rSh.EnterSelFrmMode( &rDragPt );
    3315           0 :                 g_bFrmDrag = true;
    3316             :             }
    3317             : 
    3318           0 :             const int nSelection = rSh.GetSelectionType();
    3319             : 
    3320             :             // not yet consider Draw objects
    3321           0 :             if( nsSelectionType::SEL_GRF & nSelection )
    3322             :             {
    3323           0 :                 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
    3324           0 :                 rSh.GetFlyFrmAttr( aSet );
    3325           0 :                 SwFormatURL aURL( static_cast<const SwFormatURL&>(aSet.Get( RES_URL )) );
    3326           0 :                 aURL.SetURL( aTmp.GetURL(), false );
    3327           0 :                 aSet.Put( aURL );
    3328           0 :                 rSh.SetFlyFrmAttr( aSet );
    3329           0 :                 return true;
    3330             :             }
    3331             : 
    3332           0 :             if( nsSelectionType::SEL_DRW & nSelection )
    3333             :             {
    3334           0 :                 rSh.LeaveSelFrmMode();
    3335           0 :                 rSh.UnSelectFrm();
    3336           0 :                 rSh.ShowCrsr();
    3337           0 :                 g_bFrmDrag = false;
    3338           0 :             }
    3339             :         }
    3340             :     }
    3341             : 
    3342           0 :     if( &rSh != &rSrcSh && (nsSelectionType::SEL_GRF & rSh.GetSelectionType()) &&
    3343           0 :         TRNSFR_GRAPHIC == eBufferType )
    3344             :     {
    3345             :         // ReRead the graphic
    3346           0 :         OUString sGrfNm;
    3347           0 :         OUString sFltNm;
    3348           0 :         rSrcSh.GetGrfNms( &sGrfNm, &sFltNm );
    3349           0 :         rSh.ReRead( sGrfNm, sFltNm, rSrcSh.GetGraphic() );
    3350           0 :         return true;
    3351             :     }
    3352             : 
    3353             :     //not in selections or selected frames
    3354           0 :     if( rSh.ChgCurrPam( rDragPt ) ||
    3355           0 :         ( rSh.IsSelFrmMode() && rSh.IsInsideSelectedObj( rDragPt )) )
    3356           0 :         return false;
    3357             : 
    3358           0 :     if( rSrcSh.IsTableMode() )
    3359           0 :         bTableSel = true;
    3360           0 :     else if( rSrcSh.IsSelFrmMode() || rSrcSh.IsObjSelected() )
    3361             :     {
    3362             :         // don't move position-protected objects!
    3363           0 :         if( bMove && rSrcSh.IsSelObjProtected( FlyProtectFlags::Pos ) != FlyProtectFlags::NONE )
    3364           0 :             return false;
    3365             : 
    3366           0 :         bFrmSel = true;
    3367             :     }
    3368             : 
    3369           0 :     const int nSel = rSrcSh.GetSelectionType();
    3370             : 
    3371           0 :     SwUndoId eUndoId = bMove ? UNDO_UI_DRAG_AND_MOVE : UNDO_UI_DRAG_AND_COPY;
    3372             : 
    3373           0 :     SwRewriter aRewriter;
    3374             : 
    3375           0 :     aRewriter.AddRule(UndoArg1, rSrcSh.GetSelDescr());
    3376             : 
    3377           0 :     if(rSrcSh.GetDoc() != rSh.GetDoc())
    3378           0 :         rSrcSh.StartUndo( eUndoId, &aRewriter );
    3379           0 :     rSh.StartUndo( eUndoId, &aRewriter );
    3380             : 
    3381           0 :     rSh.StartAction();
    3382           0 :     rSrcSh.StartAction();
    3383             : 
    3384           0 :     if( &rSrcSh != &rSh )
    3385             :     {
    3386           0 :         rSh.EnterStdMode();
    3387           0 :         rSh.SwCrsrShell::SetCrsr( rDragPt, true );
    3388           0 :         cWord = rSrcSh.IntelligentCut( nSel, false );
    3389             :     }
    3390           0 :     else if( !bTableSel && !bFrmSel )
    3391             :     {
    3392           0 :         if( !rSh.IsAddMode() )
    3393             :         {
    3394             :             // #i87233#
    3395           0 :             if ( rSh.IsBlockMode() )
    3396             :             {
    3397             :                 // preserve order of cursors for block mode
    3398           0 :                 rSh.GoPrevCrsr();
    3399             :             }
    3400             : 
    3401           0 :             rSh.SwCrsrShell::CreateCrsr();
    3402             :         }
    3403           0 :         rSh.SwCrsrShell::SetCrsr( rDragPt, true, false );
    3404           0 :         rSh.GoPrevCrsr();
    3405           0 :         cWord = rSh.IntelligentCut( rSh.GetSelectionType(), false );
    3406           0 :         rSh.GoNextCrsr();
    3407             :     }
    3408             : 
    3409           0 :     bInWrd  = rSh.IsInWrd();
    3410           0 :     bEndWrd = rSh.IsEndWrd();
    3411           0 :     bSttWrd = !bEndWrd && rSh.IsSttWrd();
    3412           0 :     bSttPara= rSh.IsSttPara();
    3413             : 
    3414           0 :     Point aSttPt( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY() );
    3415             : 
    3416             :     // at first, select INetFelder!
    3417           0 :     if( TRNSFR_INETFLD == eBufferType )
    3418             :     {
    3419           0 :         if( &rSrcSh == &rSh )
    3420             :         {
    3421           0 :             rSh.GoPrevCrsr();
    3422           0 :             rSh.SwCrsrShell::SetCrsr( aSttPt, true );
    3423           0 :             rSh.SelectTextAttr( RES_TXTATR_INETFMT );
    3424           0 :             if( rSh.ChgCurrPam( rDragPt ) )
    3425             :             {
    3426             :                 // don't copy/move inside of yourself
    3427           0 :                 rSh.DestroyCrsr();
    3428           0 :                 rSh.EndUndo();
    3429           0 :                 rSh.EndAction();
    3430           0 :                 rSh.EndAction();
    3431           0 :                 return false;
    3432             :             }
    3433           0 :             rSh.GoNextCrsr();
    3434             :         }
    3435             :         else
    3436             :         {
    3437           0 :             rSrcSh.SwCrsrShell::SetCrsr( aSttPt, true );
    3438           0 :             rSrcSh.SelectTextAttr( RES_TXTATR_INETFMT );
    3439             :         }
    3440             : 
    3441             :         // is there an URL attribute at the insert point? Then replace that,
    3442             :         // so simply put up a selection?
    3443           0 :         rSh.DelINetAttrWithText();
    3444           0 :         g_bDDINetAttr = true;
    3445             :     }
    3446             : 
    3447           0 :     if ( rSrcSh.IsSelFrmMode() )
    3448             :     {
    3449             :         //Hack: fool the special treatment
    3450           0 :         aSttPt -= aSttPt - rSrcSh.GetObjRect().Pos();
    3451             :     }
    3452             : 
    3453             :     bool bRet = rSrcSh.SwFEShell::Copy( &rSh, aSttPt, rDragPt, bMove,
    3454           0 :                                             !bIsXSelection );
    3455             : 
    3456           0 :     if( !bIsXSelection )
    3457             :     {
    3458           0 :         rSrcSh.Push();
    3459           0 :         if ( bRet && bMove && !bFrmSel )
    3460             :         {
    3461           0 :             if ( bTableSel )
    3462             :             {
    3463             :                 /* delete table contents not cells */
    3464           0 :                 rSrcSh.Delete();
    3465             :             }
    3466             :             else
    3467             :             {
    3468             :                 //SmartCut, take one of the blanks along.
    3469           0 :                 rSh.SwCrsrShell::DestroyCrsr();
    3470           0 :                 if ( cWord == SwWrtShell::WORD_SPACE_BEFORE )
    3471           0 :                     rSh.ExtendSelection( false );
    3472           0 :                 else if ( cWord == SwWrtShell::WORD_SPACE_AFTER )
    3473           0 :                     rSh.ExtendSelection();
    3474           0 :                 rSrcSh.DelRight();
    3475             :             }
    3476             :         }
    3477           0 :         rSrcSh.KillPams();
    3478           0 :         rSrcSh.Pop( false );
    3479             : 
    3480             :         /* after dragging a table selection inside one shell
    3481             :             set cursor to the drop position. */
    3482           0 :         if( &rSh == &rSrcSh && ( bTableSel || rSh.IsBlockMode() ) )
    3483             :         {
    3484           0 :             rSrcSh.SwCrsrShell::SetCrsr(rDragPt);
    3485           0 :             rSrcSh.GetSwCrsr()->SetMark();
    3486             :         }
    3487             :     }
    3488             : 
    3489           0 :     if( bRet && !bTableSel && !bFrmSel )
    3490             :     {
    3491           0 :         if( (bInWrd || bEndWrd) &&
    3492           0 :             (cWord == SwWrtShell::WORD_SPACE_AFTER ||
    3493             :                 cWord == SwWrtShell::WORD_SPACE_BEFORE) )
    3494             :         {
    3495           0 :             if ( bSttWrd || (bInWrd && !bEndWrd))
    3496           0 :                 rSh.SwEditShell::Insert(' ', bIsXSelection);
    3497           0 :             if ( !bSttWrd || (bInWrd && !bSttPara) )
    3498             :             {
    3499           0 :                 rSh.SwapPam();
    3500           0 :                 if ( !bSttWrd )
    3501           0 :                     rSh.SwEditShell::Insert(' ', bIsXSelection);
    3502           0 :                 rSh.SwapPam();
    3503             :             }
    3504             :         }
    3505             : 
    3506           0 :         if( bIsXSelection )
    3507             :         {
    3508           0 :             if( &rSrcSh == &rSh && !rSh.IsAddMode() )
    3509             :             {
    3510           0 :                 rSh.SwCrsrShell::DestroyCrsr();
    3511           0 :                 rSh.GoPrevCrsr();
    3512             :             }
    3513             :             else
    3514             :             {
    3515           0 :                 rSh.SwapPam();
    3516           0 :                 rSh.SwCrsrShell::ClearMark();
    3517             :             }
    3518             :         }
    3519             :         else
    3520             :         {
    3521           0 :             if( rSh.IsAddMode() )
    3522           0 :                 rSh.SwCrsrShell::CreateCrsr();
    3523             :             else
    3524             :             {
    3525             :                 // turn on selection mode
    3526           0 :                 rSh.SttSelect();
    3527           0 :                 rSh.EndSelect();
    3528             :             }
    3529             :         }
    3530             :     }
    3531             : 
    3532           0 :     if( bRet && bMove && bFrmSel )
    3533           0 :         rSrcSh.LeaveSelFrmMode();
    3534             : 
    3535           0 :     if( rSrcSh.GetDoc() != rSh.GetDoc() )
    3536           0 :         rSrcSh.EndUndo();
    3537           0 :     rSh.EndUndo();
    3538             : 
    3539             :         // put the shell in the right state
    3540           0 :     if( &rSrcSh != &rSh && ( rSh.IsFrmSelected() || rSh.IsObjSelected() ))
    3541           0 :         rSh.EnterSelFrmMode();
    3542             : 
    3543           0 :     rSrcSh.EndAction();
    3544           0 :     rSh.EndAction();
    3545           0 :     return true;
    3546             : }
    3547             : 
    3548             : // Interfaces for Selection
    3549          50 : void SwTransferable::CreateSelection( SwWrtShell& rSh,
    3550             :                                       const SwFrameShell * _pCreatorView )
    3551             : {
    3552          50 :     SwModule *pMod = SW_MOD();
    3553          50 :     SwTransferable* pNew = new SwTransferable( rSh );
    3554             : 
    3555          50 :     pNew->pCreatorView = _pCreatorView;
    3556             : 
    3557          50 :     uno::Reference< XTransferable > xRef( pNew );
    3558          50 :     pMod->pXSelection = pNew;
    3559          50 :     pNew->CopyToSelection( rSh.GetWin() );
    3560          50 : }
    3561             : 
    3562        2926 : void SwTransferable::ClearSelection( SwWrtShell& rSh,
    3563             :                                      const SwFrameShell * _pCreatorView)
    3564             : {
    3565        2926 :     SwModule *pMod = SW_MOD();
    3566        2972 :     if( pMod->pXSelection &&
    3567          73 :         ((!pMod->pXSelection->pWrtShell) || (pMod->pXSelection->pWrtShell == &rSh)) &&
    3568           0 :         (!_pCreatorView || (pMod->pXSelection->pCreatorView == _pCreatorView)) )
    3569             :     {
    3570          46 :         TransferableHelper::ClearSelection( rSh.GetWin() );
    3571             :     }
    3572        2926 : }
    3573             : 
    3574             : namespace
    3575             : {
    3576             :     class theSwTransferableUnoTunnelId : public rtl::Static< UnoTunnelIdInit, SwTransferable > {};
    3577             : }
    3578             : 
    3579          46 : const Sequence< sal_Int8 >& SwTransferable::getUnoTunnelId()
    3580             : {
    3581          46 :     return theSwTransferableUnoTunnelId::get().getSeq();
    3582             : }
    3583             : 
    3584          23 : sal_Int64 SwTransferable::getSomething( const Sequence< sal_Int8 >& rId ) throw( RuntimeException, std::exception )
    3585             : {
    3586             :     sal_Int64 nRet;
    3587          46 :     if( ( rId.getLength() == 16 ) &&
    3588          23 :         ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
    3589             :     {
    3590          23 :         nRet = sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ) );
    3591             :     }
    3592             :     else
    3593           0 :         nRet = TransferableHelper::getSomething(rId);
    3594          23 :     return nRet;
    3595             : }
    3596             : 
    3597        1312 : SwTransferable* SwTransferable::GetSwTransferable( const TransferableDataHelper& rData )
    3598             : {
    3599        1312 :     SwTransferable* pSwTransferable = NULL;
    3600             : 
    3601        1312 :     uno::Reference<XUnoTunnel> xTunnel( rData.GetTransferable(), UNO_QUERY );
    3602        1312 :     if ( xTunnel.is() )
    3603             :     {
    3604           3 :         sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() );
    3605           3 :         if ( nHandle )
    3606           3 :             pSwTransferable = reinterpret_cast<SwTransferable*>( (sal_IntPtr) nHandle );
    3607             :     }
    3608             : 
    3609        1312 :     return pSwTransferable;
    3610             : 
    3611             : }
    3612             : 
    3613           1 : SwTrnsfrDdeLink::SwTrnsfrDdeLink( SwTransferable& rTrans, SwWrtShell& rSh )
    3614             :     : rTrnsfr(rTrans)
    3615             :     , pDocShell(0)
    3616             :     , nOldTimeOut(0)
    3617             :     , bDelBookmrk(false)
    3618           1 :     , bInDisconnect(false)
    3619             : {
    3620             :     // we only end up here with table- or text selection
    3621           1 :     if( nsSelectionType::SEL_TBL_CELLS & rSh.GetSelectionType() )
    3622             :     {
    3623           0 :         SwFrameFormat* pFormat = rSh.GetTableFormat();
    3624           0 :         if( pFormat )
    3625           0 :             sName = pFormat->GetName();
    3626             :     }
    3627             :     else
    3628             :     {
    3629             :         // creating a temp. bookmark without undo
    3630           1 :         bool bUndo = rSh.DoesUndo();
    3631           1 :         rSh.DoUndo( false );
    3632           1 :         bool bIsModified = rSh.IsModified();
    3633             : 
    3634             :         ::sw::mark::IMark* pMark = rSh.SetBookmark(
    3635             :             vcl::KeyCode(),
    3636             :             OUString(),
    3637             :             OUString(),
    3638           1 :             IDocumentMarkAccess::MarkType::DDE_BOOKMARK);
    3639           1 :         if(pMark)
    3640             :         {
    3641           1 :             sName = pMark->GetName();
    3642           1 :             bDelBookmrk = true;
    3643           1 :             if( !bIsModified )
    3644           1 :                 rSh.ResetModified();
    3645             :         }
    3646             :         else
    3647           0 :             sName.clear();
    3648           1 :         rSh.DoUndo( bUndo );
    3649             :     }
    3650             : 
    3651           3 :     if( !sName.isEmpty() &&
    3652           2 :         0 != ( pDocShell = rSh.GetDoc()->GetDocShell() ) )
    3653             :     {
    3654             :         // then we create our "server" and connect to it
    3655           1 :         refObj = pDocShell->DdeCreateLinkSource( sName );
    3656           1 :         if( refObj.Is() )
    3657             :         {
    3658           1 :             refObj->AddConnectAdvise( this );
    3659             :             refObj->AddDataAdvise( this,
    3660             :                             aEmptyOUStr,
    3661           1 :                             ADVISEMODE_NODATA | ADVISEMODE_ONLYONCE );
    3662           1 :             nOldTimeOut = refObj->GetUpdateTimeout();
    3663           1 :             refObj->SetUpdateTimeout( 0 );
    3664             :         }
    3665             :     }
    3666           1 : }
    3667             : 
    3668           0 : SwTrnsfrDdeLink::~SwTrnsfrDdeLink()
    3669             : {
    3670           0 :     if( refObj.Is() )
    3671           0 :         Disconnect( true );
    3672           0 : }
    3673             : 
    3674           0 : ::sfx2::SvBaseLink::UpdateResult SwTrnsfrDdeLink::DataChanged( const OUString& ,
    3675             :                                     const uno::Any& )
    3676             : {
    3677             :     // well, that's it with the link
    3678           0 :     if( !bInDisconnect )
    3679             :     {
    3680           0 :         if( FindDocShell() && pDocShell->GetView() )
    3681           0 :             rTrnsfr.RemoveDDELinkFormat( pDocShell->GetView()->GetEditWin() );
    3682           0 :         Disconnect( false );
    3683             :     }
    3684           0 :     return SUCCESS;
    3685             : }
    3686             : 
    3687           0 : bool SwTrnsfrDdeLink::WriteData( SvStream& rStrm )
    3688             : {
    3689           0 :     if( !refObj.Is() || !FindDocShell() )
    3690           0 :         return false;
    3691             : 
    3692           0 :     rtl_TextEncoding eEncoding = DDE_TXT_ENCODING;
    3693             :     const OString aAppNm(OUStringToOString(
    3694           0 :         Application::GetAppName(), eEncoding));
    3695             :     const OString aTopic(OUStringToOString(
    3696           0 :         pDocShell->GetTitle(SFX_TITLE_FULLNAME), eEncoding));
    3697           0 :     const OString aName(OUStringToOString(sName, eEncoding));
    3698             : 
    3699           0 :     boost::scoped_array<sal_Char> pMem(new sal_Char[ aAppNm.getLength() + aTopic.getLength() + aName.getLength() + 4 ]);
    3700             : 
    3701           0 :     sal_Int32 nLen = aAppNm.getLength();
    3702           0 :     memcpy( pMem.get(), aAppNm.getStr(), nLen );
    3703           0 :     pMem[ nLen++ ] = 0;
    3704           0 :     memcpy( pMem.get() + nLen, aTopic.getStr(), aTopic.getLength() );
    3705           0 :     nLen = nLen + aTopic.getLength();
    3706           0 :     pMem[ nLen++ ] = 0;
    3707           0 :     memcpy( pMem.get() + nLen, aName.getStr(), aName.getLength() );
    3708           0 :     nLen = nLen + aName.getLength();
    3709           0 :     pMem[ nLen++ ] = 0;
    3710           0 :     pMem[ nLen++ ] = 0;
    3711             : 
    3712           0 :     rStrm.Write( pMem.get(), nLen );
    3713           0 :     pMem.reset();
    3714             : 
    3715           0 :     IDocumentMarkAccess* const pMarkAccess = pDocShell->GetDoc()->getIDocumentMarkAccess();
    3716           0 :     IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(sName);
    3717           0 :     if(ppMark != pMarkAccess->getAllMarksEnd()
    3718           0 :         && IDocumentMarkAccess::GetType(**ppMark) != IDocumentMarkAccess::MarkType::BOOKMARK)
    3719             :     {
    3720             :         // the mark is still a DdeBookmark
    3721             :         // we replace it with a Bookmark, so it will get saved etc.
    3722           0 :         ::sw::mark::IMark* const pMark = ppMark->get();
    3723           0 :         ::sfx2::SvLinkSource* p = &refObj;
    3724           0 :         SwServerObject& rServerObject = dynamic_cast<SwServerObject&>(*p);
    3725             : 
    3726             :         // collecting state of old mark
    3727           0 :         SwPaM aPaM(pMark->GetMarkStart());
    3728           0 :         *aPaM.GetPoint() = pMark->GetMarkStart();
    3729           0 :         if(pMark->IsExpanded())
    3730             :         {
    3731           0 :             aPaM.SetMark();
    3732           0 :             *aPaM.GetMark() = pMark->GetMarkEnd();
    3733             :         }
    3734           0 :         OUString sMarkName = pMark->GetName();
    3735             : 
    3736             :         // remove mark
    3737           0 :         rServerObject.SetNoServer(); // this removes the connection between SwServerObject and mark
    3738             :         // N.B. ppMark was not loaded from file and cannot have xml:id
    3739           0 :         pMarkAccess->deleteMark(ppMark);
    3740             : 
    3741             :         // recreate as Bookmark
    3742             :         ::sw::mark::IMark* const pNewMark = pMarkAccess->makeMark(
    3743             :             aPaM,
    3744             :             sMarkName,
    3745           0 :             IDocumentMarkAccess::MarkType::BOOKMARK);
    3746           0 :         rServerObject.SetDdeBookmark(*pNewMark);
    3747             :     }
    3748             : 
    3749           0 :     bDelBookmrk = false;
    3750           0 :     return true;
    3751             : }
    3752             : 
    3753           0 : void SwTrnsfrDdeLink::Disconnect( bool bRemoveDataAdvise )
    3754             : {
    3755             :     //  don't accept DataChanged anymore, when already in Disconnect!
    3756             :     //  (DTOR from Bookmark sends a DataChanged!)
    3757           0 :     bool bOldDisconnect = bInDisconnect;
    3758           0 :     bInDisconnect = true;
    3759             : 
    3760             :     // destroy the unused bookmark again (without Undo!)?
    3761           0 :     if( bDelBookmrk && refObj.Is() && FindDocShell() )
    3762             :     {
    3763           0 :         SwDoc* pDoc = pDocShell->GetDoc();
    3764           0 :         ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
    3765             : 
    3766             :         // #i58448#
    3767           0 :         Link<> aSavedOle2Link( pDoc->GetOle2Link() );
    3768           0 :         pDoc->SetOle2Link( Link<>() );
    3769             : 
    3770           0 :         bool bIsModified = pDoc->getIDocumentState().IsModified();
    3771             : 
    3772           0 :         IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
    3773           0 :         pMarkAccess->deleteMark(pMarkAccess->findMark(sName));
    3774             : 
    3775           0 :         if( !bIsModified )
    3776           0 :             pDoc->getIDocumentState().ResetModified();
    3777             :         // #i58448#
    3778           0 :         pDoc->SetOle2Link( aSavedOle2Link );
    3779             : 
    3780           0 :         bDelBookmrk = false;
    3781             :     }
    3782             : 
    3783           0 :     if( refObj.Is() )
    3784             :     {
    3785           0 :         refObj->SetUpdateTimeout( nOldTimeOut );
    3786           0 :         refObj->RemoveConnectAdvise( this );
    3787           0 :         if( bRemoveDataAdvise )
    3788             :             // in a DataChanged the SelectionObject must NEVER be deleted
    3789             :             // is already handled by the base class
    3790             :             // (ADVISEMODE_ONLYONCE!!!!)
    3791             :             // but always in normal Disconnect!
    3792           0 :             refObj->RemoveAllDataAdvise( this );
    3793           0 :         refObj.Clear();
    3794             :     }
    3795           0 :     bInDisconnect = bOldDisconnect;
    3796           0 : }
    3797             : 
    3798           0 : bool SwTrnsfrDdeLink::FindDocShell()
    3799             : {
    3800           0 :     TypeId aType( TYPE( SwDocShell ) );
    3801           0 :     SfxObjectShell* pTmpSh = SfxObjectShell::GetFirst( &aType );
    3802           0 :     while( pTmpSh )
    3803             :     {
    3804           0 :         if( pTmpSh == pDocShell )       // that's what we want to have
    3805             :         {
    3806           0 :             if( pDocShell->GetDoc() )
    3807           0 :                 return true;
    3808           0 :             break;      // the Doc is not there anymore, so leave!
    3809             :         }
    3810           0 :         pTmpSh = SfxObjectShell::GetNext( *pTmpSh, &aType );
    3811             :     }
    3812             : 
    3813           0 :     pDocShell = 0;
    3814           0 :     return false;
    3815             : }
    3816             : 
    3817           1 : void SwTrnsfrDdeLink::Closed()
    3818             : {
    3819           1 :     if( !bInDisconnect && refObj.Is() )
    3820             :     {
    3821           1 :         refObj->RemoveAllDataAdvise( this );
    3822           1 :         refObj->RemoveConnectAdvise( this );
    3823           1 :         refObj.Clear();
    3824             :     }
    3825         178 : }
    3826             : 
    3827             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11