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/sdbc/XConnection.hpp>
24 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
25 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
27 #include <comphelper/extract.hxx>
28 #include <sot/formats.hxx>
29 #include <sot/exchange.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
;
45 OColumnTransferable::OColumnTransferable(const ODataAccessDescriptor
& _rDescriptor
, ColumnTransferFormatFlags _nFormats
)
46 :m_nFormatFlags(_nFormats
)
48 OUString sDataSource
, sDatabaseLocation
, sConnectionResource
, sCommand
, sFieldName
;
49 if ( _rDescriptor
.has( DataAccessDescriptorProperty::DataSource
) ) _rDescriptor
[ DataAccessDescriptorProperty::DataSource
] >>= sDataSource
;
50 if ( _rDescriptor
.has( DataAccessDescriptorProperty::DatabaseLocation
) ) _rDescriptor
[ DataAccessDescriptorProperty::DatabaseLocation
] >>= sDatabaseLocation
;
51 if ( _rDescriptor
.has( DataAccessDescriptorProperty::ConnectionResource
) ) _rDescriptor
[ DataAccessDescriptorProperty::ConnectionResource
] >>= sConnectionResource
;
52 if ( _rDescriptor
.has( DataAccessDescriptorProperty::Command
) ) _rDescriptor
[ DataAccessDescriptorProperty::Command
] >>= sCommand
;
53 if ( _rDescriptor
.has( DataAccessDescriptorProperty::ColumnName
) ) _rDescriptor
[ DataAccessDescriptorProperty::ColumnName
] >>= sFieldName
;
55 sal_Int32 nCommandType
= CommandType::TABLE
;
56 OSL_VERIFY( _rDescriptor
[ DataAccessDescriptorProperty::CommandType
] >>= nCommandType
);
60 sDataSource
.isEmpty() ? sDatabaseLocation
: sDataSource
,
61 sConnectionResource
, nCommandType
, sCommand
, sFieldName
);
63 if ( m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
65 if ( _rDescriptor
.has( DataAccessDescriptorProperty::Connection
) )
66 m_aDescriptor
[ DataAccessDescriptorProperty::Connection
] = _rDescriptor
[ DataAccessDescriptorProperty::Connection
];
67 if ( _rDescriptor
.has( DataAccessDescriptorProperty::ColumnObject
) )
68 m_aDescriptor
[ DataAccessDescriptorProperty::ColumnObject
] = _rDescriptor
[ DataAccessDescriptorProperty::ColumnObject
];
73 OColumnTransferable::OColumnTransferable(const Reference
< XPropertySet
>& _rxForm
,
74 const OUString
& _rFieldName
, const Reference
< XPropertySet
>& _rxColumn
,
75 const Reference
< XConnection
>& _rxConnection
, ColumnTransferFormatFlags _nFormats
)
76 :m_nFormatFlags(_nFormats
)
78 OSL_ENSURE(_rxForm
.is(), "OColumnTransferable::OColumnTransferable: invalid form!");
79 // collect the necessary information from the form
81 sal_Int32 nCommandType
= CommandType::TABLE
;
82 OUString sDatasource
,sURL
;
84 bool bTryToParse
= true;
87 _rxForm
->getPropertyValue(FM_PROP_COMMANDTYPE
) >>= nCommandType
;
88 _rxForm
->getPropertyValue(FM_PROP_COMMAND
) >>= sCommand
;
89 _rxForm
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sDatasource
;
90 _rxForm
->getPropertyValue(FM_PROP_URL
) >>= sURL
;
91 bTryToParse
= ::cppu::any2bool(_rxForm
->getPropertyValue(FM_PROP_ESCAPE_PROCESSING
));
95 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
98 // If the data source is an SQL-statement and simple enough (means "select <field list> from <table> where...")
99 // we are able to fake the drag information we are about to create.
100 if (bTryToParse
&& (CommandType::COMMAND
== nCommandType
))
104 Reference
< XTablesSupplier
> xSupTab
;
105 _rxForm
->getPropertyValue("SingleSelectQueryComposer") >>= xSupTab
;
109 Reference
< XNameAccess
> xNames
= xSupTab
->getTables();
112 Sequence
< OUString
> aTables
= xNames
->getElementNames();
113 if (1 == aTables
.getLength())
115 sCommand
= aTables
[0];
116 nCommandType
= CommandType::TABLE
;
123 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
127 implConstruct(sDatasource
, sURL
,nCommandType
, sCommand
, _rFieldName
);
129 if ((m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
132 m_aDescriptor
[DataAccessDescriptorProperty::ColumnObject
] <<= _rxColumn
;
133 if (_rxConnection
.is())
134 m_aDescriptor
[DataAccessDescriptorProperty::Connection
] <<= _rxConnection
;
139 SotClipboardFormatId
OColumnTransferable::getDescriptorFormatId()
141 static SotClipboardFormatId s_nFormat
= static_cast<SotClipboardFormatId
>(-1);
142 if (static_cast<SotClipboardFormatId
>(-1) == s_nFormat
)
144 s_nFormat
= SotExchange::RegisterFormatName("application/x-openoffice;windows_formatname=\"dbaccess.ColumnDescriptorTransfer\"");
145 OSL_ENSURE(static_cast<SotClipboardFormatId
>(-1) != s_nFormat
, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
151 void OColumnTransferable::implConstruct( const OUString
& _rDatasource
152 ,const OUString
& _rConnectionResource
153 ,const sal_Int32 _nCommandType
154 ,const OUString
& _rCommand
155 , const OUString
& _rFieldName
)
157 const sal_Unicode cSeparator
= u
'\x000B';
158 const OUString
sSeparator(&cSeparator
, 1);
160 m_sCompatibleFormat
.clear();
161 m_sCompatibleFormat
+= _rDatasource
;
162 m_sCompatibleFormat
+= sSeparator
;
163 m_sCompatibleFormat
+= _rCommand
;
164 m_sCompatibleFormat
+= sSeparator
;
166 sal_Unicode cCommandType
;
167 switch (_nCommandType
)
169 case CommandType::TABLE
:
172 case CommandType::QUERY
:
179 m_sCompatibleFormat
+= OUString(&cCommandType
, 1);
180 m_sCompatibleFormat
+= sSeparator
;
181 m_sCompatibleFormat
+= _rFieldName
;
183 m_aDescriptor
.clear();
184 if ((m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
186 m_aDescriptor
.setDataSource(_rDatasource
);
187 if ( !_rConnectionResource
.isEmpty() )
188 m_aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] <<= _rConnectionResource
;
190 m_aDescriptor
[DataAccessDescriptorProperty::Command
] <<= _rCommand
;
191 m_aDescriptor
[DataAccessDescriptorProperty::CommandType
] <<= _nCommandType
;
192 m_aDescriptor
[DataAccessDescriptorProperty::ColumnName
] <<= _rFieldName
;
197 void OColumnTransferable::AddSupportedFormats()
199 if (ColumnTransferFormatFlags::CONTROL_EXCHANGE
& m_nFormatFlags
)
200 AddFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
);
202 if (ColumnTransferFormatFlags::FIELD_DESCRIPTOR
& m_nFormatFlags
)
203 AddFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
);
205 if (ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
& m_nFormatFlags
)
206 AddFormat(getDescriptorFormatId());
210 bool OColumnTransferable::GetData( const DataFlavor
& _rFlavor
, const OUString
& /*rDestDoc*/ )
212 const SotClipboardFormatId nFormatId
= SotExchange::GetFormat(_rFlavor
);
215 case SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
:
216 case SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
:
217 return SetString(m_sCompatibleFormat
, _rFlavor
);
220 if (nFormatId
== getDescriptorFormatId())
221 return SetAny( makeAny( m_aDescriptor
.createPropertyValueSequence() ) );
227 bool OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector
& _rFlavors
, ColumnTransferFormatFlags _nFormats
)
229 bool bFieldFormat
= bool(_nFormats
& ColumnTransferFormatFlags::FIELD_DESCRIPTOR
);
230 bool bControlFormat
= bool(_nFormats
& ColumnTransferFormatFlags::CONTROL_EXCHANGE
);
231 bool bDescriptorFormat
= bool(_nFormats
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
);
232 SotClipboardFormatId nFormatId
= getDescriptorFormatId();
233 return std::any_of(_rFlavors
.begin(), _rFlavors
.end(),
234 [&](const DataFlavorEx
& rCheck
) {
235 return (bFieldFormat
&& (SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
== rCheck
.mnSotId
))
236 || (bControlFormat
&& (SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
== rCheck
.mnSotId
))
237 || (bDescriptorFormat
&& (nFormatId
== rCheck
.mnSotId
));
242 ODataAccessDescriptor
OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper
& _rData
)
244 if (_rData
.HasFormat(getDescriptorFormatId()))
246 // the object has a real descriptor object (not just the old compatible format)
248 // extract the any from the transferable
251 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor
);
252 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
254 Any aDescriptor
= _rData
.GetAny(aFlavor
, OUString());
256 // extract the property value sequence
257 Sequence
< PropertyValue
> aDescriptorProps
;
258 bSuccess
= aDescriptor
>>= aDescriptorProps
;
259 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
261 // build the real descriptor
262 return ODataAccessDescriptor(aDescriptorProps
);
265 // only the old (compatible) format exists -> use the other extract method ...
266 OUString sDatasource
, sCommand
, sFieldName
,sDatabaseLocation
,sConnectionResource
;
267 sal_Int32 nCommandType
= CommandType::COMMAND
;
269 ODataAccessDescriptor aDescriptor
;
270 if (extractColumnDescriptor(_rData
, sDatasource
, sDatabaseLocation
,sConnectionResource
,nCommandType
, sCommand
, sFieldName
))
272 // and build an own descriptor
273 if ( !sDatasource
.isEmpty() )
274 aDescriptor
[DataAccessDescriptorProperty::DataSource
] <<= sDatasource
;
275 if ( !sDatabaseLocation
.isEmpty() )
276 aDescriptor
[DataAccessDescriptorProperty::DatabaseLocation
] <<= sDatabaseLocation
;
277 if ( !sConnectionResource
.isEmpty() )
278 aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] <<= sConnectionResource
;
280 aDescriptor
[DataAccessDescriptorProperty::Command
] <<= sCommand
;
281 aDescriptor
[DataAccessDescriptorProperty::CommandType
] <<= nCommandType
;
282 aDescriptor
[DataAccessDescriptorProperty::ColumnName
] <<= sFieldName
;
288 bool OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper
& _rData
289 ,OUString
& _rDatasource
290 ,OUString
& _rDatabaseLocation
291 ,OUString
& _rConnectionResource
292 ,sal_Int32
& _nCommandType
294 ,OUString
& _rFieldName
)
296 if ( _rData
.HasFormat(getDescriptorFormatId()) )
298 ODataAccessDescriptor aDescriptor
= extractColumnDescriptor(_rData
);
299 if ( aDescriptor
.has(DataAccessDescriptorProperty::DataSource
) )
300 aDescriptor
[DataAccessDescriptorProperty::DataSource
] >>= _rDatasource
;
301 if ( aDescriptor
.has(DataAccessDescriptorProperty::DatabaseLocation
) )
302 aDescriptor
[DataAccessDescriptorProperty::DatabaseLocation
] >>= _rDatabaseLocation
;
303 if ( aDescriptor
.has(DataAccessDescriptorProperty::ConnectionResource
) )
304 aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] >>= _rConnectionResource
;
306 aDescriptor
[DataAccessDescriptorProperty::Command
] >>= _rCommand
;
307 aDescriptor
[DataAccessDescriptorProperty::CommandType
] >>= _nCommandType
;
308 aDescriptor
[DataAccessDescriptorProperty::ColumnName
] >>= _rFieldName
;
312 // check if we have a (string) format we can use...
313 SotClipboardFormatId nRecognizedFormat
= SotClipboardFormatId::NONE
;
314 if (_rData
.HasFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
))
315 nRecognizedFormat
= SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
;
316 if (_rData
.HasFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
))
317 nRecognizedFormat
= SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
;
318 if (nRecognizedFormat
== SotClipboardFormatId::NONE
)
321 OUString sFieldDescription
;
322 (void)const_cast<TransferableDataHelper
&>(_rData
).GetString(nRecognizedFormat
, sFieldDescription
);
324 const sal_Unicode cSeparator
= u
'\x000B';
326 _rDatasource
= sFieldDescription
.getToken(0, cSeparator
, nIdx
);
327 _rCommand
= sFieldDescription
.getToken(0, cSeparator
, nIdx
);
328 _nCommandType
= sFieldDescription
.getToken(0, cSeparator
, nIdx
).toInt32();
329 _rFieldName
= sFieldDescription
.getToken(0, cSeparator
, nIdx
);
335 ODataAccessObjectTransferable::ODataAccessObjectTransferable(
336 const OUString
& _rDatasource
337 ,const sal_Int32 _nCommandType
338 ,const OUString
& _rCommand
341 construct(_rDatasource
,OUString(),_nCommandType
,_rCommand
,nullptr,(CommandType::COMMAND
== _nCommandType
),_rCommand
);
344 ODataAccessObjectTransferable::ODataAccessObjectTransferable(
345 const OUString
& _rDatasource
346 ,const sal_Int32 _nCommandType
347 ,const OUString
& _rCommand
348 ,const Reference
< XConnection
>& _rxConnection
)
350 OSL_ENSURE(_rxConnection
.is(),"Wrong ctor used.!");
351 construct(_rDatasource
,OUString(),_nCommandType
,_rCommand
,_rxConnection
,(CommandType::COMMAND
== _nCommandType
),_rCommand
);
355 ODataAccessObjectTransferable::ODataAccessObjectTransferable(const Reference
< XPropertySet
>& _rxLivingForm
)
357 // collect some properties of the form
358 OUString sDatasourceName
,sConnectionResource
;
359 sal_Int32 nObjectType
= CommandType::COMMAND
;
360 OUString sObjectName
;
361 Reference
< XConnection
> xConnection
;
364 _rxLivingForm
->getPropertyValue(FM_PROP_COMMANDTYPE
) >>= nObjectType
;
365 _rxLivingForm
->getPropertyValue(FM_PROP_COMMAND
) >>= sObjectName
;
366 _rxLivingForm
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sDatasourceName
;
367 _rxLivingForm
->getPropertyValue(FM_PROP_URL
) >>= sConnectionResource
;
368 _rxLivingForm
->getPropertyValue(FM_PROP_ACTIVE_CONNECTION
) >>= xConnection
;
372 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
376 // check if the SQL-statement is modified
377 OUString sCompleteStatement
;
380 _rxLivingForm
->getPropertyValue(FM_PROP_ACTIVECOMMAND
) >>= sCompleteStatement
;
382 catch (const Exception
&)
384 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
388 construct( sDatasourceName
391 ,sObjectName
,xConnection
392 ,CommandType::QUERY
!= nObjectType
393 ,sCompleteStatement
);
397 void ODataAccessObjectTransferable::AddSupportedFormats()
399 sal_Int32 nObjectType
= CommandType::COMMAND
;
400 m_aDescriptor
[DataAccessDescriptorProperty::CommandType
] >>= nObjectType
;
403 case CommandType::TABLE
:
404 AddFormat(SotClipboardFormatId::DBACCESS_TABLE
);
406 case CommandType::QUERY
:
407 AddFormat(SotClipboardFormatId::DBACCESS_QUERY
);
409 case CommandType::COMMAND
:
410 AddFormat(SotClipboardFormatId::DBACCESS_COMMAND
);
414 if (!m_sCompatibleObjectDescription
.isEmpty())
415 AddFormat(SotClipboardFormatId::SBA_DATAEXCHANGE
);
419 bool ODataAccessObjectTransferable::GetData( const DataFlavor
& rFlavor
, const OUString
& /*rDestDoc*/ )
421 SotClipboardFormatId nFormat
= SotExchange::GetFormat(rFlavor
);
424 case SotClipboardFormatId::DBACCESS_TABLE
:
425 case SotClipboardFormatId::DBACCESS_QUERY
:
426 case SotClipboardFormatId::DBACCESS_COMMAND
:
427 return SetAny( makeAny(m_aDescriptor
.createPropertyValueSequence()) );
429 case SotClipboardFormatId::SBA_DATAEXCHANGE
:
430 return SetString(m_sCompatibleObjectDescription
, rFlavor
);
437 bool ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector
& _rFlavors
)
439 return std::any_of(_rFlavors
.begin(), _rFlavors
.end(),
440 [](const DataFlavorEx
& rCheck
) {
441 return SotClipboardFormatId::DBACCESS_TABLE
== rCheck
.mnSotId
442 || SotClipboardFormatId::DBACCESS_QUERY
== rCheck
.mnSotId
443 || SotClipboardFormatId::DBACCESS_COMMAND
== rCheck
.mnSotId
;
448 ODataAccessDescriptor
ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper
& _rData
)
450 SotClipboardFormatId nKnownFormatId
= SotClipboardFormatId::NONE
;
451 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_TABLE
) )
452 nKnownFormatId
= SotClipboardFormatId::DBACCESS_TABLE
;
453 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_QUERY
) )
454 nKnownFormatId
= SotClipboardFormatId::DBACCESS_QUERY
;
455 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_COMMAND
) )
456 nKnownFormatId
= SotClipboardFormatId::DBACCESS_COMMAND
;
458 if (SotClipboardFormatId::NONE
!= nKnownFormatId
)
460 // extract the any from the transferable
463 SotExchange::GetFormatDataFlavor(nKnownFormatId
, aFlavor
);
464 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
466 Any aDescriptor
= _rData
.GetAny(aFlavor
, OUString());
468 // extract the property value sequence
469 Sequence
< PropertyValue
> aDescriptorProps
;
470 bSuccess
= aDescriptor
>>= aDescriptorProps
;
471 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
473 // build the real descriptor
474 return ODataAccessDescriptor(aDescriptorProps
);
477 OSL_FAIL( "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
478 return ODataAccessDescriptor();
482 void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence
< Any
>& _rSelRows
)
484 const sal_Unicode
cSeparator(11);
485 const OUString
sSeparator(&cSeparator
, 1);
487 for ( const Any
& rSelRow
: _rSelRows
)
489 sal_Int32
nSelectedRow( 0 );
490 OSL_VERIFY( rSelRow
>>= nSelectedRow
);
492 m_sCompatibleObjectDescription
+= OUString::number(nSelectedRow
);
493 m_sCompatibleObjectDescription
+= sSeparator
;
498 void ODataAccessObjectTransferable::ObjectReleased()
500 m_aDescriptor
.clear();
503 void ODataAccessObjectTransferable::construct( const OUString
& _rDatasource
504 ,const OUString
& _rConnectionResource
505 ,const sal_Int32 _nCommandType
506 ,const OUString
& _rCommand
507 ,const Reference
< XConnection
>& _rxConnection
509 ,const OUString
& _sActiveCommand
)
511 m_aDescriptor
.setDataSource(_rDatasource
);
512 // build the descriptor (the property sequence)
513 if ( !_rConnectionResource
.isEmpty() )
514 m_aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] <<= _rConnectionResource
;
515 if ( _rxConnection
.is() )
516 m_aDescriptor
[DataAccessDescriptorProperty::Connection
] <<= _rxConnection
;
517 m_aDescriptor
[DataAccessDescriptorProperty::Command
] <<= _rCommand
;
518 m_aDescriptor
[DataAccessDescriptorProperty::CommandType
] <<= _nCommandType
;
520 // extract the single values from the sequence
522 OUString sObjectName
= _rCommand
;
524 // for compatibility: create a string which can be used for the SotClipboardFormatId::SBA_DATAEXCHANGE format
526 bool bTreatAsStatement
= (CommandType::COMMAND
== _nCommandType
);
527 // statements are - in this old and ugly format - described as queries
529 const sal_Unicode cSeparator
= u
'\x000B';
530 const OUString
sSeparator(&cSeparator
, 1);
532 const sal_Unicode cTableMark
= '1';
533 const sal_Unicode cQueryMark
= '0';
535 // build the descriptor string
536 m_sCompatibleObjectDescription
+= _rDatasource
;
537 m_sCompatibleObjectDescription
+= sSeparator
;
538 m_sCompatibleObjectDescription
+= bTreatAsStatement
? OUString() : sObjectName
;
539 m_sCompatibleObjectDescription
+= sSeparator
;
540 switch (_nCommandType
)
542 case CommandType::TABLE
:
543 m_sCompatibleObjectDescription
+= OUString(&cTableMark
, 1);
545 case CommandType::QUERY
:
546 m_sCompatibleObjectDescription
+= OUString(&cQueryMark
, 1);
548 case CommandType::COMMAND
:
549 m_sCompatibleObjectDescription
+= OUString(&cQueryMark
, 1);
550 // think of it as a query
553 m_sCompatibleObjectDescription
+= sSeparator
;
554 m_sCompatibleObjectDescription
+= _bAddCommand
? _sActiveCommand
: OUString();
555 m_sCompatibleObjectDescription
+= sSeparator
;
559 OMultiColumnTransferable::OMultiColumnTransferable(const Sequence
< PropertyValue
>& _aDescriptors
) : m_aDescriptors(_aDescriptors
)
563 SotClipboardFormatId
OMultiColumnTransferable::getDescriptorFormatId()
565 static SotClipboardFormatId s_nFormat
= static_cast<SotClipboardFormatId
>(-1);
566 if (static_cast<SotClipboardFormatId
>(-1) == s_nFormat
)
568 s_nFormat
= SotExchange::RegisterFormatName("application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\"");
569 OSL_ENSURE(static_cast<SotClipboardFormatId
>(-1) != s_nFormat
, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
574 void OMultiColumnTransferable::AddSupportedFormats()
576 AddFormat(getDescriptorFormatId());
579 bool OMultiColumnTransferable::GetData( const DataFlavor
& _rFlavor
, const OUString
& /*rDestDoc*/ )
581 const SotClipboardFormatId nFormatId
= SotExchange::GetFormat(_rFlavor
);
582 if (nFormatId
== getDescriptorFormatId())
584 return SetAny( makeAny( m_aDescriptors
) );
591 bool OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector
& _rFlavors
)
593 const SotClipboardFormatId nFormatId
= getDescriptorFormatId();
594 return std::all_of(_rFlavors
.begin(), _rFlavors
.end(),
595 [&nFormatId
](const DataFlavorEx
& rCheck
) { return nFormatId
== rCheck
.mnSotId
; });
599 Sequence
< PropertyValue
> OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper
& _rData
)
601 Sequence
< PropertyValue
> aList
;
602 if (_rData
.HasFormat(getDescriptorFormatId()))
604 // extract the any from the transferable
607 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor
);
608 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
610 _rData
.GetAny(aFlavor
, OUString()) >>= aList
;
611 } // if (_rData.HasFormat(getDescriptorFormatId()))
615 void OMultiColumnTransferable::ObjectReleased()
617 m_aDescriptors
.realloc(0);
624 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */