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/sdrlinestartendattribute.hxx> 40*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir namespace drawinglayer 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir namespace attribute 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir class ImpSdrLineStartEndAttribute 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir public: 51*cdf0e10cSrcweir // refcounter 52*cdf0e10cSrcweir sal_uInt32 mnRefCount; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir // line arrow definitions 55*cdf0e10cSrcweir basegfx::B2DPolyPolygon maStartPolyPolygon; // start Line PolyPolygon 56*cdf0e10cSrcweir basegfx::B2DPolyPolygon maEndPolyPolygon; // end Line PolyPolygon 57*cdf0e10cSrcweir double mfStartWidth; // 1/100th mm 58*cdf0e10cSrcweir double mfEndWidth; // 1/100th mm 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // bitfield 61*cdf0e10cSrcweir unsigned mbStartActive : 1L; // start of Line is active 62*cdf0e10cSrcweir unsigned mbEndActive : 1L; // end of Line is active 63*cdf0e10cSrcweir unsigned mbStartCentered : 1L; // Line is centered on line start point 64*cdf0e10cSrcweir unsigned mbEndCentered : 1L; // Line is centered on line end point 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir ImpSdrLineStartEndAttribute( 67*cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rStartPolyPolygon, 68*cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rEndPolyPolygon, 69*cdf0e10cSrcweir double fStartWidth, 70*cdf0e10cSrcweir double fEndWidth, 71*cdf0e10cSrcweir bool bStartActive, 72*cdf0e10cSrcweir bool bEndActive, 73*cdf0e10cSrcweir bool bStartCentered, 74*cdf0e10cSrcweir bool bEndCentered) 75*cdf0e10cSrcweir : mnRefCount(0), 76*cdf0e10cSrcweir maStartPolyPolygon(rStartPolyPolygon), 77*cdf0e10cSrcweir maEndPolyPolygon(rEndPolyPolygon), 78*cdf0e10cSrcweir mfStartWidth(fStartWidth), 79*cdf0e10cSrcweir mfEndWidth(fEndWidth), 80*cdf0e10cSrcweir mbStartActive(bStartActive), 81*cdf0e10cSrcweir mbEndActive(bEndActive), 82*cdf0e10cSrcweir mbStartCentered(bStartCentered), 83*cdf0e10cSrcweir mbEndCentered(bEndCentered) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // data read access 88*cdf0e10cSrcweir const basegfx::B2DPolyPolygon& getStartPolyPolygon() const { return maStartPolyPolygon; } 89*cdf0e10cSrcweir const basegfx::B2DPolyPolygon& getEndPolyPolygon() const { return maEndPolyPolygon; } 90*cdf0e10cSrcweir double getStartWidth() const { return mfStartWidth; } 91*cdf0e10cSrcweir double getEndWidth() const { return mfEndWidth; } 92*cdf0e10cSrcweir bool isStartActive() const { return mbStartActive; } 93*cdf0e10cSrcweir bool isEndActive() const { return mbEndActive; } 94*cdf0e10cSrcweir bool isStartCentered() const { return mbStartCentered; } 95*cdf0e10cSrcweir bool isEndCentered() const { return mbEndCentered; } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir bool operator==(const ImpSdrLineStartEndAttribute& rCandidate) const 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir return (getStartPolyPolygon() == rCandidate.getStartPolyPolygon() 100*cdf0e10cSrcweir && getEndPolyPolygon() == rCandidate.getEndPolyPolygon() 101*cdf0e10cSrcweir && getStartWidth() == rCandidate.getStartWidth() 102*cdf0e10cSrcweir && getEndWidth() == rCandidate.getEndWidth() 103*cdf0e10cSrcweir && isStartActive() == rCandidate.isStartActive() 104*cdf0e10cSrcweir && isEndActive() == rCandidate.isEndActive() 105*cdf0e10cSrcweir && isStartCentered() == rCandidate.isStartCentered() 106*cdf0e10cSrcweir && isEndCentered() == rCandidate.isEndCentered()); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir static ImpSdrLineStartEndAttribute* get_global_default() 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir static ImpSdrLineStartEndAttribute* pDefault = 0; 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir if(!pDefault) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir pDefault = new ImpSdrLineStartEndAttribute( 116*cdf0e10cSrcweir basegfx::B2DPolyPolygon(), 117*cdf0e10cSrcweir basegfx::B2DPolyPolygon(), 118*cdf0e10cSrcweir 0.0, 119*cdf0e10cSrcweir 0.0, 120*cdf0e10cSrcweir false, 121*cdf0e10cSrcweir false, 122*cdf0e10cSrcweir false, 123*cdf0e10cSrcweir false); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // never delete; start with RefCount 1, not 0 126*cdf0e10cSrcweir pDefault->mnRefCount++; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir return pDefault; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir }; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir SdrLineStartEndAttribute::SdrLineStartEndAttribute( 134*cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rStartPolyPolygon, 135*cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rEndPolyPolygon, 136*cdf0e10cSrcweir double fStartWidth, 137*cdf0e10cSrcweir double fEndWidth, 138*cdf0e10cSrcweir bool bStartActive, 139*cdf0e10cSrcweir bool bEndActive, 140*cdf0e10cSrcweir bool bStartCentered, 141*cdf0e10cSrcweir bool bEndCentered) 142*cdf0e10cSrcweir : mpSdrLineStartEndAttribute(new ImpSdrLineStartEndAttribute( 143*cdf0e10cSrcweir rStartPolyPolygon, rEndPolyPolygon, fStartWidth, fEndWidth, bStartActive, bEndActive, bStartCentered, bEndCentered)) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir SdrLineStartEndAttribute::SdrLineStartEndAttribute() 148*cdf0e10cSrcweir : mpSdrLineStartEndAttribute(ImpSdrLineStartEndAttribute::get_global_default()) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir mpSdrLineStartEndAttribute->mnRefCount++; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir SdrLineStartEndAttribute::SdrLineStartEndAttribute(const SdrLineStartEndAttribute& rCandidate) 154*cdf0e10cSrcweir : mpSdrLineStartEndAttribute(rCandidate.mpSdrLineStartEndAttribute) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir mpSdrLineStartEndAttribute->mnRefCount++; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir SdrLineStartEndAttribute::~SdrLineStartEndAttribute() 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir if(mpSdrLineStartEndAttribute->mnRefCount) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir mpSdrLineStartEndAttribute->mnRefCount--; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir else 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir delete mpSdrLineStartEndAttribute; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir bool SdrLineStartEndAttribute::isDefault() const 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir return mpSdrLineStartEndAttribute == ImpSdrLineStartEndAttribute::get_global_default(); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir SdrLineStartEndAttribute& SdrLineStartEndAttribute::operator=(const SdrLineStartEndAttribute& rCandidate) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir if(rCandidate.mpSdrLineStartEndAttribute != mpSdrLineStartEndAttribute) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir if(mpSdrLineStartEndAttribute->mnRefCount) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir mpSdrLineStartEndAttribute->mnRefCount--; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir else 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir delete mpSdrLineStartEndAttribute; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir mpSdrLineStartEndAttribute = rCandidate.mpSdrLineStartEndAttribute; 190*cdf0e10cSrcweir mpSdrLineStartEndAttribute->mnRefCount++; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir return *this; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir bool SdrLineStartEndAttribute::operator==(const SdrLineStartEndAttribute& rCandidate) const 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir if(rCandidate.mpSdrLineStartEndAttribute == mpSdrLineStartEndAttribute) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir return true; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir if(rCandidate.isDefault() != isDefault()) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir return false; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir return (*rCandidate.mpSdrLineStartEndAttribute == *mpSdrLineStartEndAttribute); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getStartPolyPolygon() const 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir return mpSdrLineStartEndAttribute->getStartPolyPolygon(); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getEndPolyPolygon() const 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir return mpSdrLineStartEndAttribute->getEndPolyPolygon(); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir double SdrLineStartEndAttribute::getStartWidth() const 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir return mpSdrLineStartEndAttribute->getStartWidth(); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir double SdrLineStartEndAttribute::getEndWidth() const 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir return mpSdrLineStartEndAttribute->getEndWidth(); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir bool SdrLineStartEndAttribute::isStartActive() const 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir return mpSdrLineStartEndAttribute->isStartActive(); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir bool SdrLineStartEndAttribute::isEndActive() const 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir return mpSdrLineStartEndAttribute->isEndActive(); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir bool SdrLineStartEndAttribute::isStartCentered() const 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir return mpSdrLineStartEndAttribute->isStartCentered(); 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir bool SdrLineStartEndAttribute::isEndCentered() const 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir return mpSdrLineStartEndAttribute->isEndCentered(); 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir } // end of namespace attribute 251*cdf0e10cSrcweir } // end of namespace drawinglayer 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 254*cdf0e10cSrcweir // eof 255