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