1*4bfbcde8SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*4bfbcde8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*4bfbcde8SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*4bfbcde8SAndrew Rist * distributed with this work for additional information 6*4bfbcde8SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*4bfbcde8SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*4bfbcde8SAndrew Rist * "License"); you may not use this file except in compliance 9*4bfbcde8SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*4bfbcde8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*4bfbcde8SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*4bfbcde8SAndrew Rist * software distributed under the License is distributed on an 15*4bfbcde8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*4bfbcde8SAndrew Rist * KIND, either express or implied. See the License for the 17*4bfbcde8SAndrew Rist * specific language governing permissions and limitations 18*4bfbcde8SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*4bfbcde8SAndrew Rist *************************************************************/ 21cdf0e10cSrcweir 22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 23cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include <drawinglayer/attribute/fillhatchattribute.hxx> 26cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx> 27cdf0e10cSrcweir 28cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 29cdf0e10cSrcweir 30cdf0e10cSrcweir namespace drawinglayer 31cdf0e10cSrcweir { 32cdf0e10cSrcweir namespace attribute 33cdf0e10cSrcweir { 34cdf0e10cSrcweir class ImpFillHatchAttribute 35cdf0e10cSrcweir { 36cdf0e10cSrcweir public: 37cdf0e10cSrcweir // refcounter 38cdf0e10cSrcweir sal_uInt32 mnRefCount; 39cdf0e10cSrcweir 40cdf0e10cSrcweir // data definitions 41cdf0e10cSrcweir HatchStyle meStyle; 42cdf0e10cSrcweir double mfDistance; 43cdf0e10cSrcweir double mfAngle; 44cdf0e10cSrcweir basegfx::BColor maColor; 45cdf0e10cSrcweir 46cdf0e10cSrcweir // bitfield 47cdf0e10cSrcweir unsigned mbFillBackground : 1; 48cdf0e10cSrcweir 49cdf0e10cSrcweir ImpFillHatchAttribute( 50cdf0e10cSrcweir HatchStyle eStyle, 51cdf0e10cSrcweir double fDistance, 52cdf0e10cSrcweir double fAngle, 53cdf0e10cSrcweir const basegfx::BColor& rColor, 54cdf0e10cSrcweir bool bFillBackground) 55cdf0e10cSrcweir : mnRefCount(0), 56cdf0e10cSrcweir meStyle(eStyle), 57cdf0e10cSrcweir mfDistance(fDistance), 58cdf0e10cSrcweir mfAngle(fAngle), 59cdf0e10cSrcweir maColor(rColor), 60cdf0e10cSrcweir mbFillBackground(bFillBackground) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir // data read access 65cdf0e10cSrcweir HatchStyle getStyle() const { return meStyle; } 66cdf0e10cSrcweir double getDistance() const { return mfDistance; } 67cdf0e10cSrcweir double getAngle() const { return mfAngle; } 68cdf0e10cSrcweir const basegfx::BColor& getColor() const { return maColor; } 69cdf0e10cSrcweir bool isFillBackground() const { return mbFillBackground; } 70cdf0e10cSrcweir 71cdf0e10cSrcweir bool operator==(const ImpFillHatchAttribute& rCandidate) const 72cdf0e10cSrcweir { 73cdf0e10cSrcweir return (getStyle() == rCandidate.getStyle() 74cdf0e10cSrcweir && getDistance() == rCandidate.getDistance() 75cdf0e10cSrcweir && getAngle() == rCandidate.getAngle() 76cdf0e10cSrcweir && getColor() == rCandidate.getColor() 77cdf0e10cSrcweir && isFillBackground() == rCandidate.isFillBackground()); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir static ImpFillHatchAttribute* get_global_default() 81cdf0e10cSrcweir { 82cdf0e10cSrcweir static ImpFillHatchAttribute* pDefault = 0; 83cdf0e10cSrcweir 84cdf0e10cSrcweir if(!pDefault) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir pDefault = new ImpFillHatchAttribute( 87cdf0e10cSrcweir HATCHSTYLE_SINGLE, 88cdf0e10cSrcweir 0.0, 0.0, 89cdf0e10cSrcweir basegfx::BColor(), 90cdf0e10cSrcweir false); 91cdf0e10cSrcweir 92cdf0e10cSrcweir // never delete; start with RefCount 1, not 0 93cdf0e10cSrcweir pDefault->mnRefCount++; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir return pDefault; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir }; 99cdf0e10cSrcweir 100cdf0e10cSrcweir FillHatchAttribute::FillHatchAttribute( 101cdf0e10cSrcweir HatchStyle eStyle, 102cdf0e10cSrcweir double fDistance, 103cdf0e10cSrcweir double fAngle, 104cdf0e10cSrcweir const basegfx::BColor& rColor, 105cdf0e10cSrcweir bool bFillBackground) 106cdf0e10cSrcweir : mpFillHatchAttribute(new ImpFillHatchAttribute( 107cdf0e10cSrcweir eStyle, fDistance, fAngle, rColor, bFillBackground)) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir FillHatchAttribute::FillHatchAttribute() 112cdf0e10cSrcweir : mpFillHatchAttribute(ImpFillHatchAttribute::get_global_default()) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir mpFillHatchAttribute->mnRefCount++; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir FillHatchAttribute::FillHatchAttribute(const FillHatchAttribute& rCandidate) 118cdf0e10cSrcweir : mpFillHatchAttribute(rCandidate.mpFillHatchAttribute) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir mpFillHatchAttribute->mnRefCount++; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir FillHatchAttribute::~FillHatchAttribute() 124cdf0e10cSrcweir { 125cdf0e10cSrcweir if(mpFillHatchAttribute->mnRefCount) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir mpFillHatchAttribute->mnRefCount--; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir else 130cdf0e10cSrcweir { 131cdf0e10cSrcweir delete mpFillHatchAttribute; 132cdf0e10cSrcweir } 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir bool FillHatchAttribute::isDefault() const 136cdf0e10cSrcweir { 137cdf0e10cSrcweir return mpFillHatchAttribute == ImpFillHatchAttribute::get_global_default(); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir FillHatchAttribute& FillHatchAttribute::operator=(const FillHatchAttribute& rCandidate) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir if(rCandidate.mpFillHatchAttribute != mpFillHatchAttribute) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir if(mpFillHatchAttribute->mnRefCount) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir mpFillHatchAttribute->mnRefCount--; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir else 149cdf0e10cSrcweir { 150cdf0e10cSrcweir delete mpFillHatchAttribute; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir mpFillHatchAttribute = rCandidate.mpFillHatchAttribute; 154cdf0e10cSrcweir mpFillHatchAttribute->mnRefCount++; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir return *this; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir bool FillHatchAttribute::operator==(const FillHatchAttribute& rCandidate) const 161cdf0e10cSrcweir { 162cdf0e10cSrcweir if(rCandidate.mpFillHatchAttribute == mpFillHatchAttribute) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir return true; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir if(rCandidate.isDefault() != isDefault()) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir return false; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir return (*rCandidate.mpFillHatchAttribute == *mpFillHatchAttribute); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir // data read access 176cdf0e10cSrcweir HatchStyle FillHatchAttribute::getStyle() const 177cdf0e10cSrcweir { 178cdf0e10cSrcweir return mpFillHatchAttribute->getStyle(); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir double FillHatchAttribute::getDistance() const 182cdf0e10cSrcweir { 183cdf0e10cSrcweir return mpFillHatchAttribute->getDistance(); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir double FillHatchAttribute::getAngle() const 187cdf0e10cSrcweir { 188cdf0e10cSrcweir return mpFillHatchAttribute->getAngle(); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir const basegfx::BColor& FillHatchAttribute::getColor() const 192cdf0e10cSrcweir { 193cdf0e10cSrcweir return mpFillHatchAttribute->getColor(); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir bool FillHatchAttribute::isFillBackground() const 197cdf0e10cSrcweir { 198cdf0e10cSrcweir return mpFillHatchAttribute->isFillBackground(); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir } // end of namespace attribute 202cdf0e10cSrcweir } // end of namespace drawinglayer 203cdf0e10cSrcweir 204cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 205cdf0e10cSrcweir // eof 206