1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_drawinglayer.hxx" 30 31 #include <drawinglayer/attribute/lineattribute.hxx> 32 #include <basegfx/color/bcolor.hxx> 33 34 ////////////////////////////////////////////////////////////////////////////// 35 36 namespace drawinglayer 37 { 38 namespace attribute 39 { 40 class ImpLineAttribute 41 { 42 public: 43 // refcounter 44 sal_uInt32 mnRefCount; 45 46 // data definitions 47 basegfx::BColor maColor; // color 48 double mfWidth; // absolute line width 49 basegfx::B2DLineJoin meLineJoin; // type of LineJoin 50 51 ImpLineAttribute( 52 const basegfx::BColor& rColor, 53 double fWidth, 54 basegfx::B2DLineJoin aB2DLineJoin) 55 : mnRefCount(0), 56 maColor(rColor), 57 mfWidth(fWidth), 58 meLineJoin(aB2DLineJoin) 59 { 60 } 61 62 // data read access 63 const basegfx::BColor& getColor() const { return maColor; } 64 double getWidth() const { return mfWidth; } 65 basegfx::B2DLineJoin getLineJoin() const { return meLineJoin; } 66 67 bool operator==(const ImpLineAttribute& rCandidate) const 68 { 69 return (getColor() == rCandidate.getColor() 70 && getWidth() == rCandidate.getWidth() 71 && getLineJoin() == rCandidate.getLineJoin()); 72 } 73 74 static ImpLineAttribute* get_global_default() 75 { 76 static ImpLineAttribute* pDefault = 0; 77 78 if(!pDefault) 79 { 80 pDefault = new ImpLineAttribute( 81 basegfx::BColor(), 82 0.0, 83 basegfx::B2DLINEJOIN_ROUND); 84 85 // never delete; start with RefCount 1, not 0 86 pDefault->mnRefCount++; 87 } 88 89 return pDefault; 90 } 91 }; 92 93 LineAttribute::LineAttribute( 94 const basegfx::BColor& rColor, 95 double fWidth, 96 basegfx::B2DLineJoin aB2DLineJoin) 97 : mpLineAttribute(new ImpLineAttribute( 98 rColor, fWidth, aB2DLineJoin)) 99 { 100 } 101 102 LineAttribute::LineAttribute() 103 : mpLineAttribute(ImpLineAttribute::get_global_default()) 104 { 105 mpLineAttribute->mnRefCount++; 106 } 107 108 LineAttribute::LineAttribute(const LineAttribute& rCandidate) 109 : mpLineAttribute(rCandidate.mpLineAttribute) 110 { 111 mpLineAttribute->mnRefCount++; 112 } 113 114 LineAttribute::~LineAttribute() 115 { 116 if(mpLineAttribute->mnRefCount) 117 { 118 mpLineAttribute->mnRefCount--; 119 } 120 else 121 { 122 delete mpLineAttribute; 123 } 124 } 125 126 bool LineAttribute::isDefault() const 127 { 128 return mpLineAttribute == ImpLineAttribute::get_global_default(); 129 } 130 131 LineAttribute& LineAttribute::operator=(const LineAttribute& rCandidate) 132 { 133 if(rCandidate.mpLineAttribute != mpLineAttribute) 134 { 135 if(mpLineAttribute->mnRefCount) 136 { 137 mpLineAttribute->mnRefCount--; 138 } 139 else 140 { 141 delete mpLineAttribute; 142 } 143 144 mpLineAttribute = rCandidate.mpLineAttribute; 145 mpLineAttribute->mnRefCount++; 146 } 147 148 return *this; 149 } 150 151 bool LineAttribute::operator==(const LineAttribute& rCandidate) const 152 { 153 if(rCandidate.mpLineAttribute == mpLineAttribute) 154 { 155 return true; 156 } 157 158 if(rCandidate.isDefault() != isDefault()) 159 { 160 return false; 161 } 162 163 return (*rCandidate.mpLineAttribute == *mpLineAttribute); 164 } 165 166 const basegfx::BColor& LineAttribute::getColor() const 167 { 168 return mpLineAttribute->getColor(); 169 } 170 171 double LineAttribute::getWidth() const 172 { 173 return mpLineAttribute->getWidth(); 174 } 175 176 basegfx::B2DLineJoin LineAttribute::getLineJoin() const 177 { 178 return mpLineAttribute->getLineJoin(); 179 } 180 181 } // end of namespace attribute 182 } // end of namespace drawinglayer 183 184 ////////////////////////////////////////////////////////////////////////////// 185 // eof 186