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