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