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/properties.hxx>
27 #include <svx/sdr/properties/itemsettools.hxx>
28 #include <svl/itemset.hxx>
29 #include <svx/svdogrp.hxx>
30 #include <svx/svditer.hxx>
31 #include <svx/xfillit0.hxx>
32 
33 //////////////////////////////////////////////////////////////////////////////
34 
35 namespace sdr
36 {
37 	namespace properties
38 	{
BaseProperties(SdrObject & rObj)39 		BaseProperties::BaseProperties(SdrObject& rObj)
40 		:	mrObject(rObj)
41 		{
42 		}
43 
BaseProperties(const BaseProperties &,SdrObject & rObj)44 		BaseProperties::BaseProperties(const BaseProperties& /*rProps*/, SdrObject& rObj)
45 		:	mrObject(rObj)
46 		{
47 		}
48 
~BaseProperties()49 		BaseProperties::~BaseProperties()
50 		{
51 		}
52 
GetMergedItemSet() const53 		const SfxItemSet& BaseProperties::GetMergedItemSet() const
54 		{
55 			// default implementation falls back to GetObjectItemSet()
56 			return GetObjectItemSet();
57 		}
58 
SetMergedItemSet(const SfxItemSet & rSet,sal_Bool bClearAllItems)59 		void BaseProperties::SetMergedItemSet(const SfxItemSet& rSet, sal_Bool bClearAllItems)
60 		{
61 			// clear items if requested
62 			if(bClearAllItems)
63 			{
64 				ClearObjectItem();
65 			}
66 
67 			// default implementation falls back to SetObjectItemSet()
68 			SetObjectItemSet(rSet);
69 		}
70 
SetMergedItem(const SfxPoolItem & rItem)71 		void BaseProperties::SetMergedItem(const SfxPoolItem& rItem)
72 		{
73 			// default implementation falls back to SetObjectItem()
74 			SetObjectItem(rItem);
75 		}
76 
ClearMergedItem(const sal_uInt16 nWhich)77 		void BaseProperties::ClearMergedItem(const sal_uInt16 nWhich)
78 		{
79 			// default implementation falls back to ClearObjectItem()
80 			ClearObjectItem(nWhich);
81 		}
82 
Scale(const Fraction &)83 		void BaseProperties::Scale(const Fraction& /*rScale*/)
84 		{
85 			// default implementation does nothing; overload where
86 			// an ItemSet is implemented.
87 		}
88 
MoveToItemPool(SfxItemPool *,SfxItemPool *,SdrModel *)89 		void BaseProperties::MoveToItemPool(SfxItemPool* /*pSrcPool*/, SfxItemPool* /*pDestPool*/, SdrModel* /*pNewModel*/)
90 		{
91 			// Move properties to a new ItemPool. Default implementation does nothing.
92 			// Overload where an ItemSet is implemented.
93 		}
94 
SetModel(SdrModel *,SdrModel *)95 		void BaseProperties::SetModel(SdrModel* /*pOldModel*/, SdrModel* /*pNewModel*/)
96 		{
97 			// Set new model. Default implementation does nothing.
98 			// Overload where an ItemSet is implemented.
99 		}
100 
ForceStyleToHardAttributes()101 		void BaseProperties::ForceStyleToHardAttributes()
102 		{
103 			// force all attributes which come from styles to hard attributes
104 			// to be able to live without the style. Default implementation does nothing.
105 			// Overload where an ItemSet is implemented.
106 		}
107 
108 		//void BaseProperties::SetItemAndBroadcast(const SfxPoolItem& rItem)
109 		//{
110 		//	ItemChangeBroadcaster aC(GetSdrObject());
111 		//	SetObjectItem(rItem);
112 		//	BroadcastItemChange(aC);
113 		//}
114 
115 		//void BaseProperties::ClearItemAndBroadcast(const sal_uInt16 nWhich)
116 		//{
117 		//	ItemChangeBroadcaster aC(GetSdrObject());
118 		//	ClearObjectItem(nWhich);
119 		//	BroadcastItemChange(aC);
120 		//}
121 
SetMergedItemSetAndBroadcast(const SfxItemSet & rSet,sal_Bool bClearAllItems)122 		void BaseProperties::SetMergedItemSetAndBroadcast(const SfxItemSet& rSet, sal_Bool bClearAllItems)
123 		{
124 			ItemChangeBroadcaster aC(GetSdrObject());
125 
126 			if(bClearAllItems)
127 			{
128 				ClearObjectItem();
129 			}
130 
131 			SetMergedItemSet(rSet);
132 			BroadcastItemChange(aC);
133 		}
134 
GetItem(const sal_uInt16 nWhich) const135 		const SfxPoolItem& BaseProperties::GetItem(const sal_uInt16 nWhich) const
136 		{
137 			return GetObjectItemSet().Get(nWhich);
138 		}
139 
BroadcastItemChange(const ItemChangeBroadcaster & rChange)140 		void BaseProperties::BroadcastItemChange(const ItemChangeBroadcaster& rChange)
141 		{
142 			const sal_uInt32 nCount(rChange.GetRectangleCount());
143 
144 			// #110094#-14 Reduce to do only second change
145 			//// invalidate all remembered rectangles
146 			//for(sal_uInt32 a(0); a < nCount; a++)
147 			//{
148 			//	GetSdrObject().BroadcastObjectChange(rChange.GetRectangle(a));
149 			//}
150 
151 			// invalidate all new rectangles
152 			if(GetSdrObject().ISA(SdrObjGroup))
153 			{
154 				SdrObjListIter aIter((SdrObjGroup&)GetSdrObject(), IM_DEEPNOGROUPS);
155 
156 				while(aIter.IsMore())
157 				{
158 					SdrObject* pObj = aIter.Next();
159 					// This is done with ItemSetChanged
160 					// pObj->SetChanged();
161 					pObj->BroadcastObjectChange();
162 				}
163 			}
164 			else
165 			{
166 				// This is done with ItemSetChanged
167 				// GetSdrObject().SetChanged();
168 				GetSdrObject().BroadcastObjectChange();
169 			}
170 
171 			// also send the user calls
172 			for(sal_uInt32 a(0L); a < nCount; a++)
173 			{
174 				GetSdrObject().SendUserCall(SDRUSERCALL_CHGATTR, rChange.GetRectangle(a));
175 			}
176 		}
177 
getVersion() const178         sal_uInt32 BaseProperties::getVersion() const
179         {
180             return 0;
181         }
182 
CleanupFillProperties(SfxItemSet & rItemSet)183 		void CleanupFillProperties( SfxItemSet& rItemSet )
184 		{
185 			const bool bFillBitmap = rItemSet.GetItemState(XATTR_FILLBITMAP, sal_False) == SFX_ITEM_SET;
186 			const bool bFillGradient = rItemSet.GetItemState(XATTR_FILLGRADIENT, sal_False) == SFX_ITEM_SET;
187 			const bool bFillHatch = rItemSet.GetItemState(XATTR_FILLHATCH, sal_False) == SFX_ITEM_SET;
188 			if( bFillBitmap || bFillGradient || bFillHatch )
189 			{
190 				const XFillStyleItem* pFillStyleItem = dynamic_cast< const XFillStyleItem* >( rItemSet.GetItem(XATTR_FILLSTYLE) );
191 				if( pFillStyleItem )
192 				{
193 					if( bFillBitmap && (pFillStyleItem->GetValue() != XFILL_BITMAP) )
194 					{
195 						rItemSet.ClearItem( XATTR_FILLBITMAP );
196 					}
197 
198 					if( bFillGradient && (pFillStyleItem->GetValue() != XFILL_GRADIENT) )
199 					{
200 						rItemSet.ClearItem( XATTR_FILLGRADIENT );
201 					}
202 
203 					if( bFillHatch && (pFillStyleItem->GetValue() != XFILL_HATCH) )
204 					{
205 						rItemSet.ClearItem( XATTR_FILLHATCH );
206 					}
207 				}
208 			}
209 		}
210 
211 	} // end of namespace properties
212 } // end of namespace sdr
213 
214 //////////////////////////////////////////////////////////////////////////////
215 // eof
216