LibreOffice Module svx (master)  1
properties.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 <libxml/xmlwriter.h>
21 
24 #include <svl/itemset.hxx>
25 #include <svx/svdogrp.hxx>
26 #include <svx/svditer.hxx>
27 #include <svx/xdef.hxx>
28 #include <svx/xfillit0.hxx>
29 #include <svx/svdmodel.hxx>
30 
31 using namespace com::sun::star;
32 
33 namespace sdr::properties
34 {
35  BaseProperties::BaseProperties(SdrObject& rObj)
36  : mrObject(rObj)
37  {
38  }
39 
41  {
42  }
43 
45  {
46  SfxStyleSheet* pDefaultStyleSheet(GetSdrObject().getSdrModelFromSdrObject().GetDefaultStyleSheet());
47 
48  // tdf#118139 Only do this when StyleSheet really differs. It may e.g.
49  // be the case that nullptr == pDefaultStyleSheet and there is none set yet,
50  // so indeed no need to set it (needed for some strange old MSWord2003
51  // documents with CustomShape-'Group' and added Text-Frames, see task description)
52  if(pDefaultStyleSheet != GetStyleSheet())
53  {
54  // do not delete hard attributes when setting dsefault Style
55  SetStyleSheet(pDefaultStyleSheet, true);
56  }
57  }
58 
60  {
61  return mrObject;
62  }
63 
65  {
66  return mrObject;
67  }
68 
70  {
71  // default implementation falls back to GetObjectItemSet()
72  return GetObjectItemSet();
73  }
74 
75  void BaseProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems)
76  {
77  // clear items if requested
78  if(bClearAllItems)
79  {
81  }
82 
83  // default implementation falls back to SetObjectItemSet()
84  SetObjectItemSet(rSet);
85  }
86 
88  {
89  // default implementation falls back to SetObjectItem()
90  SetObjectItem(rItem);
91  }
92 
93  void BaseProperties::ClearMergedItem(const sal_uInt16 nWhich)
94  {
95  // default implementation falls back to ClearObjectItem()
96  ClearObjectItem(nWhich);
97  }
98 
100  {
101  // force all attributes which come from styles to hard attributes
102  // to be able to live without the style. Default implementation does nothing.
103  // Override where an ItemSet is implemented.
104  }
105 
106  void BaseProperties::SetMergedItemSetAndBroadcast(const SfxItemSet& rSet, bool bClearAllItems)
107  {
109 
110  if(bClearAllItems)
111  {
112  ClearObjectItem();
113  }
114 
115  SetMergedItemSet(rSet);
117  }
118 
119  const SfxPoolItem& BaseProperties::GetItem(const sal_uInt16 nWhich) const
120  {
121  return GetObjectItemSet().Get(nWhich);
122  }
123 
125  {
126  const sal_uInt32 nCount(rChange.GetRectangleCount());
127 
128  // invalidate all new rectangles
129  if(dynamic_cast<const SdrObjGroup*>( &GetSdrObject() ) != nullptr)
130  {
131  SdrObjListIter aIter(static_cast<SdrObjGroup&>(GetSdrObject()), SdrIterMode::DeepNoGroups);
132 
133  while(aIter.IsMore())
134  {
135  SdrObject* pObj = aIter.Next();
136  pObj->BroadcastObjectChange();
137  }
138  }
139  else
140  {
142  }
143 
144  // also send the user calls
145  for(sal_uInt32 a(0); a < nCount; a++)
146  {
148  }
149  }
150 
151  sal_uInt32 BaseProperties::getVersion() const
152  {
153  return 0;
154  }
155 
157  {
158  xmlTextWriterStartElement(pWriter, BAD_CAST("BaseProperties"));
159  xmlTextWriterEndElement(pWriter);
160  }
161 
163  {
164  const bool bFillBitmap = rItemSet.GetItemState(XATTR_FILLBITMAP, false) == SfxItemState::SET;
165  const bool bFillGradient = rItemSet.GetItemState(XATTR_FILLGRADIENT, false) == SfxItemState::SET;
166  const bool bFillHatch = rItemSet.GetItemState(XATTR_FILLHATCH, false) == SfxItemState::SET;
167  if( bFillBitmap || bFillGradient || bFillHatch )
168  {
169  const XFillStyleItem* pFillStyleItem = rItemSet.GetItem(XATTR_FILLSTYLE);
170  if( pFillStyleItem )
171  {
172  if( bFillBitmap && (pFillStyleItem->GetValue() != drawing::FillStyle_BITMAP) )
173  {
174  rItemSet.ClearItem( XATTR_FILLBITMAP );
175  }
176 
177  if( bFillGradient && (pFillStyleItem->GetValue() != drawing::FillStyle_GRADIENT) )
178  {
179  rItemSet.ClearItem( XATTR_FILLGRADIENT );
180  }
181 
182  if( bFillHatch && (pFillStyleItem->GetValue() != drawing::FillStyle_HATCH) )
183  {
184  rItemSet.ClearItem( XATTR_FILLHATCH );
185  }
186  }
187  }
188  }
189 
190 } // end of namespace
191 
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual const SfxItemSet & GetObjectItemSet() const =0
#define XATTR_FILLHATCH
Definition: xdef.hxx:110
const SfxPoolItem & GetItem(const sal_uInt16 nWhich) const
Definition: properties.cxx:119
const tools::Rectangle & GetRectangle(sal_uInt32 nIndex) const
struct _xmlTextWriter * xmlTextWriterPtr
#define XATTR_FILLGRADIENT
Definition: xdef.hxx:109
virtual const SfxItemSet & GetMergedItemSet() const
Definition: properties.cxx:69
virtual void ForceStyleToHardAttributes()
Definition: properties.cxx:99
virtual void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: properties.cxx:75
virtual void ClearObjectItem(const sal_uInt16 nWhich=0)=0
bool IsMore() const
Definition: svditer.hxx:62
int nCount
void BroadcastItemChange(const ItemChangeBroadcaster &rChange)
Definition: properties.cxx:124
virtual SfxStyleSheet * GetStyleSheet() const =0
virtual void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)=0
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
virtual void SetObjectItem(const SfxPoolItem &rItem)=0
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
void SetMergedItemSetAndBroadcast(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: properties.cxx:106
void CleanupFillProperties(SfxItemSet &rItemSet)
Definition: properties.cxx:162
uno_Any a
void BroadcastObjectChange() const
Definition: svdobj.cxx:904
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: properties.cxx:156
#define XATTR_FILLSTYLE
Definition: xdef.hxx:107
Abstract DrawObject.
Definition: svdobj.hxx:312
virtual void applyDefaultStyleSheetFromSdrModel()
Definition: properties.cxx:44
SdrObject * Next()
Definition: svditer.hxx:63
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define XATTR_FILLBITMAP
Definition: xdef.hxx:111
virtual void SetMergedItem(const SfxPoolItem &rItem)
Definition: properties.cxx:87
const SdrObject & GetSdrObject() const
Definition: properties.cxx:59
virtual sal_uInt32 getVersion() const
Definition: properties.cxx:151
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
virtual void ClearMergedItem(const sal_uInt16 nWhich)
Definition: properties.cxx:93
void SendUserCall(SdrUserCallType eUserCall, const tools::Rectangle &rBoundRect) const
Definition: svdobj.cxx:2648
virtual void SetObjectItemSet(const SfxItemSet &rSet)=0
EnumT GetValue() const