1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/sdr/properties/customshapeproperties.hxx>
21 #include <svl/itemset.hxx>
22 #include <svl/style.hxx>
23 #include <svx/svdoashp.hxx>
24 #include <editeng/eeitem.hxx>
25 #include <svx/sdtagitm.hxx>
26 #include <svl/whiter.hxx>
27 #include <svl/smplhint.hxx>
29 //////////////////////////////////////////////////////////////////////////////
35 void CustomShapeProperties::UpdateTextFrameStatus()
37 SdrTextObj
& rObj
= (SdrTextObj
&)GetSdrObject();
38 SdrTextAutoGrowHeightItem
& rAutoGrowHeightItem
=
39 (SdrTextAutoGrowHeightItem
&)rObj
.GetMergedItem( SDRATTR_TEXT_AUTOGROWHEIGHT
);
40 rObj
.bTextFrame
= rAutoGrowHeightItem
.GetValue() != 0;
42 if ( rObj
.bTextFrame
)
43 rObj
.NbcAdjustTextFrameWidthAndHeight();
46 SfxItemSet
& CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool
& rPool
)
48 return *(new SfxItemSet(rPool
,
50 // ranges from SdrAttrObj
51 SDRATTR_START
, SDRATTR_SHADOW_LAST
,
52 SDRATTR_MISC_FIRST
, SDRATTR_MISC_LAST
,
53 SDRATTR_TEXTDIRECTION
, SDRATTR_TEXTDIRECTION
,
56 SDRATTR_GRAF_FIRST
, SDRATTR_GRAF_LAST
,
59 SDRATTR_3D_FIRST
, SDRATTR_3D_LAST
,
61 // CustomShape properties
62 SDRATTR_CUSTOMSHAPE_FIRST
, SDRATTR_CUSTOMSHAPE_LAST
,
64 // range from SdrTextObj
65 EE_ITEMS_START
, EE_ITEMS_END
,
70 sal_Bool
CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich
, const SfxPoolItem
* pNewItem
) const
72 sal_Bool bAllowItemChange
= sal_True
;
75 if ( ( nWhich
>= SDRATTR_CUSTOMSHAPE_FIRST
) && ( nWhich
<= SDRATTR_CUSTOMSHAPE_LAST
) )
76 bAllowItemChange
= sal_False
;
78 if ( bAllowItemChange
)
79 bAllowItemChange
= TextProperties::AllowItemChange( nWhich
, pNewItem
);
80 return bAllowItemChange
;
82 void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich
)
86 SfxWhichIter
aIter( *mpItemSet
);
87 sal_uInt16 nWhich2
= aIter
.FirstWhich();
90 TextProperties::ClearObjectItemDirect( nWhich2
);
91 nWhich2
= aIter
.NextWhich();
93 SfxItemSet
aSet((SfxItemPool
&)(*GetSdrObject().GetObjectItemPool()));
97 TextProperties::ClearObjectItem( nWhich
);
99 void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich
)
103 SfxWhichIter
aIter( *mpItemSet
);
104 sal_uInt16 nWhich2
= aIter
.FirstWhich();
107 TextProperties::ClearObjectItemDirect( nWhich2
);
108 nWhich2
= aIter
.NextWhich();
112 TextProperties::ClearObjectItemDirect( nWhich
);
114 void CustomShapeProperties::ItemSetChanged(const SfxItemSet
& rSet
)
116 SdrObjCustomShape
& rObj
= (SdrObjCustomShape
&)GetSdrObject();
118 if( SFX_ITEM_SET
== rSet
.GetItemState( SDRATTR_TEXT_AUTOGROWHEIGHT
) )
120 rObj
.bTextFrame
= ((SdrTextAutoGrowHeightItem
&)rSet
.Get( SDRATTR_TEXT_AUTOGROWHEIGHT
)).GetValue() != 0;
124 TextProperties::ItemSetChanged(rSet
);
126 // local changes, removing cached objects
127 rObj
.InvalidateRenderGeometry();
129 void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich
, const SfxPoolItem
* pNewItem
)
131 SdrObjCustomShape
& rObj
= (SdrObjCustomShape
&)GetSdrObject();
132 //OutlinerParaObject* pParaObj = rObj.GetOutlinerParaObject();
134 if( pNewItem
&& ( SDRATTR_TEXT_AUTOGROWHEIGHT
== nWhich
) )
136 rObj
.bTextFrame
= ((SdrTextAutoGrowHeightItem
*)pNewItem
)->GetValue() != 0;
139 TextProperties::ItemChange( nWhich
, pNewItem
);
141 rObj
.InvalidateRenderGeometry();
143 void CustomShapeProperties::SetStyleSheet(SfxStyleSheet
* pNewStyleSheet
, sal_Bool bDontRemoveHardAttr
)
145 TextProperties::SetStyleSheet( pNewStyleSheet
, bDontRemoveHardAttr
);
146 UpdateTextFrameStatus();
148 void CustomShapeProperties::ForceDefaultAttributes()
150 UpdateTextFrameStatus();
152 /* SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
154 SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
155 sal_Bool bTextFrame(rObj.IsTextFrame());
162 mpItemSet->Put(XLineStyleItem(XLINE_NONE));
163 mpItemSet->Put(XFillColorItem(String(), Color(COL_WHITE)));
164 mpItemSet->Put(XFillStyleItem(XFILL_NONE));
168 mpItemSet->Put(SvxAdjustItem(SVX_ADJUST_CENTER));
169 mpItemSet->Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_CENTER));
170 mpItemSet->Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
174 CustomShapeProperties::CustomShapeProperties(SdrObject
& rObj
)
175 : TextProperties(rObj
)
179 CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties
& rProps
, SdrObject
& rObj
)
180 : TextProperties(rProps
, rObj
)
184 CustomShapeProperties::~CustomShapeProperties()
188 BaseProperties
& CustomShapeProperties::Clone(SdrObject
& rObj
) const
190 return *(new CustomShapeProperties(*this, rObj
));
192 void CustomShapeProperties::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
194 TextProperties::Notify( rBC
, rHint
);
196 sal_Bool bRemoveRenderGeometry
= sal_False
;
198 const SfxStyleSheetHint
*pStyleHint
= PTR_CAST( SfxStyleSheetHint
, &rHint
);
199 const SfxSimpleHint
*pSimpleHint
= PTR_CAST( SfxSimpleHint
, &rHint
);
200 if ( pStyleHint
&& pStyleHint
->GetStyleSheet() == GetStyleSheet() )
202 switch( pStyleHint
->GetHint() )
204 case SFX_STYLESHEET_MODIFIED
:
205 case SFX_STYLESHEET_CHANGED
:
206 bRemoveRenderGeometry
= sal_True
;
210 else if ( pSimpleHint
&& pSimpleHint
->GetId() == SFX_HINT_DATACHANGED
)
212 bRemoveRenderGeometry
= sal_True
;
214 if ( bRemoveRenderGeometry
)
216 UpdateTextFrameStatus();
218 // local changes, removing cached objects
219 SdrObjCustomShape
& rObj
= (SdrObjCustomShape
&)GetSdrObject();
220 rObj
.InvalidateRenderGeometry();
224 } // end of namespace properties
225 } // end of namespace sdr
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */