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/customshapeproperties.hxx>
31 #include <svl/itemset.hxx>
32 #include <svl/style.hxx>
33 #include <svx/svdoashp.hxx>
34 #include <editeng/eeitem.hxx>
35 #include <svx/sdtagitm.hxx>
36 #include <svl/whiter.hxx>
37 #include <svl/itemset.hxx>
38 #include <svl/smplhint.hxx>
39 
40 //////////////////////////////////////////////////////////////////////////////
41 
42 namespace sdr
43 {
44 	namespace properties
45 	{
46 		void CustomShapeProperties::UpdateTextFrameStatus()
47 		{
48 			SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
49 			SdrTextAutoGrowHeightItem& rAutoGrowHeightItem =
50 				(SdrTextAutoGrowHeightItem&)rObj.GetMergedItem( SDRATTR_TEXT_AUTOGROWHEIGHT );
51 			rObj.bTextFrame = rAutoGrowHeightItem.GetValue() != 0;
52 
53 			if ( rObj.bTextFrame )
54 				rObj.NbcAdjustTextFrameWidthAndHeight();
55 		}
56 
57 		SfxItemSet& CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
58 		{
59 			return *(new SfxItemSet(rPool,
60 
61 				// ranges from SdrAttrObj
62 				SDRATTR_START, SDRATTR_SHADOW_LAST,
63 				SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
64 				SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
65 
66 				// Graphic Attributes
67 				SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
68 
69 				// 3d Properties
70 				SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
71 
72 				// CustomShape properties
73 				SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
74 
75 				// range from SdrTextObj
76 				EE_ITEMS_START, EE_ITEMS_END,
77 
78 				// end
79 				0, 0));
80 		}
81 		sal_Bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
82 		{
83 			sal_Bool bAllowItemChange = sal_True;
84 			if ( !pNewItem )
85 			{
86 				if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
87 					bAllowItemChange = sal_False;
88 			}
89 			if ( bAllowItemChange )
90 				bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
91 			return bAllowItemChange;
92 		}
93 		void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
94 		{
95 			if ( !nWhich )
96 			{
97 				SfxWhichIter aIter( *mpItemSet );
98 				sal_uInt16 nWhich2 = aIter.FirstWhich();
99 				while( nWhich2 )
100 				{
101 					TextProperties::ClearObjectItemDirect( nWhich2 );
102 					nWhich2 = aIter.NextWhich();
103 				}
104 				SfxItemSet aSet((SfxItemPool&)(*GetSdrObject().GetObjectItemPool()));
105 				ItemSetChanged(aSet);
106 			}
107 			else
108 				TextProperties::ClearObjectItem( nWhich );
109 		}
110 		void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
111 		{
112 			if ( !nWhich )
113 			{
114 				SfxWhichIter aIter( *mpItemSet );
115 				sal_uInt16 nWhich2 = aIter.FirstWhich();
116 				while( nWhich2 )
117 				{
118 					TextProperties::ClearObjectItemDirect( nWhich2 );
119 					nWhich2 = aIter.NextWhich();
120 				}
121 			}
122 			else
123 				TextProperties::ClearObjectItemDirect( nWhich );
124 		}
125 		void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
126 		{
127 			SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
128 
129 			if( SFX_ITEM_SET == rSet.GetItemState( SDRATTR_TEXT_AUTOGROWHEIGHT ) )
130 			{
131 				rObj.bTextFrame = ((SdrTextAutoGrowHeightItem&)rSet.Get( SDRATTR_TEXT_AUTOGROWHEIGHT )).GetValue() != 0;
132 			}
133 
134 			// call parent
135 			TextProperties::ItemSetChanged(rSet);
136 
137 			// local changes, removing cached objects
138 			rObj.InvalidateRenderGeometry();
139 		}
140 		void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
141 		{
142 			SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
143 			//OutlinerParaObject* pParaObj = rObj.GetOutlinerParaObject();
144 
145 			if( pNewItem && ( SDRATTR_TEXT_AUTOGROWHEIGHT == nWhich ) )
146 			{
147 				rObj.bTextFrame = ((SdrTextAutoGrowHeightItem*)pNewItem)->GetValue() != 0;
148 			}
149 			// call parent
150 			TextProperties::ItemChange( nWhich, pNewItem );
151 
152 			rObj.InvalidateRenderGeometry();
153 		}
154 		void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
155 		{
156 			TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
157 			UpdateTextFrameStatus();
158 		}
159 		void CustomShapeProperties::ForceDefaultAttributes()
160 		{
161 			UpdateTextFrameStatus();
162 
163 /* SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
164 
165 			SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
166 			sal_Bool bTextFrame(rObj.IsTextFrame());
167 
168 			// force ItemSet
169 			GetObjectItemSet();
170 
171 			if(bTextFrame)
172 			{
173 				mpItemSet->Put(XLineStyleItem(XLINE_NONE));
174 				mpItemSet->Put(XFillColorItem(String(), Color(COL_WHITE)));
175 				mpItemSet->Put(XFillStyleItem(XFILL_NONE));
176 			}
177 			else
178 			{
179 				mpItemSet->Put(SvxAdjustItem(SVX_ADJUST_CENTER));
180 				mpItemSet->Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_CENTER));
181 				mpItemSet->Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
182 			}
183 */
184 		}
185 		CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
186 		:	TextProperties(rObj)
187 		{
188 		}
189 
190 		CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
191 		:	TextProperties(rProps, rObj)
192 		{
193 		}
194 
195 		CustomShapeProperties::~CustomShapeProperties()
196 		{
197 		}
198 
199 		BaseProperties& CustomShapeProperties::Clone(SdrObject& rObj) const
200 		{
201 			return *(new CustomShapeProperties(*this, rObj));
202 		}
203 		void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
204 		{
205 			TextProperties::Notify( rBC, rHint );
206 
207 			sal_Bool bRemoveRenderGeometry = sal_False;
208 
209 			const SfxStyleSheetHint *pStyleHint = PTR_CAST( SfxStyleSheetHint, &rHint );
210 			const SfxSimpleHint *pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
211 			if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
212 			{
213 				switch( pStyleHint->GetHint() )
214 				{
215 					case SFX_STYLESHEET_MODIFIED :
216 					case SFX_STYLESHEET_CHANGED	 :
217 						bRemoveRenderGeometry = sal_True;
218 					break;
219 				};
220 			}
221 			else if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DATACHANGED )
222 			{
223 				bRemoveRenderGeometry = sal_True;
224 			}
225 			if ( bRemoveRenderGeometry )
226 			{
227 				UpdateTextFrameStatus();
228 
229 				// local changes, removing cached objects
230 				SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
231 				rObj.InvalidateRenderGeometry();
232 			}
233 
234 		}
235 	} // end of namespace properties
236 } // end of namespace sdr
237 
238 //////////////////////////////////////////////////////////////////////////////
239 // eof
240