sd: keep a non-owning pointer to the OverridingShell
[LibreOffice.git] / svx / source / fmcomp / dbaexchange.cxx
blobd2b71656b0c3c806a8f6bd9c113565932e7987b1
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 <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>
26 #include <fmprop.hxx>
27 #include <comphelper/extract.hxx>
28 #include <sot/formats.hxx>
29 #include <sot/exchange.hxx>
30 #include <o3tl/string_view.hxx>
33 namespace svx
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::sdbcx;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::datatransfer;
45 OColumnTransferable::OColumnTransferable(ColumnTransferFormatFlags nFormats)
46 : m_nFormatFlags(nFormats)
50 void OColumnTransferable::setDescriptor(const ODataAccessDescriptor& rDescriptor)
52 ClearFormats();
54 OUString sDataSource, sDatabaseLocation, sConnectionResource, sCommand, sFieldName;
55 if ( rDescriptor.has( DataAccessDescriptorProperty::DataSource ) ) rDescriptor[ DataAccessDescriptorProperty::DataSource ] >>= sDataSource;
56 if ( rDescriptor.has( DataAccessDescriptorProperty::DatabaseLocation ) ) rDescriptor[ DataAccessDescriptorProperty::DatabaseLocation ] >>= sDatabaseLocation;
57 if ( rDescriptor.has( DataAccessDescriptorProperty::ConnectionResource ) ) rDescriptor[ DataAccessDescriptorProperty::ConnectionResource ] >>= sConnectionResource;
58 if ( rDescriptor.has( DataAccessDescriptorProperty::Command ) ) rDescriptor[ DataAccessDescriptorProperty::Command ] >>= sCommand;
59 if ( rDescriptor.has( DataAccessDescriptorProperty::ColumnName ) ) rDescriptor[ DataAccessDescriptorProperty::ColumnName ] >>= sFieldName;
61 sal_Int32 nCommandType = CommandType::TABLE;
62 OSL_VERIFY( rDescriptor[ DataAccessDescriptorProperty::CommandType ] >>= nCommandType );
64 implConstruct(
65 sDataSource.isEmpty() ? sDatabaseLocation : sDataSource,
66 sConnectionResource, nCommandType, sCommand, sFieldName );
68 if ( m_nFormatFlags & ColumnTransferFormatFlags::COLUMN_DESCRIPTOR )
70 if ( rDescriptor.has( DataAccessDescriptorProperty::Connection ) )
71 m_aDescriptor[ DataAccessDescriptorProperty::Connection ] = rDescriptor[ DataAccessDescriptorProperty::Connection ];
72 if ( rDescriptor.has( DataAccessDescriptorProperty::ColumnObject ) )
73 m_aDescriptor[ DataAccessDescriptorProperty::ColumnObject ] = rDescriptor[ DataAccessDescriptorProperty::ColumnObject ];
77 OColumnTransferable::OColumnTransferable(const Reference< XPropertySet >& _rxForm,
78 const OUString& _rFieldName, const Reference< XPropertySet >& _rxColumn,
79 const Reference< XConnection >& _rxConnection, ColumnTransferFormatFlags _nFormats)
80 :m_nFormatFlags(_nFormats)
82 OSL_ENSURE(_rxForm.is(), "OColumnTransferable::OColumnTransferable: invalid form!");
83 // collect the necessary information from the form
84 OUString sCommand;
85 sal_Int32 nCommandType = CommandType::TABLE;
86 OUString sDatasource,sURL;
88 bool bTryToParse = true;
89 try
91 _rxForm->getPropertyValue(FM_PROP_COMMANDTYPE) >>= nCommandType;
92 _rxForm->getPropertyValue(FM_PROP_COMMAND) >>= sCommand;
93 _rxForm->getPropertyValue(FM_PROP_DATASOURCE) >>= sDatasource;
94 _rxForm->getPropertyValue(FM_PROP_URL) >>= sURL;
95 bTryToParse = ::cppu::any2bool(_rxForm->getPropertyValue(FM_PROP_ESCAPE_PROCESSING));
97 catch(Exception&)
99 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
102 // If the data source is an SQL-statement and simple enough (means "select <field list> from <table> where...")
103 // we are able to fake the drag information we are about to create.
104 if (bTryToParse && (CommandType::COMMAND == nCommandType))
108 Reference< XTablesSupplier > xSupTab;
109 _rxForm->getPropertyValue(u"SingleSelectQueryComposer"_ustr) >>= xSupTab;
111 if(xSupTab.is())
113 Reference< XNameAccess > xNames = xSupTab->getTables();
114 if (xNames.is())
116 Sequence< OUString > aTables = xNames->getElementNames();
117 if (1 == aTables.getLength())
119 sCommand = aTables[0];
120 nCommandType = CommandType::TABLE;
125 catch(Exception&)
127 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
131 implConstruct(sDatasource, sURL,nCommandType, sCommand, _rFieldName);
133 if ((m_nFormatFlags & ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR)
135 if (_rxColumn.is())
136 m_aDescriptor[DataAccessDescriptorProperty::ColumnObject] <<= _rxColumn;
137 if (_rxConnection.is())
138 m_aDescriptor[DataAccessDescriptorProperty::Connection] <<= _rxConnection;
143 SotClipboardFormatId OColumnTransferable::getDescriptorFormatId()
145 static SotClipboardFormatId s_nFormat = static_cast<SotClipboardFormatId>(-1);
146 if (static_cast<SotClipboardFormatId>(-1) == s_nFormat)
148 s_nFormat = SotExchange::RegisterFormatName(u"application/x-openoffice;windows_formatname=\"dbaccess.ColumnDescriptorTransfer\""_ustr);
149 OSL_ENSURE(static_cast<SotClipboardFormatId>(-1) != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
151 return s_nFormat;
155 void OColumnTransferable::implConstruct( const OUString& _rDatasource
156 ,const OUString& _rConnectionResource
157 ,const sal_Int32 _nCommandType
158 ,const OUString& _rCommand
159 , const OUString& _rFieldName)
161 const sal_Unicode cSeparator = u'\x000B';
162 const OUString sSeparator(&cSeparator, 1);
164 m_sCompatibleFormat.clear();
165 m_sCompatibleFormat += _rDatasource;
166 m_sCompatibleFormat += sSeparator;
167 m_sCompatibleFormat += _rCommand;
168 m_sCompatibleFormat += sSeparator;
170 sal_Unicode cCommandType;
171 switch (_nCommandType)
173 case CommandType::TABLE:
174 cCommandType = '0';
175 break;
176 case CommandType::QUERY:
177 cCommandType = '1';
178 break;
179 default:
180 cCommandType = '2';
181 break;
183 m_sCompatibleFormat += OUStringChar(cCommandType);
184 m_sCompatibleFormat += sSeparator;
185 m_sCompatibleFormat += _rFieldName;
187 m_aDescriptor.clear();
188 if ((m_nFormatFlags & ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR)
190 m_aDescriptor.setDataSource(_rDatasource);
191 if ( !_rConnectionResource.isEmpty() )
192 m_aDescriptor[DataAccessDescriptorProperty::ConnectionResource] <<= _rConnectionResource;
194 m_aDescriptor[DataAccessDescriptorProperty::Command] <<= _rCommand;
195 m_aDescriptor[DataAccessDescriptorProperty::CommandType] <<= _nCommandType;
196 m_aDescriptor[DataAccessDescriptorProperty::ColumnName] <<= _rFieldName;
201 void OColumnTransferable::AddSupportedFormats()
203 if (ColumnTransferFormatFlags::CONTROL_EXCHANGE & m_nFormatFlags)
204 AddFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE);
206 if (ColumnTransferFormatFlags::FIELD_DESCRIPTOR & m_nFormatFlags)
207 AddFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE);
209 if (ColumnTransferFormatFlags::COLUMN_DESCRIPTOR & m_nFormatFlags)
210 AddFormat(getDescriptorFormatId());
214 bool OColumnTransferable::GetData( const DataFlavor& _rFlavor, const OUString& /*rDestDoc*/ )
216 const SotClipboardFormatId nFormatId = SotExchange::GetFormat(_rFlavor);
217 switch (nFormatId)
219 case SotClipboardFormatId::SBA_FIELDDATAEXCHANGE:
220 case SotClipboardFormatId::SBA_CTRLDATAEXCHANGE:
221 return SetString(m_sCompatibleFormat);
222 default: break;
224 if (nFormatId == getDescriptorFormatId())
225 return SetAny( Any( m_aDescriptor.createPropertyValueSequence() ) );
227 return false;
231 bool OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector& _rFlavors, ColumnTransferFormatFlags _nFormats)
233 bool bFieldFormat = bool(_nFormats & ColumnTransferFormatFlags::FIELD_DESCRIPTOR);
234 bool bControlFormat = bool(_nFormats & ColumnTransferFormatFlags::CONTROL_EXCHANGE);
235 bool bDescriptorFormat = bool(_nFormats & ColumnTransferFormatFlags::COLUMN_DESCRIPTOR);
236 SotClipboardFormatId nFormatId = getDescriptorFormatId();
237 return std::any_of(_rFlavors.begin(), _rFlavors.end(),
238 [&](const DataFlavorEx& rCheck) {
239 return (bFieldFormat && (SotClipboardFormatId::SBA_FIELDDATAEXCHANGE == rCheck.mnSotId))
240 || (bControlFormat && (SotClipboardFormatId::SBA_CTRLDATAEXCHANGE == rCheck.mnSotId))
241 || (bDescriptorFormat && (nFormatId == rCheck.mnSotId));
246 ODataAccessDescriptor OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData)
248 if (_rData.HasFormat(getDescriptorFormatId()))
250 // the object has a real descriptor object (not just the old compatible format)
252 // extract the any from the transferable
253 DataFlavor aFlavor;
254 bool bSuccess =
255 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor);
256 OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
258 Any aDescriptor = _rData.GetAny(aFlavor, OUString());
260 // extract the property value sequence
261 Sequence< PropertyValue > aDescriptorProps;
262 bSuccess = aDescriptor >>= aDescriptorProps;
263 OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
265 // build the real descriptor
266 return ODataAccessDescriptor(aDescriptorProps);
269 // only the old (compatible) format exists -> use the other extract method ...
270 OUString sDatasource, sCommand, sFieldName,sDatabaseLocation,sConnectionResource;
271 sal_Int32 nCommandType = CommandType::COMMAND;
273 ODataAccessDescriptor aDescriptor;
274 if (extractColumnDescriptor(_rData, sDatasource, sDatabaseLocation,sConnectionResource,nCommandType, sCommand, sFieldName))
276 // and build an own descriptor
277 if ( !sDatasource.isEmpty() )
278 aDescriptor[DataAccessDescriptorProperty::DataSource] <<= sDatasource;
279 if ( !sDatabaseLocation.isEmpty() )
280 aDescriptor[DataAccessDescriptorProperty::DatabaseLocation] <<= sDatabaseLocation;
281 if ( !sConnectionResource.isEmpty() )
282 aDescriptor[DataAccessDescriptorProperty::ConnectionResource] <<= sConnectionResource;
284 aDescriptor[DataAccessDescriptorProperty::Command] <<= sCommand;
285 aDescriptor[DataAccessDescriptorProperty::CommandType] <<= nCommandType;
286 aDescriptor[DataAccessDescriptorProperty::ColumnName] <<= sFieldName;
288 return aDescriptor;
292 bool OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData
293 ,OUString& _rDatasource
294 ,OUString& _rDatabaseLocation
295 ,OUString& _rConnectionResource
296 ,sal_Int32& _nCommandType
297 ,OUString& _rCommand
298 ,OUString& _rFieldName)
300 if ( _rData.HasFormat(getDescriptorFormatId()) )
302 ODataAccessDescriptor aDescriptor = extractColumnDescriptor(_rData);
303 if ( aDescriptor.has(DataAccessDescriptorProperty::DataSource) )
304 aDescriptor[DataAccessDescriptorProperty::DataSource] >>= _rDatasource;
305 if ( aDescriptor.has(DataAccessDescriptorProperty::DatabaseLocation) )
306 aDescriptor[DataAccessDescriptorProperty::DatabaseLocation] >>= _rDatabaseLocation;
307 if ( aDescriptor.has(DataAccessDescriptorProperty::ConnectionResource) )
308 aDescriptor[DataAccessDescriptorProperty::ConnectionResource] >>= _rConnectionResource;
310 aDescriptor[DataAccessDescriptorProperty::Command] >>= _rCommand;
311 aDescriptor[DataAccessDescriptorProperty::CommandType] >>= _nCommandType;
312 aDescriptor[DataAccessDescriptorProperty::ColumnName] >>= _rFieldName;
313 return true;
316 // check if we have a (string) format we can use...
317 SotClipboardFormatId nRecognizedFormat = SotClipboardFormatId::NONE;
318 if (_rData.HasFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE))
319 nRecognizedFormat = SotClipboardFormatId::SBA_FIELDDATAEXCHANGE;
320 if (_rData.HasFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE))
321 nRecognizedFormat = SotClipboardFormatId::SBA_CTRLDATAEXCHANGE;
322 if (nRecognizedFormat == SotClipboardFormatId::NONE)
323 return false;
325 OUString sFieldDescription;
326 (void)_rData.GetString(nRecognizedFormat, sFieldDescription);
328 const sal_Unicode cSeparator = u'\x000B';
329 sal_Int32 nIdx{ 0 };
330 _rDatasource = sFieldDescription.getToken(0, cSeparator, nIdx);
331 _rCommand = sFieldDescription.getToken(0, cSeparator, nIdx);
332 _nCommandType = o3tl::toInt32(o3tl::getToken(sFieldDescription, 0, cSeparator, nIdx));
333 _rFieldName = sFieldDescription.getToken(0, cSeparator, nIdx);
335 return true;
338 ODataAccessObjectTransferable::ODataAccessObjectTransferable()
342 void ODataAccessObjectTransferable::Update(
343 const OUString& _rDatasource,
344 const sal_Int32 _nCommandType,
345 const OUString& _rCommand)
347 construct(_rDatasource,OUString(),_nCommandType,_rCommand,nullptr,(CommandType::COMMAND == _nCommandType),_rCommand);
350 void ODataAccessObjectTransferable::Update(
351 const OUString& _rDatasource,
352 const sal_Int32 _nCommandType,
353 const OUString& _rCommand,
354 const Reference< XConnection >& _rxConnection)
356 OSL_ENSURE(_rxConnection.is(), "Wrong Update used.!");
357 construct(_rDatasource,OUString(),_nCommandType,_rCommand,_rxConnection,(CommandType::COMMAND == _nCommandType),_rCommand);
360 ODataAccessObjectTransferable::ODataAccessObjectTransferable(const Reference< XPropertySet >& _rxLivingForm)
362 // collect some properties of the form
363 OUString sDatasourceName,sConnectionResource;
364 sal_Int32 nObjectType = CommandType::COMMAND;
365 OUString sObjectName;
366 Reference< XConnection > xConnection;
369 _rxLivingForm->getPropertyValue(FM_PROP_COMMANDTYPE) >>= nObjectType;
370 _rxLivingForm->getPropertyValue(FM_PROP_COMMAND) >>= sObjectName;
371 _rxLivingForm->getPropertyValue(FM_PROP_DATASOURCE) >>= sDatasourceName;
372 _rxLivingForm->getPropertyValue(FM_PROP_URL) >>= sConnectionResource;
373 _rxLivingForm->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xConnection;
375 catch(Exception&)
377 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
378 return;
381 // check if the SQL-statement is modified
382 OUString sCompleteStatement;
385 _rxLivingForm->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sCompleteStatement;
387 catch (const Exception&)
389 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
390 return;
393 construct( sDatasourceName
394 ,sConnectionResource
395 ,nObjectType
396 ,sObjectName,xConnection
397 ,CommandType::QUERY != nObjectType
398 ,sCompleteStatement);
402 void ODataAccessObjectTransferable::AddSupportedFormats()
404 sal_Int32 nObjectType = CommandType::COMMAND;
405 m_aDescriptor[DataAccessDescriptorProperty::CommandType] >>= nObjectType;
406 switch (nObjectType)
408 case CommandType::TABLE:
409 AddFormat(SotClipboardFormatId::DBACCESS_TABLE);
410 break;
411 case CommandType::QUERY:
412 AddFormat(SotClipboardFormatId::DBACCESS_QUERY);
413 break;
414 case CommandType::COMMAND:
415 AddFormat(SotClipboardFormatId::DBACCESS_COMMAND);
416 break;
419 if (!m_sCompatibleObjectDescription.isEmpty())
420 AddFormat(SotClipboardFormatId::SBA_DATAEXCHANGE);
424 bool ODataAccessObjectTransferable::GetData( const DataFlavor& rFlavor, const OUString& /*rDestDoc*/ )
426 SotClipboardFormatId nFormat = SotExchange::GetFormat(rFlavor);
427 switch (nFormat)
429 case SotClipboardFormatId::DBACCESS_TABLE:
430 case SotClipboardFormatId::DBACCESS_QUERY:
431 case SotClipboardFormatId::DBACCESS_COMMAND:
432 return SetAny( Any(m_aDescriptor.createPropertyValueSequence()) );
434 case SotClipboardFormatId::SBA_DATAEXCHANGE:
435 return SetString(m_sCompatibleObjectDescription);
436 default: break;
438 return false;
442 bool ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector& _rFlavors)
444 return std::any_of(_rFlavors.begin(), _rFlavors.end(),
445 [](const DataFlavorEx& rCheck) {
446 return SotClipboardFormatId::DBACCESS_TABLE == rCheck.mnSotId
447 || SotClipboardFormatId::DBACCESS_QUERY == rCheck.mnSotId
448 || SotClipboardFormatId::DBACCESS_COMMAND == rCheck.mnSotId;
453 ODataAccessDescriptor ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper& _rData)
455 SotClipboardFormatId nKnownFormatId = SotClipboardFormatId::NONE;
456 if ( _rData.HasFormat( SotClipboardFormatId::DBACCESS_TABLE ) )
457 nKnownFormatId = SotClipboardFormatId::DBACCESS_TABLE;
458 if ( _rData.HasFormat( SotClipboardFormatId::DBACCESS_QUERY ) )
459 nKnownFormatId = SotClipboardFormatId::DBACCESS_QUERY;
460 if ( _rData.HasFormat( SotClipboardFormatId::DBACCESS_COMMAND ) )
461 nKnownFormatId = SotClipboardFormatId::DBACCESS_COMMAND;
463 if (SotClipboardFormatId::NONE != nKnownFormatId)
465 // extract the any from the transferable
466 DataFlavor aFlavor;
467 bool bSuccess =
468 SotExchange::GetFormatDataFlavor(nKnownFormatId, aFlavor);
469 OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
471 Any aDescriptor = _rData.GetAny(aFlavor, OUString());
473 // extract the property value sequence
474 Sequence< PropertyValue > aDescriptorProps;
475 bSuccess = aDescriptor >>= aDescriptorProps;
476 OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
478 // build the real descriptor
479 return ODataAccessDescriptor(aDescriptorProps);
482 OSL_FAIL( "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
483 return ODataAccessDescriptor();
487 void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence< Any >& _rSelRows )
489 const sal_Unicode cSeparator(11);
490 const OUString sSeparator(&cSeparator, 1);
492 for ( const Any& rSelRow : _rSelRows )
494 sal_Int32 nSelectedRow( 0 );
495 OSL_VERIFY( rSelRow >>= nSelectedRow );
497 m_sCompatibleObjectDescription += OUString::number(nSelectedRow);
498 m_sCompatibleObjectDescription += sSeparator;
503 void ODataAccessObjectTransferable::ObjectReleased()
505 m_aDescriptor.clear();
508 void ODataAccessObjectTransferable::construct( const OUString& _rDatasource
509 ,const OUString& _rConnectionResource
510 ,const sal_Int32 _nCommandType
511 ,const OUString& _rCommand
512 ,const Reference< XConnection >& _rxConnection
513 ,bool _bAddCommand
514 ,const OUString& _sActiveCommand)
516 m_aDescriptor.setDataSource(_rDatasource);
517 // build the descriptor (the property sequence)
518 if ( !_rConnectionResource.isEmpty() )
519 m_aDescriptor[DataAccessDescriptorProperty::ConnectionResource] <<= _rConnectionResource;
520 if ( _rxConnection.is() )
521 m_aDescriptor[DataAccessDescriptorProperty::Connection] <<= _rxConnection;
522 m_aDescriptor[DataAccessDescriptorProperty::Command] <<= _rCommand;
523 m_aDescriptor[DataAccessDescriptorProperty::CommandType] <<= _nCommandType;
525 // extract the single values from the sequence
527 OUString sObjectName = _rCommand;
529 // for compatibility: create a string which can be used for the SotClipboardFormatId::SBA_DATAEXCHANGE format
531 bool bTreatAsStatement = (CommandType::COMMAND == _nCommandType);
532 // statements are - in this old and ugly format - described as queries
534 const sal_Unicode cSeparator = u'\x000B';
535 const OUString sSeparator(&cSeparator, 1);
537 const sal_Unicode cTableMark = '1';
538 const sal_Unicode cQueryMark = '0';
540 // build the descriptor string
541 m_sCompatibleObjectDescription += _rDatasource;
542 m_sCompatibleObjectDescription += sSeparator;
543 m_sCompatibleObjectDescription += bTreatAsStatement ? OUString() : sObjectName;
544 m_sCompatibleObjectDescription += sSeparator;
545 switch (_nCommandType)
547 case CommandType::TABLE:
548 m_sCompatibleObjectDescription += OUStringChar(cTableMark);
549 break;
550 case CommandType::QUERY:
551 m_sCompatibleObjectDescription += OUStringChar(cQueryMark);
552 break;
553 case CommandType::COMMAND:
554 m_sCompatibleObjectDescription += OUStringChar(cQueryMark);
555 // think of it as a query
556 break;
558 m_sCompatibleObjectDescription += sSeparator;
559 m_sCompatibleObjectDescription += _bAddCommand ? _sActiveCommand : OUString();
560 m_sCompatibleObjectDescription += sSeparator;
563 OMultiColumnTransferable::OMultiColumnTransferable()
567 void OMultiColumnTransferable::setDescriptors(const Sequence< PropertyValue >& rDescriptors)
569 ClearFormats();
570 m_aDescriptors = rDescriptors;
573 SotClipboardFormatId OMultiColumnTransferable::getDescriptorFormatId()
575 static SotClipboardFormatId s_nFormat = static_cast<SotClipboardFormatId>(-1);
576 if (static_cast<SotClipboardFormatId>(-1) == s_nFormat)
578 s_nFormat = SotExchange::RegisterFormatName(u"application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\""_ustr);
579 OSL_ENSURE(static_cast<SotClipboardFormatId>(-1) != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
581 return s_nFormat;
584 void OMultiColumnTransferable::AddSupportedFormats()
586 AddFormat(getDescriptorFormatId());
589 bool OMultiColumnTransferable::GetData( const DataFlavor& _rFlavor, const OUString& /*rDestDoc*/ )
591 const SotClipboardFormatId nFormatId = SotExchange::GetFormat(_rFlavor);
592 if (nFormatId == getDescriptorFormatId())
594 return SetAny( Any( m_aDescriptors ) );
597 return false;
600 bool OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector& _rFlavors)
602 const SotClipboardFormatId nFormatId = getDescriptorFormatId();
603 return std::all_of(_rFlavors.begin(), _rFlavors.end(),
604 [&nFormatId](const DataFlavorEx& rCheck) { return nFormatId == rCheck.mnSotId; });
607 Sequence< PropertyValue > OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper& _rData)
609 Sequence< PropertyValue > aList;
610 if (_rData.HasFormat(getDescriptorFormatId()))
612 // extract the any from the transferable
613 DataFlavor aFlavor;
614 bool bSuccess =
615 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor);
616 OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
618 _rData.GetAny(aFlavor, OUString()) >>= aList;
619 } // if (_rData.HasFormat(getDescriptorFormatId()))
620 return aList;
623 void OMultiColumnTransferable::ObjectReleased()
625 m_aDescriptors.realloc(0);
629 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */