update dev300-m58
[ooovba.git] / svx / source / fmcomp / dbaobjectex.cxx
blobd30ba00e27fb5982b830b4aa1790940f9eac6b56
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbaobjectex.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/dbaobjectex.hxx>
34 #include <osl/diagnose.h>
35 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
36 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
37 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
38 #ifndef _SVX_FMPROP_HRC
39 #include "fmprop.hrc"
40 #endif
41 #include <comphelper/extract.hxx>
42 #include <sot/formats.hxx>
43 #include <sot/exchange.hxx>
44 #include <comphelper/propertysetinfo.hxx>
45 #ifndef _SVX_FMPROP_HRC
46 #include "fmprop.hrc"
47 #endif
49 //........................................................................
50 namespace svx
52 //........................................................................
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::sdb;
57 using namespace ::com::sun::star::sdbc;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::ucb;
60 using namespace ::com::sun::star::sdbcx;
61 using namespace ::com::sun::star::container;
62 using namespace ::com::sun::star::datatransfer;
63 using namespace ::comphelper;
65 //====================================================================
66 //= OComponentTransferable
67 //====================================================================
68 //--------------------------------------------------------------------
69 OComponentTransferable::OComponentTransferable(const ::rtl::OUString& _rDatasourceOrLocation
70 ,const Reference< XContent>& _xContent)
72 m_aDescriptor.setDataSource(_rDatasourceOrLocation);
73 m_aDescriptor[daComponent] <<= _xContent;
77 //--------------------------------------------------------------------
78 sal_uInt32 OComponentTransferable::getDescriptorFormatId(sal_Bool _bExtractForm)
80 static sal_uInt32 s_nReportFormat = (sal_uInt32)-1;
81 static sal_uInt32 s_nFormFormat = (sal_uInt32)-1;
82 if ( _bExtractForm && (sal_uInt32)-1 == s_nFormFormat )
84 s_nFormFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"" ));
85 OSL_ENSURE((sal_uInt32)-1 != s_nFormFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
87 else if ( !_bExtractForm && (sal_uInt32)-1 == s_nReportFormat)
89 s_nReportFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\""));
90 OSL_ENSURE((sal_uInt32)-1 != s_nReportFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
92 return _bExtractForm ? s_nFormFormat : s_nReportFormat;
95 //--------------------------------------------------------------------
96 void OComponentTransferable::AddSupportedFormats()
98 sal_Bool bForm = sal_True;
99 try
101 Reference<XPropertySet> xProp;
102 m_aDescriptor[daComponent] >>= xProp;
103 if ( xProp.is() )
104 xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm"))) >>= bForm;
106 catch(Exception)
108 AddFormat(getDescriptorFormatId(bForm));
111 //--------------------------------------------------------------------
112 sal_Bool OComponentTransferable::GetData( const DataFlavor& _rFlavor )
114 const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
115 if ( nFormatId == getDescriptorFormatId(sal_True) || nFormatId == getDescriptorFormatId(sal_False) )
116 return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor );
118 return sal_False;
121 //--------------------------------------------------------------------
122 sal_Bool OComponentTransferable::canExtractComponentDescriptor(const DataFlavorExVector& _rFlavors,sal_Bool _bForm )
124 DataFlavorExVector::const_iterator aEnd = _rFlavors.end();
125 for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
126 aCheck != aEnd;
127 ++aCheck
130 if ( getDescriptorFormatId(_bForm) == aCheck->mnSotId )
131 return sal_True;
134 return sal_False;
137 //--------------------------------------------------------------------
138 ODataAccessDescriptor OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData)
140 sal_Bool bForm = _rData.HasFormat(getDescriptorFormatId(sal_True));
141 if ( bForm || _rData.HasFormat(getDescriptorFormatId(sal_False)) )
143 // the object has a real descriptor object (not just the old compatible format)
145 // extract the any from the transferable
146 DataFlavor aFlavor;
147 #if OSL_DEBUG_LEVEL > 0
148 sal_Bool bSuccess =
149 #endif
150 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(bForm), aFlavor);
151 OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
153 Any aDescriptor = _rData.GetAny(aFlavor);
155 // extract the property value sequence
156 Sequence< PropertyValue > aDescriptorProps;
157 #if OSL_DEBUG_LEVEL > 0
158 bSuccess =
159 #endif
160 aDescriptor >>= aDescriptorProps;
161 OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!");
163 // build the real descriptor
164 return ODataAccessDescriptor(aDescriptorProps);
167 return ODataAccessDescriptor();
170 //--------------------------------------------------------------------
171 sal_Bool OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData
172 ,sal_Bool _bExtractForm
173 , ::rtl::OUString& _rDatasourceOrLocation
174 , ::com::sun::star::uno::Reference< XContent>& _xContent)
176 if ( _rData.HasFormat( getDescriptorFormatId(_bExtractForm)) )
178 ODataAccessDescriptor aDescriptor = extractComponentDescriptor(_rData);
179 _rDatasourceOrLocation = aDescriptor.getDataSource();
180 aDescriptor[daComponent] >>= _xContent;
181 return sal_True;
184 return sal_False;
186 //........................................................................
187 } // namespace svx
188 //........................................................................