/src/libreoffice/include/svx/dbaexchange.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 | | |
20 | | #ifndef INCLUDED_SVX_DBAEXCHANGE_HXX |
21 | | #define INCLUDED_SVX_DBAEXCHANGE_HXX |
22 | | |
23 | | #include <config_options.h> |
24 | | #include <sal/config.h> |
25 | | |
26 | | #include <o3tl/typed_flags_set.hxx> |
27 | | #include <vcl/transfer.hxx> |
28 | | #include <com/sun/star/beans/PropertyValue.hpp> |
29 | | #include <svx/dataaccessdescriptor.hxx> |
30 | | #include <com/sun/star/uno/Sequence.hxx> |
31 | | #include <svx/svxdllapi.h> |
32 | | |
33 | | namespace com::sun::star::sdbc { class XConnection; } |
34 | | namespace com::sun::star::beans { class XPropertySet; } |
35 | | |
36 | | // column transfer formats |
37 | | enum class ColumnTransferFormatFlags |
38 | | { |
39 | | FIELD_DESCRIPTOR = 0x01, // the field descriptor format |
40 | | CONTROL_EXCHANGE = 0x02, // the control exchange format |
41 | | COLUMN_DESCRIPTOR = 0x04, // data access descriptor for a column |
42 | | }; |
43 | | namespace o3tl |
44 | | { |
45 | | template<> struct typed_flags<ColumnTransferFormatFlags> : is_typed_flags<ColumnTransferFormatFlags, 0x07> {}; |
46 | | } |
47 | | |
48 | | |
49 | | namespace svx |
50 | | { |
51 | | |
52 | | |
53 | | //= OColumnTransferable |
54 | | |
55 | | class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC OColumnTransferable final : public TransferDataContainer |
56 | | { |
57 | | public: |
58 | | OColumnTransferable(ColumnTransferFormatFlags nFormats); |
59 | | |
60 | | /** construct the transferable from a data access descriptor |
61 | | |
62 | | Note that some of the aspects, in particular all which cannot be represented |
63 | | as string, can only be transported via the CTF_COLUMN_DESCRIPTOR format. |
64 | | |
65 | | @param rDescriptor |
66 | | The descriptor for the column. It must contain at least |
67 | | <ul><li>information sufficient to create a connection, that is, either one of DataSource, DatabaseLocation, |
68 | | ConnectionResource, and DataAccessDescriptorProperty::Connection</li> |
69 | | <li>a Command</li> |
70 | | <li>a CommandType</li> |
71 | | <li>a ColumnName or ColumnObject</li> |
72 | | </ul> |
73 | | */ |
74 | | void setDescriptor(const ODataAccessDescriptor& rDescriptor); |
75 | | |
76 | | |
77 | | /** construct the transferable from a DatabaseForm component and a field name |
78 | | |
79 | | @param _rxForm |
80 | | the form which is bound to the data source which's field is to be dragged |
81 | | |
82 | | @param _rFieldName |
83 | | the name of the field to be dragged |
84 | | |
85 | | @param _rxColumn |
86 | | the column object. Won't be used if <arg>_nFormats</arg> does not include the CTF_COLUMN_DESCRIPTOR |
87 | | flag.<br/> |
88 | | May be <NULL/>. |
89 | | |
90 | | @param _rxConnection |
91 | | the connection the column belongs to. Won't be used if <arg>_nFormats</arg> does not include the CTF_COLUMN_DESCRIPTOR |
92 | | flag.<br/> |
93 | | May be <NULL/>. |
94 | | |
95 | | @param _nFormats |
96 | | supported formats. Must be a combination of the CTF_XXX flags |
97 | | */ |
98 | | OColumnTransferable( |
99 | | const css::uno::Reference< css::beans::XPropertySet >& _rxForm, |
100 | | const OUString& _rFieldName, |
101 | | const css::uno::Reference< css::beans::XPropertySet >& _rxColumn, |
102 | | const css::uno::Reference< css::sdbc::XConnection >& _rxConnection, |
103 | | ColumnTransferFormatFlags _nFormats |
104 | | ); |
105 | | |
106 | | /** checks whether or not a column descriptor can be extracted from the data flavor vector given |
107 | | @param _rFlavors |
108 | | available flavors |
109 | | @param _nFormats |
110 | | formats to accept |
111 | | */ |
112 | | static bool canExtractColumnDescriptor(const DataFlavorExVector& _rFlavors, ColumnTransferFormatFlags _nFormats); |
113 | | |
114 | | /** extracts a column descriptor from the transferable given |
115 | | */ |
116 | | static bool extractColumnDescriptor( |
117 | | const TransferableDataHelper& _rData |
118 | | ,OUString& _rDatasource |
119 | | ,OUString& _rDatabaseLocation |
120 | | ,OUString& _rConnectionResource |
121 | | ,sal_Int32& _nCommandType |
122 | | ,OUString& _rCommand |
123 | | ,OUString& _rFieldName |
124 | | ); |
125 | | |
126 | | /** extracts a column descriptor from the transferable given |
127 | | */ |
128 | | static ODataAccessDescriptor |
129 | | extractColumnDescriptor(const TransferableDataHelper& _rData); |
130 | | |
131 | | private: |
132 | | // TransferableHelper overridables |
133 | | virtual void AddSupportedFormats() override; |
134 | | virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override; |
135 | | |
136 | | static SotClipboardFormatId getDescriptorFormatId(); |
137 | | |
138 | | SVX_DLLPRIVATE void implConstruct( |
139 | | const OUString& _rDatasource |
140 | | ,const OUString& _rConnectionResource |
141 | | ,const sal_Int32 _nCommandType |
142 | | ,const OUString& _rCommand |
143 | | ,const OUString& _rFieldName |
144 | | ); |
145 | | |
146 | | ODataAccessDescriptor m_aDescriptor; |
147 | | OUString m_sCompatibleFormat; |
148 | | ColumnTransferFormatFlags m_nFormatFlags; |
149 | | }; |
150 | | |
151 | | |
152 | | //= ODataAccessObjectTransferable |
153 | | |
154 | | /** class for transferring data access objects (tables, queries, statements ...) |
155 | | */ |
156 | | class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC ODataAccessObjectTransferable : public TransferDataContainer |
157 | | { |
158 | | ODataAccessDescriptor m_aDescriptor; |
159 | | OUString m_sCompatibleObjectDescription; |
160 | | // needed to provide a SotClipboardFormatId::SBA_DATAEXCHANGE format |
161 | | |
162 | | public: |
163 | | /** should be used copying and the connection is needed. |
164 | | @param _rDatasource |
165 | | The data source name. |
166 | | @param _nCommandType |
167 | | The kind of command. @see com.sun.star.sdbc.CommandType |
168 | | @param _rCommand |
169 | | The command, either a name of a table or query or a SQL statement. |
170 | | */ |
171 | | void Update( |
172 | | const OUString& _rDatasource, |
173 | | const sal_Int32 _nCommandType, |
174 | | const OUString& _rCommand, |
175 | | const css::uno::Reference< css::sdbc::XConnection >& _rxConnection |
176 | | ); |
177 | | |
178 | | /** should be used when copying a query object and no connection is available. |
179 | | @param _rDatasource |
180 | | The data source name. |
181 | | @param _nCommandType |
182 | | The kind of command. @see com.sun.star.sdbc.CommandType |
183 | | @param _rCommand |
184 | | The command, either a name of a table or query or a SQL statement. |
185 | | */ |
186 | | void Update( |
187 | | const OUString& _rDatasource, |
188 | | const sal_Int32 _nCommandType, |
189 | | const OUString& _rCommand |
190 | | ); |
191 | | |
192 | | /** with this ctor, only the object descriptor format will be provided |
193 | | */ |
194 | | ODataAccessObjectTransferable( |
195 | | const css::uno::Reference< css::beans::XPropertySet >& _rxLivingForm |
196 | | ); |
197 | | |
198 | | ODataAccessObjectTransferable(); |
199 | | |
200 | | /** checks whether or not an object descriptor can be extracted from the data flavor vector given |
201 | | @param _rFlavors |
202 | | available flavors |
203 | | @param _nFormats |
204 | | formats to accept |
205 | | */ |
206 | | static bool canExtractObjectDescriptor(const DataFlavorExVector& _rFlavors); |
207 | | |
208 | | /** extracts an object descriptor from the transferable given |
209 | | */ |
210 | | static ODataAccessDescriptor |
211 | | extractObjectDescriptor(const TransferableDataHelper& _rData); |
212 | | |
213 | | protected: |
214 | | virtual void AddSupportedFormats() override; |
215 | | virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override; |
216 | | virtual void ObjectReleased() override; |
217 | | |
218 | | protected: |
219 | 0 | const ODataAccessDescriptor& getDescriptor() const { return m_aDescriptor; } |
220 | 0 | ODataAccessDescriptor& getDescriptor() { return m_aDescriptor; } |
221 | | protected: |
222 | | void addCompatibleSelectionDescription( |
223 | | const css::uno::Sequence< css::uno::Any >& _rSelRows |
224 | | ); |
225 | | // normally, a derived class could simply access getDescriptor[DataAccessDescriptorProperty::Selection] and place the sequence therein |
226 | | // but unfortunately, we have this damned compatible format, and this can't be accessed in |
227 | | // derived classes (our class is the only one which should be contaminated with this) |
228 | | |
229 | | private: |
230 | | SVX_DLLPRIVATE void construct( const OUString& _rDatasourceOrLocation |
231 | | ,const OUString& _rConnectionResource |
232 | | ,const sal_Int32 _nCommandType |
233 | | ,const OUString& _rCommand |
234 | | ,const css::uno::Reference< css::sdbc::XConnection >& _rxConnection |
235 | | ,bool _bAddCommand |
236 | | ,const OUString& _sActiveCommand); |
237 | | }; |
238 | | |
239 | | |
240 | | //= OMultiColumnTransferable |
241 | | |
242 | | /** class for transferring multiple columns |
243 | | */ |
244 | | class SAL_WARN_UNUSED UNLESS_MERGELIBS_MORE(SVXCORE_DLLPUBLIC) OMultiColumnTransferable final : public TransferDataContainer |
245 | | { |
246 | | public: |
247 | | OMultiColumnTransferable(); |
248 | | |
249 | | void setDescriptors(const css::uno::Sequence< css::beans::PropertyValue >& rDescriptors); |
250 | | |
251 | | /** checks whether or not an object descriptor can be extracted from the data flavor vector given |
252 | | @param _rFlavors |
253 | | available flavors |
254 | | @param _nFormats |
255 | | formats to accept |
256 | | */ |
257 | | static bool canExtractDescriptor(const DataFlavorExVector& _rFlavors); |
258 | | |
259 | | /** extracts an object descriptor from the transferable given |
260 | | */ |
261 | | static css::uno::Sequence< css::beans::PropertyValue > extractDescriptor(const TransferableDataHelper& _rData); |
262 | | |
263 | | private: |
264 | | virtual void AddSupportedFormats() override; |
265 | | virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override; |
266 | | virtual void ObjectReleased() override; |
267 | | static SotClipboardFormatId getDescriptorFormatId(); |
268 | | |
269 | | css::uno::Sequence< css::beans::PropertyValue > m_aDescriptors; |
270 | | }; |
271 | | |
272 | | |
273 | | } |
274 | | |
275 | | |
276 | | #endif // INCLUDED_SVX_DBAEXCHANGE_HXX |
277 | | |
278 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |