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.mbTextFrame);
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.mbTextFrame != 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:
76  // Range from SdrTextObj:
78  }
79 
80  bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
81  {
82  bool bAllowItemChange = true;
83  if ( !pNewItem )
84  {
85  if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
86  bAllowItemChange = false;
87  }
88  if ( bAllowItemChange )
89  bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
90  return bAllowItemChange;
91  }
92 
93  void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
94  {
95  if ( !nWhich )
96  {
97  SfxWhichIter aIter( *mxItemSet );
98  sal_uInt16 nWhich2 = aIter.FirstWhich();
99  while( nWhich2 )
100  {
102  nWhich2 = aIter.NextWhich();
103  }
104  SfxItemSet aSet(GetSdrObject().GetObjectItemPool());
105  ItemSetChanged(&aSet);
106  }
107  else
109  }
110 
111  void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
112  {
113  if ( !nWhich )
114  {
115  SfxWhichIter aIter( *mxItemSet );
116  sal_uInt16 nWhich2 = aIter.FirstWhich();
117  while( nWhich2 )
118  {
120  nWhich2 = aIter.NextWhich();
121  }
122  }
123  else
125  }
126 
128  {
129  // call parent
131 
132  // update bTextFrame and RenderGeometry
133  UpdateTextFrameStatus(true);
134  }
135 
136  void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
137  {
138  switch(nWhich)
139  {
141  {
142  // #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize()
143  UpdateTextFrameStatus(false);
144  break;
145  }
146  default:
147  {
148  break;
149  }
150  }
151 
152  // call parent
154  }
155 
156  void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
157  {
158  // call parent
159  TextProperties::ItemChange( nWhich, pNewItem );
160 
161  // update bTextFrame and RenderGeometry
162  UpdateTextFrameStatus(true);
163  }
164 
165  void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
166  {
167  // call parent (always first thing to do, may create the SfxItemSet)
168  TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
169 
170  // update bTextFrame and RenderGeometry
171  UpdateTextFrameStatus(true);
172  }
173 
175  {
176  // update bTextFrame and RenderGeometry
177  UpdateTextFrameStatus(true);
178 
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...
181  }
182 
184  : TextProperties(rObj)
185  {
186  }
187 
189  : TextProperties(rProps, rObj)
190  {
191  }
192 
194  {
195  }
196 
197  std::unique_ptr<BaseProperties> CustomShapeProperties::Clone(SdrObject& rObj) const
198  {
199  return std::unique_ptr<BaseProperties>(new CustomShapeProperties(*this, rObj));
200  }
201 
203  {
204  TextProperties::Notify( rBC, rHint );
205 
206  bool bRemoveRenderGeometry = false;
207  const SfxStyleSheetHint* pStyleHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
208 
209  if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
210  {
211  switch( pStyleHint->GetId() )
212  {
213  case SfxHintId::StyleSheetModified :
214  case SfxHintId::StyleSheetChanged :
215  bRemoveRenderGeometry = true;
216  break;
217  default: break;
218  }
219  }
220  else if ( rHint.GetId() == SfxHintId::DataChanged )
221  {
222  bRemoveRenderGeometry = true;
223  }
224 
225  // update bTextFrame and RenderGeometry
226  UpdateTextFrameStatus(bRemoveRenderGeometry);
227  }
228 } // end of namespace
229 
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SdrOnOffItem > SDRATTR_TEXT_AUTOGROWHEIGHT(SDRATTR_MISC_FIRST+2)
virtual SfxStyleSheet * GetStyleSheet() const override
constexpr sal_uInt16 SDRATTR_TEXTCOLUMNS_LAST(SDRATTR_TEXTCOLUMNS_SPACING)
virtual void ClearObjectItemDirect(const sal_uInt16 nWhich) override
static constexpr auto Items
virtual void PostItemChange(const sal_uInt16 nWhich) override
virtual void AdaptTextMinSize() override
Definition: svdoashp.cxx:1374
sal_uInt16 FirstWhich()
constexpr sal_uInt16 SDRATTR_TEXTCOLUMNS_FIRST(SDRATTR_SOFTEDGE_LAST+1)
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
constexpr sal_uInt16 SDRATTR_START(XATTR_START)
sal_uInt16 NextWhich()
virtual void ItemSetChanged(const SfxItemSet *) override
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)
bool mbTextFrame
Definition: svdotext.hxx:219
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:259
virtual void PostItemChange(const sal_uInt16 nWhich) override
virtual void ItemSetChanged(const SfxItemSet *) override
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
void InvalidateRenderGeometry()
Definition: svdoashp.cxx:3200
void UpdateTextFrameStatus(bool bInvalidateRenderGeometry)