LibreOffice Module sw (master)  1
swdtflvr.cxx
Go to the documentation of this file.
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/XTransactedObject.hpp>
23 #include <com/sun/star/embed/Aspects.hpp>
24 #include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
25 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
26 #include <com/sun/star/embed/MSOLEObjectSystemCreator.hpp>
27 #include <com/sun/star/text/XPasteListener.hpp>
28 
30 #include <svtools/insdlg.hxx>
31 #include <unotools/tempfile.hxx>
32 #include <comphelper/fileformat.h>
36 #include <comphelper/string.hxx>
37 #include <o3tl/deleter.hxx>
39 #include <sot/filelist.hxx>
40 #include <svx/svxdlg.hxx>
42 #include <osl/endian.h>
43 #include <sfx2/linkmgr.hxx>
44 #include <tools/urlobj.hxx>
45 #include <vcl/wrkwin.hxx>
46 #include <vcl/weld.hxx>
47 #include <sfx2/dispatch.hxx>
48 #include <sfx2/viewfrm.hxx>
49 #include <svl/stritem.hxx>
50 #include <vcl/imap.hxx>
51 #include <sot/storage.hxx>
52 #include <vcl/graph.hxx>
53 #include <svl/urihelper.hxx>
54 #include <svx/svdmodel.hxx>
55 #include <svx/xmlexchg.hxx>
56 #include <svx/dbaexchange.hxx>
57 #include <svx/clipfmtitem.hxx>
58 #include <svx/svxids.hrc>
59 #include <sfx2/mieclip.hxx>
60 #include <svx/svdetc.hxx>
61 #include <svx/xoutbmp.hxx>
62 #include <svl/urlbmk.hxx>
63 #include <svtools/htmlout.hxx>
64 #include <svx/hlnkitem.hxx>
65 #include <vcl/inetimg.hxx>
66 #include <editeng/paperinf.hxx>
67 #include <svx/fmview.hxx>
69 #include <sfx2/docfilt.hxx>
70 #include <vcl/imapobj.hxx>
71 #include <sfx2/docfile.hxx>
73 #include <unotools/streamwrap.hxx>
74 #include <vcl/graphicfilter.hxx>
75 
76 #ifdef _WIN32
77 #define WIN32_LEAN_AND_MEAN
78 #include <prewin.h>
79 #include <windows.h>
80 #include <postwin.h>
82 #include <osl/file.hxx>
83 #endif
84 
85 #include <svx/unomodel.hxx>
86 #include <fmturl.hxx>
87 #include <fmtinfmt.hxx>
88 #include <fmtfsize.hxx>
89 #include <swdtflvr.hxx>
90 #include <shellio.hxx>
91 #include <ddefld.hxx>
92 #include <doc.hxx>
93 #include <IDocumentUndoRedo.hxx>
98 #include <IDocumentState.hxx>
99 #include <pagedesc.hxx>
100 #include <IMark.hxx>
101 #include <docary.hxx>
102 #include <section.hxx>
103 #include <ndtxt.hxx>
104 #include <edtdd.hxx>
105 #include <edtwin.hxx>
106 #include <navicont.hxx>
107 #include <swcont.hxx>
108 #include <wrtsh.hxx>
109 #include <swmodule.hxx>
110 #include <view.hxx>
111 #include <docsh.hxx>
112 #include <wdocsh.hxx>
113 #include <fldbas.hxx>
114 #include <swundo.hxx>
115 #include <pam.hxx>
116 #include <ndole.hxx>
117 #include <swwait.hxx>
118 #include <viewopt.hxx>
119 #include <swerror.h>
120 #include <SwCapObjType.hxx>
121 #include <cmdid.h>
122 #include <strings.hrc>
123 #include <sot/stg.hxx>
124 #include <svx/svditer.hxx>
125 #include <editeng/eeitem.hxx>
126 #include <editeng/fhgtitem.hxx>
127 #include <svx/svdpage.hxx>
128 #include <avmedia/mediawindow.hxx>
129 #include <swcrsr.hxx>
130 #include <SwRewriter.hxx>
131 #include <globals.hrc>
132 #include <app.hrc>
133 #include <vcl/svapp.hxx>
134 #include <swserv.hxx>
135 #include <calbck.hxx>
136 #include <fmtmeta.hxx>
137 #include <itabenum.hxx>
138 #include <iodetect.hxx>
139 #include <unotextrange.hxx>
140 #include <unoframe.hxx>
141 
144 #include <comphelper/lok.hxx>
146 
147 #include <memory>
148 
149 #define OLESIZE 11905 - 2 * lMinBorder, 6 * MM50
150 
151 constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_DRAWMODEL = 0x00000001;
152 constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_HTML = 0x00000002;
153 constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_RTF = 0x00000004;
154 constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_STRING = 0x00000008;
155 constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_SWOLE = 0x00000010;
156 constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_DDE = 0x00000020;
157 constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_RICHTEXT = 0x00000040;
158 
159 using namespace ::svx;
160 using namespace ::com::sun::star;
161 using namespace ::com::sun::star::uno;
162 using namespace ::com::sun::star::datatransfer;
163 
164 #define DDE_TXT_ENCODING osl_getThreadTextEncoding()
165 
167 {
168  OUString sName;
173  bool bDelBookmrk : 1;
174  bool bInDisconnect : 1;
175 
176  bool FindDocShell();
177 
179 
180 protected:
181  virtual ~SwTrnsfrDdeLink() override;
182 
183 public:
184  SwTrnsfrDdeLink( SwTransferable& rTrans, SwWrtShell& rSh );
185 
186  virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
187  const OUString& rMimeType, const css::uno::Any & rValue ) override;
188  virtual void Closed() override;
189 
190  bool WriteData( SvStream& rStrm );
191 
192  void Disconnect( bool bRemoveDataAdvise );
193 };
194 
197 {
198 public:
199  SwPasteContext(SwWrtShell& rWrtShell);
200  ~SwPasteContext();
201 
202  void remember();
203  void forget();
204 
205 private:
207  std::unique_ptr<SwPaM> m_pPaM;
208  sal_Int32 m_nStartContent = 0;
209 };
210 
211 // helper class for Action and Undo enclosing
213 {
215 public:
216  SwTrnsfrActionAndUndo( SwWrtShell *pS, bool bDelSel = false, SwPasteContext* pContext = nullptr)
217  : pSh( pS )
218  {
220  if( bDelSel )
221  {
222  if (pContext)
223  pContext->forget();
224  pSh->DelRight();
225  if (pContext)
226  pContext->remember();
227  }
228  pSh->StartAllAction();
229  }
230  ~SwTrnsfrActionAndUndo() COVERITY_NOEXCEPT_FALSE
231  {
232  pSh->EndUndo();
233  pSh->EndAllAction();
234  }
235 };
236 
238  : m_pWrtShell( &rSh ),
239  m_pCreatorView( nullptr ),
240  m_pOrigGraphic( nullptr ),
241  m_eBufferType( TransferBufferType::NONE )
242 {
243  rSh.GetView().AddTransferable(*this);
244  SwDocShell* pDShell = rSh.GetDoc()->GetDocShell();
245  if( pDShell )
246  {
248  if( pDShell->GetMedium() )
249  {
250  const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject();
255  }
256 
258  }
259 }
260 
262 {
263  SolarMutexGuard aSolarGuard;
264 
265  // the DDELink still needs the WrtShell!
266  if( m_xDdeLink.is() )
267  {
268  static_cast<SwTrnsfrDdeLink*>( m_xDdeLink.get() )->Disconnect( true );
269  m_xDdeLink.clear();
270  }
271 
272  m_pWrtShell = nullptr;
273 
274  // release reference to the document so that aDocShellRef will delete
275  // it (if aDocShellRef is set). Otherwise, the OLE nodes keep references
276  // to their sub-storage when the storage is already dead.
277  m_pClpDocFac.reset();
278 
279  // first close, then the Ref. can be cleared as well, so that
280  // the DocShell really gets deleted!
281  if( m_aDocShellRef.Is() )
282  {
284  SwDocShell* pDocSh = static_cast<SwDocShell*>(pObj);
285  pDocSh->DoClose();
286  }
288 
289  SwModule* pMod = SW_MOD();
290  if(pMod)
291  {
292  if ( pMod->m_pDragDrop == this )
293  pMod->m_pDragDrop = nullptr;
294  else if ( pMod->m_pXSelection == this )
295  pMod->m_pXSelection = nullptr;
296  }
297 
299 }
300 
301 static SwDoc * lcl_GetDoc(SwDocFac & rDocFac)
302 {
303  SwDoc *const pDoc = rDocFac.GetDoc();
304  OSL_ENSURE( pDoc, "Document not found" );
305  if (pDoc)
306  {
307  pDoc->SetClipBoard( true );
308  }
309  return pDoc;
310 }
311 
313 {
314  SwModule *pMod = SW_MOD();
315  if( this == pMod->m_pDragDrop )
316  pMod->m_pDragDrop = nullptr;
317  else if( this == pMod->m_pXSelection )
318  pMod->m_pXSelection = nullptr;
319 }
320 
322 {
323  // only need if we are the current XSelection Object
324  SwModule *pMod = SW_MOD();
326  {
327  SetDataForDragAndDrop( Point( 0,0) );
328  }
329 }
330 
332 {
333  //set OleVisArea. Upper left corner of the page and size of
334  //RealSize in Twips.
335  const Size aSz( OLESIZE );
336  SwRect aVis( Point( DOCUMENTBORDER, DOCUMENTBORDER ), aSz );
337  pDoc->SetVisArea( aVis.SVRect() );
338 }
339 
340 uno::Reference < embed::XEmbeddedObject > SwTransferable::FindOLEObj( sal_Int64& nAspect ) const
341 {
342  uno::Reference < embed::XEmbeddedObject > xObj;
343  if( m_pClpDocFac )
344  {
345  SwIterator<SwContentNode,SwFormatColl> aIter( *m_pClpDocFac->GetDoc()->GetDfltGrfFormatColl() );
346  for( SwContentNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
347  if( SwNodeType::Ole == pNd->GetNodeType() )
348  {
349  xObj = static_cast<SwOLENode*>(pNd)->GetOLEObj().GetOleRef();
350  nAspect = static_cast<SwOLENode*>(pNd)->GetAspect();
351  break;
352  }
353  }
354  return xObj;
355 }
356 
358 {
359  if( m_pClpDocFac )
360  {
361  SwIterator<SwContentNode,SwFormatColl> aIter( *m_pClpDocFac->GetDoc()->GetDfltGrfFormatColl() );
362  for( SwContentNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
363  if( SwNodeType::Ole == pNd->GetNodeType() )
364  {
365  return static_cast<SwOLENode*>(pNd)->GetGraphic();
366  }
367  }
368 
369  return nullptr;
370 }
371 
373 {
374  RemoveFormat( SotClipboardFormatId::LINK );
375  CopyToClipboard( const_cast<vcl::Window*>(&rWin) );
376 }
377 
378 namespace
379 {
380  //Resolves: fdo#40717 surely when we create a clipboard document we should
381  //overwrite the clipboard documents styles and settings with that of the
382  //source, so that we can WYSIWYG paste. If we want that the destinations
383  //styles are used over the source styles, that's a matter of the
384  //destination paste code to handle, not the source paste code.
385  void lclOverWriteDoc(SwWrtShell &rSrcWrtShell, SwDoc &rDest)
386  {
387  const SwDoc &rSrc = *rSrcWrtShell.GetDoc();
388 
389  rDest.ReplaceCompatibilityOptions(rSrc);
390  rDest.ReplaceDefaults(rSrc);
391 
392  //It would probably make most sense here to only insert the styles used
393  //by the selection, e.g. apply SwDoc::IsUsed on styles ?
394  rDest.ReplaceStyles(rSrc, false);
395 
396  rSrcWrtShell.Copy(&rDest);
397 
399  }
400 
401  void lclCheckAndPerformRotation(Graphic& aGraphic)
402  {
403  GraphicNativeMetadata aMetadata;
404  if ( aMetadata.read(aGraphic) )
405  {
406  sal_uInt16 aRotation = aMetadata.getRotation();
407  if (aRotation != 0)
408  {
409  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "modules/swriter/ui/queryrotateintostandarddialog.ui"));
410  std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("QueryRotateIntoStandardOrientationDialog"));
411  if (xQueryBox->run() == RET_YES)
412  {
413  GraphicNativeTransform aTransform( aGraphic );
414  aTransform.rotate( aRotation );
415  }
416  }
417  }
418  }
419 }
420 
421 bool SwTransferable::GetData( const DataFlavor& rFlavor, const OUString& rDestDoc )
422 {
423  SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor );
424 
425  // we can only fulfil the request if
426  // 1) we have data for this format
427  // 2) we have either a clipboard document (pClpDocFac), or
428  // we have a SwWrtShell (so we can generate a new clipboard document)
429  if( !HasFormat( nFormat ) || ( m_pClpDocFac == nullptr && m_pWrtShell == nullptr ) )
430  return false;
431 
432  if( !m_pClpDocFac )
433  {
434  SelectionType nSelectionType = m_pWrtShell->GetSelectionType();
435 
436  // when pending we will not get the correct type, but SelectionType::Text
437  // as fallback. This *happens* during D&D, so we need to check if we are in
438  // the fallback and just try to get a graphic
439  const bool bPending(m_pWrtShell->ActionPend());
440 
441  // SEL_GRF is from ContentType of editsh
442  if(bPending || ((SelectionType::Graphic | SelectionType::DbForm) & nSelectionType))
443  {
444  m_pClpGraphic.reset(new Graphic);
445  if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *m_pClpGraphic ))
447  m_pClpBitmap.reset(new Graphic);
448  if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *m_pClpBitmap ))
450 
451  // is it a URL-Button ?
452  OUString sURL;
453  OUString sDesc;
454  if( m_pWrtShell->GetURLFromButton( sURL, sDesc ) )
455  {
456  m_pBookmark.reset(new INetBookmark( sURL, sDesc ));
458  }
459  }
460 
461  m_pClpDocFac.reset(new SwDocFac);
462  SwDoc *const pTmpDoc = lcl_GetDoc(*m_pClpDocFac);
463 
464  pTmpDoc->getIDocumentFieldsAccess().LockExpFields(); // never update fields - leave text as it is
465  lclOverWriteDoc(*m_pWrtShell, *pTmpDoc);
466 
467  // in CORE a new one was created (OLE-objects copied!)
468  m_aDocShellRef = pTmpDoc->GetTmpDocShell();
469  if( m_aDocShellRef.Is() )
471  pTmpDoc->SetTmpDocShell( nullptr );
472 
473  if( nSelectionType & SelectionType::Text && !m_pWrtShell->HasMark() )
474  {
475  SwContentAtPos aContentAtPos( IsAttrAtPos::InetAttr );
476 
478 
479  bool bSelect = g_bExecuteDrag &&
482  if( m_pWrtShell->GetContentAtPos( aPos, aContentAtPos, bSelect ) )
483  {
484  m_pBookmark.reset(new INetBookmark(
485  static_cast<const SwFormatINetFormat*>(aContentAtPos.aFnd.pAttr)->GetValue(),
486  aContentAtPos.sStr ));
488  if( bSelect )
490  }
491  }
493  {
495  m_pWrtShell->GetFlyFrameAttr( aSet );
496  const SwFormatURL& rURL = aSet.Get( RES_URL );
497  if( rURL.GetMap() )
498  m_pImageMap.reset(new ImageMap( *rURL.GetMap() ));
499  else if( !rURL.GetURL().isEmpty() )
500  m_pTargetURL.reset(new INetImage(OUString(), rURL.GetURL(),
501  rURL.GetTargetFrameName() ));
502  }
503  }
504 
505  bool bOK = false;
507  {
508  //TODO/MBA: testing - is this the "single OLE object" case?!
509  // get OLE-Object from ClipDoc and get the data from that.
510  sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; // will be set in the next statement
511  uno::Reference < embed::XEmbeddedObject > xObj = FindOLEObj( nAspect );
512  const Graphic* pOLEGraph = FindOLEReplacementGraphic();
513  if( xObj.is() )
514  {
515  TransferableDataHelper aD( new SvEmbedTransferHelper( xObj, pOLEGraph, nAspect ) );
516  uno::Any aAny = aD.GetAny(rFlavor, rDestDoc);
517  if( aAny.hasValue() )
518  bOK = SetAny( aAny );
519  }
520 
521  // the following solution will be used in the case when the object can not generate the image
522  // TODO/LATER: in future the transferhelper must probably be created based on object and the replacement stream
523  // TODO: Block not required now, SvEmbedTransferHelper should be able to handle GDIMetaFile format
524  if ( nFormat == SotClipboardFormatId::GDIMETAFILE )
525  {
526  pOLEGraph = FindOLEReplacementGraphic();
527  if ( pOLEGraph )
528  bOK = SetGDIMetaFile( pOLEGraph->GetGDIMetaFile() );
529  }
530  }
531  else
532  {
533  switch( nFormat )
534  {
535  case SotClipboardFormatId::LINK:
536  if( m_xDdeLink.is() )
537  bOK = SetObject( m_xDdeLink.get(), SWTRANSFER_OBJECTTYPE_DDE, rFlavor );
538  break;
539 
540  case SotClipboardFormatId::OBJECTDESCRIPTOR:
541  case SotClipboardFormatId::LINKSRCDESCRIPTOR:
543  break;
544 
545  case SotClipboardFormatId::DRAWING:
546  {
547  SwDoc *const pDoc = lcl_GetDoc(*m_pClpDocFac);
550  }
551  break;
552 
553  case SotClipboardFormatId::STRING:
554  {
555  SwDoc *const pDoc = lcl_GetDoc(*m_pClpDocFac);
556  bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_STRING, rFlavor );
557  }
558  break;
559  case SotClipboardFormatId::RTF:
560  {
561  SwDoc *const pDoc = lcl_GetDoc(*m_pClpDocFac);
562  bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_RTF, rFlavor );
563  }
564  break;
565  case SotClipboardFormatId::RICHTEXT:
566  {
567  SwDoc *const pDoc = lcl_GetDoc(*m_pClpDocFac);
568  bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_RICHTEXT, rFlavor );
569  }
570  break;
571 
572  case SotClipboardFormatId::HTML:
573  {
574  SwDoc *const pDoc = lcl_GetDoc(*m_pClpDocFac);
575  bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_HTML, rFlavor );
576  }
577  break;
578 
579  case SotClipboardFormatId::SVXB:
581  bOK = SetGraphic( *m_pOrigGraphic );
582  break;
583 
584  case SotClipboardFormatId::GDIMETAFILE:
586  bOK = SetGDIMetaFile( m_pClpGraphic->GetGDIMetaFile() );
587  break;
588  case SotClipboardFormatId::BITMAP:
589  case SotClipboardFormatId::PNG:
590  // Neither pClpBitmap nor pClpGraphic are necessarily set
591  if( (m_eBufferType & TransferBufferType::Graphic) && (m_pClpBitmap != nullptr || m_pClpGraphic != nullptr))
592  bOK = SetBitmapEx( (m_pClpBitmap ? m_pClpBitmap : m_pClpGraphic)->GetBitmapEx(), rFlavor );
593  break;
594 
595  case SotClipboardFormatId::SVIM:
596  if( m_pImageMap )
597  bOK = SetImageMap( *m_pImageMap );
598  break;
599 
600  case SotClipboardFormatId::INET_IMAGE:
601  if( m_pTargetURL )
602  bOK = SetINetImage( *m_pTargetURL, rFlavor );
603  break;
604 
605  case SotClipboardFormatId::SOLK:
606  case SotClipboardFormatId::NETSCAPE_BOOKMARK:
607  case SotClipboardFormatId::FILEGRPDESCRIPTOR:
608  case SotClipboardFormatId::FILECONTENT:
609  case SotClipboardFormatId::UNIFORMRESOURCELOCATOR:
610  case SotClipboardFormatId::SIMPLE_FILE:
612  bOK = SetINetBookmark( *m_pBookmark, rFlavor );
613  break;
614 
615  case SotClipboardFormatId::EMBED_SOURCE:
616  if( !m_aDocShellRef.Is() )
617  {
618  SwDoc *const pDoc = lcl_GetDoc(*m_pClpDocFac);
619  SwDocShell* pNewDocSh = new SwDocShell( pDoc,
620  SfxObjectCreateMode::EMBEDDED );
621  m_aDocShellRef = pNewDocSh;
624  }
626  rFlavor );
627  break;
628  default: break;
629  }
630  }
631  return bOK;
632 }
633 
635  void* pObject, sal_uInt32 nObjectType,
636  const DataFlavor& /*rFlavor*/ )
637 {
638  bool bRet = false;
639  WriterRef xWrt;
640 
641  switch( nObjectType )
642  {
644  {
645  // don't change the sequence of commands
646  SdrModel *pModel = static_cast<SdrModel*>(pObject);
647  xStream->SetBufferSize( 16348 );
648 
649  // for the changed pool defaults from drawing layer pool set those
650  // attributes as hard attributes to preserve them for saving
651  const SfxItemPool& rItemPool = pModel->GetItemPool();
652  const SvxFontHeightItem& rDefaultFontHeight = rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT);
653 
654  // SW should have no MasterPages
655  OSL_ENSURE(0 == pModel->GetMasterPageCount(), "SW with MasterPages (!)");
656 
657  for(sal_uInt16 a(0); a < pModel->GetPageCount(); a++)
658  {
659  const SdrPage* pPage = pModel->GetPage(a);
660  SdrObjListIter aIter(pPage, SdrIterMode::DeepNoGroups);
661 
662  while(aIter.IsMore())
663  {
664  SdrObject* pObj = aIter.Next();
665  const SvxFontHeightItem& rItem = pObj->GetMergedItem(EE_CHAR_FONTHEIGHT);
666 
667  if(rItem.GetHeight() == rDefaultFontHeight.GetHeight())
668  {
669  pObj->SetMergedItem(rDefaultFontHeight);
670  }
671  }
672  }
673 
674  {
675  uno::Reference<io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *xStream ) );
676  if( SvxDrawingLayerExport( pModel, xDocOut ) )
677  xStream->Commit();
678  }
679 
680  bRet = ERRCODE_NONE == xStream->GetError();
681  }
682  break;
683 
685  {
686  SfxObjectShell* pEmbObj = static_cast<SfxObjectShell*>(pObject);
687  try
688  {
689  ::utl::TempFile aTempFile;
690  aTempFile.EnableKillingFile();
691  uno::Reference< embed::XStorage > xWorkStore =
692  ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
693 
694  // write document storage
695  pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false );
696  // mba: no BaseURL for clipboard
697  SfxMedium aMedium( xWorkStore, OUString() );
698  pEmbObj->DoSaveObjectAs( aMedium, false );
699  pEmbObj->DoSaveCompleted();
700 
701  uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
702  if ( xTransact.is() )
703  xTransact->commit();
704 
705  std::unique_ptr<SvStream> pSrcStm(::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ ));
706  if( pSrcStm )
707  {
708  xStream->SetBufferSize( 0xff00 );
709  xStream->WriteStream( *pSrcStm );
710  pSrcStm.reset();
711  }
712 
713  xWorkStore->dispose();
714  xWorkStore.clear();
715  xStream->Commit();
716  }
717  catch (const uno::Exception&)
718  {
719  }
720 
721  bRet = ( xStream->GetError() == ERRCODE_NONE );
722  }
723  break;
724 
726  {
727  xStream->SetBufferSize( 1024 );
728  SwTrnsfrDdeLink* pDdeLnk = static_cast<SwTrnsfrDdeLink*>(pObject);
729  if( pDdeLnk->WriteData( *xStream ) )
730  {
731  xStream->Commit();
732  bRet = ERRCODE_NONE == xStream->GetError();
733  }
734  }
735  break;
736 
738  GetHTMLWriter(OUString(), OUString(), xWrt);
739  break;
740 
743  GetRTFWriter(OUString(), OUString(), xWrt);
744  break;
745 
747  GetASCWriter(OUString(), OUString(), xWrt);
748  if( xWrt.is() )
749  {
750  SwAsciiOptions aAOpt;
751  aAOpt.SetCharSet( RTL_TEXTENCODING_UTF8 );
752  xWrt->SetAsciiOptions( aAOpt );
753 
754  // no start char for clipboard
755  xWrt->m_bUCS2_WithStartChar = false;
756  }
757  break;
758  default: break;
759  }
760 
761  if( xWrt.is() )
762  {
763  SwDoc* pDoc = static_cast<SwDoc*>(pObject);
764  xWrt->m_bWriteClipboardDoc = true;
765  xWrt->m_bWriteOnlyFirstTable = bool(TransferBufferType::Table & m_eBufferType);
766  xWrt->SetShowProgress(false);
767 
768 #if defined(DEBUGPASTE)
769  SvFileStream aPasteDebug(OUString(
770  "PASTEBUFFER.debug"), StreamMode::WRITE|StreamMode::TRUNC);
771  SwWriter aDbgWrt( aPasteDebug, *pDoc );
772  aDbgWrt.Write( xWrt );
773 #endif
774 
775  SwWriter aWrt( *xStream, *pDoc );
776  if( ! aWrt.Write( xWrt ).IsError() )
777  {
778  xStream->WriteChar( '\0' ); // terminate with a zero
779  xStream->Commit();
780  bRet = true;
781  }
782  }
783 
784  return bRet;
785 }
786 
788 {
789  int nRet = Copy( true );
790  if( nRet )
791  DeleteSelection();
792  return nRet;
793 }
794 
796 {
797  if(!m_pWrtShell)
798  return;
799  // ask for type of selection before action-bracketing
800  const SelectionType nSelection = m_pWrtShell->GetSelectionType();
802  if( ( SelectionType::Text | SelectionType::Table ) & nSelection )
803  m_pWrtShell->IntelligentCut( nSelection );
806 }
807 
809 {
810  int nRet = 1;
811  if(!m_pWrtShell)
812  return 0;
813 
814  OUString sGrfNm;
815  const SelectionType nSelection = m_pWrtShell->GetSelectionType();
816  if( nSelection == SelectionType::Graphic )
817  {
818  m_pClpGraphic.reset(new Graphic);
819  if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *m_pClpGraphic ))
821  m_pClpBitmap.reset(new Graphic);
822  if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *m_pClpBitmap ))
824 
825  m_pClpDocFac.reset(new SwDocFac);
826  SwDoc *const pDoc = lcl_GetDoc(*m_pClpDocFac);
827  m_pWrtShell->Copy( pDoc );
828 
830  AddFormat( SotClipboardFormatId::SVXB );
831 
833  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
834 
835  const Graphic* pGrf = m_pWrtShell->GetGraphic();
836  if( pGrf && pGrf->IsSupportedGraphic() )
837  {
838  AddFormat( SotClipboardFormatId::GDIMETAFILE );
839  AddFormat( SotClipboardFormatId::PNG );
840  AddFormat( SotClipboardFormatId::BITMAP );
841  }
843  m_pWrtShell->GetGrfNms( &sGrfNm, nullptr );
844  }
845  else if ( nSelection == SelectionType::Ole )
846  {
847  m_pClpDocFac.reset(new SwDocFac);
848  SwDoc *const pDoc = lcl_GetDoc(*m_pClpDocFac);
849  m_aDocShellRef = new SwDocShell( pDoc, SfxObjectCreateMode::EMBEDDED);
851  m_pWrtShell->Copy( pDoc );
852 
853  AddFormat( SotClipboardFormatId::EMBED_SOURCE );
854 
855  // --> OD #i98753#
856  // set size of embedded object at the object description structure
857  m_aObjDesc.maSize = OutputDevice::LogicToLogic(m_pWrtShell->GetObjSize(), MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM));
858  // <--
860  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
861 
862  AddFormat( SotClipboardFormatId::GDIMETAFILE );
863 
864  // Fetch the formats supported via embedtransferhelper as well
865  sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
866  uno::Reference < embed::XEmbeddedObject > xObj = FindOLEObj( nAspect );
867  const Graphic* pOLEGraph = FindOLEReplacementGraphic();
868  if( xObj.is() )
869  {
870  TransferableDataHelper aD( new SvEmbedTransferHelper( xObj, pOLEGraph, nAspect ) );
871  if ( aD.GetTransferable().is() )
872  {
874 
875  for( const auto& rItem : aVector )
876  AddFormat( rItem );
877  }
878  }
880  }
881  // Is there anything to provide anyway?
882  else if ( m_pWrtShell->IsSelection() || m_pWrtShell->IsFrameSelected() ||
884  {
885  std::unique_ptr<SwWait> pWait;
886  if( m_pWrtShell->ShouldWait() )
887  pWait.reset(new SwWait( *m_pWrtShell->GetView().GetDocShell(), true ));
888 
889  m_pClpDocFac.reset(new SwDocFac);
890 
891  // create additional cursor so that equal treatment of keyboard
892  // and mouse selection is possible.
893  // In AddMode with keyboard selection, the new cursor is not created
894  // before the cursor is moved after end of selection.
895  if( m_pWrtShell->IsAddMode() && m_pWrtShell->SwCursorShell::HasSelection() )
897 
898  SwDoc *const pTmpDoc = lcl_GetDoc(*m_pClpDocFac);
899 
900  pTmpDoc->getIDocumentFieldsAccess().LockExpFields(); // Never update fields - leave text as is
901  lclOverWriteDoc(*m_pWrtShell, *pTmpDoc);
902 
903  {
904  IDocumentMarkAccess* const pMarkAccess = pTmpDoc->getIDocumentMarkAccess();
905  std::vector< ::sw::mark::IMark* > vDdeMarks;
906  // find all DDE-Bookmarks
907  for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAllMarksBegin();
908  ppMark != pMarkAccess->getAllMarksEnd();
909  ++ppMark)
910  {
912  vDdeMarks.push_back(ppMark->get());
913  }
914  // remove all DDE-Bookmarks, they are invalid inside the clipdoc!
915  for(const auto& rpMark : vDdeMarks)
916  pMarkAccess->deleteMark(rpMark);
917  }
918 
919  // a new one was created in CORE (OLE objects copied!)
920  m_aDocShellRef = pTmpDoc->GetTmpDocShell();
921  if( m_aDocShellRef.Is() )
923  pTmpDoc->SetTmpDocShell( nullptr );
924 
925  if( m_pWrtShell->IsObjSelected() )
927  else
928  {
930  if (m_pWrtShell->IntelligentCut(nSelection, false) != SwWrtShell::NO_WORD)
932  }
933 
934  bool bDDELink = m_pWrtShell->IsSelection();
935  if( nSelection & SelectionType::TableCell )
936  {
938  bDDELink = m_pWrtShell->HasWholeTabSelection();
939  }
940 
941  //When someone needs it, we 'OLE' him something
942  AddFormat( SotClipboardFormatId::EMBED_SOURCE );
943 
944  //put RTF ahead of the OLE's Metafile to have less loss
945  if( !m_pWrtShell->IsObjSelected() )
946  {
947  AddFormat( SotClipboardFormatId::RTF );
948  AddFormat( SotClipboardFormatId::RICHTEXT );
949  AddFormat( SotClipboardFormatId::HTML );
950  }
951  if( m_pWrtShell->IsSelection() )
952  AddFormat( SotClipboardFormatId::STRING );
953 
954  if( nSelection & ( SelectionType::DrawObject | SelectionType::DbForm ))
955  {
956  AddFormat( SotClipboardFormatId::DRAWING );
957  if ( nSelection & SelectionType::DrawObject )
958  {
959  AddFormat( SotClipboardFormatId::GDIMETAFILE );
960  AddFormat( SotClipboardFormatId::PNG );
961  AddFormat( SotClipboardFormatId::BITMAP );
962  }
964 
965  m_pClpGraphic.reset(new Graphic);
966  if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *m_pClpGraphic ))
968  m_pClpBitmap.reset(new Graphic);
969  if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *m_pClpBitmap ))
971 
972  // is it a URL-Button ?
973  OUString sURL;
974  OUString sDesc;
975  if( m_pWrtShell->GetURLFromButton( sURL, sDesc ) )
976  {
977  AddFormat( SotClipboardFormatId::STRING );
978  AddFormat( SotClipboardFormatId::SOLK );
979  AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
980  AddFormat( SotClipboardFormatId::FILECONTENT );
981  AddFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR );
982  AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR );
984  nRet = 1;
985  }
986  }
987 
988  // at Cut, DDE-Link doesn't make sense!!
989  SwDocShell* pDShell;
990  if( !bIsCut && bDDELink &&
991  nullptr != ( pDShell = m_pWrtShell->GetDoc()->GetDocShell()) &&
992  SfxObjectCreateMode::STANDARD == pDShell->GetCreateMode() )
993  {
994  AddFormat( SotClipboardFormatId::LINK );
995  m_xDdeLink = new SwTrnsfrDdeLink( *this, *m_pWrtShell );
996  }
997 
998  //ObjectDescriptor was already filly from the old DocShell.
999  //Now adjust it. Thus in GetData the first query can still
1000  //be answered with delayed rendering.
1001  Size aSz( OLESIZE );
1002  m_aObjDesc.maSize = OutputDevice::LogicToLogic(aSz, MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM));
1003 
1005  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
1006  }
1007  else
1008  nRet = 0;
1009 
1010  if( m_pWrtShell->IsFrameSelected() )
1011  {
1013  m_pWrtShell->GetFlyFrameAttr( aSet );
1014  const SwFormatURL& rURL = aSet.Get( RES_URL );
1015  if( rURL.GetMap() )
1016  {
1017  m_pImageMap.reset( new ImageMap( *rURL.GetMap() ) );
1018  AddFormat( SotClipboardFormatId::SVIM );
1019  }
1020  else if( !rURL.GetURL().isEmpty() )
1021  {
1022  m_pTargetURL.reset(new INetImage( sGrfNm, rURL.GetURL(),
1023  rURL.GetTargetFrameName() ));
1024  AddFormat( SotClipboardFormatId::INET_IMAGE );
1025  }
1026  }
1027 
1028  return nRet;
1029 }
1030 
1031 int SwTransferable::Copy( bool bIsCut )
1032 {
1033  int nRet = PrepareForCopy( bIsCut );
1034  if ( nRet )
1035  {
1037  }
1038  return nRet;
1039 }
1040 
1042 {
1043  if(!m_pWrtShell)
1044  return;
1045  SwWait aWait( *m_pWrtShell->GetView().GetDocShell(), true );
1046 
1047  OUString aStr( m_pWrtShell->Calculate() );
1048 
1049  m_pClpDocFac.reset(new SwDocFac);
1050  SwDoc *const pDoc = lcl_GetDoc(*m_pClpDocFac);
1051  m_pWrtShell->Copy(pDoc, & aStr);
1053  AddFormat( SotClipboardFormatId::STRING );
1054 
1056 }
1057 
1058 bool SwTransferable::CopyGlossary( SwTextBlocks& rGlossary, const OUString& rStr )
1059 {
1060  if(!m_pWrtShell)
1061  return false;
1062  SwWait aWait( *m_pWrtShell->GetView().GetDocShell(), true );
1063 
1064  m_pClpDocFac.reset(new SwDocFac);
1065  SwDoc *const pCDoc = lcl_GetDoc(*m_pClpDocFac);
1066 
1067  SwNodes& rNds = pCDoc->GetNodes();
1068  SwNodeIndex aNodeIdx( *rNds.GetEndOfContent().StartOfSectionNode() );
1069  SwContentNode* pCNd = rNds.GoNext( &aNodeIdx ); // go to 1st ContentNode
1070  SwPaM aPam( *pCNd );
1071 
1072  pCDoc->getIDocumentFieldsAccess().LockExpFields(); // never update fields - leave text as it is
1073 
1074  pCDoc->InsertGlossary( rGlossary, rStr, aPam );
1075 
1076  // a new one was created in CORE (OLE-Objects copied!)
1077  m_aDocShellRef = pCDoc->GetTmpDocShell();
1078  if( m_aDocShellRef.Is() )
1080  pCDoc->SetTmpDocShell( nullptr );
1081 
1083 
1084  //When someone needs it, we 'OLE' her something.
1085  AddFormat( SotClipboardFormatId::EMBED_SOURCE );
1086  AddFormat( SotClipboardFormatId::RTF );
1087  AddFormat( SotClipboardFormatId::RICHTEXT );
1088  AddFormat( SotClipboardFormatId::HTML );
1089  AddFormat( SotClipboardFormatId::STRING );
1090 
1091  //ObjectDescriptor was already filled from the old DocShell.
1092  //Now adjust it. Thus in GetData the first query can still
1093  //be answered with delayed rendering.
1094  Size aSz( OLESIZE );
1095  m_aObjDesc.maSize = OutputDevice::LogicToLogic(aSz, MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM));
1096 
1098  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
1099 
1101 
1102  return true;
1103 }
1104 
1105 static uno::Reference < XTransferable > * lcl_getTransferPointer ( uno::Reference < XTransferable > &xRef )
1106 {
1107  return &xRef;
1108 }
1109 
1111  : m_rWrtShell(rWrtShell)
1112 {
1113  remember();
1114 }
1115 
1117 {
1119  return;
1120 
1121  SwPaM* pCursor = m_rWrtShell.GetCursor();
1122  if (!pCursor)
1123  return;
1124 
1125  // Set point to the previous node, so it is not moved.
1126  const SwNodeIndex& rNodeIndex = pCursor->GetPoint()->nNode;
1127  m_pPaM.reset(new SwPaM(rNodeIndex, rNodeIndex, 0, -1));
1128  m_nStartContent = pCursor->GetPoint()->nContent.GetIndex();
1129 }
1130 
1131 void SwPasteContext::forget() { m_pPaM.reset(); }
1132 
1134 {
1135  try
1136  {
1138  return;
1139 
1140  beans::PropertyValue aPropertyValue;
1141 
1142  switch (m_rWrtShell.GetView().GetShellMode())
1143  {
1144  case ShellMode::Graphic:
1145  {
1147  if (!pFormat)
1148  return;
1149 
1150  aPropertyValue.Name = "TextGraphicObject";
1151  aPropertyValue.Value
1152  <<= SwXTextGraphicObject::CreateXTextGraphicObject(*pFormat->GetDoc(), pFormat);
1153  break;
1154  }
1155 
1156  default:
1157  {
1158  if (!m_pPaM)
1159  return;
1160 
1161  SwPaM* pCursor = m_rWrtShell.GetCursor();
1162  if (!pCursor)
1163  return;
1164 
1165  if (!pCursor->GetPoint()->nNode.GetNode().IsTextNode())
1166  // Non-text was pasted.
1167  return;
1168 
1169  // Update mark after paste.
1170  *m_pPaM->GetMark() = *pCursor->GetPoint();
1171 
1172  // Restore point.
1173  ++m_pPaM->GetPoint()->nNode;
1174  SwNode& rNode = m_pPaM->GetNode();
1175  if (!rNode.IsTextNode())
1176  // Starting point is no longer text.
1177  return;
1178 
1179  m_pPaM->GetPoint()->nContent.Assign(static_cast<SwContentNode*>(&rNode),
1180  m_nStartContent);
1181 
1182  aPropertyValue.Name = "TextRange";
1183  const uno::Reference<text::XTextRange> xTextRange = SwXTextRange::CreateXTextRange(
1184  *m_pPaM->GetDoc(), *m_pPaM->GetPoint(), m_pPaM->GetMark());
1185  aPropertyValue.Value <<= xTextRange;
1186  break;
1187  }
1188  }
1189 
1190  if (aPropertyValue.Name.isEmpty())
1191  return;
1192 
1193  // Invoke the listeners.
1194  uno::Sequence<beans::PropertyValue> aEvent{ aPropertyValue };
1195 
1197  while (it.hasMoreElements())
1198  {
1199  uno::Reference<text::XPasteListener> xListener(it.next(), UNO_QUERY);
1200  if (xListener.is())
1201  xListener->notifyPasteEvent(aEvent);
1202  }
1203  }
1204  catch (const uno::Exception& rException)
1205  {
1206  SAL_WARN("sw",
1207  "SwPasteContext::~SwPasteContext: uncaught exception: " << rException.Message);
1208  }
1209 }
1210 
1212  const TransferableDataHelper& rData )
1213 {
1214  // Check the common case first: We can always paste our own data!
1215  // If _only_ the internal format can be pasted, this check will
1216  // yield 'true', while the one below would give a (wrong) result 'false'.
1217 
1218  bool bIsPaste = ( GetSwTransferable( rData ) != nullptr );
1219 
1220  // if it's not our own data, we need to have a closer look:
1221  if( ! bIsPaste )
1222  {
1223  // determine the proper paste action, and return true if we find one
1224  uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
1225 
1226  SotExchangeDest nDestination = SwTransferable::GetSotDestination( rSh );
1227  sal_uInt16 nSourceOptions =
1228  (( SotExchangeDest::DOC_TEXTFRAME == nDestination ||
1229  SotExchangeDest::SWDOC_FREE_AREA == nDestination ||
1230  SotExchangeDest::DOC_TEXTFRAME_WEB == nDestination ||
1231  SotExchangeDest::SWDOC_FREE_AREA_WEB == nDestination )
1234 
1235  SotClipboardFormatId nFormat; // output param for GetExchangeAction
1236  sal_uInt8 nEventAction; // output param for GetExchangeAction
1238  rData.GetDataFlavorExVector(),
1239  nDestination,
1240  nSourceOptions, /* ?? */
1241  EXCHG_IN_ACTION_DEFAULT, /* ?? */
1242  nFormat, nEventAction, SotClipboardFormatId::NONE,
1243  lcl_getTransferPointer ( xTransferable ) );
1244 
1245  // if we find a suitable action, we can paste!
1246  bIsPaste = (EXCHG_INOUT_ACTION_NONE != nAction);
1247  }
1248 
1249  return bIsPaste;
1250 }
1251 
1252 bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndStdIds nAnchorType, bool bIgnoreComments)
1253 {
1254  SwPasteContext aPasteContext(rSh);
1255 
1256  sal_uInt8 nEventAction, nAction=0;
1257  SotExchangeDest nDestination = SwTransferable::GetSotDestination( rSh );
1258  SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
1259  SotExchangeActionFlags nActionFlags = SotExchangeActionFlags::NONE;
1260  bool bSingleCellTable = false;
1261 
1262  if( GetSwTransferable( rData ) )
1263  {
1265  }
1266  else
1267  {
1268  sal_uInt16 nSourceOptions =
1269  (( SotExchangeDest::DOC_TEXTFRAME == nDestination ||
1270  SotExchangeDest::SWDOC_FREE_AREA == nDestination ||
1271  SotExchangeDest::DOC_TEXTFRAME_WEB == nDestination ||
1272  SotExchangeDest::SWDOC_FREE_AREA_WEB == nDestination )
1275  uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
1277  rData.GetDataFlavorExVector(),
1278  nDestination,
1279  nSourceOptions, /* ?? */
1280  EXCHG_IN_ACTION_DEFAULT, /* ?? */
1281  nFormat, nEventAction, SotClipboardFormatId::NONE,
1282  lcl_getTransferPointer ( xTransferable ),
1283  &nActionFlags );
1284  }
1285 
1286  // tdf#37223 avoid OLE insertion of worksheets in the following cases:
1287  // content of 1-cell worksheets are inserted as simple text using RTF format,
1288  // bigger worksheets within native (Writer) table cells are inserted as native tables,
1289  // ie. cell by cell instead of embedding the worksheet in a single cell of the Writer table
1290  if ( EXCHG_OUT_ACTION_INSERT_OLE == nAction && ( rData.HasFormat( SotClipboardFormatId::SYLK ) ||
1291  rData.HasFormat( SotClipboardFormatId::SYLK_BIGCAPS ) ) )
1292  {
1293  // is it a 1-cell worksheet?
1294  OUString aExpand;
1295  if( rData.GetString( SotClipboardFormatId::STRING, aExpand ))
1296  {
1297  const sal_Int32 nNewlines{comphelper::string::getTokenCount(aExpand, '\n')};
1298  const sal_Int32 nRows = nNewlines ? nNewlines-1 : 0;
1299  if ( nRows == 1 )
1300  {
1301  const sal_Int32 nCols = comphelper::string::getTokenCount(aExpand.getToken(0, '\n'), '\t');
1302  if (nCols == 1)
1303  bSingleCellTable = true;
1304  }
1305  }
1306 
1307  // convert the worksheet to a temporary native table using HTML format, and copy that into the original native table
1308  if (!bSingleCellTable && rData.HasFormat( SotClipboardFormatId::HTML ) &&
1309  rSh.GetDoc()->IsIdxInTable(rSh.GetCursor()->GetNode()) != nullptr && rSh.DoesUndo())
1310  {
1311  SfxDispatcher* pDispatch = rSh.GetView().GetViewFrame()->GetDispatcher();
1312  sal_uInt32 nLevel = 0;
1313  // within Writer table cells, inserting worksheets using HTML format results only plain text, not a native table,
1314  // so remove all outer nested tables temporary to get a working insertion point
1315  // (RTF format has no such problem, but that inserts the hidden rows of the original Calc worksheet, too)
1316  do
1317  {
1318  // insert a random character to redo the place of the insertion at the end
1319  pDispatch->Execute(FN_INSERT_NNBSP, SfxCallMode::SYNCHRON);
1320  pDispatch->Execute(FN_TABLE_DELETE_TABLE, SfxCallMode::SYNCHRON);
1321  nLevel++;
1322  } while (rSh.GetDoc()->IsIdxInTable(rSh.GetCursor()->GetNode()) != nullptr);
1323  if ( SwTransferable::PasteData( rData, rSh, EXCHG_OUT_ACTION_INSERT_STRING, nActionFlags, SotClipboardFormatId::HTML,
1324  nDestination, false, false, nullptr, 0, false, nAnchorType, bIgnoreComments, &aPasteContext ))
1325  {
1326  pDispatch->Execute(FN_CHAR_LEFT, SfxCallMode::SYNCHRON);
1327  pDispatch->Execute(FN_TABLE_SELECT_ALL, SfxCallMode::SYNCHRON);
1328  pDispatch->Execute(SID_COPY, SfxCallMode::SYNCHRON);
1329  for(sal_uInt32 a = 0; a < 1 + (nLevel * 2); a++)
1330  pDispatch->Execute(SID_UNDO, SfxCallMode::SYNCHRON);
1331  pDispatch->Execute(SID_PASTE, SfxCallMode::SYNCHRON);
1332  return true;
1333  } else {
1334  for(sal_uInt32 a = 0; a < (nLevel * 2); a++)
1335  pDispatch->Execute(SID_UNDO, SfxCallMode::SYNCHRON);
1336  }
1337  }
1338  }
1339 
1340  // special case for tables from draw application or 1-cell tables
1341  if( EXCHG_OUT_ACTION_INSERT_DRAWOBJ == nAction || bSingleCellTable )
1342  {
1343  if( rData.HasFormat( SotClipboardFormatId::RTF ) )
1344  {
1346  nFormat = SotClipboardFormatId::RTF;
1347  }
1348  else if( rData.HasFormat( SotClipboardFormatId::RICHTEXT ) )
1349  {
1351  nFormat = SotClipboardFormatId::RICHTEXT;
1352  }
1353  }
1354 
1355  return EXCHG_INOUT_ACTION_NONE != nAction &&
1356  SwTransferable::PasteData( rData, rSh, nAction, nActionFlags, nFormat,
1357  nDestination, false, false, nullptr, 0, false, nAnchorType, bIgnoreComments, &aPasteContext );
1358 }
1359 
1361  SwWrtShell& rSh, sal_uInt8 nAction, SotExchangeActionFlags nActionFlags,
1362  SotClipboardFormatId nFormat,
1363  SotExchangeDest nDestination, bool bIsPasteFormat,
1364  bool bIsDefault,
1365  const Point* pPt, sal_Int8 nDropAction,
1366  bool bPasteSelection, RndStdIds nAnchorType,
1367  bool bIgnoreComments,
1368  SwPasteContext* pContext )
1369 {
1370  SwWait aWait( *rSh.GetView().GetDocShell(), false );
1371  std::unique_ptr<SwTrnsfrActionAndUndo, o3tl::default_delete<SwTrnsfrActionAndUndo>> pAction;
1372  SwModule* pMod = SW_MOD();
1373 
1374  bool bRet = false;
1375  bool bCallAutoCaption = false;
1376 
1377  if( pPt )
1378  {
1379  // external Drop
1380  if( bPasteSelection ? !pMod->m_pXSelection : !pMod->m_pDragDrop )
1381  {
1382  switch( nDestination )
1383  {
1384  case SotExchangeDest::DOC_LNKD_GRAPH_W_IMAP:
1385  case SotExchangeDest::DOC_LNKD_GRAPHOBJ:
1386  case SotExchangeDest::DOC_GRAPH_W_IMAP:
1387  case SotExchangeDest::DOC_GRAPHOBJ:
1388  case SotExchangeDest::DOC_OLEOBJ:
1389  case SotExchangeDest::DOC_DRAWOBJ:
1390  case SotExchangeDest::DOC_URLBUTTON:
1391  case SotExchangeDest::DOC_GROUPOBJ:
1392  // select frames/objects
1393  SwTransferable::SetSelInShell( rSh, true, pPt );
1394  break;
1395 
1396  default:
1397  SwTransferable::SetSelInShell( rSh, false, pPt );
1398  break;
1399  }
1400  }
1401  }
1402  else if( ( !GetSwTransferable( rData ) || bIsPasteFormat ) &&
1403  !rSh.IsTableMode() && rSh.HasSelection() )
1404  {
1405  // then delete the selections
1406 
1407  //don't delete selected content
1408  // - at table-selection
1409  // - at ReRead of a graphic/DDEData
1410  // - at D&D, for the right selection was taken care of
1411  // in Drop-Handler
1412  bool bDelSel = false;
1413  switch( nDestination )
1414  {
1415  case SotExchangeDest::DOC_TEXTFRAME:
1416  case SotExchangeDest::SWDOC_FREE_AREA:
1417  case SotExchangeDest::DOC_TEXTFRAME_WEB:
1418  case SotExchangeDest::SWDOC_FREE_AREA_WEB:
1419  bDelSel = true;
1420  break;
1421  default:
1422  break;
1423  }
1424 
1425  if( bDelSel )
1426  // #i34830#
1427  pAction.reset(new SwTrnsfrActionAndUndo(&rSh, true, pContext));
1428  }
1429 
1430  SwTransferable *pTrans=nullptr, *pTunneledTrans=GetSwTransferable( rData );
1431 
1432  // check for private drop
1433  bool bPrivateDrop(pPt);
1434  if (bPrivateDrop)
1435  {
1436  if (bPasteSelection)
1437  pTrans = pMod->m_pXSelection;
1438  else
1439  pTrans = pMod->m_pDragDrop;
1440  bPrivateDrop = nullptr != pTrans;
1441  }
1442  bool bNeedToSelectBeforePaste(false);
1443 
1444  if(bPrivateDrop && DND_ACTION_LINK == nDropAction)
1445  {
1446  // internal drop on object, suppress bPrivateDrop to change internal fill
1447  bPrivateDrop = false;
1448  bNeedToSelectBeforePaste = true;
1449  }
1450 
1451  if(bPrivateDrop && pPt && DND_ACTION_MOVE == nDropAction)
1452  {
1453  // check if dragged over a useful target. If yes, use as content exchange
1454  // drop as if from external
1455  const SwFrameFormat* pSwFrameFormat = rSh.GetFormatFromObj(*pPt);
1456 
1457  if(dynamic_cast< const SwDrawFrameFormat* >(pSwFrameFormat))
1458  {
1459  bPrivateDrop = false;
1460  bNeedToSelectBeforePaste = true;
1461  }
1462  }
1463 
1464  if(bPrivateDrop)
1465  {
1466  // then internal Drag & Drop or XSelection
1467  bRet = pTrans->PrivateDrop( rSh, *pPt, DND_ACTION_MOVE == nDropAction,
1468  bPasteSelection );
1469  }
1470  else if( !pPt && pTunneledTrans &&
1471  EXCHG_OUT_ACTION_INSERT_PRIVATE == nAction )
1472  {
1473  // then internal paste
1474  bRet = pTunneledTrans->PrivatePaste(rSh, pContext);
1475  }
1476  else if( EXCHG_INOUT_ACTION_NONE != nAction )
1477  {
1478  if( !pAction )
1479  {
1480  pAction.reset(new SwTrnsfrActionAndUndo( &rSh ));
1481  }
1482 
1483  // in Drag&Drop MessageBoxes must not be showed
1484  bool bMsg = nullptr == pPt;
1485 
1486  // delete selections
1487 
1488  switch( nAction )
1489  {
1491  OSL_ENSURE( pPt, "EXCHG_OUT_ACTION_INSERT_PRIVATE: what should happen here?" );
1492  break;
1493 
1495  OSL_ENSURE( pPt, "EXCHG_OUT_ACTION_MOVE_PRIVATE: what should happen here?" );
1496  break;
1497 
1498  case EXCHG_IN_ACTION_MOVE:
1499  case EXCHG_IN_ACTION_COPY:
1500  case EXCHG_IN_ACTION_LINK:
1505 
1506  // then we have to use the format
1507  switch( nFormat )
1508  {
1509  case SotClipboardFormatId::DRAWING:
1510  bRet = SwTransferable::PasteSdrFormat( rData, rSh,
1511  SwPasteSdr::Insert, pPt,
1512  nActionFlags, bNeedToSelectBeforePaste);
1513  break;
1514 
1515  case SotClipboardFormatId::HTML:
1516  case SotClipboardFormatId::HTML_SIMPLE:
1517  case SotClipboardFormatId::HTML_NO_COMMENT:
1518  case SotClipboardFormatId::RTF:
1519  case SotClipboardFormatId::RICHTEXT:
1520  case SotClipboardFormatId::STRING:
1521  bRet = SwTransferable::PasteFileContent( rData, rSh,
1522  nFormat, bMsg, bIgnoreComments );
1523  break;
1524 
1525  case SotClipboardFormatId::NETSCAPE_BOOKMARK:
1526  {
1527  INetBookmark aBkmk;
1528  if( rData.GetINetBookmark( nFormat, aBkmk ) )
1529  {
1530  SwFormatINetFormat aFormat( aBkmk.GetURL(), OUString() );
1531  rSh.InsertURL( aFormat, aBkmk.GetDescription() );
1532  bRet = true;
1533  }
1534  }
1535  break;
1536 
1537  case SotClipboardFormatId::SD_OLE:
1538  bRet = SwTransferable::PasteOLE( rData, rSh, nFormat,
1539  nActionFlags, bMsg );
1540  break;
1541 
1542  case SotClipboardFormatId::SVIM:
1543  bRet = SwTransferable::PasteImageMap( rData, rSh );
1544  break;
1545 
1546  case SotClipboardFormatId::SVXB:
1547  case SotClipboardFormatId::BITMAP:
1548  case SotClipboardFormatId::PNG:
1549  case SotClipboardFormatId::GDIMETAFILE:
1550  bRet = SwTransferable::PasteGrf( rData, rSh, nFormat,
1551  SwPasteSdr::Insert,pPt,
1552  nActionFlags, nDropAction, bNeedToSelectBeforePaste);
1553  break;
1554 
1555  case SotClipboardFormatId::XFORMS:
1556  case SotClipboardFormatId::SBA_FIELDDATAEXCHANGE:
1557  case SotClipboardFormatId::SBA_DATAEXCHANGE:
1558  case SotClipboardFormatId::SBA_CTRLDATAEXCHANGE:
1559  bRet = SwTransferable::PasteDBData( rData, rSh, nFormat,
1560  EXCHG_IN_ACTION_LINK == nAction,
1561  pPt, bMsg );
1562  break;
1563 
1564  case SotClipboardFormatId::SIMPLE_FILE:
1565  bRet = SwTransferable::PasteFileName( rData, rSh, nFormat,
1566  ( EXCHG_IN_ACTION_MOVE == nAction
1568  : EXCHG_IN_ACTION_LINK == nAction
1570  : SwPasteSdr::Insert),
1571  pPt, nActionFlags, nullptr );
1572  break;
1573 
1574  case SotClipboardFormatId::FILE_LIST:
1575  // then insert as graphics only
1576  bRet = SwTransferable::PasteFileList( rData, rSh,
1577  EXCHG_IN_ACTION_LINK == nAction,
1578  pPt, bMsg );
1579  break;
1580 
1581  case SotClipboardFormatId::SONLK:
1582  if( pPt )
1583  {
1584  NaviContentBookmark aBkmk;
1585  if( aBkmk.Paste( rData ) )
1586  {
1587  if(bIsDefault)
1588  {
1589  switch(aBkmk.GetDefaultDragType())
1590  {
1591  case RegionMode::NONE: nAction = EXCHG_IN_ACTION_COPY; break;
1592  case RegionMode::EMBEDDED: nAction = EXCHG_IN_ACTION_MOVE; break;
1593  case RegionMode::LINK: nAction = EXCHG_IN_ACTION_LINK; break;
1594  }
1595  }
1596  rSh.NavigatorPaste( aBkmk, nAction );
1597  bRet = true;
1598  }
1599  }
1600  break;
1601 
1602  case SotClipboardFormatId::INET_IMAGE:
1603  case SotClipboardFormatId::NETSCAPE_IMAGE:
1604  bRet = SwTransferable::PasteTargetURL( rData, rSh,
1605  SwPasteSdr::Insert,
1606  pPt, true );
1607  break;
1608 
1609  default:
1610  OSL_ENSURE( pPt, "unknown format" );
1611  }
1612  break;
1613 
1615  {
1616  bool graphicInserted;
1617  bRet = SwTransferable::PasteFileName( rData, rSh, nFormat,
1618  SwPasteSdr::Insert, pPt,
1619  nActionFlags,
1620  &graphicInserted );
1621  if( graphicInserted )
1622  bCallAutoCaption = true;
1623  }
1624  break;
1625 
1627  bRet = SwTransferable::PasteOLE( rData, rSh, nFormat,
1628  nActionFlags,bMsg );
1629  break;
1630 
1632  {
1633  bool bReRead = 0 != CNT_HasGrf( rSh.GetCntType() );
1634  bRet = SwTransferable::PasteDDE( rData, rSh, bReRead, bMsg );
1635  }
1636  break;
1637 
1639  {
1640  OUString sURL, sDesc;
1641  if( SotClipboardFormatId::SIMPLE_FILE == nFormat )
1642  {
1643  if( rData.GetString( nFormat, sURL ) && !sURL.isEmpty() )
1644  {
1645  SwTransferable::CheckForURLOrLNKFile( rData, sURL, &sDesc );
1646  if( sDesc.isEmpty() )
1647  sDesc = sURL;
1648  bRet = true;
1649  }
1650  }
1651  else
1652  {
1653  INetBookmark aBkmk;
1654  if( rData.GetINetBookmark( nFormat, aBkmk ) )
1655  {
1656  sURL = aBkmk.GetURL();
1657  sDesc = aBkmk.GetDescription();
1658  bRet = true;
1659  }
1660  }
1661 
1662  if( bRet )
1663  {
1664  SwFormatINetFormat aFormat( sURL, OUString() );
1665  rSh.InsertURL( aFormat, sDesc );
1666  }
1667  }
1668  break;
1669 
1671  switch( nFormat )
1672  {
1673  case SotClipboardFormatId::DRAWING:
1674  bRet = SwTransferable::PasteSdrFormat( rData, rSh,
1675  SwPasteSdr::SetAttr, pPt,
1676  nActionFlags, bNeedToSelectBeforePaste);
1677  break;
1678  case SotClipboardFormatId::SVXB:
1679  case SotClipboardFormatId::GDIMETAFILE:
1680  case SotClipboardFormatId::BITMAP:
1681  case SotClipboardFormatId::PNG:
1682  case SotClipboardFormatId::NETSCAPE_BOOKMARK:
1683  case SotClipboardFormatId::SIMPLE_FILE:
1684  case SotClipboardFormatId::FILEGRPDESCRIPTOR:
1685  case SotClipboardFormatId::UNIFORMRESOURCELOCATOR:
1686  bRet = SwTransferable::PasteGrf( rData, rSh, nFormat,
1687  SwPasteSdr::SetAttr, pPt,
1688  nActionFlags, nDropAction, bNeedToSelectBeforePaste);
1689  break;
1690  default:
1691  OSL_FAIL( "unknown format" );
1692  }
1693 
1694  break;
1695 
1697  bRet = SwTransferable::PasteSdrFormat( rData, rSh,
1698  SwPasteSdr::Insert, pPt,
1699  nActionFlags, bNeedToSelectBeforePaste);
1700  break;
1705  bRet = SwTransferable::PasteGrf( rData, rSh, nFormat,
1706  SwPasteSdr::Insert, pPt,
1707  nActionFlags, nDropAction, bNeedToSelectBeforePaste, nAnchorType );
1708  break;
1709 
1711  bRet = SwTransferable::PasteSdrFormat( rData, rSh,
1712  SwPasteSdr::Replace, pPt,
1713  nActionFlags, bNeedToSelectBeforePaste);
1714  break;
1715 
1720  bRet = SwTransferable::PasteGrf( rData, rSh, nFormat,
1721  SwPasteSdr::Replace,pPt,
1722  nActionFlags, nDropAction, bNeedToSelectBeforePaste);
1723  break;
1724 
1726  bRet = SwTransferable::PasteAsHyperlink( rData, rSh, nFormat );
1727  break;
1728 
1729  default:
1730  OSL_FAIL("unknown action" );
1731  }
1732  }
1733 
1734  if( !bPasteSelection && rSh.IsFrameSelected() )
1735  {
1736  rSh.EnterSelFrameMode();
1737  //force ::SelectShell
1738  rSh.GetView().StopShellTimer();
1739  }
1740 
1741  pAction.reset();
1742  if( bCallAutoCaption )
1743  rSh.GetView().AutoCaption( GRAPHIC_CAP );
1744 
1745  return bRet;
1746 }
1747 
1749 {
1750  SotExchangeDest nRet = SotExchangeDest::NONE;
1751 
1752  ObjCntType eOType = rSh.GetObjCntTypeOfSelection();
1753 
1754  switch( eOType )
1755  {
1756  case OBJCNT_GRF:
1757  {
1758  bool bIMap, bLink;
1759  bIMap = nullptr != rSh.GetFlyFrameFormat()->GetURL().GetMap();
1760  OUString aDummy;
1761  rSh.GetGrfNms( &aDummy, nullptr );
1762  bLink = !aDummy.isEmpty();
1763 
1764  if( bLink && bIMap )
1765  nRet = SotExchangeDest::DOC_LNKD_GRAPH_W_IMAP;
1766  else if( bLink )
1767  nRet = SotExchangeDest::DOC_LNKD_GRAPHOBJ;
1768  else if( bIMap )
1769  nRet = SotExchangeDest::DOC_GRAPH_W_IMAP;
1770  else
1771  nRet = SotExchangeDest::DOC_GRAPHOBJ;
1772  }
1773  break;
1774 
1775  case OBJCNT_FLY:
1776  if( dynamic_cast< const SwWebDocShell *>( rSh.GetView().GetDocShell() ) != nullptr )
1777  nRet = SotExchangeDest::DOC_TEXTFRAME_WEB;
1778  else
1779  nRet = SotExchangeDest::DOC_TEXTFRAME;
1780  break;
1781  case OBJCNT_OLE: nRet = SotExchangeDest::DOC_OLEOBJ; break;
1782 
1783  case OBJCNT_CONTROL: /* no Action avail */
1784  case OBJCNT_SIMPLE: nRet = SotExchangeDest::DOC_DRAWOBJ; break;
1785  case OBJCNT_URLBUTTON: nRet = SotExchangeDest::DOC_URLBUTTON; break;
1786  case OBJCNT_GROUPOBJ: nRet = SotExchangeDest::DOC_GROUPOBJ; break;
1787 
1788  // what do we do at multiple selections???
1789  default:
1790  {
1791  if( dynamic_cast< const SwWebDocShell *>( rSh.GetView().GetDocShell() ) != nullptr )
1792  nRet = SotExchangeDest::SWDOC_FREE_AREA_WEB;
1793  else
1794  nRet = SotExchangeDest::SWDOC_FREE_AREA;
1795  }
1796  }
1797 
1798  return nRet;
1799 }
1800 
1802  SwWrtShell& rSh, SotClipboardFormatId nFormat, bool bMsg, bool bIgnoreComments )
1803 {
1804  const char* pResId = STR_CLPBRD_FORMAT_ERROR;
1805  bool bRet = false;
1806 
1807  MSE40HTMLClipFormatObj aMSE40ClpObj;
1808 
1810  SvStream* pStream = nullptr;
1811  Reader* pRead = nullptr;
1812  OUString sData;
1813  switch( nFormat )
1814  {
1815  case SotClipboardFormatId::STRING:
1816  {
1817  pRead = ReadAscii;
1818  if( rData.GetString( nFormat, sData ) )
1819  {
1820  pStream = new SvMemoryStream( const_cast<sal_Unicode *>(sData.getStr()),
1821  sData.getLength() * sizeof( sal_Unicode ),
1822  StreamMode::READ );
1823 #ifdef OSL_BIGENDIAN
1824  pStream->SetEndian( SvStreamEndian::BIG );
1825 #else
1826  pStream->SetEndian( SvStreamEndian::LITTLE );
1827 #endif
1828 
1829  SwAsciiOptions aAOpt;
1830  aAOpt.SetCharSet( RTL_TEXTENCODING_UCS2 );
1831  pRead->GetReaderOpt().SetASCIIOpts( aAOpt );
1832  break;
1833  }
1834  }
1835  [[fallthrough]]; // because then test if we get a stream
1836 
1837  default:
1838  if( rData.GetSotStorageStream( nFormat, xStrm ) )
1839  {
1840  if( ( SotClipboardFormatId::HTML_SIMPLE == nFormat ) ||
1841  ( SotClipboardFormatId::HTML_NO_COMMENT == nFormat ) )
1842  {
1843  pStream = aMSE40ClpObj.IsValid( *xStrm );
1844  pRead = ReadHTML;
1845  pRead->SetReadUTF8( true );
1846 
1847  bool bNoComments =
1848  ( nFormat == SotClipboardFormatId::HTML_NO_COMMENT );
1849  pRead->SetIgnoreHTMLComments( bNoComments );
1850  }
1851  else
1852  {
1853  pStream = xStrm.get();
1854  if( SotClipboardFormatId::RTF == nFormat || SotClipboardFormatId::RICHTEXT == nFormat)
1855  pRead = SwReaderWriter::GetRtfReader();
1856  else if( !pRead )
1857  {
1858  pRead = ReadHTML;
1859  pRead->SetReadUTF8( true );
1860  }
1861  }
1862  }
1863  break;
1864  }
1865 
1866  if( pStream && pRead )
1867  {
1868  Link<SwCursorShell*,void> aOldLink( rSh.GetChgLnk() );
1870 
1871  const SwPosition& rInsPos = *rSh.GetCursor()->Start();
1872  SwReader aReader(*pStream, OUString(), OUString(), *rSh.GetCursor());
1873  rSh.SaveTableBoxContent( &rInsPos );
1874 
1875  if (bIgnoreComments)
1876  pRead->SetIgnoreHTMLComments(true);
1877 
1878  if( aReader.Read( *pRead ).IsError() )
1879  pResId = STR_ERROR_CLPBRD_READ;
1880  else
1881  {
1882  pResId = nullptr;
1883  bRet = true;
1884  }
1885 
1886  rSh.SetChgLnk( aOldLink );
1887  if( bRet )
1888  rSh.CallChgLnk();
1889  }
1890  else
1891  pResId = STR_CLPBRD_FORMAT_ERROR;
1892 
1893  // Exist a SvMemoryStream? (data in the OUString and xStrm is empty)
1894  if( pStream && !xStrm.is() )
1895  delete pStream;
1896 
1897  if (bMsg && pResId)
1898  {
1899  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
1900  VclMessageType::Info, VclButtonsType::Ok,
1901  SwResId(pResId)));
1902  xBox->run();
1903  }
1904  return bRet;
1905 }
1906 
1908  SotClipboardFormatId nFormat, SotExchangeActionFlags nActionFlags, bool bMsg )
1909 {
1910  bool bRet = false;
1912  uno::Reference < io::XInputStream > xStrm;
1913  uno::Reference < embed::XStorage > xStore;
1914  Reader* pRead = nullptr;
1915 
1916  // Get the preferred format
1918  if( rData.HasFormat( SotClipboardFormatId::EMBEDDED_OBJ ) )
1919  nId = SotClipboardFormatId::EMBEDDED_OBJ;
1920  else if( rData.HasFormat( SotClipboardFormatId::EMBED_SOURCE ) &&
1921  rData.HasFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ))
1922  nId = SotClipboardFormatId::EMBED_SOURCE;
1923  else
1924  nId = SotClipboardFormatId::NONE;
1925 
1926  if (nId != SotClipboardFormatId::NONE)
1927  {
1928  SwDocShell* pDocSh = rSh.GetDoc()->GetDocShell();
1929  xStrm = rData.GetInputStream(nId, SfxObjectShell::CreateShellID(pDocSh));
1930  }
1931 
1932  if (xStrm.is())
1933  {
1934  // if there is an embedded object, first try if it's a writer object
1935  // this will be inserted into the document by using a Reader
1936  try
1937  {
1939  switch( SotStorage::GetFormatID( xStore ) )
1940  {
1941  case SotClipboardFormatId::STARWRITER_60:
1942  case SotClipboardFormatId::STARWRITERWEB_60:
1943  case SotClipboardFormatId::STARWRITERGLOB_60:
1944  case SotClipboardFormatId::STARWRITER_8:
1945  case SotClipboardFormatId::STARWRITERWEB_8:
1946  case SotClipboardFormatId::STARWRITERGLOB_8:
1947  pRead = ReadXML;
1948  break;
1949  default:
1950  try
1951  {
1952  uno::Reference < lang::XComponent > xComp( xStore, uno::UNO_QUERY );
1953  xComp->dispose();
1954  xStore = nullptr;
1955  }
1956  catch (const uno::Exception&)
1957  {
1958  }
1959 
1960  break;
1961  }
1962  }
1963  catch (const uno::Exception&)
1964  {
1965  // it wasn't a storage, but maybe it's a useful stream
1966  }
1967  }
1968 
1969  if( pRead )
1970  {
1971  SwPaM &rPAM = *rSh.GetCursor();
1972  SwReader aReader(xStore, OUString(), rPAM);
1973  if( ! aReader.Read( *pRead ).IsError() )
1974  bRet = true;
1975  else if( bMsg )
1976  {
1977  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
1978  VclMessageType::Info, VclButtonsType::Ok,
1979  SwResId(STR_ERROR_CLPBRD_READ)));
1980  xBox->run();
1981  }
1982  }
1983  else
1984  {
1985  // temporary storage until the object is inserted
1986  uno::Reference< embed::XStorage > xTmpStor;
1987  uno::Reference < embed::XEmbeddedObject > xObj;
1988  OUString aName;
1990 
1991  if ( xStrm.is() )
1992  {
1993  if ( !rData.GetTransferableObjectDescriptor( SotClipboardFormatId::OBJECTDESCRIPTOR, aObjDesc ) )
1994  {
1995  OSL_ENSURE( !xStrm.is(), "An object without descriptor in clipboard!");
1996  }
1997  }
1998  else
1999  {
2000  if( rData.HasFormat( SotClipboardFormatId::OBJECTDESCRIPTOR_OLE ) && rData.GetTransferableObjectDescriptor( nFormat, aObjDesc ) )
2001  {
2002  xStrm = rData.GetInputStream(SotClipboardFormatId::EMBED_SOURCE_OLE, OUString());
2003  if (!xStrm.is())
2004  xStrm = rData.GetInputStream(SotClipboardFormatId::EMBEDDED_OBJ_OLE, OUString());
2005 
2006  if ( !xStrm.is() )
2007  {
2008  // This is MSOLE object that should be created by direct using of system clipboard
2009  try
2010  {
2012  uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator =
2013  embed::MSOLEObjectSystemCreator::create( ::comphelper::getProcessComponentContext() );
2014 
2015  embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
2016  xTmpStor,
2017  "DummyName",
2018  uno::Sequence< beans::PropertyValue >() );
2019 
2020  // TODO/LATER: in future InsertedObjectInfo will be used to get container related information
2021  // for example whether the object should be an iconified one
2022  xObj = aInfo.Object;
2023  }
2024  catch (const uno::Exception&)
2025  {
2026  }
2027  }
2028  }
2029  }
2030 
2031  if ( xStrm.is() && !xObj.is() )
2032  xObj = aCnt.InsertEmbeddedObject( xStrm, aName );
2033 
2034  if( xObj.is() )
2035  {
2036  svt::EmbeddedObjectRef xObjRef( xObj, aObjDesc.mnViewAspect );
2037 
2038  // try to get the replacement image from the clipboard
2039  Graphic aGraphic;
2040  SotClipboardFormatId nGrFormat = SotClipboardFormatId::NONE;
2041 
2042  // limit the size of the preview metafile to 100000 actions
2043  GDIMetaFile aMetafile;
2044  if (rData.GetGDIMetaFile(SotClipboardFormatId::GDIMETAFILE, aMetafile, 100000))
2045  {
2046  nGrFormat = SotClipboardFormatId::GDIMETAFILE;
2047  aGraphic = aMetafile;
2048  }
2049 
2050  // insert replacement image ( if there is one ) into the object helper
2051  if ( nGrFormat != SotClipboardFormatId::NONE )
2052  {
2053  DataFlavor aDataFlavor;
2054  SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
2055  xObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType );
2056  }
2057  else if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
2058  {
2059  // it is important to have an icon, let an empty graphic be used
2060  // if no other graphic is provided
2061  // TODO/LATER: in future a default bitmap could be used
2062  MapMode aMapMode( MapUnit::Map100thMM );
2063  aGraphic.SetPrefSize( Size( 2500, 2500 ) );
2064  aGraphic.SetPrefMapMode( aMapMode );
2065  xObjRef.SetGraphic( aGraphic, OUString() );
2066  }
2067 
2068  //set size. This is a hack because of handing over, size should be
2069  //passed to the InsertOle!!!!!!!!!!
2070  Size aSize;
2071  if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
2072  {
2073  if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
2074  aSize = aObjDesc.maSize;
2075  else
2076  {
2077  MapMode aMapMode( MapUnit::Map100thMM );
2078  aSize = xObjRef.GetSize( &aMapMode );
2079  }
2080  }
2081  else if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
2082  {
2083  aSize = aObjDesc.maSize; //always 100TH_MM
2084  MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) );
2085  aSize = OutputDevice::LogicToLogic(aSize, MapMode(MapUnit::Map100thMM), MapMode(aUnit));
2086  awt::Size aSz;
2087  try
2088  {
2089  aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
2090  }
2091  catch (const embed::NoVisualAreaSizeException&)
2092  {
2093  // in this case the provided size is used
2094  }
2095 
2096  if ( aSz.Width != aSize.Width() || aSz.Height != aSize.Height() )
2097  {
2098  aSz.Width = aSize.Width();
2099  aSz.Height = aSize.Height();
2100  xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
2101  }
2102  }
2103  else
2104  {
2105  // the descriptor contains the wrong object size
2106  // the following call will let the MSOLE objects cache the size if it is possible
2107  // it should be done while the object is running
2108  try
2109  {
2110  xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
2111  }
2112  catch (const uno::Exception&)
2113  {
2114  }
2115  }
2116  //End of Hack!
2117 
2118  rSh.InsertOleObject( xObjRef );
2119  bRet = true;
2120 
2121  if( bRet && ( nActionFlags & SotExchangeActionFlags::InsertTargetUrl) )
2122  SwTransferable::PasteTargetURL( rData, rSh, SwPasteSdr::NONE, nullptr, false );
2123 
2124  // let the object be unloaded if possible
2125  SwOLEObj::UnloadObject( xObj, rSh.GetDoc(), embed::Aspects::MSOLE_CONTENT );
2126  }
2127  }
2128  return bRet;
2129 }
2130 
2132  SwWrtShell& rSh, SwPasteSdr nAction,
2133  const Point* pPt, bool bInsertGRF )
2134 {
2135  bool bRet = false;
2136  INetImage aINetImg;
2137  if( ( rData.HasFormat( SotClipboardFormatId::INET_IMAGE ) &&
2138  rData.GetINetImage( SotClipboardFormatId::INET_IMAGE, aINetImg )) ||
2139  ( rData.HasFormat( SotClipboardFormatId::NETSCAPE_IMAGE ) &&
2140  rData.GetINetImage( SotClipboardFormatId::NETSCAPE_IMAGE, aINetImg )) )
2141  {
2142  if( !aINetImg.GetImageURL().isEmpty() && bInsertGRF )
2143  {
2144  OUString sURL( aINetImg.GetImageURL() );
2145  SwTransferable::CheckForURLOrLNKFile( rData, sURL );
2146 
2148  Graphic aGraphic;
2150  bRet = ERRCODE_NONE == GraphicFilter::LoadGraphic(sURL, OUString(), aGraphic, &rFlt);
2151 
2152  if( bRet )
2153  {
2154  //Check and Perform rotation if needed
2155  lclCheckAndPerformRotation(aGraphic);
2156 
2157  switch( nAction )
2158  {
2159  case SwPasteSdr::Insert:
2160  SwTransferable::SetSelInShell( rSh, false, pPt );
2161  rSh.Insert(sURL, OUString(), aGraphic);
2162  break;
2163 
2164  case SwPasteSdr::Replace:
2165  if( rSh.IsObjSelected() )
2166  {
2167  rSh.ReplaceSdrObj( sURL, &aGraphic );
2168  Point aPt( pPt ? *pPt : rSh.GetCursorDocPos() );
2169  SwTransferable::SetSelInShell( rSh, true, &aPt );
2170  }
2171  else
2172  rSh.ReRead(sURL, OUString(), &aGraphic);
2173  break;
2174 
2175  case SwPasteSdr::SetAttr:
2176  if( rSh.IsObjSelected() )
2177  rSh.Paste( aGraphic, OUString() );
2178  else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() )
2179  rSh.ReRead(sURL, OUString(), &aGraphic);
2180  else
2181  {
2182  SwTransferable::SetSelInShell( rSh, false, pPt );
2183  rSh.Insert(sURL, OUString(), aGraphic);
2184  }
2185  break;
2186  default:
2187  bRet = false;
2188  }
2189  }
2190  }
2191  else
2192  bRet = true;
2193  }
2194 
2195  if( bRet )
2196  {
2198  rSh.GetFlyFrameAttr( aSet );
2199  SwFormatURL aURL( aSet.Get( RES_URL ) );
2200 
2201  if( aURL.GetURL() != aINetImg.GetTargetURL() ||
2202  aURL.GetTargetFrameName() != aINetImg.GetTargetFrame() )
2203  {
2204  aURL.SetURL( aINetImg.GetTargetURL(), false );
2205  aURL.SetTargetFrameName( aINetImg.GetTargetFrame() );
2206  aSet.Put( aURL );
2207  rSh.SetFlyFrameAttr( aSet );
2208  }
2209  }
2210  return bRet;
2211 }
2212 
2213 void SwTransferable::SetSelInShell( SwWrtShell& rSh, bool bSelectFrame,
2214  const Point* pPt )
2215 {
2216  if( bSelectFrame )
2217  {
2218  // select frames/objects
2219  if( pPt && !rSh.GetView().GetViewFrame()->GetDispatcher()->IsLocked() )
2220  {
2221  rSh.GetView().NoRotate();
2222  if( rSh.SelectObj( *pPt ))
2223  {
2224  rSh.HideCursor();
2225  rSh.EnterSelFrameMode( pPt );
2226  g_bFrameDrag = true;
2227  }
2228  }
2229  }
2230  else
2231  {
2232  if( rSh.IsFrameSelected() || rSh.IsObjSelected() )
2233  {
2234  rSh.UnSelectFrame();
2235  rSh.LeaveSelFrameMode();
2236  rSh.GetView().GetEditWin().StopInsFrame();
2237  g_bFrameDrag = false;
2238  }
2239  else if( rSh.GetView().GetDrawFuncPtr() )
2240  rSh.GetView().GetEditWin().StopInsFrame();
2241 
2242  rSh.EnterStdMode();
2243  if( pPt )
2244  rSh.SwCursorShell::SetCursor( *pPt, true );
2245  }
2246 }
2247 
2249  SwWrtShell& rWrtShell, bool bReReadGrf,
2250  bool bMsg )
2251 {
2252  // data from Clipboardformat
2253  OUString aApp, aTopic, aItem;
2254 
2255  {
2257  if( !rData.GetSotStorageStream( SotClipboardFormatId::LINK, xStrm ))
2258  {
2259  OSL_ENSURE( false, "DDE Data not found." );
2260  return false;
2261  } // report useful error!!
2262 
2263  rtl_TextEncoding eEncoding = DDE_TXT_ENCODING;
2264  aApp = read_zeroTerminated_uInt8s_ToOUString(*xStrm, eEncoding);
2265  aTopic = read_zeroTerminated_uInt8s_ToOUString(*xStrm, eEncoding);
2266  aItem = read_zeroTerminated_uInt8s_ToOUString(*xStrm, eEncoding);
2267  }
2268 
2269  OUString aCmd;
2270  sfx2::MakeLnkName( aCmd, &aApp, aTopic, aItem );
2271 
2272  // do we want to read in a graphic now?
2273  SotClipboardFormatId nFormat;
2274  if( !rData.HasFormat( SotClipboardFormatId::RTF ) &&
2275  !rData.HasFormat( SotClipboardFormatId::RICHTEXT ) &&
2276  !rData.HasFormat( SotClipboardFormatId::HTML ) &&
2277  !rData.HasFormat( SotClipboardFormatId::STRING ) &&
2278  (rData.HasFormat( nFormat = SotClipboardFormatId::GDIMETAFILE ) ||
2279  rData.HasFormat( nFormat = SotClipboardFormatId::BITMAP )) )
2280  {
2281  Graphic aGrf;
2282  bool bRet = rData.GetGraphic( nFormat, aGrf );
2283  if( bRet )
2284  {
2285  OUString sLnkTyp("DDE");
2286  if ( bReReadGrf )
2287  rWrtShell.ReRead( aCmd, sLnkTyp, &aGrf );
2288  else
2289  rWrtShell.Insert( aCmd, sLnkTyp, aGrf );
2290  }
2291  return bRet;
2292  }
2293 
2294  SwFieldType* pTyp = nullptr;
2295  size_t i = 1;
2296  size_t j;
2297  OUString aName;
2298  bool bDoublePaste = false;
2299  const size_t nSize = rWrtShell.GetFieldTypeCount();
2300  const ::utl::TransliterationWrapper& rColl = ::GetAppCmpStrIgnore();
2301 
2302  do {
2303  aName = aApp + OUString::number( i );
2304  for( j = INIT_FLDTYPES; j < nSize; j++ )
2305  {
2306  pTyp = rWrtShell.GetFieldType( j );
2307  if( SwFieldIds::Dde == pTyp->Which() )
2308  {
2309  if( rColl.isEqual( static_cast<SwDDEFieldType*>(pTyp)->GetCmd(), aCmd ) &&
2310  SfxLinkUpdateMode::ALWAYS == static_cast<SwDDEFieldType*>(pTyp)->GetType() )
2311  {
2312  aName = pTyp->GetName();
2313  bDoublePaste = true;
2314  break;
2315  }
2316  else if( rColl.isEqual( aName, pTyp->GetName() ) )
2317  break;
2318  }
2319  }
2320  if( j == nSize )
2321  break;
2322  ++i;
2323  }
2324  while( !bDoublePaste );
2325 
2326  if( !bDoublePaste )
2327  {
2328  SwDDEFieldType aType( aName, aCmd, SfxLinkUpdateMode::ALWAYS );
2329  pTyp = rWrtShell.InsertFieldType( aType );
2330  }
2331 
2332  SwDDEFieldType* pDDETyp = static_cast<SwDDEFieldType*>(pTyp);
2333 
2334  OUString aExpand;
2335  if( rData.GetString( SotClipboardFormatId::STRING, aExpand ))
2336  {
2337  do { // middle checked loop
2338 
2339  const sal_Int32 nNewlines{comphelper::string::getTokenCount(aExpand, '\n')};
2340  // When data comes from a spreadsheet, we add a DDE-table
2341  if( !aExpand.isEmpty() &&
2342  ( rData.HasFormat( SotClipboardFormatId::SYLK ) ||
2343  rData.HasFormat( SotClipboardFormatId::SYLK_BIGCAPS ) ) )
2344  {
2345  const sal_Int32 nRows = nNewlines ? nNewlines-1 : 0;
2346  const sal_Int32 nCols = comphelper::string::getTokenCount(aExpand.getToken(0, '\n'), '\t');
2347 
2348  // don't try to insert tables that are too large for writer
2349  if (nRows > SAL_MAX_UINT16 || nCols > SAL_MAX_UINT16)
2350  {
2351  if( bMsg )
2352  {
2353  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
2354  VclMessageType::Info, VclButtonsType::Ok,
2355  SwResId(STR_TABLE_TOO_LARGE)));
2356  xBox->run();
2357  }
2358  pDDETyp = nullptr;
2359  break;
2360  }
2361 
2362  // at least one column & row must be there
2363  if( !nRows || !nCols )
2364  {
2365  if( bMsg )
2366  {
2367  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
2368  VclMessageType::Info, VclButtonsType::Ok,
2369  SwResId(STR_NO_TABLE)));
2370  xBox->run();
2371  }
2372  pDDETyp = nullptr;
2373  break;
2374  }
2375 
2376  rWrtShell.InsertDDETable(
2377  SwInsertTableOptions( SwInsertTableFlags::SplitLayout, 1 ), // TODO MULTIHEADER
2378  pDDETyp, nRows, nCols );
2379  }
2380  else if( nNewlines > 1 )
2381  {
2382  // multiple paragraphs -> insert a protected section
2383  if( rWrtShell.HasSelection() )
2384  rWrtShell.DelRight();
2385 
2386  SwSectionData aSect( DDE_LINK_SECTION, aName );
2387  aSect.SetLinkFileName( aCmd );
2388  aSect.SetProtectFlag(true);
2389  rWrtShell.InsertSection( aSect );
2390 
2391  pDDETyp = nullptr; // remove FieldTypes again
2392  }
2393  else
2394  {
2395  // insert
2396  SwDDEField aSwDDEField( pDDETyp );
2397  rWrtShell.Insert( aSwDDEField );
2398  }
2399 
2400  } while( false );
2401  }
2402  else
2403  pDDETyp = nullptr; // remove FieldTypes again
2404 
2405  if( !pDDETyp && !bDoublePaste )
2406  {
2407  // remove FieldType again - error occurred!
2408  for( j = nSize; j >= INIT_FLDTYPES; --j )
2409  if( pTyp == rWrtShell.GetFieldType( j ) )
2410  {
2411  rWrtShell.RemoveFieldType( j );
2412  break;
2413  }
2414  }
2415 
2416  return true;
2417 }
2418 
2420  SwWrtShell& rSh, SwPasteSdr nAction,
2421  const Point* pPt, SotExchangeActionFlags nActionFlags, bool bNeedToSelectBeforePaste)
2422 {
2423  bool bRet = false;
2425  if( rData.GetSotStorageStream( SotClipboardFormatId::DRAWING, xStrm ))
2426  {
2427  xStrm->SetVersion( SOFFICE_FILEFORMAT_50 );
2428 
2429  if(bNeedToSelectBeforePaste && pPt)
2430  {
2431  // if this is an internal drag, need to set the target right (select it), else
2432  // still the source will be selected
2433  SwTransferable::SetSelInShell( rSh, true, pPt );
2434  }
2435 
2436  rSh.Paste( *xStrm, nAction, pPt );
2437  bRet = true;
2438 
2439  if( bRet && ( nActionFlags & SotExchangeActionFlags::InsertTargetUrl ))
2440  SwTransferable::PasteTargetURL( rData, rSh, SwPasteSdr::NONE, nullptr, false );
2441  }
2442  return bRet;
2443 }
2444 
2446  SotClipboardFormatId nFormat, SwPasteSdr nAction, const Point* pPt,
2447  SotExchangeActionFlags nActionFlags, sal_Int8 nDropAction, bool bNeedToSelectBeforePaste, RndStdIds nAnchorType )
2448 {
2449  bool bRet = false;
2450 
2451  Graphic aGraphic;
2452  INetBookmark aBkmk;
2453  bool bCheckForGrf = false, bCheckForImageMap = false;
2454 
2455  switch( nFormat )
2456  {
2457  case SotClipboardFormatId::BITMAP:
2458  case SotClipboardFormatId::PNG:
2459  case SotClipboardFormatId::GDIMETAFILE:
2460  bRet = rData.GetGraphic( nFormat, aGraphic );
2461  break;
2462 
2463  case SotClipboardFormatId::SVXB:
2464  {
2466 
2467  if(rData.GetSotStorageStream(SotClipboardFormatId::SVXB, xStm))
2468  {
2469  ReadGraphic( *xStm, aGraphic );
2470  bRet = (GraphicType::NONE != aGraphic.GetType() && GraphicType::Default != aGraphic.GetType());
2471  }
2472 
2473  break;
2474  }
2475 
2476  case SotClipboardFormatId::NETSCAPE_BOOKMARK:
2477  case SotClipboardFormatId::FILEGRPDESCRIPTOR:
2478  case SotClipboardFormatId::UNIFORMRESOURCELOCATOR:
2479  bRet = rData.GetINetBookmark( nFormat, aBkmk );
2480  if( bRet )
2481  {
2482  if( SwPasteSdr::SetAttr == nAction )
2483  nFormat = SotClipboardFormatId::NETSCAPE_BOOKMARK;
2484  else
2485  bCheckForGrf = true;
2486  }
2487  break;
2488 
2489  case SotClipboardFormatId::SIMPLE_FILE:
2490  {
2491  OUString sText;
2492  bRet = rData.GetString( nFormat, sText );
2493  if( bRet )
2494  {
2495  OUString sDesc;
2496  SwTransferable::CheckForURLOrLNKFile( rData, sText, &sDesc );
2497 
2499  false);
2500 
2501 #ifdef _WIN32
2502  // Now that the path could be modified after SwTransferable::CheckForURLOrLNKFile,
2503  // where it could have been converted to URL, and made sure it's actually converted
2504  // to URL in URIHelper::SmartRel2Abs, we can finally convert file: URL back to
2505  // system path to make sure we don't use short path.
2506  // It looks not optimal, when we could apply GetLongPathNameW right to the original
2507  // pasted filename. But I don't know if (1) all arriving strings are system paths;
2508  // and (2) if SwTransferable::CheckForURLOrLNKFile could result in a different short
2509  // path, so taking a safe route.
2510  if (sText.startsWithIgnoreAsciiCase("file:"))
2511  {
2512  // tdf#124500: Convert short path to long path which should be used in links
2513  OUString sSysPath;
2514  osl::FileBase::getSystemPathFromFileURL(sText, sSysPath);
2515  std::unique_ptr<sal_Unicode[]> aBuf(new sal_Unicode[32767]);
2516  DWORD nCopied = GetLongPathNameW(o3tl::toW(sSysPath.getStr()),
2517  o3tl::toW(aBuf.get()), 32767);
2518  if (nCopied && nCopied < 32767)
2519  sText = URIHelper::SmartRel2Abs(INetURLObject(), aBuf.get(),
2520  Link<OUString*, bool>(), false);
2521  }
2522 #endif
2523 
2524  aBkmk = INetBookmark(sText, sDesc);
2525  bCheckForGrf = true;
2526  bCheckForImageMap = SwPasteSdr::Replace == nAction;
2527  }
2528  }
2529  break;
2530 
2531  default:
2532  bRet = rData.GetGraphic( nFormat, aGraphic );
2533  break;
2534  }
2535 
2536  if( bCheckForGrf )
2537  {
2540  bRet = ERRCODE_NONE == GraphicFilter::LoadGraphic(aBkmk.GetURL(), OUString(),
2541  aGraphic, &rFlt );
2542 
2543  if( !bRet && SwPasteSdr::SetAttr == nAction &&
2544  SotClipboardFormatId::SIMPLE_FILE == nFormat &&
2545  // only at frame selection
2546  rSh.IsFrameSelected() )
2547  {
2548  // then set as hyperlink after the graphic
2549  nFormat = SotClipboardFormatId::NETSCAPE_BOOKMARK;
2550  bRet = true;
2551  }
2552  }
2553 
2554  if(pPt && bNeedToSelectBeforePaste)
2555  {
2556  // when using internal D&Ds, still the source object is selected and
2557  // this is necessary to get the correct source data which is also
2558  // dependent from selection. After receiving the drag data it is
2559  // now time to select the correct target object
2560  SwTransferable::SetSelInShell( rSh, true, pPt );
2561  }
2562 
2563  if( bRet )
2564  {
2565  //Check and Perform rotation if needed
2566  lclCheckAndPerformRotation(aGraphic);
2567 
2568  OUString sURL;
2569  if( dynamic_cast< const SwWebDocShell *>( rSh.GetView().GetDocShell() ) != nullptr
2570  // #i123922# if link action is noted, also take URL
2571  || DND_ACTION_LINK == nDropAction)
2572  {
2573  sURL = aBkmk.GetURL();
2574  }
2575 
2576  switch( nAction )
2577  {
2578  case SwPasteSdr::Insert:
2579  {
2580  SwTransferable::SetSelInShell( rSh, false, pPt );
2581  rSh.Insert(sURL, OUString(), aGraphic, nullptr, nAnchorType);
2582  break;
2583  }
2584 
2585  case SwPasteSdr::Replace:
2586  {
2587  if( rSh.IsObjSelected() )
2588  {
2589  // #i123922# for D&D on draw objects, do for now the same for
2590  // SwPasteSdr::Replace (D&D) as for SwPasteSdr::SetAttr (D&D and
2591  // CTRL+SHIFT). The code below replaces the draw object with
2592  // a writer graphic; maybe this is an option later again if wanted
2593  rSh.Paste( aGraphic, sURL );
2594 
2595  // rSh.ReplaceSdrObj(sURL, OUString(), &aGraphic);
2596  // Point aPt( pPt ? *pPt : rSh.GetCursorDocPos() );
2597  // SwTransferable::SetSelInShell( rSh, true, &aPt );
2598  }
2599  else
2600  {
2601  // set graphic at writer graphic without link
2602  rSh.ReRead(sURL, OUString(), &aGraphic);
2603  }
2604 
2605  break;
2606  }
2607 
2608  case SwPasteSdr::SetAttr:
2609  {
2610  if( SotClipboardFormatId::NETSCAPE_BOOKMARK == nFormat )
2611  {
2612  if( rSh.IsFrameSelected() )
2613  {
2615  rSh.GetFlyFrameAttr( aSet );
2616  SwFormatURL aURL( aSet.Get( RES_URL ) );
2617  aURL.SetURL( aBkmk.GetURL(), false );
2618  aSet.Put( aURL );
2619  rSh.SetFlyFrameAttr( aSet );
2620  }
2621  }
2622  else if( rSh.IsObjSelected() )
2623  {
2624  // set as attribute at DrawObject
2625  rSh.Paste( aGraphic, sURL );
2626  }
2627  else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() )
2628  {
2629  // set as linked graphic at writer graphic frame
2630  rSh.ReRead(sURL, OUString(), &aGraphic);
2631  }
2632  else
2633  {
2634  SwTransferable::SetSelInShell( rSh, false, pPt );
2635  rSh.Insert(aBkmk.GetURL(), OUString(), aGraphic);
2636  }
2637  break;
2638  }
2639  default:
2640  {
2641  bRet = false;
2642  break;
2643  }
2644  }
2645  }
2646 
2647  if( bRet )
2648  {
2649 
2650  if( nActionFlags &
2651  ( SotExchangeActionFlags::InsertImageMap | SotExchangeActionFlags::ReplaceImageMap ) )
2652  SwTransferable::PasteImageMap( rData, rSh );
2653 
2654  if( nActionFlags & SotExchangeActionFlags::InsertTargetUrl )
2655  SwTransferable::PasteTargetURL( rData, rSh, SwPasteSdr::NONE, nullptr, false );
2656  }
2657  else if( bCheckForImageMap )
2658  {
2659  // or should the file be an ImageMap-File?
2660  ImageMap aMap;
2661  SfxMedium aMed( INetURLObject(aBkmk.GetURL()).GetFull(),
2662  StreamMode::STD_READ );
2663  SvStream* pStream = aMed.GetInStream();
2664  if( pStream != nullptr &&
2665  !pStream->GetError() &&
2666  // mba: no BaseURL for clipboard functionality
2667  aMap.Read( *pStream, IMAP_FORMAT_DETECT ) == IMAP_ERR_OK &&
2668  aMap.GetIMapObjectCount() )
2669  {
2671  rSh.GetFlyFrameAttr( aSet );
2672  SwFormatURL aURL( aSet.Get( RES_URL ) );
2673  aURL.SetMap( &aMap );
2674  aSet.Put( aURL );
2675  rSh.SetFlyFrameAttr( aSet );
2676  bRet = true;
2677  }
2678  }
2679 
2680  return bRet;
2681 }
2682 
2684  SwWrtShell& rSh )
2685 {
2686  bool bRet = false;
2687  if( rData.HasFormat( SotClipboardFormatId::SVIM ))
2688  {
2690  rSh.GetFlyFrameAttr( aSet );
2691  SwFormatURL aURL( aSet.Get( RES_URL ) );
2692  const ImageMap* pOld = aURL.GetMap();
2693 
2694  // set or replace, that is the question
2695  ImageMap aImageMap;
2696  if( rData.GetImageMap( SotClipboardFormatId::SVIM, aImageMap ) &&
2697  ( !pOld || aImageMap != *pOld ))
2698  {
2699  aURL.SetMap( &aImageMap );
2700  aSet.Put( aURL );
2701  rSh.SetFlyFrameAttr( aSet );
2702  }
2703  bRet = true;
2704  }
2705  return bRet;
2706 }
2707 
2709  SwWrtShell& rSh, SotClipboardFormatId nFormat )
2710 {
2711  bool bRet = false;
2712  OUString sFile;
2713  if( rData.GetString( nFormat, sFile ) && !sFile.isEmpty() )
2714  {
2715  OUString sDesc;
2716  SwTransferable::CheckForURLOrLNKFile( rData, sFile, &sDesc );
2717 
2718  // first, make the URL absolute
2719  INetURLObject aURL;
2720  aURL.SetSmartProtocol( INetProtocol::File );
2721  aURL.SetSmartURL( sFile );
2723 
2724  switch( rSh.GetObjCntTypeOfSelection() )
2725  {
2726  case OBJCNT_FLY:
2727  case OBJCNT_GRF:
2728  case OBJCNT_OLE:
2729  {
2731  rSh.GetFlyFrameAttr( aSet );
2732  SwFormatURL aURL2( aSet.Get( RES_URL ) );
2733  aURL2.SetURL( sFile, false );
2734  if( aURL2.GetName().isEmpty() )
2735  aURL2.SetName( sFile );
2736  aSet.Put( aURL2 );
2737  rSh.SetFlyFrameAttr( aSet );
2738  }
2739  break;
2740 
2741  default:
2742  {
2743  rSh.InsertURL( SwFormatINetFormat( sFile, OUString() ),
2744  sDesc.isEmpty() ? sFile : sDesc);
2745  }
2746  }
2747  bRet = true;
2748  }
2749  return bRet;
2750 }
2751 
2753  SwWrtShell& rSh, SotClipboardFormatId nFormat,
2754  SwPasteSdr nAction, const Point* pPt,
2755  SotExchangeActionFlags nActionFlags,
2756  bool * graphicInserted)
2757 {
2758  bool bRet = SwTransferable::PasteGrf( rData, rSh, nFormat, nAction,
2759  pPt, nActionFlags, 0, false);
2760  if (graphicInserted != nullptr) {
2761  *graphicInserted = bRet;
2762  }
2763  if( !bRet )
2764  {
2765  OUString sFile, sDesc;
2766  if( rData.GetString( nFormat, sFile ) && !sFile.isEmpty() )
2767  {
2768 #if HAVE_FEATURE_AVMEDIA
2769  INetURLObject aMediaURL;
2770 
2771  aMediaURL.SetSmartURL( sFile );
2772  const OUString aMediaURLStr( aMediaURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
2773 
2774  if( ::avmedia::MediaWindow::isMediaURL( aMediaURLStr, ""/*TODO?*/ ) )
2775  {
2776  const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aMediaURLStr );
2778  SID_INSERT_AVMEDIA, SfxCallMode::SYNCHRON,
2779  { &aMediaURLItem });
2780  }
2781 #else
2782  if (false)
2783  {
2784  }
2785 #endif
2786  else
2787  {
2788  bool bIsURLFile = SwTransferable::CheckForURLOrLNKFile( rData, sFile, &sDesc );
2789 
2790  //Own FileFormat? --> insert, not for StarWriter/Web
2791  OUString sFileURL = URIHelper::SmartRel2Abs(INetURLObject(), sFile, Link<OUString *, bool>(), false );
2792  std::shared_ptr<const SfxFilter> pFlt = SwPasteSdr::SetAttr == nAction
2793  ? nullptr : SwIoSystem::GetFileFilter(sFileURL);
2794  if( pFlt && dynamic_cast< const SwWebDocShell *>( rSh.GetView().GetDocShell() ) == nullptr )
2795  {
2796  // and then pull up the insert-region-dialog
2797  SwSectionData aSect(
2799  rSh.GetDoc()->GetUniqueSectionName() );
2800  aSect.SetLinkFileName( sFileURL );
2801  aSect.SetProtectFlag( true );
2802 
2803  rSh.StartInsertRegionDialog( aSect ); // starts dialog asynchronously
2804  bRet = true;
2805  }
2806  else if( SwPasteSdr::SetAttr == nAction ||
2807  ( bIsURLFile && SwPasteSdr::Insert == nAction ))
2808  {
2809  //we can insert foreign files as links after all
2810 
2811  // first, make the URL absolute
2812  INetURLObject aURL;
2813  aURL.SetSmartProtocol( INetProtocol::File );
2814  aURL.SetSmartURL( sFile );
2816 
2817  switch( rSh.GetObjCntTypeOfSelection() )
2818  {
2819  case OBJCNT_FLY:
2820  case OBJCNT_GRF:
2821  case OBJCNT_OLE:
2822  {
2824  rSh.GetFlyFrameAttr( aSet );
2825  SwFormatURL aURL2( aSet.Get( RES_URL ) );
2826  aURL2.SetURL( sFile, false );
2827  if( aURL2.GetName().isEmpty() )
2828  aURL2.SetName( sFile );
2829  aSet.Put( aURL2 );
2830  rSh.SetFlyFrameAttr( aSet );
2831  }
2832  break;
2833 
2834  default:
2835  {
2836  rSh.InsertURL( SwFormatINetFormat( sFile, OUString() ),
2837  sDesc.isEmpty() ? sFile : sDesc );
2838  }
2839  }
2840  bRet = true;
2841  }
2842  }
2843  }
2844  }
2845  return bRet;
2846 }
2847 
2849  SwWrtShell& rSh, SotClipboardFormatId nFormat, bool bLink,
2850  const Point* pDragPt, bool bMsg )
2851 {
2852  bool bRet = false;
2853  OUString sText;
2854  if( rData.GetString( nFormat, sText ) && !sText.isEmpty() )
2855  {
2856  sal_uInt16 nWh = SotClipboardFormatId::SBA_CTRLDATAEXCHANGE == nFormat
2857  ? 0
2858  : SotClipboardFormatId::SBA_DATAEXCHANGE == nFormat
2859  ? (bLink
2861  : FN_QRY_INSERT)
2862  : (bLink
2863  ? 0
2864  : FN_QRY_INSERT_FIELD );
2865  const DataFlavorExVector& rVector = rData.GetDataFlavorExVector();
2866  bool bHaveColumnDescriptor = OColumnTransferable::canExtractColumnDescriptor(rVector, ColumnTransferFormatFlags::COLUMN_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE);
2867  if ( SotClipboardFormatId::XFORMS == nFormat )
2868  {
2869  rSh.MakeDrawView();
2870  FmFormView* pFmView = dynamic_cast<FmFormView*>( rSh.GetDrawView() );
2871  if (pFmView && pDragPt)
2872  {
2873  const OXFormsDescriptor &rDesc = OXFormsTransferable::extractDescriptor(rData);
2874  SdrObjectUniquePtr pObj = pFmView->CreateXFormsControl(rDesc);
2875  if(pObj)
2876  {
2877  rSh.SwFEShell::InsertDrawObj( *(pObj.release()), *pDragPt );
2878  }
2879  }
2880  }
2881  else if( nWh )
2882  {
2883  std::unique_ptr<SfxUnoAnyItem> pConnectionItem;
2884  std::unique_ptr<SfxUnoAnyItem> pCursorItem;
2885  std::unique_ptr<SfxUnoAnyItem> pColumnItem;
2886  std::unique_ptr<SfxUnoAnyItem> pSourceItem;
2887  std::unique_ptr<SfxUnoAnyItem> pCommandItem;
2888  std::unique_ptr<SfxUnoAnyItem> pCommandTypeItem;
2889  std::unique_ptr<SfxUnoAnyItem> pColumnNameItem;
2890  std::unique_ptr<SfxUnoAnyItem> pSelectionItem;
2891 
2892  bool bDataAvailable = true;
2893  ODataAccessDescriptor aDesc;
2894  if(bHaveColumnDescriptor)
2895  aDesc = OColumnTransferable::extractColumnDescriptor(rData);
2896  else if(ODataAccessObjectTransferable::canExtractObjectDescriptor(rVector) )
2897  aDesc = ODataAccessObjectTransferable::extractObjectDescriptor(rData);
2898  else
2899  bDataAvailable = false;
2900 
2901  if ( bDataAvailable )
2902  {
2903  pConnectionItem.reset(new SfxUnoAnyItem(FN_DB_CONNECTION_ANY, aDesc[DataAccessDescriptorProperty::Connection]));
2904  pColumnItem.reset(new SfxUnoAnyItem(FN_DB_COLUMN_ANY, aDesc[DataAccessDescriptorProperty::ColumnObject]));
2905  pSourceItem.reset(new SfxUnoAnyItem(FN_DB_DATA_SOURCE_ANY, makeAny(aDesc.getDataSource())));
2906  pCommandItem.reset(new SfxUnoAnyItem(FN_DB_DATA_COMMAND_ANY, aDesc[DataAccessDescriptorProperty::Command]));
2907  pCommandTypeItem.reset(new SfxUnoAnyItem(FN_DB_DATA_COMMAND_TYPE_ANY, aDesc[DataAccessDescriptorProperty::CommandType]));
2908  pColumnNameItem.reset(new SfxUnoAnyItem(FN_DB_DATA_COLUMN_NAME_ANY, aDesc[DataAccessDescriptorProperty::ColumnName]));
2909  pSelectionItem.reset(new SfxUnoAnyItem(FN_DB_DATA_SELECTION_ANY, aDesc[DataAccessDescriptorProperty::Selection]));
2910  pCursorItem.reset(new SfxUnoAnyItem(FN_DB_DATA_CURSOR_ANY, aDesc[DataAccessDescriptorProperty::Cursor]));
2911  }
2912 
2913  SwView& rView = rSh.GetView();
2914  //force ::SelectShell
2915  rView.StopShellTimer();
2916 
2917  SfxStringItem aDataDesc( nWh, sText );
2919  nWh, SfxCallMode::ASYNCHRON,
2920  { &aDataDesc, pConnectionItem.get(), pColumnItem.get(),
2921  pSourceItem.get(), pCommandItem.get(), pCommandTypeItem.get(),
2922  pColumnNameItem.get(), pSelectionItem.get(),
2923  pCursorItem.get() });
2924  }
2925  else
2926  {
2927  rSh.MakeDrawView();
2928  FmFormView* pFmView = dynamic_cast<FmFormView*>( rSh.GetDrawView() );
2929  if (pFmView && bHaveColumnDescriptor && pDragPt)
2930  {
2931  SdrObjectUniquePtr pObj = pFmView->CreateFieldControl( OColumnTransferable::extractColumnDescriptor(rData) );
2932  if (pObj)
2933  rSh.SwFEShell::InsertDrawObj( *(pObj.release()), *pDragPt );
2934  }
2935  }
2936  bRet = true;
2937  }
2938  else if( bMsg )
2939  {
2940  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
2941  VclMessageType::Info, VclButtonsType::Ok,
2942  SwResId(STR_CLPBRD_FORMAT_ERROR)));
2943  xBox->run();
2944  }
2945  return bRet;
2946 }
2947 
2949  SwWrtShell& rSh, bool bLink,
2950  const Point* pPt, bool bMsg )
2951 {
2952  bool bRet = false;
2953  FileList aFileList;
2954  if( rData.GetFileList( SotClipboardFormatId::FILE_LIST, aFileList ) &&
2955  aFileList.Count() )
2956  {
2958  OUString sFlyNm;
2959  // iterate over the filelist
2960  for( sal_uLong n = 0, nEnd = aFileList.Count(); n < nEnd; ++n )
2961  {
2963  pHlp->CopyString( SotClipboardFormatId::SIMPLE_FILE, aFileList.GetFile( n ));
2964  TransferableDataHelper aData( pHlp );
2965 
2966  if( SwTransferable::PasteFileName( aData, rSh, SotClipboardFormatId::SIMPLE_FILE, nAct,
2967  pPt, SotExchangeActionFlags::NONE, nullptr ))
2968  {
2969  if( bLink )
2970  {
2971  sFlyNm = rSh.GetFlyName();
2972  SwTransferable::SetSelInShell( rSh, false, pPt );
2973  }
2974  bRet = true;
2975  }
2976  }
2977  if( !sFlyNm.isEmpty() )
2978  rSh.GotoFly( sFlyNm );
2979  }
2980  else if( bMsg )
2981  {
2982  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
2983  VclMessageType::Info, VclButtonsType::Ok,
2984  SwResId(STR_CLPBRD_FORMAT_ERROR)));
2985  xBox->run();
2986  }
2987  return bRet;
2988 }
2989 
2991  OUString& rFileName, OUString* pTitle )
2992 {
2993  bool bIsURLFile = false;
2994  INetBookmark aBkmk;
2995  if( rData.GetINetBookmark( SotClipboardFormatId::SOLK, aBkmk ) )
2996  {
2997  rFileName = aBkmk.GetURL();
2998  if( pTitle )
2999  *pTitle = aBkmk.GetDescription();
3000  bIsURLFile = true;
3001  }
3002  else
3003  {
3004  if( rFileName.getLength()>4 && rFileName.endsWithIgnoreAsciiCase(".url") )
3005  {
3006  OSL_ENSURE( false, "how do we read today .URL - Files?" );
3007  }
3008  }
3009  return bIsURLFile;
3010 }
3011 
3013  const TransferableDataHelper& rData )
3014 {
3015  // we can paste-special if there's an entry in the paste-special-format list
3016  SvxClipboardFormatItem aClipboardFormatItem(0);
3017  FillClipFormatItem( rWrtShell, rData, aClipboardFormatItem);
3018  return aClipboardFormatItem.Count() > 0;
3019 }
3020 
3022  TransferableDataHelper& rData,
3023  SotClipboardFormatId nFormat )
3024 {
3025  SwWait aWait( *rSh.GetView().GetDocShell(), false );
3026  bool bRet = false;
3027 
3028  SotClipboardFormatId nPrivateFormat = SotClipboardFormatId::PRIVATE;
3029  SwTransferable *pClipboard = GetSwTransferable( rData );
3030  if( pClipboard &&
3032  nPrivateFormat = SotClipboardFormatId::EMBED_SOURCE;
3033 
3034  if( pClipboard && nPrivateFormat == nFormat )
3035  bRet = pClipboard->PrivatePaste( rSh );
3036  else if( rData.HasFormat( nFormat ) )
3037  {
3038  uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
3039  sal_uInt8 nEventAction;
3040  SotExchangeDest nDestination = SwTransferable::GetSotDestination( rSh );
3041  sal_uInt16 nSourceOptions =
3042  (( SotExchangeDest::DOC_TEXTFRAME == nDestination ||
3043  SotExchangeDest::SWDOC_FREE_AREA == nDestination ||
3044  SotExchangeDest::DOC_TEXTFRAME_WEB == nDestination ||
3045  SotExchangeDest::SWDOC_FREE_AREA_WEB == nDestination )
3048  SotExchangeActionFlags nActionFlags;
3050  rData.GetDataFlavorExVector(),
3051  nDestination,
3052  nSourceOptions, /* ?? */
3053  EXCHG_IN_ACTION_DEFAULT, /* ?? */
3054  nFormat, nEventAction, nFormat,
3055  lcl_getTransferPointer ( xTransferable ),
3056  &nActionFlags );
3057 
3058  if( EXCHG_INOUT_ACTION_NONE != nAction )
3059  bRet = SwTransferable::PasteData( rData, rSh, nAction, nActionFlags, nFormat,
3060  nDestination, true, false );
3061  }
3062  return bRet;
3063 }
3064 
3066  SotClipboardFormatId nFormat, SotExchangeDest nDestination )
3067 {
3068  sal_uInt8 nAction = EXCHG_INOUT_ACTION_NONE, nEventAction;
3069  if( rData.HasFormat( nFormat )) {
3070  uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
3072  rData.GetDataFlavorExVector(),
3073  nDestination, EXCHG_IN_ACTION_COPY,
3074  EXCHG_IN_ACTION_COPY, nFormat,
3075  nEventAction, nFormat,
3076  lcl_getTransferPointer ( xTransferable ) );
3077  }
3078  return EXCHG_INOUT_ACTION_NONE != nAction;
3079 }
3080 
3086 {
3087  SotClipboardFormatId::HTML,
3088  SotClipboardFormatId::HTML_SIMPLE,
3089  SotClipboardFormatId::HTML_NO_COMMENT,
3090  SotClipboardFormatId::RTF,
3091  SotClipboardFormatId::RICHTEXT,
3092  SotClipboardFormatId::STRING,
3093  SotClipboardFormatId::SONLK,
3094  SotClipboardFormatId::NETSCAPE_BOOKMARK,
3095  SotClipboardFormatId::DRAWING,
3096  SotClipboardFormatId::SVXB,
3097  SotClipboardFormatId::GDIMETAFILE,
3098  SotClipboardFormatId::BITMAP,
3099  SotClipboardFormatId::SVIM,
3100  SotClipboardFormatId::FILEGRPDESCRIPTOR,
3101  SotClipboardFormatId::NONE
3102 };
3103 
3105 {
3106  // Plain text == unformatted
3107  return SwTransferable::PasteFormat( rSh, rData, SotClipboardFormatId::STRING );
3108 }
3109 
3111 {
3112  bool bRet = false;
3114  ScopedVclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog(rSh.GetView().GetEditWin().GetFrameWeld()));
3115 
3116  DataFlavorExVector aFormats( rData.GetDataFlavorExVector() );
3118 
3120 
3121  SwTransferable *pClipboard = GetSwTransferable( rData );
3122  if( pClipboard )
3123  {
3124  aDesc = pClipboard->m_aObjDesc;
3125  const char* pResId;
3126  if( pClipboard->m_eBufferType & TransferBufferType::Document )
3127  pResId = STR_PRIVATETEXT;
3128  else if( pClipboard->m_eBufferType & TransferBufferType::Graphic )
3129  pResId = STR_PRIVATEGRAPHIC;
3130  else if( pClipboard->m_eBufferType == TransferBufferType::Ole )
3131  pResId = STR_PRIVATEOLE;
3132  else
3133  pResId = nullptr;
3134 
3135  if (pResId)
3136  {
3137  if (strcmp(STR_PRIVATEOLE, pResId) == 0 || strcmp(STR_PRIVATEGRAPHIC, pResId) == 0)
3138  {
3139  // add SotClipboardFormatId::EMBED_SOURCE to the formats. This
3140  // format display then the private format name.
3141  DataFlavorEx aFlavorEx;
3142  aFlavorEx.mnSotId = SotClipboardFormatId::EMBED_SOURCE;
3143  aFormats.insert( aFormats.begin(), aFlavorEx );
3144  }
3145  pDlg->SetObjName( pClipboard->m_aObjDesc.maClassName,
3146  SwResId(pResId) );
3147  pDlg->Insert(SotClipboardFormatId::EMBED_SOURCE, OUString());
3148  }
3149  }
3150  else
3151  {
3152  if( rData.HasFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ) )
3153  {
3155  SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc );
3156  }
3157 
3158  if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::EMBED_SOURCE, nDest ))
3159  pDlg->Insert(SotClipboardFormatId::EMBED_SOURCE, OUString());
3160  if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::LINK_SOURCE, nDest ))
3161  pDlg->Insert(SotClipboardFormatId::LINK_SOURCE, OUString());
3162  }
3163 
3164  if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::LINK, nDest ))
3165  pDlg->Insert( SotClipboardFormatId::LINK, SwResId(STR_DDEFORMAT) );
3166 
3167  for( SotClipboardFormatId* pIds = aPasteSpecialIds; *pIds != SotClipboardFormatId::NONE; ++pIds )
3168  if( SwTransferable::TestAllowedFormat( rData, *pIds, nDest ))
3169  pDlg->Insert(*pIds, OUString());
3170 
3171  SotClipboardFormatId nFormat = pDlg->GetFormat( rData.GetTransferable() );
3172 
3173  if( nFormat != SotClipboardFormatId::NONE )
3174  bRet = SwTransferable::PasteFormat( rSh, rData, nFormat );
3175 
3176  if ( bRet )
3177  rFormatUsed = nFormat;
3178 
3179  return bRet;
3180 }
3181 
3183  const TransferableDataHelper& rData,
3184  SvxClipboardFormatItem & rToFill )
3185 {
3187 
3188  SwTransferable *pClipboard = GetSwTransferable( rData );
3189  if( pClipboard )
3190  {
3191  const char* pResId;
3192  if( pClipboard->m_eBufferType & TransferBufferType::Document )
3193  pResId = STR_PRIVATETEXT;
3194  else if( pClipboard->m_eBufferType & TransferBufferType::Graphic )
3195  pResId = STR_PRIVATEGRAPHIC;
3196  else if( pClipboard->m_eBufferType == TransferBufferType::Ole )
3197  pResId = STR_PRIVATEOLE;
3198  else
3199  pResId = nullptr;
3200 
3201  if (pResId)
3202  rToFill.AddClipbrdFormat(SotClipboardFormatId::EMBED_SOURCE,
3203  SwResId(pResId));
3204  }
3205  else
3206  {
3208  if (rData.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR))
3209  {
3210  (void)const_cast<TransferableDataHelper&>(rData).GetTransferableObjectDescriptor(
3211  SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc);
3212  }
3213 
3214  if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::EMBED_SOURCE, nDest ))
3215  rToFill.AddClipbrdFormat( SotClipboardFormatId::EMBED_SOURCE,
3216  aDesc.maTypeName );
3217  if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::LINK_SOURCE, nDest ))
3218  rToFill.AddClipbrdFormat( SotClipboardFormatId::LINK_SOURCE );
3219 
3220  SotClipboardFormatId nFormat;
3221  if ( rData.HasFormat(nFormat = SotClipboardFormatId::EMBED_SOURCE_OLE) || rData.HasFormat(nFormat = SotClipboardFormatId::EMBEDDED_OBJ_OLE) )
3222  {
3223  OUString sName,sSource;
3224  if ( SvPasteObjectHelper::GetEmbeddedName(rData,sName,sSource,nFormat) )
3225  rToFill.AddClipbrdFormat( nFormat, sName );
3226  }
3227  }
3228 
3229  if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::LINK, nDest ))
3230  rToFill.AddClipbrdFormat( SotClipboardFormatId::LINK, SwResId(STR_DDEFORMAT) );
3231 
3232  for( SotClipboardFormatId* pIds = aPasteSpecialIds; *pIds != SotClipboardFormatId::NONE; ++pIds )
3233  if( SwTransferable::TestAllowedFormat( rData, *pIds, nDest ))
3234  rToFill.AddClipbrdFormat(*pIds, OUString());
3235 }
3236 
3238 {
3239  if(!m_pWrtShell)
3240  return;
3241  OUString sGrfNm;
3242  const SelectionType nSelection = m_pWrtShell->GetSelectionType();
3243  if( SelectionType::Graphic == nSelection)
3244  {
3245  AddFormat( SotClipboardFormatId::SVXB );
3246  const Graphic* pGrf = m_pWrtShell->GetGraphic();
3247  if ( pGrf && pGrf->IsSupportedGraphic() )
3248  {
3249  AddFormat( SotClipboardFormatId::GDIMETAFILE );
3250  AddFormat( SotClipboardFormatId::PNG );
3251  AddFormat( SotClipboardFormatId::BITMAP );
3252  }
3254  m_pWrtShell->GetGrfNms( &sGrfNm, nullptr );
3255  }
3256  else if( SelectionType::Ole == nSelection )
3257  {
3258  AddFormat( SotClipboardFormatId::EMBED_SOURCE );
3260  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
3261  AddFormat( SotClipboardFormatId::GDIMETAFILE );
3263  }
3264  //Is there anything to provide anyway?
3265  else if ( m_pWrtShell->IsSelection() || m_pWrtShell->IsFrameSelected() ||
3267  {
3268  if( m_pWrtShell->IsObjSelected() )
3270  else
3271  {
3273  if( SwWrtShell::NO_WORD !=
3274  m_pWrtShell->IntelligentCut( nSelection, false ))
3276  }
3277 
3278  if( nSelection & SelectionType::TableCell )
3280 
3281  AddFormat( SotClipboardFormatId::EMBED_SOURCE );
3282 
3283  //put RTF ahead of the OLE's Metafile for less loss
3284  if( !m_pWrtShell->IsObjSelected() )
3285  {
3286  AddFormat( SotClipboardFormatId::RTF );
3287  AddFormat( SotClipboardFormatId::RICHTEXT );
3288  AddFormat( SotClipboardFormatId::HTML );
3289  }
3290  if( m_pWrtShell->IsSelection() )
3291  AddFormat( SotClipboardFormatId::STRING );
3292 
3293  if( nSelection & ( SelectionType::DrawObject | SelectionType::DbForm ))
3294  {
3295  AddFormat( SotClipboardFormatId::DRAWING );
3296  if ( nSelection & SelectionType::DrawObject )
3297  {
3298  AddFormat( SotClipboardFormatId::GDIMETAFILE );
3299  AddFormat( SotClipboardFormatId::PNG );
3300  AddFormat( SotClipboardFormatId::BITMAP );
3301  }
3303 
3304  m_pClpGraphic.reset(new Graphic);
3305  if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *m_pClpGraphic ))
3306  m_pOrigGraphic = m_pClpGraphic.get();
3307  m_pClpBitmap.reset(new Graphic);
3308  if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *m_pClpBitmap ))
3309  m_pOrigGraphic = m_pClpBitmap.get();
3310 
3311  // is it a URL-Button ?
3312  OUString sURL;
3313  OUString sDesc;
3314  if( m_pWrtShell->GetURLFromButton( sURL, sDesc ) )
3315  {
3316  AddFormat( SotClipboardFormatId::STRING );
3317  AddFormat( SotClipboardFormatId::SOLK );
3318  AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
3319  AddFormat( SotClipboardFormatId::FILECONTENT );
3320  AddFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR );
3321  AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR );
3323  }
3324  }
3325 
3326  //ObjectDescriptor was already filled from the old DocShell.
3327  //Now adjust it. Thus in GetData the first query can still
3328  //be answered with delayed rendering.
3329  m_aObjDesc.maDragStartPos = rSttPos;
3331  MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM));
3333  AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
3334  }
3335  else if( nSelection & SelectionType::Text && !m_pWrtShell->HasMark() )
3336  {
3337  // is only one field - selected?
3338  SwContentAtPos aContentAtPos( IsAttrAtPos::InetAttr );
3340 
3341  if( m_pWrtShell->GetContentAtPos( aPos, aContentAtPos ) )
3342  {
3343  AddFormat( SotClipboardFormatId::STRING );
3344  AddFormat( SotClipboardFormatId::SOLK );
3345  AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
3346  AddFormat( SotClipboardFormatId::FILECONTENT );
3347  AddFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR );
3348  AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR );
3350  }
3351  }
3352 
3353  if( m_pWrtShell->IsFrameSelected() )
3354  {
3356  m_pWrtShell->GetFlyFrameAttr( aSet );
3357  const SwFormatURL& rURL = aSet.Get( RES_URL );
3358  if( rURL.GetMap() )
3359  {
3360  m_pImageMap.reset( new ImageMap( *rURL.GetMap() ) );
3361  AddFormat( SotClipboardFormatId::SVIM );
3362  }
3363  else if( !rURL.GetURL().isEmpty() )
3364  {
3365  m_pTargetURL.reset(new INetImage( sGrfNm, rURL.GetURL(),
3366  rURL.GetTargetFrameName() ));
3367  AddFormat( SotClipboardFormatId::INET_IMAGE );
3368  }
3369  }
3370 }
3371 
3372 void SwTransferable::StartDrag( vcl::Window* pWin, const Point& rPos )
3373 {
3374  if(!m_pWrtShell)
3375  return;
3377  m_bCleanUp = true;
3378 
3379  m_pWrtShell->GetViewOptions()->SetIdle( false );
3380 
3381  if( m_pWrtShell->IsSelFrameMode() )
3383 
3384  SW_MOD()->m_pDragDrop = this;
3385 
3386  SetDataForDragAndDrop( rPos );
3387 
3388  sal_Int8 nDragOptions = DND_ACTION_COPYMOVE | DND_ACTION_LINK;
3389  SwDocShell* pDShell = m_pWrtShell->GetView().GetDocShell();
3390  if( ( pDShell && pDShell->IsReadOnly() ) || m_pWrtShell->HasReadonlySel() )
3391  nDragOptions &= ~DND_ACTION_MOVE;
3392 
3393  TransferableHelper::StartDrag( pWin, nDragOptions );
3394 }
3395 
3397 {
3398  //And the last finishing work so that all statuses are right
3399  if( DND_ACTION_MOVE == nAction )
3400  {
3401  if( m_bCleanUp )
3402  {
3403  //It was dropped outside of Writer. We still have to
3404  //delete.
3405 
3408  if ( m_pWrtShell->IsTableMode() )
3410  else
3411  {
3413  //SmartCut, take one of the blanks along
3415  m_pWrtShell->DelRight();
3416  }
3419  }
3420  else
3421  {
3422  const SelectionType nSelection = m_pWrtShell->GetSelectionType();
3425  {
3427  }
3428  }
3429  }
3431 
3432  if( m_pWrtShell->IsSelFrameMode() )
3434  else
3436 
3438 }
3439 
3440 namespace
3441 {
3442 
3443 bool lcl_checkClassification(SwDoc* pSourceDoc, SwDoc* pDestinationDoc)
3444 {
3445  if (!pSourceDoc || !pDestinationDoc)
3446  return true;
3447 
3448  SwDocShell* pSourceShell = pSourceDoc->GetDocShell();
3449  SwDocShell* pDestinationShell = pDestinationDoc->GetDocShell();
3450  if (!pSourceShell || !pDestinationShell)
3451  return true;
3452 
3455 }
3456 
3457 }
3458 
3460 {
3461  // first, ask for the SelectionType, then action-bracketing !!!!
3462  // (otherwise it's not pasted into a TableSelection!!!)
3463  OSL_ENSURE( !rShell.ActionPend(), "Paste must never have an ActionPend" );
3464  if ( !m_pClpDocFac )
3465  return false; // the return value of the SwFEShell::Paste also is bool!
3466 
3467  const SelectionType nSelection = rShell.GetSelectionType();
3468 
3469  SwTrnsfrActionAndUndo aAction( &rShell );
3470 
3471  bool bKillPaMs = false;
3472 
3473  //Delete selected content, not at table-selection and table in Clipboard, and don't delete hovering graphics.
3474  if( rShell.HasSelection() && !( nSelection & SelectionType::TableCell) && !( nSelection & SelectionType::DrawObject))
3475  {
3476  bKillPaMs = true;
3477  rShell.SetRetainSelection( true );
3478  if (pContext)
3479  pContext->forget();
3480  rShell.DelRight();
3481  if (pContext)
3482  pContext->remember();
3483  // when a Fly was selected, a valid cursor position has to be found now
3484  // (parked Cursor!)
3486  SelectionType::Ole | SelectionType::DrawObject |
3487  SelectionType::DbForm ) & nSelection )
3488  {
3489  // position the cursor again
3490  Point aPt( rShell.GetCharRect().Pos() );
3491  rShell.SwCursorShell::SetCursor( aPt, true );
3492  }
3493  rShell.SetRetainSelection( false );
3494  }
3495  if ( nSelection & SelectionType::DrawObject) //unselect hovering graphics
3496  {
3497  rShell.ResetSelect(nullptr,false);
3498  }
3499 
3500  bool bInWrd = false, bEndWrd = false, bSttWrd = false,
3502  if( bSmart )
3503  {
3504  // Why not for other Scripts? If TransferBufferType::DocumentWord is set, we have a word
3505  // in the buffer, word in this context means 'something with spaces at beginning
3506  // and end'. In this case we definitely want these spaces to be inserted here.
3507  bInWrd = rShell.IsInWord();
3508  bEndWrd = rShell.IsEndWrd();
3509  bSmart = bInWrd || bEndWrd;
3510  if( bSmart )
3511  {
3512  bSttWrd = rShell.IsStartWord();
3513  if (!bSttWrd && (bInWrd || bEndWrd))
3514  rShell.SwEditShell::Insert(' ');
3515  }
3516  }
3517 
3518  bool bRet = true;
3519  // m_pWrtShell is nullptr when the source document is closed already.
3520  if (!m_pWrtShell || lcl_checkClassification(m_pWrtShell->GetDoc(), rShell.GetDoc()))
3521  bRet = rShell.Paste(m_pClpDocFac->GetDoc());
3522 
3523  if( bKillPaMs )
3524  rShell.KillPams();
3525 
3526  // If Smart Paste then insert blank
3527  if( bRet && bSmart && ((bInWrd && !bEndWrd )|| bSttWrd) )
3528  rShell.SwEditShell::Insert(' ');
3529 
3530  return bRet;
3531 }
3532 
3533 bool SwTransferable::PrivateDrop( SwWrtShell& rSh, const Point& rDragPt,
3534  bool bMove, bool bIsXSelection )
3535 {
3536  int cWord = 0;
3537  bool bInWrd = false;
3538  bool bEndWrd = false;
3539  bool bSttWrd = false;
3540  bool bSttPara = false;
3541  bool bTableSel = false;
3542  bool bFrameSel = false;
3543 
3544  SwWrtShell& rSrcSh = *GetShell();
3545 
3546  rSh.UnSetVisibleCursor();
3547 
3549  {
3550  if( rSh.GetFormatFromObj( rDragPt ) )
3551  {
3552  INetBookmark aTmp;
3554  aTmp = *m_pBookmark;
3555 
3556  // select target graphic
3557  if( rSh.SelectObj( rDragPt ) )
3558  {
3559  rSh.HideCursor();
3560  rSh.EnterSelFrameMode( &rDragPt );
3561  g_bFrameDrag = true;
3562  }
3563 
3564  const SelectionType nSelection = rSh.GetSelectionType();
3565 
3566  // not yet consider Draw objects
3567  if( SelectionType::Graphic & nSelection )
3568  {
3570  rSh.GetFlyFrameAttr( aSet );
3571  SwFormatURL aURL( aSet.Get( RES_URL ) );
3572  aURL.SetURL( aTmp.GetURL(), false );
3573  aSet.Put( aURL );
3574  rSh.SetFlyFrameAttr( aSet );
3575  return true;
3576  }
3577 
3578  if( SelectionType::DrawObject & nSelection )
3579  {
3580  rSh.LeaveSelFrameMode();
3581  rSh.UnSelectFrame();
3582  rSh.ShowCursor();
3583  g_bFrameDrag = false;
3584  }
3585  }
3586  }
3587 
3588  if( &rSh != &rSrcSh && (SelectionType::Graphic & rSh.GetSelectionType()) &&
3590  {
3591  // ReRead the graphic
3592  OUString sGrfNm;
3593  OUString sFltNm;
3594  rSrcSh.GetGrfNms( &sGrfNm, &sFltNm );
3595  rSh.ReRead( sGrfNm, sFltNm, rSrcSh.GetGraphic() );
3596  return true;
3597  }
3598 
3599  //not in selections or selected frames
3600  if( rSh.TestCurrPam( rDragPt ) ||
3601  ( rSh.IsSelFrameMode() && rSh.IsInsideSelectedObj( rDragPt )) )
3602  return false;
3603 
3604  if( rSrcSh.IsTableMode() )
3605  bTableSel = true;
3606  else if( rSrcSh.IsSelFrameMode() || rSrcSh.IsObjSelected() )
3607  {
3608  // don't move position-protected objects!
3610  return false;
3611 
3612  bFrameSel = true;
3613  }
3614 
3615  const SelectionType nSel = rSrcSh.GetSelectionType();
3616 
3618 
3619  SwRewriter aRewriter;
3620 
3621  aRewriter.AddRule(UndoArg1, rSrcSh.GetSelDescr());
3622 
3623  if(rSrcSh.GetDoc() != rSh.GetDoc())
3624  rSrcSh.StartUndo( eUndoId, &aRewriter );
3625  rSh.StartUndo( eUndoId, &aRewriter );
3626 
3627  rSh.StartAction();
3628  rSrcSh.StartAction();
3629 
3630  if( &rSrcSh != &rSh )
3631  {
3632  rSh.EnterStdMode();
3633  rSh.SwCursorShell::SetCursor( rDragPt, true );
3634  cWord = rSrcSh.IntelligentCut( nSel, false );
3635  }
3636  else if( !bTableSel && !bFrameSel )
3637  {
3638  if( !rSh.IsAddMode() )
3639  {
3640  // #i87233#
3641  if ( rSh.IsBlockMode() )
3642  {
3643  // preserve order of cursors for block mode
3644  rSh.GoPrevCursor();
3645  }
3646 
3647  rSh.SwCursorShell::CreateCursor();
3648  }
3649  rSh.SwCursorShell::SetCursor( rDragPt, true, false );
3650  rSh.GoPrevCursor();
3651  cWord = rSh.IntelligentCut( rSh.GetSelectionType(), false );
3652  rSh.GoNextCursor();
3653  }
3654 
3655  bInWrd = rSh.IsInWord();
3656  bEndWrd = rSh.IsEndWrd();
3657  bSttWrd = !bEndWrd && rSh.IsStartWord();
3658  bSttPara= rSh.IsSttPara();
3659 
3661 
3662  // at first, select InetFields!
3664  {
3665  if( &rSrcSh == &rSh )
3666  {
3667  rSh.GoPrevCursor();
3668  rSh.SwCursorShell::SetCursor( aSttPt, true );
3670  if( rSh.TestCurrPam( rDragPt ) )
3671  {
3672  // don't copy/move inside of yourself
3673  rSh.DestroyCursor();
3674  rSh.EndUndo();
3675  rSh.EndAction();
3676  rSh.EndAction();
3677  return false;
3678  }
3679  rSh.GoNextCursor();
3680  }
3681  else
3682  {
3683  rSrcSh.SwCursorShell::SetCursor( aSttPt, true );
3685  }
3686 
3687  // is there a URL attribute at the insert point? Then replace that,
3688  // so simply put up a selection?
3689  rSh.DelINetAttrWithText();
3690  g_bDDINetAttr = true;
3691  }
3692 
3693  if ( rSrcSh.IsSelFrameMode() )
3694  {
3695  //Hack: fool the special treatment
3696  aSttPt = rSrcSh.GetObjRect().Pos();
3697  }
3698 
3699  bool bRet = rSrcSh.SwFEShell::Copy( &rSh, aSttPt, rDragPt, bMove,
3700  !bIsXSelection );
3701 
3702  if( !bIsXSelection )
3703  {
3704  rSrcSh.Push();
3705  if ( bRet && bMove && !bFrameSel )
3706  {
3707  if ( bTableSel )
3708  {
3709  /* delete table contents not cells */
3710  rSrcSh.Delete();
3711  }
3712  else
3713  {
3714  //SmartCut, take one of the blanks along.
3715  rSh.SwCursorShell::DestroyCursor();
3716  if ( cWord == SwWrtShell::WORD_SPACE_BEFORE )
3717  rSh.ExtendSelection( false );
3718  else if ( cWord == SwWrtShell::WORD_SPACE_AFTER )
3719  rSh.ExtendSelection();
3720  rSrcSh.DelRight();
3721  }
3722  }
3723  rSrcSh.KillPams();
3725 
3726  /* after dragging a table selection inside one shell
3727  set cursor to the drop position. */
3728  if( &rSh == &rSrcSh && ( bTableSel || rSh.IsBlockMode() ) )
3729  {
3730  rSrcSh.CalcLayout();
3731  rSrcSh.SwCursorShell::SetCursor(rDragPt);
3732  rSrcSh.GetSwCursor()->SetMark();
3733  }
3734  }
3735 
3736  if( bRet && !bTableSel && !bFrameSel )
3737  {
3738  if( (bInWrd || bEndWrd) &&
3739  (cWord == SwWrtShell::WORD_SPACE_AFTER ||
3740  cWord == SwWrtShell::WORD_SPACE_BEFORE) )
3741  {
3742  if ( bSttWrd || (bInWrd && !bEndWrd))
3743  rSh.SwEditShell::Insert(' ', bIsXSelection);
3744  if ( !bSttWrd || (bInWrd && !bSttPara) )
3745  {
3746  rSh.SwapPam();
3747  if ( !bSttWrd )
3748  rSh.SwEditShell::Insert(' ', bIsXSelection);
3749  rSh.SwapPam();
3750  }
3751  }
3752 
3753  if( bIsXSelection )
3754  {
3755  if( &rSrcSh == &rSh && !rSh.IsAddMode() )
3756  {
3757  rSh.SwCursorShell::DestroyCursor();
3758  rSh.GoPrevCursor();
3759  }
3760  else
3761  {
3762  rSh.SwapPam();
3763  rSh.SwCursorShell::ClearMark();
3764  }
3765  }
3766  else
3767  {
3768  if( rSh.IsAddMode() )
3769  rSh.SwCursorShell::CreateCursor();
3770  else
3771  {
3772  // turn on selection mode
3773  rSh.SttSelect();
3774  rSh.EndSelect();
3775  }
3776  }
3777  }
3778 
3779  if( bRet && bMove && bFrameSel )
3780  rSrcSh.LeaveSelFrameMode();
3781 
3782  if( rSrcSh.GetDoc() != rSh.GetDoc() )
3783  rSrcSh.EndUndo();
3784  rSh.EndUndo();
3785 
3786  // put the shell in the right state
3787  if( &rSrcSh != &rSh && ( rSh.IsFrameSelected() || rSh.IsObjSelected() ))
3788  rSh.EnterSelFrameMode();
3789 
3790  rSrcSh.EndAction();
3791  rSh.EndAction();
3792  return true;
3793 }
3794 
3795 // Interfaces for Selection
3797  const SwFrameShell * _pCreatorView )
3798 {
3799  SwModule *pMod = SW_MOD();
3801 
3802  pNew->m_pCreatorView = _pCreatorView;
3803 
3804  pMod->m_pXSelection = pNew.get();
3805  pNew->CopyToSelection( rSh.GetWin() );
3806 }
3807 
3809  const SwFrameShell * _pCreatorView)
3810 {
3811  SwModule *pMod = SW_MOD();
3812  if( pMod->m_pXSelection &&
3813  ((!pMod->m_pXSelection->m_pWrtShell) || (pMod->m_pXSelection->m_pWrtShell == &rSh)) &&
3814  (!_pCreatorView || (pMod->m_pXSelection->m_pCreatorView == _pCreatorView)) )
3815  {
3817  }
3818 }
3819 
3820 namespace
3821 {
3822  class theSwTransferableUnoTunnelId : public rtl::Static< UnoTunnelIdInit, SwTransferable > {};
3823 }
3824 
3826 {
3827  return theSwTransferableUnoTunnelId::get().getSeq();
3828 }
3829 
3831 {
3832  sal_Int64 nRet;
3833  if( ( rId.getLength() == 16 ) &&
3834  ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
3835  {
3836  nRet = sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ) );
3837  }
3838  else
3840  return nRet;
3841 }
3842 
3844 {
3845  SwTransferable* pSwTransferable = nullptr;
3846 
3847  uno::Reference<XUnoTunnel> xTunnel( rData.GetTransferable(), UNO_QUERY );
3848  if ( xTunnel.is() )
3849  {
3850  sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() );
3851  if ( nHandle )
3852  pSwTransferable = reinterpret_cast<SwTransferable*>( static_cast<sal_IntPtr>(nHandle) );
3853  }
3854 
3855  return pSwTransferable;
3856 
3857 }
3858 
3860  : rTrnsfr(rTrans)
3861  , pDocShell(nullptr)
3862  , nOldTimeOut(0)
3863  , bDelBookmrk(false)
3864  , bInDisconnect(false)
3865 {
3866  // we only end up here with table- or text selection
3868  {
3869  SwFrameFormat* pFormat = rSh.GetTableFormat();
3870  if( pFormat )
3871  sName = pFormat->GetName();
3872  }
3873  else
3874  {
3875  // creating a temp. bookmark without undo
3876  bool bUndo = rSh.DoesUndo();
3877  rSh.DoUndo( false );
3878  bool bIsModified = rSh.IsModified();
3879 
3880  ::sw::mark::IMark* pMark = rSh.SetBookmark(
3881  vcl::KeyCode(),
3882  OUString(),
3884  if(pMark)
3885  {
3886  sName = pMark->GetName();
3887  bDelBookmrk = true;
3888  if( !bIsModified )
3889  rSh.ResetModified();
3890  }
3891  else
3892  sName.clear();
3893  rSh.DoUndo( bUndo );
3894  }
3895 
3896  if( !sName.isEmpty() &&
3897  nullptr != ( pDocShell = rSh.GetDoc()->GetDocShell() ) )
3898  {
3899  // then we create our "server" and connect to it
3901  if( refObj.is() )
3902  {
3903  refObj->AddConnectAdvise( this );
3904  refObj->AddDataAdvise( this,
3905  OUString(),
3907  nOldTimeOut = refObj->GetUpdateTimeout();
3908  refObj->SetUpdateTimeout( 0 );
3909  }
3910  }
3911 }
3912 
3914 {
3915  if( refObj.is() )
3916  Disconnect( true );
3917 }
3918 
3920  const uno::Any& )
3921 {
3922  // well, that's it with the link
3923  if( !bInDisconnect )
3924  {
3925  if( FindDocShell() && pDocShell->GetView() )
3927  Disconnect( false );
3928  }
3929  return SUCCESS;
3930 }
3931 
3933 {
3934  if( !refObj.is() || !FindDocShell() )
3935  return false;
3936 
3937  rtl_TextEncoding eEncoding = DDE_TXT_ENCODING;
3938  const OString aAppNm(OUStringToOString(
3939  Application::GetAppName(), eEncoding));
3940  const OString aTopic(OUStringToOString(
3941  pDocShell->GetTitle(SFX_TITLE_FULLNAME), eEncoding));
3942  const OString aName(OUStringToOString(sName, eEncoding));
3943 
3944  std::unique_ptr<sal_Char[]> pMem(new sal_Char[ aAppNm.getLength() + aTopic.getLength() + aName.getLength() + 4 ]);
3945 
3946  sal_Int32 nLen = aAppNm.getLength();
3947  memcpy( pMem.get(), aAppNm.getStr(), nLen );
3948  pMem[ nLen++ ] = 0;
3949  memcpy( pMem.get() + nLen, aTopic.getStr(), aTopic.getLength() );
3950  nLen = nLen + aTopic.getLength();
3951  pMem[ nLen++ ] = 0;
3952  memcpy( pMem.get() + nLen, aName.getStr(), aName.getLength() );
3953  nLen = nLen + aName.getLength();
3954  pMem[ nLen++ ] = 0;
3955  pMem[ nLen++ ] = 0;
3956 
3957  rStrm.WriteBytes( pMem.get(), nLen );
3958  pMem.reset();
3959 
3960  IDocumentMarkAccess* const pMarkAccess = pDocShell->GetDoc()->getIDocumentMarkAccess();
3961  IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(sName);
3962  if(ppMark != pMarkAccess->getAllMarksEnd()
3964  {
3965  // the mark is still a DdeBookmark
3966  // we replace it with a Bookmark, so it will get saved etc.
3967  ::sw::mark::IMark* const pMark = ppMark->get();
3969  SwServerObject& rServerObject = dynamic_cast<SwServerObject&>(*p);
3970 
3971  // collecting state of old mark
3972  SwPaM aPaM(pMark->GetMarkStart());
3973  *aPaM.GetPoint() = pMark->GetMarkStart();
3974  if(pMark->IsExpanded())
3975  {
3976  aPaM.SetMark();
3977  *aPaM.GetMark() = pMark->GetMarkEnd();
3978  }
3979  OUString sMarkName = pMark->GetName();
3980 
3981  // remove mark
3982  rServerObject.SetNoServer(); // this removes the connection between SwServerObject and mark
3983  // N.B. ppMark was not loaded from file and cannot have xml:id
3984  pMarkAccess->deleteMark(ppMark);
3985 
3986  // recreate as Bookmark
3987  ::sw::mark::IMark* const pNewMark = pMarkAccess->makeMark(
3988  aPaM,
3989  sMarkName,
3992  rServerObject.SetDdeBookmark(*pNewMark);
3993  }
3994 
3995  bDelBookmrk = false;
3996  return true;
3997 }
3998 
3999 void SwTrnsfrDdeLink::Disconnect( bool bRemoveDataAdvise )
4000 {
4001  // don't accept DataChanged anymore, when already in Disconnect!
4002  // (DTOR from Bookmark sends a DataChanged!)
4003  bool bOldDisconnect = bInDisconnect;
4004  bInDisconnect = true;
4005 
4006  // destroy the unused bookmark again (without Undo!)?
4007  if( bDelBookmrk && refObj.is() && FindDocShell() )
4008  {
4009  SwDoc* pDoc = pDocShell->GetDoc();
4010  ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
4011 
4012  // #i58448#
4013  Link<bool,void> aSavedOle2Link( pDoc->GetOle2Link() );
4014  pDoc->SetOle2Link( Link<bool,void>() );
4015 
4016  bool bIsModified = pDoc->getIDocumentState().IsModified();
4017 
4018  IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
4019  pMarkAccess->deleteMark(pMarkAccess->findMark(sName));
4020 
4021  if( !bIsModified )
4022  pDoc->getIDocumentState().ResetModified();
4023  // #i58448#
4024  pDoc->SetOle2Link( aSavedOle2Link );
4025 
4026  bDelBookmrk = false;
4027  }
4028 
4029  if( refObj.is() )
4030  {
4031  refObj->SetUpdateTimeout( nOldTimeOut );
4032  refObj->RemoveConnectAdvise( this );
4033  if( bRemoveDataAdvise )
4034  // in a DataChanged the SelectionObject must NEVER be deleted
4035  // is already handled by the base class
4036  // (ADVISEMODE_ONLYONCE!!!!)
4037  // but always in normal Disconnect!
4038  refObj->RemoveAllDataAdvise( this );
4039  refObj.clear();
4040  }
4041  bInDisconnect = bOldDisconnect;
4042 }
4043 
4045 {
4046  SfxObjectShell* pTmpSh = SfxObjectShell::GetFirst( checkSfxObjectShell<SwDocShell> );
4047  while( pTmpSh )
4048  {
4049  if( pTmpSh == pDocShell ) // that's what we want to have
4050  {
4051  if( pDocShell->GetDoc() )
4052  return true;
4053  break; // the Doc is not there anymore, so leave!
4054  }
4055  pTmpSh = SfxObjectShell::GetNext( *pTmpSh, checkSfxObjectShell<SwDocShell> );
4056  }
4057 
4058  pDocShell = nullptr;
4059  return false;
4060 }
4061 
4063 {
4064  if( !bInDisconnect && refObj.is() )
4065  {
4066  refObj->RemoveAllDataAdvise( this );
4067  refObj->RemoveConnectAdvise( this );
4068  refObj.clear();
4069  }
4070 }
4071 
4072 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwFieldType * GetFieldType(size_t nField, SwFieldIds nResId=SwFieldIds::Unknown) const
get field types with a ResId, if 0 get all
Definition: edfld.cxx:68
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
SfxViewFrame * GetViewFrame() const
bool UnloadObject()
Definition: ndole.cxx:958
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:233
long Width() const
bool is() const
void StopShellTimer()
Definition: view.cxx:1759
SwWrtShell * GetShell()
Definition: swdtflvr.hxx:203
#define EXCHG_IN_ACTION_COPY
#define FN_DB_CONNECTION_ANY
Definition: cmdid.h:709
#define FN_DB_DATA_SOURCE_ANY
Definition: cmdid.h:711
bool GetGraphic(SotClipboardFormatId nFormat, Graphic &rGraphic)
virtual void SetVisArea(const tools::Rectangle &rVisArea)
const ::utl::TransliterationWrapper & GetAppCmpStrIgnore()
Definition: init.cxx:823
bool SetINetImage(const INetImage &rINtImg, const css::datatransfer::DataFlavor &rFlavor)
static OUString GetAppName()
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
#define EXCHG_IN_ACTION_MOVE
void KillPams()
Definition: crsrsh.cxx:1010
void SetDataForDragAndDrop(const Point &rSttPos)
Definition: swdtflvr.cxx:3237
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
static SwTransferable * GetSwTransferable(const TransferableDataHelper &rData)
Definition: swdtflvr.cxx:3843
bool hasValue()
SwTransferable(const SwTransferable &)=delete
static bool PasteAsHyperlink(TransferableDataHelper &rData, SwWrtShell &rSh, SotClipboardFormatId nFormat)
Definition: swdtflvr.cxx:2708
#define RES_URL
Definition: hintids.hxx:216
#define EXCHG_OUT_ACTION_INSERT_STRING
virtual const OUString & GetName() const =0
Marks a position in the document model.
Definition: pam.hxx:35
SwTransferable * m_pXSelection
Definition: swmodule.hxx:128
TransferableObjectDescriptor m_aObjDesc
Definition: swdtflvr.hxx:66
css::uno::Any GetAny(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool SetBitmapEx(const BitmapEx &rBitmap, const css::datatransfer::DataFlavor &rFlavor)
SdrView * GetDrawView()
Definition: vnew.cxx:376
void AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId=nullptr)
Definition: viewdlg2.cxx:135
virtual bool DoSaveCompleted(SfxMedium *pNewStor=nullptr, bool bRegisterRecent=true)
#define ADVISEMODE_NODATA
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:185
const OUString & GetImageURL() const
virtual ::sfx2::SvLinkSource * DdeCreateLinkSource(const OUString &rItem) override
Definition: docsh2.cxx:1362
void SaveTableBoxContent(const SwPosition *pPos=nullptr)
Definition: trvltbl.cxx:873
void InsertDDETable(const SwInsertTableOptions &rInsTableOpts, SwDDEFieldType *pDDEType, sal_uInt16 nRows, sal_uInt16 nCols)
Definition: edtab.cxx:212
tools::SvRef< sfx2::SvBaseLink > m_xDdeLink
Definition: swdtflvr.hxx:67
SAL_DLLPRIVATE void SetProtectFlag(bool const bFlag)
Definition: section.hxx:106
void SetLinkFileName(OUString const &rNew)
Definition: section.hxx:118
OUString GetTitle(sal_uInt16 nMaxLen=0) const
static css::uno::Reference< css::embed::XStorage > GetStorageFromInputStream(const css::uno::Reference< css::io::XInputStream > &xStream, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
void ReRead(const OUString &rGrfName, const OUString &rFltName, const Graphic *pGraphic=nullptr)
Re-read if graphic is not ok. Current graphic is replaced by the new one.
Definition: editsh.cxx:300
std::unique_ptr< SwPaM > m_pPaM
Definition: swdtflvr.cxx:207
bool GoNextCursor()
go to the next SSelection
Definition: crsrsh.cxx:1345
SwUndoId
Definition: swundo.hxx:29
SwDocShell * GetDocShell()
Definition: doc.hxx:1340
bool g_bExecuteDrag
Definition: edtdd.cxx:48
bool GetURLFromButton(OUString &rURL, OUString &rDescr) const
Definition: wrtsh3.cxx:202
void ReadGraphic(SvStream &rIStream, Graphic &rGraphic)
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
const OUString & GetTargetURL() const
void AddTransferable(SwTransferable &rTransferable)
Definition: view.cxx:1853
constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_DRAWMODEL
Definition: swdtflvr.cxx:151
const SfxObjectShellLock & GetTmpDocShell()
Definition: doc.hxx:1347
long Height() const
signed char sal_Int8
SwNodeIndex nNode
Definition: pam.hxx:37
void Insert(SwField const &)
Definition: wrtsh2.cxx:71
bool IsTableMode() const
Definition: crsrsh.hxx:643
bool IsSttPara() const
Definition: crsrsh.cxx:1083
void Copy(SwDoc *pClpDoc, const OUString *pNewClpText=nullptr)
Copy and Paste methods for internal clipboard.
Definition: fecopy.cxx:84
bool Is() const
#define FN_TABLE_DELETE_TABLE
Definition: cmdid.h:352
static sal_uInt8 GetExchangeAction(const DataFlavorExVector &rDataFlavorExVector, SotExchangeDest nDestination, sal_uInt16 nSourceOptions, sal_uInt8 nUserAction, SotClipboardFormatId &rFormat, sal_uInt8 &rDefaultAction, SotClipboardFormatId nOnlyTestFormat=SotClipboardFormatId::NONE, const css::uno::Reference< css::datatransfer::XTransferable > *pxTransferable=nullptr, SotExchangeActionFlags *pActionFlags=nullptr)
SfxDispatcher * GetDispatcher()
int PrepareForCopy(bool bIsCut=false)
Definition: swdtflvr.cxx:808
static SvxAbstractDialogFactory * Create()
static bool IsPaste(const SwWrtShell &, const TransferableDataHelper &)
Definition: swdtflvr.cxx:1211
::std::vector< DataFlavorEx > DataFlavorExVector
sal_uIntPtr sal_uLong
constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_RICHTEXT
Definition: swdtflvr.cxx:157
void SetPrefMapMode(const MapMode &rPrefMapMode)
Size GetObjSize() const
Definition: feshview.cxx:2310
static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark &rMark)
Returns the MarkType used to create the mark.
Definition: docbm.cxx:322
bool PrivateDrop(SwWrtShell &rSh, const Point &rDragPt, bool bMove, bool bIsXSelection)
Definition: swdtflvr.cxx:3533
const SfxPoolItem * pAttr
Definition: crsrsh.hxx:100
#define DDE_TXT_ENCODING
Definition: swdtflvr.cxx:164
bool Pop(SwCursorShell::PopMode=SwCursorShell::PopMode::DeleteStack)
Definition: wrtsh1.cxx:1690
bool SetTransferableObjectDescriptor(const TransferableObjectDescriptor &rDesc)
#define EXCHG_OUT_ACTION_INSERT_DDE
#define CNT_HasGrf(USH)
Definition: editsh.hxx:137
bool IsModified() const
Changes in document?
Definition: edws.cxx:64
#define SOFFICE_FILEFORMAT_CURRENT
css::uno::Reference< css::document::XDocumentProperties > getDocProperties()
Provides access to the marks of a document.
void SetChgLnk(const Link< SwCursorShell *, void > &rLnk)
Definition: crsrsh.hxx:485
static bool PasteFileList(TransferableDataHelper &rData, SwWrtShell &rSh, bool bLink, const Point *pPt, bool bMsg)
Definition: swdtflvr.cxx:2948
static bool PasteFormat(SwWrtShell &rSh, TransferableDataHelper &rData, SotClipboardFormatId nFormat)
Definition: swdtflvr.cxx:3021
SwSection const * InsertSection(SwSectionData &rNewData, SfxItemSet const *const =nullptr)
Definition: edsect.cxx:35
bool IsSupportedGraphic() const
SwCursor * GetSwCursor() const
Definition: crsrsh.hxx:864
Definition: doc.hxx:185
bool HasFormat(SotClipboardFormatId nFormat)
void SetOle2Link(const Link< bool, void > &rLink)
Definition: doc.hxx:1316
SVL_DLLPUBLIC OUString removePassword(OUString const &rURI, INetURLObject::EncodeMechanism eEncodeMechanism, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
OUString GetUniqueSectionName(const OUString *pChkStr=nullptr) const
Definition: ndsect.cxx:1356
static bool CheckForURLOrLNKFile(TransferableDataHelper &rData, OUString &rFileName, OUString *pTitle=nullptr)
Definition: swdtflvr.cxx:2990
aBuf
#define EXCHG_OUT_ACTION_REPLACE_SVXB
comphelper::OInterfaceContainerHelper2 & GetPasteListeners()
Definition: fecopy.cxx:1180
sal_Int16 nId
bool IsInsideSelectedObj(const Point &rPt)
returns enum values
Definition: feshview.cxx:1285
ObjCntType
Definition: fesh.hxx:120
SvStream * IsValid(SvStream &)
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:233
#define DND_ACTION_COPYMOVE
#define FN_DB_DATA_COMMAND_ANY
Definition: cmdid.h:712
void RemoveDDELinkFormat(const vcl::Window &rWin)
Definition: swdtflvr.cxx:372
void GetASCWriter(const OUString &rFltNm, const OUString &, WriterRef &xRet)
Definition: wrtasc.cxx:207
OUString GetSelDescr() const
Definition: wrtsh1.cxx:1733
SwNode & GetNode() const
Definition: ndindex.hxx:118
void SetTmpDocShell(SfxObjectShellLock rLock)
in case during copying of embedded object a new shell is created, it should be set here and cleaned l...
Definition: doc.hxx:1346
ShellMode GetShellMode()
Definition: view0.cxx:114
void EnterStdMode()
Definition: select.cxx:552
virtual ::sw::mark::IMark * makeMark(const SwPaM &rPaM, const OUString &rProposedName, MarkType eMark,::sw::mark::InsertMode eMode)=0
Generates a new mark in the document for a certain selection.
SwEditWin & GetEditWin()
Definition: view.hxx:403
void DestroyCursor()
transform TableCursor to normal cursor, nullify Tablemode
Definition: crsrsh.cxx:142
void Pos(const Point &rNew)
Definition: swrect.hxx:167
ErrCode Write(WriterRef const &rxWriter, const OUString *=nullptr)
Definition: shellio.cxx:743
void DoUndo(bool bOn=true)
Undo.
Definition: edws.cxx:199
void ReplaceCompatibilityOptions(const SwDoc &rSource)
Definition: docnew.cxx:869
SotExchangeDest
void SetReadUTF8(bool bSet)
Definition: shellio.hxx:251
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1348
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:176
size_t GetIMapObjectCount() const
void NavigatorPaste(const NaviContentBookmark &rBkmk, const sal_uInt16 nAction)
Definition: wrtsh2.cxx:556
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
sal_uInt16 Count() const
void SetClipBoard(bool bNew)
Definition: doc.hxx:956
#define EXCHG_OUT_ACTION_MOVE_PRIVATE
bool GetINetBookmark(SotClipboardFormatId nFormat, INetBookmark &rBmk)
SVX_DLLPUBLIC bool SvxDrawingLayerExport(SdrModel *pModel, const css::uno::Reference< css::io::XOutputStream > &xOut)
bool InsertOleObject(const svt::EmbeddedObjectRef &xObj, SwFlyFrameFormat **pFlyFrameFormat=nullptr)
Definition: wrtsh1.cxx:464
void FillTransferableObjectDescriptor(TransferableObjectDescriptor &rDesc) const
bool HasFormat(SotClipboardFormatId nFormat) const
void EndAllAction()
Definition: edws.cxx:96
#define ADVISEMODE_ONLYONCE
void ReplaceStyles(const SwDoc &rSource, bool bIncludePageStyles=true)
Definition: docfmt.cxx:1548
bool SetINetBookmark(const INetBookmark &rBmk, const css::datatransfer::DataFlavor &rFlavor)
bool SetObject(void *pUserObject, sal_uInt32 nUserObjectId, const css::datatransfer::DataFlavor &rFlavor)
void StartInsertRegionDialog(const SwSectionData &)
Definition: regionsw.cxx:176
bool DelRight()
Definition: delete.cxx:292
sal_uInt16 getRotation()
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:187
virtual void LockExpFields()=0
#define DND_ACTION_MOVE
void SwapPam()
Definition: crsrsh.cxx:964
#define EXCHG_IN_ACTION_DEFAULT
Used by the UI to modify the document model.
Definition: wrtsh.hxx:86
bool CopyGlossary(SwTextBlocks &rGlossary, const OUString &rStr)
Definition: swdtflvr.cxx:1058
void AddFormat(SotClipboardFormatId nFormat)
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:389
SdrObjectUniquePtr CreateXFormsControl(const svx::OXFormsDescriptor &_rDesc)
weld::Window * GetFrameWeld() const
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: swdtflvr.cxx:3825
#define EXCHG_OUT_ACTION_INSERT_IMAGEMAP
sal_uInt16 sal_Unicode
Reader * ReadXML
Definition: fltini.cxx:65
bool GotoFly(const OUString &rName, FlyCntType eType=FLYCNTTYPE_ALL, bool bSelFrame=true)
Definition: move.cxx:590
const SwView & GetView() const
Definition: wrtsh.hxx:424
RET_YES
virtual const_iterator_t findMark(const OUString &rMark) const =0
Finds a mark by name.
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
#define FN_TABLE_SELECT_ALL
Definition: cmdid.h:341
bool IsMore() const
SwIndex nContent
Definition: pam.hxx:38
void ReplaceDefaults(const SwDoc &rSource)
Definition: docnew.cxx:837
#define SAL_MAX_UINT16
static void CreateSelection(SwWrtShell &rSh, const SwFrameShell *pCreator=nullptr)
Definition: swdtflvr.cxx:3796
SwDoc * GetDoc()
Document is created after calling Read(...).
Definition: docfact.cxx:38
bool Paste(SwDoc *pClpDoc)
Definition: fecopy.cxx:683
#define EXCHG_INOUT_ACTION_NONE
const Link< bool, void > & GetOle2Link() const
Definition: doc.hxx:1317
char sal_Char
const OUString & GetName() const
Definition: format.hxx:111
bool Paste(TransferableDataHelper &rData)
Definition: content.cxx:3690
Graphic * m_pOrigGraphic
Definition: swdtflvr.hxx:76
#define FN_QRY_MERGE_FIELD
Definition: cmdid.h:241
Reader * ReadHTML
Definition: fltini.cxx:65
bool InsertGlossary(SwTextBlocks &rBlock, const OUString &rEntry, SwPaM &rPaM, SwCursorShell *pShell=nullptr)
inserts an AutoText block
Definition: docglos.cxx:131
bool g_bDDINetAttr
Definition: edtwin.cxx:186
const GDIMetaFile & GetGDIMetaFile() const
OUString sStr
Definition: crsrsh.hxx:107
TransferBufferType m_eBufferType
Definition: swdtflvr.hxx:81
SwPasteSdr
Definition: fesh.hxx:157
static bool ShowPasteInfo(SfxClassificationCheckPasteResult eResult)
bool IsBlockMode() const
Definition: wrtsh.hxx:157
const Link< SwCursorShell *, void > & GetChgLnk() const
Definition: crsrsh.hxx:486
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
void GetGrfNms(OUString *pGrfName, OUString *pFltName, const SwFlyFrameFormat *=nullptr) const
Returns the name and the filter name of a graphic if the pointer is on a graphic. ...
Definition: editsh.cxx:310
static bool PasteData(TransferableDataHelper &rData, SwWrtShell &rSh, sal_uInt8 nAction, SotExchangeActionFlags nActionFlags, SotClipboardFormatId nFormat, SotExchangeDest nDestination, bool bIsPasteFormat, bool bIsDefault, const Point *pDDPos=nullptr, sal_Int8 nDropAction=0, bool bPasteSelection=false, RndStdIds nAnchorType=RndStdIds::FLY_AT_PARA, bool bIgnoreComments=false, SwPasteContext *pContext=nullptr)
Definition: swdtflvr.cxx:1360
#define EXCHG_OUT_ACTION_INSERT_GRAPH
SotClipboardFormatId
void SetMap(const ImageMap *pM)
Pointer will be copied.
Definition: atrfrm.cxx:1742
SfxObjectCreateMode GetCreateMode() const
static SotExchangeDest GetSotDestination(const SwWrtShell &rSh)
Definition: swdtflvr.cxx:1748
static SfxClassificationCheckPasteResult CheckPaste(const css::uno::Reference< css::document::XDocumentProperties > &xSource, const css::uno::Reference< css::document::XDocumentProperties > &xDestination)
static SotClipboardFormatId GetFormatID(css::uno::Reference< css::embed::XStorage > const &xStorage)
void GetHTMLWriter(const OUString &, const OUString &rBaseURL, WriterRef &xRet)
Definition: wrthtml.cxx:1550
static long GetDDStartPosX()
Definition: edtwin.hxx:245
static SotClipboardFormatId aPasteSpecialIds[]
the list of formats which will be offered to the user in the 'Paste Special...' dialog and the paste ...
Definition: swdtflvr.cxx:3085
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:164
std::unique_ptr< SwDocFac, o3tl::default_delete< SwDocFac > > m_pClpDocFac
Definition: swdtflvr.hxx:73
static ErrCode LoadGraphic(const OUString &rPath, const OUString &rFilter, Graphic &rGraphic, GraphicFilter *pFilter=nullptr, sal_uInt16 *pDeterminedFormat=nullptr)
void StopInsFrame()
Definition: edtwin.cxx:730
bool GetFlyFrameAttr(SfxItemSet &rSet) const
Definition: fefly1.cxx:1023
virtual const_iterator_t getAllMarksBegin() const =0
returns a STL-like random access iterator to the begin of the sequence of marks.
container_t::const_iterator const_iterator_t
void SetCharSet(rtl_TextEncoding nVal)
Definition: shellio.hxx:77
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:202
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
bool SetGraphic(const Graphic &rGraphic)
bool IsEmpty() const
void EndSelect()
Definition: select.cxx:426
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:614
bool ShouldWait() const
Should WaitPtr be switched on for the clipboard?
Definition: crsrsh.cxx:2934
#define SFX_TITLE_FULLNAME
OUString read_zeroTerminated_uInt8s_ToOUString(SvStream &rStream, rtl_TextEncoding eEnc)
bool IsSelection() const
Definition: crsrsh.hxx:875
static bool PasteDBData(TransferableDataHelper &rData, SwWrtShell &rSh, SotClipboardFormatId nFormat, bool bLink, const Point *pDragPt, bool bMsg)
Definition: swdtflvr.cxx:2848
bool GetINetImage(SotClipboardFormatId nFormat, INetImage &rINtImg)
T * get() const
SwgReaderOption & GetReaderOpt()
Definition: shellio.hxx:232
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
void RemoveFormat(SotClipboardFormatId nFormat)
#define FN_CHAR_LEFT
Definition: cmdid.h:615
#define SOFFICE_FILEFORMAT_50
Style of a layout element.
Definition: frmfmt.hxx:57
void NoRotate()
Definition: viewdraw.cxx:440
bool DeleteTableSel()
Current selection, may be whole table.
Definition: fetab.cxx:1283
#define IMAP_FORMAT_DETECT
bool HasSelection() const
Definition: wrtsh.hxx:137
static bool PasteFileContent(TransferableDataHelper &, SwWrtShell &rSh, SotClipboardFormatId nFormat, bool bMsg, bool bIgnoreComments=false)
Definition: swdtflvr.cxx:1801
#define SW_MOD()
Definition: swmodule.hxx:255
virtual const_iterator_t getAllMarksEnd() const =0
returns a STL-like random access iterator to the end of the sequence of marks.
sal_uInt16 GetMasterPageCount() const
SwPaM * CreateCursor()
delete the current cursor and make the following into the current
Definition: crsrsh.cxx:118
std::unique_ptr< Graphic > m_pClpBitmap
Definition: swdtflvr.hxx:75
TransferBufferType
Definition: swdtflvr.hxx:47
static SwDoc * lcl_GetDoc(SwDocFac &rDocFac)
Definition: swdtflvr.cxx:301
SwFieldType * InsertFieldType(const SwFieldType &)
insert field type
Definition: edfld.cxx:350
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
const SwFrameShell * m_pCreatorView
Definition: swdtflvr.hxx:72
static bool PasteSpecial(SwWrtShell &rSh, TransferableDataHelper &, SotClipboardFormatId &rFormatUsed)
Definition: swdtflvr.cxx:3110
const SwPosition * GetPoint() const
Definition: pam.hxx:207
GraphicType GetType() const
void SetIgnoreHTMLComments(bool bSet)
Definition: shellio.hxx:259
OUString const & GetURL() const
void SetSmartProtocol(INetProtocol eTheSmartScheme)
virtual bool IsModified() const =0
Changes of document?
void EndAction(const bool bIdleEnd=false, const bool DoSetPosX=false)
Definition: crsrsh.cxx:229
void DelINetAttrWithText()
If cursor is in a INetAttribute it will be deleted completely including the descriptive text (needed ...
Definition: editsh.cxx:731
static bool PasteTargetURL(TransferableDataHelper &rData, SwWrtShell &rSh, SwPasteSdr nAction, const Point *pPt, bool bInsertGRF)
Definition: swdtflvr.cxx:2131
void SetRetainSelection(bool bRet)
Definition: wrtsh.hxx:266
virtual void DragFinished(sal_Int8 nDropAction) override
Definition: swdtflvr.cxx:3396
SotExchangeActionFlags
css::uno::Reference< css::datatransfer::XTransferable > GetXTransferable() const
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2143
bool GetString(SotClipboardFormatId nFormat, OUString &rStr)
#define EXCHG_OUT_ACTION_INSERT_INTERACTIVE
OUString sName
bool InsertURL(const SwFormatINetFormat &rFormat, const OUString &rStr, bool bKeepSelection=false)
Definition: editsh.cxx:639
bool ActionPend() const
Definition: viewsh.hxx:199
int i
css::uno::Reference< css::embed::XEmbeddedObject > FindOLEObj(sal_Int64 &nAspect) const
Definition: swdtflvr.cxx:340
bool IsIdle() const
Definition: viewopt.hxx:201
int IntelligentCut(SelectionType nSelectionType, bool bCut=true)
Definition: select.cxx:870
::sw::mark::IMark * SetBookmark(const vcl::KeyCode &, const OUString &rName, IDocumentMarkAccess::MarkType eMark=IDocumentMarkAccess::MarkType::BOOKMARK)
Definition: crbm.cxx:82
bool SetFlyFrameAttr(SfxItemSet &rSet)
Definition: fefly1.cxx:1066
void SetNoServer()
Definition: swserv.cxx:252
sal_Int32 m_nStartContent
Definition: swdtflvr.cxx:208
bool SelectTextAttr(sal_uInt16 nWhich, const SwTextAttr *pAttr=nullptr)
Definition: move.cxx:675
const SdrPage * GetPage(sal_uInt16 nPgNum) const
size_t GetFieldTypeCount(SwFieldIds nResId=SwFieldIds::Unknown) const
count field types with a ResId, if SwFieldIds::Unknown count all
Definition: edfld.cxx:47
const SwFormatURL & GetURL(bool=true) const
Definition: fmturl.hxx:78
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:222
std::size_t WriteBytes(const void *pData, std::size_t nSize)
static OUString CreateShellID(const SfxObjectShell *pShell)
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:29
const OUString & GetTargetFrame() const
bool IsInWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES) const
Definition: crstrvl1.cxx:36
static bool IsPasteSpecial(const SwWrtShell &rWrtShell, const TransferableDataHelper &)
Definition: swdtflvr.cxx:3012
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper)=0
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:426
const OUString & GetDescription() const
virtual bool WriteObject(tools::SvRef< SotStorageStream > &rxOStm, void *pUserObject, sal_uInt32 nUserObjectId, const css::datatransfer::DataFlavor &rFlavor) override
Definition: swdtflvr.cxx:634
static long GetDDStartPosY()
Definition: edtwin.hxx:246
void PrepareOLE(const TransferableObjectDescriptor &rObjDesc)
static css::uno::Reference< css::embed::XStorage > GetStorageFromURL(const OUString &aURL, sal_Int32 nStorageMode, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
OUString GetFile(size_t nIndex) const
#define EE_CHAR_FONTHEIGHT
void CopyToClipboard(vcl::Window *pWindow) const
void StartDrag(vcl::Window *pWin, const Point &rPos)
Definition: swdtflvr.cxx:3372
void CopyString(const OUString &rStr)
long ResetSelect(const Point *, bool)
Definition: select.cxx:337
#define FN_DB_DATA_CURSOR_ANY
Definition: cmdid.h:716
void StartDrag(vcl::Window *pWindow, sal_Int8 nDragSourceActions)
Marks a node in the document model.
Definition: ndindex.hxx:31
int Copy(bool bIsCut=false)
Definition: swdtflvr.cxx:1031
void SetMergedItem(const SfxPoolItem &rItem)
static void ClearSelection(vcl::Window *pWindow)
virtual void SetObjName(const SvGlobalName &rClass, const OUString &rObjName)=0
GUIDCNamePair const aData
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
void DragFinished()
Definition: edtdd.cxx:149
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
#define DND_ACTION_LINK
void SttSelect()
Definition: select.cxx:386
void SetURL(const OUString &rURL, bool bServerMap)
Definition: atrfrm.cxx:1736
const SfxPoolItem & GetMergedItem(const sal_uInt16 nWhich) const
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:119
bool PrivatePaste(SwWrtShell &rShell, SwPasteContext *pContext=nullptr)
Definition: swdtflvr.cxx:3459
bool HasReadonlySel() const
Definition: crsrsh.cxx:3227
#define FN_QRY_INSERT_FIELD
Definition: cmdid.h:242
#define FN_DB_DATA_COLUMN_NAME_ANY
Definition: cmdid.h:714
size_t Count() const
SwDrawBase * GetDrawFuncPtr() const
Definition: view.hxx:513
constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_SWOLE
Definition: swdtflvr.cxx:155
static bool isMediaURL(const OUString &rURL, const OUString &rReferer, bool bDeep=false, Size *pPreferredSizePixel=nullptr)
#define FN_DB_DATA_SELECTION_ANY
Definition: cmdid.h:715
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
#define EXCHG_OUT_ACTION_REPLACE_IMAGEMAP
static uno::Reference< XTransferable > * lcl_getTransferPointer(uno::Reference< XTransferable > &xRef)
Definition: swdtflvr.cxx:1105
virtual void AddSupportedFormats() override
Definition: swdtflvr.cxx:321
#define RES_TXTATR_INETFMT
Definition: hintids.hxx:141
const Graphic * GetGraphic(bool bWait=true) const
Definition: editsh.cxx:244
virtual ~SwTransferable() override
Definition: swdtflvr.cxx:261
FlyProtectFlags IsSelObjProtected(FlyProtectFlags eType) const
Which Protection is set at selected object?
Definition: feshview.cxx:2613
bool HasMark()
Definition: crsrsh.hxx:873
const SwPosition * Start() const
Definition: pam.hxx:212
SwDocShell * GetDocShell()
Definition: view.cxx:1115
SwFrameFormat * GetTableFormat()
Definition: edws.cxx:182
Reader * ReadAscii
Definition: fltini.cxx:65
bool IsReadOnly() const
SfxClassificationCheckPasteResult
virtual void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName)=0
void ReplaceSdrObj(const OUString &rGrfName, const Graphic *pGrf)
Definition: fefly1.cxx:1762
bool GetSotStorageStream(SotClipboardFormatId nFormat, tools::SvRef< SotStorageStream > &rStreamRef)
bool GetImageMap(SotClipboardFormatId nFormat, ImageMap &rIMap)
void StartAction()
Definition: crsrsh.cxx:212
static void FillClipFormatItem(const SwWrtShell &rSh, const TransferableDataHelper &rData, SvxClipboardFormatItem &rToFill)
Definition: swdtflvr.cxx:3182
bool IsStartWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES) const
Definition: crstrvl1.cxx:27
bool Delete()
Delete content of all ranges.
Definition: eddel.cxx:117
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rId) override
SelectionType
Definition: wrtsh.hxx:56
const ImageMap * GetMap() const
Definition: fmturl.hxx:68
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static bool PasteDDE(TransferableDataHelper &rData, SwWrtShell &rWrtShell, bool bReReadGrf, bool bMsg)
Definition: swdtflvr.cxx:2248
std::unique_ptr< INetBookmark > m_pBookmark
Definition: swdtflvr.hxx:77
bool IsError() const
ErrCode Read(const Reader &)
Definition: shellio.cxx:76
bool GetGDIMetaFile(SotClipboardFormatId nFormat, GDIMetaFile &rMtf, size_t nMaxActions=0)
SwTrnsfrActionAndUndo(SwWrtShell *pS, bool bDelSel=false, SwPasteContext *pContext=nullptr)
Definition: swdtflvr.cxx:216
void CallChgLnk()
Definition: crsrsh.cxx:2414
#define INIT_FLDTYPES
Definition: swtypes.hxx:118
void GetRTFWriter(const OUString &rFltName, const OUString &rBaseURL, WriterRef &xRet)
Definition: fltini.cxx:675
void CalculateAndCopy()
Definition: swdtflvr.cxx:1041
SdrObject * Next()
bool SetImageMap(const ImageMap &rIMap)
~SwTrnsfrActionAndUndo() COVERITY_NOEXCEPT_FALSE
Definition: swdtflvr.cxx:230
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
Definition: swdtflvr.cxx:421
static void InitOle(SfxObjectShell *pDoc)
Definition: swdtflvr.cxx:331
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
void copyDocumentProperties(const SwDoc &rSource)
Copy document properties from rSource to m_xDocumentProperties.
Definition: fmtatr2.cxx:827
const Graphic * FindOLEReplacementGraphic() const
Definition: swdtflvr.cxx:357
const SwFrameFormat * GetFormatFromObj(const Point &rPt, SwRect **pRectToFill=nullptr) const
Definition: fefly1.cxx:1585
sal_uInt32 GetHeight() const
#define FN_DB_DATA_COMMAND_TYPE_ANY
Definition: cmdid.h:713
void MakeDrawView()
Definition: vnew.cxx:366
#define IMAP_ERR_OK
SwWrtShell * m_pWrtShell
Definition: swdtflvr.hxx:69
void MakeLnkName(OUString &rName, const OUString *pType, const OUString &rFile, const OUString &rLink, const OUString *pFilter)
tools::Rectangle SVRect() const
Definition: swrect.hxx:282
static bool Paste(SwWrtShell &, TransferableDataHelper &, RndStdIds nAnchorType=RndStdIds::FLY_AT_PARA, bool bIgnoreComments=false)
Definition: swdtflvr.cxx:1252
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:145
bool TestCurrPam(const Point &rPt, bool bTstHit=false)
Search in the selected area for a Selection that covers the given point.
Definition: crsrsh.cxx:979
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
SwPasteContext(SwWrtShell &rWrtShell)
Definition: swdtflvr.cxx:1110
SwTableNode * IsIdxInTable(const SwNodeIndex &rIdx)
Definition: ndtbl.cxx:216
#define ERRCODE_NONE
bool GetDrawObjGraphic(SotClipboardFormatId nFormat, Graphic &rGrf) const
Get selected DrawObj as graphics (MetaFile/Bitmap).
Definition: fecopy.cxx:1182
static SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
unsigned char sal_uInt8
#define EXCHG_OUT_ACTION_INSERT_BITMAP
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:426
void Read(SvStream &rIStm)
static void ClearSelection(SwWrtShell &rSh, const SwFrameShell *pCreator=nullptr)
Definition: swdtflvr.cxx:3808
vcl::Window * GetWin() const
Definition: viewsh.hxx:340
sal_uInt16 GetCntType() const
Determine form of content. Return Type at CurrentCursor->SPoint.
Definition: edws.cxx:125
bool ExtendSelection(bool bEnd=true, sal_Int32 nCount=1)
extend current SSelection by n characters
Definition: crsrsh.cxx:2511
const OUString & GetTargetFrameName() const
Definition: fmturl.hxx:65
Tracks the boundaries of pasted content and notifies listeners.
Definition: swdtflvr.cxx:196
SdrObjectUniquePtr CreateFieldControl(const OUString &rFieldDesc) const
void SetIdle(bool b) const
Definition: viewopt.hxx:208
void ResetModified()
Definition: edws.cxx:74
void SetEndian(SvStreamEndian SvStreamEndian)
#define EXCHG_OUT_ACTION_REPLACE_DRAWOBJ
ObjCntType GetObjCntTypeOfSelection() const
Definition: fefly1.cxx:1734
sal_Int32 GetIndex() const
Definition: index.hxx:95
SwRect GetObjRect() const
For adjustment of PosAttr when anchor changes.
Definition: fefly1.cxx:1263
#define EXCHG_OUT_ACTION_REPLACE_BITMAP
bool DoInitNew(SfxMedium *pMedium=nullptr)
SwNodes & GetNodes()
Definition: doc.hxx:403
constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_HTML
Definition: swdtflvr.cxx:152
void RemoveFieldType(size_t nField)
delete field type
Definition: edfld.cxx:98
bool GoPrevCursor()</