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