Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/inc/fmexch.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_SVX_SOURCE_INC_FMEXCH_HXX
20
#define INCLUDED_SVX_SOURCE_INC_FMEXCH_HXX
21
22
#include <config_options.h>
23
#include <sal/config.h>
24
25
#include <set>
26
27
#include <sot/exchange.hxx>
28
#include <vcl/transfer.hxx>
29
#include <com/sun/star/uno/Sequence.hxx>
30
#include <com/sun/star/form/XForms.hpp>
31
#include <rtl/ref.hxx>
32
#include <tools/link.hxx>
33
#include <vcl/weld/TreeView.hxx>
34
#include <svx/svxdllapi.h>
35
36
namespace svxform
37
{
38
    typedef ::std::set<std::unique_ptr<weld::TreeIter>> ListBoxEntrySet;
39
40
    //= OLocalExchange
41
    class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) OLocalExchange : public TransferDataContainer
42
    {
43
    private:
44
        Link<OLocalExchange&,void>  m_aClipboardListener;
45
        bool            m_bDragging         : 1;
46
        bool            m_bClipboardOwner   : 1;
47
48
    public:
49
        class GrantAccess
50
        {
51
            friend class OLocalExchangeHelper;
52
        };
53
54
    public:
55
        OLocalExchange( );
56
57
0
        bool        isDragging() const { return m_bDragging; }
58
0
        bool        isClipboardOwner() const { return m_bClipboardOwner; }
59
60
        void        setDragging(bool bDragging);
61
        SVXCORE_DLLPRIVATE void copyToClipboard(const weld::Widget& rWidget, const GrantAccess&);
62
63
0
        void        setClipboardListener( const Link<OLocalExchange&,void>& _rListener ) { m_aClipboardListener = _rListener; }
64
65
        SVXCORE_DLLPRIVATE void clear();
66
67
        static  bool    hasFormat( const DataFlavorExVector& _rFormats, SotClipboardFormatId _nFormatId );
68
69
    protected:
70
        // XClipboardOwner
71
        virtual void SAL_CALL lostOwnership( const css::uno::Reference< css::datatransfer::clipboard::XClipboard >& _rxClipboard, const css::uno::Reference< css::datatransfer::XTransferable >& _rxTrans ) override;
72
73
        // TransferableHelper
74
        virtual void        DragFinished( sal_Int8 nDropAction ) override;
75
        virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
76
77
    private:
78
         // don't allow this base class method to be called from outside
79
        using TransferDataContainer::StartDrag;
80
    };
81
82
83
    //= OLocalExchangeHelper
84
85
    /// a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself
86
    class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) OLocalExchangeHelper
87
    {
88
    protected:
89
        rtl::Reference<OLocalExchange> m_xTransferable;
90
91
    public:
92
        OLocalExchangeHelper();
93
        virtual ~OLocalExchangeHelper();
94
95
        void        prepareDrag( );
96
97
        SVXCORE_DLLPRIVATE void copyToClipboard(const weld::Widget& rWidget) const;
98
99
0
        bool    isDragSource() const { return m_xTransferable.is() && m_xTransferable->isDragging(); }
100
0
        bool    isClipboardOwner() const { return m_xTransferable.is() && m_xTransferable->isClipboardOwner(); }
101
0
        bool    isDataExchangeActive( ) const { return isDragSource() || isClipboardOwner(); }
102
0
        void        clear() { if ( isDataExchangeActive() ) m_xTransferable->clear(); }
103
104
0
        SVX_DLLPRIVATE void     setClipboardListener( const Link<OLocalExchange&,void>& _rListener ) { if ( m_xTransferable.is() ) m_xTransferable->setClipboardListener( _rListener ); }
105
106
    protected:
107
        SVX_DLLPRIVATE virtual rtl::Reference<OLocalExchange> createExchange() const = 0;
108
109
    protected:
110
        SVX_DLLPRIVATE void implReset();
111
    };
112
113
    class OControlTransferData
