1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 #include <svx/dbaobjectex.hxx> 27 #include <osl/diagnose.h> 28 #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 29 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> 30 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> 31 #ifndef _SVX_FMPROP_HRC 32 #include "fmprop.hrc" 33 #endif 34 #include <comphelper/extract.hxx> 35 #include <sot/formats.hxx> 36 #include <sot/exchange.hxx> 37 #include <comphelper/propertysetinfo.hxx> 38 #ifndef _SVX_FMPROP_HRC 39 #include "fmprop.hrc" 40 #endif 41 42 //........................................................................ 43 namespace svx 44 { 45 //........................................................................ 46 47 using namespace ::com::sun::star::uno; 48 using namespace ::com::sun::star::beans; 49 using namespace ::com::sun::star::sdb; 50 using namespace ::com::sun::star::sdbc; 51 using namespace ::com::sun::star::lang; 52 using namespace ::com::sun::star::ucb; 53 using namespace ::com::sun::star::sdbcx; 54 using namespace ::com::sun::star::container; 55 using namespace ::com::sun::star::datatransfer; 56 using namespace ::comphelper; 57 58 //==================================================================== 59 //= OComponentTransferable 60 //==================================================================== 61 //-------------------------------------------------------------------- OComponentTransferable(const::rtl::OUString & _rDatasourceOrLocation,const Reference<XContent> & _xContent)62 OComponentTransferable::OComponentTransferable(const ::rtl::OUString& _rDatasourceOrLocation 63 ,const Reference< XContent>& _xContent) 64 { 65 m_aDescriptor.setDataSource(_rDatasourceOrLocation); 66 m_aDescriptor[daComponent] <<= _xContent; 67 } 68 69 70 //-------------------------------------------------------------------- getDescriptorFormatId(sal_Bool _bExtractForm)71 sal_uInt32 OComponentTransferable::getDescriptorFormatId(sal_Bool _bExtractForm) 72 { 73 static sal_uInt32 s_nReportFormat = (sal_uInt32)-1; 74 static sal_uInt32 s_nFormFormat = (sal_uInt32)-1; 75 if ( _bExtractForm && (sal_uInt32)-1 == s_nFormFormat ) 76 { 77 s_nFormFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"" )); 78 OSL_ENSURE((sal_uInt32)-1 != s_nFormFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!"); 79 } 80 else if ( !_bExtractForm && (sal_uInt32)-1 == s_nReportFormat) 81 { 82 s_nReportFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\"")); 83 OSL_ENSURE((sal_uInt32)-1 != s_nReportFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!"); 84 } 85 return _bExtractForm ? s_nFormFormat : s_nReportFormat; 86 } 87 88 //-------------------------------------------------------------------- AddSupportedFormats()89 void OComponentTransferable::AddSupportedFormats() 90 { 91 sal_Bool bForm = sal_True; 92 try 93 { 94 Reference<XPropertySet> xProp; 95 m_aDescriptor[daComponent] >>= xProp; 96 if ( xProp.is() ) 97 xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm"))) >>= bForm; 98 } 99 catch(Exception) 100 {} 101 AddFormat(getDescriptorFormatId(bForm)); 102 } 103 104 //-------------------------------------------------------------------- GetData(const DataFlavor & _rFlavor)105 sal_Bool OComponentTransferable::GetData( const DataFlavor& _rFlavor ) 106 { 107 const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor); 108 if ( nFormatId == getDescriptorFormatId(sal_True) || nFormatId == getDescriptorFormatId(sal_False) ) 109 return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor ); 110 111 return sal_False; 112 } 113 114 //-------------------------------------------------------------------- canExtractComponentDescriptor(const DataFlavorExVector & _rFlavors,sal_Bool _bForm)115 sal_Bool OComponentTransferable::canExtractComponentDescriptor(const DataFlavorExVector& _rFlavors,sal_Bool _bForm ) 116 { 117 DataFlavorExVector::const_iterator aEnd = _rFlavors.end(); 118 for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin(); 119 aCheck != aEnd; 120 ++aCheck 121 ) 122 { 123 if ( getDescriptorFormatId(_bForm) == aCheck->mnSotId ) 124 return sal_True; 125 } 126 127 return sal_False; 128 } 129 130 //-------------------------------------------------------------------- extractComponentDescriptor(const TransferableDataHelper & _rData)131 ODataAccessDescriptor OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData) 132 { 133 sal_Bool bForm = _rData.HasFormat(getDescriptorFormatId(sal_True)); 134 if ( bForm || _rData.HasFormat(getDescriptorFormatId(sal_False)) ) 135 { 136 // the object has a real descriptor object (not just the old compatible format) 137 138 // extract the any from the transferable 139 DataFlavor aFlavor; 140 #if OSL_DEBUG_LEVEL > 0 141 sal_Bool bSuccess = 142 #endif 143 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(bForm), aFlavor); 144 OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!"); 145 146 Any aDescriptor = _rData.GetAny(aFlavor); 147 148 // extract the property value sequence 149 Sequence< PropertyValue > aDescriptorProps; 150 #if OSL_DEBUG_LEVEL > 0 151 bSuccess = 152 #endif 153 aDescriptor >>= aDescriptorProps; 154 OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!"); 155 156 // build the real descriptor 157 return ODataAccessDescriptor(aDescriptorProps); 158 } 159 160 return ODataAccessDescriptor(); 161 } 162 163 //-------------------------------------------------------------------- extractComponentDescriptor(const TransferableDataHelper & _rData,sal_Bool _bExtractForm,::rtl::OUString & _rDatasourceOrLocation,::com::sun::star::uno::Reference<XContent> & _xContent)164 sal_Bool OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData 165 ,sal_Bool _bExtractForm 166 , ::rtl::OUString& _rDatasourceOrLocation 167 , ::com::sun::star::uno::Reference< XContent>& _xContent) 168 { 169 if ( _rData.HasFormat( getDescriptorFormatId(_bExtractForm)) ) 170 { 171 ODataAccessDescriptor aDescriptor = extractComponentDescriptor(_rData); 172 _rDatasourceOrLocation = aDescriptor.getDataSource(); 173 aDescriptor[daComponent] >>= _xContent; 174 return sal_True; 175 } 176 177 return sal_False; 178 } 179 //........................................................................ 180 } // namespace svx 181 //........................................................................ 182 183 184