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 #ifndef INCLUDED_SVX_DBAEXCHANGE_HXX 21 #define INCLUDED_SVX_DBAEXCHANGE_HXX 22 23 #include <sal/config.h> 24 25 #include <o3tl/typed_flags_set.hxx> 26 #include <vcl/transfer.hxx> 27 #include <com/sun/star/beans/PropertyValue.hpp> 28 #include <svx/dataaccessdescriptor.hxx> 29 #include <com/sun/star/uno/Sequence.hxx> 30 #include <svx/svxdllapi.h> 31 32 namespace com::sun::star::sdbc { class XConnection; } 33 namespace com::sun::star::beans { class XPropertySet; } 34 35 // column transfer formats 36 enum class ColumnTransferFormatFlags 37 { 38 FIELD_DESCRIPTOR = 0x01, // the field descriptor format 39 CONTROL_EXCHANGE = 0x02, // the control exchange format 40 COLUMN_DESCRIPTOR = 0x04, // data access descriptor for a column 41 }; 42 namespace o3tl 43 { 44 template<> struct typed_flags<ColumnTransferFormatFlags> : is_typed_flags<ColumnTransferFormatFlags, 0x07> {}; 45 } 46 47 48 namespace svx 49 { 50 51 52 //= OColumnTransferable 53 54 class SAL_WARN_UNUSED SVX_DLLPUBLIC OColumnTransferable final : public TransferableHelper 55 { 56 public: 57 /** construct the transferable from a data access descriptor 58 59 Note that some of the aspects, in particular all which cannot be represented 60 as string, can only be transported via the CTF_COLUMN_DESCRIPTOR format. 61 62 @param _rDescriptor 63 The descriptor for the column. It must contain at least 64 <ul><li>information sufficient to create a connection, that is, either one of DataSource, DatabaseLocation, 65 ConnectionResource, and DataAccessDescriptorProperty::Connection</li> 66 <li>a Command</li> 67 <li>a CommandType</li> 68 <li>a ColumnName or ColumnObject</li> 69 </ul> 70 */ 71 OColumnTransferable( 72 const ODataAccessDescriptor& _rDescriptor, 73 ColumnTransferFormatFlags _nFormats 74 ); 75 76 /** construct the transferable from a DatabaseForm component and a field name 77 78 @param _rxForm 79 the form which is bound to the data source which's field is to be dragged 80 81 @param _rFieldName 82 the name of the field to be dragged 83 84 @param _rxColumn 85 the column object. Won't be used if <arg>_nFormats</arg> does not include the CTF_COLUMN_DESCRIPTOR 86 flag.<br/> 87 May be <NULL/>. 88 89 @param _rxConnection 90 the connection the column belongs to. Won't be used if <arg>_nFormats</arg> does not include the CTF_COLUMN_DESCRIPTOR 91 flag.<br/> 92 May be <NULL/>. 93 94 @param _nFormats 95 supported formats. Must be a combination of the CTF_XXX flags 96 */ 97 OColumnTransferable( 98 const css::uno::Reference< css::beans::XPropertySet >& _rxForm, 99 const OUString& _rFieldName, 100 const css::uno::Reference< css::beans::XPropertySet >& _rxColumn, 101 const css::uno::Reference< css::sdbc::XConnection >& _rxConnection, 102 ColumnTransferFormatFlags _nFormats 103 ); 104 105 /** checks whether or not a column descriptor can be extracted from the data flavor vector given 106 @param _rFlavors 107 available flavors 108 @param _nFormats 109 formats to accept 110 */ 111 static bool canExtractColumnDescriptor(const DataFlavorExVector& _rFlavors, ColumnTransferFormatFlags _nFormats); 112 113 /** extracts a column descriptor from the transferable given 114 */ 115 static bool extractColumnDescriptor( 116 const TransferableDataHelper& _rData 117 ,OUString& _rDatasource 118 ,OUString& _rDatabaseLocation 119 ,OUString& _rConnectionResource 120 ,sal_Int32& _nCommandType 121 ,OUString& _rCommand 122 ,OUString& _rFieldName 123 ); 124 125 /** extracts a column descriptor from the transferable given 126 */ 127 static ODataAccessDescriptor 128 extractColumnDescriptor(const TransferableDataHelper& _rData); 129 130 private: 131 // TransferableHelper overridables 132 virtual void AddSupportedFormats() override; 133 virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override; 134 135 static SotClipboardFormatId getDescriptorFormatId(); 136 137 SVX_DLLPRIVATE void implConstruct( 138 const OUString& _rDatasource 139 ,const OUString& _rConnectionResource 140 ,const sal_Int32 _nCommandType 141 ,const OUString& _rCommand 142 ,const OUString& _rFieldName 143 ); 144 145 ODataAccessDescriptor m_aDescriptor; 146 OUString m_sCompatibleFormat; 147 ColumnTransferFormatFlags const m_nFormatFlags; 148 }; 149 150 151 //= ODataAccessObjectTransferable 152 153 /** class for transferring data access objects (tables, queries, statements ...) 154 */ 155 class SAL_WARN_UNUSED SVX_DLLPUBLIC ODataAccessObjectTransferable : public TransferableHelper 156 { 157 ODataAccessDescriptor m_aDescriptor; 158 OUString m_sCompatibleObjectDescription; 159 // needed to provide a SotClipboardFormatId::SBA_DATAEXCHANGE format 160 161 public: 162 /** should be used copying and the connection is needed. 163 @param _rDatasource 164 The data source name. 165 @param _nCommandType 166 The kind of command. @see com.sun.star.sdbc.CommandType 167 @param _rCommand 168 The command, either a name of a table or query or a SQL statement. 169 */ 170 ODataAccessObjectTransferable( 171 const OUString& _rDatasourceOrLocation 172 ,const sal_Int32 _nCommandType 173 ,const OUString& _rCommand 174 ,const css::uno::Reference< css::sdbc::XConnection >& _rxConnection 175 ); 176 177 /** should be used when copying a query object and no connection is available. 178 @param _rDatasource 179 The data source name. 180 @param _nCommandType 181 The kind of command. @see com.sun.star.sdbc.CommandType 182 @param _rCommand 183 The command, either a name of a table or query or a SQL statement. 184 */ 185 ODataAccessObjectTransferable( 186 const OUString& _rDatasourceOrLocation 187 ,const sal_Int32 _nCommandType 188 ,const OUString& _rCommand 189 ); 190 191 /** with this ctor, only the object descriptor format will be provided 192 */ 193 ODataAccessObjectTransferable( 194 const css::uno::Reference< css::beans::XPropertySet >& _rxLivingForm 195 ); 196 197 /** checks whether or not an object descriptor can be extracted from the data flavor vector given 198 @param _rFlavors 199 available flavors 200 @param _nFormats 201 formats to accept 202 */ 203 static bool canExtractObjectDescriptor(const DataFlavorExVector& _rFlavors); 204 205 /** extracts an object descriptor from the transferable given 206 */ 207 static ODataAccessDescriptor 208 extractObjectDescriptor(const TransferableDataHelper& _rData); 209 210 protected: 211 virtual void AddSupportedFormats() override; 212 virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override; 213 virtual void ObjectReleased() override; 214 215 protected: getDescriptor() const216 const ODataAccessDescriptor& getDescriptor() const { return m_aDescriptor; } getDescriptor()217 ODataAccessDescriptor& getDescriptor() { return m_aDescriptor; } 218 protected: 219 void addCompatibleSelectionDescription( 220 const css::uno::Sequence< css::uno::Any >& _rSelRows 221 ); 222 // normally, a derived class could simply access getDescriptor[DataAccessDescriptorProperty::Selection] and place the sequence therein 223 // but unfortunately, we have this damned compatible format, and this can't be accessed in 224 // derived classes (our class is the only one which should be contaminated with this) 225 226 private: 227 SVX_DLLPRIVATE void construct( const OUString& _rDatasourceOrLocation 228 ,const OUString& _rConnectionResource 229 ,const sal_Int32 _nCommandType 230 ,const OUString& _rCommand 231 ,const css::uno::Reference< css::sdbc::XConnection >& _rxConnection 232 ,bool _bAddCommand 233 ,const OUString& _sActiveCommand); 234 }; 235 236 237 //= OMultiColumnTransferable 238 239 /** class for transferring multiple columns 240 */ 241 class SAL_WARN_UNUSED SVX_DLLPUBLIC OMultiColumnTransferable final : public TransferableHelper 242 { 243 public: 244 OMultiColumnTransferable(const css::uno::Sequence< css::beans::PropertyValue >& _aDescriptors); 245 246 /** checks whether or not an object descriptor can be extracted from the data flavor vector given 247 @param _rFlavors 248 available flavors 249 @param _nFormats 250 formats to accept 251 */ 252 static bool canExtractDescriptor(const DataFlavorExVector& _rFlavors); 253 254 /** extracts an object descriptor from the transferable given 255 */ 256 static css::uno::Sequence< css::beans::PropertyValue > extractDescriptor(const TransferableDataHelper& _rData); 257 258 private: 259 virtual void AddSupportedFormats() override; 260 virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override; 261 virtual void ObjectReleased() override; 262 static SotClipboardFormatId getDescriptorFormatId(); 263 264 css::uno::Sequence< css::beans::PropertyValue > m_aDescriptors; 265 }; 266 267 268 } 269 270 271 #endif // INCLUDED_SVX_DBAEXCHANGE_HXX 272 273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 274