sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / vcl / osx / DataFlavorMapping.hxx
blob1d4d4219d37a4c481ae3ee1b95d0669b7de5a73f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <com/sun/star/datatransfer/DataFlavor.hpp>
23 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
24 #include <com/sun/star/datatransfer/XTransferable.hpp>
25 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
27 #include <premac.h>
28 #import <Cocoa/Cocoa.h>
29 #include <postmac.h>
31 #include <memory>
32 #include <unordered_map>
34 /* An interface to get the clipboard data in either
35 system or OOo format.
37 class DataProvider
39 public:
40 virtual ~DataProvider() {};
42 /* Get the clipboard data in the system format.
43 The caller has to retain/release the returned
44 CFDataRef on demand.
46 virtual NSData* getSystemData() = 0;
48 /* Get the clipboard data in OOo format.
50 virtual css::uno::Any getOOoData() = 0;
53 typedef std::unique_ptr<DataProvider> DataProviderPtr_t;
55 class DataFlavorMapper
57 public:
58 /* Initialize a DataFavorMapper instance. Throws a RuntimeException in case the XMimeContentTypeFactory service
59 cannot be created.
61 DataFlavorMapper();
62 ~DataFlavorMapper();
64 /* Map a system data flavor to an OpenOffice data flavor.
65 Return an empty string if there is not suitable
66 mapping from a system data flavor to an LibreOffice data
67 flavor.
69 css::datatransfer::DataFlavor systemToOpenOfficeFlavor( const NSString* systemDataFlavor) const;
71 /* Map an OpenOffice data flavor to a system data flavor.
72 If there is no suitable mapping available NULL will
73 be returned.
75 const NSString* openOfficeToSystemFlavor(const css::datatransfer::DataFlavor& oooDataFlavor, bool& rbInternal, bool bIsSystemClipboard = false) const;
77 /* Select the best available image data type
78 If there is no suitable mapping available NULL will
79 be returned.
81 static NSString* openOfficeImageToSystemFlavor(NSPasteboard* pPasteboard);
83 /* Get a data provider which is able to provide the data 'rTransferable' offers in a format that can
84 be put on to the system clipboard.
86 DataProviderPtr_t getDataProvider( const NSString* systemFlavor,
87 const css::uno::Reference< css::datatransfer::XTransferable > & rTransferable) const;
89 /* Get a data provider which is able to provide 'systemData' in the OOo expected format.
91 static DataProviderPtr_t getDataProvider( const NSString* systemFlavor, NSArray* systemData);
93 /* Get a data provider which is able to provide 'systemData' in the OOo expected format.
95 static DataProviderPtr_t getDataProvider( const NSString* systemFlavor, NSData* systemData);
97 /* Translate a sequence of DataFlavors into an NSArray of system types.
98 Only those DataFlavors for which a suitable mapping to a system
99 type exist will be contained in the returned types array.
101 NSArray* flavorSequenceToTypesArray(const css::uno::Sequence<css::datatransfer::DataFlavor>& flavors, bool bIsSystemClipboard = false) const;
103 /* Translate an NSArray of system types into a sequence of DataFlavors.
104 Only those types for which a suitable mapping to a DataFlavor
105 exist will be contained in the new DataFlavor Sequence.
107 css::uno::Sequence<css::datatransfer::DataFlavor> typesArrayToFlavorSequence(NSArray* types) const;
109 /* Returns an NSArray containing all pasteboard types supported by OOo
111 static NSArray* getAllSupportedPboardTypes();
113 private:
114 /* Determines if the provided Mime content type is valid.
116 bool isValidMimeContentType(const OUString& contentType) const;
118 private:
119 css::uno::Reference< css::datatransfer::XMimeContentTypeFactory> mrXMimeCntFactory;
120 typedef std::unordered_map< OUString, NSString* > OfficeOnlyTypes;
121 mutable OfficeOnlyTypes maOfficeOnlyTypes;
124 typedef std::shared_ptr<DataFlavorMapper> DataFlavorMapperPtr_t;
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */