1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew 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 {
40215d8f42SArmin Le Grand     namespace properties
41215d8f42SArmin Le Grand     {
UpdateTextFrameStatus(bool bInvalidateRenderGeometry)42*e88cae92SArmin Le Grand         void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry)
43215d8f42SArmin Le Grand         {
44215d8f42SArmin Le Grand             SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
45215d8f42SArmin Le Grand             const bool bOld(rObj.bTextFrame);
46215d8f42SArmin Le Grand 
47*e88cae92SArmin Le Grand             // change TextFrame flag when bResizeShapeToFitText changes (which is mapped
48*e88cae92SArmin Le Grand             // on the item SDRATTR_TEXT_AUTOGROWHEIGHT for custom shapes, argh)
49215d8f42SArmin Le Grand             rObj.bTextFrame = 0 != static_cast< const SdrTextAutoGrowHeightItem& >(GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT)).GetValue();
50215d8f42SArmin Le Grand 
51*e88cae92SArmin Le Grand             // check if it did change
52215d8f42SArmin Le Grand             if(rObj.bTextFrame != bOld)
53215d8f42SArmin Le Grand             {
54*e88cae92SArmin Le Grand                 // on change also invalidate render geometry
55*e88cae92SArmin Le Grand                 bInvalidateRenderGeometry = true;
56215d8f42SArmin Le Grand 
57*e88cae92SArmin Le Grand                 // #115391# Potential recursion, since it calls SetObjectItemSet again, but rObj.bTextFrame
58*e88cae92SArmin Le Grand                 // will not change again. Thus it will be only one level and terminate safely
59215d8f42SArmin Le Grand                 rObj.AdaptTextMinSize();
60215d8f42SArmin Le Grand             }
61*e88cae92SArmin Le Grand 
62*e88cae92SArmin Le Grand             if(bInvalidateRenderGeometry)
63*e88cae92SArmin Le Grand             {
64*e88cae92SArmin Le Grand                 // if asked for or bResizeShapeToFitText changed, make sure that
65*e88cae92SArmin Le Grand                 // the render geometry is reconstructed using changed parameters
66*e88cae92SArmin Le Grand                 rObj.InvalidateRenderGeometry();
67*e88cae92SArmin Le Grand             }
68215d8f42SArmin Le Grand         }
69215d8f42SArmin Le Grand 
CreateObjectSpecificItemSet(SfxItemPool & rPool)70215d8f42SArmin Le Grand         SfxItemSet& CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
71215d8f42SArmin Le Grand         {
72215d8f42SArmin Le Grand             return *(new SfxItemSet(rPool,
73215d8f42SArmin Le Grand 
74215d8f42SArmin Le Grand                 // ranges from SdrAttrObj
75215d8f42SArmin Le Grand                 SDRATTR_START, SDRATTR_SHADOW_LAST,
76215d8f42SArmin Le Grand                 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
77215d8f42SArmin Le Grand                 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
78215d8f42SArmin Le Grand 
79215d8f42SArmin Le Grand                 // Graphic Attributes
80215d8f42SArmin Le Grand                 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
81215d8f42SArmin Le Grand 
82215d8f42SArmin Le Grand                 // 3d Properties
83215d8f42SArmin Le Grand                 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
84215d8f42SArmin Le Grand 
85215d8f42SArmin Le Grand                 // CustomShape properties
86215d8f42SArmin Le Grand                 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
87215d8f42SArmin Le Grand 
88215d8f42SArmin Le Grand                 // range from SdrTextObj
89215d8f42SArmin Le Grand                 EE_ITEMS_START, EE_ITEMS_END,
90215d8f42SArmin Le Grand 
91215d8f42SArmin Le Grand                 // end
92215d8f42SArmin Le Grand                 0, 0));
93215d8f42SArmin Le Grand         }
94215d8f42SArmin Le Grand 
AllowItemChange(const sal_uInt16 nWhich,const SfxPoolItem * pNewItem) const95215d8f42SArmin Le Grand         sal_Bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
96215d8f42SArmin Le Grand         {
97215d8f42SArmin Le Grand             sal_Bool bAllowItemChange = sal_True;
98215d8f42SArmin Le Grand             if ( !pNewItem )
99215d8f42SArmin Le Grand             {
100215d8f42SArmin Le Grand                 if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
101215d8f42SArmin Le Grand                     bAllowItemChange = sal_False;
102215d8f42SArmin Le Grand             }
103215d8f42SArmin Le Grand             if ( bAllowItemChange )
104215d8f42SArmin Le Grand                 bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
105215d8f42SArmin Le Grand             return bAllowItemChange;
106215d8f42SArmin Le Grand         }
107215d8f42SArmin Le Grand 
ClearObjectItem(const sal_uInt16 nWhich)108215d8f42SArmin Le Grand         void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
109215d8f42SArmin Le Grand         {
110215d8f42SArmin Le Grand             if ( !nWhich )
111215d8f42SArmin Le Grand             {
112215d8f42SArmin Le Grand                 SfxWhichIter aIter( *mpItemSet );
113215d8f42SArmin Le Grand                 sal_uInt16 nWhich2 = aIter.FirstWhich();
114215d8f42SArmin Le Grand                 while( nWhich2 )
115215d8f42SArmin Le Grand                 {
116215d8f42SArmin Le Grand                     TextProperties::ClearObjectItemDirect( nWhich2 );
117215d8f42SArmin Le Grand                     nWhich2 = aIter.NextWhich();
118215d8f42SArmin Le Grand                 }
119215d8f42SArmin Le Grand                 SfxItemSet aSet((SfxItemPool&)(*GetSdrObject().GetObjectItemPool()));
120215d8f42SArmin Le Grand                 ItemSetChanged(aSet);
121215d8f42SArmin Le Grand             }
122215d8f42SArmin Le Grand             else
123215d8f42SArmin Le Grand                 TextProperties::ClearObjectItem( nWhich );
124215d8f42SArmin Le Grand         }
125215d8f42SArmin Le Grand 
ClearObjectItemDirect(const sal_uInt16 nWhich)126215d8f42SArmin Le Grand         void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
127215d8f42SArmin Le Grand         {
128215d8f42SArmin Le Grand             if ( !nWhich )
129215d8f42SArmin Le Grand             {
130215d8f42SArmin Le Grand                 SfxWhichIter aIter( *mpItemSet );
131215d8f42SArmin Le Grand                 sal_uInt16 nWhich2 = aIter.FirstWhich();
132215d8f42SArmin Le Grand                 while( nWhich2 )
133215d8f42SArmin Le Grand                 {
134215d8f42SArmin Le Grand                     TextProperties::ClearObjectItemDirect( nWhich2 );
135215d8f42SArmin Le Grand                     nWhich2 = aIter.NextWhich();
136215d8f42SArmin Le Grand                 }
137215d8f42SArmin Le Grand             }
138215d8f42SArmin Le Grand             else
139215d8f42SArmin Le Grand                 TextProperties::ClearObjectItemDirect( nWhich );
140215d8f42SArmin Le Grand         }
141215d8f42SArmin Le Grand 
ItemSetChanged(const SfxItemSet & rSet)142215d8f42SArmin Le Grand         void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
143215d8f42SArmin Le Grand         {
144215d8f42SArmin Le Grand             // call parent
145215d8f42SArmin Le Grand             TextProperties::ItemSetChanged(rSet);
146215d8f42SArmin Le Grand 
147215d8f42SArmin Le Grand             // update bTextFrame and RenderGeometry
148*e88cae92SArmin Le Grand             UpdateTextFrameStatus(true);
149215d8f42SArmin Le Grand         }
150215d8f42SArmin Le Grand 
PostItemChange(const sal_uInt16 nWhich)151215d8f42SArmin Le Grand         void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
152215d8f42SArmin Le Grand         {
153215d8f42SArmin Le Grand             switch(nWhich)
154215d8f42SArmin Le Grand             {
155215d8f42SArmin Le Grand                 case SDRATTR_TEXT_AUTOGROWHEIGHT:
156215d8f42SArmin Le Grand                 {
157215d8f42SArmin Le Grand                     // #115391#  update bTextFrame and RenderGeometry using AdaptTextMinSize()
158*e88cae92SArmin Le Grand                     UpdateTextFrameStatus(false);
159215d8f42SArmin Le Grand                     break;
160215d8f42SArmin Le Grand                 }
161215d8f42SArmin Le Grand                 default:
162215d8f42SArmin Le Grand                 {
163215d8f42SArmin Le Grand                     break;
164215d8f42SArmin Le Grand                 }
165215d8f42SArmin Le Grand             }
166215d8f42SArmin Le Grand 
167215d8f42SArmin Le Grand             // call parent
168215d8f42SArmin Le Grand             TextProperties::PostItemChange(nWhich);
169215d8f42SArmin Le Grand         }
170215d8f42SArmin Le Grand 
ItemChange(const sal_uInt16 nWhich,const SfxPoolItem * pNewItem)171215d8f42SArmin Le Grand         void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
172215d8f42SArmin Le Grand         {
173215d8f42SArmin Le Grand             // call parent
174215d8f42SArmin Le Grand             TextProperties::ItemChange( nWhich, pNewItem );
175215d8f42SArmin Le Grand 
176215d8f42SArmin Le Grand             // update bTextFrame and RenderGeometry
177*e88cae92SArmin Le Grand             UpdateTextFrameStatus(true);
178215d8f42SArmin Le Grand         }
179215d8f42SArmin Le Grand 
SetStyleSheet(SfxStyleSheet * pNewStyleSheet,sal_Bool bDontRemoveHardAttr)180215d8f42SArmin Le Grand         void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
181215d8f42SArmin Le Grand         {
182215d8f42SArmin Le Grand             // call parent
183215d8f42SArmin Le Grand             TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
184215d8f42SArmin Le Grand 
185215d8f42SArmin Le Grand             // update bTextFrame and RenderGeometry
186*e88cae92SArmin Le Grand             UpdateTextFrameStatus(true);
187215d8f42SArmin Le Grand         }
188215d8f42SArmin Le Grand 
ForceDefaultAttributes()189215d8f42SArmin Le Grand         void CustomShapeProperties::ForceDefaultAttributes()
190215d8f42SArmin Le Grand         {
191215d8f42SArmin Le Grand             // update bTextFrame and RenderGeometry
192*e88cae92SArmin Le Grand             UpdateTextFrameStatus(true);
193215d8f42SArmin Le Grand 
194215d8f42SArmin Le Grand             // SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
195215d8f42SArmin Le Grand             // This means: Do *not* call parent here is by purpose...
196215d8f42SArmin Le Grand         }
197215d8f42SArmin Le Grand 
CustomShapeProperties(SdrObject & rObj)198215d8f42SArmin Le Grand         CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
199215d8f42SArmin Le Grand         :   TextProperties(rObj)
200215d8f42SArmin Le Grand         {
201215d8f42SArmin Le Grand         }
202215d8f42SArmin Le Grand 
CustomShapeProperties(const CustomShapeProperties & rProps,SdrObject & rObj)203215d8f42SArmin Le Grand         CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
204215d8f42SArmin Le Grand         :   TextProperties(rProps, rObj)
205215d8f42SArmin Le Grand         {
206215d8f42SArmin Le Grand         }
207215d8f42SArmin Le Grand 
~CustomShapeProperties()208215d8f42SArmin Le Grand         CustomShapeProperties::~CustomShapeProperties()
209215d8f42SArmin Le Grand         {
210215d8f42SArmin Le Grand         }
211215d8f42SArmin Le Grand 
Clone(SdrObject & rObj) const212215d8f42SArmin Le Grand         BaseProperties& CustomShapeProperties::Clone(SdrObject& rObj) const
213215d8f42SArmin Le Grand         {
214215d8f42SArmin Le Grand             return *(new CustomShapeProperties(*this, rObj));
215215d8f42SArmin Le Grand         }
216215d8f42SArmin Le Grand 
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)217215d8f42SArmin Le Grand         void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
218215d8f42SArmin Le Grand         {
219215d8f42SArmin Le Grand             TextProperties::Notify( rBC, rHint );
220215d8f42SArmin Le Grand 
221215d8f42SArmin Le Grand             sal_Bool bRemoveRenderGeometry = sal_False;
222215d8f42SArmin Le Grand             const SfxStyleSheetHint *pStyleHint = PTR_CAST( SfxStyleSheetHint, &rHint );
223215d8f42SArmin Le Grand             const SfxSimpleHint *pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
224215d8f42SArmin Le Grand 
225215d8f42SArmin Le Grand             if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
226215d8f42SArmin Le Grand             {
227215d8f42SArmin Le Grand                 switch( pStyleHint->GetHint() )
228215d8f42SArmin Le Grand                 {
229215d8f42SArmin Le Grand                     case SFX_STYLESHEET_MODIFIED :
230215d8f42SArmin Le Grand                     case SFX_STYLESHEET_CHANGED	 :
231215d8f42SArmin Le Grand                         bRemoveRenderGeometry = sal_True;
232215d8f42SArmin Le Grand                     break;
233215d8f42SArmin Le Grand                 };
234215d8f42SArmin Le Grand             }
235215d8f42SArmin Le Grand             else if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DATACHANGED )
236215d8f42SArmin Le Grand             {
237215d8f42SArmin Le Grand                 bRemoveRenderGeometry = sal_True;
238215d8f42SArmin Le Grand             }
239215d8f42SArmin Le Grand 
240*e88cae92SArmin Le Grand             // update bTextFrame and RenderGeometry
241*e88cae92SArmin Le Grand             UpdateTextFrameStatus(bRemoveRenderGeometry);
242215d8f42SArmin Le Grand         }
243215d8f42SArmin Le Grand     } // end of namespace properties
244cdf0e10cSrcweir } // end of namespace sdr
245cdf0e10cSrcweir 
246cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
247cdf0e10cSrcweir // eof
248