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