1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef DBUI_TABLECOPYHELPER_HXX
28 #define DBUI_TABLECOPYHELPER_HXX
29 
30 #ifndef DBAUI_APPELEMENTTYPE_HXX
31 #include "AppElementType.hxx"
32 #endif
33 #ifndef _DBAUI_COMMON_TYPES_HXX_
34 #include "commontypes.hxx"
35 #endif
36 #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
37 #include <svx/dataaccessdescriptor.hxx>
38 #endif
39 #ifndef _SOT_STORAGE_HXX
40 #include <sot/storage.hxx>
41 #endif
42 #ifndef _TRANSFER_HXX
43 #include <svtools/transfer.hxx>
44 #endif
45 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
46 #include <com/sun/star/sdbc/XConnection.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
49 #include <com/sun/star/sdbc/XResultSet.hpp>
50 #endif
51 #include <functional>
52 
53 class SvLBoxEntry;
54 //........................................................................
55 namespace dbaui
56 {
57 //........................................................................
58     class OGenericUnoController;
59     /// unary_function Functor object for class DataFlavorExVector::value_type returntype is bool
60     struct TAppSupportedSotFunctor : ::std::unary_function<DataFlavorExVector::value_type,bool>
61     {
62 	    ElementType	eEntryType;
63 	    sal_Bool	bQueryDrop;
64 	    TAppSupportedSotFunctor(const ElementType& _eEntryType,sal_Bool _bQueryDrop)
65 		    : eEntryType(_eEntryType)
66 		    , bQueryDrop(_bQueryDrop)
67 	    {
68 	    }
69 
70 	    inline bool operator()(const DataFlavorExVector::value_type& _aType)
71 	    {
72 		    switch (_aType.mnSotId)
73 		    {
74 			    case SOT_FORMAT_RTF:					// RTF data descriptions
75 			    case SOT_FORMATSTR_ID_HTML:				// HTML data descriptions
76 			    case SOT_FORMATSTR_ID_DBACCESS_TABLE:	// table descriptor
77 				    return (E_TABLE == eEntryType);
78 			    case SOT_FORMATSTR_ID_DBACCESS_QUERY:	// query descriptor
79 			    case SOT_FORMATSTR_ID_DBACCESS_COMMAND:	// SQL command
80 				    return ((E_QUERY == eEntryType) || ( !bQueryDrop && E_TABLE == eEntryType));
81 		    }
82 		    return false;
83 	    }
84     };
85 
86     class OTableCopyHelper
87     {
88 	private:
89         OGenericUnoController*  m_pController;
90 		::rtl::OUString		    m_sTableNameForAppend;
91 
92     public:
93         // is needed to describe the drop target
94 		struct DropDescriptor
95 		{
96 			::svx::ODataAccessDescriptor	aDroppedData;
97 			//dyf add 20070601
98 			//for transfor the tablename
99 			::rtl::OUString                 sDefaultTableName;
100 			//dyf add end
101 			String							aUrl;
102 			SotStorageStreamRef				aHtmlRtfStorage;
103 			ElementType						nType;
104             SvLBoxEntry*                    pDroppedAt;
105 			sal_Int8						nAction;
106 			sal_Bool						bHtml;
107 			sal_Bool						bError;
108 
109 			DropDescriptor() : nType(E_TABLE),pDroppedAt(NULL),nAction(DND_ACTION_NONE) { }
110 		};
111 
112         OTableCopyHelper(OGenericUnoController* _pControler);
113 
114         /** pastes a table into the data source
115 			@param	_rPasteData
116 				The data helper.
117             @param	_sDestDataSourceName
118 				The name of the dest data source.
119 		*/
120 		void pasteTable( const TransferableDataHelper& _rTransData
121                         ,const ::rtl::OUString& _sDestDataSourceName
122                         ,const SharedConnection& _xConnection);
123 
124         /** pastes a table into the data source
125 			@param	_nFormatId
126 				The format which should be copied.
127 			@param	_rPasteData
128 				The data helper.
129             @param	_sDestDataSourceName
130 				The name of the dest data source.
131 		*/
132 		void pasteTable( SotFormatStringId _nFormatId
133                         ,const TransferableDataHelper& _rTransData
134                         ,const ::rtl::OUString& _sDestDataSourceName
135                         ,const SharedConnection& _xConnection);
136 
137 		/** copies a table which was constructed by tags like HTML or RTF
138 			@param	_rDesc
139 				The Drop descriptor
140 			@param	_bCheck
141 				If set to <TRUE/> than the controller checks only if a copy is possible.
142             @param  _xConnection
143                 The connection
144 		*/
145 		sal_Bool copyTagTable(  DropDescriptor& _rDesc,
146                                 sal_Bool _bCheck,
147                                 const SharedConnection& _xConnection);
148 
149         /** copies a table which was constructed by tags like HTML or RTF
150 			@param	_rDesc
151 				The Drop descriptor
152 			@param	_bCheck
153 				If set to <TRUE/> than the controller checks only if a copy is possible.
154             @param  _xConnection
155                 The connection
156 		*/
157 		void asyncCopyTagTable(  DropDescriptor& _rDesc
158                                 ,const ::rtl::OUString& _sDestDataSourceName
159                                 ,const SharedConnection& _xConnection);
160 
161         /** copies a table which was constructed by tags like HTML or RTF
162             @param  _aDroppedData
163                 The dropped data
164 			@param	_rDesc
165 				IN/OUT parameter
166             @param  _xConnection
167                 The connection
168 		*/
169         sal_Bool copyTagTable(const TransferableDataHelper& _aDroppedData,
170                               DropDescriptor& _rAsyncDrop,
171                               const SharedConnection& _xConnection);
172 
173         /// returns <TRUE/> if the clipboard supports a table format, otherwise <FALSE/>.
174 		sal_Bool isTableFormat(const TransferableDataHelper& _rClipboard) const;
175 
176         inline void                     SetTableNameForAppend( const ::rtl::OUString& _rDefaultTableName ) { m_sTableNameForAppend = _rDefaultTableName; }
177         inline void                     ResetTableNameForAppend() { SetTableNameForAppend( ::rtl::OUString() ); }
178 		inline const ::rtl::OUString&   GetTableNameForAppend() const { return m_sTableNameForAppend ;}
179 
180     private:
181 		/** pastes a table into the data source
182 			@param	_rPasteData
183 				The data descriptor.
184             @param	_sDestDataSourceName
185 				The name of the dest data source.
186 		*/
187 		void pasteTable(
188             const ::svx::ODataAccessDescriptor& _rPasteData,
189             const ::rtl::OUString& _sDestDataSourceName,
190             const SharedConnection& _xDestConnection
191         );
192 
193 		/** insert a table into the data source. The source can eihter be a table or a query
194 		*/
195 		void insertTable(
196 			const ::rtl::OUString& i_rSourceDataSource,
197 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& i_rSourceConnection,
198 			const ::rtl::OUString& i_rCommand,
199             const sal_Int32 i_nCommandType,
200             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >& i_rSourceRows,
201 			const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& i_rSelection,
202 			const sal_Bool i_bBookmarkSelection,
203             const ::rtl::OUString& i_rDestDataSource,
204             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& i_rDestConnection
205         );
206 
207     };
208 //........................................................................
209 }	// namespace dbaui
210 //........................................................................
211 #endif // DBUI_TABLECOPYHELPER_HXX
212 
213