calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / attribute / fillgraphicattribute.cxx
blob300d6f6123f16f844421be2a6cc9d2bde2986035
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 <sal/config.h>
22 #include <algorithm>
24 #include <drawinglayer/attribute/fillgraphicattribute.hxx>
25 #include <utility>
26 #include <vcl/graph.hxx>
28 namespace drawinglayer::attribute
30 class ImpFillGraphicAttribute
32 public:
33 // data definitions
34 Graphic maGraphic;
35 basegfx::B2DRange maGraphicRange;
37 bool mbTiling : 1;
39 // tiling definitions, offsets in X/Y in percent for each 2nd row.
40 // If both are set, Y is ignored (X has precedence)
41 double mfOffsetX;
42 double mfOffsetY;
44 ImpFillGraphicAttribute(
45 Graphic aGraphic,
46 const basegfx::B2DRange& rGraphicRange,
47 bool bTiling,
48 double fOffsetX,
49 double fOffsetY)
50 : maGraphic(std::move(aGraphic)),
51 maGraphicRange(rGraphicRange),
52 mbTiling(bTiling),
53 mfOffsetX(fOffsetX),
54 mfOffsetY(fOffsetY)
56 // access once to ensure that the buffered bitmap exists, else
57 // the SolarMutex may be needed to create it. This may not be
58 // available when a renderer works with multi-threading.
59 // When changing this, please check if it is still possible to
60 // use a metafile as texture for a 3D object
61 maGraphic.GetBitmapEx();
64 ImpFillGraphicAttribute()
65 : mbTiling(false),
66 mfOffsetX(0.0),
67 mfOffsetY(0.0)
71 // data read access
72 const Graphic& getGraphic() const { return maGraphic; }
73 const basegfx::B2DRange& getGraphicRange() const { return maGraphicRange; }
74 bool getTiling() const { return mbTiling; }
75 double getOffsetX() const { return mfOffsetX; }
76 double getOffsetY() const { return mfOffsetY; }
78 bool operator==(const ImpFillGraphicAttribute& rCandidate) const
80 return (getGraphic() == rCandidate.getGraphic()
81 && getGraphicRange() == rCandidate.getGraphicRange()
82 && getTiling() == rCandidate.getTiling()
83 && getOffsetX() == rCandidate.getOffsetX()
84 && getOffsetY() == rCandidate.getOffsetY());
88 namespace
90 FillGraphicAttribute::ImplType& theGlobalDefault()
92 static FillGraphicAttribute::ImplType SINGLETON;
93 return SINGLETON;
97 FillGraphicAttribute::FillGraphicAttribute(
98 const Graphic& rGraphic,
99 const basegfx::B2DRange& rGraphicRange,
100 bool bTiling,
101 double fOffsetX,
102 double fOffsetY)
103 : mpFillGraphicAttribute(ImpFillGraphicAttribute(
104 rGraphic, rGraphicRange, bTiling,
105 std::clamp(fOffsetX, 0.0, 1.0),
106 std::clamp(fOffsetY, 0.0, 1.0)))
110 FillGraphicAttribute::FillGraphicAttribute(const FillGraphicAttribute&) = default;
112 FillGraphicAttribute::~FillGraphicAttribute() = default;
114 bool FillGraphicAttribute::isDefault() const
116 return mpFillGraphicAttribute.same_object(theGlobalDefault());
119 FillGraphicAttribute& FillGraphicAttribute::operator=(const FillGraphicAttribute&) = default;
121 bool FillGraphicAttribute::operator==(const FillGraphicAttribute& rCandidate) const
123 // tdf#87509 default attr is always != non-default attr, even with same values
124 if(rCandidate.isDefault() != isDefault())
125 return false;
127 return rCandidate.mpFillGraphicAttribute == mpFillGraphicAttribute;
130 const Graphic& FillGraphicAttribute::getGraphic() const
132 return mpFillGraphicAttribute->getGraphic();
135 const basegfx::B2DRange& FillGraphicAttribute::getGraphicRange() const
137 return mpFillGraphicAttribute->getGraphicRange();
140 bool FillGraphicAttribute::getTiling() const
142 return mpFillGraphicAttribute->getTiling();
145 double FillGraphicAttribute::getOffsetX() const
147 return mpFillGraphicAttribute->getOffsetX();
150 double FillGraphicAttribute::getOffsetY() const
152 return mpFillGraphicAttribute->getOffsetY();
155 } // end of namespace
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */