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>
40 class SfxAbstractPasteDialog
;
45 class SvxClipboardFormatItem
;
49 enum class SwPasteSdr
;
51 enum class TransferBufferType
: sal_uInt16
55 DocumentWord
= 0x0002,
60 Drawing
= 0x0081, // drawing is internal too!
63 template<> struct typed_flags
<TransferBufferType
> : is_typed_flags
<TransferBufferType
, 0x00ef> {};
65 // paste table into a table
66 enum class PasteTableType
68 PASTE_DEFAULT
, // paste table by overwriting table cells
69 PASTE_ROW
, // paste table as rows above
70 PASTE_COLUMN
, // paste table as columns before
71 PASTE_TABLE
// paste table as nested table
74 class SW_DLLPUBLIC SwTransferable
: public TransferableHelper
76 friend class SwView_Impl
;
77 SfxObjectShellLock m_aDocShellRef
;
78 TransferableObjectDescriptor m_aObjDesc
;
79 tools::SvRef
<sfx2::SvBaseLink
> m_xDdeLink
;
81 SwWrtShell
*m_pWrtShell
;
82 /* #96392# Added pCreatorView to distinguish SwFrameShell from
84 const SwFrameShell
*m_pCreatorView
;
85 std::unique_ptr
<SwDocFac
, o3tl::default_delete
<SwDocFac
>> m_pClpDocFac
;
86 std::unique_ptr
<Graphic
> m_pClpGraphic
;
87 std::unique_ptr
<Graphic
> m_pClpBitmap
;
88 Graphic
*m_pOrigGraphic
;
89 std::unique_ptr
<INetBookmark
> m_pBookmark
; // URL and description!
90 std::unique_ptr
<ImageMap
> m_pImageMap
;
91 std::unique_ptr
<INetImage
> m_pTargetURL
;
93 TransferBufferType m_eBufferType
;
95 bool m_bOldIdle
:1; //D&D Idle flag from the viewsettings
96 bool m_bCleanUp
:1; //D&D cleanup after Drop (not by internal Drop)
98 // helper methods for the copy
99 css::uno::Reference
< css::embed::XEmbeddedObject
> FindOLEObj( sal_Int64
& nAspect
) const;
100 const Graphic
* FindOLEReplacementGraphic() const;
101 void DeleteSelection();
103 // helper methods for the paste
104 static SwTransferable
* GetSwTransferable( const TransferableDataHelper
& rData
);
105 static void SetSelInShell( SwWrtShell
& , bool , const Point
* );
106 static bool CheckForURLOrLNKFile( TransferableDataHelper
& rData
,
107 OUString
& rFileName
, OUString
* pTitle
= nullptr );
108 static bool TestAllowedFormat( const TransferableDataHelper
& rData
,
109 SotClipboardFormatId nFormat
, SotExchangeDest nDestination
);
111 static bool PasteFileContent( TransferableDataHelper
&,
112 SwWrtShell
& rSh
, SotClipboardFormatId nFormat
, bool bMsg
, bool bIgnoreComments
= false );
113 static bool PasteOLE( TransferableDataHelper
& rData
, SwWrtShell
& rSh
,
114 SotClipboardFormatId nFormat
, SotExchangeActionFlags nActionFlags
, bool bMsg
);
115 static bool PasteTargetURL( TransferableDataHelper
& rData
, SwWrtShell
& rSh
,
116 SwPasteSdr nAction
, const Point
* pPt
, bool bInsertGRF
);
118 static bool PasteDDE( TransferableDataHelper
& rData
, SwWrtShell
& rWrtShell
,
119 bool bReReadGrf
, bool bMsg
);
121 static bool PasteSdrFormat( TransferableDataHelper
& rData
,
122 SwWrtShell
& rSh
, SwPasteSdr nAction
,
123 const Point
* pPt
, SotExchangeActionFlags nActionFlags
, bool bNeedToSelectBeforePaste
);
125 static bool PasteGrf( TransferableDataHelper
& rData
, SwWrtShell
& rSh
,
126 SotClipboardFormatId nFormat
, SwPasteSdr nAction
, const Point
* pPt
,
127 SotExchangeActionFlags nActionFlags
, sal_Int8 nDropAction
, bool bNeedToSelectBeforePaste
, RndStdIds nAnchorType
= RndStdIds::FLY_AT_PARA
);
129 static bool PasteImageMap( TransferableDataHelper
& rData
,
132 static bool PasteAsHyperlink( TransferableDataHelper
& rData
,
133 SwWrtShell
& rSh
, SotClipboardFormatId nFormat
);
135 static bool PasteFileName( TransferableDataHelper
& rData
,
136 SwWrtShell
& rSh
, SotClipboardFormatId nFormat
, SwPasteSdr nAction
,
137 const Point
* pPt
, SotExchangeActionFlags nActionFlags
, bool * graphicInserted
);
139 static bool PasteDBData( TransferableDataHelper
& rData
, SwWrtShell
& rSh
,
140 SotClipboardFormatId nFormat
, bool bLink
, const Point
* pDragPt
,
143 static bool PasteFileList( TransferableDataHelper
& rData
,
144 SwWrtShell
& rSh
, bool bLink
,
145 const Point
* pPt
, bool bMsg
);
147 bool PrivateDrop( SwWrtShell
& rSh
, const Point
& rDragPt
, bool bMove
,
148 bool bIsXSelection
);
150 bool PrivatePaste( SwWrtShell
& rShell
, SwPasteContext
* pContext
= nullptr, PasteTableType ePasteTable
= PasteTableType::PASTE_DEFAULT
);
152 void SetDataForDragAndDrop( const Point
& rSttPos
);
154 SwTransferable( const SwTransferable
& ) = delete;
155 SwTransferable
& operator=( const SwTransferable
& ) = delete;
158 virtual void AddSupportedFormats() override
;
159 virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
160 virtual bool WriteObject( tools::SvRef
<SotStorageStream
>& rxOStm
,
162 sal_uInt32 nUserObjectId
,
163 const css::datatransfer::DataFlavor
& rFlavor
) override
;
164 virtual void DragFinished( sal_Int8 nDropAction
) override
;
165 virtual void ObjectReleased() override
;
166 virtual sal_Bool SAL_CALL
isComplex() override
;
168 using TransferableHelper::StartDrag
;
171 SwTransferable( SwWrtShell
& );
172 virtual ~SwTransferable() override
;
174 static SotExchangeDest
GetSotDestination( const SwWrtShell
& rSh
);
176 // set properties on the document, like PageMargin, VisArea.
178 static void InitOle( SfxObjectShell
* pDoc
);
180 // copy - methods and helper methods for the copy
182 int Copy( bool bIsCut
= false );
183 int PrepareForCopy( bool bIsCut
= false );
184 void CalculateAndCopy(); // special for Calculator
185 bool CopyGlossary( SwTextBlocks
& rGlossary
, const OUString
& rStr
);
187 // remove the DDE-Link format promise
188 void RemoveDDELinkFormat( const vcl::Window
& rWin
);
190 // paste - methods and helper methods for the paste
191 static bool IsPaste( const SwWrtShell
&, const TransferableDataHelper
& );
192 static bool Paste( SwWrtShell
&, TransferableDataHelper
&, RndStdIds nAnchorType
= RndStdIds::FLY_AT_PARA
,
193 bool bIgnoreComments
= false, PasteTableType ePasteTable
= PasteTableType::PASTE_DEFAULT
);
194 static bool PasteData( TransferableDataHelper
& rData
,
195 SwWrtShell
& rSh
, sal_uInt8 nAction
, SotExchangeActionFlags nActionFlags
,
196 SotClipboardFormatId nFormat
,
197 SotExchangeDest nDestination
, bool bIsPasteFormat
,
199 const Point
* pDDPos
= nullptr, sal_Int8 nDropAction
= 0,
200 bool bPasteSelection
= false, RndStdIds nAnchorType
= RndStdIds::FLY_AT_PARA
,
201 bool bIgnoreComments
= false,
202 SwPasteContext
* pContext
= nullptr,
203 PasteTableType nPaste
= PasteTableType::PASTE_DEFAULT
);
205 static bool IsPasteSpecial( const SwWrtShell
& rWrtShell
,
206 const TransferableDataHelper
& );
207 static bool IsPasteOwnFormat( const TransferableDataHelper
& );
208 static bool PasteUnformatted( SwWrtShell
& rSh
, TransferableDataHelper
& );
210 * @brief PrePasteSpecial Prepares the given dialog without actually running it
214 static void PrePasteSpecial( const SwWrtShell
& rSh
, TransferableDataHelper
&, const VclPtr
<SfxAbstractPasteDialog
>& pDlg
);
215 static bool PasteFormat( SwWrtShell
& rSh
, TransferableDataHelper
& rData
,
216 SotClipboardFormatId nFormat
);
218 static void FillClipFormatItem( const SwWrtShell
& rSh
,
219 const TransferableDataHelper
& rData
,
220 SvxClipboardFormatItem
& rToFill
);
222 // Interfaces for Drag & Drop
223 void StartDrag( vcl::Window
* pWin
, const Point
& rPos
);
225 SwWrtShell
* GetShell() { return m_pWrtShell
; }
226 void SetCleanUp( bool bFlag
) { m_bCleanUp
= bFlag
; }
228 // Interfaces for Selection
229 /* #96392# Added pCreator to distinguish SwFrameShell from SwWrtShell. */
230 static void CreateSelection( SwWrtShell
& rSh
,
231 const SwFrameShell
* pCreator
= nullptr );
232 static void ClearSelection( SwWrtShell
& rSh
,
233 const SwFrameShell
* pCreator
= nullptr );
235 // the related SwView is being closed and the SwTransferable is invalid now
236 void Invalidate() {m_pWrtShell
= nullptr;}
237 static const css::uno::Sequence
< sal_Int8
>& getUnoTunnelId();
239 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& rId
) override
;
241 static void SelectPasteFormat(TransferableDataHelper
& rData
, sal_uInt8
& nAction
,
242 SotClipboardFormatId
& nFormat
);
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */