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 #include <sal/log.hxx>
32 
33 
34 namespace sdr::properties
35 {
36  void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry)
37  {
38  SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
39  const bool bOld(rObj.bTextFrame);
40 
41  // change TextFrame flag when bResizeShapeToFitText changes (which is mapped
42  // on the item SDRATTR_TEXT_AUTOGROWHEIGHT for custom shapes, argh)
44 
45  // check if it did change
46  if(rObj.bTextFrame != bOld)
47  {
48  // on change also invalidate render geometry
49  bInvalidateRenderGeometry = true;
50 
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();
54  }
55 
56  if(bInvalidateRenderGeometry)
57  {
58  // if asked for or bResizeShapeToFitText changed, make sure that
59  // the render geometry is reconstructed using changed parameters
61  }
62  }
63 
65  {
66  return std::make_unique<SfxItemSet>(
67  rPool,
68  svl::Items<
69  // Ranges from SdrAttrObj:
73  // Graphic attributes, 3D properties, CustomShape
74  // properties:
77  // Range from SdrTextObj:
79  }
80 
81  bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
82  {
83  bool bAllowItemChange = true;
84  if ( !pNewItem )
85  {
86  if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
87  bAllowItemChange = false;
88  }
89  if ( bAllowItemChange )
90  bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
91  return bAllowItemChange;
92  }
93 
94  void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
95  {
96  if ( !nWhich )
97  {
98  SfxWhichIter aIter( *mpItemSet );
99  sal_uInt16 nWhich2 = aIter.FirstWhich();
100  while( nWhich2 )
101  {
103  nWhich2 = aIter.NextWhich();
104  }
105  SfxItemSet aSet(GetSdrObject().GetObjectItemPool());
106  ItemSetChanged(aSet);
107  }
108  else
110  }
111 
112  void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
113  {
114  if ( !nWhich )
115  {
116  SfxWhichIter aIter( *mpItemSet );
117  sal_uInt16 nWhich2 = aIter.FirstWhich();
118  while( nWhich2 )
119  {
121  nWhich2 = aIter.NextWhich();
122  }
123  }
124  else
126  }
127 
129  {
130  // call parent
132 
133  // update bTextFrame and RenderGeometry
134  UpdateTextFrameStatus(true);
135  }
136 
137  void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
138  {
139  switch(nWhich)
140  {
142  {
143  // #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize()
144  UpdateTextFrameStatus(false);
145  break;
146  }
147  default:
148  {
149  break;
150  }
151  }
152 
153  // call parent
155  }
156 
157  void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
158  {
159  // call parent
160  TextProperties::ItemChange( nWhich, pNewItem );
161 
162  // update bTextFrame and RenderGeometry
163  UpdateTextFrameStatus(true);
164  }
165 
166  void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
167  {
168  // call parent (always first thing to do, may create the SfxItemSet)
169  TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
170 
171  // update bTextFrame and RenderGeometry
172  UpdateTextFrameStatus(true);
173  }
174 
176  {
177  // update bTextFrame and RenderGeometry
178  UpdateTextFrameStatus(true);
179 
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...
182  }
183 
185  : TextProperties(rObj)
186  {
187  }
188 
190  : TextProperties(rProps, rObj)
191  {
192  }
193 
195  {
196  }
197 
198  std::unique_ptr<BaseProperties> CustomShapeProperties::Clone(SdrObject& rObj) const
199  {
200  return std::unique_ptr<BaseProperties>(new CustomShapeProperties(*this, rObj));
201  }
202 
204  {
205  TextProperties::Notify( rBC, rHint );
206 
207  bool bRemoveRenderGeometry = false;
208  const SfxStyleSheetHint* pStyleHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
209 
210  if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
211  {
212  switch( pStyleHint->GetId() )
213  {
214  case SfxHintId::StyleSheetModified :
215  case SfxHintId::StyleSheetChanged :
216  bRemoveRenderGeometry = true;
217  break;
218  default: break;
219  }
220  }
221  else if ( rHint.GetId() == SfxHintId::DataChanged )
222  {
223  bRemoveRenderGeometry = true;
224  }
225 
226  // update bTextFrame and RenderGeometry
227  UpdateTextFrameStatus(bRemoveRenderGeometry);
228  }
229 } // end of namespace
230 
231 /* 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:1357
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)
std::unique_ptr< SfxItemSet > mpItemSet
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:260
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
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
virtual std::unique_ptr< SfxItemSet > CreateObjectSpecificItemSet(SfxItemPool &rPool) override
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:3191
void UpdateTextFrameStatus(bool bInvalidateRenderGeometry)