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/sdrshadowattribute.hxx> 40 #include <basegfx/vector/b2dvector.hxx> 41 #include <basegfx/color/bcolor.hxx> 42 43 ////////////////////////////////////////////////////////////////////////////// 44 45 namespace drawinglayer 46 { 47 namespace attribute 48 { 49 class ImpSdrShadowAttribute 50 { 51 public: 52 // refcounter 53 sal_uInt32 mnRefCount; 54 55 // shadow definitions 56 basegfx::B2DVector maOffset; // shadow offset 1/100th mm 57 double mfTransparence; // [0.0 .. 1.0], 0.0==no transp. 58 basegfx::BColor maColor; // color of shadow 59 60 ImpSdrShadowAttribute( 61 const basegfx::B2DVector& rOffset, 62 double fTransparence, 63 const basegfx::BColor& rColor) 64 : mnRefCount(0), 65 maOffset(rOffset), 66 mfTransparence(fTransparence), 67 maColor(rColor) 68 { 69 } 70 71 // data read access 72 const basegfx::B2DVector& getOffset() const { return maOffset; } 73 double getTransparence() const { return mfTransparence; } 74 const basegfx::BColor& getColor() const { return maColor; } 75 76 bool operator==(const ImpSdrShadowAttribute& rCandidate) const 77 { 78 return (getOffset() == rCandidate.getOffset() 79 && getTransparence() == rCandidate.getTransparence() 80 && getColor() == rCandidate.getColor()); 81 } 82 83 static ImpSdrShadowAttribute* get_global_default() 84 { 85 static ImpSdrShadowAttribute* pDefault = 0; 86 87 if(!pDefault) 88 { 89 pDefault = new ImpSdrShadowAttribute( 90 basegfx::B2DVector(), 91 0.0, 92 basegfx::BColor()); 93 94 // never delete; start with RefCount 1, not 0 95 pDefault->mnRefCount++; 96 } 97 98 return pDefault; 99 } 100 }; 101 102 SdrShadowAttribute::SdrShadowAttribute( 103 const basegfx::B2DVector& rOffset, 104 double fTransparence, 105 const basegfx::BColor& rColor) 106 : mpSdrShadowAttribute(new ImpSdrShadowAttribute( 107 rOffset, fTransparence, rColor)) 108 { 109 } 110 111 SdrShadowAttribute::SdrShadowAttribute() 112 : mpSdrShadowAttribute(ImpSdrShadowAttribute::get_global_default()) 113 { 114 mpSdrShadowAttribute->mnRefCount++; 115 } 116 117 SdrShadowAttribute::SdrShadowAttribute(const SdrShadowAttribute& rCandidate) 118 : mpSdrShadowAttribute(rCandidate.mpSdrShadowAttribute) 119 { 120 mpSdrShadowAttribute->mnRefCount++; 121 } 122 123 SdrShadowAttribute::~SdrShadowAttribute() 124 { 125 if(mpSdrShadowAttribute->mnRefCount) 126 { 127 mpSdrShadowAttribute->mnRefCount--; 128 } 129 else 130 { 131 delete mpSdrShadowAttribute; 132 } 133 } 134 135 bool SdrShadowAttribute::isDefault() const 136 { 137 return mpSdrShadowAttribute == ImpSdrShadowAttribute::get_global_default(); 138 } 139 140 SdrShadowAttribute& SdrShadowAttribute::operator=(const SdrShadowAttribute& rCandidate) 141 { 142 if(rCandidate.mpSdrShadowAttribute != mpSdrShadowAttribute) 143 { 144 if(mpSdrShadowAttribute->mnRefCount) 145 { 146 mpSdrShadowAttribute->mnRefCount--; 147 } 148 else 149 { 150 delete mpSdrShadowAttribute; 151 } 152 153 mpSdrShadowAttribute = rCandidate.mpSdrShadowAttribute; 154 mpSdrShadowAttribute->mnRefCount++; 155 } 156 157 return *this; 158 } 159 160 bool SdrShadowAttribute::operator==(const SdrShadowAttribute& rCandidate) const 161 { 162 if(rCandidate.mpSdrShadowAttribute == mpSdrShadowAttribute) 163 { 164 return true; 165 } 166 167 if(rCandidate.isDefault() != isDefault()) 168 { 169 return false; 170 } 171 172 return (*rCandidate.mpSdrShadowAttribute == *mpSdrShadowAttribute); 173 } 174 175 const basegfx::B2DVector& SdrShadowAttribute::getOffset() const 176 { 177 return mpSdrShadowAttribute->getOffset(); 178 } 179 180 double SdrShadowAttribute::getTransparence() const 181 { 182 return mpSdrShadowAttribute->getTransparence(); 183 } 184 185 const basegfx::BColor& SdrShadowAttribute::getColor() const 186 { 187 return mpSdrShadowAttribute->getColor(); 188 } 189 } // end of namespace attribute 190 } // end of namespace drawinglayer 191 192 ////////////////////////////////////////////////////////////////////////////// 193 // eof 194