xref: /aoo4110/main/svx/inc/svx/dbaexchange.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SVX_DBAEXCHANGE_HXX_
25 #define _SVX_DBAEXCHANGE_HXX_
26 
27 #include <svtools/transfer.hxx>
28 #include <comphelper/stl_types.hxx>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/sdbc/XConnection.hpp>
31 #include <svx/dataaccessdescriptor.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
33 #include "svx/svxdllapi.h"
34 
35 //........................................................................
36 namespace svx
37 {
38 //........................................................................
39 
40 // column transfer formats
41 #define CTF_FIELD_DESCRIPTOR		0x0001		// the field descriptor format
42 #define CTF_CONTROL_EXCHANGE		0x0002		// the control exchange format
43 #define CTF_COLUMN_DESCRIPTOR		0x0004		// data access descriptor for a column
44 
45 	//====================================================================
46 	//= OColumnTransferable
47 	//====================================================================
48 	class SVX_DLLPUBLIC OColumnTransferable : public TransferableHelper
49 	{
50 	protected:
51 		ODataAccessDescriptor	m_aDescriptor;
52 		::rtl::OUString			m_sCompatibleFormat;
53 		sal_Int32				m_nFormatFlags;
54 
55 	public:
56 		/** construct the transferable
57 		*/
58 		OColumnTransferable(
59 			 const ::rtl::OUString&	_rDatasource
60 			,const ::rtl::OUString& _rConnectionResource
61 			,const sal_Int32		_nCommandType
62 			,const ::rtl::OUString&	_rCommand
63 			,const ::rtl::OUString&	_rFieldName
64 			,sal_Int32	_nFormats
65 		);
66 
67 		/** construct the transferable from a data access descriptor
68 
69             Note that some of the aspects, in particular all which cannot be represented
70             as string, can only be transported via the CTF_COLUMN_DESCRIPTOR format.
71 
72         @param _rDescriptor
73             The descriptor for the column. It must contain at least
74             <ul><li>information sufficient to create a connection, that is, either one of DataSource, DatabaseLocation,
75                     ConnectionResource, and daConnection</li>
76                 <li>a Command</li>
77                 <li>a CommandType</li>
78                 <li>a ColumnName or ColumnObject</li>
79             </ul>
80 		*/
81 		OColumnTransferable(
82             const ODataAccessDescriptor& _rDescriptor,
83 			sal_Int32                    _nFormats
84 		);
85 
86 		/** construct the transferable from a DatabaseForm component and a field name
87 
88 			@param _rxForm
89 				the form which is bound to the data source which's field is to be dragged
90 
91 			@param _rFieldName
92 				the name of the field to be dragged
93 
94 			@param _rxColumn
95 				the column object. Won't be used if <arg>_nFormats</arg> does not include the CTF_COLUMN_DESCRIPTOR
96 				flag.<br/>
97 				May be <NULL/>.
98 
99 			@param _rxConnection
100 				the connection the column belongs to. Won't be used if <arg>_nFormats</arg> does not include the CTF_COLUMN_DESCRIPTOR
101 				flag.<br/>
102 				May be <NULL/>.
103 
104 			@param _nFormats
105 				supported formats. Must be a combination of the CTF_XXX flags
106 		*/
107 		OColumnTransferable(
108 			const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxForm,
109 			const ::rtl::OUString& _rFieldName,
110 			const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn,
111 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
112 			sal_Int32	_nFormats
113 		);
114 
115 		/** checks whether or not a column descriptor can be extracted from the data flavor vector given
116 			@param _rFlavors
117 				available flavors
118 			@param _nFormats
119 				formats to accept
120 		*/
121 		static sal_Bool canExtractColumnDescriptor(const DataFlavorExVector& _rFlavors, sal_Int32 _nFormats);
122 
123 		/** extracts a column descriptor from the transferable given
124 		*/
125 		static sal_Bool extractColumnDescriptor(
126 			 const TransferableDataHelper&	_rData
127 			,::rtl::OUString&				_rDatasource
128 			,::rtl::OUString&				_rDatabaseLocation
129 			,::rtl::OUString&				_rConnectionResource
130 			,sal_Int32&						_nCommandType
131 			,::rtl::OUString&				_rCommand
132 			,::rtl::OUString&				_rFieldName
133 		);
134 
135 		/** extracts a column descriptor from the transferable given
136 		*/
137 		static ODataAccessDescriptor
138 						extractColumnDescriptor(const TransferableDataHelper& _rData);
139 
140 		/** adds the data contained in the object to the given data container
141 			<p>This method helps you treating this class as simple container class:<br/>
142 			At the moment, it is a data container and a transferable.
143 			Using <method>addDataToContainer</method>, you can treat the class as dumb data container,
144 			doing the Drag'n'Drop with a <type>TransferDataContainer</type> instance (which may contain
145 			additional formats)</p>
146 			@TODO
147 				split this class into a two separate classes: one for the data container aspect, one for
148 				the transfer aspect
149 		*/
150 		void addDataToContainer( TransferDataContainer* _pContainer );
151 
152 	protected:
153 		// TransferableHelper overridables
154 		virtual void		AddSupportedFormats();
155 		virtual sal_Bool	GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
156 
157 		static sal_uInt32	getDescriptorFormatId();
158 
159 	private:
160 		SVX_DLLPRIVATE void implConstruct(
161 			const ::rtl::OUString&	_rDatasource
162 			,const ::rtl::OUString& _rConnectionResource
163 			,const sal_Int32		_nCommandType
164 			,const ::rtl::OUString&	_rCommand
165 			,const ::rtl::OUString&	_rFieldName
166 		);
167 	};
168 
169 	//====================================================================
170 	//= ODataAccessObjectTransferable
171 	//====================================================================
172 	/** class for transfering data access objects (tables, queries, statements ...)
173 	*/
174 	class SVX_DLLPUBLIC ODataAccessObjectTransferable : public TransferableHelper
175 	{
176 		ODataAccessDescriptor	m_aDescriptor;
177 		::rtl::OUString			m_sCompatibleObjectDescription;
178 			// needed to provide a SOT_FORMATSTR_ID_SBA_DATAEXCHANGE format
179 
180 	public:
181 		/** should be used copying and the connection is needed.
182 			@param	_rDatasource
183 				The data source name.
184 			@param	_nCommandType
185 				The kind of command. @see com.sun.star.sdbc.CommandType
186 			@param	_rCommand
187 				The command, either a name of a table or query or a SQL statement.
188 		*/
189 		ODataAccessObjectTransferable(
190 			const ::rtl::OUString&	_rDatasourceOrLocation
191 			,const ::rtl::OUString& _rConnectionResource
192 			,const sal_Int32			_nCommandType
193 			,const ::rtl::OUString&	_rCommand
194 			,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection
195 		);
196 
197 		/** should be used when copying a query object and no connection is available.
198 			@param	_rDatasource
199 				The data source name.
200 			@param	_nCommandType
201 				The kind of command. @see com.sun.star.sdbc.CommandType
202 			@param	_rCommand
203 				The command, either a name of a table or query or a SQL statement.
204 		*/
205 		ODataAccessObjectTransferable(
206 			const ::rtl::OUString&	_rDatasourceOrLocation
207 			,const ::rtl::OUString& _rConnectionResource
208 			,const sal_Int32		_nCommandType
209 			,const ::rtl::OUString&	_rCommand
210 		);
211 
212 		/** with this ctor, only the object descriptor format will be provided
213 		*/
214 		ODataAccessObjectTransferable(
215 			const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxLivingForm
216 		);
217 
218 		/** checks whether or not an object descriptor can be extracted from the data flavor vector given
219 			@param _rFlavors
220 				available flavors
221 			@param _nFormats
222 				formats to accept
223 		*/
224 		static sal_Bool canExtractObjectDescriptor(const DataFlavorExVector& _rFlavors);
225 
226 		/** extracts a object descriptor from the transferable given
227 		*/
228 		static ODataAccessDescriptor
229 						extractObjectDescriptor(const TransferableDataHelper& _rData);
230 
231 	protected:
232 		virtual void		AddSupportedFormats();
233 		virtual sal_Bool	GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
234 		virtual void		ObjectReleased();
235 
236 	protected:
getDescriptor() const237 		const	ODataAccessDescriptor&	getDescriptor() const	{ return m_aDescriptor; }
getDescriptor()238 				ODataAccessDescriptor&	getDescriptor()			{ return m_aDescriptor; }
239 	protected:
240 		void	addCompatibleSelectionDescription(
241 			const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rSelRows
242 		);
243 			// normally, a derived class could simply access getDescriptor[daSelection] and place the sequence therein
244 			// but unfortunately, we have this damned compatible format, and this can't be accessed in
245 			// derived classes (our class is the only one which should be contaminated with this)
246 
247 	private:
248 		SVX_DLLPRIVATE void construct(	const ::rtl::OUString&	_rDatasourceOrLocation
249 						,const ::rtl::OUString& _rConnectionResource
250 						,const sal_Int32		_nCommandType
251 						,const ::rtl::OUString&	_rCommand
252 						,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection
253 						,sal_Bool _bAddCommand
254 						,const ::rtl::OUString& _sActiveCommand);
255 	};
256 
257     //====================================================================
258 	//= OMultiColumnTransferable
259 	//====================================================================
260 	/** class for transfering multiple columns
261 	*/
262 	class SVX_DLLPUBLIC OMultiColumnTransferable : public TransferableHelper
263 	{
264         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >	m_aDescriptors;
265 
266 	public:
267         OMultiColumnTransferable(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _aDescriptors);
268 
269         void push_back(ODataAccessDescriptor& _aDescriptor);
270 
271         /** checks whether or not an object descriptor can be extracted from the data flavor vector given
272 			@param _rFlavors
273 				available flavors
274 			@param _nFormats
275 				formats to accept
276 		*/
277 		static sal_Bool canExtractDescriptor(const DataFlavorExVector& _rFlavors);
278 
279 		/** extracts a object descriptor from the transferable given
280 		*/
281 		static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > extractDescriptor(const TransferableDataHelper& _rData);
282 
283 	protected:
284 		virtual void		AddSupportedFormats();
285 		virtual sal_Bool	GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
286         virtual void        ObjectReleased();
287         static sal_uInt32	getDescriptorFormatId();
288     };
289 
290 //........................................................................
291 }	// namespace svx
292 //........................................................................
293 
294 #endif // _SVX_DBAEXCHANGE_HXX_
295 
296