tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / svx / source / sdr / overlay / overlayobject.cxx
blob6966f5d0e7a83498e17c53b468a4d1ab9e3360ec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svx/sdr/overlay/overlayobject.hxx>
21 #include <svx/sdr/overlay/overlaymanager.hxx>
22 #include <basegfx/matrix/b2dhommatrix.hxx>
23 #include <basegfx/vector/b2dvector.hxx>
24 #include <basegfx/matrix/b2dhommatrixtools.hxx>
25 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
26 #include <osl/diagnose.h>
28 namespace sdr::overlay
30 void OverlayObject::objectChange()
32 const basegfx::B2DRange aPreviousRange(maBaseRange);
33 maBaseRange.reset();
34 resetPrimitive2DSequence();
35 // setPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DContainer());
37 if(getOverlayManager() && !aPreviousRange.isEmpty())
39 getOverlayManager()->invalidateRange(aPreviousRange);
42 const basegfx::B2DRange& rCurrentRange = getBaseRange();
44 if(getOverlayManager() && rCurrentRange != aPreviousRange && !rCurrentRange.isEmpty())
46 getOverlayManager()->invalidateRange(rCurrentRange);
50 // OverlayObject implementations.
51 drawinglayer::primitive2d::Primitive2DContainer OverlayObject::createOverlayObjectPrimitive2DSequence()
53 // Default implementation has to assert a missing implementation. It cannot
54 // be useful to have overlay object derivations which have no visualisation
55 // at all
56 OSL_FAIL("OverlayObject derivation without visualisation definition (missing createOverlayObjectPrimitive2DSequence implementation) (!)");
57 return drawinglayer::primitive2d::Primitive2DContainer();
60 sal_uInt32 OverlayObject::impCheckBlinkTimeValueRange(sal_uInt64 nBlinkTime)
62 if(nBlinkTime < 25)
64 nBlinkTime = 25;
66 else if(nBlinkTime > 10000)
68 nBlinkTime = 10000;
71 return nBlinkTime;
74 void OverlayObject::allowAntiAliase(bool bNew)
76 if(bNew != mbAllowsAntiAliase)
78 // remember new value
79 mbAllowsAntiAliase = bNew;
81 // register change (after change)
82 objectChange();
86 OverlayObject::OverlayObject(Color aBaseColor)
87 : mpOverlayManager(nullptr),
88 maOffset(0.0, 0.0),
89 maBaseColor(aBaseColor),
90 mbIsVisible(true),
91 mbIsHittable(true),
92 mbAllowsAnimation(false),
93 mbAllowsAntiAliase(true),
94 mbHighContrastSelection(false)
98 OverlayObject::~OverlayObject()
100 OSL_ENSURE(nullptr == getOverlayManager(), "OverlayObject is destructed which is still registered at OverlayManager (!)");
103 drawinglayer::primitive2d::Primitive2DContainer OverlayObject::getOverlayObjectPrimitive2DSequence() const
105 if(getPrimitive2DSequence().empty())
107 // no existing sequence; create one
108 const_cast< OverlayObject* >(this)->maPrimitive2DSequence = const_cast< OverlayObject* >(this)->createOverlayObjectPrimitive2DSequence();
110 if(!getOffset().equalZero())
112 // embed to offset transformation
113 const basegfx::B2DHomMatrix aTranslateGridOffset(
114 basegfx::utils::createTranslateB2DHomMatrix(
115 getOffset()));
116 const_cast< OverlayObject* >(this)->maPrimitive2DSequence =
117 drawinglayer::primitive2d::Primitive2DContainer {
118 new drawinglayer::primitive2d::TransformPrimitive2D(
119 aTranslateGridOffset,
120 std::move(const_cast<drawinglayer::primitive2d::Primitive2DContainer&>(maPrimitive2DSequence)))
125 return getPrimitive2DSequence();
128 const basegfx::B2DRange& OverlayObject::getBaseRange() const
130 if(getOverlayManager() && maBaseRange.isEmpty())
132 const drawinglayer::primitive2d::Primitive2DContainer aSequence = getOverlayObjectPrimitive2DSequence();
134 if(!aSequence.empty())
136 const drawinglayer::geometry::ViewInformation2D & aViewInformation2D(getOverlayManager()->getCurrentViewInformation2D());
138 const_cast< sdr::overlay::OverlayObject* >(this)->maBaseRange =
139 aSequence.getB2DRange(aViewInformation2D);
143 return maBaseRange;
146 void OverlayObject::setVisible(bool bNew)
148 if(bNew != mbIsVisible)
150 // remember new value
151 mbIsVisible = bNew;
153 // register change (after change)
154 objectChange();
158 void OverlayObject::setHittable(bool bNew)
160 if(bNew != mbIsHittable)
162 // remember new value
163 mbIsHittable = bNew;
165 // register change (after change)
166 objectChange();
170 void OverlayObject::setBaseColor(Color aNew)
172 if(aNew != maBaseColor)
174 // remember new value
175 maBaseColor = aNew;
177 // register change (after change)
178 objectChange();
182 void OverlayObject::setOffset(const basegfx::B2DVector& rOffset)
184 if(rOffset != maOffset)
186 // remember new value
187 maOffset = rOffset;
189 // register change (after change)
190 objectChange();
194 void OverlayObject::Trigger(sal_uInt32 /*nTime*/)
196 // default does not register again
199 void OverlayObject::stripeDefinitionHasChanged()
201 // default does not need to do anything
205 OverlayObjectWithBasePosition::OverlayObjectWithBasePosition(const basegfx::B2DPoint& rBasePos, Color aBaseColor)
206 : OverlayObject(aBaseColor),
207 maBasePosition(rBasePos)
211 OverlayObjectWithBasePosition::~OverlayObjectWithBasePosition()
215 void OverlayObjectWithBasePosition::setBasePosition(const basegfx::B2DPoint& rNew)
217 if(rNew != maBasePosition)
219 // remember new value
220 maBasePosition = rNew;
222 // register change (after change)
223 objectChange();
227 } // end of namespace
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */