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
& _rConnectionResource
48 ,const sal_Int32 _nCommandType
49 ,const OUString
& _rCommand
50 ,const OUString
& _rFieldName
51 ,ColumnTransferFormatFlags _nFormats
)
52 :m_nFormatFlags(_nFormats
)
54 implConstruct(_rDatasource
,_rConnectionResource
,_nCommandType
, _rCommand
, _rFieldName
);
58 OColumnTransferable::OColumnTransferable(const ODataAccessDescriptor
& _rDescriptor
, ColumnTransferFormatFlags _nFormats
)
59 :m_nFormatFlags(_nFormats
)
61 OUString sDataSource
, sDatabaseLocation
, sConnectionResource
, sCommand
, sFieldName
;
62 if ( _rDescriptor
.has( daDataSource
) ) _rDescriptor
[ daDataSource
] >>= sDataSource
;
63 if ( _rDescriptor
.has( daDatabaseLocation
) ) _rDescriptor
[ daDatabaseLocation
] >>= sDatabaseLocation
;
64 if ( _rDescriptor
.has( daConnectionResource
) ) _rDescriptor
[ daConnectionResource
] >>= sConnectionResource
;
65 if ( _rDescriptor
.has( daCommand
) ) _rDescriptor
[ daCommand
] >>= sCommand
;
66 if ( _rDescriptor
.has( daColumnName
) ) _rDescriptor
[ daColumnName
] >>= sFieldName
;
68 sal_Int32 nCommandType
= CommandType::TABLE
;
69 OSL_VERIFY( _rDescriptor
[ daCommandType
] >>= nCommandType
);
73 sDataSource
.isEmpty() ? sDatabaseLocation
: sDataSource
,
74 sConnectionResource
, nCommandType
, sCommand
, sFieldName
);
76 if ( m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
78 if ( _rDescriptor
.has( daConnection
) )
79 m_aDescriptor
[ daConnection
] = _rDescriptor
[ daConnection
];
80 if ( _rDescriptor
.has( daColumnObject
) )
81 m_aDescriptor
[ daColumnObject
] = _rDescriptor
[ daColumnObject
];
86 OColumnTransferable::OColumnTransferable(const Reference
< XPropertySet
>& _rxForm
,
87 const OUString
& _rFieldName
, const Reference
< XPropertySet
>& _rxColumn
,
88 const Reference
< XConnection
>& _rxConnection
, ColumnTransferFormatFlags _nFormats
)
89 :m_nFormatFlags(_nFormats
)
91 OSL_ENSURE(_rxForm
.is(), "OColumnTransferable::OColumnTransferable: invalid form!");
92 // collect the necessary information from the form
94 sal_Int32 nCommandType
= CommandType::TABLE
;
95 OUString sDatasource
,sURL
;
97 bool bTryToParse
= true;
100 _rxForm
->getPropertyValue(FM_PROP_COMMANDTYPE
) >>= nCommandType
;
101 _rxForm
->getPropertyValue(FM_PROP_COMMAND
) >>= sCommand
;
102 _rxForm
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sDatasource
;
103 _rxForm
->getPropertyValue(FM_PROP_URL
) >>= sURL
;
104 bTryToParse
= ::cppu::any2bool(_rxForm
->getPropertyValue(FM_PROP_ESCAPE_PROCESSING
));
108 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
111 // If the data source is an SQL-statement and simple enough (means "select <field list> from <table> where ....")
112 // we are able to fake the drag information we are about to create.
113 if (bTryToParse
&& (CommandType::COMMAND
== nCommandType
))
117 Reference
< XTablesSupplier
> xSupTab
;
118 _rxForm
->getPropertyValue("SingleSelectQueryComposer") >>= xSupTab
;
122 Reference
< XNameAccess
> xNames
= xSupTab
->getTables();
125 Sequence
< OUString
> aTables
= xNames
->getElementNames();
126 if (1 == aTables
.getLength())
128 sCommand
= aTables
[0];
129 nCommandType
= CommandType::TABLE
;
136 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
140 implConstruct(sDatasource
, sURL
,nCommandType
, sCommand
, _rFieldName
);
142 if ((m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
145 m_aDescriptor
[daColumnObject
] <<= _rxColumn
;
146 if (_rxConnection
.is())
147 m_aDescriptor
[daConnection
] <<= _rxConnection
;
152 SotClipboardFormatId
OColumnTransferable::getDescriptorFormatId()
154 static SotClipboardFormatId s_nFormat
= static_cast<SotClipboardFormatId
>(-1);
155 if (static_cast<SotClipboardFormatId
>(-1) == s_nFormat
)
157 s_nFormat
= SotExchange::RegisterFormatName(OUString("application/x-openoffice;windows_formatname=\"dbaccess.ColumnDescriptorTransfer\""));
158 OSL_ENSURE(static_cast<SotClipboardFormatId
>(-1) != s_nFormat
, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
164 void OColumnTransferable::implConstruct( const OUString
& _rDatasource
165 ,const OUString
& _rConnectionResource
166 ,const sal_Int32 _nCommandType
167 ,const OUString
& _rCommand
168 , const OUString
& _rFieldName
)
170 const sal_Unicode cSeparator
= sal_Unicode(11);
171 const OUString
sSeparator(&cSeparator
, 1);
173 m_sCompatibleFormat
.clear();
174 m_sCompatibleFormat
+= _rDatasource
;
175 m_sCompatibleFormat
+= sSeparator
;
176 m_sCompatibleFormat
+= _rCommand
;
177 m_sCompatibleFormat
+= sSeparator
;
179 sal_Unicode cCommandType
;
180 switch (_nCommandType
)
182 case CommandType::TABLE
:
185 case CommandType::QUERY
:
192 m_sCompatibleFormat
+= OUString(&cCommandType
, 1);
193 m_sCompatibleFormat
+= sSeparator
;
194 m_sCompatibleFormat
+= _rFieldName
;
196 m_aDescriptor
.clear();
197 if ((m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
199 m_aDescriptor
.setDataSource(_rDatasource
);
200 if ( !_rConnectionResource
.isEmpty() )
201 m_aDescriptor
[daConnectionResource
] <<= _rConnectionResource
;
203 m_aDescriptor
[daCommand
] <<= _rCommand
;
204 m_aDescriptor
[daCommandType
] <<= _nCommandType
;
205 m_aDescriptor
[daColumnName
] <<= _rFieldName
;
210 void OColumnTransferable::AddSupportedFormats()
212 if (ColumnTransferFormatFlags::CONTROL_EXCHANGE
& m_nFormatFlags
)
213 AddFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
);
215 if (ColumnTransferFormatFlags::FIELD_DESCRIPTOR
& m_nFormatFlags
)
216 AddFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
);
218 if (ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
& m_nFormatFlags
)
219 AddFormat(getDescriptorFormatId());
223 bool OColumnTransferable::GetData( const DataFlavor
& _rFlavor
, const OUString
& /*rDestDoc*/ )
225 const SotClipboardFormatId nFormatId
= SotExchange::GetFormat(_rFlavor
);
228 case SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
:
229 case SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
:
230 return SetString(m_sCompatibleFormat
, _rFlavor
);
233 if (nFormatId
== getDescriptorFormatId())
234 return SetAny( makeAny( m_aDescriptor
.createPropertyValueSequence() ), _rFlavor
);
240 bool OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector
& _rFlavors
, ColumnTransferFormatFlags _nFormats
)
242 bool bFieldFormat
= bool(_nFormats
& ColumnTransferFormatFlags::FIELD_DESCRIPTOR
);
243 bool bControlFormat
= bool(_nFormats
& ColumnTransferFormatFlags::CONTROL_EXCHANGE
);
244 bool bDescriptorFormat
= bool(_nFormats
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
);
245 for ( DataFlavorExVector::const_iterator aCheck
= _rFlavors
.begin();
246 aCheck
!= _rFlavors
.end();
250 if (bFieldFormat
&& (SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
== aCheck
->mnSotId
))
252 if (bControlFormat
&& (SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
== aCheck
->mnSotId
))
254 if (bDescriptorFormat
&& (getDescriptorFormatId() == aCheck
->mnSotId
))
262 ODataAccessDescriptor
OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper
& _rData
)
264 if (_rData
.HasFormat(getDescriptorFormatId()))
266 // the object has a real descriptor object (not just the old compatible format)
268 // extract the any from the transferable
270 #if OSL_DEBUG_LEVEL > 0
273 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor
);
274 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
276 Any aDescriptor
= _rData
.GetAny(aFlavor
, OUString());
278 // extract the property value sequence
279 Sequence
< PropertyValue
> aDescriptorProps
;
280 #if OSL_DEBUG_LEVEL > 0
283 aDescriptor
>>= aDescriptorProps
;
284 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
286 // build the real descriptor
287 return ODataAccessDescriptor(aDescriptorProps
);
290 // only the old (compatible) format exists -> use the other extract method ...
291 OUString sDatasource
, sCommand
, sFieldName
,sDatabaseLocation
,sConnectionResource
;
292 sal_Int32 nCommandType
= CommandType::COMMAND
;
294 ODataAccessDescriptor aDescriptor
;
295 if (extractColumnDescriptor(_rData
, sDatasource
, sDatabaseLocation
,sConnectionResource
,nCommandType
, sCommand
, sFieldName
))
297 // and build an own descriptor
298 if ( !sDatasource
.isEmpty() )
299 aDescriptor
[daDataSource
] <<= sDatasource
;
300 if ( !sDatabaseLocation
.isEmpty() )
301 aDescriptor
[daDatabaseLocation
] <<= sDatabaseLocation
;
302 if ( !sConnectionResource
.isEmpty() )
303 aDescriptor
[daConnectionResource
] <<= sConnectionResource
;
305 aDescriptor
[daCommand
] <<= sCommand
;
306 aDescriptor
[daCommandType
] <<= nCommandType
;
307 aDescriptor
[daColumnName
] <<= sFieldName
;
313 bool OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper
& _rData
314 ,OUString
& _rDatasource
315 ,OUString
& _rDatabaseLocation
316 ,OUString
& _rConnectionResource
317 ,sal_Int32
& _nCommandType
319 ,OUString
& _rFieldName
)
321 if ( _rData
.HasFormat(getDescriptorFormatId()) )
323 ODataAccessDescriptor aDescriptor
= extractColumnDescriptor(_rData
);
324 if ( aDescriptor
.has(daDataSource
) )
325 aDescriptor
[daDataSource
] >>= _rDatasource
;
326 if ( aDescriptor
.has(daDatabaseLocation
) )
327 aDescriptor
[daDatabaseLocation
] >>= _rDatabaseLocation
;
328 if ( aDescriptor
.has(daConnectionResource
) )
329 aDescriptor
[daConnectionResource
] >>= _rConnectionResource
;
331 aDescriptor
[daCommand
] >>= _rCommand
;
332 aDescriptor
[daCommandType
] >>= _nCommandType
;
333 aDescriptor
[daColumnName
] >>= _rFieldName
;
337 // check if we have a (string) format we can use ....
338 SotClipboardFormatId nRecognizedFormat
= SotClipboardFormatId::NONE
;
339 if (_rData
.HasFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
))
340 nRecognizedFormat
= SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
;
341 if (_rData
.HasFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
))
342 nRecognizedFormat
= SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
;
343 if (nRecognizedFormat
== SotClipboardFormatId::NONE
)
346 OUString sFieldDescription
;
347 (void)const_cast<TransferableDataHelper
&>(_rData
).GetString(nRecognizedFormat
, sFieldDescription
);
349 const sal_Unicode cSeparator
= sal_Unicode(11);
350 _rDatasource
= sFieldDescription
.getToken(0, cSeparator
);
351 _rCommand
= sFieldDescription
.getToken(1, cSeparator
);
352 _nCommandType
= sFieldDescription
.getToken(2, cSeparator
).toInt32();
353 _rFieldName
= sFieldDescription
.getToken(3, cSeparator
);
359 void OColumnTransferable::addDataToContainer( TransferDataContainer
* _pContainer
)
361 OSL_ENSURE( _pContainer
, "OColumnTransferable::addDataToContainer: invalid container!" );
364 if ( m_nFormatFlags
& ColumnTransferFormatFlags::FIELD_DESCRIPTOR
)
365 _pContainer
->CopyAny( SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
, makeAny( m_sCompatibleFormat
) );
367 if ( m_nFormatFlags
& ColumnTransferFormatFlags::CONTROL_EXCHANGE
)
368 _pContainer
->CopyAny( SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
, makeAny( m_sCompatibleFormat
) );
370 if ( m_nFormatFlags
& ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
372 Any aContent
= makeAny( m_aDescriptor
.createPropertyValueSequence() );
373 _pContainer
->CopyAny( getDescriptorFormatId(), aContent
);
378 ODataAccessObjectTransferable::ODataAccessObjectTransferable(
379 const OUString
& _rDatasource
380 ,const OUString
& _rConnectionResource
381 ,const sal_Int32 _nCommandType
382 ,const OUString
& _rCommand
385 construct(_rDatasource
,_rConnectionResource
,_nCommandType
,_rCommand
,NULL
,(CommandType::COMMAND
== _nCommandType
),_rCommand
);
388 ODataAccessObjectTransferable::ODataAccessObjectTransferable(
389 const OUString
& _rDatasource
390 ,const OUString
& _rConnectionResource
391 ,const sal_Int32 _nCommandType
392 ,const OUString
& _rCommand
393 ,const Reference
< XConnection
>& _rxConnection
)
395 OSL_ENSURE(_rxConnection
.is(),"Wrong ctor used.!");
396 construct(_rDatasource
,_rConnectionResource
,_nCommandType
,_rCommand
,_rxConnection
,(CommandType::COMMAND
== _nCommandType
),_rCommand
);
400 ODataAccessObjectTransferable::ODataAccessObjectTransferable(const Reference
< XPropertySet
>& _rxLivingForm
)
402 // collect some properties of the form
403 OUString sDatasourceName
,sConnectionResource
;
404 sal_Int32 nObjectType
= CommandType::COMMAND
;
405 OUString sObjectName
;
406 Reference
< XConnection
> xConnection
;
409 _rxLivingForm
->getPropertyValue(FM_PROP_COMMANDTYPE
) >>= nObjectType
;
410 _rxLivingForm
->getPropertyValue(FM_PROP_COMMAND
) >>= sObjectName
;
411 _rxLivingForm
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sDatasourceName
;
412 _rxLivingForm
->getPropertyValue(FM_PROP_URL
) >>= sConnectionResource
;
413 _rxLivingForm
->getPropertyValue(FM_PROP_ACTIVE_CONNECTION
) >>= xConnection
;
417 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
421 // check if the SQL-statement is modified
422 OUString sCompleteStatement
;
425 _rxLivingForm
->getPropertyValue(FM_PROP_ACTIVECOMMAND
) >>= sCompleteStatement
;
427 catch (const Exception
&)
429 OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
433 construct( sDatasourceName
436 ,sObjectName
,xConnection
437 ,!((CommandType::QUERY
== nObjectType
))
438 ,sCompleteStatement
);
442 void ODataAccessObjectTransferable::AddSupportedFormats()
444 sal_Int32 nObjectType
= CommandType::COMMAND
;
445 m_aDescriptor
[daCommandType
] >>= nObjectType
;
448 case CommandType::TABLE
:
449 AddFormat(SotClipboardFormatId::DBACCESS_TABLE
);
451 case CommandType::QUERY
:
452 AddFormat(SotClipboardFormatId::DBACCESS_QUERY
);
454 case CommandType::COMMAND
:
455 AddFormat(SotClipboardFormatId::DBACCESS_COMMAND
);
459 if (!m_sCompatibleObjectDescription
.isEmpty())
460 AddFormat(SotClipboardFormatId::SBA_DATAEXCHANGE
);
464 bool ODataAccessObjectTransferable::GetData( const DataFlavor
& rFlavor
, const OUString
& /*rDestDoc*/ )
466 SotClipboardFormatId nFormat
= SotExchange::GetFormat(rFlavor
);
469 case SotClipboardFormatId::DBACCESS_TABLE
:
470 case SotClipboardFormatId::DBACCESS_QUERY
:
471 case SotClipboardFormatId::DBACCESS_COMMAND
:
472 return SetAny( makeAny(m_aDescriptor
.createPropertyValueSequence()), rFlavor
);
474 case SotClipboardFormatId::SBA_DATAEXCHANGE
:
475 return SetString(m_sCompatibleObjectDescription
, rFlavor
);
482 bool ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector
& _rFlavors
)
484 for ( DataFlavorExVector::const_iterator aCheck
= _rFlavors
.begin();
485 aCheck
!= _rFlavors
.end();
489 if (SotClipboardFormatId::DBACCESS_TABLE
== aCheck
->mnSotId
)
491 if (SotClipboardFormatId::DBACCESS_QUERY
== aCheck
->mnSotId
)
493 if (SotClipboardFormatId::DBACCESS_COMMAND
== aCheck
->mnSotId
)
500 ODataAccessDescriptor
ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper
& _rData
)
502 SotClipboardFormatId nKnownFormatId
= SotClipboardFormatId::NONE
;
503 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_TABLE
) )
504 nKnownFormatId
= SotClipboardFormatId::DBACCESS_TABLE
;
505 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_QUERY
) )
506 nKnownFormatId
= SotClipboardFormatId::DBACCESS_QUERY
;
507 if ( _rData
.HasFormat( SotClipboardFormatId::DBACCESS_COMMAND
) )
508 nKnownFormatId
= SotClipboardFormatId::DBACCESS_COMMAND
;
510 if (SotClipboardFormatId::NONE
!= nKnownFormatId
)
512 // extract the any from the transferable
514 #if OSL_DEBUG_LEVEL > 0
517 SotExchange::GetFormatDataFlavor(nKnownFormatId
, aFlavor
);
518 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
520 Any aDescriptor
= _rData
.GetAny(aFlavor
, OUString());
522 // extract the property value sequence
523 Sequence
< PropertyValue
> aDescriptorProps
;
524 #if OSL_DEBUG_LEVEL > 0
527 aDescriptor
>>= aDescriptorProps
;
528 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
530 // build the real descriptor
531 return ODataAccessDescriptor(aDescriptorProps
);
534 OSL_FAIL( "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
535 return ODataAccessDescriptor();
539 void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence
< Any
>& _rSelRows
)
541 const sal_Unicode
cSeparator(11);
542 const OUString
sSeparator(&cSeparator
, 1);
544 const Any
* pSelRows
= _rSelRows
.getConstArray();
545 const Any
* pSelRowsEnd
= pSelRows
+ _rSelRows
.getLength();
546 for ( ; pSelRows
< pSelRowsEnd
; ++pSelRows
)
548 sal_Int32
nSelectedRow( 0 );
549 OSL_VERIFY( *pSelRows
>>= nSelectedRow
);
551 m_sCompatibleObjectDescription
+= OUString::number(nSelectedRow
);
552 m_sCompatibleObjectDescription
+= sSeparator
;
557 void ODataAccessObjectTransferable::ObjectReleased()
559 m_aDescriptor
.clear();
562 void ODataAccessObjectTransferable::construct( const OUString
& _rDatasource
563 ,const OUString
& _rConnectionResource
564 ,const sal_Int32 _nCommandType
565 ,const OUString
& _rCommand
566 ,const Reference
< XConnection
>& _rxConnection
568 ,const OUString
& _sActiveCommand
)
570 m_aDescriptor
.setDataSource(_rDatasource
);
571 // build the descriptor (the property sequence)
572 if ( !_rConnectionResource
.isEmpty() )
573 m_aDescriptor
[daConnectionResource
] <<= _rConnectionResource
;
574 if ( _rxConnection
.is() )
575 m_aDescriptor
[daConnection
] <<= _rxConnection
;
576 m_aDescriptor
[daCommand
] <<= _rCommand
;
577 m_aDescriptor
[daCommandType
] <<= _nCommandType
;
579 // extract the single values from the sequence
581 OUString sObjectName
;
582 OUString sDatasourceName
= _rDatasource
;
583 sObjectName
= _rCommand
;
585 // for compatibility: create a string which can be used for the SotClipboardFormatId::SBA_DATAEXCHANGE format
587 bool bTreatAsStatement
= (CommandType::COMMAND
== _nCommandType
);
588 // statements are - in this old and ugly format - described as queries
590 const sal_Unicode cSeparator
= sal_Unicode(11);
591 const OUString
sSeparator(&cSeparator
, 1);
593 const sal_Unicode cTableMark
= '1';
594 const sal_Unicode cQueryMark
= '0';
596 // build the descriptor string
597 m_sCompatibleObjectDescription
+= sDatasourceName
;
598 m_sCompatibleObjectDescription
+= sSeparator
;
599 m_sCompatibleObjectDescription
+= bTreatAsStatement
? OUString() : sObjectName
;
600 m_sCompatibleObjectDescription
+= sSeparator
;
601 switch (_nCommandType
)
603 case CommandType::TABLE
:
604 m_sCompatibleObjectDescription
+= OUString(&cTableMark
, 1);
606 case CommandType::QUERY
:
607 m_sCompatibleObjectDescription
+= OUString(&cQueryMark
, 1);
609 case CommandType::COMMAND
:
610 m_sCompatibleObjectDescription
+= OUString(&cQueryMark
, 1);
611 // think of it as a query
614 m_sCompatibleObjectDescription
+= sSeparator
;
615 m_sCompatibleObjectDescription
+= _bAddCommand
? _sActiveCommand
: OUString();
616 m_sCompatibleObjectDescription
+= sSeparator
;
620 OMultiColumnTransferable::OMultiColumnTransferable(const Sequence
< PropertyValue
>& _aDescriptors
) : m_aDescriptors(_aDescriptors
)
624 SotClipboardFormatId
OMultiColumnTransferable::getDescriptorFormatId()
626 static SotClipboardFormatId s_nFormat
= static_cast<SotClipboardFormatId
>(-1);
627 if (static_cast<SotClipboardFormatId
>(-1) == s_nFormat
)
629 s_nFormat
= SotExchange::RegisterFormatName(OUString("application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\""));
630 OSL_ENSURE(static_cast<SotClipboardFormatId
>(-1) != s_nFormat
, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
635 void OMultiColumnTransferable::AddSupportedFormats()
637 AddFormat(getDescriptorFormatId());
640 bool OMultiColumnTransferable::GetData( const DataFlavor
& _rFlavor
, const OUString
& /*rDestDoc*/ )
642 const SotClipboardFormatId nFormatId
= SotExchange::GetFormat(_rFlavor
);
643 if (nFormatId
== getDescriptorFormatId())
645 return SetAny( makeAny( m_aDescriptors
), _rFlavor
);
652 bool OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector
& _rFlavors
)
654 DataFlavorExVector::const_iterator aCheck
= _rFlavors
.begin();
656 aCheck
!= _rFlavors
.end() && getDescriptorFormatId() == aCheck
->mnSotId
;
661 return aCheck
== _rFlavors
.end();
665 Sequence
< PropertyValue
> OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper
& _rData
)
667 Sequence
< PropertyValue
> aList
;
668 if (_rData
.HasFormat(getDescriptorFormatId()))
670 // extract the any from the transferable
672 #if OSL_DEBUG_LEVEL > 0
675 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor
);
676 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
678 _rData
.GetAny(aFlavor
, OUString()) >>= aList
;
679 } // if (_rData.HasFormat(getDescriptorFormatId()))
683 void OMultiColumnTransferable::ObjectReleased()
685 m_aDescriptors
.realloc(0);
693 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */