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