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 <sal/config.h>
22 #include <sdr/properties/customshapeproperties.hxx>
23 #include <svl/itemset.hxx>
24 #include <svl/style.hxx>
25 #include <svx/svdoashp.hxx>
26 #include <svx/sdooitm.hxx>
27 #include <editeng/eeitem.hxx>
28 #include <svl/whiter.hxx>
29 #include <svl/hint.hxx>
32 namespace sdr::properties
34 void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry
)
36 SdrObjCustomShape
& rObj
= static_cast< SdrObjCustomShape
& >(GetSdrObject());
37 const bool bOld(rObj
.mbTextFrame
);
39 // change TextFrame flag when bResizeShapeToFitText changes (which is mapped
40 // on the item SDRATTR_TEXT_AUTOGROWHEIGHT for custom shapes, argh)
41 rObj
.mbTextFrame
= GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT
).GetValue();
43 // check if it did change
44 if(rObj
.mbTextFrame
!= bOld
)
46 // on change also invalidate render geometry
47 bInvalidateRenderGeometry
= true;
49 // #115391# Potential recursion, since it calls SetObjectItemSet again, but rObj.bTextFrame
50 // will not change again. Thus it will be only one level and terminate safely
51 rObj
.AdaptTextMinSize();
54 if(bInvalidateRenderGeometry
)
56 // if asked for or bResizeShapeToFitText changed, make sure that
57 // the render geometry is reconstructed using changed parameters
58 rObj
.InvalidateRenderGeometry();
62 SfxItemSet
CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool
& rPool
)
67 // Ranges from SdrAttrObj:
68 SDRATTR_START
, SDRATTR_SHADOW_LAST
,
69 SDRATTR_MISC_FIRST
, SDRATTR_MISC_LAST
,
70 SDRATTR_TEXTDIRECTION
, SDRATTR_TEXTDIRECTION
,
71 // Graphic attributes, 3D properties, CustomShape
73 SDRATTR_GRAF_FIRST
, SDRATTR_CUSTOMSHAPE_LAST
,
74 SDRATTR_GLOW_FIRST
, SDRATTR_GLOW_TEXT_LAST
,
75 SDRATTR_TEXTCOLUMNS_FIRST
, SDRATTR_TEXTCOLUMNS_LAST
,
76 SDRATTR_WRITINGMODE2
, SDRATTR_WRITINGMODE2
,
77 // Range from SdrTextObj:
78 EE_ITEMS_START
, EE_ITEMS_END
>);
81 bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich
, const SfxPoolItem
* pNewItem
) const
83 bool bAllowItemChange
= true;
86 if ( ( nWhich
>= SDRATTR_CUSTOMSHAPE_FIRST
) && ( nWhich
<= SDRATTR_CUSTOMSHAPE_LAST
) )
87 bAllowItemChange
= false;
89 if ( bAllowItemChange
)
90 bAllowItemChange
= TextProperties::AllowItemChange( nWhich
, pNewItem
);
91 return bAllowItemChange
;
94 void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich
)
98 SfxWhichIter
aIter( *moItemSet
);
99 sal_uInt16 nWhich2
= aIter
.FirstWhich();
102 TextProperties::ClearObjectItemDirect( nWhich2
);
103 nWhich2
= aIter
.NextWhich();
105 ItemSetChanged({}, 0);
108 TextProperties::ClearObjectItem( nWhich
);
111 void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich
)
115 SfxWhichIter
aIter( *moItemSet
);
116 sal_uInt16 nWhich2
= aIter
.FirstWhich();
119 TextProperties::ClearObjectItemDirect( nWhich2
);
120 nWhich2
= aIter
.NextWhich();
124 TextProperties::ClearObjectItemDirect( nWhich
);
127 void CustomShapeProperties::ItemSetChanged(std::span
< const SfxPoolItem
* const > aChangedItems
, sal_uInt16 nDeletedWhich
, bool bAdjustTextFrameWidthAndHeight
)
130 TextProperties::ItemSetChanged(aChangedItems
, nDeletedWhich
, bAdjustTextFrameWidthAndHeight
);
132 // update bTextFrame and RenderGeometry
133 UpdateTextFrameStatus(true);
136 void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich
)
140 case SDRATTR_TEXT_AUTOGROWHEIGHT
:
142 // #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize()
143 UpdateTextFrameStatus(false);
153 TextProperties::PostItemChange(nWhich
);
156 void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich
, const SfxPoolItem
* pNewItem
)
159 TextProperties::ItemChange( nWhich
, pNewItem
);
161 // update bTextFrame and RenderGeometry
162 UpdateTextFrameStatus(true);
165 void CustomShapeProperties::SetStyleSheet(SfxStyleSheet
* pNewStyleSheet
, bool bDontRemoveHardAttr
,
166 bool bBroadcast
, bool bAdjustTextFrameWidthAndHeight
)
168 // call parent (always first thing to do, may create the SfxItemSet)
169 TextProperties::SetStyleSheet( pNewStyleSheet
, bDontRemoveHardAttr
, bBroadcast
, bAdjustTextFrameWidthAndHeight
);
171 // update bTextFrame and RenderGeometry
172 UpdateTextFrameStatus(true);
175 void CustomShapeProperties::ForceDefaultAttributes()
177 // update bTextFrame and RenderGeometry
178 UpdateTextFrameStatus(true);
180 // SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
181 // This means: Do *not* call parent here is by purpose...
184 CustomShapeProperties::CustomShapeProperties(SdrObject
& rObj
)
185 : TextProperties(rObj
)
189 CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties
& rProps
, SdrObject
& rObj
)
190 : TextProperties(rProps
, rObj
)
194 CustomShapeProperties::~CustomShapeProperties()
198 std::unique_ptr
<BaseProperties
> CustomShapeProperties::Clone(SdrObject
& rObj
) const
200 return std::unique_ptr
<BaseProperties
>(new CustomShapeProperties(*this, rObj
));
203 void CustomShapeProperties::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
205 TextProperties::Notify( rBC
, rHint
);
207 bool bRemoveRenderGeometry
= false;
209 if (rHint
.GetId() == SfxHintId::StyleSheetModified
||
210 rHint
.GetId() == SfxHintId::StyleSheetModifiedExtended
||
211 rHint
.GetId() == SfxHintId::StyleSheetChanged
)
213 const SfxStyleSheetHint
* pStyleHint
= static_cast<const SfxStyleSheetHint
*>(&rHint
);
214 if ( pStyleHint
->GetStyleSheet() == GetStyleSheet() )
215 bRemoveRenderGeometry
= true;
217 else if ( rHint
.GetId() == SfxHintId::DataChanged
)
219 bRemoveRenderGeometry
= true;
222 // update bTextFrame and RenderGeometry
223 UpdateTextFrameStatus(bRemoveRenderGeometry
);
225 } // end of namespace
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */