LibreOffice Module svx (master)  1
dbaobjectex.cxx
Go to the documentation of this file.
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 <com/sun/star/ucb/XContent.hpp>
25 #include <fmprop.hxx>
26 #include <sot/formats.hxx>
27 #include <sot/exchange.hxx>
28 
29 
30 namespace svx
31 {
32 
33 
34  using namespace ::com::sun::star::uno;
35  using namespace ::com::sun::star::beans;
36  using namespace ::com::sun::star::sdb;
37  using namespace ::com::sun::star::lang;
38  using namespace ::com::sun::star::ucb;
39  using namespace ::com::sun::star::sdbcx;
40  using namespace ::com::sun::star::container;
41  using namespace ::com::sun::star::datatransfer;
42 
43  OComponentTransferable::OComponentTransferable(const OUString& _rDatasourceOrLocation
44  ,const Reference< XContent>& _xContent)
45  {
46  m_aDescriptor.setDataSource(_rDatasourceOrLocation);
48  }
49 
50 
52  {
53  static SotClipboardFormatId s_nReportFormat = static_cast<SotClipboardFormatId>(-1);
54  static SotClipboardFormatId s_nFormFormat = static_cast<SotClipboardFormatId>(-1);
55  if ( _bExtractForm && static_cast<SotClipboardFormatId>(-1) == s_nFormFormat )
56  {
57  s_nFormFormat = SotExchange::RegisterFormatName("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"");
58  OSL_ENSURE(static_cast<SotClipboardFormatId>(-1) != s_nFormFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
59  }
60  else if ( !_bExtractForm && static_cast<SotClipboardFormatId>(-1) == s_nReportFormat)
61  {
62  s_nReportFormat = SotExchange::RegisterFormatName("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\"");
63  OSL_ENSURE(static_cast<SotClipboardFormatId>(-1) != s_nReportFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
64  }
65  return _bExtractForm ? s_nFormFormat : s_nReportFormat;
66  }
67 
68 
70  {
71  bool bForm = true;
72  try
73  {
74  Reference<XPropertySet> xProp;
76  if ( xProp.is() )
77  xProp->getPropertyValue("IsForm") >>= bForm;
78  }
79  catch(const Exception&)
80  {}
82  }
83 
84 
85  bool OComponentTransferable::GetData( const DataFlavor& _rFlavor, const OUString& /*rDestDoc*/ )
86  {
87  const SotClipboardFormatId nFormatId = SotExchange::GetFormat(_rFlavor);
88  if ( nFormatId == getDescriptorFormatId(true) || nFormatId == getDescriptorFormatId(false) )
90 
91  return false;
92  }
93 
94 
96  {
97  SotClipboardFormatId nFormatId = getDescriptorFormatId(_bForm);
98  return std::any_of(_rFlavors.begin(), _rFlavors.end(),
99  [&nFormatId](const DataFlavorEx& rCheck) { return nFormatId == rCheck.mnSotId; });
100  }
101 
102 
104  {
105  bool bForm = _rData.HasFormat(getDescriptorFormatId(true));
106  if ( bForm || _rData.HasFormat(getDescriptorFormatId(false)) )
107  {
108  // the object has a real descriptor object (not just the old compatible format)
109 
110  // extract the any from the transferable
111  DataFlavor aFlavor;
112  bool bSuccess =
114  OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
115 
116  Any aDescriptor = _rData.GetAny(aFlavor, OUString());
117 
118  // extract the property value sequence
119  Sequence< PropertyValue > aDescriptorProps;
120  bSuccess = aDescriptor >>= aDescriptorProps;
121  OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!");
122 
123  // build the real descriptor
124  return ODataAccessDescriptor(aDescriptorProps);
125  }
126 
127  return ODataAccessDescriptor();
128  }
129 
130 
131 }
132 
133 
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SotClipboardFormatId RegisterFormatName(const OUString &rName)
css::uno::Any GetAny(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
void setDataSource(const OUString &_sDataSourceNameOrLocation)
set the data source name, if it is not file URL
::std::vector< DataFlavorEx > DataFlavorExVector
css::uno::Sequence< css::beans::PropertyValue > const & createPropertyValueSequence()
returns the descriptor as property value sequence
bool HasFormat(SotClipboardFormatId nFormat) const
void AddFormat(SotClipboardFormatId nFormat)
ODataAccessDescriptor m_aDescriptor
Definition: dbaobjectex.hxx:64
SotClipboardFormatId
selection are bookmarks? (boolean)
static bool canExtractComponentDescriptor(const DataFlavorExVector &_rFlavors, bool _bForm)
checks whether or not a component descriptor can be extracted from the data flavor vector given ...
Definition: dbaobjectex.cxx:95
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
Definition: dbaobjectex.cxx:85
static SotClipboardFormatId getDescriptorFormatId(bool _bExtractForm)
Definition: dbaobjectex.cxx:51
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
class encapsulating the css::sdb::DataAccessDescriptor service.
OComponentTransferable(const OUString &_rDatasourceOrLocation, const css::uno::Reference< css::ucb::XContent > &_xContent)
construct the transferable
Definition: dbaobjectex.cxx:43
virtual void AddSupportedFormats() override
Definition: dbaobjectex.cxx:69
bool SetAny(const css::uno::Any &rAny)
static ODataAccessDescriptor extractComponentDescriptor(const TransferableDataHelper &_rData)
extracts a component descriptor from the transferable given
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)