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 <editeng/eeitem.hxx>
27 #include <svx/sdtagitm.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 std::make_unique<SfxItemSet>(
65  rPool,
66  svl::Items<
67  // Ranges from SdrAttrObj:
71  // Graphic attributes, 3D properties, CustomShape
72  // properties:
74  // Range from SdrTextObj:
76  }
77 
78  bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
79  {
80  bool bAllowItemChange = true;
81  if ( !pNewItem )
82  {
83  if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
84  bAllowItemChange = false;
85  }
86  if ( bAllowItemChange )
87  bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
88  return bAllowItemChange;
89  }
90 
91  void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
92  {
93  if ( !nWhich )
94  {
95  SfxWhichIter aIter( *mpItemSet );
96  sal_uInt16 nWhich2 = aIter.FirstWhich();
97  while( nWhich2 )
98  {
100  nWhich2 = aIter.NextWhich();
101  }
102  SfxItemSet aSet(GetSdrObject().GetObjectItemPool());
103  ItemSetChanged(aSet);
104  }
105  else
107  }
108 
109  void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
110  {
111  if ( !nWhich )
112  {
113  SfxWhichIter aIter( *mpItemSet );
114  sal_uInt16 nWhich2 = aIter.FirstWhich();
115  while( nWhich2 )
116  {
118  nWhich2 = aIter.NextWhich();
119  }
120  }
121  else
123  }
124 
126  {
127  // call parent
129 
130  // update bTextFrame and RenderGeometry
131  UpdateTextFrameStatus(true);
132  }
133 
134  void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
135  {
136  switch(nWhich)
137  {
139  {
140  // #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize()
141  UpdateTextFrameStatus(false);
142  break;
143  }
144  default:
145  {
146  break;
147  }
148  }
149 
150  // call parent
152  }
153 
154  void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
155  {
156  // call parent
157  TextProperties::ItemChange( nWhich, pNewItem );
158 
159  // update bTextFrame and RenderGeometry
160  UpdateTextFrameStatus(true);
161  }
162 
163  void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
164  {
165  // call parent (always first thing to do, may create the SfxItemSet)
166  TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
167 
168  // update bTextFrame and RenderGeometry
169  UpdateTextFrameStatus(true);
170  }
171 
173  {
174  // update bTextFrame and RenderGeometry
175  UpdateTextFrameStatus(true);
176 
177  // SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
178  // This means: Do *not* call parent here is by purpose...
179  }
180 
182  : TextProperties(rObj)
183  {
184  }
185 
187  : TextProperties(rProps, rObj)
188  {
189  }
190 
192  {
193  }
194 
195  std::unique_ptr<BaseProperties> CustomShapeProperties::Clone(SdrObject& rObj) const
196  {
197  return std::unique_ptr<BaseProperties>(new CustomShapeProperties(*this, rObj));
198  }
199 
201  {
202  TextProperties::Notify( rBC, rHint );
203 
204  bool bRemoveRenderGeometry = false;
205  const SfxStyleSheetHint* pStyleHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
206 
207  if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
208  {
209  switch( pStyleHint->GetId() )
210  {
211  case SfxHintId::StyleSheetModified :
212  case SfxHintId::StyleSheetChanged :
213  bRemoveRenderGeometry = true;
214  break;
215  default: break;
216  }
217  }
218  else if ( rHint.GetId() == SfxHintId::DataChanged )
219  {
220  bRemoveRenderGeometry = true;
221  }
222 
223  // update bTextFrame and RenderGeometry
224  UpdateTextFrameStatus(bRemoveRenderGeometry);
225  }
226 } // end of namespace
227 
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define EE_ITEMS_START
virtual SfxStyleSheet * GetStyleSheet() const override
virtual void ClearObjectItemDirect(const sal_uInt16 nWhich) override
#define SDRATTR_CUSTOMSHAPE_LAST
Definition: svddef.hxx:396
virtual void PostItemChange(const sal_uInt16 nWhich) override
virtual void AdaptTextMinSize() override
Definition: svdoashp.cxx:1401
sal_uInt16 FirstWhich()
virtual const SfxItemSet & GetObjectItemSet() const override
#define SDRATTR_MISC_LAST
Definition: svddef.hxx:220
std::unique_ptr< SfxItemSet > mpItemSet
SfxHintId GetId() const
virtual void ItemSetChanged(const SfxItemSet &rSet) override
sal_uInt16 NextWhich()
SfxStyleSheetBase * GetStyleSheet() const
#define SDRATTR_SHADOW_LAST
Definition: svddef.hxx:178
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual bool AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) const override
virtual std::unique_ptr< BaseProperties > Clone(SdrObject &rObj) const override
#define SDRATTR_MISC_FIRST
Definition: svddef.hxx:193
virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) override
#define SDRATTR_TEXTDIRECTION
Definition: svddef.hxx:302
#define SDRATTR_START
Definition: svddef.hxx:168
#define SDRATTR_GRAF_FIRST
Definition: svddef.hxx:307
Abstract DrawObject.
Definition: svdobj.hxx:312
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
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
#define SDRATTR_TEXT_AUTOGROWHEIGHT
Definition: svddef.hxx:196
virtual std::unique_ptr< SfxItemSet > CreateObjectSpecificItemSet(SfxItemPool &rPool) override
const SdrObject & GetSdrObject() const
Definition: properties.cxx:60
virtual void ClearObjectItem(const sal_uInt16 nWhich=0) override
virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) override
#define SDRATTR_CUSTOMSHAPE_FIRST
Definition: svddef.hxx:392
virtual void ClearObjectItem(const sal_uInt16 nWhich=0) override
virtual void ItemSetChanged(const SfxItemSet &rSet) override
#define EE_ITEMS_END
void InvalidateRenderGeometry()
Definition: svdoashp.cxx:3183
void UpdateTextFrameStatus(bool bInvalidateRenderGeometry)