merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / browser / dbexchange.cxx
blob97e9aa41e72305a9e2385dcd3f79985bd6681ef7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbexchange.cxx,v $
10 * $Revision: 1.28 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef DBAUI_DBEXCHANGE_HXX
35 #include "dbexchange.hxx"
36 #endif
37 #ifndef _SOT_FORMATS_HXX
38 #include <sot/formats.hxx>
39 #endif
40 #ifndef _SOT_STORAGE_HXX
41 #include <sot/storage.hxx>
42 #endif
43 #ifndef _OSL_DIAGNOSE_H_
44 #include <osl/diagnose.h>
45 #endif
46 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
47 #include <com/sun/star/sdb/CommandType.hpp>
48 #endif
49 #ifndef DBAUI_TOKENWRITER_HXX
50 #include "TokenWriter.hxx"
51 #endif
52 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
53 #include "dbustrings.hrc"
54 #endif
55 //#ifndef _COMPHELPER_EXTRACT_HXX_
56 //#include <comphelper/extract.hxx>
57 //#endif
58 #ifndef _COMPHELPER_UNO3_HXX_
59 #include <comphelper/uno3.hxx>
60 #endif
61 #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
62 #include <svx/dataaccessdescriptor.hxx>
63 #endif
64 #include "UITools.hxx"
67 namespace dbaui
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::sdb;
72 using namespace ::com::sun::star::beans;
73 using namespace ::com::sun::star::lang;
74 using namespace ::com::sun::star::util;
75 using namespace ::com::sun::star::sdbc;
76 using namespace ::com::sun::star::datatransfer;
77 using namespace ::svx;
79 namespace
81 template<class T > void lcl_addListener(const Reference<T>& _xComponent,ODataClipboard* _pListener)
83 if ( _xComponent.is() )
85 Reference< XComponent> xCom(_xComponent,UNO_QUERY);
86 if ( xCom.is() )
87 xCom->addEventListener(Reference< XEventListener>((::cppu::OWeakObject*)_pListener,UNO_QUERY));
90 template<class T > void lcl_removeListener(const Reference<T>& _xComponent,ODataClipboard* _pListener)
92 if ( _xComponent.is() )
94 Reference< XComponent> xCom(_xComponent,UNO_QUERY);
95 if ( xCom.is() )
96 xCom->removeEventListener(Reference< XEventListener>((::cppu::OWeakObject*)_pListener,UNO_QUERY));
101 // -----------------------------------------------------------------------------
102 ODataClipboard::ODataClipboard(
103 const ::rtl::OUString& _rDatasource,
104 const sal_Int32 _nCommandType,
105 const ::rtl::OUString& _rCommand,
106 const Reference< XConnection >& _rxConnection,
107 const Reference< XNumberFormatter >& _rxFormatter,
108 const Reference< XMultiServiceFactory >& _rxORB)
109 :ODataAccessObjectTransferable( _rDatasource,::rtl::OUString(), _nCommandType, _rCommand, _rxConnection )
110 ,m_pHtml(NULL)
111 ,m_pRtf(NULL)
113 osl_incrementInterlockedCount( &m_refCount );
114 lcl_addListener(_rxConnection,this);
116 m_pHtml = new OHTMLImportExport(getDescriptor(), _rxORB, _rxFormatter);
117 m_aEventListeners.push_back(m_pHtml);
119 m_pRtf = new ORTFImportExport(getDescriptor(), _rxORB, _rxFormatter);
120 m_aEventListeners.push_back(m_pRtf);
121 osl_decrementInterlockedCount( &m_refCount );
124 // -----------------------------------------------------------------------------
125 ODataClipboard::ODataClipboard(
126 const ::rtl::OUString& _rDatasource,
127 const sal_Int32 _nCommandType,
128 const ::rtl::OUString& _rCommand,
129 const Reference< XNumberFormatter >& _rxFormatter,
130 const Reference< XMultiServiceFactory >& _rxORB)
131 :ODataAccessObjectTransferable( _rDatasource, ::rtl::OUString(),_nCommandType, _rCommand)
132 ,m_pHtml(NULL)
133 ,m_pRtf(NULL)
135 m_pHtml = new OHTMLImportExport(getDescriptor(),_rxORB, _rxFormatter);
136 m_aEventListeners.push_back(m_pHtml);
138 m_pRtf = new ORTFImportExport(getDescriptor(),_rxORB, _rxFormatter);
139 m_aEventListeners.push_back(m_pRtf);
142 // -----------------------------------------------------------------------------
143 ODataClipboard::ODataClipboard( const Reference< XPropertySet >& _rxLivingForm,
144 const Sequence< Any >& _rSelectedRows,
145 const Reference< XResultSet>& _rxResultSet,
146 const Reference< XMultiServiceFactory >& _rxORB)
147 :ODataAccessObjectTransferable( _rxLivingForm )
148 ,m_pHtml(NULL)
149 ,m_pRtf(NULL)
151 osl_incrementInterlockedCount( &m_refCount );
153 Reference<XConnection> xConnection;
154 getDescriptor()[daConnection] >>= xConnection;
155 lcl_addListener(xConnection,this);
156 lcl_addListener(_rxResultSet,this);
158 getDescriptor()[daSelection] <<= _rSelectedRows;
159 getDescriptor()[daBookmarkSelection]<<= sal_False; // by definition, it's the indicies
160 getDescriptor()[daCursor] <<= _rxResultSet;
161 addCompatibleSelectionDescription( _rSelectedRows );
163 if ( xConnection.is() && _rxORB.is() )
165 Reference< XNumberFormatter > xFormatter( getNumberFormatter( xConnection, _rxORB ) );
166 if ( xFormatter.is() )
168 m_pHtml = new OHTMLImportExport( getDescriptor(),_rxORB, xFormatter );
169 m_aEventListeners.push_back( m_pHtml );
171 m_pRtf = new ORTFImportExport( getDescriptor(),_rxORB, xFormatter );
172 m_aEventListeners.push_back( m_pRtf );
177 osl_decrementInterlockedCount( &m_refCount );
180 // -----------------------------------------------------------------------------
181 sal_Bool ODataClipboard::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId, const ::com::sun::star::datatransfer::DataFlavor& /*rFlavor*/ )
183 if (nUserObjectId == SOT_FORMAT_RTF || nUserObjectId == SOT_FORMATSTR_ID_HTML )
185 ODatabaseImportExport* pExport = reinterpret_cast<ODatabaseImportExport*>(pUserObject);
186 if ( pExport && rxOStm.Is() )
188 pExport->setStream(&rxOStm);
189 return pExport->Write();
192 return sal_False;
195 // -----------------------------------------------------------------------------
196 void ODataClipboard::AddSupportedFormats()
198 // RTF?
199 if (m_pRtf)
200 AddFormat(SOT_FORMAT_RTF);
202 // HTML?
203 if (m_pHtml)
204 AddFormat(SOT_FORMATSTR_ID_HTML);
206 ODataAccessObjectTransferable::AddSupportedFormats();
209 // -----------------------------------------------------------------------------
210 sal_Bool ODataClipboard::GetData( const DataFlavor& rFlavor )
212 const ULONG nFormat = SotExchange::GetFormat(rFlavor);
213 switch (nFormat)
215 case SOT_FORMAT_RTF:
216 if ( m_pRtf )
217 m_pRtf->initialize(getDescriptor());
218 return m_pRtf && SetObject(m_pRtf, SOT_FORMAT_RTF, rFlavor);
219 case SOT_FORMATSTR_ID_HTML:
220 if ( m_pHtml )
221 m_pHtml->initialize(getDescriptor());
222 return m_pHtml && SetObject(m_pHtml, SOT_FORMATSTR_ID_HTML, rFlavor);
225 return ODataAccessObjectTransferable::GetData( rFlavor );
228 // -----------------------------------------------------------------------------
229 void ODataClipboard::ObjectReleased()
231 if ( m_pHtml )
233 m_pHtml->dispose();
234 m_pHtml = NULL;
235 } // if ( m_pHtml )
236 if ( m_pRtf )
238 m_pRtf->dispose();
239 m_pRtf = NULL;
241 m_aEventListeners.clear();
242 Reference<XConnection> xConnection;
243 Reference<XResultSet> xProp;
244 if ( getDescriptor().has(daConnection) && (getDescriptor()[daConnection] >>= xConnection) )
245 lcl_removeListener(xConnection,this);
246 if ( getDescriptor().has(daCursor) && (getDescriptor()[daCursor] >>= xProp) )
247 lcl_removeListener(xProp,this);
249 ODataAccessObjectTransferable::ObjectReleased( );
251 // -----------------------------------------------------------------------------
252 void SAL_CALL ODataClipboard::disposing( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
254 Reference<XConnection> xConnection;
255 Reference<XResultSet> xProp;
256 if ( getDescriptor().has(daConnection) && (getDescriptor()[daConnection] >>= xConnection) )
258 lcl_removeListener(xConnection,this);
259 getDescriptor().erase(daConnection);
260 } // if ( getDescriptor().has(daConnection) && (getDescriptor()[daConnection] >>= xConnection) )
261 if ( getDescriptor().has(daCursor) && (getDescriptor()[daCursor] >>= xProp) )
263 lcl_removeListener(xProp,this);
264 getDescriptor().erase(daCursor);
265 } // if ( getDescriptor().has(daCursor) && (getDescriptor()[daCursor] >>= xProp) )
267 if ( getDescriptor().has(daColumnObject) )
268 getDescriptor().erase(daColumnObject);
270 if ( getDescriptor().has(daComponent) )
271 getDescriptor().erase(daComponent);
274 ClearFormats();
275 //getDescriptor().clear();
276 AddSupportedFormats();
278 /*m_pHtml = NULL;
279 m_pRtf = NULL;
280 m_aEventListeners.clear();*/
282 // -----------------------------------------------------------------------------
283 IMPLEMENT_FORWARD_XINTERFACE2( ODataClipboard, ODataAccessObjectTransferable, TDataClipboard_BASE )