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/customshapeproperties.hxx>
27 #include <svl/itemset.hxx>
28 #include <svl/style.hxx>
29 #include <svx/svdoashp.hxx>
30 #include <editeng/eeitem.hxx>
31 #include <svx/sdtagitm.hxx>
32 #include <svl/whiter.hxx>
33 #include <svl/itemset.hxx>
34 #include <svl/smplhint.hxx>
35 
36 //////////////////////////////////////////////////////////////////////////////
37 
38 namespace sdr
39 {
40     namespace properties
41     {
UpdateTextFrameStatus(bool bInvalidateRenderGeometry)42         void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry)
43         {
44             SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
45             const bool bOld(rObj.bTextFrame);
46 
47             // change TextFrame flag when bResizeShapeToFitText changes (which is mapped
48             // on the item SDRATTR_TEXT_AUTOGROWHEIGHT for custom shapes, argh)
49             rObj.bTextFrame = 0 != static_cast< const SdrTextAutoGrowHeightItem& >(GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT)).GetValue();
50 
51             // check if it did change
52             if(rObj.bTextFrame != bOld)
53             {
54                 // on change also invalidate render geometry
55                 bInvalidateRenderGeometry = true;
56 
57                 // #115391# Potential recursion, since it calls SetObjectItemSet again, but rObj.bTextFrame
58                 // will not change again. Thus it will be only one level and terminate safely
59                 rObj.AdaptTextMinSize();
60             }
61 
62             if(bInvalidateRenderGeometry)
63             {
64                 // if asked for or bResizeShapeToFitText changed, make sure that
65                 // the render geometry is reconstructed using changed parameters
66                 rObj.InvalidateRenderGeometry();
67             }
68         }
69 
CreateObjectSpecificItemSet(SfxItemPool & rPool)70         SfxItemSet& CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
71         {
72             return *(new SfxItemSet(rPool,
73 
74                 // ranges from SdrAttrObj
75                 SDRATTR_START, SDRATTR_SHADOW_LAST,
76                 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
77                 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
78 
79                 // Graphic Attributes
80                 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
81 
82                 // 3d Properties
83                 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
84 
85                 // CustomShape properties
86                 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
87 
88                 // range from SdrTextObj
89                 EE_ITEMS_START, EE_ITEMS_END,
90 
91                 // end
92                 0, 0));
93         }
94 
AllowItemChange(const sal_uInt16 nWhich,const SfxPoolItem * pNewItem) const95         sal_Bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
96         {
97             sal_Bool bAllowItemChange = sal_True;
98             if ( !pNewItem )
99             {
100                 if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
101                     bAllowItemChange = sal_False;
102             }
103             if ( bAllowItemChange )
104                 bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
105             return bAllowItemChange;
106         }
107 
ClearObjectItem(const sal_uInt16 nWhich)108         void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
109         {
110             if ( !nWhich )
111             {
112                 SfxWhichIter aIter( *mpItemSet );
113                 sal_uInt16 nWhich2 = aIter.FirstWhich();
114                 while( nWhich2 )
115                 {
116                     TextProperties::ClearObjectItemDirect( nWhich2 );
117                     nWhich2 = aIter.NextWhich();
118                 }
119                 SfxItemSet aSet((SfxItemPool&)(*GetSdrObject().GetObjectItemPool()));
120                 ItemSetChanged(aSet);
121             }
122             else
123                 TextProperties::ClearObjectItem( nWhich );
124         }
125 
ClearObjectItemDirect(const sal_uInt16 nWhich)126         void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
127         {
128             if ( !nWhich )
129             {
130                 SfxWhichIter aIter( *mpItemSet );
131                 sal_uInt16 nWhich2 = aIter.FirstWhich();
132                 while( nWhich2 )
133                 {
134                     TextProperties::ClearObjectItemDirect( nWhich2 );
135                     nWhich2 = aIter.NextWhich();
136                 }
137             }
138             else
139                 TextProperties::ClearObjectItemDirect( nWhich );
140         }
141 
ItemSetChanged(const SfxItemSet & rSet)142         void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
143         {
144             // call parent
145             TextProperties::ItemSetChanged(rSet);
146 
147             // update bTextFrame and RenderGeometry
148             UpdateTextFrameStatus(true);
149         }
150 
PostItemChange(const sal_uInt16 nWhich)151         void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
152         {
153             switch(nWhich)
154             {
155                 case SDRATTR_TEXT_AUTOGROWHEIGHT:
156                 {
157                     // #115391#  update bTextFrame and RenderGeometry using AdaptTextMinSize()
158                     UpdateTextFrameStatus(false);
159                     break;
160                 }
161                 default:
162                 {
163                     break;
164                 }
165             }
166 
167             // call parent
168             TextProperties::PostItemChange(nWhich);
169         }
170 
ItemChange(const sal_uInt16 nWhich,const SfxPoolItem * pNewItem)171         void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
172         {
173             // call parent
174             TextProperties::ItemChange( nWhich, pNewItem );
175 
176             // update bTextFrame and RenderGeometry
177             UpdateTextFrameStatus(true);
178         }
179 
SetStyleSheet(SfxStyleSheet * pNewStyleSheet,sal_Bool bDontRemoveHardAttr)180         void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
181         {
182             // call parent
183             TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
184 
185             // update bTextFrame and RenderGeometry
186             UpdateTextFrameStatus(true);
187         }
188 
ForceDefaultAttributes()189         void CustomShapeProperties::ForceDefaultAttributes()
190         {
191             // update bTextFrame and RenderGeometry
192             UpdateTextFrameStatus(true);
193 
194             // SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
195             // This means: Do *not* call parent here is by purpose...
196         }
197 
CustomShapeProperties(SdrObject & rObj)198         CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
199         :   TextProperties(rObj)
200         {
201         }
202 
CustomShapeProperties(const CustomShapeProperties & rProps,SdrObject & rObj)203         CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
204         :   TextProperties(rProps, rObj)
205         {
206         }
207 
~CustomShapeProperties()208         CustomShapeProperties::~CustomShapeProperties()
209         {
210         }
211 
Clone(SdrObject & rObj) const212         BaseProperties& CustomShapeProperties::Clone(SdrObject& rObj) const
213         {
214             return *(new CustomShapeProperties(*this, rObj));
215         }
216 
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)217         void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
218         {
219             TextProperties::Notify( rBC, rHint );
220 
221             sal_Bool bRemoveRenderGeometry = sal_False;
222             const SfxStyleSheetHint *pStyleHint = PTR_CAST( SfxStyleSheetHint, &rHint );
223             const SfxSimpleHint *pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
224 
225             if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
226             {
227                 switch( pStyleHint->GetHint() )
228                 {
229                     case SFX_STYLESHEET_MODIFIED :
230                     case SFX_STYLESHEET_CHANGED	 :
231                         bRemoveRenderGeometry = sal_True;
232                     break;
233                 };
234             }
235             else if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DATACHANGED )
236             {
237                 bRemoveRenderGeometry = sal_True;
238             }
239 
240             // update bTextFrame and RenderGeometry
241             UpdateTextFrameStatus(bRemoveRenderGeometry);
242         }
243     } // end of namespace properties
244 } // end of namespace sdr
245 
246 //////////////////////////////////////////////////////////////////////////////
247 // eof
248