1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/svdogrp.hxx>
26 #include <svx/svdpage.hxx>
27 #include <osl/diagnose.h>
30 namespace sdr::properties
32 GroupProperties::GroupProperties(SdrObject
& rObj
)
33 : BaseProperties(rObj
)
37 GroupProperties::~GroupProperties()
41 std::unique_ptr
<BaseProperties
> GroupProperties::Clone(SdrObject
& rObj
) const
43 return std::unique_ptr
<BaseProperties
>(new GroupProperties(rObj
));
46 SfxItemSet
GroupProperties::CreateObjectSpecificItemSet(SfxItemPool
& rPool
)
48 return SfxItemSet(rPool
);
51 const SfxItemSet
& GroupProperties::GetObjectItemSet() const
53 assert(!"GroupProperties::GetObjectItemSet() should never be called");
57 const SfxItemSet
& GroupProperties::GetMergedItemSet() const
61 // clear local itemset for merge
62 moMergedItemSet
->ClearItem();
63 else if(!moMergedItemSet
)
64 // force local itemset
65 moMergedItemSet
.emplace(GetSdrObject().GetObjectItemPool());
67 // collect all ItemSets in mpItemSet
68 const SdrObjList
* pSub(static_cast<const SdrObjGroup
&>(GetSdrObject()).GetSubList());
69 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
71 return *moMergedItemSet
;
72 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
74 const SfxItemSet
& rSet
= pObj
->GetMergedItemSet();
75 SfxWhichIter
aIter(rSet
);
76 sal_uInt16
nWhich(aIter
.FirstWhich());
80 if(SfxItemState::INVALID
== aIter
.GetItemState(false))
82 moMergedItemSet
->InvalidateItem(nWhich
);
86 moMergedItemSet
->MergeValue(rSet
.Get(nWhich
));
89 nWhich
= aIter
.NextWhich();
93 // For group properties, do not call parent since groups do
94 // not have local ItemSets.
95 return *moMergedItemSet
;
98 void GroupProperties::SetMergedItemSet(const SfxItemSet
& rSet
, bool bClearAllItems
, bool bAdjustTextFrameWidthAndHeight
)
100 // iterate over contained SdrObjects
101 const SdrObjList
* pSub(static_cast<const SdrObjGroup
&>(GetSdrObject()).GetSubList());
102 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
105 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
106 // Set merged ItemSet at contained object
107 pObj
->SetMergedItemSet(rSet
, bClearAllItems
, bAdjustTextFrameWidthAndHeight
);
109 // Do not call parent here. Group objects do not have local ItemSets
110 // where items need to be set.
113 void GroupProperties::SetObjectItem(const SfxPoolItem
& /*rItem*/)
115 assert(!"GroupProperties::SetObjectItem() should never be called");
118 void GroupProperties::SetObjectItemDirect(const SfxPoolItem
& /*rItem*/)
120 assert(!"GroupProperties::SetObjectItemDirect() should never be called");
123 void GroupProperties::ClearObjectItem(const sal_uInt16 nWhich
)
125 // iterate over contained SdrObjects
126 const SdrObjList
* pSub(static_cast<const SdrObjGroup
&>(GetSdrObject()).GetSubList());
127 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
130 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
131 pObj
->GetProperties().ClearObjectItem(nWhich
);
134 void GroupProperties::ClearObjectItemDirect(const sal_uInt16
/*nWhich*/)
136 assert(!"GroupProperties::ClearObjectItemDirect() should never be called");
139 void GroupProperties::SetMergedItem(const SfxPoolItem
& rItem
)
141 const SdrObjList
* pSub(static_cast<const SdrObjGroup
&>(GetSdrObject()).GetSubList());
142 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
145 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
146 pObj
->GetProperties().SetMergedItem(rItem
);
149 void GroupProperties::ClearMergedItem(const sal_uInt16 nWhich
)
151 const SdrObjList
* pSub(static_cast<const SdrObjGroup
&>(GetSdrObject()).GetSubList());
152 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
155 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
156 pObj
->GetProperties().ClearMergedItem(nWhich
);
159 void GroupProperties::SetObjectItemSet(const SfxItemSet
& /*rSet*/, bool /*bAdjustTextFrameWidthAndHeight*/)
161 assert(!"GroupProperties::SetObjectItemSet() should never be called");
164 SfxStyleSheet
* GroupProperties::GetStyleSheet() const
166 SfxStyleSheet
* pRetval
= nullptr;
168 const SdrObjList
* pSub(static_cast<const SdrObjGroup
&>(GetSdrObject()).GetSubList());
169 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
173 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
175 SfxStyleSheet
* pCandidate
= pObj
->GetStyleSheet();
179 if(pCandidate
!= pRetval
)
181 // different StyleSheets, return none
187 pRetval
= pCandidate
;
194 void GroupProperties::SetStyleSheet(SfxStyleSheet
* pNewStyleSheet
, bool bDontRemoveHardAttr
,
195 bool bBroadcast
, bool bAdjustTextFrameWidthAndHeight
)
197 const SdrObjList
* pSub(static_cast<const SdrObjGroup
&>(GetSdrObject()).GetSubList());
198 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
202 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
205 pObj
->SetStyleSheet(pNewStyleSheet
, bDontRemoveHardAttr
);
207 pObj
->NbcSetStyleSheet(pNewStyleSheet
, bDontRemoveHardAttr
, bAdjustTextFrameWidthAndHeight
);
211 void GroupProperties::ForceStyleToHardAttributes()
213 const SdrObjList
* pSub(static_cast<const SdrObjGroup
&>(GetSdrObject()).GetSubList());
214 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
217 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
218 pObj
->GetProperties().ForceStyleToHardAttributes();
220 } // end of namespace
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */