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