1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbexchange.cxx,v $
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"
37 #ifndef _SOT_FORMATS_HXX
38 #include <sot/formats.hxx>
40 #ifndef _SOT_STORAGE_HXX
41 #include <sot/storage.hxx>
43 #ifndef _OSL_DIAGNOSE_H_
44 #include <osl/diagnose.h>
46 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
47 #include <com/sun/star/sdb/CommandType.hpp>
49 #ifndef DBAUI_TOKENWRITER_HXX
50 #include "TokenWriter.hxx"
52 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
53 #include "dbustrings.hrc"
55 //#ifndef _COMPHELPER_EXTRACT_HXX_
56 //#include <comphelper/extract.hxx>
58 #ifndef _COMPHELPER_UNO3_HXX_
59 #include <comphelper/uno3.hxx>
61 #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
62 #include <svx/dataaccessdescriptor.hxx>
64 #include "UITools.hxx"
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
;
81 template<class T
> void lcl_addListener(const Reference
<T
>& _xComponent
,ODataClipboard
* _pListener
)
83 if ( _xComponent
.is() )
85 Reference
< XComponent
> xCom(_xComponent
,UNO_QUERY
);
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
);
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
)
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
)
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
)
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();
195 // -----------------------------------------------------------------------------
196 void ODataClipboard::AddSupportedFormats()
200 AddFormat(SOT_FORMAT_RTF
);
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
);
217 m_pRtf
->initialize(getDescriptor());
218 return m_pRtf
&& SetObject(m_pRtf
, SOT_FORMAT_RTF
, rFlavor
);
219 case SOT_FORMATSTR_ID_HTML
:
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()
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
);
275 //getDescriptor().clear();
276 AddSupportedFormats();
280 m_aEventListeners.clear();*/
282 // -----------------------------------------------------------------------------
283 IMPLEMENT_FORWARD_XINTERFACE2( ODataClipboard
, ODataAccessObjectTransferable
, TDataClipboard_BASE
)