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