fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / browser / dbexchange.cxx
blobcbdbdadd304c6f70b53f85af45dd525404de2dfa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "dbexchange.hxx"
21 #include <sot/formats.hxx>
22 #include <sot/storage.hxx>
23 #include <osl/diagnose.h>
24 #include <com/sun/star/sdb/CommandType.hpp>
25 #include <com/sun/star/sdb/XResultSetAccess.hpp>
26 #include "TokenWriter.hxx"
27 #include "dbustrings.hrc"
28 #include <comphelper/uno3.hxx>
29 #include <svx/dataaccessdescriptor.hxx>
30 #include "UITools.hxx"
31 #include <comphelper/processfactory.hxx>
33 namespace dbaui
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::sdb;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::util;
40 using namespace ::com::sun::star::sdbc;
41 using namespace ::com::sun::star::datatransfer;
42 using namespace ::svx;
44 namespace
46 template<class T > void lcl_setListener(const Reference<T>& _xComponent, const Reference< XEventListener >& i_rListener, const bool i_bAdd )
48 if ( !_xComponent.is() )
49 return;
51 Reference< XComponent> xCom( _xComponent, UNO_QUERY );
52 OSL_ENSURE( xCom.is(), "lcl_setListener: no component!" );
53 if ( !xCom.is() )
54 return;
56 i_bAdd ? xCom->addEventListener( i_rListener ) : xCom->removeEventListener( i_rListener );
60 ODataClipboard::ODataClipboard(
61 const OUString& _rDatasource,
62 const sal_Int32 _nCommandType,
63 const OUString& _rCommand,
64 const Reference< XConnection >& _rxConnection,
65 const Reference< XNumberFormatter >& _rxFormatter,
66 const Reference< XComponentContext >& _rxORB)
67 :ODataAccessObjectTransferable( _rDatasource,OUString(), _nCommandType, _rCommand, _rxConnection )
68 ,m_pHtml(NULL)
69 ,m_pRtf(NULL)
71 osl_atomic_increment( &m_refCount );
72 lcl_setListener( _rxConnection, this, true );
74 m_pHtml.set( new OHTMLImportExport( getDescriptor(), _rxORB, _rxFormatter ) );
75 m_pRtf.set( new ORTFImportExport( getDescriptor(), _rxORB, _rxFormatter ) );
77 osl_atomic_decrement( &m_refCount );
80 ODataClipboard::ODataClipboard(
81 const OUString& _rDatasource,
82 const sal_Int32 _nCommandType,
83 const OUString& _rCommand,
84 const Reference< XNumberFormatter >& _rxFormatter,
85 const Reference< XComponentContext >& _rxORB)
86 :ODataAccessObjectTransferable( _rDatasource, OUString(),_nCommandType, _rCommand)
87 ,m_pHtml(NULL)
88 ,m_pRtf(NULL)
90 m_pHtml.set( new OHTMLImportExport( getDescriptor(),_rxORB, _rxFormatter ) );
91 m_pRtf.set( new ORTFImportExport( getDescriptor(),_rxORB, _rxFormatter ) );
94 ODataClipboard::ODataClipboard( const Reference< XPropertySet >& i_rAliveForm,
95 const Sequence< Any >& i_rSelectedRows,
96 const bool i_bBookmarkSelection,
97 const Reference< XComponentContext >& i_rORB )
98 :ODataAccessObjectTransferable( i_rAliveForm )
99 ,m_pHtml(NULL)
100 ,m_pRtf(NULL)
102 OSL_PRECOND( i_rORB.is(), "ODataClipboard::ODataClipboard: having no factory is not good ..." );
104 osl_atomic_increment( &m_refCount );
106 Reference<XConnection> xConnection;
107 getDescriptor()[ daConnection ] >>= xConnection;
108 lcl_setListener( xConnection, this, true );
110 // do not pass the form itself as source result set, since the client might operate on the form, which
111 // might lead to undesired effects. Instead, use a clone.
112 Reference< XResultSet > xResultSetClone;
113 Reference< XResultSetAccess > xResultSetAccess( i_rAliveForm, UNO_QUERY );
114 if ( xResultSetAccess.is() )
115 xResultSetClone = xResultSetAccess->createResultSet();
116 OSL_ENSURE( xResultSetClone.is(), "ODataClipboard::ODataClipboard: could not clone the form's result set" );
117 lcl_setListener( xResultSetClone, this, true );
119 getDescriptor()[daCursor] <<= xResultSetClone;
120 getDescriptor()[daSelection] <<= i_rSelectedRows;
121 getDescriptor()[daBookmarkSelection]<<= i_bBookmarkSelection;
122 addCompatibleSelectionDescription( i_rSelectedRows );
124 if ( xConnection.is() && i_rORB.is() )
126 Reference< XNumberFormatter > xFormatter( getNumberFormatter( xConnection, i_rORB ) );
127 if ( xFormatter.is() )
129 m_pHtml.set( new OHTMLImportExport( getDescriptor(), i_rORB, xFormatter ) );
130 m_pRtf.set( new ORTFImportExport( getDescriptor(), i_rORB, xFormatter ) );
134 osl_atomic_decrement( &m_refCount );
137 bool ODataClipboard::WriteObject( ::tools::SvRef<SotStorageStream>& rxOStm, void* pUserObject, SotClipboardFormatId nUserObjectId, const ::com::sun::star::datatransfer::DataFlavor& /*rFlavor*/ )
139 if (nUserObjectId == SotClipboardFormatId::RTF || nUserObjectId == SotClipboardFormatId::HTML )
141 ODatabaseImportExport* pExport = static_cast<ODatabaseImportExport*>(pUserObject);
142 if ( pExport && rxOStm.Is() )
144 pExport->setStream(&rxOStm);
145 return pExport->Write();
148 return false;
151 void ODataClipboard::AddSupportedFormats()
153 if ( m_pRtf.is() )
154 AddFormat( SotClipboardFormatId::RTF );
156 if ( m_pHtml.is() )
157 AddFormat( SotClipboardFormatId::HTML );
159 ODataAccessObjectTransferable::AddSupportedFormats();
162 bool ODataClipboard::GetData( const DataFlavor& rFlavor, const OUString& rDestDoc )
164 const SotClipboardFormatId nFormat = SotExchange::GetFormat(rFlavor);
165 switch (nFormat)
167 case SotClipboardFormatId::RTF:
168 if ( m_pRtf.is() )
169 m_pRtf->initialize(getDescriptor());
170 return m_pRtf.is() && SetObject( m_pRtf.get(), SotClipboardFormatId::RTF, rFlavor );
172 case SotClipboardFormatId::HTML:
173 if ( m_pHtml.is() )
174 m_pHtml->initialize(getDescriptor());
175 return m_pHtml.is() && SetObject( m_pHtml.get(), SotClipboardFormatId::HTML, rFlavor );
177 default: break;
180 return ODataAccessObjectTransferable::GetData(rFlavor, rDestDoc);
183 void ODataClipboard::ObjectReleased()
185 if ( m_pHtml.is() )
187 m_pHtml->dispose();
188 m_pHtml.clear();
191 if ( m_pRtf.is() )
193 m_pRtf->dispose();
194 m_pRtf.clear();
197 if ( getDescriptor().has( daConnection ) )
199 Reference<XConnection> xConnection( getDescriptor()[daConnection], UNO_QUERY );
200 lcl_setListener( xConnection, this, false );
203 if ( getDescriptor().has( daCursor ) )
205 Reference< XResultSet > xResultSet( getDescriptor()[ daCursor ], UNO_QUERY );
206 lcl_setListener( xResultSet, this, false );
209 ODataAccessObjectTransferable::ObjectReleased( );
212 void SAL_CALL ODataClipboard::disposing( const ::com::sun::star::lang::EventObject& i_rSource ) throw (::com::sun::star::uno::RuntimeException, std::exception)
214 ODataAccessDescriptor& rDescriptor( getDescriptor() );
216 if ( rDescriptor.has( daConnection ) )
218 Reference< XConnection > xConnection( rDescriptor[daConnection], UNO_QUERY );
219 if ( xConnection == i_rSource.Source )
221 rDescriptor.erase( daConnection );
225 if ( rDescriptor.has( daCursor ) )
227 Reference< XResultSet > xResultSet( rDescriptor[ daCursor ], UNO_QUERY );
228 if ( xResultSet == i_rSource.Source )
230 rDescriptor.erase( daCursor );
231 // Selection and BookmarkSelection are meaningless without a result set
232 if ( rDescriptor.has( daSelection ) )
233 rDescriptor.erase( daSelection );
234 if ( rDescriptor.has( daBookmarkSelection ) )
235 rDescriptor.erase( daBookmarkSelection );
239 // no matter whether it was the source connection or the source result set which died,
240 // we cannot provide the data anymore.
241 ClearFormats();
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */