tdf#151341 Use lzfse compression instead of bzip2
[LibreOffice.git] / vcl / osx / DataFlavorMapping.cxx
blob274a2b4a4be73348793e1288d59b44be6b47539e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include "DataFlavorMapping.hxx"
24 #include "HtmlFmtFlt.hxx"
25 #include "PictToBmpFlt.hxx"
26 #include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
27 #include <com/sun/star/datatransfer/XMimeContentType.hpp>
28 #include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp>
29 #include <com/sun/star/lang/IllegalArgumentException.hpp>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <comphelper/processfactory.hxx>
33 #include <rtl/ustring.hxx>
34 #include <osl/endian.h>
36 #include <cassert>
37 #include <string.h>
38 #include <string_view>
40 #include <premac.h>
41 #include <Cocoa/Cocoa.h>
42 #include <postmac.h>
44 using namespace ::com::sun::star::datatransfer;
45 using namespace ::com::sun::star::uno;
46 using namespace com::sun::star::lang;
47 using namespace cppu;
49 namespace
51 /* Determine whether or not a DataFlavor is valid.
53 bool isValidFlavor(const DataFlavor& aFlavor)
55 size_t len = aFlavor.MimeType.getLength();
56 Type dtype = aFlavor.DataType;
57 return ((len > 0) && ((dtype == cppu::UnoType<Sequence<sal_Int8>>::get()) || (dtype == cppu::UnoType<OUString>::get())));
60 OUString NSStringToOUString( const NSString* cfString)
62 assert(cfString && "Invalid parameter");
64 const char* utf8Str = [cfString UTF8String];
65 unsigned int len = rtl_str_getLength(utf8Str);
67 return OUString(utf8Str, len, RTL_TEXTENCODING_UTF8);
70 NSString* OUStringToNSString(std::u16string_view ustring)
72 OString utf8Str = OUStringToOString(ustring, RTL_TEXTENCODING_UTF8);
73 return [NSString stringWithCString: utf8Str.getStr() encoding: NSUTF8StringEncoding];
76 const char* FLAVOR_SESX = "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
77 const char* FLAVOR_SLSDX = "application/x-openoffice-linksrcdescriptor-xml;windows_formatname=\"Star Link Source Descriptor (XML)\"";
78 const char* FLAVOR_ESX = "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
79 const char* FLAVOR_LSX = "application/x-openoffice-link-source-xml;windows_formatname=\"Star Link Source (XML)\"";
80 const char* FLAVOR_EOX = "application/x-openoffice-embedded-obj-xml;windows_formatname=\"Star Embedded Object (XML)\"";
81 const char* FLAVOR_SVXB = "application/x-openoffice-svbx;windows_formatname=\"SVXB (StarView Bitmap/Animation)\"";
82 const char* FLAVOR_GDIMF = "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"";
83 const char* FLAVOR_WMF = "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"";
84 const char* FLAVOR_EMF = "application/x-openoffice-emf;windows_formatname=\"Image EMF\"";
85 const char* FLAVOR_SODX = "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"";
86 const char* FLAVOR_LINK = "application/x-openoffice-link;windows_formatname=\"Link\"";
87 const char* FLAVOR_DUMMY_INTERNAL = "application/x-openoffice-internal";
89 struct FlavorMap
91 const NSString* SystemFlavor;
92 const char* OOoFlavor;
93 const char* HumanPresentableName;
94 bool DataTypeOUString; // sequence<byte> otherwise
97 // This is a list of the bidirectional mapping between (internal) MIME types and (system)
98 // pasteboard types.
100 // Only pasteboard types mentioned here will be recognized, mapped, and available for pasting in a
101 // fresh LibreOffice process. When copy-pasting in-process, the situation is different.
103 // Also MIME types not mentioned here will be stored on the pasteboard (using the same type name),
104 // though. But that is IMHO a bit pointless as they in general won't then be pasteable anyway in a
105 // new LibreOffice process. See the use of the maOfficeOnlyTypes array.
107 // The SystemFlavor member is nil for the cases where there is no predefined pasteboard type UTI
108 // and we use the internal MIME type (media type) also on the pasteboard. That is OK in macOS,
109 // there is no requirement that the types are well-formed UTIs. It is different on iOS, I think,
110 // though. For an introduction to UTIs, see for instance
111 // https://alastairs-place.net/blog/2012/06/06/utis-are-better-than-you-think-and-heres-why/
113 // In those cases the MIME type might actually have parameters appended, separated by semicolons.
114 // At least the FLAVOR_SODX one must have at least a typename="%PRODUCTNAME %PRODUCTVERSION
115 // Spreadsheet" parameter (with macros expanded and translated) for LO to recognise it. See
116 // lcl_TestFormat() in sc/source/ui/view/cellsh.cxx.
118 const FlavorMap flavorMap[] =
120 { NSPasteboardTypeString, "text/plain;charset=utf-16", "Unicode Text (UTF-16)", true },
121 { NSPasteboardTypeRTF, "text/rtf", "Rich Text Format", false },
122 { NSPasteboardTypePDF, "application/pdf", "PDF File", false },
123 { NSPasteboardTypeTIFF, "image/png", "Portable Network Graphics", false },
124 { NSPasteboardTypeHTML, "text/html", "Plain Html", false },
125 SAL_WNODEPRECATED_DECLARATIONS_PUSH
126 // "'NSFilenamesPboardType' is deprecated: first deprecated in macOS 10.14 - Create
127 // multiple pasteboard items with NSPasteboardTypeFileURL or kUTTypeFileURL instead"
128 { NSFilenamesPboardType, "application/x-openoffice-filelist;windows_formatname=\"FileList\"", "FileList", false },
129 SAL_WNODEPRECATED_DECLARATIONS_POP
130 { nil, FLAVOR_SESX, "Star Embed Source (XML)", false },
131 { nil, FLAVOR_SLSDX, "Star Link Source Descriptor (XML)", false },
132 { nil, FLAVOR_ESX, "Star Embed Source (XML)", false },
133 { nil, FLAVOR_LSX, "Star Link Source (XML)", false },
134 { nil, FLAVOR_EOX, "Star Embedded Object (XML)", false },
135 { nil, FLAVOR_SVXB, "SVXB (StarView Bitmap/Animation", false },
136 { nil, FLAVOR_GDIMF, "GDIMetaFile", false },
137 { nil, FLAVOR_WMF, "Windows MetaFile", false },
138 { nil, FLAVOR_EMF, "Windows Enhanced MetaFile", false },
139 { nil, FLAVOR_SODX, "Star Object Descriptor (XML)", false },
140 { nil, FLAVOR_LINK, "Dynamic Data Exchange (DDE link)", false },
141 { nil, FLAVOR_DUMMY_INTERNAL, "internal data",false }
144 #define SIZE_FLAVOR_MAP (sizeof(flavorMap)/sizeof(FlavorMap))
146 bool isByteSequenceType(const Type& theType)
148 return (theType == cppu::UnoType<Sequence<sal_Int8>>::get());
151 bool isOUStringType(const Type& theType)
153 return (theType == cppu::UnoType<OUString>::get() );
156 /* A base class for other data provider.
158 class DataProviderBaseImpl : public DataProvider
160 public:
161 DataProviderBaseImpl(const Any& data);
162 DataProviderBaseImpl(id data);
163 virtual ~DataProviderBaseImpl() override;
165 protected:
166 Any mData;
167 //NSData* mSystemData;
168 id mSystemData;
171 } // unnamed namespace
173 DataProviderBaseImpl::DataProviderBaseImpl(const Any& data) :
174 mData(data),
175 mSystemData(nil)
179 DataProviderBaseImpl::DataProviderBaseImpl(id data) :
180 mSystemData(data)
182 [mSystemData retain];
185 DataProviderBaseImpl::~DataProviderBaseImpl()
187 if (mSystemData)
189 [mSystemData release];
193 namespace {
195 class UniDataProvider : public DataProviderBaseImpl
197 public:
198 UniDataProvider(const Any& data);
200 UniDataProvider(NSData* data);
202 virtual NSData* getSystemData() override;
204 virtual Any getOOoData() override;
209 UniDataProvider::UniDataProvider(const Any& data) :
210 DataProviderBaseImpl(data)
214 UniDataProvider::UniDataProvider(NSData* data) :
215 DataProviderBaseImpl(data)
219 NSData* UniDataProvider::getSystemData()
221 OUString ustr;
222 mData >>= ustr;
224 OString strUtf8;
225 ustr.convertToString(&strUtf8, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS);
227 return [NSData dataWithBytes: strUtf8.getStr() length: strUtf8.getLength()];
230 Any UniDataProvider::getOOoData()
232 Any oOOData;
234 if (mSystemData)
236 oOOData <<= OUString(static_cast<const char*>([mSystemData bytes]),
237 [mSystemData length],
238 RTL_TEXTENCODING_UTF8);
240 else
242 oOOData = mData;
245 return oOOData;
248 namespace {
250 class ByteSequenceDataProvider : public DataProviderBaseImpl
252 public:
253 ByteSequenceDataProvider(const Any& data);
255 ByteSequenceDataProvider(NSData* data);
257 virtual NSData* getSystemData() override;
259 virtual Any getOOoData() override;
264 ByteSequenceDataProvider::ByteSequenceDataProvider(const Any& data) :
265 DataProviderBaseImpl(data)
269 ByteSequenceDataProvider::ByteSequenceDataProvider(NSData* data) :
270 DataProviderBaseImpl(data)
274 NSData* ByteSequenceDataProvider::getSystemData()
276 Sequence<sal_Int8> rawData;
277 mData >>= rawData;
279 return [NSData dataWithBytes: rawData.getArray() length: rawData.getLength()];
282 Any ByteSequenceDataProvider::getOOoData()
284 Any oOOData;
286 if (mSystemData)
288 unsigned int flavorDataLength = [mSystemData length];
289 Sequence<sal_Int8> byteSequence;
290 byteSequence.realloc(flavorDataLength);
291 memcpy(byteSequence.getArray(), [mSystemData bytes], flavorDataLength);
292 oOOData <<= byteSequence;
294 else
296 oOOData = mData;
299 return oOOData;
302 namespace {
304 class HTMLFormatDataProvider : public DataProviderBaseImpl
306 public:
307 HTMLFormatDataProvider(NSData* data);
309 virtual NSData* getSystemData() override;
311 virtual Any getOOoData() override;
316 HTMLFormatDataProvider::HTMLFormatDataProvider(NSData* data) :
317 DataProviderBaseImpl(data)
321 NSData* HTMLFormatDataProvider::getSystemData()
323 Sequence<sal_Int8> textHtmlData;
324 mData >>= textHtmlData;
326 Sequence<sal_Int8> htmlFormatData = TextHtmlToHTMLFormat(textHtmlData);
328 return [NSData dataWithBytes: htmlFormatData.getArray() length: htmlFormatData.getLength()];
331 Any HTMLFormatDataProvider::getOOoData()
333 Any oOOData;
335 if (mSystemData)
337 unsigned int flavorDataLength = [mSystemData length];
338 Sequence<sal_Int8> unkHtmlData;
340 unkHtmlData.realloc(flavorDataLength);
341 memcpy(unkHtmlData.getArray(), [mSystemData bytes], flavorDataLength);
343 Sequence<sal_Int8>* pPlainHtml = &unkHtmlData;
344 Sequence<sal_Int8> plainHtml;
346 if (isHTMLFormat(unkHtmlData))
348 plainHtml = HTMLFormatToTextHtml(unkHtmlData);
349 pPlainHtml = &plainHtml;
352 oOOData <<= *pPlainHtml;
354 else
356 oOOData = mData;
359 return oOOData;
362 namespace {
365 class PNGDataProvider : public DataProviderBaseImpl
367 NSBitmapImageFileType meImageType;
368 public:
369 PNGDataProvider( const Any&, NSBitmapImageFileType);
371 PNGDataProvider( NSData*, NSBitmapImageFileType);
373 virtual NSData* getSystemData() override;
375 virtual Any getOOoData() override;
380 PNGDataProvider::PNGDataProvider( const Any& data, NSBitmapImageFileType eImageType) :
381 DataProviderBaseImpl(data),
382 meImageType( eImageType )
386 PNGDataProvider::PNGDataProvider( NSData* data, NSBitmapImageFileType eImageType) :
387 DataProviderBaseImpl(data),
388 meImageType( eImageType )
392 NSData* PNGDataProvider::getSystemData()
394 Sequence<sal_Int8> pngData;
395 mData >>= pngData;
397 Sequence<sal_Int8> imgData;
398 NSData* sysData = nullptr;
399 if( PNGToImage( pngData, imgData, meImageType))
400 sysData = [NSData dataWithBytes: imgData.getArray() length: imgData.getLength()];
402 return sysData;
405 /* The AOO 'PCT' filter is not yet good enough to be used
406 and there is no flavor defined for exchanging 'PCT' with AOO
407 so we convert 'PCT' to a PNG and provide this to AOO
409 Any PNGDataProvider::getOOoData()
411 Any oOOData;
413 if( mSystemData)
415 const unsigned int flavorDataLength = [mSystemData length];
416 Sequence<sal_Int8> imgData( flavorDataLength);
417 memcpy( imgData.getArray(), [mSystemData bytes], flavorDataLength);
419 Sequence<sal_Int8> pngData;
420 if( ImageToPNG( imgData, pngData))
421 oOOData <<= pngData;
423 else
425 oOOData = mData;
428 return oOOData;
431 namespace {
433 class FileListDataProvider : public DataProviderBaseImpl
435 public:
436 FileListDataProvider(const Any& data);
437 FileListDataProvider(NSArray* data);
439 virtual NSData* getSystemData() override;
440 virtual Any getOOoData() override;
445 FileListDataProvider::FileListDataProvider(const Any& data) :
446 DataProviderBaseImpl(data)
450 FileListDataProvider::FileListDataProvider(NSArray* data) :
451 DataProviderBaseImpl(data)
455 NSData* FileListDataProvider::getSystemData()
457 return [NSData data];
460 Any FileListDataProvider::getOOoData()
462 Any oOOData;
464 if (mSystemData)
466 size_t length = [mSystemData count];
467 size_t lenSeqRequired = 0;
469 for (size_t i = 0; i < length; i++)
471 NSString* fname = [mSystemData objectAtIndex: i];
472 lenSeqRequired += [fname maximumLengthOfBytesUsingEncoding: NSUnicodeStringEncoding] + sizeof(unichar);
475 Sequence<sal_Int8> oOOFileList(lenSeqRequired);
476 unichar* pBuffer = reinterpret_cast<unichar*>(oOOFileList.getArray());
477 memset(pBuffer, 0, lenSeqRequired);
479 for (size_t i = 0; i < length; i++)
481 NSString* fname = [mSystemData objectAtIndex: i];
482 [fname getCharacters: pBuffer];
483 size_t l = [fname length];
484 pBuffer += l + 1;
487 oOOData <<= oOOFileList;
489 else
491 oOOData = mData;
494 return oOOData;
497 DataFlavorMapper::DataFlavorMapper()
499 Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
500 mrXMimeCntFactory = MimeContentTypeFactory::create( xContext );
503 DataFlavorMapper::~DataFlavorMapper()
505 // release potential NSStrings
506 for( OfficeOnlyTypes::iterator it = maOfficeOnlyTypes.begin(); it != maOfficeOnlyTypes.end(); ++it )
508 [it->second release];
509 it->second = nil;
513 DataFlavor DataFlavorMapper::systemToOpenOfficeFlavor( const NSString* systemDataFlavor) const
515 DataFlavor oOOFlavor;
517 for (size_t i = 0; i < SIZE_FLAVOR_MAP; i++)
519 if ((flavorMap[i].SystemFlavor == nil && ([systemDataFlavor isEqualToString:[NSString stringWithUTF8String:flavorMap[i].OOoFlavor]]
521 [systemDataFlavor hasPrefix:[[NSString stringWithUTF8String:flavorMap[i].OOoFlavor] stringByAppendingString:@";"]]))
523 (flavorMap[i].SystemFlavor != nil && [systemDataFlavor isEqualToString:const_cast<NSString*>(flavorMap[i].SystemFlavor)]))
525 if (flavorMap[i].SystemFlavor == nil)
526 oOOFlavor.MimeType = NSStringToOUString(systemDataFlavor);
527 else
528 oOOFlavor.MimeType = OUString::createFromAscii(flavorMap[i].OOoFlavor);
529 oOOFlavor.HumanPresentableName = OUString::createFromAscii(flavorMap[i].HumanPresentableName);
530 oOOFlavor.DataType = flavorMap[i].DataTypeOUString ? cppu::UnoType<OUString>::get() : cppu::UnoType<Sequence<sal_Int8>>::get();
531 return oOOFlavor;
533 } // for
535 // look if this might be an internal type; if it comes in here it must have
536 // been through openOfficeToSystemFlavor before, so it should then be in the map
537 OUString aTryFlavor( NSStringToOUString( systemDataFlavor ) );
538 if( maOfficeOnlyTypes.find( aTryFlavor ) != maOfficeOnlyTypes.end() )
540 oOOFlavor.MimeType = aTryFlavor;
541 oOOFlavor.HumanPresentableName.clear();
542 oOOFlavor.DataType = cppu::UnoType<Sequence<sal_Int8>>::get();
545 return oOOFlavor;
548 const NSString* DataFlavorMapper::openOfficeToSystemFlavor( const DataFlavor& oOOFlavor, bool& rbInternal) const
550 const NSString* sysFlavor = nullptr;
551 rbInternal = false;
553 for( size_t i = 0; i < SIZE_FLAVOR_MAP; ++i )
555 if (oOOFlavor.MimeType.startsWith(OUString::createFromAscii(flavorMap[i].OOoFlavor)))
557 if (flavorMap[i].SystemFlavor != nil)
558 sysFlavor = flavorMap[i].SystemFlavor;
559 else
560 sysFlavor = OUStringToNSString(oOOFlavor.MimeType);
564 if(!sysFlavor)
566 rbInternal = true;
567 OfficeOnlyTypes::const_iterator it = maOfficeOnlyTypes.find( oOOFlavor.MimeType );
569 if( it == maOfficeOnlyTypes.end() )
570 sysFlavor = maOfficeOnlyTypes[ oOOFlavor.MimeType ] = OUStringToNSString( oOOFlavor.MimeType );
571 else
572 sysFlavor = it->second;
575 return sysFlavor;
578 NSString* DataFlavorMapper::openOfficeImageToSystemFlavor(NSPasteboard* pPasteboard)
580 NSArray *supportedTypes = [NSArray arrayWithObjects: NSPasteboardTypeTIFF, nil];
581 NSString *sysFlavor = [pPasteboard availableTypeFromArray:supportedTypes];
582 return sysFlavor;
585 DataProviderPtr_t DataFlavorMapper::getDataProvider( const NSString* systemFlavor, Reference<XTransferable> const & rTransferable) const
587 DataProviderPtr_t dp;
591 DataFlavor oOOFlavor = systemToOpenOfficeFlavor(systemFlavor);
593 Any data = rTransferable->getTransferData(oOOFlavor);
595 if (isByteSequenceType(data.getValueType()))
598 the HTMLFormatDataProvider prepends segment information to HTML
599 this is useful for exchange with MS Word (which brings this stuff from Windows)
600 but annoying for other applications. Since this extension is not a standard datatype
601 on the Mac, let us not provide but provide normal HTML
603 if ([systemFlavor caseInsensitiveCompare: NSHTMLPboardType] == NSOrderedSame)
605 dp = DataProviderPtr_t(new HTMLFormatDataProvider(data));
607 else
609 if ([systemFlavor caseInsensitiveCompare: NSPasteboardTypeTIFF] == NSOrderedSame)
611 dp = DataProviderPtr_t( new PNGDataProvider( data, NSBitmapImageFileTypeTIFF));
613 SAL_WNODEPRECATED_DECLARATIONS_PUSH
614 // "'NSFilenamesPboardType' is deprecated: first deprecated in macOS 10.14 - Create
615 // multiple pasteboard items with NSPasteboardTypeFileURL or kUTTypeFileURL instead"
616 else if ([systemFlavor caseInsensitiveCompare: NSFilenamesPboardType] == NSOrderedSame)
617 SAL_WNODEPRECATED_DECLARATIONS_POP
619 dp = DataProviderPtr_t(new FileListDataProvider(data));
621 else
623 dp = DataProviderPtr_t(new ByteSequenceDataProvider(data));
626 else // Must be OUString type
628 SAL_WARN_IF(
629 !isOUStringType(data.getValueType()), "vcl",
630 "must be OUString type");
631 dp = DataProviderPtr_t(new UniDataProvider(data));
634 catch( const UnsupportedFlavorException& e )
636 SAL_WARN( "vcl.osx.clipboard", "DataFlavorMapper::getDataProvider(): Exception: " << e.Message );
637 // Somebody violates the contract of the clipboard
638 // interface @see XTransferable
641 return dp;
644 DataProviderPtr_t DataFlavorMapper::getDataProvider( const NSString* /*systemFlavor*/, NSArray* systemData)
646 return DataProviderPtr_t(new FileListDataProvider(systemData));
649 DataProviderPtr_t DataFlavorMapper::getDataProvider( const NSString* systemFlavor, NSData* systemData)
651 DataProviderPtr_t dp;
653 if ([systemFlavor caseInsensitiveCompare: NSPasteboardTypeString] == NSOrderedSame)
655 dp = DataProviderPtr_t(new UniDataProvider(systemData));
657 else if ([systemFlavor caseInsensitiveCompare: NSPasteboardTypeHTML] == NSOrderedSame)
659 dp = DataProviderPtr_t(new HTMLFormatDataProvider(systemData));
661 else if ([systemFlavor caseInsensitiveCompare: NSPasteboardTypeTIFF] == NSOrderedSame)
663 dp = DataProviderPtr_t( new PNGDataProvider(systemData, NSBitmapImageFileTypeTIFF));
665 SAL_WNODEPRECATED_DECLARATIONS_PUSH
666 // "'NSFilenamesPboardType' is deprecated: first deprecated in macOS 10.14 - Create multiple
667 // pasteboard items with NSPasteboardTypeFileURL or kUTTypeFileURL instead"
668 else if ([systemFlavor caseInsensitiveCompare: NSFilenamesPboardType] == NSOrderedSame)
669 SAL_WNODEPRECATED_DECLARATIONS_POP
671 //dp = DataProviderPtr_t(new FileListDataProvider(systemData));
673 else
675 dp = DataProviderPtr_t(new ByteSequenceDataProvider(systemData));
678 return dp;
681 bool DataFlavorMapper::isValidMimeContentType(const OUString& contentType) const
683 bool result = true;
687 Reference<XMimeContentType> xCntType(mrXMimeCntFactory->createMimeContentType(contentType));
689 catch( const IllegalArgumentException& e )
691 SAL_WARN("vcl.osx.clipboard", "DataFlavorMapper::isValidMimeContentType(): Exception: " << e.Message);
692 result = false;
695 return result;
698 NSArray* DataFlavorMapper::flavorSequenceToTypesArray(const css::uno::Sequence<css::datatransfer::DataFlavor>& flavors) const
700 sal_uInt32 nFlavors = flavors.getLength();
701 NSMutableArray* array = [[NSMutableArray alloc] initWithCapacity: 1];
703 bool bNeedDummyInternalFlavor(false);
705 for (sal_uInt32 i = 0; i < nFlavors; i++)
707 if( flavors[i].MimeType.startsWith("image/bmp") )
709 [array addObject: NSPasteboardTypeTIFF];
711 else
713 const NSString* str = openOfficeToSystemFlavor(flavors[i], bNeedDummyInternalFlavor);
715 if (str != nullptr)
717 [str retain];
718 [array addObject: str];
723 // #i89462# #i90747#
724 // in case no system flavor was found to report
725 // report at least one so D&D between OOo targets works
726 if( [array count] == 0 || bNeedDummyInternalFlavor)
728 [array addObject: [NSString stringWithUTF8String: FLAVOR_DUMMY_INTERNAL]];
731 return [array autorelease];
734 css::uno::Sequence<css::datatransfer::DataFlavor> DataFlavorMapper::typesArrayToFlavorSequence(NSArray* types) const
736 int nFormats = [types count];
737 Sequence<DataFlavor> flavors;
739 for (int i = 0; i < nFormats; i++)
741 NSString* sysFormat = [types objectAtIndex: i];
742 DataFlavor oOOFlavor = systemToOpenOfficeFlavor(sysFormat);
744 if (isValidFlavor(oOOFlavor))
746 flavors.realloc(flavors.getLength() + 1);
747 flavors.getArray()[flavors.getLength() - 1] = oOOFlavor;
751 return flavors;
754 NSArray* DataFlavorMapper::getAllSupportedPboardTypes()
756 NSMutableArray* array = [[NSMutableArray alloc] initWithCapacity: SIZE_FLAVOR_MAP];
758 for (sal_uInt32 i = 0; i < SIZE_FLAVOR_MAP; i++)
760 if (flavorMap[i].SystemFlavor != nil)
761 [array addObject: flavorMap[i].SystemFlavor];
762 else
763 [array addObject: [NSString stringWithUTF8String: flavorMap[i].OOoFlavor]];
766 return [array autorelease];
769 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */