1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_SWDTFLVR_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_SWDTFLVR_HXX
22 #include <sfx2/objsh.hxx>
24 #include <vcl/transfer.hxx>
25 #include <vcl/graph.hxx>
26 #include <vcl/vclptr.hxx>
27 #include <sfx2/lnkbase.hxx>
28 #include <com/sun/star/embed/XEmbeddedObject.hpp>
29 #include <o3tl/deleter.hxx>
30 #include <o3tl/typed_flags_set.hxx>
31 #include <svx/swframetypes.hxx>
32 #include <svl/urlbmk.hxx>
41 class SfxAbstractPasteDialog
;
47 class SvxClipboardFormatItem
;
51 enum class SwPasteSdr
;
53 enum class TransferBufferType
: sal_uInt16
57 DocumentWord
= 0x0002,
62 Drawing
= 0x0081, // drawing is internal too!
65 template<> struct typed_flags
<TransferBufferType
> : is_typed_flags
<TransferBufferType
, 0x00ef> {};
67 // paste table into a table
68 enum class PasteTableType
70 PASTE_DEFAULT
, // paste table by overwriting table cells
71 PASTE_ROW
, // paste table as rows above
72 PASTE_COLUMN
, // paste table as columns before
73 PASTE_TABLE
// paste table as nested table
76 class SW_DLLPUBLIC SwTransferable final
: public TransferableHelper
78 friend class SwView_Impl
;
79 SfxObjectShellLock m_aDocShellRef
;
80 TransferableObjectDescriptor m_aObjDesc
;
81 tools::SvRef
<sfx2::SvBaseLink
> m_xDdeLink
;
83 SwWrtShell
*m_pWrtShell
;
84 /* #96392# Added pCreatorView to distinguish SwFrameShell from
86 const SwFrameShell
*m_pCreatorView
;
87 std::unique_ptr
<SwDocFac
, o3tl::default_delete
<SwDocFac
>> m_pClpDocFac
;
88 std::optional
<Graphic
> m_oClpGraphic
;
89 std::optional
<Graphic
> m_oClpBitmap
;
90 Graphic
*m_pOrigGraphic
;
91 std::optional
<INetBookmark
> m_oBookmark
; // URL and description!
92 std::unique_ptr
<ImageMap
> m_pImageMap
;
93 std::unique_ptr
<INetImage
> m_pTargetURL
;
95 TransferBufferType m_eBufferType
;
97 bool m_bOldIdle
:1; //D&D Idle flag from the viewsettings
98 bool m_bCleanUp
:1; //D&D cleanup after Drop (not by internal Drop)
100 // helper methods for the copy
101 css::uno::Reference
< css::embed::XEmbeddedObject
> FindOLEObj( sal_Int64
& nAspect
) const;
102 const Graphic
* FindOLEReplacementGraphic() const;
103 void DeleteSelection();
105 // helper methods for the paste
106 static SwTransferable
* GetSwTransferable( const TransferableDataHelper
& rData
);
107 static void SetSelInShell( SwWrtShell
& , bool , const Point
* );
108 static bool CheckForURLOrLNKFile( const TransferableDataHelper
& rData
,
109 OUString
& rFileName
, OUString
* pTitle
= nullptr );
110 static bool TestAllowedFormat( const TransferableDataHelper
& rData
,
111 SotClipboardFormatId nFormat
, SotExchangeDest nDestination
);
113 static bool PasteFileContent( const TransferableDataHelper
&,
114 SwWrtShell
& rSh
, SotClipboardFormatId nFormat
, bool bMsg
, bool bIgnoreComments
= false );
115 static bool PasteOLE( TransferableDataHelper
& rData
, SwWrtShell
& rSh
,
116 SotClipboardFormatId nFormat
, SotExchangeActionFlags nActionFlags
, bool bMsg
);
117 static bool PasteTargetURL( const TransferableDataHelper
& rData
, SwWrtShell
& rSh
,
118 SwPasteSdr nAction
, const Point
* pPt
, bool bInsertGRF
);
120 static bool PasteDDE( const TransferableDataHelper
& rData
, SwWrtShell
& rWrtShell
,
121 bool bReReadGrf
, bool bMsg
);
123 static bool PasteSdrFormat( const TransferableDataHelper
& rData
,
124 SwWrtShell
& rSh
, SwPasteSdr nAction
,
125 const Point
* pPt
, SotExchangeActionFlags nActionFlags
, bool bNeedToSelectBeforePaste
);
127 static bool PasteGrf( const TransferableDataHelper
& rData
, SwWrtShell
& rSh
,
128 SotClipboardFormatId nFormat
, SwPasteSdr nAction
, const Point
* pPt
,
129 SotExchangeActionFlags nActionFlags
, sal_Int8 nDropAction
, bool bNeedToSelectBeforePaste
, RndStdIds nAnchorType
= RndStdIds::FLY_AT_PARA
);
131 static bool PasteImageMap( const TransferableDataHelper
& rData
,
134 static bool PasteAsHyperlink( const TransferableDataHelper
& rData
,
135 SwWrtShell
& rSh
, SotClipboardFormatId nFormat
);
137 static bool PasteFileName( TransferableDataHelper
& rData
,
138 SwWrtShell
& rSh
, SotClipboardFormatId nFormat
, SwPasteSdr nAction
,
139 const Point
* pPt
, SotExchangeActionFlags nActionFlags
, bool * graphicInserted
);
141 static bool PasteDBData( const TransferableDataHelper
& rData
, SwWrtShell
& rSh
,
142 SotClipboardFormatId nFormat
, bool bLink
, const Point
* pDragPt
,
145 static bool PasteFileList( const TransferableDataHelper
& rData
,
146 SwWrtShell
& rSh
, bool bLink
,
147 const Point
* pPt
, bool bMsg
);
149 bool PrivatePaste( SwWrtShell
& rShell
, SwPasteContext
* pContext
= nullptr, PasteTableType ePasteTable
= PasteTableType::PASTE_DEFAULT
);
151 void SetDataForDragAndDrop( const Point
& rSttPos
);
153 SwTransferable( const SwTransferable
& ) = delete;
154 SwTransferable
& operator=( const SwTransferable
& ) = delete;
156 virtual void AddSupportedFormats() override
;
157 virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
158 virtual bool WriteObject( tools::SvRef
<SotTempStream
>& rxOStm
,
160 sal_uInt32 nUserObjectId
,
161 const css::datatransfer::DataFlavor
& rFlavor
) override
;
162 virtual void DragFinished( sal_Int8 nDropAction
) override
;
163 virtual void ObjectReleased() override
;
164 virtual sal_Bool SAL_CALL
isComplex() override
;
166 using TransferableHelper::StartDrag
;
169 SwTransferable( SwWrtShell
& );
170 virtual ~SwTransferable() override
;
172 static SotExchangeDest
GetSotDestination( const SwWrtShell
& rSh
);
174 // set properties on the document, like PageMargin, VisArea.
176 static void InitOle( SfxObjectShell
* pDoc
);
178 // copy - methods and helper methods for the copy
180 int Copy( bool bIsCut
= false );
181 int PrepareForCopy( bool bIsCut
= false );
182 void PrepareForCopyTextRange(SwPaM
& rPaM
);
183 void CalculateAndCopy(); // special for Calculator
184 bool CopyGlossary( SwTextBlocks
& rGlossary
, const OUString
& rStr
);
186 // remove the DDE-Link format promise
187 void RemoveDDELinkFormat(vcl::Window
& rWin
);
189 // paste - methods and helper methods for the paste
190 static bool IsPaste( const SwWrtShell
&, const TransferableDataHelper
& );
191 static bool Paste( SwWrtShell
&, TransferableDataHelper
&, RndStdIds nAnchorType
= RndStdIds::FLY_AT_PARA
,
192 bool bIgnoreComments
= false, PasteTableType ePasteTable
= PasteTableType::PASTE_DEFAULT
);
193 static bool PasteData( TransferableDataHelper
& rData
,
194 SwWrtShell
& rSh
, sal_uInt8 nAction
, SotExchangeActionFlags nActionFlags
,
195 SotClipboardFormatId nFormat
,
196 SotExchangeDest nDestination
, bool bIsPasteFormat
,
198 const Point
* pDDPos
= nullptr, sal_Int8 nDropAction
= 0,
199 bool bPasteSelection
= false, RndStdIds nAnchorType
= RndStdIds::FLY_AT_PARA
,
200 bool bIgnoreComments
= false,
201 SwPasteContext
* pContext
= nullptr,
202 PasteTableType nPaste
= PasteTableType::PASTE_DEFAULT
);
204 static bool IsPasteSpecial( const SwWrtShell
& rWrtShell
,
205 const TransferableDataHelper
& );
206 static bool IsPasteOwnFormat( const TransferableDataHelper
& );
207 static bool PasteUnformatted( SwWrtShell
& rSh
, TransferableDataHelper
& );
209 * @brief PrePasteSpecial Prepares the given dialog without actually running it
213 static void PrePasteSpecial( const SwWrtShell
& rSh
, TransferableDataHelper
&, const VclPtr
<SfxAbstractPasteDialog
>& pDlg
);
214 static bool PasteFormat( SwWrtShell
& rSh
, TransferableDataHelper
& rData
,
215 SotClipboardFormatId nFormat
);
217 static void FillClipFormatItem( const SwWrtShell
& rSh
,
218 const TransferableDataHelper
& rData
,
219 SvxClipboardFormatItem
& rToFill
);
221 // Interfaces for Drag & Drop
222 void StartDrag( vcl::Window
* pWin
, const Point
& rPos
);
224 SwWrtShell
* GetShell() { return m_pWrtShell
; }
225 void SetCleanUp( bool bFlag
) { m_bCleanUp
= bFlag
; }
227 // public only for testing
228 bool PrivateDrop( SwWrtShell
& rSh
, const Point
& rDragPt
, bool bMove
,
229 bool bIsXSelection
);
231 // Interfaces for Selection
232 /* #96392# Added pCreator to distinguish SwFrameShell from SwWrtShell. */
233 static void CreateSelection( SwWrtShell
& rSh
,
234 const SwFrameShell
* pCreator
= nullptr );
235 static void ClearSelection( const SwWrtShell
& rSh
,
236 const SwFrameShell
* pCreator
= nullptr );
238 // the related SwView is being closed and the SwTransferable is invalid now
239 void Invalidate() {m_pWrtShell
= nullptr;}
241 static void SelectPasteFormat(TransferableDataHelper
& rData
, sal_uInt8
& nAction
,
242 SotClipboardFormatId
& nFormat
);
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */