Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/inc/swdtflvr.hxx
Line
Count
Source
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
#ifndef INCLUDED_SW_SOURCE_UIBASE_INC_SWDTFLVR_HXX
20
#define INCLUDED_SW_SOURCE_UIBASE_INC_SWDTFLVR_HXX
21
22
#include <sfx2/objsh.hxx>
23
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>
33
#include <memory>
34
#include <optional>
35
36
#include <swdllapi.h>
37
38
class ImageMap;
39
class INetImage;
40
class SfxAbstractPasteDialog;
41
class SwDocFac;
42
class SwPaM;
43
class SwTextBlocks;
44
class SwWrtShell;
45
class SvxClipboardFormatItem;
46
class SwFrameShell;
47
class SwPasteContext;
48
enum class SwPasteSdr;
49
50
enum class TransferBufferType : sal_uInt16
51
{
52
        NONE          = 0x0000,
53
        Document      = 0x0001,
54
        DocumentWord  = 0x0002,
55
        Graphic       = 0x0004,
56
        Table         = 0x0008,
57
        Ole           = 0x0020,
58
        InetField     = 0x0040,
59
        Drawing       = 0x0081,   // drawing is internal too!
60
};
61
namespace o3tl {
62
    template<> struct typed_flags<TransferBufferType> : is_typed_flags<TransferBufferType, 0x00ef> {};
63
}
64
// paste table into a table
65
enum class PasteTableType
66
{
67
        PASTE_DEFAULT, // paste table by overwriting table cells
68
        PASTE_ROW,     // paste table as rows above
69
        PASTE_COLUMN,  // paste table as columns before
70
        PASTE_TABLE    // paste table as nested table
71
};
72
73
class SwTransferDdeLink;
74
75
class SAL_DLLPUBLIC_RTTI SwTransferable final : public TransferableHelper
76
{
77
    friend class SwView_Impl;
78
    SfxObjectShellLock              m_aDocShellRef;
79
    TransferableObjectDescriptor    m_aObjDesc;
80
    tools::SvRef<SwTransferDdeLink>  m_xDdeLink;
81
82
    SwWrtShell      *m_pWrtShell;
83
    /* #96392# Added pCreatorView to distinguish SwFrameShell from
84
       SwWrtShell. */
85
    const SwFrameShell *m_pCreatorView;
86
    std::unique_ptr<SwDocFac, o3tl::default_delete<SwDocFac>> m_pClpDocFac;
87
    std::optional<Graphic>        m_oClpGraphic;
88
    std::optional<Graphic>        m_oClpBitmap;
89
    Graphic                         *m_pOrigGraphic;
90
    std::optional<INetBookmark>     m_oBookmark;     // URL and description!
91
    std::unique_ptr<ImageMap>       m_pImageMap;
92
    std::unique_ptr<INetImage>      m_pTargetURL;
93
94
    TransferBufferType m_eBufferType;
95
96
    bool m_bOldIdle   :1; //D&D Idle flag from the viewsettings
97
    bool m_bCleanUp   :1; //D&D cleanup after Drop (not by internal Drop)
98
99
    // helper methods for the copy
100
    css::uno::Reference < css::embed::XEmbeddedObject > FindOLEObj( sal_Int64& nAspect ) const;
101
    const Graphic* FindOLEReplacementGraphic() const;
102
    void DeleteSelection();
103
104
    // helper methods for the paste
105
    static SwTransferable* GetSwTransferable( const TransferableDataHelper& rData );
106
    static void SetSelInShell( SwWrtShell& , bool , const Point* );
107
    static bool CheckForURLOrLNKFile( const TransferableDataHelper& rData,
108
                                OUString& rFileName, OUString* pTitle = nullptr );
109
    static bool TestAllowedFormat( const TransferableDataHelper& rData,
110
                                        SotClipboardFormatId nFormat, SotExchangeDest nDestination );
111
112
    static bool PasteFileContent( const TransferableDataHelper&,
113
                                    SwWrtShell& rSh, SotClipboardFormatId nFormat, bool bMsg, bool bIgnoreComments = false);
114
    static bool PasteOLE( const TransferableDataHelper& rData, SwWrtShell& rSh,
115
                            SotClipboardFormatId nFormat, SotExchangeActionFlags nActionFlags, bool bMsg );
116
    static bool PasteTargetURL( const TransferableDataHelper& rData, SwWrtShell& rSh,
117
                        SwPasteSdr nAction, const Point* pPt, bool bInsertGRF );
118
119
    static bool PasteDDE( const TransferableDataHelper& rData, SwWrtShell& rWrtShell,
120
                            bool bReReadGrf, bool bMsg );
121
122
    static bool PasteSdrFormat(  const TransferableDataHelper& rData,
123
                                    SwWrtShell& rSh, SwPasteSdr nAction,
124
                                    const Point* pPt, SotExchangeActionFlags nActionFlags, bool bNeedToSelectBeforePaste);
125
126
    static bool PasteGrf( const TransferableDataHelper& rData, SwWrtShell& rSh,
127
                                SotClipboardFormatId nFormat, SwPasteSdr nAction, const Point* pPt,
128
                                SotExchangeActionFlags nActionFlags, sal_Int8 nDropAction,
129
                                bool bNeedToSelectBeforePaste, bool * pbCallAutoCaption,
130
                                RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA);
131
132
    static bool PasteImageMap( const TransferableDataHelper& rData,
133
                                    SwWrtShell& rSh );
134
135
    static bool PasteAsHyperlink( const TransferableDataHelper& rData,
136
                                        SwWrtShell& rSh, SotClipboardFormatId nFormat );
137
138
    static bool PasteFileName( const TransferableDataHelper& rData,
139
                            SwWrtShell& rSh, SotClipboardFormatId nFormat, SwPasteSdr nAction,
140
                            const Point* pPt, SotExchangeActionFlags nActionFlags,
141
                            bool * pbCallAutoCaption);
142
143
    static bool PasteDBData( const TransferableDataHelper& rData, SwWrtShell& rSh,
144
                            SotClipboardFormatId nFormat, bool bLink, const Point* pDragPt,
145
                            bool bMsg );
146
147
    static bool PasteFileList( const TransferableDataHelper& rData,
148
                                SwWrtShell& rSh, bool bLink,
149
                                const Point* pPt, bool bMsg,
150
                                bool * pbCallAutoCaption);
151
152
    bool PrivatePaste( SwWrtShell& rShell, SwPasteContext* pContext = nullptr, PasteTableType ePasteTable = PasteTableType::PASTE_DEFAULT );
153
154
    void SetDataForDragAndDrop( const Point& rSttPos );
155
156
                                    SwTransferable( const SwTransferable& ) = delete;
157
    SwTransferable&                 operator=( const SwTransferable& ) = delete;
158
159
    virtual void        AddSupportedFormats() override;
160
    virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
161
    virtual bool        WriteObject( SvStream& rOStm,
162
                                        void* pUserObject,
163
                                        sal_uInt32 nUserObjectId,
164
                                        const css::datatransfer::DataFlavor& rFlavor ) override;
165
    virtual void        DragFinished( sal_Int8 nDropAction ) override;
166
    virtual void        ObjectReleased() override;
167
    virtual sal_Bool SAL_CALL isComplex() override;
168
169
    using TransferableHelper::StartDrag;
170
171
public:
172
    SW_DLLPUBLIC SwTransferable( SwWrtShell& );
173
    virtual ~SwTransferable() override;
174
175
    static SotExchangeDest GetSotDestination( const SwWrtShell& rSh );
176
177
    // set properties on the document, like PageMargin, VisArea.
178
    // And set real Size
179
    static void InitOle( SfxObjectShell* pDoc );
180
181
    // copy - methods and helper methods for the copy
182
    SW_DLLPUBLIC int  Cut();
183
    SW_DLLPUBLIC int  Copy( bool bIsCut = false, bool bDeleteRedlines = true );
184
    int  PrepareForCopy( bool bIsCut = false, bool bDeleteRedlines = true );
185
    void PrepareForCopyTextRange(SwPaM & rPaM);
186
    void  CalculateAndCopy();                // special for Calculator
187
    bool  CopyGlossary( SwTextBlocks& rGlossary, const OUString& rStr );
188
189
    // remove the DDE-Link format promise
190
    void RemoveDDELinkFormat(vcl::Window& rWin);
191
    // disconnect to not receive DataChanged listener notifications
192
    void DisconnectDDE();
193
194
    // paste - methods and helper methods for the paste
195
    static bool IsPaste( const SwWrtShell&, const TransferableDataHelper& );
196
    SW_DLLPUBLIC static bool Paste( SwWrtShell&, const TransferableDataHelper&, RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA,
197
                          bool bIgnoreComments = false, PasteTableType ePasteTable = PasteTableType::PASTE_DEFAULT);
198
    static bool PasteData( const TransferableDataHelper& rData,
199
                          SwWrtShell& rSh, sal_uInt8 nAction, SotExchangeActionFlags nActionFlags,
200
                          SotClipboardFormatId nFormat,
201
                          SotExchangeDest nDestination, bool bIsPasteFormat,
202
                          bool bIsDefault,
203
                          const Point* pDDPos = nullptr, sal_Int8 nDropAction = 0,
204
                          bool bPasteSelection = false, RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA,
205
                          bool bIgnoreComments = false,
206
                          SwPasteContext* pContext = nullptr,
207
                          PasteTableType nPaste = PasteTableType::PASTE_DEFAULT);
208
209
    static bool IsPasteSpecial( const SwWrtShell& rWrtShell,
210
                                const TransferableDataHelper& );
211
    static bool IsPasteOwnFormat( const TransferableDataHelper& );
212
    static bool PasteUnformatted( SwWrtShell& rSh, const TransferableDataHelper& );
213
    /**
214
     * @brief PrePasteSpecial Prepares the given dialog without actually running it
215
     * @param rSh
216
     * @param rFormatUsed
217
     */
218
    static void PrePasteSpecial( const SwWrtShell& rSh, const TransferableDataHelper&, const VclPtr<SfxAbstractPasteDialog>& pDlg );
219
    SW_DLLPUBLIC static bool PasteFormat( SwWrtShell& rSh, const TransferableDataHelper& rData,
220
                             SotClipboardFormatId nFormat );
221
222
    static void FillClipFormatItem( const SwWrtShell& rSh,
223
                                const TransferableDataHelper& rData,
224
                                SvxClipboardFormatItem & rToFill );
225
226
    // Interfaces for Drag & Drop
227
    void StartDrag( vcl::Window* pWin, const Point& rPos );
228
229
0
    SwWrtShell* GetShell()              { return m_pWrtShell; }
230
0
    void SetCleanUp( bool bFlag )       { m_bCleanUp = bFlag; }
231
232
    // public only for testing
233
    SW_DLLPUBLIC bool PrivateDrop( SwWrtShell& rSh, const Point& rDragPt, bool bMove,
234
                        bool bIsXSelection );
235
236
    // Interfaces for Selection
237
    /* #96392# Added pCreator to distinguish SwFrameShell from SwWrtShell. */
238
    static void CreateSelection( SwWrtShell & rSh,
239
                                 const SwFrameShell * pCreator = nullptr );
240
    static void ClearSelection( const SwWrtShell& rSh,
241
                                const SwFrameShell * pCreator = nullptr );
242
243
    // the related SwView is being closed and the SwTransferable is invalid now
244
0
    void    Invalidate() {m_pWrtShell = nullptr;}
245
246
    SW_DLLPUBLIC static void SelectPasteFormat(const TransferableDataHelper& rData, sal_uInt8& nAction,
247
                                  SotClipboardFormatId& nFormat);
248
};
249
250
#endif
251
252
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */