LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/attribute - sdrfillattribute.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 60 62 96.8 %
Date: 2012-12-17 Functions: 21 21 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <drawinglayer/attribute/sdrfillattribute.hxx>
      21             : #include <basegfx/color/bcolor.hxx>
      22             : #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx>
      23             : #include <drawinglayer/attribute/fillhatchattribute.hxx>
      24             : #include <drawinglayer/attribute/fillgradientattribute.hxx>
      25             : 
      26             : //////////////////////////////////////////////////////////////////////////////
      27             : 
      28             : namespace drawinglayer
      29             : {
      30             :     namespace attribute
      31             :     {
      32          56 :         class ImpSdrFillAttribute
      33             :         {
      34             :         public:
      35             :             // refcounter
      36             :             sal_uInt32                          mnRefCount;
      37             : 
      38             :             // fill definitions
      39             :             double                              mfTransparence;     // [0.0 .. 1.0], 0.0==no transp.
      40             :             basegfx::BColor                     maColor;            // fill color
      41             :             FillGradientAttribute               maGradient;         // fill gradient (if used)
      42             :             FillHatchAttribute                  maHatch;            // fill hatch (if used)
      43             :             SdrFillBitmapAttribute              maBitmap;           // fill bitmap (if used)
      44             : 
      45             :         public:
      46          88 :             ImpSdrFillAttribute(
      47             :                 double fTransparence,
      48             :                 const basegfx::BColor& rColor,
      49             :                 const FillGradientAttribute& rGradient,
      50             :                 const FillHatchAttribute& rHatch,
      51             :                 const SdrFillBitmapAttribute& rBitmap)
      52             :             :   mnRefCount(0),
      53             :                 mfTransparence(fTransparence),
      54             :                 maColor(rColor),
      55             :                 maGradient(rGradient),
      56             :                 maHatch(rHatch),
      57          88 :                 maBitmap(rBitmap)
      58             :             {
      59          88 :             }
      60             : 
      61             :             // data read access
      62          74 :             double getTransparence() const { return mfTransparence; }
      63          74 :             const basegfx::BColor& getColor() const { return maColor; }
      64          74 :             const FillGradientAttribute& getGradient() const { return maGradient; }
      65          74 :             const FillHatchAttribute& getHatch() const { return maHatch; }
      66          74 :             const SdrFillBitmapAttribute& getBitmap() const { return maBitmap; }
      67             : 
      68             :             // compare operator
      69          18 :             bool operator==(const ImpSdrFillAttribute& rCandidate) const
      70             :             {
      71          18 :                 return(getTransparence() == rCandidate.getTransparence()
      72          18 :                     && getColor() == rCandidate.getColor()
      73          18 :                     && getGradient() == rCandidate.getGradient()
      74          18 :                     && getHatch() == rCandidate.getHatch()
      75          72 :                     && getBitmap() == rCandidate.getBitmap());
      76             :             }
      77             : 
      78        3246 :             static ImpSdrFillAttribute* get_global_default()
      79             :             {
      80             :                 static ImpSdrFillAttribute* pDefault = 0;
      81             : 
      82        3246 :                 if(!pDefault)
      83             :                 {
      84             :                     pDefault = new ImpSdrFillAttribute(
      85             :                         0.0,
      86             :                         basegfx::BColor(),
      87             :                         FillGradientAttribute(),
      88             :                         FillHatchAttribute(),
      89          18 :                         SdrFillBitmapAttribute());
      90             : 
      91             :                     // never delete; start with RefCount 1, not 0
      92          18 :                     pDefault->mnRefCount++;
      93             :                 }
      94             : 
      95        3246 :                 return pDefault;
      96             :             }
      97             :         };
      98             : 
      99          70 :         SdrFillAttribute::SdrFillAttribute(
     100             :             double fTransparence,
     101             :             const basegfx::BColor& rColor,
     102             :             const FillGradientAttribute& rGradient,
     103             :             const FillHatchAttribute& rHatch,
     104             :             const SdrFillBitmapAttribute& rBitmap)
     105             :         :   mpSdrFillAttribute(new ImpSdrFillAttribute(
     106          70 :                 fTransparence, rColor, rGradient, rHatch, rBitmap))
     107             :         {
     108          70 :         }
     109             : 
     110        1496 :         SdrFillAttribute::SdrFillAttribute()
     111        1496 :         :   mpSdrFillAttribute(ImpSdrFillAttribute::get_global_default())
     112             :         {
     113        1496 :             mpSdrFillAttribute->mnRefCount++;
     114        1496 :         }
     115             : 
     116        1050 :         SdrFillAttribute::SdrFillAttribute(const SdrFillAttribute& rCandidate)
     117        1050 :         :   mpSdrFillAttribute(rCandidate.mpSdrFillAttribute)
     118             :         {
     119        1050 :             mpSdrFillAttribute->mnRefCount++;
     120        1050 :         }
     121             : 
     122        2576 :         SdrFillAttribute::~SdrFillAttribute()
     123             :         {
     124        2576 :             if(mpSdrFillAttribute->mnRefCount)
     125             :             {
     126        2520 :                 mpSdrFillAttribute->mnRefCount--;
     127             :             }
     128             :             else
     129             :             {
     130          56 :                 delete mpSdrFillAttribute;
     131             :             }
     132        2576 :         }
     133             : 
     134        1750 :         bool SdrFillAttribute::isDefault() const
     135             :         {
     136        1750 :             return mpSdrFillAttribute == ImpSdrFillAttribute::get_global_default();
     137             :         }
     138             : 
     139         654 :         SdrFillAttribute& SdrFillAttribute::operator=(const SdrFillAttribute& rCandidate)
     140             :         {
     141         654 :             if(rCandidate.mpSdrFillAttribute != mpSdrFillAttribute)
     142             :             {
     143          70 :                 if(mpSdrFillAttribute->mnRefCount)
     144             :                 {
     145          70 :                     mpSdrFillAttribute->mnRefCount--;
     146             :                 }
     147             :                 else
     148             :                 {
     149           0 :                     delete mpSdrFillAttribute;
     150             :                 }
     151             : 
     152          70 :                 mpSdrFillAttribute = rCandidate.mpSdrFillAttribute;
     153          70 :                 mpSdrFillAttribute->mnRefCount++;
     154             :             }
     155             : 
     156         654 :             return *this;
     157             :         }
     158             : 
     159          76 :         bool SdrFillAttribute::operator==(const SdrFillAttribute& rCandidate) const
     160             :         {
     161          76 :             if(rCandidate.mpSdrFillAttribute == mpSdrFillAttribute)
     162             :             {
     163          58 :                 return true;
     164             :             }
     165             : 
     166          18 :             if(rCandidate.isDefault() != isDefault())
     167             :             {
     168           0 :                 return false;
     169             :             }
     170             : 
     171          18 :             return (*rCandidate.mpSdrFillAttribute == *mpSdrFillAttribute);
     172             :         }
     173             : 
     174          38 :         double SdrFillAttribute::getTransparence() const
     175             :         {
     176          38 :             return mpSdrFillAttribute->getTransparence();
     177             :         }
     178             : 
     179          38 :         const basegfx::BColor& SdrFillAttribute::getColor() const
     180             :         {
     181          38 :             return mpSdrFillAttribute->getColor();
     182             :         }
     183             : 
     184          38 :         const FillGradientAttribute& SdrFillAttribute::getGradient() const
     185             :         {
     186          38 :             return mpSdrFillAttribute->getGradient();
     187             :         }
     188             : 
     189          38 :         const FillHatchAttribute& SdrFillAttribute::getHatch() const
     190             :         {
     191          38 :             return mpSdrFillAttribute->getHatch();
     192             :         }
     193             : 
     194          38 :         const SdrFillBitmapAttribute& SdrFillAttribute::getBitmap() const
     195             :         {
     196          38 :             return mpSdrFillAttribute->getBitmap();
     197             :         }
     198             :     } // end of namespace attribute
     199             : } // end of namespace drawinglayer
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10