Bump version to 6.4-15
[LibreOffice.git] / svx / source / sdr / properties / groupproperties.cxx
blobebedda8955f2e1ca00f6ac27b90b5c9fc4e197bb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <sdr/properties/groupproperties.hxx>
23 #include <svl/itemset.hxx>
24 #include <svl/whiter.hxx>
25 #include <svx/svddef.hxx>
26 #include <editeng/eeitem.hxx>
27 #include <svx/svdogrp.hxx>
28 #include <svx/svdpool.hxx>
29 #include <svx/svdpage.hxx>
32 namespace sdr
34 namespace properties
36 // create a new itemset
37 std::unique_ptr<SfxItemSet> GroupProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
39 // Groups have in principle no ItemSet. To support methods like
40 // GetMergedItemSet() the local one is used. Thus, all items in the pool
41 // may be used and a pool itemset is created.
42 return std::make_unique<SfxItemSet>(rPool);
45 GroupProperties::GroupProperties(SdrObject& rObj)
46 : DefaultProperties(rObj)
50 GroupProperties::GroupProperties(const GroupProperties& rProps, SdrObject& rObj)
51 : DefaultProperties(rProps, rObj)
55 GroupProperties::~GroupProperties()
59 std::unique_ptr<BaseProperties> GroupProperties::Clone(SdrObject& rObj) const
61 return std::unique_ptr<BaseProperties>(new GroupProperties(*this, rObj));
64 const SfxItemSet& GroupProperties::GetObjectItemSet() const
66 assert(!"GroupProperties::GetObjectItemSet() should never be called");
67 return DefaultProperties::GetObjectItemSet();
70 const SfxItemSet& GroupProperties::GetMergedItemSet() const
72 // prepare ItemSet
73 if(mpItemSet)
75 // clear local itemset for merge
76 mpItemSet->ClearItem();
78 else
80 // force local itemset
81 DefaultProperties::GetObjectItemSet();
84 // collect all ItemSets in mpItemSet
85 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
86 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
87 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
89 for(size_t a = 0; a < nCount; ++a)
91 const SfxItemSet& rSet = pSub->GetObj(a)->GetMergedItemSet();
92 SfxWhichIter aIter(rSet);
93 sal_uInt16 nWhich(aIter.FirstWhich());
95 while(nWhich)
97 if(SfxItemState::DONTCARE == rSet.GetItemState(nWhich, false))
99 mpItemSet->InvalidateItem(nWhich);
101 else
103 mpItemSet->MergeValue(rSet.Get(nWhich), true);
106 nWhich = aIter.NextWhich();
110 // For group properties, do not call parent since groups do
111 // not have local ItemSets.
112 return *mpItemSet;
115 void GroupProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems)
117 // iterate over contained SdrObjects
118 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
119 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
120 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
122 for(size_t a = 0; a < nCount; ++a)
124 SdrObject* pObj = pSub->GetObj(a);
126 if(pObj)
128 // Set merged ItemSet at contained object
129 pObj->SetMergedItemSet(rSet, bClearAllItems);
133 // Do not call parent here. Group objects do not have local ItemSets
134 // where items need to be set.
135 // DefaultProperties::SetMergedItemSet(rSet, bClearAllItems);
138 void GroupProperties::SetObjectItem(const SfxPoolItem& /*rItem*/)
140 assert(!"GroupProperties::SetObjectItem() should never be called");
143 void GroupProperties::SetObjectItemDirect(const SfxPoolItem& /*rItem*/)
145 assert(!"GroupProperties::SetObjectItemDirect() should never be called");
148 void GroupProperties::ClearObjectItem(const sal_uInt16 nWhich)
150 // iterate over contained SdrObjects
151 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
152 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
153 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
155 for(size_t a = 0; a < nCount; ++a)
157 SdrObject* pObj = pSub->GetObj(a);
159 if(pObj)
161 pObj->GetProperties().ClearObjectItem(nWhich);
166 void GroupProperties::ClearObjectItemDirect(const sal_uInt16 /*nWhich*/)
168 assert(!"GroupProperties::ClearObjectItemDirect() should never be called");
171 void GroupProperties::SetMergedItem(const SfxPoolItem& rItem)
173 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
174 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
175 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
177 for(size_t a = 0; a < nCount; ++a)
179 pSub->GetObj(a)->GetProperties().SetMergedItem(rItem);
183 void GroupProperties::ClearMergedItem(const sal_uInt16 nWhich)
185 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
186 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
187 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
189 for(size_t a = 0; a < nCount; ++a)
191 pSub->GetObj(a)->GetProperties().ClearMergedItem(nWhich);
195 void GroupProperties::SetObjectItemSet(const SfxItemSet& /*rSet*/)
197 assert(!"GroupProperties::SetObjectItemSet() should never be called");
200 void GroupProperties::ItemSetChanged(const SfxItemSet& /*rSet*/)
202 assert(!"GroupProperties::ItemSetChanged() should never be called");
205 bool GroupProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
207 assert(!"GroupProperties::AllowItemChange() should never be called");
208 return false;
211 void GroupProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
213 assert(!"GroupProperties::ItemChange() should never be called");
216 void GroupProperties::PostItemChange(const sal_uInt16 /*nWhich*/)
218 assert(!"GroupProperties::PostItemChange() should never be called");
221 SfxStyleSheet* GroupProperties::GetStyleSheet() const
223 SfxStyleSheet* pRetval = nullptr;
225 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
226 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
227 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
229 for(size_t a = 0; a < nCount; ++a)
231 SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
233 if(pRetval)
235 if(pCandidate != pRetval)
237 // different StyleSheelts, return none
238 return nullptr;
241 else
243 pRetval = pCandidate;
247 return pRetval;
250 void GroupProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
252 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
253 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
254 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
256 for(size_t a = 0; a < nCount; ++a)
258 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
262 void GroupProperties::ForceDefaultAttributes()
264 // nothing to do here, groups have no items and thus no default items, too.
267 void GroupProperties::ForceStyleToHardAttributes()
269 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
270 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
271 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
273 for(size_t a = 0; a < nCount; ++a)
275 pSub->GetObj(a)->GetProperties().ForceStyleToHardAttributes();
278 } // end of namespace properties
279 } // end of namespace sdr
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */