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