14bfbcde8SAndrew Rist /**************************************************************
24bfbcde8SAndrew Rist  *
34bfbcde8SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
44bfbcde8SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
54bfbcde8SAndrew Rist  * distributed with this work for additional information
64bfbcde8SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
74bfbcde8SAndrew Rist  * to you under the Apache License, Version 2.0 (the
84bfbcde8SAndrew Rist  * "License"); you may not use this file except in compliance
94bfbcde8SAndrew Rist  * with the License.  You may obtain a copy of the License at
104bfbcde8SAndrew Rist  *
114bfbcde8SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
124bfbcde8SAndrew Rist  *
134bfbcde8SAndrew Rist  * Unless required by applicable law or agreed to in writing,
144bfbcde8SAndrew Rist  * software distributed under the License is distributed on an
154bfbcde8SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
164bfbcde8SAndrew Rist  * KIND, either express or implied.  See the License for the
174bfbcde8SAndrew Rist  * specific language governing permissions and limitations
184bfbcde8SAndrew Rist  * under the License.
194bfbcde8SAndrew Rist  *
204bfbcde8SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <drawinglayer/attribute/sdrfillattribute.hxx>
26cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
27*035a2f44SArmin Le Grand #include <drawinglayer/attribute/sdrfillgraphicattribute.hxx>
28cdf0e10cSrcweir #include <drawinglayer/attribute/fillhatchattribute.hxx>
29cdf0e10cSrcweir #include <drawinglayer/attribute/fillgradientattribute.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace drawinglayer
34cdf0e10cSrcweir {
35cdf0e10cSrcweir 	namespace attribute
36cdf0e10cSrcweir 	{
37cdf0e10cSrcweir 		class ImpSdrFillAttribute
38cdf0e10cSrcweir 		{
39cdf0e10cSrcweir 		public:
40cdf0e10cSrcweir 			// refcounter
41cdf0e10cSrcweir 			sal_uInt32							mnRefCount;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 			// fill definitions
44cdf0e10cSrcweir 			double								mfTransparence;		// [0.0 .. 1.0], 0.0==no transp.
45cdf0e10cSrcweir 			basegfx::BColor						maColor;			// fill color
46cdf0e10cSrcweir 			FillGradientAttribute				maGradient;			// fill gradient (if used)
47cdf0e10cSrcweir 			FillHatchAttribute					maHatch;			// fill hatch (if used)
48*035a2f44SArmin Le Grand 			SdrFillGraphicAttribute				maFillGraphic;		// fill graphic (if used)
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 		public:
ImpSdrFillAttribute(double fTransparence,const basegfx::BColor & rColor,const FillGradientAttribute & rGradient,const FillHatchAttribute & rHatch,const SdrFillGraphicAttribute & rFillGraphic)51cdf0e10cSrcweir 			ImpSdrFillAttribute(
52cdf0e10cSrcweir 				double fTransparence,
53cdf0e10cSrcweir                 const basegfx::BColor& rColor,
54cdf0e10cSrcweir                 const FillGradientAttribute& rGradient,
55cdf0e10cSrcweir 				const FillHatchAttribute& rHatch,
56*035a2f44SArmin Le Grand                 const SdrFillGraphicAttribute& rFillGraphic)
57cdf0e10cSrcweir 			:	mnRefCount(0),
58cdf0e10cSrcweir 			    mfTransparence(fTransparence),
59cdf0e10cSrcweir 			    maColor(rColor),
60cdf0e10cSrcweir 			    maGradient(rGradient),
61cdf0e10cSrcweir 			    maHatch(rHatch),
62*035a2f44SArmin Le Grand 			    maFillGraphic(rFillGraphic)
63cdf0e10cSrcweir             {
64cdf0e10cSrcweir             }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 			// data read access
getTransparence() const67cdf0e10cSrcweir 			double getTransparence() const { return mfTransparence;	}
getColor() const68cdf0e10cSrcweir 			const basegfx::BColor& getColor() const { return maColor; }
getGradient() const69cdf0e10cSrcweir 			const FillGradientAttribute& getGradient() const { return maGradient; }
getHatch() const70cdf0e10cSrcweir 			const FillHatchAttribute& getHatch() const { return maHatch; }
getFillGraphic() const71*035a2f44SArmin Le Grand 			const SdrFillGraphicAttribute& getFillGraphic() const { return maFillGraphic; }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir             // compare operator
operator ==(const ImpSdrFillAttribute & rCandidate) const74cdf0e10cSrcweir 			bool operator==(const ImpSdrFillAttribute& rCandidate) const
75cdf0e10cSrcweir             {
76cdf0e10cSrcweir                 return(getTransparence() == rCandidate.getTransparence()
77cdf0e10cSrcweir                     && getColor() == rCandidate.getColor()
78cdf0e10cSrcweir                     && getGradient() == rCandidate.getGradient()
79cdf0e10cSrcweir                     && getHatch() == rCandidate.getHatch()
80*035a2f44SArmin Le Grand                     && getFillGraphic() == rCandidate.getFillGraphic());
81cdf0e10cSrcweir             }
82cdf0e10cSrcweir 
get_global_default()83cdf0e10cSrcweir             static ImpSdrFillAttribute* get_global_default()
84cdf0e10cSrcweir             {
85cdf0e10cSrcweir                 static ImpSdrFillAttribute* pDefault = 0;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir                 if(!pDefault)
88cdf0e10cSrcweir                 {
89cdf0e10cSrcweir                     pDefault = new ImpSdrFillAttribute(
90cdf0e10cSrcweir 				        0.0,
91cdf0e10cSrcweir                         basegfx::BColor(),
92cdf0e10cSrcweir                         FillGradientAttribute(),
93cdf0e10cSrcweir 				        FillHatchAttribute(),
94*035a2f44SArmin Le Grand                         SdrFillGraphicAttribute());
95cdf0e10cSrcweir 
96cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
97cdf0e10cSrcweir     			    pDefault->mnRefCount++;
98cdf0e10cSrcweir                 }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir                 return pDefault;
101cdf0e10cSrcweir             }
102cdf0e10cSrcweir 		};
103cdf0e10cSrcweir 
SdrFillAttribute(double fTransparence,const basegfx::BColor & rColor,const FillGradientAttribute & rGradient,const FillHatchAttribute & rHatch,const SdrFillGraphicAttribute & rFillGraphic)104cdf0e10cSrcweir         SdrFillAttribute::SdrFillAttribute(
105cdf0e10cSrcweir 			double fTransparence,
106cdf0e10cSrcweir             const basegfx::BColor& rColor,
107cdf0e10cSrcweir             const FillGradientAttribute& rGradient,
108cdf0e10cSrcweir 			const FillHatchAttribute& rHatch,
109*035a2f44SArmin Le Grand             const SdrFillGraphicAttribute& rFillGraphic)
110*035a2f44SArmin Le Grand 		:	mpSdrFillAttribute(
111*035a2f44SArmin Le Grand                 new ImpSdrFillAttribute(
112*035a2f44SArmin Le Grand                     fTransparence, rColor, rGradient, rHatch, rFillGraphic))
113cdf0e10cSrcweir 		{
114cdf0e10cSrcweir 		}
115cdf0e10cSrcweir 
SdrFillAttribute()116cdf0e10cSrcweir 		SdrFillAttribute::SdrFillAttribute()
117cdf0e10cSrcweir         :	mpSdrFillAttribute(ImpSdrFillAttribute::get_global_default())
118cdf0e10cSrcweir 		{
119cdf0e10cSrcweir 			mpSdrFillAttribute->mnRefCount++;
120cdf0e10cSrcweir 		}
121cdf0e10cSrcweir 
SdrFillAttribute(const SdrFillAttribute & rCandidate)122cdf0e10cSrcweir         SdrFillAttribute::SdrFillAttribute(const SdrFillAttribute& rCandidate)
123cdf0e10cSrcweir 		:	mpSdrFillAttribute(rCandidate.mpSdrFillAttribute)
124cdf0e10cSrcweir 		{
125cdf0e10cSrcweir 			mpSdrFillAttribute->mnRefCount++;
126cdf0e10cSrcweir 		}
127cdf0e10cSrcweir 
~SdrFillAttribute()128cdf0e10cSrcweir 		SdrFillAttribute::~SdrFillAttribute()
129cdf0e10cSrcweir 		{
130cdf0e10cSrcweir 			if(mpSdrFillAttribute->mnRefCount)
131cdf0e10cSrcweir 			{
132cdf0e10cSrcweir 				mpSdrFillAttribute->mnRefCount--;
133cdf0e10cSrcweir 			}
134cdf0e10cSrcweir 			else
135cdf0e10cSrcweir 			{
136cdf0e10cSrcweir 				delete mpSdrFillAttribute;
137cdf0e10cSrcweir 			}
138cdf0e10cSrcweir 		}
139cdf0e10cSrcweir 
isDefault() const140cdf0e10cSrcweir         bool SdrFillAttribute::isDefault() const
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             return mpSdrFillAttribute == ImpSdrFillAttribute::get_global_default();
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
operator =(const SdrFillAttribute & rCandidate)145cdf0e10cSrcweir         SdrFillAttribute& SdrFillAttribute::operator=(const SdrFillAttribute& rCandidate)
146cdf0e10cSrcweir 		{
147cdf0e10cSrcweir 			if(rCandidate.mpSdrFillAttribute != mpSdrFillAttribute)
148cdf0e10cSrcweir 			{
149cdf0e10cSrcweir 				if(mpSdrFillAttribute->mnRefCount)
150cdf0e10cSrcweir 				{
151cdf0e10cSrcweir 					mpSdrFillAttribute->mnRefCount--;
152cdf0e10cSrcweir 				}
153cdf0e10cSrcweir 				else
154cdf0e10cSrcweir 				{
155cdf0e10cSrcweir 					delete mpSdrFillAttribute;
156cdf0e10cSrcweir 				}
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 				mpSdrFillAttribute = rCandidate.mpSdrFillAttribute;
159cdf0e10cSrcweir 				mpSdrFillAttribute->mnRefCount++;
160cdf0e10cSrcweir 			}
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 			return *this;
163cdf0e10cSrcweir 		}
164cdf0e10cSrcweir 
operator ==(const SdrFillAttribute & rCandidate) const165cdf0e10cSrcweir 		bool SdrFillAttribute::operator==(const SdrFillAttribute& rCandidate) const
166cdf0e10cSrcweir 		{
167cdf0e10cSrcweir 			if(rCandidate.mpSdrFillAttribute == mpSdrFillAttribute)
168cdf0e10cSrcweir 			{
169cdf0e10cSrcweir 				return true;
170cdf0e10cSrcweir 			}
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
173cdf0e10cSrcweir 			{
174cdf0e10cSrcweir 				return false;
175cdf0e10cSrcweir 			}
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 			return (*rCandidate.mpSdrFillAttribute == *mpSdrFillAttribute);
178cdf0e10cSrcweir 		}
179cdf0e10cSrcweir 
getTransparence() const180cdf0e10cSrcweir 		double SdrFillAttribute::getTransparence() const
181cdf0e10cSrcweir         {
182cdf0e10cSrcweir             return mpSdrFillAttribute->getTransparence();
183cdf0e10cSrcweir         }
184cdf0e10cSrcweir 
getColor() const185cdf0e10cSrcweir 		const basegfx::BColor& SdrFillAttribute::getColor() const
186cdf0e10cSrcweir         {
187cdf0e10cSrcweir             return mpSdrFillAttribute->getColor();
188cdf0e10cSrcweir         }
189cdf0e10cSrcweir 
getGradient() const190cdf0e10cSrcweir 		const FillGradientAttribute& SdrFillAttribute::getGradient() const
191cdf0e10cSrcweir         {
192cdf0e10cSrcweir             return mpSdrFillAttribute->getGradient();
193cdf0e10cSrcweir         }
194cdf0e10cSrcweir 
getHatch() const195cdf0e10cSrcweir 		const FillHatchAttribute& SdrFillAttribute::getHatch() const
196cdf0e10cSrcweir         {
197cdf0e10cSrcweir             return mpSdrFillAttribute->getHatch();
198cdf0e10cSrcweir         }
199cdf0e10cSrcweir 
getFillGraphic() const200*035a2f44SArmin Le Grand 		const SdrFillGraphicAttribute& SdrFillAttribute::getFillGraphic() const
201cdf0e10cSrcweir         {
202*035a2f44SArmin Le Grand             return mpSdrFillAttribute->getFillGraphic();
203cdf0e10cSrcweir         }
204cdf0e10cSrcweir     } // end of namespace attribute
205cdf0e10cSrcweir } // end of namespace drawinglayer
206cdf0e10cSrcweir 
207cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
208cdf0e10cSrcweir // eof
209