bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / sdr / properties / customshapeproperties.cxx
blob07c893d1cf5160f3b2451ebb1d3e6f62e9c7a2e5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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.bTextFrame);
39 // change TextFrame flag when bResizeShapeToFitText changes (which is mapped
40 // on the item SDRATTR_TEXT_AUTOGROWHEIGHT for custom shapes, argh)
41 rObj.bTextFrame = GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT).GetValue();
43 // check if it did change
44 if(rObj.bTextFrame != 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)
64 return SfxItemSet(
65 rPool,
66 svl::Items<
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
72 // properties:
73 SDRATTR_GRAF_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
74 SDRATTR_GLOW_FIRST, SDRATTR_TEXTCOLUMNS_LAST,
75 // Range from SdrTextObj:
76 EE_ITEMS_START, EE_ITEMS_END>{});
79 bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
81 bool bAllowItemChange = true;
82 if ( !pNewItem )
84 if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
85 bAllowItemChange = false;
87 if ( bAllowItemChange )
88 bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
89 return bAllowItemChange;
92 void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
94 if ( !nWhich )
96 SfxWhichIter aIter( *mxItemSet );
97 sal_uInt16 nWhich2 = aIter.FirstWhich();
98 while( nWhich2 )
100 TextProperties::ClearObjectItemDirect( nWhich2 );
101 nWhich2 = aIter.NextWhich();
103 SfxItemSet aSet(GetSdrObject().GetObjectItemPool());
104 ItemSetChanged(aSet);
106 else
107 TextProperties::ClearObjectItem( nWhich );
110 void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
112 if ( !nWhich )
114 SfxWhichIter aIter( *mxItemSet );
115 sal_uInt16 nWhich2 = aIter.FirstWhich();
116 while( nWhich2 )
118 TextProperties::ClearObjectItemDirect( nWhich2 );
119 nWhich2 = aIter.NextWhich();
122 else
123 TextProperties::ClearObjectItemDirect( nWhich );
126 void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
128 // call parent
129 TextProperties::ItemSetChanged(rSet);
131 // update bTextFrame and RenderGeometry
132 UpdateTextFrameStatus(true);
135 void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
137 switch(nWhich)
139 case SDRATTR_TEXT_AUTOGROWHEIGHT:
141 // #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize()
142 UpdateTextFrameStatus(false);
143 break;
145 default:
147 break;
151 // call parent
152 TextProperties::PostItemChange(nWhich);
155 void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
157 // call parent
158 TextProperties::ItemChange( nWhich, pNewItem );
160 // update bTextFrame and RenderGeometry
161 UpdateTextFrameStatus(true);
164 void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
166 // call parent (always first thing to do, may create the SfxItemSet)
167 TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
169 // update bTextFrame and RenderGeometry
170 UpdateTextFrameStatus(true);
173 void CustomShapeProperties::ForceDefaultAttributes()
175 // update bTextFrame and RenderGeometry
176 UpdateTextFrameStatus(true);
178 // SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
179 // This means: Do *not* call parent here is by purpose...
182 CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
183 : TextProperties(rObj)
187 CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
188 : TextProperties(rProps, rObj)
192 CustomShapeProperties::~CustomShapeProperties()
196 std::unique_ptr<BaseProperties> CustomShapeProperties::Clone(SdrObject& rObj) const
198 return std::unique_ptr<BaseProperties>(new CustomShapeProperties(*this, rObj));
201 void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
203 TextProperties::Notify( rBC, rHint );
205 bool bRemoveRenderGeometry = false;
206 const SfxStyleSheetHint* pStyleHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
208 if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
210 switch( pStyleHint->GetId() )
212 case SfxHintId::StyleSheetModified :
213 case SfxHintId::StyleSheetChanged :
214 bRemoveRenderGeometry = true;
215 break;
216 default: break;
219 else if ( rHint.GetId() == SfxHintId::DataChanged )
221 bRemoveRenderGeometry = true;
224 // update bTextFrame and RenderGeometry
225 UpdateTextFrameStatus(bRemoveRenderGeometry);
227 } // end of namespace
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */