LibreOffice Module svx (master) 1
groupproperties.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
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>
28
29
30namespace sdr::properties
31{
33 : BaseProperties(rObj)
34 {
35 }
36
38 {
39 }
40
41 std::unique_ptr<BaseProperties> GroupProperties::Clone(SdrObject& rObj) const
42 {
43 return std::unique_ptr<BaseProperties>(new GroupProperties(rObj));
44 }
45
47 {
48 return SfxItemSet(rPool);
49 }
50
52 {
53 assert(!"GroupProperties::GetObjectItemSet() should never be called");
54 abort();
55 }
56
58 {
59 // prepare ItemSet
60 if(mxItemSet)
61 // clear local itemset for merge
62 mxItemSet->ClearItem();
63 else if(!mxItemSet)
64 // force local itemset
65 mxItemSet.emplace(GetSdrObject().GetObjectItemPool());
66
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 (!)");
70 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
71
72 for(size_t a = 0; a < nCount; ++a)
73 {
74 const SfxItemSet& rSet = pSub->GetObj(a)->GetMergedItemSet();
75 SfxWhichIter aIter(rSet);
76 sal_uInt16 nWhich(aIter.FirstWhich());
77
78 while(nWhich)
79 {
80 if(SfxItemState::DONTCARE == aIter.GetItemState(false))
81 {
82 mxItemSet->InvalidateItem(nWhich);
83 }
84 else
85 {
86 mxItemSet->MergeValue(rSet.Get(nWhich), true);
87 }
88
89 nWhich = aIter.NextWhich();
90 }
91 }
92
93 // For group properties, do not call parent since groups do
94 // not have local ItemSets.
95 return *mxItemSet;
96 }
97
98 void GroupProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems)
99 {
100 // iterate over contained SdrObjects
101 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
102 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
103 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
104
105 for(size_t a = 0; a < nCount; ++a)
106 {
107 SdrObject* pObj = pSub->GetObj(a);
108
109 if(pObj)
110 {
111 // Set merged ItemSet at contained object
112 pObj->SetMergedItemSet(rSet, bClearAllItems);
113 }
114 }
115
116 // Do not call parent here. Group objects do not have local ItemSets
117 // where items need to be set.
118 }
119
121 {
122 assert(!"GroupProperties::SetObjectItem() should never be called");
123 }
124
126 {
127 assert(!"GroupProperties::SetObjectItemDirect() should never be called");
128 }
129
130 void GroupProperties::ClearObjectItem(const sal_uInt16 nWhich)
131 {
132 // iterate over contained SdrObjects
133 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
134 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
135 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
136
137 for(size_t a = 0; a < nCount; ++a)
138 {
139 SdrObject* pObj = pSub->GetObj(a);
140
141 if(pObj)
142 {
143 pObj->GetProperties().ClearObjectItem(nWhich);
144 }
145 }
146 }
147
148 void GroupProperties::ClearObjectItemDirect(const sal_uInt16 /*nWhich*/)
149 {
150 assert(!"GroupProperties::ClearObjectItemDirect() should never be called");
151 }
152
154 {
155 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
156 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
157 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
158
159 for(size_t a = 0; a < nCount; ++a)
160 {
161 pSub->GetObj(a)->GetProperties().SetMergedItem(rItem);
162 }
163 }
164
165 void GroupProperties::ClearMergedItem(const sal_uInt16 nWhich)
166 {
167 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
168 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
169 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
170
171 for(size_t a = 0; a < nCount; ++a)
172 {
173 pSub->GetObj(a)->GetProperties().ClearMergedItem(nWhich);
174 }
175 }
176
178 {
179 assert(!"GroupProperties::SetObjectItemSet() should never be called");
180 }
181
183 {
184 SfxStyleSheet* pRetval = nullptr;
185
186 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
187 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
188 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
189
190 for(size_t a = 0; a < nCount; ++a)
191 {
192 SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
193
194 if(pRetval)
195 {
196 if(pCandidate != pRetval)
197 {
198 // different StyleSheelts, return none
199 return nullptr;
200 }
201 }
202 else
203 {
204 pRetval = pCandidate;
205 }
206 }
207
208 return pRetval;
209 }
210
211 void GroupProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr,
212 bool bBroadcast)
213 {
214 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
215 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
216 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
217
218 for(size_t a = 0; a < nCount; ++a)
219 {
220 if(bBroadcast)
221 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
222 else
223 pSub->GetObj(a)->NbcSetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
224 }
225 }
226
228 {
229 const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
230 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
231 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
232
233 for(size_t a = 0; a < nCount; ++a)
234 {
236 }
237 }
238} // end of namespace
239
240/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:822
size_t GetObjCount() const
Definition: svdpage.cxx:816
Abstract DrawObject.
Definition: svdobj.hxx:261
virtual sdr::properties::BaseProperties & GetProperties() const
Definition: svdobj.cxx:220
void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
Definition: svdobj.cxx:2252
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:2002
void NbcSetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
Definition: svdobj.cxx:2265
SfxStyleSheet * GetStyleSheet() const
Definition: svdobj.cxx:2247
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1977
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
sal_uInt16 FirstWhich()
SfxItemState GetItemState(bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
sal_uInt16 NextWhich()
virtual void ClearMergedItem(const sal_uInt16 nWhich)
Definition: properties.cxx:77
const SdrObject & GetSdrObject() const
Definition: properties.cxx:43
virtual void ForceStyleToHardAttributes()
Definition: properties.cxx:83
virtual void SetMergedItem(const SfxPoolItem &rItem)
Definition: properties.cxx:71
virtual void ClearObjectItem(const sal_uInt16 nWhich=0)=0
virtual const SfxItemSet & GetObjectItemSet() const override
virtual SfxStyleSheet * GetStyleSheet() const override
virtual void SetObjectItem(const SfxPoolItem &rItem) override
std::optional< SfxItemSet > mxItemSet
virtual SfxItemSet CreateObjectSpecificItemSet(SfxItemPool &pPool) override
virtual void SetObjectItemDirect(const SfxPoolItem &rItem) override
virtual void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false) override
virtual void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr, bool bBroadcast) override
virtual void SetMergedItem(const SfxPoolItem &rItem) override
virtual const SfxItemSet & GetMergedItemSet() const override
virtual void ClearMergedItem(const sal_uInt16 nWhich) override
virtual void SetObjectItemSet(const SfxItemSet &rSet) override
virtual void ClearObjectItem(const sal_uInt16 nWhich=0) override
virtual void ClearObjectItemDirect(const sal_uInt16 nWhich) override
virtual std::unique_ptr< BaseProperties > Clone(SdrObject &rObj) const override
virtual void ForceStyleToHardAttributes() override
int nCount
uno_Any a
static SfxItemSet & rSet