xref: /trunk/main/drawinglayer/source/attribute/sdrfillattribute.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  *  OpenOffice.org - a multi-platform office productivity suite
4  *
5  *  $RCSfile: sdrattribute.cxx,v $
6  *
7  *  $Revision: 1.5 $
8  *
9  *  last change: $Author: aw $ $Date: 2008-05-27 14:11:19 $
10  *
11  *  The Contents of this file are made available subject to
12  *  the terms of GNU Lesser General Public License Version 2.1.
13  *
14  *
15  *    GNU Lesser General Public License Version 2.1
16  *    =============================================
17  *    Copyright 2005 by Sun Microsystems, Inc.
18  *    901 San Antonio Road, Palo Alto, CA 94303, USA
19  *
20  *    This library is free software; you can redistribute it and/or
21  *    modify it under the terms of the GNU Lesser General Public
22  *    License version 2.1, as published by the Free Software Foundation.
23  *
24  *    This library is distributed in the hope that it will be useful,
25  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27  *    Lesser General Public License for more details.
28  *
29  *    You should have received a copy of the GNU Lesser General Public
30  *    License along with this library; if not, write to the Free Software
31  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32  *    MA  02111-1307  USA
33  *
34  ************************************************************************/
35 
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
38 
39 #include <drawinglayer/attribute/sdrfillattribute.hxx>
40 #include <basegfx/color/bcolor.hxx>
41 #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx>
42 #include <drawinglayer/attribute/fillhatchattribute.hxx>
43 #include <drawinglayer/attribute/fillgradientattribute.hxx>
44 
45 //////////////////////////////////////////////////////////////////////////////
46 
47 namespace drawinglayer
48 {
49     namespace attribute
50     {
51         class ImpSdrFillAttribute
52         {
53         public:
54             // refcounter
55             sal_uInt32                          mnRefCount;
56 
57             // fill definitions
58             double                              mfTransparence;     // [0.0 .. 1.0], 0.0==no transp.
59             basegfx::BColor                     maColor;            // fill color
60             FillGradientAttribute               maGradient;         // fill gradient (if used)
61             FillHatchAttribute                  maHatch;            // fill hatch (if used)
62             SdrFillBitmapAttribute              maBitmap;           // fill bitmap (if used)
63 
64         public:
65             ImpSdrFillAttribute(
66                 double fTransparence,
67                 const basegfx::BColor& rColor,
68                 const FillGradientAttribute& rGradient,
69                 const FillHatchAttribute& rHatch,
70                 const SdrFillBitmapAttribute& rBitmap)
71             :   mnRefCount(0),
72                 mfTransparence(fTransparence),
73                 maColor(rColor),
74                 maGradient(rGradient),
75                 maHatch(rHatch),
76                 maBitmap(rBitmap)
77             {
78             }
79 
80             // data read access
81             double getTransparence() const { return mfTransparence; }
82             const basegfx::BColor& getColor() const { return maColor; }
83             const FillGradientAttribute& getGradient() const { return maGradient; }
84             const FillHatchAttribute& getHatch() const { return maHatch; }
85             const SdrFillBitmapAttribute& getBitmap() const { return maBitmap; }
86 
87             // compare operator
88             bool operator==(const ImpSdrFillAttribute& rCandidate) const
89             {
90                 return(getTransparence() == rCandidate.getTransparence()
91                     && getColor() == rCandidate.getColor()
92                     && getGradient() == rCandidate.getGradient()
93                     && getHatch() == rCandidate.getHatch()
94                     && getBitmap() == rCandidate.getBitmap());
95             }
96 
97             static ImpSdrFillAttribute* get_global_default()
98             {
99                 static ImpSdrFillAttribute* pDefault = 0;
100 
101                 if(!pDefault)
102                 {
103                     pDefault = new ImpSdrFillAttribute(
104                         0.0,
105                         basegfx::BColor(),
106                         FillGradientAttribute(),
107                         FillHatchAttribute(),
108                         SdrFillBitmapAttribute());
109 
110                     // never delete; start with RefCount 1, not 0
111                     pDefault->mnRefCount++;
112                 }
113 
114                 return pDefault;
115             }
116         };
117 
118         SdrFillAttribute::SdrFillAttribute(
119             double fTransparence,
120             const basegfx::BColor& rColor,
121             const FillGradientAttribute& rGradient,
122             const FillHatchAttribute& rHatch,
123             const SdrFillBitmapAttribute& rBitmap)
124         :   mpSdrFillAttribute(new ImpSdrFillAttribute(
125                 fTransparence, rColor, rGradient, rHatch, rBitmap))
126         {
127         }
128 
129         SdrFillAttribute::SdrFillAttribute()
130         :   mpSdrFillAttribute(ImpSdrFillAttribute::get_global_default())
131         {
132             mpSdrFillAttribute->mnRefCount++;
133         }
134 
135         SdrFillAttribute::SdrFillAttribute(const SdrFillAttribute& rCandidate)
136         :   mpSdrFillAttribute(rCandidate.mpSdrFillAttribute)
137         {
138             mpSdrFillAttribute->mnRefCount++;
139         }
140 
141         SdrFillAttribute::~SdrFillAttribute()
142         {
143             if(mpSdrFillAttribute->mnRefCount)
144             {
145                 mpSdrFillAttribute->mnRefCount--;
146             }
147             else
148             {
149                 delete mpSdrFillAttribute;
150             }
151         }
152 
153         bool SdrFillAttribute::isDefault() const
154         {
155             return mpSdrFillAttribute == ImpSdrFillAttribute::get_global_default();
156         }
157 
158         SdrFillAttribute& SdrFillAttribute::operator=(const SdrFillAttribute& rCandidate)
159         {
160             if(rCandidate.mpSdrFillAttribute != mpSdrFillAttribute)
161             {
162                 if(mpSdrFillAttribute->mnRefCount)
163                 {
164                     mpSdrFillAttribute->mnRefCount--;
165                 }
166                 else
167                 {
168                     delete mpSdrFillAttribute;
169                 }
170 
171                 mpSdrFillAttribute = rCandidate.mpSdrFillAttribute;
172                 mpSdrFillAttribute->mnRefCount++;
173             }
174 
175             return *this;
176         }
177 
178         bool SdrFillAttribute::operator==(const SdrFillAttribute& rCandidate) const
179         {
180             if(rCandidate.mpSdrFillAttribute == mpSdrFillAttribute)
181             {
182                 return true;
183             }
184 
185             if(rCandidate.isDefault() != isDefault())
186             {
187                 return false;
188             }
189 
190             return (*rCandidate.mpSdrFillAttribute == *mpSdrFillAttribute);
191         }
192 
193         double SdrFillAttribute::getTransparence() const
194         {
195             return mpSdrFillAttribute->getTransparence();
196         }
197 
198         const basegfx::BColor& SdrFillAttribute::getColor() const
199         {
200             return mpSdrFillAttribute->getColor();
201         }
202 
203         const FillGradientAttribute& SdrFillAttribute::getGradient() const
204         {
205             return mpSdrFillAttribute->getGradient();
206         }
207 
208         const FillHatchAttribute& SdrFillAttribute::getHatch() const
209         {
210             return mpSdrFillAttribute->getHatch();
211         }
212 
213         const SdrFillBitmapAttribute& SdrFillAttribute::getBitmap() const
214         {
215             return mpSdrFillAttribute->getBitmap();
216         }
217     } // end of namespace attribute
218 } // end of namespace drawinglayer
219 
220 //////////////////////////////////////////////////////////////////////////////
221 // eof
222