1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svx/dbaexchange.hxx>
21 #include <osl/diagnose.h>
22 #include <com/sun/star/sdb/CommandType.hpp>
23 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
24 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
26 #include <comphelper/extract.hxx>
27 #include <sot/formats.hxx>
28 #include <sot/exchange.hxx>
29 #include <comphelper/propertysetinfo.hxx>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::beans
;
38 using namespace ::com::sun::star::sdb
;
39 using namespace ::com::sun::star::sdbc
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::sdbcx
;
42 using namespace ::com::sun::star::container
;
43 using namespace ::com::sun::star::datatransfer
;
44 using namespace ::comphelper
;
46 OColumnTransferable::OColumnTransferable(const OUString
& _rDatasource
47 ,const OUString
& _rCommand
48 ,const OUString
& _rFieldName
49 ,ColumnTransferFormatFlags _nFormats
)
50 :m_nFormatFlags(_nFormats
)
52 implConstruct(_rDatasource
,OUString(), css::sdb::CommandType::TABLE
, _rCommand
, _rFieldName
);
56 OColumnTransferable::OColumnTransferable(const ODataAccessDescriptor
& _rDescriptor
, ColumnTransferFormatFlags _nFormats
)
57 :m_nFormatFlags(_nFormats
)
59 OUString sDataSource
, sDatabaseLocation
, sConnectionResource
, sCommand
, sFieldName
;
60 if ( _rDescriptor
.has( DataAccessDescriptorProperty::DataSource
) ) _rDescriptor
[ DataAccessDescriptorProperty::DataSource
] >>= sDataSource
;
61 if ( _rDescriptor
.has( DataAccessDescriptorProperty::DatabaseLocation
) ) _rDescriptor
[ DataAccessDescriptorProperty::DatabaseLocation
] >>= sDatabaseLocation
;
62 if ( _rDescriptor
.has( DataAccessDescriptorProperty::ConnectionResource
) ) _rDescriptor
[ DataAccessDescriptorProperty::ConnectionResource
] >>= sConnectionResource
;
63 if ( _rDescriptor
.has( DataAccessDescriptorProperty::Command
) ) _rDescriptor
[ DataAccessDescriptorProperty::Command
] >>= sCommand
;
64 if ( _rDescriptor
.has( DataAccessDescriptorProperty::ColumnName
) ) _rDescriptor
[ DataAccessDescriptorProperty::ColumnName
] >>= sFieldName
;
66 sal_Int32 nCommandType
= CommandType::TABLE
;
67 OSL_VERIFY( _rDescriptor
[ DataAccessDescriptorProperty::CommandType
] >>= nCommandType
);
71 sDataSource
.isEmpty() ? sDatabaseLocation
: sDataSource
,
72 sConnectionResource
, nCommandType
, sCommand
, sFieldName
);
74 if ( m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
76 if ( _rDescriptor
.has( DataAccessDescriptorProperty::Connection
) )
77 m_aDescriptor
[ DataAccessDescriptorProperty::Connection
] = _rDescriptor
[ DataAccessDescriptorProperty::Connection
];
78 if ( _rDescriptor
.has( DataAccessDescriptorProperty::ColumnObject
) )
79 m_aDescriptor
[ DataAccessDescriptorProperty::ColumnObject
] = _rDescriptor
[ DataAccessDescriptorProperty::ColumnObject
];
84 OColumnTransferable::OColumnTransferable(const Reference
< XPropertySet
>& _rxForm
,
85 const OUString
& _rFieldName
, const Reference
< XPropertySet
>& _rxColumn
,
86 const Reference
< XConnection
>& _rxConnection
, ColumnTransferFormatFlags _nFormats
)
87 :m_nFormatFlags(_nFormats
)
89 OSL_ENSURE(_rxForm
.is(), "OColumnTransferable::OColumnTransferable: invalid form!");
90 // collect the necessary information from the form
92 sal_Int32 nCommandType
= CommandType::TABLE
;
93 OUString sDatasource
,sURL
;
95 bool bTryToParse
= true;
98 _rxForm
->getPropertyValue(FM_PROP_COMMANDTYPE
) >>= nCommandType
;
99 _rxForm
->getPropertyValue(FM_PROP_COMMAND
) >>= sCommand
;
100 _rxForm
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sDatasource
;
101 _rxForm
->getPropertyValue(FM_PROP_URL
) >>= sURL
;
102 bTryToParse
= ::cppu::any2bool(_rxForm
->getPropertyValue(FM_PROP_ESCAPE_PROCESSING
));
106 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
109 // If the data source is an SQL-statement and simple enough (means "select <field list> from <table> where ....")
110 // we are able to fake the drag information we are about to create.
111 if (bTryToParse
&& (CommandType::COMMAND
== nCommandType
))
115 Reference
< XTablesSupplier
> xSupTab
;
116 _rxForm
->getPropertyValue("SingleSelectQueryComposer") >>= xSupTab
;
120 Reference
< XNameAccess
> xNames
= xSupTab
->getTables();
123 Sequence
< OUString
> aTables
= xNames
->getElementNames();
124 if (1 == aTables
.getLength())
126 sCommand
= aTables
[0];
127 nCommandType
= CommandType::TABLE
;
134 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
138 implConstruct(sDatasource
, sURL
,nCommandType
, sCommand
, _rFieldName
);
140 if ((m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
143 m_aDescriptor
[DataAccessDescriptorProperty::ColumnObject
] <<= _rxColumn
;
144 if (_rxConnection
.is())
145 m_aDescriptor
[DataAccessDescriptorProperty::Connection
] <<= _rxConnection
;
150 SotClipboardFormatId
OColumnTransferable::getDescriptorFormatId()
152 static SotClipboardFormatId s_nFormat
= static_cast<SotClipboardFormatId
>(-1);
153 if (static_cast<SotClipboardFormatId
>(-1) == s_nFormat
)
155 s_nFormat
= SotExchange::RegisterFormatName("application/x-openoffice;windows_formatname=\"dbaccess.ColumnDescriptorTransfer\"");
156 OSL_ENSURE(static_cast<SotClipboardFormatId
>(-1) != s_nFormat
, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
162 void OColumnTransferable::implConstruct( const OUString
& _rDatasource
163 ,const OUString
& _rConnectionResource
164 ,const sal_Int32 _nCommandType
165 ,const OUString
& _rCommand
166 , const OUString
& _rFieldName
)
168 const sal_Unicode cSeparator
= u
'\x000B';
169 const OUString
sSeparator(&cSeparator
, 1);
171 m_sCompatibleFormat
.clear();
172 m_sCompatibleFormat
+= _rDatasource
;
173 m_sCompatibleFormat
+= sSeparator
;
174 m_sCompatibleFormat
+= _rCommand
;
175 m_sCompatibleFormat
+= sSeparator
;
177 sal_Unicode cCommandType
;
178 switch (_nCommandType
)
180 case CommandType::TABLE
:
183 case CommandType::QUERY
:
190 m_sCompatibleFormat
+= OUString(&cCommandType
, 1);
191 m_sCompatibleFormat
+= sSeparator
;
192 m_sCompatibleFormat
+= _rFieldName
;
194 m_aDescriptor
.clear();
195 if ((m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
197 m_aDescriptor
.setDataSource(_rDatasource
);
198 if ( !_rConnectionResource
.isEmpty() )
199 m_aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] <<= _rConnectionResource
;
201 m_aDescriptor
[DataAccessDescriptorProperty::Command
] <<= _rCommand
;
202 m_aDescriptor
[DataAccessDescriptorProperty::CommandType
] <<= _nCommandType
;
203 m_aDescriptor
[DataAccessDescriptorProperty::ColumnName
] <<= _rFieldName
;
208 void OColumnTransferable::AddSupportedFormats()
210 if (ColumnTransferFormatFlags::CONTROL_EXCHANGE
& m_nFormatFlags
)
211 AddFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
);
213 if (ColumnTransferFormatFlags::FIELD_DESCRIPTOR
& m_nFormatFlags
)
214 AddFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
);
216 if (ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
& m_nFormatFlags
)
217 AddFormat(getDescriptorFormatId());
221 bool OColumnTransferable::GetData( const DataFlavor
& _rFlavor
, const OUString
& /*rDestDoc*/ )
223 const SotClipboardFormatId nFormatId
= SotExchange::GetFormat(_rFlavor
);
226 case SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
:
227 case SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
:
228 return SetString(m_sCompatibleFormat
, _rFlavor
);
231 if (nFormatId
== getDescriptorFormatId())
232 return SetAny( makeAny( m_aDescriptor
.createPropertyValueSequence() ) );
238 bool OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector
& _rFlavors
, ColumnTransferFormatFlags _nFormats
)
240 bool bFieldFormat
= bool(_nFormats
& ColumnTransferFormatFlags::FIELD_DESCRIPTOR
);
241 bool bControlFormat
= bool(_nFormats
& ColumnTransferFormatFlags::CONTROL_EXCHANGE
);
242 bool bDescriptorFormat
= bool(_nFormats
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
);
243 for ( DataFlavorExVector::const_iterator aCheck
= _rFlavors
.begin();
244 aCheck
!= _rFlavors
.end();
248 if (bFieldFormat
&& (SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
== aCheck
->mnSotId
))
250 if (bControlFormat
&& (SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
== aCheck
->mnSotId
))
252 if (bDescriptorFormat
&& (getDescriptorFormatId() == aCheck
->mnSotId
))
260 ODataAccessDescriptor
OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper
& _rData
)
262 if (_rData
.HasFormat(getDescriptorFormatId()))
264 // the object has a real descriptor object (not just the old compatible format)
266 // extract the any from the transferable
269 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor
);
270 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
272 Any aDescriptor
= _rData
.GetAny(aFlavor
, OUString());
274 // extract the property value sequence
275 Sequence
< PropertyValue
> aDescriptorProps
;
276 bSuccess
= aDescriptor
>>= aDescriptorProps
;
277 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
279 // build the real descriptor
280 return ODataAccessDescriptor(aDescriptorProps
);
283 // only the old (compatible) format exists -> use the other extract method ...
284 OUString sDatasource
, sCommand
, sFieldName
,sDatabaseLocation
,sConnectionResource
;
285 sal_Int32 nCommandType
= CommandType::COMMAND
;
287 ODataAccessDescriptor aDescriptor
;
288 if (extractColumnDescriptor(_rData
, sDatasource
, sDatabaseLocation
,sConnectionResource
,nCommandType
, sCommand
, sFieldName
))
290 // and build an own descriptor
291 if ( !sDatasource
.isEmpty() )
292 aDescriptor
[DataAccessDescriptorProperty::DataSource
] <<= sDatasource
;
293 if ( !sDatabaseLocation
.isEmpty() )
294 aDescriptor
[DataAccessDescriptorProperty::DatabaseLocation
] <<= sDatabaseLocation
;
295 if ( !sConnectionResource
.isEmpty() )
296 aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] <<= sConnectionResource
;
298 aDescriptor
[DataAccessDescriptorProperty::Command
] <<= sCommand
;
299 aDescriptor
[DataAccessDescriptorProperty::CommandType
] <<= nCommandType
;
300 aDescriptor
[DataAccessDescriptorProperty::ColumnName
] <<= sFieldName
;
306 bool OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper
& _rData
307 ,OUString
& _rDatasource
308 ,OUString
& _rDatabaseLocation
309 ,OUString
& _rConnectionResource
310 ,sal_Int32
& _nCommandType
312 ,OUString
& _rFieldName
)
314 if ( _rData
.HasFormat(getDescriptorFormatId()) )
316 ODataAccessDescriptor aDescriptor
= extractColumnDescriptor(_rData
);
317 if ( aDescriptor
.has(DataAccessDescriptorProperty::DataSource
) )
318 aDescriptor
[DataAccessDescriptorProperty::DataSource
] >>= _rDatasource
;
319 if ( aDescriptor
.has(DataAccessDescriptorProperty::DatabaseLocation
) )
320 aDescriptor
[DataAccessDescriptorProperty::DatabaseLocation
] >>= _rDatabaseLocation
;
321 if ( aDescriptor
.has(DataAccessDescriptorProperty::ConnectionResource
) )
322 aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] >>= _rConnectionResource
;
324 aDescriptor
[DataAccessDescriptorProperty::Command
] >>= _rCommand
;
325 aDescriptor
[DataAccessDescriptorProperty::CommandType
] >>= _nCommandType
;
326 aDescriptor
[DataAccessDescriptorProperty::ColumnName
] >>= _rFieldName
;
330 // check if we have a (string) format we can use ....
331 SotClipboardFormatId nRecognizedFormat
= SotClipboardFormatId::NONE
;
332 if (_rData
.HasFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
))
333 nRecognizedFormat
= SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
;
334 if (_rData
.HasFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
))
335 nRecognizedFormat
= SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
;
336 if (nRecognizedFormat
== SotClipboardFormatId::NONE
)
339 OUString sFieldDescription
;
340 (void)const_cast<TransferableDataHelper
&>(_rData
).GetString(nRecognizedFormat
, sFieldDescription
);
342 const sal_Unicode cSeparator
= u
'\x000B';
343 _rDatasource
= sFieldDescription
.getToken(0, cSeparator
);
344 _rCommand
= sFieldDescription
.getToken(1, cSeparator
);
345 _nCommandType
= sFieldDescription
.getToken(2, cSeparator
).toInt32();
346 _rFieldName
= sFieldDescription
.getToken(3, cSeparator
);
352 void OColumnTransferable::addDataToContainer( TransferDataContainer
* _pContainer
)
354 OSL_ENSURE( _pContainer
, "OColumnTransferable::addDataToContainer: invalid container!" );
357 if ( m_nFormatFlags
& ColumnTransferFormatFlags::FIELD_DESCRIPTOR
)
358 _pContainer
->CopyAny( SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
, makeAny( m_sCompatibleFormat
) );
360 if ( m_nFormatFlags
& ColumnTransferFormatFlags::CONTROL_EXCHANGE
)
361 _pContainer
->CopyAny( SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
, makeAny( m_sCompatibleFormat
) );
363 if ( m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
365 Any aContent
= makeAny( m_aDescriptor
.createPropertyValueSequence() );
366 _pContainer
->CopyAny( getDescriptorFormatId(), aContent
);
371 ODataAccessObjectTransferable::ODataAccessObjectTransferable(
372 const OUString
& _rDatasource
373 ,const sal_Int32 _nCommandType
374 ,const OUString
& _rCommand
377 construct(_rDatasource
,OUString(),_nCommandType
,_rCommand
,nullptr,(CommandType::COMMAND
== _nCommandType
),_rCommand
);
380 ODataAccessObjectTransferable::ODataAccessObjectTransferable(
381 const OUString
& _rDatasource
382 ,const sal_Int32 _nCommandType
383 ,const OUString
& _rCommand
384 ,const Reference
< XConnection
>& _rxConnection
)
386 OSL_ENSURE(_rxConnection
.is(),"Wrong ctor used.!");
387 construct(_rDatasource
,OUString(),_nCommandType
,_rCommand
,_rxConnection
,(CommandType::COMMAND
== _nCommandType
),_rCommand
);
391 ODataAccessObjectTransferable::ODataAccessObjectTransferable(const Reference
< XPropertySet
>& _rxLivingForm
)
393 // collect some properties of the form
394 OUString sDatasourceName
,sConnectionResource
;
395 sal_Int32 nObjectType
= CommandType::COMMAND
;
396 OUString sObjectName
;
397 Reference
< XConnection
> xConnection
;
400 _rxLivingForm
->getPropertyValue(FM_PROP_COMMANDTYPE
) >>= nObjectType
;
401 _rxLivingForm
->getPropertyValue(FM_PROP_COMMAND
) >>= sObjectName
;
402 _rxLivingForm
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sDatasourceName
;
403 _rxLivingForm
->getPropertyValue(FM_PROP_URL
) >>= sConnectionResource
;
404 _rxLivingForm
->getPropertyValue(FM_PROP_ACTIVE_CONNECTION
) >>= xConnection
;
408 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
412 // check if the SQL-statement is modified
413 OUString sCompleteStatement
;
416 _rxLivingForm
->getPropertyValue(FM_PROP_ACTIVECOMMAND
) >>= sCompleteStatement
;
418 catch (const Exception
&)
420 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
424 construct( sDatasourceName
427 ,sObjectName
,xConnection
428 ,!((CommandType::QUERY
== nObjectType
))
429 ,sCompleteStatement
);
433 void ODataAccessObjectTransferable::AddSupportedFormats()
435 sal_Int32 nObjectType
= CommandType::COMMAND
;
436 m_aDescriptor
[DataAccessDescriptorProperty::CommandType
] >>= nObjectType
;
439 case CommandType::TABLE
:
440 AddFormat(SotClipboardFormatId::DBACCESS_TABLE
);
442 case CommandType::QUERY
:
443 AddFormat(SotClipboardFormatId::DBACCESS_QUERY
);
445 case CommandType::COMMAND
:
446 AddFormat(SotClipboardFormatId::DBACCESS_COMMAND
);
450 if (!m_sCompatibleObjectDescription
.isEmpty())
451 AddFormat(SotClipboardFormatId::SBA_DATAEXCHANGE
);
455 bool ODataAccessObjectTransferable::GetData( const DataFlavor
& rFlavor
, const OUString
& /*rDestDoc*/ )
457 SotClipboardFormatId nFormat
= SotExchange::GetFormat(rFlavor
);
460 case SotClipboardFormatId::DBACCESS_TABLE
:
461 case SotClipboardFormatId::DBACCESS_QUERY
:
462 case SotClipboardFormatId::DBACCESS_COMMAND
:
463 return SetAny( makeAny(m_aDescriptor
.createPropertyValueSequence()) );
465 case SotClipboardFormatId::SBA_DATAEXCHANGE
:
466 return SetString(m_sCompatibleObjectDescription
, rFlavor
);
473 bool ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector
& _rFlavors
)
475 for ( DataFlavorExVector::const_iterator aCheck
= _rFlavors
.begin();
476 aCheck
!= _rFlavors
.end();
480 if (SotClipboardFormatId::DBACCESS_TABLE
== aCheck
->mnSotId
)
482 if (SotClipboardFormatId::DBACCESS_QUERY
== aCheck
->mnSotId
)
484 if (SotClipboardFormatId::DBACCESS_COMMAND
== aCheck
->mnSotId
)
491 ODataAccessDescriptor
ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper
& _rData
)
493 SotClipboardFormatId nKnownFormatId
= SotClipboardFormatId::NONE
;
494 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_TABLE
) )
495 nKnownFormatId
= SotClipboardFormatId::DBACCESS_TABLE
;
496 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_QUERY
) )
497 nKnownFormatId
= SotClipboardFormatId::DBACCESS_QUERY
;
498 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_COMMAND
) )
499 nKnownFormatId
= SotClipboardFormatId::DBACCESS_COMMAND
;
501 if (SotClipboardFormatId::NONE
!= nKnownFormatId
)
503 // extract the any from the transferable
506 SotExchange::GetFormatDataFlavor(nKnownFormatId
, aFlavor
);
507 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
509 Any aDescriptor
= _rData
.GetAny(aFlavor
, OUString());
511 // extract the property value sequence
512 Sequence
< PropertyValue
> aDescriptorProps
;
513 bSuccess
= aDescriptor
>>= aDescriptorProps
;
514 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
516 // build the real descriptor
517 return ODataAccessDescriptor(aDescriptorProps
);
520 OSL_FAIL( "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
521 return ODataAccessDescriptor();
525 void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence
< Any
>& _rSelRows
)
527 const sal_Unicode
cSeparator(11);
528 const OUString
sSeparator(&cSeparator
, 1);
530 const Any
* pSelRows
= _rSelRows
.getConstArray();
531 const Any
* pSelRowsEnd
= pSelRows
+ _rSelRows
.getLength();
532 for ( ; pSelRows
< pSelRowsEnd
; ++pSelRows
)
534 sal_Int32
nSelectedRow( 0 );
535 OSL_VERIFY( *pSelRows
>>= nSelectedRow
);
537 m_sCompatibleObjectDescription
+= OUString::number(nSelectedRow
);
538 m_sCompatibleObjectDescription
+= sSeparator
;
543 void ODataAccessObjectTransferable::ObjectReleased()
545 m_aDescriptor
.clear();
548 void ODataAccessObjectTransferable::construct( const OUString
& _rDatasource
549 ,const OUString
& _rConnectionResource
550 ,const sal_Int32 _nCommandType
551 ,const OUString
& _rCommand
552 ,const Reference
< XConnection
>& _rxConnection
554 ,const OUString
& _sActiveCommand
)
556 m_aDescriptor
.setDataSource(_rDatasource
);
557 // build the descriptor (the property sequence)
558 if ( !_rConnectionResource
.isEmpty() )
559 m_aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] <<= _rConnectionResource
;
560 if ( _rxConnection
.is() )
561 m_aDescriptor
[DataAccessDescriptorProperty::Connection
] <<= _rxConnection
;
562 m_aDescriptor
[DataAccessDescriptorProperty::Command
] <<= _rCommand
;
563 m_aDescriptor
[DataAccessDescriptorProperty::CommandType
] <<= _nCommandType
;
565 // extract the single values from the sequence
567 OUString sObjectName
;
568 sObjectName
= _rCommand
;
570 // for compatibility: create a string which can be used for the SotClipboardFormatId::SBA_DATAEXCHANGE format
572 bool bTreatAsStatement
= (CommandType::COMMAND
== _nCommandType
);
573 // statements are - in this old and ugly format - described as queries
575 const sal_Unicode cSeparator
= u
'\x000B';
576 const OUString
sSeparator(&cSeparator
, 1);
578 const sal_Unicode cTableMark
= '1';
579 const sal_Unicode cQueryMark
= '0';
581 // build the descriptor string
582 m_sCompatibleObjectDescription
+= _rDatasource
;
583 m_sCompatibleObjectDescription
+= sSeparator
;
584 m_sCompatibleObjectDescription
+= bTreatAsStatement
? OUString() : sObjectName
;
585 m_sCompatibleObjectDescription
+= sSeparator
;
586 switch (_nCommandType
)
588 case CommandType::TABLE
:
589 m_sCompatibleObjectDescription
+= OUString(&cTableMark
, 1);
591 case CommandType::QUERY
:
592 m_sCompatibleObjectDescription
+= OUString(&cQueryMark
, 1);
594 case CommandType::COMMAND
:
595 m_sCompatibleObjectDescription
+= OUString(&cQueryMark
, 1);
596 // think of it as a query
599 m_sCompatibleObjectDescription
+= sSeparator
;
600 m_sCompatibleObjectDescription
+= _bAddCommand
? _sActiveCommand
: OUString();
601 m_sCompatibleObjectDescription
+= sSeparator
;
605 OMultiColumnTransferable::OMultiColumnTransferable(const Sequence
< PropertyValue
>& _aDescriptors
) : m_aDescriptors(_aDescriptors
)
609 SotClipboardFormatId
OMultiColumnTransferable::getDescriptorFormatId()
611 static SotClipboardFormatId s_nFormat
= static_cast<SotClipboardFormatId
>(-1);
612 if (static_cast<SotClipboardFormatId
>(-1) == s_nFormat
)
614 s_nFormat
= SotExchange::RegisterFormatName("application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\"");
615 OSL_ENSURE(static_cast<SotClipboardFormatId
>(-1) != s_nFormat
, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
620 void OMultiColumnTransferable::AddSupportedFormats()
622 AddFormat(getDescriptorFormatId());
625 bool OMultiColumnTransferable::GetData( const DataFlavor
& _rFlavor
, const OUString
& /*rDestDoc*/ )
627 const SotClipboardFormatId nFormatId
= SotExchange::GetFormat(_rFlavor
);
628 if (nFormatId
== getDescriptorFormatId())
630 return SetAny( makeAny( m_aDescriptors
) );
637 bool OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector
& _rFlavors
)
639 DataFlavorExVector::const_iterator aCheck
= _rFlavors
.begin();
641 aCheck
!= _rFlavors
.end() && getDescriptorFormatId() == aCheck
->mnSotId
;
646 return aCheck
== _rFlavors
.end();
650 Sequence
< PropertyValue
> OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper
& _rData
)
652 Sequence
< PropertyValue
> aList
;
653 if (_rData
.HasFormat(getDescriptorFormatId()))
655 // extract the any from the transferable
658 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor
);
659 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
661 _rData
.GetAny(aFlavor
, OUString()) >>= aList
;
662 } // if (_rData.HasFormat(getDescriptorFormatId()))
666 void OMultiColumnTransferable::ObjectReleased()
668 m_aDescriptors
.realloc(0);
675 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */