LCOV - code coverage report
Current view: top level - svx/source/sdr/properties - groupproperties.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 49 104 47.1 %
Date: 2015-06-13 12:38:46 Functions: 11 25 44.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 <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           1 :         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           1 :             return new SfxItemSet(rPool);
      42             :         }
      43             : 
      44       35185 :         GroupProperties::GroupProperties(SdrObject& rObj)
      45       35185 :         :   DefaultProperties(rObj)
      46             :         {
      47       35185 :         }
      48             : 
      49          29 :         GroupProperties::GroupProperties(const GroupProperties& rProps, SdrObject& rObj)
      50          29 :         :   DefaultProperties(rProps, rObj)
      51             :         {
      52          29 :         }
      53             : 
      54       69676 :         GroupProperties::~GroupProperties()
      55             :         {
      56       69676 :         }
      57             : 
      58          29 :         BaseProperties& GroupProperties::Clone(SdrObject& rObj) const
      59             :         {
      60          29 :             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           4 :         const SfxItemSet& GroupProperties::GetMergedItemSet() const
      70             :         {
      71             :             // prepare ItemSet
      72           4 :             if(mpItemSet)
      73             :             {
      74             :                 // clear local itemset for merge
      75           3 :                 mpItemSet->ClearItem();
      76             :             }
      77             :             else
      78             :             {
      79             :                 // force local itemset
      80           1 :                 DefaultProperties::GetObjectItemSet();
      81             :             }
      82             : 
      83             :             // collect all ItemSets in mpItemSet
      84           4 :             const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
      85           4 :             const size_t nCount(pSub->GetObjCount());
      86             : 
      87           8 :             for(size_t a = 0; a < nCount; ++a)
      88             :             {
      89           4 :                 const SfxItemSet& rSet = pSub->GetObj(a)->GetMergedItemSet();
      90           4 :                 SfxWhichIter aIter(rSet);
      91           4 :                 sal_uInt16 nWhich(aIter.FirstWhich());
      92             : 
      93         836 :                 while(nWhich)
      94             :                 {
      95         828 :                     if(SfxItemState::DONTCARE == rSet.GetItemState(nWhich, false))
      96             :                     {
      97           0 :                         mpItemSet->InvalidateItem(nWhich);
      98             :                     }
      99             :                     else
     100             :                     {
     101         828 :                         mpItemSet->MergeValue(rSet.Get(nWhich), true);
     102             :                     }
     103             : 
     104         828 :                     nWhich = aIter.NextWhich();
     105             :                 }
     106           4 :             }
     107             : 
     108             :             // For group proerties, do not call parent since groups do
     109             :             // not have local ItemSets.
     110           4 :             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         365 :         void GroupProperties::ClearMergedItem(const sal_uInt16 nWhich)
     167             :         {
     168         365 :             const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
     169         365 :             const size_t nCount(pSub->GetObjCount());
     170             : 
     171         365 :             for(size_t a = 0; a < nCount; ++a)
     172             :             {
     173           0 :                 pSub->GetObj(a)->GetProperties().ClearMergedItem(nWhich);
     174             :             }
     175         365 :         }
     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        1206 :         void GroupProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
     232             :         {
     233        1206 :             const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
     234        1206 :             const size_t nCount(pSub->GetObjCount());
     235             : 
     236        3066 :             for(size_t a = 0; a < nCount; ++a)
     237             :             {
     238        1860 :                 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
     239             :             }
     240        1206 :         }
     241             : 
     242           1 :         void GroupProperties::ForceDefaultAttributes()
     243             :         {
     244             :             // nothing to do here, groups have no items and thus no default items, too.
     245           1 :         }
     246             : 
     247       34351 :         void GroupProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
     248             :         {
     249       34351 :             if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
     250             :             {
     251       34351 :                 const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
     252       34351 :                 const size_t nCount(pSub->GetObjCount());
     253             : 
     254       34741 :                 for(size_t a = 0; a < nCount; ++a)
     255             :                 {
     256         390 :                     pSub->GetObj(a)->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
     257             :                 }
     258             : 
     259             :                 // also clear local ItemSet, it's only temporary for group objects anyways.
     260       34351 :                 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       34351 :         }
     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             : } // end of namespace sdr
     286             : 
     287             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11