xref: /core/sc/source/ui/view/overlayobject.cxx (revision 9d68c794)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <overlayobject.hxx>
21 #include <basegfx/range/b2drange.hxx>
22 #include <basegfx/polygon/b2dpolygon.hxx>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
24 #include <svx/sdr/overlay/overlaymanager.hxx>
25 #include <drawinglayer/primitive2d/PolyPolygonMarkerPrimitive2D.hxx>
26 #include <officecfg/Office/Common.hxx>
27 #include <vcl/settings.hxx>
28 
29 using sdr::overlay::OverlayObject;
30 using sdr::overlay::OverlayManager;
31 
32 #define DASH_UPDATE_INTERVAL 500    // in msec
33 
ScOverlayDashedBorder(const::basegfx::B2DRange & rRange,const Color & rColor)34 ScOverlayDashedBorder::ScOverlayDashedBorder(const ::basegfx::B2DRange& rRange, const Color& rColor) :
35     OverlayObject(rColor),
36     mbToggle(true)
37 {
38     // tdf#155414 include system "reduce animation" preferences
39     // Allow the system's "reduce animation" preferences to disable the
40     // Calc animated border when copying a selection of cells.
41     mbAllowsAnimation = (officecfg::Office::Common::VCL::AnimationsEnabled::get() && !MiscSettings::GetUseReducedAnimation());
42     maRange = rRange;
43 }
44 
~ScOverlayDashedBorder()45 ScOverlayDashedBorder::~ScOverlayDashedBorder()
46 {
47 }
48 
Trigger(sal_uInt32 nTime)49 void ScOverlayDashedBorder::Trigger(sal_uInt32 nTime)
50 {
51     OverlayManager* pMgr = getOverlayManager();
52     if (pMgr)
53     {
54         SetTime(nTime + DASH_UPDATE_INTERVAL);
55         mbToggle = !mbToggle;
56         pMgr->InsertEvent(*this);
57         objectChange();
58     }
59 }
60 
stripeDefinitionHasChanged()61 void ScOverlayDashedBorder::stripeDefinitionHasChanged()
62 {
63     objectChange();
64 }
65 
createOverlayObjectPrimitive2DSequence()66 drawinglayer::primitive2d::Primitive2DContainer ScOverlayDashedBorder::createOverlayObjectPrimitive2DSequence()
67 {
68     using ::basegfx::B2DPolygon;
69     using ::basegfx::B2DPolyPolygon;
70 
71     OverlayManager* pMgr = getOverlayManager();
72     if (!pMgr)
73         return drawinglayer::primitive2d::Primitive2DContainer();
74 
75     basegfx::BColor aColorA = pMgr->getStripeColorA().getBColor();
76     basegfx::BColor aColorB = pMgr->getStripeColorB().getBColor();
77     if (!mbToggle)
78         ::std::swap(aColorA, aColorB);
79 
80     const basegfx::B2DPolygon aPoly = basegfx::utils::createPolygonFromRect(maRange);
81     B2DPolyPolygon aPolygon(aPoly);
82     const drawinglayer::primitive2d::Primitive2DReference aReference(
83         new drawinglayer::primitive2d::PolyPolygonMarkerPrimitive2D(
84             std::move(aPolygon), aColorA, aColorB, pMgr->getStripeLengthPixel()));
85 
86     return drawinglayer::primitive2d::Primitive2DContainer { aReference };
87 }
88 
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
90