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