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