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