Bump version to 6.4-15
[LibreOffice.git] / svx / source / sdr / properties / customshapeproperties.cxx
bloba51fb7359b6cc6f7f38d758cd222ad4ca092eec1
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 <editeng/eeitem.hxx>
27 #include <svx/sdtagitm.hxx>
28 #include <svl/whiter.hxx>
29 #include <svl/hint.hxx>
32 namespace sdr
34 namespace properties
36 void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry)
38 SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
39 const bool bOld(rObj.bTextFrame);
41 // change TextFrame flag when bResizeShapeToFitText changes (which is mapped
42 // on the item SDRATTR_TEXT_AUTOGROWHEIGHT for custom shapes, argh)
43 rObj.bTextFrame = GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT).GetValue();
45 // check if it did change
46 if(rObj.bTextFrame != bOld)
48 // on change also invalidate render geometry
49 bInvalidateRenderGeometry = true;
51 // #115391# Potential recursion, since it calls SetObjectItemSet again, but rObj.bTextFrame
52 // will not change again. Thus it will be only one level and terminate safely
53 rObj.AdaptTextMinSize();
56 if(bInvalidateRenderGeometry)
58 // if asked for or bResizeShapeToFitText changed, make sure that
59 // the render geometry is reconstructed using changed parameters
60 rObj.InvalidateRenderGeometry();
64 std::unique_ptr<SfxItemSet> CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
66 return std::make_unique<SfxItemSet>(
67 rPool,
68 svl::Items<
69 // Ranges from SdrAttrObj:
70 SDRATTR_START, SDRATTR_SHADOW_LAST,
71 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
72 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
73 // Graphic attributes, 3D properties, CustomShape
74 // properties:
75 SDRATTR_GRAF_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
76 // Range from SdrTextObj:
77 EE_ITEMS_START, EE_ITEMS_END>{});
80 bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
82 bool bAllowItemChange = true;
83 if ( !pNewItem )
85 if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
86 bAllowItemChange = false;
88 if ( bAllowItemChange )
89 bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
90 return bAllowItemChange;
93 void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
95 if ( !nWhich )
97 SfxWhichIter aIter( *mpItemSet );
98 sal_uInt16 nWhich2 = aIter.FirstWhich();
99 while( nWhich2 )
101 TextProperties::ClearObjectItemDirect( nWhich2 );
102 nWhich2 = aIter.NextWhich();
104 SfxItemSet aSet(GetSdrObject().GetObjectItemPool());
105 ItemSetChanged(aSet);
107 else
108 TextProperties::ClearObjectItem( nWhich );
111 void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
113 if ( !nWhich )
115 SfxWhichIter aIter( *mpItemSet );
116 sal_uInt16 nWhich2 = aIter.FirstWhich();
117 while( nWhich2 )
119 TextProperties::ClearObjectItemDirect( nWhich2 );
120 nWhich2 = aIter.NextWhich();
123 else
124 TextProperties::ClearObjectItemDirect( nWhich );
127 void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
129 // call parent
130 TextProperties::ItemSetChanged(rSet);
132 // update bTextFrame and RenderGeometry
133 UpdateTextFrameStatus(true);
136 void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
138 switch(nWhich)
140 case SDRATTR_TEXT_AUTOGROWHEIGHT:
142 // #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize()
143 UpdateTextFrameStatus(false);
144 break;
146 default:
148 break;
152 // call parent
153 TextProperties::PostItemChange(nWhich);
156 void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
158 // call parent
159 TextProperties::ItemChange( nWhich, pNewItem );
161 // update bTextFrame and RenderGeometry
162 UpdateTextFrameStatus(true);
165 void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
167 // call parent (always first thing to do, may create the SfxItemSet)
168 TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
170 // update bTextFrame and RenderGeometry
171 UpdateTextFrameStatus(true);
174 void CustomShapeProperties::ForceDefaultAttributes()
176 // update bTextFrame and RenderGeometry
177 UpdateTextFrameStatus(true);
179 // SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
180 // This means: Do *not* call parent here is by purpose...
183 CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
184 : TextProperties(rObj)
188 CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
189 : TextProperties(rProps, rObj)
193 CustomShapeProperties::~CustomShapeProperties()
197 std::unique_ptr<BaseProperties> CustomShapeProperties::Clone(SdrObject& rObj) const
199 return std::unique_ptr<BaseProperties>(new CustomShapeProperties(*this, rObj));
202 void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
204 TextProperties::Notify( rBC, rHint );
206 bool bRemoveRenderGeometry = false;
207 const SfxStyleSheetHint* pStyleHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
209 if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
211 switch( pStyleHint->GetId() )
213 case SfxHintId::StyleSheetModified :
214 case SfxHintId::StyleSheetChanged :
215 bRemoveRenderGeometry = true;
216 break;
217 default: break;
220 else if ( rHint.GetId() == SfxHintId::DataChanged )
222 bRemoveRenderGeometry = true;
225 // update bTextFrame and RenderGeometry
226 UpdateTextFrameStatus(bRemoveRenderGeometry);
228 } // end of namespace properties
229 } // end of namespace sdr
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */