xref: /AOO41X/main/svx/source/sdr/properties/customshapeproperties.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <svx/sdr/properties/customshapeproperties.hxx>
27cdf0e10cSrcweir #include <svl/itemset.hxx>
28cdf0e10cSrcweir #include <svl/style.hxx>
29cdf0e10cSrcweir #include <svx/svdoashp.hxx>
30cdf0e10cSrcweir #include <editeng/eeitem.hxx>
31cdf0e10cSrcweir #include <svx/sdtagitm.hxx>
32cdf0e10cSrcweir #include <svl/whiter.hxx>
33cdf0e10cSrcweir #include <svl/itemset.hxx>
34cdf0e10cSrcweir #include <svl/smplhint.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace sdr
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 	namespace properties
41cdf0e10cSrcweir 	{
42cdf0e10cSrcweir 		void CustomShapeProperties::UpdateTextFrameStatus()
43cdf0e10cSrcweir 		{
44cdf0e10cSrcweir 			SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
45cdf0e10cSrcweir 			SdrTextAutoGrowHeightItem& rAutoGrowHeightItem =
46cdf0e10cSrcweir 				(SdrTextAutoGrowHeightItem&)rObj.GetMergedItem( SDRATTR_TEXT_AUTOGROWHEIGHT );
47cdf0e10cSrcweir 			rObj.bTextFrame = rAutoGrowHeightItem.GetValue() != 0;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 			if ( rObj.bTextFrame )
50cdf0e10cSrcweir 				rObj.NbcAdjustTextFrameWidthAndHeight();
51cdf0e10cSrcweir 		}
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 		SfxItemSet& CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
54cdf0e10cSrcweir 		{
55cdf0e10cSrcweir 			return *(new SfxItemSet(rPool,
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 				// ranges from SdrAttrObj
58cdf0e10cSrcweir 				SDRATTR_START, SDRATTR_SHADOW_LAST,
59cdf0e10cSrcweir 				SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
60cdf0e10cSrcweir 				SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 				// Graphic Attributes
63cdf0e10cSrcweir 				SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 				// 3d Properties
66cdf0e10cSrcweir 				SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 				// CustomShape properties
69cdf0e10cSrcweir 				SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 				// range from SdrTextObj
72cdf0e10cSrcweir 				EE_ITEMS_START, EE_ITEMS_END,
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 				// end
75cdf0e10cSrcweir 				0, 0));
76cdf0e10cSrcweir 		}
77cdf0e10cSrcweir 		sal_Bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
78cdf0e10cSrcweir 		{
79cdf0e10cSrcweir 			sal_Bool bAllowItemChange = sal_True;
80cdf0e10cSrcweir 			if ( !pNewItem )
81cdf0e10cSrcweir 			{
82cdf0e10cSrcweir 				if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
83cdf0e10cSrcweir 					bAllowItemChange = sal_False;
84cdf0e10cSrcweir 			}
85cdf0e10cSrcweir 			if ( bAllowItemChange )
86cdf0e10cSrcweir 				bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
87cdf0e10cSrcweir 			return bAllowItemChange;
88cdf0e10cSrcweir 		}
89cdf0e10cSrcweir 		void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
90cdf0e10cSrcweir 		{
91cdf0e10cSrcweir 			if ( !nWhich )
92cdf0e10cSrcweir 			{
93cdf0e10cSrcweir 				SfxWhichIter aIter( *mpItemSet );
94cdf0e10cSrcweir 				sal_uInt16 nWhich2 = aIter.FirstWhich();
95cdf0e10cSrcweir 				while( nWhich2 )
96cdf0e10cSrcweir 				{
97cdf0e10cSrcweir 					TextProperties::ClearObjectItemDirect( nWhich2 );
98cdf0e10cSrcweir 					nWhich2 = aIter.NextWhich();
99cdf0e10cSrcweir 				}
100cdf0e10cSrcweir 				SfxItemSet aSet((SfxItemPool&)(*GetSdrObject().GetObjectItemPool()));
101cdf0e10cSrcweir 				ItemSetChanged(aSet);
102cdf0e10cSrcweir 			}
103cdf0e10cSrcweir 			else
104cdf0e10cSrcweir 				TextProperties::ClearObjectItem( nWhich );
105cdf0e10cSrcweir 		}
106cdf0e10cSrcweir 		void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
107cdf0e10cSrcweir 		{
108cdf0e10cSrcweir 			if ( !nWhich )
109cdf0e10cSrcweir 			{
110cdf0e10cSrcweir 				SfxWhichIter aIter( *mpItemSet );
111cdf0e10cSrcweir 				sal_uInt16 nWhich2 = aIter.FirstWhich();
112cdf0e10cSrcweir 				while( nWhich2 )
113cdf0e10cSrcweir 				{
114cdf0e10cSrcweir 					TextProperties::ClearObjectItemDirect( nWhich2 );
115cdf0e10cSrcweir 					nWhich2 = aIter.NextWhich();
116cdf0e10cSrcweir 				}
117cdf0e10cSrcweir 			}
118cdf0e10cSrcweir 			else
119cdf0e10cSrcweir 				TextProperties::ClearObjectItemDirect( nWhich );
120cdf0e10cSrcweir 		}
121cdf0e10cSrcweir 		void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
122cdf0e10cSrcweir 		{
123cdf0e10cSrcweir 			SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 			if( SFX_ITEM_SET == rSet.GetItemState( SDRATTR_TEXT_AUTOGROWHEIGHT ) )
126cdf0e10cSrcweir 			{
127cdf0e10cSrcweir 				rObj.bTextFrame = ((SdrTextAutoGrowHeightItem&)rSet.Get( SDRATTR_TEXT_AUTOGROWHEIGHT )).GetValue() != 0;
128cdf0e10cSrcweir 			}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 			// call parent
131cdf0e10cSrcweir 			TextProperties::ItemSetChanged(rSet);
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 			// local changes, removing cached objects
134cdf0e10cSrcweir 			rObj.InvalidateRenderGeometry();
135cdf0e10cSrcweir 		}
136cdf0e10cSrcweir 		void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
137cdf0e10cSrcweir 		{
138cdf0e10cSrcweir 			SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
139cdf0e10cSrcweir 			//OutlinerParaObject* pParaObj = rObj.GetOutlinerParaObject();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 			if( pNewItem && ( SDRATTR_TEXT_AUTOGROWHEIGHT == nWhich ) )
142cdf0e10cSrcweir 			{
143cdf0e10cSrcweir 				rObj.bTextFrame = ((SdrTextAutoGrowHeightItem*)pNewItem)->GetValue() != 0;
144cdf0e10cSrcweir 			}
145cdf0e10cSrcweir 			// call parent
146cdf0e10cSrcweir 			TextProperties::ItemChange( nWhich, pNewItem );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 			rObj.InvalidateRenderGeometry();
149cdf0e10cSrcweir 		}
150cdf0e10cSrcweir 		void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
151cdf0e10cSrcweir 		{
152cdf0e10cSrcweir 			TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
153cdf0e10cSrcweir 			UpdateTextFrameStatus();
154cdf0e10cSrcweir 		}
155cdf0e10cSrcweir 		void CustomShapeProperties::ForceDefaultAttributes()
156cdf0e10cSrcweir 		{
157cdf0e10cSrcweir 			UpdateTextFrameStatus();
158cdf0e10cSrcweir 
159cdf0e10cSrcweir /* SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 			SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
162cdf0e10cSrcweir 			sal_Bool bTextFrame(rObj.IsTextFrame());
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 			// force ItemSet
165cdf0e10cSrcweir 			GetObjectItemSet();
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 			if(bTextFrame)
168cdf0e10cSrcweir 			{
169cdf0e10cSrcweir 				mpItemSet->Put(XLineStyleItem(XLINE_NONE));
170cdf0e10cSrcweir 				mpItemSet->Put(XFillColorItem(String(), Color(COL_WHITE)));
171cdf0e10cSrcweir 				mpItemSet->Put(XFillStyleItem(XFILL_NONE));
172cdf0e10cSrcweir 			}
173cdf0e10cSrcweir 			else
174cdf0e10cSrcweir 			{
175cdf0e10cSrcweir 				mpItemSet->Put(SvxAdjustItem(SVX_ADJUST_CENTER));
176cdf0e10cSrcweir 				mpItemSet->Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_CENTER));
177cdf0e10cSrcweir 				mpItemSet->Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
178cdf0e10cSrcweir 			}
179cdf0e10cSrcweir */
180cdf0e10cSrcweir 		}
181cdf0e10cSrcweir 		CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
182cdf0e10cSrcweir 		:	TextProperties(rObj)
183cdf0e10cSrcweir 		{
184cdf0e10cSrcweir 		}
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 		CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
187cdf0e10cSrcweir 		:	TextProperties(rProps, rObj)
188cdf0e10cSrcweir 		{
189cdf0e10cSrcweir 		}
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 		CustomShapeProperties::~CustomShapeProperties()
192cdf0e10cSrcweir 		{
193cdf0e10cSrcweir 		}
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 		BaseProperties& CustomShapeProperties::Clone(SdrObject& rObj) const
196cdf0e10cSrcweir 		{
197cdf0e10cSrcweir 			return *(new CustomShapeProperties(*this, rObj));
198cdf0e10cSrcweir 		}
199cdf0e10cSrcweir 		void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
200cdf0e10cSrcweir 		{
201cdf0e10cSrcweir 			TextProperties::Notify( rBC, rHint );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 			sal_Bool bRemoveRenderGeometry = sal_False;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 			const SfxStyleSheetHint *pStyleHint = PTR_CAST( SfxStyleSheetHint, &rHint );
206cdf0e10cSrcweir 			const SfxSimpleHint *pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
207cdf0e10cSrcweir 			if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
208cdf0e10cSrcweir 			{
209cdf0e10cSrcweir 				switch( pStyleHint->GetHint() )
210cdf0e10cSrcweir 				{
211cdf0e10cSrcweir 					case SFX_STYLESHEET_MODIFIED :
212cdf0e10cSrcweir 					case SFX_STYLESHEET_CHANGED	 :
213cdf0e10cSrcweir 						bRemoveRenderGeometry = sal_True;
214cdf0e10cSrcweir 					break;
215cdf0e10cSrcweir 				};
216cdf0e10cSrcweir 			}
217cdf0e10cSrcweir 			else if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DATACHANGED )
218cdf0e10cSrcweir 			{
219cdf0e10cSrcweir 				bRemoveRenderGeometry = sal_True;
220cdf0e10cSrcweir 			}
221cdf0e10cSrcweir 			if ( bRemoveRenderGeometry )
222cdf0e10cSrcweir 			{
223cdf0e10cSrcweir 				UpdateTextFrameStatus();
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 				// local changes, removing cached objects
226cdf0e10cSrcweir 				SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
227cdf0e10cSrcweir 				rObj.InvalidateRenderGeometry();
228cdf0e10cSrcweir 			}
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 		}
231cdf0e10cSrcweir 	} // end of namespace properties
232cdf0e10cSrcweir } // end of namespace sdr
233cdf0e10cSrcweir 
234cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
235cdf0e10cSrcweir // eof
236