Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
29 :
30 : //........................................................................
31 : namespace svx
32 : {
33 : //........................................................................
34 :
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;
45 :
46 : //====================================================================
47 : //= OComponentTransferable
48 : //====================================================================
49 : //--------------------------------------------------------------------
50 0 : OComponentTransferable::OComponentTransferable(const ::rtl::OUString& _rDatasourceOrLocation
51 0 : ,const Reference< XContent>& _xContent)
52 : {
53 0 : m_aDescriptor.setDataSource(_rDatasourceOrLocation);
54 0 : m_aDescriptor[daComponent] <<= _xContent;
55 0 : }
56 :
57 :
58 : //--------------------------------------------------------------------
59 0 : sal_uInt32 OComponentTransferable::getDescriptorFormatId(sal_Bool _bExtractForm)
60 : {
61 : static sal_uInt32 s_nReportFormat = (sal_uInt32)-1;
62 : static sal_uInt32 s_nFormFormat = (sal_uInt32)-1;
63 0 : if ( _bExtractForm && (sal_uInt32)-1 == s_nFormFormat )
64 : {
65 0 : s_nFormFormat = SotExchange::RegisterFormatName(rtl::OUString("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"" ));
66 0 : OSL_ENSURE((sal_uInt32)-1 != s_nFormFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
67 : }
68 0 : else if ( !_bExtractForm && (sal_uInt32)-1 == s_nReportFormat)
69 : {
70 0 : s_nReportFormat = SotExchange::RegisterFormatName(rtl::OUString("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\""));
71 : OSL_ENSURE((sal_uInt32)-1 != s_nReportFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
72 : }
73 0 : return _bExtractForm ? s_nFormFormat : s_nReportFormat;
74 : }
75 :
76 : //--------------------------------------------------------------------
77 0 : void OComponentTransferable::AddSupportedFormats()
78 : {
79 0 : sal_Bool bForm = sal_True;
80 : try
81 : {
82 0 : Reference<XPropertySet> xProp;
83 0 : m_aDescriptor[daComponent] >>= xProp;
84 0 : if ( xProp.is() )
85 0 : xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm"))) >>= bForm;
86 : }
87 0 : catch(Exception)
88 0 : {}
89 0 : AddFormat(getDescriptorFormatId(bForm));
90 0 : }
91 :
92 : //--------------------------------------------------------------------
93 0 : sal_Bool OComponentTransferable::GetData( const DataFlavor& _rFlavor )
94 : {
95 0 : const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
96 0 : if ( nFormatId == getDescriptorFormatId(sal_True) || nFormatId == getDescriptorFormatId(sal_False) )
97 0 : return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor );
98 :
99 0 : return sal_False;
100 : }
101 :
102 : //--------------------------------------------------------------------
103 0 : sal_Bool OComponentTransferable::canExtractComponentDescriptor(const DataFlavorExVector& _rFlavors,sal_Bool _bForm )
104 : {
105 0 : DataFlavorExVector::const_iterator aEnd = _rFlavors.end();
106 0 : for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
107 : aCheck != aEnd;
108 : ++aCheck
109 : )
110 : {
111 0 : if ( getDescriptorFormatId(_bForm) == aCheck->mnSotId )
112 0 : return sal_True;
113 : }
114 :
115 0 : return sal_False;
116 : }
117 :
118 : //--------------------------------------------------------------------
119 0 : ODataAccessDescriptor OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData)
120 : {
121 0 : sal_Bool bForm = _rData.HasFormat(getDescriptorFormatId(sal_True));
122 0 : if ( bForm || _rData.HasFormat(getDescriptorFormatId(sal_False)) )
123 : {
124 : // the object has a real descriptor object (not just the old compatible format)
125 :
126 : // extract the any from the transferable
127 0 : DataFlavor aFlavor;
128 : #if OSL_DEBUG_LEVEL > 0
129 : sal_Bool bSuccess =
130 : #endif
131 0 : SotExchange::GetFormatDataFlavor(getDescriptorFormatId(bForm), aFlavor);
132 : OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
133 :
134 0 : Any aDescriptor = _rData.GetAny(aFlavor);
135 :
136 : // extract the property value sequence
137 0 : Sequence< PropertyValue > aDescriptorProps;
138 : #if OSL_DEBUG_LEVEL > 0
139 : bSuccess =
140 : #endif
141 0 : aDescriptor >>= aDescriptorProps;
142 : OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!");
143 :
144 : // build the real descriptor
145 0 : return ODataAccessDescriptor(aDescriptorProps);
146 : }
147 :
148 0 : return ODataAccessDescriptor();
149 : }
150 :
151 : //........................................................................
152 : } // namespace svx
153 : //........................................................................
154 :
155 :
156 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|