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/beans/XPropertySet.hpp>
23 #include <com/sun/star/sdb/CommandType.hpp>
24 #include <com/sun/star/sdbc/XConnection.hpp>
25 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
27 #include <comphelper/extract.hxx>
28 #include <sot/formats.hxx>
29 #include <sot/exchange.hxx>
30 #include <o3tl/string_view.hxx>
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::beans
;
39 using namespace ::com::sun::star::sdb
;
40 using namespace ::com::sun::star::sdbc
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::sdbcx
;
43 using namespace ::com::sun::star::container
;
44 using namespace ::com::sun::star::datatransfer
;
46 OColumnTransferable::OColumnTransferable(ColumnTransferFormatFlags nFormats
)
47 : m_nFormatFlags(nFormats
)
51 void OColumnTransferable::setDescriptor(const ODataAccessDescriptor
& rDescriptor
)
55 OUString sDataSource
, sDatabaseLocation
, sConnectionResource
, sCommand
, sFieldName
;
56 if ( rDescriptor
.has( DataAccessDescriptorProperty::DataSource
) ) rDescriptor
[ DataAccessDescriptorProperty::DataSource
] >>= sDataSource
;
57 if ( rDescriptor
.has( DataAccessDescriptorProperty::DatabaseLocation
) ) rDescriptor
[ DataAccessDescriptorProperty::DatabaseLocation
] >>= sDatabaseLocation
;
58 if ( rDescriptor
.has( DataAccessDescriptorProperty::ConnectionResource
) ) rDescriptor
[ DataAccessDescriptorProperty::ConnectionResource
] >>= sConnectionResource
;
59 if ( rDescriptor
.has( DataAccessDescriptorProperty::Command
) ) rDescriptor
[ DataAccessDescriptorProperty::Command
] >>= sCommand
;
60 if ( rDescriptor
.has( DataAccessDescriptorProperty::ColumnName
) ) rDescriptor
[ DataAccessDescriptorProperty::ColumnName
] >>= sFieldName
;
62 sal_Int32 nCommandType
= CommandType::TABLE
;
63 OSL_VERIFY( rDescriptor
[ DataAccessDescriptorProperty::CommandType
] >>= nCommandType
);
66 sDataSource
.isEmpty() ? sDatabaseLocation
: sDataSource
,
67 sConnectionResource
, nCommandType
, sCommand
, sFieldName
);
69 if ( m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
71 if ( rDescriptor
.has( DataAccessDescriptorProperty::Connection
) )
72 m_aDescriptor
[ DataAccessDescriptorProperty::Connection
] = rDescriptor
[ DataAccessDescriptorProperty::Connection
];
73 if ( rDescriptor
.has( DataAccessDescriptorProperty::ColumnObject
) )
74 m_aDescriptor
[ DataAccessDescriptorProperty::ColumnObject
] = rDescriptor
[ DataAccessDescriptorProperty::ColumnObject
];
78 OColumnTransferable::OColumnTransferable(const Reference
< XPropertySet
>& _rxForm
,
79 const OUString
& _rFieldName
, const Reference
< XPropertySet
>& _rxColumn
,
80 const Reference
< XConnection
>& _rxConnection
, ColumnTransferFormatFlags _nFormats
)
81 :m_nFormatFlags(_nFormats
)
83 OSL_ENSURE(_rxForm
.is(), "OColumnTransferable::OColumnTransferable: invalid form!");
84 // collect the necessary information from the form
86 sal_Int32 nCommandType
= CommandType::TABLE
;
87 OUString sDatasource
,sURL
;
89 bool bTryToParse
= true;
92 _rxForm
->getPropertyValue(FM_PROP_COMMANDTYPE
) >>= nCommandType
;
93 _rxForm
->getPropertyValue(FM_PROP_COMMAND
) >>= sCommand
;
94 _rxForm
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sDatasource
;
95 _rxForm
->getPropertyValue(FM_PROP_URL
) >>= sURL
;
96 bTryToParse
= ::cppu::any2bool(_rxForm
->getPropertyValue(FM_PROP_ESCAPE_PROCESSING
));
100 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
103 // If the data source is an SQL-statement and simple enough (means "select <field list> from <table> where...")
104 // we are able to fake the drag information we are about to create.
105 if (bTryToParse
&& (CommandType::COMMAND
== nCommandType
))
109 Reference
< XTablesSupplier
> xSupTab
;
110 _rxForm
->getPropertyValue("SingleSelectQueryComposer") >>= xSupTab
;
114 Reference
< XNameAccess
> xNames
= xSupTab
->getTables();
117 Sequence
< OUString
> aTables
= xNames
->getElementNames();
118 if (1 == aTables
.getLength())
120 sCommand
= aTables
[0];
121 nCommandType
= CommandType::TABLE
;
128 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
132 implConstruct(sDatasource
, sURL
,nCommandType
, sCommand
, _rFieldName
);
134 if ((m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
137 m_aDescriptor
[DataAccessDescriptorProperty::ColumnObject
] <<= _rxColumn
;
138 if (_rxConnection
.is())
139 m_aDescriptor
[DataAccessDescriptorProperty::Connection
] <<= _rxConnection
;
144 SotClipboardFormatId
OColumnTransferable::getDescriptorFormatId()
146 static SotClipboardFormatId s_nFormat
= static_cast<SotClipboardFormatId
>(-1);
147 if (static_cast<SotClipboardFormatId
>(-1) == s_nFormat
)
149 s_nFormat
= SotExchange::RegisterFormatName("application/x-openoffice;windows_formatname=\"dbaccess.ColumnDescriptorTransfer\"");
150 OSL_ENSURE(static_cast<SotClipboardFormatId
>(-1) != s_nFormat
, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
156 void OColumnTransferable::implConstruct( const OUString
& _rDatasource
157 ,const OUString
& _rConnectionResource
158 ,const sal_Int32 _nCommandType
159 ,const OUString
& _rCommand
160 , const OUString
& _rFieldName
)
162 const sal_Unicode cSeparator
= u
'\x000B';
163 const OUString
sSeparator(&cSeparator
, 1);
165 m_sCompatibleFormat
.clear();
166 m_sCompatibleFormat
+= _rDatasource
;
167 m_sCompatibleFormat
+= sSeparator
;
168 m_sCompatibleFormat
+= _rCommand
;
169 m_sCompatibleFormat
+= sSeparator
;
171 sal_Unicode cCommandType
;
172 switch (_nCommandType
)
174 case CommandType::TABLE
:
177 case CommandType::QUERY
:
184 m_sCompatibleFormat
+= OUStringChar(cCommandType
);
185 m_sCompatibleFormat
+= sSeparator
;
186 m_sCompatibleFormat
+= _rFieldName
;
188 m_aDescriptor
.clear();
189 if ((m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
191 m_aDescriptor
.setDataSource(_rDatasource
);
192 if ( !_rConnectionResource
.isEmpty() )
193 m_aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] <<= _rConnectionResource
;
195 m_aDescriptor
[DataAccessDescriptorProperty::Command
] <<= _rCommand
;
196 m_aDescriptor
[DataAccessDescriptorProperty::CommandType
] <<= _nCommandType
;
197 m_aDescriptor
[DataAccessDescriptorProperty::ColumnName
] <<= _rFieldName
;
202 void OColumnTransferable::AddSupportedFormats()
204 if (ColumnTransferFormatFlags::CONTROL_EXCHANGE
& m_nFormatFlags
)
205 AddFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
);
207 if (ColumnTransferFormatFlags::FIELD_DESCRIPTOR
& m_nFormatFlags
)
208 AddFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
);
210 if (ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
& m_nFormatFlags
)
211 AddFormat(getDescriptorFormatId());
215 bool OColumnTransferable::GetData( const DataFlavor
& _rFlavor
, const OUString
& /*rDestDoc*/ )
217 const SotClipboardFormatId nFormatId
= SotExchange::GetFormat(_rFlavor
);
220 case SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
:
221 case SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
:
222 return SetString(m_sCompatibleFormat
);
225 if (nFormatId
== getDescriptorFormatId())
226 return SetAny( Any( m_aDescriptor
.createPropertyValueSequence() ) );
232 bool OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector
& _rFlavors
, ColumnTransferFormatFlags _nFormats
)
234 bool bFieldFormat
= bool(_nFormats
& ColumnTransferFormatFlags::FIELD_DESCRIPTOR
);
235 bool bControlFormat
= bool(_nFormats
& ColumnTransferFormatFlags::CONTROL_EXCHANGE
);
236 bool bDescriptorFormat
= bool(_nFormats
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
);
237 SotClipboardFormatId nFormatId
= getDescriptorFormatId();
238 return std::any_of(_rFlavors
.begin(), _rFlavors
.end(),
239 [&](const DataFlavorEx
& rCheck
) {
240 return (bFieldFormat
&& (SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
== rCheck
.mnSotId
))
241 || (bControlFormat
&& (SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
== rCheck
.mnSotId
))
242 || (bDescriptorFormat
&& (nFormatId
== rCheck
.mnSotId
));
247 ODataAccessDescriptor
OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper
& _rData
)
249 if (_rData
.HasFormat(getDescriptorFormatId()))
251 // the object has a real descriptor object (not just the old compatible format)
253 // extract the any from the transferable
256 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor
);
257 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
259 Any aDescriptor
= _rData
.GetAny(aFlavor
, OUString());
261 // extract the property value sequence
262 Sequence
< PropertyValue
> aDescriptorProps
;
263 bSuccess
= aDescriptor
>>= aDescriptorProps
;
264 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
266 // build the real descriptor
267 return ODataAccessDescriptor(aDescriptorProps
);
270 // only the old (compatible) format exists -> use the other extract method ...
271 OUString sDatasource
, sCommand
, sFieldName
,sDatabaseLocation
,sConnectionResource
;
272 sal_Int32 nCommandType
= CommandType::COMMAND
;
274 ODataAccessDescriptor aDescriptor
;
275 if (extractColumnDescriptor(_rData
, sDatasource
, sDatabaseLocation
,sConnectionResource
,nCommandType
, sCommand
, sFieldName
))
277 // and build an own descriptor
278 if ( !sDatasource
.isEmpty() )
279 aDescriptor
[DataAccessDescriptorProperty::DataSource
] <<= sDatasource
;
280 if ( !sDatabaseLocation
.isEmpty() )
281 aDescriptor
[DataAccessDescriptorProperty::DatabaseLocation
] <<= sDatabaseLocation
;
282 if ( !sConnectionResource
.isEmpty() )
283 aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] <<= sConnectionResource
;
285 aDescriptor
[DataAccessDescriptorProperty::Command
] <<= sCommand
;
286 aDescriptor
[DataAccessDescriptorProperty::CommandType
] <<= nCommandType
;
287 aDescriptor
[DataAccessDescriptorProperty::ColumnName
] <<= sFieldName
;
293 bool OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper
& _rData
294 ,OUString
& _rDatasource
295 ,OUString
& _rDatabaseLocation
296 ,OUString
& _rConnectionResource
297 ,sal_Int32
& _nCommandType
299 ,OUString
& _rFieldName
)
301 if ( _rData
.HasFormat(getDescriptorFormatId()) )
303 ODataAccessDescriptor aDescriptor
= extractColumnDescriptor(_rData
);
304 if ( aDescriptor
.has(DataAccessDescriptorProperty::DataSource
) )
305 aDescriptor
[DataAccessDescriptorProperty::DataSource
] >>= _rDatasource
;
306 if ( aDescriptor
.has(DataAccessDescriptorProperty::DatabaseLocation
) )
307 aDescriptor
[DataAccessDescriptorProperty::DatabaseLocation
] >>= _rDatabaseLocation
;
308 if ( aDescriptor
.has(DataAccessDescriptorProperty::ConnectionResource
) )
309 aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] >>= _rConnectionResource
;
311 aDescriptor
[DataAccessDescriptorProperty::Command
] >>= _rCommand
;
312 aDescriptor
[DataAccessDescriptorProperty::CommandType
] >>= _nCommandType
;
313 aDescriptor
[DataAccessDescriptorProperty::ColumnName
] >>= _rFieldName
;
317 // check if we have a (string) format we can use...
318 SotClipboardFormatId nRecognizedFormat
= SotClipboardFormatId::NONE
;
319 if (_rData
.HasFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
))
320 nRecognizedFormat
= SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
;
321 if (_rData
.HasFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
))
322 nRecognizedFormat
= SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
;
323 if (nRecognizedFormat
== SotClipboardFormatId::NONE
)
326 OUString sFieldDescription
;
327 (void)_rData
.GetString(nRecognizedFormat
, sFieldDescription
);
329 const sal_Unicode cSeparator
= u
'\x000B';
331 _rDatasource
= sFieldDescription
.getToken(0, cSeparator
, nIdx
);
332 _rCommand
= sFieldDescription
.getToken(0, cSeparator
, nIdx
);
333 _nCommandType
= o3tl::toInt32(o3tl::getToken(sFieldDescription
, 0, cSeparator
, nIdx
));
334 _rFieldName
= sFieldDescription
.getToken(0, cSeparator
, nIdx
);
339 ODataAccessObjectTransferable::ODataAccessObjectTransferable()
343 void ODataAccessObjectTransferable::Update(
344 const OUString
& _rDatasource
,
345 const sal_Int32 _nCommandType
,
346 const OUString
& _rCommand
)
348 construct(_rDatasource
,OUString(),_nCommandType
,_rCommand
,nullptr,(CommandType::COMMAND
== _nCommandType
),_rCommand
);
351 void ODataAccessObjectTransferable::Update(
352 const OUString
& _rDatasource
,
353 const sal_Int32 _nCommandType
,
354 const OUString
& _rCommand
,
355 const Reference
< XConnection
>& _rxConnection
)
357 OSL_ENSURE(_rxConnection
.is(), "Wrong Update used.!");
358 construct(_rDatasource
,OUString(),_nCommandType
,_rCommand
,_rxConnection
,(CommandType::COMMAND
== _nCommandType
),_rCommand
);
361 ODataAccessObjectTransferable::ODataAccessObjectTransferable(const Reference
< XPropertySet
>& _rxLivingForm
)
363 // collect some properties of the form
364 OUString sDatasourceName
,sConnectionResource
;
365 sal_Int32 nObjectType
= CommandType::COMMAND
;
366 OUString sObjectName
;
367 Reference
< XConnection
> xConnection
;
370 _rxLivingForm
->getPropertyValue(FM_PROP_COMMANDTYPE
) >>= nObjectType
;
371 _rxLivingForm
->getPropertyValue(FM_PROP_COMMAND
) >>= sObjectName
;
372 _rxLivingForm
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sDatasourceName
;
373 _rxLivingForm
->getPropertyValue(FM_PROP_URL
) >>= sConnectionResource
;
374 _rxLivingForm
->getPropertyValue(FM_PROP_ACTIVE_CONNECTION
) >>= xConnection
;
378 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
382 // check if the SQL-statement is modified
383 OUString sCompleteStatement
;
386 _rxLivingForm
->getPropertyValue(FM_PROP_ACTIVECOMMAND
) >>= sCompleteStatement
;
388 catch (const Exception
&)
390 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
394 construct( sDatasourceName
397 ,sObjectName
,xConnection
398 ,CommandType::QUERY
!= nObjectType
399 ,sCompleteStatement
);
403 void ODataAccessObjectTransferable::AddSupportedFormats()
405 sal_Int32 nObjectType
= CommandType::COMMAND
;
406 m_aDescriptor
[DataAccessDescriptorProperty::CommandType
] >>= nObjectType
;
409 case CommandType::TABLE
:
410 AddFormat(SotClipboardFormatId::DBACCESS_TABLE
);
412 case CommandType::QUERY
:
413 AddFormat(SotClipboardFormatId::DBACCESS_QUERY
);
415 case CommandType::COMMAND
:
416 AddFormat(SotClipboardFormatId::DBACCESS_COMMAND
);
420 if (!m_sCompatibleObjectDescription
.isEmpty())
421 AddFormat(SotClipboardFormatId::SBA_DATAEXCHANGE
);
425 bool ODataAccessObjectTransferable::GetData( const DataFlavor
& rFlavor
, const OUString
& /*rDestDoc*/ )
427 SotClipboardFormatId nFormat
= SotExchange::GetFormat(rFlavor
);
430 case SotClipboardFormatId::DBACCESS_TABLE
:
431 case SotClipboardFormatId::DBACCESS_QUERY
:
432 case SotClipboardFormatId::DBACCESS_COMMAND
:
433 return SetAny( Any(m_aDescriptor
.createPropertyValueSequence()) );
435 case SotClipboardFormatId::SBA_DATAEXCHANGE
:
436 return SetString(m_sCompatibleObjectDescription
);
443 bool ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector
& _rFlavors
)
445 return std::any_of(_rFlavors
.begin(), _rFlavors
.end(),
446 [](const DataFlavorEx
& rCheck
) {
447 return SotClipboardFormatId::DBACCESS_TABLE
== rCheck
.mnSotId
448 || SotClipboardFormatId::DBACCESS_QUERY
== rCheck
.mnSotId
449 || SotClipboardFormatId::DBACCESS_COMMAND
== rCheck
.mnSotId
;
454 ODataAccessDescriptor
ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper
& _rData
)
456 SotClipboardFormatId nKnownFormatId
= SotClipboardFormatId::NONE
;
457 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_TABLE
) )
458 nKnownFormatId
= SotClipboardFormatId::DBACCESS_TABLE
;
459 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_QUERY
) )
460 nKnownFormatId
= SotClipboardFormatId::DBACCESS_QUERY
;
461 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_COMMAND
) )
462 nKnownFormatId
= SotClipboardFormatId::DBACCESS_COMMAND
;
464 if (SotClipboardFormatId::NONE
!= nKnownFormatId
)
466 // extract the any from the transferable
469 SotExchange::GetFormatDataFlavor(nKnownFormatId
, aFlavor
);
470 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
472 Any aDescriptor
= _rData
.GetAny(aFlavor
, OUString());
474 // extract the property value sequence
475 Sequence
< PropertyValue
> aDescriptorProps
;
476 bSuccess
= aDescriptor
>>= aDescriptorProps
;
477 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
479 // build the real descriptor
480 return ODataAccessDescriptor(aDescriptorProps
);
483 OSL_FAIL( "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
484 return ODataAccessDescriptor();
488 void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence
< Any
>& _rSelRows
)
490 const sal_Unicode
cSeparator(11);
491 const OUString
sSeparator(&cSeparator
, 1);
493 for ( const Any
& rSelRow
: _rSelRows
)
495 sal_Int32
nSelectedRow( 0 );
496 OSL_VERIFY( rSelRow
>>= nSelectedRow
);
498 m_sCompatibleObjectDescription
+= OUString::number(nSelectedRow
);
499 m_sCompatibleObjectDescription
+= sSeparator
;
504 void ODataAccessObjectTransferable::ObjectReleased()
506 m_aDescriptor
.clear();
509 void ODataAccessObjectTransferable::construct( const OUString
& _rDatasource
510 ,const OUString
& _rConnectionResource
511 ,const sal_Int32 _nCommandType
512 ,const OUString
& _rCommand
513 ,const Reference
< XConnection
>& _rxConnection
515 ,const OUString
& _sActiveCommand
)
517 m_aDescriptor
.setDataSource(_rDatasource
);
518 // build the descriptor (the property sequence)
519 if ( !_rConnectionResource
.isEmpty() )
520 m_aDescriptor
[DataAccessDescriptorProperty::ConnectionResource
] <<= _rConnectionResource
;
521 if ( _rxConnection
.is() )
522 m_aDescriptor
[DataAccessDescriptorProperty::Connection
] <<= _rxConnection
;
523 m_aDescriptor
[DataAccessDescriptorProperty::Command
] <<= _rCommand
;
524 m_aDescriptor
[DataAccessDescriptorProperty::CommandType
] <<= _nCommandType
;
526 // extract the single values from the sequence
528 OUString sObjectName
= _rCommand
;
530 // for compatibility: create a string which can be used for the SotClipboardFormatId::SBA_DATAEXCHANGE format
532 bool bTreatAsStatement
= (CommandType::COMMAND
== _nCommandType
);
533 // statements are - in this old and ugly format - described as queries
535 const sal_Unicode cSeparator
= u
'\x000B';
536 const OUString
sSeparator(&cSeparator
, 1);
538 const sal_Unicode cTableMark
= '1';
539 const sal_Unicode cQueryMark
= '0';
541 // build the descriptor string
542 m_sCompatibleObjectDescription
+= _rDatasource
;
543 m_sCompatibleObjectDescription
+= sSeparator
;
544 m_sCompatibleObjectDescription
+= bTreatAsStatement
? OUString() : sObjectName
;
545 m_sCompatibleObjectDescription
+= sSeparator
;
546 switch (_nCommandType
)
548 case CommandType::TABLE
:
549 m_sCompatibleObjectDescription
+= OUStringChar(cTableMark
);
551 case CommandType::QUERY
:
552 m_sCompatibleObjectDescription
+= OUStringChar(cQueryMark
);
554 case CommandType::COMMAND
:
555 m_sCompatibleObjectDescription
+= OUStringChar(cQueryMark
);
556 // think of it as a query
559 m_sCompatibleObjectDescription
+= sSeparator
;
560 m_sCompatibleObjectDescription
+= _bAddCommand
? _sActiveCommand
: OUString();
561 m_sCompatibleObjectDescription
+= sSeparator
;
564 OMultiColumnTransferable::OMultiColumnTransferable()
568 void OMultiColumnTransferable::setDescriptors(const Sequence
< PropertyValue
>& rDescriptors
)
571 m_aDescriptors
= rDescriptors
;
574 SotClipboardFormatId
OMultiColumnTransferable::getDescriptorFormatId()
576 static SotClipboardFormatId s_nFormat
= static_cast<SotClipboardFormatId
>(-1);
577 if (static_cast<SotClipboardFormatId
>(-1) == s_nFormat
)
579 s_nFormat
= SotExchange::RegisterFormatName("application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\"");
580 OSL_ENSURE(static_cast<SotClipboardFormatId
>(-1) != s_nFormat
, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
585 void OMultiColumnTransferable::AddSupportedFormats()
587 AddFormat(getDescriptorFormatId());
590 bool OMultiColumnTransferable::GetData( const DataFlavor
& _rFlavor
, const OUString
& /*rDestDoc*/ )
592 const SotClipboardFormatId nFormatId
= SotExchange::GetFormat(_rFlavor
);
593 if (nFormatId
== getDescriptorFormatId())
595 return SetAny( Any( m_aDescriptors
) );
601 bool OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector
& _rFlavors
)
603 const SotClipboardFormatId nFormatId
= getDescriptorFormatId();
604 return std::all_of(_rFlavors
.begin(), _rFlavors
.end(),
605 [&nFormatId
](const DataFlavorEx
& rCheck
) { return nFormatId
== rCheck
.mnSotId
; });
608 Sequence
< PropertyValue
> OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper
& _rData
)
610 Sequence
< PropertyValue
> aList
;
611 if (_rData
.HasFormat(getDescriptorFormatId()))
613 // extract the any from the transferable
616 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor
);
617 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
619 _rData
.GetAny(aFlavor
, OUString()) >>= aList
;
620 } // if (_rData.HasFormat(getDescriptorFormatId()))
624 void OMultiColumnTransferable::ObjectReleased()
626 m_aDescriptors
.realloc(0);
630 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */