tdf#151679 Do not push FLAVOR_LINK to macOS general pasteboard
When copying text from a Writer document and the
FLAVOR_LINK flavor is pasted, Writer will edit the
copied text in order to create a bookmark for DDE.
The problem is that many macOS clipboard managers
fetch *all* available flavors that are available in
the macOS general pasteboard instead of just one
flavor and this triggers the FLAVOR_LINK flavor's
unusual editing behavor in Writer every time the
user copies Writer text.
Users have reported in tdf#1515679 that on macOS,
Microsoft Writer, Excel, and PowerPoint do not
recognize this flavor like is done on Windows so,
in theory, we can just filter out this flavor when
adding flavors to the macOS general pasteboard.
With this change, the FLAVOR_LINK flavor will still
be visible when copying and pasting within a single
LibreOffice instance as well as when dragging from
LibreOffice to other applications.
Change-Id: Ia391398286fa8795ac65b4702a15caf59fb3ae70
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161305
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
Reviewed-by: Patrick Luby <plubius@libreoffice.org>
(cherry picked from commit 29cc78b12315083ac5cfb2f59101d25e76b4f662)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161316
diff --git a/vcl/osx/DataFlavorMapping.cxx b/vcl/osx/DataFlavorMapping.cxx
index 274a2b4..361e268b 100644
--- a/vcl/osx/DataFlavorMapping.cxx
+++ b/vcl/osx/DataFlavorMapping.cxx
@@ -545,7 +545,7 @@ DataFlavor DataFlavorMapper::systemToOpenOfficeFlavor( const NSString* systemDat
return oOOFlavor;
}
const NSString* DataFlavorMapper::openOfficeToSystemFlavor( const DataFlavor& oOOFlavor, bool& rbInternal) const
const NSString* DataFlavorMapper::openOfficeToSystemFlavor( const DataFlavor& oOOFlavor, bool& rbInternal, bool bIsSystemClipboard ) const
{
const NSString* sysFlavor = nullptr;
rbInternal = false;
@@ -554,6 +554,25 @@ const NSString* DataFlavorMapper::openOfficeToSystemFlavor( const DataFlavor& oO
{
if (oOOFlavor.MimeType.startsWith(OUString::createFromAscii(flavorMap[i].OOoFlavor)))
{
// tdf#151679 Do not push FLAVOR_LINK to macOS general pasteboard
// When copying text from a Writer document and the FLAVOR_LINK
// flavor is pasted, Writer will edit the copied text in order
// to create a bookmark for DDE.
// The problem is that many macOS clipboard managers fetch *all*
// available flavors that are available in the macOS general
// pasteboard instead of just one flavor and this triggers the
// FLAVOR_LINK flavor's unusual editing behavor in Writer every
// time the user copies Writer text.
// Users have reported in tdf#1515679 that on macOS, Microsoft
// Writer, Excel, and PowerPoint do not recognize this flavor
// like is done on Windows so, in theory, we can just filter out
// this flavor when adding flavors to the macOS general pasteboard.
// With this change, the FLAVOR_LINK flavor will still be visible
// when copying and pasting within a single LibreOffice instance
// as well as when dragging from LibreOffice to other applications.
if (bIsSystemClipboard && !strcmp(FLAVOR_LINK, flavorMap[i].OOoFlavor))
return nullptr;
if (flavorMap[i].SystemFlavor != nil)
sysFlavor = flavorMap[i].SystemFlavor;
else
@@ -695,7 +714,7 @@ bool DataFlavorMapper::isValidMimeContentType(const OUString& contentType) const
return result;
}
NSArray* DataFlavorMapper::flavorSequenceToTypesArray(const css::uno::Sequence<css::datatransfer::DataFlavor>& flavors) const
NSArray* DataFlavorMapper::flavorSequenceToTypesArray(const css::uno::Sequence<css::datatransfer::DataFlavor>& flavors, bool bIsSystemClipboard) const
{
sal_uInt32 nFlavors = flavors.getLength();
NSMutableArray* array = [[NSMutableArray alloc] initWithCapacity: 1];
@@ -710,7 +729,7 @@ NSArray* DataFlavorMapper::flavorSequenceToTypesArray(const css::uno::Sequence<c
}
else
{
const NSString* str = openOfficeToSystemFlavor(flavors[i], bNeedDummyInternalFlavor);
const NSString* str = openOfficeToSystemFlavor(flavors[i], bNeedDummyInternalFlavor, bIsSystemClipboard);
if (str != nullptr)
{
diff --git a/vcl/osx/DataFlavorMapping.hxx b/vcl/osx/DataFlavorMapping.hxx
index fb5c807..1d4d421 100644
--- a/vcl/osx/DataFlavorMapping.hxx
+++ b/vcl/osx/DataFlavorMapping.hxx
@@ -72,7 +72,7 @@ public:
If there is no suitable mapping available NULL will
be returned.
*/
const NSString* openOfficeToSystemFlavor(const css::datatransfer::DataFlavor& oooDataFlavor, bool& rbInternal) const;
const NSString* openOfficeToSystemFlavor(const css::datatransfer::DataFlavor& oooDataFlavor, bool& rbInternal, bool bIsSystemClipboard = false) const;
/* Select the best available image data type
If there is no suitable mapping available NULL will
@@ -98,7 +98,7 @@ public:
Only those DataFlavors for which a suitable mapping to a system
type exist will be contained in the returned types array.
*/
NSArray* flavorSequenceToTypesArray(const css::uno::Sequence<css::datatransfer::DataFlavor>& flavors) const;
NSArray* flavorSequenceToTypesArray(const css::uno::Sequence<css::datatransfer::DataFlavor>& flavors, bool bIsSystemClipboard = false) const;
/* Translate an NSArray of system types into a sequence of DataFlavors.
Only those types for which a suitable mapping to a DataFlavor
diff --git a/vcl/osx/clipboard.cxx b/vcl/osx/clipboard.cxx
index 2dc2d5e..5d925b3 100644
--- a/vcl/osx/clipboard.cxx
+++ b/vcl/osx/clipboard.cxx
@@ -158,7 +158,7 @@ void SAL_CALL AquaClipboard::setContents(
uno::Reference<datatransfer::clipboard::XClipboardOwner> const & xClipboardOwner)
{
NSArray* types = xTransferable.is() ?
mpDataFlavorMapper->flavorSequenceToTypesArray(xTransferable->getTransferDataFlavors()) :
mpDataFlavorMapper->flavorSequenceToTypesArray(xTransferable->getTransferDataFlavors(), true) :
[NSArray array];
osl::ClearableMutexGuard aGuard(m_aMutex);