tdf#155414 include system "reduce animation" preferences

Allow the system's "reduce animation" preferences to disable the
Calc animated border when copying a selection of cells.

Also, fix failure to stop the animated border when a copy action is
performed in a different document by cancelling the animated border.
This transferable has lost ownership of the system clipboard so,
in essence, the previous copy action that created this transferable
has been cancelled.

Change-Id: I4da6d557c5dbf653c38a99eb7a16d961843a41d6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154752
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Reviewed-by: Patrick Luby <plubius@neooffice.org>
(cherry picked from commit 55bc4dc435d2e730a088aac881f0d4a248a030ba)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154859
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/include/vcl/settings.hxx b/include/vcl/settings.hxx
index 7f4849c..addf6eb 100644
--- a/include/vcl/settings.hxx
+++ b/include/vcl/settings.hxx
@@ -655,6 +655,8 @@ public:
    static bool                     GetUseDarkMode();
    static void                     SetAppColorMode(int nMode);
    static int                      GetAppColorMode();
    // return true if system preferences are set to use reduced animation
    static bool                     GetUseReducedAnimation();
    bool                            operator ==( const MiscSettings& rSet ) const;
    bool                            operator !=( const MiscSettings& rSet ) const;
};
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index ec5914a..1a8216e 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -557,6 +557,18 @@ IMPL_LINK( ScCellShell, ClipboardChanged, TransferableDataHelper*, pDataHelper, 
    rBindings.Invalidate( SID_PASTE_AS_LINK );
    rBindings.Invalidate( SID_PASTE_TEXTIMPORT_DIALOG );
    rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );

    // Fix failure to stop the animated border when a copy action is
    // performed in a different document by cancelling the animated border.
    // This transferable has lost ownership of the system clipboard so,
    // in essence, the previous copy action that created this transferable
    // has been cancelled.
    if ( !GetViewData().IsAnyFillMode() )
    {
        GetViewData().SetPasteMode( ScPasteFlags::NONE );
        // Clear CopySourceOverlay in each window of a split/frozen tabview
        GetViewData().GetView()->UpdateCopySourceOverlay();
    }
}

namespace {
diff --git a/sc/source/ui/view/overlayobject.cxx b/sc/source/ui/view/overlayobject.cxx
index 2be2007..a564265 100644
--- a/sc/source/ui/view/overlayobject.cxx
+++ b/sc/source/ui/view/overlayobject.cxx
@@ -24,6 +24,7 @@
#include <svx/sdr/overlay/overlaymanager.hxx>
#include <drawinglayer/primitive2d/PolyPolygonMarkerPrimitive2D.hxx>
#include <officecfg/Office/Common.hxx>
#include <vcl/settings.hxx>

using sdr::overlay::OverlayObject;
using sdr::overlay::OverlayManager;
@@ -34,7 +35,10 @@ ScOverlayDashedBorder::ScOverlayDashedBorder(const ::basegfx::B2DRange& rRange, 
    OverlayObject(rColor),
    mbToggle(true)
{
    mbAllowsAnimation = officecfg::Office::Common::VCL::AnimationsEnabled::get();
    // tdf#155414 include system "reduce animation" preferences
    // Allow the system's "reduce animation" preferences to disable the
    // Calc animated border when copying a selection of cells.
    mbAllowsAnimation = (officecfg::Office::Common::VCL::AnimationsEnabled::get() && !MiscSettings::GetUseReducedAnimation());
    maRange = rRange;
}

diff --git a/vcl/inc/osx/salframe.h b/vcl/inc/osx/salframe.h
index a9c2a40..87ab098 100644
--- a/vcl/inc/osx/salframe.h
+++ b/vcl/inc/osx/salframe.h
@@ -165,6 +165,7 @@ public:
    virtual void EndSetClipRegion() override;
    virtual void UpdateDarkMode() override;
    virtual bool GetUseDarkMode() const override;
    virtual bool GetUseReducedAnimation() const override;

    void UpdateFrameGeometry();

diff --git a/vcl/inc/salframe.hxx b/vcl/inc/salframe.hxx
index 8f6e2dd..0c3b170 100644
--- a/vcl/inc/salframe.hxx
+++ b/vcl/inc/salframe.hxx
@@ -301,6 +301,7 @@ public:

    virtual void            UpdateDarkMode() {}
    virtual bool            GetUseDarkMode() const { return false; }
    virtual bool            GetUseReducedAnimation() const { return false; };

    // Call the callback set; this sometimes necessary for implementation classes
    // that should not know more than necessary about the SalFrame implementation
diff --git a/vcl/osx/salframe.cxx b/vcl/osx/salframe.cxx
index 18ab569..a82cf9d 100644
--- a/vcl/osx/salframe.cxx
+++ b/vcl/osx/salframe.cxx
@@ -1309,6 +1309,11 @@ bool AquaSalFrame::GetUseDarkMode() const
    return bUseDarkMode;
}

bool AquaSalFrame::GetUseReducedAnimation() const
{
    return [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion];
}

// on OSX-Aqua the style settings are independent of the frame, so it does
// not really belong here. Since the connection to the Appearance_Manager
// is currently done in salnativewidgets.cxx this would be a good place.
diff --git a/vcl/source/app/settings.cxx b/vcl/source/app/settings.cxx
index 9921b0b7..a0385c4 100644
--- a/vcl/source/app/settings.cxx
+++ b/vcl/source/app/settings.cxx
@@ -2822,6 +2822,14 @@ void MiscSettings::SetAppColorMode(int nMode)
    batch->commit();
}

bool MiscSettings::GetUseReducedAnimation()
{
    vcl::Window* pDefWindow = ImplGetDefaultWindow();
    if (pDefWindow == nullptr)
        return false;
    return pDefWindow->ImplGetFrame()->GetUseReducedAnimation();
}

HelpSettings::HelpSettings()
    : mxData(std::make_shared<ImplHelpData>())
{