[Libreoffice-commits] core.git: include/sal vcl/osx
Tor Lillqvist (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jan 15 07:49:37 UTC 2021
include/sal/log-areas.dox | 1
vcl/osx/DataFlavorMapping.cxx | 79 +++++++++++++++++++++++-------------------
2 files changed, 46 insertions(+), 34 deletions(-)
New commits:
commit 84a6cfd9bb6532602ca811b0d5daf016bb9b4578
Author: Tor Lillqvist <tml at collabora.com>
AuthorDate: Thu Jan 14 16:03:33 2021 +0200
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Fri Jan 15 08:48:54 2021 +0100
Fix handling of the OBJECTDESCRIPTOR clipboard (pasteboard) type on macOS
This fixes a demonstrable problem, and affects only macOS.
This is also on the path towards fixing
https://github.com/CollaboraOnline/online/issues/849 , even if the
code touched here is for macOS only. The iOS pasteboard handling code
is based on the macOS one.
We need the pasteboard to have the OBJECTDESCRIPTOR type as a MIME
type that includes the typename attribute, because the code in sc
checks for that when it decides whether it is a proper
OBJECTDESCRIPTOR.
Simplify the data in the flavorMap array. No need to duplicate the
same MIME type string as both the pasteboard type and MIME type, for
those cases where the MIME type is used diretly as pasteboard type. We
also know that for those types, the MIME type might have additional
parameters, so be more lenient in checking.
With this change, and my recent change to sot, this now works:
Start LibreOffice. Open a spreadsheet. Select a cell range. (It can
include formulas.) Edit > Copy. Quit LibreOffice.
Start LibreOffice again. Open a spreadsheet. Edit > Paste. You get the
very same cells that you pasted as such (with relative cell addresses
in formulas properly adjusted, as expected).
Previously, it would paste an image of the copied cell range, which is
fairly pointless.
There is still lots of opportunity for cleanup in the clipboard code
for macOS and iOS. It is presumably rather pointless to put images on
the pasteboard in Windows bitmap format, for instance. Just PNG should
be enough. No idea why the code provides the TIFF pasteboard type for
images. Ditto for Windows metafiles (WMF and EMF). It is also unclear
how useful the EMBED_SOURCE or LINK_SOURCE types are on macOS, for
instance.
Change-Id: I573648480b03972b506203b4f470d513bcb81212
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109297
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist <tml at collabora.com>
diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox
index e6463117d1b8..4bdd3fb19a23 100644
--- a/include/sal/log-areas.dox
+++ b/include/sal/log-areas.dox
@@ -484,6 +484,7 @@ certain functionality.
@li @c vcl.opengl
@li @c vcl.opengl.qt5 - QT5 OpenGL
@li @c vcl.osx
+ at li @c vcl.osx.clipboard
@li @c vcl.osx.print
@li @c vcl.pdfwriter
@li @c vcl.plugadapt - the Unix/X11 backend plugin mechanism
diff --git a/vcl/osx/DataFlavorMapping.cxx b/vcl/osx/DataFlavorMapping.cxx
index 26724c5aed97..5659ce1e342b 100644
--- a/vcl/osx/DataFlavorMapping.cxx
+++ b/vcl/osx/DataFlavorMapping.cxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
@@ -74,19 +74,6 @@ namespace
return [NSString stringWithCString: utf8Str.getStr() encoding: NSUTF8StringEncoding];
}
- NSString* PBTYPE_SODX = @"application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"";
- NSString* PBTYPE_SESX = @"application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
- NSString* PBTYPE_SLSDX = @"application/x-openoffice-linksrcdescriptor-xml;windows_formatname=\"Star Link Source Descriptor (XML)\"";
- NSString* PBTYPE_ESX = @"application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
- NSString* PBTYPE_LSX = @"application/x-openoffice-link-source-xml;windows_formatname=\"Star Link Source (XML)\"";
- NSString* PBTYPE_EOX = @"application/x-openoffice-embedded-obj-xml;windows_formatname=\"Star Embedded Object (XML)\"";
- NSString* PBTYPE_SVXB = @"application/x-openoffice-svbx;windows_formatname=\"SVXB (StarView Bitmap/Animation)\"";
- NSString* PBTYPE_GDIMF = @"application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"";
- NSString* PBTYPE_WMF = @"application/x-openoffice-wmf;windows_formatname=\"Image WMF\"";
- NSString* PBTYPE_EMF = @"application/x-openoffice-emf;windows_formatname=\"Image EMF\"";
-
- NSString* PBTYPE_DUMMY_INTERNAL = @"application/x-openoffice-internal";
-
const char* FLAVOR_SODX = "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"";
const char* FLAVOR_SESX = "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
const char* FLAVOR_SLSDX = "application/x-openoffice-linksrcdescriptor-xml;windows_formatname=\"Star Link Source Descriptor (XML)\"";
@@ -108,8 +95,17 @@ namespace
bool DataTypeOUString; // sequence<byte> otherwise
};
- /* At the moment it appears as if only MS Office pastes "public.html" to the clipboard.
- */
+ // The SystemFlavor member is nil for the cases where there is no predefined pasteboard type UTI
+ // and we use the internal MIME type (media type) also on the pasteboard. That is OK in macOS,
+ // there is no requirement that the types are well-formed UTIs. It is different on iOS, I think,
+ // though. For an introduction to UTIs, see for instance
+ // https://alastairs-place.net/blog/2012/06/06/utis-are-better-than-you-think-and-heres-why/
+ //
+ // In those cases the MIME type might actually have parameters appended, separated by semicolons.
+ // At least the FLAVOR_SODX one must have at least a typename="%PRODUCTNAME %PRODUCTVERSION
+ // Spreadsheet" parameter (with macros expanded and translated) for LO to recognise it. See
+ // lcl_TestFormat() in sc/source/ui/view/cellsh.cxx.
+
const FlavorMap flavorMap[] =
{
{ NSPasteboardTypeString, "text/plain;charset=utf-16", "Unicode Text (UTF-16)", true },
@@ -122,17 +118,17 @@ SAL_WNODEPRECATED_DECLARATIONS_PUSH
// multiple pasteboard items with NSPasteboardTypeFileURL or kUTTypeFileURL instead"
{ NSFilenamesPboardType, "application/x-openoffice-filelist;windows_formatname=\"FileList\"", "FileList", false },
SAL_WNODEPRECATED_DECLARATIONS_POP
- { PBTYPE_SESX, FLAVOR_SESX, "Star Embed Source (XML)", false },
- { PBTYPE_SLSDX, FLAVOR_SLSDX, "Star Link Source Descriptor (XML)", false },
- { PBTYPE_ESX, FLAVOR_ESX, "Star Embed Source (XML)", false },
- { PBTYPE_LSX, FLAVOR_LSX, "Star Link Source (XML)", false },
- { PBTYPE_EOX, FLAVOR_EOX, "Star Embedded Object (XML)", false },
- { PBTYPE_SVXB, FLAVOR_SVXB, "SVXB (StarView Bitmap/Animation", false },
- { PBTYPE_GDIMF, FLAVOR_GDIMF, "GDIMetaFile", false },
- { PBTYPE_WMF, FLAVOR_WMF, "Windows MetaFile", false },
- { PBTYPE_EMF, FLAVOR_EMF, "Windows Enhanced MetaFile", false },
- { PBTYPE_SODX, FLAVOR_SODX, "Star Object Descriptor (XML)", false },
- { PBTYPE_DUMMY_INTERNAL, FLAVOR_DUMMY_INTERNAL, "internal data",false }
+ { nil, FLAVOR_SESX, "Star Embed Source (XML)", false },
+ { nil, FLAVOR_SLSDX, "Star Link Source Descriptor (XML)", false },
+ { nil, FLAVOR_ESX, "Star Embed Source (XML)", false },
+ { nil, FLAVOR_LSX, "Star Link Source (XML)", false },
+ { nil, FLAVOR_EOX, "Star Embedded Object (XML)", false },
+ { nil, FLAVOR_SVXB, "SVXB (StarView Bitmap/Animation", false },
+ { nil, FLAVOR_GDIMF, "GDIMetaFile", false },
+ { nil, FLAVOR_WMF, "Windows MetaFile", false },
+ { nil, FLAVOR_EMF, "Windows Enhanced MetaFile", false },
+ { nil, FLAVOR_SODX, "Star Object Descriptor (XML)", false },
+ { nil, FLAVOR_DUMMY_INTERNAL, "internal data",false }
};
#define SIZE_FLAVOR_MAP (sizeof(flavorMap)/sizeof(FlavorMap))
@@ -510,9 +506,16 @@ DataFlavor DataFlavorMapper::systemToOpenOfficeFlavor( const NSString* systemDat
for (size_t i = 0; i < SIZE_FLAVOR_MAP; i++)
{
- if ([systemDataFlavor caseInsensitiveCompare:const_cast<NSString*>(flavorMap[i].SystemFlavor)] == NSOrderedSame)
+ if ((flavorMap[i].SystemFlavor == nil && ([systemDataFlavor isEqualToString:[NSString stringWithUTF8String:flavorMap[i].OOoFlavor]]
+ ||
+ [systemDataFlavor hasPrefix:[[NSString stringWithUTF8String:flavorMap[i].OOoFlavor] stringByAppendingString:@";"]]))
+ ||
+ (flavorMap[i].SystemFlavor != nil && [systemDataFlavor isEqualToString:const_cast<NSString*>(flavorMap[i].SystemFlavor)]))
{
- oOOFlavor.MimeType = OUString::createFromAscii(flavorMap[i].OOoFlavor);
+ if (flavorMap[i].SystemFlavor == nil)
+ oOOFlavor.MimeType = NSStringToOUString(systemDataFlavor);
+ else
+ oOOFlavor.MimeType = OUString::createFromAscii(flavorMap[i].OOoFlavor);
oOOFlavor.HumanPresentableName = OUString::createFromAscii(flavorMap[i].HumanPresentableName);
oOOFlavor.DataType = flavorMap[i].DataTypeOUString ? cppu::UnoType<OUString>::get() : cppu::UnoType<Sequence<sal_Int8>>::get();
return oOOFlavor;
@@ -541,7 +544,10 @@ const NSString* DataFlavorMapper::openOfficeToSystemFlavor( const DataFlavor& oO
{
if (oOOFlavor.MimeType.startsWith(OUString::createFromAscii(flavorMap[i].OOoFlavor)))
{
- sysFlavor = flavorMap[i].SystemFlavor;
+ if (flavorMap[i].SystemFlavor != nil)
+ sysFlavor = flavorMap[i].SystemFlavor;
+ else
+ sysFlavor = OUStringToNSString(oOOFlavor.MimeType);
}
}
@@ -615,8 +621,9 @@ SAL_WNODEPRECATED_DECLARATIONS_POP
dp = DataProviderPtr_t(new UniDataProvider(data));
}
}
- catch(UnsupportedFlavorException&)
+ catch( const UnsupportedFlavorException& e )
{
+ SAL_WARN( "vcl.osx.clipboard", "DataFlavorMapper::getDataProvider(): Exception: " << e.Message );
// Somebody violates the contract of the clipboard
// interface @see XTransferable
}
@@ -669,8 +676,9 @@ bool DataFlavorMapper::isValidMimeContentType(const OUString& contentType) const
{
Reference<XMimeContentType> xCntType(mrXMimeCntFactory->createMimeContentType(contentType));
}
- catch( IllegalArgumentException& )
+ catch( const IllegalArgumentException& e )
{
+ SAL_WARN("vcl.osx.clipboard", "DataFlavorMapper::isValidMimeContentType(): Exception: " << e.Message);
result = false;
}
@@ -707,7 +715,7 @@ NSArray* DataFlavorMapper::flavorSequenceToTypesArray(const css::uno::Sequence<c
// report at least one so D&D between OOo targets works
if( [array count] == 0 || bNeedDummyInternalFlavor)
{
- [array addObject: PBTYPE_DUMMY_INTERNAL];
+ [array addObject: [NSString stringWithUTF8String: FLAVOR_DUMMY_INTERNAL]];
}
return [array autorelease];
@@ -739,7 +747,10 @@ NSArray* DataFlavorMapper::getAllSupportedPboardTypes()
for (sal_uInt32 i = 0; i < SIZE_FLAVOR_MAP; i++)
{
- [array addObject: flavorMap[i].SystemFlavor];
+ if (flavorMap[i].SystemFlavor != nil)
+ [array addObject: flavorMap[i].SystemFlavor];
+ else
+ [array addObject: [NSString stringWithUTF8String: flavorMap[i].OOoFlavor]];
}
return [array autorelease];
More information about the Libreoffice-commits
mailing list