LCOV - code coverage report
Current view: top level - svx/source/sdr/properties - groupproperties.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 50 105 47.6 %
Date: 2014-11-03 Functions: 13 27 48.1 %
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 <sdr/properties/groupproperties.hxx>
      21             : #include <svl/itemset.hxx>
      22             : #include <svl/whiter.hxx>
      23             : #include <svx/svddef.hxx>
      24             : #include <editeng/eeitem.hxx>
      25             : #include <svx/svdogrp.hxx>
      26             : #include <svx/svdpool.hxx>
      27             : #include <svx/svdpage.hxx>
      28             : 
      29             : 
      30             : 
      31             : namespace sdr
      32             : {
      33             :     namespace properties
      34             :     {
      35             :         // create a new itemset
      36           2 :         SfxItemSet& GroupProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
      37             :         {
      38             :             // Groups have in principle no ItemSet. To support methods like
      39             :             // GetMergedItemSet() the local one is used. Thus, all items in the pool
      40             :             // may be used and a pool itemset is created.
      41           2 :             return *(new SfxItemSet(rPool));
      42             :         }
      43             : 
      44       23121 :         GroupProperties::GroupProperties(SdrObject& rObj)
      45       23121 :         :   DefaultProperties(rObj)
      46             :         {
      47       23121 :         }
      48             : 
      49          58 :         GroupProperties::GroupProperties(const GroupProperties& rProps, SdrObject& rObj)
      50          58 :         :   DefaultProperties(rProps, rObj)
      51             :         {
      52          58 :         }
      53             : 
      54       45100 :         GroupProperties::~GroupProperties()
      55             :         {
      56       45100 :         }
      57             : 
      58          58 :         BaseProperties& GroupProperties::Clone(SdrObject& rObj) const
      59             :         {
      60          58 :             return *(new GroupProperties(*this, rObj));
      61             :         }
      62             : 
      63           0 :         const SfxItemSet& GroupProperties::GetObjectItemSet() const
      64             :         {
      65             :             DBG_ASSERT(false, "GroupProperties::GetObjectItemSet() should never be called (!)");
      66           0 :             return DefaultProperties::GetObjectItemSet();
      67             :         }
      68             : 
      69           8 :         const SfxItemSet& GroupProperties::GetMergedItemSet() const
      70             :         {
      71             :             // prepare ItemSet
      72           8 :             if(mpItemSet)
      73             :             {
      74             :                 // clear local itemset for merge
      75           6 :                 mpItemSet->ClearItem();
      76             :             }
      77             :             else
      78             :             {
      79             :                 // force local itemset
      80           2 :                 DefaultProperties::GetObjectItemSet();
      81             :             }
      82             : 
      83             :             // collect all ItemSets in mpItemSet
      84           8 :             const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
      85           8 :             const size_t nCount(pSub->GetObjCount());
      86             : 
      87          16 :             for(size_t a = 0; a < nCount; ++a)
      88             :             {
      89           8 :                 const SfxItemSet& rSet = pSub->GetObj(a)->GetMergedItemSet();
      90           8 :                 SfxWhichIter aIter(rSet);
      91           8 :                 sal_uInt16 nWhich(aIter.FirstWhich());
      92             : 
      93        1672 :                 while(nWhich)
      94             :                 {
      95        1656 :                     if(SfxItemState::DONTCARE == rSet.GetItemState(nWhich, false))
      96             :                     {
      97           0 :                         mpItemSet->InvalidateItem(nWhich);
      98             :                     }
      99             :                     else
     100             :                     {
     101        1656 :                         mpItemSet->MergeValue(rSet.Get(nWhich), true);
     102             :                     }
     103             : 
     104        1656 :                     nWhich = aIter.NextWhich();
     105             :                 }
     106           8 :             }
     107             : 
     108             :             // For group proerties, do not call parent since groups do
     109             :             // not have local ItemSets.
     110           8 :             return *mpItemSet;
     111             :         }
     112             : 
     113           0 :         void GroupProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems)
     114             :         {
     115             :             // iterate over contained SdrObjects
     116           0 :             const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
     117           0 :             const size_t nCount(pSub->GetObjCount());
     118             : 
     119           0 :             for(size_t a = 0; a < nCount; ++a)
     120             :             {
     121           0 :                 SdrObject* pObj = pSub->GetObj(a);
     122             : 
     123           0 :                 if(pObj)
     124             :                 {
     125             :                     // Set merged ItemSet at contained object
     126           0 :                     pObj->SetMergedItemSet(rSet, bClearAllItems);
     127             :                 }
     128             :             }
     129             : 
     130             :             // Do not call parent here. Group objects do not have local ItemSets
     131             :             // where items need to be set.
     132             :             // DefaultProperties::SetMergedItemSet(rSet, bClearAllItems);
     133           0 :         }
     134             : 
     135           0 :         void GroupProperties::SetObjectItem(const SfxPoolItem& /*rItem*/)
     136             :         {
     137             :             DBG_ASSERT(false, "GroupProperties::SetObjectItem() should never be called (!)");
     138           0 :         }
     139             : 
     140           0 :         void GroupProperties::SetObjectItemDirect(const SfxPoolItem& /*rItem*/)
     141             :         {
     142             :             DBG_ASSERT(false, "GroupProperties::SetObjectItemDirect() should never be called (!)");
     143           0 :         }
     144             : 
     145           0 :         void GroupProperties::ClearObjectItem(const sal_uInt16 /*nWhich*/)
     146             :         {
     147             :             DBG_ASSERT(false, "GroupProperties::ClearObjectItem() should never be called (!)");
     148           0 :         }
     149             : 
     150           0 :         void GroupProperties::ClearObjectItemDirect(const sal_uInt16 /*nWhich*/)
     151             :         {
     152             :             DBG_ASSERT(false, "GroupProperties::ClearObjectItemDirect() should never be called (!)");
     153           0 :         }
     154             : 
     155           0 :         void GroupProperties::SetMergedItem(const SfxPoolItem& rItem)
     156             :         {
     157           0 :             const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
     158           0 :             const size_t nCount(pSub->GetObjCount());
     159             : 
     160           0 :             for(size_t a = 0; a < nCount; ++a)
     161             :             {
     162           0 :                 pSub->GetObj(a)->GetProperties().SetMergedItem(rItem);
     163             :             }
     164           0 :         }
     165             : 
     166         680 :         void GroupProperties::ClearMergedItem(const sal_uInt16 nWhich)
     167             :         {
     168         680 :             const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
     169         680 :             const size_t nCount(pSub->GetObjCount());
     170             : 
     171         680 :             for(size_t a = 0; a < nCount; ++a)
     172             :             {
     173           0 :                 pSub->GetObj(a)->GetProperties().ClearMergedItem(nWhich);
     174             :             }
     175         680 :         }
     176             : 
     177           0 :         void GroupProperties::SetObjectItemSet(const SfxItemSet& /*rSet*/)
     178             :         {
     179             :             DBG_ASSERT(false, "GroupProperties::SetObjectItemSet() should never be called (!)");
     180           0 :         }
     181             : 
     182           0 :         void GroupProperties::ItemSetChanged(const SfxItemSet& /*rSet*/)
     183             :         {
     184             :             DBG_ASSERT(false, "GroupProperties::ItemSetChanged() should never be called (!)");
     185           0 :         }
     186             : 
     187           0 :         bool GroupProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
     188             :         {
     189             :             DBG_ASSERT(false, "GroupProperties::AllowItemChange() should never be called (!)");
     190           0 :             return false;
     191             :         }
     192             : 
     193           0 :         void GroupProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
     194             :         {
     195             :             DBG_ASSERT(false, "GroupProperties::ItemChange() should never be called (!)");
     196           0 :         }
     197             : 
     198           0 :         void GroupProperties::PostItemChange(const sal_uInt16 /*nWhich*/)
     199             :         {
     200             :             DBG_ASSERT(false, "GroupProperties::PostItemChange() should never be called (!)");
     201           0 :         }
     202             : 
     203           0 :         SfxStyleSheet* GroupProperties::GetStyleSheet() const
     204             :         {
     205           0 :             SfxStyleSheet* pRetval = 0L;
     206             : 
     207           0 :             const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
     208           0 :             const size_t nCount(pSub->GetObjCount());
     209             : 
     210           0 :             for(size_t a = 0; a < nCount; ++a)
     211             :             {
     212           0 :                 SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
     213             : 
     214           0 :                 if(pRetval)
     215             :                 {
     216           0 :                     if(pCandidate != pRetval)
     217             :                     {
     218             :                         // different StyleSheelts, return none
     219           0 :                         return 0L;
     220             :                     }
     221             :                 }
     222             :                 else
     223             :                 {
     224           0 :                     pRetval = pCandidate;
     225             :                 }
     226             :             }
     227             : 
     228           0 :             return pRetval;
     229             :         }
     230             : 
     231        2358 :         void GroupProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
     232             :         {
     233        2358 :             const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
     234        2358 :             const size_t nCount(pSub->GetObjCount());
     235             : 
     236        6016 :             for(size_t a = 0; a < nCount; ++a)
     237             :             {
     238        3658 :                 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
     239             :             }
     240        2358 :         }
     241             : 
     242           2 :         void GroupProperties::ForceDefaultAttributes()
     243             :         {
     244             :             // nothing to do here, groups have no items and thus no default items, too.
     245           2 :         }
     246             : 
     247       21483 :         void GroupProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
     248             :         {
     249       21483 :             if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
     250             :             {
     251       21483 :                 const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
     252       21483 :                 const size_t nCount(pSub->GetObjCount());
     253             : 
     254       22259 :                 for(size_t a = 0; a < nCount; ++a)
     255             :                 {
     256         776 :                     pSub->GetObj(a)->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
     257             :                 }
     258             : 
     259             :                 // also clear local ItemSet, it's only temporary for group objects anyways.
     260       21483 :                 if(mpItemSet)
     261             :                 {
     262             :                     // #121905#
     263             :                     // copy/paste is still using clone operators and MoveToItemPool functionality.
     264             :                     // Since SfxItemSet contains a pool pointer, ClearItem is not enough here.
     265             :                     // The ItemSet for merge is constructed on demand, so it's enough here to
     266             :                     // just delete it and set to 0L.
     267             :                     // mpItemSet->ClearItem();
     268           0 :                     delete mpItemSet;
     269           0 :                     mpItemSet = 0L;
     270             :                 }
     271             :             }
     272       21483 :         }
     273             : 
     274           0 :         void GroupProperties::ForceStyleToHardAttributes()
     275             :         {
     276           0 :             const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
     277           0 :             const size_t nCount(pSub->GetObjCount());
     278             : 
     279           0 :             for(size_t a = 0; a < nCount; ++a)
     280             :             {
     281           0 :                 pSub->GetObj(a)->GetProperties().ForceStyleToHardAttributes();
     282             :             }
     283           0 :         }
     284             :     } // end of namespace properties
     285         651 : } // end of namespace sdr
     286             : 
     287             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10