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/svddef.hxx>
26 #include <editeng/eeitem.hxx>
27 #include <svx/svdogrp.hxx>
28 #include <svx/svdpool.hxx>
29 #include <svx/svdpage.hxx>
30 
31 
32 namespace sdr
33 {
34  namespace properties
35  {
36  // create a new itemset
37  std::unique_ptr<SfxItemSet> GroupProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
38  {
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);
43  }
44 
46  : DefaultProperties(rObj)
47  {
48  }
49 
51  : DefaultProperties(rProps, rObj)
52  {
53  }
54 
56  {
57  }
58 
59  std::unique_ptr<BaseProperties> GroupProperties::Clone(SdrObject& rObj) const
60  {
61  return std::unique_ptr<BaseProperties>(new GroupProperties(*this, rObj));
62  }
63 
65  {
66  assert(!"GroupProperties::GetObjectItemSet() should never be called");
68  }
69 
71  {
72  // prepare ItemSet
73  if(mpItemSet)
74  {
75  // clear local itemset for merge
76  mpItemSet->ClearItem();
77  }
78  else
79  {
80  // force local itemset
82  }
83 
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());
88 
89  for(size_t a = 0; a < nCount; ++a)
90  {
91  const SfxItemSet& rSet = pSub->GetObj(a)->GetMergedItemSet();
92  SfxWhichIter aIter(rSet);
93  sal_uInt16 nWhich(aIter.FirstWhich());
94 
95  while(nWhich)
96  {
97  if(SfxItemState::DONTCARE == rSet.GetItemState(nWhich, false))
98  {
99  mpItemSet->InvalidateItem(nWhich);
100  }
101  else
102  {
103  mpItemSet->MergeValue(rSet.Get(nWhich), true);
104  }
105 
106  nWhich = aIter.NextWhich();
107  }
108  }
109 
110  // For group properties, do not call parent since groups do
111  // not have local ItemSets.
112  return *mpItemSet;
113  }
114 
115  void GroupProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems)
116  {
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());
121 
122  for(size_t a = 0; a < nCount; ++a)
123  {
124  SdrObject* pObj = pSub->GetObj(a);
125 
126  if(pObj)
127  {
128  // Set merged ItemSet at contained object
129  pObj->SetMergedItemSet(rSet, bClearAllItems);
130  }
131  }
132 
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);
136  }
137 
139  {
140  assert(!"GroupProperties::SetObjectItem() should never be called");
141  }
142 
144  {
145  assert(!"GroupProperties::SetObjectItemDirect() should never be called");
146  }
147 
148  void GroupProperties::ClearObjectItem(const sal_uInt16 /*nWhich*/)
149  {
150  assert(!"GroupProperties::ClearObjectItem() should never be called");
151  }
152 
153  void GroupProperties::ClearObjectItemDirect(const sal_uInt16 /*nWhich*/)
154  {
155  assert(!"GroupProperties::ClearObjectItemDirect() should never be called");
156  }
157 
159  {
160  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
161  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
162  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
163 
164  for(size_t a = 0; a < nCount; ++a)
165  {
166  pSub->GetObj(a)->GetProperties().SetMergedItem(rItem);
167  }
168  }
169 
170  void GroupProperties::ClearMergedItem(const sal_uInt16 nWhich)
171  {
172  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
173  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
174  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
175 
176  for(size_t a = 0; a < nCount; ++a)
177  {
178  pSub->GetObj(a)->GetProperties().ClearMergedItem(nWhich);
179  }
180  }
181 
183  {
184  assert(!"GroupProperties::SetObjectItemSet() should never be called");
185  }
186 
188  {
189  assert(!"GroupProperties::ItemSetChanged() should never be called");
190  }
191 
192  bool GroupProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
193  {
194  assert(!"GroupProperties::AllowItemChange() should never be called");
195  return false;
196  }
197 
198  void GroupProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
199  {
200  assert(!"GroupProperties::ItemChange() should never be called");
201  }
202 
203  void GroupProperties::PostItemChange(const sal_uInt16 /*nWhich*/)
204  {
205  assert(!"GroupProperties::PostItemChange() should never be called");
206  }
207 
209  {
210  SfxStyleSheet* pRetval = nullptr;
211 
212  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
213  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
214  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
215 
216  for(size_t a = 0; a < nCount; ++a)
217  {
218  SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
219 
220  if(pRetval)
221  {
222  if(pCandidate != pRetval)
223  {
224  // different StyleSheelts, return none
225  return nullptr;
226  }
227  }
228  else
229  {
230  pRetval = pCandidate;
231  }
232  }
233 
234  return pRetval;
235  }
236 
237  void GroupProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
238  {
239  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
240  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
241  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
242 
243  for(size_t a = 0; a < nCount; ++a)
244  {
245  pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
246  }
247  }
248 
250  {
251  // nothing to do here, groups have no items and thus no default items, too.
252  }
253 
255  {
256  const SdrObjList* pSub(static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList());
257  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
258  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
259 
260  for(size_t a = 0; a < nCount; ++a)
261  {
263  }
264  }
265  } // end of namespace properties
266 } // end of namespace sdr
267 
268 /* 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:2167
virtual const SfxItemSet & GetObjectItemSet() const override
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:773
size_t GetObjCount() const
Definition: svdpage.cxx:767
sal_uInt16 FirstWhich()
virtual void SetObjectItemSet(const SfxItemSet &rSet) override
virtual sdr::properties::BaseProperties & GetProperties() const
Definition: svdobj.cxx:230
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:102
virtual void ClearMergedItem(const sal_uInt16 nWhich) override
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:2162
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:1936
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:1911
virtual std::unique_ptr< BaseProperties > Clone(SdrObject &rObj) const override
virtual void SetMergedItem(const SfxPoolItem &rItem)
Definition: properties.cxx:90
const SdrObject & GetSdrObject() const
Definition: properties.cxx:62
virtual void ClearMergedItem(const sal_uInt16 nWhich)
Definition: properties.cxx:96
virtual void ForceStyleToHardAttributes() override