xref: /AOO41X/main/drawinglayer/source/attribute/sdrfillattribute.cxx (revision 4bfbcde8d64cc5d114df10dce4a9ed79eff32278)
1*4bfbcde8SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*4bfbcde8SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*4bfbcde8SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*4bfbcde8SAndrew Rist  * distributed with this work for additional information
6*4bfbcde8SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*4bfbcde8SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*4bfbcde8SAndrew Rist  * "License"); you may not use this file except in compliance
9*4bfbcde8SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*4bfbcde8SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*4bfbcde8SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*4bfbcde8SAndrew Rist  * software distributed under the License is distributed on an
15*4bfbcde8SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*4bfbcde8SAndrew Rist  * KIND, either express or implied.  See the License for the
17*4bfbcde8SAndrew Rist  * specific language governing permissions and limitations
18*4bfbcde8SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*4bfbcde8SAndrew 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>
27cdf0e10cSrcweir #include <drawinglayer/attribute/sdrfillbitmapattribute.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)
48cdf0e10cSrcweir 			SdrFillBitmapAttribute				maBitmap;			// fill bitmap (if used)
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 		public:
51cdf0e10cSrcweir 			ImpSdrFillAttribute(
52cdf0e10cSrcweir 				double fTransparence,
53cdf0e10cSrcweir                 const basegfx::BColor& rColor,
54cdf0e10cSrcweir                 const FillGradientAttribute& rGradient,
55cdf0e10cSrcweir 				const FillHatchAttribute& rHatch,
56cdf0e10cSrcweir                 const SdrFillBitmapAttribute& rBitmap)
57cdf0e10cSrcweir 			:	mnRefCount(0),
58cdf0e10cSrcweir 			    mfTransparence(fTransparence),
59cdf0e10cSrcweir 			    maColor(rColor),
60cdf0e10cSrcweir 			    maGradient(rGradient),
61cdf0e10cSrcweir 			    maHatch(rHatch),
62cdf0e10cSrcweir 			    maBitmap(rBitmap)
63cdf0e10cSrcweir             {
64cdf0e10cSrcweir             }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 			// data read access
67cdf0e10cSrcweir 			double getTransparence() const { return mfTransparence;	}
68cdf0e10cSrcweir 			const basegfx::BColor& getColor() const { return maColor; }
69cdf0e10cSrcweir 			const FillGradientAttribute& getGradient() const { return maGradient; }
70cdf0e10cSrcweir 			const FillHatchAttribute& getHatch() const { return maHatch; }
71cdf0e10cSrcweir 			const SdrFillBitmapAttribute& getBitmap() const { return maBitmap; }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir             // compare operator
74cdf0e10cSrcweir 			bool operator==(const ImpSdrFillAttribute& rCandidate) const
75cdf0e10cSrcweir             {
76cdf0e10cSrcweir                 return(getTransparence() == rCandidate.getTransparence()
77cdf0e10cSrcweir                     && getColor() == rCandidate.getColor()
78cdf0e10cSrcweir                     && getGradient() == rCandidate.getGradient()
79cdf0e10cSrcweir                     && getHatch() == rCandidate.getHatch()
80cdf0e10cSrcweir                     && getBitmap() == rCandidate.getBitmap());
81cdf0e10cSrcweir             }
82cdf0e10cSrcweir 
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(),
94cdf0e10cSrcweir                         SdrFillBitmapAttribute());
95cdf0e10cSrcweir 
96cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
97cdf0e10cSrcweir     			    pDefault->mnRefCount++;
98cdf0e10cSrcweir                 }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir                 return pDefault;
101cdf0e10cSrcweir             }
102cdf0e10cSrcweir 		};
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         SdrFillAttribute::SdrFillAttribute(
105cdf0e10cSrcweir 			double fTransparence,
106cdf0e10cSrcweir             const basegfx::BColor& rColor,
107cdf0e10cSrcweir             const FillGradientAttribute& rGradient,
108cdf0e10cSrcweir 			const FillHatchAttribute& rHatch,
109cdf0e10cSrcweir             const SdrFillBitmapAttribute& rBitmap)
110cdf0e10cSrcweir 		:	mpSdrFillAttribute(new ImpSdrFillAttribute(
111cdf0e10cSrcweir                 fTransparence, rColor, rGradient, rHatch, rBitmap))
112cdf0e10cSrcweir 		{
113cdf0e10cSrcweir 		}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 		SdrFillAttribute::SdrFillAttribute()
116cdf0e10cSrcweir         :	mpSdrFillAttribute(ImpSdrFillAttribute::get_global_default())
117cdf0e10cSrcweir 		{
118cdf0e10cSrcweir 			mpSdrFillAttribute->mnRefCount++;
119cdf0e10cSrcweir 		}
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         SdrFillAttribute::SdrFillAttribute(const SdrFillAttribute& rCandidate)
122cdf0e10cSrcweir 		:	mpSdrFillAttribute(rCandidate.mpSdrFillAttribute)
123cdf0e10cSrcweir 		{
124cdf0e10cSrcweir 			mpSdrFillAttribute->mnRefCount++;
125cdf0e10cSrcweir 		}
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 		SdrFillAttribute::~SdrFillAttribute()
128cdf0e10cSrcweir 		{
129cdf0e10cSrcweir 			if(mpSdrFillAttribute->mnRefCount)
130cdf0e10cSrcweir 			{
131cdf0e10cSrcweir 				mpSdrFillAttribute->mnRefCount--;
132cdf0e10cSrcweir 			}
133cdf0e10cSrcweir 			else
134cdf0e10cSrcweir 			{
135cdf0e10cSrcweir 				delete mpSdrFillAttribute;
136cdf0e10cSrcweir 			}
137cdf0e10cSrcweir 		}
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         bool SdrFillAttribute::isDefault() const
140cdf0e10cSrcweir         {
141cdf0e10cSrcweir             return mpSdrFillAttribute == ImpSdrFillAttribute::get_global_default();
142cdf0e10cSrcweir         }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         SdrFillAttribute& SdrFillAttribute::operator=(const SdrFillAttribute& rCandidate)
145cdf0e10cSrcweir 		{
146cdf0e10cSrcweir 			if(rCandidate.mpSdrFillAttribute != mpSdrFillAttribute)
147cdf0e10cSrcweir 			{
148cdf0e10cSrcweir 				if(mpSdrFillAttribute->mnRefCount)
149cdf0e10cSrcweir 				{
150cdf0e10cSrcweir 					mpSdrFillAttribute->mnRefCount--;
151cdf0e10cSrcweir 				}
152cdf0e10cSrcweir 				else
153cdf0e10cSrcweir 				{
154cdf0e10cSrcweir 					delete mpSdrFillAttribute;
155cdf0e10cSrcweir 				}
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 				mpSdrFillAttribute = rCandidate.mpSdrFillAttribute;
158cdf0e10cSrcweir 				mpSdrFillAttribute->mnRefCount++;
159cdf0e10cSrcweir 			}
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 			return *this;
162cdf0e10cSrcweir 		}
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		bool SdrFillAttribute::operator==(const SdrFillAttribute& rCandidate) const
165cdf0e10cSrcweir 		{
166cdf0e10cSrcweir 			if(rCandidate.mpSdrFillAttribute == mpSdrFillAttribute)
167cdf0e10cSrcweir 			{
168cdf0e10cSrcweir 				return true;
169cdf0e10cSrcweir 			}
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
172cdf0e10cSrcweir 			{
173cdf0e10cSrcweir 				return false;
174cdf0e10cSrcweir 			}
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 			return (*rCandidate.mpSdrFillAttribute == *mpSdrFillAttribute);
177cdf0e10cSrcweir 		}
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 		double SdrFillAttribute::getTransparence() const
180cdf0e10cSrcweir         {
181cdf0e10cSrcweir             return mpSdrFillAttribute->getTransparence();
182cdf0e10cSrcweir         }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 		const basegfx::BColor& SdrFillAttribute::getColor() const
185cdf0e10cSrcweir         {
186cdf0e10cSrcweir             return mpSdrFillAttribute->getColor();
187cdf0e10cSrcweir         }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 		const FillGradientAttribute& SdrFillAttribute::getGradient() const
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir             return mpSdrFillAttribute->getGradient();
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 		const FillHatchAttribute& SdrFillAttribute::getHatch() const
195cdf0e10cSrcweir         {
196cdf0e10cSrcweir             return mpSdrFillAttribute->getHatch();
197cdf0e10cSrcweir         }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 		const SdrFillBitmapAttribute& SdrFillAttribute::getBitmap() const
200cdf0e10cSrcweir         {
201cdf0e10cSrcweir             return mpSdrFillAttribute->getBitmap();
202cdf0e10cSrcweir         }
203cdf0e10cSrcweir     } // end of namespace attribute
204cdf0e10cSrcweir } // end of namespace drawinglayer
205cdf0e10cSrcweir 
206cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
207cdf0e10cSrcweir // eof
208