114
    {
115
    private:
116
        DataFlavorExVector  m_aCurrentFormats;
117
118
    protected:
119
        ListBoxEntrySet     m_aSelectedEntries;
120
        css::uno::Sequence< css::uno::Sequence< sal_uInt32 > >
121
                            m_aControlPaths;
122
        css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >
123
                            m_aHiddenControlModels;
124
125
        css::uno::Reference< css::form::XForms >
126
                            m_xFormsRoot;       // the root of the forms collection where the entries we represent reside
127
                                                // this uniquely identifies the page and the document
128
129
        bool        m_bFocusEntry;
130
131
    protected:
132
        // updates m_aCurrentFormats with all formats we currently could supply
133
        void    updateFormats( );
134
135
    public:
136
        OControlTransferData( );
137
138
        // ctor to construct the data from an arbitrary Transferable (usually clipboard data)
139
        OControlTransferData(
140
            const css::uno::Reference< css::datatransfer::XTransferable >& _rxTransferable
141
        );
142
143
        inline const DataFlavorExVector&    GetDataFlavorExVector() const;
144
145
        void addSelectedEntry(std::unique_ptr<weld::TreeIter> xEntry);
146
        void setFocusEntry(bool _bFocusEntry);
147
148
        /** notifies the data transfer object that a certain entry has been removed from the owning tree
149
150
            In case the removed entry is part of the transfer object's selection, the entry is removed from
151
            the selection.
152
153
            @param  _pEntry
154
            @return the number of entries remaining in the selection.
155
        */
156
        size_t onEntryRemoved(const weld::TreeIter* _pEntry);
157
158
        void setFormsRoot(
159
            const css::uno::Reference< css::form::XForms >& _rxFormsRoot
160
0
            ) { m_xFormsRoot = _rxFormsRoot; }
161
162
        void buildPathFormat(const weld::TreeView* pTreeBox, const weld::TreeIter* pRoot);
163
            // assembles m_aControlPaths from m_aSelectedEntries
164
            // (it is assumed that the entries are sorted in m_aSelectedEntries with respect to the neighbor relationship)
165
166
167
        void buildListFromPath(const weld::TreeView* pTreeBox, const weld::TreeIter* pRoot);
168
            // The reverse way: throws everything out of m_aSelectedEntries and rebuilds it using m_aControlPaths
169
170
        void addHiddenControlsFormat(const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >& seqInterfaces);
171
            // adds an SVX_FML_HIDDEN_CONTROLS format and remembers the passed interfaces for it
172
            // (it is NOT checked whether actually only hidden controls are denominated
173
            // by this - the caller must ensure that)
174
175
0
        const ListBoxEntrySet&      selected() const { return m_aSelectedEntries; }
176
        const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >&
177
0
                                    hiddenControls() const { return m_aHiddenControlModels; }
178
179
        const css::uno::Reference< css::form::XForms >&
180
0
                                getFormsRoot() const { return m_xFormsRoot; }
181
    };
182
183
184
    inline const DataFlavorExVector& OControlTransferData::GetDataFlavorExVector() const
185
0
    {
186
0
        const_cast< OControlTransferData* >( this )->updateFormats( );
187
0
        return m_aCurrentFormats;
188
0
    }
189
190
    class OControlExchange final : public OLocalExchange, public OControlTransferData
191
    {
192
    public:
193
        OControlExchange( );
194
195
    public:
196
        static SotClipboardFormatId getFieldExchangeFormatId( );
197
        static SotClipboardFormatId getControlPathFormatId( );
198
        static SotClipboardFormatId getHiddenControlModelsFormatId( );
199
200
        inline static bool  hasFieldExchangeFormat( const DataFlavorExVector& _rFormats );
201
        inline static bool  hasControlPathFormat( const DataFlavorExVector& _rFormats );
202
        inline static bool  hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats );
203
204
    private:
205
        virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
206
        virtual void        AddSupportedFormats() override;
207
    };
208
209
    class OControlExchangeHelper final : public OLocalExchangeHelper
210
    {
211
    public:
212
0
        OControlExchangeHelper() : OLocalExchangeHelper() { }
213
214
0
        OControlExchange* operator->() const { return static_cast< OControlExchange* >( m_xTransferable.get() ); }
215
0
        OControlExchange& operator*() const { return *static_cast< OControlExchange* >( m_xTransferable.get() ); }
216
217
    private:
218
        virtual rtl::Reference<OLocalExchange> createExchange() const override;
219
    };
220
221
222
    inline bool OControlExchange::hasFieldExchangeFormat( const DataFlavorExVector& _rFormats )
223
0
    {
224
0
        return hasFormat( _rFormats, getFieldExchangeFormatId() );
225
0
    }
226
227
    inline bool OControlExchange::hasControlPathFormat( const DataFlavorExVector& _rFormats )
228
0
    {
229
0
        return hasFormat( _rFormats, getControlPathFormatId() );
230
0
    }
231
232
    inline bool OControlExchange::hasHiddenControlModelsFormat( const DataFlavorExVector& _rFormats )
233
0
    {
234
0
        return hasFormat( _rFormats, getHiddenControlModelsFormatId() );
235
0
    }
236
237
238
}
239
240
241
#endif
242
243
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */