1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_OSX_DATAFLAVORMAPPING_HXX
21 #define INCLUDED_VCL_OSX_DATAFLAVORMAPPING_HXX
23 #include <com/sun/star/datatransfer/DataFlavor.hpp>
24 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
25 #include <com/sun/star/datatransfer/XTransferable.hpp>
26 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
29 #import <Cocoa/Cocoa.h>
33 #include <unordered_map>
34 #include <boost/shared_ptr.hpp>
36 /* An interface to get the clipboard data in either
42 virtual ~DataProvider() {};
44 /* Get the clipboard data in the system format.
45 The caller has to retain/release the returned
48 virtual NSData
* getSystemData() = 0;
50 /* Get the clipboard data in OOo format.
52 virtual com::sun::star::uno::Any
getOOoData() = 0;
55 typedef std::unique_ptr
<DataProvider
> DataProviderPtr_t
;
57 class DataFlavorMapper
60 /* Initialialize a DataFavorMapper instance. Throws a RuntimeException in case the XMimeContentTypeFactory service
66 /* Map a system data flavor to an OpenOffice data flavor.
67 Return an empty string if there is not suitable
68 mapping from a system data flavor to a OpenOffice data
71 com::sun::star::datatransfer::DataFlavor
systemToOpenOfficeFlavor( const NSString
* systemDataFlavor
) const;
73 /* Map an OpenOffice data flavor to a system data flavor.
74 If there is no suitable mapping available NULL will
77 const NSString
* openOfficeToSystemFlavor(const com::sun::star::datatransfer::DataFlavor
& oooDataFlavor
, bool& rbInternal
) const;
79 /* Select the best available image data type
80 If there is no suitable mapping available NULL will
83 static NSString
* openOfficeImageToSystemFlavor(NSPasteboard
* pPasteboard
);
85 /* Get a data provider which is able to provide the data 'rTransferable' offers in a format that can
86 be put on to the system clipboard.
88 DataProviderPtr_t
getDataProvider( const NSString
* systemFlavor
,
89 const com::sun::star::uno::Reference
< com::sun::star::datatransfer::XTransferable
> rTransferable
) const;
91 /* Get a data provider which is able to provide 'systemData' in the OOo expected format.
93 static DataProviderPtr_t
getDataProvider( const NSString
* systemFlavor
, NSArray
* systemData
);
95 /* Get a data provider which is able to provide 'systemData' in the OOo expected format.
97 static DataProviderPtr_t
getDataProvider( const NSString
* systemFlavor
, NSData
* systemData
);
99 /* Translate a sequence of DataFlavors into a NSArray of system types.
100 Only those DataFlavors for which a suitable mapping to a system
101 type exist will be contained in the returned types array.
103 NSArray
* flavorSequenceToTypesArray(const com::sun::star::uno::Sequence
<com::sun::star::datatransfer::DataFlavor
>& flavors
) const;
105 /* Translate a NSArray of system types into a sequence of DataFlavors.
106 Only those types for which a suitable mapping to a DataFlavor
107 exist will be contained in the new DataFlavor Sequence.
109 com::sun::star::uno::Sequence
<com::sun::star::datatransfer::DataFlavor
> typesArrayToFlavorSequence(NSArray
* types
) const;
111 /* Returns an NSArray containing all pasteboard types supported by OOo
113 static NSArray
* getAllSupportedPboardTypes();
116 /* Determines if the provided Mime content type is valid.
118 bool isValidMimeContentType(const OUString
& contentType
) const;
121 ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::XMimeContentTypeFactory
> mrXMimeCntFactory
;
122 typedef std::unordered_map
< OUString
, NSString
*, OUStringHash
> OfficeOnlyTypes
;
123 mutable OfficeOnlyTypes maOfficeOnlyTypes
;
126 typedef boost::shared_ptr
<DataFlavorMapper
> DataFlavorMapperPtr_t
;
128 #endif // INCLUDED_VCL_OSX_DATAFLAVORMAPPING_HXX
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */