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 .
20 #ifndef INCLUDED_SVX_DBAEXCHANGE_HXX
21 #define INCLUDED_SVX_DBAEXCHANGE_HXX
23 #include <sal/config.h>
25 #include <o3tl/typed_flags_set.hxx>
26 #include <vcl/transfer.hxx>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <svx/dataaccessdescriptor.hxx>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <svx/svxdllapi.h>
32 namespace com::sun::star::sdbc
{ class XConnection
; }
33 namespace com::sun::star::beans
{ class XPropertySet
; }
35 // column transfer formats
36 enum class ColumnTransferFormatFlags
38 FIELD_DESCRIPTOR
= 0x01, // the field descriptor format
39 CONTROL_EXCHANGE
= 0x02, // the control exchange format
40 COLUMN_DESCRIPTOR
= 0x04, // data access descriptor for a column
44 template<> struct typed_flags
<ColumnTransferFormatFlags
> : is_typed_flags
<ColumnTransferFormatFlags
, 0x07> {};
52 //= OColumnTransferable
54 class SAL_WARN_UNUSED SVX_DLLPUBLIC OColumnTransferable final
: public TransferableHelper
57 /** construct the transferable from a data access descriptor
59 Note that some of the aspects, in particular all which cannot be represented
60 as string, can only be transported via the CTF_COLUMN_DESCRIPTOR format.
63 The descriptor for the column. It must contain at least
64 <ul><li>information sufficient to create a connection, that is, either one of DataSource, DatabaseLocation,
65 ConnectionResource, and DataAccessDescriptorProperty::Connection</li>
67 <li>a CommandType</li>
68 <li>a ColumnName or ColumnObject</li>
72 const ODataAccessDescriptor
& _rDescriptor
,
73 ColumnTransferFormatFlags _nFormats
76 /** construct the transferable from a DatabaseForm component and a field name
79 the form which is bound to the data source which's field is to be dragged
82 the name of the field to be dragged
85 the column object. Won't be used if <arg>_nFormats</arg> does not include the CTF_COLUMN_DESCRIPTOR
90 the connection the column belongs to. Won't be used if <arg>_nFormats</arg> does not include the CTF_COLUMN_DESCRIPTOR
95 supported formats. Must be a combination of the CTF_XXX flags
98 const css::uno::Reference
< css::beans::XPropertySet
>& _rxForm
,
99 const OUString
& _rFieldName
,
100 const css::uno::Reference
< css::beans::XPropertySet
>& _rxColumn
,
101 const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
,
102 ColumnTransferFormatFlags _nFormats
105 /** checks whether or not a column descriptor can be extracted from the data flavor vector given
111 static bool canExtractColumnDescriptor(const DataFlavorExVector
& _rFlavors
, ColumnTransferFormatFlags _nFormats
);
113 /** extracts a column descriptor from the transferable given
115 static bool extractColumnDescriptor(
116 const TransferableDataHelper
& _rData
117 ,OUString
& _rDatasource
118 ,OUString
& _rDatabaseLocation
119 ,OUString
& _rConnectionResource
120 ,sal_Int32
& _nCommandType
122 ,OUString
& _rFieldName
125 /** extracts a column descriptor from the transferable given
127 static ODataAccessDescriptor
128 extractColumnDescriptor(const TransferableDataHelper
& _rData
);
131 // TransferableHelper overridables
132 virtual void AddSupportedFormats() override
;
133 virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
135 static SotClipboardFormatId
getDescriptorFormatId();
137 SVX_DLLPRIVATE
void implConstruct(
138 const OUString
& _rDatasource
139 ,const OUString
& _rConnectionResource
140 ,const sal_Int32 _nCommandType
141 ,const OUString
& _rCommand
142 ,const OUString
& _rFieldName
145 ODataAccessDescriptor m_aDescriptor
;
146 OUString m_sCompatibleFormat
;
147 ColumnTransferFormatFlags
const m_nFormatFlags
;
151 //= ODataAccessObjectTransferable
153 /** class for transferring data access objects (tables, queries, statements ...)
155 class SAL_WARN_UNUSED SVX_DLLPUBLIC ODataAccessObjectTransferable
: public TransferableHelper
157 ODataAccessDescriptor m_aDescriptor
;
158 OUString m_sCompatibleObjectDescription
;
159 // needed to provide a SotClipboardFormatId::SBA_DATAEXCHANGE format
162 /** should be used copying and the connection is needed.
164 The data source name.
166 The kind of command. @see com.sun.star.sdbc.CommandType
168 The command, either a name of a table or query or a SQL statement.
170 ODataAccessObjectTransferable(
171 const OUString
& _rDatasourceOrLocation
172 ,const sal_Int32 _nCommandType
173 ,const OUString
& _rCommand
174 ,const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
177 /** should be used when copying a query object and no connection is available.
179 The data source name.
181 The kind of command. @see com.sun.star.sdbc.CommandType
183 The command, either a name of a table or query or a SQL statement.
185 ODataAccessObjectTransferable(
186 const OUString
& _rDatasourceOrLocation
187 ,const sal_Int32 _nCommandType
188 ,const OUString
& _rCommand
191 /** with this ctor, only the object descriptor format will be provided
193 ODataAccessObjectTransferable(
194 const css::uno::Reference
< css::beans::XPropertySet
>& _rxLivingForm
197 /** checks whether or not an object descriptor can be extracted from the data flavor vector given
203 static bool canExtractObjectDescriptor(const DataFlavorExVector
& _rFlavors
);
205 /** extracts a object descriptor from the transferable given
207 static ODataAccessDescriptor
208 extractObjectDescriptor(const TransferableDataHelper
& _rData
);
211 virtual void AddSupportedFormats() override
;
212 virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
213 virtual void ObjectReleased() override
;
216 const ODataAccessDescriptor
& getDescriptor() const { return m_aDescriptor
; }
217 ODataAccessDescriptor
& getDescriptor() { return m_aDescriptor
; }
219 void addCompatibleSelectionDescription(
220 const css::uno::Sequence
< css::uno::Any
>& _rSelRows
222 // normally, a derived class could simply access getDescriptor[DataAccessDescriptorProperty::Selection] and place the sequence therein
223 // but unfortunately, we have this damned compatible format, and this can't be accessed in
224 // derived classes (our class is the only one which should be contaminated with this)
227 SVX_DLLPRIVATE
void construct( const OUString
& _rDatasourceOrLocation
228 ,const OUString
& _rConnectionResource
229 ,const sal_Int32 _nCommandType
230 ,const OUString
& _rCommand
231 ,const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
233 ,const OUString
& _sActiveCommand
);
237 //= OMultiColumnTransferable
239 /** class for transferring multiple columns
241 class SAL_WARN_UNUSED SVX_DLLPUBLIC OMultiColumnTransferable final
: public TransferableHelper
244 OMultiColumnTransferable(const css::uno::Sequence
< css::beans::PropertyValue
>& _aDescriptors
);
246 /** checks whether or not an object descriptor can be extracted from the data flavor vector given
252 static bool canExtractDescriptor(const DataFlavorExVector
& _rFlavors
);
254 /** extracts a object descriptor from the transferable given
256 static css::uno::Sequence
< css::beans::PropertyValue
> extractDescriptor(const TransferableDataHelper
& _rData
);
259 virtual void AddSupportedFormats() override
;
260 virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
261 virtual void ObjectReleased() override
;
262 static SotClipboardFormatId
getDescriptorFormatId();
264 css::uno::Sequence
< css::beans::PropertyValue
> m_aDescriptors
;
271 #endif // INCLUDED_SVX_DBAEXCHANGE_HXX
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */