1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_DATAFLAVORMAPPING_HXX_
29 #define INCLUDED_DATAFLAVORMAPPING_HXX_
30 
31 #include <com/sun/star/datatransfer/DataFlavor.hpp>
32 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
33 #include <com/sun/star/datatransfer/XTransferable.hpp>
34 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
35 
36 #include <premac.h>
37 #import <Cocoa/Cocoa.h>
38 #include <postmac.h>
39 
40 #include <memory>
41 #include <boost/shared_ptr.hpp>
42 
43 
44 /* An interface to get the clipboard data in either
45    system or OOo format.
46  */
47 class DataProvider
48 {
49 public:
50   virtual ~DataProvider() {};
51 
52   /* Get the clipboard data in the system format.
53 	 The caller has to retain/release the returned
54 	 CFDataRef on demand.
55    */
56   virtual NSData* getSystemData() = 0;
57 
58   /* Get the clipboard data in OOo format.
59    */
60   virtual com::sun::star::uno::Any getOOoData() = 0;
61 };
62 
63 typedef std::auto_ptr<DataProvider> DataProviderPtr_t;
64 
65 
66 //################################
67 
68 
69 class DataFlavorMapper
70 {
71 public:
72   /* Initialialize a DataFavorMapper instance. Throws a RuntimeException in case the XMimeContentTypeFactory service
73 	 cannot be created.
74    */
75   DataFlavorMapper();
76 
77 
78   /* Map a system data flavor to an OpenOffice data flavor.
79 	 Return an empty string if there is not suiteable
80 	 mapping from a system data flavor to a OpenOffice data
81 	 flavor.
82   */
83   com::sun::star::datatransfer::DataFlavor systemToOpenOfficeFlavor(NSString* systemDataFlavor) const;
84 
85 
86   /* Map an OpenOffice data flavor to a system data flavor.
87 	 If there is no suiteable mapping available NULL will
88 	 be returned.
89   */
90   NSString* openOfficeToSystemFlavor(const com::sun::star::datatransfer::DataFlavor& oooDataFlavor) const;
91 
92   /* Select the best available image data type
93 	 If there is no suiteable mapping available NULL will
94 	 be returned.
95   */
96   NSString* openOfficeImageToSystemFlavor(NSPasteboard* pPasteboard) const;
97 
98   /* Get a data provider which is able to provide the data 'rTransferable' offers in a format that can
99 	 be put on to the system clipboard.
100    */
101   DataProviderPtr_t getDataProvider(NSString* systemFlavor,
102 									const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable > rTransferable) const;
103 
104 
105 
106   /* Get a data provider which is able to provide 'systemData' in the OOo expected format.
107    */
108   DataProviderPtr_t getDataProvider(const NSString* systemFlavor, NSArray* systemData) const;
109 
110 
111   /* Get a data provider which is able to provide 'systemData' in the OOo expected format.
112    */
113   DataProviderPtr_t getDataProvider(const NSString* systemFlavor, NSData* systemData) const;
114 
115 
116   /* Translate a sequence of DataFlavors into a NSArray of system types.
117 	 Only those DataFlavors for which a suitable mapping to a system
118 	 type exist will be contained in the returned types array.
119    */
120   NSArray* flavorSequenceToTypesArray(const com::sun::star::uno::Sequence<com::sun::star::datatransfer::DataFlavor>& flavors) const;
121 
122   /* Translate a NSArray of system types into a sequence of DataFlavors.
123 	 Only those types for which a suitable mapping to a DataFlavor
124 	 exist will be contained in the new DataFlavor Sequence.
125   */
126   com::sun::star::uno::Sequence<com::sun::star::datatransfer::DataFlavor> typesArrayToFlavorSequence(NSArray* types) const;
127 
128   /* Returns an NSArray containing all pasteboard types supported by OOo
129    */
130   NSArray* DataFlavorMapper::getAllSupportedPboardTypes() const;
131 
132 private:
133   /* Determines if the provided Mime content type is valid.
134    */
135   bool isValidMimeContentType(const rtl::OUString& contentType) const;
136 
137 private:
138   ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XMimeContentTypeFactory> mrXMimeCntFactory;
139 };
140 
141 typedef boost::shared_ptr<DataFlavorMapper> DataFlavorMapperPtr_t;
142 
143 #endif
144