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