Branch data Line data Source code
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 <drawinglayer/attribute/sdrshadowattribute.hxx>
21 : : #include <basegfx/vector/b2dvector.hxx>
22 : : #include <basegfx/color/bcolor.hxx>
23 : :
24 : : //////////////////////////////////////////////////////////////////////////////
25 : :
26 : : namespace drawinglayer
27 : : {
28 : : namespace attribute
29 : : {
30 : 0 : class ImpSdrShadowAttribute
31 : : {
32 : : public:
33 : : // refcounter
34 : : sal_uInt32 mnRefCount;
35 : :
36 : : // shadow definitions
37 : : basegfx::B2DVector maOffset; // shadow offset 1/100th mm
38 : : double mfTransparence; // [0.0 .. 1.0], 0.0==no transp.
39 : : basegfx::BColor maColor; // color of shadow
40 : :
41 : 63 : ImpSdrShadowAttribute(
42 : : const basegfx::B2DVector& rOffset,
43 : : double fTransparence,
44 : : const basegfx::BColor& rColor)
45 : : : mnRefCount(0),
46 : : maOffset(rOffset),
47 : : mfTransparence(fTransparence),
48 : 63 : maColor(rColor)
49 : : {
50 : 63 : }
51 : :
52 : : // data read access
53 : 0 : const basegfx::B2DVector& getOffset() const { return maOffset; }
54 : 0 : double getTransparence() const { return mfTransparence; }
55 : 0 : const basegfx::BColor& getColor() const { return maColor; }
56 : :
57 : 0 : bool operator==(const ImpSdrShadowAttribute& rCandidate) const
58 : : {
59 : 0 : return (getOffset() == rCandidate.getOffset()
60 : 0 : && getTransparence() == rCandidate.getTransparence()
61 [ # # ]: 0 : && getColor() == rCandidate.getColor());
[ # # # # ]
62 : : }
63 : :
64 : 235161 : static ImpSdrShadowAttribute* get_global_default()
65 : : {
66 : : static ImpSdrShadowAttribute* pDefault = 0;
67 : :
68 [ + + ]: 235161 : if(!pDefault)
69 : : {
70 : : pDefault = new ImpSdrShadowAttribute(
71 : : basegfx::B2DVector(),
72 : : 0.0,
73 [ + - ]: 63 : basegfx::BColor());
74 : :
75 : : // never delete; start with RefCount 1, not 0
76 : 63 : pDefault->mnRefCount++;
77 : : }
78 : :
79 : 235161 : return pDefault;
80 : : }
81 : : };
82 : :
83 : 0 : SdrShadowAttribute::SdrShadowAttribute(
84 : : const basegfx::B2DVector& rOffset,
85 : : double fTransparence,
86 : : const basegfx::BColor& rColor)
87 : : : mpSdrShadowAttribute(new ImpSdrShadowAttribute(
88 : 0 : rOffset, fTransparence, rColor))
89 : : {
90 : 0 : }
91 : :
92 : 195034 : SdrShadowAttribute::SdrShadowAttribute()
93 : 195034 : : mpSdrShadowAttribute(ImpSdrShadowAttribute::get_global_default())
94 : : {
95 : 195034 : mpSdrShadowAttribute->mnRefCount++;
96 : 195034 : }
97 : :
98 : 184153 : SdrShadowAttribute::SdrShadowAttribute(const SdrShadowAttribute& rCandidate)
99 : 184153 : : mpSdrShadowAttribute(rCandidate.mpSdrShadowAttribute)
100 : : {
101 : 184153 : mpSdrShadowAttribute->mnRefCount++;
102 : 184153 : }
103 : :
104 : 379187 : SdrShadowAttribute::~SdrShadowAttribute()
105 : : {
106 [ + - ]: 379187 : if(mpSdrShadowAttribute->mnRefCount)
107 : : {
108 : 379187 : mpSdrShadowAttribute->mnRefCount--;
109 : : }
110 : : else
111 : : {
112 [ # # ]: 0 : delete mpSdrShadowAttribute;
113 : : }
114 : 379187 : }
115 : :
116 : 40127 : bool SdrShadowAttribute::isDefault() const
117 : : {
118 : 40127 : return mpSdrShadowAttribute == ImpSdrShadowAttribute::get_global_default();
119 : : }
120 : :
121 : 86431 : SdrShadowAttribute& SdrShadowAttribute::operator=(const SdrShadowAttribute& rCandidate)
122 : : {
123 [ - + ]: 86431 : if(rCandidate.mpSdrShadowAttribute != mpSdrShadowAttribute)
124 : : {
125 [ # # ]: 0 : if(mpSdrShadowAttribute->mnRefCount)
126 : : {
127 : 0 : mpSdrShadowAttribute->mnRefCount--;
128 : : }
129 : : else
130 : : {
131 [ # # ]: 0 : delete mpSdrShadowAttribute;
132 : : }
133 : :
134 : 0 : mpSdrShadowAttribute = rCandidate.mpSdrShadowAttribute;
135 : 0 : mpSdrShadowAttribute->mnRefCount++;
136 : : }
137 : :
138 : 86431 : return *this;
139 : : }
140 : :
141 : 65935 : bool SdrShadowAttribute::operator==(const SdrShadowAttribute& rCandidate) const
142 : : {
143 [ + - ]: 65935 : if(rCandidate.mpSdrShadowAttribute == mpSdrShadowAttribute)
144 : : {
145 : 65935 : return true;
146 : : }
147 : :
148 [ # # ]: 0 : if(rCandidate.isDefault() != isDefault())
149 : : {
150 : 0 : return false;
151 : : }
152 : :
153 : 65935 : return (*rCandidate.mpSdrShadowAttribute == *mpSdrShadowAttribute);
154 : : }
155 : :
156 : 0 : const basegfx::B2DVector& SdrShadowAttribute::getOffset() const
157 : : {
158 : 0 : return mpSdrShadowAttribute->getOffset();
159 : : }
160 : :
161 : 0 : double SdrShadowAttribute::getTransparence() const
162 : : {
163 : 0 : return mpSdrShadowAttribute->getTransparence();
164 : : }
165 : :
166 : 0 : const basegfx::BColor& SdrShadowAttribute::getColor() const
167 : : {
168 : 0 : return mpSdrShadowAttribute->getColor();
169 : : }
170 : : } // end of namespace attribute
171 : : } // end of namespace drawinglayer
172 : :
173 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|