bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / fmcomp / dbaobjectex.cxx
blob38d4a1e0d4c38bdca6174285c57d1d55e927ed13
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/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 "fmprop.hrc"
25 #include <comphelper/extract.hxx>
26 #include <sot/formats.hxx>
27 #include <sot/exchange.hxx>
28 #include <comphelper/propertysetinfo.hxx>
31 namespace svx
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::sdb;
38 using namespace ::com::sun::star::sdbc;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::ucb;
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 OComponentTransferable::OComponentTransferable(const OUString& _rDatasourceOrLocation
47 ,const Reference< XContent>& _xContent)
49 m_aDescriptor.setDataSource(_rDatasourceOrLocation);
50 m_aDescriptor[daComponent] <<= _xContent;
55 SotClipboardFormatId OComponentTransferable::getDescriptorFormatId(bool _bExtractForm)
57 static SotClipboardFormatId s_nReportFormat = static_cast<SotClipboardFormatId>(-1);
58 static SotClipboardFormatId s_nFormFormat = static_cast<SotClipboardFormatId>(-1);
59 if ( _bExtractForm && static_cast<SotClipboardFormatId>(-1) == s_nFormFormat )
61 s_nFormFormat = SotExchange::RegisterFormatName(OUString("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"" ));
62 OSL_ENSURE(static_cast<SotClipboardFormatId>(-1) != s_nFormFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
64 else if ( !_bExtractForm && static_cast<SotClipboardFormatId>(-1) == s_nReportFormat)
66 s_nReportFormat = SotExchange::RegisterFormatName(OUString("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\""));
67 OSL_ENSURE(static_cast<SotClipboardFormatId>(-1) != s_nReportFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
69 return _bExtractForm ? s_nFormFormat : s_nReportFormat;
73 void OComponentTransferable::AddSupportedFormats()
75 bool bForm = true;
76 try
78 Reference<XPropertySet> xProp;
79 m_aDescriptor[daComponent] >>= xProp;
80 if ( xProp.is() )
81 xProp->getPropertyValue("IsForm") >>= bForm;
83 catch(const Exception&)
85 AddFormat(getDescriptorFormatId(bForm));
89 bool OComponentTransferable::GetData( const DataFlavor& _rFlavor, const OUString& /*rDestDoc*/ )
91 const SotClipboardFormatId nFormatId = SotExchange::GetFormat(_rFlavor);
92 if ( nFormatId == getDescriptorFormatId(true) || nFormatId == getDescriptorFormatId(false) )
93 return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor );
95 return false;
99 bool OComponentTransferable::canExtractComponentDescriptor(const DataFlavorExVector& _rFlavors, bool _bForm )
101 DataFlavorExVector::const_iterator aEnd = _rFlavors.end();
102 for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
103 aCheck != aEnd;
104 ++aCheck
107 if ( getDescriptorFormatId(_bForm) == aCheck->mnSotId )
108 return true;
111 return false;
115 ODataAccessDescriptor OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData)
117 bool bForm = _rData.HasFormat(getDescriptorFormatId(true));
118 if ( bForm || _rData.HasFormat(getDescriptorFormatId(false)) )
120 // the object has a real descriptor object (not just the old compatible format)
122 // extract the any from the transferable
123 DataFlavor aFlavor;
124 #if OSL_DEBUG_LEVEL > 0
125 bool bSuccess =
126 #endif
127 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(bForm), aFlavor);
128 OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
130 Any aDescriptor = _rData.GetAny(aFlavor, OUString());
132 // extract the property value sequence
133 Sequence< PropertyValue > aDescriptorProps;
134 #if OSL_DEBUG_LEVEL > 0
135 bSuccess =
136 #endif
137 aDescriptor >>= aDescriptorProps;
138 OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!");
140 // build the real descriptor
141 return ODataAccessDescriptor(aDescriptorProps);
144 return ODataAccessDescriptor();
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */