xref: /trunk/main/svx/source/sdr/properties/groupproperties.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <svx/sdr/properties/groupproperties.hxx>
27cdf0e10cSrcweir #include <svl/itemset.hxx>
28cdf0e10cSrcweir #include <svl/whiter.hxx>
29cdf0e10cSrcweir #include <svx/svddef.hxx>
30cdf0e10cSrcweir #include <editeng/eeitem.hxx>
31cdf0e10cSrcweir #include <svx/svdogrp.hxx>
32cdf0e10cSrcweir #include <svx/svdpool.hxx>
33cdf0e10cSrcweir #include <svx/svdpage.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace sdr
38cdf0e10cSrcweir {
39cdf0e10cSrcweir     namespace properties
40cdf0e10cSrcweir     {
41cdf0e10cSrcweir         // create a new itemset
CreateObjectSpecificItemSet(SfxItemPool & rPool)42cdf0e10cSrcweir         SfxItemSet& GroupProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
43cdf0e10cSrcweir         {
44cdf0e10cSrcweir             // Groups have in principle no ItemSet. To support methods like
45cdf0e10cSrcweir             // GetMergedItemSet() the local one is used. Thus, all items in the pool
46cdf0e10cSrcweir             // may be used and a pool itemset is created.
47cdf0e10cSrcweir             return *(new SfxItemSet(rPool));
48cdf0e10cSrcweir         }
49cdf0e10cSrcweir 
GroupProperties(SdrObject & rObj)50cdf0e10cSrcweir         GroupProperties::GroupProperties(SdrObject& rObj)
51cdf0e10cSrcweir         :   DefaultProperties(rObj)
52cdf0e10cSrcweir         {
53cdf0e10cSrcweir         }
54cdf0e10cSrcweir 
GroupProperties(const GroupProperties & rProps,SdrObject & rObj)55cdf0e10cSrcweir         GroupProperties::GroupProperties(const GroupProperties& rProps, SdrObject& rObj)
56cdf0e10cSrcweir         :   DefaultProperties(rProps, rObj)
57cdf0e10cSrcweir         {
58cdf0e10cSrcweir         }
59cdf0e10cSrcweir 
~GroupProperties()60cdf0e10cSrcweir         GroupProperties::~GroupProperties()
61cdf0e10cSrcweir         {
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir 
Clone(SdrObject & rObj) const64cdf0e10cSrcweir         BaseProperties& GroupProperties::Clone(SdrObject& rObj) const
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             return *(new GroupProperties(*this, rObj));
67cdf0e10cSrcweir         }
68cdf0e10cSrcweir 
GetObjectItemSet() const69cdf0e10cSrcweir         const SfxItemSet& GroupProperties::GetObjectItemSet() const
70cdf0e10cSrcweir         {
71cdf0e10cSrcweir             DBG_ASSERT(sal_False, "GroupProperties::GetObjectItemSet() should never be called (!)");
72cdf0e10cSrcweir             return DefaultProperties::GetObjectItemSet();
73cdf0e10cSrcweir         }
74cdf0e10cSrcweir 
GetMergedItemSet() const75cdf0e10cSrcweir         const SfxItemSet& GroupProperties::GetMergedItemSet() const
76cdf0e10cSrcweir         {
77cdf0e10cSrcweir             // prepare ItemSet
78cdf0e10cSrcweir             if(mpItemSet)
79cdf0e10cSrcweir             {
80cdf0e10cSrcweir                 // clear local itemset for merge
81cdf0e10cSrcweir                 mpItemSet->ClearItem();
82cdf0e10cSrcweir             }
83cdf0e10cSrcweir             else
84cdf0e10cSrcweir             {
85cdf0e10cSrcweir                 // force local itemset
86cdf0e10cSrcweir                 DefaultProperties::GetObjectItemSet();
87cdf0e10cSrcweir             }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir             // collect all ItemSets in mpItemSet
90cdf0e10cSrcweir             const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList();
91cdf0e10cSrcweir             const sal_uInt32 nCount(pSub->GetObjCount());
92cdf0e10cSrcweir 
93cdf0e10cSrcweir             for(sal_uInt32 a(0L); a < nCount; a++)
94cdf0e10cSrcweir             {
95cdf0e10cSrcweir                 const SfxItemSet& rSet = pSub->GetObj(a)->GetMergedItemSet();
96cdf0e10cSrcweir                 SfxWhichIter aIter(rSet);
97cdf0e10cSrcweir                 sal_uInt16 nWhich(aIter.FirstWhich());
98cdf0e10cSrcweir 
99cdf0e10cSrcweir                 while(nWhich)
100cdf0e10cSrcweir                 {
101cdf0e10cSrcweir                     if(SFX_ITEM_DONTCARE == rSet.GetItemState(nWhich, sal_False))
102cdf0e10cSrcweir                     {
103cdf0e10cSrcweir                         mpItemSet->InvalidateItem(nWhich);
104cdf0e10cSrcweir                     }
105cdf0e10cSrcweir                     else
106cdf0e10cSrcweir                     {
107cdf0e10cSrcweir                         mpItemSet->MergeValue(rSet.Get(nWhich), sal_True);
108cdf0e10cSrcweir                     }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir                     nWhich = aIter.NextWhich();
111cdf0e10cSrcweir                 }
112cdf0e10cSrcweir             }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir             // For group proerties, do not call parent since groups do
115cdf0e10cSrcweir             // not have local ItemSets.
116cdf0e10cSrcweir             return *mpItemSet;
117cdf0e10cSrcweir         }
118cdf0e10cSrcweir 
SetMergedItemSet(const SfxItemSet & rSet,sal_Bool bClearAllItems)119cdf0e10cSrcweir         void GroupProperties::SetMergedItemSet(const SfxItemSet& rSet, sal_Bool bClearAllItems)
120cdf0e10cSrcweir         {
121cdf0e10cSrcweir             // iterate over contained SdrObjects
122cdf0e10cSrcweir             const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList();
123cdf0e10cSrcweir             const sal_uInt32 nCount(pSub->GetObjCount());
124cdf0e10cSrcweir 
125cdf0e10cSrcweir             for(sal_uInt32 a(0L); a < nCount; a++)
126cdf0e10cSrcweir             {
127cdf0e10cSrcweir                 SdrObject* pObj = pSub->GetObj(a);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir                 if(pObj)
130cdf0e10cSrcweir                 {
131cdf0e10cSrcweir                     // Set merged ItemSet at contained object
132cdf0e10cSrcweir                     pObj->SetMergedItemSet(rSet, bClearAllItems);
133cdf0e10cSrcweir                 }
134cdf0e10cSrcweir             }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir             // Do not call parent here. Group objects do not have local ItemSets
137cdf0e10cSrcweir             // where items need to be set.
138cdf0e10cSrcweir             // DefaultProperties::SetMergedItemSet(rSet, bClearAllItems);
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir 
SetObjectItem(const SfxPoolItem &)141cdf0e10cSrcweir         void GroupProperties::SetObjectItem(const SfxPoolItem& /*rItem*/)
142cdf0e10cSrcweir         {
143cdf0e10cSrcweir             DBG_ASSERT(sal_False, "GroupProperties::SetObjectItem() should never be called (!)");
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir 
SetObjectItemDirect(const SfxPoolItem &)146cdf0e10cSrcweir         void GroupProperties::SetObjectItemDirect(const SfxPoolItem& /*rItem*/)
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir             DBG_ASSERT(sal_False, "GroupProperties::SetObjectItemDirect() should never be called (!)");
149cdf0e10cSrcweir         }
150cdf0e10cSrcweir 
ClearObjectItem(const sal_uInt16)151cdf0e10cSrcweir         void GroupProperties::ClearObjectItem(const sal_uInt16 /*nWhich*/)
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir             DBG_ASSERT(sal_False, "GroupProperties::ClearObjectItem() should never be called (!)");
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir 
ClearObjectItemDirect(const sal_uInt16)156cdf0e10cSrcweir         void GroupProperties::ClearObjectItemDirect(const sal_uInt16 /*nWhich*/)
157cdf0e10cSrcweir         {
158cdf0e10cSrcweir             DBG_ASSERT(sal_False, "GroupProperties::ClearObjectItemDirect() should never be called (!)");
159cdf0e10cSrcweir         }
160cdf0e10cSrcweir 
SetMergedItem(const SfxPoolItem & rItem)161cdf0e10cSrcweir         void GroupProperties::SetMergedItem(const SfxPoolItem& rItem)
162cdf0e10cSrcweir         {
163cdf0e10cSrcweir             const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList();
164cdf0e10cSrcweir             const sal_uInt32 nCount(pSub->GetObjCount());
165cdf0e10cSrcweir 
166cdf0e10cSrcweir             for(sal_uInt32 a(0L); a < nCount; a++)
167cdf0e10cSrcweir             {
168cdf0e10cSrcweir                 pSub->GetObj(a)->GetProperties().SetMergedItem(rItem);
169cdf0e10cSrcweir             }
170cdf0e10cSrcweir         }
171cdf0e10cSrcweir 
ClearMergedItem(const sal_uInt16 nWhich)172cdf0e10cSrcweir         void GroupProperties::ClearMergedItem(const sal_uInt16 nWhich)
173cdf0e10cSrcweir         {
174cdf0e10cSrcweir             const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList();
175cdf0e10cSrcweir             const sal_uInt32 nCount(pSub->GetObjCount());
176cdf0e10cSrcweir 
177cdf0e10cSrcweir             for(sal_uInt32 a(0L); a < nCount; a++)
178cdf0e10cSrcweir             {
179cdf0e10cSrcweir                 pSub->GetObj(a)->GetProperties().ClearMergedItem(nWhich);
180cdf0e10cSrcweir             }
181cdf0e10cSrcweir         }
182cdf0e10cSrcweir 
SetObjectItemSet(const SfxItemSet &)183cdf0e10cSrcweir         void GroupProperties::SetObjectItemSet(const SfxItemSet& /*rSet*/)
184cdf0e10cSrcweir         {
185cdf0e10cSrcweir             DBG_ASSERT(sal_False, "GroupProperties::SetObjectItemSet() should never be called (!)");
186cdf0e10cSrcweir         }
187cdf0e10cSrcweir 
ItemSetChanged(const SfxItemSet &)188cdf0e10cSrcweir         void GroupProperties::ItemSetChanged(const SfxItemSet& /*rSet*/)
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             DBG_ASSERT(sal_False, "GroupProperties::ItemSetChanged() should never be called (!)");
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir 
AllowItemChange(const sal_uInt16,const SfxPoolItem *) const193cdf0e10cSrcweir         sal_Bool GroupProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
194cdf0e10cSrcweir         {
195cdf0e10cSrcweir             DBG_ASSERT(sal_False, "GroupProperties::AllowItemChange() should never be called (!)");
196cdf0e10cSrcweir             return sal_False;
197cdf0e10cSrcweir         }
198cdf0e10cSrcweir 
ItemChange(const sal_uInt16,const SfxPoolItem *)199cdf0e10cSrcweir         void GroupProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
200cdf0e10cSrcweir         {
201cdf0e10cSrcweir             DBG_ASSERT(sal_False, "GroupProperties::ItemChange() should never be called (!)");
202cdf0e10cSrcweir         }
203cdf0e10cSrcweir 
PostItemChange(const sal_uInt16)204cdf0e10cSrcweir         void GroupProperties::PostItemChange(const sal_uInt16 /*nWhich*/)
205cdf0e10cSrcweir         {
206cdf0e10cSrcweir             DBG_ASSERT(sal_False, "GroupProperties::PostItemChange() should never be called (!)");
207cdf0e10cSrcweir         }
208cdf0e10cSrcweir 
GetStyleSheet() const209cdf0e10cSrcweir         SfxStyleSheet* GroupProperties::GetStyleSheet() const
210cdf0e10cSrcweir         {
211cdf0e10cSrcweir             SfxStyleSheet* pRetval = 0L;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir             const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList();
214cdf0e10cSrcweir             const sal_uInt32 nCount(pSub->GetObjCount());
215cdf0e10cSrcweir 
216cdf0e10cSrcweir             for(sal_uInt32 a(0L); a < nCount; a++)
217cdf0e10cSrcweir             {
218cdf0e10cSrcweir                 SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
219cdf0e10cSrcweir 
220cdf0e10cSrcweir                 if(pRetval)
221cdf0e10cSrcweir                 {
222cdf0e10cSrcweir                     if(pCandidate != pRetval)
223cdf0e10cSrcweir                     {
224cdf0e10cSrcweir                         // different StyleSheelts, return none
225cdf0e10cSrcweir                         return 0L;
226cdf0e10cSrcweir                     }
227cdf0e10cSrcweir                 }
228cdf0e10cSrcweir                 else
229cdf0e10cSrcweir                 {
230cdf0e10cSrcweir                     pRetval = pCandidate;
231cdf0e10cSrcweir                 }
232cdf0e10cSrcweir             }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir             return pRetval;
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir 
SetStyleSheet(SfxStyleSheet * pNewStyleSheet,sal_Bool bDontRemoveHardAttr)237cdf0e10cSrcweir         void GroupProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
238cdf0e10cSrcweir         {
239cdf0e10cSrcweir             const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList();
240cdf0e10cSrcweir             const sal_uInt32 nCount(pSub->GetObjCount());
241cdf0e10cSrcweir 
242cdf0e10cSrcweir             for(sal_uInt32 a(0L); a < nCount; a++)
243cdf0e10cSrcweir             {
244cdf0e10cSrcweir                 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
245cdf0e10cSrcweir             }
246cdf0e10cSrcweir         }
247cdf0e10cSrcweir 
ForceDefaultAttributes()248cdf0e10cSrcweir         void GroupProperties::ForceDefaultAttributes()
249cdf0e10cSrcweir         {
250cdf0e10cSrcweir             // nothing to do here, groups have no items and thus no default items, too.
251cdf0e10cSrcweir         }
252cdf0e10cSrcweir 
MoveToItemPool(SfxItemPool * pSrcPool,SfxItemPool * pDestPool,SdrModel * pNewModel)253cdf0e10cSrcweir         void GroupProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
254cdf0e10cSrcweir         {
255cdf0e10cSrcweir             if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
256cdf0e10cSrcweir             {
257cdf0e10cSrcweir                 const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList();
258cdf0e10cSrcweir                 const sal_uInt32 nCount(pSub->GetObjCount());
259cdf0e10cSrcweir 
260cdf0e10cSrcweir                 for(sal_uInt32 a(0L); a < nCount; a++)
261cdf0e10cSrcweir                 {
262cdf0e10cSrcweir                     pSub->GetObj(a)->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
263cdf0e10cSrcweir                 }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir                 // also clear local ItemSet, it's only temporary for group objects anyways.
266cdf0e10cSrcweir                 if(mpItemSet)
267cdf0e10cSrcweir                 {
268cdf0e10cSrcweir                     // #121905#
269cdf0e10cSrcweir                     // copy/paste is still using clone operators and MoveToItemPool functionality.
270cdf0e10cSrcweir                     // Since SfxItemSet contains a pool pointer, ClearItem is not enough here.
271cdf0e10cSrcweir                     // The ItemSet for merge is constructed on demand, so it's enough here to
272cdf0e10cSrcweir                     // just delete it and set to 0L.
273cdf0e10cSrcweir                     // mpItemSet->ClearItem();
274cdf0e10cSrcweir                     delete mpItemSet;
275cdf0e10cSrcweir                     mpItemSet = 0L;
276cdf0e10cSrcweir                 }
277cdf0e10cSrcweir             }
278cdf0e10cSrcweir         }
279cdf0e10cSrcweir 
ForceStyleToHardAttributes()280cdf0e10cSrcweir         void GroupProperties::ForceStyleToHardAttributes()
281cdf0e10cSrcweir         {
282cdf0e10cSrcweir             const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList();
283cdf0e10cSrcweir             const sal_uInt32 nCount(pSub->GetObjCount());
284cdf0e10cSrcweir 
285cdf0e10cSrcweir             for(sal_uInt32 a(0L); a < nCount; a++)
286cdf0e10cSrcweir             {
287cdf0e10cSrcweir                 pSub->GetObj(a)->GetProperties().ForceStyleToHardAttributes();
288cdf0e10cSrcweir             }
289cdf0e10cSrcweir         }
290cdf0e10cSrcweir     } // end of namespace properties
291cdf0e10cSrcweir } // end of namespace sdr
292cdf0e10cSrcweir 
293cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
294cdf0e10cSrcweir // eof
295