Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / fmcomp / dbaexchange.cxx
blobfd639185e4c97dd716d6a76643836c3d0342e7f8
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/sdb/CommandType.hpp>
23 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
24 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
25 #include "fmprop.hrc"
26 #include <comphelper/extract.hxx>
27 #include <sot/formats.hxx>
28 #include <sot/exchange.hxx>
29 #include <comphelper/propertysetinfo.hxx>
32 namespace svx
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;
47 //= OColumnTransferable
50 OColumnTransferable::OColumnTransferable(const OUString& _rDatasource
51 ,const OUString& _rConnectionResource
52 ,const sal_Int32 _nCommandType
53 ,const OUString& _rCommand
54 ,const OUString& _rFieldName
55 ,sal_Int32 _nFormats)
56 :m_nFormatFlags(_nFormats)
58 implConstruct(_rDatasource,_rConnectionResource,_nCommandType, _rCommand, _rFieldName);
62 OColumnTransferable::OColumnTransferable(const ODataAccessDescriptor& _rDescriptor, sal_Int32 _nFormats )
63 :m_nFormatFlags(_nFormats)
65 OUString sDataSource, sDatabaseLocation, sConnectionResource, sCommand, sFieldName;
66 if ( _rDescriptor.has( daDataSource ) ) _rDescriptor[ daDataSource ] >>= sDataSource;
67 if ( _rDescriptor.has( daDatabaseLocation ) ) _rDescriptor[ daDatabaseLocation ] >>= sDatabaseLocation;
68 if ( _rDescriptor.has( daConnectionResource ) ) _rDescriptor[ daConnectionResource ] >>= sConnectionResource;
69 if ( _rDescriptor.has( daCommand ) ) _rDescriptor[ daCommand ] >>= sCommand;
70 if ( _rDescriptor.has( daColumnName ) ) _rDescriptor[ daColumnName ] >>= sFieldName;
72 sal_Int32 nCommandType = CommandType::TABLE;
73 OSL_VERIFY( _rDescriptor[ daCommandType ] >>= nCommandType );
76 implConstruct(
77 sDataSource.isEmpty() ? sDatabaseLocation : sDataSource,
78 sConnectionResource, nCommandType, sCommand, sFieldName );
80 if ( m_nFormatFlags & CTF_COLUMN_DESCRIPTOR )
82 if ( _rDescriptor.has( daConnection ) )
83 m_aDescriptor[ daConnection ] = _rDescriptor[ daConnection ];
84 if ( _rDescriptor.has( daColumnObject ) )
85 m_aDescriptor[ daColumnObject ] = _rDescriptor[ daColumnObject ];
90 OColumnTransferable::OColumnTransferable(const Reference< XPropertySet >& _rxForm,
91 const OUString& _rFieldName, const Reference< XPropertySet >& _rxColumn,
92 const Reference< XConnection >& _rxConnection, sal_Int32 _nFormats)
93 :m_nFormatFlags(_nFormats)
95 OSL_ENSURE(_rxForm.is(), "OColumnTransferable::OColumnTransferable: invalid form!");
96 // collect the necessary information from the form
97 OUString sCommand;
98 sal_Int32 nCommandType = CommandType::TABLE;
99 OUString sDatasource,sURL;
101 bool bTryToParse = true;
104 _rxForm->getPropertyValue(FM_PROP_COMMANDTYPE) >>= nCommandType;
105 _rxForm->getPropertyValue(FM_PROP_COMMAND) >>= sCommand;
106 _rxForm->getPropertyValue(FM_PROP_DATASOURCE) >>= sDatasource;
107 _rxForm->getPropertyValue(FM_PROP_URL) >>= sURL;
108 bTryToParse = ::cppu::any2bool(_rxForm->getPropertyValue(FM_PROP_ESCAPE_PROCESSING));
110 catch(Exception&)
112 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
115 // If the data source is an SQL-statement and simple enough (means "select <field list> from <table> where ....")
116 // we are able to fake the drag information we are about to create.
117 if (bTryToParse && (CommandType::COMMAND == nCommandType))
121 Reference< XTablesSupplier > xSupTab;
122 _rxForm->getPropertyValue("SingleSelectQueryComposer") >>= xSupTab;
124 if(xSupTab.is())
126 Reference< XNameAccess > xNames = xSupTab->getTables();
127 if (xNames.is())
129 Sequence< OUString > aTables = xNames->getElementNames();
130 if (1 == aTables.getLength())
132 sCommand = aTables[0];
133 nCommandType = CommandType::TABLE;
138 catch(Exception&)
140 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
144 implConstruct(sDatasource, sURL,nCommandType, sCommand, _rFieldName);
146 if ((m_nFormatFlags & CTF_COLUMN_DESCRIPTOR) == CTF_COLUMN_DESCRIPTOR)
148 if (_rxColumn.is())
149 m_aDescriptor[daColumnObject] <<= _rxColumn;
150 if (_rxConnection.is())
151 m_aDescriptor[daConnection] <<= _rxConnection;
156 sal_uInt32 OColumnTransferable::getDescriptorFormatId()
158 static sal_uInt32 s_nFormat = (sal_uInt32)-1;
159 if ((sal_uInt32)-1 == s_nFormat)
161 s_nFormat = SotExchange::RegisterFormatName(OUString("application/x-openoffice;windows_formatname=\"dbaccess.ColumnDescriptorTransfer\""));
162 OSL_ENSURE((sal_uInt32)-1 != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
164 return s_nFormat;
168 void OColumnTransferable::implConstruct( const OUString& _rDatasource
169 ,const OUString& _rConnectionResource
170 ,const sal_Int32 _nCommandType
171 ,const OUString& _rCommand
172 , const OUString& _rFieldName)
174 const sal_Unicode cSeparator = sal_Unicode(11);
175 const OUString sSeparator(&cSeparator, 1);
177 m_sCompatibleFormat = OUString();
178 m_sCompatibleFormat += _rDatasource;
179 m_sCompatibleFormat += sSeparator;
180 m_sCompatibleFormat += _rCommand;
181 m_sCompatibleFormat += sSeparator;
183 sal_Unicode cCommandType;
184 switch (_nCommandType)
186 case CommandType::TABLE:
187 cCommandType = '0';
188 break;
189 case CommandType::QUERY:
190 cCommandType = '1';
191 break;
192 default:
193 cCommandType = '2';
194 break;
196 m_sCompatibleFormat += OUString(&cCommandType, 1);
197 m_sCompatibleFormat += sSeparator;
198 m_sCompatibleFormat += _rFieldName;
200 m_aDescriptor.clear();
201 if ((m_nFormatFlags & CTF_COLUMN_DESCRIPTOR) == CTF_COLUMN_DESCRIPTOR)
203 m_aDescriptor.setDataSource(_rDatasource);
204 if ( !_rConnectionResource.isEmpty() )
205 m_aDescriptor[daConnectionResource] <<= _rConnectionResource;
207 m_aDescriptor[daCommand] <<= _rCommand;
208 m_aDescriptor[daCommandType] <<= _nCommandType;
209 m_aDescriptor[daColumnName] <<= _rFieldName;
214 void OColumnTransferable::AddSupportedFormats()
216 if (CTF_CONTROL_EXCHANGE & m_nFormatFlags)
217 AddFormat(SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE);
219 if (CTF_FIELD_DESCRIPTOR & m_nFormatFlags)
220 AddFormat(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE);
222 if (CTF_COLUMN_DESCRIPTOR & m_nFormatFlags)
223 AddFormat(getDescriptorFormatId());
227 bool OColumnTransferable::GetData( const DataFlavor& _rFlavor )
229 const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
230 switch (nFormatId)
232 case SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE:
233 case SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE:
234 return SetString(m_sCompatibleFormat, _rFlavor);
236 if (nFormatId == getDescriptorFormatId())
237 return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor );
239 return false;
243 bool OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector& _rFlavors, sal_Int32 _nFormats)
245 bool bFieldFormat = 0 != (_nFormats & CTF_FIELD_DESCRIPTOR);
246 bool bControlFormat = 0 != (_nFormats & CTF_CONTROL_EXCHANGE);
247 bool bDescriptorFormat = 0 != (_nFormats & CTF_COLUMN_DESCRIPTOR);
248 for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
249 aCheck != _rFlavors.end();
250 ++aCheck
253 if (bFieldFormat && (SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE == aCheck->mnSotId))
254 return true;
255 if (bControlFormat && (SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == aCheck->mnSotId))
256 return true;
257 if (bDescriptorFormat && (getDescriptorFormatId() == aCheck->mnSotId))
258 return true;
261 return false;
265 ODataAccessDescriptor OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData)
267 if (_rData.HasFormat(getDescriptorFormatId()))
269 // the object has a real descriptor object (not just the old compatible format)
271 // extract the any from the transferable
272 DataFlavor aFlavor;
273 #if OSL_DEBUG_LEVEL > 0
274 bool bSuccess =
275 #endif
276 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor);
277 OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
279 Any aDescriptor = _rData.GetAny(aFlavor);
281 // extract the property value sequence
282 Sequence< PropertyValue > aDescriptorProps;
283 #if OSL_DEBUG_LEVEL > 0
284 bSuccess =
285 #endif
286 aDescriptor >>= aDescriptorProps;
287 OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
289 // build the real descriptor
290 return ODataAccessDescriptor(aDescriptorProps);
293 // only the old (compatible) format exists -> use the other extract method ...
294 OUString sDatasource, sCommand, sFieldName,sDatabaseLocation,sConnectionResource;
295 sal_Int32 nCommandType = CommandType::COMMAND;
297 ODataAccessDescriptor aDescriptor;
298 if (extractColumnDescriptor(_rData, sDatasource, sDatabaseLocation,sConnectionResource,nCommandType, sCommand, sFieldName))
300 // and build an own descriptor
301 if ( !sDatasource.isEmpty() )
302 aDescriptor[daDataSource] <<= sDatasource;
303 if ( !sDatabaseLocation.isEmpty() )
304 aDescriptor[daDatabaseLocation] <<= sDatabaseLocation;
305 if ( !sConnectionResource.isEmpty() )
306 aDescriptor[daConnectionResource] <<= sConnectionResource;
308 aDescriptor[daCommand] <<= sCommand;
309 aDescriptor[daCommandType] <<= nCommandType;
310 aDescriptor[daColumnName] <<= sFieldName;
312 return aDescriptor;
316 bool OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData
317 ,OUString& _rDatasource
318 ,OUString& _rDatabaseLocation
319 ,OUString& _rConnectionResource
320 ,sal_Int32& _nCommandType
321 ,OUString& _rCommand
322 ,OUString& _rFieldName)
324 if ( _rData.HasFormat(getDescriptorFormatId()) )
326 ODataAccessDescriptor aDescriptor = extractColumnDescriptor(_rData);
327 if ( aDescriptor.has(daDataSource) )
328 aDescriptor[daDataSource] >>= _rDatasource;
329 if ( aDescriptor.has(daDatabaseLocation) )
330 aDescriptor[daDatabaseLocation] >>= _rDatabaseLocation;
331 if ( aDescriptor.has(daConnectionResource) )
332 aDescriptor[daConnectionResource] >>= _rConnectionResource;
334 aDescriptor[daCommand] >>= _rCommand;
335 aDescriptor[daCommandType] >>= _nCommandType;
336 aDescriptor[daColumnName] >>= _rFieldName;
337 return true;
340 // check if we have a (string) format we can use ....
341 SotFormatStringId nRecognizedFormat = 0;
342 if (_rData.HasFormat(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE))
343 nRecognizedFormat = SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE;
344 if (_rData.HasFormat(SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE))
345 nRecognizedFormat = SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE;
346 if (!nRecognizedFormat)
347 return false;
349 OUString sFieldDescription;
350 const_cast<TransferableDataHelper&>(_rData).GetString(nRecognizedFormat, sFieldDescription);
352 const sal_Unicode cSeparator = sal_Unicode(11);
353 _rDatasource = sFieldDescription.getToken(0, cSeparator);
354 _rCommand = sFieldDescription.getToken(1, cSeparator);
355 _nCommandType = sFieldDescription.getToken(2, cSeparator).toInt32();
356 _rFieldName = sFieldDescription.getToken(3, cSeparator);
358 return true;
362 void OColumnTransferable::addDataToContainer( TransferDataContainer* _pContainer )
364 OSL_ENSURE( _pContainer, "OColumnTransferable::addDataToContainer: invalid container!" );
365 if ( _pContainer )
367 if ( m_nFormatFlags & CTF_FIELD_DESCRIPTOR )
368 _pContainer->CopyAny( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE, makeAny( m_sCompatibleFormat ) );
370 if ( m_nFormatFlags & CTF_CONTROL_EXCHANGE )
371 _pContainer->CopyAny( SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE, makeAny( m_sCompatibleFormat ) );
373 if ( m_nFormatFlags & CTF_COLUMN_DESCRIPTOR )
375 Any aContent = makeAny( m_aDescriptor.createPropertyValueSequence() );
376 _pContainer->CopyAny(
377 sal::static_int_cast< sal_uInt16 >( getDescriptorFormatId() ),
378 aContent );
384 //= ODataAccessObjectTransferable
386 ODataAccessObjectTransferable::ODataAccessObjectTransferable(
387 const OUString& _rDatasource
388 ,const OUString& _rConnectionResource
389 ,const sal_Int32 _nCommandType
390 ,const OUString& _rCommand
393 construct(_rDatasource,_rConnectionResource,_nCommandType,_rCommand,NULL,(CommandType::COMMAND == _nCommandType),_rCommand);
396 ODataAccessObjectTransferable::ODataAccessObjectTransferable(
397 const OUString& _rDatasource
398 ,const OUString& _rConnectionResource
399 ,const sal_Int32 _nCommandType
400 ,const OUString& _rCommand
401 ,const Reference< XConnection >& _rxConnection)
403 OSL_ENSURE(_rxConnection.is(),"Wrong ctor used.!");
404 construct(_rDatasource,_rConnectionResource,_nCommandType,_rCommand,_rxConnection,(CommandType::COMMAND == _nCommandType),_rCommand);
408 ODataAccessObjectTransferable::ODataAccessObjectTransferable(const Reference< XPropertySet >& _rxLivingForm)
410 // collect some properties of the form
411 OUString sDatasourceName,sConnectionResource;
412 sal_Int32 nObjectType = CommandType::COMMAND;
413 OUString sObjectName;
414 Reference< XConnection > xConnection;
417 _rxLivingForm->getPropertyValue(FM_PROP_COMMANDTYPE) >>= nObjectType;
418 _rxLivingForm->getPropertyValue(FM_PROP_COMMAND) >>= sObjectName;
419 _rxLivingForm->getPropertyValue(FM_PROP_DATASOURCE) >>= sDatasourceName;
420 _rxLivingForm->getPropertyValue(FM_PROP_URL) >>= sConnectionResource;
421 _rxLivingForm->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xConnection;
423 catch(Exception&)
425 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
426 return;
429 // check if the SQL-statement is modified
430 OUString sCompleteStatement;
433 _rxLivingForm->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sCompleteStatement;
435 catch (const Exception&)
437 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
438 return;
441 construct( sDatasourceName
442 ,sConnectionResource
443 ,nObjectType
444 ,sObjectName,xConnection
445 ,!((CommandType::QUERY == nObjectType))
446 ,sCompleteStatement);
450 void ODataAccessObjectTransferable::AddSupportedFormats()
452 sal_Int32 nObjectType = CommandType::COMMAND;
453 m_aDescriptor[daCommandType] >>= nObjectType;
454 switch (nObjectType)
456 case CommandType::TABLE:
457 AddFormat(SOT_FORMATSTR_ID_DBACCESS_TABLE);
458 break;
459 case CommandType::QUERY:
460 AddFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY);
461 break;
462 case CommandType::COMMAND:
463 AddFormat(SOT_FORMATSTR_ID_DBACCESS_COMMAND);
464 break;
467 if (!m_sCompatibleObjectDescription.isEmpty())
468 AddFormat(SOT_FORMATSTR_ID_SBA_DATAEXCHANGE);
472 bool ODataAccessObjectTransferable::GetData( const DataFlavor& rFlavor )
474 sal_uIntPtr nFormat = SotExchange::GetFormat(rFlavor);
475 switch (nFormat)
477 case SOT_FORMATSTR_ID_DBACCESS_TABLE:
478 case SOT_FORMATSTR_ID_DBACCESS_QUERY:
479 case SOT_FORMATSTR_ID_DBACCESS_COMMAND:
480 return SetAny( makeAny(m_aDescriptor.createPropertyValueSequence()), rFlavor );
482 case SOT_FORMATSTR_ID_SBA_DATAEXCHANGE:
483 return SetString(m_sCompatibleObjectDescription, rFlavor);
485 return false;
489 bool ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector& _rFlavors)
491 for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
492 aCheck != _rFlavors.end();
493 ++aCheck
496 if (SOT_FORMATSTR_ID_DBACCESS_TABLE == aCheck->mnSotId)
497 return true;
498 if (SOT_FORMATSTR_ID_DBACCESS_QUERY == aCheck->mnSotId)
499 return true;
500 if (SOT_FORMATSTR_ID_DBACCESS_COMMAND == aCheck->mnSotId)
501 return true;
503 return false;
507 ODataAccessDescriptor ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper& _rData)
509 sal_Int32 nKnownFormatId = 0;
510 if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_TABLE ) )
511 nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_TABLE;
512 if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_QUERY ) )
513 nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_QUERY;
514 if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_COMMAND ) )
515 nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_COMMAND;
517 if (0 != nKnownFormatId)
519 // extract the any from the transferable
520 DataFlavor aFlavor;
521 #if OSL_DEBUG_LEVEL > 0
522 bool bSuccess =
523 #endif
524 SotExchange::GetFormatDataFlavor(nKnownFormatId, aFlavor);
525 OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
527 Any aDescriptor = _rData.GetAny(aFlavor);
529 // extract the property value sequence
530 Sequence< PropertyValue > aDescriptorProps;
531 #if OSL_DEBUG_LEVEL > 0
532 bSuccess =
533 #endif
534 aDescriptor >>= aDescriptorProps;
535 OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
537 // build the real descriptor
538 return ODataAccessDescriptor(aDescriptorProps);
541 OSL_FAIL( "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
542 return ODataAccessDescriptor();
546 void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence< Any >& _rSelRows )
548 const sal_Unicode cSeparator(11);
549 const OUString sSeparator(&cSeparator, 1);
551 const Any* pSelRows = _rSelRows.getConstArray();
552 const Any* pSelRowsEnd = pSelRows + _rSelRows.getLength();
553 for ( ; pSelRows < pSelRowsEnd; ++pSelRows )
555 sal_Int32 nSelectedRow( 0 );
556 OSL_VERIFY( *pSelRows >>= nSelectedRow );
558 m_sCompatibleObjectDescription += OUString::number(nSelectedRow);
559 m_sCompatibleObjectDescription += sSeparator;
564 void ODataAccessObjectTransferable::ObjectReleased()
566 m_aDescriptor.clear();
569 void ODataAccessObjectTransferable::construct( const OUString& _rDatasource
570 ,const OUString& _rConnectionResource
571 ,const sal_Int32 _nCommandType
572 ,const OUString& _rCommand
573 ,const Reference< XConnection >& _rxConnection
574 ,bool _bAddCommand
575 ,const OUString& _sActiveCommand)
577 m_aDescriptor.setDataSource(_rDatasource);
578 // build the descriptor (the property sequence)
579 if ( !_rConnectionResource.isEmpty() )
580 m_aDescriptor[daConnectionResource] <<= _rConnectionResource;
581 if ( _rxConnection.is() )
582 m_aDescriptor[daConnection] <<= _rxConnection;
583 m_aDescriptor[daCommand] <<= _rCommand;
584 m_aDescriptor[daCommandType] <<= _nCommandType;
586 // extract the single values from the sequence
588 OUString sObjectName;
589 OUString sDatasourceName = _rDatasource;
590 sObjectName = _rCommand;
592 // for compatibility: create a string which can be used for the SOT_FORMATSTR_ID_SBA_DATAEXCHANGE format
594 bool bTreatAsStatement = (CommandType::COMMAND == _nCommandType);
595 // statements are - in this old and ugly format - described as queries
597 const sal_Unicode cSeparator = sal_Unicode(11);
598 const OUString sSeparator(&cSeparator, 1);
600 const sal_Unicode cTableMark = '1';
601 const sal_Unicode cQueryMark = '0';
603 // build the descriptor string
604 m_sCompatibleObjectDescription += sDatasourceName;
605 m_sCompatibleObjectDescription += sSeparator;
606 m_sCompatibleObjectDescription += bTreatAsStatement ? OUString() : sObjectName;
607 m_sCompatibleObjectDescription += sSeparator;
608 switch (_nCommandType)
610 case CommandType::TABLE:
611 m_sCompatibleObjectDescription += OUString(&cTableMark, 1);
612 break;
613 case CommandType::QUERY:
614 m_sCompatibleObjectDescription += OUString(&cQueryMark, 1);
615 break;
616 case CommandType::COMMAND:
617 m_sCompatibleObjectDescription += OUString(&cQueryMark, 1);
618 // think of it as a query
619 break;
621 m_sCompatibleObjectDescription += sSeparator;
622 m_sCompatibleObjectDescription += _bAddCommand ? _sActiveCommand : OUString();
623 m_sCompatibleObjectDescription += sSeparator;
627 OMultiColumnTransferable::OMultiColumnTransferable(const Sequence< PropertyValue >& _aDescriptors) : m_aDescriptors(_aDescriptors)
631 sal_uInt32 OMultiColumnTransferable::getDescriptorFormatId()
633 static sal_uInt32 s_nFormat = (sal_uInt32)-1;
634 if ((sal_uInt32)-1 == s_nFormat)
636 s_nFormat = SotExchange::RegisterFormatName(OUString("application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\""));
637 OSL_ENSURE((sal_uInt32)-1 != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
639 return s_nFormat;
642 void OMultiColumnTransferable::AddSupportedFormats()
644 AddFormat(getDescriptorFormatId());
647 bool OMultiColumnTransferable::GetData( const DataFlavor& _rFlavor )
649 const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
650 if (nFormatId == getDescriptorFormatId())
652 return SetAny( makeAny( m_aDescriptors ), _rFlavor );
655 return false;
659 bool OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector& _rFlavors)
661 DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
662 for ( ;
663 aCheck != _rFlavors.end() && getDescriptorFormatId() == aCheck->mnSotId;
664 ++aCheck
668 return aCheck == _rFlavors.end();
672 Sequence< PropertyValue > OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper& _rData)
674 Sequence< PropertyValue > aList;
675 if (_rData.HasFormat(getDescriptorFormatId()))
677 // extract the any from the transferable
678 DataFlavor aFlavor;
679 #if OSL_DEBUG_LEVEL > 0
680 bool bSuccess =
681 #endif
682 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor);
683 OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
685 _rData.GetAny(aFlavor) >>= aList;
686 } // if (_rData.HasFormat(getDescriptorFormatId()))
687 return aList;
690 void OMultiColumnTransferable::ObjectReleased()
692 m_aDescriptors.realloc(0);
696 } // namespace svx
700 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */