LCOV - code coverage report
Current view: top level - libreoffice/svx/source/sdr/properties - defaultproperties.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 73 94 77.7 %
Date: 2012-12-17 Functions: 11 20 55.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 <svx/sdr/properties/defaultproperties.hxx>
      21             : #include <svx/sdr/properties/itemsettools.hxx>
      22             : #include <svl/itemset.hxx>
      23             : #include <svl/whiter.hxx>
      24             : 
      25             : #include <vector>
      26             : #include <svx/svdobj.hxx>
      27             : #include <svx/svddef.hxx>
      28             : #include <svx/svdpool.hxx>
      29             : #include <editeng/eeitem.hxx>
      30             : 
      31             : //////////////////////////////////////////////////////////////////////////////
      32             : 
      33             : namespace sdr
      34             : {
      35             :     namespace properties
      36             :     {
      37           0 :         SfxItemSet& DefaultProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
      38             :         {
      39             :             // Basic implementation; Basic object has NO attributes
      40           0 :             return *(new SfxItemSet(rPool));
      41             :         }
      42             : 
      43       11698 :         DefaultProperties::DefaultProperties(SdrObject& rObj)
      44             :         :   BaseProperties(rObj),
      45       11698 :             mpItemSet(0L)
      46             :         {
      47       11698 :         }
      48             : 
      49           8 :         DefaultProperties::DefaultProperties(const DefaultProperties& rProps, SdrObject& rObj)
      50             :         :   BaseProperties(rObj),
      51           8 :             mpItemSet(0L)
      52             :         {
      53           8 :             if(rProps.mpItemSet)
      54             :             {
      55           8 :                 mpItemSet = rProps.mpItemSet->Clone(sal_True);
      56             : 
      57             :                 // do not keep parent info, this may be changed by later construrtors.
      58             :                 // This class just copies the ItemSet, ignore parent.
      59           8 :                 if(mpItemSet && mpItemSet->GetParent())
      60             :                 {
      61           0 :                     mpItemSet->SetParent(0L);
      62             :                 }
      63             :             }
      64           8 :         }
      65             : 
      66           0 :         BaseProperties& DefaultProperties::Clone(SdrObject& rObj) const
      67             :         {
      68           0 :             return *(new DefaultProperties(*this, rObj));
      69             :         }
      70             : 
      71       23068 :         DefaultProperties::~DefaultProperties()
      72             :         {
      73       11534 :             if(mpItemSet)
      74             :             {
      75        9026 :                 delete mpItemSet;
      76        9026 :                 mpItemSet = 0L;
      77             :             }
      78       11534 :         }
      79             : 
      80      818382 :         const SfxItemSet& DefaultProperties::GetObjectItemSet() const
      81             :         {
      82      818382 :             if(!mpItemSet)
      83             :             {
      84        9188 :                 ((DefaultProperties*)this)->mpItemSet = &(((DefaultProperties*)this)->CreateObjectSpecificItemSet(*GetSdrObject().GetObjectItemPool()));
      85        9188 :                 ((DefaultProperties*)this)->ForceDefaultAttributes();
      86             :             }
      87             : 
      88             :             DBG_ASSERT(mpItemSet, "Could not create an SfxItemSet(!)");
      89             : 
      90      818382 :             return *mpItemSet;
      91             :         }
      92             : 
      93       20764 :         void DefaultProperties::SetObjectItem(const SfxPoolItem& rItem)
      94             :         {
      95       20764 :             const sal_uInt16 nWhichID(rItem.Which());
      96             : 
      97       20764 :             if(AllowItemChange(nWhichID, &rItem))
      98             :             {
      99       20764 :                 ItemChange(nWhichID, &rItem);
     100       20764 :                 PostItemChange(nWhichID);
     101             : 
     102       20764 :                 SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), nWhichID, nWhichID);
     103       20764 :                 aSet.Put(rItem);
     104       20764 :                 ItemSetChanged(aSet);
     105             :             }
     106       20764 :         }
     107             : 
     108       12164 :         void DefaultProperties::SetObjectItemDirect(const SfxPoolItem& rItem)
     109             :         {
     110       12164 :             const sal_uInt16 nWhichID(rItem.Which());
     111             : 
     112       12164 :             if(AllowItemChange(nWhichID, &rItem))
     113             :             {
     114       12164 :                 ItemChange(nWhichID, &rItem);
     115             :             }
     116       12164 :         }
     117             : 
     118          88 :         void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich)
     119             :         {
     120          88 :             if(AllowItemChange(nWhich))
     121             :             {
     122          88 :                 ItemChange(nWhich);
     123          88 :                 PostItemChange(nWhich);
     124             : 
     125          88 :                 if(nWhich)
     126             :                 {
     127           0 :                     SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), nWhich, nWhich, 0, 0);
     128           0 :                     ItemSetChanged(aSet);
     129             :                 }
     130             :             }
     131          88 :         }
     132             : 
     133       25420 :         void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
     134             :         {
     135       25420 :             if(AllowItemChange(nWhich))
     136             :             {
     137       24924 :                 ItemChange(nWhich);
     138             :             }
     139       25420 :         }
     140             : 
     141       19392 :         void DefaultProperties::SetObjectItemSet(const SfxItemSet& rSet)
     142             :         {
     143       19392 :             SfxWhichIter aWhichIter(rSet);
     144       19392 :             sal_uInt16 nWhich(aWhichIter.FirstWhich());
     145             :             const SfxPoolItem *pPoolItem;
     146       19392 :             std::vector< sal_uInt16 > aPostItemChangeList;
     147       19392 :             sal_Bool bDidChange(sal_False);
     148       19392 :             SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), SDRATTR_START, EE_ITEMS_END);
     149             : 
     150             :             // give a hint to STL_Vector
     151       19392 :             aPostItemChangeList.reserve(rSet.Count());
     152             : 
     153     1818778 :             while(nWhich)
     154             :             {
     155     1779994 :                 if(SFX_ITEM_SET == rSet.GetItemState(nWhich, sal_False, &pPoolItem))
     156             :                 {
     157      159836 :                     if(AllowItemChange(nWhich, pPoolItem))
     158             :                     {
     159      159836 :                         bDidChange = sal_True;
     160      159836 :                         ItemChange(nWhich, pPoolItem);
     161      159836 :                         aPostItemChangeList.push_back( nWhich );
     162      159836 :                         aSet.Put(*pPoolItem);
     163             :                     }
     164             :                 }
     165             : 
     166     1779994 :                 nWhich = aWhichIter.NextWhich();
     167             :             }
     168             : 
     169       19392 :             if(bDidChange)
     170             :             {
     171       19386 :                 std::vector< sal_uInt16 >::iterator aIter = aPostItemChangeList.begin();
     172       19386 :                 const std::vector< sal_uInt16 >::iterator aEnd = aPostItemChangeList.end();
     173             : 
     174      198608 :                 while(aIter != aEnd)
     175             :                 {
     176      159836 :                     PostItemChange(*aIter);
     177      159836 :                     ++aIter;
     178             :                 }
     179             : 
     180       19386 :                 ItemSetChanged(aSet);
     181       19392 :             }
     182       19392 :         }
     183             : 
     184           0 :         void DefaultProperties::ItemSetChanged(const SfxItemSet& /*rSet*/)
     185             :         {
     186           0 :         }
     187             : 
     188      217776 :         sal_Bool DefaultProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
     189             :         {
     190      217776 :             return sal_True;
     191             :         }
     192             : 
     193           0 :         void DefaultProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
     194             :         {
     195           0 :         }
     196             : 
     197      180688 :         void DefaultProperties::PostItemChange(const sal_uInt16 nWhich )
     198             :         {
     199      180688 :             if( (nWhich == XATTR_FILLSTYLE) && (mpItemSet != NULL) )
     200        8012 :                 CleanupFillProperties(*mpItemSet);
     201      180688 :         }
     202             : 
     203           0 :         void DefaultProperties::SetStyleSheet(SfxStyleSheet* /*pNewStyleSheet*/, sal_Bool /*bDontRemoveHardAttr*/)
     204             :         {
     205             :             // no StyleSheet in DefaultProperties
     206           0 :         }
     207             : 
     208           0 :         SfxStyleSheet* DefaultProperties::GetStyleSheet() const
     209             :         {
     210             :             // no StyleSheet in DefaultProperties
     211           0 :             return 0L;
     212             :         }
     213             : 
     214           0 :         void DefaultProperties::ForceDefaultAttributes()
     215             :         {
     216           0 :         }
     217             : 
     218           0 :         void DefaultProperties::Scale(const Fraction& rScale)
     219             :         {
     220           0 :             if(mpItemSet)
     221             :             {
     222           0 :                 ScaleItemSet(*mpItemSet, rScale);
     223             :             }
     224           0 :         }
     225             :     } // end of namespace properties
     226             : } // end of namespace sdr
     227             : 
     228             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10