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/sdrlineattribute.hxx> 40 #include <basegfx/color/bcolor.hxx> 41 42 ////////////////////////////////////////////////////////////////////////////// 43 44 namespace drawinglayer 45 { 46 namespace attribute 47 { 48 class ImpSdrLineAttribute 49 { 50 public: 51 // refcounter 52 sal_uInt32 mnRefCount; 53 54 // line definitions 55 basegfx::B2DLineJoin meJoin; // B2DLINEJOIN_* defines 56 double mfWidth; // 1/100th mm, 0.0==hair 57 double mfTransparence; // [0.0 .. 1.0], 0.0==no transp. 58 basegfx::BColor maColor; // color of line 59 ::std::vector< double > maDotDashArray; // array of double which defines the dot-dash pattern 60 double mfFullDotDashLen; // sum of maDotDashArray (for convenience) 61 62 ImpSdrLineAttribute( 63 basegfx::B2DLineJoin eJoin, 64 double fWidth, 65 double fTransparence, 66 const basegfx::BColor& rColor, 67 const ::std::vector< double >& rDotDashArray, 68 double fFullDotDashLen) 69 : mnRefCount(0), 70 meJoin(eJoin), 71 mfWidth(fWidth), 72 mfTransparence(fTransparence), 73 maColor(rColor), 74 maDotDashArray(rDotDashArray), 75 mfFullDotDashLen(fFullDotDashLen) 76 { 77 } 78 79 ImpSdrLineAttribute(const basegfx::BColor& rColor) 80 : mnRefCount(0), 81 meJoin(basegfx::B2DLINEJOIN_NONE), 82 mfWidth(0.0), 83 mfTransparence(0.0), 84 maColor(rColor), 85 maDotDashArray(), 86 mfFullDotDashLen(0.0) 87 { 88 } 89 90 // data read access 91 basegfx::B2DLineJoin getJoin() const { return meJoin; } 92 double getWidth() const { return mfWidth; } 93 double getTransparence() const { return mfTransparence; } 94 const basegfx::BColor& getColor() const { return maColor; } 95 const ::std::vector< double >& getDotDashArray() const { return maDotDashArray; } 96 double getFullDotDashLen() const { return mfFullDotDashLen; } 97 98 bool operator==(const ImpSdrLineAttribute& rCandidate) const 99 { 100 return (getJoin() == rCandidate.getJoin() 101 && getWidth() == rCandidate.getWidth() 102 && getTransparence() == rCandidate.getTransparence() 103 && getColor() == rCandidate.getColor() 104 && getDotDashArray() == rCandidate.getDotDashArray()); 105 } 106 107 static ImpSdrLineAttribute* get_global_default() 108 { 109 static ImpSdrLineAttribute* pDefault = 0; 110 111 if(!pDefault) 112 { 113 pDefault = new ImpSdrLineAttribute( 114 basegfx::B2DLINEJOIN_ROUND, 115 0.0, 116 0.0, 117 basegfx::BColor(), 118 std::vector< double >(), 119 0.0); 120 121 // never delete; start with RefCount 1, not 0 122 pDefault->mnRefCount++; 123 } 124 125 return pDefault; 126 } 127 }; 128 129 SdrLineAttribute::SdrLineAttribute( 130 basegfx::B2DLineJoin eJoin, 131 double fWidth, 132 double fTransparence, 133 const basegfx::BColor& rColor, 134 const ::std::vector< double >& rDotDashArray, 135 double fFullDotDashLen) 136 : mpSdrLineAttribute(new ImpSdrLineAttribute( 137 eJoin, fWidth, fTransparence, rColor, rDotDashArray, fFullDotDashLen)) 138 { 139 } 140 141 SdrLineAttribute::SdrLineAttribute( 142 const basegfx::BColor& rColor) 143 : mpSdrLineAttribute(new ImpSdrLineAttribute(rColor)) 144 { 145 } 146 147 SdrLineAttribute::SdrLineAttribute() 148 : mpSdrLineAttribute(ImpSdrLineAttribute::get_global_default()) 149 { 150 mpSdrLineAttribute->mnRefCount++; 151 } 152 153 SdrLineAttribute::SdrLineAttribute(const SdrLineAttribute& rCandidate) 154 : mpSdrLineAttribute(rCandidate.mpSdrLineAttribute) 155 { 156 mpSdrLineAttribute->mnRefCount++; 157 } 158 159 SdrLineAttribute::~SdrLineAttribute() 160 { 161 if(mpSdrLineAttribute->mnRefCount) 162 { 163 mpSdrLineAttribute->mnRefCount--; 164 } 165 else 166 { 167 delete mpSdrLineAttribute; 168 } 169 } 170 171 bool SdrLineAttribute::isDefault() const 172 { 173 return mpSdrLineAttribute == ImpSdrLineAttribute::get_global_default(); 174 } 175 176 SdrLineAttribute& SdrLineAttribute::operator=(const SdrLineAttribute& rCandidate) 177 { 178 if(rCandidate.mpSdrLineAttribute != mpSdrLineAttribute) 179 { 180 if(mpSdrLineAttribute->mnRefCount) 181 { 182 mpSdrLineAttribute->mnRefCount--; 183 } 184 else 185 { 186 delete mpSdrLineAttribute; 187 } 188 189 mpSdrLineAttribute = rCandidate.mpSdrLineAttribute; 190 mpSdrLineAttribute->mnRefCount++; 191 } 192 193 return *this; 194 } 195 196 bool SdrLineAttribute::operator==(const SdrLineAttribute& rCandidate) const 197 { 198 if(rCandidate.mpSdrLineAttribute == mpSdrLineAttribute) 199 { 200 return true; 201 } 202 203 if(rCandidate.isDefault() != isDefault()) 204 { 205 return false; 206 } 207 208 return (*rCandidate.mpSdrLineAttribute == *mpSdrLineAttribute); 209 } 210 211 basegfx::B2DLineJoin SdrLineAttribute::getJoin() const 212 { 213 return mpSdrLineAttribute->getJoin(); 214 } 215 216 double SdrLineAttribute::getWidth() const 217 { 218 return mpSdrLineAttribute->getWidth(); 219 } 220 221 double SdrLineAttribute::getTransparence() const 222 { 223 return mpSdrLineAttribute->getTransparence(); 224 } 225 226 const basegfx::BColor& SdrLineAttribute::getColor() const 227 { 228 return mpSdrLineAttribute->getColor(); 229 } 230 231 const ::std::vector< double >& SdrLineAttribute::getDotDashArray() const 232 { 233 return mpSdrLineAttribute->getDotDashArray(); 234 } 235 236 double SdrLineAttribute::getFullDotDashLen() const 237 { 238 return mpSdrLineAttribute->getFullDotDashLen(); 239 } 240 241 bool SdrLineAttribute::isDashed() const 242 { 243 return (0L != getDotDashArray().size()); 244 } 245 246 } // end of namespace attribute 247 } // end of namespace drawinglayer 248 249 ////////////////////////////////////////////////////////////////////////////// 250 // eof 251