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/dbaobjectex.hxx>
21 #include <osl/diagnose.h>
22 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
23 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
24 #include <com/sun/star/ucb/XContent.hpp>
25 #include <sot/formats.hxx>
26 #include <sot/exchange.hxx>
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::beans
;
35 using namespace ::com::sun::star::sdb
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::ucb
;
38 using namespace ::com::sun::star::sdbcx
;
39 using namespace ::com::sun::star::container
;
40 using namespace ::com::sun::star::datatransfer
;
42 OComponentTransferable::OComponentTransferable()
46 void OComponentTransferable::Update(const OUString
& rDatasourceOrLocation
47 ,const Reference
< XContent
>& xContent
)
51 m_aDescriptor
.setDataSource(rDatasourceOrLocation
);
52 m_aDescriptor
[DataAccessDescriptorProperty::Component
] <<= xContent
;
54 AddSupportedFormats();
57 SotClipboardFormatId
OComponentTransferable::getDescriptorFormatId(bool _bExtractForm
)
59 static SotClipboardFormatId s_nReportFormat
= static_cast<SotClipboardFormatId
>(-1);
60 static SotClipboardFormatId s_nFormFormat
= static_cast<SotClipboardFormatId
>(-1);
61 if ( _bExtractForm
&& static_cast<SotClipboardFormatId
>(-1) == s_nFormFormat
)
63 s_nFormFormat
= SotExchange::RegisterFormatName("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"");
64 OSL_ENSURE(static_cast<SotClipboardFormatId
>(-1) != s_nFormFormat
, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
66 else if ( !_bExtractForm
&& static_cast<SotClipboardFormatId
>(-1) == s_nReportFormat
)
68 s_nReportFormat
= SotExchange::RegisterFormatName("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\"");
69 OSL_ENSURE(static_cast<SotClipboardFormatId
>(-1) != s_nReportFormat
, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
71 return _bExtractForm
? s_nFormFormat
: s_nReportFormat
;
75 void OComponentTransferable::AddSupportedFormats()
80 Reference
<XPropertySet
> xProp
;
81 m_aDescriptor
[DataAccessDescriptorProperty::Component
] >>= xProp
;
83 xProp
->getPropertyValue("IsForm") >>= bForm
;
85 catch(const Exception
&)
87 AddFormat(getDescriptorFormatId(bForm
));
91 bool OComponentTransferable::GetData( const DataFlavor
& _rFlavor
, const OUString
& /*rDestDoc*/ )
93 const SotClipboardFormatId nFormatId
= SotExchange::GetFormat(_rFlavor
);
94 if ( nFormatId
== getDescriptorFormatId(true) || nFormatId
== getDescriptorFormatId(false) )
95 return SetAny( makeAny( m_aDescriptor
.createPropertyValueSequence() ) );
101 bool OComponentTransferable::canExtractComponentDescriptor(const DataFlavorExVector
& _rFlavors
, bool _bForm
)
103 SotClipboardFormatId nFormatId
= getDescriptorFormatId(_bForm
);
104 return std::any_of(_rFlavors
.begin(), _rFlavors
.end(),
105 [&nFormatId
](const DataFlavorEx
& rCheck
) { return nFormatId
== rCheck
.mnSotId
; });
109 ODataAccessDescriptor
OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper
& _rData
)
111 bool bForm
= _rData
.HasFormat(getDescriptorFormatId(true));
112 if ( bForm
|| _rData
.HasFormat(getDescriptorFormatId(false)) )
114 // the object has a real descriptor object (not just the old compatible format)
116 // extract the any from the transferable
119 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(bForm
), aFlavor
);
120 OSL_ENSURE(bSuccess
, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
122 Any aDescriptor
= _rData
.GetAny(aFlavor
, OUString());
124 // extract the property value sequence
125 Sequence
< PropertyValue
> aDescriptorProps
;
126 bSuccess
= aDescriptor
>>= aDescriptorProps
;
127 OSL_ENSURE(bSuccess
, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!");
129 // build the real descriptor
130 return ODataAccessDescriptor(aDescriptorProps
);
133 return ODataAccessDescriptor();
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */