xref: /AOO41X/main/dbaccess/source/ui/inc/TableCopyHelper.hxx (revision 2e2212a7c22e96cf6f6fab0dd042c34a45a64bd6)
1*2e2212a7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2e2212a7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2e2212a7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2e2212a7SAndrew Rist  * distributed with this work for additional information
6*2e2212a7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2e2212a7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2e2212a7SAndrew Rist  * "License"); you may not use this file except in compliance
9*2e2212a7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2e2212a7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2e2212a7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2e2212a7SAndrew Rist  * software distributed under the License is distributed on an
15*2e2212a7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2e2212a7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2e2212a7SAndrew Rist  * specific language governing permissions and limitations
18*2e2212a7SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2e2212a7SAndrew Rist  *************************************************************/
21*2e2212a7SAndrew Rist 
22*2e2212a7SAndrew Rist 
23cdf0e10cSrcweir #ifndef DBUI_TABLECOPYHELPER_HXX
24cdf0e10cSrcweir #define DBUI_TABLECOPYHELPER_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #ifndef DBAUI_APPELEMENTTYPE_HXX
27cdf0e10cSrcweir #include "AppElementType.hxx"
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #ifndef _DBAUI_COMMON_TYPES_HXX_
30cdf0e10cSrcweir #include "commontypes.hxx"
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
33cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #ifndef _SOT_STORAGE_HXX
36cdf0e10cSrcweir #include <sot/storage.hxx>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #ifndef _TRANSFER_HXX
39cdf0e10cSrcweir #include <svtools/transfer.hxx>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
42cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
45cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #include <functional>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir class SvLBoxEntry;
50cdf0e10cSrcweir //........................................................................
51cdf0e10cSrcweir namespace dbaui
52cdf0e10cSrcweir {
53cdf0e10cSrcweir //........................................................................
54cdf0e10cSrcweir     class OGenericUnoController;
55cdf0e10cSrcweir     /// unary_function Functor object for class DataFlavorExVector::value_type returntype is bool
56cdf0e10cSrcweir     struct TAppSupportedSotFunctor : ::std::unary_function<DataFlavorExVector::value_type,bool>
57cdf0e10cSrcweir     {
58cdf0e10cSrcweir 	    ElementType	eEntryType;
59cdf0e10cSrcweir 	    sal_Bool	bQueryDrop;
TAppSupportedSotFunctordbaui::TAppSupportedSotFunctor60cdf0e10cSrcweir 	    TAppSupportedSotFunctor(const ElementType& _eEntryType,sal_Bool _bQueryDrop)
61cdf0e10cSrcweir 		    : eEntryType(_eEntryType)
62cdf0e10cSrcweir 		    , bQueryDrop(_bQueryDrop)
63cdf0e10cSrcweir 	    {
64cdf0e10cSrcweir 	    }
65cdf0e10cSrcweir 
operator ()dbaui::TAppSupportedSotFunctor66cdf0e10cSrcweir 	    inline bool operator()(const DataFlavorExVector::value_type& _aType)
67cdf0e10cSrcweir 	    {
68cdf0e10cSrcweir 		    switch (_aType.mnSotId)
69cdf0e10cSrcweir 		    {
70cdf0e10cSrcweir 			    case SOT_FORMAT_RTF:					// RTF data descriptions
71cdf0e10cSrcweir 			    case SOT_FORMATSTR_ID_HTML:				// HTML data descriptions
72cdf0e10cSrcweir 			    case SOT_FORMATSTR_ID_DBACCESS_TABLE:	// table descriptor
73cdf0e10cSrcweir 				    return (E_TABLE == eEntryType);
74cdf0e10cSrcweir 			    case SOT_FORMATSTR_ID_DBACCESS_QUERY:	// query descriptor
75cdf0e10cSrcweir 			    case SOT_FORMATSTR_ID_DBACCESS_COMMAND:	// SQL command
76cdf0e10cSrcweir 				    return ((E_QUERY == eEntryType) || ( !bQueryDrop && E_TABLE == eEntryType));
77cdf0e10cSrcweir 		    }
78cdf0e10cSrcweir 		    return false;
79cdf0e10cSrcweir 	    }
80cdf0e10cSrcweir     };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     class OTableCopyHelper
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir 	private:
85cdf0e10cSrcweir         OGenericUnoController*  m_pController;
86cdf0e10cSrcweir 		::rtl::OUString		    m_sTableNameForAppend;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     public:
89cdf0e10cSrcweir         // is needed to describe the drop target
90cdf0e10cSrcweir 		struct DropDescriptor
91cdf0e10cSrcweir 		{
92cdf0e10cSrcweir 			::svx::ODataAccessDescriptor	aDroppedData;
93cdf0e10cSrcweir 			//dyf add 20070601
94cdf0e10cSrcweir 			//for transfor the tablename
95cdf0e10cSrcweir 			::rtl::OUString                 sDefaultTableName;
96cdf0e10cSrcweir 			//dyf add end
97cdf0e10cSrcweir 			String							aUrl;
98cdf0e10cSrcweir 			SotStorageStreamRef				aHtmlRtfStorage;
99cdf0e10cSrcweir 			ElementType						nType;
100cdf0e10cSrcweir             SvLBoxEntry*                    pDroppedAt;
101cdf0e10cSrcweir 			sal_Int8						nAction;
102cdf0e10cSrcweir 			sal_Bool						bHtml;
103cdf0e10cSrcweir 			sal_Bool						bError;
104cdf0e10cSrcweir 
DropDescriptordbaui::OTableCopyHelper::DropDescriptor105cdf0e10cSrcweir 			DropDescriptor() : nType(E_TABLE),pDroppedAt(NULL),nAction(DND_ACTION_NONE) { }
106cdf0e10cSrcweir 		};
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         OTableCopyHelper(OGenericUnoController* _pControler);
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         /** pastes a table into the data source
111cdf0e10cSrcweir 			@param	_rPasteData
112cdf0e10cSrcweir 				The data helper.
113cdf0e10cSrcweir             @param	_sDestDataSourceName
114cdf0e10cSrcweir 				The name of the dest data source.
115cdf0e10cSrcweir 		*/
116cdf0e10cSrcweir 		void pasteTable( const TransferableDataHelper& _rTransData
117cdf0e10cSrcweir                         ,const ::rtl::OUString& _sDestDataSourceName
118cdf0e10cSrcweir                         ,const SharedConnection& _xConnection);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         /** pastes a table into the data source
121cdf0e10cSrcweir 			@param	_nFormatId
122cdf0e10cSrcweir 				The format which should be copied.
123cdf0e10cSrcweir 			@param	_rPasteData
124cdf0e10cSrcweir 				The data helper.
125cdf0e10cSrcweir             @param	_sDestDataSourceName
126cdf0e10cSrcweir 				The name of the dest data source.
127cdf0e10cSrcweir 		*/
128cdf0e10cSrcweir 		void pasteTable( SotFormatStringId _nFormatId
129cdf0e10cSrcweir                         ,const TransferableDataHelper& _rTransData
130cdf0e10cSrcweir                         ,const ::rtl::OUString& _sDestDataSourceName
131cdf0e10cSrcweir                         ,const SharedConnection& _xConnection);
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		/** copies a table which was constructed by tags like HTML or RTF
134cdf0e10cSrcweir 			@param	_rDesc
135cdf0e10cSrcweir 				The Drop descriptor
136cdf0e10cSrcweir 			@param	_bCheck
137cdf0e10cSrcweir 				If set to <TRUE/> than the controller checks only if a copy is possible.
138cdf0e10cSrcweir             @param  _xConnection
139cdf0e10cSrcweir                 The connection
140cdf0e10cSrcweir 		*/
141cdf0e10cSrcweir 		sal_Bool copyTagTable(  DropDescriptor& _rDesc,
142cdf0e10cSrcweir                                 sal_Bool _bCheck,
143cdf0e10cSrcweir                                 const SharedConnection& _xConnection);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         /** copies a table which was constructed by tags like HTML or RTF
146cdf0e10cSrcweir 			@param	_rDesc
147cdf0e10cSrcweir 				The Drop descriptor
148cdf0e10cSrcweir 			@param	_bCheck
149cdf0e10cSrcweir 				If set to <TRUE/> than the controller checks only if a copy is possible.
150cdf0e10cSrcweir             @param  _xConnection
151cdf0e10cSrcweir                 The connection
152cdf0e10cSrcweir 		*/
153cdf0e10cSrcweir 		void asyncCopyTagTable(  DropDescriptor& _rDesc
154cdf0e10cSrcweir                                 ,const ::rtl::OUString& _sDestDataSourceName
155cdf0e10cSrcweir                                 ,const SharedConnection& _xConnection);
156cdf0e10cSrcweir 
157cdf0e10cSrcweir         /** copies a table which was constructed by tags like HTML or RTF
158cdf0e10cSrcweir             @param  _aDroppedData
159cdf0e10cSrcweir                 The dropped data
160cdf0e10cSrcweir 			@param	_rDesc
161cdf0e10cSrcweir 				IN/OUT parameter
162cdf0e10cSrcweir             @param  _xConnection
163cdf0e10cSrcweir                 The connection
164cdf0e10cSrcweir 		*/
165cdf0e10cSrcweir         sal_Bool copyTagTable(const TransferableDataHelper& _aDroppedData,
166cdf0e10cSrcweir                               DropDescriptor& _rAsyncDrop,
167cdf0e10cSrcweir                               const SharedConnection& _xConnection);
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         /// returns <TRUE/> if the clipboard supports a table format, otherwise <FALSE/>.
170cdf0e10cSrcweir 		sal_Bool isTableFormat(const TransferableDataHelper& _rClipboard) const;
171cdf0e10cSrcweir 
SetTableNameForAppend(const::rtl::OUString & _rDefaultTableName)172cdf0e10cSrcweir         inline void                     SetTableNameForAppend( const ::rtl::OUString& _rDefaultTableName ) { m_sTableNameForAppend = _rDefaultTableName; }
ResetTableNameForAppend()173cdf0e10cSrcweir         inline void                     ResetTableNameForAppend() { SetTableNameForAppend( ::rtl::OUString() ); }
GetTableNameForAppend() const174cdf0e10cSrcweir 		inline const ::rtl::OUString&   GetTableNameForAppend() const { return m_sTableNameForAppend ;}
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     private:
177cdf0e10cSrcweir 		/** pastes a table into the data source
178cdf0e10cSrcweir 			@param	_rPasteData
179cdf0e10cSrcweir 				The data descriptor.
180cdf0e10cSrcweir             @param	_sDestDataSourceName
181cdf0e10cSrcweir 				The name of the dest data source.
182cdf0e10cSrcweir 		*/
183cdf0e10cSrcweir 		void pasteTable(
184cdf0e10cSrcweir             const ::svx::ODataAccessDescriptor& _rPasteData,
185cdf0e10cSrcweir             const ::rtl::OUString& _sDestDataSourceName,
186cdf0e10cSrcweir             const SharedConnection& _xDestConnection
187cdf0e10cSrcweir         );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 		/** insert a table into the data source. The source can eihter be a table or a query
190cdf0e10cSrcweir 		*/
191cdf0e10cSrcweir 		void insertTable(
192cdf0e10cSrcweir 			const ::rtl::OUString& i_rSourceDataSource,
193cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& i_rSourceConnection,
194cdf0e10cSrcweir 			const ::rtl::OUString& i_rCommand,
195cdf0e10cSrcweir             const sal_Int32 i_nCommandType,
196cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >& i_rSourceRows,
197cdf0e10cSrcweir 			const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& i_rSelection,
198cdf0e10cSrcweir 			const sal_Bool i_bBookmarkSelection,
199cdf0e10cSrcweir             const ::rtl::OUString& i_rDestDataSource,
200cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& i_rDestConnection
201cdf0e10cSrcweir         );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     };
204cdf0e10cSrcweir //........................................................................
205cdf0e10cSrcweir }	// namespace dbaui
206cdf0e10cSrcweir //........................................................................
207cdf0e10cSrcweir #endif // DBUI_TABLECOPYHELPER_HXX
208cdf0e10cSrcweir 
209