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 _SVX_DBAEXCHANGE_HXX_
21 #define _SVX_DBAEXCHANGE_HXX_
23 #include <svtools/transfer.hxx>
24 #include <comphelper/stl_types.hxx>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/sdbc/XConnection.hpp>
27 #include <svx/dataaccessdescriptor.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include "svx/svxdllapi.h"
31 //........................................................................
34 //........................................................................
36 // column transfer formats
37 #define CTF_FIELD_DESCRIPTOR 0x0001 // the field descriptor format
38 #define CTF_CONTROL_EXCHANGE 0x0002 // the control exchange format
39 #define CTF_COLUMN_DESCRIPTOR 0x0004 // data access descriptor for a column
41 //====================================================================
42 //= OColumnTransferable
43 //====================================================================
44 class SVX_DLLPUBLIC OColumnTransferable
: public TransferableHelper
47 ODataAccessDescriptor m_aDescriptor
;
48 OUString m_sCompatibleFormat
;
49 sal_Int32 m_nFormatFlags
;
52 /** construct the transferable
55 const OUString
& _rDatasource
56 ,const OUString
& _rConnectionResource
57 ,const sal_Int32 _nCommandType
58 ,const OUString
& _rCommand
59 ,const OUString
& _rFieldName
63 /** construct the transferable from a data access descriptor
65 Note that some of the aspects, in particular all which cannot be represented
66 as string, can only be transported via the CTF_COLUMN_DESCRIPTOR format.
69 The descriptor for the column. It must contain at least
70 <ul><li>information sufficient to create a connection, that is, either one of DataSource, DatabaseLocation,
71 ConnectionResource, and daConnection</li>
73 <li>a CommandType</li>
74 <li>a ColumnName or ColumnObject</li>
78 const ODataAccessDescriptor
& _rDescriptor
,
82 /** construct the transferable from a DatabaseForm component and a field name
85 the form which is bound to the data source which's field is to be dragged
88 the name of the field to be dragged
91 the column object. Won't be used if <arg>_nFormats</arg> does not include the CTF_COLUMN_DESCRIPTOR
96 the connection the column belongs to. Won't be used if <arg>_nFormats</arg> does not include the CTF_COLUMN_DESCRIPTOR
101 supported formats. Must be a combination of the CTF_XXX flags
104 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxForm
,
105 const OUString
& _rFieldName
,
106 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxColumn
,
107 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _rxConnection
,
111 /** checks whether or not a column descriptor can be extracted from the data flavor vector given
117 static sal_Bool
canExtractColumnDescriptor(const DataFlavorExVector
& _rFlavors
, sal_Int32 _nFormats
);
119 /** extracts a column descriptor from the transferable given
121 static sal_Bool
extractColumnDescriptor(
122 const TransferableDataHelper
& _rData
123 ,OUString
& _rDatasource
124 ,OUString
& _rDatabaseLocation
125 ,OUString
& _rConnectionResource
126 ,sal_Int32
& _nCommandType
128 ,OUString
& _rFieldName
131 /** extracts a column descriptor from the transferable given
133 static ODataAccessDescriptor
134 extractColumnDescriptor(const TransferableDataHelper
& _rData
);
136 /** adds the data contained in the object to the given data container
137 <p>This method helps you treating this class as simple container class:<br/>
138 At the moment, it is a data container and a transferable.
139 Using <method>addDataToContainer</method>, you can treat the class as dumb data container,
140 doing the Drag'n'Drop with a <type>TransferDataContainer</type> instance (which may contain
141 additional formats)</p>
143 split this class into a two separate classes: one for the data container aspect, one for
146 void addDataToContainer( TransferDataContainer
* _pContainer
);
149 // TransferableHelper overridables
150 virtual void AddSupportedFormats();
151 virtual sal_Bool
GetData( const ::com::sun::star::datatransfer::DataFlavor
& rFlavor
);
153 static sal_uInt32
getDescriptorFormatId();
156 SVX_DLLPRIVATE
void implConstruct(
157 const OUString
& _rDatasource
158 ,const OUString
& _rConnectionResource
159 ,const sal_Int32 _nCommandType
160 ,const OUString
& _rCommand
161 ,const OUString
& _rFieldName
165 //====================================================================
166 //= ODataAccessObjectTransferable
167 //====================================================================
168 /** class for transfering data access objects (tables, queries, statements ...)
170 class SVX_DLLPUBLIC ODataAccessObjectTransferable
: public TransferableHelper
172 ODataAccessDescriptor m_aDescriptor
;
173 OUString m_sCompatibleObjectDescription
;
174 // needed to provide a SOT_FORMATSTR_ID_SBA_DATAEXCHANGE format
177 /** should be used copying and the connection is needed.
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 OUString
& _rConnectionResource
188 ,const sal_Int32 _nCommandType
189 ,const OUString
& _rCommand
190 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _rxConnection
193 /** should be used when copying a query object and no connection is available.
195 The data source name.
197 The kind of command. @see com.sun.star.sdbc.CommandType
199 The command, either a name of a table or query or a SQL statement.
201 ODataAccessObjectTransferable(
202 const OUString
& _rDatasourceOrLocation
203 ,const OUString
& _rConnectionResource
204 ,const sal_Int32 _nCommandType
205 ,const OUString
& _rCommand
208 /** with this ctor, only the object descriptor format will be provided
210 ODataAccessObjectTransferable(
211 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxLivingForm
214 /** checks whether or not an object descriptor can be extracted from the data flavor vector given
220 static sal_Bool
canExtractObjectDescriptor(const DataFlavorExVector
& _rFlavors
);
222 /** extracts a object descriptor from the transferable given
224 static ODataAccessDescriptor
225 extractObjectDescriptor(const TransferableDataHelper
& _rData
);
228 virtual void AddSupportedFormats();
229 virtual sal_Bool
GetData( const ::com::sun::star::datatransfer::DataFlavor
& rFlavor
);
230 virtual void ObjectReleased();
233 const ODataAccessDescriptor
& getDescriptor() const { return m_aDescriptor
; }
234 ODataAccessDescriptor
& getDescriptor() { return m_aDescriptor
; }
236 void addCompatibleSelectionDescription(
237 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& _rSelRows
239 // normally, a derived class could simply access getDescriptor[daSelection] and place the sequence therein
240 // but unfortunately, we have this damned compatible format, and this can't be accessed in
241 // derived classes (our class is the only one which should be contaminated with this)
244 SVX_DLLPRIVATE
void construct( const OUString
& _rDatasourceOrLocation
245 ,const OUString
& _rConnectionResource
246 ,const sal_Int32 _nCommandType
247 ,const OUString
& _rCommand
248 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _rxConnection
249 ,sal_Bool _bAddCommand
250 ,const OUString
& _sActiveCommand
);
253 //====================================================================
254 //= OMultiColumnTransferable
255 //====================================================================
256 /** class for transfering multiple columns
258 class SVX_DLLPUBLIC OMultiColumnTransferable
: public TransferableHelper
260 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> m_aDescriptors
;
263 OMultiColumnTransferable(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aDescriptors
);
265 /** checks whether or not an object descriptor can be extracted from the data flavor vector given
271 static sal_Bool
canExtractDescriptor(const DataFlavorExVector
& _rFlavors
);
273 /** extracts a object descriptor from the transferable given
275 static ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> extractDescriptor(const TransferableDataHelper
& _rData
);
278 virtual void AddSupportedFormats();
279 virtual sal_Bool
GetData( const ::com::sun::star::datatransfer::DataFlavor
& rFlavor
);
280 virtual void ObjectReleased();
281 static sal_uInt32
getDescriptorFormatId();
284 //........................................................................
286 //........................................................................
288 #endif // _SVX_DBAEXCHANGE_HXX_
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */