xref: /AOO41X/main/vcl/aqua/source/dtrans/DataFlavorMapping.cxx (revision 4fa933033e3d01935fc0e011d53e3c129b01c2a0)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "vcl/unohelp.hxx"
25cdf0e10cSrcweir #include <DataFlavorMapping.hxx>
26cdf0e10cSrcweir #include "HtmlFmtFlt.hxx"
27cdf0e10cSrcweir #include "PictToBmpFlt.hxx"
28cdf0e10cSrcweir #include "com/sun/star/datatransfer/UnsupportedFlavorException.hpp"
29cdf0e10cSrcweir #include "com/sun/star/datatransfer/XMimeContentType.hpp"
30cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
31cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <rtl/ustring.hxx>
34cdf0e10cSrcweir #include <rtl/memory.h>
35cdf0e10cSrcweir #include <osl/endian.h>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <vector>
38cdf0e10cSrcweir #include <stdio.h>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <premac.h>
41cdf0e10cSrcweir #include <Cocoa/Cocoa.h>
42cdf0e10cSrcweir #include <postmac.h>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer;
45cdf0e10cSrcweir using namespace rtl;
46cdf0e10cSrcweir using namespace ::com::sun::star::uno;
47cdf0e10cSrcweir using namespace com::sun::star::lang;
48cdf0e10cSrcweir using namespace cppu;
49cdf0e10cSrcweir using namespace std;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace // private
52cdf0e10cSrcweir {
53cdf0e10cSrcweir   const Type CPPUTYPE_SEQINT8  = getCppuType((Sequence<sal_Int8>*)0);
54cdf0e10cSrcweir   const Type CPPUTYPE_OUSTRING = getCppuType( (OUString*)0 );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir   /* Determine whether or not a DataFlavor is valid.
57cdf0e10cSrcweir    */
58cdf0e10cSrcweir   bool isValidFlavor(const DataFlavor& aFlavor)
59cdf0e10cSrcweir   {
60cdf0e10cSrcweir 	size_t len = aFlavor.MimeType.getLength();
61cdf0e10cSrcweir 	Type dtype = aFlavor.DataType;
62cdf0e10cSrcweir 	return ((len > 0) && ((dtype == CPPUTYPE_SEQINT8) || (dtype == CPPUTYPE_OUSTRING)));
63cdf0e10cSrcweir   }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir   typedef vector<sal_Unicode> UnicodeBuffer;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir   OUString NSStringToOUString(NSString* cfString)
68cdf0e10cSrcweir   {
69cdf0e10cSrcweir 	BOOST_ASSERT(cfString && "Invalid parameter");
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	const char* utf8Str = [cfString UTF8String];
72cdf0e10cSrcweir 	unsigned int len = rtl_str_getLength(utf8Str);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	return OUString(utf8Str, len, RTL_TEXTENCODING_UTF8);
75cdf0e10cSrcweir   }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir   NSString* OUStringToNSString(const OUString& ustring)
78cdf0e10cSrcweir   {
79cdf0e10cSrcweir 	OString utf8Str = OUStringToOString(ustring, RTL_TEXTENCODING_UTF8);
80cdf0e10cSrcweir 	return [NSString stringWithCString: utf8Str.getStr() encoding: NSUTF8StringEncoding];
81cdf0e10cSrcweir   }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir   const NSString* PBTYPE_UT16 = @"CorePasteboardFlavorType 0x75743136";
85cdf0e10cSrcweir   const NSString* PBTYPE_PICT = @"CorePasteboardFlavorType 0x50494354";
86cdf0e10cSrcweir   const NSString* PBTYPE_HTML = @"CorePasteboardFlavorType 0x48544D4C";
87cdf0e10cSrcweir   const NSString* PBTYPE_SODX = @"application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"";
88cdf0e10cSrcweir   const NSString* PBTYPE_SESX = @"application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
89cdf0e10cSrcweir   const NSString* PBTYPE_SLSDX = @"application/x-openoffice-linksrcdescriptor-xml;windows_formatname=\"Star Link Source Descriptor (XML)\"";
90cdf0e10cSrcweir   const NSString* PBTYPE_ESX = @"application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
91cdf0e10cSrcweir   const NSString* PBTYPE_LSX = @"application/x-openoffice-link-source-xml;windows_formatname=\"Star Link Source (XML)\"";
92cdf0e10cSrcweir   const NSString* PBTYPE_EOX = @"application/x-openoffice-embedded-obj-xml;windows_formatname=\"Star Embedded Object (XML)\"";
93cdf0e10cSrcweir   const NSString* PBTYPE_SVXB = @"application/x-openoffice-svbx;windows_formatname=\"SVXB (StarView Bitmap/Animation)\"";
94cdf0e10cSrcweir   const NSString* PBTYPE_GDIMF = @"application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"";
95cdf0e10cSrcweir   const NSString* PBTYPE_WMF = @"application/x-openoffice-wmf;windows_formatname=\"Image WMF\"";
96cdf0e10cSrcweir   const NSString* PBTYPE_EMF = @"application/x-openoffice-emf;windows_formatname=\"Image EMF\"";
97cdf0e10cSrcweir 
98cdf0e10cSrcweir   const NSString* PBTYPE_DUMMY_INTERNAL = @"application/x-openoffice-internal";
99cdf0e10cSrcweir 
100cdf0e10cSrcweir   const char* FLAVOR_SODX = "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"";
101cdf0e10cSrcweir   const char* FLAVOR_SESX = "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
102cdf0e10cSrcweir   const char* FLAVOR_SLSDX = "application/x-openoffice-linksrcdescriptor-xml;windows_formatname=\"Star Link Source Descriptor (XML)\"";
103cdf0e10cSrcweir   const char* FLAVOR_ESX = "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
104cdf0e10cSrcweir   const char* FLAVOR_LSX = "application/x-openoffice-link-source-xml;windows_formatname=\"Star Link Source (XML)\"";
105cdf0e10cSrcweir   const char* FLAVOR_EOX = "application/x-openoffice-embedded-obj-xml;windows_formatname=\"Star Embedded Object (XML)\"";
106cdf0e10cSrcweir   const char* FLAVOR_SVXB = "application/x-openoffice-svbx;windows_formatname=\"SVXB (StarView Bitmap/Animation)\"";
107cdf0e10cSrcweir   const char* FLAVOR_GDIMF = "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"";
108cdf0e10cSrcweir   const char* FLAVOR_WMF = "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"";
109cdf0e10cSrcweir   const char* FLAVOR_EMF = "application/x-openoffice-emf;windows_formatname=\"Image EMF\"";
110cdf0e10cSrcweir 
111cdf0e10cSrcweir   const char* FLAVOR_DUMMY_INTERNAL = "application/x-openoffice-internal";
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 
114cdf0e10cSrcweir   struct FlavorMap
115cdf0e10cSrcweir   {
116cdf0e10cSrcweir 	NSString* SystemFlavor;
117cdf0e10cSrcweir 	const char* OOoFlavor;
118cdf0e10cSrcweir 	const char* HumanPresentableName;
119cdf0e10cSrcweir 	Type DataType;
120cdf0e10cSrcweir   };
121cdf0e10cSrcweir 
122cdf0e10cSrcweir   /* At the moment it appears as if only MS Office pastes "public.html" to the clipboard.
123cdf0e10cSrcweir    */
124cdf0e10cSrcweir   FlavorMap flavorMap[] =
125cdf0e10cSrcweir 	{
126cdf0e10cSrcweir 	  { NSStringPboardType, "text/plain;charset=utf-16", "Unicode Text (UTF-16)", CPPUTYPE_OUSTRING },
127cdf0e10cSrcweir 	  { NSRTFPboardType, "text/richtext", "Rich Text Format", CPPUTYPE_SEQINT8 },
128cdf0e10cSrcweir 	  { NSTIFFPboardType, "image/bmp", "Windows Bitmap", CPPUTYPE_SEQINT8 },
129cdf0e10cSrcweir 	  { NSPICTPboardType, "image/bmp", "Windows Bitmap", CPPUTYPE_SEQINT8 },
130cdf0e10cSrcweir 	  { NSHTMLPboardType, "text/html", "Plain Html", CPPUTYPE_SEQINT8 },
131cdf0e10cSrcweir 	  { NSFilenamesPboardType, "application/x-openoffice-filelist;windows_formatname=\"FileList\"", "FileList", CPPUTYPE_SEQINT8 },
132cdf0e10cSrcweir 	  { PBTYPE_SESX, FLAVOR_SESX, "Star Embed Source (XML)", CPPUTYPE_SEQINT8 },
133cdf0e10cSrcweir 	  { PBTYPE_SLSDX, FLAVOR_SLSDX, "Star Link Source Descriptor (XML)", CPPUTYPE_SEQINT8 },
134cdf0e10cSrcweir 	  { PBTYPE_ESX, FLAVOR_ESX, "Star Embed Source (XML)", CPPUTYPE_SEQINT8 },
135cdf0e10cSrcweir 	  { PBTYPE_LSX, FLAVOR_LSX, "Star Link Source (XML)", CPPUTYPE_SEQINT8 },
136cdf0e10cSrcweir 	  { PBTYPE_EOX, FLAVOR_EOX, "Star Embedded Object (XML)", CPPUTYPE_SEQINT8 },
137cdf0e10cSrcweir 	  { PBTYPE_SVXB, FLAVOR_SVXB, "SVXB (StarView Bitmap/Animation", CPPUTYPE_SEQINT8 },
138cdf0e10cSrcweir 	  { PBTYPE_GDIMF, FLAVOR_GDIMF, "GDIMetaFile", CPPUTYPE_SEQINT8 },
139cdf0e10cSrcweir 	  { PBTYPE_WMF, FLAVOR_WMF, "Windows MetaFile", CPPUTYPE_SEQINT8 },
140cdf0e10cSrcweir 	  { PBTYPE_EMF, FLAVOR_EMF, "Windows Enhanced MetaFile", CPPUTYPE_SEQINT8 },
141cdf0e10cSrcweir 	  { PBTYPE_SODX, FLAVOR_SODX, "Star Object Descriptor (XML)", CPPUTYPE_SEQINT8 },
142cdf0e10cSrcweir       { PBTYPE_DUMMY_INTERNAL, FLAVOR_DUMMY_INTERNAL, "internal data",CPPUTYPE_SEQINT8 }
143cdf0e10cSrcweir 	};
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
146cdf0e10cSrcweir   #define SIZE_FLAVOR_MAP (sizeof(flavorMap)/sizeof(FlavorMap))
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 
149cdf0e10cSrcweir   inline bool isByteSequenceType(const Type& theType)
150cdf0e10cSrcweir   {
151cdf0e10cSrcweir 	return (theType == CPPUTYPE_SEQINT8);
152cdf0e10cSrcweir   }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir   inline bool isOUStringType(const Type& theType)
155cdf0e10cSrcweir   {
156cdf0e10cSrcweir 	return (theType == CPPUTYPE_OUSTRING);
157cdf0e10cSrcweir   }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir } // namespace private
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //###########################
163cdf0e10cSrcweir 
164cdf0e10cSrcweir /* A base class for other data provider.
165cdf0e10cSrcweir  */
166cdf0e10cSrcweir class DataProviderBaseImpl : public DataProvider
167cdf0e10cSrcweir {
168cdf0e10cSrcweir public:
169cdf0e10cSrcweir   DataProviderBaseImpl(const Any& data);
170cdf0e10cSrcweir   DataProviderBaseImpl(id data);
171cdf0e10cSrcweir   virtual ~DataProviderBaseImpl();
172cdf0e10cSrcweir 
173cdf0e10cSrcweir protected:
174cdf0e10cSrcweir   Any mData;
175cdf0e10cSrcweir   //NSData* mSystemData;
176cdf0e10cSrcweir   id mSystemData;
177cdf0e10cSrcweir };
178cdf0e10cSrcweir 
179cdf0e10cSrcweir DataProviderBaseImpl::DataProviderBaseImpl(const Any& data) :
180cdf0e10cSrcweir   mData(data),
181cdf0e10cSrcweir   mSystemData(nil)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir DataProviderBaseImpl::DataProviderBaseImpl(id data) :
186cdf0e10cSrcweir   mSystemData(data)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir   [mSystemData retain];
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 
192cdf0e10cSrcweir DataProviderBaseImpl::~DataProviderBaseImpl()
193cdf0e10cSrcweir {
194cdf0e10cSrcweir   if (mSystemData)
195cdf0e10cSrcweir 	{
196cdf0e10cSrcweir 	  [mSystemData release];
197cdf0e10cSrcweir 	}
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir //#################################
201cdf0e10cSrcweir 
202cdf0e10cSrcweir class UniDataProvider : public DataProviderBaseImpl
203cdf0e10cSrcweir {
204cdf0e10cSrcweir public:
205cdf0e10cSrcweir   UniDataProvider(const Any& data);
206cdf0e10cSrcweir 
207cdf0e10cSrcweir   UniDataProvider(NSData* data);
208cdf0e10cSrcweir 
209cdf0e10cSrcweir   virtual NSData* getSystemData();
210cdf0e10cSrcweir 
211cdf0e10cSrcweir   virtual Any getOOoData();
212cdf0e10cSrcweir };
213cdf0e10cSrcweir 
214cdf0e10cSrcweir UniDataProvider::UniDataProvider(const Any& data) :
215cdf0e10cSrcweir   DataProviderBaseImpl(data)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir UniDataProvider::UniDataProvider(NSData* data) :
220cdf0e10cSrcweir   DataProviderBaseImpl(data)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir NSData* UniDataProvider::getSystemData()
225cdf0e10cSrcweir {
226cdf0e10cSrcweir   OUString ustr;
227cdf0e10cSrcweir   mData >>= ustr;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir   OString strUtf8;
230cdf0e10cSrcweir   ustr.convertToString(&strUtf8, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS);
231cdf0e10cSrcweir 
232cdf0e10cSrcweir   return [NSData dataWithBytes: strUtf8.getStr() length: strUtf8.getLength()];
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir Any UniDataProvider::getOOoData()
236cdf0e10cSrcweir {
237cdf0e10cSrcweir   Any oOOData;
238cdf0e10cSrcweir 
239cdf0e10cSrcweir   if (mSystemData)
240cdf0e10cSrcweir 	{
241cdf0e10cSrcweir 	  oOOData = makeAny(OUString(reinterpret_cast<const sal_Char*>([mSystemData bytes]),
242cdf0e10cSrcweir 								 [mSystemData length],
243cdf0e10cSrcweir 								 RTL_TEXTENCODING_UTF8));
244cdf0e10cSrcweir 	}
245cdf0e10cSrcweir   else
246cdf0e10cSrcweir 	{
247cdf0e10cSrcweir 	  oOOData = mData;
248cdf0e10cSrcweir 	}
249cdf0e10cSrcweir 
250cdf0e10cSrcweir   return oOOData;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir //###########################
254cdf0e10cSrcweir 
255cdf0e10cSrcweir class ByteSequenceDataProvider : public DataProviderBaseImpl
256cdf0e10cSrcweir {
257cdf0e10cSrcweir public:
258cdf0e10cSrcweir   ByteSequenceDataProvider(const Any& data);
259cdf0e10cSrcweir 
260cdf0e10cSrcweir   ByteSequenceDataProvider(NSData* data);
261cdf0e10cSrcweir 
262cdf0e10cSrcweir   virtual NSData* getSystemData();
263cdf0e10cSrcweir 
264cdf0e10cSrcweir   virtual Any getOOoData();
265cdf0e10cSrcweir };
266cdf0e10cSrcweir 
267cdf0e10cSrcweir ByteSequenceDataProvider::ByteSequenceDataProvider(const Any& data) :
268cdf0e10cSrcweir   DataProviderBaseImpl(data)
269cdf0e10cSrcweir {
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir ByteSequenceDataProvider::ByteSequenceDataProvider(NSData* data) :
273cdf0e10cSrcweir   DataProviderBaseImpl(data)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 
278cdf0e10cSrcweir NSData* ByteSequenceDataProvider::getSystemData()
279cdf0e10cSrcweir {
280cdf0e10cSrcweir    Sequence<sal_Int8> rawData;
281cdf0e10cSrcweir    mData >>= rawData;
282cdf0e10cSrcweir 
283cdf0e10cSrcweir    return [NSData dataWithBytes: rawData.getArray()	length: rawData.getLength()];
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir Any ByteSequenceDataProvider::getOOoData()
287cdf0e10cSrcweir {
288cdf0e10cSrcweir   Any oOOData;
289cdf0e10cSrcweir 
290cdf0e10cSrcweir   if (mSystemData)
291cdf0e10cSrcweir 	{
292cdf0e10cSrcweir 	  unsigned int flavorDataLength = [mSystemData length];
293cdf0e10cSrcweir 	  Sequence<sal_Int8> byteSequence;
294cdf0e10cSrcweir 	  byteSequence.realloc(flavorDataLength);
295cdf0e10cSrcweir 	  memcpy(byteSequence.getArray(), [mSystemData bytes], flavorDataLength);
296cdf0e10cSrcweir 	  oOOData = makeAny(byteSequence);
297cdf0e10cSrcweir 	}
298cdf0e10cSrcweir   else
299cdf0e10cSrcweir 	{
300cdf0e10cSrcweir 	  oOOData =  mData;
301cdf0e10cSrcweir 	}
302cdf0e10cSrcweir 
303cdf0e10cSrcweir   return oOOData;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 
307cdf0e10cSrcweir //###########################
308cdf0e10cSrcweir 
309cdf0e10cSrcweir class HTMLFormatDataProvider : public DataProviderBaseImpl
310cdf0e10cSrcweir {
311cdf0e10cSrcweir public:
312cdf0e10cSrcweir   HTMLFormatDataProvider(const Any& data);
313cdf0e10cSrcweir 
314cdf0e10cSrcweir   HTMLFormatDataProvider(NSData* data);
315cdf0e10cSrcweir 
316cdf0e10cSrcweir   virtual NSData* getSystemData();
317cdf0e10cSrcweir 
318cdf0e10cSrcweir   virtual Any getOOoData();
319cdf0e10cSrcweir };
320cdf0e10cSrcweir 
321cdf0e10cSrcweir HTMLFormatDataProvider::HTMLFormatDataProvider(const Any& data) :
322cdf0e10cSrcweir   DataProviderBaseImpl(data)
323cdf0e10cSrcweir {
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir HTMLFormatDataProvider::HTMLFormatDataProvider(NSData* data) :
327cdf0e10cSrcweir   DataProviderBaseImpl(data)
328cdf0e10cSrcweir {
329cdf0e10cSrcweir }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir NSData* HTMLFormatDataProvider::getSystemData()
332cdf0e10cSrcweir {
333cdf0e10cSrcweir   Sequence<sal_Int8> textHtmlData;
334cdf0e10cSrcweir   mData >>= textHtmlData;
335cdf0e10cSrcweir 
336cdf0e10cSrcweir   Sequence<sal_Int8> htmlFormatData = TextHtmlToHTMLFormat(textHtmlData);
337cdf0e10cSrcweir 
338cdf0e10cSrcweir   return [NSData dataWithBytes: htmlFormatData.getArray() length: htmlFormatData.getLength()];
339cdf0e10cSrcweir }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir Any HTMLFormatDataProvider::getOOoData()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir   Any oOOData;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir   if (mSystemData)
346cdf0e10cSrcweir 	{
347cdf0e10cSrcweir 	  unsigned int flavorDataLength = [mSystemData length];
348cdf0e10cSrcweir 	  Sequence<sal_Int8> unkHtmlData;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 	  unkHtmlData.realloc(flavorDataLength);
351cdf0e10cSrcweir 	  memcpy(unkHtmlData.getArray(), [mSystemData bytes], flavorDataLength);
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 	  Sequence<sal_Int8>* pPlainHtml = &unkHtmlData;
354cdf0e10cSrcweir 	  Sequence<sal_Int8> plainHtml;
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	  if (isHTMLFormat(unkHtmlData))
357cdf0e10cSrcweir 		{
358cdf0e10cSrcweir 		  plainHtml = HTMLFormatToTextHtml(unkHtmlData);
359cdf0e10cSrcweir 		  pPlainHtml = &plainHtml;
360cdf0e10cSrcweir 		}
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 	  oOOData = makeAny(*pPlainHtml);
363cdf0e10cSrcweir 	}
364cdf0e10cSrcweir   else
365cdf0e10cSrcweir 	{
366cdf0e10cSrcweir 	  oOOData = mData;
367cdf0e10cSrcweir 	}
368cdf0e10cSrcweir 
369cdf0e10cSrcweir   return oOOData;
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir //###########################
373cdf0e10cSrcweir 
374cdf0e10cSrcweir class BMPDataProvider : public DataProviderBaseImpl
375cdf0e10cSrcweir {
376cdf0e10cSrcweir     NSBitmapImageFileType meImageType;
377cdf0e10cSrcweir public:
378cdf0e10cSrcweir   BMPDataProvider(const Any& data, NSBitmapImageFileType eImageType );
379cdf0e10cSrcweir 
380cdf0e10cSrcweir   BMPDataProvider(NSData* data, NSBitmapImageFileType eImageType);
381cdf0e10cSrcweir 
382cdf0e10cSrcweir   virtual NSData* getSystemData();
383cdf0e10cSrcweir 
384cdf0e10cSrcweir   virtual Any getOOoData();
385cdf0e10cSrcweir };
386cdf0e10cSrcweir 
387cdf0e10cSrcweir BMPDataProvider::BMPDataProvider(const Any& data, NSBitmapImageFileType eImageType) :
388cdf0e10cSrcweir   DataProviderBaseImpl(data),
389cdf0e10cSrcweir   meImageType( eImageType )
390cdf0e10cSrcweir {
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir BMPDataProvider::BMPDataProvider(NSData* data, NSBitmapImageFileType eImageType) :
394cdf0e10cSrcweir   DataProviderBaseImpl(data),
395cdf0e10cSrcweir   meImageType( eImageType )
396cdf0e10cSrcweir {
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir NSData* BMPDataProvider::getSystemData()
400cdf0e10cSrcweir {
401cdf0e10cSrcweir   Sequence<sal_Int8> bmpData;
402cdf0e10cSrcweir   mData >>= bmpData;
403cdf0e10cSrcweir 
404cdf0e10cSrcweir   Sequence<sal_Int8> pictData;
405cdf0e10cSrcweir   NSData* sysData = NULL;
406cdf0e10cSrcweir 
407cdf0e10cSrcweir   if (BMPToImage(bmpData, pictData, meImageType))
408cdf0e10cSrcweir 	{
409cdf0e10cSrcweir 	  sysData = [NSData dataWithBytes: pictData.getArray() length: pictData.getLength()];
410cdf0e10cSrcweir 	}
411cdf0e10cSrcweir 
412cdf0e10cSrcweir   return sysData;
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir /* At the moment the OOo 'PCT' filter is not good enough to be used
416cdf0e10cSrcweir    and there is no flavor defined for exchanging 'PCT' with OOo so
417cdf0e10cSrcweir    we will at the moment convert 'PCT' to a Windows BMP and provide
418cdf0e10cSrcweir    this to OOo
419cdf0e10cSrcweir */
420cdf0e10cSrcweir Any BMPDataProvider::getOOoData()
421cdf0e10cSrcweir {
422cdf0e10cSrcweir   Any oOOData;
423cdf0e10cSrcweir 
424cdf0e10cSrcweir   if (mSystemData)
425cdf0e10cSrcweir 	{
426cdf0e10cSrcweir 	  unsigned int flavorDataLength = [mSystemData length];
427cdf0e10cSrcweir 	  Sequence<sal_Int8> pictData(flavorDataLength);
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 	  memcpy(pictData.getArray(), [mSystemData bytes], flavorDataLength);
430cdf0e10cSrcweir 
431cdf0e10cSrcweir 	  Sequence<sal_Int8> bmpData;
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 	  if (ImageToBMP(pictData, bmpData, meImageType))
434cdf0e10cSrcweir 		{
435cdf0e10cSrcweir 		  oOOData = makeAny(bmpData);
436cdf0e10cSrcweir 		}
437cdf0e10cSrcweir 	}
438cdf0e10cSrcweir   else
439cdf0e10cSrcweir 	{
440cdf0e10cSrcweir 	  oOOData = mData;
441cdf0e10cSrcweir 	}
442cdf0e10cSrcweir 
443cdf0e10cSrcweir   return oOOData;
444cdf0e10cSrcweir }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir //######################
447cdf0e10cSrcweir 
448cdf0e10cSrcweir class FileListDataProvider : public DataProviderBaseImpl
449cdf0e10cSrcweir {
450cdf0e10cSrcweir public:
451cdf0e10cSrcweir   FileListDataProvider(const Any& data);
452cdf0e10cSrcweir   FileListDataProvider(NSArray* data);
453cdf0e10cSrcweir 
454cdf0e10cSrcweir   virtual NSData* getSystemData();
455cdf0e10cSrcweir   virtual Any getOOoData();
456cdf0e10cSrcweir };
457cdf0e10cSrcweir 
458cdf0e10cSrcweir FileListDataProvider::FileListDataProvider(const Any& data) :
459cdf0e10cSrcweir   DataProviderBaseImpl(data)
460cdf0e10cSrcweir {
461cdf0e10cSrcweir }
462cdf0e10cSrcweir 
463cdf0e10cSrcweir FileListDataProvider::FileListDataProvider(NSArray* data) :
464cdf0e10cSrcweir   DataProviderBaseImpl(data)
465cdf0e10cSrcweir {
466cdf0e10cSrcweir }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir NSData* FileListDataProvider::getSystemData()
469cdf0e10cSrcweir {
470cdf0e10cSrcweir   return [NSData data];
471cdf0e10cSrcweir }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir Any FileListDataProvider::getOOoData()
474cdf0e10cSrcweir {
475cdf0e10cSrcweir   Any oOOData;
476cdf0e10cSrcweir 
477cdf0e10cSrcweir   if (mSystemData)
478cdf0e10cSrcweir 	{
479cdf0e10cSrcweir 	  size_t length = [mSystemData count];
480cdf0e10cSrcweir 	  size_t lenSeqRequired = 0;
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 	  for (size_t i = 0; i < length; i++)
483cdf0e10cSrcweir 		{
484cdf0e10cSrcweir 		  NSString* fname = [mSystemData objectAtIndex: i];
485cdf0e10cSrcweir 		  lenSeqRequired += [fname maximumLengthOfBytesUsingEncoding: NSUnicodeStringEncoding] + sizeof(unichar);
486cdf0e10cSrcweir 		}
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 	  Sequence<sal_Int8> oOOFileList(lenSeqRequired);
489cdf0e10cSrcweir 	  unichar* pBuffer = reinterpret_cast<unichar*>(oOOFileList.getArray());
490cdf0e10cSrcweir 	  rtl_zeroMemory(pBuffer, lenSeqRequired);
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 	  for (size_t i = 0; i < length; i++)
493cdf0e10cSrcweir 		{
494cdf0e10cSrcweir 		  NSString* fname = [mSystemData objectAtIndex: i];
495cdf0e10cSrcweir 		  [fname getCharacters: pBuffer];
496cdf0e10cSrcweir 		  size_t l = [fname length];
497cdf0e10cSrcweir 		  pBuffer += l + 1;
498cdf0e10cSrcweir 		}
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 	  oOOData = makeAny(oOOFileList);
501cdf0e10cSrcweir 	}
502cdf0e10cSrcweir   else
503cdf0e10cSrcweir 	{
504cdf0e10cSrcweir 	  oOOData = mData;
505cdf0e10cSrcweir 	}
506cdf0e10cSrcweir 
507cdf0e10cSrcweir   return oOOData;
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir //###########################
511cdf0e10cSrcweir 
512cdf0e10cSrcweir DataFlavorMapper::DataFlavorMapper()
513cdf0e10cSrcweir {
514cdf0e10cSrcweir     Reference<XMultiServiceFactory> mrServiceManager = vcl::unohelper::GetMultiServiceFactory();
515cdf0e10cSrcweir     mrXMimeCntFactory = Reference<XMimeContentTypeFactory>(mrServiceManager->createInstance(
516cdf0e10cSrcweir 	   OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.datatransfer.MimeContentTypeFactory"))), UNO_QUERY);
517cdf0e10cSrcweir 
518cdf0e10cSrcweir   if (!mrXMimeCntFactory.is())
519cdf0e10cSrcweir 	throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("AquaClipboard: Cannot create com.sun.star.datatransfer.MimeContentTypeFactory")), NULL);
520cdf0e10cSrcweir }
521cdf0e10cSrcweir 
5229950dfd1SHerbert Dürr DataFlavorMapper::~DataFlavorMapper()
5239950dfd1SHerbert Dürr {
5249950dfd1SHerbert Dürr     // release potential NSStrings
5259950dfd1SHerbert Dürr     for( OfficeOnlyTypes::iterator it = maOfficeOnlyTypes.begin(); it != maOfficeOnlyTypes.end(); ++it )
5269950dfd1SHerbert Dürr     {
5279950dfd1SHerbert Dürr         [it->second release];
5289950dfd1SHerbert Dürr         it->second = nil;
5299950dfd1SHerbert Dürr     }
5309950dfd1SHerbert Dürr }
5319950dfd1SHerbert Dürr 
532cdf0e10cSrcweir DataFlavor DataFlavorMapper::systemToOpenOfficeFlavor(NSString* systemDataFlavor) const
533cdf0e10cSrcweir {
534cdf0e10cSrcweir   DataFlavor oOOFlavor;
535cdf0e10cSrcweir 
536cdf0e10cSrcweir   for (size_t i = 0; i < SIZE_FLAVOR_MAP; i++)
537cdf0e10cSrcweir 	{
538cdf0e10cSrcweir 	  if ([systemDataFlavor caseInsensitiveCompare: flavorMap[i].SystemFlavor] == NSOrderedSame)
539cdf0e10cSrcweir 		{
540cdf0e10cSrcweir 		  oOOFlavor.MimeType = OUString::createFromAscii( flavorMap[i].OOoFlavor);
541c63ba1e9SHerbert Dürr 		  oOOFlavor.HumanPresentableName = OUString::createFromAscii( flavorMap[i].HumanPresentableName);
542cdf0e10cSrcweir 		  oOOFlavor.DataType = flavorMap[i].DataType;
543cdf0e10cSrcweir 		  return oOOFlavor;
544cdf0e10cSrcweir 		}
545cdf0e10cSrcweir 	} // for
546cdf0e10cSrcweir 
5479950dfd1SHerbert Dürr 	// look if this might be an internal type; if it comes in here it must have
5489950dfd1SHerbert Dürr 	// been through openOfficeToSystemFlavor before, so it should then be in the map
5499950dfd1SHerbert Dürr 	rtl::OUString aTryFlavor( NSStringToOUString( systemDataFlavor ) );
5509950dfd1SHerbert Dürr 	if( maOfficeOnlyTypes.find( aTryFlavor ) != maOfficeOnlyTypes.end() )
5519950dfd1SHerbert Dürr 	{
5529950dfd1SHerbert Dürr 	    oOOFlavor.MimeType = aTryFlavor;
5539950dfd1SHerbert Dürr 	    oOOFlavor.HumanPresentableName = rtl::OUString();
5549950dfd1SHerbert Dürr 	    oOOFlavor.DataType = CPPUTYPE_SEQINT8;
5559950dfd1SHerbert Dürr 	}
5569950dfd1SHerbert Dürr 
557cdf0e10cSrcweir 	return oOOFlavor;
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir NSString* DataFlavorMapper::openOfficeToSystemFlavor(const DataFlavor& oOOFlavor) const
561cdf0e10cSrcweir {
562cdf0e10cSrcweir     NSString* sysFlavor = NULL;
563cdf0e10cSrcweir 
5649950dfd1SHerbert Dürr 	for( size_t i = 0; i < SIZE_FLAVOR_MAP; ++i )
565cdf0e10cSrcweir 	{
566cdf0e10cSrcweir 	    if (oOOFlavor.MimeType.compareToAscii(flavorMap[i].OOoFlavor, strlen(flavorMap[i].OOoFlavor)) == 0)
567cdf0e10cSrcweir 		{
568cdf0e10cSrcweir 		    sysFlavor = flavorMap[i].SystemFlavor;
569cdf0e10cSrcweir 		}
570cdf0e10cSrcweir 	}
571cdf0e10cSrcweir 
572*4fa93303SAndre Fischer         return sysFlavor;
573*4fa93303SAndre Fischer }
574*4fa93303SAndre Fischer 
575*4fa93303SAndre Fischer NSString* DataFlavorMapper::internalOpenOfficeToSystemFlavor(const DataFlavor& oOOFlavor) const
5769950dfd1SHerbert Dürr {
577*4fa93303SAndre Fischer     NSString* sysFlavor = NULL;
5789950dfd1SHerbert Dürr     OfficeOnlyTypes::const_iterator it = maOfficeOnlyTypes.find( oOOFlavor.MimeType );
5799950dfd1SHerbert Dürr     if( it == maOfficeOnlyTypes.end() )
5809950dfd1SHerbert Dürr         sysFlavor = maOfficeOnlyTypes[ oOOFlavor.MimeType ] = OUStringToNSString( oOOFlavor.MimeType );
5819950dfd1SHerbert Dürr     else
5829950dfd1SHerbert Dürr         sysFlavor = it->second;
5839950dfd1SHerbert Dürr 
584cdf0e10cSrcweir     return sysFlavor;
585cdf0e10cSrcweir }
586cdf0e10cSrcweir 
587cdf0e10cSrcweir NSString* DataFlavorMapper::openOfficeImageToSystemFlavor(NSPasteboard* pPasteboard) const
588cdf0e10cSrcweir {
589cdf0e10cSrcweir     NSArray *supportedTypes = [NSArray arrayWithObjects: NSTIFFPboardType, NSPICTPboardType, nil];
590cdf0e10cSrcweir     NSString *sysFlavor = [pPasteboard availableTypeFromArray:supportedTypes];
591cdf0e10cSrcweir     return sysFlavor;
592cdf0e10cSrcweir }
593cdf0e10cSrcweir 
594cdf0e10cSrcweir DataProviderPtr_t DataFlavorMapper::getDataProvider(NSString* systemFlavor, Reference<XTransferable> rTransferable) const
595cdf0e10cSrcweir {
596cdf0e10cSrcweir   DataProviderPtr_t dp;
597cdf0e10cSrcweir 
598cdf0e10cSrcweir   try
599cdf0e10cSrcweir 	{
600cdf0e10cSrcweir 	  DataFlavor oOOFlavor = systemToOpenOfficeFlavor(systemFlavor);
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 	  Any data = rTransferable->getTransferData(oOOFlavor);
603cdf0e10cSrcweir 
604cdf0e10cSrcweir 	  if (isByteSequenceType(data.getValueType()))
605cdf0e10cSrcweir 		{
606cdf0e10cSrcweir 		  /*
607cdf0e10cSrcweir 		     the HTMLFormatDataProvider prepends segment information to HTML
608cdf0e10cSrcweir 		     this is useful for exchange with MS Word (which brings this stuff from Windows)
609cdf0e10cSrcweir 		     but annoying for other applications. Since this extension is not a standard datatype
610cdf0e10cSrcweir 		     on the Mac, let us not provide but provide normal HTML
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 		  if ([systemFlavor caseInsensitiveCompare: NSHTMLPboardType] == NSOrderedSame)
613cdf0e10cSrcweir 			{
614cdf0e10cSrcweir 			  dp = DataProviderPtr_t(new HTMLFormatDataProvider(data));
615cdf0e10cSrcweir 			}
616cdf0e10cSrcweir 		  else
617cdf0e10cSrcweir 		  */
618cdf0e10cSrcweir 		  if ([systemFlavor caseInsensitiveCompare: NSPICTPboardType] == NSOrderedSame)
619cdf0e10cSrcweir 			{
620cdf0e10cSrcweir 			  dp = DataProviderPtr_t(new BMPDataProvider(data, PICTImageFileType));
621cdf0e10cSrcweir 			}
622cdf0e10cSrcweir 		  else if ([systemFlavor caseInsensitiveCompare: NSTIFFPboardType] == NSOrderedSame)
623cdf0e10cSrcweir 			{
624cdf0e10cSrcweir 			  dp = DataProviderPtr_t(new BMPDataProvider(data, NSTIFFFileType));
625cdf0e10cSrcweir 			}
626cdf0e10cSrcweir 		  else if ([systemFlavor caseInsensitiveCompare: NSFilenamesPboardType] == NSOrderedSame)
627cdf0e10cSrcweir 			{
628cdf0e10cSrcweir 			  dp = DataProviderPtr_t(new FileListDataProvider(data));
629cdf0e10cSrcweir 			}
630cdf0e10cSrcweir 		  else
631cdf0e10cSrcweir 			{
632cdf0e10cSrcweir 			  dp = DataProviderPtr_t(new ByteSequenceDataProvider(data));
633cdf0e10cSrcweir 			}
634cdf0e10cSrcweir 		}
635cdf0e10cSrcweir 	  else // Must be OUString type
636cdf0e10cSrcweir 		{
637cdf0e10cSrcweir 		  BOOST_ASSERT(isOUStringType(data.getValueType()));
638cdf0e10cSrcweir 		  dp = DataProviderPtr_t(new UniDataProvider(data));
639cdf0e10cSrcweir 		}
640cdf0e10cSrcweir 	}
641cdf0e10cSrcweir   catch(UnsupportedFlavorException&)
642cdf0e10cSrcweir 	{
643cdf0e10cSrcweir 	  // Somebody violates the contract of the clipboard
644cdf0e10cSrcweir 	  // interface @see XTransferable
645cdf0e10cSrcweir 	}
646cdf0e10cSrcweir 
647cdf0e10cSrcweir   return dp;
648cdf0e10cSrcweir }
649cdf0e10cSrcweir 
650cdf0e10cSrcweir DataProviderPtr_t DataFlavorMapper::getDataProvider(const NSString* /*systemFlavor*/, NSArray* systemData) const
651cdf0e10cSrcweir {
652cdf0e10cSrcweir   return DataProviderPtr_t(new FileListDataProvider(systemData));
653cdf0e10cSrcweir }
654cdf0e10cSrcweir 
655cdf0e10cSrcweir DataProviderPtr_t DataFlavorMapper::getDataProvider(const NSString* systemFlavor, NSData* systemData) const
656cdf0e10cSrcweir {
657cdf0e10cSrcweir   DataProviderPtr_t dp;
658cdf0e10cSrcweir 
659cdf0e10cSrcweir   if ([systemFlavor caseInsensitiveCompare: NSStringPboardType] == NSOrderedSame)
660cdf0e10cSrcweir 	{
661cdf0e10cSrcweir 	  dp = DataProviderPtr_t(new UniDataProvider(systemData));
662cdf0e10cSrcweir 	}
663cdf0e10cSrcweir   else if ([systemFlavor caseInsensitiveCompare: NSHTMLPboardType] == NSOrderedSame)
664cdf0e10cSrcweir 	{
665cdf0e10cSrcweir 	  dp = DataProviderPtr_t(new HTMLFormatDataProvider(systemData));
666cdf0e10cSrcweir 	}
667cdf0e10cSrcweir   else if ([systemFlavor caseInsensitiveCompare: NSPICTPboardType] == NSOrderedSame)
668cdf0e10cSrcweir 	{
669cdf0e10cSrcweir 	  dp = DataProviderPtr_t(new BMPDataProvider(systemData, PICTImageFileType));
670cdf0e10cSrcweir 	}
671cdf0e10cSrcweir   else if ([systemFlavor caseInsensitiveCompare: NSTIFFPboardType] == NSOrderedSame)
672cdf0e10cSrcweir 	{
673cdf0e10cSrcweir 	  dp = DataProviderPtr_t(new BMPDataProvider(systemData, NSTIFFFileType));
674cdf0e10cSrcweir 	}
675cdf0e10cSrcweir   else if ([systemFlavor caseInsensitiveCompare: NSFilenamesPboardType] == NSOrderedSame)
676cdf0e10cSrcweir 	{
677cdf0e10cSrcweir 	  //dp = DataProviderPtr_t(new FileListDataProvider(systemData));
678cdf0e10cSrcweir 	}
679cdf0e10cSrcweir   else
680cdf0e10cSrcweir 	{
681cdf0e10cSrcweir 	  dp = DataProviderPtr_t(new ByteSequenceDataProvider(systemData));
682cdf0e10cSrcweir 	}
683cdf0e10cSrcweir 
684cdf0e10cSrcweir   return dp;
685cdf0e10cSrcweir }
686cdf0e10cSrcweir 
687cdf0e10cSrcweir bool DataFlavorMapper::isValidMimeContentType(const rtl::OUString& contentType) const
688cdf0e10cSrcweir {
689cdf0e10cSrcweir   bool result = true;
690cdf0e10cSrcweir 
691cdf0e10cSrcweir   try
692cdf0e10cSrcweir 	{
693cdf0e10cSrcweir 	  Reference<XMimeContentType> xCntType(mrXMimeCntFactory->createMimeContentType(contentType));
694cdf0e10cSrcweir 	}
695cdf0e10cSrcweir   catch( IllegalArgumentException& )
696cdf0e10cSrcweir 	{
697cdf0e10cSrcweir 	  result = false;
698cdf0e10cSrcweir 	}
699cdf0e10cSrcweir 
700cdf0e10cSrcweir   return result;
701cdf0e10cSrcweir }
702cdf0e10cSrcweir 
703cdf0e10cSrcweir NSArray* DataFlavorMapper::flavorSequenceToTypesArray(const com::sun::star::uno::Sequence<com::sun::star::datatransfer::DataFlavor>& flavors) const
704cdf0e10cSrcweir {
705cdf0e10cSrcweir   sal_uInt32 nFlavors = flavors.getLength();
706cdf0e10cSrcweir   NSMutableArray* array = [[NSMutableArray alloc] initWithCapacity: 1];
707cdf0e10cSrcweir 
708*4fa93303SAndre Fischer   bool bNeedDummyInternalFlavor (true);
709*4fa93303SAndre Fischer 
710cdf0e10cSrcweir   for (sal_uInt32 i = 0; i < nFlavors; i++)
711cdf0e10cSrcweir   {
712cdf0e10cSrcweir       if( flavors[i].MimeType.compareToAscii( "image/bmp", 9 ) == 0 )
713cdf0e10cSrcweir       {
714cdf0e10cSrcweir           [array addObject: NSTIFFPboardType];
715cdf0e10cSrcweir           [array addObject: NSPICTPboardType];
716cdf0e10cSrcweir       }
717cdf0e10cSrcweir       else
718cdf0e10cSrcweir       {
719cdf0e10cSrcweir           NSString* str = openOfficeToSystemFlavor(flavors[i]);
720*4fa93303SAndre Fischer           if (str == NULL)
721*4fa93303SAndre Fischer               str = internalOpenOfficeToSystemFlavor(flavors[i]);
722*4fa93303SAndre Fischer           else
723*4fa93303SAndre Fischer               bNeedDummyInternalFlavor = false;
724cdf0e10cSrcweir 
725cdf0e10cSrcweir           if (str != NULL)
726cdf0e10cSrcweir           {
7279950dfd1SHerbert Dürr               [str retain];
728cdf0e10cSrcweir               [array addObject: str];
729cdf0e10cSrcweir           }
730cdf0e10cSrcweir       }
731cdf0e10cSrcweir   }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir    // #i89462# #i90747#
734cdf0e10cSrcweir    // in case no system flavor was found to report
735cdf0e10cSrcweir    // report at least one so D&D between OOo targets works
736*4fa93303SAndre Fischer   if( [array count] == 0 || bNeedDummyInternalFlavor)
737cdf0e10cSrcweir   {
738cdf0e10cSrcweir       [array addObject: PBTYPE_DUMMY_INTERNAL];
739cdf0e10cSrcweir   }
740cdf0e10cSrcweir 
741cdf0e10cSrcweir   return [array autorelease];
742cdf0e10cSrcweir }
743cdf0e10cSrcweir 
744cdf0e10cSrcweir com::sun::star::uno::Sequence<com::sun::star::datatransfer::DataFlavor> DataFlavorMapper::typesArrayToFlavorSequence(NSArray* types) const
745cdf0e10cSrcweir {
746cdf0e10cSrcweir   int nFormats = [types count];
747cdf0e10cSrcweir   Sequence<DataFlavor> flavors;
748cdf0e10cSrcweir 
749cdf0e10cSrcweir   for (int i = 0; i < nFormats; i++)
750cdf0e10cSrcweir 	{
751cdf0e10cSrcweir 	  NSString* sysFormat = [types objectAtIndex: i];
752cdf0e10cSrcweir 	  DataFlavor oOOFlavor = systemToOpenOfficeFlavor(sysFormat);
753cdf0e10cSrcweir 
754cdf0e10cSrcweir 	  if (isValidFlavor(oOOFlavor))
755cdf0e10cSrcweir 		{
756cdf0e10cSrcweir 		  flavors.realloc(flavors.getLength() + 1);
757cdf0e10cSrcweir 		  flavors[flavors.getLength() - 1] = oOOFlavor;
758cdf0e10cSrcweir 		}
759cdf0e10cSrcweir 	}
760cdf0e10cSrcweir 
761cdf0e10cSrcweir   return flavors;
762cdf0e10cSrcweir }
763cdf0e10cSrcweir 
764cdf0e10cSrcweir 
765cdf0e10cSrcweir NSArray* DataFlavorMapper::getAllSupportedPboardTypes() const
766cdf0e10cSrcweir {
767cdf0e10cSrcweir   NSMutableArray* array = [[NSMutableArray alloc] initWithCapacity: SIZE_FLAVOR_MAP];
768cdf0e10cSrcweir 
769cdf0e10cSrcweir   for (sal_uInt32 i = 0; i < SIZE_FLAVOR_MAP; i++)
770cdf0e10cSrcweir 	{
771cdf0e10cSrcweir 	  [array addObject: flavorMap[i].SystemFlavor];
772cdf0e10cSrcweir 	}
773cdf0e10cSrcweir 
774cdf0e10cSrcweir   return [array autorelease];
775cdf0e10cSrcweir }
776