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