LibreOffice Module svx (master)  1
customshapeproperties.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/config.h>
21 
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>
30 
31 
32 namespace sdr::properties
33 {
34  void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry)
35  {
36  SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
37  const bool bOld(rObj.bTextFrame);
38 
39  // change TextFrame flag when bResizeShapeToFitText changes (which is mapped
40  // on the item SDRATTR_TEXT_AUTOGROWHEIGHT for custom shapes, argh)
42 
43  // check if it did change
44  if(rObj.bTextFrame != bOld)
45  {
46  // on change also invalidate render geometry
47  bInvalidateRenderGeometry = true;
48 
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();
52  }
53 
54  if(bInvalidateRenderGeometry)
55  {
56  // if asked for or bResizeShapeToFitText changed, make sure that
57  // the render geometry is reconstructed using changed parameters
59  }
60  }
61 
63  {
64  return SfxItemSet(
65  rPool,
66  svl::Items<
67  // Ranges from SdrAttrObj:
71  // Graphic attributes, 3D properties, CustomShape
72  // properties:
75  // Range from SdrTextObj:
77  }
78 
79  bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
80  {
81  bool bAllowItemChange = true;
82  if ( !pNewItem )
83  {
84  if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
85  bAllowItemChange = false;
86  }
87  if ( bAllowItemChange )
88  bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
89  return bAllowItemChange;
90  }
91 
92  void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
93  {
94  if ( !nWhich )
95  {
96  SfxWhichIter aIter( *mxItemSet );
97  sal_uInt16 nWhich2 = aIter.FirstWhich();
98  while( nWhich2 )
99  {
101  nWhich2 = aIter.NextWhich();
102  }
103  SfxItemSet aSet(GetSdrObject().GetObjectItemPool());
104  ItemSetChanged(aSet);
105  }
106  else
108  }
109 
110  void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
111  {
112  if ( !nWhich )
113  {
114  SfxWhichIter aIter( *mxItemSet );
115  sal_uInt16 nWhich2 = aIter.FirstWhich();
116  while( nWhich2 )
117  {
119  nWhich2 = aIter.NextWhich();
120  }
121  }
122  else
124  }
125 
127  {
128  // call parent
130 
131  // update bTextFrame and RenderGeometry
132  UpdateTextFrameStatus(true);
133  }
134 
135  void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
136  {
137  switch(nWhich)
138  {
140  {
141  // #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize()
142  UpdateTextFrameStatus(false);
143  break;
144  }
145  default:
146  {
147  break;
148  }
149  }
150 
151  // call parent
153  }
154 
155  void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
156  {
157  // call parent
158  TextProperties::ItemChange( nWhich, pNewItem );
159 
160  // update bTextFrame and RenderGeometry
161  UpdateTextFrameStatus(true);
162  }
163 
164  void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
165  {
166  // call parent (always first thing to do, may create the SfxItemSet)
167  TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
168 
169  // update bTextFrame and RenderGeometry
170  UpdateTextFrameStatus(true);
171  }
172 
174  {
175  // update bTextFrame and RenderGeometry
176  UpdateTextFrameStatus(true);
177 
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...
180  }
181 
183  : TextProperties(rObj)
184  {
185  }
186 
188  : TextProperties(rProps, rObj)
189  {
190  }
191 
193  {
194  }
195 
196  std::unique_ptr<BaseProperties> CustomShapeProperties::Clone(SdrObject& rObj) const
197  {
198  return std::unique_ptr<BaseProperties>(new CustomShapeProperties(*this, rObj));
199  }
200 
202  {
203  TextProperties::Notify( rBC, rHint );
204 
205  bool bRemoveRenderGeometry = false;
206  const SfxStyleSheetHint* pStyleHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
207 
208  if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
209  {
210  switch( pStyleHint->GetId() )
211  {
212  case SfxHintId::StyleSheetModified :
213  case SfxHintId::StyleSheetChanged :
214  bRemoveRenderGeometry = true;
215  break;
216  default: break;
217  }
218  }
219  else if ( rHint.GetId() == SfxHintId::DataChanged )
220  {
221  bRemoveRenderGeometry = true;
222  }
223 
224  // update bTextFrame and RenderGeometry
225  UpdateTextFrameStatus(bRemoveRenderGeometry);
226  }
227 } // end of namespace
228 
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SdrOnOffItem > SDRATTR_TEXT_AUTOGROWHEIGHT(SDRATTR_MISC_FIRST+2)
virtual SfxStyleSheet * GetStyleSheet() const override
virtual void ClearObjectItemDirect(const sal_uInt16 nWhich) override
virtual void PostItemChange(const sal_uInt16 nWhich) override
virtual void AdaptTextMinSize() override
Definition: svdoashp.cxx:1374
sal_uInt16 FirstWhich()
constexpr sal_uInt16 EE_ITEMS_END(EE_FEATURE_END)
virtual const SfxItemSet & GetObjectItemSet() const override
constexpr sal_uInt16 SDRATTR_MISC_LAST(SDRATTR_TEXT_CHAINNEXTNAME)
SfxHintId GetId() const
virtual void ItemSetChanged(const SfxItemSet &rSet) override
constexpr sal_uInt16 SDRATTR_START(XATTR_START)
sal_uInt16 NextWhich()
SfxStyleSheetBase * GetStyleSheet() const
constexpr sal_uInt16 SDRATTR_CUSTOMSHAPE_FIRST(SDRATTR_3D_LAST+1)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
constexpr sal_uInt16 SDRATTR_SOFTEDGE_LAST(SDRATTR_SOFTEDGE_RADIUS)
virtual bool AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) const override
constexpr sal_uInt16 SDRATTR_GLOW_FIRST(SDRATTR_TABLE_LAST+1)
constexpr TypedWhichId< SvxWritingModeItem > SDRATTR_TEXTDIRECTION(SDRATTR_NOTPERSIST_FIRST+34)
virtual std::unique_ptr< BaseProperties > Clone(SdrObject &rObj) const override
constexpr sal_uInt16 EE_ITEMS_START(OWN_ATTR_VALUE_END+1)
virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) override
constexpr sal_uInt16 SDRATTR_GRAF_FIRST(SDRATTR_NOTPERSIST_LAST+1)
Abstract DrawObject.
Definition: svdobj.hxx:258
virtual void PostItemChange(const sal_uInt16 nWhich) override
bool bTextFrame
Definition: svdotext.hxx:231
virtual bool AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) const override
virtual void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr) override
constexpr sal_uInt16 SDRATTR_SHADOW_LAST(SDRATTR_SHADOWBLUR)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual SfxItemSet CreateObjectSpecificItemSet(SfxItemPool &rPool) override
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr) override
virtual void ClearObjectItemDirect(const sal_uInt16 nWhich) override
std::optional< SfxItemSet > mxItemSet
constexpr sal_uInt16 SDRATTR_CUSTOMSHAPE_LAST(SDRATTR_CUSTOMSHAPE_GEOMETRY)
const SdrObject & GetSdrObject() const
Definition: properties.cxx:59
virtual void ClearObjectItem(const sal_uInt16 nWhich=0) override
constexpr sal_uInt16 SDRATTR_MISC_FIRST(SDRATTR_CAPTION_LAST+1)
virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) override
virtual void ClearObjectItem(const sal_uInt16 nWhich=0) override
virtual void ItemSetChanged(const SfxItemSet &rSet) override
void InvalidateRenderGeometry()
Definition: svdoashp.cxx:3204
void UpdateTextFrameStatus(bool bInvalidateRenderGeometry)