xref: /trunk/main/svx/source/sdr/properties/defaultproperties.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <svx/sdr/properties/defaultproperties.hxx>
27cdf0e10cSrcweir #include <svx/sdr/properties/itemsettools.hxx>
28cdf0e10cSrcweir #include <svl/itemset.hxx>
29cdf0e10cSrcweir #include <svl/whiter.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <vector>
32cdf0e10cSrcweir #include <svx/svdobj.hxx>
33cdf0e10cSrcweir #include <svx/svddef.hxx>
34cdf0e10cSrcweir #include <svx/svdpool.hxx>
35cdf0e10cSrcweir #include <editeng/eeitem.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace sdr
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     namespace properties
42cdf0e10cSrcweir     {
CreateObjectSpecificItemSet(SfxItemPool & rPool)43cdf0e10cSrcweir         SfxItemSet& DefaultProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
44cdf0e10cSrcweir         {
45cdf0e10cSrcweir             // Basic implementation; Basic object has NO attributes
46cdf0e10cSrcweir             return *(new SfxItemSet(rPool));
47cdf0e10cSrcweir         }
48cdf0e10cSrcweir 
DefaultProperties(SdrObject & rObj)49cdf0e10cSrcweir         DefaultProperties::DefaultProperties(SdrObject& rObj)
50cdf0e10cSrcweir         :   BaseProperties(rObj),
51cdf0e10cSrcweir             mpItemSet(0L)
52cdf0e10cSrcweir         {
53cdf0e10cSrcweir         }
54cdf0e10cSrcweir 
DefaultProperties(const DefaultProperties & rProps,SdrObject & rObj)55cdf0e10cSrcweir         DefaultProperties::DefaultProperties(const DefaultProperties& rProps, SdrObject& rObj)
56cdf0e10cSrcweir         :   BaseProperties(rObj),
57cdf0e10cSrcweir             mpItemSet(0L)
58cdf0e10cSrcweir         {
59cdf0e10cSrcweir             if(rProps.mpItemSet)
60cdf0e10cSrcweir             {
61cdf0e10cSrcweir                 mpItemSet = rProps.mpItemSet->Clone(sal_True);
62cdf0e10cSrcweir 
63*dcaf07f7SJohn Bampton                 // do not keep parent info, this may be changed by later constructors.
64cdf0e10cSrcweir                 // This class just copies the ItemSet, ignore parent.
65cdf0e10cSrcweir                 if(mpItemSet && mpItemSet->GetParent())
66cdf0e10cSrcweir                 {
67cdf0e10cSrcweir                     mpItemSet->SetParent(0L);
68cdf0e10cSrcweir                 }
69cdf0e10cSrcweir             }
70cdf0e10cSrcweir         }
71cdf0e10cSrcweir 
Clone(SdrObject & rObj) const72cdf0e10cSrcweir         BaseProperties& DefaultProperties::Clone(SdrObject& rObj) const
73cdf0e10cSrcweir         {
74cdf0e10cSrcweir             return *(new DefaultProperties(*this, rObj));
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir 
~DefaultProperties()77cdf0e10cSrcweir         DefaultProperties::~DefaultProperties()
78cdf0e10cSrcweir         {
79cdf0e10cSrcweir             if(mpItemSet)
80cdf0e10cSrcweir             {
81cdf0e10cSrcweir                 delete mpItemSet;
82cdf0e10cSrcweir                 mpItemSet = 0L;
83cdf0e10cSrcweir             }
84cdf0e10cSrcweir         }
85cdf0e10cSrcweir 
GetObjectItemSet() const86cdf0e10cSrcweir         const SfxItemSet& DefaultProperties::GetObjectItemSet() const
87cdf0e10cSrcweir         {
88cdf0e10cSrcweir             if(!mpItemSet)
89cdf0e10cSrcweir             {
90cdf0e10cSrcweir                 ((DefaultProperties*)this)->mpItemSet = &(((DefaultProperties*)this)->CreateObjectSpecificItemSet(*GetSdrObject().GetObjectItemPool()));
91cdf0e10cSrcweir                 ((DefaultProperties*)this)->ForceDefaultAttributes();
92cdf0e10cSrcweir             }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir             DBG_ASSERT(mpItemSet, "Could not create an SfxItemSet(!)");
95cdf0e10cSrcweir 
96cdf0e10cSrcweir             return *mpItemSet;
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir 
SetObjectItem(const SfxPoolItem & rItem)99cdf0e10cSrcweir         void DefaultProperties::SetObjectItem(const SfxPoolItem& rItem)
100cdf0e10cSrcweir         {
101cdf0e10cSrcweir             const sal_uInt16 nWhichID(rItem.Which());
102cdf0e10cSrcweir 
103cdf0e10cSrcweir             if(AllowItemChange(nWhichID, &rItem))
104cdf0e10cSrcweir             {
105cdf0e10cSrcweir                 ItemChange(nWhichID, &rItem);
106cdf0e10cSrcweir                 PostItemChange(nWhichID);
107cdf0e10cSrcweir 
108cdf0e10cSrcweir                 SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), nWhichID, nWhichID);
109cdf0e10cSrcweir                 aSet.Put(rItem);
110cdf0e10cSrcweir                 ItemSetChanged(aSet);
111cdf0e10cSrcweir             }
112cdf0e10cSrcweir         }
113cdf0e10cSrcweir 
SetObjectItemDirect(const SfxPoolItem & rItem)114cdf0e10cSrcweir         void DefaultProperties::SetObjectItemDirect(const SfxPoolItem& rItem)
115cdf0e10cSrcweir         {
116cdf0e10cSrcweir             const sal_uInt16 nWhichID(rItem.Which());
117cdf0e10cSrcweir 
118cdf0e10cSrcweir             if(AllowItemChange(nWhichID, &rItem))
119cdf0e10cSrcweir             {
120cdf0e10cSrcweir                 ItemChange(nWhichID, &rItem);
121cdf0e10cSrcweir             }
122cdf0e10cSrcweir         }
123cdf0e10cSrcweir 
ClearObjectItem(const sal_uInt16 nWhich)124cdf0e10cSrcweir         void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich)
125cdf0e10cSrcweir         {
126cdf0e10cSrcweir             if(AllowItemChange(nWhich))
127cdf0e10cSrcweir             {
128cdf0e10cSrcweir                 ItemChange(nWhich);
129cdf0e10cSrcweir                 PostItemChange(nWhich);
130cdf0e10cSrcweir 
131cdf0e10cSrcweir                 if(nWhich)
132cdf0e10cSrcweir                 {
133cdf0e10cSrcweir                     SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), nWhich, nWhich, 0, 0);
134cdf0e10cSrcweir                     ItemSetChanged(aSet);
135cdf0e10cSrcweir                 }
136cdf0e10cSrcweir             }
137cdf0e10cSrcweir         }
138cdf0e10cSrcweir 
ClearObjectItemDirect(const sal_uInt16 nWhich)139cdf0e10cSrcweir         void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
140cdf0e10cSrcweir         {
141cdf0e10cSrcweir             if(AllowItemChange(nWhich))
142cdf0e10cSrcweir             {
143cdf0e10cSrcweir                 ItemChange(nWhich);
144cdf0e10cSrcweir             }
145cdf0e10cSrcweir         }
146cdf0e10cSrcweir 
SetObjectItemSet(const SfxItemSet & rSet)147cdf0e10cSrcweir         void DefaultProperties::SetObjectItemSet(const SfxItemSet& rSet)
148cdf0e10cSrcweir         {
149cdf0e10cSrcweir             SfxWhichIter aWhichIter(rSet);
150cdf0e10cSrcweir             sal_uInt16 nWhich(aWhichIter.FirstWhich());
151cdf0e10cSrcweir             const SfxPoolItem *pPoolItem;
152cdf0e10cSrcweir             std::vector< sal_uInt16 > aPostItemChangeList;
153cdf0e10cSrcweir             sal_Bool bDidChange(sal_False);
154cdf0e10cSrcweir             SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), SDRATTR_START, EE_ITEMS_END, 0, 0);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir             // give a hint to STL_Vector
157cdf0e10cSrcweir             aPostItemChangeList.reserve(rSet.Count());
158cdf0e10cSrcweir 
159cdf0e10cSrcweir             while(nWhich)
160cdf0e10cSrcweir             {
161cdf0e10cSrcweir                 if(SFX_ITEM_SET == rSet.GetItemState(nWhich, sal_False, &pPoolItem))
162cdf0e10cSrcweir                 {
163cdf0e10cSrcweir                     if(AllowItemChange(nWhich, pPoolItem))
164cdf0e10cSrcweir                     {
165cdf0e10cSrcweir                         bDidChange = sal_True;
166cdf0e10cSrcweir                         ItemChange(nWhich, pPoolItem);
167cdf0e10cSrcweir                         aPostItemChangeList.push_back( nWhich );
168cdf0e10cSrcweir                         aSet.Put(*pPoolItem);
169cdf0e10cSrcweir                     }
170cdf0e10cSrcweir                 }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir                 nWhich = aWhichIter.NextWhich();
173cdf0e10cSrcweir             }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir             if(bDidChange)
176cdf0e10cSrcweir             {
177cdf0e10cSrcweir                 std::vector< sal_uInt16 >::iterator aIter = aPostItemChangeList.begin();
178cdf0e10cSrcweir                 const std::vector< sal_uInt16 >::iterator aEnd = aPostItemChangeList.end();
179cdf0e10cSrcweir 
180cdf0e10cSrcweir                 while(aIter != aEnd)
181cdf0e10cSrcweir                 {
182cdf0e10cSrcweir                     PostItemChange(*aIter);
183cdf0e10cSrcweir                     aIter++;
184cdf0e10cSrcweir                 }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir                 ItemSetChanged(aSet);
187cdf0e10cSrcweir             }
188cdf0e10cSrcweir         }
189cdf0e10cSrcweir 
ItemSetChanged(const SfxItemSet &)190cdf0e10cSrcweir         void DefaultProperties::ItemSetChanged(const SfxItemSet& /*rSet*/)
191cdf0e10cSrcweir         {
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir 
AllowItemChange(const sal_uInt16,const SfxPoolItem *) const194cdf0e10cSrcweir         sal_Bool DefaultProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
195cdf0e10cSrcweir         {
196cdf0e10cSrcweir             return sal_True;
197cdf0e10cSrcweir         }
198cdf0e10cSrcweir 
ItemChange(const sal_uInt16,const SfxPoolItem *)199cdf0e10cSrcweir         void DefaultProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
200cdf0e10cSrcweir         {
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir 
PostItemChange(const sal_uInt16 nWhich)203cdf0e10cSrcweir         void DefaultProperties::PostItemChange(const sal_uInt16 nWhich )
204cdf0e10cSrcweir         {
205cdf0e10cSrcweir             if( (nWhich == XATTR_FILLSTYLE) && (mpItemSet != NULL) )
206cdf0e10cSrcweir                 CleanupFillProperties(*mpItemSet);
207cdf0e10cSrcweir         }
208cdf0e10cSrcweir 
SetStyleSheet(SfxStyleSheet *,sal_Bool)209cdf0e10cSrcweir         void DefaultProperties::SetStyleSheet(SfxStyleSheet* /*pNewStyleSheet*/, sal_Bool /*bDontRemoveHardAttr*/)
210cdf0e10cSrcweir         {
211cdf0e10cSrcweir             // no StyleSheet in DefaultProperties
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir 
GetStyleSheet() const214cdf0e10cSrcweir         SfxStyleSheet* DefaultProperties::GetStyleSheet() const
215cdf0e10cSrcweir         {
216cdf0e10cSrcweir             // no StyleSheet in DefaultProperties
217cdf0e10cSrcweir             return 0L;
218cdf0e10cSrcweir         }
219cdf0e10cSrcweir 
ForceDefaultAttributes()220cdf0e10cSrcweir         void DefaultProperties::ForceDefaultAttributes()
221cdf0e10cSrcweir         {
222cdf0e10cSrcweir         }
223cdf0e10cSrcweir 
Scale(const Fraction & rScale)224cdf0e10cSrcweir         void DefaultProperties::Scale(const Fraction& rScale)
225cdf0e10cSrcweir         {
226cdf0e10cSrcweir             if(mpItemSet)
227cdf0e10cSrcweir             {
228cdf0e10cSrcweir                 ScaleItemSet(*mpItemSet, rScale);
229cdf0e10cSrcweir             }
230cdf0e10cSrcweir         }
231cdf0e10cSrcweir     } // end of namespace properties
232cdf0e10cSrcweir } // end of namespace sdr
233cdf0e10cSrcweir 
234cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
235cdf0e10cSrcweir // eof
236