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 
28 
29 namespace sdr::properties
30 {
31  // create a new itemset
32  std::unique_ptr<SfxItemSet> GroupProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
33  {
34  // Groups have in principle no ItemSet. To support methods like
35  // GetMergedItemSet() the local one is used. Thus, all items in the pool
36  // may be used and a pool itemset is created.
37  return std::make_unique<SfxItemSet>(rPool);
38  }
39 
41  : DefaultProperties(rObj)
42  {
43  }
44 
46  : DefaultProperties(rProps, rObj)
47  {
48  }
49 
51  {
52  }
53 
54  std::unique_ptr<BaseProperties> GroupProperties::Clone(SdrObject& rObj) const
55  {
56  return std::unique_ptr<BaseProperties>(new GroupProperties(*this, rObj));
57  }
58 
60  {
61  assert(!"GroupProperties::GetObjectItemSet() should never be called");
63  }
64 
66  {
67  // prepare ItemSet
68  if(mpItemSet)
69  {
70  // clear local itemset for merge
71  mpItemSet->ClearItem();
72  }
73  else
74  {
75  // force local itemset
77  }
78 
79  // collect all ItemSets in mpItemSet
80  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
81  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
82  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
83 
84  for(size_t a = 0; a < nCount; ++a)
85  {
86  const SfxItemSet& rSet = pSub->GetObj(a)->GetMergedItemSet();
87  SfxWhichIter aIter(rSet);
88  sal_uInt16 nWhich(aIter.FirstWhich());
89 
90  while(nWhich)
91  {
92  if(SfxItemState::DONTCARE == rSet.GetItemState(nWhich, false))
93  {
94  mpItemSet->InvalidateItem(nWhich);
95  }
96  else
97  {
98  mpItemSet->MergeValue(rSet.Get(nWhich), true);
99  }
100 
101  nWhich = aIter.NextWhich();
102  }
103  }
104 
105  // For group properties, do not call parent since groups do
106  // not have local ItemSets.
107  return *mpItemSet;
108  }
109 
110  void GroupProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems)
111  {
112  // iterate over contained SdrObjects
113  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
114  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
115  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
116 
117  for(size_t a = 0; a < nCount; ++a)
118  {
119  SdrObject* pObj = pSub->GetObj(a);
120 
121  if(pObj)
122  {
123  // Set merged ItemSet at contained object
124  pObj->SetMergedItemSet(rSet, bClearAllItems);
125  }
126  }
127 
128  // Do not call parent here. Group objects do not have local ItemSets
129  // where items need to be set.
130  // DefaultProperties::SetMergedItemSet(rSet, bClearAllItems);
131  }
132 
134  {
135  assert(!"GroupProperties::SetObjectItem() should never be called");
136  }
137 
139  {
140  assert(!"GroupProperties::SetObjectItemDirect() should never be called");
141  }
142 
143  void GroupProperties::ClearObjectItem(const sal_uInt16 nWhich)
144  {
145  // iterate over contained SdrObjects
146  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
147  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
148  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
149 
150  for(size_t a = 0; a < nCount; ++a)
151  {
152  SdrObject* pObj = pSub->GetObj(a);
153 
154  if(pObj)
155  {
156  pObj->GetProperties().ClearObjectItem(nWhich);
157  }
158  }
159  }
160 
161  void GroupProperties::ClearObjectItemDirect(const sal_uInt16 /*nWhich*/)
162  {
163  assert(!"GroupProperties::ClearObjectItemDirect() should never be called");
164  }
165 
167  {
168  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
169  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
170  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
171 
172  for(size_t a = 0; a < nCount; ++a)
173  {
174  pSub->GetObj(a)->GetProperties().SetMergedItem(rItem);
175  }
176  }
177 
178  void GroupProperties::ClearMergedItem(const sal_uInt16 nWhich)
179  {
180  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
181  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
182  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
183 
184  for(size_t a = 0; a < nCount; ++a)
185  {
186  pSub->GetObj(a)->GetProperties().ClearMergedItem(nWhich);
187  }
188  }
189 
191  {
192  assert(!"GroupProperties::SetObjectItemSet() should never be called");
193  }
194 
196  {
197  assert(!"GroupProperties::ItemSetChanged() should never be called");
198  }
199 
200  bool GroupProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
201  {
202  assert(!"GroupProperties::AllowItemChange() should never be called");
203  return false;
204  }
205 
206  void GroupProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
207  {
208  assert(!"GroupProperties::ItemChange() should never be called");
209  }
210 
211  void GroupProperties::PostItemChange(const sal_uInt16 /*nWhich*/)
212  {
213  assert(!"GroupProperties::PostItemChange() should never be called");
214  }
215 
217  {
218  SfxStyleSheet* pRetval = nullptr;
219 
220  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
221  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
222  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
223 
224  for(size_t a = 0; a < nCount; ++a)
225  {
226  SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
227 
228  if(pRetval)
229  {
230  if(pCandidate != pRetval)
231  {
232  // different StyleSheelts, return none
233  return nullptr;
234  }
235  }
236  else
237  {
238  pRetval = pCandidate;
239  }
240  }
241 
242  return pRetval;
243  }
244 
245  void GroupProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
246  {
247  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
248  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
249  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
250 
251  for(size_t a = 0; a < nCount; ++a)
252  {
253  pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
254  }
255  }
256 
258  {
259  // nothing to do here, groups have no items and thus no default items, too.
260  }
261 
263  {
264  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
265  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
266  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
267 
268  for(size_t a = 0; a < nCount; ++a)
269  {
271  }
272  }
273 } // end of namespace
274 
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void ForceDefaultAttributes() override
virtual void ClearObjectItemDirect(const sal_uInt16 nWhich) override
virtual const SfxItemSet & GetObjectItemSet() const override
virtual void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false) override
void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
Definition: svdobj.cxx:2145
virtual const SfxItemSet & GetObjectItemSet() const override
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:758
size_t GetObjCount() const
Definition: svdpage.cxx:752
sal_uInt16 FirstWhich()
virtual void SetObjectItemSet(const SfxItemSet &rSet) override
virtual sdr::properties::BaseProperties & GetProperties() const
Definition: svdobj.cxx:204
virtual const SfxItemSet & GetMergedItemSet() const override
std::unique_ptr< SfxItemSet > mpItemSet
virtual void SetMergedItem(const SfxPoolItem &rItem) override
sal_uInt16 NextWhich()
virtual void ForceStyleToHardAttributes()
Definition: properties.cxx:99
virtual void ClearMergedItem(const sal_uInt16 nWhich) override
virtual void ClearObjectItem(const sal_uInt16 nWhich=0)=0
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
virtual std::unique_ptr< SfxItemSet > CreateObjectSpecificItemSet(SfxItemPool &rPool) override
virtual void ClearObjectItem(const sal_uInt16 nWhich=0) override
virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) override
int nCount
virtual void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr) override
SfxStyleSheet * GetStyleSheet() const
Definition: svdobj.cxx:2140
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:1914
virtual void SetObjectItemDirect(const SfxPoolItem &rItem) override
virtual bool AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) const override
virtual void ItemSetChanged(const SfxItemSet &rSet) override
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
uno_Any a
virtual void SetObjectItem(const SfxPoolItem &rItem) override
Abstract DrawObject.
Definition: svdobj.hxx:312
virtual SfxStyleSheet * GetStyleSheet() const override
virtual void PostItemChange(const sal_uInt16 nWhich) override
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1889
virtual std::unique_ptr< BaseProperties > Clone(SdrObject &rObj) const override
virtual void SetMergedItem(const SfxPoolItem &rItem)
Definition: properties.cxx:87
const SdrObject & GetSdrObject() const
Definition: properties.cxx:59
virtual void ClearMergedItem(const sal_uInt16 nWhich)
Definition: properties.cxx:93
virtual void ForceStyleToHardAttributes() override