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 #ifndef DBUI_TABLECOPYHELPER_HXX
24 #define DBUI_TABLECOPYHELPER_HXX
25 
26 #ifndef DBAUI_APPELEMENTTYPE_HXX
27 #include "AppElementType.hxx"
28 #endif
29 #ifndef _DBAUI_COMMON_TYPES_HXX_
30 #include "commontypes.hxx"
31 #endif
32 #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
33 #include <svx/dataaccessdescriptor.hxx>
34 #endif
35 #ifndef _SOT_STORAGE_HXX
36 #include <sot/storage.hxx>
37 #endif
38 #ifndef _TRANSFER_HXX
39 #include <svtools/transfer.hxx>
40 #endif
41 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
42 #include <com/sun/star/sdbc/XConnection.hpp>
43 #endif
44 #ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
45 #include <com/sun/star/sdbc/XResultSet.hpp>
46 #endif
47 #include <functional>
48 
49 class SvLBoxEntry;
50 //........................................................................
51 namespace dbaui
52 {
53 //........................................................................
54     class OGenericUnoController;
55     /// unary_function Functor object for class DataFlavorExVector::value_type returntype is bool
56     struct TAppSupportedSotFunctor : ::std::unary_function<DataFlavorExVector::value_type,bool>
57     {
58 	    ElementType	eEntryType;
59 	    sal_Bool	bQueryDrop;
TAppSupportedSotFunctordbaui::TAppSupportedSotFunctor60 	    TAppSupportedSotFunctor(const ElementType& _eEntryType,sal_Bool _bQueryDrop)
61 		    : eEntryType(_eEntryType)
62 		    , bQueryDrop(_bQueryDrop)
63 	    {
64 	    }
65 
operator ()dbaui::TAppSupportedSotFunctor66 	    inline bool operator()(const DataFlavorExVector::value_type& _aType)
67 	    {
68 		    switch (_aType.mnSotId)
69 		    {
70 			    case SOT_FORMAT_RTF:					// RTF data descriptions
71 			    case SOT_FORMATSTR_ID_HTML:				// HTML data descriptions
72 			    case SOT_FORMATSTR_ID_DBACCESS_TABLE:	// table descriptor
73 				    return (E_TABLE == eEntryType);
74 			    case SOT_FORMATSTR_ID_DBACCESS_QUERY:	// query descriptor
75 			    case SOT_FORMATSTR_ID_DBACCESS_COMMAND:	// SQL command
76 				    return ((E_QUERY == eEntryType) || ( !bQueryDrop && E_TABLE == eEntryType));
77 		    }
78 		    return false;
79 	    }
80     };
81 
82     class OTableCopyHelper
83     {
84 	private:
85         OGenericUnoController*  m_pController;
86 		::rtl::OUString		    m_sTableNameForAppend;
87 
88     public:
89         // is needed to describe the drop target
90 		struct DropDescriptor
91 		{
92 			::svx::ODataAccessDescriptor	aDroppedData;
93 			//dyf add 20070601
94 			//for transfor the tablename
95 			::rtl::OUString                 sDefaultTableName;
96 			//dyf add end
97 			String							aUrl;
98 			SotStorageStreamRef				aHtmlRtfStorage;
99 			ElementType						nType;
100             SvLBoxEntry*                    pDroppedAt;
101 			sal_Int8						nAction;
102 			sal_Bool						bHtml;
103 			sal_Bool						bError;
104 
DropDescriptordbaui::OTableCopyHelper::DropDescriptor105 			DropDescriptor() : nType(E_TABLE),pDroppedAt(NULL),nAction(DND_ACTION_NONE) { }
106 		};
107 
108         OTableCopyHelper(OGenericUnoController* _pControler);
109 
110         /** pastes a table into the data source
111 			@param	_rPasteData
112 				The data helper.
113             @param	_sDestDataSourceName
114 				The name of the dest data source.
115 		*/
116 		void pasteTable( const TransferableDataHelper& _rTransData
117                         ,const ::rtl::OUString& _sDestDataSourceName
118                         ,const SharedConnection& _xConnection);
119 
120         /** pastes a table into the data source
121 			@param	_nFormatId
122 				The format which should be copied.
123 			@param	_rPasteData
124 				The data helper.
125             @param	_sDestDataSourceName
126 				The name of the dest data source.
127 		*/
128 		void pasteTable( SotFormatStringId _nFormatId
129                         ,const TransferableDataHelper& _rTransData
130                         ,const ::rtl::OUString& _sDestDataSourceName
131                         ,const SharedConnection& _xConnection);
132 
133 		/** copies a table which was constructed by tags like HTML or RTF
134 			@param	_rDesc
135 				The Drop descriptor
136 			@param	_bCheck
137 				If set to <TRUE/> than the controller checks only if a copy is possible.
138             @param  _xConnection
139                 The connection
140 		*/
141 		sal_Bool copyTagTable(  DropDescriptor& _rDesc,
142                                 sal_Bool _bCheck,
143                                 const SharedConnection& _xConnection);
144 
145         /** copies a table which was constructed by tags like HTML or RTF
146 			@param	_rDesc
147 				The Drop descriptor
148 			@param	_bCheck
149 				If set to <TRUE/> than the controller checks only if a copy is possible.
150             @param  _xConnection
151                 The connection
152 		*/
153 		void asyncCopyTagTable(  DropDescriptor& _rDesc
154                                 ,const ::rtl::OUString& _sDestDataSourceName
155                                 ,const SharedConnection& _xConnection);
156 
157         /** copies a table which was constructed by tags like HTML or RTF
158             @param  _aDroppedData
159                 The dropped data
160 			@param	_rDesc
161 				IN/OUT parameter
162             @param  _xConnection
163                 The connection
164 		*/
165         sal_Bool copyTagTable(const TransferableDataHelper& _aDroppedData,
166                               DropDescriptor& _rAsyncDrop,
167                               const SharedConnection& _xConnection);
168 
169         /// returns <TRUE/> if the clipboard supports a table format, otherwise <FALSE/>.
170 		sal_Bool isTableFormat(const TransferableDataHelper& _rClipboard) const;
171 
SetTableNameForAppend(const::rtl::OUString & _rDefaultTableName)172         inline void                     SetTableNameForAppend( const ::rtl::OUString& _rDefaultTableName ) { m_sTableNameForAppend = _rDefaultTableName; }
ResetTableNameForAppend()173         inline void                     ResetTableNameForAppend() { SetTableNameForAppend( ::rtl::OUString() ); }
GetTableNameForAppend() const174 		inline const ::rtl::OUString&   GetTableNameForAppend() const { return m_sTableNameForAppend ;}
175 
176     private:
177 		/** pastes a table into the data source
178 			@param	_rPasteData
179 				The data descriptor.
180             @param	_sDestDataSourceName
181 				The name of the dest data source.
182 		*/
183 		void pasteTable(
184             const ::svx::ODataAccessDescriptor& _rPasteData,
185             const ::rtl::OUString& _sDestDataSourceName,
186             const SharedConnection& _xDestConnection
187         );
188 
189 		/** insert a table into the data source. The source can eihter be a table or a query
190 		*/
191 		void insertTable(
192 			const ::rtl::OUString& i_rSourceDataSource,
193 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& i_rSourceConnection,
194 			const ::rtl::OUString& i_rCommand,
195             const sal_Int32 i_nCommandType,
196             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >& i_rSourceRows,
197 			const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& i_rSelection,
198 			const sal_Bool i_bBookmarkSelection,
199             const ::rtl::OUString& i_rDestDataSource,
200             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& i_rDestConnection
201         );
202 
203     };
204 //........................................................................
205 }	// namespace dbaui
206 //........................................................................
207 #endif // DBUI_TABLECOPYHELPER_HXX
208 
209