Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svx/dbaobjectex.hxx>
30 : : #include <osl/diagnose.h>
31 : : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
32 : : #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
33 : : #include "fmprop.hrc"
34 : : #include <comphelper/extract.hxx>
35 : : #include <sot/formats.hxx>
36 : : #include <sot/exchange.hxx>
37 : : #include <comphelper/propertysetinfo.hxx>
38 : :
39 : : //........................................................................
40 : : namespace svx
41 : : {
42 : : //........................................................................
43 : :
44 : : using namespace ::com::sun::star::uno;
45 : : using namespace ::com::sun::star::beans;
46 : : using namespace ::com::sun::star::sdb;
47 : : using namespace ::com::sun::star::sdbc;
48 : : using namespace ::com::sun::star::lang;
49 : : using namespace ::com::sun::star::ucb;
50 : : using namespace ::com::sun::star::sdbcx;
51 : : using namespace ::com::sun::star::container;
52 : : using namespace ::com::sun::star::datatransfer;
53 : : using namespace ::comphelper;
54 : :
55 : : //====================================================================
56 : : //= OComponentTransferable
57 : : //====================================================================
58 : : //--------------------------------------------------------------------
59 : 0 : OComponentTransferable::OComponentTransferable(const ::rtl::OUString& _rDatasourceOrLocation
60 [ # # ]: 0 : ,const Reference< XContent>& _xContent)
61 : : {
62 [ # # ]: 0 : m_aDescriptor.setDataSource(_rDatasourceOrLocation);
63 [ # # ][ # # ]: 0 : m_aDescriptor[daComponent] <<= _xContent;
64 : 0 : }
65 : :
66 : :
67 : : //--------------------------------------------------------------------
68 : 0 : sal_uInt32 OComponentTransferable::getDescriptorFormatId(sal_Bool _bExtractForm)
69 : : {
70 : : static sal_uInt32 s_nReportFormat = (sal_uInt32)-1;
71 : : static sal_uInt32 s_nFormFormat = (sal_uInt32)-1;
72 [ # # ][ # # ]: 0 : if ( _bExtractForm && (sal_uInt32)-1 == s_nFormFormat )
73 : : {
74 [ # # ][ # # ]: 0 : s_nFormFormat = SotExchange::RegisterFormatName(rtl::OUString("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"" ));
[ # # ]
75 : 0 : OSL_ENSURE((sal_uInt32)-1 != s_nFormFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
76 : : }
77 [ # # ][ # # ]: 0 : else if ( !_bExtractForm && (sal_uInt32)-1 == s_nReportFormat)
78 : : {
79 [ # # ][ # # ]: 0 : s_nReportFormat = SotExchange::RegisterFormatName(rtl::OUString("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\""));
[ # # ]
80 : : OSL_ENSURE((sal_uInt32)-1 != s_nReportFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
81 : : }
82 [ # # ]: 0 : return _bExtractForm ? s_nFormFormat : s_nReportFormat;
83 : : }
84 : :
85 : : //--------------------------------------------------------------------
86 : 0 : void OComponentTransferable::AddSupportedFormats()
87 : : {
88 : 0 : sal_Bool bForm = sal_True;
89 : : try
90 : : {
91 : 0 : Reference<XPropertySet> xProp;
92 [ # # ][ # # ]: 0 : m_aDescriptor[daComponent] >>= xProp;
93 [ # # ]: 0 : if ( xProp.is() )
94 [ # # ][ # # ]: 0 : xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm"))) >>= bForm;
[ # # ]
95 : : }
96 [ # # # # ]: 0 : catch(Exception)
97 [ # # ]: 0 : {}
98 [ # # ][ # # ]: 0 : AddFormat(getDescriptorFormatId(bForm));
99 : 0 : }
100 : :
101 : : //--------------------------------------------------------------------
102 : 0 : sal_Bool OComponentTransferable::GetData( const DataFlavor& _rFlavor )
103 : : {
104 : 0 : const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
105 [ # # ][ # # ]: 0 : if ( nFormatId == getDescriptorFormatId(sal_True) || nFormatId == getDescriptorFormatId(sal_False) )
[ # # ]
106 [ # # ][ # # ]: 0 : return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor );
107 : :
108 : 0 : return sal_False;
109 : : }
110 : :
111 : : //--------------------------------------------------------------------
112 : 0 : sal_Bool OComponentTransferable::canExtractComponentDescriptor(const DataFlavorExVector& _rFlavors,sal_Bool _bForm )
113 : : {
114 : 0 : DataFlavorExVector::const_iterator aEnd = _rFlavors.end();
115 [ # # ][ # # ]: 0 : for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
116 : : aCheck != aEnd;
117 : : ++aCheck
118 : : )
119 : : {
120 [ # # ][ # # ]: 0 : if ( getDescriptorFormatId(_bForm) == aCheck->mnSotId )
121 : 0 : return sal_True;
122 : : }
123 : :
124 : 0 : return sal_False;
125 : : }
126 : :
127 : : //--------------------------------------------------------------------
128 : 0 : ODataAccessDescriptor OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData)
129 : : {
130 : 0 : sal_Bool bForm = _rData.HasFormat(getDescriptorFormatId(sal_True));
131 [ # # ][ # # ]: 0 : if ( bForm || _rData.HasFormat(getDescriptorFormatId(sal_False)) )
[ # # ]
132 : : {
133 : : // the object has a real descriptor object (not just the old compatible format)
134 : :
135 : : // extract the any from the transferable
136 : 0 : DataFlavor aFlavor;
137 : : #if OSL_DEBUG_LEVEL > 0
138 : : sal_Bool bSuccess =
139 : : #endif
140 [ # # ][ # # ]: 0 : SotExchange::GetFormatDataFlavor(getDescriptorFormatId(bForm), aFlavor);
141 : : OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
142 : :
143 [ # # ]: 0 : Any aDescriptor = _rData.GetAny(aFlavor);
144 : :
145 : : // extract the property value sequence
146 [ # # ]: 0 : Sequence< PropertyValue > aDescriptorProps;
147 : : #if OSL_DEBUG_LEVEL > 0
148 : : bSuccess =
149 : : #endif
150 [ # # ]: 0 : aDescriptor >>= aDescriptorProps;
151 : : OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!");
152 : :
153 : : // build the real descriptor
154 [ # # ][ # # ]: 0 : return ODataAccessDescriptor(aDescriptorProps);
155 : : }
156 : :
157 : 0 : return ODataAccessDescriptor();
158 : : }
159 : :
160 : : //........................................................................
161 : : } // namespace svx
162 : : //........................................................................
163 : :
164 : :
165 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|